2 * Interface code to StatusWindow widget/control
4 * Copyright 1996 Bruce Milner
5 * Copyright 1998 Eric Kohl
15 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
16 * The second cdrom contains executables drawstat.exe,gettext.exe,
17 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
22 * 1) Don't hard code bar to bottom of window, allow CCS_TOP also.
26 #define _MAX(a,b) (((a)>(b))?(a):(b))
27 #define _MIN(a,b) (((a)>(b))?(b):(a))
34 static STATUSWINDOWINFO *GetStatusInfo(HWND32 hwnd)
38 wndPtr = WIN_FindWndPtr(hwnd);
39 return ((STATUSWINDOWINFO *) wndPtr->wExtra[0]);
44 STATUS_DrawSizeGrip (HDC32 hdc, LPRECT32 lpRect)
50 pt.x = lpRect->right - 1;
51 pt.y = lpRect->bottom - 1;
53 hOldPen = SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DFACE));
54 MoveToEx32 (hdc, pt.x - 12, pt.y, NULL);
55 LineTo32 (hdc, pt.x, pt.y);
56 LineTo32 (hdc, pt.x, pt.y - 12);
61 SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DSHADOW));
62 for (i = 1; i < 11; i += 4) {
63 MoveToEx32 (hdc, pt.x - i, pt.y, NULL);
64 LineTo32 (hdc, pt.x, pt.y - i);
66 MoveToEx32 (hdc, pt.x - i-1, pt.y, NULL);
67 LineTo32 (hdc, pt.x, pt.y - i-1);
70 SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DHIGHLIGHT));
71 for (i = 3; i < 13; i += 4) {
72 MoveToEx32 (hdc, pt.x - i, pt.y, NULL);
73 LineTo32 (hdc, pt.x, pt.y - i);
76 SelectObject32 (hdc, hOldPen);
81 SB_DrawPart( HDC32 hdc, LPRECT32 lprc, HICON32 hIcon,
82 LPCSTR text, UINT32 style )
85 UINT32 border = BDR_SUNKENOUTER;
87 if (style==SBT_POPOUT)
88 border = BDR_RAISEDOUTER;
89 else if (style==SBT_NOBORDERS)
92 DrawEdge32(hdc, &r, border, BF_RECT|BF_ADJUST);
96 INT32 cy = r.bottom - r.top;
99 DrawIconEx32 (hdc, r.left, r.top, hIcon, cy, cy, 0, 0, DI_NORMAL);
105 int oldbkmode = SetBkMode32(hdc, TRANSPARENT);
106 LPSTR p = (LPSTR)text;
107 UINT32 align = DT_LEFT;
118 DrawText32A(hdc, p, lstrlen32A(p), &r, align|DT_VCENTER|DT_SINGLELINE);
119 if (oldbkmode != TRANSPARENT)
120 SetBkMode32(hdc, oldbkmode);
126 SW_Refresh( HWND32 hwnd, HDC32 hdc, STATUSWINDOWINFO *self )
134 wndPtr = WIN_FindWndPtr(hwnd);
136 if (!IsWindowVisible32(hwnd)) {
140 GetClientRect32 (hwnd, &rect);
142 if (self->clrBk != CLR_DEFAULT)
143 hbrBk = CreateSolidBrush32 (self->clrBk);
145 hbrBk = GetSysColorBrush32 (COLOR_3DFACE);
146 FillRect32(hdc, &rect, hbrBk);
148 hOldFont = SelectObject32 (hdc, self->hFont ? self->hFont : self->hDefaultFont);
158 for (i = 0; i < self->numParts; i++) {
159 if (self->parts[i].style == SBT_OWNERDRAW) {
160 DRAWITEMSTRUCT32 dis;
161 WND *wndPtr = WIN_FindWndPtr(hwnd);
163 dis.CtlID = wndPtr->wIDmenu;
167 dis.rcItem = self->part0.bound;
168 dis.itemData = (INT32)self->part0.text;
169 SendMessage32A (GetParent32 (hwnd), WM_DRAWITEM,
170 (WPARAM32)wndPtr->wIDmenu, (LPARAM)&dis);
174 &self->parts[i].bound,
175 self->parts[i].hIcon,
177 self->parts[i].style);
181 SelectObject32 (hdc, hOldFont);
183 if (self->clrBk != CLR_DEFAULT)
184 DeleteObject32 (hbrBk);
186 if (wndPtr->dwStyle & SBARS_SIZEGRIP)
187 STATUS_DrawSizeGrip (hdc, &rect);
194 SW_GetBorders(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
198 out = (LPINT32) lParam;
199 out[0] = HORZ_BORDER; /* horizontal border width */
200 out[1] = VERT_BORDER; /* vertical border width */
201 out[2] = HORZ_GAP; /* width of border between rectangles */
206 SW_SetPartBounds(HWND32 hwnd, STATUSWINDOWINFO *self)
210 STATUSWINDOWPART *part;
212 /* get our window size */
213 GetClientRect32(hwnd, &rect);
215 rect.top += VERT_BORDER;
217 /* set bounds for simple rectangle */
218 self->part0.bound = rect;
220 /* set bounds for non-simple rectangles */
221 for (i = 0; i < self->numParts; i++) {
222 part = &self->parts[i];
223 r = &self->parts[i].bound;
225 r->bottom = rect.bottom;
229 r->left = self->parts[i-1].bound.right + HORZ_GAP;
231 r->right = rect.right;
238 SW_SetText(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
244 STATUSWINDOWPART *part;
246 text = (LPSTR) lParam;
247 part_num = ((INT32) wParam) & 0x00ff;
248 style = ((INT32) wParam) & 0xff00;
250 if ((self->simple) || (self->parts==NULL) || (part_num==255))
253 part = &self->parts[part_num];
254 if (!part) return FALSE;
256 if (style == SBT_OWNERDRAW) {
260 /* duplicate string */
262 HeapFree(SystemHeap, 0, part->text);
264 if (text && (len = lstrlen32A(text))) {
265 part->text = HeapAlloc(SystemHeap, 0, len+1);
266 lstrcpy32A(part->text, text);
269 InvalidateRect32(hwnd, &part->bound, FALSE);
270 // SW_RefreshPart (hdc, part);
275 SW_SetParts(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
279 STATUSWINDOWPART * tmp;
284 self->simple = FALSE;
286 oldNumParts = self->numParts;
287 self->numParts = (INT32) wParam;
288 parts = (LPINT32) lParam;
289 if (oldNumParts > self->numParts) {
290 for (i = self->numParts ; i < oldNumParts; i++) {
291 if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
292 HeapFree(SystemHeap, 0, self->parts[i].text);
295 else if (oldNumParts < self->numParts) {
296 tmp = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY,
297 sizeof(STATUSWINDOWPART) * self->numParts);
298 for (i = 0; i < oldNumParts; i++) {
299 tmp[i] = self->parts[i];
302 HeapFree(SystemHeap, 0, self->parts);
306 for (i = 0; i < self->numParts; i++) {
307 self->parts[i].x = parts[i];
309 SW_SetPartBounds(hwnd, self);
312 SW_Refresh(hwnd, hdc, self);
313 ReleaseDC32(hwnd, hdc);
318 SW_GetParts(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
324 self = GetStatusInfo(hwnd);
325 num_parts = (INT32) wParam;
326 parts = (LPINT32) lParam;
328 return (self->numParts);
329 for (i = 0; i < num_parts; i++) {
330 parts[i] = self->parts[i].x;
333 return (self->numParts);
337 SW_Create(HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
339 LPCREATESTRUCT32A lpCreate = (LPCREATESTRUCT32A) lParam;
340 NONCLIENTMETRICS32A nclm;
346 STATUSWINDOWINFO *self;
348 wndPtr = WIN_FindWndPtr(hwnd);
349 self = (STATUSWINDOWINFO*)HeapAlloc (SystemHeap, HEAP_ZERO_MEMORY,
350 sizeof(STATUSWINDOWINFO));
351 wndPtr->wExtra[0] = (DWORD)self;
355 self->simple = FALSE;
356 self->clrBk = CLR_DEFAULT;
358 GetClientRect32(hwnd, &rect);
360 nclm.cbSize = sizeof(NONCLIENTMETRICS32A);
361 SystemParametersInfo32A (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
362 self->hDefaultFont = CreateFontIndirect32A (&nclm.lfStatusFont);
364 /* initialize simple case */
365 self->part0.bound = rect;
366 self->part0.text = 0;
368 self->part0.style = 0;
369 self->part0.hIcon = 0;
371 /* initialize first part */
372 self->parts = HeapAlloc (SystemHeap, HEAP_ZERO_MEMORY,
373 sizeof(STATUSWINDOWPART));
374 self->parts[0].bound = rect;
375 self->parts[0].text = 0;
376 self->parts[0].x = -1;
377 self->parts[0].style = 0;
378 self->parts[0].hIcon = 0;
380 if ((len = lstrlen32A (lpCreate->lpszName))) {
381 self->parts[0].text = HeapAlloc (SystemHeap, 0, len + 1);
382 lstrcpy32A (self->parts[0].text, lpCreate->lpszName);
385 if ((hdc = GetDC32 (0))) {
389 hOldFont = SelectObject32 (hdc,self->hDefaultFont);
390 GetTextMetrics32A(hdc, &tm);
391 self->textHeight = tm.tmHeight;
392 SelectObject32 (hdc, hOldFont);
396 parent = GetParent32 (hwnd);
397 GetClientRect32 (parent, &rect);
398 width = rect.right - rect.left;
399 self->height = self->textHeight + 4 + VERT_BORDER;
400 MoveWindow32 (hwnd, lpCreate->x, lpCreate->y-1, width, self->height, FALSE);
401 SW_SetPartBounds (hwnd, self);
406 SW_GetRect(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
411 part_num = ((INT32) wParam) & 0x00ff;
412 rect = (LPRECT32) lParam;
414 *rect = self->part0.bound;
416 *rect = self->parts[part_num].bound;
421 SW_GetText(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
425 STATUSWINDOWPART *part;
428 part_num = ((INT32) wParam) & 0x00ff;
429 out_text = (LPSTR) lParam;
433 part = &self->parts[part_num];
435 if (part->style == SBT_OWNERDRAW)
436 result = (LRESULT) part->text;
438 result = part->text ? lstrlen32A(part->text) : 0;
439 result |= (part->style << 16);
441 lstrcpy32A(out_text, part->text);
448 SW_GetTextLength(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
451 STATUSWINDOWPART *part;
454 part_num = ((INT32) wParam) & 0x00ff;
459 part = &self->parts[part_num];
462 result = lstrlen32A(part->text);
466 result |= (part->style << 16);
471 SW_SetMinHeight(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
477 if (IsWindowVisible32 (hwnd)) {
478 parent = GetParent32(hwnd);
479 GetClientRect32(parent, &parent_rect);
480 self->height = (INT32)wParam + VERT_BORDER;
481 width = parent_rect.right - parent_rect.left;
482 x = parent_rect.left;
483 y = parent_rect.bottom - self->height;
484 MoveWindow32(hwnd, parent_rect.left, parent_rect.bottom - self->height,
485 width, self->height, TRUE);
486 SW_SetPartBounds(hwnd, self);
493 SW_SetBkColor(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
498 oldBkColor = self->clrBk;
499 self->clrBk = (COLORREF)lParam;
501 SW_Refresh(hwnd, hdc, self);
502 ReleaseDC32(hwnd, hdc);
508 SW_SetIcon (STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
510 INT32 nPart = (INT32)wParam & 0x00ff;
512 if ((nPart < -1) || (nPart >= self->numParts)) return FALSE;
515 self->part0.hIcon = (HICON32)lParam;
517 InvalidateRect32(hwnd, &self->part0.bound, FALSE);
520 self->parts[nPart].hIcon = (HICON32)lParam;
522 InvalidateRect32(hwnd, &self->parts[nPart].bound, FALSE);
528 SW_GetIcon(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
532 nPart = (INT32)wParam & 0x00ff;
533 if ((nPart < -1) || (nPart >= self->numParts)) return 0;
536 return (self->part0.hIcon);
538 return (self->parts[nPart].hIcon);
542 SW_Simple(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
549 wndPtr = WIN_FindWndPtr(hwnd);
551 simple = (BOOL32) wParam;
552 self->simple = simple;
554 /* send notification */
555 nmhdr.hwndFrom = hwnd;
556 nmhdr.idFrom = wndPtr->wIDmenu;
557 nmhdr.code = SBN_SIMPLEMODECHANGE;
558 SendMessage32A (GetParent32 (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
561 SW_Refresh(hwnd, hdc, self);
562 ReleaseDC32(hwnd, hdc);
569 SW_Destroy(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
573 for (i = 0; i < self->numParts; i++) {
574 if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
575 HeapFree(SystemHeap, 0, self->parts[i].text);
577 if (self->part0.text && (self->part0.style != SBT_OWNERDRAW))
578 HeapFree(SystemHeap, 0, self->part0.text);
579 HeapFree(SystemHeap, 0, self->parts);
581 /* delete default font */
582 if (self->hDefaultFont)
583 DeleteObject32 (self->hDefaultFont);
585 HeapFree(SystemHeap, 0, self);
591 SW_WMGetText (STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
595 if (!(self->parts[0].text))
597 len = lstrlen32A (self->parts[0].text);
599 lstrcpy32A ((LPSTR)lParam, self->parts[0].text);
608 SW_WMGetTextLength (STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
610 if (!(self->parts[0].text))
612 return (lstrlen32A (self->parts[0].text));
617 SW_NcHitTest (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
622 if (wndPtr->dwStyle & SBARS_SIZEGRIP) {
623 GetClientRect32 (wndPtr->hwndSelf, &rect);
625 pt.x = (INT32)LOWORD(lParam);
626 pt.y = (INT32)HIWORD(lParam);
627 ScreenToClient32 (wndPtr->hwndSelf, &pt);
629 rect.left = rect.right - 13;
632 if (PtInRect32 (&rect, pt))
633 return HTBOTTOMRIGHT;
636 return DefWindowProc32A (wndPtr->hwndSelf, WM_NCHITTEST, wParam, lParam);
641 SW_NcLButtonDown (HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
643 PostMessage32A (GetParent32 (hwnd), WM_NCLBUTTONDOWN,
650 SW_NcLButtonUp (HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
652 PostMessage32A (GetParent32 (hwnd), WM_NCLBUTTONUP,
659 SW_Paint(STATUSWINDOWINFO *self, HWND32 hwnd)
664 hdc = BeginPaint32(hwnd, &ps);
665 SW_Refresh(hwnd, hdc, self);
666 EndPaint32(hwnd, &ps);
672 SW_WMSetFont (STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
676 self->hFont = (HFONT32)wParam;
677 if (LOWORD(lParam) == TRUE) {
679 SW_Refresh(hwnd, hdc, self);
680 ReleaseDC32(hwnd, hdc);
687 SW_WMSetText (STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
690 STATUSWINDOWPART *part;
692 if (self->numParts == 0) return FALSE;
694 part = &self->parts[0];
695 /* duplicate string */
697 HeapFree(SystemHeap, 0, part->text);
699 if (lParam && (len = lstrlen32A((LPCSTR)lParam))) {
700 part->text = HeapAlloc (SystemHeap, 0, len+1);
701 lstrcpy32A (part->text, (LPCSTR)lParam);
703 InvalidateRect32(hwnd, &part->bound, FALSE);
704 // SW_RefreshPart (hdc, part);
711 SW_Size(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
713 /* Need to resize width to match parent */
720 flags = (INT32) wParam;
723 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED, SIZE_RESTORED
726 if (flags == SIZE_RESTORED) {
727 /* width and height don't apply */
728 parent = GetParent32(hwnd);
729 GetClientRect32(parent, &parent_rect);
730 width = parent_rect.right - parent_rect.left;
731 x = parent_rect.left;
732 y = parent_rect.bottom - self->height;
733 MoveWindow32(hwnd, parent_rect.left, parent_rect.bottom - self->height,
734 width, self->height, TRUE);
735 SW_SetPartBounds(hwnd, self);
742 SW_SendNotify (HWND32 hwnd, UINT32 code)
747 wndPtr = WIN_FindWndPtr(hwnd);
748 nmhdr.hwndFrom = hwnd;
749 nmhdr.idFrom = wndPtr->wIDmenu;
751 SendMessage32A (GetParent32 (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
759 StatusWindowProc (HWND32 hwnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam)
761 STATUSWINDOWINFO *self;
764 wndPtr = WIN_FindWndPtr(hwnd);
765 self = GetStatusInfo(hwnd);
769 return SW_GetBorders(self, hwnd, wParam, lParam);
771 return SW_GetIcon(self, hwnd, wParam, lParam);
773 return SW_GetParts(self, hwnd, wParam, lParam);
775 return SW_GetRect(self, hwnd, wParam, lParam);
777 return SW_GetText(self, hwnd, wParam, lParam);
778 case SB_GETTEXTLENGTH32A:
779 return SW_GetTextLength(self, hwnd, wParam, lParam);
783 return SW_SetBkColor(self, hwnd, wParam, lParam);
785 return SW_SetIcon(self, hwnd, wParam, lParam);
786 case SB_SETMINHEIGHT:
787 return SW_SetMinHeight(self, hwnd, wParam, lParam);
789 return SW_SetParts(self, hwnd, wParam, lParam);
791 return SW_SetText(self, hwnd, wParam, lParam);
793 return SW_Simple(self, hwnd, wParam, lParam);
796 return SW_Create(hwnd, wParam, lParam);
798 return SW_Destroy(self, hwnd, wParam, lParam);
802 return SW_WMGetText(self, hwnd, wParam, lParam);
803 case WM_GETTEXTLENGTH:
804 return SW_WMGetTextLength(self, hwnd, wParam, lParam);
806 case WM_LBUTTONDBLCLK:
807 return SW_SendNotify (hwnd, NM_DBLCLK);
810 return SW_SendNotify (hwnd, NM_CLICK);
813 return SW_NcHitTest (wndPtr, wParam, lParam);
815 case WM_NCLBUTTONDOWN:
816 return SW_NcLButtonDown (hwnd, wParam, lParam);
819 return SW_NcLButtonUp (hwnd, wParam, lParam);
822 return SW_Paint(self, hwnd);
823 case WM_RBUTTONDBLCLK:
824 return SW_SendNotify (hwnd, NM_RDBLCLK);
826 return SW_SendNotify (hwnd, NM_RCLICK);
828 return SW_WMSetFont(self, hwnd, wParam, lParam);
830 return SW_WMSetText(self, hwnd, wParam, lParam);
832 return SW_Size(self, hwnd, wParam, lParam);
834 return DefWindowProc32A (hwnd, msg, wParam, lParam);
840 /***********************************************************************
841 * STATUS_Register [Internal]
843 * Registers the status window class.
845 void STATUS_Register (void)
847 WNDCLASS32A wndClass;
849 if (GlobalFindAtom32A (STATUSCLASSNAME32A)) return;
851 ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
852 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
853 wndClass.lpfnWndProc = (WNDPROC32)StatusWindowProc;
854 wndClass.cbClsExtra = 0;
855 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
856 wndClass.hCursor = LoadCursor32A (0, IDC_ARROW32A);
857 wndClass.hbrBackground = (HBRUSH32)(COLOR_3DFACE + 1);
858 wndClass.lpszClassName = STATUSCLASSNAME32A;
860 RegisterClass32A (&wndClass);