]> git.saurik.com Git - wxWidgets.git/blob - src/msw/minifram.cpp
Attempt at getting mingw32 working again... still doesn't work
[wxWidgets.git] / src / msw / minifram.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: minifram.cpp
3 // Purpose: wxMiniFrame
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "minifram.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #include "wx/window.h"
24 #include "wx/msw/private.h"
25
26 #ifndef WX_PRECOMP
27 #include "wx/setup.h"
28 #include "wx/event.h"
29 #include "wx/app.h"
30 #include "wx/utils.h"
31 #endif
32
33 #if wxUSE_ITSY_BITSY
34
35 #include "wx/minifram.h"
36
37 #ifndef __TWIN32__
38 #ifdef __GNUWIN32__
39 #include "wx/msw/gnuwin32/extra.h"
40 #endif
41 #endif
42
43 #if !USE_SHARED_LIBRARY
44 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame, wxFrame)
45 #endif
46
47 long wxMiniFrame::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
48 {
49 if ((GetWindowStyleFlag() & wxTINY_CAPTION_HORIZ) ||
50 (GetWindowStyleFlag() & wxTINY_CAPTION_VERT))
51 return ::ibDefWindowProc((HWND) GetHWND(), nMsg, wParam, lParam);
52 else if ( m_oldWndProc )
53 return ::CallWindowProc(CASTWNDPROC m_oldWndProc, (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
54 else
55 return ::DefWindowProc((HWND) GetHWND(), nMsg, wParam, lParam);
56 }
57
58 wxMiniFrame::~wxMiniFrame(void)
59 {
60 }
61
62 /////////////////////////////////////////////////////////////////////////
63 //
64 // Project: ItsyBitsy window support module
65 // Module: itsybits.c
66 //
67 //
68 // ItsyBitsy is a support module that allows you to create windows
69 // that look and act very much like a popup window witha system
70 // menu and caption bar, except everything is scaled to about 2/3
71 // scale.
72 //
73 // For documentation on how to use ItsyBits, read the document
74 // ITSYBITS.DOC.
75 //
76 // Revisions:
77 // 9/27/91 Charlie Kindel (cek/ckindel)
78 // Wrote and documented it.
79 //
80 // 1/14/93 cek
81 // 2/23/93 cek Added minimize/maximize buttons.
82 // 3/18/93 cek Fixed system menu bug where system menu
83 // popped back up if you clicked on the
84 // icon again while it was up.
85 // 3/24/93 cek More comments. Fixed DS_MODALDIALOG style
86 // problem. Use auto precompiled headers
87 // in MSVC.
88 //
89 //////////////////////////////////////////////////////////////////////////
90
91 #include "wx/window.h"
92 #include "wx/msw/private.h"
93
94 #include <string.h>
95
96 #if !defined( __WATCOMC__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__)
97 #include <memory.h>
98 #endif
99
100 #include <stdlib.h>
101
102 #ifndef _RGB_H_
103 #define _RGB_H_
104
105 // Some mildly useful macros for the standard 16 colors
106 #define RGBBLACK RGB(0,0,0)
107 #define RGBRED RGB(128,0,0)
108 #define RGBGREEN RGB(0,128,0)
109 #define RGBBLUE RGB(0,0,128)
110
111 #define RGBBROWN RGB(128,128,0)
112 #define RGBMAGENTA RGB(128,0,128)
113 #define RGBCYAN RGB(0,128,128)
114 #define RGBLTGRAY RGB(192,192,192)
115
116 #define RGBGRAY RGB(128,128,128)
117 #define RGBLTRED RGB(255,0,0)
118 #define RGBLTGREEN RGB(0,255,0)
119 #define RGBLTBLUE RGB(0,0,255)
120
121 #define RGBYELLOW RGB(255,255,0)
122 #define RGBLTMAGENTA RGB(255,0,255)
123 #define RGBLTCYAN RGB(0,255,255)
124 #define RGBWHITE RGB(255,255,255)
125 #endif
126
127 #ifndef GlobalAllocPtr
128 #define GlobalPtrHandle(lp) \
129 ((HGLOBAL)GlobalHandle(lp))
130
131 #define GlobalLockPtr(lp) \
132 ((BOOL)GlobalLock(GlobalPtrHandle(lp)))
133 #define GlobalUnlockPtr(lp) \
134 GlobalUnlock(GlobalPtrHandle(lp))
135
136 #define GlobalAllocPtr(flags, cb) \
137 (GlobalLock(GlobalAlloc((flags), (cb))))
138 #define GlobalReAllocPtr(lp, cbNew, flags) \
139 (GlobalUnlockPtr(lp), GlobalLock(GlobalReAlloc(GlobalPtrHandle(lp) , (cbNew), (flags))))
140 #define GlobalFreePtr(lp) \
141 (GlobalUnlockPtr(lp), (BOOL)GlobalFree(GlobalPtrHandle(lp)))
142 #endif
143
144 #if defined(__BORLANDC__) || defined(__WATCOMC__)
145 #define max(a,b) (((a) > (b)) ? (a) : (b))
146 #define min(a,b) (((a) < (b)) ? (a) : (b))
147 #endif
148
149 // CAPTIONXY is the default size of the system menu icon. This
150 // determines the height/width of the caption.
151 //
152 // The value that results from the following formula works out
153 // nicely for the veritcal caption on VGA, 8514 (Large Fonts),
154 // 8514 (Small Fonts), XGA (Small Fonts), XGA (Large Fonts),
155 // and TIGA (Small Fonts). It may not be good on other displays.
156 //
157 // The problem is that TT fonts turn into bitmap fonts when they
158 // are sized below a certain threshold. The idea is to make the
159 // size of the caption just big enough to get the smallest TT
160 // (scalable) font to fit.
161 //
162 #define CAPTIONXY (GetSystemMetrics( SM_CYCAPTION ) / 2 + 1)
163
164 #define TestWinStyle( hWnd, dwStyleBit ) \
165 (((DWORD)GetWindowLong( hWnd, GWL_STYLE ) & (DWORD)dwStyleBit) ? TRUE : FALSE )
166 #define HASCAPTION( hwnd ) (TestWinStyle( hwnd, IBS_VERTCAPTION ) ||\
167 TestWinStyle( hwnd, IBS_HORZCAPTION ))
168
169 #define SETCAPTIONSIZE(h,i) (UINT)SetProp(h,"ibSize",(HANDLE)i)
170 #define GETCAPTIONSIZE(h) (UINT)GetProp(h,"ibSize")
171 #define FREECAPTIONSIZE(h) RemoveProp(h,"ibSize")
172
173 #define SETMENUWASUPFLAG(h,i) (UINT)SetProp(h,"ibFlag",(HANDLE)i)
174 #define GETMENUWASUPFLAG(h) (UINT)GetProp(h,"ibFlag")
175 #define FREEMENUWASUPFLAG(h) RemoveProp(h,"ibFlag")
176
177 /////////////////////////////////////////////////////////////////////
178 // Little known fact:
179 // ExtTextOut() is the fastest way to draw a filled rectangle
180 // in Windows (if you don't want dithered colors or borders).
181 //
182 // Unfortunately there is a bug in the Windows 3.0 8514 driver
183 // in using ExtTextOut() to a memory DC. If you are drawing
184 // to an off screen bitmap, then blitting that bitmap to the
185 // display, do not #define wxUSE_EXTTEXTOUT below.
186 //
187 // The following macro (DRAWFASTRECT) draws a filled rectangle
188 // with no border and a solid color. It uses the current back-
189 // ground color as the fill color.
190 //////////////////////////////////////////////////////////////////////
191 #define wxUSE_EXTTEXTOUT
192 #ifdef wxUSE_EXTTEXTOUT
193 #define DRAWFASTRECT(hdc,lprc) ExtTextOut(hdc,0,0,ETO_OPAQUE,lprc,NULL,0,NULL)
194 #else
195 #define DRAWFASTRECT(hdc,lprc) {\
196 HBRUSH hbr = CreateSolidBrush( GetBkColor( hdc ) ) ;\
197 hbr = SelectObject(hdc, hbr) ;\
198 PatBlt(hdc,(lprc)->left,(lprc)->top,(lprc)->right-(lprc)->left,(lprc)->bottom-(lprc)->top,PATCOPY) ;\
199 hbr = SelectObject(hdc, hbr) ;\
200 DeleteObject( hbr ) ;\
201 }
202 #endif
203
204 // The DrawArrow function takes the following to indicate what
205 // kind of arrow to draw.
206 //
207 #define ARROW_UP 0
208 #define ARROW_DOWN 1
209 #define ARROW_RESTORE 2
210
211 BOOL PASCAL DepressMinMaxButton( HWND hWnd, UINT uiHT, LPRECT ) ;
212 BOOL PASCAL DoMenu( HWND hWnd ) ;
213 void PASCAL SetupSystemMenu( HWND hWnd, HMENU hMenu ) ;
214 BOOL PASCAL GetCaptionRect( HWND hWnd, LPRECT lprc ) ;
215 BOOL PASCAL GetIconRect( HWND hWnd, LPRECT lprc ) ;
216 BOOL PASCAL GetButtonRect( HWND hWnd, UINT nPos, LPRECT lprc ) ;
217 BOOL PASCAL GetMinButtonRect( HWND hWnd, LPRECT lprc ) ;
218 BOOL PASCAL GetMaxButtonRect( HWND hWnd, LPRECT lprc ) ;
219 BOOL PASCAL DrawCaption( HDC hDC, HWND hWnd, LPRECT lprc,
220 BOOL fVert, BOOL fSysMenu,
221 BOOL fMin, BOOL fMax, BOOL fActive ) ;
222 void PASCAL DrawSysMenu( HDC hDC, HWND hWnd, BOOL fInvert ) ;
223 void PASCAL DrawButton( HDC hDC, HWND hWnd, BOOL fMin, BOOL fDepressed ) ;
224 void PASCAL DrawArrow( HDC hdc, LPRECT lprc, UINT uiStyle ) ;
225
226 // Global vars
227 //
228 static BOOL fWin31 ;
229
230 ///////////////////////////////////////////////////////////////////////
231 // External/Public functions
232 ///////////////////////////////////////////////////////////////////////
233
234 /////////////////////////////////////////////////////////////////
235 // UINT WINAPI ibGetCaptionSize( HWND hWnd )
236 //
237 // Description:
238 //
239 // Gets the size of the caption (height if horz, width if
240 // vertical).
241 //
242 // Comments:
243 //
244 ///////////////////////////////////////////////////////////////
245 UINT WINAPI ibGetCaptionSize( HWND hWnd )
246 {
247 return GETCAPTIONSIZE( hWnd ) + 1 ;
248 } // ibSetCaptionSize()
249
250 /////////////////////////////////////////////////////////////////
251 // UINT WINAPI ibSetCaptionSize( HWND hWnd, UINT nSize )
252 //
253 // Description:
254 //
255 // Changes the size of the caption (height if horz, width if
256 // vertical).
257 //
258 // Comments:
259 //
260 //////////////////////////////////////////////////////////////////
261 UINT WINAPI ibSetCaptionSize( HWND hWnd, UINT nSize )
262 {
263 UINT ui ;
264
265 if (nSize <= 0)
266 return 0 ;
267
268 nSize-- ;
269 ui = SETCAPTIONSIZE( hWnd, nSize ) ;
270
271 // Once we change the window style, we need a WM_NCCALCRECT
272 // to be generated.
273 //
274 // SWP_FRAMECHANGED is not documented in the 3.1 SDK docs,
275 // but *is* in WINDOWS.H.
276 //
277 SetWindowPos( hWnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED |
278 SWP_NOSIZE | SWP_NOMOVE |
279 SWP_NOACTIVATE | SWP_NOZORDER) ;
280
281 return ui ;
282
283 } // ibSetCaptionSize()
284
285 /////////////////////////////////////////////////////////////////
286 // LRESULT WINAPI ibDefWindowProc( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
287 //
288 // Description:
289 //
290 // This function should be called instead of DefWindowProc() for
291 // windows that want to have itsybitsy captions.
292 //
293 // Comments:
294 //
295 //////////////////////////////////////////////////////////////////
296 LRESULT WINAPI ibDefWindowProc( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
297 {
298 LRESULT lRet ;
299 UINT nCapSize ;
300
301 switch( uiMsg )
302 {
303 case WM_SYSCHAR:
304 // If ALT-SPACE
305 // was hit then pop up the menu
306 //
307 if (HASCAPTION( hWnd ) && (wParam == VK_SPACE))
308 {
309 DoMenu( hWnd ) ;
310 break ;
311 }
312
313 // FALL THROUGH!!!!
314 //
315
316 case WM_SYSKEYDOWN:
317 case WM_SYSKEYUP:
318 case WM_KEYDOWN:
319 case WM_KEYUP:
320 {
321 DWORD dw = GetWindowLong( hWnd, GWL_STYLE ) ;
322
323 // Fool DefWindowProc into thinking we do not have
324 // a system menu. Otherwise it will try to
325 // pop up its own.
326 //
327 SetWindowLong( hWnd, GWL_STYLE, dw &~WS_SYSMENU ) ;
328 lRet = DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
329 SetWindowLong( hWnd, GWL_STYLE, dw ) ;
330 return lRet ;
331 }
332 break ;
333
334 case WM_COMMAND:
335 // The menu that is poped up for the system menu with
336 // TrackPopupMenu() sends it's notifications as WM_COMMAND
337 // messages. We need to translate these into
338 // WM_SYSCOMMAND messages. All standard WM_SYSCOMMAND
339 // ids are greater than 0xF000.
340 //
341 // This could be a possible cause of confusion if the
342 // itsybitsy window had children that used SC_MOVE or SC_CLOSE
343 // as their IDs. Take note and be careful.
344 //
345 // Also, because ibDefWindowProc looks at WM_COMMAND messages,
346 // you will need to be careful to call ibDefWindowProc() for
347 // any wm_command messages that you would normally ignore.
348 // Otherwise the system menu won't work.
349 //
350 if (wParam >= 0xF000)
351 // Call PostMessage() here instead of SendMessage!
352 // Here's why:
353 // Our menu was created by TrackPopupMenu(). TPM() does
354 // not return until after the menu has been destroyed
355 // (and thus the command associated with the menu selection
356 // sent). Therefore when we get here, we are still
357 // *inside* TPM(). If we Send WM_SYSCOMMAND, SC_CLOSE
358 // to the window, the window will be destroyed before
359 // TPM() returns to our code within DoMenu() below. Wel...
360 // We do stuff with the window handle after DoMenu()
361 // returns (namely GetProp()). Since the window has
362 // been destroyed,this is bad.
363 PostMessage( hWnd, WM_SYSCOMMAND, wParam, lParam ) ;
364
365 return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
366
367 case WM_GETMINMAXINFO:
368 {
369 nCapSize = GETCAPTIONSIZE( hWnd ) ;
370 if (HASCAPTION( hWnd ) && TestWinStyle( hWnd, WS_THICKFRAME ))
371 {
372 LPPOINT lppt = (LPPOINT)lParam ;
373 RECT rcMenu ;
374 RECT rcMin ;
375 RECT rcMax ;
376 int nX ;
377 int cx, cy ; // window frame/border width
378
379 if (TestWinStyle( hWnd, WS_THICKFRAME ))
380 {
381 cx = GetSystemMetrics( SM_CXFRAME ) ;
382 cy = GetSystemMetrics( SM_CYFRAME ) ;
383 }
384 else if (TestWinStyle(hWnd, WS_BORDER ))
385 {
386 cx = GetSystemMetrics( SM_CXBORDER ) ;
387 cy = GetSystemMetrics( SM_CYBORDER ) ;
388 }
389 else
390 {
391 // VZ: I don't know what should be here, but the vars must
392 // be inited!
393 wxFAIL_MSG("don't know how to initialize cx, cy");
394
395 cx = cy = 0;
396 }
397
398 GetIconRect( hWnd, &rcMenu ) ;
399 GetMinButtonRect( hWnd, &rcMin ) ;
400 GetMaxButtonRect( hWnd, &rcMax ) ;
401 nX = (rcMenu.right-rcMenu.left) +
402 (rcMin.right-rcMin.left) +
403 (rcMin.right-rcMin.left) ;
404
405
406 if (TestWinStyle( hWnd, IBS_VERTCAPTION ) )
407 {
408 lppt[3].x = nCapSize + cx * 2 - 1 ;
409 lppt[3].y = nX + (2* nCapSize) ;
410 }
411 else
412 {
413 lppt[3].x = nX + (2* nCapSize) ;
414 lppt[3].y = nCapSize + cy * 2 - 1 ;
415 }
416 }
417 return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
418 }
419 break ;
420
421 /////////////////////////////////////////////////////////////////////
422 // Non-client area messages. These are used to allow the
423 // minature caption bar to be handled correctly.
424 //
425 case WM_NCCREATE:
426 {
427 DWORD dwStyle ;
428
429 // We have two things that we need to store somewhere:
430 // 1) The caption height (width).
431 // and 2) A flag indicating whether the sysmenu was
432 // just up or not.
433 //
434 // CAPTIONXY is a macro that calls GetSystemMetrics.
435 //
436 SETCAPTIONSIZE( hWnd, CAPTIONXY ) ;
437
438 // Set our flag that tells us whether the system menu was
439 // 'just up'.
440 //
441 SETMENUWASUPFLAG( hWnd, FALSE ) ;
442
443 // Are we in 3.1? If so we have some neat features
444 // we can use like rotated TrueType fonts.
445 //
446 fWin31 = (BOOL)(LOWORD( GetVersion() ) >= 0x030A) ;
447
448 // If IBS_????CAPTION was specified and the WS_DLGFRAME (or
449 // WS_DLGFRAME 'cause it == WS_CAPTION | WS_BORDER)
450 // was specified the creator made a mistake. Things get really
451 // ugly if DefWindowProc sees WS_DLGFRAME, so we strip
452 // the WS_DLGFRAME part off!
453 //
454 dwStyle = GetWindowLong( hWnd, GWL_STYLE ) ;
455 if ((dwStyle & IBS_VERTCAPTION || dwStyle & IBS_HORZCAPTION) &&
456 dwStyle & WS_DLGFRAME)
457 {
458 dwStyle &= (DWORD)~WS_DLGFRAME ;
459 SetWindowLong( hWnd, GWL_STYLE, dwStyle ) ;
460 }
461 }
462 return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
463
464 case WM_NCDESTROY:
465 // We store the caption size in a window prop. so we
466 // must remove props.
467 //
468 FREECAPTIONSIZE( hWnd ) ;
469 FREEMENUWASUPFLAG( hWnd ) ;
470 return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
471
472 case WM_NCCALCSIZE:
473 // This is sent when the window manager wants to find out
474 // how big our client area is to be. If we have a mini-caption
475 // then we trap this message and calculate the cleint area rect,
476 // which is the client area rect calculated by DefWindowProc()
477 // minus the width/height of the mini-caption bar
478 //
479 lRet = DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
480 if (!IsIconic( hWnd ) && HASCAPTION( hWnd ))
481 {
482 nCapSize = GETCAPTIONSIZE( hWnd ) ;
483
484 if (TestWinStyle( hWnd, IBS_VERTCAPTION ) )
485 ((LPRECT)lParam)->left += nCapSize ;
486 else
487 ((LPRECT)lParam)->top += nCapSize ;
488 }
489 return lRet ;
490
491 case WM_NCHITTEST:
492 // This message is sent whenever the mouse moves over us.
493 // We will depend on DefWindowProc for everything unless
494 // there is a mini-caption, in which case we will
495 // return HTCAPTION or HTSYSMENU. When the user clicks
496 // or double clicks, NC_LBUTTON/ message are sent with
497 // wParam equal to what we return here.
498 // This means that this is an ideal place to figure out
499 // where we are!
500 //
501 // let defwindowproc handle the standard borders etc...
502 //
503 lRet = DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
504 if (!IsIconic( hWnd ) && HASCAPTION( hWnd ) && lRet == HTNOWHERE)
505 {
506 RECT rc ;
507 RECT rcMenu ;
508 RECT rcMinButton ;
509 RECT rcMaxButton ;
510 POINT pt ;
511
512 nCapSize = GETCAPTIONSIZE( hWnd ) ;
513
514 // if DefWindowProc returned HTCAPTION then we have to
515 // refine the area and return HTSYSMENU if appropriate
516 //
517 pt.x = LOWORD( lParam ) ;
518 pt.y = HIWORD( lParam ) ;
519
520 GetCaptionRect( hWnd, &rc ) ; // window coords
521 if (PtInRect( &rc, pt ))
522 {
523 lRet = HTCAPTION ;
524
525 // rely on the fact that Get???Rect() return an invalid
526 // (empty) rectangle if the menu/buttons don't exist
527 //
528 GetIconRect( hWnd, &rcMenu ) ;
529 GetMinButtonRect( hWnd, &rcMinButton ) ;
530 GetMaxButtonRect( hWnd, &rcMaxButton ) ;
531
532 if (PtInRect( &rcMenu, pt ))
533 lRet = HTSYSMENU ;
534
535 if (PtInRect( &rcMinButton, pt ))
536 lRet = HTMINBUTTON ;
537 else
538 if (PtInRect( &rcMaxButton, pt ))
539 lRet = HTMAXBUTTON ;
540 }
541 }
542 if (lRet != HTSYSMENU)
543 SETMENUWASUPFLAG( hWnd, FALSE ) ;
544 return lRet ;
545
546 case WM_NCLBUTTONDBLCLK:
547 // Windows recieve WM_NC?BUTTONDBLCLK messages whether they
548 // have CS_DBLCLKS or not. We watch for one of these
549 // to see if the user double clicked on the system menu (to
550 // close the window) or on the caption (to maximize the window).
551 //
552 if (!IsIconic( hWnd ) && HASCAPTION( hWnd ) && wParam == HTSYSMENU)
553 {
554 SendMessage( hWnd, WM_CLOSE, 0, 0L ) ;
555 break ;
556 }
557 return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
558
559 case WM_NCLBUTTONDOWN:
560 {
561 RECT rc ;
562
563 // If we're iconic or we don't have a caption then
564 // DefWindowProc will do the job just fine.
565 //
566 if (IsIconic( hWnd ) || !HASCAPTION( hWnd ))
567 return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
568
569 // Here's were we handle the system menu, the min and max buttons.
570 // If you wanted to change the behavior of the min/max buttons
571 // do something like swap tool palettes or something, you
572 // would change the SendMessage() calls below.
573 //
574 switch (wParam)
575 {
576 case HTSYSMENU:
577 if (GETMENUWASUPFLAG( hWnd ) == FALSE && DoMenu( hWnd ))
578 SETMENUWASUPFLAG( hWnd, TRUE ) ;
579 else
580 SETMENUWASUPFLAG( hWnd, FALSE ) ;
581 break ;
582
583 case HTMINBUTTON:
584 GetMinButtonRect( hWnd, &rc ) ;
585 // Note that DepressMinMaxButton() goes into
586 // a PeekMessage() loop waiting for the mouse
587 // to come back up.
588 //
589 if (DepressMinMaxButton( hWnd, wParam, &rc ))
590 SendMessage( hWnd, WM_SYSCOMMAND, SC_MINIMIZE, lParam ) ;
591 break ;
592
593 case HTMAXBUTTON:
594 GetMaxButtonRect( hWnd, &rc ) ;
595 // Note that DepressMinMaxButton() goes into
596 // a PeekMessage() loop waiting for the mouse
597 // to come back up.
598 //
599 if (DepressMinMaxButton( hWnd, wParam, &rc ))
600 {
601 if (IsZoomed(hWnd))
602 SendMessage( hWnd, WM_SYSCOMMAND, SC_RESTORE, lParam ) ;
603 else
604 SendMessage( hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, lParam ) ;
605 }
606 break ;
607
608 default:
609 // Well, it appears as though the user clicked somewhere other
610 // than the buttons. We let DefWindowProc do it's magic.
611 // This is where things like dragging and sizing the
612 // window happen.
613 //
614 return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
615 }
616 }
617 break ;
618
619 case WM_NCPAINT:
620 case WM_NCACTIVATE:
621 if (IsIconic( hWnd ))
622 return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
623
624 // Paint the non-client area here. We will call DefWindowProc
625 // after we are done so it can paint the borders and so
626 // forth...
627 //
628 lRet = DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
629 if (HASCAPTION( hWnd ))
630 {
631 RECT rcCap ;
632 RECT rc ;
633 HDC hDC = GetWindowDC( hWnd ) ;
634 BOOL fActive ;
635
636 GetCaptionRect( hWnd, &rcCap ) ; // Convert to window coords
637 GetWindowRect( hWnd, &rc ) ;
638 OffsetRect( &rcCap, -rc.left, -rc.top ) ;
639
640 if (uiMsg == WM_NCPAINT)
641 fActive = (hWnd == GetActiveWindow()) ;
642 else
643 fActive = wParam ;
644
645 DrawCaption( hDC, hWnd, &rcCap,
646 TestWinStyle(hWnd, IBS_VERTCAPTION),
647 TestWinStyle(hWnd, WS_SYSMENU),
648 TestWinStyle(hWnd, WS_MINIMIZEBOX),
649 TestWinStyle(hWnd, WS_MAXIMIZEBOX),
650 fActive ) ;
651
652 ReleaseDC( hWnd, hDC ) ;
653 }
654 return lRet;
655 break;
656
657 default:
658 return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
659 }
660
661 return 0L ;
662
663 } // ibDefWindowProc()
664
665 // ibAdjustWindowRect( HWND hWnd, LPRECT lprc )
666 //
667 // Does the same thing as the USER function AdjustWindowRect(),
668 // but knows about itsybitsy windows. AdjustWindowRect() is
669 // bogus for stuff like this.
670 //
671 void WINAPI ibAdjustWindowRect( HWND hWnd, LPRECT lprc )
672 {
673 short cx = 0, cy = 0 ;
674 UINT nCapSize ;
675
676 nCapSize = GETCAPTIONSIZE( hWnd ) ;
677
678 // First check Windows's styles, then our own.
679 //
680 if (TestWinStyle( hWnd, WS_THICKFRAME ))
681 {
682 cx = GetSystemMetrics( SM_CXFRAME ) ;
683 cy = GetSystemMetrics( SM_CYFRAME ) ;
684 }
685 else
686 if (TestWinStyle(hWnd, DS_MODALFRAME ))
687 {
688 cx = GetSystemMetrics( SM_CXDLGFRAME ) + GetSystemMetrics( SM_CXBORDER ) ;
689 cy = GetSystemMetrics( SM_CYDLGFRAME ) + GetSystemMetrics( SM_CYBORDER ) ;
690 }
691 else
692 if (TestWinStyle(hWnd, WS_BORDER ))
693 {
694 cx = GetSystemMetrics( SM_CXBORDER ) ;
695 cy = GetSystemMetrics( SM_CYBORDER ) ;
696 }
697
698 InflateRect( lprc, cx, cy ) ;
699
700 if (TestWinStyle( hWnd, IBS_VERTCAPTION ))
701 lprc->left -= nCapSize ;
702 else
703 if (TestWinStyle( hWnd, IBS_HORZCAPTION ))
704 lprc->top -= nCapSize ;
705
706 } // ibAdjustWindowRect()
707
708
709 ///////////////////////////////////////////////////////////////////////
710 // Internal functions
711 ///////////////////////////////////////////////////////////////////////
712
713 // DepressMinMaxButton()
714 //
715 // This function is called when the user has pressed either the min or
716 // max button (i.e. WM_NCLBUTTONDOWN). We go into a Peekmessage() loop,
717 // waiting for the mouse to come back up. This allows us to make the
718 // button change up/down state like a real button does.
719 //
720 // lprc points to the rectangle that describes the button the
721 // user has clicked on.
722 //
723 BOOL PASCAL DepressMinMaxButton( HWND hWnd, UINT uiHT, LPRECT lprc )
724 {
725 BOOL fDepressed = TRUE ;
726 MSG msg ;
727
728 // Draw button in down state
729 DrawButton( NULL, hWnd, uiHT == HTMINBUTTON, fDepressed ) ;
730 SetCapture( hWnd ) ;
731
732 while (TRUE)
733 {
734 if (PeekMessage((LPMSG)&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
735 {
736 switch (msg.message)
737 {
738 case WM_LBUTTONUP:
739 if (fDepressed)
740 DrawButton( NULL, hWnd, uiHT == HTMINBUTTON, !fDepressed ) ;
741 ReleaseCapture();
742 return PtInRect( lprc, msg.pt ) ;
743
744 case WM_MOUSEMOVE:
745 if (PtInRect( lprc, msg.pt ))
746 {
747 if (!fDepressed)
748 DrawButton( NULL, hWnd, uiHT == HTMINBUTTON, fDepressed = TRUE ) ;
749 }
750 else
751 {
752 if (fDepressed)
753 DrawButton( NULL, hWnd, uiHT == HTMINBUTTON, fDepressed = FALSE ) ;
754 }
755 break;
756 }
757 }
758 }
759
760 } // DepressMinMaxButton()
761
762 // DrawCaption( HDC hDC, HWND hWnd, LPRECT lprc,
763 // BOOL fVert, BOOL fSysMenu, BOOL fActive )
764 //
765 // This function draws an itsy bitsy caption bar with or
766 // without system menu to the dc specified by hDC. The
767 // caption is drawn to fit within the lprc RECT and is
768 // drawn//withOut/ borders.
769 //
770 BOOL PASCAL DrawCaption( HDC hDC, HWND hWnd, LPRECT lprc,
771 BOOL fVert, BOOL fSysMenu, BOOL fMin,
772 BOOL fMax, BOOL fActive )
773 {
774 RECT rc ;
775 RECT rcCap ;
776 COLORREF rgbCaptionBG ;
777 COLORREF rgbText ;
778 COLORREF rgbWindowFrame ;
779 HBRUSH hbrCaption ;
780 UINT ui ;
781 UINT nCapSize ;
782
783 nCapSize = GETCAPTIONSIZE( hWnd ) ;
784
785 // Get the colors.
786 //
787 rgbWindowFrame = GetSysColor( COLOR_WINDOWFRAME ) ;
788
789 // if we have focus use the active caption color
790 // otherwise use the inactive caption color
791 //
792 if (fActive)
793 {
794 rgbText = GetSysColor( COLOR_CAPTIONTEXT ) ;
795 rgbCaptionBG = GetSysColor( COLOR_ACTIVECAPTION ) ;
796 }
797 else
798 {
799 if (fWin31)
800 rgbText = GetSysColor( COLOR_INACTIVECAPTIONTEXT ) ;
801 else
802 rgbText = GetSysColor( COLOR_CAPTIONTEXT ) ;
803
804 rgbCaptionBG = GetSysColor( COLOR_INACTIVECAPTION ) ;
805 }
806
807 SetBkMode( hDC, TRANSPARENT ) ;
808 SelectObject( hDC, GetStockObject( NULL_BRUSH ) ) ;
809 SelectObject( hDC, GetStockObject( NULL_PEN ) ) ;
810
811 rcCap = *lprc ;
812
813 if (fSysMenu)
814 {
815 if (fVert)
816 rcCap.top += nCapSize ;
817 else
818 rcCap.left += nCapSize ;
819 }
820
821 if (fMax)
822 {
823 if (fVert)
824 rcCap.bottom -= nCapSize ;
825 else
826 rcCap.right -= nCapSize ;
827 }
828
829 if (fMin)
830 {
831 if (fVert)
832 rcCap.bottom -= nCapSize ;
833 else
834 rcCap.right -= nCapSize ;
835 }
836
837 if (fVert)
838 {
839 rc.left = lprc->right - 1 ;
840 rc.right = lprc->right ;
841 rc.top = lprc->top ;
842 rc.bottom = lprc->bottom ;
843 }
844 else
845 {
846 rc.left = lprc->left ;
847 rc.right = lprc->right ;
848 rc.bottom = lprc->bottom ;
849 rc.top = rc.bottom - 1 ;
850 }
851
852 SetBkColor( hDC, rgbWindowFrame ) ;
853 DRAWFASTRECT( hDC, &rc ) ;
854
855 hbrCaption = CreateSolidBrush( rgbCaptionBG ) ;
856 hbrCaption = (HBRUSH) SelectObject( hDC, hbrCaption ) ;
857 SelectObject( hDC, (HPEN) GetStockObject( NULL_PEN ) ) ;
858 if (fVert)
859 Rectangle( hDC, rcCap.left, rcCap.top, rcCap.right, rcCap.bottom + 1 ) ;
860 else
861 Rectangle( hDC, rcCap.left, rcCap.top, rcCap.right+1, rcCap.bottom ) ;
862 hbrCaption = (HBRUSH) SelectObject( hDC, hbrCaption ) ;
863 DeleteObject( hbrCaption ) ;
864
865
866 // Draw caption text here. Only do it in 3.1 'cause 3.1 gives
867 // us 'small fonts'.
868 //
869 ui = GetWindowTextLength( hWnd ) ;
870 if (fWin31)
871 {
872 HFONT hFont ;
873 LPSTR lpsz ;
874 LOGFONT lf ;
875 TEXTMETRIC tm ;
876 int cx ;
877 int cy ;
878 SIZE Size ;
879
880 lpsz = (char*)GlobalAllocPtr( GHND, ui + 2 );
881 if (lpsz)
882 {
883 UINT nBkMode ;
884
885 GetWindowText( hWnd, lpsz, ui + 1 ) ;
886 nBkMode = SetBkMode( hDC, TRANSPARENT ) ;
887 rgbText = SetTextColor( hDC, rgbText ) ;
888
889 memset( &lf, '\0', sizeof(LOGFONT) ) ;
890
891 lf.lfHeight = -(int)(nCapSize - 3) ;
892 lf.lfCharSet = ANSI_CHARSET ;
893 lf.lfQuality = DEFAULT_QUALITY ;
894 lf.lfClipPrecision = CLIP_LH_ANGLES | CLIP_STROKE_PRECIS ;
895 if (nCapSize >= 20)
896 {
897 lf.lfWeight = FW_BOLD ;
898 }
899
900 if (fVert)
901 {
902 // Can only rotate true type fonts (well, ok, we could
903 // try and use "modern").
904 strcpy( lf.lfFaceName, "Arial" ) ;
905 lf.lfPitchAndFamily = FF_SWISS | 0x04;
906 lf.lfEscapement = 900 ;
907
908 // Note: The Win 3.1 documentation for CreateFont() say's
909 // that the lfOrientation member is ignored. It appears,
910 // that on Windows 16 3.1 this is true, but when running
911 // as a 16 bit WinApp on WindowsNT 3.1 the lfOrientation
912 // must be set or the text does not rotate!
913 //
914 lf.lfOrientation = 900 ;
915
916 hFont = CreateFontIndirect( &lf ) ;
917 hFont = (HFONT) SelectObject( hDC, hFont ) ;
918
919 GetTextExtentPoint( hDC, lpsz, ui, &Size ) ;
920 cx = rcCap.bottom - ((rcCap.bottom - rcCap.top - Size.cx) / 2) ;
921 cy = rcCap.left - 1 + ((rcCap.right - rcCap.left - Size.cy) / 2) ;
922
923 // Make sure we got a rotatable font back.
924 //
925 GetTextMetrics( hDC, &tm ) ;
926 if (tm.tmPitchAndFamily & TMPF_VECTOR ||
927 tm.tmPitchAndFamily & TMPF_TRUETYPE)
928 {
929 ExtTextOut( hDC,
930 cy,
931 min( (long)cx, rcCap.bottom),
932 ETO_CLIPPED, &rcCap,
933 lpsz, ui, NULL ) ;
934 }
935
936 hFont = (HFONT) SelectObject( hDC, hFont ) ;
937 DeleteObject( hFont ) ;
938 }
939 else
940 {
941 // Use small fonts always for the horizontal. Cause it looks
942 // more like "System" than Arial.
943 //
944 lf.lfPitchAndFamily = FF_SWISS ;
945
946 hFont = CreateFontIndirect( &lf ) ;
947 hFont = (HFONT) SelectObject( hDC, hFont ) ;
948
949 GetTextExtentPoint( hDC, lpsz, ui, &Size ) ;
950 cx = rcCap.left + ((rcCap.right - rcCap.left - Size.cx) / 2) ;
951 cy = rcCap.top + ((rcCap.bottom - rcCap.top - Size.cy) / 2) ;
952
953 // Figger out how big the string is
954 //
955 ExtTextOut( hDC,
956 max( (long)cx, rcCap.left ),
957 cy,
958 ETO_CLIPPED, &rcCap,
959 lpsz, ui, NULL ) ;
960
961 hFont = (HFONT) SelectObject( hDC, hFont ) ;
962 DeleteObject( hFont ) ;
963 }
964
965 // Unsetup the DC
966 //
967 rgbText = SetTextColor( hDC, rgbText ) ;
968 SetBkMode( hDC, nBkMode ) ;
969
970 GlobalFreePtr( lpsz ) ;
971 }
972 }
973
974 if (fSysMenu)
975 DrawSysMenu( hDC, hWnd, FALSE ) ;
976
977 if (fMin)
978 DrawButton( hDC, hWnd, TRUE, FALSE ) ;
979
980 if (fMax)
981 DrawButton( hDC, hWnd, FALSE, FALSE ) ;
982
983 return TRUE ;
984
985 } // DrawCaption()
986
987
988 // DrawSysMenu( HDC hDC, hWnd, BOOL fInvert )
989 //
990 // Draws the little system menu icon.
991 //
992 void PASCAL DrawSysMenu( HDC hDC, HWND hWnd, BOOL fInvert )
993 {
994 RECT rcIcon ;
995 RECT rcTemp ;
996 RECT rc ;
997 COLORREF rgbIconFace ;
998 COLORREF rgbWindowFrame ;
999 BOOL fDC ;
1000 UINT nCapSize ;
1001
1002 nCapSize = GETCAPTIONSIZE( hWnd ) ;
1003
1004 if (!hDC)
1005 {
1006 fDC = TRUE ;
1007 hDC = GetWindowDC( hWnd ) ;
1008 }
1009 else
1010 fDC = FALSE ;
1011
1012 if (hDC)
1013 {
1014 rgbIconFace = GetNearestColor( hDC, RGBLTGRAY ) ;
1015 rgbWindowFrame = GetSysColor( COLOR_WINDOWFRAME ) ;
1016
1017 GetIconRect( hWnd, &rcIcon ) ;
1018 GetWindowRect( hWnd, &rc ) ;
1019
1020 OffsetRect( &rcIcon, -rc.left, -rc.top ) ;
1021
1022 rcTemp = rcIcon ;
1023
1024 if (TestWinStyle( hWnd, IBS_VERTCAPTION ))
1025 {
1026 rc = rcIcon ; // separator line
1027 rc.top = ++rc.bottom - 1 ;
1028 }
1029 else
1030 {
1031 rc = rcIcon ; // separator line
1032 rc.left = ++rc.right - 1 ;
1033 }
1034
1035 // Fill
1036 SetBkColor( hDC, rgbIconFace ) ;
1037 DRAWFASTRECT( hDC, &rcTemp ) ;
1038
1039 // Draw separator line
1040 SetBkColor( hDC, rgbWindowFrame ) ;
1041 DRAWFASTRECT( hDC, &rc ) ;
1042
1043 if (nCapSize > 4)
1044 {
1045 // Draw the little horizontal doo-hickey
1046 //
1047 rcTemp.top = rcIcon.top + ((nCapSize-1) / 2) ;
1048 rcTemp.bottom = rcTemp.top + 3 ;
1049 rcTemp.left = rcTemp.left + 3 ;
1050 rcTemp.right = rcTemp.right - 1 ;
1051
1052 SetBkColor( hDC, RGBGRAY ) ;
1053 DRAWFASTRECT( hDC, &rcTemp ) ;
1054
1055 rc = rcTemp ;
1056 OffsetRect( &rc, -1, -1 ) ;
1057 SetBkColor( hDC, RGBBLACK ) ;
1058 DRAWFASTRECT( hDC, &rc ) ;
1059
1060 InflateRect( &rc, -1, -1 ) ;
1061 SetBkColor( hDC, RGBWHITE ) ;
1062 DRAWFASTRECT( hDC, &rc ) ;
1063 }
1064
1065 if (fInvert)
1066 InvertRect( hDC, &rcIcon ) ;
1067
1068 if (fDC)
1069 ReleaseDC( hWnd, hDC ) ;
1070 }
1071
1072 } // DrawSysMenu()
1073
1074 // DoMenu( HWND hWnd )
1075 //
1076 // Pops up the system menu.
1077 //
1078 BOOL PASCAL DoMenu( HWND hWnd )
1079 {
1080 HDC hDC ;
1081 RECT rcIcon ;
1082 RECT rc ;
1083 POINT pt ;
1084 HMENU hMenu ;
1085 DWORD dw ;
1086
1087 if (!TestWinStyle(hWnd, WS_SYSMENU))
1088 return FALSE ;
1089
1090 hDC = GetWindowDC( hWnd );
1091 if (hDC)
1092 {
1093 // Invert the icon
1094 //
1095 DrawSysMenu( hDC, hWnd, TRUE ) ;
1096
1097 // Pop up the menu
1098 //
1099 if (TestWinStyle( hWnd, IBS_VERTCAPTION ))
1100 {
1101 pt.x = -1 ;
1102 pt.y = 0 ;
1103 }
1104 else
1105 {
1106 pt.x = 0 ;
1107 pt.y = -1 ;
1108 }
1109
1110 GetIconRect( hWnd, &rcIcon ) ;
1111 GetWindowRect( hWnd, &rc ) ;
1112 OffsetRect( &rcIcon, -rc.left, -rc.top ) ;
1113
1114 ClientToScreen( hWnd, &pt ) ;
1115 ClientToScreen( hWnd, (LPPOINT)&rc.right ) ;
1116
1117 dw = GetWindowLong( hWnd, GWL_STYLE ) ;
1118 SetWindowLong( hWnd, GWL_STYLE, dw | WS_SYSMENU ) ;
1119
1120 hMenu = GetSystemMenu( hWnd, FALSE ) ;
1121 SetupSystemMenu( hWnd, hMenu ) ;
1122
1123 SetWindowLong( hWnd, GWL_STYLE, dw ) ;
1124
1125 TrackPopupMenu( hMenu, 0, //TPM_LEFTALIGN,
1126 pt.x,
1127 pt.y,
1128 0,
1129 hWnd,
1130 &rc ) ;
1131
1132 DrawSysMenu( hDC, hWnd, FALSE ) ;
1133 ReleaseDC( hWnd, hDC ) ;
1134 }
1135 return TRUE ;
1136
1137 } // DoMenu()
1138
1139 // SetupSystemMenu( HWND hWnd, HMENU hMenu )
1140 //
1141 // Enables/Disables the appropriate menu items on the
1142 // menu passed for the window passed.
1143 //
1144 void PASCAL SetupSystemMenu( HWND hWnd, HMENU hMenu )
1145 {
1146 UINT wMove ;
1147 UINT wSize ;
1148 UINT wMinBox ;
1149 UINT wMaxBox ;
1150 UINT wRestore ;
1151
1152 // Assume all should be grayed.
1153 //
1154 wSize = wMove = wMinBox = wMaxBox = wRestore = MF_GRAYED ;
1155
1156 if (TestWinStyle( hWnd, WS_MAXIMIZEBOX ) || IsIconic( hWnd ))
1157 wMaxBox = MF_ENABLED ;
1158
1159 if (TestWinStyle( hWnd, WS_MINIMIZEBOX ))
1160 wMinBox = MF_ENABLED ;
1161
1162 if (IsZoomed( hWnd ))
1163 wRestore = MF_ENABLED ;
1164
1165 if (TestWinStyle( hWnd, WS_THICKFRAME ) &&
1166 !(IsIconic( hWnd ) || IsZoomed( hWnd )))
1167 wSize = MF_ENABLED ;
1168
1169 if (!IsZoomed( hWnd ) &&
1170 !IsIconic( hWnd ) &&
1171 TestWinStyle( hWnd, WS_CAPTION ) )
1172 wMove = MF_ENABLED ;
1173
1174 EnableMenuItem( hMenu, SC_MOVE, wMove ) ;
1175 EnableMenuItem( hMenu, SC_SIZE, wSize ) ;
1176 EnableMenuItem( hMenu, SC_MINIMIZE, wMinBox ) ;
1177 EnableMenuItem( hMenu, SC_MAXIMIZE, wMaxBox ) ;
1178 EnableMenuItem( hMenu, SC_RESTORE, wRestore ) ;
1179
1180 } // SetupSystemMenu()
1181
1182 // GetCaptionRect( HWND hWnd, LPRECT lprc )
1183 //
1184 // calcluales the rectangle of the mini-caption in screen coords.
1185 //
1186 BOOL PASCAL GetCaptionRect( HWND hWnd, LPRECT lprc )
1187 {
1188 UINT nCapSize ;
1189
1190 nCapSize = GETCAPTIONSIZE( hWnd ) ;
1191
1192 if (!HASCAPTION( hWnd ))
1193 {
1194 SetRectEmpty( lprc ) ;
1195 return FALSE ;
1196 }
1197
1198 GetWindowRect( hWnd, lprc ) ;
1199
1200 // the window might have other non-client components like
1201 // borders
1202 //
1203 if (TestWinStyle( hWnd, WS_THICKFRAME ))
1204 {
1205 lprc->left += GetSystemMetrics( SM_CXFRAME ) ;
1206 lprc->top += GetSystemMetrics( SM_CYFRAME ) ;
1207 lprc->right -= GetSystemMetrics( SM_CXFRAME ) ;
1208 lprc->bottom -= GetSystemMetrics( SM_CYFRAME ) ;
1209 }
1210 else
1211 if (TestWinStyle( hWnd, DS_MODALFRAME )) // if it's a dialog box
1212 {
1213 lprc->left += GetSystemMetrics( SM_CXDLGFRAME ) + GetSystemMetrics( SM_CXBORDER ) ;
1214 lprc->top += GetSystemMetrics( SM_CYDLGFRAME ) + GetSystemMetrics( SM_CYBORDER ) ;
1215 lprc->right -= GetSystemMetrics( SM_CXDLGFRAME ) + GetSystemMetrics( SM_CXBORDER ) ;
1216 lprc->bottom -= GetSystemMetrics( SM_CYDLGFRAME ) + GetSystemMetrics( SM_CYBORDER ) ;
1217 }
1218 else
1219 if (TestWinStyle( hWnd, WS_BORDER ))
1220 {
1221 lprc->left += GetSystemMetrics( SM_CXBORDER ) ;
1222 lprc->top += GetSystemMetrics( SM_CYBORDER ) ;
1223 lprc->right -= GetSystemMetrics( SM_CXBORDER ) ;
1224 lprc->bottom -= GetSystemMetrics( SM_CYBORDER ) ;
1225 }
1226
1227 if (TestWinStyle( hWnd, IBS_VERTCAPTION ))
1228 lprc->right = lprc->left + nCapSize ;
1229 else
1230 lprc->bottom = lprc->top + nCapSize ;
1231
1232 return TRUE ;
1233 } // GetCaptionRect()
1234
1235 // GetIconRect( HWND hWnd, LPRECT lprc )
1236 //
1237 // Calculates the rect of the icon in screen coordinates.
1238 //
1239 BOOL PASCAL GetIconRect( HWND hWnd, LPRECT lprc )
1240 {
1241 UINT nCapSize ;
1242 BOOL fMenu, fVert ;
1243
1244 fMenu= TestWinStyle( hWnd, WS_SYSMENU ) ;
1245 fVert = TestWinStyle( hWnd, IBS_VERTCAPTION ) ;
1246
1247 if (!GetCaptionRect( hWnd, lprc )) // window coords
1248 return FALSE ;
1249
1250 if (!fMenu)
1251 {
1252 SetRectEmpty( lprc ) ;
1253 return FALSE ;
1254 }
1255
1256 nCapSize = GETCAPTIONSIZE( hWnd ) ;
1257
1258 if (fVert)
1259 lprc->bottom = lprc->top + nCapSize ;
1260 else
1261 lprc->right = lprc->left + nCapSize ;
1262
1263 lprc->bottom-- ;
1264 lprc->right-- ;
1265
1266 return TRUE ;
1267
1268 } // GetIconRect()
1269
1270 // GetMinButtonRect()
1271 //
1272 // Calculates the rect of the minimize button in screen
1273 // coordinates.
1274 //
1275 // For horizontal captions, we have the following situation ('Y' is minimize
1276 // and '^' is maximize or restore):
1277 //
1278 // +---------------------------------+
1279 // | - | | Y | ^ |
1280 // +---------------------------------+
1281 // | |.......| <-- This is the width (nSize)
1282 //
1283 // For vertical captions, we have the following:
1284 //
1285 // | |
1286 // | |
1287 // | |
1288 // | |
1289 // | |
1290 // | |
1291 // |--|--
1292 // | Y| .
1293 // |--| . <-- This is the height of the rectangle (nSize)
1294 // | ^| .
1295 // +--+--
1296 //
1297 // In order to figure out where the minimize button goes, we first need
1298 // to know if there is a maximize button. If so, use GetMaxButtonRect()
1299 // to place...
1300 //
1301 BOOL PASCAL GetMinButtonRect( HWND hWnd, LPRECT lprc )
1302 {
1303 if (!TestWinStyle( hWnd, WS_MINIMIZEBOX ))
1304 {
1305 SetRectEmpty( lprc ) ;
1306 return FALSE ;
1307 }
1308
1309 // The minimize button can be in either position 1 or 2. If there
1310 // is a maximize button, it's in position 2.
1311 //
1312 if (TestWinStyle( hWnd, WS_MAXIMIZEBOX ))
1313 return GetButtonRect( hWnd, 2, lprc ) ;
1314 else
1315 return GetButtonRect( hWnd, 1, lprc ) ;
1316 }
1317
1318 // GetMaxButtonRect()
1319 //
1320 // Calculates the rect of the maximize button in screen
1321 // coordinates.
1322 //
1323 // The maximize button, if present, is always to the far right
1324 // or bottom.
1325 //
1326 BOOL PASCAL GetMaxButtonRect( HWND hWnd, LPRECT lprc )
1327 {
1328 //The maximize button can only be in position 1.
1329 //
1330 if (TestWinStyle( hWnd, WS_MAXIMIZEBOX ))
1331 return GetButtonRect( hWnd, 1, lprc ) ;
1332 else
1333 {
1334 SetRectEmpty( lprc ) ;
1335 return FALSE ;
1336 }
1337 }
1338
1339 // Get the rect where a button would go.
1340 //
1341 // This function does not care if it's a min or max, just whether
1342 // it is the first from the right/bottom or second from the right/bottom
1343 // and so on..
1344 //
1345 BOOL PASCAL GetButtonRect( HWND hWnd, UINT nPos, LPRECT lprc )
1346 {
1347 UINT nSize = 0 ;
1348
1349 if (!GetCaptionRect( hWnd, lprc )) //window coords
1350 return FALSE ;
1351
1352 nSize = GETCAPTIONSIZE( hWnd ) ;
1353
1354 if (TestWinStyle( hWnd, IBS_VERTCAPTION ))
1355 {
1356 lprc->bottom -= nSize * (nPos-1) ;
1357 lprc->top = lprc->bottom - nSize + 1 ;
1358 }
1359 else
1360 {
1361 lprc->right -= nSize * (nPos-1) ;
1362 lprc->left = lprc->right - nSize + 1 ;
1363 }
1364
1365 return TRUE ;
1366 } // GetButtonRect()
1367
1368 // DrawButton( HDC hDC, HWND hWnd, BOOL fMin, BOOL fDepressed )
1369 //
1370 // Draws either the min, max, or restore buttons. If fMin is FALSE then it
1371 // will draw either the Max or Restore button. If fDepressed is TRUE it will
1372 // draw the button in a down state.
1373 //
1374 void PASCAL DrawButton( HDC hDC, HWND hWnd, BOOL fMin, BOOL fDepressed)
1375 {
1376 RECT rcButton ;
1377 RECT rc ;
1378 COLORREF rgbWindowFrame ;
1379 BOOL fDC ;
1380 UINT nCapSize ;
1381 UINT nOffset ;
1382 int n ;
1383
1384 nCapSize = GETCAPTIONSIZE( hWnd ) ;
1385
1386 // If you look at the standard Windows' min/max buttons, you will notice
1387 // that they have two pixels of 'shadow' to the bottom and right. Since
1388 // our buttons can be really, really small, we only want one pixel of
1389 // shadow when they are small. I arbitrarily decided that if the
1390 // caption size is greater than or equal to 20 we will use two
1391 // pixels. That's what this THREASHOLD stuff does.
1392 //
1393 #define THRESHOLD 20
1394 nOffset = (nCapSize >= THRESHOLD) ? 2 : 1 ;
1395
1396 if (!hDC)
1397 {
1398 fDC = TRUE ;
1399 hDC = GetWindowDC( hWnd ) ;
1400 }
1401 else
1402 fDC = FALSE ;
1403
1404 if (hDC)
1405 {
1406 rgbWindowFrame = GetSysColor( COLOR_WINDOWFRAME ) ;
1407
1408 if (fMin)
1409 GetMinButtonRect( hWnd, &rcButton ) ;
1410 else
1411 GetMaxButtonRect( hWnd, &rcButton ) ;
1412
1413 GetWindowRect( hWnd, &rc ) ;
1414 OffsetRect( &rcButton, -rc.left, -rc.top ) ;
1415
1416 rc = rcButton ;
1417 if (TestWinStyle( hWnd, IBS_VERTCAPTION ))
1418 {
1419 rc = rcButton ; //separator line
1420 rc.bottom = --rc.top + 1 ;
1421 rcButton.right-- ;
1422 }
1423 else
1424 {
1425 rc = rcButton ; //separator line
1426 rc.right = --rc.left + 1 ;
1427 rcButton.bottom-- ;
1428 }
1429
1430 //Draw separator line
1431 SetBkColor( hDC, rgbWindowFrame ) ;
1432 DRAWFASTRECT( hDC, &rc ) ;
1433
1434 //Fill
1435 SetBkColor( hDC, RGBLTGRAY ) ;
1436 DRAWFASTRECT( hDC, &rcButton ) ;
1437
1438 if (!fDepressed)
1439 {
1440 //The normal min/max buttons have one pixel on the top and left
1441 //sides for the highlight, and two pixels on the bottom and
1442 //right side for the shadow.
1443 //
1444 //When our caption is 'small' we only use one pixel on all
1445 //sides.
1446 //
1447 SetBkColor( hDC, RGBWHITE ) ;
1448 //Draw left side
1449 rc = rcButton ;
1450 rc.right = rc.left + 1 ;
1451 DRAWFASTRECT( hDC, &rc ) ;
1452
1453 //Draw Top
1454 rc = rcButton ;
1455 rc.bottom = rc.top + 1 ;
1456 DRAWFASTRECT( hDC, &rc ) ;
1457
1458 SetBkColor( hDC, RGBGRAY ) ;
1459 //Draw right side
1460 rc = rcButton ;
1461 rc.left = rc.right - 1 ;
1462 DRAWFASTRECT( hDC, &rc ) ;
1463 if (nCapSize > THRESHOLD)
1464 {
1465 rc.left-- ;
1466 rc.top++ ;
1467 DRAWFASTRECT( hDC, &rc ) ;
1468 }
1469
1470 //Draw bottom
1471 rc = rcButton ;
1472 rc.top = rc.bottom - 1 ;
1473 DRAWFASTRECT( hDC, &rc ) ;
1474 if (nCapSize > THRESHOLD)
1475 {
1476 rc.top-- ;
1477 rc.left++ ;
1478 DRAWFASTRECT( hDC, &rc ) ;
1479 }
1480
1481 rcButton.left++ ;
1482 rcButton.top++ ;
1483 rcButton.right -= nOffset ;
1484 rcButton.bottom -= nOffset ;
1485 }
1486 else
1487 {
1488 //Draw depressed state
1489
1490 SetBkColor( hDC, RGBGRAY ) ;
1491 //Draw left side
1492 rc = rcButton ;
1493 rc.right = rc.left + nOffset ;
1494 DRAWFASTRECT( hDC, &rc ) ;
1495
1496 //Draw Top
1497 rc = rcButton ;
1498 rc.bottom = rc.top + nOffset ;
1499 DRAWFASTRECT( hDC, &rc ) ;
1500
1501 rcButton.left += 2 * nOffset ;
1502 rcButton.top += 2 * nOffset ;
1503 }
1504
1505 // Now draw the arrows. We do not want the
1506 // arrows to grow too large when we have a bigger than
1507 // normal caption, so we restrict their size.
1508 //
1509 // rcButton now represents where we can place our
1510 // arrows.
1511 //
1512 // The maximum size of our arrows (i.e. the width of rcButton)
1513 // has been empirically determined to be SM_CYCAPTION / 2
1514 //
1515 n = ((GetSystemMetrics( SM_CYCAPTION )) / 2) -
1516 (rcButton.right - rcButton.left) ;
1517 if (n < 1)
1518 InflateRect( &rcButton, n/2-1, n/2-1 ) ;
1519
1520 if (fMin)
1521 DrawArrow( hDC, &rcButton, ARROW_DOWN ) ;
1522 else
1523 if (IsZoomed( hWnd ))
1524 {
1525 DrawArrow( hDC, &rcButton, ARROW_RESTORE ) ;
1526 }
1527 else
1528 DrawArrow( hDC, &rcButton, ARROW_UP ) ;
1529
1530 if (fDC)
1531 ReleaseDC( hWnd, hDC ) ;
1532 }
1533
1534 } // DrawButton()
1535
1536
1537 // DrawArrow
1538 //
1539 // Draws either a up or down arrow. The arrow is bound by the rectangle
1540 //
1541 void PASCAL DrawArrow( HDC hdc, LPRECT lprc, UINT uiStyle )
1542 {
1543 int row ;
1544 int xTip ;
1545 int yTip ;
1546 RECT rc ;
1547 int nMax = (lprc->bottom - lprc->top) >> 1 ;
1548
1549 SetBkColor( hdc, RGBBLACK ) ;
1550
1551 // We draw the arrow by drawing a series of horizontal lines
1552 //
1553 xTip = lprc->left + ((lprc->right - lprc->left+1) >> 1) ;
1554 switch (uiStyle)
1555 {
1556 case ARROW_UP:
1557 yTip = lprc->top + ((lprc->bottom - lprc->top-1) >> 2) ;
1558 for (row = 1 ; row <= nMax ; row++ )
1559 {
1560 rc.left = xTip - row ;
1561 rc.right = xTip + row - 1 ;
1562 rc.top = yTip + row ;
1563 rc.bottom = rc.top + 1 ;
1564 DRAWFASTRECT( hdc, &rc ) ;
1565 }
1566 break ;
1567
1568 case ARROW_DOWN:
1569 yTip = lprc->bottom - ((lprc->bottom - lprc->top-1) >> 2) ;
1570 for ( row = nMax ; row > 0 ; row-- )
1571 {
1572 rc.left = xTip - row ;
1573 rc.right = xTip + row - 1 ;
1574 rc.top = yTip - row ;
1575 rc.bottom = rc.top + 1 ;
1576 DRAWFASTRECT( hdc, &rc ) ;
1577 }
1578 break ;
1579
1580 case ARROW_RESTORE:
1581 default:
1582 yTip = lprc->top + ((lprc->bottom - lprc->top-1) >> 3) - 2;
1583 for (row = 1 ; row <= nMax ; row++ )
1584 {
1585 rc.left = xTip - row ;
1586 rc.right = xTip + row - 1 ;
1587 rc.top = yTip + row ;
1588 rc.bottom = rc.top + 1 ;
1589 DRAWFASTRECT( hdc, &rc ) ;
1590 }
1591
1592 yTip += (nMax+1) * 2 ;
1593 for ( row = nMax ; row > 0 ; row-- )
1594 {
1595 rc.left = xTip - row ;
1596 rc.right = xTip + row - 1 ;
1597 rc.top = yTip - row ;
1598 rc.bottom = rc.top + 1 ;
1599 DRAWFASTRECT( hdc, &rc ) ;
1600 }
1601 break ;
1602 }
1603
1604 } // DrawArrow()
1605
1606 #endif // wxUSE_ITSY_BITSY