[SHELL32] -CShellDispatch: Properly register Shell.Application. Implement CShellDispa...
[reactos.git] / reactos / base / applications / rapps_new / splitter.cpp
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps_new/splitter.cpp
5 * PURPOSE: SplitterBar functions
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 */
8
9 #include "rapps.h"
10
11 HWND hVSplitter = NULL;
12 HWND hHSplitter = NULL;
13
14 static int HSplitterPos = 0;
15
16 int
17 GetHSplitterPos(VOID)
18 {
19 return HSplitterPos;
20 }
21
22 VOID
23 SetHSplitterPos(int Pos)
24 {
25 HSplitterPos = Pos;
26 }
27
28 /* Callback for horizontal splitter bar */
29 LRESULT CALLBACK
30 HSplitterWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
31 {
32 switch (Msg)
33 {
34 case WM_CREATE:
35 {
36 SetHSplitterPos(GetWindowHeight(hListView));
37 }
38 break;
39
40 case WM_LBUTTONDOWN:
41 {
42 SetCapture(hwnd);
43 }
44 break;
45
46 case WM_LBUTTONUP:
47 case WM_RBUTTONDOWN:
48 if (GetCapture() == hwnd)
49 {
50 ReleaseCapture();
51 }
52 break;
53
54 case WM_MOUSEMOVE:
55 if (GetCapture() == hwnd)
56 {
57 int Width = GetClientWindowWidth(hMainWnd) - GetWindowWidth(hTreeView) - SPLIT_WIDTH;
58 int NewPos;
59 HDWP hdwp;
60 POINT Point;
61
62 GetCursorPos(&Point);
63 ScreenToClient(hMainWnd, &Point);
64
65 NewPos = Point.y;
66
67 if ((GetClientWindowHeight(hMainWnd) - GetWindowHeight(hStatusBar) - SPLIT_WIDTH) < NewPos)
68 break;
69
70 if ((GetWindowHeight(hToolBar) + SPLIT_WIDTH) > NewPos)
71 break;
72
73 SetHSplitterPos(NewPos);
74
75 hdwp = BeginDeferWindowPos(3);
76
77 /* Size HSplitBar */
78 if (hdwp)
79 hdwp = DeferWindowPos(hdwp,
80 hHSplitter,
81 0,
82 GetWindowWidth(hTreeView) + SPLIT_WIDTH,
83 Point.y,
84 Width,
85 SPLIT_WIDTH,
86 SWP_NOZORDER|SWP_NOACTIVATE);
87
88 /* Size ListView */
89 if (hdwp)
90 hdwp = DeferWindowPos(hdwp,
91 hListView,
92 0,
93 GetWindowWidth(hTreeView) + SPLIT_WIDTH,
94 GetWindowHeight(hToolBar),
95 Width,
96 Point.y - GetWindowHeight(hToolBar),
97 SWP_NOZORDER|SWP_NOACTIVATE);
98
99 /* Size RichEdit */
100 if (hdwp)
101 hdwp = DeferWindowPos(hdwp,
102 hRichEdit,
103 0,
104 GetWindowWidth(hTreeView) + SPLIT_WIDTH,
105 Point.y + SPLIT_WIDTH,
106 Width,
107 GetClientWindowHeight(hMainWnd) - (Point.y + SPLIT_WIDTH + GetWindowHeight(hStatusBar)),
108 SWP_NOZORDER|SWP_NOACTIVATE);
109
110 if (hdwp)
111 EndDeferWindowPos(hdwp);
112 }
113 break;
114 }
115
116 return DefWindowProc(hwnd, Msg, wParam, lParam);
117 }
118
119 /* Create horizontal splitter bar */
120 BOOL
121 CreateHSplitBar(HWND hwnd)
122 {
123 WCHAR szWindowClass[] = L"HSplitterWindowClass";
124 WNDCLASSEXW WndClass = {0};
125
126 WndClass.cbSize = sizeof(WndClass);
127 WndClass.lpszClassName = szWindowClass;
128 WndClass.lpfnWndProc = HSplitterWindowProc;
129 WndClass.hInstance = hInst;
130 WndClass.style = CS_HREDRAW | CS_VREDRAW;
131 WndClass.hCursor = LoadCursor(0, IDC_SIZENS);
132 WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
133
134 if (RegisterClassExW(&WndClass) == (ATOM) 0)
135 {
136 /* TODO: Show error message */
137 return FALSE;
138 }
139
140 hHSplitter = CreateWindowExW(WS_EX_TRANSPARENT,
141 szWindowClass,
142 NULL,
143 WS_CHILD | WS_VISIBLE,
144 205, 180, 465, SPLIT_WIDTH,
145 hwnd,
146 NULL,
147 hInst,
148 NULL);
149
150
151 if (hHSplitter == NULL)
152 {
153 /* TODO: Show error message */
154 return FALSE;
155 }
156
157 ShowWindow(hHSplitter, SW_SHOW);
158 UpdateWindow(hHSplitter);
159
160 return TRUE;
161 }
162
163 /* Callback for vertical splitter bar */
164 LRESULT CALLBACK
165 VSplitterWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
166 {
167 switch (Msg)
168 {
169 case WM_LBUTTONDOWN:
170 SetCapture(hwnd);
171 break;
172
173 case WM_LBUTTONUP:
174 case WM_RBUTTONDOWN:
175 if (GetCapture() == hwnd)
176 {
177 ReleaseCapture();
178 }
179 break;
180
181 case WM_MOUSEMOVE:
182 if (GetCapture() == hwnd)
183 {
184 HDWP hdwp;
185 POINT Point;
186
187 GetCursorPos(&Point);
188 ScreenToClient(hMainWnd, &Point);
189
190 if ((GetClientWindowWidth(hMainWnd) - SPLIT_WIDTH) < Point.x)
191 break;
192
193 if (SPLIT_WIDTH > Point.x)
194 break;
195
196 hdwp = BeginDeferWindowPos(5);
197
198 /* Size VSplitBar */
199 if (hdwp)
200 hdwp = DeferWindowPos(hdwp,
201 hwnd,
202 0,
203 Point.x,
204 GetWindowHeight(hToolBar),
205 SPLIT_WIDTH,
206 GetClientWindowHeight(hMainWnd) - GetWindowHeight(hToolBar) - GetWindowHeight(hStatusBar),
207 SWP_NOZORDER|SWP_NOACTIVATE);
208
209 /* Size TreeView */
210 if (hdwp)
211 hdwp = DeferWindowPos(hdwp,
212 hTreeView,
213 0,
214 0,
215 GetWindowHeight(hToolBar),
216 Point.x,
217 GetClientWindowHeight(hMainWnd) - GetWindowHeight(hToolBar) - GetWindowHeight(hStatusBar),
218 SWP_NOZORDER|SWP_NOACTIVATE);
219
220 /* Size ListView */
221 if (hdwp)
222 hdwp = DeferWindowPos(hdwp,
223 hListView,
224 0,
225 Point.x + SPLIT_WIDTH,
226 GetWindowHeight(hToolBar),
227 GetClientWindowWidth(hMainWnd) - (Point.x + SPLIT_WIDTH),
228 GetHSplitterPos() - GetWindowHeight(hToolBar),
229 SWP_NOZORDER|SWP_NOACTIVATE);
230
231 if (hdwp)
232 hdwp = DeferWindowPos(hdwp,
233 hRichEdit,
234 0,
235 Point.x + SPLIT_WIDTH,
236 GetHSplitterPos() + SPLIT_WIDTH,
237 GetClientWindowWidth(hMainWnd) - (Point.x + SPLIT_WIDTH),
238 GetClientWindowHeight(hMainWnd) - (GetHSplitterPos() + SPLIT_WIDTH + GetWindowHeight(hStatusBar)),
239 SWP_NOZORDER|SWP_NOACTIVATE);
240
241 if (hdwp)
242 hdwp = DeferWindowPos(hdwp,
243 hHSplitter,
244 0,
245 Point.x + SPLIT_WIDTH,
246 GetHSplitterPos(),
247 GetClientWindowWidth(hMainWnd) - (Point.x + SPLIT_WIDTH),
248 SPLIT_WIDTH,
249 SWP_NOZORDER|SWP_NOACTIVATE);
250
251 if (hdwp)
252 EndDeferWindowPos(hdwp);
253 }
254 break;
255 }
256
257 return DefWindowProc(hwnd, Msg, wParam, lParam);
258 }
259
260 /* Create vertical splitter bar */
261 BOOL
262 CreateVSplitBar(HWND hwnd)
263 {
264 WCHAR szWindowClass[] = L"VSplitterWindowClass";
265 WNDCLASSEXW WndClass = {0};
266
267 WndClass.cbSize = sizeof(WndClass);
268 WndClass.lpszClassName = szWindowClass;
269 WndClass.lpfnWndProc = VSplitterWindowProc;
270 WndClass.hInstance = hInst;
271 WndClass.style = CS_HREDRAW | CS_VREDRAW;
272 WndClass.hCursor = LoadCursor(0, IDC_SIZEWE);
273 WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
274
275 if (RegisterClassExW(&WndClass) == (ATOM) 0)
276 {
277 /* TODO: Show error message */
278 return FALSE;
279 }
280
281 hVSplitter = CreateWindowExW(WS_EX_TRANSPARENT,
282 szWindowClass,
283 NULL,
284 WS_CHILD | WS_VISIBLE,
285 201, 28, SPLIT_WIDTH, 350,
286 hwnd,
287 NULL,
288 hInst,
289 NULL);
290
291
292 if (!hVSplitter)
293 {
294 /* TODO: Show error message */
295 return FALSE;
296 }
297
298 ShowWindow(hVSplitter, SW_SHOW);
299 UpdateWindow(hVSplitter);
300
301 return TRUE;
302 }