Release 940815
[wine/gsoc-2012-control.git] / windows / defwnd.c
blob12443b104e7e2de04028640d52741bc020e0c0a5
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 */
31 /***********************************************************************
32 * DEFWND_SetText
34 * Set the window text.
36 void DEFWND_SetText( HWND hwnd, LPSTR text )
38 LPSTR textPtr;
39 WND *wndPtr = WIN_FindWndPtr( hwnd );
41 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
42 wndPtr->hText = USER_HEAP_ALLOC( LMEM_MOVEABLE, strlen(text) + 1 );
43 textPtr = (LPSTR) USER_HEAP_ADDR( wndPtr->hText );
44 strcpy( textPtr, text );
48 /***********************************************************************
49 * DefWindowProc (USER.107)
51 LONG DefWindowProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
53 MEASUREITEMSTRUCT *measure;
54 CLASS * classPtr;
55 LPSTR textPtr;
56 int len;
57 WND * wndPtr = WIN_FindWndPtr( hwnd );
59 #ifdef DEBUG_MESSAGE
60 printf( "DefWindowProc: %d %d %d %08x\n", hwnd, msg, wParam, lParam );
61 #endif
63 switch(msg)
65 case WM_NCCREATE:
67 CREATESTRUCT * createStruct = (CREATESTRUCT *)lParam;
68 if (createStruct->lpszName)
69 DEFWND_SetText( hwnd, createStruct->lpszName );
70 if ((createStruct->style & WS_VSCROLL) ||
71 (createStruct->style & WS_HSCROLL)) NC_CreateScrollBars(hwnd);
72 return 1;
75 case WM_NCCALCSIZE:
76 return NC_HandleNCCalcSize( hwnd, (NCCALCSIZE_PARAMS *)lParam );
78 case WM_NCPAINT:
79 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
81 case WM_PAINTICON:
82 printf("going to call NC_HandleNCPaintIcon\n");
83 return NC_HandleNCPaintIcon( hwnd );
86 case WM_NCHITTEST:
87 return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
89 case WM_NCLBUTTONDOWN:
90 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
92 case WM_NCLBUTTONDBLCLK:
93 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
95 case WM_NCACTIVATE:
96 return NC_HandleNCActivate( hwnd, wParam );
98 case WM_NCDESTROY:
99 if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
100 wndPtr->hText = 0;
101 if (wndPtr->VScroll) free(wndPtr->VScroll);
102 if (wndPtr->HScroll) free(wndPtr->HScroll);
103 return 0;
105 case WM_PAINT:
107 PAINTSTRUCT paintstruct;
108 BeginPaint( hwnd, &paintstruct );
109 EndPaint( hwnd, &paintstruct );
110 return 0;
113 case WM_CLOSE:
114 DestroyWindow( hwnd );
115 return 0;
117 case WM_MOUSEACTIVATE:
118 if (wndPtr->dwStyle & WS_CHILD)
120 LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
121 wParam, lParam );
122 if (ret) return ret;
124 return MA_ACTIVATE;
126 case WM_ACTIVATE:
127 if (wParam) SetFocus( hwnd );
128 break;
130 case WM_WINDOWPOSCHANGING:
131 return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)lParam );
133 case WM_WINDOWPOSCHANGED:
135 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
136 if (!(winPos->flags & SWP_NOMOVE))
137 SendMessage( hwnd, WM_MOVE, 0,
138 MAKELONG( wndPtr->rectClient.left,
139 wndPtr->rectClient.top ));
140 if (!(winPos->flags & SWP_NOSIZE))
141 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
142 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
143 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
144 return 0;
147 case WM_ERASEBKGND:
148 case WM_ICONERASEBKGND:
150 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 1;
151 if (!classPtr->wc.hbrBackground) return 1;
152 if (classPtr->wc.hbrBackground <= COLOR_MAX+1)
154 HBRUSH hbrush;
155 hbrush = CreateSolidBrush(
156 GetSysColor(classPtr->wc.hbrBackground-1));
157 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
158 DeleteObject (hbrush);
160 else
161 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
162 classPtr->wc.hbrBackground );
163 return 0;
166 case WM_GETDLGCODE:
167 return 0;
169 case WM_CTLCOLOR:
171 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
173 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
174 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
175 UnrealizeObject( sysColorObjects.hbrushScrollbar );
176 return sysColorObjects.hbrushScrollbar;
178 else
180 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
181 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
182 return sysColorObjects.hbrushWindow;
186 case WM_GETTEXT:
188 if (wParam)
190 if (wndPtr->hText)
192 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
193 if ((int)wParam > (len = strlen(textPtr)))
195 strcpy((char *)lParam, textPtr);
196 return (DWORD)len;
199 lParam = (DWORD)NULL;
201 return (0L);
204 case WM_GETTEXTLENGTH:
206 if (wndPtr->hText)
208 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
209 return (DWORD)strlen(textPtr);
211 return (0L);
214 case WM_SETTEXT:
215 DEFWND_SetText( hwnd, (LPSTR)lParam );
216 NC_HandleNCPaint( hwnd, (HRGN)1 ); /* Repaint caption */
217 return 0;
219 case WM_SETCURSOR:
220 if (wndPtr->dwStyle & WS_CHILD)
221 if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
222 return TRUE;
223 return NC_HandleSetCursor( hwnd, wParam, lParam );
225 case WM_SYSCOMMAND:
226 return NC_HandleSysCommand( hwnd, wParam, MAKEPOINT(lParam) );
228 case WM_SYSKEYDOWN:
229 if (wParam == VK_MENU)
230 SendMessage( hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0L );
231 break;
233 case WM_SYSKEYUP:
234 break;
235 case WM_MEASUREITEM:
236 measure = (MEASUREITEMSTRUCT *)lParam;
237 switch(measure->CtlType) {
238 case ODT_BUTTON:
239 break;
240 case ODT_COMBOBOX:
241 measure->itemHeight = 10;
242 /* printf("defwndproc WM_MEASUREITEM // ODT_COMBOBOX !\n");*/
243 break;
244 case ODT_LISTBOX:
245 measure->itemHeight = 10;
246 /* printf("defwndproc WM_MEASUREITEM // ODT_LISTBOX !\n");*/
247 break;
248 case ODT_MENU:
249 break;
250 default:
251 break;
253 break;
255 return 0;