libyui  3.9.3
YMultiSelectionBox.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: YMultiSelectionBox.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YMultiSelectionBox.h"
30 #include "YUISymbols.h"
31 #include "YMacroRecorder.h"
32 #include "YUIException.h"
33 
34 using std::string;
35 
36 
38 {
40  : shrinkable( false )
41  {}
42 
43  bool shrinkable;
44 };
45 
46 
47 
48 YMultiSelectionBox::YMultiSelectionBox( YWidget * parent, const string & label )
49  : YSelectionWidget( parent, label,
50  false ) // enforceSingleSelection
51  , priv( new YMultiSelectionBoxPrivate )
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 
73 void YMultiSelectionBox::setShrinkable( bool shrinkable )
74 {
75  priv->shrinkable = shrinkable;
76 }
77 
78 
79 const YPropertySet &
81 {
82  static YPropertySet propSet;
83 
84  if ( propSet.isEmpty() )
85  {
86  /*
87  * @property itemList SelectedItems All currently selected items
88  * @property itemList Items All items
89  * @property itemID CurrentItem The current item (no matter if selected or not)
90  * @property string Label Caption above the MultiSelectionBox
91  */
92  propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) );
93  propSet.add( YProperty( YUIProperty_SelectedItems, YOtherProperty ) );
94  propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
95  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
96  propSet.add( YProperty( YUIProperty_IconPath, YStringProperty ) );
97  propSet.add( YWidget::propertySet() );
98  }
99 
100  return propSet;
101 }
102 
103 
104 bool
105 YMultiSelectionBox::setProperty( const string & propertyName, const YPropertyValue & val )
106 {
107  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
108 
109  if ( propertyName == YUIProperty_CurrentItem ) return false; // Needs special handling
110  else if ( propertyName == YUIProperty_SelectedItems ) return false; // Needs special handling
111  else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
112  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
113  else if ( propertyName == YUIProperty_IconPath ) setIconBasePath( val.stringVal() );
114  else
115  {
116  return YWidget::setProperty( propertyName, val );
117  }
118 
119  return true; // success -- no special processing necessary
120 }
121 
122 
124 YMultiSelectionBox::getProperty( const string & propertyName )
125 {
126  propertySet().check( propertyName ); // throws exceptions if not found
127 
128  if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( YOtherProperty );
129  else if ( propertyName == YUIProperty_SelectedItems ) return YPropertyValue( YOtherProperty );
130  else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
131  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
132  else
133  {
134  return YWidget::getProperty( propertyName );
135  }
136 }
137 
138 
139 
140 void
142 {
143  macroRecorder->recordWidgetProperty( this, YUIProperty_CurrentItem );
144  macroRecorder->recordWidgetProperty( this, YUIProperty_SelectedItems );
145 }
Abstract base class for macro recorders.
bool isEmpty() const
Returns &#39;true&#39; if this property set does not contain anything.
Definition: YProperty.h:263
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.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
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 ~YMultiSelectionBox()
Destructor.
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YWidget.cc:395
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
virtual void recordWidgetProperty(YWidget *widget, const char *propertyName)=0
Record one widget property.
YMultiSelectionBox(YWidget *parent, const std::string &label)
Constructor.
Class for widget properties.
Definition: YProperty.h:51
virtual void saveUserInput(YMacroRecorder *macroRecorder)
Save the widget&#39;s user input to a macro recorder.
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
void setIconBasePath(const std::string &basePath)
Set this widget&#39;s base path where to look up icons.
virtual void setShrinkable(bool shrinkable=true)
Make this MultiSelectionBox very small.
bool shrinkable() const
Return &#39;true&#39; if this MultiSelectionBox should be very small.
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