X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4552892fc214995d0e0a5f1e059915d2a89c023b..921c65ed3d889117c600387cebb0bce2470cff8e:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 76b0b095ed..031585be7c 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -47,6 +47,7 @@ #include "wx/msgdlg.h" #include "wx/settings.h" #include "wx/statbox.h" + #include "wx/sizer.h" #endif #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__) @@ -107,13 +108,7 @@ #include #endif -#if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__) - #ifdef __WIN95__ - #include - #endif -#elif !defined(__WXMICROWIN__) && !defined(__WXWINCE__) // broken compiler - #include "wx/msw/gnuwin32/extra.h" -#endif +#include #include "wx/msw/missing.h" @@ -125,6 +120,9 @@ #define HAVE_TRACKMOUSEEVENT #endif // everything needed for TrackMouseEvent() +#define USE_DEFERRED_SIZING 1 +#define USE_DEFER_BUG_WORKAROUND 1 + // --------------------------------------------------------------------------- // global variables // --------------------------------------------------------------------------- @@ -223,9 +221,12 @@ static void EnsureParentHasControlParentStyle(wxWindow *parent) // instead bool GetCursorPosWinCE(POINT* pt) { - DWORD pos = GetMessagePos(); - pt->x = LOWORD(pos); - pt->y = HIWORD(pos); + if (!GetCursorPos(pt)) + { + DWORD pos = GetMessagePos(); + pt->x = LOWORD(pos); + pt->y = HIWORD(pos); + } return true; } #endif @@ -464,6 +465,9 @@ void wxWindowMSW::Init() m_lastMouseY = -1; m_lastMouseEvent = -1; #endif // wxUSE_MOUSEEVENT_HACK + + m_pendingPosition = wxDefaultPosition; + m_pendingSize = wxDefaultSize; } // Destructor @@ -511,6 +515,7 @@ wxWindowMSW::~wxWindowMSW() } delete m_childrenDisabled; + } // real construction (Init() must have been called before!) @@ -1365,7 +1370,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; @@ -1549,29 +1555,20 @@ void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height) // 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; - if ( hdwp ) - { - hdwp = ::DeferWindowPos(hdwp, GetHwnd(), NULL, - x, y, width, height, - SWP_NOZORDER); - if ( !hdwp ) - { - wxLogLastError(_T("DeferWindowPos")); - } +#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; - } - - // otherwise (or if deferring failed) move the window in place immediately - if ( !hdwp ) - { - if ( !::MoveWindow(GetHwnd(), x, y, width, height, IsShown()) ) - { - wxLogLastError(wxT("MoveWindow")); - } - } +#endif } // set the size of the window: if the dimensions are positive, just use them, @@ -1586,9 +1583,28 @@ void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) { // get the current size and position... int currentX, currentY; + int currentW, currentH; + +#if USE_DEFER_BUG_WORKAROUND + currentX = m_pendingPosition.x; + if (currentX == wxDefaultCoord) + GetPosition(¤tX, NULL); + + currentY = m_pendingPosition.y; + if (currentY == wxDefaultCoord) + GetPosition(NULL, ¤tY); + + currentW = m_pendingSize.x; + if (currentW == wxDefaultCoord) + GetSize(¤tW, NULL); + + currentH = m_pendingSize.y; + if (currentH == wxDefaultCoord) + GetSize(NULL, ¤tH); +#else GetPosition(¤tX, ¤tY); - int currentW,currentH; GetSize(¤tW, ¤tH); +#endif // ... and don't do anything (avoiding flicker) if it's already ok if ( x == currentX && y == currentY && @@ -1638,6 +1654,24 @@ 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_pendingPosition = wxPoint(x, y); + m_pendingSize = wxSize(width, height); + } + else + { + m_pendingPosition = wxDefaultPosition; + m_pendingSize = wxDefaultSize; + } +#endif + DoMoveWindow(x, y, width, height); } @@ -1737,7 +1771,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 ) @@ -2318,6 +2352,31 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l break; #endif // !__WXWINCE__ + case WM_WINDOWPOSCHANGED: + { + WINDOWPOS *lpPos = (WINDOWPOS *)lParam; + + if ( !(lpPos->flags & SWP_NOSIZE) ) + { + RECT rc; + ::GetClientRect(GetHwnd(), &rc); + + 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); + + } + } + break; + #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) case WM_ACTIVATEAPP: // This implicitly sends a wxEVT_ACTIVATE_APP event @@ -3516,7 +3575,7 @@ bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd), // specific way (for example, depending on the current position) POINT pt; #ifdef __WXWINCE__ - if ( !::GetCursorPosWinCE(&pt) ) + if ( !::GetCursorPosWinCE(&pt)) #else if ( !::GetCursorPos(&pt) ) #endif @@ -3604,7 +3663,11 @@ wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id), { wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData); - wxCHECK_MSG( pMenuItem && pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), + // see comment before the same test in MSWOnMeasureItem() below + if ( !pMenuItem ) + return false; + + wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem), false, _T("MSWOnDrawItem: bad wxMenuItem pointer") ); // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent @@ -3869,6 +3932,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() ) { @@ -4081,6 +4145,10 @@ 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; + for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) { if ( win->MSWPrintChild(hDC, (wxWindow *)this) ) @@ -4135,17 +4203,34 @@ bool wxWindowMSW::HandleMoving(wxRect& rect) bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam) { +#if USE_DEFERRED_SIZING // when we resize this window, its children are probably going to be // repositioned as well, prepare to use DeferWindowPos() for them - const int numChildren = GetChildren().GetCount(); + int numChildren = 0; + for ( HWND child = ::GetWindow(GetHwndOf(this), GW_CHILD); + child; + child = ::GetWindow(child, GW_HWNDNEXT) ) + { + numChildren ++; + } + + // Protect against valid m_hDWP being overwritten + bool useDefer = false; + if ( numChildren > 1 ) { - m_hDWP = (WXHANDLE)::BeginDeferWindowPos(numChildren); - if ( !m_hDWP ) + if (!m_hDWP) { - wxLogLastError(_T("BeginDeferWindowPos")); + m_hDWP = (WXHANDLE)::BeginDeferWindowPos(numChildren); + if ( !m_hDWP ) + { + wxLogLastError(_T("BeginDeferWindowPos")); + } + if (m_hDWP) + useDefer = true; } } +#endif // update this window size bool processed = false; @@ -4178,8 +4263,9 @@ bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam) processed = GetEventHandler()->ProcessEvent(event); } +#if USE_DEFERRED_SIZING // and finally change the positions of all child windows at once - if ( m_hDWP ) + if ( useDefer && m_hDWP ) { // reset m_hDWP to NULL so that child windows don't try to use our // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't @@ -4193,7 +4279,20 @@ 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_pendingPosition = wxDefaultPosition; + child->m_pendingSize = wxDefaultSize; + } +#endif } +#endif return processed; } @@ -5930,6 +6029,31 @@ 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__