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)
169 dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
171 dis.hwndItem = infoPtr->Self;
174 dis.itemData = (INT)part->text;
175 SendMessageW (infoPtr->Notify, WM_DRAWITEM, (WPARAM)dis.CtlID, (LPARAM)&dis);
181 INT cy = r.bottom - r.top;
184 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
187 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
193 STATUSBAR_RefreshPart (STATUS_INFO *infoPtr, HDC hdc, STATUSWINDOWPART *part, int itemID)
198 TRACE("item %d\n", itemID);
199 if (!IsWindowVisible (infoPtr->Self))
202 if (part->bound.right < part->bound.left) return;
204 if (infoPtr->clrBk != CLR_DEFAULT)
205 hbrBk = CreateSolidBrush (infoPtr->clrBk);
207 hbrBk = GetSysColorBrush (COLOR_3DFACE);
208 FillRect(hdc, &part->bound, hbrBk);
210 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
212 STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
214 SelectObject (hdc, hOldFont);
216 if (infoPtr->clrBk != CLR_DEFAULT)
217 DeleteObject (hbrBk);
219 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
223 GetClientRect (infoPtr->Self, &rect);
224 STATUSBAR_DrawSizeGrip (hdc, &rect);
230 STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
238 if (!IsWindowVisible(infoPtr->Self))
241 STATUSBAR_SetPartBounds(infoPtr);
243 GetClientRect (infoPtr->Self, &rect);
245 if (infoPtr->clrBk != CLR_DEFAULT)
246 hbrBk = CreateSolidBrush (infoPtr->clrBk);
248 hbrBk = GetSysColorBrush (COLOR_3DFACE);
249 FillRect(hdc, &rect, hbrBk);
251 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
253 if (infoPtr->simple) {
254 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
256 for (i = 0; i < infoPtr->numParts; i++) {
257 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
261 SelectObject (hdc, hOldFont);
263 if (infoPtr->clrBk != CLR_DEFAULT)
264 DeleteObject (hbrBk);
266 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
267 STATUSBAR_DrawSizeGrip (hdc, &rect);
274 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
276 STATUSWINDOWPART *part;
280 /* get our window size */
281 GetClientRect (infoPtr->Self, &rect);
282 TRACE("client wnd size is %ld,%ld - %ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom);
284 rect.left += infoPtr->horizontalBorder;
285 rect.top += infoPtr->verticalBorder;
287 /* set bounds for simple rectangle */
288 infoPtr->part0.bound = rect;
290 /* set bounds for non-simple rectangles */
291 for (i = 0; i < infoPtr->numParts; i++) {
292 part = &infoPtr->parts[i];
293 r = &infoPtr->parts[i].bound;
295 r->bottom = rect.bottom;
299 r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
301 r->right = rect.right;
305 if (infoPtr->hwndToolTip) {
308 ti.cbSize = sizeof(TTTOOLINFOW);
309 ti.hwnd = infoPtr->Self;
312 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
320 STATUSBAR_Relay2Tip (STATUS_INFO *infoPtr, UINT uMsg,
321 WPARAM wParam, LPARAM lParam)
325 msg.hwnd = infoPtr->Self;
329 msg.time = GetMessageTime ();
330 msg.pt.x = LOWORD(GetMessagePos ());
331 msg.pt.y = HIWORD(GetMessagePos ());
333 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
338 STATUSBAR_GetBorders (STATUS_INFO *infoPtr, INT out[])
341 out[0] = infoPtr->horizontalBorder;
342 out[1] = infoPtr->verticalBorder;
343 out[2] = infoPtr->horizontalGap;
350 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, INT in[])
353 infoPtr->horizontalBorder = in[0];
354 infoPtr->verticalBorder = in[1];
355 infoPtr->horizontalGap = in[2];
356 InvalidateRect(infoPtr->Self, NULL, FALSE);
363 STATUSBAR_GetIcon (STATUS_INFO *infoPtr, INT nPart)
365 TRACE("%d\n", nPart);
366 /* MSDN says: "simple parts are indexed with -1" */
367 if ((nPart < -1) || (nPart >= infoPtr->numParts))
371 return (infoPtr->part0.hIcon);
373 return (infoPtr->parts[nPart].hIcon);
378 STATUSBAR_GetParts (STATUS_INFO *infoPtr, INT num_parts, INT parts[])
382 TRACE("(%d)\n", num_parts);
384 for (i = 0; i < num_parts; i++) {
385 parts[i] = infoPtr->parts[i].x;
388 return infoPtr->numParts;
393 STATUSBAR_GetRect (STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
395 TRACE("part %d\n", nPart);
397 *rect = infoPtr->part0.bound;
399 *rect = infoPtr->parts[nPart].bound;
405 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
407 STATUSWINDOWPART *part;
410 TRACE("part %d\n", nPart);
412 /* MSDN says: "simple parts use index of 0", so this check is ok. */
413 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
416 part = &infoPtr->part0;
418 part = &infoPtr->parts[nPart];
420 if (part->style & SBT_OWNERDRAW)
421 result = (LRESULT)part->text;
423 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
424 NULL, 0, NULL, NULL ) - 1 : 0;
425 result = MAKELONG( len, part->style );
426 if (part->text && buf)
427 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
434 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
436 STATUSWINDOWPART *part;
439 TRACE("part %d\n", nPart);
440 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
443 part = &infoPtr->part0;
445 part = &infoPtr->parts[nPart];
447 if (part->style & SBT_OWNERDRAW)
448 result = (LRESULT)part->text;
450 result = part->text ? strlenW (part->text) : 0;
451 result |= (part->style << 16);
452 if (part->text && buf)
453 strcpyW (buf, part->text);
460 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
462 STATUSWINDOWPART *part;
465 TRACE("part %d\n", nPart);
467 /* MSDN says: "simple parts use index of 0", so this check is ok. */
468 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
471 part = &infoPtr->part0;
473 part = &infoPtr->parts[nPart];
475 if ((~part->style & SBT_OWNERDRAW) && part->text)
476 result = strlenW(part->text);
480 result |= (part->style << 16);
485 STATUSBAR_GetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
489 CHAR buf[INFOTIPSIZE];
492 if (infoPtr->hwndToolTip) {
494 ti.cbSize = sizeof(TTTOOLINFOA);
495 ti.hwnd = infoPtr->Self;
498 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
500 lstrcpynA (tip, buf, size);
507 STATUSBAR_GetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
511 WCHAR buf[INFOTIPSIZE];
514 if (infoPtr->hwndToolTip) {
516 ti.cbSize = sizeof(TTTOOLINFOW);
517 ti.hwnd = infoPtr->Self;
520 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
522 lstrcpynW(tip, buf, size);
530 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
534 oldBkColor = infoPtr->clrBk;
535 infoPtr->clrBk = color;
536 InvalidateRect(infoPtr->Self, NULL, FALSE);
538 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
544 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
546 if ((nPart < -1) || (nPart >= infoPtr->numParts))
549 TRACE("setting part %d\n", nPart);
551 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
553 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
555 infoPtr->part0.hIcon = hIcon;
557 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
559 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
562 infoPtr->parts[nPart].hIcon = hIcon;
563 if (!(infoPtr->simple))
564 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
571 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
574 TRACE("(height=%d)\n", height);
575 if (IsWindowVisible (infoPtr->Self)) {
579 GetClientRect (infoPtr->Notify, &parent_rect);
580 infoPtr->height = height + infoPtr->verticalBorder;
581 width = parent_rect.right - parent_rect.left;
582 x = parent_rect.left;
583 y = parent_rect.bottom - infoPtr->height;
584 MoveWindow (infoPtr->Self, parent_rect.left,
585 parent_rect.bottom - infoPtr->height,
586 width, infoPtr->height, TRUE);
587 STATUSBAR_SetPartBounds (infoPtr);
595 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
597 STATUSWINDOWPART *tmp;
600 TRACE("(%d,%p)\n", count, parts);
602 oldNumParts = infoPtr->numParts;
603 infoPtr->numParts = count;
604 if (oldNumParts > infoPtr->numParts) {
605 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
606 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
607 Free (infoPtr->parts[i].text);
609 } else if (oldNumParts < infoPtr->numParts) {
610 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
611 if (!tmp) return FALSE;
612 for (i = 0; i < oldNumParts; i++) {
613 tmp[i] = infoPtr->parts[i];
616 Free (infoPtr->parts);
617 infoPtr->parts = tmp;
619 if (oldNumParts == infoPtr->numParts) {
620 for (i=0; i < oldNumParts; i++)
621 if (infoPtr->parts[i].x != parts[i])
623 if (i==oldNumParts) /* Unchanged? no need to redraw! */
627 for (i = 0; i < infoPtr->numParts; i++)
628 infoPtr->parts[i].x = parts[i];
630 if (infoPtr->hwndToolTip) {
634 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
635 ti.cbSize = sizeof(TTTOOLINFOW);
636 ti.hwnd = infoPtr->Self;
638 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
639 if (nTipCount < infoPtr->numParts) {
641 for (i = nTipCount; i < infoPtr->numParts; i++) {
642 TRACE("add tool %d\n", i);
644 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
648 else if (nTipCount > infoPtr->numParts) {
650 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
651 TRACE("delete tool %d\n", i);
653 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
658 STATUSBAR_SetPartBounds (infoPtr);
659 InvalidateRect(infoPtr->Self, NULL, FALSE);
665 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
666 LPCWSTR text, BOOL isW)
668 STATUSWINDOWPART *part=NULL;
669 BOOL changed = FALSE;
672 if (style & SBT_OWNERDRAW) {
673 TRACE("part %d, text %p\n",nPart,text);
675 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
677 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
678 * window is assumed to be a simple window */
680 if (nPart == 0x00ff) {
681 part = &infoPtr->part0;
683 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
684 part = &infoPtr->parts[nPart];
687 if (!part) return FALSE;
689 if (part->style != style)
692 oldStyle = part->style;
694 if (style & SBT_OWNERDRAW) {
695 if (!(oldStyle & SBT_OWNERDRAW)) {
698 } else if (part->text == text)
700 part->text = (LPWSTR)text;
705 LPCSTR atxt = (LPCSTR)text;
706 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
707 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
708 if (!ntext) return FALSE;
709 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
711 ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
712 if (!ntext) return FALSE;
713 strcpyW (ntext, text);
716 /* check if text is unchanged -> no need to redraw */
718 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
723 if (!changed && !part->text)
727 if (part->text && !(oldStyle & SBT_OWNERDRAW))
731 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
738 STATUSBAR_SetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR text)
740 TRACE("part %d: \"%s\"\n", id, text);
741 if (infoPtr->hwndToolTip) {
743 ti.cbSize = sizeof(TTTOOLINFOA);
744 ti.hwnd = infoPtr->Self;
748 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
757 STATUSBAR_SetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR text)
759 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
760 if (infoPtr->hwndToolTip) {
762 ti.cbSize = sizeof(TTTOOLINFOW);
763 ti.hwnd = infoPtr->Self;
767 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
775 inline static LRESULT
776 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
778 BOOL bOld = infoPtr->bUnicode;
780 TRACE("(0x%x)\n", bUnicode);
781 infoPtr->bUnicode = bUnicode;
788 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
792 TRACE("(simple=%d)\n", simple);
793 if (infoPtr->simple == simple) /* no need to change */
796 infoPtr->simple = simple;
798 /* send notification */
799 nmhdr.hwndFrom = infoPtr->Self;
800 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
801 nmhdr.code = SBN_SIMPLEMODECHANGE;
802 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
803 InvalidateRect(infoPtr->Self, NULL, FALSE);
809 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
814 for (i = 0; i < infoPtr->numParts; i++) {
815 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
816 Free (infoPtr->parts[i].text);
818 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
819 Free (infoPtr->part0.text);
820 Free (infoPtr->parts);
822 /* delete default font */
823 if (infoPtr->hDefaultFont)
824 DeleteObject (infoPtr->hDefaultFont);
826 /* delete tool tip control */
827 if (infoPtr->hwndToolTip)
828 DestroyWindow (infoPtr->hwndToolTip);
830 SetWindowLongPtrW(infoPtr->Self, 0, 0);
837 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
839 STATUS_INFO *infoPtr;
840 NONCLIENTMETRICSW nclm;
843 int i, width, len, textHeight = 0;
847 infoPtr = (STATUS_INFO*)Alloc (sizeof(STATUS_INFO));
848 if (!infoPtr) goto create_fail;
849 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
851 infoPtr->Self = hwnd;
852 infoPtr->Notify = lpCreate->hwndParent;
853 infoPtr->numParts = 1;
855 infoPtr->simple = FALSE;
856 infoPtr->clrBk = CLR_DEFAULT;
858 infoPtr->horizontalBorder = HORZ_BORDER;
859 infoPtr->verticalBorder = VERT_BORDER;
860 infoPtr->horizontalGap = HORZ_GAP;
862 i = SendMessageW(infoPtr->Notify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
863 infoPtr->NtfUnicode = (i == NFR_UNICODE);
865 GetClientRect (hwnd, &rect);
866 InvalidateRect (hwnd, &rect, 0);
869 ZeroMemory (&nclm, sizeof(nclm));
870 nclm.cbSize = sizeof(nclm);
871 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
872 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
874 /* initialize simple case */
875 infoPtr->part0.bound = rect;
876 infoPtr->part0.text = 0;
877 infoPtr->part0.x = 0;
878 infoPtr->part0.style = 0;
879 infoPtr->part0.hIcon = 0;
881 /* initialize first part */
882 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
883 if (!infoPtr->parts) goto create_fail;
884 infoPtr->parts[0].bound = rect;
885 infoPtr->parts[0].text = 0;
886 infoPtr->parts[0].x = -1;
887 infoPtr->parts[0].style = 0;
888 infoPtr->parts[0].hIcon = 0;
890 if (IsWindowUnicode (hwnd)) {
891 infoPtr->bUnicode = TRUE;
892 if (lpCreate->lpszName &&
893 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
894 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
895 if (!infoPtr->parts[0].text) goto create_fail;
896 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
900 if (lpCreate->lpszName &&
901 (len = strlen((LPCSTR)lpCreate->lpszName))) {
902 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
903 infoPtr->parts[0].text = Alloc (lenW*sizeof(WCHAR));
904 if (!infoPtr->parts[0].text) goto create_fail;
905 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
906 infoPtr->parts[0].text, lenW );
910 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
912 /* statusbars on managed windows should not have SIZEGRIP style */
913 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent &&
914 GetPropA( lpCreate->hwndParent, "__wine_x11_managed" ))
915 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
917 if ((hdc = GetDC (hwnd))) {
921 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
922 GetTextMetricsW (hdc, &tm);
923 textHeight = tm.tmHeight;
924 SelectObject (hdc, hOldFont);
925 ReleaseDC (hwnd, hdc);
927 TRACE(" textHeight=%d\n", textHeight);
929 if (dwStyle & SBT_TOOLTIPS) {
930 infoPtr->hwndToolTip =
931 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
932 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
933 CW_USEDEFAULT, hwnd, 0,
934 (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
936 if (infoPtr->hwndToolTip) {
937 NMTOOLTIPSCREATED nmttc;
939 nmttc.hdr.hwndFrom = hwnd;
940 nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
941 nmttc.hdr.code = NM_TOOLTIPSCREATED;
942 nmttc.hwndToolTips = infoPtr->hwndToolTip;
944 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
945 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
949 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
950 GetClientRect (infoPtr->Notify, &rect);
951 width = rect.right - rect.left;
952 infoPtr->height = textHeight + 4 + infoPtr->verticalBorder;
953 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
954 width, infoPtr->height, SWP_NOZORDER);
955 STATUSBAR_SetPartBounds (infoPtr);
962 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
967 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
968 * of the first part only (usual behaviour) */
970 STATUSBAR_WMGetText (STATUS_INFO *infoPtr, INT size, LPWSTR buf)
975 if (!(infoPtr->parts[0].text))
977 if (infoPtr->bUnicode)
978 len = strlenW (infoPtr->parts[0].text);
980 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
983 if (infoPtr->bUnicode)
984 strcpyW (buf, infoPtr->parts[0].text);
986 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
987 (LPSTR)buf, len+1, NULL, NULL );
996 STATUSBAR_WMNCHitTest (STATUS_INFO *infoPtr, INT x, INT y)
998 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1002 GetClientRect (infoPtr->Self, &rect);
1006 ScreenToClient (infoPtr->Self, &pt);
1008 rect.left = rect.right - 13;
1011 if (PtInRect (&rect, pt))
1012 return HTBOTTOMRIGHT;
1020 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1025 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1026 hdc = BeginPaint (infoPtr->Self, &ps);
1027 STATUSBAR_Refresh (infoPtr, hdc);
1028 EndPaint (infoPtr->Self, &ps);
1035 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1037 infoPtr->hFont = font;
1038 TRACE("%p\n", infoPtr->hFont);
1040 InvalidateRect(infoPtr->Self, NULL, FALSE);
1047 STATUSBAR_WMSetText (STATUS_INFO *infoPtr, LPCSTR text)
1049 STATUSWINDOWPART *part;
1053 if (infoPtr->numParts == 0)
1056 part = &infoPtr->parts[0];
1057 /* duplicate string */
1061 if (infoPtr->bUnicode) {
1062 if (text && (len = strlenW((LPCWSTR)text))) {
1063 part->text = Alloc ((len+1)*sizeof(WCHAR));
1064 if (!part->text) return FALSE;
1065 strcpyW (part->text, (LPCWSTR)text);
1069 if (text && (len = lstrlenA(text))) {
1070 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1071 part->text = Alloc (lenW*sizeof(WCHAR));
1072 if (!part->text) return FALSE;
1073 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1077 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1084 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1089 /* Need to resize width to match parent */
1090 TRACE("flags %04x\n", flags);
1092 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED)
1094 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1098 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1100 /* width and height don't apply */
1101 GetClientRect (infoPtr->Notify, &parent_rect);
1102 width = parent_rect.right - parent_rect.left;
1103 x = parent_rect.left;
1104 y = parent_rect.bottom - infoPtr->height;
1105 MoveWindow (infoPtr->Self, parent_rect.left,
1106 parent_rect.bottom - infoPtr->height,
1107 width, infoPtr->height, TRUE);
1108 STATUSBAR_SetPartBounds (infoPtr);
1114 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1116 if (cmd == NF_REQUERY) {
1117 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1118 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1120 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1125 STATUSBAR_SendNotify (STATUS_INFO *infoPtr, UINT code)
1129 TRACE("code %04x\n", code);
1130 nmhdr.hwndFrom = infoPtr->Self;
1131 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
1133 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
1139 static LRESULT WINAPI
1140 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1142 STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1143 INT nPart = ((INT) wParam) & 0x00ff;
1146 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1147 if (!infoPtr && msg != WM_CREATE)
1148 return DefWindowProcW (hwnd, msg, wParam, lParam);
1152 return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1155 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1158 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1161 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1164 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1167 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1169 case SB_GETTEXTLENGTHA:
1170 case SB_GETTEXTLENGTHW:
1171 return STATUSBAR_GetTextLength (infoPtr, nPart);
1173 case SB_GETTIPTEXTA:
1174 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1176 case SB_GETTIPTEXTW:
1177 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1179 case SB_GETUNICODEFORMAT:
1180 return infoPtr->bUnicode;
1183 return infoPtr->simple;
1186 return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1189 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1192 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1194 case SB_SETMINHEIGHT:
1195 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1198 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1201 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1204 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1206 case SB_SETTIPTEXTA:
1207 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1209 case SB_SETTIPTEXTW:
1210 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1212 case SB_SETUNICODEFORMAT:
1213 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1216 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1219 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1222 return STATUSBAR_WMDestroy (infoPtr);
1225 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1228 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1230 case WM_GETTEXTLENGTH:
1231 return STATUSBAR_GetTextLength (infoPtr, 0);
1233 case WM_LBUTTONDBLCLK:
1234 return STATUSBAR_SendNotify (infoPtr, NM_DBLCLK);
1237 return STATUSBAR_SendNotify (infoPtr, NM_CLICK);
1240 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1243 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1244 (INT)HIWORD(lParam));
1245 if (res != HTERROR) return res;
1246 return DefWindowProcW (hwnd, msg, wParam, lParam);
1248 case WM_NCLBUTTONUP:
1249 case WM_NCLBUTTONDOWN:
1250 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1253 case WM_NOTIFYFORMAT:
1254 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1257 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1259 case WM_RBUTTONDBLCLK:
1260 return STATUSBAR_SendNotify (infoPtr, NM_RDBLCLK);
1263 return STATUSBAR_SendNotify (infoPtr, NM_RCLICK);
1266 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1269 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1272 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1273 return DefWindowProcW (hwnd, msg, wParam, lParam);
1276 if ((msg >= WM_USER) && (msg < WM_APP))
1277 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1278 msg, wParam, lParam);
1279 return DefWindowProcW (hwnd, msg, wParam, lParam);
1284 /***********************************************************************
1285 * STATUS_Register [Internal]
1287 * Registers the status window class.
1291 STATUS_Register (void)
1295 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1296 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1297 wndClass.lpfnWndProc = StatusWindowProc;
1298 wndClass.cbClsExtra = 0;
1299 wndClass.cbWndExtra = sizeof(STATUS_INFO *);
1300 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1301 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1302 wndClass.lpszClassName = STATUSCLASSNAMEW;
1304 RegisterClassW (&wndClass);
1308 /***********************************************************************
1309 * STATUS_Unregister [Internal]
1311 * Unregisters the status window class.
1315 STATUS_Unregister (void)
1317 UnregisterClassW (STATUSCLASSNAMEW, NULL);