libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YLabel.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YLabel.h
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef YLabel_h
00026 #define YLabel_h
00027 
00028 #include "YWidget.h"
00029 #include <string>
00030 #include "ImplPtr.h"
00031 
00032 
00033 class YLabelPrivate;
00034 
00035 /**
00036  * Implementation of the Label, Heading and OutputField widgets
00037  **/
00038 class YLabel : public YWidget
00039 {
00040 public:
00041 
00042     /**
00043      * Constructor.
00044      *
00045      * 'isHeading' indicates if this should be displayed as a Heading widget,
00046      * i.e. with a bold and/or larger font.
00047      * This cannot be changed after creating the widget.
00048      *
00049      * 'isOutputField' indicates if this should be displayed as an OutputField
00050      * widget, i.e. similar to an InputField the user can't change.
00051      * This cannot be changed after creating the widget.
00052      **/
00053     YLabel( YWidget *           parent,
00054             const std::string & text,
00055             bool                isHeading       = false,
00056             bool                isOutputField   = false );
00057 
00058     /**
00059      * Destructor.
00060      **/
00061     virtual ~YLabel();
00062 
00063     /**
00064      * Returns a descriptive name of this widget class for logging,
00065      * debugging etc.
00066      *
00067      * Reimplemented from YWidget.
00068      **/
00069     virtual const char * widgetClass() const;
00070 
00071     /**
00072      * Return the text the widget displays.
00073      **/
00074     std::string text() const;
00075 
00076     /**
00077      * Aliases for text().
00078      **/
00079     std::string value() const { return text(); }
00080     std::string label() const { return text(); }
00081 
00082     /**
00083      * Set the text the widget displays.
00084      *
00085      * Derived classes should overwrite this, but call this base class function
00086      * in the overwritten function.
00087      **/
00088     virtual void setText( const std::string & newText );
00089 
00090     /**
00091      * Aliases for setText().
00092      **/
00093     void setValue( const std::string & newValue ) { setText( newValue ); }
00094     void setLabel( const std::string & newLabel ) { setText( newLabel ); }
00095 
00096     /**
00097      * Return 'true' if this is a Heading widget, i.e., it should display its
00098      * text in a bold and/or larger font.
00099      *
00100      * This cannot be changed after creating the widget.
00101      **/
00102     bool isHeading() const;
00103 
00104     /**
00105      * Return 'true' if this is an OutputField widget, i.e., it should display
00106      * its text similar to an InputField the user can't change.
00107      *
00108      * This cannot be changed after creating the widget.
00109      **/
00110     bool isOutputField() const;
00111 
00112     /**
00113      * Return 'true' if a bold font should be used.
00114      **/
00115     bool useBoldFont() const;
00116 
00117     /**
00118      * Switch bold font on or off.
00119      *
00120      * Derived classes should overwrite this, but call this base class function
00121      * in the overwritten function.
00122      **/
00123     virtual void setUseBoldFont( bool bold = true );
00124 
00125     /**
00126      * Set a property.
00127      * Reimplemented from YWidget.
00128      *
00129      * This method may throw exceptions, for example
00130      *   - if there is no property with that name
00131      *   - if the expected type and the type mismatch
00132      *   - if the value is out of range
00133      *
00134      * This function returns 'true' if the value was successfully set and
00135      * 'false' if that value requires special handling (not in error cases:
00136      * those are covered by exceptions).
00137      **/
00138     virtual bool setProperty( const std::string & propertyName,
00139                               const YPropertyValue & val );
00140 
00141     /**
00142      * Get a property.
00143      * Reimplemented from YWidget.
00144      *
00145      * This method may throw exceptions, for example
00146      *   - if there is no property with that name
00147      **/
00148     virtual YPropertyValue getProperty( const std::string & propertyName );
00149 
00150     /**
00151      * Return this class's property set.
00152      * This also initializes the property set upon the first call.
00153      *
00154      * Reimplemented from YWidget.
00155      **/
00156     virtual const YPropertySet & propertySet();
00157 
00158     /**
00159      * Returns a descriptive label of this widget instance for debugging.
00160      *
00161      * Reimplemented from YWidget since a YLabel doesn't have a shortcut
00162      * property.
00163      **/
00164     virtual std::string debugLabel() const;
00165 
00166 private:
00167 
00168     ImplPtr<YLabelPrivate> priv;
00169 };
00170 
00171 
00172 typedef YLabel  YHeading;
00173 typedef YLabel  YOutputField;
00174 
00175 
00176 #endif // YLabel_h
 All Classes Functions Variables Enumerations Friends