Difference between revisions of "Dialog Configurations"

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Jump to: navigation, search
(Configuration Attributes)
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{VersionBadge|0.5}} {{VersionBadge|0.6}}
 +
 
=== Introduction ===
 
=== Introduction ===
 
Dialogs (frame windows) can be moved around, resized, hidden, and rolled up while the application is running.  MultiColumnLists can have their columns rearranged, resized, and a column can sort its content in ascending or descending order.  However closing and then restarting the application will reset these settings to their default values, those specified within a .layout file if one was use, or those specified in code.
 
Dialogs (frame windows) can be moved around, resized, hidden, and rolled up while the application is running.  MultiColumnLists can have their columns rearranged, resized, and a column can sort its content in ascending or descending order.  However closing and then restarting the application will reset these settings to their default values, those specified within a .layout file if one was use, or those specified in code.
Line 16: Line 18:
  
 
Edit Sample_Demo7.cpp to add the following at the end of the Demo7Sample::initialiseSample() function, between ''initDemoEventWiring();'' and ''return true;'':
 
Edit Sample_Demo7.cpp to add the following at the end of the Demo7Sample::initialiseSample() function, between ''initDemoEventWiring();'' and ''return true;'':
 +
<source lang="cpp">
 
   m_dialogConfigurations.loadConfigurations("../datafiles/configs/Sample_Demo7.xml", "../datafiles/configs/DialogConfigurations.xsd");
 
   m_dialogConfigurations.loadConfigurations("../datafiles/configs/Sample_Demo7.xml", "../datafiles/configs/DialogConfigurations.xsd");
 
   m_dialogConfigurations.addDialog("Demo7/Window1");
 
   m_dialogConfigurations.addDialog("Demo7/Window1");
 
   m_dialogConfigurations.addDialog("Demo7/Window2");
 
   m_dialogConfigurations.addDialog("Demo7/Window2");
 
   m_dialogConfigurations.addDialog("Demo7/Window3");
 
   m_dialogConfigurations.addDialog("Demo7/Window3");
 +
</source>
  
 
Add the following to Demo7Sample::cleanupSample()
 
Add the following to Demo7Sample::cleanupSample()
 +
<source lang="cpp">
 
   m_dialogConfigurations.saveConfigurations();
 
   m_dialogConfigurations.saveConfigurations();
 +
</source>
  
 
That's it!  From now on the 3 windows within that demo will "remember" their previous configurations.
 
That's it!  From now on the 3 windows within that demo will "remember" their previous configurations.
Line 35: Line 41:
 
The second parameter of addDialog() allows you to specify which attributes to monitor.  By default every attribute is monitored.  However you can specify to monitor one or many of the following, separated by spaces:  Position, Visible, and RolledUp.
 
The second parameter of addDialog() allows you to specify which attributes to monitor.  By default every attribute is monitored.  However you can specify to monitor one or many of the following, separated by spaces:  Position, Visible, and RolledUp.
  
The addMultiColumnList() function behaves in a similar manner, allowing you to specify which MultiColumnLists which of their attributes to monitor.  Again the default is to monitor every attribute but you can also specify one or many of the following:  ColumnSequence, ColumnWidths, SortedColumn, and AscendingSort.
+
The addMultiColumnList() function behaves in a similar manner, allowing you to specify which MultiColumnLists and which of their attributes to monitor.  Again the default is to monitor every attribute but you can also specify one or many of the following:  ColumnSequence, ColumnWidths, SortedColumn, and AscendingSort.
  
 
=== Files ===
 
=== Files ===
  
 
==== DialogConfigurations.h ====
 
==== DialogConfigurations.h ====
<pre>
+
<source lang="cpp">
 
#ifndef _DialogConfigurations_h_
 
#ifndef _DialogConfigurations_h_
 
#define _DialogConfigurations_h_
 
#define _DialogConfigurations_h_
Line 53: Line 59:
 
{
 
{
 
public:
 
public:
 +
// Constructor.
 +
// Sets various default values.
 
DialogConfigurations();
 
DialogConfigurations();
void setDialogDefaults(const CEGUI::URect& position, const bool& visible, const bool& rolledup); // Set default values
+
 
 +
// Load the configuration of every stored dialog and multi column list.
 +
// By default, also apply these configurations.
 +
bool loadConfigurations(const CEGUI::String& xmlFile, const CEGUI::String& schema = "", const bool& applyConfigurations = true);
 +
 
 +
// Store the configuration of every dialog and multi column list.
 +
bool saveConfigurations();
 +
 
 +
// Set default configurations for dialogs.
 +
void setDialogDefaults(const CEGUI::URect& position, const bool& visible, const bool& rolledup);
 +
 
 +
// Specify which dialog attributes are monitored by default.
 
void setDefaultDialogAttributesMonitored(const CEGUI::String& attributesMonitored);
 
void setDefaultDialogAttributesMonitored(const CEGUI::String& attributesMonitored);
bool addDialog(const CEGUI::String& widget, const CEGUI::String& attributesMonitored = ""); // Add a dialog to be monitored
 
const CEGUI::URect& getDialogSavedPosition(const CEGUI::String& dialog); // Return the position of the specified dialog
 
const bool& getDialogSavedVisible(const CEGUI::String& dialog); // Return the visible/hidden state of the specified dialog
 
const bool& getDialogSavedRolledup(const CEGUI::String& dialog); // Return the expansion state of the specified dialog
 
  
 +
// Add a dialog to be monitored.
 +
// Optionally specify which attributes this specific dialog monitors.
 +
bool addDialog(const CEGUI::String& widget, const CEGUI::String& attributesMonitored = "");
 +
 +
// Return the position of the specified dialog.
 +
const CEGUI::URect& getDialogSavedPosition(const CEGUI::String& dialog);
 +
 +
// Return the visible/hidden state of the specified dialog.
 +
const bool& getDialogSavedVisible(const CEGUI::String& dialog);
 +
 +
// Return the expansion state of the specified dialog.
 +
const bool& getDialogSavedRolledup(const CEGUI::String& dialog);
 +
 +
// Apply the saved configuration to the specified dialog.
 +
bool applyDialogConfiguration(const CEGUI::String& dialog = "");
 +
 +
// Set default configurations for multi column lists.
 
void setMultiColumnListDefaults(const std::vector<CEGUI::String>& columnSequence, const CEGUI::uint& sortedColumn, const bool& sortAscending, const std::vector<CEGUI::String>& columnWidths);
 
void setMultiColumnListDefaults(const std::vector<CEGUI::String>& columnSequence, const CEGUI::uint& sortedColumn, const bool& sortAscending, const std::vector<CEGUI::String>& columnWidths);
 +
 +
// Specify which dialog attributes are monitored by default.
 
void setDefaultMultiColumnListAttributesMonitored(const CEGUI::String& attributesMonitored);
 
void setDefaultMultiColumnListAttributesMonitored(const CEGUI::String& attributesMonitored);
bool addMultiColumnList(const CEGUI::String& widget, const CEGUI::String& attributesMonitored = ""); // Add a MultiColumnList to be monitored
 
  
bool loadConfigurations(const CEGUI::String& xmlFile, const CEGUI::String& schema = ""); // Load the position of every stored dialog
+
// Add a MultiColumnList to be monitored.
bool saveConfigurations(); // Store the position of every dialogs
+
bool addMultiColumnList(const CEGUI::String& widget, const CEGUI::String& attributesMonitored = "");
 +
 
 +
// Apply the saved configuration to the specified multi column list.
 +
bool applyMultiColumnListConfiguration(const CEGUI::String& multiColumnList = "");
  
bool isMonitoringAttribute(const std::vector<CEGUI::String>& list, const CEGUI::String& attribute); // Whether a particular attribute is monitored
 
 
private:
 
private:
 +
// Whether a particular attribute is monitored.
 +
bool isMonitoringAttribute(const std::vector<CEGUI::String>& list, const CEGUI::String& attribute);
 +
 +
// Performs the actual load every stored configuration.
 
     void elementStart(const CEGUI::String& element, const CEGUI::XMLAttributes& xmlAttributes);
 
     void elementStart(const CEGUI::String& element, const CEGUI::XMLAttributes& xmlAttributes);
static const CEGUI::String m_DialogConfigurationElement; // Tag name for dialog positions element
 
static const CEGUI::String m_configurationElementDialog; // Tag name for position elements
 
static const char windowNameAttribute[]; // Attribute name that stores the name of the window
 
static const char windowPosAttribute[]; // Attribute name that stores the position of the window
 
static const char windowVisibleAttribute[]; // Attribute name that stores the visible state of the window
 
static const char windowRolledupAttribute[]; // Attribute name that stores the rolledUp state of the window
 
static const CEGUI::String m_configurationElementMultiColumnList; // Tag name of MultiColumnList elements
 
static const char mclColumnSequenceAttribute[]; // Attribute name that stores the sequence of the columns
 
static const char mclSortedColumnAttribute[]; // Attribute name that stores which column is sorted
 
static const char mclAscendingSortAttribute[]; // Attribute name that stores the sort order direction
 
static const char DialogConfigurations::mclColumnWidthAttribute[]; // Attribute name that stores the widths of the columns
 
static const char DialogConfigurations::mclColumnWidthSeparator; // Separator for the column widths
 
static const char monitoredAttributeAll[]; // Special attribute name
 
static const char monitoredAttributeNone[]; // Special attribute name
 
  
 +
// Tag name for dialog positions element.
 +
static const CEGUI::String m_DialogConfigurationElement;
 +
 +
// Tag name for position elements.
 +
static const CEGUI::String m_configurationElementDialog;
 +
 +
// Attribute name that stores the name of the window.
 +
static const char windowNameAttribute[];
 +
 +
// Attribute name that stores the position of the window.
 +
static const char windowPosAttribute[];
 +
 +
// Attribute name that stores the visible state of the window.
 +
static const char windowVisibleAttribute[];
 +
 +
// Attribute name that stores the rolledUp state of the window.
 +
static const char windowRolledupAttribute[];
 +
 +
// Tag name of MultiColumnList elements.
 +
static const CEGUI::String m_configurationElementMultiColumnList;
 +
 +
// Attribute name that stores the sequence of the columns.
 +
static const char mclColumnSequenceAttribute[];
 +
 +
// Attribute name that stores which column is sorted.
 +
static const char mclSortedColumnAttribute[];
 +
 +
// Attribute name that stores the sort order direction.
 +
static const char mclAscendingSortAttribute[];
 +
 +
// Attribute name that stores the widths of the columns.
 +
static const char DialogConfigurations::mclColumnWidthAttribute[];
 +
 +
// Separator for the column sequences.
 +
static const char DialogConfigurations::mclColumnSequenceSeparator;
 +
 +
// Separator for the column widths.
 +
static const char DialogConfigurations::mclColumnWidthSeparator;
 +
 +
// Special attribute name to monitor every attribute.
 +
static const char monitoredAttributeAll[];
 +
 +
// Special attribute name to monitor no attribute.
 +
static const char monitoredAttributeNone[];
 +
 +
// The value of one dialog configuration.
 
struct DialogConfig {
 
struct DialogConfig {
 
CEGUI::URect position;
 
CEGUI::URect position;
Line 91: Line 162:
 
bool rolledup;
 
bool rolledup;
 
};
 
};
std::map<CEGUI::String, DialogConfig> m_dialogConfigurations; // List of the dialog configurations
 
CEGUI::URect m_defaultPosition; // Default position, used by getSavedPosition()
 
bool m_defaultVisible; // Default visible/hidden, used by getSavedVisible()
 
bool m_defaultRolledup; // Default rolled up/expanded, used by getSavedRolledup()
 
void _setDialogAttributesMonitored(const CEGUI::String& dialog, const CEGUI::String& attributesMonitored); // Specify which attributes to monitor for this dialog
 
std::map<CEGUI::String, std::vector<CEGUI::String>> m_attributesMonitoredDialog; // List of the attributes monitored per dialog
 
  
 +
// List of the dialog configurations.
 +
std::map<CEGUI::String, DialogConfig> m_dialogConfigurations;
 +
 +
// Default position.
 +
CEGUI::URect m_defaultPosition;
 +
 +
// Default visible/hidden.
 +
bool m_defaultVisible;
 +
 +
// Default rolled up/expanded.
 +
bool m_defaultRolledup;
 +
 +
// Specify which attributes to monitor for this dialog.
 +
void _setDialogAttributesMonitored(const CEGUI::String& dialog, const CEGUI::String& attributesMonitored);
 +
 +
// List of the attributes monitored per dialog.
 +
std::map<CEGUI::String, std::vector<CEGUI::String>> m_attributesMonitoredDialog;
 +
 +
// The value of one multi column list configuration.
 
struct MultiColumnListConfig {
 
struct MultiColumnListConfig {
 
std::vector<CEGUI::String> columnSequence;
 
std::vector<CEGUI::String> columnSequence;
Line 104: Line 188:
 
std::vector<CEGUI::String> columnWidths;
 
std::vector<CEGUI::String> columnWidths;
 
};
 
};
 +
 +
// List of the multi column list configurations.
 
std::map<CEGUI::String, MultiColumnListConfig> m_multiColumnListConfigurations;
 
std::map<CEGUI::String, MultiColumnListConfig> m_multiColumnListConfigurations;
 +
 +
// Default column sequence.
 
std::vector<CEGUI::String> m_defaultColumnSequence;
 
std::vector<CEGUI::String> m_defaultColumnSequence;
 +
 +
// Default sorted column.
 
CEGUI::uint m_defaultSortedColumn;
 
CEGUI::uint m_defaultSortedColumn;
 +
 +
// Default sort order.
 
bool m_defaultSortAscending;
 
bool m_defaultSortAscending;
 +
 +
// Default column widths.
 
std::vector<CEGUI::String> m_defaultColumnWidths;
 
std::vector<CEGUI::String> m_defaultColumnWidths;
void _setMultiColumnListAttributesMonitored(const CEGUI::String& multiColumnList, const CEGUI::String& attributesMonitored); // Specify which attributes to monitor for this dialog
 
std::map<CEGUI::String, std::vector<CEGUI::String>> m_attributesMonitoredMultiColumnList; // List of the attributes monitored per MultiColumnList
 
  
CEGUI::String m_configFile; // File containing the positions
+
// Specify which attributes to monitor for this multi column list.
static std::vector<CEGUI::String> m_attributeList; // List of the supported attributes
+
void _setMultiColumnListAttributesMonitored(const CEGUI::String& multiColumnList, const CEGUI::String& attributesMonitored);
 +
 
 +
// List of the attributes monitored per MultiColumnList
 +
std::map<CEGUI::String, std::vector<CEGUI::String>> m_attributesMonitoredMultiColumnList;
 +
 
 +
// File containing the positions.
 +
CEGUI::String m_configFile;
 +
 
 +
// List of the supported attributes.
 +
static std::vector<CEGUI::String> m_attributeList;
 
};
 
};
  
 
#endif // _DialogConfigurations_h_
 
