Commit 25c36ce46ad518f2ca1f851d607e69c31a375773

Authored by perry.werneck@gmail.com
1 parent b2e41aad

gtk3 for windows da segfault quando usa "custom widgets" no dialogo de impressao

Showing 2 changed files with 66 additions and 14 deletions   Show diff stats
src/include/pw3270.h
... ... @@ -68,6 +68,17 @@
68 68  
69 69 LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint def);
70 70  
  71 + typedef enum pw3270_src
  72 + {
  73 + PW3270_SRC_ALL, /**< Screen contents */
  74 + PW3270_SRC_SELECTED, /**< Selected region */
  75 +
  76 + PW3270_SRC_USER
  77 + } PW3270_SRC;
  78 +
  79 + LIB3270_EXPORT void pw3270_print(GtkWidget *widget, GObject *action, GtkPrintOperationAction oper, PW3270_SRC src);
  80 +
  81 +
71 82 #ifdef HAVE_GTKMAC
72 83 #include <gtk-mac-bundle.h>
73 84 LIB3270_EXPORT GtkMacBundle * pw3270_get_bundle(void);
... ...
src/pw3270/print.c
... ... @@ -39,7 +39,7 @@
39 39 {
40 40 GdkColor color[V3270_COLOR_COUNT];
41 41 int show_selection : 1;
42   - int all : 1;
  42 + PW3270_SRC src;
43 43  
44 44 H3270 * session;
45 45 gchar * font;
... ... @@ -66,6 +66,7 @@
66 66 {
67 67 cairo_t *cr = gtk_print_context_get_cairo_context(context);
68 68  
  69 + trace("Font: %s",info->font);
69 70 cairo_select_font_face(cr, info->font, CAIRO_FONT_SLANT_NORMAL, info->fontweight);
70 71  
71 72 info->font_scaled = cairo_get_scaled_font(cr);
... ... @@ -127,7 +128,7 @@
127 128 unsigned char c;
128 129 unsigned short attr;
129 130  
130   - if(!lib3270_get_element(info->session,baddr++,&c,&attr) && (info->all || (attr & LIB3270_ATTR_SELECTED)))
  131 + if(!lib3270_get_element(info->session,baddr++,&c,&attr) && (info->src == PW3270_SRC_ALL || (attr & LIB3270_ATTR_SELECTED)))
131 132 {
132 133 if(!info->show_selection)
133 134 attr &= ~LIB3270_ATTR_SELECTED;
... ... @@ -298,15 +299,30 @@ static gchar * enum_to_string(GType type, guint enum_value)
298 299 set_boolean_to_config("print","selection",active);
299 300 }
300 301  
  302 + static void load_settings(PRINT_INFO *i)
  303 + {
  304 + gchar *ptr = get_string_from_config("print","colors","");
  305 +
  306 + i->font = get_string_from_config("print","font","Courier 10");
  307 +
  308 + if(*ptr)
  309 + v3270_set_color_table(i->color,ptr);
  310 + else
  311 + v3270_set_mono_color_table(i->color,"black","white");
  312 + g_free(ptr);
  313 + }
  314 +
301 315 static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info)
302 316 {
303   - static const gchar * text[] = { N_( "_Font:" ), N_( "C_olor scheme:" ) };
304 317 GtkWidget * container = gtk_table_new(3,2,FALSE);
  318 + static const gchar * text[] = { N_( "_Font:" ), N_( "C_olor scheme:" ) };
305 319 GtkWidget * label[G_N_ELEMENTS(text)];
306 320 GtkWidget * widget;
307 321 int f;
308 322 gchar * ptr;
309 323  
  324 + trace("%s starts",__FUNCTION__);
  325 +
310 326 for(f=0;f<G_N_ELEMENTS(label);f++)
311 327 {
312 328 label[f] = gtk_label_new_with_mnemonic(gettext(text[f]));
... ... @@ -323,19 +339,11 @@ static gchar * enum_to_string(GType type, guint enum_value)
323 339 #endif // GTK(3,2,0)
324 340 gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);
325 341  
326   - info->font = get_string_from_config("print","font","Courier 10");
  342 + load_settings(info);
327 343 gtk_font_button_set_font_name((GtkFontButton *) widget,info->font);
328 344 font_set((GtkFontButton *) widget,info);
329 345 g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info);
330 346  
331   - // Color scheme dropdown
332   - ptr = get_string_from_config("print","colors","");
333   - if(*ptr)
334   - v3270_set_color_table(info->color,ptr);
335   - else
336   - v3270_set_mono_color_table(info->color,"black","white");
337   - g_free(ptr);
338   -
339 347 widget = color_scheme_new(info->color);
340 348 gtk_label_set_mnemonic_widget(GTK_LABEL(label[1]),widget);
341 349  
... ... @@ -345,7 +353,7 @@ static gchar * enum_to_string(GType type, guint enum_value)
345 353 // Selection checkbox
346 354 widget = gtk_check_button_new_with_label(_("Print selection box"));
347 355  
348   - if(info->all)
  356 + if(info->src == PW3270_SRC_ALL)
349 357 {
350 358 info->show_selection = get_boolean_from_config("print","selection",FALSE);
351 359 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),info->show_selection);
... ... @@ -361,7 +369,7 @@ static gchar * enum_to_string(GType type, guint enum_value)
361 369 // Show and return
362 370 gtk_widget_show_all(container);
363 371  
364   - trace("%s ends",__FUNCTION__);
  372 + trace("%s ends container=%p",__FUNCTION__,container);
