Commit b3d7d133b9043857006241a7ad48d45ceea0c6df

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

Implementando novo diálogo de impressão

Showing 3 changed files with 121 additions and 24 deletions   Show diff stats
colors.conf 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +[X3270]
  2 +Label=X3270
  3 +Terminal=black,deepSkyBlue,red,pink,green,turquoise,yellow,white,black,blue3,orange,purple,paleGreen,paleTurquoise2,grey,white
  4 +BaseAttributes=green,red,deepSkyBlue,white
  5 +SelectedText=dimGrey,black,dimGrey
  6 +Cursor=white,white
  7 +OIA=black,white,white,white,white
  8 +
  9 +[Reverse]
  10 +Label=Reverse
  11 +Label[pt_BR]=Invertido
  12 +Terminal=white,blue,firebrick,pink,green4,cadetBlue,goldenrod,black,black,blue3,orange,purple,paleGreen,darkTurquoise,grey,black
  13 +BaseAttributes=green4,firebrick,blue,black
  14 +SelectedText=dimGrey,black,dimGrey
  15 +Cursor=black,black
  16 +OIA=white,black,black,black,black
  17 +
  18 +[Bright]
  19 +Label=Bright
  20 +Label[pt_BR]=Cores fortes
  21 +Terminal=black,blue,red,magenta,green,turquoise,yellow,white,black,blue3,orange,purple,paleGreen,cyan,grey,white
  22 +BaseAttributes=green,red,blue,white
  23 +SelectedText=dimGrey,black,dimGrey
  24 +Cursor=white,white
  25 +OIA=black,white,white,white,white
  26 +
  27 +[CPE]
  28 +Label=CPE
  29 +Terminal=black,LightBlue1,PaleVioletRed1,pink,green,turquoise,yellow,white,black,LightBlue3,orange,MediumPurple1,paleGreen,paleTurquoise2,grey80,white
  30 +BaseAttributes=green,PaleVioletRed1,LightBlue1,white
  31 +SelectedText=dimGrey,black,dimGrey
  32 +Cursor=white,white
  33 +OIA=black,white,white,white,white
  34 +
  35 +[Green]
  36 +Label=Green
  37 +Label[pt_BR]=Verde
  38 +Terminal=black,green,green,green,green,green,green,green,green,green,green,green,green,green,green,green
  39 +BaseAttributes=green,green,green,green
  40 +SelectedText=dimGrey,green,dimGrey
  41 +Cursor=green,green
  42 +OIA=black,green,green,green,green
... ...
src/gtk/actions.c
... ... @@ -201,14 +201,14 @@ static void lib3270_toggle_action(GtkToggleAction *action,GtkWidget *widget)
201 201  
202 202 static void selection_move_action(GtkAction *action, GtkWidget *widget)
203 203 {
204   - trace("Action %s activated on widget %p dir=%s",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"direction"));
  204 + 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"));
205 205 lib3270_move_selection(GTK_V3270(widget)->host,(LIB3270_DIRECTION) g_object_get_data(G_OBJECT(action),"direction"));
206 206 }
207 207  
208 208 static void cursor_move_action(GtkAction *action, GtkWidget *widget)
209 209 {
210 210 int flags = (int) g_object_get_data(G_OBJECT(action),"move_flags");
211   - trace("Action %s activated on widget %p flags=%04x",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"move_flags"));
  211 + 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"));
212 212 lib3270_move_cursor(GTK_V3270(widget)->host,(LIB3270_DIRECTION) (flags & 0x03), (flags & 0x80) );
213 213 }
214 214  
... ...
src/gtk/print.c
... ... @@ -36,28 +36,60 @@
36 36  
37 37 typedef struct _print_info
38 38 {
39   - GdkColor color[V3270_COLOR_COUNT];
  39 + GdkColor color[V3270_COLOR_COUNT];
  40 + H3270 * session;
  41 + gchar * font;
  42 + int rows;
  43 + int cols;
  44 + int pages;
  45 + cairo_font_extents_t extents;
  46 + cairo_scaled_font_t * font_scaled;
40 47  
41 48 } PRINT_INFO;
42 49  
43 50 /*--[ Implement ]------------------------------------------------------------------------------------*/
44 51  
45   - static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info)
  52 + static void setup_font(cairo_t *cr, PRINT_INFO *info)
46 53 {
47   - trace("%s",__FUNCTION__);
48   - gtk_print_operation_cancel(prt);
  54 + cairo_select_font_face(cr, info->font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  55 +
  56 + info->font_scaled = cairo_get_scaled_font(cr);
  57 + cairo_scaled_font_reference(info->font_scaled);
  58 + cairo_scaled_font_extents(info->font_scaled,&info->extents);
  59 +
  60 + }
  61 +
  62 + static void begin_print_all(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info)
  63 + {
  64 + cairo_t *cr = gtk_print_context_get_cairo_context(context);
  65 +
  66 + lib3270_get_screen_size(info->session,&info->rows,&info->cols);
  67 + setup_font(cr,info);
  68 +
  69 + gtk_print_operation_set_n_pages(prt,1);
49 70 }
50 71  
51 72 static void draw_page(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info)
52 73 {
53   - trace("%s",__FUNCTION__);
  74 + cairo_t *cr = gtk_print_context_get_cairo_context(context);
  75 +
  76 + cairo_set_scaled_font(cr,info->font_scaled);
54 77  
  78 + cairo_move_to(cr,0,0);
  79 + cairo_show_text(cr, "Teste");
  80 +
  81 + cairo_stroke(cr);
55 82 }
56 83  
57 84 static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info)
58 85 {
59 86 trace("%s",__FUNCTION__);
60 87  
  88 + if(info->font_scaled)
  89 + cairo_scaled_font_destroy(info->font_scaled);
  90 +
  91 + if(info->font)
  92 + g_free(info->font);
61 93  
62 94 g_free(info);
63 95 }
... ... @@ -69,28 +101,41 @@
69 101 }
70 102 #endif // GTK(3,2,0)
71 103  
  104 + static void font_set(GtkFontButton *widget, PRINT_INFO *info)
  105 + {
  106 + if(info->font)
  107 + g_free(info->font);
  108 +
  109 + info->font = g_strdup(gtk_font_button_get_font_name(widget));
  110 + set_string_to_config("print","font","%s",info->font);
  111 + trace("Font set to \"%s\"",info->font);
  112 + }
  113 +
