diff --git a/src/dialogs/print/print.c b/src/dialogs/print/print.c index 6cb8a80..c587fdc 100644 --- a/src/dialogs/print/print.c +++ b/src/dialogs/print/print.c @@ -136,14 +136,23 @@ V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object); - if(operation->contents.text) - g_strfreev(operation->contents.text); - if(operation->font.info.scaled) cairo_scaled_font_destroy(operation->font.info.scaled); g_free(operation->font.name); + if(operation->contents.text) + { + size_t row; + + for(row = 0; operation->contents.text[row]; row++) + { + g_free(operation->contents.text[row]); + } + g_free(operation->contents.text); + + } + } static void V3270PrintOperation_class_init(V3270PrintOperationClass *klass) @@ -191,7 +200,7 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT operation->widget = GTK_V3270(widget); operation->session = v3270_get_session(widget); - V3270PrintOperation_set_mode(operation, mode); + V3270PrintOperation_set_text_by_mode(operation, mode); return operation; } @@ -223,16 +232,33 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT v3270_print(widget,LIB3270_PRINT_COPY); } - void V3270PrintOperation_set_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode) + void V3270PrintOperation_set_text_by_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode) { operation->mode = mode; - // Text rectangle (in characters). switch(mode) { case LIB3270_PRINT_ALL: - operation->contents.height = lib3270_get_height(operation->session); - operation->contents.width = lib3270_get_width(operation->session); + { + size_t row, col; + int baddr = 0; + column * text; + + operation->contents.height = lib3270_get_height(operation->session); + operation->contents.width = lib3270_get_width(operation->session); + + operation->contents.text = g_new0(column *, operation->contents.height+1); + + for(row = 0; row < operation->contents.height; row++) + { + operation->contents.text[row] = text = g_new0(column, operation->contents.width); + for(col = 0; col < operation->contents.width; col++) + { + lib3270_get_element(operation->session,baddr++,&text[col].c,&text[col].attr); + } + } + + } break; case LIB3270_PRINT_SELECTED: @@ -260,28 +286,29 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT } } - operation->contents.height = rect.height; - operation->contents.width = rect.width; + operation->contents.height = rect.height - rect.y; + operation->contents.width = rect.width - rect.x; } break; case LIB3270_PRINT_COPY: { - lib3270_autoptr(char) text = v3270_get_copy(GTK_WIDGET(operation->widget)); - if(text) + lib3270_autoptr(char) copy = v3270_get_copy(GTK_WIDGET(operation->widget)); + if(copy) { size_t r; - - operation->contents.text = g_strsplit(text,"\n",-1); - operation->contents.height = g_strv_length(operation->contents.text); + gchar ** text = g_strsplit(copy,"\n",-1); + operation->contents.height = g_strv_length(text); operation->contents.width = 0; for(r=0;r < operation->contents.height;r++) { - operation->contents.width = MAX(operation->contents.width,strlen(operation->contents.text[r])); + operation->contents.width = MAX(operation->contents.width,strlen(text[r])); } + g_strfreev(text); + } } break; diff --git a/src/dialogs/print/private.h b/src/dialogs/print/private.h index bc6b55c..23ef8c3 100644 --- a/src/dialogs/print/private.h +++ b/src/dialogs/print/private.h @@ -40,6 +40,12 @@ }; + typedef struct _column + { + unsigned char c; + unsigned short attr; + } column; + struct _V3270PrintOperation { GtkPrintOperation parent; @@ -55,7 +61,7 @@ { size_t width; ///< @brief Width of the contents (in columns); size_t height; ///< @brief Height of the contents (in rows); - gchar **text; ///< @brief Text contents; + column **text; ///< @brief Report contents. } contents; struct diff --git a/src/include/v3270/print.h b/src/include/v3270/print.h index 54512e4..202ded8 100644 --- a/src/include/v3270/print.h +++ b/src/include/v3270/print.h @@ -52,7 +52,7 @@ /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ LIB3270_EXPORT V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode); - LIB3270_EXPORT void V3270PrintOperation_set_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode); + LIB3270_EXPORT void V3270PrintOperation_set_text_by_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode); LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname); -- libgit2 0.21.2