2 * Default window procedure
4 * Copyright 1993 Alexandre Julliard
13 #include "nonclient.h"
17 /* #define DEBUG_MESSAGE */
22 #define COLOR_MAX COLOR_BTNHIGHLIGHT
24 static short iMenuKey
= 0;
25 static short iMenuSysKey
= 0;
27 /***********************************************************************
30 * Set the window text.
32 void DEFWND_SetText( HWND hwnd
, LPSTR text
)
35 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
38 if (wndPtr
->hText
) USER_HEAP_FREE( wndPtr
->hText
);
39 wndPtr
->hText
= USER_HEAP_ALLOC( strlen(text
) + 1 );
40 textPtr
= (LPSTR
) USER_HEAP_LIN_ADDR( wndPtr
->hText
);
41 strcpy( textPtr
, text
);
43 XStoreName( display
, wndPtr
->window
, text
);
47 /***********************************************************************
48 * DefWindowProc (USER.107)
50 LRESULT
DefWindowProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
55 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
57 EnterSpyMessage(SPY_DEFWNDPROC
,hwnd
,msg
,wParam
,lParam
);
63 CREATESTRUCT
*createStruct
= (CREATESTRUCT
*)PTR_SEG_TO_LIN(lParam
);
64 if (createStruct
->lpszName
)
66 (LPSTR
)PTR_SEG_TO_LIN(createStruct
->lpszName
) );
71 return NC_HandleNCCalcSize( hwnd
,
72 (NCCALCSIZE_PARAMS
*)PTR_SEG_TO_LIN(lParam
) );
76 return NC_HandleNCPaint( hwnd
);
80 POINT pt
= { LOWORD(lParam
), HIWORD(lParam
) };
81 return NC_HandleNCHitTest( hwnd
, pt
);
84 case WM_NCLBUTTONDOWN
:
85 return NC_HandleNCLButtonDown( hwnd
, wParam
, lParam
);
87 case WM_LBUTTONDBLCLK
:
88 case WM_NCLBUTTONDBLCLK
:
89 return NC_HandleNCLButtonDblClk( hwnd
, wParam
, lParam
);
92 return NC_HandleNCActivate( hwnd
, wParam
);
95 if (wndPtr
->hText
) USER_HEAP_FREE(wndPtr
->hText
);
96 if (wndPtr
->hVScroll
) USER_HEAP_FREE(wndPtr
->hVScroll
);
97 if (wndPtr
->hHScroll
) USER_HEAP_FREE(wndPtr
->hHScroll
);
98 wndPtr
->hText
= wndPtr
->hVScroll
= wndPtr
->hHScroll
= 0;
103 PAINTSTRUCT paintstruct
;
104 BeginPaint( hwnd
, &paintstruct
);
105 EndPaint( hwnd
, &paintstruct
);
112 ValidateRect( hwnd
, NULL
);
113 wndPtr
->flags
|= WIN_NO_REDRAW
;
115 else wndPtr
->flags
&= ~WIN_NO_REDRAW
;
119 DestroyWindow( hwnd
);
122 case WM_MOUSEACTIVATE
:
123 if (wndPtr
->dwStyle
& WS_CHILD
)
125 LONG ret
= SendMessage( wndPtr
->hwndParent
, WM_MOUSEACTIVATE
,
132 /* LOWORD() needed for WINELIB32 implementation. Should be fine. */
133 if (LOWORD(wParam
)!=WA_INACTIVE
) SetFocus( hwnd
);
136 case WM_WINDOWPOSCHANGING
:
137 return WINPOS_HandleWindowPosChanging( (WINDOWPOS
*)PTR_SEG_TO_LIN(lParam
) );
139 case WM_WINDOWPOSCHANGED
:
141 WINDOWPOS
* winPos
= (WINDOWPOS
*)PTR_SEG_TO_LIN(lParam
);
142 if (!(winPos
->flags
& SWP_NOMOVE
))
143 SendMessage( hwnd
, WM_MOVE
, 0,
144 MAKELONG( wndPtr
->rectClient
.left
,
145 wndPtr
->rectClient
.top
));
146 if (!(winPos
->flags
& SWP_NOSIZE
))
147 SendMessage( hwnd
, WM_SIZE
, SIZE_RESTORED
,
148 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
149 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
154 case WM_ICONERASEBKGND
:
156 if (!(classPtr
= CLASS_FindClassPtr( wndPtr
->hClass
))) return 0;
157 if (!classPtr
->wc
.hbrBackground
) return 0;
158 if (classPtr
->wc
.hbrBackground
<= (HBRUSH
)(COLOR_MAX
+1))
161 hbrush
= CreateSolidBrush(
162 GetSysColor(((DWORD
)classPtr
->wc
.hbrBackground
)-1));
163 FillWindow( GetParent(hwnd
), hwnd
, (HDC
)wParam
, hbrush
);
164 DeleteObject (hbrush
);
167 FillWindow( GetParent(hwnd
), hwnd
, (HDC
)wParam
,
168 classPtr
->wc
.hbrBackground
);
175 case WM_CTLCOLORMSGBOX
:
176 case WM_CTLCOLOREDIT
:
177 case WM_CTLCOLORLISTBOX
:
180 case WM_CTLCOLORSTATIC
:
181 SetBkColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOW
) );
182 SetTextColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
183 return (LONG
)sysColorObjects
.hbrushWindow
;
185 case WM_CTLCOLORSCROLLBAR
:
186 SetBkColor( (HDC
)wParam
, RGB(255, 255, 255) );
187 SetTextColor( (HDC
)wParam
, RGB(0, 0, 0) );
188 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
189 return (LONG
)sysColorObjects
.hbrushScrollbar
;
193 if (HIWORD(lParam
) == CTLCOLOR_SCROLLBAR
)
195 SetBkColor( (HDC
)wParam
, RGB(255, 255, 255) );
196 SetTextColor( (HDC
)wParam
, RGB(0, 0, 0) );
197 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
198 return (LONG
)sysColorObjects
.hbrushScrollbar
;
202 SetBkColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOW
) );
203 SetTextColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
204 return (LONG
)sysColorObjects
.hbrushWindow
;
214 textPtr
= (LPSTR
)USER_HEAP_LIN_ADDR(wndPtr
->hText
);
215 if ((int)wParam
> (len
= strlen(textPtr
)))
217 strcpy((char *)PTR_SEG_TO_LIN(lParam
), textPtr
);
225 case WM_GETTEXTLENGTH
:
229 textPtr
= (LPSTR
)USER_HEAP_LIN_ADDR(wndPtr
->hText
);
230 return (DWORD
)strlen(textPtr
);
236 DEFWND_SetText( hwnd
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
237 NC_HandleNCPaint( hwnd
); /* Repaint caption */
241 if (wndPtr
->dwStyle
& WS_CHILD
)
242 if (SendMessage(wndPtr
->hwndParent
, WM_SETCURSOR
, wParam
, lParam
))
244 return NC_HandleSetCursor( hwnd
, wParam
, lParam
);
248 POINT pt
= { LOWORD(lParam
), HIWORD(lParam
) };
249 return NC_HandleSysCommand( hwnd
, wParam
, pt
);
254 if(wParam
== VK_F10
) iMenuKey
= VK_F10
;
258 /* this breaks current pseudo accelerators but
259 creates a basis for implementing real ones */
267 if (wParam
== VK_MENU
)
269 iMenuSysKey
= (iMenuSysKey
)? 0: 1;
277 if( (wParam
== VK_MENU
&& iMenuSysKey
) ||
278 (wParam
== VK_F10
&& iMenuKey
) )
280 /* Send to WS_OVERLAPPED parent. TODO: Handle MDI */
281 SendMessage( WIN_GetTopParent(hwnd
), WM_SYSCOMMAND
,
289 if( !lParam
) return 0; /* sent from ShowWindow */
291 if( !(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->hwndOwner
)
294 if( wndPtr
->dwStyle
& WS_VISIBLE
)
295 { if( wParam
) return 0; }
297 if(!wParam
) return 0;
299 ShowWindow(hwnd
,(wParam
)? SW_SHOWNOACTIVATE
: SW_HIDE
);
304 /* EndMenu() should be called if in menu state but currently it's
305 impossible to detect - menu code should be updated*/
307 if( GetCapture() == hwnd
)
319 case WM_QUERYDROPOBJECT
:
320 if(wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
)
324 case WM_QUERYDRAGICON
:
330 if( (hI
= LoadIcon(wndPtr
->hInstance
,MAKEINTRESOURCE(len
))) )
336 case WM_QUERYENDSESSION
: