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"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
77 COLORREF clrBk; /* background color */
78 BOOL bUnicode; /* unicode flag */
79 BOOL NtfUnicode; /* notify format */
80 STATUSWINDOWPART part0; /* simple window */
81 STATUSWINDOWPART* parts;
88 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
89 * The second cdrom contains executables drawstat.exe, gettext.exe,
90 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
99 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
101 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
103 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
107 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
109 HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
113 TRACE("draw size grip %ld,%ld - %ld,%ld\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
115 pt.x = lpRect->right - 1;
116 pt.y = lpRect->bottom - 1;
118 hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
119 hOldPen = SelectObject( hdc, hPenFace );
120 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
121 LineTo (hdc, pt.x, pt.y);
122 LineTo (hdc, pt.x, pt.y - 13);
127 hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
128 SelectObject( hdc, hPenShadow );
129 for (i = 1; i < 11; i += 4) {
130 MoveToEx (hdc, pt.x - i, pt.y, NULL);
131 LineTo (hdc, pt.x + 1, pt.y - i - 1);
133 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
134 LineTo (hdc, pt.x + 1, pt.y - i - 2);
137 hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
138 SelectObject( hdc, hPenHighlight );
139 for (i = 3; i < 13; i += 4) {
140 MoveToEx (hdc, pt.x - i, pt.y, NULL);
141 LineTo (hdc, pt.x + 1, pt.y - i - 1);
144 SelectObject (hdc, hOldPen);
145 DeleteObject( hPenFace );
146 DeleteObject( hPenShadow );
147 DeleteObject( hPenHighlight );
152 STATUSBAR_DrawPart (STATUS_INFO *infoPtr, HDC hdc, STATUSWINDOWPART *part, int itemID)
154 RECT r = part->bound;
155 UINT border = BDR_SUNKENOUTER;
157 TRACE("part bound %ld,%ld - %ld,%ld\n", r.left, r.top, r.right, r.bottom);
158 if (part->style & SBT_POPOUT)
159 border = BDR_RAISEDOUTER;
160 else if (part->style & SBT_NOBORDERS)
163 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
165 if (part->style & SBT_OWNERDRAW) {
168 dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
170 dis.hwndItem = infoPtr->Self;
173 dis.itemData = (INT)part->text;
174 SendMessageW (infoPtr->Notify, WM_DRAWITEM, (WPARAM)dis.CtlID, (LPARAM)&dis);
177 INT cy = r.bottom - r.top;
180 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
183 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
189 STATUSBAR_RefreshPart (STATUS_INFO *infoPtr, HDC hdc, STATUSWINDOWPART *part, int itemID)
194 TRACE("item %d\n", itemID);
195 if (!IsWindowVisible (infoPtr->Self))
198 if (part->bound.right < part->bound.left) return;
200 if (infoPtr->clrBk != CLR_DEFAULT)
201 hbrBk = CreateSolidBrush (infoPtr->clrBk);
203 hbrBk = GetSysColorBrush (COLOR_3DFACE);
204 FillRect(hdc, &part->bound, hbrBk);
206 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
208 STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
210 SelectObject (hdc, hOldFont);
212 if (infoPtr->clrBk != CLR_DEFAULT)
213 DeleteObject (hbrBk);
215 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
218 GetClientRect (infoPtr->Self, &rect);
219 STATUSBAR_DrawSizeGrip (hdc, &rect);
225 STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
233 if (!IsWindowVisible(infoPtr->Self))
236 STATUSBAR_SetPartBounds(infoPtr);
238 GetClientRect (infoPtr->Self, &rect);
240 if (infoPtr->clrBk != CLR_DEFAULT)
241 hbrBk = CreateSolidBrush (infoPtr->clrBk);
243 hbrBk = GetSysColorBrush (COLOR_3DFACE);
244 FillRect(hdc, &rect, hbrBk);
246 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
248 if (infoPtr->simple) {
249 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
251 for (i = 0; i < infoPtr->numParts; i++) {
252 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
256 SelectObject (hdc, hOldFont);
258 if (infoPtr->clrBk != CLR_DEFAULT)
259 DeleteObject (hbrBk);
261 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
262 STATUSBAR_DrawSizeGrip (hdc, &rect);
269 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
271 STATUSWINDOWPART *part;
275 /* get our window size */
276 GetClientRect (infoPtr->Self, &rect);
277 TRACE("client wnd size is %ld,%ld - %ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom);
279 rect.left += infoPtr->horizontalBorder;
280 rect.top += infoPtr->verticalBorder;
282 /* set bounds for simple rectangle */
283 infoPtr->part0.bound = rect;
285 /* set bounds for non-simple rectangles */
286 for (i = 0; i < infoPtr->numParts; i++) {
287 part = &infoPtr->parts[i];
288 r = &infoPtr->parts[i].bound;
290 r->bottom = rect.bottom;
294 r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
296 r->right = rect.right;
300 if (infoPtr->hwndToolTip) {
303 ti.cbSize = sizeof(TTTOOLINFOW);
304 ti.hwnd = infoPtr->Self;
307 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
315 STATUSBAR_Relay2Tip (STATUS_INFO *infoPtr, UINT uMsg,
316 WPARAM wParam, LPARAM lParam)
320 msg.hwnd = infoPtr->Self;
324 msg.time = GetMessageTime ();
325 msg.pt.x = LOWORD(GetMessagePos ());
326 msg.pt.y = HIWORD(GetMessagePos ());
328 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
333 STATUSBAR_GetBorders (STATUS_INFO *infoPtr, INT out[])
336 out[0] = infoPtr->horizontalBorder;
337 out[1] = infoPtr->verticalBorder;
338 out[2] = infoPtr->horizontalGap;
345 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, INT in[])
348 infoPtr->horizontalBorder = in[0];
349 infoPtr->verticalBorder = in[1];
350 infoPtr->horizontalGap = in[2];
351 InvalidateRect(infoPtr->Self, NULL, FALSE);
358 STATUSBAR_GetIcon (STATUS_INFO *infoPtr, INT nPart)
360 TRACE("%d\n", nPart);
361 /* MSDN says: "simple parts are indexed with -1" */
362 if ((nPart < -1) || (nPart >= infoPtr->numParts))
366 return (infoPtr->part0.hIcon);
368 return (infoPtr->parts[nPart].hIcon);
373 STATUSBAR_GetParts (STATUS_INFO *infoPtr, INT num_parts, INT parts[])
377 TRACE("(%d)\n", num_parts);
379 for (i = 0; i < num_parts; i++) {
380 parts[i] = infoPtr->parts[i].x;
383 return infoPtr->numParts;
388 STATUSBAR_GetRect (STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
390 TRACE("part %d\n", nPart);
392 *rect = infoPtr->part0.bound;
394 *rect = infoPtr->parts[nPart].bound;
400 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
402 STATUSWINDOWPART *part;
405 TRACE("part %d\n", nPart);
407 /* MSDN says: "simple parts use index of 0", so this check is ok. */
408 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
411 part = &infoPtr->part0;
413 part = &infoPtr->parts[nPart];
415 if (part->style & SBT_OWNERDRAW)
416 result = (LRESULT)part->text;
418 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
419 NULL, 0, NULL, NULL ) - 1 : 0;
420 result = MAKELONG( len, part->style );
421 if (part->text && buf)
422 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
429 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
431 STATUSWINDOWPART *part;
434 TRACE("part %d\n", nPart);
435 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
438 part = &infoPtr->part0;
440 part = &infoPtr->parts[nPart];
442 if (part->style & SBT_OWNERDRAW)
443 result = (LRESULT)part->text;
445 result = part->text ? strlenW (part->text) : 0;
446 result |= (part->style << 16);
447 if (part->text && buf)
448 strcpyW (buf, part->text);
455 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
457 STATUSWINDOWPART *part;
460 TRACE("part %d\n", nPart);
462 /* MSDN says: "simple parts use index of 0", so this check is ok. */
463 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
466 part = &infoPtr->part0;
468 part = &infoPtr->parts[nPart];
470 if ((~part->style & SBT_OWNERDRAW) && part->text)
471 result = strlenW(part->text);
475 result |= (part->style << 16);
480 STATUSBAR_GetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
484 CHAR buf[INFOTIPSIZE];
487 if (infoPtr->hwndToolTip) {
489 ti.cbSize = sizeof(TTTOOLINFOA);
490 ti.hwnd = infoPtr->Self;
493 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
495 lstrcpynA (tip, buf, size);
502 STATUSBAR_GetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
506 WCHAR buf[INFOTIPSIZE];
509 if (infoPtr->hwndToolTip) {
511 ti.cbSize = sizeof(TTTOOLINFOW);
512 ti.hwnd = infoPtr->Self;
515 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
517 lstrcpynW(tip, buf, size);
525 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
529 oldBkColor = infoPtr->clrBk;
530 infoPtr->clrBk = color;
531 InvalidateRect(infoPtr->Self, NULL, FALSE);
533 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
539 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
541 if ((nPart < -1) || (nPart >= infoPtr->numParts))
544 TRACE("setting part %d\n", nPart);
546 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
548 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
550 infoPtr->part0.hIcon = hIcon;
552 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
554 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
557 infoPtr->parts[nPart].hIcon = hIcon;
558 if (!(infoPtr->simple))
559 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
566 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
569 TRACE("(height=%d)\n", height);
570 if (IsWindowVisible (infoPtr->Self)) {
574 GetClientRect (infoPtr->Notify, &parent_rect);
575 infoPtr->height = height + infoPtr->verticalBorder;
576 width = parent_rect.right - parent_rect.left;
577 x = parent_rect.left;
578 y = parent_rect.bottom - infoPtr->height;
579 MoveWindow (infoPtr->Self, parent_rect.left,
580 parent_rect.bottom - infoPtr->height,
581 width, infoPtr->height, TRUE);
582 STATUSBAR_SetPartBounds (infoPtr);
590 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
592 STATUSWINDOWPART *tmp;
595 TRACE("(%d,%p)\n", count, parts);
597 oldNumParts = infoPtr->numParts;
598 infoPtr->numParts = count;
599 if (oldNumParts > infoPtr->numParts) {
600 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
601 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
602 Free (infoPtr->parts[i].text);
604 } else if (oldNumParts < infoPtr->numParts) {
605 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
606 if (!tmp) return FALSE;
607 for (i = 0; i < oldNumParts; i++) {
608 tmp[i] = infoPtr->parts[i];
611 Free (infoPtr->parts);
612 infoPtr->parts = tmp;
614 if (oldNumParts == infoPtr->numParts) {
615 for (i=0; i < oldNumParts; i++)
616 if (infoPtr->parts[i].x != parts[i])
618 if (i==oldNumParts) /* Unchanged? no need to redraw! */
622 for (i = 0; i < infoPtr->numParts; i++)
623 infoPtr->parts[i].x = parts[i];
625 if (infoPtr->hwndToolTip) {
629 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
630 ti.cbSize = sizeof(TTTOOLINFOW);
631 ti.hwnd = infoPtr->Self;
633 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
634 if (nTipCount < infoPtr->numParts) {
636 for (i = nTipCount; i < infoPtr->numParts; i++) {
637 TRACE("add tool %d\n", i);
639 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
643 else if (nTipCount > infoPtr->numParts) {
645 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
646 TRACE("delete tool %d\n", i);
648 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
653 STATUSBAR_SetPartBounds (infoPtr);
654 InvalidateRect(infoPtr->Self, NULL, FALSE);
660 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
661 LPCWSTR text, BOOL isW)
663 STATUSWINDOWPART *part=NULL;
664 BOOL changed = FALSE;
667 if (style & SBT_OWNERDRAW) {
668 TRACE("part %d, text %p\n",nPart,text);
670 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
672 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
673 * window is assumed to be a simple window */
675 if (nPart == 0x00ff) {
676 part = &infoPtr->part0;
678 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
679 part = &infoPtr->parts[nPart];
682 if (!part) return FALSE;
684 if (part->style != style)
687 oldStyle = part->style;
689 if (style & SBT_OWNERDRAW) {
690 if (!(oldStyle & SBT_OWNERDRAW)) {
693 } else if (part->text == text)
695 part->text = (LPWSTR)text;
700 LPCSTR atxt = (LPCSTR)text;
701 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
702 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
703 if (!ntext) return FALSE;
704 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
706 ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
707 if (!ntext) return FALSE;
708 strcpyW (ntext, text);
711 /* check if text is unchanged -> no need to redraw */
713 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
718 if (!changed && !part->text)
722 if (part->text && !(oldStyle & SBT_OWNERDRAW))
726 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
733 STATUSBAR_SetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR text)
735 TRACE("part %d: \"%s\"\n", id, text);
736 if (infoPtr->hwndToolTip) {
738 ti.cbSize = sizeof(TTTOOLINFOA);
739 ti.hwnd = infoPtr->Self;
743 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
751 STATUSBAR_SetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR text)
753 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
754 if (infoPtr->hwndToolTip) {
756 ti.cbSize = sizeof(TTTOOLINFOW);
757 ti.hwnd = infoPtr->Self;
761 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
768 inline static LRESULT
769 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
771 BOOL bOld = infoPtr->bUnicode;
773 TRACE("(0x%x)\n", bUnicode);
774 infoPtr->bUnicode = bUnicode;
781 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
785 TRACE("(simple=%d)\n", simple);
786 if (infoPtr->simple == simple) /* no need to change */
789 infoPtr->simple = simple;
791 /* send notification */
792 nmhdr.hwndFrom = infoPtr->Self;
793 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
794 nmhdr.code = SBN_SIMPLEMODECHANGE;
795 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
796 InvalidateRect(infoPtr->Self, NULL, FALSE);
802 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
807 for (i = 0; i < infoPtr->numParts; i++) {
808 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
809 Free (infoPtr->parts[i].text);
811 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
812 Free (infoPtr->part0.text);
813 Free (infoPtr->parts);
815 /* delete default font */
816 if (infoPtr->hDefaultFont)
817 DeleteObject (infoPtr->hDefaultFont);
819 /* delete tool tip control */
820 if (infoPtr->hwndToolTip)
821 DestroyWindow (infoPtr->hwndToolTip);
823 SetWindowLongPtrW(infoPtr->Self, 0, 0);
830 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
832 STATUS_INFO *infoPtr;
833 NONCLIENTMETRICSW nclm;
836 int i, width, len, textHeight = 0;
840 infoPtr = (STATUS_INFO*)Alloc (sizeof(STATUS_INFO));
841 if (!infoPtr) goto create_fail;
842 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
844 infoPtr->Self = hwnd;
845 infoPtr->Notify = lpCreate->hwndParent;
846 infoPtr->numParts = 1;
848 infoPtr->simple = FALSE;
849 infoPtr->clrBk = CLR_DEFAULT;
851 infoPtr->horizontalBorder = HORZ_BORDER;
852 infoPtr->verticalBorder = VERT_BORDER;
853 infoPtr->horizontalGap = HORZ_GAP;
855 i = SendMessageW(infoPtr->Notify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
856 infoPtr->NtfUnicode = (i == NFR_UNICODE);
858 GetClientRect (hwnd, &rect);
859 InvalidateRect (hwnd, &rect, 0);
862 ZeroMemory (&nclm, sizeof(nclm));
863 nclm.cbSize = sizeof(nclm);
864 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
865 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
867 /* initialize simple case */
868 infoPtr->part0.bound = rect;
869 infoPtr->part0.text = 0;
870 infoPtr->part0.x = 0;
871 infoPtr->part0.style = 0;
872 infoPtr->part0.hIcon = 0;
874 /* initialize first part */
875 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
876 if (!infoPtr->parts) goto create_fail;
877 infoPtr->parts[0].bound = rect;
878 infoPtr->parts[0].text = 0;
879 infoPtr->parts[0].x = -1;
880 infoPtr->parts[0].style = 0;
881 infoPtr->parts[0].hIcon = 0;
883 if (IsWindowUnicode (hwnd)) {
884 infoPtr->bUnicode = TRUE;
885 if (lpCreate->lpszName &&
886 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
887 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
888 if (!infoPtr->parts[0].text) goto create_fail;
889 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
893 if (lpCreate->lpszName &&
894 (len = strlen((LPCSTR)lpCreate->lpszName))) {
895 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
896 infoPtr->parts[0].text = Alloc (lenW*sizeof(WCHAR));
897 if (!infoPtr->parts[0].text) goto create_fail;
898 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
899 infoPtr->parts[0].text, lenW );
903 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
905 /* statusbars on managed windows should not have SIZEGRIP style */
906 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent &&
907 GetPropA( lpCreate->hwndParent, "__wine_x11_managed" ))
908 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
910 if ((hdc = GetDC (hwnd))) {
914 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
915 GetTextMetricsW (hdc, &tm);
916 textHeight = tm.tmHeight;
917 SelectObject (hdc, hOldFont);
918 ReleaseDC (hwnd, hdc);
920 TRACE(" textHeight=%d\n", textHeight);
922 if (dwStyle & SBT_TOOLTIPS) {
923 infoPtr->hwndToolTip =
924 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
925 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
926 CW_USEDEFAULT, hwnd, 0,
927 (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
929 if (infoPtr->hwndToolTip) {
930 NMTOOLTIPSCREATED nmttc;
932 nmttc.hdr.hwndFrom = hwnd;
933 nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
934 nmttc.hdr.code = NM_TOOLTIPSCREATED;
935 nmttc.hwndToolTips = infoPtr->hwndToolTip;
937 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
938 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
942 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
943 GetClientRect (infoPtr->Notify, &rect);
944 width = rect.right - rect.left;
945 infoPtr->height = textHeight + 4 + infoPtr->verticalBorder;
946 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
947 width, infoPtr->height, SWP_NOZORDER);
948 STATUSBAR_SetPartBounds (infoPtr);
955 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
960 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
961 * of the first part only (usual behaviour) */
963 STATUSBAR_WMGetText (STATUS_INFO *infoPtr, INT size, LPWSTR buf)
968 if (!(infoPtr->parts[0].text))
970 if (infoPtr->bUnicode)
971 len = strlenW (infoPtr->parts[0].text);
973 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
976 if (infoPtr->bUnicode)
977 strcpyW (buf, infoPtr->parts[0].text);
979 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
980 (LPSTR)buf, len+1, NULL, NULL );
989 STATUSBAR_WMNCHitTest (STATUS_INFO *infoPtr, INT x, INT y)
991 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
995 GetClientRect (infoPtr->Self, &rect);
999 ScreenToClient (infoPtr->Self, &pt);
1001 rect.left = rect.right - 13;
1004 if (PtInRect (&rect, pt))
1005 return HTBOTTOMRIGHT;
1013 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1018 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1019 hdc = BeginPaint (infoPtr->Self, &ps);
1020 STATUSBAR_Refresh (infoPtr, hdc);
1021 EndPaint (infoPtr->Self, &ps);
1028 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1030 infoPtr->hFont = font;
1031 TRACE("%p\n", infoPtr->hFont);
1033 InvalidateRect(infoPtr->Self, NULL, FALSE);
1040 STATUSBAR_WMSetText (STATUS_INFO *infoPtr, LPCSTR text)
1042 STATUSWINDOWPART *part;
1046 if (infoPtr->numParts == 0)
1049 part = &infoPtr->parts[0];
1050 /* duplicate string */
1054 if (infoPtr->bUnicode) {
1055 if (text && (len = strlenW((LPCWSTR)text))) {
1056 part->text = Alloc ((len+1)*sizeof(WCHAR));
1057 if (!part->text) return FALSE;
1058 strcpyW (part->text, (LPCWSTR)text);
1062 if (text && (len = lstrlenA(text))) {
1063 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1064 part->text = Alloc (lenW*sizeof(WCHAR));
1065 if (!part->text) return FALSE;
1066 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1070 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1077 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1082 /* Need to resize width to match parent */
1083 TRACE("flags %04x\n", flags);
1085 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1086 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1090 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1092 /* width and height don't apply */
1093 GetClientRect (infoPtr->Notify, &parent_rect);
1094 width = parent_rect.right - parent_rect.left;
1095 x = parent_rect.left;
1096 y = parent_rect.bottom - infoPtr->height;
1097 MoveWindow (infoPtr->Self, parent_rect.left,
1098 parent_rect.bottom - infoPtr->height,
1099 width, infoPtr->height, TRUE);
1100 STATUSBAR_SetPartBounds (infoPtr);
1106 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1108 if (cmd == NF_REQUERY) {
1109 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1110 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1112 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1117 STATUSBAR_SendNotify (STATUS_INFO *infoPtr, UINT code)
1121 TRACE("code %04x\n", code);
1122 nmhdr.hwndFrom = infoPtr->Self;
1123 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
1125 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
1131 static LRESULT WINAPI
1132 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1134 STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1135 INT nPart = ((INT) wParam) & 0x00ff;
1138 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1139 if (!infoPtr && msg != WM_CREATE)
1140 return DefWindowProcW (hwnd, msg, wParam, lParam);
1144 return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1147 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1150 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1153 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1156 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1159 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1161 case SB_GETTEXTLENGTHA:
1162 case SB_GETTEXTLENGTHW:
1163 return STATUSBAR_GetTextLength (infoPtr, nPart);
1165 case SB_GETTIPTEXTA:
1166 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1168 case SB_GETTIPTEXTW:
1169 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1171 case SB_GETUNICODEFORMAT:
1172 return infoPtr->bUnicode;
1175 return infoPtr->simple;
1178 return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1181 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1184 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1186 case SB_SETMINHEIGHT:
1187 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1190 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1193 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1196 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1198 case SB_SETTIPTEXTA:
1199 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1201 case SB_SETTIPTEXTW:
1202 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1204 case SB_SETUNICODEFORMAT:
1205 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1208 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1211 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1214 return STATUSBAR_WMDestroy (infoPtr);
1217 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1220 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1222 case WM_GETTEXTLENGTH:
1223 return STATUSBAR_GetTextLength (infoPtr, 0);
1225 case WM_LBUTTONDBLCLK:
1226 return STATUSBAR_SendNotify (infoPtr, NM_DBLCLK);
1229 return STATUSBAR_SendNotify (infoPtr, NM_CLICK);
1232 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1235 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1236 (INT)HIWORD(lParam));
1237 if (res != HTERROR) return res;
1238 return DefWindowProcW (hwnd, msg, wParam, lParam);
1240 case WM_NCLBUTTONUP:
1241 case WM_NCLBUTTONDOWN:
1242 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1245 case WM_NOTIFYFORMAT:
1246 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1249 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1251 case WM_RBUTTONDBLCLK:
1252 return STATUSBAR_SendNotify (infoPtr, NM_RDBLCLK);
1255 return STATUSBAR_SendNotify (infoPtr, NM_RCLICK);
1258 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1261 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1264 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1265 return DefWindowProcW (hwnd, msg, wParam, lParam);
1268 if ((msg >= WM_USER) && (msg < WM_APP))
1269 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1270 msg, wParam, lParam);
1271 return DefWindowProcW (hwnd, msg, wParam, lParam);
1276 /***********************************************************************
1277 * STATUS_Register [Internal]
1279 * Registers the status window class.
1283 STATUS_Register (void)
1287 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1288 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1289 wndClass.lpfnWndProc = StatusWindowProc;
1290 wndClass.cbClsExtra = 0;
1291 wndClass.cbWndExtra = sizeof(STATUS_INFO *);
1292 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1293 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1294 wndClass.lpszClassName = STATUSCLASSNAMEW;
1296 RegisterClassW (&wndClass);
1300 /***********************************************************************
1301 * STATUS_Unregister [Internal]
1303 * Unregisters the status window class.
1307 STATUS_Unregister (void)
1309 UnregisterClassW (STATUSCLASSNAMEW, NULL);