Release 940912
[wine/gsoc-2012-control.git] / windows / defwnd.c
blob071e681b2a44630207f01f1833542b547cd41b6a
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 );
47 #include <assert.h>
49 /***********************************************************************
50 * DefWindowProc (USER.107)
52 LONG DefWindowProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
54 MEASUREITEMSTRUCT *measure;
55 CLASS * classPtr;
56 LPSTR textPtr;
57 int len;
58 WND * wndPtr = WIN_FindWndPtr( hwnd );
60 #ifdef DEBUG_MESSAGE
61 printf( "DefWindowProc: %d %d %d %08x\n", hwnd, msg, wParam, lParam );
62 #endif
64 switch(msg)
66 case WM_NCCREATE:
68 CREATESTRUCT * createStruct = (CREATESTRUCT *)lParam;
69 if (createStruct->lpszName)
70 DEFWND_SetText( hwnd, createStruct->lpszName );
71 if ((createStruct->style & WS_VSCROLL) ||
72 (createStruct->style & WS_HSCROLL)) NC_CreateScrollBars(hwnd);
73 return 1;
76 case WM_NCCALCSIZE:
77 return NC_HandleNCCalcSize( hwnd, (NCCALCSIZE_PARAMS *)lParam );
79 case WM_PAINTICON:
80 case WM_NCPAINT:
81 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
84 case WM_NCHITTEST:
85 return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
87 case WM_NCLBUTTONDOWN:
88 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
90 case WM_LBUTTONDBLCLK:
91 case WM_NCLBUTTONDBLCLK:
92 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
94 case WM_NCACTIVATE:
95 return NC_HandleNCActivate( hwnd, wParam );
97 case WM_NCDESTROY:
98 if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
99 wndPtr->hText = 0;
100 if (wndPtr->VScroll) free(wndPtr->VScroll);
101 if (wndPtr->HScroll) free(wndPtr->HScroll);
102 return 0;
104 case WM_PAINT:
106 PAINTSTRUCT paintstruct;
107 BeginPaint( hwnd, &paintstruct );
108 EndPaint( hwnd, &paintstruct );
109 return 0;
112 case WM_CLOSE:
113 DestroyWindow( hwnd );
114 return 0;
116 case WM_MOUSEACTIVATE:
117 if (wndPtr->dwStyle & WS_CHILD)
119 LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
120 wParam, lParam );
121 if (ret) return ret;
123 return MA_ACTIVATE;
125 case WM_ACTIVATE:
126 if (wParam) SetFocus( hwnd );
127 break;
129 case WM_WINDOWPOSCHANGING:
130 return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)lParam );
132 case WM_WINDOWPOSCHANGED:
134 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
135 if (!(winPos->flags & SWP_NOMOVE))
136 SendMessage( hwnd, WM_MOVE, 0,
137 MAKELONG( wndPtr->rectClient.left,
138 wndPtr->rectClient.top ));
139 if (!(winPos->flags & SWP_NOSIZE))
140 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
141 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
142 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
143 return 0;
146 case WM_ERASEBKGND:
147 case WM_ICONERASEBKGND:
149 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 1;
150 if (!classPtr->wc.hbrBackground) return 1;
151 if (classPtr->wc.hbrBackground <= COLOR_MAX+1)
153 HBRUSH hbrush;
154 hbrush = CreateSolidBrush(
155 GetSysColor(classPtr->wc.hbrBackground-1));
156 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
157 DeleteObject (hbrush);
159 else
160 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
161 classPtr->wc.hbrBackground );
162 return 0;
165 case WM_GETDLGCODE:
166 return 0;
168 case WM_CTLCOLOR:
170 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
172 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
173 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
174 UnrealizeObject( sysColorObjects.hbrushScrollbar );
175 return sysColorObjects.hbrushScrollbar;
177 else
179 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
180 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
181 return sysColorObjects.hbrushWindow;
185 case WM_GETTEXT:
187 if (wParam)
189 if (wndPtr->hText)
191 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
192 if ((int)wParam > (len = strlen(textPtr)))
194 strcpy((char *)lParam, textPtr);
195 return (DWORD)len;
198 lParam = (DWORD)NULL;
200 return (0L);
203 case WM_GETTEXTLENGTH:
205 if (wndPtr->hText)
207 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
208 return (DWORD)strlen(textPtr);
210 return (0L);
213 case WM_SETTEXT:
214 DEFWND_SetText( hwnd, (LPSTR)lParam );
215 NC_HandleNCPaint( hwnd, (HRGN)1 ); /* Repaint caption */
216 return 0;
218 case WM_SETCURSOR:
219 if (wndPtr->dwStyle & WS_CHILD)
220 if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
221 return TRUE;
222 return NC_HandleSetCursor( hwnd, wParam, lParam );
224 case WM_SYSCOMMAND:
225 return NC_HandleSysCommand( hwnd, wParam, MAKEPOINT(lParam) );
227 case WM_SYSKEYDOWN:
228 if (wParam == VK_MENU)
229 SendMessage( hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0L );
230 break;
232 case WM_SYSKEYUP:
233 break;
234 case WM_MEASUREITEM:
235 measure = (MEASUREITEMSTRUCT *)lParam;
236 switch(measure->CtlType) {
237 case ODT_BUTTON:
238 break;
239 case ODT_COMBOBOX:
240 measure->itemHeight = 10;
241 /* printf("defwndproc WM_MEASUREITEM // ODT_COMBOBOX !\n");*/
242 break;
243 case ODT_LISTBOX:
244 measure->itemHeight = 10;
245 /* printf("defwndproc WM_MEASUREITEM // ODT_LISTBOX !\n");*/
246 break;
247 case ODT_MENU:
248 break;
249 default:
250 break;
252 break;
254 return 0;