#endif // _DialogConfigurations_h_
</pre>
+
</source>
  
 
==== DialogConfigurations.cpp ====
 
==== DialogConfigurations.cpp ====
<pre>
+
<source lang="cpp">
 
#include "DialogConfigurations.h"
 
#include "DialogConfigurations.h"
 
#include "CEGUIPropertyHelper.h"
 
#include "CEGUIPropertyHelper.h"
Line 138: Line 239:
 
const char DialogConfigurations::mclSortedColumnAttribute[] = "SortedColumn";
 
const char DialogConfigurations::mclSortedColumnAttribute[] = "SortedColumn";
 
const char DialogConfigurations::mclAscendingSortAttribute[]= "AscendingSort";
 
const char DialogConfigurations::mclAscendingSortAttribute[]= "AscendingSort";
 +
const char DialogConfigurations::mclColumnSequenceSeparator = ',';
 
const char DialogConfigurations::mclColumnWidthSeparator = ';';
 
const char DialogConfigurations::mclColumnWidthSeparator = ';';
  
Line 207: Line 309:
 
_setDialogAttributesMonitored("", monitoredAttributeAll);
 
_setDialogAttributesMonitored("", monitoredAttributeAll);
 
_setMultiColumnListAttributesMonitored("", monitoredAttributeAll);
 
_setMultiColumnListAttributesMonitored("", monitoredAttributeAll);
 +
}
 +
 +
bool DialogConfigurations::loadConfigurations(const CEGUI::String& xmlFile, const CEGUI::String& schema, const bool& applyConfigurations)
 +
{
 +
// Load the config of every stored dialog
 +
assert(!xmlFile.empty() && "You must specify an xml file to loadConfigurations()");
 +
m_configFile = xmlFile;
 +
bool loadedOk = true;
 +
try
 +
{
 +
CEGUI::System::getSingleton().getXMLParser()->parseXMLFile(*this, m_configFile, schema, "");
 +
}
 +
catch(const CEGUI::Exception&)
 +
{
 +
// File is empty or parse error
 +
// Silently ignore; we'll create a new file when saving
 +
loadedOk = false;
 +
}
 +
 +
if(applyConfigurations)
 +
{
 +
applyDialogConfiguration();
 +
applyMultiColumnListConfiguration();
 +
}
 +
 +
return loadedOk;
 +
}
 +
 +
bool DialogConfigurations::saveConfigurations()
 +
{
 +
// Store the configuration of every registered dialog, either within
 +
// the loaded XML file or those manually registered via addDialog()
 +
assert(!m_configFile.empty() && "You must specify an xml file by calling loadConfigurations() before saveConfigurations()");
 +
 +
// Try to open the XML file in writing mode
 +
    std::ofstream fileSave;
 +
fileSave.open(m_configFile.c_str(), std::ios::out) ;
 +
    if( !fileSave.is_open() )
 +
    {
 +
CEGUI::Logger::getSingleton().logEvent("Could not write to dialog configuration file ("
 +
+ m_configFile
 +
+ ").  Is it read-only?",
 +
CEGUI::Errors);
 +
        return false;
 +
    }
 +
 +
// Write the header
 +
fileSave << "<?xml version=\"1.0\" ?>" << std::endl
 +
<< "<" << m_DialogConfigurationElement << ">"
 +
<< std::endl;
 +
 +
// Write each dialog's configuration
 +
DialogConfig dialogConfig;
 +
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
 +
std::map<CEGUI::String, DialogConfig>::iterator itDialogConfig;
 +
std::map<CEGUI::String, std::vector<CEGUI::String>>::iterator itAttributesMonitored;
 +
std::vector<CEGUI::String> attributesMonitored;
 +
CEGUI::Window* window;
 +
for(itDialogConfig = m_dialogConfigurations.begin(); itDialogConfig != m_dialogConfigurations.end(); ++itDialogConfig)
 +
{
 +
if(!winMgr.isWindowPresent(itDialogConfig->first))
 +
continue;
 +
 +
itAttributesMonitored = m_attributesMonitoredDialog.find(itDialogConfig->first);
 +
if(itAttributesMonitored != m_attributesMonitoredDialog.end())
 +
attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
 +
else
 +
{
 +
// Use default attributes
 +
itAttributesMonitored = m_attributesMonitoredDialog.find("");
 +
if(itAttributesMonitored != m_attributesMonitoredDialog.end())
 +
attributesMonitored = (*itAttributesMonitored).second;
 +
}
 +
 +
window = winMgr.getWindow(itDialogConfig->first);
 +
dialogConfig.position = window->getArea();
 +
dialogConfig.visible = window->isVisible();
 +
if( window->testClassName("FrameWindow") )
 +
dialogConfig.rolledup = static_cast<CEGUI::FrameWindow*>(window)->isRolledup();
 +
else
 +
dialogConfig.rolledup = false;
 +
fileSave << "  <" << m_configurationElementDialog.c_str() << " "
 +
<< windowNameAttribute << "=\"" << itDialogConfig->first << "\" ";
 +
if(isMonitoringAttribute(attributesMonitored, windowPosAttribute))
 +
fileSave << windowPosAttribute << "=\"" << CEGUI::PropertyHelper::urectToString(dialogConfig.position) << "\" ";
 +
if(isMonitoringAttribute(attributesMonitored, windowVisibleAttribute))
 +
fileSave << windowVisibleAttribute << "=\"" << dialogConfig.visible << "\" ";
 +
if(isMonitoringAttribute(attributesMonitored, windowRolledupAttribute))
 +
fileSave << windowRolledupAttribute << "=\"" << dialogConfig.rolledup << "\" ";
 +
fileSave << "/>" << std::endl;
 +
}
 +
 +
 +
// Write each MultiColumnList's configuration
 +
std::map<CEGUI::String, MultiColumnListConfig>::iterator itMultiColumnListConfig;
 +
attributesMonitored.clear();
 +
CEGUI::MultiColumnList* multiColumnList;
 +
for(itMultiColumnListConfig = m_multiColumnListConfigurations.begin(); itMultiColumnListConfig != m_multiColumnListConfigurations.end(); ++itMultiColumnListConfig)
 +
{
 +
itAttributesMonitored = m_attributesMonitoredMultiColumnList.find(itMultiColumnListConfig->first);
 +
if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
 +
attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
 +
else
 +
{
 +
// Use default attributes
 +
itAttributesMonitored = m_attributesMonitoredMultiColumnList.find("");
 +
if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
 +
attributesMonitored = (*itAttributesMonitored).second;
 +
}
 +
 +
multiColumnList = static_cast<CEGUI::MultiColumnList*>(winMgr.getWindow(itMultiColumnListConfig->first));
 +
fileSave << "  <" << m_configurationElementMultiColumnList.c_str() << " "
 +
<< windowNameAttribute << "=\"" << itMultiColumnListConfig->first << "\" ";
 +
if(isMonitoringAttribute(attributesMonitored, mclColumnSequenceAttribute) && multiColumnList->getColumnCount())
 +
{
 +
fileSave << mclColumnSequenceAttribute << "=\"";
 +
for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount(); ++columnIndex)
 +
{
 +
if(columnIndex)
 +
fileSave << mclColumnSequenceSeparator;
 +
fileSave << multiColumnList->getColumnID(columnIndex);
 +
}
 +
fileSave << "\" ";
 +
}
 +
if(isMonitoringAttribute(attributesMonitored, mclColumnWidthAttribute) && multiColumnList->getColumnCount())
 +
{
 +
fileSave << mclColumnWidthAttribute << "=\"";
 +
for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount(); ++columnIndex)
 +
{
 +
if(columnIndex)
 +
fileSave << mclColumnWidthSeparator;
 +
fileSave << CEGUI::PropertyHelper::udimToString(multiColumnList->getColumnHeaderWidth(columnIndex));
 +
}
 +
fileSave << "\" ";
 +
}
 +
if(isMonitoringAttribute(attributesMonitored, mclSortedColumnAttribute))
 +
fileSave << mclSortedColumnAttribute << "=\"" << multiColumnList->getColumnID(multiColumnList->getSortColumn()) << "\" ";
 +
if(isMonitoringAttribute(attributesMonitored, mclAscendingSortAttribute))
 +
fileSave << mclAscendingSortAttribute << "=\"" << (multiColumnList->getSortDirection() != CEGUI::ListHeaderSegment::Descending) << "\" ";
 +
fileSave << "/>" << std::endl;
 +
}
 +
 +
 +
// Write the footer
 +
fileSave << "</" << m_DialogConfigurationElement << ">" << std::endl;
 +
fileSave.close();
 +
return true;
 
}
 
}
  
Line 240: Line 489:
 
CEGUI::Window* window = CEGUI::WindowManager::getSingleton().getWindow(widget);
 
CEGUI::Window* window = CEGUI::WindowManager::getSingleton().getWindow(widget);
 
DialogConfig config;
 
DialogConfig config;
config.position = window->getWindowArea();
+
config.position = window->getArea();
 
config.visible = window->isVisible();
 
config.visible = window->isVisible();
 
if( window->testClassName("FrameWindow") )
 
if( window->testClassName("FrameWindow") )
Line 273: Line 522:
 
itConfig = m_dialogConfigurations.find(dialog);
 
itConfig = m_dialogConfigurations.find(dialog);
 
return itConfig == m_dialogConfigurations.end() ? m_defaultRolledup : (*itConfig).second.rolledup;
 
return itConfig == m_dialogConfigurations.end() ? m_defaultRolledup : (*itConfig).second.rolledup;
 +
}
 +
 +
bool DialogConfigurations::applyDialogConfiguration(const CEGUI::String& dialog)
 +
{
 +
// Apply the saved configuration to a dialog
 +
if(dialog.length() == 0)
 +
{
 +
// Load every dialog configurations
 +
std::map<CEGUI::String, DialogConfig>::iterator itConfig;
 +
for(itConfig = m_dialogConfigurations.begin(); itConfig != m_dialogConfigurations.end(); itConfig++)
 +
{
 +
applyDialogConfiguration((*itConfig).first);
 +
}
 +
}
 +
else
 +
{
 +
// Find this dialog's configuration
 +
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
 +
std::map<CEGUI::String, DialogConfig>::iterator itConfig;
 +
itConfig = m_dialogConfigurations.find(dialog);
 +
if(itConfig == m_dialogConfigurations.end() || !winMgr.isWindowPresent(dialog))
 +
return false;
 +
 +
// Determine which attributes are monitored
 +
std::vector<CEGUI::String> attributesMonitored;
 +
std::map<CEGUI::String, std::vector<CEGUI::String>>::iterator itAttributesMonitored;
 +
itAttributesMonitored = m_attributesMonitoredDialog.find(dialog);
 +
if(itAttributesMonitored != m_attributesMonitoredDialog.end())
 +
attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
 +
else
 +
{
 +
// Use default attributes
 +
itAttributesMonitored = m_attributesMonitoredDialog.find("");
 +
if(itAttributesMonitored == m_attributesMonitoredDialog.end())
 +
return false;  // Could not retrieve the default attributes (should never happen)
 +
attributesMonitored = (*itAttributesMonitored).second;
 +
}
 +
 +
// Apply the configuration to the dialog
 +
CEGUI::Window* window = winMgr.getWindow(dialog);
 +
if(isMonitoringAttribute(attributesMonitored, windowPosAttribute))
 +
window->setArea((*itConfig).second.position);
 +
if(isMonitoringAttribute(attributesMonitored, windowVisibleAttribute))
 +
window->setVisible((*itConfig).second.visible);
 +
if(isMonitoringAttribute(attributesMonitored, windowRolledupAttribute))
 +
{
 +
if( window->testClassName("FrameWindow") )
 +
{
 +
CEGUI::FrameWindow* frameWindow = static_cast<CEGUI::FrameWindow*>(window);
 +
if(frameWindow->isRolledup() != (*itConfig).second.rolledup)
 +
frameWindow->toggleRollup();
 +
}
 +
}
 +
}
 +
return true;
 
}
 
}
  
