# HG changeset patch
# User ladanyi
# Date 1125041723 0
# Node ID dd8672338691f5686850a58ac7f6398b66f7e614
# Parent  d5dc956393b269da80a91e7079e93cae66a468d1
 - use Gtk::Dialog to set the new values of edge and node maps
 - update all edges/nodes when editing a map so that edge widths and node
   sizes change properly
 - coordinate maps are no longer selectable in the maps window

diff -r d5dc956393b2 -r dd8672338691 gui/graph_displayer_canvas-event.cc
--- a/gui/graph_displayer_canvas-event.cc	Tue Aug 23 16:27:59 2005 +0000
+++ b/gui/graph_displayer_canvas-event.cc	Fri Aug 26 07:35:23 2005 +0000
@@ -32,11 +32,6 @@
 	  //has to do the same thing as in the case of NODE_MAP_EDIT
 	case NODE_MAP_EDIT:
 	  {
-	    GdkEvent * generated=new GdkEvent();
-	    generated->type=GDK_KEY_PRESS;
-	    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
-	    entryWidgetChangeHandler(generated);
-	    entrywidget.hide();
 	    break;
 	  }
 	default:
@@ -548,316 +543,189 @@
 bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
 {
   if(actual_tool==EDGE_MAP_EDIT)
+  {
+    switch(e->type)
     {
-      switch(e->type)
-	{
-	case GDK_KEY_PRESS:
-	  //for Escape or Enter hide the displayed widget
-	  {
-	    nodeMapEditEventHandler(e);
-	    break;
-	  }
-	case GDK_BUTTON_PRESS:
-	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
-	  {
-	    //for determine, whether it was an edge
-	    Edge clicked_edge=INVALID;
+      case GDK_BUTTON_PRESS:
+        {
+          //for determine, whether it was an edge
+          Edge clicked_edge=INVALID;
 
-	    //find the activated item between texts
-            window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
-            active_item=(get_item_at(clicked_x, clicked_y));
-	    for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
-	      {
-		if(edgetextmap[i]==active_item)
-		  {
-		    clicked_edge=i;
-		  }
-	      }
+          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
+          active_item=(get_item_at(clicked_x, clicked_y));
 
-	    //if it was not between texts, search for it between edges
-	    if(clicked_edge==INVALID)
-	      {
-		for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
-		  {
-		    //at the same time only one can be active
-		    if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
-		      {
-			clicked_edge=i;
-		      }
-		  }
-	      }
-	    //if it was really an edge...
-	    if(clicked_edge!=INVALID)
-	      {
-                // the id map is not editable
-                if (edgemap_to_edit == "id") return 0;
+          //find the activated item between texts
+          for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
+          {
+            //at the same time only one can be active
+            if(edgetextmap[i]==active_item)
+            {
+              clicked_edge=i;
+            }
+          }
 
-		//If there is already edited edge, it has to be saved first
-		if(entrywidget.is_visible())
-		  {
-		    GdkEvent * generated=new GdkEvent();
-		    generated->type=GDK_KEY_PRESS;
-		    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
-		    entryWidgetChangeHandler(generated);
-		  }
-		//If the previous value could be saved, we can go further, otherwise not
-		if(!entrywidget.is_visible())
-		  {
-		    //and there is activated map
-		    if(edgetextmap[clicked_edge]->property_text().get_value()!="")
-		      {
-			//activate the general variable for it
-			active_edge=clicked_edge;
-			//delete visible widget if there is
-			if(canvasentrywidget)
-			  {
-			    delete(canvasentrywidget);
-			  }
+          //if it was not between texts, search for it between edges
+          if(clicked_edge==INVALID)
+          {
+            for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
+            {
+              //at the same time only one can be active
+              if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
+              {
+                clicked_edge=i;
+              }
+            }
+          }
+ 
+          //if it was really an edge...
+          if(clicked_edge!=INVALID)
+          {
+            // the id map is not editable
+            if (edgemap_to_edit == "id") return 0;
 
-			//initialize the entry
-			entrywidget.show();
+            //and there is activated map
+            if(edgetextmap[clicked_edge]->property_text().get_value()!="")
+            {
+              //activate the general variable for it
+              active_edge=clicked_edge;
 
-			//fill in the correct value
-			entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
-
-			//replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
-			xy<double> entry_coos;
-			entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
-			entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
-			entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
-			entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
-			canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
-			canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4);
-			canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
-
-			//setting the focus to newly created widget
-			parentwin->set_focus(entrywidget);
-			parentwin->activate_focus();
-		      }
-		  }
-	      }
-	    //if it was not an edge...
-	    else
-	      {
-		//In this case the click did not happen on an edge
-		//if there is visible entry we save the value in it
-		//we pretend like an Enter was presse din the Entry widget
-		GdkEvent * generated=new GdkEvent();
-		generated->type=GDK_KEY_PRESS;
-		((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
-		entryWidgetChangeHandler(generated);
-	      }
-	    break;
-	  }
-	default:
-	  break;
-	}
+              //create a dialog
+              Gtk::Dialog dialog("Edit value", *parentwin, true);
+              dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+              dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
+              Gtk::VBox* vbox = dialog.get_vbox();
+              Gtk::Adjustment adj(
+                  (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge],
+                  -1000000.0,
+                  1000000.0,
+                  1.0, 5.0, 0.0);
+              //TODO: find out why doesn't it work with
+              //numeric_limits<double>::min/max
+              Gtk::SpinButton spin(adj);
+              spin.set_numeric(true);
+              spin.set_digits(4);
+              vbox->add(spin);
+              spin.show();
+              switch (dialog.run())
+              {
+                case Gtk::RESPONSE_NONE:
+                case Gtk::RESPONSE_CANCEL:
+                  break;
+                case Gtk::RESPONSE_ACCEPT:
+                  double new_value = spin.get_value();
+                  (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge] =
+                    new_value;
+                  std::ostringstream ostr;
+                  ostr << new_value;
+                  edgetextmap[active_edge]->property_text().set_value(
+                      ostr.str());
+                  //mapwin.updateEdge(active_edge);
+                  mapwin.updateEdge(Edge(INVALID));
+              }
+            }
+          }
+          break;
+        }
+      default:
+        break;
     }
+  }
   return false;  
 }
 
 bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
 {
   if(actual_tool==NODE_MAP_EDIT)
+  {
+    switch(e->type)
     {
-      switch(e->type)
-	{
-	case GDK_KEY_PRESS:
-	  //for Escape or Enter hide the displayed widget
-	  {
-	    switch(((GdkEventKey*)e)->keyval)
-	      {
-	      case GDK_Escape:
-		entrywidget.hide();
-		break;
-	      case GDK_Return:
-	      case GDK_KP_Enter:
-		entrywidget.hide();
-		break;
-	      default:
-		break;
-	      }
-  
-	    break;
-	  }
-	case GDK_BUTTON_PRESS:
-	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
-	  {
-	    //for determine, whether it was a node
-	    Node clicked_node=INVALID;
+      case GDK_BUTTON_PRESS:
+        {
+          //for determine, whether it was a node
+          Node clicked_node=INVALID;
 
-	    //find the activated item between texts
-	    active_item=(get_item_at(e->button.x, e->button.y));
-	    for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
-	      {
-		//at the same time only one can be active
-		if(nodetextmap[i]==active_item)
-		  {
-		    clicked_node=i;
-		  }
-	      }
+          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
+          active_item=(get_item_at(clicked_x, clicked_y));
 
-	    //if there was not, search for it between nodes
-	    if(clicked_node==INVALID)
-	      {
-		window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
-		active_item=(get_item_at(clicked_x, clicked_y));
+          //find the activated item between texts
+          for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
+          {
+            //at the same time only one can be active
+            if(nodetextmap[i]==active_item)
+            {
+              clicked_node=i;
+            }
+          }
 
-		for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
-		  {
-		    //at the same time only one can be active
-		    if(nodesmap[i]==active_item)
-		      {
-			clicked_node=i;
-		      }
-		  }
-	      }
-	    //if it was really an edge...
-	    if(clicked_node!=INVALID)
-	      {
-                // the id map is not editable
-                if (nodemap_to_edit == "id") return 0;
-		//If there is already edited edge, it has to be saved first
-		if(entrywidget.is_visible())
-		  {
-		    GdkEvent * generated=new GdkEvent();
-		    generated->type=GDK_KEY_PRESS;
-		    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
-		    entryWidgetChangeHandler(generated);
-		  }
-		//If the previous value could be saved, we can go further, otherwise not
-		if(!entrywidget.is_visible())
-		  {
-		    //and there is activated map
-		    if(nodetextmap[clicked_node]->property_text().get_value()!="")
-		      {
-			//activate the general variable for it
-			active_node=clicked_node;
-			//delete visible widget if there is
-			if(canvasentrywidget)
-			  {
-			    delete(canvasentrywidget);
-			  }
+          //if there was not, search for it between nodes
+          if(clicked_node==INVALID)
+          {
+            for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
+            {
+              //at the same time only one can be active
+              if(nodesmap[i]==active_item)
+              {
+                clicked_node=i;
+              }
+            }
+          }
 
-			//initialize the entry
-			entrywidget.show();
+          //if it was really a node...
+          if(clicked_node!=INVALID)
+          {
+            // the id map is not editable
+            if (nodemap_to_edit == "id") return 0;
 
-			//fill in the correct value
-			entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
+            //and there is activated map
+            if(nodetextmap[clicked_node]->property_text().get_value()!="")
+            {
+              //activate the general variable for it
+              active_node=clicked_node;
 
-			//replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
-			xy<double> entry_coos;
-			entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
-			entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
-			entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
-			entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
-			canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
-			canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4);
-			canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
-		      }
-		  }
-	      }
-	    //if it was not an edge...
-	    else
-	      {
-		//In this case the click did not happen on an edge
-		//if there is visible entry we save the value in it
-		//we pretend like an Enter was presse din the Entry widget
-		GdkEvent * generated=new GdkEvent();
-		generated->type=GDK_KEY_PRESS;
-		((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
-		entryWidgetChangeHandler(generated);
-	      }
-	    break;
-	  }
-	default:
-	  break;
-	}
+              //create a dialog
+              Gtk::Dialog dialog("Edit value", *parentwin, true);
+              dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+              dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
+              Gtk::VBox* vbox = dialog.get_vbox();
+              Gtk::Adjustment adj(
+                  (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node],
+                  -1000000.0,
+                  1000000.0,
+                  1.0, 5.0, 0.0);
+              //TODO: find out why doesn't it work with
+              //numeric_limits<double>::min/max
+              Gtk::SpinButton spin(adj);
+              spin.set_numeric(true);
+              spin.set_digits(4);
+              vbox->add(spin);
+              spin.show();
+              switch (dialog.run())
+              {
+                case Gtk::RESPONSE_NONE:
+                case Gtk::RESPONSE_CANCEL:
+                  break;
+                case Gtk::RESPONSE_ACCEPT:
+                  double new_value = spin.get_value();
+                  (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node] =
+                    new_value;
+                  std::ostringstream ostr;
+                  ostr << new_value;
+                  nodetextmap[active_node]->property_text().set_value(
+                      ostr.str());
+                  //mapwin.updateNode(active_node);
+                  mapwin.updateNode(Node(INVALID));
+              }
+            }
+          }
+          break;
+        }
+      default:
+        break;
     }
+  }
   return false;  
 }
 
-bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
-{
-  if(entrywidget.is_visible())
-    {
-      if(e->type==GDK_KEY_PRESS)
-	{
-	  switch(((GdkEventKey*)e)->keyval)
-	    {
-	    case GDK_Escape:
-	      entrywidget.hide();
-	      break;
-	    case GDK_KP_Enter:
-	    case GDK_Return:
-	      {
-		//these variables check whether the text in the entry is valid
-		bool valid_double=true;
-		int point_num=0;
-
-		//getting the value from the entry and converting it to double
-		Glib::ustring mapvalue_str = entrywidget.get_text();
-
-		char * mapvalue_ch=new char [mapvalue_str.length()];
-		for(int i=0;i<(int)(mapvalue_str.length());i++)
-		  {
-		    if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.'))
-		      {
-			valid_double=false;
-		      }
-		    else
-		      {
-			if(mapvalue_str[i]=='.')
-			  {
-			    point_num++;
-			  }
-		      }
-		    mapvalue_ch[i]=mapvalue_str[i];
-		  }
-  	      
-		//if the text in the entry was correct
-		if((point_num<=1)&&(valid_double))
-		  {
-		    double mapvalue_d=atof(mapvalue_ch);
-
-		    //reconvert the double to string for the correct format
-		    std::ostringstream ostr;
-		    ostr << mapvalue_d;
-
-		    //save the value to the correct place
-		    switch(actual_tool)
-		      {
-		      case EDGE_MAP_EDIT:
-			edgetextmap[active_edge]->property_text().set_value(ostr.str());
-			(*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
-			mapwin.updateEdge(active_edge);
-			break;
-		      case NODE_MAP_EDIT:
-			nodetextmap[active_node]->property_text().set_value(ostr.str());
-			(*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
-			mapwin.updateNode(active_node);
-			break;
-		      default:
-			break;
-		      }
-		    entrywidget.hide();
-		  }
-		//the text in the entry was not correct for a double
-		else
-		  {
-		    std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl;
-		  }
-
-		break;
-	      }
-	    default:
-	      break;
-	    }
-	}
-    }
-  return false;
-}
-
 void GraphDisplayerCanvas::deleteItem(Node node_to_delete)
 {
   delete(nodetextmap[node_to_delete]);
diff -r d5dc956393b2 -r dd8672338691 gui/graph_displayer_canvas.cc
--- a/gui/graph_displayer_canvas.cc	Tue Aug 23 16:27:59 2005 +0000
+++ b/gui/graph_displayer_canvas.cc	Fri Aug 26 07:35:23 2005 +0000
@@ -4,9 +4,9 @@
 
 GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
   nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
-  nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
-  canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
-  target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
+  nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), mapstorage(ms),
+  isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
+  edgemap_to_edit(""), mapwin(mw)
 {
   parentwin=mainwin;
 
@@ -14,9 +14,6 @@
   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
   actual_tool=MOVE;
 
-  //setting event handler for the editor widget
-  entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
-
   active_node=INVALID;
   active_edge=INVALID;
   forming_edge=INVALID;
@@ -35,11 +32,6 @@
     delete edgesmap[e];
     delete edgetextmap[e];
   }
-
-  if(canvasentrywidget)
-  {
-    delete(canvasentrywidget);
-  }
 }
 
 void GraphDisplayerCanvas::drawGraph()
diff -r d5dc956393b2 -r dd8672338691 gui/graph_displayer_canvas.h
--- a/gui/graph_displayer_canvas.h	Tue Aug 23 16:27:59 2005 +0000
+++ b/gui/graph_displayer_canvas.h	Fri Aug 26 07:35:23 2005 +0000
@@ -90,9 +90,6 @@
   ///event handler for the case when node map editor tool is active
   bool nodeMapEditEventHandler(GdkEvent*);
 
-  ///event handler for the case when the entry widget is changed
-  bool entryWidgetChangeHandler(GdkEvent*);
-
 public:
   ///Moves the text to new place
   void textReposition(xy<double>);
@@ -140,12 +137,6 @@
   ///Group of graphical elements of displayed_graph
   Gnome::Canvas::Group displayed_graph;
 
-  ///Map editor entry
-  Gtk::Entry entrywidget;
-
-  ///GnomeCanvas holder for entry
-  Gnome::Canvas::Widget * canvasentrywidget;
-
   ///Here we store the maps that can be displayed through properties.
   MapStorage & mapstorage;
 
@@ -175,8 +166,7 @@
   ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
   MapWin & mapwin;
 
-  ///We need to store the parent window to be able to set the focus on a given widget
-  ///We will use this variable to activate the set focus on entry widget in the case of editing map values.
+  ///pointer to the parent window
   Gtk::Window * parentwin;
 
 };
diff -r d5dc956393b2 -r dd8672338691 gui/map_win.cc
--- a/gui/map_win.cc	Tue Aug 23 16:27:59 2005 +0000
+++ b/gui/map_win.cc	Fri Aug 26 07:35:23 2005 +0000
@@ -81,7 +81,10 @@
 
     for(;emsi!=ms.endOfNodeMaps();emsi++)
     {
-      listStrings.push_back(emsi->first);
+      if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y"))
+      {
+        listStrings.push_back(emsi->first);
+      }
     }
 
     n_combo_array[i].set_popdown_strings(listStrings);
@@ -148,7 +151,10 @@
 
     for(;emsi!=ms.endOfNodeMaps();emsi++)
     {
-      listStrings.push_back(emsi->first);
+      if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y"))
+      {
+        listStrings.push_back(emsi->first);
+      }
     }
 
     n_combo_array[i].set_popdown_strings(listStrings);