From 91d5b4301c473539d268b8c9c35b9c43a3b62cf3 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 16 Jul 2019 15:10:43 -0300 Subject: [PATCH] Adding property "clipboar" on v3270 widget to allow set of which clipboard will be used. --- src/clipboard/selection.c | 6 +----- src/include/terminal.h | 1 + src/terminal/properties.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------- src/terminal/widget.c | 3 +++ 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/clipboard/selection.c b/src/clipboard/selection.c index 9a53640..d28588d 100644 --- a/src/clipboard/selection.c +++ b/src/clipboard/selection.c @@ -143,11 +143,7 @@ void v3270_update_system_clipboard(GtkWidget *widget) } // Has clipboard data, inform system. -//#ifdef DEBUG -// GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_PRIMARY); -//#else - GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD); -//#endif // DEBUG + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); // Create target list // diff --git a/src/include/terminal.h b/src/include/terminal.h index 5921fa7..6a427e8 100644 --- a/src/include/terminal.h +++ b/src/include/terminal.h @@ -118,6 +118,7 @@ G_BEGIN_DECLS struct { int baddr; ///< @brief Selection address. + GdkAtom target; ///< @brief A GdkAtom which identifies the clipboard to use. GDK_SELECTION_CLIPBOARD gives the default clipboard. V3270_SELECT_FORMAT format; ///< @brief Copy format. GList * blocks; ///< @brief Selection blocks. diff --git a/src/terminal/properties.c b/src/terminal/properties.c index 4652465..a37af78 100644 --- a/src/terminal/properties.c +++ b/src/terminal/properties.c @@ -45,7 +45,9 @@ #include #include - #define PROP_BEGIN 2 + #define PROP_FONT_FAMILY 2 + #define PROP_CLIPBOARD 3 + #define PROP_DYNAMIC 4 /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -92,10 +94,32 @@ // Check for internal properties. switch(prop_id) { - case PROP_BEGIN: // Font-family + case PROP_FONT_FAMILY: // Font-family v3270_set_font_family(GTK_WIDGET(object), g_value_get_string(value)); break; + case PROP_CLIPBOARD: // Clipboard + { + const gchar * name = g_value_get_string(value); + if(!*name) { + g_message("Setting default clipboard"); + window->selection.target = GDK_SELECTION_CLIPBOARD; + } + else + { + GdkAtom clipboard = gdk_atom_intern(name,TRUE); + if(clipboard == GDK_NONE) + { + g_warning("\"%s\" is not a valid clipboard name",name); + } + else + { + window->selection.target = clipboard; + } + } + } + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -146,10 +170,14 @@ // Check for internal properties. switch(prop_id) { - case PROP_BEGIN: // Font-family + case PROP_FONT_FAMILY: // Font-family g_value_set_string(value,v3270_get_font_family(GTK_WIDGET(object))); break; + case PROP_CLIPBOARD: // Clipboard + g_value_take_string(value,gdk_atom_name(window->selection.target)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -202,9 +230,9 @@ gobject_class->set_property = v3270_set_property; gobject_class->get_property = v3270_get_property; - klass->properties.count = PROP_BEGIN; - // Setup internal properties. + + // Font family klass->properties.font_family = g_param_spec_string( "font_family", "font_family", @@ -215,14 +243,33 @@ g_object_class_install_property( gobject_class, - klass->properties.count++, + PROP_FONT_FAMILY, klass->properties.font_family ); + // Clipboard + spec = g_param_spec_string( + "clipboard", + "clipboard", + _("Clipboard name"), + FALSE, + G_PARAM_READABLE|G_PARAM_WRITABLE + ); + + g_object_class_install_property( + gobject_class, + PROP_CLIPBOARD, + spec + ); + + // + // Create dynamic properties + klass->properties.count = PROP_DYNAMIC; + + // // Extract properties from LIB3270 control tables // - // Extract toggle class. klass->properties.type.toggle = klass->properties.count; for(ix = 0; ix < LIB3270_TOGGLE_COUNT; ix++) diff --git a/src/terminal/widget.c b/src/terminal/widget.c index a28fe83..9a32bfd 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.c @@ -541,6 +541,9 @@ static void v3270_init(v3270 *widget) // Install callbacks v3270_install_callbacks(widget); + // Setup clipboard. + widget->selection.target = GDK_SELECTION_CLIPBOARD; + // Reset timer widget->activity.timestamp = time(0); widget->activity.disconnect = 0; -- libgit2 0.21.2