26e9d3a1c6f0f65351d5261ea66ecaf8b9e64d92
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)
39 #include "wine/unicode.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(statusbar
);
66 UINT minHeight
; /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
71 COLORREF clrBk
; /* background color */
72 BOOL bUnicode
; /* notify format. TRUE if notifies in Unicode */
73 STATUSWINDOWPART part0
; /* simple window */
74 STATUSWINDOWPART
* parts
;
81 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
82 * The second cdrom contains executables drawstat.exe, gettext.exe,
83 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
90 static const WCHAR themeClass
[] = { 'S','t','a','t','u','s',0 };
94 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
);
96 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
);
98 static inline LPCSTR
debugstr_t(LPCWSTR text
, BOOL isW
)
100 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
104 STATUSBAR_ComputeHeight(STATUS_INFO
*infoPtr
)
111 COMCTL32_GetFontMetrics(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
, &tm
);
112 margin
= (tm
.tmInternalLeading
? tm
.tmInternalLeading
: 2);
113 height
= max(tm
.tmHeight
+ margin
+ 2*GetSystemMetrics(SM_CYBORDER
), infoPtr
->minHeight
) + infoPtr
->verticalBorder
;
115 if ((theme
= GetWindowTheme(infoPtr
->Self
)))
117 /* Determine bar height from theme such that the content area is
118 * textHeight pixels large */
119 HDC hdc
= GetDC(infoPtr
->Self
);
122 SetRect(&r
, 0, 0, 0, max(infoPtr
->minHeight
, tm
.tmHeight
));
123 if (SUCCEEDED(GetThemeBackgroundExtent(theme
, hdc
, SP_PANE
, 0, &r
, &r
)))
125 height
= r
.bottom
- r
.top
;
127 ReleaseDC(infoPtr
->Self
, hdc
);
130 TRACE(" textHeight=%d+%d, final height=%d\n", tm
.tmHeight
, tm
.tmInternalLeading
, height
);
135 STATUSBAR_DrawSizeGrip (HTHEME theme
, HDC hdc
, LPRECT lpRect
)
139 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect
));
144 if (SUCCEEDED (GetThemePartSize (theme
, hdc
, SP_GRIPPER
, 0, lpRect
,
145 TS_DRAW
, &gripperSize
)))
147 rc
.left
= rc
.right
- gripperSize
.cx
;
148 rc
.top
= rc
.bottom
- gripperSize
.cy
;
149 if (SUCCEEDED (DrawThemeBackground(theme
, hdc
, SP_GRIPPER
, 0, &rc
, NULL
)))
154 rc
.left
= max( rc
.left
, rc
.right
- GetSystemMetrics(SM_CXVSCROLL
) - 1 );
155 rc
.top
= max( rc
.top
, rc
.bottom
- GetSystemMetrics(SM_CYHSCROLL
) - 1 );
156 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
161 STATUSBAR_DrawPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
163 RECT r
= part
->bound
;
164 UINT border
= BDR_SUNKENOUTER
;
165 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
166 int themePart
= SP_PANE
;
169 TRACE("part bound %s\n", wine_dbgstr_rect(&r
));
170 if (part
->style
& SBT_POPOUT
)
171 border
= BDR_RAISEDOUTER
;
172 else if (part
->style
& SBT_NOBORDERS
)
177 if ((GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
178 && (infoPtr
->simple
|| (itemID
== (infoPtr
->numParts
-1))))
179 themePart
= SP_GRIPPERPANE
;
180 DrawThemeBackground(theme
, hdc
, themePart
, 0, &r
, NULL
);
183 DrawEdge(hdc
, &r
, border
, BF_RECT
|BF_ADJUST
);
186 INT cy
= r
.bottom
- r
.top
;
187 DrawIconEx (hdc
, r
.left
+ 2, r
.top
, part
->hIcon
, cy
, cy
, 0, 0, DI_NORMAL
);
191 if (part
->style
& SBT_OWNERDRAW
) {
194 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
196 dis
.hwndItem
= infoPtr
->Self
;
199 dis
.itemData
= (ULONG_PTR
)part
->text
;
200 SendMessageW (infoPtr
->Notify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
207 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
213 DrawThemeText(theme
, hdc
, SP_PANE
, 0, part
->text
, -1, DT_VCENTER
|DT_SINGLELINE
|DT_NOPREFIX
, 0, &r
);
216 DrawStatusTextW (hdc
, &r
, part
->text
, SBT_NOBORDERS
);
223 STATUSBAR_RefreshPart (const STATUS_INFO
*infoPtr
, HDC hdc
, const STATUSWINDOWPART
*part
, int itemID
)
228 TRACE("item %d\n", itemID
);
230 if (part
->bound
.right
< part
->bound
.left
) return;
232 if (!RectVisible(hdc
, &part
->bound
))
235 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
238 GetClientRect (infoPtr
->Self
, &cr
);
239 DrawThemeBackground(theme
, hdc
, 0, 0, &cr
, &part
->bound
);
243 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
244 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
246 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
247 FillRect(hdc
, &part
->bound
, hbrBk
);
248 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
249 DeleteObject (hbrBk
);
252 STATUSBAR_DrawPart (infoPtr
, hdc
, part
, itemID
);
257 STATUSBAR_Refresh (STATUS_INFO
*infoPtr
, HDC hdc
)
265 if (!IsWindowVisible(infoPtr
->Self
))
268 STATUSBAR_SetPartBounds(infoPtr
);
270 GetClientRect (infoPtr
->Self
, &rect
);
272 if ((theme
= GetWindowTheme (infoPtr
->Self
)))
274 DrawThemeBackground(theme
, hdc
, 0, 0, &rect
, NULL
);
278 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
279 hbrBk
= CreateSolidBrush (infoPtr
->clrBk
);
281 hbrBk
= GetSysColorBrush (COLOR_3DFACE
);
282 FillRect(hdc
, &rect
, hbrBk
);
283 if (infoPtr
->clrBk
!= CLR_DEFAULT
)
284 DeleteObject (hbrBk
);
287 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
289 if (infoPtr
->simple
) {
290 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->part0
, 0);
294 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
295 STATUSBAR_RefreshPart (infoPtr
, hdc
, &infoPtr
->parts
[i
], i
);
299 SelectObject (hdc
, hOldFont
);
301 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
)
302 STATUSBAR_DrawSizeGrip (theme
, hdc
, &rect
);
309 STATUSBAR_InternalHitTest(const STATUS_INFO
*infoPtr
, const POINT
*pt
)
316 for (i
= 0; i
< infoPtr
->numParts
; i
++)
317 if (pt
->x
>= infoPtr
->parts
[i
].bound
.left
&& pt
->x
<= infoPtr
->parts
[i
].bound
.right
)
324 STATUSBAR_SetPartBounds (STATUS_INFO
*infoPtr
)
326 STATUSWINDOWPART
*part
;
330 /* get our window size */
331 GetClientRect (infoPtr
->Self
, &rect
);
332 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect
));
334 rect
.left
+= infoPtr
->horizontalBorder
;
335 rect
.top
+= infoPtr
->verticalBorder
;
337 /* set bounds for simple rectangle */
338 infoPtr
->part0
.bound
= rect
;
340 /* set bounds for non-simple rectangles */
341 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
342 part
= &infoPtr
->parts
[i
];
343 r
= &infoPtr
->parts
[i
].bound
;
345 r
->bottom
= rect
.bottom
;
349 r
->left
= infoPtr
->parts
[i
-1].bound
.right
+ infoPtr
->horizontalGap
;
351 r
->right
= rect
.right
;
355 if (infoPtr
->hwndToolTip
) {
358 ti
.cbSize
= sizeof(TTTOOLINFOW
);
359 ti
.hwnd
= infoPtr
->Self
;
362 SendMessageW (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
,
370 STATUSBAR_Relay2Tip (const STATUS_INFO
*infoPtr
, UINT uMsg
,
371 WPARAM wParam
, LPARAM lParam
)
375 msg
.hwnd
= infoPtr
->Self
;
379 msg
.time
= GetMessageTime ();
380 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
381 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
383 return SendMessageW (infoPtr
->hwndToolTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
388 STATUSBAR_GetBorders (const STATUS_INFO
*infoPtr
, INT out
[])
391 out
[0] = infoPtr
->horizontalBorder
;
392 out
[1] = infoPtr
->verticalBorder
;
393 out
[2] = infoPtr
->horizontalGap
;
400 STATUSBAR_SetBorders (STATUS_INFO
*infoPtr
, const INT in
[])
403 infoPtr
->horizontalBorder
= in
[0];
404 infoPtr
->verticalBorder
= in
[1];
405 infoPtr
->horizontalGap
= in
[2];
406 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
413 STATUSBAR_GetIcon (const STATUS_INFO
*infoPtr
, INT nPart
)
415 TRACE("%d\n", nPart
);
416 /* MSDN says: "simple parts are indexed with -1" */
417 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
421 return (infoPtr
->part0
.hIcon
);
423 return (infoPtr
->parts
[nPart
].hIcon
);
428 STATUSBAR_GetParts (const STATUS_INFO
*infoPtr
, INT num_parts
, INT parts
[])
432 TRACE("(%d)\n", num_parts
);
434 for (i
= 0; i
< num_parts
; i
++) {
435 parts
[i
] = infoPtr
->parts
[i
].x
;
438 return infoPtr
->numParts
;
443 STATUSBAR_GetRect (const STATUS_INFO
*infoPtr
, INT nPart
, LPRECT rect
)
445 TRACE("part %d\n", nPart
);
446 if(nPart
>= infoPtr
->numParts
|| nPart
< 0)
449 *rect
= infoPtr
->part0
.bound
;
451 *rect
= infoPtr
->parts
[nPart
].bound
;
457 STATUSBAR_GetTextA (STATUS_INFO
*infoPtr
, INT nPart
, LPSTR buf
)
459 STATUSWINDOWPART
*part
;
462 TRACE("part %d\n", nPart
);
464 /* MSDN says: "simple parts use index of 0", so this check is ok. */
465 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
468 part
= &infoPtr
->part0
;
470 part
= &infoPtr
->parts
[nPart
];
472 if (part
->style
& SBT_OWNERDRAW
)
473 result
= (LRESULT
)part
->text
;
475 DWORD len
= part
->text
? WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1,
476 NULL
, 0, NULL
, NULL
) - 1 : 0;
477 result
= MAKELONG( len
, part
->style
);
478 if (part
->text
&& buf
)
479 WideCharToMultiByte( CP_ACP
, 0, part
->text
, -1, buf
, len
+1, NULL
, NULL
);
486 STATUSBAR_GetTextW (STATUS_INFO
*infoPtr
, INT nPart
, LPWSTR buf
)
488 STATUSWINDOWPART
*part
;
491 TRACE("part %d\n", nPart
);
492 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
495 part
= &infoPtr
->part0
;
497 part
= &infoPtr
->parts
[nPart
];
499 if (part
->style
& SBT_OWNERDRAW
)
500 result
= (LRESULT
)part
->text
;
502 result
= part
->text
? strlenW (part
->text
) : 0;
503 result
|= (part
->style
<< 16);
504 if (part
->text
&& buf
)
505 strcpyW (buf
, part
->text
);
512 STATUSBAR_GetTextLength (STATUS_INFO
*infoPtr
, INT nPart
)
514 STATUSWINDOWPART
*part
;
517 TRACE("part %d\n", nPart
);
519 /* MSDN says: "simple parts use index of 0", so this check is ok. */
520 if (nPart
< 0 || nPart
>= infoPtr
->numParts
) return 0;
523 part
= &infoPtr
->part0
;
525 part
= &infoPtr
->parts
[nPart
];
527 if ((~part
->style
& SBT_OWNERDRAW
) && part
->text
)
528 result
= strlenW(part
->text
);
532 result
|= (part
->style
<< 16);
537 STATUSBAR_GetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR tip
, INT size
)
541 CHAR buf
[INFOTIPSIZE
];
544 if (infoPtr
->hwndToolTip
) {
546 ti
.cbSize
= sizeof(TTTOOLINFOA
);
547 ti
.hwnd
= infoPtr
->Self
;
550 SendMessageA (infoPtr
->hwndToolTip
, TTM_GETTEXTA
, 0, (LPARAM
)&ti
);
552 lstrcpynA (tip
, buf
, size
);
559 STATUSBAR_GetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR tip
, INT size
)
563 WCHAR buf
[INFOTIPSIZE
];
566 if (infoPtr
->hwndToolTip
) {
568 ti
.cbSize
= sizeof(TTTOOLINFOW
);
569 ti
.hwnd
= infoPtr
->Self
;
572 SendMessageW(infoPtr
->hwndToolTip
, TTM_GETTEXTW
, 0, (LPARAM
)&ti
);
574 lstrcpynW(tip
, buf
, size
);
582 STATUSBAR_SetBkColor (STATUS_INFO
*infoPtr
, COLORREF color
)
586 oldBkColor
= infoPtr
->clrBk
;
587 infoPtr
->clrBk
= color
;
588 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
590 TRACE("CREF: %08x -> %08x\n", oldBkColor
, infoPtr
->clrBk
);
596 STATUSBAR_SetIcon (STATUS_INFO
*infoPtr
, INT nPart
, HICON hIcon
)
598 if ((nPart
< -1) || (nPart
>= infoPtr
->numParts
))
601 TRACE("setting part %d\n", nPart
);
603 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
605 if (infoPtr
->part0
.hIcon
== hIcon
) /* same as - no redraw */
607 infoPtr
->part0
.hIcon
= hIcon
;
609 InvalidateRect(infoPtr
->Self
, &infoPtr
->part0
.bound
, FALSE
);
611 if (infoPtr
->parts
[nPart
].hIcon
== hIcon
) /* same as - no redraw */
614 infoPtr
->parts
[nPart
].hIcon
= hIcon
;
615 if (!(infoPtr
->simple
))
616 InvalidateRect(infoPtr
->Self
, &infoPtr
->parts
[nPart
].bound
, FALSE
);
623 STATUSBAR_SetMinHeight (STATUS_INFO
*infoPtr
, INT height
)
625 DWORD ysize
= GetSystemMetrics(SM_CYSIZE
);
626 if (ysize
& 1) ysize
--;
627 infoPtr
->minHeight
= max(height
, ysize
);
628 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
629 /* like native, don't resize the control */
635 STATUSBAR_SetParts (STATUS_INFO
*infoPtr
, INT count
, LPINT parts
)
637 STATUSWINDOWPART
*tmp
;
640 TRACE("(%d,%p)\n", count
, parts
);
642 if(!count
) return FALSE
;
644 oldNumParts
= infoPtr
->numParts
;
645 infoPtr
->numParts
= count
;
646 if (oldNumParts
> infoPtr
->numParts
) {
647 for (i
= infoPtr
->numParts
; i
< oldNumParts
; i
++) {
648 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
649 Free (infoPtr
->parts
[i
].text
);
651 } else if (oldNumParts
< infoPtr
->numParts
) {
652 tmp
= Alloc (sizeof(STATUSWINDOWPART
) * infoPtr
->numParts
);
653 if (!tmp
) return FALSE
;
654 for (i
= 0; i
< oldNumParts
; i
++) {
655 tmp
[i
] = infoPtr
->parts
[i
];
657 Free (infoPtr
->parts
);
658 infoPtr
->parts
= tmp
;
660 if (oldNumParts
== infoPtr
->numParts
) {
661 for (i
=0; i
< oldNumParts
; i
++)
662 if (infoPtr
->parts
[i
].x
!= parts
[i
])
664 if (i
==oldNumParts
) /* Unchanged? no need to redraw! */
668 for (i
= 0; i
< infoPtr
->numParts
; i
++)
669 infoPtr
->parts
[i
].x
= parts
[i
];
671 if (infoPtr
->hwndToolTip
) {
676 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
677 ti
.cbSize
= sizeof(TTTOOLINFOW
);
678 ti
.hwnd
= infoPtr
->Self
;
679 ti
.lpszText
= &wEmpty
;
681 nTipCount
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETTOOLCOUNT
, 0, 0);
682 if (nTipCount
< infoPtr
->numParts
) {
684 for (i
= nTipCount
; i
< infoPtr
->numParts
; i
++) {
685 TRACE("add tool %d\n", i
);
687 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
691 else if (nTipCount
> infoPtr
->numParts
) {
693 for (i
= nTipCount
- 1; i
>= infoPtr
->numParts
; i
--) {
694 TRACE("delete tool %d\n", i
);
696 SendMessageW (infoPtr
->hwndToolTip
, TTM_DELTOOLW
,
701 STATUSBAR_SetPartBounds (infoPtr
);
702 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
708 STATUSBAR_SetTextT (STATUS_INFO
*infoPtr
, INT nPart
, WORD style
,
709 LPWSTR text
, BOOL isW
)
711 STATUSWINDOWPART
*part
=NULL
;
712 BOOL changed
= FALSE
;
715 if (style
& SBT_OWNERDRAW
) {
716 TRACE("part %d, text %p\n",nPart
,text
);
718 else TRACE("part %d, text %s\n", nPart
, debugstr_t(text
, isW
));
720 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
721 * window is assumed to be a simple window */
723 if (nPart
== 0x00ff) {
724 part
= &infoPtr
->part0
;
726 if (infoPtr
->parts
&& nPart
>= 0 && nPart
< infoPtr
->numParts
) {
727 part
= &infoPtr
->parts
[nPart
];
730 if (!part
) return FALSE
;
732 if (part
->style
!= style
)
735 oldStyle
= part
->style
;
737 if (style
& SBT_OWNERDRAW
) {
738 if (!(oldStyle
& SBT_OWNERDRAW
))
746 LPCSTR atxt
= (LPCSTR
)text
;
747 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, NULL
, 0 );
748 ntext
= Alloc( (len
+ 1)*sizeof(WCHAR
) );
749 if (!ntext
) return FALSE
;
750 MultiByteToWideChar( CP_ACP
, 0, atxt
, -1, ntext
, len
);
752 ntext
= Alloc( (strlenW(text
) + 1)*sizeof(WCHAR
) );
753 if (!ntext
) return FALSE
;
754 strcpyW (ntext
, text
);
757 /* replace nonprintable characters with spaces */
767 /* check if text is unchanged -> no need to redraw */
769 if (!changed
&& part
->text
&& !lstrcmpW(ntext
, part
->text
)) {
774 if (!changed
&& !part
->text
)
778 if (!(oldStyle
& SBT_OWNERDRAW
))
782 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
783 UpdateWindow(infoPtr
->Self
);
790 STATUSBAR_SetTipTextA (const STATUS_INFO
*infoPtr
, INT id
, LPSTR text
)
792 TRACE("part %d: \"%s\"\n", id
, text
);
793 if (infoPtr
->hwndToolTip
) {
795 ti
.cbSize
= sizeof(TTTOOLINFOA
);
796 ti
.hwnd
= infoPtr
->Self
;
800 SendMessageA (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTA
, 0, (LPARAM
)&ti
);
808 STATUSBAR_SetTipTextW (const STATUS_INFO
*infoPtr
, INT id
, LPWSTR text
)
810 TRACE("part %d: \"%s\"\n", id
, debugstr_w(text
));
811 if (infoPtr
->hwndToolTip
) {
813 ti
.cbSize
= sizeof(TTTOOLINFOW
);
814 ti
.hwnd
= infoPtr
->Self
;
818 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
825 static inline LRESULT
826 STATUSBAR_SetUnicodeFormat (STATUS_INFO
*infoPtr
, BOOL bUnicode
)
828 BOOL bOld
= infoPtr
->bUnicode
;
830 TRACE("(0x%x)\n", bUnicode
);
831 infoPtr
->bUnicode
= bUnicode
;
838 STATUSBAR_Simple (STATUS_INFO
*infoPtr
, BOOL simple
)
842 TRACE("(simple=%d)\n", simple
);
843 if (infoPtr
->simple
== simple
) /* no need to change */
846 infoPtr
->simple
= simple
;
848 /* send notification */
849 nmhdr
.hwndFrom
= infoPtr
->Self
;
850 nmhdr
.idFrom
= GetWindowLongPtrW (infoPtr
->Self
, GWLP_ID
);
851 nmhdr
.code
= SBN_SIMPLEMODECHANGE
;
852 SendMessageW (infoPtr
->Notify
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
853 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
859 STATUSBAR_WMDestroy (STATUS_INFO
*infoPtr
)
864 for (i
= 0; i
< infoPtr
->numParts
; i
++) {
865 if (!(infoPtr
->parts
[i
].style
& SBT_OWNERDRAW
))
866 Free (infoPtr
->parts
[i
].text
);
868 if (!(infoPtr
->part0
.style
& SBT_OWNERDRAW
))
869 Free (infoPtr
->part0
.text
);
870 Free (infoPtr
->parts
);
872 /* delete default font */
873 if (infoPtr
->hDefaultFont
)
874 DeleteObject (infoPtr
->hDefaultFont
);
876 /* delete tool tip control */
877 if (infoPtr
->hwndToolTip
)
878 DestroyWindow (infoPtr
->hwndToolTip
);
880 CloseThemeData (GetWindowTheme (infoPtr
->Self
));
882 SetWindowLongPtrW(infoPtr
->Self
, 0, 0);
889 STATUSBAR_WMCreate (HWND hwnd
, const CREATESTRUCTA
*lpCreate
)
891 STATUS_INFO
*infoPtr
;
892 NONCLIENTMETRICSW nclm
;
898 infoPtr
= Alloc (sizeof(STATUS_INFO
));
899 if (!infoPtr
) goto create_fail
;
900 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
902 infoPtr
->Self
= hwnd
;
903 infoPtr
->Notify
= lpCreate
->hwndParent
;
904 infoPtr
->numParts
= 1;
906 infoPtr
->simple
= FALSE
;
907 infoPtr
->clrBk
= CLR_DEFAULT
;
909 infoPtr
->horizontalBorder
= HORZ_BORDER
;
910 infoPtr
->verticalBorder
= VERT_BORDER
;
911 infoPtr
->horizontalGap
= HORZ_GAP
;
912 infoPtr
->minHeight
= GetSystemMetrics(SM_CYSIZE
);
913 if (infoPtr
->minHeight
& 1) infoPtr
->minHeight
--;
915 STATUSBAR_NotifyFormat(infoPtr
, infoPtr
->Notify
, NF_REQUERY
);
917 ZeroMemory (&nclm
, sizeof(nclm
));
918 nclm
.cbSize
= sizeof(nclm
);
919 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0);
920 infoPtr
->hDefaultFont
= CreateFontIndirectW (&nclm
.lfStatusFont
);
922 GetClientRect (hwnd
, &rect
);
924 /* initialize simple case */
925 infoPtr
->part0
.bound
= rect
;
926 infoPtr
->part0
.text
= 0;
927 infoPtr
->part0
.x
= 0;
928 infoPtr
->part0
.style
= 0;
929 infoPtr
->part0
.hIcon
= 0;
931 /* initialize first part */
932 infoPtr
->parts
= Alloc (sizeof(STATUSWINDOWPART
));
933 if (!infoPtr
->parts
) goto create_fail
;
934 infoPtr
->parts
[0].bound
= rect
;
935 infoPtr
->parts
[0].text
= 0;
936 infoPtr
->parts
[0].x
= -1;
937 infoPtr
->parts
[0].style
= 0;
938 infoPtr
->parts
[0].hIcon
= 0;
940 OpenThemeData (hwnd
, themeClass
);
942 if (lpCreate
->lpszName
&& (len
= strlenW ((LPCWSTR
)lpCreate
->lpszName
)))
944 infoPtr
->parts
[0].text
= Alloc ((len
+ 1)*sizeof(WCHAR
));
945 if (!infoPtr
->parts
[0].text
) goto create_fail
;
946 strcpyW (infoPtr
->parts
[0].text
, (LPCWSTR
)lpCreate
->lpszName
);
949 dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
950 /* native seems to clear WS_BORDER, too */
951 dwStyle
&= ~WS_BORDER
;
952 SetWindowLongW (hwnd
, GWL_STYLE
, dwStyle
);
954 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
956 if (dwStyle
& SBT_TOOLTIPS
) {
957 infoPtr
->hwndToolTip
=
958 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
| TTS_ALWAYSTIP
,
959 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
960 CW_USEDEFAULT
, hwnd
, 0,
961 (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
), NULL
);
963 if (infoPtr
->hwndToolTip
) {
964 NMTOOLTIPSCREATED nmttc
;
966 nmttc
.hdr
.hwndFrom
= hwnd
;
967 nmttc
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
968 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
969 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
971 SendMessageW (lpCreate
->hwndParent
, WM_NOTIFY
, nmttc
.hdr
.idFrom
, (LPARAM
)&nmttc
);
979 if (infoPtr
) STATUSBAR_WMDestroy(infoPtr
);
984 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
985 * of the first part only (usual behaviour) */
987 STATUSBAR_WMGetText (const STATUS_INFO
*infoPtr
, INT size
, LPWSTR buf
)
992 if (!(infoPtr
->parts
[0].text
))
995 len
= strlenW (infoPtr
->parts
[0].text
);
999 else if (size
> len
) {
1000 strcpyW (buf
, infoPtr
->parts
[0].text
);
1004 memcpy (buf
, infoPtr
->parts
[0].text
, (size
- 1) * sizeof(WCHAR
));
1012 STATUSBAR_WMNCHitTest (const STATUS_INFO
*infoPtr
, INT x
, INT y
)
1014 if (GetWindowLongW (infoPtr
->Self
, GWL_STYLE
) & SBARS_SIZEGRIP
) {
1018 GetClientRect (infoPtr
->Self
, &rect
);
1022 ScreenToClient (infoPtr
->Self
, &pt
);
1024 rect
.left
= rect
.right
- 13;
1027 if (PtInRect (&rect
, pt
))
1029 if (GetWindowLongW( infoPtr
->Self
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) return HTBOTTOMLEFT
;
1030 else return HTBOTTOMRIGHT
;
1039 STATUSBAR_WMPaint (STATUS_INFO
*infoPtr
, HDC hdc
)
1044 if (hdc
) return STATUSBAR_Refresh (infoPtr
, hdc
);
1045 hdc
= BeginPaint (infoPtr
->Self
, &ps
);
1046 STATUSBAR_Refresh (infoPtr
, hdc
);
1047 EndPaint (infoPtr
->Self
, &ps
);
1054 STATUSBAR_WMSetFont (STATUS_INFO
*infoPtr
, HFONT font
, BOOL redraw
)
1056 infoPtr
->hFont
= font
;
1057 TRACE("%p\n", infoPtr
->hFont
);
1059 infoPtr
->height
= STATUSBAR_ComputeHeight(infoPtr
);
1060 SendMessageW(infoPtr
->Self
, WM_SIZE
, 0, 0); /* update size */
1062 InvalidateRect(infoPtr
->Self
, NULL
, FALSE
);
1069 STATUSBAR_WMSetText (const STATUS_INFO
*infoPtr
, LPCSTR text
)
1071 STATUSWINDOWPART
*part
;
1075 if (infoPtr
->numParts
== 0)
1078 part
= &infoPtr
->parts
[0];
1079 /* duplicate string */
1083 if (text
&& (len
= strlenW((LPCWSTR
)text
))) {
1084 part
->text
= Alloc ((len
+1)*sizeof(WCHAR
));
1085 if (!part
->text
) return FALSE
;
1086 strcpyW (part
->text
, (LPCWSTR
)text
);
1089 InvalidateRect(infoPtr
->Self
, &part
->bound
, FALSE
);
1096 STATUSBAR_WMSize (STATUS_INFO
*infoPtr
, WORD flags
)
1101 /* Need to resize width to match parent */
1102 TRACE("flags %04x\n", flags
);
1104 if (flags
!= SIZE_RESTORED
&& flags
!= SIZE_MAXIMIZED
) {
1105 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1109 if (GetWindowLongW(infoPtr
->Self
, GWL_STYLE
) & CCS_NORESIZE
) return FALSE
;
1111 /* width and height don't apply */
1112 if (!GetClientRect (infoPtr
->Notify
, &parent_rect
))
1115 width
= parent_rect
.right
- parent_rect
.left
;
1116 x
= parent_rect
.left
;
1117 y
= parent_rect
.bottom
- infoPtr
->height
;
1118 MoveWindow (infoPtr
->Self
, x
, y
, width
, infoPtr
->height
, TRUE
);
1119 STATUSBAR_SetPartBounds (infoPtr
);
1124 /* update theme after a WM_THEMECHANGED message */
1125 static LRESULT
theme_changed (const STATUS_INFO
* infoPtr
)
1127 HTHEME theme
= GetWindowTheme (infoPtr
->Self
);
1128 CloseThemeData (theme
);
1129 OpenThemeData (infoPtr
->Self
, themeClass
);
1135 STATUSBAR_NotifyFormat (STATUS_INFO
*infoPtr
, HWND from
, INT cmd
)
1137 if (cmd
== NF_REQUERY
) {
1138 INT i
= SendMessageW(from
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->Self
, NF_QUERY
);
1139 infoPtr
->bUnicode
= (i
== NFR_UNICODE
);
1141 return infoPtr
->bUnicode
? NFR_UNICODE
: NFR_ANSI
;
1146 STATUSBAR_SendMouseNotify(const STATUS_INFO
*infoPtr
, UINT code
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1150 TRACE("code %04x, lParam=%lx\n", code
, lParam
);
1151 nm
.hdr
.hwndFrom
= infoPtr
->Self
;
1152 nm
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->Self
, GWLP_ID
);
1154 nm
.pt
.x
= (short)LOWORD(lParam
);
1155 nm
.pt
.y
= (short)HIWORD(lParam
);
1156 nm
.dwItemSpec
= STATUSBAR_InternalHitTest(infoPtr
, &nm
.pt
);
1158 nm
.dwHitInfo
= 0x30000; /* seems constant */
1160 /* Do default processing if WM_NOTIFY returns zero */
1161 if(!SendMessageW(infoPtr
->Notify
, WM_NOTIFY
, nm
.hdr
.idFrom
, (LPARAM
)&nm
))
1163 return DefWindowProcW(infoPtr
->Self
, msg
, wParam
, lParam
);
1170 static LRESULT WINAPI
1171 StatusWindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1173 STATUS_INFO
*infoPtr
= (STATUS_INFO
*)GetWindowLongPtrW (hwnd
, 0);
1174 INT nPart
= ((INT
) wParam
) & 0x00ff;
1177 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1178 if (!infoPtr
&& msg
!= WM_CREATE
)
1179 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1183 return STATUSBAR_GetBorders (infoPtr
, (INT
*)lParam
);
1186 return (LRESULT
)STATUSBAR_GetIcon (infoPtr
, nPart
);
1189 return STATUSBAR_GetParts (infoPtr
, (INT
)wParam
, (INT
*)lParam
);
1192 return STATUSBAR_GetRect (infoPtr
, nPart
, (LPRECT
)lParam
);
1195 return STATUSBAR_GetTextA (infoPtr
, nPart
, (LPSTR
)lParam
);
1198 return STATUSBAR_GetTextW (infoPtr
, nPart
, (LPWSTR
)lParam
);
1200 case SB_GETTEXTLENGTHA
:
1201 case SB_GETTEXTLENGTHW
:
1202 return STATUSBAR_GetTextLength (infoPtr
, nPart
);
1204 case SB_GETTIPTEXTA
:
1205 return STATUSBAR_GetTipTextA (infoPtr
, LOWORD(wParam
), (LPSTR
)lParam
, HIWORD(wParam
));
1207 case SB_GETTIPTEXTW
:
1208 return STATUSBAR_GetTipTextW (infoPtr
, LOWORD(wParam
), (LPWSTR
)lParam
, HIWORD(wParam
));
1210 case SB_GETUNICODEFORMAT
:
1211 return infoPtr
->bUnicode
;
1214 return infoPtr
->simple
;
1217 return STATUSBAR_SetBorders (infoPtr
, (INT
*)lParam
);
1220 return STATUSBAR_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1223 return STATUSBAR_SetIcon (infoPtr
, nPart
, (HICON
)lParam
);
1225 case SB_SETMINHEIGHT
:
1226 return STATUSBAR_SetMinHeight (infoPtr
, (INT
)wParam
);
1229 return STATUSBAR_SetParts (infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
1232 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, FALSE
);
1235 return STATUSBAR_SetTextT (infoPtr
, nPart
, wParam
& 0xff00, (LPWSTR
)lParam
, TRUE
);
1237 case SB_SETTIPTEXTA
:
1238 return STATUSBAR_SetTipTextA (infoPtr
, (INT
)wParam
, (LPSTR
)lParam
);
1240 case SB_SETTIPTEXTW
:
1241 return STATUSBAR_SetTipTextW (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1243 case SB_SETUNICODEFORMAT
:
1244 return STATUSBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1247 return STATUSBAR_Simple (infoPtr
, (BOOL
)wParam
);
1250 return STATUSBAR_WMCreate (hwnd
, (LPCREATESTRUCTA
)lParam
);
1253 return STATUSBAR_WMDestroy (infoPtr
);
1256 return (LRESULT
)(infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
);
1259 return STATUSBAR_WMGetText (infoPtr
, (INT
)wParam
, (LPWSTR
)lParam
);
1261 case WM_GETTEXTLENGTH
:
1262 return LOWORD(STATUSBAR_GetTextLength (infoPtr
, 0));
1264 case WM_LBUTTONDBLCLK
:
1265 return STATUSBAR_SendMouseNotify(infoPtr
, NM_DBLCLK
, msg
, wParam
, lParam
);
1268 return STATUSBAR_SendMouseNotify(infoPtr
, NM_CLICK
, msg
, wParam
, lParam
);
1271 return STATUSBAR_Relay2Tip (infoPtr
, msg
, wParam
, lParam
);
1274 res
= STATUSBAR_WMNCHitTest(infoPtr
, (short)LOWORD(lParam
),
1275 (short)HIWORD(lParam
));
1276 if (res
!= HTERROR
) return res
;
1277 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1279 case WM_NCLBUTTONUP
:
1280 case WM_NCLBUTTONDOWN
:
1281 PostMessageW (infoPtr
->Notify
, msg
, wParam
, lParam
);
1284 case WM_NOTIFYFORMAT
:
1285 return STATUSBAR_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
1287 case WM_PRINTCLIENT
:
1289 return STATUSBAR_WMPaint (infoPtr
, (HDC
)wParam
);
1291 case WM_RBUTTONDBLCLK
:
1292 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RDBLCLK
, msg
, wParam
, lParam
);
1295 return STATUSBAR_SendMouseNotify(infoPtr
, NM_RCLICK
, msg
, wParam
, lParam
);
1298 return STATUSBAR_WMSetFont (infoPtr
, (HFONT
)wParam
, LOWORD(lParam
));
1301 return STATUSBAR_WMSetText (infoPtr
, (LPCSTR
)lParam
);
1304 if (STATUSBAR_WMSize (infoPtr
, (WORD
)wParam
)) return 0;
1305 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1307 case WM_SYSCOLORCHANGE
:
1308 COMCTL32_RefreshSysColors();
1311 case WM_THEMECHANGED
:
1312 return theme_changed (infoPtr
);
1315 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
1316 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1317 msg
, wParam
, lParam
);
1318 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1323 /***********************************************************************
1324 * STATUS_Register [Internal]
1326 * Registers the status window class.
1330 STATUS_Register (void)
1334 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1335 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
;
1336 wndClass
.lpfnWndProc
= StatusWindowProc
;
1337 wndClass
.cbClsExtra
= 0;
1338 wndClass
.cbWndExtra
= sizeof(STATUS_INFO
*);
1339 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1340 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1341 wndClass
.lpszClassName
= STATUSCLASSNAMEW
;
1343 RegisterClassW (&wndClass
);
1347 /***********************************************************************
1348 * STATUS_Unregister [Internal]
1350 * Unregisters the status window class.
1354 STATUS_Unregister (void)
1356 UnregisterClassW (STATUSCLASSNAMEW
, NULL
);