Commit 3d52cd0c26b2b80527318b89528ca9ae9cfaf21e

Authored by perry.werneck@gmail.com
1 parent 6d5ebe31

Implementando opção para imprimir apenas o bloco selecionado

colors.conf
... ... @@ -41,15 +41,6 @@ SelectedText=dimGrey,green,dimGrey
41 41 Cursor=green,green
42 42 OIA=black,green,green,green,green
43 43  
44   -[BW]
45   -Label=Black & White
46   -Label[pt_BR]=Branco e preto
47   -Terminal=black,white,white,white,white,white,white,white,white,white,white,white,white,white,white,white
48   -BaseAttributes=white,white,white,white
49   -SelectedText=dimGrey,white,dimGrey
50   -Cursor=white,white
51   -OIA=black,green,white,white
52   -
53 44 [WB]
54 45 Label=White on Black
55 46 Label[pt_BR]=Branco com fundo preto
... ...
src/gtk/print.c
... ... @@ -37,6 +37,9 @@
37 37 typedef struct _print_info
38 38 {
39 39 GdkColor color[V3270_COLOR_COUNT];
  40 + int show_selection : 1;
  41 + int all : 1;
  42 +
40 43 H3270 * session;
41 44 gchar * font;
42 45 guint fontsize;
... ... @@ -77,9 +80,8 @@
77 80  
78 81 }
79 82  
80   - static void begin_print_all(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info)
  83 + static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info)
81 84 {
82   - lib3270_get_screen_size(info->session,&info->rows,&info->cols);
83 85 setup_font(context,info);
84 86 gtk_print_operation_set_n_pages(prt,1);
85 87 }
... ... @@ -115,8 +117,12 @@
115 117 unsigned char c;
116 118 unsigned short attr;
117 119  
118   - if(!lib3270_get_element(info->session,baddr++,&c,&attr))
  120 + if(!lib3270_get_element(info->session,baddr++,&c,&attr) && (info->all || (attr & LIB3270_ATTR_SELECTED)))
  121 + {
  122 + if(!info->show_selection)
  123 + attr &= ~LIB3270_ATTR_SELECTED;
119 124 v3270_draw_element(cr,c,attr,info->session,info->extents.height,&rect,info->color);
  125 + }
120 126  
121 127 rect.x += (rect.width-1);
122 128 }
... ... @@ -205,6 +211,13 @@
205 211  
206 212 }
207 213  
  214 + static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info)
  215 + {
  216 + gboolean active = gtk_toggle_button_get_active(togglebutton);
  217 + info->show_selection = active ? 1 : 0;
  218 + set_boolean_to_config("print","selection",active);
  219 + }
  220 +
208 221 static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info)
209 222 {
210 223 static const gchar *def_colors = "white," // V3270_COLOR_BACKGROUND
... ... @@ -239,7 +252,7 @@
239 252 "black"; // V3270_COLOR_OIA_STATUS_INVALID
240 253  
241 254 static const gchar * label[] = { N_( "Font:" ), N_( "Color scheme:" ) };
242   - GtkWidget * container = gtk_table_new(2,2,FALSE);
  255 + GtkWidget * container = gtk_table_new(3,2,FALSE);
243 256 GtkWidget * widget;
244 257 int f;
245 258  
... ... @@ -277,6 +290,22 @@
277 290  
278 291 gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);
279 292  
  293 + // Selection checkbox
  294 + widget = gtk_check_button_new_with_label(_("Print selection box"));
  295 +
  296 + if(info->all)
  297 + {
  298 + info->show_selection = get_boolean_from_config("print","selection",FALSE);
  299 + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),info->show_selection);
  300 + g_signal_connect(G_OBJECT(widget),"toggled",G_CALLBACK(toggle_show_selection),info);
  301 + }
  302 + else
  303 + {
  304 + gtk_widget_set_sensitive(widget,FALSE);
  305 + }
  306 +
  307 + gtk_table_attach(GTK_TABLE(container),widget,1,2,2,3,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);
  308 +
280 309 // Show and return
281 310 gtk_widget_show_all(container);
282 311 return G_OBJECT(container);
... ... @@ -315,9 +344,8 @@
315 344 g_free(ptr);
316 345 }
317 346  
318   - gtk_print_operation_set_custom_tab_label(print,_( "Style" ));
319   -
320   -// gtk_print_operation_set_show_progress(print,TRUE);
  347 + gtk_print_operation_set_custom_tab_label(print,_( "Options" ));
  348 + gtk_print_operation_set_show_progress(print,TRUE);
321 349  
322 350 // Common signals
323 351 g_signal_connect(print,"done",G_CALLBACK(done),*info);
... ... @@ -338,7 +366,10 @@
338 366  
339 367 trace("Action %s activated on widget %p print=%p",gtk_action_get_name(action),widget,print);
340 368  
341   - g_signal_connect(print,"begin_print",G_CALLBACK(begin_print_all),info);
  369 + lib3270_get_screen_size(info->session,&info->rows,&info->cols);
  370 +
  371 + info->all = 1;
  372 + g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info);
