win32u: Move WM_GETTEXT implementation from user32.
[wine.git] / dlls / user32 / defwnd.c
blobd29846ad623394dc911ba69f4c1ff7a9635763b3
1 /*
2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
5 * 1995 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <string.h>
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winnls.h"
29 #include "imm.h"
30 #include "win.h"
31 #include "user_private.h"
32 #include "controls.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(win);
37 /***********************************************************************
38 * DEFWND_ControlColor
40 * Default colors for control painting.
42 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
44 if( ctlType == CTLCOLOR_SCROLLBAR)
46 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
47 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
48 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
49 SetBkColor( hDC, bk);
51 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
52 * we better use 0x55aa bitmap brush to make scrollbar's background
53 * look different from the window background.
55 if (bk == GetSysColor(COLOR_WINDOW))
56 return SYSCOLOR_Get55AABrush();
58 UnrealizeObject( hb );
59 return hb;
62 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
64 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
65 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
66 else {
67 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
68 return GetSysColorBrush(COLOR_3DFACE);
70 return GetSysColorBrush(COLOR_WINDOW);
74 /***********************************************************************
75 * DefWindowProcA (USER32.@)
77 * See DefWindowProcW.
79 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
81 LRESULT result = 0;
82 HWND full_handle;
84 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
86 if (!IsWindow( hwnd )) return 0;
87 ERR( "called for other process window %p\n", hwnd );
88 return 0;
90 hwnd = full_handle;
92 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
94 switch(msg)
96 case WM_NCCREATE:
97 if (lParam)
99 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
101 result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, NtUserDefWindowProc, TRUE );
103 if(cs->style & (WS_HSCROLL | WS_VSCROLL))
105 SCROLLINFO si = {sizeof si, SIF_ALL, 0, 100, 0, 0, 0};
106 SetScrollInfo( hwnd, SB_HORZ, &si, FALSE );
107 SetScrollInfo( hwnd, SB_VERT, &si, FALSE );
110 break;
112 case WM_NCMOUSEMOVE:
113 result = NC_HandleNCMouseMove( hwnd, wParam, lParam );
114 break;
116 case WM_NCMOUSELEAVE:
117 result = NC_HandleNCMouseLeave( hwnd );
118 break;
120 case WM_SYSCOMMAND:
121 result = NC_HandleSysCommand( hwnd, wParam, lParam );
122 break;
124 case WM_IME_CHAR:
125 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
126 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
127 break;
129 case WM_IME_KEYDOWN:
130 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
131 break;
133 case WM_IME_KEYUP:
134 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
135 break;
137 case WM_IME_COMPOSITION:
138 if (lParam & GCS_RESULTSTR)
140 LONG size, i;
141 unsigned char lead = 0;
142 char *buf = NULL;
143 HIMC himc = ImmGetContext( hwnd );
145 if (himc)
147 if ((size = ImmGetCompositionStringA( himc, GCS_RESULTSTR, NULL, 0 )))
149 if (!(buf = HeapAlloc( GetProcessHeap(), 0, size ))) size = 0;
150 else size = ImmGetCompositionStringA( himc, GCS_RESULTSTR, buf, size );
152 ImmReleaseContext( hwnd, himc );
154 for (i = 0; i < size; i++)
156 unsigned char c = buf[i];
157 if (!lead)
159 if (IsDBCSLeadByte( c ))
160 lead = c;
161 else
162 SendMessageA( hwnd, WM_IME_CHAR, c, 1 );
164 else
166 SendMessageA( hwnd, WM_IME_CHAR, MAKEWORD(c, lead), 1 );
167 lead = 0;
170 HeapFree( GetProcessHeap(), 0, buf );
173 /* fall through */
174 case WM_IME_STARTCOMPOSITION:
175 case WM_IME_ENDCOMPOSITION:
176 case WM_IME_SELECT:
177 case WM_IME_NOTIFY:
178 case WM_IME_CONTROL:
180 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
181 if (hwndIME)
182 result = SendMessageA( hwndIME, msg, wParam, lParam );
184 break;
185 case WM_IME_SETCONTEXT:
187 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
188 if (hwndIME) result = ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
190 break;
192 default:
193 result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, NtUserDefWindowProc, TRUE );
194 break;
197 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
198 return result;
202 /***********************************************************************
203 * DefWindowProcW (USER32.@) Calls default window message handler
205 * Calls default window procedure for messages not processed
206 * by application.
208 * RETURNS
209 * Return value is dependent upon the message.
211 LRESULT WINAPI DefWindowProcW(
212 HWND hwnd, /* [in] window procedure receiving message */
213 UINT msg, /* [in] message identifier */
214 WPARAM wParam, /* [in] first message parameter */
215 LPARAM lParam ) /* [in] second message parameter */
217 LRESULT result = 0;
218 HWND full_handle;
220 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
222 if (!IsWindow( hwnd )) return 0;
223 ERR( "called for other process window %p\n", hwnd );
224 return 0;
226 hwnd = full_handle;
227 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
229 switch(msg)
231 case WM_NCCREATE:
232 if (lParam)
234 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
236 result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, NtUserDefWindowProc, FALSE );
238 if(cs->style & (WS_HSCROLL | WS_VSCROLL))
240 SCROLLINFO si = {sizeof si, SIF_ALL, 0, 100, 0, 0, 0};
241 SetScrollInfo( hwnd, SB_HORZ, &si, FALSE );
242 SetScrollInfo( hwnd, SB_VERT, &si, FALSE );
245 break;
247 case WM_NCMOUSEMOVE:
248 result = NC_HandleNCMouseMove( hwnd, wParam, lParam );
249 break;
251 case WM_NCMOUSELEAVE:
252 result = NC_HandleNCMouseLeave( hwnd );
253 break;
255 case WM_SYSCOMMAND:
256 result = NC_HandleSysCommand( hwnd, wParam, lParam );
257 break;
259 case WM_IME_CHAR:
260 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
261 break;
263 case WM_IME_KEYDOWN:
264 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
265 break;
267 case WM_IME_KEYUP:
268 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
269 break;
271 case WM_IME_SETCONTEXT:
273 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
274 if (hwndIME) result = ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
276 break;
278 case WM_IME_COMPOSITION:
279 if (lParam & GCS_RESULTSTR)
281 LONG size, i;
282 WCHAR *buf = NULL;
283 HIMC himc = ImmGetContext( hwnd );
285 if (himc)
287 if ((size = ImmGetCompositionStringW( himc, GCS_RESULTSTR, NULL, 0 )))
289 if (!(buf = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) size = 0;
290 else size = ImmGetCompositionStringW( himc, GCS_RESULTSTR, buf, size * sizeof(WCHAR) );
292 ImmReleaseContext( hwnd, himc );
294 for (i = 0; i < size / sizeof(WCHAR); i++)
295 SendMessageW( hwnd, WM_IME_CHAR, buf[i], 1 );
296 HeapFree( GetProcessHeap(), 0, buf );
299 /* fall through */
300 case WM_IME_STARTCOMPOSITION:
301 case WM_IME_ENDCOMPOSITION:
302 case WM_IME_SELECT:
303 case WM_IME_NOTIFY:
304 case WM_IME_CONTROL:
306 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
307 if (hwndIME)
308 result = SendMessageW( hwndIME, msg, wParam, lParam );
310 break;
312 default:
313 result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, NtUserDefWindowProc, FALSE );
314 break;
316 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
317 return result;