365 373 return G_OBJECT(container);
366 374 }
367 375  
... ... @@ -419,8 +427,13 @@ static gchar * enum_to_string(GType type, guint enum_value)
419 427  
420 428 // Common signals
421 429 g_signal_connect(print,"done",G_CALLBACK(done),*info);
  430 +
  431 +#if GTK_CHECK_VERSION(3,0,0) && !defined(WIN32)
422 432 g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info);
423 433 g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info);
  434 +#else
  435 + load_settings(*info);
  436 +#endif // WIN32
424 437  
425 438 // Load page and print settings
426 439 {
... ... @@ -485,6 +498,9 @@ static gchar * enum_to_string(GType type, guint enum_value)
485 498  
486 499 void print_all_action(GtkAction *action, GtkWidget *widget)
487 500 {
  501 + pw3270_print(widget,G_OBJECT(action),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, PW3270_SRC_ALL);
  502 +
  503 +/*
488 504 PRINT_INFO * info = NULL;
489 505 GtkPrintOperation * print = begin_print_operation(G_OBJECT(action),widget,&info);
490 506  
... ... @@ -503,10 +519,14 @@ static gchar * enum_to_string(GType type, guint enum_value)
503 519  
504 520  
505 521 g_object_unref(print);
  522 +*/
506 523 }
507 524  
508 525 void print_selected_action(GtkAction *action, GtkWidget *widget)
509 526 {
  527 + pw3270_print(widget,G_OBJECT(action),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, PW3270_SRC_SELECTED);
  528 +
  529 +/*
510 530 PRINT_INFO * info = NULL;
511 531 int start, end, rows;
512 532 GtkPrintOperation * print = begin_print_operation(G_OBJECT(action),widget,&info);;
... ... @@ -537,6 +557,7 @@ static gchar * enum_to_string(GType type, guint enum_value)
537 557 gtk_print_operation_run(print,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),NULL);
538 558  
539 559 g_object_unref(print);
  560 +*/
540 561 }
541 562  
542 563 static void draw_text(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info)
... ... @@ -598,3 +619,23 @@ static gchar * enum_to_string(GType type, guint enum_value)
598 619 g_object_unref(print);
599 620 }
600 621  
  622 + LIB3270_EXPORT void pw3270_print(GtkWidget *widget, GObject *action, GtkPrintOperationAction oper, PW3270_SRC src)
  623 + {
  624 + PRINT_INFO * info = NULL;
  625 + GtkPrintOperation * print = begin_print_operation(action,widget,&info);
  626 +
  627 + #ifdef X3270_TRACE
  628 + if(action)
  629 + lib3270_trace_event(NULL,"Action %s activated on widget %p\n",gtk_action_get_name(GTK_ACTION(action)),widget);
  630 + #endif
  631 +
  632 + lib3270_get_screen_size(info->session,&info->rows,&info->cols);
  633 +
  634 + info->src = src;
  635 + g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info);
  636 + g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info);
  637 +
  638 + // Run Print dialog
  639 + gtk_print_operation_run(print,oper,GTK_WINDOW(gtk_widget_get_toplevel(widget)),NULL);
  640 + g_object_unref(print);
  641 + }
... ...