342 373 g_signal_connect(print,"draw_page",G_CALLBACK(draw_page),info);
343 374  
344 375 // Run Print dialog
... ... @@ -350,8 +381,35 @@
350 381  
351 382 void print_selected_action(GtkAction *action, GtkWidget *widget)
352 383 {
  384 + PRINT_INFO * info = NULL;
  385 + int start, end, rows;
  386 + GtkPrintOperation * print = begin_print_operation(action,widget,&info);;
  387 +
353 388 trace("Action %s activated on widget %p",gtk_action_get_name(action),widget);
354 389  
  390 + if(lib3270_get_selected_addr(info->session,&start,&end))
  391 + {
  392 + g_warning("Can't get selected addresses for action %s",gtk_action_get_name(action));
  393 + g_object_unref(print);
  394 + return;
  395 + }
  396 +
  397 + info->baddr = start;
  398 + lib3270_get_screen_size(info->session,&rows,&info->cols);
  399 +
  400 + info->rows = ((end / info->cols) - (start / info->cols))+1;
  401 +
  402 + trace("First row: %d End row: %d Num rows: %d",(start / info->cols),(end / info->cols),info->rows);
  403 +
  404 + info->all = 0;
  405 + g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info);
  406 + g_signal_connect(print,"draw_page",G_CALLBACK(draw_page),info);
  407 +
  408 + // Run Print dialog
  409 + gtk_print_operation_run(print,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),NULL);
  410 +
  411 +
  412 + g_object_unref(print);
355 413 }
356 414  
357 415 void print_copy_action(GtkAction *action, GtkWidget *widget)
... ...
src/gtk/v3270/draw.c
... ... @@ -93,26 +93,30 @@ gboolean v3270_expose(GtkWidget *widget, GdkEventExpose *event)
93 93 #endif // GTk3
94 94  
95 95  
96   -void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color)
  96 +static void get_element_colors(unsigned short attr, GdkColor **fg, GdkColor **bg, GdkColor *color)
97 97 {
98   - GdkColor *fg;
99   - GdkColor *bg;
100   -
101 98 if(attr & LIB3270_ATTR_SELECTED)
102 99 {
103   - fg = color+V3270_COLOR_SELECTED_FG;
104   - bg = color+V3270_COLOR_SELECTED_BG;
  100 + *fg = color+V3270_COLOR_SELECTED_FG;
  101 + *bg = color+V3270_COLOR_SELECTED_BG;
105 102 }
106 103 else
107 104 {
108   - bg = color+((attr & 0x00F0) >> 4);
  105 + *bg = color+((attr & 0x00F0) >> 4);
109 106  
110 107 if(attr & LIB3270_ATTR_FIELD)
111   - fg = color+(attr & 0x0003)+V3270_COLOR_FIELD;
  108 + *fg = color+(attr & 0x0003)+V3270_COLOR_FIELD;
112 109 else
113   - fg = color+(attr & 0x000F);
  110 + *fg = color+(attr & 0x000F);
114 111 }
  112 +}
115 113  
  114 +void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color)
  115 +{
  116 + GdkColor *fg;
  117 + GdkColor *bg;
  118 +
  119 + get_element_colors(attr,&fg,&bg,color);
116 120 v3270_draw_char(cr,chr,attr,session,height,rect,fg,bg);
117 121 }
118 122  
... ... @@ -368,19 +372,7 @@ void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short
368 372 GdkColor * fg;
369 373 GdkColor * bg;
370 374  
371   - if(attr & LIB3270_ATTR_SELECTED)
372   - {
373   - fg = widget->color+V3270_COLOR_SELECTED_FG;
374   - bg = widget->color+V3270_COLOR_SELECTED_BG;
375   - }
376   - else
377   - {
378   - fg = widget->color+((attr & 0x00F0) >> 4);
379   - if(attr & LIB3270_ATTR_FIELD)
380   - bg = widget->color+(attr & 0x0003)+V3270_COLOR_FIELD;
381   - else
382   - bg = widget->color+(attr & 0x000F);
383   - }
  375 + get_element_colors(attr,&fg,&bg,widget->color);
384 376  
385 377 cairo_set_scaled_font(cr,widget->font_scaled);
386 378  
... ...
src/include/lib3270/selection.h
... ... @@ -73,5 +73,17 @@
73 73 */
74 74 LIB3270_EXPORT int lib3270_move_selection(H3270 *h, LIB3270_DIRECTION dir);
75 75  
  76 + /**
  77 + * Get addresses of selected area.
  78 + *
  79 + * @param h Session handle.
  80 + * @param begin Pointer to the begin value.
  81 + * @param end Pointer to the end value.
  82 + *
  83 + * @return 0 if the selected area was get, non zero if unselected or unavailable.
  84 + *
  85 + */
  86 + LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end);
  87 +
76 88  
77 89 #endif // LIB3270_SELECTION_H_INCLUDED
... ...
src/lib3270/selection.c
... ... @@ -360,6 +360,26 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession)
360 360 return get_text(hSession,0);
361 361 }
362 362  
  363 +LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end)
  364 +{
  365 + if(!hSession->selected || hSession->select.begin == hSession->select.end)
  366 + return -1;
  367 +
  368 + if(hSession->select.end > hSession->select.begin)
  369 + {
  370 + *begin = hSession->select.begin;
  371 + *end = hSession->select.end;
  372 + }
  373 + else
  374 + {
  375 + *begin = hSession->select.end;
  376 + *end = hSession->select.begin;
  377 + }
  378 +
  379 + return 0;
  380 +}
  381 +
  382 +
363 383 LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir)
364 384 {
365 385 if(!hSession->selected || hSession->select.begin == hSession->select.end)
... ...