]> git.saurik.com Git - wxWidgets.git/commitdiff
Fixed auto-resizing behavior when double-clicking a splitter; Added wxPropertyGrid...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Tue, 16 Feb 2010 16:24:30 +0000 (16:24 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Tue, 16 Feb 2010 16:24:30 +0000 (16:24 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63502 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

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

index 13ff03b8b53cff75a68f8ac65ccd26b084fcda26..2d744fe7c9bad5b14345c6780ea0ee408d2999ab 100644 (file)
@@ -735,11 +735,12 @@ public:
 
     /**
         Centers the splitter.
-
-        If argument is true, automatic splitter centering is enabled (only
-        applicapple if style wxPG_SPLITTER_AUTO_CENTER was defined).
+        
+        @param enableAutoResizing
+            If @true, automatic column resizing is enabled (only applicapple
+            if window style wxPG_SPLITTER_AUTO_CENTER is used).
     */
-    void CenterSplitter( bool enable_auto_centering = false );
+    void CenterSplitter( bool enableAutoResizing = false );
 
     /** Deletes all properties.
     */
@@ -937,9 +938,13 @@ public:
     /** Returns current selection text colour. */
     wxColour GetSelectionForegroundColour() const { return m_colSelFore; }
 
-    /** Returns current splitter x position. */
-    int GetSplitterPosition() const
-        { return m_pState->DoGetSplitterPosition(0); }
+    /**
+        Returns current splitter x position.
+    */
+    int GetSplitterPosition( unsigned int splitterIndex = 0 ) const
+    {
+        return m_pState->DoGetSplitterPosition(splitterIndex);
+    }
 
     /** Returns wxTextCtrl active in currently selected property, if any. Takes
         into account wxOwnerDrawnComboBox.
@@ -1021,6 +1026,17 @@ public:
     */
     void ResetColours();
 
+    /**
+        Resets column sizes and splitter positions, based on proportions.
+
+        @param enableAutoResizing
+            If @true, automatic column resizing is enabled (only applicapple
+            if window style wxPG_SPLITTER_AUTO_CENTER is used).
+
+        @see wxPropertyGridInterface::SetColumnProportion()
+    */
+    void ResetColumnSizes( bool enableAutoResizing = false );
+
     /**
         Selects a property.
         Editor widget is automatically created, but not focused unless focus is
index d6171510d67f25d4d3679eb127659f89056b9ac3..828db8d2a04b17cb9a9efeb416f7a9ce2bf83834 100644 (file)
@@ -554,6 +554,8 @@ public:
         return m_columnProportions[column];
     }
 
+    void ResetColumnSizes( int setSplitterFlags );
+
     wxPropertyCategory* GetPropertyCategory( const wxPGProperty* p ) const;
 
     wxPGProperty* GetPropertyByLabel( const wxString& name,
index 818c14dd511bce17bbc40e7979d5c1431a1bb6f7..c7bf80a9967e9feb0acbaae07c9fa45b52316e9b 100644 (file)
@@ -503,11 +503,13 @@ public:
     bool ChangePropertyValue( wxPGPropArg id, wxVariant newValue );
 
     /**
-        Centers the splitter. If argument is true, automatic splitter centering
-        is enabled (only applicable if style wxPG_SPLITTER_AUTO_CENTER was
-        defined).
+        Centers the splitter.
+
+        @param enableAutoResizing
+            If @true, automatic column resizing is enabled (only applicapple
+            if window style wxPG_SPLITTER_AUTO_CENTER is used).
     */
-    void CenterSplitter( bool enable_auto_centering = false );
+    void CenterSplitter( bool enableAutoResizing = false );
 
     /**
         Deletes all properties.
@@ -735,7 +737,7 @@ public:
     /**
         Returns current splitter x position.
     */
-    int GetSplitterPosition() const;
+    int GetSplitterPosition( unsigned int splitterIndex = 0 ) const;
 
     /**
         Returns wxTextCtrl active in currently selected property, if any. Takes
@@ -839,6 +841,17 @@ public:
     */
     void ResetColours();
 
+    /**
+        Resets column sizes and splitter positions, based on proportions.
+
+        @param enableAutoResizing
+            If @true, automatic column resizing is enabled (only applicapple
+            if window style wxPG_SPLITTER_AUTO_CENTER is used).
+
+        @see wxPropertyGridInterface::SetColumnProportion()
+    */
+    void ResetColumnSizes( bool enableAutoResizing = false );
+
     /**
         Removes given property from selection. If property is not selected,
         an assertion failure will occur.
index 296559d4eec46af6196f2b7b174bc8913db887eb..ee5e0e92e3d7ed0e9eb7f5aa4d0b74c0f30fe389 100644 (file)
@@ -2812,10 +2812,22 @@ void wxPropertyGrid::DoSetSplitterPosition( int newxpos,
 
 // -----------------------------------------------------------------------
 
-void wxPropertyGrid::CenterSplitter( bool enableAutoCentering )
+void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing )
+{
+    wxPropertyGridPageState* state = m_pState;
+    if ( state )
+        state->ResetColumnSizes(0);
+
+    if ( enableAutoResizing && HasFlag(wxPG_SPLITTER_AUTO_CENTER) )
+        m_pState->m_dontCenterSplitter = false;
+}
+
+// -----------------------------------------------------------------------
+
+void wxPropertyGrid::CenterSplitter( bool enableAutoResizing )
 {
     SetSplitterPosition( m_width/2 );
-    if ( enableAutoCentering && HasFlag(wxPG_SPLITTER_AUTO_CENTER) )
+    if ( enableAutoResizing && HasFlag(wxPG_SPLITTER_AUTO_CENTER) )
         m_pState->m_dontCenterSplitter = false;
 }
 
@@ -4626,7 +4638,7 @@ bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &even
                         // Double-clicking the splitter causes auto-centering
                         if ( m_pState->GetColumnCount() <= 2 )
                         {
-                            CenterSplitter( true );
+                            ResetColumnSizes( true );
 
                             SendEvent(wxEVT_PG_COL_DRAGGING,
                                       m_propHover,
@@ -5040,8 +5052,14 @@ bool wxPropertyGrid::HandleMouseUp( int x, unsigned int WXUNUSED(y),
                   wxPG_SEL_NOVALIDATE,
                   (unsigned int)m_draggedSplitter);
 
-        // Disable splitter auto-centering
-        state->m_dontCenterSplitter = true;
+        // Disable splitter auto-centering (but only if moved any -
+        // otherwise we end up disabling auto-center even after a
+        // recentering double-click).
+        int posDiff = abs(m_startingSplitterX - 
+                          GetSplitterPosition(m_draggedSplitter));
+
+        if ( posDiff > 1 )
+            state->m_dontCenterSplitter = true;
 
         // This is necessary to return cursor
         if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
index 81135d64d858b5607884bdab4ffed850647e0292..cd965c51372360d3667df9b7a46665176abd5026 100644 (file)
@@ -1106,22 +1106,28 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
             //
             // Generic re-center code
             //
+            ResetColumnSizes(wxPG_SPLITTER_FROM_AUTO_CENTER);
+        }
+    }
+}
 
-            // Calculate sum of proportions
-            int psum = 0;
-            for ( i=0; i<m_colWidths.size(); i++ )
-                psum += m_columnProportions[i];
-            int puwid = (pg->m_width*256) / psum;
-            int cpos = 0;
+void wxPropertyGridPageState::ResetColumnSizes( int setSplitterFlags )
+{
+    unsigned int i;
+    // Calculate sum of proportions
+    int psum = 0;
+    for ( i=0; i<m_colWidths.size(); i++ )
+        psum += m_columnProportions[i];
+    int puwid = (m_pPropGrid->m_width*256) / psum;
+    int cpos = 0;
 
-            for ( i=0; i<(m_colWidths.size() - 1); i++ )
-            {
-                int cwid = (puwid*m_columnProportions[i]) / 256;
-                cpos += cwid;
-                DoSetSplitterPosition(cpos, i,
-                                      wxPG_SPLITTER_FROM_AUTO_CENTER);
-            }
-        }
+    // Convert proportion to splitter positions
+    for ( i=0; i<(m_colWidths.size() - 1); i++ )
+    {
+        int cwid = (puwid*m_columnProportions[i]) / 256;
+        cpos += cwid;
+        DoSetSplitterPosition(cpos, i,
+                              setSplitterFlags);
     }
 }