📄 manager.cpp
字号:
if ( m_arrPages.GetCount() == 1 )
{
// Last page: do not remove page entry
m_pPropGrid->Clear();
m_selPage = -1;
m_iFlags &= ~wxPG_MAN_FL_PAGE_INSERTED; pd->m_label.clear();
}
// Change selection if current is page
else if ( page == m_selPage )
{
if ( !m_pPropGrid->ClearSelection() )
return false;
// Substitute page to select
int substitute = page - 1;
if ( substitute < 0 )
substitute = page + 1;
SelectPage(substitute);
}
// Remove toolbar icon
#if wxUSE_TOOLBAR
if ( m_windowStyle & wxPG_TOOLBAR )
{
wxASSERT( m_pToolbar );
int toolPos = GetExtraStyle() & wxPG_EX_MODE_BUTTONS ? 3 : 0;
toolPos += page;
m_pToolbar->DeleteToolByPos(toolPos);
// Delete separator as well, for consistency
if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS) &&
GetPageCount() == 1 )
m_pToolbar->DeleteToolByPos(2);
}
#endif
if ( m_arrPages.GetCount() > 1 )
{
m_arrPages.RemoveAt(page);
delete pd;
}
// Adjust indexes that were above removed
if ( m_selPage > page )
m_selPage--;
return true;
}
// -----------------------------------------------------------------------
bool wxPropertyGridManager::ProcessEvent( wxEvent& event )
{
int evtType = event.GetEventType();
#ifdef __WXPYTHON__
// NB: For some reason, under wxPython, Connect in Init doesn't work properly,
// so we'll need to call OnPropertyGridSelect manually. Multiple call's
// don't really matter.
if ( evtType == wxEVT_PG_SELECTED )
OnPropertyGridSelect((wxPropertyGridEvent&)event);
#endif
// Property grid events get special attention
if ( evtType >= wxPG_BASE_EVT_TYPE &&
evtType < (wxPG_MAX_EVT_TYPE) &&
m_selPage >= 0 )
{
wxPropertyGridPage* page = GetPage(m_selPage);
wxPropertyGridEvent* pgEvent = wxDynamicCast(&event, wxPropertyGridEvent);
// Add property grid events to appropriate custom pages
// but stop propagating to parent if page says it is
// handling everything.
if ( pgEvent && !page->m_isDefault )
{
if ( pgEvent->IsPending() )
page->AddPendingEvent(event);
else
page->ProcessEvent(event);
if ( page->IsHandlingAllEvents() )
event.StopPropagation();
}
}
return wxPanel::ProcessEvent(event);
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::RepaintSplitter( wxDC& dc, int new_splittery, int new_width,
int new_height, bool desc_too )
{
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_pPropGrid->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 );
}
}
wxClientDC dc(this);
RepaintSplitter( dc, 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 propgridY = 0;
int propgridBottomY = height;
// Toolbar at the top.
#if wxUSE_TOOLBAR
if ( m_pToolbar )
{
int tbHeight;
#if ( wxMINOR_VERSION < 6 || (wxMINOR_VERSION == 6 && wxRELEASE_NUMBER < 2) )
tbHeight = -1;
#else
// In wxWidgets 2.6.2+, Toolbar default height may be broken
#if defined(__WXMSW__)
tbHeight = 24;
#elif defined(__WXGTK__)
tbHeight = -1; // 22;
#elif defined(__WXMAC__)
tbHeight = 22;
#else
tbHeight = 22;
#endif
#endif
m_pToolbar->SetSize(0,0,width,tbHeight);
propgridY = 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);
propgridBottomY -= 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 = propgridY + m_pPropGrid->m_lineHeight;
if ( new_splittery < nspy_min )
new_splittery = nspy_min;
propgridBottomY = new_splittery;
RefreshHelpBox( new_splittery, width, height );
}
if ( m_iFlags & wxPG_FL_INITIALIZED )
{
int pgh = propgridBottomY - propgridY;
m_pPropGrid->SetSize( 0, propgridY, width, pgh );
m_extraHeight = height - pgh;
m_width = width;
m_height = height;
}
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::SetDescBoxHeight( int ht, bool refresh )
{
if ( m_windowStyle & wxPG_DESCRIPTION )
{
m_nextDescBoxSize = ht;
if ( refresh )
RecalculatePositions(m_width, m_height);
}
}
// -----------------------------------------------------------------------
int wxPropertyGridManager::GetDescBoxHeight() const
{
return GetClientSize().y - m_splitterY;
}
// -----------------------------------------------------------------------
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( dc, m_splitterY, m_width, m_height, false );
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::Refresh(bool eraseBackground, const wxRect* rect )
{
m_pPropGrid->Refresh(eraseBackground);
wxWindow::Refresh(eraseBackground,rect);
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::RefreshProperty( wxPGProperty* p )
{
wxPropertyGrid* grid = p->GetGrid();
if ( GetPage(m_selPage)->GetStatePtr() == p->GetParent()->GetParentState() )
grid->RefreshProperty(p);
}
// -----------------------------------------------------------------------
void wxPropertyGridManager::RecreateControls()
{
bool was_shown = IsShown();
if ( was_shown )
Show ( false );
wxWindowID baseId = m_pPropGrid->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)
/*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
#if defined(__WXMSW__)
// Eliminate toolbar flicker on XP
// NOTE: Not enabled since it corrupts drawing somewhat.
/*
#ifndef WS_EX_COMPOSITED
#define WS_EX_COMPOSITED 0x02000000L
#endif
HWND hWnd = (HWND)m_pToolbar->GetHWND();
::SetWindowLong( hWnd, GWL_EXSTYLE,
::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
*/
#endif
m_pToolbar->SetCursor ( *wxSTANDARD_CURSOR );
if ( (GetExtraStyle()&wxPG_EX_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_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_pPropGrid->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_pPropGrid->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_pPropGrid->m_iFlags |= (wxPG_FL_NOSTATUSBARHELP);
if ( !m_pTxtHelpCaption )
{
m_pTxtHelpCaption = new wxStaticText (this,baseId+ID_ADVHELPCAPTION_OFFSET,wxT(""));
m_pTxtHelpCaption->SetFont( m_pPropGrid->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_pPropGrid->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;
}
int width, height;
GetClientSize(&width,&height);
RecalculatePositions(width,height);
if ( was_shown )
Show ( true );
}
// -----------------------------------------------------------------------
wxPGId wxPropertyGridManager::DoGetPropertyByName( wxPGPropNameStr name ) const
{
//return GetPropertyByName2(name, (wxPropertyGridState**)NULL );
size_t i;
for ( i=0; i<GetPageCount(); i++ )
{
wxPropertyGridState* pState = ((wxPropertyGridPage*)m_arrPages.Item(i))->GetStatePtr();
wxPGId id = pState->BaseGetPropertyByName(name);
if ( wxPGIdIsOk(id) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -