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
23 * 1) Implement all CCS_* styles.
24 * 2) Send WM_QUERYFORMAT
25 * 3) Use DrawEdge to draw the SizeGrip
26 * 4) Implement DrawStatusText and use it.
33 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
57 COLORREF clrBk; /* background color */
58 BOOL bUnicode; /* unicode flag */
59 STATUSWINDOWPART part0; /* simple window */
60 STATUSWINDOWPART* parts;
64 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
65 * The second cdrom contains executables drawstat.exe, gettext.exe,
66 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
73 #define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongW (hwnd, 0))
77 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr);
79 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
81 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
85 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
91 TRACE("draw size grip %d,%d - %d,%d\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
93 //FIXME: use DrawEdge to draw this
94 pt.x = lpRect->right - 1;
95 pt.y = lpRect->bottom - 1;
97 hOldPen = SelectObject (hdc, GetSysColorPen (COLOR_3DFACE));
98 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
99 LineTo (hdc, pt.x, pt.y);
100 LineTo (hdc, pt.x, pt.y - 12);
105 SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
106 for (i = 1; i < 11; i += 4) {
107 MoveToEx (hdc, pt.x - i, pt.y, NULL);
108 LineTo (hdc, pt.x, pt.y - i);
110 MoveToEx (hdc, pt.x - i-1, pt.y, NULL);
111 LineTo (hdc, pt.x, pt.y - i-1);
114 SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
115 for (i = 3; i < 13; i += 4) {
116 MoveToEx (hdc, pt.x - i, pt.y, NULL);
117 LineTo (hdc, pt.x, pt.y - i);
120 SelectObject (hdc, hOldPen);
125 STATUSBAR_DrawPart (HDC hdc, STATUSWINDOWPART *part)
127 RECT r = part->bound;
128 UINT border = BDR_SUNKENOUTER;
130 TRACE("part bound %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom);
131 if (part->style & SBT_POPOUT)
132 border = BDR_RAISEDOUTER;
133 else if (part->style & SBT_NOBORDERS)
136 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
140 INT cy = r.bottom - r.top;
143 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
149 int oldbkmode = SetBkMode(hdc, TRANSPARENT);
150 LPWSTR p = (LPWSTR)part->text;
151 UINT align = DT_LEFT;
162 TRACE("%s at %d,%d - %d,%d\n", debugstr_w(p), r.left, r.top, r.right, r.bottom);
163 DrawTextW (hdc, p, -1, &r, align|DT_VCENTER|DT_SINGLELINE);
164 SetBkMode(hdc, oldbkmode);
170 STATUSBAR_RefreshPart (STATUSWINDOWINFO *infoPtr, STATUSWINDOWPART *part, HDC hdc, int itemID)
175 TRACE("item %d\n", itemID);
176 if (!IsWindowVisible (infoPtr->Self))
179 if (part->bound.right < part->bound.left) return;
181 if (infoPtr->clrBk != CLR_DEFAULT)
182 hbrBk = CreateSolidBrush (infoPtr->clrBk);
184 hbrBk = GetSysColorBrush (COLOR_3DFACE);
185 FillRect(hdc, &part->bound, hbrBk);
187 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
189 if (part->style & SBT_OWNERDRAW) {
192 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
194 dis.hwndItem = infoPtr->Self;
196 dis.rcItem = part->bound;
197 dis.itemData = (INT)part->text;
198 SendMessageW (GetParent (infoPtr->Self), WM_DRAWITEM,
199 (WPARAM)dis.CtlID, (LPARAM)&dis);
201 STATUSBAR_DrawPart (hdc, part);
203 SelectObject (hdc, hOldFont);
205 if (infoPtr->clrBk != CLR_DEFAULT)
206 DeleteObject (hbrBk);
208 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
211 GetClientRect (infoPtr->Self, &rect);
212 STATUSBAR_DrawSizeGrip (hdc, &rect);
218 STATUSBAR_Refresh (STATUSWINDOWINFO *infoPtr, HDC hdc)
226 if (!IsWindowVisible(infoPtr->Self))
229 STATUSBAR_SetPartBounds(infoPtr);
231 GetClientRect (infoPtr->Self, &rect);
233 if (infoPtr->clrBk != CLR_DEFAULT)
234 hbrBk = CreateSolidBrush (infoPtr->clrBk);
236 hbrBk = GetSysColorBrush (COLOR_3DFACE);
237 FillRect(hdc, &rect, hbrBk);
239 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
241 if (infoPtr->simple) {
242 STATUSBAR_RefreshPart (infoPtr, &infoPtr->part0, hdc, 0);
244 for (i = 0; i < infoPtr->numParts; i++) {
245 if (infoPtr->parts[i].style & SBT_OWNERDRAW) {
248 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
250 dis.hwndItem = infoPtr->Self;
252 dis.rcItem = infoPtr->parts[i].bound;
253 dis.itemData = (INT)infoPtr->parts[i].text;
254 SendMessageW (GetParent (infoPtr->Self), WM_DRAWITEM,
255 (WPARAM)dis.CtlID, (LPARAM)&dis);
257 STATUSBAR_RefreshPart (infoPtr, &infoPtr->parts[i], hdc, i);
261 SelectObject (hdc, hOldFont);
263 if (infoPtr->clrBk != CLR_DEFAULT)
264 DeleteObject (hbrBk);
266 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
267 STATUSBAR_DrawSizeGrip (hdc, &rect);
274 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr)
276 STATUSWINDOWPART *part;
280 /* get our window size */
281 GetClientRect (infoPtr->Self, &rect);
282 TRACE("client wnd size is %d,%d - %d,%d\n", rect.left, rect.top, rect.right, rect.bottom);
284 rect.top += VERT_BORDER;
286 /* set bounds for simple rectangle */
287 infoPtr->part0.bound = rect;
289 /* set bounds for non-simple rectangles */
290 for (i = 0; i < infoPtr->numParts; i++) {
291 part = &infoPtr->parts[i];
292 r = &infoPtr->parts[i].bound;
294 r->bottom = rect.bottom;
298 r->left = infoPtr->parts[i-1].bound.right + HORZ_GAP;
300 r->right = rect.right;
304 if (infoPtr->hwndToolTip) {
307 ti.cbSize = sizeof(TTTOOLINFOW);
308 ti.hwnd = infoPtr->Self;
311 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
319 STATUSBAR_Relay2Tip (STATUSWINDOWINFO *infoPtr, UINT uMsg,
320 WPARAM wParam, LPARAM lParam)
324 msg.hwnd = infoPtr->Self;
328 msg.time = GetMessageTime ();
329 msg.pt.x = LOWORD(GetMessagePos ());
330 msg.pt.y = HIWORD(GetMessagePos ());
332 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
337 STATUSBAR_GetBorders (INT out[])
340 out[0] = HORZ_BORDER; /* horizontal border width */
341 out[1] = VERT_BORDER; /* vertical border width */
342 out[2] = HORZ_GAP; /* width of border between rectangles */
349 STATUSBAR_GetIcon (STATUSWINDOWINFO *infoPtr, INT nPart)
351 TRACE("%d\n", nPart);
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);
396 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
399 part = &infoPtr->part0;
401 part = &infoPtr->parts[nPart];
403 if (part->style & SBT_OWNERDRAW)
404 result = (LRESULT)part->text;
406 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
407 NULL, 0, NULL, NULL ) - 1 : 0;
408 result = MAKELONG( len, part->style );
409 if (part->text && buf)
410 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
417 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, INT nPart, LPWSTR buf)
419 STATUSWINDOWPART *part;
422 TRACE("part %d\n", nPart);
423 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
426 part = &infoPtr->part0;
428 part = &infoPtr->parts[nPart];
430 if (part->style & SBT_OWNERDRAW)
431 result = (LRESULT)part->text;
433 result = part->text ? strlenW (part->text) : 0;
434 result |= (part->style << 16);
435 if (part->text && buf)
436 strcpyW (buf, part->text);
443 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, INT nPart)
445 STATUSWINDOWPART *part;
448 TRACE("part %d\n", nPart);
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);
531 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
533 infoPtr->part0.hIcon = hIcon;
535 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
537 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
540 infoPtr->parts[nPart].hIcon = hIcon;
541 if (!(infoPtr->simple))
542 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
549 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, INT height)
552 TRACE("(height=%d)\n", height);
553 if (IsWindowVisible (infoPtr->Self)) {
557 GetClientRect (GetParent (infoPtr->Self), &parent_rect);
558 infoPtr->height = height + VERT_BORDER;
559 width = parent_rect.right - parent_rect.left;
560 x = parent_rect.left;
561 y = parent_rect.bottom - infoPtr->height;
562 MoveWindow (infoPtr->Self, parent_rect.left,
563 parent_rect.bottom - infoPtr->height,
564 width, infoPtr->height, TRUE);
565 STATUSBAR_SetPartBounds (infoPtr);
573 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, INT count, LPINT parts)
575 STATUSWINDOWPART *tmp;
578 TRACE("(%d,%p)\n", count, parts);
580 oldNumParts = infoPtr->numParts;
581 infoPtr->numParts = count;
582 if (oldNumParts > infoPtr->numParts) {
583 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
584 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
585 COMCTL32_Free (infoPtr->parts[i].text);
587 } else if (oldNumParts < infoPtr->numParts) {
588 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
589 if (!tmp) return FALSE;
590 for (i = 0; i < oldNumParts; i++) {
591 tmp[i] = infoPtr->parts[i];
594 COMCTL32_Free (infoPtr->parts);
595 infoPtr->parts = tmp;
597 if (oldNumParts == infoPtr->numParts) {
598 for (i=0; i < oldNumParts; i++)
599 if (infoPtr->parts[i].x != parts[i])
601 if (i==oldNumParts) /* Unchanged? no need to redraw! */
605 for (i = 0; i < infoPtr->numParts; i++)
606 infoPtr->parts[i].x = parts[i];
608 if (infoPtr->hwndToolTip) {
612 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
613 ti.cbSize = sizeof(TTTOOLINFOW);
614 ti.hwnd = infoPtr->Self;
616 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
617 if (nTipCount < infoPtr->numParts) {
619 for (i = nTipCount; i < infoPtr->numParts; i++) {
620 TRACE("add tool %d\n", i);
622 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
626 else if (nTipCount > infoPtr->numParts) {
628 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
629 TRACE("delete tool %d\n", i);
631 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
636 STATUSBAR_SetPartBounds (infoPtr);
637 InvalidateRect(infoPtr->Self, NULL, FALSE);
643 STATUSBAR_SetTextT (STATUSWINDOWINFO *infoPtr, INT nPart, WORD style,
644 LPCWSTR text, BOOL isW)
646 STATUSWINDOWPART *part=NULL;
647 BOOL changed = FALSE;
649 TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
650 if (nPart < 0 || nPart >= infoPtr->numParts) return FALSE;
653 part = &infoPtr->part0;
654 else if (!infoPtr->simple && infoPtr->parts)
655 part = &infoPtr->parts[nPart];
656 if (!part) return FALSE;
658 if (part->style != style)
662 if (style & SBT_OWNERDRAW) {
663 if (part->text == text)
665 part->text = (LPWSTR)text;
670 LPCSTR atxt = (LPCSTR)text;
671 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
672 ntext = COMCTL32_Alloc( (len + 1)*sizeof(WCHAR) );
673 if (!ntext) return FALSE;
674 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
676 ntext = COMCTL32_Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
677 if (!ntext) return FALSE;
678 strcpyW (ntext, text);
681 /* check if text is unchanged -> no need to redraw */
683 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
684 if (!isW) COMCTL32_Free(ntext);
688 if (!changed && !part->text)
693 COMCTL32_Free (part->text);
696 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
703 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR text)
705 TRACE("part %d: \"%s\"\n", id, text);
706 if (infoPtr->hwndToolTip) {
708 ti.cbSize = sizeof(TTTOOLINFOA);
709 ti.hwnd = infoPtr->Self;
713 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
722 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR text)
724 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
725 if (infoPtr->hwndToolTip) {
727 ti.cbSize = sizeof(TTTOOLINFOW);
728 ti.hwnd = infoPtr->Self;
732 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
740 inline static LRESULT
741 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, BOOL bUnicode)
743 BOOL bOld = infoPtr->bUnicode;
745 TRACE("(0x%x)\n", bUnicode);
746 infoPtr->bUnicode = bUnicode;
753 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, BOOL simple)
757 TRACE("(simple=%d)\n", simple);
758 if (infoPtr->simple == simple) /* no need to change */
761 infoPtr->simple = simple;
763 /* send notification */
764 nmhdr.hwndFrom = infoPtr->Self;
765 nmhdr.idFrom = GetWindowLongW (infoPtr->Self, GWL_ID);
766 nmhdr.code = SBN_SIMPLEMODECHANGE;
767 SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY, 0, (LPARAM)&nmhdr);
768 InvalidateRect(infoPtr->Self, NULL, FALSE);
774 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr)
779 for (i = 0; i < infoPtr->numParts; i++) {
780 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
781 COMCTL32_Free (infoPtr->parts[i].text);
783 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
784 COMCTL32_Free (infoPtr->part0.text);
785 COMCTL32_Free (infoPtr->parts);
787 /* delete default font */
788 if (infoPtr->hDefaultFont)
789 DeleteObject (infoPtr->hDefaultFont);
791 /* delete tool tip control */
792 if (infoPtr->hwndToolTip)
793 DestroyWindow (infoPtr->hwndToolTip);
795 COMCTL32_Free (infoPtr);
796 SetWindowLongW(infoPtr->Self, 0, 0);
802 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
804 STATUSWINDOWINFO *infoPtr;
805 NONCLIENTMETRICSW nclm;
808 int width, len, textHeight = 0;
812 infoPtr = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
813 if (!infoPtr) goto create_fail;
814 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
816 infoPtr->Self = hwnd;
817 infoPtr->numParts = 1;
819 infoPtr->simple = FALSE;
820 infoPtr->clrBk = CLR_DEFAULT;
823 /* FIXME: send unicode parent notification query (WM_QUERYFORMAT) here */
825 GetClientRect (hwnd, &rect);
826 InvalidateRect (hwnd, &rect, 0);
829 ZeroMemory (&nclm, sizeof(nclm));
830 nclm.cbSize = sizeof(nclm);
831 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
832 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
834 /* initialize simple case */
835 infoPtr->part0.bound = rect;
836 infoPtr->part0.text = 0;
837 infoPtr->part0.x = 0;
838 infoPtr->part0.style = 0;
839 infoPtr->part0.hIcon = 0;
841 /* initialize first part */
842 infoPtr->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
843 if (!infoPtr->parts) goto create_fail;
844 infoPtr->parts[0].bound = rect;
845 infoPtr->parts[0].text = 0;
846 infoPtr->parts[0].x = -1;
847 infoPtr->parts[0].style = 0;
848 infoPtr->parts[0].hIcon = 0;
850 if (IsWindowUnicode (hwnd)) {
851 infoPtr->bUnicode = TRUE;
852 if (lpCreate->lpszName &&
853 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
854 infoPtr->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
855 if (!infoPtr->parts[0].text) goto create_fail;
856 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
860 if (lpCreate->lpszName &&
861 (len = strlen((LPCSTR)lpCreate->lpszName))) {
862 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
863 infoPtr->parts[0].text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
864 if (!infoPtr->parts[0].text) goto create_fail;
865 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
866 infoPtr->parts[0].text, lenW );
870 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
872 /* statusbars on managed windows should not have SIZEGRIP style */
873 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
874 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
875 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
877 if ((hdc = GetDC (0))) {
881 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
882 GetTextMetricsW (hdc, &tm);
883 textHeight = tm.tmHeight;
884 SelectObject (hdc, hOldFont);
887 TRACE(" textHeight=%d\n", textHeight);
889 if (dwStyle & SBT_TOOLTIPS) {
890 infoPtr->hwndToolTip =
891 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
892 CW_USEDEFAULT, CW_USEDEFAULT,
893 CW_USEDEFAULT, CW_USEDEFAULT,
895 GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
897 if (infoPtr->hwndToolTip) {
898 NMTOOLTIPSCREATED nmttc;
900 nmttc.hdr.hwndFrom = hwnd;
901 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
902 nmttc.hdr.code = NM_TOOLTIPSCREATED;
903 nmttc.hwndToolTips = infoPtr->hwndToolTip;
905 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
906 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
910 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
911 GetClientRect (GetParent (hwnd), &rect);
912 width = rect.right - rect.left;
913 infoPtr->height = textHeight + 4 + VERT_BORDER;
914 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
915 width, infoPtr->height, SWP_NOZORDER);
916 STATUSBAR_SetPartBounds (infoPtr);
923 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
928 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
929 * of the first part only (usual behaviour) */
931 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
936 if (!(infoPtr->parts[0].text))
938 if (infoPtr->bUnicode)
939 len = strlenW (infoPtr->parts[0].text);
941 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
944 if (infoPtr->bUnicode)
945 strcpyW (buf, infoPtr->parts[0].text);
947 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
948 (LPSTR)buf, len+1, NULL, NULL );
957 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
959 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
963 GetClientRect (infoPtr->Self, &rect);
967 ScreenToClient (infoPtr->Self, &pt);
969 rect.left = rect.right - 13;
972 if (PtInRect (&rect, pt))
973 return HTBOTTOMRIGHT;
981 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
986 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
987 hdc = BeginPaint (infoPtr->Self, &ps);
988 STATUSBAR_Refresh (infoPtr, hdc);
989 EndPaint (infoPtr->Self, &ps);
996 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
998 infoPtr->hFont = font;
999 TRACE("%04x\n", infoPtr->hFont);
1001 InvalidateRect(infoPtr->Self, NULL, FALSE);
1008 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
1010 STATUSWINDOWPART *part;
1014 if (infoPtr->numParts == 0)
1017 part = &infoPtr->parts[0];
1018 /* duplicate string */
1020 COMCTL32_Free (part->text);
1022 if (infoPtr->bUnicode) {
1023 if (text && (len = strlenW((LPCWSTR)text))) {
1024 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1025 if (!part->text) return FALSE;
1026 strcpyW (part->text, (LPCWSTR)text);
1030 if (text && (len = lstrlenA(text))) {
1031 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1032 part->text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
1033 if (!part->text) return FALSE;
1034 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1038 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1045 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1050 /* Need to resize width to match parent */
1051 TRACE("flags %04x\n", flags);
1053 if (flags != SIZE_RESTORED) {
1054 WARN("flags MUST be SIZE_RESTORED\n");
1057 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1059 /* width and height don't apply */
1060 GetClientRect (GetParent(infoPtr->Self), &parent_rect);
1061 width = parent_rect.right - parent_rect.left;
1062 x = parent_rect.left;
1063 y = parent_rect.bottom - infoPtr->height;
1064 MoveWindow (infoPtr->Self, parent_rect.left,
1065 parent_rect.bottom - infoPtr->height,
1066 width, infoPtr->height, TRUE);
1067 STATUSBAR_SetPartBounds (infoPtr);
1073 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1077 TRACE("code %04x\n", code);
1078 nmhdr.hwndFrom = hwnd;
1079 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1081 SendMessageW (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1087 static LRESULT WINAPI
1088 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1090 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1091 INT nPart = ((INT) wParam) & 0x00ff;
1094 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1095 if (!infoPtr && msg != WM_CREATE)
1096 return DefWindowProcW (hwnd, msg, wParam, lParam);
1100 return STATUSBAR_GetBorders ((INT *)lParam);
1103 return STATUSBAR_GetIcon (infoPtr, nPart);
1106 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1109 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1112 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1115 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1117 case SB_GETTEXTLENGTHA:
1118 case SB_GETTEXTLENGTHW:
1119 return STATUSBAR_GetTextLength (infoPtr, nPart);
1121 case SB_GETTIPTEXTA:
1122 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1124 case SB_GETTIPTEXTW:
1125 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1127 case SB_GETUNICODEFORMAT:
1128 return infoPtr->bUnicode;
1131 return infoPtr->simple;
1134 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1137 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1139 case SB_SETMINHEIGHT:
1140 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1143 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1146 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1149 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1151 case SB_SETTIPTEXTA:
1152 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1154 case SB_SETTIPTEXTW:
1155 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1157 case SB_SETUNICODEFORMAT:
1158 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1161 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1164 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1167 return STATUSBAR_WMDestroy (infoPtr);
1170 return infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont;
1173 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1175 case WM_GETTEXTLENGTH:
1176 return STATUSBAR_GetTextLength (infoPtr, 0);
1178 case WM_LBUTTONDBLCLK:
1179 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1182 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1185 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1188 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1189 (INT)HIWORD(lParam));
1190 if (res != HTERROR) return res;
1191 return DefWindowProcW (hwnd, msg, wParam, lParam);
1193 case WM_NCLBUTTONUP:
1194 case WM_NCLBUTTONDOWN:
1195 PostMessageW (GetParent (hwnd), msg, wParam, lParam);
1199 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1201 case WM_RBUTTONDBLCLK:
1202 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1205 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1208 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1211 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1215 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1216 return DefWindowProcW (hwnd, msg, wParam, lParam);
1220 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1221 msg, wParam, lParam);
1222 return DefWindowProcW (hwnd, msg, wParam, lParam);
1228 /***********************************************************************
1229 * STATUS_Register [Internal]
1231 * Registers the status window class.
1235 STATUS_Register (void)
1239 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1240 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1241 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1242 wndClass.cbClsExtra = 0;
1243 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1244 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
1245 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1246 wndClass.lpszClassName = STATUSCLASSNAMEW;
1248 RegisterClassW (&wndClass);
1252 /***********************************************************************
1253 * STATUS_Unregister [Internal]
1255 * Unregisters the status window class.
1259 STATUS_Unregister (void)
1261 UnregisterClassW (STATUSCLASSNAMEW, (HINSTANCE)NULL);