00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TREE_H
00023 #define TREE_H
00024
00025 #include "treeitem.h"
00026 #include "widget.h"
00027
00028 #include <list>
00029 #include <cwidget/generic/util/eassert.h>
00030
00031 namespace cwidget
00032 {
00033 namespace config
00034 {
00035 class keybindings;
00036 }
00037
00038 namespace widgets
00039 {
00040
00041 class tree_search_func
00042 {
00043 public:
00044 virtual bool operator()(const treeitem &item)=0;
00045 virtual ~tree_search_func() {}
00046 };
00047
00048 class tree_search_string:public tree_search_func
00049 {
00050 std::wstring s;
00051 public:
00052 tree_search_string(const std::wstring &_s):s(_s) {}
00053
00054 virtual bool operator()(const treeitem &item);
00055 };
00056
00057 class tree : public widget
00058 {
00059 treeitem *root;
00060 treeiterator begin, end;
00061
00062 treeiterator top;
00063 treeiterator selected;
00064
00065
00066
00067
00068 bool hierarchical;
00069
00070
00071
00072
00073
00074
00075
00076 struct flat_frame
00077 {
00078 treeiterator begin, end, top, selected;
00079
00080 flat_frame *next;
00081 flat_frame(treeiterator _begin,
00082 treeiterator _end,
00083 treeiterator _top,
00084 treeiterator _selected,
00085 flat_frame *_next)
00086 :begin(_begin), end(_end), top(_top), selected(_selected), next(_next) {}
00087 };
00088 flat_frame *prev_level;
00089
00090 int line_of(treeiterator item);
00091 bool item_visible(treeiterator item);
00092
00093 void do_shown();
00094 protected:
00095 void sync_bounds();
00096
00097
00098
00099
00100
00101 virtual bool handle_key(const config::key &k);
00102
00103 protected:
00104 tree();
00105 tree(treeitem *_root, bool showroot);
00106
00107 public:
00108 static util::ref_ptr<tree>
00109 create()
00110 {
00111 util::ref_ptr<tree> rval(new tree);
00112 rval->decref();
00113 return rval;
00114 }
00115
00116 static util::ref_ptr<tree>
00117 create(treeitem *root, bool showroot = false)
00118 {
00119 util::ref_ptr<tree> rval(new tree(root, showroot));
00120 rval->decref();
00121 return rval;
00122 }
00123
00124 void set_root(treeitem *_root, bool showroot=false);
00125
00127 int width_request();
00128
00133 int height_request(int w);
00134
00135 bool get_cursorvisible();
00136 point get_cursorloc();
00137 virtual bool focus_me() {return true;}
00138 virtual void paint(const style &st);
00139 virtual void dispatch_mouse(short id, int x, int y, int z, mmask_t bstate);
00140
00150 void set_selection(treeiterator to, bool force_to_top = false);
00151
00158 treeiterator get_selection() const
00159 {
00160 return selected;
00161 }
00162
00164 treeiterator get_begin()
00165 {
00166 return begin;
00167 }
00168
00170 treeiterator get_end()
00171 {
00172 return end;
00173 }
00174
00175 virtual ~tree();
00176
00177 void search_for(tree_search_func &matches);
00178 void search_for(const std::wstring &s)
00179 {
00180 tree_search_string matches(s);
00181 search_for(matches);
00182 }
00183
00184 void search_back_for(tree_search_func &matches);
00185 void search_back_for(const std::wstring &s)
00186 {
00187 tree_search_string matches(s);
00188 search_back_for(matches);
00189 }
00190
00191 void set_hierarchical(bool _hierarchical);
00192 bool get_hierarchical() {return hierarchical;}
00193
00195 void highlight_current();
00196
00198 void unhighlight_current();
00199
00206 sigc::signal1<void, treeitem *> selection_changed;
00207
00208
00209 void line_up();
00210 void line_down();
00211 void page_up();
00212 void page_down();
00213 void jump_to_begin();
00214 void jump_to_end();
00215 void level_line_up();
00216 void level_line_down();
00217
00218 static config::keybindings *bindings;
00219 static void init_bindings();
00220
00221 };
00222
00223 typedef util::ref_ptr<tree> tree_ref;
00224 }
00225 }
00226
00227 #endif