libyui  3.0.5
 All Classes Functions Variables Enumerations Friends
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 }