X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f8105809ef8f7cb0d1a9933f3f790b7b446c7cfa..e0aeebed0a3003f455e2bd7e962143faa1dde4c8:/utils/configtool/src/configitem.cpp diff --git a/utils/configtool/src/configitem.cpp b/utils/configtool/src/configitem.cpp index ca5c268270..fdf4ceac4f 100644 --- a/utils/configtool/src/configitem.cpp +++ b/utils/configtool/src/configitem.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: configitem.cpp -// Purpose: wxWindows Configuration Tool config item class +// Purpose: wxWidgets Configuration Tool config item class // Author: Julian Smart // Modified by: // Created: 2003-06-03 @@ -9,19 +9,18 @@ // Licence: ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "configitem.h" #endif -// Includes other headers for precompiled compilation -#include "wx/wx.h" +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #include "wx/tokenzr.h" - #include "configitem.h" #include "configtree.h" #include "configtooldoc.h" @@ -33,21 +32,21 @@ IMPLEMENT_CLASS(ctConfigItem, wxObject) ctConfigItem::ctConfigItem() { - m_modified = FALSE; + m_modified = false; m_type = ctTypeBoolCheck; m_treeItemId = wxTreeItemId(); - m_enabled = TRUE; + m_enabled = true; m_parent = NULL; - m_active = TRUE; + m_active = true; } ctConfigItem::ctConfigItem(ctConfigItem* parent, ctConfigType type, const wxString& name) { - m_modified = FALSE; + m_modified = false; m_type = type; m_treeItemId = wxTreeItemId(); - m_enabled = FALSE; - m_active = TRUE; + m_enabled = false; + m_active = true; SetName(name); m_parent = parent; if (parent) @@ -82,7 +81,7 @@ bool ctConfigItem::CanEditProperty(const wxString& propName) const if (prop) return !prop->GetReadOnly(); else - return FALSE; + return false; } /// Assignment operator. @@ -105,10 +104,10 @@ void ctConfigItem::SetName(const wxString& name ) /// Clear children void ctConfigItem::Clear() { - wxNode* node = m_children.GetFirst(); + wxObjectList::compatibility_iterator node = m_children.GetFirst(); while (node) { - wxNode* next = node->GetNext(); + wxObjectList::compatibility_iterator next = node->GetNext(); ctConfigItem* child = (ctConfigItem*) node->GetData(); // This should delete 'node' too, assuming @@ -165,7 +164,7 @@ void ctConfigItem::InitProperties() m_properties.AddProperty(prop); } prop->SetDescription(_("Name

The name of the configuration setting.")); - prop->SetReadOnly(TRUE); + prop->SetReadOnly(true); m_properties.AddProperty( new ctProperty( @@ -176,7 +175,7 @@ void ctConfigItem::InitProperties() m_properties.AddProperty( new ctProperty( wxT("Default-state

The default state."), - wxVariant((bool) TRUE, wxT("default-state")), + wxVariant(true, wxT("default-state")), wxT("bool"))); if (GetType() == ctTypeString) @@ -184,7 +183,7 @@ void ctConfigItem::InitProperties() m_properties.AddProperty( new ctProperty( wxT("Default-value

The default value."), - wxVariant((bool) TRUE, wxT("default-value")), + wxVariant(true, wxT("default-value")), wxT(""))); } else if (GetType() == ctTypeInteger) @@ -220,6 +219,12 @@ void ctConfigItem::InitProperties() wxVariant(wxT(""), wxT("enabled-if-not")), wxT("configitems"))); + m_properties.AddProperty( + new ctProperty( + wxT("Indeterminate-if

When any of these settings are 1, this setting becomes active and indeterminate. Taking wxUSE_UNICODE as an example:

If Custom is 1, wxUSE_UNICODE is indeterminate."), + wxVariant(wxT(""), wxT("indeterminate-if")), + wxT("configitems"))); + m_properties.AddProperty( new ctProperty( wxT("Exclusivity

The settings that are mutually exclusive with this one."), @@ -240,7 +245,7 @@ void ctConfigItem::InitProperties() m_properties.AddProperty( new ctProperty( - wxT("Help-topic

The help topic in the wxWindows manual for this component or setting."), + wxT("Help-topic

