Release 951226
[wine/multimedia.git] / windows / defwnd.c
blob42aad583b46453886e9012388f58b8303a614f7f
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 static short iMenuKey = 0;
25 static short iMenuSysKey = 0;
27 /***********************************************************************
28 * DEFWND_SetText
30 * Set the window text.
32 void DEFWND_SetText( HWND hwnd, LPSTR text )
34 LPSTR textPtr;
35 WND *wndPtr = WIN_FindWndPtr( hwnd );
37 if (!text) text = "";
38 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
39 wndPtr->hText = USER_HEAP_ALLOC( strlen(text) + 1 );
40 textPtr = (LPSTR) USER_HEAP_LIN_ADDR( wndPtr->hText );
41 strcpy( textPtr, text );
42 if (wndPtr->window)
43 XStoreName( display, wndPtr->window, text );
47 /***********************************************************************
48 * DefWindowProc (USER.107)
50 LRESULT DefWindowProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
52 CLASS * classPtr;
53 LPSTR textPtr;
54 int len;
55 WND * wndPtr = WIN_FindWndPtr( hwnd );
57 EnterSpyMessage(SPY_DEFWNDPROC,hwnd,msg,wParam,lParam);
59 switch(msg)
61 case WM_NCCREATE:
63 CREATESTRUCT *createStruct = (CREATESTRUCT*)PTR_SEG_TO_LIN(lParam);
64 if (createStruct->lpszName)
65 DEFWND_SetText( hwnd,
66 (LPSTR)PTR_SEG_TO_LIN(createStruct->lpszName) );
67 return 1;
70 case WM_NCCALCSIZE:
71 return NC_HandleNCCalcSize( hwnd,
72 (NCCALCSIZE_PARAMS *)PTR_SEG_TO_LIN(lParam) );
74 case WM_PAINTICON:
75 case WM_NCPAINT:
76 return NC_HandleNCPaint( hwnd );
78 case WM_NCHITTEST:
80 POINT pt = { LOWORD(lParam), HIWORD(lParam) };
81 return NC_HandleNCHitTest( hwnd, pt );
84 case WM_NCLBUTTONDOWN:
85 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
87 case WM_LBUTTONDBLCLK:
88 case WM_NCLBUTTONDBLCLK:
89 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
91 case WM_NCACTIVATE:
92 return NC_HandleNCActivate( hwnd, wParam );
94 case WM_NCDESTROY:
95 if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
96 if (wndPtr->hVScroll) USER_HEAP_FREE(wndPtr->hVScroll);
97 if (wndPtr->hHScroll) USER_HEAP_FREE(wndPtr->hHScroll);
98 wndPtr->hText = wndPtr->hVScroll = wndPtr->hHScroll = 0;
99 return 0;
101 case WM_PAINT:
103 PAINTSTRUCT paintstruct;
104 BeginPaint( hwnd, &paintstruct );
105 EndPaint( hwnd, &paintstruct );
106 return 0;
109 case WM_SETREDRAW:
110 if (!wParam)
112 ValidateRect( hwnd, NULL );
113 wndPtr->flags |= WIN_NO_REDRAW;
115 else wndPtr->flags &= ~WIN_NO_REDRAW;
116 return 0;
118 case WM_CLOSE:
119 DestroyWindow( hwnd );
120 return 0;
122 case WM_MOUSEACTIVATE:
123 if (wndPtr->dwStyle & WS_CHILD)
125 LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
126 wParam, lParam );
127 if (ret) return ret;
129 return MA_ACTIVATE;
131 case WM_ACTIVATE:
132 /* LOWORD() needed for WINELIB32 implementation. Should be fine. */
133 if (LOWORD(wParam)!=WA_INACTIVE) SetFocus( hwnd );
134 break;
136 case WM_WINDOWPOSCHANGING:
137 return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)PTR_SEG_TO_LIN(lParam) );
139 case WM_WINDOWPOSCHANGED:
141 WINDOWPOS * winPos = (WINDOWPOS *)PTR_SEG_TO_LIN(lParam);
142 if (!(winPos->flags & SWP_NOMOVE))
143 SendMessage( hwnd, WM_MOVE, 0,
144 MAKELONG( wndPtr->rectClient.left,
145 wndPtr->rectClient.top ));
146 if (!(winPos->flags & SWP_NOSIZE))
147 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
148 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
149 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
150 return 0;
153 case WM_ERASEBKGND:
154 case WM_ICONERASEBKGND:
156 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
157 if (!classPtr->wc.hbrBackground) return 0;
158 if (classPtr->wc.hbrBackground <= (HBRUSH)(COLOR_MAX+1))
160 HBRUSH hbrush;
161 hbrush = CreateSolidBrush(
162 GetSysColor(((DWORD)classPtr->wc.hbrBackground)-1));
163 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
164 DeleteObject (hbrush);
166 else
167 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
168 classPtr->wc.hbrBackground );
169 return 1;
172 case WM_GETDLGCODE:
173 return 0;
175 case WM_CTLCOLORMSGBOX:
176 case WM_CTLCOLOREDIT:
177 case WM_CTLCOLORLISTBOX:
178 case WM_CTLCOLORBTN:
179 case WM_CTLCOLORDLG:
180 case WM_CTLCOLORSTATIC:
181 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
182 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
183 return (LONG)sysColorObjects.hbrushWindow;
185 case WM_CTLCOLORSCROLLBAR:
186 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
187 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
188 UnrealizeObject( sysColorObjects.hbrushScrollbar );
189 return (LONG)sysColorObjects.hbrushScrollbar;
191 case WM_CTLCOLOR:
193 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
195 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
196 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
197 UnrealizeObject( sysColorObjects.hbrushScrollbar );
198 return (LONG)sysColorObjects.hbrushScrollbar;
200 else
202 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
203 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
204 return (LONG)sysColorObjects.hbrushWindow;
208 case WM_GETTEXT:
210 if (wParam)
212 if (wndPtr->hText)
214 textPtr = (LPSTR)USER_HEAP_LIN_ADDR(wndPtr->hText);
215 if ((int)wParam > (len = strlen(textPtr)))
217 strcpy((char *)PTR_SEG_TO_LIN(lParam), textPtr);
218 return (DWORD)len;
222 return 0;
225 case WM_GETTEXTLENGTH:
227 if (wndPtr->hText)
229 textPtr = (LPSTR)USER_HEAP_LIN_ADDR(wndPtr->hText);
230 return (DWORD)strlen(textPtr);
232 return 0;
235 case WM_SETTEXT:
236 DEFWND_SetText( hwnd, (LPSTR)PTR_SEG_TO_LIN(lParam) );
237 NC_HandleNCPaint( hwnd ); /* Repaint caption */
238 return 0;
240 case WM_SETCURSOR:
241 if (wndPtr->dwStyle & WS_CHILD)
242 if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
243 return TRUE;
244 return NC_HandleSetCursor( hwnd, wParam, lParam );
246 case WM_SYSCOMMAND:
248 POINT pt = { LOWORD(lParam), HIWORD(lParam) };
249 return NC_HandleSysCommand( hwnd, wParam, pt );
252 case WM_KEYDOWN:
254 if(wParam == VK_F10) iMenuKey = VK_F10;
255 break;
257 case WM_SYSKEYDOWN:
258 /* this breaks current pseudo accelerators but
259 creates a basis for implementing real ones */
261 if(wParam == VK_F10)
263 iMenuKey = VK_F10;
264 break;
267 if (wParam == VK_MENU)
269 iMenuSysKey = (iMenuSysKey)? 0: 1;
270 iMenuKey = 0;
272 break;
274 case WM_KEYUP:
275 case WM_SYSKEYUP:
277 if( (wParam == VK_MENU && iMenuSysKey) ||
278 (wParam == VK_F10 && iMenuKey) )
280 /* Send to WS_OVERLAPPED parent. TODO: Handle MDI */
281 SendMessage( WIN_GetTopParent(hwnd), WM_SYSCOMMAND,
282 SC_KEYMENU, 0L );
284 iMenuSysKey = 0;
285 iMenuKey = 0;
286 break;
288 case WM_SHOWWINDOW:
289 if( !lParam ) return 0; /* sent from ShowWindow */
291 if( !(wndPtr->dwStyle & WS_POPUP) || !wndPtr->hwndOwner )
292 return 0;
294 if( wndPtr->dwStyle & WS_VISIBLE )
295 { if( wParam ) return 0; }
296 else
297 if(!wParam ) return 0;
299 ShowWindow(hwnd,(wParam)? SW_SHOWNOACTIVATE: SW_HIDE);
300 break;
302 case WM_CANCELMODE:
304 /* EndMenu() should be called if in menu state but currently it's
305 impossible to detect - menu code should be updated*/
307 if( GetCapture() == hwnd )
308 ReleaseCapture();
310 break;
312 case WM_VKEYTOITEM:
313 case WM_CHARTOITEM:
314 return -1;
316 case WM_DROPOBJECT:
317 return DRAG_FILE;
319 case WM_QUERYDROPOBJECT:
320 if(wndPtr->dwExStyle & WS_EX_ACCEPTFILES)
321 return 1;
322 break;
324 case WM_QUERYDRAGICON:
326 HICON hI = 0;
328 len = 1;
329 while(len < 64)
330 if( (hI = LoadIcon(wndPtr->hInstance,MAKEINTRESOURCE(len))) )
331 return (LRESULT)hI;
333 break;
335 case WM_QUERYOPEN:
336 case WM_QUERYENDSESSION:
337 return 1;
340 return 0;