Release 960331
[wine.git] / windows / defwnd.c
blobd081f22ae59cf4e97575d08c0737a10da09f4255
1 /*
2 * Default window procedure
4 * Copyright 1993 Alexandre Julliard
5 * 1995 Alex Korobka
6 */
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "win.h"
11 #include "class.h"
12 #include "user.h"
13 #include "nonclient.h"
14 #include "winpos.h"
15 #include "syscolor.h"
16 #include "stddebug.h"
17 /* #define DEBUG_MESSAGE */
18 #include "debug.h"
19 #include "spy.h"
21 /* Last COLOR id */
22 #define COLOR_MAX COLOR_BTNHIGHLIGHT
24 /* bits in the dwKeyData */
25 #define KEYDATA_ALT 0x2000
26 #define KEYDATA_PREVSTATE 0x4000
28 static short iF10Key = 0;
29 static short iMenuSysKey = 0;
31 /***********************************************************************
32 * DEFWND_SetText
34 * Set the window text.
36 void DEFWND_SetText( HWND hwnd, LPSTR text )
38 LPSTR textPtr;
39 WND *wndPtr = WIN_FindWndPtr( hwnd );
41 if (!text) text = "";
42 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
43 wndPtr->hText = USER_HEAP_ALLOC( strlen(text) + 1 );
44 textPtr = (LPSTR) USER_HEAP_LIN_ADDR( wndPtr->hText );
45 strcpy( textPtr, text );
46 if (wndPtr->window)
47 XStoreName( display, wndPtr->window, text );
51 /***********************************************************************
52 * DefWindowProc (USER.107)
54 LRESULT DefWindowProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
56 CLASS * classPtr;
57 LPSTR textPtr;
58 int len;
59 WND * wndPtr = WIN_FindWndPtr( hwnd );
61 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
63 switch(msg)
65 case WM_NCCREATE:
67 CREATESTRUCT *createStruct = (CREATESTRUCT*)PTR_SEG_TO_LIN(lParam);
68 if (createStruct->lpszName)
69 DEFWND_SetText( hwnd,
70 (LPSTR)PTR_SEG_TO_LIN(createStruct->lpszName) );
71 return 1;
74 case WM_NCCALCSIZE:
75 return NC_HandleNCCalcSize( hwnd,
76 (NCCALCSIZE_PARAMS *)PTR_SEG_TO_LIN(lParam) );
78 case WM_PAINTICON:
79 case WM_NCPAINT:
80 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
82 case WM_NCHITTEST:
84 POINT pt = { LOWORD(lParam), HIWORD(lParam) };
85 return NC_HandleNCHitTest( hwnd, pt );
88 case WM_NCLBUTTONDOWN:
89 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
91 case WM_LBUTTONDBLCLK:
92 case WM_NCLBUTTONDBLCLK:
93 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
95 case WM_NCACTIVATE:
96 return NC_HandleNCActivate( hwnd, wParam );
98 case WM_NCDESTROY:
99 if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
100 if (wndPtr->hVScroll) USER_HEAP_FREE(wndPtr->hVScroll);
101 if (wndPtr->hHScroll) USER_HEAP_FREE(wndPtr->hHScroll);
102 wndPtr->hText = wndPtr->hVScroll = wndPtr->hHScroll = 0;
103 return 0;
105 case WM_PAINT:
107 PAINTSTRUCT paintstruct;
108 BeginPaint( hwnd, &paintstruct );
109 EndPaint( hwnd, &paintstruct );
110 return 0;
113 case WM_SETREDRAW:
114 if (!wParam)
116 ValidateRect( hwnd, NULL );
117 wndPtr->flags |= WIN_NO_REDRAW;
119 else wndPtr->flags &= ~WIN_NO_REDRAW;
120 return 0;
122 case WM_CLOSE:
123 DestroyWindow( hwnd );
124 return 0;
126 case WM_MOUSEACTIVATE:
127 if (wndPtr->dwStyle & WS_CHILD)
129 LONG ret = SendMessage( wndPtr->parent->hwndSelf, WM_MOUSEACTIVATE,
130 wParam, lParam );
131 if (ret) return ret;
133 return MA_ACTIVATE;
135 case WM_ACTIVATE:
136 /* LOWORD() needed for WINELIB32 implementation. Should be fine. */
137 if (LOWORD(wParam)!=WA_INACTIVE) SetFocus( hwnd );
138 break;
140 case WM_WINDOWPOSCHANGING:
141 return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)PTR_SEG_TO_LIN(lParam) );
143 case WM_WINDOWPOSCHANGED:
145 /* Note: Windoze uses unknown SWP flags 0x1000 and 0x0800 to
146 * decide whether to send WM_MOVE or/and WM_SIZE respectively
149 WINDOWPOS * winPos = (WINDOWPOS *)PTR_SEG_TO_LIN(lParam);
150 WPARAM wp = SIZE_RESTORED;
152 if (!(winPos->flags & SWP_NOMOVE))
153 SendMessage( hwnd, WM_MOVE, 0,
154 MAKELONG( wndPtr->rectClient.left,
155 wndPtr->rectClient.top ));
156 if (!(winPos->flags & SWP_NOSIZE))
158 if( wndPtr->dwStyle & WS_MAXIMIZE ) wp = SIZE_MAXIMIZED;
159 else if(wndPtr->dwStyle & WS_MINIMIZE ) wp = SIZE_MINIMIZED;
161 SendMessage( hwnd, WM_SIZE, wp,
162 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
163 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
166 return 0;
169 case WM_ERASEBKGND:
170 case WM_ICONERASEBKGND:
172 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
173 if (!classPtr->wc.hbrBackground) return 0;
174 if (classPtr->wc.hbrBackground <= (HBRUSH)(COLOR_MAX+1))
176 HBRUSH hbrush;
177 hbrush = CreateSolidBrush(
178 GetSysColor(((DWORD)classPtr->wc.hbrBackground)-1));
179 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
180 DeleteObject (hbrush);
182 else
183 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
184 classPtr->wc.hbrBackground );
185 return 1;
188 case WM_GETDLGCODE:
189 return 0;
191 case WM_CTLCOLORMSGBOX:
192 case WM_CTLCOLOREDIT:
193 case WM_CTLCOLORLISTBOX:
194 case WM_CTLCOLORBTN:
195 case WM_CTLCOLORDLG:
196 case WM_CTLCOLORSTATIC:
197 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
198 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
199 return (LONG)sysColorObjects.hbrushWindow;
201 case WM_CTLCOLORSCROLLBAR:
202 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
203 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
204 UnrealizeObject( sysColorObjects.hbrushScrollbar );
205 return (LONG)sysColorObjects.hbrushScrollbar;
207 case WM_CTLCOLOR:
209 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
211 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
212 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
213 UnrealizeObject( sysColorObjects.hbrushScrollbar );
214 return (LONG)sysColorObjects.hbrushScrollbar;
216 else
218 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
219 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
220 return (LONG)sysColorObjects.hbrushWindow;
224 case WM_GETTEXT:
226 if (wParam)
228 if (wndPtr->hText)
230 textPtr = (LPSTR)USER_HEAP_LIN_ADDR(wndPtr->hText);
231 if ((int)wParam > (len = strlen(textPtr)))
233 strcpy((char *)PTR_SEG_TO_LIN(lParam), textPtr);
234 return (DWORD)len;
238 return 0;
241 case WM_GETTEXTLENGTH:
243 if (wndPtr->hText)
245 textPtr = (LPSTR)USER_HEAP_LIN_ADDR(wndPtr->hText);
246 return (DWORD)strlen(textPtr);
248 return 0;
251 case WM_SETTEXT:
252 DEFWND_SetText( hwnd, (LPSTR)PTR_SEG_TO_LIN(lParam) );
253 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
254 return 0;
256 case WM_SETCURSOR:
257 if (wndPtr->dwStyle & WS_CHILD)
258 if (SendMessage(wndPtr->parent->hwndSelf, WM_SETCURSOR,
259 wParam, lParam))
260 return TRUE;
261 return NC_HandleSetCursor( hwnd, wParam, lParam );
263 case WM_SYSCOMMAND:
265 POINT pt = { LOWORD(lParam), HIWORD(lParam) };
266 return NC_HandleSysCommand( hwnd, wParam, pt );
268 case WM_KEYDOWN:
270 if(wParam == VK_F10) iF10Key = VK_F10;
271 break;
273 case WM_SYSKEYDOWN:
275 if( HIWORD(lParam) & KEYDATA_ALT )
277 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
278 if( wParam == VK_MENU && !iMenuSysKey )
279 iMenuSysKey = 1;
280 else
281 iMenuSysKey = 0;
283 iF10Key = 0;
286 else if( wParam == VK_F10 )
287 iF10Key = 1;
288 else
289 if( wParam == VK_ESCAPE && GetKeyState(VK_SHIFT) < 0 )
290 SendMessage( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU,
291 (LPARAM)VK_SPACE);
292 break;
294 case WM_KEYUP:
295 case WM_SYSKEYUP:
297 /* Press and release F10 or ALT */
299 if( ( wParam == VK_MENU && iMenuSysKey )
300 || ( wParam == VK_F10 && iF10Key ) )
302 SendMessage( WIN_GetTopParent(hwnd), WM_SYSCOMMAND,
303 SC_KEYMENU, 0L );
305 iMenuSysKey = iF10Key = 0;
306 break;
308 case WM_SYSCHAR:
310 iMenuSysKey = 0;
312 if( wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE) )
314 PostMessage(hwnd, WM_SYSCOMMAND, (WPARAM)SC_RESTORE, 0L );
315 break;
318 if( (HIWORD(lParam) & KEYDATA_ALT) && wParam )
320 if( wParam == VK_TAB || wParam == VK_ESCAPE )
321 break;
323 if( wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD) )
324 SendMessage( wndPtr->parent->hwndSelf, msg, wParam, lParam );
325 else
326 SendMessage(hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
328 else
329 /* check for Ctrl-Esc */
330 if( wParam != VK_ESCAPE )
331 MessageBeep(0);
333 break;
335 case WM_SHOWWINDOW:
336 if( !lParam ) return 0; /* sent from ShowWindow */
338 if( !(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner )
339 return 0;
341 if( wndPtr->dwStyle & WS_VISIBLE )
342 { if( wParam ) return 0; }
343 else
344 if(!wParam ) return 0;
346 ShowWindow(hwnd,(wParam)? SW_SHOWNOACTIVATE: SW_HIDE);
347 break;
349 case WM_CANCELMODE:
351 /* EndMenu() should be called if in menu state but currently it's
352 impossible to detect - menu code should be updated*/
354 if( GetCapture() == hwnd )
355 ReleaseCapture();
357 break;
359 case WM_VKEYTOITEM:
360 case WM_CHARTOITEM:
361 return -1;
363 case WM_DROPOBJECT:
364 return DRAG_FILE;
366 case WM_QUERYDROPOBJECT:
367 if(wndPtr->dwExStyle & WS_EX_ACCEPTFILES)
368 return 1;
369 break;
371 case WM_QUERYDRAGICON:
373 HICON hI = 0;
375 len = 1;
376 while(len < 64)
377 if( (hI = LoadIcon(wndPtr->hInstance,MAKEINTRESOURCE(len))) )
378 return (LRESULT)hI;
380 break;
382 case WM_QUERYOPEN:
383 case WM_QUERYENDSESSION:
384 return 1;
387 return 0;