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
This commit is contained in:
Jaakko Salli
2009-12-12 09:38:10 +00:00
parent 9dac189e72
commit 5405bfb439
5 changed files with 131 additions and 26 deletions

View File

@@ -635,6 +635,15 @@ enum wxPG_KEYBOARD_ACTIONS
Respond to wxEVT_PG_LABEL_EDIT_ENDING event, generated when is about to 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 end editing of a property label. You can veto this event to prevent the
action. 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 @endEventTable
@remarks @remarks
@@ -2115,6 +2124,12 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent ); wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
wxEVT_PG_LABEL_EDIT_ENDING, wxPropertyGridEvent ); 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 #else
enum { enum {
@@ -2128,7 +2143,10 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
wxEVT_PG_ITEM_EXPANDED, wxEVT_PG_ITEM_EXPANDED,
wxEVT_PG_DOUBLE_CLICK, wxEVT_PG_DOUBLE_CLICK,
wxEVT_PG_LABEL_EDIT_BEGIN, 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 #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_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_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_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) \ #define wxPropertyGridEventHandler(fn) \
wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ) wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn )
@@ -2184,6 +2205,8 @@ public:
/** /**
Returns the column index associated with this event. 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 unsigned int GetColumn() const
{ {

View File

@@ -392,6 +392,15 @@ typedef int (*wxPGSortCallback)(wxPropertyGrid* propGrid,
Respond to wxEVT_PG_LABEL_EDIT_ENDING event, generated when is about to 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 end editing of a property label. You can veto this event to prevent the
action. 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 @endEventTable
@remarks @remarks
@@ -1055,6 +1064,13 @@ public:
*/ */
bool CanVeto() const; 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 Returns highest level non-category, non-root parent of property for
which event occurred. Useful when you have nested properties with which event occurred. Useful when you have nested properties with

View File

@@ -688,7 +688,8 @@ enum
ID_SAVESTATE, ID_SAVESTATE,
ID_RESTORESTATE, ID_RESTORESTATE,
ID_RUNMINIMAL, 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_COLLAPSED( PGID, FormMain::OnPropertyGridItemCollapse )
EVT_PG_ITEM_EXPANDED( PGID, FormMain::OnPropertyGridItemExpand ) 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 ) 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 // EVT_TEXT handling
void FormMain::OnPropertyGridTextUpdate( wxCommandEvent& event ) 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->Append(ID_REMOVEPAGE, wxT("Remove Page") );
menuTools2->AppendSeparator(); menuTools2->AppendSeparator();
menuTools2->Append(ID_FITCOLUMNS, wxT("Fit Columns") ); menuTools2->Append(ID_FITCOLUMNS, wxT("Fit Columns") );
m_itemVetoDragging =
menuTools2->AppendCheckItem(ID_VETOCOLDRAG,
"Veto Column Dragging");
menuTools2->AppendSeparator(); menuTools2->AppendSeparator();
menuTools2->Append(ID_CHANGEFLAGSITEMS, wxT("Change Children of FlagsProp") ); menuTools2->Append(ID_CHANGEFLAGSITEMS, wxT("Change Children of FlagsProp") );
menuTools2->AppendSeparator(); menuTools2->AppendSeparator();

View File

@@ -145,6 +145,7 @@ public:
wxMenuItem* m_itemCatColours; wxMenuItem* m_itemCatColours;
wxMenuItem* m_itemFreeze; wxMenuItem* m_itemFreeze;
wxMenuItem* m_itemEnable; wxMenuItem* m_itemEnable;
wxMenuItem* m_itemVetoDragging;
wxVariant m_storedValues; wxVariant m_storedValues;
@@ -233,6 +234,9 @@ public:
void OnPropertyGridItemExpand( wxPropertyGridEvent& event ); void OnPropertyGridItemExpand( wxPropertyGridEvent& event );
void OnPropertyGridLabelEditBegin( wxPropertyGridEvent& event ); void OnPropertyGridLabelEditBegin( wxPropertyGridEvent& event );
void OnPropertyGridLabelEditEnding( wxPropertyGridEvent& event ); void OnPropertyGridLabelEditEnding( wxPropertyGridEvent& event );
void OnPropertyGridColBeginDrag( wxPropertyGridEvent& event );
void OnPropertyGridColDragging( wxPropertyGridEvent& event );
void OnPropertyGridColEndDrag( wxPropertyGridEvent& event );
void OnAbout( wxCommandEvent& event ); void OnAbout( wxCommandEvent& event );

View File

@@ -4350,6 +4350,9 @@ bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p,
unsigned int selFlags, unsigned int selFlags,
unsigned int column ) 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 // Send property grid event of specific type and with specific property
wxPropertyGridEvent evt( eventType, m_eventObject->GetId() ); wxPropertyGridEvent evt( eventType, m_eventObject->GetId() );
evt.SetPropertyGrid(this); evt.SetPropertyGrid(this);
@@ -4484,6 +4487,11 @@ bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &even
// send event // send event
DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE); DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE);
// Allow application to veto dragging
if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG,
p, NULL, 0,
(unsigned int)splitterHit) )
{
if ( m_wndEditor ) if ( m_wndEditor )
{ {
// Changes must be committed here or the // Changes must be committed here or the
@@ -4515,6 +4523,7 @@ bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &even
} }
} }
} }
}
else else
{ {
// Click on margin. // Click on margin.
@@ -4652,6 +4661,12 @@ bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y,
Update(); Update();
Refresh(); Refresh();
SendEvent(wxEVT_PG_COL_DRAGGING,
m_propHover,
NULL,
wxPG_SEL_NOVALIDATE,
(unsigned int)m_draggedSplitter);
} }
m_dragStatus = 2; 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) // (it is only here as a reminder to not to do it)
//splitterX = x; //splitterX = x;
SendEvent(wxEVT_PG_COL_END_DRAG,
m_propHover,
NULL,
wxPG_SEL_NOVALIDATE,
(unsigned int)m_draggedSplitter);
// Disable splitter auto-centering // Disable splitter auto-centering
state->m_dontCenterSplitter = true; 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_DOUBLE_CLICK, wxPropertyGridEvent );
wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent ); wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent );
wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING, 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 );
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------