+ if ( !wxToolBarBase::Realize() )
+ return false;
+
+ m_needsLayout = true;
+ DoLayout();
+
+ SetInitialSize(wxDefaultSize);
+
+ return true;
+}
+
+void wxToolBar::SetWindowStyleFlag( long style )
+{
+ wxToolBarBase::SetWindowStyleFlag(style);
+
+ m_needsLayout = true;
+
+ Refresh();
+}
+
+void wxToolBar::DoLayout()
+{
+ wxASSERT_MSG( m_needsLayout, _T("why are we called?") );
+
+ m_needsLayout = false;
+
+ wxCoord x = m_xMargin,
+ y = m_yMargin;
+
+ wxCoord widthTool = 0, maxWidthTool = 0;
+ wxCoord heightTool = 0, maxHeightTool = 0;
+ wxCoord margin = IsVertical() ? m_xMargin : m_yMargin;
+ wxCoord *pCur = IsVertical() ? &y : &x;
+
+ // calculate the positions of all elements
+ for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
+ node;
+ node = node->GetNext() )
+ {
+ wxToolBarTool *tool = (wxToolBarTool *) node->GetData();
+
+ tool->m_x = x;
+ tool->m_y = y;
+
+ // TODO ugly number fiddling
+ if (tool->IsButton())
+ {
+ if (IsVertical())
+ {
+ widthTool = m_defaultHeight;
+ heightTool = m_defaultWidth;
+ if(HasFlag(wxTB_TEXT))
+ heightTool += GetFont().GetPointSize() * tool->GetLabel().length();
+ }
+ else
+ {
+ widthTool = m_defaultWidth;
+ if(HasFlag(wxTB_TEXT))
+ widthTool += GetFont().GetPointSize() * tool->GetLabel().length();
+
+ heightTool = m_defaultHeight;
+ }
+
+ if(widthTool > maxWidthTool) // Record max width of tool
+ {
+ maxWidthTool = widthTool;
+ }
+
+ if(heightTool > maxHeightTool) // Record max width of tool
+ {
+ maxHeightTool = heightTool;
+ }
+
+ *pCur += widthTool;
+ }
+ else if (tool->IsSeparator())
+ {
+ *pCur += m_widthSeparator;
+ }
+ else if (!IsVertical()) // horizontal control
+ {
+ wxControl *control = tool->GetControl();
+ wxSize size = control->GetSize();
+ tool->m_y += (m_defaultHeight - size.y)/2;
+ tool->m_width = size.x;
+ tool->m_height = size.y;
+
+ *pCur += tool->m_width;
+ }
+ *pCur += margin;
+ }
+
+ // calculate the total toolbar size
+ wxCoord xMin, yMin;
+
+ if(!HasFlag(wxTB_TEXT))