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* Open (Canvas::Group *parent, const std::string &filename)
36 ViewBTree *tree = new ViewBTree (parent, filename);
38 if (tree->fp == NULL) {
46 void ViewBTree::GoBack ()
55 void ViewBTree::AddNode (uint num, uint padre)
57 /* Hack de ultima hora :P */
59 /* evito quedar en circulo :D */
60 back.push (last_visited);
64 uchar *node = ReadBlock (num);
66 BTreeNodeHeader node_h;
67 ReadNodoHeader (node, &node_h);
69 std::list<BTreeData *> keys = ReadKeys (node, node_h);
71 ViewNode *vnode = new ViewNode (this, num, padre, node_h, keys);
72 vnode->property_y () = 10;
73 vnode->property_x () = 10;
75 vnode->signal_selected().connect ( sigc::mem_fun (*this, &ViewBTree::on_item_selected) );
76 vnode->signal_activated().connect ( sigc::mem_fun (*this, &ViewBTree::on_item_activated) );
78 last_selected = vnode;
81 void ViewBTree::on_item_activated (BTreeData *data, uint num, ViewNode *vnode)
85 uint next = data->GetChild ();
88 std::cout << next << std::endl;
92 void ViewBTree::on_item_selected (BTreeData *data, uint num, ViewNode *vnode)
94 BTreeNodeHeader node_h;
97 node = ReadBlock (num);
98 ReadNodoHeader (node, &node_h);
102 if (vnode != last_selected)
103 last_selected->SetSelected (false);
104 last_selected = vnode;
106 m_signal_selected (data, node_h);
109 ViewBTree::type_signal_selected ViewBTree::signal_selected ()
111 return m_signal_selected;
114 void ViewBTree::Clear ()
117 delete last_selected;
120 void ViewBTree::HighliteKey (Clave &k)
122 last_selected->HighliteKey (k);