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