Line 307: Line 611:
 
MultiColumnListConfig config;
 
MultiColumnListConfig config;
 
CEGUI::MultiColumnList* multiColumnList = static_cast<CEGUI::MultiColumnList*>(CEGUI::WindowManager::getSingleton().getWindow(widget));
 
CEGUI::MultiColumnList* multiColumnList = static_cast<CEGUI::MultiColumnList*>(CEGUI::WindowManager::getSingleton().getWindow(widget));
 +
assert(multiColumnList->testClassName("MultiColumnList") && "This widget is not a MultiColumnList");
 +
 
for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount(); ++columnIndex)
 
for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount(); ++columnIndex)
 
{
 
{
Line 319: Line 625:
 
}
 
}
  
bool DialogConfigurations::loadConfigurations(const CEGUI::String& xmlFile, const CEGUI::String& schema)
+
bool DialogConfigurations::applyMultiColumnListConfiguration(const CEGUI::String& multiColumnList)
 
{
 
{
// Load the config of every stored dialog
+
// Apply the saved configuration to a multi column list
assert(!xmlFile.empty() && "You must specify an xml file to loadConfigurations()");
+
if(multiColumnList.length() == 0)
m_configFile = xmlFile;
+
try
+
 
{
 
{
CEGUI::System::getSingleton().getXMLParser()->parseXMLFile(*this, m_configFile, schema, "");
+
// Load every multi column list configurations
}
+
std::map<CEGUI::String, MultiColumnListConfig>::iterator itConfig;
catch(...)
+
for(itConfig = m_multiColumnListConfigurations.begin(); itConfig != m_multiColumnListConfigurations.end(); itConfig++)
{
+
// File is empty or parse error
+
// Silently ignore; we'll create a new file when saving
+
}
+
return true;
+
}
+
 
+
bool DialogConfigurations::saveConfigurations()
+
{
+
// Store the configuration of every registered dialog, either within
+
// the loaded XML file or those manually registered via addDialog()
+
assert(!m_configFile.empty() && "You must specify an xml file by calling loadConfigurations() before saveConfigurations()");
+
 
+
// Try to open the XML file in writing mode
+
    std::ofstream fileSave;
+
fileSave.open(m_configFile.c_str(), std::ios::out) ;
+
    if( !fileSave.is_open() )
+
    {
+
CEGUI::Logger::getSingleton().logEvent("Could not write to dialog configuration file ("
+
+ m_configFile
+
+ ").  Is it read-only?",
+
CEGUI::Errors);
+
        return false;
+
    }
+
 
+
// Write the header
+
fileSave << "<?xml version=\"1.0\" ?>" << std::endl
+
<< "<" << m_DialogConfigurationElement << ">"
+
<< std::endl;
+
 
+
// Write each dialog's configuration
+
DialogConfig dialogConfig;
+
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
+
std::map<CEGUI::String, DialogConfig>::iterator itDialogConfig;
+
std::map<CEGUI::String, std::vector<CEGUI::String>>::iterator itAttributesMonitored;
+
std::vector<CEGUI::String> attributesMonitored;
+
CEGUI::Window* window;
+
for(itDialogConfig = m_dialogConfigurations.begin(); itDialogConfig != m_dialogConfigurations.end(); ++itDialogConfig)
+
{
+
itAttributesMonitored = m_attributesMonitoredDialog.find(itDialogConfig->first);
+
if(itAttributesMonitored != m_attributesMonitoredDialog.end())
+
attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
+
else
+
 
{
 
{
// Use default attributes
+
applyMultiColumnListConfiguration((*itConfig).first);
itAttributesMonitored = m_attributesMonitoredDialog.find("");
+
if(itAttributesMonitored != m_attributesMonitoredDialog.end())
+
attributesMonitored = (*itAttributesMonitored).second;
+
 
}
 
}
 
window = winMgr.getWindow(itDialogConfig->first);
 
dialogConfig.position = window->getWindowArea();
 
dialogConfig.visible = window->isVisible();
 
if( window->testClassName("FrameWindow") )
 
dialogConfig.rolledup = static_cast<CEGUI::FrameWindow*>(window)->isRolledup();
 
else
 
dialogConfig.rolledup = false;
 
fileSave << "  <" << m_configurationElementDialog.c_str() << " "
 
<< windowNameAttribute << "=\"" << itDialogConfig->first << "\" ";
 
if(isMonitoringAttribute(attributesMonitored, windowPosAttribute))
 
fileSave << windowPosAttribute << "=\"" << CEGUI::PropertyHelper::urectToString(dialogConfig.position) << "\" ";
 
if(isMonitoringAttribute(attributesMonitored, windowVisibleAttribute))
 
fileSave << windowVisibleAttribute << "=\"" << dialogConfig.visible << "\" ";
 
if(isMonitoringAttribute(attributesMonitored, windowRolledupAttribute))
 
fileSave << windowRolledupAttribute << "=\"" << dialogConfig.rolledup << "\" ";
 
fileSave << "/>" << std::endl;
 
 
}
 
}
 +
else
 +
{
 +
// Find this multi column list's configuration
 +
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
 +
std::map<CEGUI::String, MultiColumnListConfig>::iterator itConfig;
 +
itConfig = m_multiColumnListConfigurations.find(multiColumnList);
 +
if(itConfig == m_multiColumnListConfigurations.end() || !winMgr.isWindowPresent(multiColumnList))
 +
return false;
  
 
+
// Determine which attributes are monitored
// Write each MultiColumnList's configuration
+
std::vector<CEGUI::String> attributesMonitored;
std::map<CEGUI::String, MultiColumnListConfig>::iterator itMultiColumnListConfig;
+
std::map<CEGUI::String, std::vector<CEGUI::String>>::iterator itAttributesMonitored;
attributesMonitored.clear();
+
itAttributesMonitored = m_attributesMonitoredMultiColumnList.find(multiColumnList);
CEGUI::MultiColumnList* multiColumnList;
+
for(itMultiColumnListConfig = m_multiColumnListConfigurations.begin(); itMultiColumnListConfig != m_multiColumnListConfigurations.end(); ++itMultiColumnListConfig)
+
{
+
itAttributesMonitored = m_attributesMonitoredMultiColumnList.find(itMultiColumnListConfig->first);
+
 
if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
 
if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
+
attributesMonitored = (*itAttributesMonitored).second; // Multi column list has specified attributes
 
else
 
else
 
{
 
{
 
// Use default attributes
 
// Use default attributes
 
itAttributesMonitored = m_attributesMonitoredMultiColumnList.find("");
 
itAttributesMonitored = m_attributesMonitoredMultiColumnList.find("");
if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
+
if(itAttributesMonitored == m_attributesMonitoredMultiColumnList.end())
attributesMonitored = (*itAttributesMonitored).second;
+
return false;  // Could not retrieve the default attributes (should never happen)
 +
attributesMonitored = (*itAttributesMonitored).second;
 
}
 
}
  
multiColumnList = static_cast<CEGUI::MultiColumnList*>(winMgr.getWindow(itMultiColumnListConfig->first));
+
// Apply the configuration to the multi column list
fileSave << "  <" << m_configurationElementMultiColumnList.c_str() << " "
+
CEGUI::MultiColumnList* window = static_cast<CEGUI::MultiColumnList*>(winMgr.getWindow(multiColumnList));
<< windowNameAttribute << "=\"" << itMultiColumnListConfig->first << "\" ";
+
if(isMonitoringAttribute(attributesMonitored, mclColumnSequenceAttribute))
if(isMonitoringAttribute(attributesMonitored, mclColumnSequenceAttribute) && multiColumnList->getColumnCount())
+
 
{
 
{
fileSave << mclColumnSequenceAttribute << "=\"";
+
for(CEGUI::uint columnIndex = 0; columnIndex < window->getColumnCount() && columnIndex < (*itConfig).second.columnSequence.size(); ++columnIndex)
for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount(); ++columnIndex)
+
 
{
 
{
if(columnIndex)
+
window->moveColumn(window->getColumnWithID(CEGUI::PropertyHelper::stringToUint((*itConfig).second.columnSequence.at(columnIndex))),
fileSave << ",";
+
columnIndex);
fileSave << multiColumnList->getColumnID(columnIndex);
+
 
}
 
}
fileSave << "\" ";
 
 
}
 
}
if(isMonitoringAttribute(attributesMonitored, mclColumnWidthAttribute) && multiColumnList->getColumnCount())
+
if(isMonitoringAttribute(attributesMonitored, mclColumnWidthAttribute))
 
{
 
{
fileSave << mclColumnWidthAttribute << "=\"";
+
CEGUI::UDim width;
for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount(); ++columnIndex)
+
for(CEGUI::uint columnIndex = 0; columnIndex < window->getColumnCount() && columnIndex < (*itConfig).second.columnWidths.size(); ++columnIndex)
 
{
 
{
if(columnIndex)
+
width = CEGUI::PropertyHelper::stringToUDim((*itConfig).second.columnWidths.at(columnIndex));
fileSave << mclColumnWidthSeparator;
+
window->setColumnHeaderWidth(columnIndex, width);
fileSave << CEGUI::PropertyHelper::udimToString(multiColumnList->getColumnHeaderWidth(columnIndex));
+
 
}
 
}
fileSave << "\" ";
 
 
}
 
}
 
if(isMonitoringAttribute(attributesMonitored, mclSortedColumnAttribute))
 
if(isMonitoringAttribute(attributesMonitored, mclSortedColumnAttribute))
fileSave << mclSortedColumnAttribute << "=\"" << multiColumnList->getColumnID(multiColumnList->getSortColumn()) << "\" ";
+
{
 +
window->setSortColumn( window->getColumnWithID((*itConfig).second.sortedColumn) );
 +
}
 
if(isMonitoringAttribute(attributesMonitored, mclAscendingSortAttribute))
 
if(isMonitoringAttribute(attributesMonitored, mclAscendingSortAttribute))
fileSave << mclAscendingSortAttribute << "=\"" << (multiColumnList->getSortDirection() != CEGUI::ListHeaderSegment::Descending) << "\" ";
+
{
fileSave << "/>" << std::endl;
+
window->setSortDirection( (*itConfig).second.sortAscending ? CEGUI::ListHeaderSegment::Ascending
 +
: CEGUI::ListHeaderSegment::Descending);
 +
}
 
}
 
}
 
 
// Write the footer
 
fileSave << "</" << m_DialogConfigurationElement << ">" << std::endl;
 
fileSave.close();
 
 
return true;
 
return true;
 
}
 
}
Line 467: Line 706:
 
void DialogConfigurations::elementStart(const CEGUI::String& element, const CEGUI::XMLAttributes& xmlAttributes)
 
void DialogConfigurations::elementStart(const CEGUI::String& element, const CEGUI::XMLAttributes& xmlAttributes)
 
