Convert WND.text field to Unicode.
[wine] / windows / defwnd.c
1 /*
2  * Default window procedure
3  *
4  * Copyright 1993, 1996 Alexandre Julliard
5  *           1995 Alex Korobka
6  */
7
8 #include <string.h>
9
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"
26
27 DEFAULT_DEBUG_CHANNEL(win);
28
29   /* bits in the dwKeyData */
30 #define KEYDATA_ALT             0x2000
31 #define KEYDATA_PREVSTATE       0x4000
32
33 static short iF10Key = 0;
34 static short iMenuSysKey = 0;
35
36 /***********************************************************************
37  *           DEFWND_HandleWindowPosChanged
38  *
39  * Handle the WM_WINDOWPOSCHANGED message.
40  */
41 static void DEFWND_HandleWindowPosChanged( WND *wndPtr, UINT flags )
42 {
43     WPARAM16 wp = SIZE_RESTORED;
44
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))
49     {
50         if (wndPtr->dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
51         else if (wndPtr->dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
52
53         SendMessage16( wndPtr->hwndSelf, WM_SIZE, wp, 
54                      MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
55                             wndPtr->rectClient.bottom-wndPtr->rectClient.top));
56     }
57 }
58
59
60 /***********************************************************************
61  *           DEFWND_SetTextA
62  *
63  * Set the window text.
64  */
65 void DEFWND_SetTextA( WND *wndPtr, LPCSTR text )
66 {
67     int count;
68
69     if (!text) text = "";
70     count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
71
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");
77
78     wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
79 }
80
81 /***********************************************************************
82  *           DEFWND_SetTextW
83  *
84  * Set the window text.
85  */
86 void DEFWND_SetTextW( WND *wndPtr, LPCWSTR text )
87 {
88     static const WCHAR empty_string[] = {0};
89     int count;
90
91     if (!text) text = empty_string;
92     count = strlenW(text) + 1;
93
94     if (wndPtr->text) HeapFree(SystemHeap, 0, wndPtr->text);
95     if ((wndPtr->text = HeapAlloc(SystemHeap, 0, count * sizeof(WCHAR))))
96         lstrcpyW( wndPtr->text, text );
97     else
98         ERR("Not enough memory for window text");
99
100     wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
101 }
102
103 /***********************************************************************
104  *           DEFWND_ControlColor
105  *
106  * Default colors for control painting.
107  */
108 HBRUSH DEFWND_ControlColor( HDC hDC, UINT16 ctlType )
109 {
110     if( ctlType == CTLCOLOR_SCROLLBAR)
111     {
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);
120
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. 
124             */
125            if (bk == GetSysColor(COLOR_WINDOW)) {
126                return CACHE_GetPattern55AABrush();
127            }
128         }
129         UnrealizeObject( hb );
130         return hb;
131     }
132
133     SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
134
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);
141         }
142     }
143     else
144         SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
145     return GetSysColorBrush(COLOR_WINDOW);
146 }
147
148
149 /***********************************************************************
150  *           DEFWND_SetRedraw
151  */
152 static void DEFWND_SetRedraw( WND* wndPtr, WPARAM wParam )
153 {
154     BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
155
156     TRACE("%04x %i\n", wndPtr->hwndSelf, (wParam!=0) );
157
158     if( wParam )
159     {
160         if( !bVisible )
161         {
162             wndPtr->dwStyle |= WS_VISIBLE;
163             DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
164         }
165     }
166     else if( bVisible )
167     {
168         if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
169         else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
170
171         PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, wParam, 0 );
172         DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
173         wndPtr->dwStyle &= ~WS_VISIBLE;
174     }
175 }
176
177 /***********************************************************************
178  *           DEFWND_Print
179  *
180  * This method handles the default behavior for the WM_PRINT message.
181  */
182 static void DEFWND_Print(
183   WND*  wndPtr,
184   HDC   hdc,
185   ULONG uFlags)
186 {
187   /*
188    * Visibility flag.
189    */
190   if ( (uFlags & PRF_CHECKVISIBLE) &&
191        !IsWindowVisible(wndPtr->hwndSelf) )
192       return;
193
194   /*
195    * Unimplemented flags.
196    */
197   if ( (uFlags & PRF_CHILDREN) ||
198        (uFlags & PRF_OWNED)    ||
199        (uFlags & PRF_NONCLIENT) )
200   {
201     WARN("WM_PRINT message with unsupported flags\n");
202   }
203
204   /*
205    * Background
206    */
207   if ( uFlags & PRF_ERASEBKGND)
208     SendMessageA(wndPtr->hwndSelf, WM_ERASEBKGND, (WPARAM)hdc, 0);
209
210   /*
211    * Client area
212    */
213   if ( uFlags & PRF_CLIENT)
214     SendMessageA(wndPtr->hwndSelf, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
215 }
216
217 /***********************************************************************
218  *           DEFWND_DefWinProc
219  *
220  * Default window procedure for messages that are the same in Win16 and Win32.
221  */
222 static LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT msg, WPARAM wParam,
223                                   LPARAM lParam )
224 {
225     switch(msg)
226     {
227     case WM_NCPAINT:
228         return NC_HandleNCPaint( wndPtr->hwndSelf, (HRGN)wParam );
229
230     case WM_NCHITTEST:
231         return NC_HandleNCHitTest( wndPtr->hwndSelf, MAKEPOINT16(lParam) );
232
233     case WM_NCLBUTTONDOWN:
234         return NC_HandleNCLButtonDown( wndPtr, wParam, lParam );
235
236     case WM_LBUTTONDBLCLK:
237     case WM_NCLBUTTONDBLCLK:
238         return NC_HandleNCLButtonDblClk( wndPtr, wParam, lParam );
239
240     case WM_RBUTTONUP:
241     case WM_NCRBUTTONUP:
242         if ((wndPtr->flags & WIN_ISWIN32) || (TWEAK_WineLook > WIN31_LOOK))
243         {
244             ClientToScreen16(wndPtr->hwndSelf, (LPPOINT16)&lParam);
245             SendMessageA( wndPtr->hwndSelf, WM_CONTEXTMENU,
246                             wndPtr->hwndSelf, lParam);
247         }
248         break;
249
250     case WM_CONTEXTMENU:
251         if( wndPtr->dwStyle & WS_CHILD )
252             SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
253         else if (wndPtr->hSysMenu)
254         {
255             LONG hitcode;
256             POINT16 pt = MAKEPOINT16(lParam);
257
258             ScreenToClient16(wndPtr->hwndSelf, &pt);
259             hitcode = NC_HandleNCHitTest(wndPtr->hwndSelf, pt);
260
261             /* Track system popup if click was in the caption area. */
262             if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
263                 TrackPopupMenu(GetSystemMenu(wndPtr->hwndSelf, FALSE),
264                                TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
265                                pt.x, pt.y, 0, wndPtr->hwndSelf, NULL);
266         }
267         break;
268
269     case WM_NCACTIVATE:
270         return NC_HandleNCActivate( wndPtr, wParam );
271
272     case WM_NCDESTROY:
273         if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
274         wndPtr->text = NULL;
275         if (wndPtr->pVScroll) HeapFree( SystemHeap, 0, wndPtr->pVScroll );
276         if (wndPtr->pHScroll) HeapFree( SystemHeap, 0, wndPtr->pHScroll );
277         wndPtr->pVScroll = wndPtr->pHScroll = NULL;
278         return 0;
279
280     case WM_PRINT:
281         DEFWND_Print(wndPtr, (HDC)wParam, lParam);
282         return 0;
283
284     case WM_PAINTICON:
285     case WM_PAINT:
286         {
287             PAINTSTRUCT16 ps;
288             HDC16 hdc = BeginPaint16( wndPtr->hwndSelf, &ps );
289             if( hdc ) 
290             {
291               if( (wndPtr->dwStyle & WS_MINIMIZE) && wndPtr->class->hIcon )
292               {
293                 int x = (wndPtr->rectWindow.right - wndPtr->rectWindow.left -
294                         GetSystemMetrics(SM_CXICON))/2;
295                 int y = (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top -
296                         GetSystemMetrics(SM_CYICON))/2;
297                 TRACE("Painting class icon: vis rect=(%i,%i - %i,%i)\n",
298                 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
299                 DrawIcon( hdc, x, y, wndPtr->class->hIcon );
300               }
301               EndPaint16( wndPtr->hwndSelf, &ps );
302             }
303             return 0;
304         }
305
306     case WM_SETREDRAW:
307         DEFWND_SetRedraw( wndPtr, wParam );
308         return 0;
309
310     case WM_CLOSE:
311         DestroyWindow( wndPtr->hwndSelf );
312         return 0;
313
314     case WM_MOUSEACTIVATE:
315         if (wndPtr->dwStyle & WS_CHILD)
316         {
317             LONG ret = SendMessage16( wndPtr->parent->hwndSelf,
318                                       WM_MOUSEACTIVATE, wParam, lParam );
319             if (ret) return ret;
320         }
321
322         /* Caption clicks are handled by the NC_HandleNCLButtonDown() */ 
323         return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
324
325     case WM_ACTIVATE:
326         /* The default action in Windows is to set the keyboard focus to
327          * the window, if it's being activated and not minimized */
328         if (LOWORD(wParam) != WA_INACTIVE) {
329                 if (!(wndPtr->dwStyle & WS_MINIMIZE))
330                         SetFocus(wndPtr->hwndSelf);
331         }
332         break;
333
334     case WM_ERASEBKGND:
335     case WM_ICONERASEBKGND:
336         {
337             RECT rect;
338
339             if (!wndPtr->class->hbrBackground) return 0;
340
341             /*  Since WM_ERASEBKGND may receive either a window dc or a    */ 
342             /*  client dc, the area to be erased has to be retrieved from  */
343             /*  the device context.                                        */
344             GetClipBox( (HDC)wParam, &rect );
345
346             /* Always call the Win32 variant of FillRect even on Win16,
347              * since despite the fact that Win16, as well as Win32,
348              * supports special background brushes for a window class,
349              * the Win16 variant of FillRect does not.
350              */
351             FillRect( (HDC) wParam, &rect, wndPtr->class->hbrBackground);
352             return 1;
353         }
354
355     case WM_GETDLGCODE:
356         return 0;
357
358     case WM_CTLCOLORMSGBOX:
359     case WM_CTLCOLOREDIT:
360     case WM_CTLCOLORLISTBOX:
361     case WM_CTLCOLORBTN:
362     case WM_CTLCOLORDLG:
363     case WM_CTLCOLORSTATIC:
364     case WM_CTLCOLORSCROLLBAR:
365         return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
366
367     case WM_CTLCOLOR:
368         return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
369         
370     case WM_GETTEXTLENGTH:
371         if (wndPtr->text) return (LRESULT)strlenW(wndPtr->text);
372         return 0;
373
374     case WM_SETCURSOR:
375         if (wndPtr->dwStyle & WS_CHILD)
376             if (SendMessage16(wndPtr->parent->hwndSelf, WM_SETCURSOR,
377                             wParam, lParam))
378                 return TRUE;
379         return NC_HandleSetCursor( wndPtr->hwndSelf, wParam, lParam );
380
381     case WM_SYSCOMMAND:
382         return NC_HandleSysCommand( wndPtr->hwndSelf, wParam,
383                                     MAKEPOINT16(lParam) );
384
385     case WM_KEYDOWN:
386         if(wParam == VK_F10) iF10Key = VK_F10;
387         break;
388
389     case WM_SYSKEYDOWN:
390         if( HIWORD(lParam) & KEYDATA_ALT )
391         {
392             /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
393               if( wParam == VK_MENU && !iMenuSysKey )
394                 iMenuSysKey = 1;
395               else
396                 iMenuSysKey = 0;
397             
398             iF10Key = 0;
399
400             if( wParam == VK_F4 )       /* try to close the window */
401             {
402                 HWND hWnd = WIN_GetTopParent( wndPtr->hwndSelf );
403                 wndPtr = WIN_FindWndPtr( hWnd );
404                 if( wndPtr && !(wndPtr->class->style & CS_NOCLOSE) )
405                     PostMessage16( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 );
406                 WIN_ReleaseWndPtr(wndPtr);
407             }
408         } 
409         else if( wParam == VK_F10 )
410                 iF10Key = 1;
411              else
412                 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
413                     SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
414                                   (WPARAM16)SC_KEYMENU, (LPARAM)VK_SPACE);
415         break;
416
417     case WM_KEYUP:
418     case WM_SYSKEYUP:
419         /* Press and release F10 or ALT */
420         if (((wParam == VK_MENU) && iMenuSysKey) ||
421             ((wParam == VK_F10) && iF10Key))
422               SendMessage16( WIN_GetTopParent(wndPtr->hwndSelf),
423                              WM_SYSCOMMAND, SC_KEYMENU, 0L );
424         iMenuSysKey = iF10Key = 0;
425         break;
426
427     case WM_SYSCHAR:
428         iMenuSysKey = 0;
429         if (wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE))
430         {
431             PostMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
432                            (WPARAM16)SC_RESTORE, 0L ); 
433             break;
434         } 
435         if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
436         {
437             if (wParam == VK_TAB || wParam == VK_ESCAPE) break;
438             if (wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD))
439                 SendMessage16( wndPtr->parent->hwndSelf, msg, wParam, lParam );
440             else
441                 SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
442                                (WPARAM16)SC_KEYMENU, (LPARAM)(DWORD)wParam );
443         } 
444         else /* check for Ctrl-Esc */
445             if (wParam != VK_ESCAPE) MessageBeep(0);
446         break;
447
448     case WM_SHOWWINDOW:
449         if (!lParam) return 0; /* sent from ShowWindow */
450         if (!(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner) return 0;
451         if ((wndPtr->dwStyle & WS_VISIBLE) && wParam) return 0;
452         else if (!(wndPtr->dwStyle & WS_VISIBLE) && !wParam) return 0;
453         ShowWindow( wndPtr->hwndSelf, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
454         break; 
455
456     case WM_CANCELMODE:
457         if (wndPtr->parent == WIN_GetDesktop()) EndMenu();
458         if (GetCapture() == wndPtr->hwndSelf) ReleaseCapture();
459         WIN_ReleaseDesktop();
460         break;
461
462     case WM_VKEYTOITEM:
463     case WM_CHARTOITEM:
464         return -1;
465
466     case WM_DROPOBJECT:
467         return DRAG_FILE;  
468
469     case WM_QUERYDROPOBJECT:
470         if (wndPtr->dwExStyle & WS_EX_ACCEPTFILES) return 1;
471         break;
472
473     case WM_QUERYDRAGICON:
474         {
475             HICON16 hIcon=0;
476             UINT16 len;
477
478             if( (hIcon=wndPtr->class->hCursor) ) return (LRESULT)hIcon;
479             for(len=1; len<64; len++)
480                 if((hIcon=LoadIcon16(wndPtr->hInstance,MAKEINTRESOURCE16(len))))
481                     return (LRESULT)hIcon;
482             return (LRESULT)LoadIcon16(0,IDI_APPLICATION16);
483         }
484         break;
485
486     case WM_ISACTIVEICON:
487         return ((wndPtr->flags & WIN_NCACTIVATED) != 0);
488
489     case WM_NOTIFYFORMAT:
490       if (IsWindowUnicode(wndPtr->hwndSelf)) return NFR_UNICODE;
491       else return NFR_ANSI;
492         
493     case WM_QUERYOPEN:
494     case WM_QUERYENDSESSION:
495         return 1;
496
497     case WM_SETICON:
498         {
499                 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
500                 HICON16 hOldIcon = GetClassLongA(wndPtr->hwndSelf, index); 
501                 SetClassLongA(wndPtr->hwndSelf, index, lParam);
502
503                 SetWindowPos(wndPtr->hwndSelf, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
504                          | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE
505                          | SWP_NOZORDER);
506
507                 if( wndPtr->flags & WIN_NATIVE )
508                     wndPtr->pDriver->pSetHostAttr(wndPtr, HAK_ICONS, 0);
509
510                 return hOldIcon;
511         }
512
513     case WM_GETICON:
514         {
515                 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
516                 return GetClassLongA(wndPtr->hwndSelf, index); 
517         }
518
519     case WM_HELP:
520         SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
521         break;
522     }
523
524     return 0;
525 }
526
527
528
529 /***********************************************************************
530  *           DefWindowProc16   (USER.107)
531  */
532 LRESULT WINAPI DefWindowProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
533                                 LPARAM lParam )
534 {
535     WND * wndPtr = WIN_FindWndPtr( hwnd );
536     LRESULT result = 0;
537
538     if (!wndPtr) return 0;
539     SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
540
541     switch(msg)
542     {
543     case WM_NCCREATE:
544         {
545             CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
546             if (cs->lpszName)
547                 DEFWND_SetTextA( wndPtr, (LPCSTR)PTR_SEG_TO_LIN(cs->lpszName) );
548             result = 1;
549         }
550         break;
551
552     case WM_NCCALCSIZE:
553         {
554             RECT rect32;
555             CONV_RECT16TO32( (RECT16 *)PTR_SEG_TO_LIN(lParam), &rect32 );
556             result = NC_HandleNCCalcSize( wndPtr, &rect32 );
557             CONV_RECT32TO16( &rect32, (RECT16 *)PTR_SEG_TO_LIN(lParam) );
558         }
559         break;
560
561     case WM_WINDOWPOSCHANGING:
562         result = WINPOS_HandleWindowPosChanging16( wndPtr,
563                                        (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam) );
564         break;
565
566     case WM_WINDOWPOSCHANGED:
567         {
568             WINDOWPOS16 * winPos = (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam);
569             DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
570         }
571         break;
572
573     case WM_GETTEXT:
574         if (wParam && wndPtr->text)
575         {
576             lstrcpynWtoA( (LPSTR)PTR_SEG_TO_LIN(lParam), wndPtr->text, wParam );
577             result = (LRESULT)strlen( (LPSTR)PTR_SEG_TO_LIN(lParam) );
578         }
579         break;
580
581     case WM_SETTEXT:
582         DEFWND_SetTextA( wndPtr, (LPCSTR)PTR_SEG_TO_LIN(lParam) );
583         if( wndPtr->dwStyle & WS_CAPTION ) NC_HandleNCPaint( hwnd , (HRGN)1 );
584         break;
585
586     default:
587         result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
588         break;
589     }
590
591     WIN_ReleaseWndPtr(wndPtr);
592     SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result );
593     return result;
594 }
595
596
597 /***********************************************************************
598  *  DefWindowProcA [USER32.126] 
599  *
600  */
601 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam,
602                                  LPARAM lParam )
603 {
604     WND * wndPtr = WIN_FindWndPtr( hwnd );
605     LRESULT result = 0;
606
607     if (!wndPtr) return 0;
608     SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
609
610     switch(msg)
611     {
612     case WM_NCCREATE:
613         {
614             CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
615             if (cs->lpszName) DEFWND_SetTextA( wndPtr, cs->lpszName );
616             result = 1;
617         }
618         break;
619
620     case WM_NCCALCSIZE:
621         result = NC_HandleNCCalcSize( wndPtr, (RECT *)lParam );
622         break;
623
624     case WM_WINDOWPOSCHANGING:
625         result = WINPOS_HandleWindowPosChanging( wndPtr,
626                                                    (WINDOWPOS *)lParam );
627         break;
628
629     case WM_WINDOWPOSCHANGED:
630         {
631             WINDOWPOS * winPos = (WINDOWPOS *)lParam;
632             DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
633         }
634         break;
635
636     case WM_GETTEXT:
637         if (wParam && wndPtr->text)
638         {
639             lstrcpynWtoA( (LPSTR)lParam, wndPtr->text, wParam );
640             result = (LRESULT)strlen( (LPSTR)lParam );
641         }
642         break;
643
644     case WM_SETTEXT:
645         DEFWND_SetTextA( wndPtr, (LPCSTR)lParam );
646         NC_HandleNCPaint( hwnd , (HRGN)1 );  /* Repaint caption */
647         break;
648
649     default:
650         result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
651         break;
652     }
653
654     WIN_ReleaseWndPtr(wndPtr);
655     SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result );
656     return result;
657 }
658
659
660 /***********************************************************************
661  * DefWindowProcW [USER32.127] Calls default window message handler
662  * 
663  * Calls default window procedure for messages not processed 
664  *  by application.
665  *
666  *  RETURNS
667  *     Return value is dependent upon the message.
668 */
669 LRESULT WINAPI DefWindowProcW( 
670     HWND hwnd,      /* [in] window procedure recieving message */
671     UINT msg,       /* [in] message identifier */
672     WPARAM wParam,  /* [in] first message parameter */
673     LPARAM lParam )   /* [in] second message parameter */
674 {
675     WND * wndPtr = WIN_FindWndPtr( hwnd );
676     LRESULT result = 0;
677
678     if (!wndPtr) return 0;
679     switch(msg)
680     {
681     case WM_NCCREATE:
682         {
683             CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
684             if (cs->lpszName) DEFWND_SetTextW( wndPtr, cs->lpszName );
685             result = 1;
686         }
687         break;
688
689     case WM_GETTEXT:
690         if (wParam && wndPtr->text)
691         {
692             lstrcpynW( (LPWSTR)lParam, wndPtr->text, wParam );
693             result = strlenW( (LPWSTR)lParam );
694         }
695         break;
696
697     case WM_SETTEXT:
698         DEFWND_SetTextW( wndPtr, (LPCWSTR)lParam );
699         NC_HandleNCPaint( hwnd , (HRGN)1 );  /* Repaint caption */
700         break;
701
702     default:
703         result = DefWindowProcA( hwnd, msg, wParam, lParam );
704         break;
705     }
706     WIN_ReleaseWndPtr(wndPtr);
707     return result;
708 }