winemenubuilder: silence an err
[wine/multimedia.git] / dlls / user32 / defwnd.c
blob0ac308c8ddb4b1613448ad80590af9206faae1c9
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/server.h"
37 #include "wine/exception.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(win);
42 /* bits in the dwKeyData */
43 #define KEYDATA_ALT 0x2000
44 #define KEYDATA_PREVSTATE 0x4000
46 #define DRAG_FILE 0x454C4946
48 static short iF10Key = 0;
49 static short iMenuSysKey = 0;
50 static const WCHAR imm32W[] = { 'i','m','m','3','2','\0' };
52 /***********************************************************************
53 * DEFWND_HandleWindowPosChanged
55 * Handle the WM_WINDOWPOSCHANGED message.
57 static void DEFWND_HandleWindowPosChanged( HWND hwnd, const WINDOWPOS *winpos )
59 RECT rect;
61 WIN_GetRectangles( hwnd, COORDS_PARENT, NULL, &rect );
62 if (!(winpos->flags & SWP_NOCLIENTMOVE))
63 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG(rect.left, rect.top));
65 if (!(winpos->flags & SWP_NOCLIENTSIZE) || (winpos->flags & SWP_STATECHANGED))
67 if (IsIconic( hwnd ))
69 SendMessageW( hwnd, WM_SIZE, SIZE_MINIMIZED, 0 );
71 else
73 WPARAM wp = IsZoomed( hwnd ) ? SIZE_MAXIMIZED : SIZE_RESTORED;
75 SendMessageW( hwnd, WM_SIZE, wp, MAKELONG(rect.right-rect.left, rect.bottom-rect.top) );
81 /***********************************************************************
82 * DEFWND_SetTextA
84 * Set the window text.
86 static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
88 int count;
89 WCHAR *textW;
90 WND *wndPtr;
92 if (!text) text = "";
93 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
95 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
96 if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
98 HeapFree(GetProcessHeap(), 0, wndPtr->text);
99 wndPtr->text = textW;
100 MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
101 SERVER_START_REQ( set_window_text )
103 req->handle = wine_server_user_handle( hwnd );
104 wine_server_add_data( req, textW, (count-1) * sizeof(WCHAR) );
105 wine_server_call( req );
107 SERVER_END_REQ;
109 else
110 ERR("Not enough memory for window text\n");
111 WIN_ReleasePtr( wndPtr );
113 USER_Driver->pSetWindowText( hwnd, textW );
116 /***********************************************************************
117 * DEFWND_SetTextW
119 * Set the window text.
121 static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
123 static const WCHAR empty_string[] = {0};
124 WND *wndPtr;
125 int count;
127 if (!text) text = empty_string;
128 count = strlenW(text) + 1;
130 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
131 HeapFree(GetProcessHeap(), 0, wndPtr->text);
132 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
134 strcpyW( wndPtr->text, text );
135 SERVER_START_REQ( set_window_text )
137 req->handle = wine_server_user_handle( hwnd );
138 wine_server_add_data( req, wndPtr->text, (count-1) * sizeof(WCHAR) );
139 wine_server_call( req );
141 SERVER_END_REQ;
143 else
144 ERR("Not enough memory for window text\n");
145 text = wndPtr->text;
146 WIN_ReleasePtr( wndPtr );
148 USER_Driver->pSetWindowText( hwnd, text );
151 /***********************************************************************
152 * DEFWND_ControlColor
154 * Default colors for control painting.
156 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
158 if( ctlType == CTLCOLOR_SCROLLBAR)
160 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
161 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
162 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
163 SetBkColor( hDC, bk);
165 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
166 * we better use 0x55aa bitmap brush to make scrollbar's background
167 * look different from the window background.
169 if (bk == GetSysColor(COLOR_WINDOW))
170 return SYSCOLOR_55AABrush;
172 UnrealizeObject( hb );
173 return hb;
176 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
178 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
179 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
180 else {
181 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
182 return GetSysColorBrush(COLOR_3DFACE);
184 return GetSysColorBrush(COLOR_WINDOW);
188 /***********************************************************************
189 * DEFWND_Print
191 * This method handles the default behavior for the WM_PRINT message.
193 static void DEFWND_Print( HWND hwnd, HDC hdc, ULONG uFlags)
196 * Visibility flag.
198 if ( (uFlags & PRF_CHECKVISIBLE) &&
199 !IsWindowVisible(hwnd) )
200 return;
203 * Unimplemented flags.
205 if ( (uFlags & PRF_CHILDREN) ||
206 (uFlags & PRF_OWNED) ||
207 (uFlags & PRF_NONCLIENT) )
209 WARN("WM_PRINT message with unsupported flags\n");
213 * Background
215 if ( uFlags & PRF_ERASEBKGND)
216 SendMessageW(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
219 * Client area
221 if ( uFlags & PRF_CLIENT)
222 SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, uFlags);
227 * helpers for calling IMM32
229 * WM_IME_* messages are generated only by IMM32,
230 * so I assume imm32 is already LoadLibrary-ed.
232 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
234 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
235 HWND (WINAPI *pFunc)(HWND);
236 HWND hwndRet = 0;
238 if (!hInstIMM)
240 ERR( "cannot get IMM32 handle\n" );
241 return 0;
244 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
245 if ( pFunc != NULL )
246 hwndRet = (*pFunc)( hwnd );
248 return hwndRet;
251 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
253 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
254 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
255 BOOL fRet = FALSE;
257 if (!hInstIMM)
259 ERR( "cannot get IMM32 handle\n" );
260 return FALSE;
263 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
264 if ( pFunc != NULL )
265 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
267 return fRet;
270 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
272 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
273 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
274 BOOL fRet = FALSE;
276 if (!hInstIMM)
278 ERR( "cannot get IMM32 handle\n" );
279 return FALSE;
282 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
283 if ( pFunc != NULL )
284 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
286 return fRet;
291 /***********************************************************************
292 * DEFWND_DefWinProc
294 * Default window procedure for messages that are the same in Ansi and Unicode.
296 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
298 switch(msg)
300 case WM_NCPAINT:
301 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
303 case WM_NCHITTEST:
305 POINT pt;
306 pt.x = (short)LOWORD(lParam);
307 pt.y = (short)HIWORD(lParam);
308 return NC_HandleNCHitTest( hwnd, pt );
311 case WM_NCCALCSIZE:
312 return NC_HandleNCCalcSize( hwnd, wParam, (RECT *)lParam );
314 case WM_WINDOWPOSCHANGING:
315 return WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
317 case WM_WINDOWPOSCHANGED:
318 DEFWND_HandleWindowPosChanged( hwnd, (const WINDOWPOS *)lParam );
319 break;
321 case WM_LBUTTONDOWN:
322 case WM_RBUTTONDOWN:
323 case WM_MBUTTONDOWN:
324 iF10Key = iMenuSysKey = 0;
325 break;
327 case WM_NCLBUTTONDOWN:
328 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
330 case WM_LBUTTONDBLCLK:
331 return NC_HandleNCLButtonDblClk( hwnd, HTCLIENT, lParam );
333 case WM_NCLBUTTONDBLCLK:
334 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
336 case WM_NCRBUTTONDOWN:
337 return NC_HandleNCRButtonDown( hwnd, wParam, lParam );
339 case WM_RBUTTONUP:
341 POINT pt;
342 pt.x = (short)LOWORD(lParam);
343 pt.y = (short)HIWORD(lParam);
344 ClientToScreen(hwnd, &pt);
345 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
347 break;
349 case WM_NCRBUTTONUP:
351 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
352 * in Windows), but what _should_ we do? According to MSDN :
353 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
354 * message to the window". When is it appropriate?
356 break;
358 case WM_CONTEXTMENU:
359 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
360 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
361 else
363 LONG hitcode;
364 POINT pt;
365 WND *wndPtr = WIN_GetPtr( hwnd );
366 HMENU hMenu = wndPtr->hSysMenu;
367 WIN_ReleasePtr( wndPtr );
368 if (!hMenu) return 0;
369 pt.x = (short)LOWORD(lParam);
370 pt.y = (short)HIWORD(lParam);
371 hitcode = NC_HandleNCHitTest(hwnd, pt);
373 /* Track system popup if click was in the caption area. */
374 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
375 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
376 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
377 pt.x, pt.y, 0, hwnd, NULL);
379 break;
381 case WM_POPUPSYSTEMMENU:
383 /* This is an undocumented message used by the windows taskbar to
384 display the system menu of windows that belong to other processes. */
385 HMENU menu = GetSystemMenu(hwnd, FALSE);
387 if (menu)
388 TrackPopupMenu(menu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
389 LOWORD(lParam), HIWORD(lParam), 0, hwnd, NULL);
390 return 0;
393 case WM_NCACTIVATE:
394 return NC_HandleNCActivate( hwnd, wParam, lParam );
396 case WM_NCDESTROY:
398 WND *wndPtr = WIN_GetPtr( hwnd );
399 if (!wndPtr) return 0;
400 HeapFree( GetProcessHeap(), 0, wndPtr->text );
401 wndPtr->text = NULL;
402 HeapFree( GetProcessHeap(), 0, wndPtr->pScroll );
403 wndPtr->pScroll = NULL;
404 WIN_ReleasePtr( wndPtr );
405 return 0;
408 case WM_PRINT:
409 DEFWND_Print(hwnd, (HDC)wParam, lParam);
410 return 0;
412 case WM_PAINTICON:
413 case WM_PAINT:
415 PAINTSTRUCT ps;
416 HDC hdc = BeginPaint( hwnd, &ps );
417 if( hdc )
419 HICON hIcon;
420 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON))) )
422 RECT rc;
423 int x, y;
425 GetClientRect( hwnd, &rc );
426 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
427 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
428 TRACE("Painting class icon: vis rect=(%s)\n",
429 wine_dbgstr_rect(&ps.rcPaint));
430 DrawIcon( hdc, x, y, hIcon );
432 EndPaint( hwnd, &ps );
434 return 0;
437 case WM_SYNCPAINT:
438 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
439 return 0;
441 case WM_SETREDRAW:
442 if (wParam) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
443 else
445 RedrawWindow( hwnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
446 WIN_SetStyle( hwnd, 0, WS_VISIBLE );
448 return 0;
450 case WM_CLOSE:
451 DestroyWindow( hwnd );
452 return 0;
454 case WM_MOUSEACTIVATE:
455 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
457 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
458 if (ret) return ret;
461 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
462 return MA_ACTIVATE;
464 case WM_ACTIVATE:
465 /* The default action in Windows is to set the keyboard focus to
466 * the window, if it's being activated and not minimized */
467 if (LOWORD(wParam) != WA_INACTIVE) {
468 if (!IsIconic(hwnd)) SetFocus(hwnd);
470 break;
472 case WM_MOUSEWHEEL:
473 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
474 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
475 break;
477 case WM_ERASEBKGND:
478 case WM_ICONERASEBKGND:
480 RECT rect;
481 HDC hdc = (HDC)wParam;
482 HBRUSH hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
483 if (!hbr) return 0;
485 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
487 /* can't use GetClipBox with a parent DC or we fill the whole parent */
488 GetClientRect( hwnd, &rect );
489 DPtoLP( hdc, (LPPOINT)&rect, 2 );
491 else GetClipBox( hdc, &rect );
492 FillRect( hdc, &rect, hbr );
493 return 1;
496 case WM_GETDLGCODE:
497 return 0;
499 case WM_CTLCOLORMSGBOX:
500 case WM_CTLCOLOREDIT:
501 case WM_CTLCOLORLISTBOX:
502 case WM_CTLCOLORBTN:
503 case WM_CTLCOLORDLG:
504 case WM_CTLCOLORSTATIC:
505 case WM_CTLCOLORSCROLLBAR:
506 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
508 case WM_CTLCOLOR:
509 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
511 case WM_SETCURSOR:
512 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
514 /* with the exception of the border around a resizable wnd,
515 * give the parent first chance to set the cursor */
516 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
518 HWND parent = GetParent( hwnd );
519 if (parent != GetDesktopWindow() &&
520 SendMessageW( parent, WM_SETCURSOR, wParam, lParam )) return TRUE;
523 NC_HandleSetCursor( hwnd, wParam, lParam );
524 break;
526 case WM_SYSCOMMAND:
527 return NC_HandleSysCommand( hwnd, wParam, lParam );
529 case WM_KEYDOWN:
530 if(wParam == VK_F10) iF10Key = VK_F10;
531 break;
533 case WM_SYSKEYDOWN:
534 if( HIWORD(lParam) & KEYDATA_ALT )
536 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
537 if ( (wParam == VK_MENU || wParam == VK_LMENU
538 || wParam == VK_RMENU) && !iMenuSysKey )
539 iMenuSysKey = 1;
540 else
541 iMenuSysKey = 0;
543 iF10Key = 0;
545 if( wParam == VK_F4 ) /* try to close the window */
547 HWND top = GetAncestor( hwnd, GA_ROOT );
548 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
549 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
552 else if( wParam == VK_F10 )
554 if (GetKeyState(VK_SHIFT) & 0x8000)
555 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, -1 );
556 iF10Key = 1;
558 else if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
559 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
560 break;
562 case WM_KEYUP:
563 case WM_SYSKEYUP:
564 /* Press and release F10 or ALT */
565 if (((wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU)
566 && iMenuSysKey) || ((wParam == VK_F10) && iF10Key))
567 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
568 iMenuSysKey = iF10Key = 0;
569 break;
571 case WM_SYSCHAR:
573 iMenuSysKey = 0;
574 if (wParam == '\r' && IsIconic(hwnd))
576 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
577 break;
579 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
581 if (wParam == '\t' || wParam == '\x1b') break;
582 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
583 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
584 else
585 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
587 else /* check for Ctrl-Esc */
588 if (wParam != '\x1b') MessageBeep(0);
589 break;
592 case WM_SHOWWINDOW:
594 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
595 WND *pWnd;
596 if (!lParam) return 0; /* sent from ShowWindow */
597 if ((style & WS_VISIBLE) && wParam) return 0;
598 if (!(style & WS_VISIBLE) && !wParam) return 0;
599 if (!GetWindow( hwnd, GW_OWNER )) return 0;
600 if (!(pWnd = WIN_GetPtr( hwnd ))) return 0;
601 if (pWnd == WND_OTHER_PROCESS) return 0;
602 if (wParam)
604 if (!(pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP))
606 WIN_ReleasePtr( pWnd );
607 return 0;
609 pWnd->flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP;
611 else pWnd->flags |= WIN_NEEDS_SHOW_OWNEDPOPUP;
612 WIN_ReleasePtr( pWnd );
613 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
614 break;
617 case WM_CANCELMODE:
618 iMenuSysKey = 0;
619 MENU_EndMenu( hwnd );
620 if (GetCapture() == hwnd) ReleaseCapture();
621 break;
623 case WM_VKEYTOITEM:
624 case WM_CHARTOITEM:
625 return -1;
627 case WM_DROPOBJECT:
628 return DRAG_FILE;
630 case WM_QUERYDROPOBJECT:
631 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
633 case WM_QUERYDRAGICON:
635 UINT len;
637 HICON hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON );
638 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
639 if (hIcon) return (LRESULT)hIcon;
640 for(len=1; len<64; len++)
641 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
642 return (LRESULT)hIcon;
643 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
645 break;
647 case WM_ISACTIVEICON:
649 WND *wndPtr = WIN_GetPtr( hwnd );
650 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
651 WIN_ReleasePtr( wndPtr );
652 return ret;
655 case WM_NOTIFYFORMAT:
656 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
657 else return NFR_ANSI;
659 case WM_QUERYOPEN:
660 case WM_QUERYENDSESSION:
661 return 1;
663 case WM_SETICON:
665 HICON ret;
666 WND *wndPtr = WIN_GetPtr( hwnd );
668 switch(wParam)
670 case ICON_SMALL:
671 ret = wndPtr->hIconSmall;
672 wndPtr->hIconSmall = (HICON)lParam;
673 break;
674 case ICON_BIG:
675 ret = wndPtr->hIcon;
676 wndPtr->hIcon = (HICON)lParam;
677 break;
678 default:
679 ret = 0;
680 break;
682 WIN_ReleasePtr( wndPtr );
684 USER_Driver->pSetWindowIcon( hwnd, wParam, (HICON)lParam );
686 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
687 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
689 return (LRESULT)ret;
692 case WM_GETICON:
694 HICON ret;
695 WND *wndPtr = WIN_GetPtr( hwnd );
697 switch(wParam)
699 case ICON_SMALL:
700 ret = wndPtr->hIconSmall;
701 break;
702 case ICON_BIG:
703 ret = wndPtr->hIcon;
704 break;
705 case ICON_SMALL2:
706 ret = wndPtr->hIconSmall;
707 if (!ret) ret = (HICON)GetClassLongPtrW( hwnd, GCLP_HICONSM );
708 /* FIXME: should have a default here if class icon is null */
709 break;
710 default:
711 ret = 0;
712 break;
714 WIN_ReleasePtr( wndPtr );
715 return (LRESULT)ret;
718 case WM_HELP:
719 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
720 break;
722 case WM_APPCOMMAND:
724 HWND parent = GetParent(hwnd);
725 if(!parent)
726 HOOK_CallHooks(WH_SHELL, HSHELL_APPCOMMAND, wParam, lParam, TRUE);
727 else
728 SendMessageW( parent, msg, wParam, lParam );
729 break;
731 case WM_KEYF1:
733 HELPINFO hi;
735 hi.cbSize = sizeof(HELPINFO);
736 GetCursorPos( &hi.MousePos );
737 if (MENU_IsMenuActive())
739 hi.iContextType = HELPINFO_MENUITEM;
740 hi.hItemHandle = MENU_IsMenuActive();
741 hi.iCtrlId = MenuItemFromPoint( hwnd, hi.hItemHandle, hi.MousePos );
742 hi.dwContextId = GetMenuContextHelpId( hi.hItemHandle );
744 else
746 hi.iContextType = HELPINFO_WINDOW;
747 hi.hItemHandle = hwnd;
748 hi.iCtrlId = GetWindowLongPtrA( hwnd, GWLP_ID );
749 hi.dwContextId = GetWindowContextHelpId( hwnd );
751 SendMessageW( hwnd, WM_HELP, 0, (LPARAM)&hi );
752 break;
755 case WM_INPUTLANGCHANGEREQUEST:
756 ActivateKeyboardLayout( (HKL)lParam, 0 );
757 break;
759 case WM_INPUTLANGCHANGE:
761 int count = 0;
762 HWND *win_array = WIN_ListChildren( hwnd );
764 if (!win_array)
765 break;
766 while (win_array[count])
767 SendMessageW( win_array[count++], WM_INPUTLANGCHANGE, wParam, lParam);
768 HeapFree(GetProcessHeap(),0,win_array);
769 break;
774 return 0;
777 static LPARAM DEFWND_GetTextA( WND *wndPtr, LPSTR dest, WPARAM wParam )
779 LPARAM result = 0;
781 __TRY
783 if (wndPtr->text)
785 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
786 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
787 result = strlen( dest );
789 else dest[0] = '\0';
791 __EXCEPT_PAGE_FAULT
793 return 0;
795 __ENDTRY
796 return result;
799 /***********************************************************************
800 * DefWindowProcA (USER32.@)
802 * See DefWindowProcW.
804 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
806 LRESULT result = 0;
807 HWND full_handle;
809 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
811 if (!IsWindow( hwnd )) return 0;
812 ERR( "called for other process window %p\n", hwnd );
813 return 0;
815 hwnd = full_handle;
817 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
819 switch(msg)
821 case WM_NCCREATE:
822 if (lParam)
824 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
825 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
826 * may have child window IDs instead of window name */
827 if (!IS_INTRESOURCE(cs->lpszName))
828 DEFWND_SetTextA( hwnd, cs->lpszName );
829 result = 1;
831 break;
833 case WM_GETTEXTLENGTH:
835 WND *wndPtr = WIN_GetPtr( hwnd );
836 if (wndPtr && wndPtr->text)
837 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
838 NULL, 0, NULL, NULL );
839 WIN_ReleasePtr( wndPtr );
841 break;
843 case WM_GETTEXT:
844 if (wParam)
846 LPSTR dest = (LPSTR)lParam;
847 WND *wndPtr = WIN_GetPtr( hwnd );
849 if (!wndPtr) break;
850 result = DEFWND_GetTextA( wndPtr, dest, wParam );
852 WIN_ReleasePtr( wndPtr );
854 break;
856 case WM_SETTEXT:
857 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
858 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
859 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
860 result = 1; /* success. FIXME: check text length */
861 break;
863 case WM_IME_CHAR:
864 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
865 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
866 break;
868 case WM_IME_KEYDOWN:
869 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
870 break;
872 case WM_IME_KEYUP:
873 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
874 break;
876 case WM_IME_STARTCOMPOSITION:
877 case WM_IME_COMPOSITION:
878 case WM_IME_ENDCOMPOSITION:
879 case WM_IME_SELECT:
880 case WM_IME_NOTIFY:
882 HWND hwndIME;
884 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
885 if (hwndIME)
886 result = SendMessageA( hwndIME, msg, wParam, lParam );
888 break;
889 case WM_IME_SETCONTEXT:
891 HWND hwndIME;
893 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
894 if (hwndIME)
895 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
897 break;
899 case WM_SYSCHAR:
901 CHAR ch = LOWORD(wParam);
902 WCHAR wch;
903 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
904 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
906 /* fall through */
907 default:
908 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
909 break;
912 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
913 return result;
917 static LPARAM DEFWND_GetTextW( WND *wndPtr, LPWSTR dest, WPARAM wParam )
919 LPARAM result = 0;
921 __TRY
923 if (wndPtr->text)
925 lstrcpynW( dest, wndPtr->text, wParam );
926 result = strlenW( dest );
928 else dest[0] = '\0';
930 __EXCEPT_PAGE_FAULT
932 return 0;
934 __ENDTRY
936 return result;
939 /***********************************************************************
940 * DefWindowProcW (USER32.@) Calls default window message handler
942 * Calls default window procedure for messages not processed
943 * by application.
945 * RETURNS
946 * Return value is dependent upon the message.
948 LRESULT WINAPI DefWindowProcW(
949 HWND hwnd, /* [in] window procedure receiving message */
950 UINT msg, /* [in] message identifier */
951 WPARAM wParam, /* [in] first message parameter */
952 LPARAM lParam ) /* [in] second message parameter */
954 LRESULT result = 0;
955 HWND full_handle;
957 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
959 if (!IsWindow( hwnd )) return 0;
960 ERR( "called for other process window %p\n", hwnd );
961 return 0;
963 hwnd = full_handle;
964 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
966 switch(msg)
968 case WM_NCCREATE:
969 if (lParam)
971 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
972 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
973 * may have child window IDs instead of window name */
974 if (!IS_INTRESOURCE(cs->lpszName))
975 DEFWND_SetTextW( hwnd, cs->lpszName );
976 result = 1;
978 break;
980 case WM_GETTEXTLENGTH:
982 WND *wndPtr = WIN_GetPtr( hwnd );
983 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
984 WIN_ReleasePtr( wndPtr );
986 break;
988 case WM_GETTEXT:
989 if (wParam)
991 LPWSTR dest = (LPWSTR)lParam;
992 WND *wndPtr = WIN_GetPtr( hwnd );
994 if (!wndPtr) break;
995 result = DEFWND_GetTextW( wndPtr, dest, wParam );
996 WIN_ReleasePtr( wndPtr );
998 break;
1000 case WM_SETTEXT:
1001 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
1002 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
1003 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
1004 result = 1; /* success. FIXME: check text length */
1005 break;
1007 case WM_IME_CHAR:
1008 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
1009 break;
1011 case WM_IME_KEYDOWN:
1012 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
1013 break;
1015 case WM_IME_KEYUP:
1016 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
1017 break;
1019 case WM_IME_SETCONTEXT:
1021 HWND hwndIME;
1023 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1024 if (hwndIME)
1025 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
1027 break;
1029 case WM_IME_STARTCOMPOSITION:
1030 case WM_IME_COMPOSITION:
1031 case WM_IME_ENDCOMPOSITION:
1032 case WM_IME_SELECT:
1033 case WM_IME_NOTIFY:
1035 HWND hwndIME;
1037 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1038 if (hwndIME)
1039 result = SendMessageW( hwndIME, msg, wParam, lParam );
1041 break;
1043 default:
1044 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1045 break;
1047 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
1048 return result;