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

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

today is a good day ;)

File size: 44.9 KB
Line 
1/* $Id: win32wbasenonclient.cpp,v 1.18 2000-04-01 11:35:00 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 SYSTEMTIME time; //WYSIWYGOFOA
860
861 GetSystemTime(&time);
862
863
864 memDC = CreateCompatibleDC(hdc);
865 r.right -= r.left;
866 r.bottom -= r.top;
867 r.left = r.top = 0;
868 r2 = r;
869 memBmp = CreateCompatibleBitmap(hdc,r.right,r.bottom);
870 oldBmp = SelectObject(memDC,memBmp);
871
872 hPrevPen = SelectObject(memDC,GetSysColorPen(COLOR_3DFACE));
873 MoveToEx(memDC,r.left,r.bottom-1,NULL);
874 LineTo(memDC,r.right,r.bottom-1);
875 SelectObject(memDC,hPrevPen);
876 r.bottom--;
877
878 if (SYSCOLOR_GetUseWinColors())
879 {
880 COLORREF startColor = GetSysColor(active ? COLOR_ACTIVECAPTION:COLOR_INACTIVECAPTION),endColor = GetSysColor(active ? COLOR_GRADIENTACTIVECAPTION:COLOR_GRADIENTINACTIVECAPTION);
881
882 if ((time.wMonth == 4) && (time.wDay == 1))
883 {
884 startColor = RGB(rand() & 0xFF,rand() & 0xFF,rand() & 0xFF);
885 endColor = RGB(rand() & 0xFF,rand() & 0xFF,rand() & 0xFF);
886 }
887
888 if (startColor == endColor)
889 FillRect(memDC,&r,GetSysColorBrush(startColor));
890 else
891 {
892 INT rDiff = GetRValue(endColor)-GetRValue(startColor);
893 INT gDiff = GetGValue(endColor)-GetGValue(startColor);
894 INT bDiff = GetBValue(endColor)-GetBValue(startColor);
895 INT steps = MAX(MAX(abs(rDiff),abs(gDiff)),abs(bDiff));
896 INT w = r.right-r.left;
897 RECT r2;
898
899 if (w < steps) steps = w;
900 r2.left = r2.right = r.left;
901 r2.top = r.top;
902 r2.bottom = r.bottom;
903 for (INT x = 0;x <= steps;x++)
904 {
905 COLORREF color = RGB(GetRValue(startColor)+rDiff*x/steps,GetGValue(startColor)+gDiff*x/steps,GetBValue(startColor)+bDiff*x/steps);
906 HBRUSH brush = CreateSolidBrush(color);
907
908 r2.left = r2.right;
909 r2.right = r.left+w*x/steps;
910 FillRect(memDC,&r2,brush);
911 DeleteObject(brush);
912 }
913 }
914 } else FillRect(memDC,&r,GetSysColorBrush(active ? COLOR_ACTIVECAPTION:COLOR_INACTIVECAPTION));
915
916 if (!hbitmapClose)
917 {
918 if (!(hbitmapClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE)))) return;
919 hbitmapCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
920 hbitmapMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
921 hbitmapMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
922 hbitmapMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOM));
923 hbitmapMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOMD));
924 hbitmapRestore = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
925 hbitmapRestoreD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
926 hbitmapContextHelp = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CONTEXTHELP));
927 hbitmapContextHelpD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CONTEXTHELPD));
928 }
929
930 if ((dwStyle & WS_SYSMENU) && !(dwExStyle & WS_EX_TOOLWINDOW))
931 {
932 if (DrawSysButton(memDC,&r))
933 r.left += GetSystemMetrics(SM_CYCAPTION) - 1;
934 }
935
936 if (dwStyle & WS_SYSMENU)
937 {
938 UINT state;
939
940 /* Go get the sysmenu */
941 state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
942
943 /* Draw a grayed close button if disabled and a normal one if SC_CLOSE is not there */
944 DrawCloseButton(memDC,&r2,FALSE,
945 ((((state & MF_DISABLED) || (state & MF_GRAYED))) && (state != 0xFFFFFFFF)));
946 r.right -= GetSystemMetrics(SM_CYCAPTION)-1;
947
948 if (dwExStyle & WS_EX_CONTEXTHELP)
949 {
950 DrawContextHelpButton(memDC,&r2,FALSE,FALSE);
951 r.right -= GetSystemMetrics(SM_CXSIZE)+1;
952 }
953
954 if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX))
955 {
956 /* In win95 the two buttons are always there */
957 /* But if the menu item is not in the menu they're disabled*/
958
959 DrawMaxButton(memDC,&r2,FALSE,(!(dwStyle & WS_MAXIMIZEBOX)));
960 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
961
962 DrawMinButton(memDC,&r2,FALSE, (!(dwStyle & WS_MINIMIZEBOX)));
963 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
964 }
965 }
966
967 if (GetWindowTextA(buffer, sizeof(buffer)-2 )) //WYSIWYGOFOA: -2
968 {
969 NONCLIENTMETRICSA nclm;
970 HFONT hFont, hOldFont;
971
972 if ((time.wMonth == 4) && (time.wDay == 1)) strcat(buffer,"/2"); //WYSIWYGOFOA
973
974 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
975 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
976 if (dwExStyle & WS_EX_TOOLWINDOW)
977 hFont = CreateFontIndirectA (&nclm.lfSmCaptionFont);
978 else
979 hFont = CreateFontIndirectA (&nclm.lfCaptionFont);
980 hOldFont = SelectObject (memDC, hFont);
981 SetTextColor(memDC,GetSysColor(active ? COLOR_CAPTIONTEXT:COLOR_INACTIVECAPTIONTEXT));
982 SetBkMode(memDC, TRANSPARENT );
983 r.left += 2;
984 DrawTextExA(memDC,buffer,-1,&r,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT | DT_END_ELLIPSIS,NULL);
985 DeleteObject (SelectObject (memDC, hOldFont));
986 }
987
988 BitBlt(hdc,rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top,memDC,0,0,SRCCOPY);
989 SelectObject(memDC,oldBmp);
990 DeleteObject(memBmp);
991 DeleteDC(memDC);
992}
993//******************************************************************************
994//******************************************************************************
995VOID Win32BaseWindow::DoNCPaint(HRGN clip,BOOL suppress_menupaint)
996{
997 BOOL active = flags & WIN_NCACTIVATED;
998 HDC hdc;
999 RECT rect,rectClip,rfuzz;
1000
1001 /* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in
1002 the call to GetDCEx implying that it is allowed not to use it either.
1003 However, the suggested GetDCEx( , DCX_WINDOW | DCX_INTERSECTRGN)
1004 will cause clipRgn to be deleted after ReleaseDC().
1005 Now, how is the "system" supposed to tell what happened?
1006 */
1007
1008 dprintf(("DoNCPaint %x %x %d", getWindowHandle(), clip, suppress_menupaint));
1009 DecreaseLogCount();
1010
1011 if (!(hdc = GetDCEx( Win32Hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
1012 ((clip > 1) ?(DCX_INTERSECTRGN /*| DCX_KEEPCLIPRGN*/) : 0) ))) return;
1013
1014 rect.top = rect.left = 0;
1015 rect.right = rectWindow.right - rectWindow.left;
1016 rect.bottom = rectWindow.bottom - rectWindow.top;
1017
1018 if (clip > 1)
1019 {
1020 //only redraw caption
1021 GetRgnBox(clip,&rectClip);
1022 }
1023 else
1024 {
1025 clip = 0;
1026 rectClip = rect;
1027 }
1028
1029 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1030
1031 if (HAS_BIGFRAME( dwStyle, dwExStyle))
1032 {
1033 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST);
1034 }
1035 if (HAS_THICKFRAME( dwStyle, dwExStyle ))
1036 DrawFrame(hdc, &rect, FALSE, active );
1037 else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
1038 DrawFrame( hdc, &rect, TRUE, active );
1039 else if (HAS_THINFRAME( dwStyle ))
1040 {
1041 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
1042 Rectangle( hdc, 0, 0, rect.right, rect.bottom );
1043 }
1044
1045 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1046 {
1047 RECT r = rect;
1048 if (dwExStyle & WS_EX_TOOLWINDOW)
1049 {
1050 r.bottom = rect.top + GetSystemMetrics(SM_CYSMCAPTION);
1051 rect.top += GetSystemMetrics(SM_CYSMCAPTION);
1052 }
1053 else
1054 {
1055 r.bottom = rect.top + GetSystemMetrics(SM_CYCAPTION);
1056 rect.top += GetSystemMetrics(SM_CYCAPTION);
1057 }
1058 if( !clip || IntersectRect( &rfuzz, &r, &rectClip ) )
1059 DrawCaption(hdc,&r,active);
1060 }
1061
1062 if (HAS_MENU())
1063 {
1064 RECT r = rect;
1065 r.bottom = rect.top + GetSystemMetrics(SM_CYMENU);
1066
1067 rect.top += MENU_DrawMenuBar(hdc,&r,Win32Hwnd,suppress_menupaint)+1;
1068 }
1069
1070 if (dwExStyle & WS_EX_CLIENTEDGE)
1071 DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
1072
1073 if (dwExStyle & WS_EX_STATICEDGE)
1074 DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
1075
1076 /* Draw the scroll-bars */
1077 if (dwStyle & WS_VSCROLL)
1078 SCROLL_DrawScrollBar(Win32Hwnd,hdc,SB_VERT,TRUE,TRUE);
1079 if (dwStyle & WS_HSCROLL)
1080 SCROLL_DrawScrollBar(Win32Hwnd,hdc,SB_HORZ,TRUE,TRUE);
1081
1082 /* Draw the "size-box" */
1083 if ((dwStyle & WS_VSCROLL) && (dwStyle & WS_HSCROLL))
1084 {
1085 RECT r = rect;
1086 r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1;
1087 r.top = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1;
1088 FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) );
1089 //CB: todo: child window have sometimes a size grip (i.e. Notepad)
1090 // WS_SIZEBOX isn't set in these cases
1091 if (!(dwStyle & WS_CHILD))
1092 {
1093 POINT p1,p2;
1094 HPEN penDark = GetSysColorPen(COLOR_3DSHADOW);
1095 HPEN penWhite = GetSysColorPen(COLOR_3DHILIGHT);
1096 HPEN oldPen = SelectObject(hdc,penDark);
1097 INT x;
1098
1099 p1.x = r.right-1;
1100 p1.y = r.bottom;
1101 p2.x = r.right;
1102 p2.y = r.bottom-1;
1103 for (x = 0;x < 3;x++)
1104 {
1105 SelectObject(hdc,penDark);
1106 MoveToEx(hdc,p1.x,p1.y,NULL);
1107 LineTo(hdc,p2.x,p2.y);
1108 p1.x--;
1109 p2.y--;
1110 MoveToEx(hdc,p1.x,p1.y,NULL);
1111 LineTo(hdc,p2.x,p2.y);
1112 SelectObject(hdc,penWhite);
1113 p1.x--;
1114 p2.y--;
1115 MoveToEx(hdc,p1.x,p1.y,NULL);
1116 LineTo(hdc,p2.x,p2.y);
1117 p1.x -= 2;
1118 p2.y -= 2;
1119 }
1120
1121 SelectObject(hdc,oldPen);
1122 }
1123 }
1124
1125 ReleaseDC(Win32Hwnd,hdc);
1126 IncreaseLogCount();
1127 dprintf(("**DoNCPaint %x DONE", getWindowHandle()));
1128}
1129//******************************************************************************
1130//******************************************************************************
1131LONG Win32BaseWindow::HandleNCPaint(HRGN clip)
1132{
1133//CB: ignore it for now (SetWindowPos in WM_CREATE)
1134// if (!(dwStyle & WS_VISIBLE)) return 0;
1135
1136 if (dwStyle & WS_MINIMIZE) return 0;
1137
1138 DoNCPaint(clip,FALSE);
1139
1140 return 0;
1141}
1142/***********************************************************************
1143 * NC_HandleNCLButtonDblClk
1144 *
1145 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1146 */
1147LONG Win32BaseWindow::HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam)
1148{
1149 /*
1150 * if this is an icon, send a restore since we are handling
1151 * a double click
1152 */
1153 if (dwStyle & WS_MINIMIZE)
1154 {
1155 SendInternalMessageA(WM_SYSCOMMAND,SC_RESTORE,lParam);
1156 return 0;
1157 }
1158
1159 switch(wParam) /* Hit test */
1160 {
1161 case HTCAPTION:
1162 /* stop processing if WS_MAXIMIZEBOX is missing */
1163 if (dwStyle & WS_MAXIMIZEBOX)
1164 SendInternalMessageA(WM_SYSCOMMAND,
1165 (dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
1166 lParam);
1167 break;
1168
1169 case HTSYSMENU:
1170 if (!(GetClassWord(Win32Hwnd,GCW_STYLE) & CS_NOCLOSE))
1171 SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
1172 break;
1173
1174 case HTHSCROLL:
1175 SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
1176 break;
1177
1178 case HTVSCROLL:
1179 SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
1180 break;
1181 }
1182
1183 return 0;
1184}
1185//******************************************************************************
1186//******************************************************************************
1187LONG Win32BaseWindow::HandleNCRButtonUp(WPARAM wParam,LPARAM lParam)
1188{
1189 switch(wParam)
1190 {
1191 case HTCAPTION:
1192 if (GetActiveWindow() != Win32Hwnd)
1193 SetActiveWindow();
1194
1195 if (((GetActiveWindow() == Win32Hwnd) || isMDIChild()) && (dwStyle & WS_SYSMENU))
1196 {
1197 SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTCAPTION,lParam);
1198 }
1199 break;
1200
1201 default:
1202 break;
1203 }
1204
1205 return 0;
1206}
1207/***********************************************************************
1208 * NC_HandleSysCommand
1209 *
1210 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1211 *
1212 */
1213LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam,POINT *pt32)
1214{
1215 UINT uCommand = wParam & 0xFFF0;
1216
1217 switch (uCommand)
1218 {
1219
1220 case SC_SIZE:
1221 {
1222 DWORD flags;
1223
1224 if (dwStyle & WS_MAXIMIZE) break;
1225
1226 switch ((wParam & 0xF)+2)
1227 {
1228 case HTLEFT:
1229 flags = TFOS_LEFT;
1230 break;
1231
1232 case HTRIGHT:
1233 flags = TFOS_RIGHT;
1234 break;
1235
1236 case HTTOP:
1237 flags = TFOS_TOP;
1238 break;
1239
1240 case HTTOPLEFT:
1241 flags = TFOS_TOP | TFOS_LEFT;
1242 break;
1243
1244 case HTTOPRIGHT:
1245 flags = TFOS_TOP | TFOS_RIGHT;
1246 break;
1247
1248 case HTBOTTOM:
1249 flags = TFOS_BOTTOM;
1250 break;
1251
1252 case HTBOTTOMLEFT:
1253 flags = TFOS_BOTTOM | TFOS_LEFT;
1254 break;
1255
1256 case HTBOTTOMRIGHT:
1257 flags = TFOS_BOTTOM | TFOS_RIGHT;
1258 break;
1259
1260 default:
1261 flags = TFOS_BOTTOM | TFOS_RIGHT;
1262 break;
1263 }
1264 if (flags) FrameTrackFrame(this,flags);
1265 break;
1266 }
1267
1268 case SC_MOVE:
1269 if (dwStyle & WS_MAXIMIZE) break;
1270 FrameTrackFrame(this,TFOS_MOVE);
1271 break;
1272
1273 case SC_MINIMIZE:
1274 ShowWindow(SW_MINIMIZE);
1275 break;
1276
1277 case SC_MAXIMIZE:
1278 ShowWindow(SW_MAXIMIZE);
1279 break;
1280
1281 case SC_RESTORE:
1282 ShowWindow(SW_RESTORE);
1283 break;
1284
1285 case SC_CLOSE:
1286 return SendInternalMessageA(WM_CLOSE,0,0);
1287
1288 case SC_CONTEXTHELP:
1289 {
1290 //CB: todo
1291 break;
1292 }
1293
1294 case SC_VSCROLL:
1295 case SC_HSCROLL:
1296 TrackScrollBar(wParam,*pt32);
1297 break;
1298
1299 case SC_MOUSEMENU:
1300 MENU_TrackMouseMenuBar(Win32Hwnd,wParam & 0x000F,*pt32);
1301 break;
1302
1303 case SC_KEYMENU:
1304 MENU_TrackKbdMenuBar(Win32Hwnd,wParam,pt32->x);
1305 break;
1306
1307 case SC_TASKLIST:
1308 OSLibWinShowTaskList(getOS2FrameWindowHandle());
1309 break;
1310
1311 case SC_SCREENSAVE:
1312 if (wParam == SC_ABOUTODIN) {
1313 if(ShellAboutA == 0) {
1314 HINSTANCE hShell32 = LoadLibraryA("SHELL32");
1315 if(hShell32 == 0)
1316 break;
1317 *(VOID **)&ShellAboutA = (VOID *)GetProcAddress(hShell32, "ShellAboutA");
1318 }
1319 ShellAboutA(Win32Hwnd,"Odin","Odin alpha release compiled with IBM VAC++",0);
1320 }
1321 else
1322 if (wParam == SC_PUTMARK)
1323 dprintf(("Mark requested by user\n"));
1324 break;
1325
1326 case SC_HOTKEY:
1327 case SC_ARRANGE:
1328 case SC_NEXTWINDOW:
1329 case SC_PREVWINDOW:
1330 break;
1331 }
1332 return 0;
1333}
1334/*****************************************************************************
1335 * Name : VOID WIN32API DrawCaption
1336 * Purpose : The DrawCaption function draws a window caption.
1337 * Parameters: HDC hdc handle of device context
1338 * LPRECT lprc address of bounding rectangle coordinates
1339 * HFONT hfont handle of font for caption
1340 * HICON hicon handle of icon in caption
1341 * LPSTR lpszText address of caption string
1342 * WORD wFlags drawing options
1343 * Variables :
1344 * Result :
1345 * Remark :
1346 * Status : UNTESTED STUB
1347 *
1348 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1349 *****************************************************************************/
1350BOOL WIN32API DrawCaption (HWND hwnd,HDC hdc,const RECT *lprc,UINT wFlags)
1351{
1352 dprintf(("USER32: DrawCaption"));
1353
1354 return DrawCaptionTempA(hwnd,hdc,lprc,0,0,NULL,wFlags & 0x1F);
1355}
1356//******************************************************************************
1357// CB: this code is a subset of Win32BaseWindow::DrawCaption
1358// todo: move Win32BaseWindow:DrawCaption to this function
1359//******************************************************************************
1360BOOL WIN32API DrawCaptionTemp(HWND hwnd,HDC hdc,const RECT *rect,HFONT hFont,HICON hIcon,LPWSTR str,UINT uFlags,BOOL unicode)
1361{
1362 RECT rc = *rect;
1363
1364 /* drawing background */
1365 if (uFlags & DC_INBUTTON)
1366 {
1367 FillRect (hdc, &rc, GetSysColorBrush (COLOR_3DFACE));
1368
1369 if (uFlags & DC_ACTIVE)
1370 {
1371 HBRUSH hbr = SelectObject (hdc, GetPattern55AABrush ());
1372 PatBlt (hdc, rc.left, rc.top,
1373 rc.right-rc.left, rc.bottom-rc.top, 0xFA0089);
1374 SelectObject (hdc, hbr);
1375 }
1376 } else
1377 {
1378 FillRect (hdc, &rc, GetSysColorBrush ((uFlags & DC_ACTIVE) ?
1379 COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION));
1380 }
1381
1382 /* drawing icon */
1383 if ((uFlags & DC_ICON) && !(uFlags & DC_SMALLCAP))
1384 {
1385 POINT pt;
1386
1387 pt.x = rc.left + 2;
1388 pt.y = (rc.bottom + rc.top - GetSystemMetrics(SM_CYSMICON)) / 2;
1389
1390 if (hIcon)
1391 {
1392 DrawIconEx (hdc, pt.x, pt.y, hIcon, GetSystemMetrics(SM_CXSMICON),
1393 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
1394 } else
1395 {
1396 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
1397
1398 if (!win32wnd) return 0;
1399
1400 DrawIconEx (hdc, pt.x, pt.y, win32wnd->IconForWindow(ICON_SMALL),
1401 GetSystemMetrics(SM_CXSMICON),
1402 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
1403 }
1404
1405 rc.left += (rc.bottom - rc.top);
1406 }
1407
1408 /* drawing text */
1409 if (uFlags & DC_TEXT)
1410 {
1411 HFONT hOldFont;
1412
1413 if (uFlags & DC_INBUTTON)
1414 SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
1415 else if (uFlags & DC_ACTIVE)
1416 SetTextColor (hdc, GetSysColor (COLOR_CAPTIONTEXT));
1417 else
1418 SetTextColor (hdc, GetSysColor (COLOR_INACTIVECAPTIONTEXT));
1419
1420 SetBkMode (hdc, TRANSPARENT);
1421
1422 if (hFont)
1423 hOldFont = SelectObject (hdc, hFont);
1424 else
1425 {
1426 NONCLIENTMETRICSA nclm;
1427 HFONT hNewFont;
1428
1429 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
1430 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
1431 hNewFont = CreateFontIndirectA ((uFlags & DC_SMALLCAP) ?
1432 &nclm.lfSmCaptionFont : &nclm.lfCaptionFont);
1433 hOldFont = SelectObject (hdc, hNewFont);
1434 }
1435
1436 if (str)
1437 {
1438 if (unicode)
1439 DrawTextW(hdc,str,-1,&rc,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
1440 else
1441 DrawTextA(hdc,(LPSTR)str,-1,&rc,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
1442 } else
1443 {
1444 CHAR szText[128];
1445 INT nLen;
1446
1447 nLen = GetWindowTextA (hwnd, szText, 128);
1448 DrawTextA (hdc, szText, nLen, &rc,
1449 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
1450 }
1451
1452 if (hFont)
1453 SelectObject (hdc, hOldFont);
1454 else
1455 DeleteObject (SelectObject (hdc, hOldFont));
1456 }
1457
1458 /* drawing focus ??? */
1459 //if (uFlags & 0x2000)
1460 // FIXME("undocumented flag (0x2000)!\n");
1461
1462 return 0;
1463}
1464/***********************************************************************
1465 * DrawCaptionTemp32A [USER32.599]
1466 *
1467 * PARAMS
1468 *
1469 * RETURNS
1470 * Success:
1471 * Failure:
1472 */
1473BOOL WIN32API DrawCaptionTempA(HWND hwnd,HDC hdc,const RECT *rect,HFONT hFont,HICON hIcon,LPCSTR str,UINT uFlags)
1474{
1475 dprintf(("USER32: DrawCaptionTempA"));
1476
1477 return DrawCaptionTemp(hwnd,hdc,rect,hFont,hIcon,(LPWSTR)str,uFlags,FALSE);
1478}
1479/***********************************************************************
1480 * DrawCaptionTemp32W [USER32.602]
1481 *
1482 * PARAMS
1483 *
1484 * RETURNS
1485 * Success:
1486 * Failure:
1487 */
1488BOOL WIN32API DrawCaptionTempW (HWND hwnd,HDC hdc,const RECT *rect,HFONT hFont,HICON hIcon,LPCWSTR str,UINT uFlags)
1489{
1490 dprintf(("USER32: DrawCaptionTempA"));
1491
1492 return DrawCaptionTemp(hwnd,hdc,rect,hFont,hIcon,(LPWSTR)str,uFlags,TRUE);
1493}
1494
Note: See TracBrowser for help on using the repository browser.