Commit 5c6e7a077d29d32682866e23cb3e85751295e307
1 parent
d0bf1b0d
Exists in
master
and in
5 other branches
Implementando popup menus
Showing
5 changed files
with
52 additions
and
10 deletions
Show diff stats
pw3270.cbp
... | ... | @@ -58,6 +58,7 @@ |
58 | 58 | <Unit filename="src/gtk/mainwindow.c"> |
59 | 59 | <Option compilerVar="CC" /> |
60 | 60 | </Unit> |
61 | + <Unit filename="src/gtk/uiparser/Makefile.in" /> | |
61 | 62 | <Unit filename="src/gtk/uiparser/accelerator.c"> |
62 | 63 | <Option compilerVar="CC" /> |
63 | 64 | </Unit> |
... | ... | @@ -80,7 +81,13 @@ |
80 | 81 | <Option compilerVar="CC" /> |
81 | 82 | </Unit> |
82 | 83 | <Unit filename="src/gtk/uiparser/parser.h" /> |
84 | + <Unit filename="src/gtk/uiparser/popup.c"> | |
85 | + <Option compilerVar="CC" /> | |
86 | + </Unit> | |
83 | 87 | <Unit filename="src/gtk/uiparser/private.h" /> |
88 | + <Unit filename="src/gtk/uiparser/script.c"> | |
89 | + <Option compilerVar="CC" /> | |
90 | + </Unit> | |
84 | 91 | <Unit filename="src/gtk/uiparser/separator.c"> |
85 | 92 | <Option compilerVar="CC" /> |
86 | 93 | </Unit> | ... | ... |
src/gtk/mainwindow.c
... | ... | @@ -114,9 +114,30 @@ |
114 | 114 | set_integer_to_config("terminal","model",id); |
115 | 115 | } |
116 | 116 | |
117 | - static gboolean popup(GtkWidget *widget, gboolean selected, gboolean online, GdkEventButton *event, gpointer popup) | |
117 | + static gboolean popup_menu(GtkWidget *widget, gboolean selected, gboolean online, GdkEventButton *event, GtkWidget **popup) | |
118 | 118 | { |
119 | - trace("Popup on widget %p online=%s selected=%s",widget,online ? "Yes" : "No", selected ? "Yes" : "No"); | |
119 | + GtkWidget *menu = NULL; | |
120 | + | |
121 | + if(!online) | |
122 | + menu = popup[POPUP_OFFLINE] ? popup[POPUP_OFFLINE] : popup[POPUP_DEFAULT]; | |
123 | + else if(selected && popup[POPUP_SELECTION]) | |
124 | + menu = popup[POPUP_SELECTION]; | |
125 | + else if(popup[POPUP_ONLINE]) | |
126 | + menu = popup[POPUP_ONLINE]; | |
127 | + else | |
128 | + menu = popup[POPUP_DEFAULT]; | |
129 | + | |
130 | + trace("Popup %p on widget %p online=%s selected=%s",menu,widget,online ? "Yes" : "No", selected ? "Yes" : "No"); | |
131 | + | |
132 | + if(!menu) | |
133 | + return FALSE; | |
134 | + | |
135 | + trace("Showing popup \"%s\"",gtk_widget_get_name(menu)); | |
136 | + | |
137 | + gtk_widget_show_all(menu); | |
138 | + gtk_menu_set_screen(GTK_MENU(menu), gtk_widget_get_screen(widget)); | |
139 | + gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button,event->time); | |
140 | + | |
120 | 141 | return TRUE; |
121 | 142 | } |
122 | 143 | |
... | ... | @@ -205,6 +226,7 @@ |
205 | 226 | H3270 * host = v3270_get_session(terminal); |
206 | 227 | gchar * path = build_data_filename("ui",NULL); |
207 | 228 | GtkActionGroup **group; |
229 | + GtkWidget **popup; | |
208 | 230 | int f; |
209 | 231 | |
210 | 232 | // Initialize terminal config |
... | ... | @@ -226,7 +248,8 @@ |
226 | 248 | |
227 | 249 | // Create window |
228 | 250 | window = ui_parse_xml_folder(path,groupname,popupname,terminal,widget_setup); |
229 | - group = g_object_get_data(G_OBJECT(window),"action_groups"); | |
251 | + group = g_object_get_data(G_OBJECT(window),"action_groups"); | |
252 | + popup = g_object_get_data(G_OBJECT(window),"popup_menus"); | |
230 | 253 | |
231 | 254 | // Setup action groups |
232 | 255 | gtk_action_group_set_sensitive(group[ACTION_GROUP_SELECTION],FALSE); |
... | ... | @@ -242,7 +265,7 @@ |
242 | 265 | g_signal_connect(terminal,"update_config",G_CALLBACK(update_config),0); |
243 | 266 | g_signal_connect(terminal,"model_changed",G_CALLBACK(update_model),0); |
244 | 267 | g_signal_connect(terminal,"selecting",G_CALLBACK(selecting),group); |
245 | - g_signal_connect(terminal,"popup",G_CALLBACK(popup),NULL); | |
268 | + g_signal_connect(terminal,"popup",G_CALLBACK(popup_menu),popup); | |
246 | 269 | |
247 | 270 | g_free(path); |
248 | 271 | gtk_widget_grab_focus(terminal); | ... | ... |
src/gtk/uiparser/parser.c
... | ... | @@ -255,8 +255,11 @@ GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, con |
255 | 255 | p.toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
256 | 256 | p.center_widget = widget; |
257 | 257 | p.group = groupname; |
258 | - p.popup = popupname; | |
258 | + p.popupname = popupname; | |
259 | 259 | p.strings = g_string_chunk_new(0); |
260 | + p.popup = g_new0(GtkWidget *,(g_strv_length((gchar **) p.popupname)+1)); | |
261 | + | |
262 | + g_object_set_data_full(G_OBJECT(p.toplevel),"popup_menus",(gpointer) p.popup, g_free); | |
260 | 263 | |
261 | 264 | for(current = g_list_first(file);current;current = g_list_next(current)) |
262 | 265 | { | ... | ... |
src/gtk/uiparser/popup.c
... | ... | @@ -62,9 +62,9 @@ |
62 | 62 | return NULL; |
63 | 63 | } |
64 | 64 | |
65 | - for(f=0;info->popup[f] && pos < 0;pos++) | |
65 | + for(f=0;info->popupname[f] && pos < 0;f++) | |
66 | 66 | { |
67 | - if(!g_strcasecmp(info->popup[f],id)) | |
67 | + if(!g_strcasecmp(info->popupname[f],id)) | |
68 | 68 | { |
69 | 69 | pos = f; |
70 | 70 | break; |
... | ... | @@ -76,10 +76,18 @@ |
76 | 76 | *error = g_error_new(ERROR_DOMAIN,EINVAL,_( "Unknown popup type \"%s\""),id); |
77 | 77 | return NULL; |
78 | 78 | } |
79 | + else | |
80 | + { | |
81 | + widget = info->popup[pos]; | |
82 | + } | |
79 | 83 | |
80 | - widget = gtk_menu_new(); | |
84 | + if(!widget) | |
85 | + { | |
86 | + info->popup[pos] = widget = gtk_menu_new(); | |
87 | + gtk_widget_show_all(widget); | |
88 | + } | |
81 | 89 | |
82 | - g_object_set_data(G_OBJECT(widget),"popup_id",(gpointer) pos); | |
90 | + trace("popup(%s): %p id=\"%s\" (%d)",id,widget,info->popupname[pos],pos); | |
83 | 91 | |
84 | 92 | return G_OBJECT(ui_insert_element(info, action, UI_ELEMENT_POPUP, names, values, G_OBJECT(widget), error)); |
85 | 93 | } | ... | ... |
src/gtk/uiparser/private.h
... | ... | @@ -56,9 +56,10 @@ |
56 | 56 | GtkWidget * toplevel; |
57 | 57 | GObject * element; |
58 | 58 | GtkWidget * center_widget; |
59 | + GtkWidget ** popup; /**< Popup widgets */ | |
59 | 60 | GStringChunk * strings; |
60 | 61 | const gchar ** group; /**< Action group list */ |
61 | - const gchar ** popup; /**< Popup names */ | |
62 | + const gchar ** popupname; /**< Popup names */ | |
62 | 63 | GHashTable * actions; /**< List of actions */ |
63 | 64 | GHashTable * element_list[UI_ELEMENT_COUNT]; |
64 | 65 | }; | ... | ... |