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 GtkTreeIter iter;
00138 public:
00142 GtkTreeStore* GtkModel() { return model; }
00148 VDKTreeViewModel(GType* types, int ncol);
00152 ~VDKTreeViewModel();
00166 GtkTreeIter* AppendBlank(GtkTreeIter* parent = NULL);
00180 GtkTreeIter* PrependBlank(GtkTreeIter* parent = NULL);
00190 GtkTreeIter* InsertTuple(VDKTreeViewModelTuple &tuple,GtkTreeIter* parent = NULL, bool recurse = false);
00194 void Clear();
00199 void Remove(GtkTreeIter* i);
00210 void SetData(GtkTreeIter* node,...);
00234 void SetCell(GtkTreeIter* node, int column, const char* value);
00281 char *GetCell(GtkTreeIter* node, int column);
00289 void GetTuple(GtkTreeIter* node,VDKTreeViewModelTuple& tuple);
00299 GtkTreeIter* Root();
00303 GtkTreeIter* Next();
00308 bool HasChild(GtkTreeIter* iter)
00309 { return gtk_tree_model_iter_has_child (GTK_TREE_MODEL(model), iter); }
00312 GtkTreeIter* Child(GtkTreeIter* parent);
00331 bool Find(GtkTreeIter* iter,int column, char* value);
00332
00333 };
00334
00335
00339 class VDKTreeViewModelIterator
00340 {
00341 VDKTreeViewModel* model;
00342 GtkTreeIter iter, *internal_iter;
00343 public:
00344 VDKTreeViewModelIterator(): model(NULL),internal_iter(NULL) {}
00351 VDKTreeViewModelIterator(VDKTreeViewModel* model,GtkTreeIter* parent = NULL);
00355 GtkTreeIter* current() { return internal_iter; }
00359 operator int() { return internal_iter != NULL; }
00387 bool HasChild();
00391 void operator++();
00395 void operator++(int);
00396 };
00397
00402 class VDKTreeViewColumn: public VDKNotCopyAble
00403 {
00404 protected:
00405 static void edited_callback (GtkCellRendererText *cell,
00406 gchar *path_string,
00407 gchar *new_text,
00408 gpointer data);
00409 static void toggled_callback (GtkCellRendererToggle *cell,
00410 gchar *path_string,
00411 gpointer data);
00412 private:
00413 GtkCellRenderer *cell;
00414 GtkTreeViewColumn *column;
00415 VDKTreeView* owner;
00416 gulong handler_seq_no;
00417 int id;
00418 public:
00422 VDKReadWriteValueProp<VDKTreeViewColumn,VDKRgb> NormalBackground;
00426 VDKReadWriteValueProp<VDKTreeViewColumn,VDKRgb> Foreground;
00430 VDKReadWriteValueProp<VDKTreeViewColumn,VDKFont*> Font;
00434 VDKReadWriteValueProp<VDKTreeViewColumn,const char*> Title;
00440 VDKReadWriteValueProp<VDKTreeViewColumn,int> Width;
00444 VDKReadWriteValueProp<VDKTreeViewColumn,bool> Sortable;
00445
00511 VDKTreeViewColumn(VDKTreeView *owner,
00512 int column,
00513 char* title = NULL,
00514 bool editable = false,
00515 int editcol = -1);
00519 ~VDKTreeViewColumn();
00523 GtkTreeViewColumn *GtkColumn() { return column; }
00527 GtkCellRenderer* Renderer() { return cell; }
00531 VDKTreeView* Owner() { return owner; }
00535 void ActiveTitle(bool flag = true);
00536
00537 protected:
00538 void SetNormalBackground(VDKRgb rgb);
00539 void SetForeground(VDKRgb rgb);
00540 void SetFont(VDKFont* font);
00541 void SetTitle(const char* title);
00542 const char* GetTitle();
00543 void SetWidth(int w);
00544 int GetWidth();
00545 void SetSortable(bool flag);
00546 bool GetSortable();
00547 };
00548
00549 typedef VDKList<VDKTreeViewColumn> VDKTreeViewColumnList;
00550 typedef VDKListIterator<VDKTreeViewColumn> VDKTreeViewColumnListIterator;
00551
00552 class VDKTreeViewIter: public GtkTreeIter
00553 {
00554 public:
00555 bool operator==(VDKTreeViewIter& i) { return false; }
00556 bool operator<(VDKTreeViewIter& i) { return false; }
00557 };
00558
00559 typedef VDKArray<VDKTreeViewIter> VDKTreeViewIterArray;
00560 typedef VDKValueList<VDKTreeViewIter> VDKTreeViewIterList;
00561 typedef VDKValueListIterator<VDKTreeViewIter> VDKTreeViewIterListIterator;
00562
00568 class VDKTreeView: public VDKObject
00569 {
00570 private:
00571 GtkTreeSelection *selection;
00572 VDKTreeViewColumnList *columns;
00573 VDKTreeViewIterList selections;
00574
00575 protected:
00576
00577 public:
00581 VDKReadWriteValueProp<VDKTreeView,VDKTreeViewModel*> Model;
00585 VDKReadOnlyValueProp<VDKTreeView,int> SelectedColumn;
00597 VDKTreeView(VDKForm* owner ,
00598 VDKTreeViewModel* model = NULL,
00599 GtkSelectionMode mode = GTK_SELECTION_SINGLE);
00603 ~VDKTreeView();
00604
00608 void SetModel(VDKTreeViewModel* model);
00609
00613 VDKTreeViewColumnList * Columns() { return columns; }
00617 void GetSelections();
00623 VDKTreeViewIterList &Selections() { return selections; }
00628 void SelectNode(GtkTreeIter* iter);
00633 void UnselectNode(GtkTreeIter* iter);
00639 void Expand(GtkTreeIter* iter = NULL, bool expand_all = false);
00643 void RemoveSelected(void);
00644 #ifdef USE_SIGCPLUSPLUS
00645
00658 VDKSignal3< void, GtkTreeIter*, int , char* > OnCellEdited;
00672 VDKSignal3< void, GtkTreeIter*, int, bool> OnCellToggled;
00673 #endif
00674 };
00675
00676 #endif
00677
00678
00679
00680