libyui  2.42.5
 All Classes Functions Variables Enumerations Friends
YTable.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: YTable.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YUISymbols.h"
30 #include "YTable.h"
31 
32 
34 {
35  YTablePrivate( YTableHeader * header )
36  : header( header )
37  , keepSorting( false )
38  , immediateMode( false )
39  {
40  }
41 
42  YTableHeader * header;
43  bool keepSorting;
44  bool immediateMode;
45 };
46 
47 
48 
49 
50 YTable::YTable( YWidget * parent, YTableHeader * header, bool multiSelection )
51  : YSelectionWidget( parent,
52  "", // label
53  ! multiSelection ) // enforceSingleSelection
54  , priv( new YTablePrivate( header ) )
55 {
56  YUI_CHECK_PTR( header );
57  YUI_CHECK_NEW( priv );
58 
59  setDefaultStretchable( YD_HORIZ, true );
60  setDefaultStretchable( YD_VERT, true );
61 }
62 
63 
65 {
66  if ( priv->header )
67  delete priv->header;
68 }
69 
70 
71 void
73 {
74  YUI_CHECK_PTR( newHeader );
75 
76  if ( priv->header->columns() != newHeader->columns() )
78 
79  delete priv->header;
80  priv->header = newHeader;
81 }
82 
83 
84 int
86 {
87  return priv->header->columns();
88 }
89 
90 
91 bool
92 YTable::hasColumn( int column ) const
93 {
94  return priv->header->hasColumn( column );
95 }
96 
97 
98 std::string
99 YTable::header( int column ) const
100 {
101  return priv->header->header( column );
102 }
103 
104 
105 YAlignmentType
106 YTable::alignment( int column ) const
107 {
108  return priv->header->alignment( column );
109 }
110 
111 
112 bool
114 {
115  return priv->immediateMode;
116 }
117 
118 
119 void
120 YTable::setImmediateMode( bool immediateMode )
121 {
122  priv->immediateMode = immediateMode;
123 
124  if ( immediateMode )
125  setNotify( true );
126 }
127 
128 
129 bool
131 {
132  return priv->keepSorting;
133 }
134 
135 
136 void
137 YTable::setKeepSorting( bool keepSorting )
138 {
139  priv->keepSorting = keepSorting;
140 }
141 
142 
143 bool
145 {
147 }
148 
149 
150 const YPropertySet &
152 {
153  static YPropertySet propSet;
154 
155  if ( propSet.isEmpty() )
156  {
157  /*
158  * @property itemID Value The currently selected item
159  * @property itemID CurrentItem The currently selected item
160  * @property itemList Items All items
161  * @property itemList SelectedItems All currently selected items
162  * @property std::string Cell One cell (one column of one item)
163  * @property integer Cell (ChangeWidget only) One cell as integer
164  * @property `icon(...) Cell Icon for one one cell
165  * @property std::string Item Alias for Cell
166  * @property std::string Item QueryWidget only: Return one complete item
167  * @property std::string IconPath Base path for icons
168  * @property bool MultiSelection Flag: User can select multiple items (read-only)
169  */
170  propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) );
171  propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) );
172  propSet.add( YProperty( YUIProperty_SelectedItems, YOtherProperty ) );
173  propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
174  propSet.add( YProperty( YUIProperty_Cell, YOtherProperty ) );
175  propSet.add( YProperty( YUIProperty_Item, YOtherProperty ) );
176  propSet.add( YProperty( YUIProperty_IconPath, YStringProperty ) );
177  propSet.add( YProperty( YUIProperty_MultiSelection, YBoolProperty, true ) ); // read-only
178  propSet.add( YWidget::propertySet() );
179  }
180 
181  return propSet;
182 }
183 
184 
185 bool
186 YTable::setProperty( const std::string & propertyName, const YPropertyValue & val )
187 {
188  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
189 
190  if ( propertyName == YUIProperty_Value ) return false; // Needs special handling
191  else if ( propertyName == YUIProperty_CurrentItem ) return false; // Needs special handling
192  else if ( propertyName == YUIProperty_SelectedItems ) return false; // Needs special handling
193  else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
194  else if ( propertyName == YUIProperty_Cell ) return false; // Needs special handling
195  else if ( propertyName == YUIProperty_Item ) return false; // Needs special handling
196  else if ( propertyName == YUIProperty_IconPath ) setIconBasePath( val.stringVal() );
197  else
198  {
199  return YWidget::setProperty( propertyName, val );
200  }
201 
202  return true; // success -- no special processing necessary
203 }
204 
205 
207 YTable::getProperty( const std::string & propertyName )
208 {
209  propertySet().check( propertyName ); // throws exceptions if not found
210 
211  if ( propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty );
212  else if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( YOtherProperty );
213  else if ( propertyName == YUIProperty_SelectedItems ) return YPropertyValue( YOtherProperty );
214  else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
215  else if ( propertyName == YUIProperty_Cell ) return YPropertyValue( YOtherProperty );
216  else if ( propertyName == YUIProperty_Item ) return YPropertyValue( YOtherProperty );
217  else if ( propertyName == YUIProperty_IconPath ) return YPropertyValue( iconBasePath() );
218  else
219  {
220  return YWidget::getProperty( propertyName );
221  }
222 }