Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgpropertyfield_checkbox.h

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library 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 GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2008-02-01 12:19:52 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/include/pgpropertyfield_checkbox.h,v $
00025     CVS/RCS Revision: $Revision: 1.3 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 
00030 #ifndef PG_PROPERTYFIELD_CHECKBOX_H
00031 #define PG_PROPERTYFIELD_CHECKBOX_H
00032 
00033 #include "pgpropertyeditor.h"
00034 #include "pgcheckbutton.h"
00035 
00042 template<typename B>
00043 class PG_PropertyField_Checkbox : public PG_PropertyEditor::PG_PropertyEditorField, public SigC::Object  {
00044         B* myProperty;
00045         PG_CheckButton* checkbox;
00046         bool switchInverted;
00047 
00048         bool click( bool b) {
00049                 sigValueChanged(this,b);
00050                 return true;
00051         }
00052 
00053 public:
00054         typedef PG_Signal2<PG_PropertyField_Checkbox*, B> CheckboxPropertySignal;
00055         CheckboxPropertySignal sigValueChanged;
00056         CheckboxPropertySignal sigValueApplied;
00057 
00064         PG_PropertyField_Checkbox( PG_PropertyEditor* propertyEditor, const std::string& name, B* b, bool inverted = false ) : myProperty( b ), switchInverted( inverted ) {
00065                 PG_Rect r = propertyEditor->RegisterProperty( name, this );
00066                 checkbox = new PG_CheckButton( propertyEditor, r, PG_NULLSTR, -1, propertyEditor->GetStyleName("BoolProperty") );
00067                 checkbox->sigClick.connect( SigC::slot(*this, &PG_PropertyField_Checkbox::click));
00068                 Reload();
00069         };
00070 
00077         PG_PropertyField_Checkbox( PG_PropertyEditor* propertyEditor, const std::string& name, const B& b, bool inverted = false ) : myProperty( NULL ), switchInverted( inverted ) {
00078                 PG_Rect r = propertyEditor->RegisterProperty( name, this );
00079                 checkbox = new PG_CheckButton( propertyEditor, r, PG_NULLSTR, -1, propertyEditor->GetStyleName("BoolProperty") );
00080                 checkbox->sigClick.connect( SigC::slot(*this, &PG_PropertyField_Checkbox::click));
00081 
00082                 if ( bool(b) ^ switchInverted )
00083                         checkbox->SetPressed();
00084                 else
00085                         checkbox->SetUnpressed();
00086         };
00087 
00088         bool Valid() {
00089                 return true;
00090         };
00091         bool Apply() {
00092                 if ( myProperty )
00093                         *myProperty = checkbox->GetPressed() ^ switchInverted;
00094 
00095                 sigValueApplied( this, checkbox->GetPressed() ^ switchInverted );
00096                 return true;
00097         };
00098         void Reload() {
00099                 if ( myProperty ) {
00100                         if ( bool(*myProperty) ^ switchInverted )
00101                                 checkbox->SetPressed();
00102                         else
00103                                 checkbox->SetUnpressed();
00104       }
00105         };
00106 };
00107 
00108 #endif

Generated on Tue Jun 24 01:27:48 2008 for Advanced Strategic Command by  doxygen 1.4.2