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"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
75 COLORREF clrBk; /* background color */
76 BOOL bUnicode; /* unicode flag */
77 BOOL NtfUnicode; /* notify format */
78 STATUSWINDOWPART part0; /* simple window */
79 STATUSWINDOWPART* parts;
83 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
84 * The second cdrom contains executables drawstat.exe, gettext.exe,
85 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
92 #define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongW (hwnd, 0))
96 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr);
98 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
100 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
104 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
106 HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
110 TRACE("draw size grip %ld,%ld - %ld,%ld\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
112 pt.x = lpRect->right - 1;
113 pt.y = lpRect->bottom - 1;
115 hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
116 hOldPen = SelectObject( hdc, hPenFace );
117 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
118 LineTo (hdc, pt.x, pt.y);
119 LineTo (hdc, pt.x, pt.y - 13);
124 hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
125 SelectObject( hdc, hPenShadow );
126 for (i = 1; i < 11; i += 4) {
127 MoveToEx (hdc, pt.x - i, pt.y, NULL);
128 LineTo (hdc, pt.x + 1, pt.y - i - 1);
130 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
131 LineTo (hdc, pt.x + 1, pt.y - i - 2);
134 hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
135 SelectObject( hdc, hPenHighlight );
136 for (i = 3; i < 13; i += 4) {
137 MoveToEx (hdc, pt.x - i, pt.y, NULL);
138 LineTo (hdc, pt.x + 1, pt.y - i - 1);
141 SelectObject (hdc, hOldPen);
142 DeleteObject( hPenFace );
143 DeleteObject( hPenShadow );
144 DeleteObject( hPenHighlight );
149 STATUSBAR_DrawPart (HDC hdc, const STATUSWINDOWPART *part, const STATUSWINDOWINFO *infoPtr, int itemID)
151 RECT r = part->bound;
152 UINT border = BDR_SUNKENOUTER;
154 TRACE("part bound %ld,%ld - %ld,%ld\n", r.left, r.top, r.right, r.bottom);
155 if (part->style & SBT_POPOUT)
156 border = BDR_RAISEDOUTER;
157 else if (part->style & SBT_NOBORDERS)
160 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
162 if (part->style & SBT_OWNERDRAW)
166 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
168 dis.hwndItem = infoPtr->Self;
171 dis.itemData = (INT)part->text;
172 SendMessageW (GetParent (infoPtr->Self), WM_DRAWITEM,
173 (WPARAM)dis.CtlID, (LPARAM)&dis);
179 INT cy = r.bottom - r.top;
182 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
185 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
191 STATUSBAR_RefreshPart (const STATUSWINDOWINFO *infoPtr, const STATUSWINDOWPART *part, HDC hdc, int itemID)
196 TRACE("item %d\n", itemID);
197 if (!IsWindowVisible (infoPtr->Self))
200 if (part->bound.right < part->bound.left) return;
202 if (infoPtr->clrBk != CLR_DEFAULT)
203 hbrBk = CreateSolidBrush (infoPtr->clrBk);
205 hbrBk = GetSysColorBrush (COLOR_3DFACE);
206 FillRect(hdc, &part->bound, hbrBk);
208 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
210 STATUSBAR_DrawPart (hdc, part, infoPtr, itemID);
212 SelectObject (hdc, hOldFont);
214 if (infoPtr->clrBk != CLR_DEFAULT)
215 DeleteObject (hbrBk);
217 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
221 GetClientRect (infoPtr->Self, &rect);
222 STATUSBAR_DrawSizeGrip (hdc, &rect);
228 STATUSBAR_Refresh (STATUSWINDOWINFO *infoPtr, HDC hdc)
236 if (!IsWindowVisible(infoPtr->Self))
239 STATUSBAR_SetPartBounds(infoPtr);
241 GetClientRect (infoPtr->Self, &rect);
243 if (infoPtr->clrBk != CLR_DEFAULT)
244 hbrBk = CreateSolidBrush (infoPtr->clrBk);
246 hbrBk = GetSysColorBrush (COLOR_3DFACE);
247 FillRect(hdc, &rect, hbrBk);
249 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
251 if (infoPtr->simple) {
252 STATUSBAR_RefreshPart (infoPtr, &infoPtr->part0, hdc, 0);
254 for (i = 0; i < infoPtr->numParts; i++) {
255 STATUSBAR_RefreshPart (infoPtr, &infoPtr->parts[i], hdc, i);
259 SelectObject (hdc, hOldFont);
261 if (infoPtr->clrBk != CLR_DEFAULT)
262 DeleteObject (hbrBk);
264 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
265 STATUSBAR_DrawSizeGrip (hdc, &rect);
272 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr)
274 STATUSWINDOWPART *part;
278 /* get our window size */
279 GetClientRect (infoPtr->Self, &rect);
280 TRACE("client wnd size is %ld,%ld - %ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom);
282 rect.top += VERT_BORDER;
284 /* set bounds for simple rectangle */
285 infoPtr->part0.bound = rect;
287 /* set bounds for non-simple rectangles */
288 for (i = 0; i < infoPtr->numParts; i++) {
289 part = &infoPtr->parts[i];
290 r = &infoPtr->parts[i].bound;
292 r->bottom = rect.bottom;
296 r->left = infoPtr->parts[i-1].bound.right + HORZ_GAP;
298 r->right = rect.right;
302 if (infoPtr->hwndToolTip) {
305 ti.cbSize = sizeof(TTTOOLINFOW);
306 ti.hwnd = infoPtr->Self;
309 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
317 STATUSBAR_Relay2Tip (STATUSWINDOWINFO *infoPtr, UINT uMsg,
318 WPARAM wParam, LPARAM lParam)
322 msg.hwnd = infoPtr->Self;
326 msg.time = GetMessageTime ();
327 msg.pt.x = LOWORD(GetMessagePos ());
328 msg.pt.y = HIWORD(GetMessagePos ());
330 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
335 STATUSBAR_GetBorders (INT out[])
338 out[0] = HORZ_BORDER; /* horizontal border width */
339 out[1] = VERT_BORDER; /* vertical border width */
340 out[2] = HORZ_GAP; /* width of border between rectangles */
347 STATUSBAR_GetIcon (STATUSWINDOWINFO *infoPtr, INT nPart)
349 TRACE("%d\n", nPart);
350 /* MSDN says: "simple parts are indexed with -1" */
351 if ((nPart < -1) || (nPart >= infoPtr->numParts))
355 return (infoPtr->part0.hIcon);
357 return (infoPtr->parts[nPart].hIcon);
362 STATUSBAR_GetParts (STATUSWINDOWINFO *infoPtr, INT num_parts, INT parts[])
366 TRACE("(%d)\n", num_parts);
368 for (i = 0; i < num_parts; i++) {
369 parts[i] = infoPtr->parts[i].x;
372 return infoPtr->numParts;
377 STATUSBAR_GetRect (STATUSWINDOWINFO *infoPtr, INT nPart, LPRECT rect)
379 TRACE("part %d\n", nPart);
381 *rect = infoPtr->part0.bound;
383 *rect = infoPtr->parts[nPart].bound;
389 STATUSBAR_GetTextA (STATUSWINDOWINFO *infoPtr, INT nPart, LPSTR buf)
391 STATUSWINDOWPART *part;
394 TRACE("part %d\n", nPart);
396 /* MSDN says: "simple parts use index of 0", so this check is ok. */
397 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
400 part = &infoPtr->part0;
402 part = &infoPtr->parts[nPart];
404 if (part->style & SBT_OWNERDRAW)
405 result = (LRESULT)part->text;
407 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
408 NULL, 0, NULL, NULL ) - 1 : 0;
409 result = MAKELONG( len, part->style );
410 if (part->text && buf)
411 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
418 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, INT nPart, LPWSTR buf)
420 STATUSWINDOWPART *part;
423 TRACE("part %d\n", nPart);
424 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
427 part = &infoPtr->part0;
429 part = &infoPtr->parts[nPart];
431 if (part->style & SBT_OWNERDRAW)
432 result = (LRESULT)part->text;
434 result = part->text ? strlenW (part->text) : 0;
435 result |= (part->style << 16);
436 if (part->text && buf)
437 strcpyW (buf, part->text);
444 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, INT nPart)
446 STATUSWINDOWPART *part;
449 TRACE("part %d\n", nPart);
451 /* MSDN says: "simple parts use index of 0", so this check is ok. */
452 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
455 part = &infoPtr->part0;
457 part = &infoPtr->parts[nPart];
460 result = strlenW(part->text);
464 result |= (part->style << 16);
469 STATUSBAR_GetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR tip, INT size)
473 CHAR buf[INFOTIPSIZE];
476 if (infoPtr->hwndToolTip) {
478 ti.cbSize = sizeof(TTTOOLINFOA);
479 ti.hwnd = infoPtr->Self;
482 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
484 lstrcpynA (tip, buf, size);
491 STATUSBAR_GetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR tip, INT size)
495 WCHAR buf[INFOTIPSIZE];
498 if (infoPtr->hwndToolTip) {
500 ti.cbSize = sizeof(TTTOOLINFOW);
501 ti.hwnd = infoPtr->Self;
504 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
506 lstrcpynW(tip, buf, size);
514 STATUSBAR_SetBkColor (STATUSWINDOWINFO *infoPtr, COLORREF color)
518 oldBkColor = infoPtr->clrBk;
519 infoPtr->clrBk = color;
520 InvalidateRect(infoPtr->Self, NULL, FALSE);
522 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
528 STATUSBAR_SetIcon (STATUSWINDOWINFO *infoPtr, INT nPart, HICON hIcon)
530 if ((nPart < -1) || (nPart >= infoPtr->numParts))
533 TRACE("setting part %d\n", nPart);
535 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
537 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
539 infoPtr->part0.hIcon = hIcon;
541 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
543 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
546 infoPtr->parts[nPart].hIcon = hIcon;
547 if (!(infoPtr->simple))
548 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
555 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, INT height)
558 TRACE("(height=%d)\n", height);
559 if (IsWindowVisible (infoPtr->Self)) {
563 GetClientRect (GetParent (infoPtr->Self), &parent_rect);
564 infoPtr->height = height + VERT_BORDER;
565 width = parent_rect.right - parent_rect.left;
566 x = parent_rect.left;
567 y = parent_rect.bottom - infoPtr->height;
568 MoveWindow (infoPtr->Self, parent_rect.left,
569 parent_rect.bottom - infoPtr->height,
570 width, infoPtr->height, TRUE);
571 STATUSBAR_SetPartBounds (infoPtr);
579 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, INT count, LPINT parts)
581 STATUSWINDOWPART *tmp;
584 TRACE("(%d,%p)\n", count, parts);
586 oldNumParts = infoPtr->numParts;
587 infoPtr->numParts = count;
588 if (oldNumParts > infoPtr->numParts) {
589 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
590 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
591 COMCTL32_Free (infoPtr->parts[i].text);
593 } else if (oldNumParts < infoPtr->numParts) {
594 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
595 if (!tmp) return FALSE;
596 for (i = 0; i < oldNumParts; i++) {
597 tmp[i] = infoPtr->parts[i];
600 COMCTL32_Free (infoPtr->parts);
601 infoPtr->parts = tmp;
603 if (oldNumParts == infoPtr->numParts) {
604 for (i=0; i < oldNumParts; i++)
605 if (infoPtr->parts[i].x != parts[i])
607 if (i==oldNumParts) /* Unchanged? no need to redraw! */
611 for (i = 0; i < infoPtr->numParts; i++)
612 infoPtr->parts[i].x = parts[i];
614 if (infoPtr->hwndToolTip) {
618 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
619 ti.cbSize = sizeof(TTTOOLINFOW);
620 ti.hwnd = infoPtr->Self;
622 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
623 if (nTipCount < infoPtr->numParts) {
625 for (i = nTipCount; i < infoPtr->numParts; i++) {
626 TRACE("add tool %d\n", i);
628 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
632 else if (nTipCount > infoPtr->numParts) {
634 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
635 TRACE("delete tool %d\n", i);
637 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
642 STATUSBAR_SetPartBounds (infoPtr);
643 InvalidateRect(infoPtr->Self, NULL, FALSE);
649 STATUSBAR_SetTextT (STATUSWINDOWINFO *infoPtr, INT nPart, WORD style,
650 LPCWSTR text, BOOL isW)
652 STATUSWINDOWPART *part=NULL;
653 BOOL changed = FALSE;
655 if (style & SBT_OWNERDRAW) {
656 TRACE("part %d, text %p\n",nPart,text);
658 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
660 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
661 * window is assumed to be a simple window */
663 if (nPart == 0x00ff) {
664 part = &infoPtr->part0;
666 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
667 part = &infoPtr->parts[nPart];
670 if (!part) return FALSE;
672 if (part->style != style)
676 if (style & SBT_OWNERDRAW) {
677 if (part->text == text)
679 part->text = (LPWSTR)text;
684 LPCSTR atxt = (LPCSTR)text;
685 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
686 ntext = COMCTL32_Alloc( (len + 1)*sizeof(WCHAR) );
687 if (!ntext) return FALSE;
688 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
690 ntext = COMCTL32_Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
691 if (!ntext) return FALSE;
692 strcpyW (ntext, text);
695 /* check if text is unchanged -> no need to redraw */
697 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
698 if (!isW) COMCTL32_Free(ntext);
702 if (!changed && !part->text)
707 COMCTL32_Free (part->text);
710 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
717 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR text)
719 TRACE("part %d: \"%s\"\n", id, text);
720 if (infoPtr->hwndToolTip) {
722 ti.cbSize = sizeof(TTTOOLINFOA);
723 ti.hwnd = infoPtr->Self;
727 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
736 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR text)
738 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
739 if (infoPtr->hwndToolTip) {
741 ti.cbSize = sizeof(TTTOOLINFOW);
742 ti.hwnd = infoPtr->Self;
746 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
754 inline static LRESULT
755 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, BOOL bUnicode)
757 BOOL bOld = infoPtr->bUnicode;
759 TRACE("(0x%x)\n", bUnicode);
760 infoPtr->bUnicode = bUnicode;
767 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, BOOL simple)
771 TRACE("(simple=%d)\n", simple);
772 if (infoPtr->simple == simple) /* no need to change */
775 infoPtr->simple = simple;
777 /* send notification */
778 nmhdr.hwndFrom = infoPtr->Self;
779 nmhdr.idFrom = GetWindowLongW (infoPtr->Self, GWL_ID);
780 nmhdr.code = SBN_SIMPLEMODECHANGE;
781 SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY, 0, (LPARAM)&nmhdr);
782 InvalidateRect(infoPtr->Self, NULL, FALSE);
788 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr)
793 for (i = 0; i < infoPtr->numParts; i++) {
794 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
795 COMCTL32_Free (infoPtr->parts[i].text);
797 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
798 COMCTL32_Free (infoPtr->part0.text);
799 COMCTL32_Free (infoPtr->parts);
801 /* delete default font */
802 if (infoPtr->hDefaultFont)
803 DeleteObject (infoPtr->hDefaultFont);
805 /* delete tool tip control */
806 if (infoPtr->hwndToolTip)
807 DestroyWindow (infoPtr->hwndToolTip);
809 COMCTL32_Free (infoPtr);
810 SetWindowLongW(infoPtr->Self, 0, 0);
816 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
818 STATUSWINDOWINFO *infoPtr;
819 NONCLIENTMETRICSW nclm;
822 int i, width, len, textHeight = 0;
826 infoPtr = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
827 if (!infoPtr) goto create_fail;
828 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
830 infoPtr->Self = hwnd;
831 infoPtr->numParts = 1;
833 infoPtr->simple = FALSE;
834 infoPtr->clrBk = CLR_DEFAULT;
837 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
838 infoPtr->NtfUnicode = (i == NFR_UNICODE);
840 GetClientRect (hwnd, &rect);
841 InvalidateRect (hwnd, &rect, 0);
844 ZeroMemory (&nclm, sizeof(nclm));
845 nclm.cbSize = sizeof(nclm);
846 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
847 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
849 /* initialize simple case */
850 infoPtr->part0.bound = rect;
851 infoPtr->part0.text = 0;
852 infoPtr->part0.x = 0;
853 infoPtr->part0.style = 0;
854 infoPtr->part0.hIcon = 0;
856 /* initialize first part */
857 infoPtr->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
858 if (!infoPtr->parts) goto create_fail;
859 infoPtr->parts[0].bound = rect;
860 infoPtr->parts[0].text = 0;
861 infoPtr->parts[0].x = -1;
862 infoPtr->parts[0].style = 0;
863 infoPtr->parts[0].hIcon = 0;
865 if (IsWindowUnicode (hwnd)) {
866 infoPtr->bUnicode = TRUE;
867 if (lpCreate->lpszName &&
868 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
869 infoPtr->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
870 if (!infoPtr->parts[0].text) goto create_fail;
871 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
875 if (lpCreate->lpszName &&
876 (len = strlen((LPCSTR)lpCreate->lpszName))) {
877 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
878 infoPtr->parts[0].text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
879 if (!infoPtr->parts[0].text) goto create_fail;
880 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
881 infoPtr->parts[0].text, lenW );
885 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
887 /* statusbars on managed windows should not have SIZEGRIP style */
888 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
889 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
890 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
892 if ((hdc = GetDC (hwnd))) {
896 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
897 GetTextMetricsW (hdc, &tm);
898 textHeight = tm.tmHeight;
899 SelectObject (hdc, hOldFont);
900 ReleaseDC (hwnd, hdc);
902 TRACE(" textHeight=%d\n", textHeight);
904 if (dwStyle & SBT_TOOLTIPS) {
905 infoPtr->hwndToolTip =
906 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
907 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
908 CW_USEDEFAULT, hwnd, 0,
909 (HINSTANCE)GetWindowLongW(hwnd, GWL_HINSTANCE), NULL);
911 if (infoPtr->hwndToolTip) {
912 NMTOOLTIPSCREATED nmttc;
914 nmttc.hdr.hwndFrom = hwnd;
915 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
916 nmttc.hdr.code = NM_TOOLTIPSCREATED;
917 nmttc.hwndToolTips = infoPtr->hwndToolTip;
919 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
920 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
924 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
925 GetClientRect (GetParent (hwnd), &rect);
926 width = rect.right - rect.left;
927 infoPtr->height = textHeight + 4 + VERT_BORDER;
928 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
929 width, infoPtr->height, SWP_NOZORDER);
930 STATUSBAR_SetPartBounds (infoPtr);
937 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
942 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
943 * of the first part only (usual behaviour) */
945 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
950 if (!(infoPtr->parts[0].text))
952 if (infoPtr->bUnicode)
953 len = strlenW (infoPtr->parts[0].text);
955 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
958 if (infoPtr->bUnicode)
959 strcpyW (buf, infoPtr->parts[0].text);
961 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
962 (LPSTR)buf, len+1, NULL, NULL );
971 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
973 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
977 GetClientRect (infoPtr->Self, &rect);
981 ScreenToClient (infoPtr->Self, &pt);
983 rect.left = rect.right - 13;
986 if (PtInRect (&rect, pt))
987 return HTBOTTOMRIGHT;
995 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
1000 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1001 hdc = BeginPaint (infoPtr->Self, &ps);
1002 STATUSBAR_Refresh (infoPtr, hdc);
1003 EndPaint (infoPtr->Self, &ps);
1010 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
1012 infoPtr->hFont = font;
1013 TRACE("%p\n", infoPtr->hFont);
1015 InvalidateRect(infoPtr->Self, NULL, FALSE);
1022 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
1024 STATUSWINDOWPART *part;
1028 if (infoPtr->numParts == 0)
1031 part = &infoPtr->parts[0];
1032 /* duplicate string */
1034 COMCTL32_Free (part->text);
1036 if (infoPtr->bUnicode) {
1037 if (text && (len = strlenW((LPCWSTR)text))) {
1038 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1039 if (!part->text) return FALSE;
1040 strcpyW (part->text, (LPCWSTR)text);
1044 if (text && (len = lstrlenA(text))) {
1045 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1046 part->text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
1047 if (!part->text) return FALSE;
1048 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1052 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1059 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1064 /* Need to resize width to match parent */
1065 TRACE("flags %04x\n", flags);
1067 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED)
1069 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1073 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1075 /* width and height don't apply */
1076 GetClientRect (GetParent(infoPtr->Self), &parent_rect);
1077 width = parent_rect.right - parent_rect.left;
1078 x = parent_rect.left;
1079 y = parent_rect.bottom - infoPtr->height;
1080 MoveWindow (infoPtr->Self, parent_rect.left,
1081 parent_rect.bottom - infoPtr->height,
1082 width, infoPtr->height, TRUE);
1083 STATUSBAR_SetPartBounds (infoPtr);
1089 STATUSBAR_NotifyFormat (STATUSWINDOWINFO *infoPtr, HWND from, INT cmd)
1091 if (cmd == NF_REQUERY) {
1092 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1093 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1095 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1100 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1104 TRACE("code %04x\n", code);
1105 nmhdr.hwndFrom = hwnd;
1106 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1108 SendMessageW (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1114 static LRESULT WINAPI
1115 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1117 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1118 INT nPart = ((INT) wParam) & 0x00ff;
1121 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1122 if (!infoPtr && msg != WM_CREATE)
1123 return DefWindowProcW (hwnd, msg, wParam, lParam);
1127 return STATUSBAR_GetBorders ((INT *)lParam);
1130 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1133 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1136 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1139 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1142 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1144 case SB_GETTEXTLENGTHA:
1145 case SB_GETTEXTLENGTHW:
1146 return STATUSBAR_GetTextLength (infoPtr, nPart);
1148 case SB_GETTIPTEXTA:
1149 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1151 case SB_GETTIPTEXTW:
1152 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1154 case SB_GETUNICODEFORMAT:
1155 return infoPtr->bUnicode;
1158 return infoPtr->simple;
1161 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1164 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1166 case SB_SETMINHEIGHT:
1167 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1170 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1173 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1176 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1178 case SB_SETTIPTEXTA:
1179 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1181 case SB_SETTIPTEXTW:
1182 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1184 case SB_SETUNICODEFORMAT:
1185 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1188 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1191 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1194 return STATUSBAR_WMDestroy (infoPtr);
1197 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1200 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1202 case WM_GETTEXTLENGTH:
1203 return STATUSBAR_GetTextLength (infoPtr, 0);
1205 case WM_LBUTTONDBLCLK:
1206 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1209 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1212 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1215 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1216 (INT)HIWORD(lParam));
1217 if (res != HTERROR) return res;
1218 return DefWindowProcW (hwnd, msg, wParam, lParam);
1220 case WM_NCLBUTTONUP:
1221 case WM_NCLBUTTONDOWN:
1222 PostMessageW (GetParent (hwnd), msg, wParam, lParam);
1225 case WM_NOTIFYFORMAT:
1226 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1229 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1231 case WM_RBUTTONDBLCLK:
1232 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1235 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1238 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1241 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1244 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1245 return DefWindowProcW (hwnd, msg, wParam, lParam);
1248 if ((msg >= WM_USER) && (msg < WM_APP))
1249 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1250 msg, wParam, lParam);
1251 return DefWindowProcW (hwnd, msg, wParam, lParam);
1257 /***********************************************************************
1258 * STATUS_Register [Internal]
1260 * Registers the status window class.
1264 STATUS_Register (void)
1268 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1269 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1270 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1271 wndClass.cbClsExtra = 0;
1272 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1273 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1274 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1275 wndClass.lpszClassName = STATUSCLASSNAMEW;
1277 RegisterClassW (&wndClass);
1281 /***********************************************************************
1282 * STATUS_Unregister [Internal]
1284 * Unregisters the status window class.
1288 STATUS_Unregister (void)
1290 UnregisterClassW (STATUSCLASSNAMEW, NULL);