2002-04-30 00:57:31 +04:00
|
|
|
//
|
2003-01-21 17:51:54 +03:00
|
|
|
// "$Id: Fl_Preferences.H,v 1.1.2.12 2003/01/21 14:51:54 easysw Exp $"
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|
|
|
|
// Preferences definitions for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
|
|
|
// Copyright 2002 by Matthias Melcher.
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Fl_Preferences_H
|
|
|
|
# define Fl_Preferences_H
|
|
|
|
|
|
|
|
# ifdef WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
# endif // WIN32
|
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
# include <stdio.h>
|
|
|
|
# include "Fl_Export.H"
|
2002-04-30 00:57:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preferences are a data tree containing a root, branches and leafs
|
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
class FL_EXPORT Fl_Preferences
|
2002-04-30 00:57:31 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-05-07 04:43:20 +04:00
|
|
|
enum Root { SYSTEM=0, USER };
|
|
|
|
// enum Type { win32, macos, fltk };
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
Fl_Preferences( Root root, const char *vendor, const char *application );
|
2002-08-27 07:03:37 +04:00
|
|
|
Fl_Preferences( const char *path, const char *vendor, const char *application );
|
2002-08-14 20:19:48 +04:00
|
|
|
Fl_Preferences( Fl_Preferences&, const char *group );
|
|
|
|
Fl_Preferences( Fl_Preferences*, const char *group );
|
|
|
|
~Fl_Preferences();
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
int groups();
|
|
|
|
const char *group( int );
|
|
|
|
char groupExists( const char *group );
|
|
|
|
char deleteGroup( const char *group );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
int entries();
|
|
|
|
const char *entry( int );
|
|
|
|
char entryExists( const char *entry );
|
|
|
|
char deleteEntry( const char *entry );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
char set( const char *entry, int value );
|
|
|
|
char set( const char *entry, float value );
|
|
|
|
char set( const char *entry, double value );
|
|
|
|
char set( const char *entry, const char *value );
|
|
|
|
char set( const char *entry, const void *value, int size );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
char get( const char *entry, int &value, int defaultValue );
|
|
|
|
char get( const char *entry, float &value, float defaultValue );
|
|
|
|
char get( const char *entry, double &value, double defaultValue );
|
|
|
|
char get( const char *entry, char *&value, const char *defaultValue );
|
|
|
|
char get( const char *entry, char *value, const char *defaultValue, int maxSize );
|
|
|
|
char get( const char *entry, void *&value, const void *defaultValue, int defaultSize );
|
|
|
|
char get( const char *entry, void *value, const void *defaultValue, int defaultSize, int maxSize );
|
|
|
|
int size( const char *entry );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
char getUserdataPath( char *path, int pathlen );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
void flush();
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
// char export( const char *filename, Type fileFormat );
|
|
|
|
// char import( const char *filename );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2003-01-21 17:51:54 +03:00
|
|
|
class FL_EXPORT Name {
|
2002-05-01 02:25:18 +04:00
|
|
|
char *data_;
|
|
|
|
public:
|
2002-08-14 20:19:48 +04:00
|
|
|
Name( unsigned int n );
|
|
|
|
Name( const char *format, ... );
|
|
|
|
operator const char *() { return data_; }
|
|
|
|
~Name();
|
2002-05-01 02:25:18 +04:00
|
|
|
};
|
2002-04-30 00:57:31 +04:00
|
|
|
|
|
|
|
struct Entry
|
|
|
|
{
|
|
|
|
char *name, *value;
|
|
|
|
};
|
|
|
|
|
2002-05-04 00:30:19 +04:00
|
|
|
private:
|
|
|
|
|
|
|
|
static char nameBuffer[128];
|
|
|
|
|
2003-01-21 17:51:54 +03:00
|
|
|
class FL_EXPORT Node // a node contains a list to all its entries
|
2002-04-30 00:57:31 +04:00
|
|
|
{ // and all means to manage the tree structure
|
|
|
|
Node *child_, *next_, *parent_;
|
|
|
|
char *path_;
|
|
|
|
char dirty_;
|
|
|
|
public:
|
|
|
|
Node( const char *path );
|
|
|
|
~Node();
|
|
|
|
// node methods
|
|
|
|
int write( FILE *f );
|
|
|
|
Node *find( const char *path );
|
2002-09-06 00:44:36 +04:00
|
|
|
Node *search( const char *path, int offset=0 );
|
2002-04-30 00:57:31 +04:00
|
|
|
Node *addChild( const char *path );
|
|
|
|
void setParent( Node *parent );
|
|
|
|
char remove();
|
|
|
|
char dirty();
|
|
|
|
// entry methods
|
|
|
|
int nChildren();
|
|
|
|
const char *child( int ix );
|
|
|
|
void set( const char *name, const char *value );
|
|
|
|
void set( const char *line );
|
|
|
|
void add( const char *line );
|
|
|
|
const char *get( const char *name );
|
|
|
|
int getEntry( const char *name );
|
|
|
|
char deleteEntry( const char *name );
|
|
|
|
// public values
|
|
|
|
Entry *entry;
|
|
|
|
int nEntry, NEntry;
|
|
|
|
static int lastEntrySet;
|
|
|
|
};
|
|
|
|
friend class Node;
|
|
|
|
|
2003-01-21 17:51:54 +03:00
|
|
|
class FL_EXPORT RootNode // the root node manages file paths and basic reading and writing
|
2002-04-30 00:57:31 +04:00
|
|
|
{
|
|
|
|
Fl_Preferences *prefs_;
|
|
|
|
char *filename_;
|
|
|
|
char *vendor_, *application_;
|
|
|
|
public:
|
2002-05-04 00:30:19 +04:00
|
|
|
RootNode( Fl_Preferences *, Root root, const char *vendor, const char *application );
|
2002-08-27 07:03:37 +04:00
|
|
|
RootNode( Fl_Preferences *, const char *path, const char *vendor, const char *application );
|
2002-04-30 00:57:31 +04:00
|
|
|
~RootNode();
|
|
|
|
int read();
|
|
|
|
int write();
|
2002-04-30 22:11:49 +04:00
|
|
|
char getPath( char *path, int pathlen );
|
2002-04-30 00:57:31 +04:00
|
|
|
};
|
|
|
|
friend class RootNode;
|
|
|
|
|
|
|
|
Node *node;
|
|
|
|
RootNode *rootNode;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // !Fl_Preferences_H
|
|
|
|
|
|
|
|
//
|
2003-01-21 17:51:54 +03:00
|
|
|
// End of "$Id: Fl_Preferences.H,v 1.1.2.12 2003/01/21 14:51:54 easysw Exp $".
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|