Release 940301
[wine/gsoc-2012-control.git] / windows / defwnd.c
bloba495d08b088b39c7bdda3b0273097fee8cb33da5
1 /*
2 * Default window procedure
4 * Copyright 1993 Alexandre Julliard
5 */
7 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
10 #include "windows.h"
11 #include "win.h"
12 #include "class.h"
13 #include "user.h"
15 extern LONG NC_HandleNCPaint( HWND hwnd, HRGN hrgn );
16 extern LONG NC_HandleNCActivate( HWND hwnd, WORD wParam );
17 extern LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params );
18 extern LONG NC_HandleNCHitTest( HWND hwnd, POINT pt );
19 extern LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam );
20 extern LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam );
21 extern LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt );
22 extern LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam );
23 extern void NC_TrackSysMenu( HWND hwnd ); /* menu.c */
27 /***********************************************************************
28 * DEFWND_SetText
30 * Set the window text.
32 void DEFWND_SetText( HWND hwnd, LPSTR text )
34 LPSTR textPtr;
35 WND *wndPtr = WIN_FindWndPtr( hwnd );
37 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
38 wndPtr->hText = USER_HEAP_ALLOC( LMEM_MOVEABLE, strlen(text) + 2 );
39 textPtr = (LPSTR) USER_HEAP_ADDR( wndPtr->hText );
40 strcpy( textPtr, text );
41 /* for use by edit control */
42 *(textPtr + strlen(text) + 1) = '\0';
46 /***********************************************************************
47 * DefWindowProc (USER.107)
49 LONG DefWindowProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
51 CLASS * classPtr;
52 LPSTR textPtr;
53 int len;
54 WND * wndPtr = WIN_FindWndPtr( hwnd );
56 #ifdef DEBUG_MESSAGE
57 printf( "DefWindowProc: %d %d %d %08x\n", hwnd, msg, wParam, lParam );
58 #endif
60 switch(msg)
62 case WM_NCCREATE:
64 CREATESTRUCT * createStruct = (CREATESTRUCT *)lParam;
65 if (createStruct->lpszName)
66 DEFWND_SetText( hwnd, createStruct->lpszName );
67 if ((createStruct->style & WS_VSCROLL) ||
68 (createStruct->style & WS_HSCROLL)) NC_CreateScrollBars(hwnd);
69 return 1;
72 case WM_NCCALCSIZE:
73 return NC_HandleNCCalcSize( hwnd, (NCCALCSIZE_PARAMS *)lParam );
75 case WM_NCPAINT:
76 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
78 case WM_NCHITTEST:
79 return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
81 case WM_NCLBUTTONDOWN:
82 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
84 case WM_NCLBUTTONDBLCLK:
85 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
87 case WM_NCACTIVATE:
88 return NC_HandleNCActivate( hwnd, wParam );
90 case WM_NCDESTROY:
91 if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
92 wndPtr->hText = 0;
93 if (wndPtr->VScroll) free(wndPtr->VScroll);
94 if (wndPtr->HScroll) free(wndPtr->HScroll);
95 return 0;
97 case WM_PAINT:
99 PAINTSTRUCT paintstruct;
100 BeginPaint( hwnd, &paintstruct );
101 EndPaint( hwnd, &paintstruct );
102 return 0;
105 case WM_CLOSE:
106 DestroyWindow( hwnd );
107 return 0;
109 case WM_MOUSEACTIVATE:
110 if (wndPtr->dwStyle & WS_CHILD)
112 LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
113 wParam, lParam );
114 if (ret) return ret;
116 return MA_ACTIVATE;
118 case WM_ACTIVATE:
119 if (wParam) SetFocus( hwnd );
120 break;
122 case WM_WINDOWPOSCHANGED:
124 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
125 if (!(winPos->flags & SWP_NOMOVE))
126 SendMessage( hwnd, WM_MOVE, 0,
127 MAKELONG( wndPtr->rectClient.left,
128 wndPtr->rectClient.top ));
129 if (!(winPos->flags & SWP_NOSIZE))
130 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
131 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
132 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
133 return 0;
136 case WM_ERASEBKGND:
137 case WM_ICONERASEBKGND:
139 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 1;
140 if (!classPtr->wc.hbrBackground) return 1;
141 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
142 classPtr->wc.hbrBackground );
143 return 0;
146 case WM_GETDLGCODE:
147 return 0;
149 case WM_CTLCOLOR:
151 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
153 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
154 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
155 /* hbr = sysClrObjects.hbrScrollbar;
156 UnrealizeObject(hbr); */
157 return GetStockObject(LTGRAY_BRUSH);
159 else
161 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
162 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
163 /* hbr = sysClrObjects.hbrWindow; */
164 return GetStockObject(WHITE_BRUSH);
168 case WM_GETTEXT:
170 if (wParam)
172 if (wndPtr->hText)
174 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
175 if ((int)wParam > (len = strlen(textPtr)))
177 strcpy((char *)lParam, textPtr);
178 return (DWORD)len;
181 lParam = (DWORD)NULL;
183 return (0L);
186 case WM_GETTEXTLENGTH:
188 if (wndPtr->hText)
190 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
191 return (DWORD)strlen(textPtr);
193 return (0L);
196 case WM_SETTEXT:
197 DEFWND_SetText( hwnd, (LPSTR)lParam );
198 NC_HandleNCPaint( hwnd, (HRGN)1 ); /* Repaint caption */
199 return 0;
201 case WM_SETCURSOR:
202 if (wndPtr->dwStyle & WS_CHILD)
203 if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
204 return TRUE;
205 return NC_HandleSetCursor( hwnd, wParam, lParam );
207 case WM_SYSCOMMAND:
208 return NC_HandleSysCommand( hwnd, wParam, MAKEPOINT(lParam) );
210 case WM_SYSKEYDOWN:
211 if (wParam == VK_MENU) {
212 printf("VK_MENU Pressed // hMenu=%04X !\n", GetMenu(hwnd));
213 NC_TrackSysMenu(hwnd);
215 break;
216 case WM_SYSKEYUP:
217 if (wParam == VK_MENU) {
218 printf("VK_MENU Released // hMenu=%04X !\n", GetMenu(hwnd));
220 break;
222 return 0;