diff -r f1b70894b953 -r 9fe6eebde1a8 graph_displayer_canvas-event.cc --- a/graph_displayer_canvas-event.cc Tue Jul 26 21:20:01 2005 +0000 +++ b/graph_displayer_canvas-event.cc Wed Jul 27 10:47:38 2005 +0000 @@ -424,10 +424,13 @@ switch(e->type) { case GDK_BUTTON_PRESS: + //finding the clicked items window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); active_item=(get_item_at(clicked_x, clicked_y)); active_node=INVALID; active_edge=INVALID; + + //was it a node? for (NodeIt i(g); i!=INVALID; ++i) { if(nodesmap[i]==active_item) @@ -435,6 +438,7 @@ active_node=i; } } + //or was it an edge? if(active_node==INVALID) { for (EdgeIt i(g); i!=INVALID; ++i) @@ -445,6 +449,8 @@ } } } + + //recolor activated item if(active_item) { *active_item << Gnome::Canvas::Properties::fill_color("red"); @@ -455,8 +461,10 @@ window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); if(active_item) { + //the cursor was not moved since pressing it if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) { + //a node was found if(active_node!=INVALID) { @@ -522,14 +530,19 @@ 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. { + //find the activated item window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); active_item=(get_item_at(clicked_x, clicked_y)); + + //determine, whether it was an edge Graph::EdgeIt clicked_edge=INVALID; for (EdgeIt i(g); i!=INVALID; ++i) { @@ -538,29 +551,55 @@ clicked_edge=i; } } + //if it was really an edge... if(clicked_edge!=INVALID) { - if(edgetextmap[clicked_edge]->property_text().get_value()!="") + //If there is already edited edge, it has to be saved first + if(entrywidget.is_visible()) { - active_edge=clicked_edge; - if(canvasentrywidget) + 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()!="") { - delete(canvasentrywidget); + //activate the general variable for it + active_edge=clicked_edge; + //delete visible widget if there is + if(canvasentrywidget) + { + delete(canvasentrywidget); + } + + //initialize the entry + entrywidget.show(); + + //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()*1.5); + canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5); } - entrywidget.show(); - entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value()); - 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()*1.5); - canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->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; @@ -579,6 +618,7 @@ switch(e->type) { case GDK_KEY_PRESS: + //for Escape or Enter hide the displayed widget { switch(((GdkEventKey*)e)->keyval) { @@ -596,9 +636,13 @@ 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. { + //find the activated item window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); active_item=(get_item_at(clicked_x, clicked_y)); + + //determine, whether it was a node Graph::NodeIt clicked_node=INVALID; for (NodeIt i(g); i!=INVALID; ++i) { @@ -607,6 +651,8 @@ clicked_node=i; } } + + //if it was really an edge... if(clicked_node!=INVALID) { //If there is already edited edge, it has to be saved first @@ -620,16 +666,24 @@ //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); } + + //initialize the entry entrywidget.show(); + + //fill in the correct value entrywidget.set_text(nodetextmap[active_node]->property_text().get_value()); + + //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; @@ -641,8 +695,12 @@ } } } + //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; @@ -670,8 +728,11 @@ 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()]; @@ -693,46 +754,10 @@ double mapvalue_d=atof(mapvalue_ch); -// double double_map_fract_value=0; -// double double_map_value=0; -// int offset=0; -// int found_letter=0; - //converting text to double -// for(int i=0;i<(int)(mapvalue.length());i++) -// { -// if(((mapvalue[i]<='9')&&(mapvalue[i]>='0'))||(mapvalue[i]=='.')) -// { -// if(mapvalue[i]=='.') -// { -// //for calculating non-integer part of double we step backward from the end -// //after each step the number will be divided by ten, and the new value will be added -// //to step backward from the end until the point the actual character of the string is the following: -// // mapvalue.length()-(i-position_of_point) -// //if i was the number of the first character after the decimal point the selected character will be the last -// //if i was the number of the last character, the selected character will be the first after the decimal point -// offset=mapvalue.length()+i; -// } -// else -// { -// if(!offset) -// { -// double_map_value=10*double_map_value+mapvalue[i]-'0'; -// } -// else -// { -// double_map_fract_value=double_map_fract_value/10+(double)(mapvalue[offset-i]-'0')/10; -// } -// } -// } -// else -// { -// found_letter++; -// continue; -// } -// } - + //if the text in the entry was correct if((point_num<=1)&&(valid_double)) { + //save the value to the correct place switch(actual_tool) { case EDGE_MAP_EDIT: @@ -748,6 +773,7 @@ } entrywidget.hide(); } + //the text in the entry was not correct for a double else { std::cout << "ERROR: only handling of double values is implemented yet!" << std::endl; @@ -826,17 +852,27 @@ void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) { + //create the new map Graph::EdgeMap * emptr=new Graph::EdgeMap (g,default_value); mapstorage.addEdgeMap(mapname,emptr); + + //add it to the list of the displayable maps mapwin->registerNewEdgeMap(mapname); + + //display it changeEdgeText(mapname); } void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) { + //create the new map Graph::NodeMap * emptr=new Graph::NodeMap (g,default_value); mapstorage.addNodeMap(mapname,emptr); + + //add it to the list of the displayable maps mapwin->registerNewNodeMap(mapname); + + //display it changeNodeText(mapname); }