m_colWidths.push_back( wxPG_DEFAULT_SPLITTERX );
m_fSplitterX = wxPG_DEFAULT_SPLITTERX;
+ m_columnProportions.push_back(1);
+ m_columnProportions.push_back(1);
+
m_isSplitterPreSet = false;
m_dontCenterSplitter = false;
}
// Auto center splitter
- if ( !m_dontCenterSplitter && m_colWidths.size() == 2 )
+ if ( !m_dontCenterSplitter )
{
- float centerX = (float)(pg->m_width/2);
- float splitterX;
-
- if ( m_fSplitterX < 0.0 )
+ if ( m_colWidths.size() == 2 &&
+ m_columnProportions[0] == m_columnProportions[1] )
{
- splitterX = centerX;
- }
- else if ( widthChange )
- {
- //float centerX = float(pg->GetSize().x) * 0.5;
+ //
+ // When we have two columns of equal proportion, then use this
+ // code. It will look nicer when the scrollbar visibility is
+ // toggled on and off.
+ //
+ // TODO: Adapt this to generic recenter code.
+ //
+ float centerX = (float)(pg->m_width/2);
+ float splitterX;
+
+ if ( m_fSplitterX < 0.0 )
+ {
+ splitterX = centerX;
+ }
+ else if ( widthChange )
+ {
+ //float centerX = float(pg->GetSize().x) * 0.5;
- // Recenter?
- splitterX = m_fSplitterX + (float(widthChange) * 0.5);
- float deviation = fabs(centerX - splitterX);
+ // Recenter?
+ splitterX = m_fSplitterX + (float(widthChange) * 0.5);
+ float deviation = fabs(centerX - splitterX);
- // If deviating from center, adjust towards it
- if ( deviation > 20.0 )
+ // If deviating from center, adjust towards it
+ if ( deviation > 20.0 )
+ {
+ if ( splitterX > centerX)
+ splitterX -= 2;
+ else
+ splitterX += 2;
+ }
+ }
+ else
{
- if ( splitterX > centerX)
- splitterX -= 2;
- else
- splitterX += 2;
+ // No width change, just keep sure we keep splitter position intact
+ splitterX = m_fSplitterX;
+ float deviation = fabs(centerX - splitterX);
+ if ( deviation > 50.0 )
+ {
+ splitterX = centerX;
+ }
}
+
+ DoSetSplitterPosition((int)splitterX, 0,
+ wxPG_SPLITTER_FROM_AUTO_CENTER);
+
+ m_fSplitterX = splitterX; // needed to retain accuracy
}
else
{
- // No width change, just keep sure we keep splitter position intact
- splitterX = m_fSplitterX;
- float deviation = fabs(centerX - splitterX);
- if ( deviation > 50.0 )
+ //
+ // Generic re-center code
+ //
+
+ // 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;
+
+ for ( i=0; i<(m_colWidths.size() - 1); i++ )
{
- splitterX = centerX;
+ int cwid = (puwid*m_columnProportions[i]) / 256;
+ cpos += cwid;
+ DoSetSplitterPosition(cpos, i,
+ wxPG_SPLITTER_FROM_AUTO_CENTER);
}
}
-
- DoSetSplitterPosition((int)splitterX, 0,
- wxPG_SPLITTER_FROM_AUTO_CENTER);
-
- m_fSplitterX = splitterX; // needed to retain accuracy
}
}
{
wxASSERT( colCount >= 2 );
m_colWidths.SetCount( colCount, wxPG_DRAG_MARGIN );
+ m_columnProportions.SetCount( colCount, 1 );
if ( m_colWidths.size() > (unsigned int)colCount )
m_colWidths.RemoveAt( m_colWidths.size()-1,
m_colWidths.size() - colCount );
CheckColumnWidths();
}
+void wxPropertyGridPageState::DoSetColumnProportion( unsigned int column,
+ int proportion )
+{
+ wxASSERT_MSG( proportion >= 1,
+ "Column proportion must 1 or higher" );
+
+ if ( proportion < 1 )
+ proportion = 1;
+
+ while ( m_columnProportions.size() <= column )
+ m_columnProportions.push_back(1);
+
+ m_columnProportions[column] = proportion;
+}
+
// Returns column index, -1 for margin
int wxPropertyGridPageState::HitTestH( int x, int* pSplitterHit, int* pSplitterHitOffset ) const
{