]> git.llucax.com Git - z.facultad/75.52/treemulator.git/commitdiff
Algo de Signals para pasar eventos.
authorRicardo Markiewicz <rmarkie@fi.uba.ar>
Sun, 25 Sep 2005 02:04:54 +0000 (02:04 +0000)
committerRicardo Markiewicz <rmarkie@fi.uba.ar>
Sun, 25 Sep 2005 02:04:54 +0000 (02:04 +0000)
viewer/view_btree.cpp
viewer/view_btree.h
viewer/view_btree_data.cpp
viewer/view_btree_data.h

index 5c54a874f174304d7f39c755881b7d54b6be8ff8..4fb08394351c2372693b743cc2667e424986f6ef 100644 (file)
@@ -1,7 +1,8 @@
 
 #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),
@@ -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<uint> childs = vnode->getChilds ();
        std::list<uint>::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<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);
@@ -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;
+}
+
index e3a5c688268e52dab36b12e4cb7059415c9b3ac9..8227609835b0ff2233398f2cc3432b63be937453 100644 (file)
@@ -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<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;
@@ -26,6 +30,7 @@ class ViewBTree : public Canvas::Group, public BTree {
                std::map<uint,bool> 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<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
index a98c30eb79f0b2cd6bf24091e9ad275bf91539a9..04889ccbdca9ba092fe104c7002ce526731c0dcb 100644 (file)
@@ -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)
 {
index 4020b3f68029fb4b2ac36e9329fe02d294548baf..1af3866be6a9340f0a2a9e4f68ef443f0694f113 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <libgnomecanvasmm.h>
 #include <string>
+#include <gtkmm/button.h>
 
 #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<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);