From 229de929f3576fb97aae8d8a00cdd663d0972c80 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 31 Jul 2003 11:33:39 +0000 Subject: [PATCH] Suppressed some flicker in standard wxToolBar git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22410 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/toolbar/toolbar.cpp | 6 +++-- src/msw/frame.cpp | 52 ++++++++++++++++++++++++++++++++----- src/msw/tbar95.cpp | 4 +++ 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index cda93e9e86..4071436847 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -92,7 +92,7 @@ public: const wxString& title = _T("wxToolBar Sample"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE); + long style = wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE); void RecreateToolbar(); @@ -267,6 +267,7 @@ void MyFrame::RecreateToolbar() style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL); style |= m_horzToolbar ? wxTB_HORIZONTAL : wxTB_VERTICAL; + style |= wxNO_FULL_REPAINT_ON_RESIZE ; toolBar = CreateToolBar(style, ID_TOOLBAR); #endif @@ -611,7 +612,8 @@ void MyFrame::DoToggleHelp() void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event) { - event.Enable( m_textWindow->CanCopy() ); + if (m_textWindow) + event.Enable( m_textWindow->CanCopy() ); } void MyFrame::OnChangeToolTip(wxCommandEvent& WXUNUSED(event)) diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index 0d51775ff8..62e85fbec7 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -474,23 +474,63 @@ void wxFrame::PositionToolBar() } #endif // wxUSE_STATUSBAR + int tx, ty; int tw, th; + toolbar->GetPosition(&tx, &ty); toolbar->GetSize(&tw, &th); + + // Adjust + if (ty < 0 && (-ty == th)) + ty = 0; + if (tx < 0 && (-tx == tw)) + tx = 0; + + int desiredW = tw; + int desiredH = th; if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) { - th = height; + desiredH = height; } else { - tw = width; - if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT ) - th -= 3; - } + desiredW = width; +// if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT ) +// desiredW -= 3; + } // use the 'real' MSW position here, don't offset relativly to the // client area origin - toolbar->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); + + // Optimise such that we don't have to always resize the toolbar + // when the frame changes, otherwise we'll get a lot of flicker. + bool heightChanging = TRUE; + bool widthChanging = TRUE; + + if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) + { + // It's OK if the current height is greater than what can be shown. + heightChanging = (desiredH > th) ; + widthChanging = (desiredW != tw) ; + + // The next time around, we may not have to set the size + if (heightChanging) + desiredH = desiredH + 200; + } + else + { + // It's OK if the current width is greater than what can be shown. + widthChanging = (desiredW > tw) ; + heightChanging = (desiredH != th) ; + + // The next time around, we may not have to set the size + if (widthChanging) + desiredW = desiredW + 200; + } + + if (tx != 0 || ty != 0 || widthChanging || heightChanging) + toolbar->SetSize(0, 0, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS); + #endif // __WXWINCE__ } } diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index 0307c1eff2..f6fd243ceb 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -1311,6 +1311,10 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) { // yes, do erase it! dc.DrawRectangle(rectItem); + + // Necessary in case we use a no-paint-on-size + // style in the parent: the controls can disappear + control->Refresh(FALSE); } } } -- 2.45.2