X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cba2db0c2969f9b83e8a1736e260d22200e99a99..a92b0cfd2bd0bef75b43c071df0b0e028f360d8e:/src/generic/prop.cpp diff --git a/src/generic/prop.cpp b/src/generic/prop.cpp index a353201fcc..028427d935 100644 --- a/src/generic/prop.cpp +++ b/src/generic/prop.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -20,30 +20,19 @@ #pragma hdrstop #endif +#if wxUSE_PROPSHEET + #ifndef WX_PRECOMP -#include "wx/wx.h" #endif +#include "wx/debug.h" +#include "wx/prop.h" + #include #include #include #include -#if wxUSE_IOSTREAMH -#if defined(__WXMSW__) && !defined(__GNUWIN32__) -#include -#else -#include -#endif -#else -#include -#endif - -#include "wx/window.h" -#include "wx/utils.h" -#include "wx/list.h" -#include "wx/debug.h" -#include "wx/prop.h" IMPLEMENT_DYNAMIC_CLASS(wxPropertyValue, wxObject) @@ -59,11 +48,12 @@ wxPropertyValue::wxPropertyValue(void) wxPropertyValue::wxPropertyValue(const wxPropertyValue& copyFrom) { + m_value.string = (wxChar*) NULL; m_modifiedFlag = FALSE; Copy((wxPropertyValue& )copyFrom); } -wxPropertyValue::wxPropertyValue(const char *val) +wxPropertyValue::wxPropertyValue(const wxChar *val) { m_modifiedFlag = FALSE; m_type = wxPropertyValueString; @@ -79,7 +69,7 @@ wxPropertyValue::wxPropertyValue(const wxString& val) m_modifiedFlag = FALSE; m_type = wxPropertyValueString; - m_value.string = copystring((const char *)val); + m_value.string = copystring((const wxChar *)val); m_clientData = NULL; m_next = NULL; m_last = NULL; @@ -122,7 +112,7 @@ wxPropertyValue::wxPropertyValue(double the_real) } // Pointer versions: we have a pointer to the real C++ value. -wxPropertyValue::wxPropertyValue(char **val) +wxPropertyValue::wxPropertyValue(wxChar **val) { m_modifiedFlag = FALSE; m_type = wxPropertyValueStringPtr; @@ -190,7 +180,7 @@ wxPropertyValue::wxPropertyValue(wxStringList *the_list) wxNode *node = the_list->First(); while (node) { - char *s = (char *)node->Data(); + wxChar *s = (wxChar *)node->Data(); Append(new wxPropertyValue(s)); node = node->Next(); } @@ -254,7 +244,7 @@ void wxPropertyValue::Insert(wxPropertyValue *expr) void wxPropertyValue::Delete(wxPropertyValue *node) { wxPropertyValue *expr = GetFirst(); - + wxPropertyValue *previous = NULL; while (expr && (expr != node)) { @@ -266,7 +256,7 @@ void wxPropertyValue::Delete(wxPropertyValue *node) { if (previous) previous->m_next = expr->m_next; - + // If node was the first in the list, // make the list point to the NEXT one. if (GetFirst() == expr) @@ -339,10 +329,8 @@ wxPropertyValue *wxPropertyValue::NewCopy(void) const case wxPropertyValueStringPtr: return new wxPropertyValue(m_value.stringPtr); - case wxPropertyValueNull: -#ifdef __X__ - cerr << "Should never get here!\n"; -#endif + case wxPropertyValueNull: + wxFAIL_MSG( wxT("Should never get here!\n" ) ); break; } return NULL; @@ -350,6 +338,11 @@ wxPropertyValue *wxPropertyValue::NewCopy(void) const void wxPropertyValue::Copy(wxPropertyValue& copyFrom) { + if (m_type == wxPropertyValueString) + { + delete[] m_value.string ; + m_value.string = NULL; + } m_type = copyFrom.Type(); switch (m_type) @@ -361,11 +354,11 @@ void wxPropertyValue::Copy(wxPropertyValue& copyFrom) case wxPropertyValueReal: (*this) = copyFrom.RealValue(); return ; - + case wxPropertyValueString: (*this) = wxString(copyFrom.StringValue()); return ; - + case wxPropertyValuebool: (*this) = copyFrom.BoolValue(); return ; @@ -382,11 +375,22 @@ void wxPropertyValue::Copy(wxPropertyValue& copyFrom) return ; case wxPropertyValueStringPtr: { - char** s = copyFrom.StringValuePtr(); + wxChar** s = copyFrom.StringValuePtr(); + +#if 0 + // what is this? are you trying to assign a bool or a string? VA can't figure it out.. +#if defined(__VISAGECPP__) || defined( __VISUALC__ ) (*this) = s; +#else + (*this) = s != 0; +#endif +#endif // if 0 + + (*this) = (bool)(s != 0); + return ; } - + case wxPropertyValueList: { m_value.first = NULL; @@ -401,10 +405,8 @@ void wxPropertyValue::Copy(wxPropertyValue& copyFrom) } return; } - case wxPropertyValueNull: -#ifdef __X__ - cerr << "Should never get here!\n"; -#endif + case wxPropertyValueNull: + wxFAIL_MSG( wxT("Should never get here!\n" ) ); break; } } @@ -457,7 +459,7 @@ int wxPropertyValue::Number(void) const return i; } -void wxPropertyValue::WritePropertyClause(ostream& stream) // Write this expression as a top-level clause +void wxPropertyValue::WritePropertyClause(wxString& stream) // Write this expression as a top-level clause { if (m_type != wxPropertyValueList) return; @@ -466,90 +468,78 @@ void wxPropertyValue::WritePropertyClause(ostream& stream) // Write this expres if (node) { node->WritePropertyType(stream); - stream << "("; + stream.Append( wxT("(") ); node = node->m_next; bool first = TRUE; while (node) { if (!first) - stream << " "; + stream.Append( wxT(" ") ); node->WritePropertyType(stream); node = node->m_next; - if (node) stream << ",\n"; + if (node) + stream.Append( wxT(",\n" ) ); first = FALSE; } - stream << ").\n\n"; + stream.Append( wxT(").\n\n") ); } } -void wxPropertyValue::WritePropertyType(ostream& stream) // Write as any other subexpression +void wxPropertyValue::WritePropertyType(wxString& stream) // Write as any other subexpression { + wxString tmp; switch (m_type) { case wxPropertyValueInteger: { - stream << m_value.integer; + tmp.Printf( wxT("%ld"), m_value.integer ); + stream.Append( tmp ); break; } case wxPropertyValueIntegerPtr: { - stream << *m_value.integerPtr; + tmp.Printf( wxT("%ld"), *m_value.integerPtr ); + stream.Append( tmp ); break; } case wxPropertyValuebool: { if (m_value.integer) - stream << "True"; + stream.Append( wxT("True") ); else - stream << "False"; + stream.Append( wxT("False") ); break; } case wxPropertyValueboolPtr: { if (*m_value.integerPtr) - stream << "True"; + stream.Append( wxT("True") ); else - stream << "False"; + stream.Append( wxT("False") ); break; } case wxPropertyValueReal: { - float f = m_value.real; - sprintf(wxBuffer, "%.6g", (double)f); - stream << wxBuffer; + double d = m_value.real; + tmp.Printf( wxT("%.6g"), d ); + stream.Append( tmp ); break; } case wxPropertyValueRealPtr: { - float f = *m_value.realPtr; -/* Now the parser can cope with this. - // Prevent printing in 'e' notation. Any better way? - if (fabs(f) < 0.00001) - f = 0.0; -*/ - sprintf(wxBuffer, "%.6g", f); - stream << wxBuffer; + double d = *m_value.realPtr; + tmp.Printf( wxT("%.6g"), d ); + stream.Append( tmp ); break; } case wxPropertyValueString: { -// stream << "\""; - int i; - int len = strlen(m_value.string); - for (i = 0; i < len; i++) - { - char ch = m_value.string[i]; -// if (ch == '"' || ch == '\\') -// stream << "\\"; - stream << ch; - } - -// stream << "\""; + stream.Append( m_value.string ); break; } case wxPropertyValueStringPtr: { - wxFAIL_MSG( "wxPropertyValue::WritePropertyType( wxPropertyValueStringPtr ) not implemented" ); + wxFAIL_MSG( wxT("wxPropertyValue::WritePropertyType( wxPropertyValueStringPtr ) not implemented") ); /* int i; int len = strlen(*(m_value.stringPtr)); @@ -564,19 +554,20 @@ void wxPropertyValue::WritePropertyType(ostream& stream) // Write as any othe case wxPropertyValueList: { if (!m_value.first) - stream << "[]"; + stream.Append( wxT("[]") ); else { wxPropertyValue *expr = m_value.first; - stream << "["; + stream.Append( wxT("[") ); while (expr) { expr->WritePropertyType(stream); expr = expr->m_next; - if (expr) stream << ", "; + if (expr) + stream.Append( wxT(", ") ); } - stream << "]"; + stream.Append( wxT("]") ); } break; } @@ -586,16 +577,9 @@ void wxPropertyValue::WritePropertyType(ostream& stream) // Write as any othe wxString wxPropertyValue::GetStringRepresentation(void) { - char buf[500]; - buf[0] = 0; - - ostrstream str((char *)buf, (int)500, ios::out); + wxString str; WritePropertyType(str); - str << '\0'; - str.flush(); - - wxString theString(buf); - return theString; + return str; } void wxPropertyValue::operator=(const wxPropertyValue& val) @@ -607,9 +591,17 @@ void wxPropertyValue::operator=(const wxPropertyValue& val) // void wxPropertyValue::operator=(const char *val) void wxPropertyValue::operator=(const wxString& val1) { - const char *val = (const char *)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; @@ -622,14 +614,13 @@ void wxPropertyValue::operator=(const wxString& val1) } else if (m_type == wxPropertyValueStringPtr) { - if (*m_value.stringPtr) - delete[] *m_value.stringPtr; + 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; @@ -638,6 +629,13 @@ void wxPropertyValue::operator=(const wxString& val1) 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; @@ -657,6 +655,13 @@ void wxPropertyValue::operator=(const long val) 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; @@ -672,6 +677,13 @@ void wxPropertyValue::operator=(const bool val) 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; @@ -689,13 +701,20 @@ void wxPropertyValue::operator=(const float val) m_next = NULL; } -void wxPropertyValue::operator=(const char **val) +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 = (char **)val; + m_value.stringPtr = (wxChar **)val; else m_value.stringPtr = NULL; m_clientData = NULL; @@ -787,7 +806,7 @@ bool *wxPropertyValue::BoolValuePtr(void) const return m_value.boolPtr; } -char *wxPropertyValue::StringValue(void) const { +wxChar *wxPropertyValue::StringValue(void) const { if (m_type == wxPropertyValueString) return m_value.string; else if (m_type == wxPropertyValueStringPtr) @@ -795,7 +814,7 @@ char *wxPropertyValue::StringValue(void) const { else return NULL; } -char **wxPropertyValue::StringValuePtr(void) const +wxChar **wxPropertyValue::StringValuePtr(void) const { return m_value.stringPtr; } @@ -803,7 +822,7 @@ char **wxPropertyValue::StringValuePtr(void) const /* * A property (name plus value) */ - + IMPLEMENT_DYNAMIC_CLASS(wxProperty, wxObject) wxProperty::wxProperty(void) @@ -893,7 +912,7 @@ void wxProperty::operator=(const wxPropertyValue& val) /* * Base property view class */ - + IMPLEMENT_DYNAMIC_CLASS(wxPropertyView, wxEvtHandler) wxPropertyView::wxPropertyView(long flags) @@ -917,7 +936,7 @@ wxPropertyValidator *wxPropertyView::FindPropertyValidator(wxProperty *property) { if (property->GetValidator()) return property->GetValidator(); - + wxNode *node = m_validatorRegistryList.First(); while (node) { @@ -951,16 +970,6 @@ wxPropertySheet::~wxPropertySheet(void) Clear(); } -bool wxPropertySheet::Save( ostream& WXUNUSED(str) ) -{ - return FALSE; -} - -bool wxPropertySheet::Load( ostream& WXUNUSED(str) ) -{ - return FALSE; -} - void wxPropertySheet::UpdateAllViews( wxPropertyView *WXUNUSED(thisView) ) { } @@ -968,13 +977,13 @@ void wxPropertySheet::UpdateAllViews( wxPropertyView *WXUNUSED(thisView) ) // Add a property void wxPropertySheet::AddProperty(wxProperty *property) { - m_properties.Append((const char*) property->GetName(), property); + m_properties.Append((const wxChar*) property->GetName(), property); } // Get property by name wxProperty *wxPropertySheet::GetProperty(const wxString& name) const { - wxNode *node = m_properties.Find((const char*) name); + wxNode *node = m_properties.Find((const wxChar*) name); if (!node) return NULL; else @@ -998,14 +1007,14 @@ void wxPropertySheet::RemoveProperty(const wxString& name) if(node) { wxProperty *prop = (wxProperty *)node->Data(); - delete prop; + delete prop; m_properties.DeleteNode(node); } -} +} bool wxPropertySheet::HasProperty(const wxString& name) const -{ - return (GetProperty(name)?TRUE:FALSE); +{ + return (GetProperty(name)?TRUE:FALSE); } // Clear all properties @@ -1031,7 +1040,7 @@ void wxPropertySheet::SetAllModified(bool flag) wxProperty *prop = (wxProperty *)node->Data(); prop->GetValue().SetModified(flag); node = node->Next(); - } + } } /* @@ -1052,19 +1061,19 @@ wxPropertyValidatorRegistry::~wxPropertyValidatorRegistry(void) void wxPropertyValidatorRegistry::RegisterValidator(const wxString& typeName, wxPropertyValidator *validator) { - Put((const char*) typeName, validator); + Put((const wxChar*) typeName, validator); } wxPropertyValidator *wxPropertyValidatorRegistry::GetValidator(const wxString& typeName) { - return (wxPropertyValidator *)Get((const char*) typeName); + return (wxPropertyValidator *)Get((const wxChar*) typeName); } void wxPropertyValidatorRegistry::ClearRegistry(void) { BeginFind(); wxNode *node; - while ((node = Next())) + while ((node = Next()) != NULL) { delete (wxPropertyValidator *)node->Data(); } @@ -1086,66 +1095,66 @@ wxPropertyValidator::wxPropertyValidator(long flags) wxPropertyValidator::~wxPropertyValidator(void) {} -bool wxPropertyValidator::StringToFloat (char *s, float *number) { - double num; - bool ok = StringToDouble (s, &num); - *number = (float) num; - return ok; +bool wxPropertyValidator::StringToFloat (wxChar *s, float *number) { + double num; + bool ok = StringToDouble (s, &num); + *number = (float) num; + return ok; } -bool wxPropertyValidator::StringToDouble (char *s, double *number) { +bool wxPropertyValidator::StringToDouble (wxChar *s, double *number) { bool ok = TRUE; - char *value_ptr; - *number = strtod (s, &value_ptr); + wxChar *value_ptr; + *number = wxStrtod (s, &value_ptr); if (value_ptr) { - int len = strlen (value_ptr); - for (int i = 0; i < len; i++) { - ok = (isspace (value_ptr[i]) != 0); - if (!ok) return FALSE; - } + 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 (char *s, int *number) { - long num; - bool ok = StringToLong (s, &num); - *number = (int) num; - return ok; +bool wxPropertyValidator::StringToInt (wxChar *s, int *number) { + long num; + bool ok = StringToLong (s, &num); + *number = (int) num; + return ok; } -bool wxPropertyValidator::StringToLong (char *s, long *number) { +bool wxPropertyValidator::StringToLong (wxChar *s, long *number) { bool ok = TRUE; - char *value_ptr; - *number = strtol (s, &value_ptr, 10); + wxChar *value_ptr; + *number = wxStrtol (s, &value_ptr, 10); if (value_ptr) { - int len = strlen (value_ptr); - for (int i = 0; i < len; i++) { - ok = (isspace (value_ptr[i]) != 0); - if (!ok) return FALSE; - } + int len = wxStrlen (value_ptr); + for (int i = 0; i < len; i++) { + ok = (wxIsspace (value_ptr[i]) != 0); + if (!ok) return FALSE; + } } return ok; } -char *wxPropertyValidator::FloatToString (float number) { - static char buf[20]; - sprintf (buf, "%.6g", number); - return buf; +wxChar *wxPropertyValidator::FloatToString (float number) { + static wxChar buf[20]; + wxSprintf (buf, wxT("%.6g"), number); + return buf; } -char *wxPropertyValidator::DoubleToString (double number) { - static char buf[20]; - sprintf (buf, "%.6g", number); - return buf; +wxChar *wxPropertyValidator::DoubleToString (double number) { + static wxChar buf[20]; + wxSprintf (buf, wxT("%.6g"), number); + return buf; } -char *wxPropertyValidator::IntToString (int number) { - return ::IntToString (number); +wxChar *wxPropertyValidator::IntToString (int number) { + return ::IntToString (number); } -char *wxPropertyValidator::LongToString (long number) { - return ::LongToString (number); +wxChar *wxPropertyValidator::LongToString (long number) { + return ::LongToString (number); } - +#endif // wxUSE_PROPSHEET