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