{
 
{
// Performs the actual load every stored dialog
+
// Performs the actual load every stored configuration
 
if (element == m_configurationElementDialog)
 
if (element == m_configurationElementDialog)
 
     {
 
     {
Line 474: Line 713:
 
config.visible  = m_defaultVisible;
 
config.visible  = m_defaultVisible;
 
config.rolledup = m_defaultRolledup;
 
config.rolledup = m_defaultRolledup;
CEGUI::String name;
+
CEGUI::String name, monitoredAttributes;
 
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
 
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
  
 
name = xmlAttributes.getValueAsString(windowNameAttribute);
 
name = xmlAttributes.getValueAsString(windowNameAttribute);
CEGUI::Window* window = winMgr.getWindow(name);
 
  
std::vector<CEGUI::String> attributesMonitored;
+
if(xmlAttributes.exists(windowPosAttribute))
std::map<CEGUI::String, std::vector<CEGUI::String>>::iterator itAttributesMonitored;
+
itAttributesMonitored = m_attributesMonitoredDialog.find(name);
+
if(itAttributesMonitored != m_attributesMonitoredDialog.end())
+
attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
+
else
+
{
+
// Use default attributes
+
itAttributesMonitored = m_attributesMonitoredDialog.find("");
+
if(itAttributesMonitored != m_attributesMonitoredDialog.end())
+
attributesMonitored = (*itAttributesMonitored).second;
+
}
+
 
+
if(xmlAttributes.exists(windowPosAttribute) && isMonitoringAttribute(attributesMonitored, windowPosAttribute))
+
 
{
 
{
 
config.position = CEGUI::PropertyHelper::stringToURect(xmlAttributes.getValueAsString(windowPosAttribute));
 
config.position = CEGUI::PropertyHelper::stringToURect(xmlAttributes.getValueAsString(windowPosAttribute));
window->setWindowArea(config.position);
+
monitoredAttributes.append(" ").append(windowPosAttribute);
 
}
 
}
if(xmlAttributes.exists(windowVisibleAttribute) && isMonitoringAttribute(attributesMonitored, windowVisibleAttribute))
+
if(xmlAttributes.exists(windowVisibleAttribute))
 
{
 
{
 
config.visible = xmlAttributes.getValueAsBool(windowVisibleAttribute);
 
config.visible = xmlAttributes.getValueAsBool(windowVisibleAttribute);
window->setVisible(config.visible);
+
monitoredAttributes.append(" ").append(windowVisibleAttribute);
 
}
 
}
if(xmlAttributes.exists(windowRolledupAttribute) && isMonitoringAttribute(attributesMonitored, windowRolledupAttribute))
+
if(xmlAttributes.exists(windowRolledupAttribute))
 
{
 
{
 
config.rolledup = xmlAttributes.getValueAsBool(windowRolledupAttribute);
 
config.rolledup = xmlAttributes.getValueAsBool(windowRolledupAttribute);
if( winMgr.getWindow(name)->testClassName("FrameWindow") )
+
monitoredAttributes.append(" ").append(windowRolledupAttribute);
{
+
//CEGUI::MultiColumnList* mcl;
+
CEGUI::FrameWindow* frameWindow = static_cast<CEGUI::FrameWindow*>(window);
+
if(frameWindow->isRolledup() != config.rolledup)
+
frameWindow->toggleRollup();
+
}
+
 
}
 
}
  
 +
_setDialogAttributesMonitored(name, monitoredAttributes);
 
m_dialogConfigurations[name] = config;
 
m_dialogConfigurations[name] = config;
 
}
 
}
Line 522: Line 742:
 
config.sortedColumn  = m_defaultSortedColumn;
 
config.sortedColumn  = m_defaultSortedColumn;
 
config.sortAscending = m_defaultSortAscending;
 
config.sortAscending = m_defaultSortAscending;
CEGUI::String name;
+
CEGUI::String name, monitoredAttributes;
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
+
  
 
name = xmlAttributes.getValueAsString(windowNameAttribute);
 
name = xmlAttributes.getValueAsString(windowNameAttribute);
CEGUI::MultiColumnList* multiColumnList = static_cast<CEGUI::MultiColumnList*>(winMgr.getWindow(name));
 
  
std::vector<CEGUI::String> attributesMonitored;
+
if(xmlAttributes.exists(mclColumnSequenceAttribute))
std::map<CEGUI::String, std::vector<CEGUI::String>>::iterator itAttributesMonitored;
+
itAttributesMonitored = m_attributesMonitoredMultiColumnList.find(name);
+
if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
+
attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
+
else
+
{
+
// Use default attributes
+
itAttributesMonitored = m_attributesMonitoredMultiColumnList.find("");
+
if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
+
attributesMonitored = (*itAttributesMonitored).second;
+
}
+
 
+
if(xmlAttributes.exists(mclColumnSequenceAttribute) && isMonitoringAttribute(attributesMonitored, mclColumnSequenceAttribute))
+
 
{
 
{
 
CEGUI::String columnSequence = xmlAttributes.getValueAsString(mclColumnSequenceAttribute);
 
CEGUI::String columnSequence = xmlAttributes.getValueAsString(mclColumnSequenceAttribute);
Tokenize(columnSequence, config.columnSequence, ',');
+
Tokenize(columnSequence, config.columnSequence, mclColumnSequenceSeparator);
for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount() && columnIndex < config.columnSequence.size(); ++columnIndex)
+
monitoredAttributes.append(" ").append(mclColumnSequenceAttribute);
{
+
multiColumnList->moveColumn(multiColumnList->getColumnWithID(CEGUI::PropertyHelper::stringToUint(config.columnSequence.at(columnIndex))),
+
columnIndex);
+
}
+
 
}
 
}
if(xmlAttributes.exists(mclColumnWidthAttribute) && isMonitoringAttribute(attributesMonitored, mclColumnWidthAttribute))
+
if(xmlAttributes.exists(mclColumnWidthAttribute))
 
{
 
{
 
CEGUI::String columnWidths = xmlAttributes.getValueAsString(mclColumnWidthAttribute);
 
CEGUI::String columnWidths = xmlAttributes.getValueAsString(mclColumnWidthAttribute);
 
Tokenize(columnWidths, config.columnWidths, mclColumnWidthSeparator);
 
Tokenize(columnWidths, config.columnWidths, mclColumnWidthSeparator);
CEGUI::UDim width;
+
monitoredAttributes.append(" ").append(mclColumnWidthAttribute);
for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount() && columnIndex < config.columnWidths.size(); ++columnIndex)
+
{
+
width = CEGUI::PropertyHelper::stringToUDim(config.columnWidths.at(columnIndex));
+
multiColumnList->setColumnHeaderWidth(columnIndex, width);
+
}
+
 
}
 
}
if(xmlAttributes.exists(mclSortedColumnAttribute) && isMonitoringAttribute(attributesMonitored, mclSortedColumnAttribute))
+
if(xmlAttributes.exists(mclSortedColumnAttribute))
 
{
 
{
 
config.sortedColumn = xmlAttributes.getValueAsInteger(mclSortedColumnAttribute);
 
config.sortedColumn = xmlAttributes.getValueAsInteger(mclSortedColumnAttribute);
multiColumnList->setSortColumn( multiColumnList->getColumnWithID(config.sortedColumn) );
+
monitoredAttributes.append(" ").append(mclSortedColumnAttribute);
 
}
 
}
if(xmlAttributes.exists(mclAscendingSortAttribute) && isMonitoringAttribute(attributesMonitored, mclAscendingSortAttribute))
+
if(xmlAttributes.exists(mclAscendingSortAttribute))
 
{
 
{
 
config.sortAscending = xmlAttributes.getValueAsBool(mclAscendingSortAttribute);
 
config.sortAscending = xmlAttributes.getValueAsBool(mclAscendingSortAttribute);
multiColumnList->setSortDirection( config.sortAscending ? CEGUI::ListHeaderSegment::Ascending
+
monitoredAttributes.append(" ").append(mclAscendingSortAttribute);
: CEGUI::ListHeaderSegment::Descending);
+
 
}
 
}
  
 +
_setMultiColumnListAttributesMonitored(name, monitoredAttributes);
 
m_multiColumnListConfigurations[name] = config;
 
m_multiColumnListConfigurations[name] = config;
 
}
 
}
Line 660: Line 856:
 
m_attributesMonitoredMultiColumnList[multiColumnList] = newAttributes;
 
m_attributesMonitoredMultiColumnList[multiColumnList] = newAttributes;
 
}
 
}
</pre>
+
</source>
  
 
==== DialogConfigurationsDemo.h ====
 
==== DialogConfigurationsDemo.h ====
<pre>
+
<source lang="cpp">
 
#ifndef _DialogConfigurationsDemo_h_
 
#ifndef _DialogConfigurationsDemo_h_
 
#define _DialogConfigurationsDemo_h_
 
#define _DialogConfigurationsDemo_h_
Line 683: Line 879:
  
 
// Load the TaharezLook scheme and set up the default mouse cursor and font
 
// Load the TaharezLook scheme and set up the default mouse cursor and font
SchemeManager::getSingleton().loadScheme("TaharezLookSkin.scheme");
+
SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
 
System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
 
System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
FontManager::getSingleton().createFont("Commonwealth-10.font");
+
if(!FontManager::getSingleton().isFontPresent("Commonwealth-10"))
 +
FontManager::getSingleton().createFont("Commonwealth-10.font");
  
 
// Set the GUI Sheet
 
// Set the GUI Sheet
Line 747: Line 944:
 
}
 
}
  
    void cleanupSample(void)
+
void cleanupSample(void)
 
{
 
{
 
m_DialogConfigurations.saveConfigurations();
 
m_DialogConfigurations.saveConfigurations();
Line 798: Line 995:
  
 
#endif // _DialogConfigurationsDemo_h_
 
#endif // _DialogConfigurationsDemo_h_
</pre>
+
</source>
  
 
==== main.cpp ====
 
==== main.cpp ====
<pre>
+
<source lang="cpp">
 
#if defined( __WIN32__ ) || defined( _WIN32 )
 
#if defined( __WIN32__ ) || defined( _WIN32 )
 
#define WIN32_LEAN_AND_MEAN
 
#define WIN32_LEAN_AND_MEAN
Line 819: Line 1,016:
 
     return app.run();
 
     return app.run();
 
}
 
}
</pre>
+
</source>
 +
 
  
 
==== DialogConfigurations.layout ====
 
==== DialogConfigurations.layout ====
<pre>
+
<source lang="xml">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
  
Line 833: Line 1,031:
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.1875,0},{0.00833335,0},{0.8025,0},{0.111667,0}}" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.1875,0},{0.00833335,0},{0.8025,0},{0.111667,0}}" />
            <AutoWindow NameSuffix="__auto_hscrollbar__" >
 
                <AutoWindow NameSuffix="__auto_incbtn__" />
 
                <AutoWindow NameSuffix="__auto_decbtn__" />
 
                <AutoWindow NameSuffix="__auto_thumb__" />
 
            </AutoWindow>
 
            <AutoWindow NameSuffix="__auto_vscrollbar__" >
 
                <AutoWindow NameSuffix="__auto_incbtn__" />
 
                <AutoWindow NameSuffix="__auto_decbtn__" />
 
                <AutoWindow NameSuffix="__auto_thumb__" />
 
            </AutoWindow>
 
 
             <Window Type="TaharezLook/Button" Name="DialogConfigurations/Toolbar/ShowA" >
 
             <Window Type="TaharezLook/Button" Name="DialogConfigurations/Toolbar/ShowA" >
                 <Property Name="Text" >Show A</Property>
+
                 <Property Name="Text" Value="Show A" />
 
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
                 <Property Name="UnifiedAreaRect" Value="{{0.0581303,0},{0.156452,0},{0.30813,0},{0.858064,0}}" />
 
                 <Property Name="UnifiedAreaRect" Value="{{0.0581303,0},{0.156452,0},{0.30813,0},{0.858064,0}}" />
Line 850: Line 1,038:
 
             <Window Type="TaharezLook/Button" Name="DialogConfigurations/Toolbar/ShowC" >
 
             <Window Type="TaharezLook/Button" Name="DialogConfigurations/Toolbar/ShowC" >
 
                 <Property Name="Font" Value="Commonwealth-10" />
 
                 <Property Name="Font" Value="Commonwealth-10" />
                 <Property Name="Text" >Show C</Property>
+
                 <Property Name="Text" Value="Show C" />
 
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
                 <Property Name="UnifiedAreaRect" Value="{{0.388618,0},{0.156452,0},{0.638618,0},{0.858064,0}}" />
 
                 <Property Name="UnifiedAreaRect" Value="{{0.388618,0},{0.156452,0},{0.638618,0},{0.858064,0}}" />
Line 856: Line 1,044:
 
             <Window Type="TaharezLook/Button" Name="DialogConfigurations/Toolbar/ShowD" >
 
             <Window Type="TaharezLook/Button" Name="DialogConfigurations/Toolbar/ShowD" >
 
                 <Property Name="Font" Value="Commonwealth-10" />
 
                 <Property Name="Font" Value="Commonwealth-10" />
                 <Property Name="Text" >Show D</Property>
+
                 <Property Name="Text" Value="Show D" />
 
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
                 <Property Name="UnifiedAreaRect" Value="{{0.704878,0},{0.156452,0},{0.954878,0},{0.858064,0}}" />
 
                 <Property Name="UnifiedAreaRect" Value="{{0.704878,0},{0.156452,0},{0.954878,0},{0.858064,0}}" />
Line 862: Line 1,050:
 
         </Window>
 
         </Window>
 
         <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_A" >
 
         <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_A" >
             <Property Name="Text" >A - RolledUp not saved</Property>
+
             <Property Name="Text" Value="A - RolledUp not saved" />
 
             <Property Name="TitlebarFont" Value="Commonwealth-10" />
 
             <Property Name="TitlebarFont" Value="Commonwealth-10" />
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="TitlebarEnabled" Value="True" />
 
             <Property Name="TitlebarEnabled" Value="True" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.035,0},{0.123333,0},{0.325,0},{0.47,0}}" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.035,0},{0.123333,0},{0.325,0},{0.47,0}}" />
            <AutoWindow NameSuffix="__auto_titlebar__" >
 
                <Property Name="Font" Value="Commonwealth-10" />
 
                <Property Name="Text" >A - RolledUp not saved</Property>
 
            </AutoWindow>
 
            <AutoWindow NameSuffix="__auto_closebutton__" />
 
 
         </Window>
 
         </Window>
 
         <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_B" >
 
         <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_B" >
             <Property Name="Text" >B - Visible not saved</Property>
