X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dda4f6c089cd8db779cd10904be3263c72d98700..6b707fc394b2601878996dc7581c6d7427f8f4dd:/src/univ/toolbar.cpp diff --git a/src/univ/toolbar.cpp b/src/univ/toolbar.cpp index 8f77a0470e..74ff8b55e0 100644 --- a/src/univ/toolbar.cpp +++ b/src/univ/toolbar.cpp @@ -18,7 +18,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "univtoolbar.h" #endif @@ -38,6 +38,7 @@ #include "wx/univ/renderer.h" +#include "wx/frame.h" #include "wx/toolbar.h" #include "wx/image.h" #include "wx/log.h" @@ -71,6 +72,24 @@ public: // no position yet m_x = m_y = -1; + m_width = + m_height = 0; + + // not pressed yet + m_isInverted = FALSE; + + // mouse not here yet + m_underMouse = FALSE; + } + + wxToolBarTool(wxToolBar *tbar, wxControl *control) + : wxToolBarToolBase(tbar, control) + { + // no position yet + m_x = + m_y = -1; + m_width = + m_height = 0; // not pressed yet m_isInverted = FALSE; @@ -95,9 +114,11 @@ public: bool IsUnderMouse() { return m_underMouse; } public: - // the tool position (the size is known by the toolbar itself) - int m_x, - m_y; + // the tool position (for controls) + wxCoord m_x; + wxCoord m_y; + wxCoord m_width; + wxCoord m_height; private: // TRUE if the tool is pressed @@ -190,7 +211,7 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const return NULL; } - for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); node; node = node->GetNext() ) { @@ -329,9 +350,7 @@ wxToolBarToolBase *wxToolBar::CreateTool(int id, wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) { - wxFAIL_MSG( wxT("Toolbar doesn't support controls yet (TODO)") ); - - return NULL; + return new wxToolBarTool(this, control); } // ---------------------------------------------------------------------------- @@ -357,13 +376,39 @@ wxRect wxToolBar::GetToolRect(wxToolBarToolBase *toolBase) const if ( IsVertical() ) { - rect.width = m_defaultWidth; - rect.height = tool->IsSeparator() ? m_widthSeparator : m_defaultHeight; + if (tool->IsButton()) + { + rect.width = m_defaultWidth; + rect.height = m_defaultHeight; + } + else if (tool->IsSeparator()) + { + rect.width = m_defaultWidth; + rect.height = m_widthSeparator; + } + else // control + { + rect.width = tool->m_width; + rect.height = tool->m_height; + } } else // horizontal { - rect.width = tool->IsSeparator() ? m_widthSeparator : m_defaultWidth; - rect.height = m_defaultHeight; + if (tool->IsButton()) + { + rect.width = m_defaultWidth; + rect.height = m_defaultHeight; + } + else if (tool->IsSeparator()) + { + rect.width = m_widthSeparator; + rect.height = m_defaultHeight; + } + else // control + { + rect.width = tool->m_width; + rect.height = tool->m_height; + } } rect.width += 2*m_xMargin; @@ -399,7 +444,7 @@ void wxToolBar::DoLayout() *pCur = IsVertical() ? &y : &x; // calculate the positions of all elements - for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); node; node = node->GetNext() ) { @@ -409,7 +454,25 @@ void wxToolBar::DoLayout() tool->m_y = y; // TODO ugly number fiddling - *pCur += ( tool->IsSeparator() ? m_widthSeparator : (widthTool+2) ) + margin; + if (tool->IsButton()) + { + *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 @@ -505,7 +568,7 @@ void wxToolBar::DoDraw(wxControlRenderer *renderer) GetRectLimits(rectUpdate, &start, &end); // and redraw all the tools intersecting it - for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); node; node = node->GetNext() ) { @@ -561,7 +624,15 @@ void wxToolBar::DoDraw(wxControlRenderer *renderer) } //else: leave both the label and the bitmap invalid to draw a separator - rend->DrawToolBarButton(dc, label, bitmap, rectTool, flags); + if ( !tool->IsControl() ) + { + rend->DrawToolBarButton(dc, label, bitmap, rectTool, flags, tool->GetStyle()); + } + else // control + { + wxControl *control = tool->GetControl(); + control->Move(tool->m_x, tool->m_y); + } } } @@ -574,6 +645,8 @@ bool wxToolBar::PerformAction(const wxControlAction& action, const wxString& strArg) { wxToolBarTool *tool = (wxToolBarTool*) FindById(numArg); + if (!tool) + return false; if ( action == wxACTION_TOOLBAR_TOGGLE ) { @@ -778,9 +851,9 @@ bool wxStdToolbarInputHandler::HandleMouseMove(wxInputConsumer *consumer, } bool wxStdToolbarInputHandler::HandleFocus(wxInputConsumer *consumer, - const wxFocusEvent& event) + const wxFocusEvent& WXUNUSED(event)) { - if (m_toolCapture) + if ( m_toolCapture ) { // We shouldn't be left with a highlighted button consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolCapture->GetId() );