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
);
130 memset (&r
, 0, sizeof (r
));
131 r
.bottom
= 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
)
146 HPEN hPenFace
, hPenShadow
, hPenHighlight
, hOldPen
;
150 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect
));
156 gripperRect
= *lpRect
;
157 if (SUCCEEDED (GetThemePartSize (theme
, hdc
, SP_GRIPPER
, 0, lpRect
,
158 TS_DRAW
, &gripperSize
)))
160 gripperRect
.left
= gripperRect
.right
- gripperSize
.cx
;
161 gripperRect
.top
= gripperRect
.bottom
- gripperSize
.cy
;
162 if (SUCCEEDED (DrawThemeBackground(theme
, hdc
, SP_GRIPPER
, 0, &gripperRect
, NULL
)))
167 pt
.x
= lpRect
->right
- 1;
168 pt
.y
= lpRect
->bottom
- 1;
170 hPenFace
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
);
171 hOldPen
= SelectObject( hdc
, hPenFace
);
172 MoveToEx (hdc
, pt
.x
- 12, pt
.y
, NULL
);
173 LineTo (hdc
, pt
.x
, pt
.y
);
174 LineTo (hdc
, pt
.x
, pt
.y
- 13);
179 hPenShadow
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dShadow
);
180 SelectObject( hdc
, hPenShadow
);
181 for (i
= 1; i
< 11; i
+= 4) {
182 MoveToEx (hdc
, pt
.x
- i
, pt
.y
, NULL
);
183 LineTo (hdc
, pt
.x
+ 1, pt
.y
- i
- 1);
185 MoveToEx (hdc
, pt
.x
- i
- 1, pt
.y
, NULL
);
186 LineTo (hdc
, pt
.x
+ 1, pt
.y
- i
- 2);
189 hPenHighlight
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dHilight
);
190 SelectObject( hdc
, hPenHighlight
);
191 for (i
= 3; i
< 13; i
+= 4) {
192 MoveToEx (hdc
, pt
.x
- i
, pt
.y
, NULL
);
193 LineTo (hdc
, pt
.x
+ 1, pt
.y
- i
- 1);
196 SelectObject (hdc
, hOldPen
);
197 DeleteObject( hPenFace
);
198 DeleteObject( hPenShadow
);
199 DeleteObject( hPenHighlight
);
204 STATUSBAR_DrawPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
206 RECT r
= part
->bound
;
207 UINT border
= BDR_SUNKENOUTER
;
208 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
209 int themePart
= SP_PANE
;
212 TRACE("part bound %s\n", wine_dbgstr_rect(&r
));
213 if (part
->style
& SBT_POPOUT
)
214 border
= BDR_RAISEDOUTER
;
215 else if (part
->style
& SBT_NOBORDERS
)
220 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
221 && (infoPtr
->simple
|| (itemID
== (infoPtr
->numParts
-1))))
222 themePart
= SP_GRIPPERPANE
;
223 DrawThemeBackground(theme
, hdc
, themePart
, 0, &r
, NULL
);
226 DrawEdge(hdc
, &r
, border
, BF_RECT
|BF_ADJUST
);
229 INT cy
= r
.bottom
- r
.top
;
230 DrawIconEx (hdc
, r
.left
+ 2, r
.top
, part
->hIcon
, cy
, cy
, 0, 0, DI_NORMAL
);
234 if (part
->style
& SBT_OWNERDRAW
) {
237 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
239 dis
.hwndItem
= infoPtr
->Self
;
242 dis
.itemData
= (ULONG_PTR
)part
->text
;
243 SendMessageW (infoPtr
->Notify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
246 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
252 STATUSBAR_RefreshPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
257 TRACE("item %d\n", itemID
);
259 if (part
->bound
.right
< part
->bound
.left
) return;
261 if (!RectVisible(hdc
, &part
->bound
))
264 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
267 GetClientRect (infoPtr
->Self
, &cr
);
268 DrawThemeBackground(theme
, hdc
, 0, 0, &cr
, &part
->bound
);
272 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
273 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
275 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
276 FillRect(hdc
, &part
->bound
, hbrBk
);
277 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
278 DeleteObject (hbrBk
);
281 STATUSBAR_DrawPart (infoPtr
, hdc
, part
, itemID
);
286 STATUSBAR_Refresh (STATUS_INFO
*infoPtr
, HDC hdc
)
294 if (!IsWindowVisible(infoPtr
->Self
))
297 STATUSBAR_SetPartBounds(infoPtr
);
299 GetClientRect (infoPtr
->Self
, &rect
);
301 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
303 DrawThemeBackground(theme
, hdc
, 0, 0, &rect
, NULL
);
307 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
308 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
310 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
311 FillRect(hdc
, &rect
, hbrBk
);
312 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
313 DeleteObject (hbrBk
);
316 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
318 if (infoPtr
->simple
) {
319 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->part0
, 0);
323 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
324 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->parts
[i
], i
);
328 SelectObject (hdc
, hOldFont
);
330 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
331 STATUSBAR_DrawSizeGrip (theme
, hdc
, &rect
);
338 STATUSBAR_InternalHitTest(const STATUS_INFO
*infoPtr
, const POINT
*pt
)
345 for (i
= 0; i
< infoPtr
->numParts
; i
++)
346 if (pt
->x
>= infoPtr
->parts
[i
].bound
.left
&& pt
->x
<= infoPtr
->parts
[i
].bound
.right
)
353 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
)
355 STATUSWINDOWPART
*part
;
359 /* get our window size */
360 GetClientRect (infoPtr
->Self
, &rect
);
361 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect
));
363 rect
.left
+= infoPtr
->horizontalBorder
;
364 rect
.top
+= infoPtr
->verticalBorder
;
366 /* set bounds for simple rectangle */
367 infoPtr
->part0
.bound
= rect
;
369 /* set bounds for non-simple rectangles */
370 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
371 part
= &infoPtr
->parts
[i
];
372 r
= &infoPtr
->parts
[i
].bound
;
374 r
->bottom
= rect
.bottom
;
378 r
->left
= infoPtr
->parts
[i
-1].bound
.right
+ infoPtr
->horizontalGap
;
380 r
->right
= rect
.right
;
384 if (infoPtr
->hwndToolTip
) {
387 ti
.cbSize
= sizeof(TTTOOLINFOW
);
388 ti
.hwnd
= infoPtr
->Self
;
391 SendMessageW (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
,
399 STATUSBAR_Relay2Tip (const STATUS_INFO
*infoPtr
, UINT uMsg
,
400 WPARAM wParam
, LPARAM lParam
)
404 msg
.hwnd
= infoPtr
->Self
;
408 msg
.time
= GetMessageTime ();
409 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
410 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
412 return SendMessageW (infoPtr
->hwndToolTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
417 STATUSBAR_GetBorders (const STATUS_INFO
*infoPtr
, INT out
[])
420 out
[0] = infoPtr
->horizontalBorder
;
421 out
[1] = infoPtr
->verticalBorder
;
422 out
[2] = infoPtr
->horizontalGap
;
429 STATUSBAR_SetBorders (STATUS_INFO
*infoPtr
, const INT in
[])
432 infoPtr
->horizontalBorder
= in
[0];
433 infoPtr
->verticalBorder
= in
[1];
434 infoPtr
->horizontalGap
= in
[2];
435 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
442 STATUSBAR_GetIcon (const STATUS_INFO
*infoPtr
, INT nPart
)
444 TRACE("%d\n", nPart
);
445 /* MSDN says: "simple parts are indexed with -1" */
446 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
450 return (infoPtr
->part0
.hIcon
);
452 return (infoPtr
->parts
[nPart
].hIcon
);
457 STATUSBAR_GetParts (const STATUS_INFO
*infoPtr
, INT num_parts
, INT parts
[])
461 TRACE("(%d)\n", num_parts
);
463 for (i
= 0; i
< num_parts
; i
++) {
464 parts
[i
] = infoPtr
->parts
[i
].x
;
467 return infoPtr
->numParts
;
472 STATUSBAR_GetRect (const STATUS_INFO
*infoPtr
, INT nPart
, LPRECT rect
)
474 TRACE("part %d\n", nPart
);
475 if(nPart
>= infoPtr
->numParts
|| nPart
< 0)
478 *rect
= infoPtr
->part0
.bound
;
480 *rect
= infoPtr
->parts
[nPart
].bound
;
486 STATUSBAR_GetTextA (STATUS_INFO
*infoPtr
, INT nPart
, LPSTR buf
)
488 STATUSWINDOWPART
*part
;
491 TRACE("part %d\n", nPart
);
493 /* MSDN says: "simple parts use index of 0", so this check is ok. */
494 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
497 part
= &infoPtr
->part0
;
499 part
= &infoPtr
->parts
[nPart
];
501 if (part
->style
& SBT_OWNERDRAW
)
502 result
= (LRESULT
)part
->text
;
504 DWORD len
= part
->text
? WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1,
505 NULL
, 0, NULL
, NULL
) - 1 : 0;
506 result
= MAKELONG( len
, part
->style
);
507 if (part
->text
&& buf
)
508 WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1, buf
, len
+1, NULL
, NULL
);
515 STATUSBAR_GetTextW (STATUS_INFO
*infoPtr
, INT nPart
, LPWSTR buf
)
517 STATUSWINDOWPART
*part
;
520 TRACE("part %d\n", nPart
);
521 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
524 part
= &infoPtr
->part0
;
526 part
= &infoPtr
->parts
[nPart
];
528 if (part
->style
& SBT_OWNERDRAW
)
529 result
= (LRESULT
)part
->text
;
531 result
= part
->text
? strlenW (part
->text
) : 0;
532 result
|= (part
->style
<< 16);
533 if (part
->text
&& buf
)
534 strcpyW (buf
, part
->text
);
541 STATUSBAR_GetTextLength (STATUS_INFO
*infoPtr
, INT nPart
)
543 STATUSWINDOWPART
*part
;
546 TRACE("part %d\n", nPart
);
548 /* MSDN says: "simple parts use index of 0", so this check is ok. */
549 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
552 part
= &infoPtr
->part0
;
554 part
= &infoPtr
->parts
[nPart
];
556 if ((~part
->style
& SBT_OWNERDRAW
) && part
->text
)
557 result
= strlenW(part
->text
);
561 result
|= (part
->style
<< 16);
566 STATUSBAR_GetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR tip
, INT size
)
570 CHAR buf
[INFOTIPSIZE
];
573 if (infoPtr
->hwndToolTip
) {
575 ti
.cbSize
= sizeof(TTTOOLINFOA
);
576 ti
.hwnd
= infoPtr
->Self
;
579 SendMessageA (infoPtr
->hwndToolTip
, TTM_GETTEXTA
, 0, (LPARAM
)&ti
);
581 lstrcpynA (tip
, buf
, size
);
588 STATUSBAR_GetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR tip
, INT size
)
592 WCHAR buf
[INFOTIPSIZE
];
595 if (infoPtr
->hwndToolTip
) {
597 ti
.cbSize
= sizeof(TTTOOLINFOW
);
598 ti
.hwnd
= infoPtr
->Self
;
601 SendMessageW(infoPtr
->hwndToolTip
, TTM_GETTEXTW
, 0, (LPARAM
)&ti
);
603 lstrcpynW(tip
, buf
, size
);
611 STATUSBAR_SetBkColor (STATUS_INFO
*infoPtr
, COLORREF color
)
615 oldBkColor
= infoPtr
->clrBk
;
616 infoPtr
->clrBk
= color
;
617 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
619 TRACE("CREF: %08x -> %08x\n", oldBkColor
, infoPtr
->clrBk
);
625 STATUSBAR_SetIcon (STATUS_INFO
*infoPtr
, INT nPart
, HICON hIcon
)
627 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
630 TRACE("setting part %d\n", nPart
);
632 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
634 if (infoPtr
->part0
.hIcon
== hIcon
) /* same as - no redraw */
636 infoPtr
->part0
.hIcon
= hIcon
;
638 InvalidateRect(infoPtr
->Self
, &infoPtr
->part0
.bound
, FALSE
);
640 if (infoPtr
->parts
[nPart
].hIcon
== hIcon
) /* same as - no redraw */
643 infoPtr
->parts
[nPart
].hIcon
= hIcon
;
644 if (!(infoPtr
->simple
))
645 InvalidateRect(infoPtr
->Self
, &infoPtr
->parts
[nPart
].bound
, FALSE
);
652 STATUSBAR_SetMinHeight (STATUS_INFO
*infoPtr
, INT height
)
654 DWORD ysize
= GetSystemMetrics(SM_CYSIZE
);
655 if (ysize
& 1) ysize
--;
656 infoPtr
->minHeight
= max(height
, ysize
);
657 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
658 /* like native, don't resize the control */
664 STATUSBAR_SetParts (STATUS_INFO
*infoPtr
, INT count
, LPINT parts
)
666 STATUSWINDOWPART
*tmp
;
669 TRACE("(%d,%p)\n", count
, parts
);
671 if(!count
) return FALSE
;
673 oldNumParts
= infoPtr
->numParts
;
674 infoPtr
->numParts
= count
;
675 if (oldNumParts
> infoPtr
->numParts
) {
676 for (i
= infoPtr
->numParts
; i
< oldNumParts
; i
++) {
677 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
678 Free (infoPtr
->parts
[i
].text
);
680 } else if (oldNumParts
< infoPtr
->numParts
) {
681 tmp
= Alloc (sizeof(STATUSWINDOWPART
) * infoPtr
->numParts
);
682 if (!tmp
) return FALSE
;
683 for (i
= 0; i
< oldNumParts
; i
++) {
684 tmp
[i
] = infoPtr
->parts
[i
];
686 Free (infoPtr
->parts
);
687 infoPtr
->parts
= tmp
;
689 if (oldNumParts
== infoPtr
->numParts
) {
690 for (i
=0; i
< oldNumParts
; i
++)
691 if (infoPtr
->parts
[i
].x
!= parts
[i
])
693 if (i
==oldNumParts
) /* Unchanged? no need to redraw! */
697 for (i
= 0; i
< infoPtr
->numParts
; i
++)
698 infoPtr
->parts
[i
].x
= parts
[i
];
700 if (infoPtr
->hwndToolTip
) {
705 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
706 ti
.cbSize
= sizeof(TTTOOLINFOW
);
707 ti
.hwnd
= infoPtr
->Self
;
708 ti
.lpszText
= &wEmpty
;
710 nTipCount
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETTOOLCOUNT
, 0, 0);
711 if (nTipCount
< infoPtr
->numParts
) {
713 for (i
= nTipCount
; i
< infoPtr
->numParts
; i
++) {
714 TRACE("add tool %d\n", i
);
716 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
720 else if (nTipCount
> infoPtr
->numParts
) {
722 for (i
= nTipCount
- 1; i
>= infoPtr
->numParts
; i
--) {
723 TRACE("delete tool %d\n", i
);
725 SendMessageW (infoPtr
->hwndToolTip
, TTM_DELTOOLW
,
730 STATUSBAR_SetPartBounds (infoPtr
);
731 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
737 STATUSBAR_SetTextT (STATUS_INFO
*infoPtr
, INT nPart
, WORD style
,
738 LPWSTR text
, BOOL isW
)
740 STATUSWINDOWPART
*part
=NULL
;
741 BOOL changed
= FALSE
;
744 if (style
& SBT_OWNERDRAW
) {
745 TRACE("part %d, text %p\n",nPart
,text
);
747 else TRACE("part %d, text %s\n", nPart
, debugstr_t(text
, isW
));
749 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
750 * window is assumed to be a simple window */
752 if (nPart
== 0x00ff) {
753 part
= &infoPtr
->part0
;
755 if (infoPtr
->parts
&& nPart
>= 0 && nPart
< infoPtr
->numParts
) {
756 part
= &infoPtr
->parts
[nPart
];
759 if (!part
) return FALSE
;
761 if (part
->style
!= style
)
764 oldStyle
= part
->style
;
766 if (style
& SBT_OWNERDRAW
) {
767 if (!(oldStyle
& SBT_OWNERDRAW
))
775 LPCSTR atxt
= (LPCSTR
)text
;
776 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, NULL
, 0 );
777 ntext
= Alloc( (len
+ 1)*sizeof(WCHAR
) );
778 if (!ntext
) return FALSE
;
779 MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, ntext
, len
);
781 ntext
= Alloc( (strlenW(text
) + 1)*sizeof(WCHAR
) );
782 if (!ntext
) return FALSE
;
783 strcpyW (ntext
, text
);
786 /* replace nonprintable characters with spaces */
796 /* check if text is unchanged -> no need to redraw */
798 if (!changed
&& part
->text
&& !lstrcmpW(ntext
, part
->text
)) {
803 if (!changed
&& !part
->text
)
807 if (!(oldStyle
& SBT_OWNERDRAW
))
811 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
812 UpdateWindow(infoPtr
->Self
);
819 STATUSBAR_SetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR text
)
821 TRACE("part %d: \"%s\"\n", id
, text
);
822 if (infoPtr
->hwndToolTip
) {
824 ti
.cbSize
= sizeof(TTTOOLINFOA
);
825 ti
.hwnd
= infoPtr
->Self
;
829 SendMessageA (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTA
, 0, (LPARAM
)&ti
);
837 STATUSBAR_SetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR text
)
839 TRACE("part %d: \"%s\"\n", id
, debugstr_w(text
));
840 if (infoPtr
->hwndToolTip
) {
842 ti
.cbSize
= sizeof(TTTOOLINFOW
);
843 ti
.hwnd
= infoPtr
->Self
;
847 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
854 static inline LRESULT
855 STATUSBAR_SetUnicodeFormat (STATUS_INFO
*infoPtr
, BOOL bUnicode
)
857 BOOL bOld
= infoPtr
->bUnicode
;
859 TRACE("(0x%x)\n", bUnicode
);
860 infoPtr
->bUnicode
= bUnicode
;
867 STATUSBAR_Simple (STATUS_INFO
*infoPtr
, BOOL simple
)
871 TRACE("(simple=%d)\n", simple
);
872 if (infoPtr
->simple
== simple
) /* no need to change */
875 infoPtr
->simple
= simple
;
877 /* send notification */
878 nmhdr
.hwndFrom
= infoPtr
->Self
;
879 nmhdr
.idFrom
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
880 nmhdr
.code
= SBN_SIMPLEMODECHANGE
;
881 SendMessageW (infoPtr
->Notify
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
882 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
888 STATUSBAR_WMDestroy (STATUS_INFO
*infoPtr
)
893 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
894 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
895 Free (infoPtr
->parts
[i
].text
);
897 if (!(infoPtr
->part0
.style
& SBT_OWNERDRAW
))
898 Free (infoPtr
->part0
.text
);
899 Free (infoPtr
->parts
);
901 /* delete default font */
902 if (infoPtr
->hDefaultFont
)
903 DeleteObject (infoPtr
->hDefaultFont
);
905 /* delete tool tip control */
906 if (infoPtr
->hwndToolTip
)
907 DestroyWindow (infoPtr
->hwndToolTip
);
909 CloseThemeData (GetWindowTheme (infoPtr
->Self
));
911 SetWindowLongPtrW(infoPtr
->Self
, 0, 0);
918 STATUSBAR_WMCreate (HWND hwnd
, const CREATESTRUCTA
*lpCreate
)
920 STATUS_INFO
*infoPtr
;
921 NONCLIENTMETRICSW nclm
;
927 infoPtr
= Alloc (sizeof(STATUS_INFO
));
928 if (!infoPtr
) goto create_fail
;
929 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
931 infoPtr
->Self
= hwnd
;
932 infoPtr
->Notify
= lpCreate
->hwndParent
;
933 infoPtr
->numParts
= 1;
935 infoPtr
->simple
= FALSE
;
936 infoPtr
->clrBk
= CLR_DEFAULT
;
938 infoPtr
->horizontalBorder
= HORZ_BORDER
;
939 infoPtr
->verticalBorder
= VERT_BORDER
;
940 infoPtr
->horizontalGap
= HORZ_GAP
;
941 infoPtr
->minHeight
= GetSystemMetrics(SM_CYSIZE
);
942 if (infoPtr
->minHeight
& 1) infoPtr
->minHeight
--;
944 STATUSBAR_NotifyFormat(infoPtr
, infoPtr
->Notify
, NF_REQUERY
);
946 ZeroMemory (&nclm
, sizeof(nclm
));
947 nclm
.cbSize
= sizeof(nclm
);
948 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0);
949 infoPtr
->hDefaultFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
951 GetClientRect (hwnd
, &rect
);
953 /* initialize simple case */
954 infoPtr
->part0
.bound
= rect
;
955 infoPtr
->part0
.text
= 0;
956 infoPtr
->part0
.x
= 0;
957 infoPtr
->part0
.style
= 0;
958 infoPtr
->part0
.hIcon
= 0;
960 /* initialize first part */
961 infoPtr
->parts
= Alloc (sizeof(STATUSWINDOWPART
));
962 if (!infoPtr
->parts
) goto create_fail
;
963 infoPtr
->parts
[0].bound
= rect
;
964 infoPtr
->parts
[0].text
= 0;
965 infoPtr
->parts
[0].x
= -1;
966 infoPtr
->parts
[0].style
= 0;
967 infoPtr
->parts
[0].hIcon
= 0;
969 OpenThemeData (hwnd
, themeClass
);
971 if (lpCreate
->lpszName
&& (len
= strlenW ((LPCWSTR
)lpCreate
->lpszName
)))
973 infoPtr
->parts
[0].text
= Alloc ((len
+ 1)*sizeof(WCHAR
));
974 if (!infoPtr
->parts
[0].text
) goto create_fail
;
975 strcpyW (infoPtr
->parts
[0].text
, (LPCWSTR
)lpCreate
->lpszName
);
978 dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
979 /* native seems to clear WS_BORDER, too */
980 dwStyle
&= ~WS_BORDER
;
981 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
983 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
985 if (dwStyle
& SBT_TOOLTIPS
) {
986 infoPtr
->hwndToolTip
=
987 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
| TTS_ALWAYSTIP
,
988 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
989 CW_USEDEFAULT
, hwnd
, 0,
990 (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
), NULL
);
992 if (infoPtr
->hwndToolTip
) {
993 NMTOOLTIPSCREATED nmttc
;
995 nmttc
.hdr
.hwndFrom
= hwnd
;
996 nmttc
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
997 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
998 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
1000 SendMessageW (lpCreate
->hwndParent
, WM_NOTIFY
, nmttc
.hdr
.idFrom
, (LPARAM
)&nmttc
);
1007 TRACE(" failed!\n");
1008 if (infoPtr
) STATUSBAR_WMDestroy(infoPtr
);
1013 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
1014 * of the first part only (usual behaviour) */
1016 STATUSBAR_WMGetText (const STATUS_INFO
*infoPtr
, INT size
, LPWSTR buf
)
1021 if (!(infoPtr
->parts
[0].text
))
1024 len
= strlenW (infoPtr
->parts
[0].text
);
1028 else if (size
> len
) {
1029 strcpyW (buf
, infoPtr
->parts
[0].text
);
1033 memcpy (buf
, infoPtr
->parts
[0].text
, (size
- 1) * sizeof(WCHAR
));
1041 STATUSBAR_WMNCHitTest (const STATUS_INFO
*infoPtr
, INT x
, INT y
)
1043 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
) {
1047 GetClientRect (infoPtr
->Self
, &rect
);
1051 ScreenToClient (infoPtr
->Self
, &pt
);
1053 rect
.left
= rect
.right
- 13;
1056 if (PtInRect (&rect
, pt
))
1058 if (GetWindowLongW( infoPtr
->Self
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) return HTBOTTOMLEFT
;
1059 else return HTBOTTOMRIGHT
;
1068 STATUSBAR_WMPaint (STATUS_INFO
*infoPtr
, HDC hdc
)
1073 if (hdc
) return STATUSBAR_Refresh (infoPtr
, hdc
);
1074 hdc
= BeginPaint (infoPtr
->Self
, &ps
);
1075 STATUSBAR_Refresh (infoPtr
, hdc
);
1076 EndPaint (infoPtr
->Self
, &ps
);
1083 STATUSBAR_WMSetFont (STATUS_INFO
*infoPtr
, HFONT font
, BOOL redraw
)
1085 infoPtr
->hFont
= font
;
1086 TRACE("%p\n", infoPtr
->hFont
);
1088 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
1089 SendMessageW(infoPtr
->Self
, WM_SIZE
, 0, 0); /* update size */
1091 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
1098 STATUSBAR_WMSetText (const STATUS_INFO
*infoPtr
, LPCSTR text
)
1100 STATUSWINDOWPART
*part
;
1104 if (infoPtr
->numParts
== 0)
1107 part
= &infoPtr
->parts
[0];
1108 /* duplicate string */
1112 if (text
&& (len
= strlenW((LPCWSTR
)text
))) {
1113 part
->text
= Alloc ((len
+1)*sizeof(WCHAR
));
1114 if (!part
->text
) return FALSE
;
1115 strcpyW (part
->text
, (LPCWSTR
)text
);
1118 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
1125 STATUSBAR_WMSize (STATUS_INFO
*infoPtr
, WORD flags
)
1130 /* Need to resize width to match parent */
1131 TRACE("flags %04x\n", flags
);
1133 if (flags
!= SIZE_RESTORED
&& flags
!= SIZE_MAXIMIZED
) {
1134 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1138 if (GetWindowLongW(infoPtr
->Self
, GWL_STYLE
) & CCS_NORESIZE
) return FALSE
;
1140 /* width and height don't apply */
1141 if (!GetClientRect (infoPtr
->Notify
, &parent_rect
))
1144 width
= parent_rect
.right
- parent_rect
.left
;
1145 x
= parent_rect
.left
;
1146 y
= parent_rect
.bottom
- infoPtr
->height
;
1147 MoveWindow (infoPtr
->Self
, x
, y
, width
, infoPtr
->height
, TRUE
);
1148 STATUSBAR_SetPartBounds (infoPtr
);
1153 /* update theme after a WM_THEMECHANGED message */
1154 static LRESULT
theme_changed (const STATUS_INFO
* infoPtr
)
1156 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
1157 CloseThemeData (theme
);
1158 OpenThemeData (infoPtr
->Self
, themeClass
);
1164 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
)
1166 if (cmd
== NF_REQUERY
) {
1167 INT i
= SendMessageW(from
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->Self
, NF_QUERY
);
1168 infoPtr
->bUnicode
= (i
== NFR_UNICODE
);
1170 return infoPtr
->bUnicode
? NFR_UNICODE
: NFR_ANSI
;
1175 STATUSBAR_SendMouseNotify(const STATUS_INFO
*infoPtr
, UINT code
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1179 TRACE("code %04x, lParam=%lx\n", code
, lParam
);
1180 nm
.hdr
.hwndFrom
= infoPtr
->Self
;
1181 nm
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->Self
, GWLP_ID
);
1183 nm
.pt
.x
= (short)LOWORD(lParam
);
1184 nm
.pt
.y
= (short)HIWORD(lParam
);
1185 nm
.dwItemSpec
= STATUSBAR_InternalHitTest(infoPtr
, &nm
.pt
);
1187 nm
.dwHitInfo
= 0x30000; /* seems constant */
1189 /* Do default processing if WM_NOTIFY returns zero */
1190 if(!SendMessageW(infoPtr
->Notify
, WM_NOTIFY
, nm
.hdr
.idFrom
, (LPARAM
)&nm
))
1192 return DefWindowProcW(infoPtr
->Self
, msg
, wParam
, lParam
);
1199 static LRESULT WINAPI
1200 StatusWindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1202 STATUS_INFO
*infoPtr
= (STATUS_INFO
*)GetWindowLongPtrW (hwnd
, 0);
1203 INT nPart
= ((INT
) wParam
) & 0x00ff;
1206 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1207 if (!infoPtr
&& msg
!= WM_CREATE
)
1208 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1212 return STATUSBAR_GetBorders (infoPtr
, (INT
*)lParam
);
1215 return (LRESULT
)STATUSBAR_GetIcon (infoPtr
, nPart
);
1218 return STATUSBAR_GetParts (infoPtr
, (INT
)wParam
, (INT
*)lParam
);
1221 return STATUSBAR_GetRect (infoPtr
, nPart
, (LPRECT
)lParam
);
1224 return STATUSBAR_GetTextA (infoPtr
, nPart
, (LPSTR
)lParam
);
1227 return STATUSBAR_GetTextW (infoPtr
, nPart
, (LPWSTR
)lParam
);
1229 case SB_GETTEXTLENGTHA
:
1230 case SB_GETTEXTLENGTHW
:
1231 return STATUSBAR_GetTextLength (infoPtr
, nPart
);
1233 case SB_GETTIPTEXTA
:
1234 return STATUSBAR_GetTipTextA (infoPtr
, LOWORD(wParam
), (LPSTR
)lParam
, HIWORD(wParam
));
1236 case SB_GETTIPTEXTW
:
1237 return STATUSBAR_GetTipTextW (infoPtr
, LOWORD(wParam
), (LPWSTR
)lParam
, HIWORD(wParam
));
1239 case SB_GETUNICODEFORMAT
:
1240 return infoPtr
->bUnicode
;
1243 return infoPtr
->simple
;
1246 return STATUSBAR_SetBorders (infoPtr
, (INT
*)lParam
);
1249 return STATUSBAR_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1252 return STATUSBAR_SetIcon (infoPtr
, nPart
, (HICON
)lParam
);
1254 case SB_SETMINHEIGHT
:
1255 return STATUSBAR_SetMinHeight (infoPtr
, (INT
)wParam
);
1258 return STATUSBAR_SetParts (infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
1261 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, FALSE
);
1264 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, TRUE
);
1266 case SB_SETTIPTEXTA
:
1267 return STATUSBAR_SetTipTextA (infoPtr
, (INT
)wParam
, (LPSTR
)lParam
);
1269 case SB_SETTIPTEXTW
:
1270 return STATUSBAR_SetTipTextW (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1272 case SB_SETUNICODEFORMAT
:
1273 return STATUSBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1276 return STATUSBAR_Simple (infoPtr
, (BOOL
)wParam
);
1279 return STATUSBAR_WMCreate (hwnd
, (LPCREATESTRUCTA
)lParam
);
1282 return STATUSBAR_WMDestroy (infoPtr
);
1285 return (LRESULT
)(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
1288 return STATUSBAR_WMGetText (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1290 case WM_GETTEXTLENGTH
:
1291 return LOWORD(STATUSBAR_GetTextLength (infoPtr
, 0));
1293 case WM_LBUTTONDBLCLK
:
1294 return STATUSBAR_SendMouseNotify(infoPtr
, NM_DBLCLK
, msg
, wParam
, lParam
);
1297 return STATUSBAR_SendMouseNotify(infoPtr
, NM_CLICK
, msg
, wParam
, lParam
);
1300 return STATUSBAR_Relay2Tip (infoPtr
, msg
, wParam
, lParam
);
1303 res
= STATUSBAR_WMNCHitTest(infoPtr
, (short)LOWORD(lParam
),
1304 (short)HIWORD(lParam
));
1305 if (res
!= HTERROR
) return res
;
1306 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1308 case WM_NCLBUTTONUP
:
1309 case WM_NCLBUTTONDOWN
:
1310 PostMessageW (infoPtr
->Notify
, msg
, wParam
, lParam
);
1313 case WM_NOTIFYFORMAT
:
1314 return STATUSBAR_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
1316 case WM_PRINTCLIENT
:
1318 return STATUSBAR_WMPaint (infoPtr
, (HDC
)wParam
);
1320 case WM_RBUTTONDBLCLK
:
1321 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RDBLCLK
, msg
, wParam
, lParam
);
1324 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RCLICK
, msg
, wParam
, lParam
);
1327 return STATUSBAR_WMSetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
1330 return STATUSBAR_WMSetText (infoPtr
, (LPCSTR
)lParam
);
1333 if (STATUSBAR_WMSize (infoPtr
, (WORD
)wParam
)) return 0;
1334 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1336 case WM_SYSCOLORCHANGE
:
1337 COMCTL32_RefreshSysColors();
1340 case WM_THEMECHANGED
:
1341 return theme_changed (infoPtr
);
1344 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
1345 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1346 msg
, wParam
, lParam
);
1347 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1352 /***********************************************************************
1353 * STATUS_Register [Internal]
1355 * Registers the status window class.
1359 STATUS_Register (void)
1363 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1364 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
;
1365 wndClass
.lpfnWndProc
= StatusWindowProc
;
1366 wndClass
.cbClsExtra
= 0;
1367 wndClass
.cbWndExtra
= sizeof(STATUS_INFO
*);
1368 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1369 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1370 wndClass
.lpszClassName
= STATUSCLASSNAMEW
;
1372 RegisterClassW (&wndClass
);
1376 /***********************************************************************
1377 * STATUS_Unregister [Internal]
1379 * Unregisters the status window class.
1383 STATUS_Unregister (void)
1385 UnregisterClassW (STATUSCLASSNAMEW
, NULL
);