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);
76 COLORREF clrBk; /* background color */
77 BOOL bUnicode; /* unicode flag */
78 BOOL NtfUnicode; /* notify format */
79 STATUSWINDOWPART part0; /* simple window */
80 STATUSWINDOWPART* parts;
84 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
85 * The second cdrom contains executables drawstat.exe, gettext.exe,
86 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
93 #define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongW (hwnd, 0))
97 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr);
99 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
101 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
105 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
107 HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
111 TRACE("draw size grip %ld,%ld - %ld,%ld\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
113 pt.x = lpRect->right - 1;
114 pt.y = lpRect->bottom - 1;
116 hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
117 hOldPen = SelectObject( hdc, hPenFace );
118 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
119 LineTo (hdc, pt.x, pt.y);
120 LineTo (hdc, pt.x, pt.y - 13);
125 hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
126 SelectObject( hdc, hPenShadow );
127 for (i = 1; i < 11; i += 4) {
128 MoveToEx (hdc, pt.x - i, pt.y, NULL);
129 LineTo (hdc, pt.x + 1, pt.y - i - 1);
131 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
132 LineTo (hdc, pt.x + 1, pt.y - i - 2);
135 hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
136 SelectObject( hdc, hPenHighlight );
137 for (i = 3; i < 13; i += 4) {
138 MoveToEx (hdc, pt.x - i, pt.y, NULL);
139 LineTo (hdc, pt.x + 1, pt.y - i - 1);
142 SelectObject (hdc, hOldPen);
143 DeleteObject( hPenFace );
144 DeleteObject( hPenShadow );
145 DeleteObject( hPenHighlight );
150 STATUSBAR_DrawPart (HDC hdc, const STATUSWINDOWPART *part, const STATUSWINDOWINFO *infoPtr, int itemID)
152 RECT r = part->bound;
153 UINT border = BDR_SUNKENOUTER;
155 TRACE("part bound %ld,%ld - %ld,%ld\n", r.left, r.top, r.right, r.bottom);
156 if (part->style & SBT_POPOUT)
157 border = BDR_RAISEDOUTER;
158 else if (part->style & SBT_NOBORDERS)
161 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
163 if (part->style & SBT_OWNERDRAW)
167 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
169 dis.hwndItem = infoPtr->Self;
172 dis.itemData = (INT)part->text;
173 SendMessageW (GetParent (infoPtr->Self), WM_DRAWITEM,
174 (WPARAM)dis.CtlID, (LPARAM)&dis);
180 INT cy = r.bottom - r.top;
183 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
186 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
192 STATUSBAR_RefreshPart (const STATUSWINDOWINFO *infoPtr, const STATUSWINDOWPART *part, HDC hdc, int itemID)
197 TRACE("item %d\n", itemID);
198 if (!IsWindowVisible (infoPtr->Self))
201 if (part->bound.right < part->bound.left) return;
203 if (infoPtr->clrBk != CLR_DEFAULT)
204 hbrBk = CreateSolidBrush (infoPtr->clrBk);
206 hbrBk = GetSysColorBrush (COLOR_3DFACE);
207 FillRect(hdc, &part->bound, hbrBk);
209 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
211 STATUSBAR_DrawPart (hdc, part, infoPtr, itemID);
213 SelectObject (hdc, hOldFont);
215 if (infoPtr->clrBk != CLR_DEFAULT)
216 DeleteObject (hbrBk);
218 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
222 GetClientRect (infoPtr->Self, &rect);
223 STATUSBAR_DrawSizeGrip (hdc, &rect);
229 STATUSBAR_Refresh (STATUSWINDOWINFO *infoPtr, HDC hdc)
237 if (!IsWindowVisible(infoPtr->Self))
240 STATUSBAR_SetPartBounds(infoPtr);
242 GetClientRect (infoPtr->Self, &rect);
244 if (infoPtr->clrBk != CLR_DEFAULT)
245 hbrBk = CreateSolidBrush (infoPtr->clrBk);
247 hbrBk = GetSysColorBrush (COLOR_3DFACE);
248 FillRect(hdc, &rect, hbrBk);
250 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
252 if (infoPtr->simple) {
253 STATUSBAR_RefreshPart (infoPtr, &infoPtr->part0, hdc, 0);
255 for (i = 0; i < infoPtr->numParts; i++) {
256 STATUSBAR_RefreshPart (infoPtr, &infoPtr->parts[i], hdc, i);
260 SelectObject (hdc, hOldFont);
262 if (infoPtr->clrBk != CLR_DEFAULT)
263 DeleteObject (hbrBk);
265 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
266 STATUSBAR_DrawSizeGrip (hdc, &rect);
273 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr)
275 STATUSWINDOWPART *part;
279 /* get our window size */
280 GetClientRect (infoPtr->Self, &rect);
281 TRACE("client wnd size is %ld,%ld - %ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom);
283 rect.top += VERT_BORDER;
285 /* set bounds for simple rectangle */
286 infoPtr->part0.bound = rect;
288 /* set bounds for non-simple rectangles */
289 for (i = 0; i < infoPtr->numParts; i++) {
290 part = &infoPtr->parts[i];
291 r = &infoPtr->parts[i].bound;
293 r->bottom = rect.bottom;
297 r->left = infoPtr->parts[i-1].bound.right + HORZ_GAP;
299 r->right = rect.right;
303 if (infoPtr->hwndToolTip) {
306 ti.cbSize = sizeof(TTTOOLINFOW);
307 ti.hwnd = infoPtr->Self;
310 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
318 STATUSBAR_Relay2Tip (STATUSWINDOWINFO *infoPtr, UINT uMsg,
319 WPARAM wParam, LPARAM lParam)
323 msg.hwnd = infoPtr->Self;
327 msg.time = GetMessageTime ();
328 msg.pt.x = LOWORD(GetMessagePos ());
329 msg.pt.y = HIWORD(GetMessagePos ());
331 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
336 STATUSBAR_GetBorders (INT out[])
339 out[0] = HORZ_BORDER; /* horizontal border width */
340 out[1] = VERT_BORDER; /* vertical border width */
341 out[2] = HORZ_GAP; /* width of border between rectangles */
348 STATUSBAR_GetIcon (STATUSWINDOWINFO *infoPtr, INT nPart)
350 TRACE("%d\n", nPart);
351 /* MSDN says: "simple parts are indexed with -1" */
352 if ((nPart < -1) || (nPart >= infoPtr->numParts))
356 return (infoPtr->part0.hIcon);
358 return (infoPtr->parts[nPart].hIcon);
363 STATUSBAR_GetParts (STATUSWINDOWINFO *infoPtr, INT num_parts, INT parts[])
367 TRACE("(%d)\n", num_parts);
369 for (i = 0; i < num_parts; i++) {
370 parts[i] = infoPtr->parts[i].x;
373 return infoPtr->numParts;
378 STATUSBAR_GetRect (STATUSWINDOWINFO *infoPtr, INT nPart, LPRECT rect)
380 TRACE("part %d\n", nPart);
382 *rect = infoPtr->part0.bound;
384 *rect = infoPtr->parts[nPart].bound;
390 STATUSBAR_GetTextA (STATUSWINDOWINFO *infoPtr, INT nPart, LPSTR buf)
392 STATUSWINDOWPART *part;
395 TRACE("part %d\n", nPart);
397 /* MSDN says: "simple parts use index of 0", so this check is ok. */
398 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
401 part = &infoPtr->part0;
403 part = &infoPtr->parts[nPart];
405 if (part->style & SBT_OWNERDRAW)
406 result = (LRESULT)part->text;
408 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
409 NULL, 0, NULL, NULL ) - 1 : 0;
410 result = MAKELONG( len, part->style );
411 if (part->text && buf)
412 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
419 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, INT nPart, LPWSTR buf)
421 STATUSWINDOWPART *part;
424 TRACE("part %d\n", nPart);
425 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
428 part = &infoPtr->part0;
430 part = &infoPtr->parts[nPart];
432 if (part->style & SBT_OWNERDRAW)
433 result = (LRESULT)part->text;
435 result = part->text ? strlenW (part->text) : 0;
436 result |= (part->style << 16);
437 if (part->text && buf)
438 strcpyW (buf, part->text);
445 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, INT nPart)
447 STATUSWINDOWPART *part;
450 TRACE("part %d\n", nPart);
452 /* MSDN says: "simple parts use index of 0", so this check is ok. */
453 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
456 part = &infoPtr->part0;
458 part = &infoPtr->parts[nPart];
461 result = strlenW(part->text);
465 result |= (part->style << 16);
470 STATUSBAR_GetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR tip, INT size)
474 CHAR buf[INFOTIPSIZE];
477 if (infoPtr->hwndToolTip) {
479 ti.cbSize = sizeof(TTTOOLINFOA);
480 ti.hwnd = infoPtr->Self;
483 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
485 lstrcpynA (tip, buf, size);
492 STATUSBAR_GetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR tip, INT size)
496 WCHAR buf[INFOTIPSIZE];
499 if (infoPtr->hwndToolTip) {
501 ti.cbSize = sizeof(TTTOOLINFOW);
502 ti.hwnd = infoPtr->Self;
505 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
507 lstrcpynW(tip, buf, size);
515 STATUSBAR_SetBkColor (STATUSWINDOWINFO *infoPtr, COLORREF color)
519 oldBkColor = infoPtr->clrBk;
520 infoPtr->clrBk = color;
521 InvalidateRect(infoPtr->Self, NULL, FALSE);
523 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
529 STATUSBAR_SetIcon (STATUSWINDOWINFO *infoPtr, INT nPart, HICON hIcon)
531 if ((nPart < -1) || (nPart >= infoPtr->numParts))
534 TRACE("setting part %d\n", nPart);
536 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
538 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
540 infoPtr->part0.hIcon = hIcon;
542 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
544 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
547 infoPtr->parts[nPart].hIcon = hIcon;
548 if (!(infoPtr->simple))
549 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
556 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, INT height)
559 TRACE("(height=%d)\n", height);
560 if (IsWindowVisible (infoPtr->Self)) {
564 GetClientRect (GetParent (infoPtr->Self), &parent_rect);
565 infoPtr->height = height + VERT_BORDER;
566 width = parent_rect.right - parent_rect.left;
567 x = parent_rect.left;
568 y = parent_rect.bottom - infoPtr->height;
569 MoveWindow (infoPtr->Self, parent_rect.left,
570 parent_rect.bottom - infoPtr->height,
571 width, infoPtr->height, TRUE);
572 STATUSBAR_SetPartBounds (infoPtr);
580 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, INT count, LPINT parts)
582 STATUSWINDOWPART *tmp;
585 TRACE("(%d,%p)\n", count, parts);
587 oldNumParts = infoPtr->numParts;
588 infoPtr->numParts = count;
589 if (oldNumParts > infoPtr->numParts) {
590 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
591 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
592 Free (infoPtr->parts[i].text);
594 } else if (oldNumParts < infoPtr->numParts) {
595 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
596 if (!tmp) return FALSE;
597 for (i = 0; i < oldNumParts; i++) {
598 tmp[i] = infoPtr->parts[i];
601 Free (infoPtr->parts);
602 infoPtr->parts = tmp;
604 if (oldNumParts == infoPtr->numParts) {
605 for (i=0; i < oldNumParts; i++)
606 if (infoPtr->parts[i].x != parts[i])
608 if (i==oldNumParts) /* Unchanged? no need to redraw! */
612 for (i = 0; i < infoPtr->numParts; i++)
613 infoPtr->parts[i].x = parts[i];
615 if (infoPtr->hwndToolTip) {
619 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
620 ti.cbSize = sizeof(TTTOOLINFOW);
621 ti.hwnd = infoPtr->Self;
623 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
624 if (nTipCount < infoPtr->numParts) {
626 for (i = nTipCount; i < infoPtr->numParts; i++) {
627 TRACE("add tool %d\n", i);
629 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
633 else if (nTipCount > infoPtr->numParts) {
635 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
636 TRACE("delete tool %d\n", i);
638 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
643 STATUSBAR_SetPartBounds (infoPtr);
644 InvalidateRect(infoPtr->Self, NULL, FALSE);
650 STATUSBAR_SetTextT (STATUSWINDOWINFO *infoPtr, INT nPart, WORD style,
651 LPCWSTR text, BOOL isW)
653 STATUSWINDOWPART *part=NULL;
654 BOOL changed = FALSE;
656 if (style & SBT_OWNERDRAW) {
657 TRACE("part %d, text %p\n",nPart,text);
659 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
661 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
662 * window is assumed to be a simple window */
664 if (nPart == 0x00ff) {
665 part = &infoPtr->part0;
667 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
668 part = &infoPtr->parts[nPart];
671 if (!part) return FALSE;
673 if (part->style != style)
677 if (style & SBT_OWNERDRAW) {
678 if (part->text == text)
680 part->text = (LPWSTR)text;
685 LPCSTR atxt = (LPCSTR)text;
686 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
687 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
688 if (!ntext) return FALSE;
689 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
691 ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
692 if (!ntext) return FALSE;
693 strcpyW (ntext, text);
696 /* check if text is unchanged -> no need to redraw */
698 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
699 if (!isW) Free(ntext);
703 if (!changed && !part->text)
711 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
718 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR text)
720 TRACE("part %d: \"%s\"\n", id, text);
721 if (infoPtr->hwndToolTip) {
723 ti.cbSize = sizeof(TTTOOLINFOA);
724 ti.hwnd = infoPtr->Self;
728 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
737 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR text)
739 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
740 if (infoPtr->hwndToolTip) {
742 ti.cbSize = sizeof(TTTOOLINFOW);
743 ti.hwnd = infoPtr->Self;
747 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
755 inline static LRESULT
756 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, BOOL bUnicode)
758 BOOL bOld = infoPtr->bUnicode;
760 TRACE("(0x%x)\n", bUnicode);
761 infoPtr->bUnicode = bUnicode;
768 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, BOOL simple)
772 TRACE("(simple=%d)\n", simple);
773 if (infoPtr->simple == simple) /* no need to change */
776 infoPtr->simple = simple;
778 /* send notification */
779 nmhdr.hwndFrom = infoPtr->Self;
780 nmhdr.idFrom = GetWindowLongW (infoPtr->Self, GWL_ID);
781 nmhdr.code = SBN_SIMPLEMODECHANGE;
782 SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY, 0, (LPARAM)&nmhdr);
783 InvalidateRect(infoPtr->Self, NULL, FALSE);
789 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr)
794 for (i = 0; i < infoPtr->numParts; i++) {
795 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
796 Free (infoPtr->parts[i].text);
798 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
799 Free (infoPtr->part0.text);
800 Free (infoPtr->parts);
802 /* delete default font */
803 if (infoPtr->hDefaultFont)
804 DeleteObject (infoPtr->hDefaultFont);
806 /* delete tool tip control */
807 if (infoPtr->hwndToolTip)
808 DestroyWindow (infoPtr->hwndToolTip);
810 SetWindowLongW(infoPtr->Self, 0, 0);
817 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
819 STATUSWINDOWINFO *infoPtr;
820 NONCLIENTMETRICSW nclm;
823 int i, width, len, textHeight = 0;
827 infoPtr = (STATUSWINDOWINFO*)Alloc (sizeof(STATUSWINDOWINFO));
828 if (!infoPtr) goto create_fail;
829 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
831 infoPtr->Self = hwnd;
832 infoPtr->numParts = 1;
834 infoPtr->simple = FALSE;
835 infoPtr->clrBk = CLR_DEFAULT;
838 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
839 infoPtr->NtfUnicode = (i == NFR_UNICODE);
841 GetClientRect (hwnd, &rect);
842 InvalidateRect (hwnd, &rect, 0);
845 ZeroMemory (&nclm, sizeof(nclm));
846 nclm.cbSize = sizeof(nclm);
847 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
848 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
850 /* initialize simple case */
851 infoPtr->part0.bound = rect;
852 infoPtr->part0.text = 0;
853 infoPtr->part0.x = 0;
854 infoPtr->part0.style = 0;
855 infoPtr->part0.hIcon = 0;
857 /* initialize first part */
858 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
859 if (!infoPtr->parts) goto create_fail;
860 infoPtr->parts[0].bound = rect;
861 infoPtr->parts[0].text = 0;
862 infoPtr->parts[0].x = -1;
863 infoPtr->parts[0].style = 0;
864 infoPtr->parts[0].hIcon = 0;
866 if (IsWindowUnicode (hwnd)) {
867 infoPtr->bUnicode = TRUE;
868 if (lpCreate->lpszName &&
869 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
870 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
871 if (!infoPtr->parts[0].text) goto create_fail;
872 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
876 if (lpCreate->lpszName &&
877 (len = strlen((LPCSTR)lpCreate->lpszName))) {
878 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
879 infoPtr->parts[0].text = Alloc (lenW*sizeof(WCHAR));
880 if (!infoPtr->parts[0].text) goto create_fail;
881 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
882 infoPtr->parts[0].text, lenW );
886 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
888 /* statusbars on managed windows should not have SIZEGRIP style */
889 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
890 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
891 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
893 if ((hdc = GetDC (hwnd))) {
897 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
898 GetTextMetricsW (hdc, &tm);
899 textHeight = tm.tmHeight;
900 SelectObject (hdc, hOldFont);
901 ReleaseDC (hwnd, hdc);
903 TRACE(" textHeight=%d\n", textHeight);
905 if (dwStyle & SBT_TOOLTIPS) {
906 infoPtr->hwndToolTip =
907 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
908 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
909 CW_USEDEFAULT, hwnd, 0,
910 (HINSTANCE)GetWindowLongW(hwnd, GWL_HINSTANCE), NULL);
912 if (infoPtr->hwndToolTip) {
913 NMTOOLTIPSCREATED nmttc;
915 nmttc.hdr.hwndFrom = hwnd;
916 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
917 nmttc.hdr.code = NM_TOOLTIPSCREATED;
918 nmttc.hwndToolTips = infoPtr->hwndToolTip;
920 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
921 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
925 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
926 GetClientRect (GetParent (hwnd), &rect);
927 width = rect.right - rect.left;
928 infoPtr->height = textHeight + 4 + VERT_BORDER;
929 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
930 width, infoPtr->height, SWP_NOZORDER);
931 STATUSBAR_SetPartBounds (infoPtr);
938 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
943 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
944 * of the first part only (usual behaviour) */
946 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
951 if (!(infoPtr->parts[0].text))
953 if (infoPtr->bUnicode)
954 len = strlenW (infoPtr->parts[0].text);
956 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
959 if (infoPtr->bUnicode)
960 strcpyW (buf, infoPtr->parts[0].text);
962 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
963 (LPSTR)buf, len+1, NULL, NULL );
972 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
974 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
978 GetClientRect (infoPtr->Self, &rect);
982 ScreenToClient (infoPtr->Self, &pt);
984 rect.left = rect.right - 13;
987 if (PtInRect (&rect, pt))
988 return HTBOTTOMRIGHT;
996 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
1001 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1002 hdc = BeginPaint (infoPtr->Self, &ps);
1003 STATUSBAR_Refresh (infoPtr, hdc);
1004 EndPaint (infoPtr->Self, &ps);
1011 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
1013 infoPtr->hFont = font;
1014 TRACE("%p\n", infoPtr->hFont);
1016 InvalidateRect(infoPtr->Self, NULL, FALSE);
1023 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
1025 STATUSWINDOWPART *part;
1029 if (infoPtr->numParts == 0)
1032 part = &infoPtr->parts[0];
1033 /* duplicate string */
1037 if (infoPtr->bUnicode) {
1038 if (text && (len = strlenW((LPCWSTR)text))) {
1039 part->text = Alloc ((len+1)*sizeof(WCHAR));
1040 if (!part->text) return FALSE;
1041 strcpyW (part->text, (LPCWSTR)text);
1045 if (text && (len = lstrlenA(text))) {
1046 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1047 part->text = Alloc (lenW*sizeof(WCHAR));
1048 if (!part->text) return FALSE;
1049 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1053 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1060 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1065 /* Need to resize width to match parent */
1066 TRACE("flags %04x\n", flags);
1068 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED)
1070 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1074 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1076 /* width and height don't apply */
1077 GetClientRect (GetParent(infoPtr->Self), &parent_rect);
1078 width = parent_rect.right - parent_rect.left;
1079 x = parent_rect.left;
1080 y = parent_rect.bottom - infoPtr->height;
1081 MoveWindow (infoPtr->Self, parent_rect.left,
1082 parent_rect.bottom - infoPtr->height,
1083 width, infoPtr->height, TRUE);
1084 STATUSBAR_SetPartBounds (infoPtr);
1090 STATUSBAR_NotifyFormat (STATUSWINDOWINFO *infoPtr, HWND from, INT cmd)
1092 if (cmd == NF_REQUERY) {
1093 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1094 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1096 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1101 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1105 TRACE("code %04x\n", code);
1106 nmhdr.hwndFrom = hwnd;
1107 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1109 SendMessageW (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1115 static LRESULT WINAPI
1116 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1118 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1119 INT nPart = ((INT) wParam) & 0x00ff;
1122 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1123 if (!infoPtr && msg != WM_CREATE)
1124 return DefWindowProcW (hwnd, msg, wParam, lParam);
1128 return STATUSBAR_GetBorders ((INT *)lParam);
1131 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1134 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1137 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1140 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1143 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1145 case SB_GETTEXTLENGTHA:
1146 case SB_GETTEXTLENGTHW:
1147 return STATUSBAR_GetTextLength (infoPtr, nPart);
1149 case SB_GETTIPTEXTA:
1150 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1152 case SB_GETTIPTEXTW:
1153 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1155 case SB_GETUNICODEFORMAT:
1156 return infoPtr->bUnicode;
1159 return infoPtr->simple;
1162 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1165 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1167 case SB_SETMINHEIGHT:
1168 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1171 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1174 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1177 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1179 case SB_SETTIPTEXTA:
1180 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1182 case SB_SETTIPTEXTW:
1183 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1185 case SB_SETUNICODEFORMAT:
1186 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1189 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1192 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1195 return STATUSBAR_WMDestroy (infoPtr);
1198 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1201 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1203 case WM_GETTEXTLENGTH:
1204 return STATUSBAR_GetTextLength (infoPtr, 0);
1206 case WM_LBUTTONDBLCLK:
1207 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1210 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1213 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1216 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1217 (INT)HIWORD(lParam));
1218 if (res != HTERROR) return res;
1219 return DefWindowProcW (hwnd, msg, wParam, lParam);
1221 case WM_NCLBUTTONUP:
1222 case WM_NCLBUTTONDOWN:
1223 PostMessageW (GetParent (hwnd), msg, wParam, lParam);
1226 case WM_NOTIFYFORMAT:
1227 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1230 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1232 case WM_RBUTTONDBLCLK:
1233 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1236 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1239 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1242 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1245 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1246 return DefWindowProcW (hwnd, msg, wParam, lParam);
1249 if ((msg >= WM_USER) && (msg < WM_APP))
1250 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1251 msg, wParam, lParam);
1252 return DefWindowProcW (hwnd, msg, wParam, lParam);
1258 /***********************************************************************
1259 * STATUS_Register [Internal]
1261 * Registers the status window class.
1265 STATUS_Register (void)
1269 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1270 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1271 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1272 wndClass.cbClsExtra = 0;
1273 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1274 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1275 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1276 wndClass.lpszClassName = STATUSCLASSNAMEW;
1278 RegisterClassW (&wndClass);
1282 /***********************************************************************
1283 * STATUS_Unregister [Internal]
1285 * Unregisters the status window class.
1289 STATUS_Unregister (void)
1291 UnregisterClassW (STATUSCLASSNAMEW, NULL);