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

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

resource handling changes

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