libyui  3.10.0
YFrame.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YFrame.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YUISymbols.h"
30 #include "YFrame.h"
31 #include "YShortcut.h"
32 
33 using std::string;
34 
35 
37 {
38  YFramePrivate( const string & frameLabel )
39  : label( frameLabel )
40  {}
41 
42  string label;
43 };
44 
45 
46 
47 
48 YFrame::YFrame( YWidget * parent, const string & label )
49  : YSingleChildContainerWidget( parent )
50  , priv( new YFramePrivate( YShortcut::cleanShortcutString( label ) ) )
51 {
52  YUI_CHECK_NEW( priv );
53 }
54 
55 
57 {
58  // NOP
59 }
60 
61 
62 void YFrame::setLabel( const string & newLabel )
63 {
64  priv->label = YShortcut::cleanShortcutString( newLabel );
65 }
66 
67 
68 string YFrame::label() const
69 {
70  return priv->label;
71 }
72 
73 
74 const YPropertySet &
76 {
77  static YPropertySet propSet;
78 
79  if ( propSet.isEmpty() )
80  {
81  /*
82  * @property string Label the text on the frame
83  */
84 
85  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
86  propSet.add( YWidget::propertySet() );
87  }
88 
89  return propSet;
90 }
91 
92 
93 bool
94 YFrame::setProperty( const string & propertyName, const YPropertyValue & val )
95 {
96  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
97 
98  if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
99  else
100  {
101  return YWidget::setProperty( propertyName, val );
102  }
103 
104  return true; // success -- no special processing necessary
105 }
106 
107 
109 YFrame::getProperty( const string & propertyName )
110 {
111  propertySet().check( propertyName ); // throws exceptions if not found
112 
113  if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
114  else
115  {
116  return YWidget::getProperty( propertyName );
117  }
118 }
YPropertySet::add
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:146
YWidget
Abstract base class of all UI widgets.
Definition: YWidget.h:54
YPropertySet
A set of properties to check names and types against.
Definition: YProperty.h:197
YPropertySet::isEmpty
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
Definition: YProperty.h:263
YPropertyValue::stringVal
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
YSingleChildContainerWidget
Container widget class that manages one child.
Definition: YSingleChildContainerWidget.h:34
YPropertyValue::type
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
YWidget::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:457
YShortcut
Helper class for shortcut management: This class holds data about the shortcut for one single widget.
Definition: YShortcut.h:40
YProperty
Class for widget properties.
Definition: YProperty.h:51
YFrame::label
std::string label() const
Get the current frame label.
Definition: YFrame.cc:68
YFrame::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YFrame.cc:75
YPropertySet::check
void check(const std::string &propertyName) const
Check if a property 'propertyName' exists in this property set.
Definition: YProperty.cc:88
YFramePrivate
Definition: YFrame.cc:36
YFrame::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YFrame.cc:94
YPropertyValue
Transport class for the value of simple properties.
Definition: YProperty.h:104
YFrame::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YFrame.cc:109
YFrame::YFrame
YFrame(YWidget *parent, const std::string &label)
Constructor.
Definition: YFrame.cc:48
YShortcut::cleanShortcutString
std::string cleanShortcutString()
Returns the shortcut string ( from the widget's shortcut property ) without any "&" markers.
Definition: YShortcut.cc:93
YFrame::~YFrame
virtual ~YFrame()
Destructor.
Definition: YFrame.cc:56
YWidget::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:432
YFrame::setLabel
virtual void setLabel(const std::string &newLabel)
Change the frame label.
Definition: YFrame.cc:62
YWidget::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YWidget.cc:395