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