From 55079b432bf9e46f9b19efa71462b32022ffcf5e Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Fri, 29 Apr 2005 18:58:38 +0000 Subject: [PATCH] Removed previous broken fix for deferred positioning bug, and added fix using sizers, which works better git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33918 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 3 +++ include/wx/msw/window.h | 12 --------- src/msw/radiobox.cpp | 16 +++-------- src/msw/slider95.cpp | 17 +++--------- src/msw/spinctrl.cpp | 35 +++--------------------- src/msw/window.cpp | 60 ++++++++--------------------------------- 6 files changed, 25 insertions(+), 118 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 5500ee0fd4..5e712b3e0a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -23,6 +23,9 @@ wxMSW: by refreshing parent when the radio box moves. - Added ability set the system option "msw.staticbox.optimized-paint" to 0 to allow a panel to paint graphics around controls within a static box. +- Worked around an apparent bug in deferred window positioning (moving a + window from (x, y) to (a, b) and back to (x, y) misses the last step) by + checking window positions against corresponding sizer state, if any. wxMac: diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 377afca91b..b5058d57da 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -544,17 +544,5 @@ WX_DECLARE_HASH(wxWindowMSW, wxWindowList, wxWinHashTable); extern wxWinHashTable *wxWinHandleHash; -// ---------------------------------------------------------------------------- -// extra data needed for correcting problems with deferred positioning -// ---------------------------------------------------------------------------- - -struct wxExtraWindowData -{ - // Stored during deferred positioning - wxPoint m_pos; - wxSize m_size; - bool m_deferring:1; -}; - #endif // _WX_WINDOW_H_ diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index 181a778ae0..50e27bae8d 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -657,22 +657,14 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) x_offset += widthBtn + cx1; } } - if (hdwp) - { - // Store the size so we can report it accurately - wxExtraWindowData* extraData = (wxExtraWindowData*) m_windowReserved; - if (!extraData) - { - extraData = new wxExtraWindowData; - m_windowReserved = (void*) extraData; - } - extraData->m_pos = wxPoint(xx, yy); - extraData->m_size = wxSize(width, height); - extraData->m_deferring = true; +#if USE_DEFERRED_SIZING + if (parent) + { // hdwp must be updated as it may have been changed parent->m_hDWP = (WXHANDLE)hdwp; } +#endif } // ---------------------------------------------------------------------------- diff --git a/src/msw/slider95.cpp b/src/msw/slider95.cpp index 35380bd868..f9106b7830 100644 --- a/src/msw/slider95.cpp +++ b/src/msw/slider95.cpp @@ -43,7 +43,6 @@ #endif #define USE_DEFERRED_SIZING 1 -#define USE_DEFER_BUG_WORKAROUND 0 // ---------------------------------------------------------------------------- // constants @@ -507,22 +506,14 @@ void wxSlider::DoMoveWindow(int x, int y, int width, int height) width, height - hLabel); } - if ( hdwp ) - { - // Store the size so we can report it accurately - wxExtraWindowData* extraData = (wxExtraWindowData*) m_windowReserved; - if (!extraData) - { - extraData = new wxExtraWindowData; - m_windowReserved = (void*) extraData; - } - extraData->m_pos = wxPoint(x, y); - extraData->m_size = wxSize(width, height); - extraData->m_deferring = true; +#if USE_DEFERRED_SIZING + if ( parent ) + { // hdwp must be updated as it may have been changed parent->m_hDWP = (WXHANDLE)hdwp; } +#endif } wxSize wxSlider::DoGetBestSize() const diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index b33dee669b..606772143f 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -590,37 +590,18 @@ void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) wxMoveWindowDeferred(hdwp, this, GetHwnd(), x, y, widthBtn, height); - if (hdwp) +#if USE_DEFERRED_SIZING + if (parent) { - // Store the size so we can report it accurately - wxExtraWindowData* extraData = (wxExtraWindowData*) m_windowReserved; - if (!extraData) - { - extraData = new wxExtraWindowData; - m_windowReserved = (void*) extraData; - } - extraData->m_pos = wxPoint(originalX, y); - extraData->m_size = wxSize(width, height); - extraData->m_deferring = true; - // hdwp must be updated as it may have been changed parent->m_hDWP = (WXHANDLE)hdwp; } +#endif } // get total size of the control void wxSpinCtrl::DoGetSize(int *x, int *y) const { -#if USE_DEFER_BUG_WORKAROUND - wxExtraWindowData* extraData = (wxExtraWindowData*) m_windowReserved; - if (extraData && extraData->m_deferring && GetParent() && GetParent()->m_hDWP) - { - *x = extraData->m_size.x; - *y = extraData->m_size.y; - return; - } -#endif - RECT spinrect, textrect, ctrlrect; GetWindowRect(GetHwnd(), &spinrect); GetWindowRect(GetBuddyHwnd(), &textrect); @@ -634,16 +615,6 @@ void wxSpinCtrl::DoGetSize(int *x, int *y) const void wxSpinCtrl::DoGetPosition(int *x, int *y) const { -#if USE_DEFER_BUG_WORKAROUND - wxExtraWindowData* extraData = (wxExtraWindowData*) m_windowReserved; - if (extraData && extraData->m_deferring && GetParent() && GetParent()->m_hDWP) - { - *x = extraData->m_pos.x; - *y = extraData->m_pos.y; - return; - } -#endif - // hack: pretend that our HWND is the text control just for a moment WXHWND hWnd = GetHWND(); wxConstCast(this, wxSpinCtrl)->m_hWnd = m_hwndBuddy; diff --git a/src/msw/window.cpp b/src/msw/window.cpp index c2a83c0347..d72864aa13 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -120,7 +120,7 @@ #endif // everything needed for TrackMouseEvent() #define USE_DEFERRED_SIZING 1 -#define USE_DEFER_BUG_WORKAROUND 0 +#define USE_DEFER_BUG_WORKAROUND 1 // --------------------------------------------------------------------------- // global variables @@ -471,12 +471,6 @@ wxWindowMSW::~wxWindowMSW() { m_isBeingDeleted = true; - if (m_windowReserved) - { - delete (wxExtraWindowData*) m_windowReserved; - m_windowReserved = NULL; - } - #ifndef __WXUNIVERSAL__ // VS: make sure there's no wxFrame with last focus set to us: for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) @@ -1452,16 +1446,6 @@ void wxWindowMSW::DoSetToolTip(wxToolTip *tooltip) // Get total size void wxWindowMSW::DoGetSize(int *x, int *y) const { -#if USE_DEFER_BUG_WORKAROUND - wxExtraWindowData* extraData = (wxExtraWindowData*) m_windowReserved; - if (extraData && extraData->m_deferring && GetParent() && GetParent()->m_hDWP) - { - *x = extraData->m_size.x; - *y = extraData->m_size.y; - return; - } -#endif - RECT rect = wxGetWindowRect(GetHwnd()); if ( x ) @@ -1483,16 +1467,6 @@ void wxWindowMSW::DoGetClientSize(int *x, int *y) const void wxWindowMSW::DoGetPosition(int *x, int *y) const { -#if USE_DEFER_BUG_WORKAROUND - wxExtraWindowData* extraData = (wxExtraWindowData*) m_windowReserved; - if (extraData && extraData->m_deferring && GetParent() && GetParent()->m_hDWP) - { - *x = extraData->m_pos.x; - *y = extraData->m_pos.y; - return; - } -#endif - RECT rect = wxGetWindowRect(GetHwnd()); POINT point; @@ -1584,22 +1558,11 @@ void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height) wxMoveWindowDeferred(hdwp, this, GetHwnd(), x, y, width, height); - if ( hdwp ) - { - // Store the size so we can report it accurately - wxExtraWindowData* extraData = (wxExtraWindowData*) m_windowReserved; - if (!extraData) - { - extraData = new wxExtraWindowData; - m_windowReserved = (void*) extraData; - } - extraData->m_pos = wxPoint(x, y); - extraData->m_size = wxSize(width, height); - extraData->m_deferring = true; - +#if USE_DEFERRED_SIZING + if ( parent ) // hdwp must be updated as it may have been changed parent->m_hDWP = (WXHANDLE)hdwp; - } +#endif } // set the size of the window: if the dimensions are positive, just use them, @@ -4255,15 +4218,14 @@ bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam) node = node->GetNext() ) { wxWindow *child = node->GetData(); - wxExtraWindowData* extraData = (wxExtraWindowData*) child->m_windowReserved; - if (extraData && extraData->m_deferring) + wxSizer* sizer = child->GetContainingSizer(); + if (sizer) { - wxPoint pos = child->GetPosition(); - - if (extraData->m_pos != pos) - child->Move(extraData->m_pos); - - extraData->m_deferring = false; + wxSizerItem* item = sizer->GetItem(child, true); + if (item->GetRect().GetPosition() != child->GetPosition()) + { + child->Move(item->GetRect().GetPosition()); + } } } #endif -- 2.45.2