Release 940405
[wine/gsoc-2012-control.git] / windows / defwnd.c
blob5163a2015bb0c47001dee1b2ec38730797326cc6
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"
16 extern LONG NC_HandleNCPaint( HWND hwnd, HRGN hrgn );
17 extern LONG NC_HandleNCActivate( HWND hwnd, WORD wParam );
18 extern LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params );
19 extern LONG NC_HandleNCHitTest( HWND hwnd, POINT pt );
20 extern LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam );
21 extern LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam );
22 extern LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt );
23 extern LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam );
24 extern void NC_TrackSysMenu( HWND hwnd ); /* menu.c */
25 extern BOOL ActivateMenuFocus(HWND hWnd); /* menu.c */
29 /***********************************************************************
30 * DEFWND_SetText
32 * Set the window text.
34 void DEFWND_SetText( HWND hwnd, LPSTR text )
36 LPSTR textPtr;
37 WND *wndPtr = WIN_FindWndPtr( hwnd );
39 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
40 wndPtr->hText = USER_HEAP_ALLOC( LMEM_MOVEABLE, strlen(text) + 2 );
41 textPtr = (LPSTR) USER_HEAP_ADDR( wndPtr->hText );
42 strcpy( textPtr, text );
43 /* for use by edit control */
44 *(textPtr + strlen(text) + 1) = '\0';
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_NCHITTEST:
82 return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
84 case WM_NCLBUTTONDOWN:
85 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
87 case WM_NCLBUTTONDBLCLK:
88 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
90 case WM_NCACTIVATE:
91 return NC_HandleNCActivate( hwnd, wParam );
93 case WM_NCDESTROY:
94 if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
95 wndPtr->hText = 0;
96 if (wndPtr->VScroll) free(wndPtr->VScroll);
97 if (wndPtr->HScroll) free(wndPtr->HScroll);
98 return 0;
100 case WM_PAINT:
102 PAINTSTRUCT paintstruct;
103 BeginPaint( hwnd, &paintstruct );
104 EndPaint( hwnd, &paintstruct );
105 return 0;
108 case WM_CLOSE:
109 DestroyWindow( hwnd );
110 return 0;
112 case WM_MOUSEACTIVATE:
113 if (wndPtr->dwStyle & WS_CHILD)
115 LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
116 wParam, lParam );
117 if (ret) return ret;
119 return MA_ACTIVATE;
121 case WM_ACTIVATE:
122 if (wParam) SetFocus( hwnd );
123 break;
125 case WM_WINDOWPOSCHANGED:
127 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
128 if (!(winPos->flags & SWP_NOMOVE))
129 SendMessage( hwnd, WM_MOVE, 0,
130 MAKELONG( wndPtr->rectClient.left,
131 wndPtr->rectClient.top ));
132 if (!(winPos->flags & SWP_NOSIZE))
133 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
134 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
135 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
136 return 0;
139 case WM_ERASEBKGND:
140 case WM_ICONERASEBKGND:
142 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 1;
143 if (!classPtr->wc.hbrBackground) return 1;
144 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
145 classPtr->wc.hbrBackground );
146 return 0;
149 case WM_GETDLGCODE:
150 return 0;
152 case WM_CTLCOLOR:
154 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
156 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
157 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
158 /* hbr = sysClrObjects.hbrScrollbar;
159 UnrealizeObject(hbr); */
160 return GetStockObject(LTGRAY_BRUSH);
162 else
164 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
165 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
166 /* hbr = sysClrObjects.hbrWindow; */
167 return GetStockObject(WHITE_BRUSH);
171 case WM_GETTEXT:
173 if (wParam)
175 if (wndPtr->hText)
177 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
178 if ((int)wParam > (len = strlen(textPtr)))
180 strcpy((char *)lParam, textPtr);
181 return (DWORD)len;
184 lParam = (DWORD)NULL;
186 return (0L);
189 case WM_GETTEXTLENGTH:
191 if (wndPtr->hText)
193 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
194 return (DWORD)strlen(textPtr);
196 return (0L);
199 case WM_SETTEXT:
200 DEFWND_SetText( hwnd, (LPSTR)lParam );
201 NC_HandleNCPaint( hwnd, (HRGN)1 ); /* Repaint caption */
202 return 0;
204 case WM_SETCURSOR:
205 if (wndPtr->dwStyle & WS_CHILD)
206 if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
207 return TRUE;
208 return NC_HandleSetCursor( hwnd, wParam, lParam );
210 case WM_SYSCOMMAND:
211 return NC_HandleSysCommand( hwnd, wParam, MAKEPOINT(lParam) );
213 case WM_SYSKEYDOWN:
214 if (wParam == VK_MENU) ActivateMenuFocus(hwnd);
215 break;
216 case WM_SYSKEYUP:
217 break;
218 case WM_MENUCHAR:
219 MessageBeep(0);
220 break;
221 case WM_MEASUREITEM:
222 measure = (MEASUREITEMSTRUCT *)lParam;
223 switch(measure->CtlType) {
224 case ODT_BUTTON:
225 break;
226 case ODT_COMBOBOX:
227 measure->itemHeight = 10;
228 /* printf("defwndproc WM_MEASUREITEM // ODT_COMBOBOX !\n");*/
229 break;
230 case ODT_LISTBOX:
231 measure->itemHeight = 10;
232 /* printf("defwndproc WM_MEASUREITEM // ODT_LISTBOX !\n");*/
233 break;
234 case ODT_MENU:
235 break;
236 default:
237 break;
239 break;
241 return 0;