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

Last change on this file since 3306 was 3306, checked in by cbratschi, 25 years ago

* empty log message *

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