[User32]
[reactos.git] / reactos / dll / win32 / user32 / controls / regcontrol.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS User32
4 * PURPOSE: Built-in control registration
5 * FILE: dll/win32/user32/controls/regcontrol.c
6 * PROGRAMER: Ge van Geldorp (ge@gse.nl)
7 * REVISION HISTORY: 2003/06/16 GvG Created
8 * NOTES: Adapted from Wine
9 */
10
11 #include <user32.h>
12
13 #include <wine/debug.h>
14 WINE_DEFAULT_DEBUG_CHANNEL(user32);
15
16 DWORD RegisterDefaultClasses = FALSE;
17
18 static PFNCLIENT pfnClientA;
19 static PFNCLIENT pfnClientW;
20 static PFNCLIENTWORKER pfnClientWorker;
21
22 //
23 // FIXME!
24 // These are not "System Classes" but Global Classes that are registered
25 // every time a process is created, so these can be unregistered as the msdn
26 // documents states.
27 //
28 static const struct
29 {
30 const struct builtin_class_descr *desc;
31 WORD fnid;
32 WORD ClsId;
33 } g_SysClasses[] =
34 {
35 { &DIALOG_builtin_class, FNID_DIALOG, ICLS_DIALOG},
36 /* { &POPUPMENU_builtin_class, FNID_MENU, ICLS_MENU}, // moved to win32k */
37 { &COMBO_builtin_class, FNID_COMBOBOX, ICLS_COMBOBOX},
38 { &COMBOLBOX_builtin_class, FNID_COMBOLBOX, ICLS_COMBOLBOX},
39 { &MDICLIENT_builtin_class, FNID_MDICLIENT, ICLS_MDICLIENT},
40 #if 0
41 { &MENU_builtin_class, FNID_MENU, ICLS_MENU},
42 #endif
43 /* { &SCROLL_builtin_class, FNID_SCROLLBAR, ICLS_SCROLLBAR}, // moved to win32k */
44 { &BUTTON_builtin_class, FNID_BUTTON, ICLS_BUTTON},
45 { &LISTBOX_builtin_class, FNID_LISTBOX, ICLS_LISTBOX},
46 { &EDIT_builtin_class, FNID_EDIT, ICLS_EDIT},
47 /* { &ICONTITLE_builtin_class, FNID_ICONTITLE, ICLS_ICONTITLE}, // moved to win32k */
48 { &STATIC_builtin_class, FNID_STATIC, ICLS_STATIC},
49 };
50
51 BOOL WINAPI RegisterSystemControls(VOID)
52 {
53 WNDCLASSEXW WndClass;
54 UINT i;
55 ATOM atom;
56
57 if (RegisterDefaultClasses) return TRUE;
58
59 ZeroMemory(&WndClass, sizeof(WndClass));
60
61 WndClass.cbSize = sizeof(WndClass);
62
63 for (i = 0; i != sizeof(g_SysClasses) / sizeof(g_SysClasses[0]); i++)
64 {
65 WndClass.lpszClassName = g_SysClasses[i].desc->name;
66
67 // Set Global bit!
68 WndClass.style = g_SysClasses[i].desc->style|CS_GLOBALCLASS;
69 WndClass.lpfnWndProc = g_SysClasses[i].desc->procW;
70 WndClass.cbWndExtra = g_SysClasses[i].desc->extra;
71 WndClass.hCursor = LoadCursorW(NULL, g_SysClasses[i].desc->cursor);
72 WndClass.hbrBackground= g_SysClasses[i].desc->brush;
73
74 atom = RegisterClassExWOWW( &WndClass,
75 0,
76 g_SysClasses[i].fnid,
77 0,
78 FALSE);
79 if (atom)
80 RegisterDefaultClasses |= ICLASS_TO_MASK(g_SysClasses[i].ClsId);
81 }
82
83 return TRUE;
84 }
85
86 LRESULT
87 WINAPI
88 MsgWindowProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
89 {
90 PWND pWnd;
91
92 pWnd = ValidateHwnd(hwnd);
93 if (pWnd)
94 {
95 if (!pWnd->fnid)
96 {
97 NtUserSetWindowFNID(hwnd, FNID_MESSAGEWND);
98 }
99 }
100
101 if (message == WM_NCCREATE) return TRUE;
102
103 if (message == WM_DESTROY)
104 NtUserSetWindowFNID(hwnd, FNID_DESTROY);
105
106 return DefWindowProc(hwnd, message, wParam, lParam );
107 }
108
109 LRESULT
110 WINAPI
111 DialogWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode)
112 {
113 if (unicode)
114 return DefDlgProcW( hwnd, uMsg, wParam, lParam);
115 return DefDlgProcA( hwnd, uMsg, wParam, lParam);
116 }
117
118 BOOL WINAPI RegisterClientPFN(VOID)
119 {
120 NTSTATUS Status;
121
122 pfnClientA.pfnScrollBarWndProc = ScrollBarWndProcA;
123 pfnClientW.pfnScrollBarWndProc = ScrollBarWndProcW;
124 pfnClientA.pfnTitleWndProc = IconTitleWndProc;
125 pfnClientW.pfnTitleWndProc = IconTitleWndProc;
126 pfnClientA.pfnMenuWndProc = PopupMenuWndProcA;
127 pfnClientW.pfnMenuWndProc = PopupMenuWndProcW;
128 pfnClientA.pfnDesktopWndProc = DesktopWndProc;
129 pfnClientW.pfnDesktopWndProc = DesktopWndProc;
130 pfnClientA.pfnDefWindowProc = DefWindowProcA;
131 pfnClientW.pfnDefWindowProc = DefWindowProcW;
132 pfnClientA.pfnMessageWindowProc = MsgWindowProc;
133 pfnClientW.pfnMessageWindowProc = MsgWindowProc;
134 pfnClientA.pfnSwitchWindowProc = DefWindowProcA;
135 pfnClientW.pfnSwitchWindowProc = DefWindowProcW;
136 pfnClientA.pfnButtonWndProc = ButtonWndProcA;
137 pfnClientW.pfnButtonWndProc = ButtonWndProcW;
138 pfnClientA.pfnComboBoxWndProc = ComboWndProcA;
139 pfnClientW.pfnComboBoxWndProc = ComboWndProcW;
140 pfnClientA.pfnComboListBoxProc = ListBoxWndProcA;
141 pfnClientW.pfnComboListBoxProc = ListBoxWndProcW;
142 pfnClientA.pfnDialogWndProc = DefDlgProcA;
143 pfnClientW.pfnDialogWndProc = DefDlgProcW;
144 pfnClientA.pfnEditWndProc = EditWndProcA;
145 pfnClientW.pfnEditWndProc = EditWndProcW;
146 pfnClientA.pfnListBoxWndProc = ListBoxWndProcA;
147 pfnClientW.pfnListBoxWndProc = ListBoxWndProcW;
148 pfnClientA.pfnMDIClientWndProc = MDIClientWndProcA;
149 pfnClientW.pfnMDIClientWndProc = MDIClientWndProcW;
150 pfnClientA.pfnStaticWndProc = StaticWndProcA;
151 pfnClientW.pfnStaticWndProc = StaticWndProcW;
152 pfnClientA.pfnImeWndProc = DefWindowProcA;
153 pfnClientW.pfnImeWndProc = DefWindowProcW;
154 pfnClientA.pfnGhostWndProc = DefWindowProcA;
155 pfnClientW.pfnGhostWndProc = DefWindowProcW;
156 pfnClientA.pfnHkINLPCWPSTRUCT = DefWindowProcA;
157 pfnClientW.pfnHkINLPCWPSTRUCT = DefWindowProcW;
158 pfnClientA.pfnHkINLPCWPRETSTRUCT = DefWindowProcA;
159 pfnClientW.pfnHkINLPCWPRETSTRUCT = DefWindowProcW;
160 pfnClientA.pfnDispatchHook = DefWindowProcA;
161 pfnClientW.pfnDispatchHook = DefWindowProcW;
162 pfnClientA.pfnDispatchDefWindowProc = DefWindowProcA;
163 pfnClientW.pfnDispatchDefWindowProc = DefWindowProcW;
164 pfnClientA.pfnDispatchMessage = DefWindowProcA;
165 pfnClientW.pfnDispatchMessage = DefWindowProcW;
166 pfnClientA.pfnMDIActivateDlgProc = DefWindowProcA;
167 pfnClientW.pfnMDIActivateDlgProc = DefWindowProcW;
168
169 pfnClientWorker.pfnButtonWndProc = ButtonWndProc_common;
170 pfnClientWorker.pfnComboBoxWndProc = ComboWndProc_common;
171 pfnClientWorker.pfnComboListBoxProc = ListBoxWndProc_common;
172 pfnClientWorker.pfnDialogWndProc = DialogWndProc_common;
173 pfnClientWorker.pfnEditWndProc = EditWndProc_common;
174 pfnClientWorker.pfnListBoxWndProc = ListBoxWndProc_common;
175 pfnClientWorker.pfnMDIClientWndProc = MDIClientWndProc_common;
176 pfnClientWorker.pfnStaticWndProc = StaticWndProc_common;
177 pfnClientWorker.pfnImeWndProc = User32DefWindowProc;
178 pfnClientWorker.pfnGhostWndProc = User32DefWindowProc;
179 pfnClientWorker.pfnCtfHookProc = User32DefWindowProc;
180
181 Status = NtUserInitializeClientPfnArrays( &pfnClientA,
182 &pfnClientW,
183 &pfnClientWorker,
184 User32Instance);
185
186 return NT_SUCCESS(Status) ? TRUE : FALSE;
187 }