windows.networking.hostname/tests: Add IHostNameFactory::CreateHostName() tests.
[wine.git] / dlls / user32 / defwnd.c
blob60afec4e7c65c75738603664bd0a4b6ba28b4c4a
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 "user_private.h"
23 #include "controls.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(win);
28 static void default_ime_compositionW( HWND hwnd, WPARAM wparam, LPARAM lparam )
30 WCHAR *buf = NULL;
31 LONG size, i;
32 HIMC himc;
34 if (!(lparam & GCS_RESULTSTR) || !(himc = ImmGetContext( hwnd ))) return;
36 if ((size = ImmGetCompositionStringW( himc, GCS_RESULTSTR, NULL, 0 )))
38 if (!(buf = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) size = 0;
39 else size = ImmGetCompositionStringW( himc, GCS_RESULTSTR, buf, size * sizeof(WCHAR) );
41 ImmReleaseContext( hwnd, himc );
43 for (i = 0; i < size / sizeof(WCHAR); i++)
44 SendMessageW( hwnd, WM_IME_CHAR, buf[i], 1 );
45 HeapFree( GetProcessHeap(), 0, buf );
48 static void default_ime_compositionA( HWND hwnd, WPARAM wparam, LPARAM lparam )
50 unsigned char lead = 0;
51 char *buf = NULL;
52 LONG size, i;
53 HIMC himc;
55 if (!(lparam & GCS_RESULTSTR) || !(himc = ImmGetContext( hwnd ))) return;
57 if ((size = ImmGetCompositionStringA( himc, GCS_RESULTSTR, NULL, 0 )))
59 if (!(buf = HeapAlloc( GetProcessHeap(), 0, size ))) size = 0;
60 else size = ImmGetCompositionStringA( himc, GCS_RESULTSTR, buf, size );
62 ImmReleaseContext( hwnd, himc );
64 for (i = 0; i < size; i++)
66 unsigned char c = buf[i];
67 if (!lead)
69 if (IsDBCSLeadByte( c )) lead = c;
70 else SendMessageA( hwnd, WM_IME_CHAR, c, 1 );
72 else
74 SendMessageA( hwnd, WM_IME_CHAR, MAKEWORD(c, lead), 1 );
75 lead = 0;
79 HeapFree( GetProcessHeap(), 0, buf );
82 /***********************************************************************
83 * DefWindowProcA (USER32.@)
85 * See DefWindowProcW.
87 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
89 LRESULT result = 0;
90 HWND full_handle;
92 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
94 if (!IsWindow( hwnd )) return 0;
95 ERR( "called for other process window %p\n", hwnd );
96 return 0;
98 hwnd = full_handle;
100 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
102 switch(msg)
104 case WM_SYSCOMMAND:
105 result = NC_HandleSysCommand( hwnd, wParam, lParam );
106 break;
108 case WM_IME_CHAR:
109 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
110 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
111 break;
113 case WM_IME_KEYDOWN:
114 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
115 break;
117 case WM_IME_KEYUP:
118 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
119 break;
121 case WM_IME_COMPOSITION:
123 HWND ime_hwnd = NtUserGetDefaultImeWindow( hwnd );
124 if (!ime_hwnd || ime_hwnd == NtUserGetParent( hwnd )) break;
126 default_ime_compositionA( hwnd, wParam, lParam );
127 /* fall through */
130 default:
131 result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, NtUserDefWindowProc, TRUE );
132 break;
135 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
136 return result;
140 /***********************************************************************
141 * DefWindowProcW (USER32.@) Calls default window message handler
143 * Calls default window procedure for messages not processed
144 * by application.
146 * RETURNS
147 * Return value is dependent upon the message.
149 LRESULT WINAPI DefWindowProcW(
150 HWND hwnd, /* [in] window procedure receiving message */
151 UINT msg, /* [in] message identifier */
152 WPARAM wParam, /* [in] first message parameter */
153 LPARAM lParam ) /* [in] second message parameter */
155 LRESULT result = 0;
156 HWND full_handle;
158 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
160 if (!IsWindow( hwnd )) return 0;
161 ERR( "called for other process window %p\n", hwnd );
162 return 0;
164 hwnd = full_handle;
165 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
167 switch(msg)
169 case WM_SYSCOMMAND:
170 result = NC_HandleSysCommand( hwnd, wParam, lParam );
171 break;
173 case WM_IME_CHAR:
174 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
175 break;
177 case WM_IME_KEYDOWN:
178 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
179 break;
181 case WM_IME_KEYUP:
182 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
183 break;
185 case WM_IME_COMPOSITION:
187 HWND ime_hwnd = NtUserGetDefaultImeWindow( hwnd );
188 if (!ime_hwnd || ime_hwnd == NtUserGetParent( hwnd )) break;
190 default_ime_compositionW( hwnd, wParam, lParam );
191 /* fall through */
194 default:
195 result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, NtUserDefWindowProc, FALSE );
196 break;
198 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
199 return result;