+
             <Property Name="Text" Value="B - Visible not saved" />
 
             <Property Name="TitlebarFont" Value="Commonwealth-10" />
 
             <Property Name="TitlebarFont" Value="Commonwealth-10" />
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="TitlebarEnabled" Value="True" />
 
             <Property Name="TitlebarEnabled" Value="True" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.35125,0},{0.123333,0},{0.64125,0},{0.47,0}}" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.35125,0},{0.123333,0},{0.64125,0},{0.47,0}}" />
            <AutoWindow NameSuffix="__auto_titlebar__" >
 
                <Property Name="Font" Value="Commonwealth-10" />
 
                <Property Name="Text" >B - Visible not saved</Property>
 
            </AutoWindow>
 
            <AutoWindow NameSuffix="__auto_closebutton__" />
 
 
         </Window>
 
         </Window>
 
         <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_C" >
 
         <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_C" >
             <Property Name="Text" >C - Position &amp; Size not saved</Property>
+
             <Property Name="Text" Value="C - Position &amp; Size not saved" />
 
             <Property Name="TitlebarFont" Value="Commonwealth-10" />
 
             <Property Name="TitlebarFont" Value="Commonwealth-10" />
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="TitlebarEnabled" Value="True" />
 
             <Property Name="TitlebarEnabled" Value="True" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.6675,0},{0.123333,0},{0.957501,0},{0.47,0}}" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.6675,0},{0.123333,0},{0.957501,0},{0.47,0}}" />
            <AutoWindow NameSuffix="__auto_titlebar__" >
 
                <Property Name="Font" Value="Commonwealth-10" />
 
                <Property Name="Text" >C - Position &amp; Size not saved</Property>
 
            </AutoWindow>
 
            <AutoWindow NameSuffix="__auto_closebutton__" />
 
 
         </Window>
 
         </Window>
 
         <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_D" >
 
         <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_D" >
             <Property Name="Text" >D Saves MultiColumnList column width, sequence, and sort</Property>
+
             <Property Name="Text" Value="D Saves MultiColumnList column width, sequence, and sort" />
 
             <Property Name="TitlebarFont" Value="Commonwealth-10" />
 
             <Property Name="TitlebarFont" Value="Commonwealth-10" />
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
             <Property Name="TitlebarEnabled" Value="True" />
 
             <Property Name="TitlebarEnabled" Value="True" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.10625,0},{0.53375,0},{0.86625,0},{0.962083,0}}" />
 
             <Property Name="UnifiedAreaRect" Value="{{0.10625,0},{0.53375,0},{0.86625,0},{0.962083,0}}" />
            <AutoWindow NameSuffix="__auto_titlebar__" >
 
                <Property Name="Font" Value="Commonwealth-10" />
 
                <Property Name="Text" >D - Saves MultiColumnList column width, sequence, and sort</Property>
 
            </AutoWindow>
 
            <AutoWindow NameSuffix="__auto_closebutton__" />
 
 
             <Window Type="TaharezLook/MultiColumnList" Name="DialogConfigurations/Window_D/MultiColumnList" >
 
             <Window Type="TaharezLook/MultiColumnList" Name="DialogConfigurations/Window_D/MultiColumnList" >
 
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
 
                 <Property Name="UnifiedAreaRect" Value="{{0.031235,0},{0.140467,0},{0.968886,0},{0.950778,0}}" />
 
                 <Property Name="UnifiedAreaRect" Value="{{0.031235,0},{0.140467,0},{0.968886,0},{0.950778,0}}" />
                <AutoWindow NameSuffix="__auto_listheader__" />
 
                <AutoWindow NameSuffix="__auto_hscrollbar__" >
 
                    <AutoWindow NameSuffix="__auto_incbtn__" />
 
                    <AutoWindow NameSuffix="__auto_decbtn__" />
 
                    <AutoWindow NameSuffix="__auto_thumb__" />
 
                </AutoWindow>
 
                <AutoWindow NameSuffix="__auto_vscrollbar__" >
 
                    <AutoWindow NameSuffix="__auto_incbtn__" />
 
                    <AutoWindow NameSuffix="__auto_decbtn__" />
 
                    <AutoWindow NameSuffix="__auto_thumb__" />
 
                </AutoWindow>
 
 
             </Window>
 
             </Window>
 
         </Window>
 
         </Window>
 
     </Window>
 
     </Window>
 
</GUILayout>
 
</GUILayout>
</pre>
+
</source>
 +
 
 +
[[Category:Tutorials]]

Latest revision as of 16:16, 4 March 2011

Written for CEGUI 0.5


Works with versions 0.5.x (obsolete)

Written for CEGUI 0.6


Works with versions 0.6.x (obsolete)

Introduction

Dialogs (frame windows) can be moved around, resized, hidden, and rolled up while the application is running. MultiColumnLists can have their columns rearranged, resized, and a column can sort its content in ascending or descending order. However closing and then restarting the application will reset these settings to their default values, those specified within a .layout file if one was use, or those specified in code.

This clases saves these attributes into an XML file. When the application restarts the contents of the XML file will be read and the dialogs and MultiColumnLists will be restored to their last states.

Please discuss this snippet in the Storing Dialog Configurations thread on the message board.

Incorporating into Sample_Demo7

This demo contains 3 dialogs. Let's store their configurations.

Add DialogConfigurations.cpp to the Sample_Demo7 project.

Edit Sample_Demo7.h:

  • add #include "DialogConfigurations.h"
  • add within the protected section: DialogConfigurations m_dialogConfigurations;

Edit Sample_Demo7.cpp to add the following at the end of the Demo7Sample::initialiseSample() function, between initDemoEventWiring(); and return true;:

  m_dialogConfigurations.loadConfigurations("../datafiles/configs/Sample_Demo7.xml", "../datafiles/configs/DialogConfigurations.xsd");
  m_dialogConfigurations.addDialog("Demo7/Window1");
  m_dialogConfigurations.addDialog("Demo7/Window2");
  m_dialogConfigurations.addDialog("Demo7/Window3");

Add the following to Demo7Sample::cleanupSample()

  m_dialogConfigurations.saveConfigurations();

That's it! From now on the 3 windows within that demo will "remember" their previous configurations.

Warning: the Demo7Sample::cleanupSample() is never called when exiting the demo, despite what the comments might say. A solution is presented on the message board.

Configuration Attributes

The XML configuration file is loaded by a call to loadConfigurations(). It silently ignores errors within that XML file. The worst that will happen is that some dialogs and MultiColumnLists will revert to their initial values.

Calling addDialog() and passing the window name as parameter will register that dialog to have its configuration written to the XML file. The next call to saveConfigurations() will write the configuration of that registered window such that the next time loadConfigurations() is called the window will be automatically registered.

The second parameter of addDialog() allows you to specify which attributes to monitor. By default every attribute is monitored. However you can specify to monitor one or many of the following, separated by spaces: Position, Visible, and RolledUp.

The addMultiColumnList() function behaves in a similar manner, allowing you to specify which MultiColumnLists and which of their attributes to monitor. Again the default is to monitor every attribute but you can also specify one or many of the following: ColumnSequence, ColumnWidths, SortedColumn, and AscendingSort.

Files

DialogConfigurations.h

#ifndef _DialogConfigurations_h_
#define _DialogConfigurations_h_
 
#include "CEGUI.h"
#include "CEGUIXMLHandler.h"
#include "CEGUIXMLParser.h"
#include "CEGUIXMLAttributes.h"
#include <map>
 
class DialogConfigurations : public CEGUI::XMLHandler
{
public:
	// Constructor.
	// Sets various default values.
	DialogConfigurations();
 
	// Load the configuration of every stored dialog and multi column list.
	// By default, also apply these configurations.
	bool loadConfigurations(const CEGUI::String& xmlFile, const CEGUI::String& schema = "", const bool& applyConfigurations = true);
 
	// Store the configuration of every dialog and multi column list.
	bool saveConfigurations();
 
	// Set default configurations for dialogs.
	void setDialogDefaults(const CEGUI::URect& position, const bool& visible, const bool& rolledup);
 
	// Specify which dialog attributes are monitored by default.
	void setDefaultDialogAttributesMonitored(const CEGUI::String& attributesMonitored);
 
	// Add a dialog to be monitored.
	// Optionally specify which attributes this specific dialog monitors.
	bool addDialog(const CEGUI::String& widget, const CEGUI::String& attributesMonitored = "");
 
	// Return the position of the specified dialog.
	const CEGUI::URect& getDialogSavedPosition(const CEGUI::String& dialog);
 
	// Return the visible/hidden state of the specified dialog.
	const bool& getDialogSavedVisible(const CEGUI::String& dialog);
 
	// Return the expansion state of the specified dialog.
	const bool& getDialogSavedRolledup(const CEGUI::String& dialog);
 
	// Apply the saved configuration to the specified dialog.
	bool applyDialogConfiguration(const CEGUI::String& dialog = "");
 
	// Set default configurations for multi column lists.
	void setMultiColumnListDefaults(const std::vector<CEGUI::String>& columnSequence, const CEGUI::uint& sortedColumn, const bool& sortAscending, const std::vector<CEGUI::String>& columnWidths);
 
	// Specify which dialog attributes are monitored by default.
	void setDefaultMultiColumnListAttributesMonitored(const CEGUI::String& attributesMonitored);
 
	// Add a MultiColumnList to be monitored.
	bool addMultiColumnList(const CEGUI::String& widget, const CEGUI::String& attributesMonitored = "");
 
	// Apply the saved configuration to the specified multi column list.
	bool applyMultiColumnListConfiguration(const CEGUI::String& multiColumnList = "");
 
private:
	// Whether a particular attribute is monitored.
	bool isMonitoringAttribute(const std::vector<CEGUI::String>& list, const CEGUI::String& attribute);
 
	// Performs the actual load every stored configuration.
    void elementStart(const CEGUI::String& element, const CEGUI::XMLAttributes& xmlAttributes);
 
	// Tag name for dialog positions element.
	static const CEGUI::String m_DialogConfigurationElement;
 
	// Tag name for position elements.
	static const CEGUI::String m_configurationElementDialog;
 
	// Attribute name that stores the name of the window.
	static const char windowNameAttribute[];
 
	// Attribute name that stores the position of the window.
	static const char windowPosAttribute[];
 
	// Attribute name that stores the visible state of the window.
	static const char windowVisibleAttribute[];
 
	// Attribute name that stores the rolledUp state of the window.
	static const char windowRolledupAttribute[];
 
	// Tag name of MultiColumnList elements.
	static const CEGUI::String m_configurationElementMultiColumnList;
 
	// Attribute name that stores the sequence of the columns.
	static const char mclColumnSequenceAttribute[];
 
	// Attribute name that stores which column is sorted.
	static const char mclSortedColumnAttribute[];
 
	// Attribute name that stores the sort order direction.
	static const char mclAscendingSortAttribute[];
 
	// Attribute name that stores the widths of the columns.
	static const char DialogConfigurations::mclColumnWidthAttribute[];
 
	// Separator for the column sequences.
	static const char DialogConfigurations::mclColumnSequenceSeparator;
 
	// Separator for the column widths.
	static const char DialogConfigurations::mclColumnWidthSeparator;
 
	// Special attribute name to monitor every attribute.
	static const char monitoredAttributeAll[];
 
	// Special attribute name to monitor no attribute.
	static const char monitoredAttributeNone[];
 
	// The value of one dialog configuration.
	struct DialogConfig {
		CEGUI::URect position;
		bool visible;
		bool rolledup;
	};
 
	// List of the dialog configurations.
	std::map<CEGUI::String, DialogConfig> m_dialogConfigurations;
 
	// Default position.
	CEGUI::URect m_defaultPosition;
 
	// Default visible/hidden.
	bool m_defaultVisible;
 
	// Default rolled up/expanded.
	bool m_defaultRolledup;
 
	// Specify which attributes to monitor for this dialog.
	void _setDialogAttributesMonitored(const CEGUI::String& dialog, const CEGUI::String& attributesMonitored);
 
	// List of the attributes monitored per dialog.
	std::map<CEGUI::String, std::vector<CEGUI::String>> m_attributesMonitoredDialog;
 
	// The value of one multi column list configuration.
	struct MultiColumnListConfig {
		std::vector<CEGUI::String> columnSequence;
		CEGUI::uint sortedColumn;
		bool sortAscending;
		std::vector<CEGUI::String> columnWidths;
	};
 
	// List of the multi column list configurations.
	std::map<CEGUI::String, MultiColumnListConfig> m_multiColumnListConfigurations;
 
	// Default column sequence.
	std::vector<CEGUI::String> m_defaultColumnSequence;
 
	// Default sorted column.
	CEGUI::uint m_defaultSortedColumn;
 
