Don't allow comctl32 controls to access their infoPtr before it has
[wine.git] / windows / defwnd.c
blobea42f41ede4d838927e19d4155834e1717bea38a
1 /*
2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
5 * 1995 Alex Korobka
6 */
8 #include <string.h>
10 #include "win.h"
11 #include "user.h"
12 #include "heap.h"
13 #include "nonclient.h"
14 #include "winpos.h"
15 #include "dce.h"
16 #include "debugtools.h"
17 #include "spy.h"
18 #include "windef.h"
19 #include "wingdi.h"
20 #include "winnls.h"
21 #include "wine/unicode.h"
22 #include "wine/winuser16.h"
23 #include "imm.h"
25 DEFAULT_DEBUG_CHANNEL(win);
27 /* bits in the dwKeyData */
28 #define KEYDATA_ALT 0x2000
29 #define KEYDATA_PREVSTATE 0x4000
31 static short iF10Key = 0;
32 static short iMenuSysKey = 0;
34 /***********************************************************************
35 * DEFWND_HandleWindowPosChanged
37 * Handle the WM_WINDOWPOSCHANGED message.
39 static void DEFWND_HandleWindowPosChanged( WND *wndPtr, UINT flags )
41 WPARAM wp = SIZE_RESTORED;
43 if (!(flags & SWP_NOCLIENTMOVE))
44 SendMessageW( wndPtr->hwndSelf, WM_MOVE, 0,
45 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top));
46 if (!(flags & SWP_NOCLIENTSIZE))
48 if (wndPtr->dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
49 else if (wndPtr->dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
51 SendMessageW( wndPtr->hwndSelf, WM_SIZE, wp,
52 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
53 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
58 /***********************************************************************
59 * DEFWND_SetTextA
61 * Set the window text.
63 void DEFWND_SetTextA( WND *wndPtr, LPCSTR text )
65 int count;
67 if (!text) text = "";
68 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
70 if (wndPtr->text) HeapFree(SystemHeap, 0, wndPtr->text);
71 if ((wndPtr->text = HeapAlloc(SystemHeap, 0, count * sizeof(WCHAR))))
72 MultiByteToWideChar( CP_ACP, 0, text, -1, wndPtr->text, count );
73 else
74 ERR("Not enough memory for window text");
76 wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
79 /***********************************************************************
80 * DEFWND_SetTextW
82 * Set the window text.
84 void DEFWND_SetTextW( WND *wndPtr, LPCWSTR text )
86 static const WCHAR empty_string[] = {0};
87 int count;
89 if (!text) text = empty_string;
90 count = strlenW(text) + 1;
92 if (wndPtr->text) HeapFree(SystemHeap, 0, wndPtr->text);
93 if ((wndPtr->text = HeapAlloc(SystemHeap, 0, count * sizeof(WCHAR))))
94 strcpyW( wndPtr->text, text );
95 else
96 ERR("Not enough memory for window text");
98 wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
101 /***********************************************************************
102 * DEFWND_ControlColor
104 * Default colors for control painting.
106 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
108 if( ctlType == CTLCOLOR_SCROLLBAR)
110 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
111 if (TWEAK_WineLook == WIN31_LOOK) {
112 SetTextColor( hDC, RGB(0, 0, 0) );
113 SetBkColor( hDC, RGB(255, 255, 255) );
114 } else {
115 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
116 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
117 SetBkColor( hDC, bk);
119 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
120 * we better use 0x55aa bitmap brush to make scrollbar's background
121 * look different from the window background.
123 if (bk == GetSysColor(COLOR_WINDOW)) {
124 return CACHE_GetPattern55AABrush();
127 UnrealizeObject( hb );
128 return hb;
131 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
133 if (TWEAK_WineLook > WIN31_LOOK) {
134 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
135 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
136 else {
137 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
138 return GetSysColorBrush(COLOR_3DFACE);
141 else
142 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
143 return GetSysColorBrush(COLOR_WINDOW);
147 /***********************************************************************
148 * DEFWND_SetRedraw
150 static void DEFWND_SetRedraw( WND* wndPtr, WPARAM wParam )
152 BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
154 TRACE("%04x %i\n", wndPtr->hwndSelf, (wParam!=0) );
156 if( wParam )
158 if( !bVisible )
160 wndPtr->dwStyle |= WS_VISIBLE;
161 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
164 else if( bVisible )
166 if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
167 else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
169 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, wParam, 0 );
170 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
171 wndPtr->dwStyle &= ~WS_VISIBLE;
175 /***********************************************************************
176 * DEFWND_Print
178 * This method handles the default behavior for the WM_PRINT message.
180 static void DEFWND_Print(
181 WND* wndPtr,
182 HDC hdc,
183 ULONG uFlags)
186 * Visibility flag.
188 if ( (uFlags & PRF_CHECKVISIBLE) &&
189 !IsWindowVisible(wndPtr->hwndSelf) )
190 return;
193 * Unimplemented flags.
195 if ( (uFlags & PRF_CHILDREN) ||
196 (uFlags & PRF_OWNED) ||
197 (uFlags & PRF_NONCLIENT) )
199 WARN("WM_PRINT message with unsupported flags\n");
203 * Background
205 if ( uFlags & PRF_ERASEBKGND)
206 SendMessageW(wndPtr->hwndSelf, WM_ERASEBKGND, (WPARAM)hdc, 0);
209 * Client area
211 if ( uFlags & PRF_CLIENT)
212 SendMessageW(wndPtr->hwndSelf, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
217 * helpers for calling IMM32
219 * WM_IME_* messages are generated only by IMM32,
220 * so I assume imm32 is already LoadLibrary-ed.
222 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
224 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
225 HWND (WINAPI* pFunc)(HWND);
226 HWND hwndRet = 0;
228 if (!hInstIMM)
230 ERR( "cannot get IMM32 handle\n" );
231 return 0;
234 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
235 if ( pFunc != NULL )
236 hwndRet = (*pFunc)( hwnd );
238 return hwndRet;
241 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
243 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
244 BOOL (WINAPI* pFunc)(HWND,UINT,WPARAM,LPARAM);
245 BOOL fRet = FALSE;
247 if (!hInstIMM)
249 ERR( "cannot get IMM32 handle\n" );
250 return FALSE;
253 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
254 if ( pFunc != NULL )
255 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
257 return fRet;
260 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
262 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
263 BOOL (WINAPI* pFunc)(HWND,UINT,WPARAM,LPARAM);
264 BOOL fRet = FALSE;
266 if (!hInstIMM)
268 ERR( "cannot get IMM32 handle\n" );
269 return FALSE;
272 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
273 if ( pFunc != NULL )
274 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
276 return fRet;
281 /***********************************************************************
282 * DEFWND_DefWinProc
284 * Default window procedure for messages that are the same in Win16 and Win32.
286 static LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT msg, WPARAM wParam,
287 LPARAM lParam, BOOL unicode )
289 LRESULT (WINAPI *pSendMessage)(HWND, UINT, WPARAM, LPARAM);
290 BOOL (WINAPI *pPostMessage)(HWND, UINT, WPARAM, LPARAM);
292 pSendMessage = unicode ? SendMessageW : SendMessageA;
293 pPostMessage = unicode ? PostMessageW : PostMessageA;
295 switch(msg)
297 case WM_NCPAINT:
298 return NC_HandleNCPaint( wndPtr->hwndSelf, (HRGN)wParam );
300 case WM_NCHITTEST:
302 POINT pt;
303 pt.x = SLOWORD(lParam);
304 pt.y = SHIWORD(lParam);
305 return NC_HandleNCHitTest( wndPtr->hwndSelf, pt );
308 case WM_NCLBUTTONDOWN:
309 return NC_HandleNCLButtonDown( wndPtr, wParam, lParam );
311 case WM_LBUTTONDBLCLK:
312 case WM_NCLBUTTONDBLCLK:
313 return NC_HandleNCLButtonDblClk( wndPtr, wParam, lParam );
315 case WM_NCRBUTTONDOWN:
316 /* in Windows, capture is taken when right-clicking on the caption bar */
317 if (wParam==HTCAPTION)
319 SetCapture(wndPtr->hwndSelf);
321 break;
323 case WM_RBUTTONUP:
324 if (wndPtr->hwndSelf == GetCapture())
326 /* release capture if we took it on WM_NCRBUTTONDOWN */
327 ReleaseCapture();
329 if ((wndPtr->flags & WIN_ISWIN32) || (TWEAK_WineLook > WIN31_LOOK))
331 POINT pt;
332 pt.x = SLOWORD(lParam);
333 pt.y = SHIWORD(lParam);
334 ClientToScreen(wndPtr->hwndSelf, &pt);
335 lParam = MAKELPARAM(pt.x, pt.y);
336 pSendMessage( wndPtr->hwndSelf, WM_CONTEXTMENU, wndPtr->hwndSelf, lParam );
338 break;
340 case WM_NCRBUTTONUP:
342 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
343 * in Windows), but what _should_ we do? According to MSDN :
344 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
345 * message to the window". When is it appropriate?
347 break;
349 case WM_CONTEXTMENU:
350 if( wndPtr->dwStyle & WS_CHILD )
351 pSendMessage( wndPtr->parent->hwndSelf, msg, wParam, lParam );
352 else if (wndPtr->hSysMenu)
354 LONG hitcode;
355 POINT pt;
356 pt.x = SLOWORD(lParam);
357 pt.y = SHIWORD(lParam);
360 * WM_CONTEXTMENU coordinates are relative to screen, but
361 * NC_HandleNCHitTest expects coordinates relative to the parent's
362 * client area (to compare with the rectangle returned by
363 * GetWindowRect)
365 if (wndPtr->parent)
366 ScreenToClient(wndPtr->parent->hwndSelf, &pt);
368 hitcode = NC_HandleNCHitTest(wndPtr->hwndSelf, pt);
370 /* Track system popup if click was in the caption area. */
371 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
372 TrackPopupMenu(GetSystemMenu(wndPtr->hwndSelf, FALSE),
373 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
374 pt.x, pt.y, 0, wndPtr->hwndSelf, NULL);
376 break;
378 case WM_NCACTIVATE:
379 return NC_HandleNCActivate( wndPtr, wParam );
381 case WM_NCDESTROY:
382 if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
383 wndPtr->text = NULL;
384 if (wndPtr->pVScroll) HeapFree( SystemHeap, 0, wndPtr->pVScroll );
385 if (wndPtr->pHScroll) HeapFree( SystemHeap, 0, wndPtr->pHScroll );
386 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
387 return 0;
389 case WM_PRINT:
390 DEFWND_Print(wndPtr, (HDC)wParam, lParam);
391 return 0;
393 case WM_PAINTICON:
394 case WM_PAINT:
396 PAINTSTRUCT ps;
397 HDC hdc = BeginPaint( wndPtr->hwndSelf, &ps );
398 if( hdc )
400 HICON hIcon;
401 if( (wndPtr->dwStyle & WS_MINIMIZE) && ((hIcon = GetClassLongW( wndPtr->hwndSelf, GCL_HICON))) )
403 int x = (wndPtr->rectWindow.right - wndPtr->rectWindow.left -
404 GetSystemMetrics(SM_CXICON))/2;
405 int y = (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top -
406 GetSystemMetrics(SM_CYICON))/2;
407 TRACE("Painting class icon: vis rect=(%i,%i - %i,%i)\n",
408 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
409 DrawIcon( hdc, x, y, hIcon );
411 EndPaint( wndPtr->hwndSelf, &ps );
413 return 0;
416 case WM_SYNCPAINT:
417 if (wndPtr->hrgnUpdate)
419 RedrawWindow ( wndPtr->hwndSelf, 0, wndPtr->hrgnUpdate,
420 RDW_ERASENOW | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
422 return 0;
424 case WM_SETREDRAW:
425 DEFWND_SetRedraw( wndPtr, wParam );
426 return 0;
428 case WM_CLOSE:
429 DestroyWindow( wndPtr->hwndSelf );
430 return 0;
432 case WM_MOUSEACTIVATE:
433 if (wndPtr->dwStyle & WS_CHILD)
435 LONG ret = pSendMessage( wndPtr->parent->hwndSelf,
436 WM_MOUSEACTIVATE, wParam, lParam );
437 if (ret) return ret;
440 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
441 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
443 case WM_ACTIVATE:
444 /* The default action in Windows is to set the keyboard focus to
445 * the window, if it's being activated and not minimized */
446 if (LOWORD(wParam) != WA_INACTIVE) {
447 if (!(wndPtr->dwStyle & WS_MINIMIZE))
448 SetFocus(wndPtr->hwndSelf);
450 break;
452 case WM_MOUSEWHEEL:
453 if (wndPtr->dwStyle & WS_CHILD)
455 return pSendMessage( wndPtr->parent->hwndSelf,
456 WM_MOUSEWHEEL, wParam, lParam );
458 break;
460 case WM_ERASEBKGND:
461 case WM_ICONERASEBKGND:
463 RECT rect;
464 HBRUSH hbr = GetClassLongW( wndPtr->hwndSelf, GCL_HBRBACKGROUND );
465 if (!hbr) return 0;
467 /* Since WM_ERASEBKGND may receive either a window dc or a */
468 /* client dc, the area to be erased has to be retrieved from */
469 /* the device context. */
470 GetClipBox( (HDC)wParam, &rect );
472 /* Always call the Win32 variant of FillRect even on Win16,
473 * since despite the fact that Win16, as well as Win32,
474 * supports special background brushes for a window class,
475 * the Win16 variant of FillRect does not.
477 FillRect( (HDC) wParam, &rect, hbr );
478 return 1;
481 case WM_GETDLGCODE:
482 return 0;
484 case WM_CTLCOLORMSGBOX:
485 case WM_CTLCOLOREDIT:
486 case WM_CTLCOLORLISTBOX:
487 case WM_CTLCOLORBTN:
488 case WM_CTLCOLORDLG:
489 case WM_CTLCOLORSTATIC:
490 case WM_CTLCOLORSCROLLBAR:
491 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
493 case WM_CTLCOLOR:
494 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
496 case WM_GETTEXTLENGTH:
497 if (wndPtr->text) return (LRESULT)strlenW(wndPtr->text);
498 return 0;
500 case WM_SETCURSOR:
501 if (wndPtr->dwStyle & WS_CHILD)
502 if (pSendMessage(wndPtr->parent->hwndSelf, WM_SETCURSOR,
503 wParam, lParam))
504 return TRUE;
505 return NC_HandleSetCursor( wndPtr->hwndSelf, wParam, lParam );
507 case WM_SYSCOMMAND:
509 POINT pt;
510 pt.x = SLOWORD(lParam);
511 pt.y = SHIWORD(lParam);
512 return NC_HandleSysCommand( wndPtr->hwndSelf, wParam, pt );
515 case WM_KEYDOWN:
516 if(wParam == VK_F10) iF10Key = VK_F10;
517 break;
519 case WM_SYSKEYDOWN:
520 if( HIWORD(lParam) & KEYDATA_ALT )
522 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
523 if( wParam == VK_MENU && !iMenuSysKey )
524 iMenuSysKey = 1;
525 else
526 iMenuSysKey = 0;
528 iF10Key = 0;
530 if( wParam == VK_F4 ) /* try to close the window */
532 HWND hWnd = WIN_GetTopParent( wndPtr->hwndSelf );
533 wndPtr = WIN_FindWndPtr( hWnd );
534 if( wndPtr && !(wndPtr->clsStyle & CS_NOCLOSE) )
535 pPostMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 );
536 WIN_ReleaseWndPtr(wndPtr);
539 else if( wParam == VK_F10 )
540 iF10Key = 1;
541 else
542 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
543 pSendMessage( wndPtr->hwndSelf, WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE );
544 break;
546 case WM_KEYUP:
547 case WM_SYSKEYUP:
548 /* Press and release F10 or ALT */
549 if (((wParam == VK_MENU) && iMenuSysKey) ||
550 ((wParam == VK_F10) && iF10Key))
551 pSendMessage( WIN_GetTopParent(wndPtr->hwndSelf),
552 WM_SYSCOMMAND, SC_KEYMENU, 0L );
553 iMenuSysKey = iF10Key = 0;
554 break;
556 case WM_SYSCHAR:
557 iMenuSysKey = 0;
558 if (wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE))
560 pPostMessage( wndPtr->hwndSelf, WM_SYSCOMMAND, SC_RESTORE, 0L );
561 break;
563 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
565 if (wParam == VK_TAB || wParam == VK_ESCAPE) break;
566 if (wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD))
567 pSendMessage( wndPtr->parent->hwndSelf, msg, wParam, lParam );
568 else
569 pSendMessage( wndPtr->hwndSelf, WM_SYSCOMMAND, SC_KEYMENU, wParam );
571 else /* check for Ctrl-Esc */
572 if (wParam != VK_ESCAPE) MessageBeep(0);
573 break;
575 case WM_SHOWWINDOW:
576 if (!lParam) return 0; /* sent from ShowWindow */
577 if (!(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner) return 0;
578 if ((wndPtr->dwStyle & WS_VISIBLE) && wParam) return 0;
579 else if (!(wndPtr->dwStyle & WS_VISIBLE) && !wParam) return 0;
580 ShowWindow( wndPtr->hwndSelf, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
581 break;
583 case WM_CANCELMODE:
584 if (wndPtr->parent == WIN_GetDesktop()) EndMenu();
585 if (GetCapture() == wndPtr->hwndSelf) ReleaseCapture();
586 WIN_ReleaseDesktop();
587 break;
589 case WM_VKEYTOITEM:
590 case WM_CHARTOITEM:
591 return -1;
593 case WM_DROPOBJECT:
594 return DRAG_FILE;
596 case WM_QUERYDROPOBJECT:
597 if (wndPtr->dwExStyle & WS_EX_ACCEPTFILES) return 1;
598 break;
600 case WM_QUERYDRAGICON:
602 UINT len;
604 HICON hIcon = GetClassLongW( wndPtr->hwndSelf, GCL_HICON );
605 if (hIcon) return hIcon;
606 for(len=1; len<64; len++)
607 if((hIcon = LoadIconW(wndPtr->hInstance, MAKEINTRESOURCEW(len))))
608 return (LRESULT)hIcon;
609 return (LRESULT)LoadIconW(0, IDI_APPLICATIONW);
611 break;
613 case WM_ISACTIVEICON:
614 return ((wndPtr->flags & WIN_NCACTIVATED) != 0);
616 case WM_NOTIFYFORMAT:
617 if (IsWindowUnicode(wndPtr->hwndSelf)) return NFR_UNICODE;
618 else return NFR_ANSI;
620 case WM_QUERYOPEN:
621 case WM_QUERYENDSESSION:
622 return 1;
624 case WM_SETICON:
626 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
627 HICON hOldIcon = GetClassLongW(wndPtr->hwndSelf, index);
628 SetClassLongW(wndPtr->hwndSelf, index, lParam);
630 SetWindowPos(wndPtr->hwndSelf, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
631 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE
632 | SWP_NOZORDER);
634 if( wndPtr->flags & WIN_NATIVE )
635 wndPtr->pDriver->pSetHostAttr(wndPtr, HAK_ICONS, 0);
637 return hOldIcon;
640 case WM_GETICON:
642 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
643 return GetClassLongW(wndPtr->hwndSelf, index);
646 case WM_HELP:
647 pSendMessage( wndPtr->parent->hwndSelf, msg, wParam, lParam );
648 break;
651 return 0;
656 /***********************************************************************
657 * DefWindowProc (USER.107)
659 LRESULT WINAPI DefWindowProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
660 LPARAM lParam )
662 WND * wndPtr = WIN_FindWndPtr( hwnd );
663 LRESULT result = 0;
665 if (!wndPtr) return 0;
666 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
668 switch(msg)
670 case WM_NCCREATE:
672 CREATESTRUCT16 *cs = MapSL(lParam);
673 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
674 * may have child window IDs instead of window name */
675 if (HIWORD(cs->lpszName))
676 DEFWND_SetTextA( wndPtr, MapSL(cs->lpszName) );
677 result = 1;
679 break;
681 case WM_NCCALCSIZE:
683 RECT rect32;
684 CONV_RECT16TO32( MapSL(lParam), &rect32 );
685 result = NC_HandleNCCalcSize( wndPtr, &rect32 );
686 CONV_RECT32TO16( &rect32, MapSL(lParam) );
688 break;
690 case WM_WINDOWPOSCHANGING:
691 result = WINPOS_HandleWindowPosChanging16( wndPtr, MapSL(lParam) );
692 break;
694 case WM_WINDOWPOSCHANGED:
696 WINDOWPOS16 * winPos = MapSL(lParam);
697 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
699 break;
701 case WM_GETTEXT:
702 if (wParam && wndPtr->text)
704 LPSTR dest = MapSL(lParam);
705 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1, dest, wParam, NULL, NULL ))
706 dest[wParam-1] = 0;
707 result = strlen(dest);
709 break;
711 case WM_SETTEXT:
712 DEFWND_SetTextA( wndPtr, MapSL(lParam) );
713 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
714 NC_HandleNCPaint( hwnd , (HRGN)1 );
715 result = 1; /* success. FIXME: check text length */
716 break;
718 default:
719 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam, FALSE );
720 break;
723 WIN_ReleaseWndPtr(wndPtr);
724 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result, wParam, lParam );
725 return result;
729 /***********************************************************************
730 * DefWindowProcA (USER32.@)
733 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam,
734 LPARAM lParam )
736 WND * wndPtr = WIN_FindWndPtr( hwnd );
737 LRESULT result = 0;
739 if (!wndPtr) return 0;
740 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
742 switch(msg)
744 case WM_NCCREATE:
746 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
747 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
748 * may have child window IDs instead of window name */
749 if (HIWORD(cs->lpszName))
750 DEFWND_SetTextA( wndPtr, cs->lpszName );
751 result = 1;
753 break;
755 case WM_NCCALCSIZE:
756 result = NC_HandleNCCalcSize( wndPtr, (RECT *)lParam );
757 break;
759 case WM_WINDOWPOSCHANGING:
760 result = WINPOS_HandleWindowPosChanging( wndPtr,
761 (WINDOWPOS *)lParam );
762 break;
764 case WM_WINDOWPOSCHANGED:
766 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
767 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
769 break;
771 case WM_GETTEXT:
772 if (wParam && wndPtr->text)
774 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
775 (LPSTR)lParam, wParam, NULL, NULL ))
776 ((LPSTR)lParam)[wParam-1] = 0;
777 result = (LRESULT)strlen( (LPSTR)lParam );
779 break;
781 case WM_SETTEXT:
782 DEFWND_SetTextA( wndPtr, (LPCSTR)lParam );
783 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
784 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
785 result = 1; /* success. FIXME: check text length */
786 break;
788 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
789 case WM_IME_CHAR:
791 CHAR chChar1 = (CHAR)( (wParam>>8) & 0xff );
792 CHAR chChar2 = (CHAR)( wParam & 0xff );
794 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar1, lParam );
795 if ( IsDBCSLeadByte( chChar1 ) )
796 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar2, lParam );
798 break;
799 case WM_IME_KEYDOWN:
800 result = SendMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
801 break;
802 case WM_IME_KEYUP:
803 result = SendMessageA( hwnd, WM_KEYUP, wParam, lParam );
804 break;
806 case WM_IME_STARTCOMPOSITION:
807 case WM_IME_COMPOSITION:
808 case WM_IME_ENDCOMPOSITION:
809 case WM_IME_SELECT:
811 HWND hwndIME;
813 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
814 if (hwndIME)
815 result = SendMessageA( hwndIME, msg, wParam, lParam );
817 break;
818 case WM_IME_SETCONTEXT:
820 HWND hwndIME;
822 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
823 if (hwndIME)
824 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
826 break;
828 default:
829 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam, FALSE );
830 break;
833 WIN_ReleaseWndPtr(wndPtr);
834 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
835 return result;
839 /***********************************************************************
840 * DefWindowProcW (USER32.@) Calls default window message handler
842 * Calls default window procedure for messages not processed
843 * by application.
845 * RETURNS
846 * Return value is dependent upon the message.
848 LRESULT WINAPI DefWindowProcW(
849 HWND hwnd, /* [in] window procedure recieving message */
850 UINT msg, /* [in] message identifier */
851 WPARAM wParam, /* [in] first message parameter */
852 LPARAM lParam ) /* [in] second message parameter */
854 WND * wndPtr = WIN_FindWndPtr( hwnd );
855 LRESULT result = 0;
857 if (!wndPtr) return 0;
858 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
860 switch(msg)
862 case WM_NCCREATE:
864 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
865 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
866 * may have child window IDs instead of window name */
867 if (HIWORD(cs->lpszName))
868 DEFWND_SetTextW( wndPtr, cs->lpszName );
869 result = 1;
871 break;
873 case WM_NCCALCSIZE:
874 result = NC_HandleNCCalcSize( wndPtr, (RECT *)lParam );
875 break;
877 case WM_WINDOWPOSCHANGING:
878 result = WINPOS_HandleWindowPosChanging( wndPtr,
879 (WINDOWPOS *)lParam );
880 break;
882 case WM_WINDOWPOSCHANGED:
884 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
885 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
887 break;
889 case WM_GETTEXT:
890 if (wParam && wndPtr->text)
892 lstrcpynW( (LPWSTR)lParam, wndPtr->text, wParam );
893 result = strlenW( (LPWSTR)lParam );
895 break;
897 case WM_SETTEXT:
898 DEFWND_SetTextW( wndPtr, (LPCWSTR)lParam );
899 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
900 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
901 result = 1; /* success. FIXME: check text length */
902 break;
904 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
905 case WM_IME_CHAR:
906 SendMessageW( hwnd, WM_CHAR, wParam, lParam );
907 break;
908 case WM_IME_SETCONTEXT:
910 HWND hwndIME;
912 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
913 if (hwndIME)
914 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
916 break;
918 default:
919 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam, TRUE );
920 break;
922 WIN_ReleaseWndPtr(wndPtr);
923 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
924 return result;