]>
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 |
e259ce57 VZ |
1822 | // |
1823 | // FIXME: Unfortunately this doesn't work correctly for the maximized | |
1824 | // top level windows, the returned values are too small (e.g. | |
1825 | // under Windows 7 on a 1600*1200 screen with task bar on the | |
1826 | // right the pending size for a maximized window is 1538*1200 | |
1827 | // and WM_NCCALCSIZE returns 1528*1172 even though the correct | |
1828 | // client size of such window is 1538*1182). No idea how to fix | |
1829 | // it though, setting WS_MAXIMIZE in GWL_STYLE before calling | |
1830 | // WM_NCCALCSIZE doesn't help and AdjustWindowRectEx() doesn't | |
1831 | // work in this direction neither. So we just have to live with | |
1832 | // the slightly wrong results and relayout the window when it | |
1833 | // gets finally shown in its maximized state (see #11762). | |
dc497201 JG |
1834 | RECT rect; |
1835 | rect.left = m_pendingPosition.x; | |
1836 | rect.top = m_pendingPosition.y; | |
1837 | rect.right = rect.left + m_pendingSize.x; | |
1838 | rect.bottom = rect.top + m_pendingSize.y; | |
1839 | ||
1840 | ::SendMessage(GetHwnd(), WM_NCCALCSIZE, FALSE, (LPARAM)&rect); | |
1841 | ||
1842 | if ( x ) | |
1843 | *x = rect.right - rect.left; | |
1844 | if ( y ) | |
1845 | *y = rect.bottom - rect.top; | |
0d7f75df | 1846 | } |
0d6fdb3c | 1847 | else |
6bd9b9f2 | 1848 | #endif // wxUSE_DEFERRED_SIZING |
0d6fdb3c VZ |
1849 | { |
1850 | RECT rect = wxGetClientRect(GetHwnd()); | |
1851 | ||
1852 | if ( x ) | |
1853 | *x = rect.right; | |
1854 | if ( y ) | |
1855 | *y = rect.bottom; | |
1856 | } | |
82c9f85c VZ |
1857 | } |
1858 | ||
1859 | void wxWindowMSW::DoGetPosition(int *x, int *y) const | |
1860 | { | |
a7e0e432 VZ |
1861 | wxWindow * const parent = GetParent(); |
1862 | ||
1863 | wxPoint pos; | |
11cfa8ef VZ |
1864 | if ( m_pendingPosition != wxDefaultPosition ) |
1865 | { | |
a7e0e432 | 1866 | pos = m_pendingPosition; |
11cfa8ef VZ |
1867 | } |
1868 | else // use current position | |
1869 | { | |
1870 | RECT rect = wxGetWindowRect(GetHwnd()); | |
42e69d6b | 1871 | |
11cfa8ef VZ |
1872 | POINT point; |
1873 | point.x = rect.left; | |
1874 | point.y = rect.top; | |
42e69d6b | 1875 | |
11cfa8ef VZ |
1876 | // we do the adjustments with respect to the parent only for the "real" |
1877 | // children, not for the dialogs/frames | |
1878 | if ( !IsTopLevel() ) | |
92049cd4 | 1879 | { |
e5b5af91 VZ |
1880 | if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) |
1881 | { | |
967acfb5 | 1882 | // In RTL mode, we want the logical left x-coordinate, |
e5b5af91 VZ |
1883 | // which would be the physical right x-coordinate. |
1884 | point.x = rect.right; | |
1885 | } | |
1886 | ||
11cfa8ef VZ |
1887 | // Since we now have the absolute screen coords, if there's a |
1888 | // parent we must subtract its top left corner | |
11cfa8ef VZ |
1889 | if ( parent ) |
1890 | { | |
a7e0e432 | 1891 | ::ScreenToClient(GetHwndOf(parent), &point); |
11cfa8ef | 1892 | } |
89e3037c | 1893 | } |
42e69d6b | 1894 | |
a7e0e432 VZ |
1895 | pos.x = point.x; |
1896 | pos.y = point.y; | |
1897 | } | |
1898 | ||
1899 | // we also must adjust by the client area offset: a control which is just | |
1900 | // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx | |
1901 | if ( parent && !IsTopLevel() ) | |
1902 | { | |
1903 | const wxPoint pt(parent->GetClientAreaOrigin()); | |
1904 | pos.x -= pt.x; | |
1905 | pos.y -= pt.y; | |
11cfa8ef | 1906 | } |
a7e0e432 VZ |
1907 | |
1908 | if ( x ) | |
1909 | *x = pos.x; | |
1910 | if ( y ) | |
1911 | *y = pos.y; | |
42e69d6b | 1912 | } |
54bdd8b0 | 1913 | |
1e6feb95 | 1914 | void wxWindowMSW::DoScreenToClient(int *x, int *y) const |
42e69d6b VZ |
1915 | { |
1916 | POINT pt; | |
1917 | if ( x ) | |
1918 | pt.x = *x; | |
1919 | if ( y ) | |
1920 | pt.y = *y; | |
54bdd8b0 | 1921 | |
82c9f85c | 1922 | ::ScreenToClient(GetHwnd(), &pt); |
a23fd0e1 | 1923 | |
42e69d6b VZ |
1924 | if ( x ) |
1925 | *x = pt.x; | |
1926 | if ( y ) | |
1927 | *y = pt.y; | |
1928 | } | |
a23fd0e1 | 1929 | |
1e6feb95 | 1930 | void wxWindowMSW::DoClientToScreen(int *x, int *y) const |
42e69d6b VZ |
1931 | { |
1932 | POINT pt; | |
1933 | if ( x ) | |
1934 | pt.x = *x; | |
1935 | if ( y ) | |
1936 | pt.y = *y; | |
54bdd8b0 | 1937 | |
82c9f85c | 1938 | ::ClientToScreen(GetHwnd(), &pt); |
a23fd0e1 | 1939 | |
42e69d6b VZ |
1940 | if ( x ) |
1941 | *x = pt.x; | |
1942 | if ( y ) | |
1943 | *y = pt.y; | |
1944 | } | |
a23fd0e1 | 1945 | |
86e30911 | 1946 | bool |
7d86a2d4 VZ |
1947 | wxWindowMSW::DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height) |
1948 | { | |
6bd9b9f2 | 1949 | #if wxUSE_DEFERRED_SIZING |
7d86a2d4 VZ |
1950 | // if our parent had prepared a defer window handle for us, use it (unless |
1951 | // we are a top level window) | |
1952 | wxWindowMSW * const parent = IsTopLevel() ? NULL : GetParent(); | |
1953 | ||
1954 | HDWP hdwp = parent ? (HDWP)parent->m_hDWP : NULL; | |
1955 | if ( hdwp ) | |
1956 | { | |
1957 | hdwp = ::DeferWindowPos(hdwp, (HWND)hwnd, NULL, x, y, width, height, | |
dd28827a | 1958 | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); |
7d86a2d4 VZ |
1959 | if ( !hdwp ) |
1960 | { | |
9a83f860 | 1961 | wxLogLastError(wxT("DeferWindowPos")); |
7d86a2d4 VZ |
1962 | } |
1963 | } | |
1964 | ||
1965 | if ( parent ) | |
1966 | { | |
1967 | // hdwp must be updated as it may have been changed | |
1968 | parent->m_hDWP = (WXHANDLE)hdwp; | |
1969 | } | |
1970 | ||
86e30911 VZ |
1971 | if ( hdwp ) |
1972 | { | |
1973 | // did deferred move, remember new coordinates of the window as they're | |
1974 | // different from what Windows would return for it | |
1975 | return true; | |
1976 | } | |
1977 | ||
7d86a2d4 | 1978 | // otherwise (or if deferring failed) move the window in place immediately |
6bd9b9f2 | 1979 | #endif // wxUSE_DEFERRED_SIZING |
86e30911 | 1980 | if ( !::MoveWindow((HWND)hwnd, x, y, width, height, IsShown()) ) |
7d86a2d4 | 1981 | { |
86e30911 | 1982 | wxLogLastError(wxT("MoveWindow")); |
7d86a2d4 | 1983 | } |
86e30911 | 1984 | |
6bd9b9f2 | 1985 | // if wxUSE_DEFERRED_SIZING, indicates that we didn't use deferred move, |
86e30911 VZ |
1986 | // ignored otherwise |
1987 | return false; | |
7d86a2d4 VZ |
1988 | } |
1989 | ||
1e6feb95 | 1990 | void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height) |
b782f2e0 | 1991 | { |
62e1ba75 JS |
1992 | // TODO: is this consistent with other platforms? |
1993 | // Still, negative width or height shouldn't be allowed | |
1994 | if (width < 0) | |
1995 | width = 0; | |
1996 | if (height < 0) | |
1997 | height = 0; | |
9b6ae450 | 1998 | |
86e30911 VZ |
1999 | if ( DoMoveSibling(m_hWnd, x, y, width, height) ) |
2000 | { | |
6bd9b9f2 | 2001 | #if wxUSE_DEFERRED_SIZING |
86e30911 VZ |
2002 | m_pendingPosition = wxPoint(x, y); |
2003 | m_pendingSize = wxSize(width, height); | |
f8cba58b VZ |
2004 | } |
2005 | else // window was moved immediately, without deferring it | |
2006 | { | |
2007 | m_pendingPosition = wxDefaultPosition; | |
2008 | m_pendingSize = wxDefaultSize; | |
6bd9b9f2 | 2009 | #endif // wxUSE_DEFERRED_SIZING |
86e30911 | 2010 | } |
b782f2e0 VZ |
2011 | } |
2012 | ||
4438caf4 VZ |
2013 | // set the size of the window: if the dimensions are positive, just use them, |
2014 | // but if any of them is equal to -1, it means that we must find the value for | |
2015 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
2016 | // which case -1 is a valid value for x and y) | |
2017 | // | |
2018 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
2019 | // the width/height to best suit our contents, otherwise we reuse the current | |
2020 | // width/height | |
1e6feb95 | 2021 | void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
42e69d6b | 2022 | { |
4438caf4 | 2023 | // get the current size and position... |
42e69d6b | 2024 | int currentX, currentY; |
da78f3b1 RD |
2025 | int currentW, currentH; |
2026 | ||
42e69d6b | 2027 | GetPosition(¤tX, ¤tY); |
42e69d6b | 2028 | GetSize(¤tW, ¤tH); |
a23fd0e1 | 2029 | |
952f2aaa VZ |
2030 | // ... and don't do anything (avoiding flicker) if it's already ok unless |
2031 | // we're forced to resize the window | |
4438caf4 | 2032 | if ( x == currentX && y == currentY && |
952f2aaa VZ |
2033 | width == currentW && height == currentH && |
2034 | !(sizeFlags & wxSIZE_FORCE) ) | |
4438caf4 | 2035 | { |
e47e063a RR |
2036 | if (sizeFlags & wxSIZE_FORCE_EVENT) |
2037 | { | |
2038 | wxSizeEvent event( wxSize(width,height), GetId() ); | |
2039 | event.SetEventObject( this ); | |
2040 | HandleWindowEvent( event ); | |
2041 | } | |
42e69d6b | 2042 | return; |
4438caf4 | 2043 | } |
a23fd0e1 | 2044 | |
422d0ff0 | 2045 | if ( x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
4438caf4 | 2046 | x = currentX; |
422d0ff0 | 2047 | if ( y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
4438caf4 | 2048 | y = currentY; |
a23fd0e1 | 2049 | |
4438caf4 | 2050 | AdjustForParentClientOrigin(x, y, sizeFlags); |
a23fd0e1 | 2051 | |
abb74e0f | 2052 | wxSize size = wxDefaultSize; |
422d0ff0 | 2053 | if ( width == wxDefaultCoord ) |
4438caf4 | 2054 | { |
9e2896e5 | 2055 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) |
4438caf4 | 2056 | { |
4329eae9 | 2057 | size = GetBestSize(); |
4438caf4 VZ |
2058 | width = size.x; |
2059 | } | |
2060 | else | |
2061 | { | |
2062 | // just take the current one | |
2063 | width = currentW; | |
2064 | } | |
2065 | } | |
2066 | ||
422d0ff0 | 2067 | if ( height == wxDefaultCoord ) |
4438caf4 | 2068 | { |
9e2896e5 | 2069 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) |
4438caf4 | 2070 | { |
422d0ff0 | 2071 | if ( size.x == wxDefaultCoord ) |
4438caf4 | 2072 | { |
4329eae9 | 2073 | size = GetBestSize(); |
4438caf4 | 2074 | } |
4329eae9 | 2075 | //else: already called GetBestSize() above |
a23fd0e1 | 2076 | |
4438caf4 VZ |
2077 | height = size.y; |
2078 | } | |
2079 | else | |
2080 | { | |
2081 | // just take the current one | |
2082 | height = currentH; | |
2083 | } | |
2084 | } | |
2085 | ||
b782f2e0 | 2086 | DoMoveWindow(x, y, width, height); |
4438caf4 VZ |
2087 | } |
2088 | ||
1e6feb95 | 2089 | void wxWindowMSW::DoSetClientSize(int width, int height) |
42e69d6b | 2090 | { |
90e572f1 | 2091 | // setting the client size is less obvious than it could have been |
d4597e13 | 2092 | // because in the result of changing the total size the window scrollbar |
c72b1ad7 VZ |
2093 | // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect() |
2094 | // doesn't take neither into account) and so the client size will not be | |
2095 | // correct as the difference between the total and client size changes -- | |
2096 | // so we keep changing it until we get it right | |
d4597e13 | 2097 | // |
d6a97306 VZ |
2098 | // normally this loop shouldn't take more than 3 iterations (usually 1 but |
2099 | // if scrollbars [dis]appear as the result of the first call, then 2 and it | |
2100 | // may become 3 if the window had 0 size originally and so we didn't | |
2101 | // calculate the scrollbar correction correctly during the first iteration) | |
2102 | // but just to be on the safe side we check for it instead of making it an | |
d4597e13 | 2103 | // "infinite" loop (i.e. leaving break inside as the only way to get out) |
d6a97306 | 2104 | for ( int i = 0; i < 4; i++ ) |
d4597e13 VZ |
2105 | { |
2106 | RECT rectClient; | |
2107 | ::GetClientRect(GetHwnd(), &rectClient); | |
2bda0e17 | 2108 | |
b0268daf | 2109 | // if the size is already ok, stop here (NB: rectClient.left = top = 0) |
422d0ff0 WS |
2110 | if ( (rectClient.right == width || width == wxDefaultCoord) && |
2111 | (rectClient.bottom == height || height == wxDefaultCoord) ) | |
d4597e13 VZ |
2112 | { |
2113 | break; | |
2114 | } | |
a23fd0e1 | 2115 | |
d4597e13 VZ |
2116 | // Find the difference between the entire window (title bar and all) |
2117 | // and the client area; add this to the new client size to move the | |
2118 | // window | |
2119 | RECT rectWin; | |
2120 | ::GetWindowRect(GetHwnd(), &rectWin); | |
2121 | ||
b0268daf VZ |
2122 | const int widthWin = rectWin.right - rectWin.left, |
2123 | heightWin = rectWin.bottom - rectWin.top; | |
387a3b02 | 2124 | |
d4597e13 VZ |
2125 | // MoveWindow positions the child windows relative to the parent, so |
2126 | // adjust if necessary | |
2127 | if ( !IsTopLevel() ) | |
2128 | { | |
2129 | wxWindow *parent = GetParent(); | |
2130 | if ( parent ) | |
2131 | { | |
b0268daf | 2132 | ::ScreenToClient(GetHwndOf(parent), (POINT *)&rectWin); |
d4597e13 VZ |
2133 | } |
2134 | } | |
a23fd0e1 | 2135 | |
b0268daf | 2136 | // don't call DoMoveWindow() because we want to move window immediately |
c72b1ad7 VZ |
2137 | // and not defer it here as otherwise the value returned by |
2138 | // GetClient/WindowRect() wouldn't change as the window wouldn't be | |
2139 | // really resized | |
b0268daf VZ |
2140 | if ( !::MoveWindow(GetHwnd(), |
2141 | rectWin.left, | |
2142 | rectWin.top, | |
2143 | width + widthWin - rectClient.right, | |
2144 | height + heightWin - rectClient.bottom, | |
2145 | TRUE) ) | |
2146 | { | |
9a83f860 | 2147 | wxLogLastError(wxT("MoveWindow")); |
b0268daf | 2148 | } |
d4597e13 | 2149 | } |
42e69d6b | 2150 | } |
a23fd0e1 | 2151 | |
743b4266 VZ |
2152 | wxSize wxWindowMSW::DoGetBorderSize() const |
2153 | { | |
2154 | wxCoord border; | |
2155 | switch ( GetBorder() ) | |
2156 | { | |
2157 | case wxBORDER_STATIC: | |
2158 | case wxBORDER_SIMPLE: | |
2159 | border = 1; | |
2160 | break; | |
2161 | ||
2162 | case wxBORDER_SUNKEN: | |
2163 | border = 2; | |
2164 | break; | |
2165 | ||
2166 | case wxBORDER_RAISED: | |
2167 | case wxBORDER_DOUBLE: | |
2168 | border = 3; | |
2169 | break; | |
2170 | ||
2171 | default: | |
9a83f860 | 2172 | wxFAIL_MSG( wxT("unknown border style") ); |
743b4266 VZ |
2173 | // fall through |
2174 | ||
2175 | case wxBORDER_NONE: | |
2176 | border = 0; | |
2177 | } | |
2178 | ||
2179 | return 2*wxSize(border, border); | |
2180 | } | |
2181 | ||
42e69d6b VZ |
2182 | // --------------------------------------------------------------------------- |
2183 | // text metrics | |
2184 | // --------------------------------------------------------------------------- | |
a23fd0e1 | 2185 | |
1e6feb95 | 2186 | int wxWindowMSW::GetCharHeight() const |
42e69d6b | 2187 | { |
f6bcfd97 | 2188 | return wxGetTextMetrics(this).tmHeight; |
42e69d6b | 2189 | } |
3eddf563 | 2190 | |
1e6feb95 | 2191 | int wxWindowMSW::GetCharWidth() const |
42e69d6b | 2192 | { |
f6bcfd97 BP |
2193 | // +1 is needed because Windows apparently adds it when calculating the |
2194 | // dialog units size in pixels | |
2195 | #if wxDIALOG_UNIT_COMPATIBILITY | |
1e6feb95 | 2196 | return wxGetTextMetrics(this).tmAveCharWidth; |
f6bcfd97 BP |
2197 | #else |
2198 | return wxGetTextMetrics(this).tmAveCharWidth + 1; | |
2199 | #endif | |
42e69d6b | 2200 | } |
f4621a09 | 2201 | |
6de70470 VZ |
2202 | void wxWindowMSW::DoGetTextExtent(const wxString& string, |
2203 | int *x, int *y, | |
2204 | int *descent, | |
2205 | int *externalLeading, | |
2206 | const wxFont *fontToUse) const | |
42e69d6b | 2207 | { |
e0448413 | 2208 | wxASSERT_MSG( !fontToUse || fontToUse->Ok(), |
9a83f860 | 2209 | wxT("invalid font in GetTextExtent()") ); |
634903fd | 2210 | |
e0448413 VZ |
2211 | HFONT hfontToUse; |
2212 | if ( fontToUse ) | |
2213 | hfontToUse = GetHfontOf(*fontToUse); | |
2d17baae | 2214 | else |
e0448413 | 2215 | hfontToUse = GetHfontOf(GetFont()); |
634903fd | 2216 | |
64869ab7 | 2217 | WindowHDC hdc(GetHwnd()); |
e0448413 | 2218 | SelectInHDC selectFont(hdc, hfontToUse); |
341c92a8 | 2219 | |
42e69d6b VZ |
2220 | SIZE sizeRect; |
2221 | TEXTMETRIC tm; | |
e0a050e3 | 2222 | ::GetTextExtentPoint32(hdc, string.wx_str(), string.length(), &sizeRect); |
64869ab7 | 2223 | GetTextMetrics(hdc, &tm); |
42e69d6b | 2224 | |
0655ad29 VZ |
2225 | if ( x ) |
2226 | *x = sizeRect.cx; | |
2227 | if ( y ) | |
2228 | *y = sizeRect.cy; | |
2229 | if ( descent ) | |
2230 | *descent = tm.tmDescent; | |
2231 | if ( externalLeading ) | |
2232 | *externalLeading = tm.tmExternalLeading; | |
2bda0e17 KB |
2233 | } |
2234 | ||
c50f1fb9 VZ |
2235 | // --------------------------------------------------------------------------- |
2236 | // popup menu | |
2237 | // --------------------------------------------------------------------------- | |
2238 | ||
2e9f62da VZ |
2239 | #if wxUSE_MENUS_NATIVE |
2240 | ||
ed45e263 VZ |
2241 | // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue |
2242 | // immediately, without waiting for the next event loop iteration | |
2243 | // | |
2244 | // NB: this function should probably be made public later as it can almost | |
2245 | // surely replace wxYield() elsewhere as well | |
2246 | static void wxYieldForCommandsOnly() | |
2247 | { | |
2248 | // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't | |
2249 | // want to process it here) | |
2250 | MSG msg; | |
1bf77ee5 | 2251 | while ( ::PeekMessage(&msg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE) ) |
ed45e263 | 2252 | { |
dd7ebf8b | 2253 | if ( msg.message == WM_QUIT ) |
1bf77ee5 VZ |
2254 | { |
2255 | // if we retrieved a WM_QUIT, insert back into the message queue. | |
2256 | ::PostQuitMessage(0); | |
2257 | break; | |
2258 | } | |
7de59551 | 2259 | |
1bf77ee5 VZ |
2260 | // luckily (as we don't have access to wxEventLoopImpl method from here |
2261 | // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it | |
2262 | // immediately | |
2263 | ::TranslateMessage(&msg); | |
2264 | ::DispatchMessage(&msg); | |
2265 | } | |
ed45e263 VZ |
2266 | } |
2267 | ||
1e6feb95 | 2268 | bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y) |
c50f1fb9 | 2269 | { |
c50f1fb9 VZ |
2270 | menu->UpdateUI(); |
2271 | ||
27d2dbbc | 2272 | if ( x == wxDefaultCoord && y == wxDefaultCoord ) |
971562cb VS |
2273 | { |
2274 | wxPoint mouse = ScreenToClient(wxGetMousePosition()); | |
2275 | x = mouse.x; y = mouse.y; | |
2276 | } | |
2277 | ||
c50f1fb9 VZ |
2278 | HWND hWnd = GetHwnd(); |
2279 | HMENU hMenu = GetHmenuOf(menu); | |
2280 | POINT point; | |
2281 | point.x = x; | |
2282 | point.y = y; | |
2283 | ::ClientToScreen(hWnd, &point); | |
5cb598ae | 2284 | #if defined(__WXWINCE__) |
b40bf35c VZ |
2285 | static const UINT flags = 0; |
2286 | #else // !__WXWINCE__ | |
2287 | UINT flags = TPM_RIGHTBUTTON; | |
2288 | // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all | |
2289 | // when it's use, I'm not sure about Win95/98 but prefer to err on the safe | |
2290 | // side and not to use it there neither -- modify the test if it does work | |
2291 | // on these systems | |
2292 | if ( wxGetWinVersion() >= wxWinVersion_5 ) | |
2293 | { | |
2294 | // using TPM_RECURSE allows us to show a popup menu while another menu | |
2295 | // is opened which can be useful and is supported by the other | |
2296 | // platforms, so allow it under Windows too | |
2297 | flags |= TPM_RECURSE; | |
2298 | } | |
2299 | #endif // __WXWINCE__/!__WXWINCE__ | |
2300 | ||
7f0586ef | 2301 | ::TrackPopupMenu(hMenu, flags, point.x, point.y, 0, hWnd, NULL); |
ed45e263 | 2302 | |
90e572f1 | 2303 | // we need to do it right now as otherwise the events are never going to be |
ed45e263 VZ |
2304 | // sent to wxCurrentPopupMenu from HandleCommand() |
2305 | // | |
2306 | // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't | |
2307 | // help and we'd still need wxYieldForCommandsOnly() as the menu may be | |
2308 | // destroyed as soon as we return (it can be a local variable in the caller | |
2309 | // for example) and so we do need to process the event immediately | |
2310 | wxYieldForCommandsOnly(); | |
2311 | ||
08158721 | 2312 | return true; |
c50f1fb9 VZ |
2313 | } |
2314 | ||
1e6feb95 VZ |
2315 | #endif // wxUSE_MENUS_NATIVE |
2316 | ||
42e69d6b VZ |
2317 | // =========================================================================== |
2318 | // pre/post message processing | |
2319 | // =========================================================================== | |
2bda0e17 | 2320 | |
c140b7e7 | 2321 | WXLRESULT wxWindowMSW::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
42e69d6b VZ |
2322 | { |
2323 | if ( m_oldWndProc ) | |
2324 | return ::CallWindowProc(CASTWNDPROC m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam); | |
2325 | else | |
2326 | return ::DefWindowProc(GetHwnd(), nMsg, wParam, lParam); | |
2327 | } | |
2bda0e17 | 2328 | |
1e6feb95 | 2329 | bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg) |
42e69d6b | 2330 | { |
1e6feb95 VZ |
2331 | // wxUniversal implements tab traversal itself |
2332 | #ifndef __WXUNIVERSAL__ | |
42e69d6b | 2333 | if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) ) |
2d0a075d | 2334 | { |
42e69d6b VZ |
2335 | // intercept dialog navigation keys |
2336 | MSG *msg = (MSG *)pMsg; | |
d9317fd4 VZ |
2337 | |
2338 | // here we try to do all the job which ::IsDialogMessage() usually does | |
2339 | // internally | |
573a1586 | 2340 | if ( msg->message == WM_KEYDOWN ) |
42e69d6b | 2341 | { |
3f7bc32b VZ |
2342 | bool bCtrlDown = wxIsCtrlDown(); |
2343 | bool bShiftDown = wxIsShiftDown(); | |
a23fd0e1 | 2344 | |
42e69d6b VZ |
2345 | // WM_GETDLGCODE: ask the control if it wants the key for itself, |
2346 | // don't process it if it's the case (except for Ctrl-Tab/Enter | |
2347 | // combinations which are always processed) | |
977f50f3 VZ |
2348 | LONG lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0); |
2349 | ||
cbab1556 | 2350 | // surprisingly, DLGC_WANTALLKEYS bit mask doesn't contain the |
977f50f3 VZ |
2351 | // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically, |
2352 | // it, of course, implies them | |
2353 | if ( lDlgCode & DLGC_WANTALLKEYS ) | |
42e69d6b | 2354 | { |
977f50f3 | 2355 | lDlgCode |= DLGC_WANTTAB | DLGC_WANTARROWS; |
42e69d6b | 2356 | } |
a23fd0e1 | 2357 | |
08158721 | 2358 | bool bForward = true, |
298ca00c VZ |
2359 | bWindowChange = false, |
2360 | bFromTab = false; | |
a23fd0e1 | 2361 | |
573a1586 | 2362 | // should we process this message specially? |
08158721 | 2363 | bool bProcess = true; |
9145664b | 2364 | switch ( msg->wParam ) |
42e69d6b VZ |
2365 | { |
2366 | case VK_TAB: | |
7cc44669 VZ |
2367 | if ( (lDlgCode & DLGC_WANTTAB) && !bCtrlDown ) |
2368 | { | |
2369 | // let the control have the TAB | |
08158721 | 2370 | bProcess = false; |
42e69d6b | 2371 | } |
7cc44669 VZ |
2372 | else // use it for navigation |
2373 | { | |
42e69d6b VZ |
2374 | // Ctrl-Tab cycles thru notebook pages |
2375 | bWindowChange = bCtrlDown; | |
319fefa9 | 2376 | bForward = !bShiftDown; |
298ca00c | 2377 | bFromTab = true; |
42e69d6b VZ |
2378 | } |
2379 | break; | |
a23fd0e1 | 2380 | |
42e69d6b VZ |
2381 | case VK_UP: |
2382 | case VK_LEFT: | |
2383 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
08158721 | 2384 | bProcess = false; |
42e69d6b | 2385 | else |
08158721 | 2386 | bForward = false; |
42e69d6b | 2387 | break; |
a02eb1d2 | 2388 | |
42e69d6b VZ |
2389 | case VK_DOWN: |
2390 | case VK_RIGHT: | |
2391 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
08158721 | 2392 | bProcess = false; |
42e69d6b | 2393 | break; |
2bda0e17 | 2394 | |
efe5e221 VZ |
2395 | case VK_PRIOR: |
2396 | bForward = false; | |
2397 | // fall through | |
2398 | ||
2399 | case VK_NEXT: | |
2400 | // we treat PageUp/Dn as arrows because chances are that | |
2401 | // a control which needs arrows also needs them for | |
2402 | // navigation (e.g. wxTextCtrl, wxListCtrl, ...) | |
ada5f90d | 2403 | if ( (lDlgCode & DLGC_WANTARROWS) && !bCtrlDown ) |
efe5e221 | 2404 | bProcess = false; |
ada5f90d | 2405 | else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab |
efe5e221 VZ |
2406 | bWindowChange = true; |
2407 | break; | |
2408 | ||
42e69d6b VZ |
2409 | case VK_RETURN: |
2410 | { | |
90c6edd7 | 2411 | #if wxUSE_BUTTON |
3147bb58 | 2412 | // currently active button should get enter press even |
90c6edd7 VZ |
2413 | // if there is a default button elsewhere so check if |
2414 | // this window is a button first | |
2415 | wxWindow *btn = NULL; | |
3147bb58 | 2416 | if ( lDlgCode & DLGC_DEFPUSHBUTTON ) |
319fefa9 | 2417 | { |
3e79ed96 VZ |
2418 | // let IsDialogMessage() handle this for all |
2419 | // buttons except the owner-drawn ones which it | |
2420 | // just seems to ignore | |
2421 | long style = ::GetWindowLong(msg->hwnd, GWL_STYLE); | |
2422 | if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW ) | |
2423 | { | |
2424 | // emulate the button click | |
dca0f651 | 2425 | btn = wxFindWinFromHandle(msg->hwnd); |
3e79ed96 VZ |
2426 | } |
2427 | ||
08158721 | 2428 | bProcess = false; |
319fefa9 | 2429 | } |
90c6edd7 | 2430 | else // not a button itself, do we have default button? |
c50f1fb9 | 2431 | { |
8e86978a VZ |
2432 | // check if this window or any of its ancestors |
2433 | // wants the message for itself (we always reserve | |
2434 | // Ctrl-Enter for dialog navigation though) | |
2435 | wxWindow *win = this; | |
2436 | if ( !bCtrlDown ) | |
2437 | { | |
53b0c2bc | 2438 | // this will contain the dialog code of this |
0075ea22 | 2439 | // window and all of its parent windows in turn |
53b0c2bc VZ |
2440 | LONG lDlgCode2 = lDlgCode; |
2441 | ||
0075ea22 | 2442 | while ( win ) |
8e86978a | 2443 | { |
53b0c2bc | 2444 | if ( lDlgCode2 & DLGC_WANTMESSAGE ) |
8e86978a VZ |
2445 | { |
2446 | // as it wants to process Enter itself, | |
2447 | // don't call IsDialogMessage() which | |
2448 | // would consume it | |
2449 | return false; | |
2450 | } | |
2451 | ||
0075ea22 VZ |
2452 | // don't propagate keyboard messages beyond |
2453 | // the first top level window parent | |
2454 | if ( win->IsTopLevel() ) | |
2455 | break; | |
2456 | ||
2457 | win = win->GetParent(); | |
2458 | ||
53b0c2bc VZ |
2459 | lDlgCode2 = ::SendMessage |
2460 | ( | |
2461 | GetHwndOf(win), | |
2462 | WM_GETDLGCODE, | |
2463 | 0, | |
2464 | 0 | |
2465 | ); | |
8e86978a VZ |
2466 | } |
2467 | } | |
2468 | else // bCtrlDown | |
2469 | { | |
2470 | win = wxGetTopLevelParent(win); | |
2471 | } | |
2472 | ||
2473 | wxTopLevelWindow * const | |
2474 | tlw = wxDynamicCast(win, wxTopLevelWindow); | |
6c20e8f8 | 2475 | if ( tlw ) |
c50f1fb9 | 2476 | { |
90c6edd7 VZ |
2477 | btn = wxDynamicCast(tlw->GetDefaultItem(), |
2478 | wxButton); | |
c50f1fb9 | 2479 | } |
90c6edd7 VZ |
2480 | } |
2481 | ||
2482 | if ( btn && btn->IsEnabled() ) | |
2483 | { | |
2484 | btn->MSWCommand(BN_CLICKED, 0 /* unused */); | |
2485 | return true; | |
2486 | } | |
2487 | ||
1e6feb95 | 2488 | #endif // wxUSE_BUTTON |
90c6edd7 | 2489 | |
7b504551 | 2490 | #ifdef __WXWINCE__ |
90c6edd7 VZ |
2491 | // map Enter presses into button presses on PDAs |
2492 | wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN); | |
2493 | event.SetEventObject(this); | |
937013e0 | 2494 | if ( HandleWindowEvent(event) ) |
90c6edd7 VZ |
2495 | return true; |
2496 | #endif // __WXWINCE__ | |
42e69d6b VZ |
2497 | } |
2498 | break; | |
2bda0e17 | 2499 | |
42e69d6b | 2500 | default: |
08158721 | 2501 | bProcess = false; |
42e69d6b | 2502 | } |
2bda0e17 | 2503 | |
42e69d6b VZ |
2504 | if ( bProcess ) |
2505 | { | |
2506 | wxNavigationKeyEvent event; | |
2507 | event.SetDirection(bForward); | |
2508 | event.SetWindowChange(bWindowChange); | |
298ca00c | 2509 | event.SetFromTab(bFromTab); |
42e69d6b | 2510 | event.SetEventObject(this); |
3572173c | 2511 | |
937013e0 | 2512 | if ( HandleWindowEvent(event) ) |
57c0af52 | 2513 | { |
d7e0024b VZ |
2514 | // as we don't call IsDialogMessage(), which would take of |
2515 | // this by default, we need to manually send this message | |
1ca78aa1 JS |
2516 | // so that controls can change their UI state if needed |
2517 | MSWUpdateUIState(UIS_CLEAR, UISF_HIDEFOCUS); | |
d7e0024b | 2518 | |
08158721 | 2519 | return true; |
57c0af52 | 2520 | } |
42e69d6b VZ |
2521 | } |
2522 | } | |
a23fd0e1 | 2523 | |
98ebf919 | 2524 | if ( ::IsDialogMessage(GetHwnd(), msg) ) |
f6bcfd97 | 2525 | { |
98ebf919 VZ |
2526 | // IsDialogMessage() did something... |
2527 | return true; | |
f6bcfd97 | 2528 | } |
42e69d6b | 2529 | } |
1e6feb95 | 2530 | #endif // __WXUNIVERSAL__ |
a23fd0e1 | 2531 | |
42e69d6b VZ |
2532 | #if wxUSE_TOOLTIPS |
2533 | if ( m_tooltip ) | |
387a3b02 | 2534 | { |
42e69d6b VZ |
2535 | // relay mouse move events to the tooltip control |
2536 | MSG *msg = (MSG *)pMsg; | |
2537 | if ( msg->message == WM_MOUSEMOVE ) | |
259a4264 | 2538 | wxToolTip::RelayEvent(pMsg); |
387a3b02 | 2539 | } |
42e69d6b | 2540 | #endif // wxUSE_TOOLTIPS |
a23fd0e1 | 2541 | |
08158721 | 2542 | return false; |
387a3b02 JS |
2543 | } |
2544 | ||
1e6feb95 | 2545 | bool wxWindowMSW::MSWTranslateMessage(WXMSG* pMsg) |
387a3b02 | 2546 | { |
1e6feb95 | 2547 | #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
c50f1fb9 | 2548 | return m_acceleratorTable.Translate(this, pMsg); |
1e6feb95 | 2549 | #else |
574c939e | 2550 | (void) pMsg; |
08158721 | 2551 | return false; |
1e6feb95 | 2552 | #endif // wxUSE_ACCEL |
387a3b02 JS |
2553 | } |
2554 | ||
98ebf919 | 2555 | bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG* msg) |
a37d422a | 2556 | { |
98ebf919 VZ |
2557 | // all tests below have to deal with various bugs/misfeatures of |
2558 | // IsDialogMessage(): we have to prevent it from being called from our | |
2559 | // MSWProcessMessage() in some situations | |
2560 | ||
2561 | // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the | |
2562 | // message even when there is no cancel button and when the message is | |
2563 | // needed by the control itself: in particular, it prevents the tree in | |
2564 | // place edit control from being closed with Escape in a dialog | |
2565 | if ( msg->message == WM_KEYDOWN && msg->wParam == VK_ESCAPE ) | |
2566 | { | |
2567 | return false; | |
2568 | } | |
2569 | ||
2570 | // ::IsDialogMessage() is broken and may sometimes hang the application by | |
2571 | // going into an infinite loop when it tries to find the control to give | |
2572 | // focus to when Alt-<key> is pressed, so we try to detect [some of] the | |
2573 | // situations when this may happen and not call it then | |
2574 | if ( msg->message != WM_SYSCHAR ) | |
2575 | return true; | |
2576 | ||
2577 | // assume we can call it by default | |
2578 | bool canSafelyCallIsDlgMsg = true; | |
2579 | ||
2580 | HWND hwndFocus = ::GetFocus(); | |
2581 | ||
2582 | // if the currently focused window itself has WS_EX_CONTROLPARENT style, | |
2583 | // ::IsDialogMessage() will also enter an infinite loop, because it will | |
2584 | // recursively check the child windows but not the window itself and so if | |
2585 | // none of the children accepts focus it loops forever (as it only stops | |
2586 | // when it gets back to the window it started from) | |
2587 | // | |
2588 | // while it is very unusual that a window with WS_EX_CONTROLPARENT | |
2589 | // style has the focus, it can happen. One such possibility is if | |
2590 | // all windows are either toplevel, wxDialog, wxPanel or static | |
2591 | // controls and no window can actually accept keyboard input. | |
2592 | #if !defined(__WXWINCE__) | |
2593 | if ( ::GetWindowLong(hwndFocus, GWL_EXSTYLE) & WS_EX_CONTROLPARENT ) | |
2594 | { | |
2595 | // pessimistic by default | |
2596 | canSafelyCallIsDlgMsg = false; | |
2597 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
2598 | node; | |
2599 | node = node->GetNext() ) | |
2600 | { | |
2601 | wxWindow * const win = node->GetData(); | |
ad02525d | 2602 | if ( win->CanAcceptFocus() && |
d66d0500 | 2603 | !wxHasWindowExStyle(win, WS_EX_CONTROLPARENT) ) |
98ebf919 VZ |
2604 | { |
2605 | // it shouldn't hang... | |
2606 | canSafelyCallIsDlgMsg = true; | |
2607 | ||
2608 | break; | |
2609 | } | |
2610 | } | |
2611 | } | |
2612 | #endif // !__WXWINCE__ | |
2613 | ||
2614 | if ( canSafelyCallIsDlgMsg ) | |
2615 | { | |
2616 | // ::IsDialogMessage() can enter in an infinite loop when the | |
2617 | // currently focused window is disabled or hidden and its | |
2618 | // parent has WS_EX_CONTROLPARENT style, so don't call it in | |
2619 | // this case | |
2620 | while ( hwndFocus ) | |
2621 | { | |
2622 | if ( !::IsWindowEnabled(hwndFocus) || | |
2623 | !::IsWindowVisible(hwndFocus) ) | |
2624 | { | |
2625 | // it would enter an infinite loop if we do this! | |
2626 | canSafelyCallIsDlgMsg = false; | |
2627 | ||
2628 | break; | |
2629 | } | |
2630 | ||
2631 | if ( !(::GetWindowLong(hwndFocus, GWL_STYLE) & WS_CHILD) ) | |
2632 | { | |
2633 | // it's a top level window, don't go further -- e.g. even | |
2634 | // if the parent of a dialog is disabled, this doesn't | |
2635 | // break navigation inside the dialog | |
2636 | break; | |
2637 | } | |
2638 | ||
2639 | hwndFocus = ::GetParent(hwndFocus); | |
2640 | } | |
2641 | } | |
2642 | ||
2643 | return canSafelyCallIsDlgMsg; | |
a37d422a VZ |
2644 | } |
2645 | ||
42e69d6b | 2646 | // --------------------------------------------------------------------------- |
e39af974 | 2647 | // message params unpackers |
42e69d6b | 2648 | // --------------------------------------------------------------------------- |
2bda0e17 | 2649 | |
1e6feb95 | 2650 | void wxWindowMSW::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b VZ |
2651 | WORD *id, WXHWND *hwnd, WORD *cmd) |
2652 | { | |
2653 | *id = LOWORD(wParam); | |
2654 | *hwnd = (WXHWND)lParam; | |
2655 | *cmd = HIWORD(wParam); | |
2bda0e17 KB |
2656 | } |
2657 | ||
1e6feb95 | 2658 | void wxWindowMSW::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 2659 | WXWORD *state, WXWORD *minimized, WXHWND *hwnd) |
2bda0e17 | 2660 | { |
42e69d6b VZ |
2661 | *state = LOWORD(wParam); |
2662 | *minimized = HIWORD(wParam); | |
2663 | *hwnd = (WXHWND)lParam; | |
2bda0e17 KB |
2664 | } |
2665 | ||
1e6feb95 | 2666 | void wxWindowMSW::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 2667 | WXWORD *code, WXWORD *pos, WXHWND *hwnd) |
2bda0e17 | 2668 | { |
42e69d6b VZ |
2669 | *code = LOWORD(wParam); |
2670 | *pos = HIWORD(wParam); | |
2671 | *hwnd = (WXHWND)lParam; | |
2672 | } | |
a23fd0e1 | 2673 | |
1e6feb95 | 2674 | void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam, |
01c500af | 2675 | WXHDC *hdc, WXHWND *hwnd) |
42e69d6b | 2676 | { |
42e69d6b VZ |
2677 | *hwnd = (WXHWND)lParam; |
2678 | *hdc = (WXHDC)wParam; | |
2bda0e17 KB |
2679 | } |
2680 | ||
1e6feb95 | 2681 | void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 2682 | WXWORD *item, WXWORD *flags, WXHMENU *hmenu) |
2bda0e17 | 2683 | { |
42e69d6b VZ |
2684 | *item = (WXWORD)wParam; |
2685 | *flags = HIWORD(wParam); | |
2686 | *hmenu = (WXHMENU)lParam; | |
2687 | } | |
c085e333 | 2688 | |
42e69d6b | 2689 | // --------------------------------------------------------------------------- |
77ffb593 | 2690 | // Main wxWidgets window proc and the window proc for wxWindow |
42e69d6b | 2691 | // --------------------------------------------------------------------------- |
2bda0e17 | 2692 | |
42e69d6b VZ |
2693 | // Hook for new window just as it's being created, when the window isn't yet |
2694 | // associated with the handle | |
b225f659 VZ |
2695 | static wxWindowMSW *gs_winBeingCreated = NULL; |
2696 | ||
2697 | // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the | |
2698 | // window being created and insures that it's always unset back later | |
2699 | wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW *winBeingCreated) | |
2700 | { | |
2701 | gs_winBeingCreated = winBeingCreated; | |
2702 | } | |
2703 | ||
2704 | wxWindowCreationHook::~wxWindowCreationHook() | |
2705 | { | |
2706 | gs_winBeingCreated = NULL; | |
2707 | } | |
42e69d6b VZ |
2708 | |
2709 | // Main window proc | |
3135f4a7 | 2710 | LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
2bda0e17 | 2711 | { |
4b6a582b VZ |
2712 | // trace all messages: useful for the debugging but noticeably slows down |
2713 | // the code so don't do it by default | |
2714 | #if wxDEBUG_LEVEL >= 2 | |
5ec3853f | 2715 | wxLogTrace("winmsg", |
dca0f651 VZ |
2716 | wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"), |
2717 | wxGetMessageName(message), hWnd, (long)wParam, lParam); | |
4b6a582b | 2718 | #endif // wxDEBUG_LEVEL >= 2 |
2bda0e17 | 2719 | |
dca0f651 | 2720 | wxWindowMSW *wnd = wxFindWinFromHandle(hWnd); |
c085e333 | 2721 | |
42e69d6b | 2722 | // when we get the first message for the HWND we just created, we associate |
b225f659 VZ |
2723 | // it with wxWindow stored in gs_winBeingCreated |
2724 | if ( !wnd && gs_winBeingCreated ) | |
2d0a075d | 2725 | { |
b225f659 VZ |
2726 | wxAssociateWinWithHandle(hWnd, gs_winBeingCreated); |
2727 | wnd = gs_winBeingCreated; | |
2728 | gs_winBeingCreated = NULL; | |
42e69d6b | 2729 | wnd->SetHWND((WXHWND)hWnd); |
2d0a075d | 2730 | } |
2bda0e17 | 2731 | |
42e69d6b | 2732 | LRESULT rc; |
a23fd0e1 | 2733 | |
b46b1d59 | 2734 | if ( wnd && wxGUIEventLoop::AllowProcessing(wnd) ) |
b225f659 | 2735 | rc = wnd->MSWWindowProc(message, wParam, lParam); |
a23fd0e1 | 2736 | else |
b225f659 | 2737 | rc = ::DefWindowProc(hWnd, message, wParam, lParam); |
2bda0e17 | 2738 | |
42e69d6b | 2739 | return rc; |
f7bd2698 JS |
2740 | } |
2741 | ||
c140b7e7 | 2742 | WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
f7bd2698 | 2743 | { |
42e69d6b | 2744 | // did we process the message? |
08158721 | 2745 | bool processed = false; |
f7bd2698 | 2746 | |
42e69d6b VZ |
2747 | // the return value |
2748 | union | |
2bda0e17 | 2749 | { |
42e69d6b | 2750 | bool allow; |
c140b7e7 | 2751 | WXLRESULT result; |
42e69d6b VZ |
2752 | WXHBRUSH hBrush; |
2753 | } rc; | |
2bda0e17 | 2754 | |
42e69d6b VZ |
2755 | // for most messages we should return 0 when we do process the message |
2756 | rc.result = 0; | |
2bda0e17 | 2757 | |
42e69d6b | 2758 | switch ( message ) |
39136494 | 2759 | { |
42e69d6b VZ |
2760 | case WM_CREATE: |
2761 | { | |
2762 | bool mayCreate; | |
2763 | processed = HandleCreate((WXLPCREATESTRUCT)lParam, &mayCreate); | |
2764 | if ( processed ) | |
2765 | { | |
2766 | // return 0 to allow window creation | |
2767 | rc.result = mayCreate ? 0 : -1; | |
2768 | } | |
2769 | } | |
2770 | break; | |
47cbd6da | 2771 | |
42e69d6b | 2772 | case WM_DESTROY: |
08158721 | 2773 | // never set processed to true and *always* pass WM_DESTROY to |
ad4297f3 VZ |
2774 | // DefWindowProc() as Windows may do some internal cleanup when |
2775 | // processing it and failing to pass the message along may cause | |
2776 | // memory and resource leaks! | |
2777 | (void)HandleDestroy(); | |
42e69d6b VZ |
2778 | break; |
2779 | ||
9b6ae450 VZ |
2780 | case WM_SIZE: |
2781 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
9b6ae450 VZ |
2782 | break; |
2783 | ||
42e69d6b | 2784 | case WM_MOVE: |
132cb640 | 2785 | processed = HandleMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); |
42e69d6b | 2786 | break; |
47cbd6da | 2787 | |
7f0586ef | 2788 | #if !defined(__WXWINCE__) |
5706de1c | 2789 | case WM_MOVING: |
540b6b09 VZ |
2790 | { |
2791 | LPRECT pRect = (LPRECT)lParam; | |
2792 | wxRect rc; | |
2793 | rc.SetLeft(pRect->left); | |
2794 | rc.SetTop(pRect->top); | |
2795 | rc.SetRight(pRect->right); | |
2796 | rc.SetBottom(pRect->bottom); | |
2797 | processed = HandleMoving(rc); | |
2798 | if (processed) { | |
2799 | pRect->left = rc.GetLeft(); | |
2800 | pRect->top = rc.GetTop(); | |
2801 | pRect->right = rc.GetRight(); | |
2802 | pRect->bottom = rc.GetBottom(); | |
2803 | } | |
2804 | } | |
5706de1c | 2805 | break; |
a047aff2 | 2806 | #if 0 |
aa767a45 JS |
2807 | case WM_ENTERSIZEMOVE: |
2808 | { | |
2809 | processed = HandleEnterSizeMove(); | |
2810 | } | |
2811 | break; | |
2812 | ||
2813 | case WM_EXITSIZEMOVE: | |
2814 | { | |
2815 | processed = HandleExitSizeMove(); | |
2816 | } | |
2817 | break; | |
a047aff2 | 2818 | #endif |
5706de1c JS |
2819 | case WM_SIZING: |
2820 | { | |
2821 | LPRECT pRect = (LPRECT)lParam; | |
2822 | wxRect rc; | |
2823 | rc.SetLeft(pRect->left); | |
2824 | rc.SetTop(pRect->top); | |
2825 | rc.SetRight(pRect->right); | |
2826 | rc.SetBottom(pRect->bottom); | |
2827 | processed = HandleSizing(rc); | |
2828 | if (processed) { | |
2829 | pRect->left = rc.GetLeft(); | |
2830 | pRect->top = rc.GetTop(); | |
2831 | pRect->right = rc.GetRight(); | |
2832 | pRect->bottom = rc.GetBottom(); | |
2833 | } | |
2834 | } | |
2835 | break; | |
9b6ae450 | 2836 | #endif // !__WXWINCE__ |
5706de1c | 2837 | |
7f0586ef | 2838 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
1e6feb95 | 2839 | case WM_ACTIVATEAPP: |
afafd942 | 2840 | // This implicitly sends a wxEVT_ACTIVATE_APP event |
1e6feb95 | 2841 | wxTheApp->SetActive(wParam != 0, FindFocus()); |
42e69d6b | 2842 | break; |
8a46f9b1 | 2843 | #endif |
47cbd6da | 2844 | |
42e69d6b | 2845 | case WM_ACTIVATE: |
341c92a8 | 2846 | { |
42e69d6b VZ |
2847 | WXWORD state, minimized; |
2848 | WXHWND hwnd; | |
2849 | UnpackActivate(wParam, lParam, &state, &minimized, &hwnd); | |
2850 | ||
2851 | processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd); | |
341c92a8 | 2852 | } |
42e69d6b | 2853 | break; |
341c92a8 | 2854 | |
42e69d6b | 2855 | case WM_SETFOCUS: |
dca0f651 | 2856 | processed = HandleSetFocus((WXHWND)wParam); |
42e69d6b | 2857 | break; |
47cbd6da | 2858 | |
42e69d6b | 2859 | case WM_KILLFOCUS: |
dca0f651 | 2860 | processed = HandleKillFocus((WXHWND)wParam); |
42e69d6b | 2861 | break; |
47cbd6da | 2862 | |
c3732409 | 2863 | case WM_PRINTCLIENT: |
1a784dfc | 2864 | processed = HandlePrintClient((WXHDC)wParam); |
07c19327 VZ |
2865 | break; |
2866 | ||
c3732409 VZ |
2867 | case WM_PAINT: |
2868 | if ( wParam ) | |
5c6c3176 | 2869 | { |
5c6c3176 | 2870 | wxPaintDCEx dc((wxWindow *)this, (WXHDC)wParam); |
07c19327 | 2871 | |
5c6c3176 RD |
2872 | processed = HandlePaint(); |
2873 | } | |
c3732409 VZ |
2874 | else // no DC given |
2875 | { | |
2876 | processed = HandlePaint(); | |
2877 | } | |
5c6c3176 RD |
2878 | break; |
2879 | ||
42e69d6b | 2880 | case WM_CLOSE: |
9fd9e47a JS |
2881 | #ifdef __WXUNIVERSAL__ |
2882 | // Universal uses its own wxFrame/wxDialog, so we don't receive | |
2883 | // close events unless we have this. | |
2884 | Close(); | |
c3732409 VZ |
2885 | #endif // __WXUNIVERSAL__ |
2886 | ||
42e69d6b VZ |
2887 | // don't let the DefWindowProc() destroy our window - we'll do it |
2888 | // ourselves in ~wxWindow | |
08158721 | 2889 | processed = true; |
42e69d6b VZ |
2890 | rc.result = TRUE; |
2891 | break; | |
47cbd6da | 2892 | |
42e69d6b VZ |
2893 | case WM_SHOWWINDOW: |
2894 | processed = HandleShow(wParam != 0, (int)lParam); | |
2895 | break; | |
3a19e16d | 2896 | |
42e69d6b | 2897 | case WM_MOUSEMOVE: |
132cb640 VZ |
2898 | processed = HandleMouseMove(GET_X_LPARAM(lParam), |
2899 | GET_Y_LPARAM(lParam), | |
2900 | wParam); | |
2901 | break; | |
0d0512bd | 2902 | |
4e5c6c33 | 2903 | #ifdef HAVE_TRACKMOUSEEVENT |
e5297b7f | 2904 | case WM_MOUSELEAVE: |
aafb9978 VZ |
2905 | // filter out excess WM_MOUSELEAVE events sent after PopupMenu() |
2906 | // (on XP at least) | |
4e5c6c33 | 2907 | if ( m_mouseInWindow ) |
e5297b7f | 2908 | { |
4e5c6c33 | 2909 | GenerateMouseLeave(); |
e5297b7f | 2910 | } |
4e5c6c33 VZ |
2911 | |
2912 | // always pass processed back as false, this allows the window | |
2913 | // manager to process the message too. This is needed to | |
2914 | // ensure windows XP themes work properly as the mouse moves | |
2915 | // over widgets like buttons. So don't set processed to true here. | |
51e4e266 | 2916 | break; |
4e5c6c33 | 2917 | #endif // HAVE_TRACKMOUSEEVENT |
35bbb0c6 | 2918 | |
d2c52078 RD |
2919 | #if wxUSE_MOUSEWHEEL |
2920 | case WM_MOUSEWHEEL: | |
2921 | processed = HandleMouseWheel(wParam, lParam); | |
2922 | break; | |
2923 | #endif | |
2924 | ||
42e69d6b VZ |
2925 | case WM_LBUTTONDOWN: |
2926 | case WM_LBUTTONUP: | |
2927 | case WM_LBUTTONDBLCLK: | |
2928 | case WM_RBUTTONDOWN: | |
2929 | case WM_RBUTTONUP: | |
2930 | case WM_RBUTTONDBLCLK: | |
2931 | case WM_MBUTTONDOWN: | |
2932 | case WM_MBUTTONUP: | |
2933 | case WM_MBUTTONDBLCLK: | |
2f68482e | 2934 | #ifdef wxHAS_XBUTTON |
01101e2d VZ |
2935 | case WM_XBUTTONDOWN: |
2936 | case WM_XBUTTONUP: | |
2937 | case WM_XBUTTONDBLCLK: | |
2f68482e | 2938 | #endif // wxHAS_XBUTTON |
dfafa702 | 2939 | { |
98363307 | 2940 | #ifdef __WXMICROWIN__ |
cd4453e5 VZ |
2941 | // MicroWindows seems to ignore the fact that a window is |
2942 | // disabled. So catch mouse events and throw them away if | |
2943 | // necessary. | |
d0a3d109 | 2944 | wxWindowMSW* win = this; |
dfafa702 | 2945 | for ( ;; ) |
d0a3d109 VZ |
2946 | { |
2947 | if (!win->IsEnabled()) | |
2948 | { | |
08158721 | 2949 | processed = true; |
d0a3d109 VZ |
2950 | break; |
2951 | } | |
dfafa702 | 2952 | |
d0a3d109 | 2953 | win = win->GetParent(); |
dfafa702 | 2954 | if ( !win || win->IsTopLevel() ) |
d0a3d109 VZ |
2955 | break; |
2956 | } | |
dfafa702 | 2957 | |
03e0b2b1 VZ |
2958 | if ( processed ) |
2959 | break; | |
2960 | ||
dfafa702 | 2961 | #endif // __WXMICROWIN__ |
03e0b2b1 VZ |
2962 | int x = GET_X_LPARAM(lParam), |
2963 | y = GET_Y_LPARAM(lParam); | |
dfafa702 | 2964 | |
42b1fb63 | 2965 | #ifdef __WXWINCE__ |
03e0b2b1 | 2966 | // redirect the event to a static control if necessary by |
42b1fb63 VZ |
2967 | // finding one under mouse because under CE the static controls |
2968 | // don't generate mouse events (even with SS_NOTIFY) | |
03e0b2b1 VZ |
2969 | wxWindowMSW *win; |
2970 | if ( GetCapture() == this ) | |
2971 | { | |
2972 | // but don't do it if the mouse is captured by this window | |
2973 | // because then it should really get this event itself | |
2974 | win = this; | |
d0a3d109 | 2975 | } |
03e0b2b1 VZ |
2976 | else |
2977 | { | |
2978 | win = FindWindowForMouseEvent(this, &x, &y); | |
2b5f62a0 VZ |
2979 | |
2980 | // this should never happen | |
2981 | wxCHECK_MSG( win, 0, | |
9a83f860 | 2982 | wxT("FindWindowForMouseEvent() returned NULL") ); |
9f011847 | 2983 | } |
7d4f65e3 JS |
2984 | #ifdef __POCKETPC__ |
2985 | if (IsContextMenuEnabled() && message == WM_LBUTTONDOWN) | |
2986 | { | |
2987 | SHRGINFO shrgi = {0}; | |
faa94f3e | 2988 | |
7d4f65e3 JS |
2989 | shrgi.cbSize = sizeof(SHRGINFO); |
2990 | shrgi.hwndClient = (HWND) GetHWND(); | |
2991 | shrgi.ptDown.x = x; | |
2992 | shrgi.ptDown.y = y; | |
faa94f3e | 2993 | |
7d4f65e3 JS |
2994 | shrgi.dwFlags = SHRG_RETURNCMD; |
2995 | // shrgi.dwFlags = SHRG_NOTIFYPARENT; | |
faa94f3e | 2996 | |
7d4f65e3 JS |
2997 | if (GN_CONTEXTMENU == ::SHRecognizeGesture(&shrgi)) |
2998 | { | |
2999 | wxPoint pt(x, y); | |
3000 | pt = ClientToScreen(pt); | |
faa94f3e | 3001 | |
7d4f65e3 | 3002 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt); |
faa94f3e | 3003 | |
7d4f65e3 | 3004 | evtCtx.SetEventObject(this); |
937013e0 | 3005 | if (HandleWindowEvent(evtCtx)) |
f350d4b2 | 3006 | { |
7d4f65e3 | 3007 | processed = true; |
f350d4b2 JS |
3008 | return true; |
3009 | } | |
7d4f65e3 JS |
3010 | } |
3011 | } | |
3012 | #endif | |
3013 | ||
42b1fb63 VZ |
3014 | #else // !__WXWINCE__ |
3015 | wxWindowMSW *win = this; | |
3016 | #endif // __WXWINCE__/!__WXWINCE__ | |
9f011847 VZ |
3017 | |
3018 | processed = win->HandleMouseEvent(message, x, y, wParam); | |
2b5f62a0 | 3019 | |
9f011847 VZ |
3020 | // if the app didn't eat the event, handle it in the default |
3021 | // way, that is by giving this window the focus | |
3022 | if ( !processed ) | |
3023 | { | |
2b5f62a0 VZ |
3024 | // for the standard classes their WndProc sets the focus to |
3025 | // them anyhow and doing it from here results in some weird | |
9f011847 | 3026 | // problems, so don't do it for them (unnecessary anyhow) |
2b5f62a0 VZ |
3027 | if ( !win->IsOfStandardClass() ) |
3028 | { | |
edc09871 | 3029 | if ( message == WM_LBUTTONDOWN && win->IsFocusable() ) |
2b5f62a0 VZ |
3030 | win->SetFocus(); |
3031 | } | |
03e0b2b1 | 3032 | } |
98363307 | 3033 | } |
dfafa702 | 3034 | break; |
d0a3d109 | 3035 | |
cd4453e5 | 3036 | #ifdef MM_JOY1MOVE |
42e69d6b VZ |
3037 | case MM_JOY1MOVE: |
3038 | case MM_JOY2MOVE: | |
3039 | case MM_JOY1ZMOVE: | |
3040 | case MM_JOY2ZMOVE: | |
3041 | case MM_JOY1BUTTONDOWN: | |
3042 | case MM_JOY2BUTTONDOWN: | |
3043 | case MM_JOY1BUTTONUP: | |
3044 | case MM_JOY2BUTTONUP: | |
132cb640 VZ |
3045 | processed = HandleJoystickEvent(message, |
3046 | GET_X_LPARAM(lParam), | |
3047 | GET_Y_LPARAM(lParam), | |
3048 | wParam); | |
42e69d6b | 3049 | break; |
cd4453e5 | 3050 | #endif // __WXMICROWIN__ |
47cbd6da | 3051 | |
42e69d6b VZ |
3052 | case WM_COMMAND: |
3053 | { | |
3054 | WORD id, cmd; | |
3055 | WXHWND hwnd; | |
3056 | UnpackCommand(wParam, lParam, &id, &hwnd, &cmd); | |
47cbd6da | 3057 | |
42e69d6b VZ |
3058 | processed = HandleCommand(id, cmd, hwnd); |
3059 | } | |
3060 | break; | |
7d532b0c | 3061 | |
42e69d6b VZ |
3062 | case WM_NOTIFY: |
3063 | processed = HandleNotify((int)wParam, lParam, &rc.result); | |
3064 | break; | |
2bda0e17 | 3065 | |
27005f3a VZ |
3066 | // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU, |
3067 | // otherwise DefWindowProc() does it perfectly fine for us, but MSLU | |
3068 | // apparently doesn't always behave properly and needs some help | |
3069 | #if wxUSE_UNICODE_MSLU && defined(NF_QUERY) | |
3070 | case WM_NOTIFYFORMAT: | |
3071 | if ( lParam == NF_QUERY ) | |
3072 | { | |
3073 | processed = true; | |
3074 | rc.result = NFR_UNICODE; | |
3075 | } | |
3076 | break; | |
3077 | #endif // wxUSE_UNICODE_MSLU | |
3078 | ||
08158721 | 3079 | // for these messages we must return true if process the message |
cd4453e5 | 3080 | #ifdef WM_DRAWITEM |
42e69d6b | 3081 | case WM_DRAWITEM: |
dca0f651 VZ |
3082 | processed = MSWOnDrawItem(wParam, (WXDRAWITEMSTRUCT *)lParam); |
3083 | if ( processed ) | |
3084 | rc.result = TRUE; | |
3085 | break; | |
57a7b7c1 | 3086 | |
dca0f651 VZ |
3087 | case WM_MEASUREITEM: |
3088 | processed = MSWOnMeasureItem(wParam, (WXMEASUREITEMSTRUCT *)lParam); | |
3089 | if ( processed ) | |
3090 | rc.result = TRUE; | |
42e69d6b | 3091 | break; |
cd4453e5 VZ |
3092 | #endif // defined(WM_DRAWITEM) |
3093 | ||
9bf84618 | 3094 | case WM_GETDLGCODE: |
ff7282e1 | 3095 | if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS) ) |
9bf84618 | 3096 | { |
5a403e3f VZ |
3097 | // we always want to get the char events |
3098 | rc.result = DLGC_WANTCHARS; | |
3099 | ||
ff7282e1 | 3100 | if ( HasFlag(wxWANTS_CHARS) ) |
5a403e3f VZ |
3101 | { |
3102 | // in fact, we want everything | |
3103 | rc.result |= DLGC_WANTARROWS | | |
3104 | DLGC_WANTTAB | | |
3105 | DLGC_WANTALLKEYS; | |
3106 | } | |
3107 | ||
08158721 | 3108 | processed = true; |
9bf84618 | 3109 | } |
101f488c | 3110 | //else: get the dlg code from the DefWindowProc() |
9bf84618 VZ |
3111 | break; |
3112 | ||
4004f41e | 3113 | case WM_SYSKEYDOWN: |
42e69d6b | 3114 | case WM_KEYDOWN: |
9c7df356 VZ |
3115 | // If this has been processed by an event handler, return 0 now |
3116 | // (we've handled it). | |
3117 | m_lastKeydownProcessed = HandleKeyDown((WORD) wParam, lParam); | |
3118 | if ( m_lastKeydownProcessed ) | |
2d0a075d | 3119 | { |
08158721 | 3120 | processed = true; |
2d0a075d | 3121 | } |
81d66cf3 | 3122 | |
2b5f62a0 | 3123 | if ( !processed ) |
42e69d6b | 3124 | { |
2b5f62a0 VZ |
3125 | switch ( wParam ) |
3126 | { | |
90e572f1 | 3127 | // we consider these messages "not interesting" to OnChar, so |
2b5f62a0 VZ |
3128 | // just don't do anything more with them |
3129 | case VK_SHIFT: | |
3130 | case VK_CONTROL: | |
3131 | case VK_MENU: | |
3132 | case VK_CAPITAL: | |
3133 | case VK_NUMLOCK: | |
3134 | case VK_SCROLL: | |
08158721 | 3135 | processed = true; |
2b5f62a0 | 3136 | break; |
2bda0e17 | 3137 | |
2b5f62a0 VZ |
3138 | // avoid duplicate messages to OnChar for these ASCII keys: |
3139 | // they will be translated by TranslateMessage() and received | |
3140 | // in WM_CHAR | |
3141 | case VK_ESCAPE: | |
3142 | case VK_SPACE: | |
3143 | case VK_RETURN: | |
3144 | case VK_BACK: | |
3145 | case VK_TAB: | |
3146 | case VK_ADD: | |
3147 | case VK_SUBTRACT: | |
3148 | case VK_MULTIPLY: | |
3149 | case VK_DIVIDE: | |
7fd86b21 | 3150 | case VK_DECIMAL: |
3f2174bb VZ |
3151 | case VK_NUMPAD0: |
3152 | case VK_NUMPAD1: | |
3153 | case VK_NUMPAD2: | |
3154 | case VK_NUMPAD3: | |
3155 | case VK_NUMPAD4: | |
3156 | case VK_NUMPAD5: | |
3157 | case VK_NUMPAD6: | |
3158 | case VK_NUMPAD7: | |
3159 | case VK_NUMPAD8: | |
3160 | case VK_NUMPAD9: | |
2b5f62a0 VZ |
3161 | case VK_OEM_1: |
3162 | case VK_OEM_2: | |
3163 | case VK_OEM_3: | |
3164 | case VK_OEM_4: | |
3165 | case VK_OEM_5: | |
3166 | case VK_OEM_6: | |
3167 | case VK_OEM_7: | |
3168 | case VK_OEM_PLUS: | |
3169 | case VK_OEM_COMMA: | |
3170 | case VK_OEM_MINUS: | |
3171 | case VK_OEM_PERIOD: | |
08158721 | 3172 | // but set processed to false, not true to still pass them |
2b5f62a0 VZ |
3173 | // to the control's default window proc - otherwise |
3174 | // built-in keyboard handling won't work | |
08158721 | 3175 | processed = false; |
2b5f62a0 | 3176 | break; |
2bda0e17 | 3177 | |
42e69d6b | 3178 | #ifdef VK_APPS |
2b5f62a0 VZ |
3179 | // special case of VK_APPS: treat it the same as right mouse |
3180 | // click because both usually pop up a context menu | |
3181 | case VK_APPS: | |
ae177b45 | 3182 | processed = HandleMouseEvent(WM_RBUTTONDOWN, -1, -1, 0); |
2b5f62a0 | 3183 | break; |
42e69d6b | 3184 | #endif // VK_APPS |
2bda0e17 | 3185 | |
2b5f62a0 VZ |
3186 | default: |
3187 | // do generate a CHAR event | |
3188 | processed = HandleChar((WORD)wParam, lParam); | |
3189 | } | |
42e69d6b | 3190 | } |
2b5f62a0 | 3191 | if (message == WM_SYSKEYDOWN) // Let Windows still handle the SYSKEYs |
08158721 | 3192 | processed = false; |
42e69d6b | 3193 | break; |
2bda0e17 | 3194 | |
4004f41e | 3195 | case WM_SYSKEYUP: |
42e69d6b | 3196 | case WM_KEYUP: |
4aff28fc VZ |
3197 | #ifdef VK_APPS |
3198 | // special case of VK_APPS: treat it the same as right mouse button | |
3199 | if ( wParam == VK_APPS ) | |
3200 | { | |
ae177b45 | 3201 | processed = HandleMouseEvent(WM_RBUTTONUP, -1, -1, 0); |
4aff28fc VZ |
3202 | } |
3203 | else | |
3204 | #endif // VK_APPS | |
3205 | { | |
3206 | processed = HandleKeyUp((WORD) wParam, lParam); | |
3207 | } | |
42e69d6b | 3208 | break; |
debe6624 | 3209 | |
170cbe33 | 3210 | case WM_SYSCHAR: |
42e69d6b | 3211 | case WM_CHAR: // Always an ASCII character |
d9f14e16 RD |
3212 | if ( m_lastKeydownProcessed ) |
3213 | { | |
3214 | // The key was handled in the EVT_KEY_DOWN and handling | |
3215 | // a key in an EVT_KEY_DOWN handler is meant, by | |
3216 | // design, to prevent EVT_CHARs from happening | |
08158721 DS |
3217 | m_lastKeydownProcessed = false; |
3218 | processed = true; | |
d9f14e16 RD |
3219 | } |
3220 | else | |
7de5bdf4 | 3221 | { |
08158721 | 3222 | processed = HandleChar((WORD)wParam, lParam, true); |
7de5bdf4 | 3223 | } |
42e69d6b | 3224 | break; |
2bda0e17 | 3225 | |
5048c832 JS |
3226 | #if wxUSE_HOTKEY |
3227 | case WM_HOTKEY: | |
3228 | processed = HandleHotKey((WORD)wParam, lParam); | |
3229 | break; | |
540b6b09 | 3230 | #endif // wxUSE_HOTKEY |
5048c832 | 3231 | |
b65f16da VS |
3232 | case WM_CUT: |
3233 | case WM_COPY: | |
3234 | case WM_PASTE: | |
3235 | processed = HandleClipboardEvent(message); | |
3236 | break; | |
3237 | ||
42e69d6b VZ |
3238 | case WM_HSCROLL: |
3239 | case WM_VSCROLL: | |
a23fd0e1 | 3240 | { |
42e69d6b VZ |
3241 | WXWORD code, pos; |
3242 | WXHWND hwnd; | |
3243 | UnpackScroll(wParam, lParam, &code, &pos, &hwnd); | |
2bda0e17 | 3244 | |
42e69d6b VZ |
3245 | processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL |
3246 | : wxVERTICAL, | |
3247 | code, pos, hwnd); | |
a23fd0e1 | 3248 | } |
42e69d6b | 3249 | break; |
a23fd0e1 | 3250 | |
42e69d6b | 3251 | // CTLCOLOR messages are sent by children to query the parent for their |
01c500af | 3252 | // colors |
04ef50df | 3253 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
3254 | case WM_CTLCOLORMSGBOX: |
3255 | case WM_CTLCOLOREDIT: | |
3256 | case WM_CTLCOLORLISTBOX: | |
3257 | case WM_CTLCOLORBTN: | |
3258 | case WM_CTLCOLORDLG: | |
3259 | case WM_CTLCOLORSCROLLBAR: | |
3260 | case WM_CTLCOLORSTATIC: | |
a23fd0e1 | 3261 | { |
42e69d6b VZ |
3262 | WXHDC hdc; |
3263 | WXHWND hwnd; | |
01c500af | 3264 | UnpackCtlColor(wParam, lParam, &hdc, &hwnd); |
42e69d6b | 3265 | |
48fa6bd3 | 3266 | processed = HandleCtlColor(&rc.hBrush, (WXHDC)hdc, (WXHWND)hwnd); |
a23fd0e1 | 3267 | } |
42e69d6b | 3268 | break; |
cd4453e5 | 3269 | #endif // !__WXMICROWIN__ |
debe6624 | 3270 | |
42e69d6b | 3271 | case WM_SYSCOLORCHANGE: |
90c1530a | 3272 | // the return value for this message is ignored |
42e69d6b VZ |
3273 | processed = HandleSysColorChange(); |
3274 | break; | |
2bda0e17 | 3275 | |
7f0586ef | 3276 | #if !defined(__WXWINCE__) |
574c939e KB |
3277 | case WM_DISPLAYCHANGE: |
3278 | processed = HandleDisplayChange(); | |
3279 | break; | |
7f0586ef | 3280 | #endif |
574c939e | 3281 | |
42e69d6b | 3282 | case WM_PALETTECHANGED: |
dca0f651 | 3283 | processed = HandlePaletteChanged((WXHWND)wParam); |
42e69d6b | 3284 | break; |
2bda0e17 | 3285 | |
a5e84126 | 3286 | case WM_CAPTURECHANGED: |
dca0f651 | 3287 | processed = HandleCaptureChanged((WXHWND)lParam); |
a5e84126 JS |
3288 | break; |
3289 | ||
3c96418b JG |
3290 | case WM_SETTINGCHANGE: |
3291 | processed = HandleSettingChange(wParam, lParam); | |
3292 | break; | |
3293 | ||
42e69d6b VZ |
3294 | case WM_QUERYNEWPALETTE: |
3295 | processed = HandleQueryNewPalette(); | |
3296 | break; | |
2bda0e17 | 3297 | |
42e69d6b | 3298 | case WM_ERASEBKGND: |
bec9bf3e VZ |
3299 | { |
3300 | #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK | |
3301 | // check if an override was configured for this window | |
3302 | EraseBgHooks::const_iterator it = gs_eraseBgHooks.find(this); | |
3303 | if ( it != gs_eraseBgHooks.end() ) | |
3304 | processed = it->second->MSWEraseBgHook((WXHDC)wParam); | |
3305 | else | |
3306 | #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK | |
3307 | processed = HandleEraseBkgnd((WXHDC)wParam); | |
3308 | } | |
3309 | ||
42e69d6b VZ |
3310 | if ( processed ) |
3311 | { | |
3312 | // we processed the message, i.e. erased the background | |
3313 | rc.result = TRUE; | |
3314 | } | |
3315 | break; | |
debe6624 | 3316 | |
7f0586ef | 3317 | #if !defined(__WXWINCE__) |
42e69d6b VZ |
3318 | case WM_DROPFILES: |
3319 | processed = HandleDropFiles(wParam); | |
3320 | break; | |
7f0586ef | 3321 | #endif |
2bda0e17 | 3322 | |
42e69d6b | 3323 | case WM_INITDIALOG: |
dca0f651 | 3324 | processed = HandleInitDialog((WXHWND)wParam); |
a23fd0e1 | 3325 | |
42e69d6b VZ |
3326 | if ( processed ) |
3327 | { | |
3328 | // we never set focus from here | |
3329 | rc.result = FALSE; | |
3330 | } | |
3331 | break; | |
a23fd0e1 | 3332 | |
7f0586ef | 3333 | #if !defined(__WXWINCE__) |
42e69d6b VZ |
3334 | case WM_QUERYENDSESSION: |
3335 | processed = HandleQueryEndSession(lParam, &rc.allow); | |
3336 | break; | |
2bda0e17 | 3337 | |
42e69d6b VZ |
3338 | case WM_ENDSESSION: |
3339 | processed = HandleEndSession(wParam != 0, lParam); | |
3340 | break; | |
2bda0e17 | 3341 | |
42e69d6b | 3342 | case WM_GETMINMAXINFO: |
25889d3c | 3343 | processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam); |
42e69d6b | 3344 | break; |
7f0586ef | 3345 | #endif |
debe6624 | 3346 | |
42e69d6b | 3347 | case WM_SETCURSOR: |
dca0f651 | 3348 | processed = HandleSetCursor((WXHWND)wParam, |
42e69d6b VZ |
3349 | LOWORD(lParam), // hit test |
3350 | HIWORD(lParam)); // mouse msg | |
3351 | ||
3352 | if ( processed ) | |
3353 | { | |
3354 | // returning TRUE stops the DefWindowProc() from further | |
3355 | // processing this message - exactly what we need because we've | |
3356 | // just set the cursor. | |
3357 | rc.result = TRUE; | |
3358 | } | |
3359 | break; | |
4cdc2c13 | 3360 | |
ed5317e5 JS |
3361 | #if wxUSE_ACCESSIBILITY |
3362 | case WM_GETOBJECT: | |
3363 | { | |
3364 | //WPARAM dwFlags = (WPARAM) (DWORD) wParam; | |
3365 | LPARAM dwObjId = (LPARAM) (DWORD) lParam; | |
3366 | ||
66b9ec3d | 3367 | if (dwObjId == (LPARAM)OBJID_CLIENT && GetOrCreateAccessible()) |
ed5317e5 JS |
3368 | { |
3369 | return LresultFromObject(IID_IAccessible, wParam, (IUnknown*) GetAccessible()->GetIAccessible()); | |
3370 | } | |
3371 | break; | |
3372 | } | |
3373 | #endif | |
3374 | ||
e39af974 | 3375 | #if defined(WM_HELP) |
b96340e6 | 3376 | case WM_HELP: |
b96340e6 | 3377 | { |
a9c11b71 VZ |
3378 | // by default, WM_HELP is propagated by DefWindowProc() upwards |
3379 | // to the window parent but as we do it ourselves already | |
3380 | // (wxHelpEvent is derived from wxCommandEvent), we don't want | |
3381 | // to get the other events if we process this message at all | |
3382 | processed = true; | |
3383 | ||
3384 | // WM_HELP doesn't use lParam under CE | |
7f0586ef | 3385 | #ifndef __WXWINCE__ |
4cdc2c13 | 3386 | HELPINFO* info = (HELPINFO*) lParam; |
a9c11b71 | 3387 | if ( info->iContextType == HELPINFO_WINDOW ) |
b96340e6 | 3388 | { |
a9c11b71 VZ |
3389 | #endif // !__WXWINCE__ |
3390 | wxHelpEvent helpEvent | |
3391 | ( | |
3392 | wxEVT_HELP, | |
3393 | GetId(), | |
7f0586ef | 3394 | #ifdef __WXWINCE__ |
2d4ec362 | 3395 | wxGetMousePosition() // what else? |
7f0586ef | 3396 | #else |
a9c11b71 | 3397 | wxPoint(info->MousePos.x, info->MousePos.y) |
7f0586ef | 3398 | #endif |
a9c11b71 | 3399 | ); |
b96340e6 | 3400 | |
a9c11b71 | 3401 | helpEvent.SetEventObject(this); |
937013e0 | 3402 | HandleWindowEvent(helpEvent); |
7f0586ef | 3403 | #ifndef __WXWINCE__ |
b96340e6 | 3404 | } |
a9c11b71 | 3405 | else if ( info->iContextType == HELPINFO_MENUITEM ) |
4cdc2c13 VZ |
3406 | { |
3407 | wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId); | |
3408 | helpEvent.SetEventObject(this); | |
937013e0 | 3409 | HandleWindowEvent(helpEvent); |
69231000 | 3410 | |
4cdc2c13 | 3411 | } |
a9c11b71 VZ |
3412 | else // unknown help event? |
3413 | { | |
3414 | processed = false; | |
3415 | } | |
3416 | #endif // !__WXWINCE__ | |
b96340e6 | 3417 | } |
b96340e6 | 3418 | break; |
a9c11b71 | 3419 | #endif // WM_HELP |
4cdc2c13 | 3420 | |
7f0586ef | 3421 | #if !defined(__WXWINCE__) |
69231000 | 3422 | case WM_CONTEXTMENU: |
4cdc2c13 VZ |
3423 | { |
3424 | // we don't convert from screen to client coordinates as | |
3425 | // the event may be handled by a parent window | |
3426 | wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); | |
3427 | ||
3428 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt); | |
2d1715aa VZ |
3429 | |
3430 | // we could have got an event from our child, reflect it back | |
3431 | // to it if this is the case | |
d85c53a5 | 3432 | wxWindowMSW *win = NULL; |
dca0f651 VZ |
3433 | WXHWND hWnd = (WXHWND)wParam; |
3434 | if ( hWnd != m_hWnd ) | |
2d1715aa | 3435 | { |
dca0f651 | 3436 | win = FindItemByHWND(hWnd); |
2d1715aa VZ |
3437 | } |
3438 | ||
3439 | if ( !win ) | |
3440 | win = this; | |
3441 | ||
3442 | evtCtx.SetEventObject(win); | |
937013e0 | 3443 | processed = win->HandleWindowEvent(evtCtx); |
4cdc2c13 | 3444 | } |
69231000 | 3445 | break; |
7f0586ef | 3446 | #endif |
b74cce40 | 3447 | |
53a118d6 | 3448 | #if wxUSE_MENUS |
b74cce40 VZ |
3449 | case WM_MENUCHAR: |
3450 | // we're only interested in our own menus, not MF_SYSMENU | |
3451 | if ( HIWORD(wParam) == MF_POPUP ) | |
3452 | { | |
3453 | // handle menu chars for ownerdrawn menu items | |
3454 | int i = HandleMenuChar(toupper(LOWORD(wParam)), lParam); | |
3455 | if ( i != wxNOT_FOUND ) | |
3456 | { | |
3457 | rc.result = MAKELRESULT(i, MNC_EXECUTE); | |
08158721 | 3458 | processed = true; |
b74cce40 VZ |
3459 | } |
3460 | } | |
3461 | break; | |
53a118d6 | 3462 | #endif // wxUSE_MENUS |
355debca | 3463 | |
dbc74bcc | 3464 | #ifndef __WXWINCE__ |
355debca VZ |
3465 | case WM_POWERBROADCAST: |
3466 | { | |
3467 | bool vetoed; | |
3468 | processed = HandlePower(wParam, lParam, &vetoed); | |
3469 | rc.result = processed && vetoed ? BROADCAST_QUERY_DENY : TRUE; | |
3470 | } | |
3471 | break; | |
dbc74bcc | 3472 | #endif // __WXWINCE__ |
5acec112 | 3473 | |
a047aff2 JS |
3474 | #if wxUSE_UXTHEME |
3475 | // If we want the default themed border then we need to draw it ourselves | |
3476 | case WM_NCCALCSIZE: | |
3477 | { | |
3478 | wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); | |
dc797d8e JS |
3479 | const wxBorder border = TranslateBorder(GetBorder()); |
3480 | if (theme && border == wxBORDER_THEME) | |
a047aff2 JS |
3481 | { |
3482 | // first ask the widget to calculate the border size | |
3483 | rc.result = MSWDefWindowProc(message, wParam, lParam); | |
3484 | processed = true; | |
3485 | ||
e822d1bd VZ |
3486 | // now alter the client size making room for drawing a |
3487 | // themed border | |
dca0f651 | 3488 | RECT *rect; |
140d93c0 | 3489 | NCCALCSIZE_PARAMS *csparam = NULL; |
dca0f651 | 3490 | if ( wParam ) |
a047aff2 | 3491 | { |
140d93c0 | 3492 | csparam = (NCCALCSIZE_PARAMS *)lParam; |
dca0f651 | 3493 | rect = &csparam->rgrc[0]; |
a047aff2 JS |
3494 | } |
3495 | else | |
3496 | { | |
dca0f651 | 3497 | rect = (RECT *)lParam; |
a047aff2 | 3498 | } |
dca0f651 | 3499 | |
fe545198 | 3500 | wxUxThemeHandle hTheme((const wxWindow *)this, L"EDIT"); |
a047aff2 | 3501 | RECT rcClient = { 0, 0, 0, 0 }; |
d935b421 | 3502 | wxClientDC dc((wxWindow *)this); |
888dde65 | 3503 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
a047aff2 | 3504 | |
dca0f651 VZ |
3505 | if ( theme->GetThemeBackgroundContentRect |
3506 | ( | |
3507 | hTheme, | |
3508 | GetHdcOf(*impl), | |
3509 | EP_EDITTEXT, | |
3510 | ETS_NORMAL, | |
3511 | rect, | |
3512 | &rcClient) == S_OK ) | |
a047aff2 JS |
3513 | { |
3514 | InflateRect(&rcClient, -1, -1); | |
140d93c0 JS |
3515 | if (wParam) |
3516 | csparam->rgrc[0] = rcClient; | |
3517 | else | |
3518 | *((RECT*)lParam) = rcClient; | |
3519 | ||
3520 | // WVR_REDRAW triggers a bug whereby child windows are moved up and left, | |
3521 | // so don't use. | |
3522 | // rc.result = WVR_REDRAW; | |
a047aff2 JS |
3523 | } |
3524 | } | |
3525 | } | |
3526 | break; | |
3527 | ||
3528 | case WM_NCPAINT: | |
3529 | { | |
3530 | wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); | |
dc797d8e JS |
3531 | const wxBorder border = TranslateBorder(GetBorder()); |
3532 | if (theme && border == wxBORDER_THEME) | |
a047aff2 JS |
3533 | { |
3534 | // first ask the widget to paint its non-client area, such as scrollbars, etc. | |
3535 | rc.result = MSWDefWindowProc(message, wParam, lParam); | |
3536 | processed = true; | |
3537 | ||
fe545198 | 3538 | wxUxThemeHandle hTheme((const wxWindow *)this, L"EDIT"); |
d935b421 | 3539 | wxWindowDC dc((wxWindow *)this); |
888dde65 | 3540 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
a047aff2 JS |
3541 | |
3542 | // Clip the DC so that you only draw on the non-client area | |
3543 | RECT rcBorder; | |
3544 | wxCopyRectToRECT(GetSize(), rcBorder); | |
3545 | ||
3546 | RECT rcClient; | |
3547 | theme->GetThemeBackgroundContentRect( | |
888dde65 | 3548 | hTheme, GetHdcOf(*impl), EP_EDITTEXT, ETS_NORMAL, &rcBorder, &rcClient); |
a047aff2 JS |
3549 | InflateRect(&rcClient, -1, -1); |
3550 | ||
888dde65 | 3551 | ::ExcludeClipRect(GetHdcOf(*impl), rcClient.left, rcClient.top, |
a047aff2 JS |
3552 | rcClient.right, rcClient.bottom); |
3553 | ||
3554 | // Make sure the background is in a proper state | |
3555 | if (theme->IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL)) | |
3556 | { | |
888dde65 | 3557 | theme->DrawThemeParentBackground(GetHwnd(), GetHdcOf(*impl), &rcBorder); |
a047aff2 JS |
3558 | } |
3559 | ||
3560 | // Draw the border | |
3561 | int nState; | |
3562 | if ( !IsEnabled() ) | |
3563 | nState = ETS_DISABLED; | |
3564 | // should we check this? | |
3565 | //else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY) | |
3566 | // nState = ETS_READONLY; | |
3567 | else | |
3568 | nState = ETS_NORMAL; | |
888dde65 | 3569 | theme->DrawThemeBackground(hTheme, GetHdcOf(*impl), EP_EDITTEXT, nState, &rcBorder, NULL); |
a047aff2 JS |
3570 | } |
3571 | } | |
3572 | break; | |
3573 | ||
3574 | #endif // wxUSE_UXTHEME | |
3575 | ||
5acec112 VZ |
3576 | default: |
3577 | // try a custom message handler | |
3578 | const MSWMessageHandlers::const_iterator | |
3579 | i = gs_messageHandlers.find(message); | |
3580 | if ( i != gs_messageHandlers.end() ) | |
3581 | { | |
3582 | processed = (*i->second)(this, message, wParam, lParam); | |
3583 | } | |
a23fd0e1 | 3584 | } |
2d0a075d | 3585 | |
42e69d6b | 3586 | if ( !processed ) |
2d0a075d | 3587 | { |
4b6a582b | 3588 | #if wxDEBUG_LEVEL >= 2 |
5ec3853f | 3589 | wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."), |
42e69d6b | 3590 | wxGetMessageName(message)); |
4b6a582b | 3591 | #endif // wxDEBUG_LEVEL >= 2 |
42e69d6b | 3592 | rc.result = MSWDefWindowProc(message, wParam, lParam); |
a23fd0e1 | 3593 | } |
2bda0e17 | 3594 | |
42e69d6b | 3595 | return rc.result; |
2bda0e17 KB |
3596 | } |
3597 | ||
b225f659 VZ |
3598 | // ---------------------------------------------------------------------------- |
3599 | // wxWindow <-> HWND map | |
3600 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 3601 | |
dca0f651 | 3602 | wxWindow *wxFindWinFromHandle(HWND hwnd) |
4ce81a75 | 3603 | { |
dca0f651 VZ |
3604 | WindowHandles::const_iterator i = gs_windowHandles.find(hwnd); |
3605 | return i == gs_windowHandles.end() ? NULL : i->second; | |
42e69d6b | 3606 | } |
4ce81a75 | 3607 | |
dca0f651 | 3608 | void wxAssociateWinWithHandle(HWND hwnd, wxWindowMSW *win) |
42e69d6b | 3609 | { |
dca0f651 | 3610 | // adding NULL hwnd is (first) surely a result of an error and |
42e69d6b | 3611 | // (secondly) breaks menu command processing |
dca0f651 VZ |
3612 | wxCHECK_RET( hwnd != (HWND)NULL, |
3613 | wxT("attempt to add a NULL hwnd to window list ignored") ); | |
4ce81a75 | 3614 | |
4b6a582b | 3615 | #if wxDEBUG_LEVEL |
dca0f651 VZ |
3616 | WindowHandles::const_iterator i = gs_windowHandles.find(hwnd); |
3617 | if ( i != gs_windowHandles.end() ) | |
c7527e3f | 3618 | { |
dca0f651 VZ |
3619 | if ( i->second != win ) |
3620 | { | |
4b6a582b VZ |
3621 | wxFAIL_MSG( |
3622 | wxString::Format( | |
3623 | wxT("HWND %p already associated with another window (%s)"), | |
3624 | hwnd, win->GetClassInfo()->GetClassName() | |
3625 | ) | |
3626 | ); | |
dca0f651 VZ |
3627 | } |
3628 | //else: this actually happens currently because we associate the window | |
3629 | // with its HWND during creation (if we create it) and also when | |
3630 | // SubclassWin() is called later, this is ok | |
c7527e3f | 3631 | } |
4b6a582b | 3632 | #endif // wxDEBUG_LEVEL |
dca0f651 | 3633 | |
936bb82e | 3634 | gs_windowHandles[hwnd] = (wxWindow *)win; |
42e69d6b | 3635 | } |
4ce81a75 | 3636 | |
1e6feb95 | 3637 | void wxRemoveHandleAssociation(wxWindowMSW *win) |
42e69d6b | 3638 | { |
dca0f651 | 3639 | gs_windowHandles.erase(GetHwndOf(win)); |
4ce81a75 JS |
3640 | } |
3641 | ||
b225f659 VZ |
3642 | // ---------------------------------------------------------------------------- |
3643 | // various MSW speciic class dependent functions | |
3644 | // ---------------------------------------------------------------------------- | |
3645 | ||
42e69d6b VZ |
3646 | // Default destroyer - override if you destroy it in some other way |
3647 | // (e.g. with MDI child windows) | |
1e6feb95 | 3648 | void wxWindowMSW::MSWDestroyWindow() |
4ce81a75 | 3649 | { |
42e69d6b | 3650 | } |
4ce81a75 | 3651 | |
fa5f4858 | 3652 | void wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos, |
b225f659 VZ |
3653 | const wxSize& size, |
3654 | int& x, int& y, | |
3655 | int& w, int& h) const | |
2bda0e17 | 3656 | { |
fa5f4858 VZ |
3657 | // CW_USEDEFAULT can't be used for child windows so just position them at |
3658 | // the origin by default | |
3659 | x = pos.x == wxDefaultCoord ? 0 : pos.x; | |
3660 | y = pos.y == wxDefaultCoord ? 0 : pos.y; | |
2a77c8c4 | 3661 | |
fa5f4858 | 3662 | AdjustForParentClientOrigin(x, y); |
c085e333 | 3663 | |
fa5f4858 VZ |
3664 | // We don't have any clearly good choice for the size by default neither |
3665 | // but we must use something non-zero. | |
3666 | w = WidthDefault(size.x); | |
3667 | h = HeightDefault(size.y); | |
2bda0e17 | 3668 | |
b889a3a2 VZ |
3669 | /* |
3670 | NB: there used to be some code here which set the initial size of the | |
3671 | window to the client size of the parent if no explicit size was | |
77ffb593 | 3672 | specified. This was wrong because wxWidgets programs often assume |
b889a3a2 VZ |
3673 | that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke |
3674 | it. To see why, you should understand that Windows sends WM_SIZE from | |
3675 | inside ::CreateWindow() anyhow. However, ::CreateWindow() is called | |
3676 | from some base class ctor and so this WM_SIZE is not processed in the | |
3677 | real class' OnSize() (because it's not fully constructed yet and the | |
3678 | event goes to some base class OnSize() instead). So the WM_SIZE we | |
3679 | rely on is the one sent when the parent frame resizes its children | |
3680 | but here is the problem: if the child already has just the right | |
77ffb593 | 3681 | size, nothing will happen as both wxWidgets and Windows check for |
b889a3a2 VZ |
3682 | this and ignore any attempts to change the window size to the size it |
3683 | already has - so no WM_SIZE would be sent. | |
3684 | */ | |
b225f659 VZ |
3685 | } |
3686 | ||
9dfef5ac VZ |
3687 | WXHWND wxWindowMSW::MSWGetParent() const |
3688 | { | |
d285d708 | 3689 | return m_parent ? m_parent->GetHWND() : WXHWND(NULL); |
9dfef5ac VZ |
3690 | } |
3691 | ||
b225f659 VZ |
3692 | bool wxWindowMSW::MSWCreate(const wxChar *wclass, |
3693 | const wxChar *title, | |
3694 | const wxPoint& pos, | |
3695 | const wxSize& size, | |
3696 | WXDWORD style, | |
3697 | WXDWORD extendedStyle) | |
3698 | { | |
23035521 VZ |
3699 | // check a common bug in the user code: if the window is created with a |
3700 | // non-default ctor and Create() is called too, we'd create 2 HWND for a | |
3701 | // single wxWindow object and this results in all sorts of trouble, | |
3702 | // especially for wxTLWs | |
3703 | wxCHECK_MSG( !m_hWnd, true, "window can't be recreated" ); | |
3704 | ||
d9698bd4 VZ |
3705 | // this can happen if this function is called using the return value of |
3706 | // wxApp::GetRegisteredClassName() which failed | |
3707 | wxCHECK_MSG( wclass, false, "failed to register window class?" ); | |
3708 | ||
3709 | ||
b225f659 VZ |
3710 | // choose the position/size for the new window |
3711 | int x, y, w, h; | |
3712 | (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h); | |
3713 | ||
b225f659 VZ |
3714 | // controlId is menu handle for the top level windows, so set it to 0 |
3715 | // unless we're creating a child window | |
f586fde3 | 3716 | int controlId = style & WS_CHILD ? GetId() : 0; |
2bda0e17 | 3717 | |
b225f659 VZ |
3718 | // for each class "Foo" we have we also have "FooNR" ("no repaint") class |
3719 | // which is the same but without CS_[HV]REDRAW class styles so using it | |
3720 | // ensures that the window is not fully repainted on each resize | |
3721 | wxString className(wclass); | |
e441e1f4 | 3722 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) |
b225f659 | 3723 | { |
d9698bd4 | 3724 | className += wxApp::GetNoRedrawClassSuffix(); |
a23fd0e1 | 3725 | } |
c085e333 | 3726 | |
b225f659 VZ |
3727 | // do create the window |
3728 | wxWindowCreationHook hook(this); | |
b3daa5a3 | 3729 | |
5e67eb97 VZ |
3730 | m_hWnd = (WXHWND)::CreateWindowEx |
3731 | ( | |
3732 | extendedStyle, | |
e0a050e3 VS |
3733 | className.wx_str(), |
3734 | title ? title : m_windowName.wx_str(), | |
5e67eb97 VZ |
3735 | style, |
3736 | x, y, w, h, | |
3737 | (HWND)MSWGetParent(), | |
dca0f651 | 3738 | (HMENU)wxUIntToPtr(controlId), |
5e67eb97 VZ |
3739 | wxGetInstance(), |
3740 | NULL // no extra data | |
3741 | ); | |
b225f659 VZ |
3742 | |
3743 | if ( !m_hWnd ) | |
c7527e3f | 3744 | { |
5e67eb97 | 3745 | wxLogSysError(_("Can't create window of class %s"), className.c_str()); |
b225f659 | 3746 | |
08158721 | 3747 | return false; |
c7527e3f | 3748 | } |
b3daa5a3 | 3749 | |
b225f659 | 3750 | SubclassWin(m_hWnd); |
c085e333 | 3751 | |
08158721 | 3752 | return true; |
2bda0e17 KB |
3753 | } |
3754 | ||
42e69d6b VZ |
3755 | // =========================================================================== |
3756 | // MSW message handlers | |
3757 | // =========================================================================== | |
3758 | ||
3759 | // --------------------------------------------------------------------------- | |
3760 | // WM_NOTIFY | |
3761 | // --------------------------------------------------------------------------- | |
3762 | ||
1e6feb95 | 3763 | bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
2bda0e17 | 3764 | { |
04ef50df | 3765 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
3766 | LPNMHDR hdr = (LPNMHDR)lParam; |
3767 | HWND hWnd = hdr->hwndFrom; | |
dca0f651 | 3768 | wxWindow *win = wxFindWinFromHandle(hWnd); |
42e69d6b | 3769 | |
2b15b970 | 3770 | // if the control is one of our windows, let it handle the message itself |
42e69d6b | 3771 | if ( win ) |
564b2609 | 3772 | { |
42e69d6b | 3773 | return win->MSWOnNotify(idCtrl, lParam, result); |
564b2609 | 3774 | } |
2bda0e17 | 3775 | |
2b15b970 VZ |
3776 | // VZ: why did we do it? normally this is unnecessary and, besides, it |
3777 | // breaks the message processing for the toolbars because the tooltip | |
3778 | // notifications were being forwarded to the toolbar child controls | |
3779 | // (if it had any) before being passed to the toolbar itself, so in my | |
3780 | // example the tooltip for the combobox was always shown instead of the | |
3781 | // correct button tooltips | |
3782 | #if 0 | |
42e69d6b | 3783 | // try all our children |
222ed1d6 | 3784 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
42e69d6b | 3785 | while ( node ) |
564b2609 | 3786 | { |
42e69d6b VZ |
3787 | wxWindow *child = node->GetData(); |
3788 | if ( child->MSWOnNotify(idCtrl, lParam, result) ) | |
3789 | { | |
08158721 | 3790 | return true; |
42e69d6b | 3791 | } |
2d0a075d | 3792 | |
42e69d6b VZ |
3793 | node = node->GetNext(); |
3794 | } | |
2b15b970 | 3795 | #endif // 0 |
2d0a075d | 3796 | |
2b15b970 | 3797 | // by default, handle it ourselves |
42e69d6b | 3798 | return MSWOnNotify(idCtrl, lParam, result); |
cd4453e5 | 3799 | #else // __WXMICROWIN__ |
08158721 | 3800 | return false; |
04ef50df | 3801 | #endif |
42e69d6b | 3802 | } |
2d0a075d | 3803 | |
bd9cd534 VZ |
3804 | #if wxUSE_TOOLTIPS |
3805 | ||
3806 | bool wxWindowMSW::HandleTooltipNotify(WXUINT code, | |
3807 | WXLPARAM lParam, | |
3808 | const wxString& ttip) | |
3809 | { | |
3810 | // I don't know why it happens, but the versions of comctl32.dll starting | |
3811 | // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally, | |
3812 | // this message is supposed to be sent to Unicode programs only) -- hence | |
3813 | // we need to handle it as well, otherwise no tooltips will be shown in | |
3814 | // this case | |
7f0586ef | 3815 | #ifndef __WXWINCE__ |
118208ac VZ |
3816 | if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW) |
3817 | || ttip.empty() ) | |
bd9cd534 VZ |
3818 | { |
3819 | // not a tooltip message or no tooltip to show anyhow | |
08158721 | 3820 | return false; |
bd9cd534 | 3821 | } |
7f0586ef | 3822 | #endif |
bd9cd534 VZ |
3823 | |
3824 | LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam; | |
3825 | ||
118208ac VZ |
3826 | // We don't want to use the szText buffer because it has a limit of 80 |
3827 | // bytes and this is not enough, especially for Unicode build where it | |
3828 | // limits the tooltip string length to only 40 characters | |
3829 | // | |
3830 | // The best would be, of course, to not impose any length limitations at | |
3831 | // all but then the buffer would have to be dynamic and someone would have | |
3832 | // to free it and we don't have the tooltip owner object here any more, so | |
3833 | // for now use our own static buffer with a higher fixed max length. | |
3834 | // | |
3835 | // Note that using a static buffer should not be a problem as only a single | |
3836 | // tooltip can be shown at the same time anyhow. | |
2b5f62a0 | 3837 | #if !wxUSE_UNICODE |
118208ac | 3838 | if ( code == (WXUINT) TTN_NEEDTEXTW ) |
bd9cd534 | 3839 | { |
118208ac VZ |
3840 | // We need to convert tooltip from multi byte to Unicode on the fly. |
3841 | static wchar_t buf[513]; | |
25c46fda | 3842 | |
118208ac VZ |
3843 | // Truncate tooltip length if needed as otherwise we might not have |
3844 | // enough space for it in the buffer and MultiByteToWideChar() would | |
3845 | // return an error | |
fec9cc08 | 3846 | size_t tipLength = wxMin(ttip.length(), WXSIZEOF(buf) - 1); |
7afebc8c JS |
3847 | |
3848 | // Convert to WideChar without adding the NULL character. The NULL | |
25c46fda | 3849 | // character is added afterwards (this is more efficient). |
118208ac VZ |
3850 | int len = ::MultiByteToWideChar |
3851 | ( | |
3852 | CP_ACP, | |
3853 | 0, // no flags | |
b05fde97 | 3854 | ttip.wx_str(), |
118208ac VZ |
3855 | tipLength, |
3856 | buf, | |
3857 | WXSIZEOF(buf) - 1 | |
3858 | ); | |
3859 | ||
3860 | if ( !len ) | |
3861 | { | |
9a83f860 | 3862 | wxLogLastError(wxT("MultiByteToWideChar()")); |
118208ac | 3863 | } |
7afebc8c | 3864 | |
118208ac VZ |
3865 | buf[len] = L'\0'; |
3866 | ttText->lpszText = (LPSTR) buf; | |
3867 | } | |
3868 | else // TTN_NEEDTEXTA | |
3869 | #endif // !wxUSE_UNICODE | |
3870 | { | |
3871 | // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or | |
3872 | // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have | |
3873 | // to copy the string we have into the buffer | |
3874 | static wxChar buf[513]; | |
e408bf52 | 3875 | wxStrlcpy(buf, ttip.c_str(), WXSIZEOF(buf)); |
118208ac | 3876 | ttText->lpszText = buf; |
bd9cd534 VZ |
3877 | } |
3878 | ||
08158721 | 3879 | return true; |
bd9cd534 VZ |
3880 | } |
3881 | ||
3882 | #endif // wxUSE_TOOLTIPS | |
3883 | ||
1e6feb95 | 3884 | bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl), |
bd9cd534 VZ |
3885 | WXLPARAM lParam, |
3886 | WXLPARAM* WXUNUSED(result)) | |
42e69d6b VZ |
3887 | { |
3888 | #if wxUSE_TOOLTIPS | |
bd9cd534 | 3889 | if ( m_tooltip ) |
42e69d6b | 3890 | { |
bd9cd534 VZ |
3891 | NMHDR* hdr = (NMHDR *)lParam; |
3892 | if ( HandleTooltipNotify(hdr->code, lParam, m_tooltip->GetTip())) | |
3893 | { | |
3894 | // processed | |
08158721 | 3895 | return true; |
bd9cd534 | 3896 | } |
42e69d6b | 3897 | } |
f5dd1cf1 WS |
3898 | #else |
3899 | wxUnusedVar(lParam); | |
42e69d6b VZ |
3900 | #endif // wxUSE_TOOLTIPS |
3901 | ||
08158721 | 3902 | return false; |
42e69d6b | 3903 | } |
2b15b970 | 3904 | |
42e69d6b VZ |
3905 | // --------------------------------------------------------------------------- |
3906 | // end session messages | |
3907 | // --------------------------------------------------------------------------- | |
2d0a075d | 3908 | |
1e6feb95 | 3909 | bool wxWindowMSW::HandleQueryEndSession(long logOff, bool *mayEnd) |
42e69d6b | 3910 | { |
040e5f77 | 3911 | #ifdef ENDSESSION_LOGOFF |
abb74e0f | 3912 | wxCloseEvent event(wxEVT_QUERY_END_SESSION, wxID_ANY); |
42e69d6b | 3913 | event.SetEventObject(wxTheApp); |
08158721 | 3914 | event.SetCanVeto(true); |
a17e237f | 3915 | event.SetLoggingOff(logOff == (long)ENDSESSION_LOGOFF); |
2d0a075d | 3916 | |
42e69d6b VZ |
3917 | bool rc = wxTheApp->ProcessEvent(event); |
3918 | ||
3919 | if ( rc ) | |
3920 | { | |
3921 | // we may end only if the app didn't veto session closing (double | |
3922 | // negation...) | |
3923 | *mayEnd = !event.GetVeto(); | |
2d0a075d JS |
3924 | } |
3925 | ||
42e69d6b | 3926 | return rc; |
7f0586ef | 3927 | #else |
040e5f77 VZ |
3928 | wxUnusedVar(logOff); |
3929 | wxUnusedVar(mayEnd); | |
08158721 | 3930 | return false; |
7f0586ef | 3931 | #endif |
2bda0e17 KB |
3932 | } |
3933 | ||
1e6feb95 | 3934 | bool wxWindowMSW::HandleEndSession(bool endSession, long logOff) |
2bda0e17 | 3935 | { |
040e5f77 | 3936 | #ifdef ENDSESSION_LOGOFF |
42e69d6b VZ |
3937 | // do nothing if the session isn't ending |
3938 | if ( !endSession ) | |
08158721 | 3939 | return false; |
a23fd0e1 | 3940 | |
519dc37f VZ |
3941 | // only send once |
3942 | if ( (this != wxTheApp->GetTopWindow()) ) | |
08158721 | 3943 | return false; |
519dc37f | 3944 | |
abb74e0f | 3945 | wxCloseEvent event(wxEVT_END_SESSION, wxID_ANY); |
42e69d6b | 3946 | event.SetEventObject(wxTheApp); |
08158721 | 3947 | event.SetCanVeto(false); |
f801d19a | 3948 | event.SetLoggingOff((logOff & ENDSESSION_LOGOFF) != 0); |
519dc37f VZ |
3949 | |
3950 | return wxTheApp->ProcessEvent(event); | |
7f0586ef | 3951 | #else |
040e5f77 VZ |
3952 | wxUnusedVar(endSession); |
3953 | wxUnusedVar(logOff); | |
08158721 | 3954 | return false; |
7f0586ef | 3955 | #endif |
2bda0e17 KB |
3956 | } |
3957 | ||
42e69d6b VZ |
3958 | // --------------------------------------------------------------------------- |
3959 | // window creation/destruction | |
3960 | // --------------------------------------------------------------------------- | |
3961 | ||
0c0d1521 WS |
3962 | bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT WXUNUSED_IN_WINCE(cs), |
3963 | bool *mayCreate) | |
61179e28 | 3964 | { |
ee471817 VZ |
3965 | // VZ: why is this commented out for WinCE? If it doesn't support |
3966 | // WS_EX_CONTROLPARENT at all it should be somehow handled globally, | |
3967 | // not with multiple #ifdef's! | |
7f0586ef | 3968 | #ifndef __WXWINCE__ |
61179e28 | 3969 | if ( ((CREATESTRUCT *)cs)->dwExStyle & WS_EX_CONTROLPARENT ) |
ee471817 VZ |
3970 | EnsureParentHasControlParentStyle(GetParent()); |
3971 | #endif // !__WXWINCE__ | |
61179e28 | 3972 | |
08158721 | 3973 | *mayCreate = true; |
42e69d6b | 3974 | |
08158721 | 3975 | return true; |
2bda0e17 KB |
3976 | } |
3977 | ||
1e6feb95 | 3978 | bool wxWindowMSW::HandleDestroy() |
2bda0e17 | 3979 | { |
42e69d6b VZ |
3980 | // delete our drop target if we've got one |
3981 | #if wxUSE_DRAG_AND_DROP | |
3982 | if ( m_dropTarget != NULL ) | |
2d0a075d | 3983 | { |
42e69d6b VZ |
3984 | m_dropTarget->Revoke(m_hWnd); |
3985 | ||
3986 | delete m_dropTarget; | |
3987 | m_dropTarget = NULL; | |
2d0a075d | 3988 | } |
42e69d6b | 3989 | #endif // wxUSE_DRAG_AND_DROP |
2bda0e17 | 3990 | |
42e69d6b | 3991 | // WM_DESTROY handled |
08158721 | 3992 | return true; |
2bda0e17 KB |
3993 | } |
3994 | ||
42e69d6b VZ |
3995 | // --------------------------------------------------------------------------- |
3996 | // activation/focus | |
3997 | // --------------------------------------------------------------------------- | |
3998 | ||
1e6feb95 | 3999 | bool wxWindowMSW::HandleActivate(int state, |
42e69d6b VZ |
4000 | bool WXUNUSED(minimized), |
4001 | WXHWND WXUNUSED(activate)) | |
2bda0e17 | 4002 | { |
42e69d6b VZ |
4003 | wxActivateEvent event(wxEVT_ACTIVATE, |
4004 | (state == WA_ACTIVE) || (state == WA_CLICKACTIVE), | |
4005 | m_windowId); | |
4006 | event.SetEventObject(this); | |
4007 | ||
937013e0 | 4008 | return HandleWindowEvent(event); |
42e69d6b VZ |
4009 | } |
4010 | ||
1e6feb95 | 4011 | bool wxWindowMSW::HandleSetFocus(WXHWND hwnd) |
42e69d6b | 4012 | { |
c7aee865 RD |
4013 | // Strangly enough, some controls get set focus events when they are being |
4014 | // deleted, even if they already had focus before. | |
4015 | if ( m_isBeingDeleted ) | |
4016 | { | |
4017 | return false; | |
4018 | } | |
35bbb0c6 | 4019 | |
456bc6d9 VZ |
4020 | // notify the parent keeping track of focus for the kbd navigation |
4021 | // purposes that we got it | |
e72aa7f5 | 4022 | wxChildFocusEvent eventFocus((wxWindow *)this); |
937013e0 | 4023 | (void)HandleWindowEvent(eventFocus); |
456bc6d9 | 4024 | |
789295bf | 4025 | #if wxUSE_CARET |
42e69d6b | 4026 | // Deal with caret |
789295bf | 4027 | if ( m_caret ) |
2d0a075d | 4028 | { |
789295bf | 4029 | m_caret->OnSetFocus(); |
2bda0e17 | 4030 | } |
789295bf | 4031 | #endif // wxUSE_CARET |
42e69d6b | 4032 | |
42e69d6b VZ |
4033 | wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); |
4034 | event.SetEventObject(this); | |
4035 | ||
1e6feb95 VZ |
4036 | // wxFindWinFromHandle() may return NULL, it is ok |
4037 | event.SetWindow(wxFindWinFromHandle(hwnd)); | |
4038 | ||
937013e0 | 4039 | return HandleWindowEvent(event); |
2bda0e17 KB |
4040 | } |
4041 | ||
1e6feb95 | 4042 | bool wxWindowMSW::HandleKillFocus(WXHWND hwnd) |
2bda0e17 | 4043 | { |
789295bf | 4044 | #if wxUSE_CARET |
42e69d6b | 4045 | // Deal with caret |
789295bf | 4046 | if ( m_caret ) |
2d0a075d | 4047 | { |
789295bf | 4048 | m_caret->OnKillFocus(); |
2bda0e17 | 4049 | } |
789295bf | 4050 | #endif // wxUSE_CARET |
42e69d6b | 4051 | |
2913e597 RD |
4052 | // Don't send the event when in the process of being deleted. This can |
4053 | // only cause problems if the event handler tries to access the object. | |
4054 | if ( m_isBeingDeleted ) | |
4055 | { | |
08158721 | 4056 | return false; |
2913e597 RD |
4057 | } |
4058 | ||
42e69d6b VZ |
4059 | wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId); |
4060 | event.SetEventObject(this); | |
4061 | ||
1e6feb95 VZ |
4062 | // wxFindWinFromHandle() may return NULL, it is ok |
4063 | event.SetWindow(wxFindWinFromHandle(hwnd)); | |
4064 | ||
937013e0 | 4065 | return HandleWindowEvent(event); |
2bda0e17 KB |
4066 | } |
4067 | ||
faa49bfd WS |
4068 | // --------------------------------------------------------------------------- |
4069 | // labels | |
4070 | // --------------------------------------------------------------------------- | |
4071 | ||
4072 | void wxWindowMSW::SetLabel( const wxString& label) | |
4073 | { | |
4074 | SetWindowText(GetHwnd(), label.c_str()); | |
4075 | } | |
4076 | ||
4077 | wxString wxWindowMSW::GetLabel() const | |
4078 | { | |
4079 | return wxGetWindowText(GetHWND()); | |
4080 | } | |
4081 | ||
42e69d6b VZ |
4082 | // --------------------------------------------------------------------------- |
4083 | // miscellaneous | |
4084 | // --------------------------------------------------------------------------- | |
4085 | ||
1e6feb95 | 4086 | bool wxWindowMSW::HandleShow(bool show, int WXUNUSED(status)) |
2bda0e17 | 4087 | { |
42e69d6b | 4088 | wxShowEvent event(GetId(), show); |
687706f5 | 4089 | event.SetEventObject(this); |
42e69d6b | 4090 | |
937013e0 | 4091 | return HandleWindowEvent(event); |
2bda0e17 KB |
4092 | } |
4093 | ||
1e6feb95 | 4094 | bool wxWindowMSW::HandleInitDialog(WXHWND WXUNUSED(hWndFocus)) |
2bda0e17 | 4095 | { |
42e69d6b | 4096 | wxInitDialogEvent event(GetId()); |
687706f5 | 4097 | event.SetEventObject(this); |
42e69d6b | 4098 | |
937013e0 | 4099 | return HandleWindowEvent(event); |
2bda0e17 KB |
4100 | } |
4101 | ||
1e6feb95 | 4102 | bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam) |
2bda0e17 | 4103 | { |
7f0586ef | 4104 | #if defined (__WXMICROWIN__) || defined(__WXWINCE__) |
35bbb0c6 | 4105 | wxUnusedVar(wParam); |
08158721 | 4106 | return false; |
4ce1efe1 | 4107 | #else // __WXMICROWIN__ |
42e69d6b | 4108 | HDROP hFilesInfo = (HDROP) wParam; |
42e69d6b VZ |
4109 | |
4110 | // Get the total number of files dropped | |
c3c39620 | 4111 | UINT gwFilesDropped = ::DragQueryFile |
f6bcfd97 BP |
4112 | ( |
4113 | (HDROP)hFilesInfo, | |
4114 | (UINT)-1, | |
4115 | (LPTSTR)0, | |
4116 | (UINT)0 | |
4117 | ); | |
42e69d6b VZ |
4118 | |
4119 | wxString *files = new wxString[gwFilesDropped]; | |
c3c39620 | 4120 | for ( UINT wIndex = 0; wIndex < gwFilesDropped; wIndex++ ) |
2d0a075d | 4121 | { |
c3c39620 VZ |
4122 | // first get the needed buffer length (+1 for terminating NUL) |
4123 | size_t len = ::DragQueryFile(hFilesInfo, wIndex, NULL, 0) + 1; | |
4124 | ||
4125 | // and now get the file name | |
4126 | ::DragQueryFile(hFilesInfo, wIndex, | |
de564874 | 4127 | wxStringBuffer(files[wIndex], len), len); |
2d0a075d | 4128 | } |
2bda0e17 | 4129 | |
42e69d6b | 4130 | wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files); |
687706f5 | 4131 | event.SetEventObject(this); |
c3c39620 VZ |
4132 | |
4133 | POINT dropPoint; | |
4134 | DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint); | |
b3dc8a3e VZ |
4135 | event.m_pos.x = dropPoint.x; |
4136 | event.m_pos.y = dropPoint.y; | |
42e69d6b | 4137 | |
fe8f9ad7 VZ |
4138 | DragFinish(hFilesInfo); |
4139 | ||
937013e0 | 4140 | return HandleWindowEvent(event); |
04ef50df | 4141 | #endif |
2bda0e17 KB |
4142 | } |
4143 | ||
cc972ac6 | 4144 | |
1e6feb95 VZ |
4145 | bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd), |
4146 | short nHitTest, | |
4147 | int WXUNUSED(mouseMsg)) | |
2bda0e17 | 4148 | { |
04ef50df | 4149 | #ifndef __WXMICROWIN__ |
bfbd6dc1 | 4150 | // the logic is as follows: |
46753a7c VZ |
4151 | // 0. if we're busy, set the busy cursor (even for non client elements) |
4152 | // 1. don't set custom cursor for non client area of enabled windows | |
4153 | // 2. ask user EVT_SET_CURSOR handler for the cursor | |
4154 | // 3. if still no cursor but we're in a TLW, set the global cursor | |
42e69d6b | 4155 | |
46753a7c VZ |
4156 | HCURSOR hcursor = 0; |
4157 | if ( wxIsBusy() ) | |
43b5058d | 4158 | { |
46753a7c | 4159 | hcursor = wxGetCurrentBusyCursor(); |
43b5058d | 4160 | } |
46753a7c VZ |
4161 | else // not busy |
4162 | { | |
4163 | if ( nHitTest != HTCLIENT ) | |
4164 | return false; | |
43b5058d | 4165 | |
46753a7c VZ |
4166 | // first ask the user code - it may wish to set the cursor in some very |
4167 | // specific way (for example, depending on the current position) | |
4168 | POINT pt; | |
f2325516 | 4169 | #ifdef __WXWINCE__ |
46753a7c | 4170 | if ( !::GetCursorPosWinCE(&pt)) |
f2325516 | 4171 | #else |
46753a7c | 4172 | if ( !::GetCursorPos(&pt) ) |
3fca879c | 4173 | #endif |
46753a7c VZ |
4174 | { |
4175 | wxLogLastError(wxT("GetCursorPos")); | |
4176 | } | |
43b5058d | 4177 | |
46753a7c VZ |
4178 | int x = pt.x, |
4179 | y = pt.y; | |
4180 | ScreenToClient(&x, &y); | |
4181 | wxSetCursorEvent event(x, y); | |
564af280 RD |
4182 | event.SetId(GetId()); |
4183 | event.SetEventObject(this); | |
42e69d6b | 4184 | |
937013e0 | 4185 | bool processedEvtSetCursor = HandleWindowEvent(event); |
46753a7c | 4186 | if ( processedEvtSetCursor && event.HasCursor() ) |
bfbd6dc1 | 4187 | { |
46753a7c | 4188 | hcursor = GetHcursorOf(event.GetCursor()); |
bfbd6dc1 | 4189 | } |
43b5058d | 4190 | |
46753a7c | 4191 | if ( !hcursor ) |
bfbd6dc1 | 4192 | { |
46753a7c VZ |
4193 | // the test for processedEvtSetCursor is here to prevent using |
4194 | // m_cursor if the user code caught EVT_SET_CURSOR() and returned | |
4195 | // nothing from it - this is a way to say that our cursor shouldn't | |
4196 | // be used for this point | |
4197 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
42e69d6b | 4198 | { |
46753a7c | 4199 | hcursor = GetHcursorOf(m_cursor); |
43b5058d | 4200 | } |
46753a7c VZ |
4201 | |
4202 | if ( !hcursor && !GetParent() ) | |
43b5058d VZ |
4203 | { |
4204 | const wxCursor *cursor = wxGetGlobalCursor(); | |
4205 | if ( cursor && cursor->Ok() ) | |
4206 | { | |
4207 | hcursor = GetHcursorOf(*cursor); | |
4208 | } | |
42e69d6b VZ |
4209 | } |
4210 | } | |
4211 | } | |
4212 | ||
46753a7c | 4213 | |
bfbd6dc1 VZ |
4214 | if ( hcursor ) |
4215 | { | |
4216 | ::SetCursor(hcursor); | |
4217 | ||
4218 | // cursor set, stop here | |
08158721 | 4219 | return true; |
bfbd6dc1 | 4220 | } |
cd4453e5 VZ |
4221 | #endif // __WXMICROWIN__ |
4222 | ||
3ca6a5f0 | 4223 | // pass up the window chain |
08158721 | 4224 | return false; |
2bda0e17 KB |
4225 | } |
4226 | ||
dbc74bcc | 4227 | bool wxWindowMSW::HandlePower(WXWPARAM WXUNUSED_IN_WINCE(wParam), |
355debca | 4228 | WXLPARAM WXUNUSED(lParam), |
dbc74bcc | 4229 | bool *WXUNUSED_IN_WINCE(vetoed)) |
355debca | 4230 | { |
dbc74bcc WS |
4231 | #ifdef __WXWINCE__ |
4232 | // FIXME | |
4233 | return false; | |
4234 | #else | |
355debca VZ |
4235 | wxEventType evtType; |
4236 | switch ( wParam ) | |
4237 | { | |
4238 | case PBT_APMQUERYSUSPEND: | |
4239 | evtType = wxEVT_POWER_SUSPENDING; | |
4240 | break; | |
4241 | ||
4242 | case PBT_APMQUERYSUSPENDFAILED: | |
4243 | evtType = wxEVT_POWER_SUSPEND_CANCEL; | |
4244 | break; | |
4245 | ||
4246 | case PBT_APMSUSPEND: | |
4247 | evtType = wxEVT_POWER_SUSPENDED; | |
4248 | break; | |
4249 | ||
4250 | case PBT_APMRESUMESUSPEND: | |
4251 | evtType = wxEVT_POWER_RESUME; | |
4252 | break; | |
4253 | ||
4254 | default: | |
9a83f860 | 4255 | wxLogDebug(wxT("Unknown WM_POWERBROADCAST(%d) event"), wParam); |
355debca VZ |
4256 | // fall through |
4257 | ||
4258 | // these messages are currently not mapped to wx events | |
4259 | case PBT_APMQUERYSTANDBY: | |
4260 | case PBT_APMQUERYSTANDBYFAILED: | |
4261 | case PBT_APMSTANDBY: | |
4262 | case PBT_APMRESUMESTANDBY: | |
4263 | case PBT_APMBATTERYLOW: | |
4264 | case PBT_APMPOWERSTATUSCHANGE: | |
4265 | case PBT_APMOEMEVENT: | |
355debca | 4266 | case PBT_APMRESUMECRITICAL: |
55cd5d10 VZ |
4267 | #ifdef PBT_APMRESUMEAUTOMATIC |
4268 | case PBT_APMRESUMEAUTOMATIC: | |
4269 | #endif | |
355debca VZ |
4270 | evtType = wxEVT_NULL; |
4271 | break; | |
4272 | } | |
4273 | ||
4274 | // don't handle unknown messages | |
4275 | if ( evtType == wxEVT_NULL ) | |
4276 | return false; | |
4277 | ||
4278 | // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events? | |
4279 | ||
4280 | wxPowerEvent event(evtType); | |
937013e0 | 4281 | if ( !HandleWindowEvent(event) ) |
355debca VZ |
4282 | return false; |
4283 | ||
4284 | *vetoed = event.IsVetoed(); | |
4285 | ||
4286 | return true; | |
dbc74bcc | 4287 | #endif |
355debca VZ |
4288 | } |
4289 | ||
2e992e06 VZ |
4290 | bool wxWindowMSW::IsDoubleBuffered() const |
4291 | { | |
75e8e6dc | 4292 | for ( const wxWindowMSW *win = this; win; win = win->GetParent() ) |
d66d0500 | 4293 | { |
75e8e6dc | 4294 | if ( wxHasWindowExStyle(win, WS_EX_COMPOSITED) ) |
2e992e06 | 4295 | return true; |
75e8e6dc VZ |
4296 | |
4297 | if ( win->IsTopLevel() ) | |
4298 | break; | |
4299 | } | |
d66d0500 | 4300 | |
2e992e06 VZ |
4301 | return false; |
4302 | } | |
4303 | ||
f60ca3e2 RD |
4304 | void wxWindowMSW::SetDoubleBuffered(bool on) |
4305 | { | |
4306 | // Get the current extended style bits | |
d66d0500 | 4307 | long exstyle = wxGetWindowExStyle(this); |
f60ca3e2 RD |
4308 | |
4309 | // Twiddle the bit as needed | |
4310 | if ( on ) | |
4311 | exstyle |= WS_EX_COMPOSITED; | |
4312 | else | |
4313 | exstyle &= ~WS_EX_COMPOSITED; | |
4314 | ||
4315 | // put it back | |
d66d0500 | 4316 | wxSetWindowExStyle(this, exstyle); |
f60ca3e2 RD |
4317 | } |
4318 | ||
42e69d6b VZ |
4319 | // --------------------------------------------------------------------------- |
4320 | // owner drawn stuff | |
4321 | // --------------------------------------------------------------------------- | |
4322 | ||
61fef19b VZ |
4323 | #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \ |
4324 | (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)) | |
4325 | #define WXUNUSED_UNLESS_ODRAWN(param) param | |
4326 | #else | |
4327 | #define WXUNUSED_UNLESS_ODRAWN(param) | |
4328 | #endif | |
4329 | ||
4330 | bool | |
4331 | wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id), | |
4332 | WXDRAWITEMSTRUCT * WXUNUSED_UNLESS_ODRAWN(itemStruct)) | |
2bda0e17 | 4333 | { |
4286a5b5 | 4334 | #if wxUSE_OWNER_DRAWN |
1e6feb95 VZ |
4335 | |
4336 | #if wxUSE_MENUS_NATIVE | |
42e69d6b | 4337 | // is it a menu item? |
6f806543 VZ |
4338 | DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct; |
4339 | if ( id == 0 && pDrawStruct->CtlType == ODT_MENU ) | |
42e69d6b | 4340 | { |
42e69d6b | 4341 | wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData); |
03cef643 | 4342 | |
2d29bf54 JS |
4343 | // see comment before the same test in MSWOnMeasureItem() below |
4344 | if ( !pMenuItem ) | |
4345 | return false; | |
4346 | ||
4347 | wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem), | |
9a83f860 | 4348 | false, wxT("MSWOnDrawItem: bad wxMenuItem pointer") ); |
42e69d6b | 4349 | |
7561aacd VZ |
4350 | // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent |
4351 | // the DC from being released | |
4352 | wxDCTemp dc((WXHDC)pDrawStruct->hDC); | |
42e69d6b VZ |
4353 | wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top, |
4354 | pDrawStruct->rcItem.right - pDrawStruct->rcItem.left, | |
4355 | pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top); | |
4356 | ||
4357 | return pMenuItem->OnDrawItem | |
7561aacd VZ |
4358 | ( |
4359 | dc, | |
4360 | rect, | |
4361 | (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction, | |
4362 | (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState | |
4363 | ); | |
42e69d6b | 4364 | } |
1e6feb95 | 4365 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b | 4366 | |
c8e4fa8b JS |
4367 | #endif // USE_OWNER_DRAWN |
4368 | ||
6a89f9ee | 4369 | #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__) |
c8e4fa8b | 4370 | |
c8e4fa8b | 4371 | #if wxUSE_OWNER_DRAWN |
1384636d | 4372 | wxControl *item = wxDynamicCast(FindItem(id), wxControl); |
567be187 | 4373 | #else // !wxUSE_OWNER_DRAWN |
1384636d VS |
4374 | // we may still have owner-drawn buttons internally because we have to make |
4375 | // them owner-drawn to support colour change | |
35bbb0c6 | 4376 | wxControl *item = |
095b80e2 WS |
4377 | # if wxUSE_BUTTON |
4378 | wxDynamicCast(FindItem(id), wxButton) | |
4379 | # else | |
4380 | NULL | |
4381 | # endif | |
4382 | ; | |
cd0b1709 | 4383 | #endif // USE_OWNER_DRAWN |
567be187 VZ |
4384 | |
4385 | if ( item ) | |
4386 | { | |
4387 | return item->MSWOnDraw(itemStruct); | |
4388 | } | |
4286a5b5 | 4389 | |
c8e4fa8b JS |
4390 | #endif // wxUSE_CONTROLS |
4391 | ||
08158721 | 4392 | return false; |
2bda0e17 KB |
4393 | } |
4394 | ||
61fef19b | 4395 | bool |
d1d276f2 | 4396 | wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct) |
2bda0e17 | 4397 | { |
61fef19b | 4398 | #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE |
42e69d6b | 4399 | // is it a menu item? |
6f806543 VZ |
4400 | MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct; |
4401 | if ( id == 0 && pMeasureStruct->CtlType == ODT_MENU ) | |
2d0a075d | 4402 | { |
42e69d6b VZ |
4403 | wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData); |
4404 | ||
b6afa1a3 VZ |
4405 | // according to Carsten Fuchs the pointer may be NULL under XP if an |
4406 | // MDI child frame is initially maximized, see this for more info: | |
4407 | // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745 | |
4408 | // | |
4409 | // so silently ignore it instead of asserting | |
4410 | if ( !pMenuItem ) | |
4411 | return false; | |
4412 | ||
4413 | wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem), | |
9a83f860 | 4414 | false, wxT("MSWOnMeasureItem: bad wxMenuItem pointer") ); |
42e69d6b | 4415 | |
975b6bcf VZ |
4416 | size_t w, h; |
4417 | bool rc = pMenuItem->OnMeasureItem(&w, &h); | |
4418 | ||
4419 | pMeasureStruct->itemWidth = w; | |
4420 | pMeasureStruct->itemHeight = h; | |
4421 | ||
4422 | return rc; | |
2d0a075d | 4423 | } |
42e69d6b | 4424 | |
567be187 VZ |
4425 | wxControl *item = wxDynamicCast(FindItem(id), wxControl); |
4426 | if ( item ) | |
42e69d6b | 4427 | { |
567be187 | 4428 | return item->MSWOnMeasure(itemStruct); |
42e69d6b | 4429 | } |
d1d276f2 WS |
4430 | #else |
4431 | wxUnusedVar(id); | |
4432 | wxUnusedVar(itemStruct); | |
4433 | #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE | |
567be187 | 4434 | |
08158721 | 4435 | return false; |
2bda0e17 KB |
4436 | } |
4437 | ||
42e69d6b VZ |
4438 | // --------------------------------------------------------------------------- |
4439 | // colours and palettes | |
4440 | // --------------------------------------------------------------------------- | |
2bda0e17 | 4441 | |
1e6feb95 | 4442 | bool wxWindowMSW::HandleSysColorChange() |
2bda0e17 | 4443 | { |
42e69d6b VZ |
4444 | wxSysColourChangedEvent event; |
4445 | event.SetEventObject(this); | |
4446 | ||
937013e0 | 4447 | (void)HandleWindowEvent(event); |
23895080 VZ |
4448 | |
4449 | // always let the system carry on the default processing to allow the | |
4450 | // native controls to react to the colours update | |
08158721 | 4451 | return false; |
42e69d6b VZ |
4452 | } |
4453 | ||
574c939e KB |
4454 | bool wxWindowMSW::HandleDisplayChange() |
4455 | { | |
4456 | wxDisplayChangedEvent event; | |
4457 | event.SetEventObject(this); | |
4458 | ||
937013e0 | 4459 | return HandleWindowEvent(event); |
574c939e KB |
4460 | } |
4461 | ||
04ef50df | 4462 | #ifndef __WXMICROWIN__ |
42e69d6b | 4463 | |
1a784dfc | 4464 | bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush, WXHDC hDC, WXHWND hWnd) |
01c500af | 4465 | { |
3d74a760 | 4466 | #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__) |
43bfb798 | 4467 | wxUnusedVar(hDC); |
3d74a760 WS |
4468 | wxUnusedVar(hWnd); |
4469 | #else | |
2bae4332 | 4470 | wxControl *item = wxDynamicCast(FindItemByHWND(hWnd, true), wxControl); |
c3732409 | 4471 | |
01c500af | 4472 | if ( item ) |
1a784dfc | 4473 | *brush = item->MSWControlColor(hDC, hWnd); |
2d0a075d | 4474 | else |
1e6feb95 | 4475 | #endif // wxUSE_CONTROLS |
01c500af | 4476 | *brush = NULL; |
42e69d6b | 4477 | |
01c500af | 4478 | return *brush != NULL; |
2bda0e17 KB |
4479 | } |
4480 | ||
01c500af VZ |
4481 | #endif // __WXMICROWIN__ |
4482 | ||
1e6feb95 | 4483 | bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange) |
42e69d6b | 4484 | { |
574c939e | 4485 | #if wxUSE_PALETTE |
b95edd47 VZ |
4486 | // same as below except we don't respond to our own messages |
4487 | if ( hWndPalChange != GetHWND() ) | |
4488 | { | |
574c939e | 4489 | // check to see if we our our parents have a custom palette |
fa21d338 | 4490 | wxWindowMSW *win = this; |
b95edd47 VZ |
4491 | while ( win && !win->HasCustomPalette() ) |
4492 | { | |
4493 | win = win->GetParent(); | |
4494 | } | |
4495 | ||
4496 | if ( win && win->HasCustomPalette() ) | |
4497 | { | |
4498 | // realize the palette to see whether redrawing is needed | |
4499 | HDC hdc = ::GetDC((HWND) hWndPalChange); | |
4500 | win->m_palette.SetHPALETTE((WXHPALETTE) | |
4501 | ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE)); | |
574c939e KB |
4502 | |
4503 | int result = ::RealizePalette(hdc); | |
b95edd47 VZ |
4504 | |
4505 | // restore the palette (before releasing the DC) | |
4506 | win->m_palette.SetHPALETTE((WXHPALETTE) | |
4507 | ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE)); | |
4508 | ::RealizePalette(hdc); | |
4509 | ::ReleaseDC((HWND) hWndPalChange, hdc); | |
4510 | ||
4511 | // now check for the need to redraw | |
574c939e | 4512 | if (result > 0) |
08158721 | 4513 | ::InvalidateRect((HWND) hWndPalChange, NULL, TRUE); |
574c939e | 4514 | } |
b95edd47 VZ |
4515 | |
4516 | } | |
4517 | #endif // wxUSE_PALETTE | |
574c939e | 4518 | |
42e69d6b VZ |
4519 | wxPaletteChangedEvent event(GetId()); |
4520 | event.SetEventObject(this); | |
4521 | event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange)); | |
2d0a075d | 4522 | |
937013e0 | 4523 | return HandleWindowEvent(event); |
42e69d6b VZ |
4524 | } |
4525 | ||
a5e84126 JS |
4526 | bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture) |
4527 | { | |
63e819f2 VS |
4528 | // notify windows on the capture stack about lost capture |
4529 | // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863): | |
72f8c792 | 4530 | wxWindowBase::NotifyCaptureLost(); |
a5e84126 | 4531 | |
72f8c792 | 4532 | wxWindow *win = wxFindWinFromHandle(hWndGainedCapture); |
63e819f2 VS |
4533 | wxMouseCaptureChangedEvent event(GetId(), win); |
4534 | event.SetEventObject(this); | |
937013e0 | 4535 | return HandleWindowEvent(event); |
a5e84126 JS |
4536 | } |
4537 | ||
3c96418b JG |
4538 | bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam) |
4539 | { | |
4540 | // despite MSDN saying "(This message cannot be sent directly to a window.)" | |
4541 | // we need to send this to child windows (it is only sent to top-level | |
4542 | // windows) so {list,tree}ctrls can adjust their font size if necessary | |
4543 | // this is exactly how explorer does it to enable the font size changes | |
4544 | ||
4545 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
4546 | while ( node ) | |
4547 | { | |
4548 | // top-level windows already get this message from the system | |
4549 | wxWindow *win = node->GetData(); | |
4550 | if ( !win->IsTopLevel() ) | |
4551 | { | |
4552 | ::SendMessage(GetHwndOf(win), WM_SETTINGCHANGE, wParam, lParam); | |
4553 | } | |
4554 | ||
4555 | node = node->GetNext(); | |
4556 | } | |
4557 | ||
3c96418b JG |
4558 | // let the system handle it |
4559 | return false; | |
4560 | } | |
4561 | ||
1e6feb95 | 4562 | bool wxWindowMSW::HandleQueryNewPalette() |
42e69d6b | 4563 | { |
574c939e KB |
4564 | |
4565 | #if wxUSE_PALETTE | |
4566 | // check to see if we our our parents have a custom palette | |
fa21d338 | 4567 | wxWindowMSW *win = this; |
574c939e KB |
4568 | while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent(); |
4569 | if (win->HasCustomPalette()) { | |
4570 | /* realize the palette to see whether redrawing is needed */ | |
3a3c8603 | 4571 | HDC hdc = ::GetDC((HWND) GetHWND()); |
574c939e | 4572 | win->m_palette.SetHPALETTE( (WXHPALETTE) |
b95edd47 | 4573 | ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), FALSE) ); |
574c939e KB |
4574 | |
4575 | int result = ::RealizePalette(hdc); | |
4576 | /* restore the palette (before releasing the DC) */ | |
4577 | win->m_palette.SetHPALETTE( (WXHPALETTE) | |
b95edd47 | 4578 | ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), TRUE) ); |
574c939e KB |
4579 | ::RealizePalette(hdc); |
4580 | ::ReleaseDC((HWND) GetHWND(), hdc); | |
4581 | /* now check for the need to redraw */ | |
4582 | if (result > 0) | |
4583 | ::InvalidateRect((HWND) GetHWND(), NULL, TRUE); | |
4584 | } | |
b95edd47 | 4585 | #endif // wxUSE_PALETTE |
574c939e | 4586 | |
42e69d6b VZ |
4587 | wxQueryNewPaletteEvent event(GetId()); |
4588 | event.SetEventObject(this); | |
4589 | ||
937013e0 | 4590 | return HandleWindowEvent(event) && event.GetPaletteRealized(); |
42e69d6b VZ |
4591 | } |
4592 | ||
4593 | // Responds to colour changes: passes event on to children. | |
574c939e | 4594 | void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) |
42e69d6b | 4595 | { |
90c1530a VZ |
4596 | // the top level window also reset the standard colour map as it might have |
4597 | // changed (there is no need to do it for the non top level windows as we | |
4598 | // only have to do it once) | |
4599 | if ( IsTopLevel() ) | |
4600 | { | |
4601 | // FIXME-MT | |
08158721 | 4602 | gs_hasStdCmap = false; |
90c1530a | 4603 | } |
222ed1d6 | 4604 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
42e69d6b VZ |
4605 | while ( node ) |
4606 | { | |
23895080 VZ |
4607 | // Only propagate to non-top-level windows because Windows already |
4608 | // sends this event to all top-level ones | |
4609 | wxWindow *win = node->GetData(); | |
4610 | if ( !win->IsTopLevel() ) | |
42e69d6b | 4611 | { |
23895080 VZ |
4612 | // we need to send the real WM_SYSCOLORCHANGE and not just trigger |
4613 | // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for | |
4614 | // the standard controls | |
4615 | ::SendMessage(GetHwndOf(win), WM_SYSCOLORCHANGE, 0, 0); | |
564b2609 | 4616 | } |
42e69d6b | 4617 | |
23895080 VZ |
4618 | node = node->GetNext(); |
4619 | } | |
2bda0e17 KB |
4620 | } |
4621 | ||
90c1530a VZ |
4622 | extern wxCOLORMAP *wxGetStdColourMap() |
4623 | { | |
4624 | static COLORREF s_stdColours[wxSTD_COL_MAX]; | |
4625 | static wxCOLORMAP s_cmap[wxSTD_COL_MAX]; | |
4626 | ||
4627 | if ( !gs_hasStdCmap ) | |
4628 | { | |
08158721 | 4629 | static bool s_coloursInit = false; |
90c1530a VZ |
4630 | |
4631 | if ( !s_coloursInit ) | |
4632 | { | |
4633 | // When a bitmap is loaded, the RGB values can change (apparently | |
4634 | // because Windows adjusts them to care for the old programs always | |
4635 | // using 0xc0c0c0 while the transparent colour for the new Windows | |
4636 | // versions is different). But we do this adjustment ourselves so | |
4637 | // we want to avoid Windows' "help" and for this we need to have a | |
4638 | // reference bitmap which can tell us what the RGB values change | |
4639 | // to. | |
e5dbcb50 | 4640 | wxLogNull logNo; // suppress error if we couldn't load the bitmap |
9a83f860 | 4641 | wxBitmap stdColourBitmap(wxT("wxBITMAP_STD_COLOURS")); |
90c1530a VZ |
4642 | if ( stdColourBitmap.Ok() ) |
4643 | { | |
4644 | // the pixels in the bitmap must correspond to wxSTD_COL_XXX! | |
4645 | wxASSERT_MSG( stdColourBitmap.GetWidth() == wxSTD_COL_MAX, | |
9a83f860 | 4646 | wxT("forgot to update wxBITMAP_STD_COLOURS!") ); |
90c1530a VZ |
4647 | |
4648 | wxMemoryDC memDC; | |
4649 | memDC.SelectObject(stdColourBitmap); | |
4650 | ||
4651 | wxColour colour; | |
4652 | for ( size_t i = 0; i < WXSIZEOF(s_stdColours); i++ ) | |
4653 | { | |
4654 | memDC.GetPixel(i, 0, &colour); | |
4655 | s_stdColours[i] = wxColourToRGB(colour); | |
4656 | } | |
4657 | } | |
4658 | else // wxBITMAP_STD_COLOURS couldn't be loaded | |
4659 | { | |
4660 | s_stdColours[0] = RGB(000,000,000); // black | |
4661 | s_stdColours[1] = RGB(128,128,128); // dark grey | |
4662 | s_stdColours[2] = RGB(192,192,192); // light grey | |
4663 | s_stdColours[3] = RGB(255,255,255); // white | |
4664 | //s_stdColours[4] = RGB(000,000,255); // blue | |
4665 | //s_stdColours[5] = RGB(255,000,255); // magenta | |
4666 | } | |
4667 | ||
08158721 | 4668 | s_coloursInit = true; |
90c1530a VZ |
4669 | } |
4670 | ||
08158721 | 4671 | gs_hasStdCmap = true; |
90c1530a VZ |
4672 | |
4673 | // create the colour map | |
4674 | #define INIT_CMAP_ENTRY(col) \ | |
4675 | s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \ | |
4676 | s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col) | |
4677 | ||
4678 | INIT_CMAP_ENTRY(BTNTEXT); | |
4679 | INIT_CMAP_ENTRY(BTNSHADOW); | |
4680 | INIT_CMAP_ENTRY(BTNFACE); | |
4681 | INIT_CMAP_ENTRY(BTNHIGHLIGHT); | |
4682 | ||
4683 | #undef INIT_CMAP_ENTRY | |
4684 | } | |
4685 | ||
4686 | return s_cmap; | |
4687 | } | |
4688 | ||
a5b1be33 JS |
4689 | #if wxUSE_UXTHEME && !defined(TMT_FILLCOLOR) |
4690 | #define TMT_FILLCOLOR 3802 | |
4691 | #define TMT_TEXTCOLOR 3803 | |
4692 | #define TMT_BORDERCOLOR 3801 | |
4693 | #endif | |
4694 | ||
4695 | wxColour wxWindowMSW::MSWGetThemeColour(const wchar_t *themeName, | |
4696 | int themePart, | |
4697 | int themeState, | |
4698 | MSWThemeColour themeColour, | |
108694fe | 4699 | wxSystemColour fallback) const |
a5b1be33 JS |
4700 | { |
4701 | #if wxUSE_UXTHEME | |
4702 | const wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); | |
4703 | if ( theme ) | |
4704 | { | |
4705 | int themeProperty = 0; | |
4706 | ||
4707 | // TODO: Convert this into a table? Sure would be faster. | |
4708 | switch ( themeColour ) | |
4709 | { | |
4710 | case ThemeColourBackground: | |
4711 | themeProperty = TMT_FILLCOLOR; | |
4712 | break; | |
4713 | case ThemeColourText: | |
4714 | themeProperty = TMT_TEXTCOLOR; | |
4715 | break; | |
4716 | case ThemeColourBorder: | |
4717 | themeProperty = TMT_BORDERCOLOR; | |
4718 | break; | |
4719 | default: | |
4720 | wxFAIL_MSG(wxT("unsupported theme colour")); | |
4721 | }; | |
4722 | ||
108694fe | 4723 | wxUxThemeHandle hTheme((const wxWindow *)this, themeName); |
a5b1be33 JS |
4724 | COLORREF col; |
4725 | HRESULT hr = theme->GetThemeColor | |
4726 | ( | |
4727 | hTheme, | |
4728 | themePart, | |
4729 | themeState, | |
4730 | themeProperty, | |
4731 | &col | |
4732 | ); | |
4733 | ||
4734 | if ( SUCCEEDED(hr) ) | |
4735 | return wxRGBToColour(col); | |
4736 | ||
4737 | wxLogApiError( | |
4738 | wxString::Format( | |
4739 | "GetThemeColor(%s, %i, %i, %i)", | |
4740 | themeName, themePart, themeState, themeProperty), | |
4741 | hr); | |
4742 | } | |
b9de6a21 JS |
4743 | #else |
4744 | wxUnusedVar(themeName); | |
4745 | wxUnusedVar(themePart); | |
4746 | wxUnusedVar(themeState); | |
4747 | wxUnusedVar(themeColour); | |
a5b1be33 JS |
4748 | #endif |
4749 | return wxSystemSettings::GetColour(fallback); | |
4750 | } | |
4751 | ||
42e69d6b VZ |
4752 | // --------------------------------------------------------------------------- |
4753 | // painting | |
4754 | // --------------------------------------------------------------------------- | |
4755 | ||
7ca106e8 VZ |
4756 | // this variable is used to check that a paint event handler which processed |
4757 | // the event did create a wxPaintDC inside its code and called BeginPaint() to | |
4758 | // validate the invalidated window area as otherwise we'd keep getting an | |
4759 | // endless stream of WM_PAINT messages for this window resulting in a lot of | |
4760 | // difficult to debug problems (e.g. impossibility to repaint other windows, | |
4761 | // lack of timer and idle events and so on) | |
0369a9fe VZ |
4762 | extern bool wxDidCreatePaintDC; |
4763 | bool wxDidCreatePaintDC = false; | |
7ca106e8 | 4764 | |
1e6feb95 | 4765 | bool wxWindowMSW::HandlePaint() |
2bda0e17 | 4766 | { |
42e69d6b VZ |
4767 | HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle |
4768 | if ( !hRegion ) | |
43b2d5e7 | 4769 | { |
f6bcfd97 | 4770 | wxLogLastError(wxT("CreateRectRgn")); |
43b2d5e7 | 4771 | } |
42e69d6b | 4772 | if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR ) |
43b2d5e7 | 4773 | { |
f6bcfd97 | 4774 | wxLogLastError(wxT("GetUpdateRgn")); |
43b2d5e7 | 4775 | } |
c085e333 | 4776 | |
42e69d6b | 4777 | m_updateRegion = wxRegion((WXHRGN) hRegion); |
c085e333 | 4778 | |
7ca106e8 VZ |
4779 | wxDidCreatePaintDC = false; |
4780 | ||
42e69d6b VZ |
4781 | wxPaintEvent event(m_windowId); |
4782 | event.SetEventObject(this); | |
2bda0e17 | 4783 | |
937013e0 | 4784 | bool processed = HandleWindowEvent(event); |
1e6feb95 | 4785 | |
7ca106e8 VZ |
4786 | if ( processed && !wxDidCreatePaintDC ) |
4787 | { | |
4788 | // do call MSWDefWindowProc() to validate the update region to avoid | |
4789 | // the problems mentioned above | |
4790 | processed = false; | |
4791 | } | |
4792 | ||
1e6feb95 VZ |
4793 | // note that we must generate NC event after the normal one as otherwise |
4794 | // BeginPaint() will happily overwrite our decorations with the background | |
4795 | // colour | |
4796 | wxNcPaintEvent eventNc(m_windowId); | |
4797 | eventNc.SetEventObject(this); | |
937013e0 | 4798 | HandleWindowEvent(eventNc); |
1e6feb95 | 4799 | |
90df6033 VZ |
4800 | // don't keep an HRGN we don't need any longer (GetUpdateRegion() can only |
4801 | // be called from inside the event handlers called above) | |
4802 | m_updateRegion.Clear(); | |
4803 | ||
1e6feb95 | 4804 | return processed; |
2bda0e17 KB |
4805 | } |
4806 | ||
63da7df7 | 4807 | // Can be called from an application's OnPaint handler |
1e6feb95 | 4808 | void wxWindowMSW::OnPaint(wxPaintEvent& event) |
63da7df7 | 4809 | { |
1e6feb95 VZ |
4810 | #ifdef __WXUNIVERSAL__ |
4811 | event.Skip(); | |
4812 | #else | |
888dde65 | 4813 | HDC hDC = (HDC) wxPaintDCImpl::FindDCInCache((wxWindow*) event.GetEventObject()); |
63da7df7 JS |
4814 | if (hDC != 0) |
4815 | { | |
4816 | MSWDefWindowProc(WM_PAINT, (WPARAM) hDC, 0); | |
4817 | } | |
1e6feb95 | 4818 | #endif |
63da7df7 JS |
4819 | } |
4820 | ||
1e6feb95 | 4821 | bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc) |
8681b094 | 4822 | { |
c753eb92 | 4823 | switch ( GetBackgroundStyle() ) |
d57f1dd7 | 4824 | { |
c753eb92 | 4825 | case wxBG_STYLE_ERASE: |
b469c9d8 | 4826 | case wxBG_STYLE_COLOUR: |
c753eb92 VZ |
4827 | // we need to generate an erase background event |
4828 | { | |
4829 | wxDCTemp dc(hdc, GetClientSize()); | |
4830 | wxDCTempImpl *impl = (wxDCTempImpl*) dc.GetImpl(); | |
d57f1dd7 | 4831 | |
c753eb92 VZ |
4832 | impl->SetHDC(hdc); |
4833 | impl->SetWindow((wxWindow *)this); | |
90df6033 | 4834 | |
c753eb92 VZ |
4835 | wxEraseEvent event(m_windowId, &dc); |
4836 | event.SetEventObject(this); | |
4837 | bool rc = HandleWindowEvent(event); | |
4838 | ||
4839 | // must be called manually as ~wxDC doesn't do anything for | |
4840 | // wxDCTemp | |
4841 | impl->SelectOldObjects(hdc); | |
4842 | ||
4843 | if ( rc ) | |
4844 | { | |
06393630 | 4845 | // background erased by the user-defined handler |
c753eb92 VZ |
4846 | return true; |
4847 | } | |
4848 | } | |
4849 | // fall through | |
4850 | ||
4851 | case wxBG_STYLE_SYSTEM: | |
4852 | if ( !DoEraseBackground(hdc) ) | |
4853 | { | |
4854 | // let the default processing to take place if we didn't erase | |
4855 | // the background ourselves | |
4856 | return false; | |
4857 | } | |
4858 | break; | |
4859 | ||
4860 | case wxBG_STYLE_PAINT: | |
b469c9d8 | 4861 | case wxBG_STYLE_TRANSPARENT: |
c753eb92 VZ |
4862 | // no need to do anything here at all, background will be entirely |
4863 | // redrawn in WM_PAINT handler | |
4864 | break; | |
4865 | ||
4866 | default: | |
4867 | wxFAIL_MSG( "unknown background style" ); | |
c5bd3c62 | 4868 | } |
c753eb92 VZ |
4869 | |
4870 | return true; | |
c5bd3c62 VZ |
4871 | } |
4872 | ||
bec9bf3e VZ |
4873 | #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK |
4874 | ||
4875 | bool wxWindowMSW::MSWHasEraseBgHook() const | |
4876 | { | |
4877 | return gs_eraseBgHooks.find(this) != gs_eraseBgHooks.end(); | |
4878 | } | |
4879 | ||
4880 | void wxWindowMSW::MSWSetEraseBgHook(wxWindow *child) | |
4881 | { | |
4882 | if ( child ) | |
4883 | { | |
4884 | if ( !gs_eraseBgHooks.insert( | |
4885 | EraseBgHooks::value_type(this, child)).second ) | |
4886 | { | |
4887 | wxFAIL_MSG( wxT("Setting erase background hook twice?") ); | |
4888 | } | |
4889 | } | |
4890 | else // reset the hook | |
4891 | { | |
4892 | if ( gs_eraseBgHooks.erase(this) != 1 ) | |
4893 | { | |
4894 | wxFAIL_MSG( wxT("Resetting erase background which was not set?") ); | |
4895 | } | |
4896 | } | |
4897 | } | |
4898 | ||
4899 | #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK | |
4900 | ||
c3732409 | 4901 | bool wxWindowMSW::DoEraseBackground(WXHDC hDC) |
c581abbc | 4902 | { |
c3732409 VZ |
4903 | HBRUSH hbr = (HBRUSH)MSWGetBgBrush(hDC); |
4904 | if ( !hbr ) | |
c581abbc VZ |
4905 | return false; |
4906 | ||
bec9bf3e VZ |
4907 | // erase just the client area of the window, this is important for the |
4908 | // frames to avoid drawing over the toolbar part of the window (you might | |
4909 | // think using WS_CLIPCHILDREN would prevent this from happening, but it | |
4910 | // clearly doesn't) | |
4911 | RECT rc; | |
4912 | wxCopyRectToRECT(GetClientRect(), rc); | |
4913 | ::FillRect((HDC)hDC, &rc, hbr); | |
c581abbc VZ |
4914 | |
4915 | return true; | |
4916 | } | |
4917 | ||
c3732409 | 4918 | WXHBRUSH |
b8797d96 | 4919 | wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), wxWindowMSW *child) |
c5bd3c62 | 4920 | { |
accbb1e7 VZ |
4921 | if ( m_hasBgCol ) |
4922 | { | |
8d075f8d VZ |
4923 | // our background colour applies to: |
4924 | // 1. this window itself, always | |
4925 | // 2. all children unless the colour is "not inheritable" | |
c3732409 VZ |
4926 | // 3. even if it is not inheritable, our immediate transparent |
4927 | // children should still inherit it -- but not any transparent | |
4928 | // children because it would look wrong if a child of non | |
4929 | // transparent child would show our bg colour when the child itself | |
4930 | // does not | |
b8797d96 | 4931 | if ( child == this || |
c3732409 | 4932 | m_inheritBgCol || |
b8797d96 VZ |
4933 | (child->HasTransparentBackground() && |
4934 | child->GetParent() == this) ) | |
accbb1e7 | 4935 | { |
c3732409 VZ |
4936 | // draw children with the same colour as the parent |
4937 | wxBrush * | |
4938 | brush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour()); | |
4939 | ||
4940 | return (WXHBRUSH)GetHbrushOf(*brush); | |
accbb1e7 VZ |
4941 | } |
4942 | } | |
4943 | ||
c3732409 | 4944 | return 0; |
c5bd3c62 | 4945 | } |
8681b094 | 4946 | |
b8797d96 | 4947 | WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC, wxWindowMSW *child) |
bdd1a35d | 4948 | { |
c3732409 | 4949 | for ( wxWindowMSW *win = this; win; win = win->GetParent() ) |
c5bd3c62 | 4950 | { |
b8797d96 | 4951 | WXHBRUSH hBrush = win->MSWGetBgBrushForChild(hDC, child); |
c5bd3c62 VZ |
4952 | if ( hBrush ) |
4953 | return hBrush; | |
24cb4019 | 4954 | |
c3732409 VZ |
4955 | // background is not inherited beyond top level windows |
4956 | if ( win->IsTopLevel() ) | |
24cb4019 | 4957 | break; |
01c500af | 4958 | } |
c5bd3c62 VZ |
4959 | |
4960 | return 0; | |
8681b094 VZ |
4961 | } |
4962 | ||
b728a212 | 4963 | bool wxWindowMSW::HandlePrintClient(WXHDC hDC) |
1a784dfc | 4964 | { |
b728a212 JG |
4965 | // we receive this message when DrawThemeParentBackground() is |
4966 | // called from def window proc of several controls under XP and we | |
4967 | // must draw properly themed background here | |
4968 | // | |
4969 | // note that naively I'd expect filling the client rect with the | |
4970 | // brush returned by MSWGetBgBrush() work -- but for some reason it | |
4971 | // doesn't and we have to call parents MSWPrintChild() which is | |
4972 | // supposed to call DrawThemeBackground() with appropriate params | |
4973 | // | |
4974 | // also note that in this case lParam == PRF_CLIENT but we're | |
4975 | // clearly expected to paint the background and nothing else! | |
4976 | ||
4977 | if ( IsTopLevel() || InheritsBackgroundColour() ) | |
4978 | return false; | |
4979 | ||
4980 | // sometimes we don't want the parent to handle it at all, instead | |
4981 | // return whatever value this window wants | |
4982 | if ( !MSWShouldPropagatePrintChild() ) | |
4983 | return MSWPrintChild(hDC, (wxWindow *)this); | |
4984 | ||
4985 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
4986 | { | |
4987 | if ( win->MSWPrintChild(hDC, (wxWindow *)this) ) | |
4988 | return true; | |
4989 | ||
4990 | if ( win->IsTopLevel() || win->InheritsBackgroundColour() ) | |
4991 | break; | |
4992 | } | |
4993 | ||
1a784dfc VZ |
4994 | return false; |
4995 | } | |
4996 | ||
42e69d6b VZ |
4997 | // --------------------------------------------------------------------------- |
4998 | // moving and resizing | |
4999 | // --------------------------------------------------------------------------- | |
5000 | ||
1e6feb95 | 5001 | bool wxWindowMSW::HandleMinimize() |
42e69d6b VZ |
5002 | { |
5003 | wxIconizeEvent event(m_windowId); | |
5004 | event.SetEventObject(this); | |
2d0a075d | 5005 | |
937013e0 | 5006 | return HandleWindowEvent(event); |
2bda0e17 KB |
5007 | } |
5008 | ||
1e6feb95 | 5009 | bool wxWindowMSW::HandleMaximize() |
2bda0e17 | 5010 | { |
42e69d6b VZ |
5011 | wxMaximizeEvent event(m_windowId); |
5012 | event.SetEventObject(this); | |
c085e333 | 5013 | |
937013e0 | 5014 | return HandleWindowEvent(event); |
42e69d6b | 5015 | } |
2bda0e17 | 5016 | |
1e6feb95 | 5017 | bool wxWindowMSW::HandleMove(int x, int y) |
42e69d6b | 5018 | { |
907173e5 WS |
5019 | wxPoint point(x,y); |
5020 | wxMoveEvent event(point, m_windowId); | |
42e69d6b VZ |
5021 | event.SetEventObject(this); |
5022 | ||
937013e0 | 5023 | return HandleWindowEvent(event); |
42e69d6b VZ |
5024 | } |
5025 | ||
5706de1c JS |
5026 | bool wxWindowMSW::HandleMoving(wxRect& rect) |
5027 | { | |
5028 | wxMoveEvent event(rect, m_windowId); | |
5029 | event.SetEventObject(this); | |
577baeef | 5030 | |
937013e0 | 5031 | bool rc = HandleWindowEvent(event); |
5706de1c JS |
5032 | if (rc) |
5033 | rect = event.GetRect(); | |
5034 | return rc; | |
5035 | } | |
5036 | ||
aa767a45 JS |
5037 | bool wxWindowMSW::HandleEnterSizeMove() |
5038 | { | |
66e2ba91 | 5039 | wxMoveEvent event(wxPoint(0,0), m_windowId); |
aa767a45 JS |
5040 | event.SetEventType(wxEVT_MOVE_START); |
5041 | event.SetEventObject(this); | |
5042 | ||
937013e0 | 5043 | return HandleWindowEvent(event); |
aa767a45 JS |
5044 | } |
5045 | ||
5046 | bool wxWindowMSW::HandleExitSizeMove() | |
5047 | { | |
66e2ba91 | 5048 | wxMoveEvent event(wxPoint(0,0), m_windowId); |
aa767a45 JS |
5049 | event.SetEventType(wxEVT_MOVE_END); |
5050 | event.SetEventObject(this); | |
5051 | ||
937013e0 | 5052 | return HandleWindowEvent(event); |
aa767a45 JS |
5053 | } |
5054 | ||
4bc0f25e | 5055 | bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam) |
42e69d6b | 5056 | { |
6bd9b9f2 | 5057 | #if wxUSE_DEFERRED_SIZING |
c3723477 JS |
5058 | // when we resize this window, its children are probably going to be |
5059 | // repositioned as well, prepare to use DeferWindowPos() for them | |
5060 | int numChildren = 0; | |
5061 | for ( HWND child = ::GetWindow(GetHwndOf(this), GW_CHILD); | |
5062 | child; | |
5063 | child = ::GetWindow(child, GW_HWNDNEXT) ) | |
5064 | { | |
5065 | numChildren ++; | |
5066 | } | |
5067 | ||
3fca879c | 5068 | // Protect against valid m_hDWP being overwritten |
c3723477 JS |
5069 | bool useDefer = false; |
5070 | ||
3f48c8e2 VZ |
5071 | if ( numChildren > 1 ) |
5072 | { | |
c3723477 | 5073 | if (!m_hDWP) |
3fca879c | 5074 | { |
c3723477 JS |
5075 | m_hDWP = (WXHANDLE)::BeginDeferWindowPos(numChildren); |
5076 | if ( !m_hDWP ) | |
5077 | { | |
9a83f860 | 5078 | wxLogLastError(wxT("BeginDeferWindowPos")); |
c3723477 JS |
5079 | } |
5080 | if (m_hDWP) | |
5081 | useDefer = true; | |
3f48c8e2 VZ |
5082 | } |
5083 | } | |
6bd9b9f2 | 5084 | #endif // wxUSE_DEFERRED_SIZING |
42e69d6b | 5085 | |
3f48c8e2 VZ |
5086 | // update this window size |
5087 | bool processed = false; | |
4bc0f25e VZ |
5088 | switch ( wParam ) |
5089 | { | |
5090 | default: | |
9a83f860 | 5091 | wxFAIL_MSG( wxT("unexpected WM_SIZE parameter") ); |
4bc0f25e VZ |
5092 | // fall through nevertheless |
5093 | ||
5094 | case SIZE_MAXHIDE: | |
5095 | case SIZE_MAXSHOW: | |
5096 | // we're not interested in these messages at all | |
5097 | break; | |
5098 | ||
5099 | case SIZE_MINIMIZED: | |
5100 | processed = HandleMinimize(); | |
5101 | break; | |
5102 | ||
5103 | case SIZE_MAXIMIZED: | |
a4d1972d | 5104 | /* processed = */ HandleMaximize(); |
4bc0f25e VZ |
5105 | // fall through to send a normal size event as well |
5106 | ||
5107 | case SIZE_RESTORED: | |
5108 | // don't use w and h parameters as they specify the client size | |
5109 | // while according to the docs EVT_SIZE handler is supposed to | |
5110 | // receive the total size | |
5111 | wxSizeEvent event(GetSize(), m_windowId); | |
5112 | event.SetEventObject(this); | |
5113 | ||
937013e0 | 5114 | processed = HandleWindowEvent(event); |
4bc0f25e VZ |
5115 | } |
5116 | ||
6bd9b9f2 | 5117 | #if wxUSE_DEFERRED_SIZING |
3f48c8e2 | 5118 | // and finally change the positions of all child windows at once |
c3723477 | 5119 | if ( useDefer && m_hDWP ) |
3f48c8e2 VZ |
5120 | { |
5121 | // reset m_hDWP to NULL so that child windows don't try to use our | |
5122 | // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't | |
5123 | // happen anyhow normally but who knows what weird flow of control we | |
5124 | // may have depending on what the users EVT_SIZE handler does...) | |
5125 | HDWP hDWP = (HDWP)m_hDWP; | |
5126 | m_hDWP = NULL; | |
3fca879c | 5127 | |
3f48c8e2 VZ |
5128 | // do put all child controls in place at once |
5129 | if ( !::EndDeferWindowPos(hDWP) ) | |
5130 | { | |
9a83f860 | 5131 | wxLogLastError(wxT("EndDeferWindowPos")); |
3f48c8e2 | 5132 | } |
c3723477 | 5133 | |
da78f3b1 | 5134 | // Reset our children's pending pos/size values. |
c3723477 JS |
5135 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
5136 | node; | |
5137 | node = node->GetNext() ) | |
5138 | { | |
6bd9b9f2 VZ |
5139 | wxWindowMSW * const child = node->GetData(); |
5140 | child->MSWEndDeferWindowPos(); | |
c3723477 | 5141 | } |
3f48c8e2 | 5142 | } |
6bd9b9f2 | 5143 | #endif // wxUSE_DEFERRED_SIZING |
3f48c8e2 | 5144 | |
4bc0f25e | 5145 | return processed; |
42e69d6b VZ |
5146 | } |
5147 | ||
5706de1c JS |
5148 | bool wxWindowMSW::HandleSizing(wxRect& rect) |
5149 | { | |
5150 | wxSizeEvent event(rect, m_windowId); | |
5151 | event.SetEventObject(this); | |
577baeef | 5152 | |
937013e0 | 5153 | bool rc = HandleWindowEvent(event); |
5706de1c JS |
5154 | if (rc) |
5155 | rect = event.GetRect(); | |
5156 | return rc; | |
5157 | } | |
5158 | ||
0c0d1521 | 5159 | bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo)) |
42e69d6b | 5160 | { |
7f0586ef | 5161 | #ifdef __WXWINCE__ |
08158721 | 5162 | return false; |
7f0586ef | 5163 | #else |
42e69d6b VZ |
5164 | MINMAXINFO *info = (MINMAXINFO *)mmInfo; |
5165 | ||
08158721 | 5166 | bool rc = false; |
b2d5a7ee | 5167 | |
e7dda1ff VS |
5168 | int minWidth = GetMinWidth(), |
5169 | minHeight = GetMinHeight(), | |
5170 | maxWidth = GetMaxWidth(), | |
5171 | maxHeight = GetMaxHeight(); | |
42e69d6b | 5172 | |
422d0ff0 | 5173 | if ( minWidth != wxDefaultCoord ) |
2d0a075d | 5174 | { |
e7dda1ff | 5175 | info->ptMinTrackSize.x = minWidth; |
08158721 | 5176 | rc = true; |
2d0a075d | 5177 | } |
2bda0e17 | 5178 | |
422d0ff0 | 5179 | if ( minHeight != wxDefaultCoord ) |
42e69d6b | 5180 | { |
e7dda1ff | 5181 | info->ptMinTrackSize.y = minHeight; |
08158721 | 5182 | rc = true; |
42e69d6b | 5183 | } |
2bda0e17 | 5184 | |
422d0ff0 | 5185 | if ( maxWidth != wxDefaultCoord ) |
42e69d6b | 5186 | { |
e7dda1ff | 5187 | info->ptMaxTrackSize.x = maxWidth; |
08158721 | 5188 | rc = true; |
2d0a075d | 5189 | } |
2bda0e17 | 5190 | |
422d0ff0 | 5191 | if ( maxHeight != wxDefaultCoord ) |
42e69d6b | 5192 | { |
e7dda1ff | 5193 | info->ptMaxTrackSize.y = maxHeight; |
08158721 | 5194 | rc = true; |
42e69d6b | 5195 | } |
2bda0e17 | 5196 | |
42e69d6b | 5197 | return rc; |
7f0586ef | 5198 | #endif |
42e69d6b | 5199 | } |
2d0a075d | 5200 | |
42e69d6b VZ |
5201 | // --------------------------------------------------------------------------- |
5202 | // command messages | |
5203 | // --------------------------------------------------------------------------- | |
5204 | ||
0edeeb6d | 5205 | bool wxWindowMSW::HandleCommand(WXWORD id_, WXWORD cmd, WXHWND control) |
42e69d6b | 5206 | { |
0edeeb6d VZ |
5207 | // sign extend to int from short before comparing with the other int ids |
5208 | int id = (signed short)id_; | |
5209 | ||
1e6feb95 | 5210 | #if wxUSE_MENUS_NATIVE |
8c290175 | 5211 | if ( !cmd && wxCurrentPopupMenu ) |
42e69d6b VZ |
5212 | { |
5213 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
5214 | wxCurrentPopupMenu = NULL; | |
5215 | ||
5216 | return popupMenu->MSWCommand(cmd, id); | |
5217 | } | |
1e6feb95 | 5218 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b | 5219 | |
8c290175 | 5220 | wxWindow *win = NULL; |
71292fab VZ |
5221 | |
5222 | // first try to find it from HWND - this works even with the broken | |
5223 | // programs using the same ids for different controls | |
5224 | if ( control ) | |
42e69d6b | 5225 | { |
71292fab | 5226 | win = wxFindWinFromHandle(control); |
b853f898 | 5227 | } |
2f4ef631 | 5228 | |
71292fab VZ |
5229 | // try the id |
5230 | if ( !win ) | |
b853f898 | 5231 | { |
0edeeb6d | 5232 | win = FindItem(id); |
42e69d6b VZ |
5233 | } |
5234 | ||
5235 | if ( win ) | |
b94ae1ea | 5236 | { |
42e69d6b | 5237 | return win->MSWCommand(cmd, id); |
b94ae1ea VZ |
5238 | } |
5239 | ||
5240 | // the messages sent from the in-place edit control used by the treectrl | |
5241 | // for label editing have id == 0, but they should _not_ be treated as menu | |
5242 | // messages (they are EN_XXX ones, in fact) so don't translate anything | |
5243 | // coming from a control to wxEVT_COMMAND_MENU_SELECTED | |
5244 | if ( !control ) | |
a84fc80b | 5245 | { |
a6ac49b1 | 5246 | wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, id); |
a84fc80b | 5247 | event.SetEventObject(this); |
a84fc80b | 5248 | event.SetInt(id); |
b94ae1ea | 5249 | |
937013e0 | 5250 | return HandleWindowEvent(event); |
a84fc80b | 5251 | } |
6fe19057 VZ |
5252 | else |
5253 | { | |
01d2bf4d | 5254 | #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__) |
6fe19057 VZ |
5255 | // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND |
5256 | // notifications to its parent which we want to reflect back to | |
5257 | // wxSpinCtrl | |
5258 | wxSpinCtrl *spin = wxSpinCtrl::GetSpinForTextCtrl(control); | |
5259 | if ( spin && spin->ProcessTextCommand(cmd, id) ) | |
08158721 | 5260 | return true; |
6fe19057 | 5261 | #endif // wxUSE_SPINCTRL |
42e69d6b | 5262 | |
01d2bf4d WS |
5263 | #if wxUSE_CHOICE && defined(__SMARTPHONE__) |
5264 | // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND | |
5265 | // notifications to its parent which we want to reflect back to | |
5266 | // wxChoice | |
5267 | wxChoice *choice = wxChoice::GetChoiceForListBox(control); | |
5268 | if ( choice && choice->MSWCommand(cmd, id) ) | |
5269 | return true; | |
5270 | #endif | |
5271 | } | |
5272 | ||
08158721 | 5273 | return false; |
2bda0e17 KB |
5274 | } |
5275 | ||
42e69d6b VZ |
5276 | // --------------------------------------------------------------------------- |
5277 | // mouse events | |
5278 | // --------------------------------------------------------------------------- | |
5279 | ||
1e6feb95 VZ |
5280 | void wxWindowMSW::InitMouseEvent(wxMouseEvent& event, |
5281 | int x, int y, | |
5282 | WXUINT flags) | |
42e69d6b | 5283 | { |
1e6feb95 VZ |
5284 | // our client coords are not quite the same as Windows ones |
5285 | wxPoint pt = GetClientAreaOrigin(); | |
5286 | event.m_x = x - pt.x; | |
5287 | event.m_y = y - pt.y; | |
5288 | ||
5289 | event.m_shiftDown = (flags & MK_SHIFT) != 0; | |
5290 | event.m_controlDown = (flags & MK_CONTROL) != 0; | |
5291 | event.m_leftDown = (flags & MK_LBUTTON) != 0; | |
5292 | event.m_middleDown = (flags & MK_MBUTTON) != 0; | |
5293 | event.m_rightDown = (flags & MK_RBUTTON) != 0; | |
2f68482e | 5294 | #ifdef wxHAS_XBUTTON |
01101e2d VZ |
5295 | event.m_aux1Down = (flags & MK_XBUTTON1) != 0; |
5296 | event.m_aux2Down = (flags & MK_XBUTTON2) != 0; | |
2f68482e | 5297 | #endif // wxHAS_XBUTTON |
6719c06a | 5298 | event.m_altDown = ::wxIsAltDown(); |
1e6feb95 | 5299 | |
f0b1ccde | 5300 | #ifndef __WXWINCE__ |
1bf77ee5 | 5301 | event.SetTimestamp(::GetMessageTime()); |
f0b1ccde JS |
5302 | #endif |
5303 | ||
687706f5 | 5304 | event.SetEventObject(this); |
fb35f0c7 | 5305 | event.SetId(GetId()); |
42e69d6b VZ |
5306 | |
5307 | #if wxUSE_MOUSEEVENT_HACK | |
c358ea41 VZ |
5308 | gs_lastMouseEvent.pos = ClientToScreen(wxPoint(x, y)); |
5309 | gs_lastMouseEvent.type = event.GetEventType(); | |
42e69d6b | 5310 | #endif // wxUSE_MOUSEEVENT_HACK |
2bda0e17 KB |
5311 | } |
5312 | ||
42b1fb63 | 5313 | #ifdef __WXWINCE__ |
dfafa702 VZ |
5314 | // Windows doesn't send the mouse events to the static controls (which are |
5315 | // transparent in the sense that their WM_NCHITTEST handler returns | |
5316 | // HTTRANSPARENT) at all but we want all controls to receive the mouse events | |
5317 | // and so we manually check if we don't have a child window under mouse and if | |
5318 | // we do, send the event to it instead of the window Windows had sent WM_XXX | |
5319 | // to. | |
5320 | // | |
5321 | // Notice that this is not done for the mouse move events because this could | |
5322 | // (would?) be too slow, but only for clicks which means that the static texts | |
5323 | // still don't get move, enter nor leave events. | |
42b1fb63 | 5324 | static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y) |
dfafa702 | 5325 | { |
9a83f860 | 5326 | wxCHECK_MSG( x && y, win, wxT("NULL pointer in FindWindowForMouseEvent") ); |
dfafa702 VZ |
5327 | |
5328 | // first try to find a non transparent child: this allows us to send events | |
5329 | // to a static text which is inside a static box, for example | |
5330 | POINT pt = { *x, *y }; | |
5331 | HWND hwnd = GetHwndOf(win), | |
5332 | hwndUnderMouse; | |
5333 | ||
7f0586ef JS |
5334 | #ifdef __WXWINCE__ |
5335 | hwndUnderMouse = ::ChildWindowFromPoint | |
5336 | ( | |
5337 | hwnd, | |
5338 | pt | |
5339 | ); | |
5340 | #else | |
dfafa702 VZ |
5341 | hwndUnderMouse = ::ChildWindowFromPointEx |
5342 | ( | |
5343 | hwnd, | |
5344 | pt, | |
5345 | CWP_SKIPINVISIBLE | | |
5346 | CWP_SKIPDISABLED | | |
5347 | CWP_SKIPTRANSPARENT | |
5348 | ); | |
7f0586ef | 5349 | #endif |
dfafa702 VZ |
5350 | |
5351 | if ( !hwndUnderMouse || hwndUnderMouse == hwnd ) | |
dfafa702 VZ |
5352 | { |
5353 | // now try any child window at all | |
5354 | hwndUnderMouse = ::ChildWindowFromPoint(hwnd, pt); | |
5355 | } | |
5356 | ||
5357 | // check that we have a child window which is susceptible to receive mouse | |
5358 | // events: for this it must be shown and enabled | |
5359 | if ( hwndUnderMouse && | |
5360 | hwndUnderMouse != hwnd && | |
5361 | ::IsWindowVisible(hwndUnderMouse) && | |
5362 | ::IsWindowEnabled(hwndUnderMouse) ) | |
5363 | { | |
dca0f651 | 5364 | wxWindow *winUnderMouse = wxFindWinFromHandle(hwndUnderMouse); |
dfafa702 VZ |
5365 | if ( winUnderMouse ) |
5366 | { | |
5367 | // translate the mouse coords to the other window coords | |
5368 | win->ClientToScreen(x, y); | |
5369 | winUnderMouse->ScreenToClient(x, y); | |
5370 | ||
5371 | win = winUnderMouse; | |
5372 | } | |
5373 | } | |
5374 | ||
5375 | return win; | |
5376 | } | |
42b1fb63 | 5377 | #endif // __WXWINCE__ |
dfafa702 | 5378 | |
1e6feb95 | 5379 | bool wxWindowMSW::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags) |
2bda0e17 | 5380 | { |
42e69d6b | 5381 | // the mouse events take consecutive IDs from WM_MOUSEFIRST to |
34621cc5 | 5382 | // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST |
42e69d6b VZ |
5383 | // from the message id and take the value in the table to get wxWin event |
5384 | // id | |
5385 | static const wxEventType eventsMouse[] = | |
5386 | { | |
5387 | wxEVT_MOTION, | |
5388 | wxEVT_LEFT_DOWN, | |
5389 | wxEVT_LEFT_UP, | |
5390 | wxEVT_LEFT_DCLICK, | |
5391 | wxEVT_RIGHT_DOWN, | |
5392 | wxEVT_RIGHT_UP, | |
5393 | wxEVT_RIGHT_DCLICK, | |
5394 | wxEVT_MIDDLE_DOWN, | |
5395 | wxEVT_MIDDLE_UP, | |
01101e2d VZ |
5396 | wxEVT_MIDDLE_DCLICK, |
5397 | 0, // this one is for wxEVT_MOTION which is not used here | |
5398 | wxEVT_AUX1_DOWN, | |
5399 | wxEVT_AUX1_UP, | |
5400 | wxEVT_AUX1_DCLICK, | |
5401 | wxEVT_AUX2_DOWN, | |
5402 | wxEVT_AUX2_UP, | |
5403 | wxEVT_AUX2_DCLICK | |
42e69d6b | 5404 | }; |
2bda0e17 | 5405 | |
2f68482e | 5406 | #ifdef wxHAS_XBUTTON |
01101e2d VZ |
5407 | // the same messages are used for both auxillary mouse buttons so we need |
5408 | // to adjust the index manually | |
5409 | switch ( msg ) | |
5410 | { | |
5411 | case WM_XBUTTONDOWN: | |
5412 | case WM_XBUTTONUP: | |
5413 | case WM_XBUTTONDBLCLK: | |
5414 | if ( flags & MK_XBUTTON2 ) | |
5415 | msg += wxEVT_AUX2_DOWN - wxEVT_AUX1_DOWN; | |
5416 | } | |
2f68482e | 5417 | #endif // wxHAS_XBUTTON |
01101e2d | 5418 | |
42e69d6b VZ |
5419 | wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]); |
5420 | InitMouseEvent(event, x, y, flags); | |
5421 | ||
937013e0 | 5422 | return HandleWindowEvent(event); |
42e69d6b VZ |
5423 | } |
5424 | ||
1e6feb95 | 5425 | bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags) |
42e69d6b VZ |
5426 | { |
5427 | if ( !m_mouseInWindow ) | |
2bda0e17 | 5428 | { |
1e6feb95 VZ |
5429 | // it would be wrong to assume that just because we get a mouse move |
5430 | // event that the mouse is inside the window: although this is usually | |
5431 | // true, it is not if we had captured the mouse, so we need to check | |
5432 | // the mouse coordinates here | |
5433 | if ( !HasCapture() || IsMouseInWindow() ) | |
5434 | { | |
5435 | // Generate an ENTER event | |
08158721 | 5436 | m_mouseInWindow = true; |
e5297b7f | 5437 | |
4e5c6c33 | 5438 | #ifdef HAVE_TRACKMOUSEEVENT |
aafb9978 VZ |
5439 | typedef BOOL (WINAPI *_TrackMouseEvent_t)(LPTRACKMOUSEEVENT); |
5440 | #ifdef __WXWINCE__ | |
5441 | static const _TrackMouseEvent_t | |
5442 | s_pfn_TrackMouseEvent = _TrackMouseEvent; | |
5443 | #else // !__WXWINCE__ | |
5444 | static _TrackMouseEvent_t s_pfn_TrackMouseEvent; | |
5445 | static bool s_initDone = false; | |
5446 | if ( !s_initDone ) | |
5447 | { | |
e2d4ce7d | 5448 | // see comment in wxApp::GetComCtl32Version() explaining the |
5a9379d7 | 5449 | // use of wxLoadedDLL |
9a83f860 | 5450 | wxLoadedDLL dllComCtl32(wxT("comctl32.dll")); |
aafb9978 VZ |
5451 | if ( dllComCtl32.IsLoaded() ) |
5452 | { | |
5453 | s_pfn_TrackMouseEvent = (_TrackMouseEvent_t) | |
9a83f860 | 5454 | dllComCtl32.RawGetSymbol(wxT("_TrackMouseEvent")); |
aafb9978 VZ |
5455 | } |
5456 | ||
5457 | s_initDone = true; | |
aafb9978 VZ |
5458 | } |
5459 | ||
5460 | if ( s_pfn_TrackMouseEvent ) | |
5461 | #endif // __WXWINCE__/!__WXWINCE__ | |
5462 | { | |
5463 | WinStruct<TRACKMOUSEEVENT> trackinfo; | |
4e5c6c33 | 5464 | |
aafb9978 VZ |
5465 | trackinfo.dwFlags = TME_LEAVE; |
5466 | trackinfo.hwndTrack = GetHwnd(); | |
5467 | ||
5468 | (*s_pfn_TrackMouseEvent)(&trackinfo); | |
5469 | } | |
4e5c6c33 VZ |
5470 | #endif // HAVE_TRACKMOUSEEVENT |
5471 | ||
1e6feb95 VZ |
5472 | wxMouseEvent event(wxEVT_ENTER_WINDOW); |
5473 | InitMouseEvent(event, x, y, flags); | |
42e69d6b | 5474 | |
937013e0 | 5475 | (void)HandleWindowEvent(event); |
1e6feb95 | 5476 | } |
42e69d6b | 5477 | } |
cff58b52 | 5478 | #ifdef HAVE_TRACKMOUSEEVENT |
aafb9978 | 5479 | else // mouse not in window |
cff58b52 KH |
5480 | { |
5481 | // Check if we need to send a LEAVE event | |
5482 | // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so | |
5483 | // send it here if we are using native mouse leave tracking | |
5484 | if ( HasCapture() && !IsMouseInWindow() ) | |
5485 | { | |
5486 | GenerateMouseLeave(); | |
5487 | } | |
5488 | } | |
1ca78aa1 | 5489 | #endif // HAVE_TRACKMOUSEEVENT |
42e69d6b VZ |
5490 | |
5491 | #if wxUSE_MOUSEEVENT_HACK | |
c358ea41 VZ |
5492 | // Windows often generates mouse events even if mouse position hasn't |
5493 | // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576) | |
5494 | // | |
5495 | // Filter this out as it can result in unexpected behaviour compared to | |
5496 | // other platforms | |
5497 | if ( gs_lastMouseEvent.type == wxEVT_RIGHT_DOWN || | |
5498 | gs_lastMouseEvent.type == wxEVT_LEFT_DOWN || | |
5499 | gs_lastMouseEvent.type == wxEVT_MIDDLE_DOWN || | |
5500 | gs_lastMouseEvent.type == wxEVT_MOTION ) | |
5501 | { | |
5502 | if ( ClientToScreen(wxPoint(x, y)) == gs_lastMouseEvent.pos ) | |
5503 | { | |
5504 | gs_lastMouseEvent.type = wxEVT_MOTION; | |
42e69d6b | 5505 | |
c358ea41 VZ |
5506 | return false; |
5507 | } | |
42e69d6b VZ |
5508 | } |
5509 | #endif // wxUSE_MOUSEEVENT_HACK | |
5510 | ||
5511 | return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags); | |
5512 | } | |
5513 | ||
d2c52078 | 5514 | |
24ce4c18 | 5515 | bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam) |
d2c52078 RD |
5516 | { |
5517 | #if wxUSE_MOUSEWHEEL | |
3c297348 VZ |
5518 | // notice that WM_MOUSEWHEEL position is in screen coords (as it's |
5519 | // forwarded up to the parent by DefWindowProc()) and not in the client | |
5520 | // ones as all the other messages, translate them to the client coords for | |
5521 | // consistency | |
5522 | const wxPoint | |
5523 | pt = ScreenToClient(wxPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); | |
d2c52078 | 5524 | wxMouseEvent event(wxEVT_MOUSEWHEEL); |
3c297348 | 5525 | InitMouseEvent(event, pt.x, pt.y, LOWORD(wParam)); |
d2c52078 RD |
5526 | event.m_wheelRotation = (short)HIWORD(wParam); |
5527 | event.m_wheelDelta = WHEEL_DELTA; | |
5528 | ||
0f7a546d RD |
5529 | static int s_linesPerRotation = -1; |
5530 | if ( s_linesPerRotation == -1 ) | |
5531 | { | |
5532 | if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, | |
5533 | &s_linesPerRotation, 0)) | |
5534 | { | |
5535 | // this is not supposed to happen | |
9a83f860 | 5536 | wxLogLastError(wxT("SystemParametersInfo(GETWHEELSCROLLLINES)")); |
0f7a546d RD |
5537 | |
5538 | // the default is 3, so use it if SystemParametersInfo() failed | |
5539 | s_linesPerRotation = 3; | |
5540 | } | |
5541 | } | |
d2c52078 | 5542 | |
0f7a546d | 5543 | event.m_linesPerAction = s_linesPerRotation; |
937013e0 | 5544 | return HandleWindowEvent(event); |
0f7a546d | 5545 | |
51e4e266 VZ |
5546 | #else // !wxUSE_MOUSEWHEEL |
5547 | wxUnusedVar(wParam); | |
5548 | wxUnusedVar(lParam); | |
38caaa61 | 5549 | |
08158721 | 5550 | return false; |
51e4e266 | 5551 | #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL |
d2c52078 RD |
5552 | } |
5553 | ||
51e4e266 VZ |
5554 | void wxWindowMSW::GenerateMouseLeave() |
5555 | { | |
5556 | m_mouseInWindow = false; | |
5557 | ||
5558 | int state = 0; | |
5559 | if ( wxIsShiftDown() ) | |
5560 | state |= MK_SHIFT; | |
5561 | if ( wxIsCtrlDown() ) | |
5562 | state |= MK_CONTROL; | |
5563 | ||
5564 | // Only the high-order bit should be tested | |
5565 | if ( GetKeyState( VK_LBUTTON ) & (1<<15) ) | |
5566 | state |= MK_LBUTTON; | |
5567 | if ( GetKeyState( VK_MBUTTON ) & (1<<15) ) | |
5568 | state |= MK_MBUTTON; | |
5569 | if ( GetKeyState( VK_RBUTTON ) & (1<<15) ) | |
5570 | state |= MK_RBUTTON; | |
5571 | ||
5572 | POINT pt; | |
f2325516 JS |
5573 | #ifdef __WXWINCE__ |
5574 | if ( !::GetCursorPosWinCE(&pt) ) | |
5575 | #else | |
51e4e266 | 5576 | if ( !::GetCursorPos(&pt) ) |
f2325516 | 5577 | #endif |
51e4e266 | 5578 | { |
9a83f860 | 5579 | wxLogLastError(wxT("GetCursorPos")); |
51e4e266 VZ |
5580 | } |
5581 | ||
5582 | // we need to have client coordinates here for symmetry with | |
5583 | // wxEVT_ENTER_WINDOW | |
5584 | RECT rect = wxGetWindowRect(GetHwnd()); | |
5585 | pt.x -= rect.left; | |
5586 | pt.y -= rect.top; | |
5587 | ||
5588 | wxMouseEvent event(wxEVT_LEAVE_WINDOW); | |
5589 | InitMouseEvent(event, pt.x, pt.y, state); | |
5590 | ||
937013e0 | 5591 | (void)HandleWindowEvent(event); |
51e4e266 | 5592 | } |
d2c52078 | 5593 | |
42e69d6b VZ |
5594 | // --------------------------------------------------------------------------- |
5595 | // keyboard handling | |
5596 | // --------------------------------------------------------------------------- | |
5597 | ||
c42404a5 VZ |
5598 | // create the key event of the given type for the given key - used by |
5599 | // HandleChar and HandleKeyDown/Up | |
1e6feb95 | 5600 | wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType, |
b09bda68 | 5601 | int id, |
9c7df356 VZ |
5602 | WXLPARAM lParam, |
5603 | WXWPARAM wParam) const | |
c42404a5 VZ |
5604 | { |
5605 | wxKeyEvent event(evType); | |
5606 | event.SetId(GetId()); | |
3f7bc32b VZ |
5607 | event.m_shiftDown = wxIsShiftDown(); |
5608 | event.m_controlDown = wxIsCtrlDown(); | |
c42404a5 VZ |
5609 | event.m_altDown = (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN; |
5610 | ||
687706f5 | 5611 | event.SetEventObject((wxWindow *)this); // const_cast |
c42404a5 | 5612 | event.m_keyCode = id; |
0d9b2c16 | 5613 | #if wxUSE_UNICODE |
32b13913 | 5614 | event.m_uniChar = (wxChar) wParam; |
0d9b2c16 | 5615 | #endif |
9c7df356 VZ |
5616 | event.m_rawCode = (wxUint32) wParam; |
5617 | event.m_rawFlags = (wxUint32) lParam; | |
f0b1ccde | 5618 | #ifndef __WXWINCE__ |
1bf77ee5 | 5619 | event.SetTimestamp(::GetMessageTime()); |
f0b1ccde | 5620 | #endif |
c42404a5 | 5621 | |
1acbfd01 VZ |
5622 | // translate the position to client coordinates |
5623 | const wxPoint mousePos = ScreenToClient(wxGetMousePosition()); | |
5624 | event.m_x = mousePos.x; | |
5625 | event.m_y = mousePos.y; | |
c42404a5 VZ |
5626 | |
5627 | return event; | |
5628 | } | |
5629 | ||
08158721 | 5630 | // isASCII is true only when we're called from WM_CHAR handler and not from |
42e69d6b | 5631 | // WM_KEYDOWN one |
1e6feb95 | 5632 | bool wxWindowMSW::HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII) |
42e69d6b VZ |
5633 | { |
5634 | int id; | |
42e69d6b VZ |
5635 | if ( isASCII ) |
5636 | { | |
42e69d6b | 5637 | id = wParam; |
2d0a075d | 5638 | } |
9c7df356 | 5639 | else // we're called from WM_KEYDOWN |
c42404a5 | 5640 | { |
6121a198 VZ |
5641 | // don't pass lParam to wxCharCodeMSWToWX() here because we don't want |
5642 | // to get numpad key codes: CHAR events should use the logical keys | |
5643 | // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events | |
5644 | id = wxCharCodeMSWToWX(wParam); | |
9c7df356 | 5645 | if ( id == 0 ) |
c42404a5 | 5646 | { |
9c7df356 | 5647 | // it's ASCII and will be processed here only when called from |
08158721 DS |
5648 | // WM_CHAR (i.e. when isASCII = true), don't process it now |
5649 | return false; | |
c42404a5 | 5650 | } |
9c7df356 | 5651 | } |
42e69d6b | 5652 | |
9c7df356 | 5653 | wxKeyEvent event(CreateKeyEvent(wxEVT_CHAR, id, lParam, wParam)); |
2b5f62a0 VZ |
5654 | |
5655 | // the alphanumeric keys produced by pressing AltGr+something on European | |
5656 | // keyboards have both Ctrl and Alt modifiers which may confuse the user | |
5657 | // code as, normally, keys with Ctrl and/or Alt don't result in anything | |
5658 | // alphanumeric, so pretend that there are no modifiers at all (the | |
5659 | // KEY_DOWN event would still have the correct modifiers if they're really | |
5660 | // needed) | |
5661 | if ( event.m_controlDown && event.m_altDown && | |
5662 | (id >= 32 && id < 256) ) | |
9c7df356 | 5663 | { |
2b5f62a0 | 5664 | event.m_controlDown = |
08158721 | 5665 | event.m_altDown = false; |
2d0a075d | 5666 | } |
c42404a5 | 5667 | |
937013e0 | 5668 | return HandleWindowEvent(event); |
2bda0e17 KB |
5669 | } |
5670 | ||
1e6feb95 | 5671 | bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 5672 | { |
ff792344 | 5673 | int id = wxCharCodeMSWToWX(wParam, lParam); |
2bda0e17 | 5674 | |
c42404a5 VZ |
5675 | if ( !id ) |
5676 | { | |
5677 | // normal ASCII char | |
42e69d6b VZ |
5678 | id = wParam; |
5679 | } | |
5680 | ||
b60978b2 | 5681 | wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, id, lParam, wParam)); |
937013e0 | 5682 | return HandleWindowEvent(event); |
2bda0e17 KB |
5683 | } |
5684 | ||
1e6feb95 | 5685 | bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 5686 | { |
ff792344 | 5687 | int id = wxCharCodeMSWToWX(wParam, lParam); |
2bda0e17 | 5688 | |
c42404a5 VZ |
5689 | if ( !id ) |
5690 | { | |
5691 | // normal ASCII char | |
42e69d6b | 5692 | id = wParam; |
2d0a075d | 5693 | } |
2bda0e17 | 5694 | |
b60978b2 | 5695 | wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, id, lParam, wParam)); |
937013e0 | 5696 | return HandleWindowEvent(event); |
2bda0e17 KB |
5697 | } |
5698 | ||
53a118d6 | 5699 | #if wxUSE_MENUS |
0c0d1521 WS |
5700 | int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel), |
5701 | WXLPARAM WXUNUSED_IN_WINCE(lParam)) | |
b74cce40 | 5702 | { |
7f0586ef JS |
5703 | // FIXME: implement GetMenuItemCount for WinCE, possibly |
5704 | // in terms of GetMenuItemInfo | |
5705 | #ifndef __WXWINCE__ | |
b74cce40 VZ |
5706 | const HMENU hmenu = (HMENU)lParam; |
5707 | ||
5708 | MENUITEMINFO mii; | |
5709 | wxZeroMemory(mii); | |
5710 | mii.cbSize = sizeof(MENUITEMINFO); | |
c70ffbdb VZ |
5711 | |
5712 | // we could use MIIM_FTYPE here as we only need to know if the item is | |
5713 | // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but | |
5714 | // MIIM_FTYPE is not supported under Win95 | |
b74cce40 VZ |
5715 | mii.fMask = MIIM_TYPE | MIIM_DATA; |
5716 | ||
5717 | // find if we have this letter in any owner drawn item | |
5718 | const int count = ::GetMenuItemCount(hmenu); | |
5719 | for ( int i = 0; i < count; i++ ) | |
5720 | { | |
c70ffbdb VZ |
5721 | // previous loop iteration could modify it, reset it back before |
5722 | // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData | |
5723 | mii.cch = 0; | |
5724 | ||
b74cce40 VZ |
5725 | if ( ::GetMenuItemInfo(hmenu, i, TRUE, &mii) ) |
5726 | { | |
5727 | if ( mii.fType == MFT_OWNERDRAW ) | |
5728 | { | |
5729 | // dwItemData member of the MENUITEMINFO is a | |
5730 | // pointer to the associated wxMenuItem -- see the | |
5731 | // menu creation code | |
5732 | wxMenuItem *item = (wxMenuItem*)mii.dwItemData; | |
5733 | ||
9a83f860 | 5734 | const wxChar *p = wxStrchr(item->GetItemLabel().wx_str(), wxT('&')); |
b74cce40 VZ |
5735 | while ( p++ ) |
5736 | { | |
9a83f860 | 5737 | if ( *p == wxT('&') ) |
b74cce40 VZ |
5738 | { |
5739 | // this is not the accel char, find the real one | |
9a83f860 | 5740 | p = wxStrchr(p + 1, wxT('&')); |
b74cce40 VZ |
5741 | } |
5742 | else // got the accel char | |
5743 | { | |
5744 | // FIXME-UNICODE: this comparison doesn't risk to work | |
5745 | // for non ASCII accelerator characters I'm afraid, but | |
5746 | // what can we do? | |
907173e5 | 5747 | if ( (wchar_t)wxToupper(*p) == (wchar_t)chAccel ) |
b74cce40 VZ |
5748 | { |
5749 | return i; | |
5750 | } | |
5751 | else | |
5752 | { | |
5753 | // this one doesn't match | |
5754 | break; | |
5755 | } | |
5756 | } | |
5757 | } | |
5758 | } | |
5759 | } | |
e39af974 | 5760 | else // failed to get the menu text? |
b74cce40 | 5761 | { |
c70ffbdb | 5762 | // it's not fatal, so don't show error, but still log it |
9a83f860 | 5763 | wxLogLastError(wxT("GetMenuItemInfo")); |
b74cce40 VZ |
5764 | } |
5765 | } | |
7f0586ef | 5766 | #endif |
b74cce40 VZ |
5767 | return wxNOT_FOUND; |
5768 | } | |
5769 | ||
17a04304 VZ |
5770 | #endif // wxUSE_MENUS |
5771 | ||
5772 | bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg) | |
78c91815 | 5773 | { |
17a04304 VZ |
5774 | const wxEventType type = nMsg == WM_CUT ? wxEVT_COMMAND_TEXT_CUT |
5775 | : nMsg == WM_COPY ? wxEVT_COMMAND_TEXT_COPY | |
5776 | : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE; | |
78c91815 VZ |
5777 | wxClipboardTextEvent evt(type, GetId()); |
5778 | ||
5779 | evt.SetEventObject(this); | |
5780 | ||
937013e0 | 5781 | return HandleWindowEvent(evt); |
78c91815 VZ |
5782 | } |
5783 | ||
42e69d6b VZ |
5784 | // --------------------------------------------------------------------------- |
5785 | // joystick | |
5786 | // --------------------------------------------------------------------------- | |
5787 | ||
1e6feb95 | 5788 | bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags) |
2bda0e17 | 5789 | { |
8cb172b4 | 5790 | #ifdef JOY_BUTTON1 |
42e69d6b VZ |
5791 | int change = 0; |
5792 | if ( flags & JOY_BUTTON1CHG ) | |
5793 | change = wxJOY_BUTTON1; | |
5794 | if ( flags & JOY_BUTTON2CHG ) | |
5795 | change = wxJOY_BUTTON2; | |
5796 | if ( flags & JOY_BUTTON3CHG ) | |
5797 | change = wxJOY_BUTTON3; | |
5798 | if ( flags & JOY_BUTTON4CHG ) | |
5799 | change = wxJOY_BUTTON4; | |
2bda0e17 | 5800 | |
42e69d6b VZ |
5801 | int buttons = 0; |
5802 | if ( flags & JOY_BUTTON1 ) | |
5803 | buttons |= wxJOY_BUTTON1; | |
5804 | if ( flags & JOY_BUTTON2 ) | |
5805 | buttons |= wxJOY_BUTTON2; | |
5806 | if ( flags & JOY_BUTTON3 ) | |
5807 | buttons |= wxJOY_BUTTON3; | |
5808 | if ( flags & JOY_BUTTON4 ) | |
5809 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 5810 | |
42e69d6b VZ |
5811 | // the event ids aren't consecutive so we can't use table based lookup |
5812 | int joystick; | |
5813 | wxEventType eventType; | |
5814 | switch ( msg ) | |
5815 | { | |
5816 | case MM_JOY1MOVE: | |
5817 | joystick = 1; | |
5818 | eventType = wxEVT_JOY_MOVE; | |
5819 | break; | |
2bda0e17 | 5820 | |
42e69d6b VZ |
5821 | case MM_JOY2MOVE: |
5822 | joystick = 2; | |
5823 | eventType = wxEVT_JOY_MOVE; | |
5824 | break; | |
2bda0e17 | 5825 | |
42e69d6b VZ |
5826 | case MM_JOY1ZMOVE: |
5827 | joystick = 1; | |
5828 | eventType = wxEVT_JOY_ZMOVE; | |
5829 | break; | |
2bda0e17 | 5830 | |
42e69d6b VZ |
5831 | case MM_JOY2ZMOVE: |
5832 | joystick = 2; | |
5833 | eventType = wxEVT_JOY_ZMOVE; | |
5834 | break; | |
2bda0e17 | 5835 | |
42e69d6b VZ |
5836 | case MM_JOY1BUTTONDOWN: |
5837 | joystick = 1; | |
5838 | eventType = wxEVT_JOY_BUTTON_DOWN; | |
5839 | break; | |
2bda0e17 | 5840 | |
42e69d6b VZ |
5841 | case MM_JOY2BUTTONDOWN: |
5842 | joystick = 2; | |
5843 | eventType = wxEVT_JOY_BUTTON_DOWN; | |
5844 | break; | |
2bda0e17 | 5845 | |
42e69d6b VZ |
5846 | case MM_JOY1BUTTONUP: |
5847 | joystick = 1; | |
5848 | eventType = wxEVT_JOY_BUTTON_UP; | |
5849 | break; | |
5850 | ||
5851 | case MM_JOY2BUTTONUP: | |
5852 | joystick = 2; | |
5853 | eventType = wxEVT_JOY_BUTTON_UP; | |
5854 | break; | |
5855 | ||
5856 | default: | |
223d09f6 | 5857 | wxFAIL_MSG(wxT("no such joystick event")); |
2d0a075d | 5858 | |
08158721 | 5859 | return false; |
2d0a075d | 5860 | } |
2bda0e17 | 5861 | |
42e69d6b VZ |
5862 | wxJoystickEvent event(eventType, buttons, joystick, change); |
5863 | event.SetPosition(wxPoint(x, y)); | |
5864 | event.SetEventObject(this); | |
c085e333 | 5865 | |
937013e0 | 5866 | return HandleWindowEvent(event); |
8cb172b4 | 5867 | #else |
991420e6 WS |
5868 | wxUnusedVar(msg); |
5869 | wxUnusedVar(x); | |
5870 | wxUnusedVar(y); | |
5871 | wxUnusedVar(flags); | |
08158721 | 5872 | return false; |
8cb172b4 | 5873 | #endif |
2bda0e17 KB |
5874 | } |
5875 | ||
42e69d6b VZ |
5876 | // --------------------------------------------------------------------------- |
5877 | // scrolling | |
5878 | // --------------------------------------------------------------------------- | |
5879 | ||
1e6feb95 | 5880 | bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam, |
f4f734c1 | 5881 | WXWORD pos, WXHWND control) |
35bbb0c6 | 5882 | { |
a0d924c6 | 5883 | if ( control && control != m_hWnd ) // Prevent infinite recursion |
cc2b7472 | 5884 | { |
42e69d6b VZ |
5885 | wxWindow *child = wxFindWinFromHandle(control); |
5886 | if ( child ) | |
5887 | return child->MSWOnScroll(orientation, wParam, pos, control); | |
cc2b7472 | 5888 | } |
2bda0e17 | 5889 | |
9145664b | 5890 | wxScrollWinEvent event; |
42e69d6b VZ |
5891 | event.SetPosition(pos); |
5892 | event.SetOrientation(orientation); | |
687706f5 | 5893 | event.SetEventObject(this); |
cc2b7472 | 5894 | |
42e69d6b VZ |
5895 | switch ( wParam ) |
5896 | { | |
5897 | case SB_TOP: | |
687706f5 | 5898 | event.SetEventType(wxEVT_SCROLLWIN_TOP); |
42e69d6b | 5899 | break; |
cc2b7472 | 5900 | |
42e69d6b | 5901 | case SB_BOTTOM: |
687706f5 | 5902 | event.SetEventType(wxEVT_SCROLLWIN_BOTTOM); |
42e69d6b | 5903 | break; |
cc2b7472 | 5904 | |
42e69d6b | 5905 | case SB_LINEUP: |
687706f5 | 5906 | event.SetEventType(wxEVT_SCROLLWIN_LINEUP); |
42e69d6b | 5907 | break; |
2bda0e17 | 5908 | |
42e69d6b | 5909 | case SB_LINEDOWN: |
687706f5 | 5910 | event.SetEventType(wxEVT_SCROLLWIN_LINEDOWN); |
42e69d6b | 5911 | break; |
a02eb1d2 | 5912 | |
42e69d6b | 5913 | case SB_PAGEUP: |
687706f5 | 5914 | event.SetEventType(wxEVT_SCROLLWIN_PAGEUP); |
42e69d6b | 5915 | break; |
2bda0e17 | 5916 | |
42e69d6b | 5917 | case SB_PAGEDOWN: |
687706f5 | 5918 | event.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN); |
42e69d6b | 5919 | break; |
2bda0e17 | 5920 | |
42e69d6b | 5921 | case SB_THUMBPOSITION: |
feda3011 | 5922 | case SB_THUMBTRACK: |
f6bcfd97 BP |
5923 | // under Win32, the scrollbar range and position are 32 bit integers, |
5924 | // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must | |
5925 | // explicitly query the scrollbar for the correct position (this must | |
5926 | // be done only for these two SB_ events as they are the only one | |
5927 | // carrying the scrollbar position) | |
5928 | { | |
0cf5de11 | 5929 | WinStruct<SCROLLINFO> scrollInfo; |
f6bcfd97 BP |
5930 | scrollInfo.fMask = SIF_TRACKPOS; |
5931 | ||
5932 | if ( !::GetScrollInfo(GetHwnd(), | |
1ddb6d28 | 5933 | WXOrientToSB(orientation), |
f6bcfd97 BP |
5934 | &scrollInfo) ) |
5935 | { | |
3103e8a9 | 5936 | // Not necessarily an error, if there are no scrollbars yet. |
9a83f860 | 5937 | // wxLogLastError(wxT("GetScrollInfo")); |
f6bcfd97 BP |
5938 | } |
5939 | ||
5940 | event.SetPosition(scrollInfo.nTrackPos); | |
5941 | } | |
f6bcfd97 | 5942 | |
687706f5 | 5943 | event.SetEventType( wParam == SB_THUMBPOSITION |
f6bcfd97 | 5944 | ? wxEVT_SCROLLWIN_THUMBRELEASE |
687706f5 | 5945 | : wxEVT_SCROLLWIN_THUMBTRACK ); |
42e69d6b | 5946 | break; |
c085e333 | 5947 | |
42e69d6b | 5948 | default: |
08158721 | 5949 | return false; |
564b2609 | 5950 | } |
2bda0e17 | 5951 | |
937013e0 | 5952 | return HandleWindowEvent(event); |
2bda0e17 KB |
5953 | } |
5954 | ||
5acec112 VZ |
5955 | // ---------------------------------------------------------------------------- |
5956 | // custom message handlers | |
5957 | // ---------------------------------------------------------------------------- | |
5958 | ||
5959 | /* static */ bool | |
5960 | wxWindowMSW::MSWRegisterMessageHandler(int msg, MSWMessageHandler handler) | |
5961 | { | |
5962 | wxCHECK_MSG( gs_messageHandlers.find(msg) == gs_messageHandlers.end(), | |
9a83f860 | 5963 | false, wxT("registering handler for the same message twice") ); |
5acec112 VZ |
5964 | |
5965 | gs_messageHandlers[msg] = handler; | |
5966 | return true; | |
5967 | } | |
5968 | ||
5969 | /* static */ void | |
5970 | wxWindowMSW::MSWUnregisterMessageHandler(int msg, MSWMessageHandler handler) | |
5971 | { | |
5972 | const MSWMessageHandlers::iterator i = gs_messageHandlers.find(msg); | |
5973 | wxCHECK_RET( i != gs_messageHandlers.end() && i->second == handler, | |
9a83f860 | 5974 | wxT("unregistering non-registered handler?") ); |
5acec112 VZ |
5975 | |
5976 | gs_messageHandlers.erase(i); | |
5977 | } | |
5978 | ||
42e69d6b VZ |
5979 | // =========================================================================== |
5980 | // global functions | |
5981 | // =========================================================================== | |
5982 | ||
7a5e53ab | 5983 | void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font) |
2bda0e17 | 5984 | { |
42e69d6b VZ |
5985 | TEXTMETRIC tm; |
5986 | HDC dc = ::GetDC((HWND) wnd); | |
42e69d6b | 5987 | HFONT was = 0; |
35bbb0c6 | 5988 | |
7a5e53ab VS |
5989 | // the_font.UseResource(); |
5990 | // the_font.RealizeResource(); | |
c57c2993 | 5991 | HFONT fnt = (HFONT)the_font.GetResourceHandle(); // const_cast |
7a5e53ab VS |
5992 | if ( fnt ) |
5993 | was = (HFONT) SelectObject(dc,fnt); | |
35bbb0c6 | 5994 | |
42e69d6b | 5995 | GetTextMetrics(dc, &tm); |
7a5e53ab | 5996 | if ( fnt && was ) |
2d0a075d | 5997 | { |
42e69d6b | 5998 | SelectObject(dc,was); |
2d0a075d | 5999 | } |
42e69d6b | 6000 | ReleaseDC((HWND)wnd, dc); |
0655ad29 VZ |
6001 | |
6002 | if ( x ) | |
6003 | *x = tm.tmAveCharWidth; | |
6004 | if ( y ) | |
6005 | *y = tm.tmHeight + tm.tmExternalLeading; | |
2bda0e17 | 6006 | |
7a5e53ab | 6007 | // the_font.ReleaseResource(); |
42e69d6b | 6008 | } |
c085e333 | 6009 | |
5004c3ad JG |
6010 | // use the "extended" bit (24) of lParam to distinguish extended keys |
6011 | // from normal keys as the same key is sent | |
ed5bc8f1 VZ |
6012 | static inline |
6013 | int ChooseNormalOrExtended(int lParam, int keyNormal, int keyExtended) | |
5004c3ad | 6014 | { |
ed5bc8f1 VZ |
6015 | // except that if lParam is 0, it means we don't have real lParam from |
6016 | // WM_KEYDOWN but are just translating just a VK constant (e.g. done from | |
6017 | // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a | |
6018 | // non-numpad (hence extended) key as this is a more common case | |
6019 | return !lParam || (lParam & (1 << 24)) ? keyExtended : keyNormal; | |
5004c3ad JG |
6020 | } |
6021 | ||
d5c21b02 VZ |
6022 | // this array contains the Windows virtual key codes which map one to one to |
6023 | // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below | |
6024 | // | |
6025 | // note that keys having a normal and numpad version (e.g. WXK_HOME and | |
6026 | // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1 | |
6027 | static const struct wxKeyMapping | |
6028 | { | |
6029 | int vk; | |
6030 | wxKeyCode wxk; | |
6031 | } gs_specialKeys[] = | |
6032 | { | |
6033 | { VK_CANCEL, WXK_CANCEL }, | |
6034 | { VK_BACK, WXK_BACK }, | |
6035 | { VK_TAB, WXK_TAB }, | |
6036 | { VK_CLEAR, WXK_CLEAR }, | |
6037 | { VK_SHIFT, WXK_SHIFT }, | |
6038 | { VK_CONTROL, WXK_CONTROL }, | |
6039 | { VK_MENU , WXK_ALT }, | |
6040 | { VK_PAUSE, WXK_PAUSE }, | |
6041 | { VK_CAPITAL, WXK_CAPITAL }, | |
6042 | { VK_SPACE, WXK_SPACE }, | |
6043 | { VK_ESCAPE, WXK_ESCAPE }, | |
6044 | { VK_SELECT, WXK_SELECT }, | |
6045 | { VK_PRINT, WXK_PRINT }, | |
6046 | { VK_EXECUTE, WXK_EXECUTE }, | |
e59c2b2d VZ |
6047 | { VK_SNAPSHOT, WXK_SNAPSHOT }, |
6048 | { VK_HELP, WXK_HELP }, | |
d5c21b02 VZ |
6049 | |
6050 | { VK_NUMPAD0, WXK_NUMPAD0 }, | |
6051 | { VK_NUMPAD1, WXK_NUMPAD1 }, | |
6052 | { VK_NUMPAD2, WXK_NUMPAD2 }, | |
6053 | { VK_NUMPAD3, WXK_NUMPAD3 }, | |
6054 | { VK_NUMPAD4, WXK_NUMPAD4 }, | |
6055 | { VK_NUMPAD5, WXK_NUMPAD5 }, | |
6056 | { VK_NUMPAD6, WXK_NUMPAD6 }, | |
6057 | { VK_NUMPAD7, WXK_NUMPAD7 }, | |
6058 | { VK_NUMPAD8, WXK_NUMPAD8 }, | |
6059 | { VK_NUMPAD9, WXK_NUMPAD9 }, | |
6060 | { VK_MULTIPLY, WXK_NUMPAD_MULTIPLY }, | |
6061 | { VK_ADD, WXK_NUMPAD_ADD }, | |
6062 | { VK_SUBTRACT, WXK_NUMPAD_SUBTRACT }, | |
6063 | { VK_DECIMAL, WXK_NUMPAD_DECIMAL }, | |
6064 | { VK_DIVIDE, WXK_NUMPAD_DIVIDE }, | |
6065 | ||
6066 | { VK_F1, WXK_F1 }, | |
6067 | { VK_F2, WXK_F2 }, | |
6068 | { VK_F3, WXK_F3 }, | |
6069 | { VK_F4, WXK_F4 }, | |
6070 | { VK_F5, WXK_F5 }, | |
6071 | { VK_F6, WXK_F6 }, | |
6072 | { VK_F7, WXK_F7 }, | |
6073 | { VK_F8, WXK_F8 }, | |
6074 | { VK_F9, WXK_F9 }, | |
6075 | { VK_F10, WXK_F10 }, | |
6076 | { VK_F11, WXK_F11 }, | |
6077 | { VK_F12, WXK_F12 }, | |
6078 | { VK_F13, WXK_F13 }, | |
6079 | { VK_F14, WXK_F14 }, | |
6080 | { VK_F15, WXK_F15 }, | |
6081 | { VK_F16, WXK_F16 }, | |
6082 | { VK_F17, WXK_F17 }, | |
6083 | { VK_F18, WXK_F18 }, | |
6084 | { VK_F19, WXK_F19 }, | |
6085 | { VK_F20, WXK_F20 }, | |
6086 | { VK_F21, WXK_F21 }, | |
6087 | { VK_F22, WXK_F22 }, | |
6088 | { VK_F23, WXK_F23 }, | |
6089 | { VK_F24, WXK_F24 }, | |
6090 | ||
6091 | { VK_NUMLOCK, WXK_NUMLOCK }, | |
6092 | { VK_SCROLL, WXK_SCROLL }, | |
6093 | ||
6094 | #ifdef VK_APPS | |
6095 | { VK_LWIN, WXK_WINDOWS_LEFT }, | |
6096 | { VK_RWIN, WXK_WINDOWS_RIGHT }, | |
6097 | { VK_APPS, WXK_WINDOWS_MENU }, | |
6098 | #endif // VK_APPS defined | |
6099 | }; | |
6100 | ||
42e69d6b VZ |
6101 | // Returns 0 if was a normal ASCII value, not a special key. This indicates that |
6102 | // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead. | |
d5c21b02 | 6103 | int wxCharCodeMSWToWX(int vk, WXLPARAM lParam) |
42e69d6b | 6104 | { |
d5c21b02 VZ |
6105 | // check the table first |
6106 | for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ ) | |
6107 | { | |
6108 | if ( gs_specialKeys[n].vk == vk ) | |
6109 | return gs_specialKeys[n].wxk; | |
6110 | } | |
9c7df356 | 6111 | |
d5c21b02 VZ |
6112 | // keys requiring special handling |
6113 | int wxk; | |
6114 | switch ( vk ) | |
6115 | { | |
e77c5d96 VZ |
6116 | // the mapping for these keys may be incorrect on non-US keyboards so |
6117 | // maybe we shouldn't map them to ASCII values at all | |
d5c21b02 VZ |
6118 | case VK_OEM_1: wxk = ';'; break; |
6119 | case VK_OEM_PLUS: wxk = '+'; break; | |
6120 | case VK_OEM_COMMA: wxk = ','; break; | |
6121 | case VK_OEM_MINUS: wxk = '-'; break; | |
6122 | case VK_OEM_PERIOD: wxk = '.'; break; | |
6123 | case VK_OEM_2: wxk = '/'; break; | |
6124 | case VK_OEM_3: wxk = '~'; break; | |
6125 | case VK_OEM_4: wxk = '['; break; | |
6126 | case VK_OEM_5: wxk = '\\'; break; | |
6127 | case VK_OEM_6: wxk = ']'; break; | |
6128 | case VK_OEM_7: wxk = '\''; break; | |
702c4208 | 6129 | |
5004c3ad | 6130 | // handle extended keys |
413553cc | 6131 | case VK_PRIOR: |
d5c21b02 | 6132 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEUP, WXK_PAGEUP); |
413553cc | 6133 | break; |
d5c21b02 | 6134 | |
413553cc | 6135 | case VK_NEXT: |
d5c21b02 | 6136 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEDOWN, WXK_PAGEDOWN); |
413553cc | 6137 | break; |
d5c21b02 | 6138 | |
413553cc | 6139 | case VK_END: |
d5c21b02 | 6140 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_END, WXK_END); |
413553cc | 6141 | break; |
d5c21b02 | 6142 | |
413553cc | 6143 | case VK_HOME: |
d5c21b02 | 6144 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_HOME, WXK_HOME); |
413553cc | 6145 | break; |
d5c21b02 | 6146 | |
413553cc | 6147 | case VK_LEFT: |
d5c21b02 | 6148 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_LEFT, WXK_LEFT); |
413553cc | 6149 | break; |
d5c21b02 | 6150 | |
413553cc | 6151 | case VK_UP: |
d5c21b02 | 6152 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_UP, WXK_UP); |
413553cc | 6153 | break; |
d5c21b02 | 6154 | |
413553cc | 6155 | case VK_RIGHT: |
d5c21b02 | 6156 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_RIGHT, WXK_RIGHT); |
413553cc | 6157 | break; |
d5c21b02 | 6158 | |
413553cc | 6159 | case VK_DOWN: |
d5c21b02 | 6160 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_DOWN, WXK_DOWN); |
413553cc | 6161 | break; |
d5c21b02 | 6162 | |
413553cc | 6163 | case VK_INSERT: |
d5c21b02 | 6164 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_INSERT, WXK_INSERT); |
413553cc | 6165 | break; |
d5c21b02 | 6166 | |
413553cc | 6167 | case VK_DELETE: |
d5c21b02 | 6168 | wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_DELETE, WXK_DELETE); |
413553cc | 6169 | break; |
d5c21b02 | 6170 | |
ff792344 | 6171 | case VK_RETURN: |
ed5bc8f1 VZ |
6172 | // don't use ChooseNormalOrExtended() here as the keys are reversed |
6173 | // here: numpad enter is the extended one | |
d5c21b02 | 6174 | wxk = lParam && (lParam & (1 << 24)) ? WXK_NUMPAD_ENTER : WXK_RETURN; |
ff792344 VZ |
6175 | break; |
6176 | ||
f6bcfd97 | 6177 | default: |
d5c21b02 VZ |
6178 | wxk = 0; |
6179 | } | |
6180 | ||
6181 | return wxk; | |
6182 | } | |
6183 | ||
4f04a4fd | 6184 | WXWORD wxCharCodeWXToMSW(int wxk) |
d5c21b02 | 6185 | { |
d5c21b02 VZ |
6186 | // check the table first |
6187 | for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ ) | |
6188 | { | |
6189 | if ( gs_specialKeys[n].wxk == wxk ) | |
6190 | return gs_specialKeys[n].vk; | |
6191 | } | |
6192 | ||
6193 | // and then check for special keys not included in the table | |
6194 | WXWORD vk; | |
6195 | switch ( wxk ) | |
6196 | { | |
71403278 VZ |
6197 | case WXK_PAGEUP: |
6198 | case WXK_NUMPAD_PAGEUP: | |
6199 | vk = VK_PRIOR; | |
6200 | break; | |
6201 | ||
6202 | case WXK_PAGEDOWN: | |
6203 | case WXK_NUMPAD_PAGEDOWN: | |
6204 | vk = VK_NEXT; | |
6205 | break; | |
6206 | ||
6207 | case WXK_END: | |
6208 | case WXK_NUMPAD_END: | |
6209 | vk = VK_END; | |
6210 | break; | |
6211 | ||
6212 | case WXK_HOME: | |
6213 | case WXK_NUMPAD_HOME: | |
6214 | vk = VK_HOME; | |
6215 | break; | |
6216 | ||
6217 | case WXK_LEFT: | |
6218 | case WXK_NUMPAD_LEFT: | |
6219 | vk = VK_LEFT; | |
6220 | break; | |
6221 | ||
6222 | case WXK_UP: | |
6223 | case WXK_NUMPAD_UP: | |
6224 | vk = VK_UP; | |
6225 | break; | |
6226 | ||
6227 | case WXK_RIGHT: | |
6228 | case WXK_NUMPAD_RIGHT: | |
6229 | vk = VK_RIGHT; | |
6230 | break; | |
6231 | ||
6232 | case WXK_DOWN: | |
6233 | case WXK_NUMPAD_DOWN: | |
6234 | vk = VK_DOWN; | |
6235 | break; | |
6236 | ||
6237 | case WXK_INSERT: | |
6238 | case WXK_NUMPAD_INSERT: | |
6239 | vk = VK_INSERT; | |
6240 | break; | |
6241 | ||
6242 | case WXK_DELETE: | |
6243 | case WXK_NUMPAD_DELETE: | |
6244 | vk = VK_DELETE; | |
6245 | break; | |
d5c21b02 VZ |
6246 | |
6247 | default: | |
d9fda37b VZ |
6248 | // no VkKeyScan() under CE unfortunately, we need to test how does |
6249 | // it handle OEM keys | |
6250 | #ifndef __WXWINCE__ | |
ad294cb8 VZ |
6251 | // check to see if its one of the OEM key codes. |
6252 | BYTE vks = LOBYTE(VkKeyScan(wxk)); | |
6e3e6c8e | 6253 | if ( vks != 0xff ) |
ad294cb8 VZ |
6254 | { |
6255 | vk = vks; | |
6256 | } | |
6257 | else | |
d9fda37b | 6258 | #endif // !__WXWINCE__ |
ad294cb8 | 6259 | { |
ad294cb8 VZ |
6260 | vk = (WXWORD)wxk; |
6261 | } | |
2bda0e17 | 6262 | } |
d5c21b02 VZ |
6263 | |
6264 | return vk; | |
6265 | } | |
6266 | ||
6267 | // small helper for wxGetKeyState() and wxGetMouseState() | |
6268 | static inline bool wxIsKeyDown(WXWORD vk) | |
6269 | { | |
d9fda37b VZ |
6270 | // SM_SWAPBUTTON is not available under CE, so don't swap buttons there |
6271 | #ifdef SM_SWAPBUTTON | |
6272 | if ( vk == VK_LBUTTON || vk == VK_RBUTTON ) | |
b8f434e7 | 6273 | { |
d9fda37b VZ |
6274 | if ( ::GetSystemMetrics(SM_SWAPBUTTON) ) |
6275 | { | |
6276 | if ( vk == VK_LBUTTON ) | |
6277 | vk = VK_RBUTTON; | |
6278 | else // vk == VK_RBUTTON | |
6279 | vk = VK_LBUTTON; | |
6280 | } | |
b8f434e7 | 6281 | } |
d9fda37b VZ |
6282 | #endif // SM_SWAPBUTTON |
6283 | ||
d5c21b02 VZ |
6284 | // the low order bit indicates whether the key was pressed since the last |
6285 | // call and the high order one indicates whether it is down right now and | |
6286 | // we only want that one | |
b8f434e7 | 6287 | return (GetAsyncKeyState(vk) & (1<<15)) != 0; |
2bda0e17 KB |
6288 | } |
6289 | ||
1751226c | 6290 | bool wxGetKeyState(wxKeyCode key) |
6ed892f3 | 6291 | { |
d5c21b02 VZ |
6292 | // although this does work under Windows, it is not supported under other |
6293 | // platforms so don't allow it, you must use wxGetMouseState() instead | |
6294 | wxASSERT_MSG( key != VK_LBUTTON && | |
6295 | key != VK_RBUTTON && | |
6296 | key != VK_MBUTTON, | |
6297 | wxT("can't use wxGetKeyState() for mouse buttons") ); | |
6ed892f3 | 6298 | |
d5c21b02 | 6299 | const WXWORD vk = wxCharCodeWXToMSW(key); |
44353523 | 6300 | |
d5c21b02 VZ |
6301 | // if the requested key is a LED key, return true if the led is pressed |
6302 | if ( key == WXK_NUMLOCK || key == WXK_CAPITAL || key == WXK_SCROLL ) | |
fdec2c05 | 6303 | { |
d5c21b02 VZ |
6304 | // low order bit means LED is highlighted and high order one means the |
6305 | // key is down; for compatibility with the other ports return true if | |
6306 | // either one is set | |
b8f434e7 | 6307 | return GetKeyState(vk) != 0; |
35bbb0c6 | 6308 | |
fdec2c05 | 6309 | } |
d5c21b02 | 6310 | else // normal key |
84c51ddf | 6311 | { |
d5c21b02 | 6312 | return wxIsKeyDown(vk); |
84c51ddf | 6313 | } |
6ed892f3 RN |
6314 | } |
6315 | ||
7dd40b6f RD |
6316 | |
6317 | wxMouseState wxGetMouseState() | |
6318 | { | |
6319 | wxMouseState ms; | |
6320 | POINT pt; | |
6321 | GetCursorPos( &pt ); | |
6322 | ||
6323 | ms.SetX(pt.x); | |
6324 | ms.SetY(pt.y); | |
d5c21b02 VZ |
6325 | ms.SetLeftDown(wxIsKeyDown(VK_LBUTTON)); |
6326 | ms.SetMiddleDown(wxIsKeyDown(VK_MBUTTON)); | |
6327 | ms.SetRightDown(wxIsKeyDown(VK_RBUTTON)); | |
2f68482e | 6328 | #ifdef wxHAS_XBUTTON |
01101e2d VZ |
6329 | ms.SetAux1Down(wxIsKeyDown(VK_XBUTTON1)); |
6330 | ms.SetAux2Down(wxIsKeyDown(VK_XBUTTON2)); | |
2f68482e | 6331 | #endif // wxHAS_XBUTTON |
dd28827a | 6332 | |
6719c06a VZ |
6333 | ms.SetControlDown(wxIsCtrlDown ()); |
6334 | ms.SetShiftDown (wxIsShiftDown()); | |
6335 | ms.SetAltDown (wxIsAltDown ()); | |
7dd40b6f | 6336 | // ms.SetMetaDown(); |
dd28827a | 6337 | |
7dd40b6f RD |
6338 | return ms; |
6339 | } | |
6340 | ||
6341 | ||
42e69d6b | 6342 | wxWindow *wxGetActiveWindow() |
2bda0e17 | 6343 | { |
42e69d6b VZ |
6344 | HWND hWnd = GetActiveWindow(); |
6345 | if ( hWnd != 0 ) | |
2d0a075d | 6346 | { |
dca0f651 | 6347 | return wxFindWinFromHandle(hWnd); |
2d0a075d | 6348 | } |
42e69d6b | 6349 | return NULL; |
2bda0e17 KB |
6350 | } |
6351 | ||
8614c467 VZ |
6352 | extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd) |
6353 | { | |
6354 | HWND hwnd = (HWND)hWnd; | |
6355 | ||
6356 | // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set | |
6357 | // by code in msw/radiobox.cpp), for all the others we just search up the | |
6358 | // window hierarchy | |
d3b9f782 | 6359 | wxWindow *win = NULL; |
8614c467 VZ |
6360 | if ( hwnd ) |
6361 | { | |
dca0f651 | 6362 | win = wxFindWinFromHandle(hwnd); |
8614c467 VZ |
6363 | if ( !win ) |
6364 | { | |
a2242341 | 6365 | #if wxUSE_RADIOBOX |
8614c467 VZ |
6366 | // native radiobuttons return DLGC_RADIOBUTTON here and for any |
6367 | // wxWindow class which overrides WM_GETDLGCODE processing to | |
6368 | // do it as well, win would be already non NULL | |
a2242341 | 6369 | if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON ) |
8614c467 | 6370 | { |
975b6bcf | 6371 | win = (wxWindow *)wxGetWindowUserData(hwnd); |
8614c467 | 6372 | } |
a2242341 VZ |
6373 | //else: it's a wxRadioButton, not a radiobutton from wxRadioBox |
6374 | #endif // wxUSE_RADIOBOX | |
6375 | ||
6376 | // spin control text buddy window should be mapped to spin ctrl | |
6377 | // itself so try it too | |
24ce4c18 | 6378 | #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__) |
a2242341 VZ |
6379 | if ( !win ) |
6380 | { | |
6381 | win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd); | |
6382 | } | |
6383 | #endif // wxUSE_SPINCTRL | |
8614c467 | 6384 | } |
8614c467 VZ |
6385 | } |
6386 | ||
6387 | while ( hwnd && !win ) | |
6388 | { | |
761989ff VZ |
6389 | // this is a really ugly hack needed to avoid mistakenly returning the |
6390 | // parent frame wxWindow for the find/replace modeless dialog HWND - | |
6391 | // this, in turn, is needed to call IsDialogMessage() from | |
6392 | // wxApp::ProcessMessage() as for this we must return NULL from here | |
6393 | // | |
6394 | // FIXME: this is clearly not the best way to do it but I think we'll | |
6395 | // need to change HWND <-> wxWindow code more heavily than I can | |
6396 | // do it now to fix it | |
c67d6888 | 6397 | #ifndef __WXMICROWIN__ |
761989ff VZ |
6398 | if ( ::GetWindow(hwnd, GW_OWNER) ) |
6399 | { | |
6400 | // it's a dialog box, don't go upwards | |
6401 | break; | |
6402 | } | |
c67d6888 | 6403 | #endif |
761989ff | 6404 | |
8614c467 | 6405 | hwnd = ::GetParent(hwnd); |
dca0f651 | 6406 | win = wxFindWinFromHandle(hwnd); |
8614c467 VZ |
6407 | } |
6408 | ||
6409 | return win; | |
6410 | } | |
6411 | ||
7f0586ef | 6412 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
04ef50df | 6413 | |
42e69d6b VZ |
6414 | // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE |
6415 | // in active frames and dialogs, regardless of where the focus is. | |
6416 | static HHOOK wxTheKeyboardHook = 0; | |
2bda0e17 | 6417 | |
23c26b99 | 6418 | int APIENTRY |
42e69d6b | 6419 | wxKeyboardHook(int nCode, WORD wParam, DWORD lParam) |
2bda0e17 | 6420 | { |
42e69d6b VZ |
6421 | DWORD hiWord = HIWORD(lParam); |
6422 | if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) ) | |
43d811ea | 6423 | { |
ff792344 | 6424 | int id = wxCharCodeMSWToWX(wParam, lParam); |
32de7d24 | 6425 | if ( id != 0 ) |
43d811ea | 6426 | { |
42e69d6b VZ |
6427 | wxKeyEvent event(wxEVT_CHAR_HOOK); |
6428 | if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN ) | |
08158721 | 6429 | event.m_altDown = true; |
c085e333 | 6430 | |
687706f5 | 6431 | event.SetEventObject(NULL); |
42e69d6b | 6432 | event.m_keyCode = id; |
3f7bc32b VZ |
6433 | event.m_shiftDown = wxIsShiftDown(); |
6434 | event.m_controlDown = wxIsCtrlDown(); | |
f0b1ccde | 6435 | #ifndef __WXWINCE__ |
1bf77ee5 | 6436 | event.SetTimestamp(::GetMessageTime()); |
f0b1ccde | 6437 | #endif |
42e69d6b | 6438 | wxWindow *win = wxGetActiveWindow(); |
32de7d24 | 6439 | wxEvtHandler *handler; |
42e69d6b VZ |
6440 | if ( win ) |
6441 | { | |
32de7d24 VZ |
6442 | handler = win->GetEventHandler(); |
6443 | event.SetId(win->GetId()); | |
42e69d6b VZ |
6444 | } |
6445 | else | |
6446 | { | |
32de7d24 | 6447 | handler = wxTheApp; |
abb74e0f | 6448 | event.SetId(wxID_ANY); |
32de7d24 VZ |
6449 | } |
6450 | ||
6451 | if ( handler && handler->ProcessEvent(event) ) | |
6452 | { | |
6453 | // processed | |
6454 | return 1; | |
42e69d6b | 6455 | } |
43d811ea JS |
6456 | } |
6457 | } | |
32de7d24 | 6458 | |
42e69d6b | 6459 | return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam); |
4fabb575 | 6460 | } |
cd4453e5 | 6461 | |
23c26b99 VZ |
6462 | void wxSetKeyboardHook(bool doIt) |
6463 | { | |
6464 | if ( doIt ) | |
6465 | { | |
6466 | wxTheKeyboardHook = ::SetWindowsHookEx | |
6467 | ( | |
6468 | WH_KEYBOARD, | |
6469 | (HOOKPROC)wxKeyboardHook, | |
6470 | NULL, // must be NULL for process hook | |
6471 | ::GetCurrentThreadId() | |
6472 | ); | |
6473 | if ( !wxTheKeyboardHook ) | |
6474 | { | |
9a83f860 | 6475 | wxLogLastError(wxT("SetWindowsHookEx(wxKeyboardHook)")); |
23c26b99 VZ |
6476 | } |
6477 | } | |
6478 | else // uninstall | |
6479 | { | |
6480 | if ( wxTheKeyboardHook ) | |
6481 | ::UnhookWindowsHookEx(wxTheKeyboardHook); | |
6482 | } | |
6483 | } | |
6484 | ||
cd4453e5 | 6485 | #endif // !__WXMICROWIN__ |
4fabb575 | 6486 | |
50e08f9d | 6487 | #if wxDEBUG_LEVEL >= 2 |
4a712ba3 | 6488 | const wxChar *wxGetMessageName(int message) |
47cbd6da | 6489 | { |
42e69d6b VZ |
6490 | switch ( message ) |
6491 | { | |
4a712ba3 VZ |
6492 | case 0x0000: return wxT("WM_NULL"); |
6493 | case 0x0001: return wxT("WM_CREATE"); | |
6494 | case 0x0002: return wxT("WM_DESTROY"); | |
6495 | case 0x0003: return wxT("WM_MOVE"); | |
6496 | case 0x0005: return wxT("WM_SIZE"); | |
6497 | case 0x0006: return wxT("WM_ACTIVATE"); | |
6498 | case 0x0007: return wxT("WM_SETFOCUS"); | |
6499 | case 0x0008: return wxT("WM_KILLFOCUS"); | |
6500 | case 0x000A: return wxT("WM_ENABLE"); | |
6501 | case 0x000B: return wxT("WM_SETREDRAW"); | |
6502 | case 0x000C: return wxT("WM_SETTEXT"); | |
6503 | case 0x000D: return wxT("WM_GETTEXT"); | |
6504 | case 0x000E: return wxT("WM_GETTEXTLENGTH"); | |
6505 | case 0x000F: return wxT("WM_PAINT"); | |
6506 | case 0x0010: return wxT("WM_CLOSE"); | |
6507 | case 0x0011: return wxT("WM_QUERYENDSESSION"); | |
6508 | case 0x0012: return wxT("WM_QUIT"); | |
6509 | case 0x0013: return wxT("WM_QUERYOPEN"); | |
6510 | case 0x0014: return wxT("WM_ERASEBKGND"); | |
6511 | case 0x0015: return wxT("WM_SYSCOLORCHANGE"); | |
6512 | case 0x0016: return wxT("WM_ENDSESSION"); | |
6513 | case 0x0017: return wxT("WM_SYSTEMERROR"); | |
6514 | case 0x0018: return wxT("WM_SHOWWINDOW"); | |
6515 | case 0x0019: return wxT("WM_CTLCOLOR"); | |
6516 | case 0x001A: return wxT("WM_WININICHANGE"); | |
6517 | case 0x001B: return wxT("WM_DEVMODECHANGE"); | |
6518 | case 0x001C: return wxT("WM_ACTIVATEAPP"); | |
6519 | case 0x001D: return wxT("WM_FONTCHANGE"); | |
6520 | case 0x001E: return wxT("WM_TIMECHANGE"); | |
6521 | case 0x001F: return wxT("WM_CANCELMODE"); | |
6522 | case 0x0020: return wxT("WM_SETCURSOR"); | |
6523 | case 0x0021: return wxT("WM_MOUSEACTIVATE"); | |
6524 | case 0x0022: return wxT("WM_CHILDACTIVATE"); | |
6525 | case 0x0023: return wxT("WM_QUEUESYNC"); | |
6526 | case 0x0024: return wxT("WM_GETMINMAXINFO"); | |
6527 | case 0x0026: return wxT("WM_PAINTICON"); | |
6528 | case 0x0027: return wxT("WM_ICONERASEBKGND"); | |
6529 | case 0x0028: return wxT("WM_NEXTDLGCTL"); | |
6530 | case 0x002A: return wxT("WM_SPOOLERSTATUS"); | |
6531 | case 0x002B: return wxT("WM_DRAWITEM"); | |
6532 | case 0x002C: return wxT("WM_MEASUREITEM"); | |
6533 | case 0x002D: return wxT("WM_DELETEITEM"); | |
6534 | case 0x002E: return wxT("WM_VKEYTOITEM"); | |
6535 | case 0x002F: return wxT("WM_CHARTOITEM"); | |
6536 | case 0x0030: return wxT("WM_SETFONT"); | |
6537 | case 0x0031: return wxT("WM_GETFONT"); | |
6538 | case 0x0037: return wxT("WM_QUERYDRAGICON"); | |
6539 | case 0x0039: return wxT("WM_COMPAREITEM"); | |
6540 | case 0x0041: return wxT("WM_COMPACTING"); | |
6541 | case 0x0044: return wxT("WM_COMMNOTIFY"); | |
6542 | case 0x0046: return wxT("WM_WINDOWPOSCHANGING"); | |
6543 | case 0x0047: return wxT("WM_WINDOWPOSCHANGED"); | |
6544 | case 0x0048: return wxT("WM_POWER"); | |
6545 | ||
6546 | case 0x004A: return wxT("WM_COPYDATA"); | |
6547 | case 0x004B: return wxT("WM_CANCELJOURNAL"); | |
6548 | case 0x004E: return wxT("WM_NOTIFY"); | |
6549 | case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST"); | |
6550 | case 0x0051: return wxT("WM_INPUTLANGCHANGE"); | |
6551 | case 0x0052: return wxT("WM_TCARD"); | |
6552 | case 0x0053: return wxT("WM_HELP"); | |
6553 | case 0x0054: return wxT("WM_USERCHANGED"); | |
6554 | case 0x0055: return wxT("WM_NOTIFYFORMAT"); | |
6555 | case 0x007B: return wxT("WM_CONTEXTMENU"); | |
6556 | case 0x007C: return wxT("WM_STYLECHANGING"); | |
6557 | case 0x007D: return wxT("WM_STYLECHANGED"); | |
6558 | case 0x007E: return wxT("WM_DISPLAYCHANGE"); | |
6559 | case 0x007F: return wxT("WM_GETICON"); | |
6560 | case 0x0080: return wxT("WM_SETICON"); | |
6561 | ||
6562 | case 0x0081: return wxT("WM_NCCREATE"); | |
6563 | case 0x0082: return wxT("WM_NCDESTROY"); | |
6564 | case 0x0083: return wxT("WM_NCCALCSIZE"); | |
6565 | case 0x0084: return wxT("WM_NCHITTEST"); | |
6566 | case 0x0085: return wxT("WM_NCPAINT"); | |
6567 | case 0x0086: return wxT("WM_NCACTIVATE"); | |
6568 | case 0x0087: return wxT("WM_GETDLGCODE"); | |
6569 | case 0x00A0: return wxT("WM_NCMOUSEMOVE"); | |
6570 | case 0x00A1: return wxT("WM_NCLBUTTONDOWN"); | |
6571 | case 0x00A2: return wxT("WM_NCLBUTTONUP"); | |
6572 | case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK"); | |
6573 | case 0x00A4: return wxT("WM_NCRBUTTONDOWN"); | |
6574 | case 0x00A5: return wxT("WM_NCRBUTTONUP"); | |
6575 | case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK"); | |
6576 | case 0x00A7: return wxT("WM_NCMBUTTONDOWN"); | |
6577 | case 0x00A8: return wxT("WM_NCMBUTTONUP"); | |
6578 | case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK"); | |
609da8bb VZ |
6579 | |
6580 | case 0x00B0: return wxT("EM_GETSEL"); | |
6581 | case 0x00B1: return wxT("EM_SETSEL"); | |
6582 | case 0x00B2: return wxT("EM_GETRECT"); | |
6583 | case 0x00B3: return wxT("EM_SETRECT"); | |
6584 | case 0x00B4: return wxT("EM_SETRECTNP"); | |
6585 | case 0x00B5: return wxT("EM_SCROLL"); | |
6586 | case 0x00B6: return wxT("EM_LINESCROLL"); | |
6587 | case 0x00B7: return wxT("EM_SCROLLCARET"); | |
6588 | case 0x00B8: return wxT("EM_GETMODIFY"); | |
6589 | case 0x00B9: return wxT("EM_SETMODIFY"); | |
6590 | case 0x00BA: return wxT("EM_GETLINECOUNT"); | |
6591 | case 0x00BB: return wxT("EM_LINEINDEX"); | |
6592 | case 0x00BC: return wxT("EM_SETHANDLE"); | |
6593 | case 0x00BD: return wxT("EM_GETHANDLE"); | |
6594 | case 0x00BE: return wxT("EM_GETTHUMB"); | |
6595 | case 0x00C1: return wxT("EM_LINELENGTH"); | |
6596 | case 0x00C2: return wxT("EM_REPLACESEL"); | |
6597 | case 0x00C4: return wxT("EM_GETLINE"); | |
6598 | case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */ | |
6599 | case 0x00C6: return wxT("EM_CANUNDO"); | |
6600 | case 0x00C7: return wxT("EM_UNDO"); | |
6601 | case 0x00C8: return wxT("EM_FMTLINES"); | |
6602 | case 0x00C9: return wxT("EM_LINEFROMCHAR"); | |
6603 | case 0x00CB: return wxT("EM_SETTABSTOPS"); | |
6604 | case 0x00CC: return wxT("EM_SETPASSWORDCHAR"); | |
6605 | case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER"); | |
6606 | case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE"); | |
6607 | case 0x00CF: return wxT("EM_SETREADONLY"); | |
6608 | case 0x00D0: return wxT("EM_SETWORDBREAKPROC"); | |
6609 | case 0x00D1: return wxT("EM_GETWORDBREAKPROC"); | |
6610 | case 0x00D2: return wxT("EM_GETPASSWORDCHAR"); | |
6611 | case 0x00D3: return wxT("EM_SETMARGINS"); | |
6612 | case 0x00D4: return wxT("EM_GETMARGINS"); | |
6613 | case 0x00D5: return wxT("EM_GETLIMITTEXT"); | |
6614 | case 0x00D6: return wxT("EM_POSFROMCHAR"); | |
6615 | case 0x00D7: return wxT("EM_CHARFROMPOS"); | |
6616 | case 0x00D8: return wxT("EM_SETIMESTATUS"); | |
6617 | case 0x00D9: return wxT("EM_GETIMESTATUS"); | |
6618 | ||
4a712ba3 VZ |
6619 | case 0x0100: return wxT("WM_KEYDOWN"); |
6620 | case 0x0101: return wxT("WM_KEYUP"); | |
6621 | case 0x0102: return wxT("WM_CHAR"); | |
6622 | case 0x0103: return wxT("WM_DEADCHAR"); | |
6623 | case 0x0104: return wxT("WM_SYSKEYDOWN"); | |
6624 | case 0x0105: return wxT("WM_SYSKEYUP"); | |
6625 | case 0x0106: return wxT("WM_SYSCHAR"); | |
6626 | case 0x0107: return wxT("WM_SYSDEADCHAR"); | |
6627 | case 0x0108: return wxT("WM_KEYLAST"); | |
6628 | ||
6629 | case 0x010D: return wxT("WM_IME_STARTCOMPOSITION"); | |
6630 | case 0x010E: return wxT("WM_IME_ENDCOMPOSITION"); | |
6631 | case 0x010F: return wxT("WM_IME_COMPOSITION"); | |
6632 | ||
6633 | case 0x0110: return wxT("WM_INITDIALOG"); | |
6634 | case 0x0111: return wxT("WM_COMMAND"); | |
6635 | case 0x0112: return wxT("WM_SYSCOMMAND"); | |
6636 | case 0x0113: return wxT("WM_TIMER"); | |
6637 | case 0x0114: return wxT("WM_HSCROLL"); | |
6638 | case 0x0115: return wxT("WM_VSCROLL"); | |
6639 | case 0x0116: return wxT("WM_INITMENU"); | |
6640 | case 0x0117: return wxT("WM_INITMENUPOPUP"); | |
6641 | case 0x011F: return wxT("WM_MENUSELECT"); | |
6642 | case 0x0120: return wxT("WM_MENUCHAR"); | |
6643 | case 0x0121: return wxT("WM_ENTERIDLE"); | |
609da8bb | 6644 | |
ff9b9665 VZ |
6645 | case 0x0127: return wxT("WM_CHANGEUISTATE"); |
6646 | case 0x0128: return wxT("WM_UPDATEUISTATE"); | |
6647 | case 0x0129: return wxT("WM_QUERYUISTATE"); | |
6648 | ||
609da8bb VZ |
6649 | case 0x0132: return wxT("WM_CTLCOLORMSGBOX"); |
6650 | case 0x0133: return wxT("WM_CTLCOLOREDIT"); | |
6651 | case 0x0134: return wxT("WM_CTLCOLORLISTBOX"); | |
6652 | case 0x0135: return wxT("WM_CTLCOLORBTN"); | |
6653 | case 0x0136: return wxT("WM_CTLCOLORDLG"); | |
6654 | case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR"); | |
6655 | case 0x0138: return wxT("WM_CTLCOLORSTATIC"); | |
6656 | case 0x01E1: return wxT("MN_GETHMENU"); | |
6657 | ||
4a712ba3 VZ |
6658 | case 0x0200: return wxT("WM_MOUSEMOVE"); |
6659 | case 0x0201: return wxT("WM_LBUTTONDOWN"); | |
6660 | case 0x0202: return wxT("WM_LBUTTONUP"); | |
6661 | case 0x0203: return wxT("WM_LBUTTONDBLCLK"); | |
6662 | case 0x0204: return wxT("WM_RBUTTONDOWN"); | |
6663 | case 0x0205: return wxT("WM_RBUTTONUP"); | |
6664 | case 0x0206: return wxT("WM_RBUTTONDBLCLK"); | |
6665 | case 0x0207: return wxT("WM_MBUTTONDOWN"); | |
6666 | case 0x0208: return wxT("WM_MBUTTONUP"); | |
6667 | case 0x0209: return wxT("WM_MBUTTONDBLCLK"); | |
6668 | case 0x020A: return wxT("WM_MOUSEWHEEL"); | |
01101e2d VZ |
6669 | case 0x020B: return wxT("WM_XBUTTONDOWN"); |
6670 | case 0x020C: return wxT("WM_XBUTTONUP"); | |
6671 | case 0x020D: return wxT("WM_XBUTTONDBLCLK"); | |
4a712ba3 VZ |
6672 | case 0x0210: return wxT("WM_PARENTNOTIFY"); |
6673 | case 0x0211: return wxT("WM_ENTERMENULOOP"); | |
6674 | case 0x0212: return wxT("WM_EXITMENULOOP"); | |
6675 | ||
6676 | case 0x0213: return wxT("WM_NEXTMENU"); | |
6677 | case 0x0214: return wxT("WM_SIZING"); | |
6678 | case 0x0215: return wxT("WM_CAPTURECHANGED"); | |
6679 | case 0x0216: return wxT("WM_MOVING"); | |
6680 | case 0x0218: return wxT("WM_POWERBROADCAST"); | |
6681 | case 0x0219: return wxT("WM_DEVICECHANGE"); | |
6682 | ||
6683 | case 0x0220: return wxT("WM_MDICREATE"); | |
6684 | case 0x0221: return wxT("WM_MDIDESTROY"); | |
6685 | case 0x0222: return wxT("WM_MDIACTIVATE"); | |
6686 | case 0x0223: return wxT("WM_MDIRESTORE"); | |
6687 | case 0x0224: return wxT("WM_MDINEXT"); | |
6688 | case 0x0225: return wxT("WM_MDIMAXIMIZE"); | |
6689 | case 0x0226: return wxT("WM_MDITILE"); | |
6690 | case 0x0227: return wxT("WM_MDICASCADE"); | |
6691 | case 0x0228: return wxT("WM_MDIICONARRANGE"); | |
6692 | case 0x0229: return wxT("WM_MDIGETACTIVE"); | |
6693 | case 0x0230: return wxT("WM_MDISETMENU"); | |
6694 | case 0x0233: return wxT("WM_DROPFILES"); | |
6695 | ||
6696 | case 0x0281: return wxT("WM_IME_SETCONTEXT"); | |
6697 | case 0x0282: return wxT("WM_IME_NOTIFY"); | |
6698 | case 0x0283: return wxT("WM_IME_CONTROL"); | |
6699 | case 0x0284: return wxT("WM_IME_COMPOSITIONFULL"); | |
6700 | case 0x0285: return wxT("WM_IME_SELECT"); | |
6701 | case 0x0286: return wxT("WM_IME_CHAR"); | |
6702 | case 0x0290: return wxT("WM_IME_KEYDOWN"); | |
6703 | case 0x0291: return wxT("WM_IME_KEYUP"); | |
6704 | ||
609da8bb VZ |
6705 | case 0x02A0: return wxT("WM_NCMOUSEHOVER"); |
6706 | case 0x02A1: return wxT("WM_MOUSEHOVER"); | |
6707 | case 0x02A2: return wxT("WM_NCMOUSELEAVE"); | |
6708 | case 0x02A3: return wxT("WM_MOUSELEAVE"); | |
6709 | ||
4a712ba3 VZ |
6710 | case 0x0300: return wxT("WM_CUT"); |
6711 | case 0x0301: return wxT("WM_COPY"); | |
6712 | case 0x0302: return wxT("WM_PASTE"); | |
6713 | case 0x0303: return wxT("WM_CLEAR"); | |
6714 | case 0x0304: return wxT("WM_UNDO"); | |
6715 | case 0x0305: return wxT("WM_RENDERFORMAT"); | |
6716 | case 0x0306: return wxT("WM_RENDERALLFORMATS"); | |
6717 | case 0x0307: return wxT("WM_DESTROYCLIPBOARD"); | |
6718 | case 0x0308: return wxT("WM_DRAWCLIPBOARD"); | |
6719 | case 0x0309: return wxT("WM_PAINTCLIPBOARD"); | |
6720 | case 0x030A: return wxT("WM_VSCROLLCLIPBOARD"); | |
6721 | case 0x030B: return wxT("WM_SIZECLIPBOARD"); | |
6722 | case 0x030C: return wxT("WM_ASKCBFORMATNAME"); | |
6723 | case 0x030D: return wxT("WM_CHANGECBCHAIN"); | |
6724 | case 0x030E: return wxT("WM_HSCROLLCLIPBOARD"); | |
6725 | case 0x030F: return wxT("WM_QUERYNEWPALETTE"); | |
6726 | case 0x0310: return wxT("WM_PALETTEISCHANGING"); | |
6727 | case 0x0311: return wxT("WM_PALETTECHANGED"); | |
4a712ba3 | 6728 | case 0x0312: return wxT("WM_HOTKEY"); |
609da8bb VZ |
6729 | |
6730 | case 0x0317: return wxT("WM_PRINT"); | |
6731 | case 0x0318: return wxT("WM_PRINTCLIENT"); | |
c085e333 | 6732 | |
2d0a075d JS |
6733 | // common controls messages - although they're not strictly speaking |
6734 | // standard, it's nice to decode them nevertheless | |
a02eb1d2 | 6735 | |
2d0a075d | 6736 | // listview |
4a712ba3 VZ |
6737 | case 0x1000 + 0: return wxT("LVM_GETBKCOLOR"); |
6738 | case 0x1000 + 1: return wxT("LVM_SETBKCOLOR"); | |
6739 | case 0x1000 + 2: return wxT("LVM_GETIMAGELIST"); | |
6740 | case 0x1000 + 3: return wxT("LVM_SETIMAGELIST"); | |
6741 | case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT"); | |
6742 | case 0x1000 + 5: return wxT("LVM_GETITEMA"); | |
6743 | case 0x1000 + 75: return wxT("LVM_GETITEMW"); | |
6744 | case 0x1000 + 6: return wxT("LVM_SETITEMA"); | |
6745 | case 0x1000 + 76: return wxT("LVM_SETITEMW"); | |
6746 | case 0x1000 + 7: return wxT("LVM_INSERTITEMA"); | |
6747 | case 0x1000 + 77: return wxT("LVM_INSERTITEMW"); | |
6748 | case 0x1000 + 8: return wxT("LVM_DELETEITEM"); | |
6749 | case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS"); | |
6750 | case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK"); | |
6751 | case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK"); | |
6752 | case 0x1000 + 12: return wxT("LVM_GETNEXTITEM"); | |
6753 | case 0x1000 + 13: return wxT("LVM_FINDITEMA"); | |
6754 | case 0x1000 + 83: return wxT("LVM_FINDITEMW"); | |
6755 | case 0x1000 + 14: return wxT("LVM_GETITEMRECT"); | |
6756 | case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION"); | |
6757 | case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION"); | |
6758 | case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA"); | |
6759 | case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW"); | |
6760 | case 0x1000 + 18: return wxT("LVM_HITTEST"); | |
6761 | case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE"); | |
6762 | case 0x1000 + 20: return wxT("LVM_SCROLL"); | |
6763 | case 0x1000 + 21: return wxT("LVM_REDRAWITEMS"); | |
6764 | case 0x1000 + 22: return wxT("LVM_ARRANGE"); | |
6765 | case 0x1000 + 23: return wxT("LVM_EDITLABELA"); | |
6766 | case 0x1000 + 118: return wxT("LVM_EDITLABELW"); | |
6767 | case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL"); | |
6768 | case 0x1000 + 25: return wxT("LVM_GETCOLUMNA"); | |
6769 | case 0x1000 + 95: return wxT("LVM_GETCOLUMNW"); | |
6770 | case 0x1000 + 26: return wxT("LVM_SETCOLUMNA"); | |
6771 | case 0x1000 + 96: return wxT("LVM_SETCOLUMNW"); | |
6772 | case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA"); | |
6773 | case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW"); | |
6774 | case 0x1000 + 28: return wxT("LVM_DELETECOLUMN"); | |
6775 | case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH"); | |
6776 | case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH"); | |
6777 | case 0x1000 + 31: return wxT("LVM_GETHEADER"); | |
6778 | case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE"); | |
6779 | case 0x1000 + 34: return wxT("LVM_GETVIEWRECT"); | |
6780 | case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR"); | |
6781 | case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR"); | |
6782 | case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR"); | |
6783 | case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR"); | |
6784 | case 0x1000 + 39: return wxT("LVM_GETTOPINDEX"); | |
6785 | case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE"); | |
6786 | case 0x1000 + 41: return wxT("LVM_GETORIGIN"); | |
6787 | case 0x1000 + 42: return wxT("LVM_UPDATE"); | |
6788 | case 0x1000 + 43: return wxT("LVM_SETITEMSTATE"); | |
6789 | case 0x1000 + 44: return wxT("LVM_GETITEMSTATE"); | |
6790 | case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA"); | |
6791 | case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW"); | |
6792 | case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA"); | |
6793 | case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW"); | |
6794 | case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT"); | |
6795 | case 0x1000 + 48: return wxT("LVM_SORTITEMS"); | |
6796 | case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32"); | |
6797 | case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT"); | |
6798 | case 0x1000 + 51: return wxT("LVM_GETITEMSPACING"); | |
6799 | case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA"); | |
6800 | case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW"); | |
6801 | case 0x1000 + 53: return wxT("LVM_SETICONSPACING"); | |
6802 | case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE"); | |
6803 | case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE"); | |
6804 | case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT"); | |
6805 | case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST"); | |
6806 | case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY"); | |
6807 | case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY"); | |
6808 | case 0x1000 + 60: return wxT("LVM_SETHOTITEM"); | |
6809 | case 0x1000 + 61: return wxT("LVM_GETHOTITEM"); | |
6810 | case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR"); | |
6811 | case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR"); | |
6812 | case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT"); | |
6813 | case 0x1000 + 65: return wxT("LVM_SETWORKAREA"); | |
c085e333 | 6814 | |
2d0a075d | 6815 | // tree view |
4a712ba3 VZ |
6816 | case 0x1100 + 0: return wxT("TVM_INSERTITEMA"); |
6817 | case 0x1100 + 50: return wxT("TVM_INSERTITEMW"); | |
6818 | case 0x1100 + 1: return wxT("TVM_DELETEITEM"); | |
6819 | case 0x1100 + 2: return wxT("TVM_EXPAND"); | |
6820 | case 0x1100 + 4: return wxT("TVM_GETITEMRECT"); | |
6821 | case 0x1100 + 5: return wxT("TVM_GETCOUNT"); | |
6822 | case 0x1100 + 6: return wxT("TVM_GETINDENT"); | |
6823 | case 0x1100 + 7: return wxT("TVM_SETINDENT"); | |
6824 | case 0x1100 + 8: return wxT("TVM_GETIMAGELIST"); | |
6825 | case 0x1100 + 9: return wxT("TVM_SETIMAGELIST"); | |
6826 | case 0x1100 + 10: return wxT("TVM_GETNEXTITEM"); | |
6827 | case 0x1100 + 11: return wxT("TVM_SELECTITEM"); | |
6828 | case 0x1100 + 12: return wxT("TVM_GETITEMA"); | |
6829 | case 0x1100 + 62: return wxT("TVM_GETITEMW"); | |
6830 | case 0x1100 + 13: return wxT("TVM_SETITEMA"); | |
6831 | case 0x1100 + 63: return wxT("TVM_SETITEMW"); | |
6832 | case 0x1100 + 14: return wxT("TVM_EDITLABELA"); | |
6833 | case 0x1100 + 65: return wxT("TVM_EDITLABELW"); | |
6834 | case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL"); | |
6835 | case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT"); | |
6836 | case 0x1100 + 17: return wxT("TVM_HITTEST"); | |
6837 | case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE"); | |
6838 | case 0x1100 + 19: return wxT("TVM_SORTCHILDREN"); | |
6839 | case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE"); | |
6840 | case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB"); | |
6841 | case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW"); | |
6842 | case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA"); | |
6843 | case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW"); | |
6844 | case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS"); | |
6845 | case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS"); | |
c085e333 | 6846 | |
2d0a075d | 6847 | // header |
4a712ba3 VZ |
6848 | case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT"); |
6849 | case 0x1200 + 1: return wxT("HDM_INSERTITEMA"); | |
6850 | case 0x1200 + 10: return wxT("HDM_INSERTITEMW"); | |
6851 | case 0x1200 + 2: return wxT("HDM_DELETEITEM"); | |
6852 | case 0x1200 + 3: return wxT("HDM_GETITEMA"); | |
6853 | case 0x1200 + 11: return wxT("HDM_GETITEMW"); | |
6854 | case 0x1200 + 4: return wxT("HDM_SETITEMA"); | |
6855 | case 0x1200 + 12: return wxT("HDM_SETITEMW"); | |
6856 | case 0x1200 + 5: return wxT("HDM_LAYOUT"); | |
6857 | case 0x1200 + 6: return wxT("HDM_HITTEST"); | |
6858 | case 0x1200 + 7: return wxT("HDM_GETITEMRECT"); | |
6859 | case 0x1200 + 8: return wxT("HDM_SETIMAGELIST"); | |
6860 | case 0x1200 + 9: return wxT("HDM_GETIMAGELIST"); | |
6861 | case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX"); | |
6862 | case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE"); | |
6863 | case 0x1200 + 17: return wxT("HDM_GETORDERARRAY"); | |
6864 | case 0x1200 + 18: return wxT("HDM_SETORDERARRAY"); | |
6865 | case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER"); | |
c085e333 | 6866 | |
2d0a075d | 6867 | // tab control |
4a712ba3 VZ |
6868 | case 0x1300 + 2: return wxT("TCM_GETIMAGELIST"); |
6869 | case 0x1300 + 3: return wxT("TCM_SETIMAGELIST"); | |
6870 | case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT"); | |
6871 | case 0x1300 + 5: return wxT("TCM_GETITEMA"); | |
6872 | case 0x1300 + 60: return wxT("TCM_GETITEMW"); | |
6873 | case 0x1300 + 6: return wxT("TCM_SETITEMA"); | |
6874 | case 0x1300 + 61: return wxT("TCM_SETITEMW"); | |
6875 | case 0x1300 + 7: return wxT("TCM_INSERTITEMA"); | |
6876 | case 0x1300 + 62: return wxT("TCM_INSERTITEMW"); | |
6877 | case 0x1300 + 8: return wxT("TCM_DELETEITEM"); | |
6878 | case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS"); | |
6879 | case 0x1300 + 10: return wxT("TCM_GETITEMRECT"); | |
6880 | case 0x1300 + 11: return wxT("TCM_GETCURSEL"); | |
6881 | case 0x1300 + 12: return wxT("TCM_SETCURSEL"); | |
6882 | case 0x1300 + 13: return wxT("TCM_HITTEST"); | |
6883 | case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA"); | |
6884 | case 0x1300 + 40: return wxT("TCM_ADJUSTRECT"); | |
6885 | case 0x1300 + 41: return wxT("TCM_SETITEMSIZE"); | |
6886 | case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE"); | |
6887 | case 0x1300 + 43: return wxT("TCM_SETPADDING"); | |
6888 | case 0x1300 + 44: return wxT("TCM_GETROWCOUNT"); | |
6889 | case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS"); | |
6890 | case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS"); | |
6891 | case 0x1300 + 47: return wxT("TCM_GETCURFOCUS"); | |
6892 | case 0x1300 + 48: return wxT("TCM_SETCURFOCUS"); | |
6893 | case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH"); | |
6894 | case 0x1300 + 50: return wxT("TCM_DESELECTALL"); | |
c085e333 | 6895 | |
2d0a075d | 6896 | // toolbar |
4a712ba3 VZ |
6897 | case WM_USER+1: return wxT("TB_ENABLEBUTTON"); |
6898 | case WM_USER+2: return wxT("TB_CHECKBUTTON"); | |
6899 | case WM_USER+3: return wxT("TB_PRESSBUTTON"); | |
6900 | case WM_USER+4: return wxT("TB_HIDEBUTTON"); | |
6901 | case WM_USER+5: return wxT("TB_INDETERMINATE"); | |
6902 | case WM_USER+9: return wxT("TB_ISBUTTONENABLED"); | |
6903 | case WM_USER+10: return wxT("TB_ISBUTTONCHECKED"); | |
6904 | case WM_USER+11: return wxT("TB_ISBUTTONPRESSED"); | |
6905 | case WM_USER+12: return wxT("TB_ISBUTTONHIDDEN"); | |
6906 | case WM_USER+13: return wxT("TB_ISBUTTONINDETERMINATE"); | |
6907 | case WM_USER+17: return wxT("TB_SETSTATE"); | |
6908 | case WM_USER+18: return wxT("TB_GETSTATE"); | |
6909 | case WM_USER+19: return wxT("TB_ADDBITMAP"); | |
6910 | case WM_USER+20: return wxT("TB_ADDBUTTONS"); | |
6911 | case WM_USER+21: return wxT("TB_INSERTBUTTON"); | |
6912 | case WM_USER+22: return wxT("TB_DELETEBUTTON"); | |
6913 | case WM_USER+23: return wxT("TB_GETBUTTON"); | |
6914 | case WM_USER+24: return wxT("TB_BUTTONCOUNT"); | |
6915 | case WM_USER+25: return wxT("TB_COMMANDTOINDEX"); | |
6916 | case WM_USER+26: return wxT("TB_SAVERESTOREA"); | |
6917 | case WM_USER+76: return wxT("TB_SAVERESTOREW"); | |
6918 | case WM_USER+27: return wxT("TB_CUSTOMIZE"); | |
6919 | case WM_USER+28: return wxT("TB_ADDSTRINGA"); | |
6920 | case WM_USER+77: return wxT("TB_ADDSTRINGW"); | |
6921 | case WM_USER+29: return wxT("TB_GETITEMRECT"); | |
6922 | case WM_USER+30: return wxT("TB_BUTTONSTRUCTSIZE"); | |
6923 | case WM_USER+31: return wxT("TB_SETBUTTONSIZE"); | |
6924 | case WM_USER+32: return wxT("TB_SETBITMAPSIZE"); | |
6925 | case WM_USER+33: return wxT("TB_AUTOSIZE"); | |
6926 | case WM_USER+35: return wxT("TB_GETTOOLTIPS"); | |
6927 | case WM_USER+36: return wxT("TB_SETTOOLTIPS"); | |
6928 | case WM_USER+37: return wxT("TB_SETPARENT"); | |
6929 | case WM_USER+39: return wxT("TB_SETROWS"); | |
6930 | case WM_USER+40: return wxT("TB_GETROWS"); | |
6931 | case WM_USER+42: return wxT("TB_SETCMDID"); | |
6932 | case WM_USER+43: return wxT("TB_CHANGEBITMAP"); | |
6933 | case WM_USER+44: return wxT("TB_GETBITMAP"); | |
6934 | case WM_USER+45: return wxT("TB_GETBUTTONTEXTA"); | |
6935 | case WM_USER+75: return wxT("TB_GETBUTTONTEXTW"); | |
6936 | case WM_USER+46: return wxT("TB_REPLACEBITMAP"); | |
6937 | case WM_USER+47: return wxT("TB_SETINDENT"); | |
6938 | case WM_USER+48: return wxT("TB_SETIMAGELIST"); | |
6939 | case WM_USER+49: return wxT("TB_GETIMAGELIST"); | |
6940 | case WM_USER+50: return wxT("TB_LOADIMAGES"); | |
6941 | case WM_USER+51: return wxT("TB_GETRECT"); | |
6942 | case WM_USER+52: return wxT("TB_SETHOTIMAGELIST"); | |
6943 | case WM_USER+53: return wxT("TB_GETHOTIMAGELIST"); | |
6944 | case WM_USER+54: return wxT("TB_SETDISABLEDIMAGELIST"); | |
6945 | case WM_USER+55: return wxT("TB_GETDISABLEDIMAGELIST"); | |
6946 | case WM_USER+56: return wxT("TB_SETSTYLE"); | |
6947 | case WM_USER+57: return wxT("TB_GETSTYLE"); | |
6948 | case WM_USER+58: return wxT("TB_GETBUTTONSIZE"); | |
6949 | case WM_USER+59: return wxT("TB_SETBUTTONWIDTH"); | |
6950 | case WM_USER+60: return wxT("TB_SETMAXTEXTROWS"); | |
6951 | case WM_USER+61: return wxT("TB_GETTEXTROWS"); | |
6952 | case WM_USER+41: return wxT("TB_GETBITMAPFLAGS"); | |
c085e333 | 6953 | |
42e69d6b | 6954 | default: |
4a712ba3 VZ |
6955 | static wxString s_szBuf; |
6956 | s_szBuf.Printf(wxT("<unknown message = %d>"), message); | |
6957 | return s_szBuf.c_str(); | |
42e69d6b | 6958 | } |
47cbd6da | 6959 | } |
4b6a582b | 6960 | #endif // wxDEBUG_LEVEL >= 2 |
4aff28fc | 6961 | |
1e6feb95 | 6962 | static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win) |
f6bcfd97 BP |
6963 | { |
6964 | // prepare the DC | |
6965 | TEXTMETRIC tm; | |
6966 | HWND hwnd = GetHwndOf(win); | |
6967 | HDC hdc = ::GetDC(hwnd); | |
6968 | ||
6969 | #if !wxDIALOG_UNIT_COMPATIBILITY | |
6970 | // and select the current font into it | |
6971 | HFONT hfont = GetHfontOf(win->GetFont()); | |
6972 | if ( hfont ) | |
6973 | { | |
6974 | hfont = (HFONT)::SelectObject(hdc, hfont); | |
6975 | } | |
6976 | #endif | |
6977 | ||
6978 | // finally retrieve the text metrics from it | |
6979 | GetTextMetrics(hdc, &tm); | |
6980 | ||
6981 | #if !wxDIALOG_UNIT_COMPATIBILITY | |
6982 | // and clean up | |
6983 | if ( hfont ) | |
6984 | { | |
6985 | (void)::SelectObject(hdc, hfont); | |
6986 | } | |
6987 | #endif | |
6988 | ||
6989 | ::ReleaseDC(hwnd, hdc); | |
6990 | ||
6991 | return tm; | |
6992 | } | |
3723b7b1 JS |
6993 | |
6994 | // Find the wxWindow at the current mouse position, returning the mouse | |
6995 | // position. | |
2b5f62a0 | 6996 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) |
3723b7b1 | 6997 | { |
2b5f62a0 VZ |
6998 | pt = wxGetMousePosition(); |
6999 | return wxFindWindowAtPoint(pt); | |
57591e0e JS |
7000 | } |
7001 | ||
7002 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) | |
7003 | { | |
7004 | POINT pt2; | |
7005 | pt2.x = pt.x; | |
7006 | pt2.y = pt.y; | |
3723b7b1 | 7007 | |
ab3eae34 | 7008 | HWND hWnd = ::WindowFromPoint(pt2); |
3723b7b1 | 7009 | |
ab3eae34 | 7010 | return wxGetWindowFromHWND((WXHWND)hWnd); |
3723b7b1 JS |
7011 | } |
7012 | ||
7013 | // Get the current mouse position. | |
7014 | wxPoint wxGetMousePosition() | |
7015 | { | |
1772ead0 | 7016 | POINT pt; |
f2325516 JS |
7017 | #ifdef __WXWINCE__ |
7018 | GetCursorPosWinCE(&pt); | |
7019 | #else | |
1772ead0 | 7020 | GetCursorPos( & pt ); |
f2325516 | 7021 | #endif |
5cd16c0c | 7022 | |
1772ead0 | 7023 | return wxPoint(pt.x, pt.y); |
3723b7b1 JS |
7024 | } |
7025 | ||
5048c832 | 7026 | #if wxUSE_HOTKEY |
540b6b09 | 7027 | |
afafd942 JS |
7028 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
7029 | static void WinCEUnregisterHotKey(int modifiers, int id) | |
7030 | { | |
7031 | // Register hotkeys for the hardware buttons | |
7032 | HINSTANCE hCoreDll; | |
7033 | typedef BOOL (WINAPI *UnregisterFunc1Proc)(UINT, UINT); | |
7034 | ||
7035 | UnregisterFunc1Proc procUnregisterFunc; | |
9a83f860 | 7036 | hCoreDll = LoadLibrary(wxT("coredll.dll")); |
afafd942 JS |
7037 | if (hCoreDll) |
7038 | { | |
9a83f860 | 7039 | procUnregisterFunc = (UnregisterFunc1Proc)GetProcAddress(hCoreDll, wxT("UnregisterFunc1")); |
afafd942 JS |
7040 | if (procUnregisterFunc) |
7041 | procUnregisterFunc(modifiers, id); | |
7042 | FreeLibrary(hCoreDll); | |
7043 | } | |
7044 | } | |
7045 | #endif | |
7046 | ||
540b6b09 | 7047 | bool wxWindowMSW::RegisterHotKey(int hotkeyId, int modifiers, int keycode) |
5048c832 JS |
7048 | { |
7049 | UINT win_modifiers=0; | |
540b6b09 VZ |
7050 | if ( modifiers & wxMOD_ALT ) |
7051 | win_modifiers |= MOD_ALT; | |
7052 | if ( modifiers & wxMOD_SHIFT ) | |
7053 | win_modifiers |= MOD_SHIFT; | |
7054 | if ( modifiers & wxMOD_CONTROL ) | |
7055 | win_modifiers |= MOD_CONTROL; | |
7056 | if ( modifiers & wxMOD_WIN ) | |
7057 | win_modifiers |= MOD_WIN; | |
7058 | ||
afafd942 JS |
7059 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
7060 | // Required for PPC and Smartphone hardware buttons | |
7061 | if (keycode >= WXK_SPECIAL1 && keycode <= WXK_SPECIAL20) | |
7062 | WinCEUnregisterHotKey(win_modifiers, hotkeyId); | |
7063 | #endif | |
7064 | ||
540b6b09 VZ |
7065 | if ( !::RegisterHotKey(GetHwnd(), hotkeyId, win_modifiers, keycode) ) |
7066 | { | |
9a83f860 | 7067 | wxLogLastError(wxT("RegisterHotKey")); |
5048c832 | 7068 | |
08158721 | 7069 | return false; |
540b6b09 VZ |
7070 | } |
7071 | ||
08158721 | 7072 | return true; |
5048c832 JS |
7073 | } |
7074 | ||
7075 | bool wxWindowMSW::UnregisterHotKey(int hotkeyId) | |
7076 | { | |
afafd942 JS |
7077 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
7078 | WinCEUnregisterHotKey(MOD_WIN, hotkeyId); | |
7079 | #endif | |
7080 | ||
540b6b09 VZ |
7081 | if ( !::UnregisterHotKey(GetHwnd(), hotkeyId) ) |
7082 | { | |
9a83f860 | 7083 | wxLogLastError(wxT("UnregisterHotKey")); |
540b6b09 | 7084 | |
08158721 | 7085 | return false; |
540b6b09 VZ |
7086 | } |
7087 | ||
08158721 | 7088 | return true; |
5048c832 JS |
7089 | } |
7090 | ||
0b4f47a3 DS |
7091 | #if wxUSE_ACCEL |
7092 | ||
5048c832 JS |
7093 | bool wxWindowMSW::HandleHotKey(WXWPARAM wParam, WXLPARAM lParam) |
7094 | { | |
540b6b09 VZ |
7095 | int hotkeyId = wParam; |
7096 | int virtualKey = HIWORD(lParam); | |
7097 | int win_modifiers = LOWORD(lParam); | |
7098 | ||
5048c832 JS |
7099 | wxKeyEvent event(CreateKeyEvent(wxEVT_HOTKEY, virtualKey, wParam, lParam)); |
7100 | event.SetId(hotkeyId); | |
7101 | event.m_shiftDown = (win_modifiers & MOD_SHIFT) != 0; | |
7102 | event.m_controlDown = (win_modifiers & MOD_CONTROL) != 0; | |
7103 | event.m_altDown = (win_modifiers & MOD_ALT) != 0; | |
7104 | event.m_metaDown = (win_modifiers & MOD_WIN) != 0; | |
540b6b09 | 7105 | |
937013e0 | 7106 | return HandleWindowEvent(event); |
5048c832 | 7107 | } |
540b6b09 | 7108 | |
0b4f47a3 DS |
7109 | #endif // wxUSE_ACCEL |
7110 | ||
540b6b09 | 7111 | #endif // wxUSE_HOTKEY |
5048c832 | 7112 | |
550049c2 | 7113 | // Not tested under WinCE |
d79df32c | 7114 | #ifndef __WXWINCE__ |
d79df32c | 7115 | |
550049c2 VZ |
7116 | // this class installs a message hook which really wakes up our idle processing |
7117 | // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're | |
7118 | // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is | |
7119 | // being dragged or even inside ::MessageBox()) and so don't control message | |
7120 | // dispatching otherwise | |
7121 | class wxIdleWakeUpModule : public wxModule | |
7122 | { | |
d79df32c | 7123 | public: |
3a3c8603 | 7124 | virtual bool OnInit() |
550049c2 | 7125 | { |
3a3c8603 | 7126 | ms_hMsgHookProc = ::SetWindowsHookEx |
550049c2 VZ |
7127 | ( |
7128 | WH_GETMESSAGE, | |
7129 | &wxIdleWakeUpModule::MsgHookProc, | |
7130 | NULL, | |
7131 | GetCurrentThreadId() | |
7132 | ); | |
d79df32c | 7133 | |
550049c2 VZ |
7134 | if ( !ms_hMsgHookProc ) |
7135 | { | |
9a83f860 | 7136 | wxLogLastError(wxT("SetWindowsHookEx(WH_GETMESSAGE)")); |
550049c2 VZ |
7137 | |
7138 | return false; | |
7139 | } | |
7140 | ||
7141 | return true; | |
3a3c8603 | 7142 | } |
550049c2 | 7143 | |
3a3c8603 | 7144 | virtual void OnExit() |
550049c2 | 7145 | { |
3a3c8603 DS |
7146 | ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc); |
7147 | } | |
550049c2 | 7148 | |
3a3c8603 | 7149 | static LRESULT CALLBACK MsgHookProc(int nCode, WPARAM wParam, LPARAM lParam) |
550049c2 | 7150 | { |
3a3c8603 | 7151 | MSG *msg = (MSG*)lParam; |
34ea3c74 VZ |
7152 | |
7153 | // only process the message if it is actually going to be removed from | |
7154 | // the message queue, this prevents that the same event from being | |
7155 | // processed multiple times if now someone just called PeekMessage() | |
7156 | if ( msg->message == WM_NULL && wParam == PM_REMOVE ) | |
3a3c8603 | 7157 | { |
550049c2 | 7158 | wxTheApp->ProcessPendingEvents(); |
3a3c8603 | 7159 | } |
550049c2 | 7160 | |
3a3c8603 | 7161 | return CallNextHookEx(ms_hMsgHookProc, nCode, wParam, lParam); |
47b378bd | 7162 | } |
550049c2 | 7163 | |
d79df32c | 7164 | private: |
3a3c8603 | 7165 | static HHOOK ms_hMsgHookProc; |
550049c2 VZ |
7166 | |
7167 | DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule) | |
d79df32c | 7168 | }; |
d79df32c | 7169 | |
550049c2 VZ |
7170 | HHOOK wxIdleWakeUpModule::ms_hMsgHookProc = 0; |
7171 | ||
7172 | IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule, wxModule) | |
7173 | ||
7174 | #endif // __WXWINCE__ | |
3a3c8603 | 7175 | |
d26e1ab2 JS |
7176 | #ifdef __WXWINCE__ |
7177 | ||
7178 | #if wxUSE_STATBOX | |
7179 | static void wxAdjustZOrder(wxWindow* parent) | |
7180 | { | |
7181 | if (parent->IsKindOf(CLASSINFO(wxStaticBox))) | |
7182 | { | |
7183 | // Set the z-order correctly | |
7184 | SetWindowPos((HWND) parent->GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); | |
7185 | } | |
35bbb0c6 | 7186 | |
d26e1ab2 JS |
7187 | wxWindowList::compatibility_iterator current = parent->GetChildren().GetFirst(); |
7188 | while (current) | |
7189 | { | |
7190 | wxWindow *childWin = current->GetData(); | |
7191 | wxAdjustZOrder(childWin); | |
7192 | current = current->GetNext(); | |
7193 | } | |
7194 | } | |
7195 | #endif | |
7196 | ||
7197 | // We need to adjust the z-order of static boxes in WinCE, to | |
7198 | // make 'contained' controls visible | |
7199 | void wxWindowMSW::OnInitDialog( wxInitDialogEvent& event ) | |
7200 | { | |
7201 | #if wxUSE_STATBOX | |
7202 | wxAdjustZOrder(this); | |
7203 | #endif | |
35bbb0c6 | 7204 | |
d26e1ab2 JS |
7205 | event.Skip(); |
7206 | } | |
7207 | #endif |