	// Default sort order.
	bool m_defaultSortAscending;
 
	// Default column widths.
	std::vector<CEGUI::String> m_defaultColumnWidths;
 
	// Specify which attributes to monitor for this multi column list.
	void _setMultiColumnListAttributesMonitored(const CEGUI::String& multiColumnList, const CEGUI::String& attributesMonitored);
 
	// List of the attributes monitored per MultiColumnList
	std::map<CEGUI::String, std::vector<CEGUI::String>> m_attributesMonitoredMultiColumnList;
 
	// File containing the positions.
	CEGUI::String m_configFile;
 
	// List of the supported attributes.
	static std::vector<CEGUI::String> m_attributeList;
};
 
#endif // _DialogConfigurations_h_

DialogConfigurations.cpp

#include "DialogConfigurations.h"
#include "CEGUIPropertyHelper.h"
 
//Definition of XML elements and attributes
const CEGUI::String DialogConfigurations::m_DialogConfigurationElement( "DialogConfigurations" );
const CEGUI::String DialogConfigurations::m_configurationElementDialog( "DialogConfiguration" );
const char DialogConfigurations::windowNameAttribute[]		= "Name";
const char DialogConfigurations::windowPosAttribute[]		= "Position";
const char DialogConfigurations::windowVisibleAttribute[]	= "Visible";
const char DialogConfigurations::windowRolledupAttribute[]	= "RolledUp";
const char DialogConfigurations::monitoredAttributeAll[]	= "All";
const char DialogConfigurations::monitoredAttributeNone[]	= "None";
const CEGUI::String DialogConfigurations::m_configurationElementMultiColumnList( "MultiColumnListConfiguration" );
const char DialogConfigurations::mclColumnSequenceAttribute[]	= "ColumnSequence";
const char DialogConfigurations::mclColumnWidthAttribute[]	= "ColumnWidths";
const char DialogConfigurations::mclSortedColumnAttribute[]	= "SortedColumn";
const char DialogConfigurations::mclAscendingSortAttribute[]= "AscendingSort";
const char DialogConfigurations::mclColumnSequenceSeparator	= ',';
const char DialogConfigurations::mclColumnWidthSeparator	= ';';
 
// List of the supported attributes
// Each attribute is enclosed within spaces
//const CEGUI::String DialogConfigurations::m_attributeList = " All None Position Visible RolledUp MCLWidths MCLSequence MCLSort ";
std::vector<CEGUI::String> DialogConfigurations::m_attributeList;
 
 
void Tokenize(const CEGUI::String& str, std::vector<CEGUI::String>& tokens, const char delimiters = ' ')
{
	// Break a sentence into multiple words separated by delimiters
	// Does not handle words within double-quotes: One "2 &2" three, four
 
    // Skip delimiters at beginning
	CEGUI::String::size_type lastPos = str.find_first_not_of(delimiters, 0);
 
    // Find first "non-delimiter"
	CEGUI::String::size_type pos = str.find_first_of(delimiters, lastPos);
 
	CEGUI::String::size_type length = str.length();
	while (str.npos != pos || str.npos != lastPos)
    {
		// Cap the position to the length of the string
		if(pos == str.npos)
			pos = length;
		if(lastPos == str.npos)
			lastPos = length;
 
        // Found a token, add it to the vector
        tokens.push_back(str.substr(lastPos, pos - lastPos));
 
        // Skip delimiters
        lastPos = str.find_first_not_of(delimiters, pos);
 
        // Find next "non-delimiter"
        pos = str.find_first_of(delimiters, lastPos);
    }
}
 
DialogConfigurations::DialogConfigurations()
{
	setDialogDefaults(CEGUI::URect( CEGUI::UDim(0.0f, 0.0f),
									CEGUI::UDim(0.0f, 0.0f),
									CEGUI::UDim(0.5f, 0.0f),
									CEGUI::UDim(0.5f, 0.0f)),
					true,
					true);
 
	// setMultiColumnListDefaults()
	m_defaultSortedColumn  = 0;
	m_defaultSortAscending = true;
 
	if(m_attributeList.empty())
	{
		// This is a static variable, only initialize once
		m_attributeList.push_back(monitoredAttributeAll);
		m_attributeList.push_back(monitoredAttributeNone);
		m_attributeList.push_back(windowPosAttribute);
		m_attributeList.push_back(windowVisibleAttribute);
		m_attributeList.push_back(windowRolledupAttribute);
		m_attributeList.push_back(mclColumnSequenceAttribute);
		m_attributeList.push_back(mclSortedColumnAttribute);
		m_attributeList.push_back(mclAscendingSortAttribute);
		m_attributeList.push_back(mclColumnWidthAttribute);
	}
 
	// The default is to monitor every attribute
	_setDialogAttributesMonitored("", monitoredAttributeAll);
	_setMultiColumnListAttributesMonitored("", monitoredAttributeAll);
}
 
bool DialogConfigurations::loadConfigurations(const CEGUI::String& xmlFile, const CEGUI::String& schema, const bool& applyConfigurations)
{
	// Load the config of every stored dialog
	assert(!xmlFile.empty() && "You must specify an xml file to loadConfigurations()");
	m_configFile = xmlFile;
	bool loadedOk = true;
	try
	{
		CEGUI::System::getSingleton().getXMLParser()->parseXMLFile(*this, m_configFile, schema, "");
	}
	catch(const CEGUI::Exception&)
	{
		// File is empty or parse error
		// Silently ignore; we'll create a new file when saving
		loadedOk = false;
	}
 
	if(applyConfigurations)
	{
		applyDialogConfiguration();
		applyMultiColumnListConfiguration();
	}
 
	return loadedOk;
}
 
bool DialogConfigurations::saveConfigurations()
{
	// Store the configuration of every registered dialog, either within
	// the loaded XML file or those manually registered via addDialog() 
	assert(!m_configFile.empty() && "You must specify an xml file by calling loadConfigurations() before saveConfigurations()");
 
	// Try to open the XML file in writing mode
    std::ofstream fileSave;
	fileSave.open(m_configFile.c_str(), std::ios::out) ;
    if( !fileSave.is_open() )
    {
		CEGUI::Logger::getSingleton().logEvent("Could not write to dialog configuration file ("
												+ m_configFile
												+ ").  Is it read-only?",
												CEGUI::Errors);
        return false;
    }
 
	// Write the header
	fileSave << "<?xml version=\"1.0\" ?>" << std::endl
			<< "<" << m_DialogConfigurationElement << ">"
			<< std::endl;
 
	// Write each dialog's configuration
	DialogConfig dialogConfig;
	CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
	std::map<CEGUI::String, DialogConfig>::iterator itDialogConfig;
	std::map<CEGUI::String, std::vector<CEGUI::String>>::iterator itAttributesMonitored;
	std::vector<CEGUI::String> attributesMonitored;
	CEGUI::Window* window;
	for(itDialogConfig = m_dialogConfigurations.begin(); itDialogConfig != m_dialogConfigurations.end(); ++itDialogConfig)
	{
		if(!winMgr.isWindowPresent(itDialogConfig->first))
			continue;
 
		itAttributesMonitored = m_attributesMonitoredDialog.find(itDialogConfig->first);
		if(itAttributesMonitored != m_attributesMonitoredDialog.end())
			attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
		else
		{
			// Use default attributes
			itAttributesMonitored = m_attributesMonitoredDialog.find("");
			if(itAttributesMonitored != m_attributesMonitoredDialog.end())
				attributesMonitored = (*itAttributesMonitored).second;
		}
 
		window = winMgr.getWindow(itDialogConfig->first);
		dialogConfig.position = window->getArea();
		dialogConfig.visible	= window->isVisible();
		if( window->testClassName("FrameWindow") )
			dialogConfig.rolledup = static_cast<CEGUI::FrameWindow*>(window)->isRolledup();
		else
			dialogConfig.rolledup = false;
		fileSave << "  <" << m_configurationElementDialog.c_str() << " "
			<< windowNameAttribute		<< "=\"" << itDialogConfig->first	<< "\" ";
		if(isMonitoringAttribute(attributesMonitored, windowPosAttribute))
			fileSave << windowPosAttribute		<< "=\"" << CEGUI::PropertyHelper::urectToString(dialogConfig.position)	<< "\" ";
		if(isMonitoringAttribute(attributesMonitored, windowVisibleAttribute))
			fileSave << windowVisibleAttribute	<< "=\"" << dialogConfig.visible	<< "\" ";
		if(isMonitoringAttribute(attributesMonitored, windowRolledupAttribute))
			fileSave << windowRolledupAttribute	<< "=\"" << dialogConfig.rolledup	<< "\" ";
		fileSave << "/>" << std::endl;
	}
 
 
	// Write each MultiColumnList's configuration
	std::map<CEGUI::String, MultiColumnListConfig>::iterator itMultiColumnListConfig;
	attributesMonitored.clear();
	CEGUI::MultiColumnList* multiColumnList;
	for(itMultiColumnListConfig = m_multiColumnListConfigurations.begin(); itMultiColumnListConfig != m_multiColumnListConfigurations.end(); ++itMultiColumnListConfig)
	{
		itAttributesMonitored = m_attributesMonitoredMultiColumnList.find(itMultiColumnListConfig->first);
		if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
			attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
		else
		{
			// Use default attributes
			itAttributesMonitored = m_attributesMonitoredMultiColumnList.find("");
			if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
				attributesMonitored = (*itAttributesMonitored).second;
		}
 
		multiColumnList = static_cast<CEGUI::MultiColumnList*>(winMgr.getWindow(itMultiColumnListConfig->first));
		fileSave << "  <" << m_configurationElementMultiColumnList.c_str() << " "
			<< windowNameAttribute		<< "=\"" << itMultiColumnListConfig->first	<< "\" ";
		if(isMonitoringAttribute(attributesMonitored, mclColumnSequenceAttribute) && multiColumnList->getColumnCount())
		{
			fileSave << mclColumnSequenceAttribute << "=\"";
			for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount(); ++columnIndex)
			{
				if(columnIndex)
					fileSave << mclColumnSequenceSeparator;
				fileSave << multiColumnList->getColumnID(columnIndex);
			}
			fileSave << "\" ";
		}
		if(isMonitoringAttribute(attributesMonitored, mclColumnWidthAttribute) && multiColumnList->getColumnCount())
		{
			fileSave << mclColumnWidthAttribute << "=\"";
			for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount(); ++columnIndex)
			{
				if(columnIndex)
					fileSave << mclColumnWidthSeparator;
				fileSave << CEGUI::PropertyHelper::udimToString(multiColumnList->getColumnHeaderWidth(columnIndex));
			}
			fileSave << "\" ";
		}
		if(isMonitoringAttribute(attributesMonitored, mclSortedColumnAttribute))
			fileSave << mclSortedColumnAttribute	<< "=\"" << multiColumnList->getColumnID(multiColumnList->getSortColumn()) << "\" ";
		if(isMonitoringAttribute(attributesMonitored, mclAscendingSortAttribute))
			fileSave << mclAscendingSortAttribute << "=\"" << (multiColumnList->getSortDirection() != CEGUI::ListHeaderSegment::Descending) << "\" ";
		fileSave << "/>" << std::endl;
	}
 
 
	// Write the footer
	fileSave << "</" << m_DialogConfigurationElement << ">" << std::endl;
	fileSave.close();
	return true;
}
 
void DialogConfigurations::setDialogDefaults(const CEGUI::URect& position, const bool& visible, const bool& rolledup)
{
	// Set default values
	// Should validate what's being passed as parameters
	m_defaultPosition	= position;
	m_defaultVisible	= visible;
	m_defaultRolledup	= rolledup;
}
 
void DialogConfigurations::setDefaultDialogAttributesMonitored(const CEGUI::String& attributesMonitored)
{
	_setDialogAttributesMonitored("", attributesMonitored);
}
 
bool DialogConfigurations::addDialog(const CEGUI::String& widget, const CEGUI::String& attributesMonitored)
{
	// Add a dialog to be monitored
	// This can be used to automatically write the contents of the initial XML file
	//   rather than editing it by hand.
	assert(!widget.empty() && "You must pass a dialog name to addDialog()");
 
	if(!attributesMonitored.empty())
		_setDialogAttributesMonitored(widget, attributesMonitored);
 
	std::map<CEGUI::String, DialogConfig>::iterator itConfig;
	itConfig = m_dialogConfigurations.find(widget);
	if(itConfig != m_dialogConfigurations.end())
		return false; // This dialog is already added
 
	CEGUI::Window* window = CEGUI::WindowManager::getSingleton().getWindow(widget);
	DialogConfig config;
	config.position = window->getArea();
	config.visible	= window->isVisible();
	if( window->testClassName("FrameWindow") )
		config.rolledup = static_cast<CEGUI::FrameWindow*>(window)->isRolledup();
	else
		config.rolledup = m_defaultRolledup; // Not really needed, unless this window inherits from FrameWindow after being loaded
 
	m_dialogConfigurations[widget] = config;
	return true;
}
 
