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) Should we hide grip if the parent window is maximized?
30 #include "wine/unicode.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
54 COLORREF clrBk; /* background color */
55 BOOL bUnicode; /* unicode flag */
56 BOOL NtfUnicode; /* notify format */
57 STATUSWINDOWPART part0; /* simple window */
58 STATUSWINDOWPART* parts;
62 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
63 * The second cdrom contains executables drawstat.exe, gettext.exe,
64 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
71 #define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongW (hwnd, 0))
75 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr);
77 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
79 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
83 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
89 TRACE("draw size grip %d,%d - %d,%d\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
91 pt.x = lpRect->right - 1;
92 pt.y = lpRect->bottom - 1;
94 hOldPen = SelectObject (hdc, GetSysColorPen (COLOR_3DFACE));
95 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
96 LineTo (hdc, pt.x, pt.y);
97 LineTo (hdc, pt.x, pt.y - 13);
102 SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
103 for (i = 1; i < 11; i += 4) {
104 MoveToEx (hdc, pt.x - i, pt.y, NULL);
105 LineTo (hdc, pt.x + 1, pt.y - i - 1);
107 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
108 LineTo (hdc, pt.x + 1, pt.y - i - 2);
111 SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
112 for (i = 3; i < 13; i += 4) {
113 MoveToEx (hdc, pt.x - i, pt.y, NULL);
114 LineTo (hdc, pt.x + 1, pt.y - i - 1);
117 SelectObject (hdc, hOldPen);
122 STATUSBAR_DrawPart (HDC hdc, const STATUSWINDOWPART *part, const STATUSWINDOWINFO *infoPtr, int itemID)
124 RECT r = part->bound;
125 UINT border = BDR_SUNKENOUTER;
127 TRACE("part bound %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom);
128 if (part->style & SBT_POPOUT)
129 border = BDR_RAISEDOUTER;
130 else if (part->style & SBT_NOBORDERS)
133 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
135 if (part->style & SBT_OWNERDRAW)
139 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
141 dis.hwndItem = infoPtr->Self;
144 dis.itemData = (INT)part->text;
145 SendMessageW (GetParent (infoPtr->Self), WM_DRAWITEM,
146 (WPARAM)dis.CtlID, (LPARAM)&dis);
152 INT cy = r.bottom - r.top;
155 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
158 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
164 STATUSBAR_RefreshPart (const STATUSWINDOWINFO *infoPtr, const STATUSWINDOWPART *part, HDC hdc, int itemID)
169 TRACE("item %d\n", itemID);
170 if (!IsWindowVisible (infoPtr->Self))
173 if (part->bound.right < part->bound.left) return;
175 if (infoPtr->clrBk != CLR_DEFAULT)
176 hbrBk = CreateSolidBrush (infoPtr->clrBk);
178 hbrBk = GetSysColorBrush (COLOR_3DFACE);
179 FillRect(hdc, &part->bound, hbrBk);
181 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
183 STATUSBAR_DrawPart (hdc, part, infoPtr, itemID);
185 SelectObject (hdc, hOldFont);
187 if (infoPtr->clrBk != CLR_DEFAULT)
188 DeleteObject (hbrBk);
190 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
194 GetClientRect (infoPtr->Self, &rect);
195 STATUSBAR_DrawSizeGrip (hdc, &rect);
201 STATUSBAR_Refresh (STATUSWINDOWINFO *infoPtr, HDC hdc)
209 if (!IsWindowVisible(infoPtr->Self))
212 STATUSBAR_SetPartBounds(infoPtr);
214 GetClientRect (infoPtr->Self, &rect);
216 if (infoPtr->clrBk != CLR_DEFAULT)
217 hbrBk = CreateSolidBrush (infoPtr->clrBk);
219 hbrBk = GetSysColorBrush (COLOR_3DFACE);
220 FillRect(hdc, &rect, hbrBk);
222 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
224 if (infoPtr->simple) {
225 STATUSBAR_RefreshPart (infoPtr, &infoPtr->part0, hdc, 0);
227 for (i = 0; i < infoPtr->numParts; i++) {
228 STATUSBAR_RefreshPart (infoPtr, &infoPtr->parts[i], hdc, i);
232 SelectObject (hdc, hOldFont);
234 if (infoPtr->clrBk != CLR_DEFAULT)
235 DeleteObject (hbrBk);
237 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
238 STATUSBAR_DrawSizeGrip (hdc, &rect);
245 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr)
247 STATUSWINDOWPART *part;
251 /* get our window size */
252 GetClientRect (infoPtr->Self, &rect);
253 TRACE("client wnd size is %d,%d - %d,%d\n", rect.left, rect.top, rect.right, rect.bottom);
255 rect.top += VERT_BORDER;
257 /* set bounds for simple rectangle */
258 infoPtr->part0.bound = rect;
260 /* set bounds for non-simple rectangles */
261 for (i = 0; i < infoPtr->numParts; i++) {
262 part = &infoPtr->parts[i];
263 r = &infoPtr->parts[i].bound;
265 r->bottom = rect.bottom;
269 r->left = infoPtr->parts[i-1].bound.right + HORZ_GAP;
271 r->right = rect.right;
275 if (infoPtr->hwndToolTip) {
278 ti.cbSize = sizeof(TTTOOLINFOW);
279 ti.hwnd = infoPtr->Self;
282 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
290 STATUSBAR_Relay2Tip (STATUSWINDOWINFO *infoPtr, UINT uMsg,
291 WPARAM wParam, LPARAM lParam)
295 msg.hwnd = infoPtr->Self;
299 msg.time = GetMessageTime ();
300 msg.pt.x = LOWORD(GetMessagePos ());
301 msg.pt.y = HIWORD(GetMessagePos ());
303 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
308 STATUSBAR_GetBorders (INT out[])
311 out[0] = HORZ_BORDER; /* horizontal border width */
312 out[1] = VERT_BORDER; /* vertical border width */
313 out[2] = HORZ_GAP; /* width of border between rectangles */
320 STATUSBAR_GetIcon (STATUSWINDOWINFO *infoPtr, INT nPart)
322 TRACE("%d\n", nPart);
323 /* MSDN says: "simple parts are indexed with -1" */
324 if ((nPart < -1) || (nPart >= infoPtr->numParts))
328 return (infoPtr->part0.hIcon);
330 return (infoPtr->parts[nPart].hIcon);
335 STATUSBAR_GetParts (STATUSWINDOWINFO *infoPtr, INT num_parts, INT parts[])
339 TRACE("(%d)\n", num_parts);
341 for (i = 0; i < num_parts; i++) {
342 parts[i] = infoPtr->parts[i].x;
345 return infoPtr->numParts;
350 STATUSBAR_GetRect (STATUSWINDOWINFO *infoPtr, INT nPart, LPRECT rect)
352 TRACE("part %d\n", nPart);
354 *rect = infoPtr->part0.bound;
356 *rect = infoPtr->parts[nPart].bound;
362 STATUSBAR_GetTextA (STATUSWINDOWINFO *infoPtr, INT nPart, LPSTR buf)
364 STATUSWINDOWPART *part;
367 TRACE("part %d\n", nPart);
369 /* MSDN says: "simple parts use index of 0", so this check is ok. */
370 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
373 part = &infoPtr->part0;
375 part = &infoPtr->parts[nPart];
377 if (part->style & SBT_OWNERDRAW)
378 result = (LRESULT)part->text;
380 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
381 NULL, 0, NULL, NULL ) - 1 : 0;
382 result = MAKELONG( len, part->style );
383 if (part->text && buf)
384 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
391 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, INT nPart, LPWSTR buf)
393 STATUSWINDOWPART *part;
396 TRACE("part %d\n", nPart);
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 result = part->text ? strlenW (part->text) : 0;
408 result |= (part->style << 16);
409 if (part->text && buf)
410 strcpyW (buf, part->text);
417 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, INT nPart)
419 STATUSWINDOWPART *part;
422 TRACE("part %d\n", nPart);
424 part = &infoPtr->part0;
426 part = &infoPtr->parts[nPart];
429 result = strlenW(part->text);
433 result |= (part->style << 16);
438 STATUSBAR_GetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR tip, INT size)
442 CHAR buf[INFOTIPSIZE];
445 if (infoPtr->hwndToolTip) {
447 ti.cbSize = sizeof(TTTOOLINFOA);
448 ti.hwnd = infoPtr->Self;
451 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
453 lstrcpynA (tip, buf, size);
460 STATUSBAR_GetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR tip, INT size)
464 WCHAR buf[INFOTIPSIZE];
467 if (infoPtr->hwndToolTip) {
469 ti.cbSize = sizeof(TTTOOLINFOW);
470 ti.hwnd = infoPtr->Self;
473 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
475 lstrcpynW(tip, buf, size);
483 STATUSBAR_SetBkColor (STATUSWINDOWINFO *infoPtr, COLORREF color)
487 oldBkColor = infoPtr->clrBk;
488 infoPtr->clrBk = color;
489 InvalidateRect(infoPtr->Self, NULL, FALSE);
491 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
497 STATUSBAR_SetIcon (STATUSWINDOWINFO *infoPtr, INT nPart, HICON hIcon)
499 if ((nPart < -1) || (nPart >= infoPtr->numParts))
502 TRACE("setting part %d\n", nPart);
504 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
506 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
508 infoPtr->part0.hIcon = hIcon;
510 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
512 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
515 infoPtr->parts[nPart].hIcon = hIcon;
516 if (!(infoPtr->simple))
517 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
524 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, INT height)
527 TRACE("(height=%d)\n", height);
528 if (IsWindowVisible (infoPtr->Self)) {
532 GetClientRect (GetParent (infoPtr->Self), &parent_rect);
533 infoPtr->height = height + VERT_BORDER;
534 width = parent_rect.right - parent_rect.left;
535 x = parent_rect.left;
536 y = parent_rect.bottom - infoPtr->height;
537 MoveWindow (infoPtr->Self, parent_rect.left,
538 parent_rect.bottom - infoPtr->height,
539 width, infoPtr->height, TRUE);
540 STATUSBAR_SetPartBounds (infoPtr);
548 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, INT count, LPINT parts)
550 STATUSWINDOWPART *tmp;
553 TRACE("(%d,%p)\n", count, parts);
555 oldNumParts = infoPtr->numParts;
556 infoPtr->numParts = count;
557 if (oldNumParts > infoPtr->numParts) {
558 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
559 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
560 COMCTL32_Free (infoPtr->parts[i].text);
562 } else if (oldNumParts < infoPtr->numParts) {
563 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
564 if (!tmp) return FALSE;
565 for (i = 0; i < oldNumParts; i++) {
566 tmp[i] = infoPtr->parts[i];
569 COMCTL32_Free (infoPtr->parts);
570 infoPtr->parts = tmp;
572 if (oldNumParts == infoPtr->numParts) {
573 for (i=0; i < oldNumParts; i++)
574 if (infoPtr->parts[i].x != parts[i])
576 if (i==oldNumParts) /* Unchanged? no need to redraw! */
580 for (i = 0; i < infoPtr->numParts; i++)
581 infoPtr->parts[i].x = parts[i];
583 if (infoPtr->hwndToolTip) {
587 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
588 ti.cbSize = sizeof(TTTOOLINFOW);
589 ti.hwnd = infoPtr->Self;
591 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
592 if (nTipCount < infoPtr->numParts) {
594 for (i = nTipCount; i < infoPtr->numParts; i++) {
595 TRACE("add tool %d\n", i);
597 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
601 else if (nTipCount > infoPtr->numParts) {
603 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
604 TRACE("delete tool %d\n", i);
606 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
611 STATUSBAR_SetPartBounds (infoPtr);
612 InvalidateRect(infoPtr->Self, NULL, FALSE);
618 STATUSBAR_SetTextT (STATUSWINDOWINFO *infoPtr, INT nPart, WORD style,
619 LPCWSTR text, BOOL isW)
621 STATUSWINDOWPART *part=NULL;
622 BOOL changed = FALSE;
624 TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
626 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
627 * window is assumed to be a simple window */
629 if (nPart == 0x00ff) {
630 part = &infoPtr->part0;
632 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
633 part = &infoPtr->parts[nPart];
636 if (!part) return FALSE;
638 if (part->style != style)
642 if (style & SBT_OWNERDRAW) {
643 if (part->text == text)
645 part->text = (LPWSTR)text;
650 LPCSTR atxt = (LPCSTR)text;
651 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
652 ntext = COMCTL32_Alloc( (len + 1)*sizeof(WCHAR) );
653 if (!ntext) return FALSE;
654 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
656 ntext = COMCTL32_Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
657 if (!ntext) return FALSE;
658 strcpyW (ntext, text);
661 /* check if text is unchanged -> no need to redraw */
663 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
664 if (!isW) COMCTL32_Free(ntext);
668 if (!changed && !part->text)
673 COMCTL32_Free (part->text);
676 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
683 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR text)
685 TRACE("part %d: \"%s\"\n", id, text);
686 if (infoPtr->hwndToolTip) {
688 ti.cbSize = sizeof(TTTOOLINFOA);
689 ti.hwnd = infoPtr->Self;
693 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
702 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR text)
704 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
705 if (infoPtr->hwndToolTip) {
707 ti.cbSize = sizeof(TTTOOLINFOW);
708 ti.hwnd = infoPtr->Self;
712 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
720 inline static LRESULT
721 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, BOOL bUnicode)
723 BOOL bOld = infoPtr->bUnicode;
725 TRACE("(0x%x)\n", bUnicode);
726 infoPtr->bUnicode = bUnicode;
733 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, BOOL simple)
737 TRACE("(simple=%d)\n", simple);
738 if (infoPtr->simple == simple) /* no need to change */
741 infoPtr->simple = simple;
743 /* send notification */
744 nmhdr.hwndFrom = infoPtr->Self;
745 nmhdr.idFrom = GetWindowLongW (infoPtr->Self, GWL_ID);
746 nmhdr.code = SBN_SIMPLEMODECHANGE;
747 SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY, 0, (LPARAM)&nmhdr);
748 InvalidateRect(infoPtr->Self, NULL, FALSE);
754 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr)
759 for (i = 0; i < infoPtr->numParts; i++) {
760 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
761 COMCTL32_Free (infoPtr->parts[i].text);
763 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
764 COMCTL32_Free (infoPtr->part0.text);
765 COMCTL32_Free (infoPtr->parts);
767 /* delete default font */
768 if (infoPtr->hDefaultFont)
769 DeleteObject (infoPtr->hDefaultFont);
771 /* delete tool tip control */
772 if (infoPtr->hwndToolTip)
773 DestroyWindow (infoPtr->hwndToolTip);
775 COMCTL32_Free (infoPtr);
776 SetWindowLongW(infoPtr->Self, 0, 0);
782 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
784 STATUSWINDOWINFO *infoPtr;
785 NONCLIENTMETRICSW nclm;
788 int i, width, len, textHeight = 0;
792 infoPtr = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
793 if (!infoPtr) goto create_fail;
794 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
796 infoPtr->Self = hwnd;
797 infoPtr->numParts = 1;
799 infoPtr->simple = FALSE;
800 infoPtr->clrBk = CLR_DEFAULT;
803 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, hwnd, NF_QUERY);
804 infoPtr->NtfUnicode = (i == NFR_UNICODE);
806 GetClientRect (hwnd, &rect);
807 InvalidateRect (hwnd, &rect, 0);
810 ZeroMemory (&nclm, sizeof(nclm));
811 nclm.cbSize = sizeof(nclm);
812 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
813 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
815 /* initialize simple case */
816 infoPtr->part0.bound = rect;
817 infoPtr->part0.text = 0;
818 infoPtr->part0.x = 0;
819 infoPtr->part0.style = 0;
820 infoPtr->part0.hIcon = 0;
822 /* initialize first part */
823 infoPtr->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
824 if (!infoPtr->parts) goto create_fail;
825 infoPtr->parts[0].bound = rect;
826 infoPtr->parts[0].text = 0;
827 infoPtr->parts[0].x = -1;
828 infoPtr->parts[0].style = 0;
829 infoPtr->parts[0].hIcon = 0;
831 if (IsWindowUnicode (hwnd)) {
832 infoPtr->bUnicode = TRUE;
833 if (lpCreate->lpszName &&
834 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
835 infoPtr->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
836 if (!infoPtr->parts[0].text) goto create_fail;
837 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
841 if (lpCreate->lpszName &&
842 (len = strlen((LPCSTR)lpCreate->lpszName))) {
843 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
844 infoPtr->parts[0].text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
845 if (!infoPtr->parts[0].text) goto create_fail;
846 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
847 infoPtr->parts[0].text, lenW );
851 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
853 /* statusbars on managed windows should not have SIZEGRIP style */
854 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
855 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
856 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
858 if ((hdc = GetDC (0))) {
862 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
863 GetTextMetricsW (hdc, &tm);
864 textHeight = tm.tmHeight;
865 SelectObject (hdc, hOldFont);
868 TRACE(" textHeight=%d\n", textHeight);
870 if (dwStyle & SBT_TOOLTIPS) {
871 infoPtr->hwndToolTip =
872 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
873 CW_USEDEFAULT, CW_USEDEFAULT,
874 CW_USEDEFAULT, CW_USEDEFAULT,
876 GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
878 if (infoPtr->hwndToolTip) {
879 NMTOOLTIPSCREATED nmttc;
881 nmttc.hdr.hwndFrom = hwnd;
882 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
883 nmttc.hdr.code = NM_TOOLTIPSCREATED;
884 nmttc.hwndToolTips = infoPtr->hwndToolTip;
886 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
887 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
891 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
892 GetClientRect (GetParent (hwnd), &rect);
893 width = rect.right - rect.left;
894 infoPtr->height = textHeight + 4 + VERT_BORDER;
895 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
896 width, infoPtr->height, SWP_NOZORDER);
897 STATUSBAR_SetPartBounds (infoPtr);
904 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
909 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
910 * of the first part only (usual behaviour) */
912 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
917 if (!(infoPtr->parts[0].text))
919 if (infoPtr->bUnicode)
920 len = strlenW (infoPtr->parts[0].text);
922 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
925 if (infoPtr->bUnicode)
926 strcpyW (buf, infoPtr->parts[0].text);
928 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
929 (LPSTR)buf, len+1, NULL, NULL );
938 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
940 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
944 GetClientRect (infoPtr->Self, &rect);
948 ScreenToClient (infoPtr->Self, &pt);
950 rect.left = rect.right - 13;
953 if (PtInRect (&rect, pt))
954 return HTBOTTOMRIGHT;
962 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
967 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
968 hdc = BeginPaint (infoPtr->Self, &ps);
969 STATUSBAR_Refresh (infoPtr, hdc);
970 EndPaint (infoPtr->Self, &ps);
977 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
979 infoPtr->hFont = font;
980 TRACE("%04x\n", infoPtr->hFont);
982 InvalidateRect(infoPtr->Self, NULL, FALSE);
989 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
991 STATUSWINDOWPART *part;
995 if (infoPtr->numParts == 0)
998 part = &infoPtr->parts[0];
999 /* duplicate string */
1001 COMCTL32_Free (part->text);
1003 if (infoPtr->bUnicode) {
1004 if (text && (len = strlenW((LPCWSTR)text))) {
1005 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1006 if (!part->text) return FALSE;
1007 strcpyW (part->text, (LPCWSTR)text);
1011 if (text && (len = lstrlenA(text))) {
1012 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1013 part->text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
1014 if (!part->text) return FALSE;
1015 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1019 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1026 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1031 /* Need to resize width to match parent */
1032 TRACE("flags %04x\n", flags);
1034 if (flags != SIZE_RESTORED) {
1035 WARN("flags MUST be SIZE_RESTORED\n");
1038 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1040 /* width and height don't apply */
1041 GetClientRect (GetParent(infoPtr->Self), &parent_rect);
1042 width = parent_rect.right - parent_rect.left;
1043 x = parent_rect.left;
1044 y = parent_rect.bottom - infoPtr->height;
1045 MoveWindow (infoPtr->Self, parent_rect.left,
1046 parent_rect.bottom - infoPtr->height,
1047 width, infoPtr->height, TRUE);
1048 STATUSBAR_SetPartBounds (infoPtr);
1054 STATUSBAR_NotifyFormat (STATUSWINDOWINFO *infoPtr, HWND from, INT cmd)
1056 if (cmd == NF_REQUERY) {
1057 INT i = SendMessageW(from, WM_NOTIFYFORMAT, infoPtr->Self, NF_QUERY);
1058 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1060 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1065 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1069 TRACE("code %04x\n", code);
1070 nmhdr.hwndFrom = hwnd;
1071 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1073 SendMessageW (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1079 static LRESULT WINAPI
1080 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1082 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1083 INT nPart = ((INT) wParam) & 0x00ff;
1086 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1087 if (!infoPtr && msg != WM_CREATE)
1088 return DefWindowProcW (hwnd, msg, wParam, lParam);
1092 return STATUSBAR_GetBorders ((INT *)lParam);
1095 return STATUSBAR_GetIcon (infoPtr, nPart);
1098 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1101 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1104 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1107 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1109 case SB_GETTEXTLENGTHA:
1110 case SB_GETTEXTLENGTHW:
1111 return STATUSBAR_GetTextLength (infoPtr, nPart);
1113 case SB_GETTIPTEXTA:
1114 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1116 case SB_GETTIPTEXTW:
1117 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1119 case SB_GETUNICODEFORMAT:
1120 return infoPtr->bUnicode;
1123 return infoPtr->simple;
1126 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1129 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1131 case SB_SETMINHEIGHT:
1132 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1135 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1138 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1141 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1143 case SB_SETTIPTEXTA:
1144 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1146 case SB_SETTIPTEXTW:
1147 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1149 case SB_SETUNICODEFORMAT:
1150 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1153 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1156 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1159 return STATUSBAR_WMDestroy (infoPtr);
1162 return infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont;
1165 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1167 case WM_GETTEXTLENGTH:
1168 return STATUSBAR_GetTextLength (infoPtr, 0);
1170 case WM_LBUTTONDBLCLK:
1171 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1174 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1177 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1180 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1181 (INT)HIWORD(lParam));
1182 if (res != HTERROR) return res;
1183 return DefWindowProcW (hwnd, msg, wParam, lParam);
1185 case WM_NCLBUTTONUP:
1186 case WM_NCLBUTTONDOWN:
1187 PostMessageW (GetParent (hwnd), msg, wParam, lParam);
1190 case WM_NOTIFYFORMAT:
1191 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1194 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1196 case WM_RBUTTONDBLCLK:
1197 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1200 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1203 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1206 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1209 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1210 return DefWindowProcW (hwnd, msg, wParam, lParam);
1214 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1215 msg, wParam, lParam);
1216 return DefWindowProcW (hwnd, msg, wParam, lParam);
1222 /***********************************************************************
1223 * STATUS_Register [Internal]
1225 * Registers the status window class.
1229 STATUS_Register (void)
1233 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1234 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1235 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1236 wndClass.cbClsExtra = 0;
1237 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1238 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
1239 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1240 wndClass.lpszClassName = STATUSCLASSNAMEW;
1242 RegisterClassW (&wndClass);
1246 /***********************************************************************
1247 * STATUS_Unregister [Internal]
1249 * Unregisters the status window class.
1253 STATUS_Unregister (void)
1255 UnregisterClassW (STATUSCLASSNAMEW, (HINSTANCE)NULL);