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;
85 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
86 * The second cdrom contains executables drawstat.exe, gettext.exe,
87 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
94 #define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongW (hwnd, 0))
98 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr);
100 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
102 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
106 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
108 HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
112 TRACE("draw size grip %ld,%ld - %ld,%ld\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
114 pt.x = lpRect->right - 1;
115 pt.y = lpRect->bottom - 1;
117 hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
118 hOldPen = SelectObject( hdc, hPenFace );
119 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
120 LineTo (hdc, pt.x, pt.y);
121 LineTo (hdc, pt.x, pt.y - 13);
126 hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
127 SelectObject( hdc, hPenShadow );
128 for (i = 1; i < 11; i += 4) {
129 MoveToEx (hdc, pt.x - i, pt.y, NULL);
130 LineTo (hdc, pt.x + 1, pt.y - i - 1);
132 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
133 LineTo (hdc, pt.x + 1, pt.y - i - 2);
136 hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
137 SelectObject( hdc, hPenHighlight );
138 for (i = 3; i < 13; i += 4) {
139 MoveToEx (hdc, pt.x - i, pt.y, NULL);
140 LineTo (hdc, pt.x + 1, pt.y - i - 1);
143 SelectObject (hdc, hOldPen);
144 DeleteObject( hPenFace );
145 DeleteObject( hPenShadow );
146 DeleteObject( hPenHighlight );
151 STATUSBAR_DrawPart (HDC hdc, const STATUSWINDOWPART *part, const STATUSWINDOWINFO *infoPtr, int itemID)
153 RECT r = part->bound;
154 UINT border = BDR_SUNKENOUTER;
156 TRACE("part bound %ld,%ld - %ld,%ld\n", r.left, r.top, r.right, r.bottom);
157 if (part->style & SBT_POPOUT)
158 border = BDR_RAISEDOUTER;
159 else if (part->style & SBT_NOBORDERS)
162 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
164 if (part->style & SBT_OWNERDRAW)
168 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
170 dis.hwndItem = infoPtr->Self;
173 dis.itemData = (INT)part->text;
174 SendMessageW (infoPtr->Notify, WM_DRAWITEM, (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 (infoPtr->Notify, &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 (infoPtr->Notify, 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->Notify = lpCreate->hwndParent;
833 infoPtr->numParts = 1;
835 infoPtr->simple = FALSE;
836 infoPtr->clrBk = CLR_DEFAULT;
839 i = SendMessageW(infoPtr->Notify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
840 infoPtr->NtfUnicode = (i == NFR_UNICODE);
842 GetClientRect (hwnd, &rect);
843 InvalidateRect (hwnd, &rect, 0);
846 ZeroMemory (&nclm, sizeof(nclm));
847 nclm.cbSize = sizeof(nclm);
848 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
849 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
851 /* initialize simple case */
852 infoPtr->part0.bound = rect;
853 infoPtr->part0.text = 0;
854 infoPtr->part0.x = 0;
855 infoPtr->part0.style = 0;
856 infoPtr->part0.hIcon = 0;
858 /* initialize first part */
859 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
860 if (!infoPtr->parts) goto create_fail;
861 infoPtr->parts[0].bound = rect;
862 infoPtr->parts[0].text = 0;
863 infoPtr->parts[0].x = -1;
864 infoPtr->parts[0].style = 0;
865 infoPtr->parts[0].hIcon = 0;
867 if (IsWindowUnicode (hwnd)) {
868 infoPtr->bUnicode = TRUE;
869 if (lpCreate->lpszName &&
870 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
871 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
872 if (!infoPtr->parts[0].text) goto create_fail;
873 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
877 if (lpCreate->lpszName &&
878 (len = strlen((LPCSTR)lpCreate->lpszName))) {
879 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
880 infoPtr->parts[0].text = Alloc (lenW*sizeof(WCHAR));
881 if (!infoPtr->parts[0].text) goto create_fail;
882 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
883 infoPtr->parts[0].text, lenW );
887 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
889 /* statusbars on managed windows should not have SIZEGRIP style */
890 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
891 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
892 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
894 if ((hdc = GetDC (hwnd))) {
898 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
899 GetTextMetricsW (hdc, &tm);
900 textHeight = tm.tmHeight;
901 SelectObject (hdc, hOldFont);
902 ReleaseDC (hwnd, hdc);
904 TRACE(" textHeight=%d\n", textHeight);
906 if (dwStyle & SBT_TOOLTIPS) {
907 infoPtr->hwndToolTip =
908 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
909 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
910 CW_USEDEFAULT, hwnd, 0,
911 (HINSTANCE)GetWindowLongW(hwnd, GWL_HINSTANCE), NULL);
913 if (infoPtr->hwndToolTip) {
914 NMTOOLTIPSCREATED nmttc;
916 nmttc.hdr.hwndFrom = hwnd;
917 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
918 nmttc.hdr.code = NM_TOOLTIPSCREATED;
919 nmttc.hwndToolTips = infoPtr->hwndToolTip;
921 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
922 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
926 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
927 GetClientRect (infoPtr->Notify, &rect);
928 width = rect.right - rect.left;
929 infoPtr->height = textHeight + 4 + VERT_BORDER;
930 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
931 width, infoPtr->height, SWP_NOZORDER);
932 STATUSBAR_SetPartBounds (infoPtr);
939 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
944 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
945 * of the first part only (usual behaviour) */
947 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
952 if (!(infoPtr->parts[0].text))
954 if (infoPtr->bUnicode)
955 len = strlenW (infoPtr->parts[0].text);
957 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
960 if (infoPtr->bUnicode)
961 strcpyW (buf, infoPtr->parts[0].text);
963 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
964 (LPSTR)buf, len+1, NULL, NULL );
973 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
975 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
979 GetClientRect (infoPtr->Self, &rect);
983 ScreenToClient (infoPtr->Self, &pt);
985 rect.left = rect.right - 13;
988 if (PtInRect (&rect, pt))
989 return HTBOTTOMRIGHT;
997 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
1002 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1003 hdc = BeginPaint (infoPtr->Self, &ps);
1004 STATUSBAR_Refresh (infoPtr, hdc);
1005 EndPaint (infoPtr->Self, &ps);
1012 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
1014 infoPtr->hFont = font;
1015 TRACE("%p\n", infoPtr->hFont);
1017 InvalidateRect(infoPtr->Self, NULL, FALSE);
1024 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
1026 STATUSWINDOWPART *part;
1030 if (infoPtr->numParts == 0)
1033 part = &infoPtr->parts[0];
1034 /* duplicate string */
1038 if (infoPtr->bUnicode) {
1039 if (text && (len = strlenW((LPCWSTR)text))) {
1040 part->text = Alloc ((len+1)*sizeof(WCHAR));
1041 if (!part->text) return FALSE;
1042 strcpyW (part->text, (LPCWSTR)text);
1046 if (text && (len = lstrlenA(text))) {
1047 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1048 part->text = Alloc (lenW*sizeof(WCHAR));
1049 if (!part->text) return FALSE;
1050 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1054 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1061 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1066 /* Need to resize width to match parent */
1067 TRACE("flags %04x\n", flags);
1069 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED)
1071 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1075 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1077 /* width and height don't apply */
1078 GetClientRect (infoPtr->Notify, &parent_rect);
1079 width = parent_rect.right - parent_rect.left;
1080 x = parent_rect.left;
1081 y = parent_rect.bottom - infoPtr->height;
1082 MoveWindow (infoPtr->Self, parent_rect.left,
1083 parent_rect.bottom - infoPtr->height,
1084 width, infoPtr->height, TRUE);
1085 STATUSBAR_SetPartBounds (infoPtr);
1091 STATUSBAR_NotifyFormat (STATUSWINDOWINFO *infoPtr, HWND from, INT cmd)
1093 if (cmd == NF_REQUERY) {
1094 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1095 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1097 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1102 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1104 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1107 TRACE("code %04x\n", code);
1108 nmhdr.hwndFrom = hwnd;
1109 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1111 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
1117 static LRESULT WINAPI
1118 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1120 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1121 INT nPart = ((INT) wParam) & 0x00ff;
1124 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1125 if (!infoPtr && msg != WM_CREATE)
1126 return DefWindowProcW (hwnd, msg, wParam, lParam);
1130 return STATUSBAR_GetBorders ((INT *)lParam);
1133 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1136 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1139 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1142 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1145 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1147 case SB_GETTEXTLENGTHA:
1148 case SB_GETTEXTLENGTHW:
1149 return STATUSBAR_GetTextLength (infoPtr, nPart);
1151 case SB_GETTIPTEXTA:
1152 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1154 case SB_GETTIPTEXTW:
1155 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1157 case SB_GETUNICODEFORMAT:
1158 return infoPtr->bUnicode;
1161 return infoPtr->simple;
1164 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1167 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1169 case SB_SETMINHEIGHT:
1170 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1173 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1176 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1179 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1181 case SB_SETTIPTEXTA:
1182 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1184 case SB_SETTIPTEXTW:
1185 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1187 case SB_SETUNICODEFORMAT:
1188 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1191 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1194 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1197 return STATUSBAR_WMDestroy (infoPtr);
1200 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1203 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1205 case WM_GETTEXTLENGTH:
1206 return STATUSBAR_GetTextLength (infoPtr, 0);
1208 case WM_LBUTTONDBLCLK:
1209 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1212 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1215 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1218 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1219 (INT)HIWORD(lParam));
1220 if (res != HTERROR) return res;
1221 return DefWindowProcW (hwnd, msg, wParam, lParam);
1223 case WM_NCLBUTTONUP:
1224 case WM_NCLBUTTONDOWN:
1225 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1228 case WM_NOTIFYFORMAT:
1229 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1232 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1234 case WM_RBUTTONDBLCLK:
1235 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1238 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1241 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1244 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1247 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1248 return DefWindowProcW (hwnd, msg, wParam, lParam);
1251 if ((msg >= WM_USER) && (msg < WM_APP))
1252 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1253 msg, wParam, lParam);
1254 return DefWindowProcW (hwnd, msg, wParam, lParam);
1260 /***********************************************************************
1261 * STATUS_Register [Internal]
1263 * Registers the status window class.
1267 STATUS_Register (void)
1271 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1272 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1273 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1274 wndClass.cbClsExtra = 0;
1275 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1276 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1277 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1278 wndClass.lpszClassName = STATUSCLASSNAMEW;
1280 RegisterClassW (&wndClass);
1284 /***********************************************************************
1285 * STATUS_Unregister [Internal]
1287 * Unregisters the status window class.
1291 STATUS_Unregister (void)
1293 UnregisterClassW (STATUSCLASSNAMEW, NULL);