Added a first-cut version of MapVirtualKeyExW() that has the same
[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 #include <string.h>
9
10 #include "win.h"
11 #include "button.h"
12 #include "combo.h"
13 #include "desktop.h"
14 #include "gdi.h"
15 #include "heap.h"
16 #include "mdi.h"
17 #include "menu.h"
18 #include "scroll.h"
19 #include "static.h"
20 #include "wine/unicode.h"
21
22 /* Built-in classes */
23
24 static const char bi_class_nameA[BIC32_NB_CLASSES][10] =
25 {
26     "Button",
27     "Edit",
28     "ListBox",
29     "ComboBox",
30     "ComboLBox",
31     POPUPMENU_CLASS_NAME,
32     "Static",
33     "ScrollBar",
34     "MDIClient",
35     DESKTOP_CLASS_NAME,
36     DIALOG_CLASS_NAME,
37     ICONTITLE_CLASS_NAME
38 };
39
40 static const WCHAR bi_class_nameW[BIC32_NB_CLASSES][10] =
41 {
42     {'B','u','t','t','o','n',0},
43     {'E','d','i','t',0},
44     {'L','i','s','t','B','o','x',0},
45     {'C','o','m','b','o','B','o','x',0},
46     {'C','o','m','b','o','L','B','o','x',0},
47     {'#','3','2','7','6','8',0},
48     {'S','t','a','t','i','c',0},
49     {'S','c','r','o','l','l','B','a','r',0},
50     {'M','D','I','C','l','i','e','n','t',0},
51     {'#','3','2','7','6','9',0},
52     {'#','3','2','7','7','0',0},
53     {'#','3','2','7','7','2',0}
54 };
55
56 typedef struct {
57     BOOL unicode;
58     union {
59         WNDCLASSA A;
60         WNDCLASSW W;
61     } wnd_class;
62 } BUILTINCLASS;
63
64 static BUILTINCLASS WIDGETS_BuiltinClasses[BIC32_NB_CLASSES] =
65 {
66     /* BIC32_BUTTON */
67     { TRUE, {
68     { CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC,
69       ButtonWndProc, 0, sizeof(BUTTONINFO), 0, 0,
70       (HCURSOR)IDC_ARROWW, 0, 0, (LPCSTR)bi_class_nameW[0] }}},
71     /* BIC32_EDIT */
72     { FALSE, {
73     { CS_GLOBALCLASS | CS_DBLCLKS /*| CS_PARENTDC*/,
74       EditWndProc, 0, sizeof(void *), 0, 0,
75       (HCURSOR)IDC_IBEAMA, 0, 0, bi_class_nameA[1] }}},
76     /* BIC32_LISTBOX */
77     { FALSE, {
78     { CS_GLOBALCLASS | CS_DBLCLKS /*| CS_PARENTDC*/,
79       ListBoxWndProc, 0, sizeof(void *), 0, 0,
80       (HCURSOR)IDC_ARROWA, 0, 0, bi_class_nameA[2] }}},
81     /* BIC32_COMBO */
82     { FALSE, {
83     { CS_GLOBALCLASS | CS_PARENTDC | CS_DBLCLKS, 
84       ComboWndProc, 0, sizeof(void *), 0, 0,
85       (HCURSOR)IDC_ARROWA, 0, 0, bi_class_nameA[3] }}},
86     /* BIC32_COMBOLB */
87     { FALSE, {
88     { CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS, ComboLBWndProc,
89       0, sizeof(void *), 0, 0, (HCURSOR)IDC_ARROWA, 0, 0, bi_class_nameA[4] }}},
90     /* BIC32_POPUPMENU */
91     { FALSE, {
92     { CS_GLOBALCLASS | CS_SAVEBITS, PopupMenuWndProc, 0, sizeof(HMENU),
93       0, 0, (HCURSOR)IDC_ARROWA, NULL_BRUSH, 0, bi_class_nameA[5] }}},
94     /* BIC32_STATIC */
95     { FALSE, {
96     { CS_GLOBALCLASS | CS_DBLCLKS | CS_PARENTDC, StaticWndProc,
97       0, sizeof(STATICINFO), 0, 0, (HCURSOR)IDC_ARROWA, 0, 0, bi_class_nameA[6] }}},
98     /* BIC32_SCROLL */
99     { FALSE, {
100     { CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC,
101       ScrollBarWndProc, 0, sizeof(SCROLLBAR_INFO), 0, 0,
102       (HCURSOR)IDC_ARROWA, 0, 0, bi_class_nameA[7] }}},
103     /* BIC32_MDICLIENT */
104     { FALSE, {
105     { CS_GLOBALCLASS, MDIClientWndProc,
106       0, sizeof(MDICLIENTINFO), 0, 0, (HCURSOR)IDC_ARROWA, STOCK_LTGRAY_BRUSH, 0, bi_class_nameA[8] }}},
107     /* BIC32_DESKTOP */
108     { FALSE, {
109     { CS_GLOBALCLASS, DesktopWndProc, 0, sizeof(DESKTOP),
110       0, 0, (HCURSOR)IDC_ARROWA, 0, 0, bi_class_nameA[9] }}},
111     /* BIC32_DIALOG */
112     { FALSE, {
113     { CS_GLOBALCLASS | CS_SAVEBITS, DefDlgProcA, 0, DLGWINDOWEXTRA,
114       0, 0, (HCURSOR)IDC_ARROWA, 0, 0, bi_class_nameA[10] }}},
115     /* BIC32_ICONTITLE */
116     { FALSE, {
117     { CS_GLOBALCLASS, IconTitleWndProc, 0, 0, 
118       0, 0, (HCURSOR)IDC_ARROWA, 0, 0, bi_class_nameA[11] }}}
119 };
120
121 static ATOM bicAtomTable[BIC32_NB_CLASSES];
122
123 /***********************************************************************
124  *           WIDGETS_Init
125  * 
126  * Initialize the built-in window classes.
127  */
128 BOOL WIDGETS_Init(void)
129 {
130     int i;
131     BUILTINCLASS *cls = WIDGETS_BuiltinClasses;
132
133     /* Create builtin classes */
134
135     for (i = 0; i < BIC32_NB_CLASSES; i++, cls++)
136     {
137         if(cls->unicode)
138         {
139             WCHAR nameW[20];
140             /* Just to make sure the string is > 0x10000 */
141             strcpyW( nameW, (WCHAR *)cls->wnd_class.W.lpszClassName );
142             cls->wnd_class.W.lpszClassName = nameW;
143             cls->wnd_class.W.hCursor = LoadCursorW( 0, (LPCWSTR)cls->wnd_class.W.hCursor );
144             if (!(bicAtomTable[i] = RegisterClassW( &(cls->wnd_class.W) ))) return FALSE;
145         }
146         else
147         {
148             char name[20];
149             /* Just to make sure the string is > 0x10000 */
150             strcpy( name, (char *)cls->wnd_class.A.lpszClassName );
151             cls->wnd_class.A.lpszClassName = name;
152             cls->wnd_class.A.hCursor = LoadCursorA( 0, (LPCSTR)cls->wnd_class.A.hCursor );
153             if (!(bicAtomTable[i] = RegisterClassA( &(cls->wnd_class.A) ))) return FALSE;
154         }
155     }
156
157     return TRUE;
158 }
159
160
161 /***********************************************************************
162  *           WIDGETS_IsControl32
163  *
164  * Check whether pWnd is a built-in control or not.
165  */
166 BOOL    WIDGETS_IsControl( WND* pWnd, BUILTIN_CLASS32 cls )
167 {
168     assert( cls < BIC32_NB_CLASSES );
169     return (GetClassWord(pWnd->hwndSelf, GCW_ATOM) == bicAtomTable[cls]);
170 }