]> git.llucax.com Git - z.facultad/75.52/treemulator.git/blob - viewer/view_node.cpp
Paso el block_data a BTree en lugar de Clave.
[z.facultad/75.52/treemulator.git] / viewer / view_node.cpp
1
2 #include "view_node.h"
3
4 ViewNode::ViewNode (Canvas::Group *parent, uint num, uint padre, BTreeNodeHeader &header, std::list<BTreeData *> &keys)
5         : Canvas::Group (*parent)
6 {
7         last_selected = NULL;
8         double header_w = ViewBTree::byte_to_pixels * sizeof (BTreeNodeHeader);
9         this->num = num;
10         this->padre = padre;
11
12         /* Fondo */
13         int w1 = (int)(ViewBTree::node_width / 512.0f);
14         int used_width = 0;
15
16         double y = 0;
17
18         /* Header */
19         Canvas::Rect *h = new Canvas::Rect (*this, 0, 0, header_w, ViewBTree::node_height);
20         h->property_fill_color() = "blue";
21         h->property_outline_color() = "black";
22
23         /* Numero de nodo */
24         std::string node_num;
25         std::stringstream ss;
26         ss << num;
27         ss >> node_num;
28         new Canvas::Text (*this, header_w/2, ViewBTree::node_height/2, node_num);
29
30         double x = header_w;
31         y = 0;
32
33         std::list<BTreeData *>::iterator it = keys.begin ();
34         while (it != keys.end ()) {
35                 BTreeData *data = (*it);
36                 double w = ViewBTree::byte_to_pixels * data->Size ();
37
38                 ViewBTreeData *v = ViewBTreeData::Create (data, this, x, y, w+x, y+ViewBTree::node_height);
39                 v->signal_clicked ().connect ( sigc::mem_fun (this , &ViewNode::on_item_clicked ));
40                 v->signal_double_clicked ().connect ( sigc::mem_fun (this , &ViewNode::on_item_activated ));
41                 x += w;
42                 used_width += w;
43                 if (x >= 512) {
44                         x = 0;
45                         y += ViewBTree::node_height + 5;
46                 }
47                 it++;
48
49                 datas.push_back (v);
50
51                 if (!dynamic_cast<BTreeLeafData *>(data)) {
52                         /* Si no es un dato de una hoja, tiene hijos */
53                         hijos.push_back (data->GetChild ());
54                 }
55         }
56         w1 = ViewBTree::node_width - used_width;
57         if (w1 > 0) {
58                 fondo = new Canvas::Rect (*this, x, y, x+w1, ViewBTree::node_height+y);
59                 fondo->property_fill_color() = "gray";
60                 fondo->property_outline_color() = "black";
61         }
62 }
63
64 void ViewNode::on_item_clicked (BTreeData *data, ViewBTreeData *s)
65 {
66         if (last_selected)
67                 if (s != last_selected)
68                         last_selected->SetSelected (false);
69         last_selected = s;
70         m_signal_selected (data, num, this);
71 }
72
73 void ViewNode::on_item_activated (BTreeData *data, ViewBTreeData *s)
74 {
75         /* Solo activo los que tienen hijos */
76         if (dynamic_cast<BTreeLeafData *> (data) == NULL)
77                 m_signal_activated (data, num, this);
78 }
79
80 ViewNode::type_signal_selected ViewNode::signal_selected ()
81 {
82         return m_signal_selected;
83 }
84
85 ViewNode::type_signal_activated ViewNode::signal_activated ()
86 {
87         return m_signal_activated;
88 }
89
90 void ViewNode::SetSelected (bool b)
91 {
92         if (last_selected) {
93                 last_selected->SetSelected (b);
94         }
95 }
96
97 void ViewNode::HighliteKey (Clave &k)
98 {
99         std::list<ViewBTreeData *>::iterator it;
100
101         it = datas.begin ();
102         while (it != datas.end ()) {
103                 if ((*(*it)) == k) {
104                         if (last_selected)
105                                 last_selected->SetSelected (false);
106                         last_selected = *it;
107                         last_selected->SetSelected (true);
108                 }
109                 it++;
110         }
111 }
112