2 * Interface code to StatusWindow widget/control
4 * Copyright 1996 Bruce Milner
5 * Copyright 1998, 1999 Eric Kohl
9 * 1) Don't hard code bar to bottom of window, allow CCS_TOP also.
10 * 2) Tooltip support (almost done).
11 * 3) where else should we use infoPtr->hwndParent instead of GetParent() ?
12 * 4) send WM_QUERYFORMAT
17 #include "wine/unicode.h"
19 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(statusbar);
42 COLORREF clrBk; /* background color */
43 BOOL bUnicode; /* unicode flag */
44 STATUSWINDOWPART part0; /* simple window */
45 STATUSWINDOWPART *parts;
49 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
50 * The second cdrom contains executables drawstat.exe, gettext.exe,
51 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
58 #define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongA (hwnd, 0))
62 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr, HWND hwnd);
65 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
71 TRACE("draw size grip %d,%d - %d,%d\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
72 pt.x = lpRect->right - 1;
73 pt.y = lpRect->bottom - 1;
75 hOldPen = SelectObject (hdc, GetSysColorPen (COLOR_3DFACE));
76 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
77 LineTo (hdc, pt.x, pt.y);
78 LineTo (hdc, pt.x, pt.y - 12);
83 SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
84 for (i = 1; i < 11; i += 4) {
85 MoveToEx (hdc, pt.x - i, pt.y, NULL);
86 LineTo (hdc, pt.x, pt.y - i);
88 MoveToEx (hdc, pt.x - i-1, pt.y, NULL);
89 LineTo (hdc, pt.x, pt.y - i-1);
92 SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
93 for (i = 3; i < 13; i += 4) {
94 MoveToEx (hdc, pt.x - i, pt.y, NULL);
95 LineTo (hdc, pt.x, pt.y - i);
98 SelectObject (hdc, hOldPen);
103 STATUSBAR_DrawPart (HDC hdc, STATUSWINDOWPART *part)
105 RECT r = part->bound;
106 UINT border = BDR_SUNKENOUTER;
108 TRACE("part bound %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom);
109 if (part->style & SBT_POPOUT)
110 border = BDR_RAISEDOUTER;
111 else if (part->style & SBT_NOBORDERS)
114 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
118 INT cy = r.bottom - r.top;
121 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
127 int oldbkmode = SetBkMode(hdc, TRANSPARENT);
128 LPWSTR p = (LPWSTR)part->text;
129 UINT align = DT_LEFT;
140 TRACE("%s at %d,%d - %d,%d\n", debugstr_w(p), r.left, r.top, r.right, r.bottom);
141 DrawTextW (hdc, p, -1, &r, align|DT_VCENTER|DT_SINGLELINE);
142 if (oldbkmode != TRANSPARENT)
143 SetBkMode(hdc, oldbkmode);
149 STATUSBAR_RefreshPart (STATUSWINDOWINFO *infoPtr, HWND hwnd, STATUSWINDOWPART *part, HDC hdc, int itemID)
154 TRACE("item %d\n", itemID);
155 if (!IsWindowVisible (hwnd))
158 if (part->bound.right < part->bound.left) return;
160 if (infoPtr->clrBk != CLR_DEFAULT)
161 hbrBk = CreateSolidBrush (infoPtr->clrBk);
163 hbrBk = GetSysColorBrush (COLOR_3DFACE);
164 FillRect(hdc, &part->bound, hbrBk);
166 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
168 if (part->style & SBT_OWNERDRAW) {
171 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
175 dis.rcItem = part->bound;
176 dis.itemData = (INT)part->text;
177 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
178 (WPARAM)dis.CtlID, (LPARAM)&dis);
180 STATUSBAR_DrawPart (hdc, part);
182 SelectObject (hdc, hOldFont);
184 if (infoPtr->clrBk != CLR_DEFAULT)
185 DeleteObject (hbrBk);
187 if (GetWindowLongA (hwnd, GWL_STYLE) & SBARS_SIZEGRIP) {
190 GetClientRect (hwnd, &rect);
191 STATUSBAR_DrawSizeGrip (hdc, &rect);
197 STATUSBAR_Refresh (STATUSWINDOWINFO *infoPtr, HWND hwnd, HDC hdc)
205 if (!IsWindowVisible(hwnd))
208 STATUSBAR_SetPartBounds(infoPtr, hwnd);
210 GetClientRect (hwnd, &rect);
212 if (infoPtr->clrBk != CLR_DEFAULT)
213 hbrBk = CreateSolidBrush (infoPtr->clrBk);
215 hbrBk = GetSysColorBrush (COLOR_3DFACE);
216 FillRect(hdc, &rect, hbrBk);
218 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
220 if (infoPtr->simple) {
221 STATUSBAR_RefreshPart (infoPtr, hwnd, &infoPtr->part0, hdc, 0);
223 for (i = 0; i < infoPtr->numParts; i++) {
224 if (infoPtr->parts[i].style & SBT_OWNERDRAW) {
227 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
231 dis.rcItem = infoPtr->parts[i].bound;
232 dis.itemData = (INT)infoPtr->parts[i].text;
233 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
234 (WPARAM)dis.CtlID, (LPARAM)&dis);
236 STATUSBAR_RefreshPart (infoPtr, hwnd, &infoPtr->parts[i], hdc, i);
240 SelectObject (hdc, hOldFont);
242 if (infoPtr->clrBk != CLR_DEFAULT)
243 DeleteObject (hbrBk);
245 if (GetWindowLongA(hwnd, GWL_STYLE) & SBARS_SIZEGRIP)
246 STATUSBAR_DrawSizeGrip (hdc, &rect);
253 STATUSBAR_SetPartBounds (STATUSWINDOWINFO *infoPtr, HWND hwnd)
255 STATUSWINDOWPART *part;
259 /* get our window size */
260 GetClientRect (hwnd, &rect);
261 TRACE("client wnd size is %d,%d - %d,%d\n", rect.left, rect.top, rect.right, rect.bottom);
263 rect.top += VERT_BORDER;
265 /* set bounds for simple rectangle */
266 infoPtr->part0.bound = rect;
268 /* set bounds for non-simple rectangles */
269 for (i = 0; i < infoPtr->numParts; i++) {
270 part = &infoPtr->parts[i];
271 r = &infoPtr->parts[i].bound;
273 r->bottom = rect.bottom;
277 r->left = infoPtr->parts[i-1].bound.right + HORZ_GAP;
279 r->right = rect.right;
283 if (infoPtr->hwndToolTip) {
286 ti.cbSize = sizeof(TTTOOLINFOA);
290 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
298 STATUSBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
299 WPARAM wParam, LPARAM lParam)
307 msg.time = GetMessageTime ();
308 msg.pt.x = LOWORD(GetMessagePos ());
309 msg.pt.y = HIWORD(GetMessagePos ());
311 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
315 inline static LRESULT
316 STATUSBAR_GetBorders (LPARAM lParam)
318 LPINT out = (LPINT) lParam;
321 out[0] = HORZ_BORDER; /* horizontal border width */
322 out[1] = VERT_BORDER; /* vertical border width */
323 out[2] = HORZ_GAP; /* width of border between rectangles */
330 STATUSBAR_GetIcon (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam)
334 nPart = (INT)wParam & 0x00ff;
335 TRACE("%d\n", nPart);
336 if ((nPart < -1) || (nPart >= infoPtr->numParts))
340 return (infoPtr->part0.hIcon);
342 return (infoPtr->parts[nPart].hIcon);
347 STATUSBAR_GetParts (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
353 num_parts = (INT) wParam;
354 TRACE("(%d)\n", num_parts);
355 parts = (LPINT) lParam;
357 for (i = 0; i < num_parts; i++) {
358 parts[i] = infoPtr->parts[i].x;
361 return (infoPtr->numParts);
366 STATUSBAR_GetRect (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
371 nPart = ((INT) wParam) & 0x00ff;
372 TRACE("part %d\n", nPart);
373 rect = (LPRECT) lParam;
375 *rect = infoPtr->part0.bound;
377 *rect = infoPtr->parts[nPart].bound;
383 STATUSBAR_GetTextA (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
385 STATUSWINDOWPART *part;
389 nPart = ((INT) wParam) & 0x00ff;
390 TRACE("part %d\n", nPart);
392 part = &infoPtr->part0;
394 part = &infoPtr->parts[nPart];
396 if (part->style & SBT_OWNERDRAW)
397 result = (LRESULT)part->text;
399 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
400 NULL, 0, NULL, NULL ) - 1 : 0;
401 result = MAKELONG( len, part->style );
403 WideCharToMultiByte( CP_ACP, 0, part->text, -1, (LPSTR)lParam, len+1, NULL, NULL );
410 STATUSBAR_GetTextW (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
412 STATUSWINDOWPART *part;
416 nPart = ((INT)wParam) & 0x00ff;
417 TRACE("part %d\n", nPart);
419 part = &infoPtr->part0;
421 part = &infoPtr->parts[nPart];
423 if (part->style & SBT_OWNERDRAW)
424 result = (LRESULT)part->text;
426 result = part->text ? strlenW (part->text) : 0;
427 result |= (part->style << 16);
428 if (part->text && lParam)
429 strcpyW ((LPWSTR)lParam, part->text);
436 STATUSBAR_GetTextLength (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam)
438 STATUSWINDOWPART *part;
442 nPart = ((INT) wParam) & 0x00ff;
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);
461 STATUSBAR_GetTipTextA (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
463 LPSTR tip = (LPSTR)lParam;
466 CHAR buf[INFOTIPSIZE];
469 if (infoPtr->hwndToolTip) {
471 ti.cbSize = sizeof(TTTOOLINFOA);
473 ti.uId = LOWORD(wParam);
475 SendMessageA(infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
477 lstrcpynA(tip, buf, HIWORD(wParam));
484 STATUSBAR_GetTipTextW (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
486 LPWSTR tip = (LPWSTR)lParam;
490 WCHAR buf[INFOTIPSIZE];
493 if (infoPtr->hwndToolTip) {
495 ti.cbSize = sizeof(TTTOOLINFOW);
497 ti.uId = LOWORD(wParam);
499 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
501 lstrcpynW(tip, buf, HIWORD(wParam));
508 inline static LRESULT
509 STATUSBAR_GetUnicodeFormat (STATUSWINDOWINFO *infoPtr, HWND hwnd)
511 return infoPtr->bUnicode;
515 inline static LRESULT
516 STATUSBAR_IsSimple (STATUSWINDOWINFO *infoPtr, HWND hwnd)
518 return infoPtr->simple;
523 STATUSBAR_SetBkColor (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
527 oldBkColor = infoPtr->clrBk;
528 infoPtr->clrBk = (COLORREF)lParam;
529 InvalidateRect(hwnd, NULL, FALSE);
531 TRACE("CREF: %08lx -> %08lx\n", oldBkColor, infoPtr->clrBk);
537 STATUSBAR_SetIcon (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
539 INT nPart = (INT)wParam & 0x00ff;
541 if ((nPart < -1) || (nPart >= infoPtr->numParts))
544 TRACE("setting part %d, icon %lx\n",nPart,lParam);
547 if (infoPtr->part0.hIcon == (HICON)lParam) /* same as - no redraw */
549 infoPtr->part0.hIcon = (HICON)lParam;
551 InvalidateRect(hwnd, &infoPtr->part0.bound, FALSE);
553 if (infoPtr->parts[nPart].hIcon == (HICON)lParam) /* same as - no redraw */
556 infoPtr->parts[nPart].hIcon = (HICON)lParam;
557 if (!(infoPtr->simple))
558 InvalidateRect(hwnd, &infoPtr->parts[nPart].bound, FALSE);
565 STATUSBAR_SetMinHeight (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
569 if (IsWindowVisible (hwnd)) {
570 HWND parent = GetParent (hwnd);
574 GetClientRect (parent, &parent_rect);
575 infoPtr->height = (INT)wParam + VERT_BORDER;
576 width = parent_rect.right - parent_rect.left;
577 x = parent_rect.left;
578 y = parent_rect.bottom - infoPtr->height;
579 MoveWindow (hwnd, parent_rect.left,
580 parent_rect.bottom - infoPtr->height,
581 width, infoPtr->height, TRUE);
582 STATUSBAR_SetPartBounds (infoPtr, hwnd);
590 STATUSBAR_SetParts (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
592 STATUSWINDOWPART *tmp;
597 TRACE("(%d,%p)\n",wParam,(LPVOID)lParam);
599 /* FIXME: should return FALSE sometimes (maybe when wParam == 0 ?) */
601 infoPtr->simple = FALSE;
603 oldNumParts = infoPtr->numParts;
604 infoPtr->numParts = (INT) wParam;
605 parts = (LPINT) lParam;
606 if (oldNumParts > infoPtr->numParts) {
607 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
608 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
609 COMCTL32_Free (infoPtr->parts[i].text);
612 if (oldNumParts < infoPtr->numParts) {
613 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
614 for (i = 0; i < oldNumParts; i++) {
615 tmp[i] = infoPtr->parts[i];
618 COMCTL32_Free (infoPtr->parts);
619 infoPtr->parts = tmp;
621 if (oldNumParts == infoPtr->numParts) {
622 for (i=0;i<oldNumParts;i++)
623 if (infoPtr->parts[i].x != parts[i])
625 if (i==oldNumParts) /* Unchanged? no need to redraw! */
629 for (i = 0; i < infoPtr->numParts; i++)
630 infoPtr->parts[i].x = parts[i];
632 if (infoPtr->hwndToolTip) {
634 SendMessageA (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
636 if (nTipCount < infoPtr->numParts) {
641 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
642 ti.cbSize = sizeof(TTTOOLINFOA);
644 for (i = nTipCount; i < infoPtr->numParts; i++) {
645 TRACE("add tool %d\n", i);
647 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
651 else if (nTipCount > infoPtr->numParts) {
655 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
656 FIXME("delete tool %d\n", i);
660 STATUSBAR_SetPartBounds (infoPtr, hwnd);
661 InvalidateRect(hwnd, NULL, FALSE);
667 STATUSBAR_SetTextA (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
669 STATUSWINDOWPART *part=NULL;
673 BOOL changed = FALSE;
675 text = (LPSTR) lParam;
676 nPart = ((INT) wParam) & 0x00ff;
677 style = ((INT) wParam) & 0xff00;
679 TRACE("part %d, text %s\n",nPart,debugstr_a(text));
682 part = &infoPtr->part0;
683 else if (!infoPtr->simple && infoPtr->parts!=NULL)
684 part = &infoPtr->parts[nPart];
685 if (!part) return FALSE;
687 if (part->style != style)
691 if (style & SBT_OWNERDRAW) {
692 if (part->text == (LPWSTR)text)
694 part->text = (LPWSTR)text;
698 /* check if text is unchanged -> no need to redraw */
700 DWORD len = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
701 LPWSTR tmptext = COMCTL32_Alloc(len*sizeof(WCHAR));
702 MultiByteToWideChar( CP_ACP, 0, text, -1, tmptext, len );
704 if (!changed && part->text && !lstrcmpW(tmptext,part->text)) {
705 COMCTL32_Free(tmptext);
710 if (!changed && !part->text)
716 COMCTL32_Free (part->text);
719 InvalidateRect(hwnd, &part->bound, FALSE);
726 STATUSBAR_SetTextW (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
728 STATUSWINDOWPART *part;
729 INT nPart, style, len;
731 BOOL bRedraw = FALSE;
733 text = (LPWSTR) lParam;
734 nPart = ((INT) wParam) & 0x00ff;
735 style = ((INT) wParam) & 0xff00;
737 TRACE("part %d -> %s with style %04x\n", nPart, debugstr_w(text), style);
738 if ((infoPtr->simple) || (infoPtr->parts==NULL) || (nPart==255))
739 part = &infoPtr->part0;
741 part = &infoPtr->parts[nPart];
742 if (!part) return FALSE;
744 if(part->style != style)
749 /* FIXME: not sure how/if we can check for change in string with ownerdraw(remove this if we can't)... */
750 if (style & SBT_OWNERDRAW)
758 COMCTL32_Free(part->text);
762 } else if(!part->text || strcmpW(part->text, text)) /* see if the new string differs from the existing string */
764 if(part->text) COMCTL32_Free(part->text);
767 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
768 strcpyW(part->text, text);
773 InvalidateRect(hwnd, &part->bound, FALSE);
780 STATUSBAR_SetTipTextA (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
782 TRACE("part %d: \"%s\"\n", (INT)wParam, (LPSTR)lParam);
783 if (infoPtr->hwndToolTip) {
785 ti.cbSize = sizeof(TTTOOLINFOA);
787 ti.uId = (INT)wParam;
789 ti.lpszText = (LPSTR)lParam;
790 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
799 STATUSBAR_SetTipTextW (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
801 TRACE("part %d: \"%s\"\n", (INT)wParam, (LPSTR)lParam);
802 if (infoPtr->hwndToolTip) {
804 ti.cbSize = sizeof(TTTOOLINFOW);
806 ti.uId = (INT)wParam;
808 ti.lpszText = (LPWSTR)lParam;
809 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
817 inline static LRESULT
818 STATUSBAR_SetUnicodeFormat (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam)
820 BOOL bOld = infoPtr->bUnicode;
822 TRACE("(0x%x)\n", (BOOL)wParam);
823 infoPtr->bUnicode = (BOOL)wParam;
830 STATUSBAR_Simple (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
834 TRACE("(is simple: %d)\n", wParam);
835 if (infoPtr->simple == wParam) /* no need to change */
838 infoPtr->simple = (BOOL)wParam;
840 /* send notification */
841 nmhdr.hwndFrom = hwnd;
842 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
843 nmhdr.code = SBN_SIMPLEMODECHANGE;
844 SendMessageA (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
845 InvalidateRect(hwnd, NULL, FALSE);
851 STATUSBAR_WMCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
853 LPCREATESTRUCTA lpCreate = (LPCREATESTRUCTA)lParam;
854 NONCLIENTMETRICSA nclm;
859 STATUSWINDOWINFO *infoPtr;
862 infoPtr = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
863 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
865 infoPtr->hwndParent = lpCreate->hwndParent;
866 infoPtr->numParts = 1;
868 infoPtr->simple = FALSE;
869 infoPtr->clrBk = CLR_DEFAULT;
872 /* TODO: send unicode parent notification query (WM_QUERYFORMAT) here */
874 GetClientRect (hwnd, &rect);
875 InvalidateRect (hwnd, &rect, 0);
878 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
879 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
880 infoPtr->hDefaultFont = CreateFontIndirectA (&nclm.lfStatusFont);
882 /* initialize simple case */
883 infoPtr->part0.bound = rect;
884 infoPtr->part0.text = 0;
885 infoPtr->part0.x = 0;
886 infoPtr->part0.style = 0;
887 infoPtr->part0.hIcon = 0;
889 /* initialize first part */
890 infoPtr->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
891 infoPtr->parts[0].bound = rect;
892 infoPtr->parts[0].text = 0;
893 infoPtr->parts[0].x = -1;
894 infoPtr->parts[0].style = 0;
895 infoPtr->parts[0].hIcon = 0;
897 if (IsWindowUnicode (hwnd)) {
898 infoPtr->bUnicode = TRUE;
899 if (lpCreate->lpszName &&
900 (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
901 infoPtr->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
902 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
906 if (lpCreate->lpszName &&
907 (len = strlen((LPCSTR)lpCreate->lpszName))) {
908 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
909 infoPtr->parts[0].text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
910 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
911 infoPtr->parts[0].text, lenW );
915 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
917 /* statusbars on managed windows should not have SIZEGRIP style */
918 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
919 if (GetWindowLongA(lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
920 SetWindowLongA (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
922 if ((hdc = GetDC (0))) {
926 hOldFont = SelectObject (hdc,infoPtr->hDefaultFont);
927 GetTextMetricsA(hdc, &tm);
928 infoPtr->textHeight = tm.tmHeight;
929 SelectObject (hdc, hOldFont);
933 if (dwStyle & SBT_TOOLTIPS) {
934 infoPtr->hwndToolTip =
935 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
936 CW_USEDEFAULT, CW_USEDEFAULT,
937 CW_USEDEFAULT, CW_USEDEFAULT,
939 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
941 if (infoPtr->hwndToolTip) {
942 NMTOOLTIPSCREATED nmttc;
944 nmttc.hdr.hwndFrom = hwnd;
945 nmttc.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
946 nmttc.hdr.code = NM_TOOLTIPSCREATED;
947 nmttc.hwndToolTips = infoPtr->hwndToolTip;
949 SendMessageA (lpCreate->hwndParent, WM_NOTIFY,
950 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
954 if (!dwStyle & CCS_NORESIZE) /* don't resize wnd if it doesn't want it ! */
956 GetClientRect (GetParent (hwnd), &rect);
957 width = rect.right - rect.left;
958 infoPtr->height = infoPtr->textHeight + 4 + VERT_BORDER;
959 SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
960 width, infoPtr->height, SWP_NOZORDER);
961 STATUSBAR_SetPartBounds (infoPtr, hwnd);
969 STATUSBAR_WMDestroy (STATUSWINDOWINFO *infoPtr, HWND hwnd)
974 for (i = 0; i < infoPtr->numParts; i++) {
975 if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
976 COMCTL32_Free (infoPtr->parts[i].text);
978 if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
979 COMCTL32_Free (infoPtr->part0.text);
980 COMCTL32_Free (infoPtr->parts);
982 /* delete default font */
983 if (infoPtr->hDefaultFont)
984 DeleteObject (infoPtr->hDefaultFont);
986 /* delete tool tip control */
987 if (infoPtr->hwndToolTip)
988 DestroyWindow (infoPtr->hwndToolTip);
990 COMCTL32_Free (infoPtr);
991 SetWindowLongA(hwnd, 0, 0);
996 static inline LRESULT
997 STATUSBAR_WMGetFont (STATUSWINDOWINFO *infoPtr, HWND hwnd)
1000 return infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont;
1004 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
1005 * of the first part only (usual behaviour) */
1007 STATUSBAR_WMGetText (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
1012 if (!(infoPtr->parts[0].text))
1014 if (infoPtr->bUnicode)
1015 len = strlenW (infoPtr->parts[0].text);
1017 len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
1020 if (infoPtr->bUnicode)
1021 strcpyW ((LPWSTR)lParam, infoPtr->parts[0].text);
1023 WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
1024 (LPSTR)lParam, len+1, NULL, NULL );
1032 inline static LRESULT
1033 STATUSBAR_WMMouseMove (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
1035 if (infoPtr->hwndToolTip)
1036 STATUSBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
1037 WM_MOUSEMOVE, wParam, lParam);
1043 STATUSBAR_WMNCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
1045 if (GetWindowLongA (hwnd, GWL_STYLE) & SBARS_SIZEGRIP) {
1049 GetClientRect (hwnd, &rect);
1051 pt.x = (INT)LOWORD(lParam);
1052 pt.y = (INT)HIWORD(lParam);
1053 ScreenToClient (hwnd, &pt);
1055 rect.left = rect.right - 13;
1058 if (PtInRect (&rect, pt))
1059 return HTBOTTOMRIGHT;
1062 /* FIXME: instead check result in StatusWindowProc and call if needed ? */
1063 return DefWindowProcA (hwnd, WM_NCHITTEST, wParam, lParam);
1067 static inline LRESULT
1068 STATUSBAR_WMNCLButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1071 PostMessageA (GetParent (hwnd), WM_NCLBUTTONDOWN, wParam, lParam);
1076 static inline LRESULT
1077 STATUSBAR_WMNCLButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1080 PostMessageA (GetParent (hwnd), WM_NCLBUTTONUP, wParam, lParam);
1086 STATUSBAR_WMPaint (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam)
1092 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1093 STATUSBAR_Refresh (infoPtr, hwnd, hdc);
1095 EndPaint (hwnd, &ps);
1102 STATUSBAR_WMSetFont (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
1104 infoPtr->hFont = (HFONT)wParam;
1105 TRACE("%04x\n", infoPtr->hFont);
1106 if (LOWORD(lParam) == TRUE)
1107 InvalidateRect(hwnd, NULL, FALSE);
1114 STATUSBAR_WMSetText (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
1116 STATUSWINDOWPART *part;
1120 if (infoPtr->numParts == 0)
1123 part = &infoPtr->parts[0];
1124 /* duplicate string */
1126 COMCTL32_Free (part->text);
1128 if (infoPtr->bUnicode) {
1129 if (lParam && (len = strlenW((LPCWSTR)lParam))) {
1130 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1131 strcpyW (part->text, (LPCWSTR)lParam);
1135 if (lParam && (len = lstrlenA((LPCSTR)lParam))) {
1136 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lParam, -1, NULL, 0 );
1137 part->text = COMCTL32_Alloc (lenW*sizeof(WCHAR));
1138 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lParam, -1, part->text, lenW );
1142 InvalidateRect(hwnd, &part->bound, FALSE);
1149 STATUSBAR_WMSize (STATUSWINDOWINFO *infoPtr, HWND hwnd, WPARAM wParam, LPARAM lParam)
1151 INT width, x, y, flags;
1155 /* Need to resize width to match parent */
1156 flags = (INT) wParam;
1158 TRACE("flags %04x\n", flags);
1159 /* FIXME for flags =
1160 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED, SIZE_RESTORED
1163 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1164 if (!dwStyle & CCS_NORESIZE) /* don't resize wnd if it doesn't want it ! */
1166 if (flags == SIZE_RESTORED) {
1167 /* width and height don't apply */
1168 GetClientRect (infoPtr->hwndParent, &parent_rect);
1169 width = parent_rect.right - parent_rect.left;
1170 x = parent_rect.left;
1171 y = parent_rect.bottom - infoPtr->height;
1172 MoveWindow (hwnd, parent_rect.left,
1173 parent_rect.bottom - infoPtr->height,
1174 width, infoPtr->height, TRUE);
1175 STATUSBAR_SetPartBounds (infoPtr, hwnd);
1177 return 0; /* FIXME: ok to return here ? */
1180 /* FIXME: instead check result in StatusWindowProc and call if needed ? */
1181 return DefWindowProcA (hwnd, WM_SIZE, wParam, lParam);
1186 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1190 TRACE("code %04x\n", code);
1191 nmhdr.hwndFrom = hwnd;
1192 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1194 SendMessageA (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1200 static LRESULT WINAPI
1201 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1203 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr(hwnd);
1205 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1206 if (!(infoPtr) && (msg != WM_CREATE))
1207 return DefWindowProcA (hwnd, msg, wParam, lParam);
1211 return STATUSBAR_GetBorders (lParam);
1214 return STATUSBAR_GetIcon (infoPtr, hwnd, wParam);
1217 return STATUSBAR_GetParts (infoPtr, hwnd, wParam, lParam);
1220 return STATUSBAR_GetRect (infoPtr, hwnd, wParam, lParam);
1223 return STATUSBAR_GetTextA (infoPtr, hwnd, wParam, lParam);
1226 return STATUSBAR_GetTextW (infoPtr, hwnd, wParam, lParam);
1228 case SB_GETTEXTLENGTHA:
1229 case SB_GETTEXTLENGTHW:
1230 return STATUSBAR_GetTextLength (infoPtr, hwnd, wParam);
1232 case SB_GETTIPTEXTA:
1233 return STATUSBAR_GetTipTextA (infoPtr, hwnd, wParam, lParam);
1235 case SB_GETTIPTEXTW:
1236 return STATUSBAR_GetTipTextW (infoPtr, hwnd, wParam, lParam);
1238 case SB_GETUNICODEFORMAT:
1239 return STATUSBAR_GetUnicodeFormat (infoPtr, hwnd);
1242 return STATUSBAR_IsSimple (infoPtr, hwnd);
1245 return STATUSBAR_SetBkColor (infoPtr, hwnd, wParam, lParam);
1248 return STATUSBAR_SetIcon (infoPtr, hwnd, wParam, lParam);
1250 case SB_SETMINHEIGHT:
1251 return STATUSBAR_SetMinHeight (infoPtr, hwnd, wParam, lParam);
1254 return STATUSBAR_SetParts (infoPtr, hwnd, wParam, lParam);
1257 return STATUSBAR_SetTextA (infoPtr, hwnd, wParam, lParam);
1260 return STATUSBAR_SetTextW (infoPtr, hwnd, wParam, lParam);
1262 case SB_SETTIPTEXTA:
1263 return STATUSBAR_SetTipTextA (infoPtr, hwnd, wParam, lParam);
1265 case SB_SETTIPTEXTW:
1266 return STATUSBAR_SetTipTextW (infoPtr, hwnd, wParam, lParam);
1268 case SB_SETUNICODEFORMAT:
1269 return STATUSBAR_SetUnicodeFormat (infoPtr, hwnd, wParam);
1272 return STATUSBAR_Simple (infoPtr, hwnd, wParam, lParam);
1276 return STATUSBAR_WMCreate (hwnd, wParam, lParam);
1279 return STATUSBAR_WMDestroy (infoPtr, hwnd);
1282 return STATUSBAR_WMGetFont (infoPtr, hwnd);
1285 return STATUSBAR_WMGetText (infoPtr, hwnd, wParam, lParam);
1287 case WM_GETTEXTLENGTH:
1288 return STATUSBAR_GetTextLength (infoPtr, hwnd, 0);
1290 case WM_LBUTTONDBLCLK:
1291 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1294 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1297 return STATUSBAR_WMMouseMove (infoPtr, hwnd, wParam, lParam);
1300 return STATUSBAR_WMNCHitTest (hwnd, wParam, lParam);
1302 case WM_NCLBUTTONDOWN:
1303 return STATUSBAR_WMNCLButtonDown (hwnd, wParam, lParam);
1305 case WM_NCLBUTTONUP:
1306 return STATUSBAR_WMNCLButtonUp (hwnd, wParam, lParam);
1309 return STATUSBAR_WMPaint (infoPtr, hwnd, wParam);
1311 case WM_RBUTTONDBLCLK:
1312 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1315 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1318 return STATUSBAR_WMSetFont (infoPtr, hwnd, wParam, lParam);
1321 return STATUSBAR_WMSetText (infoPtr, hwnd, wParam, lParam);
1324 return STATUSBAR_WMSize (infoPtr, hwnd, wParam, lParam);
1328 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1329 msg, wParam, lParam);
1330 return DefWindowProcA (hwnd, msg, wParam, lParam);
1336 /***********************************************************************
1337 * STATUS_Register [Internal]
1339 * Registers the status window class.
1343 STATUS_Register (void)
1347 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1348 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1349 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1350 wndClass.cbClsExtra = 0;
1351 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1352 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1353 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1354 wndClass.lpszClassName = STATUSCLASSNAMEA;
1356 RegisterClassA (&wndClass);
1360 /***********************************************************************
1361 * STATUS_Unregister [Internal]
1363 * Unregisters the status window class.
1367 STATUS_Unregister (void)
1369 UnregisterClassA (STATUSCLASSNAMEA, (HINSTANCE)NULL);