Release 961222
[wine/multimedia.git] / controls / status.c
blobccb188bac54ebb47c6b35bf4a5878279795c4041
1 /*
2 * Interface code to StatusWindow widget/control
4 * Copyright 1996 Bruce Milner
5 */
7 #define NO_TRANSITION_TYPES /* This file is Win32-clean */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "windows.h"
11 #include "status.h"
12 #include "commctrl.h"
13 #include "heap.h"
14 #include "syscolor.h"
15 #include "win.h"
18 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
19 * The second cdrom contains executables drawstat.exe,gettext.exe,
20 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
24 * Fixme/Todo
25 * 1) Add size grip to status bar - SBARS_SIZEGRIP
26 * 2) Don't hard code bar to bottom of window, allow CCS_TOP also
27 * 3) Fix SBT_OWNERDRAW
28 * 4) Add DrawStatusText32A funtion
31 static STATUSWINDOWINFO *GetStatusInfo(HWND32 hwnd)
33 WND *wndPtr;
35 wndPtr = WIN_FindWndPtr(hwnd);
36 return ((STATUSWINDOWINFO *) &wndPtr->wExtra[0]);
39 /***********************************************************************
40 * DrawStatusText32A (COMCTL32.3)
42 void DrawStatusText32A( HDC32 hdc, LPRECT32 lprc, LPCSTR text, UINT32 style )
44 RECT32 r, rt;
45 int oldbkmode;
47 r = *lprc;
49 if (style == 0 ||
50 style == SBT_POPOUT) {
51 InflateRect32(&r, -1, -1);
52 SelectObject32(hdc, sysColorObjects.hbrushScrollbar);
53 Rectangle32(hdc, r.left, r.top, r.right, r.bottom);
55 /* draw border */
56 SelectObject32(hdc, sysColorObjects.hpenWindowFrame);
57 if (style == 0)
58 DrawEdge32(hdc, &r, EDGE_SUNKEN, BF_RECT);
59 else
60 DrawEdge32(hdc, &r, EDGE_RAISED, BF_RECT);
62 else if (style == SBT_NOBORDERS) {
63 SelectObject32(hdc, sysColorObjects.hbrushScrollbar);
64 Rectangle32(hdc, r.left, r.top, r.right, r.bottom);
66 else { /* fixme for SBT_OWNERDRAW, SBT_RTLREADING */
70 /* now draw text */
71 if ((style != SBT_OWNERDRAW) && text) {
72 SelectObject32(hdc, sysColorObjects.hpenWindowText);
73 oldbkmode = SetBkMode32(hdc, TRANSPARENT);
74 rt = r;
75 rt.left += 3;
76 DrawText32A(hdc, text, lstrlen32A(text),
77 &rt, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
79 if (oldbkmode != TRANSPARENT)
80 SetBkMode32(hdc, oldbkmode);
84 static BOOL32 SW_Refresh( HWND32 hwnd, HDC32 hdc, STATUSWINDOWINFO *self )
86 int i;
88 if (!IsWindowVisible(hwnd)) {
89 return (TRUE);
92 if (self->simple) {
93 DrawStatusText32A(hdc,
94 &self->part0.bound,
95 self->part0.text,
96 self->part0.style);
98 else {
99 for (i = 0; i < self->numParts; i++) {
100 DrawStatusText32A(hdc,
101 &self->parts[i].bound,
102 self->parts[i].text,
103 self->parts[i].style);
107 return TRUE;
111 static LRESULT
112 SW_GetBorders(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
114 LPINT32 out;
116 /* FIXME for sizegrips */
117 out = (LPINT32) lParam;
118 out[0] = 1; /* vertical border width */
119 out[1] = 1; /* horizontal border width */
120 out[2] = 1; /* width of border between rectangles */
121 return TRUE;
124 static void
125 SW_SetPartBounds(HWND32 hwnd, STATUSWINDOWINFO *self)
127 int i;
128 RECT32 rect, *r;
129 STATUSWINDOWPART *part;
130 int sep = 1;
132 /* get our window size */
133 GetClientRect32(hwnd, &rect);
135 /* set bounds for simple rectangle */
136 self->part0.bound = rect;
138 /* set bounds for non-simple rectangles */
139 for (i = 0; i < self->numParts; i++) {
140 part = &self->parts[i];
141 r = &self->parts[i].bound;
142 r->top = rect.top;
143 r->bottom = rect.bottom;
144 if (i == 0)
145 r->left = 0;
146 else
147 r->left = self->parts[i-1].bound.right+sep;
148 if (part->x == -1)
149 r->right = rect.right;
150 else
151 r->right = part->x;
155 static LRESULT
156 SW_SetText(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
158 int part_num;
159 int style;
160 LPSTR text;
161 int len;
162 STATUSWINDOWPART *part;
164 text = (LPSTR) lParam;
165 part_num = ((INT32) wParam) & 0x00ff;
166 style = ((INT32) wParam) & 0xff00;
168 if (part_num > 255)
169 return FALSE;
171 if (self->simple)
172 part = &self->part0;
173 else
174 part = &self->parts[part_num];
175 part->style = style;
176 if (style == SBT_OWNERDRAW) {
177 part->text = text;
179 else {
180 /* duplicate string */
181 if (part->text)
182 HeapFree(SystemHeap, 0, part->text);
183 part->text = 0;
184 if (text && (len = lstrlen32A(text))) {
185 part->text = HeapAlloc(SystemHeap, 0, len+1);
186 lstrcpy32A(part->text, text);
189 InvalidateRect32(hwnd, &part->bound, FALSE);
190 return TRUE;
193 static LRESULT
194 SW_SetParts(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
196 HDC32 hdc;
197 LPINT32 parts;
198 STATUSWINDOWPART * tmp;
199 int i;
200 int oldNumParts;
202 if (self->simple) {
203 self->simple = FALSE;
205 oldNumParts = self->numParts;
206 self->numParts = (INT32) wParam;
207 parts = (LPINT32) lParam;
208 if (oldNumParts > self->numParts) {
209 for (i = self->numParts ; i < oldNumParts; i++) {
210 if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
211 HeapFree(SystemHeap, 0, self->parts[i].text);
214 else if (oldNumParts < self->numParts) {
215 tmp = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY,
216 sizeof(STATUSWINDOWPART) * self->numParts);
217 for (i = 0; i < oldNumParts; i++) {
218 tmp[i] = self->parts[i];
220 if (self->parts)
221 HeapFree(SystemHeap, 0, self->parts);
222 self->parts = tmp;
225 for (i = 0; i < self->numParts; i++) {
226 self->parts[i].x = parts[i];
228 SW_SetPartBounds(hwnd, self);
230 hdc = GetDC32(hwnd);
231 SW_Refresh(hwnd, hdc, self);
232 ReleaseDC32(hwnd, hdc);
233 return TRUE;
236 static LRESULT
237 SW_GetParts(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
239 LPINT32 parts;
240 INT32 num_parts;
241 int i;
243 self = GetStatusInfo(hwnd);
244 num_parts = (INT32) wParam;
245 parts = (LPINT32) lParam;
246 if (parts) {
247 return (self->numParts);
248 for (i = 0; i < num_parts; i++) {
249 parts[i] = self->parts[i].x;
252 return (self->numParts);
255 static LRESULT
256 SW_Create(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
258 RECT32 rect;
259 LPCREATESTRUCT32A lpCreate = (LPCREATESTRUCT32A) lParam;
260 int height, width;
261 HDC32 hdc;
262 HWND32 parent;
264 self->numParts = 0;
265 self->parts = 0;
266 self->simple = TRUE;
267 GetClientRect32(hwnd, &rect);
269 /* initialize simple case */
270 self->part0.bound = rect;
271 self->part0.text = 0;
272 self->part0.x = 0;
273 self->part0.style = 0;
275 height = 40;
276 if ((hdc = GetDC32(0))) {
277 TEXTMETRIC32A tm;
278 GetTextMetrics32A(hdc, &tm);
279 self->textHeight = tm.tmHeight;
280 ReleaseDC32(0, hdc);
283 parent = GetParent32(hwnd);
284 GetClientRect32(parent, &rect);
285 width = rect.right - rect.left;
286 height = (self->textHeight * 3)/2;
287 MoveWindow(hwnd, lpCreate->x, lpCreate->y-1, width, height, FALSE);
288 SW_SetPartBounds(hwnd, self);
289 return 0;
292 static LRESULT
293 SW_GetRect(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
295 int part_num;
296 LPRECT32 rect;
298 part_num = ((INT32) wParam) & 0x00ff;
299 rect = (LPRECT32) lParam;
300 if (self->simple)
301 *rect = self->part0.bound;
302 else
303 *rect = self->parts[part_num].bound;
304 return TRUE;
307 static LRESULT
308 SW_GetText(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
310 int part_num;
311 LRESULT result;
312 STATUSWINDOWPART *part;
313 LPSTR out_text;
315 part_num = ((INT32) wParam) & 0x00ff;
316 out_text = (LPSTR) lParam;
317 if (self->simple)
318 part = &self->part0;
319 else
320 part = &self->parts[part_num];
322 if (part->style == SBT_OWNERDRAW)
323 result = (LRESULT) part->text;
324 else {
325 result = part->text ? lstrlen32A(part->text) : 0;
326 result |= (part->style << 16);
327 if (out_text) {
328 lstrcpy32A(out_text, part->text);
331 return result;
334 static LRESULT
335 SW_GetTextLength(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
337 int part_num;
338 STATUSWINDOWPART *part;
339 DWORD result;
341 part_num = ((INT32) wParam) & 0x00ff;
343 if (self->simple)
344 part = &self->part0;
345 else
346 part = &self->parts[part_num];
348 if (part->text)
349 result = lstrlen32A(part->text);
350 else
351 result = 0;
353 result |= (part->style << 16);
354 return result;
357 static LRESULT
358 SW_SetMinHeight(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
360 /* FIXME */
361 /* size is wParam | 2*pixels_of_horz_border */
362 return TRUE;
365 static LRESULT
366 SW_Simple(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
368 BOOL32 simple;
369 HDC32 hdc;
371 simple = (BOOL32) wParam;
372 self->simple = simple;
373 hdc = GetDC32(hwnd);
374 SW_Refresh(hwnd, hdc, self);
375 ReleaseDC32(hwnd, hdc);
376 return TRUE;
379 static LRESULT
380 SW_Size(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
382 /* Need to resize width to match parent */
383 INT32 width, height, x, y;
384 RECT32 parent_rect;
385 HWND32 parent;
387 INT32 flags;
389 flags = (INT32) wParam;
391 /* FIXME for flags =
392 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED, SIZE_RESTORED
395 if (flags == SIZE_RESTORED) {
396 /* width and height don't apply */
397 parent = GetParent32(hwnd);
398 GetClientRect32(parent, &parent_rect);
399 height = (self->textHeight * 3)/2;
400 width = parent_rect.right - parent_rect.left;
401 x = parent_rect.left;
402 y = parent_rect.bottom - height;
403 MoveWindow(hwnd, parent_rect.left, parent_rect.bottom - height - 1,
404 width, height, TRUE);
405 SW_SetPartBounds(hwnd, self);
407 return 0;
410 static LRESULT
411 SW_Destroy(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
413 int i;
415 for (i = 0; i < self->numParts; i++) {
416 if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
417 HeapFree(SystemHeap, 0, self->parts[i].text);
419 if (self->part0.text && (self->part0.style != SBT_OWNERDRAW))
420 HeapFree(SystemHeap, 0, self->part0.text);
421 HeapFree(SystemHeap, 0, self->parts);
422 return 0;
427 static LRESULT
428 SW_Paint(STATUSWINDOWINFO *self, HWND32 hwnd)
430 HDC32 hdc;
431 PAINTSTRUCT32 ps;
433 hdc = BeginPaint32(hwnd, &ps);
434 SW_Refresh(hwnd, hdc, self);
435 EndPaint32(hwnd, &ps);
436 return 0;
439 LRESULT StatusWindowProc( HWND32 hwnd, UINT32 msg,
440 WPARAM32 wParam, LPARAM lParam )
442 STATUSWINDOWINFO *self;
444 self = GetStatusInfo(hwnd);
446 switch (msg) {
447 case SB_GETBORDERS:
448 return SW_GetBorders(self, hwnd, wParam, lParam);
449 case SB_GETPARTS:
450 return SW_GetParts(self, hwnd, wParam, lParam);
451 case SB_GETRECT:
452 return SW_GetRect(self, hwnd, wParam, lParam);
453 case SB_GETTEXT32A:
454 return SW_GetText(self, hwnd, wParam, lParam);
455 case SB_GETTEXTLENGTH32A:
456 return SW_GetTextLength(self, hwnd, wParam, lParam);
457 case SB_SETMINHEIGHT:
458 return SW_SetMinHeight(self, hwnd, wParam, lParam);
459 case SB_SETPARTS:
460 return SW_SetParts(self, hwnd, wParam, lParam);
461 case SB_SETTEXT32A:
462 return SW_SetText(self, hwnd, wParam, lParam);
463 case SB_SIMPLE:
464 return SW_Simple(self, hwnd, wParam, lParam);
466 case WM_CREATE:
467 return SW_Create(self, hwnd, wParam, lParam);
468 case WM_DESTROY:
469 return SW_Destroy(self, hwnd, wParam, lParam);
470 case WM_PAINT:
471 return SW_Paint(self, hwnd);
472 case WM_SIZE:
473 return SW_Size(self, hwnd, wParam, lParam);
474 default:
475 return DefWindowProc32A(hwnd, msg, wParam, lParam);
477 return 0;
481 /***********************************************************************
482 * CreateStatusWindow32A (COMCTL32.4)
484 HWND32 CreateStatusWindow32A( INT32 style, LPCSTR text, HWND32 parent,
485 UINT32 wid )
487 HWND32 ret;
488 ATOM atom;
490 atom = GlobalFindAtom32A(STATUSCLASSNAME32A);
491 if (!atom) {
492 /* Some apps don't call InitCommonControls */
493 InitCommonControls();
496 ret = CreateWindowEx32A(0, STATUSCLASSNAME32A, "Status Window",
497 style, CW_USEDEFAULT32, CW_USEDEFAULT32,
498 CW_USEDEFAULT32, CW_USEDEFAULT32, parent, 0, 0, 0);
499 return (ret);