1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
/********************************************************************\
* The following is code copied from Gnumeric 1.7.8 src/gui-util.c, *
* and it has been modified slightly to work within GnuCash. *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
/* Miguel de Icaza is not sure specifically who from the Gnumeric
* community is the copyright owner of the code below, so, on his
* recommendation, here is the full list of Gnumeric authors.
*
* Miguel de Icaza, creator.
* Jody Goldberg, maintainer.
* Harald Ashburner, Options pricers
* Sean Atkinson, functions and X-Base importing.
* Michel Berkelaar, Simplex algorithm for Solver (LP Solve).
* Jean Brefort, Core charting engine.
* Grandma Chema Celorio, Tester and sheet copy.
* Frank Chiulli, OLE support.
* Kenneth Christiansen, i18n, misc stuff.
* Zbigniew Chyla, plugin system, i18n.
* J.H.M. Dassen (Ray), debian packaging.
* Jeroen Dirks, Simplex algorithm for Solver (LP Solve).
* Tom Dyas, plugin support.
* Gergo Erdi, Gnumeric hacker.
* John Gotts, rpm packaging.
* Andreas J. Guelzow, Gnumeric hacker.
* Jon K. Hellan, Gnumeric hacker.
* Ross Ihaka, special functions.
* Jukka-Pekka Iivonen, numerous functions and tools.
* Jakub Jelinek, Gnumeric hacker.
* Chris Lahey, number format engine.
* Adrian Likins, documentation, debugging.
* Takashi Matsuda, original text plugin.
* Michael Meeks, Excel and OLE2 importing.
* Lutz Muller, SheetObject improvements.
* Emmanuel Pacaud, Many plot types for charting engine.
* Federico M. Quintero, canvas support.
* Mark Probst, Guile support.
* Rasca, HTML, troff, LaTeX exporters.
* Vincent Renardias, original CSV support, French localization.
* Ariel Rios, Guile support.
* Uwe Steinmann, Paradox Importer.
* Arturo Tena, OLE support.
* Almer S. Tigelaar, Gnumeric hacker.
* Bruno Unna, Excel bits.
* Daniel Veillard, XML support.
* Vladimir Vuksan, financial functions.
* Morten Welinder, Gnumeric hacker and leak plugging demi-god.
*/
#include "gnc-csv-gnumeric-popup.h"
#include <glib/gi18n.h>
static void
popup_item_activate (GtkWidget *item, gpointer *user_data)
{
GnumericPopupMenuElement const *elem =
g_object_get_data (G_OBJECT (item), "descriptor");
GnumericPopupMenuHandler handler =
g_object_get_data (G_OBJECT (item), "handler");
g_return_if_fail (elem != NULL);
g_return_if_fail (handler != NULL);
if (handler (elem, user_data))
gtk_widget_destroy (gtk_widget_get_toplevel (item));
}
static void
gnumeric_create_popup_menu_list (GSList *elements,
GnumericPopupMenuHandler handler,
gpointer user_data,
int display_filter,
int sensitive_filter,
GdkEventButton *event)
{
GtkWidget *menu = gtk_menu_new ();
GtkWidget *item;
for (; elements != NULL ; elements = elements->next)
{
GnumericPopupMenuElement const *element = elements->data;
char const * const name = element->name;
char const * const pix_name = element->pixmap;
if (element->display_filter != 0 &&
!(element->display_filter & display_filter))
continue;
if (name != NULL && *name != '\0')
{
GtkWidget *label = gtk_label_new_with_mnemonic (name);
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
item = gtk_menu_item_new();
gtk_box_set_homogeneous (GTK_BOX (box), FALSE);
gtk_widget_set_hexpand (GTK_WIDGET(box), FALSE);
gtk_widget_set_halign (GTK_WIDGET(box), GTK_ALIGN_START);
if (pix_name != NULL)
{
GtkWidget *image = gtk_image_new_from_icon_name (pix_name,
GTK_ICON_SIZE_MENU);
gtk_container_add (GTK_CONTAINER (box), image);
gtk_widget_show (image);
}
gtk_box_pack_end (GTK_BOX (box), label, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (item), box);
if (element->sensitive_filter != 0 &&
(element->sensitive_filter & sensitive_filter))
gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
}
else
{
/* separator */
item = gtk_separator_menu_item_new ();
}
gtk_widget_show_all (item);
if (element->index != 0)
{
g_signal_connect (G_OBJECT (item),
"activate",
G_CALLBACK (&popup_item_activate), user_data);
g_object_set_data (
G_OBJECT (item), "descriptor", (gpointer)(element));
g_object_set_data (
G_OBJECT (item), "handler", (gpointer)handler);
}
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
gnumeric_popup_menu (GTK_MENU (menu), event);
}
void
gnumeric_create_popup_menu (GnumericPopupMenuElement const *elements,
GnumericPopupMenuHandler handler,
gpointer user_data,
int display_filter, int sensitive_filter,
GdkEventButton *event)
{
int i;
GSList *tmp = NULL;
for (i = 0; elements [i].name != NULL; i++)
tmp = g_slist_prepend (tmp, (gpointer)(elements + i));
tmp = g_slist_reverse (tmp);
gnumeric_create_popup_menu_list (tmp, handler, user_data,
display_filter, sensitive_filter, event);
g_slist_free (tmp);
}
static void
kill_popup_menu (GtkWidget *widget, GtkMenu *menu)
{
g_return_if_fail (menu != NULL);
g_return_if_fail (GTK_IS_MENU (menu));
g_object_unref (G_OBJECT (menu));
}
/**
* gnumeric_popup_menu :
* @menu : #GtkMenu
* @event : #GdkEventButton optionally NULL
*
* Bring up a popup and if @event is non-NULL ensure that the popup is on the
* right screen.
**/
void
gnumeric_popup_menu (GtkMenu *menu, GdkEventButton *event)
{
g_return_if_fail (menu != NULL);
g_return_if_fail (GTK_IS_MENU (menu));
g_object_ref_sink (menu);
if (event)
gtk_menu_set_screen (menu,
gdk_window_get_screen (event->window));
g_signal_connect (G_OBJECT (menu),
"hide",
G_CALLBACK (kill_popup_menu), menu);
/* Do NOT pass the button used to create the menu.
* instead pass 0. Otherwise bringing up a menu with
* the right button will disable clicking on the menu with the left.
*/
#if GTK_CHECK_VERSION(3,22,0)
gtk_menu_popup_at_pointer (GTK_MENU(menu), (GdkEvent *) event);
#else
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 0,
(event != NULL) ? event->time
: gtk_get_current_event_time());
#endif
}
|