Commit c718872aef01d73e504f2862aa05a7896b341f8c

Authored by Perry Werneck
1 parent c85e42c2
Exists in master and in 1 other branch develop

Adding property to control de clipboard behavior.

src/include/terminal.h
... ... @@ -49,6 +49,7 @@ G_BEGIN_DECLS
49 49 V3270_SETTING_HOST_TYPE,
50 50 V3270_SETTING_CRL_PROTOCOL,
51 51 V3270_SETTING_TERMINAL_COLORS,
  52 + V3270_SETTING_SELECTION_OPTIONS,
52 53  
53 54 V3270_SETTING_COUNT ///< @brief Number of setting properties.
54 55 } V3270_SETTING;
... ... @@ -116,6 +117,16 @@ G_BEGIN_DECLS
116 117 #define KEY_FLAG_ALT 0x0002
117 118 #endif // !WIN32
118 119  
  120 + typedef enum _V3270SelectionOption {
  121 +
  122 + V3270_SELECTION_PLAIN_TEXT = 0x0000, ///< @brief Uses only plain text.
  123 + V3270_SELECTION_FONT_FAMILY = 0x0001, ///< @brief Inform font-family.
  124 + V3270_SELECTION_COLORS = 0x0002, ///< @brief Inform terminal colors.
  125 +
  126 + } V3270SelectionOption;
  127 +
  128 + #define V3270_SELECTION_DEFAULT (V3270_SELECTION_FONT_FAMILY|V3270_SELECTION_COLORS)
  129 +
119 130 /*--[ Globals ]--------------------------------------------------------------------------------------*/
120 131  
121 132 struct v3270_ssl_status_msg
... ... @@ -149,10 +160,11 @@ G_BEGIN_DECLS
149 160  
150 161 struct {
151 162  
152   - int baddr; ///< @brief Selection address.
153   - GdkAtom target; ///< @brief A GdkAtom which identifies the clipboard to use. GDK_SELECTION_CLIPBOARD gives the default clipboard.
154   - V3270_COPY_MODE format; ///< @brief Copy mode.
155   - GList * blocks; ///< @brief Selection blocks.
  163 + int baddr; ///< @brief Selection address.
  164 + GdkAtom target; ///< @brief A GdkAtom which identifies the clipboard to use. GDK_SELECTION_CLIPBOARD gives the default clipboard.
  165 + V3270_COPY_MODE format; ///< @brief Copy mode.
  166 + GList * blocks; ///< @brief Selection blocks.
  167 + V3270SelectionOption options; ///< @brief Selection options.
156 168  
157 169 } selection;
158 170  
... ...
src/selection/html.c
... ... @@ -53,17 +53,24 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
53 53 {
54 54 const GList * element = selection;
55 55 GString * string = g_string_new("");
56   - gchar * bgColor = gdk_rgba_to_string(terminal->color+V3270_COLOR_BACKGROUND);
  56 + gchar * bgColor;
57 57 gchar * fgColor;
58 58  
59   - g_string_append_printf(
60   - string,
61   - "<div style=\"font-family:%s,monospace;padding:1em;display:inline-block;background-color:%s\">",
62   - terminal->font.family,
63   - bgColor
64   - );
  59 + g_string_append(string,"<div style=\"padding:1em;display:inline-block");
65 60  
66   - g_free(bgColor);
  61 + if(terminal->selection.options & V3270_SELECTION_FONT_FAMILY)
  62 + {
  63 + g_string_append_printf(string,";font-family:%s,monospace",terminal->font.family);
  64 + }
  65 +
  66 + if(terminal->selection.options & V3270_SELECTION_COLORS)
  67 + {
  68 + bgColor = gdk_rgba_to_string(terminal->color+V3270_COLOR_BACKGROUND);
  69 + g_string_append_printf(string,";background-color:%s",bgColor);
  70 + g_free(bgColor);
  71 + }
  72 +
  73 + g_string_append(string,"\">");
67 74  
68 75 while(element)
69 76 {
... ... @@ -71,17 +78,20 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
71 78 unsigned int row, col, src = 0;
72 79 unsigned short flags = block->contents[0].attribute.visual;
73 80  
74   - get_element_colors(terminal,flags,&fgColor,&bgColor);
  81 + if(terminal->selection.options & V3270_SELECTION_COLORS)
  82 + {
  83 + get_element_colors(terminal,flags,&fgColor,&bgColor);
75 84  
76   - g_string_append_printf(
77   - string,
78   - "<span style=\"background-color:%s;color:%s\">",
79   - bgColor,
80   - fgColor
81   - );
  85 + g_string_append_printf(
  86 + string,
  87 + "<span style=\"background-color:%s;color:%s\">",
  88 + bgColor,
  89 + fgColor
  90 + );
82 91  
83   - g_free(bgColor);
84   - g_free(fgColor);
  92 + g_free(bgColor);
  93 + g_free(fgColor);
  94 + }
85 95  
86 96 #ifdef DEBUG
87 97 g_string_append_c(string,'\n');
... ... @@ -95,18 +105,20 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
95 105 {
96 106 flags = block->contents[src].attribute.visual;
97 107  
98   - get_element_colors(terminal,flags,&fgColor,&bgColor);
99   -
100   - g_string_append_printf(
101   - string,
102   - "</span><span style=\"background-color:%s;color:%s\">",
103   - bgColor,
104   - fgColor
105   - );
  108 + if(terminal->selection.options & V3270_SELECTION_COLORS)
  109 + {
  110 + get_element_colors(terminal,flags,&fgColor,&bgColor);
106 111  
107   - g_free(bgColor);
108   - g_free(fgColor);
  112 + g_string_append_printf(
  113 + string,
  114 + "</span><span style=\"background-color:%s;color:%s\">",
  115 + bgColor,
  116 + fgColor
  117 + );
109 118  
  119 + g_free(bgColor);
  120 + g_free(fgColor);
  121 + }
110 122  
111 123 }
112 124  
... ... @@ -128,7 +140,10 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
128 140 #endif // DEBUG
129 141 }
130 142  
131   - g_string_append(string,"</span>");
  143 + if(terminal->selection.options & V3270_SELECTION_COLORS)
  144 + {
  145 + g_string_append(string,"</span>");
  146 + }
132 147  
133 148 element = g_list_next(element);
134 149 }
... ... @@ -139,6 +154,8 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
139 154  
140 155 g_string_append(string,"</div>");
141 156  
  157 + debug("\n%s\n------------> %u",string->str,(unsigned int) terminal->selection.options);
  158 +
