Commit f18949342f65ef2110c9a51ef21bb02f080bd85c
1 parent
f17f14a5
Exists in
master
and in
1 other branch
Moving common dialogs do widget library.
Showing
12 changed files
with
735 additions
and
7 deletions
Show diff stats
Makefile.in
... | ... | @@ -126,6 +126,7 @@ $(OBJDBG)/%.o: \ |
126 | 126 | $(CFLAGS) \ |
127 | 127 | -Wall -Wextra -fstack-check \ |
128 | 128 | -DDEBUG=1 \ |
129 | + -DDATADIR=$(BASEDIR) \ | |
129 | 130 | -o $@ -c $< |
130 | 131 | |
131 | 132 | $(OBJDBG)/%.o: \ |
... | ... | @@ -146,6 +147,7 @@ $(OBJRLS)/%.o: \ |
146 | 147 | @$(CC) \ |
147 | 148 | $(CFLAGS) \ |
148 | 149 | -DNDEBUG=1 \ |
150 | + -DDATADIR=$(datarootdir)/pw3270 \ | |
149 | 151 | -o $@ -c $< |
150 | 152 | |
151 | 153 | $(OBJRLS)/%.o: \ | ... | ... |
... | ... | @@ -0,0 +1,81 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como - e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * | |
28 | + */ | |
29 | + | |
30 | + #include <config.h> | |
31 | + #define ENABLE_NLS | |
32 | + | |
33 | + #ifndef GETTEXT_PACKAGE | |
34 | + #define GETTEXT_PACKAGE PACKAGE_NAME | |
35 | + #endif | |
36 | + | |
37 | + #include <libintl.h> | |
38 | + #include <glib/gi18n.h> | |
39 | + | |
40 | + #include <v3270.h> | |
41 | + #include <v3270/colorscheme.h> | |
42 | + | |
43 | + #define V3270_COLOR_BASE V3270_COLOR_GRAY+1 | |
44 | + | |
45 | +/*--[ Widget definition ]----------------------------------------------------------------------------*/ | |
46 | + | |
47 | + struct _V3270ColorSchemeClass | |
48 | + { | |
49 | + GtkComboBoxClass parent_class; | |
50 | + | |
51 | + | |
52 | + }; | |
53 | + | |
54 | + struct _V3270ColorScheme | |
55 | + { | |
56 | + GtkComboBox parent; | |
57 | + | |
58 | + }; | |
59 | + | |
60 | + G_DEFINE_TYPE(V3270ColorScheme, V3270ColorScheme, GTK_TYPE_COMBO_BOX); | |
61 | + | |
62 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
63 | + | |
64 | + static void V3270ColorScheme_class_init(G_GNUC_UNUSED V3270ColorSchemeClass *klass) | |
65 | + { | |
66 | + | |
67 | + } | |
68 | + | |
69 | + static void V3270ColorScheme_init(V3270ColorScheme *widget) | |
70 | + { | |
71 | + | |
72 | + } | |
73 | + | |
74 | + LIB3270_EXPORT GtkWidget * v3270_color_scheme_new(GdkRGBA *colors) | |
75 | + { | |
76 | + GtkWidget *widget = GTK_WIDGET(g_object_new(GTK_TYPE_V3270_COLOR_SCHEME, NULL)); | |
77 | + | |
78 | + | |
79 | + return widget; | |
80 | + } | |
81 | + | ... | ... |
src/include/v3270.h
... | ... | @@ -260,6 +260,11 @@ |
260 | 260 | LIB3270_EXPORT GtkWidget * v3270_host_select_new(GtkWidget *widget); |
261 | 261 | LIB3270_EXPORT void v3270_select_host(GtkWidget *widget); |
262 | 262 | |
263 | ||
264 | + LIB3270_EXPORT void v3270_print(GtkWidget *widget, LIB3270_PRINT_MODE mode); | |
265 | + LIB3270_EXPORT void v3270_print_all(GtkWidget *widget); | |
266 | + LIB3270_EXPORT void v3270_print_selected(GtkWidget *widget); | |
267 | + LIB3270_EXPORT void v3270_print_copy(GtkWidget *widget); | |
263 | 268 | |
264 | 269 | G_END_DECLS |
265 | 270 | ... | ... |
... | ... | @@ -0,0 +1,54 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como hostdialog.h e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * | |
28 | + */ | |
29 | + | |
30 | +#ifndef V3270_COLOR_SCHEME_H_INCLUDED | |
31 | + | |
32 | + #include <gtk/gtk.h> | |
33 | + | |
34 | + G_BEGIN_DECLS | |
35 | + | |
36 | +/*--[ Progress widget ]------------------------------------------------------------------------------*/ | |
37 | + | |
38 | + #define GTK_TYPE_V3270_COLOR_SCHEME (V3270ColorScheme_get_type()) | |
39 | + #define GTK_V3270_COLOR_SCHEME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_COLOR_SCHEME, V3270ColorScheme)) | |
40 | + #define GTK_V3270_COLOR_SCHEME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_COLOR_SCHEME, V3270ColorSchemeClass)) | |
41 | + #define GTK_IS_V3270_COLOR_SCHEME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270_COLOR_SCHEME)) | |
42 | + #define GTK_IS_V3270_COLOR_SCHEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270_COLOR_SCHEME)) | |
43 | + #define GTK_V3270_COLOR_SCHEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270_COLOR_SCHEME, V3270ColorSchemeClass)) | |
44 | + | |
45 | + typedef struct _V3270ColorScheme V3270ColorScheme; | |
46 | + typedef struct _V3270ColorSchemeClass V3270ColorSchemeClass; | |
47 | + | |
48 | +/*--[ Prototipes ]-----------------------------------------------------------------------------------*/ | |
49 | + | |
50 | + LIB3270_EXPORT GtkWidget * v3270_color_scheme_new(GdkRGBA *colors); | |
51 | + | |
52 | + G_END_DECLS | |
53 | + | |
54 | +#endif // V3270_COLOR_SCHEME_H_INCLUDED | ... | ... |
src/testprogram/testprogram.c
... | ... | @@ -114,7 +114,6 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
114 | 114 | gtk_widget_show_all(trace); |
115 | 115 | } |
116 | 116 | |
117 | - | |
118 | 117 | /* |
119 | 118 | v3270_set_url(terminal,url); |
120 | 119 | v3270_connect(terminal); |
... | ... | @@ -164,6 +163,9 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
164 | 163 | |
165 | 164 | // v3270_set_script(terminal,'R'); |
166 | 165 | |
166 | + v3270_print_all(terminal); | |
167 | + | |
168 | + | |
167 | 169 | } |
168 | 170 | |
169 | 171 | int main (int argc, char **argv) { | ... | ... |
src/v3270/callbacks.c
... | ... | @@ -326,9 +326,10 @@ static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const |
326 | 326 | |
327 | 327 | } |
328 | 328 | |
329 | -static int emit_print_signal(H3270 *session) | |
329 | + | |
330 | +static int print(H3270 *session, LIB3270_PRINT_MODE mode) | |
330 | 331 | { |
331 | - g_signal_emit(GTK_WIDGET(lib3270_get_user_data(session)), v3270_widget_signal[SIGNAL_PRINT], 0); | |
332 | + v3270_print(GTK_WIDGET(lib3270_get_user_data(session)), mode); | |
332 | 333 | return 0; |
333 | 334 | } |
334 | 335 | |
... | ... | @@ -425,7 +426,7 @@ static void popup_handler(H3270 *session, LIB3270_NOTIFY type, const char *title |
425 | 426 | cbk->ctlr_done = ctlr_done; |
426 | 427 | cbk->message = message; |
427 | 428 | cbk->update_ssl = update_ssl; |
428 | - cbk->print = emit_print_signal; | |
429 | + cbk->print = print; | |
429 | 430 | |
430 | 431 | } |
431 | 432 | ... | ... |
src/v3270/keyboard.c
... | ... | @@ -81,14 +81,17 @@ |
81 | 81 | { GDK_KP_Add, GDK_NUMLOCK_MASK, NULL, NULL }, |
82 | 82 | { GDK_KP_Subtract, GDK_NUMLOCK_MASK, NULL, NULL }, |
83 | 83 | |
84 | - { GDK_3270_PrintScreen, 0, lib3270_print, NULL }, | |
84 | + { GDK_3270_PrintScreen, 0, lib3270_print_all, NULL }, | |
85 | + { GDK_P, GDK_CONTROL_MASK, lib3270_print_all, NULL }, | |
86 | + | |
85 | 87 | { GDK_Sys_Req, 0, lib3270_sysreq, NULL }, |
86 | 88 | |
87 | - { GDK_Print, GDK_CONTROL_MASK, lib3270_print, NULL }, | |
89 | + { GDK_Print, GDK_CONTROL_MASK, lib3270_print_all, NULL }, | |
88 | 90 | { GDK_Print, GDK_SHIFT_MASK, lib3270_sysreq, NULL }, |
89 | 91 | { GDK_Control_R, 0, NULL, NULL }, |
90 | 92 | { GDK_Control_L, 0, NULL, NULL }, |
91 | 93 | |
94 | + | |
92 | 95 | #ifdef WIN32 |
93 | 96 | { GDK_Pause, 0, NULL, NULL }, |
94 | 97 | #endif | ... | ... |
src/v3270/marshal
... | ... | @@ -0,0 +1,541 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como - e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * | |
28 | + */ | |
29 | + | |
30 | + #include "private.h" | |
31 | + #include <v3270.h> | |
32 | + #include <v3270/colorscheme.h> | |
33 | + #include <lib3270/selection.h> | |
34 | + #include <lib3270/log.h> | |
35 | + #include <lib3270/trace.h> | |
36 | + | |
37 | + #define AUTO_FONT_SIZE 1 | |
38 | + | |
39 | +#ifdef AUTO_FONT_SIZE | |
40 | + #define FONT_CONFIG "font-family" | |
41 | + #define DEFAULT_FONT "Courier New" | |
42 | +#else | |
43 | + #define FONT_CONFIG "font" | |
44 | + #define DEFAULT_FONT "Courier New 10" | |
45 | +#endif // AUTO_FONT_SIZE | |
46 | + | |
47 | +/*--[ Structs ]--------------------------------------------------------------------------------------*/ | |
48 | + | |
49 | + typedef struct _print_info | |
50 | + { | |
51 | + GdkRGBA color[V3270_COLOR_COUNT]; | |
52 | + int show_selection : 1; | |
53 | + LIB3270_PRINT_MODE src; | |
54 | + | |
55 | + v3270 * widget; | |
56 | + | |
57 | + int baddr; | |
58 | + int rows; | |
59 | + int cols; ///< @brief Max line width. | |
60 | + int pages; | |
61 | + int lpp; ///< @brief Lines per page. | |
62 | + | |
63 | + v3270FontInfo font; | |
64 | + | |
65 | + double left; | |
66 | + double width; ///< @brief Report width. | |
67 | + double height; ///< @brief Report height (all pages). | |
68 | + | |
69 | + gchar **text; | |
70 | + | |
71 | + } PRINT_INFO; | |
72 | + | |
73 | + | |
74 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
75 | + | |
76 | + static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) | |
77 | + { | |
78 | + cairo_font_extents_t extents; | |
79 | + cairo_t * cr = gtk_print_context_get_cairo_context(context); | |
80 | + | |
81 | + // Setup font | |
82 | + if(info->font.family) | |
83 | + { | |
84 | + PangoFontDescription * descr = pango_font_description_from_string(info->font.family); | |
85 | + if(descr) | |
86 | + { | |
87 | + cairo_select_font_face(cr, pango_font_description_get_family(descr), | |
88 | + CAIRO_FONT_SLANT_NORMAL, | |
89 | + pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL); | |
90 | + | |
91 | +#ifdef AUTO_FONT_SIZE | |
92 | + { | |
93 | + double width = gtk_print_context_get_width(context); | |
94 | +#if GTK_CHECK_VERSION(3,0,0) | |
95 | + double cols = (double) info->cols; | |
96 | +#else | |
97 | + double cols = (double) (info->cols+5); | |
98 | +#endif // GTK(3,0,0) | |
99 | + double current = width / cols; | |
100 | + double valid = current; | |
101 | + | |
102 | + do | |
103 | + { | |
104 | + valid = current; | |
105 | + current = valid +1.0; | |
106 | + cairo_set_font_size(cr,current); | |
107 | + cairo_font_extents(cr,&extents); | |
108 | + } | |
109 | + while( (cols * extents.max_x_advance) < width ); | |
110 | + | |
111 | + cairo_set_font_size(cr,valid); | |
112 | + | |
113 | + } | |
114 | +#endif // AUTO_FONT_SIZE | |
115 | + | |
116 | + pango_font_description_free(descr); | |
117 | + } | |
118 | + } | |
119 | + | |
120 | + info->font.scaled = cairo_get_scaled_font(cr); | |
121 | + cairo_scaled_font_reference(info->font.scaled); | |
122 | + cairo_scaled_font_extents(info->font.scaled,&extents); | |
123 | + | |
124 | + info->font.height = extents.height; | |
125 | + info->font.descent = extents.descent; | |
126 | + info->font.width = extents.max_x_advance; | |
127 | + | |
128 | + info->width = ((double) info->cols) * extents.max_x_advance; | |
129 | + info->height = ((double) info->rows) * (extents.height + extents.descent); | |
130 | + | |
131 | + // Center image | |
132 | + info->left = (gtk_print_context_get_width(context)-info->width)/2; | |
133 | + if(info->left < 2) | |
134 | + info->left = 2; | |
135 | + | |
136 | + // Setup page size | |
137 | + info->lpp = (gtk_print_context_get_height(context) / (extents.height + extents.descent)); | |
138 | + info->pages = (info->rows / info->lpp)+1; | |
139 | + | |
140 | + gtk_print_operation_set_n_pages(prt,info->pages); | |
141 | + } | |
142 | + | |
143 | + static void draw_screen(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) | |
144 | + { | |
145 | + int row; | |
146 | + int col; | |
147 | + cairo_t * cr = gtk_print_context_get_cairo_context(context); | |
148 | + int baddr = info->baddr; | |
149 | + GdkRectangle rect; | |
150 | + | |
151 | + cairo_set_scaled_font(cr,info->font.scaled); | |
152 | + | |
153 | + memset(&rect,0,sizeof(rect)); | |
154 | + rect.y = 2; | |
155 | + rect.height = (info->font.height + info->font.descent); | |
156 | + rect.width = info->font.width; | |
157 | + | |
158 | + // Clear page | |
159 | + gdk_cairo_set_source_rgba(cr,info->color+V3270_COLOR_BACKGROUND); | |
160 | + cairo_rectangle(cr, info->left-2, 0, (rect.width*info->cols)+4, (rect.height*info->rows)+4); | |
161 | + cairo_fill(cr); | |
162 | + cairo_stroke(cr); | |
163 | + | |
164 | + rect.width++; | |
165 | + rect.height++; | |
166 | + | |
167 | + for(row = 0; row < info->rows; row++) | |
168 | + { | |
169 | + rect.x = info->left; | |
170 | + for(col = 0; col < info->cols; col++) | |
171 | + { | |
172 | + unsigned char c; | |
173 | + unsigned short attr; | |
174 | + | |
175 | + if(!lib3270_get_element(info->widget->host,baddr++,&c,&attr) && (info->src == LIB3270_PRINT_ALL || (attr & LIB3270_ATTR_SELECTED))) | |
176 | + { | |
177 | + if(!info->show_selection) | |
178 | + attr &= ~LIB3270_ATTR_SELECTED; | |
179 | + v3270_draw_element(cr,c,attr,info->widget->host,&info->font,&rect,info->color); | |
180 | + } | |
181 | + | |
182 | + rect.x += (rect.width-1); | |
183 | + } | |
184 | + rect.y += (rect.height-1); | |
185 | + | |
186 | + } | |
187 | + } | |
188 | + | |
189 | + /* | |
190 | + static void show_print_error(GtkWidget *widget, GError *err) | |
191 | + { | |
192 | + GtkWidget *dialog = gtk_message_dialog_new_with_markup( GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
193 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
194 | + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, | |
195 | + "%s",_( "Print operation failed" )); | |
196 | + | |
197 | + g_warning("%s",err->message); | |
198 | + | |
199 | + gtk_window_set_title(GTK_WINDOW(dialog),_("Error")); | |
200 | + | |
201 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",err->message); | |
202 | + | |
203 | + gtk_dialog_run(GTK_DIALOG(dialog)); | |
204 | + gtk_widget_destroy(dialog); | |
205 | +} | |
206 | +*/ | |
207 | + | |
208 | + static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info) | |
209 | + { | |
210 | + debug("%s(%p)",__FUNCTION__,info->widget); | |
211 | + g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_DONE], 0, prt, (guint) result); | |
212 | + | |
213 | + | |
214 | + debug("%s",__FUNCTION__); | |
215 | + if(info->font.scaled) | |
216 | + cairo_scaled_font_destroy(info->font.scaled); | |
217 | + | |
218 | + debug("%s",__FUNCTION__); | |
219 | + if(info->text) | |
220 | + g_strfreev(info->text); | |
221 | + | |
222 | + debug("%s",__FUNCTION__); | |
223 | + if(info->font.family) | |
224 | + g_free(info->font.family); | |
225 | + | |
226 | + debug("%s",__FUNCTION__); | |
227 | + g_free(info); | |
228 | + debug("%s",__FUNCTION__); | |
229 | + } | |
230 | + | |
231 | +#ifndef AUTO_FONT_SIZE | |
232 | + | |
233 | +#if GTK_CHECK_VERSION(3,2,0) | |
234 | + static gboolean filter_monospaced(const PangoFontFamily *family,const PangoFontFace *face,gpointer data) | |
235 | + { | |
236 | + return pango_font_family_is_monospace((PangoFontFamily *) family); | |
237 | + } | |
238 | +#endif // GTK(3,2,0) | |
239 | + | |
240 | + static void font_set(GtkFontButton *widget, PRINT_INFO *info) | |
241 | + { | |
242 | + if(info->font) | |
243 | + g_free(info->font); | |
244 | + info->font = g_strdup(gtk_font_button_get_font_name(widget)); | |
245 | + } | |
246 | + | |
247 | +#else | |
248 | + | |
249 | + static void font_name_changed(GtkComboBox *combo, PRINT_INFO *info) | |
250 | + { | |
251 | + GValue value = { 0, }; | |
252 | + GtkTreeIter iter; | |
253 | + | |
254 | + if(!gtk_combo_box_get_active_iter(combo,&iter)) | |
255 | + return; | |
256 | + | |
257 | + gtk_tree_model_get_value(gtk_combo_box_get_model(combo),&iter,0,&value); | |
258 | + | |
259 | + if(info->font.family) | |
260 | + g_free(info->font.family); | |
261 | + | |
262 | + info->font.family = g_value_dup_string(&value); | |
263 | + | |
264 | + } | |
265 | + | |
266 | +#endif // !AUTO_FONT_SIZE | |
267 | + | |
268 | + static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info) | |
269 | + { | |
270 | + gboolean active = gtk_toggle_button_get_active(togglebutton); | |
271 | + info->show_selection = active ? 1 : 0; | |
272 | + } | |
273 | + | |
274 | + static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) | |
275 | + { | |
276 | + GtkWidget * container = gtk_table_new(3,2,FALSE); | |
277 | + static const gchar * text[] = { N_( "_Font:" ), N_( "C_olor scheme:" ) }; | |
278 | + GtkWidget * label[G_N_ELEMENTS(text)]; | |
279 | + GtkWidget * widget; | |
280 | + size_t f; | |
281 | + | |
282 | + for(f=0;f<G_N_ELEMENTS(label);f++) | |
283 | + { | |
284 | + label[f] = gtk_label_new_with_mnemonic(gettext(text[f])); | |
285 | + gtk_misc_set_alignment(GTK_MISC(label[f]),0,0.5); | |
286 | + gtk_table_attach(GTK_TABLE(container),label[f],0,1,f,f+1,GTK_FILL,GTK_FILL,0,0); | |
287 | + } | |
288 | + | |
289 | + // Font selection button | |
290 | +#ifdef AUTO_FONT_SIZE | |
291 | + { | |
292 | + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(1,G_TYPE_STRING); | |
293 | + GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); | |
294 | + PangoFontFamily **families; | |
295 | + gint n_families, i; | |
296 | + GtkTreeIter iter; | |
297 | + | |
298 | + widget = gtk_combo_box_new_with_model(model); | |
299 | + | |
300 | + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE); | |
301 | + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); | |
302 | + | |
303 | + g_signal_connect(G_OBJECT(widget),"changed",G_CALLBACK(font_name_changed),info); | |
304 | + | |
305 | + pango_context_list_families(gtk_widget_get_pango_context(container),&families, &n_families); | |
306 | + | |
307 | + for(i=0; i<n_families; i++) | |
308 | + { | |
309 | + if(pango_font_family_is_monospace(families[i])) | |
310 | + { | |
311 | + const gchar *name = pango_font_family_get_name (families[i]); | |
312 | + gtk_list_store_append((GtkListStore *) model,&iter); | |
313 | + gtk_list_store_set((GtkListStore *) model, &iter,0, name, -1); | |
314 | + | |
315 | + if(!g_ascii_strcasecmp(name,info->font.family)) | |
316 | + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); | |
317 | + } | |
318 | + } | |
319 | + | |
320 | + g_free(families); | |
321 | + } | |
322 | +#else | |
323 | + { | |
324 | + widget = gtk_font_button_new_with_font(info->font); | |
325 | + gtk_font_button_set_show_size((GtkFontButton *) widget,TRUE); | |
326 | + gtk_font_button_set_use_font((GtkFontButton *) widget,TRUE); | |
327 | + gtk_label_set_mnemonic_widget(GTK_LABEL(label[0]),widget); | |
328 | + g_free(info->font); | |
329 | + | |
330 | +#if GTK_CHECK_VERSION(3,2,0) | |
331 | + gtk_font_chooser_set_filter_func((GtkFontChooser *) widget,filter_monospaced,NULL,NULL); | |
332 | +#endif // GTK(3,2,0) | |
333 | + | |
334 | + g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info); | |
335 | + | |
336 | + } | |
337 | +#endif | |
338 | + | |
339 | + gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); | |
340 | + | |
341 | + g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_BEGIN], 0, prt); | |
342 | + | |
343 | + | |
344 | + widget = v3270_color_scheme_new(info->color); | |
345 | + gtk_label_set_mnemonic_widget(GTK_LABEL(label[1]),widget); | |
346 | + | |
347 | + g_object_set_data(G_OBJECT(container),"combo",widget); | |
348 | + gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); | |
349 | + | |
350 | + // Selection checkbox | |
351 | + widget = gtk_check_button_new_with_label( _("Print selection box") ); | |
352 | + | |
353 | + if(info->src == LIB3270_PRINT_ALL) | |
354 | + { | |
355 | + info->show_selection = FALSE; | |
356 | + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),info->show_selection); | |
357 | + g_signal_connect(G_OBJECT(widget),"toggled",G_CALLBACK(toggle_show_selection),info); | |
358 | + } | |
359 | + else | |
360 | + { | |
361 | + gtk_widget_set_sensitive(widget,FALSE); | |
362 | + } | |
363 | + | |
364 | + gtk_table_attach(GTK_TABLE(container),widget,1,2,2,3,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); | |
365 | + | |
366 | + // Show and return | |
367 | + gtk_widget_show_all(container); | |
368 | + | |
369 | + return G_OBJECT(container); | |
370 | + } | |
371 | + | |
372 | + static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget, PRINT_INFO *info) | |
373 | + { | |
374 | + g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_APPLY], 0, prt); | |
375 | + | |
376 | + /* | |
377 | + GtkWidget * combo = g_object_get_data(G_OBJECT(widget),"combo"); | |
378 | + GdkRGBA * clr = g_object_get_data(G_OBJECT(combo),"selected"); | |
379 | + | |
380 | + trace("%s starts combo=%p clr=%p widget=%p",__FUNCTION__,combo,clr,widget); | |
381 | + | |
382 | + if(info->font.family) | |
383 | + set_string_to_config("print",FONT_CONFIG,info->font.family); | |
384 | + | |
385 | + if(clr) | |
386 | + { | |
387 | + int f; | |
388 | + GString *str = g_string_new(""); | |
389 | + for(f=0;f<V3270_COLOR_COUNT;f++) | |
390 | + { | |
391 | + info->color[f] = clr[f]; | |
392 | + if(f) | |
393 | + g_string_append_c(str,';'); | |
394 | + g_string_append_printf(str,"%s",gdk_rgba_to_string(clr+f)); | |
395 | + } | |
396 | + set_string_to_config("print","colors","%s",str->str); | |
397 | + g_string_free(str,TRUE); | |
398 | + } | |
399 | + | |
400 | + trace("%s ends",__FUNCTION__); | |
401 | + */ | |
402 | + | |
403 | + } | |
404 | + | |
405 | + static GtkPrintOperation * begin_print_operation(GtkWidget *widget, PRINT_INFO **info) | |
406 | + { | |
407 | + GtkPrintOperation * print = gtk_print_operation_new(); | |
408 | + GtkPrintSettings * settings = gtk_print_settings_new(); | |
409 | + GtkPageSetup * setup = gtk_page_setup_new(); | |
410 | + // GtkPaperSize * papersize = NULL; | |
411 | + | |
412 | + *info = g_new0(PRINT_INFO,1); | |
413 | + (*info)->cols = 80; | |
414 | + (*info)->widget = widget; | |
415 | + (*info)->font.family = g_strdup(DEFAULT_FONT); | |
416 | + | |
417 | + debug("%s",__FUNCTION__); | |
418 | + gtk_print_operation_set_custom_tab_label(print, _( "Options" ) ); | |
419 | + gtk_print_operation_set_show_progress(print,TRUE); | |
420 | + | |
421 | + // Common signals | |
422 | + g_signal_connect(print,"done",G_CALLBACK(done),*info); | |
423 | + | |
424 | +#if GTK_CHECK_VERSION(3,0,0) && !defined(WIN32) | |
425 | + g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info); | |
426 | + g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info); | |
427 | +#endif // !WIN32 | |
428 | + | |
429 | + // Finish settings | |
430 | + gtk_print_operation_set_print_settings(print,settings); | |
431 | + //gtk_page_setup_set_paper_size_and_default_margins(setup,papersize); | |
432 | + gtk_print_operation_set_default_page_setup(print,setup); | |
433 | + | |
434 | + return print; | |
435 | + } | |
436 | + | |
437 | + static void draw_text(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) | |
438 | + { | |
439 | + cairo_t * cr = gtk_print_context_get_cairo_context(context); | |
440 | + GdkRectangle rect; | |
441 | + int row = pg*info->lpp; | |
442 | + int l; | |
443 | + | |
444 | + cairo_set_scaled_font(cr,info->font.scaled); | |
445 | + | |
446 | + memset(&rect,0,sizeof(rect)); | |
447 | + rect.y = 2; | |
448 | + rect.height = (info->font.height + info->font.descent)+1; | |
449 | + rect.width = info->font.width+1; | |
450 | + | |
451 | + for(l=0;l<info->lpp && row < info->rows;l++) | |
452 | + { | |
453 | + cairo_move_to(cr,2,rect.y+rect.height); | |
454 | + cairo_show_text(cr, info->text[row]); | |
455 | + cairo_stroke(cr); | |
456 | + row++; | |
457 | + rect.y += (rect.height-1); | |
458 | + } | |
459 | + | |
460 | + } | |
461 | + | |
462 | + static void print_operation(GtkWidget *widget, GtkPrintOperationAction oper, LIB3270_PRINT_MODE mode) | |
463 | + { | |
464 | + PRINT_INFO * info = NULL; | |
465 | + GtkPrintOperation * print; | |
466 | + gchar * text; | |
467 | + GError * err = NULL; | |
468 | + | |
469 | + g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); | |
470 | + | |
471 | + print = begin_print_operation(widget,&info); | |
472 | + if(!print) | |
473 | + return; | |
474 | + | |
475 | + lib3270_get_screen_size(info->widget->host,&info->rows,&info->cols); | |
476 | + | |
477 | + info->src = mode; | |
478 | + | |
479 | + g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info); | |
480 | + | |
481 | + switch(mode) | |
482 | + { | |
483 | + case LIB3270_PRINT_ALL: | |
484 | + case LIB3270_PRINT_SELECTED: | |
485 | + g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info); | |
486 | + break; | |
487 | + | |
488 | + case LIB3270_PRINT_COPY: | |
489 | + | |
490 | + text = v3270_get_copy(widget); | |
491 | + | |
492 | + if(text) | |
493 | + { | |
494 | + int r; | |
495 | + | |
496 | + info->text = g_strsplit(text,"\n",-1); | |
497 | + info->rows = g_strv_length(info->text); | |
498 | + | |
499 | + for(r=0;r < info->rows;r++) | |
500 | + { | |
501 | + size_t sz = strlen(info->text[r]); | |
502 | + if(sz > info->cols) | |
503 | + info->cols = sz; | |
504 | + } | |
505 | + g_free(text); | |
506 | + } | |
507 | + g_signal_connect(print,"draw_page",G_CALLBACK(draw_text),info); | |
508 | + break; | |
509 | + | |
510 | + | |
511 | + } | |
512 | + | |
513 | + // Run Print dialog | |
514 | + gtk_print_operation_run(print,oper,GTK_WINDOW(gtk_widget_get_toplevel(widget)),&err); | |
515 | + | |
516 | + if(err) | |
517 | + g_error_free(err); | |
518 | + | |
519 | + g_object_unref(print); | |
520 | + | |
521 | + } | |
522 | + | |
523 | + void v3270_print(GtkWidget *widget, LIB3270_PRINT_MODE mode) | |
524 | + { | |
525 | + print_operation(widget,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, mode); | |
526 | + } | |
527 | + | |
528 | + void v3270_print_all(GtkWidget *widget) | |
529 | + { | |
530 | + v3270_print(widget,LIB3270_PRINT_ALL); | |
531 | + } | |
532 | + | |
533 | + void v3270_print_selected(GtkWidget *widget) | |
534 | + { | |
535 | + v3270_print(widget,LIB3270_PRINT_SELECTED); | |
536 | + } | |
537 | + | |
538 | + void v3270_print_copy(GtkWidget *widget) | |
539 | + { | |
540 | + v3270_print(widget,LIB3270_PRINT_COPY); | |
541 | + } | ... | ... |
src/v3270/private.h
src/v3270/widget.c
... | ... | @@ -495,6 +495,7 @@ static void v3270_class_init(v3270Class *klass) |
495 | 495 | G_TYPE_BOOLEAN, 3, G_TYPE_BOOLEAN, G_TYPE_UINT, G_TYPE_POINTER); |
496 | 496 | |
497 | 497 | |
498 | + /* | |
498 | 499 | v3270_widget_signal[SIGNAL_PRINT] = |
499 | 500 | g_signal_new( "print", |
500 | 501 | G_OBJECT_CLASS_TYPE (gobject_class), |
... | ... | @@ -503,6 +504,34 @@ static void v3270_class_init(v3270Class *klass) |
503 | 504 | NULL, NULL, |
504 | 505 | v3270_VOID__VOID, |
505 | 506 | G_TYPE_NONE, 0); |
507 | + */ | |
508 | + | |
509 | + v3270_widget_signal[SIGNAL_PRINT_BEGIN] = | |
510 | + g_signal_new( "print-begin", | |
511 | + G_OBJECT_CLASS_TYPE (gobject_class), | |
512 | + G_SIGNAL_RUN_FIRST, | |
513 | + 0, | |
514 | + NULL, NULL, | |
515 | + v3270_VOID__VOID_POINTER, | |
516 | + G_TYPE_NONE, 1, G_TYPE_POINTER, 0); | |
517 | + | |
518 | + v3270_widget_signal[SIGNAL_PRINT_APPLY] = | |
519 | + g_signal_new( "print-apply", | |
520 | + G_OBJECT_CLASS_TYPE (gobject_class), | |
521 | + G_SIGNAL_RUN_FIRST, | |
522 | + 0, | |
523 | + NULL, NULL, | |
524 | + v3270_VOID__VOID_POINTER, | |
525 | + G_TYPE_NONE, 1, G_TYPE_POINTER, 0); | |
526 | + | |
527 | + v3270_widget_signal[SIGNAL_PRINT_DONE] = | |
528 | + g_signal_new( "print-done", | |
529 | + G_OBJECT_CLASS_TYPE (gobject_class), | |
530 | + G_SIGNAL_RUN_FIRST, | |
531 | + 0, | |
532 | + NULL, NULL, | |
533 | + v3270_VOID__VOID_POINTER_UINT, | |
534 | + G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_UINT, 0); | |
506 | 535 | |
507 | 536 | v3270_init_properties(gobject_class); |
508 | 537 | ... | ... |
v3270.cbp
... | ... | @@ -42,6 +42,9 @@ |
42 | 42 | <Add option="`pkg-config --libs gtk+-3.0 lib3270`" /> |
43 | 43 | <Add option="-fPIC" /> |
44 | 44 | </Linker> |
45 | + <Unit filename="src/dialogs/colorscheme.c"> | |
46 | + <Option compilerVar="CC" /> | |
47 | + </Unit> | |
45 | 48 | <Unit filename="src/dialogs/hostselect.c"> |
46 | 49 | <Option compilerVar="CC" /> |
47 | 50 | </Unit> |
... | ... | @@ -50,6 +53,7 @@ |
50 | 53 | <Unit filename="src/include/config.h.in" /> |
51 | 54 | <Unit filename="src/include/hostselect.h" /> |
52 | 55 | <Unit filename="src/include/v3270.h" /> |
56 | + <Unit filename="src/include/v3270/colorscheme.h" /> | |
53 | 57 | <Unit filename="src/include/v3270/filetransfer.h" /> |
54 | 58 | <Unit filename="src/include/v3270/ftprogress.h" /> |
55 | 59 | <Unit filename="src/include/v3270/trace.h" /> |
... | ... | @@ -98,6 +102,9 @@ |
98 | 102 | <Unit filename="src/v3270/oia.c"> |
99 | 103 | <Option compilerVar="CC" /> |
100 | 104 | </Unit> |
105 | + <Unit filename="src/v3270/print.c"> | |
106 | + <Option compilerVar="CC" /> | |
107 | + </Unit> | |
101 | 108 | <Unit filename="src/v3270/private.h" /> |
102 | 109 | <Unit filename="src/v3270/properties.c"> |
103 | 110 | <Option compilerVar="CC" /> | ... | ... |