source: trunk/src/user32/win32wbasenonclient.cpp@ 5120

Last change on this file since 5120 was 4597, checked in by sandervl, 25 years ago

export selectClientArea for gdi32

File size: 45.7 KB
Line 
1/* $Id: win32wbasenonclient.cpp,v 1.26 2000-11-15 13:57:57 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 * Corel Version 20000212
9 *
10 * Copyright 1994 Alexandre Julliard
11 *
12 * TODO: Not thread/process safe
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <os2win.h>
18#include <win.h>
19#include <stdlib.h>
20#include <string.h>
21#include <stdarg.h>
22#include <assert.h>
23#include <misc.h>
24#include <heapstring.h>
25#include <win32wbase.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 DBG_LOCALLOG DBG_win32wbasenonclient
42#include "dbglocal.h"
43
44/* bits in the dwKeyData */
45#define KEYDATA_ALT 0x2000
46#define KEYDATA_PREVSTATE 0x4000
47
48static INT bitmapW = 16,bitmapH = 14;
49static HBITMAP hbitmapClose = 0;
50static HBITMAP hbitmapCloseD = 0;
51static HBITMAP hbitmapMinimize = 0;
52static HBITMAP hbitmapMinimizeD = 0;
53static HBITMAP hbitmapMaximize = 0;
54static HBITMAP hbitmapMaximizeD = 0;
55static HBITMAP hbitmapRestore = 0;
56static HBITMAP hbitmapRestoreD = 0;
57static HBITMAP hbitmapContextHelp = 0;
58static HBITMAP hbitmapContextHelpD = 0;
59
60BYTE lpGrayMask[] = { 0xAA, 0xA0,
61 0x55, 0x50,
62 0xAA, 0xA0,
63 0x55, 0x50,
64 0xAA, 0xA0,
65 0x55, 0x50,
66 0xAA, 0xA0,
67 0x55, 0x50,
68 0xAA, 0xA0,
69 0x55, 0x50};
70
71static INT (* WINAPI ShellAboutA)(HWND,LPCSTR,LPCSTR,HICON) = 0;
72
73//******************************************************************************
74//******************************************************************************
75LONG Win32BaseWindow::HandleNCActivate(WPARAM wParam)
76{
77 WORD wStateChange;
78
79 if( wParam ) wStateChange = !(flags & WIN_NCACTIVATED);
80 else wStateChange = flags & WIN_NCACTIVATED;
81
82 if( wStateChange )
83 {
84 if (wParam) flags |= WIN_NCACTIVATED;
85 else flags &= ~WIN_NCACTIVATED;
86
87 if (!(dwStyle & WS_CAPTION)) return TRUE;
88
89 if(!(dwStyle & WS_MINIMIZE))
90 DoNCPaint((HRGN)1,FALSE);
91 }
92
93 return TRUE;
94}
95//******************************************************************************
96//******************************************************************************
97VOID Win32BaseWindow::TrackMinMaxHelpBox(WORD wParam)
98{
99 MSG msg;
100 HDC hdc;
101 BOOL pressed = TRUE;
102 UINT state;
103
104 if (wParam == HTMINBUTTON)
105 {
106 /* If the style is not present, do nothing */
107 if (!(dwStyle & WS_MINIMIZEBOX))
108 return;
109 /* Check if the sysmenu item for minimize is there */
110 state = GetMenuState(hSysMenu,SC_MINIMIZE,MF_BYCOMMAND);
111 } else if (wParam == HTMAXBUTTON)
112 {
113 /* If the style is not present, do nothing */
114 if (!(dwStyle & WS_MAXIMIZEBOX))
115 return;
116 /* Check if the sysmenu item for maximize is there */
117 state = GetMenuState(hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
118 } else state = 0;
119 SetCapture(Win32Hwnd);
120 hdc = GetWindowDC(Win32Hwnd);
121 if (wParam == HTMINBUTTON)
122 DrawMinButton(hdc,NULL,TRUE,FALSE);
123 else if (wParam == HTMAXBUTTON)
124 DrawMaxButton(hdc,NULL,TRUE,FALSE);
125 else
126 DrawContextHelpButton(hdc,NULL,TRUE,FALSE);
127 do
128 {
129 BOOL oldstate = pressed;
130
131 GetMessageA(&msg,Win32Hwnd,0,0);
132 pressed = (HandleNCHitTest(msg.pt) == wParam);
133 if (pressed != oldstate)
134 {
135 if (wParam == HTMINBUTTON)
136 DrawMinButton(hdc,NULL,pressed,FALSE);
137 else if (wParam == HTMAXBUTTON)
138 DrawMaxButton(hdc,NULL,pressed,FALSE);
139 else
140 DrawContextHelpButton(hdc,NULL,pressed,FALSE);
141 }
142 } while (msg.message != WM_LBUTTONUP);
143 if (wParam == HTMINBUTTON)
144 DrawMinButton(hdc,NULL,FALSE,FALSE);
145 else if (wParam == HTMAXBUTTON)
146 DrawMaxButton(hdc,NULL,FALSE,FALSE);
147 else
148 DrawContextHelpButton(hdc,NULL,FALSE,FALSE);
149 ReleaseCapture();
150 ReleaseDC(Win32Hwnd,hdc);
151 /* If the item minimize or maximize of the sysmenu are not there */
152 /* or if the style is not present, do nothing */
153 if ((!pressed) || (state == 0xFFFFFFFF))
154 return;
155
156 if (wParam == HTMINBUTTON)
157 SendInternalMessageA(WM_SYSCOMMAND,SC_MINIMIZE,*(LPARAM*)&msg.pt);
158 else if (wParam == HTMAXBUTTON)
159 SendInternalMessageA(WM_SYSCOMMAND,IsZoomed(Win32Hwnd) ? SC_RESTORE:SC_MAXIMIZE,*(LPARAM*)&msg.pt);
160 else
161 SendInternalMessageA(WM_SYSCOMMAND,SC_CONTEXTHELP,*(LPARAM*)&msg.pt);
162}
163//******************************************************************************
164//******************************************************************************
165VOID Win32BaseWindow::TrackCloseButton(WORD wParam)
166{
167 MSG msg;
168 HDC hdc;
169 BOOL pressed = TRUE;
170 UINT state;
171
172 if (hSysMenu == 0)
173 return;
174 state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
175 /* If the item close of the sysmenu is disabled or not there do nothing */
176 if((state & MF_DISABLED) || (state & MF_GRAYED) || (state == 0xFFFFFFFF))
177 return;
178 hdc = GetWindowDC(Win32Hwnd);
179 SetCapture(Win32Hwnd);
180 DrawCloseButton(hdc,NULL,TRUE,FALSE);
181 do
182 {
183 BOOL oldstate = pressed;
184
185 GetMessageA(&msg,Win32Hwnd,0,0);
186 pressed = (HandleNCHitTest(msg.pt) == wParam);
187 if (pressed != oldstate)
188 DrawCloseButton(hdc,NULL,pressed,FALSE);
189 } while (msg.message != WM_LBUTTONUP);
190 DrawCloseButton(hdc,NULL,FALSE,FALSE);
191 ReleaseCapture();
192 ReleaseDC(Win32Hwnd,hdc);
193 if (!pressed) return;
194 SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,*(LPARAM*)&msg.pt);
195}
196//******************************************************************************
197//******************************************************************************
198VOID Win32BaseWindow::TrackScrollBar(WPARAM wParam,POINT pt)
199{
200 INT scrollbar;
201 MSG msg;
202
203 if ((wParam & 0xfff0) == SC_HSCROLL)
204 {
205 if ((wParam & 0x0f) != HTHSCROLL) return;
206 scrollbar = SB_HORZ;
207 } else /* SC_VSCROLL */
208 {
209 if ((wParam & 0x0f) != HTVSCROLL) return;
210 scrollbar = SB_VERT;
211 }
212
213 ScreenToClient(getWindowHandle(), &pt);
214 pt.x += rectClient.left;
215 pt.y += rectClient.top;
216
217 SCROLL_HandleScrollEvent(getWindowHandle(),0,MAKELONG(pt.x,pt.y),scrollbar,WM_LBUTTONDOWN);
218 if (GetCapture() != Win32Hwnd) return;
219 do
220 {
221 GetMessageA(&msg, 0, 0, 0);
222 if(msg.hwnd == getWindowHandle())
223 {
224 switch(msg.message)
225 {
226 case WM_LBUTTONUP:
227 case WM_MOUSEMOVE:
228 pt.x = msg.pt.x;
229 pt.y = msg.pt.y;
230 ScreenToClient(getWindowHandle(), &pt);
231 pt.x += rectClient.left;
232 pt.y += rectClient.top;
233 msg.lParam = MAKELONG(pt.x,pt.y);
234
235 case WM_SYSTIMER:
236 SCROLL_HandleScrollEvent(Win32Hwnd,msg.wParam,msg.lParam,scrollbar,msg.message);
237 break;
238
239 default:
240 TranslateMessage(&msg);
241 DispatchMessageA(&msg);
242 break;
243 }
244 }
245 else {
246 TranslateMessage(&msg);
247 DispatchMessageA(&msg);
248 }
249 if (!IsWindow())
250 {
251 ReleaseCapture();
252 break;
253 }
254 } while (msg.message != WM_LBUTTONUP);
255}
256//******************************************************************************
257//******************************************************************************
258LONG Win32BaseWindow::HandleNCLButtonDown(WPARAM wParam,LPARAM lParam)
259{
260 switch(wParam) /* Hit test */
261 {
262 case HTCAPTION:
263 {
264 Win32BaseWindow *topparent = GetTopParent();
265
266 if (GetActiveWindow() != topparent->getWindowHandle())
267 {
268 //SvL: Calling topparent->SetActiveWindow() causes focus problems
269// topparent->SetActiveWindow();
270 OSLibWinSetFocus(topparent->getOS2WindowHandle());
271 }
272
273 if (GetActiveWindow() == topparent->getWindowHandle())
274 SendInternalMessageA(WM_SYSCOMMAND,SC_MOVE+HTCAPTION,lParam);
275 else dprintf(("ACtive window (%x) != toplevel wnd %x", OSLibWinQueryActiveWindow(), topparent->getWindowHandle()));
276 break;
277 }
278
279 case HTSYSMENU:
280 if(dwStyle & WS_SYSMENU )
281 {
282 SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTSYSMENU,lParam);
283 }
284 break;
285
286 case HTMENU:
287 SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU,lParam);
288 break;
289
290 case HTHSCROLL:
291 SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
292 break;
293
294 case HTVSCROLL:
295 SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
296 break;
297
298 case HTMINBUTTON:
299 case HTMAXBUTTON:
300 case HTHELP:
301 TrackMinMaxHelpBox(wParam);
302 break;
303
304 case HTCLOSE:
305 TrackCloseButton(wParam);
306 break;
307
308 case HTLEFT:
309 case HTRIGHT:
310 case HTTOP:
311 case HTTOPLEFT:
312 case HTTOPRIGHT:
313 case HTBOTTOM:
314 case HTBOTTOMLEFT:
315 case HTBOTTOMRIGHT:
316 /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */
317 SendInternalMessageA(WM_SYSCOMMAND,SC_SIZE+wParam-2,lParam);
318 break;
319 case HTBORDER:
320 break;
321 }
322
323 return 0;
324}
325//******************************************************************************
326//******************************************************************************
327VOID Win32BaseWindow::AdjustMaximizedRect(LPRECT rect)
328{
329 if (HAS_THICKFRAME(dwStyle,dwExStyle ))
330 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
331 else
332 if (HAS_DLGFRAME( dwStyle, dwExStyle ))
333 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
334 else
335 if (HAS_THINFRAME( dwStyle ))
336 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
337}
338//******************************************************************************
339//******************************************************************************
340VOID Win32BaseWindow::AdjustTrackInfo(PPOINT minTrackSize,PPOINT maxTrackSize)
341{
342 if ((dwStyle & WS_THICKFRAME) || !(dwStyle & (WS_POPUP | WS_CHILD)))
343 GetMinMaxInfo(NULL,NULL,minTrackSize,maxTrackSize);
344}
345//******************************************************************************
346//******************************************************************************
347VOID Win32BaseWindow::AdjustRectOuter(LPRECT rect,BOOL menu)
348{
349 if(dwStyle & WS_ICONIC) return;
350
351 if (HAS_THICKFRAME(dwStyle,dwExStyle ))
352 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
353 else
354 if (HAS_DLGFRAME( dwStyle, dwExStyle ))
355 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
356 else
357 if (HAS_THINFRAME( dwStyle ))
358 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
359
360 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
361 {
362 if (dwExStyle & WS_EX_TOOLWINDOW)
363 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
364 else
365 rect->top -= GetSystemMetrics(SM_CYCAPTION);
366 }
367
368 if (menu)
369 rect->top -= GetSystemMetrics(SM_CYMENU);
370}
371//******************************************************************************
372//******************************************************************************
373VOID Win32BaseWindow::AdjustRectInner(LPRECT rect)
374{
375 if(dwStyle & WS_ICONIC) return;
376
377 if (dwExStyle & WS_EX_CLIENTEDGE)
378 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
379
380 if (dwExStyle & WS_EX_STATICEDGE)
381 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
382
383 if (dwStyle & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
384 if (dwStyle & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
385}
386//******************************************************************************
387//******************************************************************************
388LONG Win32BaseWindow::HandleNCCalcSize(BOOL calcValidRects,RECT *winRect)
389{
390 RECT tmpRect = { 0, 0, 0, 0 };
391 LONG result = 0;
392 UINT style;
393
394 dprintf(("Default WM_NCCALCSIZE handler"));
395
396 if (!calcValidRects) return 0;
397
398 style = (UINT) GetClassLongA(Win32Hwnd,GCL_STYLE);
399
400 if (style & CS_VREDRAW) result |= WVR_VREDRAW;
401 if (style & CS_HREDRAW) result |= WVR_HREDRAW;
402
403 if(!(dwStyle & WS_MINIMIZE))
404 {
405 AdjustRectOuter(&tmpRect,FALSE);
406
407 winRect->left -= tmpRect.left;
408 winRect->top -= tmpRect.top;
409 winRect->right -= tmpRect.right;
410 winRect->bottom -= tmpRect.bottom;
411
412 if (HAS_MENU())
413 {
414 winRect->top +=
415 MENU_GetMenuBarHeight(Win32Hwnd,
416 winRect->right - winRect->left,
417 -tmpRect.left, -tmpRect.top ) + 1;
418 }
419
420 SetRect (&tmpRect, 0, 0, 0, 0);
421 AdjustRectInner(&tmpRect);
422 winRect->left -= tmpRect.left;
423 winRect->top -= tmpRect.top;
424 winRect->right -= tmpRect.right;
425 winRect->bottom -= tmpRect.bottom;
426
427 if (winRect->top > winRect->bottom)
428 winRect->bottom = winRect->top;
429
430 if (winRect->left > winRect->right)
431 winRect->right = winRect->left;
432 }
433
434 return result;
435}
436//******************************************************************************
437//******************************************************************************
438LONG Win32BaseWindow::HandleNCHitTest(POINT pt)
439{
440 RECT rect;
441
442 if (dwStyle & WS_MINIMIZE) return HTCAPTION;
443
444 GetWindowRect(getWindowHandle(), &rect);
445
446 if (!PtInRect(&rect,pt)) return HTNOWHERE;
447
448 /* Check borders */
449 if (HAS_THICKFRAME(dwStyle,dwExStyle))
450 {
451 InflateRect(&rect,-GetSystemMetrics(SM_CXFRAME),-GetSystemMetrics(SM_CYFRAME));
452 if (!PtInRect(&rect,pt))
453 {
454 /* Check top sizing border */
455 if (pt.y < rect.top)
456 {
457 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTTOPLEFT;
458 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTTOPRIGHT;
459 return HTTOP;
460 }
461 /* Check bottom sizing border */
462 if (pt.y >= rect.bottom)
463 {
464 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMLEFT;
465 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMRIGHT;
466 return HTBOTTOM;
467 }
468 /* Check left sizing border */
469 if (pt.x < rect.left)
470 {
471 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPLEFT;
472 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMLEFT;
473 return HTLEFT;
474 }
475 /* Check right sizing border */
476 if (pt.x >= rect.right)
477 {
478 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPRIGHT;
479 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMRIGHT;
480 return HTRIGHT;
481 }
482 }
483 } else /* No thick frame */
484 {
485 if (HAS_DLGFRAME(dwStyle,dwExStyle))
486 InflateRect(&rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
487 else if (HAS_THINFRAME(dwStyle ))
488 InflateRect(&rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
489 if (!PtInRect( &rect, pt )) return HTBORDER;
490 }
491
492 /* Check caption */
493
494 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
495 {
496 if (dwExStyle & WS_EX_TOOLWINDOW)
497 rect.top += GetSystemMetrics(SM_CYSMCAPTION)-1;
498 else
499 rect.top += GetSystemMetrics(SM_CYCAPTION)-1;
500 if (!PtInRect(&rect,pt))
501 {
502 /* Check system menu */
503 if(dwStyle & WS_SYSMENU)
504 {
505 /* Check if there is an user icon */
506 if (IconForWindow(ICON_SMALL))
507 rect.left += GetSystemMetrics(SM_CYCAPTION) - 1;
508 }
509 if (pt.x < rect.left) return HTSYSMENU;
510
511 /* Check close button */
512 if (dwStyle & WS_SYSMENU)
513 rect.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
514 if (pt.x > rect.right) return HTCLOSE;
515
516 //Check context help
517 if (dwExStyle & WS_EX_CONTEXTHELP)
518 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
519 if (pt.x > rect.right) return HTHELP;
520
521 /* Check maximize box */
522 /* In win95 there is automatically a Maximize button when there is a minimize one*/
523 if ((dwStyle & WS_MAXIMIZEBOX)|| (dwStyle & WS_MINIMIZEBOX))
524 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
525 if (pt.x > rect.right) return HTMAXBUTTON;
526
527 /* Check minimize box */
528 /* In win95 there is automatically a Maximize button when there is a Maximize one*/
529 if ((dwStyle & WS_MINIMIZEBOX)||(dwStyle & WS_MAXIMIZEBOX))
530 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
531
532 if (pt.x > rect.right) return HTMINBUTTON;
533 return HTCAPTION;
534 }
535 }
536
537 /* Check client area */
538
539 ScreenToClient(Win32Hwnd,&pt);
540 getClientRect(&rect);
541 if (PtInRect(&rect,pt)) return HTCLIENT;
542
543 /* Check vertical scroll bar */
544
545 if (dwStyle & WS_VSCROLL)
546 {
547 rect.right += GetSystemMetrics(SM_CXVSCROLL);
548 if (PtInRect( &rect, pt )) return HTVSCROLL;
549 }
550
551 /* Check horizontal scroll bar */
552
553 if (dwStyle & WS_HSCROLL)
554 {
555 rect.bottom += GetSystemMetrics(SM_CYHSCROLL);
556 if (PtInRect( &rect, pt ))
557 {
558 /* Check size box */
559 if ((dwStyle & WS_VSCROLL) &&
560 (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL)))
561 return (dwStyle & WS_CHILD) ? HTSIZE:HTBOTTOMRIGHT;
562 return HTHSCROLL;
563 }
564 }
565
566 /* Check menu bar */
567
568 if (HAS_MENU())
569 {
570 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
571 return HTMENU;
572 }
573
574 /* Has to return HTNOWHERE if nothing was found
575 Could happen when a window has a customized non client area */
576 return HTNOWHERE;
577}
578
579//******************************************************************************
580//******************************************************************************
581VOID Win32BaseWindow::GetInsideRect(RECT *rect)
582{
583 rect->top = rect->left = 0;
584 rect->right = rectWindow.right - rectWindow.left;
585 rect->bottom = rectWindow.bottom - rectWindow.top;
586
587 if (dwStyle & WS_ICONIC) return;
588
589 /* Remove frame from rectangle */
590 if (HAS_THICKFRAME(dwStyle,dwExStyle))
591 {
592 InflateRect( rect, -GetSystemMetrics(SM_CXSIZEFRAME), -GetSystemMetrics(SM_CYSIZEFRAME) );
593 }
594 else if (HAS_DLGFRAME(dwStyle,dwExStyle ))
595 {
596 InflateRect( rect, -GetSystemMetrics(SM_CXFIXEDFRAME), -GetSystemMetrics(SM_CYFIXEDFRAME));
597 }
598 else if (HAS_THINFRAME(dwStyle))
599 {
600 InflateRect( rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER) );
601 }
602
603 /* We have additional border information if the window
604 * is a child (but not an MDI child) */
605 if ( (dwStyle & WS_CHILD) &&
606 ( (dwExStyle & WS_EX_MDICHILD) == 0 ) )
607 {
608 if (dwExStyle & WS_EX_CLIENTEDGE)
609 InflateRect (rect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE));
610
611 if (dwExStyle & WS_EX_STATICEDGE)
612 InflateRect (rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
613 }
614}
615//******************************************************************************
616//******************************************************************************
617VOID Win32BaseWindow::DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active)
618{
619 INT width, height;
620 HBRUSH oldBrush;
621
622 if (dlgFrame)
623 {
624 width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
625 height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
626 }
627 else
628 {
629 width = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXEDGE);
630 height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYEDGE);
631 }
632
633 oldBrush = SelectObject(hdc,GetSysColorBrush(active ? COLOR_ACTIVEBORDER:COLOR_INACTIVEBORDER));
634
635 /* Draw frame */
636 PatBlt(hdc,rect->left, rect->top, rect->right-rect->left, height,PATCOPY); //top
637 PatBlt(hdc,rect->left, rect->top, width, rect->bottom-rect->top,PATCOPY); //left
638 PatBlt(hdc,rect->left, rect->bottom-1, rect->right-rect->left,-height,PATCOPY); //bottom
639 PatBlt(hdc,rect->right-1,rect->top, -width, rect->bottom-rect->top,PATCOPY); //right
640 SelectObject(hdc,oldBrush);
641
642 InflateRect(rect,-width,-height);
643}
644//******************************************************************************
645//******************************************************************************
646BOOL Win32BaseWindow::DrawSysButton(HDC hdc,RECT *rect)
647{
648 HICON hSysIcon;
649 RECT r;
650
651 if (!rect) GetInsideRect(&r);
652 else r = *rect;
653
654 hSysIcon = IconForWindow(ICON_SMALL);
655
656//CB: todo: add icons (including Odin icon) to user32.rc
657 if (hSysIcon)
658 DrawIconEx(hdc,r.left+2,r.top+2,hSysIcon,
659 GetSystemMetrics(SM_CXSMICON),
660 GetSystemMetrics(SM_CYSMICON),
661 0, 0, DI_NORMAL);
662
663 return (hSysIcon != 0);
664}
665//******************************************************************************
666//******************************************************************************
667BOOL Win32BaseWindow::GetSysPopupPos(RECT* rect)
668{
669 if(hSysMenu)
670 {
671 if(dwStyle & WS_MINIMIZE )
672 *rect = rectWindow;
673 else
674 {
675 GetInsideRect(rect );
676 OffsetRect( rect, rectWindow.left, rectWindow.top);
677 rect->right = rect->left + GetSystemMetrics(SM_CYCAPTION) - 1;
678 rect->bottom = rect->top + GetSystemMetrics(SM_CYCAPTION) - 1;
679 }
680 return TRUE;
681 }
682 return FALSE;
683}
684//******************************************************************************
685//******************************************************************************
686BOOL Win32BaseWindow::DrawGrayButton(HDC hdc,int x,int y)
687{
688 HBITMAP hMaskBmp;
689 HDC hdcMask = CreateCompatibleDC (0);
690 HBRUSH hOldBrush;
691 hMaskBmp = CreateBitmap (12, 10, 1, 1, lpGrayMask);
692
693 if(hMaskBmp == 0)
694 return FALSE;
695
696 SelectObject (hdcMask, hMaskBmp);
697
698 /* Draw the grayed bitmap using the mask */
699 hOldBrush = SelectObject (hdc, RGB(128, 128, 128));
700 BitBlt (hdc, x, y, 12, 10,
701 hdcMask, 0, 0, 0xB8074A);
702
703 /* Clean up */
704 SelectObject (hdc, hOldBrush);
705 DeleteObject(hMaskBmp);
706 DeleteDC (hdcMask);
707
708 return TRUE;
709}
710//******************************************************************************
711//******************************************************************************
712VOID Win32BaseWindow::DrawCloseButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed)
713{
714 RECT r;
715 HDC hdcMem;
716 BITMAP bmp;
717 HBITMAP hBmp, hOldBmp;
718
719 if (!rect) GetInsideRect(&r);
720 else r = *rect;
721
722 /* A tool window has a smaller Close button */
723 if (dwExStyle & WS_EX_TOOLWINDOW)
724 {
725 RECT toolRect;
726 INT iBmpHeight = 11; /* Windows does not use SM_CXSMSIZE and SM_CYSMSIZE */
727 INT iBmpWidth = 11; /* it uses 11x11 for the close button in tool window */
728 INT iCaptionHeight = GetSystemMetrics(SM_CYSMCAPTION);
729
730
731 toolRect.top = r.top + (iCaptionHeight - 1 - iBmpHeight) / 2;
732 toolRect.left = r.right - (iCaptionHeight + 1 + iBmpWidth) / 2;
733 toolRect.bottom = toolRect.top + iBmpHeight;
734 toolRect.right = toolRect.left + iBmpWidth;
735 DrawFrameControl(hdc,&toolRect,
736 DFC_CAPTION,DFCS_CAPTIONCLOSE |
737 down ? DFCS_PUSHED : 0 |
738 bGrayed ? DFCS_INACTIVE : 0);
739 } else
740 {
741 hdcMem = CreateCompatibleDC( hdc );
742 hBmp = down ? hbitmapCloseD : hbitmapClose;
743 hOldBmp = SelectObject (hdcMem, hBmp);
744 GetObjectA (hBmp, sizeof(BITMAP), &bmp);
745
746 BitBlt (hdc, r.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2,
747 r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
748 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
749
750 if(bGrayed)
751 DrawGrayButton(hdc,r.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2 + 2,
752 r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
753
754 SelectObject (hdcMem, hOldBmp);
755 DeleteDC (hdcMem);
756 }
757}
758//******************************************************************************
759//******************************************************************************
760VOID Win32BaseWindow::DrawMaxButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed)
761{
762 RECT r;
763 HDC hdcMem;
764 BITMAP bmp;
765 HBITMAP hBmp,hOldBmp;
766
767 if (!rect) GetInsideRect(&r);
768 else r = *rect;
769 hdcMem = CreateCompatibleDC( hdc );
770 hBmp = IsZoomed(Win32Hwnd) ?
771 (down ? hbitmapRestoreD : hbitmapRestore ) :
772 (down ? hbitmapMaximizeD: hbitmapMaximize);
773 hOldBmp = SelectObject( hdcMem, hBmp );
774 GetObjectA (hBmp, sizeof(BITMAP), &bmp);
775
776 if (dwStyle & WS_SYSMENU)
777 r.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
778
779 if (dwExStyle & WS_EX_CONTEXTHELP)
780 r.right -= bmp.bmWidth;
781
782 BitBlt( hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
783 r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
784 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
785
786 if(bGrayed)
787 DrawGrayButton(hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
788 r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
789
790 SelectObject (hdcMem, hOldBmp);
791 DeleteDC( hdcMem );
792}
793//******************************************************************************
794//******************************************************************************
795VOID Win32BaseWindow::DrawMinButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed)
796{
797 RECT r;
798 HDC hdcMem;
799 BITMAP bmp;
800 HBITMAP hBmp,hOldBmp;
801
802 if (!rect) GetInsideRect(&r);
803 else r = *rect;
804
805 hdcMem = CreateCompatibleDC( hdc );
806 hBmp = down ? hbitmapMinimizeD : hbitmapMinimize;
807 hOldBmp= SelectObject( hdcMem, hBmp );
808 GetObjectA (hBmp, sizeof(BITMAP), &bmp);
809
810 if (dwStyle & WS_SYSMENU)
811 r.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
812
813 if (dwExStyle & WS_EX_CONTEXTHELP)
814 r.right -= bmp.bmWidth;
815
816 /* In win 95 there is always a Maximize box when there is a Minimize one */
817 if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX))
818 r.right -= bmp.bmWidth;
819
820 BitBlt( hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
821 r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
822 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
823
824 if(bGrayed)
825 DrawGrayButton(hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
826 r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
827
828
829 SelectObject (hdcMem, hOldBmp);
830 DeleteDC( hdcMem );
831}
832//******************************************************************************
833//******************************************************************************
834VOID Win32BaseWindow::DrawContextHelpButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed)
835{
836 RECT r;
837 HDC hdcMem;
838 BITMAP bmp;
839 HBITMAP hBmp,hOldBmp;
840
841 if (!rect) GetInsideRect(&r);
842 else r = *rect;
843
844 hdcMem = CreateCompatibleDC(hdc);
845 hBmp = down ? hbitmapContextHelpD : hbitmapContextHelp;
846 hOldBmp = SelectObject(hdcMem,hBmp);
847 GetObjectA(hBmp,sizeof(BITMAP),&bmp);
848
849 if (dwStyle & WS_SYSMENU)
850 r.right -= GetSystemMetrics(SM_CYCAPTION)+1;
851
852 BitBlt( hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
853 r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
854 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
855
856 if(bGrayed)
857 DrawGrayButton(hdc, r.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
858 r.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
859
860
861 SelectObject (hdcMem, hOldBmp);
862 DeleteDC( hdcMem );
863}
864//******************************************************************************
865//******************************************************************************
866VOID Win32BaseWindow::DrawCaption(HDC hdc,RECT *rect,BOOL active)
867{
868 RECT r = *rect,r2;
869 char buffer[256];
870 HPEN hPrevPen;
871 HDC memDC;
872 HBITMAP memBmp,oldBmp;
873
874 memDC = CreateCompatibleDC(hdc);
875 r.right -= r.left;
876 r.bottom -= r.top;
877 r.left = r.top = 0;
878 r2 = r;
879 memBmp = CreateCompatibleBitmap(hdc,r.right,r.bottom);
880 oldBmp = SelectObject(memDC,memBmp);
881
882 hPrevPen = SelectObject(memDC,GetSysColorPen(COLOR_3DFACE));
883 MoveToEx(memDC,r.left,r.bottom-1,NULL);
884 LineTo(memDC,r.right,r.bottom-1);
885 SelectObject(memDC,hPrevPen);
886 r.bottom--;
887
888 if (SYSCOLOR_GetUseWinColors())
889 {
890 COLORREF startColor = GetSysColor(active ? COLOR_ACTIVECAPTION:COLOR_INACTIVECAPTION),endColor = GetSysColor(active ? COLOR_GRADIENTACTIVECAPTION:COLOR_GRADIENTINACTIVECAPTION);
891
892 if (startColor == endColor)
893 FillRect(memDC,&r,GetSysColorBrush(startColor));
894 else
895 {
896 INT rDiff = GetRValue(endColor)-GetRValue(startColor);
897 INT gDiff = GetGValue(endColor)-GetGValue(startColor);
898 INT bDiff = GetBValue(endColor)-GetBValue(startColor);
899 INT steps = MAX(MAX(abs(rDiff),abs(gDiff)),abs(bDiff));
900 INT w = r.right-r.left;
901 RECT r2;
902
903 if (w < steps) steps = w;
904 r2.left = r2.right = r.left;
905 r2.top = r.top;
906 r2.bottom = r.bottom;
907 for (INT x = 0;x <= steps;x++)
908 {
909 COLORREF color = RGB(GetRValue(startColor)+rDiff*x/steps,GetGValue(startColor)+gDiff*x/steps,GetBValue(startColor)+bDiff*x/steps);
910 HBRUSH brush = CreateSolidBrush(color);
911
912 r2.left = r2.right;
913 r2.right = r.left+w*x/steps;
914 FillRect(memDC,&r2,brush);
915 DeleteObject(brush);
916 }
917 }
918 } else FillRect(memDC,&r,GetSysColorBrush(active ? COLOR_ACTIVECAPTION:COLOR_INACTIVECAPTION));
919
920 if (!hbitmapClose)
921 {
922 if (!(hbitmapClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE)))) return;
923 hbitmapCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
924 hbitmapMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
925 hbitmapMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
926 hbitmapMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOM));
927 hbitmapMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOMD));
928 hbitmapRestore = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
929 hbitmapRestoreD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
930 hbitmapContextHelp = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CONTEXTHELP));
931 hbitmapContextHelpD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CONTEXTHELPD));
932 }
933
934 if ((dwStyle & WS_SYSMENU) && !(dwExStyle & WS_EX_TOOLWINDOW))
935 {
936 if (DrawSysButton(memDC,&r))
937 r.left += GetSystemMetrics(SM_CYCAPTION) - 1;
938 }
939
940 if (dwStyle & WS_SYSMENU)
941 {
942 UINT state;
943
944 /* Go get the sysmenu */
945 state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
946
947 /* Draw a grayed close button if disabled and a normal one if SC_CLOSE is not there */
948 DrawCloseButton(memDC,&r2,FALSE,
949 ((((state & MF_DISABLED) || (state & MF_GRAYED))) && (state != 0xFFFFFFFF)));
950 r.right -= GetSystemMetrics(SM_CYCAPTION)-1;
951
952 if (dwExStyle & WS_EX_CONTEXTHELP)
953 {
954 DrawContextHelpButton(memDC,&r2,FALSE,FALSE);
955 r.right -= GetSystemMetrics(SM_CXSIZE)+1;
956 }
957
958 if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX))
959 {
960 /* In win95 the two buttons are always there */
961 /* But if the menu item is not in the menu they're disabled*/
962
963 DrawMaxButton(memDC,&r2,FALSE,(!(dwStyle & WS_MAXIMIZEBOX)));
964 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
965
966 DrawMinButton(memDC,&r2,FALSE, (!(dwStyle & WS_MINIMIZEBOX)));
967 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
968 }
969 }
970
971 if (GetWindowTextA(buffer, sizeof(buffer) ))
972 {
973 NONCLIENTMETRICSA nclm;
974 HFONT hFont, hOldFont;
975
976 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
977 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
978 if (dwExStyle & WS_EX_TOOLWINDOW)
979 hFont = CreateFontIndirectA (&nclm.lfSmCaptionFont);
980 else
981 hFont = CreateFontIndirectA (&nclm.lfCaptionFont);
982 hOldFont = SelectObject (memDC, hFont);
983 SetTextColor(memDC,GetSysColor(active ? COLOR_CAPTIONTEXT:COLOR_INACTIVECAPTIONTEXT));
984 SetBkMode(memDC, TRANSPARENT );
985 r.left += 2;
986 DrawTextExA(memDC,buffer,-1,&r,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT | DT_END_ELLIPSIS,NULL);
987 DeleteObject (SelectObject (memDC, hOldFont));
988 IncreaseLogCount();
989 dprintf(("DrawCaption %s %d", buffer, active));
990 DecreaseLogCount();
991 }
992
993 BitBlt(hdc,rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top,memDC,0,0,SRCCOPY);
994 SelectObject(memDC,oldBmp);
995 DeleteObject(memBmp);
996 DeleteDC(memDC);
997}
998//******************************************************************************
999//******************************************************************************
1000VOID Win32BaseWindow::DoNCPaint(HRGN clip,BOOL suppress_menupaint)
1001{
1002 BOOL active = flags & WIN_NCACTIVATED;
1003 HDC hdc;
1004 RECT rect,rectClip,rfuzz;
1005
1006 /* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in
1007 the call to GetDCEx implying that it is allowed not to use it either.
1008 However, the suggested GetDCEx( , DCX_WINDOW | DCX_INTERSECTRGN)
1009 will cause clipRgn to be deleted after ReleaseDC().
1010 Now, how is the "system" supposed to tell what happened?
1011 */
1012
1013 dprintf(("DoNCPaint %x %x %d", getWindowHandle(), clip, suppress_menupaint));
1014 DecreaseLogCount();
1015
1016 rect.top = rect.left = 0;
1017 rect.right = rectWindow.right - rectWindow.left;
1018 rect.bottom = rectWindow.bottom - rectWindow.top;
1019
1020 if (clip > 1)
1021 {
1022 //only redraw caption
1023 GetRgnBox(clip,&rectClip);
1024#if 1
1025 //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
1026 // with a region that covers the entire window (RealPlayer 7 Update 1)
1027 // As we don't need to clip anything when that occurs, this workaround
1028 // solves the problem.
1029 if(rectClip.right == getWindowWidth() && rectClip.bottom == getWindowHeight())
1030 {
1031 clip = 0;
1032 rectClip = rect;
1033 }
1034#endif
1035 }
1036 else
1037 {
1038 clip = 0;
1039 rectClip = rect;
1040 }
1041
1042 if (!(hdc = GetDCEx( Win32Hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
1043 ((clip > 1) ?(DCX_INTERSECTRGN /*| DCX_KEEPCLIPRGN*/) : 0) ))) return;
1044
1045 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1046
1047 if (HAS_BIGFRAME( dwStyle, dwExStyle))
1048 {
1049 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST);
1050 }
1051 if (HAS_THICKFRAME( dwStyle, dwExStyle ))
1052 DrawFrame(hdc, &rect, FALSE, active );
1053 else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
1054 DrawFrame( hdc, &rect, TRUE, active );
1055 else if (HAS_THINFRAME( dwStyle ))
1056 {
1057 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
1058 Rectangle( hdc, 0, 0, rect.right, rect.bottom );
1059 }
1060
1061 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1062 {
1063 RECT r = rect;
1064 if (dwExStyle & WS_EX_TOOLWINDOW)
1065 {
1066 r.bottom = rect.top + GetSystemMetrics(SM_CYSMCAPTION);
1067 rect.top += GetSystemMetrics(SM_CYSMCAPTION);
1068 }
1069 else
1070 {
1071 r.bottom = rect.top + GetSystemMetrics(SM_CYCAPTION);
1072 rect.top += GetSystemMetrics(SM_CYCAPTION);
1073 }
1074 if( !clip || IntersectRect( &rfuzz, &r, &rectClip ) )
1075 DrawCaption(hdc,&r,active);
1076 }
1077
1078 if (HAS_MENU())
1079 {
1080 RECT r = rect;
1081 r.bottom = rect.top + GetSystemMetrics(SM_CYMENU);
1082
1083 rect.top += MENU_DrawMenuBar(hdc,&r,Win32Hwnd,suppress_menupaint)+1;
1084 }
1085
1086 if (dwExStyle & WS_EX_CLIENTEDGE)
1087 DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
1088
1089 if (dwExStyle & WS_EX_STATICEDGE)
1090 DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
1091
1092 /* Draw the scroll-bars */
1093 if (dwStyle & WS_VSCROLL)
1094 SCROLL_DrawScrollBar(Win32Hwnd,hdc,SB_VERT,TRUE,TRUE);
1095 if (dwStyle & WS_HSCROLL)
1096 SCROLL_DrawScrollBar(Win32Hwnd,hdc,SB_HORZ,TRUE,TRUE);
1097
1098 /* Draw the "size-box" */
1099 if ((dwStyle & WS_VSCROLL) && (dwStyle & WS_HSCROLL))
1100 {
1101 RECT r = rect;
1102 r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1;
1103 r.top = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1;
1104 FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) );
1105 //CB: todo: child windows have sometimes a size grip (i.e. Notepad)
1106 // WS_SIZEBOX isn't set in these cases
1107 if (!(dwStyle & WS_CHILD))
1108 {
1109 POINT p1,p2;
1110 HPEN penDark = GetSysColorPen(COLOR_3DSHADOW);
1111 HPEN penWhite = GetSysColorPen(COLOR_3DHILIGHT);
1112 HPEN oldPen = SelectObject(hdc,penDark);
1113 INT x;
1114
1115 p1.x = r.right-1;
1116 p1.y = r.bottom;
1117 p2.x = r.right;
1118 p2.y = r.bottom-1;
1119 for (x = 0;x < 3;x++)
1120 {
1121 SelectObject(hdc,penDark);
1122 MoveToEx(hdc,p1.x,p1.y,NULL);
1123 LineTo(hdc,p2.x,p2.y);
1124 p1.x--;
1125 p2.y--;
1126 MoveToEx(hdc,p1.x,p1.y,NULL);
1127 LineTo(hdc,p2.x,p2.y);
1128 SelectObject(hdc,penWhite);
1129 p1.x--;
1130 p2.y--;
1131 MoveToEx(hdc,p1.x,p1.y,NULL);
1132 LineTo(hdc,p2.x,p2.y);
1133 p1.x -= 2;
1134 p2.y -= 2;
1135 }
1136
1137 SelectObject(hdc,oldPen);
1138 }
1139 }
1140
1141 ReleaseDC(getWindowHandle(),hdc);
1142 IncreaseLogCount();
1143 dprintf(("**DoNCPaint %x DONE", getWindowHandle()));
1144}
1145//******************************************************************************
1146//******************************************************************************
1147LONG Win32BaseWindow::HandleNCPaint(HRGN clip)
1148{
1149//CB: ignore it for now (SetWindowPos in WM_CREATE)
1150// if (!(dwStyle & WS_VISIBLE)) return 0;
1151
1152 if (dwStyle & WS_MINIMIZE) return 0;
1153
1154 DoNCPaint(clip,FALSE);
1155
1156 return 0;
1157}
1158/***********************************************************************
1159 * NC_HandleNCLButtonDblClk
1160 *
1161 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1162 */
1163LONG Win32BaseWindow::HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam)
1164{
1165 /*
1166 * if this is an icon, send a restore since we are handling
1167 * a double click
1168 */
1169 if (dwStyle & WS_MINIMIZE)
1170 {
1171 SendInternalMessageA(WM_SYSCOMMAND,SC_RESTORE,lParam);
1172 return 0;
1173 }
1174
1175 switch(wParam) /* Hit test */
1176 {
1177 case HTCAPTION:
1178 /* stop processing if WS_MAXIMIZEBOX is missing */
1179 if (dwStyle & WS_MAXIMIZEBOX)
1180 SendInternalMessageA(WM_SYSCOMMAND,
1181 (dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
1182 lParam);
1183 break;
1184
1185 case HTSYSMENU:
1186 if (!(GetClassWord(Win32Hwnd,GCW_STYLE) & CS_NOCLOSE))
1187 SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
1188 break;
1189
1190 case HTHSCROLL:
1191 SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
1192 break;
1193
1194 case HTVSCROLL:
1195 SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
1196 break;
1197 }
1198
1199 return 0;
1200}
1201//******************************************************************************
1202//******************************************************************************
1203LONG Win32BaseWindow::HandleNCRButtonUp(WPARAM wParam,LPARAM lParam)
1204{
1205 switch(wParam)
1206 {
1207 case HTCAPTION:
1208 if (GetActiveWindow() != Win32Hwnd)
1209 SetActiveWindow();
1210
1211 if (((GetActiveWindow() == Win32Hwnd) || isMDIChild()) && (dwStyle & WS_SYSMENU))
1212 {
1213 SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTCAPTION,lParam);
1214 }
1215 break;
1216
1217 default:
1218 break;
1219 }
1220
1221 return 0;
1222}
1223/***********************************************************************
1224 * NC_HandleSysCommand
1225 *
1226 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1227 *
1228 */
1229LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam,POINT *pt32)
1230{
1231 UINT uCommand = wParam & 0xFFF0;
1232
1233 switch (uCommand)
1234 {
1235
1236 case SC_SIZE:
1237 {
1238 DWORD flags;
1239
1240 if (dwStyle & WS_MAXIMIZE) break;
1241
1242 switch ((wParam & 0xF)+2)
1243 {
1244 case HTLEFT:
1245 flags = TFOS_LEFT;
1246 break;
1247
1248 case HTRIGHT:
1249 flags = TFOS_RIGHT;
1250 break;
1251
1252 case HTTOP:
1253 flags = TFOS_TOP;
1254 break;
1255
1256 case HTTOPLEFT:
1257 flags = TFOS_TOP | TFOS_LEFT;
1258 break;
1259
1260 case HTTOPRIGHT:
1261 flags = TFOS_TOP | TFOS_RIGHT;
1262 break;
1263
1264 case HTBOTTOM:
1265 flags = TFOS_BOTTOM;
1266 break;
1267
1268 case HTBOTTOMLEFT:
1269 flags = TFOS_BOTTOM | TFOS_LEFT;
1270 break;
1271
1272 case HTBOTTOMRIGHT:
1273 flags = TFOS_BOTTOM | TFOS_RIGHT;
1274 break;
1275
1276 default:
1277 flags = TFOS_BOTTOM | TFOS_RIGHT;
1278 break;
1279 }
1280 if (flags) FrameTrackFrame(this,flags);
1281 break;
1282 }
1283
1284 case SC_MOVE:
1285 if (dwStyle & WS_MAXIMIZE) break;
1286 FrameTrackFrame(this,TFOS_MOVE);
1287 break;
1288
1289 case SC_MINIMIZE:
1290 ShowWindow(SW_MINIMIZE);
1291 break;
1292
1293 case SC_MAXIMIZE:
1294 ShowWindow(SW_MAXIMIZE);
1295 break;
1296
1297 case SC_RESTORE:
1298 ShowWindow(SW_RESTORE);
1299 break;
1300
1301 case SC_CLOSE:
1302 return SendInternalMessageA(WM_CLOSE,0,0);
1303
1304 case SC_CONTEXTHELP:
1305 {
1306 //CB: todo
1307 break;
1308 }
1309
1310 case SC_VSCROLL:
1311 case SC_HSCROLL:
1312 TrackScrollBar(wParam,*pt32);
1313 break;
1314
1315 case SC_MOUSEMENU:
1316 MENU_TrackMouseMenuBar(Win32Hwnd,wParam & 0x000F,*pt32);
1317 break;
1318
1319 case SC_KEYMENU:
1320 MENU_TrackKbdMenuBar(Win32Hwnd,wParam,pt32->x);
1321 break;
1322
1323 case SC_TASKLIST:
1324 OSLibWinShowTaskList(getOS2WindowHandle());
1325 break;
1326
1327 case SC_SCREENSAVE:
1328 if (wParam == SC_ABOUTODIN) {
1329 if(ShellAboutA == 0) {
1330 HINSTANCE hShell32 = LoadLibraryA("SHELL32");
1331 if(hShell32 == 0)
1332 break;
1333 *(VOID **)&ShellAboutA = (VOID *)GetProcAddress(hShell32, "ShellAboutA");
1334 }
1335 ShellAboutA(Win32Hwnd,"Odin","Odin alpha release compiled with IBM VAC++",0);
1336 }
1337#ifdef DEBUG
1338 //SvL: Do NOT turn this into a dprintf.
1339 else
1340 if (wParam == SC_PUTMARK)
1341 WriteLog(("Mark requested by user\n"));
1342 else
1343 if (wParam == SC_DEBUGINT3)
1344 DebugInt3();
1345#endif
1346 break;
1347
1348 case SC_HOTKEY:
1349 case SC_ARRANGE:
1350 case SC_NEXTWINDOW:
1351 case SC_PREVWINDOW:
1352 break;
1353 }
1354 return 0;
1355}
1356/*****************************************************************************
1357 * Name : VOID WIN32API DrawCaption
1358 * Purpose : The DrawCaption function draws a window caption.
1359 * Parameters: HDC hdc handle of device context
1360 * LPRECT lprc address of bounding rectangle coordinates
1361 * HFONT hfont handle of font for caption
1362 * HICON hicon handle of icon in caption
1363 * LPSTR lpszText address of caption string
1364 * WORD wFlags drawing options
1365 * Variables :
1366 * Result :
1367 * Remark :
1368 * Status : UNTESTED STUB
1369 *
1370 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1371 *****************************************************************************/
1372BOOL WIN32API DrawCaption (HWND hwnd,HDC hdc,const RECT *lprc,UINT wFlags)
1373{
1374 dprintf(("USER32: DrawCaption"));
1375
1376 return DrawCaptionTempA(hwnd,hdc,lprc,0,0,NULL,wFlags & 0x1F);
1377}
1378//******************************************************************************
1379// CB: this code is a subset of Win32BaseWindow::DrawCaption
1380// todo: move Win32BaseWindow:DrawCaption to this function
1381//******************************************************************************
1382BOOL WIN32API DrawCaptionTemp(HWND hwnd,HDC hdc,const RECT *rect,HFONT hFont,HICON hIcon,LPWSTR str,UINT uFlags,BOOL unicode)
1383{
1384 RECT rc = *rect;
1385
1386 /* drawing background */
1387 if (uFlags & DC_INBUTTON)
1388 {
1389 FillRect (hdc, &rc, GetSysColorBrush (COLOR_3DFACE));
1390
1391 if (uFlags & DC_ACTIVE)
1392 {
1393 HBRUSH hbr = SelectObject (hdc, GetPattern55AABrush ());
1394 PatBlt (hdc, rc.left, rc.top,
1395 rc.right-rc.left, rc.bottom-rc.top, 0xFA0089);
1396 SelectObject (hdc, hbr);
1397 }
1398 } else
1399 {
1400 FillRect (hdc, &rc, GetSysColorBrush ((uFlags & DC_ACTIVE) ?
1401 COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION));
1402 }
1403
1404 /* drawing icon */
1405 if ((uFlags & DC_ICON) && !(uFlags & DC_SMALLCAP))
1406 {
1407 POINT pt;
1408
1409 pt.x = rc.left + 2;
1410 pt.y = (rc.bottom + rc.top - GetSystemMetrics(SM_CYSMICON)) / 2;
1411
1412 if (hIcon)
1413 {
1414 DrawIconEx (hdc, pt.x, pt.y, hIcon, GetSystemMetrics(SM_CXSMICON),
1415 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
1416 } else
1417 {
1418 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
1419
1420 if (!win32wnd) return 0;
1421
1422 DrawIconEx (hdc, pt.x, pt.y, win32wnd->IconForWindow(ICON_SMALL),
1423 GetSystemMetrics(SM_CXSMICON),
1424 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
1425 }
1426
1427 rc.left += (rc.bottom - rc.top);
1428 }
1429
1430 /* drawing text */
1431 if (uFlags & DC_TEXT)
1432 {
1433 HFONT hOldFont;
1434
1435 if (uFlags & DC_INBUTTON)
1436 SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
1437 else if (uFlags & DC_ACTIVE)
1438 SetTextColor (hdc, GetSysColor (COLOR_CAPTIONTEXT));
1439 else
1440 SetTextColor (hdc, GetSysColor (COLOR_INACTIVECAPTIONTEXT));
1441
1442 SetBkMode (hdc, TRANSPARENT);
1443
1444 if (hFont)
1445 hOldFont = SelectObject (hdc, hFont);
1446 else
1447 {
1448 NONCLIENTMETRICSA nclm;
1449 HFONT hNewFont;
1450
1451 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
1452 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
1453 hNewFont = CreateFontIndirectA ((uFlags & DC_SMALLCAP) ?
1454 &nclm.lfSmCaptionFont : &nclm.lfCaptionFont);
1455 hOldFont = SelectObject (hdc, hNewFont);
1456 }
1457
1458 if (str)
1459 {
1460 if (unicode)
1461 DrawTextW(hdc,str,-1,&rc,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
1462 else
1463 DrawTextA(hdc,(LPSTR)str,-1,&rc,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
1464 } else
1465 {
1466 CHAR szText[128];
1467 INT nLen;
1468
1469 nLen = GetWindowTextA (hwnd, szText, 128);
1470 DrawTextA (hdc, szText, nLen, &rc,
1471 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
1472 }
1473
1474 if (hFont)
1475 SelectObject (hdc, hOldFont);
1476 else
1477 DeleteObject (SelectObject (hdc, hOldFont));
1478 }
1479
1480 /* drawing focus ??? */
1481 //if (uFlags & 0x2000)
1482 // FIXME("undocumented flag (0x2000)!\n");
1483
1484 return 0;
1485}
1486/***********************************************************************
1487 * DrawCaptionTemp32A [USER32.599]
1488 *
1489 * PARAMS
1490 *
1491 * RETURNS
1492 * Success:
1493 * Failure:
1494 */
1495BOOL WIN32API DrawCaptionTempA(HWND hwnd,HDC hdc,const RECT *rect,HFONT hFont,HICON hIcon,LPCSTR str,UINT uFlags)
1496{
1497 dprintf(("USER32: DrawCaptionTempA"));
1498
1499 return DrawCaptionTemp(hwnd,hdc,rect,hFont,hIcon,(LPWSTR)str,uFlags,FALSE);
1500}
1501/***********************************************************************
1502 * DrawCaptionTemp32W [USER32.602]
1503 *
1504 * PARAMS
1505 *
1506 * RETURNS
1507 * Success:
1508 * Failure:
1509 */
1510BOOL WIN32API DrawCaptionTempW (HWND hwnd,HDC hdc,const RECT *rect,HFONT hFont,HICON hIcon,LPCWSTR str,UINT uFlags)
1511{
1512 dprintf(("USER32: DrawCaptionTempA"));
1513
1514 return DrawCaptionTemp(hwnd,hdc,rect,hFont,hIcon,(LPWSTR)str,uFlags,TRUE);
1515}
1516
Note: See TracBrowser for help on using the repository browser.