📄 advprops.cpp
字号:
wxT("Normal"),
wxT("Light"),
wxT("Bold"),
(const wxChar*) NULL
};
static long gs_fp_es_weight_values[] = {
wxNORMAL,
wxLIGHT,
wxBOLD
};
// Class body is in advprops.h
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty,wxBaseParentProperty,
wxFont,const wxFont&,TextCtrlAndButton)
wxFontPropertyClass::wxFontPropertyClass( const wxString& label, const wxString& name,
const wxFont& value )
: wxPGPropertyWithChildren(label,name)
{
wxPG_INIT_REQUIRED_TYPE(wxFont)
DoSetValue( wxPGVariantCreator(value) );
// Initialize font family choices list
if ( !wxPGGlobalVars->m_fontFamilyChoices )
{
WX_PG_GLOBALS_LOCKER()
wxFontEnumerator enumerator;
enumerator.EnumerateFacenames();
#if wxMINOR_VERSION > 6
wxArrayString faceNames = enumerator.GetFacenames();
#else
wxArrayString& faceNames = *enumerator.GetFacenames();
#endif
faceNames.Sort();
wxPGGlobalVars->m_fontFamilyChoices = new wxPGChoices(faceNames);
}
wxString emptyString(wxEmptyString);
AddChild( wxIntProperty( _("Point Size"),emptyString,m_value_wxFont.GetPointSize() ) );
AddChild( wxEnumProperty(_("Family"), emptyString,
gs_fp_es_family_labels,gs_fp_es_family_values,
m_value_wxFont.GetFamily()) );
wxString faceName = m_value_wxFont.GetFaceName();
// If font was not in there, add it now
if ( faceName.length() &&
wxPGGlobalVars->m_fontFamilyChoices->Index(faceName) == wxNOT_FOUND )
wxPGGlobalVars->m_fontFamilyChoices->AddAsSorted(faceName);
wxPGProperty* p = wxEnumProperty(_("Face Name"),emptyString,
*wxPGGlobalVars->m_fontFamilyChoices);
p->SetValueFromString(faceName,wxPG_FULL_VALUE);
AddChild( p );
AddChild( wxEnumProperty(_("Style"),emptyString,
gs_fp_es_style_labels,gs_fp_es_style_values,m_value_wxFont.GetStyle()) );
AddChild( wxEnumProperty(_("Weight"),emptyString,
gs_fp_es_weight_labels,gs_fp_es_weight_values,m_value_wxFont.GetWeight()) );
AddChild( wxBoolProperty(_("Underlined"),emptyString,
m_value_wxFont.GetUnderlined()) );
}
wxFontPropertyClass::~wxFontPropertyClass () { }
void wxFontPropertyClass::DoSetValue( wxPGVariant value )
{
const wxFont* font = wxPGVariantToWxObjectPtr(value,wxFont);
if ( font && font->Ok() )
m_value_wxFont = *font;
else
m_value_wxFont = wxFont(10,wxSWISS,wxNORMAL,wxNORMAL);
RefreshChildren();
}
wxPGVariant wxFontPropertyClass::DoGetValue() const
{
return wxPGVariantCreator(m_value_wxFont);
}
wxString wxFontPropertyClass::GetValueAsString( int argFlags ) const
{
return wxPGPropertyWithChildren::GetValueAsString(argFlags);
}
bool wxFontPropertyClass::OnEvent( wxPropertyGrid* propgrid, wxWindow* primary,
wxEvent& event )
{
if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
{
// Update value from last minute changes
PrepareValueForDialogEditing(propgrid);
wxFontData data;
data.SetInitialFont(m_value_wxFont);
data.SetColour(*wxBLACK);
wxFontDialog dlg(propgrid, data);
if ( dlg.ShowModal() == wxID_OK )
{
propgrid->EditorsValueWasModified();
wxFontData retData = dlg.GetFontData();
wxFont font = retData.GetChosenFont();
DoSetValue(wxPGVariantCreator(font));
UpdateControl(primary);
return true;
}
}
return false;
}
void wxFontPropertyClass::RefreshChildren()
{
if ( !GetCount() ) return;
Item(0)->DoSetValue( (long)m_value_wxFont.GetPointSize() );
Item(1)->DoSetValue( (long)m_value_wxFont.GetFamily() );
Item(2)->SetValueFromString( m_value_wxFont.GetFaceName(), wxPG_FULL_VALUE );
Item(3)->DoSetValue( (long)m_value_wxFont.GetStyle() );
Item(4)->DoSetValue( (long)m_value_wxFont.GetWeight() );
Item(5)->DoSetValue( m_value_wxFont.GetUnderlined() );
}
void wxFontPropertyClass::ChildChanged( wxPGProperty* p )
{
wxASSERT( this == p->GetParent() );
int ind = p->GetIndexInParent();
if ( ind == 0 )
{
m_value_wxFont.SetPointSize( wxPGVariantToLong(p->DoGetValue()) );
}
else if ( ind == 1 )
{
int fam = p->DoGetValue().GetLong();
if ( fam < wxDEFAULT ||
fam > wxTELETYPE )
fam = wxDEFAULT;
m_value_wxFont.SetFamily( fam );
}
else if ( ind == 2 )
{
m_value_wxFont.SetFaceName( p->GetValueAsString(wxPG_FULL_VALUE) );
}
else if ( ind == 3 )
{
int st = wxPGVariantToLong(p->DoGetValue());
if ( st != wxFONTSTYLE_NORMAL &&
st != wxFONTSTYLE_SLANT &&
st != wxFONTSTYLE_ITALIC )
st = wxFONTWEIGHT_NORMAL;
m_value_wxFont.SetStyle( st );
}
else if ( ind == 4 )
{
int wt = wxPGVariantToLong(p->DoGetValue());
if ( wt != wxFONTWEIGHT_NORMAL &&
wt != wxFONTWEIGHT_LIGHT &&
wt != wxFONTWEIGHT_BOLD )
wt = wxFONTWEIGHT_NORMAL;
m_value_wxFont.SetWeight( wt );
}
else if ( ind == 5 )
{
m_value_wxFont.SetUnderlined( wxPGVariantToBool(p->DoGetValue())?true:false );
}
}
/*
wxSize wxFontPropertyClass::GetImageSize() const
{
return wxSize(-1,-1);
}
void wxFontPropertyClass::OnCustomPaint(wxDC& dc,
const wxRect& rect,
wxPGPaintData& paintData)
{
wxString drawFace;
if ( paintData.m_choiceItem >= 0 )
drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
else
drawFace = m_value_wxFont.GetFaceName();
if ( drawFace.length() )
{
// Draw the background
dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
//dc.SetBrush( *wxWHITE_BRUSH );
//dc.SetPen( *wxMEDIUM_GREY_PEN );
dc.DrawRectangle( rect );
wxFont oldFont = dc.GetFont();
wxFont drawFont(oldFont.GetPointSize(),
wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
dc.SetFont(drawFont);
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
dc.SetFont(oldFont);
}
else
{
// No file - just draw a white box
dc.SetBrush ( *wxWHITE_BRUSH );
dc.DrawRectangle ( rect );
}
}
*/
// -----------------------------------------------------------------------
// wxSystemColourProperty
// -----------------------------------------------------------------------
// wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
#define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
#include <wx/colordlg.h>
//#define wx_cp_es_syscolours_len 25
static const wxChar* gs_cp_es_syscolour_labels[] = {
wxT("AppWorkspace"),
wxT("ActiveBorder"),
wxT("ActiveCaption"),
wxT("ButtonFace"),
wxT("ButtonHighlight"),
wxT("ButtonShadow"),
wxT("ButtonText"),
wxT("CaptionText"),
wxT("ControlDark"),
wxT("ControlLight"),
wxT("Desktop"),
wxT("GrayText"),
wxT("Highlight"),
wxT("HighlightText"),
wxT("InactiveBorder"),
wxT("InactiveCaption"),
wxT("InactiveCaptionText"),
wxT("Menu"),
wxT("Scrollbar"),
wxT("Tooltip"),
wxT("TooltipText"),
wxT("Window"),
wxT("WindowFrame"),
wxT("WindowText"),
wxT("Custom"),
(const wxChar*) NULL
};
static long gs_cp_es_syscolour_values[] = {
wxSYS_COLOUR_APPWORKSPACE,
wxSYS_COLOUR_ACTIVEBORDER,
wxSYS_COLOUR_ACTIVECAPTION,
wxSYS_COLOUR_BTNFACE,
wxSYS_COLOUR_BTNHIGHLIGHT,
wxSYS_COLOUR_BTNSHADOW,
wxSYS_COLOUR_BTNTEXT ,
wxSYS_COLOUR_CAPTIONTEXT,
wxSYS_COLOUR_3DDKSHADOW,
wxSYS_COLOUR_3DLIGHT,
wxSYS_COLOUR_BACKGROUND,
wxSYS_COLOUR_GRAYTEXT,
wxSYS_COLOUR_HIGHLIGHT,
wxSYS_COLOUR_HIGHLIGHTTEXT,
wxSYS_COLOUR_INACTIVEBORDER,
wxSYS_COLOUR_INACTIVECAPTION,
wxSYS_COLOUR_INACTIVECAPTIONTEXT,
wxSYS_COLOUR_MENU,
wxSYS_COLOUR_SCROLLBAR,
wxSYS_COLOUR_INFOBK,
wxSYS_COLOUR_INFOTEXT,
wxSYS_COLOUR_WINDOW,
wxSYS_COLOUR_WINDOWFRAME,
wxSYS_COLOUR_WINDOWTEXT,
wxPG_COLOUR_CUSTOM
};
// Class body is in advprops.h
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty,wxEnumProperty,
wxColourPropertyValue,const wxColourPropertyValue&,Choice)
void wxSystemColourPropertyClass::Init( int type, const wxColour& colour )
{
m_value.m_type = type;
if ( colour.Ok() )
m_value.m_colour = colour;
else
m_value.m_colour = *wxWHITE;
m_flags |= wxPG_PROP_STATIC_CHOICES; // Colour selection cannot be changed.
}
static wxPGChoices gs_wxSystemColourProperty_choicesCache;
wxSystemColourPropertyClass::wxSystemColourPropertyClass( const wxString& label, const wxString& name,
const wxColourPropertyValue& value )
: wxEnumPropertyClass( label,
name,
gs_cp_es_syscolour_labels,
gs_cp_es_syscolour_values,
&gs_wxSystemColourProperty_choicesCache )
{
wxPG_INIT_REQUIRED_TYPE(wxColourPropertyValue)
if ( &value )
Init(value.m_type,value.m_colour);
else
Init(0,*wxBLACK);
DoSetValue( &m_value );
}
wxSystemColourPropertyClass::wxSystemColourPropertyClass( const wxString& label, const wxString& name,
const wxChar** labels, const long* values, wxPGChoices* choicesCache,
const wxColourPropertyValue& value )
: wxEnumPropertyClass( label, name, labels, values, choicesCache )
{
if ( &value )
Init(value.m_type,value.m_colour);
else
Init(wxPG_COLOUR_CUSTOM,*wxBLACK);
}
wxSystemColourPropertyClass::wxSystemColourPropertyClass( const wxString& label, const wxString& name,
const wxChar** labels, const long* values, wxPGChoices* choicesCache,
const wxColour& value )
: wxEnumPropertyClass( label, name, labels, values, choicesCache )
{
Init(wxPG_COLOUR_CUSTOM,value);
}
wxSystemColourPropertyClass::~wxSystemColourPropertyClass() { }
int wxSystemColourPropertyClass::ColToInd( const wxColour& colour )
{
size_t i;
size_t i_max = m_choices.GetCount() - 1;
if ( !colour.Ok() )
return wxNOT_FOUND;
long pixval = wxPG_COLOUR(colour.Red(),colour.Green(),colour.Blue());
const wxArrayInt& arrValues = m_choices.GetValues();
for ( i=0; i<i_max; i++ )
{
int ind = i;
if ( arrValues.GetCount() )
ind = arrValues[i];
if ( GetColour(ind) == pixval )
{
/*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
GetClassName(),GetLabel().c_str(),
(int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
(int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
return ind;
}
}
return wxNOT_FOUND;
}
static inline wxColour wxColourFromPGLong( long col )
{
return wxColour((col&0xFF),((col>>8)&0xFF),((col>>16)&0xFF));
}
void wxSystemColourPropertyClass::DoSetValue( wxPGVariant value )
{
wxColourPropertyValue* pval = wxPGVariantToWxObjectPtr(value,wxColourPropertyValue);
m_flags &= ~(wxPG_PROP_UNSPECIFIED);
if ( pval != (wxColourPropertyValue*) NULL )
{
if ( !pval->m_colour.Ok() )
{
m_flags |= wxPG_PROP_UNSPECIFIED;
m_index = wxNOT_FOUND;
m_value.Init( wxPG_COLOUR_CUSTOM, *wxWHITE );
return;
}
else if ( pval != &m_value )
{
m_value = *pval;
}
}
else
{
m_value.Init( wxPG_COLOUR_CUSTOM, *wxWHITE );
}
if ( m_value.m_type < wxPG_COLOUR_WEB_BASE )
{
m_value.m_colour = GetColour( m_value.m_type );
wxEnumPropertyClass::DoSetValue( (long)m_value.m_type );
}
else
{
m_index = m_choices.GetCount()-1;
}
}
long wxSystemColourPropertyClass::GetColour( int index )
{
wxColour colour = wxSystemSettings::GetColour ( (wxSystemColour)index );
return wxPG_COLOUR(colour.Red(),colour.Green(),colour.Blue());
}
wxPGVariant wxSystemColourPropertyClass::DoGetValue() const
{
return wxPGVariantCreator(&m_value);
}
wxString wxSystemColourPropertyClass::GetValueAsString( int argFlags ) const
{
// Always show custom colour for non-choice editor
// Assumes changed editor means its textctrl based...
if ( m_value.m_type == wxPG_COLOUR_CUSTOM ||
(argFlags & wxPG_PROPERTY_SPECIFIC) )
{
/*#ifdef __WXDEBUG__
// Sanity check
if ( m_value.m_type != wxPG_COLOUR_CUSTOM &&
(GetEditorClass() == wxPG_EDITOR(Choice) ||
GetEditorClass() == wxPG_EDITOR(ChoiceAndButton)) )
{
wxLogDebug(wxT("wxSystemColourPropertyClass: Assumed wrong editor type!!!"));
}
#endif*/
return wxString::Format(wxT("(%i,%i,%i)"),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -