diff --git a/src/dialogs/print/begin.c b/src/dialogs/print/begin.c index 11cafbb..46d00ff 100644 --- a/src/dialogs/print/begin.c +++ b/src/dialogs/print/begin.c @@ -33,8 +33,8 @@ void V3270PrintOperation_begin_print(GtkPrintOperation *prt, GtkPrintContext *context) { - cairo_t * cr = gtk_print_context_get_cairo_context(context); V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); + cairo_t * cr = gtk_print_context_get_cairo_context(context); trace("%s",__FUNCTION__); @@ -78,9 +78,6 @@ operation->font.info.width++; - // Center text on page - // operation->font.info.left = 2; - operation->font.info.left = (gtk_print_context_get_width(context)- (operation->font.info.width * operation->contents.width))/2; if(operation->font.info.left < 2) operation->font.info.left = 2; diff --git a/src/dialogs/print/convenience.c b/src/dialogs/print/convenience.c new file mode 100644 index 0000000..8ab6c7d --- /dev/null +++ b/src/dialogs/print/convenience.c @@ -0,0 +1,144 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include "private.h" + #include + #include + #include + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + int v3270_print(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, GError **error) + { + int rc; + + if(!(widget && GTK_IS_V3270(widget))) + { + return errno = EINVAL; + } + + /* + if(!v3270_is_connected(widget)) + { + if(error) + { + *error = g_error_new(g_quark_from_static_string(PACKAGE_NAME),ENOTCONN,"%s",strerror(ENOTCONN)); + } + else + { + GtkWidget *popup = gtk_message_dialog_new_with_markup( + GTK_WINDOW(gtk_widget_get_toplevel(widget)), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, + _("Can't print data") + ); + + gtk_window_set_title(GTK_WINDOW(popup),_("Operation has failed")); + + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",strerror(ENOTCONN)); + + gtk_dialog_run(GTK_DIALOG(popup)); + gtk_widget_destroy(popup); + } + + return errno = ENOTCONN; + } + */ + + lib3270_trace_event(v3270_get_session(widget),"print action activated (type=%d)",(int) mode); + + // Print operation. + V3270PrintOperation * operation = v3270_print_operation_new(widget, mode); + + if(error) + { + gtk_print_operation_run( + GTK_PRINT_OPERATION(operation), + GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, + GTK_WINDOW(gtk_widget_get_toplevel(widget)), + error + ); + + rc = (*error == NULL ? 0 : -1); + + } + else + { + GError *err = NULL; + + gtk_print_operation_run( + GTK_PRINT_OPERATION(operation), + GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, + GTK_WINDOW(gtk_widget_get_toplevel(widget)), + &err + ); + + if(err) + { + GtkWidget *popup = gtk_message_dialog_new_with_markup( + GTK_WINDOW(gtk_widget_get_toplevel(widget)), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, + _("Can't print data") + ); + + gtk_window_set_title(GTK_WINDOW(popup),_("Operation has failed")); + + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",strerror(ENOTCONN)); + + gtk_dialog_run(GTK_DIALOG(popup)); + gtk_widget_destroy(popup); + + g_error_free(err); + + rc = -1; + } + } + + g_object_unref(operation); + + return rc; + + } + + int v3270_print_all(GtkWidget *widget, GError **error) + { + return v3270_print(widget,LIB3270_CONTENT_ALL,error); + } + + int v3270_print_selected(GtkWidget *widget, GError **error) + { + return v3270_print(widget,LIB3270_CONTENT_SELECTED,error); + } + + int v3270_print_copy(GtkWidget *widget, GError **error) + { + return v3270_print(widget,LIB3270_CONTENT_COPY,error); + } + diff --git a/src/dialogs/print/custom.c b/src/dialogs/print/custom.c new file mode 100644 index 0000000..aee178c --- /dev/null +++ b/src/dialogs/print/custom.c @@ -0,0 +1,144 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include "private.h" + #include + #include + #include + #include + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + +#ifndef _WIN32 + static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA *colors, V3270PrintOperation *operation) { + + debug("%s=%p",__FUNCTION__,colors); + + int f; + for(f=0;fcolors[f] = colors[f]; + + } + + static void font_name_changed(GtkComboBox *widget, V3270PrintOperation *operation) + { + GValue value = { 0, }; + GtkTreeIter iter; + + if(!gtk_combo_box_get_active_iter(widget,&iter)) + return; + + gtk_tree_model_get_value(gtk_combo_box_get_model(widget),&iter,0,&value); + + g_free(operation->font.name); + operation->font.name = g_value_dup_string(&value); + + debug("%s=%s",__FUNCTION__,operation->font.name); + } + + static void toggle_show_selection(GtkToggleButton *widget, V3270PrintOperation *operation) + { + operation->show_selection = gtk_toggle_button_get_active(widget); + } + + GtkWidget * V3270PrintOperation_custom_widget_new(GtkPrintOperation *prt) + { + static const gchar * text[] = + { + N_( "_Font:" ), + N_( "C_olor scheme:" ) + }; + + size_t f; + + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); + + if(operation->widget) + g_signal_emit(operation->widget, v3270_widget_signal[V3270_SIGNAL_PRINT_SETUP], 0, prt); + + // Create dialog + + GtkWidget * frame = gtk_frame_new(""); + GtkGrid * grid = GTK_GRID(gtk_grid_new()); + GtkWidget * font = v3270_font_selection_new(operation->font.name); + GtkWidget * color = v3270_color_scheme_new(); + GtkWidget * selected = gtk_check_button_new_with_label( _("Print selection box") ); + + // The print dialog doesn't follow the guidelines from https://developer.gnome.org/hig/stable/visual-layout.html.en )-: + + gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_NONE); + + GtkWidget *label = gtk_label_new(NULL); + + gtk_label_set_markup(GTK_LABEL(label),_("Text options")); + gtk_frame_set_label_widget(GTK_FRAME(frame),label); + + gtk_container_set_border_width(GTK_CONTAINER(frame),12); + + gtk_container_set_border_width(GTK_CONTAINER(grid),6); + + g_object_set(G_OBJECT(grid),"margin-start",8,NULL); + + gtk_grid_set_row_spacing(grid,6); + gtk_grid_set_column_spacing(grid,12); + + v3270_color_scheme_set_rgba(color,operation->colors); + g_signal_connect(G_OBJECT(color),"update-colors",G_CALLBACK(color_scheme_changed),operation); + g_signal_connect(G_OBJECT(font),"changed",G_CALLBACK(font_name_changed),operation); + g_signal_connect(G_OBJECT(selected),"toggled",G_CALLBACK(toggle_show_selection),operation); + + for(f=0;fwidget) + g_signal_emit(operation->widget, v3270_widget_signal[V3270_SIGNAL_PRINT_APPLY], 0, prt); + + } + +#endif // _WIN32 diff --git a/src/dialogs/print/draw.c b/src/dialogs/print/draw.c index dd0239c..187a46d 100644 --- a/src/dialogs/print/draw.c +++ b/src/dialogs/print/draw.c @@ -29,29 +29,60 @@ #include "private.h" #include + #include /*--[ Implement ]------------------------------------------------------------------------------------*/ + static gint get_row(const V3270PrintOperation * operation, gint row, const lib3270_selection **block) + { + const GList * element = NULL; + const lib3270_selection * selection = NULL; + + debug("Searching for row %u", row); + + for(element = operation->contents.selection; element; element = element->next) + { + selection = (const lib3270_selection *) element->data; + + if(((unsigned int) row) < selection->bounds.height) + { + // Found block. + debug("Found row %u",row); + *block = selection; + return row; + } + + debug("Skipping block with %u rows",selection->bounds.height); + row -= (int) selection->bounds.height; + } + + return -1; + } + void V3270PrintOperation_draw_page(GtkPrintOperation *prt, GtkPrintContext *context, gint page) { - cairo_t * cr = gtk_print_context_get_cairo_context(context); V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); + cairo_t * cr = gtk_print_context_get_cairo_context(context); - size_t from = page * operation->lpp; - - if(from > operation->contents.height) + // Convert page number in rows. + gint row = page * operation->lpp; + if(((unsigned int) row) > operation->contents.height) return; - // Create a rectangle with the size of 1 character. + debug("%s: page=%d skip_rows=%d",__FUNCTION__,page,row); + + // Get block + const lib3270_selection * selection = NULL; + row = get_row(operation,row,&selection); + + // Setup a rectangle with the size of 1 character. GdkRectangle rect; memset(&rect,0,sizeof(rect)); rect.y = 2; rect.height = operation->font.info.height + operation->font.info.descent; rect.width = operation->font.info.width; - // Draw "operation->lpp" lines starting from "from" - - // Clear contents. + // Clear drawing area. gdk_cairo_set_source_rgba(cr,operation->colors + V3270_COLOR_BACKGROUND); cairo_rectangle( cr, @@ -63,6 +94,70 @@ cairo_fill(cr); cairo_stroke(cr); + // Draw LPP lines + size_t drawing; + + for(drawing = 0; drawing < operation->lpp; drawing++) + { + size_t pos = (row * selection->bounds.width); + debug("Drawing: %u row=%u selection=%p pos=%u", (unsigned int) drawing, row, selection, (unsigned int) pos); + + if(((unsigned int) ++row) > selection->bounds.height) + { + debug("Searching for next block (first line=%u)",(unsigned int) (page * operation->lpp) + drawing); + row = get_row(operation,(page * operation->lpp) + drawing, &selection); + if(row < 0) + { + break; + } + } + + // Draw columns + size_t col; + rect.x = operation->font.info.left; + + for(col = 0; col < selection->bounds.width;col++) + { + if(selection->contents[pos].chr) + { + // Draw character. + unsigned short attr = selection->contents[pos].attribute.visual; + + if(!operation->show_selection) + attr &= ~LIB3270_ATTR_SELECTED; + + v3270_draw_element( + cr, + selection->contents[pos].chr, + attr, + operation->session, + &operation->font.info, + &rect, + operation->colors + ); + + } + pos++; + + // Advance to the next char + rect.x += (rect.width-1); + + } + + // Advance to the next row + rect.y += (rect.height-1); + + } + + /* + + + // Create a rectangle with the size of 1 character. + + // Draw "operation->lpp" lines starting from "from" + + // Clear contents. + // draw "lpp" lines starting from "from" size_t r; @@ -107,5 +202,6 @@ rect.y += (rect.height-1); } + */ } diff --git a/src/dialogs/print/print.c b/src/dialogs/print/print.c index 3bc1218..b86bd41 100644 --- a/src/dialogs/print/print.c +++ b/src/dialogs/print/print.c @@ -30,7 +30,6 @@ #include "private.h" #include #include - #include #include G_DEFINE_TYPE(V3270PrintOperation, V3270PrintOperation, GTK_TYPE_PRINT_OPERATION); @@ -48,115 +47,6 @@ } -#ifndef _WIN32 - static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA *colors, V3270PrintOperation *operation) { - - debug("%s=%p",__FUNCTION__,colors); - - int f; - for(f=0;fcolors[f] = colors[f]; - - } - - static void font_name_changed(GtkComboBox *widget, V3270PrintOperation *operation) - { - GValue value = { 0, }; - GtkTreeIter iter; - - if(!gtk_combo_box_get_active_iter(widget,&iter)) - return; - - gtk_tree_model_get_value(gtk_combo_box_get_model(widget),&iter,0,&value); - - g_free(operation->font.name); - operation->font.name = g_value_dup_string(&value); - - debug("%s=%s",__FUNCTION__,operation->font.name); - } - - static void toggle_show_selection(GtkToggleButton *widget, V3270PrintOperation *operation) - { - operation->show_selection = gtk_toggle_button_get_active(widget); - } - - static GtkWidget * create_custom_widget(GtkPrintOperation *prt) - { - static const gchar * text[] = - { - N_( "_Font:" ), - N_( "C_olor scheme:" ) - }; - - size_t f; - - V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); - - if(operation->widget) - g_signal_emit(operation->widget, v3270_widget_signal[V3270_SIGNAL_PRINT_SETUP], 0, prt); - - // Create dialog - - GtkWidget * frame = gtk_frame_new(""); - GtkGrid * grid = GTK_GRID(gtk_grid_new()); - GtkWidget * font = v3270_font_selection_new(operation->font.name); - GtkWidget * color = v3270_color_scheme_new(); - GtkWidget * selected = gtk_check_button_new_with_label( _("Print selection box") ); - - // The print dialog doesn't follow the guidelines from https://developer.gnome.org/hig/stable/visual-layout.html.en )-: - - gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_NONE); - - GtkWidget *label = gtk_label_new(NULL); - - gtk_label_set_markup(GTK_LABEL(label),_("Text options")); - gtk_frame_set_label_widget(GTK_FRAME(frame),label); - - gtk_container_set_border_width(GTK_CONTAINER(frame),12); - - gtk_container_set_border_width(GTK_CONTAINER(grid),6); - - g_object_set(G_OBJECT(grid),"margin-start",8,NULL); - - gtk_grid_set_row_spacing(grid,6); - gtk_grid_set_column_spacing(grid,12); - - v3270_color_scheme_set_rgba(color,operation->colors); - g_signal_connect(G_OBJECT(color),"update-colors",G_CALLBACK(color_scheme_changed),operation); - g_signal_connect(G_OBJECT(font),"changed",G_CALLBACK(font_name_changed),operation); - g_signal_connect(G_OBJECT(selected),"toggled",G_CALLBACK(toggle_show_selection),operation); - - - for(f=0;fwidget) - g_signal_emit(operation->widget, v3270_widget_signal[V3270_SIGNAL_PRINT_APPLY], 0, prt); - - } - -#endif // _WIN32 - static void dispose(GObject *object) { debug("%s",__FUNCTION__); @@ -168,17 +58,12 @@ g_free(operation->font.name); - if(operation->contents.text) + if(operation->contents.dynamic) { - size_t row; - - for(row = 0; operation->contents.text[row]; row++) - { - g_free(operation->contents.text[row]); - } - g_free(operation->contents.text); - + g_list_free_full(operation->contents.dynamic,(GDestroyNotify) lib3270_free); + operation->contents.dynamic = NULL; } + operation->contents.selection = NULL; G_OBJECT_CLASS(V3270PrintOperation_parent_class)->dispose(object); @@ -194,8 +79,8 @@ operation->draw_page = V3270PrintOperation_draw_page; #ifndef _WIN32 - operation->create_custom_widget = create_custom_widget; - operation->custom_widget_apply = custom_widget_apply; + operation->create_custom_widget = V3270PrintOperation_custom_widget_new; + operation->custom_widget_apply = V3270PrintOperation_custom_widget_apply; #endif // _WIN32 } @@ -208,13 +93,10 @@ gtk_print_operation_set_print_settings(GTK_PRINT_OPERATION(widget),gtk_print_settings_new()); gtk_print_operation_set_default_page_setup(GTK_PRINT_OPERATION(widget),gtk_page_setup_new()); - // Setup defaults widget->mode = LIB3270_CONTENT_ALL; widget->show_selection = FALSE; widget->font.name = NULL; // g_strdup(v3270_default_font); - widget->contents.width = 80; - v3270_set_mono_color_table(widget->colors,"#000000","#FFFFFF"); } @@ -225,165 +107,46 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTE V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(g_object_new(GTK_TYPE_V3270_PRINT_OPERATION, NULL)); - operation->mode = mode; - operation->widget = GTK_V3270(widget); - operation->session = v3270_get_session(widget); - operation->font.name = g_strdup(v3270_get_font_family(widget)); - - V3270PrintOperation_set_text_by_mode(operation, mode); - - return operation; -} - -/*--[ Convenience ]----------------------------------------------------------------------------------*/ - - int v3270_print(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, GError **error) - { - if(*error) - { - return -1; - } - - lib3270_trace_event(v3270_get_session(widget),"print action activated (type=%d)",(int) mode); - - if(v3270_is_connected(widget)) - { - V3270PrintOperation * operation = v3270_print_operation_new(widget, mode); - gtk_print_operation_run(GTK_PRINT_OPERATION(operation),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),error); - g_object_unref(operation); - return (*error != NULL); - } - - *error = g_error_new(g_quark_from_static_string(PACKAGE_NAME),ENOTCONN,"%s",strerror(ENOTCONN)); - - return -1; + operation->mode = mode; + operation->widget = GTK_V3270(widget); + operation->session = v3270_get_session(widget); + operation->font.name = g_strdup(v3270_get_font_family(widget)); - } - - int v3270_print_all(GtkWidget *widget, GError **error) - { - return v3270_print(widget,LIB3270_CONTENT_ALL,error); - } - - int v3270_print_selected(GtkWidget *widget, GError **error) - { - return v3270_print(widget,LIB3270_CONTENT_SELECTED,error); - } - - int v3270_print_copy(GtkWidget *widget, GError **error) - { - return v3270_print(widget,LIB3270_CONTENT_COPY,error); - } - - void V3270PrintOperation_set_text_by_mode(V3270PrintOperation * operation, LIB3270_CONTENT_OPTION mode) - { - operation->mode = mode; - - switch(mode) + // Get contents. + switch(operation->mode) { case LIB3270_CONTENT_ALL: - { - 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); - } - } - - } + debug("%s","LIB3270_CONTENT_ALL"); + operation->contents.dynamic = g_new0(GList,1); + operation->contents.dynamic->data = (gpointer) lib3270_get_selection(operation->session,0,1); + operation->contents.selection = operation->contents.dynamic; break; - case LIB3270_CONTENT_SELECTED: - { - unsigned int row, col; - unsigned int baddr = 0; - - GdkRectangle rect; - memset(&rect,0,sizeof(rect)); - rect.x = lib3270_get_width(operation->session); - rect.y = lib3270_get_height(operation->session); - - // Get regions - - for(row = 0; row < lib3270_get_height(operation->session); row++) - { - for(col = 0; col < lib3270_get_width(operation->session); col++) - { - if(lib3270_is_selected(operation->session,baddr++)) - { - rect.x = MIN( ((unsigned int) rect.x),col); - rect.width = MAX( ((unsigned int) rect.width),col); - - rect.y = MIN( ((unsigned int) rect.y),row); - rect.height = MAX( ((unsigned int) rect.height),row); - } - } - } - - operation->contents.height = rect.height - rect.y; - operation->contents.width = rect.width - rect.x; - - // Get contents - int r = 0; - column * text; - - operation->contents.text = g_new0(column *, operation->contents.height+1); - - for(row = rect.y; ((int) row) < rect.width; row++) - { - int c = 0; - operation->contents.text[r++] = text = g_new0(column, operation->contents.width); - - for(col = rect.x; ((int) col) < rect.height; col++) - { - lib3270_get_element(operation->session,lib3270_translate_to_address(operation->session,row,col),&text[c].c,&text[c].attr); - if(!(text[c].attr & LIB3270_ATTR_SELECTED)) - { - text[c].c = 0; - text[c].attr = 0; - } - c++; - } - - } - - } + case LIB3270_CONTENT_COPY: + debug("%s","LIB3270_CONTENT_COPY"); + operation->contents.selection = v3270_get_selection_blocks(operation->widget); break; - case LIB3270_CONTENT_COPY: - { - lib3270_autoptr(char) copy = v3270_get_copy(GTK_WIDGET(operation->widget)); - if(copy) - { - size_t r; - 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(text[r])); - } - - g_strfreev(text); - - } - } + case LIB3270_CONTENT_SELECTED: + debug("%s","LIB3270_CONTENT_SELECTED"); + operation->contents.dynamic = g_new0(GList,1); + operation->contents.dynamic->data = (gpointer) lib3270_get_selection(operation->session,0,0); + operation->contents.selection = operation->contents.dynamic; break; + } + // Get metrics + const GList * element; + for(element = operation->contents.selection; element; element = element->next) + { + const lib3270_selection * selection = (const lib3270_selection *) element->data; + + if(selection->bounds.width > operation->contents.width) + operation->contents.width = selection->bounds.width; + + operation->contents.height += selection->bounds.height; } - debug("%s: width=%u height=%u",__FUNCTION__,(unsigned int) operation->contents.width, (unsigned int) operation->contents.height); + return operation; +} - } diff --git a/src/dialogs/print/private.h b/src/dialogs/print/private.h index 052bdd0..194fcb9 100644 --- a/src/dialogs/print/private.h +++ b/src/dialogs/print/private.h @@ -58,11 +58,12 @@ size_t pages; ///< @brief Number of pages. gboolean show_selection; ///< @brief Print selection box? - struct + struct { - size_t width; ///< @brief Width of the contents (in columns); - size_t height; ///< @brief Height of the contents (in rows); - column **text; ///< @brief Report contents. + unsigned int width; ///< @brief Max line width. + unsigned int height; ///< @brief Number of lines to print. + GList * dynamic; + const GList * selection; } contents; struct @@ -75,7 +76,9 @@ /*--[ Prototypes ]-----------------------------------------------------------------------------------*/ - G_GNUC_INTERNAL void V3270PrintOperation_begin_print(GtkPrintOperation *prt, GtkPrintContext *context); - G_GNUC_INTERNAL void V3270PrintOperation_draw_page(GtkPrintOperation *prt, GtkPrintContext *context, gint page); + G_GNUC_INTERNAL void V3270PrintOperation_begin_print(GtkPrintOperation *prt, GtkPrintContext *context); + G_GNUC_INTERNAL void V3270PrintOperation_draw_page(GtkPrintOperation *prt, GtkPrintContext *context, gint page); + G_GNUC_INTERNAL GtkWidget * V3270PrintOperation_custom_widget_new(GtkPrintOperation *prt); + G_GNUC_INTERNAL void V3270PrintOperation_custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget); diff --git a/src/include/v3270/print.h b/src/include/v3270/print.h index f068ff4..b7be1cd 100644 --- a/src/include/v3270/print.h +++ b/src/include/v3270/print.h @@ -52,12 +52,8 @@ /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ LIB3270_EXPORT V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode); - LIB3270_EXPORT void V3270PrintOperation_set_text_by_mode(V3270PrintOperation * operation, LIB3270_CONTENT_OPTION mode); - - LIB3270_EXPORT GtkTreeModel * v3270_font_family_model_new(GtkWidget *widget, const gchar *selected, GtkTreeIter * active); - LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname); - - + LIB3270_EXPORT GtkTreeModel * v3270_font_family_model_new(GtkWidget *widget, const gchar *selected, GtkTreeIter * active); + LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname); LIB3270_EXPORT GType V3270PrintOperation_get_type(void); G_END_DECLS diff --git a/src/selection/table.c b/src/selection/table.c index 372d007..7f8ee9f 100644 --- a/src/selection/table.c +++ b/src/selection/table.c @@ -34,7 +34,7 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ /// @brief Check if column has data. -static gboolean hasDataOnColumn(v3270 * terminal, unsigned int col, const GList *selection, gboolean all) +static gboolean hasDataOnColumn(v3270 * G_GNUC_UNUSED(terminal), unsigned int col, const GList *selection, gboolean all) { while(selection) { @@ -118,7 +118,7 @@ gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, c } #endif // DEBUG - GList * element = selection; + const GList * element = selection; unsigned int width = lib3270_get_width(terminal->host); g_autofree gchar * line = g_malloc0(width+1); GList * column; diff --git a/src/terminal/callbacks.c b/src/terminal/callbacks.c index f5986fe..56920f8 100644 --- a/src/terminal/callbacks.c +++ b/src/terminal/callbacks.c @@ -329,32 +329,7 @@ static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const static int print(H3270 *session, LIB3270_CONTENT_OPTION mode) { - GtkWidget * widget = GTK_WIDGET(lib3270_get_user_data(session)); - GError * error = NULL; - - v3270_print(widget, mode, &error); - - if(error) - { - GtkWidget *dialog = - gtk_message_dialog_new_with_markup( - GTK_WINDOW(gtk_widget_get_toplevel(widget)), - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, - _( "Operation has failed" )); - - gtk_window_set_title(GTK_WINDOW(dialog),_("Can't print")); - - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - g_error_free(error); - return -1; - - } - - return 0; + return v3270_print(GTK_WIDGET(lib3270_get_user_data(session)), mode, NULL); } static int save(H3270 *session, LIB3270_CONTENT_OPTION mode, const char *filename) diff --git a/v3270.cbp b/v3270.cbp index d9c79f4..f9ca86c 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -63,6 +63,12 @@ + + + + -- libgit2 0.21.2