diff --git a/src/clipboard/linux/paste.c b/src/clipboard/linux/paste.c index 24e2f44..1ccf4fa 100644 --- a/src/clipboard/linux/paste.c +++ b/src/clipboard/linux/paste.c @@ -33,7 +33,7 @@ static void text_received(G_GNUC_UNUSED GtkClipboard *clipboard, const gchar *text, GtkWidget *widget) { - v3270_paste_string(widget,text,"UTF-8"); + v3270_paste_text(widget,text,"UTF-8"); } LIB3270_EXPORT void v3270_paste(GtkWidget *widget) diff --git a/src/clipboard/selection.c b/src/clipboard/selection.c index f1fe0cf..d097d1a 100644 --- a/src/clipboard/selection.c +++ b/src/clipboard/selection.c @@ -31,11 +31,13 @@ /*--[ Globals ]--------------------------------------------------------------------------------------*/ +/* static const GtkTargetEntry targets[] = { { "COMPOUND_TEXT", 0, CLIPBOARD_TYPE_TEXT }, { "UTF8_STRING", 0, CLIPBOARD_TYPE_TEXT }, }; +*/ /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -47,6 +49,8 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa { v3270 * widget = GTK_V3270(obj); + debug("%s target=%u",__FUNCTION__,(unsigned int) target); + switch(target) { case CLIPBOARD_TYPE_TEXT: /* Get clipboard contents as text */ @@ -157,10 +161,30 @@ void v3270_update_system_clipboard(GtkWidget *widget) { GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD); + // Create target list + // + // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html + // + GtkTargetList * list = gtk_target_list_new(NULL, 0); + GtkTargetEntry * targets; + int n_targets; + + gtk_target_list_add_text_targets(list, CLIPBOARD_TYPE_TEXT); + targets = gtk_target_table_new_from_list(list, &n_targets); + +#ifdef DEBUG + { + int ix; + for(ix = 0; ix < n_targets; ix++) { + debug("target(%d)=\"%s\"",ix,targets[ix].target); + } + } +#endif // DEBUG + if(gtk_clipboard_set_with_owner( clipboard, targets, - G_N_ELEMENTS(targets), + n_targets, (GtkClipboardGetFunc) clipboard_get, (GtkClipboardClearFunc) clipboard_clear, G_OBJECT(widget) @@ -169,11 +193,14 @@ void v3270_update_system_clipboard(GtkWidget *widget) gtk_clipboard_set_can_store(clipboard,targets,1); } + gtk_target_table_free(targets, n_targets); + gtk_target_list_unref(list); + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); } } -LIB3270_EXPORT void v3270_copy(GtkWidget *widget, V3270_SELECT_FORMAT mode, gboolean cut) +LIB3270_EXPORT void v3270_copy_text(GtkWidget *widget, V3270_SELECT_FORMAT mode, gboolean cut) { g_return_if_fail(GTK_IS_V3270(widget)); GTK_V3270(widget)->selection.format = mode; diff --git a/src/clipboard/text.c b/src/clipboard/text.c index 322822a..ad7b805 100644 --- a/src/clipboard/text.c +++ b/src/clipboard/text.c @@ -30,7 +30,7 @@ #include -LIB3270_EXPORT void v3270_copy_append(GtkWidget *widget) +LIB3270_EXPORT void v3270_copy_text_append(GtkWidget *widget) { v3270 * terminal; char * str; @@ -42,7 +42,7 @@ LIB3270_EXPORT void v3270_copy_append(GtkWidget *widget) if(!terminal->selection.text) { // Clipboard is empty, do a single copy - v3270_copy(widget, V3270_SELECT_TEXT, FALSE); + v3270_copy_text(widget, V3270_SELECT_TEXT, FALSE); return; } @@ -161,7 +161,7 @@ const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut) } -LIB3270_EXPORT void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding) +LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget, const gchar *text, const gchar *encoding) { gchar * buffer = NULL; H3270 * session = v3270_get_session(widget); diff --git a/src/clipboard/windows/paste.c b/src/clipboard/windows/paste.c index 08dde4a..277f826 100644 --- a/src/clipboard/windows/paste.c +++ b/src/clipboard/windows/paste.c @@ -48,7 +48,7 @@ LIB3270_EXPORT void v3270_paste(GtkWidget *widget) LPTSTR lptstr = GlobalLock(hglb); if (lptstr != NULL) { - v3270_paste_string(widget,lptstr,"CP1252"); + v3270_paste_text(widget,lptstr,"CP1252"); GlobalUnlock(hglb); } } diff --git a/src/include/v3270.h b/src/include/v3270.h index 8c62d4d..e3de2a5 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -189,8 +189,6 @@ V3270_SELECT_MAX } V3270_SELECT_FORMAT; - LIB3270_EXPORT void v3270_copy(GtkWidget *widget, V3270_SELECT_FORMAT mode, gboolean cut); - LIB3270_EXPORT void v3270_copy_append(GtkWidget *widget); LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut); LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget); LIB3270_EXPORT void v3270_set_copy(GtkWidget *widget, const gchar *text); @@ -206,10 +204,14 @@ LIB3270_EXPORT gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end); LIB3270_EXPORT void v3270_unselect(GtkWidget *widget); LIB3270_EXPORT void v3270_select_all(GtkWidget *widget); - LIB3270_EXPORT void v3270_paste(GtkWidget *widget); - LIB3270_EXPORT void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); LIB3270_EXPORT void v3270_select_region(GtkWidget *widget, gint start, gint end); + LIB3270_EXPORT void v3270_copy_text(GtkWidget *widget, V3270_SELECT_FORMAT mode, gboolean cut); + LIB3270_EXPORT void v3270_copy_text_append(GtkWidget *widget); + + LIB3270_EXPORT void v3270_paste(GtkWidget *widget); + LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget, const gchar *text, const gchar *encoding); + // Colors LIB3270_EXPORT void v3270_set_colors(GtkWidget *widget, const gchar *); LIB3270_EXPORT void v3270_set_color_table(GdkRGBA *table, const gchar *colors); diff --git a/src/trace/exec.c b/src/trace/exec.c index eca79ca..7fa217a 100644 --- a/src/trace/exec.c +++ b/src/trace/exec.c @@ -106,49 +106,6 @@ g_value_unset(&val); return 0; - /* - size_t ix; - - debug("%s=%s",name,value); - - // Check toggles - for(ix = 0; ix < (size_t) LIB3270_TOGGLE_COUNT; ix++) - { - if(g_ascii_strcasecmp(name,lib3270_get_toggle_name((LIB3270_TOGGLE) ix)) == 0) - return lib3270_set_toggle(hSession,(LIB3270_TOGGLE) ix, atoi(value)); - - } - - // Check boolean properties - const LIB3270_INT_PROPERTY * bProp = lib3270_get_boolean_properties_list(); - for(ix = 0; bProp[ix].name; ix++) - { - if(g_ascii_strcasecmp(name,bProp[ix].name) == 0 && bProp[ix].set) - return bProp[ix].set(hSession,atoi(value)); - - } - - // Check integer properties - const LIB3270_INT_PROPERTY * iProp = lib3270_get_int_properties_list(); - for(ix = 0; iProp[ix].name; ix++) - { - if(g_ascii_strcasecmp(name,iProp[ix].name) == 0 && iProp[ix].set) - return iProp[ix].set(hSession,atoi(value)); - - } - - // Check string properties - const LIB3270_STRING_PROPERTY * sProp = lib3270_get_string_properties_list(); - for(ix = 0; sProp[ix].name; ix++) - { - if(g_ascii_strcasecmp(name,sProp[ix].name) == 0 && sProp[ix].set) - return sProp[ix].set(hSession,value); - - } - */ - - return errno = ENOENT; - } static int get_property(GtkWidget *widget, const gchar *name) @@ -217,6 +174,24 @@ return 0; } + if(g_str_has_prefix(cmdline,"copy")) + { + gchar * arg = cmdline+4; + g_strstrip(arg); + + if(!(*arg && g_ascii_strcasecmp(arg,"text"))) + { + // No argument or "text" copy text. + v3270_copy_text(widget, V3270_SELECT_TEXT, FALSE); + } + else if(!g_ascii_strcasecmp(arg,"table")) + { + v3270_copy_text(widget, V3270_SELECT_TABLE, FALSE); + } + + return 0; + } + if(g_str_has_suffix(cmdline,"?")) { gchar * str = strchr(cmdline,'?'); -- libgit2 0.21.2