const CEGUI::URect& DialogConfigurations::getDialogSavedPosition(const CEGUI::String& dialog)
{
	// Return the position of the specified dialog
	std::map<CEGUI::String, DialogConfig>::iterator itConfig;
	itConfig = m_dialogConfigurations.find(dialog);
	return itConfig == m_dialogConfigurations.end() ? m_defaultPosition : (*itConfig).second.position;
}
 
const bool& DialogConfigurations::getDialogSavedVisible(const CEGUI::String& dialog)
{
	// Return the visible/hidden state of the specified dialog
	std::map<CEGUI::String, DialogConfig>::iterator itConfig;
	itConfig = m_dialogConfigurations.find(dialog);
	return itConfig == m_dialogConfigurations.end() ? m_defaultVisible : (*itConfig).second.visible;
}
 
const bool& DialogConfigurations::getDialogSavedRolledup(const CEGUI::String& dialog)
{
	// Return the expansion state of the specified dialog
	std::map<CEGUI::String, DialogConfig>::iterator itConfig;
	itConfig = m_dialogConfigurations.find(dialog);
	return itConfig == m_dialogConfigurations.end() ? m_defaultRolledup : (*itConfig).second.rolledup;
}
 
bool DialogConfigurations::applyDialogConfiguration(const CEGUI::String& dialog)
{
	// Apply the saved configuration to a dialog
	if(dialog.length() == 0)
	{
		// Load every dialog configurations
		std::map<CEGUI::String, DialogConfig>::iterator itConfig;
		for(itConfig = m_dialogConfigurations.begin(); itConfig != m_dialogConfigurations.end(); itConfig++)
		{
			applyDialogConfiguration((*itConfig).first);
		}
	}
	else
	{
		// Find this dialog's configuration
		CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
		std::map<CEGUI::String, DialogConfig>::iterator itConfig;
		itConfig = m_dialogConfigurations.find(dialog);
		if(itConfig == m_dialogConfigurations.end() || !winMgr.isWindowPresent(dialog))
			return false;
 
		// Determine which attributes are monitored
		std::vector<CEGUI::String> attributesMonitored;
		std::map<CEGUI::String, std::vector<CEGUI::String>>::iterator itAttributesMonitored;
		itAttributesMonitored = m_attributesMonitoredDialog.find(dialog);
		if(itAttributesMonitored != m_attributesMonitoredDialog.end())
			attributesMonitored = (*itAttributesMonitored).second; // Dialog has specified attributes
		else
		{
			// Use default attributes
			itAttributesMonitored = m_attributesMonitoredDialog.find("");
			if(itAttributesMonitored == m_attributesMonitoredDialog.end())
				return false;  // Could not retrieve the default attributes (should never happen)
			attributesMonitored = (*itAttributesMonitored).second;
		}
 
		// Apply the configuration to the dialog
		CEGUI::Window* window = winMgr.getWindow(dialog);
		if(isMonitoringAttribute(attributesMonitored, windowPosAttribute))
			window->setArea((*itConfig).second.position);
		if(isMonitoringAttribute(attributesMonitored, windowVisibleAttribute))
			window->setVisible((*itConfig).second.visible);
		if(isMonitoringAttribute(attributesMonitored, windowRolledupAttribute))
		{
			if( window->testClassName("FrameWindow") )
			{
				CEGUI::FrameWindow* frameWindow = static_cast<CEGUI::FrameWindow*>(window);
				if(frameWindow->isRolledup() != (*itConfig).second.rolledup)
					frameWindow->toggleRollup();
			}
		}
	}
	return true;
}
 
void DialogConfigurations::setMultiColumnListDefaults(const std::vector<CEGUI::String>& columnSequence, const CEGUI::uint& sortedColumn, const bool& sortAscending, const std::vector<CEGUI::String>& columnWidths)
{
	// Set default values
	// Should validate what's being passed as parameters
	m_defaultColumnSequence = columnSequence;
	m_defaultSortedColumn	= sortedColumn;
	m_defaultSortAscending	= sortAscending;
	m_defaultColumnWidths	= columnWidths;
}
 
void DialogConfigurations::setDefaultMultiColumnListAttributesMonitored(const CEGUI::String& attributesMonitored)
{
	_setMultiColumnListAttributesMonitored("", attributesMonitored);
}
 
bool DialogConfigurations::addMultiColumnList(const CEGUI::String& widget, const CEGUI::String& attributesMonitored)
{
	// Add a MultiColumnList to be monitored
	// This can be used to automatically write the contents of the initial XML file
	//   rather than editing it by hand.
	assert(!widget.empty() && "You must pass a multiColumnList name to addMultiColumnList()");
 
	if(!attributesMonitored.empty())
		_setMultiColumnListAttributesMonitored(widget, attributesMonitored);
 
	std::map<CEGUI::String, MultiColumnListConfig>::iterator itConfig;
	itConfig = m_multiColumnListConfigurations.find(widget);
	if(itConfig != m_multiColumnListConfigurations.end())
		return false; // This MultiColumnList is already added
 
	MultiColumnListConfig config;
	CEGUI::MultiColumnList* multiColumnList = static_cast<CEGUI::MultiColumnList*>(CEGUI::WindowManager::getSingleton().getWindow(widget));
	assert(multiColumnList->testClassName("MultiColumnList") && "This widget is not a MultiColumnList");
 
	for(CEGUI::uint columnIndex = 0; columnIndex < multiColumnList->getColumnCount(); ++columnIndex)
	{
		config.columnSequence.push_back(CEGUI::PropertyHelper::uintToString(multiColumnList->getColumnID(columnIndex)));
		config.columnWidths.push_back(CEGUI::PropertyHelper::udimToString(multiColumnList->getColumnHeaderWidth(columnIndex)));
	}
	config.sortedColumn  = multiColumnList->getSortColumn();
	config.sortAscending = multiColumnList->getSortDirection() != CEGUI::ListHeaderSegment::Descending;
 
	m_multiColumnListConfigurations[widget] = config;
	return true;
}
 
bool DialogConfigurations::applyMultiColumnListConfiguration(const CEGUI::String& multiColumnList)
{
	// Apply the saved configuration to a multi column list
	if(multiColumnList.length() == 0)
	{
		// Load every multi column list configurations
		std::map<CEGUI::String, MultiColumnListConfig>::iterator itConfig;
		for(itConfig = m_multiColumnListConfigurations.begin(); itConfig != m_multiColumnListConfigurations.end(); itConfig++)
		{
			applyMultiColumnListConfiguration((*itConfig).first);
		}
	}
	else
	{
		// Find this multi column list's configuration
		CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
		std::map<CEGUI::String, MultiColumnListConfig>::iterator itConfig;
		itConfig = m_multiColumnListConfigurations.find(multiColumnList);
		if(itConfig == m_multiColumnListConfigurations.end() || !winMgr.isWindowPresent(multiColumnList))
			return false;
 
		// Determine which attributes are monitored
		std::vector<CEGUI::String> attributesMonitored;
		std::map<CEGUI::String, std::vector<CEGUI::String>>::iterator itAttributesMonitored;
		itAttributesMonitored = m_attributesMonitoredMultiColumnList.find(multiColumnList);
		if(itAttributesMonitored != m_attributesMonitoredMultiColumnList.end())
			attributesMonitored = (*itAttributesMonitored).second; // Multi column list has specified attributes
		else
		{
			// Use default attributes
			itAttributesMonitored = m_attributesMonitoredMultiColumnList.find("");
			if(itAttributesMonitored == m_attributesMonitoredMultiColumnList.end())
				return false;  // Could not retrieve the default attributes (should never happen)
			attributesMonitored = (*itAttributesMonitored).second;
		}
 
		// Apply the configuration to the multi column list
		CEGUI::MultiColumnList* window = static_cast<CEGUI::MultiColumnList*>(winMgr.getWindow(multiColumnList));
		if(isMonitoringAttribute(attributesMonitored, mclColumnSequenceAttribute))
		{
			for(CEGUI::uint columnIndex = 0; columnIndex < window->getColumnCount() && columnIndex < (*itConfig).second.columnSequence.size(); ++columnIndex)
			{
				window->moveColumn(window->getColumnWithID(CEGUI::PropertyHelper::stringToUint((*itConfig).second.columnSequence.at(columnIndex))),
									columnIndex);
			}
		}
		if(isMonitoringAttribute(attributesMonitored, mclColumnWidthAttribute))
		{
			CEGUI::UDim width;
			for(CEGUI::uint columnIndex = 0; columnIndex < window->getColumnCount() && columnIndex < (*itConfig).second.columnWidths.size(); ++columnIndex)
			{
				width = CEGUI::PropertyHelper::stringToUDim((*itConfig).second.columnWidths.at(columnIndex));
				window->setColumnHeaderWidth(columnIndex, width);
			}
		}
		if(isMonitoringAttribute(attributesMonitored, mclSortedColumnAttribute))
		{
			window->setSortColumn( window->getColumnWithID((*itConfig).second.sortedColumn) );
		}
		if(isMonitoringAttribute(attributesMonitored, mclAscendingSortAttribute))
		{
			window->setSortDirection( (*itConfig).second.sortAscending ? CEGUI::ListHeaderSegment::Ascending
																		: CEGUI::ListHeaderSegment::Descending);
		}
	}
	return true;
}
 
bool DialogConfigurations::isMonitoringAttribute(const std::vector<CEGUI::String>& list, const CEGUI::String& attribute)
{
	std::vector<CEGUI::String>::const_iterator itList;
	for(itList = list.begin(); itList != list.end(); itList++)
	{
		if(!(*itList).compare(attribute))
			return true;
	}
	return false;
}
 
void DialogConfigurations::elementStart(const CEGUI::String& element, const CEGUI::XMLAttributes& xmlAttributes)
{
	// Performs the actual load every stored configuration
	if (element == m_configurationElementDialog)
    {
		DialogConfig config;
		config.position = m_defaultPosition;
		config.visible  = m_defaultVisible;
		config.rolledup = m_defaultRolledup;
		CEGUI::String name, monitoredAttributes;
		CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
 
		name = xmlAttributes.getValueAsString(windowNameAttribute);
 
		if(xmlAttributes.exists(windowPosAttribute))
		{
			config.position	= CEGUI::PropertyHelper::stringToURect(xmlAttributes.getValueAsString(windowPosAttribute));
			monitoredAttributes.append(" ").append(windowPosAttribute);
		}
		if(xmlAttributes.exists(windowVisibleAttribute))
		{
			config.visible = xmlAttributes.getValueAsBool(windowVisibleAttribute);
			monitoredAttributes.append(" ").append(windowVisibleAttribute);
		}
		if(xmlAttributes.exists(windowRolledupAttribute))
		{
			config.rolledup	= xmlAttributes.getValueAsBool(windowRolledupAttribute);
			monitoredAttributes.append(" ").append(windowRolledupAttribute);
		}
 
		_setDialogAttributesMonitored(name, monitoredAttributes);
		m_dialogConfigurations[name] = config;
	}
	else if (element == m_configurationElementMultiColumnList)
    {
		MultiColumnListConfig config;
		config.sortedColumn  = m_defaultSortedColumn;
		config.sortAscending = m_defaultSortAscending;
		CEGUI::String name, monitoredAttributes;
 
		name = xmlAttributes.getValueAsString(windowNameAttribute);
 
		if(xmlAttributes.exists(mclColumnSequenceAttribute))
		{
			CEGUI::String columnSequence = xmlAttributes.getValueAsString(mclColumnSequenceAttribute);
			Tokenize(columnSequence, config.columnSequence, mclColumnSequenceSeparator);
			monitoredAttributes.append(" ").append(mclColumnSequenceAttribute);
		}
		if(xmlAttributes.exists(mclColumnWidthAttribute))
		{
			CEGUI::String columnWidths = xmlAttributes.getValueAsString(mclColumnWidthAttribute);
			Tokenize(columnWidths, config.columnWidths, mclColumnWidthSeparator);
			monitoredAttributes.append(" ").append(mclColumnWidthAttribute);
		}
		if(xmlAttributes.exists(mclSortedColumnAttribute))
		{
			config.sortedColumn = xmlAttributes.getValueAsInteger(mclSortedColumnAttribute);
			monitoredAttributes.append(" ").append(mclSortedColumnAttribute);
		}
		if(xmlAttributes.exists(mclAscendingSortAttribute))
		{
			config.sortAscending = xmlAttributes.getValueAsBool(mclAscendingSortAttribute);
			monitoredAttributes.append(" ").append(mclAscendingSortAttribute);
		}
 
		_setMultiColumnListAttributesMonitored(name, monitoredAttributes);
		m_multiColumnListConfigurations[name] = config;
	}
}
 
