1 #ifndef CTRLCORE_H
2 #define CTRLCORE_H
3 
4 #include <RichText/RichText.h>
5 #include <Painter/Painter.h>
6 
7 #ifdef  flagNOGTK
8 #undef  flagGTK
9 #define flagX11
10 #endif
11 
12 #include <guiplatform.h>
13 
14 #ifndef GUIPLATFORM_INCLUDE
15 	#ifdef flagVIRTUALGUI
16 		#define VIRTUALGUI 1
17 	#endif
18 
19 	#ifdef flagTURTLE
20 		#define GUIPLATFORM_KEYCODES_INCLUDE <Turtle/Keys.h>
21 		//need to make SDL_keysym.h known before K_ enum
22 		#define GUIPLATFORM_INCLUDE          <Turtle/Turtle.h>
23 		#define GUIPLATFORM_NOSCROLL
24 		#define PLATFORM_TURTLE
25 		#define TURTLE
26 	#elif VIRTUALGUI
27 		#define GUIPLATFORM_KEYCODES_INCLUDE <VirtualGui/Keys.h>
28 		#define GUIPLATFORM_INCLUDE          <VirtualGui/VirtualGui.h>
29 	#elif PLATFORM_COCOA
30 		#define GUIPLATFORM_INCLUDE          "Coco.h"
31 		#define GUIPLATFORM_NOSCROLL
32 	#elif PLATFORM_WIN32
33 		#define GUIPLATFORM_INCLUDE "Win32Gui.h"
34 	#else
35 		#ifdef flagX11
36 			#define GUIPLATFORM_INCLUDE "X11Gui.h"
37 		#else
38 			#ifndef flagGTK
39 				#define flagGTK
40 			#endif
41 			#define GUIPLATFORM_INCLUDE "Gtk.h"
42 		#endif
43 	#endif
44 
45 #endif
46 
47 #define GUI_APP_MAIN_HOOK
48 
49 #include GUIPLATFORM_INCLUDE
50 
51 namespace Upp {
52 
53 INITIALIZE(CtrlCore)
54 
55 void EnterGuiMutex();
56 bool TryEnterGuiMutex();
57 void LeaveGuiMutex();
58 
59 int  LeaveGuiMutexAll();
60 void EnterGuiMutex(int n);
61 
62 bool ThreadHasGuiLock();
63 int  GetGuiLockLevel();
64 
65 struct GuiLock {
GuiLockGuiLock66 	GuiLock()  { EnterGuiMutex(); }
~GuiLockGuiLock67 	~GuiLock() { LeaveGuiMutex(); }
68 };
69 
70 class GuiUnlock {
71 	int n;
72 
73 public:
GuiUnlock()74 	GuiUnlock()  { n = LeaveGuiMutexAll(); }
~GuiUnlock()75 	~GuiUnlock() { EnterGuiMutex(n); }
76 };
77 
78 bool ScreenInPaletteMode(); // Deprecated
79 
80 typedef ImageDraw SystemImageDraw;
81 
82 void SetSurface(Draw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff);
83 void SetSurface(Draw& w, int x, int y, int cx, int cy, const RGBA *pixels);
84 
85 enum {
86 	K_DELTA        = 0x010000,
87 
88 	K_ALT          = 0x080000,
89 	K_SHIFT        = 0x040000,
90 	K_CTRL         = 0x020000,
91 
92 	K_KEYUP        = 0x100000,
93 
94 	K_MOUSEMIDDLE  = 0x200000,
95 	K_MOUSERIGHT   = 0x400000,
96 	K_MOUSELEFT    = 0x800000,
97 	K_MOUSEDOUBLE  = 0x1000000,
98 	K_MOUSETRIPLE  = 0x2000000,
99 
100 	K_SHIFT_CTRL = K_SHIFT|K_CTRL,
101 
102 #ifdef PLATFORM_COCOA
103 	K_OPTION       = 0x4000000,
104 #endif
105 
106 	IK_DBL_CLICK   = 0x40000001, // this is just to get the info that the entry is equal to dbl-click to the menu
107 };
108 
109 #include "MKeys.h"
110 
111 bool GetShift();
112 bool GetCtrl();
113 bool GetAlt();
114 bool GetCapsLock();
115 bool GetMouseLeft();
116 bool GetMouseRight();
117 bool GetMouseMiddle();
118 
119 #ifdef PLATFORM_COCOA
120 bool GetOption();
121 #endif
122 
123 enum {
124 	DELAY_MINIMAL = 0
125 };
126 
127 void  SetTimeCallback(int delay_ms, Function<void ()> cb, void *id = NULL); // delay_ms < 0 -> periodic
128 void  KillTimeCallback(void *id);
129 bool  ExistsTimeCallback(void *id);
130 dword GetTimeClick();
131 
132 inline
133 void  PostCallback(Function<void ()> cb, void *id = NULL)  { SetTimeCallback(1, cb, id); }
134 
135 class TimeCallback
136 {
137 public:
~TimeCallback()138 	~TimeCallback()                               { Kill(); (void)dummy; }
139 
Set(int delay,Function<void ()> cb)140 	void Set(int delay, Function<void ()> cb)     { UPP::SetTimeCallback(delay, cb, this); }
Post(Function<void ()> cb)141 	void Post(Function<void ()> cb)               { UPP::PostCallback(cb, this); }
Kill()142 	void Kill()                                   { UPP::KillTimeCallback(this); }
KillSet(int delay,Function<void ()> cb)143 	void KillSet(int delay, Function<void ()> cb) { Kill(); Set(delay, cb); }
KillPost(Function<void ()> cb)144 	void KillPost(Function<void ()> cb)           { Kill(); Post(cb); }
145 
146 private:
147 	byte dummy;
148 };
149 
150 class Ctrl;
151 
152 class CtrlFrame {
153 public:
154 	virtual void FrameLayout(Rect& r) = 0;
155 	virtual void FrameAddSize(Size& sz) = 0;
156 	virtual void FramePaint(Draw& w, const Rect& r);
157 	virtual void FrameAdd(Ctrl& parent);
158 	virtual void FrameRemove();
159 	virtual int  OverPaint() const;
160 
CtrlFrame()161 	CtrlFrame() {}
~CtrlFrame()162 	virtual ~CtrlFrame() {}
163 
164 private:
165 	CtrlFrame(const CtrlFrame&);
166 	void operator=(const CtrlFrame&);
167 };
168 
169 struct NullFrameClass : public CtrlFrame {
170 	virtual void FrameLayout(Rect& r);
171 	virtual void FramePaint(Draw& w, const Rect& r);
172 	virtual void FrameAddSize(Size& sz);
173 };
174 
175 CtrlFrame& NullFrame();
176 
177 class BorderFrame : public CtrlFrame {
178 public:
179 	virtual void FrameLayout(Rect& r);
180 	virtual void FramePaint(Draw& w, const Rect& r);
181 	virtual void FrameAddSize(Size& sz);
182 
183 protected:
184 	const ColorF *border;
185 
186 public:
BorderFrame(const ColorF * border)187 	BorderFrame(const ColorF *border) : border(border) {}
188 };
189 
190 CtrlFrame& InsetFrame();
191 CtrlFrame& OutsetFrame();
192 CtrlFrame& ButtonFrame();
193 CtrlFrame& ThinInsetFrame();
194 CtrlFrame& ThinOutsetFrame();
195 CtrlFrame& BlackFrame();
196 CtrlFrame& WhiteFrame();
197 
198 CtrlFrame& XPFieldFrame();
199 
200 CtrlFrame& FieldFrame();
201 // CtrlFrame& EditFieldFrame(); //TODO remove
202 
203 CtrlFrame& TopSeparatorFrame();
204 CtrlFrame& BottomSeparatorFrame();
205 CtrlFrame& LeftSeparatorFrame();
206 CtrlFrame& RightSeparatorFrame();
207 
208 void LayoutFrameLeft(Rect& r, Ctrl *ctrl, int cx);
209 void LayoutFrameRight(Rect& r, Ctrl *ctrl, int cx);
210 void LayoutFrameTop(Rect& r, Ctrl *ctrl, int cy);
211 void LayoutFrameBottom(Rect& r, Ctrl *ctrl, int cy);
212 
213 Point GetMousePos();
214 dword GetMouseFlags();
215 
216 #define IMAGECLASS CtrlCoreImg
217 #define IMAGEFILE <CtrlCore/CtrlCore.iml>
218 #include <Draw/iml_header.h>
219 
220 class TopWindow;
221 class TrayIcon;
222 class GLCtrl;
223 
224 enum {
225 	DND_NONE = 0,
226 	DND_COPY = 1,
227 	DND_MOVE = 2,
228 
229 	DND_ALL  = 3,
230 
231 	DND_EXACTIMAGE = 0x80000000,
232 };
233 
234 struct UDropTarget;
235 
236 struct ClipData : Moveable<ClipData> {
237 	Value  data;
238 	String (*render)(const Value& data);
239 
RenderClipData240 	String  Render() const                   { return render ? (*render)(data) : ~data; }
241 
242 	ClipData(const Value& data, String (*render)(const Value& data));
243 	ClipData(const String& data);
244 	ClipData();
245 };
246 
247 class PasteClip {
248 	friend struct UDropTarget;
249 	friend class  Ctrl;
250 	friend PasteClip sMakeDropClip(bool paste);
251 
252 	GUIPLATFORM_PASTECLIP_DECLS
253 
254 	byte         action;
255 	byte         allowed;
256 	bool         paste;
257 	bool         accepted;
258 	String       fmt;
259 	String       data;
260 
261 	void GuiPlatformConstruct();
262 
263 public:
264 	bool   IsAvailable(const char *fmt) const;
265 	String Get(const char *fmt) const;
266 
267 	bool   Accept();
268 
269 	bool   Accept(const char *fmt);
GetFormat()270 	String GetFormat()                  { return fmt; }
Get()271 	String Get() const                  { return data; }
String()272 	operator String() const             { return Get(); }
273 	String operator ~() const           { return Get(); }
274 
Reject()275 	void   Reject()                     { accepted = false; }
276 
GetAction()277 	int    GetAction() const            { return action; }
GetAllowedActions()278 	int    GetAllowedActions() const    { return allowed; }
SetAction(int x)279 	void   SetAction(int x)             { action = x; }
280 
IsAccepted()281 	bool   IsAccepted() const           { return accepted; }
282 
IsQuery()283 	bool   IsQuery() const              { return !paste; }
IsPaste()284 	bool   IsPaste() const              { return paste; }
285 
286 	PasteClip();
287 };
288 
289 String  Unicode__(const WString& w);
290 WString Unicode__(const String& s);
291 
292 void GuiPlatformAdjustDragImage(ImageBuffer& b);
293 
294 Image MakeDragImage(const Image& arrow, Image sample);
295 
296 const char *ClipFmtsText();
297 bool        AcceptText	(PasteClip& clip);
298 String      GetString(PasteClip& clip);
299 WString     GetWString(PasteClip& clip);
300 String      GetTextClip(const String& text, const String& fmt);
301 String      GetTextClip(const WString& text, const String& fmt);
302 void        Append(VectorMap<String, ClipData>& data, const String& text);
303 void        Append(VectorMap<String, ClipData>& data, const WString& text);
304 
305 const char *ClipFmtsImage();
306 bool        AcceptImage(PasteClip& clip);
307 Image       GetImage(PasteClip& clip);
308 String      GetImageClip(const Image& m, const String& fmt);
309 void        Append(VectorMap<String, ClipData>& data, const Image& img);
310 
311 bool            IsAvailableFiles(PasteClip& clip);
312 bool            AcceptFiles(PasteClip& clip);
313 Vector<String>  GetClipFiles(const String& data);
314 Vector<String>  GetFiles(PasteClip& clip);
315 void            AppendFiles(VectorMap<String, ClipData>& data, const Vector<String>& files);
316 
317 template <class T>
ClipFmt()318 String ClipFmt()
319 {
320 	return String("U++ type: ") + typeid(T).name();
321 }
322 
323 template <class T>
Accept(PasteClip & clip)324 bool   Accept(PasteClip& clip)
325 {
326 	return clip.Accept(ClipFmt<T>());
327 }
328 
329 String GetInternalDropId__(const char *type, const char *id);
330 void NewInternalDrop__(const void *ptr);
331 const void *GetInternalDropPtr__();
332 
333 template <class T>
334 VectorMap<String, ClipData> InternalClip(const T& x, const char *id = "")
335 {
336 	NewInternalDrop__(&x);
337 	VectorMap<String, ClipData> d;
338 	d.Add(GetInternalDropId__(typeid(T).name(), id));
339 	return d;
340 }
341 
342 template <class T>
343 bool IsAvailableInternal(PasteClip& d, const char *id = "")
344 {
345 	return d.IsAvailable(GetInternalDropId__(typeid(T).name(), id));
346 }
347 
348 template <class T>
349 bool AcceptInternal(PasteClip& d, const char *id = "")
350 {
351 	return d.Accept(GetInternalDropId__(typeid(T).name(), id));
352 }
353 
354 template <class T>
GetInternal(PasteClip & d)355 const T& GetInternal(PasteClip& d)
356 {
357 	return *(T *)GetInternalDropPtr__();
358 }
359 
360 template <class T>
361 const T *GetInternalPtr(PasteClip& d, const char *id = "")
362 {
363 	return IsAvailableInternal<T>(d, id) ? (T *)GetInternalDropPtr__() : NULL;
364 }
365 
366 class Ctrl : public Pte<Ctrl> {
367 public:
368 	enum PlacementConstants {
369 		CENTER   = 0,
370 		MIDDLE   = 0,
371 		LEFT     = 1,
372 		RIGHT    = 2,
373 		TOP      = 1,
374 		BOTTOM   = 2,
375 		SIZE     = 3,
376 
377 		MINSIZE  = -16380,
378 		MAXSIZE  = -16381,
379 		STDSIZE  = -16382,
380 	};
381 
382 	class Logc {
383 		dword data;
384 
LSGN(dword d)385 		static int LSGN(dword d)       { return int16((d & 0x7fff) | ((d & 0x4000) << 1)); }
386 
387 	public:
388 		bool  operator==(Logc q) const { return data == q.data; }
389 		bool  operator!=(Logc q) const { return data != q.data; }
GetAlign()390 		int   GetAlign() const         { return (data >> 30) & 3; }
GetA()391 		int   GetA() const             { return LSGN(data >> 15); }
GetB()392 		int   GetB() const             { return LSGN(data); }
SetAlign(int align)393 		void  SetAlign(int align)      { data = (data & ~(3 << 30)) | (align << 30); }
SetA(int a)394 		void  SetA(int a)              { data = (data & ~(0x7fff << 15)) | ((a & 0x7fff) << 15); }
SetB(int b)395 		void  SetB(int b)              { data = (data & ~0x7fff) | (b & 0x7fff); }
396 		bool  IsEmpty() const;
397 
Logc(int al,int a,int b)398 		Logc(int al, int a, int b)     { data = (al << 30) | ((a & 0x7fff) << 15) | (b & 0x7fff); }
Logc()399 		Logc()                         { data = 0xffffffff; }
400 	};
401 
402 	struct LogPos : Moveable<LogPos> {
403 		Logc x, y;
404 
405 		bool operator==(LogPos b) const   { return x == b.x && y == b.y; }
406 		bool operator!=(LogPos b) const   { return !(*this == b); }
407 
LogPosLogPos408 		LogPos(Logc x, Logc y)            : x(x), y(y) {}
LogPosLogPos409 		LogPos()                          {}
410 	};
411 
PosLeft(int pos,int size)412 	static Logc PosLeft(int pos, int size)       { return Logc(LEFT, pos, size); }
PosRight(int pos,int size)413 	static Logc PosRight(int pos, int size)      { return Logc(RIGHT, pos, size); }
PosTop(int pos,int size)414 	static Logc PosTop(int pos, int size)        { return Logc(TOP, pos, size); }
PosBottom(int pos,int size)415 	static Logc PosBottom(int pos, int size)     { return Logc(BOTTOM, pos, size); }
PosSize(int lpos,int rpos)416 	static Logc PosSize(int lpos, int rpos)      { return Logc(SIZE, lpos, rpos); }
PosCenter(int size,int offset)417 	static Logc PosCenter(int size, int offset)  { return Logc(CENTER, offset, size); }
PosCenter(int size)418 	static Logc PosCenter(int size)              { return Logc(CENTER, 0, size); }
419 
420 	typedef bool (*MouseHook)(Ctrl *ctrl, bool inframe, int event, Point p,
421 	                          int zdelta, dword keyflags);
422 	typedef bool (*KeyHook)(Ctrl *ctrl, dword key, int count);
423 	typedef bool (*StateHook)(Ctrl *ctrl, int reason);
424 
425 	static dword KEYtoK(dword);
426 
427 private:
428 	Ctrl(Ctrl&);
429 	void operator=(Ctrl&);
430 
431 private:
432 	struct Frame : Moveable<Frame> {
433 		CtrlFrame *frame;
434 		Rect16     view;
435 
FrameFrame436 		Frame()    { view.Clear(); }
437 	};
438 	Ctrl        *parent;
439 
440 	struct Scroll : Moveable<Scroll> {
441 		Rect rect;
442 		int  dx;
443 		int  dy;
444 	};
445 
446 	struct MoveCtrl : Moveable<MoveCtrl> {
447 		Ptr<Ctrl>  ctrl;
448 		Rect       from;
449 		Rect       to;
450 	};
451 
452 	friend struct UDropTarget;
453 
454 	struct Top {
455 		GUIPLATFORM_CTRL_TOP_DECLS
456 		Vector<Scroll> scroll;
457 		VectorMap<Ctrl *, MoveCtrl> move;
458 		VectorMap<Ctrl *, MoveCtrl> scroll_move;
459 		Ptr<Ctrl>      owner;
460 	};
461 
462 	Top         *top;
463 	int          exitcode;
464 
465 	Ctrl        *prev, *next;
466 	Ctrl        *firstchild, *lastchild;//16
467 	LogPos       pos;//8
468 	Rect16       rect;
469 	Mitor<Frame> frame;//16
470 	String       info;//16
471 	int16        caretx, carety, caretcx, caretcy;//8
472 
473 	byte         overpaint;
474 
475 	bool         unicode:1;
476 
477 	bool         fullrefresh:1;
478 
479 	bool         transparent:1;
480 	bool         visible:1;
481 	bool         enabled:1;
482 	bool         wantfocus:1;
483 	bool         initfocus:1;
484 	bool         activepopup:1;
485 	bool         editable:1;
486 	bool         modify:1;
487 	bool         ignoremouse:1;
488 	bool         inframe:1;
489 	bool         inloop:1;
490 	bool         isopen:1;
491 	bool         popup:1;
492 	bool         popupgrab:1;
493 	byte         backpaint:2;//2
494 
495 	bool         akv:1;
496 	bool         destroying:1;
497 
498 	static  Ptr<Ctrl> eventCtrl;
499 	static  Ptr<Ctrl> mouseCtrl;
500 	static  Point     mousepos;
501 	static  Point     leftmousepos, rightmousepos, middlemousepos;
502 	static  Ptr<Ctrl> focusCtrl;
503 	static  Ptr<Ctrl> focusCtrlWnd;
504 	static  Ptr<Ctrl> lastActiveWnd;
505 	static  Ptr<Ctrl> caretCtrl;
506 	static  Rect      caretRect;
507 	static  Ptr<Ctrl> captureCtrl;
508 	static  bool      ignoreclick;
509 	static  bool      ignoremouseup;
510 	static  bool      ignorekeyup;
511 	static  bool      mouseinview;
512 	static  bool      mouseinframe;
513 	static  bool      globalbackpaint;
514 	static  bool      globalbackbuffer;
515 	static  bool      painting;
516 	static  int       LoopLevel;
517 	static  Ctrl     *LoopCtrl;
518 	static  int64     EventLoopNo;
519 	static  int64     EndSessionLoopNo;
520 	static  int64     eventid;
521 
522 	static  Ptr<Ctrl>           defferedSetFocus;
523 	static  Vector< Ptr<Ctrl> > defferedChildLostFocus;
524 
525 	static  Ptr<Ctrl> repeatTopCtrl;
526 	static  Point     repeatMousePos;
527 
528 	static  Vector<MouseHook>& mousehook();
529 	static  Vector<KeyHook>&   keyhook();
530 	static  Vector<StateHook>& statehook();
531 
FocusCtrl()532 	static Ptr<Ctrl> FocusCtrl() { return focusCtrl; }
FocusCtrl(Ptr<Ctrl> fc)533 	static void      FocusCtrl(Ptr<Ctrl> fc) { focusCtrl = fc; }
534 
535 	void    StateDeep(int state);
536 
537 	void    RemoveChild0(Ctrl *q);
538 
539 	static int       FindMoveCtrl(const VectorMap<Ctrl *, MoveCtrl>& m, Ctrl *x);
540 	static MoveCtrl *FindMoveCtrlPtr(VectorMap<Ctrl *, MoveCtrl>& m, Ctrl *x);
541 
542 	Size    PosVal(int v) const;
543 	void    Lay1(int& pos, int& r, int align, int a, int b, int sz) const;
544 	Rect    CalcRect(LogPos pos, const Rect& prect, const Rect& pview) const;
545 	Rect    CalcRect(const Rect& prect, const Rect& pview) const;
546 	void    UpdateRect0(bool sync = true);
547 	void    UpdateRect(bool sync = true);
548 	void    SetPos0(LogPos p, bool inframe);
549 	void    SetWndRect(const Rect& r);
550 	void    SyncMoves();
551 
552 	static  void  EndIgnore();
553 	static  void  LRep();
554 	static  void  LHold();
555 	static  void  LRepeat();
556 	static  void  RRep();
557 	static  void  RHold();
558 	static  void  RRepeat();
559 	static  void  MRep();
560 	static  void  MHold();
561 	static  void  MRepeat();
562 	static  void  KillRepeat();
563 	static  void  CheckMouseCtrl();
564 	static  void  DoCursorShape();
565 	static  Image& CursorOverride();
566 	bool    IsMouseActive() const;
567 	Image   MouseEvent0(int event, Point p, int zdelta, dword keyflags);
568 	Image   MouseEventH(int event, Point p, int zdelta, dword keyflags);
569 	Image   FrameMouseEventH(int event, Point p, int zdelta, dword keyflags);
570 	Image   MEvent0(int e, Point p, int zd);
571 	Image   DispatchMouse(int e, Point p, int zd = 0);
572 	Image   DispatchMouseEvent(int e, Point p, int zd = 0);
573 	void    LogMouseEvent(const char *f, const Ctrl *ctrl, int event, Point p, int zdelta, dword keyflags);
574 
575 	struct CallBox;
576 	static void PerformCall(CallBox *cbox);
577 
578 	void    StateH(int reason);
579 
580 	void    RefreshAccessKeys();
581 	void    RefreshAccessKeysDo(bool vis);
582 	static  void  DefferedFocusSync();
583 	static  void  SyncCaret();
584 	static  void  RefreshCaret();
585 	static  bool  DispatchKey(dword keycode, int count);
586 	void    SetFocusWnd();
587 	void    KillFocusWnd();
588 
589 	static Ptr<Ctrl> dndctrl;
590 	static Point     dndpos;
591 	static bool      dndframe;
592 	static PasteClip dndclip;
593 
594 	void    DnD(Point p, PasteClip& clip);
595 	static void DnDRepeat();
596 	static void DnDLeave();
597 
598 	void    SyncLayout(int force = 0);
599 	bool    AddScroll(const Rect& sr, int dx, int dy);
600 	Rect    GetClippedView();
601 	void    ScrollRefresh(const Rect& r, int dx, int dy);
602 	void    ScrollCtrl(Top *top, Ctrl *q, const Rect& r, Rect cr, int dx, int dy);
603 	void    SyncScroll();
604 	void    Refresh0(const Rect& area);
605 	void    PaintCaret(SystemDraw& w);
606 	void    CtrlPaint(SystemDraw& w, const Rect& clip);
607 	void    RemoveFullRefresh();
608 	bool    PaintOpaqueAreas(SystemDraw& w, const Rect& r, const Rect& clip, bool nochild = false);
609 	void    GatherTransparentAreas(Vector<Rect>& area, SystemDraw& w, Rect r, const Rect& clip);
610 	Ctrl   *FindBestOpaque(const Rect& clip);
611 	void    ExcludeDHCtrls(SystemDraw& w, const Rect& r, const Rect& clip);
612 	void    UpdateArea0(SystemDraw& draw, const Rect& clip, int backpaint);
613 	void    UpdateArea(SystemDraw& draw, const Rect& clip);
614 	Ctrl   *GetTopRect(Rect& r, bool inframe, bool clip = true);
615 	void    DoSync(Ctrl *q, Rect r, bool inframe);
616 	void    SetInfoPart(int i, const char *txt);
617 	String  GetInfoPart(int i) const;
618 
619 // System window interface...
620 	void WndShow(bool b);
621 	void WndSetPos(const Rect& rect);
622 
623 	bool IsWndOpen() const;
624 
625 	bool SetWndCapture();
626 	bool HasWndCapture() const;
627 	bool ReleaseWndCapture();
628 
629 	static void SetMouseCursor(const Image& m);
630 
631 	static void DoDeactivate(Ptr<Ctrl> pfocusCtrl, Ptr<Ctrl> nfocusCtrl);
632 	static void DoKillFocus(Ptr<Ctrl> pfocusCtrl, Ptr<Ctrl> nfocusCtrl);
633 	static void DoSetFocus(Ptr<Ctrl> pfocusCtrl, Ptr<Ctrl> nfocusCtrl, bool activate);
634 
635 	bool SetFocus0(bool activate);
636 	void ActivateWnd();
637 	void ClickActivateWnd();
638 	bool SetWndFocus();
639 	bool HasWndFocus() const;
640 
641 	void WndInvalidateRect(const Rect& r);
642 
643 	void WndScrollView(const Rect& r, int dx, int dy);
644 
645 	void SetWndForeground();
646 	bool IsWndForeground() const;
647 
648 	void WndEnable(bool b);
649 
650 	Rect GetWndScreenRect() const;
651 
652 	void WndUpdate();
653 	void WndUpdate(const Rect& r);
654 
655 	void WndFree();
656 	void WndDestroy();
657 
658 	void SysEndLoop();
659 
660 	String Name0() const;
661 
662 	static void InitTimer();
663 
664 	static String appname;
665 
666 	static Size Bsize;
667 	static Size Dsize;
668 	static Size Csize;
669 	static bool IsNoLayoutZoom;
670 	static void Csizeinit();
671 	static void (*skin)();
672 
673 	friend void  InitRichTextZoom();
674 	friend void  AvoidPaintingCheck__();
675 	friend dword GetKeyStateSafe(dword what);
676 	friend void  CtrlSetDefaultSkin(void (*_skin)());
677 	friend class DHCtrl;
678 	friend class TopFrameDraw;
679 	friend class ViewDraw;
680 	friend class TopWindow;
681 	friend class TrayIcon;
682 	friend class GLCtrl;
683 	friend class WaitCursor;
684 	friend struct UDropSource;
685 	friend class DnDAction;
686 	friend class PasteClip;
687 
688 	typedef Ctrl CLASSNAME;
689 
690 	void        GuiPlatformConstruct();
691 	void        GuiPlatformDestruct();
692 	void        GuiPlatformRemove();
693 	void        GuiPlatformGetTopRect(Rect& r) const;
694 	bool        GuiPlatformRefreshFrameSpecial(const Rect& r);
695 	bool        GuiPlatformSetFullRefreshSpecial();
696 	static void GuiPlatformSelection(PasteClip& d);
697 
698 #ifdef GUIPLATFORM_CTRL_DECLS_INCLUDE
699 	#include GUIPLATFORM_CTRL_DECLS_INCLUDE
700 #else
701 	GUIPLATFORM_CTRL_DECLS
702 #endif
703 
704 	static void InstallPanicBox();
705 
706 	bool IsDHCtrl() const;
707 
708 private:
709 			void    DoRemove();
710 
711 protected:
712 	static void     TimerProc(dword time);
713 
Unicode()714 			Ctrl&   Unicode()                         { unicode = true; return *this; }
715 
716 public:
717 	enum StateReason {
718 		FOCUS      = 10,
719 		ACTIVATE   = 11,
720 		DEACTIVATE = 12,
721 		SHOW       = 13,
722 		ENABLE     = 14,
723 		EDITABLE   = 15,
724 		OPEN       = 16,
725 		CLOSE      = 17,
726 		POSITION   = 100,
727 		LAYOUTPOS  = 101,
728 	};
729 
730 	enum MouseEvents {
731 		BUTTON        = 0x0F,
732 		ACTION        = 0xF0,
733 
734 		MOUSEENTER    = 0x10,
735 		MOUSEMOVE     = 0x20,
736 		MOUSELEAVE    = 0x30,
737 		CURSORIMAGE   = 0x40,
738 		MOUSEWHEEL    = 0x50,
739 
740 		DOWN          = 0x80,
741 		UP            = 0x90,
742 		DOUBLE        = 0xa0,
743 		REPEAT        = 0xb0,
744 		DRAG          = 0xc0,
745 		HOLD          = 0xd0,
746 		TRIPLE        = 0xe0,
747 
748 		LEFTDOWN      = LEFT|DOWN,
749 		LEFTDOUBLE    = LEFT|DOUBLE,
750 		LEFTREPEAT    = LEFT|REPEAT,
751 		LEFTUP        = LEFT|UP,
752 		LEFTDRAG      = LEFT|DRAG,
753 		LEFTHOLD      = LEFT|HOLD,
754 		LEFTTRIPLE    = LEFT|TRIPLE,
755 
756 		RIGHTDOWN     = RIGHT|DOWN,
757 		RIGHTDOUBLE   = RIGHT|DOUBLE,
758 		RIGHTREPEAT   = RIGHT|REPEAT,
759 		RIGHTUP       = RIGHT|UP,
760 		RIGHTDRAG     = RIGHT|DRAG,
761 		RIGHTHOLD     = RIGHT|HOLD,
762 		RIGHTTRIPLE   = RIGHT|TRIPLE,
763 
764 		MIDDLEDOWN     = MIDDLE|DOWN,
765 		MIDDLEDOUBLE   = MIDDLE|DOUBLE,
766 		MIDDLEREPEAT   = MIDDLE|REPEAT,
767 		MIDDLEUP       = MIDDLE|UP,
768 		MIDDLEDRAG     = MIDDLE|DRAG,
769 		MIDDLEHOLD     = MIDDLE|HOLD,
770 		MIDDLETRIPLE   = MIDDLE|TRIPLE
771 	};
772 
773 	enum {
774 		NOBACKPAINT,
775 		FULLBACKPAINT,
776 		TRANSPARENTBACKPAINT,
777 		EXCLUDEPAINT,
778 	};
779 
780 	static  Vector<Ctrl *> GetTopCtrls();
781 	static  Vector<Ctrl *> GetTopWindows();
782 	static  void   CloseTopCtrls();
783 
784 	static  void   InstallMouseHook(MouseHook hook);
785 	static  void   DeinstallMouseHook(MouseHook hook);
786 
787 	static  void   InstallKeyHook(KeyHook hook);
788 	static  void   DeinstallKeyHook(KeyHook hook);
789 
790 	static  void   InstallStateHook(StateHook hook);
791 	static  void   DeinstallStateHook(StateHook hook);
792 
793 	static  int    RegisterSystemHotKey(dword key, Function<void ()> cb);
794 	static  void   UnregisterSystemHotKey(int id);
795 
796 	virtual bool   Accept();
797 	virtual void   Reject();
798 	virtual void   SetData(const Value& data);
799 	virtual Value  GetData() const;
800 	virtual void   Serialize(Stream& s);
801 	virtual void   Jsonize(JsonIO& jio);
802 	virtual void   Xmlize(XmlIO& xio);
803 	virtual void   SetModify();
804 	virtual void   ClearModify();
805 	virtual bool   IsModified() const;
806 
807 	virtual void   Paint(Draw& w);
808 	virtual int    OverPaint() const;
809 
810 	virtual void   CancelMode();
811 
812 	virtual void   Activate();
813 	virtual void   Deactivate();
814 	virtual void   DeactivateBy(Ctrl *new_focus);
815 
816 	virtual Image  FrameMouseEvent(int event, Point p, int zdelta, dword keyflags);
817 	virtual Image  MouseEvent(int event, Point p, int zdelta, dword keyflags);
818 	virtual void   MouseEnter(Point p, dword keyflags);
819 	virtual void   MouseMove(Point p, dword keyflags);
820 	virtual void   LeftDown(Point p, dword keyflags);
821 	virtual void   LeftDouble(Point p, dword keyflags);
822 	virtual void   LeftTriple(Point p, dword keyflags);
823 	virtual void   LeftRepeat(Point p, dword keyflags);
824 	virtual void   LeftDrag(Point p, dword keyflags);
825 	virtual void   LeftHold(Point p, dword keyflags);
826 	virtual void   LeftUp(Point p, dword keyflags);
827 	virtual void   RightDown(Point p, dword keyflags);
828 	virtual void   RightDouble(Point p, dword keyflags);
829 	virtual void   RightTriple(Point p, dword keyflags);
830 	virtual void   RightRepeat(Point p, dword keyflags);
831 	virtual void   RightDrag(Point p, dword keyflags);
832 	virtual void   RightHold(Point p, dword keyflags);
833 	virtual void   RightUp(Point p, dword keyflags);
834 	virtual void   MiddleDown(Point p, dword keyflags);
835 	virtual void   MiddleDouble(Point p, dword keyflags);
836 	virtual void   MiddleTriple(Point p, dword keyflags);
837 	virtual void   MiddleRepeat(Point p, dword keyflags);
838 	virtual void   MiddleDrag(Point p, dword keyflags);
839 	virtual void   MiddleHold(Point p, dword keyflags);
840 	virtual void   MiddleUp(Point p, dword keyflags);
841 	virtual void   MouseWheel(Point p, int zdelta, dword keyflags);
842 	virtual void   MouseLeave();
843 
844 	virtual void   DragAndDrop(Point p, PasteClip& d);
845 	virtual void   FrameDragAndDrop(Point p, PasteClip& d);
846 	virtual void   DragRepeat(Point p);
847 	virtual void   DragEnter();
848 	virtual void   DragLeave();
849 	virtual String GetDropData(const String& fmt) const;
850 	virtual String GetSelectionData(const String& fmt) const;
851 
852 	virtual Image  CursorImage(Point p, dword keyflags);
853 
854 	virtual bool   Key(dword key, int count);
855 	virtual void   GotFocus();
856 	virtual void   LostFocus();
857 	virtual bool   HotKey(dword key);
858 
859 	virtual dword  GetAccessKeys() const;
860 	virtual void   AssignAccessKeys(dword used);
861 
862 	virtual void   PostInput(); // Deprecated
863 
864 	virtual void   ChildFrameMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags);
865 	virtual void   ChildMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags);
866 	virtual void   ChildGotFocus();
867 	virtual void   ChildLostFocus();
868 	virtual void   ChildAdded(Ctrl *child);
869 	virtual void   ChildRemoved(Ctrl *child);
870 	virtual void   ParentChange();
871 
872 	virtual void   State(int reason);
873 
874 	virtual void   Layout();
875 
876 	virtual Size   GetMinSize() const;
877 	virtual Size   GetStdSize() const;
878 	virtual Size   GetMaxSize() const;
879 
880 	virtual bool   IsShowEnabled() const;
881 
882 	virtual Rect   GetOpaqueRect() const;
883 	virtual Rect   GetVoidRect() const ;
884 
885 	virtual void   Updated();
886 
887 	virtual void   Close();
888 
889 	virtual bool   IsOcxChild();
890 
891 	virtual String GetDesc() const;
892 
SetMinSize(Size sz)893 	virtual void   SetMinSize(Size sz) {}
894 
895 	Event<>          WhenAction;
896 
897 	void             AddChild(Ctrl *child);
898 	void             AddChild(Ctrl *child, Ctrl *insafter);
899 	void             AddChildBefore(Ctrl *child, Ctrl *insbefore);
900 	void             RemoveChild(Ctrl *child);
GetParent()901 	Ctrl            *GetParent() const           { return parent; }
GetLastChild()902 	Ctrl            *GetLastChild() const        { return lastchild; }
GetFirstChild()903 	Ctrl            *GetFirstChild() const       { return firstchild; }
GetPrev()904 	Ctrl            *GetPrev() const             { return parent ? prev : NULL; }
GetNext()905 	Ctrl            *GetNext() const             { return parent ? next : NULL; }
906 	int              GetChildIndex(const Ctrl *child) const;
907 	Ctrl            *GetIndexChild(int i) const;
908 	int              GetChildCount() const;
909 	template <class T>
910 	T               *GetAscendant() const;
911 
912 	int              GetViewChildIndex(const Ctrl *child) const;
913 	int              GetViewChildCount() const;
914 	Ctrl            *GetViewIndexChild(int ii) const;
915 
IsChild()916 	bool             IsChild() const             { return parent; }
917 
918 	Ctrl            *ChildFromPoint(Point& pt) const;
919 
920 	bool             IsForeground() const;
921 	void             SetForeground();
922 
923 	const Ctrl      *GetTopCtrl() const;
924 	Ctrl            *GetTopCtrl();
925 	const Ctrl      *GetOwner() const;
926 	Ctrl            *GetOwner();
927 	const Ctrl      *GetTopCtrlOwner() const;
928 	Ctrl            *GetTopCtrlOwner();
929 
930 	Ctrl            *GetOwnerCtrl();
931 	const Ctrl      *GetOwnerCtrl() const;
932 
933 	const TopWindow *GetTopWindow() const;
934 	TopWindow       *GetTopWindow();
935 
936 	const TopWindow *GetMainWindow() const;
937 	TopWindow       *GetMainWindow();
938 
939 	Ctrl&            SetFrame(int i, CtrlFrame& frm);
SetFrame(CtrlFrame & frm)940 	Ctrl&            SetFrame(CtrlFrame& frm)            { return SetFrame(0, frm); }
941 	Ctrl&            AddFrame(CtrlFrame& frm);
942 	const CtrlFrame& GetFrame(int i = 0) const           { return *frame[i].frame; }
943 	CtrlFrame&       GetFrame(int i = 0)                 { return *frame[i].frame; }
944 	void             RemoveFrame(int i);
945 	void             RemoveFrame(CtrlFrame& frm);
946 	void             InsertFrame(int i, CtrlFrame& frm);
947 	int              FindFrame(CtrlFrame& frm);
GetFrameCount()948 	int              GetFrameCount() const               { return frame.GetCount(); }
949 	void             ClearFrames();
950 
951 	bool        IsOpen() const;
952 
Shutdown()953 	void        Shutdown()                               { destroying = true; }
IsShutdown()954 	bool        IsShutdown() const                       { return destroying; }
955 
956 	Ctrl&       SetPos(LogPos p, bool inframe);
957 
958 	Ctrl&       SetPos(LogPos p);
SetPos(Logc x,Logc y)959 	Ctrl&       SetPos(Logc x, Logc y)                   { return SetPos(LogPos(x, y)); }
960 	Ctrl&       SetPosX(Logc x);
961 	Ctrl&       SetPosY(Logc y);
962 
963 	void        SetRect(const Rect& r);
964 	void        SetRect(int x, int y, int cx, int cy);
965 	void        SetRectX(int x, int cx);
966 	void        SetRectY(int y, int cy);
967 
968 	Ctrl&       SetFramePos(LogPos p);
SetFramePos(Logc x,Logc y)969 	Ctrl&       SetFramePos(Logc x, Logc y)              { return SetFramePos(LogPos(x, y)); }
970 	Ctrl&       SetFramePosX(Logc x);
971 	Ctrl&       SetFramePosY(Logc y);
972 
973 	void        SetFrameRect(const Rect& r);
974 	void        SetFrameRect(int x, int y, int cx, int cy);
975 	void        SetFrameRectX(int x, int cx);
976 	void        SetFrameRectY(int y, int cy);
977 
InFrame()978 	bool        InFrame() const                          { return inframe; }
InView()979 	bool        InView() const                           { return !inframe; }
GetPos()980 	LogPos      GetPos() const                           { return pos; }
981 
RefreshLayout()982 	void        RefreshLayout()                          { SyncLayout(1); }
RefreshLayoutDeep()983 	void        RefreshLayoutDeep()                      { SyncLayout(2); }
RefreshParentLayout()984 	void        RefreshParentLayout()                    { if(parent) parent->RefreshLayout(); }
985 
UpdateLayout()986 	void        UpdateLayout()                           { SyncLayout(); }
UpdateParentLayout()987 	void        UpdateParentLayout()                     { if(parent) parent->UpdateLayout(); }
988 
989 	Ctrl&       LeftPos(int a, int size = STDSIZE);
990 	Ctrl&       RightPos(int a, int size = STDSIZE);
991 	Ctrl&       TopPos(int a, int size = STDSIZE);
992 	Ctrl&       BottomPos(int a, int size = STDSIZE);
993 	Ctrl&       HSizePos(int a = 0, int b = 0);
994 	Ctrl&       VSizePos(int a = 0, int b = 0);
995 	Ctrl&       SizePos();
996 	Ctrl&       HCenterPos(int size = STDSIZE, int delta = 0);
997 	Ctrl&       VCenterPos(int size = STDSIZE, int delta = 0);
998 
999 	Ctrl&       LeftPosZ(int a, int size = STDSIZE);
1000 	Ctrl&       RightPosZ(int a, int size = STDSIZE);
1001 	Ctrl&       TopPosZ(int a, int size = STDSIZE);
1002 	Ctrl&       BottomPosZ(int a, int size = STDSIZE);
1003 	Ctrl&       HSizePosZ(int a = 0, int b = 0);
1004 	Ctrl&       VSizePosZ(int a = 0, int b = 0);
1005 	Ctrl&       HCenterPosZ(int size = STDSIZE, int delta = 0);
1006 	Ctrl&       VCenterPosZ(int size = STDSIZE, int delta = 0);
1007 
1008 	Rect        GetRect() const;
1009 	Rect        GetScreenRect() const;
1010 
1011 	Rect        GetView() const;
1012 	Rect        GetScreenView() const;
1013 	Size        GetSize() const;
1014 
1015 	Rect        GetVisibleScreenRect() const;
1016 	Rect        GetVisibleScreenView() const;
1017 
1018 	Rect        GetWorkArea() const;
1019 
1020 	Size        AddFrameSize(int cx, int cy) const;
AddFrameSize(Size sz)1021 	Size        AddFrameSize(Size sz) const              { return AddFrameSize(sz.cx, sz.cy); }
1022 
1023 	void        Refresh(const Rect& r);
1024 	void        Refresh(int x, int y, int cx, int cy);
1025 	void        Refresh();
IsFullRefresh()1026 	bool        IsFullRefresh() const                    { return fullrefresh; }
1027 
1028 	void        RefreshFrame(const Rect& r);
1029 	void        RefreshFrame(int x, int y, int cx, int cy);
1030 	void        RefreshFrame();
1031 
IsPainting()1032 	static bool IsPainting()                             { return painting; }
1033 
1034 	void        ScrollView(const Rect& r, int dx, int dy);
1035 	void        ScrollView(int x, int y, int cx, int cy, int dx, int dy);
1036 	void        ScrollView(int dx, int dy);
ScrollView(const Rect & r,Size delta)1037 	void        ScrollView(const Rect& r, Size delta)    { ScrollView(r, delta.cx, delta.cy); }
ScrollView(Size delta)1038 	void        ScrollView(Size delta)                   { ScrollView(delta.cx, delta.cy); }
1039 
1040 	void        Sync();
1041 	void        Sync(const Rect& r);
1042 
1043 	static Image OverrideCursor(const Image& m);
1044 
1045 	void        DrawCtrl(Draw& w, int x = 0, int y = 0);
1046 	void        DrawCtrlWithParent(Draw& w, int x = 0, int y = 0);
1047 
1048 	bool    HasChild(Ctrl *ctrl) const;
1049 	bool    HasChildDeep(Ctrl *ctrl) const;
1050 
1051 	Ctrl&   IgnoreMouse(bool b = true)                   { ignoremouse = b; return *this; }
NoIgnoreMouse()1052 	Ctrl&   NoIgnoreMouse()                              { return IgnoreMouse(false); }
IsIgnoreMouse()1053 	bool    IsIgnoreMouse() const                        { return ignoremouse; }
1054 	bool    HasMouse() const;
1055 	bool    HasMouseDeep() const;
1056 	bool    HasMouseInFrame(const Rect& r) const;
1057 	bool    HasMouseIn(const Rect& r) const;
1058 	Point   GetMouseViewPos() const;
1059 	static Ctrl *GetMouseCtrl();
1060 
1061 	static void IgnoreMouseClick();
1062 	static void IgnoreMouseUp();
1063 	static void UnIgnoreMouse();
1064 
1065 	bool    SetCapture();
1066 	bool    ReleaseCapture();
1067 	bool    HasCapture() const;
1068 	static bool  ReleaseCtrlCapture();
1069 	static Ctrl *GetCaptureCtrl();
1070 
1071 	bool    SetFocus();
HasFocus()1072 	bool    HasFocus() const                   { return FocusCtrl() == this; }
1073 	bool    HasFocusDeep() const;
1074 	Ctrl&   WantFocus(bool ft = true)          { wantfocus = ft; return *this; }
NoWantFocus()1075 	Ctrl&   NoWantFocus()                      { return WantFocus(false); }
IsWantFocus()1076 	bool	IsWantFocus() const                { return wantfocus; }
1077 	bool    SetWantFocus();
1078 	Ctrl&   InitFocus(bool ft = true)          { initfocus = ft; return *this; }
NoInitFocus()1079 	Ctrl&   NoInitFocus()                      { return InitFocus(false); }
IsInitFocus()1080 	bool    IsInitFocus() const                { return initfocus; }
GetFocusChild()1081 	Ctrl   *GetFocusChild() const              { return HasChild(FocusCtrl()) ? ~FocusCtrl() : NULL; }
GetFocusChildDeep()1082 	Ctrl   *GetFocusChildDeep() const          { return HasChildDeep(FocusCtrl()) ? ~FocusCtrl() : NULL; }
1083 
1084 	void    CancelModeDeep();
1085 
1086 	void    SetCaret(int x, int y, int cx, int cy);
1087 	void    SetCaret(const Rect& r);
1088 	Rect    GetCaret() const;
1089 	void    KillCaret();
1090 
GetFocusCtrl()1091 	static Ctrl *GetFocusCtrl()                { return FocusCtrl(); }
1092 
GetEventTopCtrl()1093 	static Ctrl *GetEventTopCtrl()             { return eventCtrl; }
1094 
1095 	static bool  IterateFocusForward(Ctrl *ctrl, Ctrl *top, bool noframe = false, bool init = false, bool all = false);
1096 	static bool  IterateFocusBackward(Ctrl *ctrl, Ctrl *top, bool noframe = false, bool all = false);
1097 
1098 	static dword AccessKeyBit(int accesskey);
1099 	dword   GetAccessKeysDeep() const;
1100 	void    DistributeAccessKeys();
1101 	bool    VisibleAccessKeys();
1102 
1103 	void    Show(bool show = true);
Hide()1104 	void    Hide()                             { Show(false); }
IsShown()1105 	bool    IsShown() const                    { return visible; }
1106 	bool    IsVisible() const;
1107 
1108 	void    Enable(bool enable = true);
Disable()1109 	void    Disable()                          { Enable(false); }
IsEnabled()1110 	bool    IsEnabled() const                  { return enabled; }
1111 
1112 	Ctrl&   SetEditable(bool editable = true);
SetReadOnly()1113 	Ctrl&   SetReadOnly()                      { return SetEditable(false); }
IsEditable()1114 	bool    IsEditable() const                 { return editable; }
IsReadOnly()1115 	bool    IsReadOnly() const                 { return !editable; }
1116 
1117 	void    ClearModifyDeep();
1118 	bool    IsModifiedDeep() const;
IsModifySet()1119 	bool    IsModifySet() const                { return modify; } // deprecated
1120 
1121 	void    UpdateRefresh();
1122 	void    Update();
1123 	void    Action();
1124 	void    UpdateAction();
1125 	void    UpdateActionRefresh();
1126 
1127 	Ctrl&   BackPaint(int bp = FULLBACKPAINT)  { backpaint = bp; return *this; }
TransparentBackPaint()1128 	Ctrl&   TransparentBackPaint()             { backpaint = TRANSPARENTBACKPAINT; return *this; }
NoBackPaint()1129 	Ctrl&   NoBackPaint()                      { return BackPaint(NOBACKPAINT); }
1130 	Ctrl&   BackPaintHint();
GetBackPaint()1131 	int     GetBackPaint() const               { return backpaint; }
1132 	Ctrl&   Transparent(bool bp = true)        { transparent = bp; return *this; }
NoTransparent()1133 	Ctrl&   NoTransparent()                    { return Transparent(false); }
IsTransparent()1134 	bool    IsTransparent() const              { return transparent; }
1135 
Info(const char * txt)1136 	Ctrl&   Info(const char *txt)              { info = txt; return *this; }
GetInfo()1137 	String  GetInfo() const                    { return info; }
1138 
1139 	Ctrl&   Tip(const char *txt);
1140 	Ctrl&   HelpLine(const char *txt);
1141 	Ctrl&   Description(const char *txt);
1142 	Ctrl&   HelpTopic(const char *txt);
1143 	Ctrl&   LayoutId(const char *txt);
1144 
1145 	String  GetTip() const;
1146 	String  GetHelpLine() const;
1147 	String  GetDescription() const;
1148 	String  GetHelpTopic() const;
1149 	String  GetLayoutId() const;
ClearInfo()1150 	void    ClearInfo()                        { info.Clear(); }
1151 
Add(Ctrl & ctrl)1152 	void    Add(Ctrl& ctrl)                    { AddChild(&ctrl); }
1153 	Ctrl&   operator<<(Ctrl& ctrl)             { Add(ctrl); return *this; }
1154 
1155 	void    Remove();
1156 
1157 	Value        operator~() const             { return GetData(); }
1158 	const Value& operator<<=(const Value& v)   { SetData(v); return v; }
IsNullInstance()1159 	bool         IsNullInstance() const        { return GetData().IsNull(); }
1160 
1161 	Callback     operator<<=(Callback  action) { WhenAction = action; return action; }
1162 
1163 	Event<>&     operator<<(Event<> action)    { return WhenAction << action; }
1164 	Event<>&     operator^=(Event<> action)    { return WhenAction = action; }
1165 
1166 	void    SetTimeCallback(int delay_ms, Function<void ()> cb, int id = 0);
1167 	void    KillTimeCallback(int id = 0);
1168 	void    KillSetTimeCallback(int delay_ms, Function<void ()> cb, int id);
1169 	bool    ExistsTimeCallback(int id = 0) const;
1170 	void    PostCallback(Function<void ()> cb, int id = 0);
1171 	void    KillPostCallback(Function<void ()> cb, int id);
1172 
1173 	enum { TIMEID_COUNT = 1 };
1174 
1175 	static Ctrl *GetActiveCtrl();
1176 	static Ctrl *GetActiveWindow();
1177 
1178 	static Ctrl *GetVisibleChild(Ctrl *ctrl, Point p, bool pointinframe);
1179 
1180 	void   PopUp(Ctrl *owner = NULL, bool savebits = true, bool activate = true, bool dropshadow = false,
1181 	             bool topmost = false);
1182 
1183 	void   SetAlpha(byte alpha);
1184 
1185 	static bool IsWaitingEvent();
1186 	static bool ProcessEvent(bool *quit = NULL);
1187 	static bool ProcessEvents(bool *quit = NULL);
1188 
IsPopUp()1189 	bool   IsPopUp() const          { return popup; }
1190 
1191 	static void  EventLoop(Ctrl *loopctrl = NULL);
GetLoopLevel()1192 	static int   GetLoopLevel()     { return LoopLevel; }
GetLoopCtrl()1193 	static Ctrl *GetLoopCtrl()      { return LoopCtrl; }
1194 
1195 	void   EndLoop();
1196 	void   EndLoop(int code);
1197 	bool   InLoop() const;
1198 	bool   InCurrentLoop() const;
1199 	int    GetExitCode() const;
1200 
1201 	static PasteClip& Clipboard();
1202 	static PasteClip& Selection();
1203 
1204 	void   SetSelectionSource(const char *fmts);
1205 
1206 	static void RegisterDropFormats(const char *fmts); // MacOS requires drop formats to be registered
1207 
1208 	int    DoDragAndDrop(const char *fmts, const Image& sample, dword actions,
1209 	                     const VectorMap<String, ClipData>& data);
1210 	int    DoDragAndDrop(const char *fmts, const Image& sample = Null, dword actions = DND_ALL);
1211 	int    DoDragAndDrop(const VectorMap<String, ClipData>& data, const Image& sample = Null,
1212 	                     dword actions = DND_ALL);
1213 	static Ctrl *GetDragAndDropSource();
1214 	static Ctrl *GetDragAndDropTarget();
IsDragAndDropSource()1215 	bool   IsDragAndDropSource()    { return this == GetDragAndDropSource(); }
IsDragAndDropTarget()1216 	bool   IsDragAndDropTarget()    { return this == GetDragAndDropTarget(); }
StdSampleSize()1217 	static Size  StdSampleSize()    { return Size(DPI(126), DPI(106)); }
1218 
1219 public:
1220 	static void SetSkin(void (*skin)());
1221 
1222 	static const char *GetZoomText();
1223 	static void SetZoomSize(Size sz, Size bsz = Size(0, 0));
1224 	static int  HorzLayoutZoom(int cx);
1225 	static double HorzLayoutZoomf(double cx);
1226 	static int  VertLayoutZoom(int cy);
1227 	static Size LayoutZoom(int cx, int cy);
1228 	static Size LayoutZoom(Size sz);
1229 	static void NoLayoutZoom();
1230 	static void GetZoomRatio(Size& m, Size& d);
1231 
1232 	static void SetUHDEnabled(bool set = true);
1233 	static bool IsUHDEnabled();
1234 
1235 	static void SetDarkThemeEnabled(bool set = true);
1236 	static bool IsDarkThemeEnabled();
1237 
1238 	static bool ClickFocus();
1239 	static void ClickFocus(bool cf);
1240 
1241 	static Rect   GetVirtualWorkArea();
1242 	static Rect   GetVirtualScreenArea();
1243 	static Rect   GetPrimaryWorkArea();
1244 	static Rect   GetPrimaryScreenArea();
1245 	static void   GetWorkArea(Array<Rect>& rc);
1246 	static Rect   GetWorkArea(Point pt);
GetMouseWorkArea()1247 	static Rect   GetMouseWorkArea()                     { return GetWorkArea(GetMousePos()); }
1248 	static int    GetKbdDelay();
1249 	static int    GetKbdSpeed();
1250 	static bool   IsAlphaSupported();
1251 	static Rect   GetDefaultWindowRect();
1252 	static String GetAppName();
1253 	static void   SetAppName(const String& appname);
1254 	static bool   IsCompositedGui();
1255 
1256 	static void   GlobalBackPaint(bool b = true);
1257 	static void   GlobalBackPaintHint();
1258 	static void   GlobalBackBuffer(bool b = true);
1259 
1260 	static void   ReSkin();
1261 
1262 	String        Name() const;
1263 	static String Name(Ctrl *ctrl);
1264 
1265 #ifdef _DEBUG
1266 	virtual void   Dump() const;
1267 	virtual void   Dump(Stream& s) const;
1268 
1269 	static bool LogMessages;
1270 #endif
1271 
1272 	static void ShowRepaint(int ms);
1273 
1274 	static bool MemoryCheck;
1275 
1276 	static void GuiSleep(int ms);
1277 
1278 	static void SetTimerGranularity(int ms);
1279 
1280 	static void Call(Function<void ()> cb);
1281 
IsShutdownThreads()1282 	static bool IsShutdownThreads()                     { return Thread::IsShutdownThreads(); }
1283 	static void ShutdownThreads();
1284 
GetEventId()1285 	static int64 GetEventId()                           { return eventid; }
1286 
1287 	Ctrl();
1288 	virtual ~Ctrl();
1289 };
1290 
GetScreenSize()1291 inline Size GetScreenSize()  { return Ctrl::GetVirtualScreenArea().GetSize(); } // Deprecated
1292 
1293 bool   GuiPlatformHasSizeGrip();
1294 void   GuiPlatformGripResize(TopWindow *q);
1295 Color  GuiPlatformGetScreenPixel(int x, int y);
1296 void   GuiPlatformAfterMenuPopUp();
1297 
Zx(int cx)1298 inline int  Zx(int cx) { return Ctrl::HorzLayoutZoom(cx); }
Zxf(double cx)1299 inline double Zxf(double cx) { return Ctrl::HorzLayoutZoomf(cx); }
Zy(int cy)1300 inline int  Zy(int cy) { return Ctrl::VertLayoutZoom(cy); }
Zsz(int cx,int cy)1301 inline Size Zsz(int cx, int cy) { return Size(Zx(cx), Zy(cy)); }
Zsz(Size sz)1302 inline Size Zsz(Size sz) { return Zsz(sz.cx, sz.cy); }
InvZx(int cx)1303 inline int  InvZx(int cx) { return 100000 * cx / Zx(100000); }
InvZxf(double cx)1304 inline double InvZxf(double cx) { return 100000 * cx / Zx(100000); }
1305 
1306 Font FontZ(int face, int height = 0);
1307 
1308 Font StdFontZ(int height = 0);
1309 Font SansSerifZ(int height = 0);
1310 Font SerifZ(int height = 0);
1311 Font MonospaceZ(int height = 0);
1312 Font RomanZ(int height = 0);
1313 Font ArialZ(int height = 0);
1314 Font CourierZ(int height = 0);
1315 
1316 Font ScreenSansZ(int height = 0); // deprecated
1317 Font ScreenSerifZ(int height = 0); // deprecated
1318 Font ScreenFixedZ(int height = 0); // deprecated
1319 
1320 int   EditFieldIsThin();
1321 Value TopSeparator1();
1322 Value TopSeparator2();
1323 int   FrameButtonWidth();
1324 int   ScrollBarArrowSize();
1325 Color FieldFrameColor();
1326 
1327 enum { GUISTYLE_FLAT, GUISTYLE_CLASSIC, GUISTYLE_XP, GUISTYLE_X };
1328 int GUI_GlobalStyle();
1329 
1330 int GUI_DragFullWindow();
1331 
1332 enum { GUIEFFECT_NONE, GUIEFFECT_SLIDE, GUIEFFECT_FADE };
1333 int GUI_PopUpEffect();
1334 
1335 int GUI_ToolTips();
1336 int GUI_ToolTipDelay();
1337 
1338 int GUI_DropShadows();
1339 int GUI_AltAccessKeys();
1340 int GUI_AKD_Conservative();
1341 int GUI_DragDistance();
1342 int GUI_DblClickTime();
1343 int GUI_WheelScrollLines();
1344 
1345 void GUI_GlobalStyle_Write(int);
1346 void GUI_DragFullWindow_Write(int);
1347 void GUI_PopUpEffect_Write(int);
1348 void GUI_ToolTips_Write(int);
1349 void GUI_ToolTipDelay_Write(int);
1350 void GUI_DropShadows_Write(int);
1351 void GUI_AltAccessKeys_Write(int);
1352 void GUI_AKD_Conservative_Write(int);
1353 void GUI_DragDistance_Write(int);
1354 void GUI_DblClickTime_Write(int);
1355 void GUI_WheelScrollLines_Write(int);
1356 
1357 void  EditFieldIsThin_Write(int);
1358 void  TopSeparator1_Write(Value);
1359 void  TopSeparator2_Write(Value);
1360 void  FrameButtonWidth_Write(int);
1361 void  ScrollBarArrowSize_Write(int);
1362 void  FieldFrameColor_Write(Color);
1363 
1364 String Name(const Ctrl *ctrl);
1365 String Desc(const Ctrl *ctrl);
1366 void   Dump(const Ctrl *ctrl);
1367 
1368 inline Ctrl *operator<<(Ctrl *parent, Ctrl& child)
1369 {
1370 	parent->Add(child);
1371 	return parent;
1372 }
1373 
GetHashValue(Ctrl * x)1374 inline hash_t GetHashValue(Ctrl *x)
1375 {
1376 	return (hash_t)(intptr_t)x;
1377 }
1378 
1379 String GetKeyDesc(dword key);
1380 
1381 Vector< Ptr<Ctrl> > DisableCtrls(const Vector<Ctrl *>& ctrl, Ctrl *exclude = NULL);
1382 void EnableCtrls(const Vector< Ptr<Ctrl> >& ctrl);
1383 
1384 template <class T>
1385 class FrameCtrl : public T, public CtrlFrame {
1386 public:
FrameAdd(Ctrl & parent)1387 	virtual void FrameAdd(Ctrl& parent) { parent.Add(*this); }
FrameRemove()1388 	virtual void FrameRemove()          { this->Ctrl::Remove(); }
1389 
FrameCtrl()1390 	FrameCtrl()                         { this->NoWantFocus(); }
1391 };
1392 
1393 template <class T>
1394 class FrameLR : public FrameCtrl<T> {
1395 public:
FrameAddSize(Size & sz)1396 	virtual void FrameAddSize(Size& sz) { sz.cx += (cx ? cx : sz.cy) * this->IsShown(); }
1397 
1398 protected:
1399 	int cx;
1400 
1401 public:
Width(int _cx)1402 	FrameLR& Width(int _cx)             { cx = _cx; this->RefreshParentLayout(); return *this; }
GetWidth()1403 	int      GetWidth() const           { return cx; }
FrameLR()1404 	FrameLR()                           { cx = 0; }
1405 };
1406 
1407 template <class T>
1408 class FrameLeft : public FrameLR<T> {
1409 public:
FrameLayout(Rect & r)1410 	virtual void FrameLayout(Rect& r) {
1411 		LayoutFrameLeft(r, this, this->cx ? this->cx : FrameButtonWidth());
1412 	}
1413 };
1414 
1415 template <class T>
1416 class FrameRight : public FrameLR<T> {
1417 public:
FrameLayout(Rect & r)1418 	virtual void FrameLayout(Rect& r) {
1419 		LayoutFrameRight(r, this, this->cx ? this->cx : FrameButtonWidth());
1420 	}
1421 };
1422 
1423 template <class T>
1424 class FrameTB : public FrameCtrl<T> {
1425 public:
FrameAddSize(Size & sz)1426 	virtual void FrameAddSize(Size& sz) { sz.cy += (cy ? cy : sz.cx) * this->IsShown(); }
1427 
1428 protected:
1429 	int cy;
1430 
1431 public:
Height(int _cy)1432 	FrameTB& Height(int _cy)            { cy = _cy; this->RefreshParentLayout(); return *this; }
GetHeight()1433 	int      GetHeight() const          { return cy; }
FrameTB()1434 	FrameTB()                           { cy = 0; }
1435 };
1436 
1437 template <class T>
1438 class FrameTop : public FrameTB<T> {
1439 public:
FrameLayout(Rect & r)1440 	virtual void FrameLayout(Rect& r) {
1441 		LayoutFrameTop(r, this, this->cy ? this->cy : r.Width());
1442 	}
1443 };
1444 
1445 template <class T>
1446 class FrameBottom : public FrameTB<T> {
1447 public:
FrameLayout(Rect & r)1448 	virtual void FrameLayout(Rect& r) {
1449 		LayoutFrameBottom(r, this, this->cy ? this->cy : r.Width());
1450 	}
1451 };
1452 
1453 class Modality {
1454 	Ptr<Ctrl>           active;
1455 	bool                fore_only;
1456 	Vector< Ptr<Ctrl> > enable;
1457 
1458 public:
1459 	void Begin(Ctrl *modal, bool fore_only = false);
1460 	void End();
1461 
~Modality()1462 	~Modality()      { End(); }
1463 };
1464 
1465 class LocalLoop : public Ctrl {
1466 public:
1467 	virtual void CancelMode();
1468 
1469 private:
1470 	Ctrl *master;
1471 
1472 public:
1473 	void  Run();
SetMaster(Ctrl & m)1474 	void  SetMaster(Ctrl& m)      { master = &m; }
GetMaster()1475 	Ctrl& GetMaster() const       { return *master; }
1476 
LocalLoop()1477 	LocalLoop()                   { master = NULL; }
1478 };
1479 
1480 enum {
1481 	DRAWDRAGRECT_SOLID, DRAWDRAGRECT_NORMAL, DRAWDRAGRECT_DASHED
1482 };
1483 
1484 bool PointLoop(Ctrl& ctrl, const Vector<Image>& ani, int ani_ms);
1485 bool PointLoop(Ctrl& ctrl, const Image& img);
1486 
1487 class RectTracker : public LocalLoop {
1488 public:
1489 	virtual void  LeftUp(Point, dword);
1490 	virtual void  RightUp(Point, dword);
1491 	virtual void  MouseMove(Point p, dword);
1492 	virtual Image CursorImage(Point, dword);
1493 	virtual void  Paint(Draw& w);
1494 
1495 public:
1496 	struct Rounder {
1497 		virtual Rect Round(const Rect& r) = 0;
1498 	};
1499 
1500 protected:
1501 	Image           master_image;
1502 
1503 	Rect            rect;
1504 	int             tx, ty;
1505 	Rect            maxrect;
1506 	Size            minsize, maxsize;
1507 	bool            keepratio;
1508 	Rect            clip;
1509 	Color           color;
1510 	Image           cursorimage;
1511 	int             width;
1512 	int             pattern;
1513 	int             animation;
1514 	int             panim;
1515 	Rounder        *rounder;
1516 
1517 	Rect            org;
1518 	Rect            o;
1519 	Point           op;
1520 
1521 	Rect            Round(const Rect& r);
1522 
1523 	virtual void    RefreshRect(const Rect& old, const Rect& r);
1524 	virtual void    DrawRect(Draw& w, Rect r1);
1525 
1526 public:
1527 	Event<Rect>  sync;
1528 	Event<Rect&> round;
1529 
SetCursorImage(const Image & m)1530 	RectTracker&    SetCursorImage(const Image& m) { cursorimage = m; return *this; }
MinSize(Size sz)1531 	RectTracker&    MinSize(Size sz)               { minsize = sz; return *this; }
MaxSize(Size sz)1532 	RectTracker&    MaxSize(Size sz)               { maxsize = sz; return *this; }
MaxRect(const Rect & mr)1533 	RectTracker&    MaxRect(const Rect& mr)        { maxrect = mr; return *this; }
Clip(const Rect & c)1534 	RectTracker&    Clip(const Rect& c)            { clip = c; return *this; }
Width(int n)1535 	RectTracker&    Width(int n)                   { width = n; return *this; }
SetColor(Color c)1536 	RectTracker&    SetColor(Color c)              { color = c; return *this; }
Pattern(int p)1537 	RectTracker&    Pattern(int p)                 { pattern = p; return *this; }
Dashed()1538 	RectTracker&    Dashed()                       { return Pattern(DRAWDRAGRECT_DASHED); }
Solid()1539 	RectTracker&    Solid()                        { return Pattern(DRAWDRAGRECT_SOLID); }
Normal()1540 	RectTracker&    Normal()                       { return Pattern(DRAWDRAGRECT_NORMAL); }
1541 	RectTracker&    Animation(int step_ms = 40)    { animation = step_ms; return *this; }
KeepRatio(bool b)1542 	RectTracker&    KeepRatio(bool b)              { keepratio = b; return *this; }
Round(Rounder & r)1543 	RectTracker&    Round(Rounder& r)              { rounder = &r; return *this; }
1544 
Get()1545 	Rect            Get()                          { return rect; }
1546 
1547 	Rect  Track(const Rect& r, int tx = ALIGN_RIGHT, int ty = ALIGN_BOTTOM);
1548 	int   TrackHorzLine(int x0, int y0, int cx, int line);
1549 	int   TrackVertLine(int x0, int y0, int cy, int line);
1550 	Point TrackLine(int x0, int y0);
1551 
1552 	RectTracker(Ctrl& master);
1553 };
1554 
1555 class WaitCursor {
1556 	Image   prev;
1557 	bool    flag;
1558 
1559 public:
1560 	void    Show();
1561 
1562 	WaitCursor(bool show = true);
1563 	~WaitCursor();
1564 };
1565 
1566 class AutoWaitCursor : public WaitCursor {
1567 protected:
1568 	int&   avg;
1569 	int    time0;
1570 
1571 public:
Cancel()1572 	void Cancel()                   { time0 = 0; }
1573 
1574 	AutoWaitCursor(int& avg);
1575 	~AutoWaitCursor();
1576 };
1577 
1578 void    ClearClipboard();
1579 void    AppendClipboard(const char *format, const byte *data, int length);
1580 void    AppendClipboard(const char *format, const String& data);
1581 void    AppendClipboard(const char *format, const Value& data, String (*render)(const Value& data));
1582 void    AppendClipboard(const char *format, const ClipData& data);
1583 void    AppendClipboard(const VectorMap<String, ClipData>& data);
1584 String  ReadClipboard(const char *format);
1585 bool    IsClipboardAvailable(const char *format);
1586 
WriteClipboard(const char * format,const String & data)1587 inline  void WriteClipboard(const char *format, const String& data)
1588 	{ ClearClipboard(); AppendClipboard(format, data); }
1589 
1590 void    AppendClipboardText(const String& s);
1591 String  ReadClipboardText();
1592 void    AppendClipboardUnicodeText(const WString& s);
1593 WString ReadClipboardUnicodeText();
1594 bool    IsClipboardAvailableText();
1595 
WriteClipboardText(const String & s)1596 inline  void WriteClipboardText(const String& s)
1597 	{ ClearClipboard(); AppendClipboardText(s); }
WriteClipboardUnicodeText(const WString & s)1598 inline  void WriteClipboardUnicodeText(const WString& s)
1599 	{ ClearClipboard(); AppendClipboardUnicodeText(s); }
1600 
1601 template <class T>
AppendClipboardFormat(const T & object)1602 inline void AppendClipboardFormat(const T& object) {
1603 	AppendClipboard(typeid(T).name(), StoreAsString(const_cast<T&>(object)));
1604 }
1605 
1606 template <class T>
WriteClipboardFormat(const T & object)1607 inline void WriteClipboardFormat(const T& object) {
1608 	ClearClipboard();
1609 	AppendClipboardFormat(object);
1610 }
1611 
1612 template <class T>
ReadClipboardFormat(T & object)1613 inline bool ReadClipboardFormat(T& object)
1614 {
1615 	String s = ReadClipboard(typeid(T).name());
1616 	return !IsNull(s) && LoadFromString(object, s);
1617 }
1618 
1619 template <class T>
IsClipboardFormatAvailable()1620 bool IsClipboardFormatAvailable()
1621 {
1622 	return IsClipboardAvailable(typeid(T).name());
1623 }
1624 
1625 template <class T>
ReadClipboardFormat()1626 inline T ReadClipboardFormat() {
1627 	T object;
1628 	ReadClipboardFormat(object);
1629 	return object;
1630 }
1631 
1632 Image  ReadClipboardImage();
1633 void   AppendClipboardImage(const Image& img);
1634 
WriteClipboardImage(const Image & img)1635 inline void WriteClipboardImage(const Image& img)
1636 	{ ClearClipboard(); AppendClipboardImage(img); }
1637 
1638 bool (*&DisplayErrorFn())(const Value& v);
DisplayError(const Value & v)1639 inline bool DisplayError(const Value& v) { return DisplayErrorFn()(v); }
1640 
1641 const char *ClipFmtsRTF();
1642 
1643 void       EncodeRTF(Stream& stream, const RichText& richtext, byte charset,
1644 	Size dot_page_size = Size(4960, 7015), const Rect& dot_margin = Rect(472, 472, 472, 472),
1645 	void *context = NULL);
1646 String     EncodeRTF(const RichText& richtext, byte charset,
1647 	Size dot_page_size = Size(4960, 7015), const Rect& dot_margin = Rect(472, 472, 472, 472),
1648 	void *context = NULL);
1649 String     EncodeRTF(const RichText& richtext, byte charset, int dot_page_width);
1650 String     EncodeRTF(const RichText& richtext);
1651 RichText   ParseRTF(const char *rtf);
1652 
1653 void WriteClipboardHTML(const String& html);
1654 
1655 #include <CtrlCore/TopWindow.h>
1656 
1657 #include GUIPLATFORM_INCLUDE_AFTER
1658 
1659 template <class T>
GetAscendant()1660 T *Ctrl::GetAscendant() const
1661 {
1662 	for(Ctrl *p = GetParent(); p; p = p->GetParent())
1663 		if(T *a = dynamic_cast<T*>(p))
1664 			return a;
1665 	return NULL;
1666 }
1667 
1668 #ifdef HAS_TopFrameDraw
1669 
1670 class ViewDraw : public TopFrameDraw {
1671 public:
1672 	ViewDraw(Ctrl *ctrl, const Rect& r);
ViewDraw(Ctrl * ctrl)1673 	ViewDraw(Ctrl *ctrl) : ViewDraw(ctrl, ctrl->GetSize()) {}
ViewDraw(Ctrl * ctrl,int x,int y,int cx,int cy)1674 	ViewDraw(Ctrl *ctrl, int x, int y, int cx, int cy) : ViewDraw(ctrl, RectC(x, y, cx, cy)) {}
1675 };
1676 
1677 #endif
1678 
1679 }
1680 
1681 #endif
1682