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);
397 part = &infoPtr->part0;
399 part = &infoPtr->parts[nPart];
401 if (part->style & SBT_OWNERDRAW)
402 result = (LRESULT)part->text;
404 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
405 NULL, 0, NULL, NULL ) - 1 : 0;
406 result = MAKELONG( len, part->style );
407 if (part->text && buf)
408 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
415 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, INT nPart, LPWSTR buf)
417 STATUSWINDOWPART *part;
420 TRACE("part %d\n", nPart);
422 part = &infoPtr->part0;
424 part = &infoPtr->parts[nPart];
426 if (part->style & SBT_OWNERDRAW)
427 result = (LRESULT)part->text;
429 result = part->text ? strlenW (part->text) : 0;
430 result |= (part->style << 16);
431 if (part->text && buf)
432 strcpyW (buf, part->text);
439 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, INT nPart)
441 STATUSWINDOWPART *part;
444 TRACE("part %d\n", nPart);
446 part = &infoPtr->part0;
448 part = &infoPtr->parts[nPart];
451 result = strlenW(part->text);
455 result |= (part->style << 16);
460 STATUSBAR_GetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR tip, INT size)
464 CHAR buf[INFOTIPSIZE];
467 if (infoPtr->hwndToolTip) {
469 ti.cbSize = sizeof(TTTOOLINFOA);
470 ti.hwnd = infoPtr->Self;
473 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
475 lstrcpynA (tip, buf, size);
482 STATUSBAR_GetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR tip, INT size)
486 WCHAR buf[INFOTIPSIZE];
489 if (infoPtr->hwndToolTip) {
491 ti.cbSize = sizeof(TTTOOLINFOW);
492 ti.hwnd = infoPtr->Self;
495 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
497 lstrcpynW(tip, buf, size);
505 STATUSBAR_SetBkColor (STATUSWINDOWINFO *infoPtr, COLORREF color)
509 oldBkColor = infoPtr->clrBk;
510 infoPtr->clrBk = color;
511 InvalidateRect(infoPtr->Self, NULL, FALSE);
513 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
519 STATUSBAR_SetIcon (STATUSWINDOWINFO *infoPtr, INT nPart, HICON hIcon)
521 if ((nPart < -1) || (nPart >= infoPtr->numParts))
524 TRACE("setting part %d\n", nPart);
527 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
529 infoPtr->part0.hIcon = hIcon;
531 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
533 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
536 infoPtr->parts[nPart].hIcon = hIcon;
537 if (!(infoPtr->simple))
538 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
545 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, INT height)
548 TRACE("(height=%d)\n", height);
549 if (IsWindowVisible (infoPtr->Self)) {
553 GetClientRect (GetParent (infoPtr->Self), &parent_rect);
554 infoPtr->height = height + VERT_BORDER;
555 width = parent_rect.right - parent_rect.left;
556 x = parent_rect.left;
557 y = parent_rect.bottom - infoPtr->height;
558 MoveWindow (infoPtr->Self, parent_rect.left,
559 parent_rect.bottom - infoPtr->height,
560 width, infoPtr->height, TRUE);
561 STATUSBAR_SetPartBounds (infoPtr);
569 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, INT count, LPINT parts)
571 STATUSWINDOWPART *tmp;
574 TRACE("(%d,%p)\n", count, parts);
577 infoPtr->simple = FALSE;
579 oldNumParts = infoPtr->numParts;
580 infoPtr->numParts = count;
581 if (oldNumParts > infoPtr->numParts) {
582 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
583 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
584 COMCTL32_Free (infoPtr->parts[i].text);
586 } else if (oldNumParts < infoPtr->numParts) {
587 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
588 if (!tmp) return FALSE;
589 for (i = 0; i < oldNumParts; i++) {
590 tmp[i] = infoPtr->parts[i];
593 COMCTL32_Free (infoPtr->parts);
594 infoPtr->parts = tmp;
596 if (oldNumParts == infoPtr->numParts) {
597 for (i=0; i < oldNumParts; i++)
598 if (infoPtr->parts[i].x != parts[i])
600 if (i==oldNumParts) /* Unchanged? no need to redraw! */
604 for (i = 0; i < infoPtr->numParts; i++)
605 infoPtr->parts[i].x = parts[i];
607 if (infoPtr->hwndToolTip) {
611 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
612 ti.cbSize = sizeof(TTTOOLINFOW);
613 ti.hwnd = infoPtr->Self;
615 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
616 if (nTipCount < infoPtr->numParts) {
618 for (i = nTipCount; i < infoPtr->numParts; i++) {
619 TRACE("add tool %d\n", i);
621 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
625 else if (nTipCount > infoPtr->numParts) {
627 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
628 TRACE("delete tool %d\n", i);
630 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
635 STATUSBAR_SetPartBounds (infoPtr);
636 InvalidateRect(infoPtr->Self, NULL, FALSE);
642 STATUSBAR_SetTextT (STATUSWINDOWINFO *infoPtr, INT nPart, WORD style,
643 LPCWSTR text, BOOL isW)
645 STATUSWINDOWPART *part=NULL;
646 BOOL changed = FALSE;
648 TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
651 part = &infoPtr->part0;
652 else if (!infoPtr->simple && infoPtr->parts)
653 part = &infoPtr->parts[nPart];
654 if (!part) return FALSE;
656 if (part->style != style)
660 if (style & SBT_OWNERDRAW) {
661 if (part->text == text)
663 part->text = (LPWSTR)text;
668 LPCSTR atxt = (LPCSTR)text;
669 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
670 ntext = COMCTL32_Alloc( (len + 1)*sizeof(WCHAR) );
671 if (!ntext) return FALSE;
672 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
674 ntext = COMCTL32_Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
675 if (!ntext) return FALSE;
676 strcpyW (ntext, text);
679 /* check if text is unchanged -> no need to redraw */
681 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
682 if (!isW) COMCTL32_Free(ntext);
686 if (!changed && !part->text)
691 COMCTL32_Free (part->text);
694 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
701 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR text)
703 TRACE("part %d: \"%s\"\n", id, text);
704 if (infoPtr->hwndToolTip) {
706 ti.cbSize = sizeof(TTTOOLINFOA);
707 ti.hwnd = infoPtr->Self;
711 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
720 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR text)
722 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
723 if (infoPtr->hwndToolTip) {
725 ti.cbSize = sizeof(TTTOOLINFOW);
726 ti.hwnd = infoPtr->Self;
730 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
738 inline static LRESULT
739 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, BOOL bUnicode)
741 BOOL bOld = infoPtr->bUnicode;
743 TRACE("(0x%x)\n", bUnicode);
744 infoPtr->bUnicode = bUnicode;
751 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, BOOL simple)
755 TRACE("(simple=%d)\n", simple);
756 if (infoPtr->simple == simple) /* no need to change */
759 infoPtr->simple = simple;
761 /* send notification */
762 nmhdr.hwndFrom = infoPtr->Self;
763 nmhdr.idFrom = GetWindowLongW (infoPtr->Self, GWL_ID);
764 nmhdr.code = SBN_SIMPLEMODECHANGE;
765 SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY, 0, (LPARAM)&nmhdr);
766 InvalidateRect(infoPtr->Self, NULL, FALSE);
772 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr)
777 for (i = 0; i < infoPtr->numParts; i++) {
778 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
779 COMCTL32_Free (infoPtr->parts[i].text);
781 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
782 COMCTL32_Free (infoPtr->part0.text);
783 COMCTL32_Free (infoPtr->parts);
785 /* delete default font */
786 if (infoPtr->hDefaultFont)
787 DeleteObject (infoPtr->hDefaultFont);
789 /* delete tool tip control */
790 if (infoPtr->hwndToolTip)
791 DestroyWindow (infoPtr->hwndToolTip);
793 COMCTL32_Free (infoPtr);
794 SetWindowLongW(infoPtr->Self, 0, 0);
800 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
802 STATUSWINDOWINFO *infoPtr;
803 NONCLIENTMETRICSW nclm;
806 int width, len, textHeight = 0;
810 infoPtr = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
811 if (!infoPtr) goto create_fail;
812 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
814 infoPtr->Self = hwnd;
815 infoPtr->numParts = 1;
817 infoPtr->simple = FALSE;
818 infoPtr->clrBk = CLR_DEFAULT;
821 /* FIXME: send unicode parent notification query (WM_QUERYFORMAT) here */
823 GetClientRect (hwnd, &rect);
824 InvalidateRect (hwnd, &rect, 0);
827 ZeroMemory (&nclm, sizeof(nclm));
828 nclm.cbSize = sizeof(nclm);
829 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
830 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
832 /* initialize simple case */
833 infoPtr->part0.bound = rect;
834 infoPtr->part0.text = 0;
835 infoPtr->part0.x = 0;
836 infoPtr->part0.style = 0;
837 infoPtr->part0.hIcon = 0;
839 /* initialize first part */
840 infoPtr->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
841 if (!infoPtr->parts) goto create_fail;
842 infoPtr->parts[0].bound = rect;
843 infoPtr->parts[0].text = 0;
844 infoPtr->parts[0].x = -1;
845 infoPtr->parts[0].style = 0;
846 infoPtr->parts[0].hIcon = 0;
848 if (IsWindowUnicode (hwnd)) {
849 infoPtr->bUnicode = TRUE;
850 if (lpCreate->lpszName &&
851 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
852 infoPtr->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
853 if (!infoPtr->parts[0].text) goto create_fail;
854 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
858 if (lpCreate->lpszName &&
859 (len = strlen((LPCSTR)lpCreate->lpszName))) {
860 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
861 infoPtr->parts[0].text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
862 if (!infoPtr->parts[0].text) goto create_fail;
863 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
864 infoPtr->parts[0].text, lenW );
868 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
870 /* statusbars on managed windows should not have SIZEGRIP style */
871 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
872 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
873 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
875 if ((hdc = GetDC (0))) {
879 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
880 GetTextMetricsW (hdc, &tm);
881 textHeight = tm.tmHeight;
882 SelectObject (hdc, hOldFont);
885 TRACE(" textHeight=%d\n", textHeight);
887 if (dwStyle & SBT_TOOLTIPS) {
888 infoPtr->hwndToolTip =
889 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
890 CW_USEDEFAULT, CW_USEDEFAULT,
891 CW_USEDEFAULT, CW_USEDEFAULT,
893 GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
895 if (infoPtr->hwndToolTip) {
896 NMTOOLTIPSCREATED nmttc;
898 nmttc.hdr.hwndFrom = hwnd;
899 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
900 nmttc.hdr.code = NM_TOOLTIPSCREATED;
901 nmttc.hwndToolTips = infoPtr->hwndToolTip;
903 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
904 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
908 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
909 GetClientRect (GetParent (hwnd), &rect);
910 width = rect.right - rect.left;
911 infoPtr->height = textHeight + 4 + VERT_BORDER;
912 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
913 width, infoPtr->height, SWP_NOZORDER);
914 STATUSBAR_SetPartBounds (infoPtr);
921 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
926 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
927 * of the first part only (usual behaviour) */
929 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
934 if (!(infoPtr->parts[0].text))
936 if (infoPtr->bUnicode)
937 len = strlenW (infoPtr->parts[0].text);
939 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
942 if (infoPtr->bUnicode)
943 strcpyW (buf, infoPtr->parts[0].text);
945 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
946 (LPSTR)buf, len+1, NULL, NULL );
955 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
957 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
961 GetClientRect (infoPtr->Self, &rect);
965 ScreenToClient (infoPtr->Self, &pt);
967 rect.left = rect.right - 13;
970 if (PtInRect (&rect, pt))
971 return HTBOTTOMRIGHT;
979 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
984 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
985 hdc = BeginPaint (infoPtr->Self, &ps);
986 STATUSBAR_Refresh (infoPtr, hdc);
987 EndPaint (infoPtr->Self, &ps);
994 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
996 infoPtr->hFont = font;
997 TRACE("%04x\n", infoPtr->hFont);
999 InvalidateRect(infoPtr->Self, NULL, FALSE);
1006 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
1008 STATUSWINDOWPART *part;
1012 if (infoPtr->numParts == 0)
1015 part = &infoPtr->parts[0];
1016 /* duplicate string */
1018 COMCTL32_Free (part->text);
1020 if (infoPtr->bUnicode) {
1021 if (text && (len = strlenW((LPCWSTR)text))) {
1022 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1023 if (!part->text) return FALSE;
1024 strcpyW (part->text, (LPCWSTR)text);
1028 if (text && (len = lstrlenA(text))) {
1029 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1030 part->text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
1031 if (!part->text) return FALSE;
1032 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1036 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1043 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1048 /* Need to resize width to match parent */
1049 TRACE("flags %04x\n", flags);
1051 if (flags != SIZE_RESTORED) {
1052 WARN("flags MUST be SIZE_RESTORED\n");
1055 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1057 /* width and height don't apply */
1058 GetClientRect (GetParent(infoPtr->Self), &parent_rect);
1059 width = parent_rect.right - parent_rect.left;
1060 x = parent_rect.left;
1061 y = parent_rect.bottom - infoPtr->height;
1062 MoveWindow (infoPtr->Self, parent_rect.left,
1063 parent_rect.bottom - infoPtr->height,
1064 width, infoPtr->height, TRUE);
1065 STATUSBAR_SetPartBounds (infoPtr);
1071 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1075 TRACE("code %04x\n", code);
1076 nmhdr.hwndFrom = hwnd;
1077 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1079 SendMessageW (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1085 static LRESULT WINAPI
1086 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1088 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1089 INT nPart = ((INT) wParam) & 0x00ff;
1092 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1093 if (!infoPtr && msg != WM_CREATE)
1094 return DefWindowProcW (hwnd, msg, wParam, lParam);
1098 return STATUSBAR_GetBorders ((INT *)lParam);
1101 return STATUSBAR_GetIcon (infoPtr, nPart);
1104 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1107 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1110 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1113 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1115 case SB_GETTEXTLENGTHA:
1116 case SB_GETTEXTLENGTHW:
1117 return STATUSBAR_GetTextLength (infoPtr, nPart);
1119 case SB_GETTIPTEXTA:
1120 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1122 case SB_GETTIPTEXTW:
1123 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1125 case SB_GETUNICODEFORMAT:
1126 return infoPtr->bUnicode;
1129 return infoPtr->simple;
1132 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1135 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1137 case SB_SETMINHEIGHT:
1138 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1141 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1144 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1147 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1149 case SB_SETTIPTEXTA:
1150 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1152 case SB_SETTIPTEXTW:
1153 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1155 case SB_SETUNICODEFORMAT:
1156 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1159 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1162 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1165 return STATUSBAR_WMDestroy (infoPtr);
1168 return infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont;
1171 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1173 case WM_GETTEXTLENGTH:
1174 return STATUSBAR_GetTextLength (infoPtr, 0);
1176 case WM_LBUTTONDBLCLK:
1177 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1180 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1183 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1186 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1187 (INT)HIWORD(lParam));
1188 if (res != HTERROR) return res;
1189 return DefWindowProcW (hwnd, msg, wParam, lParam);
1191 case WM_NCLBUTTONUP:
1192 case WM_NCLBUTTONDOWN:
1193 PostMessageW (GetParent (hwnd), msg, wParam, lParam);
1197 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1199 case WM_RBUTTONDBLCLK:
1200 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1203 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1206 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1209 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1213 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1214 return DefWindowProcW (hwnd, msg, wParam, lParam);
1218 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1219 msg, wParam, lParam);
1220 return DefWindowProcW (hwnd, msg, wParam, lParam);
1226 /***********************************************************************
1227 * STATUS_Register [Internal]
1229 * Registers the status window class.
1233 STATUS_Register (void)
1237 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1238 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1239 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1240 wndClass.cbClsExtra = 0;
1241 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1242 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
1243 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1244 wndClass.lpszClassName = STATUSCLASSNAMEW;
1246 RegisterClassW (&wndClass);
1250 /***********************************************************************
1251 * STATUS_Unregister [Internal]
1253 * Unregisters the status window class.
1257 STATUS_Unregister (void)
1259 UnregisterClassW (STATUSCLASSNAMEW, (HINSTANCE)NULL);