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, STATUSWINDOWPART *part)
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);
136 INT cy = r.bottom - r.top;
139 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
143 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
148 STATUSBAR_RefreshPart (STATUSWINDOWINFO *infoPtr, STATUSWINDOWPART *part, HDC hdc, int itemID)
153 TRACE("item %d\n", itemID);
154 if (!IsWindowVisible (infoPtr->Self))
157 if (part->bound.right < part->bound.left) return;
159 if (infoPtr->clrBk != CLR_DEFAULT)
160 hbrBk = CreateSolidBrush (infoPtr->clrBk);
162 hbrBk = GetSysColorBrush (COLOR_3DFACE);
163 FillRect(hdc, &part->bound, hbrBk);
165 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
167 if (part->style & SBT_OWNERDRAW) {
170 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
172 dis.hwndItem = infoPtr->Self;
174 dis.rcItem = part->bound;
175 dis.itemData = (INT)part->text;
176 SendMessageW (GetParent (infoPtr->Self), WM_DRAWITEM,
177 (WPARAM)dis.CtlID, (LPARAM)&dis);
179 STATUSBAR_DrawPart (hdc, part);
181 SelectObject (hdc, hOldFont);
183 if (infoPtr->clrBk != CLR_DEFAULT)
184 DeleteObject (hbrBk);
186 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
189 GetClientRect (infoPtr->Self, &rect);
190 STATUSBAR_DrawSizeGrip (hdc, &rect);
196 STATUSBAR_Refresh (STATUSWINDOWINFO *infoPtr, HDC hdc)
204 if (!IsWindowVisible(infoPtr->Self))
207 STATUSBAR_SetPartBounds(infoPtr);
209 GetClientRect (infoPtr->Self, &rect);
211 if (infoPtr->clrBk != CLR_DEFAULT)
212 hbrBk = CreateSolidBrush (infoPtr->clrBk);
214 hbrBk = GetSysColorBrush (COLOR_3DFACE);
215 FillRect(hdc, &rect, hbrBk);
217 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
219 if (infoPtr->simple) {
220 STATUSBAR_RefreshPart (infoPtr, &infoPtr->part0, hdc, 0);
222 for (i = 0; i < infoPtr->numParts; i++) {
223 if (infoPtr->parts[i].style & SBT_OWNERDRAW) {
226 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
228 dis.hwndItem = infoPtr->Self;
230 dis.rcItem = infoPtr->parts[i].bound;
231 dis.itemData = (INT)infoPtr->parts[i].text;
232 SendMessageW (GetParent (infoPtr->Self), WM_DRAWITEM,
233 (WPARAM)dis.CtlID, (LPARAM)&dis);
235 STATUSBAR_RefreshPart (infoPtr, &infoPtr->parts[i], hdc, i);
239 SelectObject (hdc, hOldFont);
241 if (infoPtr->clrBk != CLR_DEFAULT)
242 DeleteObject (hbrBk);
244 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
245 STATUSBAR_DrawSizeGrip (hdc, &rect);
252 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr)
254 STATUSWINDOWPART *part;
258 /* get our window size */
259 GetClientRect (infoPtr->Self, &rect);
260 TRACE("client wnd size is %d,%d - %d,%d\n", rect.left, rect.top, rect.right, rect.bottom);
262 rect.top += VERT_BORDER;
264 /* set bounds for simple rectangle */
265 infoPtr->part0.bound = rect;
267 /* set bounds for non-simple rectangles */
268 for (i = 0; i < infoPtr->numParts; i++) {
269 part = &infoPtr->parts[i];
270 r = &infoPtr->parts[i].bound;
272 r->bottom = rect.bottom;
276 r->left = infoPtr->parts[i-1].bound.right + HORZ_GAP;
278 r->right = rect.right;
282 if (infoPtr->hwndToolTip) {
285 ti.cbSize = sizeof(TTTOOLINFOW);
286 ti.hwnd = infoPtr->Self;
289 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
297 STATUSBAR_Relay2Tip (STATUSWINDOWINFO *infoPtr, UINT uMsg,
298 WPARAM wParam, LPARAM lParam)
302 msg.hwnd = infoPtr->Self;
306 msg.time = GetMessageTime ();
307 msg.pt.x = LOWORD(GetMessagePos ());
308 msg.pt.y = HIWORD(GetMessagePos ());
310 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
315 STATUSBAR_GetBorders (INT out[])
318 out[0] = HORZ_BORDER; /* horizontal border width */
319 out[1] = VERT_BORDER; /* vertical border width */
320 out[2] = HORZ_GAP; /* width of border between rectangles */
327 STATUSBAR_GetIcon (STATUSWINDOWINFO *infoPtr, INT nPart)
329 TRACE("%d\n", nPart);
330 if ((nPart < -1) || (nPart >= infoPtr->numParts))
334 return (infoPtr->part0.hIcon);
336 return (infoPtr->parts[nPart].hIcon);
341 STATUSBAR_GetParts (STATUSWINDOWINFO *infoPtr, INT num_parts, INT parts[])
345 TRACE("(%d)\n", num_parts);
347 for (i = 0; i < num_parts; i++) {
348 parts[i] = infoPtr->parts[i].x;
351 return infoPtr->numParts;
356 STATUSBAR_GetRect (STATUSWINDOWINFO *infoPtr, INT nPart, LPRECT rect)
358 TRACE("part %d\n", nPart);
360 *rect = infoPtr->part0.bound;
362 *rect = infoPtr->parts[nPart].bound;
368 STATUSBAR_GetTextA (STATUSWINDOWINFO *infoPtr, INT nPart, LPSTR buf)
370 STATUSWINDOWPART *part;
373 TRACE("part %d\n", nPart);
374 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
377 part = &infoPtr->part0;
379 part = &infoPtr->parts[nPart];
381 if (part->style & SBT_OWNERDRAW)
382 result = (LRESULT)part->text;
384 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
385 NULL, 0, NULL, NULL ) - 1 : 0;
386 result = MAKELONG( len, part->style );
387 if (part->text && buf)
388 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
395 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, INT nPart, LPWSTR buf)
397 STATUSWINDOWPART *part;
400 TRACE("part %d\n", nPart);
401 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
404 part = &infoPtr->part0;
406 part = &infoPtr->parts[nPart];
408 if (part->style & SBT_OWNERDRAW)
409 result = (LRESULT)part->text;
411 result = part->text ? strlenW (part->text) : 0;
412 result |= (part->style << 16);
413 if (part->text && buf)
414 strcpyW (buf, part->text);
421 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, INT nPart)
423 STATUSWINDOWPART *part;
426 TRACE("part %d\n", nPart);
428 part = &infoPtr->part0;
430 part = &infoPtr->parts[nPart];
433 result = strlenW(part->text);
437 result |= (part->style << 16);
442 STATUSBAR_GetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR tip, INT size)
446 CHAR buf[INFOTIPSIZE];
449 if (infoPtr->hwndToolTip) {
451 ti.cbSize = sizeof(TTTOOLINFOA);
452 ti.hwnd = infoPtr->Self;
455 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
457 lstrcpynA (tip, buf, size);
464 STATUSBAR_GetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR tip, INT size)
468 WCHAR buf[INFOTIPSIZE];
471 if (infoPtr->hwndToolTip) {
473 ti.cbSize = sizeof(TTTOOLINFOW);
474 ti.hwnd = infoPtr->Self;
477 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
479 lstrcpynW(tip, buf, size);
487 STATUSBAR_SetBkColor (STATUSWINDOWINFO *infoPtr, COLORREF color)
491 oldBkColor = infoPtr->clrBk;
492 infoPtr->clrBk = color;
493 InvalidateRect(infoPtr->Self, NULL, FALSE);
495 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
501 STATUSBAR_SetIcon (STATUSWINDOWINFO *infoPtr, INT nPart, HICON hIcon)
503 if ((nPart < -1) || (nPart >= infoPtr->numParts))
506 TRACE("setting part %d\n", nPart);
509 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
511 infoPtr->part0.hIcon = hIcon;
513 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
515 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
518 infoPtr->parts[nPart].hIcon = hIcon;
519 if (!(infoPtr->simple))
520 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
527 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, INT height)
530 TRACE("(height=%d)\n", height);
531 if (IsWindowVisible (infoPtr->Self)) {
535 GetClientRect (GetParent (infoPtr->Self), &parent_rect);
536 infoPtr->height = height + VERT_BORDER;
537 width = parent_rect.right - parent_rect.left;
538 x = parent_rect.left;
539 y = parent_rect.bottom - infoPtr->height;
540 MoveWindow (infoPtr->Self, parent_rect.left,
541 parent_rect.bottom - infoPtr->height,
542 width, infoPtr->height, TRUE);
543 STATUSBAR_SetPartBounds (infoPtr);
551 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, INT count, LPINT parts)
553 STATUSWINDOWPART *tmp;
556 TRACE("(%d,%p)\n", count, parts);
558 oldNumParts = infoPtr->numParts;
559 infoPtr->numParts = count;
560 if (oldNumParts > infoPtr->numParts) {
561 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
562 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
563 COMCTL32_Free (infoPtr->parts[i].text);
565 } else if (oldNumParts < infoPtr->numParts) {
566 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
567 if (!tmp) return FALSE;
568 for (i = 0; i < oldNumParts; i++) {
569 tmp[i] = infoPtr->parts[i];
572 COMCTL32_Free (infoPtr->parts);
573 infoPtr->parts = tmp;
575 if (oldNumParts == infoPtr->numParts) {
576 for (i=0; i < oldNumParts; i++)
577 if (infoPtr->parts[i].x != parts[i])
579 if (i==oldNumParts) /* Unchanged? no need to redraw! */
583 for (i = 0; i < infoPtr->numParts; i++)
584 infoPtr->parts[i].x = parts[i];
586 if (infoPtr->hwndToolTip) {
590 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
591 ti.cbSize = sizeof(TTTOOLINFOW);
592 ti.hwnd = infoPtr->Self;
594 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
595 if (nTipCount < infoPtr->numParts) {
597 for (i = nTipCount; i < infoPtr->numParts; i++) {
598 TRACE("add tool %d\n", i);
600 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
604 else if (nTipCount > infoPtr->numParts) {
606 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
607 TRACE("delete tool %d\n", i);
609 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
614 STATUSBAR_SetPartBounds (infoPtr);
615 InvalidateRect(infoPtr->Self, NULL, FALSE);
621 STATUSBAR_SetTextT (STATUSWINDOWINFO *infoPtr, INT nPart, WORD style,
622 LPCWSTR text, BOOL isW)
624 STATUSWINDOWPART *part=NULL;
625 BOOL changed = FALSE;
627 TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
628 if (nPart < 0 || nPart >= infoPtr->numParts) return FALSE;
631 part = &infoPtr->part0;
632 else if (!infoPtr->simple && infoPtr->parts)
633 part = &infoPtr->parts[nPart];
634 if (!part) return FALSE;
636 if (part->style != style)
640 if (style & SBT_OWNERDRAW) {
641 if (part->text == text)
643 part->text = (LPWSTR)text;
648 LPCSTR atxt = (LPCSTR)text;
649 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
650 ntext = COMCTL32_Alloc( (len + 1)*sizeof(WCHAR) );
651 if (!ntext) return FALSE;
652 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
654 ntext = COMCTL32_Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
655 if (!ntext) return FALSE;
656 strcpyW (ntext, text);
659 /* check if text is unchanged -> no need to redraw */
661 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
662 if (!isW) COMCTL32_Free(ntext);
666 if (!changed && !part->text)
671 COMCTL32_Free (part->text);
674 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
681 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR text)
683 TRACE("part %d: \"%s\"\n", id, text);
684 if (infoPtr->hwndToolTip) {
686 ti.cbSize = sizeof(TTTOOLINFOA);
687 ti.hwnd = infoPtr->Self;
691 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
700 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR text)
702 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
703 if (infoPtr->hwndToolTip) {
705 ti.cbSize = sizeof(TTTOOLINFOW);
706 ti.hwnd = infoPtr->Self;
710 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
718 inline static LRESULT
719 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, BOOL bUnicode)
721 BOOL bOld = infoPtr->bUnicode;
723 TRACE("(0x%x)\n", bUnicode);
724 infoPtr->bUnicode = bUnicode;
731 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, BOOL simple)
735 TRACE("(simple=%d)\n", simple);
736 if (infoPtr->simple == simple) /* no need to change */
739 infoPtr->simple = simple;
741 /* send notification */
742 nmhdr.hwndFrom = infoPtr->Self;
743 nmhdr.idFrom = GetWindowLongW (infoPtr->Self, GWL_ID);
744 nmhdr.code = SBN_SIMPLEMODECHANGE;
745 SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY, 0, (LPARAM)&nmhdr);
746 InvalidateRect(infoPtr->Self, NULL, FALSE);
752 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr)
757 for (i = 0; i < infoPtr->numParts; i++) {
758 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
759 COMCTL32_Free (infoPtr->parts[i].text);
761 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
762 COMCTL32_Free (infoPtr->part0.text);
763 COMCTL32_Free (infoPtr->parts);
765 /* delete default font */
766 if (infoPtr->hDefaultFont)
767 DeleteObject (infoPtr->hDefaultFont);
769 /* delete tool tip control */
770 if (infoPtr->hwndToolTip)
771 DestroyWindow (infoPtr->hwndToolTip);
773 COMCTL32_Free (infoPtr);
774 SetWindowLongW(infoPtr->Self, 0, 0);
780 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
782 STATUSWINDOWINFO *infoPtr;
783 NONCLIENTMETRICSW nclm;
786 int i, width, len, textHeight = 0;
790 infoPtr = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
791 if (!infoPtr) goto create_fail;
792 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
794 infoPtr->Self = hwnd;
795 infoPtr->numParts = 1;
797 infoPtr->simple = FALSE;
798 infoPtr->clrBk = CLR_DEFAULT;
801 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, hwnd, NF_QUERY);
802 infoPtr->NtfUnicode = (i == NFR_UNICODE);
804 GetClientRect (hwnd, &rect);
805 InvalidateRect (hwnd, &rect, 0);
808 ZeroMemory (&nclm, sizeof(nclm));
809 nclm.cbSize = sizeof(nclm);
810 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
811 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
813 /* initialize simple case */
814 infoPtr->part0.bound = rect;
815 infoPtr->part0.text = 0;
816 infoPtr->part0.x = 0;
817 infoPtr->part0.style = 0;
818 infoPtr->part0.hIcon = 0;
820 /* initialize first part */
821 infoPtr->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
822 if (!infoPtr->parts) goto create_fail;
823 infoPtr->parts[0].bound = rect;
824 infoPtr->parts[0].text = 0;
825 infoPtr->parts[0].x = -1;
826 infoPtr->parts[0].style = 0;
827 infoPtr->parts[0].hIcon = 0;
829 if (IsWindowUnicode (hwnd)) {
830 infoPtr->bUnicode = TRUE;
831 if (lpCreate->lpszName &&
832 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
833 infoPtr->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
834 if (!infoPtr->parts[0].text) goto create_fail;
835 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
839 if (lpCreate->lpszName &&
840 (len = strlen((LPCSTR)lpCreate->lpszName))) {
841 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
842 infoPtr->parts[0].text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
843 if (!infoPtr->parts[0].text) goto create_fail;
844 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
845 infoPtr->parts[0].text, lenW );
849 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
851 /* statusbars on managed windows should not have SIZEGRIP style */
852 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
853 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
854 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
856 if ((hdc = GetDC (0))) {
860 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
861 GetTextMetricsW (hdc, &tm);
862 textHeight = tm.tmHeight;
863 SelectObject (hdc, hOldFont);
866 TRACE(" textHeight=%d\n", textHeight);
868 if (dwStyle & SBT_TOOLTIPS) {
869 infoPtr->hwndToolTip =
870 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
871 CW_USEDEFAULT, CW_USEDEFAULT,
872 CW_USEDEFAULT, CW_USEDEFAULT,
874 GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
876 if (infoPtr->hwndToolTip) {
877 NMTOOLTIPSCREATED nmttc;
879 nmttc.hdr.hwndFrom = hwnd;
880 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
881 nmttc.hdr.code = NM_TOOLTIPSCREATED;
882 nmttc.hwndToolTips = infoPtr->hwndToolTip;
884 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
885 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
889 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
890 GetClientRect (GetParent (hwnd), &rect);
891 width = rect.right - rect.left;
892 infoPtr->height = textHeight + 4 + VERT_BORDER;
893 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
894 width, infoPtr->height, SWP_NOZORDER);
895 STATUSBAR_SetPartBounds (infoPtr);
902 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
907 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
908 * of the first part only (usual behaviour) */
910 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
915 if (!(infoPtr->parts[0].text))
917 if (infoPtr->bUnicode)
918 len = strlenW (infoPtr->parts[0].text);
920 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
923 if (infoPtr->bUnicode)
924 strcpyW (buf, infoPtr->parts[0].text);
926 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
927 (LPSTR)buf, len+1, NULL, NULL );
936 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
938 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
942 GetClientRect (infoPtr->Self, &rect);
946 ScreenToClient (infoPtr->Self, &pt);
948 rect.left = rect.right - 13;
951 if (PtInRect (&rect, pt))
952 return HTBOTTOMRIGHT;
960 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
965 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
966 hdc = BeginPaint (infoPtr->Self, &ps);
967 STATUSBAR_Refresh (infoPtr, hdc);
968 EndPaint (infoPtr->Self, &ps);
975 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
977 infoPtr->hFont = font;
978 TRACE("%04x\n", infoPtr->hFont);
980 InvalidateRect(infoPtr->Self, NULL, FALSE);
987 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
989 STATUSWINDOWPART *part;
993 if (infoPtr->numParts == 0)
996 part = &infoPtr->parts[0];
997 /* duplicate string */
999 COMCTL32_Free (part->text);
1001 if (infoPtr->bUnicode) {
1002 if (text && (len = strlenW((LPCWSTR)text))) {
1003 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1004 if (!part->text) return FALSE;
1005 strcpyW (part->text, (LPCWSTR)text);
1009 if (text && (len = lstrlenA(text))) {
1010 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1011 part->text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
1012 if (!part->text) return FALSE;
1013 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1017 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1024 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1029 /* Need to resize width to match parent */
1030 TRACE("flags %04x\n", flags);
1032 if (flags != SIZE_RESTORED) {
1033 WARN("flags MUST be SIZE_RESTORED\n");
1036 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1038 /* width and height don't apply */
1039 GetClientRect (GetParent(infoPtr->Self), &parent_rect);
1040 width = parent_rect.right - parent_rect.left;
1041 x = parent_rect.left;
1042 y = parent_rect.bottom - infoPtr->height;
1043 MoveWindow (infoPtr->Self, parent_rect.left,
1044 parent_rect.bottom - infoPtr->height,
1045 width, infoPtr->height, TRUE);
1046 STATUSBAR_SetPartBounds (infoPtr);
1052 STATUSBAR_NotifyFormat (STATUSWINDOWINFO *infoPtr, HWND from, INT cmd)
1054 if (cmd == NF_REQUERY) {
1055 INT i = SendMessageW(from, WM_NOTIFYFORMAT, infoPtr->Self, NF_QUERY);
1056 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1058 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1063 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1067 TRACE("code %04x\n", code);
1068 nmhdr.hwndFrom = hwnd;
1069 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1071 SendMessageW (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1077 static LRESULT WINAPI
1078 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1080 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1081 INT nPart = ((INT) wParam) & 0x00ff;
1084 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1085 if (!infoPtr && msg != WM_CREATE)
1086 return DefWindowProcW (hwnd, msg, wParam, lParam);
1090 return STATUSBAR_GetBorders ((INT *)lParam);
1093 return STATUSBAR_GetIcon (infoPtr, nPart);
1096 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1099 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1102 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1105 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1107 case SB_GETTEXTLENGTHA:
1108 case SB_GETTEXTLENGTHW:
1109 return STATUSBAR_GetTextLength (infoPtr, nPart);
1111 case SB_GETTIPTEXTA:
1112 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1114 case SB_GETTIPTEXTW:
1115 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1117 case SB_GETUNICODEFORMAT:
1118 return infoPtr->bUnicode;
1121 return infoPtr->simple;
1124 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1127 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1129 case SB_SETMINHEIGHT:
1130 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1133 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1136 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1139 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1141 case SB_SETTIPTEXTA:
1142 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1144 case SB_SETTIPTEXTW:
1145 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1147 case SB_SETUNICODEFORMAT:
1148 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1151 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1154 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1157 return STATUSBAR_WMDestroy (infoPtr);
1160 return infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont;
1163 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1165 case WM_GETTEXTLENGTH:
1166 return STATUSBAR_GetTextLength (infoPtr, 0);
1168 case WM_LBUTTONDBLCLK:
1169 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1172 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1175 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1178 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1179 (INT)HIWORD(lParam));
1180 if (res != HTERROR) return res;
1181 return DefWindowProcW (hwnd, msg, wParam, lParam);
1183 case WM_NCLBUTTONUP:
1184 case WM_NCLBUTTONDOWN:
1185 PostMessageW (GetParent (hwnd), msg, wParam, lParam);
1188 case WM_NOTIFYFORMAT:
1189 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1192 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1194 case WM_RBUTTONDBLCLK:
1195 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1198 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1201 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1204 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1207 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1208 return DefWindowProcW (hwnd, msg, wParam, lParam);
1212 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1213 msg, wParam, lParam);
1214 return DefWindowProcW (hwnd, msg, wParam, lParam);
1220 /***********************************************************************
1221 * STATUS_Register [Internal]
1223 * Registers the status window class.
1227 STATUS_Register (void)
1231 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1232 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1233 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1234 wndClass.cbClsExtra = 0;
1235 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1236 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
1237 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1238 wndClass.lpszClassName = STATUSCLASSNAMEW;
1240 RegisterClassW (&wndClass);
1244 /***********************************************************************
1245 * STATUS_Unregister [Internal]
1247 * Unregisters the status window class.
1251 STATUS_Unregister (void)
1253 UnregisterClassW (STATUSCLASSNAMEW, (HINSTANCE)NULL);