libyui  3.3.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 
36 {
38  : shrinkable( false )
39  {}
40 
41  bool shrinkable;
42 };
43 
44 
45 
46 YMultiSelectionBox::YMultiSelectionBox( YWidget * parent, const std::string & label )
47  : YSelectionWidget( parent, label,
48  false ) // enforceSingleSelection
49  , priv( new YMultiSelectionBoxPrivate )
50 {
51  YUI_CHECK_NEW( priv );
52 
53  setDefaultStretchable( YD_HORIZ, true );
54  setDefaultStretchable( YD_VERT, true );
55 
56 }
57 
58 
60 {
61  // NOP
62 }
63 
64 
66 {
67  return priv->shrinkable;
68 }
69 
70 
71 void YMultiSelectionBox::setShrinkable( bool shrinkable )
72 {
73  priv->shrinkable = shrinkable;
74 }
75 
76 
77 const YPropertySet &
79 {
80  static YPropertySet propSet;
81 
82  if ( propSet.isEmpty() )
83  {
84  /*
85  * @property itemList SelectedItems All currently selected items
86  * @property itemList Items All items
87  * @property itemID CurrentItem The current item (no matter if selected or not)
88  * @property std::string Label Caption above the MultiSelectionBox
89  */
90  propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) );
91  propSet.add( YProperty( YUIProperty_SelectedItems, YOtherProperty ) );
92  propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
93  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
94  propSet.add( YProperty( YUIProperty_IconPath, YStringProperty ) );
95  propSet.add( YWidget::propertySet() );
96  }
97 
98  return propSet;
99 }
100 
101 
102 bool
103 YMultiSelectionBox::setProperty( const std::string & propertyName, const YPropertyValue & val )
104 {
105  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
106 
107  if ( propertyName == YUIProperty_CurrentItem ) return false; // Needs special handling
108  else if ( propertyName == YUIProperty_SelectedItems ) return false; // Needs special handling
109  else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
110  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
111  else if ( propertyName == YUIProperty_IconPath ) setIconBasePath( val.stringVal() );
112  else
113  {
114  return YWidget::setProperty( propertyName, val );
115  }
116 
117  return true; // success -- no special processing necessary
118 }
119 
120 
122 YMultiSelectionBox::getProperty( const std::string & propertyName )
123 {
124  propertySet().check( propertyName ); // throws exceptions if not found
125 
126  if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( YOtherProperty );
127  else if ( propertyName == YUIProperty_SelectedItems ) return YPropertyValue( YOtherProperty );
128  else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
129  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
130  else
131  {
132  return YWidget::getProperty( propertyName );
133  }
134 }
135 
136 
137 
138 void
140 {
141  macroRecorder->recordWidgetProperty( this, YUIProperty_CurrentItem );
142  macroRecorder->recordWidgetProperty( this, YUIProperty_SelectedItems );
143 }
std::string label() const
Return this widget's label (the caption above the item list).
Abstract base class for macro recorders.
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
Definition: YProperty.h:263
virtual void setLabel(const std::string &newLabel)
Change this widget'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:145
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:428
A set of properties to check names and types against.
Definition: YProperty.h:197
virtual ~YMultiSelectionBox()
Destructor.
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YWidget.cc:393
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:453
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:561
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's user input to a macro recorder.
virtual const YPropertySet & propertySet()
Return this class'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's base path where to look up icons.
virtual void setShrinkable(bool shrinkable=true)
Make this MultiSelectionBox very small.
bool shrinkable() const
Return 'true' if this MultiSelectionBox should be very small.
void check(const std::string &propertyName) const
Check if a property 'propertyName' 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