Fixed auto-resizing behavior when double-clicking a splitter; Added wxPropertyGrid::ResetColumnSizes(); wxPropertyGrid::GetSplitterPosition() got splitterIndex argument

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63502 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2010-02-16 16:24:30 +00:00
parent 4279fdb44a
commit 76733d4cae
5 changed files with 87 additions and 32 deletions

View File

@@ -736,10 +736,11 @@ 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

View 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,

View 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.

View 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,7 +5052,13 @@ bool wxPropertyGrid::HandleMouseUp( int x, unsigned int WXUNUSED(y),
wxPG_SEL_NOVALIDATE,
(unsigned int)m_draggedSplitter);
// Disable splitter auto-centering
// 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

View File

@@ -1106,22 +1106,28 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
//
// Generic re-center code
//
ResetColumnSizes(wxPG_SPLITTER_FROM_AUTO_CENTER);
}
}
}
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 = (pg->m_width*256) / psum;
int puwid = (m_pPropGrid->m_width*256) / psum;
int cpos = 0;
// 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,
wxPG_SPLITTER_FROM_AUTO_CENTER);
}
}
setSplitterFlags);
}
}