From 3d52cd0c26b2b80527318b89528ca9ae9cfaf21e Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Tue, 27 Mar 2012 14:07:42 +0000 Subject: [PATCH] Implementando opção para imprimir apenas o bloco selecionado --- colors.conf | 9 --------- src/gtk/print.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/gtk/v3270/draw.c | 36 ++++++++++++++---------------------- src/include/lib3270/selection.h | 12 ++++++++++++ src/lib3270/selection.c | 20 ++++++++++++++++++++ 5 files changed, 112 insertions(+), 39 deletions(-) diff --git a/colors.conf b/colors.conf index fb65096..94796d1 100644 --- a/colors.conf +++ b/colors.conf @@ -41,15 +41,6 @@ SelectedText=dimGrey,green,dimGrey Cursor=green,green OIA=black,green,green,green,green -[BW] -Label=Black & White -Label[pt_BR]=Branco e preto -Terminal=black,white,white,white,white,white,white,white,white,white,white,white,white,white,white,white -BaseAttributes=white,white,white,white -SelectedText=dimGrey,white,dimGrey -Cursor=white,white -OIA=black,green,white,white - [WB] Label=White on Black Label[pt_BR]=Branco com fundo preto diff --git a/src/gtk/print.c b/src/gtk/print.c index dd3582d..0419146 100644 --- a/src/gtk/print.c +++ b/src/gtk/print.c @@ -37,6 +37,9 @@ typedef struct _print_info { GdkColor color[V3270_COLOR_COUNT]; + int show_selection : 1; + int all : 1; + H3270 * session; gchar * font; guint fontsize; @@ -77,9 +80,8 @@ } - static void begin_print_all(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) + static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) { - lib3270_get_screen_size(info->session,&info->rows,&info->cols); setup_font(context,info); gtk_print_operation_set_n_pages(prt,1); } @@ -115,8 +117,12 @@ unsigned char c; unsigned short attr; - if(!lib3270_get_element(info->session,baddr++,&c,&attr)) + if(!lib3270_get_element(info->session,baddr++,&c,&attr) && (info->all || (attr & LIB3270_ATTR_SELECTED))) + { + if(!info->show_selection) + attr &= ~LIB3270_ATTR_SELECTED; v3270_draw_element(cr,c,attr,info->session,info->extents.height,&rect,info->color); + } rect.x += (rect.width-1); } @@ -205,6 +211,13 @@ } + static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info) + { + gboolean active = gtk_toggle_button_get_active(togglebutton); + info->show_selection = active ? 1 : 0; + set_boolean_to_config("print","selection",active); + } + static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) { static const gchar *def_colors = "white," // V3270_COLOR_BACKGROUND @@ -239,7 +252,7 @@ "black"; // V3270_COLOR_OIA_STATUS_INVALID static const gchar * label[] = { N_( "Font:" ), N_( "Color scheme:" ) }; - GtkWidget * container = gtk_table_new(2,2,FALSE); + GtkWidget * container = gtk_table_new(3,2,FALSE); GtkWidget * widget; int f; @@ -277,6 +290,22 @@ 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->all) + { + info->show_selection = get_boolean_from_config("print","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); @@ -315,9 +344,8 @@ g_free(ptr); } - gtk_print_operation_set_custom_tab_label(print,_( "Style" )); - -// gtk_print_operation_set_show_progress(print,TRUE); + 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); @@ -338,7 +366,10 @@ 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); + lib3270_get_screen_size(info->session,&info->rows,&info->cols); + + info->all = 1; + g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info); g_signal_connect(print,"draw_page",G_CALLBACK(draw_page),info); // Run Print dialog @@ -350,8 +381,35 @@ void print_selected_action(GtkAction *action, GtkWidget *widget) { + PRINT_INFO * info = NULL; + int start, end, rows; + GtkPrintOperation * print = begin_print_operation(action,widget,&info);; + trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); + if(lib3270_get_selected_addr(info->session,&start,&end)) + { + g_warning("Can't get selected addresses for action %s",gtk_action_get_name(action)); + g_object_unref(print); + return; + } + + info->baddr = start; + lib3270_get_screen_size(info->session,&rows,&info->cols); + + info->rows = ((end / info->cols) - (start / info->cols))+1; + + trace("First row: %d End row: %d Num rows: %d",(start / info->cols),(end / info->cols),info->rows); + + info->all = 0; + g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),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); + + + g_object_unref(print); } void print_copy_action(GtkAction *action, GtkWidget *widget) diff --git a/src/gtk/v3270/draw.c b/src/gtk/v3270/draw.c index c44dfde..ee8a2fb 100644 --- a/src/gtk/v3270/draw.c +++ b/src/gtk/v3270/draw.c @@ -93,26 +93,30 @@ gboolean v3270_expose(GtkWidget *widget, GdkEventExpose *event) #endif // GTk3 -void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color) +static void get_element_colors(unsigned short attr, GdkColor **fg, GdkColor **bg, GdkColor *color) { - GdkColor *fg; - GdkColor *bg; - if(attr & LIB3270_ATTR_SELECTED) { - fg = color+V3270_COLOR_SELECTED_FG; - bg = color+V3270_COLOR_SELECTED_BG; + *fg = color+V3270_COLOR_SELECTED_FG; + *bg = color+V3270_COLOR_SELECTED_BG; } else { - bg = color+((attr & 0x00F0) >> 4); + *bg = color+((attr & 0x00F0) >> 4); if(attr & LIB3270_ATTR_FIELD) - fg = color+(attr & 0x0003)+V3270_COLOR_FIELD; + *fg = color+(attr & 0x0003)+V3270_COLOR_FIELD; else - fg = color+(attr & 0x000F); + *fg = color+(attr & 0x000F); } +} +void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color) +{ + GdkColor *fg; + GdkColor *bg; + + get_element_colors(attr,&fg,&bg,color); v3270_draw_char(cr,chr,attr,session,height,rect,fg,bg); } @@ -368,19 +372,7 @@ void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short GdkColor * fg; GdkColor * bg; - if(attr & LIB3270_ATTR_SELECTED) - { - fg = widget->color+V3270_COLOR_SELECTED_FG; - bg = widget->color+V3270_COLOR_SELECTED_BG; - } - else - { - fg = widget->color+((attr & 0x00F0) >> 4); - if(attr & LIB3270_ATTR_FIELD) - bg = widget->color+(attr & 0x0003)+V3270_COLOR_FIELD; - else - bg = widget->color+(attr & 0x000F); - } + get_element_colors(attr,&fg,&bg,widget->color); cairo_set_scaled_font(cr,widget->font_scaled); diff --git a/src/include/lib3270/selection.h b/src/include/lib3270/selection.h index 7b0bd51..63a5da1 100644 --- a/src/include/lib3270/selection.h +++ b/src/include/lib3270/selection.h @@ -73,5 +73,17 @@ */ LIB3270_EXPORT int lib3270_move_selection(H3270 *h, LIB3270_DIRECTION dir); + /** + * Get addresses of selected area. + * + * @param h Session handle. + * @param begin Pointer to the begin value. + * @param end Pointer to the end value. + * + * @return 0 if the selected area was get, non zero if unselected or unavailable. + * + */ + LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end); + #endif // LIB3270_SELECTION_H_INCLUDED diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index 72f6934..eb3c0f3 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -360,6 +360,26 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) return get_text(hSession,0); } +LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end) +{ + if(!hSession->selected || hSession->select.begin == hSession->select.end) + return -1; + + if(hSession->select.end > hSession->select.begin) + { + *begin = hSession->select.begin; + *end = hSession->select.end; + } + else + { + *begin = hSession->select.end; + *end = hSession->select.begin; + } + + return 0; +} + + LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) { if(!hSession->selected || hSession->select.begin == hSession->select.end) -- libgit2 0.21.2