2 * Interface code to StatusWindow widget/control
4 * Copyright 1996 Bruce Milner
5 * Copyright 1998, 1999 Eric Kohl
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Sep. 24, 2002, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
32 * -- CCS_BOTTOM (default)
37 * -- CCS_NOPARENTALIGN
40 * -- CCS_VERT (defaults to RIGHT)
45 WINE_DEFAULT_DEBUG_CHANNEL(statusbar
);
62 UINT minHeight
; /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
67 COLORREF clrBk
; /* background color */
68 BOOL bUnicode
; /* notify format. TRUE if notifies in Unicode */
69 STATUSWINDOWPART part0
; /* simple window */
70 STATUSWINDOWPART
* parts
;
77 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
78 * The second cdrom contains executables drawstat.exe, gettext.exe,
79 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
86 static const WCHAR themeClass
[] = { 'S','t','a','t','u','s',0 };
90 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
);
92 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
);
94 static inline LPCSTR
debugstr_t(LPCWSTR text
, BOOL isW
)
96 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
100 STATUSBAR_ComputeHeight(STATUS_INFO
*infoPtr
)
107 COMCTL32_GetFontMetrics(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
, &tm
);
108 margin
= (tm
.tmInternalLeading
? tm
.tmInternalLeading
: 2);
109 height
= max(tm
.tmHeight
+ margin
+ 2*GetSystemMetrics(SM_CYBORDER
), infoPtr
->minHeight
) + infoPtr
->verticalBorder
;
111 if ((theme
= GetWindowTheme(infoPtr
->Self
)))
113 /* Determine bar height from theme such that the content area is
114 * textHeight pixels large */
115 HDC hdc
= GetDC(infoPtr
->Self
);
118 SetRect(&r
, 0, 0, 0, max(infoPtr
->minHeight
, tm
.tmHeight
));
119 if (SUCCEEDED(GetThemeBackgroundExtent(theme
, hdc
, SP_PANE
, 0, &r
, &r
)))
121 height
= r
.bottom
- r
.top
;
123 ReleaseDC(infoPtr
->Self
, hdc
);
126 TRACE(" textHeight=%d+%d, final height=%d\n", tm
.tmHeight
, tm
.tmInternalLeading
, height
);
131 STATUSBAR_DrawSizeGrip (HTHEME theme
, HDC hdc
, LPRECT lpRect
)
135 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect
));
140 if (SUCCEEDED (GetThemePartSize (theme
, hdc
, SP_GRIPPER
, 0, lpRect
,
141 TS_DRAW
, &gripperSize
)))
143 rc
.left
= rc
.right
- gripperSize
.cx
;
144 rc
.top
= rc
.bottom
- gripperSize
.cy
;
145 if (SUCCEEDED (DrawThemeBackground(theme
, hdc
, SP_GRIPPER
, 0, &rc
, NULL
)))
150 rc
.left
= max( rc
.left
, rc
.right
- GetSystemMetrics(SM_CXVSCROLL
) - 1 );
151 rc
.top
= max( rc
.top
, rc
.bottom
- GetSystemMetrics(SM_CYHSCROLL
) - 1 );
152 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
157 STATUSBAR_DrawPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
159 RECT r
= part
->bound
;
160 UINT border
= BDR_SUNKENOUTER
;
161 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
162 int themePart
= SP_PANE
;
165 TRACE("part bound %s\n", wine_dbgstr_rect(&r
));
166 if (part
->style
& SBT_POPOUT
)
167 border
= BDR_RAISEDOUTER
;
168 else if (part
->style
& SBT_NOBORDERS
)
173 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
174 && (infoPtr
->simple
|| (itemID
== (infoPtr
->numParts
-1))))
175 themePart
= SP_GRIPPERPANE
;
176 DrawThemeBackground(theme
, hdc
, themePart
, 0, &r
, NULL
);
179 DrawEdge(hdc
, &r
, border
, BF_RECT
|BF_ADJUST
);
182 INT cy
= r
.bottom
- r
.top
;
183 DrawIconEx (hdc
, r
.left
+ 2, r
.top
, part
->hIcon
, cy
, cy
, 0, 0, DI_NORMAL
);
187 if (part
->style
& SBT_OWNERDRAW
) {
190 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
192 dis
.hwndItem
= infoPtr
->Self
;
195 dis
.itemData
= (ULONG_PTR
)part
->text
;
196 SendMessageW (infoPtr
->Notify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
199 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
205 STATUSBAR_RefreshPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
210 TRACE("item %d\n", itemID
);
212 if (part
->bound
.right
< part
->bound
.left
) return;
214 if (!RectVisible(hdc
, &part
->bound
))
217 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
220 GetClientRect (infoPtr
->Self
, &cr
);
221 DrawThemeBackground(theme
, hdc
, 0, 0, &cr
, &part
->bound
);
225 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
226 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
228 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
229 FillRect(hdc
, &part
->bound
, hbrBk
);
230 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
231 DeleteObject (hbrBk
);
234 STATUSBAR_DrawPart (infoPtr
, hdc
, part
, itemID
);
239 STATUSBAR_Refresh (STATUS_INFO
*infoPtr
, HDC hdc
)
247 if (!IsWindowVisible(infoPtr
->Self
))
250 STATUSBAR_SetPartBounds(infoPtr
);
252 GetClientRect (infoPtr
->Self
, &rect
);
254 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
256 DrawThemeBackground(theme
, hdc
, 0, 0, &rect
, NULL
);
260 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
261 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
263 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
264 FillRect(hdc
, &rect
, hbrBk
);
265 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
266 DeleteObject (hbrBk
);
269 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
271 if (infoPtr
->simple
) {
272 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->part0
, 0);
276 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
277 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->parts
[i
], i
);
281 SelectObject (hdc
, hOldFont
);
283 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
284 STATUSBAR_DrawSizeGrip (theme
, hdc
, &rect
);
291 STATUSBAR_InternalHitTest(const STATUS_INFO
*infoPtr
, const POINT
*pt
)
298 for (i
= 0; i
< infoPtr
->numParts
; i
++)
299 if (pt
->x
>= infoPtr
->parts
[i
].bound
.left
&& pt
->x
<= infoPtr
->parts
[i
].bound
.right
)
306 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
)
308 STATUSWINDOWPART
*part
;
312 /* get our window size */
313 GetClientRect (infoPtr
->Self
, &rect
);
314 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect
));
316 rect
.left
+= infoPtr
->horizontalBorder
;
317 rect
.top
+= infoPtr
->verticalBorder
;
319 /* set bounds for simple rectangle */
320 infoPtr
->part0
.bound
= rect
;
322 /* set bounds for non-simple rectangles */
323 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
324 part
= &infoPtr
->parts
[i
];
325 r
= &infoPtr
->parts
[i
].bound
;
327 r
->bottom
= rect
.bottom
;
331 r
->left
= infoPtr
->parts
[i
-1].bound
.right
+ infoPtr
->horizontalGap
;
333 r
->right
= rect
.right
;
337 if (infoPtr
->hwndToolTip
) {
340 ti
.cbSize
= sizeof(TTTOOLINFOW
);
341 ti
.hwnd
= infoPtr
->Self
;
344 SendMessageW (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
,
352 STATUSBAR_Relay2Tip (const STATUS_INFO
*infoPtr
, UINT uMsg
,
353 WPARAM wParam
, LPARAM lParam
)
357 msg
.hwnd
= infoPtr
->Self
;
361 msg
.time
= GetMessageTime ();
362 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
363 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
365 return SendMessageW (infoPtr
->hwndToolTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
370 STATUSBAR_GetBorders (const STATUS_INFO
*infoPtr
, INT out
[])
373 out
[0] = infoPtr
->horizontalBorder
;
374 out
[1] = infoPtr
->verticalBorder
;
375 out
[2] = infoPtr
->horizontalGap
;
382 STATUSBAR_SetBorders (STATUS_INFO
*infoPtr
, const INT in
[])
385 infoPtr
->horizontalBorder
= in
[0];
386 infoPtr
->verticalBorder
= in
[1];
387 infoPtr
->horizontalGap
= in
[2];
388 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
395 STATUSBAR_GetIcon (const STATUS_INFO
*infoPtr
, INT nPart
)
397 TRACE("%d\n", nPart
);
398 /* MSDN says: "simple parts are indexed with -1" */
399 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
403 return (infoPtr
->part0
.hIcon
);
405 return (infoPtr
->parts
[nPart
].hIcon
);
410 STATUSBAR_GetParts (const STATUS_INFO
*infoPtr
, INT num_parts
, INT parts
[])
414 TRACE("(%d)\n", num_parts
);
416 for (i
= 0; i
< num_parts
; i
++) {
417 parts
[i
] = infoPtr
->parts
[i
].x
;
420 return infoPtr
->numParts
;
425 STATUSBAR_GetRect (const STATUS_INFO
*infoPtr
, INT nPart
, LPRECT rect
)
427 TRACE("part %d\n", nPart
);
428 if(nPart
>= infoPtr
->numParts
|| nPart
< 0)
431 *rect
= infoPtr
->part0
.bound
;
433 *rect
= infoPtr
->parts
[nPart
].bound
;
439 STATUSBAR_GetTextA (STATUS_INFO
*infoPtr
, INT nPart
, LPSTR buf
)
441 STATUSWINDOWPART
*part
;
444 TRACE("part %d\n", nPart
);
446 /* MSDN says: "simple parts use index of 0", so this check is ok. */
447 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
450 part
= &infoPtr
->part0
;
452 part
= &infoPtr
->parts
[nPart
];
454 if (part
->style
& SBT_OWNERDRAW
)
455 result
= (LRESULT
)part
->text
;
457 DWORD len
= part
->text
? WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1,
458 NULL
, 0, NULL
, NULL
) - 1 : 0;
459 result
= MAKELONG( len
, part
->style
);
460 if (part
->text
&& buf
)
461 WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1, buf
, len
+1, NULL
, NULL
);
468 STATUSBAR_GetTextW (STATUS_INFO
*infoPtr
, INT nPart
, LPWSTR buf
)
470 STATUSWINDOWPART
*part
;
473 TRACE("part %d\n", nPart
);
474 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
477 part
= &infoPtr
->part0
;
479 part
= &infoPtr
->parts
[nPart
];
481 if (part
->style
& SBT_OWNERDRAW
)
482 result
= (LRESULT
)part
->text
;
484 result
= part
->text
? strlenW (part
->text
) : 0;
485 result
|= (part
->style
<< 16);
486 if (part
->text
&& buf
)
487 strcpyW (buf
, part
->text
);
494 STATUSBAR_GetTextLength (STATUS_INFO
*infoPtr
, INT nPart
)
496 STATUSWINDOWPART
*part
;
499 TRACE("part %d\n", nPart
);
501 /* MSDN says: "simple parts use index of 0", so this check is ok. */
502 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
505 part
= &infoPtr
->part0
;
507 part
= &infoPtr
->parts
[nPart
];
509 if ((~part
->style
& SBT_OWNERDRAW
) && part
->text
)
510 result
= strlenW(part
->text
);
514 result
|= (part
->style
<< 16);
519 STATUSBAR_GetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR tip
, INT size
)
523 CHAR buf
[INFOTIPSIZE
];
526 if (infoPtr
->hwndToolTip
) {
528 ti
.cbSize
= sizeof(TTTOOLINFOA
);
529 ti
.hwnd
= infoPtr
->Self
;
532 SendMessageA (infoPtr
->hwndToolTip
, TTM_GETTEXTA
, 0, (LPARAM
)&ti
);
534 lstrcpynA (tip
, buf
, size
);
541 STATUSBAR_GetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR tip
, INT size
)
545 WCHAR buf
[INFOTIPSIZE
];
548 if (infoPtr
->hwndToolTip
) {
550 ti
.cbSize
= sizeof(TTTOOLINFOW
);
551 ti
.hwnd
= infoPtr
->Self
;
554 SendMessageW(infoPtr
->hwndToolTip
, TTM_GETTEXTW
, 0, (LPARAM
)&ti
);
556 lstrcpynW(tip
, buf
, size
);
564 STATUSBAR_SetBkColor (STATUS_INFO
*infoPtr
, COLORREF color
)
568 oldBkColor
= infoPtr
->clrBk
;
569 infoPtr
->clrBk
= color
;
570 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
572 TRACE("CREF: %08x -> %08x\n", oldBkColor
, infoPtr
->clrBk
);
578 STATUSBAR_SetIcon (STATUS_INFO
*infoPtr
, INT nPart
, HICON hIcon
)
580 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
583 TRACE("setting part %d\n", nPart
);
585 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
587 if (infoPtr
->part0
.hIcon
== hIcon
) /* same as - no redraw */
589 infoPtr
->part0
.hIcon
= hIcon
;
591 InvalidateRect(infoPtr
->Self
, &infoPtr
->part0
.bound
, FALSE
);
593 if (infoPtr
->parts
[nPart
].hIcon
== hIcon
) /* same as - no redraw */
596 infoPtr
->parts
[nPart
].hIcon
= hIcon
;
597 if (!(infoPtr
->simple
))
598 InvalidateRect(infoPtr
->Self
, &infoPtr
->parts
[nPart
].bound
, FALSE
);
605 STATUSBAR_SetMinHeight (STATUS_INFO
*infoPtr
, INT height
)
607 DWORD ysize
= GetSystemMetrics(SM_CYSIZE
);
608 if (ysize
& 1) ysize
--;
609 infoPtr
->minHeight
= max(height
, ysize
);
610 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
611 /* like native, don't resize the control */
617 STATUSBAR_SetParts (STATUS_INFO
*infoPtr
, INT count
, LPINT parts
)
619 STATUSWINDOWPART
*tmp
;
622 TRACE("(%d,%p)\n", count
, parts
);
624 if(!count
) return FALSE
;
626 oldNumParts
= infoPtr
->numParts
;
627 infoPtr
->numParts
= count
;
628 if (oldNumParts
> infoPtr
->numParts
) {
629 for (i
= infoPtr
->numParts
; i
< oldNumParts
; i
++) {
630 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
631 Free (infoPtr
->parts
[i
].text
);
633 } else if (oldNumParts
< infoPtr
->numParts
) {
634 tmp
= Alloc (sizeof(STATUSWINDOWPART
) * infoPtr
->numParts
);
635 if (!tmp
) return FALSE
;
636 for (i
= 0; i
< oldNumParts
; i
++) {
637 tmp
[i
] = infoPtr
->parts
[i
];
639 Free (infoPtr
->parts
);
640 infoPtr
->parts
= tmp
;
642 if (oldNumParts
== infoPtr
->numParts
) {
643 for (i
=0; i
< oldNumParts
; i
++)
644 if (infoPtr
->parts
[i
].x
!= parts
[i
])
646 if (i
==oldNumParts
) /* Unchanged? no need to redraw! */
650 for (i
= 0; i
< infoPtr
->numParts
; i
++)
651 infoPtr
->parts
[i
].x
= parts
[i
];
653 if (infoPtr
->hwndToolTip
) {
658 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
659 ti
.cbSize
= sizeof(TTTOOLINFOW
);
660 ti
.hwnd
= infoPtr
->Self
;
661 ti
.lpszText
= &wEmpty
;
663 nTipCount
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETTOOLCOUNT
, 0, 0);
664 if (nTipCount
< infoPtr
->numParts
) {
666 for (i
= nTipCount
; i
< infoPtr
->numParts
; i
++) {
667 TRACE("add tool %d\n", i
);
669 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
673 else if (nTipCount
> infoPtr
->numParts
) {
675 for (i
= nTipCount
- 1; i
>= infoPtr
->numParts
; i
--) {
676 TRACE("delete tool %d\n", i
);
678 SendMessageW (infoPtr
->hwndToolTip
, TTM_DELTOOLW
,
683 STATUSBAR_SetPartBounds (infoPtr
);
684 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
690 STATUSBAR_SetTextT (STATUS_INFO
*infoPtr
, INT nPart
, WORD style
,
691 LPWSTR text
, BOOL isW
)
693 STATUSWINDOWPART
*part
=NULL
;
694 BOOL changed
= FALSE
;
697 if (style
& SBT_OWNERDRAW
) {
698 TRACE("part %d, text %p\n",nPart
,text
);
700 else TRACE("part %d, text %s\n", nPart
, debugstr_t(text
, isW
));
702 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
703 * window is assumed to be a simple window */
705 if (nPart
== 0x00ff) {
706 part
= &infoPtr
->part0
;
708 if (infoPtr
->parts
&& nPart
>= 0 && nPart
< infoPtr
->numParts
) {
709 part
= &infoPtr
->parts
[nPart
];
712 if (!part
) return FALSE
;
714 if (part
->style
!= style
)
717 oldStyle
= part
->style
;
719 if (style
& SBT_OWNERDRAW
) {
720 if (!(oldStyle
& SBT_OWNERDRAW
))
728 LPCSTR atxt
= (LPCSTR
)text
;
729 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, NULL
, 0 );
730 ntext
= Alloc( (len
+ 1)*sizeof(WCHAR
) );
731 if (!ntext
) return FALSE
;
732 MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, ntext
, len
);
734 ntext
= Alloc( (strlenW(text
) + 1)*sizeof(WCHAR
) );
735 if (!ntext
) return FALSE
;
736 strcpyW (ntext
, text
);
739 /* replace nonprintable characters with spaces */
749 /* check if text is unchanged -> no need to redraw */
751 if (!changed
&& part
->text
&& !lstrcmpW(ntext
, part
->text
)) {
756 if (!changed
&& !part
->text
)
760 if (!(oldStyle
& SBT_OWNERDRAW
))
764 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
765 UpdateWindow(infoPtr
->Self
);
772 STATUSBAR_SetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR text
)
774 TRACE("part %d: \"%s\"\n", id
, text
);
775 if (infoPtr
->hwndToolTip
) {
777 ti
.cbSize
= sizeof(TTTOOLINFOA
);
778 ti
.hwnd
= infoPtr
->Self
;
782 SendMessageA (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTA
, 0, (LPARAM
)&ti
);
790 STATUSBAR_SetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR text
)
792 TRACE("part %d: \"%s\"\n", id
, debugstr_w(text
));
793 if (infoPtr
->hwndToolTip
) {
795 ti
.cbSize
= sizeof(TTTOOLINFOW
);
796 ti
.hwnd
= infoPtr
->Self
;
800 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
807 static inline LRESULT
808 STATUSBAR_SetUnicodeFormat (STATUS_INFO
*infoPtr
, BOOL bUnicode
)
810 BOOL bOld
= infoPtr
->bUnicode
;
812 TRACE("(0x%x)\n", bUnicode
);
813 infoPtr
->bUnicode
= bUnicode
;
820 STATUSBAR_Simple (STATUS_INFO
*infoPtr
, BOOL simple
)
824 TRACE("(simple=%d)\n", simple
);
825 if (infoPtr
->simple
== simple
) /* no need to change */
828 infoPtr
->simple
= simple
;
830 /* send notification */
831 nmhdr
.hwndFrom
= infoPtr
->Self
;
832 nmhdr
.idFrom
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
833 nmhdr
.code
= SBN_SIMPLEMODECHANGE
;
834 SendMessageW (infoPtr
->Notify
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
835 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
841 STATUSBAR_WMDestroy (STATUS_INFO
*infoPtr
)
846 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
847 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
848 Free (infoPtr
->parts
[i
].text
);
850 if (!(infoPtr
->part0
.style
& SBT_OWNERDRAW
))
851 Free (infoPtr
->part0
.text
);
852 Free (infoPtr
->parts
);
854 /* delete default font */
855 if (infoPtr
->hDefaultFont
)
856 DeleteObject (infoPtr
->hDefaultFont
);
858 /* delete tool tip control */
859 if (infoPtr
->hwndToolTip
)
860 DestroyWindow (infoPtr
->hwndToolTip
);
862 CloseThemeData (GetWindowTheme (infoPtr
->Self
));
864 SetWindowLongPtrW(infoPtr
->Self
, 0, 0);
871 STATUSBAR_WMCreate (HWND hwnd
, const CREATESTRUCTA
*lpCreate
)
873 STATUS_INFO
*infoPtr
;
874 NONCLIENTMETRICSW nclm
;
880 infoPtr
= Alloc (sizeof(STATUS_INFO
));
881 if (!infoPtr
) goto create_fail
;
882 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
884 infoPtr
->Self
= hwnd
;
885 infoPtr
->Notify
= lpCreate
->hwndParent
;
886 infoPtr
->numParts
= 1;
888 infoPtr
->simple
= FALSE
;
889 infoPtr
->clrBk
= CLR_DEFAULT
;
891 infoPtr
->horizontalBorder
= HORZ_BORDER
;
892 infoPtr
->verticalBorder
= VERT_BORDER
;
893 infoPtr
->horizontalGap
= HORZ_GAP
;
894 infoPtr
->minHeight
= GetSystemMetrics(SM_CYSIZE
);
895 if (infoPtr
->minHeight
& 1) infoPtr
->minHeight
--;
897 STATUSBAR_NotifyFormat(infoPtr
, infoPtr
->Notify
, NF_REQUERY
);
899 ZeroMemory (&nclm
, sizeof(nclm
));
900 nclm
.cbSize
= sizeof(nclm
);
901 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0);
902 infoPtr
->hDefaultFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
904 GetClientRect (hwnd
, &rect
);
906 /* initialize simple case */
907 infoPtr
->part0
.bound
= rect
;
908 infoPtr
->part0
.text
= 0;
909 infoPtr
->part0
.x
= 0;
910 infoPtr
->part0
.style
= 0;
911 infoPtr
->part0
.hIcon
= 0;
913 /* initialize first part */
914 infoPtr
->parts
= Alloc (sizeof(STATUSWINDOWPART
));
915 if (!infoPtr
->parts
) goto create_fail
;
916 infoPtr
->parts
[0].bound
= rect
;
917 infoPtr
->parts
[0].text
= 0;
918 infoPtr
->parts
[0].x
= -1;
919 infoPtr
->parts
[0].style
= 0;
920 infoPtr
->parts
[0].hIcon
= 0;
922 OpenThemeData (hwnd
, themeClass
);
924 if (lpCreate
->lpszName
&& (len
= strlenW ((LPCWSTR
)lpCreate
->lpszName
)))
926 infoPtr
->parts
[0].text
= Alloc ((len
+ 1)*sizeof(WCHAR
));
927 if (!infoPtr
->parts
[0].text
) goto create_fail
;
928 strcpyW (infoPtr
->parts
[0].text
, (LPCWSTR
)lpCreate
->lpszName
);
931 dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
932 /* native seems to clear WS_BORDER, too */
933 dwStyle
&= ~WS_BORDER
;
934 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
936 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
938 if (dwStyle
& SBT_TOOLTIPS
) {
939 infoPtr
->hwndToolTip
=
940 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
| TTS_ALWAYSTIP
,
941 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
942 CW_USEDEFAULT
, hwnd
, 0,
943 (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
), NULL
);
945 if (infoPtr
->hwndToolTip
) {
946 NMTOOLTIPSCREATED nmttc
;
948 nmttc
.hdr
.hwndFrom
= hwnd
;
949 nmttc
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
950 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
951 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
953 SendMessageW (lpCreate
->hwndParent
, WM_NOTIFY
, nmttc
.hdr
.idFrom
, (LPARAM
)&nmttc
);
961 if (infoPtr
) STATUSBAR_WMDestroy(infoPtr
);
966 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
967 * of the first part only (usual behaviour) */
969 STATUSBAR_WMGetText (const STATUS_INFO
*infoPtr
, INT size
, LPWSTR buf
)
974 if (!(infoPtr
->parts
[0].text
))
977 len
= strlenW (infoPtr
->parts
[0].text
);
981 else if (size
> len
) {
982 strcpyW (buf
, infoPtr
->parts
[0].text
);
986 memcpy (buf
, infoPtr
->parts
[0].text
, (size
- 1) * sizeof(WCHAR
));
994 STATUSBAR_WMNCHitTest (const STATUS_INFO
*infoPtr
, INT x
, INT y
)
996 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
) {
1000 GetClientRect (infoPtr
->Self
, &rect
);
1004 ScreenToClient (infoPtr
->Self
, &pt
);
1006 rect
.left
= rect
.right
- 13;
1009 if (PtInRect (&rect
, pt
))
1011 if (GetWindowLongW( infoPtr
->Self
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) return HTBOTTOMLEFT
;
1012 else return HTBOTTOMRIGHT
;
1021 STATUSBAR_WMPaint (STATUS_INFO
*infoPtr
, HDC hdc
)
1026 if (hdc
) return STATUSBAR_Refresh (infoPtr
, hdc
);
1027 hdc
= BeginPaint (infoPtr
->Self
, &ps
);
1028 STATUSBAR_Refresh (infoPtr
, hdc
);
1029 EndPaint (infoPtr
->Self
, &ps
);
1036 STATUSBAR_WMSetFont (STATUS_INFO
*infoPtr
, HFONT font
, BOOL redraw
)
1038 infoPtr
->hFont
= font
;
1039 TRACE("%p\n", infoPtr
->hFont
);
1041 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
1042 SendMessageW(infoPtr
->Self
, WM_SIZE
, 0, 0); /* update size */
1044 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
1051 STATUSBAR_WMSetText (const STATUS_INFO
*infoPtr
, LPCSTR text
)
1053 STATUSWINDOWPART
*part
;
1057 if (infoPtr
->numParts
== 0)
1060 part
= &infoPtr
->parts
[0];
1061 /* duplicate string */
1065 if (text
&& (len
= strlenW((LPCWSTR
)text
))) {
1066 part
->text
= Alloc ((len
+1)*sizeof(WCHAR
));
1067 if (!part
->text
) return FALSE
;
1068 strcpyW (part
->text
, (LPCWSTR
)text
);
1071 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
1078 STATUSBAR_WMSize (STATUS_INFO
*infoPtr
, WORD flags
)
1083 /* Need to resize width to match parent */
1084 TRACE("flags %04x\n", flags
);
1086 if (flags
!= SIZE_RESTORED
&& flags
!= SIZE_MAXIMIZED
) {
1087 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1091 if (GetWindowLongW(infoPtr
->Self
, GWL_STYLE
) & CCS_NORESIZE
) return FALSE
;
1093 /* width and height don't apply */
1094 if (!GetClientRect (infoPtr
->Notify
, &parent_rect
))
1097 width
= parent_rect
.right
- parent_rect
.left
;
1098 x
= parent_rect
.left
;
1099 y
= parent_rect
.bottom
- infoPtr
->height
;
1100 MoveWindow (infoPtr
->Self
, x
, y
, width
, infoPtr
->height
, TRUE
);
1101 STATUSBAR_SetPartBounds (infoPtr
);
1106 /* update theme after a WM_THEMECHANGED message */
1107 static LRESULT
theme_changed (const STATUS_INFO
* infoPtr
)
1109 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
1110 CloseThemeData (theme
);
1111 OpenThemeData (infoPtr
->Self
, themeClass
);
1117 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
)
1119 if (cmd
== NF_REQUERY
) {
1120 INT i
= SendMessageW(from
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->Self
, NF_QUERY
);
1121 infoPtr
->bUnicode
= (i
== NFR_UNICODE
);
1123 return infoPtr
->bUnicode
? NFR_UNICODE
: NFR_ANSI
;
1128 STATUSBAR_SendMouseNotify(const STATUS_INFO
*infoPtr
, UINT code
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1132 TRACE("code %04x, lParam=%lx\n", code
, lParam
);
1133 nm
.hdr
.hwndFrom
= infoPtr
->Self
;
1134 nm
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->Self
, GWLP_ID
);
1136 nm
.pt
.x
= (short)LOWORD(lParam
);
1137 nm
.pt
.y
= (short)HIWORD(lParam
);
1138 nm
.dwItemSpec
= STATUSBAR_InternalHitTest(infoPtr
, &nm
.pt
);
1140 nm
.dwHitInfo
= 0x30000; /* seems constant */
1142 /* Do default processing if WM_NOTIFY returns zero */
1143 if(!SendMessageW(infoPtr
->Notify
, WM_NOTIFY
, nm
.hdr
.idFrom
, (LPARAM
)&nm
))
1145 return DefWindowProcW(infoPtr
->Self
, msg
, wParam
, lParam
);
1152 static LRESULT WINAPI
1153 StatusWindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1155 STATUS_INFO
*infoPtr
= (STATUS_INFO
*)GetWindowLongPtrW (hwnd
, 0);
1156 INT nPart
= ((INT
) wParam
) & 0x00ff;
1159 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1160 if (!infoPtr
&& msg
!= WM_CREATE
)
1161 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1165 return STATUSBAR_GetBorders (infoPtr
, (INT
*)lParam
);
1168 return (LRESULT
)STATUSBAR_GetIcon (infoPtr
, nPart
);
1171 return STATUSBAR_GetParts (infoPtr
, (INT
)wParam
, (INT
*)lParam
);
1174 return STATUSBAR_GetRect (infoPtr
, nPart
, (LPRECT
)lParam
);
1177 return STATUSBAR_GetTextA (infoPtr
, nPart
, (LPSTR
)lParam
);
1180 return STATUSBAR_GetTextW (infoPtr
, nPart
, (LPWSTR
)lParam
);
1182 case SB_GETTEXTLENGTHA
:
1183 case SB_GETTEXTLENGTHW
:
1184 return STATUSBAR_GetTextLength (infoPtr
, nPart
);
1186 case SB_GETTIPTEXTA
:
1187 return STATUSBAR_GetTipTextA (infoPtr
, LOWORD(wParam
), (LPSTR
)lParam
, HIWORD(wParam
));
1189 case SB_GETTIPTEXTW
:
1190 return STATUSBAR_GetTipTextW (infoPtr
, LOWORD(wParam
), (LPWSTR
)lParam
, HIWORD(wParam
));
1192 case SB_GETUNICODEFORMAT
:
1193 return infoPtr
->bUnicode
;
1196 return infoPtr
->simple
;
1199 return STATUSBAR_SetBorders (infoPtr
, (INT
*)lParam
);
1202 return STATUSBAR_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1205 return STATUSBAR_SetIcon (infoPtr
, nPart
, (HICON
)lParam
);
1207 case SB_SETMINHEIGHT
:
1208 return STATUSBAR_SetMinHeight (infoPtr
, (INT
)wParam
);
1211 return STATUSBAR_SetParts (infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
1214 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, FALSE
);
1217 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, TRUE
);
1219 case SB_SETTIPTEXTA
:
1220 return STATUSBAR_SetTipTextA (infoPtr
, (INT
)wParam
, (LPSTR
)lParam
);
1222 case SB_SETTIPTEXTW
:
1223 return STATUSBAR_SetTipTextW (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1225 case SB_SETUNICODEFORMAT
:
1226 return STATUSBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1229 return STATUSBAR_Simple (infoPtr
, (BOOL
)wParam
);
1232 return STATUSBAR_WMCreate (hwnd
, (LPCREATESTRUCTA
)lParam
);
1235 return STATUSBAR_WMDestroy (infoPtr
);
1238 return (LRESULT
)(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
1241 return STATUSBAR_WMGetText (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1243 case WM_GETTEXTLENGTH
:
1244 return LOWORD(STATUSBAR_GetTextLength (infoPtr
, 0));
1246 case WM_LBUTTONDBLCLK
:
1247 return STATUSBAR_SendMouseNotify(infoPtr
, NM_DBLCLK
, msg
, wParam
, lParam
);
1250 return STATUSBAR_SendMouseNotify(infoPtr
, NM_CLICK
, msg
, wParam
, lParam
);
1253 return STATUSBAR_Relay2Tip (infoPtr
, msg
, wParam
, lParam
);
1256 res
= STATUSBAR_WMNCHitTest(infoPtr
, (short)LOWORD(lParam
),
1257 (short)HIWORD(lParam
));
1258 if (res
!= HTERROR
) return res
;
1259 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1261 case WM_NCLBUTTONUP
:
1262 case WM_NCLBUTTONDOWN
:
1263 PostMessageW (infoPtr
->Notify
, msg
, wParam
, lParam
);
1266 case WM_NOTIFYFORMAT
:
1267 return STATUSBAR_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
1269 case WM_PRINTCLIENT
:
1271 return STATUSBAR_WMPaint (infoPtr
, (HDC
)wParam
);
1273 case WM_RBUTTONDBLCLK
:
1274 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RDBLCLK
, msg
, wParam
, lParam
);
1277 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RCLICK
, msg
, wParam
, lParam
);
1280 return STATUSBAR_WMSetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
1283 return STATUSBAR_WMSetText (infoPtr
, (LPCSTR
)lParam
);
1286 if (STATUSBAR_WMSize (infoPtr
, (WORD
)wParam
)) return 0;
1287 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1289 case WM_SYSCOLORCHANGE
:
1290 COMCTL32_RefreshSysColors();
1293 case WM_THEMECHANGED
:
1294 return theme_changed (infoPtr
);
1297 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
1298 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1299 msg
, wParam
, lParam
);
1300 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1305 /***********************************************************************
1306 * STATUS_Register [Internal]
1308 * Registers the status window class.
1312 STATUS_Register (void)
1316 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1317 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
;
1318 wndClass
.lpfnWndProc
= StatusWindowProc
;
1319 wndClass
.cbClsExtra
= 0;
1320 wndClass
.cbWndExtra
= sizeof(STATUS_INFO
*);
1321 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1322 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1323 wndClass
.lpszClassName
= STATUSCLASSNAMEW
;
1325 RegisterClassW (&wndClass
);
1329 /***********************************************************************
1330 * STATUS_Unregister [Internal]
1332 * Unregisters the status window class.
1336 STATUS_Unregister (void)
1338 UnregisterClassW (STATUSCLASSNAMEW
, NULL
);