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; /* 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 %d,%d - %d,%d\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 (const STATUS_INFO *infoPtr, HDC hdc, const 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 %d,%d - %d,%d\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 (const STATUS_INFO *infoPtr, HDC hdc, const 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_InternalHitTest(const STATUS_INFO *infoPtr, const LPPOINT pt)
320 for (i = 0; i < infoPtr->numParts; i++)
321 if (pt->x >= infoPtr->parts[i].bound.left && pt->x <= infoPtr->parts[i].bound.right)
328 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
330 STATUSWINDOWPART *part;
334 /* get our window size */
335 GetClientRect (infoPtr->Self, &rect);
336 TRACE("client wnd size is %d,%d - %d,%d\n", rect.left, rect.top, rect.right, rect.bottom);
338 rect.left += infoPtr->horizontalBorder;
339 rect.top += infoPtr->verticalBorder;
341 /* set bounds for simple rectangle */
342 infoPtr->part0.bound = rect;
344 /* set bounds for non-simple rectangles */
345 for (i = 0; i < infoPtr->numParts; i++) {
346 part = &infoPtr->parts[i];
347 r = &infoPtr->parts[i].bound;
349 r->bottom = rect.bottom;
353 r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
355 r->right = rect.right;
359 if (infoPtr->hwndToolTip) {
362 ti.cbSize = sizeof(TTTOOLINFOW);
363 ti.hwnd = infoPtr->Self;
366 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
374 STATUSBAR_Relay2Tip (const STATUS_INFO *infoPtr, UINT uMsg,
375 WPARAM wParam, LPARAM lParam)
379 msg.hwnd = infoPtr->Self;
383 msg.time = GetMessageTime ();
384 msg.pt.x = (short)LOWORD(GetMessagePos ());
385 msg.pt.y = (short)HIWORD(GetMessagePos ());
387 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
392 STATUSBAR_GetBorders (const STATUS_INFO *infoPtr, INT out[])
395 out[0] = infoPtr->horizontalBorder;
396 out[1] = infoPtr->verticalBorder;
397 out[2] = infoPtr->horizontalGap;
404 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, const INT in[])
407 infoPtr->horizontalBorder = in[0];
408 infoPtr->verticalBorder = in[1];
409 infoPtr->horizontalGap = in[2];
410 InvalidateRect(infoPtr->Self, NULL, FALSE);
417 STATUSBAR_GetIcon (const STATUS_INFO *infoPtr, INT nPart)
419 TRACE("%d\n", nPart);
420 /* MSDN says: "simple parts are indexed with -1" */
421 if ((nPart < -1) || (nPart >= infoPtr->numParts))
425 return (infoPtr->part0.hIcon);
427 return (infoPtr->parts[nPart].hIcon);
432 STATUSBAR_GetParts (const STATUS_INFO *infoPtr, INT num_parts, INT parts[])
436 TRACE("(%d)\n", num_parts);
438 for (i = 0; i < num_parts; i++) {
439 parts[i] = infoPtr->parts[i].x;
442 return infoPtr->numParts;
447 STATUSBAR_GetRect (const STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
449 TRACE("part %d\n", nPart);
450 if(nPart >= infoPtr->numParts || nPart < 0)
453 *rect = infoPtr->part0.bound;
455 *rect = infoPtr->parts[nPart].bound;
461 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
463 STATUSWINDOWPART *part;
466 TRACE("part %d\n", nPart);
468 /* MSDN says: "simple parts use index of 0", so this check is ok. */
469 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
472 part = &infoPtr->part0;
474 part = &infoPtr->parts[nPart];
476 if (part->style & SBT_OWNERDRAW)
477 result = (LRESULT)part->text;
479 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
480 NULL, 0, NULL, NULL ) - 1 : 0;
481 result = MAKELONG( len, part->style );
482 if (part->text && buf)
483 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
490 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
492 STATUSWINDOWPART *part;
495 TRACE("part %d\n", nPart);
496 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
499 part = &infoPtr->part0;
501 part = &infoPtr->parts[nPart];
503 if (part->style & SBT_OWNERDRAW)
504 result = (LRESULT)part->text;
506 result = part->text ? strlenW (part->text) : 0;
507 result |= (part->style << 16);
508 if (part->text && buf)
509 strcpyW (buf, part->text);
516 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
518 STATUSWINDOWPART *part;
521 TRACE("part %d\n", nPart);
523 /* MSDN says: "simple parts use index of 0", so this check is ok. */
524 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
527 part = &infoPtr->part0;
529 part = &infoPtr->parts[nPart];
531 if ((~part->style & SBT_OWNERDRAW) && part->text)
532 result = strlenW(part->text);
536 result |= (part->style << 16);
541 STATUSBAR_GetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
545 CHAR buf[INFOTIPSIZE];
548 if (infoPtr->hwndToolTip) {
550 ti.cbSize = sizeof(TTTOOLINFOA);
551 ti.hwnd = infoPtr->Self;
554 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
556 lstrcpynA (tip, buf, size);
563 STATUSBAR_GetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
567 WCHAR buf[INFOTIPSIZE];
570 if (infoPtr->hwndToolTip) {
572 ti.cbSize = sizeof(TTTOOLINFOW);
573 ti.hwnd = infoPtr->Self;
576 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
578 lstrcpynW(tip, buf, size);
586 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
590 oldBkColor = infoPtr->clrBk;
591 infoPtr->clrBk = color;
592 InvalidateRect(infoPtr->Self, NULL, FALSE);
594 TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
600 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
602 if ((nPart < -1) || (nPart >= infoPtr->numParts))
605 TRACE("setting part %d\n", nPart);
607 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
609 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
611 infoPtr->part0.hIcon = hIcon;
613 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
615 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
618 infoPtr->parts[nPart].hIcon = hIcon;
619 if (!(infoPtr->simple))
620 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
627 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
630 TRACE("(height=%d)\n", height);
631 if (IsWindowVisible (infoPtr->Self)) {
636 GetClientRect (infoPtr->Notify, &parent_rect);
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 width = parent_rect.right - parent_rect.left;
655 x = parent_rect.left;
656 y = parent_rect.bottom - infoPtr->height;
657 MoveWindow (infoPtr->Self, parent_rect.left,
658 parent_rect.bottom - infoPtr->height,
659 width, infoPtr->height, TRUE);
660 STATUSBAR_SetPartBounds (infoPtr);
668 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
670 STATUSWINDOWPART *tmp;
673 TRACE("(%d,%p)\n", count, parts);
675 oldNumParts = infoPtr->numParts;
676 infoPtr->numParts = count;
677 if (oldNumParts > infoPtr->numParts) {
678 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
679 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
680 Free (infoPtr->parts[i].text);
682 } else if (oldNumParts < infoPtr->numParts) {
683 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
684 if (!tmp) return FALSE;
685 for (i = 0; i < oldNumParts; i++) {
686 tmp[i] = infoPtr->parts[i];
688 Free (infoPtr->parts);
689 infoPtr->parts = tmp;
691 if (oldNumParts == infoPtr->numParts) {
692 for (i=0; i < oldNumParts; i++)
693 if (infoPtr->parts[i].x != parts[i])
695 if (i==oldNumParts) /* Unchanged? no need to redraw! */
699 for (i = 0; i < infoPtr->numParts; i++)
700 infoPtr->parts[i].x = parts[i];
702 if (infoPtr->hwndToolTip) {
706 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
707 ti.cbSize = sizeof(TTTOOLINFOW);
708 ti.hwnd = infoPtr->Self;
710 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
711 if (nTipCount < infoPtr->numParts) {
713 for (i = nTipCount; i < infoPtr->numParts; i++) {
714 TRACE("add tool %d\n", i);
716 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
720 else if (nTipCount > infoPtr->numParts) {
722 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
723 TRACE("delete tool %d\n", i);
725 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
730 STATUSBAR_SetPartBounds (infoPtr);
731 InvalidateRect(infoPtr->Self, NULL, FALSE);
737 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
738 LPCWSTR text, BOOL isW)
740 STATUSWINDOWPART *part=NULL;
741 BOOL changed = FALSE;
744 if (style & SBT_OWNERDRAW) {
745 TRACE("part %d, text %p\n",nPart,text);
747 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
749 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
750 * window is assumed to be a simple window */
752 if (nPart == 0x00ff) {
753 part = &infoPtr->part0;
755 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
756 part = &infoPtr->parts[nPart];
759 if (!part) return FALSE;
761 if (part->style != style)
764 oldStyle = part->style;
766 if (style & SBT_OWNERDRAW) {
767 if (!(oldStyle & SBT_OWNERDRAW))
769 else if (part->text == text)
771 part->text = (LPWSTR)text;
776 LPCSTR atxt = (LPCSTR)text;
777 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
778 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
779 if (!ntext) return FALSE;
780 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
782 ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
783 if (!ntext) return FALSE;
784 strcpyW (ntext, text);
787 /* check if text is unchanged -> no need to redraw */
789 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
794 if (!changed && !part->text)
798 if (!(oldStyle & SBT_OWNERDRAW))
802 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
803 UpdateWindow(infoPtr->Self);
810 STATUSBAR_SetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR text)
812 TRACE("part %d: \"%s\"\n", id, text);
813 if (infoPtr->hwndToolTip) {
815 ti.cbSize = sizeof(TTTOOLINFOA);
816 ti.hwnd = infoPtr->Self;
820 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
828 STATUSBAR_SetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR text)
830 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
831 if (infoPtr->hwndToolTip) {
833 ti.cbSize = sizeof(TTTOOLINFOW);
834 ti.hwnd = infoPtr->Self;
838 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
845 static inline LRESULT
846 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
848 BOOL bOld = infoPtr->bUnicode;
850 TRACE("(0x%x)\n", bUnicode);
851 infoPtr->bUnicode = bUnicode;
858 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
862 TRACE("(simple=%d)\n", simple);
863 if (infoPtr->simple == simple) /* no need to change */
866 infoPtr->simple = simple;
868 /* send notification */
869 nmhdr.hwndFrom = infoPtr->Self;
870 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
871 nmhdr.code = SBN_SIMPLEMODECHANGE;
872 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
873 InvalidateRect(infoPtr->Self, NULL, FALSE);
879 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
884 for (i = 0; i < infoPtr->numParts; i++) {
885 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
886 Free (infoPtr->parts[i].text);
888 if (!(infoPtr->part0.style & SBT_OWNERDRAW))
889 Free (infoPtr->part0.text);
890 Free (infoPtr->parts);
892 /* delete default font */
893 if (infoPtr->hDefaultFont)
894 DeleteObject (infoPtr->hDefaultFont);
896 /* delete tool tip control */
897 if (infoPtr->hwndToolTip)
898 DestroyWindow (infoPtr->hwndToolTip);
900 CloseThemeData (GetWindowTheme (infoPtr->Self));
902 SetWindowLongPtrW(infoPtr->Self, 0, 0);
909 STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
911 STATUS_INFO *infoPtr;
912 NONCLIENTMETRICSW nclm;
915 int i, width, len, textHeight = 0;
919 infoPtr = (STATUS_INFO*)Alloc (sizeof(STATUS_INFO));
920 if (!infoPtr) goto create_fail;
921 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
923 infoPtr->Self = hwnd;
924 infoPtr->Notify = lpCreate->hwndParent;
925 infoPtr->numParts = 1;
927 infoPtr->simple = FALSE;
928 infoPtr->clrBk = CLR_DEFAULT;
930 infoPtr->horizontalBorder = HORZ_BORDER;
931 infoPtr->verticalBorder = VERT_BORDER;
932 infoPtr->horizontalGap = HORZ_GAP;
934 i = SendMessageW(infoPtr->Notify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
935 infoPtr->NtfUnicode = (i == NFR_UNICODE);
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 (IsWindowUnicode (hwnd)) {
965 infoPtr->bUnicode = TRUE;
966 if (lpCreate->lpszName &&
967 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
968 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
969 if (!infoPtr->parts[0].text) goto create_fail;
970 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
974 if (lpCreate->lpszName &&
975 (len = strlen((LPCSTR)lpCreate->lpszName))) {
976 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
977 infoPtr->parts[0].text = Alloc (lenW*sizeof(WCHAR));
978 if (!infoPtr->parts[0].text) goto create_fail;
979 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
980 infoPtr->parts[0].text, lenW );
984 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
985 /* native seems to clear WS_BORDER, too */
986 dwStyle &= ~WS_BORDER;
988 /* statusbars on managed windows should not have SIZEGRIP style */
989 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent &&
990 GetPropA( lpCreate->hwndParent, "__wine_x11_managed" ))
991 dwStyle &= ~SBARS_SIZEGRIP;
993 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
995 if ((hdc = GetDC (hwnd))) {
999 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
1000 GetTextMetricsW (hdc, &tm);
1001 textHeight = tm.tmHeight;
1002 SelectObject (hdc, hOldFont);
1003 ReleaseDC (hwnd, hdc);
1005 TRACE(" textHeight=%d\n", textHeight);
1007 if (dwStyle & SBT_TOOLTIPS) {
1008 infoPtr->hwndToolTip =
1009 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
1010 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1011 CW_USEDEFAULT, hwnd, 0,
1012 (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
1014 if (infoPtr->hwndToolTip) {
1015 NMTOOLTIPSCREATED nmttc;
1017 nmttc.hdr.hwndFrom = hwnd;
1018 nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
1019 nmttc.hdr.code = NM_TOOLTIPSCREATED;
1020 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1022 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
1023 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
1027 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
1029 GetClientRect (infoPtr->Notify, &rect);
1030 width = rect.right - rect.left;
1031 infoPtr->height = textHeight + 4 + infoPtr->verticalBorder;
1033 if ((theme = GetWindowTheme (hwnd)))
1035 /* Determine bar height from theme such that the content area is
1036 * textHeight pixels large */
1037 HDC hdc = GetDC (hwnd);
1039 memset (&r, 0, sizeof (r));
1040 r.bottom = textHeight;
1041 if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
1043 infoPtr->height = r.bottom - r.top;
1045 ReleaseDC (hwnd, hdc);
1048 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
1049 width, infoPtr->height, SWP_NOZORDER);
1050 STATUSBAR_SetPartBounds (infoPtr);
1056 TRACE(" failed!\n");
1057 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
1062 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
1063 * of the first part only (usual behaviour) */
1065 STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
1070 if (!(infoPtr->parts[0].text))
1072 if (infoPtr->bUnicode)
1073 len = strlenW (infoPtr->parts[0].text);
1075 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
1078 if (infoPtr->bUnicode)
1079 strcpyW (buf, infoPtr->parts[0].text);
1081 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
1082 (LPSTR)buf, len+1, NULL, NULL );
1091 STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
1093 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1097 GetClientRect (infoPtr->Self, &rect);
1101 ScreenToClient (infoPtr->Self, &pt);
1103 rect.left = rect.right - 13;
1106 if (PtInRect (&rect, pt))
1107 return HTBOTTOMRIGHT;
1115 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1120 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1121 hdc = BeginPaint (infoPtr->Self, &ps);
1122 STATUSBAR_Refresh (infoPtr, hdc);
1123 EndPaint (infoPtr->Self, &ps);
1130 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1132 infoPtr->hFont = font;
1133 TRACE("%p\n", infoPtr->hFont);
1135 InvalidateRect(infoPtr->Self, NULL, FALSE);
1142 STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
1144 STATUSWINDOWPART *part;
1148 if (infoPtr->numParts == 0)
1151 part = &infoPtr->parts[0];
1152 /* duplicate string */
1155 if (infoPtr->bUnicode) {
1156 if (text && (len = strlenW((LPCWSTR)text))) {
1157 part->text = Alloc ((len+1)*sizeof(WCHAR));
1158 if (!part->text) return FALSE;
1159 strcpyW (part->text, (LPCWSTR)text);
1163 if (text && (len = lstrlenA(text))) {
1164 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1165 part->text = Alloc (lenW*sizeof(WCHAR));
1166 if (!part->text) return FALSE;
1167 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1171 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1178 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1183 /* Need to resize width to match parent */
1184 TRACE("flags %04x\n", flags);
1186 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1187 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1191 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1193 /* width and height don't apply */
1194 GetClientRect (infoPtr->Notify, &parent_rect);
1195 width = parent_rect.right - parent_rect.left;
1196 x = parent_rect.left;
1197 y = parent_rect.bottom - infoPtr->height;
1198 MoveWindow (infoPtr->Self, parent_rect.left,
1199 parent_rect.bottom - infoPtr->height,
1200 width, infoPtr->height, TRUE);
1201 STATUSBAR_SetPartBounds (infoPtr);
1206 /* update theme after a WM_THEMECHANGED message */
1207 static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1209 HTHEME theme = GetWindowTheme (infoPtr->Self);
1210 CloseThemeData (theme);
1211 OpenThemeData (infoPtr->Self, themeClass);
1217 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1219 if (cmd == NF_REQUERY) {
1220 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1221 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1223 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1228 STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, LPARAM lParam)
1232 TRACE("code %04x, lParam=%lx\n", code, lParam);
1233 nm.hdr.hwndFrom = infoPtr->Self;
1234 nm.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1236 nm.pt.x = (short)LOWORD(lParam);
1237 nm.pt.y = (short)HIWORD(lParam);
1238 nm.dwItemSpec = STATUSBAR_InternalHitTest(infoPtr, &nm.pt);
1240 nm.dwHitInfo = 0x30000; /* seems constant */
1241 SendMessageW(infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nm);
1247 static LRESULT WINAPI
1248 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1250 STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1251 INT nPart = ((INT) wParam) & 0x00ff;
1254 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, msg, wParam, lParam);
1255 if (!infoPtr && msg != WM_CREATE)
1256 return DefWindowProcW (hwnd, msg, wParam, lParam);
1260 return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1263 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1266 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1269 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1272 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1275 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1277 case SB_GETTEXTLENGTHA:
1278 case SB_GETTEXTLENGTHW:
1279 return STATUSBAR_GetTextLength (infoPtr, nPart);
1281 case SB_GETTIPTEXTA:
1282 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1284 case SB_GETTIPTEXTW:
1285 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1287 case SB_GETUNICODEFORMAT:
1288 return infoPtr->bUnicode;
1291 return infoPtr->simple;
1294 return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1297 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1300 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1302 case SB_SETMINHEIGHT:
1303 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1306 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1309 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1312 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1314 case SB_SETTIPTEXTA:
1315 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1317 case SB_SETTIPTEXTW:
1318 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1320 case SB_SETUNICODEFORMAT:
1321 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1324 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1327 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1330 return STATUSBAR_WMDestroy (infoPtr);
1333 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1336 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1338 case WM_GETTEXTLENGTH:
1339 return STATUSBAR_GetTextLength (infoPtr, 0);
1341 case WM_LBUTTONDBLCLK:
1342 return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, lParam);
1345 return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, lParam);
1348 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1351 res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
1352 (short)HIWORD(lParam));
1353 if (res != HTERROR) return res;
1354 return DefWindowProcW (hwnd, msg, wParam, lParam);
1356 case WM_NCLBUTTONUP:
1357 case WM_NCLBUTTONDOWN:
1358 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1361 case WM_NOTIFYFORMAT:
1362 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1364 case WM_PRINTCLIENT:
1366 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1368 case WM_RBUTTONDBLCLK:
1369 return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, lParam);
1372 return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, lParam);
1375 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1378 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1381 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1382 return DefWindowProcW (hwnd, msg, wParam, lParam);
1384 case WM_THEMECHANGED:
1385 return theme_changed (infoPtr);
1388 if ((msg >= WM_USER) && (msg < WM_APP))
1389 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1390 msg, wParam, lParam);
1391 return DefWindowProcW (hwnd, msg, wParam, lParam);
1396 /***********************************************************************
1397 * STATUS_Register [Internal]
1399 * Registers the status window class.
1403 STATUS_Register (void)
1407 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1408 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1409 wndClass.lpfnWndProc = StatusWindowProc;
1410 wndClass.cbClsExtra = 0;
1411 wndClass.cbWndExtra = sizeof(STATUS_INFO *);
1412 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1413 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1414 wndClass.lpszClassName = STATUSCLASSNAMEW;
1416 RegisterClassW (&wndClass);
1420 /***********************************************************************
1421 * STATUS_Unregister [Internal]
1423 * Unregisters the status window class.
1427 STATUS_Unregister (void)
1429 UnregisterClassW (STATUSCLASSNAMEW, NULL);