1 | /* $Id: win32wbasenonclient.cpp,v 1.8 2000-02-03 17:13:03 cbratschi Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 Window Base Class for OS/2 (non-client methods)
|
---|
4 | *
|
---|
5 | * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
|
---|
6 | *
|
---|
7 | * Based on Wine code (windows\nonclient.c)
|
---|
8 | *
|
---|
9 | * Copyright 1994 Alexandre Julliard
|
---|
10 | *
|
---|
11 | * TODO: Not thread/process safe
|
---|
12 | *
|
---|
13 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
14 | *
|
---|
15 | */
|
---|
16 | #include <os2win.h>
|
---|
17 | #include <win.h>
|
---|
18 | #include <stdlib.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <stdarg.h>
|
---|
21 | #include <assert.h>
|
---|
22 | #include <misc.h>
|
---|
23 | #include <heapstring.h>
|
---|
24 | #include <win32wbase.h>
|
---|
25 | #include <winres.h>
|
---|
26 | #include "wndmsg.h"
|
---|
27 | #include "pmframe.h"
|
---|
28 | #include "oslibwin.h"
|
---|
29 | #include "oslibmsg.h"
|
---|
30 | #include "oslibutil.h"
|
---|
31 | #include "oslibgdi.h"
|
---|
32 | #include "oslibres.h"
|
---|
33 | #include "oslibdos.h"
|
---|
34 | #include "syscolor.h"
|
---|
35 | #include "win32wndhandle.h"
|
---|
36 | #include "dc.h"
|
---|
37 | #include "win32wdesktop.h"
|
---|
38 | #include "controls.h"
|
---|
39 | #include <menu.h>
|
---|
40 |
|
---|
41 | #define SC_ABOUTODIN (SC_SCREENSAVE+1)
|
---|
42 | #define SC_PUTMARK (SC_SCREENSAVE+2)
|
---|
43 |
|
---|
44 | /* bits in the dwKeyData */
|
---|
45 | #define KEYDATA_ALT 0x2000
|
---|
46 | #define KEYDATA_PREVSTATE 0x4000
|
---|
47 |
|
---|
48 | static HBITMAP hbitmapClose = 0;
|
---|
49 | static HBITMAP hbitmapCloseD = 0;
|
---|
50 | static HBITMAP hbitmapMinimize = 0;
|
---|
51 | static HBITMAP hbitmapMinimizeD = 0;
|
---|
52 | static HBITMAP hbitmapMaximize = 0;
|
---|
53 | static HBITMAP hbitmapMaximizeD = 0;
|
---|
54 | static HBITMAP hbitmapRestore = 0;
|
---|
55 | static HBITMAP hbitmapRestoreD = 0;
|
---|
56 |
|
---|
57 | BYTE lpGrayMask[] = { 0xAA, 0xA0,
|
---|
58 | 0x55, 0x50,
|
---|
59 | 0xAA, 0xA0,
|
---|
60 | 0x55, 0x50,
|
---|
61 | 0xAA, 0xA0,
|
---|
62 | 0x55, 0x50,
|
---|
63 | 0xAA, 0xA0,
|
---|
64 | 0x55, 0x50,
|
---|
65 | 0xAA, 0xA0,
|
---|
66 | 0x55, 0x50};
|
---|
67 |
|
---|
68 | static INT (* WINAPI ShellAboutA)(HWND,LPCSTR,LPCSTR,HICON) = 0;
|
---|
69 |
|
---|
70 | //******************************************************************************
|
---|
71 | //******************************************************************************
|
---|
72 | LONG Win32BaseWindow::HandleNCActivate(WPARAM wParam)
|
---|
73 | {
|
---|
74 | WORD wStateChange;
|
---|
75 |
|
---|
76 | if( wParam ) wStateChange = !(flags & WIN_NCACTIVATED);
|
---|
77 | else wStateChange = flags & WIN_NCACTIVATED;
|
---|
78 |
|
---|
79 | if( wStateChange )
|
---|
80 | {
|
---|
81 | if (wParam) flags |= WIN_NCACTIVATED;
|
---|
82 | else flags &= ~WIN_NCACTIVATED;
|
---|
83 |
|
---|
84 | if (!(dwStyle & WS_CAPTION)) return TRUE;
|
---|
85 |
|
---|
86 | if(!(dwStyle & WS_MINIMIZE))
|
---|
87 | DoNCPaint((HRGN)1,FALSE);
|
---|
88 | }
|
---|
89 |
|
---|
90 | return TRUE;
|
---|
91 | }
|
---|
92 | //******************************************************************************
|
---|
93 | //******************************************************************************
|
---|
94 | VOID Win32BaseWindow::TrackMinMaxBox(WORD wParam)
|
---|
95 | {
|
---|
96 | MSG msg;
|
---|
97 | HDC hdc;
|
---|
98 | BOOL pressed = TRUE;
|
---|
99 | UINT state;
|
---|
100 |
|
---|
101 | if (wParam == HTMINBUTTON)
|
---|
102 | {
|
---|
103 | /* If the style is not present, do nothing */
|
---|
104 | if (!(dwStyle & WS_MINIMIZEBOX))
|
---|
105 | return;
|
---|
106 | /* Check if the sysmenu item for minimize is there */
|
---|
107 | state = GetMenuState(hSysMenu,SC_MINIMIZE,MF_BYCOMMAND);
|
---|
108 | } else
|
---|
109 | {
|
---|
110 | /* If the style is not present, do nothing */
|
---|
111 | if (!(dwStyle & WS_MAXIMIZEBOX))
|
---|
112 | return;
|
---|
113 | /* Check if the sysmenu item for maximize is there */
|
---|
114 | state = GetMenuState(hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
|
---|
115 | }
|
---|
116 | SetCapture(Win32Hwnd);
|
---|
117 | hdc = GetWindowDC(Win32Hwnd);
|
---|
118 | if (wParam == HTMINBUTTON)
|
---|
119 | DrawMinButton(hdc,NULL,TRUE,FALSE);
|
---|
120 | else
|
---|
121 | DrawMaxButton(hdc,NULL,TRUE,FALSE);
|
---|
122 | do
|
---|
123 | {
|
---|
124 | BOOL oldstate = pressed;
|
---|
125 |
|
---|
126 | GetMessageA(&msg,Win32Hwnd,0,0);
|
---|
127 | pressed = (HandleNCHitTest(msg.pt) == wParam);
|
---|
128 | if (pressed != oldstate)
|
---|
129 | {
|
---|
130 | if (wParam == HTMINBUTTON)
|
---|
131 | DrawMinButton(hdc,NULL,pressed,FALSE);
|
---|
132 | else
|
---|
133 | DrawMaxButton(hdc,NULL,pressed,FALSE);
|
---|
134 | }
|
---|
135 | } while (msg.message != WM_LBUTTONUP);
|
---|
136 | if (wParam == HTMINBUTTON)
|
---|
137 | DrawMinButton(hdc,NULL,FALSE,FALSE);
|
---|
138 | else
|
---|
139 | DrawMaxButton(hdc,NULL,FALSE,FALSE);
|
---|
140 | ReleaseCapture();
|
---|
141 | ReleaseDC(Win32Hwnd,hdc);
|
---|
142 | /* If the item minimize or maximize of the sysmenu are not there */
|
---|
143 | /* or if the style is not present, do nothing */
|
---|
144 | if ((!pressed) || (state == 0xFFFFFFFF))
|
---|
145 | return;
|
---|
146 | if (wParam == HTMINBUTTON)
|
---|
147 | SendInternalMessageA(WM_SYSCOMMAND,SC_MINIMIZE,*(LPARAM*)&msg.pt);
|
---|
148 | else
|
---|
149 | SendInternalMessageA(WM_SYSCOMMAND,IsZoomed(Win32Hwnd) ? SC_RESTORE:SC_MAXIMIZE,*(LPARAM*)&msg.pt);
|
---|
150 | }
|
---|
151 | //******************************************************************************
|
---|
152 | //******************************************************************************
|
---|
153 | VOID Win32BaseWindow::TrackCloseButton(WORD wParam)
|
---|
154 | {
|
---|
155 | MSG msg;
|
---|
156 | HDC hdc;
|
---|
157 | BOOL pressed = TRUE;
|
---|
158 | UINT state;
|
---|
159 |
|
---|
160 | if (hSysMenu == 0)
|
---|
161 | return;
|
---|
162 | state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
|
---|
163 | /* If the item close of the sysmenu is disabled or not there do nothing */
|
---|
164 | if((state & MF_DISABLED) || (state & MF_GRAYED) || (state == 0xFFFFFFFF))
|
---|
165 | return;
|
---|
166 | hdc = GetWindowDC(Win32Hwnd);
|
---|
167 | SetCapture(Win32Hwnd);
|
---|
168 | DrawCloseButton(hdc,NULL,TRUE,FALSE);
|
---|
169 | do
|
---|
170 | {
|
---|
171 | BOOL oldstate = pressed;
|
---|
172 |
|
---|
173 | GetMessageA(&msg,Win32Hwnd,0,0);
|
---|
174 | pressed = (HandleNCHitTest(msg.pt) == wParam);
|
---|
175 | if (pressed != oldstate)
|
---|
176 | DrawCloseButton(hdc,NULL,pressed,FALSE);
|
---|
177 | } while (msg.message != WM_LBUTTONUP);
|
---|
178 | DrawCloseButton(hdc,NULL,FALSE,FALSE);
|
---|
179 | ReleaseCapture();
|
---|
180 | ReleaseDC(Win32Hwnd,hdc);
|
---|
181 | if (!pressed) return;
|
---|
182 | SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,*(LPARAM*)&msg.pt);
|
---|
183 | }
|
---|
184 | //******************************************************************************
|
---|
185 | //******************************************************************************
|
---|
186 | VOID Win32BaseWindow::TrackScrollBar(WPARAM wParam,POINT pt)
|
---|
187 | {
|
---|
188 | INT scrollbar;
|
---|
189 | MSG msg;
|
---|
190 |
|
---|
191 | if ((wParam & 0xfff0) == SC_HSCROLL)
|
---|
192 | {
|
---|
193 | if ((wParam & 0x0f) != HTHSCROLL) return;
|
---|
194 | scrollbar = SB_HORZ;
|
---|
195 | } else /* SC_VSCROLL */
|
---|
196 | {
|
---|
197 | if ((wParam & 0x0f) != HTVSCROLL) return;
|
---|
198 | scrollbar = SB_VERT;
|
---|
199 | }
|
---|
200 |
|
---|
201 | pt.x -= rectWindow.left;
|
---|
202 | pt.y -= rectWindow.top;
|
---|
203 | SCROLL_HandleScrollEvent(Win32Hwnd,0,MAKELONG(pt.x,pt.y),scrollbar,WM_LBUTTONDOWN);
|
---|
204 | if (GetCapture() != Win32Hwnd) return;
|
---|
205 | do
|
---|
206 | {
|
---|
207 | GetMessageA(&msg, 0, 0, 0);
|
---|
208 | if(msg.hwnd == getWindowHandle())
|
---|
209 | {
|
---|
210 | switch(msg.message)
|
---|
211 | {
|
---|
212 | case WM_LBUTTONUP:
|
---|
213 | case WM_MOUSEMOVE:
|
---|
214 | pt.x = msg.pt.x-rectWindow.left;
|
---|
215 | pt.y = msg.pt.y-rectWindow.top;
|
---|
216 | msg.lParam = MAKELONG(pt.x,pt.y);
|
---|
217 |
|
---|
218 | case WM_SYSTIMER:
|
---|
219 | SCROLL_HandleScrollEvent(Win32Hwnd,msg.wParam,msg.lParam,scrollbar,msg.message);
|
---|
220 | break;
|
---|
221 |
|
---|
222 | default:
|
---|
223 | TranslateMessage(&msg);
|
---|
224 | DispatchMessageA(&msg);
|
---|
225 | break;
|
---|
226 | }
|
---|
227 | }
|
---|
228 | else {
|
---|
229 | TranslateMessage(&msg);
|
---|
230 | DispatchMessageA(&msg);
|
---|
231 | }
|
---|
232 | if (!IsWindow())
|
---|
233 | {
|
---|
234 | ReleaseCapture();
|
---|
235 | break;
|
---|
236 | }
|
---|
237 | } while (msg.message != WM_LBUTTONUP);
|
---|
238 | }
|
---|
239 | //******************************************************************************
|
---|
240 | //******************************************************************************
|
---|
241 | LONG Win32BaseWindow::HandleNCLButtonDown(WPARAM wParam,LPARAM lParam)
|
---|
242 | {
|
---|
243 | switch(wParam) /* Hit test */
|
---|
244 | {
|
---|
245 | case HTCAPTION:
|
---|
246 | {
|
---|
247 | Win32BaseWindow *topparent = GetTopParent();
|
---|
248 |
|
---|
249 | if (GetActiveWindow() != topparent->getWindowHandle())
|
---|
250 | topparent->SetActiveWindow();
|
---|
251 |
|
---|
252 | if (GetActiveWindow() == topparent->getWindowHandle())
|
---|
253 | SendInternalMessageA(WM_SYSCOMMAND,SC_MOVE+HTCAPTION,lParam);
|
---|
254 | break;
|
---|
255 | }
|
---|
256 |
|
---|
257 | case HTSYSMENU:
|
---|
258 | if(dwStyle & WS_SYSMENU )
|
---|
259 | {
|
---|
260 | SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTSYSMENU,lParam);
|
---|
261 | }
|
---|
262 | break;
|
---|
263 |
|
---|
264 | case HTMENU:
|
---|
265 | SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU,lParam);
|
---|
266 | break;
|
---|
267 |
|
---|
268 | case HTHSCROLL:
|
---|
269 | SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
|
---|
270 | break;
|
---|
271 |
|
---|
272 | case HTVSCROLL:
|
---|
273 | SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
|
---|
274 | break;
|
---|
275 |
|
---|
276 | case HTMINBUTTON:
|
---|
277 | case HTMAXBUTTON:
|
---|
278 | TrackMinMaxBox(wParam);
|
---|
279 | break;
|
---|
280 |
|
---|
281 | case HTCLOSE:
|
---|
282 | TrackCloseButton(wParam);
|
---|
283 | break;
|
---|
284 |
|
---|
285 | case HTLEFT:
|
---|
286 | case HTRIGHT:
|
---|
287 | case HTTOP:
|
---|
288 | case HTTOPLEFT:
|
---|
289 | case HTTOPRIGHT:
|
---|
290 | case HTBOTTOM:
|
---|
291 | case HTBOTTOMLEFT:
|
---|
292 | case HTBOTTOMRIGHT:
|
---|
293 | /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */
|
---|
294 | SendInternalMessageA(WM_SYSCOMMAND,SC_SIZE+wParam-2,lParam);
|
---|
295 | break;
|
---|
296 | case HTBORDER:
|
---|
297 | break;
|
---|
298 | }
|
---|
299 |
|
---|
300 | return 0;
|
---|
301 | }
|
---|
302 | //******************************************************************************
|
---|
303 | //******************************************************************************
|
---|
304 | VOID Win32BaseWindow::AdjustMaximizedRect(LPRECT rect)
|
---|
305 | {
|
---|
306 | if (HAS_THICKFRAME(dwStyle,dwExStyle ))
|
---|
307 | InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
|
---|
308 | else
|
---|
309 | if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
---|
310 | InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
|
---|
311 | else
|
---|
312 | if (HAS_THINFRAME( dwStyle ))
|
---|
313 | InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
|
---|
314 | }
|
---|
315 | //******************************************************************************
|
---|
316 | //******************************************************************************
|
---|
317 | VOID Win32BaseWindow::AdjustTrackInfo(PPOINT minTrackSize,PPOINT maxTrackSize)
|
---|
318 | {
|
---|
319 | if ((dwStyle & WS_THICKFRAME) || !(dwStyle & (WS_POPUP | WS_CHILD)))
|
---|
320 | GetMinMaxInfo(NULL,NULL,minTrackSize,maxTrackSize);
|
---|
321 | }
|
---|
322 | //******************************************************************************
|
---|
323 | //******************************************************************************
|
---|
324 | VOID Win32BaseWindow::AdjustRectOuter(LPRECT rect,BOOL menu)
|
---|
325 | {
|
---|
326 | if(dwStyle & WS_ICONIC) return;
|
---|
327 |
|
---|
328 | if (HAS_THICKFRAME(dwStyle,dwExStyle ))
|
---|
329 | InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
|
---|
330 | else
|
---|
331 | if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
---|
332 | InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
|
---|
333 | else
|
---|
334 | if (HAS_THINFRAME( dwStyle ))
|
---|
335 | InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
|
---|
336 |
|
---|
337 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
338 | {
|
---|
339 | if (dwExStyle & WS_EX_TOOLWINDOW)
|
---|
340 | rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
|
---|
341 | else
|
---|
342 | rect->top -= GetSystemMetrics(SM_CYCAPTION);
|
---|
343 | }
|
---|
344 |
|
---|
345 | if (menu)
|
---|
346 | rect->top -= GetSystemMetrics(SM_CYMENU);
|
---|
347 | }
|
---|
348 | //******************************************************************************
|
---|
349 | //******************************************************************************
|
---|
350 | VOID Win32BaseWindow::AdjustRectInner(LPRECT rect)
|
---|
351 | {
|
---|
352 | if(dwStyle & WS_ICONIC) return;
|
---|
353 |
|
---|
354 | if (dwExStyle & WS_EX_CLIENTEDGE)
|
---|
355 | InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
|
---|
356 |
|
---|
357 | if (dwExStyle & WS_EX_STATICEDGE)
|
---|
358 | InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
|
---|
359 |
|
---|
360 | if (dwStyle & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
|
---|
361 | if (dwStyle & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
|
---|
362 | }
|
---|
363 | //******************************************************************************
|
---|
364 | //******************************************************************************
|
---|
365 | LONG Win32BaseWindow::HandleNCCalcSize(BOOL calcValidRects,RECT *winRect)
|
---|
366 | {
|
---|
367 | RECT tmpRect = { 0, 0, 0, 0 };
|
---|
368 | LONG result = 0;
|
---|
369 | UINT style;
|
---|
370 |
|
---|
371 | dprintf(("Default WM_NCCALCSIZE handler"));
|
---|
372 |
|
---|
373 | if (!calcValidRects) return 0;
|
---|
374 |
|
---|
375 | style = (UINT) GetClassLongA(Win32Hwnd,GCL_STYLE);
|
---|
376 |
|
---|
377 | if (style & CS_VREDRAW) result |= WVR_VREDRAW;
|
---|
378 | if (style & CS_HREDRAW) result |= WVR_HREDRAW;
|
---|
379 |
|
---|
380 | if(!(dwStyle & WS_MINIMIZE))
|
---|
381 | {
|
---|
382 | AdjustRectOuter(&tmpRect,FALSE);
|
---|
383 |
|
---|
384 | winRect->left -= tmpRect.left;
|
---|
385 | winRect->top -= tmpRect.top;
|
---|
386 | winRect->right -= tmpRect.right;
|
---|
387 | winRect->bottom -= tmpRect.bottom;
|
---|
388 |
|
---|
389 | if (HAS_MENU())
|
---|
390 | {
|
---|
391 | winRect->top +=
|
---|
392 | MENU_GetMenuBarHeight(Win32Hwnd,
|
---|
393 | winRect->right - winRect->left,
|
---|
394 | -tmpRect.left, -tmpRect.top ) + 1;
|
---|
395 | }
|
---|
396 |
|
---|
397 | SetRect (&tmpRect, 0, 0, 0, 0);
|
---|
398 | AdjustRectInner(&tmpRect);
|
---|
399 | winRect->left -= tmpRect.left;
|
---|
400 | winRect->top -= tmpRect.top;
|
---|
401 | winRect->right -= tmpRect.right;
|
---|
402 | winRect->bottom -= tmpRect.bottom;
|
---|
403 | }
|
---|
404 |
|
---|
405 | return result;
|
---|
406 | }
|
---|
407 | //******************************************************************************
|
---|
408 | //******************************************************************************
|
---|
409 | LONG Win32BaseWindow::HandleNCHitTest(POINT pt)
|
---|
410 | {
|
---|
411 | RECT rect = rectWindow;
|
---|
412 |
|
---|
413 | if (dwStyle & WS_MINIMIZE) return HTCAPTION;
|
---|
414 |
|
---|
415 | if (!PtInRect(&rect,pt)) return HTNOWHERE;
|
---|
416 |
|
---|
417 | /* Check borders */
|
---|
418 | if (HAS_THICKFRAME(dwStyle,dwExStyle))
|
---|
419 | {
|
---|
420 | InflateRect(&rect,-GetSystemMetrics(SM_CXFRAME),-GetSystemMetrics(SM_CYFRAME));
|
---|
421 | if (!PtInRect(&rect,pt))
|
---|
422 | {
|
---|
423 | /* Check top sizing border */
|
---|
424 | if (pt.y < rect.top)
|
---|
425 | {
|
---|
426 | if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTTOPLEFT;
|
---|
427 | if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTTOPRIGHT;
|
---|
428 | return HTTOP;
|
---|
429 | }
|
---|
430 | /* Check bottom sizing border */
|
---|
431 | if (pt.y >= rect.bottom)
|
---|
432 | {
|
---|
433 | if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMLEFT;
|
---|
434 | if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMRIGHT;
|
---|
435 | return HTBOTTOM;
|
---|
436 | }
|
---|
437 | /* Check left sizing border */
|
---|
438 | if (pt.x < rect.left)
|
---|
439 | {
|
---|
440 | if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPLEFT;
|
---|
441 | if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMLEFT;
|
---|
442 | return HTLEFT;
|
---|
443 | }
|
---|
444 | /* Check right sizing border */
|
---|
445 | if (pt.x >= rect.right)
|
---|
446 | {
|
---|
447 | if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPRIGHT;
|
---|
448 | if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMRIGHT;
|
---|
449 | return HTRIGHT;
|
---|
450 | }
|
---|
451 | }
|
---|
452 | } else /* No thick frame */
|
---|
453 | {
|
---|
454 | if (HAS_DLGFRAME(dwStyle,dwExStyle))
|
---|
455 | InflateRect(&rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
|
---|
456 | else if (HAS_THINFRAME(dwStyle ))
|
---|
457 | InflateRect(&rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
|
---|
458 | if (!PtInRect( &rect, pt )) return HTBORDER;
|
---|
459 | }
|
---|
460 |
|
---|
461 | /* Check caption */
|
---|
462 |
|
---|
463 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
464 | {
|
---|
465 | if (dwExStyle & WS_EX_TOOLWINDOW)
|
---|
466 | rect.top += GetSystemMetrics(SM_CYSMCAPTION)-1;
|
---|
467 | else
|
---|
468 | rect.top += GetSystemMetrics(SM_CYCAPTION)-1;
|
---|
469 | if (!PtInRect(&rect,pt))
|
---|
470 | {
|
---|
471 | /* Check system menu */
|
---|
472 | if(dwStyle & WS_SYSMENU)
|
---|
473 | {
|
---|
474 | /* Check if there is an user icon */
|
---|
475 | HICON hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICONSM);
|
---|
476 | if(!hIcon) hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICON);
|
---|
477 |
|
---|
478 | /* If there is an icon associated with the window OR */
|
---|
479 | /* If there is no hIcon specified and this is not a modal dialog, */
|
---|
480 | /* there is a system menu icon. */
|
---|
481 | if((hIcon != 0) || (!(dwStyle & DS_MODALFRAME)))
|
---|
482 | rect.left += GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
483 | }
|
---|
484 | if (pt.x < rect.left) return HTSYSMENU;
|
---|
485 |
|
---|
486 | /* Check close button */
|
---|
487 | if (dwStyle & WS_SYSMENU)
|
---|
488 | rect.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
489 | if (pt.x > rect.right) return HTCLOSE;
|
---|
490 |
|
---|
491 | /* Check maximize box */
|
---|
492 | /* In win95 there is automatically a Maximize button when there is a minimize one*/
|
---|
493 | if ((dwStyle & WS_MAXIMIZEBOX)|| (dwStyle & WS_MINIMIZEBOX))
|
---|
494 | rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
|
---|
495 | if (pt.x > rect.right) return HTMAXBUTTON;
|
---|
496 |
|
---|
497 | /* Check minimize box */
|
---|
498 | /* In win95 there is automatically a Maximize button when there is a Maximize one*/
|
---|
499 | if ((dwStyle & WS_MINIMIZEBOX)||(dwStyle & WS_MAXIMIZEBOX))
|
---|
500 | rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
|
---|
501 |
|
---|
502 | if (pt.x > rect.right) return HTMINBUTTON;
|
---|
503 | return HTCAPTION;
|
---|
504 | }
|
---|
505 | }
|
---|
506 |
|
---|
507 | /* Check client area */
|
---|
508 |
|
---|
509 | ScreenToClient(Win32Hwnd,&pt);
|
---|
510 | getClientRect(&rect);
|
---|
511 | if (PtInRect(&rect,pt)) return HTCLIENT;
|
---|
512 |
|
---|
513 | /* Check vertical scroll bar */
|
---|
514 |
|
---|
515 | if (dwStyle & WS_VSCROLL)
|
---|
516 | {
|
---|
517 | rect.right += GetSystemMetrics(SM_CXVSCROLL);
|
---|
518 | if (PtInRect( &rect, pt )) return HTVSCROLL;
|
---|
519 | }
|
---|
520 |
|
---|
521 | /* Check horizontal scroll bar */
|
---|
522 |
|
---|
523 | if (dwStyle & WS_HSCROLL)
|
---|
524 | {
|
---|
525 | rect.bottom += GetSystemMetrics(SM_CYHSCROLL);
|
---|
526 | if (PtInRect( &rect, pt ))
|
---|
527 | {
|
---|
528 | /* Check size box */
|
---|
529 | if ((dwStyle & WS_VSCROLL) &&
|
---|
530 | (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL)))
|
---|
531 | return (dwStyle & WS_CHILD) ? HTSIZE:HTBOTTOMRIGHT;
|
---|
532 | return HTHSCROLL;
|
---|
533 | }
|
---|
534 | }
|
---|
535 |
|
---|
536 | /* Check menu bar */
|
---|
537 |
|
---|
538 | if (HAS_MENU())
|
---|
539 | {
|
---|
540 | if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
|
---|
541 | return HTMENU;
|
---|
542 | }
|
---|
543 |
|
---|
544 | /* Should never get here */
|
---|
545 | return HTERROR;
|
---|
546 | }
|
---|
547 |
|
---|
548 | //******************************************************************************
|
---|
549 | //******************************************************************************
|
---|
550 | VOID Win32BaseWindow::GetInsideRect(RECT *rect)
|
---|
551 | {
|
---|
552 | rect->top = rect->left = 0;
|
---|
553 | rect->right = rectWindow.right - rectWindow.left;
|
---|
554 | rect->bottom = rectWindow.bottom - rectWindow.top;
|
---|
555 |
|
---|
556 | if (dwStyle & WS_ICONIC) return;
|
---|
557 |
|
---|
558 | /* Remove frame from rectangle */
|
---|
559 | if (HAS_THICKFRAME(dwStyle,dwExStyle))
|
---|
560 | {
|
---|
561 | InflateRect( rect, -GetSystemMetrics(SM_CXSIZEFRAME), -GetSystemMetrics(SM_CYSIZEFRAME) );
|
---|
562 | }
|
---|
563 | else if (HAS_DLGFRAME(dwStyle,dwExStyle ))
|
---|
564 | {
|
---|
565 | InflateRect( rect, -GetSystemMetrics(SM_CXFIXEDFRAME), -GetSystemMetrics(SM_CYFIXEDFRAME));
|
---|
566 | }
|
---|
567 | else if (HAS_THINFRAME(dwStyle))
|
---|
568 | {
|
---|
569 | InflateRect( rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER) );
|
---|
570 | }
|
---|
571 |
|
---|
572 | /* We have additional border information if the window
|
---|
573 | * is a child (but not an MDI child) */
|
---|
574 | if ( (dwStyle & WS_CHILD) &&
|
---|
575 | ( (dwExStyle & WS_EX_MDICHILD) == 0 ) )
|
---|
576 | {
|
---|
577 | if (dwExStyle & WS_EX_CLIENTEDGE)
|
---|
578 | InflateRect (rect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE));
|
---|
579 |
|
---|
580 | if (dwExStyle & WS_EX_STATICEDGE)
|
---|
581 | InflateRect (rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
|
---|
582 | }
|
---|
583 | }
|
---|
584 | //******************************************************************************
|
---|
585 | //******************************************************************************
|
---|
586 | VOID Win32BaseWindow::DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active)
|
---|
587 | {
|
---|
588 | INT width, height;
|
---|
589 | HBRUSH oldBrush;
|
---|
590 |
|
---|
591 | if (dlgFrame)
|
---|
592 | {
|
---|
593 | width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
|
---|
594 | height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
|
---|
595 | }
|
---|
596 | else
|
---|
597 | {
|
---|
598 | width = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXEDGE);
|
---|
599 | height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYEDGE);
|
---|
600 | }
|
---|
601 |
|
---|
602 | oldBrush = SelectObject(hdc,GetSysColorBrush(active ? COLOR_ACTIVEBORDER:COLOR_INACTIVEBORDER));
|
---|
603 |
|
---|
604 | /* Draw frame */
|
---|
605 | PatBlt(hdc,rect->left, rect->top, rect->right-rect->left, height,PATCOPY);
|
---|
606 | PatBlt(hdc,rect->left, rect->top, width, rect->bottom-rect->top,PATCOPY);
|
---|
607 | PatBlt(hdc,rect->left, rect->bottom-1, rect->right-rect->left,-height,PATCOPY);
|
---|
608 | PatBlt(hdc,rect->right-1,rect->top, -width, rect->bottom-rect->top,PATCOPY);
|
---|
609 | SelectObject(hdc,oldBrush);
|
---|
610 |
|
---|
611 | InflateRect(rect,-width,-height);
|
---|
612 | }
|
---|
613 | //******************************************************************************
|
---|
614 | //******************************************************************************
|
---|
615 | BOOL Win32BaseWindow::DrawSysButton(HDC hdc,RECT *rect)
|
---|
616 | {
|
---|
617 | HICON hIcon;
|
---|
618 | RECT r;
|
---|
619 |
|
---|
620 | if (!rect) GetInsideRect(&r);
|
---|
621 | else r = *rect;
|
---|
622 |
|
---|
623 | hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICONSM);
|
---|
624 | if(!hIcon) hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICON);
|
---|
625 |
|
---|
626 | /* If there is no hIcon specified or this is not a modal dialog, */
|
---|
627 | /* get the default one. */
|
---|
628 | if(hIcon == 0)
|
---|
629 | if (!(dwStyle & DS_MODALFRAME))
|
---|
630 | hIcon = LoadImageA(0, MAKEINTRESOURCEA(OIC_ODINICON), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
---|
631 |
|
---|
632 | if (hIcon)
|
---|
633 | DrawIconEx(hdc,r.left+2,r.top+2,hIcon,
|
---|
634 | GetSystemMetrics(SM_CXSMICON),
|
---|
635 | GetSystemMetrics(SM_CYSMICON),
|
---|
636 | 0, 0, DI_NORMAL);
|
---|
637 |
|
---|
638 | return (hIcon != 0);
|
---|
639 | }
|
---|
640 | //******************************************************************************
|
---|
641 | //******************************************************************************
|
---|
642 | BOOL Win32BaseWindow::GetSysPopupPos(RECT* rect)
|
---|
643 | {
|
---|
644 | if(hSysMenu)
|
---|
645 | {
|
---|
646 | if(dwStyle & WS_MINIMIZE )
|
---|
647 | *rect = rectWindow;
|
---|
648 | else
|
---|
649 | {
|
---|
650 | GetInsideRect(rect );
|
---|
651 | OffsetRect( rect, rectWindow.left, rectWindow.top);
|
---|
652 | rect->right = rect->left + GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
653 | rect->bottom = rect->top + GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
654 | }
|
---|
655 | return TRUE;
|
---|
656 | }
|
---|
657 | return FALSE;
|
---|
658 | }
|
---|
659 | //******************************************************************************
|
---|
660 | //******************************************************************************
|
---|
661 | BOOL Win32BaseWindow::DrawGrayButton(HDC hdc,int x,int y)
|
---|
662 | {
|
---|
663 | HBITMAP hMaskBmp;
|
---|
664 | HDC hdcMask = CreateCompatibleDC (0);
|
---|
665 | HBRUSH hOldBrush;
|
---|
666 | hMaskBmp = CreateBitmap (12, 10, 1, 1, lpGrayMask);
|
---|
667 |
|
---|
668 | if(hMaskBmp == 0)
|
---|
669 | return FALSE;
|
---|
670 |
|
---|
671 | SelectObject (hdcMask, hMaskBmp);
|
---|
672 |
|
---|
673 | /* Draw the grayed bitmap using the mask */
|
---|
674 | hOldBrush = SelectObject (hdc, RGB(128, 128, 128));
|
---|
675 | BitBlt (hdc, x, y, 12, 10,
|
---|
676 | hdcMask, 0, 0, 0xB8074A);
|
---|
677 |
|
---|
678 | /* Clean up */
|
---|
679 | SelectObject (hdc, hOldBrush);
|
---|
680 | DeleteObject(hMaskBmp);
|
---|
681 | DeleteDC (hdcMask);
|
---|
682 |
|
---|
683 | return TRUE;
|
---|
684 | }
|
---|
685 | //******************************************************************************
|
---|
686 | //******************************************************************************
|
---|
687 | VOID Win32BaseWindow::DrawCloseButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed)
|
---|
688 | {
|
---|
689 | RECT r;
|
---|
690 | HDC hdcMem;
|
---|
691 | BITMAP bmp;
|
---|
692 | HBITMAP hBmp, hOldBmp;
|
---|
693 |
|
---|
694 | if (!rect) GetInsideRect(&r);
|
---|
695 | else r = *rect;
|
---|
696 |
|
---|
697 | hdcMem = CreateCompatibleDC( hdc );
|
---|
698 | hBmp = down ? hbitmapCloseD : hbitmapClose;
|
---|
699 | hOldBmp = SelectObject (hdcMem, hBmp);
|
---|
700 | GetObjectA (hBmp, sizeof(BITMAP), &bmp);
|
---|
701 |
|
---|
702 | BitBlt (hdc, r.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2,
|
---|
703 | r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
|
---|
704 | bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
|
---|
705 |
|
---|
706 | if(bGrayed)
|
---|
707 | DrawGrayButton(hdc,r.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2 + 2,
|
---|
708 | r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
|
---|
709 |
|
---|
710 | SelectObject (hdcMem, hOldBmp);
|
---|
711 | DeleteDC (hdcMem);
|
---|
712 | }
|
---|
713 | //******************************************************************************
|
---|
714 | //******************************************************************************
|
---|
715 | VOID Win32BaseWindow::DrawMaxButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed)
|
---|
716 | {
|
---|
717 | RECT r;
|
---|
718 | HDC hdcMem;
|
---|
719 | BITMAP bmp;
|
---|
720 | HBITMAP hBmp,hOldBmp;
|
---|
721 |
|
---|
722 | if (!rect) GetInsideRect(&r);
|
---|
723 | else r = *rect;
|
---|
724 | hdcMem = CreateCompatibleDC( hdc );
|
---|
725 | hBmp = IsZoomed(Win32Hwnd) ?
|
---|
726 | (down ? hbitmapRestoreD : hbitmapRestore ) :
|
---|
727 | (down ? hbitmapMaximizeD: hbitmapMaximize);
|
---|
728 | hOldBmp=SelectObject( hdcMem, hBmp );
|
---|
729 | GetObjectA (hBmp, sizeof(BITMAP), &bmp);
|
---|
730 |
|
---|
731 | if (dwStyle & WS_SYSMENU)
|
---|
732 | r.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
|
---|
733 |
|
---|
734 | BitBlt( hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
|
---|
735 | r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
|
---|
736 | bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
|
---|
737 |
|
---|
738 | if(bGrayed)
|
---|
739 | DrawGrayButton(hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
|
---|
740 | r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
|
---|
741 |
|
---|
742 | SelectObject (hdcMem, hOldBmp);
|
---|
743 | DeleteDC( hdcMem );
|
---|
744 | }
|
---|
745 | //******************************************************************************
|
---|
746 | //******************************************************************************
|
---|
747 | VOID Win32BaseWindow::DrawMinButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed)
|
---|
748 | {
|
---|
749 | RECT r;
|
---|
750 | HDC hdcMem;
|
---|
751 | BITMAP bmp;
|
---|
752 | HBITMAP hBmp,hOldBmp;
|
---|
753 |
|
---|
754 | if (!rect) GetInsideRect(&r);
|
---|
755 | else r = *rect;
|
---|
756 |
|
---|
757 | hdcMem = CreateCompatibleDC( hdc );
|
---|
758 | hBmp = down ? hbitmapMinimizeD : hbitmapMinimize;
|
---|
759 | hOldBmp= SelectObject( hdcMem, hBmp );
|
---|
760 | GetObjectA (hBmp, sizeof(BITMAP), &bmp);
|
---|
761 |
|
---|
762 | if (dwStyle & WS_SYSMENU)
|
---|
763 | r.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
|
---|
764 |
|
---|
765 | /* In win 95 there is always a Maximize box when there is a Minimize one */
|
---|
766 | if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX))
|
---|
767 | r.right -= bmp.bmWidth;
|
---|
768 |
|
---|
769 | BitBlt( hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
|
---|
770 | r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
|
---|
771 | bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
|
---|
772 |
|
---|
773 | if(bGrayed)
|
---|
774 | DrawGrayButton(hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
|
---|
775 | r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
|
---|
776 |
|
---|
777 |
|
---|
778 | SelectObject (hdcMem, hOldBmp);
|
---|
779 | DeleteDC( hdcMem );
|
---|
780 | }
|
---|
781 | //******************************************************************************
|
---|
782 | // redrawText: only redraws text
|
---|
783 | //******************************************************************************
|
---|
784 | VOID Win32BaseWindow::DrawCaption(HDC hdc,RECT *rect,BOOL active,BOOL redrawText)
|
---|
785 | {
|
---|
786 | RECT r = *rect,r2;
|
---|
787 | char buffer[256];
|
---|
788 | HPEN hPrevPen;
|
---|
789 | HDC memDC;
|
---|
790 | HBITMAP memBmp,oldBmp;
|
---|
791 |
|
---|
792 | memDC = CreateCompatibleDC(hdc);
|
---|
793 | r.right -= r.left;
|
---|
794 | r.bottom -= r.top;
|
---|
795 | r.left = r.top = 0;
|
---|
796 | r2 = r;
|
---|
797 | memBmp = CreateCompatibleBitmap(hdc,r.right,r.bottom);
|
---|
798 | oldBmp = SelectObject(memDC,memBmp);
|
---|
799 |
|
---|
800 | hPrevPen = SelectObject(memDC,GetSysColorPen(COLOR_3DFACE));
|
---|
801 | MoveToEx(memDC,r.left,r.bottom-1,NULL);
|
---|
802 | LineTo(memDC,r.right,r.bottom-1);
|
---|
803 | SelectObject(memDC,hPrevPen);
|
---|
804 | r.bottom--;
|
---|
805 |
|
---|
806 | if (SYSCOLOR_GetUseWinColors())
|
---|
807 | {
|
---|
808 | COLORREF startColor = GetSysColor(active ? COLOR_ACTIVECAPTION:COLOR_INACTIVECAPTION),endColor = GetSysColor(active ? COLOR_GRADIENTACTIVECAPTION:COLOR_GRADIENTINACTIVECAPTION);
|
---|
809 |
|
---|
810 | if (startColor == endColor)
|
---|
811 | FillRect(memDC,&r,GetSysColorBrush(startColor));
|
---|
812 | else
|
---|
813 | {
|
---|
814 | INT rDiff = GetRValue(endColor)-GetRValue(startColor);
|
---|
815 | INT gDiff = GetGValue(endColor)-GetGValue(startColor);
|
---|
816 | INT bDiff = GetBValue(endColor)-GetBValue(startColor);
|
---|
817 | INT steps = MAX(MAX(abs(rDiff),abs(gDiff)),abs(bDiff));
|
---|
818 | INT w = r.right-r.left;
|
---|
819 | RECT r2;
|
---|
820 |
|
---|
821 | if (w < steps) steps = w;
|
---|
822 | r2.left = r2.right = r.left;
|
---|
823 | r2.top = r.top;
|
---|
824 | r2.bottom = r.bottom;
|
---|
825 | for (INT x = 0;x <= steps;x++)
|
---|
826 | {
|
---|
827 | COLORREF color = RGB(GetRValue(startColor)+rDiff*x/steps,GetGValue(startColor)+gDiff*x/steps,GetBValue(startColor)+bDiff*x/steps);
|
---|
828 | HBRUSH brush = CreateSolidBrush(color);
|
---|
829 |
|
---|
830 | r2.left = r2.right;
|
---|
831 | r2.right = r.left+w*x/steps;
|
---|
832 | FillRect(memDC,&r2,brush);
|
---|
833 | DeleteObject(brush);
|
---|
834 | }
|
---|
835 | }
|
---|
836 | } else FillRect(memDC,&r,GetSysColorBrush(active ? COLOR_ACTIVECAPTION:COLOR_INACTIVECAPTION));
|
---|
837 |
|
---|
838 | if (!hbitmapClose)
|
---|
839 | {
|
---|
840 | if (!(hbitmapClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE)))) return;
|
---|
841 | hbitmapCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
|
---|
842 | hbitmapMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
|
---|
843 | hbitmapMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
|
---|
844 | hbitmapMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOM));
|
---|
845 | hbitmapMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOMD));
|
---|
846 | hbitmapRestore = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
|
---|
847 | hbitmapRestoreD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
|
---|
848 | }
|
---|
849 |
|
---|
850 | if ((dwStyle & WS_SYSMENU) && !(dwExStyle & WS_EX_TOOLWINDOW))
|
---|
851 | {
|
---|
852 | if (redrawText || DrawSysButton(memDC,&r))
|
---|
853 | r.left += GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
854 | }
|
---|
855 |
|
---|
856 | if (dwStyle & WS_SYSMENU)
|
---|
857 | {
|
---|
858 | UINT state;
|
---|
859 |
|
---|
860 | if (!redrawText)
|
---|
861 | {
|
---|
862 | /* Go get the sysmenu */
|
---|
863 | state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
|
---|
864 |
|
---|
865 | /* Draw a grayed close button if disabled and a normal one if SC_CLOSE is not there */
|
---|
866 | DrawCloseButton(memDC,&r2,FALSE,
|
---|
867 | ((((state & MF_DISABLED) || (state & MF_GRAYED))) && (state != 0xFFFFFFFF)));
|
---|
868 | }
|
---|
869 | r.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
870 |
|
---|
871 | if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX))
|
---|
872 | {
|
---|
873 | /* In win95 the two buttons are always there */
|
---|
874 | /* But if the menu item is not in the menu they're disabled*/
|
---|
875 |
|
---|
876 | if (!redrawText)
|
---|
877 | DrawMaxButton(memDC,&r2,FALSE,(!(dwStyle & WS_MAXIMIZEBOX)));
|
---|
878 | r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
|
---|
879 |
|
---|
880 | if (!redrawText)
|
---|
881 | DrawMinButton(memDC,&r2,FALSE, (!(dwStyle & WS_MINIMIZEBOX)));
|
---|
882 | r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
|
---|
883 | }
|
---|
884 | }
|
---|
885 |
|
---|
886 | if (GetWindowTextA(buffer, sizeof(buffer) ))
|
---|
887 | {
|
---|
888 | NONCLIENTMETRICSA nclm;
|
---|
889 | HFONT hFont, hOldFont;
|
---|
890 |
|
---|
891 | nclm.cbSize = sizeof(NONCLIENTMETRICSA);
|
---|
892 | SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
|
---|
893 | if (dwExStyle & WS_EX_TOOLWINDOW)
|
---|
894 | hFont = CreateFontIndirectA (&nclm.lfSmCaptionFont);
|
---|
895 | else
|
---|
896 | hFont = CreateFontIndirectA (&nclm.lfCaptionFont);
|
---|
897 | hOldFont = SelectObject (memDC, hFont);
|
---|
898 | SetTextColor(memDC,GetSysColor(active ? COLOR_CAPTIONTEXT:COLOR_INACTIVECAPTIONTEXT));
|
---|
899 | SetBkMode(memDC, TRANSPARENT );
|
---|
900 | r.left += 2;
|
---|
901 | DrawTextA(memDC, buffer, -1, &r,
|
---|
902 | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT );
|
---|
903 | DeleteObject (SelectObject (memDC, hOldFont));
|
---|
904 | }
|
---|
905 |
|
---|
906 | BitBlt(hdc,rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top,memDC,0,0,SRCCOPY);
|
---|
907 | SelectObject(memDC,oldBmp);
|
---|
908 | DeleteObject(memBmp);
|
---|
909 | DeleteDC(memDC);
|
---|
910 | }
|
---|
911 | //******************************************************************************
|
---|
912 | //******************************************************************************
|
---|
913 | VOID Win32BaseWindow::DoNCPaint(HRGN clip,BOOL suppress_menupaint)
|
---|
914 | {
|
---|
915 | BOOL active = flags & WIN_NCACTIVATED;
|
---|
916 | HDC hdc;
|
---|
917 | RECT rect,rectClip,rfuzz;
|
---|
918 |
|
---|
919 | /* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in
|
---|
920 | the call to GetDCEx implying that it is allowed not to use it either.
|
---|
921 | However, the suggested GetDCEx( , DCX_WINDOW | DCX_INTERSECTRGN)
|
---|
922 | will cause clipRgn to be deleted after ReleaseDC().
|
---|
923 | Now, how is the "system" supposed to tell what happened?
|
---|
924 | */
|
---|
925 |
|
---|
926 | dprintf(("DoNCPaint %x %x %d", getWindowHandle(), clip, suppress_menupaint));
|
---|
927 |
|
---|
928 | if (!(hdc = GetDCEx( Win32Hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
|
---|
929 | ((clip > 1) ?(DCX_INTERSECTRGN /*| DCX_KEEPCLIPRGN*/) : 0) ))) return;
|
---|
930 |
|
---|
931 | rect.top = rect.left = 0;
|
---|
932 | rect.right = rectWindow.right - rectWindow.left;
|
---|
933 | rect.bottom = rectWindow.bottom - rectWindow.top;
|
---|
934 |
|
---|
935 | if (clip > 1)
|
---|
936 | {
|
---|
937 | //only redraw caption
|
---|
938 | GetRgnBox(clip,&rectClip);
|
---|
939 | }
|
---|
940 | else
|
---|
941 | {
|
---|
942 | clip = 0;
|
---|
943 | rectClip = rect;
|
---|
944 | }
|
---|
945 |
|
---|
946 | SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
|
---|
947 |
|
---|
948 | if (HAS_BIGFRAME( dwStyle, dwExStyle))
|
---|
949 | {
|
---|
950 | DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST);
|
---|
951 | }
|
---|
952 | if (HAS_THICKFRAME( dwStyle, dwExStyle ))
|
---|
953 | DrawFrame(hdc, &rect, FALSE, active );
|
---|
954 | else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
---|
955 | DrawFrame( hdc, &rect, TRUE, active );
|
---|
956 | else if (HAS_THINFRAME( dwStyle ))
|
---|
957 | {
|
---|
958 | SelectObject( hdc, GetStockObject(NULL_BRUSH) );
|
---|
959 | Rectangle( hdc, 0, 0, rect.right, rect.bottom );
|
---|
960 | }
|
---|
961 |
|
---|
962 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
963 | {
|
---|
964 | RECT r = rect;
|
---|
965 | if (dwExStyle & WS_EX_TOOLWINDOW)
|
---|
966 | {
|
---|
967 | r.bottom = rect.top + GetSystemMetrics(SM_CYSMCAPTION);
|
---|
968 | rect.top += GetSystemMetrics(SM_CYSMCAPTION);
|
---|
969 | }
|
---|
970 | else
|
---|
971 | {
|
---|
972 | r.bottom = rect.top + GetSystemMetrics(SM_CYCAPTION);
|
---|
973 | rect.top += GetSystemMetrics(SM_CYCAPTION);
|
---|
974 | }
|
---|
975 | if( !clip || IntersectRect( &rfuzz, &r, &rectClip ) )
|
---|
976 | DrawCaption(hdc,&r,active,FALSE);
|
---|
977 | }
|
---|
978 |
|
---|
979 | if (HAS_MENU())
|
---|
980 | {
|
---|
981 | RECT r = rect;
|
---|
982 | r.bottom = rect.top + GetSystemMetrics(SM_CYMENU);
|
---|
983 |
|
---|
984 | rect.top += MENU_DrawMenuBar(hdc,&r,Win32Hwnd,suppress_menupaint)+1;
|
---|
985 | }
|
---|
986 |
|
---|
987 | if (dwExStyle & WS_EX_CLIENTEDGE)
|
---|
988 | DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
|
---|
989 |
|
---|
990 | if (dwExStyle & WS_EX_STATICEDGE)
|
---|
991 | DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
|
---|
992 |
|
---|
993 | /* Draw the scroll-bars */
|
---|
994 | if (dwStyle & WS_VSCROLL)
|
---|
995 | SCROLL_DrawScrollBar(Win32Hwnd,hdc,SB_VERT,TRUE,TRUE);
|
---|
996 | if (dwStyle & WS_HSCROLL)
|
---|
997 | SCROLL_DrawScrollBar(Win32Hwnd,hdc,SB_HORZ,TRUE,TRUE);
|
---|
998 |
|
---|
999 | /* Draw the "size-box" */
|
---|
1000 | if ((dwStyle & WS_VSCROLL) && (dwStyle & WS_HSCROLL))
|
---|
1001 | {
|
---|
1002 | RECT r = rect;
|
---|
1003 | r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1;
|
---|
1004 | r.top = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1;
|
---|
1005 | FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) );
|
---|
1006 | if (!(dwStyle & WS_CHILD))
|
---|
1007 | {
|
---|
1008 | POINT p1,p2;
|
---|
1009 | HPEN penDark = GetSysColorPen(COLOR_3DSHADOW);
|
---|
1010 | HPEN penWhite = GetSysColorPen(COLOR_3DHILIGHT);
|
---|
1011 | HPEN oldPen = SelectObject(hdc,penDark);
|
---|
1012 | INT x;
|
---|
1013 |
|
---|
1014 | p1.x = r.right-1;
|
---|
1015 | p1.y = r.bottom;
|
---|
1016 | p2.x = r.right;
|
---|
1017 | p2.y = r.bottom-1;
|
---|
1018 | for (x = 0;x < 3;x++)
|
---|
1019 | {
|
---|
1020 | SelectObject(hdc,penDark);
|
---|
1021 | MoveToEx(hdc,p1.x,p1.y,NULL);
|
---|
1022 | LineTo(hdc,p2.x,p2.y);
|
---|
1023 | p1.x--;
|
---|
1024 | p2.y--;
|
---|
1025 | MoveToEx(hdc,p1.x,p1.y,NULL);
|
---|
1026 | LineTo(hdc,p2.x,p2.y);
|
---|
1027 | SelectObject(hdc,penWhite);
|
---|
1028 | p1.x--;
|
---|
1029 | p2.y--;
|
---|
1030 | MoveToEx(hdc,p1.x,p1.y,NULL);
|
---|
1031 | LineTo(hdc,p2.x,p2.y);
|
---|
1032 | p1.x -= 2;
|
---|
1033 | p2.y -= 2;
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | SelectObject(hdc,oldPen);
|
---|
1037 | }
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | ReleaseDC(Win32Hwnd,hdc);
|
---|
1041 | dprintf(("**DoNCPaint %x DONE", getWindowHandle()));
|
---|
1042 | }
|
---|
1043 | //******************************************************************************
|
---|
1044 | //******************************************************************************
|
---|
1045 | LONG Win32BaseWindow::HandleNCPaint(HRGN clip)
|
---|
1046 | {
|
---|
1047 | //CB: ignore it for now (SetWindowPos in WM_CREATE)
|
---|
1048 | // if (!(dwStyle & WS_VISIBLE)) return 0;
|
---|
1049 |
|
---|
1050 | if (dwStyle & WS_MINIMIZE) return 0;
|
---|
1051 |
|
---|
1052 | DoNCPaint(clip,FALSE);
|
---|
1053 |
|
---|
1054 | return 0;
|
---|
1055 | }
|
---|
1056 | /***********************************************************************
|
---|
1057 | * NC_HandleNCLButtonDblClk
|
---|
1058 | *
|
---|
1059 | * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
|
---|
1060 | */
|
---|
1061 | LONG Win32BaseWindow::HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam)
|
---|
1062 | {
|
---|
1063 | /*
|
---|
1064 | * if this is an icon, send a restore since we are handling
|
---|
1065 | * a double click
|
---|
1066 | */
|
---|
1067 | if (dwStyle & WS_MINIMIZE)
|
---|
1068 | {
|
---|
1069 | SendInternalMessageA(WM_SYSCOMMAND,SC_RESTORE,lParam);
|
---|
1070 | return 0;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | switch(wParam) /* Hit test */
|
---|
1074 | {
|
---|
1075 | case HTCAPTION:
|
---|
1076 | /* stop processing if WS_MAXIMIZEBOX is missing */
|
---|
1077 | if (dwStyle & WS_MAXIMIZEBOX)
|
---|
1078 | SendInternalMessageA(WM_SYSCOMMAND,
|
---|
1079 | (dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
|
---|
1080 | lParam);
|
---|
1081 | break;
|
---|
1082 |
|
---|
1083 | case HTSYSMENU:
|
---|
1084 | if (!(GetClassWord(Win32Hwnd,GCW_STYLE) & CS_NOCLOSE))
|
---|
1085 | SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
|
---|
1086 | break;
|
---|
1087 |
|
---|
1088 | case HTHSCROLL:
|
---|
1089 | SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
|
---|
1090 | break;
|
---|
1091 |
|
---|
1092 | case HTVSCROLL:
|
---|
1093 | SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
|
---|
1094 | break;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | return 0;
|
---|
1098 | }
|
---|
1099 | //******************************************************************************
|
---|
1100 | //******************************************************************************
|
---|
1101 | LONG Win32BaseWindow::HandleNCRButtonUp(WPARAM wParam,LPARAM lParam)
|
---|
1102 | {
|
---|
1103 | switch(wParam)
|
---|
1104 | {
|
---|
1105 | case HTCAPTION:
|
---|
1106 | if (GetActiveWindow() != Win32Hwnd)
|
---|
1107 | SetActiveWindow();
|
---|
1108 |
|
---|
1109 | if (((GetActiveWindow() == Win32Hwnd) || isMDIChild()) && (dwStyle & WS_SYSMENU))
|
---|
1110 | {
|
---|
1111 | SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTCAPTION,lParam);
|
---|
1112 | }
|
---|
1113 | break;
|
---|
1114 |
|
---|
1115 | default:
|
---|
1116 | break;
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | return 0;
|
---|
1120 | }
|
---|
1121 | /***********************************************************************
|
---|
1122 | * NC_HandleSysCommand
|
---|
1123 | *
|
---|
1124 | * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
|
---|
1125 | *
|
---|
1126 | */
|
---|
1127 | LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam,POINT *pt32)
|
---|
1128 | {
|
---|
1129 | UINT uCommand = wParam & 0xFFF0;
|
---|
1130 |
|
---|
1131 | switch (uCommand)
|
---|
1132 | {
|
---|
1133 |
|
---|
1134 | case SC_SIZE:
|
---|
1135 | {
|
---|
1136 | DWORD flags;
|
---|
1137 |
|
---|
1138 | if (dwStyle & WS_MAXIMIZE) break;
|
---|
1139 |
|
---|
1140 | switch ((wParam & 0xF)+2)
|
---|
1141 | {
|
---|
1142 | case HTLEFT:
|
---|
1143 | flags = TFOS_LEFT;
|
---|
1144 | break;
|
---|
1145 |
|
---|
1146 | case HTRIGHT:
|
---|
1147 | flags = TFOS_RIGHT;
|
---|
1148 | break;
|
---|
1149 |
|
---|
1150 | case HTTOP:
|
---|
1151 | flags = TFOS_TOP;
|
---|
1152 | break;
|
---|
1153 |
|
---|
1154 | case HTTOPLEFT:
|
---|
1155 | flags = TFOS_TOP | TFOS_LEFT;
|
---|
1156 | break;
|
---|
1157 |
|
---|
1158 | case HTTOPRIGHT:
|
---|
1159 | flags = TFOS_TOP | TFOS_RIGHT;
|
---|
1160 | break;
|
---|
1161 |
|
---|
1162 | case HTBOTTOM:
|
---|
1163 | flags = TFOS_BOTTOM;
|
---|
1164 | break;
|
---|
1165 |
|
---|
1166 | case HTBOTTOMLEFT:
|
---|
1167 | flags = TFOS_BOTTOM | TFOS_LEFT;
|
---|
1168 | break;
|
---|
1169 |
|
---|
1170 | case HTBOTTOMRIGHT:
|
---|
1171 | flags = TFOS_BOTTOM | TFOS_RIGHT;
|
---|
1172 | break;
|
---|
1173 |
|
---|
1174 | default:
|
---|
1175 | flags = TFOS_BOTTOM | TFOS_RIGHT;
|
---|
1176 | break;
|
---|
1177 | }
|
---|
1178 | if (flags) FrameTrackFrame(this,flags);
|
---|
1179 | break;
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | case SC_MOVE:
|
---|
1183 | if (dwStyle & WS_MAXIMIZE) break;
|
---|
1184 | FrameTrackFrame(this,TFOS_MOVE);
|
---|
1185 | break;
|
---|
1186 |
|
---|
1187 | case SC_MINIMIZE:
|
---|
1188 | ShowWindow(SW_MINIMIZE);
|
---|
1189 | break;
|
---|
1190 |
|
---|
1191 | case SC_MAXIMIZE:
|
---|
1192 | ShowWindow(SW_MAXIMIZE);
|
---|
1193 | break;
|
---|
1194 |
|
---|
1195 | case SC_RESTORE:
|
---|
1196 | ShowWindow(SW_RESTORE);
|
---|
1197 | break;
|
---|
1198 |
|
---|
1199 | case SC_CLOSE:
|
---|
1200 | return SendInternalMessageA(WM_CLOSE,0,0);
|
---|
1201 |
|
---|
1202 | case SC_VSCROLL:
|
---|
1203 | case SC_HSCROLL:
|
---|
1204 | TrackScrollBar(wParam,*pt32);
|
---|
1205 | break;
|
---|
1206 |
|
---|
1207 | case SC_MOUSEMENU:
|
---|
1208 | MENU_TrackMouseMenuBar(Win32Hwnd,wParam & 0x000F,*pt32);
|
---|
1209 | break;
|
---|
1210 |
|
---|
1211 | case SC_KEYMENU:
|
---|
1212 | MENU_TrackKbdMenuBar(Win32Hwnd,wParam,pt32->x);
|
---|
1213 | break;
|
---|
1214 |
|
---|
1215 | case SC_TASKLIST:
|
---|
1216 | OSLibWinShowTaskList(getOS2FrameWindowHandle());
|
---|
1217 | break;
|
---|
1218 |
|
---|
1219 | case SC_SCREENSAVE:
|
---|
1220 | if (wParam == SC_ABOUTODIN) {
|
---|
1221 | if(ShellAboutA == 0) {
|
---|
1222 | HINSTANCE hShell32 = LoadLibraryA("SHELL32");
|
---|
1223 | if(hShell32 == 0)
|
---|
1224 | break;
|
---|
1225 | *(VOID **)&ShellAboutA = (VOID *)GetProcAddress(hShell32, "ShellAboutA");
|
---|
1226 | }
|
---|
1227 | ShellAboutA(Win32Hwnd,"Odin","Odin alpha release compiled with IBM VAC++",0);
|
---|
1228 | }
|
---|
1229 | else
|
---|
1230 | if (wParam == SC_PUTMARK)
|
---|
1231 | dprintf(("Mark requested by user\n"));
|
---|
1232 | break;
|
---|
1233 |
|
---|
1234 | case SC_HOTKEY:
|
---|
1235 | case SC_ARRANGE:
|
---|
1236 | case SC_NEXTWINDOW:
|
---|
1237 | case SC_PREVWINDOW:
|
---|
1238 | break;
|
---|
1239 | }
|
---|
1240 | return 0;
|
---|
1241 | }
|
---|
1242 | //******************************************************************************
|
---|
1243 | //******************************************************************************
|
---|