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)
48 #include "wine/unicode.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(statusbar
);
75 UINT minHeight
; /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
80 COLORREF clrBk
; /* background color */
81 BOOL bUnicode
; /* notify format. TRUE if notifies in Unicode */
82 STATUSWINDOWPART part0
; /* simple window */
83 STATUSWINDOWPART
* parts
;
90 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
91 * The second cdrom contains executables drawstat.exe, gettext.exe,
92 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
99 static const WCHAR themeClass
[] = { 'S','t','a','t','u','s',0 };
103 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
);
105 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
);
107 static inline LPCSTR
debugstr_t(LPCWSTR text
, BOOL isW
)
109 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
113 STATUSBAR_ComputeHeight(STATUS_INFO
*infoPtr
)
120 COMCTL32_GetFontMetrics(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
, &tm
);
121 margin
= (tm
.tmInternalLeading
? tm
.tmInternalLeading
: 2);
122 height
= max(tm
.tmHeight
+ margin
+ 2*GetSystemMetrics(SM_CYBORDER
), infoPtr
->minHeight
) + infoPtr
->verticalBorder
;
124 if ((theme
= GetWindowTheme(infoPtr
->Self
)))
126 /* Determine bar height from theme such that the content area is
127 * textHeight pixels large */
128 HDC hdc
= GetDC(infoPtr
->Self
);
131 SetRect(&r
, 0, 0, 0, max(infoPtr
->minHeight
, tm
.tmHeight
));
132 if (SUCCEEDED(GetThemeBackgroundExtent(theme
, hdc
, SP_PANE
, 0, &r
, &r
)))
134 height
= r
.bottom
- r
.top
;
136 ReleaseDC(infoPtr
->Self
, hdc
);
139 TRACE(" textHeight=%d+%d, final height=%d\n", tm
.tmHeight
, tm
.tmInternalLeading
, height
);
144 STATUSBAR_DrawSizeGrip (HTHEME theme
, HDC hdc
, LPRECT lpRect
)
148 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect
));
153 if (SUCCEEDED (GetThemePartSize (theme
, hdc
, SP_GRIPPER
, 0, lpRect
,
154 TS_DRAW
, &gripperSize
)))
156 rc
.left
= rc
.right
- gripperSize
.cx
;
157 rc
.top
= rc
.bottom
- gripperSize
.cy
;
158 if (SUCCEEDED (DrawThemeBackground(theme
, hdc
, SP_GRIPPER
, 0, &rc
, NULL
)))
163 rc
.left
= max( rc
.left
, rc
.right
- GetSystemMetrics(SM_CXVSCROLL
) - 1 );
164 rc
.top
= max( rc
.top
, rc
.bottom
- GetSystemMetrics(SM_CYHSCROLL
) - 1 );
165 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
170 STATUSBAR_DrawPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
172 RECT r
= part
->bound
;
173 UINT border
= BDR_SUNKENOUTER
;
174 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
175 int themePart
= SP_PANE
;
178 TRACE("part bound %s\n", wine_dbgstr_rect(&r
));
179 if (part
->style
& SBT_POPOUT
)
180 border
= BDR_RAISEDOUTER
;
181 else if (part
->style
& SBT_NOBORDERS
)
186 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
187 && (infoPtr
->simple
|| (itemID
== (infoPtr
->numParts
-1))))
188 themePart
= SP_GRIPPERPANE
;
189 DrawThemeBackground(theme
, hdc
, themePart
, 0, &r
, NULL
);
192 DrawEdge(hdc
, &r
, border
, BF_RECT
|BF_ADJUST
);
195 INT cy
= r
.bottom
- r
.top
;
196 DrawIconEx (hdc
, r
.left
+ 2, r
.top
, part
->hIcon
, cy
, cy
, 0, 0, DI_NORMAL
);
200 if (part
->style
& SBT_OWNERDRAW
) {
203 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
205 dis
.hwndItem
= infoPtr
->Self
;
208 dis
.itemData
= (ULONG_PTR
)part
->text
;
209 SendMessageW (infoPtr
->Notify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
212 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
218 STATUSBAR_RefreshPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
223 TRACE("item %d\n", itemID
);
225 if (part
->bound
.right
< part
->bound
.left
) return;
227 if (!RectVisible(hdc
, &part
->bound
))
230 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
233 GetClientRect (infoPtr
->Self
, &cr
);
234 DrawThemeBackground(theme
, hdc
, 0, 0, &cr
, &part
->bound
);
238 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
239 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
241 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
242 FillRect(hdc
, &part
->bound
, hbrBk
);
243 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
244 DeleteObject (hbrBk
);
247 STATUSBAR_DrawPart (infoPtr
, hdc
, part
, itemID
);
252 STATUSBAR_Refresh (STATUS_INFO
*infoPtr
, HDC hdc
)
260 if (!IsWindowVisible(infoPtr
->Self
))
263 STATUSBAR_SetPartBounds(infoPtr
);
265 GetClientRect (infoPtr
->Self
, &rect
);
267 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
269 DrawThemeBackground(theme
, hdc
, 0, 0, &rect
, NULL
);
273 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
274 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
276 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
277 FillRect(hdc
, &rect
, hbrBk
);
278 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
279 DeleteObject (hbrBk
);
282 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
284 if (infoPtr
->simple
) {
285 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->part0
, 0);
289 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
290 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->parts
[i
], i
);
294 SelectObject (hdc
, hOldFont
);
296 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
297 STATUSBAR_DrawSizeGrip (theme
, hdc
, &rect
);
304 STATUSBAR_InternalHitTest(const STATUS_INFO
*infoPtr
, const POINT
*pt
)
311 for (i
= 0; i
< infoPtr
->numParts
; i
++)
312 if (pt
->x
>= infoPtr
->parts
[i
].bound
.left
&& pt
->x
<= infoPtr
->parts
[i
].bound
.right
)
319 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
)
321 STATUSWINDOWPART
*part
;
325 /* get our window size */
326 GetClientRect (infoPtr
->Self
, &rect
);
327 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect
));
329 rect
.left
+= infoPtr
->horizontalBorder
;
330 rect
.top
+= infoPtr
->verticalBorder
;
332 /* set bounds for simple rectangle */
333 infoPtr
->part0
.bound
= rect
;
335 /* set bounds for non-simple rectangles */
336 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
337 part
= &infoPtr
->parts
[i
];
338 r
= &infoPtr
->parts
[i
].bound
;
340 r
->bottom
= rect
.bottom
;
344 r
->left
= infoPtr
->parts
[i
-1].bound
.right
+ infoPtr
->horizontalGap
;
346 r
->right
= rect
.right
;
350 if (infoPtr
->hwndToolTip
) {
353 ti
.cbSize
= sizeof(TTTOOLINFOW
);
354 ti
.hwnd
= infoPtr
->Self
;
357 SendMessageW (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
,
365 STATUSBAR_Relay2Tip (const STATUS_INFO
*infoPtr
, UINT uMsg
,
366 WPARAM wParam
, LPARAM lParam
)
370 msg
.hwnd
= infoPtr
->Self
;
374 msg
.time
= GetMessageTime ();
375 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
376 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
378 return SendMessageW (infoPtr
->hwndToolTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
383 STATUSBAR_GetBorders (const STATUS_INFO
*infoPtr
, INT out
[])
386 out
[0] = infoPtr
->horizontalBorder
;
387 out
[1] = infoPtr
->verticalBorder
;
388 out
[2] = infoPtr
->horizontalGap
;
395 STATUSBAR_SetBorders (STATUS_INFO
*infoPtr
, const INT in
[])
398 infoPtr
->horizontalBorder
= in
[0];
399 infoPtr
->verticalBorder
= in
[1];
400 infoPtr
->horizontalGap
= in
[2];
401 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
408 STATUSBAR_GetIcon (const STATUS_INFO
*infoPtr
, INT nPart
)
410 TRACE("%d\n", nPart
);
411 /* MSDN says: "simple parts are indexed with -1" */
412 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
416 return (infoPtr
->part0
.hIcon
);
418 return (infoPtr
->parts
[nPart
].hIcon
);
423 STATUSBAR_GetParts (const STATUS_INFO
*infoPtr
, INT num_parts
, INT parts
[])
427 TRACE("(%d)\n", num_parts
);
429 for (i
= 0; i
< num_parts
; i
++) {
430 parts
[i
] = infoPtr
->parts
[i
].x
;
433 return infoPtr
->numParts
;
438 STATUSBAR_GetRect (const STATUS_INFO
*infoPtr
, INT nPart
, LPRECT rect
)
440 TRACE("part %d\n", nPart
);
441 if(nPart
>= infoPtr
->numParts
|| nPart
< 0)
444 *rect
= infoPtr
->part0
.bound
;
446 *rect
= infoPtr
->parts
[nPart
].bound
;
452 STATUSBAR_GetTextA (STATUS_INFO
*infoPtr
, INT nPart
, LPSTR buf
)
454 STATUSWINDOWPART
*part
;
457 TRACE("part %d\n", nPart
);
459 /* MSDN says: "simple parts use index of 0", so this check is ok. */
460 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
463 part
= &infoPtr
->part0
;
465 part
= &infoPtr
->parts
[nPart
];
467 if (part
->style
& SBT_OWNERDRAW
)
468 result
= (LRESULT
)part
->text
;
470 DWORD len
= part
->text
? WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1,
471 NULL
, 0, NULL
, NULL
) - 1 : 0;
472 result
= MAKELONG( len
, part
->style
);
473 if (part
->text
&& buf
)
474 WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1, buf
, len
+1, NULL
, NULL
);
481 STATUSBAR_GetTextW (STATUS_INFO
*infoPtr
, INT nPart
, LPWSTR buf
)
483 STATUSWINDOWPART
*part
;
486 TRACE("part %d\n", nPart
);
487 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
490 part
= &infoPtr
->part0
;
492 part
= &infoPtr
->parts
[nPart
];
494 if (part
->style
& SBT_OWNERDRAW
)
495 result
= (LRESULT
)part
->text
;
497 result
= part
->text
? strlenW (part
->text
) : 0;
498 result
|= (part
->style
<< 16);
499 if (part
->text
&& buf
)
500 strcpyW (buf
, part
->text
);
507 STATUSBAR_GetTextLength (STATUS_INFO
*infoPtr
, INT nPart
)
509 STATUSWINDOWPART
*part
;
512 TRACE("part %d\n", nPart
);
514 /* MSDN says: "simple parts use index of 0", so this check is ok. */
515 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
518 part
= &infoPtr
->part0
;
520 part
= &infoPtr
->parts
[nPart
];
522 if ((~part
->style
& SBT_OWNERDRAW
) && part
->text
)
523 result
= strlenW(part
->text
);
527 result
|= (part
->style
<< 16);
532 STATUSBAR_GetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR tip
, INT size
)
536 CHAR buf
[INFOTIPSIZE
];
539 if (infoPtr
->hwndToolTip
) {
541 ti
.cbSize
= sizeof(TTTOOLINFOA
);
542 ti
.hwnd
= infoPtr
->Self
;
545 SendMessageA (infoPtr
->hwndToolTip
, TTM_GETTEXTA
, 0, (LPARAM
)&ti
);
547 lstrcpynA (tip
, buf
, size
);
554 STATUSBAR_GetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR tip
, INT size
)
558 WCHAR buf
[INFOTIPSIZE
];
561 if (infoPtr
->hwndToolTip
) {
563 ti
.cbSize
= sizeof(TTTOOLINFOW
);
564 ti
.hwnd
= infoPtr
->Self
;
567 SendMessageW(infoPtr
->hwndToolTip
, TTM_GETTEXTW
, 0, (LPARAM
)&ti
);
569 lstrcpynW(tip
, buf
, size
);
577 STATUSBAR_SetBkColor (STATUS_INFO
*infoPtr
, COLORREF color
)
581 oldBkColor
= infoPtr
->clrBk
;
582 infoPtr
->clrBk
= color
;
583 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
585 TRACE("CREF: %08x -> %08x\n", oldBkColor
, infoPtr
->clrBk
);
591 STATUSBAR_SetIcon (STATUS_INFO
*infoPtr
, INT nPart
, HICON hIcon
)
593 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
596 TRACE("setting part %d\n", nPart
);
598 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
600 if (infoPtr
->part0
.hIcon
== hIcon
) /* same as - no redraw */
602 infoPtr
->part0
.hIcon
= hIcon
;
604 InvalidateRect(infoPtr
->Self
, &infoPtr
->part0
.bound
, FALSE
);
606 if (infoPtr
->parts
[nPart
].hIcon
== hIcon
) /* same as - no redraw */
609 infoPtr
->parts
[nPart
].hIcon
= hIcon
;
610 if (!(infoPtr
->simple
))
611 InvalidateRect(infoPtr
->Self
, &infoPtr
->parts
[nPart
].bound
, FALSE
);
618 STATUSBAR_SetMinHeight (STATUS_INFO
*infoPtr
, INT height
)
620 DWORD ysize
= GetSystemMetrics(SM_CYSIZE
);
621 if (ysize
& 1) ysize
--;
622 infoPtr
->minHeight
= max(height
, ysize
);
623 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
624 /* like native, don't resize the control */
630 STATUSBAR_SetParts (STATUS_INFO
*infoPtr
, INT count
, LPINT parts
)
632 STATUSWINDOWPART
*tmp
;
635 TRACE("(%d,%p)\n", count
, parts
);
637 if(!count
) return FALSE
;
639 oldNumParts
= infoPtr
->numParts
;
640 infoPtr
->numParts
= count
;
641 if (oldNumParts
> infoPtr
->numParts
) {
642 for (i
= infoPtr
->numParts
; i
< oldNumParts
; i
++) {
643 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
644 Free (infoPtr
->parts
[i
].text
);
646 } else if (oldNumParts
< infoPtr
->numParts
) {
647 tmp
= Alloc (sizeof(STATUSWINDOWPART
) * infoPtr
->numParts
);
648 if (!tmp
) return FALSE
;
649 for (i
= 0; i
< oldNumParts
; i
++) {
650 tmp
[i
] = infoPtr
->parts
[i
];
652 Free (infoPtr
->parts
);
653 infoPtr
->parts
= tmp
;
655 if (oldNumParts
== infoPtr
->numParts
) {
656 for (i
=0; i
< oldNumParts
; i
++)
657 if (infoPtr
->parts
[i
].x
!= parts
[i
])
659 if (i
==oldNumParts
) /* Unchanged? no need to redraw! */
663 for (i
= 0; i
< infoPtr
->numParts
; i
++)
664 infoPtr
->parts
[i
].x
= parts
[i
];
666 if (infoPtr
->hwndToolTip
) {
671 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
672 ti
.cbSize
= sizeof(TTTOOLINFOW
);
673 ti
.hwnd
= infoPtr
->Self
;
674 ti
.lpszText
= &wEmpty
;
676 nTipCount
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETTOOLCOUNT
, 0, 0);
677 if (nTipCount
< infoPtr
->numParts
) {
679 for (i
= nTipCount
; i
< infoPtr
->numParts
; i
++) {
680 TRACE("add tool %d\n", i
);
682 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
686 else if (nTipCount
> infoPtr
->numParts
) {
688 for (i
= nTipCount
- 1; i
>= infoPtr
->numParts
; i
--) {
689 TRACE("delete tool %d\n", i
);
691 SendMessageW (infoPtr
->hwndToolTip
, TTM_DELTOOLW
,
696 STATUSBAR_SetPartBounds (infoPtr
);
697 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
703 STATUSBAR_SetTextT (STATUS_INFO
*infoPtr
, INT nPart
, WORD style
,
704 LPWSTR text
, BOOL isW
)
706 STATUSWINDOWPART
*part
=NULL
;
707 BOOL changed
= FALSE
;
710 if (style
& SBT_OWNERDRAW
) {
711 TRACE("part %d, text %p\n",nPart
,text
);
713 else TRACE("part %d, text %s\n", nPart
, debugstr_t(text
, isW
));
715 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
716 * window is assumed to be a simple window */
718 if (nPart
== 0x00ff) {
719 part
= &infoPtr
->part0
;
721 if (infoPtr
->parts
&& nPart
>= 0 && nPart
< infoPtr
->numParts
) {
722 part
= &infoPtr
->parts
[nPart
];
725 if (!part
) return FALSE
;
727 if (part
->style
!= style
)
730 oldStyle
= part
->style
;
732 if (style
& SBT_OWNERDRAW
) {
733 if (!(oldStyle
& SBT_OWNERDRAW
))
741 LPCSTR atxt
= (LPCSTR
)text
;
742 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, NULL
, 0 );
743 ntext
= Alloc( (len
+ 1)*sizeof(WCHAR
) );
744 if (!ntext
) return FALSE
;
745 MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, ntext
, len
);
747 ntext
= Alloc( (strlenW(text
) + 1)*sizeof(WCHAR
) );
748 if (!ntext
) return FALSE
;
749 strcpyW (ntext
, text
);
752 /* replace nonprintable characters with spaces */
762 /* check if text is unchanged -> no need to redraw */
764 if (!changed
&& part
->text
&& !lstrcmpW(ntext
, part
->text
)) {
769 if (!changed
&& !part
->text
)
773 if (!(oldStyle
& SBT_OWNERDRAW
))
777 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
778 UpdateWindow(infoPtr
->Self
);
785 STATUSBAR_SetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR text
)
787 TRACE("part %d: \"%s\"\n", id
, text
);
788 if (infoPtr
->hwndToolTip
) {
790 ti
.cbSize
= sizeof(TTTOOLINFOA
);
791 ti
.hwnd
= infoPtr
->Self
;
795 SendMessageA (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTA
, 0, (LPARAM
)&ti
);
803 STATUSBAR_SetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR text
)
805 TRACE("part %d: \"%s\"\n", id
, debugstr_w(text
));
806 if (infoPtr
->hwndToolTip
) {
808 ti
.cbSize
= sizeof(TTTOOLINFOW
);
809 ti
.hwnd
= infoPtr
->Self
;
813 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
820 static inline LRESULT
821 STATUSBAR_SetUnicodeFormat (STATUS_INFO
*infoPtr
, BOOL bUnicode
)
823 BOOL bOld
= infoPtr
->bUnicode
;
825 TRACE("(0x%x)\n", bUnicode
);
826 infoPtr
->bUnicode
= bUnicode
;
833 STATUSBAR_Simple (STATUS_INFO
*infoPtr
, BOOL simple
)
837 TRACE("(simple=%d)\n", simple
);
838 if (infoPtr
->simple
== simple
) /* no need to change */
841 infoPtr
->simple
= simple
;
843 /* send notification */
844 nmhdr
.hwndFrom
= infoPtr
->Self
;
845 nmhdr
.idFrom
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
846 nmhdr
.code
= SBN_SIMPLEMODECHANGE
;
847 SendMessageW (infoPtr
->Notify
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
848 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
854 STATUSBAR_WMDestroy (STATUS_INFO
*infoPtr
)
859 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
860 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
861 Free (infoPtr
->parts
[i
].text
);
863 if (!(infoPtr
->part0
.style
& SBT_OWNERDRAW
))
864 Free (infoPtr
->part0
.text
);
865 Free (infoPtr
->parts
);
867 /* delete default font */
868 if (infoPtr
->hDefaultFont
)
869 DeleteObject (infoPtr
->hDefaultFont
);
871 /* delete tool tip control */
872 if (infoPtr
->hwndToolTip
)
873 DestroyWindow (infoPtr
->hwndToolTip
);
875 CloseThemeData (GetWindowTheme (infoPtr
->Self
));
877 SetWindowLongPtrW(infoPtr
->Self
, 0, 0);
884 STATUSBAR_WMCreate (HWND hwnd
, const CREATESTRUCTA
*lpCreate
)
886 STATUS_INFO
*infoPtr
;
887 NONCLIENTMETRICSW nclm
;
893 infoPtr
= Alloc (sizeof(STATUS_INFO
));
894 if (!infoPtr
) goto create_fail
;
895 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
897 infoPtr
->Self
= hwnd
;
898 infoPtr
->Notify
= lpCreate
->hwndParent
;
899 infoPtr
->numParts
= 1;
901 infoPtr
->simple
= FALSE
;
902 infoPtr
->clrBk
= CLR_DEFAULT
;
904 infoPtr
->horizontalBorder
= HORZ_BORDER
;
905 infoPtr
->verticalBorder
= VERT_BORDER
;
906 infoPtr
->horizontalGap
= HORZ_GAP
;
907 infoPtr
->minHeight
= GetSystemMetrics(SM_CYSIZE
);
908 if (infoPtr
->minHeight
& 1) infoPtr
->minHeight
--;
910 STATUSBAR_NotifyFormat(infoPtr
, infoPtr
->Notify
, NF_REQUERY
);
912 ZeroMemory (&nclm
, sizeof(nclm
));
913 nclm
.cbSize
= sizeof(nclm
);
914 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0);
915 infoPtr
->hDefaultFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
917 GetClientRect (hwnd
, &rect
);
919 /* initialize simple case */
920 infoPtr
->part0
.bound
= rect
;
921 infoPtr
->part0
.text
= 0;
922 infoPtr
->part0
.x
= 0;
923 infoPtr
->part0
.style
= 0;
924 infoPtr
->part0
.hIcon
= 0;
926 /* initialize first part */
927 infoPtr
->parts
= Alloc (sizeof(STATUSWINDOWPART
));
928 if (!infoPtr
->parts
) goto create_fail
;
929 infoPtr
->parts
[0].bound
= rect
;
930 infoPtr
->parts
[0].text
= 0;
931 infoPtr
->parts
[0].x
= -1;
932 infoPtr
->parts
[0].style
= 0;
933 infoPtr
->parts
[0].hIcon
= 0;
935 OpenThemeData (hwnd
, themeClass
);
937 if (lpCreate
->lpszName
&& (len
= strlenW ((LPCWSTR
)lpCreate
->lpszName
)))
939 infoPtr
->parts
[0].text
= Alloc ((len
+ 1)*sizeof(WCHAR
));
940 if (!infoPtr
->parts
[0].text
) goto create_fail
;
941 strcpyW (infoPtr
->parts
[0].text
, (LPCWSTR
)lpCreate
->lpszName
);
944 dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
945 /* native seems to clear WS_BORDER, too */
946 dwStyle
&= ~WS_BORDER
;
947 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
949 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
951 if (dwStyle
& SBT_TOOLTIPS
) {
952 infoPtr
->hwndToolTip
=
953 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
| TTS_ALWAYSTIP
,
954 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
955 CW_USEDEFAULT
, hwnd
, 0,
956 (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
), NULL
);
958 if (infoPtr
->hwndToolTip
) {
959 NMTOOLTIPSCREATED nmttc
;
961 nmttc
.hdr
.hwndFrom
= hwnd
;
962 nmttc
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
963 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
964 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
966 SendMessageW (lpCreate
->hwndParent
, WM_NOTIFY
, nmttc
.hdr
.idFrom
, (LPARAM
)&nmttc
);
974 if (infoPtr
) STATUSBAR_WMDestroy(infoPtr
);
979 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
980 * of the first part only (usual behaviour) */
982 STATUSBAR_WMGetText (const STATUS_INFO
*infoPtr
, INT size
, LPWSTR buf
)
987 if (!(infoPtr
->parts
[0].text
))
990 len
= strlenW (infoPtr
->parts
[0].text
);
994 else if (size
> len
) {
995 strcpyW (buf
, infoPtr
->parts
[0].text
);
999 memcpy (buf
, infoPtr
->parts
[0].text
, (size
- 1) * sizeof(WCHAR
));
1007 STATUSBAR_WMNCHitTest (const STATUS_INFO
*infoPtr
, INT x
, INT y
)
1009 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
) {
1013 GetClientRect (infoPtr
->Self
, &rect
);
1017 ScreenToClient (infoPtr
->Self
, &pt
);
1019 rect
.left
= rect
.right
- 13;
1022 if (PtInRect (&rect
, pt
))
1024 if (GetWindowLongW( infoPtr
->Self
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) return HTBOTTOMLEFT
;
1025 else return HTBOTTOMRIGHT
;
1034 STATUSBAR_WMPaint (STATUS_INFO
*infoPtr
, HDC hdc
)
1039 if (hdc
) return STATUSBAR_Refresh (infoPtr
, hdc
);
1040 hdc
= BeginPaint (infoPtr
->Self
, &ps
);
1041 STATUSBAR_Refresh (infoPtr
, hdc
);
1042 EndPaint (infoPtr
->Self
, &ps
);
1049 STATUSBAR_WMSetFont (STATUS_INFO
*infoPtr
, HFONT font
, BOOL redraw
)
1051 infoPtr
->hFont
= font
;
1052 TRACE("%p\n", infoPtr
->hFont
);
1054 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
1055 SendMessageW(infoPtr
->Self
, WM_SIZE
, 0, 0); /* update size */
1057 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
1064 STATUSBAR_WMSetText (const STATUS_INFO
*infoPtr
, LPCSTR text
)
1066 STATUSWINDOWPART
*part
;
1070 if (infoPtr
->numParts
== 0)
1073 part
= &infoPtr
->parts
[0];
1074 /* duplicate string */
1078 if (text
&& (len
= strlenW((LPCWSTR
)text
))) {
1079 part
->text
= Alloc ((len
+1)*sizeof(WCHAR
));
1080 if (!part
->text
) return FALSE
;
1081 strcpyW (part
->text
, (LPCWSTR
)text
);
1084 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
1091 STATUSBAR_WMSize (STATUS_INFO
*infoPtr
, WORD flags
)
1096 /* Need to resize width to match parent */
1097 TRACE("flags %04x\n", flags
);
1099 if (flags
!= SIZE_RESTORED
&& flags
!= SIZE_MAXIMIZED
) {
1100 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1104 if (GetWindowLongW(infoPtr
->Self
, GWL_STYLE
) & CCS_NORESIZE
) return FALSE
;
1106 /* width and height don't apply */
1107 if (!GetClientRect (infoPtr
->Notify
, &parent_rect
))
1110 width
= parent_rect
.right
- parent_rect
.left
;
1111 x
= parent_rect
.left
;
1112 y
= parent_rect
.bottom
- infoPtr
->height
;
1113 MoveWindow (infoPtr
->Self
, x
, y
, width
, infoPtr
->height
, TRUE
);
1114 STATUSBAR_SetPartBounds (infoPtr
);
1119 /* update theme after a WM_THEMECHANGED message */
1120 static LRESULT
theme_changed (const STATUS_INFO
* infoPtr
)
1122 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
1123 CloseThemeData (theme
);
1124 OpenThemeData (infoPtr
->Self
, themeClass
);
1130 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
)
1132 if (cmd
== NF_REQUERY
) {
1133 INT i
= SendMessageW(from
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->Self
, NF_QUERY
);
1134 infoPtr
->bUnicode
= (i
== NFR_UNICODE
);
1136 return infoPtr
->bUnicode
? NFR_UNICODE
: NFR_ANSI
;
1141 STATUSBAR_SendMouseNotify(const STATUS_INFO
*infoPtr
, UINT code
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1145 TRACE("code %04x, lParam=%lx\n", code
, lParam
);
1146 nm
.hdr
.hwndFrom
= infoPtr
->Self
;
1147 nm
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->Self
, GWLP_ID
);
1149 nm
.pt
.x
= (short)LOWORD(lParam
);
1150 nm
.pt
.y
= (short)HIWORD(lParam
);
1151 nm
.dwItemSpec
= STATUSBAR_InternalHitTest(infoPtr
, &nm
.pt
);
1153 nm
.dwHitInfo
= 0x30000; /* seems constant */
1155 /* Do default processing if WM_NOTIFY returns zero */
1156 if(!SendMessageW(infoPtr
->Notify
, WM_NOTIFY
, nm
.hdr
.idFrom
, (LPARAM
)&nm
))
1158 return DefWindowProcW(infoPtr
->Self
, msg
, wParam
, lParam
);
1165 static LRESULT WINAPI
1166 StatusWindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1168 STATUS_INFO
*infoPtr
= (STATUS_INFO
*)GetWindowLongPtrW (hwnd
, 0);
1169 INT nPart
= ((INT
) wParam
) & 0x00ff;
1172 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1173 if (!infoPtr
&& msg
!= WM_CREATE
)
1174 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1178 return STATUSBAR_GetBorders (infoPtr
, (INT
*)lParam
);
1181 return (LRESULT
)STATUSBAR_GetIcon (infoPtr
, nPart
);
1184 return STATUSBAR_GetParts (infoPtr
, (INT
)wParam
, (INT
*)lParam
);
1187 return STATUSBAR_GetRect (infoPtr
, nPart
, (LPRECT
)lParam
);
1190 return STATUSBAR_GetTextA (infoPtr
, nPart
, (LPSTR
)lParam
);
1193 return STATUSBAR_GetTextW (infoPtr
, nPart
, (LPWSTR
)lParam
);
1195 case SB_GETTEXTLENGTHA
:
1196 case SB_GETTEXTLENGTHW
:
1197 return STATUSBAR_GetTextLength (infoPtr
, nPart
);
1199 case SB_GETTIPTEXTA
:
1200 return STATUSBAR_GetTipTextA (infoPtr
, LOWORD(wParam
), (LPSTR
)lParam
, HIWORD(wParam
));
1202 case SB_GETTIPTEXTW
:
1203 return STATUSBAR_GetTipTextW (infoPtr
, LOWORD(wParam
), (LPWSTR
)lParam
, HIWORD(wParam
));
1205 case SB_GETUNICODEFORMAT
:
1206 return infoPtr
->bUnicode
;
1209 return infoPtr
->simple
;
1212 return STATUSBAR_SetBorders (infoPtr
, (INT
*)lParam
);
1215 return STATUSBAR_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1218 return STATUSBAR_SetIcon (infoPtr
, nPart
, (HICON
)lParam
);
1220 case SB_SETMINHEIGHT
:
1221 return STATUSBAR_SetMinHeight (infoPtr
, (INT
)wParam
);
1224 return STATUSBAR_SetParts (infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
1227 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, FALSE
);
1230 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, TRUE
);
1232 case SB_SETTIPTEXTA
:
1233 return STATUSBAR_SetTipTextA (infoPtr
, (INT
)wParam
, (LPSTR
)lParam
);
1235 case SB_SETTIPTEXTW
:
1236 return STATUSBAR_SetTipTextW (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1238 case SB_SETUNICODEFORMAT
:
1239 return STATUSBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1242 return STATUSBAR_Simple (infoPtr
, (BOOL
)wParam
);
1245 return STATUSBAR_WMCreate (hwnd
, (LPCREATESTRUCTA
)lParam
);
1248 return STATUSBAR_WMDestroy (infoPtr
);
1251 return (LRESULT
)(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
1254 return STATUSBAR_WMGetText (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1256 case WM_GETTEXTLENGTH
:
1257 return LOWORD(STATUSBAR_GetTextLength (infoPtr
, 0));
1259 case WM_LBUTTONDBLCLK
:
1260 return STATUSBAR_SendMouseNotify(infoPtr
, NM_DBLCLK
, msg
, wParam
, lParam
);
1263 return STATUSBAR_SendMouseNotify(infoPtr
, NM_CLICK
, msg
, wParam
, lParam
);
1266 return STATUSBAR_Relay2Tip (infoPtr
, msg
, wParam
, lParam
);
1269 res
= STATUSBAR_WMNCHitTest(infoPtr
, (short)LOWORD(lParam
),
1270 (short)HIWORD(lParam
));
1271 if (res
!= HTERROR
) return res
;
1272 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1274 case WM_NCLBUTTONUP
:
1275 case WM_NCLBUTTONDOWN
:
1276 PostMessageW (infoPtr
->Notify
, msg
, wParam
, lParam
);
1279 case WM_NOTIFYFORMAT
:
1280 return STATUSBAR_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
1282 case WM_PRINTCLIENT
:
1284 return STATUSBAR_WMPaint (infoPtr
, (HDC
)wParam
);
1286 case WM_RBUTTONDBLCLK
:
1287 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RDBLCLK
, msg
, wParam
, lParam
);
1290 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RCLICK
, msg
, wParam
, lParam
);
1293 return STATUSBAR_WMSetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
1296 return STATUSBAR_WMSetText (infoPtr
, (LPCSTR
)lParam
);
1299 if (STATUSBAR_WMSize (infoPtr
, (WORD
)wParam
)) return 0;
1300 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1302 case WM_SYSCOLORCHANGE
:
1303 COMCTL32_RefreshSysColors();
1306 case WM_THEMECHANGED
:
1307 return theme_changed (infoPtr
);
1310 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
1311 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1312 msg
, wParam
, lParam
);
1313 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1318 /***********************************************************************
1319 * STATUS_Register [Internal]
1321 * Registers the status window class.
1325 STATUS_Register (void)
1329 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1330 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
;
1331 wndClass
.lpfnWndProc
= StatusWindowProc
;
1332 wndClass
.cbClsExtra
= 0;
1333 wndClass
.cbWndExtra
= sizeof(STATUS_INFO
*);
1334 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1335 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1336 wndClass
.lpszClassName
= STATUSCLASSNAMEW
;
1338 RegisterClassW (&wndClass
);
1342 /***********************************************************************
1343 * STATUS_Unregister [Internal]
1345 * Unregisters the status window class.
1349 STATUS_Unregister (void)
1351 UnregisterClassW (STATUSCLASSNAMEW
, NULL
);