#include "view_btree.h"
#include "view_btree_data.h"
-
+#include <sigc++/slot.h>
+
double ViewBTree::byte_to_pixels = 0;
ViewBTree::ViewBTree (Canvas::Group *parent, std::string filename):Canvas::Group (*parent, 0, 0),
vnode->property_y () = y;
vnode->property_x () = pos_x[node_h.level];
pos_x[node_h.level] += NODE_WIDTH+10;
+ vnode->signal_selected().connect ( sigc::mem_fun (*this, &ViewBTree::on_item_selected) );
std::list<uint> childs = vnode->getChilds ();
std::list<uint>::iterator hit = childs.begin ();
}
}
+void ViewBTree::on_item_selected (BTreeData *data, uint num)
+{
+ BTreeNodeHeader node_h;
+ uchar *node;
+
+ node = ReadBlock (num);
+ ReadNodoHeader (node, &node_h);
+ delete [] node;
+
+ std::cout << "Emit SignalSelected" << std::endl;
+ m_signal_selected (data, node_h);
+}
+
+ViewBTree::type_signal_selected ViewBTree::signal_selected ()
+{
+ return m_signal_selected;
+}
+
ViewNode::ViewNode (Canvas::Group *parent, uint num, BTreeNodeHeader &header, std::list<BTreeData *> &keys)
: Canvas::Group (*parent)
{
double header_w = ViewBTree::byte_to_pixels * sizeof (BTreeNodeHeader);
+ this->num = num;
/* Fondo */
Canvas::Rect *fondo = new Canvas::Rect (*this, 0, 0, NODE_WIDTH, NODE_HEIGHT);
double w = ViewBTree::byte_to_pixels * data->Size ();
ViewBTreeData *v = ViewBTreeData::Create (data, this, x, 0, w+x, NODE_HEIGHT);
-
+ v->signal_clicked ().connect ( sigc::mem_fun (this , &ViewNode::on_item_clicked ));
x += w;
it++;
}
}
+void ViewNode::on_item_clicked (BTreeData *data)
+{
+ m_signal_selected (data, num);
+}
+
+ViewNode::type_signal_selected ViewNode::signal_selected ()
+{
+ return m_signal_selected;
+}
+
ViewBTree (Canvas::Group *parent, std::string filename);
static double byte_to_pixels;
+
+ typedef SigC::Signal2<void, BTreeData *, BTreeNodeHeader&> type_signal_selected;
+ type_signal_selected signal_selected ();
protected:
+ type_signal_selected m_signal_selected;
int max_level; /* Lo saco de la raiz */
/* Posicion X por nivel */
std::map<uint,double> pos_x;
std::map<uint,bool> node_placed;
void AddNode (uint num);
+ void on_item_selected (BTreeData *, uint);
};
ViewNode (Canvas::Group *parent, uint num, BTreeNodeHeader &header, std::list<BTreeData *> &keys);
std::list<uint>& getChilds () { return hijos; }
+
+ typedef SigC::Signal2<void, BTreeData *, uint> type_signal_selected;
+ type_signal_selected signal_selected ();
private:
+ void on_item_clicked (BTreeData *data);
std::list<uint> hijos;
+ type_signal_selected m_signal_selected;
+ uint num;
};
#endif
double h = property_y2() - property_y1();
std::string s = *data;
- Canvas::Text *text = new Canvas::Text (*parent, property_x1()+w/2, h/2, s);
+ new Canvas::Text (*parent, property_x1()+w/2, h/2, s);
+}
+
+bool ViewBTreeData::on_event (GdkEvent *p1)
+{
+ switch (p1->type) {
+ case GDK_BUTTON_PRESS:
+ m_signal_clicked(data);
+ }
+
+ return Canvas::Rect::on_event (p1);
}
+ViewBTreeData::type_signal_clicked ViewBTreeData::signal_clicked ()
+{
+ return m_signal_clicked;
+}
+
ViewBTreeData*
ViewBTreeData::Create (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2)
{
#include <libgnomecanvasmm.h>
#include <string>
+#include <gtkmm/button.h>
#include "btree.h"
#include "btree_data.h"
class ViewBTreeData :public Canvas::Rect {
public:
ViewBTreeData (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2);
+ virtual ~ViewBTreeData () {}
static ViewBTreeData *Create (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2);
+ typedef SigC::Signal1<void, BTreeData *> type_signal_clicked;
+ type_signal_clicked signal_clicked ();
+
protected:
+ type_signal_clicked m_signal_clicked;
+
virtual void init (Canvas::Group *parent);
BTreeData *data;
+
+ virtual bool on_event (GdkEvent *p1);
};
class ViewBTreeChildData :public ViewBTreeData {
public:
ViewBTreeChildData (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2);
+ virtual ~ViewBTreeChildData () {}
protected:
virtual void init (Canvas::Group *parent);