From f07e40a4c06be136341aad6f7ef8ae54fc803dbc Mon Sep 17 00:00:00 2001
From: James Crook <james.k.crook@gmail.com>
Date: Thu, 20 Sep 2018 13:16:09 +0100
Subject: [PATCH] Bug 1983 - Preference updates do not preserve toolbar widths

---
 src/toolbars/ToolBar.cpp     | 21 +++++++++++++++++----
 src/toolbars/ToolBar.h       |  1 +
 src/toolbars/ToolManager.cpp |  1 +
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/toolbars/ToolBar.cpp b/src/toolbars/ToolBar.cpp
index 422d9c7514..21c83ddd3b 100644
--- a/src/toolbars/ToolBar.cpp
+++ b/src/toolbars/ToolBar.cpp
@@ -459,6 +459,13 @@ void ToolBar::Create( wxWindow *parent )
    mVisible = true;
 }
 
+void ToolBar::SetToDefaultSize(){
+   wxSize sz;
+   sz.SetHeight( -1 );
+   sz.SetWidth( GetInitialWidth());
+   SetSize( sz );
+}
+
 void ToolBar::ReCreateButtons()
 {
    wxSize sz3 = GetSize();
@@ -519,12 +526,18 @@ void ToolBar::ReCreateButtons()
       sz2.SetWidth(GetMinToolbarWidth());
       sz2.y = tbs -1;
       SetMinSize(sz2);
-      // Initial size at least as big as minimum.
+      
+      // sz2 is now the minimum size.
+      // sz3 is the size we were.
+      // When recreating buttons, we want to preserve size.
+      // But not if that makes the size too small.
+
+      // Size at least as big as minimum.
       if( sz3.y < sz2.y )
          sz3.y = sz2.y;
-      //if( sz3.x < sz2.x )
-      sz3.x = GetInitialWidth();
-      //sz.SetWidth();
+      if( sz3.x < sz2.x )
+         sz3.x = sz2.x;
+
       SetSize(sz3);
    }
    else
diff --git a/src/toolbars/ToolBar.h b/src/toolbars/ToolBar.h
index 7796eadd5f..e4a91dc3f5 100644
--- a/src/toolbars/ToolBar.h
+++ b/src/toolbars/ToolBar.h
@@ -96,6 +96,7 @@ class ToolBar /* not final */ : public wxPanelWrapper
 
    bool AcceptsFocus() const override { return false; };
 
+   void SetToDefaultSize();
    //NEW virtuals:
    virtual void Create(wxWindow *parent);
    virtual void EnableDisableButtons() = 0;
diff --git a/src/toolbars/ToolManager.cpp b/src/toolbars/ToolManager.cpp
index a3880af7c6..fa3bcc8885 100644
--- a/src/toolbars/ToolManager.cpp
+++ b/src/toolbars/ToolManager.cpp
@@ -546,6 +546,7 @@ void ToolManager::Reset()
          floater->Destroy();
 
       // Recreate bar buttons (and resize it)
+      bar->SetToDefaultSize();
       bar->ReCreateButtons();
       bar->EnableDisableButtons();
 
-- 
GitLab