]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1e6feb95 | 2 | // Name: src/msw/windows.cpp |
2bda0e17 KB |
3 | // Purpose: wxWindow |
4 | // Author: Julian Smart | |
a23fd0e1 | 5 | // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation |
2bda0e17 KB |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
a3622daa | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
a23fd0e1 VZ |
12 | // =========================================================================== |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
a23fd0e1 | 21 | #pragma implementation "window.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
09914df7 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
0c589ad0 BM |
32 | #include <windows.h> |
33 | #include "wx/msw/winundef.h" | |
4e938f5b | 34 | #include "wx/window.h" |
0c589ad0 | 35 | #include "wx/accel.h" |
3a19e16d VZ |
36 | #include "wx/setup.h" |
37 | #include "wx/menu.h" | |
38 | #include "wx/dc.h" | |
39 | #include "wx/dcclient.h" | |
40 | #include "wx/utils.h" | |
41 | #include "wx/app.h" | |
3a19e16d VZ |
42 | #include "wx/layout.h" |
43 | #include "wx/dialog.h" | |
44 | #include "wx/frame.h" | |
45 | #include "wx/listbox.h" | |
46 | #include "wx/button.h" | |
3a19e16d | 47 | #include "wx/msgdlg.h" |
1f3943e0 | 48 | #include "wx/settings.h" |
8d753488 | 49 | #include "wx/statbox.h" |
2bda0e17 KB |
50 | #endif |
51 | ||
f6bcfd97 | 52 | #if wxUSE_OWNER_DRAWN |
09914df7 | 53 | #include "wx/ownerdrw.h" |
2bda0e17 KB |
54 | #endif |
55 | ||
9e2896e5 VZ |
56 | #if wxUSE_DRAG_AND_DROP |
57 | #include "wx/dnd.h" | |
2bda0e17 KB |
58 | #endif |
59 | ||
60 | #include "wx/menuitem.h" | |
47cbd6da | 61 | #include "wx/log.h" |
750b78ba | 62 | |
0c589ad0 BM |
63 | #include "wx/msw/private.h" |
64 | ||
750b78ba | 65 | #if wxUSE_TOOLTIPS |
42e69d6b | 66 | #include "wx/tooltip.h" |
750b78ba JS |
67 | #endif |
68 | ||
789295bf VZ |
69 | #if wxUSE_CARET |
70 | #include "wx/caret.h" | |
71 | #endif // wxUSE_CARET | |
72 | ||
6fe19057 VZ |
73 | #if wxUSE_SPINCTRL |
74 | #include "wx/spinctrl.h" | |
75 | #endif // wxUSE_SPINCTRL | |
76 | ||
dbda9e86 JS |
77 | #include "wx/intl.h" |
78 | #include "wx/log.h" | |
3a19e16d | 79 | |
2a47d3c1 | 80 | #include "wx/textctrl.h" |
d9317fd4 | 81 | #include "wx/notebook.h" |
2a47d3c1 | 82 | |
2bda0e17 KB |
83 | #include <string.h> |
84 | ||
04ef50df | 85 | #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__)) || defined(__CYGWIN10__) |
3a19e16d VZ |
86 | #include <shellapi.h> |
87 | #include <mmsystem.h> | |
2bda0e17 KB |
88 | #endif |
89 | ||
90 | #ifdef __WIN32__ | |
3a19e16d | 91 | #include <windowsx.h> |
2bda0e17 KB |
92 | #endif |
93 | ||
04ef50df | 94 | #if (!defined(__GNUWIN32_OLD__) && !defined(__TWIN32__) && !defined(__WXMICROWIN__)) || defined(__CYGWIN10__) |
310df81b | 95 | #ifdef __WIN95__ |
c42404a5 VZ |
96 | #include <commctrl.h> |
97 | #endif | |
04ef50df | 98 | #elif !defined(__WXMICROWIN__) // broken compiler |
c42404a5 VZ |
99 | #ifndef __TWIN32__ |
100 | #include "wx/msw/gnuwin32/extra.h" | |
3a19e16d | 101 | #endif |
57c208c5 | 102 | #endif |
2bda0e17 | 103 | |
f6bcfd97 BP |
104 | // This didn't appear in mingw until 2.95.2 |
105 | #ifndef SIF_TRACKPOS | |
106 | #define SIF_TRACKPOS 16 | |
107 | #endif | |
108 | ||
d2c52078 RD |
109 | #if wxUSE_MOUSEWHEEL |
110 | #ifndef WM_MOUSEWHEEL | |
111 | #define WM_MOUSEWHEEL 0x020A | |
c9d4f881 RD |
112 | #endif |
113 | #ifndef WHEEL_DELTA | |
d2c52078 | 114 | #define WHEEL_DELTA 120 |
c9d4f881 RD |
115 | #endif |
116 | #ifndef SPI_GETWHEELSCROLLLINES | |
d2c52078 RD |
117 | #define SPI_GETWHEELSCROLLLINES 104 |
118 | #endif | |
119 | #endif | |
120 | ||
121 | ||
a23fd0e1 | 122 | // --------------------------------------------------------------------------- |
42e69d6b | 123 | // global variables |
a23fd0e1 | 124 | // --------------------------------------------------------------------------- |
47cbd6da | 125 | |
42e69d6b VZ |
126 | // the last Windows message we got (MT-UNSAFE) |
127 | extern MSG s_currentMsg; | |
2bda0e17 | 128 | |
1e6feb95 | 129 | #if wxUSE_MENUS_NATIVE |
2bda0e17 | 130 | wxMenu *wxCurrentPopupMenu = NULL; |
1e6feb95 VZ |
131 | #endif // wxUSE_MENUS_NATIVE |
132 | ||
2ffa221c | 133 | extern const wxChar *wxCanvasClassName; |
42e69d6b VZ |
134 | |
135 | // --------------------------------------------------------------------------- | |
136 | // private functions | |
137 | // --------------------------------------------------------------------------- | |
138 | ||
139 | // the window proc for all our windows | |
3135f4a7 | 140 | LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, |
42e69d6b VZ |
141 | WPARAM wParam, LPARAM lParam); |
142 | ||
143 | #ifdef __WXDEBUG__ | |
144 | const char *wxGetMessageName(int message); | |
145 | #endif //__WXDEBUG__ | |
2bda0e17 | 146 | |
1e6feb95 VZ |
147 | void wxRemoveHandleAssociation(wxWindowMSW *win); |
148 | void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win); | |
2bda0e17 KB |
149 | wxWindow *wxFindWinFromHandle(WXHWND hWnd); |
150 | ||
4aff28fc VZ |
151 | // this magical function is used to translate VK_APPS key presses to right |
152 | // mouse clicks | |
1e6feb95 VZ |
153 | static void TranslateKbdEventToMouse(wxWindowMSW *win, |
154 | int *x, int *y, WPARAM *flags); | |
4aff28fc | 155 | |
f6bcfd97 | 156 | // get the text metrics for the current font |
1e6feb95 VZ |
157 | static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win); |
158 | ||
c48926e1 | 159 | // wrapper around BringWindowToTop() API |
44d5b352 | 160 | static inline void wxBringWindowToTop(HWND hwnd) |
c48926e1 VZ |
161 | { |
162 | #ifdef __WXMICROWIN__ | |
163 | // It seems that MicroWindows brings the _parent_ of the window to the top, | |
164 | // which can be the wrong one. | |
165 | ||
166 | // activate (set focus to) specified window | |
167 | ::SetFocus(hwnd); | |
168 | ||
169 | // raise top level parent to top of z order | |
170 | ::SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); | |
171 | #else // !__WXMICROWIN__ | |
172 | if ( !::BringWindowToTop(hwnd) ) | |
173 | { | |
174 | wxLogLastError(_T("BringWindowToTop")); | |
175 | } | |
176 | #endif // __WXMICROWIN__/!__WXMICROWIN__ | |
177 | } | |
f6bcfd97 | 178 | |
a23fd0e1 VZ |
179 | // --------------------------------------------------------------------------- |
180 | // event tables | |
181 | // --------------------------------------------------------------------------- | |
182 | ||
1e6feb95 VZ |
183 | // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu() |
184 | // method | |
185 | #ifdef __WXUNIVERSAL__ | |
186 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW, wxWindowBase) | |
187 | #else // __WXMSW__ | |
188 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) | |
189 | #endif // __WXUNIVERSAL__/__WXMSW__ | |
190 | ||
191 | BEGIN_EVENT_TABLE(wxWindowMSW, wxWindowBase) | |
192 | EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground) | |
193 | EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged) | |
194 | EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog) | |
195 | EVT_IDLE(wxWindowMSW::OnIdle) | |
2bda0e17 KB |
196 | END_EVENT_TABLE() |
197 | ||
a23fd0e1 VZ |
198 | // =========================================================================== |
199 | // implementation | |
200 | // =========================================================================== | |
201 | ||
42e69d6b VZ |
202 | // --------------------------------------------------------------------------- |
203 | // wxWindow utility functions | |
204 | // --------------------------------------------------------------------------- | |
205 | ||
2bda0e17 | 206 | // Find an item given the MS Windows id |
1e6feb95 | 207 | wxWindow *wxWindowMSW::FindItem(long id) const |
2bda0e17 | 208 | { |
1e6feb95 | 209 | #if wxUSE_CONTROLS |
f7637829 | 210 | wxControl *item = wxDynamicCastThis(wxControl); |
f048e32f VZ |
211 | if ( item ) |
212 | { | |
1e6feb95 VZ |
213 | // is it we or one of our "internal" children? |
214 | if ( item->GetId() == id | |
215 | #ifndef __WXUNIVERSAL__ | |
216 | || (item->GetSubcontrols().Index(id) != wxNOT_FOUND) | |
217 | #endif // __WXUNIVERSAL__ | |
218 | ) | |
f048e32f VZ |
219 | { |
220 | return item; | |
221 | } | |
222 | } | |
1e6feb95 | 223 | #endif // wxUSE_CONTROLS |
f048e32f | 224 | |
42e69d6b | 225 | wxWindowList::Node *current = GetChildren().GetFirst(); |
2d0a075d JS |
226 | while (current) |
227 | { | |
42e69d6b | 228 | wxWindow *childWin = current->GetData(); |
2bda0e17 | 229 | |
42e69d6b | 230 | wxWindow *wnd = childWin->FindItem(id); |
cc2b7472 | 231 | if ( wnd ) |
42e69d6b | 232 | return wnd; |
2bda0e17 | 233 | |
42e69d6b | 234 | current = current->GetNext(); |
2bda0e17 | 235 | } |
42e69d6b | 236 | |
2d0a075d | 237 | return NULL; |
2bda0e17 KB |
238 | } |
239 | ||
240 | // Find an item given the MS Windows handle | |
1e6feb95 | 241 | wxWindow *wxWindowMSW::FindItemByHWND(WXHWND hWnd, bool controlOnly) const |
2bda0e17 | 242 | { |
42e69d6b | 243 | wxWindowList::Node *current = GetChildren().GetFirst(); |
2d0a075d | 244 | while (current) |
2bda0e17 | 245 | { |
42e69d6b VZ |
246 | wxWindow *parent = current->GetData(); |
247 | ||
2d0a075d | 248 | // Do a recursive search. |
42e69d6b | 249 | wxWindow *wnd = parent->FindItemByHWND(hWnd); |
cc2b7472 | 250 | if ( wnd ) |
42e69d6b | 251 | return wnd; |
2d0a075d | 252 | |
1e6feb95 VZ |
253 | if ( !controlOnly |
254 | #if wxUSE_CONTROLS | |
255 | || parent->IsKindOf(CLASSINFO(wxControl)) | |
256 | #endif // wxUSE_CONTROLS | |
257 | ) | |
2d0a075d | 258 | { |
42e69d6b VZ |
259 | wxWindow *item = current->GetData(); |
260 | if ( item->GetHWND() == hWnd ) | |
2d0a075d JS |
261 | return item; |
262 | else | |
263 | { | |
264 | if ( item->ContainsHWND(hWnd) ) | |
265 | return item; | |
266 | } | |
267 | } | |
42e69d6b VZ |
268 | |
269 | current = current->GetNext(); | |
2bda0e17 | 270 | } |
2d0a075d | 271 | return NULL; |
2bda0e17 KB |
272 | } |
273 | ||
274 | // Default command handler | |
1e6feb95 | 275 | bool wxWindowMSW::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) |
2bda0e17 | 276 | { |
2d0a075d | 277 | return FALSE; |
2bda0e17 KB |
278 | } |
279 | ||
fd3f686c VZ |
280 | // ---------------------------------------------------------------------------- |
281 | // constructors and such | |
282 | // ---------------------------------------------------------------------------- | |
283 | ||
1e6feb95 | 284 | void wxWindowMSW::Init() |
2bda0e17 | 285 | { |
cc2b7472 VZ |
286 | // generic |
287 | InitBase(); | |
634903fd | 288 | |
cc2b7472 | 289 | // MSW specific |
42e69d6b | 290 | m_doubleClickAllowed = 0; |
cc2b7472 | 291 | |
2d0a075d JS |
292 | m_isBeingDeleted = FALSE; |
293 | m_oldWndProc = 0; | |
2d0a075d | 294 | m_useCtl3D = FALSE; |
fd3f686c | 295 | m_mouseInWindow = FALSE; |
2bda0e17 | 296 | |
2d0a075d | 297 | // wxWnd |
2d0a075d | 298 | m_hMenu = 0; |
2bda0e17 | 299 | |
319fefa9 VZ |
300 | m_hWnd = 0; |
301 | ||
302 | // pass WM_GETDLGCODE to DefWindowProc() | |
303 | m_lDlgCode = 0; | |
304 | ||
2d0a075d JS |
305 | m_xThumbSize = 0; |
306 | m_yThumbSize = 0; | |
307 | m_backgroundTransparent = FALSE; | |
2bda0e17 | 308 | |
85d10d9b VZ |
309 | // as all windows are created with WS_VISIBLE style... |
310 | m_isShown = TRUE; | |
311 | ||
a23fd0e1 | 312 | #if wxUSE_MOUSEEVENT_HACK |
cc2b7472 VZ |
313 | m_lastMouseX = |
314 | m_lastMouseY = -1; | |
315 | m_lastMouseEvent = -1; | |
a23fd0e1 | 316 | #endif // wxUSE_MOUSEEVENT_HACK |
fd3f686c VZ |
317 | } |
318 | ||
2bda0e17 | 319 | // Destructor |
1e6feb95 | 320 | wxWindowMSW::~wxWindowMSW() |
2bda0e17 | 321 | { |
2d0a075d | 322 | m_isBeingDeleted = TRUE; |
2bda0e17 | 323 | |
2d0a075d | 324 | MSWDetachWindowMenu(); |
38caaa61 | 325 | |
4a41c655 VS |
326 | // VS: make sure there's no wxFrame with last focus set to us: |
327 | for (wxWindow *win = GetParent(); win; win = win->GetParent()) | |
328 | { | |
329 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
330 | if ( frame ) | |
331 | { | |
332 | if ( frame->GetLastFocus() == this ) | |
333 | frame->SetLastFocus((wxWindow*)NULL); | |
cc0c7cd8 | 334 | break; |
4a41c655 VS |
335 | } |
336 | } | |
2bda0e17 | 337 | |
cc0c7cd8 VS |
338 | // VS: destroy children first and _then_ detach *this from its parent. |
339 | // If we'd do it the other way around, children wouldn't be able | |
340 | // find their parent frame (see above). | |
341 | DestroyChildren(); | |
342 | ||
a23fd0e1 VZ |
343 | if ( m_parent ) |
344 | m_parent->RemoveChild(this); | |
345 | ||
cc2b7472 | 346 | if ( m_hWnd ) |
42e69d6b | 347 | { |
98440bc3 VZ |
348 | // VZ: test temp removed to understand what really happens here |
349 | //if (::IsWindow(GetHwnd())) | |
df61c009 JS |
350 | { |
351 | if ( !::DestroyWindow(GetHwnd()) ) | |
f6bcfd97 | 352 | wxLogLastError(wxT("DestroyWindow")); |
df61c009 | 353 | } |
2bda0e17 | 354 | |
c50f1fb9 VZ |
355 | // remove hWnd <-> wxWindow association |
356 | wxRemoveHandleAssociation(this); | |
357 | } | |
2bda0e17 KB |
358 | } |
359 | ||
fd3f686c | 360 | // real construction (Init() must have been called before!) |
1e6feb95 VZ |
361 | bool wxWindowMSW::Create(wxWindow *parent, |
362 | wxWindowID id, | |
363 | const wxPoint& pos, | |
364 | const wxSize& size, | |
365 | long style, | |
366 | const wxString& name) | |
2d0a075d | 367 | { |
223d09f6 | 368 | wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") ); |
2bda0e17 | 369 | |
f7637829 VZ |
370 | #if wxUSE_STATBOX |
371 | // wxGTK doesn't allow to create controls with static box as the parent so | |
372 | // this will result in a crash when the program is ported to wxGTK - warn | |
373 | // about it | |
374 | // | |
375 | // the correct solution is to create the controls as siblings of the | |
376 | // static box | |
377 | wxASSERT_MSG( !wxDynamicCastThis(wxStaticBox), | |
378 | _T("wxStaticBox can't be used as a window parent!") ); | |
379 | #endif // wxUSE_STATBOX | |
380 | ||
8d99be5f VZ |
381 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) |
382 | return FALSE; | |
42e69d6b | 383 | |
fd3f686c | 384 | parent->AddChild(this); |
2bda0e17 | 385 | |
1e6feb95 VZ |
386 | // all windows are created visible |
387 | DWORD msflags = WS_CHILD | WS_VISIBLE; | |
388 | ||
389 | #ifdef __WXUNIVERSAL__ | |
390 | // no 3d effects, we draw them ourselves | |
391 | WXDWORD exStyle = 0; | |
392 | #else // !wxUniversal | |
cc2b7472 | 393 | if ( style & wxCLIP_CHILDREN ) |
2d0a075d | 394 | msflags |= WS_CLIPCHILDREN; |
d11bb14f JS |
395 | if ( style & wxCLIP_SIBLINGS ) |
396 | msflags |= WS_CLIPSIBLINGS; | |
2bda0e17 | 397 | |
2d0a075d | 398 | bool want3D; |
42e69d6b | 399 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D); |
2bda0e17 | 400 | |
2d0a075d JS |
401 | // Even with extended styles, need to combine with WS_BORDER |
402 | // for them to look right. | |
1e6feb95 VZ |
403 | if ( want3D || |
404 | (m_windowStyle & (wxBORDER | | |
405 | wxSIMPLE_BORDER | | |
406 | wxRAISED_BORDER | | |
407 | wxSUNKEN_BORDER | | |
408 | wxDOUBLE_BORDER)) ) | |
cc2b7472 | 409 | { |
2d0a075d | 410 | msflags |= WS_BORDER; |
cc2b7472 | 411 | } |
2bda0e17 | 412 | |
101f488c VZ |
413 | // calculate the value to return from WM_GETDLGCODE handler |
414 | if ( GetWindowStyleFlag() & wxWANTS_CHARS ) | |
415 | { | |
416 | // want everything: i.e. all keys and WM_CHAR message | |
417 | m_lDlgCode = DLGC_WANTARROWS | DLGC_WANTCHARS | | |
418 | DLGC_WANTTAB | DLGC_WANTMESSAGE; | |
101f488c | 419 | } |
1e6feb95 VZ |
420 | #endif // wxUniversal/!wxUniversal |
421 | ||
422 | if ( style & wxPOPUP_WINDOW ) | |
423 | { | |
424 | // a popup window floats on top of everything | |
425 | exStyle |= WS_EX_TOPMOST | WS_EX_TOOLWINDOW; | |
101f488c | 426 | |
1e6feb95 VZ |
427 | // it is also created hidden as other top level windows |
428 | msflags &= ~WS_VISIBLE; | |
429 | m_isShown = FALSE; | |
430 | } | |
431 | ||
432 | return MSWCreate(m_windowId, parent, wxCanvasClassName, | |
433 | (wxWindow *)this, NULL, | |
8bf30fe9 VZ |
434 | pos.x, pos.y, |
435 | WidthDefault(size.x), HeightDefault(size.y), | |
436 | msflags, NULL, exStyle); | |
2bda0e17 KB |
437 | } |
438 | ||
42e69d6b VZ |
439 | // --------------------------------------------------------------------------- |
440 | // basic operations | |
441 | // --------------------------------------------------------------------------- | |
442 | ||
1e6feb95 | 443 | void wxWindowMSW::SetFocus() |
2bda0e17 | 444 | { |
a23fd0e1 | 445 | HWND hWnd = GetHwnd(); |
1e6feb95 VZ |
446 | wxCHECK_RET( hWnd, _T("can't set focus to invalid window") ); |
447 | ||
8cb172b4 | 448 | #ifndef __WXMICROWIN__ |
1e6feb95 | 449 | ::SetLastError(0); |
8cb172b4 | 450 | #endif |
d0a3d109 | 451 | |
1e6feb95 VZ |
452 | if ( !::SetFocus(hWnd) ) |
453 | { | |
454 | // was there really an error? | |
8cb172b4 | 455 | #ifndef __WXMICROWIN__ |
1e6feb95 | 456 | DWORD dwRes = ::GetLastError(); |
8cb172b4 JS |
457 | #else |
458 | ||
459 | DWORD dwRes = 0; | |
460 | #endif | |
1e6feb95 VZ |
461 | if ( dwRes ) |
462 | { | |
463 | wxLogApiError(_T("SetFocus"), dwRes); | |
464 | } | |
465 | ||
466 | // VZ: just why does this happen sometimes?? any idea? | |
467 | #if 0 | |
468 | HWND hwndFocus = ::GetFocus(); | |
469 | wxASSERT_MSG( hwndFocus == hWnd, _T("SetFocus() didn't work?") ); | |
470 | #endif // 0 | |
471 | } | |
2bda0e17 KB |
472 | } |
473 | ||
42e69d6b VZ |
474 | // Get the window with the focus |
475 | wxWindow *wxWindowBase::FindFocus() | |
476 | { | |
477 | HWND hWnd = ::GetFocus(); | |
478 | if ( hWnd ) | |
479 | { | |
a2242341 | 480 | return wxGetWindowFromHWND((WXHWND)hWnd); |
42e69d6b VZ |
481 | } |
482 | ||
483 | return NULL; | |
484 | } | |
485 | ||
1e6feb95 | 486 | bool wxWindowMSW::Enable(bool enable) |
2bda0e17 | 487 | { |
cc2b7472 VZ |
488 | if ( !wxWindowBase::Enable(enable) ) |
489 | return FALSE; | |
490 | ||
a23fd0e1 | 491 | HWND hWnd = GetHwnd(); |
cc2b7472 | 492 | if ( hWnd ) |
2d0a075d | 493 | ::EnableWindow(hWnd, (BOOL)enable); |
cc2b7472 | 494 | |
cbc66a27 VZ |
495 | // VZ: no, this is a bad idea: imagine that you have a dialog with some |
496 | // disabled controls and disable it - you really wouldn't like the | |
a2242341 | 497 | // disabled controls be reenabled too when you reenable the dialog! |
cbc66a27 | 498 | #if 0 |
87a1e308 VZ |
499 | wxWindowList::Node *node = GetChildren().GetFirst(); |
500 | while ( node ) | |
501 | { | |
502 | wxWindow *child = node->GetData(); | |
503 | child->Enable(enable); | |
504 | ||
505 | node = node->GetNext(); | |
506 | } | |
cbc66a27 | 507 | #endif // 0 |
87a1e308 | 508 | |
cc2b7472 | 509 | return TRUE; |
2bda0e17 KB |
510 | } |
511 | ||
1e6feb95 | 512 | bool wxWindowMSW::Show(bool show) |
42e69d6b VZ |
513 | { |
514 | if ( !wxWindowBase::Show(show) ) | |
515 | return FALSE; | |
516 | ||
517 | HWND hWnd = GetHwnd(); | |
518 | int cshow = show ? SW_SHOW : SW_HIDE; | |
519 | ::ShowWindow(hWnd, cshow); | |
520 | ||
521 | if ( show ) | |
522 | { | |
c48926e1 | 523 | wxBringWindowToTop(hWnd); |
42e69d6b VZ |
524 | } |
525 | ||
526 | return TRUE; | |
527 | } | |
528 | ||
529 | // Raise the window to the top of the Z order | |
1e6feb95 | 530 | void wxWindowMSW::Raise() |
42e69d6b | 531 | { |
c48926e1 | 532 | wxBringWindowToTop(GetHwnd()); |
42e69d6b VZ |
533 | } |
534 | ||
535 | // Lower the window to the bottom of the Z order | |
1e6feb95 | 536 | void wxWindowMSW::Lower() |
42e69d6b VZ |
537 | { |
538 | ::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, | |
539 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | |
540 | } | |
541 | ||
1e6feb95 | 542 | void wxWindowMSW::SetTitle( const wxString& title) |
42e69d6b VZ |
543 | { |
544 | SetWindowText(GetHwnd(), title.c_str()); | |
545 | } | |
546 | ||
1e6feb95 | 547 | wxString wxWindowMSW::GetTitle() const |
42e69d6b VZ |
548 | { |
549 | return wxGetWindowText(GetHWND()); | |
550 | } | |
551 | ||
1e6feb95 | 552 | void wxWindowMSW::CaptureMouse() |
2bda0e17 | 553 | { |
a23fd0e1 | 554 | HWND hWnd = GetHwnd(); |
1e6feb95 | 555 | if ( hWnd ) |
2d0a075d | 556 | { |
1e6feb95 | 557 | ::SetCapture(hWnd); |
2d0a075d | 558 | } |
2bda0e17 KB |
559 | } |
560 | ||
1e6feb95 | 561 | void wxWindowMSW::ReleaseMouse() |
2bda0e17 | 562 | { |
1e6feb95 | 563 | if ( !::ReleaseCapture() ) |
2d0a075d | 564 | { |
1e6feb95 | 565 | wxLogLastError(_T("ReleaseCapture")); |
2d0a075d | 566 | } |
2bda0e17 KB |
567 | } |
568 | ||
1e6feb95 VZ |
569 | /* static */ wxWindow *wxWindowBase::GetCapture() |
570 | { | |
571 | HWND hwnd = ::GetCapture(); | |
572 | return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : (wxWindow *)NULL; | |
573 | } | |
574 | ||
575 | bool wxWindowMSW::SetFont(const wxFont& font) | |
2bda0e17 | 576 | { |
42e69d6b VZ |
577 | if ( !wxWindowBase::SetFont(font) ) |
578 | { | |
579 | // nothing to do | |
580 | return FALSE; | |
2d0a075d | 581 | } |
195896c7 | 582 | |
42e69d6b VZ |
583 | HWND hWnd = GetHwnd(); |
584 | if ( hWnd != 0 ) | |
585 | { | |
586 | WXHANDLE hFont = m_font.GetResourceHandle(); | |
2bda0e17 | 587 | |
223d09f6 | 588 | wxASSERT_MSG( hFont, wxT("should have valid font") ); |
3a19e16d | 589 | |
c50f1fb9 | 590 | ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); |
42e69d6b | 591 | } |
2bda0e17 | 592 | |
42e69d6b VZ |
593 | return TRUE; |
594 | } | |
1e6feb95 | 595 | bool wxWindowMSW::SetCursor(const wxCursor& cursor) |
2bda0e17 | 596 | { |
42e69d6b VZ |
597 | if ( !wxWindowBase::SetCursor(cursor) ) |
598 | { | |
599 | // no change | |
600 | return FALSE; | |
601 | } | |
602 | ||
8a9c2246 VZ |
603 | if ( m_cursor.Ok() ) |
604 | { | |
605 | HWND hWnd = GetHwnd(); | |
42e69d6b | 606 | |
8a9c2246 VZ |
607 | // Change the cursor NOW if we're within the correct window |
608 | POINT point; | |
609 | ::GetCursorPos(&point); | |
2bda0e17 | 610 | |
82c9f85c | 611 | RECT rect = wxGetWindowRect(hWnd); |
3a19e16d | 612 | |
8a9c2246 VZ |
613 | if ( ::PtInRect(&rect, point) && !wxIsBusy() ) |
614 | ::SetCursor(GetHcursorOf(m_cursor)); | |
615 | } | |
3a19e16d | 616 | |
42e69d6b | 617 | return TRUE; |
3a19e16d VZ |
618 | } |
619 | ||
1e6feb95 | 620 | void wxWindowMSW::WarpPointer (int x, int y) |
2bda0e17 | 621 | { |
1e6feb95 | 622 | ClientToScreen(&x, &y); |
42e69d6b | 623 | |
1e6feb95 VZ |
624 | if ( !::SetCursorPos(x, y) ) |
625 | { | |
626 | wxLogLastError(_T("SetCursorPos")); | |
627 | } | |
2bda0e17 KB |
628 | } |
629 | ||
42e69d6b | 630 | #if WXWIN_COMPATIBILITY |
1e6feb95 | 631 | void wxWindowMSW::MSWDeviceToLogical (float *x, float *y) const |
2bda0e17 | 632 | { |
42e69d6b VZ |
633 | } |
634 | #endif // WXWIN_COMPATIBILITY | |
81d66cf3 | 635 | |
42e69d6b VZ |
636 | // --------------------------------------------------------------------------- |
637 | // scrolling stuff | |
638 | // --------------------------------------------------------------------------- | |
2d0a075d | 639 | |
42e69d6b | 640 | #if WXWIN_COMPATIBILITY |
1e6feb95 | 641 | void wxWindowMSW::SetScrollRange(int orient, int range, bool refresh) |
42e69d6b VZ |
642 | { |
643 | #if defined(__WIN95__) | |
644 | ||
645 | int range1 = range; | |
646 | ||
647 | // Try to adjust the range to cope with page size > 1 | |
648 | // - a Windows API quirk | |
649 | int pageSize = GetScrollPage(orient); | |
650 | if ( pageSize > 1 && range > 0) | |
2d0a075d | 651 | { |
42e69d6b | 652 | range1 += (pageSize - 1); |
2d0a075d JS |
653 | } |
654 | ||
42e69d6b VZ |
655 | SCROLLINFO info; |
656 | int dir; | |
657 | ||
658 | if ( orient == wxHORIZONTAL ) { | |
659 | dir = SB_HORZ; | |
660 | } else { | |
661 | dir = SB_VERT; | |
2d0a075d | 662 | } |
cc2b7472 | 663 | |
42e69d6b VZ |
664 | info.cbSize = sizeof(SCROLLINFO); |
665 | info.nPage = pageSize; // Have to set this, or scrollbar goes awry | |
666 | info.nMin = 0; | |
667 | info.nMax = range1; | |
668 | info.nPos = 0; | |
669 | info.fMask = SIF_RANGE | SIF_PAGE; | |
670 | ||
671 | HWND hWnd = GetHwnd(); | |
672 | if ( hWnd ) | |
673 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
674 | #else | |
675 | int wOrient; | |
676 | if ( orient == wxHORIZONTAL ) | |
677 | wOrient = SB_HORZ; | |
678 | else | |
679 | wOrient = SB_VERT; | |
680 | ||
681 | HWND hWnd = GetHwnd(); | |
682 | if ( hWnd ) | |
683 | ::SetScrollRange(hWnd, wOrient, 0, range, refresh); | |
684 | #endif | |
2bda0e17 KB |
685 | } |
686 | ||
1e6feb95 | 687 | void wxWindowMSW::SetScrollPage(int orient, int page, bool refresh) |
2bda0e17 | 688 | { |
42e69d6b VZ |
689 | #if defined(__WIN95__) |
690 | SCROLLINFO info; | |
691 | int dir; | |
2d0a075d | 692 | |
42e69d6b VZ |
693 | if ( orient == wxHORIZONTAL ) { |
694 | dir = SB_HORZ; | |
695 | m_xThumbSize = page; | |
696 | } else { | |
697 | dir = SB_VERT; | |
698 | m_yThumbSize = page; | |
699 | } | |
0757d27c | 700 | |
42e69d6b VZ |
701 | info.cbSize = sizeof(SCROLLINFO); |
702 | info.nPage = page; | |
703 | info.nMin = 0; | |
704 | info.fMask = SIF_PAGE; | |
705 | ||
706 | HWND hWnd = GetHwnd(); | |
707 | if ( hWnd ) | |
708 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
709 | #else | |
710 | if ( orient == wxHORIZONTAL ) | |
711 | m_xThumbSize = page; | |
712 | else | |
713 | m_yThumbSize = page; | |
714 | #endif | |
2bda0e17 KB |
715 | } |
716 | ||
1e6feb95 | 717 | int wxWindowMSW::OldGetScrollRange(int orient) const |
2bda0e17 | 718 | { |
42e69d6b VZ |
719 | int wOrient; |
720 | if ( orient == wxHORIZONTAL ) | |
721 | wOrient = SB_HORZ; | |
722 | else | |
723 | wOrient = SB_VERT; | |
2d0a075d | 724 | |
42e69d6b VZ |
725 | #if __WATCOMC__ && defined(__WINDOWS_386__) |
726 | short minPos, maxPos; | |
727 | #else | |
728 | int minPos, maxPos; | |
729 | #endif | |
a23fd0e1 | 730 | HWND hWnd = GetHwnd(); |
42e69d6b VZ |
731 | if ( hWnd ) |
732 | { | |
733 | ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos); | |
734 | #if defined(__WIN95__) | |
735 | // Try to adjust the range to cope with page size > 1 | |
736 | // - a Windows API quirk | |
737 | int pageSize = GetScrollPage(orient); | |
738 | if ( pageSize > 1 ) | |
739 | { | |
740 | maxPos -= (pageSize - 1); | |
741 | } | |
742 | #endif | |
743 | return maxPos; | |
744 | } | |
745 | else | |
746 | return 0; | |
747 | } | |
2bda0e17 | 748 | |
1e6feb95 | 749 | int wxWindowMSW::GetScrollPage(int orient) const |
42e69d6b VZ |
750 | { |
751 | if ( orient == wxHORIZONTAL ) | |
752 | return m_xThumbSize; | |
753 | else | |
754 | return m_yThumbSize; | |
2bda0e17 KB |
755 | } |
756 | ||
42e69d6b VZ |
757 | #endif // WXWIN_COMPATIBILITY |
758 | ||
9cd6d737 VZ |
759 | inline int GetScrollPosition(HWND hWnd, int wOrient) |
760 | { | |
761 | #ifdef __WXMICROWIN__ | |
762 | return ::GetScrollPosWX(hWnd, wOrient); | |
763 | #else | |
764 | return ::GetScrollPos(hWnd, wOrient); | |
765 | #endif | |
766 | } | |
767 | ||
1e6feb95 | 768 | int wxWindowMSW::GetScrollPos(int orient) const |
2bda0e17 | 769 | { |
42e69d6b VZ |
770 | int wOrient; |
771 | if ( orient == wxHORIZONTAL ) | |
772 | wOrient = SB_HORZ; | |
773 | else | |
774 | wOrient = SB_VERT; | |
9cd6d737 | 775 | |
42e69d6b | 776 | HWND hWnd = GetHwnd(); |
9cd6d737 VZ |
777 | wxCHECK_MSG( hWnd, 0, _T("no HWND in GetScrollPos") ); |
778 | ||
779 | return GetScrollPosition(hWnd, wOrient); | |
42e69d6b | 780 | } |
2bda0e17 | 781 | |
42e69d6b VZ |
782 | // This now returns the whole range, not just the number |
783 | // of positions that we can scroll. | |
1e6feb95 | 784 | int wxWindowMSW::GetScrollRange(int orient) const |
42e69d6b VZ |
785 | { |
786 | int wOrient; | |
787 | if ( orient == wxHORIZONTAL ) | |
788 | wOrient = SB_HORZ; | |
789 | else | |
790 | wOrient = SB_VERT; | |
2bda0e17 | 791 | |
42e69d6b VZ |
792 | #if __WATCOMC__ && defined(__WINDOWS_386__) |
793 | short minPos, maxPos; | |
794 | #else | |
795 | int minPos, maxPos; | |
796 | #endif | |
a23fd0e1 | 797 | HWND hWnd = GetHwnd(); |
42e69d6b VZ |
798 | if ( hWnd ) |
799 | { | |
800 | ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos); | |
801 | #if defined(__WIN95__) | |
802 | // Try to adjust the range to cope with page size > 1 | |
803 | // - a Windows API quirk | |
804 | int pageSize = GetScrollThumb(orient); | |
805 | if ( pageSize > 1 ) | |
806 | { | |
807 | maxPos -= (pageSize - 1); | |
808 | } | |
809 | // October 10th: new range concept. | |
810 | maxPos += pageSize; | |
811 | #endif | |
2bda0e17 | 812 | |
42e69d6b VZ |
813 | return maxPos; |
814 | } | |
815 | else | |
816 | return 0; | |
cc2b7472 | 817 | } |
2bda0e17 | 818 | |
1e6feb95 | 819 | int wxWindowMSW::GetScrollThumb(int orient) const |
2bda0e17 | 820 | { |
42e69d6b VZ |
821 | if ( orient == wxHORIZONTAL ) |
822 | return m_xThumbSize; | |
823 | else | |
824 | return m_yThumbSize; | |
2bda0e17 KB |
825 | } |
826 | ||
1e6feb95 | 827 | void wxWindowMSW::SetScrollPos(int orient, int pos, bool refresh) |
2bda0e17 | 828 | { |
42e69d6b VZ |
829 | #if defined(__WIN95__) |
830 | SCROLLINFO info; | |
831 | int dir; | |
72fd19a1 | 832 | |
42e69d6b VZ |
833 | if ( orient == wxHORIZONTAL ) { |
834 | dir = SB_HORZ; | |
835 | } else { | |
836 | dir = SB_VERT; | |
837 | } | |
2d0a075d | 838 | |
42e69d6b VZ |
839 | info.cbSize = sizeof(SCROLLINFO); |
840 | info.nPage = 0; | |
841 | info.nMin = 0; | |
842 | info.nPos = pos; | |
843 | info.fMask = SIF_POS; | |
2d0a075d | 844 | |
42e69d6b VZ |
845 | HWND hWnd = GetHwnd(); |
846 | if ( hWnd ) | |
847 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
848 | #else | |
849 | int wOrient; | |
850 | if ( orient == wxHORIZONTAL ) | |
851 | wOrient = SB_HORZ; | |
852 | else | |
853 | wOrient = SB_VERT; | |
81d66cf3 | 854 | |
a23fd0e1 | 855 | HWND hWnd = GetHwnd(); |
cc2b7472 | 856 | if ( hWnd ) |
42e69d6b VZ |
857 | ::SetScrollPos(hWnd, wOrient, pos, refresh); |
858 | #endif | |
2bda0e17 KB |
859 | } |
860 | ||
42e69d6b | 861 | // New function that will replace some of the above. |
1e6feb95 | 862 | void wxWindowMSW::SetScrollbar(int orient, int pos, int thumbVisible, |
42e69d6b | 863 | int range, bool refresh) |
2bda0e17 | 864 | { |
42e69d6b VZ |
865 | #if defined(__WIN95__) |
866 | int oldRange = range - thumbVisible; | |
2bda0e17 | 867 | |
42e69d6b | 868 | int range1 = oldRange; |
2bda0e17 | 869 | |
42e69d6b VZ |
870 | // Try to adjust the range to cope with page size > 1 |
871 | // - a Windows API quirk | |
872 | int pageSize = thumbVisible; | |
873 | if ( pageSize > 1 && range > 0) | |
874 | { | |
875 | range1 += (pageSize - 1); | |
876 | } | |
2bda0e17 | 877 | |
42e69d6b VZ |
878 | SCROLLINFO info; |
879 | int dir; | |
2bda0e17 | 880 | |
42e69d6b VZ |
881 | if ( orient == wxHORIZONTAL ) { |
882 | dir = SB_HORZ; | |
883 | } else { | |
884 | dir = SB_VERT; | |
2d0a075d | 885 | } |
2bda0e17 | 886 | |
42e69d6b VZ |
887 | info.cbSize = sizeof(SCROLLINFO); |
888 | info.nPage = pageSize; // Have to set this, or scrollbar goes awry | |
889 | info.nMin = 0; | |
890 | info.nMax = range1; | |
891 | info.nPos = pos; | |
892 | info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; | |
2bda0e17 | 893 | |
42e69d6b VZ |
894 | HWND hWnd = GetHwnd(); |
895 | if ( hWnd ) | |
896 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
897 | #else | |
898 | int wOrient; | |
899 | if ( orient == wxHORIZONTAL ) | |
900 | wOrient = SB_HORZ; | |
901 | else | |
902 | wOrient = SB_VERT; | |
81d66cf3 | 903 | |
42e69d6b VZ |
904 | HWND hWnd = GetHwnd(); |
905 | if ( hWnd ) | |
81d66cf3 | 906 | { |
42e69d6b VZ |
907 | ::SetScrollRange(hWnd, wOrient, 0, range, FALSE); |
908 | ::SetScrollPos(hWnd, wOrient, pos, refresh); | |
909 | } | |
910 | #endif | |
911 | if ( orient == wxHORIZONTAL ) { | |
912 | m_xThumbSize = thumbVisible; | |
913 | } else { | |
914 | m_yThumbSize = thumbVisible; | |
81d66cf3 JS |
915 | } |
916 | } | |
917 | ||
1e6feb95 | 918 | void wxWindowMSW::ScrollWindow(int dx, int dy, const wxRect *prect) |
2bda0e17 | 919 | { |
1e6feb95 VZ |
920 | RECT rect; |
921 | if ( prect ) | |
2d0a075d | 922 | { |
1e6feb95 VZ |
923 | rect.left = prect->x; |
924 | rect.top = prect->y; | |
925 | rect.right = prect->x + prect->width; | |
926 | rect.bottom = prect->y + prect->height; | |
2d0a075d | 927 | } |
2bda0e17 | 928 | |
1e6feb95 | 929 | ::ScrollWindow(GetHwnd(), dx, dy, prect ? &rect : NULL, NULL); |
2bda0e17 KB |
930 | } |
931 | ||
9cd6d737 | 932 | static bool ScrollVertically(HWND hwnd, int kind, int count) |
b9b3393e | 933 | { |
9cd6d737 VZ |
934 | int posStart = GetScrollPosition(hwnd, SB_VERT); |
935 | ||
936 | int pos = posStart; | |
c0cdd6cc VZ |
937 | for ( int n = 0; n < count; n++ ) |
938 | { | |
939 | ::SendMessage(hwnd, WM_VSCROLL, kind, 0); | |
9cd6d737 VZ |
940 | |
941 | int posNew = GetScrollPosition(hwnd, SB_VERT); | |
942 | if ( posNew == pos ) | |
943 | { | |
944 | // don't bother to continue, we're already at top/bottom | |
945 | break; | |
946 | } | |
947 | ||
948 | pos = posNew; | |
c0cdd6cc | 949 | } |
9cd6d737 VZ |
950 | |
951 | return pos != posStart; | |
b9b3393e VZ |
952 | } |
953 | ||
9cd6d737 | 954 | bool wxWindowMSW::ScrollLines(int lines) |
b9b3393e VZ |
955 | { |
956 | bool down = lines > 0; | |
957 | ||
9cd6d737 VZ |
958 | return ScrollVertically(GetHwnd(), |
959 | down ? SB_LINEDOWN : SB_LINEUP, | |
960 | down ? lines : -lines); | |
b9b3393e VZ |
961 | } |
962 | ||
9cd6d737 | 963 | bool wxWindowMSW::ScrollPages(int pages) |
b9b3393e VZ |
964 | { |
965 | bool down = pages > 0; | |
966 | ||
9cd6d737 VZ |
967 | return ScrollVertically(GetHwnd(), |
968 | down ? SB_PAGEDOWN : SB_PAGEUP, | |
969 | down ? pages : -pages); | |
b9b3393e VZ |
970 | } |
971 | ||
42e69d6b VZ |
972 | // --------------------------------------------------------------------------- |
973 | // subclassing | |
974 | // --------------------------------------------------------------------------- | |
975 | ||
1e6feb95 | 976 | void wxWindowMSW::SubclassWin(WXHWND hWnd) |
2bda0e17 | 977 | { |
223d09f6 | 978 | wxASSERT_MSG( !m_oldWndProc, wxT("subclassing window twice?") ); |
2bda0e17 | 979 | |
c50f1fb9 | 980 | HWND hwnd = (HWND)hWnd; |
223d09f6 | 981 | wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in SubclassWin") ); |
c50f1fb9 VZ |
982 | |
983 | wxAssociateWinWithHandle(hwnd, this); | |
2bda0e17 | 984 | |
c50f1fb9 | 985 | m_oldWndProc = (WXFARPROC) GetWindowLong(hwnd, GWL_WNDPROC); |
54800df8 JS |
986 | |
987 | wxASSERT( (WXFARPROC) m_oldWndProc != (WXFARPROC) wxWndProc ); | |
d0a3d109 | 988 | |
c50f1fb9 | 989 | SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wxWndProc); |
2bda0e17 KB |
990 | } |
991 | ||
1e6feb95 | 992 | void wxWindowMSW::UnsubclassWin() |
2bda0e17 | 993 | { |
42e69d6b | 994 | wxRemoveHandleAssociation(this); |
2bda0e17 | 995 | |
42e69d6b | 996 | // Restore old Window proc |
c50f1fb9 VZ |
997 | HWND hwnd = GetHwnd(); |
998 | if ( hwnd ) | |
42e69d6b | 999 | { |
c50f1fb9 VZ |
1000 | m_hWnd = 0; |
1001 | ||
223d09f6 | 1002 | wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in UnsubclassWin") ); |
c50f1fb9 VZ |
1003 | |
1004 | FARPROC farProc = (FARPROC) GetWindowLong(hwnd, GWL_WNDPROC); | |
42e69d6b VZ |
1005 | if ( (m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc) ) |
1006 | { | |
c50f1fb9 | 1007 | SetWindowLong(hwnd, GWL_WNDPROC, (LONG) m_oldWndProc); |
42e69d6b VZ |
1008 | m_oldWndProc = 0; |
1009 | } | |
42e69d6b | 1010 | } |
2bda0e17 KB |
1011 | } |
1012 | ||
42e69d6b | 1013 | // Make a Windows extended style from the given wxWindows window style |
1e6feb95 | 1014 | WXDWORD wxWindowMSW::MakeExtendedStyle(long style, bool eliminateBorders) |
2bda0e17 | 1015 | { |
42e69d6b VZ |
1016 | WXDWORD exStyle = 0; |
1017 | if ( style & wxTRANSPARENT_WINDOW ) | |
1018 | exStyle |= WS_EX_TRANSPARENT; | |
2bda0e17 | 1019 | |
42e69d6b | 1020 | if ( !eliminateBorders ) |
2d0a075d | 1021 | { |
42e69d6b VZ |
1022 | if ( style & wxSUNKEN_BORDER ) |
1023 | exStyle |= WS_EX_CLIENTEDGE; | |
1024 | if ( style & wxDOUBLE_BORDER ) | |
1025 | exStyle |= WS_EX_DLGMODALFRAME; | |
1026 | #if defined(__WIN95__) | |
1027 | if ( style & wxRAISED_BORDER ) | |
fe25efa3 JS |
1028 | // It seems that WS_EX_WINDOWEDGE doesn't work, but WS_EX_DLGMODALFRAME does |
1029 | exStyle |= WS_EX_DLGMODALFRAME; /* WS_EX_WINDOWEDGE */; | |
42e69d6b VZ |
1030 | if ( style & wxSTATIC_BORDER ) |
1031 | exStyle |= WS_EX_STATICEDGE; | |
1032 | #endif | |
2d0a075d | 1033 | } |
42e69d6b | 1034 | return exStyle; |
2bda0e17 KB |
1035 | } |
1036 | ||
42e69d6b VZ |
1037 | // Determines whether native 3D effects or CTL3D should be used, |
1038 | // applying a default border style if required, and returning an extended | |
1039 | // style to pass to CreateWindowEx. | |
1e6feb95 | 1040 | WXDWORD wxWindowMSW::Determine3DEffects(WXDWORD defaultBorderStyle, |
8d99be5f | 1041 | bool *want3D) const |
2bda0e17 | 1042 | { |
42e69d6b VZ |
1043 | // If matches certain criteria, then assume no 3D effects |
1044 | // unless specifically requested (dealt with in MakeExtendedStyle) | |
1e6feb95 VZ |
1045 | if ( !GetParent() |
1046 | #if wxUSE_CONTROLS | |
1047 | || !IsKindOf(CLASSINFO(wxControl)) | |
1048 | #endif // wxUSE_CONTROLS | |
1049 | || (m_windowStyle & wxNO_BORDER) ) | |
2bda0e17 | 1050 | { |
42e69d6b VZ |
1051 | *want3D = FALSE; |
1052 | return MakeExtendedStyle(m_windowStyle, FALSE); | |
2bda0e17 | 1053 | } |
2bda0e17 | 1054 | |
42e69d6b VZ |
1055 | // Determine whether we should be using 3D effects or not. |
1056 | bool nativeBorder = FALSE; // by default, we don't want a Win95 effect | |
a02eb1d2 | 1057 | |
42e69d6b VZ |
1058 | // 1) App can specify global 3D effects |
1059 | *want3D = wxTheApp->GetAuto3D(); | |
2bda0e17 | 1060 | |
42e69d6b VZ |
1061 | // 2) If the parent is being drawn with user colours, or simple border specified, |
1062 | // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D | |
1063 | if ( GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) || (m_windowStyle & wxSIMPLE_BORDER) ) | |
1064 | *want3D = FALSE; | |
a23fd0e1 | 1065 | |
42e69d6b VZ |
1066 | // 3) Control can override this global setting by defining |
1067 | // a border style, e.g. wxSUNKEN_BORDER | |
1068 | if ( m_windowStyle & wxSUNKEN_BORDER ) | |
1069 | *want3D = TRUE; | |
2bda0e17 | 1070 | |
42e69d6b VZ |
1071 | // 4) If it's a special border, CTL3D can't cope so we want a native border |
1072 | if ( (m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || | |
1073 | (m_windowStyle & wxSTATIC_BORDER) ) | |
2d0a075d | 1074 | { |
42e69d6b VZ |
1075 | *want3D = TRUE; |
1076 | nativeBorder = TRUE; | |
2d0a075d | 1077 | } |
ea57084d | 1078 | |
42e69d6b VZ |
1079 | // 5) If this isn't a Win95 app, and we are using CTL3D, remove border |
1080 | // effects from extended style | |
1081 | #if wxUSE_CTL3D | |
1082 | if ( *want3D ) | |
1083 | nativeBorder = FALSE; | |
1084 | #endif | |
a23fd0e1 | 1085 | |
42e69d6b | 1086 | DWORD exStyle = MakeExtendedStyle(m_windowStyle, !nativeBorder); |
2bda0e17 | 1087 | |
42e69d6b VZ |
1088 | // If we want 3D, but haven't specified a border here, |
1089 | // apply the default border style specified. | |
1090 | // TODO what about non-Win95 WIN32? Does it have borders? | |
1091 | #if defined(__WIN95__) && !wxUSE_CTL3D | |
1092 | if ( defaultBorderStyle && (*want3D) && ! ((m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER ) || | |
1093 | (m_windowStyle & wxSTATIC_BORDER) || (m_windowStyle & wxSIMPLE_BORDER) )) | |
1094 | exStyle |= defaultBorderStyle; // WS_EX_CLIENTEDGE; | |
1095 | #endif | |
1096 | ||
1097 | return exStyle; | |
a23fd0e1 | 1098 | } |
2bda0e17 | 1099 | |
c455ab93 | 1100 | #if WXWIN_COMPATIBILITY |
42e69d6b VZ |
1101 | // If nothing defined for this, try the parent. |
1102 | // E.g. we may be a button loaded from a resource, with no callback function | |
1103 | // defined. | |
1e6feb95 | 1104 | void wxWindowMSW::OnCommand(wxWindow& win, wxCommandEvent& event) |
2bda0e17 | 1105 | { |
42e69d6b VZ |
1106 | if ( GetEventHandler()->ProcessEvent(event) ) |
1107 | return; | |
1108 | if ( m_parent ) | |
1109 | m_parent->GetEventHandler()->OnCommand(win, event); | |
1110 | } | |
1111 | #endif // WXWIN_COMPATIBILITY_2 | |
c085e333 | 1112 | |
42e69d6b | 1113 | #if WXWIN_COMPATIBILITY |
1e6feb95 | 1114 | wxObject* wxWindowMSW::GetChild(int number) const |
42e69d6b VZ |
1115 | { |
1116 | // Return a pointer to the Nth object in the Panel | |
1117 | wxNode *node = GetChildren().First(); | |
1118 | int n = number; | |
1119 | while (node && n--) | |
1120 | node = node->Next(); | |
1121 | if ( node ) | |
1122 | { | |
1123 | wxObject *obj = (wxObject *)node->Data(); | |
1124 | return(obj); | |
1125 | } | |
1126 | else | |
1127 | return NULL; | |
1128 | } | |
1129 | #endif // WXWIN_COMPATIBILITY | |
2bda0e17 | 1130 | |
42e69d6b | 1131 | // Setup background and foreground colours correctly |
1e6feb95 | 1132 | void wxWindowMSW::SetupColours() |
42e69d6b VZ |
1133 | { |
1134 | if ( GetParent() ) | |
1135 | SetBackgroundColour(GetParent()->GetBackgroundColour()); | |
1136 | } | |
a23fd0e1 | 1137 | |
1e6feb95 VZ |
1138 | bool wxWindowMSW::IsMouseInWindow() const |
1139 | { | |
1140 | // get the mouse position | |
1141 | POINT pt; | |
1142 | ::GetCursorPos(&pt); | |
1143 | ||
1144 | // find the window which currently has the cursor and go up the window | |
1145 | // chain until we find this window - or exhaust it | |
1146 | HWND hwnd = ::WindowFromPoint(pt); | |
1147 | while ( hwnd && (hwnd != GetHwnd()) ) | |
1148 | hwnd = ::GetParent(hwnd); | |
1149 | ||
1150 | return hwnd != NULL; | |
1151 | } | |
1152 | ||
1153 | void wxWindowMSW::OnIdle(wxIdleEvent& WXUNUSED(event)) | |
42e69d6b VZ |
1154 | { |
1155 | // Check if we need to send a LEAVE event | |
1156 | if ( m_mouseInWindow ) | |
2d0a075d | 1157 | { |
1e6feb95 | 1158 | if ( !IsMouseInWindow() ) |
42e69d6b VZ |
1159 | { |
1160 | // Generate a LEAVE event | |
1161 | m_mouseInWindow = FALSE; | |
2bda0e17 | 1162 | |
1e6feb95 VZ |
1163 | // Unfortunately the mouse button and keyboard state may have |
1164 | // changed by the time the OnIdle function is called, so 'state' | |
1165 | // may be meaningless. | |
42e69d6b | 1166 | int state = 0; |
3f7bc32b | 1167 | if ( wxIsShiftDown() ) |
42e69d6b | 1168 | state |= MK_SHIFT; |
3f7bc32b | 1169 | if ( wxIsCtrlDown() ) |
42e69d6b | 1170 | state |= MK_CONTROL; |
54ca0d12 GRG |
1171 | if ( GetKeyState( VK_LBUTTON ) ) |
1172 | state |= MK_LBUTTON; | |
1173 | if ( GetKeyState( VK_MBUTTON ) ) | |
1174 | state |= MK_MBUTTON; | |
1175 | if ( GetKeyState( VK_RBUTTON ) ) | |
1176 | state |= MK_RBUTTON; | |
33ac7e6f | 1177 | |
1e6feb95 VZ |
1178 | POINT pt; |
1179 | if ( !::GetCursorPos(&pt) ) | |
1180 | { | |
1181 | wxLogLastError(_T("GetCursorPos")); | |
1182 | } | |
c085e333 | 1183 | |
1e6feb95 VZ |
1184 | // we need to have client coordinates here for symmetry with |
1185 | // wxEVT_ENTER_WINDOW | |
82c9f85c | 1186 | RECT rect = wxGetWindowRect(GetHwnd()); |
1e6feb95 VZ |
1187 | pt.x -= rect.left; |
1188 | pt.y -= rect.top; | |
1189 | ||
1190 | wxMouseEvent event2(wxEVT_LEAVE_WINDOW); | |
1191 | InitMouseEvent(event2, pt.x, pt.y, state); | |
1192 | ||
1193 | (void)GetEventHandler()->ProcessEvent(event2); | |
42e69d6b VZ |
1194 | } |
1195 | } | |
c085e333 | 1196 | |
42e69d6b VZ |
1197 | UpdateWindowUI(); |
1198 | } | |
568cb543 | 1199 | |
42e69d6b | 1200 | // Set this window to be the child of 'parent'. |
1e6feb95 | 1201 | bool wxWindowMSW::Reparent(wxWindowBase *parent) |
42e69d6b VZ |
1202 | { |
1203 | if ( !wxWindowBase::Reparent(parent) ) | |
1204 | return FALSE; | |
c085e333 | 1205 | |
42e69d6b VZ |
1206 | HWND hWndChild = GetHwnd(); |
1207 | HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0; | |
a23fd0e1 | 1208 | |
42e69d6b | 1209 | ::SetParent(hWndChild, hWndParent); |
a23fd0e1 | 1210 | |
42e69d6b VZ |
1211 | return TRUE; |
1212 | } | |
a23fd0e1 | 1213 | |
1e6feb95 | 1214 | void wxWindowMSW::Clear() |
42e69d6b | 1215 | { |
1e6feb95 | 1216 | wxClientDC dc((wxWindow *)this); |
42e69d6b VZ |
1217 | wxBrush brush(GetBackgroundColour(), wxSOLID); |
1218 | dc.SetBackground(brush); | |
1219 | dc.Clear(); | |
1220 | } | |
a23fd0e1 | 1221 | |
a0e449ff VZ |
1222 | static inline void SendSetRedraw(HWND hwnd, bool on) |
1223 | { | |
1224 | ::SendMessage(hwnd, WM_SETREDRAW, (WPARAM)on, 0); | |
1225 | } | |
1226 | ||
1227 | void wxWindowMSW::Freeze() | |
1228 | { | |
94589c3f | 1229 | SendSetRedraw(GetHwnd(), FALSE); |
a0e449ff VZ |
1230 | } |
1231 | ||
1232 | void wxWindowMSW::Thaw() | |
1233 | { | |
94589c3f | 1234 | SendSetRedraw(GetHwnd(), TRUE); |
c0cdd6cc VZ |
1235 | |
1236 | // we need to refresh everything or otherwise he invalidated area is not | |
1237 | // repainted | |
1238 | Refresh(); | |
a0e449ff VZ |
1239 | } |
1240 | ||
1e6feb95 | 1241 | void wxWindowMSW::Refresh(bool eraseBack, const wxRect *rect) |
42e69d6b VZ |
1242 | { |
1243 | HWND hWnd = GetHwnd(); | |
1244 | if ( hWnd ) | |
1245 | { | |
1246 | if ( rect ) | |
1247 | { | |
1248 | RECT mswRect; | |
1249 | mswRect.left = rect->x; | |
1250 | mswRect.top = rect->y; | |
1251 | mswRect.right = rect->x + rect->width; | |
1252 | mswRect.bottom = rect->y + rect->height; | |
a23fd0e1 | 1253 | |
42e69d6b VZ |
1254 | ::InvalidateRect(hWnd, &mswRect, eraseBack); |
1255 | } | |
1256 | else | |
1257 | ::InvalidateRect(hWnd, NULL, eraseBack); | |
1258 | } | |
1259 | } | |
a23fd0e1 | 1260 | |
1e6feb95 VZ |
1261 | void wxWindowMSW::Update() |
1262 | { | |
1263 | if ( !::UpdateWindow(GetHwnd()) ) | |
1264 | { | |
1265 | wxLogLastError(_T("UpdateWindow")); | |
1266 | } | |
1267 | ||
8cb172b4 | 1268 | #if defined(__WIN32__) && !defined(__WXMICROWIN__) |
1e6feb95 VZ |
1269 | // just calling UpdateWindow() is not enough, what we did in our WM_PAINT |
1270 | // handler needs to be really drawn right now | |
1271 | (void)::GdiFlush(); | |
1272 | #endif // __WIN32__ | |
1273 | } | |
1274 | ||
42e69d6b VZ |
1275 | // --------------------------------------------------------------------------- |
1276 | // drag and drop | |
1277 | // --------------------------------------------------------------------------- | |
a23fd0e1 | 1278 | |
34636400 | 1279 | #if wxUSE_DRAG_AND_DROP |
a23fd0e1 | 1280 | |
1e6feb95 | 1281 | void wxWindowMSW::SetDropTarget(wxDropTarget *pDropTarget) |
42e69d6b VZ |
1282 | { |
1283 | if ( m_dropTarget != 0 ) { | |
1284 | m_dropTarget->Revoke(m_hWnd); | |
1285 | delete m_dropTarget; | |
1286 | } | |
a23fd0e1 | 1287 | |
42e69d6b VZ |
1288 | m_dropTarget = pDropTarget; |
1289 | if ( m_dropTarget != 0 ) | |
1290 | m_dropTarget->Register(m_hWnd); | |
1291 | } | |
a23fd0e1 | 1292 | |
42e69d6b | 1293 | #endif // wxUSE_DRAG_AND_DROP |
2a47d3c1 | 1294 | |
42e69d6b VZ |
1295 | // old style file-manager drag&drop support: we retain the old-style |
1296 | // DragAcceptFiles in parallel with SetDropTarget. | |
1e6feb95 | 1297 | void wxWindowMSW::DragAcceptFiles(bool accept) |
42e69d6b VZ |
1298 | { |
1299 | HWND hWnd = GetHwnd(); | |
1300 | if ( hWnd ) | |
1301 | ::DragAcceptFiles(hWnd, (BOOL)accept); | |
1302 | } | |
a23fd0e1 | 1303 | |
42e69d6b VZ |
1304 | // ---------------------------------------------------------------------------- |
1305 | // tooltips | |
1306 | // ---------------------------------------------------------------------------- | |
dbda9e86 | 1307 | |
42e69d6b | 1308 | #if wxUSE_TOOLTIPS |
2d0a075d | 1309 | |
1e6feb95 | 1310 | void wxWindowMSW::DoSetToolTip(wxToolTip *tooltip) |
42e69d6b VZ |
1311 | { |
1312 | wxWindowBase::DoSetToolTip(tooltip); | |
839b865d | 1313 | |
42e69d6b VZ |
1314 | if ( m_tooltip ) |
1315 | m_tooltip->SetWindow(this); | |
1316 | } | |
9a05fd8d | 1317 | |
42e69d6b | 1318 | #endif // wxUSE_TOOLTIPS |
9a05fd8d | 1319 | |
42e69d6b VZ |
1320 | // --------------------------------------------------------------------------- |
1321 | // moving and resizing | |
1322 | // --------------------------------------------------------------------------- | |
839b865d | 1323 | |
42e69d6b | 1324 | // Get total size |
1e6feb95 | 1325 | void wxWindowMSW::DoGetSize(int *x, int *y) const |
42e69d6b | 1326 | { |
82c9f85c VZ |
1327 | RECT rect = wxGetWindowRect(GetHwnd()); |
1328 | ||
42e69d6b VZ |
1329 | if ( x ) |
1330 | *x = rect.right - rect.left; | |
1331 | if ( y ) | |
1332 | *y = rect.bottom - rect.top; | |
1333 | } | |
1334 | ||
82c9f85c VZ |
1335 | // Get size *available for subwindows* i.e. excluding menu bar etc. |
1336 | void wxWindowMSW::DoGetClientSize(int *x, int *y) const | |
42e69d6b | 1337 | { |
82c9f85c | 1338 | RECT rect = wxGetClientRect(GetHwnd()); |
42e69d6b | 1339 | |
82c9f85c VZ |
1340 | if ( x ) |
1341 | *x = rect.right; | |
1342 | if ( y ) | |
1343 | *y = rect.bottom; | |
1344 | } | |
1345 | ||
1346 | void wxWindowMSW::DoGetPosition(int *x, int *y) const | |
1347 | { | |
1348 | RECT rect = wxGetWindowRect(GetHwnd()); | |
42e69d6b | 1349 | |
42e69d6b VZ |
1350 | POINT point; |
1351 | point.x = rect.left; | |
1352 | point.y = rect.top; | |
42e69d6b | 1353 | |
92049cd4 VZ |
1354 | // we do the adjustments with respect to the parent only for the "real" |
1355 | // children, not for the dialogs/frames | |
1356 | if ( !IsTopLevel() ) | |
42e69d6b | 1357 | { |
92049cd4 VZ |
1358 | HWND hParentWnd = 0; |
1359 | wxWindow *parent = GetParent(); | |
1360 | if ( parent ) | |
1361 | hParentWnd = GetWinHwnd(parent); | |
1362 | ||
1363 | // Since we now have the absolute screen coords, if there's a parent we | |
1364 | // must subtract its top left corner | |
1365 | if ( hParentWnd ) | |
1366 | { | |
1367 | ::ScreenToClient(hParentWnd, &point); | |
1368 | } | |
1369 | ||
89e3037c GT |
1370 | if ( parent ) |
1371 | { | |
1372 | // We may be faking the client origin. So a window that's really at (0, | |
1373 | // 30) may appear (to wxWin apps) to be at (0, 0). | |
1374 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1375 | point.x -= pt.x; | |
1376 | point.y -= pt.y; | |
1377 | } | |
42e69d6b VZ |
1378 | } |
1379 | ||
1380 | if ( x ) | |
1381 | *x = point.x; | |
1382 | if ( y ) | |
1383 | *y = point.y; | |
1384 | } | |
54bdd8b0 | 1385 | |
1e6feb95 | 1386 | void wxWindowMSW::DoScreenToClient(int *x, int *y) const |
42e69d6b VZ |
1387 | { |
1388 | POINT pt; | |
1389 | if ( x ) | |
1390 | pt.x = *x; | |
1391 | if ( y ) | |
1392 | pt.y = *y; | |
54bdd8b0 | 1393 | |
82c9f85c | 1394 | ::ScreenToClient(GetHwnd(), &pt); |
a23fd0e1 | 1395 | |
42e69d6b VZ |
1396 | if ( x ) |
1397 | *x = pt.x; | |
1398 | if ( y ) | |
1399 | *y = pt.y; | |
1400 | } | |
a23fd0e1 | 1401 | |
1e6feb95 | 1402 | void wxWindowMSW::DoClientToScreen(int *x, int *y) const |
42e69d6b VZ |
1403 | { |
1404 | POINT pt; | |
1405 | if ( x ) | |
1406 | pt.x = *x; | |
1407 | if ( y ) | |
1408 | pt.y = *y; | |
54bdd8b0 | 1409 | |
82c9f85c | 1410 | ::ClientToScreen(GetHwnd(), &pt); |
a23fd0e1 | 1411 | |
42e69d6b VZ |
1412 | if ( x ) |
1413 | *x = pt.x; | |
1414 | if ( y ) | |
1415 | *y = pt.y; | |
1416 | } | |
a23fd0e1 | 1417 | |
1e6feb95 | 1418 | void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height) |
b782f2e0 VZ |
1419 | { |
1420 | if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) ) | |
1421 | { | |
f6bcfd97 | 1422 | wxLogLastError(wxT("MoveWindow")); |
b782f2e0 VZ |
1423 | } |
1424 | } | |
1425 | ||
4438caf4 VZ |
1426 | // set the size of the window: if the dimensions are positive, just use them, |
1427 | // but if any of them is equal to -1, it means that we must find the value for | |
1428 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
1429 | // which case -1 is a valid value for x and y) | |
1430 | // | |
1431 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
1432 | // the width/height to best suit our contents, otherwise we reuse the current | |
1433 | // width/height | |
1e6feb95 | 1434 | void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
42e69d6b | 1435 | { |
4438caf4 | 1436 | // get the current size and position... |
42e69d6b VZ |
1437 | int currentX, currentY; |
1438 | GetPosition(¤tX, ¤tY); | |
1439 | int currentW,currentH; | |
1440 | GetSize(¤tW, ¤tH); | |
a23fd0e1 | 1441 | |
4438caf4 VZ |
1442 | // ... and don't do anything (avoiding flicker) if it's already ok |
1443 | if ( x == currentX && y == currentY && | |
1444 | width == currentW && height == currentH ) | |
1445 | { | |
42e69d6b | 1446 | return; |
4438caf4 | 1447 | } |
a23fd0e1 | 1448 | |
f8c03547 | 1449 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
4438caf4 | 1450 | x = currentX; |
f8c03547 | 1451 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
4438caf4 | 1452 | y = currentY; |
a23fd0e1 | 1453 | |
4438caf4 | 1454 | AdjustForParentClientOrigin(x, y, sizeFlags); |
a23fd0e1 | 1455 | |
4438caf4 | 1456 | wxSize size(-1, -1); |
42e69d6b | 1457 | if ( width == -1 ) |
4438caf4 | 1458 | { |
9e2896e5 | 1459 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) |
4438caf4 VZ |
1460 | { |
1461 | size = DoGetBestSize(); | |
1462 | width = size.x; | |
1463 | } | |
1464 | else | |
1465 | { | |
1466 | // just take the current one | |
1467 | width = currentW; | |
1468 | } | |
1469 | } | |
1470 | ||
42e69d6b | 1471 | if ( height == -1 ) |
4438caf4 | 1472 | { |
9e2896e5 | 1473 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) |
4438caf4 VZ |
1474 | { |
1475 | if ( size.x == -1 ) | |
1476 | { | |
b782f2e0 | 1477 | size = DoGetBestSize(); |
4438caf4 VZ |
1478 | } |
1479 | //else: already called DoGetBestSize() above | |
a23fd0e1 | 1480 | |
4438caf4 VZ |
1481 | height = size.y; |
1482 | } | |
1483 | else | |
1484 | { | |
1485 | // just take the current one | |
1486 | height = currentH; | |
1487 | } | |
1488 | } | |
1489 | ||
b782f2e0 | 1490 | DoMoveWindow(x, y, width, height); |
4438caf4 VZ |
1491 | } |
1492 | ||
1e6feb95 | 1493 | void wxWindowMSW::DoSetClientSize(int width, int height) |
42e69d6b VZ |
1494 | { |
1495 | wxWindow *parent = GetParent(); | |
1496 | HWND hWnd = GetHwnd(); | |
1497 | HWND hParentWnd = (HWND) 0; | |
1498 | if ( parent ) | |
1499 | hParentWnd = (HWND) parent->GetHWND(); | |
2bda0e17 | 1500 | |
42e69d6b VZ |
1501 | RECT rect; |
1502 | ::GetClientRect(hWnd, &rect); | |
a23fd0e1 | 1503 | |
42e69d6b VZ |
1504 | RECT rect2; |
1505 | GetWindowRect(hWnd, &rect2); | |
a23fd0e1 | 1506 | |
42e69d6b VZ |
1507 | // Find the difference between the entire window (title bar and all) |
1508 | // and the client area; add this to the new client size to move the | |
1509 | // window | |
1510 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
1511 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
a23fd0e1 | 1512 | |
42e69d6b VZ |
1513 | // If there's a parent, must subtract the parent's top left corner |
1514 | // since MoveWindow moves relative to the parent | |
a23fd0e1 | 1515 | |
42e69d6b VZ |
1516 | POINT point; |
1517 | point.x = rect2.left; | |
1518 | point.y = rect2.top; | |
1519 | if ( parent ) | |
1520 | { | |
1521 | ::ScreenToClient(hParentWnd, &point); | |
1522 | } | |
387a3b02 | 1523 | |
b782f2e0 | 1524 | DoMoveWindow(point.x, point.y, actual_width, actual_height); |
a23fd0e1 | 1525 | |
42e69d6b VZ |
1526 | wxSizeEvent event(wxSize(width, height), m_windowId); |
1527 | event.SetEventObject(this); | |
1528 | GetEventHandler()->ProcessEvent(event); | |
1529 | } | |
a23fd0e1 | 1530 | |
42e69d6b VZ |
1531 | // For implementation purposes - sometimes decorations make the client area |
1532 | // smaller | |
1e6feb95 | 1533 | wxPoint wxWindowMSW::GetClientAreaOrigin() const |
42e69d6b VZ |
1534 | { |
1535 | return wxPoint(0, 0); | |
1536 | } | |
a23fd0e1 | 1537 | |
42e69d6b VZ |
1538 | // --------------------------------------------------------------------------- |
1539 | // text metrics | |
1540 | // --------------------------------------------------------------------------- | |
a23fd0e1 | 1541 | |
1e6feb95 | 1542 | int wxWindowMSW::GetCharHeight() const |
42e69d6b | 1543 | { |
f6bcfd97 | 1544 | return wxGetTextMetrics(this).tmHeight; |
42e69d6b | 1545 | } |
3eddf563 | 1546 | |
1e6feb95 | 1547 | int wxWindowMSW::GetCharWidth() const |
42e69d6b | 1548 | { |
f6bcfd97 BP |
1549 | // +1 is needed because Windows apparently adds it when calculating the |
1550 | // dialog units size in pixels | |
1551 | #if wxDIALOG_UNIT_COMPATIBILITY | |
1e6feb95 | 1552 | return wxGetTextMetrics(this).tmAveCharWidth; |
f6bcfd97 BP |
1553 | #else |
1554 | return wxGetTextMetrics(this).tmAveCharWidth + 1; | |
1555 | #endif | |
42e69d6b | 1556 | } |
f4621a09 | 1557 | |
1e6feb95 | 1558 | void wxWindowMSW::GetTextExtent(const wxString& string, |
34636400 | 1559 | int *x, int *y, |
42e69d6b VZ |
1560 | int *descent, int *externalLeading, |
1561 | const wxFont *theFont) const | |
1562 | { | |
1563 | const wxFont *fontToUse = theFont; | |
1564 | if ( !fontToUse ) | |
1565 | fontToUse = &m_font; | |
634903fd | 1566 | |
42e69d6b VZ |
1567 | HWND hWnd = GetHwnd(); |
1568 | HDC dc = ::GetDC(hWnd); | |
634903fd | 1569 | |
42e69d6b VZ |
1570 | HFONT fnt = 0; |
1571 | HFONT hfontOld = 0; | |
1572 | if ( fontToUse && fontToUse->Ok() ) | |
1573 | { | |
1574 | fnt = (HFONT)((wxFont *)fontToUse)->GetResourceHandle(); // const_cast | |
1575 | if ( fnt ) | |
1576 | hfontOld = (HFONT)SelectObject(dc,fnt); | |
2bda0e17 | 1577 | } |
341c92a8 | 1578 | |
42e69d6b VZ |
1579 | SIZE sizeRect; |
1580 | TEXTMETRIC tm; | |
4438caf4 | 1581 | GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect); |
42e69d6b VZ |
1582 | GetTextMetrics(dc, &tm); |
1583 | ||
1584 | if ( fontToUse && fnt && hfontOld ) | |
1585 | SelectObject(dc, hfontOld); | |
1586 | ||
1587 | ReleaseDC(hWnd, dc); | |
1588 | ||
0655ad29 VZ |
1589 | if ( x ) |
1590 | *x = sizeRect.cx; | |
1591 | if ( y ) | |
1592 | *y = sizeRect.cy; | |
1593 | if ( descent ) | |
1594 | *descent = tm.tmDescent; | |
1595 | if ( externalLeading ) | |
1596 | *externalLeading = tm.tmExternalLeading; | |
2bda0e17 KB |
1597 | } |
1598 | ||
c455ab93 | 1599 | #if wxUSE_CARET && WXWIN_COMPATIBILITY |
42e69d6b VZ |
1600 | // --------------------------------------------------------------------------- |
1601 | // Caret manipulation | |
1602 | // --------------------------------------------------------------------------- | |
1603 | ||
1e6feb95 | 1604 | void wxWindowMSW::CreateCaret(int w, int h) |
2bda0e17 | 1605 | { |
789295bf | 1606 | SetCaret(new wxCaret(this, w, h)); |
2bda0e17 KB |
1607 | } |
1608 | ||
1e6feb95 | 1609 | void wxWindowMSW::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) |
2bda0e17 | 1610 | { |
789295bf | 1611 | wxFAIL_MSG("not implemented"); |
2bda0e17 KB |
1612 | } |
1613 | ||
1e6feb95 | 1614 | void wxWindowMSW::ShowCaret(bool show) |
2bda0e17 | 1615 | { |
789295bf VZ |
1616 | wxCHECK_RET( m_caret, "no caret to show" ); |
1617 | ||
1618 | m_caret->Show(show); | |
2bda0e17 KB |
1619 | } |
1620 | ||
1e6feb95 | 1621 | void wxWindowMSW::DestroyCaret() |
2bda0e17 | 1622 | { |
789295bf | 1623 | SetCaret(NULL); |
2bda0e17 KB |
1624 | } |
1625 | ||
1e6feb95 | 1626 | void wxWindowMSW::SetCaretPos(int x, int y) |
2bda0e17 | 1627 | { |
789295bf VZ |
1628 | wxCHECK_RET( m_caret, "no caret to move" ); |
1629 | ||
1630 | m_caret->Move(x, y); | |
2bda0e17 KB |
1631 | } |
1632 | ||
1e6feb95 | 1633 | void wxWindowMSW::GetCaretPos(int *x, int *y) const |
2d0a075d | 1634 | { |
789295bf VZ |
1635 | wxCHECK_RET( m_caret, "no caret to get position of" ); |
1636 | ||
1637 | m_caret->GetPosition(x, y); | |
42e69d6b | 1638 | } |
789295bf | 1639 | #endif // wxUSE_CARET |
2bda0e17 | 1640 | |
c50f1fb9 VZ |
1641 | // --------------------------------------------------------------------------- |
1642 | // popup menu | |
1643 | // --------------------------------------------------------------------------- | |
1644 | ||
ed45e263 VZ |
1645 | // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue |
1646 | // immediately, without waiting for the next event loop iteration | |
1647 | // | |
1648 | // NB: this function should probably be made public later as it can almost | |
1649 | // surely replace wxYield() elsewhere as well | |
1650 | static void wxYieldForCommandsOnly() | |
1651 | { | |
1652 | // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't | |
1653 | // want to process it here) | |
1654 | MSG msg; | |
1655 | while ( ::PeekMessage(&msg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE) | |
1656 | && msg.message != WM_QUIT ) | |
1657 | { | |
1658 | wxTheApp->DoMessage((WXMSG *)&msg); | |
1659 | } | |
1660 | } | |
1661 | ||
1e6feb95 VZ |
1662 | #if wxUSE_MENUS_NATIVE |
1663 | ||
1664 | bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y) | |
c50f1fb9 VZ |
1665 | { |
1666 | menu->SetInvokingWindow(this); | |
1667 | menu->UpdateUI(); | |
1668 | ||
1669 | HWND hWnd = GetHwnd(); | |
1670 | HMENU hMenu = GetHmenuOf(menu); | |
1671 | POINT point; | |
1672 | point.x = x; | |
1673 | point.y = y; | |
1674 | ::ClientToScreen(hWnd, &point); | |
1675 | wxCurrentPopupMenu = menu; | |
1676 | ::TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, hWnd, NULL); | |
ed45e263 VZ |
1677 | |
1678 | // we need to do it righ now as otherwise the events are never going to be | |
1679 | // sent to wxCurrentPopupMenu from HandleCommand() | |
1680 | // | |
1681 | // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't | |
1682 | // help and we'd still need wxYieldForCommandsOnly() as the menu may be | |
1683 | // destroyed as soon as we return (it can be a local variable in the caller | |
1684 | // for example) and so we do need to process the event immediately | |
1685 | wxYieldForCommandsOnly(); | |
1686 | ||
c50f1fb9 VZ |
1687 | wxCurrentPopupMenu = NULL; |
1688 | ||
1689 | menu->SetInvokingWindow(NULL); | |
1690 | ||
1691 | return TRUE; | |
1692 | } | |
1693 | ||
1e6feb95 VZ |
1694 | #endif // wxUSE_MENUS_NATIVE |
1695 | ||
42e69d6b VZ |
1696 | // =========================================================================== |
1697 | // pre/post message processing | |
1698 | // =========================================================================== | |
2bda0e17 | 1699 | |
1e6feb95 | 1700 | long wxWindowMSW::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
42e69d6b VZ |
1701 | { |
1702 | if ( m_oldWndProc ) | |
1703 | return ::CallWindowProc(CASTWNDPROC m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam); | |
1704 | else | |
1705 | return ::DefWindowProc(GetHwnd(), nMsg, wParam, lParam); | |
1706 | } | |
2bda0e17 | 1707 | |
1e6feb95 | 1708 | bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg) |
42e69d6b | 1709 | { |
1e6feb95 VZ |
1710 | // wxUniversal implements tab traversal itself |
1711 | #ifndef __WXUNIVERSAL__ | |
42e69d6b | 1712 | if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) ) |
2d0a075d | 1713 | { |
42e69d6b VZ |
1714 | // intercept dialog navigation keys |
1715 | MSG *msg = (MSG *)pMsg; | |
d9317fd4 VZ |
1716 | |
1717 | // here we try to do all the job which ::IsDialogMessage() usually does | |
1718 | // internally | |
d9506e77 | 1719 | #if 1 |
42e69d6b VZ |
1720 | bool bProcess = TRUE; |
1721 | if ( msg->message != WM_KEYDOWN ) | |
1722 | bProcess = FALSE; | |
c085e333 | 1723 | |
42e69d6b VZ |
1724 | if ( bProcess && (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN ) |
1725 | bProcess = FALSE; | |
a23fd0e1 | 1726 | |
42e69d6b VZ |
1727 | if ( bProcess ) |
1728 | { | |
3f7bc32b VZ |
1729 | bool bCtrlDown = wxIsCtrlDown(); |
1730 | bool bShiftDown = wxIsShiftDown(); | |
a23fd0e1 | 1731 | |
42e69d6b VZ |
1732 | // WM_GETDLGCODE: ask the control if it wants the key for itself, |
1733 | // don't process it if it's the case (except for Ctrl-Tab/Enter | |
1734 | // combinations which are always processed) | |
1735 | LONG lDlgCode = 0; | |
1736 | if ( !bCtrlDown ) | |
1737 | { | |
1738 | lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0); | |
1739 | } | |
a23fd0e1 | 1740 | |
42e69d6b VZ |
1741 | bool bForward = TRUE, |
1742 | bWindowChange = FALSE; | |
a23fd0e1 | 1743 | |
9145664b | 1744 | switch ( msg->wParam ) |
42e69d6b VZ |
1745 | { |
1746 | case VK_TAB: | |
319fefa9 VZ |
1747 | // assume that nobody wants Shift-TAB for himself - if we |
1748 | // don't do it there is no easy way for a control to grab | |
1749 | // TABs but still let Shift-TAB work as navugation key | |
1750 | if ( (lDlgCode & DLGC_WANTTAB) && !bShiftDown ) { | |
42e69d6b VZ |
1751 | bProcess = FALSE; |
1752 | } | |
1753 | else { | |
1754 | // Ctrl-Tab cycles thru notebook pages | |
1755 | bWindowChange = bCtrlDown; | |
319fefa9 | 1756 | bForward = !bShiftDown; |
42e69d6b VZ |
1757 | } |
1758 | break; | |
a23fd0e1 | 1759 | |
42e69d6b VZ |
1760 | case VK_UP: |
1761 | case VK_LEFT: | |
1762 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
1763 | bProcess = FALSE; | |
1764 | else | |
1765 | bForward = FALSE; | |
1766 | break; | |
a02eb1d2 | 1767 | |
42e69d6b VZ |
1768 | case VK_DOWN: |
1769 | case VK_RIGHT: | |
1770 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
1771 | bProcess = FALSE; | |
1772 | break; | |
2bda0e17 | 1773 | |
42e69d6b VZ |
1774 | case VK_RETURN: |
1775 | { | |
edccf428 | 1776 | if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown ) |
42e69d6b VZ |
1777 | { |
1778 | // control wants to process Enter itself, don't | |
1779 | // call IsDialogMessage() which would interpret | |
1780 | // it | |
1781 | return FALSE; | |
1782 | } | |
319fefa9 VZ |
1783 | else if ( lDlgCode & DLGC_BUTTON ) |
1784 | { | |
3e79ed96 VZ |
1785 | // let IsDialogMessage() handle this for all |
1786 | // buttons except the owner-drawn ones which it | |
1787 | // just seems to ignore | |
1788 | long style = ::GetWindowLong(msg->hwnd, GWL_STYLE); | |
1789 | if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW ) | |
1790 | { | |
1791 | // emulate the button click | |
1792 | wxWindow *btn = wxFindWinFromHandle((WXHWND)msg->hwnd); | |
1793 | if ( btn ) | |
1794 | btn->MSWCommand(BN_CLICKED, 0 /* unused */); | |
1795 | } | |
1796 | ||
319fefa9 VZ |
1797 | bProcess = FALSE; |
1798 | } | |
456bc6d9 VZ |
1799 | // FIXME: this should be handled by |
1800 | // wxNavigationKeyEvent handler and not here!! | |
c50f1fb9 VZ |
1801 | else |
1802 | { | |
91a62137 | 1803 | #if wxUSE_BUTTON |
456bc6d9 VZ |
1804 | wxButton *btn = wxDynamicCast(GetDefaultItem(), |
1805 | wxButton); | |
73927f8b | 1806 | if ( btn && btn->IsEnabled() ) |
c50f1fb9 VZ |
1807 | { |
1808 | // if we do have a default button, do press it | |
1809 | btn->MSWCommand(BN_CLICKED, 0 /* unused */); | |
1810 | ||
1811 | return TRUE; | |
1812 | } | |
91a62137 | 1813 | else // no default button |
1e6feb95 | 1814 | #endif // wxUSE_BUTTON |
91a62137 VZ |
1815 | { |
1816 | // no special function for enter and don't even | |
1817 | // let IsDialogMessage() have it: it seems to | |
1818 | // do something really strange with it | |
1819 | return FALSE; | |
1820 | } | |
1821 | } | |
42e69d6b VZ |
1822 | } |
1823 | break; | |
2bda0e17 | 1824 | |
42e69d6b VZ |
1825 | default: |
1826 | bProcess = FALSE; | |
1827 | } | |
2bda0e17 | 1828 | |
42e69d6b VZ |
1829 | if ( bProcess ) |
1830 | { | |
1831 | wxNavigationKeyEvent event; | |
1832 | event.SetDirection(bForward); | |
1833 | event.SetWindowChange(bWindowChange); | |
1834 | event.SetEventObject(this); | |
3572173c | 1835 | |
42e69d6b | 1836 | if ( GetEventHandler()->ProcessEvent(event) ) |
57c0af52 | 1837 | { |
42e69d6b | 1838 | return TRUE; |
57c0af52 | 1839 | } |
42e69d6b VZ |
1840 | } |
1841 | } | |
91a62137 | 1842 | #else // 0 |
d9317fd4 VZ |
1843 | // let ::IsDialogMessage() do almost everything and handle just the |
1844 | // things it doesn't here: Ctrl-TAB for switching notebook pages | |
1845 | if ( msg->message == WM_KEYDOWN ) | |
1846 | { | |
1847 | // don't process system keys here | |
1848 | if ( !(HIWORD(msg->lParam) & KF_ALTDOWN) ) | |
1849 | { | |
3f7bc32b | 1850 | if ( (msg->wParam == VK_TAB) && wxIsCtrlDown() ) |
d9317fd4 VZ |
1851 | { |
1852 | // find the first notebook parent and change its page | |
1853 | wxWindow *win = this; | |
1854 | wxNotebook *nbook = NULL; | |
1855 | while ( win && !nbook ) | |
1856 | { | |
1857 | nbook = wxDynamicCast(win, wxNotebook); | |
1858 | win = win->GetParent(); | |
1859 | } | |
1860 | ||
1861 | if ( nbook ) | |
1862 | { | |
3f7bc32b | 1863 | bool forward = !wxIsShiftDown(); |
d9317fd4 VZ |
1864 | |
1865 | nbook->AdvanceSelection(forward); | |
1866 | } | |
1867 | } | |
1868 | } | |
1869 | } | |
91a62137 | 1870 | #endif // 1/0 |
a23fd0e1 | 1871 | |
42e69d6b | 1872 | if ( ::IsDialogMessage(GetHwnd(), msg) ) |
f6bcfd97 BP |
1873 | { |
1874 | // IsDialogMessage() did something... | |
42e69d6b | 1875 | return TRUE; |
f6bcfd97 | 1876 | } |
42e69d6b | 1877 | } |
1e6feb95 | 1878 | #endif // __WXUNIVERSAL__ |
a23fd0e1 | 1879 | |
42e69d6b VZ |
1880 | #if wxUSE_TOOLTIPS |
1881 | if ( m_tooltip ) | |
387a3b02 | 1882 | { |
42e69d6b VZ |
1883 | // relay mouse move events to the tooltip control |
1884 | MSG *msg = (MSG *)pMsg; | |
1885 | if ( msg->message == WM_MOUSEMOVE ) | |
1886 | m_tooltip->RelayEvent(pMsg); | |
387a3b02 | 1887 | } |
42e69d6b | 1888 | #endif // wxUSE_TOOLTIPS |
a23fd0e1 | 1889 | |
42e69d6b | 1890 | return FALSE; |
387a3b02 JS |
1891 | } |
1892 | ||
1e6feb95 | 1893 | bool wxWindowMSW::MSWTranslateMessage(WXMSG* pMsg) |
387a3b02 | 1894 | { |
1e6feb95 | 1895 | #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
c50f1fb9 | 1896 | return m_acceleratorTable.Translate(this, pMsg); |
1e6feb95 VZ |
1897 | #else |
1898 | return FALSE; | |
1899 | #endif // wxUSE_ACCEL | |
387a3b02 JS |
1900 | } |
1901 | ||
a37d422a VZ |
1902 | bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG* pMsg) |
1903 | { | |
1904 | // preprocess all messages by default | |
1905 | return TRUE; | |
1906 | } | |
1907 | ||
42e69d6b VZ |
1908 | // --------------------------------------------------------------------------- |
1909 | // message params unpackers (different for Win16 and Win32) | |
1910 | // --------------------------------------------------------------------------- | |
2bda0e17 | 1911 | |
42e69d6b | 1912 | #ifdef __WIN32__ |
c085e333 | 1913 | |
1e6feb95 | 1914 | void wxWindowMSW::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b VZ |
1915 | WORD *id, WXHWND *hwnd, WORD *cmd) |
1916 | { | |
1917 | *id = LOWORD(wParam); | |
1918 | *hwnd = (WXHWND)lParam; | |
1919 | *cmd = HIWORD(wParam); | |
2bda0e17 KB |
1920 | } |
1921 | ||
1e6feb95 | 1922 | void wxWindowMSW::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 1923 | WXWORD *state, WXWORD *minimized, WXHWND *hwnd) |
2bda0e17 | 1924 | { |
42e69d6b VZ |
1925 | *state = LOWORD(wParam); |
1926 | *minimized = HIWORD(wParam); | |
1927 | *hwnd = (WXHWND)lParam; | |
2bda0e17 KB |
1928 | } |
1929 | ||
1e6feb95 | 1930 | void wxWindowMSW::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 1931 | WXWORD *code, WXWORD *pos, WXHWND *hwnd) |
2bda0e17 | 1932 | { |
42e69d6b VZ |
1933 | *code = LOWORD(wParam); |
1934 | *pos = HIWORD(wParam); | |
1935 | *hwnd = (WXHWND)lParam; | |
1936 | } | |
a23fd0e1 | 1937 | |
1e6feb95 | 1938 | void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b VZ |
1939 | WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd) |
1940 | { | |
04ef50df | 1941 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
1942 | *nCtlColor = CTLCOLOR_BTN; |
1943 | *hwnd = (WXHWND)lParam; | |
1944 | *hdc = (WXHDC)wParam; | |
04ef50df | 1945 | #endif |
2bda0e17 KB |
1946 | } |
1947 | ||
1e6feb95 | 1948 | void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 1949 | WXWORD *item, WXWORD *flags, WXHMENU *hmenu) |
2bda0e17 | 1950 | { |
42e69d6b VZ |
1951 | *item = (WXWORD)wParam; |
1952 | *flags = HIWORD(wParam); | |
1953 | *hmenu = (WXHMENU)lParam; | |
1954 | } | |
c085e333 | 1955 | |
42e69d6b | 1956 | #else // Win16 |
341c92a8 | 1957 | |
1e6feb95 | 1958 | void wxWindowMSW::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b VZ |
1959 | WXWORD *id, WXHWND *hwnd, WXWORD *cmd) |
1960 | { | |
1961 | *id = (WXWORD)wParam; | |
1962 | *hwnd = (WXHWND)LOWORD(lParam); | |
1963 | *cmd = HIWORD(lParam); | |
2bda0e17 KB |
1964 | } |
1965 | ||
1e6feb95 | 1966 | void wxWindowMSW::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 1967 | WXWORD *state, WXWORD *minimized, WXHWND *hwnd) |
2bda0e17 | 1968 | { |
42e69d6b VZ |
1969 | *state = (WXWORD)wParam; |
1970 | *minimized = LOWORD(lParam); | |
1971 | *hwnd = (WXHWND)HIWORD(lParam); | |
2bda0e17 KB |
1972 | } |
1973 | ||
1e6feb95 | 1974 | void wxWindowMSW::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 1975 | WXWORD *code, WXWORD *pos, WXHWND *hwnd) |
2bda0e17 | 1976 | { |
42e69d6b VZ |
1977 | *code = (WXWORD)wParam; |
1978 | *pos = LOWORD(lParam); | |
1979 | *hwnd = (WXHWND)HIWORD(lParam); | |
1980 | } | |
c085e333 | 1981 | |
1e6feb95 | 1982 | void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b VZ |
1983 | WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd) |
1984 | { | |
25889d3c | 1985 | *hwnd = (WXHWND)LOWORD(lParam); |
42e69d6b VZ |
1986 | *nCtlColor = (int)HIWORD(lParam); |
1987 | *hdc = (WXHDC)wParam; | |
2bda0e17 KB |
1988 | } |
1989 | ||
1e6feb95 | 1990 | void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam, |
42e69d6b | 1991 | WXWORD *item, WXWORD *flags, WXHMENU *hmenu) |
2bda0e17 | 1992 | { |
42e69d6b VZ |
1993 | *item = (WXWORD)wParam; |
1994 | *flags = LOWORD(lParam); | |
1995 | *hmenu = (WXHMENU)HIWORD(lParam); | |
1996 | } | |
2d0a075d | 1997 | |
42e69d6b | 1998 | #endif // Win32/16 |
c085e333 | 1999 | |
42e69d6b VZ |
2000 | // --------------------------------------------------------------------------- |
2001 | // Main wxWindows window proc and the window proc for wxWindow | |
2002 | // --------------------------------------------------------------------------- | |
2bda0e17 | 2003 | |
42e69d6b VZ |
2004 | // Hook for new window just as it's being created, when the window isn't yet |
2005 | // associated with the handle | |
1e6feb95 | 2006 | wxWindowMSW *wxWndHook = NULL; |
42e69d6b VZ |
2007 | |
2008 | // Main window proc | |
3135f4a7 | 2009 | LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
2bda0e17 | 2010 | { |
42e69d6b VZ |
2011 | // trace all messages - useful for the debugging |
2012 | #ifdef __WXDEBUG__ | |
223d09f6 | 2013 | wxLogTrace(wxTraceMessages, wxT("Processing %s(wParam=%8lx, lParam=%8lx)"), |
42e69d6b VZ |
2014 | wxGetMessageName(message), wParam, lParam); |
2015 | #endif // __WXDEBUG__ | |
2bda0e17 | 2016 | |
1e6feb95 | 2017 | wxWindowMSW *wnd = wxFindWinFromHandle((WXHWND) hWnd); |
c085e333 | 2018 | |
42e69d6b VZ |
2019 | // when we get the first message for the HWND we just created, we associate |
2020 | // it with wxWindow stored in wxWndHook | |
2021 | if ( !wnd && wxWndHook ) | |
2d0a075d | 2022 | { |
c7527e3f JS |
2023 | #if 0 // def __WXDEBUG__ |
2024 | char buf[512]; | |
2025 | ::GetClassNameA((HWND) hWnd, buf, 512); | |
2026 | wxString className(buf); | |
2027 | #endif | |
2028 | ||
42e69d6b VZ |
2029 | wxAssociateWinWithHandle(hWnd, wxWndHook); |
2030 | wnd = wxWndHook; | |
2031 | wxWndHook = NULL; | |
2032 | wnd->SetHWND((WXHWND)hWnd); | |
2d0a075d | 2033 | } |
2bda0e17 | 2034 | |
42e69d6b | 2035 | LRESULT rc; |
a23fd0e1 | 2036 | |
42e69d6b VZ |
2037 | // Stop right here if we don't have a valid handle in our wxWindow object. |
2038 | if ( wnd && !wnd->GetHWND() ) | |
2d0a075d | 2039 | { |
42e69d6b VZ |
2040 | // FIXME: why do we do this? |
2041 | wnd->SetHWND((WXHWND) hWnd); | |
2042 | rc = wnd->MSWDefWindowProc(message, wParam, lParam ); | |
2043 | wnd->SetHWND(0); | |
a23fd0e1 VZ |
2044 | } |
2045 | else | |
2046 | { | |
42e69d6b VZ |
2047 | if ( wnd ) |
2048 | rc = wnd->MSWWindowProc(message, wParam, lParam); | |
2049 | else | |
2050 | rc = DefWindowProc( hWnd, message, wParam, lParam ); | |
2d0a075d | 2051 | } |
2bda0e17 | 2052 | |
42e69d6b | 2053 | return rc; |
f7bd2698 JS |
2054 | } |
2055 | ||
1e6feb95 | 2056 | long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
f7bd2698 | 2057 | { |
42e69d6b VZ |
2058 | // did we process the message? |
2059 | bool processed = FALSE; | |
f7bd2698 | 2060 | |
42e69d6b VZ |
2061 | // the return value |
2062 | union | |
2bda0e17 | 2063 | { |
42e69d6b VZ |
2064 | bool allow; |
2065 | long result; | |
2066 | WXHICON hIcon; | |
2067 | WXHBRUSH hBrush; | |
2068 | } rc; | |
2bda0e17 | 2069 | |
42e69d6b VZ |
2070 | // for most messages we should return 0 when we do process the message |
2071 | rc.result = 0; | |
2bda0e17 | 2072 | |
42e69d6b | 2073 | switch ( message ) |
39136494 | 2074 | { |
42e69d6b VZ |
2075 | case WM_CREATE: |
2076 | { | |
2077 | bool mayCreate; | |
2078 | processed = HandleCreate((WXLPCREATESTRUCT)lParam, &mayCreate); | |
2079 | if ( processed ) | |
2080 | { | |
2081 | // return 0 to allow window creation | |
2082 | rc.result = mayCreate ? 0 : -1; | |
2083 | } | |
2084 | } | |
2085 | break; | |
47cbd6da | 2086 | |
42e69d6b | 2087 | case WM_DESTROY: |
ad4297f3 VZ |
2088 | // never set processed to TRUE and *always* pass WM_DESTROY to |
2089 | // DefWindowProc() as Windows may do some internal cleanup when | |
2090 | // processing it and failing to pass the message along may cause | |
2091 | // memory and resource leaks! | |
2092 | (void)HandleDestroy(); | |
42e69d6b VZ |
2093 | break; |
2094 | ||
2095 | case WM_MOVE: | |
132cb640 | 2096 | processed = HandleMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); |
42e69d6b | 2097 | break; |
47cbd6da | 2098 | |
42e69d6b | 2099 | case WM_SIZE: |
1e6feb95 VZ |
2100 | switch ( wParam ) |
2101 | { | |
2102 | case SIZE_MAXHIDE: | |
2103 | case SIZE_MAXSHOW: | |
2104 | // we're not interested in these messages at all | |
2105 | break; | |
2106 | ||
2107 | case SIZE_MINIMIZED: | |
2108 | // we shouldn't send sizev events for these messages as the | |
2109 | // client size may be negative which breaks existing code | |
2110 | // | |
2111 | // OTOH we might send another (wxMinimizedEvent?) one or | |
2112 | // add an additional parameter to wxSizeEvent if this is | |
2113 | // useful to anybody | |
2114 | break; | |
2115 | ||
2116 | default: | |
2117 | wxFAIL_MSG( _T("unexpected WM_SIZE parameter") ); | |
2118 | // fall through nevertheless | |
2119 | ||
2120 | case SIZE_MAXIMIZED: | |
2121 | case SIZE_RESTORED: | |
2122 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), | |
2123 | wParam); | |
2124 | } | |
2125 | break; | |
2126 | ||
8a46f9b1 | 2127 | #ifndef __WXMICROWIN__ |
1e6feb95 VZ |
2128 | case WM_ACTIVATEAPP: |
2129 | wxTheApp->SetActive(wParam != 0, FindFocus()); | |
42e69d6b | 2130 | break; |
8a46f9b1 | 2131 | #endif |
47cbd6da | 2132 | |
42e69d6b | 2133 | case WM_ACTIVATE: |
341c92a8 | 2134 | { |
42e69d6b VZ |
2135 | WXWORD state, minimized; |
2136 | WXHWND hwnd; | |
2137 | UnpackActivate(wParam, lParam, &state, &minimized, &hwnd); | |
2138 | ||
2139 | processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd); | |
341c92a8 | 2140 | } |
42e69d6b | 2141 | break; |
341c92a8 | 2142 | |
42e69d6b VZ |
2143 | case WM_SETFOCUS: |
2144 | processed = HandleSetFocus((WXHWND)(HWND)wParam); | |
2145 | break; | |
47cbd6da | 2146 | |
42e69d6b VZ |
2147 | case WM_KILLFOCUS: |
2148 | processed = HandleKillFocus((WXHWND)(HWND)wParam); | |
2149 | break; | |
47cbd6da | 2150 | |
42e69d6b VZ |
2151 | case WM_PAINT: |
2152 | processed = HandlePaint(); | |
2153 | break; | |
47cbd6da | 2154 | |
42e69d6b VZ |
2155 | case WM_CLOSE: |
2156 | // don't let the DefWindowProc() destroy our window - we'll do it | |
2157 | // ourselves in ~wxWindow | |
2158 | processed = TRUE; | |
2159 | rc.result = TRUE; | |
2160 | break; | |
47cbd6da | 2161 | |
42e69d6b VZ |
2162 | case WM_SHOWWINDOW: |
2163 | processed = HandleShow(wParam != 0, (int)lParam); | |
2164 | break; | |
3a19e16d | 2165 | |
42e69d6b | 2166 | case WM_MOUSEMOVE: |
132cb640 VZ |
2167 | processed = HandleMouseMove(GET_X_LPARAM(lParam), |
2168 | GET_Y_LPARAM(lParam), | |
2169 | wParam); | |
2170 | break; | |
0d0512bd | 2171 | |
d2c52078 RD |
2172 | #if wxUSE_MOUSEWHEEL |
2173 | case WM_MOUSEWHEEL: | |
2174 | processed = HandleMouseWheel(wParam, lParam); | |
2175 | break; | |
2176 | #endif | |
2177 | ||
42e69d6b VZ |
2178 | case WM_LBUTTONDOWN: |
2179 | case WM_LBUTTONUP: | |
2180 | case WM_LBUTTONDBLCLK: | |
2181 | case WM_RBUTTONDOWN: | |
2182 | case WM_RBUTTONUP: | |
2183 | case WM_RBUTTONDBLCLK: | |
2184 | case WM_MBUTTONDOWN: | |
2185 | case WM_MBUTTONUP: | |
2186 | case WM_MBUTTONDBLCLK: | |
d0a3d109 VZ |
2187 | { |
2188 | processed = FALSE; | |
98363307 | 2189 | #ifdef __WXMICROWIN__ |
cd4453e5 VZ |
2190 | // MicroWindows seems to ignore the fact that a window is |
2191 | // disabled. So catch mouse events and throw them away if | |
2192 | // necessary. | |
d0a3d109 VZ |
2193 | wxWindowMSW* win = this; |
2194 | while (win) | |
2195 | { | |
2196 | if (!win->IsEnabled()) | |
2197 | { | |
2198 | processed = TRUE; | |
2199 | break; | |
2200 | } | |
2201 | win = win->GetParent(); | |
2202 | if (win && win->IsTopLevel()) | |
2203 | break; | |
2204 | } | |
cd4453e5 | 2205 | #endif // __WXMICROWIN__ |
d0a3d109 VZ |
2206 | if (!processed) |
2207 | { | |
98363307 JS |
2208 | if (message == WM_LBUTTONDOWN && AcceptsFocus()) |
2209 | SetFocus(); | |
2210 | processed = HandleMouseEvent(message, | |
132cb640 VZ |
2211 | GET_X_LPARAM(lParam), |
2212 | GET_Y_LPARAM(lParam), | |
d0a3d109 VZ |
2213 | wParam); |
2214 | } | |
98363307 | 2215 | break; |
d0a3d109 | 2216 | } |
47cbd6da | 2217 | |
98363307 JS |
2218 | #ifdef __WXMICROWIN__ |
2219 | case WM_NCLBUTTONDOWN: | |
2220 | case WM_NCLBUTTONUP: | |
2221 | case WM_NCLBUTTONDBLCLK: | |
2222 | case WM_NCRBUTTONDOWN: | |
2223 | case WM_NCRBUTTONUP: | |
2224 | case WM_NCRBUTTONDBLCLK: | |
2225 | #if 0 | |
2226 | case WM_NCMBUTTONDOWN: | |
2227 | case WM_NCMBUTTONUP: | |
2228 | case WM_NCMBUTTONDBLCLK: | |
d0a3d109 VZ |
2229 | #endif |
2230 | { | |
2231 | // MicroWindows seems to ignore the fact that a window | |
2232 | // is disabled. So catch mouse events and throw them away if necessary. | |
2233 | processed = FALSE; | |
2234 | wxWindowMSW* win = this; | |
2235 | while (win) | |
2236 | { | |
2237 | if (!win->IsEnabled()) | |
2238 | { | |
2239 | processed = TRUE; | |
2240 | break; | |
2241 | } | |
2242 | win = win->GetParent(); | |
2243 | if (win && win->IsTopLevel()) | |
2244 | break; | |
2245 | } | |
2246 | break; | |
98363307 | 2247 | } |
cd4453e5 | 2248 | #endif // __WXMICROWIN__ |
d0a3d109 | 2249 | |
cd4453e5 | 2250 | #ifdef MM_JOY1MOVE |
42e69d6b VZ |
2251 | case MM_JOY1MOVE: |
2252 | case MM_JOY2MOVE: | |
2253 | case MM_JOY1ZMOVE: | |
2254 | case MM_JOY2ZMOVE: | |
2255 | case MM_JOY1BUTTONDOWN: | |
2256 | case MM_JOY2BUTTONDOWN: | |
2257 | case MM_JOY1BUTTONUP: | |
2258 | case MM_JOY2BUTTONUP: | |
132cb640 VZ |
2259 | processed = HandleJoystickEvent(message, |
2260 | GET_X_LPARAM(lParam), | |
2261 | GET_Y_LPARAM(lParam), | |
2262 | wParam); | |
42e69d6b | 2263 | break; |
cd4453e5 | 2264 | #endif // __WXMICROWIN__ |
47cbd6da | 2265 | |
42e69d6b VZ |
2266 | case WM_SYSCOMMAND: |
2267 | processed = HandleSysCommand(wParam, lParam); | |
2268 | break; | |
2a47d3c1 | 2269 | |
42e69d6b VZ |
2270 | case WM_COMMAND: |
2271 | { | |
2272 | WORD id, cmd; | |
2273 | WXHWND hwnd; | |
2274 | UnpackCommand(wParam, lParam, &id, &hwnd, &cmd); | |
47cbd6da | 2275 | |
42e69d6b VZ |
2276 | processed = HandleCommand(id, cmd, hwnd); |
2277 | } | |
2278 | break; | |
7d532b0c | 2279 | |
42e69d6b VZ |
2280 | #ifdef __WIN95__ |
2281 | case WM_NOTIFY: | |
2282 | processed = HandleNotify((int)wParam, lParam, &rc.result); | |
2283 | break; | |
2284 | #endif // Win95 | |
2bda0e17 | 2285 | |
42e69d6b | 2286 | // for these messages we must return TRUE if process the message |
cd4453e5 | 2287 | #ifdef WM_DRAWITEM |
42e69d6b VZ |
2288 | case WM_DRAWITEM: |
2289 | case WM_MEASUREITEM: | |
2290 | { | |
2291 | int idCtrl = (UINT)wParam; | |
2292 | if ( message == WM_DRAWITEM ) | |
2293 | { | |
2294 | processed = MSWOnDrawItem(idCtrl, | |
2295 | (WXDRAWITEMSTRUCT *)lParam); | |
2296 | } | |
2297 | else | |
2298 | { | |
2299 | processed = MSWOnMeasureItem(idCtrl, | |
2300 | (WXMEASUREITEMSTRUCT *)lParam); | |
2301 | } | |
57a7b7c1 | 2302 | |
42e69d6b VZ |
2303 | if ( processed ) |
2304 | rc.result = TRUE; | |
2305 | } | |
2306 | break; | |
cd4453e5 VZ |
2307 | #endif // defined(WM_DRAWITEM) |
2308 | ||
9bf84618 | 2309 | case WM_GETDLGCODE: |
101f488c | 2310 | if ( m_lDlgCode ) |
9bf84618 | 2311 | { |
101f488c | 2312 | rc.result = m_lDlgCode; |
9bf84618 VZ |
2313 | processed = TRUE; |
2314 | } | |
101f488c | 2315 | //else: get the dlg code from the DefWindowProc() |
9bf84618 VZ |
2316 | break; |
2317 | ||
4004f41e | 2318 | case WM_SYSKEYDOWN: |
42e69d6b VZ |
2319 | case WM_KEYDOWN: |
2320 | // If this has been processed by an event handler, | |
2321 | // return 0 now (we've handled it). | |
2322 | if ( HandleKeyDown((WORD) wParam, lParam) ) | |
2d0a075d | 2323 | { |
42e69d6b VZ |
2324 | processed = TRUE; |
2325 | ||
2d0a075d JS |
2326 | break; |
2327 | } | |
81d66cf3 | 2328 | |
42e69d6b VZ |
2329 | // we consider these message "not interesting" to OnChar |
2330 | if ( wParam == VK_SHIFT || wParam == VK_CONTROL ) | |
2331 | { | |
2332 | processed = TRUE; | |
81d66cf3 | 2333 | |
42e69d6b VZ |
2334 | break; |
2335 | } | |
debe6624 | 2336 | |
42e69d6b VZ |
2337 | switch ( wParam ) |
2338 | { | |
2339 | // avoid duplicate messages to OnChar for these ASCII keys: they | |
2340 | // will be translated by TranslateMessage() and received in WM_CHAR | |
2341 | case VK_ESCAPE: | |
2342 | case VK_SPACE: | |
2343 | case VK_RETURN: | |
2344 | case VK_BACK: | |
2345 | case VK_TAB: | |
882a8f40 VZ |
2346 | case VK_ADD: |
2347 | case VK_SUBTRACT: | |
edccf428 VZ |
2348 | // but set processed to FALSE, not TRUE to still pass them to |
2349 | // the control's default window proc - otherwise built-in | |
2350 | // keyboard handling won't work | |
2351 | processed = FALSE; | |
2bda0e17 | 2352 | |
42e69d6b | 2353 | break; |
2bda0e17 | 2354 | |
42e69d6b VZ |
2355 | #ifdef VK_APPS |
2356 | // special case of VK_APPS: treat it the same as right mouse | |
2357 | // click because both usually pop up a context menu | |
2358 | case VK_APPS: | |
2359 | { | |
4aff28fc VZ |
2360 | WPARAM flags; |
2361 | int x, y; | |
2362 | ||
2363 | TranslateKbdEventToMouse(this, &x, &y, &flags); | |
2364 | processed = HandleMouseEvent(WM_RBUTTONDOWN, x, y, flags); | |
42e69d6b VZ |
2365 | } |
2366 | break; | |
2367 | #endif // VK_APPS | |
2bda0e17 | 2368 | |
42e69d6b VZ |
2369 | case VK_LEFT: |
2370 | case VK_RIGHT: | |
2371 | case VK_DOWN: | |
2372 | case VK_UP: | |
2373 | default: | |
2374 | processed = HandleChar((WORD)wParam, lParam); | |
2375 | } | |
2376 | break; | |
2bda0e17 | 2377 | |
4004f41e | 2378 | case WM_SYSKEYUP: |
42e69d6b | 2379 | case WM_KEYUP: |
4aff28fc VZ |
2380 | #ifdef VK_APPS |
2381 | // special case of VK_APPS: treat it the same as right mouse button | |
2382 | if ( wParam == VK_APPS ) | |
2383 | { | |
2384 | WPARAM flags; | |
2385 | int x, y; | |
2386 | ||
2387 | TranslateKbdEventToMouse(this, &x, &y, &flags); | |
2388 | processed = HandleMouseEvent(WM_RBUTTONUP, x, y, flags); | |
2389 | } | |
2390 | else | |
2391 | #endif // VK_APPS | |
2392 | { | |
2393 | processed = HandleKeyUp((WORD) wParam, lParam); | |
2394 | } | |
42e69d6b | 2395 | break; |
debe6624 | 2396 | |
170cbe33 | 2397 | case WM_SYSCHAR: |
42e69d6b VZ |
2398 | case WM_CHAR: // Always an ASCII character |
2399 | processed = HandleChar((WORD)wParam, lParam, TRUE); | |
2400 | break; | |
2bda0e17 | 2401 | |
42e69d6b VZ |
2402 | case WM_HSCROLL: |
2403 | case WM_VSCROLL: | |
a23fd0e1 | 2404 | { |
42e69d6b VZ |
2405 | WXWORD code, pos; |
2406 | WXHWND hwnd; | |
2407 | UnpackScroll(wParam, lParam, &code, &pos, &hwnd); | |
2bda0e17 | 2408 | |
42e69d6b VZ |
2409 | processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL |
2410 | : wxVERTICAL, | |
2411 | code, pos, hwnd); | |
a23fd0e1 | 2412 | } |
42e69d6b | 2413 | break; |
a23fd0e1 | 2414 | |
42e69d6b | 2415 | // CTLCOLOR messages are sent by children to query the parent for their |
04ef50df JS |
2416 | // colors#ifndef __WXMICROWIN__ |
2417 | #ifndef __WXMICROWIN__ | |
42e69d6b VZ |
2418 | #ifdef __WIN32__ |
2419 | case WM_CTLCOLORMSGBOX: | |
2420 | case WM_CTLCOLOREDIT: | |
2421 | case WM_CTLCOLORLISTBOX: | |
2422 | case WM_CTLCOLORBTN: | |
2423 | case WM_CTLCOLORDLG: | |
2424 | case WM_CTLCOLORSCROLLBAR: | |
2425 | case WM_CTLCOLORSTATIC: | |
2426 | #else // Win16 | |
2427 | case WM_CTLCOLOR: | |
2428 | #endif // Win32/16 | |
a23fd0e1 | 2429 | { |
42e69d6b VZ |
2430 | WXWORD nCtlColor; |
2431 | WXHDC hdc; | |
2432 | WXHWND hwnd; | |
2433 | UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd); | |
2434 | ||
2435 | processed = HandleCtlColor(&rc.hBrush, | |
2436 | (WXHDC)hdc, | |
2437 | (WXHWND)hwnd, | |
2438 | nCtlColor, | |
2439 | message, | |
2440 | wParam, | |
2441 | lParam); | |
a23fd0e1 | 2442 | } |
42e69d6b | 2443 | break; |
cd4453e5 | 2444 | #endif // !__WXMICROWIN__ |
debe6624 | 2445 | |
42e69d6b VZ |
2446 | // the return value for this message is ignored |
2447 | case WM_SYSCOLORCHANGE: | |
2448 | processed = HandleSysColorChange(); | |
2449 | break; | |
2bda0e17 | 2450 | |
42e69d6b VZ |
2451 | case WM_PALETTECHANGED: |
2452 | processed = HandlePaletteChanged((WXHWND) (HWND) wParam); | |
2453 | break; | |
2bda0e17 | 2454 | |
42e69d6b VZ |
2455 | case WM_QUERYNEWPALETTE: |
2456 | processed = HandleQueryNewPalette(); | |
2457 | break; | |
2bda0e17 | 2458 | |
42e69d6b VZ |
2459 | case WM_ERASEBKGND: |
2460 | processed = HandleEraseBkgnd((WXHDC)(HDC)wParam); | |
2461 | if ( processed ) | |
2462 | { | |
2463 | // we processed the message, i.e. erased the background | |
2464 | rc.result = TRUE; | |
2465 | } | |
2466 | break; | |
debe6624 | 2467 | |
42e69d6b VZ |
2468 | case WM_DROPFILES: |
2469 | processed = HandleDropFiles(wParam); | |
2470 | break; | |
2bda0e17 | 2471 | |
42e69d6b VZ |
2472 | case WM_INITDIALOG: |
2473 | processed = HandleInitDialog((WXHWND)(HWND)wParam); | |
a23fd0e1 | 2474 | |
42e69d6b VZ |
2475 | if ( processed ) |
2476 | { | |
2477 | // we never set focus from here | |
2478 | rc.result = FALSE; | |
2479 | } | |
2480 | break; | |
a23fd0e1 | 2481 | |
42e69d6b VZ |
2482 | case WM_QUERYENDSESSION: |
2483 | processed = HandleQueryEndSession(lParam, &rc.allow); | |
2484 | break; | |
2bda0e17 | 2485 | |
42e69d6b VZ |
2486 | case WM_ENDSESSION: |
2487 | processed = HandleEndSession(wParam != 0, lParam); | |
2488 | break; | |
2bda0e17 | 2489 | |
42e69d6b | 2490 | case WM_GETMINMAXINFO: |
25889d3c | 2491 | processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam); |
42e69d6b | 2492 | break; |
debe6624 | 2493 | |
42e69d6b VZ |
2494 | case WM_SETCURSOR: |
2495 | processed = HandleSetCursor((WXHWND)(HWND)wParam, | |
2496 | LOWORD(lParam), // hit test | |
2497 | HIWORD(lParam)); // mouse msg | |
2498 | ||
2499 | if ( processed ) | |
2500 | { | |
2501 | // returning TRUE stops the DefWindowProc() from further | |
2502 | // processing this message - exactly what we need because we've | |
2503 | // just set the cursor. | |
2504 | rc.result = TRUE; | |
2505 | } | |
2506 | break; | |
4cdc2c13 | 2507 | |
04ef50df | 2508 | #if defined(__WIN32__) && defined(WM_HELP) |
b96340e6 | 2509 | case WM_HELP: |
b96340e6 | 2510 | { |
4cdc2c13 VZ |
2511 | HELPINFO* info = (HELPINFO*) lParam; |
2512 | // Don't yet process menu help events, just windows | |
2513 | if (info->iContextType == HELPINFO_WINDOW) | |
b96340e6 | 2514 | { |
24ce4c18 | 2515 | wxWindowMSW* subjectOfHelp = this; |
4cdc2c13 VZ |
2516 | bool eventProcessed = FALSE; |
2517 | while (subjectOfHelp && !eventProcessed) | |
2518 | { | |
2519 | wxHelpEvent helpEvent(wxEVT_HELP, | |
2520 | subjectOfHelp->GetId(), | |
2521 | wxPoint(info->MousePos.x, | |
2522 | info->MousePos.y) ); | |
2523 | helpEvent.SetEventObject(this); | |
2524 | eventProcessed = | |
2525 | GetEventHandler()->ProcessEvent(helpEvent); | |
2526 | ||
2527 | // Go up the window hierarchy until the event is | |
2528 | // handled (or not) | |
2529 | subjectOfHelp = subjectOfHelp->GetParent(); | |
2530 | } | |
b96340e6 | 2531 | |
4cdc2c13 | 2532 | processed = eventProcessed; |
b96340e6 | 2533 | } |
4cdc2c13 VZ |
2534 | else if (info->iContextType == HELPINFO_MENUITEM) |
2535 | { | |
2536 | wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId); | |
2537 | helpEvent.SetEventObject(this); | |
2538 | processed = GetEventHandler()->ProcessEvent(helpEvent); | |
69231000 | 2539 | |
4cdc2c13 VZ |
2540 | } |
2541 | //else: processed is already FALSE | |
b96340e6 | 2542 | } |
b96340e6 | 2543 | break; |
4cdc2c13 | 2544 | |
69231000 | 2545 | case WM_CONTEXTMENU: |
4cdc2c13 VZ |
2546 | { |
2547 | // we don't convert from screen to client coordinates as | |
2548 | // the event may be handled by a parent window | |
2549 | wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); | |
2550 | ||
2551 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt); | |
0d6ae333 | 2552 | processed = GetEventHandler()->ProcessEvent(evtCtx); |
4cdc2c13 | 2553 | } |
69231000 | 2554 | break; |
4cdc2c13 | 2555 | #endif // __WIN32__ |
d1c80692 VZ |
2556 | |
2557 | #ifdef __WXUNIVERSAL__ | |
2558 | case WM_NCHITTEST: | |
2559 | // we shouldn't allow the windows which don't want to get focus to | |
2560 | // get it | |
2561 | if ( !AcceptsFocus() ) | |
2562 | { | |
2563 | rc.result = HTTRANSPARENT; | |
2564 | processed = TRUE; | |
2565 | } | |
2566 | break; | |
2567 | #endif // __WXUNIVERSAL__ | |
a23fd0e1 | 2568 | } |
2d0a075d | 2569 | |
42e69d6b | 2570 | if ( !processed ) |
2d0a075d | 2571 | { |
42e69d6b | 2572 | #ifdef __WXDEBUG__ |
223d09f6 | 2573 | wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."), |
42e69d6b VZ |
2574 | wxGetMessageName(message)); |
2575 | #endif // __WXDEBUG__ | |
2576 | rc.result = MSWDefWindowProc(message, wParam, lParam); | |
a23fd0e1 | 2577 | } |
2bda0e17 | 2578 | |
42e69d6b | 2579 | return rc.result; |
2bda0e17 KB |
2580 | } |
2581 | ||
42e69d6b VZ |
2582 | // Dialog window proc |
2583 | LONG APIENTRY _EXPORT | |
33ac7e6f | 2584 | wxDlgProc(HWND WXUNUSED(hWnd), UINT message, WPARAM WXUNUSED(wParam), LPARAM WXUNUSED(lParam)) |
2bda0e17 | 2585 | { |
42e69d6b | 2586 | if ( message == WM_INITDIALOG ) |
2bda0e17 | 2587 | { |
42e69d6b VZ |
2588 | // for this message, returning TRUE tells system to set focus to the |
2589 | // first control in the dialog box | |
2590 | return TRUE; | |
2d0a075d | 2591 | } |
42e69d6b | 2592 | else |
2d0a075d | 2593 | { |
42e69d6b VZ |
2594 | // for all the other ones, FALSE means that we didn't process the |
2595 | // message | |
2596 | return 0; | |
2d0a075d | 2597 | } |
2bda0e17 KB |
2598 | } |
2599 | ||
42e69d6b VZ |
2600 | wxList *wxWinHandleList = NULL; |
2601 | wxWindow *wxFindWinFromHandle(WXHWND hWnd) | |
4ce81a75 | 2602 | { |
42e69d6b VZ |
2603 | wxNode *node = wxWinHandleList->Find((long)hWnd); |
2604 | if ( !node ) | |
2605 | return NULL; | |
2606 | return (wxWindow *)node->Data(); | |
2607 | } | |
4ce81a75 | 2608 | |
c7527e3f JS |
2609 | #if 0 // def __WXDEBUG__ |
2610 | static int gs_AssociationCount = 0; | |
2611 | #endif | |
2612 | ||
1e6feb95 | 2613 | void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win) |
42e69d6b VZ |
2614 | { |
2615 | // adding NULL hWnd is (first) surely a result of an error and | |
2616 | // (secondly) breaks menu command processing | |
2617 | wxCHECK_RET( hWnd != (HWND)NULL, | |
223d09f6 | 2618 | wxT("attempt to add a NULL hWnd to window list ignored") ); |
4ce81a75 | 2619 | |
c7527e3f JS |
2620 | |
2621 | wxWindow *oldWin = wxFindWinFromHandle((WXHWND) hWnd); | |
2622 | if ( oldWin && (oldWin != win) ) | |
2623 | { | |
2624 | wxString str(win->GetClassInfo()->GetClassName()); | |
f5166ed4 | 2625 | wxLogError(wxT("Bug! Found existing HWND %X for new window of class %s"), (int) hWnd, (const wxChar*) str); |
c7527e3f JS |
2626 | } |
2627 | else if (!oldWin) | |
2628 | { | |
2629 | #if 0 // def __WXDEBUG__ | |
2630 | gs_AssociationCount ++; | |
2631 | wxLogDebug("+ Association %d", gs_AssociationCount); | |
2632 | #endif | |
2633 | ||
42e69d6b | 2634 | wxWinHandleList->Append((long)hWnd, win); |
c7527e3f | 2635 | } |
42e69d6b | 2636 | } |
4ce81a75 | 2637 | |
1e6feb95 | 2638 | void wxRemoveHandleAssociation(wxWindowMSW *win) |
42e69d6b | 2639 | { |
c7527e3f JS |
2640 | #if 0 // def __WXDEBUG__ |
2641 | if (wxWinHandleList->Member(win)) | |
2642 | { | |
2643 | wxLogDebug("- Association %d", gs_AssociationCount); | |
2644 | gs_AssociationCount --; | |
2645 | } | |
2646 | #endif | |
42e69d6b | 2647 | wxWinHandleList->DeleteObject(win); |
4ce81a75 JS |
2648 | } |
2649 | ||
42e69d6b VZ |
2650 | // Default destroyer - override if you destroy it in some other way |
2651 | // (e.g. with MDI child windows) | |
1e6feb95 | 2652 | void wxWindowMSW::MSWDestroyWindow() |
4ce81a75 | 2653 | { |
42e69d6b | 2654 | } |
4ce81a75 | 2655 | |
1e6feb95 | 2656 | void wxWindowMSW::MSWDetachWindowMenu() |
42e69d6b | 2657 | { |
8cb172b4 | 2658 | #ifndef __WXUNIVERSAL__ |
42e69d6b | 2659 | if ( m_hMenu ) |
4ce81a75 | 2660 | { |
aa44b261 | 2661 | wxChar buf[1024]; |
42e69d6b | 2662 | HMENU hMenu = (HMENU)m_hMenu; |
4ce81a75 | 2663 | |
42e69d6b | 2664 | int N = ::GetMenuItemCount(hMenu); |
aa44b261 | 2665 | for ( int i = 0; i < N; i++ ) |
42e69d6b | 2666 | { |
aa44b261 | 2667 | if ( !::GetMenuString(hMenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) ) |
42e69d6b | 2668 | { |
223d09f6 | 2669 | wxLogLastError(wxT("GetMenuString")); |
4ce81a75 | 2670 | |
42e69d6b VZ |
2671 | continue; |
2672 | } | |
4ce81a75 | 2673 | |
9318daf2 | 2674 | if ( wxStrcmp(buf, _("&Window")) == 0 ) |
42e69d6b | 2675 | { |
aa44b261 VZ |
2676 | if ( !::RemoveMenu(hMenu, i, MF_BYPOSITION) ) |
2677 | { | |
2678 | wxLogLastError(wxT("RemoveMenu")); | |
2679 | } | |
4ce81a75 | 2680 | |
42e69d6b VZ |
2681 | break; |
2682 | } | |
2683 | } | |
4ce81a75 | 2684 | } |
8cb172b4 | 2685 | #endif |
4ce81a75 JS |
2686 | } |
2687 | ||
1e6feb95 VZ |
2688 | bool wxWindowMSW::MSWCreate(int id, |
2689 | wxWindow *parent, | |
2690 | const wxChar *wclass, | |
2691 | wxWindow * WXUNUSED(wx_win), | |
2692 | const wxChar *title, | |
2693 | int x, | |
2694 | int y, | |
2695 | int width, | |
2696 | int height, | |
2697 | WXDWORD style, | |
2698 | const wxChar *dialog_template, | |
2699 | WXDWORD extendedStyle) | |
2bda0e17 | 2700 | { |
42e69d6b VZ |
2701 | int x1 = CW_USEDEFAULT; |
2702 | int y1 = 0; | |
2703 | int width1 = CW_USEDEFAULT; | |
2704 | int height1 = 100; | |
c085e333 | 2705 | |
42e69d6b VZ |
2706 | // Find parent's size, if it exists, to set up a possible default |
2707 | // panel size the size of the parent window | |
1e6feb95 | 2708 | RECT rectParent; |
42e69d6b | 2709 | if ( parent ) |
a23fd0e1 | 2710 | { |
1e6feb95 | 2711 | ::GetClientRect(GetHwndOf(parent), &rectParent); |
c085e333 | 2712 | |
1e6feb95 VZ |
2713 | width1 = rectParent.right - rectParent.left; |
2714 | height1 = rectParent.bottom - rectParent.top; | |
42e69d6b | 2715 | } |
2bda0e17 | 2716 | |
655076c7 VZ |
2717 | if ( x != -1 ) |
2718 | x1 = x; | |
2719 | if ( y != -1 ) | |
2720 | y1 = y; | |
2721 | if ( width != -1 ) | |
2722 | width1 = width; | |
2723 | if ( height != -1 ) | |
2724 | height1 = height; | |
c085e333 | 2725 | |
f6bcfd97 BP |
2726 | // unfortunately, setting WS_EX_CONTROLPARENT only for some windows in the |
2727 | // hierarchy with several embedded panels (and not all of them) causes the | |
2728 | // program to hang during the next call to IsDialogMessage() due to the bug | |
2729 | // in this function (at least in Windows NT 4.0, it seems to work ok in | |
2730 | // Win2K) | |
2731 | #if 0 | |
8614c467 VZ |
2732 | // if we have wxTAB_TRAVERSAL style, we want WS_EX_CONTROLPARENT or |
2733 | // IsDialogMessage() won't work for us | |
2734 | if ( GetWindowStyleFlag() & wxTAB_TRAVERSAL ) | |
2735 | { | |
2736 | extendedStyle |= WS_EX_CONTROLPARENT; | |
2737 | } | |
f6bcfd97 | 2738 | #endif // 0 |
8614c467 | 2739 | |
1e6feb95 VZ |
2740 | HWND hParent; |
2741 | if ( GetWindowStyleFlag() & wxPOPUP_WINDOW ) | |
2742 | { | |
2743 | // popup windows should have desktop as parent because they shouldn't | |
2744 | // be limited to the parents client area as child windows usually are | |
2745 | hParent = ::GetDesktopWindow(); | |
2746 | } | |
2747 | else if ( parent ) | |
2748 | { | |
2749 | hParent = GetHwndOf(parent); | |
2750 | } | |
2751 | else | |
2752 | { | |
2753 | // top level window | |
2754 | hParent = NULL; | |
2755 | } | |
c085e333 | 2756 | |
42e69d6b | 2757 | wxWndHook = this; |
c085e333 | 2758 | |
54800df8 | 2759 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
2760 | if ( dialog_template ) |
2761 | { | |
b3daa5a3 VZ |
2762 | // for the dialogs without wxDIALOG_NO_PARENT style, use the top level |
2763 | // app window as parent - this avoids creating modal dialogs without | |
2764 | // parent | |
2765 | if ( !hParent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) | |
2766 | { | |
2767 | wxWindow *winTop = wxTheApp->GetTopWindow(); | |
2768 | if ( winTop ) | |
2769 | hParent = GetHwndOf(winTop); | |
2770 | } | |
2771 | ||
42e69d6b VZ |
2772 | m_hWnd = (WXHWND)::CreateDialog(wxGetInstance(), |
2773 | dialog_template, | |
2774 | hParent, | |
2775 | (DLGPROC)wxDlgProc); | |
2bda0e17 | 2776 | |
42e69d6b VZ |
2777 | if ( m_hWnd == 0 ) |
2778 | { | |
b3daa5a3 VZ |
2779 | wxLogError(_("Can't find dialog template '%s'!\nCheck resource include path for finding wx.rc."), |
2780 | dialog_template); | |
c085e333 | 2781 | |
42e69d6b VZ |
2782 | return FALSE; |
2783 | } | |
b3daa5a3 VZ |
2784 | |
2785 | if ( extendedStyle != 0 ) | |
c43e86bd JS |
2786 | { |
2787 | ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, extendedStyle); | |
2788 | ::SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0, | |
b3daa5a3 VZ |
2789 | SWP_NOSIZE | |
2790 | SWP_NOMOVE | | |
2791 | SWP_NOZORDER | | |
2792 | SWP_NOACTIVATE); | |
c43e86bd | 2793 | } |
b3daa5a3 | 2794 | |
3723b7b1 JS |
2795 | #if defined(__WIN95__) |
2796 | // For some reason, the system menu is activated when we use the | |
2797 | // WS_EX_CONTEXTHELP style, so let's set a reasonable icon | |
2798 | if (extendedStyle & WS_EX_CONTEXTHELP) | |
2799 | { | |
b3daa5a3 VZ |
2800 | wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame); |
2801 | if ( winTop ) | |
3723b7b1 | 2802 | { |
b3daa5a3 VZ |
2803 | wxIcon icon = winTop->GetIcon(); |
2804 | if ( icon.Ok() ) | |
2805 | { | |
2806 | ::SendMessage(GetHwnd(), WM_SETICON, | |
2807 | (WPARAM)TRUE, | |
2808 | (LPARAM)GetHiconOf(icon)); | |
2809 | } | |
3723b7b1 JS |
2810 | } |
2811 | } | |
2812 | #endif // __WIN95__ | |
2813 | ||
2814 | ||
2815 | // JACS: is the following still necessary? The above seems to work. | |
c085e333 | 2816 | |
789295bf VZ |
2817 | // ::SetWindowLong(GWL_EXSTYLE) doesn't work for the dialogs, so try |
2818 | // to take care of (at least some) extended style flags ourselves | |
2819 | if ( extendedStyle & WS_EX_TOPMOST ) | |
2820 | { | |
2821 | if ( !::SetWindowPos(GetHwnd(), HWND_TOPMOST, 0, 0, 0, 0, | |
2822 | SWP_NOSIZE | SWP_NOMOVE) ) | |
2823 | { | |
223d09f6 | 2824 | wxLogLastError(wxT("SetWindowPos")); |
789295bf VZ |
2825 | } |
2826 | } | |
2827 | ||
2828 | // move the dialog to its initial position without forcing repainting | |
2829 | if ( !::MoveWindow(GetHwnd(), x1, y1, width1, height1, FALSE) ) | |
2830 | { | |
223d09f6 | 2831 | wxLogLastError(wxT("MoveWindow")); |
789295bf | 2832 | } |
04ef50df | 2833 | |
42e69d6b | 2834 | } |
b3daa5a3 | 2835 | else // creating a normal window, not a dialog |
cd4453e5 | 2836 | #endif // !__WXMICROWIN__ |
42e69d6b VZ |
2837 | { |
2838 | int controlId = 0; | |
2839 | if ( style & WS_CHILD ) | |
1e6feb95 | 2840 | { |
42e69d6b | 2841 | controlId = id; |
b0766406 | 2842 | |
1e6feb95 VZ |
2843 | if ( GetWindowStyleFlag() & wxCLIP_SIBLINGS ) |
2844 | { | |
2845 | style |= WS_CLIPSIBLINGS; | |
2846 | } | |
2847 | } | |
42e69d6b | 2848 | |
193fe989 VZ |
2849 | wxString className(wclass); |
2850 | if ( GetWindowStyleFlag() & wxNO_FULL_REPAINT_ON_RESIZE ) | |
2851 | { | |
223d09f6 | 2852 | className += wxT("NR"); |
193fe989 VZ |
2853 | } |
2854 | ||
42e69d6b | 2855 | m_hWnd = (WXHWND)CreateWindowEx(extendedStyle, |
b782f2e0 | 2856 | className, |
223d09f6 | 2857 | title ? title : wxT(""), |
42e69d6b VZ |
2858 | style, |
2859 | x1, y1, | |
2860 | width1, height1, | |
2861 | hParent, (HMENU)controlId, | |
2862 | wxGetInstance(), | |
2863 | NULL); | |
2864 | ||
2865 | if ( !m_hWnd ) | |
2866 | { | |
f6bcfd97 | 2867 | wxLogError(_("Can't create window of class %s!\nPossible Windows 3.x compatibility problem?"), |
42e69d6b | 2868 | wclass); |
2bda0e17 | 2869 | |
a23fd0e1 | 2870 | return FALSE; |
42e69d6b | 2871 | } |
a23fd0e1 | 2872 | } |
c085e333 | 2873 | |
42e69d6b | 2874 | wxWndHook = NULL; |
b3daa5a3 | 2875 | |
c7527e3f JS |
2876 | #ifdef __WXDEBUG__ |
2877 | wxNode* node = wxWinHandleList->Member(this); | |
2878 | if (node) | |
2879 | { | |
2880 | HWND hWnd = (HWND) node->GetKeyInteger(); | |
2881 | if (hWnd != (HWND) m_hWnd) | |
2882 | { | |
f5166ed4 | 2883 | wxLogError(wxT("A second HWND association is being added for the same window!")); |
c7527e3f JS |
2884 | } |
2885 | } | |
b3daa5a3 VZ |
2886 | #endif // Debug |
2887 | ||
c7527e3f | 2888 | wxAssociateWinWithHandle((HWND) m_hWnd, this); |
c085e333 | 2889 | |
8bf30fe9 VZ |
2890 | SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); |
2891 | ||
42e69d6b | 2892 | return TRUE; |
2bda0e17 KB |
2893 | } |
2894 | ||
42e69d6b VZ |
2895 | // =========================================================================== |
2896 | // MSW message handlers | |
2897 | // =========================================================================== | |
2898 | ||
2899 | // --------------------------------------------------------------------------- | |
2900 | // WM_NOTIFY | |
2901 | // --------------------------------------------------------------------------- | |
2902 | ||
2903 | #ifdef __WIN95__ | |
2904 | // FIXME: VZ: I'm not sure at all that the order of processing is correct | |
1e6feb95 | 2905 | bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
2bda0e17 | 2906 | { |
04ef50df | 2907 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
2908 | LPNMHDR hdr = (LPNMHDR)lParam; |
2909 | HWND hWnd = hdr->hwndFrom; | |
2910 | wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd); | |
2911 | ||
2912 | // is this one of our windows? | |
2913 | if ( win ) | |
564b2609 | 2914 | { |
42e69d6b | 2915 | return win->MSWOnNotify(idCtrl, lParam, result); |
564b2609 | 2916 | } |
2bda0e17 | 2917 | |
42e69d6b VZ |
2918 | // try all our children |
2919 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
2920 | while ( node ) | |
564b2609 | 2921 | { |
42e69d6b VZ |
2922 | wxWindow *child = node->GetData(); |
2923 | if ( child->MSWOnNotify(idCtrl, lParam, result) ) | |
2924 | { | |
2925 | return TRUE; | |
42e69d6b | 2926 | } |
2d0a075d | 2927 | |
42e69d6b VZ |
2928 | node = node->GetNext(); |
2929 | } | |
2d0a075d | 2930 | |
42e69d6b VZ |
2931 | // finally try this window too (catches toolbar case) |
2932 | return MSWOnNotify(idCtrl, lParam, result); | |
cd4453e5 | 2933 | #else // __WXMICROWIN__ |
04ef50df JS |
2934 | return FALSE; |
2935 | #endif | |
42e69d6b | 2936 | } |
2d0a075d | 2937 | |
1e6feb95 | 2938 | bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl), |
42e69d6b VZ |
2939 | WXLPARAM lParam, |
2940 | WXLPARAM* WXUNUSED(result)) | |
2941 | { | |
2942 | #if wxUSE_TOOLTIPS | |
2943 | NMHDR* hdr = (NMHDR *)lParam; | |
a17e237f | 2944 | if ( (int)hdr->code == TTN_NEEDTEXT && m_tooltip ) |
42e69d6b VZ |
2945 | { |
2946 | TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam; | |
837e5743 | 2947 | ttt->lpszText = (wxChar *)m_tooltip->GetTip().c_str(); |
2d0a075d | 2948 | |
42e69d6b VZ |
2949 | // processed |
2950 | return TRUE; | |
2951 | } | |
2952 | #endif // wxUSE_TOOLTIPS | |
2953 | ||
2954 | return FALSE; | |
2955 | } | |
2956 | #endif // __WIN95__ | |
2957 | ||
2958 | // --------------------------------------------------------------------------- | |
2959 | // end session messages | |
2960 | // --------------------------------------------------------------------------- | |
2d0a075d | 2961 | |
1e6feb95 | 2962 | bool wxWindowMSW::HandleQueryEndSession(long logOff, bool *mayEnd) |
42e69d6b VZ |
2963 | { |
2964 | wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1); | |
2965 | event.SetEventObject(wxTheApp); | |
2966 | event.SetCanVeto(TRUE); | |
a17e237f | 2967 | event.SetLoggingOff(logOff == (long)ENDSESSION_LOGOFF); |
2d0a075d | 2968 | |
42e69d6b VZ |
2969 | bool rc = wxTheApp->ProcessEvent(event); |
2970 | ||
2971 | if ( rc ) | |
2972 | { | |
2973 | // we may end only if the app didn't veto session closing (double | |
2974 | // negation...) | |
2975 | *mayEnd = !event.GetVeto(); | |
2d0a075d JS |
2976 | } |
2977 | ||
42e69d6b | 2978 | return rc; |
2bda0e17 KB |
2979 | } |
2980 | ||
1e6feb95 | 2981 | bool wxWindowMSW::HandleEndSession(bool endSession, long logOff) |
2bda0e17 | 2982 | { |
42e69d6b VZ |
2983 | // do nothing if the session isn't ending |
2984 | if ( !endSession ) | |
2985 | return FALSE; | |
a23fd0e1 | 2986 | |
519dc37f VZ |
2987 | // only send once |
2988 | if ( (this != wxTheApp->GetTopWindow()) ) | |
2989 | return FALSE; | |
2990 | ||
42e69d6b VZ |
2991 | wxCloseEvent event(wxEVT_END_SESSION, -1); |
2992 | event.SetEventObject(wxTheApp); | |
2993 | event.SetCanVeto(FALSE); | |
a17e237f | 2994 | event.SetLoggingOff( (logOff == (long)ENDSESSION_LOGOFF) ); |
519dc37f VZ |
2995 | |
2996 | return wxTheApp->ProcessEvent(event); | |
2bda0e17 KB |
2997 | } |
2998 | ||
42e69d6b VZ |
2999 | // --------------------------------------------------------------------------- |
3000 | // window creation/destruction | |
3001 | // --------------------------------------------------------------------------- | |
3002 | ||
1e6feb95 | 3003 | bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT WXUNUSED(cs), bool *mayCreate) |
2bda0e17 | 3004 | { |
42e69d6b | 3005 | // TODO: should generate this event from WM_NCCREATE |
1e6feb95 | 3006 | wxWindowCreateEvent event((wxWindow *)this); |
42e69d6b | 3007 | (void)GetEventHandler()->ProcessEvent(event); |
a23fd0e1 | 3008 | |
42e69d6b VZ |
3009 | *mayCreate = TRUE; |
3010 | ||
3011 | return TRUE; | |
2bda0e17 KB |
3012 | } |
3013 | ||
1e6feb95 | 3014 | bool wxWindowMSW::HandleDestroy() |
2bda0e17 | 3015 | { |
1e6feb95 | 3016 | wxWindowDestroyEvent event((wxWindow *)this); |
42e69d6b VZ |
3017 | (void)GetEventHandler()->ProcessEvent(event); |
3018 | ||
3019 | // delete our drop target if we've got one | |
3020 | #if wxUSE_DRAG_AND_DROP | |
3021 | if ( m_dropTarget != NULL ) | |
2d0a075d | 3022 | { |
42e69d6b VZ |
3023 | m_dropTarget->Revoke(m_hWnd); |
3024 | ||
3025 | delete m_dropTarget; | |
3026 | m_dropTarget = NULL; | |
2d0a075d | 3027 | } |
42e69d6b | 3028 | #endif // wxUSE_DRAG_AND_DROP |
2bda0e17 | 3029 | |
42e69d6b VZ |
3030 | // WM_DESTROY handled |
3031 | return TRUE; | |
2bda0e17 KB |
3032 | } |
3033 | ||
42e69d6b VZ |
3034 | // --------------------------------------------------------------------------- |
3035 | // activation/focus | |
3036 | // --------------------------------------------------------------------------- | |
3037 | ||
1e6feb95 | 3038 | bool wxWindowMSW::HandleActivate(int state, |
42e69d6b VZ |
3039 | bool WXUNUSED(minimized), |
3040 | WXHWND WXUNUSED(activate)) | |
2bda0e17 | 3041 | { |
42e69d6b VZ |
3042 | wxActivateEvent event(wxEVT_ACTIVATE, |
3043 | (state == WA_ACTIVE) || (state == WA_CLICKACTIVE), | |
3044 | m_windowId); | |
3045 | event.SetEventObject(this); | |
3046 | ||
3047 | return GetEventHandler()->ProcessEvent(event); | |
3048 | } | |
3049 | ||
1e6feb95 | 3050 | bool wxWindowMSW::HandleSetFocus(WXHWND hwnd) |
42e69d6b | 3051 | { |
456bc6d9 VZ |
3052 | // notify the parent keeping track of focus for the kbd navigation |
3053 | // purposes that we got it | |
e72aa7f5 | 3054 | wxChildFocusEvent eventFocus((wxWindow *)this); |
456bc6d9 VZ |
3055 | (void)GetEventHandler()->ProcessEvent(eventFocus); |
3056 | ||
789295bf | 3057 | #if wxUSE_CARET |
42e69d6b | 3058 | // Deal with caret |
789295bf | 3059 | if ( m_caret ) |
2d0a075d | 3060 | { |
789295bf | 3061 | m_caret->OnSetFocus(); |
2bda0e17 | 3062 | } |
789295bf | 3063 | #endif // wxUSE_CARET |
42e69d6b | 3064 | |
ab93a576 RD |
3065 | #if wxUSE_TEXTCTRL |
3066 | // If it's a wxTextCtrl don't send the event as it will be done | |
456bc6d9 VZ |
3067 | // after the control gets to process it from EN_FOCUS handler |
3068 | if ( wxDynamicCastThis(wxTextCtrl) ) | |
ab93a576 RD |
3069 | { |
3070 | return FALSE; | |
3071 | } | |
456bc6d9 | 3072 | #endif // wxUSE_TEXTCTRL |
ab93a576 | 3073 | |
42e69d6b VZ |
3074 | wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); |
3075 | event.SetEventObject(this); | |
3076 | ||
1e6feb95 VZ |
3077 | // wxFindWinFromHandle() may return NULL, it is ok |
3078 | event.SetWindow(wxFindWinFromHandle(hwnd)); | |
3079 | ||
42e69d6b | 3080 | return GetEventHandler()->ProcessEvent(event); |
2bda0e17 KB |
3081 | } |
3082 | ||
1e6feb95 | 3083 | bool wxWindowMSW::HandleKillFocus(WXHWND hwnd) |
2bda0e17 | 3084 | { |
789295bf | 3085 | #if wxUSE_CARET |
42e69d6b | 3086 | // Deal with caret |
789295bf | 3087 | if ( m_caret ) |
2d0a075d | 3088 | { |
789295bf | 3089 | m_caret->OnKillFocus(); |
2bda0e17 | 3090 | } |
789295bf | 3091 | #endif // wxUSE_CARET |
42e69d6b | 3092 | |
ab93a576 RD |
3093 | #if wxUSE_TEXTCTRL |
3094 | // If it's a wxTextCtrl don't send the event as it will be done | |
3095 | // after the control gets to process it. | |
3096 | wxTextCtrl *ctrl = wxDynamicCastThis(wxTextCtrl); | |
3097 | if ( ctrl ) | |
3098 | { | |
3099 | return FALSE; | |
3100 | } | |
3101 | #endif | |
3102 | ||
42e69d6b VZ |
3103 | wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId); |
3104 | event.SetEventObject(this); | |
3105 | ||
1e6feb95 VZ |
3106 | // wxFindWinFromHandle() may return NULL, it is ok |
3107 | event.SetWindow(wxFindWinFromHandle(hwnd)); | |
3108 | ||
42e69d6b | 3109 | return GetEventHandler()->ProcessEvent(event); |
2bda0e17 KB |
3110 | } |
3111 | ||
42e69d6b VZ |
3112 | // --------------------------------------------------------------------------- |
3113 | // miscellaneous | |
3114 | // --------------------------------------------------------------------------- | |
3115 | ||
1e6feb95 | 3116 | bool wxWindowMSW::HandleShow(bool show, int WXUNUSED(status)) |
2bda0e17 | 3117 | { |
42e69d6b VZ |
3118 | wxShowEvent event(GetId(), show); |
3119 | event.m_eventObject = this; | |
3120 | ||
3121 | return GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
3122 | } |
3123 | ||
1e6feb95 | 3124 | bool wxWindowMSW::HandleInitDialog(WXHWND WXUNUSED(hWndFocus)) |
2bda0e17 | 3125 | { |
42e69d6b VZ |
3126 | wxInitDialogEvent event(GetId()); |
3127 | event.m_eventObject = this; | |
3128 | ||
3129 | return GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
3130 | } |
3131 | ||
1e6feb95 | 3132 | bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam) |
2bda0e17 | 3133 | { |
04ef50df | 3134 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
3135 | HDROP hFilesInfo = (HDROP) wParam; |
3136 | POINT dropPoint; | |
3137 | DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint); | |
3138 | ||
3139 | // Get the total number of files dropped | |
f6bcfd97 BP |
3140 | WORD gwFilesDropped = (WORD)::DragQueryFile |
3141 | ( | |
3142 | (HDROP)hFilesInfo, | |
3143 | (UINT)-1, | |
3144 | (LPTSTR)0, | |
3145 | (UINT)0 | |
3146 | ); | |
42e69d6b VZ |
3147 | |
3148 | wxString *files = new wxString[gwFilesDropped]; | |
3149 | int wIndex; | |
3150 | for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++) | |
2d0a075d | 3151 | { |
837e5743 | 3152 | DragQueryFile (hFilesInfo, wIndex, (LPTSTR) wxBuffer, 1000); |
42e69d6b | 3153 | files[wIndex] = wxBuffer; |
2d0a075d | 3154 | } |
42e69d6b | 3155 | DragFinish (hFilesInfo); |
2bda0e17 | 3156 | |
42e69d6b VZ |
3157 | wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files); |
3158 | event.m_eventObject = this; | |
b3dc8a3e VZ |
3159 | event.m_pos.x = dropPoint.x; |
3160 | event.m_pos.y = dropPoint.y; | |
42e69d6b VZ |
3161 | |
3162 | bool rc = GetEventHandler()->ProcessEvent(event); | |
3163 | ||
3164 | delete[] files; | |
3165 | ||
3166 | return rc; | |
cd4453e5 | 3167 | #else // __WXMICROWIN__ |
04ef50df JS |
3168 | return FALSE; |
3169 | #endif | |
2bda0e17 KB |
3170 | } |
3171 | ||
1e6feb95 VZ |
3172 | bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd), |
3173 | short nHitTest, | |
3174 | int WXUNUSED(mouseMsg)) | |
2bda0e17 | 3175 | { |
04ef50df | 3176 | #ifndef __WXMICROWIN__ |
bfbd6dc1 | 3177 | // the logic is as follows: |
43b5058d VZ |
3178 | // -1. don't set cursor for non client area, including but not limited to |
3179 | // the title bar, scrollbars, &c | |
3180 | // 0. allow the user to override default behaviour by using EVT_SET_CURSOR | |
bfbd6dc1 VZ |
3181 | // 1. if we have the cursor set it unless wxIsBusy() |
3182 | // 2. if we're a top level window, set some cursor anyhow | |
3183 | // 3. if wxIsBusy(), set the busy cursor, otherwise the global one | |
42e69d6b | 3184 | |
43b5058d VZ |
3185 | if ( nHitTest != HTCLIENT ) |
3186 | { | |
3187 | return FALSE; | |
3188 | } | |
3189 | ||
bfbd6dc1 | 3190 | HCURSOR hcursor = 0; |
43b5058d VZ |
3191 | |
3192 | // first ask the user code - it may wish to set the cursor in some very | |
3193 | // specific way (for example, depending on the current position) | |
3194 | POINT pt; | |
669f7a11 | 3195 | #ifdef __WIN32__ |
43b5058d VZ |
3196 | if ( !::GetCursorPos(&pt) ) |
3197 | { | |
f6bcfd97 | 3198 | wxLogLastError(wxT("GetCursorPos")); |
43b5058d | 3199 | } |
669f7a11 JS |
3200 | #else |
3201 | // In WIN16 it doesn't return a value. | |
3202 | ::GetCursorPos(&pt); | |
3203 | #endif | |
43b5058d VZ |
3204 | |
3205 | int x = pt.x, | |
3206 | y = pt.y; | |
3207 | ScreenToClient(&x, &y); | |
3208 | wxSetCursorEvent event(x, y); | |
3209 | ||
3210 | bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event); | |
3211 | if ( processedEvtSetCursor && event.HasCursor() ) | |
bfbd6dc1 | 3212 | { |
43b5058d | 3213 | hcursor = GetHcursorOf(event.GetCursor()); |
bfbd6dc1 | 3214 | } |
42e69d6b | 3215 | |
43b5058d | 3216 | if ( !hcursor ) |
bfbd6dc1 | 3217 | { |
43b5058d VZ |
3218 | bool isBusy = wxIsBusy(); |
3219 | ||
3220 | // the test for processedEvtSetCursor is here to prevent using m_cursor | |
3221 | // if the user code caught EVT_SET_CURSOR() and returned nothing from | |
3222 | // it - this is a way to say that our cursor shouldn't be used for this | |
3223 | // point | |
3224 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
bfbd6dc1 | 3225 | { |
43b5058d | 3226 | hcursor = GetHcursorOf(m_cursor); |
bfbd6dc1 | 3227 | } |
43b5058d VZ |
3228 | |
3229 | if ( !GetParent() ) | |
bfbd6dc1 | 3230 | { |
43b5058d | 3231 | if ( isBusy ) |
42e69d6b | 3232 | { |
43b5058d VZ |
3233 | hcursor = wxGetCurrentBusyCursor(); |
3234 | } | |
3235 | else if ( !hcursor ) | |
3236 | { | |
3237 | const wxCursor *cursor = wxGetGlobalCursor(); | |
3238 | if ( cursor && cursor->Ok() ) | |
3239 | { | |
3240 | hcursor = GetHcursorOf(*cursor); | |
3241 | } | |
42e69d6b VZ |
3242 | } |
3243 | } | |
3244 | } | |
3245 | ||
bfbd6dc1 VZ |
3246 | if ( hcursor ) |
3247 | { | |
3248 | ::SetCursor(hcursor); | |
3249 | ||
3250 | // cursor set, stop here | |
3251 | return TRUE; | |
3252 | } | |
cd4453e5 VZ |
3253 | #endif // __WXMICROWIN__ |
3254 | ||
3ca6a5f0 BP |
3255 | // pass up the window chain |
3256 | return FALSE; | |
2bda0e17 KB |
3257 | } |
3258 | ||
42e69d6b VZ |
3259 | // --------------------------------------------------------------------------- |
3260 | // owner drawn stuff | |
3261 | // --------------------------------------------------------------------------- | |
3262 | ||
1e6feb95 | 3263 | bool wxWindowMSW::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct) |
2bda0e17 | 3264 | { |
4286a5b5 | 3265 | #if wxUSE_OWNER_DRAWN |
1e6feb95 VZ |
3266 | |
3267 | #if wxUSE_MENUS_NATIVE | |
42e69d6b | 3268 | // is it a menu item? |
6f806543 VZ |
3269 | DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct; |
3270 | if ( id == 0 && pDrawStruct->CtlType == ODT_MENU ) | |
42e69d6b | 3271 | { |
42e69d6b VZ |
3272 | wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData); |
3273 | ||
3274 | wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); | |
3275 | ||
7561aacd VZ |
3276 | // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent |
3277 | // the DC from being released | |
3278 | wxDCTemp dc((WXHDC)pDrawStruct->hDC); | |
42e69d6b VZ |
3279 | wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top, |
3280 | pDrawStruct->rcItem.right - pDrawStruct->rcItem.left, | |
3281 | pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top); | |
3282 | ||
3283 | return pMenuItem->OnDrawItem | |
7561aacd VZ |
3284 | ( |
3285 | dc, | |
3286 | rect, | |
3287 | (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction, | |
3288 | (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState | |
3289 | ); | |
42e69d6b | 3290 | } |
1e6feb95 | 3291 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b | 3292 | |
1e6feb95 | 3293 | #if wxUSE_CONTROLS |
42e69d6b VZ |
3294 | wxWindow *item = FindItem(id); |
3295 | if ( item && item->IsKindOf(CLASSINFO(wxControl)) ) | |
3296 | { | |
3297 | return ((wxControl *)item)->MSWOnDraw(itemStruct); | |
3298 | } | |
1e6feb95 VZ |
3299 | #endif // wxUSE_CONTROLS |
3300 | ||
cd0b1709 | 3301 | #endif // USE_OWNER_DRAWN |
4286a5b5 | 3302 | |
cd0b1709 | 3303 | return FALSE; |
2bda0e17 KB |
3304 | } |
3305 | ||
1e6feb95 | 3306 | bool wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct) |
2bda0e17 | 3307 | { |
4286a5b5 | 3308 | #if wxUSE_OWNER_DRAWN |
42e69d6b | 3309 | // is it a menu item? |
6f806543 VZ |
3310 | MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct; |
3311 | if ( id == 0 && pMeasureStruct->CtlType == ODT_MENU ) | |
2d0a075d | 3312 | { |
42e69d6b VZ |
3313 | wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData); |
3314 | ||
3315 | wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); | |
3316 | ||
3317 | return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth, | |
3318 | &pMeasureStruct->itemHeight); | |
2d0a075d | 3319 | } |
42e69d6b VZ |
3320 | |
3321 | wxWindow *item = FindItem(id); | |
3322 | if ( item && item->IsKindOf(CLASSINFO(wxControl)) ) | |
3323 | { | |
3324 | return ((wxControl *)item)->MSWOnMeasure(itemStruct); | |
3325 | } | |
4286a5b5 | 3326 | #endif // owner-drawn menus |
42e69d6b | 3327 | return FALSE; |
2bda0e17 KB |
3328 | } |
3329 | ||
42e69d6b VZ |
3330 | // --------------------------------------------------------------------------- |
3331 | // colours and palettes | |
3332 | // --------------------------------------------------------------------------- | |
2bda0e17 | 3333 | |
1e6feb95 | 3334 | bool wxWindowMSW::HandleSysColorChange() |
2bda0e17 | 3335 | { |
42e69d6b VZ |
3336 | wxSysColourChangedEvent event; |
3337 | event.SetEventObject(this); | |
3338 | ||
3339 | return GetEventHandler()->ProcessEvent(event); | |
3340 | } | |
3341 | ||
1e6feb95 | 3342 | bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush, |
42e69d6b VZ |
3343 | WXHDC pDC, |
3344 | WXHWND pWnd, | |
3345 | WXUINT nCtlColor, | |
3346 | WXUINT message, | |
3347 | WXWPARAM wParam, | |
3348 | WXLPARAM lParam) | |
3349 | { | |
04ef50df | 3350 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
3351 | WXHBRUSH hBrush = 0; |
3352 | ||
3353 | if ( nCtlColor == CTLCOLOR_DLG ) | |
2d0a075d | 3354 | { |
42e69d6b | 3355 | hBrush = OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); |
2d0a075d | 3356 | } |
1e6feb95 | 3357 | #if wxUSE_CONTROLS |
2d0a075d JS |
3358 | else |
3359 | { | |
42e69d6b VZ |
3360 | wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE); |
3361 | if ( item ) | |
3362 | hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); | |
2d0a075d | 3363 | } |
1e6feb95 | 3364 | #endif // wxUSE_CONTROLS |
42e69d6b VZ |
3365 | |
3366 | if ( hBrush ) | |
3367 | *brush = hBrush; | |
3368 | ||
3369 | return hBrush != 0; | |
cd4453e5 | 3370 | #else // __WXMICROWIN__ |
04ef50df JS |
3371 | return FALSE; |
3372 | #endif | |
2bda0e17 KB |
3373 | } |
3374 | ||
42e69d6b | 3375 | // Define for each class of dialog and control |
1e6feb95 VZ |
3376 | WXHBRUSH wxWindowMSW::OnCtlColor(WXHDC WXUNUSED(hDC), |
3377 | WXHWND WXUNUSED(hWnd), | |
3378 | WXUINT WXUNUSED(nCtlColor), | |
3379 | WXUINT WXUNUSED(message), | |
3380 | WXWPARAM WXUNUSED(wParam), | |
3381 | WXLPARAM WXUNUSED(lParam)) | |
2bda0e17 | 3382 | { |
42e69d6b VZ |
3383 | return (WXHBRUSH)0; |
3384 | } | |
2d0a075d | 3385 | |
1e6feb95 | 3386 | bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange) |
42e69d6b VZ |
3387 | { |
3388 | wxPaletteChangedEvent event(GetId()); | |
3389 | event.SetEventObject(this); | |
3390 | event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange)); | |
2d0a075d | 3391 | |
42e69d6b VZ |
3392 | return GetEventHandler()->ProcessEvent(event); |
3393 | } | |
3394 | ||
1e6feb95 | 3395 | bool wxWindowMSW::HandleQueryNewPalette() |
42e69d6b VZ |
3396 | { |
3397 | wxQueryNewPaletteEvent event(GetId()); | |
3398 | event.SetEventObject(this); | |
3399 | ||
3400 | return GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized(); | |
3401 | } | |
3402 | ||
3403 | // Responds to colour changes: passes event on to children. | |
1e6feb95 | 3404 | void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& event) |
42e69d6b VZ |
3405 | { |
3406 | wxNode *node = GetChildren().First(); | |
3407 | while ( node ) | |
3408 | { | |
3409 | // Only propagate to non-top-level windows | |
3410 | wxWindow *win = (wxWindow *)node->Data(); | |
3411 | if ( win->GetParent() ) | |
3412 | { | |
3413 | wxSysColourChangedEvent event2; | |
3414 | event.m_eventObject = win; | |
3415 | win->GetEventHandler()->ProcessEvent(event2); | |
564b2609 | 3416 | } |
42e69d6b VZ |
3417 | |
3418 | node = node->Next(); | |
2bda0e17 | 3419 | } |
2bda0e17 KB |
3420 | } |
3421 | ||
42e69d6b VZ |
3422 | // --------------------------------------------------------------------------- |
3423 | // painting | |
3424 | // --------------------------------------------------------------------------- | |
3425 | ||
1e6feb95 | 3426 | bool wxWindowMSW::HandlePaint() |
2bda0e17 | 3427 | { |
42e69d6b VZ |
3428 | #ifdef __WIN32__ |
3429 | HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle | |
3430 | if ( !hRegion ) | |
f6bcfd97 | 3431 | wxLogLastError(wxT("CreateRectRgn")); |
42e69d6b | 3432 | if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR ) |
f6bcfd97 | 3433 | wxLogLastError(wxT("GetUpdateRgn")); |
c085e333 | 3434 | |
42e69d6b | 3435 | m_updateRegion = wxRegion((WXHRGN) hRegion); |
1e6feb95 | 3436 | #else // Win16 |
42e69d6b | 3437 | RECT updateRect; |
1e6feb95 | 3438 | ::GetUpdateRect(GetHwnd(), &updateRect, FALSE); |
c085e333 | 3439 | |
42e69d6b VZ |
3440 | m_updateRegion = wxRegion(updateRect.left, updateRect.top, |
3441 | updateRect.right - updateRect.left, | |
3442 | updateRect.bottom - updateRect.top); | |
1e6feb95 | 3443 | #endif // Win32/16 |
c085e333 | 3444 | |
42e69d6b VZ |
3445 | wxPaintEvent event(m_windowId); |
3446 | event.SetEventObject(this); | |
2bda0e17 | 3447 | |
1e6feb95 VZ |
3448 | bool processed = GetEventHandler()->ProcessEvent(event); |
3449 | ||
3450 | // note that we must generate NC event after the normal one as otherwise | |
3451 | // BeginPaint() will happily overwrite our decorations with the background | |
3452 | // colour | |
3453 | wxNcPaintEvent eventNc(m_windowId); | |
3454 | eventNc.SetEventObject(this); | |
3455 | GetEventHandler()->ProcessEvent(eventNc); | |
3456 | ||
3457 | return processed; | |
2bda0e17 KB |
3458 | } |
3459 | ||
63da7df7 | 3460 | // Can be called from an application's OnPaint handler |
1e6feb95 | 3461 | void wxWindowMSW::OnPaint(wxPaintEvent& event) |
63da7df7 | 3462 | { |
1e6feb95 VZ |
3463 | #ifdef __WXUNIVERSAL__ |
3464 | event.Skip(); | |
3465 | #else | |
63da7df7 JS |
3466 | HDC hDC = (HDC) wxPaintDC::FindDCInCache((wxWindow*) event.GetEventObject()); |
3467 | if (hDC != 0) | |
3468 | { | |
3469 | MSWDefWindowProc(WM_PAINT, (WPARAM) hDC, 0); | |
3470 | } | |
1e6feb95 | 3471 | #endif |
63da7df7 JS |
3472 | } |
3473 | ||
1e6feb95 | 3474 | bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc) |
a23fd0e1 | 3475 | { |
42e69d6b VZ |
3476 | // Prevents flicker when dragging |
3477 | if ( ::IsIconic(GetHwnd()) ) | |
3478 | return TRUE; | |
a23fd0e1 | 3479 | |
7561aacd | 3480 | wxDCTemp dc(hdc); |
c085e333 | 3481 | |
1e6feb95 VZ |
3482 | dc.SetHDC(hdc); |
3483 | dc.SetWindow((wxWindow *)this); | |
564b2609 | 3484 | dc.BeginDrawing(); |
c085e333 | 3485 | |
2bda0e17 | 3486 | wxEraseEvent event(m_windowId, &dc); |
42e69d6b | 3487 | event.SetEventObject(this); |
a23fd0e1 | 3488 | bool rc = GetEventHandler()->ProcessEvent(event); |
c085e333 | 3489 | |
a23fd0e1 | 3490 | dc.EndDrawing(); |
7561aacd VZ |
3491 | |
3492 | // must be called manually as ~wxDC doesn't do anything for wxDCTemp | |
a23fd0e1 | 3493 | dc.SelectOldObjects(hdc); |
a23fd0e1 VZ |
3494 | |
3495 | return rc; | |
2bda0e17 KB |
3496 | } |
3497 | ||
1e6feb95 | 3498 | void wxWindowMSW::OnEraseBackground(wxEraseEvent& event) |
2bda0e17 | 3499 | { |
2d0a075d | 3500 | RECT rect; |
a23fd0e1 | 3501 | ::GetClientRect(GetHwnd(), &rect); |
2bda0e17 | 3502 | |
42e69d6b VZ |
3503 | COLORREF ref = PALETTERGB(m_backgroundColour.Red(), |
3504 | m_backgroundColour.Green(), | |
3505 | m_backgroundColour.Blue()); | |
ce3ed50d | 3506 | HBRUSH hBrush = ::CreateSolidBrush(ref); |
42e69d6b | 3507 | if ( !hBrush ) |
f6bcfd97 | 3508 | wxLogLastError(wxT("CreateSolidBrush")); |
42e69d6b VZ |
3509 | |
3510 | HDC hdc = (HDC)event.GetDC()->GetHDC(); | |
2bda0e17 | 3511 | |
42e69d6b VZ |
3512 | int mode = ::SetMapMode(hdc, MM_TEXT); |
3513 | ||
3514 | ::FillRect(hdc, &rect, hBrush); | |
2d0a075d | 3515 | ::DeleteObject(hBrush); |
42e69d6b VZ |
3516 | ::SetMapMode(hdc, mode); |
3517 | } | |
3518 | ||
3519 | // --------------------------------------------------------------------------- | |
3520 | // moving and resizing | |
3521 | // --------------------------------------------------------------------------- | |
3522 | ||
1e6feb95 | 3523 | bool wxWindowMSW::HandleMinimize() |
42e69d6b VZ |
3524 | { |
3525 | wxIconizeEvent event(m_windowId); | |
3526 | event.SetEventObject(this); | |
2d0a075d | 3527 | |
42e69d6b | 3528 | return GetEventHandler()->ProcessEvent(event); |
2bda0e17 KB |
3529 | } |
3530 | ||
1e6feb95 | 3531 | bool wxWindowMSW::HandleMaximize() |
2bda0e17 | 3532 | { |
42e69d6b VZ |
3533 | wxMaximizeEvent event(m_windowId); |
3534 | event.SetEventObject(this); | |
c085e333 | 3535 | |
42e69d6b VZ |
3536 | return GetEventHandler()->ProcessEvent(event); |
3537 | } | |
2bda0e17 | 3538 | |
1e6feb95 | 3539 | bool wxWindowMSW::HandleMove(int x, int y) |
42e69d6b VZ |
3540 | { |
3541 | wxMoveEvent event(wxPoint(x, y), m_windowId); | |
3542 | event.SetEventObject(this); | |
3543 | ||
3544 | return GetEventHandler()->ProcessEvent(event); | |
3545 | } | |
3546 | ||
1e6feb95 | 3547 | bool wxWindowMSW::HandleSize(int w, int h, WXUINT WXUNUSED(flag)) |
42e69d6b VZ |
3548 | { |
3549 | wxSizeEvent event(wxSize(w, h), m_windowId); | |
3550 | event.SetEventObject(this); | |
3551 | ||
3552 | return GetEventHandler()->ProcessEvent(event); | |
3553 | } | |
3554 | ||
1e6feb95 | 3555 | bool wxWindowMSW::HandleGetMinMaxInfo(void *mmInfo) |
42e69d6b VZ |
3556 | { |
3557 | MINMAXINFO *info = (MINMAXINFO *)mmInfo; | |
3558 | ||
3559 | bool rc = FALSE; | |
3560 | ||
3561 | if ( m_minWidth != -1 ) | |
2d0a075d | 3562 | { |
42e69d6b VZ |
3563 | info->ptMinTrackSize.x = m_minWidth; |
3564 | rc = TRUE; | |
2d0a075d | 3565 | } |
2bda0e17 | 3566 | |
42e69d6b VZ |
3567 | if ( m_minHeight != -1 ) |
3568 | { | |
3569 | info->ptMinTrackSize.y = m_minHeight; | |
3570 | rc = TRUE; | |
3571 | } | |
2bda0e17 | 3572 | |
42e69d6b VZ |
3573 | if ( m_maxWidth != -1 ) |
3574 | { | |
3575 | info->ptMaxTrackSize.x = m_maxWidth; | |
3576 | rc = TRUE; | |
2d0a075d | 3577 | } |
2bda0e17 | 3578 | |
42e69d6b VZ |
3579 | if ( m_maxHeight != -1 ) |
3580 | { | |
3581 | info->ptMaxTrackSize.y = m_maxHeight; | |
3582 | rc = TRUE; | |
3583 | } | |
2bda0e17 | 3584 | |
42e69d6b VZ |
3585 | return rc; |
3586 | } | |
2d0a075d | 3587 | |
42e69d6b VZ |
3588 | // --------------------------------------------------------------------------- |
3589 | // command messages | |
3590 | // --------------------------------------------------------------------------- | |
3591 | ||
1e6feb95 | 3592 | bool wxWindowMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) |
42e69d6b | 3593 | { |
1e6feb95 | 3594 | #if wxUSE_MENUS_NATIVE |
42e69d6b VZ |
3595 | if ( wxCurrentPopupMenu ) |
3596 | { | |
3597 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
3598 | wxCurrentPopupMenu = NULL; | |
3599 | ||
3600 | return popupMenu->MSWCommand(cmd, id); | |
3601 | } | |
1e6feb95 | 3602 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b | 3603 | |
2f4ef631 | 3604 | wxWindow *win = (wxWindow*) NULL; |
b853f898 | 3605 | if ( cmd == 0 || cmd == 1 ) // menu or accel - use id |
42e69d6b | 3606 | { |
b853f898 VZ |
3607 | // must cast to a signed type before comparing with other ids! |
3608 | win = FindItem((signed short)id); | |
3609 | } | |
2f4ef631 JS |
3610 | |
3611 | if (!win && control) | |
b853f898 VZ |
3612 | { |
3613 | // find it from HWND - this works even with the broken programs using | |
3614 | // the same ids for different controls | |
42e69d6b VZ |
3615 | win = wxFindWinFromHandle(control); |
3616 | } | |
3617 | ||
3618 | if ( win ) | |
b94ae1ea | 3619 | { |
42e69d6b | 3620 | return win->MSWCommand(cmd, id); |
b94ae1ea VZ |
3621 | } |
3622 | ||
3623 | // the messages sent from the in-place edit control used by the treectrl | |
3624 | // for label editing have id == 0, but they should _not_ be treated as menu | |
3625 | // messages (they are EN_XXX ones, in fact) so don't translate anything | |
3626 | // coming from a control to wxEVT_COMMAND_MENU_SELECTED | |
3627 | if ( !control ) | |
a84fc80b | 3628 | { |
b94ae1ea VZ |
3629 | // If no child window, it may be an accelerator, e.g. for a popup menu |
3630 | // command | |
a84fc80b JS |
3631 | |
3632 | wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED); | |
3633 | event.SetEventObject(this); | |
3634 | event.SetId(id); | |
3635 | event.SetInt(id); | |
b94ae1ea VZ |
3636 | |
3637 | return GetEventHandler()->ProcessEvent(event); | |
a84fc80b | 3638 | } |
24ce4c18 | 3639 | #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__) |
6fe19057 VZ |
3640 | else |
3641 | { | |
3642 | // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND | |
3643 | // notifications to its parent which we want to reflect back to | |
3644 | // wxSpinCtrl | |
3645 | wxSpinCtrl *spin = wxSpinCtrl::GetSpinForTextCtrl(control); | |
3646 | if ( spin && spin->ProcessTextCommand(cmd, id) ) | |
3647 | return TRUE; | |
3648 | } | |
3649 | #endif // wxUSE_SPINCTRL | |
42e69d6b VZ |
3650 | |
3651 | return FALSE; | |
2bda0e17 KB |
3652 | } |
3653 | ||
1e6feb95 | 3654 | bool wxWindowMSW::HandleSysCommand(WXWPARAM wParam, WXLPARAM WXUNUSED(lParam)) |
2bda0e17 | 3655 | { |
42e69d6b VZ |
3656 | // 4 bits are reserved |
3657 | switch ( wParam & 0xFFFFFFF0 ) | |
3658 | { | |
3659 | case SC_MAXIMIZE: | |
3660 | return HandleMaximize(); | |
2d0a075d | 3661 | |
42e69d6b VZ |
3662 | case SC_MINIMIZE: |
3663 | return HandleMinimize(); | |
2d0a075d | 3664 | } |
2bda0e17 | 3665 | |
42e69d6b VZ |
3666 | return FALSE; |
3667 | } | |
3668 | ||
3669 | // --------------------------------------------------------------------------- | |
3670 | // mouse events | |
3671 | // --------------------------------------------------------------------------- | |
3672 | ||
1e6feb95 VZ |
3673 | void wxWindowMSW::InitMouseEvent(wxMouseEvent& event, |
3674 | int x, int y, | |
3675 | WXUINT flags) | |
42e69d6b | 3676 | { |
1e6feb95 VZ |
3677 | // our client coords are not quite the same as Windows ones |
3678 | wxPoint pt = GetClientAreaOrigin(); | |
3679 | event.m_x = x - pt.x; | |
3680 | event.m_y = y - pt.y; | |
3681 | ||
3682 | event.m_shiftDown = (flags & MK_SHIFT) != 0; | |
3683 | event.m_controlDown = (flags & MK_CONTROL) != 0; | |
3684 | event.m_leftDown = (flags & MK_LBUTTON) != 0; | |
3685 | event.m_middleDown = (flags & MK_MBUTTON) != 0; | |
3686 | event.m_rightDown = (flags & MK_RBUTTON) != 0; | |
b96340e6 | 3687 | event.m_altDown = (::GetKeyState(VK_MENU) & 0x80000000) != 0; |
1e6feb95 | 3688 | |
42e69d6b VZ |
3689 | event.SetTimestamp(s_currentMsg.time); |
3690 | event.m_eventObject = this; | |
3691 | ||
3692 | #if wxUSE_MOUSEEVENT_HACK | |
3693 | m_lastMouseX = x; | |
3694 | m_lastMouseY = y; | |
3695 | m_lastMouseEvent = event.GetEventType(); | |
3696 | #endif // wxUSE_MOUSEEVENT_HACK | |
2bda0e17 KB |
3697 | } |
3698 | ||
1e6feb95 | 3699 | bool wxWindowMSW::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags) |
2bda0e17 | 3700 | { |
42e69d6b VZ |
3701 | // the mouse events take consecutive IDs from WM_MOUSEFIRST to |
3702 | // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST | |
3703 | // from the message id and take the value in the table to get wxWin event | |
3704 | // id | |
3705 | static const wxEventType eventsMouse[] = | |
3706 | { | |
3707 | wxEVT_MOTION, | |
3708 | wxEVT_LEFT_DOWN, | |
3709 | wxEVT_LEFT_UP, | |
3710 | wxEVT_LEFT_DCLICK, | |
3711 | wxEVT_RIGHT_DOWN, | |
3712 | wxEVT_RIGHT_UP, | |
3713 | wxEVT_RIGHT_DCLICK, | |
3714 | wxEVT_MIDDLE_DOWN, | |
3715 | wxEVT_MIDDLE_UP, | |
3716 | wxEVT_MIDDLE_DCLICK | |
3717 | }; | |
2bda0e17 | 3718 | |
42e69d6b VZ |
3719 | wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]); |
3720 | InitMouseEvent(event, x, y, flags); | |
3721 | ||
3722 | return GetEventHandler()->ProcessEvent(event); | |
3723 | } | |
3724 | ||
1e6feb95 | 3725 | bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags) |
42e69d6b VZ |
3726 | { |
3727 | if ( !m_mouseInWindow ) | |
2bda0e17 | 3728 | { |
1e6feb95 VZ |
3729 | // it would be wrong to assume that just because we get a mouse move |
3730 | // event that the mouse is inside the window: although this is usually | |
3731 | // true, it is not if we had captured the mouse, so we need to check | |
3732 | // the mouse coordinates here | |
3733 | if ( !HasCapture() || IsMouseInWindow() ) | |
3734 | { | |
3735 | // Generate an ENTER event | |
3736 | m_mouseInWindow = TRUE; | |
42e69d6b | 3737 | |
1e6feb95 VZ |
3738 | wxMouseEvent event(wxEVT_ENTER_WINDOW); |
3739 | InitMouseEvent(event, x, y, flags); | |
42e69d6b | 3740 | |
1e6feb95 VZ |
3741 | (void)GetEventHandler()->ProcessEvent(event); |
3742 | } | |
42e69d6b VZ |
3743 | } |
3744 | ||
3745 | #if wxUSE_MOUSEEVENT_HACK | |
3746 | // Window gets a click down message followed by a mouse move message even | |
3747 | // if position isn't changed! We want to discard the trailing move event | |
3748 | // if x and y are the same. | |
3749 | if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN || | |
3750 | m_lastMouseEvent == wxEVT_LEFT_DOWN || | |
3751 | m_lastMouseEvent == wxEVT_MIDDLE_DOWN) && | |
06b32ebe | 3752 | (m_lastMouseX == x && m_lastMouseY == y) ) |
42e69d6b VZ |
3753 | { |
3754 | m_lastMouseEvent = wxEVT_MOTION; | |
3755 | ||
3756 | return FALSE; | |
3757 | } | |
3758 | #endif // wxUSE_MOUSEEVENT_HACK | |
3759 | ||
3760 | return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags); | |
3761 | } | |
3762 | ||
d2c52078 | 3763 | |
24ce4c18 | 3764 | bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam) |
d2c52078 RD |
3765 | { |
3766 | #if wxUSE_MOUSEWHEEL | |
3767 | wxMouseEvent event(wxEVT_MOUSEWHEEL); | |
3768 | InitMouseEvent(event, | |
3769 | GET_X_LPARAM(lParam), | |
3770 | GET_Y_LPARAM(lParam), | |
3771 | LOWORD(wParam)); | |
d2c52078 RD |
3772 | event.m_wheelRotation = (short)HIWORD(wParam); |
3773 | event.m_wheelDelta = WHEEL_DELTA; | |
3774 | ||
0f7a546d RD |
3775 | #ifdef __WIN32__ |
3776 | static int s_linesPerRotation = -1; | |
3777 | if ( s_linesPerRotation == -1 ) | |
3778 | { | |
3779 | if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, | |
3780 | &s_linesPerRotation, 0)) | |
3781 | { | |
3782 | // this is not supposed to happen | |
3783 | wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)")); | |
3784 | ||
3785 | // the default is 3, so use it if SystemParametersInfo() failed | |
3786 | s_linesPerRotation = 3; | |
3787 | } | |
3788 | } | |
3789 | #else // Win16 | |
3790 | // no SystemParametersInfo() under Win16 | |
3791 | static const int s_linesPerRotation = 3; | |
3792 | #endif | |
d2c52078 | 3793 | |
0f7a546d | 3794 | event.m_linesPerAction = s_linesPerRotation; |
d2c52078 | 3795 | return GetEventHandler()->ProcessEvent(event); |
0f7a546d | 3796 | |
d2c52078 | 3797 | #else |
38caaa61 KB |
3798 | (void) wParam; |
3799 | (void) lParam; | |
3800 | ||
d2c52078 RD |
3801 | return FALSE; |
3802 | #endif | |
3803 | } | |
3804 | ||
3805 | ||
42e69d6b VZ |
3806 | // --------------------------------------------------------------------------- |
3807 | // keyboard handling | |
3808 | // --------------------------------------------------------------------------- | |
3809 | ||
c42404a5 VZ |
3810 | // create the key event of the given type for the given key - used by |
3811 | // HandleChar and HandleKeyDown/Up | |
1e6feb95 | 3812 | wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType, |
b09bda68 VZ |
3813 | int id, |
3814 | WXLPARAM lParam) const | |
c42404a5 VZ |
3815 | { |
3816 | wxKeyEvent event(evType); | |
3817 | event.SetId(GetId()); | |
3f7bc32b VZ |
3818 | event.m_shiftDown = wxIsShiftDown(); |
3819 | event.m_controlDown = wxIsCtrlDown(); | |
c42404a5 VZ |
3820 | event.m_altDown = (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN; |
3821 | ||
3822 | event.m_eventObject = (wxWindow *)this; // const_cast | |
3823 | event.m_keyCode = id; | |
3824 | event.SetTimestamp(s_currentMsg.time); | |
3825 | ||
3826 | // translate the position to client coords | |
3827 | POINT pt; | |
3828 | GetCursorPos(&pt); | |
3829 | RECT rect; | |
3830 | GetWindowRect(GetHwnd(),&rect); | |
3831 | pt.x -= rect.left; | |
3832 | pt.y -= rect.top; | |
3833 | ||
3834 | event.m_x = pt.x; | |
3835 | event.m_y = pt.y; | |
3836 | ||
3837 | return event; | |
3838 | } | |
3839 | ||
42e69d6b VZ |
3840 | // isASCII is TRUE only when we're called from WM_CHAR handler and not from |
3841 | // WM_KEYDOWN one | |
1e6feb95 | 3842 | bool wxWindowMSW::HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII) |
42e69d6b | 3843 | { |
c42404a5 VZ |
3844 | bool ctrlDown = FALSE; |
3845 | ||
42e69d6b | 3846 | int id; |
42e69d6b VZ |
3847 | if ( isASCII ) |
3848 | { | |
3849 | // If 1 -> 26, translate to CTRL plus a letter. | |
3850 | id = wParam; | |
3851 | if ( (id > 0) && (id < 27) ) | |
2d0a075d | 3852 | { |
42e69d6b VZ |
3853 | switch (id) |
3854 | { | |
c42404a5 | 3855 | case 13: |
42e69d6b VZ |
3856 | id = WXK_RETURN; |
3857 | break; | |
c42404a5 VZ |
3858 | |
3859 | case 8: | |
42e69d6b VZ |
3860 | id = WXK_BACK; |
3861 | break; | |
c42404a5 VZ |
3862 | |
3863 | case 9: | |
42e69d6b VZ |
3864 | id = WXK_TAB; |
3865 | break; | |
c42404a5 VZ |
3866 | |
3867 | default: | |
3868 | ctrlDown = TRUE; | |
42e69d6b | 3869 | id = id + 96; |
42e69d6b | 3870 | } |
2d0a075d | 3871 | } |
2d0a075d | 3872 | } |
c42404a5 VZ |
3873 | else if ( (id = wxCharCodeMSWToWX(wParam)) == 0 ) |
3874 | { | |
42e69d6b | 3875 | // it's ASCII and will be processed here only when called from |
c42404a5 | 3876 | // WM_CHAR (i.e. when isASCII = TRUE), don't process it now |
42e69d6b VZ |
3877 | id = -1; |
3878 | } | |
2bda0e17 | 3879 | |
42e69d6b | 3880 | if ( id != -1 ) |
2d0a075d | 3881 | { |
c42404a5 VZ |
3882 | wxKeyEvent event(CreateKeyEvent(wxEVT_CHAR, id, lParam)); |
3883 | if ( ctrlDown ) | |
3884 | { | |
3885 | event.m_controlDown = TRUE; | |
3886 | } | |
42e69d6b VZ |
3887 | |
3888 | if ( GetEventHandler()->ProcessEvent(event) ) | |
3889 | return TRUE; | |
2d0a075d | 3890 | } |
c42404a5 VZ |
3891 | |
3892 | return FALSE; | |
2bda0e17 KB |
3893 | } |
3894 | ||
1e6feb95 | 3895 | bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 3896 | { |
c42404a5 | 3897 | int id = wxCharCodeMSWToWX(wParam); |
2bda0e17 | 3898 | |
c42404a5 VZ |
3899 | if ( !id ) |
3900 | { | |
3901 | // normal ASCII char | |
42e69d6b VZ |
3902 | id = wParam; |
3903 | } | |
3904 | ||
c42404a5 | 3905 | if ( id != -1 ) // VZ: does this ever happen (FIXME)? |
2bda0e17 | 3906 | { |
c42404a5 | 3907 | wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, id, lParam)); |
42e69d6b | 3908 | if ( GetEventHandler()->ProcessEvent(event) ) |
2d0a075d | 3909 | { |
42e69d6b | 3910 | return TRUE; |
2d0a075d | 3911 | } |
42e69d6b | 3912 | } |
c42404a5 VZ |
3913 | |
3914 | return FALSE; | |
2bda0e17 KB |
3915 | } |
3916 | ||
1e6feb95 | 3917 | bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 3918 | { |
c42404a5 | 3919 | int id = wxCharCodeMSWToWX(wParam); |
2bda0e17 | 3920 | |
c42404a5 VZ |
3921 | if ( !id ) |
3922 | { | |
3923 | // normal ASCII char | |
42e69d6b | 3924 | id = wParam; |
2d0a075d | 3925 | } |
2bda0e17 | 3926 | |
c42404a5 | 3927 | if ( id != -1 ) // VZ: does this ever happen (FIXME)? |
42e69d6b | 3928 | { |
c42404a5 | 3929 | wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, id, lParam)); |
42e69d6b VZ |
3930 | if ( GetEventHandler()->ProcessEvent(event) ) |
3931 | return TRUE; | |
42e69d6b | 3932 | } |
c42404a5 VZ |
3933 | |
3934 | return FALSE; | |
2bda0e17 KB |
3935 | } |
3936 | ||
42e69d6b VZ |
3937 | // --------------------------------------------------------------------------- |
3938 | // joystick | |
3939 | // --------------------------------------------------------------------------- | |
3940 | ||
1e6feb95 | 3941 | bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags) |
2bda0e17 | 3942 | { |
8cb172b4 | 3943 | #ifdef JOY_BUTTON1 |
42e69d6b VZ |
3944 | int change = 0; |
3945 | if ( flags & JOY_BUTTON1CHG ) | |
3946 | change = wxJOY_BUTTON1; | |
3947 | if ( flags & JOY_BUTTON2CHG ) | |
3948 | change = wxJOY_BUTTON2; | |
3949 | if ( flags & JOY_BUTTON3CHG ) | |
3950 | change = wxJOY_BUTTON3; | |
3951 | if ( flags & JOY_BUTTON4CHG ) | |
3952 | change = wxJOY_BUTTON4; | |
2bda0e17 | 3953 | |
42e69d6b VZ |
3954 | int buttons = 0; |
3955 | if ( flags & JOY_BUTTON1 ) | |
3956 | buttons |= wxJOY_BUTTON1; | |
3957 | if ( flags & JOY_BUTTON2 ) | |
3958 | buttons |= wxJOY_BUTTON2; | |
3959 | if ( flags & JOY_BUTTON3 ) | |
3960 | buttons |= wxJOY_BUTTON3; | |
3961 | if ( flags & JOY_BUTTON4 ) | |
3962 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 3963 | |
42e69d6b VZ |
3964 | // the event ids aren't consecutive so we can't use table based lookup |
3965 | int joystick; | |
3966 | wxEventType eventType; | |
3967 | switch ( msg ) | |
3968 | { | |
3969 | case MM_JOY1MOVE: | |
3970 | joystick = 1; | |
3971 | eventType = wxEVT_JOY_MOVE; | |
3972 | break; | |
2bda0e17 | 3973 | |
42e69d6b VZ |
3974 | case MM_JOY2MOVE: |
3975 | joystick = 2; | |
3976 | eventType = wxEVT_JOY_MOVE; | |
3977 | break; | |
2bda0e17 | 3978 | |
42e69d6b VZ |
3979 | case MM_JOY1ZMOVE: |
3980 | joystick = 1; | |
3981 | eventType = wxEVT_JOY_ZMOVE; | |
3982 | break; | |
2bda0e17 | 3983 | |
42e69d6b VZ |
3984 | case MM_JOY2ZMOVE: |
3985 | joystick = 2; | |
3986 | eventType = wxEVT_JOY_ZMOVE; | |
3987 | break; | |
2bda0e17 | 3988 | |
42e69d6b VZ |
3989 | case MM_JOY1BUTTONDOWN: |
3990 | joystick = 1; | |
3991 | eventType = wxEVT_JOY_BUTTON_DOWN; | |
3992 | break; | |
2bda0e17 | 3993 | |
42e69d6b VZ |
3994 | case MM_JOY2BUTTONDOWN: |
3995 | joystick = 2; | |
3996 | eventType = wxEVT_JOY_BUTTON_DOWN; | |
3997 | break; | |
2bda0e17 | 3998 | |
42e69d6b VZ |
3999 | case MM_JOY1BUTTONUP: |
4000 | joystick = 1; | |
4001 | eventType = wxEVT_JOY_BUTTON_UP; | |
4002 | break; | |
4003 | ||
4004 | case MM_JOY2BUTTONUP: | |
4005 | joystick = 2; | |
4006 | eventType = wxEVT_JOY_BUTTON_UP; | |
4007 | break; | |
4008 | ||
4009 | default: | |
223d09f6 | 4010 | wxFAIL_MSG(wxT("no such joystick event")); |
2d0a075d | 4011 | |
42e69d6b | 4012 | return FALSE; |
2d0a075d | 4013 | } |
2bda0e17 | 4014 | |
42e69d6b VZ |
4015 | wxJoystickEvent event(eventType, buttons, joystick, change); |
4016 | event.SetPosition(wxPoint(x, y)); | |
4017 | event.SetEventObject(this); | |
c085e333 | 4018 | |
42e69d6b | 4019 | return GetEventHandler()->ProcessEvent(event); |
8cb172b4 JS |
4020 | #else |
4021 | return FALSE; | |
4022 | #endif | |
2bda0e17 KB |
4023 | } |
4024 | ||
42e69d6b VZ |
4025 | // --------------------------------------------------------------------------- |
4026 | // scrolling | |
4027 | // --------------------------------------------------------------------------- | |
4028 | ||
1e6feb95 | 4029 | bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam, |
42e69d6b | 4030 | WXWORD pos, WXHWND control) |
2bda0e17 | 4031 | { |
42e69d6b | 4032 | if ( control ) |
cc2b7472 | 4033 | { |
42e69d6b VZ |
4034 | wxWindow *child = wxFindWinFromHandle(control); |
4035 | if ( child ) | |
4036 | return child->MSWOnScroll(orientation, wParam, pos, control); | |
cc2b7472 | 4037 | } |
2bda0e17 | 4038 | |
9145664b | 4039 | wxScrollWinEvent event; |
42e69d6b VZ |
4040 | event.SetPosition(pos); |
4041 | event.SetOrientation(orientation); | |
4042 | event.m_eventObject = this; | |
cc2b7472 | 4043 | |
42e69d6b VZ |
4044 | switch ( wParam ) |
4045 | { | |
4046 | case SB_TOP: | |
9145664b | 4047 | event.m_eventType = wxEVT_SCROLLWIN_TOP; |
42e69d6b | 4048 | break; |
cc2b7472 | 4049 | |
42e69d6b | 4050 | case SB_BOTTOM: |
9145664b | 4051 | event.m_eventType = wxEVT_SCROLLWIN_BOTTOM; |
42e69d6b | 4052 | break; |
cc2b7472 | 4053 | |
42e69d6b | 4054 | case SB_LINEUP: |
9145664b | 4055 | event.m_eventType = wxEVT_SCROLLWIN_LINEUP; |
42e69d6b | 4056 | break; |
2bda0e17 | 4057 | |
42e69d6b | 4058 | case SB_LINEDOWN: |
9145664b | 4059 | event.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; |
42e69d6b | 4060 | break; |
a02eb1d2 | 4061 | |
42e69d6b | 4062 | case SB_PAGEUP: |
9145664b | 4063 | event.m_eventType = wxEVT_SCROLLWIN_PAGEUP; |
42e69d6b | 4064 | break; |
2bda0e17 | 4065 | |
42e69d6b | 4066 | case SB_PAGEDOWN: |
9145664b | 4067 | event.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; |
42e69d6b | 4068 | break; |
2bda0e17 | 4069 | |
42e69d6b | 4070 | case SB_THUMBPOSITION: |
feda3011 | 4071 | case SB_THUMBTRACK: |
f6bcfd97 BP |
4072 | #ifdef __WIN32__ |
4073 | // under Win32, the scrollbar range and position are 32 bit integers, | |
4074 | // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must | |
4075 | // explicitly query the scrollbar for the correct position (this must | |
4076 | // be done only for these two SB_ events as they are the only one | |
4077 | // carrying the scrollbar position) | |
4078 | { | |
4079 | SCROLLINFO scrollInfo; | |
4080 | wxZeroMemory(scrollInfo); | |
4081 | scrollInfo.cbSize = sizeof(SCROLLINFO); | |
4082 | scrollInfo.fMask = SIF_TRACKPOS; | |
4083 | ||
4084 | if ( !::GetScrollInfo(GetHwnd(), | |
4085 | orientation == wxHORIZONTAL ? SB_HORZ | |
4086 | : SB_VERT, | |
4087 | &scrollInfo) ) | |
4088 | { | |
4089 | wxLogLastError(_T("GetScrollInfo")); | |
4090 | } | |
4091 | ||
4092 | event.SetPosition(scrollInfo.nTrackPos); | |
4093 | } | |
4094 | #endif // Win32 | |
4095 | ||
4096 | event.m_eventType = wParam == SB_THUMBPOSITION | |
4097 | ? wxEVT_SCROLLWIN_THUMBRELEASE | |
4098 | : wxEVT_SCROLLWIN_THUMBTRACK; | |
42e69d6b | 4099 | break; |
c085e333 | 4100 | |
42e69d6b VZ |
4101 | default: |
4102 | return FALSE; | |
564b2609 | 4103 | } |
2bda0e17 | 4104 | |
42e69d6b | 4105 | return GetEventHandler()->ProcessEvent(event); |
2bda0e17 KB |
4106 | } |
4107 | ||
42e69d6b VZ |
4108 | // =========================================================================== |
4109 | // global functions | |
4110 | // =========================================================================== | |
4111 | ||
f68586e5 | 4112 | void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont *the_font) |
2bda0e17 | 4113 | { |
42e69d6b VZ |
4114 | TEXTMETRIC tm; |
4115 | HDC dc = ::GetDC((HWND) wnd); | |
4116 | HFONT fnt =0; | |
4117 | HFONT was = 0; | |
4118 | if ( the_font ) | |
2d0a075d | 4119 | { |
42e69d6b VZ |
4120 | // the_font->UseResource(); |
4121 | // the_font->RealizeResource(); | |
f68586e5 | 4122 | fnt = (HFONT)((wxFont *)the_font)->GetResourceHandle(); // const_cast |
42e69d6b VZ |
4123 | if ( fnt ) |
4124 | was = (HFONT) SelectObject(dc,fnt); | |
2d0a075d | 4125 | } |
42e69d6b VZ |
4126 | GetTextMetrics(dc, &tm); |
4127 | if ( the_font && fnt && was ) | |
2d0a075d | 4128 | { |
42e69d6b | 4129 | SelectObject(dc,was); |
2d0a075d | 4130 | } |
42e69d6b | 4131 | ReleaseDC((HWND)wnd, dc); |
0655ad29 VZ |
4132 | |
4133 | if ( x ) | |
4134 | *x = tm.tmAveCharWidth; | |
4135 | if ( y ) | |
4136 | *y = tm.tmHeight + tm.tmExternalLeading; | |
2bda0e17 | 4137 | |
42e69d6b VZ |
4138 | // if ( the_font ) |
4139 | // the_font->ReleaseResource(); | |
4140 | } | |
c085e333 | 4141 | |
42e69d6b VZ |
4142 | // Returns 0 if was a normal ASCII value, not a special key. This indicates that |
4143 | // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead. | |
4144 | int wxCharCodeMSWToWX(int keySym) | |
4145 | { | |
f6bcfd97 | 4146 | int id; |
42e69d6b VZ |
4147 | switch (keySym) |
4148 | { | |
f6bcfd97 BP |
4149 | case VK_CANCEL: id = WXK_CANCEL; break; |
4150 | case VK_BACK: id = WXK_BACK; break; | |
4151 | case VK_TAB: id = WXK_TAB; break; | |
4152 | case VK_CLEAR: id = WXK_CLEAR; break; | |
4153 | case VK_RETURN: id = WXK_RETURN; break; | |
4154 | case VK_SHIFT: id = WXK_SHIFT; break; | |
4155 | case VK_CONTROL: id = WXK_CONTROL; break; | |
4156 | case VK_MENU : id = WXK_MENU; break; | |
4157 | case VK_PAUSE: id = WXK_PAUSE; break; | |
4158 | case VK_SPACE: id = WXK_SPACE; break; | |
4159 | case VK_ESCAPE: id = WXK_ESCAPE; break; | |
4160 | case VK_PRIOR: id = WXK_PRIOR; break; | |
4161 | case VK_NEXT : id = WXK_NEXT; break; | |
4162 | case VK_END: id = WXK_END; break; | |
4163 | case VK_HOME : id = WXK_HOME; break; | |
4164 | case VK_LEFT : id = WXK_LEFT; break; | |
4165 | case VK_UP: id = WXK_UP; break; | |
4166 | case VK_RIGHT: id = WXK_RIGHT; break; | |
4167 | case VK_DOWN : id = WXK_DOWN; break; | |
4168 | case VK_SELECT: id = WXK_SELECT; break; | |
4169 | case VK_PRINT: id = WXK_PRINT; break; | |
4170 | case VK_EXECUTE: id = WXK_EXECUTE; break; | |
4171 | case VK_INSERT: id = WXK_INSERT; break; | |
4172 | case VK_DELETE: id = WXK_DELETE; break; | |
4173 | case VK_HELP : id = WXK_HELP; break; | |
4174 | case VK_NUMPAD0: id = WXK_NUMPAD0; break; | |
4175 | case VK_NUMPAD1: id = WXK_NUMPAD1; break; | |
4176 | case VK_NUMPAD2: id = WXK_NUMPAD2; break; | |
4177 | case VK_NUMPAD3: id = WXK_NUMPAD3; break; | |
4178 | case VK_NUMPAD4: id = WXK_NUMPAD4; break; | |
4179 | case VK_NUMPAD5: id = WXK_NUMPAD5; break; | |
4180 | case VK_NUMPAD6: id = WXK_NUMPAD6; break; | |
4181 | case VK_NUMPAD7: id = WXK_NUMPAD7; break; | |
4182 | case VK_NUMPAD8: id = WXK_NUMPAD8; break; | |
4183 | case VK_NUMPAD9: id = WXK_NUMPAD9; break; | |
32a87ae7 | 4184 | case VK_MULTIPLY: id = WXK_NUMPAD_MULTIPLY; break; |
32a87ae7 | 4185 | case VK_ADD: id = WXK_NUMPAD_ADD; break; |
32a87ae7 | 4186 | case VK_SUBTRACT: id = WXK_NUMPAD_SUBTRACT; break; |
32a87ae7 VZ |
4187 | case VK_DECIMAL: id = WXK_NUMPAD_DECIMAL; break; |
4188 | case VK_DIVIDE: id = WXK_NUMPAD_DIVIDE; break; | |
f6bcfd97 BP |
4189 | case VK_F1: id = WXK_F1; break; |
4190 | case VK_F2: id = WXK_F2; break; | |
4191 | case VK_F3: id = WXK_F3; break; | |
4192 | case VK_F4: id = WXK_F4; break; | |
4193 | case VK_F5: id = WXK_F5; break; | |
4194 | case VK_F6: id = WXK_F6; break; | |
4195 | case VK_F7: id = WXK_F7; break; | |
4196 | case VK_F8: id = WXK_F8; break; | |
4197 | case VK_F9: id = WXK_F9; break; | |
4198 | case VK_F10: id = WXK_F10; break; | |
4199 | case VK_F11: id = WXK_F11; break; | |
4200 | case VK_F12: id = WXK_F12; break; | |
4201 | case VK_F13: id = WXK_F13; break; | |
4202 | case VK_F14: id = WXK_F14; break; | |
4203 | case VK_F15: id = WXK_F15; break; | |
4204 | case VK_F16: id = WXK_F16; break; | |
4205 | case VK_F17: id = WXK_F17; break; | |
4206 | case VK_F18: id = WXK_F18; break; | |
4207 | case VK_F19: id = WXK_F19; break; | |
4208 | case VK_F20: id = WXK_F20; break; | |
4209 | case VK_F21: id = WXK_F21; break; | |
4210 | case VK_F22: id = WXK_F22; break; | |
4211 | case VK_F23: id = WXK_F23; break; | |
4212 | case VK_F24: id = WXK_F24; break; | |
4213 | case VK_NUMLOCK: id = WXK_NUMLOCK; break; | |
4214 | case VK_SCROLL: id = WXK_SCROLL; break; | |
4215 | default: | |
4216 | id = 0; | |
42e69d6b | 4217 | } |
f6bcfd97 | 4218 | |
42e69d6b | 4219 | return id; |
2bda0e17 KB |
4220 | } |
4221 | ||
42e69d6b | 4222 | int wxCharCodeWXToMSW(int id, bool *isVirtual) |
2bda0e17 | 4223 | { |
42e69d6b VZ |
4224 | *isVirtual = TRUE; |
4225 | int keySym = 0; | |
4226 | switch (id) | |
2bda0e17 | 4227 | { |
42e69d6b VZ |
4228 | case WXK_CANCEL: keySym = VK_CANCEL; break; |
4229 | case WXK_CLEAR: keySym = VK_CLEAR; break; | |
4230 | case WXK_SHIFT: keySym = VK_SHIFT; break; | |
4231 | case WXK_CONTROL: keySym = VK_CONTROL; break; | |
4232 | case WXK_MENU : keySym = VK_MENU; break; | |
4233 | case WXK_PAUSE: keySym = VK_PAUSE; break; | |
4234 | case WXK_PRIOR: keySym = VK_PRIOR; break; | |
4235 | case WXK_NEXT : keySym = VK_NEXT; break; | |
4236 | case WXK_END: keySym = VK_END; break; | |
4237 | case WXK_HOME : keySym = VK_HOME; break; | |
4238 | case WXK_LEFT : keySym = VK_LEFT; break; | |
4239 | case WXK_UP: keySym = VK_UP; break; | |
4240 | case WXK_RIGHT: keySym = VK_RIGHT; break; | |
4241 | case WXK_DOWN : keySym = VK_DOWN; break; | |
4242 | case WXK_SELECT: keySym = VK_SELECT; break; | |
4243 | case WXK_PRINT: keySym = VK_PRINT; break; | |
4244 | case WXK_EXECUTE: keySym = VK_EXECUTE; break; | |
4245 | case WXK_INSERT: keySym = VK_INSERT; break; | |
4246 | case WXK_DELETE: keySym = VK_DELETE; break; | |
4247 | case WXK_HELP : keySym = VK_HELP; break; | |
4248 | case WXK_NUMPAD0: keySym = VK_NUMPAD0; break; | |
4249 | case WXK_NUMPAD1: keySym = VK_NUMPAD1; break; | |
4250 | case WXK_NUMPAD2: keySym = VK_NUMPAD2; break; | |
4251 | case WXK_NUMPAD3: keySym = VK_NUMPAD3; break; | |
4252 | case WXK_NUMPAD4: keySym = VK_NUMPAD4; break; | |
4253 | case WXK_NUMPAD5: keySym = VK_NUMPAD5; break; | |
4254 | case WXK_NUMPAD6: keySym = VK_NUMPAD6; break; | |
4255 | case WXK_NUMPAD7: keySym = VK_NUMPAD7; break; | |
4256 | case WXK_NUMPAD8: keySym = VK_NUMPAD8; break; | |
4257 | case WXK_NUMPAD9: keySym = VK_NUMPAD9; break; | |
32a87ae7 VZ |
4258 | case WXK_NUMPAD_MULTIPLY: keySym = VK_MULTIPLY; break; |
4259 | case WXK_NUMPAD_ADD: keySym = VK_ADD; break; | |
4260 | case WXK_NUMPAD_SUBTRACT: keySym = VK_SUBTRACT; break; | |
4261 | case WXK_NUMPAD_DECIMAL: keySym = VK_DECIMAL; break; | |
4262 | case WXK_NUMPAD_DIVIDE: keySym = VK_DIVIDE; break; | |
42e69d6b VZ |
4263 | case WXK_F1: keySym = VK_F1; break; |
4264 | case WXK_F2: keySym = VK_F2; break; | |
4265 | case WXK_F3: keySym = VK_F3; break; | |
4266 | case WXK_F4: keySym = VK_F4; break; | |
4267 | case WXK_F5: keySym = VK_F5; break; | |
4268 | case WXK_F6: keySym = VK_F6; break; | |
4269 | case WXK_F7: keySym = VK_F7; break; | |
4270 | case WXK_F8: keySym = VK_F8; break; | |
4271 | case WXK_F9: keySym = VK_F9; break; | |
4272 | case WXK_F10: keySym = VK_F10; break; | |
4273 | case WXK_F11: keySym = VK_F11; break; | |
4274 | case WXK_F12: keySym = VK_F12; break; | |
4275 | case WXK_F13: keySym = VK_F13; break; | |
4276 | case WXK_F14: keySym = VK_F14; break; | |
4277 | case WXK_F15: keySym = VK_F15; break; | |
4278 | case WXK_F16: keySym = VK_F16; break; | |
4279 | case WXK_F17: keySym = VK_F17; break; | |
4280 | case WXK_F18: keySym = VK_F18; break; | |
4281 | case WXK_F19: keySym = VK_F19; break; | |
4282 | case WXK_F20: keySym = VK_F20; break; | |
4283 | case WXK_F21: keySym = VK_F21; break; | |
4284 | case WXK_F22: keySym = VK_F22; break; | |
4285 | case WXK_F23: keySym = VK_F23; break; | |
4286 | case WXK_F24: keySym = VK_F24; break; | |
4287 | case WXK_NUMLOCK: keySym = VK_NUMLOCK; break; | |
4288 | case WXK_SCROLL: keySym = VK_SCROLL; break; | |
4289 | default: | |
4290 | { | |
4291 | *isVirtual = FALSE; | |
4292 | keySym = id; | |
4293 | break; | |
4294 | } | |
2bda0e17 | 4295 | } |
42e69d6b | 4296 | return keySym; |
2bda0e17 KB |
4297 | } |
4298 | ||
42e69d6b | 4299 | wxWindow *wxGetActiveWindow() |
2bda0e17 | 4300 | { |
42e69d6b VZ |
4301 | HWND hWnd = GetActiveWindow(); |
4302 | if ( hWnd != 0 ) | |
2d0a075d | 4303 | { |
42e69d6b | 4304 | return wxFindWinFromHandle((WXHWND) hWnd); |
2d0a075d | 4305 | } |
42e69d6b | 4306 | return NULL; |
2bda0e17 KB |
4307 | } |
4308 | ||
8614c467 VZ |
4309 | extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd) |
4310 | { | |
4311 | HWND hwnd = (HWND)hWnd; | |
4312 | ||
4313 | // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set | |
4314 | // by code in msw/radiobox.cpp), for all the others we just search up the | |
4315 | // window hierarchy | |
4316 | wxWindow *win = (wxWindow *)NULL; | |
4317 | if ( hwnd ) | |
4318 | { | |
4319 | win = wxFindWinFromHandle((WXHWND)hwnd); | |
4320 | if ( !win ) | |
4321 | { | |
a2242341 | 4322 | // all these hacks only work under Win32 anyhow |
4f527e71 | 4323 | #ifdef __WIN32__ |
a2242341 VZ |
4324 | |
4325 | #if wxUSE_RADIOBOX | |
8614c467 VZ |
4326 | // native radiobuttons return DLGC_RADIOBUTTON here and for any |
4327 | // wxWindow class which overrides WM_GETDLGCODE processing to | |
4328 | // do it as well, win would be already non NULL | |
a2242341 | 4329 | if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON ) |
8614c467 VZ |
4330 | { |
4331 | win = (wxWindow *)::GetWindowLong(hwnd, GWL_USERDATA); | |
4332 | } | |
a2242341 VZ |
4333 | //else: it's a wxRadioButton, not a radiobutton from wxRadioBox |
4334 | #endif // wxUSE_RADIOBOX | |
4335 | ||
4336 | // spin control text buddy window should be mapped to spin ctrl | |
4337 | // itself so try it too | |
24ce4c18 | 4338 | #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__) |
a2242341 VZ |
4339 | if ( !win ) |
4340 | { | |
4341 | win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd); | |
4342 | } | |
4343 | #endif // wxUSE_SPINCTRL | |
4344 | ||
4f527e71 | 4345 | #endif // Win32 |
8614c467 | 4346 | } |
8614c467 VZ |
4347 | } |
4348 | ||
4349 | while ( hwnd && !win ) | |
4350 | { | |
761989ff VZ |
4351 | // this is a really ugly hack needed to avoid mistakenly returning the |
4352 | // parent frame wxWindow for the find/replace modeless dialog HWND - | |
4353 | // this, in turn, is needed to call IsDialogMessage() from | |
4354 | // wxApp::ProcessMessage() as for this we must return NULL from here | |
4355 | // | |
4356 | // FIXME: this is clearly not the best way to do it but I think we'll | |
4357 | // need to change HWND <-> wxWindow code more heavily than I can | |
4358 | // do it now to fix it | |
4359 | if ( ::GetWindow(hwnd, GW_OWNER) ) | |
4360 | { | |
4361 | // it's a dialog box, don't go upwards | |
4362 | break; | |
4363 | } | |
4364 | ||
8614c467 | 4365 | hwnd = ::GetParent(hwnd); |
761989ff | 4366 | win = wxFindWinFromHandle((WXHWND)hwnd); |
8614c467 VZ |
4367 | } |
4368 | ||
4369 | return win; | |
4370 | } | |
4371 | ||
04ef50df JS |
4372 | #ifndef __WXMICROWIN__ |
4373 | ||
42e69d6b VZ |
4374 | // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE |
4375 | // in active frames and dialogs, regardless of where the focus is. | |
4376 | static HHOOK wxTheKeyboardHook = 0; | |
4377 | static FARPROC wxTheKeyboardHookProc = 0; | |
4378 | int APIENTRY _EXPORT | |
4379 | wxKeyboardHook(int nCode, WORD wParam, DWORD lParam); | |
2bda0e17 | 4380 | |
42e69d6b | 4381 | void wxSetKeyboardHook(bool doIt) |
2bda0e17 | 4382 | { |
42e69d6b | 4383 | if ( doIt ) |
2d0a075d | 4384 | { |
42e69d6b VZ |
4385 | wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance()); |
4386 | wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(), | |
c7527e3f | 4387 | |
42e69d6b | 4388 | #if defined(__WIN32__) && !defined(__TWIN32__) |
8614c467 | 4389 | GetCurrentThreadId() |
42e69d6b VZ |
4390 | // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right? |
4391 | #else | |
8614c467 | 4392 | GetCurrentTask() |
42e69d6b | 4393 | #endif |
8614c467 | 4394 | ); |
2d0a075d | 4395 | } |
2d0a075d | 4396 | else |
2d0a075d | 4397 | { |
42e69d6b | 4398 | UnhookWindowsHookEx(wxTheKeyboardHook); |
4cdc2c13 VZ |
4399 | |
4400 | // avoids warning about statement with no effect (FreeProcInstance | |
4401 | // doesn't do anything under Win32) | |
33ac7e6f | 4402 | #if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) && !defined(__NT__) && !defined(__GNUWIN32__) |
42e69d6b | 4403 | FreeProcInstance(wxTheKeyboardHookProc); |
a17e237f | 4404 | #endif |
2d0a075d | 4405 | } |
2bda0e17 KB |
4406 | } |
4407 | ||
42e69d6b VZ |
4408 | int APIENTRY _EXPORT |
4409 | wxKeyboardHook(int nCode, WORD wParam, DWORD lParam) | |
2bda0e17 | 4410 | { |
42e69d6b VZ |
4411 | DWORD hiWord = HIWORD(lParam); |
4412 | if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) ) | |
43d811ea | 4413 | { |
32de7d24 VZ |
4414 | int id = wxCharCodeMSWToWX(wParam); |
4415 | if ( id != 0 ) | |
43d811ea | 4416 | { |
42e69d6b VZ |
4417 | wxKeyEvent event(wxEVT_CHAR_HOOK); |
4418 | if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN ) | |
4419 | event.m_altDown = TRUE; | |
c085e333 | 4420 | |
42e69d6b VZ |
4421 | event.m_eventObject = NULL; |
4422 | event.m_keyCode = id; | |
3f7bc32b VZ |
4423 | event.m_shiftDown = wxIsShiftDown(); |
4424 | event.m_controlDown = wxIsCtrlDown(); | |
42e69d6b | 4425 | event.SetTimestamp(s_currentMsg.time); |
c085e333 | 4426 | |
42e69d6b | 4427 | wxWindow *win = wxGetActiveWindow(); |
32de7d24 | 4428 | wxEvtHandler *handler; |
42e69d6b VZ |
4429 | if ( win ) |
4430 | { | |
32de7d24 VZ |
4431 | handler = win->GetEventHandler(); |
4432 | event.SetId(win->GetId()); | |
42e69d6b VZ |
4433 | } |
4434 | else | |
4435 | { | |
32de7d24 VZ |
4436 | handler = wxTheApp; |
4437 | event.SetId(-1); | |
4438 | } | |
4439 | ||
4440 | if ( handler && handler->ProcessEvent(event) ) | |
4441 | { | |
4442 | // processed | |
4443 | return 1; | |
42e69d6b | 4444 | } |
43d811ea JS |
4445 | } |
4446 | } | |
32de7d24 | 4447 | |
42e69d6b | 4448 | return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam); |
4fabb575 | 4449 | } |
cd4453e5 VZ |
4450 | |
4451 | #endif // !__WXMICROWIN__ | |
4fabb575 | 4452 | |
b2aef89b | 4453 | #ifdef __WXDEBUG__ |
f449ef69 | 4454 | const char *wxGetMessageName(int message) |
47cbd6da | 4455 | { |
42e69d6b VZ |
4456 | switch ( message ) |
4457 | { | |
4458 | case 0x0000: return "WM_NULL"; | |
4459 | case 0x0001: return "WM_CREATE"; | |
4460 | case 0x0002: return "WM_DESTROY"; | |
4461 | case 0x0003: return "WM_MOVE"; | |
4462 | case 0x0005: return "WM_SIZE"; | |
4463 | case 0x0006: return "WM_ACTIVATE"; | |
4464 | case 0x0007: return "WM_SETFOCUS"; | |
4465 | case 0x0008: return "WM_KILLFOCUS"; | |
4466 | case 0x000A: return "WM_ENABLE"; | |
4467 | case 0x000B: return "WM_SETREDRAW"; | |
9b64e798 VZ |
4468 | case 0x000C: return "WM_SETTEXT"; |
4469 | case 0x000D: return "WM_GETTEXT"; | |
42e69d6b | 4470 | case 0x000E: return "WM_GETTEXTLENGTH"; |
9b64e798 | 4471 | case 0x000F: return "WM_PAINT"; |
42e69d6b VZ |
4472 | case 0x0010: return "WM_CLOSE"; |
4473 | case 0x0011: return "WM_QUERYENDSESSION"; | |
9b64e798 | 4474 | case 0x0012: return "WM_QUIT"; |
42e69d6b VZ |
4475 | case 0x0013: return "WM_QUERYOPEN"; |
4476 | case 0x0014: return "WM_ERASEBKGND"; | |
4477 | case 0x0015: return "WM_SYSCOLORCHANGE"; | |
4478 | case 0x0016: return "WM_ENDSESSION"; | |
4479 | case 0x0017: return "WM_SYSTEMERROR"; | |
4480 | case 0x0018: return "WM_SHOWWINDOW"; | |
4481 | case 0x0019: return "WM_CTLCOLOR"; | |
4482 | case 0x001A: return "WM_WININICHANGE"; | |
4483 | case 0x001B: return "WM_DEVMODECHANGE"; | |
4484 | case 0x001C: return "WM_ACTIVATEAPP"; | |
4485 | case 0x001D: return "WM_FONTCHANGE"; | |
4486 | case 0x001E: return "WM_TIMECHANGE"; | |
4487 | case 0x001F: return "WM_CANCELMODE"; | |
4488 | case 0x0020: return "WM_SETCURSOR"; | |
4489 | case 0x0021: return "WM_MOUSEACTIVATE"; | |
4490 | case 0x0022: return "WM_CHILDACTIVATE"; | |
4491 | case 0x0023: return "WM_QUEUESYNC"; | |
4492 | case 0x0024: return "WM_GETMINMAXINFO"; | |
4493 | case 0x0026: return "WM_PAINTICON"; | |
4494 | case 0x0027: return "WM_ICONERASEBKGND"; | |
4495 | case 0x0028: return "WM_NEXTDLGCTL"; | |
4496 | case 0x002A: return "WM_SPOOLERSTATUS"; | |
4497 | case 0x002B: return "WM_DRAWITEM"; | |
4498 | case 0x002C: return "WM_MEASUREITEM"; | |
4499 | case 0x002D: return "WM_DELETEITEM"; | |
4500 | case 0x002E: return "WM_VKEYTOITEM"; | |
4501 | case 0x002F: return "WM_CHARTOITEM"; | |
9b64e798 VZ |
4502 | case 0x0030: return "WM_SETFONT"; |
4503 | case 0x0031: return "WM_GETFONT"; | |
42e69d6b VZ |
4504 | case 0x0037: return "WM_QUERYDRAGICON"; |
4505 | case 0x0039: return "WM_COMPAREITEM"; | |
4506 | case 0x0041: return "WM_COMPACTING"; | |
4507 | case 0x0044: return "WM_COMMNOTIFY"; | |
4508 | case 0x0046: return "WM_WINDOWPOSCHANGING"; | |
4509 | case 0x0047: return "WM_WINDOWPOSCHANGED"; | |
4510 | case 0x0048: return "WM_POWER"; | |
c085e333 | 4511 | |
a02eb1d2 | 4512 | #ifdef __WIN32__ |
42e69d6b VZ |
4513 | case 0x004A: return "WM_COPYDATA"; |
4514 | case 0x004B: return "WM_CANCELJOURNAL"; | |
4515 | case 0x004E: return "WM_NOTIFY"; | |
9b64e798 | 4516 | case 0x0050: return "WM_INPUTLANGCHANGEREQUEST"; |
42e69d6b VZ |
4517 | case 0x0051: return "WM_INPUTLANGCHANGE"; |
4518 | case 0x0052: return "WM_TCARD"; | |
4519 | case 0x0053: return "WM_HELP"; | |
4520 | case 0x0054: return "WM_USERCHANGED"; | |
9b64e798 | 4521 | case 0x0055: return "WM_NOTIFYFORMAT"; |
42e69d6b VZ |
4522 | case 0x007B: return "WM_CONTEXTMENU"; |
4523 | case 0x007C: return "WM_STYLECHANGING"; | |
4524 | case 0x007D: return "WM_STYLECHANGED"; | |
4525 | case 0x007E: return "WM_DISPLAYCHANGE"; | |
4526 | case 0x007F: return "WM_GETICON"; | |
4527 | case 0x0080: return "WM_SETICON"; | |
a02eb1d2 | 4528 | #endif //WIN32 |
c085e333 | 4529 | |
42e69d6b VZ |
4530 | case 0x0081: return "WM_NCCREATE"; |
4531 | case 0x0082: return "WM_NCDESTROY"; | |
4532 | case 0x0083: return "WM_NCCALCSIZE"; | |
9b64e798 VZ |
4533 | case 0x0084: return "WM_NCHITTEST"; |
4534 | case 0x0085: return "WM_NCPAINT"; | |
42e69d6b VZ |
4535 | case 0x0086: return "WM_NCACTIVATE"; |
4536 | case 0x0087: return "WM_GETDLGCODE"; | |
4537 | case 0x00A0: return "WM_NCMOUSEMOVE"; | |
4538 | case 0x00A1: return "WM_NCLBUTTONDOWN"; | |
4539 | case 0x00A2: return "WM_NCLBUTTONUP"; | |
4540 | case 0x00A3: return "WM_NCLBUTTONDBLCLK"; | |
4541 | case 0x00A4: return "WM_NCRBUTTONDOWN"; | |
4542 | case 0x00A5: return "WM_NCRBUTTONUP"; | |
4543 | case 0x00A6: return "WM_NCRBUTTONDBLCLK"; | |
4544 | case 0x00A7: return "WM_NCMBUTTONDOWN"; | |
4545 | case 0x00A8: return "WM_NCMBUTTONUP"; | |
4546 | case 0x00A9: return "WM_NCMBUTTONDBLCLK"; | |
4547 | case 0x0100: return "WM_KEYDOWN"; | |
4548 | case 0x0101: return "WM_KEYUP"; | |
4549 | case 0x0102: return "WM_CHAR"; | |
4550 | case 0x0103: return "WM_DEADCHAR"; | |
4551 | case 0x0104: return "WM_SYSKEYDOWN"; | |
4552 | case 0x0105: return "WM_SYSKEYUP"; | |
4553 | case 0x0106: return "WM_SYSCHAR"; | |
4554 | case 0x0107: return "WM_SYSDEADCHAR"; | |
9b64e798 | 4555 | case 0x0108: return "WM_KEYLAST"; |
c085e333 | 4556 | |
a02eb1d2 | 4557 | #ifdef __WIN32__ |
42e69d6b VZ |
4558 | case 0x010D: return "WM_IME_STARTCOMPOSITION"; |
4559 | case 0x010E: return "WM_IME_ENDCOMPOSITION"; | |
4560 | case 0x010F: return "WM_IME_COMPOSITION"; | |
a02eb1d2 | 4561 | #endif //WIN32 |
c085e333 | 4562 | |
42e69d6b VZ |
4563 | case 0x0110: return "WM_INITDIALOG"; |
4564 | case 0x0111: return "WM_COMMAND"; | |
4565 | case 0x0112: return "WM_SYSCOMMAND"; | |
4566 | case 0x0113: return "WM_TIMER"; | |
4567 | case 0x0114: return "WM_HSCROLL"; | |
4568 | case 0x0115: return "WM_VSCROLL"; | |
4569 | case 0x0116: return "WM_INITMENU"; | |
4570 | case 0x0117: return "WM_INITMENUPOPUP"; | |
9b64e798 | 4571 | case 0x011F: return "WM_MENUSELECT"; |
42e69d6b VZ |
4572 | case 0x0120: return "WM_MENUCHAR"; |
4573 | case 0x0121: return "WM_ENTERIDLE"; | |
4574 | case 0x0200: return "WM_MOUSEMOVE"; | |
4575 | case 0x0201: return "WM_LBUTTONDOWN"; | |
4576 | case 0x0202: return "WM_LBUTTONUP"; | |
4577 | case 0x0203: return "WM_LBUTTONDBLCLK"; | |
4578 | case 0x0204: return "WM_RBUTTONDOWN"; | |
4579 | case 0x0205: return "WM_RBUTTONUP"; | |
4580 | case 0x0206: return "WM_RBUTTONDBLCLK"; | |
4581 | case 0x0207: return "WM_MBUTTONDOWN"; | |
4582 | case 0x0208: return "WM_MBUTTONUP"; | |
4583 | case 0x0209: return "WM_MBUTTONDBLCLK"; | |
d2c52078 | 4584 | case 0x020A: return "WM_MOUSEWHEEL"; |
42e69d6b VZ |
4585 | case 0x0210: return "WM_PARENTNOTIFY"; |
4586 | case 0x0211: return "WM_ENTERMENULOOP"; | |
4587 | case 0x0212: return "WM_EXITMENULOOP"; | |
c085e333 | 4588 | |
a02eb1d2 | 4589 | #ifdef __WIN32__ |
42e69d6b VZ |
4590 | case 0x0213: return "WM_NEXTMENU"; |
4591 | case 0x0214: return "WM_SIZING"; | |
4592 | case 0x0215: return "WM_CAPTURECHANGED"; | |
4593 | case 0x0216: return "WM_MOVING"; | |
9b64e798 | 4594 | case 0x0218: return "WM_POWERBROADCAST"; |
42e69d6b | 4595 | case 0x0219: return "WM_DEVICECHANGE"; |
a02eb1d2 | 4596 | #endif //WIN32 |
c085e333 | 4597 | |
42e69d6b VZ |
4598 | case 0x0220: return "WM_MDICREATE"; |
4599 | case 0x0221: return "WM_MDIDESTROY"; | |
4600 | case 0x0222: return "WM_MDIACTIVATE"; | |
4601 | case 0x0223: return "WM_MDIRESTORE"; | |
9b64e798 | 4602 | case 0x0224: return "WM_MDINEXT"; |
42e69d6b VZ |
4603 | case 0x0225: return "WM_MDIMAXIMIZE"; |
4604 | case 0x0226: return "WM_MDITILE"; | |
4605 | case 0x0227: return "WM_MDICASCADE"; | |
4606 | case 0x0228: return "WM_MDIICONARRANGE"; | |
4607 | case 0x0229: return "WM_MDIGETACTIVE"; | |
4608 | case 0x0230: return "WM_MDISETMENU"; | |
4609 | case 0x0233: return "WM_DROPFILES"; | |
c085e333 | 4610 | |
a02eb1d2 | 4611 | #ifdef __WIN32__ |
9b64e798 | 4612 | case 0x0281: return "WM_IME_SETCONTEXT"; |
42e69d6b VZ |
4613 | case 0x0282: return "WM_IME_NOTIFY"; |
4614 | case 0x0283: return "WM_IME_CONTROL"; | |
4615 | case 0x0284: return "WM_IME_COMPOSITIONFULL"; | |
9b64e798 | 4616 | case 0x0285: return "WM_IME_SELECT"; |
42e69d6b VZ |
4617 | case 0x0286: return "WM_IME_CHAR"; |
4618 | case 0x0290: return "WM_IME_KEYDOWN"; | |
4619 | case 0x0291: return "WM_IME_KEYUP"; | |
a02eb1d2 | 4620 | #endif //WIN32 |
c085e333 | 4621 | |
9b64e798 | 4622 | case 0x0300: return "WM_CUT"; |
42e69d6b VZ |
4623 | case 0x0301: return "WM_COPY"; |
4624 | case 0x0302: return "WM_PASTE"; | |
4625 | case 0x0303: return "WM_CLEAR"; | |
4626 | case 0x0304: return "WM_UNDO"; | |
9b64e798 | 4627 | case 0x0305: return "WM_RENDERFORMAT"; |
42e69d6b VZ |
4628 | case 0x0306: return "WM_RENDERALLFORMATS"; |
4629 | case 0x0307: return "WM_DESTROYCLIPBOARD"; | |
4630 | case 0x0308: return "WM_DRAWCLIPBOARD"; | |
4631 | case 0x0309: return "WM_PAINTCLIPBOARD"; | |
4632 | case 0x030A: return "WM_VSCROLLCLIPBOARD"; | |
4633 | case 0x030B: return "WM_SIZECLIPBOARD"; | |
4634 | case 0x030C: return "WM_ASKCBFORMATNAME"; | |
4635 | case 0x030D: return "WM_CHANGECBCHAIN"; | |
4636 | case 0x030E: return "WM_HSCROLLCLIPBOARD"; | |
4637 | case 0x030F: return "WM_QUERYNEWPALETTE"; | |
4638 | case 0x0310: return "WM_PALETTEISCHANGING"; | |
4639 | case 0x0311: return "WM_PALETTECHANGED"; | |
c085e333 | 4640 | |
a02eb1d2 | 4641 | #ifdef __WIN32__ |
2d0a075d JS |
4642 | // common controls messages - although they're not strictly speaking |
4643 | // standard, it's nice to decode them nevertheless | |
a02eb1d2 | 4644 | |
2d0a075d | 4645 | // listview |
42e69d6b VZ |
4646 | case 0x1000 + 0: return "LVM_GETBKCOLOR"; |
4647 | case 0x1000 + 1: return "LVM_SETBKCOLOR"; | |
9b64e798 VZ |
4648 | case 0x1000 + 2: return "LVM_GETIMAGELIST"; |
4649 | case 0x1000 + 3: return "LVM_SETIMAGELIST"; | |
4650 | case 0x1000 + 4: return "LVM_GETITEMCOUNT"; | |
42e69d6b VZ |
4651 | case 0x1000 + 5: return "LVM_GETITEMA"; |
4652 | case 0x1000 + 75: return "LVM_GETITEMW"; | |
4653 | case 0x1000 + 6: return "LVM_SETITEMA"; | |
4654 | case 0x1000 + 76: return "LVM_SETITEMW"; | |
4655 | case 0x1000 + 7: return "LVM_INSERTITEMA"; | |
4656 | case 0x1000 + 77: return "LVM_INSERTITEMW"; | |
4657 | case 0x1000 + 8: return "LVM_DELETEITEM"; | |
4658 | case 0x1000 + 9: return "LVM_DELETEALLITEMS"; | |
4659 | case 0x1000 + 10: return "LVM_GETCALLBACKMASK"; | |
4660 | case 0x1000 + 11: return "LVM_SETCALLBACKMASK"; | |
4661 | case 0x1000 + 12: return "LVM_GETNEXTITEM"; | |
4662 | case 0x1000 + 13: return "LVM_FINDITEMA"; | |
4663 | case 0x1000 + 83: return "LVM_FINDITEMW"; | |
9b64e798 | 4664 | case 0x1000 + 14: return "LVM_GETITEMRECT"; |
42e69d6b VZ |
4665 | case 0x1000 + 15: return "LVM_SETITEMPOSITION"; |
4666 | case 0x1000 + 16: return "LVM_GETITEMPOSITION"; | |
4667 | case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA"; | |
4668 | case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW"; | |
9b64e798 | 4669 | case 0x1000 + 18: return "LVM_HITTEST"; |
42e69d6b VZ |
4670 | case 0x1000 + 19: return "LVM_ENSUREVISIBLE"; |
4671 | case 0x1000 + 20: return "LVM_SCROLL"; | |
4672 | case 0x1000 + 21: return "LVM_REDRAWITEMS"; | |
4673 | case 0x1000 + 22: return "LVM_ARRANGE"; | |
4674 | case 0x1000 + 23: return "LVM_EDITLABELA"; | |
4675 | case 0x1000 + 118: return "LVM_EDITLABELW"; | |
4676 | case 0x1000 + 24: return "LVM_GETEDITCONTROL"; | |
4677 | case 0x1000 + 25: return "LVM_GETCOLUMNA"; | |
4678 | case 0x1000 + 95: return "LVM_GETCOLUMNW"; | |
4679 | case 0x1000 + 26: return "LVM_SETCOLUMNA"; | |
4680 | case 0x1000 + 96: return "LVM_SETCOLUMNW"; | |
4681 | case 0x1000 + 27: return "LVM_INSERTCOLUMNA"; | |
4682 | case 0x1000 + 97: return "LVM_INSERTCOLUMNW"; | |
4683 | case 0x1000 + 28: return "LVM_DELETECOLUMN"; | |
4684 | case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH"; | |
4685 | case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH"; | |
4686 | case 0x1000 + 31: return "LVM_GETHEADER"; | |
4687 | case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE"; | |
9b64e798 | 4688 | case 0x1000 + 34: return "LVM_GETVIEWRECT"; |
42e69d6b VZ |
4689 | case 0x1000 + 35: return "LVM_GETTEXTCOLOR"; |
4690 | case 0x1000 + 36: return "LVM_SETTEXTCOLOR"; | |
4691 | case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR"; | |
4692 | case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR"; | |
4693 | case 0x1000 + 39: return "LVM_GETTOPINDEX"; | |
4694 | case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE"; | |
4695 | case 0x1000 + 41: return "LVM_GETORIGIN"; | |
4696 | case 0x1000 + 42: return "LVM_UPDATE"; | |
4697 | case 0x1000 + 43: return "LVM_SETITEMSTATE"; | |
4698 | case 0x1000 + 44: return "LVM_GETITEMSTATE"; | |
4699 | case 0x1000 + 45: return "LVM_GETITEMTEXTA"; | |
4700 | case 0x1000 + 115: return "LVM_GETITEMTEXTW"; | |
4701 | case 0x1000 + 46: return "LVM_SETITEMTEXTA"; | |
4702 | case 0x1000 + 116: return "LVM_SETITEMTEXTW"; | |
9b64e798 | 4703 | case 0x1000 + 47: return "LVM_SETITEMCOUNT"; |
42e69d6b VZ |
4704 | case 0x1000 + 48: return "LVM_SORTITEMS"; |
4705 | case 0x1000 + 49: return "LVM_SETITEMPOSITION32"; | |
9b64e798 | 4706 | case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT"; |
42e69d6b VZ |
4707 | case 0x1000 + 51: return "LVM_GETITEMSPACING"; |
4708 | case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA"; | |
4709 | case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW"; | |
4710 | case 0x1000 + 53: return "LVM_SETICONSPACING"; | |
4711 | case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE"; | |
4712 | case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE"; | |
9b64e798 VZ |
4713 | case 0x1000 + 56: return "LVM_GETSUBITEMRECT"; |
4714 | case 0x1000 + 57: return "LVM_SUBITEMHITTEST"; | |
42e69d6b VZ |
4715 | case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY"; |
4716 | case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY"; | |
4717 | case 0x1000 + 60: return "LVM_SETHOTITEM"; | |
4718 | case 0x1000 + 61: return "LVM_GETHOTITEM"; | |
4719 | case 0x1000 + 62: return "LVM_SETHOTCURSOR"; | |
4720 | case 0x1000 + 63: return "LVM_GETHOTCURSOR"; | |
9b64e798 | 4721 | case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT"; |
42e69d6b | 4722 | case 0x1000 + 65: return "LVM_SETWORKAREA"; |
c085e333 | 4723 | |
2d0a075d | 4724 | // tree view |
42e69d6b VZ |
4725 | case 0x1100 + 0: return "TVM_INSERTITEMA"; |
4726 | case 0x1100 + 50: return "TVM_INSERTITEMW"; | |
4727 | case 0x1100 + 1: return "TVM_DELETEITEM"; | |
4728 | case 0x1100 + 2: return "TVM_EXPAND"; | |
9b64e798 VZ |
4729 | case 0x1100 + 4: return "TVM_GETITEMRECT"; |
4730 | case 0x1100 + 5: return "TVM_GETCOUNT"; | |
4731 | case 0x1100 + 6: return "TVM_GETINDENT"; | |
4732 | case 0x1100 + 7: return "TVM_SETINDENT"; | |
4733 | case 0x1100 + 8: return "TVM_GETIMAGELIST"; | |
4734 | case 0x1100 + 9: return "TVM_SETIMAGELIST"; | |
42e69d6b VZ |
4735 | case 0x1100 + 10: return "TVM_GETNEXTITEM"; |
4736 | case 0x1100 + 11: return "TVM_SELECTITEM"; | |
4737 | case 0x1100 + 12: return "TVM_GETITEMA"; | |
4738 | case 0x1100 + 62: return "TVM_GETITEMW"; | |
4739 | case 0x1100 + 13: return "TVM_SETITEMA"; | |
4740 | case 0x1100 + 63: return "TVM_SETITEMW"; | |
4741 | case 0x1100 + 14: return "TVM_EDITLABELA"; | |
4742 | case 0x1100 + 65: return "TVM_EDITLABELW"; | |
4743 | case 0x1100 + 15: return "TVM_GETEDITCONTROL"; | |
9b64e798 VZ |
4744 | case 0x1100 + 16: return "TVM_GETVISIBLECOUNT"; |
4745 | case 0x1100 + 17: return "TVM_HITTEST"; | |
42e69d6b VZ |
4746 | case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE"; |
4747 | case 0x1100 + 19: return "TVM_SORTCHILDREN"; | |
4748 | case 0x1100 + 20: return "TVM_ENSUREVISIBLE"; | |
4749 | case 0x1100 + 21: return "TVM_SORTCHILDRENCB"; | |
4750 | case 0x1100 + 22: return "TVM_ENDEDITLABELNOW"; | |
4751 | case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA"; | |
4752 | case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW"; | |
4753 | case 0x1100 + 24: return "TVM_SETTOOLTIPS"; | |
4754 | case 0x1100 + 25: return "TVM_GETTOOLTIPS"; | |
c085e333 | 4755 | |
2d0a075d | 4756 | // header |
9b64e798 | 4757 | case 0x1200 + 0: return "HDM_GETITEMCOUNT"; |
42e69d6b VZ |
4758 | case 0x1200 + 1: return "HDM_INSERTITEMA"; |
4759 | case 0x1200 + 10: return "HDM_INSERTITEMW"; | |
4760 | case 0x1200 + 2: return "HDM_DELETEITEM"; | |
4761 | case 0x1200 + 3: return "HDM_GETITEMA"; | |
4762 | case 0x1200 + 11: return "HDM_GETITEMW"; | |
4763 | case 0x1200 + 4: return "HDM_SETITEMA"; | |
4764 | case 0x1200 + 12: return "HDM_SETITEMW"; | |
9b64e798 VZ |
4765 | case 0x1200 + 5: return "HDM_LAYOUT"; |
4766 | case 0x1200 + 6: return "HDM_HITTEST"; | |
4767 | case 0x1200 + 7: return "HDM_GETITEMRECT"; | |
4768 | case 0x1200 + 8: return "HDM_SETIMAGELIST"; | |
4769 | case 0x1200 + 9: return "HDM_GETIMAGELIST"; | |
42e69d6b VZ |
4770 | case 0x1200 + 15: return "HDM_ORDERTOINDEX"; |
4771 | case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE"; | |
4772 | case 0x1200 + 17: return "HDM_GETORDERARRAY"; | |
4773 | case 0x1200 + 18: return "HDM_SETORDERARRAY"; | |
4774 | case 0x1200 + 19: return "HDM_SETHOTDIVIDER"; | |
c085e333 | 4775 | |
2d0a075d | 4776 | // tab control |
9b64e798 VZ |
4777 | case 0x1300 + 2: return "TCM_GETIMAGELIST"; |
4778 | case 0x1300 + 3: return "TCM_SETIMAGELIST"; | |
4779 | case 0x1300 + 4: return "TCM_GETITEMCOUNT"; | |
42e69d6b VZ |
4780 | case 0x1300 + 5: return "TCM_GETITEMA"; |
4781 | case 0x1300 + 60: return "TCM_GETITEMW"; | |
4782 | case 0x1300 + 6: return "TCM_SETITEMA"; | |
4783 | case 0x1300 + 61: return "TCM_SETITEMW"; | |
4784 | case 0x1300 + 7: return "TCM_INSERTITEMA"; | |
4785 | case 0x1300 + 62: return "TCM_INSERTITEMW"; | |
4786 | case 0x1300 + 8: return "TCM_DELETEITEM"; | |
4787 | case 0x1300 + 9: return "TCM_DELETEALLITEMS"; | |
9b64e798 | 4788 | case 0x1300 + 10: return "TCM_GETITEMRECT"; |
42e69d6b VZ |
4789 | case 0x1300 + 11: return "TCM_GETCURSEL"; |
4790 | case 0x1300 + 12: return "TCM_SETCURSEL"; | |
9b64e798 | 4791 | case 0x1300 + 13: return "TCM_HITTEST"; |
42e69d6b | 4792 | case 0x1300 + 14: return "TCM_SETITEMEXTRA"; |
9b64e798 | 4793 | case 0x1300 + 40: return "TCM_ADJUSTRECT"; |
42e69d6b VZ |
4794 | case 0x1300 + 41: return "TCM_SETITEMSIZE"; |
4795 | case 0x1300 + 42: return "TCM_REMOVEIMAGE"; | |
4796 | case 0x1300 + 43: return "TCM_SETPADDING"; | |
9b64e798 | 4797 | case 0x1300 + 44: return "TCM_GETROWCOUNT"; |
42e69d6b VZ |
4798 | case 0x1300 + 45: return "TCM_GETTOOLTIPS"; |
4799 | case 0x1300 + 46: return "TCM_SETTOOLTIPS"; | |
4800 | case 0x1300 + 47: return "TCM_GETCURFOCUS"; | |
4801 | case 0x1300 + 48: return "TCM_SETCURFOCUS"; | |
4802 | case 0x1300 + 49: return "TCM_SETMINTABWIDTH"; | |
4803 | case 0x1300 + 50: return "TCM_DESELECTALL"; | |
c085e333 | 4804 | |
2d0a075d | 4805 | // toolbar |
42e69d6b VZ |
4806 | case WM_USER+1: return "TB_ENABLEBUTTON"; |
4807 | case WM_USER+2: return "TB_CHECKBUTTON"; | |
4808 | case WM_USER+3: return "TB_PRESSBUTTON"; | |
4809 | case WM_USER+4: return "TB_HIDEBUTTON"; | |
4810 | case WM_USER+5: return "TB_INDETERMINATE"; | |
4811 | case WM_USER+9: return "TB_ISBUTTONENABLED"; | |
4812 | case WM_USER+10: return "TB_ISBUTTONCHECKED"; | |
4813 | case WM_USER+11: return "TB_ISBUTTONPRESSED"; | |
4814 | case WM_USER+12: return "TB_ISBUTTONHIDDEN"; | |
4815 | case WM_USER+13: return "TB_ISBUTTONINDETERMINATE"; | |
4816 | case WM_USER+17: return "TB_SETSTATE"; | |
4817 | case WM_USER+18: return "TB_GETSTATE"; | |
4818 | case WM_USER+19: return "TB_ADDBITMAP"; | |
4819 | case WM_USER+20: return "TB_ADDBUTTONS"; | |
4820 | case WM_USER+21: return "TB_INSERTBUTTON"; | |
4821 | case WM_USER+22: return "TB_DELETEBUTTON"; | |
4822 | case WM_USER+23: return "TB_GETBUTTON"; | |
9b64e798 | 4823 | case WM_USER+24: return "TB_BUTTONCOUNT"; |
42e69d6b VZ |
4824 | case WM_USER+25: return "TB_COMMANDTOINDEX"; |
4825 | case WM_USER+26: return "TB_SAVERESTOREA"; | |
4826 | case WM_USER+76: return "TB_SAVERESTOREW"; | |
4827 | case WM_USER+27: return "TB_CUSTOMIZE"; | |
4828 | case WM_USER+28: return "TB_ADDSTRINGA"; | |
4829 | case WM_USER+77: return "TB_ADDSTRINGW"; | |
9b64e798 | 4830 | case WM_USER+29: return "TB_GETITEMRECT"; |
42e69d6b VZ |
4831 | case WM_USER+30: return "TB_BUTTONSTRUCTSIZE"; |
4832 | case WM_USER+31: return "TB_SETBUTTONSIZE"; | |
4833 | case WM_USER+32: return "TB_SETBITMAPSIZE"; | |
4834 | case WM_USER+33: return "TB_AUTOSIZE"; | |
4835 | case WM_USER+35: return "TB_GETTOOLTIPS"; | |
4836 | case WM_USER+36: return "TB_SETTOOLTIPS"; | |
9b64e798 | 4837 | case WM_USER+37: return "TB_SETPARENT"; |
42e69d6b VZ |
4838 | case WM_USER+39: return "TB_SETROWS"; |
4839 | case WM_USER+40: return "TB_GETROWS"; | |
4840 | case WM_USER+42: return "TB_SETCMDID"; | |
4841 | case WM_USER+43: return "TB_CHANGEBITMAP"; | |
4842 | case WM_USER+44: return "TB_GETBITMAP"; | |
4843 | case WM_USER+45: return "TB_GETBUTTONTEXTA"; | |
4844 | case WM_USER+75: return "TB_GETBUTTONTEXTW"; | |
4845 | case WM_USER+46: return "TB_REPLACEBITMAP"; | |
9b64e798 VZ |
4846 | case WM_USER+47: return "TB_SETINDENT"; |
4847 | case WM_USER+48: return "TB_SETIMAGELIST"; | |
4848 | case WM_USER+49: return "TB_GETIMAGELIST"; | |
42e69d6b | 4849 | case WM_USER+50: return "TB_LOADIMAGES"; |
9b64e798 VZ |
4850 | case WM_USER+51: return "TB_GETRECT"; |
4851 | case WM_USER+52: return "TB_SETHOTIMAGELIST"; | |
4852 | case WM_USER+53: return "TB_GETHOTIMAGELIST"; | |
4853 | case WM_USER+54: return "TB_SETDISABLEDIMAGELIST"; | |
4854 | case WM_USER+55: return "TB_GETDISABLEDIMAGELIST"; | |
42e69d6b VZ |
4855 | case WM_USER+56: return "TB_SETSTYLE"; |
4856 | case WM_USER+57: return "TB_GETSTYLE"; | |
4857 | case WM_USER+58: return "TB_GETBUTTONSIZE"; | |
4858 | case WM_USER+59: return "TB_SETBUTTONWIDTH"; | |
4859 | case WM_USER+60: return "TB_SETMAXTEXTROWS"; | |
4860 | case WM_USER+61: return "TB_GETTEXTROWS"; | |
4861 | case WM_USER+41: return "TB_GETBITMAPFLAGS"; | |
c085e333 | 4862 | |
a02eb1d2 | 4863 | #endif //WIN32 |
c085e333 | 4864 | |
42e69d6b VZ |
4865 | default: |
4866 | static char s_szBuf[128]; | |
4867 | sprintf(s_szBuf, "<unknown message = %d>", message); | |
4868 | return s_szBuf; | |
4869 | } | |
47cbd6da | 4870 | } |
ea57084d | 4871 | #endif //__WXDEBUG__ |
4aff28fc | 4872 | |
1e6feb95 VZ |
4873 | static void TranslateKbdEventToMouse(wxWindowMSW *win, |
4874 | int *x, int *y, WPARAM *flags) | |
4aff28fc VZ |
4875 | { |
4876 | // construct the key mask | |
4877 | WPARAM& fwKeys = *flags; | |
4878 | ||
4879 | fwKeys = MK_RBUTTON; | |
3f7bc32b | 4880 | if ( wxIsCtrlDown() ) |
4aff28fc | 4881 | fwKeys |= MK_CONTROL; |
3f7bc32b | 4882 | if ( wxIsShiftDown() ) |
4aff28fc VZ |
4883 | fwKeys |= MK_SHIFT; |
4884 | ||
4885 | // simulate right mouse button click | |
4886 | DWORD dwPos = ::GetMessagePos(); | |
4887 | *x = GET_X_LPARAM(dwPos); | |
4888 | *y = GET_Y_LPARAM(dwPos); | |
4889 | ||
4890 | win->ScreenToClient(x, y); | |
4891 | } | |
f6bcfd97 | 4892 | |
1e6feb95 | 4893 | static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win) |
f6bcfd97 BP |
4894 | { |
4895 | // prepare the DC | |
4896 | TEXTMETRIC tm; | |
4897 | HWND hwnd = GetHwndOf(win); | |
4898 | HDC hdc = ::GetDC(hwnd); | |
4899 | ||
4900 | #if !wxDIALOG_UNIT_COMPATIBILITY | |
4901 | // and select the current font into it | |
4902 | HFONT hfont = GetHfontOf(win->GetFont()); | |
4903 | if ( hfont ) | |
4904 | { | |
4905 | hfont = (HFONT)::SelectObject(hdc, hfont); | |
4906 | } | |
4907 | #endif | |
4908 | ||
4909 | // finally retrieve the text metrics from it | |
4910 | GetTextMetrics(hdc, &tm); | |
4911 | ||
4912 | #if !wxDIALOG_UNIT_COMPATIBILITY | |
4913 | // and clean up | |
4914 | if ( hfont ) | |
4915 | { | |
4916 | (void)::SelectObject(hdc, hfont); | |
4917 | } | |
4918 | #endif | |
4919 | ||
4920 | ::ReleaseDC(hwnd, hdc); | |
4921 | ||
4922 | return tm; | |
4923 | } | |
3723b7b1 JS |
4924 | |
4925 | // Find the wxWindow at the current mouse position, returning the mouse | |
4926 | // position. | |
33ac7e6f | 4927 | wxWindow* wxFindWindowAtPointer(wxPoint& WXUNUSED(pt)) |
3723b7b1 | 4928 | { |
57591e0e JS |
4929 | return wxFindWindowAtPoint(wxGetMousePosition()); |
4930 | } | |
4931 | ||
4932 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) | |
4933 | { | |
4934 | POINT pt2; | |
4935 | pt2.x = pt.x; | |
4936 | pt2.y = pt.y; | |
4937 | HWND hWndHit = ::WindowFromPoint(pt2); | |
3723b7b1 JS |
4938 | |
4939 | wxWindow* win = wxFindWinFromHandle((WXHWND) hWndHit) ; | |
4940 | HWND hWnd = hWndHit; | |
4941 | ||
4942 | // Try to find a window with a wxWindow associated with it | |
4943 | while (!win && (hWnd != 0)) | |
4944 | { | |
4945 | hWnd = ::GetParent(hWnd); | |
4946 | win = wxFindWinFromHandle((WXHWND) hWnd) ; | |
4947 | } | |
4948 | return win; | |
4949 | } | |
4950 | ||
4951 | // Get the current mouse position. | |
4952 | wxPoint wxGetMousePosition() | |
4953 | { | |
1772ead0 JS |
4954 | POINT pt; |
4955 | GetCursorPos( & pt ); | |
4956 | return wxPoint(pt.x, pt.y); | |
3723b7b1 JS |
4957 | } |
4958 |