Release 941017
[wine/gsoc-2012-control.git] / windows / defwnd.c
blob501ad78032e867e2a1065702f6633ad6ebcad758
1 /*
2 * Default window procedure
4 * Copyright 1993 Alexandre Julliard
5 */
7 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
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 #include "stddebug.h"
17 /* #define DEBUG_MESSAGE /* */
18 /* #undef DEBUG_MESSAGE /* */
19 #include "debug.h"
22 /* Last COLOR id */
23 #define COLOR_MAX COLOR_BTNHIGHLIGHT
25 extern LONG NC_HandleNCPaint( HWND hwnd, HRGN hrgn );
26 extern LONG NC_HandleNCActivate( HWND hwnd, WORD wParam );
27 extern LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params );
28 extern LONG NC_HandleNCHitTest( HWND hwnd, POINT pt );
29 extern LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam );
30 extern LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam );
31 extern LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt );
32 extern LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam );
33 extern LONG WINPOS_HandleWindowPosChanging( WINDOWPOS *winpos ); /* winpos.c */
36 /***********************************************************************
37 * DEFWND_SetText
39 * Set the window text.
41 void DEFWND_SetText( HWND hwnd, LPSTR text )
43 LPSTR textPtr;
44 WND *wndPtr = WIN_FindWndPtr( hwnd );
46 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
47 wndPtr->hText = USER_HEAP_ALLOC( LMEM_MOVEABLE, strlen(text) + 1 );
48 textPtr = (LPSTR) USER_HEAP_ADDR( wndPtr->hText );
49 strcpy( textPtr, text );
52 #include <assert.h>
54 /***********************************************************************
55 * DefWindowProc (USER.107)
57 LONG DefWindowProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
59 MEASUREITEMSTRUCT *measure;
60 CLASS * classPtr;
61 LPSTR textPtr;
62 int len;
63 WND * wndPtr = WIN_FindWndPtr( hwnd );
65 dprintf_message(stddeb, "DefWindowProc: %d %d %d %08x\n",
66 hwnd, msg, wParam, lParam );
68 switch(msg)
70 case WM_NCCREATE:
72 CREATESTRUCT * createStruct = (CREATESTRUCT *)lParam;
73 if (createStruct->lpszName)
74 DEFWND_SetText( hwnd, createStruct->lpszName );
75 if ((createStruct->style & WS_VSCROLL) ||
76 (createStruct->style & WS_HSCROLL)) NC_CreateScrollBars(hwnd);
77 return 1;
80 case WM_NCCALCSIZE:
81 return NC_HandleNCCalcSize( hwnd, (NCCALCSIZE_PARAMS *)lParam );
83 case WM_PAINTICON:
84 case WM_NCPAINT:
85 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
88 case WM_NCHITTEST:
89 return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
91 case WM_NCLBUTTONDOWN:
92 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
94 case WM_LBUTTONDBLCLK:
95 case WM_NCLBUTTONDBLCLK:
96 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
98 case WM_NCACTIVATE:
99 return NC_HandleNCActivate( hwnd, wParam );
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;
108 case WM_PAINT:
110 PAINTSTRUCT paintstruct;
111 BeginPaint( hwnd, &paintstruct );
112 EndPaint( hwnd, &paintstruct );
113 return 0;
116 case WM_SETREDRAW:
117 if (wParam)
119 ValidateRect( hwnd, NULL );
120 wndPtr->flags |= WIN_NO_REDRAW;
122 else wndPtr->flags &= ~WIN_NO_REDRAW;
123 return 0;
125 case WM_CLOSE:
126 DestroyWindow( hwnd );
127 return 0;
129 case WM_MOUSEACTIVATE:
130 if (wndPtr->dwStyle & WS_CHILD)
132 LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
133 wParam, lParam );
134 if (ret) return ret;
136 return MA_ACTIVATE;
138 case WM_ACTIVATE:
139 if (wParam) SetFocus( hwnd );
140 break;
142 case WM_WINDOWPOSCHANGING:
143 return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)lParam );
145 case WM_WINDOWPOSCHANGED:
147 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
148 if (!(winPos->flags & SWP_NOMOVE))
149 SendMessage( hwnd, WM_MOVE, 0,
150 MAKELONG( wndPtr->rectClient.left,
151 wndPtr->rectClient.top ));
152 if (!(winPos->flags & SWP_NOSIZE))
153 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
154 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
155 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
156 return 0;
159 case WM_ERASEBKGND:
160 case WM_ICONERASEBKGND:
162 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 1;
163 if (!classPtr->wc.hbrBackground) return 1;
164 if (classPtr->wc.hbrBackground <= COLOR_MAX+1)
166 HBRUSH hbrush;
167 hbrush = CreateSolidBrush(
168 GetSysColor(classPtr->wc.hbrBackground-1));
169 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
170 DeleteObject (hbrush);
172 else
173 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
174 classPtr->wc.hbrBackground );
175 return 0;
178 case WM_GETDLGCODE:
179 return 0;
181 case WM_CTLCOLOR:
183 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
185 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
186 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
187 UnrealizeObject( sysColorObjects.hbrushScrollbar );
188 return sysColorObjects.hbrushScrollbar;
190 else
192 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
193 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
194 return sysColorObjects.hbrushWindow;
198 case WM_GETTEXT:
200 if (wParam)
202 if (wndPtr->hText)
204 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
205 if ((int)wParam > (len = strlen(textPtr)))
207 strcpy((char *)lParam, textPtr);
208 return (DWORD)len;
211 lParam = (DWORD)NULL;
213 return (0L);
216 case WM_GETTEXTLENGTH:
218 if (wndPtr->hText)
220 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
221 return (DWORD)strlen(textPtr);
223 return (0L);
226 case WM_SETTEXT:
227 DEFWND_SetText( hwnd, (LPSTR)lParam );
228 NC_HandleNCPaint( hwnd, (HRGN)1 ); /* Repaint caption */
229 return 0;
231 case WM_SETCURSOR:
232 if (wndPtr->dwStyle & WS_CHILD)
233 if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
234 return TRUE;
235 return NC_HandleSetCursor( hwnd, wParam, lParam );
237 case WM_SYSCOMMAND:
238 return NC_HandleSysCommand( hwnd, wParam, MAKEPOINT(lParam) );
240 case WM_SYSKEYDOWN:
241 if (wParam == VK_MENU)
242 SendMessage( hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0L );
243 break;
245 case WM_SYSKEYUP:
246 break;
247 case WM_MEASUREITEM:
248 measure = (MEASUREITEMSTRUCT *)lParam;
249 switch(measure->CtlType) {
250 case ODT_BUTTON:
251 break;
252 case ODT_COMBOBOX:
253 measure->itemHeight = 10;
254 /* printf("defwndproc WM_MEASUREITEM // ODT_COMBOBOX !\n");*/
255 break;
256 case ODT_LISTBOX:
257 measure->itemHeight = 10;
258 /* printf("defwndproc WM_MEASUREITEM // ODT_LISTBOX !\n");*/
259 break;
260 case ODT_MENU:
261 break;
262 default:
263 break;
265 break;
267 return 0;