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

pgpropertyfield_dropdown.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_dropdown.h,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #ifndef PG_PROPERTYFIELD_DROPDOWN_H
00030 #define PG_PROPERTYFIELD_DROPDOWN_H
00031 
00032 #include "pgpropertyeditor_linefield.h"
00033 #include "pgdropdown.h"
00034 
00043 template<typename StringType, typename iterator = char*>
00044 class PG_PropertyField_DropDown: public PG_PropertyEditor::PG_PropertyEditorField, public SigC::Object  {
00045 private:
00046         StringType* myProperty;
00047         PG_DropDown* dropdown;
00048 
00049         bool click() {
00050                 StringType value = dropdown->GetText();
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_DropDown::click));
00060         }
00061 
00062 public:
00063         typedef PG_Signal2<PG_PropertyField_DropDown*, StringType> DropDownPropertySignal;
00064         DropDownPropertySignal sigValueChanged;
00065         DropDownPropertySignal sigValueApplied;
00066 
00073         PG_PropertyField_DropDown( PG_PropertyEditor* propertyEditor, const std::string& name, StringType* 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          if ( *var == names[i] )
00080                       dropdown->SelectItem( i );
00081 
00082                         ++i;
00083                 }
00084         };
00085 
00093         PG_PropertyField_DropDown( PG_PropertyEditor* propertyEditor, const std::string& name, StringType* var, iterator begin, iterator end ) : myProperty( var ) {
00094                 init( propertyEditor, name );
00095 
00096       int i = 0;
00097                 while ( begin != end ) {
00098                         dropdown->AddItem( *begin );
00099          if ( *var == *begin )
00100                       dropdown->SelectItem( i );
00101 
00102                         ++begin;
00103          ++i;
00104                 }
00105         };
00106 
00113         PG_PropertyField_DropDown( PG_PropertyEditor* propertyEditor, const std::string& name, const StringType& var, const char** names ) : myProperty( NULL ) {
00114                 init( propertyEditor, name );
00115 
00116                 int i = 0;
00117                 while ( names[i] ) {
00118                         dropdown->AddItem( names[i] );
00119          if ( var == names[i] )
00120                       dropdown->SelectItem( i );
00121 
00122                         ++i;
00123                 }
00124         };
00125 
00133         PG_PropertyField_DropDown( PG_PropertyEditor* propertyEditor, const std::string& name, const StringType& var, iterator begin, iterator end ) : myProperty( NULL ) {
00134                 init( propertyEditor, name );
00135 
00136       int i = 0;
00137                 while ( begin != end ) {
00138                         dropdown->AddItem( *begin );
00139          if ( *var == *begin )
00140                       dropdown->SelectItem( i );
00141                         ++begin;
00142          ++i;
00143                 }
00144         };
00145 
00146 
00147         bool Valid() {
00148                 return true;
00149         };
00150 
00151         bool Apply() {
00152                 if ( myProperty )
00153                         *myProperty = dropdown->GetText();
00154 
00155                 sigValueApplied( this, dropdown->GetText() );
00156 
00157                 return true;
00158         };
00159 
00160         void Reload() {
00161       
00162                 if ( myProperty )
00163                         dropdown->SetText( *myProperty );
00164          
00165         };
00166 };
00167 
00168 
00169 #endif

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