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
);
117 memset (&r
, 0, sizeof (r
));
118 r
.bottom
= 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
)
133 HPEN hPenFace
, hPenShadow
, hPenHighlight
, hOldPen
;
137 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect
));
143 gripperRect
= *lpRect
;
144 if (SUCCEEDED (GetThemePartSize (theme
, hdc
, SP_GRIPPER
, 0, lpRect
,
145 TS_DRAW
, &gripperSize
)))
147 gripperRect
.left
= gripperRect
.right
- gripperSize
.cx
;
148 gripperRect
.top
= gripperRect
.bottom
- gripperSize
.cy
;
149 if (SUCCEEDED (DrawThemeBackground(theme
, hdc
, SP_GRIPPER
, 0, &gripperRect
, NULL
)))
154 pt
.x
= lpRect
->right
- 1;
155 pt
.y
= lpRect
->bottom
- 1;
157 hPenFace
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
);
158 hOldPen
= SelectObject( hdc
, hPenFace
);
159 MoveToEx (hdc
, pt
.x
- 12, pt
.y
, NULL
);
160 LineTo (hdc
, pt
.x
, pt
.y
);
161 LineTo (hdc
, pt
.x
, pt
.y
- 13);
166 hPenShadow
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dShadow
);
167 SelectObject( hdc
, hPenShadow
);
168 for (i
= 1; i
< 11; i
+= 4) {
169 MoveToEx (hdc
, pt
.x
- i
, pt
.y
, NULL
);
170 LineTo (hdc
, pt
.x
+ 1, pt
.y
- i
- 1);
172 MoveToEx (hdc
, pt
.x
- i
- 1, pt
.y
, NULL
);
173 LineTo (hdc
, pt
.x
+ 1, pt
.y
- i
- 2);
176 hPenHighlight
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dHilight
);
177 SelectObject( hdc
, hPenHighlight
);
178 for (i
= 3; i
< 13; i
+= 4) {
179 MoveToEx (hdc
, pt
.x
- i
, pt
.y
, NULL
);
180 LineTo (hdc
, pt
.x
+ 1, pt
.y
- i
- 1);
183 SelectObject (hdc
, hOldPen
);
184 DeleteObject( hPenFace
);
185 DeleteObject( hPenShadow
);
186 DeleteObject( hPenHighlight
);
191 STATUSBAR_DrawPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
193 RECT r
= part
->bound
;
194 UINT border
= BDR_SUNKENOUTER
;
195 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
196 int themePart
= SP_PANE
;
199 TRACE("part bound %s\n", wine_dbgstr_rect(&r
));
200 if (part
->style
& SBT_POPOUT
)
201 border
= BDR_RAISEDOUTER
;
202 else if (part
->style
& SBT_NOBORDERS
)
207 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
208 && (infoPtr
->simple
|| (itemID
== (infoPtr
->numParts
-1))))
209 themePart
= SP_GRIPPERPANE
;
210 DrawThemeBackground(theme
, hdc
, themePart
, 0, &r
, NULL
);
213 DrawEdge(hdc
, &r
, border
, BF_RECT
|BF_ADJUST
);
216 INT cy
= r
.bottom
- r
.top
;
217 DrawIconEx (hdc
, r
.left
+ 2, r
.top
, part
->hIcon
, cy
, cy
, 0, 0, DI_NORMAL
);
221 if (part
->style
& SBT_OWNERDRAW
) {
224 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
226 dis
.hwndItem
= infoPtr
->Self
;
229 dis
.itemData
= (ULONG_PTR
)part
->text
;
230 SendMessageW (infoPtr
->Notify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
233 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
239 STATUSBAR_RefreshPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
244 TRACE("item %d\n", itemID
);
246 if (part
->bound
.right
< part
->bound
.left
) return;
248 if (!RectVisible(hdc
, &part
->bound
))
251 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
254 GetClientRect (infoPtr
->Self
, &cr
);
255 DrawThemeBackground(theme
, hdc
, 0, 0, &cr
, &part
->bound
);
259 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
260 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
262 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
263 FillRect(hdc
, &part
->bound
, hbrBk
);
264 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
265 DeleteObject (hbrBk
);
268 STATUSBAR_DrawPart (infoPtr
, hdc
, part
, itemID
);
273 STATUSBAR_Refresh (STATUS_INFO
*infoPtr
, HDC hdc
)
281 if (!IsWindowVisible(infoPtr
->Self
))
284 STATUSBAR_SetPartBounds(infoPtr
);
286 GetClientRect (infoPtr
->Self
, &rect
);
288 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
290 DrawThemeBackground(theme
, hdc
, 0, 0, &rect
, NULL
);
294 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
295 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
297 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
298 FillRect(hdc
, &rect
, hbrBk
);
299 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
300 DeleteObject (hbrBk
);
303 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
305 if (infoPtr
->simple
) {
306 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->part0
, 0);
310 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
311 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->parts
[i
], i
);
315 SelectObject (hdc
, hOldFont
);
317 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
318 STATUSBAR_DrawSizeGrip (theme
, hdc
, &rect
);
325 STATUSBAR_InternalHitTest(const STATUS_INFO
*infoPtr
, const POINT
*pt
)
332 for (i
= 0; i
< infoPtr
->numParts
; i
++)
333 if (pt
->x
>= infoPtr
->parts
[i
].bound
.left
&& pt
->x
<= infoPtr
->parts
[i
].bound
.right
)
340 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
)
342 STATUSWINDOWPART
*part
;
346 /* get our window size */
347 GetClientRect (infoPtr
->Self
, &rect
);
348 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect
));
350 rect
.left
+= infoPtr
->horizontalBorder
;
351 rect
.top
+= infoPtr
->verticalBorder
;
353 /* set bounds for simple rectangle */
354 infoPtr
->part0
.bound
= rect
;
356 /* set bounds for non-simple rectangles */
357 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
358 part
= &infoPtr
->parts
[i
];
359 r
= &infoPtr
->parts
[i
].bound
;
361 r
->bottom
= rect
.bottom
;
365 r
->left
= infoPtr
->parts
[i
-1].bound
.right
+ infoPtr
->horizontalGap
;
367 r
->right
= rect
.right
;
371 if (infoPtr
->hwndToolTip
) {
374 ti
.cbSize
= sizeof(TTTOOLINFOW
);
375 ti
.hwnd
= infoPtr
->Self
;
378 SendMessageW (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
,
386 STATUSBAR_Relay2Tip (const STATUS_INFO
*infoPtr
, UINT uMsg
,
387 WPARAM wParam
, LPARAM lParam
)
391 msg
.hwnd
= infoPtr
->Self
;
395 msg
.time
= GetMessageTime ();
396 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
397 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
399 return SendMessageW (infoPtr
->hwndToolTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
404 STATUSBAR_GetBorders (const STATUS_INFO
*infoPtr
, INT out
[])
407 out
[0] = infoPtr
->horizontalBorder
;
408 out
[1] = infoPtr
->verticalBorder
;
409 out
[2] = infoPtr
->horizontalGap
;
416 STATUSBAR_SetBorders (STATUS_INFO
*infoPtr
, const INT in
[])
419 infoPtr
->horizontalBorder
= in
[0];
420 infoPtr
->verticalBorder
= in
[1];
421 infoPtr
->horizontalGap
= in
[2];
422 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
429 STATUSBAR_GetIcon (const STATUS_INFO
*infoPtr
, INT nPart
)
431 TRACE("%d\n", nPart
);
432 /* MSDN says: "simple parts are indexed with -1" */
433 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
437 return (infoPtr
->part0
.hIcon
);
439 return (infoPtr
->parts
[nPart
].hIcon
);
444 STATUSBAR_GetParts (const STATUS_INFO
*infoPtr
, INT num_parts
, INT parts
[])
448 TRACE("(%d)\n", num_parts
);
450 for (i
= 0; i
< num_parts
; i
++) {
451 parts
[i
] = infoPtr
->parts
[i
].x
;
454 return infoPtr
->numParts
;
459 STATUSBAR_GetRect (const STATUS_INFO
*infoPtr
, INT nPart
, LPRECT rect
)
461 TRACE("part %d\n", nPart
);
462 if(nPart
>= infoPtr
->numParts
|| nPart
< 0)
465 *rect
= infoPtr
->part0
.bound
;
467 *rect
= infoPtr
->parts
[nPart
].bound
;
473 STATUSBAR_GetTextA (STATUS_INFO
*infoPtr
, INT nPart
, LPSTR buf
)
475 STATUSWINDOWPART
*part
;
478 TRACE("part %d\n", nPart
);
480 /* MSDN says: "simple parts use index of 0", so this check is ok. */
481 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
484 part
= &infoPtr
->part0
;
486 part
= &infoPtr
->parts
[nPart
];
488 if (part
->style
& SBT_OWNERDRAW
)
489 result
= (LRESULT
)part
->text
;
491 DWORD len
= part
->text
? WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1,
492 NULL
, 0, NULL
, NULL
) - 1 : 0;
493 result
= MAKELONG( len
, part
->style
);
494 if (part
->text
&& buf
)
495 WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1, buf
, len
+1, NULL
, NULL
);
502 STATUSBAR_GetTextW (STATUS_INFO
*infoPtr
, INT nPart
, LPWSTR buf
)
504 STATUSWINDOWPART
*part
;
507 TRACE("part %d\n", nPart
);
508 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
511 part
= &infoPtr
->part0
;
513 part
= &infoPtr
->parts
[nPart
];
515 if (part
->style
& SBT_OWNERDRAW
)
516 result
= (LRESULT
)part
->text
;
518 result
= part
->text
? strlenW (part
->text
) : 0;
519 result
|= (part
->style
<< 16);
520 if (part
->text
&& buf
)
521 strcpyW (buf
, part
->text
);
528 STATUSBAR_GetTextLength (STATUS_INFO
*infoPtr
, INT nPart
)
530 STATUSWINDOWPART
*part
;
533 TRACE("part %d\n", nPart
);
535 /* MSDN says: "simple parts use index of 0", so this check is ok. */
536 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
539 part
= &infoPtr
->part0
;
541 part
= &infoPtr
->parts
[nPart
];
543 if ((~part
->style
& SBT_OWNERDRAW
) && part
->text
)
544 result
= strlenW(part
->text
);
548 result
|= (part
->style
<< 16);
553 STATUSBAR_GetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR tip
, INT size
)
557 CHAR buf
[INFOTIPSIZE
];
560 if (infoPtr
->hwndToolTip
) {
562 ti
.cbSize
= sizeof(TTTOOLINFOA
);
563 ti
.hwnd
= infoPtr
->Self
;
566 SendMessageA (infoPtr
->hwndToolTip
, TTM_GETTEXTA
, 0, (LPARAM
)&ti
);
568 lstrcpynA (tip
, buf
, size
);
575 STATUSBAR_GetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR tip
, INT size
)
579 WCHAR buf
[INFOTIPSIZE
];
582 if (infoPtr
->hwndToolTip
) {
584 ti
.cbSize
= sizeof(TTTOOLINFOW
);
585 ti
.hwnd
= infoPtr
->Self
;
588 SendMessageW(infoPtr
->hwndToolTip
, TTM_GETTEXTW
, 0, (LPARAM
)&ti
);
590 lstrcpynW(tip
, buf
, size
);
598 STATUSBAR_SetBkColor (STATUS_INFO
*infoPtr
, COLORREF color
)
602 oldBkColor
= infoPtr
->clrBk
;
603 infoPtr
->clrBk
= color
;
604 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
606 TRACE("CREF: %08x -> %08x\n", oldBkColor
, infoPtr
->clrBk
);
612 STATUSBAR_SetIcon (STATUS_INFO
*infoPtr
, INT nPart
, HICON hIcon
)
614 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
617 TRACE("setting part %d\n", nPart
);
619 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
621 if (infoPtr
->part0
.hIcon
== hIcon
) /* same as - no redraw */
623 infoPtr
->part0
.hIcon
= hIcon
;
625 InvalidateRect(infoPtr
->Self
, &infoPtr
->part0
.bound
, FALSE
);
627 if (infoPtr
->parts
[nPart
].hIcon
== hIcon
) /* same as - no redraw */
630 infoPtr
->parts
[nPart
].hIcon
= hIcon
;
631 if (!(infoPtr
->simple
))
632 InvalidateRect(infoPtr
->Self
, &infoPtr
->parts
[nPart
].bound
, FALSE
);
639 STATUSBAR_SetMinHeight (STATUS_INFO
*infoPtr
, INT height
)
641 DWORD ysize
= GetSystemMetrics(SM_CYSIZE
);
642 if (ysize
& 1) ysize
--;
643 infoPtr
->minHeight
= max(height
, ysize
);
644 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
645 /* like native, don't resize the control */
651 STATUSBAR_SetParts (STATUS_INFO
*infoPtr
, INT count
, LPINT parts
)
653 STATUSWINDOWPART
*tmp
;
656 TRACE("(%d,%p)\n", count
, parts
);
658 if(!count
) return FALSE
;
660 oldNumParts
= infoPtr
->numParts
;
661 infoPtr
->numParts
= count
;
662 if (oldNumParts
> infoPtr
->numParts
) {
663 for (i
= infoPtr
->numParts
; i
< oldNumParts
; i
++) {
664 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
665 Free (infoPtr
->parts
[i
].text
);
667 } else if (oldNumParts
< infoPtr
->numParts
) {
668 tmp
= Alloc (sizeof(STATUSWINDOWPART
) * infoPtr
->numParts
);
669 if (!tmp
) return FALSE
;
670 for (i
= 0; i
< oldNumParts
; i
++) {
671 tmp
[i
] = infoPtr
->parts
[i
];
673 Free (infoPtr
->parts
);
674 infoPtr
->parts
= tmp
;
676 if (oldNumParts
== infoPtr
->numParts
) {
677 for (i
=0; i
< oldNumParts
; i
++)
678 if (infoPtr
->parts
[i
].x
!= parts
[i
])
680 if (i
==oldNumParts
) /* Unchanged? no need to redraw! */
684 for (i
= 0; i
< infoPtr
->numParts
; i
++)
685 infoPtr
->parts
[i
].x
= parts
[i
];
687 if (infoPtr
->hwndToolTip
) {
692 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
693 ti
.cbSize
= sizeof(TTTOOLINFOW
);
694 ti
.hwnd
= infoPtr
->Self
;
695 ti
.lpszText
= &wEmpty
;
697 nTipCount
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETTOOLCOUNT
, 0, 0);
698 if (nTipCount
< infoPtr
->numParts
) {
700 for (i
= nTipCount
; i
< infoPtr
->numParts
; i
++) {
701 TRACE("add tool %d\n", i
);
703 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
707 else if (nTipCount
> infoPtr
->numParts
) {
709 for (i
= nTipCount
- 1; i
>= infoPtr
->numParts
; i
--) {
710 TRACE("delete tool %d\n", i
);
712 SendMessageW (infoPtr
->hwndToolTip
, TTM_DELTOOLW
,
717 STATUSBAR_SetPartBounds (infoPtr
);
718 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
724 STATUSBAR_SetTextT (STATUS_INFO
*infoPtr
, INT nPart
, WORD style
,
725 LPWSTR text
, BOOL isW
)
727 STATUSWINDOWPART
*part
=NULL
;
728 BOOL changed
= FALSE
;
731 if (style
& SBT_OWNERDRAW
) {
732 TRACE("part %d, text %p\n",nPart
,text
);
734 else TRACE("part %d, text %s\n", nPart
, debugstr_t(text
, isW
));
736 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
737 * window is assumed to be a simple window */
739 if (nPart
== 0x00ff) {
740 part
= &infoPtr
->part0
;
742 if (infoPtr
->parts
&& nPart
>= 0 && nPart
< infoPtr
->numParts
) {
743 part
= &infoPtr
->parts
[nPart
];
746 if (!part
) return FALSE
;
748 if (part
->style
!= style
)
751 oldStyle
= part
->style
;
753 if (style
& SBT_OWNERDRAW
) {
754 if (!(oldStyle
& SBT_OWNERDRAW
))
762 LPCSTR atxt
= (LPCSTR
)text
;
763 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, NULL
, 0 );
764 ntext
= Alloc( (len
+ 1)*sizeof(WCHAR
) );
765 if (!ntext
) return FALSE
;
766 MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, ntext
, len
);
768 ntext
= Alloc( (strlenW(text
) + 1)*sizeof(WCHAR
) );
769 if (!ntext
) return FALSE
;
770 strcpyW (ntext
, text
);
773 /* replace nonprintable characters with spaces */
783 /* check if text is unchanged -> no need to redraw */
785 if (!changed
&& part
->text
&& !lstrcmpW(ntext
, part
->text
)) {
790 if (!changed
&& !part
->text
)
794 if (!(oldStyle
& SBT_OWNERDRAW
))
798 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
799 UpdateWindow(infoPtr
->Self
);
806 STATUSBAR_SetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR text
)
808 TRACE("part %d: \"%s\"\n", id
, text
);
809 if (infoPtr
->hwndToolTip
) {
811 ti
.cbSize
= sizeof(TTTOOLINFOA
);
812 ti
.hwnd
= infoPtr
->Self
;
816 SendMessageA (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTA
, 0, (LPARAM
)&ti
);
824 STATUSBAR_SetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR text
)
826 TRACE("part %d: \"%s\"\n", id
, debugstr_w(text
));
827 if (infoPtr
->hwndToolTip
) {
829 ti
.cbSize
= sizeof(TTTOOLINFOW
);
830 ti
.hwnd
= infoPtr
->Self
;
834 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
841 static inline LRESULT
842 STATUSBAR_SetUnicodeFormat (STATUS_INFO
*infoPtr
, BOOL bUnicode
)
844 BOOL bOld
= infoPtr
->bUnicode
;
846 TRACE("(0x%x)\n", bUnicode
);
847 infoPtr
->bUnicode
= bUnicode
;
854 STATUSBAR_Simple (STATUS_INFO
*infoPtr
, BOOL simple
)
858 TRACE("(simple=%d)\n", simple
);
859 if (infoPtr
->simple
== simple
) /* no need to change */
862 infoPtr
->simple
= simple
;
864 /* send notification */
865 nmhdr
.hwndFrom
= infoPtr
->Self
;
866 nmhdr
.idFrom
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
867 nmhdr
.code
= SBN_SIMPLEMODECHANGE
;
868 SendMessageW (infoPtr
->Notify
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
869 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
875 STATUSBAR_WMDestroy (STATUS_INFO
*infoPtr
)
880 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
881 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
882 Free (infoPtr
->parts
[i
].text
);
884 if (!(infoPtr
->part0
.style
& SBT_OWNERDRAW
))
885 Free (infoPtr
->part0
.text
);
886 Free (infoPtr
->parts
);
888 /* delete default font */
889 if (infoPtr
->hDefaultFont
)
890 DeleteObject (infoPtr
->hDefaultFont
);
892 /* delete tool tip control */
893 if (infoPtr
->hwndToolTip
)
894 DestroyWindow (infoPtr
->hwndToolTip
);
896 CloseThemeData (GetWindowTheme (infoPtr
->Self
));
898 SetWindowLongPtrW(infoPtr
->Self
, 0, 0);
905 STATUSBAR_WMCreate (HWND hwnd
, const CREATESTRUCTA
*lpCreate
)
907 STATUS_INFO
*infoPtr
;
908 NONCLIENTMETRICSW nclm
;
914 infoPtr
= Alloc (sizeof(STATUS_INFO
));
915 if (!infoPtr
) goto create_fail
;
916 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
918 infoPtr
->Self
= hwnd
;
919 infoPtr
->Notify
= lpCreate
->hwndParent
;
920 infoPtr
->numParts
= 1;
922 infoPtr
->simple
= FALSE
;
923 infoPtr
->clrBk
= CLR_DEFAULT
;
925 infoPtr
->horizontalBorder
= HORZ_BORDER
;
926 infoPtr
->verticalBorder
= VERT_BORDER
;
927 infoPtr
->horizontalGap
= HORZ_GAP
;
928 infoPtr
->minHeight
= GetSystemMetrics(SM_CYSIZE
);
929 if (infoPtr
->minHeight
& 1) infoPtr
->minHeight
--;
931 STATUSBAR_NotifyFormat(infoPtr
, infoPtr
->Notify
, NF_REQUERY
);
933 ZeroMemory (&nclm
, sizeof(nclm
));
934 nclm
.cbSize
= sizeof(nclm
);
935 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0);
936 infoPtr
->hDefaultFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
938 GetClientRect (hwnd
, &rect
);
940 /* initialize simple case */
941 infoPtr
->part0
.bound
= rect
;
942 infoPtr
->part0
.text
= 0;
943 infoPtr
->part0
.x
= 0;
944 infoPtr
->part0
.style
= 0;
945 infoPtr
->part0
.hIcon
= 0;
947 /* initialize first part */
948 infoPtr
->parts
= Alloc (sizeof(STATUSWINDOWPART
));
949 if (!infoPtr
->parts
) goto create_fail
;
950 infoPtr
->parts
[0].bound
= rect
;
951 infoPtr
->parts
[0].text
= 0;
952 infoPtr
->parts
[0].x
= -1;
953 infoPtr
->parts
[0].style
= 0;
954 infoPtr
->parts
[0].hIcon
= 0;
956 OpenThemeData (hwnd
, themeClass
);
958 if (lpCreate
->lpszName
&& (len
= strlenW ((LPCWSTR
)lpCreate
->lpszName
)))
960 infoPtr
->parts
[0].text
= Alloc ((len
+ 1)*sizeof(WCHAR
));
961 if (!infoPtr
->parts
[0].text
) goto create_fail
;
962 strcpyW (infoPtr
->parts
[0].text
, (LPCWSTR
)lpCreate
->lpszName
);
965 dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
966 /* native seems to clear WS_BORDER, too */
967 dwStyle
&= ~WS_BORDER
;
968 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
970 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
972 if (dwStyle
& SBT_TOOLTIPS
) {
973 infoPtr
->hwndToolTip
=
974 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
| TTS_ALWAYSTIP
,
975 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
976 CW_USEDEFAULT
, hwnd
, 0,
977 (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
), NULL
);
979 if (infoPtr
->hwndToolTip
) {
980 NMTOOLTIPSCREATED nmttc
;
982 nmttc
.hdr
.hwndFrom
= hwnd
;
983 nmttc
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
984 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
985 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
987 SendMessageW (lpCreate
->hwndParent
, WM_NOTIFY
, nmttc
.hdr
.idFrom
, (LPARAM
)&nmttc
);
995 if (infoPtr
) STATUSBAR_WMDestroy(infoPtr
);
1000 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
1001 * of the first part only (usual behaviour) */
1003 STATUSBAR_WMGetText (const STATUS_INFO
*infoPtr
, INT size
, LPWSTR buf
)
1008 if (!(infoPtr
->parts
[0].text
))
1011 len
= strlenW (infoPtr
->parts
[0].text
);
1015 else if (size
> len
) {
1016 strcpyW (buf
, infoPtr
->parts
[0].text
);
1020 memcpy (buf
, infoPtr
->parts
[0].text
, (size
- 1) * sizeof(WCHAR
));
1028 STATUSBAR_WMNCHitTest (const STATUS_INFO
*infoPtr
, INT x
, INT y
)
1030 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
) {
1034 GetClientRect (infoPtr
->Self
, &rect
);
1038 ScreenToClient (infoPtr
->Self
, &pt
);
1040 rect
.left
= rect
.right
- 13;
1043 if (PtInRect (&rect
, pt
))
1045 if (GetWindowLongW( infoPtr
->Self
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) return HTBOTTOMLEFT
;
1046 else return HTBOTTOMRIGHT
;
1055 STATUSBAR_WMPaint (STATUS_INFO
*infoPtr
, HDC hdc
)
1060 if (hdc
) return STATUSBAR_Refresh (infoPtr
, hdc
);
1061 hdc
= BeginPaint (infoPtr
->Self
, &ps
);
1062 STATUSBAR_Refresh (infoPtr
, hdc
);
1063 EndPaint (infoPtr
->Self
, &ps
);
1070 STATUSBAR_WMSetFont (STATUS_INFO
*infoPtr
, HFONT font
, BOOL redraw
)
1072 infoPtr
->hFont
= font
;
1073 TRACE("%p\n", infoPtr
->hFont
);
1075 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
1076 SendMessageW(infoPtr
->Self
, WM_SIZE
, 0, 0); /* update size */
1078 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
1085 STATUSBAR_WMSetText (const STATUS_INFO
*infoPtr
, LPCSTR text
)
1087 STATUSWINDOWPART
*part
;
1091 if (infoPtr
->numParts
== 0)
1094 part
= &infoPtr
->parts
[0];
1095 /* duplicate string */
1099 if (text
&& (len
= strlenW((LPCWSTR
)text
))) {
1100 part
->text
= Alloc ((len
+1)*sizeof(WCHAR
));
1101 if (!part
->text
) return FALSE
;
1102 strcpyW (part
->text
, (LPCWSTR
)text
);
1105 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
1112 STATUSBAR_WMSize (STATUS_INFO
*infoPtr
, WORD flags
)
1117 /* Need to resize width to match parent */
1118 TRACE("flags %04x\n", flags
);
1120 if (flags
!= SIZE_RESTORED
&& flags
!= SIZE_MAXIMIZED
) {
1121 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1125 if (GetWindowLongW(infoPtr
->Self
, GWL_STYLE
) & CCS_NORESIZE
) return FALSE
;
1127 /* width and height don't apply */
1128 if (!GetClientRect (infoPtr
->Notify
, &parent_rect
))
1131 width
= parent_rect
.right
- parent_rect
.left
;
1132 x
= parent_rect
.left
;
1133 y
= parent_rect
.bottom
- infoPtr
->height
;
1134 MoveWindow (infoPtr
->Self
, x
, y
, width
, infoPtr
->height
, TRUE
);
1135 STATUSBAR_SetPartBounds (infoPtr
);
1140 /* update theme after a WM_THEMECHANGED message */
1141 static LRESULT
theme_changed (const STATUS_INFO
* infoPtr
)
1143 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
1144 CloseThemeData (theme
);
1145 OpenThemeData (infoPtr
->Self
, themeClass
);
1151 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
)
1153 if (cmd
== NF_REQUERY
) {
1154 INT i
= SendMessageW(from
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->Self
, NF_QUERY
);
1155 infoPtr
->bUnicode
= (i
== NFR_UNICODE
);
1157 return infoPtr
->bUnicode
? NFR_UNICODE
: NFR_ANSI
;
1162 STATUSBAR_SendMouseNotify(const STATUS_INFO
*infoPtr
, UINT code
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1166 TRACE("code %04x, lParam=%lx\n", code
, lParam
);
1167 nm
.hdr
.hwndFrom
= infoPtr
->Self
;
1168 nm
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->Self
, GWLP_ID
);
1170 nm
.pt
.x
= (short)LOWORD(lParam
);
1171 nm
.pt
.y
= (short)HIWORD(lParam
);
1172 nm
.dwItemSpec
= STATUSBAR_InternalHitTest(infoPtr
, &nm
.pt
);
1174 nm
.dwHitInfo
= 0x30000; /* seems constant */
1176 /* Do default processing if WM_NOTIFY returns zero */
1177 if(!SendMessageW(infoPtr
->Notify
, WM_NOTIFY
, nm
.hdr
.idFrom
, (LPARAM
)&nm
))
1179 return DefWindowProcW(infoPtr
->Self
, msg
, wParam
, lParam
);
1186 static LRESULT WINAPI
1187 StatusWindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1189 STATUS_INFO
*infoPtr
= (STATUS_INFO
*)GetWindowLongPtrW (hwnd
, 0);
1190 INT nPart
= ((INT
) wParam
) & 0x00ff;
1193 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1194 if (!infoPtr
&& msg
!= WM_CREATE
)
1195 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1199 return STATUSBAR_GetBorders (infoPtr
, (INT
*)lParam
);
1202 return (LRESULT
)STATUSBAR_GetIcon (infoPtr
, nPart
);
1205 return STATUSBAR_GetParts (infoPtr
, (INT
)wParam
, (INT
*)lParam
);
1208 return STATUSBAR_GetRect (infoPtr
, nPart
, (LPRECT
)lParam
);
1211 return STATUSBAR_GetTextA (infoPtr
, nPart
, (LPSTR
)lParam
);
1214 return STATUSBAR_GetTextW (infoPtr
, nPart
, (LPWSTR
)lParam
);
1216 case SB_GETTEXTLENGTHA
:
1217 case SB_GETTEXTLENGTHW
:
1218 return STATUSBAR_GetTextLength (infoPtr
, nPart
);
1220 case SB_GETTIPTEXTA
:
1221 return STATUSBAR_GetTipTextA (infoPtr
, LOWORD(wParam
), (LPSTR
)lParam
, HIWORD(wParam
));
1223 case SB_GETTIPTEXTW
:
1224 return STATUSBAR_GetTipTextW (infoPtr
, LOWORD(wParam
), (LPWSTR
)lParam
, HIWORD(wParam
));
1226 case SB_GETUNICODEFORMAT
:
1227 return infoPtr
->bUnicode
;
1230 return infoPtr
->simple
;
1233 return STATUSBAR_SetBorders (infoPtr
, (INT
*)lParam
);
1236 return STATUSBAR_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1239 return STATUSBAR_SetIcon (infoPtr
, nPart
, (HICON
)lParam
);
1241 case SB_SETMINHEIGHT
:
1242 return STATUSBAR_SetMinHeight (infoPtr
, (INT
)wParam
);
1245 return STATUSBAR_SetParts (infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
1248 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, FALSE
);
1251 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, TRUE
);
1253 case SB_SETTIPTEXTA
:
1254 return STATUSBAR_SetTipTextA (infoPtr
, (INT
)wParam
, (LPSTR
)lParam
);
1256 case SB_SETTIPTEXTW
:
1257 return STATUSBAR_SetTipTextW (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1259 case SB_SETUNICODEFORMAT
:
1260 return STATUSBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1263 return STATUSBAR_Simple (infoPtr
, (BOOL
)wParam
);
1266 return STATUSBAR_WMCreate (hwnd
, (LPCREATESTRUCTA
)lParam
);
1269 return STATUSBAR_WMDestroy (infoPtr
);
1272 return (LRESULT
)(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
1275 return STATUSBAR_WMGetText (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1277 case WM_GETTEXTLENGTH
:
1278 return LOWORD(STATUSBAR_GetTextLength (infoPtr
, 0));
1280 case WM_LBUTTONDBLCLK
:
1281 return STATUSBAR_SendMouseNotify(infoPtr
, NM_DBLCLK
, msg
, wParam
, lParam
);
1284 return STATUSBAR_SendMouseNotify(infoPtr
, NM_CLICK
, msg
, wParam
, lParam
);
1287 return STATUSBAR_Relay2Tip (infoPtr
, msg
, wParam
, lParam
);
1290 res
= STATUSBAR_WMNCHitTest(infoPtr
, (short)LOWORD(lParam
),
1291 (short)HIWORD(lParam
));
1292 if (res
!= HTERROR
) return res
;
1293 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1295 case WM_NCLBUTTONUP
:
1296 case WM_NCLBUTTONDOWN
:
1297 PostMessageW (infoPtr
->Notify
, msg
, wParam
, lParam
);
1300 case WM_NOTIFYFORMAT
:
1301 return STATUSBAR_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
1303 case WM_PRINTCLIENT
:
1305 return STATUSBAR_WMPaint (infoPtr
, (HDC
)wParam
);
1307 case WM_RBUTTONDBLCLK
:
1308 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RDBLCLK
, msg
, wParam
, lParam
);
1311 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RCLICK
, msg
, wParam
, lParam
);
1314 return STATUSBAR_WMSetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
1317 return STATUSBAR_WMSetText (infoPtr
, (LPCSTR
)lParam
);
1320 if (STATUSBAR_WMSize (infoPtr
, (WORD
)wParam
)) return 0;
1321 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1323 case WM_SYSCOLORCHANGE
:
1324 COMCTL32_RefreshSysColors();
1327 case WM_THEMECHANGED
:
1328 return theme_changed (infoPtr
);
1331 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
1332 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1333 msg
, wParam
, lParam
);
1334 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1339 /***********************************************************************
1340 * STATUS_Register [Internal]
1342 * Registers the status window class.
1346 STATUS_Register (void)
1350 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1351 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
;
1352 wndClass
.lpfnWndProc
= StatusWindowProc
;
1353 wndClass
.cbClsExtra
= 0;
1354 wndClass
.cbWndExtra
= sizeof(STATUS_INFO
*);
1355 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1356 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1357 wndClass
.lpszClassName
= STATUSCLASSNAMEW
;
1359 RegisterClassW (&wndClass
);
1363 /***********************************************************************
1364 * STATUS_Unregister [Internal]
1366 * Unregisters the status window class.
1370 STATUS_Unregister (void)
1372 UnregisterClassW (STATUSCLASSNAMEW
, NULL
);