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_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