2 * Interface code to StatusWindow widget/control
4 * Copyright 1996 Bruce Milner
5 * Copyright 1998, 1999 Eric Kohl
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Sep. 24, 2002, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
32 * -- CCS_BOTTOM (default)
37 * -- CCS_NOPARENTALIGN
40 * -- CCS_VERT (defaults to RIGHT)
48 #include "wine/unicode.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
79 COLORREF clrBk; /* background color */
80 BOOL bUnicode; /* notify format. TRUE if notifies in Unicode */
81 STATUSWINDOWPART part0; /* simple window */
82 STATUSWINDOWPART* parts;
89 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
90 * The second cdrom contains executables drawstat.exe, gettext.exe,
91 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
98 static const WCHAR themeClass[] = { 'S','t','a','t','u','s',0 };
102 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
104 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd);
106 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
108 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
112 STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
114 HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
118 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect));
124 gripperRect = *lpRect;
125 if (SUCCEEDED (GetThemePartSize (theme, hdc, SP_GRIPPER, 0, lpRect,
126 TS_DRAW, &gripperSize)))
128 gripperRect.left = gripperRect.right - gripperSize.cx;
129 gripperRect.top = gripperRect.bottom - gripperSize.cy;
130 if (SUCCEEDED (DrawThemeBackground(theme, hdc, SP_GRIPPER, 0, &gripperRect, NULL)))
135 pt.x = lpRect->right - 1;
136 pt.y = lpRect->bottom - 1;
138 hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
139 hOldPen = SelectObject( hdc, hPenFace );
140 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
141 LineTo (hdc, pt.x, pt.y);
142 LineTo (hdc, pt.x, pt.y - 13);
147 hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
148 SelectObject( hdc, hPenShadow );
149 for (i = 1; i < 11; i += 4) {
150 MoveToEx (hdc, pt.x - i, pt.y, NULL);
151 LineTo (hdc, pt.x + 1, pt.y - i - 1);
153 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
154 LineTo (hdc, pt.x + 1, pt.y - i - 2);
157 hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
158 SelectObject( hdc, hPenHighlight );
159 for (i = 3; i < 13; i += 4) {
160 MoveToEx (hdc, pt.x - i, pt.y, NULL);
161 LineTo (hdc, pt.x + 1, pt.y - i - 1);
164 SelectObject (hdc, hOldPen);
165 DeleteObject( hPenFace );
166 DeleteObject( hPenShadow );
167 DeleteObject( hPenHighlight );
172 STATUSBAR_DrawPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
174 RECT r = part->bound;
175 UINT border = BDR_SUNKENOUTER;
176 HTHEME theme = GetWindowTheme (infoPtr->Self);
177 int themePart = SP_PANE;
179 TRACE("part bound %s\n", wine_dbgstr_rect(&r));
180 if (part->style & SBT_POPOUT)
181 border = BDR_RAISEDOUTER;
182 else if (part->style & SBT_NOBORDERS)
187 if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
188 && (infoPtr->simple || (itemID == (infoPtr->numParts-1))))
189 themePart = SP_GRIPPERPANE;
190 DrawThemeBackground(theme, hdc, themePart, 0, &r, NULL);
193 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
195 if (part->style & SBT_OWNERDRAW) {
198 dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
200 dis.hwndItem = infoPtr->Self;
203 dis.itemData = (ULONG_PTR)part->text;
204 SendMessageW (infoPtr->Notify, WM_DRAWITEM, (WPARAM)dis.CtlID, (LPARAM)&dis);
207 INT cy = r.bottom - r.top;
210 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
213 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
219 STATUSBAR_RefreshPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
225 TRACE("item %d\n", itemID);
226 if (!IsWindowVisible (infoPtr->Self))
229 if (part->bound.right < part->bound.left) return;
231 if ((theme = GetWindowTheme (infoPtr->Self)))
234 GetClientRect (infoPtr->Self, &cr);
235 DrawThemeBackground(theme, hdc, 0, 0, &cr, &part->bound);
239 if (infoPtr->clrBk != CLR_DEFAULT)
240 hbrBk = CreateSolidBrush (infoPtr->clrBk);
242 hbrBk = GetSysColorBrush (COLOR_3DFACE);
243 FillRect(hdc, &part->bound, hbrBk);
244 if (infoPtr->clrBk != CLR_DEFAULT)
245 DeleteObject (hbrBk);
248 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
250 STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
252 SelectObject (hdc, hOldFont);
254 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
257 GetClientRect (infoPtr->Self, &rect);
258 STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
264 STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
273 if (!IsWindowVisible(infoPtr->Self))
276 STATUSBAR_SetPartBounds(infoPtr);
278 GetClientRect (infoPtr->Self, &rect);
280 if ((theme = GetWindowTheme (infoPtr->Self)))
282 DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
286 if (infoPtr->clrBk != CLR_DEFAULT)
287 hbrBk = CreateSolidBrush (infoPtr->clrBk);
289 hbrBk = GetSysColorBrush (COLOR_3DFACE);
290 FillRect(hdc, &rect, hbrBk);
291 if (infoPtr->clrBk != CLR_DEFAULT)
292 DeleteObject (hbrBk);
295 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
297 if (infoPtr->simple) {
298 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
300 for (i = 0; i < infoPtr->numParts; i++) {
301 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
305 SelectObject (hdc, hOldFont);
307 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
308 STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
315 STATUSBAR_InternalHitTest(const STATUS_INFO *infoPtr, const LPPOINT pt)
321 for (i = 0; i < infoPtr->numParts; i++)
322 if (pt->x >= infoPtr->parts[i].bound.left && pt->x <= infoPtr->parts[i].bound.right)
329 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
331 STATUSWINDOWPART *part;
335 /* get our window size */
336 GetClientRect (infoPtr->Self, &rect);
337 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect));
339 rect.left += infoPtr->horizontalBorder;
340 rect.top += infoPtr->verticalBorder;
342 /* set bounds for simple rectangle */
343 infoPtr->part0.bound = rect;
345 /* set bounds for non-simple rectangles */
346 for (i = 0; i < infoPtr->numParts; i++) {
347 part = &infoPtr->parts[i];
348 r = &infoPtr->parts[i].bound;
350 r->bottom = rect.bottom;
354 r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
356 r->right = rect.right;
360 if (infoPtr->hwndToolTip) {
363 ti.cbSize = sizeof(TTTOOLINFOW);
364 ti.hwnd = infoPtr->Self;
367 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
375 STATUSBAR_Relay2Tip (const STATUS_INFO *infoPtr, UINT uMsg,
376 WPARAM wParam, LPARAM lParam)
380 msg.hwnd = infoPtr->Self;
384 msg.time = GetMessageTime ();
385 msg.pt.x = (short)LOWORD(GetMessagePos ());
386 msg.pt.y = (short)HIWORD(GetMessagePos ());
388 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
393 STATUSBAR_GetBorders (const STATUS_INFO *infoPtr, INT out[])
396 out[0] = infoPtr->horizontalBorder;
397 out[1] = infoPtr->verticalBorder;
398 out[2] = infoPtr->horizontalGap;
405 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, const INT in[])
408 infoPtr->horizontalBorder = in[0];
409 infoPtr->verticalBorder = in[1];
410 infoPtr->horizontalGap = in[2];
411 InvalidateRect(infoPtr->Self, NULL, FALSE);
418 STATUSBAR_GetIcon (const STATUS_INFO *infoPtr, INT nPart)
420 TRACE("%d\n", nPart);
421 /* MSDN says: "simple parts are indexed with -1" */
422 if ((nPart < -1) || (nPart >= infoPtr->numParts))
426 return (infoPtr->part0.hIcon);
428 return (infoPtr->parts[nPart].hIcon);
433 STATUSBAR_GetParts (const STATUS_INFO *infoPtr, INT num_parts, INT parts[])
437 TRACE("(%d)\n", num_parts);
439 for (i = 0; i < num_parts; i++) {
440 parts[i] = infoPtr->parts[i].x;
443 return infoPtr->numParts;
448 STATUSBAR_GetRect (const STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
450 TRACE("part %d\n", nPart);
451 if(nPart >= infoPtr->numParts || nPart < 0)
454 *rect = infoPtr->part0.bound;
456 *rect = infoPtr->parts[nPart].bound;
462 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
464 STATUSWINDOWPART *part;
467 TRACE("part %d\n", nPart);
469 /* MSDN says: "simple parts use index of 0", so this check is ok. */
470 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
473 part = &infoPtr->part0;
475 part = &infoPtr->parts[nPart];
477 if (part->style & SBT_OWNERDRAW)
478 result = (LRESULT)part->text;
480 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
481 NULL, 0, NULL, NULL ) - 1 : 0;
482 result = MAKELONG( len, part->style );
483 if (part->text && buf)
484 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
491 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
493 STATUSWINDOWPART *part;
496 TRACE("part %d\n", nPart);
497 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
500 part = &infoPtr->part0;
502 part = &infoPtr->parts[nPart];
504 if (part->style & SBT_OWNERDRAW)
505 result = (LRESULT)part->text;
507 result = part->text ? strlenW (part->text) : 0;
508 result |= (part->style << 16);
509 if (part->text && buf)
510 strcpyW (buf, part->text);
517 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
519 STATUSWINDOWPART *part;
522 TRACE("part %d\n", nPart);
524 /* MSDN says: "simple parts use index of 0", so this check is ok. */
525 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
528 part = &infoPtr->part0;
530 part = &infoPtr->parts[nPart];
532 if ((~part->style & SBT_OWNERDRAW) && part->text)
533 result = strlenW(part->text);
537 result |= (part->style << 16);
542 STATUSBAR_GetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
546 CHAR buf[INFOTIPSIZE];
549 if (infoPtr->hwndToolTip) {
551 ti.cbSize = sizeof(TTTOOLINFOA);
552 ti.hwnd = infoPtr->Self;
555 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
557 lstrcpynA (tip, buf, size);
564 STATUSBAR_GetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
568 WCHAR buf[INFOTIPSIZE];
571 if (infoPtr->hwndToolTip) {
573 ti.cbSize = sizeof(TTTOOLINFOW);
574 ti.hwnd = infoPtr->Self;
577 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
579 lstrcpynW(tip, buf, size);
587 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
591 oldBkColor = infoPtr->clrBk;
592 infoPtr->clrBk = color;
593 InvalidateRect(infoPtr->Self, NULL, FALSE);
595 TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
601 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
603 if ((nPart < -1) || (nPart >= infoPtr->numParts))
606 TRACE("setting part %d\n", nPart);
608 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
610 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
612 infoPtr->part0.hIcon = hIcon;
614 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
616 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
619 infoPtr->parts[nPart].hIcon = hIcon;
620 if (!(infoPtr->simple))
621 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
628 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
631 TRACE("(height=%d)\n", height);
632 if (IsWindowVisible (infoPtr->Self)) {
637 infoPtr->height = height + infoPtr->verticalBorder;
639 if ((theme = GetWindowTheme (infoPtr->Self)))
641 /* Determine bar height from theme such that the content area is
642 * 'height' pixels large */
643 HDC hdc = GetDC (infoPtr->Self);
645 memset (&r, 0, sizeof (r));
647 if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
649 infoPtr->height = r.bottom - r.top;
651 ReleaseDC (infoPtr->Self, hdc);
654 if (GetClientRect (infoPtr->Notify, &parent_rect))
656 width = parent_rect.right - parent_rect.left;
657 x = parent_rect.left;
658 y = parent_rect.bottom - infoPtr->height;
659 MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
660 STATUSBAR_SetPartBounds (infoPtr);
669 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
671 STATUSWINDOWPART *tmp;
674 TRACE("(%d,%p)\n", count, parts);
676 oldNumParts = infoPtr->numParts;
677 infoPtr->numParts = count;
678 if (oldNumParts > infoPtr->numParts) {
679 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
680 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
681 Free (infoPtr->parts[i].text);
683 } else if (oldNumParts < infoPtr->numParts) {
684 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
685 if (!tmp) return FALSE;
686 for (i = 0; i < oldNumParts; i++) {
687 tmp[i] = infoPtr->parts[i];
689 Free (infoPtr->parts);
690 infoPtr->parts = tmp;
692 if (oldNumParts == infoPtr->numParts) {
693 for (i=0; i < oldNumParts; i++)
694 if (infoPtr->parts[i].x != parts[i])
696 if (i==oldNumParts) /* Unchanged? no need to redraw! */
700 for (i = 0; i < infoPtr->numParts; i++)
701 infoPtr->parts[i].x = parts[i];
703 if (infoPtr->hwndToolTip) {
707 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
708 ti.cbSize = sizeof(TTTOOLINFOW);
709 ti.hwnd = infoPtr->Self;
711 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
712 if (nTipCount < infoPtr->numParts) {
714 for (i = nTipCount; i < infoPtr->numParts; i++) {
715 TRACE("add tool %d\n", i);
717 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
721 else if (nTipCount > infoPtr->numParts) {
723 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
724 TRACE("delete tool %d\n", i);
726 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
731 STATUSBAR_SetPartBounds (infoPtr);
732 InvalidateRect(infoPtr->Self, NULL, FALSE);
738 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
739 LPCWSTR text, BOOL isW)
741 STATUSWINDOWPART *part=NULL;
742 BOOL changed = FALSE;
745 if (style & SBT_OWNERDRAW) {
746 TRACE("part %d, text %p\n",nPart,text);
748 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
750 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
751 * window is assumed to be a simple window */
753 if (nPart == 0x00ff) {
754 part = &infoPtr->part0;
756 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
757 part = &infoPtr->parts[nPart];
760 if (!part) return FALSE;
762 if (part->style != style)
765 oldStyle = part->style;
767 if (style & SBT_OWNERDRAW) {
768 if (!(oldStyle & SBT_OWNERDRAW))
770 else if (part->text == text)
772 part->text = (LPWSTR)text;
777 LPCSTR atxt = (LPCSTR)text;
778 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
779 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
780 if (!ntext) return FALSE;
781 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
783 ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
784 if (!ntext) return FALSE;
785 strcpyW (ntext, text);
788 /* check if text is unchanged -> no need to redraw */
790 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
795 if (!changed && !part->text)
799 if (!(oldStyle & SBT_OWNERDRAW))
803 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
804 UpdateWindow(infoPtr->Self);
811 STATUSBAR_SetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR text)
813 TRACE("part %d: \"%s\"\n", id, text);
814 if (infoPtr->hwndToolTip) {
816 ti.cbSize = sizeof(TTTOOLINFOA);
817 ti.hwnd = infoPtr->Self;
821 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
829 STATUSBAR_SetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR text)
831 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
832 if (infoPtr->hwndToolTip) {
834 ti.cbSize = sizeof(TTTOOLINFOW);
835 ti.hwnd = infoPtr->Self;
839 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
846 static inline LRESULT
847 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
849 BOOL bOld = infoPtr->bUnicode;
851 TRACE("(0x%x)\n", bUnicode);
852 infoPtr->bUnicode = bUnicode;
859 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
863 TRACE("(simple=%d)\n", simple);
864 if (infoPtr->simple == simple) /* no need to change */
867 infoPtr->simple = simple;
869 /* send notification */
870 nmhdr.hwndFrom = infoPtr->Self;
871 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
872 nmhdr.code = SBN_SIMPLEMODECHANGE;
873 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
874 InvalidateRect(infoPtr->Self, NULL, FALSE);
880 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
885 for (i = 0; i < infoPtr->numParts; i++) {
886 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
887 Free (infoPtr->parts[i].text);
889 if (!(infoPtr->part0.style & SBT_OWNERDRAW))
890 Free (infoPtr->part0.text);
891 Free (infoPtr->parts);
893 /* delete default font */
894 if (infoPtr->hDefaultFont)
895 DeleteObject (infoPtr->hDefaultFont);
897 /* delete tool tip control */
898 if (infoPtr->hwndToolTip)
899 DestroyWindow (infoPtr->hwndToolTip);
901 CloseThemeData (GetWindowTheme (infoPtr->Self));
903 SetWindowLongPtrW(infoPtr->Self, 0, 0);
910 STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
912 STATUS_INFO *infoPtr;
913 NONCLIENTMETRICSW nclm;
916 int width, len, textHeight = 0;
920 infoPtr = (STATUS_INFO*)Alloc (sizeof(STATUS_INFO));
921 if (!infoPtr) goto create_fail;
922 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
924 infoPtr->Self = hwnd;
925 infoPtr->Notify = lpCreate->hwndParent;
926 infoPtr->numParts = 1;
928 infoPtr->simple = FALSE;
929 infoPtr->clrBk = CLR_DEFAULT;
931 infoPtr->horizontalBorder = HORZ_BORDER;
932 infoPtr->verticalBorder = VERT_BORDER;
933 infoPtr->horizontalGap = HORZ_GAP;
935 STATUSBAR_NotifyFormat(infoPtr, infoPtr->Notify, NF_REQUERY);
937 GetClientRect (hwnd, &rect);
938 InvalidateRect (hwnd, &rect, 0);
941 ZeroMemory (&nclm, sizeof(nclm));
942 nclm.cbSize = sizeof(nclm);
943 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
944 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
946 /* initialize simple case */
947 infoPtr->part0.bound = rect;
948 infoPtr->part0.text = 0;
949 infoPtr->part0.x = 0;
950 infoPtr->part0.style = 0;
951 infoPtr->part0.hIcon = 0;
953 /* initialize first part */
954 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
955 if (!infoPtr->parts) goto create_fail;
956 infoPtr->parts[0].bound = rect;
957 infoPtr->parts[0].text = 0;
958 infoPtr->parts[0].x = -1;
959 infoPtr->parts[0].style = 0;
960 infoPtr->parts[0].hIcon = 0;
962 OpenThemeData (hwnd, themeClass);
964 if (lpCreate->lpszName && (len = strlenW ((LPCWSTR)lpCreate->lpszName)))
966 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
967 if (!infoPtr->parts[0].text) goto create_fail;
968 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
971 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
972 /* native seems to clear WS_BORDER, too */
973 dwStyle &= ~WS_BORDER;
974 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
976 if ((hdc = GetDC (hwnd))) {
980 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
981 GetTextMetricsW (hdc, &tm);
982 textHeight = tm.tmHeight;
983 SelectObject (hdc, hOldFont);
984 ReleaseDC (hwnd, hdc);
986 TRACE(" textHeight=%d\n", textHeight);
988 if (dwStyle & SBT_TOOLTIPS) {
989 infoPtr->hwndToolTip =
990 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
991 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
992 CW_USEDEFAULT, hwnd, 0,
993 (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
995 if (infoPtr->hwndToolTip) {
996 NMTOOLTIPSCREATED nmttc;
998 nmttc.hdr.hwndFrom = hwnd;
999 nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
1000 nmttc.hdr.code = NM_TOOLTIPSCREATED;
1001 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1003 SendMessageW (lpCreate->hwndParent, WM_NOTIFY, nmttc.hdr.idFrom, (LPARAM)&nmttc);
1007 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
1009 GetClientRect (infoPtr->Notify, &rect);
1010 width = rect.right - rect.left;
1011 infoPtr->height = textHeight + 4 + infoPtr->verticalBorder;
1013 if ((theme = GetWindowTheme (hwnd)))
1015 /* Determine bar height from theme such that the content area is
1016 * textHeight pixels large */
1017 HDC hdc = GetDC (hwnd);
1019 memset (&r, 0, sizeof (r));
1020 r.bottom = textHeight;
1021 if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
1023 infoPtr->height = r.bottom - r.top;
1025 ReleaseDC (hwnd, hdc);
1028 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
1029 width, infoPtr->height, SWP_NOZORDER);
1030 STATUSBAR_SetPartBounds (infoPtr);
1036 TRACE(" failed!\n");
1037 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
1042 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
1043 * of the first part only (usual behaviour) */
1045 STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
1050 if (!(infoPtr->parts[0].text))
1053 len = strlenW (infoPtr->parts[0].text);
1056 strcpyW (buf, infoPtr->parts[0].text);
1065 STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
1067 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1071 GetClientRect (infoPtr->Self, &rect);
1075 ScreenToClient (infoPtr->Self, &pt);
1077 rect.left = rect.right - 13;
1080 if (PtInRect (&rect, pt))
1081 return HTBOTTOMRIGHT;
1089 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1094 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1095 hdc = BeginPaint (infoPtr->Self, &ps);
1096 STATUSBAR_Refresh (infoPtr, hdc);
1097 EndPaint (infoPtr->Self, &ps);
1104 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1106 infoPtr->hFont = font;
1107 TRACE("%p\n", infoPtr->hFont);
1109 InvalidateRect(infoPtr->Self, NULL, FALSE);
1116 STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
1118 STATUSWINDOWPART *part;
1122 if (infoPtr->numParts == 0)
1125 part = &infoPtr->parts[0];
1126 /* duplicate string */
1130 if (text && (len = strlenW((LPCWSTR)text))) {
1131 part->text = Alloc ((len+1)*sizeof(WCHAR));
1132 if (!part->text) return FALSE;
1133 strcpyW (part->text, (LPCWSTR)text);
1136 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1143 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1148 /* Need to resize width to match parent */
1149 TRACE("flags %04x\n", flags);
1151 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1152 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1156 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1158 /* width and height don't apply */
1159 if (!GetClientRect (infoPtr->Notify, &parent_rect))
1162 width = parent_rect.right - parent_rect.left;
1163 x = parent_rect.left;
1164 y = parent_rect.bottom - infoPtr->height;
1165 MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
1166 STATUSBAR_SetPartBounds (infoPtr);
1171 /* update theme after a WM_THEMECHANGED message */
1172 static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1174 HTHEME theme = GetWindowTheme (infoPtr->Self);
1175 CloseThemeData (theme);
1176 OpenThemeData (infoPtr->Self, themeClass);
1182 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1184 if (cmd == NF_REQUERY) {
1185 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1186 infoPtr->bUnicode = (i == NFR_UNICODE);
1188 return infoPtr->bUnicode ? NFR_UNICODE : NFR_ANSI;
1193 STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, LPARAM lParam)
1197 TRACE("code %04x, lParam=%lx\n", code, lParam);
1198 nm.hdr.hwndFrom = infoPtr->Self;
1199 nm.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1201 nm.pt.x = (short)LOWORD(lParam);
1202 nm.pt.y = (short)HIWORD(lParam);
1203 nm.dwItemSpec = STATUSBAR_InternalHitTest(infoPtr, &nm.pt);
1205 nm.dwHitInfo = 0x30000; /* seems constant */
1206 SendMessageW(infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nm);
1212 static LRESULT WINAPI
1213 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1215 STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1216 INT nPart = ((INT) wParam) & 0x00ff;
1219 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, msg, wParam, lParam);
1220 if (!infoPtr && msg != WM_CREATE)
1221 return DefWindowProcW (hwnd, msg, wParam, lParam);
1225 return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1228 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1231 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1234 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1237 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1240 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1242 case SB_GETTEXTLENGTHA:
1243 case SB_GETTEXTLENGTHW:
1244 return STATUSBAR_GetTextLength (infoPtr, nPart);
1246 case SB_GETTIPTEXTA:
1247 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1249 case SB_GETTIPTEXTW:
1250 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1252 case SB_GETUNICODEFORMAT:
1253 return infoPtr->bUnicode;
1256 return infoPtr->simple;
1259 return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1262 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1265 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1267 case SB_SETMINHEIGHT:
1268 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1271 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1274 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1277 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1279 case SB_SETTIPTEXTA:
1280 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1282 case SB_SETTIPTEXTW:
1283 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1285 case SB_SETUNICODEFORMAT:
1286 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1289 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1292 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1295 return STATUSBAR_WMDestroy (infoPtr);
1298 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1301 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1303 case WM_GETTEXTLENGTH:
1304 return STATUSBAR_GetTextLength (infoPtr, 0);
1306 case WM_LBUTTONDBLCLK:
1307 return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, lParam);
1310 return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, lParam);
1313 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1316 res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
1317 (short)HIWORD(lParam));
1318 if (res != HTERROR) return res;
1319 return DefWindowProcW (hwnd, msg, wParam, lParam);
1321 case WM_NCLBUTTONUP:
1322 case WM_NCLBUTTONDOWN:
1323 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1326 case WM_NOTIFYFORMAT:
1327 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1329 case WM_PRINTCLIENT:
1331 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1333 case WM_RBUTTONDBLCLK:
1334 return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, lParam);
1337 return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, lParam);
1340 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1343 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1346 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1347 return DefWindowProcW (hwnd, msg, wParam, lParam);
1349 case WM_THEMECHANGED:
1350 return theme_changed (infoPtr);
1353 if ((msg >= WM_USER) && (msg < WM_APP))
1354 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1355 msg, wParam, lParam);
1356 return DefWindowProcW (hwnd, msg, wParam, lParam);
1361 /***********************************************************************
1362 * STATUS_Register [Internal]
1364 * Registers the status window class.
1368 STATUS_Register (void)
1372 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1373 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1374 wndClass.lpfnWndProc = StatusWindowProc;
1375 wndClass.cbClsExtra = 0;
1376 wndClass.cbWndExtra = sizeof(STATUS_INFO *);
1377 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1378 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1379 wndClass.lpszClassName = STATUSCLASSNAMEW;
1381 RegisterClassW (&wndClass);
1385 /***********************************************************************
1386 * STATUS_Unregister [Internal]
1388 * Unregisters the status window class.
1392 STATUS_Unregister (void)
1394 UnregisterClassW (STATUSCLASSNAMEW, NULL);