00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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