2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
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
31 #include "user_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(win
);
37 /***********************************************************************
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
));
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
);
62 SetTextColor( hDC
, GetSysColor(COLOR_WINDOWTEXT
));
64 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
65 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
67 SetBkColor( hDC
, GetSysColor(COLOR_3DFACE
) );
68 return GetSysColorBrush(COLOR_3DFACE
);
70 return GetSysColorBrush(COLOR_WINDOW
);
74 /***********************************************************************
75 * DefWindowProcA (USER32.@)
79 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
84 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
86 if (!IsWindow( hwnd
)) return 0;
87 ERR( "called for other process window %p\n", hwnd
);
92 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, 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
);
113 result
= NC_HandleNCMouseMove( hwnd
, wParam
, lParam
);
116 case WM_NCMOUSELEAVE
:
117 result
= NC_HandleNCMouseLeave( hwnd
);
121 result
= NC_HandleSysCommand( hwnd
, wParam
, lParam
);
125 if (HIBYTE(wParam
)) PostMessageA( hwnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
126 PostMessageA( hwnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
130 result
= PostMessageA( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
134 result
= PostMessageA( hwnd
, WM_KEYUP
, wParam
, lParam
);
137 case WM_IME_COMPOSITION
:
138 if (lParam
& GCS_RESULTSTR
)
141 unsigned char lead
= 0;
143 HIMC himc
= ImmGetContext( hwnd
);
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
];
159 if (IsDBCSLeadByte( c
))
162 SendMessageA( hwnd
, WM_IME_CHAR
, c
, 1 );
166 SendMessageA( hwnd
, WM_IME_CHAR
, MAKEWORD(c
, lead
), 1 );
170 HeapFree( GetProcessHeap(), 0, buf
);
174 case WM_IME_STARTCOMPOSITION
:
175 case WM_IME_ENDCOMPOSITION
:
180 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
182 result
= SendMessageA( hwndIME
, msg
, wParam
, lParam
);
185 case WM_IME_SETCONTEXT
:
187 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
188 if (hwndIME
) result
= ImmIsUIMessageA( hwndIME
, msg
, wParam
, lParam
);
193 result
= NtUserMessageCall( hwnd
, msg
, wParam
, lParam
, 0, NtUserDefWindowProc
, TRUE
);
197 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);
202 /***********************************************************************
203 * DefWindowProcW (USER32.@) Calls default window message handler
205 * Calls default window procedure for messages not processed
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 */
220 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
222 if (!IsWindow( hwnd
)) return 0;
223 ERR( "called for other process window %p\n", hwnd
);
227 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, 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
);
248 result
= NC_HandleNCMouseMove( hwnd
, wParam
, lParam
);
251 case WM_NCMOUSELEAVE
:
252 result
= NC_HandleNCMouseLeave( hwnd
);
256 result
= NC_HandleSysCommand( hwnd
, wParam
, lParam
);
260 PostMessageW( hwnd
, WM_CHAR
, wParam
, lParam
);
264 result
= PostMessageW( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
268 result
= PostMessageW( hwnd
, WM_KEYUP
, wParam
, lParam
);
271 case WM_IME_SETCONTEXT
:
273 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
274 if (hwndIME
) result
= ImmIsUIMessageW( hwndIME
, msg
, wParam
, lParam
);
278 case WM_IME_COMPOSITION
:
279 if (lParam
& GCS_RESULTSTR
)
283 HIMC himc
= ImmGetContext( hwnd
);
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
);
300 case WM_IME_STARTCOMPOSITION
:
301 case WM_IME_ENDCOMPOSITION
:
306 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
308 result
= SendMessageW( hwndIME
, msg
, wParam
, lParam
);
313 result
= NtUserMessageCall( hwnd
, msg
, wParam
, lParam
, 0, NtUserDefWindowProc
, FALSE
);
316 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);