2 * Interface code to StatusWindow widget/control
4 * Copyright 1996 Bruce Milner
16 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
17 * The second cdrom contains executables drawstat.exe,gettext.exe,
18 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
23 * 1) Add size grip to status bar - SBARS_SIZEGRIP
24 * 2) Don't hard code bar to bottom of window, allow CCS_TOP also
25 * 3) Fix SBT_OWNERDRAW
26 * 4) Add DrawStatusText32A funtion
29 static STATUSWINDOWINFO *GetStatusInfo(HWND32 hwnd)
33 wndPtr = WIN_FindWndPtr(hwnd);
34 return ((STATUSWINDOWINFO *) &wndPtr->wExtra[0]);
37 static BOOL32 SW_Refresh( HWND32 hwnd, HDC32 hdc, STATUSWINDOWINFO *self )
41 if (!IsWindowVisible32(hwnd)) {
46 DrawStatusText32A(hdc,
52 for (i = 0; i < self->numParts; i++) {
53 DrawStatusText32A(hdc,
54 &self->parts[i].bound,
56 self->parts[i].style);
65 SW_GetBorders(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
69 /* FIXME for sizegrips */
70 out = (LPINT32) lParam;
71 out[0] = 1; /* vertical border width */
72 out[1] = 1; /* horizontal border width */
73 out[2] = 1; /* width of border between rectangles */
78 SW_SetPartBounds(HWND32 hwnd, STATUSWINDOWINFO *self)
82 STATUSWINDOWPART *part;
85 /* get our window size */
86 GetClientRect32(hwnd, &rect);
88 /* set bounds for simple rectangle */
89 self->part0.bound = rect;
91 /* set bounds for non-simple rectangles */
92 for (i = 0; i < self->numParts; i++) {
93 part = &self->parts[i];
94 r = &self->parts[i].bound;
96 r->bottom = rect.bottom;
100 r->left = self->parts[i-1].bound.right+sep;
102 r->right = rect.right;
109 SW_SetText(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
115 STATUSWINDOWPART *part;
117 text = (LPSTR) lParam;
118 part_num = ((INT32) wParam) & 0x00ff;
119 style = ((INT32) wParam) & 0xff00;
124 if ((self->simple) || (part_num==255))
127 part = &self->parts[part_num];
129 if (style == SBT_OWNERDRAW) {
133 /* duplicate string */
135 HeapFree(SystemHeap, 0, part->text);
137 if (text && (len = lstrlen32A(text))) {
138 part->text = HeapAlloc(SystemHeap, 0, len+1);
139 lstrcpy32A(part->text, text);
142 InvalidateRect32(hwnd, &part->bound, FALSE);
147 SW_SetParts(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
151 STATUSWINDOWPART * tmp;
156 self->simple = FALSE;
158 oldNumParts = self->numParts;
159 self->numParts = (INT32) wParam;
160 parts = (LPINT32) lParam;
161 if (oldNumParts > self->numParts) {
162 for (i = self->numParts ; i < oldNumParts; i++) {
163 if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
164 HeapFree(SystemHeap, 0, self->parts[i].text);
167 else if (oldNumParts < self->numParts) {
168 tmp = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY,
169 sizeof(STATUSWINDOWPART) * self->numParts);
170 for (i = 0; i < oldNumParts; i++) {
171 tmp[i] = self->parts[i];
174 HeapFree(SystemHeap, 0, self->parts);
178 for (i = 0; i < self->numParts; i++) {
179 self->parts[i].x = parts[i];
181 SW_SetPartBounds(hwnd, self);
184 SW_Refresh(hwnd, hdc, self);
185 ReleaseDC32(hwnd, hdc);
190 SW_GetParts(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
196 self = GetStatusInfo(hwnd);
197 num_parts = (INT32) wParam;
198 parts = (LPINT32) lParam;
200 return (self->numParts);
201 for (i = 0; i < num_parts; i++) {
202 parts[i] = self->parts[i].x;
205 return (self->numParts);
209 SW_Create(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
212 LPCREATESTRUCT32A lpCreate = (LPCREATESTRUCT32A) lParam;
220 GetClientRect32(hwnd, &rect);
222 /* initialize simple case */
223 self->part0.bound = rect;
224 self->part0.text = 0;
226 self->part0.style = 0;
229 if ((hdc = GetDC32(0))) {
231 GetTextMetrics32A(hdc, &tm);
232 self->textHeight = tm.tmHeight;
236 parent = GetParent32(hwnd);
237 GetClientRect32(parent, &rect);
238 width = rect.right - rect.left;
239 height = (self->textHeight * 3)/2;
240 MoveWindow32(hwnd, lpCreate->x, lpCreate->y-1, width, height, FALSE);
241 SW_SetPartBounds(hwnd, self);
246 SW_GetRect(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
251 part_num = ((INT32) wParam) & 0x00ff;
252 rect = (LPRECT32) lParam;
254 *rect = self->part0.bound;
256 *rect = self->parts[part_num].bound;
261 SW_GetText(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
265 STATUSWINDOWPART *part;
268 part_num = ((INT32) wParam) & 0x00ff;
269 out_text = (LPSTR) lParam;
273 part = &self->parts[part_num];
275 if (part->style == SBT_OWNERDRAW)
276 result = (LRESULT) part->text;
278 result = part->text ? lstrlen32A(part->text) : 0;
279 result |= (part->style << 16);
281 lstrcpy32A(out_text, part->text);
288 SW_GetTextLength(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
291 STATUSWINDOWPART *part;
294 part_num = ((INT32) wParam) & 0x00ff;
299 part = &self->parts[part_num];
302 result = lstrlen32A(part->text);
306 result |= (part->style << 16);
311 SW_SetMinHeight(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
314 /* size is wParam | 2*pixels_of_horz_border */
319 SW_Simple(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
324 simple = (BOOL32) wParam;
325 self->simple = simple;
327 SW_Refresh(hwnd, hdc, self);
328 ReleaseDC32(hwnd, hdc);
333 SW_Size(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
335 /* Need to resize width to match parent */
336 INT32 width, height, x, y;
342 flags = (INT32) wParam;
345 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED, SIZE_RESTORED
348 if (flags == SIZE_RESTORED) {
349 /* width and height don't apply */
350 parent = GetParent32(hwnd);
351 GetClientRect32(parent, &parent_rect);
352 height = (self->textHeight * 3)/2;
353 width = parent_rect.right - parent_rect.left;
354 x = parent_rect.left;
355 y = parent_rect.bottom - height;
356 MoveWindow32(hwnd, parent_rect.left, parent_rect.bottom - height - 1,
357 width, height, TRUE);
358 SW_SetPartBounds(hwnd, self);
364 SW_Destroy(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
368 for (i = 0; i < self->numParts; i++) {
369 if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
370 HeapFree(SystemHeap, 0, self->parts[i].text);
372 if (self->part0.text && (self->part0.style != SBT_OWNERDRAW))
373 HeapFree(SystemHeap, 0, self->part0.text);
374 HeapFree(SystemHeap, 0, self->parts);
381 SW_Paint(STATUSWINDOWINFO *self, HWND32 hwnd)
386 hdc = BeginPaint32(hwnd, &ps);
387 SW_Refresh(hwnd, hdc, self);
388 EndPaint32(hwnd, &ps);
392 LRESULT WINAPI StatusWindowProc( HWND32 hwnd, UINT32 msg,
393 WPARAM32 wParam, LPARAM lParam )
395 STATUSWINDOWINFO *self;
397 self = GetStatusInfo(hwnd);
401 return SW_GetBorders(self, hwnd, wParam, lParam);
403 return SW_GetParts(self, hwnd, wParam, lParam);
405 return SW_GetRect(self, hwnd, wParam, lParam);
407 return SW_GetText(self, hwnd, wParam, lParam);
408 case SB_GETTEXTLENGTH32A:
409 return SW_GetTextLength(self, hwnd, wParam, lParam);
410 case SB_SETMINHEIGHT:
411 return SW_SetMinHeight(self, hwnd, wParam, lParam);
413 return SW_SetParts(self, hwnd, wParam, lParam);
415 return SW_SetText(self, hwnd, wParam, lParam);
417 return SW_Simple(self, hwnd, wParam, lParam);
420 return SW_Create(self, hwnd, wParam, lParam);
422 return SW_Destroy(self, hwnd, wParam, lParam);
424 return SW_Paint(self, hwnd);
426 return SW_Size(self, hwnd, wParam, lParam);
428 return DefWindowProc32A(hwnd, msg, wParam, lParam);