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