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

pgpropertyeditor.cpp

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:16:04 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pgpropertyeditor.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
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 

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