The help topic in the wxWidgets manual for this component or setting."), wxVariant(wxT(""), wxT("help-topic")), wxT("multiline"))); @@ -255,17 +260,18 @@ void ctConfigItem::InitProperties() /// Do additional actions to apply the property to the internal /// representation. -void ctConfigItem::ApplyProperty(ctProperty* prop, const wxVariant& oldValue) +void ctConfigItem::ApplyProperty(ctProperty* prop, const wxVariant& WXUNUSED(oldValue)) { ctConfigToolDoc* doc = GetDocument(); bool oldModified = doc->IsModified(); - doc->Modify(TRUE); + doc->Modify(true); wxString name = prop->GetName(); if (name == wxT("requires") || name == wxT("precludes") || name == wxT("enabled-if") || name == wxT("enabled-if-not") || + name == wxT("indeterminate-if") || name == wxT("context")) { doc->RefreshDependencies(); @@ -329,7 +335,7 @@ ctConfigItem* ctConfigItem::FindItem(const wxString& name) if (GetName() == name) return this; - for ( wxNode* node = GetChildren().GetFirst(); node; node = node->GetNext() ) + for ( wxObjectList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext() ) { ctConfigItem* child = (ctConfigItem*) node->GetData(); ctConfigItem* found = child->FindItem(name); @@ -344,7 +350,7 @@ ctConfigItem* ctConfigItem::FindNextSibling() { if (!GetParent()) return NULL; - wxNode* node = GetParent()->GetChildren().Member(this); + wxObjectList::compatibility_iterator node = GetParent()->GetChildren().Member(this); if (node && node->GetNext()) { return (ctConfigItem*) node->GetNext()->GetData(); @@ -357,7 +363,7 @@ ctConfigItem* ctConfigItem::FindPreviousSibling() { if (!GetParent()) return NULL; - wxNode* node = GetParent()->GetChildren().Member(this); + wxObjectList::compatibility_iterator node = GetParent()->GetChildren().Member(this); if (node && node->GetPrevious()) { return (ctConfigItem*) node->GetPrevious()->GetData(); @@ -383,7 +389,7 @@ ctConfigItem* ctConfigItem::DeepClone() { ctConfigItem* newItem = Clone(); - for ( wxNode* node = GetChildren().GetFirst(); node; node = node->GetNext() ) + for ( wxObjectList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext() ) { ctConfigItem* child = (ctConfigItem*) node->GetData(); ctConfigItem* newChild = child->DeepClone(); @@ -419,7 +425,7 @@ void ctConfigItem::DetachFromTree() data->SetConfigItem(NULL); m_treeItemId = wxTreeItemId(); - for ( wxNode* node = GetChildren().GetFirst(); node; node = node->GetNext() ) + for ( wxObjectList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext() ) { ctConfigItem* child = (ctConfigItem*) node->GetData(); child->DetachFromTree(); @@ -432,12 +438,14 @@ void ctConfigItem::Attach(ctConfigItem* parent, ctConfigItem* insertBefore) if (parent) { SetParent(parent); - wxNode* node = NULL; if (insertBefore) - node = parent->GetChildren().Member(insertBefore); - - if (node) - parent->GetChildren().Insert(node, this); + { + wxObjectList::compatibility_iterator node = parent->GetChildren().Member(insertBefore); + if (node) + parent->GetChildren().Insert(node, this); + else + parent->GetChildren().Append(this); + } else parent->GetChildren().Append(this); } @@ -462,18 +470,18 @@ bool ctConfigItem::IsInActiveContext() { wxString context = GetPropertyString(wxT("context")); if (context.IsEmpty()) - return TRUE; + return true; wxList contextItems; StringToItems(GetDocument()->GetTopItem(), context, contextItems); - for ( wxNode* node = contextItems.GetFirst(); node; node = node->GetNext() ) + for ( wxObjectList::compatibility_iterator node = contextItems.GetFirst(); node; node = node->GetNext() ) { ctConfigItem* otherItem = (ctConfigItem*) node->GetData(); if (otherItem->IsEnabled()) - return TRUE; + return true; } - return FALSE; + return false; } /// Evaluate the requires properties: @@ -481,18 +489,21 @@ bool ctConfigItem::IsInActiveContext() /// then this one is disabled (and inactive). void ctConfigItem::EvaluateDependencies() { + // For debugging purposes + wxString name = GetName(); wxList items; wxString requires = GetPropertyString(wxT("requires")); wxString precludes = GetPropertyString(wxT("precludes")); wxString enabledIf = GetPropertyString(wxT("enabled-if")); wxString enabledIfNot = GetPropertyString(wxT("enabled-if-not")); + wxString indeterminateIf = GetPropertyString(wxT("indeterminate-if")); - bool active = TRUE; + bool active = true; bool enabled = IsEnabled(); bool oldEnabled = enabled; bool oldActive = IsActive(); - bool explicitlyEnabled = FALSE; - bool explicitlyDisabled = FALSE; + bool explicitlyEnabled = false; + bool explicitlyDisabled = false; bool inActiveContext = IsInActiveContext(); // Add the parent to the list of dependencies, if the @@ -506,7 +517,7 @@ void ctConfigItem::EvaluateDependencies() wxList tempItems; StringToItems(GetDocument()->GetTopItem(), requires, tempItems); - wxNode* node; + wxObjectList::compatibility_iterator node; for ( node = tempItems.GetFirst(); node; node = node->GetNext() ) { // Only consider the dependency if both items are in @@ -533,9 +544,9 @@ void ctConfigItem::EvaluateDependencies() if (items.GetCount() > 0 && enabledCount == 0) { // None of the items were enabled - enabled = FALSE; - active = FALSE; - explicitlyDisabled = TRUE; + enabled = false; + active = false; + explicitlyDisabled = true; } } @@ -546,7 +557,7 @@ void ctConfigItem::EvaluateDependencies() int disabledCount = 0; int inContextCount = 0; - for ( wxNode* node = items.GetFirst(); node; node = node->GetNext() ) + for ( wxObjectList::compatibility_iterator node = items.GetFirst(); node; node = node->GetNext() ) { ctConfigItem* otherItem = (ctConfigItem*) node->GetData(); @@ -565,9 +576,9 @@ void ctConfigItem::EvaluateDependencies() // Enable if there were no related items that were enabled if (inContextCount > 0 && (disabledCount == inContextCount) && !explicitlyDisabled) { - explicitlyEnabled = TRUE; - enabled = TRUE; - active = FALSE; + explicitlyEnabled = true; + enabled = true; + active = false; } } @@ -578,9 +589,10 @@ void ctConfigItem::EvaluateDependencies() int enabledCount = 0; int inContextCount = 0; - for ( wxNode* node = items.GetFirst(); node; node = node->GetNext() ) + for ( wxObjectList::compatibility_iterator node = items.GetFirst(); node; node = node->GetNext() ) { ctConfigItem* otherItem = (ctConfigItem*) node->GetData(); + wxString otherName = otherItem->GetName(); if (inActiveContext && otherItem->IsInActiveContext()) { @@ -597,9 +609,9 @@ void ctConfigItem::EvaluateDependencies() // Enable if there were no related items that were disabled if (inContextCount > 0 && (enabledCount > 0) && !explicitlyDisabled) { - explicitlyEnabled = TRUE; - enabled = TRUE; - active = FALSE; + explicitlyEnabled = true; + enabled = true; + active = false; } } @@ -608,35 +620,78 @@ void ctConfigItem::EvaluateDependencies() { StringToItems(GetDocument()->GetTopItem(), precludes, items); int enabledCount = 0; + // int disabledCount = 0; int inContextCount = 0; - for ( wxNode* node = items.GetFirst(); node; node = node->GetNext() ) + for ( wxObjectList::compatibility_iterator node = items.GetFirst(); node; node = node->GetNext() ) { ctConfigItem* otherItem = (ctConfigItem*) node->GetData(); if (inActiveContext && otherItem->IsInActiveContext()) { - // Make this enabled and inactive, _unless_ it's - // already been explicitly disabled in the previous - // requires evaluation (it really _has_ to be off) + // Make this disabled and inactive, _unless_ it's + // already been explicitly enabled in the previous + // requires evaluation (it really _has_ to be on) +// if (!otherItem->IsEnabled()) if (otherItem->IsEnabled()) { enabledCount ++; + // disabledCount ++; } + inContextCount ++; } } // Disable if there were no related items that were disabled - if (inContextCount > 0 && (enabledCount == inContextCount) && !explicitlyEnabled) + if (inContextCount > 0 && (enabledCount > 0) && !explicitlyEnabled) +// if (inContextCount > 0 && (disabledCount > 0) && !explicitlyEnabled) { - enabled = FALSE; - active = FALSE; + enabled = false; + active = false; + explicitlyDisabled = true; + } + } + + // Indeterminate overrides the others, and + // makes the item active. + items.Clear(); + if (!indeterminateIf.IsEmpty()) + { + StringToItems(GetDocument()->GetTopItem(), indeterminateIf, items); + int enabledCount = 0; + int inContextCount = 0; + + for ( wxObjectList::compatibility_iterator node = items.GetFirst(); node; node = node->GetNext() ) + { + ctConfigItem* otherItem = (ctConfigItem*) node->GetData(); + + if (inActiveContext && otherItem->IsInActiveContext()) + { + if (otherItem->IsEnabled()) + { + enabledCount ++; + } + inContextCount ++; + } + } + if (inContextCount > 0 && enabledCount > 0) + { + active = true; + explicitlyEnabled = false; + explicitlyDisabled = false; } } // Finally check a sort of dependency: whether our // context is active. If not, make this inactive. if (!IsInActiveContext()) - active = FALSE; + active = false; + else + { + // If we didn't explicitly enable or disable it, + // then we should make it active. + if (!explicitlyEnabled && !explicitlyDisabled) + active = true; + } SetActive(active); @@ -711,7 +766,7 @@ void ctConfigItem::PropagateChange(wxList& considered) // TODO: what about string, integer? Can they have // dependencies? - for ( wxNode* node = GetDependents().GetFirst(); node; node = node->GetNext() ) + for ( wxObjectList::compatibility_iterator node = GetDependents().GetFirst(); node; node = node->GetNext() ) { ctConfigItem* child = (ctConfigItem*) node->GetData(); @@ -739,12 +794,12 @@ void ctConfigItem::PropagateRadioButton(wxList& considered) wxList list; StringToItems(GetDocument()->GetTopItem(), mutuallyExclusive, list); - for ( wxNode* node = list.GetFirst(); node; node = node->GetNext() ) + for ( wxObjectList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() ) { ctConfigItem* child = (ctConfigItem*) node->GetData(); if (child->IsEnabled() && child != this) { - child->Enable(FALSE); + child->Enable(false); child->Sync(); if (!considered.Member(child))