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)
46 #include "wine/unicode.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
70 COLORREF clrBk; /* background color */
71 BOOL bUnicode; /* unicode flag */
72 BOOL NtfUnicode; /* notify format */
73 STATUSWINDOWPART part0; /* simple window */
74 STATUSWINDOWPART* parts;
78 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
79 * The second cdrom contains executables drawstat.exe, gettext.exe,
80 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
87 #define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongW (hwnd, 0))
91 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr);
93 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
95 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
99 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
101 HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
105 TRACE("draw size grip %ld,%ld - %ld,%ld\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
107 pt.x = lpRect->right - 1;
108 pt.y = lpRect->bottom - 1;
110 hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
111 hOldPen = SelectObject( hdc, hPenFace );
112 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
113 LineTo (hdc, pt.x, pt.y);
114 LineTo (hdc, pt.x, pt.y - 13);
119 hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
120 SelectObject( hdc, hPenShadow );
121 for (i = 1; i < 11; i += 4) {
122 MoveToEx (hdc, pt.x - i, pt.y, NULL);
123 LineTo (hdc, pt.x + 1, pt.y - i - 1);
125 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
126 LineTo (hdc, pt.x + 1, pt.y - i - 2);
129 hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
130 SelectObject( hdc, hPenHighlight );
131 for (i = 3; i < 13; i += 4) {
132 MoveToEx (hdc, pt.x - i, pt.y, NULL);
133 LineTo (hdc, pt.x + 1, pt.y - i - 1);
136 SelectObject (hdc, hOldPen);
137 DeleteObject( hPenFace );
138 DeleteObject( hPenShadow );
139 DeleteObject( hPenHighlight );
144 STATUSBAR_DrawPart (HDC hdc, const STATUSWINDOWPART *part, const STATUSWINDOWINFO *infoPtr, int itemID)
146 RECT r = part->bound;
147 UINT border = BDR_SUNKENOUTER;
149 TRACE("part bound %ld,%ld - %ld,%ld\n", r.left, r.top, r.right, r.bottom);
150 if (part->style & SBT_POPOUT)
151 border = BDR_RAISEDOUTER;
152 else if (part->style & SBT_NOBORDERS)
155 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
157 if (part->style & SBT_OWNERDRAW)
161 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
163 dis.hwndItem = infoPtr->Self;
166 dis.itemData = (INT)part->text;
167 SendMessageW (GetParent (infoPtr->Self), WM_DRAWITEM,
168 (WPARAM)dis.CtlID, (LPARAM)&dis);
174 INT cy = r.bottom - r.top;
177 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
180 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
186 STATUSBAR_RefreshPart (const STATUSWINDOWINFO *infoPtr, const STATUSWINDOWPART *part, HDC hdc, int itemID)
191 TRACE("item %d\n", itemID);
192 if (!IsWindowVisible (infoPtr->Self))
195 if (part->bound.right < part->bound.left) return;
197 if (infoPtr->clrBk != CLR_DEFAULT)
198 hbrBk = CreateSolidBrush (infoPtr->clrBk);
200 hbrBk = GetSysColorBrush (COLOR_3DFACE);
201 FillRect(hdc, &part->bound, hbrBk);
203 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
205 STATUSBAR_DrawPart (hdc, part, infoPtr, itemID);
207 SelectObject (hdc, hOldFont);
209 if (infoPtr->clrBk != CLR_DEFAULT)
210 DeleteObject (hbrBk);
212 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
216 GetClientRect (infoPtr->Self, &rect);
217 STATUSBAR_DrawSizeGrip (hdc, &rect);
223 STATUSBAR_Refresh (STATUSWINDOWINFO *infoPtr, HDC hdc)
231 if (!IsWindowVisible(infoPtr->Self))
234 STATUSBAR_SetPartBounds(infoPtr);
236 GetClientRect (infoPtr->Self, &rect);
238 if (infoPtr->clrBk != CLR_DEFAULT)
239 hbrBk = CreateSolidBrush (infoPtr->clrBk);
241 hbrBk = GetSysColorBrush (COLOR_3DFACE);
242 FillRect(hdc, &rect, hbrBk);
244 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
246 if (infoPtr->simple) {
247 STATUSBAR_RefreshPart (infoPtr, &infoPtr->part0, hdc, 0);
249 for (i = 0; i < infoPtr->numParts; i++) {
250 STATUSBAR_RefreshPart (infoPtr, &infoPtr->parts[i], hdc, i);
254 SelectObject (hdc, hOldFont);
256 if (infoPtr->clrBk != CLR_DEFAULT)
257 DeleteObject (hbrBk);
259 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
260 STATUSBAR_DrawSizeGrip (hdc, &rect);
267 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr)
269 STATUSWINDOWPART *part;
273 /* get our window size */
274 GetClientRect (infoPtr->Self, &rect);
275 TRACE("client wnd size is %ld,%ld - %ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom);
277 rect.top += VERT_BORDER;
279 /* set bounds for simple rectangle */
280 infoPtr->part0.bound = rect;
282 /* set bounds for non-simple rectangles */
283 for (i = 0; i < infoPtr->numParts; i++) {
284 part = &infoPtr->parts[i];
285 r = &infoPtr->parts[i].bound;
287 r->bottom = rect.bottom;
291 r->left = infoPtr->parts[i-1].bound.right + HORZ_GAP;
293 r->right = rect.right;
297 if (infoPtr->hwndToolTip) {
300 ti.cbSize = sizeof(TTTOOLINFOW);
301 ti.hwnd = infoPtr->Self;
304 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
312 STATUSBAR_Relay2Tip (STATUSWINDOWINFO *infoPtr, UINT uMsg,
313 WPARAM wParam, LPARAM lParam)
317 msg.hwnd = infoPtr->Self;
321 msg.time = GetMessageTime ();
322 msg.pt.x = LOWORD(GetMessagePos ());
323 msg.pt.y = HIWORD(GetMessagePos ());
325 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
330 STATUSBAR_GetBorders (INT out[])
333 out[0] = HORZ_BORDER; /* horizontal border width */
334 out[1] = VERT_BORDER; /* vertical border width */
335 out[2] = HORZ_GAP; /* width of border between rectangles */
342 STATUSBAR_GetIcon (STATUSWINDOWINFO *infoPtr, INT nPart)
344 TRACE("%d\n", nPart);
345 /* MSDN says: "simple parts are indexed with -1" */
346 if ((nPart < -1) || (nPart >= infoPtr->numParts))
350 return (infoPtr->part0.hIcon);
352 return (infoPtr->parts[nPart].hIcon);
357 STATUSBAR_GetParts (STATUSWINDOWINFO *infoPtr, INT num_parts, INT parts[])
361 TRACE("(%d)\n", num_parts);
363 for (i = 0; i < num_parts; i++) {
364 parts[i] = infoPtr->parts[i].x;
367 return infoPtr->numParts;
372 STATUSBAR_GetRect (STATUSWINDOWINFO *infoPtr, INT nPart, LPRECT rect)
374 TRACE("part %d\n", nPart);
376 *rect = infoPtr->part0.bound;
378 *rect = infoPtr->parts[nPart].bound;
384 STATUSBAR_GetTextA (STATUSWINDOWINFO *infoPtr, INT nPart, LPSTR buf)
386 STATUSWINDOWPART *part;
389 TRACE("part %d\n", nPart);
391 /* MSDN says: "simple parts use index of 0", so this check is ok. */
392 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
395 part = &infoPtr->part0;
397 part = &infoPtr->parts[nPart];
399 if (part->style & SBT_OWNERDRAW)
400 result = (LRESULT)part->text;
402 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
403 NULL, 0, NULL, NULL ) - 1 : 0;
404 result = MAKELONG( len, part->style );
405 if (part->text && buf)
406 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
413 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, INT nPart, LPWSTR buf)
415 STATUSWINDOWPART *part;
418 TRACE("part %d\n", nPart);
419 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
422 part = &infoPtr->part0;
424 part = &infoPtr->parts[nPart];
426 if (part->style & SBT_OWNERDRAW)
427 result = (LRESULT)part->text;
429 result = part->text ? strlenW (part->text) : 0;
430 result |= (part->style << 16);
431 if (part->text && buf)
432 strcpyW (buf, part->text);
439 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, INT nPart)
441 STATUSWINDOWPART *part;
444 TRACE("part %d\n", nPart);
446 /* MSDN says: "simple parts use index of 0", so this check is ok. */
447 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
450 part = &infoPtr->part0;
452 part = &infoPtr->parts[nPart];
455 result = strlenW(part->text);
459 result |= (part->style << 16);
464 STATUSBAR_GetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR tip, INT size)
468 CHAR buf[INFOTIPSIZE];
471 if (infoPtr->hwndToolTip) {
473 ti.cbSize = sizeof(TTTOOLINFOA);
474 ti.hwnd = infoPtr->Self;
477 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
479 lstrcpynA (tip, buf, size);
486 STATUSBAR_GetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR tip, INT size)
490 WCHAR buf[INFOTIPSIZE];
493 if (infoPtr->hwndToolTip) {
495 ti.cbSize = sizeof(TTTOOLINFOW);
496 ti.hwnd = infoPtr->Self;
499 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
501 lstrcpynW(tip, buf, size);
509 STATUSBAR_SetBkColor (STATUSWINDOWINFO *infoPtr, COLORREF color)
513 oldBkColor = infoPtr->clrBk;
514 infoPtr->clrBk = color;
515 InvalidateRect(infoPtr->Self, NULL, FALSE);
517 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
523 STATUSBAR_SetIcon (STATUSWINDOWINFO *infoPtr, INT nPart, HICON hIcon)
525 if ((nPart < -1) || (nPart >= infoPtr->numParts))
528 TRACE("setting part %d\n", nPart);
530 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
532 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
534 infoPtr->part0.hIcon = hIcon;
536 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
538 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
541 infoPtr->parts[nPart].hIcon = hIcon;
542 if (!(infoPtr->simple))
543 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
550 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, INT height)
553 TRACE("(height=%d)\n", height);
554 if (IsWindowVisible (infoPtr->Self)) {
558 GetClientRect (GetParent (infoPtr->Self), &parent_rect);
559 infoPtr->height = height + VERT_BORDER;
560 width = parent_rect.right - parent_rect.left;
561 x = parent_rect.left;
562 y = parent_rect.bottom - infoPtr->height;
563 MoveWindow (infoPtr->Self, parent_rect.left,
564 parent_rect.bottom - infoPtr->height,
565 width, infoPtr->height, TRUE);
566 STATUSBAR_SetPartBounds (infoPtr);
574 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, INT count, LPINT parts)
576 STATUSWINDOWPART *tmp;
579 TRACE("(%d,%p)\n", count, parts);
581 oldNumParts = infoPtr->numParts;
582 infoPtr->numParts = count;
583 if (oldNumParts > infoPtr->numParts) {
584 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
585 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
586 COMCTL32_Free (infoPtr->parts[i].text);
588 } else if (oldNumParts < infoPtr->numParts) {
589 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
590 if (!tmp) return FALSE;
591 for (i = 0; i < oldNumParts; i++) {
592 tmp[i] = infoPtr->parts[i];
595 COMCTL32_Free (infoPtr->parts);
596 infoPtr->parts = tmp;
598 if (oldNumParts == infoPtr->numParts) {
599 for (i=0; i < oldNumParts; i++)
600 if (infoPtr->parts[i].x != parts[i])
602 if (i==oldNumParts) /* Unchanged? no need to redraw! */
606 for (i = 0; i < infoPtr->numParts; i++)
607 infoPtr->parts[i].x = parts[i];
609 if (infoPtr->hwndToolTip) {
613 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
614 ti.cbSize = sizeof(TTTOOLINFOW);
615 ti.hwnd = infoPtr->Self;
617 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
618 if (nTipCount < infoPtr->numParts) {
620 for (i = nTipCount; i < infoPtr->numParts; i++) {
621 TRACE("add tool %d\n", i);
623 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
627 else if (nTipCount > infoPtr->numParts) {
629 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
630 TRACE("delete tool %d\n", i);
632 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
637 STATUSBAR_SetPartBounds (infoPtr);
638 InvalidateRect(infoPtr->Self, NULL, FALSE);
644 STATUSBAR_SetTextT (STATUSWINDOWINFO *infoPtr, INT nPart, WORD style,
645 LPCWSTR text, BOOL isW)
647 STATUSWINDOWPART *part=NULL;
648 BOOL changed = FALSE;
650 if (style & SBT_OWNERDRAW) {
651 TRACE("part %d, text %p\n",nPart,text);
653 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
655 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
656 * window is assumed to be a simple window */
658 if (nPart == 0x00ff) {
659 part = &infoPtr->part0;
661 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
662 part = &infoPtr->parts[nPart];
665 if (!part) return FALSE;
667 if (part->style != style)
671 if (style & SBT_OWNERDRAW) {
672 if (part->text == text)
674 part->text = (LPWSTR)text;
679 LPCSTR atxt = (LPCSTR)text;
680 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
681 ntext = COMCTL32_Alloc( (len + 1)*sizeof(WCHAR) );
682 if (!ntext) return FALSE;
683 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
685 ntext = COMCTL32_Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
686 if (!ntext) return FALSE;
687 strcpyW (ntext, text);
690 /* check if text is unchanged -> no need to redraw */
692 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
693 if (!isW) COMCTL32_Free(ntext);
697 if (!changed && !part->text)
702 COMCTL32_Free (part->text);
705 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
712 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR text)
714 TRACE("part %d: \"%s\"\n", id, text);
715 if (infoPtr->hwndToolTip) {
717 ti.cbSize = sizeof(TTTOOLINFOA);
718 ti.hwnd = infoPtr->Self;
722 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
731 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR text)
733 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
734 if (infoPtr->hwndToolTip) {
736 ti.cbSize = sizeof(TTTOOLINFOW);
737 ti.hwnd = infoPtr->Self;
741 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
749 inline static LRESULT
750 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, BOOL bUnicode)
752 BOOL bOld = infoPtr->bUnicode;
754 TRACE("(0x%x)\n", bUnicode);
755 infoPtr->bUnicode = bUnicode;
762 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, BOOL simple)
766 TRACE("(simple=%d)\n", simple);
767 if (infoPtr->simple == simple) /* no need to change */
770 infoPtr->simple = simple;
772 /* send notification */
773 nmhdr.hwndFrom = infoPtr->Self;
774 nmhdr.idFrom = GetWindowLongW (infoPtr->Self, GWL_ID);
775 nmhdr.code = SBN_SIMPLEMODECHANGE;
776 SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY, 0, (LPARAM)&nmhdr);
777 InvalidateRect(infoPtr->Self, NULL, FALSE);
783 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr)
788 for (i = 0; i < infoPtr->numParts; i++) {
789 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
790 COMCTL32_Free (infoPtr->parts[i].text);
792 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
793 COMCTL32_Free (infoPtr->part0.text);
794 COMCTL32_Free (infoPtr->parts);
796 /* delete default font */
797 if (infoPtr->hDefaultFont)
798 DeleteObject (infoPtr->hDefaultFont);
800 /* delete tool tip control */
801 if (infoPtr->hwndToolTip)
802 DestroyWindow (infoPtr->hwndToolTip);
804 COMCTL32_Free (infoPtr);
805 SetWindowLongW(infoPtr->Self, 0, 0);
811 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
813 STATUSWINDOWINFO *infoPtr;
814 NONCLIENTMETRICSW nclm;
817 int i, width, len, textHeight = 0;
821 infoPtr = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
822 if (!infoPtr) goto create_fail;
823 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
825 infoPtr->Self = hwnd;
826 infoPtr->numParts = 1;
828 infoPtr->simple = FALSE;
829 infoPtr->clrBk = CLR_DEFAULT;
832 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
833 infoPtr->NtfUnicode = (i == NFR_UNICODE);
835 GetClientRect (hwnd, &rect);
836 InvalidateRect (hwnd, &rect, 0);
839 ZeroMemory (&nclm, sizeof(nclm));
840 nclm.cbSize = sizeof(nclm);
841 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
842 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
844 /* initialize simple case */
845 infoPtr->part0.bound = rect;
846 infoPtr->part0.text = 0;
847 infoPtr->part0.x = 0;
848 infoPtr->part0.style = 0;
849 infoPtr->part0.hIcon = 0;
851 /* initialize first part */
852 infoPtr->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
853 if (!infoPtr->parts) goto create_fail;
854 infoPtr->parts[0].bound = rect;
855 infoPtr->parts[0].text = 0;
856 infoPtr->parts[0].x = -1;
857 infoPtr->parts[0].style = 0;
858 infoPtr->parts[0].hIcon = 0;
860 if (IsWindowUnicode (hwnd)) {
861 infoPtr->bUnicode = TRUE;
862 if (lpCreate->lpszName &&
863 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
864 infoPtr->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
865 if (!infoPtr->parts[0].text) goto create_fail;
866 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
870 if (lpCreate->lpszName &&
871 (len = strlen((LPCSTR)lpCreate->lpszName))) {
872 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
873 infoPtr->parts[0].text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
874 if (!infoPtr->parts[0].text) goto create_fail;
875 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
876 infoPtr->parts[0].text, lenW );
880 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
882 /* statusbars on managed windows should not have SIZEGRIP style */
883 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
884 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
885 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
887 if ((hdc = GetDC (0))) {
891 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
892 GetTextMetricsW (hdc, &tm);
893 textHeight = tm.tmHeight;
894 SelectObject (hdc, hOldFont);
897 TRACE(" textHeight=%d\n", textHeight);
899 if (dwStyle & SBT_TOOLTIPS) {
900 infoPtr->hwndToolTip =
901 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
902 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
903 CW_USEDEFAULT, hwnd, 0,
904 (HINSTANCE)GetWindowLongW(hwnd, GWL_HINSTANCE), NULL);
906 if (infoPtr->hwndToolTip) {
907 NMTOOLTIPSCREATED nmttc;
909 nmttc.hdr.hwndFrom = hwnd;
910 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
911 nmttc.hdr.code = NM_TOOLTIPSCREATED;
912 nmttc.hwndToolTips = infoPtr->hwndToolTip;
914 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
915 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
919 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
920 GetClientRect (GetParent (hwnd), &rect);
921 width = rect.right - rect.left;
922 infoPtr->height = textHeight + 4 + VERT_BORDER;
923 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
924 width, infoPtr->height, SWP_NOZORDER);
925 STATUSBAR_SetPartBounds (infoPtr);
932 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
937 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
938 * of the first part only (usual behaviour) */
940 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
945 if (!(infoPtr->parts[0].text))
947 if (infoPtr->bUnicode)
948 len = strlenW (infoPtr->parts[0].text);
950 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
953 if (infoPtr->bUnicode)
954 strcpyW (buf, infoPtr->parts[0].text);
956 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
957 (LPSTR)buf, len+1, NULL, NULL );
966 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
968 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
972 GetClientRect (infoPtr->Self, &rect);
976 ScreenToClient (infoPtr->Self, &pt);
978 rect.left = rect.right - 13;
981 if (PtInRect (&rect, pt))
982 return HTBOTTOMRIGHT;
990 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
995 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
996 hdc = BeginPaint (infoPtr->Self, &ps);
997 STATUSBAR_Refresh (infoPtr, hdc);
998 EndPaint (infoPtr->Self, &ps);
1005 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
1007 infoPtr->hFont = font;
1008 TRACE("%p\n", infoPtr->hFont);
1010 InvalidateRect(infoPtr->Self, NULL, FALSE);
1017 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
1019 STATUSWINDOWPART *part;
1023 if (infoPtr->numParts == 0)
1026 part = &infoPtr->parts[0];
1027 /* duplicate string */
1029 COMCTL32_Free (part->text);
1031 if (infoPtr->bUnicode) {
1032 if (text && (len = strlenW((LPCWSTR)text))) {
1033 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1034 if (!part->text) return FALSE;
1035 strcpyW (part->text, (LPCWSTR)text);
1039 if (text && (len = lstrlenA(text))) {
1040 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1041 part->text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
1042 if (!part->text) return FALSE;
1043 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1047 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1054 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1059 /* Need to resize width to match parent */
1060 TRACE("flags %04x\n", flags);
1062 if (flags != SIZE_RESTORED) {
1063 WARN("flags MUST be SIZE_RESTORED\n");
1066 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1068 /* width and height don't apply */
1069 GetClientRect (GetParent(infoPtr->Self), &parent_rect);
1070 width = parent_rect.right - parent_rect.left;
1071 x = parent_rect.left;
1072 y = parent_rect.bottom - infoPtr->height;
1073 MoveWindow (infoPtr->Self, parent_rect.left,
1074 parent_rect.bottom - infoPtr->height,
1075 width, infoPtr->height, TRUE);
1076 STATUSBAR_SetPartBounds (infoPtr);
1082 STATUSBAR_NotifyFormat (STATUSWINDOWINFO *infoPtr, HWND from, INT cmd)
1084 if (cmd == NF_REQUERY) {
1085 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1086 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1088 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1093 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1097 TRACE("code %04x\n", code);
1098 nmhdr.hwndFrom = hwnd;
1099 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1101 SendMessageW (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1107 static LRESULT WINAPI
1108 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1110 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1111 INT nPart = ((INT) wParam) & 0x00ff;
1114 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1115 if (!infoPtr && msg != WM_CREATE)
1116 return DefWindowProcW (hwnd, msg, wParam, lParam);
1120 return STATUSBAR_GetBorders ((INT *)lParam);
1123 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1126 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1129 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1132 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1135 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1137 case SB_GETTEXTLENGTHA:
1138 case SB_GETTEXTLENGTHW:
1139 return STATUSBAR_GetTextLength (infoPtr, nPart);
1141 case SB_GETTIPTEXTA:
1142 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1144 case SB_GETTIPTEXTW:
1145 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1147 case SB_GETUNICODEFORMAT:
1148 return infoPtr->bUnicode;
1151 return infoPtr->simple;
1154 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1157 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1159 case SB_SETMINHEIGHT:
1160 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1163 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1166 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1169 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1171 case SB_SETTIPTEXTA:
1172 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1174 case SB_SETTIPTEXTW:
1175 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1177 case SB_SETUNICODEFORMAT:
1178 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1181 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1184 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1187 return STATUSBAR_WMDestroy (infoPtr);
1190 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1193 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1195 case WM_GETTEXTLENGTH:
1196 return STATUSBAR_GetTextLength (infoPtr, 0);
1198 case WM_LBUTTONDBLCLK:
1199 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1202 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1205 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1208 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1209 (INT)HIWORD(lParam));
1210 if (res != HTERROR) return res;
1211 return DefWindowProcW (hwnd, msg, wParam, lParam);
1213 case WM_NCLBUTTONUP:
1214 case WM_NCLBUTTONDOWN:
1215 PostMessageW (GetParent (hwnd), msg, wParam, lParam);
1218 case WM_NOTIFYFORMAT:
1219 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1222 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1224 case WM_RBUTTONDBLCLK:
1225 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1228 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1231 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1234 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1237 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1238 return DefWindowProcW (hwnd, msg, wParam, lParam);
1241 if ((msg >= WM_USER) && (msg < WM_APP))
1242 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1243 msg, wParam, lParam);
1244 return DefWindowProcW (hwnd, msg, wParam, lParam);
1250 /***********************************************************************
1251 * STATUS_Register [Internal]
1253 * Registers the status window class.
1257 STATUS_Register (void)
1261 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1262 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1263 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1264 wndClass.cbClsExtra = 0;
1265 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1266 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
1267 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1268 wndClass.lpszClassName = STATUSCLASSNAMEW;
1270 RegisterClassW (&wndClass);
1274 /***********************************************************************
1275 * STATUS_Unregister [Internal]
1277 * Unregisters the status window class.
1281 STATUS_Unregister (void)
1283 UnregisterClassW (STATUSCLASSNAMEW, NULL);