diff -r 1b8e20c04704 -r 4ca5a537ef07 graph_displayer_canvas-event.cc --- a/graph_displayer_canvas-event.cc Tue Aug 23 16:27:59 2005 +0000 +++ b/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 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::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 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::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]);