📄 widget.cpp
字号:
if ( Colour.Mid(1).ToLong(&Value,0x10) )
{
BaseParams.FgType = wxsCUSTOM_COLOUR;
BaseParams.Fg = wxColour(
( Value >> 16 ) & 0xFF,
( Value >> 8 ) & 0xFF,
Value & 0xFF );
}
}
else
{
for ( int i=0; i<wxsSystemColoursCount; i++ )
{
if ( Colour == wxsSystemColours[i].Name )
{
BaseParams.FgType = wxsSystemColours[i].Value;
BaseParams.Fg = wxSystemSettings::GetColour((wxSystemColour)BaseParams.FgType);
break;
}
}
}
}
Colour = XmlGetVariable(_T("bg"));
Colour.Trim(true).Trim(false);
BaseParams.BgType = wxsNO_COLOUR;
if ( !Colour.empty() )
{
if ( Colour[0] == _T('#') )
{
// Got web colour
long Value = 0;
if ( Colour.Mid(1).ToLong(&Value,0x10) )
{
BaseParams.BgType = wxsCUSTOM_COLOUR;
BaseParams.Bg = wxColour(
( Value >> 16 ) & 0xFF,
( Value >> 8 ) & 0xFF,
Value & 0xFF );
}
}
else
{
for ( int i=0; i<wxsSystemColoursCount; i++ )
{
if ( Colour == wxsSystemColours[i].Name )
{
BaseParams.BgType = wxsSystemColours[i].Value;
BaseParams.Bg = wxSystemSettings::GetColour((wxSystemColour)BaseParams.BgType);
break;
}
}
}
}
}
if ( pType & bptFont )
{
TiXmlElement* Store = XmlElem();
TiXmlElement* Font = Store->FirstChildElement("font");
if ( Font != NULL )
{
XmlAssignElement(Font);
// Loading font stuff
int Size = XmlGetInteger(_T("size"),wxDEFAULT);
wxString Str = XmlGetVariable(_T("style"));
int Style = wxFONTSTYLE_NORMAL;
if ( Str == _T("italic") ) Style = wxFONTSTYLE_ITALIC;
else if ( Str == _T("slant") ) Style = wxFONTSTYLE_SLANT ;
Str = XmlGetVariable(_T("weight"));
int Weight = wxNORMAL;
if ( Str == _T("bold") ) Weight = wxBOLD;
else if ( Str == _T("light") ) Weight = wxLIGHT;
bool Underlined = XmlGetInteger(_T("underlined"),0) != 0;
int Family = wxDEFAULT;
Str = XmlGetVariable(_T("family"));
if (Str == _T("decorative")) Family = wxDECORATIVE;
else if (Str == _T("roman")) Family = wxROMAN;
else if (Str == _T("script")) Family = wxSCRIPT;
else if (Str == _T("swiss")) Family = wxSWISS;
else if (Str == _T("modern")) Family = wxMODERN;
else if (Str == _T("teletype")) Family = wxTELETYPE;
wxString Face = XmlGetVariable(_T("face"));
BaseParams.UseFont = true;
BaseParams.Font = wxFont(Size,Family,Style,Weight,Underlined,Face);
}
else
{
BaseParams.UseFont = false;
BaseParams.Font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
}
XmlAssignElement(Store);
}
if ( IsContainer() )
{
if ( !XmlLoadChildren() ) return false;
}
return true;
}
bool wxsWidget::XmlSaveDefaultsT(BasePropertiesType pType)
{
assert ( XmlElem() != NULL );
if ( GetResource()->GetEditMode() != wxsResFile )
{
GetEvents()->XmlSaveFunctions(XmlElem());
}
if ( pType & bptPosition )
{
if ( !BaseParams.DefaultPosition )
{
XmlSetIntPair(_T("pos"),BaseParams.PosX,BaseParams.PosY);
}
}
if ( pType & bptSize )
{
if ( !BaseParams.DefaultSize )
{
XmlSetIntPair(_T("size"),BaseParams.SizeX,BaseParams.SizeY);
}
}
if ( pType & bptId )
{
XmlElem()->SetAttribute("name",BaseParams.IdName.mb_str());
}
if ( pType & bptVariable )
{
XmlElem()->SetAttribute("variable",BaseParams.VarName.mb_str());
XmlElem()->SetAttribute("member",BaseParams.IsMember?"yes":"no");
}
if ( pType & bptStyle )
{
int StyleBits = BaseParams.Style;
wxString StyleString;
// Warning: This may cause some data los if styles are not
// configured properly
wxsStyle* Style = GetInfo().Styles;
if ( Style )
{
for ( ; Style->Name; Style++ )
{
if ( ( Style->Value != 0 ) && ( ( StyleBits & Style->Value ) == Style->Value ) )
{
StyleString.Append('|');
StyleString.Append(Style->Name);
StyleBits &= ~Style->Value;
}
}
}
if ( StyleString.Len() != 0 )
{
XmlSetVariable(_T("style"),StyleString.c_str()+1);
}
}
if ( pType & bptEnabled )
{
if ( !BaseParams.Enabled ) XmlSetInteger(_T("enabled"),0);
}
if ( pType & bptFocused )
{
if ( BaseParams.Focused ) XmlSetInteger(_T("focused"),1);
}
if ( pType & bptHidden )
{
if ( BaseParams.Hidden ) XmlSetInteger(_T("hiddedn"),1);
}
if ( pType & bptColours )
{
if ( BaseParams.FgType == wxsCUSTOM_COLOUR )
{
XmlSetVariable( _T("fg"),
wxString::Format(_T("#%02X%02X%02X"),
BaseParams.Fg.Red(),
BaseParams.Fg.Green(),
BaseParams.Fg.Blue() ) );
}
else
{
for ( int i=0; i<wxsSystemColoursCount; i++ )
{
if ( BaseParams.FgType == wxsSystemColours[i].Value )
{
XmlSetVariable( _T("fg"), wxsSystemColours[i].Name );
break;
}
}
}
if ( BaseParams.BgType == wxsCUSTOM_COLOUR )
{
XmlSetVariable( _T("bg"),
wxString::Format(_T("#%02X%02X%02X"),
BaseParams.Bg.Red(),
BaseParams.Bg.Green(),
BaseParams.Bg.Blue() ) );
}
else
{
for ( int i=0; i<wxsSystemColoursCount; i++ )
{
if ( BaseParams.BgType == wxsSystemColours[i].Value )
{
XmlSetVariable( _T("bg"), wxsSystemColours[i].Name );
break;
}
}
}
}
if ( pType & bptFont && BaseParams.UseFont )
{
TiXmlElement* Store = XmlElem();
XmlAssignElement(Store->InsertEndChild(TiXmlElement("font"))->ToElement());
wxFont& Font = BaseParams.Font;
XmlSetInteger(_T("size"),Font.GetPointSize());
switch ( Font.GetStyle() )
{
case wxFONTSTYLE_ITALIC: XmlSetVariable(_T("style"),_T("italic")); break;
case wxFONTSTYLE_SLANT : XmlSetVariable(_T("style"),_T("slant")); break;
default:;
}
switch ( Font.GetWeight() )
{
case wxFONTWEIGHT_LIGHT: XmlSetVariable(_T("weight"),_T("light")); break;
case wxFONTWEIGHT_BOLD : XmlSetVariable(_T("weight"),_T("bold")); break;
default:;
}
switch ( Font.GetFamily() )
{
case wxFONTFAMILY_DECORATIVE: XmlSetVariable(_T("family"),_T("decorative")); break;
case wxFONTFAMILY_ROMAN : XmlSetVariable(_T("family"),_T("roman")); break;
case wxFONTFAMILY_SCRIPT : XmlSetVariable(_T("family"),_T("script")); break;
case wxFONTFAMILY_SWISS : XmlSetVariable(_T("family"),_T("swiss")); break;
case wxFONTFAMILY_MODERN : XmlSetVariable(_T("family"),_T("modern")); break;
case wxFONTFAMILY_TELETYPE : XmlSetVariable(_T("family"),_T("teletype")); break;
default:;
}
if ( Font.GetUnderlined() ) XmlSetInteger(_T("underlined"),1);
if ( !Font.GetFaceName().empty() ) XmlSetVariable(_T("face"),Font.GetFaceName());
XmlAssignElement(Store);
}
if ( IsContainer() )
{
if ( !XmlSaveChildren() ) return false;
}
return true;
}
wxString wxsWidget::XmlGetVariable(const wxString& name)
{
assert ( XmlElem() != NULL );
if ( !name || !*name ) return _T("");
TiXmlElement* Elem = XmlElem()->FirstChildElement(name.mb_str());
if ( !Elem ) return _T("");
TiXmlNode* Node = Elem->FirstChild();
while ( Node )
{
TiXmlText* Text = Node->ToText();
if ( Text )
{
return wxString(Text->Value(), wxConvUTF8);
}
Node = Node->NextSibling();
}
return _T("");
}
int wxsWidget::XmlGetInteger(const wxString& name,bool& IsInvalid,int DefaultValue)
{
wxString Tmp = XmlGetVariable(name);
long value;
if ( !Tmp.Length() || !Tmp.ToLong(&value) )
{
IsInvalid = true;
return DefaultValue;
}
IsInvalid = false;
return (int)value;
}
bool wxsWidget::XmlGetIntPair(const wxString& Name,int& P1,int& P2,int DefP1,int DefP2)
{
long _P1, _P2;
wxString Tmp = XmlGetVariable(Name);
if ( Tmp.Length() &&
Tmp.BeforeFirst(_T(',')).ToLong(&_P1) &&
Tmp.AfterLast(_T(',')).ToLong(&_P2) )
{
P1 = (int)_P1;
P2 = (int)_P2;
return true;
}
P1 = DefP1;
P2 = DefP2;
return false;
}
bool wxsWidget::XmlSetVariable(const wxString& Name,const wxString& Value)
{
assert ( XmlElem() != NULL );
TiXmlNode * NewNode = XmlElem()->InsertEndChild(TiXmlElement(Name.mb_str()));
if ( NewNode )
{
NewNode->InsertEndChild(TiXmlText(Value.mb_str()));
return true;
}
return false;
}
bool wxsWidget::XmlSetInteger(const wxString& Name,int Value)
{
return XmlSetVariable(Name,wxString::Format(_T("%d"),Value));
}
bool wxsWidget::XmlSetIntPair(const wxString& Name,int Val1,int Val2)
{
return XmlSetVariable(Name,wxString::Format(_T("%d,%d"),Val1,Val2));
}
bool wxsWidget::XmlLoadChildren()
{
assert ( XmlElem() != NULL );
bool Ret = true;
for ( TiXmlElement* Element = XmlElem()->FirstChildElement();
Element != NULL;
Element = Element->NextSiblingElement() )
{
if ( !XmlLoadChild(Element) )
{
Ret = false;
}
}
return Ret;
}
bool wxsWidget::XmlLoadChild(TiXmlElement* Element)
{
// Processing <object> elements only
if ( strcmp(Element->Value(),"object") ) return true;
const char* Name = Element->Attribute("class");
bool Ret = true;
if ( Name && *Name )
{
wxsWidget* Child = wxsGEN(wxString(Name,wxConvUTF8),GetResource());
if ( !Child )
{
return false;
}
if ( !Child->XmlLoad(Element) ) Ret = false;
if ( AddChild(Child) < 0 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -