libyui
|
00001 /************************************************************************** 00002 Copyright (C) 2000 - 2010 Novell, Inc. 00003 All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00019 **************************************************************************/ 00020 00021 00022 /*---------------------------------------------------------------------\ 00023 | | 00024 | __ __ ____ _____ ____ | 00025 | \ \ / /_ _/ ___|_ _|___ \ | 00026 | \ V / _` \___ \ | | __) | | 00027 | | | (_| |___) || | / __/ | 00028 | |_|\__,_|____/ |_| |_____| | 00029 | | 00030 | core system | 00031 | (C) SuSE GmbH | 00032 \----------------------------------------------------------------------/ 00033 00034 File: YSelectionWidget.h 00035 00036 Author: Stefan Hundhammer <sh@suse.de> 00037 00038 /-*/ 00039 00040 #ifndef YSelectionWidget_h 00041 #define YSelectionWidget_h 00042 00043 #include "YWidget.h" 00044 #include "YItem.h" 00045 #include "ImplPtr.h" 00046 00047 using std::string; 00048 class YSelectionWidgetPrivate; 00049 00058 class YSelectionWidget : public YWidget 00059 { 00060 protected: 00061 00070 YSelectionWidget( YWidget * parent, 00071 const string & label, 00072 bool enforceSingleSelection, 00073 bool recurisveSelection = false ); 00074 00075 public: 00079 virtual ~YSelectionWidget(); 00080 00085 virtual const char * widgetClass() const { return "YSelectionWidget"; } 00086 00090 string label() const; 00091 00098 virtual void setLabel( const string & newLabel ); 00099 00111 virtual void addItem( YItem * item_disown ); 00112 00116 void addItem( const string & itemLabel, bool selected = false ); 00117 00122 void addItem( const string & itemLabel, 00123 const string & iconName, 00124 bool selected = false ); 00125 00130 virtual void addItems( const YItemCollection & itemCollection ); 00131 00138 virtual void deleteAllItems(); 00139 00143 void setItems( const YItemCollection & itemCollection ) 00144 { deleteAllItems(); addItems( itemCollection ); } 00145 00156 YItemIterator itemsBegin(); 00157 YItemConstIterator itemsBegin() const; 00158 00162 YItemIterator itemsEnd(); 00163 YItemConstIterator itemsEnd() const; 00164 00168 bool hasItems() const; 00169 00176 int itemsCount() const; 00177 00181 YItem * firstItem() const; 00182 00186 virtual YItem * selectedItem(); 00187 00195 virtual YItemCollection selectedItems(); 00196 00200 bool hasSelectedItem(); 00201 00218 virtual void selectItem( YItem * item, bool selected = true ); 00219 00226 virtual void deselectAllItems(); 00227 00232 void setIconBasePath( const string & basePath ); 00233 00238 string iconBasePath() const; 00239 00248 string iconFullPath( const string & iconName ) const; 00249 00259 string iconFullPath( YItem * item ) const; 00260 00264 bool itemsContain( YItem * item ) const; 00265 00270 YItem * findItem( const string & itemLabel ) const; 00271 00277 virtual string shortcutString() const { return label(); } 00278 00284 virtual void setShortcutString( const string & str ) 00285 { setLabel( str ); } 00286 00287 protected: 00288 00297 void setEnforceSingleSelection( bool on ); 00298 00302 bool enforceSingleSelection() const; 00303 00307 bool recursiveSelection() const; 00308 00313 YItem * findSelectedItem( YItemConstIterator begin, 00314 YItemConstIterator end ); 00315 00320 void findSelectedItems( YItemCollection & selectedItems, 00321 YItemConstIterator begin, 00322 YItemConstIterator end ); 00323 00327 void deselectAllItems( YItemIterator begin, 00328 YItemIterator end ); 00333 YItem * findItem ( const string & wantedItemLabel, 00334 YItemConstIterator begin, 00335 YItemConstIterator end ) const; 00336 00341 bool itemsContain ( YItem * wantedItem, 00342 YItemConstIterator begin, 00343 YItemConstIterator end ) const; 00348 YItem * itemAt( int index ) const; 00349 00350 00351 private: 00352 00353 ImplPtr<YSelectionWidgetPrivate> priv; 00354 }; 00355 00356 00357 #endif // YSelectionWidget_h