X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f57f984cc043142c8fe066def99f327ff10d013f..9f93b45e59e93e17850bbc37a8960240072bc1c0:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 8aa92e8e2f..3be9dd4b12 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -28,7 +28,6 @@ #include "wx/msw/wrapwin.h" #include "wx/window.h" #include "wx/accel.h" - #include "wx/setup.h" #include "wx/menu.h" #include "wx/dc.h" #include "wx/dcclient.h" @@ -111,6 +110,12 @@ #if defined(__WXWINCE__) #include "wx/msw/wince/missing.h" +#ifdef __POCKETPC__ + #include + #include + #include + #include +#endif #endif #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) @@ -121,7 +126,11 @@ // resizing complicated window hierarchies, but this can in theory result in // different behaviour than the old code so we keep the possibility to use it // by setting this to 0 (in the future this should be removed completely) +#ifdef __WXWINCE__ +#define USE_DEFERRED_SIZING 0 +#else #define USE_DEFERRED_SIZING 1 +#endif // set this to 1 to filter out duplicate mouse events, e.g. mouse move events // when mouse position didnd't change @@ -484,6 +493,10 @@ void wxWindowMSW::Init() m_pendingPosition = wxDefaultPosition; m_pendingSize = wxDefaultSize; + +#ifdef __POCKETPC__ + m_contextMenuEnabled = false; +#endif } // Destructor @@ -785,22 +798,10 @@ bool wxWindowMSW::SetCursor(const wxCursor& cursor) return false; } - if ( m_cursor.Ok() ) + // don't "overwrite" busy cursor + if ( m_cursor.Ok() && !wxIsBusy() ) { - HWND hWnd = GetHwnd(); - - // Change the cursor NOW if we're within the correct window - POINT point; -#ifdef __WXWINCE__ - ::GetCursorPosWinCE(&point); -#else - ::GetCursorPos(&point); -#endif - - RECT rect = wxGetWindowRect(hWnd); - - if ( ::PtInRect(&rect, point) && !wxIsBusy() ) - ::SetCursor(GetHcursorOf(m_cursor)); + ::SetCursor(GetHcursorOf(m_cursor)); } return true; @@ -941,7 +942,7 @@ void wxWindowMSW::SetScrollbar(int orient, // We have to set the variables here to make them valid in events // triggered by ::SetScrollInfo() *(orient == wxHORIZONTAL ? &m_xThumbSize : &m_yThumbSize) = pageSize; - + ::SetScrollInfo(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT, &info, refresh); } @@ -1090,13 +1091,13 @@ void wxWindowMSW::DissociateHandle() bool wxCheckWindowWndProc(WXHWND hWnd, - WXFARPROC WXUNUSED_IN_WINCE(wndProc)) + WXFARPROC WXUNUSED(wndProc)) { // TODO: This list of window class names should be factored out so they can be // managed in one place and then accessed from here and other places, such as // wxApp::RegisterWindowClasses() and wxApp::UnregisterWindowClasses() - -#ifdef __WXWINCE__ + +#ifdef __WXWINCE__ extern wxChar *wxCanvasClassName; extern wxChar *wxCanvasClassNameNR; #else @@ -1110,6 +1111,10 @@ bool wxCheckWindowWndProc(WXHWND hWnd, wxString str(wxGetWindowClass(hWnd)); if (str == wxCanvasClassName || str == wxCanvasClassNameNR || +#if wxUSE_GLCANVAS + str == _T("wxGLCanvasClass") || + str == _T("wxGLCanvasClassNR") || +#endif // wxUSE_GLCANVAS str == wxMDIFrameClassName || str == wxMDIFrameClassNameNoRedraw || str == wxMDIChildFrameClassName || @@ -1138,6 +1143,9 @@ void wxWindowMSW::SetWindowStyleFlag(long flags) if ( !GetHwnd() ) return; + // we may need to call SetWindowPos() when we change some styles + bool callSWP = false; + WXDWORD exstyle, exstyleOld; long style = MSWGetStyle(flags, &exstyle), styleOld = MSWGetStyle(flagsOld, &exstyleOld); @@ -1153,17 +1161,40 @@ void wxWindowMSW::SetWindowStyleFlag(long flags) styleReal |= style; ::SetWindowLong(GetHwnd(), GWL_STYLE, styleReal); + + // If any of the style changes changed any of the frame styles: + // MSDN: SetWindowLong: + // Certain window data is cached, so changes you make using + // SetWindowLong will not take effect until you call the + // SetWindowPos function. Specifically, if you change any of + // the frame styles, you must call SetWindowPos with the + // SWP_FRAMECHANGED flag for the cache to be updated properly. + + callSWP = ((styleOld ^ style ) & (WS_BORDER | + WS_THICKFRAME | + WS_CAPTION | + WS_DLGFRAME | + WS_MAXIMIZEBOX | + WS_MINIMIZEBOX | + WS_SYSMENU) ) != 0; } // and the extended style + long exstyleReal = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE); + if ( exstyle != exstyleOld ) { - long exstyleReal = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE); exstyleReal &= ~exstyleOld; exstyleReal |= exstyle; ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyleReal); + // ex style changes don't take effect without calling SetWindowPos + callSWP = true; + } + + if ( callSWP ) + { // we must call SetWindowPos() to flush the cached extended style and // also to make the change to wxSTAY_ON_TOP style take effect: just // setting the style simply doesn't work @@ -1171,7 +1202,7 @@ void wxWindowMSW::SetWindowStyleFlag(long flags) exstyleReal & WS_EX_TOPMOST ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE) ) + SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED) ) { wxLogLastError(_T("SetWindowPos")); } @@ -1352,7 +1383,7 @@ void wxWindowMSW::Thaw() { wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") ); - if ( !--m_frozenness ) + if ( --m_frozenness == 0 ) { if ( IsShown() ) { @@ -1417,6 +1448,26 @@ void wxWindowMSW::Update() // drag and drop // --------------------------------------------------------------------------- +// we need to lower the sibling static boxes so controls contained within can be +// a drop target +static inline void AdjustStaticBoxZOrder(wxWindow *parent) +{ + // no sibling static boxes if we have no parent (ie TLW) + if ( !parent ) + return; + + for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst(); + node; + node = node->GetNext() ) + { + wxStaticBox *statbox = wxDynamicCast(node->GetData(), wxStaticBox); + if ( statbox ) + { + ::SetWindowPos(GetHwndOf(statbox), HWND_BOTTOM, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + } + } +} #if wxUSE_DRAG_AND_DROP void wxWindowMSW::SetDropTarget(wxDropTarget *pDropTarget) @@ -1428,7 +1479,10 @@ void wxWindowMSW::SetDropTarget(wxDropTarget *pDropTarget) m_dropTarget = pDropTarget; if ( m_dropTarget != 0 ) + { + AdjustStaticBoxZOrder(GetParent()); m_dropTarget->Register(m_hWnd); + } } #endif // wxUSE_DRAG_AND_DROP @@ -1439,7 +1493,10 @@ void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept)) #ifndef __WXWINCE__ HWND hWnd = GetHwnd(); if ( hWnd ) + { + AdjustStaticBoxZOrder(GetParent()); ::DragAcceptFiles(hWnd, (BOOL)accept); + } #endif } @@ -1501,9 +1558,10 @@ void wxWindowMSW::DoGetSize(int *x, int *y) const // Get size *available for subwindows* i.e. excluding menu bar etc. void wxWindowMSW::DoGetClientSize(int *x, int *y) const { +#if USE_DEFERRED_SIZING if ( IsTopLevel() || m_pendingSize == wxDefaultSize ) - { - // top level windows resizing is never deferred, so we can safely use +#endif + { // top level windows resizing is never deferred, so we can safely use // the current size here RECT rect = wxGetClientRect(GetHwnd()); @@ -1512,13 +1570,24 @@ void wxWindowMSW::DoGetClientSize(int *x, int *y) const if ( y ) *y = rect.bottom; } - else // non top level +#if USE_DEFERRED_SIZING + else // non top level and using deferred sizing { - // size is the same as client size for non top level windows, so - // forward to GetSize() to take into account deferred sizing (which - // wxGetClientRect() doesn't) - DoGetSize(x, y); + // we need to calculate the *pending* client size here + RECT rect; + rect.left = m_pendingPosition.x; + rect.top = m_pendingPosition.y; + rect.right = rect.left + m_pendingSize.x; + rect.bottom = rect.top + m_pendingSize.y; + + ::SendMessage(GetHwnd(), WM_NCCALCSIZE, FALSE, (LPARAM)&rect); + + if ( x ) + *x = rect.right - rect.left; + if ( y ) + *y = rect.bottom - rect.top; } +#endif } void wxWindowMSW::DoGetPosition(int *x, int *y) const @@ -1902,7 +1971,7 @@ bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y) #if defined(__WXWINCE__) UINT flags = 0; #else - UINT flags = TPM_RIGHTBUTTON; + UINT flags = TPM_RIGHTBUTTON | TPM_RECURSE; #endif ::TrackPopupMenu(hMenu, flags, point.x, point.y, 0, hWnd, NULL); @@ -2537,6 +2606,36 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l wxCHECK_MSG( win, 0, _T("FindWindowForMouseEvent() returned NULL") ); } +#ifdef __POCKETPC__ + if (IsContextMenuEnabled() && message == WM_LBUTTONDOWN) + { + SHRGINFO shrgi = {0}; + + shrgi.cbSize = sizeof(SHRGINFO); + shrgi.hwndClient = (HWND) GetHWND(); + shrgi.ptDown.x = x; + shrgi.ptDown.y = y; + + shrgi.dwFlags = SHRG_RETURNCMD; + // shrgi.dwFlags = SHRG_NOTIFYPARENT; + + if (GN_CONTEXTMENU == ::SHRecognizeGesture(&shrgi)) + { + wxPoint pt(x, y); + pt = ClientToScreen(pt); + + wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt); + + evtCtx.SetEventObject(this); + if (GetEventHandler()->ProcessEvent(evtCtx)) + { + processed = true; + return true; + } + } + } +#endif + #else // !__WXWINCE__ wxWindowMSW *win = this; #endif // __WXWINCE__/!__WXWINCE__ @@ -2804,6 +2903,10 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l processed = HandleCaptureChanged((WXHWND) (HWND) lParam); break; + case WM_SETTINGCHANGE: + processed = HandleSettingChange(wParam, lParam); + break; + case WM_QUERYNEWPALETTE: processed = HandleQueryNewPalette(); break; @@ -3888,6 +3991,30 @@ bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture) return GetEventHandler()->ProcessEvent(event); } +bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam) +{ + // despite MSDN saying "(This message cannot be sent directly to a window.)" + // we need to send this to child windows (it is only sent to top-level + // windows) so {list,tree}ctrls can adjust their font size if necessary + // this is exactly how explorer does it to enable the font size changes + + wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); + while ( node ) + { + // top-level windows already get this message from the system + wxWindow *win = node->GetData(); + if ( !win->IsTopLevel() ) + { + ::SendMessage(GetHwndOf(win), WM_SETTINGCHANGE, wParam, lParam); + } + + node = node->GetNext(); + } + + // let the system handle it + return false; +} + bool wxWindowMSW::HandleQueryNewPalette() { @@ -4064,14 +4191,11 @@ bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc) dc.SetHDC(hdc); dc.SetWindow((wxWindow *)this); - dc.BeginDrawing(); wxEraseEvent event(m_windowId, &dc); event.SetEventObject(this); bool rc = GetEventHandler()->ProcessEvent(event); - dc.EndDrawing(); - // must be called manually as ~wxDC doesn't do anything for wxDCTemp dc.SelectOldObjects(hdc); @@ -5160,9 +5284,14 @@ void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font) // use the "extended" bit (24) of lParam to distinguish extended keys // from normal keys as the same key is sent -static inline int ChooseNormalOrExtended(int lParam, int keyNormal, int keyExtended) +static inline +int ChooseNormalOrExtended(int lParam, int keyNormal, int keyExtended) { - return lParam & (1 << 24) ? keyExtended : keyNormal; + // except that if lParam is 0, it means we don't have real lParam from + // WM_KEYDOWN but are just translating just a VK constant (e.g. done from + // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a + // non-numpad (hence extended) key as this is a more common case + return !lParam || (lParam & (1 << 24)) ? keyExtended : keyNormal; } // Returns 0 if was a normal ASCII value, not a special key. This indicates that @@ -5251,10 +5380,10 @@ int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam) // handle extended keys case VK_PRIOR: - id = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PRIOR, WXK_PRIOR); + id = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEUP, WXK_PAGEUP); break; case VK_NEXT: - id = ChooseNormalOrExtended(lParam, WXK_NUMPAD_NEXT, WXK_NEXT); + id = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEDOWN, WXK_PAGEDOWN); break; case VK_END: id = ChooseNormalOrExtended(lParam, WXK_NUMPAD_END, WXK_END); @@ -5280,9 +5409,10 @@ int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam) case VK_DELETE: id = ChooseNormalOrExtended(lParam, WXK_NUMPAD_DELETE, WXK_DELETE); break; - // this order is correct as the numpad enter is the extended key case VK_RETURN: - id = ChooseNormalOrExtended(lParam, WXK_RETURN, WXK_NUMPAD_ENTER); + // don't use ChooseNormalOrExtended() here as the keys are reversed + // here: numpad enter is the extended one + id = lParam && (lParam & (1 << 24)) ? WXK_NUMPAD_ENTER : WXK_RETURN; break; default: @@ -5305,8 +5435,8 @@ WXWORD wxCharCodeWXToMSW(int id, bool *isVirtual) case WXK_ALT: keySym = VK_MENU; break; case WXK_PAUSE: keySym = VK_PAUSE; break; case WXK_CAPITAL: keySym = VK_CAPITAL; break; - case WXK_PRIOR: keySym = VK_PRIOR; break; - case WXK_NEXT : keySym = VK_NEXT; break; + case WXK_PAGEUP: keySym = VK_PRIOR; break; + case WXK_PAGEDOWN: keySym = VK_NEXT; break; case WXK_END: keySym = VK_END; break; case WXK_HOME : keySym = VK_HOME; break; case WXK_LEFT : keySym = VK_LEFT; break;