Fix build.
[reactos.git] / reactos / base / applications / rapps / splitter.c
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/splitter.c
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 DeferWindowPos(hdwp,
79 hHSplitter,
80 0,
81 GetWindowWidth(hTreeView) + SPLIT_WIDTH,
82 Point.y,
83 Width,
84 SPLIT_WIDTH,
85 SWP_NOZORDER|SWP_NOACTIVATE);
86
87 /* Size ListView */
88 DeferWindowPos(hdwp,
89 hListView,
90 0,
91 GetWindowWidth(hTreeView) + SPLIT_WIDTH,
92 GetWindowHeight(hToolBar),
93 Width,
94 Point.y - GetWindowHeight(hToolBar),
95 SWP_NOZORDER|SWP_NOACTIVATE);
96
97 /* Size RichEdit */
98 DeferWindowPos(hdwp,
99 hRichEdit,
100 0,
101 GetWindowWidth(hTreeView) + SPLIT_WIDTH,
102 Point.y + SPLIT_WIDTH,
103 Width,
104 GetClientWindowHeight(hMainWnd) - (Point.y + SPLIT_WIDTH + GetWindowHeight(hStatusBar)),
105 SWP_NOZORDER|SWP_NOACTIVATE);
106
107 EndDeferWindowPos(hdwp);
108 }
109 break;
110 }
111
112 return DefWindowProc(hwnd, Msg, wParam, lParam);
113 }
114
115 /* Create horizontal splitter bar */
116 BOOL
117 CreateHSplitBar(HWND hwnd)
118 {
119 WCHAR szWindowClass[] = L"HSplitterWindowClass";
120 WNDCLASSEXW WndClass = {0};
121
122 WndClass.cbSize = sizeof(WNDCLASSEXW);
123 WndClass.lpszClassName = szWindowClass;
124 WndClass.lpfnWndProc = HSplitterWindowProc;
125 WndClass.hInstance = hInst;
126 WndClass.style = CS_HREDRAW | CS_VREDRAW;
127 WndClass.hCursor = LoadCursor(0, IDC_SIZENS);
128 WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
129
130 if (RegisterClassExW(&WndClass) == (ATOM) 0)
131 {
132 /* TODO: Show error message */
133 return FALSE;
134 }
135
136 hHSplitter = CreateWindowExW(WS_EX_TRANSPARENT,
137 szWindowClass,
138 NULL,
139 WS_CHILD | WS_VISIBLE,
140 205, 180, 465, SPLIT_WIDTH,
141 hwnd,
142 NULL,
143 hInst,
144 NULL);
145
146
147 if (hHSplitter == NULL)
148 {
149 /* TODO: Show error message */
150 return FALSE;
151 }
152
153 ShowWindow(hHSplitter, SW_SHOW);
154 UpdateWindow(hHSplitter);
155
156 return TRUE;
157 }
158
159 /* Callback for vertical splitter bar */
160 LRESULT CALLBACK
161 VSplitterWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
162 {
163 switch (Msg)
164 {
165 case WM_LBUTTONDOWN:
166 SetCapture(hwnd);
167 break;
168
169 case WM_LBUTTONUP:
170 case WM_RBUTTONDOWN:
171 if (GetCapture() == hwnd)
172 {
173 ReleaseCapture();
174 }
175 break;
176
177 case WM_MOUSEMOVE:
178 if (GetCapture() == hwnd)
179 {
180 HDWP hdwp;
181 POINT Point;
182
183 GetCursorPos(&Point);
184 ScreenToClient(hMainWnd, &Point);
185
186 if ((GetClientWindowWidth(hMainWnd) - SPLIT_WIDTH) < Point.x)
187 break;
188
189 if (SPLIT_WIDTH > Point.x)
190 break;
191
192 hdwp = BeginDeferWindowPos(5);
193
194 /* Size VSplitBar */
195 DeferWindowPos(hdwp,
196 hwnd,
197 0,
198 Point.x,
199 GetWindowHeight(hToolBar),
200 SPLIT_WIDTH,
201 GetClientWindowHeight(hMainWnd) - GetWindowHeight(hToolBar) - GetWindowHeight(hStatusBar),
202 SWP_NOZORDER|SWP_NOACTIVATE);
203
204 /* Size TreeView */
205 DeferWindowPos(hdwp,
206 hTreeView,
207 0,
208 0,
209 GetWindowHeight(hToolBar),
210 Point.x,
211 GetClientWindowHeight(hMainWnd) - GetWindowHeight(hToolBar) - GetWindowHeight(hStatusBar),
212 SWP_NOZORDER|SWP_NOACTIVATE);
213
214 /* Size ListView */
215 DeferWindowPos(hdwp,
216 hListView,
217 0,
218 Point.x + SPLIT_WIDTH,
219 GetWindowHeight(hToolBar),
220 GetClientWindowWidth(hMainWnd) - (Point.x + SPLIT_WIDTH),
221 GetHSplitterPos() - GetWindowHeight(hToolBar),
222 SWP_NOZORDER|SWP_NOACTIVATE);
223
224 DeferWindowPos(hdwp,
225 hRichEdit,
226 0,
227 Point.x + SPLIT_WIDTH,
228 GetHSplitterPos() + SPLIT_WIDTH,
229 GetClientWindowWidth(hMainWnd) - (Point.x + SPLIT_WIDTH),
230 GetClientWindowHeight(hMainWnd) - (GetHSplitterPos() + SPLIT_WIDTH + GetWindowHeight(hStatusBar)),
231 SWP_NOZORDER|SWP_NOACTIVATE);
232
233 DeferWindowPos(hdwp,
234 hHSplitter,
235 0,
236 Point.x + SPLIT_WIDTH,
237 GetHSplitterPos(),
238 GetClientWindowWidth(hMainWnd) - (Point.x + SPLIT_WIDTH),
239 SPLIT_WIDTH,
240 SWP_NOZORDER|SWP_NOACTIVATE);
241
242 EndDeferWindowPos(hdwp);
243 }
244 break;
245 }
246
247 return DefWindowProc(hwnd, Msg, wParam, lParam);
248 }
249
250 /* Create vertical splitter bar */
251 BOOL
252 CreateVSplitBar(HWND hwnd)
253 {
254 WCHAR szWindowClass[] = L"VSplitterWindowClass";
255 WNDCLASSEXW WndClass = {0};
256
257 WndClass.cbSize = sizeof(WNDCLASSEXW);
258 WndClass.lpszClassName = szWindowClass;
259 WndClass.lpfnWndProc = VSplitterWindowProc;
260 WndClass.hInstance = hInst;
261 WndClass.style = CS_HREDRAW | CS_VREDRAW;
262 WndClass.hCursor = LoadCursor(0, IDC_SIZEWE);
263 WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
264
265 if (RegisterClassExW(&WndClass) == (ATOM) 0)
266 {
267 /* TODO: Show error message */
268 return FALSE;
269 }
270
271 hVSplitter = CreateWindowExW(WS_EX_TRANSPARENT,
272 szWindowClass,
273 NULL,
274 WS_CHILD | WS_VISIBLE,
275 201, 28, SPLIT_WIDTH, 350,
276 hwnd,
277 NULL,
278 hInst,
279 NULL);
280
281
282 if (!hVSplitter)
283 {
284 /* TODO: Show error message */
285 return FALSE;
286 }
287
288 ShowWindow(hVSplitter, SW_SHOW);
289 UpdateWindow(hVSplitter);
290
291 return TRUE;
292 }