X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/10b959e3729a77b95ab15614d1bdce74da327d8b..a3622daa901777a33969d8bc04e2d62dee14d164:/src/common/tbarsmpl.cpp diff --git a/src/common/tbarsmpl.cpp b/src/common/tbarsmpl.cpp index b14e1ee2b5..a75de10e3b 100644 --- a/src/common/tbarsmpl.cpp +++ b/src/common/tbarsmpl.cpp @@ -47,10 +47,13 @@ static wxPen * white_pen = NULL, wxToolBarSimple::wxToolBarSimple(void) { + m_currentRowsOrColumns = 0; + m_lastX = 0; + m_lastY = 0; } -bool wxToolBarSimple::Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, - const int direction, const int RowsOrColumns, const wxString& name ) +bool wxToolBarSimple::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, + const wxString& name ) { if ( ! wxWindow::Create(parent, id, pos, size, style, name) ) return FALSE; @@ -79,12 +82,10 @@ bool wxToolBarSimple::Create(wxWindow *parent, const wxWindowID id, const wxPoin { thick_black_pen = new wxPen("BLACK", 3, wxSOLID); } - m_tilingDirection = direction; - m_rowsOrColumns = RowsOrColumns; - if ( m_tilingDirection == wxVERTICAL ) - { m_lastX = 3; m_lastY = 7; } - else + if ( GetWindowStyleFlag() & wxTB_VERTICAL ) { m_lastX = 7; m_lastY = 3; } + else + { m_lastX = 3; m_lastY = 7; } m_maxWidth = m_maxHeight = 0; m_pressedTool = m_currentTool = -1; m_xMargin = 0; @@ -119,18 +120,6 @@ void wxToolBarSimple::OnPaint (wxPaintEvent& event) DrawTool(dc, mem_dc, tool); } -/* Old code which drew a line beneath the toolbar - not generally - * wanted. - int w, h; - GetClientSize( &w, &h ); - wxPen * old_pen = dc.GetPen(); - dc.SetPen( *white_pen ); - dc.DrawLine(0,0,w,0); - dc.SetPen( *black_pen ); - dc.DrawLine(0,(h-1),w,(h-1)); - dc.SetPen( *old_pen ); -*/ - count--; } @@ -323,7 +312,7 @@ void wxToolBarSimple::DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool) } } -void wxToolBarSimple::ToggleTool(const int index, const bool toggle) +void wxToolBarSimple::ToggleTool(int index, bool toggle) { wxNode *node = m_tools.Find((long)index); if (node) @@ -348,7 +337,7 @@ void wxToolBarSimple::ToggleTool(const int index, const bool toggle) // the tool we're leaving was a 'sprung push button' and if so, // spring it back to the up state. // -void wxToolBarSimple::SpringUpButton(const int index) +void wxToolBarSimple::SpringUpButton(int index) { wxNode *node=m_tools.Find((long)index); if (node) { @@ -368,4 +357,97 @@ void wxToolBarSimple::SpringUpButton(const int index) } } +void wxToolBarSimple::Layout(void) +{ + m_currentRowsOrColumns = 0; + m_lastX = m_xMargin; + m_lastY = m_yMargin; + int maxToolWidth = 0; + int maxToolHeight = 0; + m_maxWidth = 0; + m_maxHeight = 0; + + // Find the maximum tool width and height + wxNode *node = m_tools.First(); + while (node) + { + wxToolBarTool *tool = (wxToolBarTool *)node->Data(); + if (tool->GetWidth() > maxToolWidth) + maxToolWidth = (int)tool->GetWidth(); + if (tool->GetHeight() > maxToolHeight) + maxToolHeight = (int)tool->GetHeight(); + node = node->Next(); + } + + int separatorSize = m_toolSeparation; + + node = m_tools.First(); + while (node) + { + wxToolBarTool *tool = (wxToolBarTool *)node->Data(); + if (tool->m_toolStyle == wxTOOL_STYLE_SEPARATOR) + { + if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + { + if (m_currentRowsOrColumns >= m_maxCols) + m_lastY += separatorSize; + else + m_lastX += separatorSize; + } + else + { + if (m_currentRowsOrColumns >= m_maxRows) + m_lastX += separatorSize; + else + m_lastY += separatorSize; + } + } + else if (tool->m_toolStyle == wxTOOL_STYLE_BUTTON) + { + if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + { + if (m_currentRowsOrColumns >= m_maxCols) + { + m_currentRowsOrColumns = 0; + m_lastX = m_xMargin; + m_lastY += maxToolHeight + m_toolPacking; + } + tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0); + tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0); + + m_lastX += maxToolWidth + m_toolPacking; + } + else + { + if (m_currentRowsOrColumns >= m_maxRows) + { + m_currentRowsOrColumns = 0; + m_lastX += (maxToolWidth + m_toolPacking); + m_lastY = m_yMargin; + } + tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0); + tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0); + + m_lastY += maxToolHeight + m_toolPacking; + } + m_currentRowsOrColumns ++; + } + + if (m_lastX > m_maxWidth) + m_maxWidth = m_lastX; + if (m_lastY > m_maxHeight) + m_maxHeight = m_lastY; + + node = node->Next(); + } + if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + m_maxWidth += maxToolWidth; + else + m_maxHeight += maxToolHeight; + + m_maxWidth += m_xMargin; + m_maxHeight += m_yMargin; +} + + #endif