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 #include <algorithm>
00030
00031 #include "pgpropertyeditor.h"
00032 #include "pglabel.h"
00033
00034
00035 PG_PropertyEditor :: PG_PropertyEditor ( PG_Widget *parent, const PG_Rect &rect, const std::string &style, int labelWidthPercentage )
00036 : PG_ScrollWidget( parent, rect, style ), styleName( style ), ypos ( 0 ), lineHeight(25), lineSpacing(2), labelWidth(labelWidthPercentage) {}
00037 ;
00038
00039 std::string PG_PropertyEditor :: GetStyleName( const std::string& widgetName ) {
00040 return styleName;
00041 };
00042
00043 void PG_PropertyEditor :: Reload() {
00044 for ( PropertyFieldsType::iterator i = propertyFields.begin(); i != propertyFields.end(); ++i )
00045 (*i)->Reload();
00046 };
00047
00048
00049 bool PG_PropertyEditor :: Valid( bool focus ) {
00050 for ( PropertyFieldsType::iterator i = propertyFields.begin(); i != propertyFields.end(); ++i )
00051 if ( ! (*i)->Valid() ) {
00052 if ( focus )
00053 (*i)->Focus();
00054 return false;
00055 }
00056 return true;
00057 };
00058
00059 bool PG_PropertyEditor :: Apply() {
00060 for ( PropertyFieldsType::iterator i = propertyFields.begin(); i != propertyFields.end(); ++i ) {
00061 if ( ! (*i)->Valid() ) {
00062 (*i)->Focus();
00063 return false;
00064 }
00065 }
00066
00067 for ( PropertyFieldsType::iterator i = propertyFields.begin(); i != propertyFields.end(); ++i )
00068 (*i)->Apply();
00069
00070 return true;
00071 };
00072
00073 PG_Rect PG_PropertyEditor :: RegisterProperty( const std::string& name, PG_PropertyEditorField* propertyEditorField, int height ) {
00074 propertyFields.push_back( propertyEditorField );
00075
00076 if ( height <= 0 )
00077 height = lineHeight;
00078
00079 int w = Width() - my_widthScrollbar - 2 * lineSpacing;
00080
00081 PG_Label* label = new PG_Label( this, PG_Rect( 0, ypos, w * labelWidth / 100 - 1, height), name );
00082 label->LoadThemeStyle( styleName, "Label" );
00083 PG_Rect r ( w * labelWidth / 100 , ypos, w * ( 100 - labelWidth ) / 100 - 1, height );
00084 ypos += height + lineSpacing;
00085 return r;
00086 };
00087
00088 PG_PropertyEditor :: ~PG_PropertyEditor() {
00089 for ( PropertyFieldsType::iterator i = propertyFields.begin(); i != propertyFields.end(); ++i )
00090 delete *i;
00091 };
00092