msdaps: Add a stub rowset proxy object.
[wine/hramrach.git] / dlls / user32 / defwnd.c
blob0101ee2bf123237b1bef58c4947afa7eeda0adea
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;
60 WND *wndPtr = WIN_GetPtr( hwnd );
62 rect = wndPtr->rectClient;
63 WIN_ReleasePtr( wndPtr );
65 if (!(winpos->flags & SWP_NOCLIENTMOVE))
66 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG(rect.left, rect.top));
68 if (!(winpos->flags & SWP_NOCLIENTSIZE) || (winpos->flags & SWP_STATECHANGED))
70 if (IsIconic( hwnd ))
72 SendMessageW( hwnd, WM_SIZE, SIZE_MINIMIZED, 0 );
74 else
76 WPARAM wp = IsZoomed( hwnd ) ? SIZE_MAXIMIZED : SIZE_RESTORED;
78 SendMessageW( hwnd, WM_SIZE, wp, MAKELONG(rect.right-rect.left, rect.bottom-rect.top) );
84 /***********************************************************************
85 * DEFWND_SetTextA
87 * Set the window text.
89 static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
91 int count;
92 WCHAR *textW;
93 WND *wndPtr;
95 if (!text) text = "";
96 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
98 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
99 if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
101 HeapFree(GetProcessHeap(), 0, wndPtr->text);
102 wndPtr->text = textW;
103 MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
104 SERVER_START_REQ( set_window_text )
106 req->handle = wine_server_user_handle( hwnd );
107 wine_server_add_data( req, textW, (count-1) * sizeof(WCHAR) );
108 wine_server_call( req );
110 SERVER_END_REQ;
112 else
113 ERR("Not enough memory for window text\n");
114 WIN_ReleasePtr( wndPtr );
116 USER_Driver->pSetWindowText( hwnd, textW );
119 /***********************************************************************
120 * DEFWND_SetTextW
122 * Set the window text.
124 static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
126 static const WCHAR empty_string[] = {0};
127 WND *wndPtr;
128 int count;
130 if (!text) text = empty_string;
131 count = strlenW(text) + 1;
133 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
134 HeapFree(GetProcessHeap(), 0, wndPtr->text);
135 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
137 strcpyW( wndPtr->text, text );
138 SERVER_START_REQ( set_window_text )
140 req->handle = wine_server_user_handle( hwnd );
141 wine_server_add_data( req, wndPtr->text, (count-1) * sizeof(WCHAR) );
142 wine_server_call( req );
144 SERVER_END_REQ;
146 else
147 ERR("Not enough memory for window text\n");
148 text = wndPtr->text;
149 WIN_ReleasePtr( wndPtr );
151 USER_Driver->pSetWindowText( hwnd, text );
154 /***********************************************************************
155 * DEFWND_ControlColor
157 * Default colors for control painting.
159 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
161 if( ctlType == CTLCOLOR_SCROLLBAR)
163 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
164 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
165 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
166 SetBkColor( hDC, bk);
168 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
169 * we better use 0x55aa bitmap brush to make scrollbar's background
170 * look different from the window background.
172 if (bk == GetSysColor(COLOR_WINDOW))
173 return SYSCOLOR_55AABrush;
175 UnrealizeObject( hb );
176 return hb;
179 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
181 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
182 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
183 else {
184 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
185 return GetSysColorBrush(COLOR_3DFACE);
187 return GetSysColorBrush(COLOR_WINDOW);
191 /***********************************************************************
192 * DEFWND_Print
194 * This method handles the default behavior for the WM_PRINT message.
196 static void DEFWND_Print( HWND hwnd, HDC hdc, ULONG uFlags)
199 * Visibility flag.
201 if ( (uFlags & PRF_CHECKVISIBLE) &&
202 !IsWindowVisible(hwnd) )
203 return;
206 * Unimplemented flags.
208 if ( (uFlags & PRF_CHILDREN) ||
209 (uFlags & PRF_OWNED) ||
210 (uFlags & PRF_NONCLIENT) )
212 WARN("WM_PRINT message with unsupported flags\n");
216 * Background
218 if ( uFlags & PRF_ERASEBKGND)
219 SendMessageW(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
222 * Client area
224 if ( uFlags & PRF_CLIENT)
225 SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, uFlags);
230 * helpers for calling IMM32
232 * WM_IME_* messages are generated only by IMM32,
233 * so I assume imm32 is already LoadLibrary-ed.
235 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
237 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
238 HWND (WINAPI *pFunc)(HWND);
239 HWND hwndRet = 0;
241 if (!hInstIMM)
243 ERR( "cannot get IMM32 handle\n" );
244 return 0;
247 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
248 if ( pFunc != NULL )
249 hwndRet = (*pFunc)( hwnd );
251 return hwndRet;
254 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
256 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
257 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
258 BOOL fRet = FALSE;
260 if (!hInstIMM)
262 ERR( "cannot get IMM32 handle\n" );
263 return FALSE;
266 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
267 if ( pFunc != NULL )
268 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
270 return fRet;
273 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
275 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
276 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
277 BOOL fRet = FALSE;
279 if (!hInstIMM)
281 ERR( "cannot get IMM32 handle\n" );
282 return FALSE;
285 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
286 if ( pFunc != NULL )
287 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
289 return fRet;
294 /***********************************************************************
295 * DEFWND_DefWinProc
297 * Default window procedure for messages that are the same in Ansi and Unicode.
299 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
301 switch(msg)
303 case WM_NCPAINT:
304 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
306 case WM_NCHITTEST:
308 POINT pt;
309 pt.x = (short)LOWORD(lParam);
310 pt.y = (short)HIWORD(lParam);
311 return NC_HandleNCHitTest( hwnd, pt );
314 case WM_NCCALCSIZE:
315 return NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
317 case WM_WINDOWPOSCHANGING:
318 return WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
320 case WM_WINDOWPOSCHANGED:
321 DEFWND_HandleWindowPosChanged( hwnd, (const WINDOWPOS *)lParam );
322 break;
324 case WM_LBUTTONDOWN:
325 case WM_RBUTTONDOWN:
326 case WM_MBUTTONDOWN:
327 iF10Key = iMenuSysKey = 0;
328 break;
330 case WM_NCLBUTTONDOWN:
331 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
333 case WM_LBUTTONDBLCLK:
334 return NC_HandleNCLButtonDblClk( hwnd, HTCLIENT, lParam );
336 case WM_NCLBUTTONDBLCLK:
337 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
339 case WM_NCRBUTTONDOWN:
340 /* in Windows, capture is taken when right-clicking on the caption bar */
341 if (wParam==HTCAPTION)
343 SetCapture(hwnd);
345 break;
347 case WM_RBUTTONUP:
349 POINT pt;
351 if (hwnd == GetCapture())
352 /* release capture if we took it on WM_NCRBUTTONDOWN */
353 ReleaseCapture();
355 pt.x = (short)LOWORD(lParam);
356 pt.y = (short)HIWORD(lParam);
357 ClientToScreen(hwnd, &pt);
358 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
360 break;
362 case WM_NCRBUTTONUP:
364 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
365 * in Windows), but what _should_ we do? According to MSDN :
366 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
367 * message to the window". When is it appropriate?
369 break;
371 case WM_CONTEXTMENU:
372 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
373 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
374 else
376 LONG hitcode;
377 POINT pt;
378 WND *wndPtr = WIN_GetPtr( hwnd );
379 HMENU hMenu = wndPtr->hSysMenu;
380 WIN_ReleasePtr( wndPtr );
381 if (!hMenu) return 0;
382 pt.x = (short)LOWORD(lParam);
383 pt.y = (short)HIWORD(lParam);
384 hitcode = NC_HandleNCHitTest(hwnd, pt);
386 /* Track system popup if click was in the caption area. */
387 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
388 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
389 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
390 pt.x, pt.y, 0, hwnd, NULL);
392 break;
394 case WM_POPUPSYSTEMMENU:
396 /* This is an undocumented message used by the windows taskbar to
397 display the system menu of windows that belong to other processes. */
398 HMENU menu = GetSystemMenu(hwnd, FALSE);
400 if (menu)
401 TrackPopupMenu(menu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
402 LOWORD(lParam), HIWORD(lParam), 0, hwnd, NULL);
403 return 0;
406 case WM_NCACTIVATE:
407 return NC_HandleNCActivate( hwnd, wParam, lParam );
409 case WM_NCDESTROY:
411 WND *wndPtr = WIN_GetPtr( hwnd );
412 if (!wndPtr) return 0;
413 HeapFree( GetProcessHeap(), 0, wndPtr->text );
414 wndPtr->text = NULL;
415 HeapFree( GetProcessHeap(), 0, wndPtr->pScroll );
416 wndPtr->pScroll = NULL;
417 WIN_ReleasePtr( wndPtr );
418 return 0;
421 case WM_PRINT:
422 DEFWND_Print(hwnd, (HDC)wParam, lParam);
423 return 0;
425 case WM_PAINTICON:
426 case WM_PAINT:
428 PAINTSTRUCT ps;
429 HDC hdc = BeginPaint( hwnd, &ps );
430 if( hdc )
432 HICON hIcon;
433 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON))) )
435 RECT rc;
436 int x, y;
438 GetClientRect( hwnd, &rc );
439 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
440 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
441 TRACE("Painting class icon: vis rect=(%s)\n",
442 wine_dbgstr_rect(&ps.rcPaint));
443 DrawIcon( hdc, x, y, hIcon );
445 EndPaint( hwnd, &ps );
447 return 0;
450 case WM_SYNCPAINT:
451 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
452 return 0;
454 case WM_SETREDRAW:
455 if (wParam) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
456 else
458 RedrawWindow( hwnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
459 WIN_SetStyle( hwnd, 0, WS_VISIBLE );
461 return 0;
463 case WM_CLOSE:
464 DestroyWindow( hwnd );
465 return 0;
467 case WM_MOUSEACTIVATE:
468 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
470 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
471 if (ret) return ret;
474 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
475 return MA_ACTIVATE;
477 case WM_ACTIVATE:
478 /* The default action in Windows is to set the keyboard focus to
479 * the window, if it's being activated and not minimized */
480 if (LOWORD(wParam) != WA_INACTIVE) {
481 if (!IsIconic(hwnd)) SetFocus(hwnd);
483 break;
485 case WM_MOUSEWHEEL:
486 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
487 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
488 break;
490 case WM_ERASEBKGND:
491 case WM_ICONERASEBKGND:
493 RECT rect;
494 HDC hdc = (HDC)wParam;
495 HBRUSH hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
496 if (!hbr) return 0;
498 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
500 /* can't use GetClipBox with a parent DC or we fill the whole parent */
501 GetClientRect( hwnd, &rect );
502 DPtoLP( hdc, (LPPOINT)&rect, 2 );
504 else GetClipBox( hdc, &rect );
505 FillRect( hdc, &rect, hbr );
506 return 1;
509 case WM_GETDLGCODE:
510 return 0;
512 case WM_CTLCOLORMSGBOX:
513 case WM_CTLCOLOREDIT:
514 case WM_CTLCOLORLISTBOX:
515 case WM_CTLCOLORBTN:
516 case WM_CTLCOLORDLG:
517 case WM_CTLCOLORSTATIC:
518 case WM_CTLCOLORSCROLLBAR:
519 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
521 case WM_CTLCOLOR:
522 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
524 case WM_SETCURSOR:
525 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
527 /* with the exception of the border around a resizable wnd,
528 * give the parent first chance to set the cursor */
529 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
531 if (SendMessageW(GetParent(hwnd), WM_SETCURSOR, wParam, lParam)) return TRUE;
534 NC_HandleSetCursor( hwnd, wParam, lParam );
535 break;
537 case WM_SYSCOMMAND:
538 return NC_HandleSysCommand( hwnd, wParam, lParam );
540 case WM_KEYDOWN:
541 if(wParam == VK_F10) iF10Key = VK_F10;
542 break;
544 case WM_SYSKEYDOWN:
545 if( HIWORD(lParam) & KEYDATA_ALT )
547 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
548 if ( (wParam == VK_MENU || wParam == VK_LMENU
549 || wParam == VK_RMENU) && !iMenuSysKey )
550 iMenuSysKey = 1;
551 else
552 iMenuSysKey = 0;
554 iF10Key = 0;
556 if( wParam == VK_F4 ) /* try to close the window */
558 HWND top = GetAncestor( hwnd, GA_ROOT );
559 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
560 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
563 else if( wParam == VK_F10 )
565 if (GetKeyState(VK_SHIFT) & 0x8000)
566 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, -1 );
567 iF10Key = 1;
569 else if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
570 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
571 break;
573 case WM_KEYUP:
574 case WM_SYSKEYUP:
575 /* Press and release F10 or ALT */
576 if (((wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU)
577 && iMenuSysKey) || ((wParam == VK_F10) && iF10Key))
578 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
579 iMenuSysKey = iF10Key = 0;
580 break;
582 case WM_SYSCHAR:
584 iMenuSysKey = 0;
585 if (wParam == '\r' && IsIconic(hwnd))
587 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
588 break;
590 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
592 if (wParam == '\t' || wParam == '\x1b') break;
593 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
594 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
595 else
596 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
598 else /* check for Ctrl-Esc */
599 if (wParam != '\x1b') MessageBeep(0);
600 break;
603 case WM_SHOWWINDOW:
605 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
606 WND *pWnd;
607 if (!lParam) return 0; /* sent from ShowWindow */
608 if ((style & WS_VISIBLE) && wParam) return 0;
609 if (!(style & WS_VISIBLE) && !wParam) return 0;
610 if (!GetWindow( hwnd, GW_OWNER )) return 0;
611 if (!(pWnd = WIN_GetPtr( hwnd ))) return 0;
612 if (pWnd == WND_OTHER_PROCESS) return 0;
613 if (wParam)
615 if (!(pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP))
617 WIN_ReleasePtr( pWnd );
618 return 0;
620 pWnd->flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP;
622 else pWnd->flags |= WIN_NEEDS_SHOW_OWNEDPOPUP;
623 WIN_ReleasePtr( pWnd );
624 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
625 break;
628 case WM_CANCELMODE:
629 iMenuSysKey = 0;
630 MENU_EndMenu( hwnd );
631 if (GetCapture() == hwnd) ReleaseCapture();
632 break;
634 case WM_VKEYTOITEM:
635 case WM_CHARTOITEM:
636 return -1;
638 case WM_DROPOBJECT:
639 return DRAG_FILE;
641 case WM_QUERYDROPOBJECT:
642 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
644 case WM_QUERYDRAGICON:
646 UINT len;
648 HICON hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON );
649 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
650 if (hIcon) return (LRESULT)hIcon;
651 for(len=1; len<64; len++)
652 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
653 return (LRESULT)hIcon;
654 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
656 break;
658 case WM_ISACTIVEICON:
660 WND *wndPtr = WIN_GetPtr( hwnd );
661 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
662 WIN_ReleasePtr( wndPtr );
663 return ret;
666 case WM_NOTIFYFORMAT:
667 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
668 else return NFR_ANSI;
670 case WM_QUERYOPEN:
671 case WM_QUERYENDSESSION:
672 return 1;
674 case WM_SETICON:
676 HICON ret;
677 WND *wndPtr = WIN_GetPtr( hwnd );
679 switch(wParam)
681 case ICON_SMALL:
682 ret = wndPtr->hIconSmall;
683 wndPtr->hIconSmall = (HICON)lParam;
684 break;
685 case ICON_BIG:
686 ret = wndPtr->hIcon;
687 wndPtr->hIcon = (HICON)lParam;
688 break;
689 default:
690 ret = 0;
691 break;
693 WIN_ReleasePtr( wndPtr );
695 USER_Driver->pSetWindowIcon( hwnd, wParam, (HICON)lParam );
697 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
698 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
700 return (LRESULT)ret;
703 case WM_GETICON:
705 HICON ret;
706 WND *wndPtr = WIN_GetPtr( hwnd );
708 switch(wParam)
710 case ICON_SMALL:
711 ret = wndPtr->hIconSmall;
712 break;
713 case ICON_BIG:
714 ret = wndPtr->hIcon;
715 break;
716 case ICON_SMALL2:
717 ret = wndPtr->hIconSmall;
718 if (!ret) ret = (HICON)GetClassLongPtrW( hwnd, GCLP_HICONSM );
719 /* FIXME: should have a default here if class icon is null */
720 break;
721 default:
722 ret = 0;
723 break;
725 WIN_ReleasePtr( wndPtr );
726 return (LRESULT)ret;
729 case WM_HELP:
730 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
731 break;
733 case WM_APPCOMMAND:
735 HWND parent = GetParent(hwnd);
736 if(!parent)
737 HOOK_CallHooks(WH_SHELL, HSHELL_APPCOMMAND, wParam, lParam, TRUE);
738 else
739 SendMessageW( parent, msg, wParam, lParam );
740 break;
742 case WM_KEYF1:
744 HELPINFO hi;
746 hi.cbSize = sizeof(HELPINFO);
747 GetCursorPos( &hi.MousePos );
748 if (MENU_IsMenuActive())
750 hi.iContextType = HELPINFO_MENUITEM;
751 hi.hItemHandle = MENU_IsMenuActive();
752 hi.iCtrlId = MenuItemFromPoint( hwnd, hi.hItemHandle, hi.MousePos );
753 hi.dwContextId = GetMenuContextHelpId( hi.hItemHandle );
755 else
757 hi.iContextType = HELPINFO_WINDOW;
758 hi.hItemHandle = hwnd;
759 hi.iCtrlId = GetWindowLongPtrA( hwnd, GWLP_ID );
760 hi.dwContextId = GetWindowContextHelpId( hwnd );
762 SendMessageW( hwnd, WM_HELP, 0, (LPARAM)&hi );
763 break;
766 case WM_INPUTLANGCHANGEREQUEST:
767 ActivateKeyboardLayout( (HKL)lParam, 0 );
768 break;
770 case WM_INPUTLANGCHANGE:
772 int count = 0;
773 HWND *win_array = WIN_ListChildren( hwnd );
775 if (!win_array)
776 break;
777 while (win_array[count])
778 SendMessageW( win_array[count++], WM_INPUTLANGCHANGE, wParam, lParam);
779 HeapFree(GetProcessHeap(),0,win_array);
780 break;
785 return 0;
788 static LPARAM DEFWND_GetTextA( WND *wndPtr, LPSTR dest, WPARAM wParam )
790 LPARAM result = 0;
792 __TRY
794 if (wndPtr->text)
796 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
797 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
798 result = strlen( dest );
800 else dest[0] = '\0';
802 __EXCEPT_PAGE_FAULT
804 return 0;
806 __ENDTRY
807 return result;
810 /***********************************************************************
811 * DefWindowProcA (USER32.@)
813 * See DefWindowProcW.
815 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
817 LRESULT result = 0;
818 HWND full_handle;
820 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
822 if (!IsWindow( hwnd )) return 0;
823 ERR( "called for other process window %p\n", hwnd );
824 return 0;
826 hwnd = full_handle;
828 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
830 switch(msg)
832 case WM_NCCREATE:
833 if (lParam)
835 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
836 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
837 * may have child window IDs instead of window name */
838 if (HIWORD(cs->lpszName))
839 DEFWND_SetTextA( hwnd, cs->lpszName );
840 result = 1;
842 break;
844 case WM_GETTEXTLENGTH:
846 WND *wndPtr = WIN_GetPtr( hwnd );
847 if (wndPtr && wndPtr->text)
848 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
849 NULL, 0, NULL, NULL );
850 WIN_ReleasePtr( wndPtr );
852 break;
854 case WM_GETTEXT:
855 if (wParam)
857 LPSTR dest = (LPSTR)lParam;
858 WND *wndPtr = WIN_GetPtr( hwnd );
860 if (!wndPtr) break;
861 result = DEFWND_GetTextA( wndPtr, dest, wParam );
863 WIN_ReleasePtr( wndPtr );
865 break;
867 case WM_SETTEXT:
868 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
869 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
870 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
871 result = 1; /* success. FIXME: check text length */
872 break;
874 case WM_IME_CHAR:
875 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
876 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
877 break;
879 case WM_IME_KEYDOWN:
880 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
881 break;
883 case WM_IME_KEYUP:
884 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
885 break;
887 case WM_IME_STARTCOMPOSITION:
888 case WM_IME_COMPOSITION:
889 case WM_IME_ENDCOMPOSITION:
890 case WM_IME_SELECT:
891 case WM_IME_NOTIFY:
893 HWND hwndIME;
895 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
896 if (hwndIME)
897 result = SendMessageA( hwndIME, msg, wParam, lParam );
899 break;
900 case WM_IME_SETCONTEXT:
902 HWND hwndIME;
904 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
905 if (hwndIME)
906 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
908 break;
910 case WM_SYSCHAR:
912 CHAR ch = LOWORD(wParam);
913 WCHAR wch;
914 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
915 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
917 /* fall through */
918 default:
919 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
920 break;
923 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
924 return result;
928 static LPARAM DEFWND_GetTextW( WND *wndPtr, LPWSTR dest, WPARAM wParam )
930 LPARAM result = 0;
932 __TRY
934 if (wndPtr->text)
936 lstrcpynW( dest, wndPtr->text, wParam );
937 result = strlenW( dest );
939 else dest[0] = '\0';
941 __EXCEPT_PAGE_FAULT
943 return 0;
945 __ENDTRY
947 return result;
950 /***********************************************************************
951 * DefWindowProcW (USER32.@) Calls default window message handler
953 * Calls default window procedure for messages not processed
954 * by application.
956 * RETURNS
957 * Return value is dependent upon the message.
959 LRESULT WINAPI DefWindowProcW(
960 HWND hwnd, /* [in] window procedure receiving message */
961 UINT msg, /* [in] message identifier */
962 WPARAM wParam, /* [in] first message parameter */
963 LPARAM lParam ) /* [in] second message parameter */
965 LRESULT result = 0;
966 HWND full_handle;
968 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
970 if (!IsWindow( hwnd )) return 0;
971 ERR( "called for other process window %p\n", hwnd );
972 return 0;
974 hwnd = full_handle;
975 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
977 switch(msg)
979 case WM_NCCREATE:
980 if (lParam)
982 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
983 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
984 * may have child window IDs instead of window name */
985 if (HIWORD(cs->lpszName))
986 DEFWND_SetTextW( hwnd, cs->lpszName );
987 result = 1;
989 break;
991 case WM_GETTEXTLENGTH:
993 WND *wndPtr = WIN_GetPtr( hwnd );
994 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
995 WIN_ReleasePtr( wndPtr );
997 break;
999 case WM_GETTEXT:
1000 if (wParam)
1002 LPWSTR dest = (LPWSTR)lParam;
1003 WND *wndPtr = WIN_GetPtr( hwnd );
1005 if (!wndPtr) break;
1006 result = DEFWND_GetTextW( wndPtr, dest, wParam );
1007 WIN_ReleasePtr( wndPtr );
1009 break;
1011 case WM_SETTEXT:
1012 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
1013 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
1014 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
1015 result = 1; /* success. FIXME: check text length */
1016 break;
1018 case WM_IME_CHAR:
1019 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
1020 break;
1022 case WM_IME_KEYDOWN:
1023 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
1024 break;
1026 case WM_IME_KEYUP:
1027 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
1028 break;
1030 case WM_IME_SETCONTEXT:
1032 HWND hwndIME;
1034 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1035 if (hwndIME)
1036 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
1038 break;
1040 case WM_IME_STARTCOMPOSITION:
1041 case WM_IME_COMPOSITION:
1042 case WM_IME_ENDCOMPOSITION:
1043 case WM_IME_SELECT:
1044 case WM_IME_NOTIFY:
1046 HWND hwndIME;
1048 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1049 if (hwndIME)
1050 result = SendMessageW( hwndIME, msg, wParam, lParam );
1052 break;
1054 default:
1055 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1056 break;
1058 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
1059 return result;