]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
faa49bfd WS |
2 | // Name: src/msw/window.cpp |
3 | // Purpose: wxWindowMSW | |
2bda0e17 | 4 | // Author: Julian Smart |
a23fd0e1 | 5 | // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation |
2bda0e17 KB |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
a23fd0e1 VZ |
12 | // =========================================================================== |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
09914df7 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
e4db172a WS |
27 | #include "wx/window.h" |
28 | ||
2bda0e17 | 29 | #ifndef WX_PRECOMP |
9ed0d735 | 30 | #include "wx/msw/wrapwin.h" |
57bd4c60 WS |
31 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
32 | #include "wx/msw/missing.h" | |
0c589ad0 | 33 | #include "wx/accel.h" |
3a19e16d VZ |
34 | #include "wx/menu.h" |
35 | #include "wx/dc.h" | |
36 | #include "wx/dcclient.h" | |
8e92ccef | 37 | #include "wx/dcmemory.h" |
3a19e16d VZ |
38 | #include "wx/utils.h" |
39 | #include "wx/app.h" | |
3a19e16d VZ |
40 | #include "wx/layout.h" |
41 | #include "wx/dialog.h" | |
42 | #include "wx/frame.h" | |
43 | #include "wx/listbox.h" | |
44 | #include "wx/button.h" | |
3a19e16d | 45 | #include "wx/msgdlg.h" |
1f3943e0 | 46 | #include "wx/settings.h" |
8d753488 | 47 | #include "wx/statbox.h" |
1e2aa2f8 | 48 | #include "wx/sizer.h" |
88a7a4e1 | 49 | #include "wx/intl.h" |
e4db172a | 50 | #include "wx/log.h" |
fec9cc08 | 51 | #include "wx/textctrl.h" |
25466131 | 52 | #include "wx/menuitem.h" |
02761f6c | 53 | #include "wx/module.h" |
2bda0e17 KB |
54 | #endif |
55 | ||
61fef19b | 56 | #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__) |
09914df7 | 57 | #include "wx/ownerdrw.h" |
2bda0e17 KB |
58 | #endif |
59 | ||
5acec112 | 60 | #include "wx/hashmap.h" |
a3dc1da9 | 61 | #include "wx/evtloop.h" |
355debca | 62 | #include "wx/power.h" |
c6430ed0 | 63 | #include "wx/sysopt.h" |
d79df32c | 64 | |
9e2896e5 VZ |
65 | #if wxUSE_DRAG_AND_DROP |
66 | #include "wx/dnd.h" | |
2bda0e17 KB |
67 | #endif |
68 | ||
ed5317e5 JS |
69 | #if wxUSE_ACCESSIBILITY |
70 | #include "wx/access.h" | |
bef8d481 | 71 | #include <ole2.h> |
ed5317e5 JS |
72 | #include <oleacc.h> |
73 | #ifndef WM_GETOBJECT | |
74 | #define WM_GETOBJECT 0x003D | |
75 | #endif | |
76 | #ifndef OBJID_CLIENT | |
77 | #define OBJID_CLIENT 0xFFFFFFFC | |
78 | #endif | |
79 | #endif | |
80 | ||
0c589ad0 | 81 | #include "wx/msw/private.h" |
888dde65 | 82 | #include "wx/msw/dcclient.h" |
0c589ad0 | 83 | |
750b78ba | 84 | #if wxUSE_TOOLTIPS |
42e69d6b | 85 | #include "wx/tooltip.h" |
750b78ba JS |
86 | #endif |
87 | ||
789295bf VZ |
88 | #if wxUSE_CARET |
89 | #include "wx/caret.h" | |
90 | #endif // wxUSE_CARET | |
91 | ||
6fe19057 VZ |
92 | #if wxUSE_SPINCTRL |
93 | #include "wx/spinctrl.h" | |
94 | #endif // wxUSE_SPINCTRL | |
95 | ||
d9317fd4 | 96 | #include "wx/notebook.h" |
5c6c3176 | 97 | #include "wx/listctrl.h" |
aafb9978 | 98 | #include "wx/dynlib.h" |
2a47d3c1 | 99 | |
2bda0e17 KB |
100 | #include <string.h> |
101 | ||
d61c1a6f | 102 | #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__) |
3a19e16d VZ |
103 | #include <shellapi.h> |
104 | #include <mmsystem.h> | |
2bda0e17 KB |
105 | #endif |
106 | ||
107 | #ifdef __WIN32__ | |
3a19e16d | 108 | #include <windowsx.h> |
2bda0e17 KB |
109 | #endif |
110 | ||
dcfd4ac4 | 111 | #if !defined __WXWINCE__ && !defined NEED_PBT_H |
dbc74bcc WS |
112 | #include <pbt.h> |
113 | #endif | |
2bda0e17 | 114 | |
7f0586ef | 115 | #if defined(__WXWINCE__) |
4e5c6c33 | 116 | #include "wx/msw/wince/missing.h" |
7d4f65e3 JS |
117 | #ifdef __POCKETPC__ |
118 | #include <windows.h> | |
119 | #include <shellapi.h> | |
120 | #include <ole2.h> | |
121 | #include <aygshell.h> | |
122 | #endif | |
7f0586ef JS |
123 | #endif |
124 | ||
a047aff2 JS |
125 | #if wxUSE_UXTHEME |
126 | #include "wx/msw/uxtheme.h" | |
127 | #define EP_EDITTEXT 1 | |
128 | #define ETS_NORMAL 1 | |
129 | #define ETS_HOT 2 | |
130 | #define ETS_SELECTED 3 | |
131 | #define ETS_DISABLED 4 | |
132 | #define ETS_FOCUSED 5 | |
133 | #define ETS_READONLY 6 | |
134 | #define ETS_ASSIST 7 | |
135 | #endif | |
136 | ||
21487550 VZ |
137 | // define the constants used by AnimateWindow() if our SDK doesn't have them |
138 | #ifndef AW_CENTER | |
139 | #define AW_HOR_POSITIVE 0x00000001 | |
140 | #define AW_HOR_NEGATIVE 0x00000002 | |
141 | #define AW_VER_POSITIVE 0x00000004 | |
142 | #define AW_VER_NEGATIVE 0x00000008 | |
143 | #define AW_CENTER 0x00000010 | |
144 | #define AW_HIDE 0x00010000 | |
145 | #define AW_ACTIVATE 0x00020000 | |
146 | #define AW_SLIDE 0x00040000 | |
147 | #define AW_BLEND 0x00080000 | |
148 | #endif | |
149 | ||
aafb9978 | 150 | #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS |
4e5c6c33 VZ |
151 | #define HAVE_TRACKMOUSEEVENT |
152 | #endif // everything needed for TrackMouseEvent() | |
153 | ||
c358ea41 VZ |
154 | // set this to 1 to filter out duplicate mouse events, e.g. mouse move events |
155 | // when mouse position didnd't change | |
156 | #ifdef __WXWINCE__ | |
157 | #define wxUSE_MOUSEEVENT_HACK 0 | |
158 | #else | |
159 | #define wxUSE_MOUSEEVENT_HACK 1 | |
160 | #endif | |
161 | ||
2f68482e VZ |
162 | // not all compilers/platforms have X button related declarations (notably |
163 | // Windows CE doesn't, and probably some old SDKs don't neither) | |
164 | #ifdef WM_XBUTTONDOWN | |
165 | #define wxHAS_XBUTTON | |
166 | #endif | |
167 | ||
a23fd0e1 | 168 | // --------------------------------------------------------------------------- |
42e69d6b | 169 | // global variables |
a23fd0e1 | 170 | // --------------------------------------------------------------------------- |
47cbd6da | 171 | |
1950edc3 RR |
172 | #if wxUSE_MENUS_NATIVE |
173 | extern wxMenu *wxCurrentPopupMenu; | |
174 | #endif | |
175 | ||
bec9bf3e VZ |
176 | namespace |
177 | { | |
178 | ||
90c1530a VZ |
179 | // true if we had already created the std colour map, used by |
180 | // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT) | |
bec9bf3e | 181 | bool gs_hasStdCmap = false; |
90c1530a | 182 | |
c358ea41 VZ |
183 | // last mouse event information we need to filter out the duplicates |
184 | #if wxUSE_MOUSEEVENT_HACK | |
bec9bf3e | 185 | struct MouseEventInfoDummy |
c358ea41 VZ |
186 | { |
187 | // mouse position (in screen coordinates) | |
188 | wxPoint pos; | |
189 | ||
190 | // last mouse event type | |
191 | wxEventType type; | |
192 | } gs_lastMouseEvent; | |
193 | #endif // wxUSE_MOUSEEVENT_HACK | |
194 | ||
5acec112 VZ |
195 | // hash containing the registered handlers for the custom messages |
196 | WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler, | |
197 | wxIntegerHash, wxIntegerEqual, | |
198 | MSWMessageHandlers); | |
199 | ||
bec9bf3e | 200 | MSWMessageHandlers gs_messageHandlers; |
5acec112 | 201 | |
dca0f651 VZ |
202 | // hash containing all our windows, it uses HWND keys and wxWindow* values |
203 | WX_DECLARE_HASH_MAP(HWND, wxWindow *, | |
204 | wxPointerHash, wxPointerEqual, | |
205 | WindowHandles); | |
206 | ||
bec9bf3e VZ |
207 | WindowHandles gs_windowHandles; |
208 | ||
209 | #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK | |
210 | ||
211 | // temporary override for WM_ERASEBKGND processing: we don't store this in | |
212 | // wxWindow itself as we don't need it during most of the time so don't | |
213 | // increase the size of all window objects unnecessarily | |
214 | WX_DECLARE_HASH_MAP(wxWindow *, wxWindow *, | |
215 | wxPointerHash, wxPointerEqual, | |
216 | EraseBgHooks); | |
217 | ||
218 | EraseBgHooks gs_eraseBgHooks; | |
219 | ||
220 | #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK | |
221 | ||
222 | } // anonymous namespace | |
dca0f651 | 223 | |
42e69d6b VZ |
224 | // --------------------------------------------------------------------------- |
225 | // private functions | |
226 | // --------------------------------------------------------------------------- | |
227 | ||
228 | // the window proc for all our windows | |
3135f4a7 | 229 | LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, |
42e69d6b | 230 | WPARAM wParam, LPARAM lParam); |
577baeef | 231 | |
42e69d6b | 232 | |
4b6a582b | 233 | #if wxDEBUG_LEVEL >= 2 |
4a712ba3 | 234 | const wxChar *wxGetMessageName(int message); |
4b6a582b | 235 | #endif // wxDEBUG_LEVEL >= 2 |
2bda0e17 | 236 | |
1e6feb95 | 237 | void wxRemoveHandleAssociation(wxWindowMSW *win); |
cc972ac6 | 238 | extern void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win); |
2bda0e17 | 239 | |
f6bcfd97 | 240 | // get the text metrics for the current font |
1e6feb95 VZ |
241 | static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win); |
242 | ||
42b1fb63 | 243 | #ifdef __WXWINCE__ |
dfafa702 | 244 | // find the window for the mouse event at the specified position |
42b1fb63 VZ |
245 | static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y); |
246 | #endif // __WXWINCE__ | |
dfafa702 | 247 | |
c48926e1 | 248 | // wrapper around BringWindowToTop() API |
44d5b352 | 249 | static inline void wxBringWindowToTop(HWND hwnd) |
c48926e1 VZ |
250 | { |
251 | #ifdef __WXMICROWIN__ | |
252 | // It seems that MicroWindows brings the _parent_ of the window to the top, | |
253 | // which can be the wrong one. | |
254 | ||
255 | // activate (set focus to) specified window | |
256 | ::SetFocus(hwnd); | |
313901f3 | 257 | #endif |
c48926e1 VZ |
258 | |
259 | // raise top level parent to top of z order | |
313901f3 | 260 | if (!::SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)) |
c48926e1 | 261 | { |
9a83f860 | 262 | wxLogLastError(wxT("SetWindowPos")); |
c48926e1 | 263 | } |
c48926e1 | 264 | } |
f6bcfd97 | 265 | |
e0c5c96f VZ |
266 | #ifndef __WXWINCE__ |
267 | ||
ee471817 VZ |
268 | // ensure that all our parent windows have WS_EX_CONTROLPARENT style |
269 | static void EnsureParentHasControlParentStyle(wxWindow *parent) | |
270 | { | |
271 | /* | |
272 | If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our | |
273 | parent as well as otherwise several Win32 functions using | |
274 | GetNextDlgTabItem() to iterate over all controls such as | |
275 | IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed, | |
276 | all of them iterate over all the controls starting from the currently | |
277 | focused one and stop iterating when they get back to the focus but | |
278 | unless all parents have WS_EX_CONTROLPARENT bit set, they would never | |
279 | get back to the initial (focused) window: as we do have this style, | |
280 | GetNextDlgTabItem() will leave this window and continue in its parent, | |
281 | but if the parent doesn't have it, it wouldn't recurse inside it later | |
90e572f1 | 282 | on and so wouldn't have a chance of getting back to this window either. |
ee471817 | 283 | */ |
ee471817 VZ |
284 | while ( parent && !parent->IsTopLevel() ) |
285 | { | |
d66d0500 | 286 | LONG exStyle = wxGetWindowExStyle(parent); |
ee471817 VZ |
287 | if ( !(exStyle & WS_EX_CONTROLPARENT) ) |
288 | { | |
289 | // force the parent to have this style | |
d66d0500 | 290 | wxSetWindowExStyle(parent, exStyle | WS_EX_CONTROLPARENT); |
ee471817 VZ |
291 | } |
292 | ||
293 | parent = parent->GetParent(); | |
294 | } | |
ee471817 VZ |
295 | } |
296 | ||
e0c5c96f VZ |
297 | #endif // !__WXWINCE__ |
298 | ||
f2325516 JS |
299 | #ifdef __WXWINCE__ |
300 | // On Windows CE, GetCursorPos can return an error, so use this function | |
301 | // instead | |
302 | bool GetCursorPosWinCE(POINT* pt) | |
303 | { | |
7d30268c JS |
304 | if (!GetCursorPos(pt)) |
305 | { | |
306 | DWORD pos = GetMessagePos(); | |
307 | pt->x = LOWORD(pos); | |
308 | pt->y = HIWORD(pos); | |
309 | } | |
f2325516 JS |
310 | return true; |
311 | } | |
312 | #endif | |
313 | ||
a23fd0e1 VZ |
314 | // --------------------------------------------------------------------------- |
315 | // event tables | |
316 | // --------------------------------------------------------------------------- | |
317 | ||
1e6feb95 VZ |
318 | // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu() |
319 | // method | |
320 | #ifdef __WXUNIVERSAL__ | |
321 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW, wxWindowBase) | |
322 | #else // __WXMSW__ | |
51596bcb | 323 | #if wxUSE_EXTENDED_RTTI |
6a89f9ee | 324 | |
f3291a82 SC |
325 | // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls |
326 | // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as | |
327 | // windows with negative ids never can be recreated anyway | |
328 | ||
329 | bool wxWindowStreamingCallback( const wxObject *object, wxWriter * , wxPersister * , wxxVariantArray & ) | |
330 | { | |
331 | const wxWindow * win = dynamic_cast<const wxWindow*>(object) ; | |
332 | if ( win && win->GetId() < 0 ) | |
333 | return false ; | |
334 | return true ; | |
335 | } | |
336 | ||
337 | IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow, wxWindowBase,"wx/window.h", wxWindowStreamingCallback) | |
51596bcb | 338 | |
6a89f9ee SC |
339 | // make wxWindowList known before the property is used |
340 | ||
321239b6 | 341 | wxCOLLECTION_TYPE_INFO( wxWindow* , wxWindowList ) ; |
6a89f9ee SC |
342 | |
343 | template<> void wxCollectionToVariantArray( wxWindowList const &theList, wxxVariantArray &value) | |
344 | { | |
0c6b0084 | 345 | wxListCollectionToVariantArray<wxWindowList::compatibility_iterator>( theList , value ) ; |
6a89f9ee SC |
346 | } |
347 | ||
bc9fb572 JS |
348 | WX_DEFINE_FLAGS( wxWindowStyle ) |
349 | ||
321239b6 | 350 | wxBEGIN_FLAGS( wxWindowStyle ) |
bc9fb572 JS |
351 | // new style border flags, we put them first to |
352 | // use them for streaming out | |
5c6c3176 | 353 | |
321239b6 SC |
354 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
355 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
356 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
357 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
358 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
359 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
35bbb0c6 | 360 | |
bc9fb572 | 361 | // old style border flags |
321239b6 SC |
362 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
363 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
364 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
365 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
366 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 367 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
368 | |
369 | // standard window styles | |
321239b6 SC |
370 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
371 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
372 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
373 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 374 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
321239b6 SC |
375 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
376 | wxFLAGS_MEMBER(wxVSCROLL) | |
377 | wxFLAGS_MEMBER(wxHSCROLL) | |
378 | ||
379 | wxEND_FLAGS( wxWindowStyle ) | |
380 | ||
381 | wxBEGIN_PROPERTIES_TABLE(wxWindow) | |
3a3c8603 DS |
382 | wxEVENT_PROPERTY( Close , wxEVT_CLOSE_WINDOW , wxCloseEvent) |
383 | wxEVENT_PROPERTY( Create , wxEVT_CREATE , wxWindowCreateEvent ) | |
384 | wxEVENT_PROPERTY( Destroy , wxEVT_DESTROY , wxWindowDestroyEvent ) | |
51741307 SC |
385 | // Always constructor Properties first |
386 | ||
af498247 | 387 | wxREADONLY_PROPERTY( Parent,wxWindow*, GetParent, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
fb7e28db | 388 | wxPROPERTY( Id,wxWindowID, SetId, GetId, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) |
abb74e0f WS |
389 | wxPROPERTY( Position,wxPoint, SetPosition , GetPosition, wxDefaultPosition , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos |
390 | wxPROPERTY( Size,wxSize, SetSize, GetSize, wxDefaultSize , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size | |
af498247 | 391 | wxPROPERTY( WindowStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
51741307 SC |
392 | |
393 | // Then all relations of the object graph | |
394 | ||
321239b6 | 395 | wxREADONLY_PROPERTY_COLLECTION( Children , wxWindowList , wxWindowBase* , GetWindowChildren , wxPROP_OBJECT_GRAPH /*flags*/ , wxT("Helpstring") , wxT("group")) |
51741307 SC |
396 | |
397 | // and finally all other properties | |
398 | ||
3a3c8603 DS |
399 | wxPROPERTY( ExtraStyle , long , SetExtraStyle , GetExtraStyle , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle |
400 | wxPROPERTY( BackgroundColour , wxColour , SetBackgroundColour , GetBackgroundColour , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg | |
401 | wxPROPERTY( ForegroundColour , wxColour , SetForegroundColour , GetForegroundColour , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg | |
402 | wxPROPERTY( Enabled , bool , Enable , IsEnabled , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
403 | wxPROPERTY( Shown , bool , Show , IsShown , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
51741307 SC |
404 | #if 0 |
405 | // possible property candidates (not in xrc) or not valid in all subclasses | |
8b5d5223 | 406 | wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxEmptyString ) |
3a3c8603 | 407 | wxPROPERTY( Font , wxFont , SetFont , GetWindowFont , ) |
8b5d5223 | 408 | wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxEmptyString ) |
3a3c8603 DS |
409 | // MaxHeight, Width , MinHeight , Width |
410 | // TODO switch label to control and title to toplevels | |
6a89f9ee | 411 | |
3a3c8603 DS |
412 | wxPROPERTY( ThemeEnabled , bool , SetThemeEnabled , GetThemeEnabled , ) |
413 | //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , ) | |
414 | // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , ) | |
415 | wxPROPERTY( AutoLayout , bool , SetAutoLayout , GetAutoLayout , ) | |
6a89f9ee SC |
416 | |
417 | ||
418 | ||
51741307 | 419 | #endif |
321239b6 | 420 | wxEND_PROPERTIES_TABLE() |
51596bcb | 421 | |
321239b6 SC |
422 | wxBEGIN_HANDLERS_TABLE(wxWindow) |
423 | wxEND_HANDLERS_TABLE() | |
51596bcb | 424 | |
321239b6 | 425 | wxCONSTRUCTOR_DUMMY(wxWindow) |
6a89f9ee | 426 | |
51596bcb | 427 | #else |
1e6feb95 | 428 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) |
51596bcb | 429 | #endif |
1e6feb95 VZ |
430 | #endif // __WXUNIVERSAL__/__WXMSW__ |
431 | ||
432 | BEGIN_EVENT_TABLE(wxWindowMSW, wxWindowBase) | |
1e6feb95 | 433 | EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged) |
79099b80 | 434 | #ifdef __WXWINCE__ |
1e6feb95 | 435 | EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog) |
79099b80 | 436 | #endif |
2bda0e17 KB |
437 | END_EVENT_TABLE() |
438 | ||
a23fd0e1 VZ |
439 | // =========================================================================== |
440 | // implementation | |
441 | // =========================================================================== | |
442 | ||
42e69d6b VZ |
443 | // --------------------------------------------------------------------------- |
444 | // wxWindow utility functions | |
445 | // --------------------------------------------------------------------------- | |
446 | ||
2bda0e17 | 447 | // Find an item given the MS Windows id |
1e6feb95 | 448 | wxWindow *wxWindowMSW::FindItem(long id) const |
2bda0e17 | 449 | { |
1e6feb95 | 450 | #if wxUSE_CONTROLS |
f7637829 | 451 | wxControl *item = wxDynamicCastThis(wxControl); |
f048e32f VZ |
452 | if ( item ) |
453 | { | |
90e572f1 | 454 | // is it us or one of our "internal" children? |
1e6feb95 VZ |
455 | if ( item->GetId() == id |
456 | #ifndef __WXUNIVERSAL__ | |
457 | || (item->GetSubcontrols().Index(id) != wxNOT_FOUND) | |
458 | #endif // __WXUNIVERSAL__ | |
459 | ) | |
f048e32f VZ |
460 | { |
461 | return item; | |
462 | } | |
463 | } | |
1e6feb95 | 464 | #endif // wxUSE_CONTROLS |
f048e32f | 465 | |
222ed1d6 | 466 | wxWindowList::compatibility_iterator current = GetChildren().GetFirst(); |
2d0a075d JS |
467 | while (current) |
468 | { | |
42e69d6b | 469 | wxWindow *childWin = current->GetData(); |
2bda0e17 | 470 | |
42e69d6b | 471 | wxWindow *wnd = childWin->FindItem(id); |
cc2b7472 | 472 | if ( wnd ) |
42e69d6b | 473 | return wnd; |
2bda0e17 | 474 | |
42e69d6b | 475 | current = current->GetNext(); |
2bda0e17 | 476 | } |
42e69d6b | 477 | |
2d0a075d | 478 | return NULL; |
2bda0e17 KB |
479 | } |
480 | ||
481 | // Find an item given the MS Windows handle | |
1e6feb95 | 482 | wxWindow *wxWindowMSW::FindItemByHWND(WXHWND hWnd, bool controlOnly) const |
2bda0e17 | 483 | { |
222ed1d6 | 484 | wxWindowList::compatibility_iterator current = GetChildren().GetFirst(); |
2d0a075d | 485 | while (current) |
2bda0e17 | 486 | { |
42e69d6b VZ |
487 | wxWindow *parent = current->GetData(); |
488 | ||
2d0a075d | 489 | // Do a recursive search. |
42e69d6b | 490 | wxWindow *wnd = parent->FindItemByHWND(hWnd); |
cc2b7472 | 491 | if ( wnd ) |
42e69d6b | 492 | return wnd; |
2d0a075d | 493 | |
1e6feb95 VZ |
494 | if ( !controlOnly |
495 | #if wxUSE_CONTROLS | |
496 | || parent->IsKindOf(CLASSINFO(wxControl)) | |
497 | #endif // wxUSE_CONTROLS | |
498 | ) | |
2d0a075d | 499 | { |
42e69d6b VZ |
500 | wxWindow *item = current->GetData(); |
501 | if ( item->GetHWND() == hWnd ) | |
2d0a075d JS |
502 | return item; |
503 | else | |
504 | { | |
505 | if ( item->ContainsHWND(hWnd) ) | |
506 | return item; | |
507 | } | |
508 | } | |
42e69d6b VZ |
509 | |
510 | current = current->GetNext(); | |
2bda0e17 | 511 | } |
2d0a075d | 512 | return NULL; |
2bda0e17 KB |
513 | } |
514 | ||
515 | // Default command handler | |
1e6feb95 | 516 | bool wxWindowMSW::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) |
2bda0e17 | 517 | { |
08158721 | 518 | return false; |
2bda0e17 KB |
519 | } |
520 | ||
fd3f686c VZ |
521 | // ---------------------------------------------------------------------------- |
522 | // constructors and such | |
523 | // ---------------------------------------------------------------------------- | |
524 | ||
1e6feb95 | 525 | void wxWindowMSW::Init() |
2bda0e17 | 526 | { |
cc2b7472 | 527 | // MSW specific |
5a403e3f | 528 | m_oldWndProc = NULL; |
08158721 DS |
529 | m_mouseInWindow = false; |
530 | m_lastKeydownProcessed = false; | |
2bda0e17 | 531 | |
319fefa9 VZ |
532 | m_hWnd = 0; |
533 | ||
2d0a075d JS |
534 | m_xThumbSize = 0; |
535 | m_yThumbSize = 0; | |
2bda0e17 | 536 | |
f5c1b76c VZ |
537 | #if wxUSE_DEFERRED_SIZING |
538 | m_hDWP = 0; | |
67644c1d RD |
539 | m_pendingPosition = wxDefaultPosition; |
540 | m_pendingSize = wxDefaultSize; | |
f5c1b76c | 541 | #endif // wxUSE_DEFERRED_SIZING |
7d4f65e3 JS |
542 | |
543 | #ifdef __POCKETPC__ | |
544 | m_contextMenuEnabled = false; | |
545 | #endif | |
fd3f686c VZ |
546 | } |
547 | ||
2bda0e17 | 548 | // Destructor |
1e6feb95 | 549 | wxWindowMSW::~wxWindowMSW() |
2bda0e17 | 550 | { |
c6212a0c | 551 | SendDestroyEvent(); |
2bda0e17 | 552 | |
2e9f62da | 553 | #ifndef __WXUNIVERSAL__ |
4a41c655 | 554 | // VS: make sure there's no wxFrame with last focus set to us: |
2e9f62da | 555 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) |
4a41c655 | 556 | { |
085ad686 | 557 | wxTopLevelWindow *frame = wxDynamicCast(win, wxTopLevelWindow); |
4a41c655 VS |
558 | if ( frame ) |
559 | { | |
c5053639 | 560 | if ( frame->GetLastFocus() == this ) |
2e9f62da | 561 | { |
085ad686 | 562 | frame->SetLastFocus(NULL); |
2e9f62da | 563 | } |
4552892f VZ |
564 | |
565 | // apparently sometimes we can end up with our grand parent | |
566 | // pointing to us as well: this is surely a bug in focus handling | |
567 | // code but it's not clear where it happens so for now just try to | |
568 | // fix it here by not breaking out of the loop | |
569 | //break; | |
4a41c655 VS |
570 | } |
571 | } | |
2e9f62da | 572 | #endif // __WXUNIVERSAL__ |
2bda0e17 | 573 | |
cc0c7cd8 | 574 | // VS: destroy children first and _then_ detach *this from its parent. |
90e572f1 | 575 | // If we did it the other way around, children wouldn't be able |
cc0c7cd8 VS |
576 | // find their parent frame (see above). |
577 | DestroyChildren(); | |
578 | ||
cc2b7472 | 579 | if ( m_hWnd ) |
42e69d6b | 580 | { |
98440bc3 VZ |
581 | // VZ: test temp removed to understand what really happens here |
582 | //if (::IsWindow(GetHwnd())) | |
df61c009 JS |
583 | { |
584 | if ( !::DestroyWindow(GetHwnd()) ) | |
43b2d5e7 | 585 | { |
f6bcfd97 | 586 | wxLogLastError(wxT("DestroyWindow")); |
43b2d5e7 | 587 | } |
df61c009 | 588 | } |
2bda0e17 | 589 | |
c50f1fb9 VZ |
590 | // remove hWnd <-> wxWindow association |
591 | wxRemoveHandleAssociation(this); | |
592 | } | |
d7cbabe0 | 593 | |
2bda0e17 KB |
594 | } |
595 | ||
d9698bd4 VZ |
596 | /* static */ |
597 | const wxChar *wxWindowMSW::MSWGetRegisteredClassName() | |
598 | { | |
9a83f860 | 599 | return wxApp::GetRegisteredClassName(wxT("wxWindow"), COLOR_BTNFACE); |
d9698bd4 VZ |
600 | } |
601 | ||
fd3f686c | 602 | // real construction (Init() must have been called before!) |
1e6feb95 VZ |
603 | bool wxWindowMSW::Create(wxWindow *parent, |
604 | wxWindowID id, | |
605 | const wxPoint& pos, | |
606 | const wxSize& size, | |
607 | long style, | |
608 | const wxString& name) | |
2d0a075d | 609 | { |
08158721 | 610 | wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") ); |
2bda0e17 | 611 | |
8d99be5f | 612 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) |
08158721 | 613 | return false; |
42e69d6b | 614 | |
fd3f686c | 615 | parent->AddChild(this); |
2bda0e17 | 616 | |
b2d5a7ee | 617 | WXDWORD exstyle; |
e49d97e6 | 618 | DWORD msflags = MSWGetCreateWindowFlags(&exstyle); |
1e6feb95 VZ |
619 | |
620 | #ifdef __WXUNIVERSAL__ | |
d1fe917b | 621 | // no borders, we draw them ourselves |
76c79ff4 VZ |
622 | exstyle &= ~(WS_EX_DLGMODALFRAME | |
623 | WS_EX_STATICEDGE | | |
624 | WS_EX_CLIENTEDGE | | |
625 | WS_EX_WINDOWEDGE); | |
d1fe917b | 626 | msflags &= ~WS_BORDER; |
b2d5a7ee | 627 | #endif // wxUniversal |
1e6feb95 | 628 | |
ff792344 | 629 | if ( IsShown() ) |
e49d97e6 VZ |
630 | { |
631 | msflags |= WS_VISIBLE; | |
632 | } | |
1e6feb95 | 633 | |
d9698bd4 VZ |
634 | if ( !MSWCreate(MSWGetRegisteredClassName(), |
635 | NULL, pos, size, msflags, exstyle) ) | |
45956e37 VZ |
636 | return false; |
637 | ||
638 | InheritAttributes(); | |
639 | ||
640 | return true; | |
2bda0e17 KB |
641 | } |
642 | ||
42e69d6b VZ |
643 | // --------------------------------------------------------------------------- |
644 | // basic operations | |
645 | // --------------------------------------------------------------------------- | |
646 | ||
1e6feb95 | 647 | void wxWindowMSW::SetFocus() |
2bda0e17 | 648 | { |
a23fd0e1 | 649 | HWND hWnd = GetHwnd(); |
9a83f860 | 650 | wxCHECK_RET( hWnd, wxT("can't set focus to invalid window") ); |
1e6feb95 | 651 | |
4b6a582b | 652 | #if !defined(__WXWINCE__) |
1e6feb95 | 653 | ::SetLastError(0); |
8cb172b4 | 654 | #endif |
d0a3d109 | 655 | |
1e6feb95 VZ |
656 | if ( !::SetFocus(hWnd) ) |
657 | { | |
658 | // was there really an error? | |
659 | DWORD dwRes = ::GetLastError(); | |
660 | if ( dwRes ) | |
661 | { | |
5262eb0a VZ |
662 | HWND hwndFocus = ::GetFocus(); |
663 | if ( hwndFocus != hWnd ) | |
664 | { | |
9a83f860 | 665 | wxLogApiError(wxT("SetFocus"), dwRes); |
5262eb0a | 666 | } |
1e6feb95 | 667 | } |
1e6feb95 | 668 | } |
2bda0e17 KB |
669 | } |
670 | ||
ddf9d04f VZ |
671 | void wxWindowMSW::SetFocusFromKbd() |
672 | { | |
ddf9d04f VZ |
673 | // when the focus is given to the control with DLGC_HASSETSEL style from |
674 | // keyboard its contents should be entirely selected: this is what | |
675 | // ::IsDialogMessage() does and so we should do it as well to provide the | |
676 | // same LNF as the native programs | |
677 | if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE, 0, 0) & DLGC_HASSETSEL ) | |
678 | { | |
679 | ::SendMessage(GetHwnd(), EM_SETSEL, 0, -1); | |
680 | } | |
1b1ca07a VZ |
681 | |
682 | // do this after (maybe) setting the selection as like this when | |
683 | // wxEVT_SET_FOCUS handler is called, the selection would have been already | |
684 | // set correctly -- this may be important | |
685 | wxWindowBase::SetFocusFromKbd(); | |
ddf9d04f VZ |
686 | } |
687 | ||
42e69d6b | 688 | // Get the window with the focus |
0fe02759 | 689 | wxWindow *wxWindowBase::DoFindFocus() |
42e69d6b VZ |
690 | { |
691 | HWND hWnd = ::GetFocus(); | |
692 | if ( hWnd ) | |
693 | { | |
a2242341 | 694 | return wxGetWindowFromHWND((WXHWND)hWnd); |
42e69d6b VZ |
695 | } |
696 | ||
697 | return NULL; | |
698 | } | |
699 | ||
47a8a4d5 | 700 | void wxWindowMSW::DoEnable( bool enable ) |
2bda0e17 | 701 | { |
a23fd0e1 | 702 | HWND hWnd = GetHwnd(); |
cc2b7472 | 703 | if ( hWnd ) |
2d0a075d | 704 | ::EnableWindow(hWnd, (BOOL)enable); |
2bda0e17 KB |
705 | } |
706 | ||
1e6feb95 | 707 | bool wxWindowMSW::Show(bool show) |
42e69d6b VZ |
708 | { |
709 | if ( !wxWindowBase::Show(show) ) | |
08158721 | 710 | return false; |
42e69d6b VZ |
711 | |
712 | HWND hWnd = GetHwnd(); | |
42e69d6b | 713 | |
a068160f VZ |
714 | // we could be called before the underlying window is created (this is |
715 | // actually useful to prevent it from being initially shown), e.g. | |
716 | // | |
717 | // wxFoo *foo = new wxFoo; | |
718 | // foo->Hide(); | |
719 | // foo->Create(parent, ...); | |
720 | // | |
721 | // should work without errors | |
722 | if ( hWnd ) | |
42e69d6b | 723 | { |
a068160f | 724 | ::ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE); |
42e69d6b VZ |
725 | } |
726 | ||
89267fe5 VS |
727 | if ( IsFrozen() ) |
728 | { | |
729 | // DoFreeze/DoThaw don't do anything if the window is not shown, so | |
730 | // we have to call them from here now | |
731 | if ( show ) | |
732 | DoFreeze(); | |
733 | else | |
734 | DoThaw(); | |
735 | } | |
736 | ||
08158721 | 737 | return true; |
42e69d6b VZ |
738 | } |
739 | ||
376d7d97 VZ |
740 | bool |
741 | wxWindowMSW::MSWShowWithEffect(bool show, | |
742 | wxShowEffect effect, | |
eed04c99 | 743 | unsigned timeout) |
376d7d97 | 744 | { |
ffa50e73 VZ |
745 | if ( effect == wxSHOW_EFFECT_NONE ) |
746 | return Show(show); | |
747 | ||
30443550 VS |
748 | if ( !wxWindowBase::Show(show) ) |
749 | return false; | |
750 | ||
376d7d97 VZ |
751 | typedef BOOL (WINAPI *AnimateWindow_t)(HWND, DWORD, DWORD); |
752 | ||
753 | static AnimateWindow_t s_pfnAnimateWindow = NULL; | |
754 | static bool s_initDone = false; | |
755 | if ( !s_initDone ) | |
756 | { | |
9a83f860 | 757 | wxDynamicLibrary dllUser32(wxT("user32.dll"), wxDL_VERBATIM | wxDL_QUIET); |
376d7d97 VZ |
758 | wxDL_INIT_FUNC(s_pfn, AnimateWindow, dllUser32); |
759 | ||
760 | s_initDone = true; | |
761 | ||
762 | // notice that it's ok to unload user32.dll here as it won't be really | |
763 | // unloaded, being still in use because we link to it statically too | |
764 | } | |
765 | ||
766 | if ( !s_pfnAnimateWindow ) | |
767 | return Show(show); | |
768 | ||
7157abfb VZ |
769 | // Show() has a side effect of sending a WM_SIZE to the window, which helps |
770 | // ensuring that it's laid out correctly, but AnimateWindow() doesn't do | |
771 | // this so send the event ourselves | |
772 | SendSizeEvent(); | |
773 | ||
376d7d97 VZ |
774 | // prepare to use AnimateWindow() |
775 | ||
776 | if ( !timeout ) | |
777 | timeout = 200; // this is the default animation timeout, per MSDN | |
778 | ||
779 | DWORD dwFlags = show ? 0 : AW_HIDE; | |
eed04c99 | 780 | |
376d7d97 VZ |
781 | switch ( effect ) |
782 | { | |
eed04c99 VS |
783 | case wxSHOW_EFFECT_ROLL_TO_LEFT: |
784 | dwFlags |= AW_HOR_NEGATIVE; | |
785 | break; | |
786 | ||
787 | case wxSHOW_EFFECT_ROLL_TO_RIGHT: | |
788 | dwFlags |= AW_HOR_POSITIVE; | |
789 | break; | |
790 | ||
791 | case wxSHOW_EFFECT_ROLL_TO_TOP: | |
792 | dwFlags |= AW_VER_NEGATIVE; | |
793 | break; | |
794 | ||
795 | case wxSHOW_EFFECT_ROLL_TO_BOTTOM: | |
796 | dwFlags |= AW_VER_POSITIVE; | |
797 | break; | |
798 | ||
799 | case wxSHOW_EFFECT_SLIDE_TO_LEFT: | |
800 | dwFlags |= AW_SLIDE | AW_HOR_NEGATIVE; | |
801 | break; | |
802 | ||
803 | case wxSHOW_EFFECT_SLIDE_TO_RIGHT: | |
804 | dwFlags |= AW_SLIDE | AW_HOR_POSITIVE; | |
805 | break; | |
806 | ||
807 | case wxSHOW_EFFECT_SLIDE_TO_TOP: | |
808 | dwFlags |= AW_SLIDE | AW_VER_NEGATIVE; | |
376d7d97 VZ |
809 | break; |
810 | ||
eed04c99 VS |
811 | case wxSHOW_EFFECT_SLIDE_TO_BOTTOM: |
812 | dwFlags |= AW_SLIDE | AW_VER_POSITIVE; | |
376d7d97 VZ |
813 | break; |
814 | ||
815 | case wxSHOW_EFFECT_BLEND: | |
816 | dwFlags |= AW_BLEND; | |
817 | break; | |
818 | ||
819 | case wxSHOW_EFFECT_EXPAND: | |
820 | dwFlags |= AW_CENTER; | |
821 | break; | |
822 | ||
823 | ||
824 | case wxSHOW_EFFECT_MAX: | |
9a83f860 | 825 | wxFAIL_MSG( wxT("invalid window show effect") ); |
376d7d97 VZ |
826 | return false; |
827 | ||
828 | default: | |
9a83f860 | 829 | wxFAIL_MSG( wxT("unknown window show effect") ); |
376d7d97 VZ |
830 | return false; |
831 | } | |
832 | ||
376d7d97 VZ |
833 | if ( !(*s_pfnAnimateWindow)(GetHwnd(), timeout, dwFlags) ) |
834 | { | |
9a83f860 | 835 | wxLogLastError(wxT("AnimateWindow")); |
376d7d97 VZ |
836 | |
837 | return false; | |
838 | } | |
839 | ||
840 | return true; | |
841 | } | |
842 | ||
42e69d6b | 843 | // Raise the window to the top of the Z order |
1e6feb95 | 844 | void wxWindowMSW::Raise() |
42e69d6b | 845 | { |
c48926e1 | 846 | wxBringWindowToTop(GetHwnd()); |
42e69d6b VZ |
847 | } |
848 | ||
849 | // Lower the window to the bottom of the Z order | |
1e6feb95 | 850 | void wxWindowMSW::Lower() |
42e69d6b VZ |
851 | { |
852 | ::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, | |
853 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | |
854 | } | |
855 | ||
94633ad9 | 856 | void wxWindowMSW::DoCaptureMouse() |
2bda0e17 | 857 | { |
a23fd0e1 | 858 | HWND hWnd = GetHwnd(); |
1e6feb95 | 859 | if ( hWnd ) |
2d0a075d | 860 | { |
1e6feb95 | 861 | ::SetCapture(hWnd); |
2d0a075d | 862 | } |
2bda0e17 KB |
863 | } |
864 | ||
94633ad9 | 865 | void wxWindowMSW::DoReleaseMouse() |
2bda0e17 | 866 | { |
1e6feb95 | 867 | if ( !::ReleaseCapture() ) |
2d0a075d | 868 | { |
9a83f860 | 869 | wxLogLastError(wxT("ReleaseCapture")); |
2d0a075d | 870 | } |
2bda0e17 KB |
871 | } |
872 | ||
1e6feb95 VZ |
873 | /* static */ wxWindow *wxWindowBase::GetCapture() |
874 | { | |
875 | HWND hwnd = ::GetCapture(); | |
dca0f651 | 876 | return hwnd ? wxFindWinFromHandle(hwnd) : NULL; |
1e6feb95 VZ |
877 | } |
878 | ||
879 | bool wxWindowMSW::SetFont(const wxFont& font) | |
2bda0e17 | 880 | { |
42e69d6b VZ |
881 | if ( !wxWindowBase::SetFont(font) ) |
882 | { | |
883 | // nothing to do | |
08158721 | 884 | return false; |
2d0a075d | 885 | } |
195896c7 | 886 | |
42e69d6b VZ |
887 | HWND hWnd = GetHwnd(); |
888 | if ( hWnd != 0 ) | |
889 | { | |
d8df8893 VZ |
890 | // note the use of GetFont() instead of m_font: our own font could have |
891 | // just been reset and in this case we need to change the font used by | |
892 | // the native window to the default for this class, i.e. exactly what | |
893 | // GetFont() returns | |
894 | WXHANDLE hFont = GetFont().GetResourceHandle(); | |
2bda0e17 | 895 | |
223d09f6 | 896 | wxASSERT_MSG( hFont, wxT("should have valid font") ); |
3a19e16d | 897 | |
c50f1fb9 | 898 | ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); |
42e69d6b | 899 | } |
2bda0e17 | 900 | |
08158721 | 901 | return true; |
42e69d6b | 902 | } |
1e6feb95 | 903 | bool wxWindowMSW::SetCursor(const wxCursor& cursor) |
2bda0e17 | 904 | { |
42e69d6b VZ |
905 | if ( !wxWindowBase::SetCursor(cursor) ) |
906 | { | |
907 | // no change | |
08158721 | 908 | return false; |
42e69d6b VZ |
909 | } |
910 | ||
8e75dca8 VZ |
911 | // don't "overwrite" busy cursor |
912 | if ( m_cursor.Ok() && !wxIsBusy() ) | |
8a9c2246 | 913 | { |
a8b2285e VZ |
914 | // normally we should change the cursor only if it's over this window |
915 | // but we should do it always if we capture the mouse currently | |
916 | bool set = HasCapture(); | |
917 | if ( !set ) | |
918 | { | |
919 | HWND hWnd = GetHwnd(); | |
920 | ||
921 | POINT point; | |
922 | #ifdef __WXWINCE__ | |
923 | ::GetCursorPosWinCE(&point); | |
924 | #else | |
925 | ::GetCursorPos(&point); | |
926 | #endif | |
927 | ||
928 | RECT rect = wxGetWindowRect(hWnd); | |
929 | ||
930 | set = ::PtInRect(&rect, point) != 0; | |
931 | } | |
932 | ||
933 | if ( set ) | |
934 | { | |
935 | ::SetCursor(GetHcursorOf(m_cursor)); | |
936 | } | |
937 | //else: will be set later when the mouse enters this window | |
8a9c2246 | 938 | } |
3a19e16d | 939 | |
08158721 | 940 | return true; |
3a19e16d VZ |
941 | } |
942 | ||
d7e0024b | 943 | void wxWindowMSW::WarpPointer(int x, int y) |
2bda0e17 | 944 | { |
1e6feb95 | 945 | ClientToScreen(&x, &y); |
42e69d6b | 946 | |
1e6feb95 VZ |
947 | if ( !::SetCursorPos(x, y) ) |
948 | { | |
9a83f860 | 949 | wxLogLastError(wxT("SetCursorPos")); |
1e6feb95 | 950 | } |
2bda0e17 KB |
951 | } |
952 | ||
1ca78aa1 | 953 | void wxWindowMSW::MSWUpdateUIState(int action, int state) |
d7e0024b | 954 | { |
1ca78aa1 | 955 | // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good |
d7e0024b VZ |
956 | // to use it on older systems -- and could possibly do some harm |
957 | static int s_needToUpdate = -1; | |
958 | if ( s_needToUpdate == -1 ) | |
959 | { | |
960 | int verMaj, verMin; | |
406d283a | 961 | s_needToUpdate = wxGetOsVersion(&verMaj, &verMin) == wxOS_WINDOWS_NT && |
d7e0024b VZ |
962 | verMaj >= 5; |
963 | } | |
964 | ||
965 | if ( s_needToUpdate ) | |
966 | { | |
1ca78aa1 JS |
967 | // we send WM_CHANGEUISTATE so if nothing needs changing then the system |
968 | // won't send WM_UPDATEUISTATE | |
969 | ::SendMessage(GetHwnd(), WM_CHANGEUISTATE, MAKEWPARAM(action, state), 0); | |
d7e0024b VZ |
970 | } |
971 | } | |
972 | ||
42e69d6b VZ |
973 | // --------------------------------------------------------------------------- |
974 | // scrolling stuff | |
975 | // --------------------------------------------------------------------------- | |
2d0a075d | 976 | |
1ddb6d28 VZ |
977 | namespace |
978 | { | |
979 | ||
9cd6d737 VZ |
980 | inline int GetScrollPosition(HWND hWnd, int wOrient) |
981 | { | |
982 | #ifdef __WXMICROWIN__ | |
983 | return ::GetScrollPosWX(hWnd, wOrient); | |
984 | #else | |
f676b387 | 985 | WinStruct<SCROLLINFO> scrollInfo; |
4676948b | 986 | scrollInfo.cbSize = sizeof(SCROLLINFO); |
7f0586ef | 987 | scrollInfo.fMask = SIF_POS; |
e795e8b5 | 988 | ::GetScrollInfo(hWnd, wOrient, &scrollInfo ); |
a71d815b | 989 | |
7f0586ef | 990 | return scrollInfo.nPos; |
e795e8b5 | 991 | |
9cd6d737 VZ |
992 | #endif |
993 | } | |
994 | ||
1ddb6d28 VZ |
995 | inline UINT WXOrientToSB(int orient) |
996 | { | |
997 | return orient == wxHORIZONTAL ? SB_HORZ : SB_VERT; | |
998 | } | |
999 | ||
1000 | } // anonymous namespace | |
1001 | ||
1e6feb95 | 1002 | int wxWindowMSW::GetScrollPos(int orient) const |
2bda0e17 | 1003 | { |
42e69d6b | 1004 | HWND hWnd = GetHwnd(); |
9a83f860 | 1005 | wxCHECK_MSG( hWnd, 0, wxT("no HWND in GetScrollPos") ); |
9cd6d737 | 1006 | |
1ddb6d28 | 1007 | return GetScrollPosition(hWnd, WXOrientToSB(orient)); |
42e69d6b | 1008 | } |
2bda0e17 | 1009 | |
42e69d6b VZ |
1010 | // This now returns the whole range, not just the number |
1011 | // of positions that we can scroll. | |
1e6feb95 | 1012 | int wxWindowMSW::GetScrollRange(int orient) const |
42e69d6b | 1013 | { |
7f0586ef | 1014 | int maxPos; |
a23fd0e1 | 1015 | HWND hWnd = GetHwnd(); |
0cf5de11 | 1016 | if ( !hWnd ) |
42e69d6b | 1017 | return 0; |
f676b387 | 1018 | WinStruct<SCROLLINFO> scrollInfo; |
7f0586ef | 1019 | scrollInfo.fMask = SIF_RANGE; |
1ddb6d28 | 1020 | if ( !::GetScrollInfo(hWnd, WXOrientToSB(orient), &scrollInfo) ) |
7f0586ef | 1021 | { |
f676b387 RD |
1022 | // Most of the time this is not really an error, since the return |
1023 | // value can also be zero when there is no scrollbar yet. | |
9a83f860 | 1024 | // wxLogLastError(wxT("GetScrollInfo")); |
7f0586ef JS |
1025 | } |
1026 | maxPos = scrollInfo.nMax; | |
0cf5de11 VZ |
1027 | |
1028 | // undo "range - 1" done in SetScrollbar() | |
1029 | return maxPos + 1; | |
cc2b7472 | 1030 | } |
2bda0e17 | 1031 | |
1e6feb95 | 1032 | int wxWindowMSW::GetScrollThumb(int orient) const |
2bda0e17 | 1033 | { |
0cf5de11 | 1034 | return orient == wxHORIZONTAL ? m_xThumbSize : m_yThumbSize; |
2bda0e17 KB |
1035 | } |
1036 | ||
1e6feb95 | 1037 | void wxWindowMSW::SetScrollPos(int orient, int pos, bool refresh) |
2bda0e17 | 1038 | { |
5f3286d1 | 1039 | HWND hWnd = GetHwnd(); |
9a83f860 | 1040 | wxCHECK_RET( hWnd, wxT("SetScrollPos: no HWND") ); |
72fd19a1 | 1041 | |
0cf5de11 | 1042 | WinStruct<SCROLLINFO> info; |
42e69d6b VZ |
1043 | info.nPage = 0; |
1044 | info.nMin = 0; | |
1045 | info.nPos = pos; | |
1046 | info.fMask = SIF_POS; | |
a647d42a VZ |
1047 | if ( HasFlag(wxALWAYS_SHOW_SB) ) |
1048 | { | |
1049 | // disable scrollbar instead of removing it then | |
1050 | info.fMask |= SIF_DISABLENOSCROLL; | |
1051 | } | |
2d0a075d | 1052 | |
1ddb6d28 | 1053 | ::SetScrollInfo(hWnd, WXOrientToSB(orient), &info, refresh); |
2bda0e17 KB |
1054 | } |
1055 | ||
42e69d6b | 1056 | // New function that will replace some of the above. |
0cf5de11 VZ |
1057 | void wxWindowMSW::SetScrollbar(int orient, |
1058 | int pos, | |
1059 | int pageSize, | |
1060 | int range, | |
1061 | bool refresh) | |
1062 | { | |
1ddb6d28 VZ |
1063 | // We have to set the variables here to make them valid in events |
1064 | // triggered by ::SetScrollInfo() | |
1065 | *(orient == wxHORIZONTAL ? &m_xThumbSize : &m_yThumbSize) = pageSize; | |
1066 | ||
1067 | HWND hwnd = GetHwnd(); | |
1068 | if ( !hwnd ) | |
1069 | return; | |
1070 | ||
0cf5de11 | 1071 | WinStruct<SCROLLINFO> info; |
1ddb6d28 VZ |
1072 | if ( range != -1 ) |
1073 | { | |
1074 | info.nPage = pageSize; | |
1075 | info.nMin = 0; // range is nMax - nMin + 1 | |
1076 | info.nMax = range - 1; // as both nMax and nMax are inclusive | |
1077 | info.nPos = pos; | |
1078 | ||
1079 | // enable the scrollbar if it had been disabled before by specifying | |
1080 | // SIF_DISABLENOSCROLL below: as we can't know whether this had been | |
1081 | // done or not just do it always | |
1082 | ::EnableScrollBar(hwnd, WXOrientToSB(orient), ESB_ENABLE_BOTH); | |
1083 | } | |
1084 | //else: leave all the fields to be 0 | |
1085 | ||
42e69d6b | 1086 | info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; |
1ddb6d28 | 1087 | if ( HasFlag(wxALWAYS_SHOW_SB) || range == -1 ) |
a647d42a VZ |
1088 | { |
1089 | // disable scrollbar instead of removing it then | |
1090 | info.fMask |= SIF_DISABLENOSCROLL; | |
1091 | } | |
2bda0e17 | 1092 | |
1ddb6d28 | 1093 | ::SetScrollInfo(hwnd, WXOrientToSB(orient), &info, refresh); |
81d66cf3 JS |
1094 | } |
1095 | ||
1e6feb95 | 1096 | void wxWindowMSW::ScrollWindow(int dx, int dy, const wxRect *prect) |
2bda0e17 | 1097 | { |
574c939e KB |
1098 | RECT rect; |
1099 | RECT *pr; | |
1e6feb95 | 1100 | if ( prect ) |
2d0a075d | 1101 | { |
f9c980f6 | 1102 | wxCopyRectToRECT(*prect, rect); |
f797e53d VZ |
1103 | pr = ▭ |
1104 | } | |
1105 | else | |
1106 | { | |
1107 | pr = NULL; | |
304b8bc1 | 1108 | |
2d0a075d | 1109 | } |
2bda0e17 | 1110 | |
7f0586ef JS |
1111 | #ifdef __WXWINCE__ |
1112 | // FIXME: is this the exact equivalent of the line below? | |
304b8bc1 | 1113 | ::ScrollWindowEx(GetHwnd(), dx, dy, pr, pr, 0, 0, SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE); |
7f0586ef | 1114 | #else |
f797e53d | 1115 | ::ScrollWindow(GetHwnd(), dx, dy, pr, pr); |
7f0586ef | 1116 | #endif |
2bda0e17 KB |
1117 | } |
1118 | ||
9cd6d737 | 1119 | static bool ScrollVertically(HWND hwnd, int kind, int count) |
b9b3393e | 1120 | { |
9cd6d737 VZ |
1121 | int posStart = GetScrollPosition(hwnd, SB_VERT); |
1122 | ||
1123 | int pos = posStart; | |
c0cdd6cc VZ |
1124 | for ( int n = 0; n < count; n++ ) |
1125 | { | |
1126 | ::SendMessage(hwnd, WM_VSCROLL, kind, 0); | |
9cd6d737 VZ |
1127 | |
1128 | int posNew = GetScrollPosition(hwnd, SB_VERT); | |
1129 | if ( posNew == pos ) | |
1130 | { | |
1131 | // don't bother to continue, we're already at top/bottom | |
1132 | break; | |
1133 | } | |
1134 | ||
1135 | pos = posNew; | |
c0cdd6cc | 1136 | } |
9cd6d737 VZ |
1137 | |
1138 | return pos != posStart; | |
b9b3393e VZ |
1139 | } |
1140 | ||
9cd6d737 | 1141 | bool wxWindowMSW::ScrollLines(int lines) |
b9b3393e VZ |
1142 | { |
1143 | bool down = lines > 0; | |
1144 | ||
9cd6d737 VZ |
1145 | return ScrollVertically(GetHwnd(), |
1146 | down ? SB_LINEDOWN : SB_LINEUP, | |
1147 | down ? lines : -lines); | |
b9b3393e VZ |
1148 | } |
1149 | ||
9cd6d737 | 1150 | bool wxWindowMSW::ScrollPages(int pages) |
b9b3393e VZ |
1151 | { |
1152 | bool down = pages > 0; | |
1153 | ||
9cd6d737 VZ |
1154 | return ScrollVertically(GetHwnd(), |
1155 | down ? SB_PAGEDOWN : SB_PAGEUP, | |
1156 | down ? pages : -pages); | |
b9b3393e VZ |
1157 | } |
1158 | ||
978af864 VZ |
1159 | // ---------------------------------------------------------------------------- |
1160 | // RTL support | |
1161 | // ---------------------------------------------------------------------------- | |
1162 | ||
1163 | void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir) | |
1164 | { | |
08a58133 WS |
1165 | #ifdef __WXWINCE__ |
1166 | wxUnusedVar(dir); | |
1167 | #else | |
d66d0500 | 1168 | wxCHECK_RET( GetHwnd(), |
9a83f860 | 1169 | wxT("layout direction must be set after window creation") ); |
978af864 | 1170 | |
d66d0500 | 1171 | LONG styleOld = wxGetWindowExStyle(this); |
978af864 VZ |
1172 | |
1173 | LONG styleNew = styleOld; | |
1174 | switch ( dir ) | |
1175 | { | |
1176 | case wxLayout_LeftToRight: | |
1177 | styleNew &= ~WS_EX_LAYOUTRTL; | |
1178 | break; | |
1179 | ||
1180 | case wxLayout_RightToLeft: | |
1181 | styleNew |= WS_EX_LAYOUTRTL; | |
1182 | break; | |
1183 | ||
1184 | default: | |
9a83f860 | 1185 | wxFAIL_MSG(wxT("unsupported layout direction")); |
978af864 VZ |
1186 | break; |
1187 | } | |
1188 | ||
1189 | if ( styleNew != styleOld ) | |
1190 | { | |
d66d0500 | 1191 | wxSetWindowExStyle(this, styleNew); |
978af864 | 1192 | } |
08a58133 | 1193 | #endif |
978af864 VZ |
1194 | } |
1195 | ||
1196 | wxLayoutDirection wxWindowMSW::GetLayoutDirection() const | |
1197 | { | |
08a58133 WS |
1198 | #ifdef __WXWINCE__ |
1199 | return wxLayout_Default; | |
1200 | #else | |
9a83f860 | 1201 | wxCHECK_MSG( GetHwnd(), wxLayout_Default, wxT("invalid window") ); |
978af864 | 1202 | |
d66d0500 VZ |
1203 | return wxHasWindowExStyle(this, WS_EX_LAYOUTRTL) ? wxLayout_RightToLeft |
1204 | : wxLayout_LeftToRight; | |
08a58133 | 1205 | #endif |
978af864 VZ |
1206 | } |
1207 | ||
1208 | wxCoord | |
1209 | wxWindowMSW::AdjustForLayoutDirection(wxCoord x, | |
1210 | wxCoord WXUNUSED(width), | |
1211 | wxCoord WXUNUSED(widthTotal)) const | |
1212 | { | |
1213 | // Win32 mirrors the coordinates of RTL windows automatically, so don't | |
1214 | // redo it ourselves | |
1215 | return x; | |
1216 | } | |
1217 | ||
42e69d6b VZ |
1218 | // --------------------------------------------------------------------------- |
1219 | // subclassing | |
1220 | // --------------------------------------------------------------------------- | |
1221 | ||
1e6feb95 | 1222 | void wxWindowMSW::SubclassWin(WXHWND hWnd) |
2bda0e17 | 1223 | { |
223d09f6 | 1224 | wxASSERT_MSG( !m_oldWndProc, wxT("subclassing window twice?") ); |
2bda0e17 | 1225 | |
c50f1fb9 | 1226 | HWND hwnd = (HWND)hWnd; |
223d09f6 | 1227 | wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in SubclassWin") ); |
c50f1fb9 | 1228 | |
e322e3b6 VZ |
1229 | SetHWND(hWnd); |
1230 | ||
c50f1fb9 | 1231 | wxAssociateWinWithHandle(hwnd, this); |
2bda0e17 | 1232 | |
975b6bcf | 1233 | m_oldWndProc = (WXFARPROC)wxGetWindowProc((HWND)hWnd); |
b2d5a7ee | 1234 | |
b225f659 VZ |
1235 | // we don't need to subclass the window of our own class (in the Windows |
1236 | // sense of the word) | |
3a3c8603 | 1237 | if ( !wxCheckWindowWndProc(hWnd, (WXFARPROC)wxWndProc) ) |
b225f659 | 1238 | { |
975b6bcf | 1239 | wxSetWindowProc(hwnd, wxWndProc); |
b225f659 VZ |
1240 | } |
1241 | else | |
1242 | { | |
90e572f1 | 1243 | // don't bother restoring it either: this also makes it easy to |
08158721 | 1244 | // implement IsOfStandardClass() method which returns true for the |
77ffb593 | 1245 | // standard controls and false for the wxWidgets own windows as it can |
5a403e3f | 1246 | // simply check m_oldWndProc |
b225f659 VZ |
1247 | m_oldWndProc = NULL; |
1248 | } | |
e7c652bc VZ |
1249 | |
1250 | // we're officially created now, send the event | |
1251 | wxWindowCreateEvent event((wxWindow *)this); | |
937013e0 | 1252 | (void)HandleWindowEvent(event); |
2bda0e17 KB |
1253 | } |
1254 | ||
1e6feb95 | 1255 | void wxWindowMSW::UnsubclassWin() |
2bda0e17 | 1256 | { |
42e69d6b | 1257 | wxRemoveHandleAssociation(this); |
2bda0e17 | 1258 | |
42e69d6b | 1259 | // Restore old Window proc |
c50f1fb9 VZ |
1260 | HWND hwnd = GetHwnd(); |
1261 | if ( hwnd ) | |
42e69d6b | 1262 | { |
ed4780ea | 1263 | SetHWND(0); |
c50f1fb9 | 1264 | |
223d09f6 | 1265 | wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in UnsubclassWin") ); |
c50f1fb9 | 1266 | |
b225f659 | 1267 | if ( m_oldWndProc ) |
42e69d6b | 1268 | { |
eb5e4d9a | 1269 | if ( !wxCheckWindowWndProc((WXHWND)hwnd, m_oldWndProc) ) |
b225f659 | 1270 | { |
975b6bcf | 1271 | wxSetWindowProc(hwnd, (WNDPROC)m_oldWndProc); |
b225f659 VZ |
1272 | } |
1273 | ||
1274 | m_oldWndProc = NULL; | |
42e69d6b | 1275 | } |
42e69d6b | 1276 | } |
2bda0e17 KB |
1277 | } |
1278 | ||
a4d1972d | 1279 | void wxWindowMSW::AssociateHandle(WXWidget handle) |
ed4780ea VZ |
1280 | { |
1281 | if ( m_hWnd ) | |
1282 | { | |
1283 | if ( !::DestroyWindow(GetHwnd()) ) | |
43b2d5e7 | 1284 | { |
ed4780ea | 1285 | wxLogLastError(wxT("DestroyWindow")); |
43b2d5e7 | 1286 | } |
ed4780ea | 1287 | } |
a4d1972d | 1288 | |
ed4780ea VZ |
1289 | WXHWND wxhwnd = (WXHWND)handle; |
1290 | ||
e322e3b6 | 1291 | // this also calls SetHWND(wxhwnd) |
ed4780ea VZ |
1292 | SubclassWin(wxhwnd); |
1293 | } | |
1294 | ||
1295 | void wxWindowMSW::DissociateHandle() | |
a4d1972d | 1296 | { |
ed4780ea | 1297 | // this also calls SetHWND(0) for us |
a4d1972d | 1298 | UnsubclassWin(); |
ed4780ea VZ |
1299 | } |
1300 | ||
1301 | ||
0c0d1521 | 1302 | bool wxCheckWindowWndProc(WXHWND hWnd, |
11f104e5 | 1303 | WXFARPROC WXUNUSED(wndProc)) |
eb5e4d9a | 1304 | { |
d9698bd4 VZ |
1305 | const wxString str(wxGetWindowClass(hWnd)); |
1306 | ||
1307 | // TODO: get rid of wxTLWHiddenParent special case (currently it's not | |
1308 | // registered by wxApp but using ad hoc code in msw/toplevel.cpp); | |
1309 | // there is also a hidden window class used by sockets &c | |
9a83f860 | 1310 | return wxApp::IsRegisteredClassName(str) || str == wxT("wxTLWHiddenParent"); |
eb5e4d9a VS |
1311 | } |
1312 | ||
b2d5a7ee VZ |
1313 | // ---------------------------------------------------------------------------- |
1314 | // Style handling | |
1315 | // ---------------------------------------------------------------------------- | |
1316 | ||
1317 | void wxWindowMSW::SetWindowStyleFlag(long flags) | |
1318 | { | |
1319 | long flagsOld = GetWindowStyleFlag(); | |
1320 | if ( flags == flagsOld ) | |
1321 | return; | |
1322 | ||
1323 | // update the internal variable | |
1324 | wxWindowBase::SetWindowStyleFlag(flags); | |
1325 | ||
7bd6bf45 VZ |
1326 | // and the real window flags |
1327 | MSWUpdateStyle(flagsOld, GetExtraStyle()); | |
1328 | } | |
1329 | ||
1330 | void wxWindowMSW::SetExtraStyle(long exflags) | |
1331 | { | |
1332 | long exflagsOld = GetExtraStyle(); | |
1333 | if ( exflags == exflagsOld ) | |
1334 | return; | |
1335 | ||
1336 | // update the internal variable | |
1337 | wxWindowBase::SetExtraStyle(exflags); | |
1338 | ||
1339 | // and the real window flags | |
1340 | MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld); | |
1341 | } | |
1342 | ||
1343 | void wxWindowMSW::MSWUpdateStyle(long flagsOld, long exflagsOld) | |
1344 | { | |
5b2f31eb VZ |
1345 | // now update the Windows style as well if needed - and if the window had |
1346 | // been already created | |
1347 | if ( !GetHwnd() ) | |
1348 | return; | |
1349 | ||
9ce75461 VZ |
1350 | // we may need to call SetWindowPos() when we change some styles |
1351 | bool callSWP = false; | |
1352 | ||
7bd6bf45 VZ |
1353 | WXDWORD exstyle; |
1354 | long style = MSWGetStyle(GetWindowStyleFlag(), &exstyle); | |
1355 | ||
1356 | // this is quite a horrible hack but we need it because MSWGetStyle() | |
1357 | // doesn't take exflags as parameter but uses GetExtraStyle() internally | |
1358 | // and so we have to modify the window exflags temporarily to get the | |
1359 | // correct exstyleOld | |
1360 | long exflagsNew = GetExtraStyle(); | |
1361 | wxWindowBase::SetExtraStyle(exflagsOld); | |
1362 | ||
1363 | WXDWORD exstyleOld; | |
1364 | long styleOld = MSWGetStyle(flagsOld, &exstyleOld); | |
1365 | ||
1366 | wxWindowBase::SetExtraStyle(exflagsNew); | |
1367 | ||
b2d5a7ee VZ |
1368 | |
1369 | if ( style != styleOld ) | |
1370 | { | |
1371 | // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by | |
1372 | // this function so instead of simply setting the style to the new | |
1373 | // value we clear the bits which were set in styleOld but are set in | |
1374 | // the new one and set the ones which were not set before | |
1375 | long styleReal = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
1376 | styleReal &= ~styleOld; | |
1377 | styleReal |= style; | |
1378 | ||
1379 | ::SetWindowLong(GetHwnd(), GWL_STYLE, styleReal); | |
9ce75461 | 1380 | |
7bd6bf45 VZ |
1381 | // we need to call SetWindowPos() if any of the styles affecting the |
1382 | // frame appearance have changed | |
9ce75461 VZ |
1383 | callSWP = ((styleOld ^ style ) & (WS_BORDER | |
1384 | WS_THICKFRAME | | |
1385 | WS_CAPTION | | |
1386 | WS_DLGFRAME | | |
1387 | WS_MAXIMIZEBOX | | |
1388 | WS_MINIMIZEBOX | | |
1389 | WS_SYSMENU) ) != 0; | |
b2d5a7ee VZ |
1390 | } |
1391 | ||
1392 | // and the extended style | |
d66d0500 | 1393 | long exstyleReal = wxGetWindowExStyle(this); |
9ce75461 | 1394 | |
b2d5a7ee VZ |
1395 | if ( exstyle != exstyleOld ) |
1396 | { | |
b2d5a7ee VZ |
1397 | exstyleReal &= ~exstyleOld; |
1398 | exstyleReal |= exstyle; | |
1399 | ||
d66d0500 | 1400 | wxSetWindowExStyle(this, exstyleReal); |
b2d5a7ee | 1401 | |
9ce75461 VZ |
1402 | // ex style changes don't take effect without calling SetWindowPos |
1403 | callSWP = true; | |
1404 | } | |
1405 | ||
1406 | if ( callSWP ) | |
1407 | { | |
85d8df29 | 1408 | // we must call SetWindowPos() to flush the cached extended style and |
b2d5a7ee VZ |
1409 | // also to make the change to wxSTAY_ON_TOP style take effect: just |
1410 | // setting the style simply doesn't work | |
1411 | if ( !::SetWindowPos(GetHwnd(), | |
1412 | exstyleReal & WS_EX_TOPMOST ? HWND_TOPMOST | |
1413 | : HWND_NOTOPMOST, | |
1414 | 0, 0, 0, 0, | |
9ce75461 | 1415 | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED) ) |
b2d5a7ee | 1416 | { |
9a83f860 | 1417 | wxLogLastError(wxT("SetWindowPos")); |
b2d5a7ee VZ |
1418 | } |
1419 | } | |
1420 | } | |
1421 | ||
a047aff2 JS |
1422 | wxBorder wxWindowMSW::GetDefaultBorderForControl() const |
1423 | { | |
28319afe | 1424 | return wxBORDER_THEME; |
a047aff2 JS |
1425 | } |
1426 | ||
4c0d2cd3 JS |
1427 | wxBorder wxWindowMSW::GetDefaultBorder() const |
1428 | { | |
dc797d8e | 1429 | return wxWindowBase::GetDefaultBorder(); |
4c0d2cd3 JS |
1430 | } |
1431 | ||
28bf925c | 1432 | // Translate wxBORDER_THEME (and other border styles if necessary) to the value |
dc797d8e JS |
1433 | // that makes most sense for this Windows environment |
1434 | wxBorder wxWindowMSW::TranslateBorder(wxBorder border) const | |
1435 | { | |
1436 | #if defined(__POCKETPC__) || defined(__SMARTPHONE__) | |
1437 | if (border == wxBORDER_THEME || border == wxBORDER_SUNKEN || border == wxBORDER_SIMPLE) | |
1438 | return wxBORDER_SIMPLE; | |
1439 | else | |
1440 | return wxBORDER_NONE; | |
1441 | #else | |
1442 | #if wxUSE_UXTHEME | |
1443 | if (border == wxBORDER_THEME) | |
1444 | { | |
1445 | if (CanApplyThemeBorder()) | |
1446 | { | |
1447 | wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); | |
1448 | if (theme) | |
1449 | return wxBORDER_THEME; | |
1450 | } | |
28bf925c | 1451 | return wxBORDER_SUNKEN; |
dc797d8e JS |
1452 | } |
1453 | #endif | |
1454 | return border; | |
1455 | #endif | |
dc797d8e JS |
1456 | } |
1457 | ||
1458 | ||
b2d5a7ee VZ |
1459 | WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const |
1460 | { | |
77ffb593 | 1461 | // translate common wxWidgets styles to Windows ones |
af495479 VZ |
1462 | |
1463 | // most of windows are child ones, those which are not (such as | |
1464 | // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle() | |
1465 | WXDWORD style = WS_CHILD; | |
b2d5a7ee | 1466 | |
9b6ae450 VZ |
1467 | // using this flag results in very significant reduction in flicker, |
1468 | // especially with controls inside the static boxes (as the interior of the | |
90e572f1 | 1469 | // box is not redrawn twice), but sometimes results in redraw problems, so |
c7e1d004 VZ |
1470 | // optionally allow the old code to continue to use it provided a special |
1471 | // system option is turned on | |
1472 | if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children")) | |
1473 | || (flags & wxCLIP_CHILDREN) ) | |
c6430ed0 | 1474 | style |= WS_CLIPCHILDREN; |
9b6ae450 VZ |
1475 | |
1476 | // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially | |
1477 | // don't support overlapping windows and it only makes sense for them and, | |
1478 | // presumably, gives the system some extra work (to manage more clipping | |
1479 | // regions), so avoid it alltogether | |
b2d5a7ee | 1480 | |
b2d5a7ee | 1481 | |
f9007c32 JS |
1482 | if ( flags & wxVSCROLL ) |
1483 | style |= WS_VSCROLL; | |
1484 | ||
1485 | if ( flags & wxHSCROLL ) | |
1486 | style |= WS_HSCROLL; | |
1487 | ||
dc797d8e JS |
1488 | const wxBorder border = TranslateBorder(GetBorder(flags)); |
1489 | ||
1490 | // After translation, border is now optimized for the specific version of Windows | |
1491 | // and theme engine presence. | |
577baeef | 1492 | |
65bc172c VZ |
1493 | // WS_BORDER is only required for wxBORDER_SIMPLE |
1494 | if ( border == wxBORDER_SIMPLE ) | |
b2d5a7ee | 1495 | style |= WS_BORDER; |
577baeef | 1496 | |
b2d5a7ee VZ |
1497 | // now deal with ext style if the caller wants it |
1498 | if ( exstyle ) | |
1499 | { | |
1500 | *exstyle = 0; | |
1501 | ||
7f0586ef | 1502 | #ifndef __WXWINCE__ |
b2d5a7ee VZ |
1503 | if ( flags & wxTRANSPARENT_WINDOW ) |
1504 | *exstyle |= WS_EX_TRANSPARENT; | |
7f0586ef | 1505 | #endif |
b2d5a7ee | 1506 | |
fe3d9123 | 1507 | switch ( border ) |
b2d5a7ee | 1508 | { |
78cd9c69 JS |
1509 | default: |
1510 | case wxBORDER_DEFAULT: | |
9a83f860 | 1511 | wxFAIL_MSG( wxT("unknown border style") ); |
78cd9c69 | 1512 | // fall through |
b2d5a7ee VZ |
1513 | |
1514 | case wxBORDER_NONE: | |
1515 | case wxBORDER_SIMPLE: | |
78cd9c69 | 1516 | case wxBORDER_THEME: |
b2d5a7ee VZ |
1517 | break; |
1518 | ||
1519 | case wxBORDER_STATIC: | |
1520 | *exstyle |= WS_EX_STATICEDGE; | |
1521 | break; | |
1522 | ||
1523 | case wxBORDER_RAISED: | |
7699361c | 1524 | *exstyle |= WS_EX_DLGMODALFRAME; |
b2d5a7ee VZ |
1525 | break; |
1526 | ||
b2d5a7ee VZ |
1527 | case wxBORDER_SUNKEN: |
1528 | *exstyle |= WS_EX_CLIENTEDGE; | |
fe3d9123 | 1529 | style &= ~WS_BORDER; |
b2d5a7ee VZ |
1530 | break; |
1531 | ||
78cd9c69 JS |
1532 | // case wxBORDER_DOUBLE: |
1533 | // *exstyle |= WS_EX_DLGMODALFRAME; | |
1534 | // break; | |
b2d5a7ee | 1535 | } |
d515c32d | 1536 | |
09168de7 | 1537 | // wxUniv doesn't use Windows dialog navigation functions at all |
7f0586ef | 1538 | #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__) |
5b9c12e1 | 1539 | // to make the dialog navigation work with the nested panels we must |
09168de7 VZ |
1540 | // use this style (top level windows such as dialogs don't need it) |
1541 | if ( (flags & wxTAB_TRAVERSAL) && !IsTopLevel() ) | |
d515c32d VZ |
1542 | { |
1543 | *exstyle |= WS_EX_CONTROLPARENT; | |
1544 | } | |
09168de7 | 1545 | #endif // __WXUNIVERSAL__ |
b2d5a7ee VZ |
1546 | } |
1547 | ||
1548 | return style; | |
1549 | } | |
eb5e4d9a | 1550 | |
42e69d6b | 1551 | // Setup background and foreground colours correctly |
1e6feb95 | 1552 | void wxWindowMSW::SetupColours() |
42e69d6b VZ |
1553 | { |
1554 | if ( GetParent() ) | |
1555 | SetBackgroundColour(GetParent()->GetBackgroundColour()); | |
1556 | } | |
a23fd0e1 | 1557 | |
1e6feb95 VZ |
1558 | bool wxWindowMSW::IsMouseInWindow() const |
1559 | { | |
1560 | // get the mouse position | |
1561 | POINT pt; | |
f2325516 JS |
1562 | #ifdef __WXWINCE__ |
1563 | ::GetCursorPosWinCE(&pt); | |
1564 | #else | |
1e6feb95 | 1565 | ::GetCursorPos(&pt); |
f2325516 | 1566 | #endif |
1e6feb95 VZ |
1567 | |
1568 | // find the window which currently has the cursor and go up the window | |
1569 | // chain until we find this window - or exhaust it | |
1570 | HWND hwnd = ::WindowFromPoint(pt); | |
1571 | while ( hwnd && (hwnd != GetHwnd()) ) | |
1572 | hwnd = ::GetParent(hwnd); | |
1573 | ||
1574 | return hwnd != NULL; | |
1575 | } | |
1576 | ||
e39af974 | 1577 | void wxWindowMSW::OnInternalIdle() |
42e69d6b | 1578 | { |
4e5c6c33 | 1579 | #ifndef HAVE_TRACKMOUSEEVENT |
42e69d6b VZ |
1580 | // Check if we need to send a LEAVE event |
1581 | if ( m_mouseInWindow ) | |
2d0a075d | 1582 | { |
ee74faf9 VZ |
1583 | // note that we should generate the leave event whether the window has |
1584 | // or doesn't have mouse capture | |
1585 | if ( !IsMouseInWindow() ) | |
42e69d6b | 1586 | { |
51e4e266 | 1587 | GenerateMouseLeave(); |
42e69d6b VZ |
1588 | } |
1589 | } | |
4e5c6c33 | 1590 | #endif // !HAVE_TRACKMOUSEEVENT |
c085e333 | 1591 | |
df707c27 | 1592 | if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen()) |
e39af974 | 1593 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); |
42e69d6b | 1594 | } |
568cb543 | 1595 | |
42e69d6b | 1596 | // Set this window to be the child of 'parent'. |
1e6feb95 | 1597 | bool wxWindowMSW::Reparent(wxWindowBase *parent) |
42e69d6b VZ |
1598 | { |
1599 | if ( !wxWindowBase::Reparent(parent) ) | |
08158721 | 1600 | return false; |
c085e333 | 1601 | |
42e69d6b VZ |
1602 | HWND hWndChild = GetHwnd(); |
1603 | HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0; | |
a23fd0e1 | 1604 | |
42e69d6b | 1605 | ::SetParent(hWndChild, hWndParent); |
a23fd0e1 | 1606 | |
ee471817 | 1607 | #ifndef __WXWINCE__ |
d66d0500 | 1608 | if ( wxHasWindowExStyle(this, WS_EX_CONTROLPARENT) ) |
ee471817 VZ |
1609 | { |
1610 | EnsureParentHasControlParentStyle(GetParent()); | |
1611 | } | |
1612 | #endif // !__WXWINCE__ | |
1613 | ||
08158721 | 1614 | return true; |
42e69d6b | 1615 | } |
a23fd0e1 | 1616 | |
a0e449ff VZ |
1617 | static inline void SendSetRedraw(HWND hwnd, bool on) |
1618 | { | |
c67d6888 | 1619 | #ifndef __WXMICROWIN__ |
a0e449ff | 1620 | ::SendMessage(hwnd, WM_SETREDRAW, (WPARAM)on, 0); |
c67d6888 | 1621 | #endif |
a0e449ff VZ |
1622 | } |
1623 | ||
17808a75 | 1624 | void wxWindowMSW::DoFreeze() |
a0e449ff | 1625 | { |
89267fe5 VS |
1626 | if ( !IsShown() ) |
1627 | return; // no point in freezing hidden window | |
1628 | ||
1629 | SendSetRedraw(GetHwnd(), false); | |
a0e449ff VZ |
1630 | } |
1631 | ||
17808a75 | 1632 | void wxWindowMSW::DoThaw() |
a0e449ff | 1633 | { |
89267fe5 VS |
1634 | if ( !IsShown() ) |
1635 | return; // hidden windows aren't frozen by DoFreeze | |
a1037371 | 1636 | |
89267fe5 VS |
1637 | SendSetRedraw(GetHwnd(), true); |
1638 | ||
1639 | // we need to refresh everything or otherwise the invalidated area | |
1640 | // is not going to be repainted | |
1641 | Refresh(); | |
a0e449ff VZ |
1642 | } |
1643 | ||
1e6feb95 | 1644 | void wxWindowMSW::Refresh(bool eraseBack, const wxRect *rect) |
42e69d6b VZ |
1645 | { |
1646 | HWND hWnd = GetHwnd(); | |
1647 | if ( hWnd ) | |
1648 | { | |
d181e053 VZ |
1649 | RECT mswRect; |
1650 | const RECT *pRect; | |
42e69d6b VZ |
1651 | if ( rect ) |
1652 | { | |
f9c980f6 | 1653 | wxCopyRectToRECT(*rect, mswRect); |
d181e053 | 1654 | pRect = &mswRect; |
42e69d6b VZ |
1655 | } |
1656 | else | |
d181e053 VZ |
1657 | { |
1658 | pRect = NULL; | |
1659 | } | |
1660 | ||
82e3664e | 1661 | // RedrawWindow not available on SmartPhone or eVC++ 3 |
41527143 | 1662 | #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400) |
d181e053 VZ |
1663 | UINT flags = RDW_INVALIDATE | RDW_ALLCHILDREN; |
1664 | if ( eraseBack ) | |
1665 | flags |= RDW_ERASE; | |
1666 | ||
1667 | ::RedrawWindow(hWnd, pRect, NULL, flags); | |
480e9098 | 1668 | #else |
16d652a5 | 1669 | ::InvalidateRect(hWnd, pRect, eraseBack); |
480e9098 | 1670 | #endif |
42e69d6b VZ |
1671 | } |
1672 | } | |
a23fd0e1 | 1673 | |
1e6feb95 VZ |
1674 | void wxWindowMSW::Update() |
1675 | { | |
1676 | if ( !::UpdateWindow(GetHwnd()) ) | |
1677 | { | |
9a83f860 | 1678 | wxLogLastError(wxT("UpdateWindow")); |
1e6feb95 | 1679 | } |
2b5f62a0 | 1680 | |
7f0586ef | 1681 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
1e6feb95 VZ |
1682 | // just calling UpdateWindow() is not enough, what we did in our WM_PAINT |
1683 | // handler needs to be really drawn right now | |
1684 | (void)::GdiFlush(); | |
1685 | #endif // __WIN32__ | |
1686 | } | |
1687 | ||
42e69d6b VZ |
1688 | // --------------------------------------------------------------------------- |
1689 | // drag and drop | |
1690 | // --------------------------------------------------------------------------- | |
a23fd0e1 | 1691 | |
3febc967 VZ |
1692 | #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__) |
1693 | ||
1694 | #if wxUSE_STATBOX | |
1695 | ||
006b8dff JG |
1696 | // we need to lower the sibling static boxes so controls contained within can be |
1697 | // a drop target | |
3febc967 | 1698 | static void AdjustStaticBoxZOrder(wxWindow *parent) |
006b8dff | 1699 | { |
deb0d191 JG |
1700 | // no sibling static boxes if we have no parent (ie TLW) |
1701 | if ( !parent ) | |
1702 | return; | |
1703 | ||
006b8dff JG |
1704 | for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst(); |
1705 | node; | |
1706 | node = node->GetNext() ) | |
1707 | { | |
1708 | wxStaticBox *statbox = wxDynamicCast(node->GetData(), wxStaticBox); | |
1709 | if ( statbox ) | |
1710 | { | |
1711 | ::SetWindowPos(GetHwndOf(statbox), HWND_BOTTOM, 0, 0, 0, 0, | |
1712 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | |
1713 | } | |
1714 | } | |
1715 | } | |
a23fd0e1 | 1716 | |
3febc967 VZ |
1717 | #else // !wxUSE_STATBOX |
1718 | ||
1719 | static inline void AdjustStaticBoxZOrder(wxWindow * WXUNUSED(parent)) | |
1720 | { | |
1721 | } | |
1722 | ||
1723 | #endif // wxUSE_STATBOX/!wxUSE_STATBOX | |
1724 | ||
1725 | #endif // drag and drop is used | |
1726 | ||
4ce1efe1 | 1727 | #if wxUSE_DRAG_AND_DROP |
1e6feb95 | 1728 | void wxWindowMSW::SetDropTarget(wxDropTarget *pDropTarget) |
42e69d6b VZ |
1729 | { |
1730 | if ( m_dropTarget != 0 ) { | |
1731 | m_dropTarget->Revoke(m_hWnd); | |
1732 | delete m_dropTarget; | |
1733 | } | |
a23fd0e1 | 1734 | |
42e69d6b VZ |
1735 | m_dropTarget = pDropTarget; |
1736 | if ( m_dropTarget != 0 ) | |
006b8dff JG |
1737 | { |
1738 | AdjustStaticBoxZOrder(GetParent()); | |
42e69d6b | 1739 | m_dropTarget->Register(m_hWnd); |
006b8dff | 1740 | } |
42e69d6b | 1741 | } |
42e69d6b | 1742 | #endif // wxUSE_DRAG_AND_DROP |
2a47d3c1 | 1743 | |
90e572f1 | 1744 | // old-style file manager drag&drop support: we retain the old-style |
42e69d6b | 1745 | // DragAcceptFiles in parallel with SetDropTarget. |
0c0d1521 | 1746 | void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept)) |
42e69d6b | 1747 | { |
0c0d1521 | 1748 | #ifndef __WXWINCE__ |
42e69d6b VZ |
1749 | HWND hWnd = GetHwnd(); |
1750 | if ( hWnd ) | |
006b8dff JG |
1751 | { |
1752 | AdjustStaticBoxZOrder(GetParent()); | |
42e69d6b | 1753 | ::DragAcceptFiles(hWnd, (BOOL)accept); |
006b8dff | 1754 | } |
7f0586ef | 1755 | #endif |
42e69d6b | 1756 | } |
a23fd0e1 | 1757 | |
42e69d6b VZ |
1758 | // ---------------------------------------------------------------------------- |
1759 | // tooltips | |
1760 | // ---------------------------------------------------------------------------- | |
dbda9e86 | 1761 | |
42e69d6b | 1762 | #if wxUSE_TOOLTIPS |
2d0a075d | 1763 | |
1e6feb95 | 1764 | void wxWindowMSW::DoSetToolTip(wxToolTip *tooltip) |
42e69d6b VZ |
1765 | { |
1766 | wxWindowBase::DoSetToolTip(tooltip); | |
839b865d | 1767 | |
42e69d6b | 1768 | if ( m_tooltip ) |
d4e5272b | 1769 | m_tooltip->SetWindow((wxWindow *)this); |
42e69d6b | 1770 | } |
9a05fd8d | 1771 | |
42e69d6b | 1772 | #endif // wxUSE_TOOLTIPS |
9a05fd8d | 1773 | |
42e69d6b VZ |
1774 | // --------------------------------------------------------------------------- |
1775 | // moving and resizing | |
1776 | // --------------------------------------------------------------------------- | |
839b865d | 1777 | |
f7040b5f VZ |
1778 | bool wxWindowMSW::IsSizeDeferred() const |
1779 | { | |
6bd9b9f2 | 1780 | #if wxUSE_DEFERRED_SIZING |
f7040b5f VZ |
1781 | if ( m_pendingPosition != wxDefaultPosition || |
1782 | m_pendingSize != wxDefaultSize ) | |
1783 | return true; | |
6bd9b9f2 | 1784 | #endif // wxUSE_DEFERRED_SIZING |
f7040b5f VZ |
1785 | |
1786 | return false; | |
1787 | } | |
1788 | ||
42e69d6b | 1789 | // Get total size |
1e6feb95 | 1790 | void wxWindowMSW::DoGetSize(int *x, int *y) const |
42e69d6b | 1791 | { |
6bd9b9f2 | 1792 | #if wxUSE_DEFERRED_SIZING |
11cfa8ef VZ |
1793 | // if SetSize() had been called at wx level but not realized at Windows |
1794 | // level yet (i.e. EndDeferWindowPos() not called), we still should return | |
1795 | // the new and not the old position to the other wx code | |
1796 | if ( m_pendingSize != wxDefaultSize ) | |
1797 | { | |
1798 | if ( x ) | |
1799 | *x = m_pendingSize.x; | |
1800 | if ( y ) | |
1801 | *y = m_pendingSize.y; | |
1802 | } | |
1803 | else // use current size | |
6bd9b9f2 | 1804 | #endif // wxUSE_DEFERRED_SIZING |
11cfa8ef VZ |
1805 | { |
1806 | RECT rect = wxGetWindowRect(GetHwnd()); | |
82c9f85c | 1807 | |
11cfa8ef VZ |
1808 | if ( x ) |
1809 | *x = rect.right - rect.left; | |
1810 | if ( y ) | |
1811 | *y = rect.bottom - rect.top; | |
1812 | } | |
42e69d6b VZ |
1813 | } |
1814 | ||
82c9f85c VZ |
1815 | // Get size *available for subwindows* i.e. excluding menu bar etc. |
1816 | void wxWindowMSW::DoGetClientSize(int *x, int *y) const | |
42e69d6b | 1817 | { |
6bd9b9f2 | 1818 | #if wxUSE_DEFERRED_SIZING |
0d6fdb3c | 1819 | if ( m_pendingSize != wxDefaultSize ) |
0d7f75df | 1820 | { |
0d6fdb3c | 1821 | // we need to calculate the client size corresponding to pending size |
dc497201 JG |
1822 | RECT rect; |
1823 | rect.left = m_pendingPosition.x; | |
1824 | rect.top = m_pendingPosition.y; | |
1825 | rect.right = rect.left + m_pendingSize.x; | |
1826 | rect.bottom = rect.top + m_pendingSize.y; | |
1827 | ||
1828 | ::SendMessage(GetHwnd(), WM_NCCALCSIZE, FALSE, (LPARAM)&rect); | |
1829 | ||
1830 | if ( x ) | |
1831 | *x = rect.right - rect.left; | |
1832 | if ( y ) | |
1833 | *y = rect.bottom - rect.top; | |
0d7f75df | 1834 | } |
0d6fdb3c | 1835 | else |
6bd9b9f2 | 1836 | #endif // wxUSE_DEFERRED_SIZING |
0d6fdb3c VZ |
1837 | { |
1838 | RECT rect = wxGetClientRect(GetHwnd()); | |
1839 | ||
1840 | if ( x ) | |
1841 | *x = rect.right; | |
1842 | if ( y ) | |
1843 | *y = rect.bottom; | |
1844 | } | |
82c9f85c VZ |
1845 | } |
1846 | ||
1847 | void wxWindowMSW::DoGetPosition(int *x, int *y) const | |
1848 | { | |
a7e0e432 VZ |
1849 | wxWindow * const parent = GetParent(); |
1850 | ||
1851 | wxPoint pos; | |
11cfa8ef VZ |
1852 | if ( m_pendingPosition != wxDefaultPosition ) |
1853 | { | |
a7e0e432 | 1854 | pos = m_pendingPosition; |
11cfa8ef VZ |
1855 | } |
1856 | else // use current position | |
1857 | { | |
1858 | RECT rect = wxGetWindowRect(GetHwnd()); | |
42e69d6b | 1859 | |
11cfa8ef VZ |
1860 | POINT point; |
1861 | point.x = rect.left; | |
1862 | point.y = rect.top; | |
42e69d6b | 1863 | |
11cfa8ef VZ |
1864 | // we do the adjustments with respect to the parent only for the "real" |
1865 | // children, not for the dialogs/frames | |
1866 | if ( !IsTopLevel() ) | |
92049cd4 | 1867 | { |
e5b5af91 VZ |
1868 | if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) |
1869 | { | |
967acfb5 | 1870 | // In RTL mode, we want the logical left x-coordinate, |
e5b5af91 VZ |
1871 | // which would be the physical right x-coordinate. |
1872 | point.x = rect.right; | |
1873 | } | |
1874 | ||
11cfa8ef VZ |
1875 | // Since we now have the absolute screen coords, if there's a |
1876 | // parent we must subtract its top left corner | |
11cfa8ef VZ |
1877 | if ( parent ) |
1878 | { | |
a7e0e432 | 1879 | ::ScreenToClient(GetHwndOf(parent), &point); |
11cfa8ef | 1880 | } |
89e3037c | 1881 | } |
42e69d6b | 1882 | |
a7e0e432 VZ |
1883 | pos.x = point.x; |
1884 | pos.y = point.y; | |
1885 | } | |
1886 | ||
1887 | // we also must adjust by the client area offset: a control which is just | |
1888 | // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx | |
1889 | if ( parent && !IsTopLevel() ) | |
1890 | { | |
1891 | const wxPoint pt(parent->GetClientAreaOrigin()); | |
1892 | pos.x -= pt.x; | |
1893 | pos.y -= pt.y; | |
11cfa8ef | 1894 | } |
a7e0e432 VZ |
1895 | |
1896 | if ( x ) | |
1897 | *x = pos.x; | |
1898 | if ( y ) | |
1899 | *y = pos.y; | |
42e69d6b | 1900 | } |
54bdd8b0 | 1901 | |
1e6feb95 | 1902 | void wxWindowMSW::DoScreenToClient(int *x, int *y) const |
42e69d6b VZ |
1903 | { |
1904 | POINT pt; | |
1905 | if ( x ) | |
1906 | pt.x = *x; | |
1907 | if ( y ) | |
1908 | pt.y = *y; | |
54bdd8b0 | 1909 | |
82c9f85c | 1910 | ::ScreenToClient(GetHwnd(), &pt); |
a23fd0e1 | 1911 | |
42e69d6b VZ |
1912 | if ( x ) |
1913 | *x = pt.x; | |
1914 | if ( y ) | |
1915 | *y = pt.y; | |
1916 | } | |
a23fd0e1 | 1917 | |
1e6feb95 | 1918 | void wxWindowMSW::DoClientToScreen(int *x, int *y) const |
42e69d6b VZ |
1919 | { |
1920 | POINT pt; | |
1921 | if ( x ) | |
1922 | pt.x = *x; | |
1923 | if ( y ) | |
1924 | pt.y = *y; | |
54bdd8b0 | 1925 | |
82c9f85c | 1926 | ::ClientToScreen(GetHwnd(), &pt); |
a23fd0e1 | 1927 | |
42e69d6b VZ |
1928 | if ( x ) |
1929 | *x = pt.x; | |
1930 | if ( y ) | |
1931 | *y = pt.y; | |
1932 | } | |
a23fd0e1 | 1933 | |
86e30911 | 1934 | bool |
7d86a2d4 VZ |
1935 | wxWindowMSW::DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height) |
1936 | { | |
6bd9b9f2 | 1937 | #if wxUSE_DEFERRED_SIZING |
7d86a2d4 VZ |
1938 | // if our parent had prepared a defer window handle for us, use it (unless |
1939 | // we are a top level window) | |
1940 | wxWindowMSW * const parent = IsTopLevel() ? NULL : GetParent(); | |
1941 | ||
1942 | HDWP hdwp = parent ? (HDWP)parent->m_hDWP : NULL; | |
1943 | if ( hdwp ) | |
1944 | { | |
1945 | hdwp = ::DeferWindowPos(hdwp, (HWND)hwnd, NULL, x, y, width, height, | |
dd28827a | 1946 | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); |
7d86a2d4 VZ |
1947 | if ( !hdwp ) |
1948 | { | |
9a83f860 | 1949 | wxLogLastError(wxT("DeferWindowPos")); |
7d86a2d4 VZ |
1950 | } |
1951 | } | |
1952 | ||
1953 | if ( parent ) | |
1954 | { | |
1955 | // hdwp must be updated as it may have been changed | |
1956 | parent->m_hDWP = (WXHANDLE)hdwp; | |
1957 | } | |
1958 | ||
86e30911 VZ |
1959 | if ( hdwp ) |
1960 | { | |
1961 | // did deferred move, remember new coordinates of the window as they're | |
1962 | // different from what Windows would return for it | |
1963 | return true; | |
1964 | } | |
1965 | ||
7d86a2d4 | 1966 | // otherwise (or if deferring failed) move the window in place immediately |
6bd9b9f2 | 1967 | #endif // wxUSE_DEFERRED_SIZING |
86e30911 | 1968 | if ( !::MoveWindow((HWND)hwnd, x, y, width, height, IsShown()) ) |
7d86a2d4 | 1969 | { |
86e30911 | 1970 | wxLogLastError(wxT("MoveWindow")); |
7d86a2d4 | 1971 | } |
86e30911 | 1972 | |
6bd9b9f2 | 1973 | // if wxUSE_DEFERRED_SIZING, indicates that we didn't use deferred move, |
86e30911 VZ |
1974 | // ignored otherwise |
1975 | return false; | |
7d86a2d4 VZ |
1976 | } |
1977 | ||
1e6feb95 | 1978 | void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height) |
b782f2e0 | 1979 | { |
62e1ba75 JS |
1980 | // TODO: is this consistent with other platforms? |
1981 | // Still, negative width or height shouldn't be allowed | |
1982 | if (width < 0) | |
1983 | width = 0; | |
1984 | if (height < 0) | |
1985 | height = 0; | |
9b6ae450 | 1986 | |
86e30911 VZ |
1987 | if ( DoMoveSibling(m_hWnd, x, y, width, height) ) |
1988 | { | |
6bd9b9f2 | 1989 | #if wxUSE_DEFERRED_SIZING |
86e30911 VZ |
1990 | m_pendingPosition = wxPoint(x, y); |
1991 | m_pendingSize = wxSize(width, height); | |
f8cba58b VZ |
1992 | } |
1993 | else // window was moved immediately, without deferring it | |
1994 | { | |
1995 | m_pendingPosition = wxDefaultPosition; | |
1996 | m_pendingSize = wxDefaultSize; | |
6bd9b9f2 | 1997 | #endif // wxUSE_DEFERRED_SIZING |
86e30911 | 1998 | } |
b782f2e0 VZ |
1999 | } |
2000 | ||
4438caf4 VZ |
2001 | // set the size of the window: if the dimensions are positive, just use them, |
2002 | // but if any of them is equal to -1, it means that we must find the value for | |
2003 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
2004 | // which case -1 is a valid value for x and y) | |
2005 | // | |
2006 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
2007 | // the width/height to best suit our contents, otherwise we reuse the current | |
2008 | // width/height | |
1e6feb95 | 2009 | void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
42e69d6b | 2010 | { |
4438caf4 | 2011 | // get the current size and position... |
42e69d6b | 2012 | int currentX, currentY; |
da78f3b1 RD |
2013 | int currentW, currentH; |
2014 | ||
42e69d6b | 2015 | GetPosition(¤tX, ¤tY); |
42e69d6b | 2016 | GetSize(¤tW, ¤tH); |
a23fd0e1 | 2017 | |
952f2aaa VZ |
2018 | // ... and don't do anything (avoiding flicker) if it's already ok unless |
2019 | // we're forced to resize the window | |
4438caf4 | 2020 | if ( x == currentX && y == currentY && |
952f2aaa VZ |
2021 | width == currentW && height == currentH && |
2022 | !(sizeFlags & wxSIZE_FORCE) ) | |
4438caf4 | 2023 | { |
e47e063a RR |
2024 | if (sizeFlags & wxSIZE_FORCE_EVENT) |
2025 | { | |
2026 | wxSizeEvent event( wxSize(width,height), GetId() ); | |
2027 | event.SetEventObject( this ); | |
2028 | HandleWindowEvent( event ); | |
2029 | } | |
42e69d6b | 2030 | return; |
4438caf4 | 2031 | } |
a23fd0e1 | 2032 | |
422d0ff0 | 2033 | if ( x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
4438caf4 | 2034 | x = currentX; |
422d0ff0 | 2035 | if ( y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
4438caf4 | 2036 | y = currentY; |
a23fd0e1 | 2037 | |
4438caf4 | 2038 | AdjustForParentClientOrigin(x, y, sizeFlags); |
a23fd0e1 | 2039 | |
abb74e0f | 2040 | wxSize size = wxDefaultSize; |
422d0ff0 | 2041 | if ( width == wxDefaultCoord ) |
4438caf4 | 2042 | { |
9e2896e5 | 2043 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) |
4438caf4 | 2044 | { |
4329eae9 | 2045 | size = GetBestSize(); |
4438caf4 VZ |
2046 | width = size.x; |
2047 | } | |
2048 | else | |
2049 | { | |
2050 | // just take the current one | |
2051 | width = currentW; | |
2052 | } | |
2053 | } | |
2054 | ||
422d0ff0 | 2055 | if ( height == wxDefaultCoord ) |
4438caf4 | 2056 | { |
9e2896e5 | 2057 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) |
4438caf4 | 2058 | { |
422d0ff0 | 2059 | if ( size.x == wxDefaultCoord ) |
4438caf4 | 2060 | { |
4329eae9 | 2061 | size = GetBestSize(); |
4438caf4 | 2062 | } |
4329eae9 | 2063 | //else: already called GetBestSize() above |
a23fd0e1 | 2064 | |
4438caf4 VZ |
2065 | height = size.y; |
2066 | } | |
2067 | else | |
2068 | { | |
2069 | // just take the current one | |
2070 | height = currentH; | |
2071 | } | |
2072 | } | |
2073 | ||
b782f2e0 | 2074 | DoMoveWindow(x, y, width, height); |
4438caf4 VZ |
2075 | } |
2076 | ||
1e6feb95 | 2077 | void wxWindowMSW::DoSetClientSize(int width, int height) |
42e69d6b | 2078 | { |
90e572f1 | 2079 | // setting the client size is less obvious than it could have been |
d4597e13 | 2080 | // because in the result of changing the total size the window scrollbar |
c72b1ad7 VZ |
2081 | // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect() |
2082 | // doesn't take neither into account) and so the client size will not be | |
2083 | // correct as the difference between the total and client size changes -- | |
2084 | // so we keep changing it until we get it right | |
d4597e13 | 2085 | // |
d6a97306 VZ |
2086 | // normally this loop shouldn't take more than 3 iterations (usually 1 but |
2087 | // if scrollbars [dis]appear as the result of the first call, then 2 and it | |
2088 | // may become 3 if the window had 0 size originally and so we didn't | |
2089 | // calculate the scrollbar correction correctly during the first iteration) | |
2090 | // but just to be on the safe side we check for it instead of making it an | |
d4597e13 | 2091 | // "infinite" loop (i.e. leaving break inside as the only way to get out) |
d6a97306 | 2092 | for ( int i = 0; i < 4; i++ ) |
d4597e13 VZ |
2093 | { |
2094 | RECT rectClient; | |
2095 | ::GetClientRect(GetHwnd(), &rectClient); | |
2bda0e17 | 2096 | |
b0268daf | 2097 | // if the size is already ok, stop here (NB: rectClient.left = top = 0) |
422d0ff0 WS |
2098 | if ( (rectClient.right == width || width == wxDefaultCoord) && |
2099 | (rectClient.bottom == height || height == wxDefaultCoord) ) | |
d4597e13 VZ |
2100 | { |
2101 | break; | |
2102 | } | |
a23fd0e1 | 2103 | |
d4597e13 VZ |
2104 | // Find the difference between the entire window (title bar and all) |
2105 | // and the client area; add this to the new client size to move the | |
2106 | // window | |
2107 | RECT rectWin; | |
2108 | ::GetWindowRect(GetHwnd(), &rectWin); | |
2109 | ||
b0268daf VZ |
2110 | const int widthWin = rectWin.right - rectWin.left, |
2111 | heightWin = rectWin.bottom - rectWin.top; | |
387a3b02 | 2112 | |
d4597e13 VZ |
2113 | // MoveWindow positions the child windows relative to the parent, so |
2114 | // adjust if necessary | |
2115 | if ( !IsTopLevel() ) | |
2116 | { | |
2117 | wxWindow *parent = GetParent(); | |
2118 | if ( parent ) | |
2119 | { | |
b0268daf | 2120 | ::ScreenToClient(GetHwndOf(parent), (POINT *)&rectWin); |
d4597e13 VZ |
2121 | } |
2122 | } | |
a23fd0e1 | 2123 | |
b0268daf | 2124 | // don't call DoMoveWindow() because we want to move window immediately |
c72b1ad7 VZ |
2125 | // and not defer it here as otherwise the value returned by |
2126 | // GetClient/WindowRect() wouldn't change as the window wouldn't be | |
2127 | // really resized | |
b0268daf VZ |
2128 | if ( !::MoveWindow(GetHwnd(), |
2129 | rectWin.left, | |
2130 | rectWin.top, | |
2131 | width + widthWin - rectClient.right, | |
2132 | height + heightWin - rectClient.bottom, | |
2133 | TRUE) ) | |
2134 | { | |
9a83f860 | 2135 | wxLogLastError(wxT("MoveWindow")); |
b0268daf | 2136 | } |
d4597e13 | 2137 | } |
42e69d6b | 2138 | } |
a23fd0e1 | 2139 | |
743b4266 VZ |
2140 | wxSize wxWindowMSW::DoGetBorderSize() const |
2141 | { | |
2142 | wxCoord border; | |
2143 | switch ( GetBorder() ) | |
2144 | { | |
2145 | case wxBORDER_STATIC: | |
2146 | case wxBORDER_SIMPLE: | |
2147 | border = 1; | |
2148 | break; | |
2149 | ||
2150 | case wxBORDER_SUNKEN: | |
2151 | border = 2; | |
2152 | break; | |
2153 | ||
2154 | case wxBORDER_RAISED: | |
2155 | case wxBORDER_DOUBLE: | |
2156 | border = 3; | |
2157 | break; | |
2158 | ||
2159 | default: | |
9a83f860 | 2160 | wxFAIL_MSG( wxT("unknown border style") ); |
743b4266 VZ |
2161 | // fall through |
2162 | ||
2163 | case wxBORDER_NONE: | |
2164 | border = 0; | |
2165 | } | |
2166 | ||
2167 | return 2*wxSize(border, border); | |
2168 | } | |
2169 | ||
42e69d6b VZ |
2170 | // --------------------------------------------------------------------------- |
2171 | // text metrics | |
2172 | // --------------------------------------------------------------------------- | |
a23fd0e1 | 2173 | |
1e6feb95 | 2174 | int wxWindowMSW::GetCharHeight() const |
42e69d6b | 2175 | { |
f6bcfd97 | 2176 | return wxGetTextMetrics(this).tmHeight; |
42e69d6b | 2177 | } |
3eddf563 | 2178 | |
1e6feb95 | 2179 | int wxWindowMSW::GetCharWidth() const |
42e69d6b | 2180 | { |
f6bcfd97 BP |
2181 | // +1 is needed because Windows apparently adds it when calculating the |
2182 | // dialog units size in pixels | |
2183 | #if wxDIALOG_UNIT_COMPATIBILITY | |
1e6feb95 | 2184 | return wxGetTextMetrics(this).tmAveCharWidth; |
f6bcfd97 BP |
2185 | #else |
2186 | return wxGetTextMetrics(this).tmAveCharWidth + 1; | |
2187 | #endif | |
42e69d6b | 2188 | } |
f4621a09 | 2189 | |
6de70470 VZ |
2190 | void wxWindowMSW::DoGetTextExtent(const wxString& string, |
2191 | int *x, int *y, | |
2192 | int *descent, | |
2193 | int *externalLeading, | |
2194 | const wxFont *fontToUse) const | |
42e69d6b | 2195 | { |
e0448413 | 2196 | wxASSERT_MSG( !fontToUse || fontToUse->Ok(), |
9a83f860 | 2197 | wxT("invalid font in GetTextExtent()") ); |
634903fd | 2198 | |
e0448413 VZ |
2199 | HFONT hfontToUse; |
2200 | if ( fontToUse ) | |
2201 | hfontToUse = GetHfontOf(*fontToUse); | |
2d17baae | 2202 | else |
e0448413 | 2203 | hfontToUse = GetHfontOf(GetFont()); |
634903fd | 2204 | |
64869ab7 | 2205 | WindowHDC hdc(GetHwnd()); |
e0448413 | 2206 | SelectInHDC selectFont(hdc, hfontToUse); |
341c92a8 | 2207 | |
42e69d6b VZ |
2208 | SIZE sizeRect; |
2209 | TEXTMETRIC tm; | |
e0a050e3 | 2210 | ::GetTextExtentPoint32(hdc, string.wx_str(), string.length(), &sizeRect); |
64869ab7 | 2211 | GetTextMetrics(hdc, &tm); |
42e69d6b | 2212 | |
0655ad29 VZ |
2213 | if ( x ) |
2214 | *x = sizeRect.cx; | |
2215 | if ( y ) | |
2216 | *y = sizeRect.cy; | |
2217 | if ( descent ) | |
2218 | *descent = tm.tmDescent; | |
2219 | if ( externalLeading ) | |
2220 | *externalLeading = tm.tmExternalLeading; | |
2bda0e17 KB |
2221 | } |
2222 | ||
c50f1fb9 VZ |
2223 | // --------------------------------------------------------------------------- |
2224 | // popup menu | |
2225 | // --------------------------------------------------------------------------- | |
2226 | ||
2e9f62da VZ |
2227 | #if wxUSE_MENUS_NATIVE |
2228 | ||
ed45e263 VZ |
2229 | // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue |
2230 | // immediately, without waiting for the next event loop iteration | |
2231 | // | |
2232 | // NB: this function should probably be made public later as it can almost | |
2233 | // surely replace wxYield() elsewhere as well | |
2234 | static void wxYieldForCommandsOnly() | |
2235 | { | |
2236 | // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't | |
2237 | // want to process it here) | |
2238 | MSG msg; | |
1bf77ee5 | 2239 | while ( ::PeekMessage(&msg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE) ) |
ed45e263 | 2240 | { |
dd7ebf8b | 2241 | if ( msg.message == WM_QUIT ) |
1bf77ee5 VZ |
2242 | { |
2243 | // if we retrieved a WM_QUIT, insert back into the message queue. | |
2244 | ::PostQuitMessage(0); | |
2245 | break; | |
2246 | } | |
7de59551 | 2247 | |
1bf77ee5 VZ |
2248 | // luckily (as we don't have access to wxEventLoopImpl method from here |
2249 | // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it | |
2250 | // immediately | |
2251 | ::TranslateMessage(&msg); | |
2252 | ::DispatchMessage(&msg); | |
2253 | } | |
ed45e263 VZ |
2254 | } |
2255 | ||
1e6feb95 | 2256 | bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y) |
c50f1fb9 VZ |
2257 | { |
2258 | menu->SetInvokingWindow(this); | |
2259 | menu->UpdateUI(); | |
2260 | ||
27d2dbbc | 2261 | if ( x == wxDefaultCoord && y == wxDefaultCoord ) |
971562cb VS |
2262 | { |
2263 | wxPoint mouse = ScreenToClient(wxGetMousePosition()); | |
2264 | x = mouse.x; y = mouse.y; | |
2265 | } | |
2266 | ||
c50f1fb9 VZ |
2267 | HWND hWnd = GetHwnd(); |
2268 | HMENU hMenu = GetHmenuOf(menu); | |
2269 | POINT point; | |
2270 | point.x = x; | |
2271 | point.y = y; | |
2272 | ::ClientToScreen(hWnd, &point); | |
5cb598ae | 2273 | #if defined(__WXWINCE__) |
b40bf35c VZ |
2274 | static const UINT flags = 0; |
2275 | #else // !__WXWINCE__ | |
2276 | UINT flags = TPM_RIGHTBUTTON; | |
2277 | // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all | |
2278 | // when it's use, I'm not sure about Win95/98 but prefer to err on the safe | |
2279 | // side and not to use it there neither -- modify the test if it does work | |
2280 | // on these systems | |
2281 | if ( wxGetWinVersion() >= wxWinVersion_5 ) | |
2282 | { | |
2283 | // using TPM_RECURSE allows us to show a popup menu while another menu | |
2284 | // is opened which can be useful and is supported by the other | |
2285 | // platforms, so allow it under Windows too | |
2286 | flags |= TPM_RECURSE; | |
2287 | } | |
2288 | #endif // __WXWINCE__/!__WXWINCE__ | |
2289 | ||
7f0586ef | 2290 | ::TrackPopupMenu(hMenu, flags, point.x, point.y, 0, hWnd, NULL); |
ed45e263 | 2291 | |
90e572f1 | 2292 | // we need to do it right now as otherwise the events are never going to be |
ed45e263 VZ |
2293 | // sent to wxCurrentPopupMenu from HandleCommand() |
2294 | // | |
2295 | // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't | |
2296 | // help and we'd still need wxYieldForCommandsOnly() as the menu may be | |
2297 | // destroyed as soon as we return (it can be a local variable in the caller | |
2298 | // for example) and so we do need to process the event immediately | |
2299 | wxYieldForCommandsOnly(); | |
2300 | ||
c50f1fb9 VZ |
2301 | menu->SetInvokingWindow(NULL); |
2302 | ||
08158721 | 2303 | return true; |
c50f1fb9 VZ |
2304 | } |
2305 | ||
1e6feb95 VZ |
2306 | #endif // wxUSE_MENUS_NATIVE |
2307 | ||
42e69d6b VZ |
2308 | // =========================================================================== |
2309 | // pre/post message processing | |
2310 | // =========================================================================== | |
2bda0e17 | 2311 | |
c140b7e7 | 2312 | WXLRESULT wxWindowMSW::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
42e69d6b VZ |
2313 | { |
2314 | if ( m_oldWndProc ) | |
2315 | return ::CallWindowProc(CASTWNDPROC m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam); | |
2316 | else | |
2317 | return ::DefWindowProc(GetHwnd(), nMsg, wParam, lParam); | |
2318 | } | |
2bda0e17 | 2319 | |
1e6feb95 | 2320 | bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg) |
42e69d6b | 2321 | { |
1e6feb95 VZ |
2322 | // wxUniversal implements tab traversal itself |
2323 | #ifndef __WXUNIVERSAL__ | |
42e69d6b | 2324 | if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) ) |
2d0a075d | 2325 | { |
42e69d6b VZ |
2326 | // intercept dialog navigation keys |
2327 | MSG *msg = (MSG *)pMsg; | |
d9317fd4 VZ |
2328 | |
2329 | // here we try to do all the job which ::IsDialogMessage() usually does | |
2330 | // internally | |
573a1586 | 2331 | if ( msg->message == WM_KEYDOWN ) |
42e69d6b | 2332 | { |
3f7bc32b VZ |
2333 | bool bCtrlDown = wxIsCtrlDown(); |
2334 | bool bShiftDown = wxIsShiftDown(); | |
a23fd0e1 | 2335 | |
42e69d6b VZ |
2336 | // WM_GETDLGCODE: ask the control if it wants the key for itself, |
2337 | // don't process it if it's the case (except for Ctrl-Tab/Enter | |
2338 | // combinations which are always processed) | |
977f50f3 VZ |
2339 | LONG lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0); |
2340 | ||
cbab1556 | 2341 | // surprisingly, DLGC_WANTALLKEYS bit mask doesn't contain the |
977f50f3 VZ |
2342 | // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically, |
2343 | // it, of course, implies them | |
2344 | if ( lDlgCode & DLGC_WANTALLKEYS ) | |
42e69d6b | 2345 | { |
977f50f3 | 2346 | lDlgCode |= DLGC_WANTTAB | DLGC_WANTARROWS; |
42e69d6b | 2347 | } |
a23fd0e1 | 2348 | |
08158721 | 2349 | bool bForward = true, |
298ca00c VZ |
2350 | bWindowChange = false, |
2351 | bFromTab = false; | |
a23fd0e1 | 2352 | |
573a1586 | 2353 | // should we process this message specially? |
08158721 | 2354 | bool bProcess = true; |
9145664b | 2355 | switch ( msg->wParam ) |
42e69d6b VZ |
2356 | { |
2357 | case VK_TAB: | |
7cc44669 VZ |
2358 | if ( (lDlgCode & DLGC_WANTTAB) && !bCtrlDown ) |
2359 | { | |
2360 | // let the control have the TAB | |
08158721 | 2361 | bProcess = false; |
42e69d6b | 2362 | } |
7cc44669 VZ |
2363 | else // use it for navigation |
2364 | { | |
42e69d6b VZ |
2365 | // Ctrl-Tab cycles thru notebook pages |
2366 | bWindowChange = bCtrlDown; | |
319fefa9 | 2367 | bForward = !bShiftDown; |
298ca00c | 2368 | bFromTab = true; |
42e69d6b VZ |
2369 | } |
2370 | break; | |
a23fd0e1 | 2371 | |
42e69d6b VZ |
2372 | case VK_UP: |
2373 | case VK_LEFT: | |
2374 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
08158721 | 2375 | bProcess = false; |
42e69d6b | 2376 | else |
08158721 | 2377 | bForward = false; |
42e69d6b | 2378 | break; |
a02eb1d2 | 2379 | |
42e69d6b VZ |
2380 | case VK_DOWN: |
2381 | case VK_RIGHT: | |
2382 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
08158721 | 2383 | bProcess = false; |
42e69d6b | 2384 | break; |
2bda0e17 | 2385 | |
efe5e221 VZ |
2386 | case VK_PRIOR: |
2387 | bForward = false; | |
2388 | // fall through | |
2389 | ||
2390 | case VK_NEXT: | |
2391 | // we treat PageUp/Dn as arrows because chances are that | |
2392 | // a control which needs arrows also needs them for | |
2393 | // navigation (e.g. wxTextCtrl, wxListCtrl, ...) | |
ada5f90d | 2394 | if ( (lDlgCode & DLGC_WANTARROWS) && !bCtrlDown ) |
efe5e221 | 2395 | bProcess = false; |
ada5f90d | 2396 | else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab |
efe5e221 VZ |
2397 | bWindowChange = true; |
2398 | break; | |
2399 | ||
42e69d6b VZ |
2400 | case VK_RETURN: |
2401 | { | |
90c6edd7 | 2402 | #if wxUSE_BUTTON |
3147bb58 | 2403 | // currently active button should get enter press even |
90c6edd7 VZ |
2404 | // if there is a default button elsewhere so check if |
2405 | // this window is a button first | |
2406 | wxWindow *btn = NULL; | |
3147bb58 | 2407 | if ( lDlgCode & DLGC_DEFPUSHBUTTON ) |
319fefa9 | 2408 | { |
3e79ed96 VZ |
2409 | // let IsDialogMessage() handle this for all |
2410 | // buttons except the owner-drawn ones which it | |
2411 | // just seems to ignore | |
2412 | long style = ::GetWindowLong(msg->hwnd, GWL_STYLE); | |
2413 | if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW ) | |
2414 | { | |
2415 | // emulate the button click | |
dca0f651 | 2416 | btn = wxFindWinFromHandle(msg->hwnd); |
3e79ed96 VZ |
2417 | } |
2418 | ||
08158721 | 2419 | bProcess = false; |
319fefa9 | 2420 | } |
90c6edd7 | 2421 | else // not a button itself, do we have default button? |
c50f1fb9 | 2422 | { |
8e86978a VZ |
2423 | // check if this window or any of its ancestors |
2424 | // wants the message for itself (we always reserve | |
2425 | // Ctrl-Enter for dialog navigation though) | |
2426 | wxWindow *win = this; | |
2427 | if ( !bCtrlDown ) | |
2428 | { | |
53b0c2bc | 2429 | // this will contain the dialog code of this |
0075ea22 | 2430 | // window and all of its parent windows in turn |
53b0c2bc VZ |
2431 | LONG lDlgCode2 = lDlgCode; |
2432 | ||
0075ea22 | 2433 | while ( win ) |
8e86978a | 2434 | { |
53b0c2bc | 2435 | if ( lDlgCode2 & DLGC_WANTMESSAGE ) |
8e86978a VZ |
2436 | { |
2437 | // as it wants to process Enter itself, | |
2438 | // don't call IsDialogMessage() which | |
2439 | // would consume it | |
2440 | return false; | |
2441 | } | |
2442 | ||
0075ea22 VZ |
2443 | // don't propagate keyboard messages beyond |
2444 | // the first top level window parent | |
2445 | if ( win->IsTopLevel() ) | |
2446 | break; | |
2447 | ||
2448 | win = win->GetParent(); | |
2449 | ||
53b0c2bc VZ |
2450 | lDlgCode2 = ::SendMessage |
2451 | ( | |
2452 | GetHwndOf(win), | |
2453 | WM_GETDLGCODE, | |
2454 | 0, | |
2455 | 0 | |
2456 | ); | |
8e86978a VZ |
2457 | } |
2458 | } | |
2459 | else // bCtrlDown | |
2460 | { | |
2461 | win = wxGetTopLevelParent(win); | |
2462 | } | |
2463 | ||
2464 | wxTopLevelWindow * const | |
2465 | tlw = wxDynamicCast(win, wxTopLevelWindow); | |
6c20e8f8 | 2466 | if ( tlw ) |
c50f1fb9 | 2467 | { |
90c6edd7 VZ |
2468 | btn = wxDynamicCast(tlw->GetDefaultItem(), |
2469 | wxButton); | |
c50f1fb9 | 2470 | } |
90c6edd7 VZ |
2471 | } |
2472 | ||
2473 | if ( btn && btn->IsEnabled() ) | |
2474 | { | |
2475 | btn->MSWCommand(BN_CLICKED, 0 /* unused */); | |
2476 | return true; | |
2477 | } | |
2478 | ||
1e6feb95 | 2479 | #endif // wxUSE_BUTTON |
90c6edd7 | 2480 | |
7b504551 | 2481 | #ifdef __WXWINCE__ |
90c6edd7 VZ |
2482 | // map Enter presses into button presses on PDAs |
2483 | wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN); | |
2484 | event.SetEventObject(this); | |
937013e0 | 2485 | if ( HandleWindowEvent(event) ) |
90c6edd7 VZ |
2486 | return true; |
2487 | #endif // __WXWINCE__ | |
42e69d6b VZ |
2488 | } |
2489 | break; | |
2bda0e17 | 2490 | |
42e69d6b | 2491 | default: |
08158721 | 2492 | bProcess = false; |
42e69d6b | 2493 | } |
2bda0e17 | 2494 | |
42e69d6b VZ |
2495 | if ( bProcess ) |
2496 | { | |
2497 | wxNavigationKeyEvent event; | |
2498 | event.SetDirection(bForward); | |
2499 | event.SetWindowChange(bWindowChange); | |
298ca00c | 2500 | event.SetFromTab(bFromTab); |
42e69d6b | 2501 | event.SetEventObject(this); |
3572173c | 2502 | |
937013e0 | 2503 | if ( HandleWindowEvent(event) ) |
57c0af52 | 2504 | { |
d7e0024b VZ |
2505 | // as we don't call IsDialogMessage(), which would take of |
2506 | // this by default, we need to manually send this message | |
1ca78aa1 JS |
2507 | // so that controls can change their UI state if needed |
2508 | MSWUpdateUIState(UIS_CLEAR, UISF_HIDEFOCUS); | |
d7e0024b | 2509 | |
08158721 | 2510 | return true; |
57c0af52 | 2511 | } |
42e69d6b VZ |
2512 | } |
2513 | } | |
a23fd0e1 | 2514 | |
98ebf919 | 2515 | if ( ::IsDialogMessage(GetHwnd(), msg) ) |
f6bcfd97 | 2516 | { |
98ebf919 VZ |
2517 | // IsDialogMessage() did something... |
2518 | return true; | |
f6bcfd97 | 2519 | } |
42e69d6b | 2520 | } |
1e6feb95 | 2521 | #endif // __WXUNIVERSAL__ |
a23fd0e1 | 2522 | |
42e69d6b VZ |
2523 | #if wxUSE_TOOLTIPS |
2524 | if ( m_tooltip ) | |
387a3b02 | 2525 | { |
42e69d6b VZ |
2526 | // relay mouse move events to the tooltip control |
2527 | MSG *msg = (MSG *)pMsg; | |
2528 | if ( msg->message == WM_MOUSEMOVE ) | |
259a4264 | 2529 | wxToolTip::RelayEvent(pMsg); |
387a3b02 | 2530 | } |
42e69d6b | 2531 | #endif // wxUSE_TOOLTIPS |
a23fd0e1 | 2532 | |
08158721 | 2533 | return false; |
387a3b02 JS |
2534 | } |
2535 | ||
1e6feb95 | 2536 | bool wxWindowMSW::MSWTranslateMessage(WXMSG* pMsg) |
387a3b02 | 2537 | { |
1e6feb95 | 2538 | #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
c50f1fb9 | 2539 | return m_acceleratorTable.Translate(this, pMsg); |
1e6feb95 | 2540 | #else |
574c939e | 2541 | (void) pMsg; |
08158721 | 2542 | return false; |
1e6feb95 | 2543 | #endif // wxUSE_ACCEL |
387a3b02 JS |
2544 | } |
2545 | ||
98ebf919 | 2546 | bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG* msg) |
a37d422a | 2547 | { |
98ebf919 VZ |
2548 | // all tests below have to deal with various bugs/misfeatures of |
2549 | // IsDialogMessage(): we have to prevent it from being called from our | |
2550 | // MSWProcessMessage() in some situations | |
2551 | ||
2552 | // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the | |
2553 | // message even when there is no cancel button and when the message is | |
2554 | // needed by the control itself: in particular, it prevents the tree in | |
2555 | // place edit control from being closed with Escape in a dialog | |
2556 | if ( msg->message == WM_KEYDOWN && msg->wParam == VK_ESCAPE ) | |
2557 | { | |
2558 | return false; | |
2559 | } | |
2560 | ||
2561 | // ::IsDialogMessage() is broken and may sometimes hang the application by | |
2562 | // going into an infinite loop when it tries to find the control to give | |
2563 | // focus to when Alt-<key> is pressed, so we try to detect [some of] the | |
2564 | // situations when this may happen and not call it then | |
2565 | if ( msg->message != WM_SYSCHAR ) | |
2566 | return true; | |
2567 | ||
2568 | // assume we can call it by default | |
2569 | bool canSafelyCallIsDlgMsg = true; | |
2570 | ||
2571 | HWND hwndFocus = ::GetFocus(); | |
2572 | ||
2573 | // if the currently focused window itself has WS_EX_CONTROLPARENT style, | |
2574 | // ::IsDialogMessage() will also enter an infinite loop, because it will | |
2575 | // recursively check the child windows but not the window itself and so if | |
2576 | // none of the children accepts focus it loops forever (as it only stops | |
2577 | // when it gets back to the window it started from) | |
2578 | // | |
2579 | // while it is very unusual that a window with WS_EX_CONTROLPARENT | |
2580 | // style has the focus, it can happen. One such possibility is if | |
2581 | // all windows are either toplevel, wxDialog, wxPanel or static | |
2582 | // controls and no window can actually accept keyboard input. | |
2583 | #if !defined(__WXWINCE__) | |
2584 | if ( ::GetWindowLong(hwndFocus, GWL_EXSTYLE) & WS_EX_CONTROLPARENT ) | |
2585 | { | |
2586 | // pessimistic by default | |
2587 | canSafelyCallIsDlgMsg = false; | |
2588 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
2589 | node; | |
2590 | node = node->GetNext() ) | |
2591 | { | |
2592 | wxWindow * const win = node->GetData(); | |
ad02525d | 2593 | if ( win->CanAcceptFocus() && |
d66d0500 | 2594 | !wxHasWindowExStyle(win, WS_EX_CONTROLPARENT) ) |
98ebf919 VZ |
2595 | { |
2596 | // it shouldn't hang... | |
2597 | canSafelyCallIsDlgMsg = true; | |
2598 | ||
2599 | break; | |
2600 | } | |
2601 | } | |
2602 | } | |
2603 | #endif // !__WXWINCE__ | |
2604 | ||
2605 | if ( canSafelyCallIsDlgMsg ) | |
2606 | { | |
2607 | // ::IsDialogMessage() can enter in an infinite loop when the | |
2608 | // currently focused window is disabled or hidden and its | |
2609 | // parent has WS_EX_CONTROLPARENT style, so don't call it in | |
2610 | // this case | |
2611 | while ( hwndFocus ) | |
2612 | { | |
2613 | if ( !::IsWindowEnabled(hwndFocus) || | |
2614 | !::IsWindowVisible(hwndFocus) ) | |
2615 | { | |
2616 | // it would enter an infinite loop if we do this! | |
2617 | canSafelyCallIsDlgMsg = false; | |
2618 | ||
2619 | break; | |
2620 | } | |
2621 | ||
2622 | if ( !(::GetWindowLong(hwndFocus, GWL_STYLE) & WS_CHILD) ) | |
2623 | { | |
2624 | // it's a top level window, don't go further -- e.g. even | |
2625 | // if the parent of a dialog is disabled, this doesn't | |
2626 | // break navigation inside the dialog | |
2627 | break; | |
2628 | } | |
2629 | ||
2630 | hwndFocus = ::GetParent(hwndFocus); | |
2631 | } | |
2632 | } | |
2633 | ||
2634 | return canSafelyCallIsDlgMsg; | |
a37d422a VZ |
2635 | } |
2636 | ||
42e69d6b | 2637 | // --------------------------------------------------------------------------- |
e39af974 | 2638 | // message params unpackers |
42e69d6b | 2639 | // --------------------------------------------------------------------------- |
2bda0e17 | 2640 | |
1e6feb95 | 2641 | void wxWindowMSW::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b VZ |
2642 | WORD *id, WXHWND *hwnd, WORD *cmd) |
2643 | { | |
2644 | *id = LOWORD(wParam); | |
2645 | *hwnd = (WXHWND)lParam; | |
2646 | *cmd = HIWORD(wParam); | |
2bda0e17 KB |
2647 | } |
2648 | ||
1e6feb95 | 2649 | void wxWindowMSW::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 2650 | WXWORD *state, WXWORD *minimized, WXHWND *hwnd) |
2bda0e17 | 2651 | { |
42e69d6b VZ |
2652 | *state = LOWORD(wParam); |
2653 | *minimized = HIWORD(wParam); | |
2654 | *hwnd = (WXHWND)lParam; | |
2bda0e17 KB |
2655 | } |
2656 | ||
1e6feb95 | 2657 | void wxWindowMSW::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 2658 | WXWORD *code, WXWORD *pos, WXHWND *hwnd) |
2bda0e17 | 2659 | { |
42e69d6b VZ |
2660 | *code = LOWORD(wParam); |
2661 | *pos = HIWORD(wParam); | |
2662 | *hwnd = (WXHWND)lParam; | |
2663 | } | |
a23fd0e1 | 2664 | |
1e6feb95 | 2665 | void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam, |
01c500af | 2666 | WXHDC *hdc, WXHWND *hwnd) |
42e69d6b | 2667 | { |
42e69d6b VZ |
2668 | *hwnd = (WXHWND)lParam; |
2669 | *hdc = (WXHDC)wParam; | |
2bda0e17 KB |
2670 | } |
2671 | ||
1e6feb95 | 2672 | void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 2673 | WXWORD *item, WXWORD *flags, WXHMENU *hmenu) |
2bda0e17 | 2674 | { |
42e69d6b VZ |
2675 | *item = (WXWORD)wParam; |
2676 | *flags = HIWORD(wParam); | |
2677 | *hmenu = (WXHMENU)lParam; | |
2678 | } | |
c085e333 | 2679 | |
42e69d6b | 2680 | // --------------------------------------------------------------------------- |
77ffb593 | 2681 | // Main wxWidgets window proc and the window proc for wxWindow |
42e69d6b | 2682 | // --------------------------------------------------------------------------- |
2bda0e17 | 2683 | |
42e69d6b VZ |
2684 | // Hook for new window just as it's being created, when the window isn't yet |
2685 | // associated with the handle | |
b225f659 VZ |
2686 | static wxWindowMSW *gs_winBeingCreated = NULL; |
2687 | ||
2688 | // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the | |
2689 | // window being created and insures that it's always unset back later | |
2690 | wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW *winBeingCreated) | |
2691 | { | |
2692 | gs_winBeingCreated = winBeingCreated; | |
2693 | } | |
2694 | ||
2695 | wxWindowCreationHook::~wxWindowCreationHook() | |
2696 | { | |
2697 | gs_winBeingCreated = NULL; | |
2698 | } | |
42e69d6b VZ |
2699 | |
2700 | // Main window proc | |
3135f4a7 | 2701 | LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
2bda0e17 | 2702 | { |
4b6a582b VZ |
2703 | // trace all messages: useful for the debugging but noticeably slows down |
2704 | // the code so don't do it by default | |
2705 | #if wxDEBUG_LEVEL >= 2 | |
5ec3853f | 2706 | wxLogTrace("winmsg", |
dca0f651 VZ |
2707 | wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"), |
2708 | wxGetMessageName(message), hWnd, (long)wParam, lParam); | |
4b6a582b | 2709 | #endif // wxDEBUG_LEVEL >= 2 |
2bda0e17 | 2710 | |
dca0f651 | 2711 | wxWindowMSW *wnd = wxFindWinFromHandle(hWnd); |
c085e333 | 2712 | |
42e69d6b | 2713 | // when we get the first message for the HWND we just created, we associate |
b225f659 VZ |
2714 | // it with wxWindow stored in gs_winBeingCreated |
2715 | if ( !wnd && gs_winBeingCreated ) | |
2d0a075d | 2716 | { |
b225f659 VZ |
2717 | wxAssociateWinWithHandle(hWnd, gs_winBeingCreated); |
2718 | wnd = gs_winBeingCreated; | |
2719 | gs_winBeingCreated = NULL; | |
42e69d6b | 2720 | wnd->SetHWND((WXHWND)hWnd); |
2d0a075d | 2721 | } |
2bda0e17 | 2722 | |
42e69d6b | 2723 | LRESULT rc; |
a23fd0e1 | 2724 | |
b46b1d59 | 2725 | if ( wnd && wxGUIEventLoop::AllowProcessing(wnd) ) |
b225f659 | 2726 | rc = wnd->MSWWindowProc(message, wParam, lParam); |
a23fd0e1 | 2727 | else |
b225f659 | 2728 | rc = ::DefWindowProc(hWnd, message, wParam, lParam); |
2bda0e17 | 2729 | |
42e69d6b | 2730 | return rc; |
f7bd2698 JS |
2731 | } |
2732 | ||
c140b7e7 | 2733 | WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
f7bd2698 | 2734 | { |
42e69d6b | 2735 | // did we process the message? |
08158721 | 2736 | bool processed = false; |
f7bd2698 | 2737 | |
42e69d6b VZ |
2738 | // the return value |
2739 | union | |
2bda0e17 | 2740 | { |
42e69d6b | 2741 | bool allow; |
c140b7e7 | 2742 | WXLRESULT result; |
42e69d6b VZ |
2743 | WXHBRUSH hBrush; |
2744 | } rc; | |
2bda0e17 | 2745 | |
42e69d6b VZ |
2746 | // for most messages we should return 0 when we do process the message |
2747 | rc.result = 0; | |
2bda0e17 | 2748 | |
42e69d6b | 2749 | switch ( message ) |
39136494 | 2750 | { |
42e69d6b VZ |
2751 | case WM_CREATE: |
2752 | { | |
2753 | bool mayCreate; | |
2754 | processed = HandleCreate((WXLPCREATESTRUCT)lParam, &mayCreate); | |
2755 | if ( processed ) | |
2756 | { | |
2757 | // return 0 to allow window creation | |
2758 | rc.result = mayCreate ? 0 : -1; | |
2759 | } | |
2760 | } | |
2761 | break; | |
47cbd6da | 2762 | |
42e69d6b | 2763 | case WM_DESTROY: |
08158721 | 2764 | // never set processed to true and *always* pass WM_DESTROY to |
ad4297f3 VZ |
2765 | // DefWindowProc() as Windows may do some internal cleanup when |
2766 | // processing it and failing to pass the message along may cause | |
2767 | // memory and resource leaks! | |
2768 | (void)HandleDestroy(); | |
42e69d6b VZ |
2769 | break; |
2770 | ||
9b6ae450 VZ |
2771 | case WM_SIZE: |
2772 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
9b6ae450 VZ |
2773 | break; |
2774 | ||
42e69d6b | 2775 | case WM_MOVE: |
132cb640 | 2776 | processed = HandleMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); |
42e69d6b | 2777 | break; |
47cbd6da | 2778 | |
7f0586ef | 2779 | #if !defined(__WXWINCE__) |
5706de1c | 2780 | case WM_MOVING: |
540b6b09 VZ |
2781 | { |
2782 | LPRECT pRect = (LPRECT)lParam; | |
2783 | wxRect rc; | |
2784 | rc.SetLeft(pRect->left); | |
2785 | rc.SetTop(pRect->top); | |
2786 | rc.SetRight(pRect->right); | |
2787 | rc.SetBottom(pRect->bottom); | |
2788 | processed = HandleMoving(rc); | |
2789 | if (processed) { | |
2790 | pRect->left = rc.GetLeft(); | |
2791 | pRect->top = rc.GetTop(); | |
2792 | pRect->right = rc.GetRight(); | |
2793 | pRect->bottom = rc.GetBottom(); | |
2794 | } | |
2795 | } | |
5706de1c | 2796 | break; |
a047aff2 | 2797 | #if 0 |
aa767a45 JS |
2798 | case WM_ENTERSIZEMOVE: |
2799 | { | |
2800 | processed = HandleEnterSizeMove(); | |
2801 | } | |
2802 | break; | |
2803 | ||
2804 | case WM_EXITSIZEMOVE: | |
2805 | { | |
2806 | processed = HandleExitSizeMove(); | |
2807 | } | |
2808 | break; | |
a047aff2 | 2809 | #endif |
5706de1c JS |
2810 | case WM_SIZING: |
2811 | { | |
2812 | LPRECT pRect = (LPRECT)lParam; | |
2813 | wxRect rc; | |
2814 | rc.SetLeft(pRect->left); | |
2815 | rc.SetTop(pRect->top); | |
2816 | rc.SetRight(pRect->right); | |
2817 | rc.SetBottom(pRect->bottom); | |
2818 | processed = HandleSizing(rc); | |
2819 | if (processed) { | |
2820 | pRect->left = rc.GetLeft(); | |
2821 | pRect->top = rc.GetTop(); | |
2822 | pRect->right = rc.GetRight(); | |
2823 | pRect->bottom = rc.GetBottom(); | |
2824 | } | |
2825 | } | |
2826 | break; | |
9b6ae450 | 2827 | #endif // !__WXWINCE__ |
5706de1c | 2828 | |
7f0586ef | 2829 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
1e6feb95 | 2830 | case WM_ACTIVATEAPP: |
afafd942 | 2831 | // This implicitly sends a wxEVT_ACTIVATE_APP event |
1e6feb95 | 2832 | wxTheApp->SetActive(wParam != 0, FindFocus()); |
42e69d6b | 2833 | break; |
8a46f9b1 | 2834 | #endif |
47cbd6da | 2835 | |
42e69d6b | 2836 | case WM_ACTIVATE: |
341c92a8 | 2837 | { |
42e69d6b VZ |
2838 | WXWORD state, minimized; |
2839 | WXHWND hwnd; | |
2840 | UnpackActivate(wParam, lParam, &state, &minimized, &hwnd); | |
2841 | ||
2842 | processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd); | |
341c92a8 | 2843 | } |
42e69d6b | 2844 | break; |
341c92a8 | 2845 | |
42e69d6b | 2846 | case WM_SETFOCUS: |
dca0f651 | 2847 | processed = HandleSetFocus((WXHWND)wParam); |
42e69d6b | 2848 | break; |
47cbd6da | 2849 | |
42e69d6b | 2850 | case WM_KILLFOCUS: |
dca0f651 | 2851 | processed = HandleKillFocus((WXHWND)wParam); |
42e69d6b | 2852 | break; |
47cbd6da | 2853 | |
c3732409 | 2854 | case WM_PRINTCLIENT: |
1a784dfc | 2855 | processed = HandlePrintClient((WXHDC)wParam); |
07c19327 VZ |
2856 | break; |
2857 | ||
c3732409 VZ |
2858 | case WM_PAINT: |
2859 | if ( wParam ) | |
5c6c3176 | 2860 | { |
5c6c3176 | 2861 | wxPaintDCEx dc((wxWindow *)this, (WXHDC)wParam); |
07c19327 | 2862 | |
5c6c3176 RD |
2863 | processed = HandlePaint(); |
2864 | } | |
c3732409 VZ |
2865 | else // no DC given |
2866 | { | |
2867 | processed = HandlePaint(); | |
2868 | } | |
5c6c3176 RD |
2869 | break; |
2870 | ||
42e69d6b | 2871 | case WM_CLOSE: |
9fd9e47a JS |
2872 | #ifdef __WXUNIVERSAL__ |
2873 | // Universal uses its own wxFrame/wxDialog, so we don't receive | |
2874 | // close events unless we have this. | |
2875 | Close(); | |
c3732409 VZ |
2876 | #endif // __WXUNIVERSAL__ |
2877 | ||
42e69d6b VZ |
2878 | // don't let the DefWindowProc() destroy our window - we'll do it |
2879 | // ourselves in ~wxWindow | |
08158721 | 2880 | processed = true; |
42e69d6b VZ |
2881 | rc.result = TRUE; |
2882 | break; | |
47cbd6da | 2883 | |
42e69d6b VZ |
2884 | case WM_SHOWWINDOW: |
2885 | processed = HandleShow(wParam != 0, (int)lParam); | |
2886 | break; | |
3a19e16d | 2887 | |
42e69d6b | 2888 | case WM_MOUSEMOVE: |
132cb640 VZ |
2889 | processed = HandleMouseMove(GET_X_LPARAM(lParam), |
2890 | GET_Y_LPARAM(lParam), | |
2891 | wParam); | |
2892 | break; | |
0d0512bd | 2893 | |
4e5c6c33 | 2894 | #ifdef HAVE_TRACKMOUSEEVENT |
e5297b7f | 2895 | case WM_MOUSELEAVE: |
aafb9978 VZ |
2896 | // filter out excess WM_MOUSELEAVE events sent after PopupMenu() |
2897 | // (on XP at least) | |
4e5c6c33 | 2898 | if ( m_mouseInWindow ) |
e5297b7f | 2899 | { |
4e5c6c33 | 2900 | GenerateMouseLeave(); |
e5297b7f | 2901 | } |
4e5c6c33 VZ |
2902 | |
2903 | // always pass processed back as false, this allows the window | |
2904 | // manager to process the message too. This is needed to | |
2905 | // ensure windows XP themes work properly as the mouse moves | |
2906 | // over widgets like buttons. So don't set processed to true here. | |
51e4e266 | 2907 | break; |
4e5c6c33 | 2908 | #endif // HAVE_TRACKMOUSEEVENT |
35bbb0c6 | 2909 | |
d2c52078 RD |
2910 | #if wxUSE_MOUSEWHEEL |
2911 | case WM_MOUSEWHEEL: | |
2912 | processed = HandleMouseWheel(wParam, lParam); | |
2913 | break; | |
2914 | #endif | |
2915 | ||
42e69d6b VZ |
2916 | case WM_LBUTTONDOWN: |
2917 | case WM_LBUTTONUP: | |
2918 | case WM_LBUTTONDBLCLK: | |
2919 | case WM_RBUTTONDOWN: | |
2920 | case WM_RBUTTONUP: | |
2921 | case WM_RBUTTONDBLCLK: | |
2922 | case WM_MBUTTONDOWN: | |
2923 | case WM_MBUTTONUP: | |
2924 | case WM_MBUTTONDBLCLK: | |
2f68482e | 2925 | #ifdef wxHAS_XBUTTON |
01101e2d VZ |
2926 | case WM_XBUTTONDOWN: |
2927 | case WM_XBUTTONUP: | |
2928 | case WM_XBUTTONDBLCLK: | |
2f68482e | 2929 | #endif // wxHAS_XBUTTON |
dfafa702 | 2930 | { |
98363307 | 2931 | #ifdef __WXMICROWIN__ |
cd4453e5 VZ |
2932 | // MicroWindows seems to ignore the fact that a window is |
2933 | // disabled. So catch mouse events and throw them away if | |
2934 | // necessary. | |
d0a3d109 | 2935 | wxWindowMSW* win = this; |
dfafa702 | 2936 | for ( ;; ) |
d0a3d109 VZ |
2937 | { |
2938 | if (!win->IsEnabled()) | |
2939 | { | |
08158721 | 2940 | processed = true; |
d0a3d109 VZ |
2941 | break; |
2942 | } | |
dfafa702 | 2943 | |
d0a3d109 | 2944 | win = win->GetParent(); |
dfafa702 | 2945 | if ( !win || win->IsTopLevel() ) |
d0a3d109 VZ |
2946 | break; |
2947 | } | |
dfafa702 | 2948 | |
03e0b2b1 VZ |
2949 | if ( processed ) |
2950 | break; | |
2951 | ||
dfafa702 | 2952 | #endif // __WXMICROWIN__ |
03e0b2b1 VZ |
2953 | int x = GET_X_LPARAM(lParam), |
2954 | y = GET_Y_LPARAM(lParam); | |
dfafa702 | 2955 | |
42b1fb63 | 2956 | #ifdef __WXWINCE__ |
03e0b2b1 | 2957 | // redirect the event to a static control if necessary by |
42b1fb63 VZ |
2958 | // finding one under mouse because under CE the static controls |
2959 | // don't generate mouse events (even with SS_NOTIFY) | |
03e0b2b1 VZ |
2960 | wxWindowMSW *win; |
2961 | if ( GetCapture() == this ) | |
2962 | { | |
2963 | // but don't do it if the mouse is captured by this window | |
2964 | // because then it should really get this event itself | |
2965 | win = this; | |
d0a3d109 | 2966 | } |
03e0b2b1 VZ |
2967 | else |
2968 | { | |
2969 | win = FindWindowForMouseEvent(this, &x, &y); | |
2b5f62a0 VZ |
2970 | |
2971 | // this should never happen | |
2972 | wxCHECK_MSG( win, 0, | |
9a83f860 | 2973 | wxT("FindWindowForMouseEvent() returned NULL") ); |
9f011847 | 2974 | } |
7d4f65e3 JS |
2975 | #ifdef __POCKETPC__ |
2976 | if (IsContextMenuEnabled() && message == WM_LBUTTONDOWN) | |
2977 | { | |
2978 | SHRGINFO shrgi = {0}; | |
faa94f3e | 2979 | |
7d4f65e3 JS |
2980 | shrgi.cbSize = sizeof(SHRGINFO); |
2981 | shrgi.hwndClient = (HWND) GetHWND(); | |
2982 | shrgi.ptDown.x = x; | |
2983 | shrgi.ptDown.y = y; | |
faa94f3e | 2984 | |
7d4f65e3 JS |
2985 | shrgi.dwFlags = SHRG_RETURNCMD; |
2986 | // shrgi.dwFlags = SHRG_NOTIFYPARENT; | |
faa94f3e | 2987 | |
7d4f65e3 JS |
2988 | if (GN_CONTEXTMENU == ::SHRecognizeGesture(&shrgi)) |
2989 | { | |
2990 | wxPoint pt(x, y); | |
2991 | pt = ClientToScreen(pt); | |
faa94f3e | 2992 | |
7d4f65e3 | 2993 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt); |
faa94f3e | 2994 | |
7d4f65e3 | 2995 | evtCtx.SetEventObject(this); |
937013e0 | 2996 | if (HandleWindowEvent(evtCtx)) |
f350d4b2 | 2997 | { |
7d4f65e3 | 2998 | processed = true; |
f350d4b2 JS |
2999 | return true; |
3000 | } | |
7d4f65e3 JS |
3001 | } |
3002 | } | |
3003 | #endif | |
3004 | ||
42b1fb63 VZ |
3005 | #else // !__WXWINCE__ |
3006 | wxWindowMSW *win = this; | |
3007 | #endif // __WXWINCE__/!__WXWINCE__ | |
9f011847 VZ |
3008 | |
3009 | processed = win->HandleMouseEvent(message, x, y, wParam); | |
2b5f62a0 | 3010 | |
9f011847 VZ |
3011 | // if the app didn't eat the event, handle it in the default |
3012 | // way, that is by giving this window the focus | |
3013 | if ( !processed ) | |
3014 | { | |
2b5f62a0 VZ |
3015 | // for the standard classes their WndProc sets the focus to |
3016 | // them anyhow and doing it from here results in some weird | |
9f011847 | 3017 | // problems, so don't do it for them (unnecessary anyhow) |
2b5f62a0 VZ |
3018 | if ( !win->IsOfStandardClass() ) |
3019 | { | |
edc09871 | 3020 | if ( message == WM_LBUTTONDOWN && win->IsFocusable() ) |
2b5f62a0 VZ |
3021 | win->SetFocus(); |
3022 | } | |
03e0b2b1 | 3023 | } |
98363307 | 3024 | } |
dfafa702 | 3025 | break; |
d0a3d109 | 3026 | |
cd4453e5 | 3027 | #ifdef MM_JOY1MOVE |
42e69d6b VZ |
3028 | case MM_JOY1MOVE: |
3029 | case MM_JOY2MOVE: | |
3030 | case MM_JOY1ZMOVE: | |
3031 | case MM_JOY2ZMOVE: | |
3032 | case MM_JOY1BUTTONDOWN: | |
3033 | case MM_JOY2BUTTONDOWN: | |
3034 | case MM_JOY1BUTTONUP: | |
3035 | case MM_JOY2BUTTONUP: | |
132cb640 VZ |
3036 | processed = HandleJoystickEvent(message, |
3037 | GET_X_LPARAM(lParam), | |
3038 | GET_Y_LPARAM(lParam), | |
3039 | wParam); | |
42e69d6b | 3040 | break; |
cd4453e5 | 3041 | #endif // __WXMICROWIN__ |
47cbd6da | 3042 | |
42e69d6b VZ |
3043 | case WM_COMMAND: |
3044 | { | |
3045 | WORD id, cmd; | |
3046 | WXHWND hwnd; | |
3047 | UnpackCommand(wParam, lParam, &id, &hwnd, &cmd); | |
47cbd6da | 3048 | |
42e69d6b VZ |
3049 | processed = HandleCommand(id, cmd, hwnd); |
3050 | } | |
3051 | break; | |
7d532b0c | 3052 | |
42e69d6b VZ |
3053 | case WM_NOTIFY: |
3054 | processed = HandleNotify((int)wParam, lParam, &rc.result); | |
3055 | break; | |
2bda0e17 | 3056 | |
27005f3a VZ |
3057 | // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU, |
3058 | // otherwise DefWindowProc() does it perfectly fine for us, but MSLU | |
3059 | // apparently doesn't always behave properly and needs some help | |
3060 | #if wxUSE_UNICODE_MSLU && defined(NF_QUERY) | |
3061 | case WM_NOTIFYFORMAT: | |
3062 | if ( lParam == NF_QUERY ) | |
3063 | { | |
3064 | processed = true; | |
3065 | rc.result = NFR_UNICODE; | |
3066 | } | |
3067 | break; | |
3068 | #endif // wxUSE_UNICODE_MSLU | |
3069 | ||
08158721 | 3070 | // for these messages we must return true if process the message |
cd4453e5 | 3071 | #ifdef WM_DRAWITEM |
42e69d6b | 3072 | case WM_DRAWITEM: |
dca0f651 VZ |
3073 | processed = MSWOnDrawItem(wParam, (WXDRAWITEMSTRUCT *)lParam); |
3074 | if ( processed ) | |
3075 | rc.result = TRUE; | |
3076 | break; | |
57a7b7c1 | 3077 | |
dca0f651 VZ |
3078 | case WM_MEASUREITEM: |
3079 | processed = MSWOnMeasureItem(wParam, (WXMEASUREITEMSTRUCT *)lParam); | |
3080 | if ( processed ) | |
3081 | rc.result = TRUE; | |
42e69d6b | 3082 | break; |
cd4453e5 VZ |
3083 | #endif // defined(WM_DRAWITEM) |
3084 | ||
9bf84618 | 3085 | case WM_GETDLGCODE: |
ff7282e1 | 3086 | if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS) ) |
9bf84618 | 3087 | { |
5a403e3f VZ |
3088 | // we always want to get the char events |
3089 | rc.result = DLGC_WANTCHARS; | |
3090 | ||
ff7282e1 | 3091 | if ( HasFlag(wxWANTS_CHARS) ) |
5a403e3f VZ |
3092 | { |
3093 | // in fact, we want everything | |
3094 | rc.result |= DLGC_WANTARROWS | | |
3095 | DLGC_WANTTAB | | |
3096 | DLGC_WANTALLKEYS; | |
3097 | } | |
3098 | ||
08158721 | 3099 | processed = true; |
9bf84618 | 3100 | } |
101f488c | 3101 | //else: get the dlg code from the DefWindowProc() |
9bf84618 VZ |
3102 | break; |
3103 | ||
4004f41e | 3104 | case WM_SYSKEYDOWN: |
42e69d6b | 3105 | case WM_KEYDOWN: |
9c7df356 VZ |
3106 | // If this has been processed by an event handler, return 0 now |
3107 | // (we've handled it). | |
3108 | m_lastKeydownProcessed = HandleKeyDown((WORD) wParam, lParam); | |
3109 | if ( m_lastKeydownProcessed ) | |
2d0a075d | 3110 | { |
08158721 | 3111 | processed = true; |
2d0a075d | 3112 | } |
81d66cf3 | 3113 | |
2b5f62a0 | 3114 | if ( !processed ) |
42e69d6b | 3115 | { |
2b5f62a0 VZ |
3116 | switch ( wParam ) |
3117 | { | |
90e572f1 | 3118 | // we consider these messages "not interesting" to OnChar, so |
2b5f62a0 VZ |
3119 | // just don't do anything more with them |
3120 | case VK_SHIFT: | |
3121 | case VK_CONTROL: | |
3122 | case VK_MENU: | |
3123 | case VK_CAPITAL: | |
3124 | case VK_NUMLOCK: | |
3125 | case VK_SCROLL: | |
08158721 | 3126 | processed = true; |
2b5f62a0 | 3127 | break; |
2bda0e17 | 3128 | |
2b5f62a0 VZ |
3129 | // avoid duplicate messages to OnChar for these ASCII keys: |
3130 | // they will be translated by TranslateMessage() and received | |
3131 | // in WM_CHAR | |
3132 | case VK_ESCAPE: | |
3133 | case VK_SPACE: | |
3134 | case VK_RETURN: | |
3135 | case VK_BACK: | |
3136 | case VK_TAB: | |
3137 | case VK_ADD: | |
3138 | case VK_SUBTRACT: | |
3139 | case VK_MULTIPLY: | |
3140 | case VK_DIVIDE: | |
7fd86b21 | 3141 | case VK_DECIMAL: |
3f2174bb VZ |
3142 | case VK_NUMPAD0: |
3143 | case VK_NUMPAD1: | |
3144 | case VK_NUMPAD2: | |
3145 | case VK_NUMPAD3: | |
3146 | case VK_NUMPAD4: | |
3147 | case VK_NUMPAD5: | |
3148 | case VK_NUMPAD6: | |
3149 | case VK_NUMPAD7: | |
3150 | case VK_NUMPAD8: | |
3151 | case VK_NUMPAD9: | |
2b5f62a0 VZ |
3152 | case VK_OEM_1: |
3153 | case VK_OEM_2: | |
3154 | case VK_OEM_3: | |
3155 | case VK_OEM_4: | |
3156 | case VK_OEM_5: | |
3157 | case VK_OEM_6: | |
3158 | case VK_OEM_7: | |
3159 | case VK_OEM_PLUS: | |
3160 | case VK_OEM_COMMA: | |
3161 | case VK_OEM_MINUS: | |
3162 | case VK_OEM_PERIOD: | |
08158721 | 3163 | // but set processed to false, not true to still pass them |
2b5f62a0 VZ |
3164 | // to the control's default window proc - otherwise |
3165 | // built-in keyboard handling won't work | |
08158721 | 3166 | processed = false; |
2b5f62a0 | 3167 | break; |
2bda0e17 | 3168 | |
42e69d6b | 3169 | #ifdef VK_APPS |
2b5f62a0 VZ |
3170 | // special case of VK_APPS: treat it the same as right mouse |
3171 | // click because both usually pop up a context menu | |
3172 | case VK_APPS: | |
ae177b45 | 3173 | processed = HandleMouseEvent(WM_RBUTTONDOWN, -1, -1, 0); |
2b5f62a0 | 3174 | break; |
42e69d6b | 3175 | #endif // VK_APPS |
2bda0e17 | 3176 | |
2b5f62a0 VZ |
3177 | default: |
3178 | // do generate a CHAR event | |
3179 | processed = HandleChar((WORD)wParam, lParam); | |
3180 | } | |
42e69d6b | 3181 | } |
2b5f62a0 | 3182 | if (message == WM_SYSKEYDOWN) // Let Windows still handle the SYSKEYs |
08158721 | 3183 | processed = false; |
42e69d6b | 3184 | break; |
2bda0e17 | 3185 | |
4004f41e | 3186 | case WM_SYSKEYUP: |
42e69d6b | 3187 | case WM_KEYUP: |
4aff28fc VZ |
3188 | #ifdef VK_APPS |
3189 | // special case of VK_APPS: treat it the same as right mouse button | |
3190 | if ( wParam == VK_APPS ) | |
3191 | { | |
ae177b45 | 3192 | processed = HandleMouseEvent(WM_RBUTTONUP, -1, -1, 0); |
4aff28fc VZ |
3193 | } |
3194 | else | |
3195 | #endif // VK_APPS | |
3196 | { | |
3197 | processed = HandleKeyUp((WORD) wParam, lParam); | |
3198 | } | |
42e69d6b | 3199 | break; |
debe6624 | 3200 | |
170cbe33 | 3201 | case WM_SYSCHAR: |
42e69d6b | 3202 | case WM_CHAR: // Always an ASCII character |
d9f14e16 RD |
3203 | if ( m_lastKeydownProcessed ) |
3204 | { | |
3205 | // The key was handled in the EVT_KEY_DOWN and handling | |
3206 | // a key in an EVT_KEY_DOWN handler is meant, by | |
3207 | // design, to prevent EVT_CHARs from happening | |
08158721 DS |
3208 | m_lastKeydownProcessed = false; |
3209 | processed = true; | |
d9f14e16 RD |
3210 | } |
3211 | else | |
7de5bdf4 | 3212 | { |
08158721 | 3213 | processed = HandleChar((WORD)wParam, lParam, true); |
7de5bdf4 | 3214 | } |
42e69d6b | 3215 | break; |
2bda0e17 | 3216 | |
5048c832 JS |
3217 | #if wxUSE_HOTKEY |
3218 | case WM_HOTKEY: | |
3219 | processed = HandleHotKey((WORD)wParam, lParam); | |
3220 | break; | |
540b6b09 | 3221 | #endif // wxUSE_HOTKEY |
5048c832 | 3222 | |
b65f16da VS |
3223 | case WM_CUT: |
3224 | case WM_COPY: | |
3225 | case WM_PASTE: | |
3226 | processed = HandleClipboardEvent(message); | |
3227 | break; | |
3228 | ||
42e69d6b VZ |
3229 | case WM_HSCROLL: |
3230 | case WM_VSCROLL: | |
a23fd0e1 | 3231 | { |
42e69d6b VZ |
3232 | WXWORD code, pos; |
3233 | WXHWND hwnd; | |
3234 | UnpackScroll(wParam, lParam, &code, &pos, &hwnd); | |
2bda0e17 | 3235 | |
42e69d6b VZ |
3236 | processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL |
3237 | : wxVERTICAL, | |
3238 | code, pos, hwnd); | |
a23fd0e1 | 3239 | } |
42e69d6b | 3240 | break; |
a23fd0e1 | 3241 | |
42e69d6b | 3242 | // CTLCOLOR messages are sent by children to query the parent for their |
01c500af | 3243 | // colors |
04ef50df | 3244 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
3245 | case WM_CTLCOLORMSGBOX: |
3246 | case WM_CTLCOLOREDIT: | |
3247 | case WM_CTLCOLORLISTBOX: | |
3248 | case WM_CTLCOLORBTN: | |
3249 | case WM_CTLCOLORDLG: | |
3250 | case WM_CTLCOLORSCROLLBAR: | |
3251 | case WM_CTLCOLORSTATIC: | |
a23fd0e1 | 3252 | { |
42e69d6b VZ |
3253 | WXHDC hdc; |
3254 | WXHWND hwnd; | |
01c500af | 3255 | UnpackCtlColor(wParam, lParam, &hdc, &hwnd); |
42e69d6b | 3256 | |
48fa6bd3 | 3257 | processed = HandleCtlColor(&rc.hBrush, (WXHDC)hdc, (WXHWND)hwnd); |
a23fd0e1 | 3258 | } |
42e69d6b | 3259 | break; |
cd4453e5 | 3260 | #endif // !__WXMICROWIN__ |
debe6624 | 3261 | |
42e69d6b | 3262 | case WM_SYSCOLORCHANGE: |
90c1530a | 3263 | // the return value for this message is ignored |
42e69d6b VZ |
3264 | processed = HandleSysColorChange(); |
3265 | break; | |
2bda0e17 | 3266 | |
7f0586ef | 3267 | #if !defined(__WXWINCE__) |
574c939e KB |
3268 | case WM_DISPLAYCHANGE: |
3269 | processed = HandleDisplayChange(); | |
3270 | break; | |
7f0586ef | 3271 | #endif |
574c939e | 3272 | |
42e69d6b | 3273 | case WM_PALETTECHANGED: |
dca0f651 | 3274 | processed = HandlePaletteChanged((WXHWND)wParam); |
42e69d6b | 3275 | break; |
2bda0e17 | 3276 | |
a5e84126 | 3277 | case WM_CAPTURECHANGED: |
dca0f651 | 3278 | processed = HandleCaptureChanged((WXHWND)lParam); |
a5e84126 JS |
3279 | break; |
3280 | ||
3c96418b JG |
3281 | case WM_SETTINGCHANGE: |
3282 | processed = HandleSettingChange(wParam, lParam); | |
3283 | break; | |
3284 | ||
42e69d6b VZ |
3285 | case WM_QUERYNEWPALETTE: |
3286 | processed = HandleQueryNewPalette(); | |
3287 | break; | |
2bda0e17 | 3288 | |
42e69d6b | 3289 | case WM_ERASEBKGND: |
bec9bf3e VZ |
3290 | { |
3291 | #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK | |
3292 | // check if an override was configured for this window | |
3293 | EraseBgHooks::const_iterator it = gs_eraseBgHooks.find(this); | |
3294 | if ( it != gs_eraseBgHooks.end() ) | |
3295 | processed = it->second->MSWEraseBgHook((WXHDC)wParam); | |
3296 | else | |
3297 | #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK | |
3298 | processed = HandleEraseBkgnd((WXHDC)wParam); | |
3299 | } | |
3300 | ||
42e69d6b VZ |
3301 | if ( processed ) |
3302 | { | |
3303 | // we processed the message, i.e. erased the background | |
3304 | rc.result = TRUE; | |
3305 | } | |
3306 | break; | |
debe6624 | 3307 | |
7f0586ef | 3308 | #if !defined(__WXWINCE__) |
42e69d6b VZ |
3309 | case WM_DROPFILES: |
3310 | processed = HandleDropFiles(wParam); | |
3311 | break; | |
7f0586ef | 3312 | #endif |
2bda0e17 | 3313 | |
42e69d6b | 3314 | case WM_INITDIALOG: |
dca0f651 | 3315 | processed = HandleInitDialog((WXHWND)wParam); |
a23fd0e1 | 3316 | |
42e69d6b VZ |
3317 | if ( processed ) |
3318 | { | |
3319 | // we never set focus from here | |
3320 | rc.result = FALSE; | |
3321 | } | |
3322 | break; | |
a23fd0e1 | 3323 | |
7f0586ef | 3324 | #if !defined(__WXWINCE__) |
42e69d6b VZ |
3325 | case WM_QUERYENDSESSION: |
3326 | processed = HandleQueryEndSession(lParam, &rc.allow); | |
3327 | break; | |
2bda0e17 | 3328 | |
42e69d6b VZ |
3329 | case WM_ENDSESSION: |
3330 | processed = HandleEndSession(wParam != 0, lParam); | |
3331 | break; | |
2bda0e17 | 3332 | |
42e69d6b | 3333 | case WM_GETMINMAXINFO: |
25889d3c | 3334 | processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam); |
42e69d6b | 3335 | break; |
7f0586ef | 3336 | #endif |
debe6624 | 3337 | |
42e69d6b | 3338 | case WM_SETCURSOR: |
dca0f651 | 3339 | processed = HandleSetCursor((WXHWND)wParam, |
42e69d6b VZ |
3340 | LOWORD(lParam), // hit test |
3341 | HIWORD(lParam)); // mouse msg | |
3342 | ||
3343 | if ( processed ) | |
3344 | { | |
3345 | // returning TRUE stops the DefWindowProc() from further | |
3346 | // processing this message - exactly what we need because we've | |
3347 | // just set the cursor. | |
3348 | rc.result = TRUE; | |
3349 | } | |
3350 | break; | |
4cdc2c13 | 3351 | |
ed5317e5 JS |
3352 | #if wxUSE_ACCESSIBILITY |
3353 | case WM_GETOBJECT: | |
3354 | { | |
3355 | //WPARAM dwFlags = (WPARAM) (DWORD) wParam; | |
3356 | LPARAM dwObjId = (LPARAM) (DWORD) lParam; | |
3357 | ||
66b9ec3d | 3358 | if (dwObjId == (LPARAM)OBJID_CLIENT && GetOrCreateAccessible()) |
ed5317e5 JS |
3359 | { |
3360 | return LresultFromObject(IID_IAccessible, wParam, (IUnknown*) GetAccessible()->GetIAccessible()); | |
3361 | } | |
3362 | break; | |
3363 | } | |
3364 | #endif | |
3365 | ||
e39af974 | 3366 | #if defined(WM_HELP) |
b96340e6 | 3367 | case WM_HELP: |
b96340e6 | 3368 | { |
a9c11b71 VZ |
3369 | // by default, WM_HELP is propagated by DefWindowProc() upwards |
3370 | // to the window parent but as we do it ourselves already | |
3371 | // (wxHelpEvent is derived from wxCommandEvent), we don't want | |
3372 | // to get the other events if we process this message at all | |
3373 | processed = true; | |
3374 | ||
3375 | // WM_HELP doesn't use lParam under CE | |
7f0586ef | 3376 | #ifndef __WXWINCE__ |
4cdc2c13 | 3377 | HELPINFO* info = (HELPINFO*) lParam; |
a9c11b71 | 3378 | if ( info->iContextType == HELPINFO_WINDOW ) |
b96340e6 | 3379 | { |
a9c11b71 VZ |
3380 | #endif // !__WXWINCE__ |
3381 | wxHelpEvent helpEvent | |
3382 | ( | |
3383 | wxEVT_HELP, | |
3384 | GetId(), | |
7f0586ef | 3385 | #ifdef __WXWINCE__ |
2d4ec362 | 3386 | wxGetMousePosition() // what else? |
7f0586ef | 3387 | #else |
a9c11b71 | 3388 | wxPoint(info->MousePos.x, info->MousePos.y) |
7f0586ef | 3389 | #endif |
a9c11b71 | 3390 | ); |
b96340e6 | 3391 | |
a9c11b71 | 3392 | helpEvent.SetEventObject(this); |
937013e0 | 3393 | HandleWindowEvent(helpEvent); |
7f0586ef | 3394 | #ifndef __WXWINCE__ |
b96340e6 | 3395 | } |
a9c11b71 | 3396 | else if ( info->iContextType == HELPINFO_MENUITEM ) |
4cdc2c13 VZ |
3397 | { |
3398 | wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId); | |
3399 | helpEvent.SetEventObject(this); | |
937013e0 | 3400 | HandleWindowEvent(helpEvent); |
69231000 | 3401 | |
4cdc2c13 | 3402 | } |
a9c11b71 VZ |
3403 | else // unknown help event? |
3404 | { | |
3405 | processed = false; | |
3406 | } | |
3407 | #endif // !__WXWINCE__ | |
b96340e6 | 3408 | } |
b96340e6 | 3409 | break; |
a9c11b71 | 3410 | #endif // WM_HELP |
4cdc2c13 | 3411 | |
7f0586ef | 3412 | #if !defined(__WXWINCE__) |
69231000 | 3413 | case WM_CONTEXTMENU: |
4cdc2c13 VZ |
3414 | { |
3415 | // we don't convert from screen to client coordinates as | |
3416 | // the event may be handled by a parent window | |
3417 | wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); | |
3418 | ||
3419 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt); | |
2d1715aa VZ |
3420 | |
3421 | // we could have got an event from our child, reflect it back | |
3422 | // to it if this is the case | |
d85c53a5 | 3423 | wxWindowMSW *win = NULL; |
dca0f651 VZ |
3424 | WXHWND hWnd = (WXHWND)wParam; |
3425 | if ( hWnd != m_hWnd ) | |
2d1715aa | 3426 | { |
dca0f651 | 3427 | win = FindItemByHWND(hWnd); |
2d1715aa VZ |
3428 | } |
3429 | ||
3430 | if ( !win ) | |
3431 | win = this; | |
3432 | ||
3433 | evtCtx.SetEventObject(win); | |
937013e0 | 3434 | processed = win->HandleWindowEvent(evtCtx); |
4cdc2c13 | 3435 | } |
69231000 | 3436 | break; |
7f0586ef | 3437 | #endif |
b74cce40 | 3438 | |
53a118d6 | 3439 | #if wxUSE_MENUS |
b74cce40 VZ |
3440 | case WM_MENUCHAR: |
3441 | // we're only interested in our own menus, not MF_SYSMENU | |
3442 | if ( HIWORD(wParam) == MF_POPUP ) | |
3443 | { | |
3444 | // handle menu chars for ownerdrawn menu items | |
3445 | int i = HandleMenuChar(toupper(LOWORD(wParam)), lParam); | |
3446 | if ( i != wxNOT_FOUND ) | |
3447 | { | |
3448 | rc.result = MAKELRESULT(i, MNC_EXECUTE); | |
08158721 | 3449 | processed = true; |
b74cce40 VZ |
3450 | } |
3451 | } | |
3452 | break; | |
53a118d6 | 3453 | #endif // wxUSE_MENUS |
355debca | 3454 | |
dbc74bcc | 3455 | #ifndef __WXWINCE__ |
355debca VZ |
3456 | case WM_POWERBROADCAST: |
3457 | { | |
3458 | bool vetoed; | |
3459 | processed = HandlePower(wParam, lParam, &vetoed); | |
3460 | rc.result = processed && vetoed ? BROADCAST_QUERY_DENY : TRUE; | |
3461 | } | |
3462 | break; | |
dbc74bcc | 3463 | #endif // __WXWINCE__ |
5acec112 | 3464 | |
a047aff2 JS |
3465 | #if wxUSE_UXTHEME |
3466 | // If we want the default themed border then we need to draw it ourselves | |
3467 | case WM_NCCALCSIZE: | |
3468 | { | |
3469 | wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); | |
dc797d8e JS |
3470 | const wxBorder border = TranslateBorder(GetBorder()); |
3471 | if (theme && border == wxBORDER_THEME) | |
a047aff2 JS |
3472 | { |
3473 | // first ask the widget to calculate the border size | |
3474 | rc.result = MSWDefWindowProc(message, wParam, lParam); | |
3475 | processed = true; | |
3476 | ||
e822d1bd VZ |
3477 | // now alter the client size making room for drawing a |
3478 | // themed border | |
dca0f651 | 3479 | RECT *rect; |
140d93c0 | 3480 | NCCALCSIZE_PARAMS *csparam = NULL; |
dca0f651 | 3481 | if ( wParam ) |
a047aff2 | 3482 | { |
140d93c0 | 3483 | csparam = (NCCALCSIZE_PARAMS *)lParam; |
dca0f651 | 3484 | rect = &csparam->rgrc[0]; |
a047aff2 JS |
3485 | } |
3486 | else | |
3487 | { | |
dca0f651 | 3488 | rect = (RECT *)lParam; |
a047aff2 | 3489 | } |
dca0f651 | 3490 | |
fe545198 | 3491 | wxUxThemeHandle hTheme((const wxWindow *)this, L"EDIT"); |
a047aff2 | 3492 | RECT rcClient = { 0, 0, 0, 0 }; |
d935b421 | 3493 | wxClientDC dc((wxWindow *)this); |
888dde65 | 3494 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
a047aff2 | 3495 | |
dca0f651 VZ |
3496 | if ( theme->GetThemeBackgroundContentRect |
3497 | ( | |
3498 | hTheme, | |
3499 | GetHdcOf(*impl), | |
3500 | EP_EDITTEXT, | |
3501 | ETS_NORMAL, | |
3502 | rect, | |
3503 | &rcClient) == S_OK ) | |
a047aff2 JS |
3504 | { |
3505 | InflateRect(&rcClient, -1, -1); | |
140d93c0 JS |
3506 | if (wParam) |
3507 | csparam->rgrc[0] = rcClient; | |
3508 | else | |
3509 | *((RECT*)lParam) = rcClient; | |
3510 | ||
3511 | // WVR_REDRAW triggers a bug whereby child windows are moved up and left, | |
3512 | // so don't use. | |
3513 | // rc.result = WVR_REDRAW; | |
a047aff2 JS |
3514 | } |
3515 | } | |
3516 | } | |
3517 | break; | |
3518 | ||
3519 | case WM_NCPAINT: | |
3520 | { | |
3521 | wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); | |
dc797d8e JS |
3522 | const wxBorder border = TranslateBorder(GetBorder()); |
3523 | if (theme && border == wxBORDER_THEME) | |
a047aff2 JS |
3524 | { |
3525 | // first ask the widget to paint its non-client area, such as scrollbars, etc. | |
3526 | rc.result = MSWDefWindowProc(message, wParam, lParam); | |
3527 | processed = true; | |
3528 | ||
fe545198 | 3529 | wxUxThemeHandle hTheme((const wxWindow *)this, L"EDIT"); |
d935b421 | 3530 | wxWindowDC dc((wxWindow *)this); |
888dde65 | 3531 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
a047aff2 JS |
3532 | |
3533 | // Clip the DC so that you only draw on the non-client area | |
3534 | RECT rcBorder; | |
3535 | wxCopyRectToRECT(GetSize(), rcBorder); | |
3536 | ||
3537 | RECT rcClient; | |
3538 | theme->GetThemeBackgroundContentRect( | |
888dde65 | 3539 | hTheme, GetHdcOf(*impl), EP_EDITTEXT, ETS_NORMAL, &rcBorder, &rcClient); |
a047aff2 JS |
3540 | InflateRect(&rcClient, -1, -1); |
3541 | ||
888dde65 | 3542 | ::ExcludeClipRect(GetHdcOf(*impl), rcClient.left, rcClient.top, |
a047aff2 JS |
3543 | rcClient.right, rcClient.bottom); |
3544 | ||
3545 | // Make sure the background is in a proper state | |
3546 | if (theme->IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL)) | |
3547 | { | |
888dde65 | 3548 | theme->DrawThemeParentBackground(GetHwnd(), GetHdcOf(*impl), &rcBorder); |
a047aff2 JS |
3549 | } |
3550 | ||
3551 | // Draw the border | |
3552 | int nState; | |
3553 | if ( !IsEnabled() ) | |
3554 | nState = ETS_DISABLED; | |
3555 | // should we check this? | |
3556 | //else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY) | |
3557 | // nState = ETS_READONLY; | |
3558 | else | |
3559 | nState = ETS_NORMAL; | |
888dde65 | 3560 | theme->DrawThemeBackground(hTheme, GetHdcOf(*impl), EP_EDITTEXT, nState, &rcBorder, NULL); |
a047aff2 JS |
3561 | } |
3562 | } | |
3563 | break; | |
3564 | ||
3565 | #endif // wxUSE_UXTHEME | |
3566 | ||
5acec112 VZ |
3567 | default: |
3568 | // try a custom message handler | |
3569 | const MSWMessageHandlers::const_iterator | |
3570 | i = gs_messageHandlers.find(message); | |
3571 | if ( i != gs_messageHandlers.end() ) | |
3572 | { | |
3573 | processed = (*i->second)(this, message, wParam, lParam); | |
3574 | } | |
a23fd0e1 | 3575 | } |
2d0a075d | 3576 | |
42e69d6b | 3577 | if ( !processed ) |
2d0a075d | 3578 | { |
4b6a582b | 3579 | #if wxDEBUG_LEVEL >= 2 |
5ec3853f | 3580 | wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."), |
42e69d6b | 3581 | wxGetMessageName(message)); |
4b6a582b | 3582 | #endif // wxDEBUG_LEVEL >= 2 |
42e69d6b | 3583 | rc.result = MSWDefWindowProc(message, wParam, lParam); |
a23fd0e1 | 3584 | } |
2bda0e17 | 3585 | |
42e69d6b | 3586 | return rc.result; |
2bda0e17 KB |
3587 | } |
3588 | ||
b225f659 VZ |
3589 | // ---------------------------------------------------------------------------- |
3590 | // wxWindow <-> HWND map | |
3591 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 3592 | |
dca0f651 | 3593 | wxWindow *wxFindWinFromHandle(HWND hwnd) |
4ce81a75 | 3594 | { |
dca0f651 VZ |
3595 | WindowHandles::const_iterator i = gs_windowHandles.find(hwnd); |
3596 | return i == gs_windowHandles.end() ? NULL : i->second; | |
42e69d6b | 3597 | } |
4ce81a75 | 3598 | |
dca0f651 | 3599 | void wxAssociateWinWithHandle(HWND hwnd, wxWindowMSW *win) |
42e69d6b | 3600 | { |
dca0f651 | 3601 | // adding NULL hwnd is (first) surely a result of an error and |
42e69d6b | 3602 | // (secondly) breaks menu command processing |
dca0f651 VZ |
3603 | wxCHECK_RET( hwnd != (HWND)NULL, |
3604 | wxT("attempt to add a NULL hwnd to window list ignored") ); | |
4ce81a75 | 3605 | |
4b6a582b | 3606 | #if wxDEBUG_LEVEL |
dca0f651 VZ |
3607 | WindowHandles::const_iterator i = gs_windowHandles.find(hwnd); |
3608 | if ( i != gs_windowHandles.end() ) | |
c7527e3f | 3609 | { |
dca0f651 VZ |
3610 | if ( i->second != win ) |
3611 | { | |
4b6a582b VZ |
3612 | wxFAIL_MSG( |
3613 | wxString::Format( | |
3614 | wxT("HWND %p already associated with another window (%s)"), | |
3615 | hwnd, win->GetClassInfo()->GetClassName() | |
3616 | ) | |
3617 | ); | |
dca0f651 VZ |
3618 | } |
3619 | //else: this actually happens currently because we associate the window | |
3620 | // with its HWND during creation (if we create it) and also when | |
3621 | // SubclassWin() is called later, this is ok | |
c7527e3f | 3622 | } |
4b6a582b | 3623 | #endif // wxDEBUG_LEVEL |
dca0f651 | 3624 | |
936bb82e | 3625 | gs_windowHandles[hwnd] = (wxWindow *)win; |
42e69d6b | 3626 | } |
4ce81a75 | 3627 | |
1e6feb95 | 3628 | void wxRemoveHandleAssociation(wxWindowMSW *win) |
42e69d6b | 3629 | { |
dca0f651 | 3630 | gs_windowHandles.erase(GetHwndOf(win)); |
4ce81a75 JS |
3631 | } |
3632 | ||
b225f659 VZ |
3633 | // ---------------------------------------------------------------------------- |
3634 | // various MSW speciic class dependent functions | |
3635 | // ---------------------------------------------------------------------------- | |
3636 | ||
42e69d6b VZ |
3637 | // Default destroyer - override if you destroy it in some other way |
3638 | // (e.g. with MDI child windows) | |
1e6feb95 | 3639 | void wxWindowMSW::MSWDestroyWindow() |
4ce81a75 | 3640 | { |
42e69d6b | 3641 | } |
4ce81a75 | 3642 | |
b225f659 VZ |
3643 | bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos, |
3644 | const wxSize& size, | |
3645 | int& x, int& y, | |
3646 | int& w, int& h) const | |
2bda0e17 | 3647 | { |
9cb57df4 | 3648 | // yes, those are just some arbitrary hardcoded numbers |
2a77c8c4 | 3649 | static const int DEFAULT_Y = 200; |
2a77c8c4 | 3650 | |
08158721 | 3651 | bool nonDefault = false; |
c085e333 | 3652 | |
422d0ff0 | 3653 | if ( pos.x == wxDefaultCoord ) |
b225f659 | 3654 | { |
9cb57df4 VZ |
3655 | // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we |
3656 | // can just as well set it to CW_USEDEFAULT as well | |
b225f659 VZ |
3657 | x = |
3658 | y = CW_USEDEFAULT; | |
3659 | } | |
3660 | else | |
a23fd0e1 | 3661 | { |
2a77c8c4 VZ |
3662 | // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it |
3663 | // neither because it is not handled as a special value by Windows then | |
3664 | // and so we have to choose some default value for it | |
b225f659 | 3665 | x = pos.x; |
422d0ff0 | 3666 | y = pos.y == wxDefaultCoord ? DEFAULT_Y : pos.y; |
c085e333 | 3667 | |
08158721 | 3668 | nonDefault = true; |
42e69d6b | 3669 | } |
2bda0e17 | 3670 | |
b889a3a2 VZ |
3671 | /* |
3672 | NB: there used to be some code here which set the initial size of the | |
3673 | window to the client size of the parent if no explicit size was | |
77ffb593 | 3674 | specified. This was wrong because wxWidgets programs often assume |
b889a3a2 VZ |
3675 | that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke |
3676 | it. To see why, you should understand that Windows sends WM_SIZE from | |
3677 | inside ::CreateWindow() anyhow. However, ::CreateWindow() is called | |
3678 | from some base class ctor and so this WM_SIZE is not processed in the | |
3679 | real class' OnSize() (because it's not fully constructed yet and the | |
3680 | event goes to some base class OnSize() instead). So the WM_SIZE we | |
3681 | rely on is the one sent when the parent frame resizes its children | |
3682 | but here is the problem: if the child already has just the right | |
77ffb593 | 3683 | size, nothing will happen as both wxWidgets and Windows check for |
b889a3a2 VZ |
3684 | this and ignore any attempts to change the window size to the size it |
3685 | already has - so no WM_SIZE would be sent. | |
3686 | */ | |
b225f659 | 3687 | |
35bbb0c6 | 3688 | |
426936d1 RD |
3689 | // we don't use CW_USEDEFAULT here for several reasons: |
3690 | // | |
3691 | // 1. it results in huge frames on modern screens (1000*800 is not | |
3692 | // uncommon on my 1280*1024 screen) which is way too big for a half | |
77ffb593 | 3693 | // empty frame of most of wxWidgets samples for example) |
426936d1 RD |
3694 | // |
3695 | // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which | |
3696 | // the default is for whatever reason 8*8 which breaks client <-> | |
3697 | // window size calculations (it would be nice if it didn't, but it | |
3698 | // does and the simplest way to fix it seemed to change the broken | |
3699 | // default size anyhow) | |
3700 | // | |
3701 | // 3. there is just no advantage in doing it: with x and y it is | |
3702 | // possible that [future versions of] Windows position the new top | |
3703 | // level window in some smart way which we can't do, but we can | |
3704 | // guess a reasonably good size for a new window just as well | |
3705 | // ourselves | |
960b193e | 3706 | |
3a3c8603 DS |
3707 | // However, on PocketPC devices, we must use the default |
3708 | // size if possible. | |
960b193e | 3709 | #ifdef _WIN32_WCE |
422d0ff0 | 3710 | if (size.x == wxDefaultCoord) |
3a3c8603 DS |
3711 | w = CW_USEDEFAULT; |
3712 | else | |
3713 | w = size.x; | |
422d0ff0 | 3714 | if (size.y == wxDefaultCoord) |
3a3c8603 DS |
3715 | h = CW_USEDEFAULT; |
3716 | else | |
3717 | h = size.y; | |
960b193e | 3718 | #else |
422d0ff0 | 3719 | if ( size.x == wxDefaultCoord || size.y == wxDefaultCoord) |
426936d1 | 3720 | { |
08158721 | 3721 | nonDefault = true; |
8614c467 | 3722 | } |
426936d1 RD |
3723 | w = WidthDefault(size.x); |
3724 | h = HeightDefault(size.y); | |
960b193e | 3725 | #endif |
8614c467 | 3726 | |
4e9d23cd VZ |
3727 | AdjustForParentClientOrigin(x, y); |
3728 | ||
b225f659 VZ |
3729 | return nonDefault; |
3730 | } | |
3731 | ||
9dfef5ac VZ |
3732 | WXHWND wxWindowMSW::MSWGetParent() const |
3733 | { | |
d285d708 | 3734 | return m_parent ? m_parent->GetHWND() : WXHWND(NULL); |
9dfef5ac VZ |
3735 | } |
3736 | ||
b225f659 VZ |
3737 | bool wxWindowMSW::MSWCreate(const wxChar *wclass, |
3738 | const wxChar *title, | |
3739 | const wxPoint& pos, | |
3740 | const wxSize& size, | |
3741 | WXDWORD style, | |
3742 | WXDWORD extendedStyle) | |
3743 | { | |
23035521 VZ |
3744 | // check a common bug in the user code: if the window is created with a |
3745 | // non-default ctor and Create() is called too, we'd create 2 HWND for a | |
3746 | // single wxWindow object and this results in all sorts of trouble, | |
3747 | // especially for wxTLWs | |
3748 | wxCHECK_MSG( !m_hWnd, true, "window can't be recreated" ); | |
3749 | ||
d9698bd4 VZ |
3750 | // this can happen if this function is called using the return value of |
3751 | // wxApp::GetRegisteredClassName() which failed | |
3752 | wxCHECK_MSG( wclass, false, "failed to register window class?" ); | |
3753 | ||
3754 | ||
b225f659 VZ |
3755 | // choose the position/size for the new window |
3756 | int x, y, w, h; | |
3757 | (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h); | |
3758 | ||
b225f659 VZ |
3759 | // controlId is menu handle for the top level windows, so set it to 0 |
3760 | // unless we're creating a child window | |
f586fde3 | 3761 | int controlId = style & WS_CHILD ? GetId() : 0; |
2bda0e17 | 3762 | |
b225f659 VZ |
3763 | // for each class "Foo" we have we also have "FooNR" ("no repaint") class |
3764 | // which is the same but without CS_[HV]REDRAW class styles so using it | |
3765 | // ensures that the window is not fully repainted on each resize | |
3766 | wxString className(wclass); | |
e441e1f4 | 3767 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) |
b225f659 | 3768 | { |
d9698bd4 | 3769 | className += wxApp::GetNoRedrawClassSuffix(); |
a23fd0e1 | 3770 | } |
c085e333 | 3771 | |
b225f659 VZ |
3772 | // do create the window |
3773 | wxWindowCreationHook hook(this); | |
b3daa5a3 | 3774 | |
5e67eb97 VZ |
3775 | m_hWnd = (WXHWND)::CreateWindowEx |
3776 | ( | |
3777 | extendedStyle, | |
e0a050e3 VS |
3778 | className.wx_str(), |
3779 | title ? title : m_windowName.wx_str(), | |
5e67eb97 VZ |
3780 | style, |
3781 | x, y, w, h, | |
3782 | (HWND)MSWGetParent(), | |
dca0f651 | 3783 | (HMENU)wxUIntToPtr(controlId), |
5e67eb97 VZ |
3784 | wxGetInstance(), |
3785 | NULL // no extra data | |
3786 | ); | |
b225f659 VZ |
3787 | |
3788 | if ( !m_hWnd ) | |
c7527e3f | 3789 | { |
5e67eb97 | 3790 | wxLogSysError(_("Can't create window of class %s"), className.c_str()); |
b225f659 | 3791 | |
08158721 | 3792 | return false; |
c7527e3f | 3793 | } |
b3daa5a3 | 3794 | |
b225f659 | 3795 | SubclassWin(m_hWnd); |
c085e333 | 3796 | |
08158721 | 3797 | return true; |
2bda0e17 KB |
3798 | } |
3799 | ||
42e69d6b VZ |
3800 | // =========================================================================== |
3801 | // MSW message handlers | |
3802 | // =========================================================================== | |
3803 | ||
3804 | // --------------------------------------------------------------------------- | |
3805 | // WM_NOTIFY | |
3806 | // --------------------------------------------------------------------------- | |
3807 | ||
1e6feb95 | 3808 | bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
2bda0e17 | 3809 | { |
04ef50df | 3810 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
3811 | LPNMHDR hdr = (LPNMHDR)lParam; |
3812 | HWND hWnd = hdr->hwndFrom; | |
dca0f651 | 3813 | wxWindow *win = wxFindWinFromHandle(hWnd); |
42e69d6b | 3814 | |
2b15b970 | 3815 | // if the control is one of our windows, let it handle the message itself |
42e69d6b | 3816 | if ( win ) |
564b2609 | 3817 | { |
42e69d6b | 3818 | return win->MSWOnNotify(idCtrl, lParam, result); |
564b2609 | 3819 | } |
2bda0e17 | 3820 | |
2b15b970 VZ |
3821 | // VZ: why did we do it? normally this is unnecessary and, besides, it |
3822 | // breaks the message processing for the toolbars because the tooltip | |
3823 | // notifications were being forwarded to the toolbar child controls | |
3824 | // (if it had any) before being passed to the toolbar itself, so in my | |
3825 | // example the tooltip for the combobox was always shown instead of the | |
3826 | // correct button tooltips | |
3827 | #if 0 | |
42e69d6b | 3828 | // try all our children |
222ed1d6 | 3829 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
42e69d6b | 3830 | while ( node ) |
564b2609 | 3831 | { |
42e69d6b VZ |
3832 | wxWindow *child = node->GetData(); |
3833 | if ( child->MSWOnNotify(idCtrl, lParam, result) ) | |
3834 | { | |
08158721 | 3835 | return true; |
42e69d6b | 3836 | } |
2d0a075d | 3837 | |
42e69d6b VZ |
3838 | node = node->GetNext(); |
3839 | } | |
2b15b970 | 3840 | #endif // 0 |
2d0a075d | 3841 | |
2b15b970 | 3842 | // by default, handle it ourselves |
42e69d6b | 3843 | return MSWOnNotify(idCtrl, lParam, result); |
cd4453e5 | 3844 | #else // __WXMICROWIN__ |
08158721 | 3845 | return false; |
04ef50df | 3846 | #endif |
42e69d6b | 3847 | } |
2d0a075d | 3848 | |
bd9cd534 VZ |
3849 | #if wxUSE_TOOLTIPS |
3850 | ||
3851 | bool wxWindowMSW::HandleTooltipNotify(WXUINT code, | |
3852 | WXLPARAM lParam, | |
3853 | const wxString& ttip) | |
3854 | { | |
3855 | // I don't know why it happens, but the versions of comctl32.dll starting | |
3856 | // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally, | |
3857 | // this message is supposed to be sent to Unicode programs only) -- hence | |
3858 | // we need to handle it as well, otherwise no tooltips will be shown in | |
3859 | // this case | |
7f0586ef | 3860 | #ifndef __WXWINCE__ |
118208ac VZ |
3861 | if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW) |
3862 | || ttip.empty() ) | |
bd9cd534 VZ |
3863 | { |
3864 | // not a tooltip message or no tooltip to show anyhow | |
08158721 | 3865 | return false; |
bd9cd534 | 3866 | } |
7f0586ef | 3867 | #endif |
bd9cd534 VZ |
3868 | |
3869 | LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam; | |
3870 | ||
118208ac VZ |
3871 | // We don't want to use the szText buffer because it has a limit of 80 |
3872 | // bytes and this is not enough, especially for Unicode build where it | |
3873 | // limits the tooltip string length to only 40 characters | |
3874 | // | |
3875 | // The best would be, of course, to not impose any length limitations at | |
3876 | // all but then the buffer would have to be dynamic and someone would have | |
3877 | // to free it and we don't have the tooltip owner object here any more, so | |
3878 | // for now use our own static buffer with a higher fixed max length. | |
3879 | // | |
3880 | // Note that using a static buffer should not be a problem as only a single | |
3881 | // tooltip can be shown at the same time anyhow. | |
2b5f62a0 | 3882 | #if !wxUSE_UNICODE |
118208ac | 3883 | if ( code == (WXUINT) TTN_NEEDTEXTW ) |
bd9cd534 | 3884 | { |
118208ac VZ |
3885 | // We need to convert tooltip from multi byte to Unicode on the fly. |
3886 | static wchar_t buf[513]; | |
25c46fda | 3887 | |
118208ac VZ |
3888 | // Truncate tooltip length if needed as otherwise we might not have |
3889 | // enough space for it in the buffer and MultiByteToWideChar() would | |
3890 | // return an error | |
fec9cc08 | 3891 | size_t tipLength = wxMin(ttip.length(), WXSIZEOF(buf) - 1); |
7afebc8c JS |
3892 | |
3893 | // Convert to WideChar without adding the NULL character. The NULL | |
25c46fda | 3894 | // character is added afterwards (this is more efficient). |
118208ac VZ |
3895 | int len = ::MultiByteToWideChar |
3896 | ( | |
3897 | CP_ACP, | |
3898 | 0, // no flags | |
b05fde97 | 3899 | ttip.wx_str(), |
118208ac VZ |
3900 | tipLength, |
3901 | buf, | |
3902 | WXSIZEOF(buf) - 1 | |
3903 | ); | |
3904 | ||
3905 | if ( !len ) | |
3906 | { | |
9a83f860 | 3907 | wxLogLastError(wxT("MultiByteToWideChar()")); |
118208ac | 3908 | } |
7afebc8c | 3909 | |
118208ac VZ |
3910 | buf[len] = L'\0'; |
3911 | ttText->lpszText = (LPSTR) buf; | |
3912 | } | |
3913 | else // TTN_NEEDTEXTA | |
3914 | #endif // !wxUSE_UNICODE | |
3915 | { | |
3916 | // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or | |
3917 | // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have | |
3918 | // to copy the string we have into the buffer | |
3919 | static wxChar buf[513]; | |
e408bf52 | 3920 | wxStrlcpy(buf, ttip.c_str(), WXSIZEOF(buf)); |
118208ac | 3921 | ttText->lpszText = buf; |
bd9cd534 VZ |
3922 | } |
3923 | ||
08158721 | 3924 | return true; |
bd9cd534 VZ |
3925 | } |
3926 | ||
3927 | #endif // wxUSE_TOOLTIPS | |
3928 | ||
1e6feb95 | 3929 | bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl), |
bd9cd534 VZ |
3930 | WXLPARAM lParam, |
3931 | WXLPARAM* WXUNUSED(result)) | |
42e69d6b VZ |
3932 | { |
3933 | #if wxUSE_TOOLTIPS | |
bd9cd534 | 3934 | if ( m_tooltip ) |
42e69d6b | 3935 | { |
bd9cd534 VZ |
3936 | NMHDR* hdr = (NMHDR *)lParam; |
3937 | if ( HandleTooltipNotify(hdr->code, lParam, m_tooltip->GetTip())) | |
3938 | { | |
3939 | // processed | |
08158721 | 3940 | return true; |
bd9cd534 | 3941 | } |
42e69d6b | 3942 | } |
f5dd1cf1 WS |
3943 | #else |
3944 | wxUnusedVar(lParam); | |
42e69d6b VZ |
3945 | #endif // wxUSE_TOOLTIPS |
3946 | ||
08158721 | 3947 | return false; |
42e69d6b | 3948 | } |
2b15b970 | 3949 | |
42e69d6b VZ |
3950 | // --------------------------------------------------------------------------- |
3951 | // end session messages | |
3952 | // --------------------------------------------------------------------------- | |
2d0a075d | 3953 | |
1e6feb95 | 3954 | bool wxWindowMSW::HandleQueryEndSession(long logOff, bool *mayEnd) |
42e69d6b | 3955 | { |
040e5f77 | 3956 | #ifdef ENDSESSION_LOGOFF |
abb74e0f | 3957 | wxCloseEvent event(wxEVT_QUERY_END_SESSION, wxID_ANY); |
42e69d6b | 3958 | event.SetEventObject(wxTheApp); |
08158721 | 3959 | event.SetCanVeto(true); |
a17e237f | 3960 | event.SetLoggingOff(logOff == (long)ENDSESSION_LOGOFF); |
2d0a075d | 3961 | |
42e69d6b VZ |
3962 | bool rc = wxTheApp->ProcessEvent(event); |
3963 | ||
3964 | if ( rc ) | |
3965 | { | |
3966 | // we may end only if the app didn't veto session closing (double | |
3967 | // negation...) | |
3968 | *mayEnd = !event.GetVeto(); | |
2d0a075d JS |
3969 | } |
3970 | ||
42e69d6b | 3971 | return rc; |
7f0586ef | 3972 | #else |
040e5f77 VZ |
3973 | wxUnusedVar(logOff); |
3974 | wxUnusedVar(mayEnd); | |
08158721 | 3975 | return false; |
7f0586ef | 3976 | #endif |
2bda0e17 KB |
3977 | } |
3978 | ||
1e6feb95 | 3979 | bool wxWindowMSW::HandleEndSession(bool endSession, long logOff) |
2bda0e17 | 3980 | { |
040e5f77 | 3981 | #ifdef ENDSESSION_LOGOFF |
42e69d6b VZ |
3982 | // do nothing if the session isn't ending |
3983 | if ( !endSession ) | |
08158721 | 3984 | return false; |
a23fd0e1 | 3985 | |
519dc37f VZ |
3986 | // only send once |
3987 | if ( (this != wxTheApp->GetTopWindow()) ) | |
08158721 | 3988 | return false; |
519dc37f | 3989 | |
abb74e0f | 3990 | wxCloseEvent event(wxEVT_END_SESSION, wxID_ANY); |
42e69d6b | 3991 | event.SetEventObject(wxTheApp); |
08158721 | 3992 | event.SetCanVeto(false); |
f801d19a | 3993 | event.SetLoggingOff((logOff & ENDSESSION_LOGOFF) != 0); |
519dc37f VZ |
3994 | |
3995 | return wxTheApp->ProcessEvent(event); | |
7f0586ef | 3996 | #else |
040e5f77 VZ |
3997 | wxUnusedVar(endSession); |
3998 | wxUnusedVar(logOff); | |
08158721 | 3999 | return false; |
7f0586ef | 4000 | #endif |
2bda0e17 KB |
4001 | } |
4002 | ||
42e69d6b VZ |
4003 | // --------------------------------------------------------------------------- |
4004 | // window creation/destruction | |
4005 | // --------------------------------------------------------------------------- | |
4006 | ||
0c0d1521 WS |
4007 | bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT WXUNUSED_IN_WINCE(cs), |
4008 | bool *mayCreate) | |
61179e28 | 4009 | { |
ee471817 VZ |
4010 | // VZ: why is this commented out for WinCE? If it doesn't support |
4011 | // WS_EX_CONTROLPARENT at all it should be somehow handled globally, | |
4012 | // not with multiple #ifdef's! | |
7f0586ef | 4013 | #ifndef __WXWINCE__ |
61179e28 | 4014 | if ( ((CREATESTRUCT *)cs)->dwExStyle & WS_EX_CONTROLPARENT ) |
ee471817 VZ |
4015 | EnsureParentHasControlParentStyle(GetParent()); |
4016 | #endif // !__WXWINCE__ | |
61179e28 | 4017 | |
08158721 | 4018 | *mayCreate = true; |
42e69d6b | 4019 | |
08158721 | 4020 | return true; |
2bda0e17 KB |
4021 | } |
4022 | ||
1e6feb95 | 4023 | bool wxWindowMSW::HandleDestroy() |
2bda0e17 | 4024 | { |
42e69d6b VZ |
4025 | // delete our drop target if we've got one |
4026 | #if wxUSE_DRAG_AND_DROP | |
4027 | if ( m_dropTarget != NULL ) | |
2d0a075d | 4028 | { |
42e69d6b VZ |
4029 | m_dropTarget->Revoke(m_hWnd); |
4030 | ||
4031 | delete m_dropTarget; | |
4032 | m_dropTarget = NULL; | |
2d0a075d | 4033 | } |
42e69d6b | 4034 | #endif // wxUSE_DRAG_AND_DROP |
2bda0e17 | 4035 | |
42e69d6b | 4036 | // WM_DESTROY handled |
08158721 | 4037 | return true; |
2bda0e17 KB |
4038 | } |
4039 | ||
42e69d6b VZ |
4040 | // --------------------------------------------------------------------------- |
4041 | // activation/focus | |
4042 | // --------------------------------------------------------------------------- | |
4043 | ||
1e6feb95 | 4044 | bool wxWindowMSW::HandleActivate(int state, |
42e69d6b VZ |
4045 | bool WXUNUSED(minimized), |
4046 | WXHWND WXUNUSED(activate)) | |
2bda0e17 | 4047 | { |
42e69d6b VZ |
4048 | wxActivateEvent event(wxEVT_ACTIVATE, |
4049 | (state == WA_ACTIVE) || (state == WA_CLICKACTIVE), | |
4050 | m_windowId); | |
4051 | event.SetEventObject(this); | |
4052 | ||
937013e0 | 4053 | return HandleWindowEvent(event); |
42e69d6b VZ |
4054 | } |
4055 | ||
1e6feb95 | 4056 | bool wxWindowMSW::HandleSetFocus(WXHWND hwnd) |
42e69d6b | 4057 | { |
c7aee865 RD |
4058 | // Strangly enough, some controls get set focus events when they are being |
4059 | // deleted, even if they already had focus before. | |
4060 | if ( m_isBeingDeleted ) | |
4061 | { | |
4062 | return false; | |
4063 | } | |
35bbb0c6 | 4064 | |
456bc6d9 VZ |
4065 | // notify the parent keeping track of focus for the kbd navigation |
4066 | // purposes that we got it | |
e72aa7f5 | 4067 | wxChildFocusEvent eventFocus((wxWindow *)this); |
937013e0 | 4068 | (void)HandleWindowEvent(eventFocus); |
456bc6d9 | 4069 | |
789295bf | 4070 | #if wxUSE_CARET |
42e69d6b | 4071 | // Deal with caret |
789295bf | 4072 | if ( m_caret ) |
2d0a075d | 4073 | { |
789295bf | 4074 | m_caret->OnSetFocus(); |
2bda0e17 | 4075 | } |
789295bf | 4076 | #endif // wxUSE_CARET |
42e69d6b | 4077 | |
42e69d6b VZ |
4078 | wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); |
4079 | event.SetEventObject(this); | |
4080 | ||
1e6feb95 VZ |
4081 | // wxFindWinFromHandle() may return NULL, it is ok |
4082 | event.SetWindow(wxFindWinFromHandle(hwnd)); | |
4083 | ||
937013e0 | 4084 | return HandleWindowEvent(event); |
2bda0e17 KB |
4085 | } |
4086 | ||
1e6feb95 | 4087 | bool wxWindowMSW::HandleKillFocus(WXHWND hwnd) |
2bda0e17 | 4088 | { |
789295bf | 4089 | #if wxUSE_CARET |
42e69d6b | 4090 | // Deal with caret |
789295bf | 4091 | if ( m_caret ) |
2d0a075d | 4092 | { |
789295bf | 4093 | m_caret->OnKillFocus(); |
2bda0e17 | 4094 | } |
789295bf | 4095 | #endif // wxUSE_CARET |
42e69d6b | 4096 | |
2913e597 RD |
4097 | // Don't send the event when in the process of being deleted. This can |
4098 | // only cause problems if the event handler tries to access the object. | |
4099 | if ( m_isBeingDeleted ) | |
4100 | { | |
08158721 | 4101 | return false; |
2913e597 RD |
4102 | } |
4103 | ||
42e69d6b VZ |
4104 | wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId); |
4105 | event.SetEventObject(this); | |
4106 | ||
1e6feb95 VZ |
4107 | // wxFindWinFromHandle() may return NULL, it is ok |
4108 | event.SetWindow(wxFindWinFromHandle(hwnd)); | |
4109 | ||
937013e0 | 4110 | return HandleWindowEvent(event); |
2bda0e17 KB |
4111 | } |
4112 | ||
faa49bfd WS |
4113 | // --------------------------------------------------------------------------- |
4114 | // labels | |
4115 | // --------------------------------------------------------------------------- | |
4116 | ||
4117 | void wxWindowMSW::SetLabel( const wxString& label) | |
4118 | { | |
4119 | SetWindowText(GetHwnd(), label.c_str()); | |
4120 | } | |
4121 | ||
4122 | wxString wxWindowMSW::GetLabel() const | |
4123 | { | |
4124 | return wxGetWindowText(GetHWND()); | |
4125 | } | |
4126 | ||
42e69d6b VZ |
4127 | // --------------------------------------------------------------------------- |
4128 | // miscellaneous | |
4129 | // --------------------------------------------------------------------------- | |
4130 | ||
1e6feb95 | 4131 | bool wxWindowMSW::HandleShow(bool show, int WXUNUSED(status)) |
2bda0e17 | 4132 | { |
42e69d6b | 4133 | wxShowEvent event(GetId(), show); |
687706f5 | 4134 | event.SetEventObject(this); |
42e69d6b | 4135 | |
937013e0 | 4136 | return HandleWindowEvent(event); |
2bda0e17 KB |
4137 | } |
4138 | ||
1e6feb95 | 4139 | bool wxWindowMSW::HandleInitDialog(WXHWND WXUNUSED(hWndFocus)) |
2bda0e17 | 4140 | { |
42e69d6b | 4141 | wxInitDialogEvent event(GetId()); |
687706f5 | 4142 | event.SetEventObject(this); |
42e69d6b | 4143 | |
937013e0 | 4144 | return HandleWindowEvent(event); |
2bda0e17 KB |
4145 | } |
4146 | ||
1e6feb95 | 4147 | bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam) |
2bda0e17 | 4148 | { |
7f0586ef | 4149 | #if defined (__WXMICROWIN__) || defined(__WXWINCE__) |
35bbb0c6 | 4150 | wxUnusedVar(wParam); |
08158721 | 4151 | return false; |
4ce1efe1 | 4152 | #else // __WXMICROWIN__ |
42e69d6b | 4153 | HDROP hFilesInfo = (HDROP) wParam; |
42e69d6b VZ |
4154 | |
4155 | // Get the total number of files dropped | |
c3c39620 | 4156 | UINT gwFilesDropped = ::DragQueryFile |
f6bcfd97 BP |
4157 | ( |
4158 | (HDROP)hFilesInfo, | |
4159 | (UINT)-1, | |
4160 | (LPTSTR)0, | |
4161 | (UINT)0 | |
4162 | ); | |
42e69d6b VZ |
4163 | |
4164 | wxString *files = new wxString[gwFilesDropped]; | |
c3c39620 | 4165 | for ( UINT wIndex = 0; wIndex < gwFilesDropped; wIndex++ ) |
2d0a075d | 4166 | { |
c3c39620 VZ |
4167 | // first get the needed buffer length (+1 for terminating NUL) |
4168 | size_t len = ::DragQueryFile(hFilesInfo, wIndex, NULL, 0) + 1; | |
4169 | ||
4170 | // and now get the file name | |
4171 | ::DragQueryFile(hFilesInfo, wIndex, | |
de564874 | 4172 | wxStringBuffer(files[wIndex], len), len); |
2d0a075d | 4173 | } |
2bda0e17 | 4174 | |
42e69d6b | 4175 | wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files); |
687706f5 | 4176 | event.SetEventObject(this); |
c3c39620 VZ |
4177 | |
4178 | POINT dropPoint; | |
4179 | DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint); | |
b3dc8a3e VZ |
4180 | event.m_pos.x = dropPoint.x; |
4181 | event.m_pos.y = dropPoint.y; | |
42e69d6b | 4182 | |
fe8f9ad7 VZ |
4183 | DragFinish(hFilesInfo); |
4184 | ||
937013e0 | 4185 | return HandleWindowEvent(event); |
04ef50df | 4186 | #endif |
2bda0e17 KB |
4187 | } |
4188 | ||
cc972ac6 | 4189 | |
1e6feb95 VZ |
4190 | bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd), |
4191 | short nHitTest, | |
4192 | int WXUNUSED(mouseMsg)) | |
2bda0e17 | 4193 | { |
04ef50df | 4194 | #ifndef __WXMICROWIN__ |
bfbd6dc1 | 4195 | // the logic is as follows: |
46753a7c VZ |
4196 | // 0. if we're busy, set the busy cursor (even for non client elements) |
4197 | // 1. don't set custom cursor for non client area of enabled windows | |
4198 | // 2. ask user EVT_SET_CURSOR handler for the cursor | |
4199 | // 3. if still no cursor but we're in a TLW, set the global cursor | |
42e69d6b | 4200 | |
46753a7c VZ |
4201 | HCURSOR hcursor = 0; |
4202 | if ( wxIsBusy() ) | |
43b5058d | 4203 | { |
46753a7c | 4204 | hcursor = wxGetCurrentBusyCursor(); |
43b5058d | 4205 | } |
46753a7c VZ |
4206 | else // not busy |
4207 | { | |
4208 | if ( nHitTest != HTCLIENT ) | |
4209 | return false; | |
43b5058d | 4210 | |
46753a7c VZ |
4211 | // first ask the user code - it may wish to set the cursor in some very |
4212 | // specific way (for example, depending on the current position) | |
4213 | POINT pt; | |
f2325516 | 4214 | #ifdef __WXWINCE__ |
46753a7c | 4215 | if ( !::GetCursorPosWinCE(&pt)) |
f2325516 | 4216 | #else |
46753a7c | 4217 | if ( !::GetCursorPos(&pt) ) |
3fca879c | 4218 | #endif |
46753a7c VZ |
4219 | { |
4220 | wxLogLastError(wxT("GetCursorPos")); | |
4221 | } | |
43b5058d | 4222 | |
46753a7c VZ |
4223 | int x = pt.x, |
4224 | y = pt.y; | |
4225 | ScreenToClient(&x, &y); | |
4226 | wxSetCursorEvent event(x, y); | |
42e69d6b | 4227 | |
937013e0 | 4228 | bool processedEvtSetCursor = HandleWindowEvent(event); |
46753a7c | 4229 | if ( processedEvtSetCursor && event.HasCursor() ) |
bfbd6dc1 | 4230 | { |
46753a7c | 4231 | hcursor = GetHcursorOf(event.GetCursor()); |
bfbd6dc1 | 4232 | } |
43b5058d | 4233 | |
46753a7c | 4234 | if ( !hcursor ) |
bfbd6dc1 | 4235 | { |
46753a7c VZ |
4236 | // the test for processedEvtSetCursor is here to prevent using |
4237 | // m_cursor if the user code caught EVT_SET_CURSOR() and returned | |
4238 | // nothing from it - this is a way to say that our cursor shouldn't | |
4239 | // be used for this point | |
4240 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
42e69d6b | 4241 | { |
46753a7c | 4242 | hcursor = GetHcursorOf(m_cursor); |
43b5058d | 4243 | } |
46753a7c VZ |
4244 | |
4245 | if ( !hcursor && !GetParent() ) | |
43b5058d VZ |
4246 | { |
4247 | const wxCursor *cursor = wxGetGlobalCursor(); | |
4248 | if ( cursor && cursor->Ok() ) | |
4249 | { | |
4250 | hcursor = GetHcursorOf(*cursor); | |
4251 | } | |
42e69d6b VZ |
4252 | } |
4253 | } | |
4254 | } | |
4255 | ||
46753a7c | 4256 | |
bfbd6dc1 VZ |
4257 | if ( hcursor ) |
4258 | { | |
4259 | ::SetCursor(hcursor); | |
4260 | ||
4261 | // cursor set, stop here | |
08158721 | 4262 | return true; |
bfbd6dc1 | 4263 | } |
cd4453e5 VZ |
4264 | #endif // __WXMICROWIN__ |
4265 | ||
3ca6a5f0 | 4266 | // pass up the window chain |
08158721 | 4267 | return false; |
2bda0e17 KB |
4268 | } |
4269 | ||
dbc74bcc | 4270 | bool wxWindowMSW::HandlePower(WXWPARAM WXUNUSED_IN_WINCE(wParam), |
355debca | 4271 | WXLPARAM WXUNUSED(lParam), |
dbc74bcc | 4272 | bool *WXUNUSED_IN_WINCE(vetoed)) |
355debca | 4273 | { |
dbc74bcc WS |
4274 | #ifdef __WXWINCE__ |
4275 | // FIXME | |
4276 | return false; | |
4277 | #else | |
355debca VZ |
4278 | wxEventType evtType; |
4279 | switch ( wParam ) | |
4280 | { | |
4281 | case PBT_APMQUERYSUSPEND: | |
4282 | evtType = wxEVT_POWER_SUSPENDING; | |
4283 | break; | |
4284 | ||
4285 | case PBT_APMQUERYSUSPENDFAILED: | |
4286 | evtType = wxEVT_POWER_SUSPEND_CANCEL; | |
4287 | break; | |
4288 | ||
4289 | case PBT_APMSUSPEND: | |
4290 | evtType = wxEVT_POWER_SUSPENDED; | |
4291 | break; | |
4292 | ||
4293 | case PBT_APMRESUMESUSPEND: | |
4294 | evtType = wxEVT_POWER_RESUME; | |
4295 | break; | |
4296 | ||
4297 | default: | |
9a83f860 | 4298 | wxLogDebug(wxT("Unknown WM_POWERBROADCAST(%d) event"), wParam); |
355debca VZ |
4299 | // fall through |
4300 | ||
4301 | // these messages are currently not mapped to wx events | |
4302 | case PBT_APMQUERYSTANDBY: | |
4303 | case PBT_APMQUERYSTANDBYFAILED: | |
4304 | case PBT_APMSTANDBY: | |
4305 | case PBT_APMRESUMESTANDBY: | |
4306 | case PBT_APMBATTERYLOW: | |
4307 | case PBT_APMPOWERSTATUSCHANGE: | |
4308 | case PBT_APMOEMEVENT: | |
355debca | 4309 | case PBT_APMRESUMECRITICAL: |
55cd5d10 VZ |
4310 | #ifdef PBT_APMRESUMEAUTOMATIC |
4311 | case PBT_APMRESUMEAUTOMATIC: | |
4312 | #endif | |
355debca VZ |
4313 | evtType = wxEVT_NULL; |
4314 | break; | |
4315 | } | |
4316 | ||
4317 | // don't handle unknown messages | |
4318 | if ( evtType == wxEVT_NULL ) | |
4319 | return false; | |
4320 | ||
4321 | // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events? | |
4322 | ||
4323 | wxPowerEvent event(evtType); | |
937013e0 | 4324 | if ( !HandleWindowEvent(event) ) |
355debca VZ |
4325 | return false; |
4326 | ||
4327 | *vetoed = event.IsVetoed(); | |
4328 | ||
4329 | return true; | |
dbc74bcc | 4330 | #endif |
355debca VZ |
4331 | } |
4332 | ||
2e992e06 VZ |
4333 | bool wxWindowMSW::IsDoubleBuffered() const |
4334 | { | |
75e8e6dc | 4335 | for ( const wxWindowMSW *win = this; win; win = win->GetParent() ) |
d66d0500 | 4336 | { |
75e8e6dc | 4337 | if ( wxHasWindowExStyle(win, WS_EX_COMPOSITED) ) |
2e992e06 | 4338 | return true; |
75e8e6dc VZ |
4339 | |
4340 | if ( win->IsTopLevel() ) | |
4341 | break; | |
4342 | } | |
d66d0500 | 4343 | |
2e992e06 VZ |
4344 | return false; |
4345 | } | |
4346 | ||
f60ca3e2 RD |
4347 | void wxWindowMSW::SetDoubleBuffered(bool on) |
4348 | { | |
4349 | // Get the current extended style bits | |
d66d0500 | 4350 | long exstyle = wxGetWindowExStyle(this); |
f60ca3e2 RD |
4351 | |
4352 | // Twiddle the bit as needed | |
4353 | if ( on ) | |
4354 | exstyle |= WS_EX_COMPOSITED; | |
4355 | else | |
4356 | exstyle &= ~WS_EX_COMPOSITED; | |
4357 | ||
4358 | // put it back | |
d66d0500 | 4359 | wxSetWindowExStyle(this, exstyle); |
f60ca3e2 RD |
4360 | } |
4361 | ||
42e69d6b VZ |
4362 | // --------------------------------------------------------------------------- |
4363 | // owner drawn stuff | |
4364 | // --------------------------------------------------------------------------- | |
4365 | ||
61fef19b VZ |
4366 | #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \ |
4367 | (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)) | |
4368 | #define WXUNUSED_UNLESS_ODRAWN(param) param | |
4369 | #else | |
4370 | #define WXUNUSED_UNLESS_ODRAWN(param) | |
4371 | #endif | |
4372 | ||
4373 | bool | |
4374 | wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id), | |
4375 | WXDRAWITEMSTRUCT * WXUNUSED_UNLESS_ODRAWN(itemStruct)) | |
2bda0e17 | 4376 | { |
4286a5b5 | 4377 | #if wxUSE_OWNER_DRAWN |
1e6feb95 VZ |
4378 | |
4379 | #if wxUSE_MENUS_NATIVE | |
42e69d6b | 4380 | // is it a menu item? |
6f806543 VZ |
4381 | DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct; |
4382 | if ( id == 0 && pDrawStruct->CtlType == ODT_MENU ) | |
42e69d6b | 4383 | { |
42e69d6b | 4384 | wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData); |
03cef643 | 4385 | |
2d29bf54 JS |
4386 | // see comment before the same test in MSWOnMeasureItem() below |
4387 | if ( !pMenuItem ) | |
4388 | return false; | |
4389 | ||
4390 | wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem), | |
9a83f860 | 4391 | false, wxT("MSWOnDrawItem: bad wxMenuItem pointer") ); |
42e69d6b | 4392 | |
7561aacd VZ |
4393 | // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent |
4394 | // the DC from being released | |
4395 | wxDCTemp dc((WXHDC)pDrawStruct->hDC); | |
42e69d6b VZ |
4396 | wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top, |
4397 | pDrawStruct->rcItem.right - pDrawStruct->rcItem.left, | |
4398 | pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top); | |
4399 | ||
4400 | return pMenuItem->OnDrawItem | |
7561aacd VZ |
4401 | ( |
4402 | dc, | |
4403 | rect, | |
4404 | (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction, | |
4405 | (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState | |
4406 | ); | |
42e69d6b | 4407 | } |
1e6feb95 | 4408 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b | 4409 | |
c8e4fa8b JS |
4410 | #endif // USE_OWNER_DRAWN |
4411 | ||
6a89f9ee | 4412 | #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__) |
c8e4fa8b | 4413 | |
c8e4fa8b | 4414 | #if wxUSE_OWNER_DRAWN |
1384636d | 4415 | wxControl *item = wxDynamicCast(FindItem(id), wxControl); |
567be187 | 4416 | #else // !wxUSE_OWNER_DRAWN |
1384636d VS |
4417 | // we may still have owner-drawn buttons internally because we have to make |
4418 | // them owner-drawn to support colour change | |
35bbb0c6 | 4419 | wxControl *item = |
095b80e2 WS |
4420 | # if wxUSE_BUTTON |
4421 | wxDynamicCast(FindItem(id), wxButton) | |
4422 | # else | |
4423 | NULL | |
4424 | # endif | |
4425 | ; | |
cd0b1709 | 4426 | #endif // USE_OWNER_DRAWN |
567be187 VZ |
4427 | |
4428 | if ( item ) | |
4429 | { | |
4430 | return item->MSWOnDraw(itemStruct); | |
4431 | } | |
4286a5b5 | 4432 | |
c8e4fa8b JS |
4433 | #endif // wxUSE_CONTROLS |
4434 | ||
08158721 | 4435 | return false; |
2bda0e17 KB |
4436 | } |
4437 | ||
61fef19b | 4438 | bool |
d1d276f2 | 4439 | wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct) |
2bda0e17 | 4440 | { |
61fef19b | 4441 | #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE |
42e69d6b | 4442 | // is it a menu item? |
6f806543 VZ |
4443 | MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct; |
4444 | if ( id == 0 && pMeasureStruct->CtlType == ODT_MENU ) | |
2d0a075d | 4445 | { |
42e69d6b VZ |
4446 | wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData); |
4447 | ||
b6afa1a3 VZ |
4448 | // according to Carsten Fuchs the pointer may be NULL under XP if an |
4449 | // MDI child frame is initially maximized, see this for more info: | |
4450 | // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745 | |
4451 | // | |
4452 | // so silently ignore it instead of asserting | |
4453 | if ( !pMenuItem ) | |
4454 | return false; | |
4455 | ||
4456 | wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem), | |
9a83f860 | 4457 | false, wxT("MSWOnMeasureItem: bad wxMenuItem pointer") ); |
42e69d6b | 4458 | |
975b6bcf VZ |
4459 | size_t w, h; |
4460 | bool rc = pMenuItem->OnMeasureItem(&w, &h); | |
4461 | ||
4462 | pMeasureStruct->itemWidth = w; | |
4463 | pMeasureStruct->itemHeight = h; | |
4464 | ||
4465 | return rc; | |
2d0a075d | 4466 | } |
42e69d6b | 4467 | |
567be187 VZ |
4468 | wxControl *item = wxDynamicCast(FindItem(id), wxControl); |
4469 | if ( item ) | |
42e69d6b | 4470 | { |
567be187 | 4471 | return item->MSWOnMeasure(itemStruct); |
42e69d6b | 4472 | } |
d1d276f2 WS |
4473 | #else |
4474 | wxUnusedVar(id); | |
4475 | wxUnusedVar(itemStruct); | |
4476 | #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE | |
567be187 | 4477 | |
08158721 | 4478 | return false; |
2bda0e17 KB |
4479 | } |
4480 | ||
42e69d6b VZ |
4481 | // --------------------------------------------------------------------------- |
4482 | // colours and palettes | |
4483 | // --------------------------------------------------------------------------- | |
2bda0e17 | 4484 | |
1e6feb95 | 4485 | bool wxWindowMSW::HandleSysColorChange() |
2bda0e17 | 4486 | { |
42e69d6b VZ |
4487 | wxSysColourChangedEvent event; |
4488 | event.SetEventObject(this); | |
4489 | ||
937013e0 | 4490 | (void)HandleWindowEvent(event); |
23895080 VZ |
4491 | |
4492 | // always let the system carry on the default processing to allow the | |
4493 | // native controls to react to the colours update | |
08158721 | 4494 | return false; |
42e69d6b VZ |
4495 | } |
4496 | ||
574c939e KB |
4497 | bool wxWindowMSW::HandleDisplayChange() |
4498 | { | |
4499 | wxDisplayChangedEvent event; | |
4500 | event.SetEventObject(this); | |
4501 | ||
937013e0 | 4502 | return HandleWindowEvent(event); |
574c939e KB |
4503 | } |
4504 | ||
04ef50df | 4505 | #ifndef __WXMICROWIN__ |
42e69d6b | 4506 | |
1a784dfc | 4507 | bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush, WXHDC hDC, WXHWND hWnd) |
01c500af | 4508 | { |
3d74a760 | 4509 | #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__) |
43bfb798 | 4510 | wxUnusedVar(hDC); |
3d74a760 WS |
4511 | wxUnusedVar(hWnd); |
4512 | #else | |
2bae4332 | 4513 | wxControl *item = wxDynamicCast(FindItemByHWND(hWnd, true), wxControl); |
c3732409 | 4514 | |
01c500af | 4515 | if ( item ) |
1a784dfc | 4516 | *brush = item->MSWControlColor(hDC, hWnd); |
2d0a075d | 4517 | else |
1e6feb95 | 4518 | #endif // wxUSE_CONTROLS |
01c500af | 4519 | *brush = NULL; |
42e69d6b | 4520 | |
01c500af | 4521 | return *brush != NULL; |
2bda0e17 KB |
4522 | } |
4523 | ||
01c500af VZ |
4524 | #endif // __WXMICROWIN__ |
4525 | ||
1e6feb95 | 4526 | bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange) |
42e69d6b | 4527 | { |
574c939e | 4528 | #if wxUSE_PALETTE |
b95edd47 VZ |
4529 | // same as below except we don't respond to our own messages |
4530 | if ( hWndPalChange != GetHWND() ) | |
4531 | { | |
574c939e | 4532 | // check to see if we our our parents have a custom palette |
fa21d338 | 4533 | wxWindowMSW *win = this; |
b95edd47 VZ |
4534 | while ( win && !win->HasCustomPalette() ) |
4535 | { | |
4536 | win = win->GetParent(); | |
4537 | } | |
4538 | ||
4539 | if ( win && win->HasCustomPalette() ) | |
4540 | { | |
4541 | // realize the palette to see whether redrawing is needed | |
4542 | HDC hdc = ::GetDC((HWND) hWndPalChange); | |
4543 | win->m_palette.SetHPALETTE((WXHPALETTE) | |
4544 | ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE)); | |
574c939e KB |
4545 | |
4546 | int result = ::RealizePalette(hdc); | |
b95edd47 VZ |
4547 | |
4548 | // restore the palette (before releasing the DC) | |
4549 | win->m_palette.SetHPALETTE((WXHPALETTE) | |
4550 | ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE)); | |
4551 | ::RealizePalette(hdc); | |
4552 | ::ReleaseDC((HWND) hWndPalChange, hdc); | |
4553 | ||
4554 | // now check for the need to redraw | |
574c939e | 4555 | if (result > 0) |
08158721 | 4556 | ::InvalidateRect((HWND) hWndPalChange, NULL, TRUE); |
574c939e | 4557 | } |
b95edd47 VZ |
4558 | |
4559 | } | |
4560 | #endif // wxUSE_PALETTE | |
574c939e | 4561 | |
42e69d6b VZ |
4562 | wxPaletteChangedEvent event(GetId()); |
4563 | event.SetEventObject(this); | |
4564 | event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange)); | |
2d0a075d | 4565 | |
937013e0 | 4566 | return HandleWindowEvent(event); |
42e69d6b VZ |
4567 | } |
4568 | ||
a5e84126 JS |
4569 | bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture) |
4570 | { | |
63e819f2 VS |
4571 | // notify windows on the capture stack about lost capture |
4572 | // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863): | |
72f8c792 | 4573 | wxWindowBase::NotifyCaptureLost(); |
a5e84126 | 4574 | |
72f8c792 | 4575 | wxWindow *win = wxFindWinFromHandle(hWndGainedCapture); |
63e819f2 VS |
4576 | wxMouseCaptureChangedEvent event(GetId(), win); |
4577 | event.SetEventObject(this); | |
937013e0 | 4578 | return HandleWindowEvent(event); |
a5e84126 JS |
4579 | } |
4580 | ||
3c96418b JG |
4581 | bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam) |
4582 | { | |
4583 | // despite MSDN saying "(This message cannot be sent directly to a window.)" | |
4584 | // we need to send this to child windows (it is only sent to top-level | |
4585 | // windows) so {list,tree}ctrls can adjust their font size if necessary | |
4586 | // this is exactly how explorer does it to enable the font size changes | |
4587 | ||
4588 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
4589 | while ( node ) | |
4590 | { | |
4591 | // top-level windows already get this message from the system | |
4592 | wxWindow *win = node->GetData(); | |
4593 | if ( !win->IsTopLevel() ) | |
4594 | { | |
4595 | ::SendMessage(GetHwndOf(win), WM_SETTINGCHANGE, wParam, lParam); | |
4596 | } | |
4597 | ||
4598 | node = node->GetNext(); | |
4599 | } | |
4600 | ||
3c96418b JG |
4601 | // let the system handle it |
4602 | return false; | |
4603 | } | |
4604 | ||
1e6feb95 | 4605 | bool wxWindowMSW::HandleQueryNewPalette() |
42e69d6b | 4606 | { |
574c939e KB |
4607 | |
4608 | #if wxUSE_PALETTE | |
4609 | // check to see if we our our parents have a custom palette | |
fa21d338 | 4610 | wxWindowMSW *win = this; |
574c939e KB |
4611 | while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent(); |
4612 | if (win->HasCustomPalette()) { | |
4613 | /* realize the palette to see whether redrawing is needed */ | |
3a3c8603 | 4614 | HDC hdc = ::GetDC((HWND) GetHWND()); |
574c939e | 4615 | win->m_palette.SetHPALETTE( (WXHPALETTE) |
b95edd47 | 4616 | ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), FALSE) ); |
574c939e KB |
4617 | |
4618 | int result = ::RealizePalette(hdc); | |
4619 | /* restore the palette (before releasing the DC) */ | |
4620 | win->m_palette.SetHPALETTE( (WXHPALETTE) | |
b95edd47 | 4621 | ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), TRUE) ); |
574c939e KB |
4622 | ::RealizePalette(hdc); |
4623 | ::ReleaseDC((HWND) GetHWND(), hdc); | |
4624 | /* now check for the need to redraw */ | |
4625 | if (result > 0) | |
4626 | ::InvalidateRect((HWND) GetHWND(), NULL, TRUE); | |
4627 | } | |
b95edd47 | 4628 | #endif // wxUSE_PALETTE |
574c939e | 4629 | |
42e69d6b VZ |
4630 | wxQueryNewPaletteEvent event(GetId()); |
4631 | event.SetEventObject(this); | |
4632 | ||
937013e0 | 4633 | return HandleWindowEvent(event) && event.GetPaletteRealized(); |
42e69d6b VZ |
4634 | } |
4635 | ||
4636 | // Responds to colour changes: passes event on to children. | |
574c939e | 4637 | void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) |
42e69d6b | 4638 | { |
90c1530a VZ |
4639 | // the top level window also reset the standard colour map as it might have |
4640 | // changed (there is no need to do it for the non top level windows as we | |
4641 | // only have to do it once) | |
4642 | if ( IsTopLevel() ) | |
4643 | { | |
4644 | // FIXME-MT | |
08158721 | 4645 | gs_hasStdCmap = false; |
90c1530a | 4646 | } |
222ed1d6 | 4647 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
42e69d6b VZ |
4648 | while ( node ) |
4649 | { | |
23895080 VZ |
4650 | // Only propagate to non-top-level windows because Windows already |
4651 | // sends this event to all top-level ones | |
4652 | wxWindow *win = node->GetData(); | |
4653 | if ( !win->IsTopLevel() ) | |
42e69d6b | 4654 | { |
23895080 VZ |
4655 | // we need to send the real WM_SYSCOLORCHANGE and not just trigger |
4656 | // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for | |
4657 | // the standard controls | |
4658 | ::SendMessage(GetHwndOf(win), WM_SYSCOLORCHANGE, 0, 0); | |
564b2609 | 4659 | } |
42e69d6b | 4660 | |
23895080 VZ |
4661 | node = node->GetNext(); |
4662 | } | |
2bda0e17 KB |
4663 | } |
4664 | ||
90c1530a VZ |
4665 | extern wxCOLORMAP *wxGetStdColourMap() |
4666 | { | |
4667 | static COLORREF s_stdColours[wxSTD_COL_MAX]; | |
4668 | static wxCOLORMAP s_cmap[wxSTD_COL_MAX]; | |
4669 | ||
4670 | if ( !gs_hasStdCmap ) | |
4671 | { | |
08158721 | 4672 | static bool s_coloursInit = false; |
90c1530a VZ |
4673 | |
4674 | if ( !s_coloursInit ) | |
4675 | { | |
4676 | // When a bitmap is loaded, the RGB values can change (apparently | |
4677 | // because Windows adjusts them to care for the old programs always | |
4678 | // using 0xc0c0c0 while the transparent colour for the new Windows | |
4679 | // versions is different). But we do this adjustment ourselves so | |
4680 | // we want to avoid Windows' "help" and for this we need to have a | |
4681 | // reference bitmap which can tell us what the RGB values change | |
4682 | // to. | |
e5dbcb50 | 4683 | wxLogNull logNo; // suppress error if we couldn't load the bitmap |
9a83f860 | 4684 | wxBitmap stdColourBitmap(wxT("wxBITMAP_STD_COLOURS")); |
90c1530a VZ |
4685 | if ( stdColourBitmap.Ok() ) |
4686 | { | |
4687 | // the pixels in the bitmap must correspond to wxSTD_COL_XXX! | |
4688 | wxASSERT_MSG( stdColourBitmap.GetWidth() == wxSTD_COL_MAX, | |
9a83f860 | 4689 | wxT("forgot to update wxBITMAP_STD_COLOURS!") ); |
90c1530a VZ |
4690 | |
4691 | wxMemoryDC memDC; | |
4692 | memDC.SelectObject(stdColourBitmap); | |
4693 | ||
4694 | wxColour colour; | |
4695 | for ( size_t i = 0; i < WXSIZEOF(s_stdColours); i++ ) | |
4696 | { | |
4697 | memDC.GetPixel(i, 0, &colour); | |
4698 | s_stdColours[i] = wxColourToRGB(colour); | |
4699 | } | |
4700 | } | |
4701 | else // wxBITMAP_STD_COLOURS couldn't be loaded | |
4702 | { | |
4703 | s_stdColours[0] = RGB(000,000,000); // black | |
4704 | s_stdColours[1] = RGB(128,128,128); // dark grey | |
4705 | s_stdColours[2] = RGB(192,192,192); // light grey | |
4706 | s_stdColours[3] = RGB(255,255,255); // white | |
4707 | //s_stdColours[4] = RGB(000,000,255); // blue | |
4708 | //s_stdColours[5] = RGB(255,000,255); // magenta | |
4709 | } | |
4710 | ||
08158721 | 4711 | s_coloursInit = true; |
90c1530a VZ |
4712 | } |
4713 | ||
08158721 | 4714 | gs_hasStdCmap = true; |
90c1530a VZ |
4715 | |
4716 | // create the colour map | |
4717 | #define INIT_CMAP_ENTRY(col) \ | |
4718 | s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \ | |
4719 | s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col) | |
4720 | ||
4721 | INIT_CMAP_ENTRY(BTNTEXT); | |
4722 | INIT_CMAP_ENTRY(BTNSHADOW); | |
4723 | INIT_CMAP_ENTRY(BTNFACE); | |
4724 | INIT_CMAP_ENTRY(BTNHIGHLIGHT); | |
4725 | ||
4726 | #undef INIT_CMAP_ENTRY | |
4727 | } | |
4728 | ||
4729 | return s_cmap; | |
4730 | } | |
4731 | ||
a5b1be33 JS |
4732 | #if wxUSE_UXTHEME && !defined(TMT_FILLCOLOR) |
4733 | #define TMT_FILLCOLOR 3802 | |
4734 | #define TMT_TEXTCOLOR 3803 | |
4735 | #define TMT_BORDERCOLOR 3801 | |
4736 | #endif | |
4737 | ||
4738 | wxColour wxWindowMSW::MSWGetThemeColour(const wchar_t *themeName, | |
4739 | int themePart, | |
4740 | int themeState, | |
4741 | MSWThemeColour themeColour, | |
4742 | wxSystemColour fallback) | |
4743 | { | |
4744 | #if wxUSE_UXTHEME | |
4745 | const wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); | |
4746 | if ( theme ) | |
4747 | { | |
4748 | int themeProperty = 0; | |
4749 | ||
4750 | // TODO: Convert this into a table? Sure would be faster. | |
4751 | switch ( themeColour ) | |
4752 | { | |
4753 | case ThemeColourBackground: | |
4754 | themeProperty = TMT_FILLCOLOR; | |
4755 | break; | |
4756 | case ThemeColourText: | |
4757 | themeProperty = TMT_TEXTCOLOR; | |
4758 | break; | |
4759 | case ThemeColourBorder: | |
4760 | themeProperty = TMT_BORDERCOLOR; | |
4761 | break; | |
4762 | default: | |
4763 | wxFAIL_MSG(wxT("unsupported theme colour")); | |
4764 | }; | |
4765 | ||
4766 | wxUxThemeHandle hTheme(this, themeName); | |
4767 | COLORREF col; | |
4768 | HRESULT hr = theme->GetThemeColor | |
4769 | ( | |
4770 | hTheme, | |
4771 | themePart, | |
4772 | themeState, | |
4773 | themeProperty, | |
4774 | &col | |
4775 | ); | |
4776 | ||
4777 | if ( SUCCEEDED(hr) ) | |
4778 | return wxRGBToColour(col); | |
4779 | ||
4780 | wxLogApiError( | |
4781 | wxString::Format( | |
4782 | "GetThemeColor(%s, %i, %i, %i)", | |
4783 | themeName, themePart, themeState, themeProperty), | |
4784 | hr); | |
4785 | } | |
b9de6a21 JS |
4786 | #else |
4787 | wxUnusedVar(themeName); | |
4788 | wxUnusedVar(themePart); | |
4789 | wxUnusedVar(themeState); | |
4790 | wxUnusedVar(themeColour); | |
a5b1be33 JS |
4791 | #endif |
4792 | return wxSystemSettings::GetColour(fallback); | |
4793 | } | |
4794 | ||
42e69d6b VZ |
4795 | // --------------------------------------------------------------------------- |
4796 | // painting | |
4797 | // --------------------------------------------------------------------------- | |
4798 | ||
1e6feb95 | 4799 | bool wxWindowMSW::HandlePaint() |
2bda0e17 | 4800 | { |
42e69d6b VZ |
4801 | HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle |
4802 | if ( !hRegion ) | |
43b2d5e7 | 4803 | { |
f6bcfd97 | 4804 | wxLogLastError(wxT("CreateRectRgn")); |
43b2d5e7 | 4805 | } |
42e69d6b | 4806 | if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR ) |
43b2d5e7 | 4807 | { |
f6bcfd97 | 4808 | wxLogLastError(wxT("GetUpdateRgn")); |
43b2d5e7 | 4809 | } |
c085e333 | 4810 | |
42e69d6b | 4811 | m_updateRegion = wxRegion((WXHRGN) hRegion); |
c085e333 | 4812 | |
42e69d6b VZ |
4813 | wxPaintEvent event(m_windowId); |
4814 | event.SetEventObject(this); | |
2bda0e17 | 4815 | |
937013e0 | 4816 | bool processed = HandleWindowEvent(event); |
1e6feb95 VZ |
4817 | |
4818 | // note that we must generate NC event after the normal one as otherwise | |
4819 | // BeginPaint() will happily overwrite our decorations with the background | |
4820 | // colour | |
4821 | wxNcPaintEvent eventNc(m_windowId); | |
4822 | eventNc.SetEventObject(this); | |
937013e0 | 4823 | HandleWindowEvent(eventNc); |
1e6feb95 | 4824 | |
90df6033 VZ |
4825 | // don't keep an HRGN we don't need any longer (GetUpdateRegion() can only |
4826 | // be called from inside the event handlers called above) | |
4827 | m_updateRegion.Clear(); | |
4828 | ||
1e6feb95 | 4829 | return processed; |
2bda0e17 KB |
4830 | } |
4831 | ||
63da7df7 | 4832 | // Can be called from an application's OnPaint handler |
1e6feb95 | 4833 | void wxWindowMSW::OnPaint(wxPaintEvent& event) |
63da7df7 | 4834 | { |
1e6feb95 VZ |
4835 | #ifdef __WXUNIVERSAL__ |
4836 | event.Skip(); | |
4837 | #else | |
888dde65 | 4838 | HDC hDC = (HDC) wxPaintDCImpl::FindDCInCache((wxWindow*) event.GetEventObject()); |
63da7df7 JS |
4839 | if (hDC != 0) |
4840 | { | |
4841 | MSWDefWindowProc(WM_PAINT, (WPARAM) hDC, 0); | |
4842 | } | |
1e6feb95 | 4843 | #endif |
63da7df7 JS |
4844 | } |
4845 | ||
1e6feb95 | 4846 | bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc) |
8681b094 | 4847 | { |
c753eb92 | 4848 | switch ( GetBackgroundStyle() ) |
d57f1dd7 | 4849 | { |
c753eb92 | 4850 | case wxBG_STYLE_ERASE: |
b469c9d8 | 4851 | case wxBG_STYLE_COLOUR: |
c753eb92 VZ |
4852 | // we need to generate an erase background event |
4853 | { | |
4854 | wxDCTemp dc(hdc, GetClientSize()); | |
4855 | wxDCTempImpl *impl = (wxDCTempImpl*) dc.GetImpl(); | |
d57f1dd7 | 4856 | |
c753eb92 VZ |
4857 | impl->SetHDC(hdc); |
4858 | impl->SetWindow((wxWindow *)this); | |
90df6033 | 4859 | |
c753eb92 VZ |
4860 | wxEraseEvent event(m_windowId, &dc); |
4861 | event.SetEventObject(this); | |
4862 | bool rc = HandleWindowEvent(event); | |
4863 | ||
4864 | // must be called manually as ~wxDC doesn't do anything for | |
4865 | // wxDCTemp | |
4866 | impl->SelectOldObjects(hdc); | |
4867 | ||
4868 | if ( rc ) | |
4869 | { | |
06393630 | 4870 | // background erased by the user-defined handler |
c753eb92 VZ |
4871 | return true; |
4872 | } | |
4873 | } | |
4874 | // fall through | |
4875 | ||
4876 | case wxBG_STYLE_SYSTEM: | |
4877 | if ( !DoEraseBackground(hdc) ) | |
4878 | { | |
4879 | // let the default processing to take place if we didn't erase | |
4880 | // the background ourselves | |
4881 | return false; | |
4882 | } | |
4883 | break; | |
4884 | ||
4885 | case wxBG_STYLE_PAINT: | |
b469c9d8 | 4886 | case wxBG_STYLE_TRANSPARENT: |
c753eb92 VZ |
4887 | // no need to do anything here at all, background will be entirely |
4888 | // redrawn in WM_PAINT handler | |
4889 | break; | |
4890 | ||
4891 | default: | |
4892 | wxFAIL_MSG( "unknown background style" ); | |
c5bd3c62 | 4893 | } |
c753eb92 VZ |
4894 | |
4895 | return true; | |
c5bd3c62 VZ |
4896 | } |
4897 | ||
bec9bf3e VZ |
4898 | #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK |
4899 | ||
4900 | bool wxWindowMSW::MSWHasEraseBgHook() const | |
4901 | { | |
4902 | return gs_eraseBgHooks.find(this) != gs_eraseBgHooks.end(); | |
4903 | } | |
4904 | ||
4905 | void wxWindowMSW::MSWSetEraseBgHook(wxWindow *child) | |
4906 | { | |
4907 | if ( child ) | |
4908 | { | |
4909 | if ( !gs_eraseBgHooks.insert( | |
4910 | EraseBgHooks::value_type(this, child)).second ) | |
4911 | { | |
4912 | wxFAIL_MSG( wxT("Setting erase background hook twice?") ); | |
4913 | } | |
4914 | } | |
4915 | else // reset the hook | |
4916 | { | |
4917 | if ( gs_eraseBgHooks.erase(this) != 1 ) | |
4918 | { | |
4919 | wxFAIL_MSG( wxT("Resetting erase background which was not set?") ); | |
4920 | } | |
4921 | } | |
4922 | } | |
4923 | ||
4924 | #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK | |
4925 | ||
c3732409 | 4926 | bool wxWindowMSW::DoEraseBackground(WXHDC hDC) |
c581abbc | 4927 | { |
c3732409 VZ |
4928 | HBRUSH hbr = (HBRUSH)MSWGetBgBrush(hDC); |
4929 | if ( !hbr ) | |
c581abbc VZ |
4930 | return false; |
4931 | ||
bec9bf3e VZ |
4932 | // erase just the client area of the window, this is important for the |
4933 | // frames to avoid drawing over the toolbar part of the window (you might | |
4934 | // think using WS_CLIPCHILDREN would prevent this from happening, but it | |
4935 | // clearly doesn't) | |
4936 | RECT rc; | |
4937 | wxCopyRectToRECT(GetClientRect(), rc); | |
4938 | ::FillRect((HDC)hDC, &rc, hbr); | |
c581abbc VZ |
4939 | |
4940 | return true; | |
4941 | } | |
4942 | ||
c3732409 | 4943 | WXHBRUSH |
b8797d96 | 4944 | wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), wxWindowMSW *child) |
c5bd3c62 | 4945 | { |
accbb1e7 VZ |
4946 | if ( m_hasBgCol ) |
4947 | { | |
8d075f8d VZ |
4948 | // our background colour applies to: |
4949 | // 1. this window itself, always | |
4950 | // 2. all children unless the colour is "not inheritable" | |
c3732409 VZ |
4951 | // 3. even if it is not inheritable, our immediate transparent |
4952 | // children should still inherit it -- but not any transparent | |
4953 | // children because it would look wrong if a child of non | |
4954 | // transparent child would show our bg colour when the child itself | |
4955 | // does not | |
b8797d96 | 4956 | if ( child == this || |
c3732409 | 4957 | m_inheritBgCol || |
b8797d96 VZ |
4958 | (child->HasTransparentBackground() && |
4959 | child->GetParent() == this) ) | |
accbb1e7 | 4960 | { |
c3732409 VZ |
4961 | // draw children with the same colour as the parent |
4962 | wxBrush * | |
4963 | brush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour()); | |
4964 | ||
4965 | return (WXHBRUSH)GetHbrushOf(*brush); | |
accbb1e7 VZ |
4966 | } |
4967 | } | |
4968 | ||
c3732409 | 4969 | return 0; |
c5bd3c62 | 4970 | } |
8681b094 | 4971 | |
b8797d96 | 4972 | WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC, wxWindowMSW *child) |
bdd1a35d | 4973 | { |
c3732409 | 4974 | for ( wxWindowMSW *win = this; win; win = win->GetParent() ) |
c5bd3c62 | 4975 | { |
b8797d96 | 4976 | WXHBRUSH hBrush = win->MSWGetBgBrushForChild(hDC, child); |
c5bd3c62 VZ |
4977 | if ( hBrush ) |
4978 | return hBrush; | |
24cb4019 | 4979 | |
c3732409 VZ |
4980 | // background is not inherited beyond top level windows |
4981 | if ( win->IsTopLevel() ) | |
24cb4019 | 4982 | break; |
01c500af | 4983 | } |
c5bd3c62 VZ |
4984 | |
4985 | return 0; | |
8681b094 VZ |
4986 | } |
4987 | ||
b728a212 | 4988 | bool wxWindowMSW::HandlePrintClient(WXHDC hDC) |
1a784dfc | 4989 | { |
b728a212 JG |
4990 | // we receive this message when DrawThemeParentBackground() is |
4991 | // called from def window proc of several controls under XP and we | |
4992 | // must draw properly themed background here | |
4993 | // | |
4994 | // note that naively I'd expect filling the client rect with the | |
4995 | // brush returned by MSWGetBgBrush() work -- but for some reason it | |
4996 | // doesn't and we have to call parents MSWPrintChild() which is | |
4997 | // supposed to call DrawThemeBackground() with appropriate params | |
4998 | // | |
4999 | // also note that in this case lParam == PRF_CLIENT but we're | |
5000 | // clearly expected to paint the background and nothing else! | |
5001 | ||
5002 | if ( IsTopLevel() || InheritsBackgroundColour() ) | |
5003 | return false; | |
5004 | ||
5005 | // sometimes we don't want the parent to handle it at all, instead | |
5006 | // return whatever value this window wants | |
5007 | if ( !MSWShouldPropagatePrintChild() ) | |
5008 | return MSWPrintChild(hDC, (wxWindow *)this); | |
5009 | ||
5010 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
5011 | { | |
5012 | if ( win->MSWPrintChild(hDC, (wxWindow *)this) ) | |
5013 | return true; | |
5014 | ||
5015 | if ( win->IsTopLevel() || win->InheritsBackgroundColour() ) | |
5016 | break; | |
5017 | } | |
5018 | ||
1a784dfc VZ |
5019 | return false; |
5020 | } | |
5021 | ||
42e69d6b VZ |
5022 | // --------------------------------------------------------------------------- |
5023 | // moving and resizing | |
5024 | // --------------------------------------------------------------------------- | |
5025 | ||
1e6feb95 | 5026 | bool wxWindowMSW::HandleMinimize() |
42e69d6b VZ |
5027 | { |
5028 | wxIconizeEvent event(m_windowId); | |
5029 | event.SetEventObject(this); | |
2d0a075d | 5030 | |
937013e0 | 5031 | return HandleWindowEvent(event); |
2bda0e17 KB |
5032 | } |
5033 | ||
1e6feb95 | 5034 | bool wxWindowMSW::HandleMaximize() |
2bda0e17 | 5035 | { |
42e69d6b VZ |
5036 | wxMaximizeEvent event(m_windowId); |
5037 | event.SetEventObject(this); | |
c085e333 | 5038 | |
937013e0 | 5039 | return HandleWindowEvent(event); |
42e69d6b | 5040 | } |
2bda0e17 | 5041 | |
1e6feb95 | 5042 | bool wxWindowMSW::HandleMove(int x, int y) |
42e69d6b | 5043 | { |
907173e5 WS |
5044 | wxPoint point(x,y); |
5045 | wxMoveEvent event(point, m_windowId); | |
42e69d6b VZ |
5046 | event.SetEventObject(this); |
5047 | ||
937013e0 | 5048 | return HandleWindowEvent(event); |
42e69d6b VZ |
5049 | } |
5050 | ||
5706de1c JS |
5051 | bool wxWindowMSW::HandleMoving(wxRect& rect) |
5052 | { | |
5053 | wxMoveEvent event(rect, m_windowId); | |
5054 | event.SetEventObject(this); | |
577baeef | 5055 | |
937013e0 | 5056 | bool rc = HandleWindowEvent(event); |
5706de1c JS |
5057 | if (rc) |
5058 | rect = event.GetRect(); | |
5059 | return rc; | |
5060 | } | |
5061 | ||
aa767a45 JS |
5062 | bool wxWindowMSW::HandleEnterSizeMove() |
5063 | { | |
66e2ba91 | 5064 | wxMoveEvent event(wxPoint(0,0), m_windowId); |
aa767a45 JS |
5065 | event.SetEventType(wxEVT_MOVE_START); |
5066 | event.SetEventObject(this); | |
5067 | ||
937013e0 | 5068 | return HandleWindowEvent(event); |
aa767a45 JS |
5069 | } |
5070 | ||
5071 | bool wxWindowMSW::HandleExitSizeMove() | |
5072 | { | |
66e2ba91 | 5073 | wxMoveEvent event(wxPoint(0,0), m_windowId); |
aa767a45 JS |
5074 | event.SetEventType(wxEVT_MOVE_END); |
5075 | event.SetEventObject(this); | |
5076 | ||
937013e0 | 5077 | return HandleWindowEvent(event); |
aa767a45 JS |
5078 | } |
5079 | ||
4bc0f25e | 5080 | bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam) |
42e69d6b | 5081 | { |
6bd9b9f2 | 5082 | #if wxUSE_DEFERRED_SIZING |
c3723477 JS |
5083 | // when we resize this window, its children are probably going to be |
5084 | // repositioned as well, prepare to use DeferWindowPos() for them | |
5085 | int numChildren = 0; | |
5086 | for ( HWND child = ::GetWindow(GetHwndOf(this), GW_CHILD); | |
5087 | child; | |
5088 | child = ::GetWindow(child, GW_HWNDNEXT) ) | |
5089 | { | |
5090 | numChildren ++; | |
5091 | } | |
5092 | ||
3fca879c | 5093 | // Protect against valid m_hDWP being overwritten |
c3723477 JS |
5094 | bool useDefer = false; |
5095 | ||
3f48c8e2 VZ |
5096 | if ( numChildren > 1 ) |
5097 | { | |
c3723477 | 5098 | if (!m_hDWP) |
3fca879c | 5099 | { |
c3723477 JS |
5100 | m_hDWP = (WXHANDLE)::BeginDeferWindowPos(numChildren); |
5101 | if ( !m_hDWP ) | |
5102 | { | |
9a83f860 | 5103 | wxLogLastError(wxT("BeginDeferWindowPos")); |
c3723477 JS |
5104 | } |
5105 | if (m_hDWP) | |
5106 | useDefer = true; | |
3f48c8e2 VZ |
5107 | } |
5108 | } | |
6bd9b9f2 | 5109 | #endif // wxUSE_DEFERRED_SIZING |
42e69d6b | 5110 | |
3f48c8e2 VZ |
5111 | // update this window size |
5112 | bool processed = false; | |
4bc0f25e VZ |
5113 | switch ( wParam ) |
5114 | { | |
5115 | default: | |
9a83f860 | 5116 | wxFAIL_MSG( wxT("unexpected WM_SIZE parameter") ); |
4bc0f25e VZ |
5117 | // fall through nevertheless |
5118 | ||
5119 | case SIZE_MAXHIDE: | |
5120 | case SIZE_MAXSHOW: | |
5121 | // we're not interested in these messages at all | |
5122 | break; | |
5123 | ||
5124 | case SIZE_MINIMIZED: | |
5125 | processed = HandleMinimize(); | |
5126 | break; | |
5127 | ||
5128 | case SIZE_MAXIMIZED: | |
a4d1972d | 5129 | /* processed = */ HandleMaximize(); |
4bc0f25e VZ |
5130 | // fall through to send a normal size event as well |
5131 | ||
5132 | case SIZE_RESTORED: | |
5133 | // don't use w and h parameters as they specify the client size | |
5134 | // while according to the docs EVT_SIZE handler is supposed to | |
5135 | // receive the total size | |
5136 | wxSizeEvent event(GetSize(), m_windowId); | |
5137 | event.SetEventObject(this); | |
5138 | ||
937013e0 | 5139 | processed = HandleWindowEvent(event); |
4bc0f25e VZ |
5140 | } |
5141 | ||
6bd9b9f2 | 5142 | #if wxUSE_DEFERRED_SIZING |
3f48c8e2 | 5143 | // and finally change the positions of all child windows at once |
c3723477 | 5144 | if ( useDefer && m_hDWP ) |
3f48c8e2 VZ |
5145 | { |
5146 | // reset m_hDWP to NULL so that child windows don't try to use our | |
5147 | // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't | |
5148 | // happen anyhow normally but who knows what weird flow of control we | |
5149 | // may have depending on what the users EVT_SIZE handler does...) | |
5150 | HDWP hDWP = (HDWP)m_hDWP; | |
5151 | m_hDWP = NULL; | |
3fca879c | 5152 | |
3f48c8e2 VZ |
5153 | // do put all child controls in place at once |
5154 | if ( !::EndDeferWindowPos(hDWP) ) | |
5155 | { | |
9a83f860 | 5156 | wxLogLastError(wxT("EndDeferWindowPos")); |
3f48c8e2 | 5157 | } |
c3723477 | 5158 | |
da78f3b1 | 5159 | // Reset our children's pending pos/size values. |
c3723477 JS |
5160 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
5161 | node; | |
5162 | node = node->GetNext() ) | |
5163 | { | |
6bd9b9f2 VZ |
5164 | wxWindowMSW * const child = node->GetData(); |
5165 | child->MSWEndDeferWindowPos(); | |
c3723477 | 5166 | } |
3f48c8e2 | 5167 | } |
6bd9b9f2 | 5168 | #endif // wxUSE_DEFERRED_SIZING |
3f48c8e2 | 5169 | |
4bc0f25e | 5170 | return processed; |
42e69d6b VZ |
5171 | } |
5172 | ||
5706de1c JS |
5173 | bool wxWindowMSW::HandleSizing(wxRect& rect) |
5174 | { | |
5175 | wxSizeEvent event(rect, m_windowId); | |
5176 | event.SetEventObject(this); | |
577baeef | 5177 | |
937013e0 | 5178 | bool rc = HandleWindowEvent(event); |
5706de1c JS |
5179 | if (rc) |
5180 | rect = event.GetRect(); | |
5181 | return rc; | |
5182 | } | |
5183 | ||
0c0d1521 | 5184 | bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo)) |
42e69d6b | 5185 | { |
7f0586ef | 5186 | #ifdef __WXWINCE__ |
08158721 | 5187 | return false; |
7f0586ef | 5188 | #else |
42e69d6b VZ |
5189 | MINMAXINFO *info = (MINMAXINFO *)mmInfo; |
5190 | ||
08158721 | 5191 | bool rc = false; |
b2d5a7ee | 5192 | |
e7dda1ff VS |
5193 | int minWidth = GetMinWidth(), |
5194 | minHeight = GetMinHeight(), | |
5195 | maxWidth = GetMaxWidth(), | |
5196 | maxHeight = GetMaxHeight(); | |
42e69d6b | 5197 | |
422d0ff0 | 5198 | if ( minWidth != wxDefaultCoord ) |
2d0a075d | 5199 | { |
e7dda1ff | 5200 | info->ptMinTrackSize.x = minWidth; |
08158721 | 5201 | rc = true; |
2d0a075d | 5202 | } |
2bda0e17 | 5203 | |
422d0ff0 | 5204 | if ( minHeight != wxDefaultCoord ) |
42e69d6b | 5205 | { |
e7dda1ff | 5206 | info->ptMinTrackSize.y = minHeight; |
08158721 | 5207 | rc = true; |
42e69d6b | 5208 | } |
2bda0e17 | 5209 | |
422d0ff0 | 5210 | if ( maxWidth != wxDefaultCoord ) |
42e69d6b | 5211 | { |
e7dda1ff | 5212 | info->ptMaxTrackSize.x = maxWidth; |
08158721 | 5213 | rc = true; |
2d0a075d | 5214 | } |
2bda0e17 | 5215 | |
422d0ff0 | 5216 | if ( maxHeight != wxDefaultCoord ) |
42e69d6b | 5217 | { |
e7dda1ff | 5218 | info->ptMaxTrackSize.y = maxHeight; |
08158721 | 5219 | rc = true; |
42e69d6b | 5220 | } |
2bda0e17 | 5221 | |
42e69d6b | 5222 | return rc; |
7f0586ef | 5223 | #endif |
42e69d6b | 5224 | } |
2d0a075d | 5225 | |
42e69d6b VZ |
5226 | // --------------------------------------------------------------------------- |
5227 | // command messages | |
5228 | // --------------------------------------------------------------------------- | |
5229 | ||
0edeeb6d | 5230 | bool wxWindowMSW::HandleCommand(WXWORD id_, WXWORD cmd, WXHWND control) |
42e69d6b | 5231 | { |
0edeeb6d VZ |
5232 | // sign extend to int from short before comparing with the other int ids |
5233 | int id = (signed short)id_; | |
5234 | ||
1e6feb95 | 5235 | #if wxUSE_MENUS_NATIVE |
8c290175 | 5236 | if ( !cmd && wxCurrentPopupMenu ) |
42e69d6b VZ |
5237 | { |
5238 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
5239 | wxCurrentPopupMenu = NULL; | |
5240 | ||
5241 | return popupMenu->MSWCommand(cmd, id); | |
5242 | } | |
1e6feb95 | 5243 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b | 5244 | |
8c290175 | 5245 | wxWindow *win = NULL; |
71292fab VZ |
5246 | |
5247 | // first try to find it from HWND - this works even with the broken | |
5248 | // programs using the same ids for different controls | |
5249 | if ( control ) | |
42e69d6b | 5250 | { |
71292fab | 5251 | win = wxFindWinFromHandle(control); |
b853f898 | 5252 | } |
2f4ef631 | 5253 | |
71292fab VZ |
5254 | // try the id |
5255 | if ( !win ) | |
b853f898 | 5256 | { |
0edeeb6d | 5257 | win = FindItem(id); |
42e69d6b VZ |
5258 | } |
5259 | ||
5260 | if ( win ) | |
b94ae1ea | 5261 | { |
42e69d6b | 5262 | return win->MSWCommand(cmd, id); |
b94ae1ea VZ |
5263 | } |
5264 | ||
5265 | // the messages sent from the in-place edit control used by the treectrl | |
5266 | // for label editing have id == 0, but they should _not_ be treated as menu | |
5267 | // messages (they are EN_XXX ones, in fact) so don't translate anything | |
5268 | // coming from a control to wxEVT_COMMAND_MENU_SELECTED | |
5269 | if ( !control ) | |
a84fc80b | 5270 | { |
a6ac49b1 | 5271 | wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, id); |
a84fc80b | 5272 | event.SetEventObject(this); |
a84fc80b | 5273 | event.SetInt(id); |
b94ae1ea | 5274 | |
937013e0 | 5275 | return HandleWindowEvent(event); |
a84fc80b | 5276 | } |
6fe19057 VZ |
5277 | else |
5278 | { | |
01d2bf4d | 5279 | #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__) |
6fe19057 VZ |
5280 | // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND |
5281 | // notifications to its parent which we want to reflect back to | |
5282 | // wxSpinCtrl | |
5283 | wxSpinCtrl *spin = wxSpinCtrl::GetSpinForTextCtrl(control); | |
5284 | if ( spin && spin->ProcessTextCommand(cmd, id) ) | |
08158721 | 5285 | return true; |
6fe19057 | 5286 | #endif // wxUSE_SPINCTRL |
42e69d6b | 5287 | |
01d2bf4d WS |
5288 | #if wxUSE_CHOICE && defined(__SMARTPHONE__) |
5289 | // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND | |
5290 | // notifications to its parent which we want to reflect back to | |
5291 | // wxChoice | |
5292 | wxChoice *choice = wxChoice::GetChoiceForListBox(control); | |
5293 | if ( choice && choice->MSWCommand(cmd, id) ) | |
5294 | return true; | |
5295 | #endif | |
5296 | } | |
5297 | ||
08158721 | 5298 | return false; |
2bda0e17 KB |
5299 | } |
5300 | ||
42e69d6b VZ |
5301 | // --------------------------------------------------------------------------- |
5302 | // mouse events | |
5303 | // --------------------------------------------------------------------------- | |
5304 | ||
1e6feb95 VZ |
5305 | void wxWindowMSW::InitMouseEvent(wxMouseEvent& event, |
5306 | int x, int y, | |
5307 | WXUINT flags) | |
42e69d6b | 5308 | { |
1e6feb95 VZ |
5309 | // our client coords are not quite the same as Windows ones |
5310 | wxPoint pt = GetClientAreaOrigin(); | |
5311 | event.m_x = x - pt.x; | |
5312 | event.m_y = y - pt.y; | |
5313 | ||
5314 | event.m_shiftDown = (flags & MK_SHIFT) != 0; | |
5315 | event.m_controlDown = (flags & MK_CONTROL) != 0; | |
5316 | event.m_leftDown = (flags & MK_LBUTTON) != 0; | |
5317 | event.m_middleDown = (flags & MK_MBUTTON) != 0; | |
5318 | event.m_rightDown = (flags & MK_RBUTTON) != 0; | |
2f68482e | 5319 | #ifdef wxHAS_XBUTTON |
01101e2d VZ |
5320 | event.m_aux1Down = (flags & MK_XBUTTON1) != 0; |
5321 | event.m_aux2Down = (flags & MK_XBUTTON2) != 0; | |
2f68482e | 5322 | #endif // wxHAS_XBUTTON |
6719c06a | 5323 | event.m_altDown = ::wxIsAltDown(); |
1e6feb95 | 5324 | |
f0b1ccde | 5325 | #ifndef __WXWINCE__ |
1bf77ee5 | 5326 | event.SetTimestamp(::GetMessageTime()); |
f0b1ccde JS |
5327 | #endif |
5328 | ||
687706f5 | 5329 | event.SetEventObject(this); |
fb35f0c7 | 5330 | event.SetId(GetId()); |
42e69d6b VZ |
5331 | |
5332 | #if wxUSE_MOUSEEVENT_HACK | |
c358ea41 VZ |
5333 | gs_lastMouseEvent.pos = ClientToScreen(wxPoint(x, y)); |
5334 | gs_lastMouseEvent.type = event.GetEventType(); | |
42e69d6b | 5335 | #endif // wxUSE_MOUSEEVENT_HACK |
2bda0e17 KB |
5336 | } |
5337 | ||
42b1fb63 | 5338 | #ifdef __WXWINCE__ |
dfafa702 VZ |
5339 | // Windows doesn't send the mouse events to the static controls (which are |
5340 | // transparent in the sense that their WM_NCHITTEST handler returns | |
5341 | // HTTRANSPARENT) at all but we want all controls to receive the mouse events | |
5342 | // and so we manually check if we don't have a child window under mouse and if | |
5343 | // we do, send the event to it instead of the window Windows had sent WM_XXX | |
5344 | // to. | |
5345 | // | |
5346 | // Notice that this is not done for the mouse move events because this could | |
5347 | // (would?) be too slow, but only for clicks which means that the static texts | |
5348 | // still don't get move, enter nor leave events. | |
42b1fb63 | 5349 | static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y) |
dfafa702 | 5350 | { |
9a83f860 | 5351 | wxCHECK_MSG( x && y, win, wxT("NULL pointer in FindWindowForMouseEvent") ); |
dfafa702 VZ |
5352 | |
5353 | // first try to find a non transparent child: this allows us to send events | |
5354 | // to a static text which is inside a static box, for example | |
5355 | POINT pt = { *x, *y }; | |
5356 | HWND hwnd = GetHwndOf(win), | |
5357 | hwndUnderMouse; | |
5358 | ||
7f0586ef JS |
5359 | #ifdef __WXWINCE__ |
5360 | hwndUnderMouse = ::ChildWindowFromPoint | |
5361 | ( | |
5362 | hwnd, | |
5363 | pt | |
5364 | ); | |
5365 | #else | |
dfafa702 VZ |
5366 | hwndUnderMouse = ::ChildWindowFromPointEx |
5367 | ( | |
5368 | hwnd, | |
5369 | pt, | |
5370 | CWP_SKIPINVISIBLE | | |
5371 | CWP_SKIPDISABLED | | |
5372 | CWP_SKIPTRANSPARENT | |
5373 | ); | |
7f0586ef | 5374 | #endif |
dfafa702 VZ |
5375 | |
5376 | if ( !hwndUnderMouse || hwndUnderMouse == hwnd ) | |
dfafa702 VZ |
5377 | { |
5378 | // now try any child window at all | |
5379 | hwndUnderMouse = ::ChildWindowFromPoint(hwnd, pt); | |
5380 | } | |
5381 | ||
5382 | // check that we have a child window which is susceptible to receive mouse | |
5383 | // events: for this it must be shown and enabled | |
5384 | if ( hwndUnderMouse && | |
5385 | hwndUnderMouse != hwnd && | |
5386 | ::IsWindowVisible(hwndUnderMouse) && | |
5387 | ::IsWindowEnabled(hwndUnderMouse) ) | |
5388 | { | |
dca0f651 | 5389 | wxWindow *winUnderMouse = wxFindWinFromHandle(hwndUnderMouse); |
dfafa702 VZ |
5390 | if ( winUnderMouse ) |
5391 | { | |
5392 | // translate the mouse coords to the other window coords | |
5393 | win->ClientToScreen(x, y); | |
5394 | winUnderMouse->ScreenToClient(x, y); | |
5395 | ||
5396 | win = winUnderMouse; | |
5397 | } | |
5398 | } | |
5399 | ||
5400 | return win; | |
5401 | } | |
42b1fb63 | 5402 | #endif // __WXWINCE__ |
dfafa702 | 5403 | |
1e6feb95 | 5404 | bool wxWindowMSW::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags) |
2bda0e17 | 5405 | { |
42e69d6b | 5406 | // the mouse events take consecutive IDs from WM_MOUSEFIRST to |
34621cc5 | 5407 | // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST |
42e69d6b VZ |
5408 | // from the message id and take the value in the table to get wxWin event |
5409 | // id | |
5410 | static const wxEventType eventsMouse[] = | |
5411 | { | |
5412 | wxEVT_MOTION, | |
5413 | wxEVT_LEFT_DOWN, | |
5414 | wxEVT_LEFT_UP, | |
5415 | wxEVT_LEFT_DCLICK, | |
5416 | wxEVT_RIGHT_DOWN, | |
5417 | wxEVT_RIGHT_UP, | |
5418 | wxEVT_RIGHT_DCLICK, | |
5419 | wxEVT_MIDDLE_DOWN, | |
5420 | wxEVT_MIDDLE_UP, | |
01101e2d VZ |
5421 | wxEVT_MIDDLE_DCLICK, |
5422 | 0, // this one is for wxEVT_MOTION which is not used here | |
5423 | wxEVT_AUX1_DOWN, | |
5424 | wxEVT_AUX1_UP, | |
5425 | wxEVT_AUX1_DCLICK, | |
5426 | wxEVT_AUX2_DOWN, | |
5427 | wxEVT_AUX2_UP, | |
5428 | wxEVT_AUX2_DCLICK | |
42e69d6b | 5429 | }; |
2bda0e17 | 5430 | |
2f68482e | 5431 | #ifdef wxHAS_XBUTTON |
01101e2d VZ |
5432 | // the same messages are used for both auxillary mouse buttons so we need |
5433 | // to adjust the index manually | |
5434 | switch ( msg ) | |
5435 | { | |
5436 | case WM_XBUTTONDOWN: | |
5437 | case WM_XBUTTONUP: | |
5438 | case WM_XBUTTONDBLCLK: | |
5439 | if ( flags & MK_XBUTTON2 ) | |
5440 | msg += wxEVT_AUX2_DOWN - wxEVT_AUX1_DOWN; | |
5441 | } | |
2f68482e | 5442 | #endif // wxHAS_XBUTTON |
01101e2d | 5443 | |
42e69d6b VZ |
5444 | wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]); |
5445 | InitMouseEvent(event, x, y, flags); | |
5446 | ||
937013e0 | 5447 | return HandleWindowEvent(event); |
42e69d6b VZ |
5448 | } |
5449 | ||
1e6feb95 | 5450 | bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags) |
42e69d6b VZ |
5451 | { |
5452 | if ( !m_mouseInWindow ) | |
2bda0e17 | 5453 | { |
1e6feb95 VZ |
5454 | // it would be wrong to assume that just because we get a mouse move |
5455 | // event that the mouse is inside the window: although this is usually | |
5456 | // true, it is not if we had captured the mouse, so we need to check | |
5457 | // the mouse coordinates here | |
5458 | if ( !HasCapture() || IsMouseInWindow() ) | |
5459 | { | |
5460 | // Generate an ENTER event | |
08158721 | 5461 | m_mouseInWindow = true; |
e5297b7f | 5462 | |
4e5c6c33 | 5463 | #ifdef HAVE_TRACKMOUSEEVENT |
aafb9978 VZ |
5464 | typedef BOOL (WINAPI *_TrackMouseEvent_t)(LPTRACKMOUSEEVENT); |
5465 | #ifdef __WXWINCE__ | |
5466 | static const _TrackMouseEvent_t | |
5467 | s_pfn_TrackMouseEvent = _TrackMouseEvent; | |
5468 | #else // !__WXWINCE__ | |
5469 | static _TrackMouseEvent_t s_pfn_TrackMouseEvent; | |
5470 | static bool s_initDone = false; | |
5471 | if ( !s_initDone ) | |
5472 | { | |
e2d4ce7d | 5473 | // see comment in wxApp::GetComCtl32Version() explaining the |
5a9379d7 | 5474 | // use of wxLoadedDLL |
9a83f860 | 5475 | wxLoadedDLL dllComCtl32(wxT("comctl32.dll")); |
aafb9978 VZ |
5476 | if ( dllComCtl32.IsLoaded() ) |
5477 | { | |
5478 | s_pfn_TrackMouseEvent = (_TrackMouseEvent_t) | |
9a83f860 | 5479 | dllComCtl32.RawGetSymbol(wxT("_TrackMouseEvent")); |
aafb9978 VZ |
5480 | } |
5481 | ||
5482 | s_initDone = true; | |
aafb9978 VZ |
5483 | } |
5484 | ||
5485 | if ( s_pfn_TrackMouseEvent ) | |
5486 | #endif // __WXWINCE__/!__WXWINCE__ | |
5487 | { | |
5488 | WinStruct<TRACKMOUSEEVENT> trackinfo; | |
4e5c6c33 | 5489 | |
aafb9978 VZ |
5490 | trackinfo.dwFlags = TME_LEAVE; |
5491 | trackinfo.hwndTrack = GetHwnd(); | |
5492 | ||
5493 | (*s_pfn_TrackMouseEvent)(&trackinfo); | |
5494 | } | |
4e5c6c33 VZ |
5495 | #endif // HAVE_TRACKMOUSEEVENT |
5496 | ||
1e6feb95 VZ |
5497 | wxMouseEvent event(wxEVT_ENTER_WINDOW); |
5498 | InitMouseEvent(event, x, y, flags); | |
42e69d6b | 5499 | |
937013e0 | 5500 | (void)HandleWindowEvent(event); |
1e6feb95 | 5501 | } |
42e69d6b | 5502 | } |
cff58b52 | 5503 | #ifdef HAVE_TRACKMOUSEEVENT |
aafb9978 | 5504 | else // mouse not in window |
cff58b52 KH |
5505 | { |
5506 | // Check if we need to send a LEAVE event | |
5507 | // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so | |
5508 | // send it here if we are using native mouse leave tracking | |
5509 | if ( HasCapture() && !IsMouseInWindow() ) | |
5510 | { | |
5511 | GenerateMouseLeave(); | |
5512 | } | |
5513 | } | |
1ca78aa1 | 5514 | #endif // HAVE_TRACKMOUSEEVENT |
42e69d6b VZ |
5515 | |
5516 | #if wxUSE_MOUSEEVENT_HACK | |
c358ea41 VZ |
5517 | // Windows often generates mouse events even if mouse position hasn't |
5518 | // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576) | |
5519 | // | |
5520 | // Filter this out as it can result in unexpected behaviour compared to | |
5521 | // other platforms | |
5522 | if ( gs_lastMouseEvent.type == wxEVT_RIGHT_DOWN || | |
5523 | gs_lastMouseEvent.type == wxEVT_LEFT_DOWN || | |
5524 | gs_lastMouseEvent.type == wxEVT_MIDDLE_DOWN || | |
5525 | gs_lastMouseEvent.type == wxEVT_MOTION ) | |
5526 | { | |
5527 | if ( ClientToScreen(wxPoint(x, y)) == gs_lastMouseEvent.pos ) | |
5528 | { | |
5529 | gs_lastMouseEvent.type = wxEVT_MOTION; | |
42e69d6b | 5530 | |
c358ea41 VZ |
5531 | return false; |
5532 | } | |
42e69d6b VZ |
5533 | } |
5534 | #endif // wxUSE_MOUSEEVENT_HACK | |
5535 | ||
5536 | return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags); | |
5537 | } | |
5538 | ||
d2c52078 | 5539 | |
24ce4c18 | 5540 | bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam) |
d2c52078 RD |
5541 | { |
5542 | #if wxUSE_MOUSEWHEEL | |
3c297348 VZ |
5543 | // notice that WM_MOUSEWHEEL position is in screen coords (as it's |
5544 | // forwarded up to the parent by DefWindowProc()) and not in the client | |
5545 | // ones as all the other messages, translate them to the client coords for | |
5546 | // consistency | |
5547 | const wxPoint | |
5548 | pt = ScreenToClient(wxPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); | |
d2c52078 | 5549 | wxMouseEvent event(wxEVT_MOUSEWHEEL); |
3c297348 | 5550 | InitMouseEvent(event, pt.x, pt.y, LOWORD(wParam)); |
d2c52078 RD |
5551 | event.m_wheelRotation = (short)HIWORD(wParam); |
5552 | event.m_wheelDelta = WHEEL_DELTA; | |
5553 | ||
0f7a546d RD |
5554 | static int s_linesPerRotation = -1; |
5555 | if ( s_linesPerRotation == -1 ) | |
5556 | { | |
5557 | if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, | |
5558 | &s_linesPerRotation, 0)) | |
5559 | { | |
5560 | // this is not supposed to happen | |
9a83f860 | 5561 | wxLogLastError(wxT("SystemParametersInfo(GETWHEELSCROLLLINES)")); |
0f7a546d RD |
5562 | |
5563 | // the default is 3, so use it if SystemParametersInfo() failed | |
5564 | s_linesPerRotation = 3; | |
5565 | } | |
5566 | } | |
d2c52078 | 5567 | |
0f7a546d | 5568 | event.m_linesPerAction = s_linesPerRotation; |
937013e0 | 5569 | return HandleWindowEvent(event); |
0f7a546d | 5570 | |
51e4e266 VZ |
5571 | #else // !wxUSE_MOUSEWHEEL |
5572 | wxUnusedVar(wParam); | |
5573 | wxUnusedVar(lParam); | |
38caaa61 | 5574 | |
08158721 | 5575 | return false; |
51e4e266 | 5576 | #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL |
d2c52078 RD |
5577 | } |
5578 | ||
51e4e266 VZ |
5579 | void wxWindowMSW::GenerateMouseLeave() |
5580 | { | |
5581 | m_mouseInWindow = false; | |
5582 | ||
5583 | int state = 0; | |
5584 | if ( wxIsShiftDown() ) | |
5585 | state |= MK_SHIFT; | |
5586 | if ( wxIsCtrlDown() ) | |
5587 | state |= MK_CONTROL; | |
5588 | ||
5589 | // Only the high-order bit should be tested | |
5590 | if ( GetKeyState( VK_LBUTTON ) & (1<<15) ) | |
5591 | state |= MK_LBUTTON; | |
5592 | if ( GetKeyState( VK_MBUTTON ) & (1<<15) ) | |
5593 | state |= MK_MBUTTON; | |
5594 | if ( GetKeyState( VK_RBUTTON ) & (1<<15) ) | |
5595 | state |= MK_RBUTTON; | |
5596 | ||
5597 | POINT pt; | |
f2325516 JS |
5598 | #ifdef __WXWINCE__ |
5599 | if ( !::GetCursorPosWinCE(&pt) ) | |
5600 | #else | |
51e4e266 | 5601 | if ( !::GetCursorPos(&pt) ) |
f2325516 | 5602 | #endif |
51e4e266 | 5603 | { |
9a83f860 | 5604 | wxLogLastError(wxT("GetCursorPos")); |
51e4e266 VZ |
5605 | } |
5606 | ||
5607 | // we need to have client coordinates here for symmetry with | |
5608 | // wxEVT_ENTER_WINDOW | |
5609 | RECT rect = wxGetWindowRect(GetHwnd()); | |
5610 | pt.x -= rect.left; | |
5611 | pt.y -= rect.top; | |
5612 | ||
5613 | wxMouseEvent event(wxEVT_LEAVE_WINDOW); | |
5614 | InitMouseEvent(event, pt.x, pt.y, state); | |
5615 | ||
937013e0 | 5616 | (void)HandleWindowEvent(event); |
51e4e266 | 5617 | } |
d2c52078 | 5618 | |
42e69d6b VZ |
5619 | // --------------------------------------------------------------------------- |
5620 | // keyboard handling | |
5621 | // --------------------------------------------------------------------------- | |
5622 | ||
c42404a5 VZ |
5623 | // create the key event of the given type for the given key - used by |
5624 | // HandleChar and HandleKeyDown/Up | |
1e6feb95 | 5625 | wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType, |
b09bda68 | 5626 | int id, |
9c7df356 VZ |
5627 | WXLPARAM lParam, |
5628 | WXWPARAM wParam) const | |
c42404a5 VZ |
5629 | { |
5630 | wxKeyEvent event(evType); | |
5631 | event.SetId(GetId()); | |
3f7bc32b VZ |
5632 | event.m_shiftDown = wxIsShiftDown(); |
5633 | event.m_controlDown = wxIsCtrlDown(); | |
c42404a5 VZ |
5634 | event.m_altDown = (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN; |
5635 | ||
687706f5 | 5636 | event.SetEventObject((wxWindow *)this); // const_cast |
c42404a5 | 5637 | event.m_keyCode = id; |
0d9b2c16 | 5638 | #if wxUSE_UNICODE |
32b13913 | 5639 | event.m_uniChar = (wxChar) wParam; |
0d9b2c16 | 5640 | #endif |
9c7df356 VZ |
5641 | event.m_rawCode = (wxUint32) wParam; |
5642 | event.m_rawFlags = (wxUint32) lParam; | |
f0b1ccde | 5643 | #ifndef __WXWINCE__ |
1bf77ee5 | 5644 | event.SetTimestamp(::GetMessageTime()); |
f0b1ccde | 5645 | #endif |
c42404a5 VZ |
5646 | |
5647 | // translate the position to client coords | |
5648 | POINT pt; | |
f2325516 JS |
5649 | #ifdef __WXWINCE__ |
5650 | GetCursorPosWinCE(&pt); | |
5651 | #else | |
c42404a5 | 5652 | GetCursorPos(&pt); |
f2325516 | 5653 | #endif |
c42404a5 VZ |
5654 | RECT rect; |
5655 | GetWindowRect(GetHwnd(),&rect); | |
5656 | pt.x -= rect.left; | |
5657 | pt.y -= rect.top; | |
5658 | ||
5659 | event.m_x = pt.x; | |
5660 | event.m_y = pt.y; | |
5661 | ||
5662 | return event; | |
5663 | } | |
5664 | ||
08158721 | 5665 | // isASCII is true only when we're called from WM_CHAR handler and not from |
42e69d6b | 5666 | // WM_KEYDOWN one |
1e6feb95 | 5667 | bool wxWindowMSW::HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII) |
42e69d6b VZ |
5668 | { |
5669 | int id; | |
42e69d6b VZ |
5670 | if ( isASCII ) |
5671 | { | |
42e69d6b | 5672 | id = wParam; |
2d0a075d | 5673 | } |
9c7df356 | 5674 | else // we're called from WM_KEYDOWN |
c42404a5 | 5675 | { |
6121a198 VZ |
5676 | // don't pass lParam to wxCharCodeMSWToWX() here because we don't want |
5677 | // to get numpad key codes: CHAR events should use the logical keys | |
5678 | // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events | |
5679 | id = wxCharCodeMSWToWX(wParam); | |
9c7df356 | 5680 | if ( id == 0 ) |
c42404a5 | 5681 | { |
9c7df356 | 5682 | // it's ASCII and will be processed here only when called from |
08158721 DS |
5683 | // WM_CHAR (i.e. when isASCII = true), don't process it now |
5684 | return false; | |
c42404a5 | 5685 | } |
9c7df356 | 5686 | } |
42e69d6b | 5687 | |
9c7df356 | 5688 | wxKeyEvent event(CreateKeyEvent(wxEVT_CHAR, id, lParam, wParam)); |
2b5f62a0 VZ |
5689 | |
5690 | // the alphanumeric keys produced by pressing AltGr+something on European | |
5691 | // keyboards have both Ctrl and Alt modifiers which may confuse the user | |
5692 | // code as, normally, keys with Ctrl and/or Alt don't result in anything | |
5693 | // alphanumeric, so pretend that there are no modifiers at all (the | |
5694 | // KEY_DOWN event would still have the correct modifiers if they're really | |
5695 | // needed) | |
5696 | if ( event.m_controlDown && event.m_altDown && | |
5697 | (id >= 32 && id < 256) ) | |
9c7df356 | 5698 | { |
2b5f62a0 | 5699 | event.m_controlDown = |
08158721 | 5700 | event.m_altDown = false; |
2d0a075d | 5701 | } |
c42404a5 | 5702 | |
937013e0 | 5703 | return HandleWindowEvent(event); |
2bda0e17 KB |
5704 | } |
5705 | ||
1e6feb95 | 5706 | bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 5707 | { |
ff792344 | 5708 | int id = wxCharCodeMSWToWX(wParam, lParam); |
2bda0e17 | 5709 | |
c42404a5 VZ |
5710 | if ( !id ) |
5711 | { | |
5712 | // normal ASCII char | |
42e69d6b VZ |
5713 | id = wParam; |
5714 | } | |
5715 | ||
b60978b2 | 5716 | wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, id, lParam, wParam)); |
937013e0 | 5717 | return HandleWindowEvent(event); |
2bda0e17 KB |
5718 | } |
5719 | ||
1e6feb95 | 5720 | bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 5721 | { |
ff792344 | 5722 | int id = wxCharCodeMSWToWX(wParam, lParam); |
2bda0e17 | 5723 | |
c42404a5 VZ |
5724 | if ( !id ) |
5725 | { | |
5726 | // normal ASCII char | |
42e69d6b | 5727 | id = wParam; |
2d0a075d | 5728 | } |
2bda0e17 | 5729 | |
b60978b2 | 5730 | wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, id, lParam, wParam)); |
937013e0 | 5731 | return HandleWindowEvent(event); |
2bda0e17 KB |
5732 | } |
5733 | ||
53a118d6 | 5734 | #if wxUSE_MENUS |
0c0d1521 WS |
5735 | int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel), |
5736 | WXLPARAM WXUNUSED_IN_WINCE(lParam)) | |
b74cce40 | 5737 | { |
7f0586ef JS |
5738 | // FIXME: implement GetMenuItemCount for WinCE, possibly |
5739 | // in terms of GetMenuItemInfo | |
5740 | #ifndef __WXWINCE__ | |
b74cce40 VZ |
5741 | const HMENU hmenu = (HMENU)lParam; |
5742 | ||
5743 | MENUITEMINFO mii; | |
5744 | wxZeroMemory(mii); | |
5745 | mii.cbSize = sizeof(MENUITEMINFO); | |
c70ffbdb VZ |
5746 | |
5747 | // we could use MIIM_FTYPE here as we only need to know if the item is | |
5748 | // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but | |
5749 | // MIIM_FTYPE is not supported under Win95 | |
b74cce40 VZ |
5750 | mii.fMask = MIIM_TYPE | MIIM_DATA; |
5751 | ||
5752 | // find if we have this letter in any owner drawn item | |
5753 | const int count = ::GetMenuItemCount(hmenu); | |
5754 | for ( int i = 0; i < count; i++ ) | |
5755 | { | |
c70ffbdb VZ |
5756 | // previous loop iteration could modify it, reset it back before |
5757 | // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData | |
5758 | mii.cch = 0; | |
5759 | ||
b74cce40 VZ |
5760 | if ( ::GetMenuItemInfo(hmenu, i, TRUE, &mii) ) |
5761 | { | |
5762 | if ( mii.fType == MFT_OWNERDRAW ) | |
5763 | { | |
5764 | // dwItemData member of the MENUITEMINFO is a | |
5765 | // pointer to the associated wxMenuItem -- see the | |
5766 | // menu creation code | |
5767 | wxMenuItem *item = (wxMenuItem*)mii.dwItemData; | |
5768 | ||
9a83f860 | 5769 | const wxChar *p = wxStrchr(item->GetItemLabel().wx_str(), wxT('&')); |
b74cce40 VZ |
5770 | while ( p++ ) |
5771 | { | |
9a83f860 | 5772 | if ( *p == wxT('&') ) |
b74cce40 VZ |
5773 | { |
5774 | // this is not the accel char, find the real one | |
9a83f860 | 5775 | p = wxStrchr(p + 1, wxT('&')); |
b74cce40 VZ |
5776 | } |
5777 | else // got the accel char | |
5778 | { | |
5779 | // FIXME-UNICODE: this comparison doesn't risk to work | |
5780 | // for non ASCII accelerator characters I'm afraid, but | |
5781 | // what can we do? | |
907173e5 | 5782 | if ( (wchar_t)wxToupper(*p) == (wchar_t)chAccel ) |
b74cce40 VZ |
5783 | { |
5784 | return i; | |
5785 | } | |
5786 | else | |
5787 | { | |
5788 | // this one doesn't match | |
5789 | break; | |
5790 | } | |
5791 | } | |
5792 | } | |
5793 | } | |
5794 | } | |
e39af974 | 5795 | else // failed to get the menu text? |
b74cce40 | 5796 | { |
c70ffbdb | 5797 | // it's not fatal, so don't show error, but still log it |
9a83f860 | 5798 | wxLogLastError(wxT("GetMenuItemInfo")); |
b74cce40 VZ |
5799 | } |
5800 | } | |
7f0586ef | 5801 | #endif |
b74cce40 VZ |
5802 | return wxNOT_FOUND; |
5803 | } | |
5804 | ||
17a04304 VZ |
5805 | #endif // wxUSE_MENUS |
5806 | ||
5807 | bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg) | |
78c91815 | 5808 | { |
17a04304 VZ |
5809 | const wxEventType type = nMsg == WM_CUT ? wxEVT_COMMAND_TEXT_CUT |
5810 | : nMsg == WM_COPY ? wxEVT_COMMAND_TEXT_COPY | |
5811 | : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE; | |
78c91815 VZ |
5812 | wxClipboardTextEvent evt(type, GetId()); |
5813 | ||
5814 | evt.SetEventObject(this); | |
5815 | ||
937013e0 | 5816 | return HandleWindowEvent(evt); |
78c91815 VZ |
5817 | } |
5818 | ||
42e69d6b VZ |
5819 | // --------------------------------------------------------------------------- |
5820 | // joystick | |
5821 | // --------------------------------------------------------------------------- | |
5822 | ||
1e6feb95 | 5823 | bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags) |
2bda0e17 | 5824 | { |
8cb172b4 | 5825 | #ifdef JOY_BUTTON1 |
42e69d6b VZ |
5826 | int change = 0; |
5827 | if ( flags & JOY_BUTTON1CHG ) | |
5828 | change = wxJOY_BUTTON1; | |
5829 | if ( flags & JOY_BUTTON2CHG ) | |
5830 | change = wxJOY_BUTTON2; | |
5831 | if ( flags & JOY_BUTTON3CHG ) | |
5832 | change = wxJOY_BUTTON3; | |
5833 | if ( flags & JOY_BUTTON4CHG ) | |
5834 | change = wxJOY_BUTTON4; | |
2bda0e17 | 5835 | |
42e69d6b VZ |
5836 | int buttons = 0; |
5837 | if ( flags & JOY_BUTTON1 ) | |
5838 | buttons |= wxJOY_BUTTON1; | |
5839 | if ( flags & JOY_BUTTON2 ) | |
5840 | buttons |= wxJOY_BUTTON2; | |
5841 | if ( flags & JOY_BUTTON3 ) | |
5842 | buttons |= wxJOY_BUTTON3; | |
5843 | if ( flags & JOY_BUTTON4 ) | |
5844 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 5845 | |
42e69d6b VZ |
5846 | // the event ids aren't consecutive so we can't use table based lookup |
5847 | int joystick; | |
5848 | wxEventType eventType; | |
5849 | switch ( msg ) | |
5850 | { | |
5851 | case MM_JOY1MOVE: | |
5852 | joystick = 1; | |
5853 | eventType = wxEVT_JOY_MOVE; | |
5854 | break; | |
2bda0e17 | 5855 | |
42e69d6b VZ |
5856 | case MM_JOY2MOVE: |
5857 | joystick = 2; | |
5858 | eventType = wxEVT_JOY_MOVE; | |
5859 | break; | |
2bda0e17 | 5860 | |
42e69d6b VZ |
5861 | case MM_JOY1ZMOVE: |
5862 | joystick = 1; | |
5863 | eventType = wxEVT_JOY_ZMOVE; | |
5864 | break; | |
2bda0e17 | 5865 | |
42e69d6b VZ |
5866 | case MM_JOY2ZMOVE: |
5867 | joystick = 2; | |
5868 | eventType = wxEVT_JOY_ZMOVE; | |
5869 | break; | |
2bda0e17 | 5870 | |
42e69d6b VZ |
5871 | case MM_JOY1BUTTONDOWN: |
5872 | joystick = 1; | |
5873 | eventType = wxEVT_JOY_BUTTON_DOWN; | |
5874 | break; | |
2bda0e17 | 5875 | |
42e69d6b VZ |
5876 | case MM_JOY2BUTTONDOWN: |
5877 | joystick = 2; | |
5878 | eventType = wxEVT_JOY_BUTTON_DOWN; | |
5879 | break; | |
2bda0e17 | 5880 | |
42e69d6b VZ |
5881 | case MM_JOY1BUTTONUP: |
5882 | joystick = 1; | |
5883 | eventType = wxEVT_JOY_BUTTON_UP; | |
5884 | break; | |
5885 | ||
5886 | case MM_JOY2BUTTONUP: | |
5887 | joystick = 2; | |
5888 | eventType = wxEVT_JOY_BUTTON_UP; | |
5889 | break; | |
5890 | ||
5891 | default: | |
223d09f6 | 5892 | wxFAIL_MSG(wxT("no such joystick event")); |
2d0a075d | 5893 | |
08158721 | 5894 | return false; |
2d0a075d | 5895 | } |
2bda0e17 | 5896 | |
42e69d6b VZ |
5897 | wxJoystickEvent event(eventType, buttons, joystick, change); |
5898 | event.SetPosition(wxPoint(x, y)); | |
5899 | event.SetEventObject(this); | |
c085e333 | 5900 | |
937013e0 | 5901 | return HandleWindowEvent(event); |
8cb172b4 | 5902 | #else |
991420e6 WS |
5903 | wxUnusedVar(msg); |
5904 | wxUnusedVar(x); | |
5905 | wxUnusedVar(y); | |
5906 | wxUnusedVar(flags); | |
08158721 | 5907 | return false; |
8cb172b4 | 5908 | #endif |
2bda0e17 KB |
5909 | } |
5910 | ||
42e69d6b VZ |
5911 | // --------------------------------------------------------------------------- |
5912 | // scrolling | |
5913 | // --------------------------------------------------------------------------- | |
5914 | ||
1e6feb95 | 5915 | bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam, |
f4f734c1 | 5916 | WXWORD pos, WXHWND control) |
35bbb0c6 | 5917 | { |
a0d924c6 | 5918 | if ( control && control != m_hWnd ) // Prevent infinite recursion |
cc2b7472 | 5919 | { |
42e69d6b VZ |
5920 | wxWindow *child = wxFindWinFromHandle(control); |
5921 | if ( child ) | |
5922 | return child->MSWOnScroll(orientation, wParam, pos, control); | |
cc2b7472 | 5923 | } |
2bda0e17 | 5924 | |
9145664b | 5925 | wxScrollWinEvent event; |
42e69d6b VZ |
5926 | event.SetPosition(pos); |
5927 | event.SetOrientation(orientation); | |
687706f5 | 5928 | event.SetEventObject(this); |
cc2b7472 | 5929 | |
42e69d6b VZ |
5930 | switch ( wParam ) |
5931 | { | |
5932 | case SB_TOP: | |
687706f5 | 5933 | event.SetEventType(wxEVT_SCROLLWIN_TOP); |
42e69d6b | 5934 | break; |
cc2b7472 | 5935 | |
42e69d6b | 5936 | case SB_BOTTOM: |
687706f5 | 5937 | event.SetEventType(wxEVT_SCROLLWIN_BOTTOM); |
42e69d6b | 5938 | break; |
cc2b7472 | 5939 | |
42e69d6b | 5940 | case SB_LINEUP: |
687706f5 | 5941 | event.SetEventType(wxEVT_SCROLLWIN_LINEUP); |
42e69d6b | 5942 | break; |
2bda0e17 | 5943 | |
42e69d6b | 5944 | case SB_LINEDOWN: |
687706f5 | 5945 | event.SetEventType(wxEVT_SCROLLWIN_LINEDOWN); |
42e69d6b | 5946 | break; |
a02eb1d2 | 5947 | |
42e69d6b | 5948 | case SB_PAGEUP: |
687706f5 | 5949 | event.SetEventType(wxEVT_SCROLLWIN_PAGEUP); |
42e69d6b | 5950 | break; |
2bda0e17 | 5951 | |
42e69d6b | 5952 | case SB_PAGEDOWN: |
687706f5 | 5953 | event.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN); |
42e69d6b | 5954 | break; |
2bda0e17 | 5955 | |
42e69d6b | 5956 | case SB_THUMBPOSITION: |
feda3011 | 5957 | case SB_THUMBTRACK: |
f6bcfd97 BP |
5958 | // under Win32, the scrollbar range and position are 32 bit integers, |
5959 | // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must | |
5960 | // explicitly query the scrollbar for the correct position (this must | |
5961 | // be done only for these two SB_ events as they are the only one | |
5962 | // carrying the scrollbar position) | |
5963 | { | |
0cf5de11 | 5964 | WinStruct<SCROLLINFO> scrollInfo; |
f6bcfd97 BP |
5965 | scrollInfo.fMask = SIF_TRACKPOS; |
5966 | ||
5967 | if ( !::GetScrollInfo(GetHwnd(), | |
1ddb6d28 | 5968 | WXOrientToSB(orientation), |
f6bcfd97 BP |
5969 | &scrollInfo) ) |
5970 | { | |
3103e8a9 | 5971 | // Not necessarily an error, if there are no scrollbars yet. |
9a83f860 | 5972 | // wxLogLastError(wxT("GetScrollInfo")); |
f6bcfd97 BP |
5973 | } |
5974 | ||
5975 | event.SetPosition(scrollInfo.nTrackPos); | |
5976 | } | |
f6bcfd97 | 5977 | |
687706f5 | 5978 | event.SetEventType( wParam == SB_THUMBPOSITION |
f6bcfd97 | 5979 | ? wxEVT_SCROLLWIN_THUMBRELEASE |
687706f5 | 5980 | : wxEVT_SCROLLWIN_THUMBTRACK ); |
42e69d6b | 5981 | break; |
c085e333 | 5982 | |
42e69d6b | 5983 | default: |
08158721 | 5984 | return false; |
564b2609 | 5985 | } |
2bda0e17 | 5986 | |
937013e0 | 5987 | return HandleWindowEvent(event); |
2bda0e17 KB |
5988 | } |
5989 | ||
5acec112 VZ |
5990 | // ---------------------------------------------------------------------------- |
5991 | // custom message handlers | |
5992 | // ---------------------------------------------------------------------------- | |
5993 | ||
5994 | /* static */ bool | |
5995 | wxWindowMSW::MSWRegisterMessageHandler(int msg, MSWMessageHandler handler) | |
5996 | { | |
5997 | wxCHECK_MSG( gs_messageHandlers.find(msg) == gs_messageHandlers.end(), | |
9a83f860 | 5998 | false, wxT("registering handler for the same message twice") ); |
5acec112 VZ |
5999 | |
6000 | gs_messageHandlers[msg] = handler; | |
6001 | return true; | |
6002 | } | |
6003 | ||
6004 | /* static */ void | |
6005 | wxWindowMSW::MSWUnregisterMessageHandler(int msg, MSWMessageHandler handler) | |
6006 | { | |
6007 | const MSWMessageHandlers::iterator i = gs_messageHandlers.find(msg); | |
6008 | wxCHECK_RET( i != gs_messageHandlers.end() && i->second == handler, | |
9a83f860 | 6009 | wxT("unregistering non-registered handler?") ); |
5acec112 VZ |
6010 | |
6011 | gs_messageHandlers.erase(i); | |
6012 | } | |
6013 | ||
42e69d6b VZ |
6014 | // =========================================================================== |
6015 | // global functions | |
6016 | // =========================================================================== | |
6017 | ||
7a5e53ab | 6018 | void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font) |
2bda0e17 | 6019 | { |
42e69d6b VZ |
6020 | TEXTMETRIC tm; |
6021 | HDC dc = ::GetDC((HWND) wnd); | |
42e69d6b | 6022 | HFONT was = 0; |
35bbb0c6 | 6023 | |
7a5e53ab VS |
6024 | // the_font.UseResource(); |
6025 | // the_font.RealizeResource(); | |
c57c2993 | 6026 | HFONT fnt = (HFONT)the_font.GetResourceHandle(); // const_cast |
7a5e53ab VS |
6027 | if ( fnt ) |
6028 | was = (HFONT) SelectObject(dc,fnt); | |
35bbb0c6 | 6029 | |
42e69d6b | 6030 | GetTextMetrics(dc, &tm); |
7a5e53ab | 6031 | if ( fnt && was ) |
2d0a075d | 6032 | { |
42e69d6b | 6033 | SelectObject(dc,was); |
2d0a075d | 6034 | } |
42e69d6b | 6035 | ReleaseDC((HWND)wnd, dc); |
0655ad29 VZ |
6036 | |
6037 | if ( x ) | |
6038 | *x = tm.tmAveCharWidth; | |
6039 | if ( y ) | |
6040 | *y = tm.tmHeight + tm.tmExternalLeading; | |
2bda0e17 | 6041 | |
7a5e53ab | 6042 | // the_font.ReleaseResource(); |
42e69d6b | 6043 | } |
c085e333 | 6044 | |
5004c3ad JG |
6045 | // use the "extended" bit (24) of lParam to distinguish extended keys |
6046 | // from normal keys as the same key is sent | |
ed5bc8f1 VZ |
6047 | static inline |
6048 | int ChooseNormalOrExtended(int lParam, int keyNormal, int keyExtended) | |
5004c3ad | 6049 | { |
ed5bc8f1 VZ |
6050 | // except that if lParam is 0, it means we don't have real lParam from |
6051 | // WM_KEYDOWN but are just translating just a VK constant (e.g. done from | |
6052 | // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a | |
6053 | // non-numpad (hence extended) key as this is a more common case | |
6054 | return !lParam || (lParam & (1 << 24)) ? keyExtended : keyNormal; | |
5004c3ad JG |
6055 | } |
6056 | ||
d5c21b02 VZ |
6057 | // this array contains the Windows virtual key codes which map one to one to |
6058 | // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below | |
6059 | // | |
6060 | // note that keys having a normal and numpad version (e.g. WXK_HOME and | |
6061 | // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1 | |
6062 | static const struct wxKeyMapping | |
6063 | { | |
6064 | int vk; | |
6065 | wxKeyCode wxk; | |
6066 | } gs_specialKeys[] = | |
6067 | { | |
6068 | { VK_CANCEL, WXK_CANCEL }, | |
6069 | { VK_BACK, WXK_BACK }, | |
6070 | { VK_TAB, WXK_TAB }, | |
6071 | { VK_CLEAR, WXK_CLEAR }, | |
6072 | { VK_SHIFT, WXK_SHIFT }, | |
6073 | { VK_CONTROL, WXK_CONTROL }, | |
6074 | { VK_MENU , WXK_ALT }, | |
6075 | { VK_PAUSE, WXK_PAUSE }, | |
6076 | { VK_CAPITAL, WXK_CAPITAL }, | |
6077 | { VK_SPACE, WXK_SPACE }, | |
6078 | { VK_ESCAPE, WXK_ESCAPE }, | |
6079 | { VK_SELECT, WXK_SELECT }, | |
6080 | { VK_PRINT, WXK_PRINT }, | |
6081 | { VK_EXECUTE, WXK_EXECUTE }, | |
e59c2b2d VZ |
6082 | { VK_SNAPSHOT, WXK_SNAPSHOT }, |
6083 | { VK_HELP, WXK_HELP }, | |
d5c21b02 VZ |
6084 | |
6085 | { VK_NUMPAD0, WXK_NUMPAD0 }, | |
6086 | { VK_NUMPAD1, WXK_NUMPAD1 }, | |
6087 | { VK_NUMPAD2, WXK_NUMPAD2 }, | |
6088 | { VK_NUMPAD3, WXK_NUMPAD3 }, | |
6089 | { VK_NUMPAD4, WXK_NUMPAD4 }, | |
6090 | { VK_NUMPAD5, WXK_NUMPAD5 }, | |
6091 | { VK_NUMPAD6, WXK_NUMPAD6 }, | |
6092 | { VK_NUMPAD7, WXK_NUMPAD7 }, | |
6093 | { VK_NUMPAD8, WXK_NUMPAD8 }, | |
6094 | { VK_NUMPAD9, WXK_NUMPAD9 }, | |
6095 | { VK_MULTIPLY, WXK_NUMPAD_MULTIPLY }, | |
6096 | { VK_ADD, WXK_NUMPAD_ADD }, | |
6097 | { VK_SUBTRACT, WXK_NUMPAD_SUBTRACT }, | |
6098 | { VK_DECIMAL, WXK_NUMPAD_DECIMAL }, | |
6099 | { VK_DIVIDE, WXK_NUMPAD_DIVIDE }, | |
6100 | ||
6101 | { VK_F1, WXK_F1 }, | |
6102 | { VK_F2, WXK_F2 }, | |
6103 | { VK_F3, WXK_F3 }, | |
6104 | { VK_F4, WXK_F4 }, | |
6105 | { VK_F5, WXK_F5 }, | |
6106 | { VK_F6, WXK_F6 }, | |
6107 | { VK_F7, WXK_F7 }, | |
6108 | { VK_F8, WXK_F8 }, | |
6109 | { VK_F9, WXK_F9 }, | |
6110 | { VK_F10, WXK_F10 }, | |
6111 | { VK_F11, WXK_F11 }, | |
6112 | { VK_F12, WXK_F12 }, | |
6113 | { VK_F13, WXK_F13 }, | |
6114 | { VK_F14, WXK_F14 }, | |
6115 | { VK_F15, WXK_F15 }, | |
6116 | { VK_F16, WXK_F16 }, | |
6117 | { VK_F17, WXK_F17 }, | |
6118 | { VK_F18, WXK_F18 }, | |
6119 | { VK_F19, WXK_F19 }, | |
6120 | { VK_F20, WXK_F20 }, | |
6121 | { VK_F21, WXK_F21 }, | |
6122 | { VK_F22, WXK_F22 }, | |
6123 | { VK_F23, WXK_F23 }, | |
6124 | { VK_F24, WXK_F24 }, | |
6125 | ||
6126 | { VK_NUMLOCK, WXK_NUMLOCK }, | |
6127 | { VK_SCROLL, WXK_SCROLL }, | |
6128 | ||
6129 | #ifdef VK_APPS | |
6130 | { VK_LWIN, WXK_WINDOWS_LEFT }, | |
6131 | { VK_RWIN, WXK_WINDOWS_RIGHT }, | |
6132 | { VK_APPS, WXK_WINDOWS_MENU }, | |
6133 | #endif // VK_APPS defined | |
6134 | }; | |
6135 | ||
42e69d6b VZ |
6136 | // Returns 0 if was a normal ASCII value, not a special key. This indicates that |
6137 | // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead. | |
d5c21b02 | 6138 | int wxCharCodeMSWToWX(int vk, WXLPARAM lParam) |
42e69d6b | 6139 | { |
d5c21b02 VZ |
6140 | // check the table first |
6141 | for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ ) | |
6142 | { | |
6143 | if ( gs_specialKeys[n].vk == vk ) | |
6144 | return gs_specialKeys[n].wxk; | |
6145 | } | |
9c7df356 | 6146 | |
d5c21b02 VZ |
6147 | // keys requiring special handling |
6148 | int wxk; | |
6149 | switch ( vk ) | |
6150 | { | |
e77c5d96 VZ |
6151 | // the mapping for these keys may be incorrect on non-US keyboards so |
6152 | // maybe we shouldn't map them to ASCII values at all | |
d5c21b02 VZ |
6153 | case VK_OEM_1: wxk = ';'; break; |
6154 | case VK_OEM_PLUS: wxk = '+'; break; | |
6155 | case VK_OEM_COMMA: wxk = ','; break; | |
6156 | case VK_OEM_MINUS: wxk = '-'; break; | |
6157 | case VK_OEM_PERIOD: wxk = '.'; break; | |
6158 | case VK_OEM_2: wxk = '/'; break; | |
6159 | case VK_OEM_3: wxk = '~'; break; | |
6160 | case VK_OEM_4: wxk = '['; break; | |
6161 | case VK_OEM_5: wxk = '\\'; break; | |
6162 | case VK_OEM_6: wxk = ']'; break; | |
6163 | case VK_OEM_7: wxk = '\''; break; | |
702c4208 | 6164 | |
5004c3ad | 6165 | // handle extended keys |
413553cc | 6166 | case VK_PRIOR: |
d5c21b02 | 6167 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEUP, WXK_PAGEUP); |
413553cc | 6168 | break; |
d5c21b02 | 6169 | |
413553cc | 6170 | case VK_NEXT: |
d5c21b02 | 6171 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEDOWN, WXK_PAGEDOWN); |
413553cc | 6172 | break; |
d5c21b02 | 6173 | |
413553cc | 6174 | case VK_END: |
d5c21b02 | 6175 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_END, WXK_END); |
413553cc | 6176 | break; |
d5c21b02 | 6177 | |
413553cc | 6178 | case VK_HOME: |
d5c21b02 | 6179 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_HOME, WXK_HOME); |
413553cc | 6180 | break; |
d5c21b02 | 6181 | |
413553cc | 6182 | case VK_LEFT: |
d5c21b02 | 6183 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_LEFT, WXK_LEFT); |
413553cc | 6184 | break; |
d5c21b02 | 6185 | |
413553cc | 6186 | case VK_UP: |
d5c21b02 | 6187 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_UP, WXK_UP); |
413553cc | 6188 | break; |
d5c21b02 | 6189 | |
413553cc | 6190 | case VK_RIGHT: |
d5c21b02 | 6191 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_RIGHT, WXK_RIGHT); |
413553cc | 6192 | break; |
d5c21b02 | 6193 | |
413553cc | 6194 | case VK_DOWN: |
d5c21b02 | 6195 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_DOWN, WXK_DOWN); |
413553cc | 6196 | break; |
d5c21b02 | 6197 | |
413553cc | 6198 | case VK_INSERT: |
d5c21b02 | 6199 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_INSERT, WXK_INSERT); |
413553cc | 6200 | break; |
d5c21b02 | 6201 | |
413553cc | 6202 | case VK_DELETE: |
d5c21b02 | 6203 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_DELETE, WXK_DELETE); |
413553cc | 6204 | break; |
d5c21b02 | 6205 | |
ff792344 | 6206 | case VK_RETURN: |
ed5bc8f1 VZ |
6207 | // don't use ChooseNormalOrExtended() here as the keys are reversed |
6208 | // here: numpad enter is the extended one | |
d5c21b02 | 6209 | wxk = lParam && (lParam & (1 << 24)) ? WXK_NUMPAD_ENTER : WXK_RETURN; |
ff792344 VZ |
6210 | break; |
6211 | ||
f6bcfd97 | 6212 | default: |
d5c21b02 VZ |
6213 | wxk = 0; |
6214 | } | |
6215 | ||
6216 | return wxk; | |
6217 | } | |
6218 | ||
4f04a4fd | 6219 | WXWORD wxCharCodeWXToMSW(int wxk) |
d5c21b02 | 6220 | { |
d5c21b02 VZ |
6221 | // check the table first |
6222 | for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ ) | |
6223 | { | |
6224 | if ( gs_specialKeys[n].wxk == wxk ) | |
6225 | return gs_specialKeys[n].vk; | |
6226 | } | |
6227 | ||
6228 | // and then check for special keys not included in the table | |
6229 | WXWORD vk; | |
6230 | switch ( wxk ) | |
6231 | { | |
71403278 VZ |
6232 | case WXK_PAGEUP: |
6233 | case WXK_NUMPAD_PAGEUP: | |
6234 | vk = VK_PRIOR; | |
6235 | break; | |
6236 | ||
6237 | case WXK_PAGEDOWN: | |
6238 | case WXK_NUMPAD_PAGEDOWN: | |
6239 | vk = VK_NEXT; | |
6240 | break; | |
6241 | ||
6242 | case WXK_END: | |
6243 | case WXK_NUMPAD_END: | |
6244 | vk = VK_END; | |
6245 | break; | |
6246 | ||
6247 | case WXK_HOME: | |
6248 | case WXK_NUMPAD_HOME: | |
6249 | vk = VK_HOME; | |
6250 | break; | |
6251 | ||
6252 | case WXK_LEFT: | |
6253 | case WXK_NUMPAD_LEFT: | |
6254 | vk = VK_LEFT; | |
6255 | break; | |
6256 | ||
6257 | case WXK_UP: | |
6258 | case WXK_NUMPAD_UP: | |
6259 | vk = VK_UP; | |
6260 | break; | |
6261 | ||
6262 | case WXK_RIGHT: | |
6263 | case WXK_NUMPAD_RIGHT: | |
6264 | vk = VK_RIGHT; | |
6265 | break; | |
6266 | ||
6267 | case WXK_DOWN: | |
6268 | case WXK_NUMPAD_DOWN: | |
6269 | vk = VK_DOWN; | |
6270 | break; | |
6271 | ||
6272 | case WXK_INSERT: | |
6273 | case WXK_NUMPAD_INSERT: | |
6274 | vk = VK_INSERT; | |
6275 | break; | |
6276 | ||
6277 | case WXK_DELETE: | |
6278 | case WXK_NUMPAD_DELETE: | |
6279 | vk = VK_DELETE; | |
6280 | break; | |
d5c21b02 VZ |
6281 | |
6282 | default: | |
d9fda37b VZ |
6283 | // no VkKeyScan() under CE unfortunately, we need to test how does |
6284 | // it handle OEM keys | |
6285 | #ifndef __WXWINCE__ | |
ad294cb8 VZ |
6286 | // check to see if its one of the OEM key codes. |
6287 | BYTE vks = LOBYTE(VkKeyScan(wxk)); | |
6e3e6c8e | 6288 | if ( vks != 0xff ) |
ad294cb8 VZ |
6289 | { |
6290 | vk = vks; | |
6291 | } | |
6292 | else | |
d9fda37b | 6293 | #endif // !__WXWINCE__ |
ad294cb8 | 6294 | { |
ad294cb8 VZ |
6295 | vk = (WXWORD)wxk; |
6296 | } | |
2bda0e17 | 6297 | } |
d5c21b02 VZ |
6298 | |
6299 | return vk; | |
6300 | } | |
6301 | ||
6302 | // small helper for wxGetKeyState() and wxGetMouseState() | |
6303 | static inline bool wxIsKeyDown(WXWORD vk) | |
6304 | { | |
d9fda37b VZ |
6305 | // SM_SWAPBUTTON is not available under CE, so don't swap buttons there |
6306 | #ifdef SM_SWAPBUTTON | |
6307 | if ( vk == VK_LBUTTON || vk == VK_RBUTTON ) | |
b8f434e7 | 6308 | { |
d9fda37b VZ |
6309 | if ( ::GetSystemMetrics(SM_SWAPBUTTON) ) |
6310 | { | |
6311 | if ( vk == VK_LBUTTON ) | |
6312 | vk = VK_RBUTTON; | |
6313 | else // vk == VK_RBUTTON | |
6314 | vk = VK_LBUTTON; | |
6315 | } | |
b8f434e7 | 6316 | } |
d9fda37b VZ |
6317 | #endif // SM_SWAPBUTTON |
6318 | ||
d5c21b02 VZ |
6319 | // the low order bit indicates whether the key was pressed since the last |
6320 | // call and the high order one indicates whether it is down right now and | |
6321 | // we only want that one | |
b8f434e7 | 6322 | return (GetAsyncKeyState(vk) & (1<<15)) != 0; |
2bda0e17 KB |
6323 | } |
6324 | ||
1751226c | 6325 | bool wxGetKeyState(wxKeyCode key) |
6ed892f3 | 6326 | { |
d5c21b02 VZ |
6327 | // although this does work under Windows, it is not supported under other |
6328 | // platforms so don't allow it, you must use wxGetMouseState() instead | |
6329 | wxASSERT_MSG( key != VK_LBUTTON && | |
6330 | key != VK_RBUTTON && | |
6331 | key != VK_MBUTTON, | |
6332 | wxT("can't use wxGetKeyState() for mouse buttons") ); | |
6ed892f3 | 6333 | |
d5c21b02 | 6334 | const WXWORD vk = wxCharCodeWXToMSW(key); |
44353523 | 6335 | |
d5c21b02 VZ |
6336 | // if the requested key is a LED key, return true if the led is pressed |
6337 | if ( key == WXK_NUMLOCK || key == WXK_CAPITAL || key == WXK_SCROLL ) | |
fdec2c05 | 6338 | { |
d5c21b02 VZ |
6339 | // low order bit means LED is highlighted and high order one means the |
6340 | // key is down; for compatibility with the other ports return true if | |
6341 | // either one is set | |
b8f434e7 | 6342 | return GetKeyState(vk) != 0; |
35bbb0c6 | 6343 | |
fdec2c05 | 6344 | } |
d5c21b02 | 6345 | else // normal key |
84c51ddf | 6346 | { |
d5c21b02 | 6347 | return wxIsKeyDown(vk); |
84c51ddf | 6348 | } |
6ed892f3 RN |
6349 | } |
6350 | ||
7dd40b6f RD |
6351 | |
6352 | wxMouseState wxGetMouseState() | |
6353 | { | |
6354 | wxMouseState ms; | |
6355 | POINT pt; | |
6356 | GetCursorPos( &pt ); | |
6357 | ||
6358 | ms.SetX(pt.x); | |
6359 | ms.SetY(pt.y); | |
d5c21b02 VZ |
6360 | ms.SetLeftDown(wxIsKeyDown(VK_LBUTTON)); |
6361 | ms.SetMiddleDown(wxIsKeyDown(VK_MBUTTON)); | |
6362 | ms.SetRightDown(wxIsKeyDown(VK_RBUTTON)); | |
2f68482e | 6363 | #ifdef wxHAS_XBUTTON |
01101e2d VZ |
6364 | ms.SetAux1Down(wxIsKeyDown(VK_XBUTTON1)); |
6365 | ms.SetAux2Down(wxIsKeyDown(VK_XBUTTON2)); | |
2f68482e | 6366 | #endif // wxHAS_XBUTTON |
dd28827a | 6367 | |
6719c06a VZ |
6368 | ms.SetControlDown(wxIsCtrlDown ()); |
6369 | ms.SetShiftDown (wxIsShiftDown()); | |
6370 | ms.SetAltDown (wxIsAltDown ()); | |
7dd40b6f | 6371 | // ms.SetMetaDown(); |
dd28827a | 6372 | |
7dd40b6f RD |
6373 | return ms; |
6374 | } | |
6375 | ||
6376 | ||
42e69d6b | 6377 | wxWindow *wxGetActiveWindow() |
2bda0e17 | 6378 | { |
42e69d6b VZ |
6379 | HWND hWnd = GetActiveWindow(); |
6380 | if ( hWnd != 0 ) | |
2d0a075d | 6381 | { |
dca0f651 | 6382 | return wxFindWinFromHandle(hWnd); |
2d0a075d | 6383 | } |
42e69d6b | 6384 | return NULL; |
2bda0e17 KB |
6385 | } |
6386 | ||
8614c467 VZ |
6387 | extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd) |
6388 | { | |
6389 | HWND hwnd = (HWND)hWnd; | |
6390 | ||
6391 | // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set | |
6392 | // by code in msw/radiobox.cpp), for all the others we just search up the | |
6393 | // window hierarchy | |
d3b9f782 | 6394 | wxWindow *win = NULL; |
8614c467 VZ |
6395 | if ( hwnd ) |
6396 | { | |
dca0f651 | 6397 | win = wxFindWinFromHandle(hwnd); |
8614c467 VZ |
6398 | if ( !win ) |
6399 | { | |
a2242341 | 6400 | #if wxUSE_RADIOBOX |
8614c467 VZ |
6401 | // native radiobuttons return DLGC_RADIOBUTTON here and for any |
6402 | // wxWindow class which overrides WM_GETDLGCODE processing to | |
6403 | // do it as well, win would be already non NULL | |
a2242341 | 6404 | if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON ) |
8614c467 | 6405 | { |
975b6bcf | 6406 | win = (wxWindow *)wxGetWindowUserData(hwnd); |
8614c467 | 6407 | } |
a2242341 VZ |
6408 | //else: it's a wxRadioButton, not a radiobutton from wxRadioBox |
6409 | #endif // wxUSE_RADIOBOX | |
6410 | ||
6411 | // spin control text buddy window should be mapped to spin ctrl | |
6412 | // itself so try it too | |
24ce4c18 | 6413 | #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__) |
a2242341 VZ |
6414 | if ( !win ) |
6415 | { | |
6416 | win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd); | |
6417 | } | |
6418 | #endif // wxUSE_SPINCTRL | |
8614c467 | 6419 | } |
8614c467 VZ |
6420 | } |
6421 | ||
6422 | while ( hwnd && !win ) | |
6423 | { | |
761989ff VZ |
6424 | // this is a really ugly hack needed to avoid mistakenly returning the |
6425 | // parent frame wxWindow for the find/replace modeless dialog HWND - | |
6426 | // this, in turn, is needed to call IsDialogMessage() from | |
6427 | // wxApp::ProcessMessage() as for this we must return NULL from here | |
6428 | // | |
6429 | // FIXME: this is clearly not the best way to do it but I think we'll | |
6430 | // need to change HWND <-> wxWindow code more heavily than I can | |
6431 | // do it now to fix it | |
c67d6888 | 6432 | #ifndef __WXMICROWIN__ |
761989ff VZ |
6433 | if ( ::GetWindow(hwnd, GW_OWNER) ) |
6434 | { | |
6435 | // it's a dialog box, don't go upwards | |
6436 | break; | |
6437 | } | |
c67d6888 | 6438 | #endif |
761989ff | 6439 | |
8614c467 | 6440 | hwnd = ::GetParent(hwnd); |
dca0f651 | 6441 | win = wxFindWinFromHandle(hwnd); |
8614c467 VZ |
6442 | } |
6443 | ||
6444 | return win; | |
6445 | } | |
6446 | ||
7f0586ef | 6447 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
04ef50df | 6448 | |
42e69d6b VZ |
6449 | // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE |
6450 | // in active frames and dialogs, regardless of where the focus is. | |
6451 | static HHOOK wxTheKeyboardHook = 0; | |
2bda0e17 | 6452 | |
23c26b99 | 6453 | int APIENTRY |
42e69d6b | 6454 | wxKeyboardHook(int nCode, WORD wParam, DWORD lParam) |
2bda0e17 | 6455 | { |
42e69d6b VZ |
6456 | DWORD hiWord = HIWORD(lParam); |
6457 | if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) ) | |
43d811ea | 6458 | { |
ff792344 | 6459 | int id = wxCharCodeMSWToWX(wParam, lParam); |
32de7d24 | 6460 | if ( id != 0 ) |
43d811ea | 6461 | { |
42e69d6b VZ |
6462 | wxKeyEvent event(wxEVT_CHAR_HOOK); |
6463 | if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN ) | |
08158721 | 6464 | event.m_altDown = true; |
c085e333 | 6465 | |
687706f5 | 6466 | event.SetEventObject(NULL); |
42e69d6b | 6467 | event.m_keyCode = id; |
3f7bc32b VZ |
6468 | event.m_shiftDown = wxIsShiftDown(); |
6469 | event.m_controlDown = wxIsCtrlDown(); | |
f0b1ccde | 6470 | #ifndef __WXWINCE__ |
1bf77ee5 | 6471 | event.SetTimestamp(::GetMessageTime()); |
f0b1ccde | 6472 | #endif |
42e69d6b | 6473 | wxWindow *win = wxGetActiveWindow(); |
32de7d24 | 6474 | wxEvtHandler *handler; |
42e69d6b VZ |
6475 | if ( win ) |
6476 | { | |
32de7d24 VZ |
6477 | handler = win->GetEventHandler(); |
6478 | event.SetId(win->GetId()); | |
42e69d6b VZ |
6479 | } |
6480 | else | |
6481 | { | |
32de7d24 | 6482 | handler = wxTheApp; |
abb74e0f | 6483 | event.SetId(wxID_ANY); |
32de7d24 VZ |
6484 | } |
6485 | ||
6486 | if ( handler && handler->ProcessEvent(event) ) | |
6487 | { | |
6488 | // processed | |
6489 | return 1; | |
42e69d6b | 6490 | } |
43d811ea JS |
6491 | } |
6492 | } | |
32de7d24 | 6493 | |
42e69d6b | 6494 | return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam); |
4fabb575 | 6495 | } |
cd4453e5 | 6496 | |
23c26b99 VZ |
6497 | void wxSetKeyboardHook(bool doIt) |
6498 | { | |
6499 | if ( doIt ) | |
6500 | { | |
6501 | wxTheKeyboardHook = ::SetWindowsHookEx | |
6502 | ( | |
6503 | WH_KEYBOARD, | |
6504 | (HOOKPROC)wxKeyboardHook, | |
6505 | NULL, // must be NULL for process hook | |
6506 | ::GetCurrentThreadId() | |
6507 | ); | |
6508 | if ( !wxTheKeyboardHook ) | |
6509 | { | |
9a83f860 | 6510 | wxLogLastError(wxT("SetWindowsHookEx(wxKeyboardHook)")); |
23c26b99 VZ |
6511 | } |
6512 | } | |
6513 | else // uninstall | |
6514 | { | |
6515 | if ( wxTheKeyboardHook ) | |
6516 | ::UnhookWindowsHookEx(wxTheKeyboardHook); | |
6517 | } | |
6518 | } | |
6519 | ||
cd4453e5 | 6520 | #endif // !__WXMICROWIN__ |
4fabb575 | 6521 | |
50e08f9d | 6522 | #if wxDEBUG_LEVEL >= 2 |
4a712ba3 | 6523 | const wxChar *wxGetMessageName(int message) |
47cbd6da | 6524 | { |
42e69d6b VZ |
6525 | switch ( message ) |
6526 | { | |
4a712ba3 VZ |
6527 | case 0x0000: return wxT("WM_NULL"); |
6528 | case 0x0001: return wxT("WM_CREATE"); | |
6529 | case 0x0002: return wxT("WM_DESTROY"); | |
6530 | case 0x0003: return wxT("WM_MOVE"); | |
6531 | case 0x0005: return wxT("WM_SIZE"); | |
6532 | case 0x0006: return wxT("WM_ACTIVATE"); | |
6533 | case 0x0007: return wxT("WM_SETFOCUS"); | |
6534 | case 0x0008: return wxT("WM_KILLFOCUS"); | |
6535 | case 0x000A: return wxT("WM_ENABLE"); | |
6536 | case 0x000B: return wxT("WM_SETREDRAW"); | |
6537 | case 0x000C: return wxT("WM_SETTEXT"); | |
6538 | case 0x000D: return wxT("WM_GETTEXT"); | |
6539 | case 0x000E: return wxT("WM_GETTEXTLENGTH"); | |
6540 | case 0x000F: return wxT("WM_PAINT"); | |
6541 | case 0x0010: return wxT("WM_CLOSE"); | |
6542 | case 0x0011: return wxT("WM_QUERYENDSESSION"); | |
6543 | case 0x0012: return wxT("WM_QUIT"); | |
6544 | case 0x0013: return wxT("WM_QUERYOPEN"); | |
6545 | case 0x0014: return wxT("WM_ERASEBKGND"); | |
6546 | case 0x0015: return wxT("WM_SYSCOLORCHANGE"); | |
6547 | case 0x0016: return wxT("WM_ENDSESSION"); | |
6548 | case 0x0017: return wxT("WM_SYSTEMERROR"); | |
6549 | case 0x0018: return wxT("WM_SHOWWINDOW"); | |
6550 | case 0x0019: return wxT("WM_CTLCOLOR"); | |
6551 | case 0x001A: return wxT("WM_WININICHANGE"); | |
6552 | case 0x001B: return wxT("WM_DEVMODECHANGE"); | |
6553 | case 0x001C: return wxT("WM_ACTIVATEAPP"); | |
6554 | case 0x001D: return wxT("WM_FONTCHANGE"); | |
6555 | case 0x001E: return wxT("WM_TIMECHANGE"); | |
6556 | case 0x001F: return wxT("WM_CANCELMODE"); | |
6557 | case 0x0020: return wxT("WM_SETCURSOR"); | |
6558 | case 0x0021: return wxT("WM_MOUSEACTIVATE"); | |
6559 | case 0x0022: return wxT("WM_CHILDACTIVATE"); | |
6560 | case 0x0023: return wxT("WM_QUEUESYNC"); | |
6561 | case 0x0024: return wxT("WM_GETMINMAXINFO"); | |
6562 | case 0x0026: return wxT("WM_PAINTICON"); | |
6563 | case 0x0027: return wxT("WM_ICONERASEBKGND"); | |
6564 | case 0x0028: return wxT("WM_NEXTDLGCTL"); | |
6565 | case 0x002A: return wxT("WM_SPOOLERSTATUS"); | |
6566 | case 0x002B: return wxT("WM_DRAWITEM"); | |
6567 | case 0x002C: return wxT("WM_MEASUREITEM"); | |
6568 | case 0x002D: return wxT("WM_DELETEITEM"); | |
6569 | case 0x002E: return wxT("WM_VKEYTOITEM"); | |
6570 | case 0x002F: return wxT("WM_CHARTOITEM"); | |
6571 | case 0x0030: return wxT("WM_SETFONT"); | |
6572 | case 0x0031: return wxT("WM_GETFONT"); | |
6573 | case 0x0037: return wxT("WM_QUERYDRAGICON"); | |
6574 | case 0x0039: return wxT("WM_COMPAREITEM"); | |
6575 | case 0x0041: return wxT("WM_COMPACTING"); | |
6576 | case 0x0044: return wxT("WM_COMMNOTIFY"); | |
6577 | case 0x0046: return wxT("WM_WINDOWPOSCHANGING"); | |
6578 | case 0x0047: return wxT("WM_WINDOWPOSCHANGED"); | |
6579 | case 0x0048: return wxT("WM_POWER"); | |
6580 | ||
6581 | case 0x004A: return wxT("WM_COPYDATA"); | |
6582 | case 0x004B: return wxT("WM_CANCELJOURNAL"); | |
6583 | case 0x004E: return wxT("WM_NOTIFY"); | |
6584 | case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST"); | |
6585 | case 0x0051: return wxT("WM_INPUTLANGCHANGE"); | |
6586 | case 0x0052: return wxT("WM_TCARD"); | |
6587 | case 0x0053: return wxT("WM_HELP"); | |
6588 | case 0x0054: return wxT("WM_USERCHANGED"); | |
6589 | case 0x0055: return wxT("WM_NOTIFYFORMAT"); | |
6590 | case 0x007B: return wxT("WM_CONTEXTMENU"); | |
6591 | case 0x007C: return wxT("WM_STYLECHANGING"); | |
6592 | case 0x007D: return wxT("WM_STYLECHANGED"); | |
6593 | case 0x007E: return wxT("WM_DISPLAYCHANGE"); | |
6594 | case 0x007F: return wxT("WM_GETICON"); | |
6595 | case 0x0080: return wxT("WM_SETICON"); | |
6596 | ||
6597 | case 0x0081: return wxT("WM_NCCREATE"); | |
6598 | case 0x0082: return wxT("WM_NCDESTROY"); | |
6599 | case 0x0083: return wxT("WM_NCCALCSIZE"); | |
6600 | case 0x0084: return wxT("WM_NCHITTEST"); | |
6601 | case 0x0085: return wxT("WM_NCPAINT"); | |
6602 | case 0x0086: return wxT("WM_NCACTIVATE"); | |
6603 | case 0x0087: return wxT("WM_GETDLGCODE"); | |
6604 | case 0x00A0: return wxT("WM_NCMOUSEMOVE"); | |
6605 | case 0x00A1: return wxT("WM_NCLBUTTONDOWN"); | |
6606 | case 0x00A2: return wxT("WM_NCLBUTTONUP"); | |
6607 | case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK"); | |
6608 | case 0x00A4: return wxT("WM_NCRBUTTONDOWN"); | |
6609 | case 0x00A5: return wxT("WM_NCRBUTTONUP"); | |
6610 | case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK"); | |
6611 | case 0x00A7: return wxT("WM_NCMBUTTONDOWN"); | |
6612 | case 0x00A8: return wxT("WM_NCMBUTTONUP"); | |
6613 | case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK"); | |
609da8bb VZ |
6614 | |
6615 | case 0x00B0: return wxT("EM_GETSEL"); | |
6616 | case 0x00B1: return wxT("EM_SETSEL"); | |
6617 | case 0x00B2: return wxT("EM_GETRECT"); | |
6618 | case 0x00B3: return wxT("EM_SETRECT"); | |
6619 | case 0x00B4: return wxT("EM_SETRECTNP"); | |
6620 | case 0x00B5: return wxT("EM_SCROLL"); | |
6621 | case 0x00B6: return wxT("EM_LINESCROLL"); | |
6622 | case 0x00B7: return wxT("EM_SCROLLCARET"); | |
6623 | case 0x00B8: return wxT("EM_GETMODIFY"); | |
6624 | case 0x00B9: return wxT("EM_SETMODIFY"); | |
6625 | case 0x00BA: return wxT("EM_GETLINECOUNT"); | |
6626 | case 0x00BB: return wxT("EM_LINEINDEX"); | |
6627 | case 0x00BC: return wxT("EM_SETHANDLE"); | |
6628 | case 0x00BD: return wxT("EM_GETHANDLE"); | |
6629 | case 0x00BE: return wxT("EM_GETTHUMB"); | |
6630 | case 0x00C1: return wxT("EM_LINELENGTH"); | |
6631 | case 0x00C2: return wxT("EM_REPLACESEL"); | |
6632 | case 0x00C4: return wxT("EM_GETLINE"); | |
6633 | case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */ | |
6634 | case 0x00C6: return wxT("EM_CANUNDO"); | |
6635 | case 0x00C7: return wxT("EM_UNDO"); | |
6636 | case 0x00C8: return wxT("EM_FMTLINES"); | |
6637 | case 0x00C9: return wxT("EM_LINEFROMCHAR"); | |
6638 | case 0x00CB: return wxT("EM_SETTABSTOPS"); | |
6639 | case 0x00CC: return wxT("EM_SETPASSWORDCHAR"); | |
6640 | case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER"); | |
6641 | case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE"); | |
6642 | case 0x00CF: return wxT("EM_SETREADONLY"); | |
6643 | case 0x00D0: return wxT("EM_SETWORDBREAKPROC"); | |
6644 | case 0x00D1: return wxT("EM_GETWORDBREAKPROC"); | |
6645 | case 0x00D2: return wxT("EM_GETPASSWORDCHAR"); | |
6646 | case 0x00D3: return wxT("EM_SETMARGINS"); | |
6647 | case 0x00D4: return wxT("EM_GETMARGINS"); | |
6648 | case 0x00D5: return wxT("EM_GETLIMITTEXT"); | |
6649 | case 0x00D6: return wxT("EM_POSFROMCHAR"); | |
6650 | case 0x00D7: return wxT("EM_CHARFROMPOS"); | |
6651 | case 0x00D8: return wxT("EM_SETIMESTATUS"); | |
6652 | case 0x00D9: return wxT("EM_GETIMESTATUS"); | |
6653 | ||
4a712ba3 VZ |
6654 | case 0x0100: return wxT("WM_KEYDOWN"); |
6655 | case 0x0101: return wxT("WM_KEYUP"); | |
6656 | case 0x0102: return wxT("WM_CHAR"); | |
6657 | case 0x0103: return wxT("WM_DEADCHAR"); | |
6658 | case 0x0104: return wxT("WM_SYSKEYDOWN"); | |
6659 | case 0x0105: return wxT("WM_SYSKEYUP"); | |
6660 | case 0x0106: return wxT("WM_SYSCHAR"); | |
6661 | case 0x0107: return wxT("WM_SYSDEADCHAR"); | |
6662 | case 0x0108: return wxT("WM_KEYLAST"); | |
6663 | ||
6664 | case 0x010D: return wxT("WM_IME_STARTCOMPOSITION"); | |
6665 | case 0x010E: return wxT("WM_IME_ENDCOMPOSITION"); | |
6666 | case 0x010F: return wxT("WM_IME_COMPOSITION"); | |
6667 | ||
6668 | case 0x0110: return wxT("WM_INITDIALOG"); | |
6669 | case 0x0111: return wxT("WM_COMMAND"); | |
6670 | case 0x0112: return wxT("WM_SYSCOMMAND"); | |
6671 | case 0x0113: return wxT("WM_TIMER"); | |
6672 | case 0x0114: return wxT("WM_HSCROLL"); | |
6673 | case 0x0115: return wxT("WM_VSCROLL"); | |
6674 | case 0x0116: return wxT("WM_INITMENU"); | |
6675 | case 0x0117: return wxT("WM_INITMENUPOPUP"); | |
6676 | case 0x011F: return wxT("WM_MENUSELECT"); | |
6677 | case 0x0120: return wxT("WM_MENUCHAR"); | |
6678 | case 0x0121: return wxT("WM_ENTERIDLE"); | |
609da8bb | 6679 | |
ff9b9665 VZ |
6680 | case 0x0127: return wxT("WM_CHANGEUISTATE"); |
6681 | case 0x0128: return wxT("WM_UPDATEUISTATE"); | |
6682 | case 0x0129: return wxT("WM_QUERYUISTATE"); | |
6683 | ||
609da8bb VZ |
6684 | case 0x0132: return wxT("WM_CTLCOLORMSGBOX"); |
6685 | case 0x0133: return wxT("WM_CTLCOLOREDIT"); | |
6686 | case 0x0134: return wxT("WM_CTLCOLORLISTBOX"); | |
6687 | case 0x0135: return wxT("WM_CTLCOLORBTN"); | |
6688 | case 0x0136: return wxT("WM_CTLCOLORDLG"); | |
6689 | case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR"); | |
6690 | case 0x0138: return wxT("WM_CTLCOLORSTATIC"); | |
6691 | case 0x01E1: return wxT("MN_GETHMENU"); | |
6692 | ||
4a712ba3 VZ |
6693 | case 0x0200: return wxT("WM_MOUSEMOVE"); |
6694 | case 0x0201: return wxT("WM_LBUTTONDOWN"); | |
6695 | case 0x0202: return wxT("WM_LBUTTONUP"); | |
6696 | case 0x0203: return wxT("WM_LBUTTONDBLCLK"); | |
6697 | case 0x0204: return wxT("WM_RBUTTONDOWN"); | |
6698 | case 0x0205: return wxT("WM_RBUTTONUP"); | |
6699 | case 0x0206: return wxT("WM_RBUTTONDBLCLK"); | |
6700 | case 0x0207: return wxT("WM_MBUTTONDOWN"); | |
6701 | case 0x0208: return wxT("WM_MBUTTONUP"); | |
6702 | case 0x0209: return wxT("WM_MBUTTONDBLCLK"); | |
6703 | case 0x020A: return wxT("WM_MOUSEWHEEL"); | |
01101e2d VZ |
6704 | case 0x020B: return wxT("WM_XBUTTONDOWN"); |
6705 | case 0x020C: return wxT("WM_XBUTTONUP"); | |
6706 | case 0x020D: return wxT("WM_XBUTTONDBLCLK"); | |
4a712ba3 VZ |
6707 | case 0x0210: return wxT("WM_PARENTNOTIFY"); |
6708 | case 0x0211: return wxT("WM_ENTERMENULOOP"); | |
6709 | case 0x0212: return wxT("WM_EXITMENULOOP"); | |
6710 | ||
6711 | case 0x0213: return wxT("WM_NEXTMENU"); | |
6712 | case 0x0214: return wxT("WM_SIZING"); | |
6713 | case 0x0215: return wxT("WM_CAPTURECHANGED"); | |
6714 | case 0x0216: return wxT("WM_MOVING"); | |
6715 | case 0x0218: return wxT("WM_POWERBROADCAST"); | |
6716 | case 0x0219: return wxT("WM_DEVICECHANGE"); | |
6717 | ||
6718 | case 0x0220: return wxT("WM_MDICREATE"); | |
6719 | case 0x0221: return wxT("WM_MDIDESTROY"); | |
6720 | case 0x0222: return wxT("WM_MDIACTIVATE"); | |
6721 | case 0x0223: return wxT("WM_MDIRESTORE"); | |
6722 | case 0x0224: return wxT("WM_MDINEXT"); | |
6723 | case 0x0225: return wxT("WM_MDIMAXIMIZE"); | |
6724 | case 0x0226: return wxT("WM_MDITILE"); | |
6725 | case 0x0227: return wxT("WM_MDICASCADE"); | |
6726 | case 0x0228: return wxT("WM_MDIICONARRANGE"); | |
6727 | case 0x0229: return wxT("WM_MDIGETACTIVE"); | |
6728 | case 0x0230: return wxT("WM_MDISETMENU"); | |
6729 | case 0x0233: return wxT("WM_DROPFILES"); | |
6730 | ||
6731 | case 0x0281: return wxT("WM_IME_SETCONTEXT"); | |
6732 | case 0x0282: return wxT("WM_IME_NOTIFY"); | |
6733 | case 0x0283: return wxT("WM_IME_CONTROL"); | |
6734 | case 0x0284: return wxT("WM_IME_COMPOSITIONFULL"); | |
6735 | case 0x0285: return wxT("WM_IME_SELECT"); | |
6736 | case 0x0286: return wxT("WM_IME_CHAR"); | |
6737 | case 0x0290: return wxT("WM_IME_KEYDOWN"); | |
6738 | case 0x0291: return wxT("WM_IME_KEYUP"); | |
6739 | ||
609da8bb VZ |
6740 | case 0x02A0: return wxT("WM_NCMOUSEHOVER"); |
6741 | case 0x02A1: return wxT("WM_MOUSEHOVER"); | |
6742 | case 0x02A2: return wxT("WM_NCMOUSELEAVE"); | |
6743 | case 0x02A3: return wxT("WM_MOUSELEAVE"); | |
6744 | ||
4a712ba3 VZ |
6745 | case 0x0300: return wxT("WM_CUT"); |
6746 | case 0x0301: return wxT("WM_COPY"); | |
6747 | case 0x0302: return wxT("WM_PASTE"); | |
6748 | case 0x0303: return wxT("WM_CLEAR"); | |
6749 | case 0x0304: return wxT("WM_UNDO"); | |
6750 | case 0x0305: return wxT("WM_RENDERFORMAT"); | |
6751 | case 0x0306: return wxT("WM_RENDERALLFORMATS"); | |
6752 | case 0x0307: return wxT("WM_DESTROYCLIPBOARD"); | |
6753 | case 0x0308: return wxT("WM_DRAWCLIPBOARD"); | |
6754 | case 0x0309: return wxT("WM_PAINTCLIPBOARD"); | |
6755 | case 0x030A: return wxT("WM_VSCROLLCLIPBOARD"); | |
6756 | case 0x030B: return wxT("WM_SIZECLIPBOARD"); | |
6757 | case 0x030C: return wxT("WM_ASKCBFORMATNAME"); | |
6758 | case 0x030D: return wxT("WM_CHANGECBCHAIN"); | |
6759 | case 0x030E: return wxT("WM_HSCROLLCLIPBOARD"); | |
6760 | case 0x030F: return wxT("WM_QUERYNEWPALETTE"); | |
6761 | case 0x0310: return wxT("WM_PALETTEISCHANGING"); | |
6762 | case 0x0311: return wxT("WM_PALETTECHANGED"); | |
4a712ba3 | 6763 | case 0x0312: return wxT("WM_HOTKEY"); |
609da8bb VZ |
6764 | |
6765 | case 0x0317: return wxT("WM_PRINT"); | |
6766 | case 0x0318: return wxT("WM_PRINTCLIENT"); | |
c085e333 | 6767 | |
2d0a075d JS |
6768 | // common controls messages - although they're not strictly speaking |
6769 | // standard, it's nice to decode them nevertheless | |
a02eb1d2 | 6770 | |
2d0a075d | 6771 | // listview |
4a712ba3 VZ |
6772 | case 0x1000 + 0: return wxT("LVM_GETBKCOLOR"); |
6773 | case 0x1000 + 1: return wxT("LVM_SETBKCOLOR"); | |
6774 | case 0x1000 + 2: return wxT("LVM_GETIMAGELIST"); | |
6775 | case 0x1000 + 3: return wxT("LVM_SETIMAGELIST"); | |
6776 | case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT"); | |
6777 | case 0x1000 + 5: return wxT("LVM_GETITEMA"); | |
6778 | case 0x1000 + 75: return wxT("LVM_GETITEMW"); | |
6779 | case 0x1000 + 6: return wxT("LVM_SETITEMA"); | |
6780 | case 0x1000 + 76: return wxT("LVM_SETITEMW"); | |
6781 | case 0x1000 + 7: return wxT("LVM_INSERTITEMA"); | |
6782 | case 0x1000 + 77: return wxT("LVM_INSERTITEMW"); | |
6783 | case 0x1000 + 8: return wxT("LVM_DELETEITEM"); | |
6784 | case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS"); | |
6785 | case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK"); | |
6786 | case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK"); | |
6787 | case 0x1000 + 12: return wxT("LVM_GETNEXTITEM"); | |
6788 | case 0x1000 + 13: return wxT("LVM_FINDITEMA"); | |
6789 | case 0x1000 + 83: return wxT("LVM_FINDITEMW"); | |
6790 | case 0x1000 + 14: return wxT("LVM_GETITEMRECT"); | |
6791 | case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION"); | |
6792 | case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION"); | |
6793 | case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA"); | |
6794 | case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW"); | |
6795 | case 0x1000 + 18: return wxT("LVM_HITTEST"); | |
6796 | case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE"); | |
6797 | case 0x1000 + 20: return wxT("LVM_SCROLL"); | |
6798 | case 0x1000 + 21: return wxT("LVM_REDRAWITEMS"); | |
6799 | case 0x1000 + 22: return wxT("LVM_ARRANGE"); | |
6800 | case 0x1000 + 23: return wxT("LVM_EDITLABELA"); | |
6801 | case 0x1000 + 118: return wxT("LVM_EDITLABELW"); | |
6802 | case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL"); | |
6803 | case 0x1000 + 25: return wxT("LVM_GETCOLUMNA"); | |
6804 | case 0x1000 + 95: return wxT("LVM_GETCOLUMNW"); | |
6805 | case 0x1000 + 26: return wxT("LVM_SETCOLUMNA"); | |
6806 | case 0x1000 + 96: return wxT("LVM_SETCOLUMNW"); | |
6807 | case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA"); | |
6808 | case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW"); | |
6809 | case 0x1000 + 28: return wxT("LVM_DELETECOLUMN"); | |
6810 | case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH"); | |
6811 | case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH"); | |
6812 | case 0x1000 + 31: return wxT("LVM_GETHEADER"); | |
6813 | case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE"); | |
6814 | case 0x1000 + 34: return wxT("LVM_GETVIEWRECT"); | |
6815 | case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR"); | |
6816 | case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR"); | |
6817 | case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR"); | |
6818 | case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR"); | |
6819 | case 0x1000 + 39: return wxT("LVM_GETTOPINDEX"); | |
6820 | case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE"); | |
6821 | case 0x1000 + 41: return wxT("LVM_GETORIGIN"); | |
6822 | case 0x1000 + 42: return wxT("LVM_UPDATE"); | |
6823 | case 0x1000 + 43: return wxT("LVM_SETITEMSTATE"); | |
6824 | case 0x1000 + 44: return wxT("LVM_GETITEMSTATE"); | |
6825 | case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA"); | |
6826 | case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW"); | |
6827 | case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA"); | |
6828 | case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW"); | |
6829 | case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT"); | |
6830 | case 0x1000 + 48: return wxT("LVM_SORTITEMS"); | |
6831 | case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32"); | |
6832 | case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT"); | |
6833 | case 0x1000 + 51: return wxT("LVM_GETITEMSPACING"); | |
6834 | case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA"); | |
6835 | case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW"); | |
6836 | case 0x1000 + 53: return wxT("LVM_SETICONSPACING"); | |
6837 | case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE"); | |
6838 | case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE"); | |
6839 | case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT"); | |
6840 | case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST"); | |
6841 | case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY"); | |
6842 | case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY"); | |
6843 | case 0x1000 + 60: return wxT("LVM_SETHOTITEM"); | |
6844 | case 0x1000 + 61: return wxT("LVM_GETHOTITEM"); | |
6845 | case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR"); | |
6846 | case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR"); | |
6847 | case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT"); | |
6848 | case 0x1000 + 65: return wxT("LVM_SETWORKAREA"); | |
c085e333 | 6849 | |
2d0a075d | 6850 | // tree view |
4a712ba3 VZ |
6851 | case 0x1100 + 0: return wxT("TVM_INSERTITEMA"); |
6852 | case 0x1100 + 50: return wxT("TVM_INSERTITEMW"); | |
6853 | case 0x1100 + 1: return wxT("TVM_DELETEITEM"); | |
6854 | case 0x1100 + 2: return wxT("TVM_EXPAND"); | |
6855 | case 0x1100 + 4: return wxT("TVM_GETITEMRECT"); | |
6856 | case 0x1100 + 5: return wxT("TVM_GETCOUNT"); | |
6857 | case 0x1100 + 6: return wxT("TVM_GETINDENT"); | |
6858 | case 0x1100 + 7: return wxT("TVM_SETINDENT"); | |
6859 | case 0x1100 + 8: return wxT("TVM_GETIMAGELIST"); | |
6860 | case 0x1100 + 9: return wxT("TVM_SETIMAGELIST"); | |
6861 | case 0x1100 + 10: return wxT("TVM_GETNEXTITEM"); | |
6862 | case 0x1100 + 11: return wxT("TVM_SELECTITEM"); | |
6863 | case 0x1100 + 12: return wxT("TVM_GETITEMA"); | |
6864 | case 0x1100 + 62: return wxT("TVM_GETITEMW"); | |
6865 | case 0x1100 + 13: return wxT("TVM_SETITEMA"); | |
6866 | case 0x1100 + 63: return wxT("TVM_SETITEMW"); | |
6867 | case 0x1100 + 14: return wxT("TVM_EDITLABELA"); | |
6868 | case 0x1100 + 65: return wxT("TVM_EDITLABELW"); | |
6869 | case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL"); | |
6870 | case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT"); | |
6871 | case 0x1100 + 17: return wxT("TVM_HITTEST"); | |
6872 | case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE"); | |
6873 | case 0x1100 + 19: return wxT("TVM_SORTCHILDREN"); | |
6874 | case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE"); | |
6875 | case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB"); | |
6876 | case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW"); | |
6877 | case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA"); | |
6878 | case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW"); | |
6879 | case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS"); | |
6880 | case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS"); | |
c085e333 | 6881 | |
2d0a075d | 6882 | // header |
4a712ba3 VZ |
6883 | case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT"); |
6884 | case 0x1200 + 1: return wxT("HDM_INSERTITEMA"); | |
6885 | case 0x1200 + 10: return wxT("HDM_INSERTITEMW"); | |
6886 | case 0x1200 + 2: return wxT("HDM_DELETEITEM"); | |
6887 | case 0x1200 + 3: return wxT("HDM_GETITEMA"); | |
6888 | case 0x1200 + 11: return wxT("HDM_GETITEMW"); | |
6889 | case 0x1200 + 4: return wxT("HDM_SETITEMA"); | |
6890 | case 0x1200 + 12: return wxT("HDM_SETITEMW"); | |
6891 | case 0x1200 + 5: return wxT("HDM_LAYOUT"); | |
6892 | case 0x1200 + 6: return wxT("HDM_HITTEST"); | |
6893 | case 0x1200 + 7: return wxT("HDM_GETITEMRECT"); | |
6894 | case 0x1200 + 8: return wxT("HDM_SETIMAGELIST"); | |
6895 | case 0x1200 + 9: return wxT("HDM_GETIMAGELIST"); | |
6896 | case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX"); | |
6897 | case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE"); | |
6898 | case 0x1200 + 17: return wxT("HDM_GETORDERARRAY"); | |
6899 | case 0x1200 + 18: return wxT("HDM_SETORDERARRAY"); | |
6900 | case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER"); | |
c085e333 | 6901 | |
2d0a075d | 6902 | // tab control |
4a712ba3 VZ |
6903 | case 0x1300 + 2: return wxT("TCM_GETIMAGELIST"); |
6904 | case 0x1300 + 3: return wxT("TCM_SETIMAGELIST"); | |
6905 | case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT"); | |
6906 | case 0x1300 + 5: return wxT("TCM_GETITEMA"); | |
6907 | case 0x1300 + 60: return wxT("TCM_GETITEMW"); | |
6908 | case 0x1300 + 6: return wxT("TCM_SETITEMA"); | |
6909 | case 0x1300 + 61: return wxT("TCM_SETITEMW"); | |
6910 | case 0x1300 + 7: return wxT("TCM_INSERTITEMA"); | |
6911 | case 0x1300 + 62: return wxT("TCM_INSERTITEMW"); | |
6912 | case 0x1300 + 8: return wxT("TCM_DELETEITEM"); | |
6913 | case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS"); | |
6914 | case 0x1300 + 10: return wxT("TCM_GETITEMRECT"); | |
6915 | case 0x1300 + 11: return wxT("TCM_GETCURSEL"); | |
6916 | case 0x1300 + 12: return wxT("TCM_SETCURSEL"); | |
6917 | case 0x1300 + 13: return wxT("TCM_HITTEST"); | |
6918 | case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA"); | |
6919 | case 0x1300 + 40: return wxT("TCM_ADJUSTRECT"); | |
6920 | case 0x1300 + 41: return wxT("TCM_SETITEMSIZE"); | |
6921 | case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE"); | |
6922 | case 0x1300 + 43: return wxT("TCM_SETPADDING"); | |
6923 | case 0x1300 + 44: return wxT("TCM_GETROWCOUNT"); | |
6924 | case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS"); | |
6925 | case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS"); | |
6926 | case 0x1300 + 47: return wxT("TCM_GETCURFOCUS"); | |
6927 | case 0x1300 + 48: return wxT("TCM_SETCURFOCUS"); | |
6928 | case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH"); | |
6929 | case 0x1300 + 50: return wxT("TCM_DESELECTALL"); | |
c085e333 | 6930 | |
2d0a075d | 6931 | // toolbar |
4a712ba3 VZ |
6932 | case WM_USER+1: return wxT("TB_ENABLEBUTTON"); |
6933 | case WM_USER+2: return wxT("TB_CHECKBUTTON"); | |
6934 | case WM_USER+3: return wxT("TB_PRESSBUTTON"); | |
6935 | case WM_USER+4: return wxT("TB_HIDEBUTTON"); | |
6936 | case WM_USER+5: return wxT("TB_INDETERMINATE"); | |
6937 | case WM_USER+9: return wxT("TB_ISBUTTONENABLED"); | |
6938 | case WM_USER+10: return wxT("TB_ISBUTTONCHECKED"); | |
6939 | case WM_USER+11: return wxT("TB_ISBUTTONPRESSED"); | |
6940 | case WM_USER+12: return wxT("TB_ISBUTTONHIDDEN"); | |
6941 | case WM_USER+13: return wxT("TB_ISBUTTONINDETERMINATE"); | |
6942 | case WM_USER+17: return wxT("TB_SETSTATE"); | |
6943 | case WM_USER+18: return wxT("TB_GETSTATE"); | |
6944 | case WM_USER+19: return wxT("TB_ADDBITMAP"); | |
6945 | case WM_USER+20: return wxT("TB_ADDBUTTONS"); | |
6946 | case WM_USER+21: return wxT("TB_INSERTBUTTON"); | |
6947 | case WM_USER+22: return wxT("TB_DELETEBUTTON"); | |
6948 | case WM_USER+23: return wxT("TB_GETBUTTON"); | |
6949 | case WM_USER+24: return wxT("TB_BUTTONCOUNT"); | |
6950 | case WM_USER+25: return wxT("TB_COMMANDTOINDEX"); | |
6951 | case WM_USER+26: return wxT("TB_SAVERESTOREA"); | |
6952 | case WM_USER+76: return wxT("TB_SAVERESTOREW"); | |
6953 | case WM_USER+27: return wxT("TB_CUSTOMIZE"); | |
6954 | case WM_USER+28: return wxT("TB_ADDSTRINGA"); | |
6955 | case WM_USER+77: return wxT("TB_ADDSTRINGW"); | |
6956 | case WM_USER+29: return wxT("TB_GETITEMRECT"); | |
6957 | case WM_USER+30: return wxT("TB_BUTTONSTRUCTSIZE"); | |
6958 | case WM_USER+31: return wxT("TB_SETBUTTONSIZE"); | |
6959 | case WM_USER+32: return wxT("TB_SETBITMAPSIZE"); | |
6960 | case WM_USER+33: return wxT("TB_AUTOSIZE"); | |
6961 | case WM_USER+35: return wxT("TB_GETTOOLTIPS"); | |
6962 | case WM_USER+36: return wxT("TB_SETTOOLTIPS"); | |
6963 | case WM_USER+37: return wxT("TB_SETPARENT"); | |
6964 | case WM_USER+39: return wxT("TB_SETROWS"); | |
6965 | case WM_USER+40: return wxT("TB_GETROWS"); | |
6966 | case WM_USER+42: return wxT("TB_SETCMDID"); | |
6967 | case WM_USER+43: return wxT("TB_CHANGEBITMAP"); | |
6968 | case WM_USER+44: return wxT("TB_GETBITMAP"); | |
6969 | case WM_USER+45: return wxT("TB_GETBUTTONTEXTA"); | |
6970 | case WM_USER+75: return wxT("TB_GETBUTTONTEXTW"); | |
6971 | case WM_USER+46: return wxT("TB_REPLACEBITMAP"); | |
6972 | case WM_USER+47: return wxT("TB_SETINDENT"); | |
6973 | case WM_USER+48: return wxT("TB_SETIMAGELIST"); | |
6974 | case WM_USER+49: return wxT("TB_GETIMAGELIST"); | |
6975 | case WM_USER+50: return wxT("TB_LOADIMAGES"); | |
6976 | case WM_USER+51: return wxT("TB_GETRECT"); | |
6977 | case WM_USER+52: return wxT("TB_SETHOTIMAGELIST"); | |
6978 | case WM_USER+53: return wxT("TB_GETHOTIMAGELIST"); | |
6979 | case WM_USER+54: return wxT("TB_SETDISABLEDIMAGELIST"); | |
6980 | case WM_USER+55: return wxT("TB_GETDISABLEDIMAGELIST"); | |
6981 | case WM_USER+56: return wxT("TB_SETSTYLE"); | |
6982 | case WM_USER+57: return wxT("TB_GETSTYLE"); | |
6983 | case WM_USER+58: return wxT("TB_GETBUTTONSIZE"); | |
6984 | case WM_USER+59: return wxT("TB_SETBUTTONWIDTH"); | |
6985 | case WM_USER+60: return wxT("TB_SETMAXTEXTROWS"); | |
6986 | case WM_USER+61: return wxT("TB_GETTEXTROWS"); | |
6987 | case WM_USER+41: return wxT("TB_GETBITMAPFLAGS"); | |
c085e333 | 6988 | |
42e69d6b | 6989 | default: |
4a712ba3 VZ |
6990 | static wxString s_szBuf; |
6991 | s_szBuf.Printf(wxT("<unknown message = %d>"), message); | |
6992 | return s_szBuf.c_str(); | |
42e69d6b | 6993 | } |
47cbd6da | 6994 | } |
4b6a582b | 6995 | #endif // wxDEBUG_LEVEL >= 2 |
4aff28fc | 6996 | |
1e6feb95 | 6997 | static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win) |
f6bcfd97 BP |
6998 | { |
6999 | // prepare the DC | |
7000 | TEXTMETRIC tm; | |
7001 | HWND hwnd = GetHwndOf(win); | |
7002 | HDC hdc = ::GetDC(hwnd); | |
7003 | ||
7004 | #if !wxDIALOG_UNIT_COMPATIBILITY | |
7005 | // and select the current font into it | |
7006 | HFONT hfont = GetHfontOf(win->GetFont()); | |
7007 | if ( hfont ) | |
7008 | { | |
7009 | hfont = (HFONT)::SelectObject(hdc, hfont); | |
7010 | } | |
7011 | #endif | |
7012 | ||
7013 | // finally retrieve the text metrics from it | |
7014 | GetTextMetrics(hdc, &tm); | |
7015 | ||
7016 | #if !wxDIALOG_UNIT_COMPATIBILITY | |
7017 | // and clean up | |
7018 | if ( hfont ) | |
7019 | { | |
7020 | (void)::SelectObject(hdc, hfont); | |
7021 | } | |
7022 | #endif | |
7023 | ||
7024 | ::ReleaseDC(hwnd, hdc); | |
7025 | ||
7026 | return tm; | |
7027 | } | |
3723b7b1 JS |
7028 | |
7029 | // Find the wxWindow at the current mouse position, returning the mouse | |
7030 | // position. | |
2b5f62a0 | 7031 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) |
3723b7b1 | 7032 | { |
2b5f62a0 VZ |
7033 | pt = wxGetMousePosition(); |
7034 | return wxFindWindowAtPoint(pt); | |
57591e0e JS |
7035 | } |
7036 | ||
7037 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) | |
7038 | { | |
7039 | POINT pt2; | |
7040 | pt2.x = pt.x; | |
7041 | pt2.y = pt.y; | |
3723b7b1 | 7042 | |
ab3eae34 | 7043 | HWND hWnd = ::WindowFromPoint(pt2); |
3723b7b1 | 7044 | |
ab3eae34 | 7045 | return wxGetWindowFromHWND((WXHWND)hWnd); |
3723b7b1 JS |
7046 | } |
7047 | ||
7048 | // Get the current mouse position. | |
7049 | wxPoint wxGetMousePosition() | |
7050 | { | |
1772ead0 | 7051 | POINT pt; |
f2325516 JS |
7052 | #ifdef __WXWINCE__ |
7053 | GetCursorPosWinCE(&pt); | |
7054 | #else | |
1772ead0 | 7055 | GetCursorPos( & pt ); |
f2325516 | 7056 | #endif |
5cd16c0c | 7057 | |
1772ead0 | 7058 | return wxPoint(pt.x, pt.y); |
3723b7b1 JS |
7059 | } |
7060 | ||
5048c832 | 7061 | #if wxUSE_HOTKEY |
540b6b09 | 7062 | |
afafd942 JS |
7063 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
7064 | static void WinCEUnregisterHotKey(int modifiers, int id) | |
7065 | { | |
7066 | // Register hotkeys for the hardware buttons | |
7067 | HINSTANCE hCoreDll; | |
7068 | typedef BOOL (WINAPI *UnregisterFunc1Proc)(UINT, UINT); | |
7069 | ||
7070 | UnregisterFunc1Proc procUnregisterFunc; | |
9a83f860 | 7071 | hCoreDll = LoadLibrary(wxT("coredll.dll")); |
afafd942 JS |
7072 | if (hCoreDll) |
7073 | { | |
9a83f860 | 7074 | procUnregisterFunc = (UnregisterFunc1Proc)GetProcAddress(hCoreDll, wxT("UnregisterFunc1")); |
afafd942 JS |
7075 | if (procUnregisterFunc) |
7076 | procUnregisterFunc(modifiers, id); | |
7077 | FreeLibrary(hCoreDll); | |
7078 | } | |
7079 | } | |
7080 | #endif | |
7081 | ||
540b6b09 | 7082 | bool wxWindowMSW::RegisterHotKey(int hotkeyId, int modifiers, int keycode) |
5048c832 JS |
7083 | { |
7084 | UINT win_modifiers=0; | |
540b6b09 VZ |
7085 | if ( modifiers & wxMOD_ALT ) |
7086 | win_modifiers |= MOD_ALT; | |
7087 | if ( modifiers & wxMOD_SHIFT ) | |
7088 | win_modifiers |= MOD_SHIFT; | |
7089 | if ( modifiers & wxMOD_CONTROL ) | |
7090 | win_modifiers |= MOD_CONTROL; | |
7091 | if ( modifiers & wxMOD_WIN ) | |
7092 | win_modifiers |= MOD_WIN; | |
7093 | ||
afafd942 JS |
7094 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
7095 | // Required for PPC and Smartphone hardware buttons | |
7096 | if (keycode >= WXK_SPECIAL1 && keycode <= WXK_SPECIAL20) | |
7097 | WinCEUnregisterHotKey(win_modifiers, hotkeyId); | |
7098 | #endif | |
7099 | ||
540b6b09 VZ |
7100 | if ( !::RegisterHotKey(GetHwnd(), hotkeyId, win_modifiers, keycode) ) |
7101 | { | |
9a83f860 | 7102 | wxLogLastError(wxT("RegisterHotKey")); |
5048c832 | 7103 | |
08158721 | 7104 | return false; |
540b6b09 VZ |
7105 | } |
7106 | ||
08158721 | 7107 | return true; |
5048c832 JS |
7108 | } |
7109 | ||
7110 | bool wxWindowMSW::UnregisterHotKey(int hotkeyId) | |
7111 | { | |
afafd942 JS |
7112 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
7113 | WinCEUnregisterHotKey(MOD_WIN, hotkeyId); | |
7114 | #endif | |
7115 | ||
540b6b09 VZ |
7116 | if ( !::UnregisterHotKey(GetHwnd(), hotkeyId) ) |
7117 | { | |
9a83f860 | 7118 | wxLogLastError(wxT("UnregisterHotKey")); |
540b6b09 | 7119 | |
08158721 | 7120 | return false; |
540b6b09 VZ |
7121 | } |
7122 | ||
08158721 | 7123 | return true; |
5048c832 JS |
7124 | } |
7125 | ||
0b4f47a3 DS |
7126 | #if wxUSE_ACCEL |
7127 | ||
5048c832 JS |
7128 | bool wxWindowMSW::HandleHotKey(WXWPARAM wParam, WXLPARAM lParam) |
7129 | { | |
540b6b09 VZ |
7130 | int hotkeyId = wParam; |
7131 | int virtualKey = HIWORD(lParam); | |
7132 | int win_modifiers = LOWORD(lParam); | |
7133 | ||
5048c832 JS |
7134 | wxKeyEvent event(CreateKeyEvent(wxEVT_HOTKEY, virtualKey, wParam, lParam)); |
7135 | event.SetId(hotkeyId); | |
7136 | event.m_shiftDown = (win_modifiers & MOD_SHIFT) != 0; | |
7137 | event.m_controlDown = (win_modifiers & MOD_CONTROL) != 0; | |
7138 | event.m_altDown = (win_modifiers & MOD_ALT) != 0; | |
7139 | event.m_metaDown = (win_modifiers & MOD_WIN) != 0; | |
540b6b09 | 7140 | |
937013e0 | 7141 | return HandleWindowEvent(event); |
5048c832 | 7142 | } |
540b6b09 | 7143 | |
0b4f47a3 DS |
7144 | #endif // wxUSE_ACCEL |
7145 | ||
540b6b09 | 7146 | #endif // wxUSE_HOTKEY |
5048c832 | 7147 | |
550049c2 | 7148 | // Not tested under WinCE |
d79df32c | 7149 | #ifndef __WXWINCE__ |
d79df32c | 7150 | |
550049c2 VZ |
7151 | // this class installs a message hook which really wakes up our idle processing |
7152 | // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're | |
7153 | // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is | |
7154 | // being dragged or even inside ::MessageBox()) and so don't control message | |
7155 | // dispatching otherwise | |
7156 | class wxIdleWakeUpModule : public wxModule | |
7157 | { | |
d79df32c | 7158 | public: |
3a3c8603 | 7159 | virtual bool OnInit() |
550049c2 | 7160 | { |
3a3c8603 | 7161 | ms_hMsgHookProc = ::SetWindowsHookEx |
550049c2 VZ |
7162 | ( |
7163 | WH_GETMESSAGE, | |
7164 | &wxIdleWakeUpModule::MsgHookProc, | |
7165 | NULL, | |
7166 | GetCurrentThreadId() | |
7167 | ); | |
d79df32c | 7168 | |
550049c2 VZ |
7169 | if ( !ms_hMsgHookProc ) |
7170 | { | |
9a83f860 | 7171 | wxLogLastError(wxT("SetWindowsHookEx(WH_GETMESSAGE)")); |
550049c2 VZ |
7172 | |
7173 | return false; | |
7174 | } | |
7175 | ||
7176 | return true; | |
3a3c8603 | 7177 | } |
550049c2 | 7178 | |
3a3c8603 | 7179 | virtual void OnExit() |
550049c2 | 7180 | { |
3a3c8603 DS |
7181 | ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc); |
7182 | } | |
550049c2 | 7183 | |
3a3c8603 | 7184 | static LRESULT CALLBACK MsgHookProc(int nCode, WPARAM wParam, LPARAM lParam) |
550049c2 | 7185 | { |
3a3c8603 | 7186 | MSG *msg = (MSG*)lParam; |
34ea3c74 VZ |
7187 | |
7188 | // only process the message if it is actually going to be removed from | |
7189 | // the message queue, this prevents that the same event from being | |
7190 | // processed multiple times if now someone just called PeekMessage() | |
7191 | if ( msg->message == WM_NULL && wParam == PM_REMOVE ) | |
3a3c8603 | 7192 | { |
550049c2 | 7193 | wxTheApp->ProcessPendingEvents(); |
3a3c8603 | 7194 | } |
550049c2 | 7195 | |
3a3c8603 | 7196 | return CallNextHookEx(ms_hMsgHookProc, nCode, wParam, lParam); |
47b378bd | 7197 | } |
550049c2 | 7198 | |
d79df32c | 7199 | private: |
3a3c8603 | 7200 | static HHOOK ms_hMsgHookProc; |
550049c2 VZ |
7201 | |
7202 | DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule) | |
d79df32c | 7203 | }; |
d79df32c | 7204 | |
550049c2 VZ |
7205 | HHOOK wxIdleWakeUpModule::ms_hMsgHookProc = 0; |
7206 | ||
7207 | IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule, wxModule) | |
7208 | ||
7209 | #endif // __WXWINCE__ | |
3a3c8603 | 7210 | |
d26e1ab2 JS |
7211 | #ifdef __WXWINCE__ |
7212 | ||
7213 | #if wxUSE_STATBOX | |
7214 | static void wxAdjustZOrder(wxWindow* parent) | |
7215 | { | |
7216 | if (parent->IsKindOf(CLASSINFO(wxStaticBox))) | |
7217 | { | |
7218 | // Set the z-order correctly | |
7219 | SetWindowPos((HWND) parent->GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); | |
7220 | } | |
35bbb0c6 | 7221 | |
d26e1ab2 JS |
7222 | wxWindowList::compatibility_iterator current = parent->GetChildren().GetFirst(); |
7223 | while (current) | |
7224 | { | |
7225 | wxWindow *childWin = current->GetData(); | |
7226 | wxAdjustZOrder(childWin); | |
7227 | current = current->GetNext(); | |
7228 | } | |
7229 | } | |
7230 | #endif | |
7231 | ||
7232 | // We need to adjust the z-order of static boxes in WinCE, to | |
7233 | // make 'contained' controls visible | |
7234 | void wxWindowMSW::OnInitDialog( wxInitDialogEvent& event ) | |
7235 | { | |
7236 | #if wxUSE_STATBOX | |
7237 | wxAdjustZOrder(this); | |
7238 | #endif | |
35bbb0c6 | 7239 | |
d26e1ab2 JS |
7240 | event.Skip(); |
7241 | } | |
7242 | #endif |