From: erg Date: Wed, 24 Jun 2009 22:43:58 +0000 (+0000) Subject: Add viewport refresh function; X-Git-Tag: LAST_LIBGRAPH~32^2~1877 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ee6c7dfd468d14285298c4a3b315a65d441526da;p=graphviz Add viewport refresh function; add name argument when new graph is added; fix memory leaks; clean up code, putting common code into functions --- diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index 5240f6474..e56f0722e 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -465,7 +465,7 @@ void init_viewport(ViewInfo * view) set_viewport_settings_from_template(view, view->default_attributes); view->dfltViewType = VT_NONE; view->dfltEngine = GVK_NONE; - view->Topview->Graphdata.GraphFileName=(char*)0; + view->Topview->Graphdata.GraphFileName = (char*)0; view->Topview->Graphdata.Modified=0; view->colschms=NULL; view->flush=1; @@ -569,8 +569,9 @@ static Agraph_t *loadGraph(char *filename) fclose (input_file); return 0; } - view->Topview->Graphdata.GraphFileName = strdup (filename); - return g; + free (view->Topview->Graphdata.GraphFileName); + view->Topview->Graphdata.GraphFileName = strdup (filename); + return g; } #ifdef UNUSED static void refresh_borders(Agraph_t* g) @@ -588,45 +589,54 @@ int add_graph_to_viewport_from_file(char *fileName) { Agraph_t *graph = loadGraph(fileName); - return add_graph_to_viewport (graph); + return add_graph_to_viewport (graph, fileName); } -int add_graph_to_viewport(Agraph_t* graph) +void +refreshViewport (int doClear) { - if (graph) - { - view->graphCount = view->graphCount + 1; - view->g =(Agraph_t **) realloc(view->g,sizeof(Agraph_t *) * view->graphCount); - view->g[view->graphCount - 1] = graph; - view->activeGraph = view->graphCount - 1; - load_settings_from_graph(view->g[view->activeGraph]); - update_graph_from_settings(view->g[view->activeGraph]); - set_viewport_settings_from_template(view, view->g[view->activeGraph]); - update_topview(graph, view->Topview,1); - gtk_combo_box_append_text(view->graphComboBox,view->Topview->Graphdata.GraphFileName); - fill_key(view->orig_key,get_md5_key(graph)); - expose_event(view->drawing_area, NULL, NULL); - return 1; + Agraph_t* graph = view->g[view->activeGraph]; + + load_settings_from_graph(graph); + update_graph_from_settings(graph); + set_viewport_settings_from_template(view, graph); + if (doClear) + cleartopview(view->Topview); + update_topview(graph, view->Topview,1); + fill_key(view->orig_key,get_md5_key(graph)); + expose_event(view->drawing_area, NULL, NULL); +} + +static void +activate (int id, int doClear) +{ + view->activeGraph = id; + refreshViewport (doClear); +} + +int add_graph_to_viewport(Agraph_t* graph, char* id) +{ + if (graph) { + view->graphCount = view->graphCount + 1; + view->g =(Agraph_t **) realloc(view->g,sizeof(Agraph_t *) * view->graphCount); + view->g[view->graphCount - 1] = graph; + + gtk_combo_box_append_text(view->graphComboBox,id); + + activate (view->graphCount - 1, 0); + return 1; } - else - { - return 0; + else { + return 0; } } void switch_graph(int graphId) { - if (graphId >= view->graphCount) - return;/*wrong entry*/ - view->activeGraph = graphId; - load_settings_from_graph(view->g[view->activeGraph]); - update_graph_from_settings(view->g[view->activeGraph]); - set_viewport_settings_from_template(view, view->g[view->activeGraph]); - cleartopview(view->Topview); - update_topview(view->g[view->activeGraph], view->Topview,1); - fill_key(view->orig_key,get_md5_key(view->g[view->activeGraph])); - expose_event(view->drawing_area, NULL, NULL); - + if (graphId >= view->graphCount) + return;/*wrong entry*/ + else + activate (graphId, 1); } #if 0 diff --git a/cmd/smyrna/viewport.h b/cmd/smyrna/viewport.h index c75f19709..4d7cf6bf2 100755 --- a/cmd/smyrna/viewport.h +++ b/cmd/smyrna/viewport.h @@ -26,8 +26,9 @@ void init_viewport(ViewInfo * view); void set_viewport_settings_from_template(ViewInfo * view, Agraph_t *); void clear_viewport(ViewInfo * view); +void refreshViewport (int doClear); int add_graph_to_viewport_from_file(char *fileName); -int add_graph_to_viewport(Agraph_t* graph); +int add_graph_to_viewport(Agraph_t* graph, char*); int close_graph(ViewInfo * view,int graphid); int save_graph(void); int save_graph_with_file_name(Agraph_t * graph, char *fileName); @@ -41,6 +42,7 @@ void move_nodes(Agraph_t * g); void please_wait(void); void please_dont_wait(void); extern md5_byte_t* get_md5_key(Agraph_t* graph); +void fill_key(md5_byte_t* b,md5_byte_t* data); colorschemaset* create_color_theme(int themeid); extern void getcolorfromschema(colorschemaset* sc,float l,float maxl,RGBColor* c);