From 82cf9b3ab642f7de339efdb023f83f158bb220d7 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 11 Jun 2016 16:29:25 -0400 Subject: [PATCH] Don't increase width when a toolbar is repeatedly docked and undocked --- src/toolbars/ToolBar.h | 3 +++ src/toolbars/ToolDock.cpp | 11 ++++++++--- src/toolbars/ToolDock.h | 2 +- src/toolbars/ToolManager.cpp | 13 +++++++------ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/toolbars/ToolBar.h b/src/toolbars/ToolBar.h index 340da44de..df942ce69 100644 --- a/src/toolbars/ToolBar.h +++ b/src/toolbars/ToolBar.h @@ -80,6 +80,9 @@ enum ToolBarCount }; +// How may pixels padding each side of a floating toolbar +enum { ToolBarFloatMargin = 1 }; + class ToolBar /* not final */ : public wxPanel { diff --git a/src/toolbars/ToolDock.cpp b/src/toolbars/ToolDock.cpp index f760bccb3..0fe74c51f 100644 --- a/src/toolbars/ToolDock.cpp +++ b/src/toolbars/ToolDock.cpp @@ -129,14 +129,19 @@ int ToolDock::GetBarCount() // // Handle ToolDock events // -void ToolDock::Dock( ToolBar *bar, int before ) +void ToolDock::Dock( ToolBar *bar, bool deflate, int before ) { // Adopt the toolbar into our family bar->Reparent( this ); mBars[ bar->GetId() ] = bar; - // Reset height - bar->SetSize( bar->GetSize().x, bar->GetDockedSize().y ); + // Reset size + bar->SetSize( + // Undo the expansion that was applied when un-docking + bar->GetSize().x - (deflate ? 2 * ToolBarFloatMargin : 0), + // Don't need to adjust y the same way. + bar->GetDockedSize().y + ); // Park the NEW bar in the correct berth if( before >= 0 && before < (int)mDockedBars.GetCount() ) diff --git a/src/toolbars/ToolDock.h b/src/toolbars/ToolDock.h index f45989c06..3475d66f0 100644 --- a/src/toolbars/ToolDock.h +++ b/src/toolbars/ToolDock.h @@ -60,7 +60,7 @@ class ToolDock final : public wxPanel int Find(ToolBar *bar) const; int GetOrder( ToolBar *bar ); int GetBarCount(); - void Dock( ToolBar *bar, int ndx = -1 ); + void Dock( ToolBar *bar, bool deflate, int ndx = -1 ); void Undock( ToolBar *bar ); int PositionBar( ToolBar *t, wxPoint & pos, wxRect & rect ); diff --git a/src/toolbars/ToolManager.cpp b/src/toolbars/ToolManager.cpp index 12f0acb41..f1729de85 100644 --- a/src/toolbars/ToolManager.cpp +++ b/src/toolbars/ToolManager.cpp @@ -136,7 +136,8 @@ class ToolFrame final : public wxFrame width += sizerW; } - SetSize(width + 2, bar->GetDockedSize().y + 2); + SetSize(width + 2 * ToolBarFloatMargin, + bar->GetDockedSize().y + 2 * ToolBarFloatMargin); // Attach the sizer and resize the window to fit SetSizer(s.release()); @@ -557,7 +558,7 @@ void ToolManager::Reset() if( dock != NULL ) { // when we dock, we reparent, so bar is no longer a child of floater. - dock->Dock( bar ); + dock->Dock( bar, false ); Expose( ndx, expose ); //OK (and good) to DELETE floater, as bar is no longer in it. if( floater ) @@ -783,7 +784,7 @@ void ToolManager::ReadConfig() ToolBar *t = mBars[ ndx ]; // Dock it - d->Dock( t ); + d->Dock( t, false ); // Show or hide it Expose( t->GetId(), show[ t->GetId() ] ); @@ -796,7 +797,7 @@ void ToolManager::ReadConfig() ToolBar *t = mBars[ unordered[ dock ][ ord ] ]; // Dock it - d->Dock( t ); + d->Dock( t, false ); // Show or hide the bar Expose( t->GetId(), show[ t->GetId() ] ); @@ -1017,7 +1018,7 @@ void ToolManager::OnMouse( wxMouseEvent & event ) if( mDragDock && !event.ShiftDown() ) { // Trip over...everyone ashore that's going ashore... - mDragDock->Dock( mDragBar, mDragBefore ); + mDragDock->Dock( mDragBar, true, mDragBefore ); // Done with the floater mDragWindow->Destroy(); @@ -1303,7 +1304,7 @@ void ToolManager::HandleEscapeKey() // Why don't you leave me alone? // Well, I feel so break up // I want to go home. - mPrevDock->Dock( mDragBar, mPrevSlot ); + mPrevDock->Dock( mDragBar, true, mPrevSlot ); // Done with the floater mDragWindow->Destroy();