libyui  3.4.2
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 
35 {
37  : shrinkable( false )
38  , immediateMode( false )
39  {}
40 
41  bool shrinkable;
42  bool immediateMode;
43 };
44 
45 
46 
47 
48 YSelectionBox::YSelectionBox( YWidget * parent, const std::string & label )
49  : YSelectionWidget( parent, label,
50  true ) // enforceSingleSelection
51  , priv( new YSelectionBoxPrivate() )
52 {
53  YUI_CHECK_NEW( priv );
54 
55  setDefaultStretchable( YD_HORIZ, true );
56  setDefaultStretchable( YD_VERT, true );
57 
58 }
59 
60 
62 {
63  // NOP
64 }
65 
66 
68 {
69  return priv->shrinkable;
70 }
71 
72 
74 {
75  priv->shrinkable = shrinkable;
76 }
77 
78 
80 {
81  return priv->immediateMode;
82 }
83 
84 
86 {
87  priv->immediateMode = immediateMode;
88 
89  if ( immediateMode )
90  setNotify( true );
91 }
92 
93 
94 const YPropertySet &
96 {
97  static YPropertySet propSet;
98 
99  if ( propSet.isEmpty() )
100  {
101  /*
102  * @property itemID Value The currently selected item
103  * @property itemID CurrentItem The currently selected item
104  * @property itemList Items All items
105  * @property std::string Label Caption above the selection box
106  * @property std::string IconPath Base path for icons
107  */
108  propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) );
109  propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) );
110  propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
111  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
112  propSet.add( YProperty( YUIProperty_IconPath, YStringProperty ) );
113  propSet.add( YWidget::propertySet() );
114  }
115 
116  return propSet;
117 }
118 
119 
120 bool
121 YSelectionBox::setProperty( const std::string & propertyName, const YPropertyValue & val )
122 {
123  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
124 
125  if ( propertyName == YUIProperty_Value ) return false; // Needs special handling
126  else if ( propertyName == YUIProperty_CurrentItem ) return false; // Needs special handling
127  else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
128  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
129  else if ( propertyName == YUIProperty_IconPath ) setIconBasePath( val.stringVal() );
130  else
131  {
132  return YWidget::setProperty( propertyName, val );
133  }
134 
135  return true; // success -- no special processing necessary
136 }
137 
138 
140 YSelectionBox::getProperty( const std::string & propertyName )
141 {
142  propertySet().check( propertyName ); // throws exceptions if not found
143 
144  if ( propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty );
145  else if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( YOtherProperty );
146  else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
147  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
148  else if ( propertyName == YUIProperty_IconPath ) return YPropertyValue( iconBasePath() );
149  else
150  {
151  return YWidget::getProperty( propertyName );
152  }
153 }
std::string label() const
Return this widget&#39;s label (the caption above the item list).
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:145
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:430
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:393
YSelectionBox(YWidget *parent, const std::string &label)
Constructor.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:455
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:564
Class for widget properties.
Definition: YProperty.h:51
void setNotify(bool notify=true)
Sets the Notify property.
Definition: YWidget.cc:520
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:87
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
std::string iconBasePath() const
Return this widget&#39;s base path where to look up icons as set with setIconBasePath().