push 556f62bab943c37bb6cbad95a6ecb3d73e04a93f
[wine/hacks.git] / dlls / user32 / defwnd.c
blobe3ec37c46d8ac8d99a1d493e5d68305759ee251c
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 "config.h"
23 #include "wine/port.h"
25 #include <string.h>
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winnls.h"
32 #include "win.h"
33 #include "user_private.h"
34 #include "controls.h"
35 #include "wine/unicode.h"
36 #include "wine/winuser16.h"
37 #include "wine/server.h"
38 #include "wine/exception.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win);
43 /* bits in the dwKeyData */
44 #define KEYDATA_ALT 0x2000
45 #define KEYDATA_PREVSTATE 0x4000
47 static short iF10Key = 0;
48 static short iMenuSysKey = 0;
49 static const WCHAR imm32W[] = { 'i','m','m','3','2','\0' };
51 /***********************************************************************
52 * DEFWND_HandleWindowPosChanged
54 * Handle the WM_WINDOWPOSCHANGED message.
56 static void DEFWND_HandleWindowPosChanged( HWND hwnd, const WINDOWPOS *winpos )
58 RECT rect;
59 WND *wndPtr = WIN_GetPtr( hwnd );
61 rect = wndPtr->rectClient;
62 WIN_ReleasePtr( wndPtr );
64 if (!(winpos->flags & SWP_NOCLIENTMOVE))
65 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG(rect.left, rect.top));
67 if (!(winpos->flags & SWP_NOCLIENTSIZE) || (winpos->flags & SWP_STATECHANGED))
69 WPARAM wp = SIZE_RESTORED;
70 if (IsZoomed(hwnd)) wp = SIZE_MAXIMIZED;
71 else if (IsIconic(hwnd)) wp = SIZE_MINIMIZED;
73 SendMessageW( hwnd, WM_SIZE, wp, MAKELONG(rect.right-rect.left, rect.bottom-rect.top) );
78 /***********************************************************************
79 * DEFWND_SetTextA
81 * Set the window text.
83 static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
85 int count;
86 WCHAR *textW;
87 WND *wndPtr;
89 if (!text) text = "";
90 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
92 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
93 if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
95 HeapFree(GetProcessHeap(), 0, wndPtr->text);
96 wndPtr->text = textW;
97 MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
98 SERVER_START_REQ( set_window_text )
100 req->handle = wine_server_user_handle( hwnd );
101 wine_server_add_data( req, textW, (count-1) * sizeof(WCHAR) );
102 wine_server_call( req );
104 SERVER_END_REQ;
106 else
107 ERR("Not enough memory for window text\n");
108 WIN_ReleasePtr( wndPtr );
110 USER_Driver->pSetWindowText( hwnd, textW );
113 /***********************************************************************
114 * DEFWND_SetTextW
116 * Set the window text.
118 static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
120 static const WCHAR empty_string[] = {0};
121 WND *wndPtr;
122 int count;
124 if (!text) text = empty_string;
125 count = strlenW(text) + 1;
127 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
128 HeapFree(GetProcessHeap(), 0, wndPtr->text);
129 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
131 strcpyW( wndPtr->text, text );
132 SERVER_START_REQ( set_window_text )
134 req->handle = wine_server_user_handle( hwnd );
135 wine_server_add_data( req, wndPtr->text, (count-1) * sizeof(WCHAR) );
136 wine_server_call( req );
138 SERVER_END_REQ;
140 else
141 ERR("Not enough memory for window text\n");
142 text = wndPtr->text;
143 WIN_ReleasePtr( wndPtr );
145 USER_Driver->pSetWindowText( hwnd, text );
148 /***********************************************************************
149 * DEFWND_ControlColor
151 * Default colors for control painting.
153 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
155 if( ctlType == CTLCOLOR_SCROLLBAR)
157 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
158 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
159 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
160 SetBkColor( hDC, bk);
162 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
163 * we better use 0x55aa bitmap brush to make scrollbar's background
164 * look different from the window background.
166 if (bk == GetSysColor(COLOR_WINDOW))
167 return SYSCOLOR_55AABrush;
169 UnrealizeObject( hb );
170 return hb;
173 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
175 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
176 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
177 else {
178 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
179 return GetSysColorBrush(COLOR_3DFACE);
181 return GetSysColorBrush(COLOR_WINDOW);
185 /***********************************************************************
186 * DEFWND_Print
188 * This method handles the default behavior for the WM_PRINT message.
190 static void DEFWND_Print( HWND hwnd, HDC hdc, ULONG uFlags)
193 * Visibility flag.
195 if ( (uFlags & PRF_CHECKVISIBLE) &&
196 !IsWindowVisible(hwnd) )
197 return;
200 * Unimplemented flags.
202 if ( (uFlags & PRF_CHILDREN) ||
203 (uFlags & PRF_OWNED) ||
204 (uFlags & PRF_NONCLIENT) )
206 WARN("WM_PRINT message with unsupported flags\n");
210 * Background
212 if ( uFlags & PRF_ERASEBKGND)
213 SendMessageW(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
216 * Client area
218 if ( uFlags & PRF_CLIENT)
219 SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
224 * helpers for calling IMM32
226 * WM_IME_* messages are generated only by IMM32,
227 * so I assume imm32 is already LoadLibrary-ed.
229 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
231 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
232 HWND (WINAPI *pFunc)(HWND);
233 HWND hwndRet = 0;
235 if (!hInstIMM)
237 ERR( "cannot get IMM32 handle\n" );
238 return 0;
241 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
242 if ( pFunc != NULL )
243 hwndRet = (*pFunc)( hwnd );
245 return hwndRet;
248 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
250 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
251 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
252 BOOL fRet = FALSE;
254 if (!hInstIMM)
256 ERR( "cannot get IMM32 handle\n" );
257 return FALSE;
260 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
261 if ( pFunc != NULL )
262 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
264 return fRet;
267 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
269 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
270 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
271 BOOL fRet = FALSE;
273 if (!hInstIMM)
275 ERR( "cannot get IMM32 handle\n" );
276 return FALSE;
279 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
280 if ( pFunc != NULL )
281 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
283 return fRet;
288 /***********************************************************************
289 * DEFWND_DefWinProc
291 * Default window procedure for messages that are the same in Ansi and Unicode.
293 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
295 switch(msg)
297 case WM_NCPAINT:
298 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
300 case WM_NCHITTEST:
302 POINT pt;
303 pt.x = (short)LOWORD(lParam);
304 pt.y = (short)HIWORD(lParam);
305 return NC_HandleNCHitTest( hwnd, pt );
308 case WM_NCCALCSIZE:
309 return NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
311 case WM_WINDOWPOSCHANGING:
312 return WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
314 case WM_WINDOWPOSCHANGED:
315 DEFWND_HandleWindowPosChanged( hwnd, (const WINDOWPOS *)lParam );
316 break;
318 case WM_LBUTTONDOWN:
319 case WM_RBUTTONDOWN:
320 case WM_MBUTTONDOWN:
321 iF10Key = iMenuSysKey = 0;
322 break;
324 case WM_NCLBUTTONDOWN:
325 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
327 case WM_LBUTTONDBLCLK:
328 return NC_HandleNCLButtonDblClk( hwnd, HTCLIENT, lParam );
330 case WM_NCLBUTTONDBLCLK:
331 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
333 case WM_NCRBUTTONDOWN:
334 /* in Windows, capture is taken when right-clicking on the caption bar */
335 if (wParam==HTCAPTION)
337 SetCapture(hwnd);
339 break;
341 case WM_RBUTTONUP:
343 POINT pt;
345 if (hwnd == GetCapture())
346 /* release capture if we took it on WM_NCRBUTTONDOWN */
347 ReleaseCapture();
349 pt.x = (short)LOWORD(lParam);
350 pt.y = (short)HIWORD(lParam);
351 ClientToScreen(hwnd, &pt);
352 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
354 break;
356 case WM_NCRBUTTONUP:
358 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
359 * in Windows), but what _should_ we do? According to MSDN :
360 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
361 * message to the window". When is it appropriate?
363 break;
365 case WM_CONTEXTMENU:
366 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
367 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
368 else
370 LONG hitcode;
371 POINT pt;
372 WND *wndPtr = WIN_GetPtr( hwnd );
373 HMENU hMenu = wndPtr->hSysMenu;
374 WIN_ReleasePtr( wndPtr );
375 if (!hMenu) return 0;
376 pt.x = (short)LOWORD(lParam);
377 pt.y = (short)HIWORD(lParam);
378 hitcode = NC_HandleNCHitTest(hwnd, pt);
380 /* Track system popup if click was in the caption area. */
381 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
382 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
383 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
384 pt.x, pt.y, 0, hwnd, NULL);
386 break;
388 case WM_POPUPSYSTEMMENU:
390 /* This is an undocumented message used by the windows taskbar to
391 display the system menu of windows that belong to other processes. */
392 HMENU menu = GetSystemMenu(hwnd, FALSE);
394 if (menu)
395 TrackPopupMenu(menu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
396 LOWORD(lParam), HIWORD(lParam), 0, hwnd, NULL);
397 return 0;
400 case WM_NCACTIVATE:
401 return NC_HandleNCActivate( hwnd, wParam, lParam );
403 case WM_NCDESTROY:
405 WND *wndPtr = WIN_GetPtr( hwnd );
406 if (!wndPtr) return 0;
407 HeapFree( GetProcessHeap(), 0, wndPtr->text );
408 wndPtr->text = NULL;
409 HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll );
410 HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll );
411 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
412 WIN_ReleasePtr( wndPtr );
413 return 0;
416 case WM_PRINT:
417 DEFWND_Print(hwnd, (HDC)wParam, lParam);
418 return 0;
420 case WM_PAINTICON:
421 case WM_PAINT:
423 PAINTSTRUCT ps;
424 HDC hdc = BeginPaint( hwnd, &ps );
425 if( hdc )
427 HICON hIcon;
428 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON))) )
430 RECT rc;
431 int x, y;
433 GetClientRect( hwnd, &rc );
434 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
435 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
436 TRACE("Painting class icon: vis rect=(%s)\n",
437 wine_dbgstr_rect(&ps.rcPaint));
438 DrawIcon( hdc, x, y, hIcon );
440 EndPaint( hwnd, &ps );
442 return 0;
445 case WM_SYNCPAINT:
446 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
447 return 0;
449 case WM_SETREDRAW:
450 if (wParam) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
451 else
453 RedrawWindow( hwnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
454 WIN_SetStyle( hwnd, 0, WS_VISIBLE );
456 return 0;
458 case WM_CLOSE:
459 DestroyWindow( hwnd );
460 return 0;
462 case WM_MOUSEACTIVATE:
463 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
465 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
466 if (ret) return ret;
469 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
470 return MA_ACTIVATE;
472 case WM_ACTIVATE:
473 /* The default action in Windows is to set the keyboard focus to
474 * the window, if it's being activated and not minimized */
475 if (LOWORD(wParam) != WA_INACTIVE) {
476 if (!IsIconic(hwnd)) SetFocus(hwnd);
478 break;
480 case WM_MOUSEWHEEL:
481 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
482 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
483 break;
485 case WM_ERASEBKGND:
486 case WM_ICONERASEBKGND:
488 RECT rect;
489 HDC hdc = (HDC)wParam;
490 HBRUSH hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
491 if (!hbr) return 0;
493 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
495 /* can't use GetClipBox with a parent DC or we fill the whole parent */
496 GetClientRect( hwnd, &rect );
497 DPtoLP( hdc, (LPPOINT)&rect, 2 );
499 else GetClipBox( hdc, &rect );
500 FillRect( hdc, &rect, hbr );
501 return 1;
504 case WM_GETDLGCODE:
505 return 0;
507 case WM_CTLCOLORMSGBOX:
508 case WM_CTLCOLOREDIT:
509 case WM_CTLCOLORLISTBOX:
510 case WM_CTLCOLORBTN:
511 case WM_CTLCOLORDLG:
512 case WM_CTLCOLORSTATIC:
513 case WM_CTLCOLORSCROLLBAR:
514 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
516 case WM_CTLCOLOR:
517 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
519 case WM_SETCURSOR:
520 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
522 /* with the exception of the border around a resizable wnd,
523 * give the parent first chance to set the cursor */
524 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
526 if (SendMessageW(GetParent(hwnd), WM_SETCURSOR, wParam, lParam)) return TRUE;
529 NC_HandleSetCursor( hwnd, wParam, lParam );
530 break;
532 case WM_SYSCOMMAND:
533 return NC_HandleSysCommand( hwnd, wParam, lParam );
535 case WM_KEYDOWN:
536 if(wParam == VK_F10) iF10Key = VK_F10;
537 break;
539 case WM_SYSKEYDOWN:
540 if( HIWORD(lParam) & KEYDATA_ALT )
542 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
543 if ( (wParam == VK_MENU || wParam == VK_LMENU
544 || wParam == VK_RMENU) && !iMenuSysKey )
545 iMenuSysKey = 1;
546 else
547 iMenuSysKey = 0;
549 iF10Key = 0;
551 if( wParam == VK_F4 ) /* try to close the window */
553 HWND top = GetAncestor( hwnd, GA_ROOT );
554 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
555 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
558 else if( wParam == VK_F10 )
559 iF10Key = 1;
560 else if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
561 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
562 break;
564 case WM_KEYUP:
565 case WM_SYSKEYUP:
566 /* Press and release F10 or ALT */
567 if (((wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU)
568 && iMenuSysKey) || ((wParam == VK_F10) && iF10Key))
569 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
570 iMenuSysKey = iF10Key = 0;
571 break;
573 case WM_SYSCHAR:
575 iMenuSysKey = 0;
576 if (wParam == '\r' && IsIconic(hwnd))
578 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
579 break;
581 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
583 if (wParam == '\t' || wParam == '\x1b') break;
584 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
585 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
586 else
587 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
589 else /* check for Ctrl-Esc */
590 if (wParam != '\x1b') MessageBeep(0);
591 break;
594 case WM_SHOWWINDOW:
596 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
597 WND *pWnd;
598 if (!lParam) return 0; /* sent from ShowWindow */
599 if ((style & WS_VISIBLE) && wParam) return 0;
600 if (!(style & WS_VISIBLE) && !wParam) return 0;
601 if (!GetWindow( hwnd, GW_OWNER )) return 0;
602 if (!(pWnd = WIN_GetPtr( hwnd ))) return 0;
603 if (pWnd == WND_OTHER_PROCESS) return 0;
604 if (wParam)
606 if (!(pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP))
608 WIN_ReleasePtr( pWnd );
609 return 0;
611 pWnd->flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP;
613 else pWnd->flags |= WIN_NEEDS_SHOW_OWNEDPOPUP;
614 WIN_ReleasePtr( pWnd );
615 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
616 break;
619 case WM_CANCELMODE:
620 iMenuSysKey = 0;
621 MENU_EndMenu( hwnd );
622 if (GetCapture() == hwnd) ReleaseCapture();
623 break;
625 case WM_VKEYTOITEM:
626 case WM_CHARTOITEM:
627 return -1;
629 case WM_DROPOBJECT:
630 return DRAG_FILE;
632 case WM_QUERYDROPOBJECT:
633 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
635 case WM_QUERYDRAGICON:
637 UINT len;
639 HICON hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON );
640 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
641 if (hIcon) return (LRESULT)hIcon;
642 for(len=1; len<64; len++)
643 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
644 return (LRESULT)hIcon;
645 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
647 break;
649 case WM_ISACTIVEICON:
651 WND *wndPtr = WIN_GetPtr( hwnd );
652 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
653 WIN_ReleasePtr( wndPtr );
654 return ret;
657 case WM_NOTIFYFORMAT:
658 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
659 else return NFR_ANSI;
661 case WM_QUERYOPEN:
662 case WM_QUERYENDSESSION:
663 return 1;
665 case WM_SETICON:
667 HICON ret;
668 WND *wndPtr = WIN_GetPtr( hwnd );
670 switch(wParam)
672 case ICON_SMALL:
673 ret = wndPtr->hIconSmall;
674 wndPtr->hIconSmall = (HICON)lParam;
675 break;
676 case ICON_BIG:
677 ret = wndPtr->hIcon;
678 wndPtr->hIcon = (HICON)lParam;
679 break;
680 default:
681 ret = 0;
682 break;
684 WIN_ReleasePtr( wndPtr );
686 USER_Driver->pSetWindowIcon( hwnd, wParam, (HICON)lParam );
688 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
689 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
691 return (LRESULT)ret;
694 case WM_GETICON:
696 HICON ret;
697 WND *wndPtr = WIN_GetPtr( hwnd );
699 switch(wParam)
701 case ICON_SMALL:
702 ret = wndPtr->hIconSmall;
703 break;
704 case ICON_BIG:
705 ret = wndPtr->hIcon;
706 break;
707 case ICON_SMALL2:
708 ret = wndPtr->hIconSmall;
709 if (!ret) ret = (HICON)GetClassLongPtrW( hwnd, GCLP_HICONSM );
710 /* FIXME: should have a default here if class icon is null */
711 break;
712 default:
713 ret = 0;
714 break;
716 WIN_ReleasePtr( wndPtr );
717 return (LRESULT)ret;
720 case WM_HELP:
721 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
722 break;
724 case WM_APPCOMMAND:
726 HWND parent = GetParent(hwnd);
727 if(!parent)
728 HOOK_CallHooks(WH_SHELL, HSHELL_APPCOMMAND, wParam, lParam, TRUE);
729 else
730 SendMessageW( parent, msg, wParam, lParam );
731 break;
733 case WM_KEYF1:
735 HELPINFO hi;
737 hi.cbSize = sizeof(HELPINFO);
738 GetCursorPos( &hi.MousePos );
739 if (MENU_IsMenuActive())
741 hi.iContextType = HELPINFO_MENUITEM;
742 hi.hItemHandle = MENU_IsMenuActive();
743 hi.iCtrlId = MenuItemFromPoint( hwnd, hi.hItemHandle, hi.MousePos );
744 hi.dwContextId = GetMenuContextHelpId( hi.hItemHandle );
746 else
748 hi.iContextType = HELPINFO_WINDOW;
749 hi.hItemHandle = hwnd;
750 hi.iCtrlId = GetWindowLongPtrA( hwnd, GWLP_ID );
751 hi.dwContextId = GetWindowContextHelpId( hwnd );
753 SendMessageW( hwnd, WM_HELP, 0, (LPARAM)&hi );
754 break;
757 case WM_INPUTLANGCHANGEREQUEST:
758 ActivateKeyboardLayout( (HKL)lParam, 0 );
759 break;
761 case WM_INPUTLANGCHANGE:
763 int count = 0;
764 HWND *win_array = WIN_ListChildren( hwnd );
766 if (!win_array)
767 break;
768 while (win_array[count])
769 SendMessageW( win_array[count++], WM_INPUTLANGCHANGE, wParam, lParam);
770 HeapFree(GetProcessHeap(),0,win_array);
771 break;
776 return 0;
779 static LPARAM DEFWND_GetTextA( WND *wndPtr, LPSTR dest, WPARAM wParam )
781 LPARAM result = 0;
783 __TRY
785 if (wndPtr->text)
787 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
788 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
789 result = strlen( dest );
791 else dest[0] = '\0';
793 __EXCEPT_PAGE_FAULT
795 return 0;
797 __ENDTRY
798 return result;
801 /***********************************************************************
802 * DefWindowProcA (USER32.@)
804 * See DefWindowProcW.
806 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
808 LRESULT result = 0;
809 HWND full_handle;
811 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
813 if (!IsWindow( hwnd )) return 0;
814 ERR( "called for other process window %p\n", hwnd );
815 return 0;
817 hwnd = full_handle;
819 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
821 switch(msg)
823 case WM_NCCREATE:
824 if (lParam)
826 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
827 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
828 * may have child window IDs instead of window name */
829 if (HIWORD(cs->lpszName))
830 DEFWND_SetTextA( hwnd, cs->lpszName );
831 result = 1;
833 break;
835 case WM_GETTEXTLENGTH:
837 WND *wndPtr = WIN_GetPtr( hwnd );
838 if (wndPtr && wndPtr->text)
839 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
840 NULL, 0, NULL, NULL );
841 WIN_ReleasePtr( wndPtr );
843 break;
845 case WM_GETTEXT:
846 if (wParam)
848 LPSTR dest = (LPSTR)lParam;
849 WND *wndPtr = WIN_GetPtr( hwnd );
851 if (!wndPtr) break;
852 result = DEFWND_GetTextA( wndPtr, dest, wParam );
854 WIN_ReleasePtr( wndPtr );
856 break;
858 case WM_SETTEXT:
859 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
860 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
861 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
862 result = 1; /* success. FIXME: check text length */
863 break;
865 case WM_IME_CHAR:
866 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
867 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
868 break;
870 case WM_IME_KEYDOWN:
871 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
872 break;
874 case WM_IME_KEYUP:
875 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
876 break;
878 case WM_IME_STARTCOMPOSITION:
879 case WM_IME_COMPOSITION:
880 case WM_IME_ENDCOMPOSITION:
881 case WM_IME_SELECT:
882 case WM_IME_NOTIFY:
884 HWND hwndIME;
886 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
887 if (hwndIME)
888 result = SendMessageA( hwndIME, msg, wParam, lParam );
890 break;
891 case WM_IME_SETCONTEXT:
893 HWND hwndIME;
895 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
896 if (hwndIME)
897 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
899 break;
901 case WM_SYSCHAR:
903 CHAR ch = LOWORD(wParam);
904 WCHAR wch;
905 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
906 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
908 /* fall through */
909 default:
910 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
911 break;
914 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
915 return result;
919 static LPARAM DEFWND_GetTextW( WND *wndPtr, LPWSTR dest, WPARAM wParam )
921 LPARAM result = 0;
923 __TRY
925 if (wndPtr->text)
927 lstrcpynW( dest, wndPtr->text, wParam );
928 result = strlenW( dest );
930 else dest[0] = '\0';
932 __EXCEPT_PAGE_FAULT
934 return 0;
936 __ENDTRY
938 return result;
941 /***********************************************************************
942 * DefWindowProcW (USER32.@) Calls default window message handler
944 * Calls default window procedure for messages not processed
945 * by application.
947 * RETURNS
948 * Return value is dependent upon the message.
950 LRESULT WINAPI DefWindowProcW(
951 HWND hwnd, /* [in] window procedure receiving message */
952 UINT msg, /* [in] message identifier */
953 WPARAM wParam, /* [in] first message parameter */
954 LPARAM lParam ) /* [in] second message parameter */
956 LRESULT result = 0;
957 HWND full_handle;
959 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
961 if (!IsWindow( hwnd )) return 0;
962 ERR( "called for other process window %p\n", hwnd );
963 return 0;
965 hwnd = full_handle;
966 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
968 switch(msg)
970 case WM_NCCREATE:
971 if (lParam)
973 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
974 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
975 * may have child window IDs instead of window name */
976 if (HIWORD(cs->lpszName))
977 DEFWND_SetTextW( hwnd, cs->lpszName );
978 result = 1;
980 break;
982 case WM_GETTEXTLENGTH:
984 WND *wndPtr = WIN_GetPtr( hwnd );
985 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
986 WIN_ReleasePtr( wndPtr );
988 break;
990 case WM_GETTEXT:
991 if (wParam)
993 LPWSTR dest = (LPWSTR)lParam;
994 WND *wndPtr = WIN_GetPtr( hwnd );
996 if (!wndPtr) break;
997 result = DEFWND_GetTextW( wndPtr, dest, wParam );
998 WIN_ReleasePtr( wndPtr );
1000 break;
1002 case WM_SETTEXT:
1003 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
1004 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
1005 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
1006 result = 1; /* success. FIXME: check text length */
1007 break;
1009 case WM_IME_CHAR:
1010 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
1011 break;
1013 case WM_IME_KEYDOWN:
1014 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
1015 break;
1017 case WM_IME_KEYUP:
1018 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
1019 break;
1021 case WM_IME_SETCONTEXT:
1023 HWND hwndIME;
1025 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1026 if (hwndIME)
1027 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
1029 break;
1031 case WM_IME_STARTCOMPOSITION:
1032 case WM_IME_COMPOSITION:
1033 case WM_IME_ENDCOMPOSITION:
1034 case WM_IME_SELECT:
1035 case WM_IME_NOTIFY:
1037 HWND hwndIME;
1039 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1040 if (hwndIME)
1041 result = SendMessageW( hwndIME, msg, wParam, lParam );
1043 break;
1045 default:
1046 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1047 break;
1049 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
1050 return result;