]> git.saurik.com Git - wxWidgets.git/commitdiff
* Fixed wxToolbar95 and wxToolbarGTK to emit TOOL_ENTER event with id==-1 when the...
authorMattia Barbon <mbarbon@cpan.org>
Sun, 23 Sep 2001 15:38:01 +0000 (15:38 +0000)
committerMattia Barbon <mbarbon@cpan.org>
Sun, 23 Sep 2001 15:38:01 +0000 (15:38 +0000)
  leaves a tool.
* Fixed wxToolbar95::FindToolForPosition to take into account dummy spacers inserted
  together with a control for comctl32.dll versions < 4.71

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11676 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/tbar95.h
src/gtk/tbargtk.cpp
src/gtk1/tbargtk.cpp
src/msw/tbar95.cpp

index 50bcf72eb2f336df71e972e536eb2837913cead1..9bdf0109c5eb6c9cfb3064f0c619c6ab06aa455d 100644 (file)
@@ -99,6 +99,9 @@ protected:
     // the total number of toolbar elements
     size_t m_nButtons;
 
+    // the tool the cursor is in
+    wxToolBarToolBase *m_pInTool;
+
 private:
     DECLARE_EVENT_TABLE()
     DECLARE_DYNAMIC_CLASS(wxToolBar)
index b78ce9d916df3e24127b852c73763c2b784f4536..e0e94b95f49cd8cccb317f14e5a71990ec2abd21 100644 (file)
@@ -128,12 +128,12 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
 }
 
 //-----------------------------------------------------------------------------
-// "enter_notify_event"
+// "enter_notify_event" / "leave_notify_event"
 //-----------------------------------------------------------------------------
 
-static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), 
-                                        GdkEventCrossing *WXUNUSED(gdk_event),
-                                        wxToolBarTool *tool )
+static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget), 
+                                       GdkEventCrossing *gdk_event,
+                                       wxToolBarTool *tool )
 {
     if (g_isIdle) wxapp_install_idle_handler();
 
@@ -142,7 +142,10 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
     wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
     
     // emit the event
-    tb->OnMouseEnter( tool->GetId() );
+    if( gdk_event->type == GDK_ENTER_NOTIFY )
+        tb->OnMouseEnter( tool->GetId() );
+    else
+        tb->OnMouseEnter( -1 );
   
     return FALSE;
 }
@@ -349,7 +352,11 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
 
             gtk_signal_connect( GTK_OBJECT(tool->m_item),
                                 "enter_notify_event", 
-                                GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback),
+                                GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback),
+                                (gpointer)tool );
+            gtk_signal_connect( GTK_OBJECT(tool->m_item),
+                                "leave_notify_event", 
+                                GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback),
                                 (gpointer)tool );
             break;
 
index b78ce9d916df3e24127b852c73763c2b784f4536..e0e94b95f49cd8cccb317f14e5a71990ec2abd21 100644 (file)
@@ -128,12 +128,12 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
 }
 
 //-----------------------------------------------------------------------------
-// "enter_notify_event"
+// "enter_notify_event" / "leave_notify_event"
 //-----------------------------------------------------------------------------
 
-static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), 
-                                        GdkEventCrossing *WXUNUSED(gdk_event),
-                                        wxToolBarTool *tool )
+static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget), 
+                                       GdkEventCrossing *gdk_event,
+                                       wxToolBarTool *tool )
 {
     if (g_isIdle) wxapp_install_idle_handler();
 
@@ -142,7 +142,10 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
     wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
     
     // emit the event
-    tb->OnMouseEnter( tool->GetId() );
+    if( gdk_event->type == GDK_ENTER_NOTIFY )
+        tb->OnMouseEnter( tool->GetId() );
+    else
+        tb->OnMouseEnter( -1 );
   
     return FALSE;
 }
@@ -349,7 +352,11 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
 
             gtk_signal_connect( GTK_OBJECT(tool->m_item),
                                 "enter_notify_event", 
-                                GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback),
+                                GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback),
+                                (gpointer)tool );
+            gtk_signal_connect( GTK_OBJECT(tool->m_item),
+                                "leave_notify_event", 
+                                GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback),
                                 (gpointer)tool );
             break;
 
index f1ed7ca012dbc8808beba69bc7d6825cff8adfa2..46ab1c4fe25744aae16976962088527fd54fa044 100644 (file)
@@ -815,9 +815,6 @@ bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl),
         }
     }
 
-    // For backward compatibility...
-    OnMouseEnter(tool->GetId());
-
     return TRUE;
 }
 
@@ -872,6 +869,25 @@ wxSize wxToolBar::GetToolSize() const
     }
 }
 
+static wxToolBarToolBase *GetItemSkippingDummySpacers( const wxToolBarToolsList& tools, size_t index )
+{
+    wxToolBarToolsList::Node* current = tools.GetFirst();
+
+    for( ; current != 0; current = current->GetNext() )
+    {
+        if( index == 0 )
+            return current->GetData();
+        size_t separators = ((wxToolBarTool*)current->GetData())->GetSeparatorsCount();
+        // if it is a normal button, sepcount == 0, so skip 1
+        // item ( the button )
+        // otherwise, skip as many items as the separator count,
+        // plus the control itself
+        index -= separators ? separators + 1: 1;
+    }
+
+    return 0;
+}
+
 wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
 {
     POINT pt;
@@ -884,7 +900,20 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
         return (wxToolBarToolBase *)NULL;
     }
 
-    return m_tools.Item((size_t)index)->GetData();
+    // if comctl32 version < 4.71
+    // wxToolBar95 adds dummy spacers
+#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
+    if ( wxTheApp->GetComCtl32Version() >= 471 )
+    {
+        return m_tools.Item((size_t)index)->GetData();
+    }
+    else
+    {
+        return GetItemSkippingDummySpacers( m_tools, (size_t) index );
+    }
+#else
+    return GetItemSkippingDummySpacers( m_tools, (size_t) index );
+#endif
 }
 
 void wxToolBar::UpdateSize()
@@ -1002,6 +1031,28 @@ long wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
             return 0;
         }
     }
+    else if ( nMsg == WM_MOUSEMOVE )
+    {
+        wxCoord x = GET_X_LPARAM(lParam), y = GET_Y_LPARAM(lParam);
+        wxToolBarToolBase* tool = FindToolForPosition( x, y );
+
+        // cursor left current tool
+        if( tool != m_pInTool && !tool )
+        {
+            m_pInTool = 0;
+            OnMouseEnter( -1 );
+        }
+
+        // cursor entered a tool
+        if( tool != m_pInTool && tool )
+        {
+            m_pInTool = tool;
+            OnMouseEnter( tool->GetId() );
+        }
+
+        // we don't handle mouse moves, so fall through
+        // to wxControl::MSWWindowProc
+    }
 
     return wxControl::MSWWindowProc(nMsg, wParam, lParam);
 }