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