Release 940804
[wine/gsoc-2012-control.git] / windows / defwnd.c
blob1adc1e3ec14ddb727996236ec9c29a5513dac0c5
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"
17 /* Last COLOR id */
18 #define COLOR_MAX COLOR_BTNHIGHLIGHT
20 extern LONG NC_HandleNCPaint( HWND hwnd, HRGN hrgn );
21 extern LONG NC_HandleNCActivate( HWND hwnd, WORD wParam );
22 extern LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params );
23 extern LONG NC_HandleNCHitTest( HWND hwnd, POINT pt );
24 extern LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam );
25 extern LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam );
26 extern LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt );
27 extern LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam );
28 extern LONG WINPOS_HandleWindowPosChanging( WINDOWPOS *winpos ); /* winpos.c */
29 extern void NC_TrackSysMenu( HWND hwnd ); /* menu.c */
30 extern BOOL ActivateMenuBarFocus(HWND hWnd); /* menu.c */
34 /***********************************************************************
35 * DEFWND_SetText
37 * Set the window text.
39 void DEFWND_SetText( HWND hwnd, LPSTR text )
41 LPSTR textPtr;
42 WND *wndPtr = WIN_FindWndPtr( hwnd );
44 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
45 wndPtr->hText = USER_HEAP_ALLOC( LMEM_MOVEABLE, strlen(text) + 1 );
46 textPtr = (LPSTR) USER_HEAP_ADDR( wndPtr->hText );
47 strcpy( textPtr, text );
51 /***********************************************************************
52 * DefWindowProc (USER.107)
54 LONG DefWindowProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
56 MEASUREITEMSTRUCT *measure;
57 CLASS * classPtr;
58 LPSTR textPtr;
59 int len;
60 WND * wndPtr = WIN_FindWndPtr( hwnd );
62 #ifdef DEBUG_MESSAGE
63 printf( "DefWindowProc: %d %d %d %08x\n", hwnd, msg, wParam, lParam );
64 #endif
66 switch(msg)
68 case WM_NCCREATE:
70 CREATESTRUCT * createStruct = (CREATESTRUCT *)lParam;
71 if (createStruct->lpszName)
72 DEFWND_SetText( hwnd, createStruct->lpszName );
73 if ((createStruct->style & WS_VSCROLL) ||
74 (createStruct->style & WS_HSCROLL)) NC_CreateScrollBars(hwnd);
75 return 1;
78 case WM_NCCALCSIZE:
79 return NC_HandleNCCalcSize( hwnd, (NCCALCSIZE_PARAMS *)lParam );
81 case WM_NCPAINT:
82 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
84 case WM_PAINTICON:
85 printf("going to call NC_HandleNCPaintIcon\n");
86 return NC_HandleNCPaintIcon( hwnd );
89 case WM_NCHITTEST:
90 return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
92 case WM_NCLBUTTONDOWN:
93 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
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_CLOSE:
117 DestroyWindow( hwnd );
118 return 0;
120 case WM_MOUSEACTIVATE:
121 if (wndPtr->dwStyle & WS_CHILD)
123 LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
124 wParam, lParam );
125 if (ret) return ret;
127 return MA_ACTIVATE;
129 case WM_ACTIVATE:
130 if (wParam) SetFocus( hwnd );
131 break;
133 case WM_WINDOWPOSCHANGING:
134 return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)lParam );
136 case WM_WINDOWPOSCHANGED:
138 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
139 if (!(winPos->flags & SWP_NOMOVE))
140 SendMessage( hwnd, WM_MOVE, 0,
141 MAKELONG( wndPtr->rectClient.left,
142 wndPtr->rectClient.top ));
143 if (!(winPos->flags & SWP_NOSIZE))
144 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
145 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
146 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
147 return 0;
150 case WM_ERASEBKGND:
151 case WM_ICONERASEBKGND:
153 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 1;
154 if (!classPtr->wc.hbrBackground) return 1;
155 if (classPtr->wc.hbrBackground <= COLOR_MAX+1)
157 HBRUSH hbrush;
158 hbrush = CreateSolidBrush(
159 GetSysColor(classPtr->wc.hbrBackground-1));
160 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
161 DeleteObject (hbrush);
163 else
164 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
165 classPtr->wc.hbrBackground );
166 return 0;
169 case WM_GETDLGCODE:
170 return 0;
172 case WM_CTLCOLOR:
174 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
176 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
177 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
178 UnrealizeObject( sysColorObjects.hbrushScrollbar );
179 return sysColorObjects.hbrushScrollbar;
181 else
183 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
184 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
185 return sysColorObjects.hbrushWindow;
189 case WM_GETTEXT:
191 if (wParam)
193 if (wndPtr->hText)
195 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
196 if ((int)wParam > (len = strlen(textPtr)))
198 strcpy((char *)lParam, textPtr);
199 return (DWORD)len;
202 lParam = (DWORD)NULL;
204 return (0L);
207 case WM_GETTEXTLENGTH:
209 if (wndPtr->hText)
211 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
212 return (DWORD)strlen(textPtr);
214 return (0L);
217 case WM_SETTEXT:
218 DEFWND_SetText( hwnd, (LPSTR)lParam );
219 NC_HandleNCPaint( hwnd, (HRGN)1 ); /* Repaint caption */
220 return 0;
222 case WM_SETCURSOR:
223 if (wndPtr->dwStyle & WS_CHILD)
224 if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
225 return TRUE;
226 return NC_HandleSetCursor( hwnd, wParam, lParam );
228 case WM_SYSCOMMAND:
229 return NC_HandleSysCommand( hwnd, wParam, MAKEPOINT(lParam) );
231 case WM_SYSKEYDOWN:
232 if (wParam == VK_MENU) ActivateMenuBarFocus(hwnd);
233 break;
234 case WM_SYSKEYUP:
235 break;
236 case WM_MENUCHAR:
237 MessageBeep(0);
238 break;
239 case WM_MEASUREITEM:
240 measure = (MEASUREITEMSTRUCT *)lParam;
241 switch(measure->CtlType) {
242 case ODT_BUTTON:
243 break;
244 case ODT_COMBOBOX:
245 measure->itemHeight = 10;
246 /* printf("defwndproc WM_MEASUREITEM // ODT_COMBOBOX !\n");*/
247 break;
248 case ODT_LISTBOX:
249 measure->itemHeight = 10;
250 /* printf("defwndproc WM_MEASUREITEM // ODT_LISTBOX !\n");*/
251 break;
252 case ODT_MENU:
253 break;
254 default:
255 break;
257 break;
259 return 0;