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