Release 970329
[wine] / controls / widgets.c
1 /*
2  * Windows widgets (built-in window classes)
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #include <assert.h>
8
9 #include "win.h"
10 #include "commctrl.h"
11 #include "button.h"
12 #include "static.h"
13 #include "status.h"
14 #include "scroll.h"
15 #include "desktop.h"
16 #include "mdi.h"
17 #include "gdi.h"
18 #include "module.h"
19 #include "heap.h"
20
21 /* Window procedures */
22
23 extern LRESULT EditWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
24                             LPARAM lParam );
25 extern LRESULT ComboWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
26                              LPARAM lParam );
27 extern LRESULT ComboLBWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
28                                LPARAM lParam );
29 extern LRESULT ListBoxWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
30                                LPARAM lParam );
31 extern LRESULT PopupMenuWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
32                                  LPARAM lParam );
33
34 /* Win16 class info */
35
36 typedef struct
37 {
38     UINT16     style;
39     INT16      wndExtra;
40     HBRUSH16   background;
41     LPCSTR     procName;
42     LPCSTR     className;
43 } BUILTIN_CLASS_INFO16;
44
45 /* Win16 built-in classes */
46
47 static const BUILTIN_CLASS_INFO16 WIDGETS_BuiltinClasses16[] =
48 {
49     { CS_GLOBALCLASS | CS_PARENTDC,
50        sizeof(STATICINFO), 0, "StaticWndProc", "Static" },
51     { CS_GLOBALCLASS, sizeof(MDICLIENTINFO),
52       STOCK_LTGRAY_BRUSH, "MDIClientWndProc", "MDIClient" }
53 };
54
55 #define NB_BUILTIN_CLASSES16 \
56          (sizeof(WIDGETS_BuiltinClasses16)/sizeof(WIDGETS_BuiltinClasses16[0]))
57
58 /* Win32 built-in classes */
59
60 static WNDCLASS32A WIDGETS_BuiltinClasses32[BIC32_NB_CLASSES] =
61 {
62     /* BIC32_BUTTON */
63     { CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC,
64       ButtonWndProc, 0, sizeof(BUTTONINFO), 0, 0, 0, 0, 0, "Button" },
65     /* BIC32_EDIT */
66     { CS_GLOBALCLASS | CS_DBLCLKS /*| CS_PARENTDC*/,
67       EditWndProc, 0, sizeof(void *), 0, 0, 0, 0, 0, "Edit" },
68     /* BIC32_LISTBOX */
69     { CS_GLOBALCLASS | CS_DBLCLKS /*| CS_PARENTDC*/,
70       ListBoxWndProc, 0, sizeof(void *), 0, 0, 0, 0, 0, "ListBox" },
71     /* BIC32_COMBO */
72     { CS_GLOBALCLASS | CS_PARENTDC | CS_DBLCLKS, 
73       ComboWndProc, 0, sizeof(void *), 0, 0, 0, 0, 0, "ComboBox" },
74     /* BIC32_COMBOLB */
75     { CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS,
76       ComboLBWndProc, 0, sizeof(void *), 0, 0, 0, 0, 0, "ComboLBox" },
77     /* BIC32_POPUPMENU */
78     { CS_GLOBALCLASS | CS_SAVEBITS, PopupMenuWndProc,
79       0, sizeof(HMENU32), 0, 0, 0, 0, 0, POPUPMENU_CLASS_NAME },
80     /* BIC32_SCROLL */
81     { CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC,
82       ScrollBarWndProc, 0, sizeof(SCROLLBAR_INFO), 0, 0, 0, 0, 0, "ScrollBar"},
83     /* BIC32_DESKTOP */
84     { CS_GLOBALCLASS, DesktopWndProc, 0, sizeof(DESKTOPINFO),
85       0, 0, 0, 0, 0, DESKTOP_CLASS_NAME },
86     /* BIC32_DIALOG */
87     { CS_GLOBALCLASS | CS_SAVEBITS, DefDlgProc32A, 0, DLGWINDOWEXTRA,
88       0, 0, 0, 0, 0, DIALOG_CLASS_NAME }
89 };
90
91 static ATOM bicAtomTable[BIC32_NB_CLASSES];
92
93 /* Win32 common controls */
94
95 static WNDCLASS32A WIDGETS_CommonControls32[] =
96 {
97     { CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW, StatusWindowProc, 0,
98       sizeof(STATUSWINDOWINFO), 0, 0, 0, 0, 0, STATUSCLASSNAME32A },
99 };
100
101 #define NB_COMMON_CONTROLS32 \
102          (sizeof(WIDGETS_CommonControls32)/sizeof(WIDGETS_CommonControls32[0]))
103
104
105 /***********************************************************************
106  *           WIDGETS_Init
107  * 
108  * Initialize the built-in window classes.
109  */
110 BOOL32 WIDGETS_Init(void)
111 {
112     int i;
113     char *name;
114     const BUILTIN_CLASS_INFO16 *info16 = WIDGETS_BuiltinClasses16;
115     WNDCLASS16 class16;
116     WNDCLASS32A *class32 = WIDGETS_BuiltinClasses32;
117
118     if (!(name = SEGPTR_ALLOC( 20 * sizeof(char) ))) return FALSE;
119
120     /* Create 16-bit classes */
121
122     class16.cbClsExtra    = 0;
123     class16.hInstance     = 0;
124     class16.hIcon         = 0;
125     class16.hCursor       = LoadCursor16( 0, IDC_ARROW );
126     class16.lpszMenuName  = (SEGPTR)0;
127     class16.lpszClassName = SEGPTR_GET(name);
128     for (i = 0; i < NB_BUILTIN_CLASSES16; i++, info16++)
129     {
130         class16.style         = info16->style;
131         class16.lpfnWndProc   = (WNDPROC16)MODULE_GetWndProcEntry16( info16->procName );
132         class16.cbWndExtra    = info16->wndExtra;
133         class16.hbrBackground = info16->background;
134         strcpy( name, info16->className );
135         if (!RegisterClass16( &class16 )) return FALSE;
136     }
137
138     /* Create 32-bit classes */
139
140     for (i = 0; i < BIC32_NB_CLASSES; i++, class32++)
141     {
142         /* Just to make sure the string is > 0x10000 */
143         strcpy( name, (char *)class32->lpszClassName );
144         class32->lpszClassName = name;
145         class32->hCursor = LoadCursor16( 0, IDC_ARROW );
146         if (!(bicAtomTable[i] = RegisterClass32A( class32 ))) return FALSE;
147     }
148
149     SEGPTR_FREE(name);
150     return TRUE;
151 }
152
153
154 /***********************************************************************
155  *           InitCommonControls   (COMCTL32.15)
156  */
157 void InitCommonControls(void)
158 {
159     int i;
160     char name[30];
161     WNDCLASS32A *class32 = WIDGETS_CommonControls32;
162
163     for (i = 0; i < NB_COMMON_CONTROLS32; i++, class32++)
164     {
165         /* Just to make sure the string is > 0x10000 */
166         strcpy( name, (char *)class32->lpszClassName );
167         class32->lpszClassName = name;
168         class32->hCursor = LoadCursor16( 0, IDC_ARROW );
169         RegisterClass32A( class32 );
170     }
171 }
172
173
174 /***********************************************************************
175  *           WIDGETS_IsControl32
176  *
177  * Check whether pWnd is a built-in control or not.
178  */
179 BOOL32  WIDGETS_IsControl32( WND* pWnd, BUILTIN_CLASS32 cls )
180 {
181     assert( cls < BIC32_NB_CLASSES );
182     return (pWnd->class->atomName == bicAtomTable[cls]);
183 }