From 0b7b696bd0e19818a87c4adbd94bd5bdef4192ca Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 25 Jan 2019 11:03:02 -0200 Subject: [PATCH] Updating print dialog. --- src/dialogs/fontselect.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/include/v3270.h | 1 + src/include/v3270/print.h | 12 +++++++----- src/testprogram/testprogram.c | 10 ++++++++++ src/trace/trace.c | 2 +- src/v3270/font.c | 5 +++++ src/v3270/print.c | 521 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ src/v3270/private.h | 2 +- src/v3270/widget.c | 13 +------------ 9 files changed, 199 insertions(+), 439 deletions(-) create mode 100644 src/dialogs/fontselect.c diff --git a/src/dialogs/fontselect.c b/src/dialogs/fontselect.c new file mode 100644 index 0000000..da10278 --- /dev/null +++ b/src/dialogs/fontselect.c @@ -0,0 +1,72 @@ +/* + * "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 + #include + #include + +/*--[ Widget definition ]----------------------------------------------------------------------------*/ + + LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname) + { + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(1,G_TYPE_STRING); + GtkWidget * widget = gtk_combo_box_new_with_model(model); + + GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); + + if(!(fontname && *fontname)) + fontname = v3270_get_default_font_name(); + + gint n_families, i; + PangoFontFamily **families; + pango_context_list_families(gtk_widget_get_pango_context(widget),&families, &n_families); + + for(i=0; i < n_families; i++) + { + if(!pango_font_family_is_monospace(families[i])) + continue; + + const gchar *name = pango_font_family_get_name (families[i]); + GtkTreeIter iter; + + gtk_list_store_append((GtkListStore *) model,&iter); + gtk_list_store_set((GtkListStore *) model, &iter,0, name, -1); + + if(!g_ascii_strcasecmp(name,fontname)) + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); + + } + + g_free(families); + + return widget; + } + diff --git a/src/include/v3270.h b/src/include/v3270.h index 8bdc83f..32f9553 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -220,6 +220,7 @@ // Misc LIB3270_EXPORT GtkIMContext * v3270_get_im_context(GtkWidget *widget); + LIB3270_EXPORT const gchar * v3270_get_default_font_name(); LIB3270_EXPORT gboolean v3270_get_toggle(GtkWidget *widget, LIB3270_TOGGLE ix); LIB3270_EXPORT gboolean v3270_set_toggle(GtkWidget *widget, LIB3270_TOGGLE ix, gboolean state); diff --git a/src/include/v3270/print.h b/src/include/v3270/print.h index ebfbb78..487ba59 100644 --- a/src/include/v3270/print.h +++ b/src/include/v3270/print.h @@ -40,18 +40,20 @@ #define GTK_TYPE_V3270_PRINT_OPERATION (V3270PrintOperation_get_type()) #define GTK_V3270_PRINT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_PRINT_OPERATION, V3270PrintOperation)) - #define GTK_V3270_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_PRINT_OPERATION, V3270PrintOperationClass)) + #define GTK_V3270_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_PRINT_OPERATION, V3270PrintOperationClass)) #define GTK_IS_V3270_PRINT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270_PRINT_OPERATION)) - #define GTK_IS_V3270_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270_PRINT_OPERATION)) - #define GTK_V3270_PRINT_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270_PRINT_OPERATION, V3270V3270PrintOperationClass)) + #define GTK_IS_V3270_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270_PRINT_OPERATION)) + #define GTK_V3270_PRINT_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270_PRINT_OPERATION, V3270V3270PrintOperationClass)) - typedef struct _V3270PrintOperation V3270PrintOperation; - typedef struct _V3270PrintPrintOperation V3270PrintOperationClass; + typedef struct _V3270PrintOperation V3270PrintOperation; + typedef struct _V3270PrintOperationClass V3270PrintOperationClass; /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ LIB3270_EXPORT V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode); + LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname); + G_END_DECLS #endif // V3270_PRINT_OPERATION_H_INCLUDED diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index e667f80..83024ac 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -103,6 +103,12 @@ static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA } +static void print_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) +{ + debug("%s",__FUNCTION__); + v3270_print_all(terminal); +} + static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { /* @@ -172,6 +178,9 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL,2); GtkWidget *grid = gtk_grid_new(); GtkWidget *color = v3270_color_scheme_new(); + GtkWidget *print = gtk_button_new_with_label("Print"); + + g_signal_connect(G_OBJECT(print),"clicked",G_CALLBACK(print_clicked),terminal); gtk_widget_set_can_focus(color,FALSE); gtk_widget_set_focus_on_click(color,FALSE); @@ -179,6 +188,7 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { g_signal_connect(G_OBJECT(color),"update-colors",G_CALLBACK(color_scheme_changed),terminal); gtk_grid_attach(GTK_GRID(grid),color,0,0,1,1); + gtk_grid_attach(GTK_GRID(grid),print,1,0,1,1); gtk_box_pack_start(GTK_BOX(box),grid,FALSE,TRUE,0); gtk_box_pack_start(GTK_BOX(box),terminal,TRUE,TRUE,0); diff --git a/src/trace/trace.c b/src/trace/trace.c index e2666ce..7bf1291 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -357,7 +357,7 @@ static void destroy(GtkWidget *widget) gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window->scroll),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); window->view = gtk_text_view_new(); - v3270_trace_set_font_from_string(GTK_WIDGET(window),"Monospaced"); + v3270_trace_set_font_from_string(GTK_WIDGET(window),v3270_get_default_font_name()); window->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(window->view)); gtk_text_view_set_editable(GTK_TEXT_VIEW(window->view), TRUE); diff --git a/src/v3270/font.c b/src/v3270/font.c index 0daad5b..f97498f 100644 --- a/src/v3270/font.c +++ b/src/v3270/font.c @@ -44,6 +44,11 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ +const gchar * v3270_get_default_font_name() +{ + return v3270_default_font; +} + void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) { // update font metrics diff --git a/src/v3270/print.c b/src/v3270/print.c index 164f1f1..124447e 100644 --- a/src/v3270/print.c +++ b/src/v3270/print.c @@ -32,499 +32,180 @@ #include "private.h" #include #include + #include #include #include #include - #define AUTO_FONT_SIZE 1 +/*--[ Widget definition ]----------------------------------------------------------------------------*/ -#ifdef AUTO_FONT_SIZE - #define FONT_CONFIG "font-family" - #define DEFAULT_FONT "Courier New" -#else - #define FONT_CONFIG "font" - #define DEFAULT_FONT "Courier New 10" -#endif // AUTO_FONT_SIZE - -/*--[ Structs ]--------------------------------------------------------------------------------------*/ - - typedef struct _print_info - { - GdkRGBA color[V3270_COLOR_COUNT]; - int show_selection : 1; - LIB3270_PRINT_MODE src; - - v3270 * widget; - - int baddr; - int rows; - int cols; ///< @brief Max line width. - int pages; - int lpp; ///< @brief Lines per page. - - v3270FontInfo font; - - double left; - double width; ///< @brief Report width. - double height; ///< @brief Report height (all pages). - - gchar **text; - - } PRINT_INFO; - - -/*--[ Implement ]------------------------------------------------------------------------------------*/ - - static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) + struct _V3270PrintOperationClass { - cairo_font_extents_t extents; - cairo_t * cr = gtk_print_context_get_cairo_context(context); - - // Setup font - if(info->font.family) - { - PangoFontDescription * descr = pango_font_description_from_string(info->font.family); - if(descr) - { - cairo_select_font_face(cr, pango_font_description_get_family(descr), - CAIRO_FONT_SLANT_NORMAL, - pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL); - -#ifdef AUTO_FONT_SIZE - { - double width = gtk_print_context_get_width(context); -#if GTK_CHECK_VERSION(3,0,0) - double cols = (double) info->cols; -#else - double cols = (double) (info->cols+5); -#endif // GTK(3,0,0) - double current = width / cols; - double valid = current; - - do - { - valid = current; - current = valid +1.0; - cairo_set_font_size(cr,current); - cairo_font_extents(cr,&extents); - } - while( (cols * extents.max_x_advance) < width ); - - cairo_set_font_size(cr,valid); - - } -#endif // AUTO_FONT_SIZE - - pango_font_description_free(descr); - } - } - - info->font.scaled = cairo_get_scaled_font(cr); - cairo_scaled_font_reference(info->font.scaled); - cairo_scaled_font_extents(info->font.scaled,&extents); - - info->font.height = extents.height; - info->font.descent = extents.descent; - info->font.width = extents.max_x_advance; - - info->width = ((double) info->cols) * extents.max_x_advance; - info->height = ((double) info->rows) * (extents.height + extents.descent); - - // Center image - info->left = (gtk_print_context_get_width(context)-info->width)/2; - if(info->left < 2) - info->left = 2; - - // Setup page size - info->lpp = (gtk_print_context_get_height(context) / (extents.height + extents.descent)); - info->pages = (info->rows / info->lpp)+1; + GtkPrintOperationClass parent_class; - gtk_print_operation_set_n_pages(prt,info->pages); - } + }; - static void draw_screen(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) + struct _V3270PrintOperation { - int row; - int col; - cairo_t * cr = gtk_print_context_get_cairo_context(context); - int baddr = info->baddr; - GdkRectangle rect; + GtkPrintOperation parent; + GdkRGBA color[V3270_COLOR_COUNT]; + LIB3270_PRINT_MODE mode; + v3270 * widget; + H3270 * session; - cairo_set_scaled_font(cr,info->font.scaled); + struct { + gchar * name; + v3270FontInfo info; + } font; - memset(&rect,0,sizeof(rect)); - rect.y = 2; - rect.height = (info->font.height + info->font.descent); - rect.width = info->font.width; + gboolean show_selection; - // Clear page - gdk_cairo_set_source_rgba(cr,info->color+V3270_COLOR_BACKGROUND); - cairo_rectangle(cr, info->left-2, 0, (rect.width*info->cols)+4, (rect.height*info->rows)+4); - cairo_fill(cr); - cairo_stroke(cr); - rect.width++; - rect.height++; + }; - for(row = 0; row < info->rows; row++) - { - rect.x = info->left; - for(col = 0; col < info->cols; col++) - { - unsigned char c; - unsigned short attr; - - if(!lib3270_get_element(info->widget->host,baddr++,&c,&attr) && (info->src == LIB3270_PRINT_ALL || (attr & LIB3270_ATTR_SELECTED))) - { - if(!info->show_selection) - attr &= ~LIB3270_ATTR_SELECTED; - v3270_draw_element(cr,c,attr,info->widget->host,&info->font,&rect,info->color); - } - - rect.x += (rect.width-1); - } - rect.y += (rect.height-1); + G_DEFINE_TYPE(V3270PrintOperation, V3270PrintOperation, GTK_TYPE_PRINT_OPERATION); - } - } - - /* - static void show_print_error(GtkWidget *widget, GError *err) - { - 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, - "%s",_( "Print operation failed" )); - - g_warning("%s",err->message); - - gtk_window_set_title(GTK_WINDOW(dialog),_("Error")); - - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",err->message); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); -} -*/ +/*--[ Implement ]------------------------------------------------------------------------------------*/ - static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info) + static void done(GtkPrintOperation *prt, GtkPrintOperationResult result) { - debug("%s(%p)",__FUNCTION__,info->widget); - g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_DONE], 0, prt, (guint) result); + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); debug("%s",__FUNCTION__); - if(info->font.scaled) - cairo_scaled_font_destroy(info->font.scaled); - - debug("%s",__FUNCTION__); - if(info->text) - g_strfreev(info->text); - - debug("%s",__FUNCTION__); - if(info->font.family) - g_free(info->font.family); - - debug("%s",__FUNCTION__); - g_free(info); - debug("%s",__FUNCTION__); - } - -#ifndef AUTO_FONT_SIZE - -#if GTK_CHECK_VERSION(3,2,0) - static gboolean filter_monospaced(const PangoFontFamily *family,const PangoFontFace *face,gpointer data) - { - return pango_font_family_is_monospace((PangoFontFamily *) family); - } -#endif // GTK(3,2,0) - - static void font_set(GtkFontButton *widget, PRINT_INFO *info) - { - if(info->font) - g_free(info->font); - info->font = g_strdup(gtk_font_button_get_font_name(widget)); - } - -#else - - static void font_name_changed(GtkComboBox *combo, PRINT_INFO *info) - { - GValue value = { 0, }; - GtkTreeIter iter; - - if(!gtk_combo_box_get_active_iter(combo,&iter)) - return; - - gtk_tree_model_get_value(gtk_combo_box_get_model(combo),&iter,0,&value); - if(info->font.family) - g_free(info->font.family); - - info->font.family = g_value_dup_string(&value); + if(operation->widget) + g_signal_emit(GTK_WIDGET(operation->widget), v3270_widget_signal[SIGNAL_PRINT_DONE], 0, prt, (guint) result); } -#endif // !AUTO_FONT_SIZE - - static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info) +#ifndef _WIN32 + static GtkWidget * create_custom_widget(GtkPrintOperation *prt) { - gboolean active = gtk_toggle_button_get_active(togglebutton); - info->show_selection = active ? 1 : 0; - } - - static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) - { - GtkWidget * container = gtk_table_new(3,2,FALSE); - static const gchar * text[] = { N_( "_Font:" ), N_( "C_olor scheme:" ) }; - GtkWidget * label[G_N_ELEMENTS(text)]; - GtkWidget * widget; - size_t f; - - for(f=0;fwidget) + g_signal_emit(operation->widget, v3270_widget_signal[SIGNAL_PRINT_SETUP], 0, prt); - g_signal_connect(G_OBJECT(widget),"changed",G_CALLBACK(font_name_changed),info); + // Create dialog - pango_context_list_families(gtk_widget_get_pango_context(container),&families, &n_families); + GtkGrid * grid = GTK_GRID(gtk_grid_new()); + GtkWidget * font = v3270_font_selection_new(operation->font.name); + GtkWidget * color = v3270_color_scheme_new(); - for(i=0; ifont.family)) - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); - } - } + v3270_color_scheme_set_rgba(color,operation->color); - g_free(families); - } -#else + for(f=0;ffont); - gtk_font_button_set_show_size((GtkFontButton *) widget,TRUE); - gtk_font_button_set_use_font((GtkFontButton *) widget,TRUE); - gtk_label_set_mnemonic_widget(GTK_LABEL(label[0]),widget); - g_free(info->font); - -#if GTK_CHECK_VERSION(3,2,0) - gtk_font_chooser_set_filter_func((GtkFontChooser *) widget,filter_monospaced,NULL,NULL); -#endif // GTK(3,2,0) - - g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info); - + GtkWidget *label = gtk_label_new_with_mnemonic(gettext(text[f])); + gtk_misc_set_alignment(GTK_MISC(label),0,0.5); + gtk_grid_attach(grid,label,0,f,1,1); } -#endif - - gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); - - g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_BEGIN], 0, prt); + gtk_grid_attach(grid,font,1,0,1,1); + gtk_grid_attach(grid,color,1,1,1,1); - widget = v3270_color_scheme_new(); - v3270_color_scheme_set_rgba(widget,info->color); - gtk_label_set_mnemonic_widget(GTK_LABEL(label[1]),widget); - - g_object_set_data(G_OBJECT(container),"combo",widget); - gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); - - // Selection checkbox - widget = gtk_check_button_new_with_label( _("Print selection box") ); + gtk_widget_show_all(GTK_WIDGET(grid)); + return GTK_WIDGET(grid); + } - if(info->src == LIB3270_PRINT_ALL) - { - info->show_selection = FALSE; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),info->show_selection); - g_signal_connect(G_OBJECT(widget),"toggled",G_CALLBACK(toggle_show_selection),info); - } - else - { - gtk_widget_set_sensitive(widget,FALSE); - } + static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget) + { + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); - gtk_table_attach(GTK_TABLE(container),widget,1,2,2,3,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); + debug("%s",__FUNCTION__); - // Show and return - gtk_widget_show_all(container); + if(operation->widget) + g_signal_emit(operation->widget, v3270_widget_signal[SIGNAL_PRINT_APPLY], 0, prt); - return G_OBJECT(container); } +#endif // _WIN32 - static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget, PRINT_INFO *info) + static void dispose(GObject *object) { - g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_APPLY], 0, prt); - - /* - GtkWidget * combo = g_object_get_data(G_OBJECT(widget),"combo"); - GdkRGBA * clr = g_object_get_data(G_OBJECT(combo),"selected"); - - trace("%s starts combo=%p clr=%p widget=%p",__FUNCTION__,combo,clr,widget); + debug("%s",__FUNCTION__); - if(info->font.family) - set_string_to_config("print",FONT_CONFIG,info->font.family); + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object); - if(clr) - { - int f; - GString *str = g_string_new(""); - for(f=0;fcolor[f] = clr[f]; - if(f) - g_string_append_c(str,';'); - g_string_append_printf(str,"%s",gdk_rgba_to_string(clr+f)); - } - set_string_to_config("print","colors","%s",str->str); - g_string_free(str,TRUE); - } - - trace("%s ends",__FUNCTION__); - */ + g_free(operation->font.name); } - static GtkPrintOperation * begin_print_operation(GtkWidget *widget, PRINT_INFO **info) + static void V3270PrintOperation_class_init(V3270PrintOperationClass *klass) { - GtkPrintOperation * print = gtk_print_operation_new(); - GtkPrintSettings * settings = gtk_print_settings_new(); - GtkPageSetup * setup = gtk_page_setup_new(); - // GtkPaperSize * papersize = NULL; - - *info = g_new0(PRINT_INFO,1); - (*info)->cols = 80; - (*info)->widget = widget; - (*info)->font.family = g_strdup(DEFAULT_FONT); + GtkPrintOperationClass * operation = GTK_PRINT_OPERATION_CLASS(klass); - debug("%s",__FUNCTION__); - gtk_print_operation_set_custom_tab_label(print, _( "Options" ) ); - gtk_print_operation_set_show_progress(print,TRUE); + G_OBJECT_CLASS(klass)->dispose = dispose; + operation->done = done; - // Common signals +#ifndef _WIN32 + operation->create_custom_widget = create_custom_widget; + operation->custom_widget_apply = custom_widget_apply; +#endif // _WIN32 + /* + // Common signals g_signal_connect(print,"done",G_CALLBACK(done),*info); #if GTK_CHECK_VERSION(3,0,0) && !defined(WIN32) - g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info); - g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info); + g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info); + g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info); #endif // !WIN32 +*/ - // Finish settings - gtk_print_operation_set_print_settings(print,settings); - //gtk_page_setup_set_paper_size_and_default_margins(setup,papersize); - gtk_print_operation_set_default_page_setup(print,setup); - - return print; } - static void draw_text(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) + static void V3270PrintOperation_init(V3270PrintOperation *widget) { - cairo_t * cr = gtk_print_context_get_cairo_context(context); - GdkRectangle rect; - int row = pg*info->lpp; - int l; + // Setup print operation. + gtk_print_operation_set_custom_tab_label(GTK_PRINT_OPERATION(widget), _( "Options" ) ); + gtk_print_operation_set_show_progress(GTK_PRINT_OPERATION(widget),TRUE); + 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()); - cairo_set_scaled_font(cr,info->font.scaled); - memset(&rect,0,sizeof(rect)); - rect.y = 2; - rect.height = (info->font.height + info->font.descent)+1; - rect.width = info->font.width+1; + // Setup defaults + widget->mode = LIB3270_PRINT_ALL; + widget->show_selection = FALSE; + widget->font.name = g_strdup(v3270_default_font); - for(l=0;llpp && row < info->rows;l++) - { - cairo_move_to(cr,2,rect.y+rect.height); - cairo_show_text(cr, info->text[row]); - cairo_stroke(cr); - row++; - rect.y += (rect.height-1); - } + v3270_set_mono_color_table(widget->color,"#000000","#FFFFFF"); } - static void print_operation(GtkWidget *widget, GtkPrintOperationAction oper, LIB3270_PRINT_MODE mode) - { - PRINT_INFO * info = NULL; - GtkPrintOperation * print; - gchar * text; - GError * err = NULL; - - g_return_if_fail(GTK_IS_V3270(widget)); - - print = begin_print_operation(widget,&info); - if(!print) - return; - - lib3270_get_screen_size(info->widget->host,&info->rows,&info->cols); +V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode) +{ + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); - info->src = mode; - - g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info); - - switch(mode) - { - case LIB3270_PRINT_ALL: - case LIB3270_PRINT_SELECTED: - g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info); - break; + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(g_object_new(GTK_TYPE_V3270_PRINT_OPERATION, NULL)); - case LIB3270_PRINT_COPY: + operation->mode = mode; + operation->widget = GTK_V3270(widget); + operation->session = v3270_get_session(widget); - text = v3270_get_copy(widget); - - if(text) - { - int r; - - info->text = g_strsplit(text,"\n",-1); - info->rows = g_strv_length(info->text); - - for(r=0;r < info->rows;r++) - { - size_t sz = strlen(info->text[r]); - if(sz > info->cols) - info->cols = sz; - } - g_free(text); - } - g_signal_connect(print,"draw_page",G_CALLBACK(draw_text),info); - break; - - - } - - // Run Print dialog - gtk_print_operation_run(print,oper,GTK_WINDOW(gtk_widget_get_toplevel(widget)),&err); - - if(err) - g_error_free(err); - - g_object_unref(print); + return operation; +} - } +/*--[ Convenience ]----------------------------------------------------------------------------------*/ void v3270_print(GtkWidget *widget, LIB3270_PRINT_MODE mode) { - print_operation(widget,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, mode); + g_autoptr(GError) err = NULL; + + 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)),&err); + g_object_unref(operation); + } void v3270_print_all(GtkWidget *widget) diff --git a/src/v3270/private.h b/src/v3270/private.h index 4818f41..14c65cb 100644 --- a/src/v3270/private.h +++ b/src/v3270/private.h @@ -79,7 +79,7 @@ G_BEGIN_DECLS SIGNAL_CHANGED, SIGNAL_MESSAGE, SIGNAL_FIELD, - SIGNAL_PRINT_BEGIN, + SIGNAL_PRINT_SETUP, SIGNAL_PRINT_APPLY, SIGNAL_PRINT_DONE, diff --git a/src/v3270/widget.c b/src/v3270/widget.c index eb99a8a..5905623 100644 --- a/src/v3270/widget.c +++ b/src/v3270/widget.c @@ -497,18 +497,7 @@ static void v3270_class_init(v3270Class *klass) G_TYPE_BOOLEAN, 3, G_TYPE_BOOLEAN, G_TYPE_UINT, G_TYPE_POINTER); - /* - v3270_widget_signal[SIGNAL_PRINT] = - g_signal_new( "print", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - v3270_VOID__VOID, - G_TYPE_NONE, 0); - */ - - v3270_widget_signal[SIGNAL_PRINT_BEGIN] = + v3270_widget_signal[SIGNAL_PRINT_SETUP] = g_signal_new( "print-begin", G_OBJECT_CLASS_TYPE (gobject_class), G_SIGNAL_RUN_FIRST, -- libgit2 0.21.2