dpnet/tests: Add a trailing '\n' to some ok() calls.
[wine.git] / dlls / user32 / defwnd.c
blobbcd6f91e5d8ef53d12529d50e68b2f3c9f9b655e
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 "imm.h"
33 #include "win.h"
34 #include "user_private.h"
35 #include "controls.h"
36 #include "wine/unicode.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 #define DRAG_FILE 0x454C4946
49 static short iF10Key = 0;
50 static short iMenuSysKey = 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_Get55AABrush();
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 /***********************************************************************
228 * DEFWND_DefWinProc
230 * Default window procedure for messages that are the same in Ansi and Unicode.
232 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
234 switch(msg)
236 case WM_NCPAINT:
237 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
239 case WM_NCHITTEST:
241 POINT pt;
242 pt.x = (short)LOWORD(lParam);
243 pt.y = (short)HIWORD(lParam);
244 return NC_HandleNCHitTest( hwnd, pt );
247 case WM_NCCALCSIZE:
248 return NC_HandleNCCalcSize( hwnd, wParam, (RECT *)lParam );
250 case WM_WINDOWPOSCHANGING:
251 return WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
253 case WM_WINDOWPOSCHANGED:
254 DEFWND_HandleWindowPosChanged( hwnd, (const WINDOWPOS *)lParam );
255 break;
257 case WM_LBUTTONDOWN:
258 case WM_RBUTTONDOWN:
259 case WM_MBUTTONDOWN:
260 iF10Key = iMenuSysKey = 0;
261 break;
263 case WM_NCLBUTTONDOWN:
264 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
266 case WM_LBUTTONDBLCLK:
267 return NC_HandleNCLButtonDblClk( hwnd, HTCLIENT, lParam );
269 case WM_NCLBUTTONDBLCLK:
270 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
272 case WM_NCRBUTTONDOWN:
273 return NC_HandleNCRButtonDown( hwnd, wParam, lParam );
275 case WM_RBUTTONUP:
277 POINT pt;
278 pt.x = (short)LOWORD(lParam);
279 pt.y = (short)HIWORD(lParam);
280 ClientToScreen(hwnd, &pt);
281 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
283 break;
285 case WM_NCRBUTTONUP:
287 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
288 * in Windows), but what _should_ we do? According to MSDN :
289 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
290 * message to the window". When is it appropriate?
292 break;
294 case WM_CONTEXTMENU:
295 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
296 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
297 else
299 LONG hitcode;
300 POINT pt;
301 WND *wndPtr = WIN_GetPtr( hwnd );
302 HMENU hMenu = wndPtr->hSysMenu;
303 WIN_ReleasePtr( wndPtr );
304 if (!hMenu) return 0;
305 pt.x = (short)LOWORD(lParam);
306 pt.y = (short)HIWORD(lParam);
307 hitcode = NC_HandleNCHitTest(hwnd, pt);
309 /* Track system popup if click was in the caption area. */
310 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
311 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
312 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
313 pt.x, pt.y, 0, hwnd, NULL);
315 break;
317 case WM_POPUPSYSTEMMENU:
319 /* This is an undocumented message used by the windows taskbar to
320 display the system menu of windows that belong to other processes. */
321 HMENU menu = GetSystemMenu(hwnd, FALSE);
323 if (menu)
324 TrackPopupMenu(menu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
325 LOWORD(lParam), HIWORD(lParam), 0, hwnd, NULL);
326 return 0;
329 case WM_NCACTIVATE:
330 return NC_HandleNCActivate( hwnd, wParam, lParam );
332 case WM_NCDESTROY:
334 WND *wndPtr = WIN_GetPtr( hwnd );
335 if (!wndPtr) return 0;
336 HeapFree( GetProcessHeap(), 0, wndPtr->text );
337 wndPtr->text = NULL;
338 HeapFree( GetProcessHeap(), 0, wndPtr->pScroll );
339 wndPtr->pScroll = NULL;
340 WIN_ReleasePtr( wndPtr );
341 return 0;
344 case WM_PRINT:
345 DEFWND_Print(hwnd, (HDC)wParam, lParam);
346 return 0;
348 case WM_PAINTICON:
349 case WM_PAINT:
351 PAINTSTRUCT ps;
352 HDC hdc = BeginPaint( hwnd, &ps );
353 if( hdc )
355 HICON hIcon;
356 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON))) )
358 RECT rc;
359 int x, y;
361 GetClientRect( hwnd, &rc );
362 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
363 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
364 TRACE("Painting class icon: vis rect=(%s)\n",
365 wine_dbgstr_rect(&ps.rcPaint));
366 DrawIcon( hdc, x, y, hIcon );
368 EndPaint( hwnd, &ps );
370 return 0;
373 case WM_SYNCPAINT:
374 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
375 return 0;
377 case WM_SETREDRAW:
378 if (wParam) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
379 else
381 RedrawWindow( hwnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
382 WIN_SetStyle( hwnd, 0, WS_VISIBLE );
384 return 0;
386 case WM_CLOSE:
387 DestroyWindow( hwnd );
388 return 0;
390 case WM_MOUSEACTIVATE:
391 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
393 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
394 if (ret) return ret;
397 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
398 return MA_ACTIVATE;
400 case WM_ACTIVATE:
401 /* The default action in Windows is to set the keyboard focus to
402 * the window, if it's being activated and not minimized */
403 if (LOWORD(wParam) != WA_INACTIVE) {
404 if (!IsIconic(hwnd)) SetFocus(hwnd);
406 break;
408 case WM_MOUSEWHEEL:
409 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
410 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
411 break;
413 case WM_ERASEBKGND:
414 case WM_ICONERASEBKGND:
416 RECT rect;
417 HDC hdc = (HDC)wParam;
418 HBRUSH hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
419 if (!hbr) return 0;
421 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
423 /* can't use GetClipBox with a parent DC or we fill the whole parent */
424 GetClientRect( hwnd, &rect );
425 DPtoLP( hdc, (LPPOINT)&rect, 2 );
427 else GetClipBox( hdc, &rect );
428 FillRect( hdc, &rect, hbr );
429 return 1;
432 case WM_GETDLGCODE:
433 return 0;
435 case WM_CTLCOLORMSGBOX:
436 case WM_CTLCOLOREDIT:
437 case WM_CTLCOLORLISTBOX:
438 case WM_CTLCOLORBTN:
439 case WM_CTLCOLORDLG:
440 case WM_CTLCOLORSTATIC:
441 case WM_CTLCOLORSCROLLBAR:
442 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
444 case WM_CTLCOLOR:
445 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
447 case WM_SETCURSOR:
448 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
450 /* with the exception of the border around a resizable wnd,
451 * give the parent first chance to set the cursor */
452 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
454 HWND parent = GetParent( hwnd );
455 if (parent != GetDesktopWindow() &&
456 SendMessageW( parent, WM_SETCURSOR, wParam, lParam )) return TRUE;
459 NC_HandleSetCursor( hwnd, wParam, lParam );
460 break;
462 case WM_SYSCOMMAND:
463 return NC_HandleSysCommand( hwnd, wParam, lParam );
465 case WM_KEYDOWN:
466 if(wParam == VK_F10) iF10Key = VK_F10;
467 break;
469 case WM_SYSKEYDOWN:
470 if( HIWORD(lParam) & KEYDATA_ALT )
472 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
473 if ( (wParam == VK_MENU || wParam == VK_LMENU
474 || wParam == VK_RMENU) && !iMenuSysKey )
475 iMenuSysKey = 1;
476 else
477 iMenuSysKey = 0;
479 iF10Key = 0;
481 if( wParam == VK_F4 ) /* try to close the window */
483 HWND top = GetAncestor( hwnd, GA_ROOT );
484 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
485 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
488 else if( wParam == VK_F10 )
490 if (GetKeyState(VK_SHIFT) & 0x8000)
491 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, -1 );
492 iF10Key = 1;
494 else if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
495 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
496 break;
498 case WM_KEYUP:
499 case WM_SYSKEYUP:
500 /* Press and release F10 or ALT */
501 if (((wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU)
502 && iMenuSysKey) || ((wParam == VK_F10) && iF10Key))
503 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
504 iMenuSysKey = iF10Key = 0;
505 break;
507 case WM_SYSCHAR:
509 iMenuSysKey = 0;
510 if (wParam == '\r' && IsIconic(hwnd))
512 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
513 break;
515 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
517 if (wParam == '\t' || wParam == '\x1b') break;
518 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
519 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
520 else
521 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
523 else /* check for Ctrl-Esc */
524 if (wParam != '\x1b') MessageBeep(0);
525 break;
528 case WM_SHOWWINDOW:
530 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
531 WND *pWnd;
532 if (!lParam) return 0; /* sent from ShowWindow */
533 if ((style & WS_VISIBLE) && wParam) return 0;
534 if (!(style & WS_VISIBLE) && !wParam) return 0;
535 if (!GetWindow( hwnd, GW_OWNER )) return 0;
536 if (!(pWnd = WIN_GetPtr( hwnd ))) return 0;
537 if (pWnd == WND_OTHER_PROCESS) return 0;
538 if (wParam)
540 if (!(pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP))
542 WIN_ReleasePtr( pWnd );
543 return 0;
545 pWnd->flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP;
547 else pWnd->flags |= WIN_NEEDS_SHOW_OWNEDPOPUP;
548 WIN_ReleasePtr( pWnd );
549 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
550 break;
553 case WM_CANCELMODE:
554 iMenuSysKey = 0;
555 MENU_EndMenu( hwnd );
556 if (GetCapture() == hwnd) ReleaseCapture();
557 break;
559 case WM_VKEYTOITEM:
560 case WM_CHARTOITEM:
561 return -1;
563 case WM_DROPOBJECT:
564 return DRAG_FILE;
566 case WM_QUERYDROPOBJECT:
567 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
569 case WM_QUERYDRAGICON:
571 UINT len;
573 HICON hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON );
574 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
575 if (hIcon) return (LRESULT)hIcon;
576 for(len=1; len<64; len++)
577 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
578 return (LRESULT)hIcon;
579 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
581 break;
583 case WM_ISACTIVEICON:
585 WND *wndPtr = WIN_GetPtr( hwnd );
586 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
587 WIN_ReleasePtr( wndPtr );
588 return ret;
591 case WM_NOTIFYFORMAT:
592 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
593 else return NFR_ANSI;
595 case WM_QUERYOPEN:
596 case WM_QUERYENDSESSION:
597 return 1;
599 case WM_SETICON:
601 HICON ret;
602 WND *wndPtr = WIN_GetPtr( hwnd );
604 switch(wParam)
606 case ICON_SMALL:
607 ret = wndPtr->hIconSmall;
608 wndPtr->hIconSmall = (HICON)lParam;
609 break;
610 case ICON_BIG:
611 ret = wndPtr->hIcon;
612 wndPtr->hIcon = (HICON)lParam;
613 break;
614 default:
615 ret = 0;
616 break;
618 WIN_ReleasePtr( wndPtr );
620 USER_Driver->pSetWindowIcon( hwnd, wParam, (HICON)lParam );
622 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
623 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
625 return (LRESULT)ret;
628 case WM_GETICON:
630 HICON ret;
631 WND *wndPtr = WIN_GetPtr( hwnd );
633 switch(wParam)
635 case ICON_SMALL:
636 ret = wndPtr->hIconSmall;
637 break;
638 case ICON_BIG:
639 ret = wndPtr->hIcon;
640 break;
641 case ICON_SMALL2:
642 ret = wndPtr->hIconSmall;
643 if (!ret) ret = (HICON)GetClassLongPtrW( hwnd, GCLP_HICONSM );
644 /* FIXME: should have a default here if class icon is null */
645 break;
646 default:
647 ret = 0;
648 break;
650 WIN_ReleasePtr( wndPtr );
651 return (LRESULT)ret;
654 case WM_HELP:
655 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
656 break;
658 case WM_STYLECHANGED:
659 if (wParam == GWL_STYLE && (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED))
661 STYLESTRUCT *style = (STYLESTRUCT *)lParam;
662 if ((style->styleOld ^ style->styleNew) & (WS_CAPTION|WS_THICKFRAME|WS_VSCROLL|WS_HSCROLL))
663 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOZORDER |
664 SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE );
666 break;
668 case WM_APPCOMMAND:
670 HWND parent = GetParent(hwnd);
671 if(!parent)
672 HOOK_CallHooks(WH_SHELL, HSHELL_APPCOMMAND, wParam, lParam, TRUE);
673 else
674 SendMessageW( parent, msg, wParam, lParam );
675 break;
677 case WM_KEYF1:
679 HELPINFO hi;
681 hi.cbSize = sizeof(HELPINFO);
682 GetCursorPos( &hi.MousePos );
683 if (MENU_IsMenuActive())
685 hi.iContextType = HELPINFO_MENUITEM;
686 hi.hItemHandle = MENU_IsMenuActive();
687 hi.iCtrlId = MenuItemFromPoint( hwnd, hi.hItemHandle, hi.MousePos );
688 hi.dwContextId = GetMenuContextHelpId( hi.hItemHandle );
690 else
692 hi.iContextType = HELPINFO_WINDOW;
693 hi.hItemHandle = hwnd;
694 hi.iCtrlId = GetWindowLongPtrA( hwnd, GWLP_ID );
695 hi.dwContextId = GetWindowContextHelpId( hwnd );
697 SendMessageW( hwnd, WM_HELP, 0, (LPARAM)&hi );
698 break;
701 case WM_INPUTLANGCHANGEREQUEST:
702 ActivateKeyboardLayout( (HKL)lParam, 0 );
703 break;
705 case WM_INPUTLANGCHANGE:
707 int count = 0;
708 HWND *win_array = WIN_ListChildren( hwnd );
710 if (!win_array)
711 break;
712 while (win_array[count])
713 SendMessageW( win_array[count++], WM_INPUTLANGCHANGE, wParam, lParam);
714 HeapFree(GetProcessHeap(),0,win_array);
715 break;
720 return 0;
723 static LPARAM DEFWND_GetTextA( WND *wndPtr, LPSTR dest, WPARAM wParam )
725 LPARAM result = 0;
727 __TRY
729 if (wndPtr->text)
731 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
732 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
733 result = strlen( dest );
735 else dest[0] = '\0';
737 __EXCEPT_PAGE_FAULT
739 return 0;
741 __ENDTRY
742 return result;
745 /***********************************************************************
746 * DefWindowProcA (USER32.@)
748 * See DefWindowProcW.
750 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
752 LRESULT result = 0;
753 HWND full_handle;
755 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
757 if (!IsWindow( hwnd )) return 0;
758 ERR( "called for other process window %p\n", hwnd );
759 return 0;
761 hwnd = full_handle;
763 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
765 switch(msg)
767 case WM_NCCREATE:
768 if (lParam)
770 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
771 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
772 * may have child window IDs instead of window name */
773 if (!IS_INTRESOURCE(cs->lpszName))
774 DEFWND_SetTextA( hwnd, cs->lpszName );
775 result = 1;
777 if(cs->style & (WS_HSCROLL | WS_VSCROLL))
779 SCROLLINFO si = {sizeof si, SIF_ALL, 0, 100, 0, 0, 0};
780 SetScrollInfo( hwnd, SB_HORZ, &si, FALSE );
781 SetScrollInfo( hwnd, SB_VERT, &si, FALSE );
784 break;
786 case WM_GETTEXTLENGTH:
788 WND *wndPtr = WIN_GetPtr( hwnd );
789 if (wndPtr && wndPtr->text)
790 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
791 NULL, 0, NULL, NULL );
792 WIN_ReleasePtr( wndPtr );
794 break;
796 case WM_GETTEXT:
797 if (wParam)
799 LPSTR dest = (LPSTR)lParam;
800 WND *wndPtr = WIN_GetPtr( hwnd );
802 if (!wndPtr) break;
803 result = DEFWND_GetTextA( wndPtr, dest, wParam );
805 WIN_ReleasePtr( wndPtr );
807 break;
809 case WM_SETTEXT:
810 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
811 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
812 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
813 result = 1; /* success. FIXME: check text length */
814 break;
816 case WM_IME_CHAR:
817 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
818 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
819 break;
821 case WM_IME_KEYDOWN:
822 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
823 break;
825 case WM_IME_KEYUP:
826 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
827 break;
829 case WM_IME_STARTCOMPOSITION:
830 case WM_IME_COMPOSITION:
831 case WM_IME_ENDCOMPOSITION:
832 case WM_IME_SELECT:
833 case WM_IME_NOTIFY:
834 case WM_IME_CONTROL:
836 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
837 if (hwndIME)
838 result = SendMessageA( hwndIME, msg, wParam, lParam );
840 break;
841 case WM_IME_SETCONTEXT:
843 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
844 if (hwndIME) result = ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
846 break;
848 case WM_SYSCHAR:
850 CHAR ch = LOWORD(wParam);
851 WCHAR wch;
852 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
853 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
855 /* fall through */
856 default:
857 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
858 break;
861 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
862 return result;
866 static LPARAM DEFWND_GetTextW( WND *wndPtr, LPWSTR dest, WPARAM wParam )
868 LPARAM result = 0;
870 __TRY
872 if (wndPtr->text)
874 lstrcpynW( dest, wndPtr->text, wParam );
875 result = strlenW( dest );
877 else dest[0] = '\0';
879 __EXCEPT_PAGE_FAULT
881 return 0;
883 __ENDTRY
885 return result;
888 /***********************************************************************
889 * DefWindowProcW (USER32.@) Calls default window message handler
891 * Calls default window procedure for messages not processed
892 * by application.
894 * RETURNS
895 * Return value is dependent upon the message.
897 LRESULT WINAPI DefWindowProcW(
898 HWND hwnd, /* [in] window procedure receiving message */
899 UINT msg, /* [in] message identifier */
900 WPARAM wParam, /* [in] first message parameter */
901 LPARAM lParam ) /* [in] second message parameter */
903 LRESULT result = 0;
904 HWND full_handle;
906 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
908 if (!IsWindow( hwnd )) return 0;
909 ERR( "called for other process window %p\n", hwnd );
910 return 0;
912 hwnd = full_handle;
913 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
915 switch(msg)
917 case WM_NCCREATE:
918 if (lParam)
920 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
921 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
922 * may have child window IDs instead of window name */
923 if (!IS_INTRESOURCE(cs->lpszName))
924 DEFWND_SetTextW( hwnd, cs->lpszName );
925 result = 1;
927 if(cs->style & (WS_HSCROLL | WS_VSCROLL))
929 SCROLLINFO si = {sizeof si, SIF_ALL, 0, 100, 0, 0, 0};
930 SetScrollInfo( hwnd, SB_HORZ, &si, FALSE );
931 SetScrollInfo( hwnd, SB_VERT, &si, FALSE );
934 break;
936 case WM_GETTEXTLENGTH:
938 WND *wndPtr = WIN_GetPtr( hwnd );
939 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
940 WIN_ReleasePtr( wndPtr );
942 break;
944 case WM_GETTEXT:
945 if (wParam)
947 LPWSTR dest = (LPWSTR)lParam;
948 WND *wndPtr = WIN_GetPtr( hwnd );
950 if (!wndPtr) break;
951 result = DEFWND_GetTextW( wndPtr, dest, wParam );
952 WIN_ReleasePtr( wndPtr );
954 break;
956 case WM_SETTEXT:
957 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
958 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
959 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
960 result = 1; /* success. FIXME: check text length */
961 break;
963 case WM_IME_CHAR:
964 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
965 break;
967 case WM_IME_KEYDOWN:
968 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
969 break;
971 case WM_IME_KEYUP:
972 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
973 break;
975 case WM_IME_SETCONTEXT:
977 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
978 if (hwndIME) result = ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
980 break;
982 case WM_IME_STARTCOMPOSITION:
983 case WM_IME_COMPOSITION:
984 case WM_IME_ENDCOMPOSITION:
985 case WM_IME_SELECT:
986 case WM_IME_NOTIFY:
987 case WM_IME_CONTROL:
989 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
990 if (hwndIME)
991 result = SendMessageW( hwndIME, msg, wParam, lParam );
993 break;
995 default:
996 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
997 break;
999 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
1000 return result;