From: Ricardo Markiewicz Date: Sun, 25 Sep 2005 02:04:54 +0000 (+0000) Subject: Algo de Signals para pasar eventos. X-Git-Tag: 1_0-pre1~104 X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/commitdiff_plain/84820a0fe02b9fdd63fb7c28d5a823bfa065c259?ds=sidebyside Algo de Signals para pasar eventos. --- diff --git a/viewer/view_btree.cpp b/viewer/view_btree.cpp index 5c54a87..4fb0839 100644 --- a/viewer/view_btree.cpp +++ b/viewer/view_btree.cpp @@ -1,7 +1,8 @@ #include "view_btree.h" #include "view_btree_data.h" - +#include + double ViewBTree::byte_to_pixels = 0; ViewBTree::ViewBTree (Canvas::Group *parent, std::string filename):Canvas::Group (*parent, 0, 0), @@ -48,6 +49,7 @@ void ViewBTree::AddNode (uint num) 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 childs = vnode->getChilds (); std::list::iterator hit = childs.begin (); @@ -62,10 +64,29 @@ void ViewBTree::AddNode (uint num) } } +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 &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); @@ -92,7 +113,7 @@ ViewNode::ViewNode (Canvas::Group *parent, uint num, BTreeNodeHeader &header, st 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++; @@ -103,3 +124,13 @@ ViewNode::ViewNode (Canvas::Group *parent, uint num, BTreeNodeHeader &header, st } } +void ViewNode::on_item_clicked (BTreeData *data) +{ + m_signal_selected (data, num); +} + +ViewNode::type_signal_selected ViewNode::signal_selected () +{ + return m_signal_selected; +} + diff --git a/viewer/view_btree.h b/viewer/view_btree.h index e3a5c68..8227609 100644 --- a/viewer/view_btree.h +++ b/viewer/view_btree.h @@ -17,7 +17,11 @@ class ViewBTree : public Canvas::Group, public BTree { ViewBTree (Canvas::Group *parent, std::string filename); static double byte_to_pixels; + + typedef SigC::Signal2 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 pos_x; @@ -26,6 +30,7 @@ class ViewBTree : public Canvas::Group, public BTree { std::map node_placed; void AddNode (uint num); + void on_item_selected (BTreeData *, uint); }; @@ -34,8 +39,14 @@ class ViewNode : public Canvas::Group { ViewNode (Canvas::Group *parent, uint num, BTreeNodeHeader &header, std::list &keys); std::list& getChilds () { return hijos; } + + typedef SigC::Signal2 type_signal_selected; + type_signal_selected signal_selected (); private: + void on_item_clicked (BTreeData *data); std::list hijos; + type_signal_selected m_signal_selected; + uint num; }; #endif diff --git a/viewer/view_btree_data.cpp b/viewer/view_btree_data.cpp index a98c30e..04889cc 100644 --- a/viewer/view_btree_data.cpp +++ b/viewer/view_btree_data.cpp @@ -17,10 +17,25 @@ void ViewBTreeData::init (Canvas::Group *parent) 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) { diff --git a/viewer/view_btree_data.h b/viewer/view_btree_data.h index 4020b3f..1af3866 100644 --- a/viewer/view_btree_data.h +++ b/viewer/view_btree_data.h @@ -4,6 +4,7 @@ #include #include +#include #include "btree.h" #include "btree_data.h" @@ -13,17 +14,26 @@ using namespace Gnome; 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 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);