Removed todo_wine from some tests that succeed now.
[wine/multimedia.git] / windows / defwnd.c
blobac4882ea532135631b41d8da141de851ed8157c3
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <string.h>
27 #include "win.h"
28 #include "user.h"
29 #include "nonclient.h"
30 #include "winpos.h"
31 #include "dce.h"
32 #include "windef.h"
33 #include "wingdi.h"
34 #include "winnls.h"
35 #include "imm.h"
36 #include "message.h"
37 #include "wine/unicode.h"
38 #include "wine/winuser16.h"
39 #include "wine/server.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;
51 /***********************************************************************
52 * DEFWND_HandleWindowPosChanged
54 * Handle the WM_WINDOWPOSCHANGED message.
56 static void DEFWND_HandleWindowPosChanged( HWND hwnd, UINT flags )
58 RECT rect;
59 WND *wndPtr = WIN_GetPtr( hwnd );
61 rect = wndPtr->rectClient;
62 WIN_ReleasePtr( wndPtr );
64 if (!(flags & SWP_NOCLIENTMOVE))
65 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG(rect.left, rect.top));
67 if (!(flags & SWP_NOCLIENTSIZE))
69 WPARAM wp = SIZE_RESTORED;
70 if (IsZoomed(hwnd)) wp = SIZE_MAXIMIZED;
71 else if (IsIconic(hwnd)) wp = SIZE_MINIMIZED;
73 SendMessageW( hwnd, WM_SIZE, wp, MAKELONG(rect.right-rect.left, rect.bottom-rect.top) );
78 /***********************************************************************
79 * DEFWND_SetTextA
81 * Set the window text.
83 static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
85 int count;
86 WCHAR *textW;
87 WND *wndPtr;
89 if (!text) text = "";
90 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
92 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
93 if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
95 if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
96 wndPtr->text = textW;
97 MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
98 SERVER_START_REQ( set_window_text )
100 req->handle = hwnd;
101 wine_server_add_data( req, textW, (count-1) * sizeof(WCHAR) );
102 wine_server_call( req );
104 SERVER_END_REQ;
106 else
107 ERR("Not enough memory for window text\n");
108 WIN_ReleasePtr( wndPtr );
110 if (USER_Driver.pSetWindowText) USER_Driver.pSetWindowText( hwnd, textW );
113 /***********************************************************************
114 * DEFWND_SetTextW
116 * Set the window text.
118 static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
120 static const WCHAR empty_string[] = {0};
121 WND *wndPtr;
122 int count;
124 if (!text) text = empty_string;
125 count = strlenW(text) + 1;
127 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
128 if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
129 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
131 strcpyW( wndPtr->text, text );
132 SERVER_START_REQ( set_window_text )
134 req->handle = hwnd;
135 wine_server_add_data( req, wndPtr->text, (count-1) * sizeof(WCHAR) );
136 wine_server_call( req );
138 SERVER_END_REQ;
140 else
141 ERR("Not enough memory for window text\n");
142 text = wndPtr->text;
143 WIN_ReleasePtr( wndPtr );
145 if (USER_Driver.pSetWindowText) USER_Driver.pSetWindowText( hwnd, text );
148 /***********************************************************************
149 * DEFWND_ControlColor
151 * Default colors for control painting.
153 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
155 if( ctlType == CTLCOLOR_SCROLLBAR)
157 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
158 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
159 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
160 SetBkColor( hDC, bk);
162 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
163 * we better use 0x55aa bitmap brush to make scrollbar's background
164 * look different from the window background.
166 if (bk == GetSysColor(COLOR_WINDOW))
167 return CACHE_GetPattern55AABrush();
169 UnrealizeObject( hb );
170 return hb;
173 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
175 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
176 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
177 else {
178 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
179 return GetSysColorBrush(COLOR_3DFACE);
181 return GetSysColorBrush(COLOR_WINDOW);
185 /***********************************************************************
186 * DEFWND_SetRedraw
188 static void DEFWND_SetRedraw( HWND hwnd, WPARAM wParam )
190 WND *wndPtr = WIN_FindWndPtr( hwnd );
191 BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
193 TRACE("%p %i\n", hwnd, (wParam!=0) );
195 if( wParam )
197 if( !bVisible )
199 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_VISIBLE );
200 DCE_InvalidateDCE( hwnd, &wndPtr->rectWindow );
203 else if( bVisible )
205 if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
206 else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
208 RedrawWindow( hwnd, NULL, 0, wParam );
209 DCE_InvalidateDCE( hwnd, &wndPtr->rectWindow );
210 WIN_SetStyle( hwnd, wndPtr->dwStyle & ~WS_VISIBLE );
212 WIN_ReleaseWndPtr( wndPtr );
215 /***********************************************************************
216 * DEFWND_Print
218 * This method handles the default behavior for the WM_PRINT message.
220 static void DEFWND_Print( HWND hwnd, HDC hdc, ULONG uFlags)
223 * Visibility flag.
225 if ( (uFlags & PRF_CHECKVISIBLE) &&
226 !IsWindowVisible(hwnd) )
227 return;
230 * Unimplemented flags.
232 if ( (uFlags & PRF_CHILDREN) ||
233 (uFlags & PRF_OWNED) ||
234 (uFlags & PRF_NONCLIENT) )
236 WARN("WM_PRINT message with unsupported flags\n");
240 * Background
242 if ( uFlags & PRF_ERASEBKGND)
243 SendMessageW(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
246 * Client area
248 if ( uFlags & PRF_CLIENT)
249 SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
254 * helpers for calling IMM32
256 * WM_IME_* messages are generated only by IMM32,
257 * so I assume imm32 is already LoadLibrary-ed.
259 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
261 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
262 HWND (WINAPI *pFunc)(HWND);
263 HWND hwndRet = 0;
265 if (!hInstIMM)
267 ERR( "cannot get IMM32 handle\n" );
268 return 0;
271 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
272 if ( pFunc != NULL )
273 hwndRet = (*pFunc)( hwnd );
275 return hwndRet;
278 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
280 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
281 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
282 BOOL fRet = FALSE;
284 if (!hInstIMM)
286 ERR( "cannot get IMM32 handle\n" );
287 return FALSE;
290 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
291 if ( pFunc != NULL )
292 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
294 return fRet;
297 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
299 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
300 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
301 BOOL fRet = FALSE;
303 if (!hInstIMM)
305 ERR( "cannot get IMM32 handle\n" );
306 return FALSE;
309 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
310 if ( pFunc != NULL )
311 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
313 return fRet;
318 /***********************************************************************
319 * DEFWND_DefWinProc
321 * Default window procedure for messages that are the same in Win16 and Win32.
323 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
325 switch(msg)
327 case WM_NCPAINT:
328 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
330 case WM_NCHITTEST:
332 POINT pt;
333 pt.x = (short)LOWORD(lParam);
334 pt.y = (short)HIWORD(lParam);
335 return NC_HandleNCHitTest( hwnd, pt );
338 case WM_NCLBUTTONDOWN:
339 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
341 case WM_LBUTTONDBLCLK:
342 case WM_NCLBUTTONDBLCLK:
343 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
345 case WM_NCRBUTTONDOWN:
346 /* in Windows, capture is taken when right-clicking on the caption bar */
347 if (wParam==HTCAPTION)
349 SetCapture(hwnd);
351 break;
353 case WM_RBUTTONUP:
355 POINT pt;
357 if (hwnd == GetCapture())
358 /* release capture if we took it on WM_NCRBUTTONDOWN */
359 ReleaseCapture();
361 pt.x = (short)LOWORD(lParam);
362 pt.y = (short)HIWORD(lParam);
363 ClientToScreen(hwnd, &pt);
364 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
366 break;
368 case WM_NCRBUTTONUP:
370 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
371 * in Windows), but what _should_ we do? According to MSDN :
372 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
373 * message to the window". When is it appropriate?
375 break;
377 case WM_CONTEXTMENU:
378 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
379 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
380 else
382 LONG hitcode;
383 POINT pt;
384 WND *wndPtr = WIN_GetPtr( hwnd );
385 HMENU hMenu = wndPtr->hSysMenu;
386 WIN_ReleasePtr( wndPtr );
387 if (!hMenu) return 0;
388 pt.x = (short)LOWORD(lParam);
389 pt.y = (short)HIWORD(lParam);
390 hitcode = NC_HandleNCHitTest(hwnd, pt);
392 /* Track system popup if click was in the caption area. */
393 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
394 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
395 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
396 pt.x, pt.y, 0, hwnd, NULL);
398 break;
400 case WM_NCACTIVATE:
401 return NC_HandleNCActivate( hwnd, wParam );
403 case WM_NCDESTROY:
405 WND *wndPtr = WIN_GetPtr( hwnd );
406 if (!wndPtr) return 0;
407 if (wndPtr->text) HeapFree( GetProcessHeap(), 0, wndPtr->text );
408 wndPtr->text = NULL;
409 if (wndPtr->pVScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll );
410 if (wndPtr->pHScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll );
411 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
412 WIN_ReleasePtr( wndPtr );
413 return 0;
416 case WM_PRINT:
417 DEFWND_Print(hwnd, (HDC)wParam, lParam);
418 return 0;
420 case WM_PAINTICON:
421 case WM_PAINT:
423 PAINTSTRUCT ps;
424 HDC hdc = BeginPaint( hwnd, &ps );
425 if( hdc )
427 HICON hIcon;
428 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongW( hwnd, GCL_HICON))) )
430 RECT rc;
431 int x, y;
433 GetClientRect( hwnd, &rc );
434 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
435 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
436 TRACE("Painting class icon: vis rect=(%ld,%ld - %ld,%ld)\n",
437 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
438 DrawIcon( hdc, x, y, hIcon );
440 EndPaint( hwnd, &ps );
442 return 0;
445 case WM_SYNCPAINT:
446 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
447 return 0;
449 case WM_SETREDRAW:
450 DEFWND_SetRedraw( hwnd, wParam );
451 return 0;
453 case WM_CLOSE:
454 DestroyWindow( hwnd );
455 return 0;
457 case WM_MOUSEACTIVATE:
458 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
460 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
461 if (ret) return ret;
464 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
465 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
467 case WM_ACTIVATE:
468 /* The default action in Windows is to set the keyboard focus to
469 * the window, if it's being activated and not minimized */
470 if (LOWORD(wParam) != WA_INACTIVE) {
471 if (!IsIconic(hwnd)) SetFocus(hwnd);
473 break;
475 case WM_MOUSEWHEEL:
476 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
477 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
478 break;
480 case WM_ERASEBKGND:
481 case WM_ICONERASEBKGND:
483 RECT rect;
484 HDC hdc = (HDC)wParam;
485 HBRUSH hbr = (HBRUSH)GetClassLongW( hwnd, GCL_HBRBACKGROUND );
486 if (!hbr) return 0;
488 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
490 /* can't use GetClipBox with a parent DC or we fill the whole parent */
491 GetClientRect( hwnd, &rect );
492 DPtoLP( hdc, (LPPOINT)&rect, 2 );
494 else GetClipBox( hdc, &rect );
495 FillRect( hdc, &rect, hbr );
496 return 1;
499 case WM_GETDLGCODE:
500 return 0;
502 case WM_CTLCOLORMSGBOX:
503 case WM_CTLCOLOREDIT:
504 case WM_CTLCOLORLISTBOX:
505 case WM_CTLCOLORBTN:
506 case WM_CTLCOLORDLG:
507 case WM_CTLCOLORSTATIC:
508 case WM_CTLCOLORSCROLLBAR:
509 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
511 case WM_CTLCOLOR:
512 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
514 case WM_SETCURSOR:
515 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
517 /* with the exception of the border around a resizable wnd,
518 * give the parent first chance to set the cursor */
519 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
521 if (SendMessageW(GetParent(hwnd), WM_SETCURSOR, wParam, lParam)) return TRUE;
524 NC_HandleSetCursor( hwnd, wParam, lParam );
525 break;
527 case WM_SYSCOMMAND:
528 return NC_HandleSysCommand( hwnd, wParam, lParam );
530 case WM_KEYDOWN:
531 if(wParam == VK_F10) iF10Key = VK_F10;
532 break;
534 case WM_SYSKEYDOWN:
535 if( HIWORD(lParam) & KEYDATA_ALT )
537 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
538 if( wParam == VK_MENU && !iMenuSysKey )
539 iMenuSysKey = 1;
540 else
541 iMenuSysKey = 0;
543 iF10Key = 0;
545 if( wParam == VK_F4 ) /* try to close the window */
547 HWND top = GetAncestor( hwnd, GA_ROOT );
548 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
549 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
552 else if( wParam == VK_F10 )
553 iF10Key = 1;
554 else
555 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
556 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
557 break;
559 case WM_KEYUP:
560 case WM_SYSKEYUP:
561 /* Press and release F10 or ALT */
562 if (((wParam == VK_MENU) && iMenuSysKey) ||
563 ((wParam == VK_F10) && iF10Key))
564 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
565 iMenuSysKey = iF10Key = 0;
566 break;
568 case WM_SYSCHAR:
570 iMenuSysKey = 0;
571 if (wParam == '\r' && IsIconic(hwnd))
573 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
574 break;
576 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
578 if (wParam == '\t' || wParam == '\x1b') break;
579 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
580 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
581 else
582 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
584 else /* check for Ctrl-Esc */
585 if (wParam != '\x1b') MessageBeep(0);
586 break;
589 case WM_SHOWWINDOW:
591 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
592 if (!lParam) return 0; /* sent from ShowWindow */
593 if (!(style & WS_POPUP)) return 0;
594 if ((style & WS_VISIBLE) && wParam) return 0;
595 if (!(style & WS_VISIBLE) && !wParam) return 0;
596 if (!GetWindow( hwnd, GW_OWNER )) return 0;
597 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
598 break;
601 case WM_CANCELMODE:
602 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
603 if (GetCapture() == hwnd) ReleaseCapture();
604 break;
606 case WM_VKEYTOITEM:
607 case WM_CHARTOITEM:
608 return -1;
610 case WM_DROPOBJECT:
611 return DRAG_FILE;
613 case WM_QUERYDROPOBJECT:
614 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
616 case WM_QUERYDRAGICON:
618 UINT len;
620 HICON hIcon = (HICON)GetClassLongW( hwnd, GCL_HICON );
621 HINSTANCE instance = (HINSTANCE)GetWindowLongW( hwnd, GWL_HINSTANCE );
622 if (hIcon) return (LRESULT)hIcon;
623 for(len=1; len<64; len++)
624 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
625 return (LRESULT)hIcon;
626 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
628 break;
630 case WM_ISACTIVEICON:
632 WND *wndPtr = WIN_GetPtr( hwnd );
633 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
634 WIN_ReleasePtr( wndPtr );
635 return ret;
638 case WM_NOTIFYFORMAT:
639 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
640 else return NFR_ANSI;
642 case WM_QUERYOPEN:
643 case WM_QUERYENDSESSION:
644 return 1;
646 case WM_SETICON:
648 HICON ret;
649 WND *wndPtr = WIN_GetPtr( hwnd );
651 switch(wParam)
653 case ICON_SMALL:
654 ret = wndPtr->hIconSmall;
655 wndPtr->hIconSmall = (HICON)lParam;
656 break;
657 case ICON_BIG:
658 ret = wndPtr->hIcon;
659 wndPtr->hIcon = (HICON)lParam;
660 break;
661 default:
662 ret = 0;
663 break;
665 WIN_ReleasePtr( wndPtr );
667 if (USER_Driver.pSetWindowIcon)
668 USER_Driver.pSetWindowIcon( hwnd, wParam, (HICON)lParam );
670 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE |
671 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
673 return (LRESULT)ret;
676 case WM_GETICON:
678 HICON ret;
679 WND *wndPtr = WIN_GetPtr( hwnd );
681 switch(wParam)
683 case ICON_SMALL:
684 ret = wndPtr->hIconSmall;
685 break;
686 case ICON_BIG:
687 ret = wndPtr->hIcon;
688 break;
689 case ICON_SMALL2:
690 ret = wndPtr->hIconSmall;
691 if (!ret) ret = (HICON)GetClassLongA( hwnd, GCL_HICONSM );
692 /* FIXME: should have a default here if class icon is null */
693 break;
694 default:
695 ret = 0;
696 break;
698 WIN_ReleasePtr( wndPtr );
699 return (LRESULT)ret;
702 case WM_HELP:
703 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
704 break;
707 return 0;
712 /***********************************************************************
713 * DefWindowProc (USER.107)
715 LRESULT WINAPI DefWindowProc16( HWND16 hwnd16, UINT16 msg, WPARAM16 wParam,
716 LPARAM lParam )
718 LRESULT result = 0;
719 HWND hwnd = WIN_Handle32( hwnd16 );
721 if (!WIN_IsCurrentProcess( hwnd ))
723 if (!IsWindow( hwnd )) return 0;
724 ERR( "called for other process window %p\n", hwnd );
725 return 0;
727 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
729 switch(msg)
731 case WM_NCCREATE:
733 CREATESTRUCT16 *cs = MapSL(lParam);
734 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
735 * may have child window IDs instead of window name */
736 if (HIWORD(cs->lpszName))
737 DEFWND_SetTextA( hwnd, MapSL(cs->lpszName) );
738 result = 1;
740 break;
742 case WM_NCCALCSIZE:
744 RECT rect32;
745 CONV_RECT16TO32( MapSL(lParam), &rect32 );
746 result = NC_HandleNCCalcSize( hwnd, &rect32 );
747 CONV_RECT32TO16( &rect32, MapSL(lParam) );
749 break;
751 case WM_WINDOWPOSCHANGING:
752 result = WINPOS_HandleWindowPosChanging16( hwnd, MapSL(lParam) );
753 break;
755 case WM_WINDOWPOSCHANGED:
757 WINDOWPOS16 * winPos = MapSL(lParam);
758 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
760 break;
762 case WM_GETTEXT:
763 case WM_SETTEXT:
764 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)MapSL(lParam) );
765 break;
767 default:
768 result = DefWindowProcA( hwnd, msg, wParam, lParam );
769 break;
772 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result, wParam, lParam );
773 return result;
777 /***********************************************************************
778 * DefWindowProcA (USER32.@)
781 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
783 LRESULT result = 0;
784 HWND full_handle;
786 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
788 if (!IsWindow( hwnd )) return 0;
789 ERR( "called for other process window %p\n", hwnd );
790 return 0;
792 hwnd = full_handle;
794 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
796 switch(msg)
798 case WM_NCCREATE:
800 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
801 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
802 * may have child window IDs instead of window name */
803 if (HIWORD(cs->lpszName))
804 DEFWND_SetTextA( hwnd, cs->lpszName );
805 result = 1;
807 break;
809 case WM_NCCALCSIZE:
810 result = NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
811 break;
813 case WM_WINDOWPOSCHANGING:
814 result = WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
815 break;
817 case WM_WINDOWPOSCHANGED:
819 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
820 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
822 break;
824 case WM_GETTEXTLENGTH:
826 WND *wndPtr = WIN_GetPtr( hwnd );
827 if (wndPtr && wndPtr->text)
828 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
829 NULL, 0, NULL, NULL );
830 WIN_ReleasePtr( wndPtr );
832 break;
834 case WM_GETTEXT:
835 if (wParam)
837 LPSTR dest = (LPSTR)lParam;
838 WND *wndPtr = WIN_GetPtr( hwnd );
840 if (!wndPtr) break;
841 if (wndPtr->text)
843 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
844 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
845 result = strlen( dest );
847 else dest[0] = '\0';
848 WIN_ReleasePtr( wndPtr );
850 break;
852 case WM_SETTEXT:
853 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
854 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
855 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
856 result = 1; /* success. FIXME: check text length */
857 break;
859 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
860 case WM_IME_CHAR:
862 CHAR chChar1 = (CHAR)( (wParam>>8) & 0xff );
863 CHAR chChar2 = (CHAR)( wParam & 0xff );
865 if (chChar1)
866 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar1, lParam );
867 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar2, lParam );
869 break;
870 case WM_IME_KEYDOWN:
871 result = SendMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
872 break;
873 case WM_IME_KEYUP:
874 result = SendMessageA( hwnd, WM_KEYUP, wParam, lParam );
875 break;
877 case WM_IME_STARTCOMPOSITION:
878 case WM_IME_COMPOSITION:
879 case WM_IME_ENDCOMPOSITION:
880 case WM_IME_SELECT:
882 HWND hwndIME;
884 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
885 if (hwndIME)
886 result = SendMessageA( hwndIME, msg, wParam, lParam );
888 break;
889 case WM_IME_SETCONTEXT:
891 HWND hwndIME;
893 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
894 if (hwndIME)
895 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
897 break;
899 case WM_INPUTLANGCHANGEREQUEST:
900 /* notify about the switch only if it's really our current layout */
901 if ((HKL)lParam == GetKeyboardLayout(0))
902 result = SendMessageA( hwnd, WM_INPUTLANGCHANGE, wParam, lParam );
903 else
904 result = 0;
905 break;
907 case WM_SYSCHAR:
909 BYTE ch = LOWORD(wParam);
910 WCHAR wch;
911 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
912 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
914 /* fall through */
915 default:
916 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
917 break;
920 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
921 return result;
925 /***********************************************************************
926 * DefWindowProcW (USER32.@) Calls default window message handler
928 * Calls default window procedure for messages not processed
929 * by application.
931 * RETURNS
932 * Return value is dependent upon the message.
934 LRESULT WINAPI DefWindowProcW(
935 HWND hwnd, /* [in] window procedure receiving message */
936 UINT msg, /* [in] message identifier */
937 WPARAM wParam, /* [in] first message parameter */
938 LPARAM lParam ) /* [in] second message parameter */
940 LRESULT result = 0;
941 HWND full_handle;
943 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
945 if (!IsWindow( hwnd )) return 0;
946 ERR( "called for other process window %p\n", hwnd );
947 return 0;
949 hwnd = full_handle;
950 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
952 switch(msg)
954 case WM_NCCREATE:
956 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
957 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
958 * may have child window IDs instead of window name */
959 if (HIWORD(cs->lpszName))
960 DEFWND_SetTextW( hwnd, cs->lpszName );
961 result = 1;
963 break;
965 case WM_NCCALCSIZE:
966 result = NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
967 break;
969 case WM_WINDOWPOSCHANGING:
970 result = WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
971 break;
973 case WM_WINDOWPOSCHANGED:
975 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
976 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
978 break;
980 case WM_GETTEXTLENGTH:
982 WND *wndPtr = WIN_GetPtr( hwnd );
983 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
984 WIN_ReleasePtr( wndPtr );
986 break;
988 case WM_GETTEXT:
989 if (wParam)
991 LPWSTR dest = (LPWSTR)lParam;
992 WND *wndPtr = WIN_GetPtr( hwnd );
994 if (!wndPtr) break;
995 if (wndPtr->text)
997 lstrcpynW( dest, wndPtr->text, wParam );
998 result = strlenW( dest );
1000 else dest[0] = '\0';
1001 WIN_ReleasePtr( wndPtr );
1003 break;
1005 case WM_SETTEXT:
1006 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
1007 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
1008 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
1009 result = 1; /* success. FIXME: check text length */
1010 break;
1012 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
1013 case WM_IME_CHAR:
1014 SendMessageW( hwnd, WM_CHAR, wParam, lParam );
1015 break;
1016 case WM_IME_SETCONTEXT:
1018 HWND hwndIME;
1020 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1021 if (hwndIME)
1022 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
1024 break;
1026 case WM_INPUTLANGCHANGEREQUEST:
1027 /* notify about the switch only if it's really our current layout */
1028 if ((HKL)lParam == GetKeyboardLayout(0))
1029 result = SendMessageW( hwnd, WM_INPUTLANGCHANGE, wParam, lParam );
1030 else
1031 result = 0;
1032 break;
1034 default:
1035 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1036 break;
1038 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
1039 return result;