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

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

* empty log message *

File size: 45.1 KB
Line 
1/* $Id: win32wbasenonclient.cpp,v 1.22 2000-04-08 18:31:07 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 IncreaseLogCount();
975 dprintf(("DrawCaption %s %d", buffer, active));
976 DecreaseLogCount();
977 }
978
979 BitBlt(hdc,rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top,memDC,0,0,SRCCOPY);
980 SelectObject(memDC,oldBmp);
981 DeleteObject(memBmp);
982 DeleteDC(memDC);
983}
984//******************************************************************************
985//******************************************************************************
986VOID Win32BaseWindow::DoNCPaint(HRGN clip,BOOL suppress_menupaint)
987{
988 BOOL active = flags & WIN_NCACTIVATED;
989 HDC hdc;
990 RECT rect,rectClip,rfuzz;
991
992 /* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in
993 the call to GetDCEx implying that it is allowed not to use it either.
994 However, the suggested GetDCEx( , DCX_WINDOW | DCX_INTERSECTRGN)
995 will cause clipRgn to be deleted after ReleaseDC().
996 Now, how is the "system" supposed to tell what happened?
997 */
998
999 dprintf(("DoNCPaint %x %x %d", getWindowHandle(), clip, suppress_menupaint));
1000 DecreaseLogCount();
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 //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
1011 // with a region that covers the entire window (RealPlayer 7 Update 1)
1012 // As we don't need to clip anything when that occurs, this workaround
1013 // solves the problem.
1014 if(rectClip.right == getWindowWidth() && rectClip.bottom == getWindowHeight())
1015 {
1016 clip = 0;
1017 rectClip = rect;
1018 }
1019 }
1020 else
1021 {
1022 clip = 0;
1023 rectClip = rect;
1024 }
1025
1026 if (!(hdc = GetDCEx( Win32Hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
1027 ((clip > 1) ?(DCX_INTERSECTRGN /*| DCX_KEEPCLIPRGN*/) : 0) ))) return;
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 windows 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#ifdef DEBUG
1322 //SvL: Do NOT turn this into a dprintf.
1323 else
1324 if (wParam == SC_PUTMARK)
1325 WriteLog(("Mark requested by user\n"));
1326#endif
1327 break;
1328
1329 case SC_HOTKEY:
1330 case SC_ARRANGE:
1331 case SC_NEXTWINDOW:
1332 case SC_PREVWINDOW:
1333 break;
1334 }
1335 return 0;
1336}
1337/*****************************************************************************
1338 * Name : VOID WIN32API DrawCaption
1339 * Purpose : The DrawCaption function draws a window caption.
1340 * Parameters: HDC hdc handle of device context
1341 * LPRECT lprc address of bounding rectangle coordinates
1342 * HFONT hfont handle of font for caption
1343 * HICON hicon handle of icon in caption
1344 * LPSTR lpszText address of caption string
1345 * WORD wFlags drawing options
1346 * Variables :
1347 * Result :
1348 * Remark :
1349 * Status : UNTESTED STUB
1350 *
1351 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1352 *****************************************************************************/
1353BOOL WIN32API DrawCaption (HWND hwnd,HDC hdc,const RECT *lprc,UINT wFlags)
1354{
1355 dprintf(("USER32: DrawCaption"));
1356
1357 return DrawCaptionTempA(hwnd,hdc,lprc,0,0,NULL,wFlags & 0x1F);
1358}
1359//******************************************************************************
1360// CB: this code is a subset of Win32BaseWindow::DrawCaption
1361// todo: move Win32BaseWindow:DrawCaption to this function
1362//******************************************************************************
1363BOOL WIN32API DrawCaptionTemp(HWND hwnd,HDC hdc,const RECT *rect,HFONT hFont,HICON hIcon,LPWSTR str,UINT uFlags,BOOL unicode)
1364{
1365 RECT rc = *rect;
1366
1367 /* drawing background */
1368 if (uFlags & DC_INBUTTON)
1369 {
1370 FillRect (hdc, &rc, GetSysColorBrush (COLOR_3DFACE));
1371
1372 if (uFlags & DC_ACTIVE)
1373 {
1374 HBRUSH hbr = SelectObject (hdc, GetPattern55AABrush ());
1375 PatBlt (hdc, rc.left, rc.top,
1376 rc.right-rc.left, rc.bottom-rc.top, 0xFA0089);
1377 SelectObject (hdc, hbr);
1378 }
1379 } else
1380 {
1381 FillRect (hdc, &rc, GetSysColorBrush ((uFlags & DC_ACTIVE) ?
1382 COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION));
1383 }
1384
1385 /* drawing icon */
1386 if ((uFlags & DC_ICON) && !(uFlags & DC_SMALLCAP))
1387 {
1388 POINT pt;
1389
1390 pt.x = rc.left + 2;
1391 pt.y = (rc.bottom + rc.top - GetSystemMetrics(SM_CYSMICON)) / 2;
1392
1393 if (hIcon)
1394 {
1395 DrawIconEx (hdc, pt.x, pt.y, hIcon, GetSystemMetrics(SM_CXSMICON),
1396 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
1397 } else
1398 {
1399 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
1400
1401 if (!win32wnd) return 0;
1402
1403 DrawIconEx (hdc, pt.x, pt.y, win32wnd->IconForWindow(ICON_SMALL),
1404 GetSystemMetrics(SM_CXSMICON),
1405 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
1406 }
1407
1408 rc.left += (rc.bottom - rc.top);
1409 }
1410
1411 /* drawing text */
1412 if (uFlags & DC_TEXT)
1413 {
1414 HFONT hOldFont;
1415
1416 if (uFlags & DC_INBUTTON)
1417 SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
1418 else if (uFlags & DC_ACTIVE)
1419 SetTextColor (hdc, GetSysColor (COLOR_CAPTIONTEXT));
1420 else
1421 SetTextColor (hdc, GetSysColor (COLOR_INACTIVECAPTIONTEXT));
1422
1423 SetBkMode (hdc, TRANSPARENT);
1424
1425 if (hFont)
1426 hOldFont = SelectObject (hdc, hFont);
1427 else
1428 {
1429 NONCLIENTMETRICSA nclm;
1430 HFONT hNewFont;
1431
1432 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
1433 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
1434 hNewFont = CreateFontIndirectA ((uFlags & DC_SMALLCAP) ?
1435 &nclm.lfSmCaptionFont : &nclm.lfCaptionFont);
1436 hOldFont = SelectObject (hdc, hNewFont);
1437 }
1438
1439 if (str)
1440 {
1441 if (unicode)
1442 DrawTextW(hdc,str,-1,&rc,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
1443 else
1444 DrawTextA(hdc,(LPSTR)str,-1,&rc,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
1445 } else
1446 {
1447 CHAR szText[128];
1448 INT nLen;
1449
1450 nLen = GetWindowTextA (hwnd, szText, 128);
1451 DrawTextA (hdc, szText, nLen, &rc,
1452 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
1453 }
1454
1455 if (hFont)
1456 SelectObject (hdc, hOldFont);
1457 else
1458 DeleteObject (SelectObject (hdc, hOldFont));
1459 }
1460
1461 /* drawing focus ??? */
1462 //if (uFlags & 0x2000)
1463 // FIXME("undocumented flag (0x2000)!\n");
1464
1465 return 0;
1466}
1467/***********************************************************************
1468 * DrawCaptionTemp32A [USER32.599]
1469 *
1470 * PARAMS
1471 *
1472 * RETURNS
1473 * Success:
1474 * Failure:
1475 */
1476BOOL WIN32API DrawCaptionTempA(HWND hwnd,HDC hdc,const RECT *rect,HFONT hFont,HICON hIcon,LPCSTR str,UINT uFlags)
1477{
1478 dprintf(("USER32: DrawCaptionTempA"));
1479
1480 return DrawCaptionTemp(hwnd,hdc,rect,hFont,hIcon,(LPWSTR)str,uFlags,FALSE);
1481}
1482/***********************************************************************
1483 * DrawCaptionTemp32W [USER32.602]
1484 *
1485 * PARAMS
1486 *
1487 * RETURNS
1488 * Success:
1489 * Failure:
1490 */
1491BOOL WIN32API DrawCaptionTempW (HWND hwnd,HDC hdc,const RECT *rect,HFONT hFont,HICON hIcon,LPCWSTR str,UINT uFlags)
1492{
1493 dprintf(("USER32: DrawCaptionTempA"));
1494
1495 return DrawCaptionTemp(hwnd,hdc,rect,hFont,hIcon,(LPWSTR)str,uFlags,TRUE);
1496}
1497
Note: See TracBrowser for help on using the repository browser.