libyui
3.0.10
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YTree.cc 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 00026 #define YUILogComponent "ui" 00027 #include "YUILog.h" 00028 00029 #include "YUISymbols.h" 00030 #include "YSelectionWidget.h" 00031 #include "YTree.h" 00032 #include "YTreeItem.h" 00033 00034 struct YTreePrivate 00035 { 00036 YTreePrivate() 00037 : immediateMode( false ) 00038 {} 00039 00040 bool immediateMode; 00041 }; 00042 00043 00044 YTree::YTree( YWidget * parent, const std::string & label, bool multiSelection, bool recursiveSelection ) 00045 : YSelectionWidget( parent, label, 00046 ! multiSelection, 00047 recursiveSelection ) 00048 , priv( new YTreePrivate() ) 00049 { 00050 YUI_CHECK_NEW( priv ); 00051 00052 setDefaultStretchable( YD_HORIZ, true ); 00053 setDefaultStretchable( YD_VERT, true ); 00054 } 00055 00056 00057 YTree::~YTree() 00058 { 00059 // NOP 00060 } 00061 00062 00063 bool 00064 YTree::immediateMode() const 00065 { 00066 return priv->immediateMode; 00067 } 00068 00069 00070 void 00071 YTree::setImmediateMode( bool immediateMode ) 00072 { 00073 priv->immediateMode = immediateMode; 00074 00075 if ( immediateMode ) 00076 setNotify( true ); 00077 } 00078 00079 00080 void 00081 YTree::addItems( const YItemCollection & itemCollection ) 00082 { 00083 YSelectionWidget::addItems( itemCollection ); 00084 rebuildTree(); 00085 } 00086 00087 00088 const YPropertySet & 00089 YTree::propertySet() 00090 { 00091 static YPropertySet propSet; 00092 00093 if ( propSet.isEmpty() ) 00094 { 00095 /* 00096 * @property itemID Value The currently selected item 00097 * @property itemID CurrentItem The currently selected item 00098 * @property list<itemID> CurrentBranch List of IDs of current branch from root to current item 00099 * @property itemList Items All items 00100 * @property map<ItemID> OpenItems Map of IDs of all open items - can only be queried, not set 00101 * @property std::string Label Caption above the tree 00102 * @property std::string IconPath Base path for icons 00103 * @property bool MultiSelection Flag: User can select multiple items (read-only) 00104 */ 00105 propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) ); 00106 propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) ); 00107 propSet.add( YProperty( YUIProperty_CurrentBranch, YOtherProperty ) ); 00108 propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) ); 00109 propSet.add( YProperty( YUIProperty_OpenItems, YOtherProperty ) ); 00110 propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); 00111 propSet.add( YProperty( YUIProperty_IconPath, YStringProperty ) ); 00112 propSet.add( YProperty( YUIProperty_SelectedItems, YOtherProperty ) ); 00113 propSet.add( YProperty( YUIProperty_MultiSelection, YBoolProperty, true ) ); // read-only 00114 propSet.add( YWidget::propertySet() ); 00115 00116 } 00117 00118 return propSet; 00119 } 00120 00121 00122 bool 00123 YTree::setProperty( const std::string & propertyName, const YPropertyValue & val ) 00124 { 00125 propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch 00126 00127 if ( propertyName == YUIProperty_Value ) return false; // Needs special handling 00128 else if ( propertyName == YUIProperty_CurrentItem ) return false; // Needs special handling 00129 else if ( propertyName == YUIProperty_CurrentBranch ) return false; // Needs special handling 00130 else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling 00131 else if ( propertyName == YUIProperty_OpenItems ) return false; // Needs special handling 00132 else if ( propertyName == YUIProperty_SelectedItems ) return false; // Needs special handling 00133 else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); 00134 else if ( propertyName == YUIProperty_IconPath ) setIconBasePath( val.stringVal() ); 00135 00136 else 00137 { 00138 return YWidget::setProperty( propertyName, val ); 00139 } 00140 00141 return true; // success -- no special processing necessary 00142 } 00143 00144 00145 YPropertyValue 00146 YTree::getProperty( const std::string & propertyName ) 00147 { 00148 propertySet().check( propertyName ); // throws exceptions if not found 00149 00150 if ( propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty ); 00151 else if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( YOtherProperty ); 00152 else if ( propertyName == YUIProperty_CurrentBranch ) return YPropertyValue( YOtherProperty ); 00153 else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty ); 00154 else if ( propertyName == YUIProperty_OpenItems ) return YPropertyValue( YOtherProperty ); 00155 else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() ); 00156 else if ( propertyName == YUIProperty_IconPath ) return YPropertyValue( iconBasePath() ); 00157 else if ( propertyName == YUIProperty_SelectedItems ) return YPropertyValue( YOtherProperty ); 00158 else 00159 { 00160 return YWidget::getProperty( propertyName ); 00161 } 00162 } 00163 00164 bool 00165 YTree::hasMultiSelection() const 00166 { 00167 return ! YSelectionWidget::enforceSingleSelection(); 00168 }