142 159 return g_string_free(string,FALSE);
143 160  
144 161 }
... ...
src/selection/linux/copy.c
... ... @@ -127,19 +127,24 @@ void v3270_update_system_clipboard(GtkWidget *widget)
127 127 //
128 128 // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html
129 129 //
130   - static const GtkTargetEntry internal_targets[] = {
131   - { "text/csv", 0, CLIPBOARD_TYPE_CSV },
132   - { "text/html", 0, CLIPBOARD_TYPE_HTML },
133   - { "application/x-v3270-unprotected", 0, CLIPBOARD_TYPE_V3270_UNPROTECTED },
134   - };
135   -
136   - GtkTargetList * list = gtk_target_list_new(internal_targets, G_N_ELEMENTS(internal_targets));
137   - GtkTargetEntry * targets;
138   - int n_targets;
  130 + GtkTargetList * list = gtk_target_list_new(NULL,0);
139 131  
140 132 gtk_target_list_add_text_targets(list, CLIPBOARD_TYPE_TEXT);
141 133  
142   - targets = gtk_target_table_new_from_list(list, &n_targets);
  134 + if(terminal->selection.options != V3270_SELECTION_PLAIN_TEXT)
  135 + {
  136 + static const GtkTargetEntry targets[] = {
  137 + { "text/csv", 0, CLIPBOARD_TYPE_CSV },
  138 + { "text/html", 0, CLIPBOARD_TYPE_HTML },
  139 + { "application/x-v3270-unprotected", 0, CLIPBOARD_TYPE_V3270_UNPROTECTED },
  140 + };
  141 +
  142 + gtk_target_list_add_table(list, targets, G_N_ELEMENTS(targets));
  143 +
  144 + }
  145 +
  146 + int n_targets;
  147 + GtkTargetEntry * targets = gtk_target_table_new_from_list(list, &n_targets);
143 148  
144 149 #ifdef DEBUG
145 150 {
... ...
src/terminal/actions/scroll.c
... ... @@ -39,9 +39,12 @@
39 39 /*--[ Implement ]------------------------------------------------------------------------------------*/
40 40  
41 41 // Callback for compatibility with the old application.
42   -static void activate_action(GtkWidget *terminal, GtkAction *action)
  42 +static void activate_action(GtkWidget G_GNUC_UNUSED(*terminal), GtkAction *action)
43 43 {
  44 + #pragma GCC diagnostic push
  45 + #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
44 46 gtk_action_activate(action);
  47 + #pragma GCC diagnostic pop
45 48 }
46 49  
47 50 LIB3270_EXPORT void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, GtkAction *action)
... ...
src/terminal/keyfile.c
... ... @@ -189,6 +189,8 @@
189 189 return;
190 190 }
191 191  
  192 + debug("%s(%s)",__FUNCTION__,name);
  193 +
