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