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 /* MSDN says: "simple parts are indexed with -1" */
331 if ((nPart < -1) || (nPart >= infoPtr->numParts))
335 return (infoPtr->part0.hIcon);
337 return (infoPtr->parts[nPart].hIcon);
342 STATUSBAR_GetParts (STATUSWINDOWINFO *infoPtr, INT num_parts, INT parts[])
346 TRACE("(%d)\n", num_parts);
348 for (i = 0; i < num_parts; i++) {
349 parts[i] = infoPtr->parts[i].x;
352 return infoPtr->numParts;
357 STATUSBAR_GetRect (STATUSWINDOWINFO *infoPtr, INT nPart, LPRECT rect)
359 TRACE("part %d\n", nPart);
361 *rect = infoPtr->part0.bound;
363 *rect = infoPtr->parts[nPart].bound;
369 STATUSBAR_GetTextA (STATUSWINDOWINFO *infoPtr, INT nPart, LPSTR buf)
371 STATUSWINDOWPART *part;
374 TRACE("part %d\n", nPart);
376 /* MSDN says: "simple parts use index of 0", so this check is ok. */
377 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
380 part = &infoPtr->part0;
382 part = &infoPtr->parts[nPart];
384 if (part->style & SBT_OWNERDRAW)
385 result = (LRESULT)part->text;
387 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
388 NULL, 0, NULL, NULL ) - 1 : 0;
389 result = MAKELONG( len, part->style );
390 if (part->text && buf)
391 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
398 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, INT nPart, LPWSTR buf)
400 STATUSWINDOWPART *part;
403 TRACE("part %d\n", nPart);
404 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
407 part = &infoPtr->part0;
409 part = &infoPtr->parts[nPart];
411 if (part->style & SBT_OWNERDRAW)
412 result = (LRESULT)part->text;
414 result = part->text ? strlenW (part->text) : 0;
415 result |= (part->style << 16);
416 if (part->text && buf)
417 strcpyW (buf, part->text);
424 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, INT nPart)
426 STATUSWINDOWPART *part;
429 TRACE("part %d\n", nPart);
431 part = &infoPtr->part0;
433 part = &infoPtr->parts[nPart];
436 result = strlenW(part->text);
440 result |= (part->style << 16);
445 STATUSBAR_GetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR tip, INT size)
449 CHAR buf[INFOTIPSIZE];
452 if (infoPtr->hwndToolTip) {
454 ti.cbSize = sizeof(TTTOOLINFOA);
455 ti.hwnd = infoPtr->Self;
458 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
460 lstrcpynA (tip, buf, size);
467 STATUSBAR_GetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR tip, INT size)
471 WCHAR buf[INFOTIPSIZE];
474 if (infoPtr->hwndToolTip) {
476 ti.cbSize = sizeof(TTTOOLINFOW);
477 ti.hwnd = infoPtr->Self;
480 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
482 lstrcpynW(tip, buf, size);
490 STATUSBAR_SetBkColor (STATUSWINDOWINFO *infoPtr, COLORREF color)
494 oldBkColor = infoPtr->clrBk;
495 infoPtr->clrBk = color;
496 InvalidateRect(infoPtr->Self, NULL, FALSE);
498 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
504 STATUSBAR_SetIcon (STATUSWINDOWINFO *infoPtr, INT nPart, HICON hIcon)
506 if ((nPart < -1) || (nPart >= infoPtr->numParts))
509 TRACE("setting part %d\n", nPart);
511 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
513 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
515 infoPtr->part0.hIcon = hIcon;
517 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
519 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
522 infoPtr->parts[nPart].hIcon = hIcon;
523 if (!(infoPtr->simple))
524 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
531 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, INT height)
534 TRACE("(height=%d)\n", height);
535 if (IsWindowVisible (infoPtr->Self)) {
539 GetClientRect (GetParent (infoPtr->Self), &parent_rect);
540 infoPtr->height = height + VERT_BORDER;
541 width = parent_rect.right - parent_rect.left;
542 x = parent_rect.left;
543 y = parent_rect.bottom - infoPtr->height;
544 MoveWindow (infoPtr->Self, parent_rect.left,
545 parent_rect.bottom - infoPtr->height,
546 width, infoPtr->height, TRUE);
547 STATUSBAR_SetPartBounds (infoPtr);
555 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, INT count, LPINT parts)
557 STATUSWINDOWPART *tmp;
560 TRACE("(%d,%p)\n", count, parts);
562 oldNumParts = infoPtr->numParts;
563 infoPtr->numParts = count;
564 if (oldNumParts > infoPtr->numParts) {
565 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
566 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
567 COMCTL32_Free (infoPtr->parts[i].text);
569 } else if (oldNumParts < infoPtr->numParts) {
570 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
571 if (!tmp) return FALSE;
572 for (i = 0; i < oldNumParts; i++) {
573 tmp[i] = infoPtr->parts[i];
576 COMCTL32_Free (infoPtr->parts);
577 infoPtr->parts = tmp;
579 if (oldNumParts == infoPtr->numParts) {
580 for (i=0; i < oldNumParts; i++)
581 if (infoPtr->parts[i].x != parts[i])
583 if (i==oldNumParts) /* Unchanged? no need to redraw! */
587 for (i = 0; i < infoPtr->numParts; i++)
588 infoPtr->parts[i].x = parts[i];
590 if (infoPtr->hwndToolTip) {
594 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
595 ti.cbSize = sizeof(TTTOOLINFOW);
596 ti.hwnd = infoPtr->Self;
598 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
599 if (nTipCount < infoPtr->numParts) {
601 for (i = nTipCount; i < infoPtr->numParts; i++) {
602 TRACE("add tool %d\n", i);
604 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
608 else if (nTipCount > infoPtr->numParts) {
610 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
611 TRACE("delete tool %d\n", i);
613 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
618 STATUSBAR_SetPartBounds (infoPtr);
619 InvalidateRect(infoPtr->Self, NULL, FALSE);
625 STATUSBAR_SetTextT (STATUSWINDOWINFO *infoPtr, INT nPart, WORD style,
626 LPCWSTR text, BOOL isW)
628 STATUSWINDOWPART *part=NULL;
629 BOOL changed = FALSE;
631 TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
633 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
634 * window is assumed to be a simple window */
636 if (nPart == 0x00ff) {
637 part = &infoPtr->part0;
639 if (infoPtr->parts && (nPart < 0 || nPart >= infoPtr->numParts)) {
640 part = &infoPtr->parts[nPart];
643 if (!part) return FALSE;
645 if (part->style != style)
649 if (style & SBT_OWNERDRAW) {
650 if (part->text == text)
652 part->text = (LPWSTR)text;
657 LPCSTR atxt = (LPCSTR)text;
658 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
659 ntext = COMCTL32_Alloc( (len + 1)*sizeof(WCHAR) );
660 if (!ntext) return FALSE;
661 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
663 ntext = COMCTL32_Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
664 if (!ntext) return FALSE;
665 strcpyW (ntext, text);
668 /* check if text is unchanged -> no need to redraw */
670 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
671 if (!isW) COMCTL32_Free(ntext);
675 if (!changed && !part->text)
680 COMCTL32_Free (part->text);
683 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
690 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR text)
692 TRACE("part %d: \"%s\"\n", id, text);
693 if (infoPtr->hwndToolTip) {
695 ti.cbSize = sizeof(TTTOOLINFOA);
696 ti.hwnd = infoPtr->Self;
700 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
709 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR text)
711 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
712 if (infoPtr->hwndToolTip) {
714 ti.cbSize = sizeof(TTTOOLINFOW);
715 ti.hwnd = infoPtr->Self;
719 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
727 inline static LRESULT
728 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, BOOL bUnicode)
730 BOOL bOld = infoPtr->bUnicode;
732 TRACE("(0x%x)\n", bUnicode);
733 infoPtr->bUnicode = bUnicode;
740 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, BOOL simple)
744 TRACE("(simple=%d)\n", simple);
745 if (infoPtr->simple == simple) /* no need to change */
748 infoPtr->simple = simple;
750 /* send notification */
751 nmhdr.hwndFrom = infoPtr->Self;
752 nmhdr.idFrom = GetWindowLongW (infoPtr->Self, GWL_ID);
753 nmhdr.code = SBN_SIMPLEMODECHANGE;
754 SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY, 0, (LPARAM)&nmhdr);
755 InvalidateRect(infoPtr->Self, NULL, FALSE);
761 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr)
766 for (i = 0; i < infoPtr->numParts; i++) {
767 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
768 COMCTL32_Free (infoPtr->parts[i].text);
770 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
771 COMCTL32_Free (infoPtr->part0.text);
772 COMCTL32_Free (infoPtr->parts);
774 /* delete default font */
775 if (infoPtr->hDefaultFont)
776 DeleteObject (infoPtr->hDefaultFont);
778 /* delete tool tip control */
779 if (infoPtr->hwndToolTip)
780 DestroyWindow (infoPtr->hwndToolTip);
782 COMCTL32_Free (infoPtr);
783 SetWindowLongW(infoPtr->Self, 0, 0);
789 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
791 STATUSWINDOWINFO *infoPtr;
792 NONCLIENTMETRICSW nclm;
795 int i, width, len, textHeight = 0;
799 infoPtr = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
800 if (!infoPtr) goto create_fail;
801 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
803 infoPtr->Self = hwnd;
804 infoPtr->numParts = 1;
806 infoPtr->simple = FALSE;
807 infoPtr->clrBk = CLR_DEFAULT;
810 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, hwnd, NF_QUERY);
811 infoPtr->NtfUnicode = (i == NFR_UNICODE);
813 GetClientRect (hwnd, &rect);
814 InvalidateRect (hwnd, &rect, 0);
817 ZeroMemory (&nclm, sizeof(nclm));
818 nclm.cbSize = sizeof(nclm);
819 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
820 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
822 /* initialize simple case */
823 infoPtr->part0.bound = rect;
824 infoPtr->part0.text = 0;
825 infoPtr->part0.x = 0;
826 infoPtr->part0.style = 0;
827 infoPtr->part0.hIcon = 0;
829 /* initialize first part */
830 infoPtr->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
831 if (!infoPtr->parts) goto create_fail;
832 infoPtr->parts[0].bound = rect;
833 infoPtr->parts[0].text = 0;
834 infoPtr->parts[0].x = -1;
835 infoPtr->parts[0].style = 0;
836 infoPtr->parts[0].hIcon = 0;
838 if (IsWindowUnicode (hwnd)) {
839 infoPtr->bUnicode = TRUE;
840 if (lpCreate->lpszName &&
841 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
842 infoPtr->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
843 if (!infoPtr->parts[0].text) goto create_fail;
844 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
848 if (lpCreate->lpszName &&
849 (len = strlen((LPCSTR)lpCreate->lpszName))) {
850 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
851 infoPtr->parts[0].text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
852 if (!infoPtr->parts[0].text) goto create_fail;
853 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
854 infoPtr->parts[0].text, lenW );
858 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
860 /* statusbars on managed windows should not have SIZEGRIP style */
861 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
862 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
863 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
865 if ((hdc = GetDC (0))) {
869 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
870 GetTextMetricsW (hdc, &tm);
871 textHeight = tm.tmHeight;
872 SelectObject (hdc, hOldFont);
875 TRACE(" textHeight=%d\n", textHeight);
877 if (dwStyle & SBT_TOOLTIPS) {
878 infoPtr->hwndToolTip =
879 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
880 CW_USEDEFAULT, CW_USEDEFAULT,
881 CW_USEDEFAULT, CW_USEDEFAULT,
883 GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
885 if (infoPtr->hwndToolTip) {
886 NMTOOLTIPSCREATED nmttc;
888 nmttc.hdr.hwndFrom = hwnd;
889 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
890 nmttc.hdr.code = NM_TOOLTIPSCREATED;
891 nmttc.hwndToolTips = infoPtr->hwndToolTip;
893 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
894 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
898 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
899 GetClientRect (GetParent (hwnd), &rect);
900 width = rect.right - rect.left;
901 infoPtr->height = textHeight + 4 + VERT_BORDER;
902 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
903 width, infoPtr->height, SWP_NOZORDER);
904 STATUSBAR_SetPartBounds (infoPtr);
911 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
916 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
917 * of the first part only (usual behaviour) */
919 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
924 if (!(infoPtr->parts[0].text))
926 if (infoPtr->bUnicode)
927 len = strlenW (infoPtr->parts[0].text);
929 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
932 if (infoPtr->bUnicode)
933 strcpyW (buf, infoPtr->parts[0].text);
935 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
936 (LPSTR)buf, len+1, NULL, NULL );
945 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
947 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
951 GetClientRect (infoPtr->Self, &rect);
955 ScreenToClient (infoPtr->Self, &pt);
957 rect.left = rect.right - 13;
960 if (PtInRect (&rect, pt))
961 return HTBOTTOMRIGHT;
969 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
974 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
975 hdc = BeginPaint (infoPtr->Self, &ps);
976 STATUSBAR_Refresh (infoPtr, hdc);
977 EndPaint (infoPtr->Self, &ps);
984 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
986 infoPtr->hFont = font;
987 TRACE("%04x\n", infoPtr->hFont);
989 InvalidateRect(infoPtr->Self, NULL, FALSE);
996 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
998 STATUSWINDOWPART *part;
1002 if (infoPtr->numParts == 0)
1005 part = &infoPtr->parts[0];
1006 /* duplicate string */
1008 COMCTL32_Free (part->text);
1010 if (infoPtr->bUnicode) {
1011 if (text && (len = strlenW((LPCWSTR)text))) {
1012 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1013 if (!part->text) return FALSE;
1014 strcpyW (part->text, (LPCWSTR)text);
1018 if (text && (len = lstrlenA(text))) {
1019 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1020 part->text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
1021 if (!part->text) return FALSE;
1022 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1026 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1033 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1038 /* Need to resize width to match parent */
1039 TRACE("flags %04x\n", flags);
1041 if (flags != SIZE_RESTORED) {
1042 WARN("flags MUST be SIZE_RESTORED\n");
1045 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1047 /* width and height don't apply */
1048 GetClientRect (GetParent(infoPtr->Self), &parent_rect);
1049 width = parent_rect.right - parent_rect.left;
1050 x = parent_rect.left;
1051 y = parent_rect.bottom - infoPtr->height;
1052 MoveWindow (infoPtr->Self, parent_rect.left,
1053 parent_rect.bottom - infoPtr->height,
1054 width, infoPtr->height, TRUE);
1055 STATUSBAR_SetPartBounds (infoPtr);
1061 STATUSBAR_NotifyFormat (STATUSWINDOWINFO *infoPtr, HWND from, INT cmd)
1063 if (cmd == NF_REQUERY) {
1064 INT i = SendMessageW(from, WM_NOTIFYFORMAT, infoPtr->Self, NF_QUERY);
1065 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1067 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1072 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1076 TRACE("code %04x\n", code);
1077 nmhdr.hwndFrom = hwnd;
1078 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1080 SendMessageW (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1086 static LRESULT WINAPI
1087 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1089 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1090 INT nPart = ((INT) wParam) & 0x00ff;
1093 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1094 if (!infoPtr && msg != WM_CREATE)
1095 return DefWindowProcW (hwnd, msg, wParam, lParam);
1099 return STATUSBAR_GetBorders ((INT *)lParam);
1102 return STATUSBAR_GetIcon (infoPtr, nPart);
1105 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1108 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1111 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1114 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1116 case SB_GETTEXTLENGTHA:
1117 case SB_GETTEXTLENGTHW:
1118 return STATUSBAR_GetTextLength (infoPtr, nPart);
1120 case SB_GETTIPTEXTA:
1121 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1123 case SB_GETTIPTEXTW:
1124 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1126 case SB_GETUNICODEFORMAT:
1127 return infoPtr->bUnicode;
1130 return infoPtr->simple;
1133 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1136 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1138 case SB_SETMINHEIGHT:
1139 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1142 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1145 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1148 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1150 case SB_SETTIPTEXTA:
1151 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1153 case SB_SETTIPTEXTW:
1154 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1156 case SB_SETUNICODEFORMAT:
1157 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1160 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1163 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1166 return STATUSBAR_WMDestroy (infoPtr);
1169 return infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont;
1172 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1174 case WM_GETTEXTLENGTH:
1175 return STATUSBAR_GetTextLength (infoPtr, 0);
1177 case WM_LBUTTONDBLCLK:
1178 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1181 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1184 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1187 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1188 (INT)HIWORD(lParam));
1189 if (res != HTERROR) return res;
1190 return DefWindowProcW (hwnd, msg, wParam, lParam);
1192 case WM_NCLBUTTONUP:
1193 case WM_NCLBUTTONDOWN:
1194 PostMessageW (GetParent (hwnd), msg, wParam, lParam);
1197 case WM_NOTIFYFORMAT:
1198 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1201 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1203 case WM_RBUTTONDBLCLK:
1204 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1207 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1210 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1213 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1216 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1217 return DefWindowProcW (hwnd, msg, wParam, lParam);
1221 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1222 msg, wParam, lParam);
1223 return DefWindowProcW (hwnd, msg, wParam, lParam);
1229 /***********************************************************************
1230 * STATUS_Register [Internal]
1232 * Registers the status window class.
1236 STATUS_Register (void)
1240 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1241 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1242 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1243 wndClass.cbClsExtra = 0;
1244 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1245 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
1246 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1247 wndClass.lpszClassName = STATUSCLASSNAMEW;
1249 RegisterClassW (&wndClass);
1253 /***********************************************************************
1254 * STATUS_Unregister [Internal]
1256 * Unregisters the status window class.
1260 STATUS_Unregister (void)
1262 UnregisterClassW (STATUSCLASSNAMEW, (HINSTANCE)NULL);