Release 950727
[wine/multimedia.git] / windows / defwnd.c
blob6263dd57586d7b5c05aeafa21245a1908434caa4
1 /*
2 * Default window procedure
4 * Copyright 1993 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include "win.h"
10 #include "class.h"
11 #include "user.h"
12 #include "nonclient.h"
13 #include "winpos.h"
14 #include "syscolor.h"
15 #include "stddebug.h"
16 /* #define DEBUG_MESSAGE */
17 #include "debug.h"
19 /* Last COLOR id */
20 #define COLOR_MAX COLOR_BTNHIGHLIGHT
22 /***********************************************************************
23 * DEFWND_SetText
25 * Set the window text.
27 void DEFWND_SetText( HWND hwnd, LPSTR text )
29 LPSTR textPtr;
30 WND *wndPtr = WIN_FindWndPtr( hwnd );
32 if (!text) text = "";
33 if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
34 wndPtr->hText = USER_HEAP_ALLOC( strlen(text) + 1 );
35 textPtr = (LPSTR) USER_HEAP_LIN_ADDR( wndPtr->hText );
36 strcpy( textPtr, text );
40 /***********************************************************************
41 * DefWindowProc (USER.107)
43 LONG DefWindowProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
45 CLASS * classPtr;
46 LPSTR textPtr;
47 int len;
48 WND * wndPtr = WIN_FindWndPtr( hwnd );
50 dprintf_message(stddeb, "DefWindowProc: %d %d %d %08lx\n",
51 hwnd, msg, wParam, lParam );
53 switch(msg)
55 case WM_NCCREATE:
57 CREATESTRUCT *createStruct = (CREATESTRUCT*)PTR_SEG_TO_LIN(lParam);
58 if (createStruct->lpszName)
59 DEFWND_SetText( hwnd,
60 (LPSTR)PTR_SEG_TO_LIN(createStruct->lpszName) );
61 return 1;
64 case WM_NCCALCSIZE:
65 return NC_HandleNCCalcSize( hwnd,
66 (NCCALCSIZE_PARAMS *)PTR_SEG_TO_LIN(lParam) );
68 case WM_PAINTICON:
69 case WM_NCPAINT:
70 return NC_HandleNCPaint( hwnd );
72 case WM_NCHITTEST:
73 return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
75 case WM_NCLBUTTONDOWN:
76 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
78 case WM_LBUTTONDBLCLK:
79 case WM_NCLBUTTONDBLCLK:
80 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
82 case WM_NCACTIVATE:
83 return NC_HandleNCActivate( hwnd, wParam );
85 case WM_NCDESTROY:
86 if (wndPtr->hText) USER_HEAP_FREE(wndPtr->hText);
87 if (wndPtr->hVScroll) USER_HEAP_FREE(wndPtr->hVScroll);
88 if (wndPtr->hHScroll) USER_HEAP_FREE(wndPtr->hHScroll);
89 wndPtr->hText = wndPtr->hVScroll = wndPtr->hHScroll = 0;
90 return 0;
92 case WM_PAINT:
94 PAINTSTRUCT paintstruct;
95 BeginPaint( hwnd, &paintstruct );
96 EndPaint( hwnd, &paintstruct );
97 return 0;
100 case WM_SETREDRAW:
101 if (!wParam)
103 ValidateRect( hwnd, NULL );
104 wndPtr->flags |= WIN_NO_REDRAW;
106 else wndPtr->flags &= ~WIN_NO_REDRAW;
107 return 0;
109 case WM_CLOSE:
110 DestroyWindow( hwnd );
111 return 0;
113 case WM_MOUSEACTIVATE:
114 if (wndPtr->dwStyle & WS_CHILD)
116 LONG ret = SendMessage( wndPtr->hwndParent, WM_MOUSEACTIVATE,
117 wParam, lParam );
118 if (ret) return ret;
120 return MA_ACTIVATE;
122 case WM_ACTIVATE:
123 if (wParam) SetFocus( hwnd );
124 break;
126 case WM_WINDOWPOSCHANGING:
127 return WINPOS_HandleWindowPosChanging( (WINDOWPOS *)PTR_SEG_TO_LIN(lParam) );
129 case WM_WINDOWPOSCHANGED:
131 WINDOWPOS * winPos = (WINDOWPOS *)PTR_SEG_TO_LIN(lParam);
132 if (!(winPos->flags & SWP_NOMOVE))
133 SendMessage( hwnd, WM_MOVE, 0,
134 MAKELONG( wndPtr->rectClient.left,
135 wndPtr->rectClient.top ));
136 if (!(winPos->flags & SWP_NOSIZE))
137 SendMessage( hwnd, WM_SIZE, SIZE_RESTORED,
138 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
139 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
140 return 0;
143 case WM_ERASEBKGND:
144 case WM_ICONERASEBKGND:
146 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
147 if (!classPtr->wc.hbrBackground) return 0;
148 if (classPtr->wc.hbrBackground <= COLOR_MAX+1)
150 HBRUSH hbrush;
151 hbrush = CreateSolidBrush(
152 GetSysColor(classPtr->wc.hbrBackground-1));
153 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
154 DeleteObject (hbrush);
156 else
157 FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
158 classPtr->wc.hbrBackground );
159 return 1;
162 case WM_GETDLGCODE:
163 return 0;
165 case WM_CTLCOLOR:
167 if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
169 SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
170 SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
171 UnrealizeObject( sysColorObjects.hbrushScrollbar );
172 return sysColorObjects.hbrushScrollbar;
174 else
176 SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
177 SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
178 return sysColorObjects.hbrushWindow;
182 case WM_GETTEXT:
184 if (wParam)
186 if (wndPtr->hText)
188 textPtr = (LPSTR)USER_HEAP_LIN_ADDR(wndPtr->hText);
189 if ((int)wParam > (len = strlen(textPtr)))
191 strcpy((char *)PTR_SEG_TO_LIN(lParam), textPtr);
192 return (DWORD)len;
196 return 0;
199 case WM_GETTEXTLENGTH:
201 if (wndPtr->hText)
203 textPtr = (LPSTR)USER_HEAP_LIN_ADDR(wndPtr->hText);
204 return (DWORD)strlen(textPtr);
206 return 0;
209 case WM_SETTEXT:
210 DEFWND_SetText( hwnd, (LPSTR)PTR_SEG_TO_LIN(lParam) );
211 NC_HandleNCPaint( hwnd ); /* Repaint caption */
212 return 0;
214 case WM_SETCURSOR:
215 if (wndPtr->dwStyle & WS_CHILD)
216 if (SendMessage(wndPtr->hwndParent, WM_SETCURSOR, wParam, lParam))
217 return TRUE;
218 return NC_HandleSetCursor( hwnd, wParam, lParam );
220 case WM_SYSCOMMAND:
221 return NC_HandleSysCommand( hwnd, wParam, MAKEPOINT(lParam) );
223 case WM_SYSKEYDOWN:
224 if (wParam == VK_MENU)
225 { /* Send to WS_OVERLAPPED parent. TODO: Handle MDI */
226 SendMessage( WIN_GetTopParent(hwnd), WM_SYSCOMMAND,
227 SC_KEYMENU, 0L );
229 break;
231 case WM_SYSKEYUP:
232 break;
234 return 0;