Release 940804
[wine] / windows / defwnd.c
1 /*
2  * Default window procedure
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
8
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include "windows.h"
12 #include "win.h"
13 #include "class.h"
14 #include "user.h"
15 #include "syscolor.h"
16
17   /* Last COLOR id */
18 #define COLOR_MAX   COLOR_BTNHIGHLIGHT
19
20 extern LONG NC_HandleNCPaint( HWND hwnd, HRGN hrgn );
21 extern LONG NC_HandleNCActivate( HWND hwnd, WORD wParam );
22 extern LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params );
23 extern LONG NC_HandleNCHitTest( HWND hwnd, POINT pt );
24 extern LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam );
25 extern LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam );
26 extern LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt );
27 extern LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam );
28 extern LONG WINPOS_HandleWindowPosChanging( WINDOWPOS *winpos ); /* winpos.c */
29 extern void NC_TrackSysMenu( HWND hwnd ); /* menu.c */
30 extern BOOL ActivateMenuBarFocus(HWND hWnd); /* menu.c */
31
32
33
34 /***********************************************************************
35  *           DEFWND_SetText
36  *
37  * Set the window text.
38  */
39 void DEFWND_SetText( HWND hwnd, LPSTR text )
40 {
41     LPSTR textPtr;
42     WND *wndPtr = WIN_FindWndPtr( hwnd );
43
44     if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
45     wndPtr->hText = USER_HEAP_ALLOC( LMEM_MOVEABLE, strlen(text) + 1 );
46     textPtr = (LPSTR) USER_HEAP_ADDR( wndPtr->hText );
47     strcpy( textPtr, text );
48 }
49
50
51 /***********************************************************************
52  *           DefWindowProc   (USER.107)
53  */
54 LONG DefWindowProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
55 {
56         MEASUREITEMSTRUCT *measure;
57         CLASS * classPtr;
58         LPSTR textPtr;
59         int len;
60         WND * wndPtr = WIN_FindWndPtr( hwnd );
61     
62 #ifdef DEBUG_MESSAGE
63     printf( "DefWindowProc: %d %d %d %08x\n", hwnd, msg, wParam, lParam );
64 #endif
65
66     switch(msg)
67     {
68     case WM_NCCREATE:
69         {
70             CREATESTRUCT * createStruct = (CREATESTRUCT *)lParam;
71             if (createStruct->lpszName)
72                 DEFWND_SetText( hwnd, createStruct->lpszName );
73             if ((createStruct->style & WS_VSCROLL) ||
74                 (createStruct->style & WS_HSCROLL)) NC_CreateScrollBars(hwnd);
75             return 1;
76         }
77
78     case WM_NCCALCSIZE:
79         return NC_HandleNCCalcSize( hwnd, (NCCALCSIZE_PARAMS *)lParam );
80
81     case WM_NCPAINT:
82         return NC_HandleNCPaint( hwnd, (HRGN)wParam );
83
84     case WM_PAINTICON:
85         printf("going to call NC_HandleNCPaintIcon\n");
86         return NC_HandleNCPaintIcon( hwnd );
87
88
89     case WM_NCHITTEST:
90         return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
91
92     case WM_NCLBUTTONDOWN:
93         return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
94
95     case WM_NCLBUTTONDBLCLK:
96         return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
97
98     case WM_NCACTIVATE:
99         return NC_HandleNCActivate( hwnd, wParam );
100
101     case WM_NCDESTROY:
102         if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
103         wndPtr->hText = 0;
104         if (wndPtr->VScroll) free(wndPtr->VScroll);
105         if (wndPtr->HScroll) free(wndPtr->HScroll);
106         return 0;
107         
108     case WM_PAINT:
109         {
110             PAINTSTRUCT paintstruct;
111             BeginPaint( hwnd, &paintstruct );
112             EndPaint( hwnd, &paintstruct );
113             return 0;
114         }
115
116     case WM_CLOSE:
117         DestroyWindow( hwnd );
118         return 0;
119
120     case WM_MOUSEACTIVATE:
121         if (wndPtr->dwStyle & WS_CHILD)
122         {
123             LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
124                                     wParam, lParam );
125             if (ret) return ret;
126         }
127         return MA_ACTIVATE;
128
129     case WM_ACTIVATE:
130         if (wParam) SetFocus( hwnd );
131         break;
132
133     case WM_WINDOWPOSCHANGING:
134         return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)lParam );
135
136     case WM_WINDOWPOSCHANGED:
137         {
138             WINDOWPOS * winPos = (WINDOWPOS *)lParam;
139             if (!(winPos->flags & SWP_NOMOVE))
140                 SendMessage( hwnd, WM_MOVE, 0,
141                              MAKELONG( wndPtr->rectClient.left,
142                                        wndPtr->rectClient.top ));
143             if (!(winPos->flags & SWP_NOSIZE))
144                 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
145                    MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
146                             wndPtr->rectClient.bottom-wndPtr->rectClient.top));
147             return 0;
148         }
149
150     case WM_ERASEBKGND:
151     case WM_ICONERASEBKGND:
152         {
153             if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 1;
154             if (!classPtr->wc.hbrBackground) return 1;
155             if (classPtr->wc.hbrBackground <= COLOR_MAX+1)
156             {
157                  HBRUSH hbrush;
158                  hbrush = CreateSolidBrush(
159                      GetSysColor(classPtr->wc.hbrBackground-1));
160                  FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
161                  DeleteObject (hbrush);
162             }
163             else
164                  FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
165                         classPtr->wc.hbrBackground );
166             return 0;
167         }
168
169     case WM_GETDLGCODE:
170         return 0;
171
172     case WM_CTLCOLOR:
173         {
174             if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
175             {
176                 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
177                 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
178                 UnrealizeObject( sysColorObjects.hbrushScrollbar );
179                 return sysColorObjects.hbrushScrollbar;
180             }
181             else
182             {
183                 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
184                 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
185                 return sysColorObjects.hbrushWindow;
186             }
187         }
188         
189     case WM_GETTEXT:
190         {
191             if (wParam)
192             {
193                 if (wndPtr->hText)
194                 {
195                     textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
196                     if ((int)wParam > (len = strlen(textPtr)))
197                     {
198                         strcpy((char *)lParam, textPtr);
199                         return (DWORD)len;
200                     }
201                 }
202                 lParam = (DWORD)NULL;
203             }
204             return (0L);
205         }
206
207     case WM_GETTEXTLENGTH:
208         {
209             if (wndPtr->hText)
210             {
211                 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
212                 return (DWORD)strlen(textPtr);
213             }
214             return (0L);
215         }
216
217     case WM_SETTEXT:
218         DEFWND_SetText( hwnd, (LPSTR)lParam );
219         NC_HandleNCPaint( hwnd, (HRGN)1 );  /* Repaint caption */
220         return 0;
221
222     case WM_SETCURSOR:
223         if (wndPtr->dwStyle & WS_CHILD)
224             if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
225                 return TRUE;
226         return NC_HandleSetCursor( hwnd, wParam, lParam );
227
228     case WM_SYSCOMMAND:
229         return NC_HandleSysCommand( hwnd, wParam, MAKEPOINT(lParam) );
230
231     case WM_SYSKEYDOWN:
232                 if (wParam == VK_MENU) ActivateMenuBarFocus(hwnd);
233                 break;          
234     case WM_SYSKEYUP:
235                 break;          
236     case WM_MENUCHAR:
237                 MessageBeep(0);
238                 break;          
239     case WM_MEASUREITEM:
240                 measure = (MEASUREITEMSTRUCT *)lParam;
241                 switch(measure->CtlType) {
242                         case ODT_BUTTON:
243                                 break;
244                         case ODT_COMBOBOX:
245                                 measure->itemHeight = 10;
246 /*                              printf("defwndproc WM_MEASUREITEM // ODT_COMBOBOX !\n");*/
247                                 break;
248                         case ODT_LISTBOX:
249                                 measure->itemHeight = 10;
250 /*                              printf("defwndproc WM_MEASUREITEM // ODT_LISTBOX !\n");*/
251                                 break;
252                         case ODT_MENU:
253                                 break;
254                         default:
255                                 break;
256                         }
257         break;          
258     }
259     return 0;
260 }