1 #define GUI_FB
2 
3 NAMESPACE_UPP
4 
5 class SystemDraw : public Draw {
6 public:
7 	virtual dword GetInfo() const;
8 	virtual Size  GetPageSize() const;
9 
10 	virtual void BeginOp();
11 	virtual void EndOp();
12 	virtual void OffsetOp(Point p);
13 	virtual bool ClipOp(const Rect& r);
14 	virtual bool ClipoffOp(const Rect& r);
15 	virtual bool ExcludeClipOp(const Rect& r);
16 	virtual bool IntersectClipOp(const Rect& r);
17 	virtual bool IsPaintingOp(const Rect& r) const;
18 	virtual Rect GetPaintRect() const;
19 
20 	virtual	void DrawRectOp(int x, int y, int cx, int cy, Color color);
21 	virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
22 	virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);
23 
24 	virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
25 	                                const int *counts, int count_count,
26 	                                int width, Color color, Color doxor);
27 	virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
28 	                                   const int *subpolygon_counts, int scc,
29 	                                   const int *disjunct_polygon_counts, int dpcc,
30 	                                   Color color, int width, Color outline,
31 	                                   uint64 pattern, Color doxor);
32 	virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color);
33 
34 	virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
35 	virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
36 		                    Color ink, int n, const int *dx);
37 
38 	virtual Size GetNativeDpi() const;
39 	virtual void BeginNative();
40 	virtual void EndNative();
41 
42 	virtual int  GetCloffLevel() const;
43 
44 private:
45 	Size  pageSize;
46 	Size  nativeSize;
47 	Size  nativeDpi;
48 	bool  palette:1;
49 	bool  color16:1;
50 	bool  is_mono:1;
51 	int   native;
52 
53 	friend class  ImageDraw;
54 	friend class  FontInfo;
55 	friend class  Font;
56 
57 	friend void StaticExitDraw_();
58 
59 	Point     actual_offset_bak;
60 
61 	struct Cloff : Moveable<Cloff> {
62 		Point org;
63 		HRGN  hrgn;
64 		Rect  drawingclip;
65 	};
66 
67 	Array<Cloff> cloff;
68 	Rect         drawingclip;
69 
70 	COLORREF  lastTextColor;
71 	Color     lastColor;
72 	HBRUSH    orgBrush;
73 	HBRUSH    actBrush;
74 	HPEN      orgPen;
75 	HPEN      actPen;
76 	int       lastPen;
77 	Color     lastPenColor;
78 
79 	void   Unselect0();
80 	void   Cinit();
81 
82 	void   LoadCaps();
83 	void   SetPrinterMode();
84 	void   Reset();
85 	void   SetOrg();
86 	friend HPALETTE GetQlibPalette();
87 	void   DotsMode();
88 
89 	static void      InitColors();
90 
91 	friend class BackDraw;
92 	friend class ScreenDraw;
93 	friend class PrintDraw;
94 
95 protected:
96 	dword style;
97 	HDC   handle;
98 	Point actual_offset;
99 
100 	SystemDraw();
101 	void   Init();
102 	void   InitClip(const Rect& clip);
103 
104 public:
105 	static Rect GetVirtualScreenArea();
106 
107 	static void SetAutoPalette(bool ap);
108 	static bool AutoPalette();
PaletteMode()109 	bool PaletteMode()                                  { return palette; }
110 
Flush()111 	static void Flush()                                 { GdiFlush(); }
112 
113 	COLORREF GetColor(Color color) const;
114 
GetOffset()115 	Point    GetOffset() const                          { return actual_offset; }
116 
117 #ifndef PLATFORM_WINCE
118 	Point LPtoDP(Point p) const;
119 	Point DPtoLP(Point p) const;
120 	Rect  LPtoDP(const Rect& r) const;
121 	Rect  DPtoLP(const Rect& r) const;
122 #endif
123 
124 	void SetColor(Color color);
125 	void SetDrawPen(int width, Color color);
126 
127 	Size  GetSizeCaps(int i, int j) const;
128 	HDC   BeginGdi();
129 	void  EndGdi();
GetHandle()130 	HDC   GetHandle()                    { return handle; }
HDC()131 	operator HDC() const                 { return handle; }
132 	void  Unselect();
Attach(HDC ahandle)133 	void  Attach(HDC ahandle)            { handle = ahandle; Init(); }
Detach()134 	HDC   Detach()                       { Unselect(); HDC h = handle; handle = NULL; return h; }
135 
136 	SystemDraw(HDC hdc);
137 	virtual ~SystemDraw();
138 
CanSetSurface()139 	bool CanSetSurface()                 { return IsGui() && IsWinNT(); }
140 };
141 
142 #ifndef PLATFORM_WINCE
143 class WinMetaFile {
144 	Size size;
145 	HENHMETAFILE hemf;
146 
147 	void     Init();
148 
149 public:
150 	void         Attach(HENHMETAFILE emf);
151 	HENHMETAFILE Detach();
152 
153 	void     Set(const void *data, dword len);
Set(const String & data)154 	void     Set(const String& data)        { Set(~data, data.GetCount()); }
155 
156 	String   Get() const;
157 
158 	operator bool() const                   { return hemf; }
SetSize(const Size & sz)159 	void     SetSize(const Size& sz)        { size = sz; }
GetSize()160 	Size     GetSize() const                { return hemf ? size : Size(0, 0); }
161 
162 	void     Clear();
163 
164 	void     Paint(Draw& w, const Rect& r) const;
165 	void     Paint(Draw& w, int x, int y, int cx, int cy) const;
166 
167 	void     Serialize(Stream& s);
168 
169 	void     ReadClipboard();
170 	void     WriteClipboard() const;
Load(const char * file)171 	void     Load(const char *file)         { Set(LoadFile(file)); }
172 
WinMetaFile()173 	WinMetaFile()                           { Init(); }
174 	WinMetaFile(HENHMETAFILE hemf);
175 	WinMetaFile(HENHMETAFILE hemf, Size sz);
176 	WinMetaFile(const char *file);
177 	WinMetaFile(void *data, int len);
178 	WinMetaFile(const String& data);
179 
~WinMetaFile()180 	~WinMetaFile()                                { Clear(); }
181 
GetHEMF()182 	HENHMETAFILE GetHEMF() const                  { return hemf; }
183 };
184 
185 class WinMetaFileDraw : public SystemDraw {
186 	Size size;
187 
188 public:
189 	bool        Create(HDC hdc, int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL);
190 	bool        Create(int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL);
191 	WinMetaFile Close();
192 
WinMetaFileDraw()193 	WinMetaFileDraw() {}
194 	WinMetaFileDraw(HDC hdc, int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL);
195 	WinMetaFileDraw(int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL);
196 	~WinMetaFileDraw();
197 };
198 
199 void DrawWMF(Draw& w, int x, int y, int cx, int cy, const String& wmf);
200 void DrawWMF(Draw& w, int x, int y, const String& wmf);
201 Drawing LoadWMF(const char *path, int cx, int cy);
202 Drawing LoadWMF(const char *path);
203 
204 String  AsWMF(const Drawing& iw);
205 
206 #endif
207 
208 class ScreenDraw : public SystemDraw {
209 public:
210 	ScreenDraw(bool ic = false);
211 	~ScreenDraw();
212 };
213 
214 #ifndef PLATFORM_WINCE
215 class PrintDraw : public SystemDraw {
216 public:
217 	virtual void StartPage();
218 	virtual void EndPage();
219 
220 private:
221 	bool aborted;
222 
223 	void  InitPrinter();
224 public:
225 	PrintDraw(HDC hdc, const char *jobname);
226 	~PrintDraw();
227 };
228 #endif
229 
230 inline bool     BitBlt(HDC ddc, Point d, HDC sdc, const Rect& s, dword rop = SRCCOPY)
231 { return BitBlt(ddc, d.x, d.y, s.Width(), s.Height(), sdc, s.left, s.top, rop); }
232 
233 inline bool     StretchBlt(HDC ddc, const Rect& r, HDC sdc, const Rect& s, dword rop = SRCCOPY)
234 { return StretchBlt(ddc, r.left, r.top, r.Width(), r.Height(), sdc, s.left, s.top, s.Width(), s.Height(), rop); }
235 
236 inline bool     PatBlt(HDC dc, const Rect& r, dword rop = PATCOPY)
237 { return PatBlt(dc, r.left, r.top, r.Width(), r.Height(), rop); }
238 
MoveTo(HDC hdc,Point pt)239 inline void     MoveTo(HDC hdc, Point pt)                         { MoveToEx(hdc, pt.x, pt.y, 0); }
LineTo(HDC hdc,Point pt)240 inline void     LineTo(HDC hdc, Point pt)                         { LineTo(hdc, pt.x, pt.y); }
241 
DrawLine(HDC hdc,Point p,Point q)242 inline void     DrawLine(HDC hdc, Point p, Point q)               { MoveTo(hdc, p); LineTo(hdc, q); }
DrawLine(HDC hdc,int px,int py,int qx,int qy)243 inline void     DrawLine(HDC hdc, int px, int py, int qx, int qy) { MoveToEx(hdc, px, py, 0); LineTo(hdc, qx, qy); }
244 
245 #ifndef PLATFORM_WINCE
DrawArc(HDC hdc,const Rect & rc,Point p,Point q)246 inline void     DrawArc(HDC hdc, const Rect& rc, Point p, Point q){ Arc(hdc, rc.left, rc.top, rc.right, rc.bottom, p.x, p.y, q.x, q.y); }
247 #endif
DrawCircle(HDC hdc,int x,int y,int radius)248 inline void     DrawCircle(HDC hdc, int x, int y, int radius)     { Ellipse(hdc, x - radius, y - radius, x + radius + 1, y + radius + 1); }
DrawCircle(HDC hdc,Point centre,int radius)249 inline void     DrawCircle(HDC hdc, Point centre, int radius)     { DrawCircle(hdc, centre.x, centre.y, radius); }
DrawEllipse(HDC hdc,const Rect & rc)250 inline void     DrawEllipse(HDC hdc, const Rect& rc)              { Ellipse(hdc, rc.left, rc.top, rc.right, rc.bottom); }
251 
DrawRect(HDC hdc,const Rect & rc)252 inline void     DrawRect(HDC hdc, const Rect& rc)                 { Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom); }
253 
254 HDC      ScreenHDC();
255 HPALETTE GetQlibPalette();
256 
257 Image Win32Icon(LPCSTR id, int iconsize = 0);
258 Image Win32Icon(int id, int iconsize = 0);
259 Image Win32Cursor(LPCSTR id);
260 Image Win32Cursor(int id);
261 HICON IconWin32(const Image& img, bool cursor = false);
262 Image Win32DllIcon(const char *dll, int ii, bool large);
263 
264 class BackDraw : public SystemDraw {
265 public:
266 	virtual bool  IsPaintingOp(const Rect& r) const;
267 
268 protected:
269 	HBITMAP hbmpold;
270 	HBITMAP hbmp;
271 
272 	Size    size;
273 	Draw   *painting;
274 	Point   painting_offset;
275 
276 public:
277 	void  Put(SystemDraw& w, int x, int y);
Put(SystemDraw & w,Point p)278 	void  Put(SystemDraw& w, Point p)                  { Put(w, p.x, p.y); }
279 
280 	void Create(SystemDraw& w, int cx, int cy);
Create(SystemDraw & w,Size sz)281 	void Create(SystemDraw& w, Size sz)                { Create(w, sz.cx, sz.cy); }
282 	void Destroy();
283 
SetPaintingDraw(Draw & w,Point off)284 	void SetPaintingDraw(Draw& w, Point off)           { painting = &w; painting_offset = off; }
285 
286 	BackDraw();
287 	~BackDraw();
288 };
289 
290 class ImageDraw : public SystemDraw {
291 	Size    size;
292 
293 	struct  Section {
294 		HDC     dc;
295 		HBITMAP hbmp, hbmpOld;
296 		RGBA   *pixels;
297 
298 		void Init(int cx, int cy);
299 		~Section();
300 	};
301 
302 	Section     rgb;
303 	Section     a;
304 	SystemDraw  alpha;
305 
306 
307 	bool    has_alpha;
308 
309 	void Init();
310 	Image Get(bool pm) const;
311 
312 public:
313 	Draw& Alpha();
314 
315 	operator Image() const;
316 
317 	Image GetStraight() const;
318 
319 	ImageDraw(Size sz);
320 	ImageDraw(int cx, int cy);
321 	~ImageDraw();
322 };
323 
324 END_UPP_NAMESPACE
325 
326 #define GUIPLATFORM_KEYCODES_INCLUDE "Win32Keys.h"
327 
328 
329 #define GUIPLATFORM_CTRL_TOP_DECLS \
330 	HWND           hwnd; \
331 	UDropTarget   *dndtgt; \
332 
333 
334 #define GUIPLATFORM_CTRL_DECLS_INCLUDE "Win32Ctrl.h"
335 
336 
337 #define GUIPLATFORM_PASTECLIP_DECLS \
338 	UDropTarget *dt; \
339 
340 #define GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE "Win32Top.h"
341 
342 NAMESPACE_UPP
343 
GetHashValue(const HWND & hwnd)344 inline unsigned GetHashValue(const HWND& hwnd)
345 {
346 	return (unsigned)(intptr_t)hwnd;
347 }
348 END_UPP_NAMESPACE
349 
350 #ifdef PLATFORM_WIN32
351 #ifndef PLATFORM_WINCE
352 
353 #include <ShellAPI.h>
354 
355 #endif
356 #endif
357 
358 #define GUIPLATFORM_INCLUDE_AFTER "Win32GuiA.h"
359