void DialogConfigurations::_setDialogAttributesMonitored(const CEGUI::String& dialog, const CEGUI::String& attributesMonitored)
{
	// Validate the attributes to be monitored
	std::vector<CEGUI::String> newAttributes;
	std::vector<CEGUI::String> listAttributesMonitored;
	Tokenize(attributesMonitored, listAttributesMonitored); // Convert attributesMonitored into a vector
	std::vector<CEGUI::String>::iterator itToken;
	for(itToken = listAttributesMonitored.begin(); itToken != listAttributesMonitored.end(); itToken++)
	{
		if(!(*itToken).compare(monitoredAttributeAll))
		{
			newAttributes.push_back(windowPosAttribute);
			newAttributes.push_back(windowVisibleAttribute);
			newAttributes.push_back(windowRolledupAttribute);
		}
		else if(!(*itToken).compare(monitoredAttributeNone))
		{
			newAttributes.clear();
		}
		else if(!(*itToken).compare(windowPosAttribute))
			newAttributes.push_back(windowPosAttribute);
		else if(!(*itToken).compare(windowVisibleAttribute))
			newAttributes.push_back(windowVisibleAttribute);
		else if(!(*itToken).compare(windowRolledupAttribute))
			newAttributes.push_back(windowRolledupAttribute);
		else
		{
			// Attribute is not supported
			assert(false && "Unsupported attribute specified for a dialog");
			CEGUI::Logger::getSingleton().logEvent("The attribute \""
													+ (*itToken)
													+ "\" is unsupported for dialogs.",
													CEGUI::Errors);
		}
	}
 
	// Store the attributes to be monitored
	m_attributesMonitoredDialog[dialog] = newAttributes;
}
 
void DialogConfigurations::_setMultiColumnListAttributesMonitored(const CEGUI::String& multiColumnList, const CEGUI::String& attributesMonitored)
{
	// Validate the attributes to be monitored
	std::vector<CEGUI::String> newAttributes;
	std::vector<CEGUI::String> listAttributesMonitored;
	Tokenize(attributesMonitored, listAttributesMonitored); // Convert attributesMonitored into a vector
	std::vector<CEGUI::String>::iterator itToken;
	for(itToken = listAttributesMonitored.begin(); itToken != listAttributesMonitored.end(); itToken++)
	{
		if(!(*itToken).compare(monitoredAttributeAll))
		{
			newAttributes.push_back(mclColumnSequenceAttribute);
			newAttributes.push_back(mclSortedColumnAttribute);
			newAttributes.push_back(mclAscendingSortAttribute);
			newAttributes.push_back(mclColumnWidthAttribute);
		}
		else if(!(*itToken).compare(monitoredAttributeNone))
		{
			newAttributes.clear();
		}
		else if(!(*itToken).compare(mclColumnSequenceAttribute))
			newAttributes.push_back(mclColumnSequenceAttribute);
		else if(!(*itToken).compare(mclSortedColumnAttribute))
			newAttributes.push_back(mclSortedColumnAttribute);
		else if(!(*itToken).compare(mclAscendingSortAttribute))
			newAttributes.push_back(mclAscendingSortAttribute);
		else if(!(*itToken).compare(mclColumnWidthAttribute))
			newAttributes.push_back(mclColumnWidthAttribute);
		else
		{
			// Attribute is not supported
			assert(false && "Unsupported attribute specified for a MultiColumnList");
			CEGUI::Logger::getSingleton().logEvent("The attribute \""
													+ (*itToken)
													+ "\" is unsupported for MultiColumnLists.",
													CEGUI::Errors);
		}
	}
 
	// Store the attributes to be monitored
	m_attributesMonitoredMultiColumnList[multiColumnList] = newAttributes;
}

DialogConfigurationsDemo.h

#ifndef _DialogConfigurationsDemo_h_
#define _DialogConfigurationsDemo_h_
 
#include "CEGuiSample.h"
#include "CEGUI.h"
#include "DialogConfigurations.h"
 
class DemoSample : public CEGuiSample
{
public:
    bool initialiseSample()
	{
		using namespace CEGUI;
		try
		{
			// Retrieve the window manager
			WindowManager& winMgr = WindowManager::getSingleton();
 
			// Load the TaharezLook scheme and set up the default mouse cursor and font
			SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
			System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
			if(!FontManager::getSingleton().isFontPresent("Commonwealth-10"))
				FontManager::getSingleton().createFont("Commonwealth-10.font");
 
			// Set the GUI Sheet
			Window* sheet = winMgr.createWindow("DefaultWindow", "root_wnd");
			System::getSingleton().setGUISheet(sheet);
 
			// Load a layout
			Window* guiLayout = winMgr.loadWindowLayout("DialogConfigurations.layout");
			sheet->addChildWindow(guiLayout);
 
			// Configure the toolbar
			winMgr.getWindow("DialogConfigurations/Toolbar/ShowA")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoSample::showA, this));
			winMgr.getWindow("DialogConfigurations/Toolbar/ShowC")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoSample::showC, this));
			winMgr.getWindow("DialogConfigurations/Toolbar/ShowD")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoSample::showD, this));
 
			// Activate the close buttons
			winMgr.getWindow("DialogConfigurations/Window_A")->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&DemoSample::closeA, this));
			winMgr.getWindow("DialogConfigurations/Window_B")->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&DemoSample::closeB, this));
			winMgr.getWindow("DialogConfigurations/Window_C")->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&DemoSample::closeC, this));
			winMgr.getWindow("DialogConfigurations/Window_D")->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&DemoSample::closeD, this));
 
			// Add columns to the MultiColumnList
			MultiColumnList* multiColumnList = static_cast<MultiColumnList*>(winMgr.getWindow("DialogConfigurations/Window_D/MultiColumnList"));
			multiColumnList->addColumn("Col A", 0, UDim(0.32f, 0));
			multiColumnList->addColumn("Col B", 1, UDim(0.32f, 0));
			multiColumnList->addColumn("Col C", 2, UDim(0.32f, 0));
 
			// Add rows
			multiColumnList->addRow();
			multiColumnList->setItem(new ListboxTextItem("1", 101), 0, 0); // ColumnID, RowID
			multiColumnList->setItem(new ListboxTextItem("4", 102), 1, 0);
			multiColumnList->setItem(new ListboxTextItem("7", 103), 2, 0);
			multiColumnList->addRow();
			multiColumnList->setItem(new ListboxTextItem("4", 201), 0, 1);
			multiColumnList->setItem(new ListboxTextItem("7", 202), 1, 1);
			multiColumnList->setItem(new ListboxTextItem("1", 203), 2, 1);
			multiColumnList->addRow();
			multiColumnList->setItem(new ListboxTextItem("7", 301), 0, 2);
			multiColumnList->setItem(new ListboxTextItem("1", 302), 1, 2);
			multiColumnList->setItem(new ListboxTextItem("4", 303), 2, 2);
 
 
			// Activate dialog configurations
			m_DialogConfigurations.loadConfigurations("DialogConfigurations.xml");
			m_DialogConfigurations.addDialog("DialogConfigurations/Window_A", "Position Visible");
			m_DialogConfigurations.addDialog("DialogConfigurations/Window_B", "Position RolledUp");
			m_DialogConfigurations.addDialog("DialogConfigurations/Window_C", "Visible RolledUp");
			m_DialogConfigurations.addDialog("DialogConfigurations/Window_D"); // Saves every attribute: Position, Visible, and RolledUp
			m_DialogConfigurations.addMultiColumnList("DialogConfigurations/Window_D/MultiColumnList"); // Saves every attribute: ColumnSequence, ColumnWidths, SortedColumn, and AscendingSort
		}
		catch(Exception &e)
		{
			#if defined( __WIN32__ ) || defined( _WIN32 )
				MessageBox(NULL, e.getMessage().c_str(), "Error initializing the demo", MB_OK | MB_ICONERROR | MB_TASKMODAL);
			#else
				std::cerr << "Error initializing the demo:" << e.getMessage().c_str() << "\n";
			#endif
		}
 
		return true;
	}
 
	void cleanupSample(void)
	{
		m_DialogConfigurations.saveConfigurations();
	}
 
	bool showA(const CEGUI::EventArgs& e)
	{
		CEGUI::WindowManager::getSingleton().getWindow("DialogConfigurations/Window_A")->setVisible(true);
		return true;
	}
 
	bool showC(const CEGUI::EventArgs& e)
	{
		CEGUI::WindowManager::getSingleton().getWindow("DialogConfigurations/Window_C")->setVisible(true);
		return true;
	}
 
	bool showD(const CEGUI::EventArgs& e)
	{
		CEGUI::WindowManager::getSingleton().getWindow("DialogConfigurations/Window_D")->setVisible(true);
		return true;
	}
 
	bool closeA(const CEGUI::EventArgs& e)
	{
		CEGUI::WindowManager::getSingleton().getWindow("DialogConfigurations/Window_A")->setVisible(false);
		return true;
	}
 
	bool closeB(const CEGUI::EventArgs& e)
	{
		CEGUI::WindowManager::getSingleton().getWindow("DialogConfigurations/Window_B")->setVisible(false);
		return true;
	}
 
	bool closeC(const CEGUI::EventArgs& e)
	{
		CEGUI::WindowManager::getSingleton().getWindow("DialogConfigurations/Window_C")->setVisible(false);
		return true;
	}
 
	bool closeD(const CEGUI::EventArgs& e)
	{
		CEGUI::WindowManager::getSingleton().getWindow("DialogConfigurations/Window_D")->setVisible(false);
		return true;
	}
private:
	DialogConfigurations m_DialogConfigurations;
};
 
#endif // _DialogConfigurationsDemo_h_

main.cpp

#if defined( __WIN32__ ) || defined( _WIN32 )
	#define WIN32_LEAN_AND_MEAN
	#define NOMINMAX
	#include "windows.h"
#endif
 
#include "DialogConfigurationsDemo.h"
 
#if defined( __WIN32__ ) || defined( _WIN32 )
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)
#else
int main(int argc, char *argv[])
#endif
{
    DemoSample app;
    return app.run();
}


DialogConfigurations.layout

<?xml version="1.0" encoding="UTF-8"?>
 
<GUILayout >
    <Window Type="DefaultWindow" Name="DialogConfigurations" >
        <Property Name="InheritsAlpha" Value="False" />
        <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
        <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
        <Window Type="TaharezLook/StaticText" Name="DialogConfigurations/Toolbar" >
            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
            <Property Name="UnifiedAreaRect" Value="{{0.1875,0},{0.00833335,0},{0.8025,0},{0.111667,0}}" />
            <Window Type="TaharezLook/Button" Name="DialogConfigurations/Toolbar/ShowA" >
                <Property Name="Text" Value="Show A" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedAreaRect" Value="{{0.0581303,0},{0.156452,0},{0.30813,0},{0.858064,0}}" />
            </Window>
            <Window Type="TaharezLook/Button" Name="DialogConfigurations/Toolbar/ShowC" >
                <Property Name="Font" Value="Commonwealth-10" />
                <Property Name="Text" Value="Show C" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedAreaRect" Value="{{0.388618,0},{0.156452,0},{0.638618,0},{0.858064,0}}" />
            </Window>
            <Window Type="TaharezLook/Button" Name="DialogConfigurations/Toolbar/ShowD" >
                <Property Name="Font" Value="Commonwealth-10" />
                <Property Name="Text" Value="Show D" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedAreaRect" Value="{{0.704878,0},{0.156452,0},{0.954878,0},{0.858064,0}}" />
            </Window>
        </Window>
        <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_A" >
            <Property Name="Text" Value="A - RolledUp not saved" />
            <Property Name="TitlebarFont" Value="Commonwealth-10" />
            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
            <Property Name="TitlebarEnabled" Value="True" />
            <Property Name="UnifiedAreaRect" Value="{{0.035,0},{0.123333,0},{0.325,0},{0.47,0}}" />
        </Window>
        <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_B" >
            <Property Name="Text" Value="B - Visible not saved" />
            <Property Name="TitlebarFont" Value="Commonwealth-10" />
            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
            <Property Name="TitlebarEnabled" Value="True" />
            <Property Name="UnifiedAreaRect" Value="{{0.35125,0},{0.123333,0},{0.64125,0},{0.47,0}}" />
        </Window>
        <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_C" >
            <Property Name="Text" Value="C - Position &amp; Size not saved" />
            <Property Name="TitlebarFont" Value="Commonwealth-10" />
            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
            <Property Name="TitlebarEnabled" Value="True" />
            <Property Name="UnifiedAreaRect" Value="{{0.6675,0},{0.123333,0},{0.957501,0},{0.47,0}}" />
        </Window>
        <Window Type="TaharezLook/FrameWindow" Name="DialogConfigurations/Window_D" >
            <Property Name="Text" Value="D Saves MultiColumnList column width, sequence, and sort" />
            <Property Name="TitlebarFont" Value="Commonwealth-10" />
            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
            <Property Name="TitlebarEnabled" Value="True" />
            <Property Name="UnifiedAreaRect" Value="{{0.10625,0},{0.53375,0},{0.86625,0},{0.962083,0}}" />
            <Window Type="TaharezLook/MultiColumnList" Name="DialogConfigurations/Window_D/MultiColumnList" >
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedAreaRect" Value="{{0.031235,0},{0.140467,0},{0.968886,0},{0.950778,0}}" />
            </Window>
        </Window>
    </Window>
</GUILayout>