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