[RAPPS] Select the search bar with ctrl+f
[reactos.git] / base / applications / rapps / splitter.cpp
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/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 if (hHSplitter == NULL)
151 {
152 /* TODO: Show error message */
153 return FALSE;
154 }
155
156 ShowWindow(hHSplitter, SW_SHOW);
157 UpdateWindow(hHSplitter);
158
159 return TRUE;
160 }
161
162 /* Callback for vertical splitter bar */
163 LRESULT CALLBACK
164 VSplitterWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
165 {
166 switch (Msg)
167 {
168 case WM_LBUTTONDOWN:
169 SetCapture(hwnd);
170 break;
171
172 case WM_LBUTTONUP:
173 case WM_RBUTTONDOWN:
174 if (GetCapture() == hwnd)
175 {
176 ReleaseCapture();
177 }
178 break;
179
180 case WM_MOUSEMOVE:
181 if (GetCapture() == hwnd)
182 {
183 HDWP hdwp;
184 POINT Point;
185
186 GetCursorPos(&Point);
187 ScreenToClient(hMainWnd, &Point);
188
189 if ((GetClientWindowWidth(hMainWnd) - SPLIT_WIDTH) < Point.x)
190 break;
191
192 if (SPLIT_WIDTH > Point.x)
193 break;
194
195 hdwp = BeginDeferWindowPos(5);
196
197 /* Size VSplitBar */
198 if (hdwp)
199 hdwp = DeferWindowPos(hdwp,
200 hwnd,
201 0,
202 Point.x,
203 GetWindowHeight(hToolBar),
204 SPLIT_WIDTH,
205 GetClientWindowHeight(hMainWnd) - GetWindowHeight(hToolBar) - GetWindowHeight(hStatusBar),
206 SWP_NOZORDER|SWP_NOACTIVATE);
207
208 /* Size TreeView */
209 if (hdwp)
210 hdwp = DeferWindowPos(hdwp,
211 hTreeView,
212 0,
213 0,
214 GetWindowHeight(hToolBar),
215 Point.x,
216 GetClientWindowHeight(hMainWnd) - GetWindowHeight(hToolBar) - GetWindowHeight(hStatusBar),
217 SWP_NOZORDER|SWP_NOACTIVATE);
218
219 /* Size ListView */
220 if (hdwp)
221 hdwp = DeferWindowPos(hdwp,
222 hListView,
223 0,
224 Point.x + SPLIT_WIDTH,
225 GetWindowHeight(hToolBar),
226 GetClientWindowWidth(hMainWnd) - (Point.x + SPLIT_WIDTH),
227 GetHSplitterPos() - GetWindowHeight(hToolBar),
228 SWP_NOZORDER|SWP_NOACTIVATE);
229
230 if (hdwp)
231 hdwp = DeferWindowPos(hdwp,
232 hRichEdit,
233 0,
234 Point.x + SPLIT_WIDTH,
235 GetHSplitterPos() + SPLIT_WIDTH,
236 GetClientWindowWidth(hMainWnd) - (Point.x + SPLIT_WIDTH),
237 GetClientWindowHeight(hMainWnd) - (GetHSplitterPos() + SPLIT_WIDTH + GetWindowHeight(hStatusBar)),
238 SWP_NOZORDER|SWP_NOACTIVATE);
239
240 if (hdwp)
241 hdwp = DeferWindowPos(hdwp,
242 hHSplitter,
243 0,
244 Point.x + SPLIT_WIDTH,
245 GetHSplitterPos(),
246 GetClientWindowWidth(hMainWnd) - (Point.x + SPLIT_WIDTH),
247 SPLIT_WIDTH,
248 SWP_NOZORDER|SWP_NOACTIVATE);
249
250 if (hdwp)
251 EndDeferWindowPos(hdwp);
252 }
253 break;
254 }
255
256 return DefWindowProc(hwnd, Msg, wParam, lParam);
257 }
258
259 /* Create vertical splitter bar */
260 BOOL
261 CreateVSplitBar(HWND hwnd)
262 {
263 WCHAR szWindowClass[] = L"VSplitterWindowClass";
264 WNDCLASSEXW WndClass = {0};
265
266 WndClass.cbSize = sizeof(WndClass);
267 WndClass.lpszClassName = szWindowClass;
268 WndClass.lpfnWndProc = VSplitterWindowProc;
269 WndClass.hInstance = hInst;
270 WndClass.style = CS_HREDRAW | CS_VREDRAW;
271 WndClass.hCursor = LoadCursor(0, IDC_SIZEWE);
272 WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
273
274 if (RegisterClassExW(&WndClass) == (ATOM) 0)
275 {
276 /* TODO: Show error message */
277 return FALSE;
278 }
279
280 hVSplitter = CreateWindowExW(WS_EX_TRANSPARENT,
281 szWindowClass,
282 NULL,
283 WS_CHILD | WS_VISIBLE,
284 201, 28, SPLIT_WIDTH, 350,
285 hwnd,
286 NULL,
287 hInst,
288 NULL);
289
290 if (!hVSplitter)
291 {
292 /* TODO: Show error message */
293 return FALSE;
294 }
295
296 ShowWindow(hVSplitter, SW_SHOW);
297 UpdateWindow(hVSplitter);
298
299 return TRUE;
300 }