Planeshift

pawsconfigwindow.h

Go to the documentation of this file.
00001 /*
00002  * pawsconfigwindow.h - Author: Ondrej Hurt
00003  *
00004  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef PAWS_CONFIG_WINDOW_HEADER
00021 #define PAWS_CONFIG_WINDOW_HEADER
00022 
00023 #include <csutil/parray.h>
00024 
00025 #include "paws/pawswidget.h"
00026 #include "paws/pawstree.h"
00027 #include "gui/pawscontrolwindow.h"
00028 
00029 
00030 
00031 /* Configuration is divided into sections. Sections are identified by names.
00032  * The main configuration window consist of a tree of sections on the left and
00033  * one section window on the right. Each node of the tree represents one section.
00034  * When a node is selected, a section window is shown on the right. (e.g. keyboard configuration)
00035  * All section windows are widgets derived from the pawsConfigSectionWindow class.
00036  *
00037  * The tree on the left is described in /data/configtree.xml file.
00038  * Each tree node that is meant to invoke configuration section (pawsConfigSectionWindow subclass)
00039  * must have two attributes defined:
00040  *            - SectionName: string that identifies section
00041  *            - factory: name of pawsConfigSectionWindow subclass that takes care of GUI of this section
00042  *
00043  * pawsConfigSectionWindow is the superclass of section windows.
00044  */
00045 class pawsConfigSectionWindow : public pawsWidget
00046 {
00047 public:
00048     pawsConfigSectionWindow()
00049     {
00050         dirty = false;
00051     }
00052     void SetSectionName(const csString &_sectionName)
00053     {
00054         sectionName = _sectionName;
00055     }
00056     virtual bool Initialize() = 0;
00058     virtual bool LoadConfig() = 0;
00060     virtual bool IsDirty()
00061     {
00062         return dirty;
00063     }
00065     virtual bool SaveConfig() = 0;
00066 
00068     virtual void SetDefault() = 0;
00069 
00070 protected:
00071     /* Says what section of configuration is being configured by this window.
00072      * A pawsConfigSectionWindow could be used by more than one section
00073      * and 'sectionName' tells which section it is.
00074      */
00075     csString sectionName;
00076 
00077     /* Is data in configuration window different from data in configuration file
00078      * i.e. do we need to save it ?
00079      * Should be set to true when user changes something, and to false when the data is loaded/saved.
00080      */
00081     bool dirty;
00082 
00083 };
00084 
00085 
00086 
00087 // The sectWnd_t structure holds a pair [ section name , section window ]
00088 struct sectWnd_t
00089 {
00090     sectWnd_t(const csString &_sectName, pawsConfigSectionWindow* _sectWnd)
00091     {
00092         sectName = _sectName;
00093         sectWnd = _sectWnd;
00094     }
00095     csString sectName;
00096     pawsConfigSectionWindow* sectWnd;
00097 };
00098 
00099 
00100 
00101 // Class pawsConfigWindow implements the main configuration window that is invoked
00102 // in-game by clicking on the "Options" button.
00103 
00104 class pawsConfigWindow : public pawsControlledWindow
00105 {
00106 public:
00107 
00108     pawsConfigWindow();
00109 
00110     // from pawsWidget:
00111     virtual bool OnButtonReleased(int mouseButton, int keyModifier, pawsWidget* widget);
00112     virtual bool OnSelected(pawsWidget* widget);
00113     virtual bool PostSetup();
00114 
00117     void SetNotify(pawsWidget* notify);
00118 
00119 
00120 private:
00122     pawsConfigSectionWindow* FindSectionWindow(const csString &sectName);
00123 
00124     iObjectRegistry* object_reg;
00125     csArray<sectWnd_t> sectWnds;
00126 
00127     pawsSimpleTree* sectionTree;
00128     pawsWidget* sectionParent;
00129     pawsConfigSectionWindow* currSectWnd;
00130     pawsWidget* okButton, * resetButton;
00131     pawsWidget* notify;
00132 };
00133 
00134 
00135 CREATE_PAWS_FACTORY(pawsConfigWindow);
00136 
00137 
00138 #endif
00139