📄 prop.cpp
字号:
}void wxPropertyValue::operator=(const wxPropertyValue& val){ m_modifiedFlag = true; Copy((wxPropertyValue&)val);}// void wxPropertyValue::operator=(const char *val)void wxPropertyValue::operator=(const wxString& val1){ const wxChar *val = (const wxChar *)val1; m_modifiedFlag = true; wxPropertyValueType oldType = m_type; if (oldType == wxPropertyValueString) { delete[] m_value.string ; m_value.string = NULL; } if (m_type == wxPropertyValueNull) m_type = wxPropertyValueString; if (m_type == wxPropertyValueString) { if (val) m_value.string = copystring(val); else m_value.string = NULL; } else if (m_type == wxPropertyValueStringPtr) { wxFAIL_MSG( wxT("Shouldn't try to assign a wxString reference to a char* pointer.") ); if (val) *m_value.stringPtr = copystring(val); else *m_value.stringPtr = NULL; } m_clientData = NULL; m_next = NULL; m_last = NULL;}void wxPropertyValue::operator=(const long val){ wxPropertyValueType oldType = m_type; if (oldType == wxPropertyValueString) { delete[] m_value.string ; m_value.string = NULL; } m_modifiedFlag = true; if (m_type == wxPropertyValueNull) m_type = wxPropertyValueInteger; if (m_type == wxPropertyValueInteger) m_value.integer = val; else if (m_type == wxPropertyValueIntegerPtr) *m_value.integerPtr = val; else if (m_type == wxPropertyValueReal) m_value.real = (float)val; else if (m_type == wxPropertyValueRealPtr) *m_value.realPtr = (float)val; m_clientData = NULL; m_next = NULL;}void wxPropertyValue::operator=(const bool val){ wxPropertyValueType oldType = m_type; if (oldType == wxPropertyValueString) { delete[] m_value.string ; m_value.string = NULL; } m_modifiedFlag = true; if (m_type == wxPropertyValueNull) m_type = wxPropertyValuebool; if (m_type == wxPropertyValuebool) m_value.integer = (long)val; else if (m_type == wxPropertyValueboolPtr) *m_value.boolPtr = val; m_clientData = NULL; m_next = NULL;}void wxPropertyValue::operator=(const float val){ wxPropertyValueType oldType = m_type; if (oldType == wxPropertyValueString) { delete[] m_value.string ; m_value.string = NULL; } m_modifiedFlag = true; if (m_type == wxPropertyValueNull) m_type = wxPropertyValueReal; if (m_type == wxPropertyValueInteger) m_value.integer = (long)val; else if (m_type == wxPropertyValueIntegerPtr) *m_value.integerPtr = (long)val; else if (m_type == wxPropertyValueReal) m_value.real = val; else if (m_type == wxPropertyValueRealPtr) *m_value.realPtr = val; m_clientData = NULL; m_next = NULL;}void wxPropertyValue::operator=(const wxChar **val){ wxPropertyValueType oldType = m_type; if (oldType == wxPropertyValueString) { delete[] m_value.string ; m_value.string = NULL; } m_modifiedFlag = true; m_type = wxPropertyValueStringPtr; if (val) m_value.stringPtr = (wxChar **)val; else m_value.stringPtr = NULL; m_clientData = NULL; m_next = NULL; m_last = NULL;}void wxPropertyValue::operator=(const long *val){ m_modifiedFlag = true; m_type = wxPropertyValueIntegerPtr; m_value.integerPtr = (long *)val; m_clientData = NULL; m_next = NULL;}void wxPropertyValue::operator=(const bool *val){ m_modifiedFlag = true; m_type = wxPropertyValueboolPtr; m_value.boolPtr = (bool *)val; m_clientData = NULL; m_next = NULL;}void wxPropertyValue::operator=(const float *val){ m_modifiedFlag = true; m_type = wxPropertyValueRealPtr; m_value.realPtr = (float *)val; m_clientData = NULL; m_next = NULL;}long wxPropertyValue::IntegerValue(void) const { if (m_type == wxPropertyValueInteger) return m_value.integer; else if (m_type == wxPropertyValueReal) return (long)m_value.real; else if (m_type == wxPropertyValueIntegerPtr) return *m_value.integerPtr; else if (m_type == wxPropertyValueRealPtr) return (long)(*m_value.realPtr); else return 0; }long *wxPropertyValue::IntegerValuePtr(void) const{ return m_value.integerPtr;}float wxPropertyValue::RealValue(void) const { if (m_type == wxPropertyValueReal) return m_value.real; else if (m_type == wxPropertyValueRealPtr) return *m_value.realPtr; else if (m_type == wxPropertyValueInteger) return (float)m_value.integer; else if (m_type == wxPropertyValueIntegerPtr) return (float)*(m_value.integerPtr); else return 0.0; }float *wxPropertyValue::RealValuePtr(void) const{ return m_value.realPtr;}bool wxPropertyValue::BoolValue(void) const { if (m_type == wxPropertyValueReal) return (m_value.real != 0.0); if (m_type == wxPropertyValueRealPtr) return (*(m_value.realPtr) != 0.0); else if (m_type == wxPropertyValueInteger) return (m_value.integer != 0); else if (m_type == wxPropertyValueIntegerPtr) return (*(m_value.integerPtr) != 0); else if (m_type == wxPropertyValuebool) return (m_value.integer != 0); else if (m_type == wxPropertyValueboolPtr) return (*(m_value.boolPtr) != 0); else return false; }bool *wxPropertyValue::BoolValuePtr(void) const{ return m_value.boolPtr;}wxChar *wxPropertyValue::StringValue(void) const { if (m_type == wxPropertyValueString) return m_value.string; else if (m_type == wxPropertyValueStringPtr) return *(m_value.stringPtr); else return NULL; }wxChar **wxPropertyValue::StringValuePtr(void) const{ return m_value.stringPtr;}/* * A property (name plus value) */IMPLEMENT_DYNAMIC_CLASS(wxProperty, wxObject)wxProperty::wxProperty(void){ m_propertyRole = wxEmptyString; m_propertyValidator = NULL; m_propertyWindow = NULL; m_enabled = true;}wxProperty::wxProperty(wxProperty& copyFrom) : wxObject(){ m_value = copyFrom.GetValue(); m_name = copyFrom.GetName(); m_propertyRole = copyFrom.GetRole(); m_propertyValidator = copyFrom.GetValidator(); m_enabled = copyFrom.IsEnabled(); m_propertyWindow = NULL;}wxProperty::wxProperty(wxString nm, wxString role, wxPropertyValidator *ed):m_name(nm), m_propertyRole(role){ m_propertyValidator = ed; m_propertyWindow = NULL; m_enabled = true;}wxProperty::wxProperty(wxString nm, const wxPropertyValue& val, wxString role, wxPropertyValidator *ed): m_value(val), m_name(nm), m_propertyRole(role){ m_propertyValidator = ed; m_propertyWindow = NULL; m_enabled = true;}wxProperty::~wxProperty(void){ if (m_propertyValidator) delete m_propertyValidator;}wxPropertyValue& wxProperty::GetValue(void) const{ return (wxPropertyValue&) m_value;}wxPropertyValidator *wxProperty::GetValidator(void) const{ return m_propertyValidator;}wxString& wxProperty::GetName(void) const{ return (wxString&) m_name;}wxString& wxProperty::GetRole(void) const{ return (wxString&) m_propertyRole;}void wxProperty::SetValue(const wxPropertyValue& val){ m_value = val;}void wxProperty::SetValidator(wxPropertyValidator *ed){ m_propertyValidator = ed;}void wxProperty::SetRole(wxString& role){ m_propertyRole = role;}void wxProperty::SetName(wxString& nm){ m_name = nm;}void wxProperty::operator=(const wxPropertyValue& val){ m_value = val;}/* * Base property view class */IMPLEMENT_DYNAMIC_CLASS(wxPropertyView, wxEvtHandler)wxPropertyView::wxPropertyView(long flags){ m_buttonFlags = flags; m_propertySheet = NULL; m_currentValidator = NULL; m_currentProperty = NULL;}wxPropertyView::~wxPropertyView(void){}void wxPropertyView::AddRegistry(wxPropertyValidatorRegistry *registry){ m_validatorRegistryList.Append(registry);}wxPropertyValidator *wxPropertyView::FindPropertyValidator(wxProperty *property){ if (property->GetValidator()) return property->GetValidator(); wxObjectList::compatibility_iterator node = m_validatorRegistryList.GetFirst(); while (node) { wxPropertyValidatorRegistry *registry = (wxPropertyValidatorRegistry *)node->GetData(); wxPropertyValidator *validator = registry->GetValidator(property->GetRole()); if (validator) return validator; node = node->GetNext(); } return NULL;/* if (!wxDefaultPropertyValidator) wxDefaultPropertyValidator = new wxPropertyListValidator; return wxDefaultPropertyValidator;*/}/* * Property sheet */IMPLEMENT_DYNAMIC_CLASS(wxPropertySheet, wxObject)wxPropertySheet::wxPropertySheet(const wxString& name):m_properties(wxKEY_STRING),m_name(name){}wxPropertySheet::~wxPropertySheet(void){ Clear();}void wxPropertySheet::UpdateAllViews( wxPropertyView *WXUNUSED(thisView) ){}// Add a propertyvoid wxPropertySheet::AddProperty(wxProperty *property){ m_properties.Append((const wxChar*) property->GetName(), property);}// Get property by namewxProperty *wxPropertySheet::GetProperty(const wxString& name) const{ wxObjectList::compatibility_iterator node = m_properties.Find((const wxChar*) name); if (!node) return NULL; else return (wxProperty *)node->GetData();}bool wxPropertySheet::SetProperty(const wxString& name, const wxPropertyValue& value){ wxProperty* prop = GetProperty(name); if(prop){ prop->SetValue(value); return true; }else{ return false; }}void wxPropertySheet::RemoveProperty(const wxString& name){ wxObjectList::compatibility_iterator node = m_properties.Find(name); if(node) { wxProperty *prop = (wxProperty *)node->GetData(); delete prop; m_properties.Erase(node); }}bool wxPropertySheet::HasProperty(const wxString& name) const{ return (GetProperty(name)?true:false);}// Clear all propertiesvoid wxPropertySheet::Clear(void){ wxObjectList::compatibility_iterator node = m_properties.GetFirst(); while (node) { wxProperty *prop = (wxProperty *)node->GetData(); delete prop; node = node->GetNext(); } m_properties.Clear();}// Sets/clears the modified flag for each property valuevoid wxPropertySheet::SetAllModified(bool flag){ wxObjectList::compatibility_iterator node = m_properties.GetFirst(); while (node) { wxProperty *prop = (wxProperty *)node->GetData(); prop->GetValue().SetModified(flag); node = node->GetNext(); }}/* * Property validator registry * */IMPLEMENT_DYNAMIC_CLASS(wxPropertyValidatorRegistry, wxHashTable)wxPropertyValidatorRegistry::wxPropertyValidatorRegistry(void):wxHashTable(wxKEY_STRING){}wxPropertyValidatorRegistry::~wxPropertyValidatorRegistry(void){ ClearRegistry();}void wxPropertyValidatorRegistry::RegisterValidator(const wxString& typeName, wxPropertyValidator *validator){ Put((const wxChar*) typeName, validator);}wxPropertyValidator *wxPropertyValidatorRegistry::GetValidator(const wxString& typeName){ return (wxPropertyValidator *)Get((const wxChar*) typeName);}void wxPropertyValidatorRegistry::ClearRegistry(void){ BeginFind(); wxHashTable::Node *node; while ((node = Next()) != NULL) { delete (wxPropertyValidator *)node->GetData(); }} /* * Property validator */IMPLEMENT_ABSTRACT_CLASS(wxPropertyValidator, wxEvtHandler)wxPropertyValidator::wxPropertyValidator(long flags){ m_validatorFlags = flags; m_validatorProperty = NULL;}wxPropertyValidator::~wxPropertyValidator(void){}bool wxPropertyValidator::StringToFloat (wxChar *s, float *number) { double num; bool ok = StringToDouble (s, &num); *number = (float) num; return ok;}bool wxPropertyValidator::StringToDouble (wxChar *s, double *number) { bool ok = true; wxChar *value_ptr; *number = wxStrtod (s, &value_ptr); if (value_ptr) { int len = wxStrlen (value_ptr); for (int i = 0; i < len; i++) { ok = (wxIsspace (value_ptr[i]) != 0); if (!ok) return false; } } return ok;}bool wxPropertyValidator::StringToInt (wxChar *s, int *number) { long num; bool ok = StringToLong (s, &num); *number = (int) num; return ok;}bool wxPropertyValidator::StringToLong (wxChar *s, long *number) { bool ok = true; wxChar *value_ptr; *number = wxStrtol (s, &value_ptr, 10); if (value_ptr) { int len = wxStrlen (value_ptr); for (int i = 0; i < len; i++) { ok = (wxIsspace (value_ptr[i]) != 0); if (!ok) return false; } } return ok;}wxChar *wxPropertyValidator::FloatToString (float number) { static wxChar buf[20]; wxSnprintf (buf, 20, wxT("%.6g"), number); return buf;}wxChar *wxPropertyValidator::DoubleToString (double number) { static wxChar buf[20]; wxSnprintf (buf, 20, wxT("%.6g"), number); return buf;}wxChar *wxPropertyValidator::IntToString (int number) { static wxChar buf[20]; wxSprintf (buf, wxT("%d"), number); return buf;}wxChar *wxPropertyValidator::LongToString (long number) { static wxChar buf[20]; wxSprintf (buf, wxT("%ld"), number); return buf;}#endif // wxUSE_PROPSHEET
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -