📄 manager.cpp
字号:
m_selPage = index;
#if wxUSE_TOOLBAR
if ( m_pToolbar )
{
m_pToolbar->ToggleTool ( pd_next->m_id, TRUE );
}
#endif
}
// -----------------------------------------------------------------------
int wxPropertyGridManager::GetPageByName ( const wxChar* name ) const
{
wxASSERT ( name );
size_t i;
for ( i=0; i<m_arrPages.GetCount(); i++ )
{
if ( ((wxPropertyGridPageData*)m_arrPages.Item(i))->m_label == name )
return i;
}
return wxNOT_FOUND;
}
// -----------------------------------------------------------------------
int wxPropertyGridManager::GetPageByState( wxPropertyGridState* pstate ) const
{
wxASSERT ( pstate );
size_t i;
for ( i=0; i<m_arrPages.GetCount(); i++ )
{
if ( pstate == &((wxPropertyGridPageData*)m_arrPages.Item(i))->m_state )
return i;
}
return wxNOT_FOUND;
}
// -----------------------------------------------------------------------
const wxString& wxPropertyGridManager::GetPageName ( int index ) const
{
wxASSERT ( index >= 0 && index < (int)m_arrPages.GetCount() );
return ((wxPropertyGridPageData*)m_arrPages.Item(index))->m_label;
}
// -----------------------------------------------------------------------
// Sets page for append, insert, etc. operations.
void wxPropertyGridManager::SetTargetPage ( int index )
{
wxASSERT ( m_selPage >= 0 );
wxASSERT ( index >= 0 );
wxASSERT ( index < (int)m_arrPages.GetCount() );
m_targetState = &((wxPropertyGridPageData*)m_arrPages.Item(index))->m_state;
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::ClearPage( int page )
{
if ( page >= 0 && page < (int)m_arrPages.GetCount() )
{
wxPropertyGridState* state = GetPageState(page);
if ( state == m_propGrid.GetState() )
m_propGrid.Clear();
else
state->Clear();
}
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::Compact ( bool compact )
{
if ( m_pButCompactor )
{
if ( compact ) m_pButCompactor->SetLabel(wxT("Expand >>"));
else m_pButCompactor->SetLabel(wxT("<< Compact"));
}
m_propGrid.Compact(compact);
}
// -----------------------------------------------------------------------
int wxPropertyGridManager::InsertPage ( int index, const wxString& label, const wxBitmap&
#if wxUSE_TOOLBAR
bmp
#endif
)
{
if ( index < 0 )
index = m_arrPages.GetCount();
//wxASSERT ( (size_t)index <= m_arrPages.GetCount() );
wxCHECK_MSG ( (size_t)index == m_arrPages.GetCount(), -1,
wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
wxPropertyGridPageData* pd;
if ( m_selPage >= 0 )
{
pd = new wxPropertyGridPageData();
pd->m_state.m_pPropGrid = &m_propGrid;
pd->m_state.InitNonCatMode();
m_targetState = &pd->m_state;
}
else
pd = (wxPropertyGridPageData*)m_arrPages.Item(0);
pd->m_label = label;
pd->m_id = m_nextTbInd;
if ( m_selPage >= 0 )
//m_arrPages.Insert( (void*)pd, index );
m_arrPages.Add( (void*)pd );
#if wxUSE_TOOLBAR
if ( m_windowStyle & wxPG_TOOLBAR )
{
if ( !m_pToolbar )
RecreateControls();
wxASSERT ( m_pToolbar );
// Add separator before first page.
if ( m_arrPages.GetCount() < 2 && !(GetExtraStyle()&wxPG_EX_NO_MODE_BUTTONS) )
m_pToolbar->AddSeparator();
if ( &bmp != &wxNullBitmap )
m_pToolbar->AddTool(m_nextTbInd,label,bmp,label,wxITEM_RADIO);
//m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
else
m_pToolbar->AddTool(m_nextTbInd,label,wxBitmap( (const char**)gs_xpm_defpage ),
label,wxITEM_RADIO);
m_nextTbInd++;
m_pToolbar->Realize();
}
#endif
// Need to increase selected index?
if ( m_selPage >= 0 )
{
if ( m_selPage >= index )
{
m_selPage += 1;
}
}
else
{
// Set reset it.
m_selPage = 0;
}
return index;
}
// -----------------------------------------------------------------------
bool wxPropertyGridManager::IsAnyModified () const
{
size_t i;
for ( i=0; i<m_arrPages.GetCount(); i++ )
{
if ( ((wxPropertyGridPageData*)m_arrPages.Item(i))->m_state.m_anyModified )
return TRUE;
}
return FALSE;
}
// -----------------------------------------------------------------------
bool wxPropertyGridManager::IsPageModified ( size_t index ) const
{
if ( ((wxPropertyGridPageData*)m_arrPages.Item(index))->m_state.m_anyModified )
return TRUE;
return FALSE;
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::RepaintSplitter ( int new_splittery, int new_width, int new_height,
bool desc_too )
{
wxClientDC dc(this);
int use_hei = new_height;
if ( m_pButCompactor )
use_hei = m_pButCompactor->GetPosition().y;
// Draw background
wxColour bgcol = GetBackgroundColour();
dc.SetBrush( bgcol );
dc.SetPen( bgcol );
int rect_hei = use_hei-new_splittery;
if ( !desc_too )
rect_hei = m_splitterHeight;
dc.DrawRectangle(0,new_splittery,new_width,rect_hei);
dc.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW ) );
int splitter_bottom = new_splittery+m_splitterHeight - 1;
int box_height = use_hei-splitter_bottom;
if ( box_height > 1 )
dc.DrawRectangle(0,splitter_bottom,new_width,box_height);
else
dc.DrawLine(0,splitter_bottom,new_width,splitter_bottom);
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::RefreshHelpBox ( int new_splittery, int new_width, int new_height )
{
//if ( new_splittery == m_splitterY && new_width == m_width )
// return;
int use_hei = new_height;
if ( m_pButCompactor )
use_hei = m_pButCompactor->GetPosition().y;
use_hei--;
//wxRendererNative::Get().DrawSplitterSash(this,dc,
//wxSize(width,m_splitterHeight),new_splittery,wxHORIZONTAL);
//wxRendererNative::Get().DrawSplitterBorder(this,dc,
// wxRect(0,new_splittery,new_width,m_splitterHeight));
// Fix help control positions.
int cap_hei = m_propGrid.m_fontHeight;
int cap_y = new_splittery+m_splitterHeight+5;
int cnt_y = cap_y+cap_hei+3;
int sub_cap_hei = cap_y+cap_hei-use_hei;
int cnt_hei = use_hei-cnt_y;
if ( sub_cap_hei > 0 )
{
cap_hei -= sub_cap_hei;
cnt_hei = 0;
}
if ( cap_hei <= 2 )
{
m_pTxtHelpCaption->Show( FALSE );
m_pTxtHelpContent->Show( FALSE );
}
else
{
m_pTxtHelpCaption->SetSize(3,cap_y,new_width-6,cap_hei);
m_pTxtHelpCaption->Show( TRUE );
if ( cnt_hei <= 2 )
{
m_pTxtHelpContent->Show( FALSE );
}
else
{
m_pTxtHelpContent->SetSize(3,cnt_y,new_width-6,cnt_hei);
m_pTxtHelpContent->Show( TRUE );
}
}
RepaintSplitter ( new_splittery, new_width, new_height, TRUE );
m_splitterY = new_splittery;
m_iFlags &= ~(wxPG_FL_DESC_REFRESH_REQUIRED);
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::RecalculatePositions ( int width, int height )
{
int propgrid_y = 0;
int propgrid_bottom_y = height;
//int button_top = height;
// Toolbar at the top.
#if wxUSE_TOOLBAR
if ( m_pToolbar )
{
m_pToolbar->SetSize(0,0,width,-1);
propgrid_y = m_pToolbar->GetSize().y;
}
#endif
// Button at the bottom.
if ( m_pButCompactor )
{
int but_hei = m_pButCompactor->GetSize().y;
m_pButCompactor->SetSize(0,height-but_hei,width,but_hei);
propgrid_bottom_y -= but_hei;
//button_top -= but_hei;
}
// Help box.
if ( m_pTxtHelpCaption )
{
int new_splittery = m_splitterY;
// Move m_splitterY
if ( ( m_splitterY >= 0 || m_nextDescBoxSize ) && m_height > 32 )
{
if ( m_nextDescBoxSize >= 0 )
{
new_splittery = m_height - m_nextDescBoxSize - m_splitterHeight;
m_nextDescBoxSize = -1;
}
new_splittery += (height-m_height);
}
else
{
new_splittery = height - wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y;
if ( new_splittery < 32 )
new_splittery = 32;
}
// Check if beyond minimum.
int nspy_min = propgrid_y + m_propGrid.m_lineHeight;
if ( new_splittery < nspy_min )
new_splittery = nspy_min;
propgrid_bottom_y = new_splittery;
RefreshHelpBox( new_splittery, width, height );
}
if ( m_iFlags & wxPG_FL_INITIALIZED )
{
int pgh = propgrid_bottom_y - propgrid_y;
m_propGrid.SetSize ( 0, propgrid_y,
width, pgh );
m_extraHeight = height - pgh;
m_width = width;
m_height = height;
}
//InvalidateBestSize();
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::SetDescBoxHeight ( int ht, bool refresh )
{
if ( m_windowStyle & wxPG_DESCRIPTION )
{
m_nextDescBoxSize = ht;
if ( refresh )
RecalculatePositions(m_width,m_height);
/*
int newypos = m_height - ht - m_splitterHeight;
if ( refresh && m_pTxtHelpContent )
RefreshHelpBox(newypos,m_width,m_height);
else
m_splitterY = newypos;*/
}
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::OnPaint ( wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc(this);
// Update everything inside the box
wxRect r = GetUpdateRegion().GetBox();
// Repaint splitter?
int r_bottom = r.y + r.height;
int splitter_bottom = m_splitterY + m_splitterHeight;
if ( r.y < splitter_bottom && r_bottom >= m_splitterY )
RepaintSplitter ( m_splitterY, m_width, m_height, FALSE );
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::Refresh (bool eraseBackground, const wxRect* rect )
{
m_propGrid.Refresh(eraseBackground);
wxWindow::Refresh(eraseBackground,rect);
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::RecreateControls ()
{
bool was_shown = IsShown();
if ( was_shown )
Show ( FALSE );
int baseId = m_propGrid.GetId();
if ( baseId < 0 )
baseId = wxPG_MAN_ALTERNATE_BASE_ID;
#if wxUSE_TOOLBAR
if ( m_windowStyle & wxPG_TOOLBAR )
{
// Has toolbar.
if ( !m_pToolbar )
{
m_pToolbar = new wxToolBar (this,baseId+ID_ADVTOOLBAR_OFFSET,
wxDefaultPosition,wxDefaultSize,
((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR)?0:wxTB_FLAT) );
m_pToolbar->SetCursor ( *wxSTANDARD_CURSOR );
if ( !(GetExtraStyle()&wxPG_EX_NO_MODE_BUTTONS) )
{
wxString desc1(_("Categorized Mode"));
wxString desc2(_("Alphabetic Mode"));
m_pToolbar->AddTool(baseId+ID_ADVTBITEMSBASE_OFFSET+0,
desc1,wxBitmap ( (const char**)gs_xpm_catmode ),
desc1,wxITEM_RADIO);
m_pToolbar->AddTool(baseId+ID_ADVTBITEMSBASE_OFFSET+1,
desc2,wxBitmap ( (const char**)gs_xpm_noncatmode ),
desc2,wxITEM_RADIO);
m_pToolbar->Realize();
}
}
if ( !(GetExtraStyle()&wxPG_EX_NO_MODE_BUTTONS) )
{
// Toggle correct mode button.
// TODO: This doesn't work in wxMSW (when changing,
// both items will get toggled).
int toggle_but_on_ind = ID_ADVTBITEMSBASE_OFFSET+0;
int toggle_but_off_ind = ID_ADVTBITEMSBASE_OFFSET+1;
if ( m_propGrid.m_pState->IsInNonCatMode() )
{
toggle_but_on_ind++;
toggle_but_off_ind--;
}
m_pToolbar->ToggleTool(baseId+toggle_but_on_ind,TRUE);
m_pToolbar->ToggleTool(baseId+toggle_but_off_ind,FALSE);
}
}
else
{
// No toolbar.
if ( m_pToolbar )
m_pToolbar->Destroy();
m_pToolbar = (wxToolBar*) NULL;
}
#endif
if ( m_windowStyle & wxPG_COMPACTOR )
{
// Has button.
if ( !m_pButCompactor )
{
m_pButCompactor = new wxButton (this,baseId+ID_ADVBUTTON_OFFSET,
!(m_propGrid.m_iFlags & wxPG_FL_HIDE_STATE)?_("<< Compact"):_("Expand >>"));
m_pButCompactor->SetCursor ( *wxSTANDARD_CURSOR );
}
}
else
{
// No button.
if ( m_pButCompactor )
m_pButCompactor->Destroy();
m_pButCompactor = (wxButton*) NULL;
}
if ( m_windowStyle & wxPG_DESCRIPTION )
{
// Has help box.
m_propGrid.m_iFlags |= (wxPG_FL_NOSTATUSBARHELP);
if ( !m_pTxtHelpCaption )
{
m_pTxtHelpCaption = new wxStaticText (this,baseId+ID_ADVHELPCAPTION_OFFSET,wxT(""));
m_pTxtHelpCaption->SetFont( m_propGrid.m_captionFont );
m_pTxtHelpCaption->SetCursor ( *wxSTANDARD_CURSOR );
}
if ( !m_pTxtHelpContent )
{
m_pTxtHelpContent = new wxStaticText (this,baseId+ID_ADVHELPCONTENT_OFFSET,
wxT(""),wxDefaultPosition,wxDefaultSize,wxALIGN_LEFT|wxST_NO_AUTORESIZE);
m_pTxtHelpContent->SetCursor ( *wxSTANDARD_CURSOR );
}
}
else
{
// No help box.
m_propGrid.m_iFlags &= ~(wxPG_FL_NOSTATUSBARHELP);
if ( m_pTxtHelpCaption )
m_pTxtHelpCaption->Destroy();
m_pTxtHelpCaption = (wxStaticText*) NULL;
if ( m_pTxtHelpContent )
m_pTxtHelpContent->Destroy();
m_pTxtHelpContent = (wxStaticText*) NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -