2 * Interface code to StatusWindow widget/control
4 * Copyright 1996 Bruce Milner
5 * Copyright 1998, 1999 Eric Kohl
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Sep. 24, 2002, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
32 * -- CCS_BOTTOM (default)
37 * -- CCS_NOPARENTALIGN
40 * -- CCS_VERT (defaults to RIGHT)
45 WINE_DEFAULT_DEBUG_CHANNEL(statusbar
);
62 UINT minHeight
; /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
67 COLORREF clrBk
; /* background color */
68 BOOL bUnicode
; /* notify format. TRUE if notifies in Unicode */
69 STATUSWINDOWPART part0
; /* simple window */
70 STATUSWINDOWPART
* parts
;
77 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
78 * The second cdrom contains executables drawstat.exe, gettext.exe,
79 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
86 static const WCHAR themeClass
[] = { 'S','t','a','t','u','s',0 };
90 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
);
92 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
);
94 static inline LPCSTR
debugstr_t(LPCWSTR text
, BOOL isW
)
96 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
100 STATUSBAR_ComputeHeight(STATUS_INFO
*infoPtr
)
107 COMCTL32_GetFontMetrics(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
, &tm
);
108 margin
= (tm
.tmInternalLeading
? tm
.tmInternalLeading
: 2);
109 height
= max(tm
.tmHeight
+ margin
+ 2*GetSystemMetrics(SM_CYBORDER
), infoPtr
->minHeight
) + infoPtr
->verticalBorder
;
111 if ((theme
= GetWindowTheme(infoPtr
->Self
)))
113 /* Determine bar height from theme such that the content area is
114 * textHeight pixels large */
115 HDC hdc
= GetDC(infoPtr
->Self
);
118 SetRect(&r
, 0, 0, 0, max(infoPtr
->minHeight
, tm
.tmHeight
));
119 if (SUCCEEDED(GetThemeBackgroundExtent(theme
, hdc
, SP_PANE
, 0, &r
, &r
)))
121 height
= r
.bottom
- r
.top
;
123 ReleaseDC(infoPtr
->Self
, hdc
);
126 TRACE(" textHeight=%d+%d, final height=%d\n", tm
.tmHeight
, tm
.tmInternalLeading
, height
);
131 STATUSBAR_DrawSizeGrip (HTHEME theme
, HDC hdc
, LPRECT lpRect
)
135 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect
));
140 if (SUCCEEDED (GetThemePartSize (theme
, hdc
, SP_GRIPPER
, 0, lpRect
,
141 TS_DRAW
, &gripperSize
)))
143 rc
.left
= rc
.right
- gripperSize
.cx
;
144 rc
.top
= rc
.bottom
- gripperSize
.cy
;
145 if (SUCCEEDED (DrawThemeBackground(theme
, hdc
, SP_GRIPPER
, 0, &rc
, NULL
)))
150 rc
.left
= max( rc
.left
, rc
.right
- GetSystemMetrics(SM_CXVSCROLL
) - 1 );
151 rc
.top
= max( rc
.top
, rc
.bottom
- GetSystemMetrics(SM_CYHSCROLL
) - 1 );
152 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
157 STATUSBAR_DrawPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
159 RECT r
= part
->bound
;
160 UINT border
= BDR_SUNKENOUTER
;
161 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
162 int themePart
= SP_PANE
;
165 TRACE("part bound %s\n", wine_dbgstr_rect(&r
));
166 if (part
->style
& SBT_POPOUT
)
167 border
= BDR_RAISEDOUTER
;
168 else if (part
->style
& SBT_NOBORDERS
)
173 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
174 && (infoPtr
->simple
|| (itemID
== (infoPtr
->numParts
-1))))
175 themePart
= SP_GRIPPERPANE
;
176 DrawThemeBackground(theme
, hdc
, themePart
, 0, &r
, NULL
);
179 DrawEdge(hdc
, &r
, border
, BF_RECT
|BF_ADJUST
);
182 INT cy
= r
.bottom
- r
.top
;
183 DrawIconEx (hdc
, r
.left
+ 2, r
.top
, part
->hIcon
, cy
, cy
, 0, 0, DI_NORMAL
);
187 if (part
->style
& SBT_OWNERDRAW
) {
190 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
192 dis
.hwndItem
= infoPtr
->Self
;
195 dis
.itemData
= (ULONG_PTR
)part
->text
;
196 SendMessageW (infoPtr
->Notify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
201 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
203 DrawThemeText(theme
, hdc
, SP_PANE
, 0, part
->text
, -1, DT_VCENTER
|DT_SINGLELINE
|DT_NOPREFIX
, 0, &r
);
205 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
212 STATUSBAR_RefreshPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
217 TRACE("item %d\n", itemID
);
219 if (part
->bound
.right
< part
->bound
.left
) return;
221 if (!RectVisible(hdc
, &part
->bound
))
224 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
227 GetClientRect (infoPtr
->Self
, &cr
);
228 DrawThemeBackground(theme
, hdc
, 0, 0, &cr
, &part
->bound
);
232 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
233 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
235 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
236 FillRect(hdc
, &part
->bound
, hbrBk
);
237 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
238 DeleteObject (hbrBk
);
241 STATUSBAR_DrawPart (infoPtr
, hdc
, part
, itemID
);
246 STATUSBAR_Refresh (STATUS_INFO
*infoPtr
, HDC hdc
)
254 if (!IsWindowVisible(infoPtr
->Self
))
257 STATUSBAR_SetPartBounds(infoPtr
);
259 GetClientRect (infoPtr
->Self
, &rect
);
261 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
263 DrawThemeBackground(theme
, hdc
, 0, 0, &rect
, NULL
);
267 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
268 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
270 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
271 FillRect(hdc
, &rect
, hbrBk
);
272 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
273 DeleteObject (hbrBk
);
276 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
278 if (infoPtr
->simple
) {
279 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->part0
, 0);
283 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
284 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->parts
[i
], i
);
288 SelectObject (hdc
, hOldFont
);
290 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
291 STATUSBAR_DrawSizeGrip (theme
, hdc
, &rect
);
298 STATUSBAR_InternalHitTest(const STATUS_INFO
*infoPtr
, const POINT
*pt
)
305 for (i
= 0; i
< infoPtr
->numParts
; i
++)
306 if (pt
->x
>= infoPtr
->parts
[i
].bound
.left
&& pt
->x
<= infoPtr
->parts
[i
].bound
.right
)
313 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
)
315 STATUSWINDOWPART
*part
;
319 /* get our window size */
320 GetClientRect (infoPtr
->Self
, &rect
);
321 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect
));
323 rect
.left
+= infoPtr
->horizontalBorder
;
324 rect
.top
+= infoPtr
->verticalBorder
;
326 /* set bounds for simple rectangle */
327 infoPtr
->part0
.bound
= rect
;
329 /* set bounds for non-simple rectangles */
330 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
331 part
= &infoPtr
->parts
[i
];
332 r
= &infoPtr
->parts
[i
].bound
;
334 r
->bottom
= rect
.bottom
;
338 r
->left
= infoPtr
->parts
[i
-1].bound
.right
+ infoPtr
->horizontalGap
;
340 r
->right
= rect
.right
;
344 if (infoPtr
->hwndToolTip
) {
347 ti
.cbSize
= sizeof(TTTOOLINFOW
);
348 ti
.hwnd
= infoPtr
->Self
;
351 SendMessageW (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
,
359 STATUSBAR_Relay2Tip (const STATUS_INFO
*infoPtr
, UINT uMsg
,
360 WPARAM wParam
, LPARAM lParam
)
364 msg
.hwnd
= infoPtr
->Self
;
368 msg
.time
= GetMessageTime ();
369 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
370 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
372 return SendMessageW (infoPtr
->hwndToolTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
377 STATUSBAR_GetBorders (const STATUS_INFO
*infoPtr
, INT out
[])
380 out
[0] = infoPtr
->horizontalBorder
;
381 out
[1] = infoPtr
->verticalBorder
;
382 out
[2] = infoPtr
->horizontalGap
;
389 STATUSBAR_SetBorders (STATUS_INFO
*infoPtr
, const INT in
[])
392 infoPtr
->horizontalBorder
= in
[0];
393 infoPtr
->verticalBorder
= in
[1];
394 infoPtr
->horizontalGap
= in
[2];
395 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
402 STATUSBAR_GetIcon (const STATUS_INFO
*infoPtr
, INT nPart
)
404 TRACE("%d\n", nPart
);
405 /* MSDN says: "simple parts are indexed with -1" */
406 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
410 return (infoPtr
->part0
.hIcon
);
412 return (infoPtr
->parts
[nPart
].hIcon
);
417 STATUSBAR_GetParts (const STATUS_INFO
*infoPtr
, INT num_parts
, INT parts
[])
421 TRACE("(%d)\n", num_parts
);
423 for (i
= 0; i
< num_parts
; i
++) {
424 parts
[i
] = infoPtr
->parts
[i
].x
;
427 return infoPtr
->numParts
;
432 STATUSBAR_GetRect (const STATUS_INFO
*infoPtr
, INT nPart
, LPRECT rect
)
434 TRACE("part %d\n", nPart
);
435 if(nPart
>= infoPtr
->numParts
|| nPart
< 0)
438 *rect
= infoPtr
->part0
.bound
;
440 *rect
= infoPtr
->parts
[nPart
].bound
;
446 STATUSBAR_GetTextA (STATUS_INFO
*infoPtr
, INT nPart
, LPSTR buf
)
448 STATUSWINDOWPART
*part
;
451 TRACE("part %d\n", nPart
);
453 /* MSDN says: "simple parts use index of 0", so this check is ok. */
454 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
457 part
= &infoPtr
->part0
;
459 part
= &infoPtr
->parts
[nPart
];
461 if (part
->style
& SBT_OWNERDRAW
)
462 result
= (LRESULT
)part
->text
;
464 DWORD len
= part
->text
? WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1,
465 NULL
, 0, NULL
, NULL
) - 1 : 0;
466 result
= MAKELONG( len
, part
->style
);
467 if (part
->text
&& buf
)
468 WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1, buf
, len
+1, NULL
, NULL
);
475 STATUSBAR_GetTextW (STATUS_INFO
*infoPtr
, INT nPart
, LPWSTR buf
)
477 STATUSWINDOWPART
*part
;
480 TRACE("part %d\n", nPart
);
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 result
= part
->text
? strlenW (part
->text
) : 0;
492 result
|= (part
->style
<< 16);
493 if (part
->text
&& buf
)
494 strcpyW (buf
, part
->text
);
501 STATUSBAR_GetTextLength (STATUS_INFO
*infoPtr
, INT nPart
)
503 STATUSWINDOWPART
*part
;
506 TRACE("part %d\n", nPart
);
508 /* MSDN says: "simple parts use index of 0", so this check is ok. */
509 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
512 part
= &infoPtr
->part0
;
514 part
= &infoPtr
->parts
[nPart
];
516 if ((~part
->style
& SBT_OWNERDRAW
) && part
->text
)
517 result
= strlenW(part
->text
);
521 result
|= (part
->style
<< 16);
526 STATUSBAR_GetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR tip
, INT size
)
530 CHAR buf
[INFOTIPSIZE
];
533 if (infoPtr
->hwndToolTip
) {
535 ti
.cbSize
= sizeof(TTTOOLINFOA
);
536 ti
.hwnd
= infoPtr
->Self
;
539 SendMessageA (infoPtr
->hwndToolTip
, TTM_GETTEXTA
, 0, (LPARAM
)&ti
);
541 lstrcpynA (tip
, buf
, size
);
548 STATUSBAR_GetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR tip
, INT size
)
552 WCHAR buf
[INFOTIPSIZE
];
555 if (infoPtr
->hwndToolTip
) {
557 ti
.cbSize
= sizeof(TTTOOLINFOW
);
558 ti
.hwnd
= infoPtr
->Self
;
561 SendMessageW(infoPtr
->hwndToolTip
, TTM_GETTEXTW
, 0, (LPARAM
)&ti
);
563 lstrcpynW(tip
, buf
, size
);
571 STATUSBAR_SetBkColor (STATUS_INFO
*infoPtr
, COLORREF color
)
575 oldBkColor
= infoPtr
->clrBk
;
576 infoPtr
->clrBk
= color
;
577 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
579 TRACE("CREF: %08x -> %08x\n", oldBkColor
, infoPtr
->clrBk
);
585 STATUSBAR_SetIcon (STATUS_INFO
*infoPtr
, INT nPart
, HICON hIcon
)
587 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
590 TRACE("setting part %d\n", nPart
);
592 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
594 if (infoPtr
->part0
.hIcon
== hIcon
) /* same as - no redraw */
596 infoPtr
->part0
.hIcon
= hIcon
;
598 InvalidateRect(infoPtr
->Self
, &infoPtr
->part0
.bound
, FALSE
);
600 if (infoPtr
->parts
[nPart
].hIcon
== hIcon
) /* same as - no redraw */
603 infoPtr
->parts
[nPart
].hIcon
= hIcon
;
604 if (!(infoPtr
->simple
))
605 InvalidateRect(infoPtr
->Self
, &infoPtr
->parts
[nPart
].bound
, FALSE
);
612 STATUSBAR_SetMinHeight (STATUS_INFO
*infoPtr
, INT height
)
614 DWORD ysize
= GetSystemMetrics(SM_CYSIZE
);
615 if (ysize
& 1) ysize
--;
616 infoPtr
->minHeight
= max(height
, ysize
);
617 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
618 /* like native, don't resize the control */
624 STATUSBAR_SetParts (STATUS_INFO
*infoPtr
, INT count
, LPINT parts
)
626 STATUSWINDOWPART
*tmp
;
629 TRACE("(%d,%p)\n", count
, parts
);
631 if(!count
) return FALSE
;
633 oldNumParts
= infoPtr
->numParts
;
634 infoPtr
->numParts
= count
;
635 if (oldNumParts
> infoPtr
->numParts
) {
636 for (i
= infoPtr
->numParts
; i
< oldNumParts
; i
++) {
637 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
638 Free (infoPtr
->parts
[i
].text
);
640 } else if (oldNumParts
< infoPtr
->numParts
) {
641 tmp
= Alloc (sizeof(STATUSWINDOWPART
) * infoPtr
->numParts
);
642 if (!tmp
) return FALSE
;
643 for (i
= 0; i
< oldNumParts
; i
++) {
644 tmp
[i
] = infoPtr
->parts
[i
];
646 Free (infoPtr
->parts
);
647 infoPtr
->parts
= tmp
;
649 if (oldNumParts
== infoPtr
->numParts
) {
650 for (i
=0; i
< oldNumParts
; i
++)
651 if (infoPtr
->parts
[i
].x
!= parts
[i
])
653 if (i
==oldNumParts
) /* Unchanged? no need to redraw! */
657 for (i
= 0; i
< infoPtr
->numParts
; i
++)
658 infoPtr
->parts
[i
].x
= parts
[i
];
660 if (infoPtr
->hwndToolTip
) {
665 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
666 ti
.cbSize
= sizeof(TTTOOLINFOW
);
667 ti
.hwnd
= infoPtr
->Self
;
668 ti
.lpszText
= &wEmpty
;
670 nTipCount
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETTOOLCOUNT
, 0, 0);
671 if (nTipCount
< infoPtr
->numParts
) {
673 for (i
= nTipCount
; i
< infoPtr
->numParts
; i
++) {
674 TRACE("add tool %d\n", i
);
676 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
680 else if (nTipCount
> infoPtr
->numParts
) {
682 for (i
= nTipCount
- 1; i
>= infoPtr
->numParts
; i
--) {
683 TRACE("delete tool %d\n", i
);
685 SendMessageW (infoPtr
->hwndToolTip
, TTM_DELTOOLW
,
690 STATUSBAR_SetPartBounds (infoPtr
);
691 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
697 STATUSBAR_SetTextT (STATUS_INFO
*infoPtr
, INT nPart
, WORD style
,
698 LPWSTR text
, BOOL isW
)
700 STATUSWINDOWPART
*part
=NULL
;
701 BOOL changed
= FALSE
;
704 if (style
& SBT_OWNERDRAW
) {
705 TRACE("part %d, text %p\n",nPart
,text
);
707 else TRACE("part %d, text %s\n", nPart
, debugstr_t(text
, isW
));
709 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
710 * window is assumed to be a simple window */
712 if (nPart
== 0x00ff) {
713 part
= &infoPtr
->part0
;
715 if (infoPtr
->parts
&& nPart
>= 0 && nPart
< infoPtr
->numParts
) {
716 part
= &infoPtr
->parts
[nPart
];
719 if (!part
) return FALSE
;
721 if (part
->style
!= style
)
724 oldStyle
= part
->style
;
726 if (style
& SBT_OWNERDRAW
) {
727 if (!(oldStyle
& SBT_OWNERDRAW
))
735 LPCSTR atxt
= (LPCSTR
)text
;
736 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, NULL
, 0 );
737 ntext
= Alloc( (len
+ 1)*sizeof(WCHAR
) );
738 if (!ntext
) return FALSE
;
739 MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, ntext
, len
);
741 ntext
= Alloc( (strlenW(text
) + 1)*sizeof(WCHAR
) );
742 if (!ntext
) return FALSE
;
743 strcpyW (ntext
, text
);
746 /* replace nonprintable characters with spaces */
756 /* check if text is unchanged -> no need to redraw */
758 if (!changed
&& part
->text
&& !lstrcmpW(ntext
, part
->text
)) {
763 if (!changed
&& !part
->text
)
767 if (!(oldStyle
& SBT_OWNERDRAW
))
771 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
772 UpdateWindow(infoPtr
->Self
);
779 STATUSBAR_SetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR text
)
781 TRACE("part %d: \"%s\"\n", id
, text
);
782 if (infoPtr
->hwndToolTip
) {
784 ti
.cbSize
= sizeof(TTTOOLINFOA
);
785 ti
.hwnd
= infoPtr
->Self
;
789 SendMessageA (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTA
, 0, (LPARAM
)&ti
);
797 STATUSBAR_SetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR text
)
799 TRACE("part %d: \"%s\"\n", id
, debugstr_w(text
));
800 if (infoPtr
->hwndToolTip
) {
802 ti
.cbSize
= sizeof(TTTOOLINFOW
);
803 ti
.hwnd
= infoPtr
->Self
;
807 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
814 static inline LRESULT
815 STATUSBAR_SetUnicodeFormat (STATUS_INFO
*infoPtr
, BOOL bUnicode
)
817 BOOL bOld
= infoPtr
->bUnicode
;
819 TRACE("(0x%x)\n", bUnicode
);
820 infoPtr
->bUnicode
= bUnicode
;
827 STATUSBAR_Simple (STATUS_INFO
*infoPtr
, BOOL simple
)
831 TRACE("(simple=%d)\n", simple
);
832 if (infoPtr
->simple
== simple
) /* no need to change */
835 infoPtr
->simple
= simple
;
837 /* send notification */
838 nmhdr
.hwndFrom
= infoPtr
->Self
;
839 nmhdr
.idFrom
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
840 nmhdr
.code
= SBN_SIMPLEMODECHANGE
;
841 SendMessageW (infoPtr
->Notify
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
842 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
848 STATUSBAR_WMDestroy (STATUS_INFO
*infoPtr
)
853 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
854 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
855 Free (infoPtr
->parts
[i
].text
);
857 if (!(infoPtr
->part0
.style
& SBT_OWNERDRAW
))
858 Free (infoPtr
->part0
.text
);
859 Free (infoPtr
->parts
);
861 /* delete default font */
862 if (infoPtr
->hDefaultFont
)
863 DeleteObject (infoPtr
->hDefaultFont
);
865 /* delete tool tip control */
866 if (infoPtr
->hwndToolTip
)
867 DestroyWindow (infoPtr
->hwndToolTip
);
869 CloseThemeData (GetWindowTheme (infoPtr
->Self
));
871 SetWindowLongPtrW(infoPtr
->Self
, 0, 0);
878 STATUSBAR_WMCreate (HWND hwnd
, const CREATESTRUCTA
*lpCreate
)
880 STATUS_INFO
*infoPtr
;
881 NONCLIENTMETRICSW nclm
;
887 infoPtr
= Alloc (sizeof(STATUS_INFO
));
888 if (!infoPtr
) goto create_fail
;
889 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
891 infoPtr
->Self
= hwnd
;
892 infoPtr
->Notify
= lpCreate
->hwndParent
;
893 infoPtr
->numParts
= 1;
895 infoPtr
->simple
= FALSE
;
896 infoPtr
->clrBk
= CLR_DEFAULT
;
898 infoPtr
->horizontalBorder
= HORZ_BORDER
;
899 infoPtr
->verticalBorder
= VERT_BORDER
;
900 infoPtr
->horizontalGap
= HORZ_GAP
;
901 infoPtr
->minHeight
= GetSystemMetrics(SM_CYSIZE
);
902 if (infoPtr
->minHeight
& 1) infoPtr
->minHeight
--;
904 STATUSBAR_NotifyFormat(infoPtr
, infoPtr
->Notify
, NF_REQUERY
);
906 ZeroMemory (&nclm
, sizeof(nclm
));
907 nclm
.cbSize
= sizeof(nclm
);
908 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0);
909 infoPtr
->hDefaultFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
911 GetClientRect (hwnd
, &rect
);
913 /* initialize simple case */
914 infoPtr
->part0
.bound
= rect
;
915 infoPtr
->part0
.text
= 0;
916 infoPtr
->part0
.x
= 0;
917 infoPtr
->part0
.style
= 0;
918 infoPtr
->part0
.hIcon
= 0;
920 /* initialize first part */
921 infoPtr
->parts
= Alloc (sizeof(STATUSWINDOWPART
));
922 if (!infoPtr
->parts
) goto create_fail
;
923 infoPtr
->parts
[0].bound
= rect
;
924 infoPtr
->parts
[0].text
= 0;
925 infoPtr
->parts
[0].x
= -1;
926 infoPtr
->parts
[0].style
= 0;
927 infoPtr
->parts
[0].hIcon
= 0;
929 OpenThemeData (hwnd
, themeClass
);
931 if (lpCreate
->lpszName
&& (len
= strlenW ((LPCWSTR
)lpCreate
->lpszName
)))
933 infoPtr
->parts
[0].text
= Alloc ((len
+ 1)*sizeof(WCHAR
));
934 if (!infoPtr
->parts
[0].text
) goto create_fail
;
935 strcpyW (infoPtr
->parts
[0].text
, (LPCWSTR
)lpCreate
->lpszName
);
938 dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
939 /* native seems to clear WS_BORDER, too */
940 dwStyle
&= ~WS_BORDER
;
941 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
943 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
945 if (dwStyle
& SBT_TOOLTIPS
) {
946 infoPtr
->hwndToolTip
=
947 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
| TTS_ALWAYSTIP
,
948 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
949 CW_USEDEFAULT
, hwnd
, 0,
950 (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
), NULL
);
952 if (infoPtr
->hwndToolTip
) {
953 NMTOOLTIPSCREATED nmttc
;
955 nmttc
.hdr
.hwndFrom
= hwnd
;
956 nmttc
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
957 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
958 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
960 SendMessageW (lpCreate
->hwndParent
, WM_NOTIFY
, nmttc
.hdr
.idFrom
, (LPARAM
)&nmttc
);
968 if (infoPtr
) STATUSBAR_WMDestroy(infoPtr
);
973 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
974 * of the first part only (usual behaviour) */
976 STATUSBAR_WMGetText (const STATUS_INFO
*infoPtr
, INT size
, LPWSTR buf
)
981 if (!(infoPtr
->parts
[0].text
))
984 len
= strlenW (infoPtr
->parts
[0].text
);
988 else if (size
> len
) {
989 strcpyW (buf
, infoPtr
->parts
[0].text
);
993 memcpy (buf
, infoPtr
->parts
[0].text
, (size
- 1) * sizeof(WCHAR
));
1001 STATUSBAR_WMNCHitTest (const STATUS_INFO
*infoPtr
, INT x
, INT y
)
1003 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
) {
1007 GetClientRect (infoPtr
->Self
, &rect
);
1011 ScreenToClient (infoPtr
->Self
, &pt
);
1013 rect
.left
= rect
.right
- 13;
1016 if (PtInRect (&rect
, pt
))
1018 if (GetWindowLongW( infoPtr
->Self
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) return HTBOTTOMLEFT
;
1019 else return HTBOTTOMRIGHT
;
1028 STATUSBAR_WMPaint (STATUS_INFO
*infoPtr
, HDC hdc
)
1033 if (hdc
) return STATUSBAR_Refresh (infoPtr
, hdc
);
1034 hdc
= BeginPaint (infoPtr
->Self
, &ps
);
1035 STATUSBAR_Refresh (infoPtr
, hdc
);
1036 EndPaint (infoPtr
->Self
, &ps
);
1043 STATUSBAR_WMSetFont (STATUS_INFO
*infoPtr
, HFONT font
, BOOL redraw
)
1045 infoPtr
->hFont
= font
;
1046 TRACE("%p\n", infoPtr
->hFont
);
1048 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
1049 SendMessageW(infoPtr
->Self
, WM_SIZE
, 0, 0); /* update size */
1051 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
1058 STATUSBAR_WMSetText (const STATUS_INFO
*infoPtr
, LPCSTR text
)
1060 STATUSWINDOWPART
*part
;
1064 if (infoPtr
->numParts
== 0)
1067 part
= &infoPtr
->parts
[0];
1068 /* duplicate string */
1072 if (text
&& (len
= strlenW((LPCWSTR
)text
))) {
1073 part
->text
= Alloc ((len
+1)*sizeof(WCHAR
));
1074 if (!part
->text
) return FALSE
;
1075 strcpyW (part
->text
, (LPCWSTR
)text
);
1078 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
1085 STATUSBAR_WMSize (STATUS_INFO
*infoPtr
, WORD flags
)
1090 /* Need to resize width to match parent */
1091 TRACE("flags %04x\n", flags
);
1093 if (flags
!= SIZE_RESTORED
&& flags
!= SIZE_MAXIMIZED
) {
1094 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1098 if (GetWindowLongW(infoPtr
->Self
, GWL_STYLE
) & CCS_NORESIZE
) return FALSE
;
1100 /* width and height don't apply */
1101 if (!GetClientRect (infoPtr
->Notify
, &parent_rect
))
1104 width
= parent_rect
.right
- parent_rect
.left
;
1105 x
= parent_rect
.left
;
1106 y
= parent_rect
.bottom
- infoPtr
->height
;
1107 MoveWindow (infoPtr
->Self
, x
, y
, width
, infoPtr
->height
, TRUE
);
1108 STATUSBAR_SetPartBounds (infoPtr
);
1113 /* update theme after a WM_THEMECHANGED message */
1114 static LRESULT
theme_changed (const STATUS_INFO
* infoPtr
)
1116 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
1117 CloseThemeData (theme
);
1118 OpenThemeData (infoPtr
->Self
, themeClass
);
1124 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
)
1126 if (cmd
== NF_REQUERY
) {
1127 INT i
= SendMessageW(from
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->Self
, NF_QUERY
);
1128 infoPtr
->bUnicode
= (i
== NFR_UNICODE
);
1130 return infoPtr
->bUnicode
? NFR_UNICODE
: NFR_ANSI
;
1135 STATUSBAR_SendMouseNotify(const STATUS_INFO
*infoPtr
, UINT code
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1139 TRACE("code %04x, lParam=%lx\n", code
, lParam
);
1140 nm
.hdr
.hwndFrom
= infoPtr
->Self
;
1141 nm
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->Self
, GWLP_ID
);
1143 nm
.pt
.x
= (short)LOWORD(lParam
);
1144 nm
.pt
.y
= (short)HIWORD(lParam
);
1145 nm
.dwItemSpec
= STATUSBAR_InternalHitTest(infoPtr
, &nm
.pt
);
1147 nm
.dwHitInfo
= 0x30000; /* seems constant */
1149 /* Do default processing if WM_NOTIFY returns zero */
1150 if(!SendMessageW(infoPtr
->Notify
, WM_NOTIFY
, nm
.hdr
.idFrom
, (LPARAM
)&nm
))
1152 return DefWindowProcW(infoPtr
->Self
, msg
, wParam
, lParam
);
1159 static LRESULT WINAPI
1160 StatusWindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1162 STATUS_INFO
*infoPtr
= (STATUS_INFO
*)GetWindowLongPtrW (hwnd
, 0);
1163 INT nPart
= ((INT
) wParam
) & 0x00ff;
1166 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1167 if (!infoPtr
&& msg
!= WM_CREATE
)
1168 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1172 return STATUSBAR_GetBorders (infoPtr
, (INT
*)lParam
);
1175 return (LRESULT
)STATUSBAR_GetIcon (infoPtr
, nPart
);
1178 return STATUSBAR_GetParts (infoPtr
, (INT
)wParam
, (INT
*)lParam
);
1181 return STATUSBAR_GetRect (infoPtr
, nPart
, (LPRECT
)lParam
);
1184 return STATUSBAR_GetTextA (infoPtr
, nPart
, (LPSTR
)lParam
);
1187 return STATUSBAR_GetTextW (infoPtr
, nPart
, (LPWSTR
)lParam
);
1189 case SB_GETTEXTLENGTHA
:
1190 case SB_GETTEXTLENGTHW
:
1191 return STATUSBAR_GetTextLength (infoPtr
, nPart
);
1193 case SB_GETTIPTEXTA
:
1194 return STATUSBAR_GetTipTextA (infoPtr
, LOWORD(wParam
), (LPSTR
)lParam
, HIWORD(wParam
));
1196 case SB_GETTIPTEXTW
:
1197 return STATUSBAR_GetTipTextW (infoPtr
, LOWORD(wParam
), (LPWSTR
)lParam
, HIWORD(wParam
));
1199 case SB_GETUNICODEFORMAT
:
1200 return infoPtr
->bUnicode
;
1203 return infoPtr
->simple
;
1206 return STATUSBAR_SetBorders (infoPtr
, (INT
*)lParam
);
1209 return STATUSBAR_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1212 return STATUSBAR_SetIcon (infoPtr
, nPart
, (HICON
)lParam
);
1214 case SB_SETMINHEIGHT
:
1215 return STATUSBAR_SetMinHeight (infoPtr
, (INT
)wParam
);
1218 return STATUSBAR_SetParts (infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
1221 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, FALSE
);
1224 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, TRUE
);
1226 case SB_SETTIPTEXTA
:
1227 return STATUSBAR_SetTipTextA (infoPtr
, (INT
)wParam
, (LPSTR
)lParam
);
1229 case SB_SETTIPTEXTW
:
1230 return STATUSBAR_SetTipTextW (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1232 case SB_SETUNICODEFORMAT
:
1233 return STATUSBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1236 return STATUSBAR_Simple (infoPtr
, (BOOL
)wParam
);
1239 return STATUSBAR_WMCreate (hwnd
, (LPCREATESTRUCTA
)lParam
);
1242 return STATUSBAR_WMDestroy (infoPtr
);
1245 return (LRESULT
)(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
1248 return STATUSBAR_WMGetText (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1250 case WM_GETTEXTLENGTH
:
1251 return LOWORD(STATUSBAR_GetTextLength (infoPtr
, 0));
1253 case WM_LBUTTONDBLCLK
:
1254 return STATUSBAR_SendMouseNotify(infoPtr
, NM_DBLCLK
, msg
, wParam
, lParam
);
1257 return STATUSBAR_SendMouseNotify(infoPtr
, NM_CLICK
, msg
, wParam
, lParam
);
1260 return STATUSBAR_Relay2Tip (infoPtr
, msg
, wParam
, lParam
);
1263 res
= STATUSBAR_WMNCHitTest(infoPtr
, (short)LOWORD(lParam
),
1264 (short)HIWORD(lParam
));
1265 if (res
!= HTERROR
) return res
;
1266 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1268 case WM_NCLBUTTONUP
:
1269 case WM_NCLBUTTONDOWN
:
1270 PostMessageW (infoPtr
->Notify
, msg
, wParam
, lParam
);
1273 case WM_NOTIFYFORMAT
:
1274 return STATUSBAR_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
1276 case WM_PRINTCLIENT
:
1278 return STATUSBAR_WMPaint (infoPtr
, (HDC
)wParam
);
1280 case WM_RBUTTONDBLCLK
:
1281 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RDBLCLK
, msg
, wParam
, lParam
);
1284 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RCLICK
, msg
, wParam
, lParam
);
1287 return STATUSBAR_WMSetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
1290 return STATUSBAR_WMSetText (infoPtr
, (LPCSTR
)lParam
);
1293 if (STATUSBAR_WMSize (infoPtr
, (WORD
)wParam
)) return 0;
1294 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1296 case WM_SYSCOLORCHANGE
:
1297 COMCTL32_RefreshSysColors();
1300 case WM_THEMECHANGED
:
1301 return theme_changed (infoPtr
);
1304 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
1305 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1306 msg
, wParam
, lParam
);
1307 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1312 /***********************************************************************
1313 * STATUS_Register [Internal]
1315 * Registers the status window class.
1319 STATUS_Register (void)
1323 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1324 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
;
1325 wndClass
.lpfnWndProc
= StatusWindowProc
;
1326 wndClass
.cbClsExtra
= 0;
1327 wndClass
.cbWndExtra
= sizeof(STATUS_INFO
*);
1328 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1329 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1330 wndClass
.lpszClassName
= STATUSCLASSNAMEW
;
1332 RegisterClassW (&wndClass
);
1336 /***********************************************************************
1337 * STATUS_Unregister [Internal]
1339 * Unregisters the status window class.
1343 STATUS_Unregister (void)
1345 UnregisterClassW (STATUSCLASSNAMEW
, NULL
);