+ // Set it to grey (or other 3D face colour)
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
+ SetFont(*wxSMALL_FONT);
+
+ if (GetWindowStyleFlag() & wxTB_VERTICAL)
+ {
+ m_vLastX = 7;
+ m_vLastY = 3;
+
+ m_maxRows = 32000; // a lot
+ m_maxCols = 1;
+ }
+ else
+ {
+ m_vLastX = 3;
+ m_vLastY = 7;
+
+ m_maxRows = 1;
+ m_maxCols = 32000; // a lot
+ }
+ SetCursor(*wxSTANDARD_CURSOR);
+
+ //
+ // The toolbar's tools, if they have labels and the winTB_TEXT
+ // style is set, then we need to take into account the size of
+ // the text when drawing tool bitmaps and the text
+ //
+ if (HasFlag(wxTB_TEXT))
+ {
+ wxClientDC vDC(this);
+
+ vDC.SetFont(GetFont());
+ vDC.GetTextExtent( "XXXX"
+ ,&m_vTextX
+ ,&m_vTextY
+ );
+ }
+
+ //
+ // Position it
+ //
+ int nX = rPos.x;
+ int nY = rPos.y;
+ int nWidth = rSize.x;
+ int nHeight = rSize.y;
+ wxFrame* pFrame = wxDynamicCast(GetParent(), wxFrame);
+
+ if (lStyle & wxTB_HORIZONTAL)
+ {
+ if (nWidth <= 0)
+ {
+ nWidth = pParent->GetClientSize().x;
+ }
+ if (nHeight <= 0)
+ {
+ if (lStyle & wxTB_TEXT)
+ nHeight = m_defaultHeight + m_vTextY;
+ else
+ nHeight = m_defaultHeight;
+ }
+ }
+ else
+ {
+ if (nHeight <= 0)
+ {
+ nHeight = pParent->GetClientSize().y;
+ }
+ if (nWidth <= 0)
+ {
+ if (lStyle & wxTB_TEXT)
+ nWidth = m_vTextX + (int)(m_vTextX/2); // a little margin
+ else
+ nWidth = m_defaultWidth + (int)(m_defaultWidth/2); // a little margin
+ }
+ }
+ if (nX < 0)
+ nX = 0;
+ if (nY < 0)
+ nY = 0;
+
+ SetSize( nX
+ ,nY
+ ,nWidth
+ ,nHeight
+ );
+ return TRUE;
+} // end of wxToolBar::Create
+
+wxToolBar::~wxToolBar()
+{
+ if (m_pToolTip)
+ {
+ delete m_pToolTip;
+ m_pToolTip = NULL;
+ }
+} // end of wxToolBar::~wxToolBar
+
+bool wxToolBar::Realize()
+{
+ int nMaxToolWidth = 0;
+ int nMaxToolHeight = 0;
+ int nX;
+ int nY;
+
+ m_nCurrentRowsOrColumns = 0;
+ m_vLastX = m_xMargin;
+ m_vLastY = m_yMargin;
+ m_vMaxWidth = 0;
+ m_vMaxHeight = 0;
+
+
+ //
+ // Find the maximum tool width and height
+ //
+ wxToolBarToolsList::Node* pNode = m_tools.GetFirst();
+
+ while (pNode )
+ {
+ wxToolBarTool* pTool = (wxToolBarTool *)pNode->GetData();
+
+ if (HasFlag(wxTB_TEXT) && !pTool->GetLabel().IsEmpty())
+ {
+ //
+ // Set the height according to the font and the border size
+ //
+ if (pTool->GetWidth() > m_vTextX)
+ nMaxToolWidth = pTool->GetWidth() + 4;
+ else
+ nMaxToolWidth = m_vTextX;
+ if (pTool->GetHeight() + m_vTextY > nMaxToolHeight)
+ nMaxToolHeight = pTool->GetHeight() + m_vTextY;
+ }
+ else
+ {
+ if (pTool->GetWidth() > nMaxToolWidth )
+ nMaxToolWidth = pTool->GetWidth() + 4;
+ if (pTool->GetHeight() > nMaxToolHeight)
+ nMaxToolHeight = pTool->GetHeight();
+ }
+ pNode = pNode->GetNext();
+ }
+
+ wxCoord vTbWidth = 0L;
+ wxCoord vTbHeight = 0L;
+
+ GetSize( &vTbWidth
+ ,&vTbHeight
+ );
+ if (vTbHeight < nMaxToolHeight)
+ {
+ SetSize( -1L
+ ,-1L
+ ,vTbWidth
+ ,nMaxToolHeight + 4
+ );
+ if (GetParent()->IsKindOf(CLASSINFO(wxFrame)))
+ {
+ wxFrame* pFrame = wxDynamicCast(GetParent(), wxFrame);
+
+ if (pFrame)
+ pFrame->PositionToolBar();
+ }
+ }
+
+ int nSeparatorSize = m_toolSeparation;
+
+ pNode = m_tools.GetFirst();
+ while (pNode)
+ {
+ wxToolBarTool* pTool = (wxToolBarTool *)pNode->GetData();
+
+ if (pTool->IsSeparator())
+ {
+ if (GetWindowStyleFlag() & wxTB_HORIZONTAL)
+ {
+ pTool->m_vX = m_vLastX + nSeparatorSize;
+ pTool->m_vHeight = m_defaultHeight + m_vTextY;
+ if (m_nCurrentRowsOrColumns >= m_maxCols)
+ m_vLastY += nSeparatorSize;
+ else
+ m_vLastX += nSeparatorSize * 4;
+ }
+ else
+ {
+ pTool->m_vY = m_vLastY + nSeparatorSize;
+ pTool->m_vHeight = m_defaultHeight + m_vTextY;
+ if (m_nCurrentRowsOrColumns >= m_maxRows)
+ m_vLastX += nSeparatorSize;
+ else
+ m_vLastY += nSeparatorSize * 4;
+ }
+ }
+ else if (pTool->IsButton())
+ {
+ if (GetWindowStyleFlag() & wxTB_HORIZONTAL)
+ {
+ if (m_nCurrentRowsOrColumns >= m_maxCols)
+ {
+ m_nCurrentRowsOrColumns = 0;
+ m_vLastX = m_xMargin;
+ m_vLastY += nMaxToolHeight + m_toolPacking;
+ }
+ pTool->m_vX = m_vLastX + (nMaxToolWidth - ((int)(nMaxToolWidth/2) + (int)(pTool->GetWidth()/2)));
+ if (HasFlag(wxTB_TEXT))
+ pTool->m_vY = m_vLastY + nSeparatorSize - 2; // just bit of adjustment
+ else
+ pTool->m_vY = m_vLastY + (nMaxToolHeight - (int)(pTool->GetHeight()/2));
+ m_vLastX += nMaxToolWidth + m_toolPacking + m_toolSeparation;
+ }
+ else
+ {
+ if (m_nCurrentRowsOrColumns >= m_maxRows)
+ {
+ m_nCurrentRowsOrColumns = 0;
+ m_vLastX += (nMaxToolWidth + m_toolPacking);
+ m_vLastY = m_yMargin;
+ }
+ pTool->m_vX = m_vLastX + pTool->GetWidth();
+ if (HasFlag(wxTB_TEXT) && !pTool->GetLabel().IsNull())
+ pTool->m_vY = m_vLastY + (nMaxToolHeight - m_vTextY) + m_toolPacking;
+ else
+ pTool->m_vY = m_vLastY + (nMaxToolHeight - (int)(pTool->GetHeight()/2));
+ m_vLastY += nMaxToolHeight + m_toolPacking + m_toolSeparation;
+ }
+ m_nCurrentRowsOrColumns++;
+ }
+ else
+ {
+ // TODO: support the controls
+ }
+
+ if (m_vLastX > m_maxWidth)
+ m_maxWidth = m_vLastX;
+ if (m_vLastY > m_maxHeight)
+ m_maxHeight = m_vLastY;
+
+ pNode = pNode->GetNext();
+ }
+
+ if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
+ m_maxWidth += nMaxToolWidth;
+ else
+ m_maxHeight += nMaxToolHeight;
+
+ m_maxWidth += m_xMargin;
+ m_maxHeight += m_yMargin;
+ m_bInitialized = TRUE;
+ return TRUE;
+} // end of wxToolBar::Realize
+
+// ----------------------------------------------------------------------------
+// event handlers
+// ----------------------------------------------------------------------------