Commit 179ca6c9415f4753f3a6d89b97eaf116f79d954c

Authored by perry.werneck@gmail.com
1 parent 73a17cbd

Incluindo liberação correta das janelas popup criadas pelo parser.

src/gtk/uiparser/parser.c
@@ -206,6 +206,19 @@ void parser_build(struct parser *p, GtkWidget *widget) @@ -206,6 +206,19 @@ void parser_build(struct parser *p, GtkWidget *widget)
206 206
207 } 207 }
208 208
  209 +static void release_popups(GtkWidget **popup)
  210 +{
  211 + int f;
  212 + for(f=0;popup[f] != ((GtkWidget *) -1);f++)
  213 + {
  214 + trace("%s[%d]=%p",__FUNCTION__,f,popup[f]);
  215 + if(popup[f])
  216 + g_object_unref(popup[f]);
  217 + }
  218 +
  219 + g_free(popup);
  220 +}
  221 +
209 GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, const gchar **popupname, GtkWidget *widget, const UI_WIDGET_SETUP *setup) 222 GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, const gchar **popupname, GtkWidget *widget, const UI_WIDGET_SETUP *setup)
210 { 223 {
211 struct parser p; 224 struct parser p;
@@ -214,6 +227,7 @@ GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, con @@ -214,6 +227,7 @@ GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, con
214 gchar * ptr; 227 gchar * ptr;
215 GList * file = NULL; 228 GList * file = NULL;
216 GList * current; 229 GList * current;
  230 + size_t sz;
217 231
218 dir = g_dir_open(path,0,&error); 232 dir = g_dir_open(path,0,&error);
219 233
@@ -257,10 +271,12 @@ GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, con @@ -257,10 +271,12 @@ GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, con
257 p.group = groupname; 271 p.group = groupname;
258 p.popupname = popupname; 272 p.popupname = popupname;
259 p.strings = g_string_chunk_new(0); 273 p.strings = g_string_chunk_new(0);
260 - p.popup = g_new0(GtkWidget *,(g_strv_length((gchar **) p.popupname)+1));  
261 p.setup = setup; 274 p.setup = setup;
262 275
263 - g_object_set_data_full(G_OBJECT(p.toplevel),"popup_menus",(gpointer) p.popup, g_free); 276 + sz = (g_strv_length((gchar **) p.popupname));
  277 + p.popup = g_new0(GtkWidget *,sz+1);
  278 + p.popup[sz] = (GtkWidget *) -1;
  279 + g_object_set_data_full(G_OBJECT(p.toplevel),"popup_menus",(gpointer) p.popup, (GDestroyNotify) release_popups);
264 280
265 for(current = g_list_first(file);current;current = g_list_next(current)) 281 for(current = g_list_first(file);current;current = g_list_next(current))
266 { 282 {
src/gtk/uiparser/popup.c
@@ -84,6 +84,7 @@ @@ -84,6 +84,7 @@
84 if(!widget) 84 if(!widget)
85 { 85 {
86 info->popup[pos] = widget = gtk_menu_new(); 86 info->popup[pos] = widget = gtk_menu_new();
  87 + g_object_ref(widget);
87 gtk_widget_show_all(widget); 88 gtk_widget_show_all(widget);
88 } 89 }
89 90
src/gtk/uiparser/testprogram.c
@@ -85,12 +85,12 @@ int main (int argc, char *argv[]) @@ -85,12 +85,12 @@ int main (int argc, char *argv[])
85 85
86 for(f=0;popupname[f];f++) 86 for(f=0;popupname[f];f++)
87 { 87 {
  88 + GtkWidget *button = gtk_button_new_with_label(popupname[f]);
  89 + gtk_box_pack_start(GTK_BOX(hbox),button,FALSE,FALSE,5);
88 if(popup[f]) 90 if(popup[f])
89 - {  
90 - GtkWidget *button = gtk_button_new_with_label(popupname[f]);  
91 - gtk_box_pack_start(GTK_BOX(hbox),button,FALSE,FALSE,5);  
92 g_signal_connect(button,"clicked",G_CALLBACK(show_popup),popup[f]); 91 g_signal_connect(button,"clicked",G_CALLBACK(show_popup),popup[f]);
93 - } 92 + else
  93 + gtk_widget_set_sensitive(button,FALSE);
94 } 94 }
95 95
96 gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,5); 96 gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,5);