192 194 GValue value = G_VALUE_INIT;
193 195 g_value_init(&value, pspec->value_type);
194 196  
... ...
src/terminal/properties/get.c
... ... @@ -139,6 +139,10 @@
139 139 }
140 140 break;
141 141  
  142 + case V3270_PROPERTY_SELECTION_OPTIONS:
  143 + g_value_set_uint(value,(guint) window->selection.options);
  144 + break;
  145 +
142 146 default:
143 147 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
144 148  
... ...
src/terminal/properties/init.c
... ... @@ -224,6 +224,26 @@
224 224 klass->properties.settings[V3270_SETTING_TERMINAL_COLORS]
225 225 );
226 226  
  227 + // Clipboard options
  228 + klass->properties.settings[V3270_SETTING_SELECTION_OPTIONS] =
  229 + g_param_spec_uint(
  230 + "selection_flags",
  231 + "selection_flags",
  232 + _("Flags to cut&paste"),
  233 + 0,
  234 + G_MAXUINT,
  235 + V3270_SELECTION_DEFAULT,
  236 + G_PARAM_READABLE|G_PARAM_WRITABLE
  237 + );
  238 +
  239 + g_object_class_install_property(
  240 + gobject_class,
  241 + V3270_PROPERTY_SELECTION_OPTIONS,
  242 + klass->properties.settings[V3270_SETTING_SELECTION_OPTIONS]
  243 + );
  244 +
  245 +
  246 +
227 247 //
228 248 // Create dynamic properties
229 249 //
... ...
src/terminal/properties/private.h
... ... @@ -48,17 +48,18 @@
48 48  
49 49 enum _v3270_internal_property
50 50 {
51   - V3270_PROPERTY_FONT_FAMILY = 2, ///< @brief Name of the font-family used by widget.
52   - V3270_PROPERTY_CLIPBOARD = 3, ///< @brief Name of the selected clipboard.
53   - V3270_PROPERTY_SESSION_NAME = 4, ///< @brief Widget's session name.
54   - V3270_PROPERTY_AUTO_DISCONNECT = 5, ///< @brief Auto disconnect.
55   - V3270_PROPERTY_REMAP_FILE = 6, ///< @brief Path of the remap file.
56   - V3270_PROPERTY_DYNAMIC_SPACING = 7, ///< @brief Toggle dynamic font spacing.
57   - V3270_PROPERTY_LU_NAMES = 8, ///< @brief The LU names list.
58   - V3270_PROPERTY_TRACE = 9, ///< @brief Is the trace widget active?
59   - V3270_PROPERTY_TERMINAL_COLORS = 10, ///< @brief Terminal colors.
  51 + V3270_PROPERTY_FONT_FAMILY = 2, ///< @brief Name of the font-family used by widget.
  52 + V3270_PROPERTY_CLIPBOARD = 3, ///< @brief Name of the selected clipboard.
  53 + V3270_PROPERTY_SESSION_NAME = 4, ///< @brief Widget's session name.
  54 + V3270_PROPERTY_AUTO_DISCONNECT = 5, ///< @brief Auto disconnect.
  55 + V3270_PROPERTY_REMAP_FILE = 6, ///< @brief Path of the remap file.
  56 + V3270_PROPERTY_DYNAMIC_SPACING = 7, ///< @brief Toggle dynamic font spacing.
  57 + V3270_PROPERTY_LU_NAMES = 8, ///< @brief The LU names list.
  58 + V3270_PROPERTY_TRACE = 9, ///< @brief Is the trace widget active?
  59 + V3270_PROPERTY_TERMINAL_COLORS = 10, ///< @brief Terminal colors.
  60 + V3270_PROPERTY_SELECTION_OPTIONS = 11,
60 61  
61   - V3270_PROPERTY_DYNAMIC = 11 ///< @brief Id of the first LIB3270 internal property.
  62 + V3270_PROPERTY_DYNAMIC = 12 ///< @brief Id of the first LIB3270 internal property.
62 63 };
63 64  
64 65 G_GNUC_INTERNAL void v3270_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
... ...
src/terminal/properties/set.c
... ... @@ -138,6 +138,10 @@
138 138 v3270_set_colors(GTK_WIDGET(object),g_value_get_string(value));
139 139 break;
140 140  
  141 + case V3270_PROPERTY_SELECTION_OPTIONS:
  142 + GTK_V3270(object)->selection.options = (V3270SelectionOption) g_value_get_uint(value);
  143 + break;
  144 +
141 145 default:
142 146 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
143 147  
... ...
src/terminal/widget.c
... ... @@ -499,6 +499,7 @@ static void v3270_init(v3270 *widget)
499 499  
500 500 // Setup clipboard.
501 501 widget->selection.target = GDK_SELECTION_CLIPBOARD;
  502 + widget->selection.options = V3270_SELECTION_DEFAULT;
502 503  
503 504 // Reset timer
504 505 widget->activity.timestamp = time(0);
... ...