src/contrib/gtk-config-store.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 02 Oct 2008 14:57:39 +0200
changeset 3723 b663cbec7661
parent 3613 4925c4225148
child 3724 53be615ed881
permissions -rw-r--r--
change button label to be more explicit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
#include "gtk-config-store.h"
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
#include "attribute-iterator.h"
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
#include "ns3/config.h"
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
#include "ns3/string.h"
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
     5
#include "ns3/pointer.h"
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
     6
#include "ns3/log.h"
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
#include <gtk/gtk.h>
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
#include <fstream>
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
namespace ns3 {
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    13
NS_LOG_COMPONENT_DEFINE ("GtkconfigStore");
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    14
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
enum {
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    16
  COL_NODE = 0,
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
  COL_LAST
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
};
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    20
struct ModelNode
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
{
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    22
  enum {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    23
    // store object + attribute name
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    24
    NODE_ATTRIBUTE,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    25
    // store object + attribute name
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    26
    NODE_POINTER,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    27
    // store object + attribute name
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    28
    NODE_VECTOR,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    29
    // store index + value (object)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    30
    NODE_VECTOR_ITEM,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    31
    // store object
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    32
    NODE_OBJECT
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    33
  } type;
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
  std::string name;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
  Ptr<Object> object;
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    36
  uint32_t index;
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
};
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
class ModelCreator : public AttributeIterator
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
{
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
public:
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
  ModelCreator ();
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
  void Build (GtkTreeStore *treestore);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
private:
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    46
  virtual void DoVisitAttribute (Ptr<Object> object, std::string name);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    47
  virtual void DoStartVisitObject (Ptr<Object> object);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    48
  virtual void DoEndVisitObject (void);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    49
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    50
  virtual void DoEndVisitPointerAttribute (void);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    51
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    52
  virtual void DoEndVisitArrayAttribute (void);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    53
  virtual void DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    54
  virtual void DoEndVisitArrayItem (void);
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    55
  void Add (ModelNode *node);
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    56
  void Remove (void);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
  GtkTreeStore *m_treestore;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
  std::vector<GtkTreeIter *> m_iters;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
};
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
ModelCreator::ModelCreator ()
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
{}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
void 
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
ModelCreator::Build (GtkTreeStore *treestore)
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
{
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
  m_treestore = treestore;
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
    68
  m_iters.push_back (0);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
  Iterate ();
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
  NS_ASSERT (m_iters.size () == 1);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
}
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    72
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    73
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    74
void
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    75
ModelCreator::Add (ModelNode *node)
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
{
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
  GtkTreeIter *parent = m_iters.back ();
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
  gtk_tree_store_append (m_treestore, current, parent);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
  gtk_tree_store_set (m_treestore, current,
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    81
		      COL_NODE, node,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    82
                     -1);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    83
  m_iters.push_back (current);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    84
}
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    85
void
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    86
ModelCreator::Remove (void)
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    87
{
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    88
  GtkTreeIter *iter = m_iters.back ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    89
  g_free (iter);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    90
  m_iters.pop_back ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
    91
}
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    92
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    93
void 
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    94
ModelCreator::DoVisitAttribute (Ptr<Object> object, std::string name)
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    95
{
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    96
  ModelNode *node = new ModelNode ();
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    97
  node->type = ModelNode::NODE_ATTRIBUTE;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    98
  node->object = object;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
    99
  node->name = name;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   100
  Add (node);
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   101
  Remove ();
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   102
}
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   103
void 
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   104
ModelCreator::DoStartVisitObject (Ptr<Object> object)
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   105
{
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   106
  ModelNode *node = new ModelNode ();
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   107
  node->type = ModelNode::NODE_OBJECT;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   108
  node->object = object;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   109
  Add (node);
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   110
}
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   111
void 
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   112
ModelCreator::DoEndVisitObject (void)
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   113
{
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   114
  Remove ();
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   115
}
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   116
void 
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   117
ModelCreator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   118
{
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   119
  ModelNode *node = new ModelNode ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   120
  node->type = ModelNode::NODE_POINTER;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   121
  node->object = object;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   122
  node->name = name;
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   123
  Add (node);
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   124
}
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   125
void 
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   126
ModelCreator::DoEndVisitPointerAttribute (void)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   127
{
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   128
  Remove ();
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   129
}
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   130
void 
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   131
ModelCreator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   132
{
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   133
  ModelNode *node = new ModelNode ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   134
  node->type = ModelNode::NODE_VECTOR;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   135
  node->object = object;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   136
  node->name = name;
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   137
  Add (node);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
void 
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   140
ModelCreator::DoEndVisitArrayAttribute (void)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   141
{
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   142
  Remove ();
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   143
}
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   144
void 
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   145
ModelCreator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
{
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   147
  GtkTreeIter *parent = m_iters.back ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   148
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   149
  ModelNode *node = new ModelNode ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   150
  node->type = ModelNode::NODE_VECTOR_ITEM;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   151
  node->object = item;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   152
  node->index = index;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   153
  gtk_tree_store_append (m_treestore, current, parent);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   154
  gtk_tree_store_set (m_treestore, current,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   155
		      COL_NODE, node,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   156
                     -1);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   157
  m_iters.push_back (current);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   158
}
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   159
void 
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   160
ModelCreator::DoEndVisitArrayItem (void)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   161
{
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   162
  GtkTreeIter *iter = m_iters.back ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   163
  g_free (iter);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   164
  m_iters.pop_back ();  
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
static void
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   168
cell_data_function_col_1 (GtkTreeViewColumn *col,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   169
			  GtkCellRenderer   *renderer,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   170
			  GtkTreeModel      *model,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   171
			  GtkTreeIter       *iter,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   172
			  gpointer           user_data)
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
{
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   174
  ModelNode *node;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   175
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   176
  if (node->type == ModelNode::NODE_ATTRIBUTE)
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
    {
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
      StringValue str;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
      node->object->GetAttribute (node->name, str);
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   180
      g_object_set(renderer, "text", str.Get ().c_str (), (char*)0);
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   181
      g_object_set(renderer, "editable", TRUE, (char*)0);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
    }
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
  else
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
    {
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   185
      g_object_set(renderer, "text", "", (char*)0);
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   186
      g_object_set(renderer, "editable", FALSE, (char*)0);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
    }
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
static void
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   191
cell_data_function_col_0 (GtkTreeViewColumn *col,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   192
			  GtkCellRenderer   *renderer,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   193
			  GtkTreeModel      *model,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   194
			  GtkTreeIter       *iter,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   195
			  gpointer           user_data)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   196
{
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   197
  ModelNode *node;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   198
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   199
  g_object_set (renderer, "editable", FALSE, (char*)0);
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   200
  switch (node->type) {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   201
  case ModelNode::NODE_OBJECT:
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   202
    g_object_set(renderer, "text", node->object->GetInstanceTypeId ().GetName ().c_str (), (char*)0);
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   203
    break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   204
  case ModelNode::NODE_POINTER:
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   205
    g_object_set(renderer, "text", node->name.c_str (), (char*)0);
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   206
    break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   207
  case ModelNode::NODE_VECTOR:
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   208
    g_object_set(renderer, "text", node->name.c_str (), (char*)0);
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   209
    break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   210
  case ModelNode::NODE_VECTOR_ITEM: {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   211
    std::stringstream oss;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   212
    oss << node->index;
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   213
    g_object_set(renderer, "text", oss.str ().c_str (), (char*)0);
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   214
  } break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   215
  case ModelNode::NODE_ATTRIBUTE:
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   216
    g_object_set(renderer, "text", node->name.c_str (), (char*)0);
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   217
    break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   218
  }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   219
}
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   220
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   221
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   222
static void
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
cell_edited_callback (GtkCellRendererText *cell,
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
		      gchar               *path_string,
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
		      gchar               *new_text,
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
		      gpointer             user_data)
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
{
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
  GtkTreeModel *model = GTK_TREE_MODEL (user_data);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   229
  GtkTreeIter iter;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   230
  gtk_tree_model_get_iter_from_string (model, &iter, path_string);
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   231
  ModelNode *node;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   232
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   233
  NS_ASSERT (node->type == ModelNode::NODE_ATTRIBUTE);
3078
22756d7f8bb5 re-enable editing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3077
diff changeset
   234
  node->object->SetAttribute (node->name, StringValue (new_text));
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   235
}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   236
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   237
static int
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   238
get_col_number_from_tree_view_column (GtkTreeViewColumn *col)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   239
{
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   240
  GList *cols;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   241
  int   num;
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   242
  g_return_val_if_fail ( col != 0, -1 );
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   243
  g_return_val_if_fail ( col->tree_view != 0, -1 );
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   244
  cols = gtk_tree_view_get_columns(GTK_TREE_VIEW(col->tree_view));
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   245
  num = g_list_index(cols, (gpointer) col);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   246
  g_list_free(cols);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   247
  return num;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   248
}
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   249
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   250
static gboolean
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   251
cell_tooltip_callback (GtkWidget  *widget,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   252
		       gint        x,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   253
		       gint        y,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   254
		       gboolean    keyboard_tip,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   255
		       GtkTooltip *tooltip,
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   256
		       gpointer    user_data)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   257
{
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   258
  GtkTreeModel *model;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   259
  GtkTreeIter iter;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   260
  GtkTreeViewColumn * column;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   261
  if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), 
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   262
					  &x, &y, keyboard_tip,
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   263
					  &model, 0, &iter))
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   264
    {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   265
      return FALSE;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   266
    }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   267
  if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   268
				      x, y, 0, &column, 0, 0))
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   269
    {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   270
      return FALSE;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   271
    }  
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   272
  int col = get_col_number_from_tree_view_column (column);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   273
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   274
  ModelNode *node;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   275
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   276
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   277
  switch (node->type) {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   278
  case ModelNode::NODE_OBJECT:
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   279
    if (col == 0)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   280
      {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   281
	std::string tip = "This object is of type " + node->object->GetInstanceTypeId ().GetName ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   282
	gtk_tooltip_set_text (tooltip, tip.c_str ());
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   283
	return TRUE;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   284
      }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   285
    break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   286
  case ModelNode::NODE_POINTER:
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   287
    if (col == 0)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   288
      {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   289
	PointerValue ptr;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   290
	node->object->GetAttribute (node->name, ptr);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   291
	std::string tip = "This object is of type " + ptr.GetObject ()->GetInstanceTypeId ().GetName ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   292
	gtk_tooltip_set_text (tooltip, tip.c_str ());
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   293
	return TRUE;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   294
      }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   295
    break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   296
  case ModelNode::NODE_VECTOR:
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   297
    break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   298
  case ModelNode::NODE_VECTOR_ITEM:
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   299
    if (col == 0)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   300
      {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   301
	std::string tip = "This object is of type " + node->object->GetInstanceTypeId ().GetName ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   302
	gtk_tooltip_set_text (tooltip, tip.c_str ());
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   303
	return TRUE;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   304
      }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   305
    break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   306
  case ModelNode::NODE_ATTRIBUTE: {
3096
dc8b5959ab61 fix optimized build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3078
diff changeset
   307
    uint32_t attrIndex = 0;
3072
c513d4411cc8 also handle parent attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3069
diff changeset
   308
    TypeId tid;
c513d4411cc8 also handle parent attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3069
diff changeset
   309
    for (tid = node->object->GetInstanceTypeId (); tid.HasParent (); tid = tid.GetParent ())
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   310
      {
3072
c513d4411cc8 also handle parent attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3069
diff changeset
   311
	for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   312
	  {
3072
c513d4411cc8 also handle parent attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3069
diff changeset
   313
	    if (tid.GetAttributeName (i) == node->name)
c513d4411cc8 also handle parent attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3069
diff changeset
   314
	      {
c513d4411cc8 also handle parent attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3069
diff changeset
   315
		attrIndex = i;
c513d4411cc8 also handle parent attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3069
diff changeset
   316
		goto out;
c513d4411cc8 also handle parent attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3069
diff changeset
   317
	      }
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   318
	  }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   319
      }
3072
c513d4411cc8 also handle parent attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3069
diff changeset
   320
    out:
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   321
    if (col == 0)
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   322
      {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   323
	std::string tip = tid.GetAttributeHelp (attrIndex);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   324
	gtk_tooltip_set_text (tooltip, tip.c_str ());
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   325
      }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   326
    else
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   327
      {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   328
	Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (attrIndex);
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   329
	std::string tip;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   330
	tip = "This attribute is of type " + checker->GetValueTypeName ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   331
	if (checker->HasUnderlyingTypeInformation ())
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   332
	  {
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   333
	    tip += " " + checker->GetUnderlyingTypeInformation ();
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   334
	  }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   335
	gtk_tooltip_set_text (tooltip, tip.c_str ());
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   336
      }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   337
    return TRUE;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   338
  } break;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   339
  }
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   340
  return FALSE;
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   341
}
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   342
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   343
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   344
static GtkWidget *
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   345
create_view (GtkTreeStore *model)
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   346
{
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   347
  GtkTreeViewColumn   *col;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   348
  GtkCellRenderer     *renderer;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   349
  GtkWidget           *view;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   350
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   351
  view = gtk_tree_view_new();
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   352
  g_object_set (view, "has-tooltip", TRUE, (char*)0);
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   353
  g_signal_connect (view, "query-tooltip", (GCallback) cell_tooltip_callback, 0);
3069
4730d8d6d63c make the iteration code more flexible. add tooltips to gtk config store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3068
diff changeset
   354
  
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   355
  gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_BOTH);
