// 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)
}
//-----------------------------------------------------------------------------
-// "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();
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;
}
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;
}
//-----------------------------------------------------------------------------
-// "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();
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;
}
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;
}
}
- // For backward compatibility...
- OnMouseEnter(tool->GetId());
-
return TRUE;
}
}
}
+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;
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()
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);
}