propgrid.cpp
来自「这是一个GPS相关的程序」· C++ 代码 · 共 2,266 行 · 第 1/5 页
CPP
2,266 行
wxPGVariant wxParentPropertyClass::DoGetValue() const
{
return wxPGVariant();
}
void wxParentPropertyClass::ChildChanged( wxPGProperty* WXUNUSED(p) )
{
}
wxString wxParentPropertyClass::GetValueAsString( int argFlags ) const
{
if ( !GetCount() )
return wxEmptyString;
return wxPGPropertyWithChildren::GetValueAsString(argFlags);
}
// -----------------------------------------------------------------------
// wxPGRootPropertyClass
// -----------------------------------------------------------------------
WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty,none,TextCtrl)
const wxPGPropertyClassInfo* wxPGRootPropertyClass::GetClassInfo() const
{
return (const wxPGPropertyClassInfo*) NULL;
}
wxPGRootPropertyClass::wxPGRootPropertyClass()
: wxPGPropertyWithChildren()
{
m_parentingType = PT_ROOT; // this was PT_CAPTION in <= 1.1.6, but changed
// so the depth calculations can become
// more consistent.
m_depth = 0;
}
wxPGRootPropertyClass::~wxPGRootPropertyClass()
{
}
// -----------------------------------------------------------------------
// wxPropertyCategoryClass
// -----------------------------------------------------------------------
wxPGProperty* wxPropertyCategory( const wxString& label, const wxString& name )
{
return new wxPropertyCategoryClass(label,name);
}
WX_PG_IMPLEMENT_CLASSINFO(wxPropertyCategory,wxBaseParentPropertyClass)
WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory,none,TextCtrl)
wxPropertyCategoryClass::wxPropertyCategoryClass()
: wxPGPropertyWithChildren()
{
// don't set colour - prepareadditem method should do this
m_parentingType = 1;
m_capFgColIndex = 1;
}
wxPropertyCategoryClass::wxPropertyCategoryClass( const wxString &label, const wxString& name )
: wxPGPropertyWithChildren(label,name)
{
// don't set colour - prepareadditem method should do this
m_parentingType = 1;
m_capFgColIndex = 1;
}
wxPropertyCategoryClass::~wxPropertyCategoryClass()
{
}
wxString wxPropertyCategoryClass::GetValueAsString( int ) const
{
return wxEmptyString;
}
void wxPropertyCategoryClass::CalculateTextExtent( wxWindow* wnd, wxFont& font )
{
int x = 0, y = 0;
wnd->GetTextExtent( m_label, &x, &y, 0, 0, &font );
m_textExtent = x;
}
// -----------------------------------------------------------------------
// wxPGEditor
// -----------------------------------------------------------------------
wxPGEditor::~wxPGEditor()
{
}
void wxPGEditor::DrawValue( wxDC& dc, wxPGProperty* property, const wxRect& rect ) const
{
if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
dc.DrawText( property->GetDisplayedString(), rect.x+wxPG_XBEFORETEXT, rect.y );
}
void wxPGEditor::SetControlStringValue( wxWindow*, const wxString& ) const
{
}
void wxPGEditor::SetControlIntValue( wxWindow*, int ) const
{
}
int wxPGEditor::InsertItem( wxWindow*, const wxString&, int ) const
{
return -1;
}
void wxPGEditor::DeleteItem( wxWindow*, int ) const
{
return;
}
void wxPGEditor::OnFocus( wxPGProperty*, wxWindow* ) const
{
}
bool wxPGEditor::CanContainCustomImage() const
{
return false;
}
// -----------------------------------------------------------------------
// wxPGClipperWindow
// -----------------------------------------------------------------------
#if wxPG_ENABLE_CLIPPER_WINDOW
//
// Clipper window is used to "remove" borders from controls
// which otherwise insist on having them despite of supplied
// wxNO_BORDER window style.
//
class wxPGClipperWindow : public wxWindow
{
DECLARE_CLASS(wxPGClipperWindow)
public:
wxPGClipperWindow()
: wxWindow()
{
wxPGClipperWindow::Init();
}
wxPGClipperWindow(wxWindow* parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize)
{
Init();
Create(parent,id,pos,size);
}
void Create(wxWindow* parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize);
virtual ~wxPGClipperWindow();
virtual bool ProcessEvent(wxEvent& event);
inline wxWindow* GetControl() const { return m_ctrl; }
// This is called before wxControl is constructed.
void GetControlRect( int xadj, int yadj, wxPoint& pt, wxSize& sz );
// This is caleed after wxControl has been constructed.
void SetControl( wxWindow* ctrl );
virtual void Refresh( bool eraseBackground = true,
const wxRect *rect = (const wxRect *) NULL );
virtual void SetFocus();
virtual bool SetFont(const wxFont& font);
inline int GetXClip() const { return m_xadj; }
inline int GetYClip() const { return m_yadj; }
protected:
wxWindow* m_ctrl;
int m_xadj; // Horizontal border clip.
int m_yadj; // Vertical border clip.
private:
void Init ()
{
m_ctrl = (wxWindow*) NULL;
}
};
IMPLEMENT_CLASS(wxPGClipperWindow,wxWindow)
// This is called before wxControl is constructed.
void wxPGClipperWindow::GetControlRect( int xadj, int yadj, wxPoint& pt, wxSize& sz )
{
m_xadj = xadj;
m_yadj = yadj;
pt.x = -xadj;
pt.y = -yadj;
wxSize own_size = GetSize();
sz.x = own_size.x+(xadj*2);
sz.y = own_size.y+(yadj*2);
}
// This is caleed after wxControl has been constructed.
void wxPGClipperWindow::SetControl( wxWindow* ctrl )
{
m_ctrl = ctrl;
// GTK requires this.
ctrl->SetSizeHints(3,3);
// Correct size of this window to match the child.
wxSize sz = GetSize();
wxSize chsz = ctrl->GetSize();
int hei_adj = chsz.y - (sz.y+(m_yadj*2));
if ( hei_adj )
SetSize(sz.x,chsz.y-(m_yadj*2));
}
void wxPGClipperWindow::Refresh( bool eraseBackground, const wxRect *rect )
{
wxWindow::Refresh(false,rect);
if ( m_ctrl )
// FIXME: Rect to sub-ctrl refresh too
m_ctrl->Refresh(eraseBackground);
}
// Pass focus to control
void wxPGClipperWindow::SetFocus()
{
if ( m_ctrl )
m_ctrl->SetFocus();
else
wxWindow::SetFocus();
}
bool wxPGClipperWindow::SetFont(const wxFont& font)
{
bool res = wxWindow::SetFont(font);
if ( m_ctrl )
return m_ctrl->SetFont(font);
return res;
}
void wxPGClipperWindow::Create(wxWindow* parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size )
{
wxWindow::Create(parent,id,pos,size);
}
wxPGClipperWindow::~wxPGClipperWindow()
{
}
bool wxPGClipperWindow::ProcessEvent(wxEvent& event)
{
if ( event.GetEventType() == wxEVT_SIZE )
{
if ( m_ctrl )
{
// Maintain correct size relationship.
wxSize sz = GetSize();
m_ctrl->SetSize(sz.x+(m_xadj*2),sz.y+(m_yadj*2));
event.Skip();
return false;
}
}
return wxWindow::ProcessEvent(event);
}
#endif // wxPG_ENABLE_CLIPPER_WINDOW
/*wxWindow* wxPropertyGrid::GetActualEditorControl( wxWindow* ctrl )
{
#if wxPG_ENABLE_CLIPPER_WINDOW
// Pass real control instead of clipper window
if ( ctrl->IsKindOf(CLASSINFO(wxPGClipperWindow)) )
{
return ((wxPGClipperWindow*)ctrl)->GetControl();
}
#else
return ctrl;
#endif
}*/
// -----------------------------------------------------------------------
// wxPGTextCtrlEditor
// -----------------------------------------------------------------------
// Clipper window support macro (depending on whether it is used
// for this editor or not)
#if wxPG_NAT_TEXTCTRL_BORDER_X || wxPG_NAT_TEXTCTRL_BORDER_Y
#define wxPG_NAT_TEXTCTRL_BORDER_ANY 1
#define wxPGDeclareRealTextCtrl(WND) \
wxASSERT( WND ); \
wxTextCtrl* tc = (wxTextCtrl*)((wxPGClipperWindow*)WND)->GetControl()
#else
#define wxPG_NAT_TEXTCTRL_BORDER_ANY 0
#define wxPGDeclareRealTextCtrl(WND) \
wxASSERT( WND ); \
wxTextCtrl* tc = (wxTextCtrl*)WND
#endif
WX_PG_IMPLEMENT_EDITOR_CLASS(TextCtrl,wxPGTextCtrlEditor,wxPGEditor)
#ifndef __WXPYTHON__
wxWindow* wxPGTextCtrlEditor::CreateControls( wxPropertyGrid* propGrid,
wxPGProperty* property,
const wxPoint& pos,
const wxSize& sz,
wxWindow** ) const
#else
wxPGWindowPair wxPGTextCtrlEditor::CreateControls( wxPropertyGrid* propGrid,
wxPGProperty* property,
const wxPoint& pos,
const wxSize& sz ) const
#endif
{
wxString text;
// If has children and limited editing, then don't create.
if ((property->GetFlags() & wxPG_PROP_NOEDITOR) &&
property->GetParentingType() < 0 &&
!property->IsKindOf(WX_PG_CLASSINFO(wxCustomProperty)))
return (wxWindow*) NULL;
if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
text = property->GetValueAsString(0);
int flags = 0;
if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
flags |= wxTE_PASSWORD;
wxWindow* wnd = propGrid->GenerateEditorTextCtrl(pos,sz,text,(wxWindow*)NULL,flags,
property->GetMaxLength());
return wnd;
}
void wxPGTextCtrlEditor::DrawValue( wxDC& dc, wxPGProperty* property, const wxRect& rect ) const
{
if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
{
wxString drawStr = property->GetDisplayedString();
// Code below should no longer be needed, as the obfuscation
// is now done in GetValueAsString.
/*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
{
size_t a = drawStr.length();
drawStr.Empty();
drawStr.Append(wxT('*'),a);
}*/
dc.DrawText( drawStr, rect.x+wxPG_XBEFORETEXT, rect.y );
}
}
void wxPGTextCtrlEditor::UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const
{
wxPGDeclareRealTextCtrl(ctrl);
tc->SetValue(property->GetDisplayedString());
}
// Provided so that, for example, ComboBox editor can use the same code
// (multiple inheritance would get way too messy).
bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid* propGrid,
wxPGProperty* property,
wxWindow* ctrl,
wxEvent& event )
{
if ( !ctrl )
return false;
if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER )
{
if ( propGrid->IsEditorsValueModified() )
{
return true;
}
}
else if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
{
wxPGDeclareRealTextCtrl(ctrl);
// If value is unspecified and character count is zero,
// then do not set as modified.
if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) ||
!tc ||
(tc->IsKindOf(CLASSINFO(wxTextCtrl)) &&
(tc->GetLastPosition() > 0)) )
{
// We must check this since an 'empty' text event
// may be triggered when creating the property.
if ( !(propGrid->GetInternalFlags() & wxPG_FL_IN_SELECT_PROPERTY) )
{
//
// Pass this event outside wxPropertyGrid so that,
// if necessary, program can tell when user is editing
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?