Release 950216
[wine.git] / windows / defwnd.c
blob37ed5aaa2847679e618c6a76eed8f86e00d1e171
1 /*
2 * Default window procedure
4 * Copyright 1993 Alexandre Julliard
6 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
7 */
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 "nonclient.h"
16 #include "winpos.h"
17 #include "syscolor.h"
18 #include "stddebug.h"
19 /* #define DEBUG_MESSAGE */
20 #include "debug.h"
22 /* Last COLOR id */
23 #define COLOR_MAX COLOR_BTNHIGHLIGHT
25 /***********************************************************************
26 * DEFWND_SetText
28 * Set the window text.
30 void DEFWND_SetText( HWND hwnd, LPSTR text )
32 LPSTR textPtr;
33 WND *wndPtr = WIN_FindWndPtr( hwnd );
35 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
36 wndPtr->hText = USER_HEAP_ALLOC( LMEM_MOVEABLE, strlen(text) + 1 );
37 textPtr = (LPSTR) USER_HEAP_ADDR( wndPtr->hText );
38 strcpy( textPtr, text );
41 #include <assert.h>
43 /***********************************************************************
44 * DefWindowProc (USER.107)
46 LONG DefWindowProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
48 MEASUREITEMSTRUCT *measure;
49 CLASS * classPtr;
50 LPSTR textPtr;
51 int len;
52 WND * wndPtr = WIN_FindWndPtr( hwnd );
54 dprintf_message(stddeb, "DefWindowProc: %d %d %d %08lx\n",
55 hwnd, msg, wParam, lParam );
57 switch(msg)
59 case WM_NCCREATE:
61 CREATESTRUCT * createStruct = (CREATESTRUCT *)lParam;
62 if (createStruct->lpszName)
63 DEFWND_SetText( hwnd, createStruct->lpszName );
64 return 1;
67 case WM_NCCALCSIZE:
68 return NC_HandleNCCalcSize( hwnd, (NCCALCSIZE_PARAMS *)lParam );
70 case WM_PAINTICON:
71 case WM_NCPAINT:
72 return NC_HandleNCPaint( hwnd );
74 case WM_NCHITTEST:
75 return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
77 case WM_NCLBUTTONDOWN:
78 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
80 case WM_LBUTTONDBLCLK:
81 case WM_NCLBUTTONDBLCLK:
82 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
84 case WM_NCACTIVATE:
85 return NC_HandleNCActivate( hwnd, wParam );
87 case WM_NCDESTROY:
88 if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
89 if (wndPtr->hVScroll) USER_HEAP_FREE(wndPtr->hVScroll);
90 if (wndPtr->hHScroll) USER_HEAP_FREE(wndPtr->hHScroll);
91 wndPtr->hText = wndPtr->hVScroll = wndPtr->hHScroll = 0;
92 return 0;
94 case WM_PAINT:
96 PAINTSTRUCT paintstruct;
97 BeginPaint( hwnd, &paintstruct );
98 EndPaint( hwnd, &paintstruct );
99 return 0;
102 case WM_SETREDRAW:
103 if (!wParam)
105 ValidateRect( hwnd, NULL );
106 wndPtr->flags |= WIN_NO_REDRAW;
108 else wndPtr->flags &= ~WIN_NO_REDRAW;
109 return 0;
111 case WM_CLOSE:
112 DestroyWindow( hwnd );
113 return 0;
115 case WM_MOUSEACTIVATE:
116 if (wndPtr->dwStyle & WS_CHILD)
118 LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
119 wParam, lParam );
120 if (ret) return ret;
122 return MA_ACTIVATE;
124 case WM_ACTIVATE:
125 if (wParam) SetFocus( hwnd );
126 break;
128 case WM_WINDOWPOSCHANGING:
129 return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)lParam );
131 case WM_WINDOWPOSCHANGED:
133 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
134 if (!(winPos->flags & SWP_NOMOVE))
135 SendMessage( hwnd, WM_MOVE, 0,
136 MAKELONG( wndPtr->rectClient.left,
137 wndPtr->rectClient.top ));
138 if (!(winPos->flags & SWP_NOSIZE))
139 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
140 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
141 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
142 return 0;
145 case WM_ERASEBKGND:
146 case WM_ICONERASEBKGND:
148 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
149 if (!classPtr->wc.hbrBackground) return 0;
150 if (classPtr->wc.hbrBackground <= COLOR_MAX+1)
152 HBRUSH hbrush;
153 hbrush = CreateSolidBrush(
154 GetSysColor(classPtr->wc.hbrBackground-1));
155 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
156 DeleteObject (hbrush);
158 else
159 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
160 classPtr->wc.hbrBackground );
161 return 1;
164 case WM_GETDLGCODE:
165 return 0;
167 case WM_CTLCOLOR:
169 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
171 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
172 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
173 UnrealizeObject( sysColorObjects.hbrushScrollbar );
174 return sysColorObjects.hbrushScrollbar;
176 else
178 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
179 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
180 return sysColorObjects.hbrushWindow;
184 case WM_GETTEXT:
186 if (wParam)
188 if (wndPtr->hText)
190 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
191 if ((int)wParam > (len = strlen(textPtr)))
193 strcpy((char *)lParam, textPtr);
194 return (DWORD)len;
197 lParam = (DWORD)NULL;
199 return (0L);
202 case WM_GETTEXTLENGTH:
204 if (wndPtr->hText)
206 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
207 return (DWORD)strlen(textPtr);
209 return (0L);
212 case WM_SETTEXT:
213 DEFWND_SetText( hwnd, (LPSTR)lParam );
214 NC_HandleNCPaint( hwnd ); /* Repaint caption */
215 return 0;
217 case WM_SETCURSOR:
218 if (wndPtr->dwStyle & WS_CHILD)
219 if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
220 return TRUE;
221 return NC_HandleSetCursor( hwnd, wParam, lParam );
223 case WM_SYSCOMMAND:
224 return NC_HandleSysCommand( hwnd, wParam, MAKEPOINT(lParam) );
226 case WM_SYSKEYDOWN:
227 if (wParam == VK_MENU)
228 { /* Send to WS_OVERLAPPED parent. TODO: Handle MDI */
229 HWND top;
230 for(top=hwnd;GetParent(top)!=0;top=GetParent(top));
231 SendMessage( top, WM_SYSCOMMAND, SC_KEYMENU, 0L );
233 break;
235 case WM_SYSKEYUP:
236 break;
237 case WM_MEASUREITEM:
238 measure = (MEASUREITEMSTRUCT *)lParam;
239 switch(measure->CtlType) {
240 case ODT_BUTTON:
241 break;
242 case ODT_COMBOBOX:
243 measure->itemHeight = 10;
244 /* printf("defwndproc WM_MEASUREITEM // ODT_COMBOBOX !\n");*/
245 break;
246 case ODT_LISTBOX:
247 measure->itemHeight = 10;
248 /* printf("defwndproc WM_MEASUREITEM // ODT_LISTBOX !\n");*/
249 break;
250 case ODT_MENU:
251 break;
252 default:
253 break;
255 break;
257 return 0;