From 4a07d70634487aab233f004be2c814cea7e57803 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 13 Jul 2010 12:38:00 +0000 Subject: [PATCH] Send right and double click events in wxGrid when using native header. Previously only simple left click event was sent in this case, now also generate right and double click ones. Closes #12156. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64937 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/generic/private/grid.h | 41 ++++++++++++++++++++++++++----- interface/wx/grid.h | 16 +++++++++--- src/generic/grid.cpp | 2 ++ 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 7c1ce7790b..beee8bcbfe 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -532,6 +532,7 @@ All (GUI): - wxAUI: update floating window position and not only size on resize (MacGyver). - Added wxComboCtrl::SetTextCtrlStyle(). - Also update client data in wxRearrangeList control (John Roberts). +- Generate more click events in wxGrid when using native header (John Roberts). GTK: diff --git a/include/wx/generic/private/grid.h b/include/wx/generic/private/grid.h index 4718828012..2f3099d07e 100644 --- a/include/wx/generic/private/grid.h +++ b/include/wx/generic/private/grid.h @@ -158,6 +158,15 @@ protected: private: wxGrid *GetOwner() const { return static_cast(GetParent()); } + static wxMouseEvent GetDummyMouseEvent() + { + // make up a dummy event for the grid event to use -- unfortunately we + // can't do anything else here + wxMouseEvent e; + e.SetState(wxGetMouseState()); + return e; + } + // override the base class method to update our m_columns array virtual void OnColumnCountChanging(unsigned int count) { @@ -195,12 +204,8 @@ private: // as this is done by the user we should notify the main program about // it - - // make up a dummy event for the grid event to use -- unfortunately we - // can't do anything else here - wxMouseEvent e; - e.SetState(wxGetMouseState()); - GetOwner()->SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, idx, e); + GetOwner()->SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, idx, + GetDummyMouseEvent()); } // overridden to react to the columns order changes in the customization @@ -214,9 +219,33 @@ private: // event handlers forwarding wxHeaderCtrl events to wxGrid void OnClick(wxHeaderCtrlEvent& event) { + GetOwner()->SendEvent(wxEVT_GRID_LABEL_LEFT_CLICK, + -1, event.GetColumn(), + GetDummyMouseEvent()); + GetOwner()->DoColHeaderClick(event.GetColumn()); } + void OnDoubleClick(wxHeaderCtrlEvent& event) + { + if ( !GetOwner()->SendEvent(wxEVT_GRID_LABEL_LEFT_DCLICK, + -1, event.GetColumn(), + GetDummyMouseEvent()) ) + { + event.Skip(); + } + } + + void OnRightClick(wxHeaderCtrlEvent& event) + { + if ( !GetOwner()->SendEvent(wxEVT_GRID_LABEL_RIGHT_CLICK, + -1, event.GetColumn(), + GetDummyMouseEvent()) ) + { + event.Skip(); + } + } + void OnBeginResize(wxHeaderCtrlEvent& event) { GetOwner()->DoStartResizeCol(event.GetColumn()); diff --git a/interface/wx/grid.h b/interface/wx/grid.h index fb68f5dcc8..efca1460b8 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -2022,10 +2022,18 @@ public: are using the grid to display tabular data and don't have thousands of columns in it. - Also note that currently @c wxEVT_GRID_LABEL_LEFT_DCLICK and - @c wxEVT_GRID_LABEL_RIGHT_DCLICK events are not generated for the column - labels if the native columns header is used (but this limitation could - possibly be lifted in the future). + Another difference between the default behaviour and the native header + behaviour is that the latter provides the user with a context menu + (which appears on right clicking the header) allowing to rearrange the + grid columns if CanDragColMove() returns @true. If you want to prevent + this from happening for some reason, you need to define a handler for + @c wxEVT_GRID_LABEL_RIGHT_CLICK event which simply does nothing (in + particular doesn't skip the event) as this will prevent the default + right click handling from working. + + Also note that currently @c wxEVT_GRID_LABEL_RIGHT_DCLICK event is not + generated for the column labels if the native columns header is used + (but this limitation could possibly be lifted in the future). */ void UseNativeColHeader(bool native = true); diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index edb709d706..0968444786 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -170,6 +170,8 @@ END_EVENT_TABLE() BEGIN_EVENT_TABLE(wxGridHeaderCtrl, wxHeaderCtrl) EVT_HEADER_CLICK(wxID_ANY, wxGridHeaderCtrl::OnClick) + EVT_HEADER_DCLICK(wxID_ANY, wxGridHeaderCtrl::OnDoubleClick) + EVT_HEADER_RIGHT_CLICK(wxID_ANY, wxGridHeaderCtrl::OnRightClick) EVT_HEADER_BEGIN_RESIZE(wxID_ANY, wxGridHeaderCtrl::OnBeginResize) EVT_HEADER_RESIZING(wxID_ANY, wxGridHeaderCtrl::OnResizing) -- 2.45.2