00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef VAR_TREE_HPP
00026 #define VAR_TREE_HPP
00027
00028 #include <list>
00029
00030 #include "variable.hpp"
00031 #include "observer.hpp"
00032 #include "ustring.hpp"
00033 #include "var_percent.hpp"
00034
00035
00036 typedef struct tree_update
00037 {
00038 int i_type;
00039 int i_parent;
00040 int i_id;
00041 bool b_active_item;
00042 bool b_visible;
00043 } tree_update;
00044
00045
00046 class VarTree: public Variable, public Subject<VarTree, tree_update>
00047 {
00048 public:
00049 VarTree( intf_thread_t *pIntf );
00050
00051 VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
00052 const UStringPtr &rcString, bool selected, bool playing,
00053 bool expanded,bool readonly, void *pData );
00054
00055 virtual ~VarTree();
00056
00057
00058 virtual const string &getType() const { return m_type; }
00059
00060
00061 virtual void add( int id, const UStringPtr &rcString, bool selected,
00062 bool playing, bool expanded, bool readonly,
00063 void *pData );
00064
00065
00066 virtual void delSelected();
00067
00068
00069 virtual void clear();
00070
00071
00072 int m_id;
00073 UStringPtr m_cString;
00074 bool m_selected;
00075 bool m_playing;
00076 bool m_expanded;
00077 bool m_deleted;
00078 void *m_pData;
00079
00080 inline bool isReadonly() { return m_readonly; };
00081
00082
00083 int size() const { return m_children.size(); }
00084
00085
00086 typedef list<VarTree>::iterator Iterator;
00087 typedef list<VarTree>::const_iterator ConstIterator;
00088
00089
00090 Iterator begin() { return m_children.begin(); }
00091 ConstIterator begin() const { return m_children.begin(); }
00092
00093
00094 Iterator end() { return m_children.end(); }
00095 ConstIterator end() const { return m_children.end(); }
00096
00097
00098 VarTree &back() { return m_children.back(); }
00099
00100
00101 Iterator operator[]( int n );
00102 ConstIterator operator[]( int n ) const;
00103
00104
00105 VarTree *parent() { return m_pParent; }
00106 void checkParents( VarTree *pParent );
00107
00108
00109 Iterator getNextSibling( Iterator );
00110
00111 Iterator next_uncle();
00112 Iterator prev_uncle();
00113
00114
00115 VarTree *root()
00116 {
00117 VarTree *parent = this;
00118 while( parent->parent() != NULL )
00119 parent = parent->parent();
00120 return parent;
00121 }
00122
00123
00124 Iterator firstLeaf();
00125
00126 void removeChild( VarTree::Iterator item )
00127 {
00128 m_children.erase( item );
00129 }
00130
00131
00132 virtual void action( VarTree *pItem ) {}
00133
00134
00135 VarPercent &getPositionVar() const
00136 { return *((VarPercent*)m_cPosition.get()); }
00137
00138
00139 const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
00140
00141
00142 int visibleItems();
00143
00144
00145 int countLeafs();
00146
00147
00148 Iterator getVisibleItem( int n );
00149
00150
00151 Iterator getLeaf( int n );
00152
00153
00154 Iterator getNextVisibleItem( Iterator it );
00155
00156
00157 Iterator getPrevVisibleItem( Iterator it );
00158
00159
00160 Iterator getNextItem( Iterator it );
00161
00162
00163 Iterator getPrevItem( Iterator it );
00164
00165
00166 Iterator getNextLeaf( Iterator it );
00167
00168
00169 Iterator getPrevLeaf( Iterator it );
00170
00171
00172 Iterator findById( int id );
00173
00174
00175 void ensureExpanded( VarTree::Iterator );
00176
00177
00178 int depth()
00179 {
00180 VarTree *parent = this;
00181 int depth = 0;
00182 while( ( parent = parent->parent() ) != NULL )
00183 depth++;
00184 return depth;
00185 }
00186
00187
00188 private:
00189
00190 list<VarTree> m_children;
00191
00192
00193 VarTree *m_pParent;
00194
00195 bool m_readonly;
00196
00197
00198 static const string m_type;
00199
00200
00201 VariablePtr m_cPosition;
00202 };
00203
00204 #endif