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
This commit is contained in:
Vadim Zeitlin
2010-07-13 12:38:00 +00:00
parent f4ad6505da
commit 4a07d70634
4 changed files with 50 additions and 10 deletions

View 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).
- Generate more click events in wxGrid when using native header (John Roberts).
GTK:

View File

@@ -158,6 +158,15 @@ protected:
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)
{
@@ -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());

View File

@@ -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);

View File

@@ -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)