2 #include "view_btree.h"
3 #include "view_btree_data.h"
4 #include <sigc++/slot.h>
6 double ViewBTree::byte_to_pixels = 0;
7 double ViewBTree::node_width = 0;
8 double ViewBTree::node_height = 0;
10 ViewBTree::ViewBTree (Canvas::Group *parent, std::string filename, uint block_size, int tree_type, int type):Canvas::Group (*parent, 0, 0),
11 BTree (filename, block_size, tree_type, type)
13 /* Cada bytes lo hago de 5 units de ancho */
14 node_width = 4 * block_size;
16 byte_to_pixels = node_width/block_size;
22 ViewBTree::ViewBTree (Canvas::Group *parent, const std::string filename)
23 :Canvas::Group (*parent, 0, 0), BTree (filename)
25 /* Cada bytes lo hago de 5 units de ancho */
26 node_width = 4 * header.block_size;
28 byte_to_pixels = node_width/header.block_size;
34 ViewBTree* ViewBTree::Open (Canvas::Group *parent, const std::string &filename)
36 ViewBTree *tree = new ViewBTree (parent, filename);
38 if (tree->fp == NULL) {
43 /* El magic no coincide!! */
44 if (strcmp (tree->header.magic, "DILUMA")) {
51 void ViewBTree::GoBack ()
60 void ViewBTree::AddNode (uint num, uint padre)
62 /* Hack de ultima hora :P */
64 /* evito quedar en circulo :D */
65 back.push (last_visited);
69 uchar *node = ReadBlock (num);
71 BTreeNodeHeader node_h;
72 ReadNodoHeader (node, &node_h);
74 std::list<BTreeData *> keys = ReadKeys (node, node_h);
76 ViewNode *vnode = new ViewNode (this, num, padre, node_h, keys);
77 vnode->property_y () = 10;
78 vnode->property_x () = 10;
80 vnode->signal_selected().connect ( sigc::mem_fun (*this, &ViewBTree::on_item_selected) );
81 vnode->signal_activated().connect ( sigc::mem_fun (*this, &ViewBTree::on_item_activated) );
83 last_selected = vnode;
86 void ViewBTree::on_item_activated (BTreeData *data, uint num, ViewNode *vnode)
90 uint next = data->GetChild ();
93 std::cout << next << std::endl;
97 void ViewBTree::on_item_selected (BTreeData *data, uint num, ViewNode *vnode)
99 BTreeNodeHeader node_h;
102 node = ReadBlock (num);
103 ReadNodoHeader (node, &node_h);
107 if (vnode != last_selected)
108 last_selected->SetSelected (false);
109 last_selected = vnode;
111 m_signal_selected (data, node_h);
114 ViewBTree::type_signal_selected ViewBTree::signal_selected ()
116 return m_signal_selected;
119 void ViewBTree::Clear ()
122 delete last_selected;
125 void ViewBTree::HighliteKey (Clave &k)
127 last_selected->HighliteKey (k);