From a8945eeff6a096fed3210a3bd44e81aa895dfa61 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Sun, 23 Sep 2001 15:38:01 +0000 Subject: [PATCH] * Fixed wxToolbar95 and wxToolbarGTK to emit TOOL_ENTER event with id==-1 when the mouse 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 | 3 +++ src/gtk/tbargtk.cpp | 19 ++++++++----- src/gtk1/tbargtk.cpp | 19 ++++++++----- src/msw/tbar95.cpp | 59 ++++++++++++++++++++++++++++++++++++++--- 4 files changed, 84 insertions(+), 16 deletions(-) diff --git a/include/wx/msw/tbar95.h b/include/wx/msw/tbar95.h index 50bcf72eb2..9bdf0109c5 100644 --- a/include/wx/msw/tbar95.h +++ b/include/wx/msw/tbar95.h @@ -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) diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index b78ce9d916..e0e94b95f4 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -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; diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index b78ce9d916..e0e94b95f4 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -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; diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index f1ed7ca012..46ab1c4fe2 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -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); } -- 2.47.2