1 #include "CtrlCore.h"
2
3 #ifdef GUI_WIN
4
5 namespace Upp {
6
7 #ifndef PLATFORM_WINCE
8
9 Vector<DHCtrl *> DHCtrl::all_active;
10
RemoveActive()11 void DHCtrl::RemoveActive()
12 {
13 for(;;) {
14 int q = FindIndex(all_active, this);
15 if(q < 0)
16 return;
17 all_active.Remove(q);
18 }
19 }
20
PreprocessMessageAll(MSG & msg)21 bool DHCtrl::PreprocessMessageAll(MSG& msg)
22 {
23 for(auto q : all_active)
24 if(q->PreprocessMessage(msg))
25 return true;
26 return false;
27 }
28
PreprocessMessage(MSG & msg)29 bool DHCtrl::PreprocessMessage(MSG& msg)
30 {
31 return false;
32 }
33
NcCreate(HWND _hwnd)34 void DHCtrl::NcCreate(HWND _hwnd)
35 {
36 hwnd = _hwnd;
37 all_active.Add(this);
38 }
39
NcDestroy()40 void DHCtrl::NcDestroy()
41 {
42 hwnd = NULL;
43 RemoveActive();
44 }
45
WindowProc(UINT message,WPARAM wParam,LPARAM lParam)46 LRESULT DHCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
47 {
48 GuiLock __;
49 if(message == WM_ERASEBKGND)
50 return 1L;
51 return DefWindowProc(hwnd, message, wParam, lParam);
52 }
53
CloseHWND()54 void DHCtrl::CloseHWND()
55 {
56 GuiLock __;
57 if(hwnd) {
58 DestroyWindow(hwnd);
59 hwnd = NULL;
60 RemoveActive();
61 }
62 }
63
OpenHWND()64 void DHCtrl::OpenHWND()
65 {
66 GuiLock __;
67 CloseHWND();
68 HWND phwnd = GetTopCtrl()->GetHWND();
69 if(phwnd)
70 CreateWindowEx(0, "UPP-CLASS-A", "",
71 WS_CHILD|WS_DISABLED|WS_VISIBLE,
72 0, 0, 20, 20,
73 phwnd, NULL, hInstance, this);
74 }
75
SyncHWND()76 void DHCtrl::SyncHWND()
77 {
78 GuiLock __;
79 HWND phwnd = GetTopCtrl()->GetHWND();
80 if(phwnd) {
81 Rect r = GetScreenView() - GetScreenClient(phwnd).TopLeft();
82 if(r != current_pos || IsVisible() != (bool)current_visible) {
83 SetWindowPos(hwnd, NULL, r.left, r.top, r.Width(), r.Height(), SWP_NOACTIVATE|SWP_NOZORDER);
84 ShowWindow(hwnd, IsVisible() ? SW_SHOW : SW_HIDE);
85 Refresh();
86 current_pos = r;
87 current_visible = IsVisible();
88 }
89 }
90 }
91
State(int reason)92 void DHCtrl::State(int reason)
93 {
94 switch(reason) {
95 case OPEN:
96 current_pos = Null;
97 current_visible = Null;
98 OpenHWND();
99 default:
100 SyncHWND();
101 break;
102 case CLOSE:
103 CloseHWND();
104 }
105 }
106
DHCtrl()107 DHCtrl::DHCtrl()
108 {
109 hwnd = NULL;
110 isdhctrl = true;
111 BackPaint(EXCLUDEPAINT);
112 }
113
~DHCtrl()114 DHCtrl::~DHCtrl()
115 {
116 CloseHWND();
117 BackPaint(EXCLUDEPAINT);
118 RemoveActive();
119 }
120
UpdateDHCtrls()121 void Ctrl::UpdateDHCtrls()
122 { // we call this in WM_PAINT to force updating in single WM_PAINT, this makes things smoother e.g. with OpenGL in splitter
123 for(Ctrl *q = GetFirstChild(); q; q = q->GetNext()) {
124 DHCtrl *dh = dynamic_cast<DHCtrl *>(q);
125 if(dh)
126 UpdateWindow(dh->GetHWND());
127 q->UpdateDHCtrls();
128 }
129 }
130
131
132 #endif
133
134 }
135
136 #endif
137