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