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 * -- CCS_BOTTOM (default)
28 * -- CCS_NOPARENTALIGN
31 * -- CCS_VERT (defaults to RIGHT)
37 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
61 COLORREF clrBk; /* background color */
62 BOOL bUnicode; /* unicode flag */
63 BOOL NtfUnicode; /* notify format */
64 STATUSWINDOWPART part0; /* simple window */
65 STATUSWINDOWPART* parts;
69 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
70 * The second cdrom contains executables drawstat.exe, gettext.exe,
71 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
78 #define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongW (hwnd, 0))
82 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr);
84 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
86 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
90 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
92 HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
96 TRACE("draw size grip %d,%d - %d,%d\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
98 pt.x = lpRect->right - 1;
99 pt.y = lpRect->bottom - 1;
101 hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
102 hOldPen = SelectObject( hdc, hPenFace );
103 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
104 LineTo (hdc, pt.x, pt.y);
105 LineTo (hdc, pt.x, pt.y - 13);
110 hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
111 SelectObject( hdc, hPenShadow );
112 for (i = 1; i < 11; i += 4) {
113 MoveToEx (hdc, pt.x - i, pt.y, NULL);
114 LineTo (hdc, pt.x + 1, pt.y - i - 1);
116 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
117 LineTo (hdc, pt.x + 1, pt.y - i - 2);
120 hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
121 SelectObject( hdc, hPenHighlight );
122 for (i = 3; i < 13; i += 4) {
123 MoveToEx (hdc, pt.x - i, pt.y, NULL);
124 LineTo (hdc, pt.x + 1, pt.y - i - 1);
127 SelectObject (hdc, hOldPen);
128 DeleteObject( hPenFace );
129 DeleteObject( hPenShadow );
130 DeleteObject( hPenHighlight );
135 STATUSBAR_DrawPart (HDC hdc, const STATUSWINDOWPART *part, const STATUSWINDOWINFO *infoPtr, int itemID)
137 RECT r = part->bound;
138 UINT border = BDR_SUNKENOUTER;
140 TRACE("part bound %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom);
141 if (part->style & SBT_POPOUT)
142 border = BDR_RAISEDOUTER;
143 else if (part->style & SBT_NOBORDERS)
146 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
148 if (part->style & SBT_OWNERDRAW)
152 dis.CtlID = GetWindowLongW (infoPtr->Self, GWL_ID);
154 dis.hwndItem = infoPtr->Self;
157 dis.itemData = (INT)part->text;
158 SendMessageW (GetParent (infoPtr->Self), WM_DRAWITEM,
159 (WPARAM)dis.CtlID, (LPARAM)&dis);
165 INT cy = r.bottom - r.top;
168 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
171 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
177 STATUSBAR_RefreshPart (const STATUSWINDOWINFO *infoPtr, const STATUSWINDOWPART *part, HDC hdc, int itemID)
182 TRACE("item %d\n", itemID);
183 if (!IsWindowVisible (infoPtr->Self))
186 if (part->bound.right < part->bound.left) return;
188 if (infoPtr->clrBk != CLR_DEFAULT)
189 hbrBk = CreateSolidBrush (infoPtr->clrBk);
191 hbrBk = GetSysColorBrush (COLOR_3DFACE);
192 FillRect(hdc, &part->bound, hbrBk);
194 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
196 STATUSBAR_DrawPart (hdc, part, infoPtr, itemID);
198 SelectObject (hdc, hOldFont);
200 if (infoPtr->clrBk != CLR_DEFAULT)
201 DeleteObject (hbrBk);
203 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
207 GetClientRect (infoPtr->Self, &rect);
208 STATUSBAR_DrawSizeGrip (hdc, &rect);
214 STATUSBAR_Refresh (STATUSWINDOWINFO *infoPtr, HDC hdc)
222 if (!IsWindowVisible(infoPtr->Self))
225 STATUSBAR_SetPartBounds(infoPtr);
227 GetClientRect (infoPtr->Self, &rect);
229 if (infoPtr->clrBk != CLR_DEFAULT)
230 hbrBk = CreateSolidBrush (infoPtr->clrBk);
232 hbrBk = GetSysColorBrush (COLOR_3DFACE);
233 FillRect(hdc, &rect, hbrBk);
235 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
237 if (infoPtr->simple) {
238 STATUSBAR_RefreshPart (infoPtr, &infoPtr->part0, hdc, 0);
240 for (i = 0; i < infoPtr->numParts; i++) {
241 STATUSBAR_RefreshPart (infoPtr, &infoPtr->parts[i], hdc, i);
245 SelectObject (hdc, hOldFont);
247 if (infoPtr->clrBk != CLR_DEFAULT)
248 DeleteObject (hbrBk);
250 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
251 STATUSBAR_DrawSizeGrip (hdc, &rect);
258 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr)
260 STATUSWINDOWPART *part;
264 /* get our window size */
265 GetClientRect (infoPtr->Self, &rect);
266 TRACE("client wnd size is %d,%d - %d,%d\n", rect.left, rect.top, rect.right, rect.bottom);
268 rect.top += VERT_BORDER;
270 /* set bounds for simple rectangle */
271 infoPtr->part0.bound = rect;
273 /* set bounds for non-simple rectangles */
274 for (i = 0; i < infoPtr->numParts; i++) {
275 part = &infoPtr->parts[i];
276 r = &infoPtr->parts[i].bound;
278 r->bottom = rect.bottom;
282 r->left = infoPtr->parts[i-1].bound.right + HORZ_GAP;
284 r->right = rect.right;
288 if (infoPtr->hwndToolTip) {
291 ti.cbSize = sizeof(TTTOOLINFOW);
292 ti.hwnd = infoPtr->Self;
295 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
303 STATUSBAR_Relay2Tip (STATUSWINDOWINFO *infoPtr, UINT uMsg,
304 WPARAM wParam, LPARAM lParam)
308 msg.hwnd = infoPtr->Self;
312 msg.time = GetMessageTime ();
313 msg.pt.x = LOWORD(GetMessagePos ());
314 msg.pt.y = HIWORD(GetMessagePos ());
316 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
321 STATUSBAR_GetBorders (INT out[])
324 out[0] = HORZ_BORDER; /* horizontal border width */
325 out[1] = VERT_BORDER; /* vertical border width */
326 out[2] = HORZ_GAP; /* width of border between rectangles */
333 STATUSBAR_GetIcon (STATUSWINDOWINFO *infoPtr, INT nPart)
335 TRACE("%d\n", nPart);
336 /* MSDN says: "simple parts are indexed with -1" */
337 if ((nPart < -1) || (nPart >= infoPtr->numParts))
341 return (infoPtr->part0.hIcon);
343 return (infoPtr->parts[nPart].hIcon);
348 STATUSBAR_GetParts (STATUSWINDOWINFO *infoPtr, INT num_parts, INT parts[])
352 TRACE("(%d)\n", num_parts);
354 for (i = 0; i < num_parts; i++) {
355 parts[i] = infoPtr->parts[i].x;
358 return infoPtr->numParts;
363 STATUSBAR_GetRect (STATUSWINDOWINFO *infoPtr, INT nPart, LPRECT rect)
365 TRACE("part %d\n", nPart);
367 *rect = infoPtr->part0.bound;
369 *rect = infoPtr->parts[nPart].bound;
375 STATUSBAR_GetTextA (STATUSWINDOWINFO *infoPtr, INT nPart, LPSTR buf)
377 STATUSWINDOWPART *part;
380 TRACE("part %d\n", nPart);
382 /* MSDN says: "simple parts use index of 0", so this check is ok. */
383 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
386 part = &infoPtr->part0;
388 part = &infoPtr->parts[nPart];
390 if (part->style & SBT_OWNERDRAW)
391 result = (LRESULT)part->text;
393 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
394 NULL, 0, NULL, NULL ) - 1 : 0;
395 result = MAKELONG( len, part->style );
396 if (part->text && buf)
397 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
404 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, INT nPart, LPWSTR buf)
406 STATUSWINDOWPART *part;
409 TRACE("part %d\n", nPart);
410 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
413 part = &infoPtr->part0;
415 part = &infoPtr->parts[nPart];
417 if (part->style & SBT_OWNERDRAW)
418 result = (LRESULT)part->text;
420 result = part->text ? strlenW (part->text) : 0;
421 result |= (part->style << 16);
422 if (part->text && buf)
423 strcpyW (buf, part->text);
430 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, INT nPart)
432 STATUSWINDOWPART *part;
435 TRACE("part %d\n", nPart);
437 /* MSDN says: "simple parts use index of 0", so this check is ok. */
438 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
441 part = &infoPtr->part0;
443 part = &infoPtr->parts[nPart];
446 result = strlenW(part->text);
450 result |= (part->style << 16);
455 STATUSBAR_GetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR tip, INT size)
459 CHAR buf[INFOTIPSIZE];
462 if (infoPtr->hwndToolTip) {
464 ti.cbSize = sizeof(TTTOOLINFOA);
465 ti.hwnd = infoPtr->Self;
468 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
470 lstrcpynA (tip, buf, size);
477 STATUSBAR_GetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR tip, INT size)
481 WCHAR buf[INFOTIPSIZE];
484 if (infoPtr->hwndToolTip) {
486 ti.cbSize = sizeof(TTTOOLINFOW);
487 ti.hwnd = infoPtr->Self;
490 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
492 lstrcpynW(tip, buf, size);
500 STATUSBAR_SetBkColor (STATUSWINDOWINFO *infoPtr, COLORREF color)
504 oldBkColor = infoPtr->clrBk;
505 infoPtr->clrBk = color;
506 InvalidateRect(infoPtr->Self, NULL, FALSE);
508 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
514 STATUSBAR_SetIcon (STATUSWINDOWINFO *infoPtr, INT nPart, HICON hIcon)
516 if ((nPart < -1) || (nPart >= infoPtr->numParts))
519 TRACE("setting part %d\n", nPart);
521 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
523 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
525 infoPtr->part0.hIcon = hIcon;
527 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
529 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
532 infoPtr->parts[nPart].hIcon = hIcon;
533 if (!(infoPtr->simple))
534 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
541 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, INT height)
544 TRACE("(height=%d)\n", height);
545 if (IsWindowVisible (infoPtr->Self)) {
549 GetClientRect (GetParent (infoPtr->Self), &parent_rect);
550 infoPtr->height = height + VERT_BORDER;
551 width = parent_rect.right - parent_rect.left;
552 x = parent_rect.left;
553 y = parent_rect.bottom - infoPtr->height;
554 MoveWindow (infoPtr->Self, parent_rect.left,
555 parent_rect.bottom - infoPtr->height,
556 width, infoPtr->height, TRUE);
557 STATUSBAR_SetPartBounds (infoPtr);
565 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, INT count, LPINT parts)
567 STATUSWINDOWPART *tmp;
570 TRACE("(%d,%p)\n", count, parts);
572 oldNumParts = infoPtr->numParts;
573 infoPtr->numParts = count;
574 if (oldNumParts > infoPtr->numParts) {
575 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
576 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
577 COMCTL32_Free (infoPtr->parts[i].text);
579 } else if (oldNumParts < infoPtr->numParts) {
580 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
581 if (!tmp) return FALSE;
582 for (i = 0; i < oldNumParts; i++) {
583 tmp[i] = infoPtr->parts[i];
586 COMCTL32_Free (infoPtr->parts);
587 infoPtr->parts = tmp;
589 if (oldNumParts == infoPtr->numParts) {
590 for (i=0; i < oldNumParts; i++)
591 if (infoPtr->parts[i].x != parts[i])
593 if (i==oldNumParts) /* Unchanged? no need to redraw! */
597 for (i = 0; i < infoPtr->numParts; i++)
598 infoPtr->parts[i].x = parts[i];
600 if (infoPtr->hwndToolTip) {
604 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
605 ti.cbSize = sizeof(TTTOOLINFOW);
606 ti.hwnd = infoPtr->Self;
608 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
609 if (nTipCount < infoPtr->numParts) {
611 for (i = nTipCount; i < infoPtr->numParts; i++) {
612 TRACE("add tool %d\n", i);
614 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
618 else if (nTipCount > infoPtr->numParts) {
620 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
621 TRACE("delete tool %d\n", i);
623 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
628 STATUSBAR_SetPartBounds (infoPtr);
629 InvalidateRect(infoPtr->Self, NULL, FALSE);
635 STATUSBAR_SetTextT (STATUSWINDOWINFO *infoPtr, INT nPart, WORD style,
636 LPCWSTR text, BOOL isW)
638 STATUSWINDOWPART *part=NULL;
639 BOOL changed = FALSE;
641 if (style & SBT_OWNERDRAW) {
642 TRACE("part %d, text %p\n",nPart,text);
644 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
646 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
647 * window is assumed to be a simple window */
649 if (nPart == 0x00ff) {
650 part = &infoPtr->part0;
652 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
653 part = &infoPtr->parts[nPart];
656 if (!part) return FALSE;
658 if (part->style != style)
662 if (style & SBT_OWNERDRAW) {
663 if (part->text == text)
665 part->text = (LPWSTR)text;
670 LPCSTR atxt = (LPCSTR)text;
671 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
672 ntext = COMCTL32_Alloc( (len + 1)*sizeof(WCHAR) );
673 if (!ntext) return FALSE;
674 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
676 ntext = COMCTL32_Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
677 if (!ntext) return FALSE;
678 strcpyW (ntext, text);
681 /* check if text is unchanged -> no need to redraw */
683 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
684 if (!isW) COMCTL32_Free(ntext);
688 if (!changed && !part->text)
693 COMCTL32_Free (part->text);
696 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
703 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, INT id, LPSTR text)
705 TRACE("part %d: \"%s\"\n", id, text);
706 if (infoPtr->hwndToolTip) {
708 ti.cbSize = sizeof(TTTOOLINFOA);
709 ti.hwnd = infoPtr->Self;
713 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
722 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, INT id, LPWSTR text)
724 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
725 if (infoPtr->hwndToolTip) {
727 ti.cbSize = sizeof(TTTOOLINFOW);
728 ti.hwnd = infoPtr->Self;
732 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
740 inline static LRESULT
741 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, BOOL bUnicode)
743 BOOL bOld = infoPtr->bUnicode;
745 TRACE("(0x%x)\n", bUnicode);
746 infoPtr->bUnicode = bUnicode;
753 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, BOOL simple)
757 TRACE("(simple=%d)\n", simple);
758 if (infoPtr->simple == simple) /* no need to change */
761 infoPtr->simple = simple;
763 /* send notification */
764 nmhdr.hwndFrom = infoPtr->Self;
765 nmhdr.idFrom = GetWindowLongW (infoPtr->Self, GWL_ID);
766 nmhdr.code = SBN_SIMPLEMODECHANGE;
767 SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY, 0, (LPARAM)&nmhdr);
768 InvalidateRect(infoPtr->Self, NULL, FALSE);
774 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr)
779 for (i = 0; i < infoPtr->numParts; i++) {
780 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
781 COMCTL32_Free (infoPtr->parts[i].text);
783 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
784 COMCTL32_Free (infoPtr->part0.text);
785 COMCTL32_Free (infoPtr->parts);
787 /* delete default font */
788 if (infoPtr->hDefaultFont)
789 DeleteObject (infoPtr->hDefaultFont);
791 /* delete tool tip control */
792 if (infoPtr->hwndToolTip)
793 DestroyWindow (infoPtr->hwndToolTip);
795 COMCTL32_Free (infoPtr);
796 SetWindowLongW(infoPtr->Self, 0, 0);
802 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
804 STATUSWINDOWINFO *infoPtr;
805 NONCLIENTMETRICSW nclm;
808 int i, width, len, textHeight = 0;
812 infoPtr = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
813 if (!infoPtr) goto create_fail;
814 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
816 infoPtr->Self = hwnd;
817 infoPtr->numParts = 1;
819 infoPtr->simple = FALSE;
820 infoPtr->clrBk = CLR_DEFAULT;
823 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
824 infoPtr->NtfUnicode = (i == NFR_UNICODE);
826 GetClientRect (hwnd, &rect);
827 InvalidateRect (hwnd, &rect, 0);
830 ZeroMemory (&nclm, sizeof(nclm));
831 nclm.cbSize = sizeof(nclm);
832 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
833 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
835 /* initialize simple case */
836 infoPtr->part0.bound = rect;
837 infoPtr->part0.text = 0;
838 infoPtr->part0.x = 0;
839 infoPtr->part0.style = 0;
840 infoPtr->part0.hIcon = 0;
842 /* initialize first part */
843 infoPtr->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
844 if (!infoPtr->parts) goto create_fail;
845 infoPtr->parts[0].bound = rect;
846 infoPtr->parts[0].text = 0;
847 infoPtr->parts[0].x = -1;
848 infoPtr->parts[0].style = 0;
849 infoPtr->parts[0].hIcon = 0;
851 if (IsWindowUnicode (hwnd)) {
852 infoPtr->bUnicode = TRUE;
853 if (lpCreate->lpszName &&
854 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
855 infoPtr->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
856 if (!infoPtr->parts[0].text) goto create_fail;
857 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
861 if (lpCreate->lpszName &&
862 (len = strlen((LPCSTR)lpCreate->lpszName))) {
863 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
864 infoPtr->parts[0].text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
865 if (!infoPtr->parts[0].text) goto create_fail;
866 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
867 infoPtr->parts[0].text, lenW );
871 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
873 /* statusbars on managed windows should not have SIZEGRIP style */
874 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
875 if (GetWindowLongW (lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
876 SetWindowLongW (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
878 if ((hdc = GetDC (0))) {
882 hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
883 GetTextMetricsW (hdc, &tm);
884 textHeight = tm.tmHeight;
885 SelectObject (hdc, hOldFont);
888 TRACE(" textHeight=%d\n", textHeight);
890 if (dwStyle & SBT_TOOLTIPS) {
891 infoPtr->hwndToolTip =
892 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
893 CW_USEDEFAULT, CW_USEDEFAULT,
894 CW_USEDEFAULT, CW_USEDEFAULT,
896 GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
898 if (infoPtr->hwndToolTip) {
899 NMTOOLTIPSCREATED nmttc;
901 nmttc.hdr.hwndFrom = hwnd;
902 nmttc.hdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
903 nmttc.hdr.code = NM_TOOLTIPSCREATED;
904 nmttc.hwndToolTips = infoPtr->hwndToolTip;
906 SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
907 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
911 if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
912 GetClientRect (GetParent (hwnd), &rect);
913 width = rect.right - rect.left;
914 infoPtr->height = textHeight + 4 + VERT_BORDER;
915 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
916 width, infoPtr->height, SWP_NOZORDER);
917 STATUSBAR_SetPartBounds (infoPtr);
924 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
929 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
930 * of the first part only (usual behaviour) */
932 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, INT size, LPWSTR buf)
937 if (!(infoPtr->parts[0].text))
939 if (infoPtr->bUnicode)
940 len = strlenW (infoPtr->parts[0].text);
942 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
945 if (infoPtr->bUnicode)
946 strcpyW (buf, infoPtr->parts[0].text);
948 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
949 (LPSTR)buf, len+1, NULL, NULL );
958 STATUSBAR_WMNCHitTest (STATUSWINDOWINFO *infoPtr, INT x, INT y)
960 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
964 GetClientRect (infoPtr->Self, &rect);
968 ScreenToClient (infoPtr->Self, &pt);
970 rect.left = rect.right - 13;
973 if (PtInRect (&rect, pt))
974 return HTBOTTOMRIGHT;
982 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HDC hdc)
987 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
988 hdc = BeginPaint (infoPtr->Self, &ps);
989 STATUSBAR_Refresh (infoPtr, hdc);
990 EndPaint (infoPtr->Self, &ps);
997 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HFONT font, BOOL redraw)
999 infoPtr->hFont = font;
1000 TRACE("%04x\n", infoPtr->hFont);
1002 InvalidateRect(infoPtr->Self, NULL, FALSE);
1009 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, LPCSTR text)
1011 STATUSWINDOWPART *part;
1015 if (infoPtr->numParts == 0)
1018 part = &infoPtr->parts[0];
1019 /* duplicate string */
1021 COMCTL32_Free (part->text);
1023 if (infoPtr->bUnicode) {
1024 if (text && (len = strlenW((LPCWSTR)text))) {
1025 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1026 if (!part->text) return FALSE;
1027 strcpyW (part->text, (LPCWSTR)text);
1031 if (text && (len = lstrlenA(text))) {
1032 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1033 part->text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
1034 if (!part->text) return FALSE;
1035 MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1039 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1046 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, WORD flags)
1051 /* Need to resize width to match parent */
1052 TRACE("flags %04x\n", flags);
1054 if (flags != SIZE_RESTORED) {
1055 WARN("flags MUST be SIZE_RESTORED\n");
1058 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1060 /* width and height don't apply */
1061 GetClientRect (GetParent(infoPtr->Self), &parent_rect);
1062 width = parent_rect.right - parent_rect.left;
1063 x = parent_rect.left;
1064 y = parent_rect.bottom - infoPtr->height;
1065 MoveWindow (infoPtr->Self, parent_rect.left,
1066 parent_rect.bottom - infoPtr->height,
1067 width, infoPtr->height, TRUE);
1068 STATUSBAR_SetPartBounds (infoPtr);
1074 STATUSBAR_NotifyFormat (STATUSWINDOWINFO *infoPtr, HWND from, INT cmd)
1076 if (cmd == NF_REQUERY) {
1077 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1078 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1080 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1085 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1089 TRACE("code %04x\n", code);
1090 nmhdr.hwndFrom = hwnd;
1091 nmhdr.idFrom = GetWindowLongW (hwnd, GWL_ID);
1093 SendMessageW (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1099 static LRESULT WINAPI
1100 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1102 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1103 INT nPart = ((INT) wParam) & 0x00ff;
1106 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1107 if (!infoPtr && msg != WM_CREATE)
1108 return DefWindowProcW (hwnd, msg, wParam, lParam);
1112 return STATUSBAR_GetBorders ((INT *)lParam);
1115 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1118 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1121 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1124 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1127 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1129 case SB_GETTEXTLENGTHA:
1130 case SB_GETTEXTLENGTHW:
1131 return STATUSBAR_GetTextLength (infoPtr, nPart);
1133 case SB_GETTIPTEXTA:
1134 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1136 case SB_GETTIPTEXTW:
1137 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1139 case SB_GETUNICODEFORMAT:
1140 return infoPtr->bUnicode;
1143 return infoPtr->simple;
1146 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1149 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1151 case SB_SETMINHEIGHT:
1152 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1155 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1158 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1161 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1163 case SB_SETTIPTEXTA:
1164 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1166 case SB_SETTIPTEXTW:
1167 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1169 case SB_SETUNICODEFORMAT:
1170 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1173 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1176 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1179 return STATUSBAR_WMDestroy (infoPtr);
1182 return infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont;
1185 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1187 case WM_GETTEXTLENGTH:
1188 return STATUSBAR_GetTextLength (infoPtr, 0);
1190 case WM_LBUTTONDBLCLK:
1191 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1194 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1197 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1200 res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1201 (INT)HIWORD(lParam));
1202 if (res != HTERROR) return res;
1203 return DefWindowProcW (hwnd, msg, wParam, lParam);
1205 case WM_NCLBUTTONUP:
1206 case WM_NCLBUTTONDOWN:
1207 PostMessageW (GetParent (hwnd), msg, wParam, lParam);
1210 case WM_NOTIFYFORMAT:
1211 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1214 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1216 case WM_RBUTTONDBLCLK:
1217 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1220 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1223 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1226 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1229 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1230 return DefWindowProcW (hwnd, msg, wParam, lParam);
1233 if ((msg >= WM_USER) && (msg < WM_APP))
1234 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1235 msg, wParam, lParam);
1236 return DefWindowProcW (hwnd, msg, wParam, lParam);
1242 /***********************************************************************
1243 * STATUS_Register [Internal]
1245 * Registers the status window class.
1249 STATUS_Register (void)
1253 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1254 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1255 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1256 wndClass.cbClsExtra = 0;
1257 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1258 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
1259 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1260 wndClass.lpszClassName = STATUSCLASSNAMEW;
1262 RegisterClassW (&wndClass);
1266 /***********************************************************************
1267 * STATUS_Unregister [Internal]
1269 * Unregisters the status window class.
1273 STATUS_Unregister (void)
1275 UnregisterClassW (STATUSCLASSNAMEW, (HINSTANCE)NULL);