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