From b3d7d133b9043857006241a7ad48d45ceea0c6df Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Mon, 26 Mar 2012 11:10:42 +0000 Subject: [PATCH] Implementando novo diálogo de impressão --- colors.conf | 42 ++++++++++++++++++++++++++++++++++++++++++ src/gtk/actions.c | 4 ++-- src/gtk/print.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 121 insertions(+), 24 deletions(-) create mode 100644 colors.conf diff --git a/colors.conf b/colors.conf new file mode 100644 index 0000000..1ba64d9 --- /dev/null +++ b/colors.conf @@ -0,0 +1,42 @@ +[X3270] +Label=X3270 +Terminal=black,deepSkyBlue,red,pink,green,turquoise,yellow,white,black,blue3,orange,purple,paleGreen,paleTurquoise2,grey,white +BaseAttributes=green,red,deepSkyBlue,white +SelectedText=dimGrey,black,dimGrey +Cursor=white,white +OIA=black,white,white,white,white + +[Reverse] +Label=Reverse +Label[pt_BR]=Invertido +Terminal=white,blue,firebrick,pink,green4,cadetBlue,goldenrod,black,black,blue3,orange,purple,paleGreen,darkTurquoise,grey,black +BaseAttributes=green4,firebrick,blue,black +SelectedText=dimGrey,black,dimGrey +Cursor=black,black +OIA=white,black,black,black,black + +[Bright] +Label=Bright +Label[pt_BR]=Cores fortes +Terminal=black,blue,red,magenta,green,turquoise,yellow,white,black,blue3,orange,purple,paleGreen,cyan,grey,white +BaseAttributes=green,red,blue,white +SelectedText=dimGrey,black,dimGrey +Cursor=white,white +OIA=black,white,white,white,white + +[CPE] +Label=CPE +Terminal=black,LightBlue1,PaleVioletRed1,pink,green,turquoise,yellow,white,black,LightBlue3,orange,MediumPurple1,paleGreen,paleTurquoise2,grey80,white +BaseAttributes=green,PaleVioletRed1,LightBlue1,white +SelectedText=dimGrey,black,dimGrey +Cursor=white,white +OIA=black,white,white,white,white + +[Green] +Label=Green +Label[pt_BR]=Verde +Terminal=black,green,green,green,green,green,green,green,green,green,green,green,green,green,green,green +BaseAttributes=green,green,green,green +SelectedText=dimGrey,green,dimGrey +Cursor=green,green +OIA=black,green,green,green,green diff --git a/src/gtk/actions.c b/src/gtk/actions.c index e3a9f67..2b6fd82 100644 --- a/src/gtk/actions.c +++ b/src/gtk/actions.c @@ -201,14 +201,14 @@ static void lib3270_toggle_action(GtkToggleAction *action,GtkWidget *widget) static void selection_move_action(GtkAction *action, GtkWidget *widget) { - trace("Action %s activated on widget %p dir=%s",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"direction")); + trace("Action %s activated on widget %p dir=%s",gtk_action_get_name(action),widget,(const gchar *) g_object_get_data(G_OBJECT(action),"direction")); lib3270_move_selection(GTK_V3270(widget)->host,(LIB3270_DIRECTION) g_object_get_data(G_OBJECT(action),"direction")); } static void cursor_move_action(GtkAction *action, GtkWidget *widget) { int flags = (int) g_object_get_data(G_OBJECT(action),"move_flags"); - trace("Action %s activated on widget %p flags=%04x",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"move_flags")); + trace("Action %s activated on widget %p flags=%04x",gtk_action_get_name(action),widget,(unsigned short) g_object_get_data(G_OBJECT(action),"move_flags")); lib3270_move_cursor(GTK_V3270(widget)->host,(LIB3270_DIRECTION) (flags & 0x03), (flags & 0x80) ); } diff --git a/src/gtk/print.c b/src/gtk/print.c index 41bdeab..4fea777 100644 --- a/src/gtk/print.c +++ b/src/gtk/print.c @@ -36,28 +36,60 @@ typedef struct _print_info { - GdkColor color[V3270_COLOR_COUNT]; + GdkColor color[V3270_COLOR_COUNT]; + H3270 * session; + gchar * font; + int rows; + int cols; + int pages; + cairo_font_extents_t extents; + cairo_scaled_font_t * font_scaled; } PRINT_INFO; /*--[ Implement ]------------------------------------------------------------------------------------*/ - static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) + static void setup_font(cairo_t *cr, PRINT_INFO *info) { - trace("%s",__FUNCTION__); - gtk_print_operation_cancel(prt); + cairo_select_font_face(cr, info->font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + + info->font_scaled = cairo_get_scaled_font(cr); + cairo_scaled_font_reference(info->font_scaled); + cairo_scaled_font_extents(info->font_scaled,&info->extents); + + } + + static void begin_print_all(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) + { + cairo_t *cr = gtk_print_context_get_cairo_context(context); + + lib3270_get_screen_size(info->session,&info->rows,&info->cols); + setup_font(cr,info); + + gtk_print_operation_set_n_pages(prt,1); } static void draw_page(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) { - trace("%s",__FUNCTION__); + cairo_t *cr = gtk_print_context_get_cairo_context(context); + + cairo_set_scaled_font(cr,info->font_scaled); + cairo_move_to(cr,0,0); + cairo_show_text(cr, "Teste"); + + cairo_stroke(cr); } static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info) { trace("%s",__FUNCTION__); + if(info->font_scaled) + cairo_scaled_font_destroy(info->font_scaled); + + if(info->font) + g_free(info->font); g_free(info); } @@ -69,28 +101,41 @@ } #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)); + set_string_to_config("print","font","%s",info->font); + trace("Font set to \"%s\"",info->font); + } + static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) { - static const gchar * label[] = { "Font:", "Colors:" }; + static const gchar * label[] = { N_( "Font:" ), N_( "Colors:" ) }; GtkWidget * container = gtk_table_new(2,2,FALSE); GtkWidget * widget; int f; for(f=0;ffont = get_string_from_config("print","font","Courier 10"); + gtk_font_button_set_font_name((GtkFontButton *) widget,info->font); + g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info); + // Color scheme dropdown // Show and return @@ -103,33 +148,39 @@ trace("%s",__FUNCTION__); } - static GtkPrintOperation * begin_print_operation(GtkAction *action, GtkWidget *widget) + static GtkPrintOperation * begin_print_operation(GtkAction *action, GtkWidget *widget, PRINT_INFO **info) { - PRINT_INFO * info = g_new0(PRINT_INFO,1); GtkPrintOperation * print = gtk_print_operation_new(); // GtkPrintSettings * settings = gtk_print_settings_new(); // GtkPageSetup * setup = gtk_page_setup_new(); -// gchar * ptr; + const gchar * attr; + + *info = g_new0(PRINT_INFO,1); + (*info)->session = v3270_get_session(widget); // Basic setup gtk_print_operation_set_allow_async(print,TRUE); -/* - ptr = g_strconcat(PACKAGE_NAME,".",gtk_action_get_name(action),NULL); - gtk_print_operation_set_job_name(print,ptr); - g_free(ptr); -*/ + attr = (const gchar *) g_object_get_data(G_OBJECT(action),"jobname"); + if(attr) + { + gtk_print_operation_set_job_name(print,attr); + } + else + { + gchar *ptr = g_strconcat(PACKAGE_NAME,".",gtk_action_get_name(action),NULL); + gtk_print_operation_set_job_name(print,ptr); + g_free(ptr); + } gtk_print_operation_set_custom_tab_label(print,_( "Style" )); // gtk_print_operation_set_show_progress(print,TRUE); // Common signals - g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info); - g_signal_connect(print,"draw_page",G_CALLBACK(draw_page),info); - g_signal_connect(print,"done",G_CALLBACK(done),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); + g_signal_connect(print,"done",G_CALLBACK(done),*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); // Finish settings // gtk_print_operation_set_print_settings(print,settings); @@ -140,10 +191,14 @@ void print_all_action(GtkAction *action, GtkWidget *widget) { - GtkPrintOperation *print = begin_print_operation(action,widget); + PRINT_INFO * info = NULL; + GtkPrintOperation * print = begin_print_operation(action,widget,&info); trace("Action %s activated on widget %p print=%p",gtk_action_get_name(action),widget,print); + g_signal_connect(print,"begin_print",G_CALLBACK(begin_print_all),info); + g_signal_connect(print,"draw_page",G_CALLBACK(draw_page),info); + // Run Print dialog gtk_print_operation_run(print,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),NULL); -- libgit2 0.21.2