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"
55 //#include "vssym32.h"
57 #include "wine/debug.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(statusbar
);
76 UINT minHeight
; /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
81 COLORREF clrBk
; /* background color */
82 BOOL bUnicode
; /* notify format. TRUE if notifies in Unicode */
83 STATUSWINDOWPART part0
; /* simple window */
84 STATUSWINDOWPART
* parts
;
91 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
92 * The second cdrom contains executables drawstat.exe, gettext.exe,
93 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
100 static const WCHAR themeClass
[] = { 'S','t','a','t','u','s',0 };
104 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
);
106 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
);
108 static inline LPCSTR
debugstr_t(LPCWSTR text
, BOOL isW
)
110 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
114 STATUSBAR_ComputeHeight(STATUS_INFO
*infoPtr
)
121 COMCTL32_GetFontMetrics(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
, &tm
);
122 margin
= (tm
.tmInternalLeading
? tm
.tmInternalLeading
: 2);
123 height
= max(tm
.tmHeight
+ margin
+ 2*GetSystemMetrics(SM_CYBORDER
), infoPtr
->minHeight
) + infoPtr
->verticalBorder
;
125 if ((theme
= GetWindowTheme(infoPtr
->Self
)))
127 /* Determine bar height from theme such that the content area is
128 * textHeight pixels large */
129 HDC hdc
= GetDC(infoPtr
->Self
);
131 memset (&r
, 0, sizeof (r
));
132 r
.bottom
= max(infoPtr
->minHeight
, tm
.tmHeight
);
133 if (SUCCEEDED(GetThemeBackgroundExtent(theme
, hdc
, SP_PANE
, 0, &r
, &r
)))
135 height
= r
.bottom
- r
.top
;
137 ReleaseDC(infoPtr
->Self
, hdc
);
140 TRACE(" textHeight=%d+%d, final height=%d\n", tm
.tmHeight
, tm
.tmInternalLeading
, height
);
145 STATUSBAR_DrawSizeGrip (HTHEME theme
, HDC hdc
, LPRECT lpRect
)
147 HPEN hPenFace
, hPenShadow
, hPenHighlight
, hOldPen
;
151 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect
));
157 gripperRect
= *lpRect
;
158 if (SUCCEEDED (GetThemePartSize (theme
, hdc
, SP_GRIPPER
, 0, lpRect
,
159 TS_DRAW
, &gripperSize
)))
161 gripperRect
.left
= gripperRect
.right
- gripperSize
.cx
;
162 gripperRect
.top
= gripperRect
.bottom
- gripperSize
.cy
;
163 if (SUCCEEDED (DrawThemeBackground(theme
, hdc
, SP_GRIPPER
, 0, &gripperRect
, NULL
)))
168 pt
.x
= lpRect
->right
- 1;
169 pt
.y
= lpRect
->bottom
- 1;
171 hPenFace
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
);
172 hOldPen
= SelectObject( hdc
, hPenFace
);
173 MoveToEx (hdc
, pt
.x
- 12, pt
.y
, NULL
);
174 LineTo (hdc
, pt
.x
, pt
.y
);
175 LineTo (hdc
, pt
.x
, pt
.y
- 13);
180 hPenShadow
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dShadow
);
181 SelectObject( hdc
, hPenShadow
);
182 for (i
= 1; i
< 11; i
+= 4) {
183 MoveToEx (hdc
, pt
.x
- i
, pt
.y
, NULL
);
184 LineTo (hdc
, pt
.x
+ 1, pt
.y
- i
- 1);
186 MoveToEx (hdc
, pt
.x
- i
- 1, pt
.y
, NULL
);
187 LineTo (hdc
, pt
.x
+ 1, pt
.y
- i
- 2);
190 hPenHighlight
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dHilight
);
191 SelectObject( hdc
, hPenHighlight
);
192 for (i
= 3; i
< 13; i
+= 4) {
193 MoveToEx (hdc
, pt
.x
- i
, pt
.y
, NULL
);
194 LineTo (hdc
, pt
.x
+ 1, pt
.y
- i
- 1);
197 SelectObject (hdc
, hOldPen
);
198 DeleteObject( hPenFace
);
199 DeleteObject( hPenShadow
);
200 DeleteObject( hPenHighlight
);
205 STATUSBAR_DrawPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
207 RECT r
= part
->bound
;
208 UINT border
= BDR_SUNKENOUTER
;
209 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
210 int themePart
= SP_PANE
;
213 TRACE("part bound %s\n", wine_dbgstr_rect(&r
));
214 if (part
->style
& SBT_POPOUT
)
215 border
= BDR_RAISEDOUTER
;
216 else if (part
->style
& SBT_NOBORDERS
)
221 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
222 && (infoPtr
->simple
|| (itemID
== (infoPtr
->numParts
-1))))
223 themePart
= SP_GRIPPERPANE
;
224 DrawThemeBackground(theme
, hdc
, themePart
, 0, &r
, NULL
);
227 DrawEdge(hdc
, &r
, border
, BF_RECT
|BF_ADJUST
);
230 INT cy
= r
.bottom
- r
.top
;
231 DrawIconEx (hdc
, r
.left
+ 2, r
.top
, part
->hIcon
, cy
, cy
, 0, 0, DI_NORMAL
);
235 if (part
->style
& SBT_OWNERDRAW
) {
238 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
240 dis
.hwndItem
= infoPtr
->Self
;
243 dis
.itemData
= (ULONG_PTR
)part
->text
;
244 SendMessageW (infoPtr
->Notify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
247 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
253 STATUSBAR_RefreshPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
258 TRACE("item %d\n", itemID
);
260 if (part
->bound
.right
< part
->bound
.left
) return;
262 if (!RectVisible(hdc
, &part
->bound
))
265 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
268 GetClientRect (infoPtr
->Self
, &cr
);
269 DrawThemeBackground(theme
, hdc
, 0, 0, &cr
, &part
->bound
);
273 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
274 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
276 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
277 FillRect(hdc
, &part
->bound
, hbrBk
);
278 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
279 DeleteObject (hbrBk
);
282 STATUSBAR_DrawPart (infoPtr
, hdc
, part
, itemID
);
287 STATUSBAR_Refresh (STATUS_INFO
*infoPtr
, HDC hdc
)
296 if (!IsWindowVisible(infoPtr
->Self
))
299 STATUSBAR_SetPartBounds(infoPtr
);
301 GetClientRect (infoPtr
->Self
, &rect
);
303 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
305 DrawThemeBackground(theme
, hdc
, 0, 0, &rect
, NULL
);
309 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
310 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
312 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
313 FillRect(hdc
, &rect
, hbrBk
);
314 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
315 DeleteObject (hbrBk
);
318 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
320 if (infoPtr
->simple
) {
321 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
)
344 for (i
= 0; i
< infoPtr
->numParts
; i
++)
345 if (pt
->x
>= infoPtr
->parts
[i
].bound
.left
&& pt
->x
<= infoPtr
->parts
[i
].bound
.right
)
352 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
)
354 STATUSWINDOWPART
*part
;
358 /* get our window size */
359 GetClientRect (infoPtr
->Self
, &rect
);
360 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect
));
362 rect
.left
+= infoPtr
->horizontalBorder
;
363 rect
.top
+= infoPtr
->verticalBorder
;
365 /* set bounds for simple rectangle */
366 infoPtr
->part0
.bound
= rect
;
368 /* set bounds for non-simple rectangles */
369 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
370 part
= &infoPtr
->parts
[i
];
371 r
= &infoPtr
->parts
[i
].bound
;
373 r
->bottom
= rect
.bottom
;
377 r
->left
= infoPtr
->parts
[i
-1].bound
.right
+ infoPtr
->horizontalGap
;
379 r
->right
= rect
.right
;
383 if (infoPtr
->hwndToolTip
) {
386 ti
.cbSize
= sizeof(TTTOOLINFOW
);
387 ti
.hwnd
= infoPtr
->Self
;
390 SendMessageW (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
,
398 STATUSBAR_Relay2Tip (const STATUS_INFO
*infoPtr
, UINT uMsg
,
399 WPARAM wParam
, LPARAM lParam
)
403 msg
.hwnd
= infoPtr
->Self
;
407 msg
.time
= GetMessageTime ();
408 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
409 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
411 return SendMessageW (infoPtr
->hwndToolTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
416 STATUSBAR_GetBorders (const STATUS_INFO
*infoPtr
, INT out
[])
419 out
[0] = infoPtr
->horizontalBorder
;
420 out
[1] = infoPtr
->verticalBorder
;
421 out
[2] = infoPtr
->horizontalGap
;
428 STATUSBAR_SetBorders (STATUS_INFO
*infoPtr
, const INT in
[])
431 infoPtr
->horizontalBorder
= in
[0];
432 infoPtr
->verticalBorder
= in
[1];
433 infoPtr
->horizontalGap
= in
[2];
434 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
441 STATUSBAR_GetIcon (const STATUS_INFO
*infoPtr
, INT nPart
)
443 TRACE("%d\n", nPart
);
444 /* MSDN says: "simple parts are indexed with -1" */
445 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
449 return (infoPtr
->part0
.hIcon
);
451 return (infoPtr
->parts
[nPart
].hIcon
);
456 STATUSBAR_GetParts (const STATUS_INFO
*infoPtr
, INT num_parts
, INT parts
[])
460 TRACE("(%d)\n", num_parts
);
462 for (i
= 0; i
< num_parts
; i
++) {
463 parts
[i
] = infoPtr
->parts
[i
].x
;
466 return infoPtr
->numParts
;
471 STATUSBAR_GetRect (const STATUS_INFO
*infoPtr
, INT nPart
, LPRECT rect
)
473 TRACE("part %d\n", nPart
);
474 if(nPart
>= infoPtr
->numParts
|| nPart
< 0)
477 *rect
= infoPtr
->part0
.bound
;
479 *rect
= infoPtr
->parts
[nPart
].bound
;
485 STATUSBAR_GetTextA (STATUS_INFO
*infoPtr
, INT nPart
, LPSTR buf
)
487 STATUSWINDOWPART
*part
;
490 TRACE("part %d\n", nPart
);
492 /* MSDN says: "simple parts use index of 0", so this check is ok. */
493 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
496 part
= &infoPtr
->part0
;
498 part
= &infoPtr
->parts
[nPart
];
500 if (part
->style
& SBT_OWNERDRAW
)
501 result
= (LRESULT
)part
->text
;
503 DWORD len
= part
->text
? WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1,
504 NULL
, 0, NULL
, NULL
) - 1 : 0;
505 result
= MAKELONG( len
, part
->style
);
506 if (part
->text
&& buf
)
507 WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1, buf
, len
+1, NULL
, NULL
);
514 STATUSBAR_GetTextW (STATUS_INFO
*infoPtr
, INT nPart
, LPWSTR buf
)
516 STATUSWINDOWPART
*part
;
519 TRACE("part %d\n", nPart
);
520 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
523 part
= &infoPtr
->part0
;
525 part
= &infoPtr
->parts
[nPart
];
527 if (part
->style
& SBT_OWNERDRAW
)
528 result
= (LRESULT
)part
->text
;
530 result
= part
->text
? strlenW (part
->text
) : 0;
531 result
|= (part
->style
<< 16);
532 if (part
->text
&& buf
)
533 strcpyW (buf
, part
->text
);
540 STATUSBAR_GetTextLength (STATUS_INFO
*infoPtr
, INT nPart
)
542 STATUSWINDOWPART
*part
;
545 TRACE("part %d\n", nPart
);
547 /* MSDN says: "simple parts use index of 0", so this check is ok. */
548 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
551 part
= &infoPtr
->part0
;
553 part
= &infoPtr
->parts
[nPart
];
555 if ((~part
->style
& SBT_OWNERDRAW
) && part
->text
)
556 result
= strlenW(part
->text
);
560 result
|= (part
->style
<< 16);
565 STATUSBAR_GetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR tip
, INT size
)
569 CHAR buf
[INFOTIPSIZE
];
572 if (infoPtr
->hwndToolTip
) {
574 ti
.cbSize
= sizeof(TTTOOLINFOA
);
575 ti
.hwnd
= infoPtr
->Self
;
578 SendMessageA (infoPtr
->hwndToolTip
, TTM_GETTEXTA
, 0, (LPARAM
)&ti
);
580 lstrcpynA (tip
, buf
, size
);
587 STATUSBAR_GetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR tip
, INT size
)
591 WCHAR buf
[INFOTIPSIZE
];
594 if (infoPtr
->hwndToolTip
) {
596 ti
.cbSize
= sizeof(TTTOOLINFOW
);
597 ti
.hwnd
= infoPtr
->Self
;
600 SendMessageW(infoPtr
->hwndToolTip
, TTM_GETTEXTW
, 0, (LPARAM
)&ti
);
602 lstrcpynW(tip
, buf
, size
);
610 STATUSBAR_SetBkColor (STATUS_INFO
*infoPtr
, COLORREF color
)
614 oldBkColor
= infoPtr
->clrBk
;
615 infoPtr
->clrBk
= color
;
616 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
618 TRACE("CREF: %08x -> %08x\n", oldBkColor
, infoPtr
->clrBk
);
624 STATUSBAR_SetIcon (STATUS_INFO
*infoPtr
, INT nPart
, HICON hIcon
)
626 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
629 TRACE("setting part %d\n", nPart
);
631 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
633 if (infoPtr
->part0
.hIcon
== hIcon
) /* same as - no redraw */
635 infoPtr
->part0
.hIcon
= hIcon
;
637 InvalidateRect(infoPtr
->Self
, &infoPtr
->part0
.bound
, FALSE
);
639 if (infoPtr
->parts
[nPart
].hIcon
== hIcon
) /* same as - no redraw */
642 infoPtr
->parts
[nPart
].hIcon
= hIcon
;
643 if (!(infoPtr
->simple
))
644 InvalidateRect(infoPtr
->Self
, &infoPtr
->parts
[nPart
].bound
, FALSE
);
651 STATUSBAR_SetMinHeight (STATUS_INFO
*infoPtr
, INT height
)
653 DWORD ysize
= GetSystemMetrics(SM_CYSIZE
);
654 if (ysize
& 1) ysize
--;
655 infoPtr
->minHeight
= max(height
, ysize
);
656 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
657 /* like native, don't resize the control */
663 STATUSBAR_SetParts (STATUS_INFO
*infoPtr
, INT count
, LPINT parts
)
665 STATUSWINDOWPART
*tmp
;
668 TRACE("(%d,%p)\n", count
, parts
);
670 if(!count
) return FALSE
;
672 oldNumParts
= infoPtr
->numParts
;
673 infoPtr
->numParts
= count
;
674 if (oldNumParts
> infoPtr
->numParts
) {
675 for (i
= infoPtr
->numParts
; i
< oldNumParts
; i
++) {
676 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
677 Free (infoPtr
->parts
[i
].text
);
679 } else if (oldNumParts
< infoPtr
->numParts
) {
680 tmp
= Alloc (sizeof(STATUSWINDOWPART
) * infoPtr
->numParts
);
681 if (!tmp
) return FALSE
;
682 for (i
= 0; i
< oldNumParts
; i
++) {
683 tmp
[i
] = infoPtr
->parts
[i
];
685 Free (infoPtr
->parts
);
686 infoPtr
->parts
= tmp
;
688 if (oldNumParts
== infoPtr
->numParts
) {
689 for (i
=0; i
< oldNumParts
; i
++)
690 if (infoPtr
->parts
[i
].x
!= parts
[i
])
692 if (i
==oldNumParts
) /* Unchanged? no need to redraw! */
696 for (i
= 0; i
< infoPtr
->numParts
; i
++)
697 infoPtr
->parts
[i
].x
= parts
[i
];
699 if (infoPtr
->hwndToolTip
) {
703 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
704 ti
.cbSize
= sizeof(TTTOOLINFOW
);
705 ti
.hwnd
= infoPtr
->Self
;
707 nTipCount
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETTOOLCOUNT
, 0, 0);
708 if (nTipCount
< infoPtr
->numParts
) {
710 for (i
= nTipCount
; i
< infoPtr
->numParts
; i
++) {
711 TRACE("add tool %d\n", i
);
713 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
717 else if (nTipCount
> infoPtr
->numParts
) {
719 for (i
= nTipCount
- 1; i
>= infoPtr
->numParts
; i
--) {
720 TRACE("delete tool %d\n", i
);
722 SendMessageW (infoPtr
->hwndToolTip
, TTM_DELTOOLW
,
727 STATUSBAR_SetPartBounds (infoPtr
);
728 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
734 STATUSBAR_SetTextT (STATUS_INFO
*infoPtr
, INT nPart
, WORD style
,
735 LPWSTR text
, BOOL isW
)
737 STATUSWINDOWPART
*part
=NULL
;
738 BOOL changed
= FALSE
;
741 if (style
& SBT_OWNERDRAW
) {
742 TRACE("part %d, text %p\n",nPart
,text
);
744 else TRACE("part %d, text %s\n", nPart
, debugstr_t(text
, isW
));
746 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
747 * window is assumed to be a simple window */
749 if (nPart
== 0x00ff) {
750 part
= &infoPtr
->part0
;
752 if (infoPtr
->parts
&& nPart
>= 0 && nPart
< infoPtr
->numParts
) {
753 part
= &infoPtr
->parts
[nPart
];
756 if (!part
) return FALSE
;
758 if (part
->style
!= style
)
761 oldStyle
= part
->style
;
763 if (style
& SBT_OWNERDRAW
) {
764 if (!(oldStyle
& SBT_OWNERDRAW
))
772 LPCSTR atxt
= (LPCSTR
)text
;
773 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, NULL
, 0 );
774 ntext
= Alloc( (len
+ 1)*sizeof(WCHAR
) );
775 if (!ntext
) return FALSE
;
776 MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, ntext
, len
);
778 ntext
= Alloc( (strlenW(text
) + 1)*sizeof(WCHAR
) );
779 if (!ntext
) return FALSE
;
780 strcpyW (ntext
, text
);
783 /* replace nonprintable characters with spaces */
793 /* check if text is unchanged -> no need to redraw */
795 if (!changed
&& part
->text
&& !lstrcmpW(ntext
, part
->text
)) {
800 if (!changed
&& !part
->text
)
804 if (!(oldStyle
& SBT_OWNERDRAW
))
808 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
809 UpdateWindow(infoPtr
->Self
);
816 STATUSBAR_SetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR text
)
818 TRACE("part %d: \"%s\"\n", id
, text
);
819 if (infoPtr
->hwndToolTip
) {
821 ti
.cbSize
= sizeof(TTTOOLINFOA
);
822 ti
.hwnd
= infoPtr
->Self
;
826 SendMessageA (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTA
, 0, (LPARAM
)&ti
);
834 STATUSBAR_SetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR text
)
836 TRACE("part %d: \"%s\"\n", id
, debugstr_w(text
));
837 if (infoPtr
->hwndToolTip
) {
839 ti
.cbSize
= sizeof(TTTOOLINFOW
);
840 ti
.hwnd
= infoPtr
->Self
;
844 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
851 static inline LRESULT
852 STATUSBAR_SetUnicodeFormat (STATUS_INFO
*infoPtr
, BOOL bUnicode
)
854 BOOL bOld
= infoPtr
->bUnicode
;
856 TRACE("(0x%x)\n", bUnicode
);
857 infoPtr
->bUnicode
= bUnicode
;
864 STATUSBAR_Simple (STATUS_INFO
*infoPtr
, BOOL simple
)
868 TRACE("(simple=%d)\n", simple
);
869 if (infoPtr
->simple
== simple
) /* no need to change */
872 infoPtr
->simple
= simple
;
874 /* send notification */
875 nmhdr
.hwndFrom
= infoPtr
->Self
;
876 nmhdr
.idFrom
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
877 nmhdr
.code
= SBN_SIMPLEMODECHANGE
;
878 SendMessageW (infoPtr
->Notify
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
879 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
885 STATUSBAR_WMDestroy (STATUS_INFO
*infoPtr
)
890 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
891 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
892 Free (infoPtr
->parts
[i
].text
);
894 if (!(infoPtr
->part0
.style
& SBT_OWNERDRAW
))
895 Free (infoPtr
->part0
.text
);
896 Free (infoPtr
->parts
);
898 /* delete default font */
899 if (infoPtr
->hDefaultFont
)
900 DeleteObject (infoPtr
->hDefaultFont
);
902 /* delete tool tip control */
903 if (infoPtr
->hwndToolTip
)
904 DestroyWindow (infoPtr
->hwndToolTip
);
906 CloseThemeData (GetWindowTheme (infoPtr
->Self
));
908 SetWindowLongPtrW(infoPtr
->Self
, 0, 0);
915 STATUSBAR_WMCreate (HWND hwnd
, const CREATESTRUCTA
*lpCreate
)
917 STATUS_INFO
*infoPtr
;
918 NONCLIENTMETRICSW nclm
;
924 infoPtr
= Alloc (sizeof(STATUS_INFO
));
925 if (!infoPtr
) goto create_fail
;
926 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
928 infoPtr
->Self
= hwnd
;
929 infoPtr
->Notify
= lpCreate
->hwndParent
;
930 infoPtr
->numParts
= 1;
932 infoPtr
->simple
= FALSE
;
933 infoPtr
->clrBk
= CLR_DEFAULT
;
935 infoPtr
->horizontalBorder
= HORZ_BORDER
;
936 infoPtr
->verticalBorder
= VERT_BORDER
;
937 infoPtr
->horizontalGap
= HORZ_GAP
;
938 infoPtr
->minHeight
= GetSystemMetrics(SM_CYSIZE
);
939 if (infoPtr
->minHeight
& 1) infoPtr
->minHeight
--;
941 STATUSBAR_NotifyFormat(infoPtr
, infoPtr
->Notify
, NF_REQUERY
);
943 ZeroMemory (&nclm
, sizeof(nclm
));
944 nclm
.cbSize
= sizeof(nclm
);
945 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0);
946 infoPtr
->hDefaultFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
948 GetClientRect (hwnd
, &rect
);
950 /* initialize simple case */
951 infoPtr
->part0
.bound
= rect
;
952 infoPtr
->part0
.text
= 0;
953 infoPtr
->part0
.x
= 0;
954 infoPtr
->part0
.style
= 0;
955 infoPtr
->part0
.hIcon
= 0;
957 /* initialize first part */
958 infoPtr
->parts
= Alloc (sizeof(STATUSWINDOWPART
));
959 if (!infoPtr
->parts
) goto create_fail
;
960 infoPtr
->parts
[0].bound
= rect
;
961 infoPtr
->parts
[0].text
= 0;
962 infoPtr
->parts
[0].x
= -1;
963 infoPtr
->parts
[0].style
= 0;
964 infoPtr
->parts
[0].hIcon
= 0;
966 OpenThemeData (hwnd
, themeClass
);
968 if (lpCreate
->lpszName
&& (len
= strlenW ((LPCWSTR
)lpCreate
->lpszName
)))
970 infoPtr
->parts
[0].text
= Alloc ((len
+ 1)*sizeof(WCHAR
));
971 if (!infoPtr
->parts
[0].text
) goto create_fail
;
972 strcpyW (infoPtr
->parts
[0].text
, (LPCWSTR
)lpCreate
->lpszName
);
975 dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
976 /* native seems to clear WS_BORDER, too */
977 dwStyle
&= ~WS_BORDER
;
978 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
980 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
982 if (dwStyle
& SBT_TOOLTIPS
) {
983 infoPtr
->hwndToolTip
=
984 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
| TTS_ALWAYSTIP
,
985 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
986 CW_USEDEFAULT
, hwnd
, 0,
987 (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
), NULL
);
989 if (infoPtr
->hwndToolTip
) {
990 NMTOOLTIPSCREATED nmttc
;
992 nmttc
.hdr
.hwndFrom
= hwnd
;
993 nmttc
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
994 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
995 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
997 SendMessageW (lpCreate
->hwndParent
, WM_NOTIFY
, nmttc
.hdr
.idFrom
, (LPARAM
)&nmttc
);
1004 TRACE(" failed!\n");
1005 if (infoPtr
) STATUSBAR_WMDestroy(infoPtr
);
1010 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
1011 * of the first part only (usual behaviour) */
1013 STATUSBAR_WMGetText (const STATUS_INFO
*infoPtr
, INT size
, LPWSTR buf
)
1018 if (!(infoPtr
->parts
[0].text
))
1021 len
= strlenW (infoPtr
->parts
[0].text
);
1025 else if (size
> len
) {
1026 strcpyW (buf
, infoPtr
->parts
[0].text
);
1030 memcpy (buf
, infoPtr
->parts
[0].text
, (size
- 1) * sizeof(WCHAR
));
1038 STATUSBAR_WMNCHitTest (const STATUS_INFO
*infoPtr
, INT x
, INT y
)
1040 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
) {
1044 GetClientRect (infoPtr
->Self
, &rect
);
1048 ScreenToClient (infoPtr
->Self
, &pt
);
1050 rect
.left
= rect
.right
- 13;
1053 if (PtInRect (&rect
, pt
))
1055 if (GetWindowLongW( infoPtr
->Self
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) return HTBOTTOMLEFT
;
1056 else return HTBOTTOMRIGHT
;
1065 STATUSBAR_WMPaint (STATUS_INFO
*infoPtr
, HDC hdc
)
1070 if (hdc
) return STATUSBAR_Refresh (infoPtr
, hdc
);
1071 hdc
= BeginPaint (infoPtr
->Self
, &ps
);
1072 STATUSBAR_Refresh (infoPtr
, hdc
);
1073 EndPaint (infoPtr
->Self
, &ps
);
1080 STATUSBAR_WMSetFont (STATUS_INFO
*infoPtr
, HFONT font
, BOOL redraw
)
1082 infoPtr
->hFont
= font
;
1083 TRACE("%p\n", infoPtr
->hFont
);
1085 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
1086 SendMessageW(infoPtr
->Self
, WM_SIZE
, 0, 0); /* update size */
1088 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
1095 STATUSBAR_WMSetText (const STATUS_INFO
*infoPtr
, LPCSTR text
)
1097 STATUSWINDOWPART
*part
;
1101 if (infoPtr
->numParts
== 0)
1104 part
= &infoPtr
->parts
[0];
1105 /* duplicate string */
1109 if (text
&& (len
= strlenW((LPCWSTR
)text
))) {
1110 part
->text
= Alloc ((len
+1)*sizeof(WCHAR
));
1111 if (!part
->text
) return FALSE
;
1112 strcpyW (part
->text
, (LPCWSTR
)text
);
1115 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
1122 STATUSBAR_WMSize (STATUS_INFO
*infoPtr
, WORD flags
)
1127 /* Need to resize width to match parent */
1128 TRACE("flags %04x\n", flags
);
1130 if (flags
!= SIZE_RESTORED
&& flags
!= SIZE_MAXIMIZED
) {
1131 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1135 if (GetWindowLongW(infoPtr
->Self
, GWL_STYLE
) & CCS_NORESIZE
) return FALSE
;
1137 /* width and height don't apply */
1138 if (!GetClientRect (infoPtr
->Notify
, &parent_rect
))
1141 width
= parent_rect
.right
- parent_rect
.left
;
1142 x
= parent_rect
.left
;
1143 y
= parent_rect
.bottom
- infoPtr
->height
;
1144 MoveWindow (infoPtr
->Self
, x
, y
, width
, infoPtr
->height
, TRUE
);
1145 STATUSBAR_SetPartBounds (infoPtr
);
1150 /* update theme after a WM_THEMECHANGED message */
1151 static LRESULT
theme_changed (const STATUS_INFO
* infoPtr
)
1153 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
1154 CloseThemeData (theme
);
1155 OpenThemeData (infoPtr
->Self
, themeClass
);
1161 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
)
1163 if (cmd
== NF_REQUERY
) {
1164 INT i
= SendMessageW(from
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->Self
, NF_QUERY
);
1165 infoPtr
->bUnicode
= (i
== NFR_UNICODE
);
1167 return infoPtr
->bUnicode
? NFR_UNICODE
: NFR_ANSI
;
1172 STATUSBAR_SendMouseNotify(const STATUS_INFO
*infoPtr
, UINT code
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1176 TRACE("code %04x, lParam=%lx\n", code
, lParam
);
1177 nm
.hdr
.hwndFrom
= infoPtr
->Self
;
1178 nm
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->Self
, GWLP_ID
);
1180 nm
.pt
.x
= (short)LOWORD(lParam
);
1181 nm
.pt
.y
= (short)HIWORD(lParam
);
1182 nm
.dwItemSpec
= STATUSBAR_InternalHitTest(infoPtr
, &nm
.pt
);
1184 nm
.dwHitInfo
= 0x30000; /* seems constant */
1186 /* Do default processing if WM_NOTIFY returns zero */
1187 if(!SendMessageW(infoPtr
->Notify
, WM_NOTIFY
, nm
.hdr
.idFrom
, (LPARAM
)&nm
))
1189 return DefWindowProcW(infoPtr
->Self
, msg
, wParam
, lParam
);
1196 static LRESULT WINAPI
1197 StatusWindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1199 STATUS_INFO
*infoPtr
= (STATUS_INFO
*)GetWindowLongPtrW (hwnd
, 0);
1200 INT nPart
= ((INT
) wParam
) & 0x00ff;
1203 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1204 if (!infoPtr
&& msg
!= WM_CREATE
)
1205 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1209 return STATUSBAR_GetBorders (infoPtr
, (INT
*)lParam
);
1212 return (LRESULT
)STATUSBAR_GetIcon (infoPtr
, nPart
);
1215 return STATUSBAR_GetParts (infoPtr
, (INT
)wParam
, (INT
*)lParam
);
1218 return STATUSBAR_GetRect (infoPtr
, nPart
, (LPRECT
)lParam
);
1221 return STATUSBAR_GetTextA (infoPtr
, nPart
, (LPSTR
)lParam
);
1224 return STATUSBAR_GetTextW (infoPtr
, nPart
, (LPWSTR
)lParam
);
1226 case SB_GETTEXTLENGTHA
:
1227 case SB_GETTEXTLENGTHW
:
1228 return STATUSBAR_GetTextLength (infoPtr
, nPart
);
1230 case SB_GETTIPTEXTA
:
1231 return STATUSBAR_GetTipTextA (infoPtr
, LOWORD(wParam
), (LPSTR
)lParam
, HIWORD(wParam
));
1233 case SB_GETTIPTEXTW
:
1234 return STATUSBAR_GetTipTextW (infoPtr
, LOWORD(wParam
), (LPWSTR
)lParam
, HIWORD(wParam
));
1236 case SB_GETUNICODEFORMAT
:
1237 return infoPtr
->bUnicode
;
1240 return infoPtr
->simple
;
1243 return STATUSBAR_SetBorders (infoPtr
, (INT
*)lParam
);
1246 return STATUSBAR_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1249 return STATUSBAR_SetIcon (infoPtr
, nPart
, (HICON
)lParam
);
1251 case SB_SETMINHEIGHT
:
1252 return STATUSBAR_SetMinHeight (infoPtr
, (INT
)wParam
);
1255 return STATUSBAR_SetParts (infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
1258 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, FALSE
);
1261 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, TRUE
);
1263 case SB_SETTIPTEXTA
:
1264 return STATUSBAR_SetTipTextA (infoPtr
, (INT
)wParam
, (LPSTR
)lParam
);
1266 case SB_SETTIPTEXTW
:
1267 return STATUSBAR_SetTipTextW (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1269 case SB_SETUNICODEFORMAT
:
1270 return STATUSBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1273 return STATUSBAR_Simple (infoPtr
, (BOOL
)wParam
);
1276 return STATUSBAR_WMCreate (hwnd
, (LPCREATESTRUCTA
)lParam
);
1279 return STATUSBAR_WMDestroy (infoPtr
);
1282 return (LRESULT
)(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
1285 return STATUSBAR_WMGetText (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1287 case WM_GETTEXTLENGTH
:
1288 return LOWORD(STATUSBAR_GetTextLength (infoPtr
, 0));
1290 case WM_LBUTTONDBLCLK
:
1291 return STATUSBAR_SendMouseNotify(infoPtr
, NM_DBLCLK
, msg
, wParam
, lParam
);
1294 return STATUSBAR_SendMouseNotify(infoPtr
, NM_CLICK
, msg
, wParam
, lParam
);
1297 return STATUSBAR_Relay2Tip (infoPtr
, msg
, wParam
, lParam
);
1300 res
= STATUSBAR_WMNCHitTest(infoPtr
, (short)LOWORD(lParam
),
1301 (short)HIWORD(lParam
));
1302 if (res
!= HTERROR
) return res
;
1303 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1305 case WM_NCLBUTTONUP
:
1306 case WM_NCLBUTTONDOWN
:
1307 PostMessageW (infoPtr
->Notify
, msg
, wParam
, lParam
);
1310 case WM_NOTIFYFORMAT
:
1311 return STATUSBAR_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
1313 case WM_PRINTCLIENT
:
1315 return STATUSBAR_WMPaint (infoPtr
, (HDC
)wParam
);
1317 case WM_RBUTTONDBLCLK
:
1318 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RDBLCLK
, msg
, wParam
, lParam
);
1321 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RCLICK
, msg
, wParam
, lParam
);
1324 return STATUSBAR_WMSetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
1327 return STATUSBAR_WMSetText (infoPtr
, (LPCSTR
)lParam
);
1330 if (STATUSBAR_WMSize (infoPtr
, (WORD
)wParam
)) return 0;
1331 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1333 case WM_SYSCOLORCHANGE
:
1334 COMCTL32_RefreshSysColors();
1337 case WM_THEMECHANGED
:
1338 return theme_changed (infoPtr
);
1341 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
1342 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1343 msg
, wParam
, lParam
);
1344 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1349 /***********************************************************************
1350 * STATUS_Register [Internal]
1352 * Registers the status window class.
1356 STATUS_Register (void)
1360 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1361 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
;
1362 wndClass
.lpfnWndProc
= StatusWindowProc
;
1363 wndClass
.cbClsExtra
= 0;
1364 wndClass
.cbWndExtra
= sizeof(STATUS_INFO
*);
1365 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1366 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1367 wndClass
.lpszClassName
= STATUSCLASSNAMEW
;
1369 RegisterClassW (&wndClass
);
1373 /***********************************************************************
1374 * STATUS_Unregister [Internal]
1376 * Unregisters the status window class.
1380 STATUS_Unregister (void)
1382 UnregisterClassW (STATUSCLASSNAMEW
, NULL
);