Get rid of nonclient.h and of the corresponding exported functions in
[wine.git] / windows / defwnd.c
bloba6e23af401fd9d13926458d2d70ff41c6f504d71
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>
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 "winpos.h"
37 #include "message.h"
38 #include "wine/unicode.h"
39 #include "wine/winuser16.h"
40 #include "wine/server.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(win);
45 /* bits in the dwKeyData */
46 #define KEYDATA_ALT 0x2000
47 #define KEYDATA_PREVSTATE 0x4000
49 static short iF10Key = 0;
50 static short iMenuSysKey = 0;
51 static const WCHAR imm32W[] = { 'i','m','m','3','2','\0' };
53 /***********************************************************************
54 * DEFWND_HandleWindowPosChanged
56 * Handle the WM_WINDOWPOSCHANGED message.
58 static void DEFWND_HandleWindowPosChanged( HWND hwnd, UINT flags )
60 RECT rect;
61 WND *wndPtr = WIN_GetPtr( hwnd );
63 rect = wndPtr->rectClient;
64 WIN_ReleasePtr( wndPtr );
66 if (!(flags & SWP_NOCLIENTMOVE))
67 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG(rect.left, rect.top));
69 if (!(flags & SWP_NOCLIENTSIZE))
71 WPARAM wp = SIZE_RESTORED;
72 if (IsZoomed(hwnd)) wp = SIZE_MAXIMIZED;
73 else if (IsIconic(hwnd)) wp = SIZE_MINIMIZED;
75 SendMessageW( hwnd, WM_SIZE, wp, MAKELONG(rect.right-rect.left, rect.bottom-rect.top) );
80 /***********************************************************************
81 * DEFWND_SetTextA
83 * Set the window text.
85 static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
87 int count;
88 WCHAR *textW;
89 WND *wndPtr;
91 if (!text) text = "";
92 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
94 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
95 if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
97 HeapFree(GetProcessHeap(), 0, wndPtr->text);
98 wndPtr->text = textW;
99 MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
100 SERVER_START_REQ( set_window_text )
102 req->handle = hwnd;
103 wine_server_add_data( req, textW, (count-1) * sizeof(WCHAR) );
104 wine_server_call( req );
106 SERVER_END_REQ;
108 else
109 ERR("Not enough memory for window text\n");
110 WIN_ReleasePtr( wndPtr );
112 if (USER_Driver.pSetWindowText) USER_Driver.pSetWindowText( hwnd, textW );
115 /***********************************************************************
116 * DEFWND_SetTextW
118 * Set the window text.
120 static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
122 static const WCHAR empty_string[] = {0};
123 WND *wndPtr;
124 int count;
126 if (!text) text = empty_string;
127 count = strlenW(text) + 1;
129 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
130 HeapFree(GetProcessHeap(), 0, wndPtr->text);
131 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
133 strcpyW( wndPtr->text, text );
134 SERVER_START_REQ( set_window_text )
136 req->handle = hwnd;
137 wine_server_add_data( req, wndPtr->text, (count-1) * sizeof(WCHAR) );
138 wine_server_call( req );
140 SERVER_END_REQ;
142 else
143 ERR("Not enough memory for window text\n");
144 text = wndPtr->text;
145 WIN_ReleasePtr( wndPtr );
147 if (USER_Driver.pSetWindowText) USER_Driver.pSetWindowText( hwnd, text );
150 /***********************************************************************
151 * DEFWND_ControlColor
153 * Default colors for control painting.
155 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
157 if( ctlType == CTLCOLOR_SCROLLBAR)
159 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
160 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
161 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
162 SetBkColor( hDC, bk);
164 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
165 * we better use 0x55aa bitmap brush to make scrollbar's background
166 * look different from the window background.
168 if (bk == GetSysColor(COLOR_WINDOW))
169 return UITOOLS_GetPattern55AABrush();
171 UnrealizeObject( hb );
172 return hb;
175 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
177 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
178 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
179 else {
180 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
181 return GetSysColorBrush(COLOR_3DFACE);
183 return GetSysColorBrush(COLOR_WINDOW);
187 /***********************************************************************
188 * DEFWND_SetRedraw
190 static void DEFWND_SetRedraw( HWND hwnd, WPARAM wParam )
192 WND *wndPtr = WIN_FindWndPtr( hwnd );
193 BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
195 TRACE("%p %i\n", hwnd, (wParam!=0) );
197 if( wParam )
199 if( !bVisible )
201 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_VISIBLE );
204 else if( bVisible )
206 if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
207 else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
209 RedrawWindow( hwnd, NULL, 0, wParam );
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 = GetModuleHandleW( imm32W );
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 = GetModuleHandleW( imm32W );
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 = GetModuleHandleW( imm32W );
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_LBUTTONDOWN:
339 case WM_RBUTTONDOWN:
340 case WM_MBUTTONDOWN:
341 iF10Key = iMenuSysKey = 0;
342 break;
344 case WM_NCLBUTTONDOWN:
345 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
347 case WM_LBUTTONDBLCLK:
348 case WM_NCLBUTTONDBLCLK:
349 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
351 case WM_NCRBUTTONDOWN:
352 /* in Windows, capture is taken when right-clicking on the caption bar */
353 if (wParam==HTCAPTION)
355 SetCapture(hwnd);
357 break;
359 case WM_RBUTTONUP:
361 POINT pt;
363 if (hwnd == GetCapture())
364 /* release capture if we took it on WM_NCRBUTTONDOWN */
365 ReleaseCapture();
367 pt.x = (short)LOWORD(lParam);
368 pt.y = (short)HIWORD(lParam);
369 ClientToScreen(hwnd, &pt);
370 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
372 break;
374 case WM_NCRBUTTONUP:
376 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
377 * in Windows), but what _should_ we do? According to MSDN :
378 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
379 * message to the window". When is it appropriate?
381 break;
383 case WM_CONTEXTMENU:
384 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
385 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
386 else
388 LONG hitcode;
389 POINT pt;
390 WND *wndPtr = WIN_GetPtr( hwnd );
391 HMENU hMenu = wndPtr->hSysMenu;
392 WIN_ReleasePtr( wndPtr );
393 if (!hMenu) return 0;
394 pt.x = (short)LOWORD(lParam);
395 pt.y = (short)HIWORD(lParam);
396 hitcode = NC_HandleNCHitTest(hwnd, pt);
398 /* Track system popup if click was in the caption area. */
399 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
400 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
401 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
402 pt.x, pt.y, 0, hwnd, NULL);
404 break;
406 case WM_NCACTIVATE:
407 return NC_HandleNCActivate( hwnd, wParam );
409 case WM_NCDESTROY:
411 WND *wndPtr = WIN_GetPtr( hwnd );
412 if (!wndPtr) return 0;
413 HeapFree( GetProcessHeap(), 0, wndPtr->text );
414 wndPtr->text = NULL;
415 HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll );
416 HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll );
417 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
418 WIN_ReleasePtr( wndPtr );
419 return 0;
422 case WM_PRINT:
423 DEFWND_Print(hwnd, (HDC)wParam, lParam);
424 return 0;
426 case WM_PAINTICON:
427 case WM_PAINT:
429 PAINTSTRUCT ps;
430 HDC hdc = BeginPaint( hwnd, &ps );
431 if( hdc )
433 HICON hIcon;
434 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongW( hwnd, GCL_HICON))) )
436 RECT rc;
437 int x, y;
439 GetClientRect( hwnd, &rc );
440 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
441 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
442 TRACE("Painting class icon: vis rect=(%ld,%ld - %ld,%ld)\n",
443 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
444 DrawIcon( hdc, x, y, hIcon );
446 EndPaint( hwnd, &ps );
448 return 0;
451 case WM_SYNCPAINT:
452 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
453 return 0;
455 case WM_SETREDRAW:
456 DEFWND_SetRedraw( hwnd, wParam );
457 return 0;
459 case WM_CLOSE:
460 DestroyWindow( hwnd );
461 return 0;
463 case WM_MOUSEACTIVATE:
464 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
466 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
467 if (ret) return ret;
470 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
471 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
473 case WM_ACTIVATE:
474 /* The default action in Windows is to set the keyboard focus to
475 * the window, if it's being activated and not minimized */
476 if (LOWORD(wParam) != WA_INACTIVE) {
477 if (!IsIconic(hwnd)) SetFocus(hwnd);
479 break;
481 case WM_MOUSEWHEEL:
482 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
483 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
484 break;
486 case WM_ERASEBKGND:
487 case WM_ICONERASEBKGND:
489 RECT rect;
490 HDC hdc = (HDC)wParam;
491 HBRUSH hbr = (HBRUSH)GetClassLongW( hwnd, GCL_HBRBACKGROUND );
492 if (!hbr) return 0;
494 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
496 /* can't use GetClipBox with a parent DC or we fill the whole parent */
497 GetClientRect( hwnd, &rect );
498 DPtoLP( hdc, (LPPOINT)&rect, 2 );
500 else GetClipBox( hdc, &rect );
501 FillRect( hdc, &rect, hbr );
502 return 1;
505 case WM_GETDLGCODE:
506 return 0;
508 case WM_CTLCOLORMSGBOX:
509 case WM_CTLCOLOREDIT:
510 case WM_CTLCOLORLISTBOX:
511 case WM_CTLCOLORBTN:
512 case WM_CTLCOLORDLG:
513 case WM_CTLCOLORSTATIC:
514 case WM_CTLCOLORSCROLLBAR:
515 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
517 case WM_CTLCOLOR:
518 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
520 case WM_SETCURSOR:
521 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
523 /* with the exception of the border around a resizable wnd,
524 * give the parent first chance to set the cursor */
525 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
527 if (SendMessageW(GetParent(hwnd), WM_SETCURSOR, wParam, lParam)) return TRUE;
530 NC_HandleSetCursor( hwnd, wParam, lParam );
531 break;
533 case WM_SYSCOMMAND:
534 return NC_HandleSysCommand( hwnd, wParam, lParam );
536 case WM_KEYDOWN:
537 if(wParam == VK_F10) iF10Key = VK_F10;
538 break;
540 case WM_SYSKEYDOWN:
541 if( HIWORD(lParam) & KEYDATA_ALT )
543 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
544 if( wParam == VK_MENU && !iMenuSysKey )
545 iMenuSysKey = 1;
546 else
547 iMenuSysKey = 0;
549 iF10Key = 0;
551 if( wParam == VK_F4 ) /* try to close the window */
553 HWND top = GetAncestor( hwnd, GA_ROOT );
554 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
555 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
558 else if( wParam == VK_F10 )
559 iF10Key = 1;
560 else if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
561 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
562 break;
564 case WM_KEYUP:
565 case WM_SYSKEYUP:
566 /* Press and release F10 or ALT */
567 if (((wParam == VK_MENU) && iMenuSysKey) ||
568 ((wParam == VK_F10) && iF10Key))
569 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
570 iMenuSysKey = iF10Key = 0;
571 break;
573 case WM_SYSCHAR:
575 iMenuSysKey = 0;
576 if (wParam == '\r' && IsIconic(hwnd))
578 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
579 break;
581 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
583 if (wParam == '\t' || wParam == '\x1b') break;
584 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
585 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
586 else
587 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
589 else /* check for Ctrl-Esc */
590 if (wParam != '\x1b') MessageBeep(0);
591 break;
594 case WM_SHOWWINDOW:
596 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
597 if (!lParam) return 0; /* sent from ShowWindow */
598 if (!(style & WS_POPUP)) return 0;
599 if ((style & WS_VISIBLE) && wParam) return 0;
600 if (!(style & WS_VISIBLE) && !wParam) return 0;
601 if (!GetWindow( hwnd, GW_OWNER )) return 0;
602 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
603 break;
606 case WM_CANCELMODE:
607 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
608 if (GetCapture() == hwnd) ReleaseCapture();
609 break;
611 case WM_VKEYTOITEM:
612 case WM_CHARTOITEM:
613 return -1;
615 case WM_DROPOBJECT:
616 return DRAG_FILE;
618 case WM_QUERYDROPOBJECT:
619 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
621 case WM_QUERYDRAGICON:
623 UINT len;
625 HICON hIcon = (HICON)GetClassLongW( hwnd, GCL_HICON );
626 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
627 if (hIcon) return (LRESULT)hIcon;
628 for(len=1; len<64; len++)
629 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
630 return (LRESULT)hIcon;
631 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
633 break;
635 case WM_ISACTIVEICON:
637 WND *wndPtr = WIN_GetPtr( hwnd );
638 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
639 WIN_ReleasePtr( wndPtr );
640 return ret;
643 case WM_NOTIFYFORMAT:
644 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
645 else return NFR_ANSI;
647 case WM_QUERYOPEN:
648 case WM_QUERYENDSESSION:
649 return 1;
651 case WM_SETICON:
653 HICON ret;
654 WND *wndPtr = WIN_GetPtr( hwnd );
656 switch(wParam)
658 case ICON_SMALL:
659 ret = wndPtr->hIconSmall;
660 wndPtr->hIconSmall = (HICON)lParam;
661 break;
662 case ICON_BIG:
663 ret = wndPtr->hIcon;
664 wndPtr->hIcon = (HICON)lParam;
665 break;
666 default:
667 ret = 0;
668 break;
670 WIN_ReleasePtr( wndPtr );
672 if (USER_Driver.pSetWindowIcon)
673 USER_Driver.pSetWindowIcon( hwnd, wParam, (HICON)lParam );
675 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE |
676 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
678 return (LRESULT)ret;
681 case WM_GETICON:
683 HICON ret;
684 WND *wndPtr = WIN_GetPtr( hwnd );
686 switch(wParam)
688 case ICON_SMALL:
689 ret = wndPtr->hIconSmall;
690 break;
691 case ICON_BIG:
692 ret = wndPtr->hIcon;
693 break;
694 case ICON_SMALL2:
695 ret = wndPtr->hIconSmall;
696 if (!ret) ret = (HICON)GetClassLongA( hwnd, GCL_HICONSM );
697 /* FIXME: should have a default here if class icon is null */
698 break;
699 default:
700 ret = 0;
701 break;
703 WIN_ReleasePtr( wndPtr );
704 return (LRESULT)ret;
707 case WM_HELP:
708 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
709 break;
712 return 0;
717 /***********************************************************************
718 * DefWindowProc (USER.107)
720 LRESULT WINAPI DefWindowProc16( HWND16 hwnd16, UINT16 msg, WPARAM16 wParam,
721 LPARAM lParam )
723 LRESULT result = 0;
724 HWND hwnd = WIN_Handle32( hwnd16 );
726 if (!WIN_IsCurrentProcess( hwnd ))
728 if (!IsWindow( hwnd )) return 0;
729 ERR( "called for other process window %p\n", hwnd );
730 return 0;
732 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
734 switch(msg)
736 case WM_NCCREATE:
738 CREATESTRUCT16 *cs = MapSL(lParam);
739 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
740 * may have child window IDs instead of window name */
741 if (HIWORD(cs->lpszName))
742 DEFWND_SetTextA( hwnd, MapSL(cs->lpszName) );
743 result = 1;
745 break;
747 case WM_NCCALCSIZE:
749 RECT rect32;
750 RECT16 *rect16 = MapSL(lParam);
752 rect32.left = rect16->left;
753 rect32.top = rect16->top;
754 rect32.right = rect16->right;
755 rect32.bottom = rect16->bottom;
756 result = NC_HandleNCCalcSize( hwnd, &rect32 );
757 rect16->left = rect32.left;
758 rect16->top = rect32.top;
759 rect16->right = rect32.right;
760 rect16->bottom = rect32.bottom;
762 break;
764 case WM_WINDOWPOSCHANGING:
765 result = WINPOS_HandleWindowPosChanging16( hwnd, MapSL(lParam) );
766 break;
768 case WM_WINDOWPOSCHANGED:
770 WINDOWPOS16 * winPos = MapSL(lParam);
771 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
773 break;
775 case WM_GETTEXT:
776 case WM_SETTEXT:
777 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)MapSL(lParam) );
778 break;
780 default:
781 result = DefWindowProcA( hwnd, msg, wParam, lParam );
782 break;
785 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result, wParam, lParam );
786 return result;
790 /***********************************************************************
791 * DefWindowProcA (USER32.@)
794 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
796 LRESULT result = 0;
797 HWND full_handle;
799 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
801 if (!IsWindow( hwnd )) return 0;
802 ERR( "called for other process window %p\n", hwnd );
803 return 0;
805 hwnd = full_handle;
807 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
809 switch(msg)
811 case WM_NCCREATE:
813 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
814 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
815 * may have child window IDs instead of window name */
816 if (HIWORD(cs->lpszName))
817 DEFWND_SetTextA( hwnd, cs->lpszName );
818 result = 1;
820 break;
822 case WM_NCCALCSIZE:
823 result = NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
824 break;
826 case WM_WINDOWPOSCHANGING:
827 result = WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
828 break;
830 case WM_WINDOWPOSCHANGED:
832 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
833 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
835 break;
837 case WM_GETTEXTLENGTH:
839 WND *wndPtr = WIN_GetPtr( hwnd );
840 if (wndPtr && wndPtr->text)
841 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
842 NULL, 0, NULL, NULL );
843 WIN_ReleasePtr( wndPtr );
845 break;
847 case WM_GETTEXT:
848 if (wParam)
850 LPSTR dest = (LPSTR)lParam;
851 WND *wndPtr = WIN_GetPtr( hwnd );
853 if (!wndPtr) break;
854 if (wndPtr->text)
856 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
857 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
858 result = strlen( dest );
860 else dest[0] = '\0';
861 WIN_ReleasePtr( wndPtr );
863 break;
865 case WM_SETTEXT:
866 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
867 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
868 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
869 result = 1; /* success. FIXME: check text length */
870 break;
872 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
873 case WM_IME_CHAR:
875 CHAR chChar1 = (CHAR)( (wParam>>8) & 0xff );
876 CHAR chChar2 = (CHAR)( wParam & 0xff );
878 if (chChar1)
879 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar1, lParam );
880 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar2, lParam );
882 break;
883 case WM_IME_KEYDOWN:
884 result = SendMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
885 break;
886 case WM_IME_KEYUP:
887 result = SendMessageA( hwnd, WM_KEYUP, wParam, lParam );
888 break;
890 case WM_IME_STARTCOMPOSITION:
891 case WM_IME_COMPOSITION:
892 case WM_IME_ENDCOMPOSITION:
893 case WM_IME_SELECT:
895 HWND hwndIME;
897 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
898 if (hwndIME)
899 result = SendMessageA( hwndIME, msg, wParam, lParam );
901 break;
902 case WM_IME_SETCONTEXT:
904 HWND hwndIME;
906 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
907 if (hwndIME)
908 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
910 break;
912 case WM_INPUTLANGCHANGEREQUEST:
913 /* notify about the switch only if it's really our current layout */
914 if ((HKL)lParam == GetKeyboardLayout(0))
915 result = SendMessageA( hwnd, WM_INPUTLANGCHANGE, wParam, lParam );
916 else
917 result = 0;
918 break;
920 case WM_SYSCHAR:
922 BYTE ch = LOWORD(wParam);
923 WCHAR wch;
924 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
925 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
927 /* fall through */
928 default:
929 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
930 break;
933 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
934 return result;
938 /***********************************************************************
939 * DefWindowProcW (USER32.@) Calls default window message handler
941 * Calls default window procedure for messages not processed
942 * by application.
944 * RETURNS
945 * Return value is dependent upon the message.
947 LRESULT WINAPI DefWindowProcW(
948 HWND hwnd, /* [in] window procedure receiving message */
949 UINT msg, /* [in] message identifier */
950 WPARAM wParam, /* [in] first message parameter */
951 LPARAM lParam ) /* [in] second message parameter */
953 LRESULT result = 0;
954 HWND full_handle;
956 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
958 if (!IsWindow( hwnd )) return 0;
959 ERR( "called for other process window %p\n", hwnd );
960 return 0;
962 hwnd = full_handle;
963 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
965 switch(msg)
967 case WM_NCCREATE:
969 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
970 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
971 * may have child window IDs instead of window name */
972 if (HIWORD(cs->lpszName))
973 DEFWND_SetTextW( hwnd, cs->lpszName );
974 result = 1;
976 break;
978 case WM_NCCALCSIZE:
979 result = NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
980 break;
982 case WM_WINDOWPOSCHANGING:
983 result = WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
984 break;
986 case WM_WINDOWPOSCHANGED:
988 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
989 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
991 break;
993 case WM_GETTEXTLENGTH:
995 WND *wndPtr = WIN_GetPtr( hwnd );
996 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
997 WIN_ReleasePtr( wndPtr );
999 break;
1001 case WM_GETTEXT:
1002 if (wParam)
1004 LPWSTR dest = (LPWSTR)lParam;
1005 WND *wndPtr = WIN_GetPtr( hwnd );
1007 if (!wndPtr) break;
1008 if (wndPtr->text)
1010 lstrcpynW( dest, wndPtr->text, wParam );
1011 result = strlenW( dest );
1013 else dest[0] = '\0';
1014 WIN_ReleasePtr( wndPtr );
1016 break;
1018 case WM_SETTEXT:
1019 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
1020 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
1021 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
1022 result = 1; /* success. FIXME: check text length */
1023 break;
1025 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
1026 case WM_IME_CHAR:
1027 SendMessageW( hwnd, WM_CHAR, wParam, lParam );
1028 break;
1029 case WM_IME_SETCONTEXT:
1031 HWND hwndIME;
1033 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1034 if (hwndIME)
1035 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
1037 break;
1039 case WM_IME_STARTCOMPOSITION:
1040 case WM_IME_COMPOSITION:
1041 case WM_IME_ENDCOMPOSITION:
1042 case WM_IME_SELECT:
1044 HWND hwndIME;
1046 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1047 if (hwndIME)
1048 result = SendMessageW( hwndIME, msg, wParam, lParam );
1050 break;
1052 case WM_INPUTLANGCHANGEREQUEST:
1053 /* notify about the switch only if it's really our current layout */
1054 if ((HKL)lParam == GetKeyboardLayout(0))
1055 result = SendMessageW( hwnd, WM_INPUTLANGCHANGE, wParam, lParam );
1056 else
1057 result = 0;
1058 break;
1060 default:
1061 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1062 break;
1064 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
1065 return result;