72 114 static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info)
73 115 {
74   - static const gchar * label[] = { "Font:", "Colors:" };
  116 + static const gchar * label[] = { N_( "Font:" ), N_( "Colors:" ) };
75 117 GtkWidget * container = gtk_table_new(2,2,FALSE);
76 118 GtkWidget * widget;
77 119 int f;
78 120  
79 121 for(f=0;f<G_N_ELEMENTS(label);f++)
80 122 {
81   - widget = gtk_label_new(label[f]);
  123 + widget = gtk_label_new(gettext(label[f]));
82 124 gtk_misc_set_alignment(GTK_MISC(widget),0,0.5);
83 125 gtk_table_attach(GTK_TABLE(container),widget,0,1,f,f+1,GTK_FILL,GTK_FILL,0,0);
84 126 }
85 127  
86 128 // Font selection button
87 129 widget = gtk_font_button_new();
88   - gtk_font_button_set_show_size(GTK_FONT_BUTTON(widget),FALSE);
89 130 #if GTK_CHECK_VERSION(3,2,0)
90 131 gtk_font_chooser_set_filter_func(widget,filter_monospaced,0);
91 132 #endif // GTK(3,2,0)
92 133 gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);
93 134  
  135 + info->font = get_string_from_config("print","font","Courier 10");
  136 + gtk_font_button_set_font_name((GtkFontButton *) widget,info->font);
  137 + g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info);
  138 +
94 139 // Color scheme dropdown
95 140  
96 141 // Show and return
... ... @@ -103,33 +148,39 @@
103 148 trace("%s",__FUNCTION__);
104 149 }
105 150  
106   - static GtkPrintOperation * begin_print_operation(GtkAction *action, GtkWidget *widget)
  151 + static GtkPrintOperation * begin_print_operation(GtkAction *action, GtkWidget *widget, PRINT_INFO **info)
107 152 {
108   - PRINT_INFO * info = g_new0(PRINT_INFO,1);
109 153 GtkPrintOperation * print = gtk_print_operation_new();
110 154 // GtkPrintSettings * settings = gtk_print_settings_new();
111 155 // GtkPageSetup * setup = gtk_page_setup_new();
112   -// gchar * ptr;
  156 + const gchar * attr;
  157 +
  158 + *info = g_new0(PRINT_INFO,1);
  159 + (*info)->session = v3270_get_session(widget);
113 160  
114 161 // Basic setup
115 162 gtk_print_operation_set_allow_async(print,TRUE);
116 163  
117   -/*
118   - ptr = g_strconcat(PACKAGE_NAME,".",gtk_action_get_name(action),NULL);
119   - gtk_print_operation_set_job_name(print,ptr);
120   - g_free(ptr);
121   -*/
  164 + attr = (const gchar *) g_object_get_data(G_OBJECT(action),"jobname");
  165 + if(attr)
  166 + {
  167 + gtk_print_operation_set_job_name(print,attr);
  168 + }
  169 + else
  170 + {
  171 + gchar *ptr = g_strconcat(PACKAGE_NAME,".",gtk_action_get_name(action),NULL);
  172 + gtk_print_operation_set_job_name(print,ptr);
  173 + g_free(ptr);
  174 + }
122 175  
123 176 gtk_print_operation_set_custom_tab_label(print,_( "Style" ));
124 177  
125 178 // gtk_print_operation_set_show_progress(print,TRUE);
126 179  
127 180 // Common signals
128   - g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info);
129   - g_signal_connect(print,"draw_page",G_CALLBACK(draw_page),info);
130   - g_signal_connect(print,"done",G_CALLBACK(done),info);
131   - g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), info);
132   - g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), info);
  181 + g_signal_connect(print,"done",G_CALLBACK(done),*info);
  182 + g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info);
  183 + g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info);
133 184  
134 185 // Finish settings
135 186 // gtk_print_operation_set_print_settings(print,settings);
... ... @@ -140,10 +191,14 @@
140 191  
141 192 void print_all_action(GtkAction *action, GtkWidget *widget)
142 193 {
143   - GtkPrintOperation *print = begin_print_operation(action,widget);
  194 + PRINT_INFO * info = NULL;
  195 + GtkPrintOperation * print = begin_print_operation(action,widget,&info);
144 196  
145 197 trace("Action %s activated on widget %p print=%p",gtk_action_get_name(action),widget,print);
146 198  
  199 + g_signal_connect(print,"begin_print",G_CALLBACK(begin_print_all),info);
  200 + g_signal_connect(print,"draw_page",G_CALLBACK(draw_page),info);
  201 +
147 202 // Run Print dialog
148 203 gtk_print_operation_run(print,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),NULL);
149 204  
... ...