From 5405bfb439dcb552bd79e6f35c347498811f85ef Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sat, 12 Dec 2009 09:38:10 +0000 Subject: [PATCH] Generate wxPropertyGrid splitter (column divider) events: wxEVT_PG_COL_BEGIN_DRAG, wxEVT_PG_COL_DRAGGING, wxEVT_PG_COL_END_DRAG git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62861 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/propgrid.h | 25 +++++++++++- interface/wx/propgrid/propgrid.h | 16 ++++++++ samples/propgrid/propgrid.cpp | 40 ++++++++++++++++++- samples/propgrid/propgrid.h | 4 ++ src/propgrid/propgrid.cpp | 66 ++++++++++++++++++++++---------- 5 files changed, 128 insertions(+), 23 deletions(-) diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index aa8b8f169c..2cd2d51d7b 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -635,6 +635,15 @@ enum wxPG_KEYBOARD_ACTIONS Respond to wxEVT_PG_LABEL_EDIT_ENDING event, generated when is about to end editing of a property label. You can veto this event to prevent the action. + @event{EVT_PG_COL_BEGIN_DRAG(id, func)} + Respond to wxEVT_PG_COL_BEGIN_DRAG event, generated when user + starts resizing a column - can be vetoed. + @event{EVT_PG_COL_DRAGGING,(id, func)} + Respond to wxEVT_PG_COL_DRAGGING, event, generated when a + column resize by user is in progress. + @event{EVT_PG_COL_END_DRAG(id, func)} + Respond to wxEVT_PG_COL_END_DRAG event, generated after column + resize by user has finished. @endEventTable @remarks @@ -2115,6 +2124,12 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_LABEL_EDIT_ENDING, wxPropertyGridEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, + wxEVT_PG_COL_BEGIN_DRAG, wxPropertyGridEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, + wxEVT_PG_COL_DRAGGING, wxPropertyGridEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, + wxEVT_PG_COL_END_DRAG, wxPropertyGridEvent ); #else enum { @@ -2128,7 +2143,10 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_ITEM_EXPANDED, wxEVT_PG_DOUBLE_CLICK, wxEVT_PG_LABEL_EDIT_BEGIN, - wxEVT_PG_LABEL_EDIT_ENDING + wxEVT_PG_LABEL_EDIT_ENDING, + wxEVT_PG_COL_BEGIN_DRAG, + wxEVT_PG_COL_DRAGGING, + wxEVT_PG_COL_END_DRAG }; #endif @@ -2151,6 +2169,9 @@ typedef void (wxEvtHandler::*wxPropertyGridEventFunction)(wxPropertyGridEvent&); #define EVT_PG_ITEM_EXPANDED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_ITEM_EXPANDED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ), #define EVT_PG_LABEL_EDIT_BEGIN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_LABEL_EDIT_BEGIN, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ), #define EVT_PG_LABEL_EDIT_ENDING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_LABEL_EDIT_ENDING, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ), +#define EVT_PG_COL_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_COL_BEGIN_DRAG, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ), +#define EVT_PG_COL_DRAGGING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_COL_DRAGGING, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ), +#define EVT_PG_COL_END_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_COL_END_DRAG, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ), #define wxPropertyGridEventHandler(fn) \ wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ) @@ -2184,6 +2205,8 @@ public: /** Returns the column index associated with this event. + For the column dragging events, it is the column to the left + of the splitter being dragged */ unsigned int GetColumn() const { diff --git a/interface/wx/propgrid/propgrid.h b/interface/wx/propgrid/propgrid.h index d206fa37f0..7ff8e48637 100644 --- a/interface/wx/propgrid/propgrid.h +++ b/interface/wx/propgrid/propgrid.h @@ -392,6 +392,15 @@ typedef int (*wxPGSortCallback)(wxPropertyGrid* propGrid, Respond to wxEVT_PG_LABEL_EDIT_ENDING event, generated when is about to end editing of a property label. You can veto this event to prevent the action. + @event{EVT_PG_COL_BEGIN_DRAG(id, func)} + Respond to wxEVT_PG_COL_BEGIN_DRAG event, generated when user + starts resizing a column - can be vetoed. + @event{EVT_PG_COL_DRAGGING,(id, func)} + Respond to wxEVT_PG_COL_DRAGGING, event, generated when a + column resize by user is in progress. + @event{EVT_PG_COL_END_DRAG(id, func)} + Respond to wxEVT_PG_COL_END_DRAG event, generated after column + resize by user has finished. @endEventTable @remarks @@ -1055,6 +1064,13 @@ public: */ bool CanVeto() const; + /** + Returns the column index associated with this event. + For the column dragging events, it is the column to the left + of the splitter being dragged + */ + unsigned int GetColumn() const; + /** Returns highest level non-category, non-root parent of property for which event occurred. Useful when you have nested properties with diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index 251e2e5b65..4e80fe3e3c 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -688,7 +688,8 @@ enum ID_SAVESTATE, ID_RESTORESTATE, ID_RUNMINIMAL, - ID_ENABLELABELEDITING + ID_ENABLELABELEDITING, + ID_VETOCOLDRAG }; // ----------------------------------------------------------------------- @@ -726,6 +727,10 @@ BEGIN_EVENT_TABLE(FormMain, wxFrame) EVT_PG_ITEM_COLLAPSED( PGID, FormMain::OnPropertyGridItemCollapse ) EVT_PG_ITEM_EXPANDED( PGID, FormMain::OnPropertyGridItemExpand ) + EVT_PG_COL_BEGIN_DRAG( PGID, FormMain::OnPropertyGridColBeginDrag ) + EVT_PG_COL_DRAGGING( PGID, FormMain::OnPropertyGridColDragging ) + EVT_PG_COL_END_DRAG( PGID, FormMain::OnPropertyGridColEndDrag ) + EVT_TEXT( PGID, FormMain::OnPropertyGridTextUpdate ) // @@ -1128,6 +1133,36 @@ void FormMain::OnPropertyGridItemExpand( wxPropertyGridEvent& ) // ----------------------------------------------------------------------- +void FormMain::OnPropertyGridColBeginDrag( wxPropertyGridEvent& event ) +{ + if ( m_itemVetoDragging->IsChecked() ) + { + wxLogDebug("Splitter %i resize was vetoed", event.GetColumn()); + event.Veto(); + } + else + { + wxLogDebug("Splitter %i resize began", event.GetColumn()); + } +} + +// ----------------------------------------------------------------------- + +void FormMain::OnPropertyGridColDragging( wxPropertyGridEvent& event ) +{ + // For now, let's not spam the log output + //wxLogDebug("Splitter %i is being resized", event.GetColumn()); +} + +// ----------------------------------------------------------------------- + +void FormMain::OnPropertyGridColEndDrag( wxPropertyGridEvent& event ) +{ + wxLogDebug("Splitter %i resize ended", event.GetColumn()); +} + +// ----------------------------------------------------------------------- + // EVT_TEXT handling void FormMain::OnPropertyGridTextUpdate( wxCommandEvent& event ) { @@ -2248,6 +2283,9 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size menuTools2->Append(ID_REMOVEPAGE, wxT("Remove Page") ); menuTools2->AppendSeparator(); menuTools2->Append(ID_FITCOLUMNS, wxT("Fit Columns") ); + m_itemVetoDragging = + menuTools2->AppendCheckItem(ID_VETOCOLDRAG, + "Veto Column Dragging"); menuTools2->AppendSeparator(); menuTools2->Append(ID_CHANGEFLAGSITEMS, wxT("Change Children of FlagsProp") ); menuTools2->AppendSeparator(); diff --git a/samples/propgrid/propgrid.h b/samples/propgrid/propgrid.h index e3c5dc5b6a..9ae5c9832f 100644 --- a/samples/propgrid/propgrid.h +++ b/samples/propgrid/propgrid.h @@ -145,6 +145,7 @@ public: wxMenuItem* m_itemCatColours; wxMenuItem* m_itemFreeze; wxMenuItem* m_itemEnable; + wxMenuItem* m_itemVetoDragging; wxVariant m_storedValues; @@ -233,6 +234,9 @@ public: void OnPropertyGridItemExpand( wxPropertyGridEvent& event ); void OnPropertyGridLabelEditBegin( wxPropertyGridEvent& event ); void OnPropertyGridLabelEditEnding( wxPropertyGridEvent& event ); + void OnPropertyGridColBeginDrag( wxPropertyGridEvent& event ); + void OnPropertyGridColDragging( wxPropertyGridEvent& event ); + void OnPropertyGridColEndDrag( wxPropertyGridEvent& event ); void OnAbout( wxCommandEvent& event ); diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 9a9da1c396..5d39a2e7e2 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -4350,6 +4350,9 @@ bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p, unsigned int selFlags, unsigned int column ) { + // selFlags should have wxPG_SEL_NOVALIDATE if event is not + // vetoable. + // Send property grid event of specific type and with specific property wxPropertyGridEvent evt( eventType, m_eventObject->GetId() ); evt.SetPropertyGrid(this); @@ -4484,33 +4487,39 @@ bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &even // send event DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE); - if ( m_wndEditor ) + // Allow application to veto dragging + if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG, + p, NULL, 0, + (unsigned int)splitterHit) ) { - // Changes must be committed here or the - // value won't be drawn correctly - if ( !CommitChangesFromEditor() ) - return res; + if ( m_wndEditor ) + { + // Changes must be committed here or the + // value won't be drawn correctly + if ( !CommitChangesFromEditor() ) + return res; - m_wndEditor->Show ( false ); - } + m_wndEditor->Show ( false ); + } - if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) - { - CaptureMouse(); - m_iFlags |= wxPG_FL_MOUSE_CAPTURED; - } + if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) + { + CaptureMouse(); + m_iFlags |= wxPG_FL_MOUSE_CAPTURED; + } - m_dragStatus = 1; - m_draggedSplitter = splitterHit; - m_dragOffset = splitterHitOffset; + m_dragStatus = 1; + m_draggedSplitter = splitterHit; + m_dragOffset = splitterHitOffset; - #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT - // Fixes button disappearance bug - if ( m_wndEditor2 ) - m_wndEditor2->Show ( false ); - #endif + #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT + // Fixes button disappearance bug + if ( m_wndEditor2 ) + m_wndEditor2->Show ( false ); + #endif - m_startingSplitterX = x - splitterHitOffset; + m_startingSplitterX = x - splitterHitOffset; + } } } } @@ -4652,6 +4661,12 @@ bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y, Update(); Refresh(); + + SendEvent(wxEVT_PG_COL_DRAGGING, + m_propHover, + NULL, + wxPG_SEL_NOVALIDATE, + (unsigned int)m_draggedSplitter); } m_dragStatus = 2; @@ -4869,6 +4884,12 @@ bool wxPropertyGrid::HandleMouseUp( int x, unsigned int WXUNUSED(y), // (it is only here as a reminder to not to do it) //splitterX = x; + SendEvent(wxEVT_PG_COL_END_DRAG, + m_propHover, + NULL, + wxPG_SEL_NOVALIDATE, + (unsigned int)m_draggedSplitter); + // Disable splitter auto-centering state->m_dontCenterSplitter = true; @@ -5787,6 +5808,9 @@ wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED, wxPropertyGridEvent ); wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEvent ); wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent ); wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING, wxPropertyGridEvent ); +wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG, wxPropertyGridEvent ); +wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING, wxPropertyGridEvent ); +wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG, wxPropertyGridEvent ); // ----------------------------------------------------------------------- -- 2.47.2