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
00026
00027 #ifndef TREEVIEW_H
00028 #define TREEVIEW_H
00029 #include <vdk/vdkobj.h>
00030 #include <vdk/dlist.h>
00031 #include <vdk/vdkprops.h>
00032 #include <vdk/vdkarray.h>
00033 #include <vdk/value_sem_list.h>
00034 class VDKTreeView;
00035
00041 typedef VDKArray<VDKString> StringRow;
00042 typedef bool (*VDKStringCompareFunction)(VDKString&, VDKString&);
00043
00044 class VDKTreeViewModelTuple: public StringRow
00045 {
00046
00047
00048
00049
00050
00051 public:
00055 VDKReadWriteValueProp<VDKTreeViewModelTuple,int> KeyIndex;
00059 VDKReadWriteValueProp<VDKTreeViewModelTuple,VDKStringCompareFunction> Less;
00063 VDKReadWriteValueProp<VDKTreeViewModelTuple,VDKStringCompareFunction> Equal;
00074 VDKTreeViewModelTuple(int n = 0, int key = 0, VDKStringCompareFunction less = NULL,
00075 VDKStringCompareFunction equal= NULL):
00076 StringRow(n),
00077 KeyIndex("KeyIndex",this,key),
00078 Less("Less",this,less),
00079 Equal("Equal",this,equal)
00080 {
00081
00082 }
00083
00084 virtual ~VDKTreeViewModelTuple() {}
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 int operator <(VDKTreeViewModelTuple& t)
00105 {
00106 int key_index = KeyIndex;
00107 VDKStringCompareFunction less = Less;
00108 if(less)
00109 return less((*this)[key_index],t[key_index]);
00110 else
00111 return (*this)[key_index] < t[key_index];
00112 }
00113 int operator==(VDKTreeViewModelTuple& t)
00114 {
00115 int key_index = KeyIndex;
00116 VDKStringCompareFunction equal = Equal;
00117 if(equal)
00118 return equal((*this)[key_index],t[key_index]);
00119 else
00120 return (*this)[key_index] == t[key_index];
00121 }
00122 };
00123
00124 typedef VDKValueList<VDKTreeViewModelTuple> VDKTreeViewModelTupleList;
00125 typedef VDKValueListIterator<VDKTreeViewModelTuple> VDKTreeViewModelTupleListIterator;
00126 typedef VDKArray<VDKTreeViewModelTuple> VDKTreeViewModelTupleArray;
00133 class VDKTreeViewModel: public VDKNotCopyAble
00134 {
00135 protected:
00136 GtkTreeStore *model;
00137
00138 public:
00142 GtkTreeStore* GtkModel() { return model; }
00148 VDKTreeViewModel(GType* types, int ncol);
00152 ~VDKTreeViewModel();
00166 void AppendBlank(GtkTreeIter* iter,GtkTreeIter* parent = NULL);
00181 void PrependBlank(GtkTreeIter* iter,GtkTreeIter* parent = NULL);
00191 void InsertTuple(GtkTreeIter* iter,VDKTreeViewModelTuple &tuple,GtkTreeIter* parent = NULL, bool recurse = false);
00195 void Clear();
00200 void Remove(GtkTreeIter* i);
00213 void SetData(GtkTreeIter* node,...);
00238 void SetCell(GtkTreeIter* node, int column, const char* value);
00287 char *GetCell(GtkTreeIter* node, int column);
00295 void GetTuple(GtkTreeIter* node,VDKTreeViewModelTuple& tuple);
00312 bool Root(GtkTreeIter* iter);
00317 bool Next(GtkTreeIter* iter);
00322 bool HasChild(GtkTreeIter* iter)
00323 { return gtk_tree_model_iter_has_child (GTK_TREE_MODEL(model), iter); }
00331 bool Child(GtkTreeIter* iter,GtkTreeIter* parent);
00351 bool Find(GtkTreeIter* iter,int column, char* value);
00352
00353 };
00354
00355
00359 class VDKTreeViewModelIterator
00360 {
00361 VDKTreeViewModel* model;
00362 GtkTreeIter iter, *internal_iter;
00363 public:
00364 VDKTreeViewModelIterator(): model(NULL),internal_iter(NULL) {}
00371 VDKTreeViewModelIterator(VDKTreeViewModel* model,GtkTreeIter* parent = NULL);
00375 GtkTreeIter* current() { return internal_iter; }
00379 operator int() { return internal_iter != NULL; }
00407 bool HasChild();
00411 void operator++();
00415 void operator++(int);
00416 };
00417
00422 class VDKTreeViewColumn: public VDKNotCopyAble
00423 {
00424 protected:
00425 static void edited_callback (GtkCellRendererText *cell,
00426 gchar *path_string,
00427 gchar *new_text,
00428 gpointer data);
00429 static void toggled_callback (GtkCellRendererToggle *cell,
00430 gchar *path_string,
00431 gpointer data);
00432 private:
00433 GtkCellRenderer *cell;
00434 GtkTreeViewColumn *column;
00435 VDKTreeView* owner;
00436 gulong handler_seq_no;
00437 int id;
00438 public:
00442 VDKReadWriteValueProp<VDKTreeViewColumn,VDKRgb> NormalBackground;
00446 VDKReadWriteValueProp<VDKTreeViewColumn,VDKRgb> Foreground;
00450 VDKReadWriteValueProp<VDKTreeViewColumn,VDKFont*> Font;
00454 VDKReadWriteValueProp<VDKTreeViewColumn,const char*> Title;
00460 VDKReadWriteValueProp<VDKTreeViewColumn,int> Width;
00464 VDKReadWriteValueProp<VDKTreeViewColumn,bool> Sortable;
00465
00531 VDKTreeViewColumn(VDKTreeView *owner,
00532 int column,
00533 char* title = NULL,
00534 bool editable = false,
00535 int editcol = -1);
00539 ~VDKTreeViewColumn();
00543 GtkTreeViewColumn *GtkColumn() { return column; }
00547 GtkCellRenderer* Renderer() { return cell; }
00551 VDKTreeView* Owner() { return owner; }
00555 void ActiveTitle(bool flag = true);
00556
00557 protected:
00558 void SetNormalBackground(VDKRgb rgb);
00559 void SetForeground(VDKRgb rgb);
00560 void SetFont(VDKFont* font);
00561 void SetTitle(const char* title);
00562 const char* GetTitle();
00563 void SetWidth(int w);
00564 int GetWidth();
00565 void SetSortable(bool flag);
00566 bool GetSortable();
00567 };
00568
00569 typedef VDKList<VDKTreeViewColumn> VDKTreeViewColumnList;
00570 typedef VDKListIterator<VDKTreeViewColumn> VDKTreeViewColumnListIterator;
00575 class VDKTreeViewIter: public GtkTreeIter
00576 {
00577 GtkTreeModel *model;
00578 public:
00583 VDKTreeViewIter(GtkTreeModel *model= NULL): model(model) {}
00587 GtkTreeModel* Model(GtkTreeModel* m = NULL) { if(m) model = m; return model; }
00588
00592 bool operator==(VDKTreeViewIter& i) { return false; }
00596 bool operator<(VDKTreeViewIter& i) { return false; }
00602 bool Child(VDKTreeViewIter* child_iter);
00608 bool Parent(VDKTreeViewIter* parent_iter);
00609 };
00610
00611 typedef VDKArray<VDKTreeViewIter> VDKTreeViewIterArray;
00612 typedef VDKValueList<VDKTreeViewIter> VDKTreeViewIterList;
00613 typedef VDKValueListIterator<VDKTreeViewIter> VDKTreeViewIterListIterator;
00614
00620 class VDKTreeView: public VDKObject
00621 {
00622 private:
00623 GtkTreeSelection *selection;
00624 VDKTreeViewColumnList *columns;
00625 VDKTreeViewIterList selections;
00626
00627 protected:
00628
00629 public:
00633 VDKReadWriteValueProp<VDKTreeView,VDKTreeViewModel*> Model;
00637 VDKReadOnlyValueProp<VDKTreeView,int> SelectedColumn;
00649 VDKTreeView(VDKForm* owner ,
00650 VDKTreeViewModel* model = NULL,
00651 GtkSelectionMode mode = GTK_SELECTION_SINGLE);
00655 ~VDKTreeView();
00656
00660 void SetModel(VDKTreeViewModel* model);
00661
00665 VDKTreeViewColumnList * Columns() { return columns; }
00669 void GetSelections();
00675 VDKTreeViewIterList &Selections() { return selections; }
00680 void SelectNode(GtkTreeIter* iter);
00685 void UnselectNode(GtkTreeIter* iter);
00691 void Expand(GtkTreeIter* iter = NULL, bool expand_all = false);
00695 void RemoveSelected(void);
00696 #ifdef USE_SIGCPLUSPLUS
00697
00710 VDKSignal3< void, GtkTreeIter*, int , char* > OnCellEdited;
00724 VDKSignal3< void, GtkTreeIter*, int, bool> OnCellToggled;
00725 #endif
00726 };
00727
00728 #endif
00729
00730
00731
00732