]> git.saurik.com Git - wxWidgets.git/blobdiff - src/univ/toolbar.cpp
CarbonEvents Added
[wxWidgets.git] / src / univ / toolbar.cpp
index e0d4b6f169489fd584128e622f1dc7dbb0175ab0..f8e1944a7254b5725585173c7094b52f8c177de6 100644 (file)
 
 #include "wx/univ/renderer.h"
 
+#include "wx/frame.h"
 #include "wx/toolbar.h"
 #include "wx/image.h"
+#include "wx/log.h"
 
 // ----------------------------------------------------------------------------
 // constants
@@ -155,13 +157,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 );
 }
 
 // ----------------------------------------------------------------------------
@@ -405,7 +409,8 @@ void wxToolBar::DoLayout()
         tool->m_x = x;
         tool->m_y = y;
 
-        *pCur += (tool->IsSeparator() ? m_widthSeparator : widthTool) + margin;
+        // TODO ugly number fiddling
+        *pCur += ( tool->IsSeparator() ? m_widthSeparator : (widthTool+2) ) + margin;
     }
 
     // calculate the total toolbar size
@@ -421,6 +426,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
 // ----------------------------------------------------------------------------
@@ -489,6 +527,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;
 
@@ -632,11 +676,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 +699,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 +736,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;