From 5300c973b51290e530eb87f6bece0b299bc0ae44 Mon Sep 17 00:00:00 2001 From: joncruz Date: Sat, 13 Oct 2007 09:05:49 +0000 Subject: [PATCH] Adding stroke & fill context menu to swatch --- src/dialogs/swatches.cpp | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/dialogs/swatches.cpp b/src/dialogs/swatches.cpp index 1196c8378..6607657e5 100644 --- a/src/dialogs/swatches.cpp +++ b/src/dialogs/swatches.cpp @@ -16,6 +16,9 @@ #include //for GTK_RESPONSE* types #include +#include +#include +#include #include #include @@ -219,6 +222,7 @@ static void dragBegin( GtkWidget *widget, GdkDragContext* dc, gpointer data ) // } static void handleClick( GtkWidget* widget, gpointer callback_data ) { + (void)widget; ColorItem* item = reinterpret_cast(callback_data); if ( item ) { item->buttonClicked(false); @@ -226,12 +230,74 @@ static void handleClick( GtkWidget* widget, gpointer callback_data ) { } static void handleSecondaryClick( GtkWidget* widget, gint arg1, gpointer callback_data ) { + (void)widget; + (void)arg1; ColorItem* item = reinterpret_cast(callback_data); if ( item ) { item->buttonClicked(true); } } +static GtkWidget* popupMenu = 0; +static ColorItem* bounceTarget = 0; + +static void redirClick( GtkMenuItem *menuitem, gpointer user_data ) +{ + (void)user_data; + if ( bounceTarget ) { + handleClick( GTK_WIDGET(menuitem), bounceTarget ); + } +} + +static void redirSecondaryClick( GtkMenuItem *menuitem, gpointer user_data ) +{ + (void)user_data; + if ( bounceTarget ) { + handleSecondaryClick( GTK_WIDGET(menuitem), 0, bounceTarget ); + } +} + +static gboolean handleButtonPress( GtkWidget* widget, GdkEventButton* event, gpointer user_data) +{ + (void)widget; + gboolean handled = FALSE; + + if ( (event->button == 3) && (event->type == GDK_BUTTON_PRESS) ) { + if ( !popupMenu ) { + popupMenu = gtk_menu_new(); + GtkWidget* child = 0; + + child = gtk_menu_item_new_with_label("Set fill"); + g_signal_connect( G_OBJECT(child), + "activate", + G_CALLBACK(redirClick), + user_data); + gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child); + + child = gtk_menu_item_new_with_label("Set stroke"); + + g_signal_connect( G_OBJECT(child), + "activate", + G_CALLBACK(redirSecondaryClick), + user_data); + gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child); + + gtk_widget_show_all(popupMenu); + } + + ColorItem* item = reinterpret_cast(user_data); + if ( item ) { + bounceTarget = item; + if ( popupMenu ) { + gtk_menu_popup(GTK_MENU(popupMenu), NULL, NULL, NULL, NULL, event->button, event->time); + handled = TRUE; + } + } + } + + return handled; +} + static void dieDieDie( GtkObject *obj, gpointer user_data ) { g_message("die die die %p %p", obj, user_data ); @@ -498,6 +564,11 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, Inkscape:: G_CALLBACK(handleSecondaryClick), this); + g_signal_connect( G_OBJECT(newBlot->gobj()), + "button-press-event", + G_CALLBACK(handleButtonPress), + this); + gtk_drag_source_set( GTK_WIDGET(newBlot->gobj()), GDK_BUTTON1_MASK, sourceColorEntries, -- 2.30.2