| 201 | } |
| 202 | |
| 203 | int |
| 204 | ghack_menu_window_select_menu(GtkWidget *menuWin, MENU_ITEM_P **_selected, |
| 205 | gint how) |
| 206 | { |
| 207 | gint rc; |
| 208 | guint num_sel, i, idx; |
| 209 | GtkWidget *clist; |
| 210 | GList *cur; |
| 211 | MENU_ITEM_P *selected = NULL; |
| 212 | menuItem *item; |
| 213 | |
| 214 | g_assert(_selected != NULL); |
| 215 | *_selected = NULL; |
| 216 | |
| 217 | if (how == PICK_NONE) { |
| 218 | gnome_dialog_close_hides(GNOME_DIALOG(menuWin), TRUE); |
| 219 | rc = gnome_dialog_run_and_close(GNOME_DIALOG(menuWin)); |
| 220 | return (rc == 1 ? -1 : 0); |
| 221 | } |
| 222 | |
| 223 | clist = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(menuWin), "clist")); |
| 224 | g_assert(clist != NULL); |
| 225 | |
| 226 | gtk_object_set_data(GTK_OBJECT(clist), "selection_mode", |
| 227 | GINT_TO_POINTER((how == PICK_ANY) |
| 228 | ? GTK_SELECTION_MULTIPLE |
| 229 | : GTK_SELECTION_SINGLE)); |
| 230 | gtk_clist_set_selection_mode(GTK_CLIST(clist), |
| 231 | (how == PICK_ANY) ? GTK_SELECTION_MULTIPLE |
| 232 | : GTK_SELECTION_SINGLE); |
| 233 | gnome_dialog_close_hides(GNOME_DIALOG(menuWin), TRUE); |
| 234 | rc = gnome_dialog_run_and_close(GNOME_DIALOG(menuWin)); |
| 235 | if ((rc == 1) || (GTK_CLIST(clist)->selection == NULL)) { |
| 236 | return (-1); |
| 237 | } |
| 238 | |
| 239 | num_sel = g_list_length(GTK_CLIST(clist)->selection); |
| 240 | if (num_sel < 1) { |
| 241 | return (-1); |
| 242 | } |
| 243 | |
| 244 | /* fill in array with selections from clist */ |
| 245 | selected = g_new0(MENU_ITEM_P, num_sel); |
| 246 | g_assert(selected != NULL); |
| 247 | cur = GTK_CLIST(clist)->selection; |
| 248 | i = 0; |
| 249 | while (cur) { |
| 250 | g_assert(i < num_sel); |
| 251 | |
| 252 | /* grab row number from clist selection list */ |
| 253 | idx = GPOINTER_TO_INT(cur->data); |
| 254 | |
| 255 | item = (menuItem *) gtk_clist_get_row_data(GTK_CLIST(clist), idx); |
| 256 | selected[i].item = item->identifier; |
| 257 | selected[i].count = -1; |
| 258 | cur = g_list_next(cur); |
| 259 | i++; |
| 260 | } |