]> git.saurik.com Git - wxWidgets.git/commitdiff
Generate wxPropertyGrid splitter (column divider) events: wxEVT_PG_COL_BEGIN_DRAG...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 12 Dec 2009 09:38:10 +0000 (09:38 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 12 Dec 2009 09:38:10 +0000 (09:38 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62861 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/propgrid.h
interface/wx/propgrid/propgrid.h
samples/propgrid/propgrid.cpp
samples/propgrid/propgrid.h
src/propgrid/propgrid.cpp

index aa8b8f169cf97feb3cabd197c033a0a52554d95d..2cd2d51d7b862d9d99c30eaf42b4bcd205d29bda 100644 (file)
@@ -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.
         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
     @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 );
                           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 {
 
 #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_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
 
     };
 #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_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 )
 
 #define wxPropertyGridEventHandler(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
     {
index d206fa37f0d685a7d477671bcffff3ce674b5cbf..7ff8e486379366a84f140e095e589129c333bf0e 100644 (file)
@@ -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.
         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
     @endEventTable
 
     @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
         which event occurred. Useful when you have nested properties with
     /**
         Returns highest level non-category, non-root parent of property for
         which event occurred. Useful when you have nested properties with
index 251e2e5b65d09fb216664a54e76e2451605d8ef9..4e80fe3e3ca4945dae102e7c14e7a787a9b95081 100644 (file)
@@ -688,7 +688,8 @@ enum
     ID_SAVESTATE,
     ID_RESTORESTATE,
     ID_RUNMINIMAL,
     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_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 )
 
     //
     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 )
 {
 // 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") );
     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();
     menuTools2->AppendSeparator();
     menuTools2->Append(ID_CHANGEFLAGSITEMS, wxT("Change Children of FlagsProp") );
     menuTools2->AppendSeparator();
index e3c5dc5b6ad6534bbd03e148be59333d41aab64a..9ae5c9832fffd21656c78e3484f24a1e83057bb8 100644 (file)
@@ -145,6 +145,7 @@ public:
     wxMenuItem*     m_itemCatColours;
     wxMenuItem*     m_itemFreeze;
     wxMenuItem*     m_itemEnable;
     wxMenuItem*     m_itemCatColours;
     wxMenuItem*     m_itemFreeze;
     wxMenuItem*     m_itemEnable;
+    wxMenuItem*     m_itemVetoDragging;
 
     wxVariant       m_storedValues;
 
 
     wxVariant       m_storedValues;
 
@@ -233,6 +234,9 @@ public:
     void OnPropertyGridItemExpand( wxPropertyGridEvent& event );
     void OnPropertyGridLabelEditBegin( wxPropertyGridEvent& event );
     void OnPropertyGridLabelEditEnding( wxPropertyGridEvent& event );
     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 );
 
 
     void OnAbout( wxCommandEvent& event );
 
index 9a9da1c396604d1edbcd85e82a3ef14df50cc025..5d39a2e7e266b92bf7a8ac0b80567d87a873a150 100644 (file)
@@ -4350,6 +4350,9 @@ bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p,
                                 unsigned int selFlags,
                                 unsigned int column )
 {
                                 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);
     // 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);
 
                         // 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();
 
                 Update();
                 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)
         //splitterX = x;
 
         // (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;
 
         // 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_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 );
 
 // -----------------------------------------------------------------------
 
 
 // -----------------------------------------------------------------------