gdi32: Reimplement Ellipse in paths to avoid calling imprecise arc helper functions.
[wine.git] / dlls / user32 / defwnd.c
blobe62f02143521a05177638c0862efb4117b3fe7fc
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 pt.x = (short)LOWORD(lParam);
302 pt.y = (short)HIWORD(lParam);
303 hitcode = NC_HandleNCHitTest(hwnd, pt);
305 /* Track system popup if click was in the caption area. */
306 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
307 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
308 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
309 pt.x, pt.y, 0, hwnd, NULL);
311 break;
313 case WM_POPUPSYSTEMMENU:
314 /* This is an undocumented message used by the windows taskbar to
315 display the system menu of windows that belong to other processes. */
316 TrackPopupMenu( GetSystemMenu(hwnd, FALSE), TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
317 (short)LOWORD(lParam), (short)HIWORD(lParam), 0, hwnd, NULL );
318 return 0;
320 case WM_NCACTIVATE:
321 return NC_HandleNCActivate( hwnd, wParam, lParam );
323 case WM_NCDESTROY:
325 WND *wndPtr = WIN_GetPtr( hwnd );
326 if (!wndPtr) return 0;
327 HeapFree( GetProcessHeap(), 0, wndPtr->text );
328 wndPtr->text = NULL;
329 HeapFree( GetProcessHeap(), 0, wndPtr->pScroll );
330 wndPtr->pScroll = NULL;
331 WIN_ReleasePtr( wndPtr );
332 return 0;
335 case WM_PRINT:
336 DEFWND_Print(hwnd, (HDC)wParam, lParam);
337 return 0;
339 case WM_PAINTICON:
340 case WM_PAINT:
342 PAINTSTRUCT ps;
343 HDC hdc = BeginPaint( hwnd, &ps );
344 if( hdc )
346 HICON hIcon;
347 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON))) )
349 RECT rc;
350 int x, y;
352 GetClientRect( hwnd, &rc );
353 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
354 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
355 TRACE("Painting class icon: vis rect=(%s)\n",
356 wine_dbgstr_rect(&ps.rcPaint));
357 DrawIcon( hdc, x, y, hIcon );
359 EndPaint( hwnd, &ps );
361 return 0;
364 case WM_SYNCPAINT:
365 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
366 return 0;
368 case WM_SETREDRAW:
369 if (wParam) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
370 else
372 RedrawWindow( hwnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
373 WIN_SetStyle( hwnd, 0, WS_VISIBLE );
375 return 0;
377 case WM_CLOSE:
378 DestroyWindow( hwnd );
379 return 0;
381 case WM_MOUSEACTIVATE:
382 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
384 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
385 if (ret) return ret;
388 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
389 return MA_ACTIVATE;
391 case WM_ACTIVATE:
392 /* The default action in Windows is to set the keyboard focus to
393 * the window, if it's being activated and not minimized */
394 if (LOWORD(wParam) != WA_INACTIVE) {
395 if (!IsIconic(hwnd)) SetFocus(hwnd);
397 break;
399 case WM_MOUSEWHEEL:
400 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
401 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
402 break;
404 case WM_ERASEBKGND:
405 case WM_ICONERASEBKGND:
407 RECT rect;
408 HDC hdc = (HDC)wParam;
409 HBRUSH hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
410 if (!hbr) return 0;
412 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
414 /* can't use GetClipBox with a parent DC or we fill the whole parent */
415 GetClientRect( hwnd, &rect );
416 DPtoLP( hdc, (LPPOINT)&rect, 2 );
418 else GetClipBox( hdc, &rect );
419 FillRect( hdc, &rect, hbr );
420 return 1;
423 case WM_GETDLGCODE:
424 return 0;
426 case WM_CTLCOLORMSGBOX:
427 case WM_CTLCOLOREDIT:
428 case WM_CTLCOLORLISTBOX:
429 case WM_CTLCOLORBTN:
430 case WM_CTLCOLORDLG:
431 case WM_CTLCOLORSTATIC:
432 case WM_CTLCOLORSCROLLBAR:
433 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
435 case WM_CTLCOLOR:
436 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
438 case WM_SETCURSOR:
439 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
441 /* with the exception of the border around a resizable wnd,
442 * give the parent first chance to set the cursor */
443 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
445 HWND parent = GetParent( hwnd );
446 if (parent != GetDesktopWindow() &&
447 SendMessageW( parent, WM_SETCURSOR, wParam, lParam )) return TRUE;
450 NC_HandleSetCursor( hwnd, wParam, lParam );
451 break;
453 case WM_SYSCOMMAND:
454 return NC_HandleSysCommand( hwnd, wParam, lParam );
456 case WM_KEYDOWN:
457 if(wParam == VK_F10) iF10Key = VK_F10;
458 break;
460 case WM_SYSKEYDOWN:
461 if( HIWORD(lParam) & KEYDATA_ALT )
463 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
464 if ( (wParam == VK_MENU || wParam == VK_LMENU
465 || wParam == VK_RMENU) && !iMenuSysKey )
466 iMenuSysKey = 1;
467 else
468 iMenuSysKey = 0;
470 iF10Key = 0;
472 if( wParam == VK_F4 ) /* try to close the window */
474 HWND top = GetAncestor( hwnd, GA_ROOT );
475 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
476 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
479 else if( wParam == VK_F10 )
481 if (GetKeyState(VK_SHIFT) & 0x8000)
482 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, -1 );
483 iF10Key = 1;
485 else if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
486 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
487 break;
489 case WM_KEYUP:
490 case WM_SYSKEYUP:
491 /* Press and release F10 or ALT */
492 if (((wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU)
493 && iMenuSysKey) || ((wParam == VK_F10) && iF10Key))
494 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
495 iMenuSysKey = iF10Key = 0;
496 break;
498 case WM_SYSCHAR:
500 iMenuSysKey = 0;
501 if (wParam == '\r' && IsIconic(hwnd))
503 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
504 break;
506 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
508 if (wParam == '\t' || wParam == '\x1b') break;
509 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
510 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
511 else
512 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
514 else /* check for Ctrl-Esc */
515 if (wParam != '\x1b') MessageBeep(0);
516 break;
519 case WM_SHOWWINDOW:
521 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
522 WND *pWnd;
523 if (!lParam) return 0; /* sent from ShowWindow */
524 if ((style & WS_VISIBLE) && wParam) return 0;
525 if (!(style & WS_VISIBLE) && !wParam) return 0;
526 if (!GetWindow( hwnd, GW_OWNER )) return 0;
527 if (!(pWnd = WIN_GetPtr( hwnd ))) return 0;
528 if (pWnd == WND_OTHER_PROCESS) return 0;
529 if (wParam)
531 if (!(pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP))
533 WIN_ReleasePtr( pWnd );
534 return 0;
536 pWnd->flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP;
538 else pWnd->flags |= WIN_NEEDS_SHOW_OWNEDPOPUP;
539 WIN_ReleasePtr( pWnd );
540 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
541 break;
544 case WM_CANCELMODE:
545 iMenuSysKey = 0;
546 MENU_EndMenu( hwnd );
547 if (GetCapture() == hwnd) ReleaseCapture();
548 break;
550 case WM_VKEYTOITEM:
551 case WM_CHARTOITEM:
552 return -1;
554 case WM_DROPOBJECT:
555 return DRAG_FILE;
557 case WM_QUERYDROPOBJECT:
558 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
560 case WM_QUERYDRAGICON:
562 UINT len;
564 HICON hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON );
565 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
566 if (hIcon) return (LRESULT)hIcon;
567 for(len=1; len<64; len++)
568 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
569 return (LRESULT)hIcon;
570 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
572 break;
574 case WM_ISACTIVEICON:
575 return (win_get_flags( hwnd ) & WIN_NCACTIVATED) != 0;
577 case WM_NOTIFYFORMAT:
578 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
579 else return NFR_ANSI;
581 case WM_QUERYOPEN:
582 case WM_QUERYENDSESSION:
583 return 1;
585 case WM_SETICON:
587 HICON ret;
588 WND *wndPtr = WIN_GetPtr( hwnd );
590 switch(wParam)
592 case ICON_SMALL:
593 ret = wndPtr->hIconSmall;
594 if (ret && !lParam && wndPtr->hIcon)
596 wndPtr->hIconSmall2 = CopyImage( wndPtr->hIcon, IMAGE_ICON,
597 GetSystemMetrics( SM_CXSMICON ),
598 GetSystemMetrics( SM_CYSMICON ), 0 );
600 else if (lParam && wndPtr->hIconSmall2)
602 DestroyIcon( wndPtr->hIconSmall2 );
603 wndPtr->hIconSmall2 = NULL;
605 wndPtr->hIconSmall = (HICON)lParam;
606 break;
607 case ICON_BIG:
608 ret = wndPtr->hIcon;
609 if (wndPtr->hIconSmall2)
611 DestroyIcon( wndPtr->hIconSmall2 );
612 wndPtr->hIconSmall2 = NULL;
614 if (lParam && !wndPtr->hIconSmall)
616 wndPtr->hIconSmall2 = CopyImage( (HICON)lParam, IMAGE_ICON,
617 GetSystemMetrics( SM_CXSMICON ),
618 GetSystemMetrics( SM_CYSMICON ), 0 );
620 wndPtr->hIcon = (HICON)lParam;
621 break;
622 default:
623 ret = 0;
624 break;
626 WIN_ReleasePtr( wndPtr );
628 USER_Driver->pSetWindowIcon( hwnd, wParam, (HICON)lParam );
630 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
631 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
633 return (LRESULT)ret;
636 case WM_GETICON:
638 HICON ret;
639 WND *wndPtr = WIN_GetPtr( hwnd );
641 switch(wParam)
643 case ICON_SMALL:
644 ret = wndPtr->hIconSmall;
645 break;
646 case ICON_BIG:
647 ret = wndPtr->hIcon;
648 break;
649 case ICON_SMALL2:
650 ret = wndPtr->hIconSmall ? wndPtr->hIconSmall : wndPtr->hIconSmall2;
651 break;
652 default:
653 ret = 0;
654 break;
656 WIN_ReleasePtr( wndPtr );
657 return (LRESULT)ret;
660 case WM_HELP:
661 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
662 break;
664 case WM_STYLECHANGED:
665 if (wParam == GWL_STYLE && (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED))
667 STYLESTRUCT *style = (STYLESTRUCT *)lParam;
668 if ((style->styleOld ^ style->styleNew) & (WS_CAPTION|WS_THICKFRAME|WS_VSCROLL|WS_HSCROLL))
669 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOZORDER |
670 SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE );
672 break;
674 case WM_APPCOMMAND:
676 HWND parent = GetParent(hwnd);
677 if(!parent)
678 HOOK_CallHooks(WH_SHELL, HSHELL_APPCOMMAND, wParam, lParam, TRUE);
679 else
680 SendMessageW( parent, msg, wParam, lParam );
681 break;
683 case WM_KEYF1:
685 HELPINFO hi;
687 hi.cbSize = sizeof(HELPINFO);
688 GetCursorPos( &hi.MousePos );
689 if (MENU_IsMenuActive())
691 hi.iContextType = HELPINFO_MENUITEM;
692 hi.hItemHandle = MENU_IsMenuActive();
693 hi.iCtrlId = MenuItemFromPoint( hwnd, hi.hItemHandle, hi.MousePos );
694 hi.dwContextId = GetMenuContextHelpId( hi.hItemHandle );
696 else
698 hi.iContextType = HELPINFO_WINDOW;
699 hi.hItemHandle = hwnd;
700 hi.iCtrlId = GetWindowLongPtrA( hwnd, GWLP_ID );
701 hi.dwContextId = GetWindowContextHelpId( hwnd );
703 SendMessageW( hwnd, WM_HELP, 0, (LPARAM)&hi );
704 break;
707 case WM_INPUTLANGCHANGEREQUEST:
708 ActivateKeyboardLayout( (HKL)lParam, 0 );
709 break;
711 case WM_INPUTLANGCHANGE:
713 int count = 0;
714 HWND *win_array = WIN_ListChildren( hwnd );
716 if (!win_array)
717 break;
718 while (win_array[count])
719 SendMessageW( win_array[count++], WM_INPUTLANGCHANGE, wParam, lParam);
720 HeapFree(GetProcessHeap(),0,win_array);
721 break;
726 return 0;
729 static LPARAM DEFWND_GetTextA( WND *wndPtr, LPSTR dest, WPARAM wParam )
731 LPARAM result = 0;
733 __TRY
735 if (wndPtr->text)
737 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
738 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
739 result = strlen( dest );
741 else dest[0] = '\0';
743 __EXCEPT_PAGE_FAULT
745 return 0;
747 __ENDTRY
748 return result;
751 /***********************************************************************
752 * DefWindowProcA (USER32.@)
754 * See DefWindowProcW.
756 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
758 LRESULT result = 0;
759 HWND full_handle;
761 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
763 if (!IsWindow( hwnd )) return 0;
764 ERR( "called for other process window %p\n", hwnd );
765 return 0;
767 hwnd = full_handle;
769 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
771 switch(msg)
773 case WM_NCCREATE:
774 if (lParam)
776 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
777 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
778 * may have child window IDs instead of window name */
779 if (!IS_INTRESOURCE(cs->lpszName))
780 DEFWND_SetTextA( hwnd, cs->lpszName );
781 result = 1;
783 if(cs->style & (WS_HSCROLL | WS_VSCROLL))
785 SCROLLINFO si = {sizeof si, SIF_ALL, 0, 100, 0, 0, 0};
786 SetScrollInfo( hwnd, SB_HORZ, &si, FALSE );
787 SetScrollInfo( hwnd, SB_VERT, &si, FALSE );
790 break;
792 case WM_GETTEXTLENGTH:
794 WND *wndPtr = WIN_GetPtr( hwnd );
795 if (wndPtr && wndPtr->text)
796 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
797 NULL, 0, NULL, NULL );
798 WIN_ReleasePtr( wndPtr );
800 break;
802 case WM_GETTEXT:
803 if (wParam)
805 LPSTR dest = (LPSTR)lParam;
806 WND *wndPtr = WIN_GetPtr( hwnd );
808 if (!wndPtr) break;
809 result = DEFWND_GetTextA( wndPtr, dest, wParam );
811 WIN_ReleasePtr( wndPtr );
813 break;
815 case WM_SETTEXT:
816 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
817 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
818 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
819 result = 1; /* success. FIXME: check text length */
820 break;
822 case WM_IME_CHAR:
823 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
824 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
825 break;
827 case WM_IME_KEYDOWN:
828 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
829 break;
831 case WM_IME_KEYUP:
832 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
833 break;
835 case WM_IME_STARTCOMPOSITION:
836 case WM_IME_COMPOSITION:
837 case WM_IME_ENDCOMPOSITION:
838 case WM_IME_SELECT:
839 case WM_IME_NOTIFY:
840 case WM_IME_CONTROL:
842 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
843 if (hwndIME)
844 result = SendMessageA( hwndIME, msg, wParam, lParam );
846 break;
847 case WM_IME_SETCONTEXT:
849 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
850 if (hwndIME) result = ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
852 break;
854 case WM_SYSCHAR:
856 CHAR ch = LOWORD(wParam);
857 WCHAR wch;
858 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
859 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
861 /* fall through */
862 default:
863 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
864 break;
867 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
868 return result;
872 static LPARAM DEFWND_GetTextW( WND *wndPtr, LPWSTR dest, WPARAM wParam )
874 LPARAM result = 0;
876 __TRY
878 if (wndPtr->text)
880 lstrcpynW( dest, wndPtr->text, wParam );
881 result = strlenW( dest );
883 else dest[0] = '\0';
885 __EXCEPT_PAGE_FAULT
887 return 0;
889 __ENDTRY
891 return result;
894 /***********************************************************************
895 * DefWindowProcW (USER32.@) Calls default window message handler
897 * Calls default window procedure for messages not processed
898 * by application.
900 * RETURNS
901 * Return value is dependent upon the message.
903 LRESULT WINAPI DefWindowProcW(
904 HWND hwnd, /* [in] window procedure receiving message */
905 UINT msg, /* [in] message identifier */
906 WPARAM wParam, /* [in] first message parameter */
907 LPARAM lParam ) /* [in] second message parameter */
909 LRESULT result = 0;
910 HWND full_handle;
912 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
914 if (!IsWindow( hwnd )) return 0;
915 ERR( "called for other process window %p\n", hwnd );
916 return 0;
918 hwnd = full_handle;
919 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
921 switch(msg)
923 case WM_NCCREATE:
924 if (lParam)
926 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
927 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
928 * may have child window IDs instead of window name */
929 if (!IS_INTRESOURCE(cs->lpszName))
930 DEFWND_SetTextW( hwnd, cs->lpszName );
931 result = 1;
933 if(cs->style & (WS_HSCROLL | WS_VSCROLL))
935 SCROLLINFO si = {sizeof si, SIF_ALL, 0, 100, 0, 0, 0};
936 SetScrollInfo( hwnd, SB_HORZ, &si, FALSE );
937 SetScrollInfo( hwnd, SB_VERT, &si, FALSE );
940 break;
942 case WM_GETTEXTLENGTH:
944 WND *wndPtr = WIN_GetPtr( hwnd );
945 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
946 WIN_ReleasePtr( wndPtr );
948 break;
950 case WM_GETTEXT:
951 if (wParam)
953 LPWSTR dest = (LPWSTR)lParam;
954 WND *wndPtr = WIN_GetPtr( hwnd );
956 if (!wndPtr) break;
957 result = DEFWND_GetTextW( wndPtr, dest, wParam );
958 WIN_ReleasePtr( wndPtr );
960 break;
962 case WM_SETTEXT:
963 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
964 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
965 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
966 result = 1; /* success. FIXME: check text length */
967 break;
969 case WM_IME_CHAR:
970 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
971 break;
973 case WM_IME_KEYDOWN:
974 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
975 break;
977 case WM_IME_KEYUP:
978 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
979 break;
981 case WM_IME_SETCONTEXT:
983 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
984 if (hwndIME) result = ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
986 break;
988 case WM_IME_STARTCOMPOSITION:
989 case WM_IME_COMPOSITION:
990 case WM_IME_ENDCOMPOSITION:
991 case WM_IME_SELECT:
992 case WM_IME_NOTIFY:
993 case WM_IME_CONTROL:
995 HWND hwndIME = ImmGetDefaultIMEWnd( hwnd );
996 if (hwndIME)
997 result = SendMessageW( hwndIME, msg, wParam, lParam );
999 break;
1001 default:
1002 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1003 break;
1005 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
1006 return result;