var_tree.hpp
Go to the documentation of this file.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
00143 int visibleItems();
00144
00145
00146 int countLeafs();
00147
00148
00149 Iterator getVisibleItem( int n );
00150
00151
00152 Iterator getLeaf( int n );
00153
00154
00155 Iterator getNextVisibleItem( Iterator it );
00156
00157
00158 Iterator getPrevVisibleItem( Iterator it );
00159
00160
00161 Iterator getNextItem( Iterator it );
00162
00163
00164 Iterator getPrevItem( Iterator it );
00165
00166
00167 Iterator getNextLeaf( Iterator it );
00168
00169
00170 Iterator getPrevLeaf( Iterator it );
00171
00172
00173 Iterator findById( int id );
00174
00175
00176 void ensureExpanded( VarTree::Iterator );
00177
00178
00179 int depth()
00180 {
00181 VarTree *parent = this;
00182 int depth = 0;
00183 while( ( parent = parent->parent() ) != NULL )
00184 depth++;
00185 return depth;
00186 }
00187
00188
00189 private:
00190
00191 list<VarTree> m_children;
00192
00193
00194 VarTree *m_pParent;
00195
00196 bool m_readonly;
00197
00198
00199 static const string m_type;
00200
00201
00202 VariablePtr m_cPosition;
00203 };
00204
00205 #endif