X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da78f3b10cfe9447053f32ea4baddf50058eafef..172df1f0351019adaada76e16847b3ca6c2421eb:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index df2d1b269e..554b6e4e26 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -54,6 +54,7 @@ #include "wx/ownerdrw.h" #endif +#include "wx/evtloop.h" #include "wx/module.h" #include "wx/sysopt.h" @@ -120,8 +121,11 @@ #define HAVE_TRACKMOUSEEVENT #endif // everything needed for TrackMouseEvent() +// if this is set to 1, we use deferred window sizing to reduce flicker when +// 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) #define USE_DEFERRED_SIZING 1 -#define USE_DEFER_BUG_WORKAROUND 1 // --------------------------------------------------------------------------- // global variables @@ -231,28 +235,6 @@ bool GetCursorPosWinCE(POINT* pt) } #endif -// --------------------------------------------------------------------------- -// wxWindowExtraData -// --------------------------------------------------------------------------- - -#if USE_DEFER_BUG_WORKAROUND -// This class is used to hold additional data memebers that were added after -// the stable 2.6.0 release. They should be moved into wxWindow for 2.7 after -// binary compatibility is no longer being maintained. - -class wxWindowExtraData { -public: - wxWindowExtraData() - : m_pendingPosition(wxDefaultPosition), - m_pendingSize(wxDefaultSize) - {} - - wxPoint m_pendingPosition; - wxSize m_pendingSize; -}; - -#endif - // --------------------------------------------------------------------------- // event tables // --------------------------------------------------------------------------- @@ -488,9 +470,8 @@ void wxWindowMSW::Init() m_lastMouseEvent = -1; #endif // wxUSE_MOUSEEVENT_HACK -#if USE_DEFER_BUG_WORKAROUND - m_extraData = new wxWindowExtraData; -#endif + m_pendingPosition = wxDefaultPosition; + m_pendingSize = wxDefaultSize; } // Destructor @@ -539,9 +520,6 @@ wxWindowMSW::~wxWindowMSW() delete m_childrenDisabled; -#if USE_DEFER_BUG_WORKAROUND - delete m_extraData; -#endif } // real construction (Init() must have been called before!) @@ -846,7 +824,7 @@ inline int GetScrollPosition(HWND hWnd, int wOrient) wOrient, &scrollInfo) ) { - // Not neccessarily an error, if there are no scrollbars yet. + // Not necessarily an error, if there are no scrollbars yet. // wxLogLastError(_T("GetScrollInfo")); } return scrollInfo.nPos; @@ -1086,7 +1064,8 @@ void wxWindowMSW::DissociateHandle() } -bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc) +bool wxCheckWindowWndProc(WXHWND hWnd, + WXFARPROC WXUNUSED_IN_WINCE(wndProc)) { // Unicows note: the code below works, but only because WNDCLASS contains // original window handler rather that the unicows fake one. This may not @@ -1098,8 +1077,6 @@ bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc) // On WinCE (at least), the wndproc comparison doesn't work, // so have to use something like this. #ifdef __WXWINCE__ - wxUnusedVar(wndProc); - extern wxChar *wxCanvasClassName; extern wxChar *wxCanvasClassNameNR; extern const wxChar *wxMDIFrameClassName; @@ -1396,7 +1373,8 @@ void wxWindowMSW::Refresh(bool eraseBack, const wxRect *rect) pRect = NULL; } -#ifndef __SMARTPHONE__ + // RedrawWindow not available on SmartPhone or eVC++ 3 +#if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400) UINT flags = RDW_INVALIDATE | RDW_ALLCHILDREN; if ( eraseBack ) flags |= RDW_ERASE; @@ -1443,14 +1421,12 @@ void wxWindowMSW::SetDropTarget(wxDropTarget *pDropTarget) // old style file-manager drag&drop support: we retain the old-style // DragAcceptFiles in parallel with SetDropTarget. -void wxWindowMSW::DragAcceptFiles(bool accept) +void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept)) { -#if !defined(__WXWINCE__) +#ifndef __WXWINCE__ HWND hWnd = GetHwnd(); if ( hWnd ) ::DragAcceptFiles(hWnd, (BOOL)accept); -#else - wxUnusedVar(accept); #endif } @@ -1477,17 +1453,32 @@ void wxWindowMSW::DoSetToolTip(wxToolTip *tooltip) // Get total size void wxWindowMSW::DoGetSize(int *x, int *y) const { - RECT rect = wxGetWindowRect(GetHwnd()); + // if SetSize() had been called at wx level but not realized at Windows + // level yet (i.e. EndDeferWindowPos() not called), we still should return + // the new and not the old position to the other wx code + if ( m_pendingSize != wxDefaultSize ) + { + if ( x ) + *x = m_pendingSize.x; + if ( y ) + *y = m_pendingSize.y; + } + else // use current size + { + RECT rect = wxGetWindowRect(GetHwnd()); - if ( x ) - *x = rect.right - rect.left; - if ( y ) - *y = rect.bottom - rect.top; + if ( x ) + *x = rect.right - rect.left; + if ( y ) + *y = rect.bottom - rect.top; + } } // Get size *available for subwindows* i.e. excluding menu bar etc. void wxWindowMSW::DoGetClientSize(int *x, int *y) const { + // this is only for top level windows whose resizing is never deferred, so + // we can safely use the current size here RECT rect = wxGetClientRect(GetHwnd()); if ( x ) @@ -1498,42 +1489,50 @@ void wxWindowMSW::DoGetClientSize(int *x, int *y) const void wxWindowMSW::DoGetPosition(int *x, int *y) const { - RECT rect = wxGetWindowRect(GetHwnd()); + wxWindow * const parent = GetParent(); - POINT point; - point.x = rect.left; - point.y = rect.top; - - // we do the adjustments with respect to the parent only for the "real" - // children, not for the dialogs/frames - if ( !IsTopLevel() ) + wxPoint pos; + if ( m_pendingPosition != wxDefaultPosition ) + { + pos = m_pendingPosition; + } + else // use current position { - HWND hParentWnd = 0; - wxWindow *parent = GetParent(); - if ( parent ) - hParentWnd = GetWinHwnd(parent); + RECT rect = wxGetWindowRect(GetHwnd()); - // Since we now have the absolute screen coords, if there's a parent we - // must subtract its top left corner - if ( hParentWnd ) - { - ::ScreenToClient(hParentWnd, &point); - } + POINT point; + point.x = rect.left; + point.y = rect.top; - if ( parent ) + // we do the adjustments with respect to the parent only for the "real" + // children, not for the dialogs/frames + if ( !IsTopLevel() ) { - // We may be faking the client origin. So a window that's really at (0, - // 30) may appear (to wxWin apps) to be at (0, 0). - wxPoint pt(parent->GetClientAreaOrigin()); - point.x -= pt.x; - point.y -= pt.y; + // Since we now have the absolute screen coords, if there's a + // parent we must subtract its top left corner + if ( parent ) + { + ::ScreenToClient(GetHwndOf(parent), &point); + } } + + pos.x = point.x; + pos.y = point.y; + } + + // we also must adjust by the client area offset: a control which is just + // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx + if ( parent && !IsTopLevel() ) + { + const wxPoint pt(parent->GetClientAreaOrigin()); + pos.x -= pt.x; + pos.y -= pt.y; } if ( x ) - *x = point.x; + *x = pos.x; if ( y ) - *y = point.y; + *y = pos.y; } void wxWindowMSW::DoScreenToClient(int *x, int *y) const @@ -1568,6 +1567,42 @@ void wxWindowMSW::DoClientToScreen(int *x, int *y) const *y = pt.y; } +void +wxWindowMSW::DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height) +{ +#if USE_DEFERRED_SIZING + // if our parent had prepared a defer window handle for us, use it (unless + // we are a top level window) + wxWindowMSW * const parent = IsTopLevel() ? NULL : GetParent(); + + HDWP hdwp = parent ? (HDWP)parent->m_hDWP : NULL; + if ( hdwp ) + { + hdwp = ::DeferWindowPos(hdwp, (HWND)hwnd, NULL, x, y, width, height, + SWP_NOZORDER); + if ( !hdwp ) + { + wxLogLastError(_T("DeferWindowPos")); + } + } + + if ( parent ) + { + // hdwp must be updated as it may have been changed + parent->m_hDWP = (WXHANDLE)hdwp; + } + + // otherwise (or if deferring failed) move the window in place immediately + if ( !hdwp ) +#endif // USE_DEFERRED_SIZING + { + if ( !::MoveWindow((HWND)hwnd, x, y, width, height, IsShown()) ) + { + wxLogLastError(wxT("MoveWindow")); + } + } +} + void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height) { // TODO: is this consistent with other platforms? @@ -1577,23 +1612,7 @@ void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height) if (height < 0) height = 0; - // if our parent had prepared a defer window handle for us, use it (unless - // we are a top level window) - wxWindowMSW *parent = GetParent(); - -#if USE_DEFERRED_SIZING - HDWP hdwp = parent && !IsTopLevel() ? (HDWP)parent->m_hDWP : NULL; -#else - HDWP hdwp = 0; -#endif - - wxMoveWindowDeferred(hdwp, this, GetHwnd(), x, y, width, height); - -#if USE_DEFERRED_SIZING - if ( parent ) - // hdwp must be updated as it may have been changed - parent->m_hDWP = (WXHANDLE)hdwp; -#endif + DoMoveSibling(m_hWnd, x, y, width, height); } // set the size of the window: if the dimensions are positive, just use them, @@ -1610,26 +1629,8 @@ void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) int currentX, currentY; int currentW, currentH; -#if USE_DEFER_BUG_WORKAROUND - currentX = m_extraData->m_pendingPosition.x; - if (currentX == wxDefaultCoord) - GetPosition(¤tX, NULL); - - currentY = m_extraData->m_pendingPosition.y; - if (currentY == wxDefaultCoord) - GetPosition(NULL, ¤tY); - - currentW = m_extraData->m_pendingSize.x; - if (currentW == wxDefaultCoord) - GetSize(¤tW, NULL); - - currentH = m_extraData->m_pendingSize.y; - if (currentH == wxDefaultCoord) - GetSize(NULL, ¤tH); -#else GetPosition(¤tX, ¤tY); GetSize(¤tW, ¤tH); -#endif // ... and don't do anything (avoiding flicker) if it's already ok if ( x == currentX && y == currentY && @@ -1679,24 +1680,8 @@ void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) } } -#if USE_DEFER_BUG_WORKAROUND - // We don't actually use the hdwp here, but we need to know whether to - // save the pending dimensions or not. This isn't done in DoMoveWindow - // (where the hdwp is used) because some controls have thier own - // DoMoveWindow so it is easier to catch it here. - HDWP hdwp = GetParent() && !IsTopLevel() ? (HDWP)GetParent()->m_hDWP : NULL; - if (hdwp) - { - m_extraData->m_pendingPosition = wxPoint(x, y); - m_extraData->m_pendingSize = wxSize(width, height); - } - else - { - m_extraData->m_pendingPosition = wxDefaultPosition; - m_extraData->m_pendingSize = wxDefaultSize; - } -#endif - + m_pendingPosition = wxPoint(x, y); + m_pendingSize = wxSize(width, height); DoMoveWindow(x, y, width, height); } @@ -1719,28 +1704,21 @@ void wxWindowMSW::DoSetClientSize(int width, int height) RECT rectClient; ::GetClientRect(GetHwnd(), &rectClient); - // if the size is already ok, stop here (rectClient.left = top = 0) + // if the size is already ok, stop here (NB: rectClient.left = top = 0) if ( (rectClient.right == width || width == wxDefaultCoord) && (rectClient.bottom == height || height == wxDefaultCoord) ) { break; } - int widthClient = width, - heightClient = height; - // Find the difference between the entire window (title bar and all) // and the client area; add this to the new client size to move the // window RECT rectWin; ::GetWindowRect(GetHwnd(), &rectWin); - widthClient += rectWin.right - rectWin.left - rectClient.right; - heightClient += rectWin.bottom - rectWin.top - rectClient.bottom; - - POINT point; - point.x = rectWin.left; - point.y = rectWin.top; + const int widthWin = rectWin.right - rectWin.left, + heightWin = rectWin.bottom - rectWin.top; // MoveWindow positions the child windows relative to the parent, so // adjust if necessary @@ -1749,11 +1727,21 @@ void wxWindowMSW::DoSetClientSize(int width, int height) wxWindow *parent = GetParent(); if ( parent ) { - ::ScreenToClient(GetHwndOf(parent), &point); + ::ScreenToClient(GetHwndOf(parent), (POINT *)&rectWin); } } - DoMoveWindow(point.x, point.y, widthClient, heightClient); + // don't call DoMoveWindow() because we want to move window immediately + // and not defer it here + if ( !::MoveWindow(GetHwnd(), + rectWin.left, + rectWin.top, + width + widthWin - rectClient.right, + height + heightWin - rectClient.bottom, + TRUE) ) + { + wxLogLastError(_T("MoveWindow")); + } } } @@ -1796,7 +1784,7 @@ void wxWindowMSW::GetTextExtent(const wxString& string, SIZE sizeRect; TEXTMETRIC tm; - GetTextExtentPoint(hdc, string, string.length(), &sizeRect); + ::GetTextExtentPoint32(hdc, string, string.length(), &sizeRect); GetTextMetrics(hdc, &tm); if ( x ) @@ -1964,38 +1952,6 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg) bProcess = false; break; - case VK_ESCAPE: - { -#if wxUSE_BUTTON - wxButton *btn = wxDynamicCast(FindWindow(wxID_CANCEL),wxButton); - - // our own wxLogDialog should react to Esc - // without Cancel button but this is a private class - // so let's try recognize it by content - #if wxUSE_LOG_DIALOG - if ( !btn && - wxDynamicCast(this,wxDialog) && - FindWindow(wxID_MORE) && - FindWindow(wxID_OK) && - !FindWindow(wxID_CANCEL) && - GetTitle().MakeLower().StartsWith(wxTheApp->GetAppName().c_str()) - ) - btn = wxDynamicCast(FindWindow(wxID_OK),wxButton); - #endif // wxUSE_LOG_DIALOG - if ( btn && btn->IsEnabled() ) - { - // if we do have a cancel button, do press it - btn->MSWCommand(BN_CLICKED, 0 /* unused */); - - // we consumed the message - return true; - } -#endif // wxUSE_BUTTON - - bProcess = false; - } - break; - case VK_RETURN: { if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown ) @@ -2285,7 +2241,7 @@ LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM w LRESULT rc; - if ( wnd ) + if ( wnd && wxEventLoop::AllowProcessing(wnd) ) rc = wnd->MSWWindowProc(message, wParam, lParam); else rc = ::DefWindowProc(hWnd, message, wParam, lParam); @@ -2377,6 +2333,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l break; #endif // !__WXWINCE__ +#if !(defined(_WIN32_WCE) && _WIN32_WCE < 400) case WM_WINDOWPOSCHANGED: { WINDOWPOS *lpPos = (WINDOWPOS *)lParam; @@ -2389,19 +2346,15 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l AutoHRGN hrgnClient(::CreateRectRgnIndirect(&rc)); AutoHRGN hrgnNew(::CreateRectRgn(lpPos->x, lpPos->y, lpPos->cx, lpPos->cy)); - AutoHRGN hrgn(::CreateRectRgn(0, 0, 0, 0)); // we need to invalidate any new exposed areas here // to force them to repaint - if ( ::CombineRgn(hrgn, hrgnNew, hrgnClient, RGN_DIFF) != NULLREGION ) - ::InvalidateRgn(GetHwnd(), hrgn, TRUE); - if ( ::CombineRgn(hrgn, hrgnClient, hrgnNew, RGN_DIFF) != NULLREGION ) - ::InvalidateRgn(GetHwnd(), hrgn, TRUE); - + if ( ::CombineRgn(hrgnNew, hrgnNew, hrgnClient, RGN_DIFF) != NULLREGION ) + ::InvalidateRgn(GetHwnd(), hrgnNew, TRUE); } } break; - +#endif #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) case WM_ACTIVATEAPP: // This implicitly sends a wxEVT_ACTIVATE_APP event @@ -3382,7 +3335,8 @@ bool wxWindowMSW::HandleEndSession(bool endSession, long logOff) // window creation/destruction // --------------------------------------------------------------------------- -bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate) +bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT WXUNUSED_IN_WINCE(cs), + bool *mayCreate) { // VZ: why is this commented out for WinCE? If it doesn't support // WS_EX_CONTROLPARENT at all it should be somehow handled globally, @@ -3390,8 +3344,6 @@ bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate) #ifndef __WXWINCE__ if ( ((CREATESTRUCT *)cs)->dwExStyle & WS_EX_CONTROLPARENT ) EnsureParentHasControlParentStyle(GetParent()); -#else - wxUnusedVar(cs); #endif // !__WXWINCE__ // TODO: should generate this event from WM_NCCREATE @@ -3957,6 +3909,7 @@ extern wxCOLORMAP *wxGetStdColourMap() // we want to avoid Windows' "help" and for this we need to have a // reference bitmap which can tell us what the RGB values change // to. + wxLogNull logNo; // suppress error if we couldn't load the bitmap wxBitmap stdColourBitmap(_T("wxBITMAP_STD_COLOURS")); if ( stdColourBitmap.Ok() ) { @@ -4169,6 +4122,15 @@ bool wxWindowMSW::HandlePrintClient(WXHDC hDC) // // also note that in this case lParam == PRF_CLIENT but we're // clearly expected to paint the background and nothing else! + + if ( IsTopLevel() || InheritsBackgroundColour() ) + return false; + + // sometimes we don't want the parent to handle it at all, instead + // return whatever value this window wants + if ( !MSWShouldPropagatePrintChild() ) + return MSWPrintChild(hDC, (wxWindow *)this); + for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) { if ( win->MSWPrintChild(hDC, (wxWindow *)this) ) @@ -4300,19 +4262,17 @@ bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam) wxLogLastError(_T("EndDeferWindowPos")); } -#if USE_DEFER_BUG_WORKAROUND // Reset our children's pending pos/size values. for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext() ) { - wxWindow *child = node->GetData(); - child->m_extraData->m_pendingPosition = wxDefaultPosition; - child->m_extraData->m_pendingSize = wxDefaultSize; + wxWindowMSW *child = node->GetData(); + child->m_pendingPosition = wxDefaultPosition; + child->m_pendingSize = wxDefaultSize; } -#endif } -#endif +#endif // USE_DEFERRED_SIZING return processed; } @@ -4328,10 +4288,9 @@ bool wxWindowMSW::HandleSizing(wxRect& rect) return rc; } -bool wxWindowMSW::HandleGetMinMaxInfo(void *mmInfo) +bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo)) { #ifdef __WXWINCE__ - wxUnusedVar(mmInfo); return false; #else MINMAXINFO *info = (MINMAXINFO *)mmInfo; @@ -4625,11 +4584,14 @@ bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags) bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam) { #if wxUSE_MOUSEWHEEL + // notice that WM_MOUSEWHEEL position is in screen coords (as it's + // forwarded up to the parent by DefWindowProc()) and not in the client + // ones as all the other messages, translate them to the client coords for + // consistency + const wxPoint + pt = ScreenToClient(wxPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); wxMouseEvent event(wxEVT_MOUSEWHEEL); - InitMouseEvent(event, - GET_X_LPARAM(lParam), - GET_Y_LPARAM(lParam), - LOWORD(wParam)); + InitMouseEvent(event, pt.x, pt.y, LOWORD(wParam)); event.m_wheelRotation = (short)HIWORD(wParam); event.m_wheelDelta = WHEEL_DELTA; @@ -4848,7 +4810,8 @@ bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam) return false; } -int wxWindowMSW::HandleMenuChar(int chAccel, WXLPARAM lParam) +int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel), + WXLPARAM WXUNUSED_IN_WINCE(lParam)) { // FIXME: implement GetMenuItemCount for WinCE, possibly // in terms of GetMenuItemInfo @@ -4906,9 +4869,6 @@ int wxWindowMSW::HandleMenuChar(int chAccel, WXLPARAM lParam) wxLogLastError(_T("GetMenuItemInfo")); } } -#else - wxUnusedVar(chAccel); - wxUnusedVar(lParam); #endif return wxNOT_FOUND; } @@ -5066,7 +5026,7 @@ bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam, : SB_VERT, &scrollInfo) ) { - // Not neccessarily an error, if there are no scrollbars yet. + // Not necessarily an error, if there are no scrollbars yet. // wxLogLastError(_T("GetScrollInfo")); } @@ -6049,31 +6009,6 @@ bool wxWindowMSW::HandleHotKey(WXWPARAM wParam, WXLPARAM lParam) #endif // wxUSE_HOTKEY -// Moves a window by deferred method or normal method -bool wxMoveWindowDeferred(HDWP& hdwp, wxWindowBase* win, HWND hWnd, int x, int y, int width, int height) -{ - if ( hdwp ) - { - hdwp = ::DeferWindowPos(hdwp, hWnd, NULL, - x, y, width, height, - SWP_NOZORDER); - if ( !hdwp ) - { - wxLogLastError(_T("DeferWindowPos")); - } - } - - // otherwise (or if deferring failed) move the window in place immediately - if ( !hdwp ) - { - if ( !::MoveWindow(hWnd, x, y, width, height, win->IsShown()) ) - { - wxLogLastError(wxT("MoveWindow")); - } - } - return hdwp != NULL; -} - // Not tested under WinCE #ifndef __WXWINCE__