quartz: Add a cleanup callback for parser filters to call on release.
[wine.git] / dlls / user32 / defwnd.c
blobfda2dc983fb7af39da4415aadee69b33f0703837
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/winuser16.h"
38 #include "wine/server.h"
39 #include "wine/exception.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(win);
44 /* bits in the dwKeyData */
45 #define KEYDATA_ALT 0x2000
46 #define KEYDATA_PREVSTATE 0x4000
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 WPARAM wp = SIZE_RESTORED;
71 if (IsZoomed(hwnd)) wp = SIZE_MAXIMIZED;
72 else if (IsIconic(hwnd)) wp = SIZE_MINIMIZED;
74 SendMessageW( hwnd, WM_SIZE, wp, MAKELONG(rect.right-rect.left, rect.bottom-rect.top) );
79 /***********************************************************************
80 * DEFWND_SetTextA
82 * Set the window text.
84 static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
86 int count;
87 WCHAR *textW;
88 WND *wndPtr;
90 if (!text) text = "";
91 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
93 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
94 if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
96 HeapFree(GetProcessHeap(), 0, wndPtr->text);
97 wndPtr->text = textW;
98 MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
99 SERVER_START_REQ( set_window_text )
101 req->handle = hwnd;
102 wine_server_add_data( req, textW, (count-1) * sizeof(WCHAR) );
103 wine_server_call( req );
105 SERVER_END_REQ;
107 else
108 ERR("Not enough memory for window text\n");
109 WIN_ReleasePtr( wndPtr );
111 USER_Driver->pSetWindowText( hwnd, textW );
114 /***********************************************************************
115 * DEFWND_SetTextW
117 * Set the window text.
119 static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
121 static const WCHAR empty_string[] = {0};
122 WND *wndPtr;
123 int count;
125 if (!text) text = empty_string;
126 count = strlenW(text) + 1;
128 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
129 HeapFree(GetProcessHeap(), 0, wndPtr->text);
130 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
132 strcpyW( wndPtr->text, text );
133 SERVER_START_REQ( set_window_text )
135 req->handle = hwnd;
136 wine_server_add_data( req, wndPtr->text, (count-1) * sizeof(WCHAR) );
137 wine_server_call( req );
139 SERVER_END_REQ;
141 else
142 ERR("Not enough memory for window text\n");
143 text = wndPtr->text;
144 WIN_ReleasePtr( wndPtr );
146 USER_Driver->pSetWindowText( hwnd, text );
149 /***********************************************************************
150 * DEFWND_ControlColor
152 * Default colors for control painting.
154 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
156 if( ctlType == CTLCOLOR_SCROLLBAR)
158 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
159 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
160 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
161 SetBkColor( hDC, bk);
163 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
164 * we better use 0x55aa bitmap brush to make scrollbar's background
165 * look different from the window background.
167 if (bk == GetSysColor(COLOR_WINDOW))
168 return SYSCOLOR_55AABrush;
170 UnrealizeObject( hb );
171 return hb;
174 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
176 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
177 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
178 else {
179 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
180 return GetSysColorBrush(COLOR_3DFACE);
182 return GetSysColorBrush(COLOR_WINDOW);
186 /***********************************************************************
187 * DEFWND_Print
189 * This method handles the default behavior for the WM_PRINT message.
191 static void DEFWND_Print( HWND hwnd, HDC hdc, ULONG uFlags)
194 * Visibility flag.
196 if ( (uFlags & PRF_CHECKVISIBLE) &&
197 !IsWindowVisible(hwnd) )
198 return;
201 * Unimplemented flags.
203 if ( (uFlags & PRF_CHILDREN) ||
204 (uFlags & PRF_OWNED) ||
205 (uFlags & PRF_NONCLIENT) )
207 WARN("WM_PRINT message with unsupported flags\n");
211 * Background
213 if ( uFlags & PRF_ERASEBKGND)
214 SendMessageW(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
217 * Client area
219 if ( uFlags & PRF_CLIENT)
220 SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
225 * helpers for calling IMM32
227 * WM_IME_* messages are generated only by IMM32,
228 * so I assume imm32 is already LoadLibrary-ed.
230 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
232 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
233 HWND (WINAPI *pFunc)(HWND);
234 HWND hwndRet = 0;
236 if (!hInstIMM)
238 ERR( "cannot get IMM32 handle\n" );
239 return 0;
242 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
243 if ( pFunc != NULL )
244 hwndRet = (*pFunc)( hwnd );
246 return hwndRet;
249 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
251 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
252 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
253 BOOL fRet = FALSE;
255 if (!hInstIMM)
257 ERR( "cannot get IMM32 handle\n" );
258 return FALSE;
261 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
262 if ( pFunc != NULL )
263 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
265 return fRet;
268 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
270 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
271 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
272 BOOL fRet = FALSE;
274 if (!hInstIMM)
276 ERR( "cannot get IMM32 handle\n" );
277 return FALSE;
280 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
281 if ( pFunc != NULL )
282 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
284 return fRet;
289 /***********************************************************************
290 * DEFWND_DefWinProc
292 * Default window procedure for messages that are the same in Ansi and Unicode.
294 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
296 switch(msg)
298 case WM_NCPAINT:
299 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
301 case WM_NCHITTEST:
303 POINT pt;
304 pt.x = (short)LOWORD(lParam);
305 pt.y = (short)HIWORD(lParam);
306 return NC_HandleNCHitTest( hwnd, pt );
309 case WM_NCCALCSIZE:
310 return NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
312 case WM_WINDOWPOSCHANGING:
313 return WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
315 case WM_WINDOWPOSCHANGED:
316 DEFWND_HandleWindowPosChanged( hwnd, (const WINDOWPOS *)lParam );
317 break;
319 case WM_LBUTTONDOWN:
320 case WM_RBUTTONDOWN:
321 case WM_MBUTTONDOWN:
322 iF10Key = iMenuSysKey = 0;
323 break;
325 case WM_NCLBUTTONDOWN:
326 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
328 case WM_LBUTTONDBLCLK:
329 case WM_NCLBUTTONDBLCLK:
330 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
332 case WM_NCRBUTTONDOWN:
333 /* in Windows, capture is taken when right-clicking on the caption bar */
334 if (wParam==HTCAPTION)
336 SetCapture(hwnd);
338 break;
340 case WM_RBUTTONUP:
342 POINT pt;
344 if (hwnd == GetCapture())
345 /* release capture if we took it on WM_NCRBUTTONDOWN */
346 ReleaseCapture();
348 pt.x = (short)LOWORD(lParam);
349 pt.y = (short)HIWORD(lParam);
350 ClientToScreen(hwnd, &pt);
351 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
353 break;
355 case WM_NCRBUTTONUP:
357 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
358 * in Windows), but what _should_ we do? According to MSDN :
359 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
360 * message to the window". When is it appropriate?
362 break;
364 case WM_CONTEXTMENU:
365 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
366 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
367 else
369 LONG hitcode;
370 POINT pt;
371 WND *wndPtr = WIN_GetPtr( hwnd );
372 HMENU hMenu = wndPtr->hSysMenu;
373 WIN_ReleasePtr( wndPtr );
374 if (!hMenu) return 0;
375 pt.x = (short)LOWORD(lParam);
376 pt.y = (short)HIWORD(lParam);
377 hitcode = NC_HandleNCHitTest(hwnd, pt);
379 /* Track system popup if click was in the caption area. */
380 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
381 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
382 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
383 pt.x, pt.y, 0, hwnd, NULL);
385 break;
387 case WM_NCACTIVATE:
388 return NC_HandleNCActivate( hwnd, wParam );
390 case WM_NCDESTROY:
392 WND *wndPtr = WIN_GetPtr( hwnd );
393 if (!wndPtr) return 0;
394 HeapFree( GetProcessHeap(), 0, wndPtr->text );
395 wndPtr->text = NULL;
396 HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll );
397 HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll );
398 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
399 WIN_ReleasePtr( wndPtr );
400 return 0;
403 case WM_PRINT:
404 DEFWND_Print(hwnd, (HDC)wParam, lParam);
405 return 0;
407 case WM_PAINTICON:
408 case WM_PAINT:
410 PAINTSTRUCT ps;
411 HDC hdc = BeginPaint( hwnd, &ps );
412 if( hdc )
414 HICON hIcon;
415 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON))) )
417 RECT rc;
418 int x, y;
420 GetClientRect( hwnd, &rc );
421 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
422 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
423 TRACE("Painting class icon: vis rect=(%d,%d - %d,%d)\n",
424 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
425 DrawIcon( hdc, x, y, hIcon );
427 EndPaint( hwnd, &ps );
429 return 0;
432 case WM_SYNCPAINT:
433 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
434 return 0;
436 case WM_SETREDRAW:
437 if (wParam) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
438 else
440 RedrawWindow( hwnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
441 WIN_SetStyle( hwnd, 0, WS_VISIBLE );
443 return 0;
445 case WM_CLOSE:
446 DestroyWindow( hwnd );
447 return 0;
449 case WM_MOUSEACTIVATE:
450 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
452 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
453 if (ret) return ret;
456 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
457 return MA_ACTIVATE;
459 case WM_ACTIVATE:
460 /* The default action in Windows is to set the keyboard focus to
461 * the window, if it's being activated and not minimized */
462 if (LOWORD(wParam) != WA_INACTIVE) {
463 if (!IsIconic(hwnd)) SetFocus(hwnd);
465 break;
467 case WM_MOUSEWHEEL:
468 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
469 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
470 break;
472 case WM_ERASEBKGND:
473 case WM_ICONERASEBKGND:
475 RECT rect;
476 HDC hdc = (HDC)wParam;
477 HBRUSH hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
478 if (!hbr) return 0;
480 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
482 /* can't use GetClipBox with a parent DC or we fill the whole parent */
483 GetClientRect( hwnd, &rect );
484 DPtoLP( hdc, (LPPOINT)&rect, 2 );
486 else GetClipBox( hdc, &rect );
487 FillRect( hdc, &rect, hbr );
488 return 1;
491 case WM_GETDLGCODE:
492 return 0;
494 case WM_CTLCOLORMSGBOX:
495 case WM_CTLCOLOREDIT:
496 case WM_CTLCOLORLISTBOX:
497 case WM_CTLCOLORBTN:
498 case WM_CTLCOLORDLG:
499 case WM_CTLCOLORSTATIC:
500 case WM_CTLCOLORSCROLLBAR:
501 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
503 case WM_CTLCOLOR:
504 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
506 case WM_SETCURSOR:
507 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
509 /* with the exception of the border around a resizable wnd,
510 * give the parent first chance to set the cursor */
511 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
513 if (SendMessageW(GetParent(hwnd), WM_SETCURSOR, wParam, lParam)) return TRUE;
516 NC_HandleSetCursor( hwnd, wParam, lParam );
517 break;
519 case WM_SYSCOMMAND:
520 return NC_HandleSysCommand( hwnd, wParam, lParam );
522 case WM_KEYDOWN:
523 if(wParam == VK_F10) iF10Key = VK_F10;
524 break;
526 case WM_SYSKEYDOWN:
527 if( HIWORD(lParam) & KEYDATA_ALT )
529 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
530 if ( (wParam == VK_MENU || wParam == VK_LMENU
531 || wParam == VK_RMENU) && !iMenuSysKey )
532 iMenuSysKey = 1;
533 else
534 iMenuSysKey = 0;
536 iF10Key = 0;
538 if( wParam == VK_F4 ) /* try to close the window */
540 HWND top = GetAncestor( hwnd, GA_ROOT );
541 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
542 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
545 else if( wParam == VK_F10 )
546 iF10Key = 1;
547 else if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
548 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
549 break;
551 case WM_KEYUP:
552 case WM_SYSKEYUP:
553 /* Press and release F10 or ALT */
554 if (((wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU)
555 && iMenuSysKey) || ((wParam == VK_F10) && iF10Key))
556 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
557 iMenuSysKey = iF10Key = 0;
558 break;
560 case WM_SYSCHAR:
562 iMenuSysKey = 0;
563 if (wParam == '\r' && IsIconic(hwnd))
565 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
566 break;
568 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
570 if (wParam == '\t' || wParam == '\x1b') break;
571 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
572 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
573 else
574 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
576 else /* check for Ctrl-Esc */
577 if (wParam != '\x1b') MessageBeep(0);
578 break;
581 case WM_SHOWWINDOW:
583 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
584 WND *pWnd;
585 if (!lParam) return 0; /* sent from ShowWindow */
586 if ((style & WS_VISIBLE) && wParam) return 0;
587 if (!(style & WS_VISIBLE) && !wParam) return 0;
588 if (!GetWindow( hwnd, GW_OWNER )) return 0;
589 if (!(pWnd = WIN_GetPtr( hwnd ))) return 0;
590 if (pWnd == WND_OTHER_PROCESS) return 0;
591 if (wParam)
593 if (!(pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP))
595 WIN_ReleasePtr( pWnd );
596 return 0;
598 pWnd->flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP;
600 else pWnd->flags |= WIN_NEEDS_SHOW_OWNEDPOPUP;
601 WIN_ReleasePtr( pWnd );
602 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
603 break;
606 case WM_CANCELMODE:
607 iMenuSysKey = 0;
608 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
609 if (GetCapture() == hwnd) ReleaseCapture();
610 break;
612 case WM_VKEYTOITEM:
613 case WM_CHARTOITEM:
614 return -1;
616 case WM_DROPOBJECT:
617 return DRAG_FILE;
619 case WM_QUERYDROPOBJECT:
620 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
622 case WM_QUERYDRAGICON:
624 UINT len;
626 HICON hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON );
627 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
628 if (hIcon) return (LRESULT)hIcon;
629 for(len=1; len<64; len++)
630 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
631 return (LRESULT)hIcon;
632 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
634 break;
636 case WM_ISACTIVEICON:
638 WND *wndPtr = WIN_GetPtr( hwnd );
639 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
640 WIN_ReleasePtr( wndPtr );
641 return ret;
644 case WM_NOTIFYFORMAT:
645 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
646 else return NFR_ANSI;
648 case WM_QUERYOPEN:
649 case WM_QUERYENDSESSION:
650 return 1;
652 case WM_ENDSESSION:
653 if (wParam)
654 PostQuitMessage(0);
655 return 0;
657 case WM_SETICON:
659 HICON ret;
660 WND *wndPtr = WIN_GetPtr( hwnd );
662 switch(wParam)
664 case ICON_SMALL:
665 ret = wndPtr->hIconSmall;
666 wndPtr->hIconSmall = (HICON)lParam;
667 break;
668 case ICON_BIG:
669 ret = wndPtr->hIcon;
670 wndPtr->hIcon = (HICON)lParam;
671 break;
672 default:
673 ret = 0;
674 break;
676 WIN_ReleasePtr( wndPtr );
678 USER_Driver->pSetWindowIcon( hwnd, wParam, (HICON)lParam );
680 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
681 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
683 return (LRESULT)ret;
686 case WM_GETICON:
688 HICON ret;
689 WND *wndPtr = WIN_GetPtr( hwnd );
691 switch(wParam)
693 case ICON_SMALL:
694 ret = wndPtr->hIconSmall;
695 break;
696 case ICON_BIG:
697 ret = wndPtr->hIcon;
698 break;
699 case ICON_SMALL2:
700 ret = wndPtr->hIconSmall;
701 if (!ret) ret = (HICON)GetClassLongPtrW( hwnd, GCLP_HICONSM );
702 /* FIXME: should have a default here if class icon is null */
703 break;
704 default:
705 ret = 0;
706 break;
708 WIN_ReleasePtr( wndPtr );
709 return (LRESULT)ret;
712 case WM_HELP:
713 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
714 break;
716 case WM_APPCOMMAND:
718 HWND parent = GetParent(hwnd);
719 if(!parent)
720 HOOK_CallHooks(WH_SHELL, HSHELL_APPCOMMAND, wParam, lParam, TRUE);
721 else
722 SendMessageW( parent, msg, wParam, lParam );
723 break;
727 return 0;
730 static LPARAM DEFWND_GetTextA( WND *wndPtr, LPSTR dest, WPARAM wParam )
732 LPARAM result = 0;
734 __TRY
736 if (wndPtr->text)
738 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
739 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
740 result = strlen( dest );
742 else dest[0] = '\0';
744 __EXCEPT_PAGE_FAULT
746 return 0;
748 __ENDTRY
749 return result;
752 /***********************************************************************
753 * DefWindowProcA (USER32.@)
755 * See DefWindowProcW.
757 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
759 LRESULT result = 0;
760 HWND full_handle;
762 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
764 if (!IsWindow( hwnd )) return 0;
765 ERR( "called for other process window %p\n", hwnd );
766 return 0;
768 hwnd = full_handle;
770 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
772 switch(msg)
774 case WM_NCCREATE:
775 if (lParam)
777 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
778 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
779 * may have child window IDs instead of window name */
780 if (HIWORD(cs->lpszName))
781 DEFWND_SetTextA( hwnd, cs->lpszName );
782 result = 1;
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 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
817 case WM_IME_CHAR:
819 CHAR chChar1 = (CHAR)( (wParam>>8) & 0xff );
820 CHAR chChar2 = (CHAR)( wParam & 0xff );
822 if (chChar1)
823 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar1, lParam );
824 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar2, lParam );
826 break;
827 case WM_IME_KEYDOWN:
828 result = SendMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
829 break;
830 case WM_IME_KEYUP:
831 result = SendMessageA( hwnd, WM_KEYUP, wParam, lParam );
832 break;
834 case WM_IME_STARTCOMPOSITION:
835 case WM_IME_COMPOSITION:
836 case WM_IME_ENDCOMPOSITION:
837 case WM_IME_SELECT:
839 HWND hwndIME;
841 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
842 if (hwndIME)
843 result = SendMessageA( hwndIME, msg, wParam, lParam );
845 break;
846 case WM_IME_SETCONTEXT:
848 HWND hwndIME;
850 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
851 if (hwndIME)
852 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
854 break;
856 case WM_INPUTLANGCHANGEREQUEST:
857 /* notify about the switch only if it's really our current layout */
858 if ((HKL)lParam == GetKeyboardLayout(0))
859 result = SendMessageA( hwnd, WM_INPUTLANGCHANGE, wParam, lParam );
860 else
861 result = 0;
862 break;
864 case WM_SYSCHAR:
866 CHAR ch = LOWORD(wParam);
867 WCHAR wch;
868 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
869 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
871 /* fall through */
872 default:
873 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
874 break;
877 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
878 return result;
882 static LPARAM DEFWND_GetTextW( WND *wndPtr, LPWSTR dest, WPARAM wParam )
884 LPARAM result = 0;
886 __TRY
888 if (wndPtr->text)
890 lstrcpynW( dest, wndPtr->text, wParam );
891 result = strlenW( dest );
893 else dest[0] = '\0';
895 __EXCEPT_PAGE_FAULT
897 return 0;
899 __ENDTRY
901 return result;
904 /***********************************************************************
905 * DefWindowProcW (USER32.@) Calls default window message handler
907 * Calls default window procedure for messages not processed
908 * by application.
910 * RETURNS
911 * Return value is dependent upon the message.
913 LRESULT WINAPI DefWindowProcW(
914 HWND hwnd, /* [in] window procedure receiving message */
915 UINT msg, /* [in] message identifier */
916 WPARAM wParam, /* [in] first message parameter */
917 LPARAM lParam ) /* [in] second message parameter */
919 LRESULT result = 0;
920 HWND full_handle;
922 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
924 if (!IsWindow( hwnd )) return 0;
925 ERR( "called for other process window %p\n", hwnd );
926 return 0;
928 hwnd = full_handle;
929 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
931 switch(msg)
933 case WM_NCCREATE:
934 if (lParam)
936 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
937 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
938 * may have child window IDs instead of window name */
939 if (HIWORD(cs->lpszName))
940 DEFWND_SetTextW( hwnd, cs->lpszName );
941 result = 1;
943 break;
945 case WM_GETTEXTLENGTH:
947 WND *wndPtr = WIN_GetPtr( hwnd );
948 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
949 WIN_ReleasePtr( wndPtr );
951 break;
953 case WM_GETTEXT:
954 if (wParam)
956 LPWSTR dest = (LPWSTR)lParam;
957 WND *wndPtr = WIN_GetPtr( hwnd );
959 if (!wndPtr) break;
960 result = DEFWND_GetTextW( wndPtr, dest, wParam );
961 WIN_ReleasePtr( wndPtr );
963 break;
965 case WM_SETTEXT:
966 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
967 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
968 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
969 result = 1; /* success. FIXME: check text length */
970 break;
972 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
973 case WM_IME_CHAR:
974 SendMessageW( hwnd, WM_CHAR, wParam, lParam );
975 break;
976 case WM_IME_SETCONTEXT:
978 HWND hwndIME;
980 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
981 if (hwndIME)
982 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
984 break;
986 case WM_IME_STARTCOMPOSITION:
987 case WM_IME_COMPOSITION:
988 case WM_IME_ENDCOMPOSITION:
989 case WM_IME_SELECT:
991 HWND hwndIME;
993 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
994 if (hwndIME)
995 result = SendMessageW( hwndIME, msg, wParam, lParam );
997 break;
999 case WM_INPUTLANGCHANGEREQUEST:
1000 /* notify about the switch only if it's really our current layout */
1001 if ((HKL)lParam == GetKeyboardLayout(0))
1002 result = SendMessageW( hwnd, WM_INPUTLANGCHANGE, wParam, lParam );
1003 else
1004 result = 0;
1005 break;
1007 default:
1008 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1009 break;
1011 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
1012 return result;