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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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; /* unicode flag */
81 BOOL NtfUnicode; /* notify format */
82 STATUSWINDOWPART part0; /* simple window */
83 STATUSWINDOWPART* parts;
90 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
91 * The second cdrom contains executables drawstat.exe, gettext.exe,
92 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
99 static const WCHAR themeClass[] = { 'S','t','a','t','u','s',0 };
103 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
105 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
107 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
111 STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
113 HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
117 TRACE("draw size grip %ld,%ld - %ld,%ld\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
123 gripperRect = *lpRect;
124 if (SUCCEEDED (GetThemePartSize (theme, hdc, SP_GRIPPER, 0, lpRect,
125 TS_DRAW, &gripperSize)))
127 gripperRect.left = gripperRect.right - gripperSize.cx;
128 gripperRect.top = gripperRect.bottom - gripperSize.cy;
129 if (SUCCEEDED (DrawThemeBackground(theme, hdc, SP_GRIPPER, 0, &gripperRect, NULL)))
134 pt.x = lpRect->right - 1;
135 pt.y = lpRect->bottom - 1;
137 hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
138 hOldPen = SelectObject( hdc, hPenFace );
139 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
140 LineTo (hdc, pt.x, pt.y);
141 LineTo (hdc, pt.x, pt.y - 13);
146 hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
147 SelectObject( hdc, hPenShadow );
148 for (i = 1; i < 11; i += 4) {
149 MoveToEx (hdc, pt.x - i, pt.y, NULL);
150 LineTo (hdc, pt.x + 1, pt.y - i - 1);
152 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
153 LineTo (hdc, pt.x + 1, pt.y - i - 2);
156 hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
157 SelectObject( hdc, hPenHighlight );
158 for (i = 3; i < 13; i += 4) {
159 MoveToEx (hdc, pt.x - i, pt.y, NULL);
160 LineTo (hdc, pt.x + 1, pt.y - i - 1);
163 SelectObject (hdc, hOldPen);
164 DeleteObject( hPenFace );
165 DeleteObject( hPenShadow );
166 DeleteObject( hPenHighlight );
171 STATUSBAR_DrawPart (STATUS_INFO *infoPtr, HDC hdc, STATUSWINDOWPART *part, int itemID)
173 RECT r = part->bound;
174 UINT border = BDR_SUNKENOUTER;
175 HTHEME theme = GetWindowTheme (infoPtr->Self);
176 int themePart = SP_PANE;
178 TRACE("part bound %ld,%ld - %ld,%ld\n", r.left, r.top, r.right, r.bottom);
179 if (part->style & SBT_POPOUT)
180 border = BDR_RAISEDOUTER;
181 else if (part->style & SBT_NOBORDERS)
186 if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
187 && (infoPtr->simple || (itemID == (infoPtr->numParts-1))))
188 themePart = SP_GRIPPERPANE;
189 DrawThemeBackground(theme, hdc, themePart, 0, &r, NULL);
192 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
194 if (part->style & SBT_OWNERDRAW) {
197 dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
199 dis.hwndItem = infoPtr->Self;
202 dis.itemData = (ULONG_PTR)part->text;
203 SendMessageW (infoPtr->Notify, WM_DRAWITEM, (WPARAM)dis.CtlID, (LPARAM)&dis);
206 INT cy = r.bottom - r.top;
209 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
212 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
218 STATUSBAR_RefreshPart (STATUS_INFO *infoPtr, HDC hdc, STATUSWINDOWPART *part, int itemID)
224 TRACE("item %d\n", itemID);
225 if (!IsWindowVisible (infoPtr->Self))
228 if (part->bound.right < part->bound.left) return;
230 if ((theme = GetWindowTheme (infoPtr->Self)))
233 GetClientRect (infoPtr->Self, &cr);
234 DrawThemeBackground(theme, hdc, 0, 0, &cr, &part->bound);
238 if (infoPtr->clrBk != CLR_DEFAULT)
239 hbrBk = CreateSolidBrush (infoPtr->clrBk);
241 hbrBk = GetSysColorBrush (COLOR_3DFACE);
242 FillRect(hdc, &part->bound, hbrBk);
243 if (infoPtr->clrBk != CLR_DEFAULT)
244 DeleteObject (hbrBk);
247 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
249 STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
251 SelectObject (hdc, hOldFont);
253 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
256 GetClientRect (infoPtr->Self, &rect);
257 STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
263 STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
272 if (!IsWindowVisible(infoPtr->Self))
275 STATUSBAR_SetPartBounds(infoPtr);
277 GetClientRect (infoPtr->Self, &rect);
279 if ((theme = GetWindowTheme (infoPtr->Self)))
281 DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
285 if (infoPtr->clrBk != CLR_DEFAULT)
286 hbrBk = CreateSolidBrush (infoPtr->clrBk);
288 hbrBk = GetSysColorBrush (COLOR_3DFACE);
289 FillRect(hdc, &rect, hbrBk);
290 if (infoPtr->clrBk != CLR_DEFAULT)
291 DeleteObject (hbrBk);
294 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
296 if (infoPtr->simple) {
297 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
299 for (i = 0; i < infoPtr->numParts; i++) {
300 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
304 SelectObject (hdc, hOldFont);
306 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
307 STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
314 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
316 STATUSWINDOWPART *part;
320 /* get our window size */
321 GetClientRect (infoPtr->Self, &rect);
322 TRACE("client wnd size is %ld,%ld - %ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom);
324 rect.left += infoPtr->horizontalBorder;
325 rect.top += infoPtr->verticalBorder;
327 /* set bounds for simple rectangle */
328 infoPtr->part0.bound = rect;
330 /* set bounds for non-simple rectangles */
331 for (i = 0; i < infoPtr->numParts; i++) {
332 part = &infoPtr->parts[i];
333 r = &infoPtr->parts[i].bound;
335 r->bottom = rect.bottom;
339 r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
341 r->right = rect.right;
345 if (infoPtr->hwndToolTip) {
348 ti.cbSize = sizeof(TTTOOLINFOW);
349 ti.hwnd = infoPtr->Self;
352 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
360 STATUSBAR_Relay2Tip (STATUS_INFO *infoPtr, UINT uMsg,
361 WPARAM wParam, LPARAM lParam)
365 msg.hwnd = infoPtr->Self;
369 msg.time = GetMessageTime ();
370 msg.pt.x = LOWORD(GetMessagePos ());
371 msg.pt.y = HIWORD(GetMessagePos ());
373 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
378 STATUSBAR_GetBorders (STATUS_INFO *infoPtr, INT out[])
381 out[0] = infoPtr->horizontalBorder;
382 out[1] = infoPtr->verticalBorder;
383 out[2] = infoPtr->horizontalGap;
390 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, INT in[])
393 infoPtr->horizontalBorder = in[0];
394 infoPtr->verticalBorder = in[1];
395 infoPtr->horizontalGap = in[2];
396 InvalidateRect(infoPtr->Self, NULL, FALSE);
403 STATUSBAR_GetIcon (STATUS_INFO *infoPtr, INT nPart)
405 TRACE("%d\n", nPart);
406 /* MSDN says: "simple parts are indexed with -1" */
407 if ((nPart < -1) || (nPart >= infoPtr->numParts))
411 return (infoPtr->part0.hIcon);
413 return (infoPtr->parts[nPart].hIcon);
418 STATUSBAR_GetParts (STATUS_INFO *infoPtr, INT num_parts, INT parts[])
422 TRACE("(%d)\n", num_parts);
424 for (i = 0; i < num_parts; i++) {
425 parts[i] = infoPtr->parts[i].x;
428 return infoPtr->numParts;
433 STATUSBAR_GetRect (STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
435 TRACE("part %d\n", nPart);
437 *rect = infoPtr->part0.bound;
439 *rect = infoPtr->parts[nPart].bound;
445 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
447 STATUSWINDOWPART *part;
450 TRACE("part %d\n", nPart);
452 /* MSDN says: "simple parts use index of 0", so this check is ok. */
453 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
456 part = &infoPtr->part0;
458 part = &infoPtr->parts[nPart];
460 if (part->style & SBT_OWNERDRAW)
461 result = (LRESULT)part->text;
463 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
464 NULL, 0, NULL, NULL ) - 1 : 0;
465 result = MAKELONG( len, part->style );
466 if (part->text && buf)
467 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
474 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
476 STATUSWINDOWPART *part;
479 TRACE("part %d\n", nPart);
480 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
483 part = &infoPtr->part0;
485 part = &infoPtr->parts[nPart];
487 if (part->style & SBT_OWNERDRAW)
488 result = (LRESULT)part->text;
490 result = part->text ? strlenW (part->text) : 0;
491 result |= (part->style << 16);
492 if (part->text && buf)
493 strcpyW (buf, part->text);
500 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
502 STATUSWINDOWPART *part;
505 TRACE("part %d\n", nPart);
507 /* MSDN says: "simple parts use index of 0", so this check is ok. */
508 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
511 part = &infoPtr->part0;
513 part = &infoPtr->parts[nPart];
515 if ((~part->style & SBT_OWNERDRAW) && part->text)
516 result = strlenW(part->text);
520 result |= (part->style << 16);
525 STATUSBAR_GetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
529 CHAR buf[INFOTIPSIZE];
532 if (infoPtr->hwndToolTip) {
534 ti.cbSize = sizeof(TTTOOLINFOA);
535 ti.hwnd = infoPtr->Self;
538 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
540 lstrcpynA (tip, buf, size);
547 STATUSBAR_GetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
551 WCHAR buf[INFOTIPSIZE];
554 if (infoPtr->hwndToolTip) {
556 ti.cbSize = sizeof(TTTOOLINFOW);
557 ti.hwnd = infoPtr->Self;
560 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
562 lstrcpynW(tip, buf, size);
570 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
574 oldBkColor = infoPtr->clrBk;
575 infoPtr->clrBk = color;
576 InvalidateRect(infoPtr->Self, NULL, FALSE);
578 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
584 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
586 if ((nPart < -1) || (nPart >= infoPtr->numParts))
589 TRACE("setting part %d\n", nPart);
591 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
593 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
595 infoPtr->part0.hIcon = hIcon;
597 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
599 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
602 infoPtr->parts[nPart].hIcon = hIcon;
603 if (!(infoPtr->simple))
604 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
611 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
614 TRACE("(height=%d)\n", height);
615 if (IsWindowVisible (infoPtr->Self)) {
620 GetClientRect (infoPtr->Notify, &parent_rect);
621 infoPtr->height = height + infoPtr->verticalBorder;
623 if ((theme = GetWindowTheme (infoPtr->Self)))
625 /* Determine bar height from theme such that the content area is
626 * 'height' pixels large */
627 HDC hdc = GetDC (infoPtr->Self);
629 memset (&r, 0, sizeof (r));
631 if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
633 infoPtr->height = r.bottom - r.top;
635 ReleaseDC (infoPtr->Self, hdc);
638 width = parent_rect.right - parent_rect.left;
639 x = parent_rect.left;
640 y = parent_rect.bottom - infoPtr->height;
641 MoveWindow (infoPtr->Self, parent_rect.left,
642 parent_rect.bottom - infoPtr->height,
643 width, infoPtr->height, TRUE);
644 STATUSBAR_SetPartBounds (infoPtr);
652 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
654 STATUSWINDOWPART *tmp;
657 TRACE("(%d,%p)\n", count, parts);
659 oldNumParts = infoPtr->numParts;
660 infoPtr->numParts = count;
661 if (oldNumParts > infoPtr->numParts) {
662 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
663 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
664 Free (infoPtr->parts[i].text);
666 } else if (oldNumParts < infoPtr->numParts) {
667 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
668 if (!tmp) return FALSE;
669 for (i = 0; i < oldNumParts; i++) {
670 tmp[i] = infoPtr->parts[i];
673 Free (infoPtr->parts);
674 infoPtr->parts = tmp;
676 if (oldNumParts == infoPtr->numParts) {
677 for (i=0; i < oldNumParts; i++)
678 if (infoPtr->parts[i].x != parts[i])
680 if (i==oldNumParts) /* Unchanged? no need to redraw! */
684 for (i = 0; i < infoPtr->numParts; i++)
685 infoPtr->parts[i].x = parts[i];
687 if (infoPtr->hwndToolTip) {
691 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
692 ti.cbSize = sizeof(TTTOOLINFOW);
693 ti.hwnd = infoPtr->Self;
695 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
696 if (nTipCount < infoPtr->numParts) {
698 for (i = nTipCount; i < infoPtr->numParts; i++) {
699 TRACE("add tool %d\n", i);
701 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
705 else if (nTipCount > infoPtr->numParts) {
707 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
708 TRACE("delete tool %d\n", i);
710 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
715 STATUSBAR_SetPartBounds (infoPtr);
716 InvalidateRect(infoPtr->Self, NULL, FALSE);
722 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
723 LPCWSTR text, BOOL isW)
725 STATUSWINDOWPART *part=NULL;
726 BOOL changed = FALSE;
729 if (style & SBT_OWNERDRAW) {
730 TRACE("part %d, text %p\n",nPart,text);
732 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
734 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
735 * window is assumed to be a simple window */
737 if (nPart == 0x00ff) {
738 part = &infoPtr->part0;
740 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
741 part = &infoPtr->parts[nPart];
744 if (!part) return FALSE;
746 if (part->style != style)
749 oldStyle = part->style;
751 if (style & SBT_OWNERDRAW) {
752 if (!(oldStyle & SBT_OWNERDRAW)) {
755 } else if (part->text == text)
757 part->text = (LPWSTR)text;
762 LPCSTR atxt = (LPCSTR)text;
763 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
764 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
765 if (!ntext) return FALSE;
766 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
768 ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
769 if (!ntext) return FALSE;
770 strcpyW (ntext, text);
773 /* check if text is unchanged -> no need to redraw */
775 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
780 if (!changed && !part->text)
784 if (part->text && !(oldStyle & SBT_OWNERDRAW))
788 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
795 STATUSBAR_SetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR text)
797 TRACE("part %d: \"%s\"\n", id, text);
798 if (infoPtr->hwndToolTip) {
800 ti.cbSize = sizeof(TTTOOLINFOA);
801 ti.hwnd = infoPtr->Self;
805 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
813 STATUSBAR_SetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR text)
815 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
816 if (infoPtr->hwndToolTip) {
818 ti.cbSize = sizeof(TTTOOLINFOW);
819 ti.hwnd = infoPtr->Self;
823 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
830 inline static LRESULT
831 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
833 BOOL bOld = infoPtr->bUnicode;
835 TRACE("(0x%x)\n", bUnicode);
836 infoPtr->bUnicode = bUnicode;
843 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
847 TRACE("(simple=%d)\n", simple);
848 if (infoPtr->simple == simple) /* no need to change */
851 infoPtr->simple = simple;
853 /* send notification */
854 nmhdr.hwndFrom = infoPtr->Self;
855 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
856 nmhdr.code = SBN_SIMPLEMODECHANGE;
857 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
858 InvalidateRect(infoPtr->Self, NULL, FALSE);
864 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
869 for (i = 0; i < infoPtr->numParts; i++) {
870 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
871 Free (infoPtr->parts[i].text);
873 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
874 Free (infoPtr->part0.text);
875 Free (infoPtr->parts);
877 /* delete default font */
878 if (infoPtr->hDefaultFont)
879 DeleteObject (infoPtr->hDefaultFont);
881 /* delete tool tip control */
882 if (infoPtr->hwndToolTip)
883 DestroyWindow (infoPtr->hwndToolTip);
885 CloseThemeData (GetWindowTheme (infoPtr->Self));
887 SetWindowLongPtrW(infoPtr->Self, 0, 0);
894 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
896 STATUS_INFO *infoPtr;
897 NONCLIENTMETRICSW nclm;
900 int i, width, len, textHeight = 0;
904 infoPtr = (STATUS_INFO*)Alloc (sizeof(STATUS_INFO));
905 if (!infoPtr) goto create_fail;
906 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
908 infoPtr->Self = hwnd;
909 infoPtr->Notify = lpCreate->hwndParent;
910 infoPtr->numParts = 1;
912 infoPtr->simple = FALSE;
913 infoPtr->clrBk = CLR_DEFAULT;
915 infoPtr->horizontalBorder = HORZ_BORDER;
916 infoPtr->verticalBorder = VERT_BORDER;
917 infoPtr->horizontalGap = HORZ_GAP;
919 i = SendMessageW(infoPtr->Notify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
920 infoPtr->NtfUnicode = (i == NFR_UNICODE);
922 GetClientRect (hwnd, &rect);
923 InvalidateRect (hwnd, &rect, 0);
926 ZeroMemory (&nclm, sizeof(nclm));
927 nclm.cbSize = sizeof(nclm);
928 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
929 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
931 /* initialize simple case */
932 infoPtr->part0.bound = rect;
933 infoPtr->part0.text = 0;
934 infoPtr->part0.x = 0;
935 infoPtr->part0.style = 0;
936 infoPtr->part0.hIcon = 0;
938 /* initialize first part */
939 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
940 if (!infoPtr->parts) goto create_fail;
941 infoPtr->parts[0].bound = rect;
942 infoPtr->parts[0].text = 0;
943 infoPtr->parts[0].x = -1;
944 infoPtr->parts[0].style = 0;
945 infoPtr->parts[0].hIcon = 0;
947 OpenThemeData (hwnd, themeClass);
949 if (IsWindowUnicode (hwnd)) {
950 infoPtr->bUnicode = TRUE;
951 if (lpCreate->lpszName &&
952 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
953 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
954 if (!infoPtr->parts[0].text) goto create_fail;
955 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
959 if (lpCreate->lpszName &&
960 (len = strlen((LPCSTR)lpCreate->lpszName))) {
961 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
962 infoPtr->parts[0].text = Alloc (lenW*sizeof(WCHAR));
963 if (!infoPtr->parts[0].text) goto create_fail;
964 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
965 infoPtr->parts[0].text, lenW );
969 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
970 /* native seems to clear WS_BORDER, too */
971 dwStyle &= ~WS_BORDER;
973 /* statusbars on managed windows should not have SIZEGRIP style */
974 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent &&
975 GetPropA( lpCreate->hwndParent, "__wine_x11_managed" ))
976 dwStyle &= ~SBARS_SIZEGRIP;
978 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
980 if ((hdc = GetDC (hwnd))) {
984 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
985 GetTextMetricsW (hdc, &tm);
986 textHeight = tm.tmHeight;
987 SelectObject (hdc, hOldFont);
988 ReleaseDC (hwnd, hdc);
990 TRACE(" textHeight=%d\n", textHeight);
992 if (dwStyle & SBT_TOOLTIPS) {
993 infoPtr->hwndToolTip =
994 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
995 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
996 CW_USEDEFAULT, hwnd, 0,
997 (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
999 if (infoPtr->hwndToolTip) {
1000 NMTOOLTIPSCREATED nmttc;
1002 nmttc.hdr.hwndFrom = hwnd;
1003 nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
1004 nmttc.hdr.code = NM_TOOLTIPSCREATED;
1005 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1007 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
1008 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
1012 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
1014 GetClientRect (infoPtr->Notify, &rect);
1015 width = rect.right - rect.left;
1016 infoPtr->height = textHeight + 4 + infoPtr->verticalBorder;
1018 if ((theme = GetWindowTheme (hwnd)))
1020 /* Determine bar height from theme such that the content area is
1021 * textHeight pixels large */
1022 HDC hdc = GetDC (hwnd);
1024 memset (&r, 0, sizeof (r));
1025 r.bottom = textHeight;
1026 if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
1028 infoPtr->height = r.bottom - r.top;
1030 ReleaseDC (hwnd, hdc);
1033 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
1034 width, infoPtr->height, SWP_NOZORDER);
1035 STATUSBAR_SetPartBounds (infoPtr);
1041 TRACE(" failed!\n");
1042 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
1047 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
1048 * of the first part only (usual behaviour) */
1050 STATUSBAR_WMGetText (STATUS_INFO *infoPtr, INT size, LPWSTR buf)
1055 if (!(infoPtr->parts[0].text))
1057 if (infoPtr->bUnicode)
1058 len = strlenW (infoPtr->parts[0].text);
1060 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
1063 if (infoPtr->bUnicode)
1064 strcpyW (buf, infoPtr->parts[0].text);
1066 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
1067 (LPSTR)buf, len+1, NULL, NULL );
1076 STATUSBAR_WMNCHitTest (STATUS_INFO *infoPtr, INT x, INT y)
1078 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1082 GetClientRect (infoPtr->Self, &rect);
1086 ScreenToClient (infoPtr->Self, &pt);
1088 rect.left = rect.right - 13;
1091 if (PtInRect (&rect, pt))
1092 return HTBOTTOMRIGHT;
1100 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1105 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1106 hdc = BeginPaint (infoPtr->Self, &ps);
1107 STATUSBAR_Refresh (infoPtr, hdc);
1108 EndPaint (infoPtr->Self, &ps);
1115 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1117 infoPtr->hFont = font;
1118 TRACE("%p\n", infoPtr->hFont);
1120 InvalidateRect(infoPtr->Self, NULL, FALSE);
1127 STATUSBAR_WMSetText (STATUS_INFO *infoPtr, LPCSTR text)
1129 STATUSWINDOWPART *part;
1133 if (infoPtr->numParts == 0)
1136 part = &infoPtr->parts[0];
1137 /* duplicate string */
1141 if (infoPtr->bUnicode) {
1142 if (text && (len = strlenW((LPCWSTR)text))) {
1143 part->text = Alloc ((len+1)*sizeof(WCHAR));
1144 if (!part->text) return FALSE;
1145 strcpyW (part->text, (LPCWSTR)text);
1149 if (text && (len = lstrlenA(text))) {
1150 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1151 part->text = Alloc (lenW*sizeof(WCHAR));
1152 if (!part->text) return FALSE;
1153 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1157 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1164 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1169 /* Need to resize width to match parent */
1170 TRACE("flags %04x\n", flags);
1172 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1173 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1177 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1179 /* width and height don't apply */
1180 GetClientRect (infoPtr->Notify, &parent_rect);
1181 width = parent_rect.right - parent_rect.left;
1182 x = parent_rect.left;
1183 y = parent_rect.bottom - infoPtr->height;
1184 MoveWindow (infoPtr->Self, parent_rect.left,
1185 parent_rect.bottom - infoPtr->height,
1186 width, infoPtr->height, TRUE);
1187 STATUSBAR_SetPartBounds (infoPtr);
1192 /* update theme after a WM_THEMECHANGED message */
1193 static LRESULT theme_changed (STATUS_INFO* infoPtr)
1195 HTHEME theme = GetWindowTheme (infoPtr->Self);
1196 CloseThemeData (theme);
1197 OpenThemeData (infoPtr->Self, themeClass);
1203 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1205 if (cmd == NF_REQUERY) {
1206 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1207 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1209 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1214 STATUSBAR_SendNotify (STATUS_INFO *infoPtr, UINT code)
1218 TRACE("code %04x\n", code);
1219 nmhdr.hwndFrom = infoPtr->Self;
1220 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
1222 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
1228 static LRESULT WINAPI
1229 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1231 STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1232 INT nPart = ((INT) wParam) & 0x00ff;
1235 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1236 if (!infoPtr && msg != WM_CREATE)
1237 return DefWindowProcW (hwnd, msg, wParam, lParam);
1241 return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1244 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1247 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1250 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1253 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1256 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1258 case SB_GETTEXTLENGTHA:
1259 case SB_GETTEXTLENGTHW:
1260 return STATUSBAR_GetTextLength (infoPtr, nPart);
1262 case SB_GETTIPTEXTA:
1263 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1265 case SB_GETTIPTEXTW:
1266 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1268 case SB_GETUNICODEFORMAT:
1269 return infoPtr->bUnicode;
1272 return infoPtr->simple;
1275 return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1278 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1281 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1283 case SB_SETMINHEIGHT:
1284 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1287 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1290 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1293 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1295 case SB_SETTIPTEXTA:
1296 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1298 case SB_SETTIPTEXTW:
1299 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1301 case SB_SETUNICODEFORMAT:
1302 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1305 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1308 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1311 return STATUSBAR_WMDestroy (infoPtr);
1314 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1317 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1319 case WM_GETTEXTLENGTH:
1320 return STATUSBAR_GetTextLength (infoPtr, 0);
1322 case WM_LBUTTONDBLCLK:
1323 return STATUSBAR_SendNotify (infoPtr, NM_DBLCLK);
1326 return STATUSBAR_SendNotify (infoPtr, NM_CLICK);
1329 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1332 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1333 (INT)HIWORD(lParam));
1334 if (res != HTERROR) return res;
1335 return DefWindowProcW (hwnd, msg, wParam, lParam);
1337 case WM_NCLBUTTONUP:
1338 case WM_NCLBUTTONDOWN:
1339 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1342 case WM_NOTIFYFORMAT:
1343 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1345 case WM_PRINTCLIENT:
1347 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1349 case WM_RBUTTONDBLCLK:
1350 return STATUSBAR_SendNotify (infoPtr, NM_RDBLCLK);
1353 return STATUSBAR_SendNotify (infoPtr, NM_RCLICK);
1356 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1359 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1362 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1363 return DefWindowProcW (hwnd, msg, wParam, lParam);
1365 case WM_THEMECHANGED:
1366 return theme_changed (infoPtr);
1369 if ((msg >= WM_USER) && (msg < WM_APP))
1370 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1371 msg, wParam, lParam);
1372 return DefWindowProcW (hwnd, msg, wParam, lParam);
1377 /***********************************************************************
1378 * STATUS_Register [Internal]
1380 * Registers the status window class.
1384 STATUS_Register (void)
1388 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1389 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1390 wndClass.lpfnWndProc = StatusWindowProc;
1391 wndClass.cbClsExtra = 0;
1392 wndClass.cbWndExtra = sizeof(STATUS_INFO *);
1393 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1394 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1395 wndClass.lpszClassName = STATUSCLASSNAMEW;
1397 RegisterClassW (&wndClass);
1401 /***********************************************************************
1402 * STATUS_Unregister [Internal]
1404 * Unregisters the status window class.
1408 STATUS_Unregister (void)
1410 UnregisterClassW (STATUSCLASSNAMEW, NULL);