Release 960428
[wine/multimedia.git] / windows / defwnd.c
blobcce73112e7e4e339563b88ad77d155bade6f752a
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 "user.h"
12 #include "nonclient.h"
13 #include "winpos.h"
14 #include "syscolor.h"
15 #include "stddebug.h"
16 /* #define DEBUG_MESSAGE */
17 #include "debug.h"
18 #include "spy.h"
20 /* Last COLOR id */
21 #define COLOR_MAX COLOR_BTNHIGHLIGHT
23 /* bits in the dwKeyData */
24 #define KEYDATA_ALT 0x2000
25 #define KEYDATA_PREVSTATE 0x4000
27 static short iF10Key = 0;
28 static short iMenuSysKey = 0;
30 /***********************************************************************
31 * DEFWND_SetText
33 * Set the window text.
35 void DEFWND_SetText( WND *wndPtr, LPSTR text )
37 LPSTR textPtr;
39 if (!text) text = "";
40 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
41 wndPtr->hText = USER_HEAP_ALLOC( strlen(text) + 1 );
42 textPtr = (LPSTR) USER_HEAP_LIN_ADDR( wndPtr->hText );
43 strcpy( textPtr, text );
44 if (wndPtr->window)
45 XStoreName( display, wndPtr->window, text );
49 /***********************************************************************
50 * DefWindowProc (USER.107)
52 LRESULT DefWindowProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
54 LPSTR textPtr;
55 int len;
56 WND * wndPtr = WIN_FindWndPtr( hwnd );
58 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
60 switch(msg)
62 case WM_NCCREATE:
64 CREATESTRUCT *createStruct = (CREATESTRUCT*)PTR_SEG_TO_LIN(lParam);
65 if (createStruct->lpszName)
66 DEFWND_SetText( wndPtr,
67 (LPSTR)PTR_SEG_TO_LIN(createStruct->lpszName) );
68 return 1;
71 case WM_NCCALCSIZE:
72 return NC_HandleNCCalcSize( hwnd,
73 (NCCALCSIZE_PARAMS *)PTR_SEG_TO_LIN(lParam) );
75 case WM_PAINTICON:
76 case WM_NCPAINT:
77 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
79 case WM_NCHITTEST:
81 POINT pt = { LOWORD(lParam), HIWORD(lParam) };
82 return NC_HandleNCHitTest( hwnd, pt );
85 case WM_NCLBUTTONDOWN:
86 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
88 case WM_LBUTTONDBLCLK:
89 case WM_NCLBUTTONDBLCLK:
90 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
92 case WM_NCACTIVATE:
93 return NC_HandleNCActivate( hwnd, wParam );
95 case WM_NCDESTROY:
96 if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
97 if (wndPtr->hVScroll) USER_HEAP_FREE(wndPtr->hVScroll);
98 if (wndPtr->hHScroll) USER_HEAP_FREE(wndPtr->hHScroll);
99 wndPtr->hText = wndPtr->hVScroll = wndPtr->hHScroll = 0;
100 return 0;
102 case WM_PAINT:
104 PAINTSTRUCT paintstruct;
105 BeginPaint( hwnd, &paintstruct );
106 EndPaint( hwnd, &paintstruct );
107 return 0;
110 case WM_SETREDRAW:
111 if (!wParam)
113 ValidateRect( hwnd, NULL );
114 wndPtr->flags |= WIN_NO_REDRAW;
116 else wndPtr->flags &= ~WIN_NO_REDRAW;
117 return 0;
119 case WM_CLOSE:
120 DestroyWindow( hwnd );
121 return 0;
123 case WM_MOUSEACTIVATE:
124 if (wndPtr->dwStyle & WS_CHILD)
126 LONG ret = SendMessage( wndPtr->parent->hwndSelf, WM_MOUSEACTIVATE,
127 wParam, lParam );
128 if (ret) return ret;
130 return MA_ACTIVATE;
132 case WM_ACTIVATE:
133 /* LOWORD() needed for WINELIB32 implementation. Should be fine. */
134 if (LOWORD(wParam)!=WA_INACTIVE) SetFocus( hwnd );
135 break;
137 case WM_WINDOWPOSCHANGING:
138 return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)PTR_SEG_TO_LIN(lParam) );
140 case WM_WINDOWPOSCHANGED:
142 WINDOWPOS * winPos = (WINDOWPOS *)PTR_SEG_TO_LIN(lParam);
143 WPARAM wp = SIZE_RESTORED;
145 if (!(winPos->flags & SWP_NOCLIENTMOVE))
146 SendMessage( hwnd, WM_MOVE, 0,
147 MAKELONG( wndPtr->rectClient.left,
148 wndPtr->rectClient.top ));
149 if (!(winPos->flags & SWP_NOCLIENTSIZE))
151 if( wndPtr->dwStyle & WS_MAXIMIZE ) wp = SIZE_MAXIMIZED;
152 else if(wndPtr->dwStyle & WS_MINIMIZE ) wp = SIZE_MINIMIZED;
154 SendMessage( hwnd, WM_SIZE, wp,
155 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
156 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
159 return 0;
162 case WM_ERASEBKGND:
163 case WM_ICONERASEBKGND:
165 if (!wndPtr->class->wc.hbrBackground) return 0;
166 if (wndPtr->class->wc.hbrBackground <= (HBRUSH)(COLOR_MAX+1))
168 HBRUSH hbrush;
169 hbrush = CreateSolidBrush(
170 GetSysColor(((DWORD)wndPtr->class->wc.hbrBackground)-1));
171 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
172 DeleteObject (hbrush);
174 else
175 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
176 wndPtr->class->wc.hbrBackground );
177 return 1;
180 case WM_GETDLGCODE:
181 return 0;
183 case WM_CTLCOLORMSGBOX:
184 case WM_CTLCOLOREDIT:
185 case WM_CTLCOLORLISTBOX:
186 case WM_CTLCOLORBTN:
187 case WM_CTLCOLORDLG:
188 case WM_CTLCOLORSTATIC:
189 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
190 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
191 return (LONG)sysColorObjects.hbrushWindow;
193 case WM_CTLCOLORSCROLLBAR:
194 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
195 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
196 UnrealizeObject( sysColorObjects.hbrushScrollbar );
197 return (LONG)sysColorObjects.hbrushScrollbar;
199 case WM_CTLCOLOR:
201 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
203 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
204 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
205 UnrealizeObject( sysColorObjects.hbrushScrollbar );
206 return (LONG)sysColorObjects.hbrushScrollbar;
208 else
210 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
211 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
212 return (LONG)sysColorObjects.hbrushWindow;
216 case WM_GETTEXT:
218 if (wParam)
220 if (wndPtr->hText)
222 textPtr = (LPSTR)USER_HEAP_LIN_ADDR(wndPtr->hText);
223 if ((int)wParam > (len = strlen(textPtr)))
225 strcpy((char *)PTR_SEG_TO_LIN(lParam), textPtr);
226 return (DWORD)len;
230 return 0;
233 case WM_GETTEXTLENGTH:
235 if (wndPtr->hText)
237 textPtr = (LPSTR)USER_HEAP_LIN_ADDR(wndPtr->hText);
238 return (DWORD)strlen(textPtr);
240 return 0;
243 case WM_SETTEXT:
244 DEFWND_SetText( wndPtr, (LPSTR)PTR_SEG_TO_LIN(lParam) );
245 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
246 return 0;
248 case WM_SETCURSOR:
249 if (wndPtr->dwStyle & WS_CHILD)
250 if (SendMessage(wndPtr->parent->hwndSelf, WM_SETCURSOR,
251 wParam, lParam))
252 return TRUE;
253 return NC_HandleSetCursor( hwnd, wParam, lParam );
255 case WM_SYSCOMMAND:
257 POINT pt = { LOWORD(lParam), HIWORD(lParam) };
258 return NC_HandleSysCommand( hwnd, wParam, pt );
260 case WM_KEYDOWN:
262 if(wParam == VK_F10) iF10Key = VK_F10;
263 break;
265 case WM_SYSKEYDOWN:
267 if( HIWORD(lParam) & KEYDATA_ALT )
269 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
270 if( wParam == VK_MENU && !iMenuSysKey )
271 iMenuSysKey = 1;
272 else
273 iMenuSysKey = 0;
275 iF10Key = 0;
278 else if( wParam == VK_F10 )
279 iF10Key = 1;
280 else
281 if( wParam == VK_ESCAPE && GetKeyState(VK_SHIFT) < 0 )
282 SendMessage( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU,
283 (LPARAM)VK_SPACE);
284 break;
286 case WM_KEYUP:
287 case WM_SYSKEYUP:
289 /* Press and release F10 or ALT */
291 if( ( wParam == VK_MENU && iMenuSysKey )
292 || ( wParam == VK_F10 && iF10Key ) )
294 SendMessage( WIN_GetTopParent(hwnd), WM_SYSCOMMAND,
295 SC_KEYMENU, 0L );
297 iMenuSysKey = iF10Key = 0;
298 break;
300 case WM_SYSCHAR:
302 iMenuSysKey = 0;
304 if( wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE) )
306 PostMessage(hwnd, WM_SYSCOMMAND, (WPARAM)SC_RESTORE, 0L );
307 break;
310 if( (HIWORD(lParam) & KEYDATA_ALT) && wParam )
312 if( wParam == VK_TAB || wParam == VK_ESCAPE )
313 break;
315 if( wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD) )
316 SendMessage( wndPtr->parent->hwndSelf, msg, wParam, lParam );
317 else
318 SendMessage(hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
320 else
321 /* check for Ctrl-Esc */
322 if( wParam != VK_ESCAPE )
323 MessageBeep(0);
325 break;
327 case WM_SHOWWINDOW:
328 if( !lParam ) return 0; /* sent from ShowWindow */
330 if( !(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner )
331 return 0;
333 if( wndPtr->dwStyle & WS_VISIBLE )
334 { if( wParam ) return 0; }
335 else
336 if(!wParam ) return 0;
338 ShowWindow(hwnd,(wParam)? SW_SHOWNOACTIVATE: SW_HIDE);
339 break;
341 case WM_CANCELMODE:
343 /* EndMenu() should be called if in menu state but currently it's
344 impossible to detect - menu code should be updated*/
346 if( GetCapture() == hwnd )
347 ReleaseCapture();
349 break;
351 case WM_VKEYTOITEM:
352 case WM_CHARTOITEM:
353 return -1;
355 case WM_DROPOBJECT:
356 return DRAG_FILE;
358 case WM_QUERYDROPOBJECT:
359 if(wndPtr->dwExStyle & WS_EX_ACCEPTFILES)
360 return 1;
361 break;
363 case WM_QUERYDRAGICON:
365 HICON hI = 0;
367 len = 1;
368 while(len < 64)
369 if( (hI = LoadIcon(wndPtr->hInstance,MAKEINTRESOURCE(len))) )
370 return (LRESULT)hI;
372 break;
374 case WM_QUERYOPEN:
375 case WM_QUERYENDSESSION:
376 return 1;
379 return 0;