localspl: Add unixname port extension.
[wine.git] / dlls / user32 / defwnd.c
blobb4b42b86ae18567cf14f3dd54ed2236f4ae7edff
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);
29 /***********************************************************************
30 * DefWindowProcA (USER32.@)
32 * See DefWindowProcW.
34 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
36 LRESULT result = 0;
37 HWND full_handle;
39 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
41 if (!IsWindow( hwnd )) return 0;
42 ERR( "called for other process window %p\n", hwnd );
43 return 0;
45 hwnd = full_handle;
47 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
49 switch(msg)
51 case WM_SYSCOMMAND:
52 result = NC_HandleSysCommand( hwnd, wParam, lParam );
53 break;
55 case WM_IME_CHAR:
56 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
57 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
58 break;
60 case WM_IME_KEYDOWN:
61 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
62 break;
64 case WM_IME_KEYUP:
65 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
66 break;
68 case WM_IME_COMPOSITION:
69 if (lParam & GCS_RESULTSTR)
71 LONG size, i;
72 unsigned char lead = 0;
73 char *buf = NULL;
74 HIMC himc = ImmGetContext( hwnd );
76 if (himc)
78 if ((size = ImmGetCompositionStringA( himc, GCS_RESULTSTR, NULL, 0 )))
80 if (!(buf = HeapAlloc( GetProcessHeap(), 0, size ))) size = 0;
81 else size = ImmGetCompositionStringA( himc, GCS_RESULTSTR, buf, size );
83 ImmReleaseContext( hwnd, himc );
85 for (i = 0; i < size; i++)
87 unsigned char c = buf[i];
88 if (!lead)
90 if (IsDBCSLeadByte( c ))
91 lead = c;
92 else
93 SendMessageA( hwnd, WM_IME_CHAR, c, 1 );
95 else
97 SendMessageA( hwnd, WM_IME_CHAR, MAKEWORD(c, lead), 1 );
98 lead = 0;
101 HeapFree( GetProcessHeap(), 0, buf );
104 /* fall through */
106 default:
107 result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, NtUserDefWindowProc, TRUE );
108 break;
111 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
112 return result;
116 /***********************************************************************
117 * DefWindowProcW (USER32.@) Calls default window message handler
119 * Calls default window procedure for messages not processed
120 * by application.
122 * RETURNS
123 * Return value is dependent upon the message.
125 LRESULT WINAPI DefWindowProcW(
126 HWND hwnd, /* [in] window procedure receiving message */
127 UINT msg, /* [in] message identifier */
128 WPARAM wParam, /* [in] first message parameter */
129 LPARAM lParam ) /* [in] second message parameter */
131 LRESULT result = 0;
132 HWND full_handle;
134 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
136 if (!IsWindow( hwnd )) return 0;
137 ERR( "called for other process window %p\n", hwnd );
138 return 0;
140 hwnd = full_handle;
141 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
143 switch(msg)
145 case WM_SYSCOMMAND:
146 result = NC_HandleSysCommand( hwnd, wParam, lParam );
147 break;
149 case WM_IME_CHAR:
150 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
151 break;
153 case WM_IME_KEYDOWN:
154 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
155 break;
157 case WM_IME_KEYUP:
158 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
159 break;
161 case WM_IME_COMPOSITION:
162 if (lParam & GCS_RESULTSTR)
164 LONG size, i;
165 WCHAR *buf = NULL;
166 HIMC himc = ImmGetContext( hwnd );
168 if (himc)
170 if ((size = ImmGetCompositionStringW( himc, GCS_RESULTSTR, NULL, 0 )))
172 if (!(buf = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) size = 0;
173 else size = ImmGetCompositionStringW( himc, GCS_RESULTSTR, buf, size * sizeof(WCHAR) );
175 ImmReleaseContext( hwnd, himc );
177 for (i = 0; i < size / sizeof(WCHAR); i++)
178 SendMessageW( hwnd, WM_IME_CHAR, buf[i], 1 );
179 HeapFree( GetProcessHeap(), 0, buf );
182 /* fall through */
184 default:
185 result = NtUserMessageCall( hwnd, msg, wParam, lParam, 0, NtUserDefWindowProc, FALSE );
186 break;
188 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
189 return result;