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