00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef YTree_h
00021 #define YTree_h
00022
00023 #include "YWidget.h"
00024 #include <ycp/YCPString.h>
00025 #include <ycp/YCPList.h>
00026
00027
00028 class YMacroRecorder;
00029 class YTreeItem;
00030
00031 typedef vector<YTreeItem *> YTreeItemList;
00032 typedef vector<YTreeItem *>::iterator YTreeItemListIterator;
00033 typedef vector<YTreeItem *>::const_iterator YTreeItemListConstIterator;
00034
00035
00039 class YTree : public YWidget
00040 {
00041 friend class YTreeItem;
00042
00043 public:
00044
00050 YTree( const YWidgetOpt & opt, YCPString label );
00051
00052
00056 virtual ~YTree();
00057
00058
00063 virtual char *widgetClass() { return "YTree"; }
00064
00065
00071 virtual void rebuildTree();
00072
00076 YTreeItem * addItem ( YTreeItem * parentItem,
00077 const YCPValue & id,
00078 const YCPString & text,
00079 const YCPString & iconName,
00080 bool open );
00081
00089 YTreeItem * addItem ( YTreeItem * parentItem,
00090 const YCPString & text,
00091 const YCPString & iconName,
00092 void * data,
00093 bool open );
00094
00098 YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue );
00099
00103 YCPValue queryWidget( const YCPSymbol & property );
00104
00109 virtual void setLabel( const YCPString & label );
00110
00118 YCPString getLabel();
00119
00124 const char *shortcutProperty() { return YUIProperty_Label; }
00125
00131 bool parseItemList( const YCPList & itemList, YTreeItem *parentItem = 0);
00132
00136 bool hasIcons() const { return _hasIcons; }
00137
00138
00139 protected:
00140
00145 virtual const YTreeItem * getCurrentItem() const = 0;
00146
00150 virtual void setCurrentItem ( YTreeItem * it ) = 0;
00151
00156 YTreeItem *findItemWithId ( const YCPValue & id );
00157
00162 YTreeItem *findItemWithText ( const YCPString & text );
00163
00168 YCPList itemsTermList( YTreeItemList items );
00169
00173 void findOpenItems( YCPMap & openItems, YTreeItemList items );
00174
00179 virtual void deleteAllItems();
00180
00181
00182
00183
00184
00185
00186 YTreeItemList items;
00187
00188
00189 private:
00190
00196 virtual void saveUserInput( YMacroRecorder *macroRecorder );
00197
00198
00199
00200
00201
00202
00203 YCPString label;
00204 bool _hasIcons;
00205 };
00206
00207
00208 class YTreeItem
00209 {
00210 friend class YTree;
00211
00212 public:
00213
00217 YTreeItem ( YTree * parent,
00218 const YCPValue & id,
00219 const YCPString & text,
00220 const YCPString & iconName,
00221 bool open = false );
00222
00226 YTreeItem ( YTreeItem * parent,
00227 const YCPValue & id,
00228 const YCPString & text,
00229 const YCPString & iconName,
00230 bool open = false );
00231
00232
00240 YTreeItem ( YTree * parent,
00241 const YCPString & text,
00242 const YCPString & iconName,
00243 void * data,
00244 bool open = false );
00245
00246
00254 YTreeItem ( YTreeItem * parent,
00255 const YCPString & text,
00256 const YCPString & iconName,
00257 void * data,
00258 bool open = false );
00259
00260
00264 virtual ~YTreeItem();
00265
00266 const YCPString & getText() const { return _text; }
00267 const YCPValue & getId() const { return _id; }
00268 const YTreeItemList & itemList() const { return _items; }
00269 bool isOpenByDefault() const { return _openByDefault; }
00270
00275 YTreeItem *findItemWithId ( const YCPValue & id );
00276
00281 YTreeItem *findItemWithText ( const YCPString & text );
00282
00287 void setOpen( bool open ) { _open = open; }
00288
00292 bool isOpen() const { return _open; }
00293
00297 void * data() const { return _data; }
00298
00303 void setData( void * data ) { _data = data; }
00304
00308 YCPString iconName() const;
00309
00313 void setIconName( const YCPString & icon ) { _iconName = icon; }
00314
00315
00316 protected:
00317
00318 YCPValue _id;
00319 void * _data;
00320 YCPString _text;
00321 YCPString _iconName;
00322 YTree * _parentTree;
00323 YTreeItem * _parentItem;
00324 bool _openByDefault;
00325 bool _open;
00326
00327 YTreeItemList _items;
00328 };
00329
00330
00331
00332 #endif // YTree_h