X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/34d26f42b16d6fb233988fec2a7fa6c8f397972d..cd318cd31b8fd9876af7ba5f4878b90f446bd0f5:/src/univ/toolbar.cpp diff --git a/src/univ/toolbar.cpp b/src/univ/toolbar.cpp index e0d4b6f169..c0eea0ba8b 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,8 +38,10 @@ #include "wx/univ/renderer.h" +#include "wx/frame.h" #include "wx/toolbar.h" #include "wx/image.h" +#include "wx/log.h" // ---------------------------------------------------------------------------- // constants @@ -70,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; @@ -94,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 @@ -155,13 +177,15 @@ bool wxToolBar::Create(wxWindow *parent, wxToolBar::~wxToolBar() { + // Make sure the toolbar is removed from the parent. + SetSize(0,0); } void wxToolBar::SetMargins(int x, int y) { // This required for similar visual effects under // native platforms and wxUniv. - wxToolBarBase::SetMargins( x + 2, y + 2 ); + wxToolBarBase::SetMargins( x + 3, y + 3 ); } // ---------------------------------------------------------------------------- @@ -187,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() ) { @@ -326,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); } // ---------------------------------------------------------------------------- @@ -354,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; @@ -396,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() ) { @@ -405,7 +453,26 @@ void wxToolBar::DoLayout() tool->m_x = x; tool->m_y = y; - *pCur += (tool->IsSeparator() ? m_widthSeparator : widthTool) + margin; + // TODO ugly number fiddling + 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 @@ -421,6 +488,39 @@ wxSize wxToolBar::DoGetBestClientSize() const return wxSize(m_maxWidth, m_maxHeight); } +void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags) +{ + int old_width, old_height; + GetSize(&old_width, &old_height); + + wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags); + + // Correct width and height if needed. + if ( width == -1 || height == -1 ) + { + int tmp_width, tmp_height; + GetSize(&tmp_width, &tmp_height); + + if ( width == -1 ) + width = tmp_width; + if ( height == -1 ) + height = tmp_height; + } + + // We must refresh the frame size when the toolbar changes size + // otherwise the toolbar can be shown incorrectly + if ( old_width != width || old_height != height ) + { + // But before we send the size event check it + // we have a frame that is not being deleted. + wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); + if ( frame && !frame->IsBeingDeleted() ) + { + frame->SendSizeEvent(); + } + } +} + // ---------------------------------------------------------------------------- // wxToolBar drawing // ---------------------------------------------------------------------------- @@ -468,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() ) { @@ -489,6 +589,12 @@ void wxToolBar::DoDraw(wxControlRenderer *renderer) break; } + if (tool->IsSeparator() && !HasFlag(wxTB_FLAT)) + { + // Draw seperators only in flat mode + continue; + } + // deal with the flags int flags = 0; @@ -518,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); + } } } @@ -632,11 +746,12 @@ bool wxStdToolbarInputHandler::HandleMouse(wxInputConsumer *consumer, if ( event.Button(1) ) { - if ( !tool || !tool->IsEnabled() ) - return TRUE; if ( event.LeftDown() || event.LeftDClick() ) { + if ( !tool || !tool->IsEnabled() ) + return TRUE; + m_winCapture = tbar; m_winCapture->CaptureMouse(); @@ -654,20 +769,17 @@ bool wxStdToolbarInputHandler::HandleMouse(wxInputConsumer *consumer, m_winCapture = NULL; } - if ( tool == m_toolCapture ) + if (m_toolCapture) { - // this will generate a click event - consumer->PerformAction( wxACTION_BUTTON_TOGGLE, tool->GetId() ); - - m_toolCapture = NULL; - - return TRUE; + if ( tool == m_toolCapture ) + consumer->PerformAction( wxACTION_BUTTON_TOGGLE, m_toolCapture->GetId() ); + else + consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolCapture->GetId() ); } - //else: the mouse was released outside the tool or in - // a different tool m_toolCapture = NULL; - + + return TRUE; } //else: don't do anything special about the double click } @@ -694,27 +806,40 @@ bool wxStdToolbarInputHandler::HandleMouseMove(wxInputConsumer *consumer, tool = (wxToolBarTool*) tbar->FindToolForPosition( event.GetX(), event.GetY() ); } - if ((tool) && (tool == m_toolLast)) + if (m_toolCapture) { - // Still over the same tool as last time - return TRUE; + // During capture we only care of the captured tool + if (tool && (tool != m_toolCapture)) + tool = NULL; + + if (tool == m_toolLast) + return TRUE; + + if (tool) + consumer->PerformAction( wxACTION_BUTTON_PRESS, m_toolCapture->GetId() ); + else + consumer->PerformAction( wxACTION_BUTTON_RELEASE, m_toolCapture->GetId() ); + + m_toolLast = tool; } - - if (m_toolLast) + else { - // Leave old tool if any - consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolLast->GetId() ); - } + if (tool == m_toolLast) + return TRUE; + + if (m_toolLast) + { + // Leave old tool if any + consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolLast->GetId() ); + } + + if (tool) + { + // Enter new tool if any + consumer->PerformAction( wxACTION_TOOLBAR_ENTER, tool->GetId() ); + } - if (m_toolCapture && (m_toolCapture != tool)) - m_toolLast = NULL; - else m_toolLast = tool; - - if (m_toolLast) - { - // Enter new tool if any - consumer->PerformAction( wxACTION_TOOLBAR_ENTER, m_toolLast->GetId() ); } return TRUE; @@ -724,9 +849,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() );