diff --git a/Makefile.in b/Makefile.in index 54c7328..cc3e9c1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -126,6 +126,7 @@ $(OBJDBG)/%.o: \ $(CFLAGS) \ -Wall -Wextra -fstack-check \ -DDEBUG=1 \ + -DDATADIR=$(BASEDIR) \ -o $@ -c $< $(OBJDBG)/%.o: \ @@ -146,6 +147,7 @@ $(OBJRLS)/%.o: \ @$(CC) \ $(CFLAGS) \ -DNDEBUG=1 \ + -DDATADIR=$(datarootdir)/pw3270 \ -o $@ -c $< $(OBJRLS)/%.o: \ diff --git a/src/dialogs/colorscheme.c b/src/dialogs/colorscheme.c new file mode 100644 index 0000000..cf98751 --- /dev/null +++ b/src/dialogs/colorscheme.c @@ -0,0 +1,81 @@ +/* + * "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 + #define ENABLE_NLS + + #ifndef GETTEXT_PACKAGE + #define GETTEXT_PACKAGE PACKAGE_NAME + #endif + + #include + #include + + #include + #include + + #define V3270_COLOR_BASE V3270_COLOR_GRAY+1 + +/*--[ Widget definition ]----------------------------------------------------------------------------*/ + + struct _V3270ColorSchemeClass + { + GtkComboBoxClass parent_class; + + + }; + + struct _V3270ColorScheme + { + GtkComboBox parent; + + }; + + G_DEFINE_TYPE(V3270ColorScheme, V3270ColorScheme, GTK_TYPE_COMBO_BOX); + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + static void V3270ColorScheme_class_init(G_GNUC_UNUSED V3270ColorSchemeClass *klass) + { + + } + + static void V3270ColorScheme_init(V3270ColorScheme *widget) + { + + } + + LIB3270_EXPORT GtkWidget * v3270_color_scheme_new(GdkRGBA *colors) + { + GtkWidget *widget = GTK_WIDGET(g_object_new(GTK_TYPE_V3270_COLOR_SCHEME, NULL)); + + + return widget; + } + diff --git a/src/include/v3270.h b/src/include/v3270.h index 1f86264..5b16c8a 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -260,6 +260,11 @@ LIB3270_EXPORT GtkWidget * v3270_host_select_new(GtkWidget *widget); LIB3270_EXPORT void v3270_select_host(GtkWidget *widget); + // Print + LIB3270_EXPORT void v3270_print(GtkWidget *widget, LIB3270_PRINT_MODE mode); + LIB3270_EXPORT void v3270_print_all(GtkWidget *widget); + LIB3270_EXPORT void v3270_print_selected(GtkWidget *widget); + LIB3270_EXPORT void v3270_print_copy(GtkWidget *widget); G_END_DECLS diff --git a/src/include/v3270/colorscheme.h b/src/include/v3270/colorscheme.h new file mode 100644 index 0000000..8372361 --- /dev/null +++ b/src/include/v3270/colorscheme.h @@ -0,0 +1,54 @@ +/* + * "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 hostdialog.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#ifndef V3270_COLOR_SCHEME_H_INCLUDED + + #include + + G_BEGIN_DECLS + +/*--[ Progress widget ]------------------------------------------------------------------------------*/ + + #define GTK_TYPE_V3270_COLOR_SCHEME (V3270ColorScheme_get_type()) + #define GTK_V3270_COLOR_SCHEME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_COLOR_SCHEME, V3270ColorScheme)) + #define GTK_V3270_COLOR_SCHEME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_COLOR_SCHEME, V3270ColorSchemeClass)) + #define GTK_IS_V3270_COLOR_SCHEME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270_COLOR_SCHEME)) + #define GTK_IS_V3270_COLOR_SCHEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270_COLOR_SCHEME)) + #define GTK_V3270_COLOR_SCHEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270_COLOR_SCHEME, V3270ColorSchemeClass)) + + typedef struct _V3270ColorScheme V3270ColorScheme; + typedef struct _V3270ColorSchemeClass V3270ColorSchemeClass; + +/*--[ Prototipes ]-----------------------------------------------------------------------------------*/ + + LIB3270_EXPORT GtkWidget * v3270_color_scheme_new(GdkRGBA *colors); + + G_END_DECLS + +#endif // V3270_COLOR_SCHEME_H_INCLUDED diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index a4dd7ba..a4cf725 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -114,7 +114,6 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { gtk_widget_show_all(trace); } - /* v3270_set_url(terminal,url); v3270_connect(terminal); @@ -164,6 +163,9 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { // v3270_set_script(terminal,'R'); + v3270_print_all(terminal); + + } int main (int argc, char **argv) { diff --git a/src/v3270/callbacks.c b/src/v3270/callbacks.c index cb13bc1..3dd465a 100644 --- a/src/v3270/callbacks.c +++ b/src/v3270/callbacks.c @@ -326,9 +326,10 @@ static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const } -static int emit_print_signal(H3270 *session) + +static int print(H3270 *session, LIB3270_PRINT_MODE mode) { - g_signal_emit(GTK_WIDGET(lib3270_get_user_data(session)), v3270_widget_signal[SIGNAL_PRINT], 0); + v3270_print(GTK_WIDGET(lib3270_get_user_data(session)), mode); return 0; } @@ -425,7 +426,7 @@ static void popup_handler(H3270 *session, LIB3270_NOTIFY type, const char *title cbk->ctlr_done = ctlr_done; cbk->message = message; cbk->update_ssl = update_ssl; - cbk->print = emit_print_signal; + cbk->print = print; } diff --git a/src/v3270/keyboard.c b/src/v3270/keyboard.c index 971c2f6..31af866 100644 --- a/src/v3270/keyboard.c +++ b/src/v3270/keyboard.c @@ -81,14 +81,17 @@ { GDK_KP_Add, GDK_NUMLOCK_MASK, NULL, NULL }, { GDK_KP_Subtract, GDK_NUMLOCK_MASK, NULL, NULL }, - { GDK_3270_PrintScreen, 0, lib3270_print, NULL }, + { GDK_3270_PrintScreen, 0, lib3270_print_all, NULL }, + { GDK_P, GDK_CONTROL_MASK, lib3270_print_all, NULL }, + { GDK_Sys_Req, 0, lib3270_sysreq, NULL }, - { GDK_Print, GDK_CONTROL_MASK, lib3270_print, NULL }, + { GDK_Print, GDK_CONTROL_MASK, lib3270_print_all, NULL }, { GDK_Print, GDK_SHIFT_MASK, lib3270_sysreq, NULL }, { GDK_Control_R, 0, NULL, NULL }, { GDK_Control_L, 0, NULL, NULL }, + #ifdef WIN32 { GDK_Pause, 0, NULL, NULL }, #endif diff --git a/src/v3270/marshal b/src/v3270/marshal index 0840b39..729551b 100644 --- a/src/v3270/marshal +++ b/src/v3270/marshal @@ -11,3 +11,4 @@ BOOLEAN:VOID,BOOLEAN,BOOLEAN,POINTER VOID:VOID,UINT,UINT VOID:VOID,UINT,POINTER,POINTER,POINTER BOOLEAN:VOID,BOOLEAN,UINT,POINTER +VOID:VOID,POINTER,UINT diff --git a/src/v3270/print.c b/src/v3270/print.c new file mode 100644 index 0000000..1ed231d --- /dev/null +++ b/src/v3270/print.c @@ -0,0 +1,541 @@ +/* + * "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 + #include + + #define AUTO_FONT_SIZE 1 + +#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) + { + 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; + + gtk_print_operation_set_n_pages(prt,info->pages); + } + + static void draw_screen(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) + { + int row; + int col; + cairo_t * cr = gtk_print_context_get_cairo_context(context); + int baddr = info->baddr; + GdkRectangle rect; + + cairo_set_scaled_font(cr,info->font.scaled); + + memset(&rect,0,sizeof(rect)); + rect.y = 2; + rect.height = (info->font.height + info->font.descent); + rect.width = info->font.width; + + // 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); + + } + } + + /* + 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); +} +*/ + + static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info) + { + debug("%s(%p)",__FUNCTION__,info->widget); + g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_DONE], 0, prt, (guint) result); + + + 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); + + } + +#endif // !AUTO_FONT_SIZE + + static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info) + { + 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;ffont.family)) + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); + } + } + + g_free(families); + } +#else + { + widget = gtk_font_button_new_with_font(info->font); + 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); + + } +#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); + + + widget = v3270_color_scheme_new(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") ); + + 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); + } + + gtk_table_attach(GTK_TABLE(container),widget,1,2,2,3,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); + + // Show and return + gtk_widget_show_all(container); + + return G_OBJECT(container); + } + + static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget, PRINT_INFO *info) + { + 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); + + if(info->font.family) + set_string_to_config("print",FONT_CONFIG,info->font.family); + + 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__); + */ + + } + + static GtkPrintOperation * begin_print_operation(GtkWidget *widget, PRINT_INFO **info) + { + 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); + + debug("%s",__FUNCTION__); + gtk_print_operation_set_custom_tab_label(print, _( "Options" ) ); + gtk_print_operation_set_show_progress(print,TRUE); + + // 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); +#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) + { + cairo_t * cr = gtk_print_context_get_cairo_context(context); + GdkRectangle rect; + int row = pg*info->lpp; + int l; + + 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; + + 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); + } + + } + + 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_val_if_fail(GTK_IS_V3270(widget),EINVAL); + + print = begin_print_operation(widget,&info); + if(!print) + return; + + lib3270_get_screen_size(info->widget->host,&info->rows,&info->cols); + + 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; + + case LIB3270_PRINT_COPY: + + 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); + + } + + void v3270_print(GtkWidget *widget, LIB3270_PRINT_MODE mode) + { + print_operation(widget,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, mode); + } + + void v3270_print_all(GtkWidget *widget) + { + v3270_print(widget,LIB3270_PRINT_ALL); + } + + void v3270_print_selected(GtkWidget *widget) + { + v3270_print(widget,LIB3270_PRINT_SELECTED); + } + + void v3270_print_copy(GtkWidget *widget) + { + v3270_print(widget,LIB3270_PRINT_COPY); + } diff --git a/src/v3270/private.h b/src/v3270/private.h index 5bdd946..4818f41 100644 --- a/src/v3270/private.h +++ b/src/v3270/private.h @@ -79,7 +79,9 @@ G_BEGIN_DECLS SIGNAL_CHANGED, SIGNAL_MESSAGE, SIGNAL_FIELD, - SIGNAL_PRINT, + SIGNAL_PRINT_BEGIN, + SIGNAL_PRINT_APPLY, + SIGNAL_PRINT_DONE, LAST_SIGNAL }; diff --git a/src/v3270/widget.c b/src/v3270/widget.c index 5c1f793..0c06c42 100644 --- a/src/v3270/widget.c +++ b/src/v3270/widget.c @@ -495,6 +495,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), @@ -503,6 +504,34 @@ static void v3270_class_init(v3270Class *klass) NULL, NULL, v3270_VOID__VOID, G_TYPE_NONE, 0); + */ + + v3270_widget_signal[SIGNAL_PRINT_BEGIN] = + g_signal_new( "print-begin", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + v3270_VOID__VOID_POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER, 0); + + v3270_widget_signal[SIGNAL_PRINT_APPLY] = + g_signal_new( "print-apply", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + v3270_VOID__VOID_POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER, 0); + + v3270_widget_signal[SIGNAL_PRINT_DONE] = + g_signal_new( "print-done", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + v3270_VOID__VOID_POINTER_UINT, + G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_UINT, 0); v3270_init_properties(gobject_class); diff --git a/v3270.cbp b/v3270.cbp index a3e7bf4..7b0f15b 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -42,6 +42,9 @@ + + @@ -50,6 +53,7 @@ + @@ -98,6 +102,9 @@ + +