Release 980628
[wine] / controls / commctrl.c
1 /*              
2  * Common controls functions
3  *
4  * Copyright 1997 Dimitrie O. Paun
5  *
6  */
7
8 #include "win.h"
9 #include "heap.h"
10 #include "commctrl.h"
11 #include "header.h"
12 #include "progress.h"
13 #include "status.h"
14 #include "toolbar.h"
15 #include "updown.h"
16 #include "debug.h"
17
18
19 /***********************************************************************
20  * DrawStatusText32A [COMCTL32.5][COMCTL32.27]
21  */
22 void WINAPI DrawStatusText32A( HDC32 hdc, LPRECT32 lprc, LPCSTR text,
23                                UINT32 style )
24 {
25     RECT32 r = *lprc;
26     UINT32 border = BDR_SUNKENOUTER;
27
28     if(style==SBT_POPOUT)
29       border = BDR_RAISEDOUTER;
30     else if(style==SBT_NOBORDERS)
31       border = 0;
32
33     DrawEdge32(hdc, &r, border, BF_RECT|BF_ADJUST|BF_MIDDLE);
34
35     /* now draw text */
36     if (text) {
37       int oldbkmode = SetBkMode32(hdc, TRANSPARENT);
38       r.left += 3;
39       DrawText32A(hdc, text, lstrlen32A(text),
40                   &r, DT_LEFT|DT_VCENTER|DT_SINGLELINE);  
41       if (oldbkmode != TRANSPARENT)
42         SetBkMode32(hdc, oldbkmode);
43     }
44     
45 }
46
47 /***********************************************************************
48  *           DrawStatusText32W   (COMCTL32.28)
49  */
50 void WINAPI DrawStatusText32W( HDC32 hdc, LPRECT32 lprc, LPCWSTR text,
51                                UINT32 style )
52 {
53   LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
54   DrawStatusText32A(hdc, lprc, p, style);
55   HeapFree( GetProcessHeap(), 0, p );         
56 }
57
58 /***********************************************************************
59  * CreateStatusWindow32A [COMCTL32.6][COMCTL32.21]
60  */
61 HWND32 WINAPI CreateStatusWindow32A( INT32 style, LPCSTR text, HWND32 parent,
62                                      UINT32 wid )
63 {
64     return CreateWindow32A(STATUSCLASSNAME32A, text, style, 
65                            CW_USEDEFAULT32, CW_USEDEFAULT32,
66                            CW_USEDEFAULT32, CW_USEDEFAULT32, 
67                            parent, wid, 0, 0);
68 }
69
70 /***********************************************************************
71  *           CreateStatusWindow32W   (COMCTL32.22)
72  */
73 HWND32 WINAPI CreateStatusWindow32W( INT32 style, LPCWSTR text, HWND32 parent,
74                                      UINT32 wid )
75 {
76     return CreateWindow32W((LPCWSTR)STATUSCLASSNAME32W, text, style, 
77                            CW_USEDEFAULT32, CW_USEDEFAULT32,
78                            CW_USEDEFAULT32, CW_USEDEFAULT32, 
79                            parent, wid, 0, 0);
80 }
81
82 /***********************************************************************
83  *           CreateUpDownControl  (COMCTL32.16)
84  */
85 HWND32 WINAPI CreateUpDownControl( DWORD style, INT32 x, INT32 y,
86                                    INT32 cx, INT32 cy, HWND32 parent,
87                                    INT32 id, HINSTANCE32 inst, HWND32 buddy,
88                                    INT32 maxVal, INT32 minVal, INT32 curVal )
89 {
90   HWND32 hUD = CreateWindow32A(UPDOWN_CLASS32A, 0, style, x, y, cx, cy,
91                                parent, id, inst, 0);
92   if(hUD){
93     SendMessage32A(hUD, UDM_SETBUDDY, buddy, 0);
94     SendMessage32A(hUD, UDM_SETRANGE, 0, MAKELONG(maxVal, minVal));
95     SendMessage32A(hUD, UDM_SETPOS, 0, MAKELONG(curVal, 0));     
96   }
97
98   return hUD;
99 }
100
101
102 /***********************************************************************
103  * InitCommonControls [COMCTL32.17]
104  *
105  *
106  *
107  */
108
109 VOID WINAPI
110 InitCommonControls (VOID)
111 {
112     INITCOMMONCONTROLSEX icc;
113
114     icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
115     icc.dwICC = ICC_WIN95_CLASSES;
116
117     InitCommonControlsEx (&icc);
118 }
119
120
121 /***********************************************************************
122  * InitCommonControlsEx [COMCTL32.81]
123  *
124  *
125  *
126  */
127
128 BOOL32 WINAPI
129 InitCommonControlsEx (LPINITCOMMONCONTROLSEX lpInitCtrls)
130 {
131   INT32 cCount;
132   DWORD dwMask;
133
134   if (lpInitCtrls == NULL) return FALSE;
135   if (lpInitCtrls->dwSize < sizeof(INITCOMMONCONTROLSEX)) return FALSE;
136
137   for (cCount = 0; cCount <= 31; cCount++) {
138     dwMask = 1 << cCount;
139     if (!(lpInitCtrls->dwICC & dwMask))
140       continue;
141
142     switch (lpInitCtrls->dwICC & dwMask) {
143       case ICC_LISTVIEW_CLASSES:
144         TRACE (commctrl, "No listview class implemented!\n");
145         HEADER_Register();
146         break;
147
148       case ICC_TREEVIEW_CLASSES:
149         TRACE (commctrl, "No treeview class implemented!\n");
150         TRACE (commctrl, "No tooltip class implemented!\n");
151         break;
152
153       case ICC_BAR_CLASSES:
154         TOOLBAR_Register ();
155         STATUS_Register ();
156         TRACE (commctrl, "No trackbar class implemented!\n");
157         TRACE (commctrl, "No tooltip class implemented!\n");
158         break;
159
160       case ICC_TAB_CLASSES:
161         TRACE (commctrl, "No tab class implemented!\n");
162         TRACE (commctrl, "No tooltip class implemented!\n");
163         UPDOWN_Register ();
164         break;
165
166       case ICC_UPDOWN_CLASS:
167         UPDOWN_Register ();
168         break;
169
170       case ICC_PROGRESS_CLASS:
171         PROGRESS_Register ();
172         break;
173
174       case ICC_HOTKEY_CLASS:
175         TRACE (commctrl, "No hotkey class implemented!\n");
176         break;
177
178       case ICC_ANIMATE_CLASS:
179         TRACE (commctrl, "No animation class implemented!\n");
180         break;
181
182       /* advanced classes - not included in Win95 */
183       case ICC_DATE_CLASSES:
184         TRACE (commctrl, "No month calendar class implemented!\n");
185         TRACE (commctrl, "No date picker class implemented!\n");
186         TRACE (commctrl, "No time picker class implemented!\n");
187         UPDOWN_Register ();
188         break;
189
190       case ICC_USEREX_CLASSES:
191         TRACE (commctrl, "No comboex class implemented!\n");
192         break;
193
194       case ICC_COOL_CLASSES:
195         TRACE (commctrl, "No rebar class implemented!\n");
196         break;
197
198       case ICC_INTERNET_CLASSES:
199         TRACE (commctrl, "No internet classes implemented!\n");
200         break;
201
202       case ICC_PAGESCROLLER_CLASS:
203         TRACE (commctrl, "No page scroller class implemented!\n");
204         break;
205
206       case ICC_NATIVEFNTCTL_CLASS:
207         TRACE (commctrl, "No native font class implemented!\n");
208         break;
209
210       default:
211         WARN (commctrl, "Unknown class! dwICC=0x%lX\n", dwMask);
212         break;
213     }
214   }
215
216   return TRUE;
217 }
218
219
220 /***********************************************************************
221  * MenuHelp [COMCTL32.2]
222  *
223  *
224  *
225  *
226  */
227
228 VOID WINAPI
229 MenuHelp (UINT32 uMsg, WPARAM32 wParam, LPARAM lParam, HMENU32 hMainMenu,
230           HINSTANCE32 hInst, HWND32 hwndStatus, LPUINT32 lpwIDs)
231 {
232     char szStatusText[128];
233
234     if (!IsWindow32 (hwndStatus)) return;
235
236     switch (uMsg) {
237         case WM_MENUSELECT:
238             TRACE (commctrl, "WM_MENUSELECT wParam=0x%X lParam=0x%lX\n",
239                    wParam, lParam);
240
241             if ((HIWORD(wParam) == 0xFFFF) && (lParam == 0)) {
242                 /* menu was closed */
243                 SendMessage32A (hwndStatus, SB_SIMPLE, FALSE, 0);
244             }
245             else {
246                 if (HIWORD(wParam) & MF_POPUP) {
247                     TRACE (commctrl, "popup menu selected!\n");
248
249                     szStatusText[0] = 0;
250                 }
251                 else {
252                     TRACE (commctrl, "menu item selected!\n");
253                     if (!LoadString32A (hInst, LOWORD(wParam), szStatusText, 128))
254                         szStatusText[0] = 0;
255                 }
256                 SendMessage32A (hwndStatus, SB_SETTEXT32A, 255 | SBT_NOBORDERS,
257                                 (LPARAM)szStatusText);
258                 SendMessage32A (hwndStatus, SB_SIMPLE, TRUE, 0);
259             }
260             break;
261
262         default:
263             WARN (commctrl, "Invalid Message!\n");
264             break;
265     }
266 }
267
268
269 /***********************************************************************
270  * CreateToolbarEx [COMCTL32.32]
271  *
272  *
273  *
274  */
275
276 HWND32 WINAPI
277 CreateToolbarEx (HWND32 hwnd, DWORD style, UINT32 wID, INT32 nBitmaps,
278                  HINSTANCE32 hBMInst, UINT32 wBMID, LPCTBBUTTON lpButtons,
279                  INT32 iNumButtons, INT32 dxButton, INT32 dyButton,
280                  INT32 dxBitmap, INT32 dyBitmap, UINT32 uStructSize)
281 {
282     HWND32 hwndTB =
283         CreateWindowEx32A (0, TOOLBARCLASSNAME32A, "", style, 0, 0, 0, 0,
284                            hwnd, (HMENU32)wID, 0, NULL);
285     if(hwndTB) {
286         TBADDBITMAP tbab;
287
288         SendMessage32A (hwndTB, TB_BUTTONSTRUCTSIZE,
289                         (WPARAM32)uStructSize, 0);
290
291         /* set bitmap and button size */
292
293         /* add bitmaps */
294         tbab.hInst = hBMInst;
295         tbab.nID   = wBMID;
296         SendMessage32A (hwndTB, TB_ADDBITMAP,
297                         (WPARAM32)nBitmaps, (LPARAM)&tbab);
298
299         /* add buttons */
300         SendMessage32A (hwndTB, TB_ADDBUTTONS32A,
301                         (WPARAM32)iNumButtons, (LPARAM)lpButtons);
302     }
303
304     return hwndTB;
305 }
306
307
308 /***********************************************************************
309  * CreateMappedBitmap [COMCTL32.8]
310  *
311  *
312  *
313  */
314
315 HBITMAP32 WINAPI
316 CreateMappedBitmap (HINSTANCE32 hInstance, INT32 idBitmap, UINT32 wFlags,
317                     LPCOLORMAP lpColorMap, INT32 iNumMaps)
318 {
319     HBITMAP32 hbm;
320
321     FIXME (commctrl, "semi-stub!\n");
322
323     hbm = LoadBitmap32A (hInstance, MAKEINTRESOURCE32A(idBitmap));
324
325     return hbm;
326  }
327
328
329 /***********************************************************************
330  * CreateToolbar [COMCTL32.7]
331  *
332  *
333  *
334  */
335
336 HWND32 WINAPI
337 CreateToolbar (HWND32 hwnd, DWORD style, UINT32 wID, INT32 nBitmaps,
338                HINSTANCE32 hBMInst, UINT32 wBMID,
339                LPCOLDTBBUTTON lpButtons,INT32 iNumButtons)
340 {
341     return CreateToolbarEx (hwnd, style | CCS_NODIVIDER, wID, nBitmaps,
342                             hBMInst, wBMID, (LPCTBBUTTON)lpButtons,
343                             iNumButtons, 0, 0, 0, 0, sizeof (OLDTBBUTTON));
344 }
345
346
347 /***********************************************************************
348  * GetEffectiveClientRect [COMCTL32.4]
349  *
350  * PARAMS
351  *     hwnd   [I] handle to the client window.
352  *     lpRect [O] pointer to the rectangle of the client window
353  *     lpInfo [I] pointer to an array of integers
354  *
355  * NOTES
356  */
357
358 VOID WINAPI
359 GetEffectiveClientRect (HWND32 hwnd, LPRECT32 lpRect, LPINT32 lpInfo)
360 {
361     RECT32 rcClient, rcCtrl;
362     INT32  idCtrl, *lpRun;
363
364     TRACE (commctrl, "hwnd=0x%08lx lpRect=0x%08lx lpInfo=0x%08lx\n",
365            (DWORD)hwnd, (DWORD)lpRect, (DWORD)lpInfo);
366
367     GetClientRect32 (hwnd, &rcClient);
368 #if 0
369     lpRun = lpInfo;
370
371     do {
372         lpRun += 3;
373         idCtrl = *lpRun;
374         if (idCtrl) {
375             TRACE (commctrl, "control id 0x%x\n", idCtrl);
376             GetWindowRect32 (GetDlgItem32 (hwnd, idCtrl), &rcCtrl);
377             MapWindowPoints32 (NULL, hwnd, (LPPOINT32)&rcCtrl, 2);
378             SubtractRect32 (&rcClient, &rcClient, &rcCtrl);
379             lpRun++;
380         }
381     } while (idCtrl);
382 #endif
383     CopyRect32 (lpRect, &rcClient);
384 }
385