chiark / gitweb /
doxygen: clean up function documentation.
[disorder] / disobedience / popup.c
CommitLineData
6982880f
RK
1/*
2 * This file is part of DisOrder
3 * Copyright (C) 2008 Richard Kettlewell
4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
6982880f 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
6982880f
RK
8 * (at your option) any later version.
9 *
e7eb3a27
RK
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
6982880f 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6982880f 17 */
132a5a4a
RK
18/** @file disobedience/popup.c
19 * @brief Disobedience popup menus
20 */
6982880f
RK
21#include "disobedience.h"
22#include "popup.h"
23
24void popup(GtkWidget **menup,
25 GdkEventButton *event,
26 struct menuitem *items,
27 int nitems,
28 void *extra) {
29 GtkWidget *menu = *menup;
30
31 /* Create the menu if it does not yet exist */
32 if(!menu) {
33 menu = *menup = gtk_menu_new();
34 g_signal_connect(menu, "destroy",
35 G_CALLBACK(gtk_widget_destroyed), menup);
36 for(int n = 0; n < nitems; ++n) {
ba6f3dd4
RK
37 if(items[n].stock) {
38 GtkWidget *image = gtk_image_new_from_stock(items[n].stock,
39 GTK_ICON_SIZE_MENU);
40 items[n].w = gtk_image_menu_item_new_with_label(items[n].name);
41 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(items[n].w),
42 image);
43 } else
44 items[n].w = gtk_menu_item_new_with_label(items[n].name);
d380121b
RK
45 /* TODO accelerators would be useful here. There might be some
46 * interaction with the main menu accelerators, _except_ for playlist
47 * case! */
6982880f
RK
48 gtk_menu_attach(GTK_MENU(menu), items[n].w, 0, 1, n, n + 1);
49 }
50 set_tool_colors(menu);
51 }
52 /* Configure item sensitivity */
53 for(int n = 0; n < nitems; ++n) {
54 if(items[n].handlerid)
55 g_signal_handler_disconnect(items[n].w,
56 items[n].handlerid);
57 gtk_widget_set_sensitive(items[n].w,
58 items[n].sensitive(extra));
59 items[n].handlerid = g_signal_connect(items[n].w,
60 "activate",
61 G_CALLBACK(items[n].activate),
62 extra);
63 }
64 /* Pop up the menu */
65 gtk_widget_show_all(menu);
66 gtk_menu_popup(GTK_MENU(menu), 0, 0, 0, 0,
67 event->button, event->time);
68}
69
83a01160 70/** @brief Make sure the right thing is selected
59cf25c4 71 * @param treeview Tree view
83a01160 72 * @param event Mouse event
6982880f
RK
73 */
74void ensure_selected(GtkTreeView *treeview,
75 GdkEventButton *event) {
76 GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
83a01160
RK
77 /* Get the path of the hovered item */
78 GtkTreePath *path;
79 if(!gtk_tree_view_get_path_at_pos(treeview,
80 event->x, event->y,
81 &path,
82 NULL,
83 NULL, NULL))
84 return; /* If there isn't one, do nothing */
85 if(!gtk_tree_selection_path_is_selected(selection, path)) {
86 /* We're hovered over one thing but it's not the selected row. This is
87 * very confusing for the poor old user so we select the hovered row. */
88 gtk_tree_selection_unselect_all(selection);
89 gtk_tree_selection_select_path(selection, path);
6982880f 90 }
83a01160 91 gtk_tree_path_free(path);
6982880f
RK
92}
93
94/*
95Local Variables:
96c-basic-offset:2
97comment-column:40
98fill-column:79
99indent-tabs-mode:nil
100End:
101*/