Added wxPropertyGridInterface::SetColumnProportion(); wxPG_SPLITTER_AUTO_CENTER window style now supports column counts higher than two.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63481 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -878,6 +878,11 @@ wxPropertyGrid::CenterSplitter() method. <b>However, be sure to call it after
|
|||||||
the sizer setup and SetSize calls!</b> (ie. usually at the end of the
|
the sizer setup and SetSize calls!</b> (ie. usually at the end of the
|
||||||
frame/dialog constructor)
|
frame/dialog constructor)
|
||||||
|
|
||||||
|
Splitter centering behavior can be customized using
|
||||||
|
wxPropertyGridInterface::SetColumnProportion(). Usually it is used to set
|
||||||
|
non-equal column proportions, which in essence stops the splitter(s) from
|
||||||
|
being 'centered' as such, and instead just auto-resized.
|
||||||
|
|
||||||
@subsection propgrid_splittersetting Setting Splitter Position When Creating Property Grid
|
@subsection propgrid_splittersetting Setting Splitter Position When Creating Property Grid
|
||||||
|
|
||||||
Splitter position cannot exceed grid size, and therefore setting it during
|
Splitter position cannot exceed grid size, and therefore setting it during
|
||||||
|
@@ -150,8 +150,12 @@ wxPG_ALPHABETIC_MODE = (wxPG_HIDE_CATEGORIES|wxPG_AUTO_SORT),
|
|||||||
*/
|
*/
|
||||||
wxPG_BOLD_MODIFIED = 0x00000040,
|
wxPG_BOLD_MODIFIED = 0x00000040,
|
||||||
|
|
||||||
/** When wxPropertyGrid is resized, splitter moves to the center. This
|
/** Using this style, the column splitters move automatically based on column
|
||||||
behavior stops once the user manually moves the splitter.
|
proportions (default is equal proportion for every column). This behavior
|
||||||
|
stops once the user manually moves a splitter, and returns when a
|
||||||
|
splitter is double-clicked.
|
||||||
|
|
||||||
|
@see wxPropertyGridInterface::SetColumnProportion().
|
||||||
*/
|
*/
|
||||||
wxPG_SPLITTER_AUTO_CENTER = 0x00000080,
|
wxPG_SPLITTER_AUTO_CENTER = 0x00000080,
|
||||||
|
|
||||||
|
@@ -861,6 +861,18 @@ public:
|
|||||||
static void SetBoolChoices( const wxString& trueChoice,
|
static void SetBoolChoices( const wxString& trueChoice,
|
||||||
const wxString& falseChoice );
|
const wxString& falseChoice );
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set proportion of a auto-stretchable column. wxPG_SPLITTER_AUTO_CENTER
|
||||||
|
window style needs to be used to indicate that columns are auto-
|
||||||
|
resizeable.
|
||||||
|
|
||||||
|
@returns Returns @false on failure.
|
||||||
|
|
||||||
|
@remarks You should call this for individual pages of
|
||||||
|
wxPropertyGridManager (if used).
|
||||||
|
*/
|
||||||
|
bool SetColumnProportion( unsigned int column, int proportion );
|
||||||
|
|
||||||
/** Sets an attribute for this property.
|
/** Sets an attribute for this property.
|
||||||
@param name
|
@param name
|
||||||
Text identifier of attribute. See @ref propgrid_property_attributes.
|
Text identifier of attribute. See @ref propgrid_property_attributes.
|
||||||
|
@@ -547,6 +547,8 @@ public:
|
|||||||
|
|
||||||
void DoRemoveFromSelection( wxPGProperty* prop );
|
void DoRemoveFromSelection( wxPGProperty* prop );
|
||||||
|
|
||||||
|
void DoSetColumnProportion( unsigned int column, int proportion );
|
||||||
|
|
||||||
wxPropertyCategory* GetPropertyCategory( const wxPGProperty* p ) const;
|
wxPropertyCategory* GetPropertyCategory( const wxPGProperty* p ) const;
|
||||||
|
|
||||||
wxPGProperty* GetPropertyByLabel( const wxString& name,
|
wxPGProperty* GetPropertyByLabel( const wxString& name,
|
||||||
@@ -704,6 +706,9 @@ protected:
|
|||||||
/** List of indices of columns the user can edit by clicking it. */
|
/** List of indices of columns the user can edit by clicking it. */
|
||||||
wxArrayInt m_editableColumns;
|
wxArrayInt m_editableColumns;
|
||||||
|
|
||||||
|
/** Column proportions */
|
||||||
|
wxArrayInt m_columnProportions;
|
||||||
|
|
||||||
double m_fSplitterX;
|
double m_fSplitterX;
|
||||||
|
|
||||||
/** Most recently added category. */
|
/** Most recently added category. */
|
||||||
|
@@ -678,6 +678,18 @@ public:
|
|||||||
static void SetBoolChoices( const wxString& trueChoice,
|
static void SetBoolChoices( const wxString& trueChoice,
|
||||||
const wxString& falseChoice );
|
const wxString& falseChoice );
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set proportion of a auto-stretchable column. wxPG_SPLITTER_AUTO_CENTER
|
||||||
|
window style needs to be used to indicate that columns are auto-
|
||||||
|
resizeable.
|
||||||
|
|
||||||
|
@returns Returns @false on failure.
|
||||||
|
|
||||||
|
@remarks You should call this for individual pages of
|
||||||
|
wxPropertyGridManager (if used).
|
||||||
|
*/
|
||||||
|
bool SetColumnProportion( unsigned int column, int proportion );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sets an attribute for this property.
|
Sets an attribute for this property.
|
||||||
|
|
||||||
|
@@ -1845,6 +1845,10 @@ void FormMain::PopulateWithLibraryConfig ()
|
|||||||
wxPropertyGridManager* pgman = m_pPropGridManager;
|
wxPropertyGridManager* pgman = m_pPropGridManager;
|
||||||
wxPropertyGridPage* pg = pgman->GetPage(wxT("wxWidgets Library Config"));
|
wxPropertyGridPage* pg = pgman->GetPage(wxT("wxWidgets Library Config"));
|
||||||
|
|
||||||
|
// Set custom column proportions
|
||||||
|
pg->SetColumnProportion(0, 3);
|
||||||
|
pg->SetColumnProportion(1, 1);
|
||||||
|
|
||||||
wxPGProperty* cat;
|
wxPGProperty* cat;
|
||||||
|
|
||||||
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_REPORT_VIEW);
|
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_REPORT_VIEW);
|
||||||
|
@@ -359,6 +359,17 @@ void wxPropertyGridInterface::ClearModifiedStatus()
|
|||||||
GetPropertyGrid()->RefreshEditor();
|
GetPropertyGrid()->RefreshEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxPropertyGridInterface::SetColumnProportion( unsigned int column,
|
||||||
|
int proportion )
|
||||||
|
{
|
||||||
|
wxCHECK(m_pState, false);
|
||||||
|
wxPropertyGrid* pg = m_pState->GetGrid();
|
||||||
|
wxCHECK(pg, false);
|
||||||
|
wxCHECK(pg->HasFlag(wxPG_SPLITTER_AUTO_CENTER), false);
|
||||||
|
m_pState->DoSetColumnProportion(column, proportion);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// wxPropertyGridInterface property value setting and getting
|
// wxPropertyGridInterface property value setting and getting
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@@ -218,6 +218,9 @@ wxPropertyGridPageState::wxPropertyGridPageState()
|
|||||||
m_colWidths.push_back( wxPG_DEFAULT_SPLITTERX );
|
m_colWidths.push_back( wxPG_DEFAULT_SPLITTERX );
|
||||||
m_fSplitterX = wxPG_DEFAULT_SPLITTERX;
|
m_fSplitterX = wxPG_DEFAULT_SPLITTERX;
|
||||||
|
|
||||||
|
m_columnProportions.push_back(1);
|
||||||
|
m_columnProportions.push_back(1);
|
||||||
|
|
||||||
m_isSplitterPreSet = false;
|
m_isSplitterPreSet = false;
|
||||||
m_dontCenterSplitter = false;
|
m_dontCenterSplitter = false;
|
||||||
|
|
||||||
@@ -1046,47 +1049,79 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Auto center splitter
|
// Auto center splitter
|
||||||
if ( !m_dontCenterSplitter && m_colWidths.size() == 2 )
|
if ( !m_dontCenterSplitter )
|
||||||
{
|
{
|
||||||
float centerX = (float)(pg->m_width/2);
|
if ( m_colWidths.size() == 2 &&
|
||||||
float splitterX;
|
m_columnProportions[0] == m_columnProportions[1] )
|
||||||
|
|
||||||
if ( m_fSplitterX < 0.0 )
|
|
||||||
{
|
{
|
||||||
splitterX = centerX;
|
//
|
||||||
}
|
// When we have two columns of equal proportion, then use this
|
||||||
else if ( widthChange )
|
// code. It will look nicer when the scrollbar visibility is
|
||||||
{
|
// toggled on and off.
|
||||||
//float centerX = float(pg->GetSize().x) * 0.5;
|
//
|
||||||
|
// TODO: Adapt this to generic recenter code.
|
||||||
|
//
|
||||||
|
float centerX = (float)(pg->m_width/2);
|
||||||
|
float splitterX;
|
||||||
|
|
||||||
// Recenter?
|
if ( m_fSplitterX < 0.0 )
|
||||||
splitterX = m_fSplitterX + (float(widthChange) * 0.5);
|
|
||||||
float deviation = fabs(centerX - splitterX);
|
|
||||||
|
|
||||||
// If deviating from center, adjust towards it
|
|
||||||
if ( deviation > 20.0 )
|
|
||||||
{
|
|
||||||
if ( splitterX > centerX)
|
|
||||||
splitterX -= 2;
|
|
||||||
else
|
|
||||||
splitterX += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 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;
|
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);
|
||||||
|
|
||||||
|
// If deviating from center, adjust towards it
|
||||||
|
if ( deviation > 20.0 )
|
||||||
|
{
|
||||||
|
if ( splitterX > centerX)
|
||||||
|
splitterX -= 2;
|
||||||
|
else
|
||||||
|
splitterX += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 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
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Generic re-center code
|
||||||
|
//
|
||||||
|
|
||||||
DoSetSplitterPosition((int)splitterX, 0,
|
// Calculate sum of proportions
|
||||||
wxPG_SPLITTER_FROM_AUTO_CENTER);
|
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;
|
||||||
|
|
||||||
m_fSplitterX = splitterX; // needed to retain accuracy
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1094,6 +1129,7 @@ void wxPropertyGridPageState::SetColumnCount( int colCount )
|
|||||||
{
|
{
|
||||||
wxASSERT( colCount >= 2 );
|
wxASSERT( colCount >= 2 );
|
||||||
m_colWidths.SetCount( colCount, wxPG_DRAG_MARGIN );
|
m_colWidths.SetCount( colCount, wxPG_DRAG_MARGIN );
|
||||||
|
m_columnProportions.SetCount( colCount, 1 );
|
||||||
if ( m_colWidths.size() > (unsigned int)colCount )
|
if ( m_colWidths.size() > (unsigned int)colCount )
|
||||||
m_colWidths.RemoveAt( m_colWidths.size()-1,
|
m_colWidths.RemoveAt( m_colWidths.size()-1,
|
||||||
m_colWidths.size() - colCount );
|
m_colWidths.size() - colCount );
|
||||||
@@ -1104,6 +1140,21 @@ void wxPropertyGridPageState::SetColumnCount( int colCount )
|
|||||||
CheckColumnWidths();
|
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
|
// Returns column index, -1 for margin
|
||||||
int wxPropertyGridPageState::HitTestH( int x, int* pSplitterHit, int* pSplitterHitOffset ) const
|
int wxPropertyGridPageState::HitTestH( int x, int* pSplitterHit, int* pSplitterHitOffset ) const
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user