]> git.saurik.com Git - wxWidgets.git/commitdiff
Send right and double click events in wxGrid when using native header.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 13 Jul 2010 12:38:00 +0000 (12:38 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 13 Jul 2010 12:38:00 +0000 (12:38 +0000)
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
include/wx/generic/private/grid.h
interface/wx/grid.h
src/generic/grid.cpp

index 7c1ce7790bc05f8515769ccdd844614becfb8911..beee8bcbfee35f3689160296b639526e6575ff68 100644 (file)
@@ -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).
 - 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:
 
 
 GTK:
 
index 4718828012fc5af10d66a43011644b329de556ce..2f3099d07ec226081650d706939ef1cda25fb18f 100644 (file)
@@ -158,6 +158,15 @@ protected:
 private:
     wxGrid *GetOwner() const { return static_cast<wxGrid *>(GetParent()); }
 
 private:
     wxGrid *GetOwner() const { return static_cast<wxGrid *>(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)
     {
     // 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
 
         // 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
     }
 
     // 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)
     {
     // 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());
     }
 
         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());
     void OnBeginResize(wxHeaderCtrlEvent& event)
     {
         GetOwner()->DoStartResizeCol(event.GetColumn());
index fb68f5dcc81d57986bb5a9d450b477e0e1056efd..efca1460b834fb27772b93fd8a3e1857a809c5ba 100644 (file)
@@ -2022,10 +2022,18 @@ public:
         are using the grid to display tabular data and don't have thousands of
         columns in it.
 
         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);
 
      */
     void UseNativeColHeader(bool native = true);
 
index edb709d70617ffdab91e7e84b4e437a7317148c0..096844478688a7c9836c293cf1955a8368d3aa78 100644 (file)
@@ -170,6 +170,8 @@ END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxGridHeaderCtrl, wxHeaderCtrl)
     EVT_HEADER_CLICK(wxID_ANY, wxGridHeaderCtrl::OnClick)
 
 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)
 
     EVT_HEADER_BEGIN_RESIZE(wxID_ANY, wxGridHeaderCtrl::OnBeginResize)
     EVT_HEADER_RESIZING(wxID_ANY, wxGridHeaderCtrl::OnResizing)