3067
2a2f4760af4d add scroll area and alternating row colors.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3063
diff changeset
   356
  gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   357
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   358
  col = gtk_tree_view_column_new();
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   359
  gtk_tree_view_column_set_title(col, "Object Attributes");
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   360
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   361
  renderer = gtk_cell_renderer_text_new ();
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   362
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   363
  gtk_tree_view_column_set_cell_data_func(col, renderer, cell_data_function_col_0, 0, 0);
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   364
  g_object_set(renderer, "editable", FALSE, (char*)0);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   365
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   366
  col = gtk_tree_view_column_new();
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   367
  gtk_tree_view_column_set_title(col, "Attribute Value");
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   368
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   369
  renderer = gtk_cell_renderer_text_new();
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   370
  g_signal_connect(renderer, "edited", (GCallback) cell_edited_callback, model);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   371
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   372
  gtk_tree_view_column_set_cell_data_func(col, renderer, cell_data_function_col_1, 0, 0);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   373
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   374
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   375
  gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL (model));
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   376
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   377
  g_object_unref(model); /* destroy model automatically with view */
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   378
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   379
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   380
  return view;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   381
}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   382
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   383
static void
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   384
save_clicked (GtkButton *button,
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   385
	      gpointer   user_data)
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   386
{
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   387
  GtkWidget *parent_window = GTK_WIDGET (user_data);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   388
  GtkWidget *dialog;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   389
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   390
  dialog = gtk_file_chooser_dialog_new ("Save File",
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   391
					GTK_WINDOW (parent_window),
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   392
					GTK_FILE_CHOOSER_ACTION_SAVE,
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   393
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   394
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   395
					(char *)0);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   396
  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   397
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   398
  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "config.txt");
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   399
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   400
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   401
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   402
    {
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   403
      char *filename;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   404
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   405
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   406
      std::ofstream os;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   407
      os.open (filename);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   408
      TextFileAttributeIterator file = TextFileAttributeIterator (os);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   409
      file.Save ();
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   410
      os.close ();
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   411
      g_free (filename);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   412
    }
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   413
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   414
  gtk_widget_destroy (dialog);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   415
}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   416
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   417
static void
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   418
load_clicked (GtkButton *button,
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   419
	      gpointer   user_data)
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   420
{
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   421
  GtkWidget *parent_window = GTK_WIDGET (user_data);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   422
  GtkWidget *dialog;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   423
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   424
  dialog = gtk_file_chooser_dialog_new ("Open File",
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   425
					GTK_WINDOW (parent_window),
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   426
					GTK_FILE_CHOOSER_ACTION_OPEN,
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   427
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   428
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   429
					(char *)0);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   430
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   431
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   432
    {
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   433
      char *filename;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   434
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   435
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   436
      std::ifstream is;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   437
      is.open (filename, std::ios::in);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   438
      std::string path, value;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   439
      while (is.good())
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   440
	{
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   441
	  is >> path >> value;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   442
	  Config::Set (path, StringValue (value));
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   443
	}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   444
      g_free (filename);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   445
    }
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   446
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   447
  gtk_widget_destroy (dialog);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   448
}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   449
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   450
static void 
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   451
exit_clicked_callback (GtkButton *button,
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   452
		       gpointer   user_data)
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   453
{
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   454
  gtk_main_quit ();
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   455
}
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   456
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   457
static gboolean
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   458
delete_event_callback (GtkWidget *widget,
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   459
		       GdkEvent  *event,
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   460
		       gpointer   user_data)
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   461
{
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   462
  gtk_main_quit ();
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   463
  return TRUE;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   464
}
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   465
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   466
static gboolean 
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   467
clean_model_callback (GtkTreeModel *model,
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   468
		      GtkTreePath *path,
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   469
		      GtkTreeIter *iter,
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   470
		      gpointer data)
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   471
{
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   472
  ModelNode *node;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   473
  gtk_tree_model_get (GTK_TREE_MODEL (model), iter, 
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   474
		      COL_NODE, &node, 
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   475
		      -1);
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   476
  delete node;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   477
  gtk_tree_store_set (GTK_TREE_STORE (model), iter,
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   478
		      COL_NODE, (ModelNode*)0,
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   479
		      -1);
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   480
  return FALSE;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   481
}
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   482
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   483
GtkConfigStore::GtkConfigStore ()
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   484
{}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   485
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   486
void 
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   487
GtkConfigStore::Configure (void)
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   488
{
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   489
  GtkWidget *window;
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   490
  GtkWidget *view;
3067
2a2f4760af4d add scroll area and alternating row colors.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3063
diff changeset
   491
  GtkWidget *scroll;
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   492
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   493
  gtk_init (0, 0);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   494
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   495
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3068
95ea2e729bf5 set a default window size.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3067
diff changeset
   496
  gtk_window_set_title (GTK_WINDOW (window), "ns-3 Object attributes.");
95ea2e729bf5 set a default window size.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3067
diff changeset
   497
  gtk_window_set_default_size (GTK_WINDOW (window), 400, 600);
95ea2e729bf5 set a default window size.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3067
diff changeset
   498
  
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   499
  g_signal_connect (window, "delete_event", (GCallback)delete_event_callback, 0);
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   500
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   501
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   502
  GtkTreeStore *model = gtk_tree_store_new (COL_LAST, G_TYPE_POINTER);
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   503
  ModelCreator creator;
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   504
  creator.Build (model);
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   505
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   506
  view = create_view (model);
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   507
  scroll = gtk_scrolled_window_new (0, 0);
3067
2a2f4760af4d add scroll area and alternating row colors.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3063
diff changeset
   508
  gtk_container_add (GTK_CONTAINER (scroll), view);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   509
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   510
  GtkWidget *vbox = gtk_vbox_new (FALSE, 5);
3067
2a2f4760af4d add scroll area and alternating row colors.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3063
diff changeset
   511
  gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   512
  gtk_box_pack_end (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 0);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   513
  GtkWidget *hbox = gtk_hbox_new (FALSE, 5);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   514
  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   515
  GtkWidget *save = gtk_button_new_with_label ("Save");
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   516
  g_signal_connect (save, "clicked",  (GCallback) save_clicked, window);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   517
  gtk_box_pack_end (GTK_BOX (hbox), save, FALSE, FALSE, 0);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   518
  GtkWidget *load = gtk_button_new_with_label ("Load");
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   519
  g_signal_connect (load, "clicked",  (GCallback) load_clicked, window);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   520
  gtk_box_pack_end (GTK_BOX (hbox), load, FALSE, FALSE, 0);
3723
b663cbec7661 change button label to be more explicit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3613
diff changeset
   521
  GtkWidget *exit = gtk_button_new_with_label ("Run Simulation");
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   522
  g_signal_connect (exit, "clicked",  (GCallback) exit_clicked_callback, 0);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   523
  gtk_box_pack_end (GTK_BOX (hbox), exit, FALSE, FALSE, 0);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   524
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   525
  gtk_container_add (GTK_CONTAINER (window), vbox);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   526
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   527
  gtk_widget_show_all (window);
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   528
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   529
  gtk_main ();
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   530
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   531
  gtk_tree_model_foreach (GTK_TREE_MODEL (model), 
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   532
			  clean_model_callback, 
3613
4925c4225148 bug 309: GtkConfigStore does not build on freebsd.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3096
diff changeset
   533
			  0);
3077
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   534
e8c8430359c6 cleanup the model memory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3072
diff changeset
   535
  gtk_widget_destroy (window);
3063
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   536
}
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   537
a1c532e3bf18 a basic but useful Gtk+-based config-store
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   538
} // namespace ns3