From d408730ce4d27aeea9e798d887f4577a3c65f762 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Tue, 31 Oct 2006 13:09:08 +0000
Subject: [PATCH] ensure that wxToolBar has one of wxTB_TOP/LEFT/RIGHT/BOTTOM
 styles set, otherwise the latest toolbar positioning code breaks down

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42840 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 include/wx/tbarbase.h      | 7 +++++++
 src/cocoa/toolbar.mm       | 8 +++++++-
 src/common/tbarbase.cpp    | 9 +++++++++
 src/gtk/tbargtk.cpp        | 2 ++
 src/gtk1/tbargtk.cpp       | 2 ++
 src/mac/carbon/toolbar.cpp | 2 ++
 src/motif/toolbar.cpp      | 2 ++
 src/msw/tbar95.cpp         | 2 ++
 src/univ/toolbar.cpp       | 2 ++
 9 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/wx/tbarbase.h b/include/wx/tbarbase.h
index 1a3dee8604..3aa70ce99d 100644
--- a/include/wx/tbarbase.h
+++ b/include/wx/tbarbase.h
@@ -564,6 +564,13 @@ protected:
     // helper functions
     // ----------------
 
+    // call this from derived class ctor/Create() to ensure that we have either
+    // wxTB_HORIZONTAL or wxTB_VERTICAL style, there is a lot of existing code
+    // which randomly checks either one or the other of them and gets confused
+    // if neither is set (and making one of them 0 is not an option neither as
+    // then the existing tests would break down)
+    void FixupStyle();
+
     // un-toggle all buttons in the same radio group
     void UnToggleRadioGroup(wxToolBarToolBase *tool);
 
diff --git a/src/cocoa/toolbar.mm b/src/cocoa/toolbar.mm
index b831696cfe..f6211e3c79 100644
--- a/src/cocoa/toolbar.mm
+++ b/src/cocoa/toolbar.mm
@@ -186,7 +186,13 @@ bool wxToolBar::Create( wxWindow *parent,
                         const wxString& name )
 {
     // Call wxControl::Create so we get a wxNonControlNSControl
-    return wxToolBarBase::Create(parent,winid,pos,size,style,wxDefaultValidator,name);
+    if ( !wxToolBarBase::Create(parent, winid, pos, size, style,
+                                wxDefaultValidator, name) )
+        return false;
+
+    FixupStyle();
+
+    return true;
 }
 
 wxToolBarToolBase *wxToolBar::CreateTool(int toolid,
diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp
index 7814a7b4ae..f8957002e0 100644
--- a/src/common/tbarbase.cpp
+++ b/src/common/tbarbase.cpp
@@ -123,6 +123,15 @@ wxToolBarBase::wxToolBarBase()
     m_defaultHeight = 15;
 }
 
+void wxToolBarBase::FixupStyle()
+{
+    if ( !HasFlag(wxTB_TOP | wxTB_LEFT | wxTB_RIGHT | wxTB_BOTTOM) )
+    {
+        // this is the default
+        m_windowStyle |= wxTB_TOP;
+    }
+}
+
 wxToolBarToolBase *wxToolBarBase::DoAddTool(int id,
                                             const wxString& label,
                                             const wxBitmap& bitmap,
diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp
index 42bca3ab03..dd18e1d3a9 100644
--- a/src/gtk/tbargtk.cpp
+++ b/src/gtk/tbargtk.cpp
@@ -287,6 +287,8 @@ bool wxToolBar::Create( wxWindow *parent,
         return false;
     }
 
+    FixupStyle();
+
     m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
     GtkSetStyle();
 
diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp
index 06885d5341..fab29b7cfe 100644
--- a/src/gtk1/tbargtk.cpp
+++ b/src/gtk1/tbargtk.cpp
@@ -285,6 +285,8 @@ bool wxToolBar::Create( wxWindow *parent,
         return false;
     }
 
+    FixupStyle();
+
     GtkOrientation orient;
     GtkToolbarStyle gtkStyle;
     GetGtkStyle(style, &orient, &gtkStyle);
diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp
index 997a557d1b..7614e62312 100644
--- a/src/mac/carbon/toolbar.cpp
+++ b/src/mac/carbon/toolbar.cpp
@@ -792,6 +792,8 @@ bool wxToolBar::Create(
     if ( !wxToolBarBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
         return false;
 
+    FixupStyle();
+
     OSStatus err = noErr;
 
 #if wxMAC_USE_NATIVE_TOOLBAR
diff --git a/src/motif/toolbar.cpp b/src/motif/toolbar.cpp
index 753bb8ff20..42851b1b38 100644
--- a/src/motif/toolbar.cpp
+++ b/src/motif/toolbar.cpp
@@ -204,6 +204,8 @@ bool wxToolBar::Create(wxWindow *parent,
                                    wxDefaultValidator, name ) )
         return false;
 
+    FixupStyle();
+
     m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
 
     Widget parentWidget = (Widget) parent->GetClientWidget();
diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp
index 16a2ec95c9..8cab9f682e 100644
--- a/src/msw/tbar95.cpp
+++ b/src/msw/tbar95.cpp
@@ -234,6 +234,8 @@ bool wxToolBar::Create(wxWindow *parent,
     if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
         return false;
 
+    FixupStyle();
+
     // MSW-specific initialisation
     if ( !MSWCreateToolbar(pos, size) )
         return false;
diff --git a/src/univ/toolbar.cpp b/src/univ/toolbar.cpp
index fafb168d02..264bddd043 100644
--- a/src/univ/toolbar.cpp
+++ b/src/univ/toolbar.cpp
@@ -190,6 +190,8 @@ bool wxToolBar::Create(wxWindow *parent,
         return false;
     }
 
+    FixupStyle();
+
     CreateInputHandler(wxINP_HANDLER_TOOLBAR);
 
     SetInitialSize(size);
-- 
2.47.2