Fix the Winelib case.
[wine.git] / windows / defwnd.c
blob1f924eb37eaa74982f34626c572fbbc0cccdff70
1 /*
2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
5 * 1995 Alex Korobka
6 */
8 #include <string.h>
10 #include "class.h"
11 #include "win.h"
12 #include "user.h"
13 #include "heap.h"
14 #include "nonclient.h"
15 #include "winpos.h"
16 #include "dce.h"
17 #include "debugtools.h"
18 #include "spy.h"
19 #include "tweak.h"
20 #include "cache.h"
21 #include "windef.h"
22 #include "wingdi.h"
23 #include "winnls.h"
24 #include "wine/unicode.h"
25 #include "wine/winuser16.h"
27 DEFAULT_DEBUG_CHANNEL(win);
29 /* bits in the dwKeyData */
30 #define KEYDATA_ALT 0x2000
31 #define KEYDATA_PREVSTATE 0x4000
33 static short iF10Key = 0;
34 static short iMenuSysKey = 0;
36 /***********************************************************************
37 * DEFWND_HandleWindowPosChanged
39 * Handle the WM_WINDOWPOSCHANGED message.
41 static void DEFWND_HandleWindowPosChanged( WND *wndPtr, UINT flags )
43 WPARAM16 wp = SIZE_RESTORED;
45 if (!(flags & SWP_NOCLIENTMOVE))
46 SendMessage16( wndPtr->hwndSelf, WM_MOVE, 0,
47 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top));
48 if (!(flags & SWP_NOCLIENTSIZE))
50 if (wndPtr->dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
51 else if (wndPtr->dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
53 SendMessage16( wndPtr->hwndSelf, WM_SIZE, wp,
54 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
55 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
60 /***********************************************************************
61 * DEFWND_SetTextA
63 * Set the window text.
65 void DEFWND_SetTextA( WND *wndPtr, LPCSTR text )
67 int count;
69 if (!text) text = "";
70 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
72 if (wndPtr->text) HeapFree(SystemHeap, 0, wndPtr->text);
73 if ((wndPtr->text = HeapAlloc(SystemHeap, 0, count * sizeof(WCHAR))))
74 MultiByteToWideChar( CP_ACP, 0, text, -1, wndPtr->text, count );
75 else
76 ERR("Not enough memory for window text");
78 wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
81 /***********************************************************************
82 * DEFWND_SetTextW
84 * Set the window text.
86 void DEFWND_SetTextW( WND *wndPtr, LPCWSTR text )
88 static const WCHAR empty_string[] = {0};
89 int count;
91 if (!text) text = empty_string;
92 count = strlenW(text) + 1;
94 if (wndPtr->text) HeapFree(SystemHeap, 0, wndPtr->text);
95 if ((wndPtr->text = HeapAlloc(SystemHeap, 0, count * sizeof(WCHAR))))
96 strcpyW( wndPtr->text, text );
97 else
98 ERR("Not enough memory for window text");
100 wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
103 /***********************************************************************
104 * DEFWND_ControlColor
106 * Default colors for control painting.
108 HBRUSH DEFWND_ControlColor( HDC hDC, UINT16 ctlType )
110 if( ctlType == CTLCOLOR_SCROLLBAR)
112 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
113 if (TWEAK_WineLook == WIN31_LOOK) {
114 SetTextColor( hDC, RGB(0, 0, 0) );
115 SetBkColor( hDC, RGB(255, 255, 255) );
116 } else {
117 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
118 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
119 SetBkColor( hDC, bk);
121 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
122 * we better use 0x55aa bitmap brush to make scrollbar's background
123 * look different from the window background.
125 if (bk == GetSysColor(COLOR_WINDOW)) {
126 return CACHE_GetPattern55AABrush();
129 UnrealizeObject( hb );
130 return hb;
133 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
135 if (TWEAK_WineLook > WIN31_LOOK) {
136 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
137 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
138 else {
139 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
140 return GetSysColorBrush(COLOR_3DFACE);
143 else
144 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
145 return GetSysColorBrush(COLOR_WINDOW);
149 /***********************************************************************
150 * DEFWND_SetRedraw
152 static void DEFWND_SetRedraw( WND* wndPtr, WPARAM wParam )
154 BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
156 TRACE("%04x %i\n", wndPtr->hwndSelf, (wParam!=0) );
158 if( wParam )
160 if( !bVisible )
162 wndPtr->dwStyle |= WS_VISIBLE;
163 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
166 else if( bVisible )
168 if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
169 else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
171 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, wParam, 0 );
172 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
173 wndPtr->dwStyle &= ~WS_VISIBLE;
177 /***********************************************************************
178 * DEFWND_Print
180 * This method handles the default behavior for the WM_PRINT message.
182 static void DEFWND_Print(
183 WND* wndPtr,
184 HDC hdc,
185 ULONG uFlags)
188 * Visibility flag.
190 if ( (uFlags & PRF_CHECKVISIBLE) &&
191 !IsWindowVisible(wndPtr->hwndSelf) )
192 return;
195 * Unimplemented flags.
197 if ( (uFlags & PRF_CHILDREN) ||
198 (uFlags & PRF_OWNED) ||
199 (uFlags & PRF_NONCLIENT) )
201 WARN("WM_PRINT message with unsupported flags\n");
205 * Background
207 if ( uFlags & PRF_ERASEBKGND)
208 SendMessageA(wndPtr->hwndSelf, WM_ERASEBKGND, (WPARAM)hdc, 0);
211 * Client area
213 if ( uFlags & PRF_CLIENT)
214 SendMessageA(wndPtr->hwndSelf, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
217 /***********************************************************************
218 * DEFWND_DefWinProc
220 * Default window procedure for messages that are the same in Win16 and Win32.
222 static LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT msg, WPARAM wParam,
223 LPARAM lParam )
225 switch(msg)
227 case WM_NCPAINT:
228 return NC_HandleNCPaint( wndPtr->hwndSelf, (HRGN)wParam );
230 case WM_NCHITTEST:
232 POINT pt;
233 pt.x = SLOWORD(lParam);
234 pt.y = SHIWORD(lParam);
235 return NC_HandleNCHitTest( wndPtr->hwndSelf, pt );
238 case WM_NCLBUTTONDOWN:
239 return NC_HandleNCLButtonDown( wndPtr, wParam, lParam );
241 case WM_LBUTTONDBLCLK:
242 case WM_NCLBUTTONDBLCLK:
243 return NC_HandleNCLButtonDblClk( wndPtr, wParam, lParam );
245 case WM_NCRBUTTONDOWN:
246 /* in Windows, capture is taken when right-clicking on the caption bar */
247 if (wParam==HTCAPTION)
249 SetCapture(wndPtr->hwndSelf);
251 break;
253 case WM_RBUTTONUP:
254 if (wndPtr->hwndSelf == GetCapture())
256 /* release capture if we took it on WM_NCRBUTTONDOWN */
257 ReleaseCapture();
259 if ((wndPtr->flags & WIN_ISWIN32) || (TWEAK_WineLook > WIN31_LOOK))
261 ClientToScreen16(wndPtr->hwndSelf, (LPPOINT16)&lParam);
262 SendMessageA( wndPtr->hwndSelf, WM_CONTEXTMENU,
263 wndPtr->hwndSelf, lParam);
265 break;
267 case WM_NCRBUTTONUP:
269 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
270 * in Windows), but what _should_ we do? According to MSDN :
271 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
272 * message to the window". When is it appropriate?
274 break;
276 case WM_CONTEXTMENU:
277 if( wndPtr->dwStyle & WS_CHILD )
278 SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
279 else if (wndPtr->hSysMenu)
281 LONG hitcode;
282 POINT pt;
283 pt.x = SLOWORD(lParam);
284 pt.y = SHIWORD(lParam);
287 * WM_CONTEXTMENU coordinates are relative to screen, but
288 * NC_HandleNCHitTest expects coordinates relative to the parent's
289 * client area (to compare with the rectangle returned by
290 * GetWindowRect)
292 if (wndPtr->parent)
293 ScreenToClient(wndPtr->parent->hwndSelf, &pt);
295 hitcode = NC_HandleNCHitTest(wndPtr->hwndSelf, pt);
297 /* Track system popup if click was in the caption area. */
298 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
299 TrackPopupMenu(GetSystemMenu(wndPtr->hwndSelf, FALSE),
300 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
301 pt.x, pt.y, 0, wndPtr->hwndSelf, NULL);
303 break;
305 case WM_NCACTIVATE:
306 return NC_HandleNCActivate( wndPtr, wParam );
308 case WM_NCDESTROY:
309 if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
310 wndPtr->text = NULL;
311 if (wndPtr->pVScroll) HeapFree( SystemHeap, 0, wndPtr->pVScroll );
312 if (wndPtr->pHScroll) HeapFree( SystemHeap, 0, wndPtr->pHScroll );
313 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
314 return 0;
316 case WM_PRINT:
317 DEFWND_Print(wndPtr, (HDC)wParam, lParam);
318 return 0;
320 case WM_PAINTICON:
321 case WM_PAINT:
323 PAINTSTRUCT16 ps;
324 HDC16 hdc = BeginPaint16( wndPtr->hwndSelf, &ps );
325 if( hdc )
327 if( (wndPtr->dwStyle & WS_MINIMIZE) && wndPtr->class->hIcon )
329 int x = (wndPtr->rectWindow.right - wndPtr->rectWindow.left -
330 GetSystemMetrics(SM_CXICON))/2;
331 int y = (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top -
332 GetSystemMetrics(SM_CYICON))/2;
333 TRACE("Painting class icon: vis rect=(%i,%i - %i,%i)\n",
334 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
335 DrawIcon( hdc, x, y, wndPtr->class->hIcon );
337 EndPaint16( wndPtr->hwndSelf, &ps );
339 return 0;
342 case WM_SYNCPAINT:
343 if (wndPtr->hrgnUpdate)
345 RedrawWindow ( wndPtr->hwndSelf, 0, wndPtr->hrgnUpdate,
346 RDW_ERASENOW | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
348 return 0;
350 case WM_SETREDRAW:
351 DEFWND_SetRedraw( wndPtr, wParam );
352 return 0;
354 case WM_CLOSE:
355 DestroyWindow( wndPtr->hwndSelf );
356 return 0;
358 case WM_MOUSEACTIVATE:
359 if (wndPtr->dwStyle & WS_CHILD)
361 LONG ret = SendMessage16( wndPtr->parent->hwndSelf,
362 WM_MOUSEACTIVATE, wParam, lParam );
363 if (ret) return ret;
366 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
367 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
369 case WM_ACTIVATE:
370 /* The default action in Windows is to set the keyboard focus to
371 * the window, if it's being activated and not minimized */
372 if (LOWORD(wParam) != WA_INACTIVE) {
373 if (!(wndPtr->dwStyle & WS_MINIMIZE))
374 SetFocus(wndPtr->hwndSelf);
376 break;
378 case WM_MOUSEWHEEL:
379 if (wndPtr->dwStyle & WS_CHILD)
381 return SendMessageA( wndPtr->parent->hwndSelf,
382 WM_MOUSEWHEEL, wParam, lParam );
384 break;
386 case WM_ERASEBKGND:
387 case WM_ICONERASEBKGND:
389 RECT rect;
391 if (!wndPtr->class->hbrBackground) return 0;
393 /* Since WM_ERASEBKGND may receive either a window dc or a */
394 /* client dc, the area to be erased has to be retrieved from */
395 /* the device context. */
396 GetClipBox( (HDC)wParam, &rect );
398 /* Always call the Win32 variant of FillRect even on Win16,
399 * since despite the fact that Win16, as well as Win32,
400 * supports special background brushes for a window class,
401 * the Win16 variant of FillRect does not.
403 FillRect( (HDC) wParam, &rect, wndPtr->class->hbrBackground);
404 return 1;
407 case WM_GETDLGCODE:
408 return 0;
410 case WM_CTLCOLORMSGBOX:
411 case WM_CTLCOLOREDIT:
412 case WM_CTLCOLORLISTBOX:
413 case WM_CTLCOLORBTN:
414 case WM_CTLCOLORDLG:
415 case WM_CTLCOLORSTATIC:
416 case WM_CTLCOLORSCROLLBAR:
417 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
419 case WM_CTLCOLOR:
420 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
422 case WM_GETTEXTLENGTH:
423 if (wndPtr->text) return (LRESULT)strlenW(wndPtr->text);
424 return 0;
426 case WM_SETCURSOR:
427 if (wndPtr->dwStyle & WS_CHILD)
428 if (SendMessage16(wndPtr->parent->hwndSelf, WM_SETCURSOR,
429 wParam, lParam))
430 return TRUE;
431 return NC_HandleSetCursor( wndPtr->hwndSelf, wParam, lParam );
433 case WM_SYSCOMMAND:
435 POINT pt;
436 pt.x = SLOWORD(lParam);
437 pt.y = SHIWORD(lParam);
438 return NC_HandleSysCommand( wndPtr->hwndSelf, wParam, pt );
441 case WM_KEYDOWN:
442 if(wParam == VK_F10) iF10Key = VK_F10;
443 break;
445 case WM_SYSKEYDOWN:
446 if( HIWORD(lParam) & KEYDATA_ALT )
448 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
449 if( wParam == VK_MENU && !iMenuSysKey )
450 iMenuSysKey = 1;
451 else
452 iMenuSysKey = 0;
454 iF10Key = 0;
456 if( wParam == VK_F4 ) /* try to close the window */
458 HWND hWnd = WIN_GetTopParent( wndPtr->hwndSelf );
459 wndPtr = WIN_FindWndPtr( hWnd );
460 if( wndPtr && !(wndPtr->class->style & CS_NOCLOSE) )
461 PostMessage16( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 );
462 WIN_ReleaseWndPtr(wndPtr);
465 else if( wParam == VK_F10 )
466 iF10Key = 1;
467 else
468 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
469 SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
470 (WPARAM16)SC_KEYMENU, (LPARAM)VK_SPACE);
471 break;
473 case WM_KEYUP:
474 case WM_SYSKEYUP:
475 /* Press and release F10 or ALT */
476 if (((wParam == VK_MENU) && iMenuSysKey) ||
477 ((wParam == VK_F10) && iF10Key))
478 SendMessage16( WIN_GetTopParent(wndPtr->hwndSelf),
479 WM_SYSCOMMAND, SC_KEYMENU, 0L );
480 iMenuSysKey = iF10Key = 0;
481 break;
483 case WM_SYSCHAR:
484 iMenuSysKey = 0;
485 if (wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE))
487 PostMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
488 (WPARAM16)SC_RESTORE, 0L );
489 break;
491 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
493 if (wParam == VK_TAB || wParam == VK_ESCAPE) break;
494 if (wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD))
495 SendMessage16( wndPtr->parent->hwndSelf, msg, wParam, lParam );
496 else
497 SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
498 (WPARAM16)SC_KEYMENU, (LPARAM)(DWORD)wParam );
500 else /* check for Ctrl-Esc */
501 if (wParam != VK_ESCAPE) MessageBeep(0);
502 break;
504 case WM_SHOWWINDOW:
505 if (!lParam) return 0; /* sent from ShowWindow */
506 if (!(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner) return 0;
507 if ((wndPtr->dwStyle & WS_VISIBLE) && wParam) return 0;
508 else if (!(wndPtr->dwStyle & WS_VISIBLE) && !wParam) return 0;
509 ShowWindow( wndPtr->hwndSelf, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
510 break;
512 case WM_CANCELMODE:
513 if (wndPtr->parent == WIN_GetDesktop()) EndMenu();
514 if (GetCapture() == wndPtr->hwndSelf) ReleaseCapture();
515 WIN_ReleaseDesktop();
516 break;
518 case WM_VKEYTOITEM:
519 case WM_CHARTOITEM:
520 return -1;
522 case WM_DROPOBJECT:
523 return DRAG_FILE;
525 case WM_QUERYDROPOBJECT:
526 if (wndPtr->dwExStyle & WS_EX_ACCEPTFILES) return 1;
527 break;
529 case WM_QUERYDRAGICON:
531 HICON16 hIcon=0;
532 UINT16 len;
534 if( (hIcon=wndPtr->class->hCursor) ) return (LRESULT)hIcon;
535 for(len=1; len<64; len++)
536 if((hIcon=LoadIconA(wndPtr->hInstance,MAKEINTRESOURCEA(len))))
537 return (LRESULT)hIcon;
538 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
540 break;
542 case WM_ISACTIVEICON:
543 return ((wndPtr->flags & WIN_NCACTIVATED) != 0);
545 case WM_NOTIFYFORMAT:
546 if (IsWindowUnicode(wndPtr->hwndSelf)) return NFR_UNICODE;
547 else return NFR_ANSI;
549 case WM_QUERYOPEN:
550 case WM_QUERYENDSESSION:
551 return 1;
553 case WM_SETICON:
555 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
556 HICON16 hOldIcon = GetClassLongA(wndPtr->hwndSelf, index);
557 SetClassLongA(wndPtr->hwndSelf, index, lParam);
559 SetWindowPos(wndPtr->hwndSelf, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
560 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE
561 | SWP_NOZORDER);
563 if( wndPtr->flags & WIN_NATIVE )
564 wndPtr->pDriver->pSetHostAttr(wndPtr, HAK_ICONS, 0);
566 return hOldIcon;
569 case WM_GETICON:
571 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
572 return GetClassLongA(wndPtr->hwndSelf, index);
575 case WM_HELP:
576 SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
577 break;
580 return 0;
585 /***********************************************************************
586 * DefWindowProc16 (USER.107)
588 LRESULT WINAPI DefWindowProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
589 LPARAM lParam )
591 WND * wndPtr = WIN_FindWndPtr( hwnd );
592 LRESULT result = 0;
594 if (!wndPtr) return 0;
595 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
597 switch(msg)
599 case WM_NCCREATE:
601 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
602 if (cs->lpszName)
603 DEFWND_SetTextA( wndPtr, (LPCSTR)PTR_SEG_TO_LIN(cs->lpszName) );
604 result = 1;
606 break;
608 case WM_NCCALCSIZE:
610 RECT rect32;
611 CONV_RECT16TO32( (RECT16 *)PTR_SEG_TO_LIN(lParam), &rect32 );
612 result = NC_HandleNCCalcSize( wndPtr, &rect32 );
613 CONV_RECT32TO16( &rect32, (RECT16 *)PTR_SEG_TO_LIN(lParam) );
615 break;
617 case WM_WINDOWPOSCHANGING:
618 result = WINPOS_HandleWindowPosChanging16( wndPtr,
619 (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam) );
620 break;
622 case WM_WINDOWPOSCHANGED:
624 WINDOWPOS16 * winPos = (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam);
625 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
627 break;
629 case WM_GETTEXT:
630 if (wParam && wndPtr->text)
632 LPSTR dest = PTR_SEG_TO_LIN(lParam);
633 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1, dest, wParam, NULL, NULL ))
634 dest[wParam-1] = 0;
635 result = strlen(dest);
637 break;
639 case WM_SETTEXT:
640 DEFWND_SetTextA( wndPtr, (LPCSTR)PTR_SEG_TO_LIN(lParam) );
641 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
642 NC_HandleNCPaint( hwnd , (HRGN)1 );
643 result = 1; /* success. FIXME: check text length */
644 break;
646 default:
647 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
648 break;
651 WIN_ReleaseWndPtr(wndPtr);
652 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result, wParam, lParam );
653 return result;
657 /***********************************************************************
658 * DefWindowProcA [USER32.126]
661 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam,
662 LPARAM lParam )
664 WND * wndPtr = WIN_FindWndPtr( hwnd );
665 LRESULT result = 0;
667 if (!wndPtr) return 0;
668 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
670 switch(msg)
672 case WM_NCCREATE:
674 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
675 if (cs->lpszName) DEFWND_SetTextA( wndPtr, cs->lpszName );
676 result = 1;
678 break;
680 case WM_NCCALCSIZE:
681 result = NC_HandleNCCalcSize( wndPtr, (RECT *)lParam );
682 break;
684 case WM_WINDOWPOSCHANGING:
685 result = WINPOS_HandleWindowPosChanging( wndPtr,
686 (WINDOWPOS *)lParam );
687 break;
689 case WM_WINDOWPOSCHANGED:
691 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
692 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
694 break;
696 case WM_GETTEXT:
697 if (wParam && wndPtr->text)
699 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
700 (LPSTR)lParam, wParam, NULL, NULL ))
701 ((LPSTR)lParam)[wParam-1] = 0;
702 result = (LRESULT)strlen( (LPSTR)lParam );
704 break;
706 case WM_SETTEXT:
707 DEFWND_SetTextA( wndPtr, (LPCSTR)lParam );
708 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
709 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
710 result = 1; /* success. FIXME: check text length */
711 break;
713 default:
714 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
715 break;
718 WIN_ReleaseWndPtr(wndPtr);
719 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
720 return result;
724 /***********************************************************************
725 * DefWindowProcW [USER32.127] Calls default window message handler
727 * Calls default window procedure for messages not processed
728 * by application.
730 * RETURNS
731 * Return value is dependent upon the message.
733 LRESULT WINAPI DefWindowProcW(
734 HWND hwnd, /* [in] window procedure recieving message */
735 UINT msg, /* [in] message identifier */
736 WPARAM wParam, /* [in] first message parameter */
737 LPARAM lParam ) /* [in] second message parameter */
739 WND * wndPtr = WIN_FindWndPtr( hwnd );
740 LRESULT result = 0;
742 if (!wndPtr) return 0;
743 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
745 switch(msg)
747 case WM_NCCREATE:
749 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
750 if (cs->lpszName) DEFWND_SetTextW( wndPtr, cs->lpszName );
751 result = 1;
753 break;
755 case WM_GETTEXT:
756 if (wParam && wndPtr->text)
758 lstrcpynW( (LPWSTR)lParam, wndPtr->text, wParam );
759 result = strlenW( (LPWSTR)lParam );
761 break;
763 case WM_SETTEXT:
764 DEFWND_SetTextW( wndPtr, (LPCWSTR)lParam );
765 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
766 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
767 result = 1; /* success. FIXME: check text length */
768 break;
770 default:
771 result = DefWindowProcA( hwnd, msg, wParam, lParam );
772 break;
774 WIN_ReleaseWndPtr(wndPtr);
775 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
776 return result;