Commit d6e1a58bda6ef2dc2d3a6032fea33a19cfd06c73
1 parent
a2973972
Exists in
master
and in
1 other branch
Working in the new "save" dialog.
Showing
7 changed files
with
220 additions
and
81 deletions
Show diff stats
src/dialogs/save/private.h
src/dialogs/save/save.c
| @@ -35,6 +35,28 @@ | @@ -35,6 +35,28 @@ | ||
| 35 | 35 | ||
| 36 | G_DEFINE_TYPE(V3270SaveDialog, V3270SaveDialog, GTK_TYPE_DIALOG); | 36 | G_DEFINE_TYPE(V3270SaveDialog, V3270SaveDialog, GTK_TYPE_DIALOG); |
| 37 | 37 | ||
| 38 | +/*--[ Formats ]--------------------------------------------------------------------------------------*/ | ||
| 39 | + | ||
| 40 | + static const struct _formats | ||
| 41 | + { | ||
| 42 | + const gchar *name; | ||
| 43 | + const gchar *extension; | ||
| 44 | + } formats[] = | ||
| 45 | + { | ||
| 46 | + { | ||
| 47 | + N_("Plain text"), | ||
| 48 | + ".txt" | ||
| 49 | + }, | ||
| 50 | + { | ||
| 51 | + N_("Comma-separated values (CSV)"), | ||
| 52 | + ".csv" | ||
| 53 | + }, | ||
| 54 | + { | ||
| 55 | + N_("HyperText Markup Language (HTML)"), | ||
| 56 | + ".html" | ||
| 57 | + } | ||
| 58 | + }; | ||
| 59 | + | ||
| 38 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 60 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 39 | 61 | ||
| 40 | /* | 62 | /* |
| @@ -44,7 +66,7 @@ | @@ -44,7 +66,7 @@ | ||
| 44 | } | 66 | } |
| 45 | */ | 67 | */ |
| 46 | 68 | ||
| 47 | - static void V3270SaveDialog_class_init(V3270SaveDialogClass *klass) | 69 | + static void V3270SaveDialog_class_init(V3270SaveDialogClass G_GNUC_UNUSED(*klass)) |
| 48 | { | 70 | { |
| 49 | 71 | ||
| 50 | debug("%s",__FUNCTION__); | 72 | debug("%s",__FUNCTION__); |
| @@ -64,6 +86,11 @@ | @@ -64,6 +86,11 @@ | ||
| 64 | 86 | ||
| 65 | static void V3270SaveDialog_init(V3270SaveDialog *dialog) | 87 | static void V3270SaveDialog_init(V3270SaveDialog *dialog) |
| 66 | { | 88 | { |
| 89 | + // 0--------1---------------------2-------3------------------ | ||
| 90 | + // 0 - Filename xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx. | ||
| 91 | + // 1 - Charset xxxxxxxxx.xxxxxxxxx. Format: xxxxxxxxx.xxxxxxxxx. | ||
| 92 | + | ||
| 93 | + | ||
| 67 | dialog->mode = LIB3270_CONTENT_ALL; | 94 | dialog->mode = LIB3270_CONTENT_ALL; |
| 68 | 95 | ||
| 69 | gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | 96 | gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); |
| @@ -82,57 +109,159 @@ | @@ -82,57 +109,159 @@ | ||
| 82 | gtk_grid_set_column_spacing(GTK_GRID(grid),12); | 109 | gtk_grid_set_column_spacing(GTK_GRID(grid),12); |
| 83 | gtk_box_pack_start(box,GTK_WIDGET(grid),TRUE,TRUE,2); | 110 | gtk_box_pack_start(box,GTK_WIDGET(grid),TRUE,TRUE,2); |
| 84 | 111 | ||
| 85 | - dialog->filename = gtk_entry_new(); | ||
| 86 | - gtk_widget_set_hexpand(GTK_WIDGET(dialog->filename),TRUE); | 112 | + // Filename entry |
| 113 | + { | ||
| 114 | + dialog->filename = gtk_entry_new(); | ||
| 115 | + gtk_widget_set_hexpand(GTK_WIDGET(dialog->filename),TRUE); | ||
| 87 | 116 | ||
| 88 | - widget = gtk_label_new_with_mnemonic("_Filename:"); | ||
| 89 | - gtk_widget_set_halign(widget,GTK_ALIGN_END); | ||
| 90 | - gtk_widget_set_valign(widget,GTK_ALIGN_CENTER); | ||
| 91 | - gtk_grid_attach(grid,GTK_WIDGET(widget),0,0,1,1); | ||
| 92 | - gtk_label_set_mnemonic_widget(GTK_LABEL(widget),dialog->filename); | 117 | + widget = gtk_label_new_with_mnemonic(_("_Filename")); |
| 118 | + gtk_widget_set_halign(widget,GTK_ALIGN_END); | ||
| 119 | + gtk_widget_set_valign(widget,GTK_ALIGN_CENTER); | ||
| 120 | + gtk_grid_attach(grid,widget,0,0,1,1); | ||
| 121 | + gtk_label_set_mnemonic_widget(GTK_LABEL(widget),dialog->filename); | ||
| 93 | 122 | ||
| 94 | #ifdef WIN32 | 123 | #ifdef WIN32 |
| 95 | - widget = gtk_button_new_from_icon_name("document-open",GTK_ICON_SIZE_BUTTON); | ||
| 96 | - //g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(select_local_file),dialog); | ||
| 97 | - gtk_grid_attach(grid,widget,2,0,1,1); | 124 | + widget = gtk_button_new_from_icon_name("document-open",GTK_ICON_SIZE_BUTTON); |
| 125 | + //g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(select_local_file),dialog); | ||
| 126 | + gtk_grid_attach(grid,widget,6,0,1,1); | ||
| 98 | #else | 127 | #else |
| 99 | - gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-open"); | ||
| 100 | - gtk_entry_set_icon_activatable(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,TRUE); | ||
| 101 | - gtk_entry_set_icon_tooltip_text(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,_("Select file")); | ||
| 102 | - // g_signal_connect(G_OBJECT(dialog->filename),"icon-press",G_CALLBACK(icon_press),dialog); | 128 | + gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-open"); |
| 129 | + gtk_entry_set_icon_activatable(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,TRUE); | ||
| 130 | + gtk_entry_set_icon_tooltip_text(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,_("Select file")); | ||
| 131 | + // g_signal_connect(G_OBJECT(dialog->filename),"icon-press",G_CALLBACK(icon_press),dialog); | ||
| 103 | #endif // WIN32 | 132 | #endif // WIN32 |
| 104 | 133 | ||
| 105 | - gtk_entry_set_width_chars(GTK_ENTRY(dialog->filename),60); | ||
| 106 | - gtk_entry_set_max_length(GTK_ENTRY(dialog->filename),PATH_MAX); | ||
| 107 | - gtk_grid_attach(grid,GTK_WIDGET(dialog->filename),1,0,1,1); | 134 | + gtk_entry_set_width_chars(GTK_ENTRY(dialog->filename),60); |
| 135 | + gtk_entry_set_max_length(GTK_ENTRY(dialog->filename),PATH_MAX); | ||
| 136 | + gtk_grid_attach(grid,GTK_WIDGET(dialog->filename),1,0,3,1); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + // Charset drop-down | ||
| 140 | + { | ||
| 141 | + static const struct _charsets | ||
| 142 | + { | ||
| 143 | + const gchar *name; | ||
| 144 | + const gchar *description; | ||
| 145 | + } charsets[] = | ||
| 146 | + { | ||
| 147 | + // http://en.wikipedia.org/wiki/Character_encoding | ||
| 148 | + { "UTF-8", N_( "UTF-8" ) }, | ||
| 149 | + { "ISO-8859-1", N_( "Western Europe (ISO 8859-1)" ) }, | ||
| 150 | + { "CP1252", N_( "Windows Western languages (CP1252)" ) }, | ||
| 151 | + }; | ||
| 152 | + | ||
| 153 | + size_t ix; | ||
| 154 | + const gchar * scharset = NULL; | ||
| 155 | + | ||
| 156 | + widget = gtk_label_new_with_mnemonic (_("C_haracter Coding")); | ||
| 157 | + gtk_widget_set_halign(widget,GTK_ALIGN_END); | ||
| 158 | + gtk_widget_set_valign(widget,GTK_ALIGN_CENTER); | ||
| 159 | + gtk_grid_attach(grid,widget,0,1,1,1); | ||
| 160 | + | ||
| 161 | + dialog->charset = gtk_combo_box_text_new(); | ||
| 162 | + | ||
| 163 | + g_get_charset(&scharset); | ||
| 164 | + | ||
| 165 | + g_autofree gchar * text = g_strdup_printf(_("Current (%s)"),scharset); | ||
| 166 | + gtk_combo_box_text_insert( | ||
| 167 | + GTK_COMBO_BOX_TEXT(dialog->charset), | ||
| 168 | + 0, | ||
| 169 | + scharset, | ||
| 170 | + text | ||
| 171 | + ); | ||
| 172 | + | ||
| 173 | + gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->charset),0); | ||
| 174 | + | ||
| 175 | + gtk_grid_attach(grid,dialog->charset,1,1,1,1); | ||
| 176 | + | ||
| 177 | + for(ix=0;ix<G_N_ELEMENTS(charsets);ix++) | ||
| 178 | + { | ||
| 179 | + if(g_ascii_strcasecmp(charsets[ix].name,scharset)) | ||
| 180 | + { | ||
| 181 | + gtk_combo_box_text_insert( | ||
| 182 | + GTK_COMBO_BOX_TEXT(dialog->charset), | ||
| 183 | + ix+1, | ||
| 184 | + charsets[ix].name, | ||
| 185 | + gettext(charsets[ix].description) | ||
| 186 | + ); | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + // Format drop-down | ||
| 193 | + { | ||
| 194 | + size_t ix; | ||
| 195 | + | ||
| 196 | + widget = gtk_label_new_with_mnemonic (_("File _Format")); | ||
| 197 | + gtk_widget_set_halign(widget,GTK_ALIGN_END); | ||
| 198 | + gtk_widget_set_valign(widget,GTK_ALIGN_CENTER); | ||
| 199 | + gtk_grid_attach(grid,widget,2,1,1,1); | ||
| 200 | + | ||
| 201 | + dialog->format = gtk_combo_box_text_new(); | ||
| 202 | + gtk_grid_attach(grid,dialog->format,3,1,1,1); | ||
| 203 | + | ||
| 204 | + for(ix=0;ix<G_N_ELEMENTS(formats);ix++) | ||
| 205 | + { | ||
| 206 | + gtk_combo_box_text_insert( | ||
| 207 | + GTK_COMBO_BOX_TEXT(dialog->format), | ||
| 208 | + ix, | ||
| 209 | + formats[ix].extension, | ||
| 210 | + gettext(formats[ix].name) | ||
| 211 | + ); | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->format),0); | ||
| 215 | + | ||
| 216 | + } | ||
| 217 | + | ||
| 108 | 218 | ||
| 109 | // Buttons | 219 | // Buttons |
| 110 | // https://developer.gnome.org/icon-naming-spec/ | 220 | // https://developer.gnome.org/icon-naming-spec/ |
| 111 | #if GTK_CHECK_VERSION(3,14,0) | 221 | #if GTK_CHECK_VERSION(3,14,0) |
| 112 | - | ||
| 113 | widget = gtk_dialog_get_header_bar(GTK_DIALOG(dialog)); | 222 | widget = gtk_dialog_get_header_bar(GTK_DIALOG(dialog)); |
| 114 | - | ||
| 115 | - button = gtk_button_new_with_mnemonic(_("_Cancel")); | ||
| 116 | - gtk_widget_set_tooltip_markup(button,_("Click to cancel operation")); | ||
| 117 | - gtk_header_bar_pack_start(GTK_HEADER_BAR(widget),button); | ||
| 118 | - g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(cancel_operation),dialog); | ||
| 119 | - | ||
| 120 | - button = gtk_button_new_with_mnemonic(_("_Save")); | ||
| 121 | - gtk_widget_set_tooltip_markup(button,_("Click to save file")); | ||
| 122 | - gtk_header_bar_pack_end(GTK_HEADER_BAR(widget),button); | ||
| 123 | - g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(apply_operation),dialog); | ||
| 124 | - | ||
| 125 | #else | 223 | #else |
| 126 | - | ||
| 127 | - #error TODO! | ||
| 128 | - | 224 | + widget = NULL; |
| 129 | #endif // GTK(3,14,0) | 225 | #endif // GTK(3,14,0) |
| 130 | 226 | ||
| 227 | + if(widget) | ||
| 228 | + { | ||
| 229 | + // Have header bar | ||
| 230 | + button = gtk_button_new_with_mnemonic(_("_Cancel")); | ||
| 231 | + gtk_widget_set_tooltip_markup(button,_("Click to cancel operation")); | ||
| 232 | + gtk_header_bar_pack_start(GTK_HEADER_BAR(widget),button); | ||
| 233 | + g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(cancel_operation),dialog); | ||
| 234 | + | ||
| 235 | + button = gtk_button_new_with_mnemonic(_("_Save")); | ||
| 236 | + gtk_widget_set_tooltip_markup(button,_("Click to save file")); | ||
| 237 | + gtk_header_bar_pack_end(GTK_HEADER_BAR(widget),button); | ||
| 238 | + g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(apply_operation),dialog); | ||
| 239 | + } | ||
| 240 | + else | ||
| 241 | + { | ||
| 242 | + gtk_dialog_add_buttons( | ||
| 243 | + GTK_DIALOG (dialog), | ||
| 244 | + _("_Cancel"), GTK_RESPONSE_CANCEL, | ||
| 245 | + _("_Save"), GTK_RESPONSE_APPLY, | ||
| 246 | + NULL | ||
| 247 | + ); | ||
| 248 | + } | ||
| 249 | + | ||
| 131 | } | 250 | } |
| 132 | 251 | ||
| 133 | GtkWidget * v3270_save_dialog_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, const gchar *filename) | 252 | GtkWidget * v3270_save_dialog_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, const gchar *filename) |
| 134 | { | 253 | { |
| 135 | - V3270SaveDialog * dialog = V3270_SAVE_DIALOG(g_object_new(GTK_TYPE_V3270SaveDialog,"use-header-bar", (gint) 1, NULL)); | 254 | + gboolean use_header; |
| 255 | + g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &use_header, NULL); | ||
| 256 | + | ||
| 257 | + // Create dialog | ||
| 258 | + V3270SaveDialog * dialog = V3270_SAVE_DIALOG( | ||
| 259 | + g_object_new( | ||
| 260 | + GTK_TYPE_V3270SaveDialog, | ||
| 261 | + "use-header-bar", (use_header ? 1 : 0), | ||
| 262 | + NULL) | ||
| 263 | + ); | ||
| 264 | + | ||
| 136 | dialog->mode = mode; | 265 | dialog->mode = mode; |
| 137 | 266 | ||
| 138 | if(filename) | 267 | if(filename) |
src/include/clipboard.h
| @@ -87,12 +87,17 @@ | @@ -87,12 +87,17 @@ | ||
| 87 | 87 | ||
| 88 | G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget); | 88 | G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget); |
| 89 | G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut); | 89 | G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut); |
| 90 | - G_GNUC_INTERNAL GList * v3270_getColumns_from_selection(v3270 * terminal); | 90 | + G_GNUC_INTERNAL GList * v3270_getColumns_from_selection(v3270 * terminal, const GList *selection); |
| 91 | 91 | ||
| 92 | /// @brief Get contents. | 92 | /// @brief Get contents. |
| 93 | - G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal); | ||
| 94 | - G_GNUC_INTERNAL gchar * v3270_get_copy_as_html(v3270 * terminal); | ||
| 95 | - G_GNUC_INTERNAL gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter); | 93 | + G_GNUC_INTERNAL gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, const gchar *encoding); |
| 94 | + G_GNUC_INTERNAL gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, const gchar *delimiter, const gchar *encoding); | ||
| 95 | + | ||
| 96 | + | ||
| 97 | + | ||
| 98 | + G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal, const gchar *encoding); | ||
| 99 | + G_GNUC_INTERNAL gchar * v3270_get_copy_as_html(v3270 * terminal, const gchar *encoding); | ||
| 100 | + G_GNUC_INTERNAL gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter, const gchar *encoding); | ||
| 96 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_data_block(v3270 * terminal); | 101 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_data_block(v3270 * terminal); |
| 97 | 102 | ||
| 98 | /// @brief Set contents. | 103 | /// @brief Set contents. |
src/selection/html.c
| @@ -49,12 +49,12 @@ static void get_element_colors(v3270 * terminal, unsigned short attr, gchar **fg | @@ -49,12 +49,12 @@ static void get_element_colors(v3270 * terminal, unsigned short attr, gchar **fg | ||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | /// @brief Get formatted contents as HTML DIV. | 51 | /// @brief Get formatted contents as HTML DIV. |
| 52 | -static gchar * get_as_div(v3270 * terminal) | 52 | +static gchar * get_as_div(v3270 * terminal, const GList *selection) |
| 53 | { | 53 | { |
| 54 | - GList * element = terminal->selection.blocks; | ||
| 55 | - GString * string = g_string_new(""); | ||
| 56 | - gchar * bgColor = gdk_rgba_to_string(terminal->color+V3270_COLOR_BACKGROUND); | ||
| 57 | - gchar * fgColor; | 54 | + const GList * element = selection; |
| 55 | + GString * string = g_string_new(""); | ||
| 56 | + gchar * bgColor = gdk_rgba_to_string(terminal->color+V3270_COLOR_BACKGROUND); | ||
| 57 | + gchar * fgColor; | ||
| 58 | 58 | ||
| 59 | g_string_append_printf( | 59 | g_string_append_printf( |
| 60 | string, | 60 | string, |
| @@ -67,7 +67,7 @@ static gchar * get_as_div(v3270 * terminal) | @@ -67,7 +67,7 @@ static gchar * get_as_div(v3270 * terminal) | ||
| 67 | 67 | ||
| 68 | while(element) | 68 | while(element) |
| 69 | { | 69 | { |
| 70 | - lib3270_selection * block = ((lib3270_selection *) element->data); | 70 | + const lib3270_selection * block = ((const lib3270_selection *) element->data); |
| 71 | unsigned int row, col, src = 0; | 71 | unsigned int row, col, src = 0; |
| 72 | unsigned short flags = block->contents[0].attribute.visual; | 72 | unsigned short flags = block->contents[0].attribute.visual; |
| 73 | 73 | ||
| @@ -144,9 +144,9 @@ static gchar * get_as_div(v3270 * terminal) | @@ -144,9 +144,9 @@ static gchar * get_as_div(v3270 * terminal) | ||
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | /// @brief Get formatted contents as HTML TABLE. | 146 | /// @brief Get formatted contents as HTML TABLE. |
| 147 | -static gchar * get_as_table(v3270 * terminal) | 147 | +static gchar * get_as_table(v3270 * terminal, const GList *selection) |
| 148 | { | 148 | { |
| 149 | - GList * element = terminal->selection.blocks; | 149 | + const GList * element = selection; |
| 150 | GString * string = g_string_new("<table><tbody>"); | 150 | GString * string = g_string_new("<table><tbody>"); |
| 151 | 151 | ||
| 152 | unsigned int width = lib3270_get_width(terminal->host); | 152 | unsigned int width = lib3270_get_width(terminal->host); |
| @@ -155,11 +155,11 @@ static gchar * get_as_table(v3270 * terminal) | @@ -155,11 +155,11 @@ static gchar * get_as_table(v3270 * terminal) | ||
| 155 | GList * column; | 155 | GList * column; |
| 156 | 156 | ||
| 157 | // Get contents | 157 | // Get contents |
| 158 | - GList * columns = v3270_getColumns_from_selection(terminal); | 158 | + GList * columns = v3270_getColumns_from_selection(terminal, selection); |
| 159 | 159 | ||
| 160 | while(element) | 160 | while(element) |
| 161 | { | 161 | { |
| 162 | - lib3270_selection * block = ((lib3270_selection *) element->data); | 162 | + const lib3270_selection * block = ((const lib3270_selection *) element->data); |
| 163 | 163 | ||
| 164 | unsigned int row, col, src = 0; | 164 | unsigned int row, col, src = 0; |
| 165 | 165 | ||
| @@ -214,14 +214,14 @@ static gchar * get_as_table(v3270 * terminal) | @@ -214,14 +214,14 @@ static gchar * get_as_table(v3270 * terminal) | ||
| 214 | 214 | ||
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | -gchar * v3270_get_copy_as_html(v3270 * terminal) | 217 | +gchar * v3270_get_copy_as_html(v3270 * terminal, const gchar *encoding) |
| 218 | { | 218 | { |
| 219 | g_autofree char * text = NULL; | 219 | g_autofree char * text = NULL; |
| 220 | 220 | ||
| 221 | if(terminal->selection.format == V3270_SELECT_TABLE) | 221 | if(terminal->selection.format == V3270_SELECT_TABLE) |
| 222 | - text = get_as_table(terminal); | 222 | + text = get_as_table(terminal, terminal->selection.blocks); |
| 223 | else | 223 | else |
| 224 | - text = get_as_div(terminal); | 224 | + text = get_as_div(terminal, terminal->selection.blocks); |
| 225 | 225 | ||
| 226 | - return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | 226 | + return g_convert(text, -1, (encoding ? encoding : "UTF-8"), lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); |
| 227 | } | 227 | } |
src/selection/linux/copy.c
| @@ -57,14 +57,14 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | @@ -57,14 +57,14 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | ||
| 57 | { | 57 | { |
| 58 | case CLIPBOARD_TYPE_TEXT: // Get clipboard contents as text | 58 | case CLIPBOARD_TYPE_TEXT: // Get clipboard contents as text |
| 59 | { | 59 | { |
| 60 | - g_autofree gchar *text = v3270_get_copy_as_text(terminal); | 60 | + g_autofree gchar *text = v3270_get_copy_as_text(terminal,"UTF-8"); |
| 61 | gtk_selection_data_set_text(selection,text,-1); | 61 | gtk_selection_data_set_text(selection,text,-1); |
| 62 | } | 62 | } |
| 63 | break; | 63 | break; |
| 64 | 64 | ||
| 65 | case CLIPBOARD_TYPE_CSV: | 65 | case CLIPBOARD_TYPE_CSV: |
| 66 | { | 66 | { |
| 67 | - g_autofree gchar *text = v3270_get_copy_as_table(terminal,";"); | 67 | + g_autofree gchar *text = v3270_get_copy_as_table(terminal,";","UTF-8"); |
| 68 | debug("Selection:\n%s",text); | 68 | debug("Selection:\n%s",text); |
| 69 | gtk_selection_data_set( | 69 | gtk_selection_data_set( |
| 70 | selection, | 70 | selection, |
| @@ -78,7 +78,7 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | @@ -78,7 +78,7 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa | ||
| 78 | 78 | ||
| 79 | case CLIPBOARD_TYPE_HTML: | 79 | case CLIPBOARD_TYPE_HTML: |
| 80 | { | 80 | { |
| 81 | - g_autofree gchar *text = v3270_get_copy_as_html(terminal); | 81 | + g_autofree gchar *text = v3270_get_copy_as_html(terminal,"UTF-8"); |
| 82 | //debug("Selection:\n%s",text); | 82 | //debug("Selection:\n%s",text); |
| 83 | gtk_selection_data_set( | 83 | gtk_selection_data_set( |
| 84 | selection, | 84 | selection, |
src/selection/table.c
| @@ -34,13 +34,11 @@ | @@ -34,13 +34,11 @@ | ||
| 34 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 34 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 35 | 35 | ||
| 36 | /// @brief Check if column has data. | 36 | /// @brief Check if column has data. |
| 37 | -static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col) | 37 | +static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col, const GList *selection) |
| 38 | { | 38 | { |
| 39 | - GList * element = terminal->selection.blocks; | ||
| 40 | - | ||
| 41 | - while(element) | 39 | + while(selection) |
| 42 | { | 40 | { |
| 43 | - lib3270_selection * block = ((lib3270_selection *) element->data); | 41 | + const lib3270_selection * block = ((const lib3270_selection *) selection->data); |
| 44 | 42 | ||
| 45 | if( (col >= block->bounds.col) && ( col < (block->bounds.col + block->bounds.width)) ) | 43 | if( (col >= block->bounds.col) && ( col < (block->bounds.col + block->bounds.width)) ) |
| 46 | { | 44 | { |
| @@ -58,14 +56,14 @@ static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col) | @@ -58,14 +56,14 @@ static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col) | ||
| 58 | 56 | ||
| 59 | } | 57 | } |
| 60 | 58 | ||
| 61 | - element = g_list_next(element); | 59 | + selection = g_list_next(selection); |
| 62 | } | 60 | } |
| 63 | 61 | ||
| 64 | return FALSE; | 62 | return FALSE; |
| 65 | } | 63 | } |
| 66 | 64 | ||
| 67 | /// @brief Get column list. | 65 | /// @brief Get column list. |
| 68 | -GList * v3270_getColumns_from_selection(v3270 * terminal) | 66 | +GList * v3270_getColumns_from_selection(v3270 * terminal, const GList *selection) |
| 69 | { | 67 | { |
| 70 | unsigned int col = 0; | 68 | unsigned int col = 0; |
| 71 | GList *rc = NULL; | 69 | GList *rc = NULL; |
| @@ -75,7 +73,7 @@ GList * v3270_getColumns_from_selection(v3270 * terminal) | @@ -75,7 +73,7 @@ GList * v3270_getColumns_from_selection(v3270 * terminal) | ||
| 75 | // debug("col(%u): %s", col, hasDataOnColumn(terminal,col) ? "yes" : "no"); | 73 | // debug("col(%u): %s", col, hasDataOnColumn(terminal,col) ? "yes" : "no"); |
| 76 | 74 | ||
| 77 | // Get first column. | 75 | // Get first column. |
| 78 | - while(!hasDataOnColumn(terminal,col)) { | 76 | + while(!hasDataOnColumn(terminal,col,selection)) { |
| 79 | if(col >= lib3270_get_width(terminal->host)) | 77 | if(col >= lib3270_get_width(terminal->host)) |
| 80 | return rc; | 78 | return rc; |
| 81 | col++; | 79 | col++; |
| @@ -87,7 +85,7 @@ GList * v3270_getColumns_from_selection(v3270 * terminal) | @@ -87,7 +85,7 @@ GList * v3270_getColumns_from_selection(v3270 * terminal) | ||
| 87 | rc = g_list_append(rc,columndescription); | 85 | rc = g_list_append(rc,columndescription); |
| 88 | 86 | ||
| 89 | // Get width. | 87 | // Get width. |
| 90 | - while(hasDataOnColumn(terminal,col++)) { | 88 | + while(hasDataOnColumn(terminal,col++,selection)) { |
| 91 | columndescription->width++; | 89 | columndescription->width++; |
| 92 | if(col >= lib3270_get_width(terminal->host)) | 90 | if(col >= lib3270_get_width(terminal->host)) |
| 93 | return rc; | 91 | return rc; |
| @@ -98,12 +96,11 @@ GList * v3270_getColumns_from_selection(v3270 * terminal) | @@ -98,12 +96,11 @@ GList * v3270_getColumns_from_selection(v3270 * terminal) | ||
| 98 | 96 | ||
| 99 | } | 97 | } |
| 100 | 98 | ||
| 101 | -/// @brief Get formatted contents as single text. | ||
| 102 | -gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter) | 99 | +gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, const gchar *delimiter, const gchar *encoding) |
| 103 | { | 100 | { |
| 104 | GString * string = g_string_new(""); | 101 | GString * string = g_string_new(""); |
| 105 | 102 | ||
| 106 | - GList * columns = v3270_getColumns_from_selection(terminal); | 103 | + GList * columns = v3270_getColumns_from_selection(terminal, selection); |
| 107 | 104 | ||
| 108 | debug("columns=%p",columns); | 105 | debug("columns=%p",columns); |
| 109 | 106 | ||
| @@ -121,7 +118,7 @@ gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter) | @@ -121,7 +118,7 @@ gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter) | ||
| 121 | } | 118 | } |
| 122 | #endif // DEBUG | 119 | #endif // DEBUG |
| 123 | 120 | ||
| 124 | - GList * element = terminal->selection.blocks; | 121 | + GList * element = selection; |
| 125 | unsigned int width = lib3270_get_width(terminal->host); | 122 | unsigned int width = lib3270_get_width(terminal->host); |
| 126 | g_autofree gchar * line = g_malloc0(width+1); | 123 | g_autofree gchar * line = g_malloc0(width+1); |
| 127 | GList * column; | 124 | GList * column; |
| @@ -167,5 +164,12 @@ gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter) | @@ -167,5 +164,12 @@ gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter) | ||
| 167 | g_list_free_full(columns,g_free); | 164 | g_list_free_full(columns,g_free); |
| 168 | 165 | ||
| 169 | g_autofree char * text = g_string_free(string,FALSE); | 166 | g_autofree char * text = g_string_free(string,FALSE); |
| 170 | - return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | 167 | + return g_convert(text, -1, (encoding ? encoding : "UTF-8"), lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); |
| 171 | } | 168 | } |
| 169 | + | ||
| 170 | +/// @brief Get formatted contents as single text. | ||
| 171 | +gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter, const gchar *encoding) | ||
| 172 | +{ | ||
| 173 | + return v3270_get_selection_as_table(terminal, terminal->selection.blocks, delimiter, encoding); | ||
| 174 | +} | ||
| 175 | + |
src/selection/text.c
| @@ -33,14 +33,13 @@ | @@ -33,14 +33,13 @@ | ||
| 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 34 | 34 | ||
| 35 | /// @brief Get formatted contents as single text. | 35 | /// @brief Get formatted contents as single text. |
| 36 | -static gchar * get_as_text(v3270 * terminal) | 36 | +gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, const gchar *encoding) |
| 37 | { | 37 | { |
| 38 | - GList * element = terminal->selection.blocks; | ||
| 39 | - GString * string = g_string_new(""); | 38 | + GString * string = g_string_new(""); |
| 40 | 39 | ||
| 41 | - while(element) | 40 | + while(selection) |
| 42 | { | 41 | { |
| 43 | - lib3270_selection * block = ((lib3270_selection *) element->data); | 42 | + lib3270_selection * block = ((lib3270_selection *) selection->data); |
| 44 | unsigned int row, col, src = 0; | 43 | unsigned int row, col, src = 0; |
| 45 | 44 | ||
| 46 | for(row=0; row < block->bounds.height; row++) | 45 | for(row=0; row < block->bounds.height; row++) |
| @@ -56,20 +55,20 @@ static gchar * get_as_text(v3270 * terminal) | @@ -56,20 +55,20 @@ static gchar * get_as_text(v3270 * terminal) | ||
| 56 | g_string_append_c(string,'\n'); | 55 | g_string_append_c(string,'\n'); |
| 57 | } | 56 | } |
| 58 | 57 | ||
| 59 | - element = g_list_next(element); | 58 | + selection = g_list_next(selection); |
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | g_autofree char * text = g_string_free(string,FALSE); | 61 | g_autofree char * text = g_string_free(string,FALSE); |
| 63 | - return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | 62 | + |
| 63 | + return g_convert(text, -1, (encoding ? encoding : "UTF-8"), lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | ||
| 64 | 64 | ||
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | -gchar * v3270_get_copy_as_text(v3270 * terminal) | 67 | +gchar * v3270_get_copy_as_text(v3270 * terminal, const gchar *encoding) |
| 68 | { | 68 | { |
| 69 | if(terminal->selection.format == V3270_SELECT_TABLE) | 69 | if(terminal->selection.format == V3270_SELECT_TABLE) |
| 70 | - return v3270_get_copy_as_table(terminal,"\t"); | ||
| 71 | - | ||
| 72 | - return get_as_text(terminal); | 70 | + return v3270_get_copy_as_table(terminal,"\t",encoding); |
| 71 | + return v3270_get_selection_as_text(terminal, terminal->selection.blocks, encoding); | ||
| 73 | } | 72 | } |
| 74 | 73 | ||
| 75 | LIB3270_EXPORT void v3270_input_text(GtkWidget *widget, const gchar *text, const gchar *encoding) | 74 | LIB3270_EXPORT void v3270_input_text(GtkWidget *widget, const gchar *text, const gchar *encoding) |
| @@ -205,6 +204,6 @@ LIB3270_EXPORT void v3270_input_text(GtkWidget *widget, const gchar *text, const | @@ -205,6 +204,6 @@ LIB3270_EXPORT void v3270_input_text(GtkWidget *widget, const gchar *text, const | ||
| 205 | LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget) | 204 | LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget) |
| 206 | { | 205 | { |
| 207 | g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | 206 | g_return_val_if_fail(GTK_IS_V3270(widget),NULL); |
| 208 | - return v3270_get_copy_as_text(GTK_V3270(widget)); | 207 | + return v3270_get_copy_as_text(GTK_V3270(widget),NULL); |
| 209 | } | 208 | } |
| 210 | 209 |