summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2009-12-28 22:26:48 +0000
committerMatthias Melcher <fltk@matthiasm.com>2009-12-28 22:26:48 +0000
commitae9b3365aa310d90d769576967263bf66bf41b19 (patch)
treecb6259035b84a6479d382527d7e90fa9b75fbf35 /src
parent9048b4b8950c95df9255e53c101b863037e56ecf (diff)
Added an ID type to preferences which can be retrieved to then re-use the same dataset. IDs can be used in callbacks as user_data(). No need to keep an Fl_Preference around that would later require deleting.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6984 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Preferences.cxx39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx
index 866c90cae..41dd90c00 100644
--- a/src/Fl_Preferences.cxx
+++ b/src/Fl_Preferences.cxx
@@ -102,6 +102,7 @@ const char *Fl_Preferences::newUUID()
b[10] = (unsigned char)(a>>16);
b[11] = (unsigned char)(a>>24);
char name[80]; // last four bytes
+ // BOOL GetComputerName(LPTSTR lpBuffer, LPDWORD nSize);
gethostname(name, 79);
memcpy(b+12, name, 4);
sprintf(uuidBuffer, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
@@ -160,8 +161,9 @@ const char *Fl_Preferences::newUUID()
*/
Fl_Preferences::Fl_Preferences( Root root, const char *vendor, const char *application )
{
- node = new Node( "." );
rootNode = new RootNode( this, root, vendor, application );
+ node = new Node( "." );
+ node->setRoot(rootNode);
}
@@ -179,8 +181,9 @@ Fl_Preferences::Fl_Preferences( Root root, const char *vendor, const char *appli
*/
Fl_Preferences::Fl_Preferences( const char *path, const char *vendor, const char *application )
{
- node = new Node( "." );
rootNode = new RootNode( this, path, vendor, application );
+ node = new Node( "." );
+ node->setRoot(rootNode);
}
@@ -247,6 +250,24 @@ Fl_Preferences::Fl_Preferences( Fl_Preferences *parent, int groupIndex )
/**
+ Create a new dataset access point using a dataset ID.
+
+ ID's are a great way to remember shortcuts to database entries that are deeply
+ nested in a preferences database, as long as the databse root is not deleted.
+ An ID can be retrieved from any Fl_Preferences dataset, and can then be used
+ to create multiple new references to the same dataset.
+
+ ID's can be put very helpful when put into the <tt>user_data()</tt> field of
+ widget callbacks.
+ */
+Fl_Preferences::Fl_Preferences( Fl_Preferences::ID id )
+{
+ node = (Node*)id;
+ rootNode = node->findRoot();
+}
+
+
+/**
The destructor removes allocated resources. When used on the
\em base preferences group, the destructor flushes all
changes to the preferences file and deletes all internal
@@ -1166,6 +1187,7 @@ Fl_Preferences::Node::Node( const char *path )
entry = 0;
nEntry = NEntry = 0;
dirty_ = 0;
+ top_ = 0;
}
// delete this and all depending nodes
@@ -1260,6 +1282,19 @@ void Fl_Preferences::Node::setParent( Node *pn )
path_ = strdup( nameBuffer );
}
+// find the corresponding root node
+Fl_Preferences::RootNode *Fl_Preferences::Node::findRoot()
+{
+ Node *n = this;
+ do {
+ if (n->top_)
+ return n->root_;
+ n = n->parent_;
+
+ } while (n);
+ return 0L;
+}
+
// add a child to this node and set its path (try to find it first...)
Fl_Preferences::Node *Fl_Preferences::Node::addChild( const char *path )
{