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

pgpropertyfield_intdropdown.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: 2007-04-13 16:15:57 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/include/pgpropertyfield_intdropdown.h,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #ifndef PG_PROPERTYFIELD_INTDROPDOWN_H
00030 #define PG_PROPERTYFIELD_INTDROPDOWN_H
00031 
00032 #include "pgpropertyeditor_linefield.h"
00033 #include "pgdropdown.h"
00034 
00043 template<typename IntType, typename iterator = char*>
00044 class PG_PropertyField_IntDropDown: public PG_PropertyEditor::PG_PropertyEditorField, public SigC::Object  {
00045 private:
00046         IntType* myProperty;
00047         PG_DropDown* dropdown;
00048 
00049         bool click() {
00050                 int value = dropdown->GetSelectedItemIndex();
00051                 sigValueChanged(this,value);
00052                 return true;
00053         }
00054 
00055         void init( PG_PropertyEditor* propertyEditor, const std::string& name ) {
00056                 PG_Rect r = propertyEditor->RegisterProperty( name, this );
00057                 dropdown = new PG_DropDown( propertyEditor, r, -1, propertyEditor->GetStyleName("DropDownSelectorProperty") );
00058                 dropdown->SetEditable( false );
00059                 dropdown->sigSelectItem.connect( SigC::slot(*this, &PG_PropertyField_IntDropDown::click));
00060         }
00061 
00062 public:
00063         typedef PG_Signal2<PG_PropertyField_IntDropDown*, IntType> DropDownPropertySignal;
00064         DropDownPropertySignal sigValueChanged;
00065         DropDownPropertySignal sigValueApplied;
00066 
00073         PG_PropertyField_IntDropDown( PG_PropertyEditor* propertyEditor, const std::string& name, IntType* var, const char** names ) : myProperty( var ) {
00074                 init( propertyEditor, name );
00075 
00076                 int i = 0;
00077                 while ( names[i] ) {
00078                         dropdown->AddItem( names[i] );
00079                         ++i;
00080                 }
00081                 dropdown->SelectItem( *var );
00082         };
00083 
00091         PG_PropertyField_IntDropDown( PG_PropertyEditor* propertyEditor, const std::string& name, IntType* var, iterator begin, iterator end ) : myProperty( var ) {
00092                 init( propertyEditor, name );
00093 
00094                 while ( begin != end ) {
00095                         dropdown->AddItem( *begin );
00096                         ++begin;
00097                 }
00098                 dropdown->SelectItem( *var );
00099         };
00100 
00107         PG_PropertyField_IntDropDown( PG_PropertyEditor* propertyEditor, const std::string& name, const IntType& var, const char** names ) : myProperty( NULL ) {
00108                 init( propertyEditor, name );
00109 
00110                 int i = 0;
00111                 while ( names[i] ) {
00112                         dropdown->AddItem( names[i] );
00113                         ++i;
00114                 }
00115                 dropdown->SelectItem( var );
00116         };
00117 
00125         PG_PropertyField_IntDropDown( PG_PropertyEditor* propertyEditor, const std::string& name, const IntType& var, iterator begin, iterator end ) : myProperty( NULL ) {
00126                 init( propertyEditor, name );
00127 
00128                 while ( begin != end ) {
00129                         dropdown->AddItem( *begin );
00130                         ++begin;
00131                 }
00132                 dropdown->SelectItem( var );
00133         };
00134 
00135 
00136         bool Valid() {
00137                 return true;
00138         };
00139 
00140         bool Apply() {
00141                 if ( myProperty )
00142                         *myProperty = dropdown->GetSelectedItemIndex();
00143 
00144                 sigValueApplied( this, dropdown->GetSelectedItemIndex() );
00145 
00146                 return true;
00147         };
00148 
00149         void Reload() {
00150                 if ( myProperty )
00151                         dropdown->SelectItem( *myProperty );
00152         };
00153 };
00154 
00155 
00156 #endif

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