libyui  3.9.3
YSelectionBox.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: YSelectionBox.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YSelectionBox.h"
30 #include "YUISymbols.h"
31 #include "YUIException.h"
32 
33 using std::string;
34 
35 
37 {
39  : shrinkable( false )
40  , immediateMode( false )
41  {}
42 
43  bool shrinkable;
44  bool immediateMode;
45 };
46 
47 
48 
49 
50 YSelectionBox::YSelectionBox( YWidget * parent, const string & label )
51  : YSelectionWidget( parent, label,
52  true ) // enforceSingleSelection
53  , priv( new YSelectionBoxPrivate() )
54 {
55  YUI_CHECK_NEW( priv );
56 
57  setDefaultStretchable( YD_HORIZ, true );
58  setDefaultStretchable( YD_VERT, true );
59 }
60 
61 
63 {
64  // NOP
65 }
66 
67 
69 {
70  return priv->shrinkable;
71 }
72 
73 
74 void YSelectionBox::setShrinkable( bool shrinkable )
75 {
76  priv->shrinkable = shrinkable;
77 }
78 
79 
81 {
82  return priv->immediateMode;
83 }
84 
85 
86 void YSelectionBox::setImmediateMode( bool immediateMode )
87 {
88  priv->immediateMode = immediateMode;
89 
90  if ( immediateMode )
91  setNotify( true );
92 }
93 
94 
95 const YPropertySet &
97 {
98  static YPropertySet propSet;
99 
100  if ( propSet.isEmpty() )
101  {
102  /*
103  * @property itemID Value The currently selected item
104  * @property itemID CurrentItem The currently selected item
105  * @property itemList Items All items
106  * @property string Label Caption above the selection box
107  * @property string IconPath Base path for icons
108  */
109  propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) );
110  propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) );
111  propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
112  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
113  propSet.add( YProperty( YUIProperty_IconPath, YStringProperty ) );
114  propSet.add( YWidget::propertySet() );
115  }
116 
117  return propSet;
118 }
119 
120 
121 bool
122 YSelectionBox::setProperty( const string & propertyName, const YPropertyValue & val )
123 {
124  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
125 
126  if ( propertyName == YUIProperty_Value ) return false; // Needs special handling
127  else if ( propertyName == YUIProperty_CurrentItem ) return false; // Needs special handling
128  else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
129  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
130  else if ( propertyName == YUIProperty_IconPath ) setIconBasePath( val.stringVal() );
131  else
132  {
133  return YWidget::setProperty( propertyName, val );
134  }
135 
136  return true; // success -- no special processing necessary
137 }
138 
139 
141 YSelectionBox::getProperty( const string & propertyName )
142 {
143  propertySet().check( propertyName ); // throws exceptions if not found
144 
145  if ( propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty );
146  else if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( YOtherProperty );
147  else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
148  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
149  else if ( propertyName == YUIProperty_IconPath ) return YPropertyValue( iconBasePath() );
150  else
151  {
152  return YWidget::getProperty( propertyName );
153  }
154 }
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
bool isEmpty() const
Returns &#39;true&#39; if this property set does not contain anything.
Definition: YProperty.h:263
bool immediateMode() const
Deliver even more events than with notify() set.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
virtual ~YSelectionBox()
Destructor.
bool shrinkable() const
Return &#39;true&#39; if this SelectionBox should be very small.
virtual void setLabel(const std::string &newLabel)
Change this widget&#39;s label (the caption above the item list).
Transport class for the value of simple properties.
Definition: YProperty.h:104
Base class for various kinds of multi-value widgets.
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:146
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:432
A set of properties to check names and types against.
Definition: YProperty.h:197
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
void setImmediateMode(bool on=true)
Set immediateMode() on or off.
virtual void setShrinkable(bool shrinkable=true)
Make this SelectionBox very small.
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YWidget.cc:395
YSelectionBox(YWidget *parent, const std::string &label)
Constructor.
std::string label() const
Return this widget&#39;s label (the caption above the item list).
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:457
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:566
Class for widget properties.
Definition: YProperty.h:51
std::string iconBasePath() const
Return this widget&#39;s base path where to look up icons as set with setIconBasePath().
void setNotify(bool notify=true)
Sets the Notify property.
Definition: YWidget.cc:522
void setIconBasePath(const std::string &basePath)
Set this widget&#39;s base path where to look up icons.
void check(const std::string &propertyName) const
Check if a property &#39;propertyName&#39; exists in this property set.
Definition: YProperty.cc:88
Abstract base class of all UI widgets.
Definition: YWidget.h:54
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169