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
23 * -- CCS_BOTTOM (default)
28 * -- CCS_NOPARENTALIGN
31 * -- CCS_VERT (defaults to RIGHT)
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(statusbar
);
65 UINT minHeight
; /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
70 COLORREF clrBk
; /* background color */
71 BOOL bUnicode
; /* notify format. TRUE if notifies in Unicode */
72 STATUSWINDOWPART part0
; /* simple window */
73 STATUSWINDOWPART
* parts
;
80 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
81 * The second cdrom contains executables drawstat.exe, gettext.exe,
82 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
89 static const WCHAR themeClass
[] = L
"Status";
93 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
);
95 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
);
97 static inline LPCSTR
debugstr_t(LPCWSTR text
, BOOL isW
)
99 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
103 STATUSBAR_ComputeHeight(STATUS_INFO
*infoPtr
)
110 COMCTL32_GetFontMetrics(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
, &tm
);
111 margin
= (tm
.tmInternalLeading
? tm
.tmInternalLeading
: 2);
112 height
= max(tm
.tmHeight
+ margin
+ 2*GetSystemMetrics(SM_CYBORDER
), infoPtr
->minHeight
) + infoPtr
->verticalBorder
;
114 if ((theme
= GetWindowTheme(infoPtr
->Self
)))
116 /* Determine bar height from theme such that the content area is
117 * textHeight pixels large */
118 HDC hdc
= GetDC(infoPtr
->Self
);
121 SetRect(&r
, 0, 0, 0, max(infoPtr
->minHeight
, tm
.tmHeight
));
122 if (SUCCEEDED(GetThemeBackgroundExtent(theme
, hdc
, SP_PANE
, 0, &r
, &r
)))
124 height
= r
.bottom
- r
.top
;
126 ReleaseDC(infoPtr
->Self
, hdc
);
129 TRACE(" textHeight=%d+%d, final height=%d\n", tm
.tmHeight
, tm
.tmInternalLeading
, height
);
134 STATUSBAR_DrawSizeGrip (HTHEME theme
, HDC hdc
, LPRECT lpRect
)
138 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect
));
143 if (SUCCEEDED (GetThemePartSize (theme
, hdc
, SP_GRIPPER
, 0, lpRect
,
144 TS_DRAW
, &gripperSize
)))
146 rc
.left
= rc
.right
- gripperSize
.cx
;
147 rc
.top
= rc
.bottom
- gripperSize
.cy
;
148 if (SUCCEEDED (DrawThemeBackground(theme
, hdc
, SP_GRIPPER
, 0, &rc
, NULL
)))
153 rc
.left
= max( rc
.left
, rc
.right
- GetSystemMetrics(SM_CXVSCROLL
) - 1 );
154 rc
.top
= max( rc
.top
, rc
.bottom
- GetSystemMetrics(SM_CYHSCROLL
) - 1 );
155 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
160 STATUSBAR_DrawPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
162 RECT r
= part
->bound
;
163 UINT border
= BDR_SUNKENOUTER
;
164 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
165 int themePart
= SP_PANE
;
168 TRACE("part bound %s\n", wine_dbgstr_rect(&r
));
169 if (part
->style
& SBT_POPOUT
)
170 border
= BDR_RAISEDOUTER
;
171 else if (part
->style
& SBT_NOBORDERS
)
176 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
177 && (infoPtr
->simple
|| (itemID
== (infoPtr
->numParts
-1))))
178 themePart
= SP_GRIPPERPANE
;
179 DrawThemeBackground(theme
, hdc
, themePart
, 0, &r
, NULL
);
182 DrawEdge(hdc
, &r
, border
, BF_RECT
|BF_ADJUST
);
185 INT cy
= r
.bottom
- r
.top
;
186 DrawIconEx (hdc
, r
.left
+ 2, r
.top
, part
->hIcon
, cy
, cy
, 0, 0, DI_NORMAL
);
190 if (part
->style
& SBT_OWNERDRAW
) {
193 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
195 dis
.hwndItem
= infoPtr
->Self
;
198 dis
.itemData
= (ULONG_PTR
)part
->text
;
199 SendMessageW (infoPtr
->Notify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
202 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
208 STATUSBAR_RefreshPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
213 TRACE("item %d\n", itemID
);
215 if (part
->bound
.right
< part
->bound
.left
) return;
217 if (!RectVisible(hdc
, &part
->bound
))
220 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
223 GetClientRect (infoPtr
->Self
, &cr
);
224 DrawThemeBackground(theme
, hdc
, 0, 0, &cr
, &part
->bound
);
228 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
229 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
231 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
232 FillRect(hdc
, &part
->bound
, hbrBk
);
233 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
234 DeleteObject (hbrBk
);
237 STATUSBAR_DrawPart (infoPtr
, hdc
, part
, itemID
);
242 STATUSBAR_Refresh (STATUS_INFO
*infoPtr
, HDC hdc
)
250 if (!IsWindowVisible(infoPtr
->Self
))
253 STATUSBAR_SetPartBounds(infoPtr
);
255 GetClientRect (infoPtr
->Self
, &rect
);
257 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
259 DrawThemeBackground(theme
, hdc
, 0, 0, &rect
, NULL
);
263 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
264 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
266 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
267 FillRect(hdc
, &rect
, hbrBk
);
268 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
269 DeleteObject (hbrBk
);
272 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
274 if (infoPtr
->simple
) {
275 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->part0
, 0);
279 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
280 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->parts
[i
], i
);
284 SelectObject (hdc
, hOldFont
);
286 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
287 && !(GetWindowLongW (infoPtr
->Notify
, GWL_STYLE
) & WS_MAXIMIZE
))
288 STATUSBAR_DrawSizeGrip (theme
, hdc
, &rect
);
295 STATUSBAR_InternalHitTest(const STATUS_INFO
*infoPtr
, const POINT
*pt
)
302 for (i
= 0; i
< infoPtr
->numParts
; i
++)
303 if (pt
->x
>= infoPtr
->parts
[i
].bound
.left
&& pt
->x
<= infoPtr
->parts
[i
].bound
.right
)
310 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
)
312 STATUSWINDOWPART
*part
;
316 /* get our window size */
317 GetClientRect (infoPtr
->Self
, &rect
);
318 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect
));
320 rect
.left
+= infoPtr
->horizontalBorder
;
321 rect
.top
+= infoPtr
->verticalBorder
;
323 /* set bounds for simple rectangle */
324 infoPtr
->part0
.bound
= rect
;
326 /* set bounds for non-simple rectangles */
327 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
328 part
= &infoPtr
->parts
[i
];
329 r
= &infoPtr
->parts
[i
].bound
;
331 r
->bottom
= rect
.bottom
;
335 r
->left
= infoPtr
->parts
[i
-1].bound
.right
+ infoPtr
->horizontalGap
;
337 r
->right
= rect
.right
;
341 if (infoPtr
->hwndToolTip
) {
344 ti
.cbSize
= sizeof(TTTOOLINFOW
);
345 ti
.hwnd
= infoPtr
->Self
;
348 SendMessageW (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
,
356 STATUSBAR_Relay2Tip (const STATUS_INFO
*infoPtr
, UINT uMsg
,
357 WPARAM wParam
, LPARAM lParam
)
361 msg
.hwnd
= infoPtr
->Self
;
365 msg
.time
= GetMessageTime ();
366 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
367 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
369 return SendMessageW (infoPtr
->hwndToolTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
374 STATUSBAR_GetBorders (const STATUS_INFO
*infoPtr
, INT out
[])
377 out
[0] = infoPtr
->horizontalBorder
;
378 out
[1] = infoPtr
->verticalBorder
;
379 out
[2] = infoPtr
->horizontalGap
;
386 STATUSBAR_SetBorders (STATUS_INFO
*infoPtr
, const INT in
[])
389 infoPtr
->horizontalBorder
= in
[0];
390 infoPtr
->verticalBorder
= in
[1];
391 infoPtr
->horizontalGap
= in
[2];
392 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
399 STATUSBAR_GetIcon (const STATUS_INFO
*infoPtr
, INT nPart
)
401 TRACE("%d\n", nPart
);
402 /* MSDN says: "simple parts are indexed with -1" */
403 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
407 return (infoPtr
->part0
.hIcon
);
409 return (infoPtr
->parts
[nPart
].hIcon
);
414 STATUSBAR_GetParts (const STATUS_INFO
*infoPtr
, INT num_parts
, INT parts
[])
418 TRACE("(%d)\n", num_parts
);
420 for (i
= 0; i
< num_parts
; i
++) {
421 parts
[i
] = infoPtr
->parts
[i
].x
;
424 return infoPtr
->numParts
;
429 STATUSBAR_GetRect (const STATUS_INFO
*infoPtr
, INT nPart
, LPRECT rect
)
431 TRACE("part %d\n", nPart
);
432 if(nPart
>= infoPtr
->numParts
|| nPart
< 0)
435 *rect
= infoPtr
->part0
.bound
;
437 *rect
= infoPtr
->parts
[nPart
].bound
;
443 STATUSBAR_GetTextA (STATUS_INFO
*infoPtr
, INT nPart
, LPSTR buf
)
445 STATUSWINDOWPART
*part
;
448 TRACE("part %d\n", nPart
);
450 /* MSDN says: "simple parts use index of 0", so this check is ok. */
451 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
454 part
= &infoPtr
->part0
;
456 part
= &infoPtr
->parts
[nPart
];
458 if (part
->style
& SBT_OWNERDRAW
)
459 result
= (LRESULT
)part
->text
;
461 DWORD len
= part
->text
? WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1,
462 NULL
, 0, NULL
, NULL
) - 1 : 0;
463 result
= MAKELONG( len
, part
->style
);
464 if (part
->text
&& buf
)
465 WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1, buf
, len
+1, NULL
, NULL
);
472 STATUSBAR_GetTextW (STATUS_INFO
*infoPtr
, INT nPart
, LPWSTR buf
)
474 STATUSWINDOWPART
*part
;
477 TRACE("part %d\n", nPart
);
478 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
481 part
= &infoPtr
->part0
;
483 part
= &infoPtr
->parts
[nPart
];
485 if (part
->style
& SBT_OWNERDRAW
)
486 result
= (LRESULT
)part
->text
;
488 result
= part
->text
? lstrlenW (part
->text
) : 0;
489 result
|= (part
->style
<< 16);
490 if (part
->text
&& buf
)
491 lstrcpyW (buf
, part
->text
);
498 STATUSBAR_GetTextLength (STATUS_INFO
*infoPtr
, INT nPart
)
500 STATUSWINDOWPART
*part
;
503 TRACE("part %d\n", nPart
);
505 /* MSDN says: "simple parts use index of 0", so this check is ok. */
506 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
509 part
= &infoPtr
->part0
;
511 part
= &infoPtr
->parts
[nPart
];
513 if ((~part
->style
& SBT_OWNERDRAW
) && part
->text
)
514 result
= lstrlenW(part
->text
);
518 result
|= (part
->style
<< 16);
523 STATUSBAR_GetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR tip
, INT size
)
527 CHAR buf
[INFOTIPSIZE
];
530 if (infoPtr
->hwndToolTip
) {
532 ti
.cbSize
= sizeof(TTTOOLINFOA
);
533 ti
.hwnd
= infoPtr
->Self
;
536 SendMessageA (infoPtr
->hwndToolTip
, TTM_GETTEXTA
, 0, (LPARAM
)&ti
);
538 lstrcpynA (tip
, buf
, size
);
545 STATUSBAR_GetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR tip
, INT size
)
549 WCHAR buf
[INFOTIPSIZE
];
552 if (infoPtr
->hwndToolTip
) {
554 ti
.cbSize
= sizeof(TTTOOLINFOW
);
555 ti
.hwnd
= infoPtr
->Self
;
558 SendMessageW(infoPtr
->hwndToolTip
, TTM_GETTEXTW
, 0, (LPARAM
)&ti
);
560 lstrcpynW(tip
, buf
, size
);
568 STATUSBAR_SetBkColor (STATUS_INFO
*infoPtr
, COLORREF color
)
572 oldBkColor
= infoPtr
->clrBk
;
573 infoPtr
->clrBk
= color
;
574 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
576 TRACE("CREF: %08x -> %08x\n", oldBkColor
, infoPtr
->clrBk
);
582 STATUSBAR_SetIcon (STATUS_INFO
*infoPtr
, INT nPart
, HICON hIcon
)
584 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
587 TRACE("setting part %d\n", nPart
);
589 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
591 if (infoPtr
->part0
.hIcon
== hIcon
) /* same as - no redraw */
593 infoPtr
->part0
.hIcon
= hIcon
;
595 InvalidateRect(infoPtr
->Self
, &infoPtr
->part0
.bound
, FALSE
);
597 if (infoPtr
->parts
[nPart
].hIcon
== hIcon
) /* same as - no redraw */
600 infoPtr
->parts
[nPart
].hIcon
= hIcon
;
601 if (!(infoPtr
->simple
))
602 InvalidateRect(infoPtr
->Self
, &infoPtr
->parts
[nPart
].bound
, FALSE
);
609 STATUSBAR_SetMinHeight (STATUS_INFO
*infoPtr
, INT height
)
611 DWORD ysize
= GetSystemMetrics(SM_CYSIZE
);
612 if (ysize
& 1) ysize
--;
613 infoPtr
->minHeight
= max(height
, ysize
);
614 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
615 /* like native, don't resize the control */
621 STATUSBAR_SetParts (STATUS_INFO
*infoPtr
, INT count
, LPINT parts
)
623 STATUSWINDOWPART
*tmp
;
626 TRACE("(%d,%p)\n", count
, parts
);
628 if(!count
) return FALSE
;
630 oldNumParts
= infoPtr
->numParts
;
631 infoPtr
->numParts
= count
;
632 if (oldNumParts
> infoPtr
->numParts
) {
633 for (i
= infoPtr
->numParts
; i
< oldNumParts
; i
++) {
634 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
635 Free (infoPtr
->parts
[i
].text
);
637 } else if (oldNumParts
< infoPtr
->numParts
) {
638 tmp
= Alloc (sizeof(STATUSWINDOWPART
) * infoPtr
->numParts
);
639 if (!tmp
) return FALSE
;
640 for (i
= 0; i
< oldNumParts
; i
++) {
641 tmp
[i
] = infoPtr
->parts
[i
];
643 Free (infoPtr
->parts
);
644 infoPtr
->parts
= tmp
;
646 if (oldNumParts
== infoPtr
->numParts
) {
647 for (i
=0; i
< oldNumParts
; i
++)
648 if (infoPtr
->parts
[i
].x
!= parts
[i
])
650 if (i
==oldNumParts
) /* Unchanged? no need to redraw! */
654 for (i
= 0; i
< infoPtr
->numParts
; i
++)
655 infoPtr
->parts
[i
].x
= parts
[i
];
657 if (infoPtr
->hwndToolTip
) {
660 WCHAR wEmpty
[] = L
"";
662 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
663 ti
.cbSize
= sizeof(TTTOOLINFOW
);
664 ti
.hwnd
= infoPtr
->Self
;
665 ti
.lpszText
= wEmpty
;
667 nTipCount
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETTOOLCOUNT
, 0, 0);
668 if (nTipCount
< infoPtr
->numParts
) {
670 for (i
= nTipCount
; i
< infoPtr
->numParts
; i
++) {
671 TRACE("add tool %d\n", i
);
673 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
677 else if (nTipCount
> infoPtr
->numParts
) {
679 for (i
= nTipCount
- 1; i
>= infoPtr
->numParts
; i
--) {
680 TRACE("delete tool %d\n", i
);
682 SendMessageW (infoPtr
->hwndToolTip
, TTM_DELTOOLW
,
687 STATUSBAR_SetPartBounds (infoPtr
);
688 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
694 STATUSBAR_SetTextT (STATUS_INFO
*infoPtr
, INT nPart
, WORD style
,
695 LPWSTR text
, BOOL isW
)
697 STATUSWINDOWPART
*part
=NULL
;
698 BOOL changed
= FALSE
;
701 if (style
& SBT_OWNERDRAW
) {
702 TRACE("part %d, text %p\n",nPart
,text
);
704 else TRACE("part %d, text %s\n", nPart
, debugstr_t(text
, isW
));
706 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
707 * window is assumed to be a simple window */
709 if (nPart
== 0x00ff) {
710 part
= &infoPtr
->part0
;
712 if (infoPtr
->parts
&& nPart
>= 0 && nPart
< infoPtr
->numParts
) {
713 part
= &infoPtr
->parts
[nPart
];
716 if (!part
) return FALSE
;
718 if (part
->style
!= style
)
721 oldStyle
= part
->style
;
723 if (style
& SBT_OWNERDRAW
) {
724 if (!(oldStyle
& SBT_OWNERDRAW
))
732 LPCSTR atxt
= (LPCSTR
)text
;
733 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, NULL
, 0 );
734 ntext
= Alloc( (len
+ 1)*sizeof(WCHAR
) );
735 if (!ntext
) return FALSE
;
736 MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, ntext
, len
);
738 ntext
= Alloc( (lstrlenW(text
) + 1)*sizeof(WCHAR
) );
739 if (!ntext
) return FALSE
;
740 lstrcpyW (ntext
, text
);
743 /* replace nonprintable characters with spaces */
747 if(*idx
< ' ' && *idx
!= '\t')
753 /* check if text is unchanged -> no need to redraw */
755 if (!changed
&& part
->text
&& !lstrcmpW(ntext
, part
->text
)) {
760 if (!changed
&& !part
->text
)
764 if (!(oldStyle
& SBT_OWNERDRAW
))
768 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
769 UpdateWindow(infoPtr
->Self
);
776 STATUSBAR_SetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR text
)
778 TRACE("part %d: \"%s\"\n", id
, text
);
779 if (infoPtr
->hwndToolTip
) {
781 ti
.cbSize
= sizeof(TTTOOLINFOA
);
782 ti
.hwnd
= infoPtr
->Self
;
786 SendMessageA (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTA
, 0, (LPARAM
)&ti
);
794 STATUSBAR_SetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR text
)
796 TRACE("part %d: \"%s\"\n", id
, debugstr_w(text
));
797 if (infoPtr
->hwndToolTip
) {
799 ti
.cbSize
= sizeof(TTTOOLINFOW
);
800 ti
.hwnd
= infoPtr
->Self
;
804 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
811 static inline LRESULT
812 STATUSBAR_SetUnicodeFormat (STATUS_INFO
*infoPtr
, BOOL bUnicode
)
814 BOOL bOld
= infoPtr
->bUnicode
;
816 TRACE("(0x%x)\n", bUnicode
);
817 infoPtr
->bUnicode
= bUnicode
;
824 STATUSBAR_Simple (STATUS_INFO
*infoPtr
, BOOL simple
)
828 TRACE("(simple=%d)\n", simple
);
829 if (infoPtr
->simple
== simple
) /* no need to change */
832 infoPtr
->simple
= simple
;
834 /* send notification */
835 nmhdr
.hwndFrom
= infoPtr
->Self
;
836 nmhdr
.idFrom
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
837 nmhdr
.code
= SBN_SIMPLEMODECHANGE
;
838 SendMessageW (infoPtr
->Notify
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
839 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
845 STATUSBAR_WMDestroy (STATUS_INFO
*infoPtr
)
850 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
851 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
852 Free (infoPtr
->parts
[i
].text
);
854 if (!(infoPtr
->part0
.style
& SBT_OWNERDRAW
))
855 Free (infoPtr
->part0
.text
);
856 Free (infoPtr
->parts
);
858 /* delete default font */
859 if (infoPtr
->hDefaultFont
)
860 DeleteObject (infoPtr
->hDefaultFont
);
862 /* delete tool tip control */
863 if (infoPtr
->hwndToolTip
)
864 DestroyWindow (infoPtr
->hwndToolTip
);
866 CloseThemeData (GetWindowTheme (infoPtr
->Self
));
868 SetWindowLongPtrW(infoPtr
->Self
, 0, 0);
875 STATUSBAR_WMCreate (HWND hwnd
, const CREATESTRUCTA
*lpCreate
)
877 STATUS_INFO
*infoPtr
;
878 NONCLIENTMETRICSW nclm
;
884 infoPtr
= Alloc (sizeof(STATUS_INFO
));
885 if (!infoPtr
) goto create_fail
;
886 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
888 infoPtr
->Self
= hwnd
;
889 infoPtr
->Notify
= lpCreate
->hwndParent
;
890 infoPtr
->numParts
= 1;
892 infoPtr
->simple
= FALSE
;
893 infoPtr
->clrBk
= CLR_DEFAULT
;
895 infoPtr
->horizontalBorder
= HORZ_BORDER
;
896 infoPtr
->verticalBorder
= VERT_BORDER
;
897 infoPtr
->horizontalGap
= HORZ_GAP
;
898 infoPtr
->minHeight
= GetSystemMetrics(SM_CYSIZE
);
899 if (infoPtr
->minHeight
& 1) infoPtr
->minHeight
--;
901 STATUSBAR_NotifyFormat(infoPtr
, infoPtr
->Notify
, NF_REQUERY
);
903 ZeroMemory (&nclm
, sizeof(nclm
));
904 nclm
.cbSize
= sizeof(nclm
);
905 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0);
906 infoPtr
->hDefaultFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
908 GetClientRect (hwnd
, &rect
);
910 /* initialize simple case */
911 infoPtr
->part0
.bound
= rect
;
912 infoPtr
->part0
.text
= 0;
913 infoPtr
->part0
.x
= 0;
914 infoPtr
->part0
.style
= 0;
915 infoPtr
->part0
.hIcon
= 0;
917 /* initialize first part */
918 infoPtr
->parts
= Alloc (sizeof(STATUSWINDOWPART
));
919 if (!infoPtr
->parts
) goto create_fail
;
920 infoPtr
->parts
[0].bound
= rect
;
921 infoPtr
->parts
[0].text
= 0;
922 infoPtr
->parts
[0].x
= -1;
923 infoPtr
->parts
[0].style
= 0;
924 infoPtr
->parts
[0].hIcon
= 0;
926 OpenThemeData (hwnd
, themeClass
);
928 if (lpCreate
->lpszName
&& (len
= lstrlenW ((LPCWSTR
)lpCreate
->lpszName
)))
930 infoPtr
->parts
[0].text
= Alloc ((len
+ 1)*sizeof(WCHAR
));
931 if (!infoPtr
->parts
[0].text
) goto create_fail
;
932 lstrcpyW (infoPtr
->parts
[0].text
, (LPCWSTR
)lpCreate
->lpszName
);
935 dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
936 /* native seems to clear WS_BORDER, too */
937 dwStyle
&= ~WS_BORDER
;
938 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
940 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
942 if (dwStyle
& SBT_TOOLTIPS
) {
943 infoPtr
->hwndToolTip
=
944 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
| TTS_ALWAYSTIP
,
945 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
946 CW_USEDEFAULT
, hwnd
, 0,
947 (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
), NULL
);
949 if (infoPtr
->hwndToolTip
) {
950 NMTOOLTIPSCREATED nmttc
;
952 nmttc
.hdr
.hwndFrom
= hwnd
;
953 nmttc
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
954 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
955 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
957 SendMessageW (lpCreate
->hwndParent
, WM_NOTIFY
, nmttc
.hdr
.idFrom
, (LPARAM
)&nmttc
);
965 if (infoPtr
) STATUSBAR_WMDestroy(infoPtr
);
970 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
971 * of the first part only (usual behaviour) */
973 STATUSBAR_WMGetText (const STATUS_INFO
*infoPtr
, INT size
, LPWSTR buf
)
978 if (!(infoPtr
->parts
[0].text
))
981 len
= lstrlenW (infoPtr
->parts
[0].text
);
985 else if (size
> len
) {
986 lstrcpyW (buf
, infoPtr
->parts
[0].text
);
990 memcpy (buf
, infoPtr
->parts
[0].text
, (size
- 1) * sizeof(WCHAR
));
998 STATUSBAR_WMNCHitTest (const STATUS_INFO
*infoPtr
, INT x
, INT y
)
1000 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
1001 && !(GetWindowLongW (infoPtr
->Notify
, GWL_STYLE
) & WS_MAXIMIZE
)) {
1005 GetClientRect (infoPtr
->Self
, &rect
);
1009 ScreenToClient (infoPtr
->Self
, &pt
);
1011 if (pt
.x
>= rect
.right
- GetSystemMetrics(SM_CXVSCROLL
))
1013 if (GetWindowLongW( infoPtr
->Self
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) return HTBOTTOMLEFT
;
1014 else return HTBOTTOMRIGHT
;
1023 STATUSBAR_WMPaint (STATUS_INFO
*infoPtr
, HDC hdc
)
1028 if (hdc
) return STATUSBAR_Refresh (infoPtr
, hdc
);
1029 hdc
= BeginPaint (infoPtr
->Self
, &ps
);
1030 STATUSBAR_Refresh (infoPtr
, hdc
);
1031 EndPaint (infoPtr
->Self
, &ps
);
1038 STATUSBAR_WMSetFont (STATUS_INFO
*infoPtr
, HFONT font
, BOOL redraw
)
1040 infoPtr
->hFont
= font
;
1041 TRACE("%p\n", infoPtr
->hFont
);
1043 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
1044 SendMessageW(infoPtr
->Self
, WM_SIZE
, 0, 0); /* update size */
1046 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
1053 STATUSBAR_WMSetText (const STATUS_INFO
*infoPtr
, LPCSTR text
)
1055 STATUSWINDOWPART
*part
;
1059 if (infoPtr
->numParts
== 0)
1062 part
= &infoPtr
->parts
[0];
1063 /* duplicate string */
1067 if (text
&& (len
= lstrlenW((LPCWSTR
)text
))) {
1068 part
->text
= Alloc ((len
+1)*sizeof(WCHAR
));
1069 if (!part
->text
) return FALSE
;
1070 lstrcpyW (part
->text
, (LPCWSTR
)text
);
1073 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
1080 STATUSBAR_WMSize (STATUS_INFO
*infoPtr
, WORD flags
)
1085 /* Need to resize width to match parent */
1086 TRACE("flags %04x\n", flags
);
1088 if (flags
!= SIZE_RESTORED
&& flags
!= SIZE_MAXIMIZED
) {
1089 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1093 if (GetWindowLongW(infoPtr
->Self
, GWL_STYLE
) & CCS_NORESIZE
) return FALSE
;
1095 /* width and height don't apply */
1096 if (!GetClientRect (infoPtr
->Notify
, &parent_rect
))
1099 width
= parent_rect
.right
- parent_rect
.left
;
1100 x
= parent_rect
.left
;
1101 y
= parent_rect
.bottom
- infoPtr
->height
;
1102 MoveWindow (infoPtr
->Self
, x
, y
, width
, infoPtr
->height
, TRUE
);
1103 STATUSBAR_SetPartBounds (infoPtr
);
1108 /* update theme after a WM_THEMECHANGED message */
1109 static LRESULT
theme_changed (const STATUS_INFO
* infoPtr
)
1111 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
1112 CloseThemeData (theme
);
1113 OpenThemeData (infoPtr
->Self
, themeClass
);
1119 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
)
1121 if (cmd
== NF_REQUERY
) {
1122 INT i
= SendMessageW(from
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->Self
, NF_QUERY
);
1123 infoPtr
->bUnicode
= (i
== NFR_UNICODE
);
1125 return infoPtr
->bUnicode
? NFR_UNICODE
: NFR_ANSI
;
1130 STATUSBAR_SendMouseNotify(const STATUS_INFO
*infoPtr
, UINT code
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1134 TRACE("code %04x, lParam=%lx\n", code
, lParam
);
1135 nm
.hdr
.hwndFrom
= infoPtr
->Self
;
1136 nm
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->Self
, GWLP_ID
);
1138 nm
.pt
.x
= (short)LOWORD(lParam
);
1139 nm
.pt
.y
= (short)HIWORD(lParam
);
1140 nm
.dwItemSpec
= STATUSBAR_InternalHitTest(infoPtr
, &nm
.pt
);
1142 nm
.dwHitInfo
= 0x30000; /* seems constant */
1144 /* Do default processing if WM_NOTIFY returns zero */
1145 if(!SendMessageW(infoPtr
->Notify
, WM_NOTIFY
, nm
.hdr
.idFrom
, (LPARAM
)&nm
))
1147 return DefWindowProcW(infoPtr
->Self
, msg
, wParam
, lParam
);
1154 static LRESULT WINAPI
1155 StatusWindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1157 STATUS_INFO
*infoPtr
= (STATUS_INFO
*)GetWindowLongPtrW (hwnd
, 0);
1158 INT nPart
= ((INT
) wParam
) & 0x00ff;
1161 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1162 if (!infoPtr
&& msg
!= WM_CREATE
)
1163 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1167 return STATUSBAR_GetBorders (infoPtr
, (INT
*)lParam
);
1170 return (LRESULT
)STATUSBAR_GetIcon (infoPtr
, nPart
);
1173 return STATUSBAR_GetParts (infoPtr
, (INT
)wParam
, (INT
*)lParam
);
1176 return STATUSBAR_GetRect (infoPtr
, nPart
, (LPRECT
)lParam
);
1179 return STATUSBAR_GetTextA (infoPtr
, nPart
, (LPSTR
)lParam
);
1182 return STATUSBAR_GetTextW (infoPtr
, nPart
, (LPWSTR
)lParam
);
1184 case SB_GETTEXTLENGTHA
:
1185 case SB_GETTEXTLENGTHW
:
1186 return STATUSBAR_GetTextLength (infoPtr
, nPart
);
1188 case SB_GETTIPTEXTA
:
1189 return STATUSBAR_GetTipTextA (infoPtr
, LOWORD(wParam
), (LPSTR
)lParam
, HIWORD(wParam
));
1191 case SB_GETTIPTEXTW
:
1192 return STATUSBAR_GetTipTextW (infoPtr
, LOWORD(wParam
), (LPWSTR
)lParam
, HIWORD(wParam
));
1194 case SB_GETUNICODEFORMAT
:
1195 return infoPtr
->bUnicode
;
1198 return infoPtr
->simple
;
1201 return STATUSBAR_SetBorders (infoPtr
, (INT
*)lParam
);
1204 return STATUSBAR_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1207 return STATUSBAR_SetIcon (infoPtr
, nPart
, (HICON
)lParam
);
1209 case SB_SETMINHEIGHT
:
1210 return STATUSBAR_SetMinHeight (infoPtr
, (INT
)wParam
);
1213 return STATUSBAR_SetParts (infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
1216 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, FALSE
);
1219 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, TRUE
);
1221 case SB_SETTIPTEXTA
:
1222 return STATUSBAR_SetTipTextA (infoPtr
, (INT
)wParam
, (LPSTR
)lParam
);
1224 case SB_SETTIPTEXTW
:
1225 return STATUSBAR_SetTipTextW (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1227 case SB_SETUNICODEFORMAT
:
1228 return STATUSBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1231 return STATUSBAR_Simple (infoPtr
, (BOOL
)wParam
);
1234 return STATUSBAR_WMCreate (hwnd
, (LPCREATESTRUCTA
)lParam
);
1237 return STATUSBAR_WMDestroy (infoPtr
);
1240 return (LRESULT
)(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
1243 return STATUSBAR_WMGetText (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1245 case WM_GETTEXTLENGTH
:
1246 return LOWORD(STATUSBAR_GetTextLength (infoPtr
, 0));
1248 case WM_LBUTTONDBLCLK
:
1249 return STATUSBAR_SendMouseNotify(infoPtr
, NM_DBLCLK
, msg
, wParam
, lParam
);
1252 return STATUSBAR_SendMouseNotify(infoPtr
, NM_CLICK
, msg
, wParam
, lParam
);
1255 return STATUSBAR_Relay2Tip (infoPtr
, msg
, wParam
, lParam
);
1258 res
= STATUSBAR_WMNCHitTest(infoPtr
, (short)LOWORD(lParam
),
1259 (short)HIWORD(lParam
));
1260 if (res
!= HTERROR
) return res
;
1261 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1263 case WM_NCLBUTTONUP
:
1264 case WM_NCLBUTTONDOWN
:
1265 PostMessageW (infoPtr
->Notify
, msg
, wParam
, lParam
);
1268 case WM_NOTIFYFORMAT
:
1269 return STATUSBAR_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
1271 case WM_PRINTCLIENT
:
1273 return STATUSBAR_WMPaint (infoPtr
, (HDC
)wParam
);
1275 case WM_RBUTTONDBLCLK
:
1276 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RDBLCLK
, msg
, wParam
, lParam
);
1279 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RCLICK
, msg
, wParam
, lParam
);
1282 return STATUSBAR_WMSetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
1285 return STATUSBAR_WMSetText (infoPtr
, (LPCSTR
)lParam
);
1288 if (STATUSBAR_WMSize (infoPtr
, (WORD
)wParam
)) return 0;
1289 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1291 case WM_SYSCOLORCHANGE
:
1292 COMCTL32_RefreshSysColors();
1295 case WM_THEMECHANGED
:
1296 return theme_changed (infoPtr
);
1299 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
1300 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1301 msg
, wParam
, lParam
);
1302 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1307 /***********************************************************************
1308 * STATUS_Register [Internal]
1310 * Registers the status window class.
1314 STATUS_Register (void)
1318 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1319 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
;
1320 wndClass
.lpfnWndProc
= StatusWindowProc
;
1321 wndClass
.cbClsExtra
= 0;
1322 wndClass
.cbWndExtra
= sizeof(STATUS_INFO
*);
1323 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1324 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1325 wndClass
.lpszClassName
= STATUSCLASSNAMEW
;
1327 RegisterClassW (&wndClass
);
1331 /***********************************************************************
1332 * STATUS_Unregister [Internal]
1334 * Unregisters the status window class.
1338 STATUS_Unregister (void)
1340 UnregisterClassW (STATUSCLASSNAMEW
, NULL
);