Commit f5ce9dbdadc76548be26bada7d536c37265af2b9
1 parent
1053cc41
Exists in
master
and in
1 other branch
Refactoring widget properties.
Showing
13 changed files
with
2002 additions
and
1981 deletions
Show diff stats
Makefile.in
@@ -36,6 +36,7 @@ SOURCES= \ | @@ -36,6 +36,7 @@ SOURCES= \ | ||
36 | $(wildcard src/terminal/@OSNAME@/*.rc) \ | 36 | $(wildcard src/terminal/@OSNAME@/*.rc) \ |
37 | $(wildcard src/terminal/@OSNAME@/*.c) \ | 37 | $(wildcard src/terminal/@OSNAME@/*.c) \ |
38 | $(wildcard src/terminal/properties/*.c) \ | 38 | $(wildcard src/terminal/properties/*.c) \ |
39 | + $(wildcard src/terminal/drawing/*.c) \ | ||
39 | $(wildcard src/terminal/font/*.c) \ | 40 | $(wildcard src/terminal/font/*.c) \ |
40 | $(wildcard src/filetransfer/*.c) \ | 41 | $(wildcard src/filetransfer/*.c) \ |
41 | $(wildcard src/selection/*.c) \ | 42 | $(wildcard src/selection/*.c) \ |
src/include/terminal.h
@@ -187,6 +187,8 @@ G_BEGIN_DECLS | @@ -187,6 +187,8 @@ G_BEGIN_DECLS | ||
187 | 187 | ||
188 | }; | 188 | }; |
189 | 189 | ||
190 | + G_GNUC_INTERNAL void v3270_activate(GtkWidget *widget); | ||
191 | + | ||
190 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ | 192 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
191 | 193 | ||
192 | G_END_DECLS | 194 | G_END_DECLS |
@@ -0,0 +1,69 @@ | @@ -0,0 +1,69 @@ | ||
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 | + #include <terminal.h> | ||
32 | + #include <lib3270/actions.h> | ||
33 | + | ||
34 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
35 | + | ||
36 | +LIB3270_EXPORT void v3270_disconnect(GtkWidget *widget) | ||
37 | +{ | ||
38 | + g_return_if_fail(GTK_IS_V3270(widget)); | ||
39 | + v3270_disable_updates(widget); | ||
40 | + debug("%s",__FUNCTION__); | ||
41 | + lib3270_unselect(GTK_V3270(widget)->host); | ||
42 | + debug("%s",__FUNCTION__); | ||
43 | + lib3270_disconnect(GTK_V3270(widget)->host); | ||
44 | + debug("%s",__FUNCTION__); | ||
45 | + v3270_enable_updates(widget); | ||
46 | + debug("%s",__FUNCTION__); | ||
47 | +} | ||
48 | + | ||
49 | +LIB3270_EXPORT int v3270_reconnect(GtkWidget *widget) | ||
50 | +{ | ||
51 | + g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); | ||
52 | + | ||
53 | + return lib3270_reconnect(GTK_V3270(widget)->host,0); | ||
54 | +} | ||
55 | + | ||
56 | +void v3270_activate(GtkWidget *widget) | ||
57 | +{ | ||
58 | + v3270 * terminal = GTK_V3270(widget); | ||
59 | + | ||
60 | + terminal->activity.timestamp = time(0); | ||
61 | + | ||
62 | + if(lib3270_is_connected(terminal->host)) | ||
63 | + lib3270_enter(terminal->host); | ||
64 | + else if(lib3270_get_url(terminal->host)) | ||
65 | + v3270_reconnect(widget); | ||
66 | + else | ||
67 | + g_warning("Terminal widget %p activated without connection or valid url",terminal); | ||
68 | +} | ||
69 | + |
src/terminal/draw.c
@@ -1,537 +0,0 @@ | @@ -1,537 +0,0 @@ | ||
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 draw.c 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 | -#ifdef WIN32 | ||
31 | - #include <winsock2.h> | ||
32 | - #include <windows.h> | ||
33 | - #include <ws2tcpip.h> | ||
34 | -#endif // WIN32 | ||
35 | - | ||
36 | - #include <gtk/gtk.h> | ||
37 | - #include <math.h> | ||
38 | - #include <ctype.h> | ||
39 | - #include <lib3270.h> | ||
40 | - #include <lib3270/log.h> | ||
41 | - #include <lib3270/session.h> | ||
42 | - #include <lib3270/toggle.h> | ||
43 | - #include <internals.h> | ||
44 | - | ||
45 | - #include <v3270.h> | ||
46 | - #include <terminal.h> | ||
47 | - | ||
48 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
49 | - | ||
50 | -gboolean v3270_draw(GtkWidget * widget, cairo_t * cr) | ||
51 | -{ | ||
52 | - v3270 * terminal = GTK_V3270(widget); | ||
53 | - | ||
54 | - cairo_set_source_surface(cr,terminal->surface,0,0); | ||
55 | - cairo_paint(cr); | ||
56 | - | ||
57 | - if(lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_CROSSHAIR) && (terminal->cursor.show&2)) | ||
58 | - { | ||
59 | - GtkAllocation allocation; | ||
60 | - gtk_widget_get_allocation(widget, &allocation); | ||
61 | - | ||
62 | - gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_CROSS_HAIR); | ||
63 | - | ||
64 | - cairo_rectangle(cr, 0,terminal->cursor.rect.y+terminal->font.height,allocation.width,1); | ||
65 | - cairo_fill(cr); | ||
66 | - | ||
67 | - cairo_rectangle(cr, terminal->cursor.rect.x,0,1,terminal->oia.rect->y-3); | ||
68 | - cairo_fill(cr); | ||
69 | - } | ||
70 | - | ||
71 | - if(terminal->cursor.show == 3) | ||
72 | - { | ||
73 | - cairo_set_source_surface(cr,terminal->cursor.surface,terminal->cursor.rect.x,terminal->cursor.rect.y); | ||
74 | - | ||
75 | - if(lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_INSERT)) | ||
76 | - { | ||
77 | - cairo_rectangle(cr, terminal->cursor.rect.x, | ||
78 | - terminal->cursor.rect.y, | ||
79 | - terminal->cursor.rect.width, | ||
80 | - terminal->cursor.rect.height ); | ||
81 | - } | ||
82 | - else | ||
83 | - { | ||
84 | - cairo_rectangle(cr, terminal->cursor.rect.x, | ||
85 | - terminal->cursor.rect.y+terminal->font.height, | ||
86 | - terminal->cursor.rect.width, | ||
87 | - terminal->font.descent ); | ||
88 | - } | ||
89 | - | ||
90 | - cairo_fill(cr); | ||
91 | - } | ||
92 | - | ||
93 | - return FALSE; | ||
94 | -} | ||
95 | - | ||
96 | -#if( !GTK_CHECK_VERSION(3,0,0)) | ||
97 | -gboolean v3270_expose(GtkWidget *widget, GdkEventExpose *event) | ||
98 | -{ | ||
99 | - cairo_t *cr = gdk_cairo_create(widget->window); | ||
100 | - v3270_draw(widget,cr); | ||
101 | - cairo_destroy(cr); | ||
102 | - return FALSE; | ||
103 | -} | ||
104 | -#endif // GTk3 | ||
105 | - | ||
106 | - | ||
107 | -static void get_element_colors(unsigned short attr, GdkRGBA **fg, GdkRGBA **bg, GdkRGBA *color) | ||
108 | -{ | ||
109 | - if(attr & LIB3270_ATTR_SELECTED) | ||
110 | - { | ||
111 | - *fg = color+V3270_COLOR_SELECTED_FG; | ||
112 | - *bg = color+V3270_COLOR_SELECTED_BG; | ||
113 | - } | ||
114 | - else | ||
115 | - { | ||
116 | - *bg = color+((attr & 0x00F0) >> 4); | ||
117 | - | ||
118 | - if(attr & LIB3270_ATTR_FIELD) | ||
119 | - *fg = color+(attr & 0x0003)+V3270_COLOR_FIELD; | ||
120 | - else | ||
121 | - *fg = color+(attr & 0x000F); | ||
122 | - } | ||
123 | -} | ||
124 | - | ||
125 | -void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *fontInfo, GdkRectangle *rect, GdkRGBA *color) | ||
126 | -{ | ||
127 | - GdkRGBA *fg; | ||
128 | - GdkRGBA *bg; | ||
129 | - | ||
130 | - get_element_colors(attr,&fg,&bg,color); | ||
131 | - v3270_draw_char(cr,chr,attr,session,fontInfo,rect,fg,bg); | ||
132 | - | ||
133 | - if(attr & LIB3270_ATTR_UNDERLINE) | ||
134 | - { | ||
135 | - cairo_scaled_font_t * font = cairo_get_scaled_font(cr); | ||
136 | - cairo_font_extents_t extents; | ||
137 | - double sl; | ||
138 | - | ||
139 | - cairo_scaled_font_extents(font,&extents); | ||
140 | - | ||
141 | - sl = extents.descent/3; | ||
142 | - if(sl < 1) | ||
143 | - sl = 1; | ||
144 | - | ||
145 | - gdk_cairo_set_source_rgba(cr,fg); | ||
146 | - | ||
147 | - cairo_rectangle(cr,rect->x,rect->y+sl+extents.ascent+(extents.descent/2),rect->width,sl); | ||
148 | - cairo_fill(cr); | ||
149 | - | ||
150 | - cairo_stroke(cr); | ||
151 | - } | ||
152 | - | ||
153 | -} | ||
154 | - | ||
155 | -void v3270_draw_text_at(cairo_t *cr, int x, int y, v3270FontInfo *font, const char *str) { | ||
156 | - | ||
157 | - size_t szText = strlen(str); | ||
158 | - | ||
159 | - if(szText == 1 && isspace(*str)) { | ||
160 | - return; | ||
161 | - } | ||
162 | - | ||
163 | - // Tem string, desenha | ||
164 | - cairo_status_t status; | ||
165 | - cairo_glyph_t * glyphs = NULL; | ||
166 | - int num_glyphs = 0; | ||
167 | - cairo_text_cluster_t * clusters = NULL; | ||
168 | - int num_clusters = 0; | ||
169 | - cairo_text_cluster_flags_t cluster_flags; | ||
170 | - cairo_scaled_font_t * scaled_font = cairo_get_scaled_font(cr); | ||
171 | - | ||
172 | - status = cairo_scaled_font_text_to_glyphs( | ||
173 | - scaled_font, | ||
174 | - (double) x, (double) (y+font->height), | ||
175 | - str, szText, | ||
176 | - &glyphs, &num_glyphs, | ||
177 | - &clusters, &num_clusters, &cluster_flags ); | ||
178 | - | ||
179 | - if (status == CAIRO_STATUS_SUCCESS) { | ||
180 | - cairo_show_text_glyphs(cr,str,szText,glyphs, num_glyphs,clusters, num_clusters, cluster_flags); | ||
181 | - } | ||
182 | - | ||
183 | - if(glyphs) | ||
184 | - cairo_glyph_free(glyphs); | ||
185 | - | ||
186 | - if(clusters) | ||
187 | - cairo_text_cluster_free(clusters); | ||
188 | - | ||
189 | -} | ||
190 | - | ||
191 | -void v3270_draw_text(cairo_t *cr, const GdkRectangle *rect, v3270FontInfo *font, const char *str) { | ||
192 | - v3270_draw_text_at(cr,rect->x,rect->y,font,str); | ||
193 | -} | ||
194 | - | ||
195 | -void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *fg, GdkRGBA *bg) | ||
196 | -{ | ||
197 | - // Clear element area | ||
198 | - gdk_cairo_set_source_rgba(cr,bg); | ||
199 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
200 | - cairo_fill(cr); | ||
201 | - | ||
202 | - // Set foreground color | ||
203 | - gdk_cairo_set_source_rgba(cr,fg); | ||
204 | - | ||
205 | - // Draw char | ||
206 | - if( (attr & LIB3270_ATTR_MARKER) && lib3270_get_toggle(session,LIB3270_TOGGLE_VIEW_FIELD) ) | ||
207 | - { | ||
208 | - double sz = (double) rect->width; | ||
209 | - if(rect->height < rect->width) | ||
210 | - sz = (double) rect->height; | ||
211 | - | ||
212 | - cairo_save(cr); | ||
213 | - | ||
214 | - sz /= 10; | ||
215 | - | ||
216 | - cairo_translate(cr, rect->x + (rect->width / 2), rect->y + (rect->height / 2)); | ||
217 | - cairo_scale(cr, sz, sz); | ||
218 | - cairo_arc(cr, 0., 0., 1., 0., 2 * M_PI); | ||
219 | - | ||
220 | - cairo_restore(cr); | ||
221 | - } | ||
222 | - else if(attr & LIB3270_ATTR_CG) | ||
223 | - { | ||
224 | - switch(chr) | ||
225 | - { | ||
226 | - case 0xd3: // CG 0xab, plus | ||
227 | - cairo_move_to(cr,rect->x+(rect->width/2),rect->y); | ||
228 | - cairo_rel_line_to(cr,0,rect->height); | ||
229 | - cairo_move_to(cr,rect->x,rect->y+(rect->height/2)); | ||
230 | - cairo_rel_line_to(cr,rect->width,0); | ||
231 | - break; | ||
232 | - | ||
233 | - case 0xa2: // CG 0x92, horizontal line | ||
234 | - cairo_move_to(cr,rect->x,rect->y+(rect->height/2)); | ||
235 | - cairo_rel_line_to(cr,rect->width,0); | ||
236 | - break; | ||
237 | - | ||
238 | - case 0x85: // CG 0x184, vertical line | ||
239 | - cairo_move_to(cr,rect->x+(rect->width/2),rect->y); | ||
240 | - cairo_rel_line_to(cr,0,rect->height); | ||
241 | - break; | ||
242 | - | ||
243 | - case 0xd4: // CG 0xac, LR corner | ||
244 | - cairo_move_to(cr,rect->x, rect->y+(rect->height/2)); | ||
245 | - cairo_rel_line_to(cr,rect->width/2,0); | ||
246 | - cairo_rel_line_to(cr,0,-(rect->height/2)); | ||
247 | - break; | ||
248 | - | ||
249 | - case 0xd5: // CG 0xad, UR corner | ||
250 | - cairo_move_to(cr,rect->x, rect->y+(rect->height/2)); | ||
251 | - cairo_rel_line_to(cr,rect->width/2,0); | ||
252 | - cairo_rel_line_to(cr,0,rect->height/2); | ||
253 | - break; | ||
254 | - | ||
255 | - case 0xc5: // CG 0xa4, UL corner | ||
256 | - cairo_move_to(cr,rect->x+rect->width,rect->y+(rect->height/2)); | ||
257 | - cairo_rel_line_to(cr,-(rect->width/2),0); | ||
258 | - cairo_rel_line_to(cr,0,(rect->height/2)); | ||
259 | - break; | ||
260 | - | ||
261 | - case 0xc4: // CG 0xa3, LL corner | ||
262 | - cairo_move_to(cr,rect->x+rect->width,rect->y+(rect->height/2)); | ||
263 | - cairo_rel_line_to(cr,-(rect->width/2),0); | ||
264 | - cairo_rel_line_to(cr,0,-(rect->height/2)); | ||
265 | - break; | ||
266 | - | ||
267 | - case 0xc6: // CG 0xa5, left tee | ||
268 | - cairo_move_to(cr,rect->x+(rect->width/2),rect->y+(rect->height/2)); | ||
269 | - cairo_rel_line_to(cr,rect->width/2,0); | ||
270 | - cairo_move_to(cr,rect->x+(rect->width/2),rect->y); | ||
271 | - cairo_rel_line_to(cr,0,rect->height); | ||
272 | - break; | ||
273 | - | ||
274 | - case 0xd6: // CG 0xae, right tee | ||
275 | - cairo_move_to(cr,rect->x+(rect->width/2),rect->y+(rect->height/2)); | ||
276 | - cairo_rel_line_to(cr,-(rect->width/2),0); | ||
277 | - cairo_move_to(cr,rect->x+(rect->width/2),rect->y); | ||
278 | - cairo_rel_line_to(cr,0,rect->height); | ||
279 | - break; | ||
280 | - | ||
281 | - case 0xc7: // CG 0xa6, bottom tee | ||
282 | - cairo_move_to(cr,rect->x+(rect->width/2),rect->y+(rect->height/2)); | ||
283 | - cairo_rel_line_to(cr,0,-(rect->height/2)); | ||
284 | - cairo_move_to(cr,rect->x,rect->y+(rect->height/2)); | ||
285 | - cairo_rel_line_to(cr,rect->width,0); | ||
286 | - break; | ||
287 | - | ||
288 | - case 0xd7: // CG 0xaf, top tee | ||
289 | - cairo_move_to(cr,rect->x+(rect->width/2),rect->y+(rect->height/2)); | ||
290 | - cairo_rel_line_to(cr,0,rect->height/2); | ||
291 | - cairo_move_to(cr,rect->x,rect->y+(rect->height/2)); | ||
292 | - cairo_rel_line_to(cr,rect->width,0); | ||
293 | - break; | ||
294 | - | ||
295 | - case 0x8c: // CG 0xf7, less or equal "≤" | ||
296 | - v3270_draw_text(cr,rect,font,"≤"); | ||
297 | - break; | ||
298 | - | ||
299 | - case 0xae: // CG 0xd9, greater or equal "≥" | ||
300 | - v3270_draw_text(cr,rect,font,"≥"); | ||
301 | - break; | ||
302 | - | ||
303 | - case 0xbe: // CG 0x3e, not equal "≠" | ||
304 | - v3270_draw_text(cr,rect,font,"≠"); | ||
305 | - break; | ||
306 | - | ||
307 | - case 0xad: // "[" | ||
308 | - v3270_draw_text(cr,rect,font,"["); | ||
309 | - break; | ||
310 | - | ||
311 | - case 0xbd: // "]" | ||
312 | - v3270_draw_text(cr,rect,font,"]"); | ||
313 | - break; | ||
314 | - | ||
315 | - default: | ||
316 | - cairo_rectangle(cr, rect->x+1, rect->y+1, rect->width-2, rect->height-2); | ||
317 | - } | ||
318 | - } | ||
319 | - else if(chr) | ||
320 | - { | ||
321 | - gchar *utf = g_convert((char *) &chr, 1, "UTF-8", lib3270_get_display_charset(session), NULL, NULL, NULL); | ||
322 | - | ||
323 | - if(utf) | ||
324 | - { | ||
325 | - v3270_draw_text(cr,rect,font,utf); | ||
326 | - g_free(utf); | ||
327 | - } | ||
328 | - } | ||
329 | - | ||
330 | - cairo_stroke(cr); | ||
331 | -} | ||
332 | - | ||
333 | -#if !GTK_CHECK_VERSION(2, 22, 0) | ||
334 | -cairo_surface_t *gdk_window_create_similar_surface(GdkWindow *window, cairo_content_t content, int width, int height) | ||
335 | -{ | ||
336 | - cairo_t *cairoContext = gdk_cairo_create(window); | ||
337 | - cairo_surface_t *cairoSurface = cairo_get_target(cairoContext); | ||
338 | - cairo_surface_t *newSurface = cairo_surface_create_similar(cairoSurface, content, width, height); | ||
339 | - cairo_destroy(cairoContext); | ||
340 | - return newSurface; | ||
341 | -} | ||
342 | -#endif // GTK_CHECK_VERSION(2, 22, 0) | ||
343 | - | ||
344 | -/// @brief Draw terminal contents. | ||
345 | -/// | ||
346 | -/// @param terminal Terminal widget. | ||
347 | -/// @param cr a cairo context. | ||
348 | -/// @param width the width of the rectangle. | ||
349 | -/// @param height the height of the rectangle. | ||
350 | -/// | ||
351 | -void v3270_redraw(v3270 *terminal, cairo_t * cr, gint width, gint height) | ||
352 | -{ | ||
353 | - unsigned int rows, cols, r; | ||
354 | - GdkRectangle rect; | ||
355 | - int addr, cursor; | ||
356 | - | ||
357 | - gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_BACKGROUND); | ||
358 | - cairo_rectangle(cr, 0, 0, width, height); | ||
359 | - cairo_fill(cr); | ||
360 | - cairo_stroke(cr); | ||
361 | - | ||
362 | - lib3270_get_screen_size(terminal->host,&rows,&cols); | ||
363 | - | ||
364 | - memset(&rect,0,sizeof(rect)); | ||
365 | - rect.y = terminal->font.margin.top; | ||
366 | - rect.width = terminal->font.width; | ||
367 | - rect.height = terminal->font.spacing; | ||
368 | - addr = 0; | ||
369 | - cursor = lib3270_get_cursor_address(terminal->host); | ||
370 | - | ||
371 | - cairo_set_scaled_font(cr,terminal->font.scaled); | ||
372 | - | ||
373 | - for(r = 0; r < rows; r++) | ||
374 | - { | ||
375 | - unsigned int c; | ||
376 | - | ||
377 | - rect.x = terminal->font.margin.left; | ||
378 | - | ||
379 | - for(c=0;c < cols;c++) | ||
380 | - { | ||
381 | - struct v3270_character element = { 0, 0 }; | ||
382 | - | ||
383 | - lib3270_get_contents(terminal->host,addr,addr,&element.chr,&element.attr); | ||
384 | - | ||
385 | - if(addr == cursor) | ||
386 | - v3270_update_cursor_rect(terminal,&rect,&element); | ||
387 | - | ||
388 | - v3270_draw_element(cr,element.chr,element.attr,terminal->host,&terminal->font,&rect,terminal->color); | ||
389 | - | ||
390 | - addr++; | ||
391 | - rect.x += rect.width; | ||
392 | - } | ||
393 | - | ||
394 | - rect.y += terminal->font.spacing; | ||
395 | - | ||
396 | - } | ||
397 | - | ||
398 | - v3270_draw_oia(terminal, cr, rect.y, cols); | ||
399 | - | ||
400 | -} | ||
401 | - | ||
402 | -LIB3270_EXPORT void v3270_reload(GtkWidget *widget) | ||
403 | -{ | ||
404 | - v3270 * terminal = GTK_V3270(widget); | ||
405 | - | ||
406 | - if(!(gtk_widget_get_realized(widget) && terminal->drawing)) | ||
407 | - return; | ||
408 | - | ||
409 | - gint width = gtk_widget_get_allocated_width(widget); | ||
410 | - gint height = gtk_widget_get_allocated_height(widget); | ||
411 | - | ||
412 | - cairo_t * cr = cairo_create(terminal->surface); | ||
413 | - | ||
414 | - v3270_redraw(terminal, cr, width, height); | ||
415 | - | ||
416 | - cairo_destroy(cr); | ||
417 | - | ||
418 | - /* | ||
419 | - v3270 * terminal = GTK_V3270(widget); | ||
420 | - cairo_t * cr; | ||
421 | - | ||
422 | - | ||
423 | - | ||
424 | - // Create new terminal image | ||
425 | - if(terminal->surface) | ||
426 | - cairo_surface_destroy(terminal->surface); | ||
427 | - | ||
428 | - terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,width,height); | ||
429 | - | ||
430 | - // Update the created image | ||
431 | - cr = cairo_create(terminal->surface); | ||
432 | - v3270_compute_font_size(terminal, cr, width, height); | ||
433 | - v3270_update_font_metrics(terminal, width, height); | ||
434 | - | ||
435 | - v3270_redraw(terminal, cr, width, height); | ||
436 | - | ||
437 | - cairo_destroy(cr); | ||
438 | - */ | ||
439 | -} | ||
440 | - | ||
441 | -void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor) | ||
442 | -{ | ||
443 | - v3270 * terminal = GTK_V3270(lib3270_get_user_data(session)); | ||
444 | - cairo_t * cr; | ||
445 | - GdkRectangle rect; | ||
446 | - unsigned int rows,cols; | ||
447 | - struct v3270_character element; | ||
448 | - | ||
449 | - element.chr = chr; | ||
450 | - element.attr = attr; | ||
451 | - | ||
452 | - if(!(gtk_widget_get_realized(GTK_WIDGET(terminal)) && terminal->drawing)) | ||
453 | - return; | ||
454 | - | ||
455 | - if(!terminal->surface) | ||
456 | - { | ||
457 | - v3270_reload(GTK_WIDGET(terminal)); | ||
458 | - gtk_widget_queue_draw(GTK_WIDGET(terminal)); | ||
459 | - return; | ||
460 | - } | ||
461 | - | ||
462 | - lib3270_get_screen_size(terminal->host,&rows,&cols); | ||
463 | - | ||
464 | - memset(&rect,0,sizeof(rect)); | ||
465 | - rect.x = terminal->font.margin.left + ((addr % cols) * terminal->font.width); | ||
466 | - rect.y = terminal->font.margin.top + ((addr / cols) * terminal->font.spacing); | ||
467 | - rect.width = terminal->font.width; | ||
468 | - rect.height = terminal->font.spacing; | ||
469 | - | ||
470 | - cr = cairo_create(terminal->surface); | ||
471 | - cairo_set_scaled_font(cr,terminal->font.scaled); | ||
472 | - v3270_draw_element(cr, chr, attr, terminal->host, &terminal->font, &rect,terminal->color); | ||
473 | - cairo_destroy(cr); | ||
474 | - | ||
475 | - if(cursor) | ||
476 | - v3270_update_cursor_rect(terminal,&rect,&element); | ||
477 | - | ||
478 | - v3270_queue_draw_area(GTK_WIDGET(terminal),rect.x,rect.y,rect.width,rect.height); | ||
479 | - | ||
480 | -} | ||
481 | - | ||
482 | -void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short attr) | ||
483 | -{ | ||
484 | - if(widget->cursor.surface && widget->drawing) | ||
485 | - { | ||
486 | - GdkRectangle rect = widget->cursor.rect; | ||
487 | - cairo_t * cr = cairo_create(widget->cursor.surface); | ||
488 | - GdkRGBA * fg; | ||
489 | - GdkRGBA * bg; | ||
490 | - | ||
491 | - get_element_colors(attr,&fg,&bg,widget->color); | ||
492 | - | ||
493 | - cairo_set_scaled_font(cr,widget->font.scaled); | ||
494 | - | ||
495 | - rect.x = 0; | ||
496 | - rect.y = 0; | ||
497 | - v3270_draw_char(cr,chr,attr,widget->host,&widget->font,&rect,bg,fg); | ||
498 | - | ||
499 | - cairo_destroy(cr); | ||
500 | - } | ||
501 | - | ||
502 | - | ||
503 | -} | ||
504 | - | ||
505 | -void v3270_update_cursor_rect(v3270 *widget, GdkRectangle *rect, const struct v3270_character *element) | ||
506 | -{ | ||
507 | - widget->cursor.chr = element->chr; | ||
508 | - widget->cursor.rect = *rect; | ||
509 | - widget->cursor.attr = element->attr; | ||
510 | - widget->cursor.rect.height = widget->font.height + widget->font.descent; | ||
511 | - v3270_update_cursor_surface(widget,element->chr,element->attr); | ||
512 | -} | ||
513 | - | ||
514 | -void v3270_queue_draw_area(GtkWidget *widget, gint x, gint y, gint width, gint height) | ||
515 | -{ | ||
516 | - | ||
517 | - if(GTK_V3270(widget)->drawing && gtk_widget_get_realized(widget)) | ||
518 | - { | ||
519 | - gtk_widget_queue_draw_area(widget,x,y,width,height); | ||
520 | - } | ||
521 | - | ||
522 | -} | ||
523 | - | ||
524 | -void v3270_disable_updates(GtkWidget *widget) | ||
525 | -{ | ||
526 | - GTK_V3270(widget)->drawing = 0; | ||
527 | -} | ||
528 | - | ||
529 | -void v3270_enable_updates(GtkWidget *widget) | ||
530 | -{ | ||
531 | - if(gtk_widget_get_realized(widget)) | ||
532 | - { | ||
533 | - GTK_V3270(widget)->drawing = 1; | ||
534 | - v3270_reload(widget); | ||
535 | - gtk_widget_queue_draw(widget); | ||
536 | - } | ||
537 | -} |
@@ -0,0 +1,553 @@ | @@ -0,0 +1,553 @@ | ||
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 draw.c 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 | + /* | ||
31 | +#ifdef WIN32 | ||
32 | + #include <winsock2.h> | ||
33 | + #include <windows.h> | ||
34 | + #include <ws2tcpip.h> | ||
35 | +#endif // WIN32 | ||
36 | +*/ | ||
37 | + | ||
38 | + #include <gtk/gtk.h> | ||
39 | + #include <math.h> | ||
40 | + #include <ctype.h> | ||
41 | + #include <lib3270.h> | ||
42 | + #include <lib3270/log.h> | ||
43 | + #include <lib3270/session.h> | ||
44 | + #include <lib3270/toggle.h> | ||
45 | + #include <internals.h> | ||
46 | + | ||
47 | + #include <v3270.h> | ||
48 | + #include <terminal.h> | ||
49 | + | ||
50 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
51 | + | ||
52 | +void v3270_cursor_draw(v3270 *widget) | ||
53 | +{ | ||
54 | + int pos = lib3270_get_cursor_address(widget->host); | ||
55 | + unsigned char c; | ||
56 | + unsigned short attr; | ||
57 | + | ||
58 | + lib3270_get_contents(widget->host,pos,pos,&c,&attr); | ||
59 | + v3270_update_cursor_surface(widget,c,attr); | ||
60 | + v3270_queue_draw_area( GTK_WIDGET(widget), | ||
61 | + widget->cursor.rect.x,widget->cursor.rect.y, | ||
62 | + widget->cursor.rect.width,widget->cursor.rect.height); | ||
63 | + | ||
64 | +} | ||
65 | + | ||
66 | +gboolean v3270_draw(GtkWidget * widget, cairo_t * cr) | ||
67 | +{ | ||
68 | + v3270 * terminal = GTK_V3270(widget); | ||
69 | + | ||
70 | + cairo_set_source_surface(cr,terminal->surface,0,0); | ||
71 | + cairo_paint(cr); | ||
72 | + | ||
73 | + if(lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_CROSSHAIR) && (terminal->cursor.show&2)) | ||
74 | + { | ||
75 | + GtkAllocation allocation; | ||
76 | + gtk_widget_get_allocation(widget, &allocation); | ||
77 | + | ||
78 | + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_CROSS_HAIR); | ||
79 | + | ||
80 | + cairo_rectangle(cr, 0,terminal->cursor.rect.y+terminal->font.height,allocation.width,1); | ||
81 | + cairo_fill(cr); | ||
82 | + | ||
83 | + cairo_rectangle(cr, terminal->cursor.rect.x,0,1,terminal->oia.rect->y-3); | ||
84 | + cairo_fill(cr); | ||
85 | + } | ||
86 | + | ||
87 | + if(terminal->cursor.show == 3) | ||
88 | + { | ||
89 | + cairo_set_source_surface(cr,terminal->cursor.surface,terminal->cursor.rect.x,terminal->cursor.rect.y); | ||
90 | + | ||
91 | + if(lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_INSERT)) | ||
92 | + { | ||
93 | + cairo_rectangle(cr, terminal->cursor.rect.x, | ||
94 | + terminal->cursor.rect.y, | ||
95 | + terminal->cursor.rect.width, | ||
96 | + terminal->cursor.rect.height ); | ||
97 | + } | ||
98 | + else | ||
99 | + { | ||
100 | + cairo_rectangle(cr, terminal->cursor.rect.x, | ||
101 | + terminal->cursor.rect.y+terminal->font.height, | ||
102 | + terminal->cursor.rect.width, | ||
103 | + terminal->font.descent ); | ||
104 | + } | ||
105 | + | ||
106 | + cairo_fill(cr); | ||
107 | + } | ||
108 | + | ||
109 | + return FALSE; | ||
110 | +} | ||
111 | + | ||
112 | +#if( !GTK_CHECK_VERSION(3,0,0)) | ||
113 | +gboolean v3270_expose(GtkWidget *widget, GdkEventExpose *event) | ||
114 | +{ | ||
115 | + cairo_t *cr = gdk_cairo_create(widget->window); | ||
116 | + v3270_draw(widget,cr); | ||
117 | + cairo_destroy(cr); | ||
118 | + return FALSE; | ||
119 | +} | ||
120 | +#endif // GTk3 | ||
121 | + | ||
122 | + | ||
123 | +static void get_element_colors(unsigned short attr, GdkRGBA **fg, GdkRGBA **bg, GdkRGBA *color) | ||
124 | +{ | ||
125 | + if(attr & LIB3270_ATTR_SELECTED) | ||
126 | + { | ||
127 | + *fg = color+V3270_COLOR_SELECTED_FG; | ||
128 | + *bg = color+V3270_COLOR_SELECTED_BG; | ||
129 | + } | ||
130 | + else | ||
131 | + { | ||
132 | + *bg = color+((attr & 0x00F0) >> 4); | ||
133 | + | ||
134 | + if(attr & LIB3270_ATTR_FIELD) | ||
135 | + *fg = color+(attr & 0x0003)+V3270_COLOR_FIELD; | ||
136 | + else | ||
137 | + *fg = color+(attr & 0x000F); | ||
138 | + } | ||
139 | +} | ||
140 | + | ||
141 | +void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *fontInfo, GdkRectangle *rect, GdkRGBA *color) | ||
142 | +{ | ||
143 | + GdkRGBA *fg; | ||
144 | + GdkRGBA *bg; | ||
145 | + | ||
146 | + get_element_colors(attr,&fg,&bg,color); | ||
147 | + v3270_draw_char(cr,chr,attr,session,fontInfo,rect,fg,bg); | ||
148 | + | ||
149 | + if(attr & LIB3270_ATTR_UNDERLINE) | ||
150 | + { | ||
151 | + cairo_scaled_font_t * font = cairo_get_scaled_font(cr); | ||
152 | + cairo_font_extents_t extents; | ||
153 | + double sl; | ||
154 | + | ||
155 | + cairo_scaled_font_extents(font,&extents); | ||
156 | + | ||
157 | + sl = extents.descent/3; | ||
158 | + if(sl < 1) | ||
159 | + sl = 1; | ||
160 | + | ||
161 | + gdk_cairo_set_source_rgba(cr,fg); | ||
162 | + | ||
163 | + cairo_rectangle(cr,rect->x,rect->y+sl+extents.ascent+(extents.descent/2),rect->width,sl); | ||
164 | + cairo_fill(cr); | ||
165 | + | ||
166 | + cairo_stroke(cr); | ||
167 | + } | ||
168 | + | ||
169 | +} | ||
170 | + | ||
171 | +void v3270_draw_text_at(cairo_t *cr, int x, int y, v3270FontInfo *font, const char *str) { | ||
172 | + | ||
173 | + size_t szText = strlen(str); | ||
174 | + | ||
175 | + if(szText == 1 && isspace(*str)) { | ||
176 | + return; | ||
177 | + } | ||
178 | + | ||
179 | + // Tem string, desenha | ||
180 | + cairo_status_t status; | ||
181 | + cairo_glyph_t * glyphs = NULL; | ||
182 | + int num_glyphs = 0; | ||
183 | + cairo_text_cluster_t * clusters = NULL; | ||
184 | + int num_clusters = 0; | ||
185 | + cairo_text_cluster_flags_t cluster_flags; | ||
186 | + cairo_scaled_font_t * scaled_font = cairo_get_scaled_font(cr); | ||
187 | + | ||
188 | + status = cairo_scaled_font_text_to_glyphs( | ||
189 | + scaled_font, | ||
190 | + (double) x, (double) (y+font->height), | ||
191 | + str, szText, | ||
192 | + &glyphs, &num_glyphs, | ||
193 | + &clusters, &num_clusters, &cluster_flags ); | ||
194 | + | ||
195 | + if (status == CAIRO_STATUS_SUCCESS) { | ||
196 | + cairo_show_text_glyphs(cr,str,szText,glyphs, num_glyphs,clusters, num_clusters, cluster_flags); | ||
197 | + } | ||
198 | + | ||
199 | + if(glyphs) | ||
200 | + cairo_glyph_free(glyphs); | ||
201 | + | ||
202 | + if(clusters) | ||
203 | + cairo_text_cluster_free(clusters); | ||
204 | + | ||
205 | +} | ||
206 | + | ||
207 | +void v3270_draw_text(cairo_t *cr, const GdkRectangle *rect, v3270FontInfo *font, const char *str) { | ||
208 | + v3270_draw_text_at(cr,rect->x,rect->y,font,str); | ||
209 | +} | ||
210 | + | ||
211 | +void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *fg, GdkRGBA *bg) | ||
212 | +{ | ||
213 | + // Clear element area | ||
214 | + gdk_cairo_set_source_rgba(cr,bg); | ||
215 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
216 | + cairo_fill(cr); | ||
217 | + | ||
218 | + // Set foreground color | ||
219 | + gdk_cairo_set_source_rgba(cr,fg); | ||
220 | + | ||
221 | + // Draw char | ||
222 | + if( (attr & LIB3270_ATTR_MARKER) && lib3270_get_toggle(session,LIB3270_TOGGLE_VIEW_FIELD) ) | ||
223 | + { | ||
224 | + double sz = (double) rect->width; | ||
225 | + if(rect->height < rect->width) | ||
226 | + sz = (double) rect->height; | ||
227 | + | ||
228 | + cairo_save(cr); | ||
229 | + | ||
230 | + sz /= 10; | ||
231 | + | ||
232 | + cairo_translate(cr, rect->x + (rect->width / 2), rect->y + (rect->height / 2)); | ||
233 | + cairo_scale(cr, sz, sz); | ||
234 | + cairo_arc(cr, 0., 0., 1., 0., 2 * M_PI); | ||
235 | + | ||
236 | + cairo_restore(cr); | ||
237 | + } | ||
238 | + else if(attr & LIB3270_ATTR_CG) | ||
239 | + { | ||
240 | + switch(chr) | ||
241 | + { | ||
242 | + case 0xd3: // CG 0xab, plus | ||
243 | + cairo_move_to(cr,rect->x+(rect->width/2),rect->y); | ||
244 | + cairo_rel_line_to(cr,0,rect->height); | ||
245 | + cairo_move_to(cr,rect->x,rect->y+(rect->height/2)); | ||
246 | + cairo_rel_line_to(cr,rect->width,0); | ||
247 | + break; | ||
248 | + | ||
249 | + case 0xa2: // CG 0x92, horizontal line | ||
250 | + cairo_move_to(cr,rect->x,rect->y+(rect->height/2)); | ||
251 | + cairo_rel_line_to(cr,rect->width,0); | ||
252 | + break; | ||
253 | + | ||
254 | + case 0x85: // CG 0x184, vertical line | ||
255 | + cairo_move_to(cr,rect->x+(rect->width/2),rect->y); | ||
256 | + cairo_rel_line_to(cr,0,rect->height); | ||
257 | + break; | ||
258 | + | ||
259 | + case 0xd4: // CG 0xac, LR corner | ||
260 | + cairo_move_to(cr,rect->x, rect->y+(rect->height/2)); | ||
261 | + cairo_rel_line_to(cr,rect->width/2,0); | ||
262 | + cairo_rel_line_to(cr,0,-(rect->height/2)); | ||
263 | + break; | ||
264 | + | ||
265 | + case 0xd5: // CG 0xad, UR corner | ||
266 | + cairo_move_to(cr,rect->x, rect->y+(rect->height/2)); | ||
267 | + cairo_rel_line_to(cr,rect->width/2,0); | ||
268 | + cairo_rel_line_to(cr,0,rect->height/2); | ||
269 | + break; | ||
270 | + | ||
271 | + case 0xc5: // CG 0xa4, UL corner | ||
272 | + cairo_move_to(cr,rect->x+rect->width,rect->y+(rect->height/2)); | ||
273 | + cairo_rel_line_to(cr,-(rect->width/2),0); | ||
274 | + cairo_rel_line_to(cr,0,(rect->height/2)); | ||
275 | + break; | ||
276 | + | ||
277 | + case 0xc4: // CG 0xa3, LL corner | ||
278 | + cairo_move_to(cr,rect->x+rect->width,rect->y+(rect->height/2)); | ||
279 | + cairo_rel_line_to(cr,-(rect->width/2),0); | ||
280 | + cairo_rel_line_to(cr,0,-(rect->height/2)); | ||
281 | + break; | ||
282 | + | ||
283 | + case 0xc6: // CG 0xa5, left tee | ||
284 | + cairo_move_to(cr,rect->x+(rect->width/2),rect->y+(rect->height/2)); | ||
285 | + cairo_rel_line_to(cr,rect->width/2,0); | ||
286 | + cairo_move_to(cr,rect->x+(rect->width/2),rect->y); | ||
287 | + cairo_rel_line_to(cr,0,rect->height); | ||
288 | + break; | ||
289 | + | ||
290 | + case 0xd6: // CG 0xae, right tee | ||
291 | + cairo_move_to(cr,rect->x+(rect->width/2),rect->y+(rect->height/2)); | ||
292 | + cairo_rel_line_to(cr,-(rect->width/2),0); | ||
293 | + cairo_move_to(cr,rect->x+(rect->width/2),rect->y); | ||
294 | + cairo_rel_line_to(cr,0,rect->height); | ||
295 | + break; | ||
296 | + | ||
297 | + case 0xc7: // CG 0xa6, bottom tee | ||
298 | + cairo_move_to(cr,rect->x+(rect->width/2),rect->y+(rect->height/2)); | ||
299 | + cairo_rel_line_to(cr,0,-(rect->height/2)); | ||
300 | + cairo_move_to(cr,rect->x,rect->y+(rect->height/2)); | ||
301 | + cairo_rel_line_to(cr,rect->width,0); | ||
302 | + break; | ||
303 | + | ||
304 | + case 0xd7: // CG 0xaf, top tee | ||
305 | + cairo_move_to(cr,rect->x+(rect->width/2),rect->y+(rect->height/2)); | ||
306 | + cairo_rel_line_to(cr,0,rect->height/2); | ||
307 | + cairo_move_to(cr,rect->x,rect->y+(rect->height/2)); | ||
308 | + cairo_rel_line_to(cr,rect->width,0); | ||
309 | + break; | ||
310 | + | ||
311 | + case 0x8c: // CG 0xf7, less or equal "≤" | ||
312 | + v3270_draw_text(cr,rect,font,"≤"); | ||
313 | + break; | ||
314 | + | ||
315 | + case 0xae: // CG 0xd9, greater or equal "≥" | ||
316 | + v3270_draw_text(cr,rect,font,"≥"); | ||
317 | + break; | ||
318 | + | ||
319 | + case 0xbe: // CG 0x3e, not equal "≠" | ||
320 | + v3270_draw_text(cr,rect,font,"≠"); | ||
321 | + break; | ||
322 | + | ||
323 | + case 0xad: // "[" | ||
324 | + v3270_draw_text(cr,rect,font,"["); | ||
325 | + break; | ||
326 | + | ||
327 | + case 0xbd: // "]" | ||
328 | + v3270_draw_text(cr,rect,font,"]"); | ||
329 | + break; | ||
330 | + | ||
331 | + default: | ||
332 | + cairo_rectangle(cr, rect->x+1, rect->y+1, rect->width-2, rect->height-2); | ||
333 | + } | ||
334 | + } | ||
335 | + else if(chr) | ||
336 | + { | ||
337 | + gchar *utf = g_convert((char *) &chr, 1, "UTF-8", lib3270_get_display_charset(session), NULL, NULL, NULL); | ||
338 | + | ||
339 | + if(utf) | ||
340 | + { | ||
341 | + v3270_draw_text(cr,rect,font,utf); | ||
342 | + g_free(utf); | ||
343 | + } | ||
344 | + } | ||
345 | + | ||
346 | + cairo_stroke(cr); | ||
347 | +} | ||
348 | + | ||
349 | +#if !GTK_CHECK_VERSION(2, 22, 0) | ||
350 | +cairo_surface_t *gdk_window_create_similar_surface(GdkWindow *window, cairo_content_t content, int width, int height) | ||
351 | +{ | ||
352 | + cairo_t *cairoContext = gdk_cairo_create(window); | ||
353 | + cairo_surface_t *cairoSurface = cairo_get_target(cairoContext); | ||
354 | + cairo_surface_t *newSurface = cairo_surface_create_similar(cairoSurface, content, width, height); | ||
355 | + cairo_destroy(cairoContext); | ||
356 | + return newSurface; | ||
357 | +} | ||
358 | +#endif // GTK_CHECK_VERSION(2, 22, 0) | ||
359 | + | ||
360 | +/// @brief Draw terminal contents. | ||
361 | +/// | ||
362 | +/// @param terminal Terminal widget. | ||
363 | +/// @param cr a cairo context. | ||
364 | +/// @param width the width of the rectangle. | ||
365 | +/// @param height the height of the rectangle. | ||
366 | +/// | ||
367 | +void v3270_redraw(v3270 *terminal, cairo_t * cr, gint width, gint height) | ||
368 | +{ | ||
369 | + unsigned int rows, cols, r; | ||
370 | + GdkRectangle rect; | ||
371 | + int addr, cursor; | ||
372 | + | ||
373 | + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_BACKGROUND); | ||
374 | + cairo_rectangle(cr, 0, 0, width, height); | ||
375 | + cairo_fill(cr); | ||
376 | + cairo_stroke(cr); | ||
377 | + | ||
378 | + lib3270_get_screen_size(terminal->host,&rows,&cols); | ||
379 | + | ||
380 | + memset(&rect,0,sizeof(rect)); | ||
381 | + rect.y = terminal->font.margin.top; | ||
382 | + rect.width = terminal->font.width; | ||
383 | + rect.height = terminal->font.spacing; | ||
384 | + addr = 0; | ||
385 | + cursor = lib3270_get_cursor_address(terminal->host); | ||
386 | + | ||
387 | + cairo_set_scaled_font(cr,terminal->font.scaled); | ||
388 | + | ||
389 | + for(r = 0; r < rows; r++) | ||
390 | + { | ||
391 | + unsigned int c; | ||
392 | + | ||
393 | + rect.x = terminal->font.margin.left; | ||
394 | + | ||
395 | + for(c=0;c < cols;c++) | ||
396 | + { | ||
397 | + struct v3270_character element = { 0, 0 }; | ||
398 | + | ||
399 | + lib3270_get_contents(terminal->host,addr,addr,&element.chr,&element.attr); | ||
400 | + | ||
401 | + if(addr == cursor) | ||
402 | + v3270_update_cursor_rect(terminal,&rect,&element); | ||
403 | + | ||
404 | + v3270_draw_element(cr,element.chr,element.attr,terminal->host,&terminal->font,&rect,terminal->color); | ||
405 | + | ||
406 | + addr++; | ||
407 | + rect.x += rect.width; | ||
408 | + } | ||
409 | + | ||
410 | + rect.y += terminal->font.spacing; | ||
411 | + | ||
412 | + } | ||
413 | + | ||
414 | + v3270_draw_oia(terminal, cr, rect.y, cols); | ||
415 | + | ||
416 | +} | ||
417 | + | ||
418 | +LIB3270_EXPORT void v3270_reload(GtkWidget *widget) | ||
419 | +{ | ||
420 | + v3270 * terminal = GTK_V3270(widget); | ||
421 | + | ||
422 | + if(!(gtk_widget_get_realized(widget) && terminal->drawing)) | ||
423 | + return; | ||
424 | + | ||
425 | + gint width = gtk_widget_get_allocated_width(widget); | ||
426 | + gint height = gtk_widget_get_allocated_height(widget); | ||
427 | + | ||
428 | + cairo_t * cr = cairo_create(terminal->surface); | ||
429 | + | ||
430 | + v3270_redraw(terminal, cr, width, height); | ||
431 | + | ||
432 | + cairo_destroy(cr); | ||
433 | + | ||
434 | + /* | ||
435 | + v3270 * terminal = GTK_V3270(widget); | ||
436 | + cairo_t * cr; | ||
437 | + | ||
438 | + | ||
439 | + | ||
440 | + // Create new terminal image | ||
441 | + if(terminal->surface) | ||
442 | + cairo_surface_destroy(terminal->surface); | ||
443 | + | ||
444 | + terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,width,height); | ||
445 | + | ||
446 | + // Update the created image | ||
447 | + cr = cairo_create(terminal->surface); | ||
448 | + v3270_compute_font_size(terminal, cr, width, height); | ||
449 | + v3270_update_font_metrics(terminal, width, height); | ||
450 | + | ||
451 | + v3270_redraw(terminal, cr, width, height); | ||
452 | + | ||
453 | + cairo_destroy(cr); | ||
454 | + */ | ||
455 | +} | ||
456 | + | ||
457 | +void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor) | ||
458 | +{ | ||
459 | + v3270 * terminal = GTK_V3270(lib3270_get_user_data(session)); | ||
460 | + cairo_t * cr; | ||
461 | + GdkRectangle rect; | ||
462 | + unsigned int rows,cols; | ||
463 | + struct v3270_character element; | ||
464 | + | ||
465 | + element.chr = chr; | ||
466 | + element.attr = attr; | ||
467 | + | ||
468 | + if(!(gtk_widget_get_realized(GTK_WIDGET(terminal)) && terminal->drawing)) | ||
469 | + return; | ||
470 | + | ||
471 | + if(!terminal->surface) | ||
472 | + { | ||
473 | + v3270_reload(GTK_WIDGET(terminal)); | ||
474 | + gtk_widget_queue_draw(GTK_WIDGET(terminal)); | ||
475 | + return; | ||
476 | + } | ||
477 | + | ||
478 | + lib3270_get_screen_size(terminal->host,&rows,&cols); | ||
479 | + | ||
480 | + memset(&rect,0,sizeof(rect)); | ||
481 | + rect.x = terminal->font.margin.left + ((addr % cols) * terminal->font.width); | ||
482 | + rect.y = terminal->font.margin.top + ((addr / cols) * terminal->font.spacing); | ||
483 | + rect.width = terminal->font.width; | ||
484 | + rect.height = terminal->font.spacing; | ||
485 | + | ||
486 | + cr = cairo_create(terminal->surface); | ||
487 | + cairo_set_scaled_font(cr,terminal->font.scaled); | ||
488 | + v3270_draw_element(cr, chr, attr, terminal->host, &terminal->font, &rect,terminal->color); | ||
489 | + cairo_destroy(cr); | ||
490 | + | ||
491 | + if(cursor) | ||
492 | + v3270_update_cursor_rect(terminal,&rect,&element); | ||
493 | + | ||
494 | + v3270_queue_draw_area(GTK_WIDGET(terminal),rect.x,rect.y,rect.width,rect.height); | ||
495 | + | ||
496 | +} | ||
497 | + | ||
498 | +void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short attr) | ||
499 | +{ | ||
500 | + if(widget->cursor.surface && widget->drawing) | ||
501 | + { | ||
502 | + GdkRectangle rect = widget->cursor.rect; | ||
503 | + cairo_t * cr = cairo_create(widget->cursor.surface); | ||
504 | + GdkRGBA * fg; | ||
505 | + GdkRGBA * bg; | ||
506 | + | ||
507 | + get_element_colors(attr,&fg,&bg,widget->color); | ||
508 | + | ||
509 | + cairo_set_scaled_font(cr,widget->font.scaled); | ||
510 | + | ||
511 | + rect.x = 0; | ||
512 | + rect.y = 0; | ||
513 | + v3270_draw_char(cr,chr,attr,widget->host,&widget->font,&rect,bg,fg); | ||
514 | + | ||
515 | + cairo_destroy(cr); | ||
516 | + } | ||
517 | + | ||
518 | + | ||
519 | +} | ||
520 | + | ||
521 | +void v3270_update_cursor_rect(v3270 *widget, GdkRectangle *rect, const struct v3270_character *element) | ||
522 | +{ | ||
523 | + widget->cursor.chr = element->chr; | ||
524 | + widget->cursor.rect = *rect; | ||
525 | + widget->cursor.attr = element->attr; | ||
526 | + widget->cursor.rect.height = widget->font.height + widget->font.descent; | ||
527 | + v3270_update_cursor_surface(widget,element->chr,element->attr); | ||
528 | +} | ||
529 | + | ||
530 | +void v3270_queue_draw_area(GtkWidget *widget, gint x, gint y, gint width, gint height) | ||
531 | +{ | ||
532 | + | ||
533 | + if(GTK_V3270(widget)->drawing && gtk_widget_get_realized(widget)) | ||
534 | + { | ||
535 | + gtk_widget_queue_draw_area(widget,x,y,width,height); | ||
536 | + } | ||
537 | + | ||
538 | +} | ||
539 | + | ||
540 | +void v3270_disable_updates(GtkWidget *widget) | ||
541 | +{ | ||
542 | + GTK_V3270(widget)->drawing = 0; | ||
543 | +} | ||
544 | + | ||
545 | +void v3270_enable_updates(GtkWidget *widget) | ||
546 | +{ | ||
547 | + if(gtk_widget_get_realized(widget)) | ||
548 | + { | ||
549 | + GTK_V3270(widget)->drawing = 1; | ||
550 | + v3270_reload(widget); | ||
551 | + gtk_widget_queue_draw(widget); | ||
552 | + } | ||
553 | +} |
@@ -0,0 +1,1170 @@ | @@ -0,0 +1,1170 @@ | ||
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 oia.c 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 | + | ||
32 | + #define ENABLE_NLS | ||
33 | + #define GETTEXT_PACKAGE PACKAGE_NAME | ||
34 | + | ||
35 | + #include <gtk/gtk.h> | ||
36 | + #include <libintl.h> | ||
37 | + #include <glib/gi18n.h> | ||
38 | + | ||
39 | + /* | ||
40 | + #ifdef WIN32 | ||
41 | + #include <winsock2.h> | ||
42 | + #include <windows.h> | ||
43 | + #include <ws2tcpip.h> | ||
44 | + #endif // WIN32 | ||
45 | + */ | ||
46 | + | ||
47 | + #include <lib3270.h> | ||
48 | + #include <lib3270/session.h> | ||
49 | + #include <lib3270/log.h> | ||
50 | + #include <lib3270/toggle.h> | ||
51 | + #include <config.h> | ||
52 | + #include <string.h> | ||
53 | + #include <errno.h> | ||
54 | + #include <ctype.h> | ||
55 | + | ||
56 | + #ifdef HAVE_LIBM | ||
57 | + #include <math.h> | ||
58 | + #endif // HAVE_LIBM | ||
59 | + | ||
60 | + #include <v3270.h> | ||
61 | + #include <terminal.h> | ||
62 | + #include <internals.h> | ||
63 | + #include <v3270/accessible.h> | ||
64 | + | ||
65 | +/*--[ Prototipes ]-----------------------------------------------------------------------------------*/ | ||
66 | + | ||
67 | +static void draw_cursor_position(cairo_t *cr, GdkRectangle *rect, v3270FontInfo *metrics, int row, int col); | ||
68 | + | ||
69 | +/*--[ Statics ]--------------------------------------------------------------------------------------*/ | ||
70 | + | ||
71 | + #include "xbm/locked.xbm" | ||
72 | + #include "xbm/unlocked.xbm" | ||
73 | + #include "xbm/negotiated.xbm" | ||
74 | + #include "xbm/warning.xbm" | ||
75 | + | ||
76 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
77 | + | ||
78 | +static void short2string(char *ptr, unsigned short vlr, size_t sz) | ||
79 | +{ | ||
80 | + int f; | ||
81 | + | ||
82 | + for(f=sz-1;f>=0;f--) | ||
83 | + { | ||
84 | + ptr[f] = '0'+(vlr%10); | ||
85 | + vlr /= 10; | ||
86 | + } | ||
87 | +} | ||
88 | + | ||
89 | + | ||
90 | +#ifdef HAVE_LIBM | ||
91 | +static gint draw_spinner(cairo_t *cr, GdkRectangle *r, GdkRGBA *color, gint step) | ||
92 | +{ | ||
93 | + static const guint num_steps = 10; | ||
94 | + | ||
95 | + gdouble dx = r->width/2; | ||
96 | + gdouble dy = r->height/2; | ||
97 | + gdouble radius = MIN (r->width / 2, r->height / 2); | ||
98 | + gdouble half = num_steps / 2; | ||
99 | + gint i; | ||
100 | + | ||
101 | + cairo_save(cr); | ||
102 | + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
103 | + | ||
104 | + cairo_rectangle(cr, r->x, r->y, r->width, r->height); | ||
105 | + cairo_clip(cr); | ||
106 | + cairo_translate(cr, r->x, r->y); | ||
107 | + | ||
108 | + step++; | ||
109 | + step %= num_steps; | ||
110 | + | ||
111 | +// debug("%s step=%d",__FUNCTION__,step); | ||
112 | + | ||
113 | + for (i = 0; i < ((gint) num_steps); i++) | ||
114 | + { | ||
115 | + gint inset = 0.7 * radius; | ||
116 | + | ||
117 | + /* transparency is a function of time and intial value */ | ||
118 | + gdouble t = (gdouble) ((i + num_steps - step) % num_steps) / num_steps; | ||
119 | + | ||
120 | + cairo_save(cr); | ||
121 | + | ||
122 | + cairo_set_source_rgba (cr, | ||
123 | + color[V3270_COLOR_OIA_SPINNER].red, | ||
124 | + color[V3270_COLOR_OIA_SPINNER].green, | ||
125 | + color[V3270_COLOR_OIA_SPINNER].blue, | ||
126 | + t); | ||
127 | + | ||
128 | + cairo_set_line_width (cr, 2.0); | ||
129 | + cairo_move_to (cr, | ||
130 | + dx + (radius - inset) * cos (i * G_PI / half), | ||
131 | + dy + (radius - inset) * sin (i * G_PI / half)); | ||
132 | + cairo_line_to (cr, | ||
133 | + dx + radius * cos (i * G_PI / half), | ||
134 | + dy + radius * sin (i * G_PI / half)); | ||
135 | + cairo_stroke (cr); | ||
136 | + | ||
137 | + cairo_restore (cr); | ||
138 | + } | ||
139 | + | ||
140 | + cairo_restore(cr); | ||
141 | + | ||
142 | + return step; | ||
143 | +} | ||
144 | +#endif // HAVE_LIBM | ||
145 | + | ||
146 | +static void setup_cursor_position(GdkRectangle *rect, v3270FontInfo *metrics, cairo_t *cr, H3270 *host, int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
147 | +{ | ||
148 | + rect->width = metrics->width * 8; | ||
149 | + rect->x -= rect->width; | ||
150 | + | ||
151 | + if(lib3270_get_toggle(host,LIB3270_TOGGLE_CURSOR_POS)) | ||
152 | + { | ||
153 | + int addr = lib3270_get_cursor_address(host); | ||
154 | + draw_cursor_position(cr,rect,metrics,addr/cols,addr%cols); | ||
155 | + } | ||
156 | +} | ||
157 | + | ||
158 | +static void setup_ticking_position(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
159 | +{ | ||
160 | + char buffer[7]; | ||
161 | + cairo_text_extents_t extents; | ||
162 | + | ||
163 | + short2string(buffer,0,2); | ||
164 | + buffer[2] = ':'; | ||
165 | + short2string(buffer+3,0,2); | ||
166 | + buffer[5] = 0; | ||
167 | + | ||
168 | + cairo_text_extents(cr,buffer,&extents); | ||
169 | + rect->width = ((int) extents.width + 2); | ||
170 | + rect->x -= rect->width; | ||
171 | +} | ||
172 | + | ||
173 | +static void setup_spinner_position(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, G_GNUC_UNUSED cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
174 | +{ | ||
175 | + rect->width = rect->height; | ||
176 | + rect->x -= rect->width; | ||
177 | +// draw_spinner(cr,rect,color,0); | ||
178 | +} | ||
179 | + | ||
180 | +static void setup_luname_position(GdkRectangle *rect, v3270FontInfo *font, cairo_t *cr, H3270 *host, G_GNUC_UNUSED int cols, GdkRGBA *color) | ||
181 | +{ | ||
182 | + const char *luname = lib3270_get_luname(host); | ||
183 | + | ||
184 | + rect->width *= 16; | ||
185 | + rect->x -= rect->width; | ||
186 | + | ||
187 | + cairo_save(cr); | ||
188 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
189 | + cairo_clip(cr); | ||
190 | + | ||
191 | +#ifdef DEBUG | ||
192 | + cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
193 | +#else | ||
194 | + gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); | ||
195 | +#endif | ||
196 | + | ||
197 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
198 | + cairo_fill(cr); | ||
199 | + | ||
200 | + if(luname) | ||
201 | + { | ||
202 | + gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_LUNAME); | ||
203 | + v3270_draw_text(cr,rect,font,luname); | ||
204 | + } | ||
205 | + | ||
206 | + cairo_restore(cr); | ||
207 | + | ||
208 | +} | ||
209 | + | ||
210 | +static void setup_single_char_right(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, G_GNUC_UNUSED cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
211 | +{ | ||
212 | + rect->x -= rect->width; | ||
213 | + | ||
214 | + /* | ||
215 | +#ifdef DEBUG | ||
216 | + cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
217 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
218 | + cairo_fill(cr); | ||
219 | +#endif | ||
220 | +*/ | ||
221 | + | ||
222 | +} | ||
223 | + | ||
224 | +static void setup_insert_position(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
225 | +{ | ||
226 | + if(rect->width > rect->height) | ||
227 | + { | ||
228 | + rect->width = rect->height; | ||
229 | + } | ||
230 | + else if(rect->height > rect->width) | ||
231 | + { | ||
232 | + rect->y += (rect->height - rect->width)/2; | ||
233 | + rect->height = rect->width; | ||
234 | + } | ||
235 | + | ||
236 | + rect->x -= rect->width; | ||
237 | + | ||
238 | +#ifdef DEBUG | ||
239 | + cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
240 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
241 | + cairo_fill(cr); | ||
242 | +#endif | ||
243 | + | ||
244 | +} | ||
245 | + | ||
246 | + | ||
247 | + | ||
248 | +static void setup_double_char_position(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
249 | +{ | ||
250 | + rect->width <<= 1; | ||
251 | + rect->x -= rect->width; | ||
252 | + | ||
253 | +#ifdef DEBUG | ||
254 | + cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
255 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
256 | + cairo_fill(cr); | ||
257 | +#endif | ||
258 | + | ||
259 | +} | ||
260 | + | ||
261 | +static int draw_centered_char(cairo_t *cr, v3270FontInfo *metrics, int x, int y, const gchar chr) | ||
262 | +{ | ||
263 | + char str[2] = { chr, 0 }; | ||
264 | +// cairo_text_extents_t extents; | ||
265 | + | ||
266 | + cairo_set_scaled_font(cr,metrics->scaled); | ||
267 | +// cairo_text_extents(cr,str,&extents); | ||
268 | + | ||
269 | + v3270_draw_text_at(cr, x, y, metrics, str); | ||
270 | + | ||
271 | + return y+metrics->height+2; | ||
272 | + | ||
273 | +} | ||
274 | + | ||
275 | +static void draw_undera(cairo_t *cr, H3270 *host, v3270FontInfo *metrics, GdkRGBA *color, GdkRectangle *rect) | ||
276 | +{ | ||
277 | + gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); | ||
278 | + | ||
279 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
280 | + cairo_fill(cr); | ||
281 | + | ||
282 | + if(lib3270_get_undera(host)) | ||
283 | + { | ||
284 | + int y; | ||
285 | + | ||
286 | + gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_FOREGROUND); | ||
287 | + | ||
288 | + y = draw_centered_char(cr, metrics,rect->x,rect->y, lib3270_in_e(host) ? 'B' : 'A'); | ||
289 | + | ||
290 | + cairo_move_to(cr,rect->x,y); | ||
291 | + cairo_rel_line_to(cr,10,0); | ||
292 | + cairo_stroke(cr); | ||
293 | + | ||
294 | + } | ||
295 | +// debug("%s",__FUNCTION__); | ||
296 | + | ||
297 | +} | ||
298 | + | ||
299 | +void v3270_draw_connection(cairo_t *cr, H3270 *host, v3270FontInfo *metrics, GdkRGBA *color, const GdkRectangle *rect) | ||
300 | +{ | ||
301 | + gchar str = ' '; | ||
302 | + | ||
303 | + gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); | ||
304 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
305 | + cairo_fill(cr); | ||
306 | + | ||
307 | + gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_FOREGROUND); | ||
308 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
309 | + cairo_stroke(cr); | ||
310 | + | ||
311 | + if(lib3270_get_oia_box_solid(host)) | ||
312 | + { | ||
313 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
314 | + cairo_fill(cr); | ||
315 | + return; | ||
316 | + } | ||
317 | + | ||
318 | + if(lib3270_in_ansi(host)) | ||
319 | + str = 'N'; | ||
320 | + else if(lib3270_in_sscp(host)) | ||
321 | + str = 'S'; | ||
322 | + else | ||
323 | + str = '?'; | ||
324 | + | ||
325 | + draw_centered_char(cr,metrics,rect->x,rect->y,str); | ||
326 | + | ||
327 | +} | ||
328 | + | ||
329 | +static void draw_xbm(cairo_t *cr, GdkRectangle *rect, int width, int height, unsigned char *bits) | ||
330 | +{ | ||
331 | + double sz = rect->width < rect->height ? rect->width : rect->height; | ||
332 | + cairo_surface_t * icon = cairo_image_surface_create_for_data( | ||
333 | + bits, | ||
334 | + CAIRO_FORMAT_A1, | ||
335 | + width,height, | ||
336 | + cairo_format_stride_for_width(CAIRO_FORMAT_A1,width)); | ||
337 | + | ||
338 | + cairo_save(cr); | ||
339 | + | ||
340 | + cairo_scale(cr, sz / ((double) width), | ||
341 | + sz / ((double) height)); | ||
342 | + | ||
343 | + cairo_mask_surface(cr,icon,(rect->width-sz)/2,(rect->height-sz)/2); | ||
344 | + | ||
345 | + cairo_surface_destroy(icon); | ||
346 | + | ||
347 | + cairo_restore(cr); | ||
348 | +} | ||
349 | + | ||
350 | +void v3270_draw_ssl_status(v3270 *widget, cairo_t *cr, GdkRectangle *rect) | ||
351 | +{ | ||
352 | + gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_BACKGROUND); | ||
353 | + | ||
354 | + cairo_translate(cr, rect->x, rect->y); | ||
355 | + cairo_rectangle(cr, 0, 0, rect->width, rect->height); | ||
356 | + cairo_fill(cr); | ||
357 | + | ||
358 | + switch(lib3270_get_ssl_state(widget->host)) | ||
359 | + { | ||
360 | + case LIB3270_SSL_UNDEFINED: // Undefined. | ||
361 | + break; | ||
362 | + | ||
363 | + case LIB3270_SSL_UNSECURE: // No secure connection | ||
364 | + gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_FOREGROUND); | ||
365 | + draw_xbm(cr,rect,unlocked_width,unlocked_height,unlocked_bits); | ||
366 | + break; | ||
367 | + | ||
368 | + case LIB3270_SSL_NEGOTIATING: // Negotiating SSL | ||
369 | + if(widget->blink.show) | ||
370 | + { | ||
371 | + gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_STATUS_WARNING); | ||
372 | + draw_xbm(cr,rect,negotiated_width,negotiated_height,negotiated_bits); | ||
373 | + } | ||
374 | + break; | ||
375 | + | ||
376 | + case LIB3270_SSL_NEGOTIATED: // Connection secure, no CA, self-signed or expired CRL | ||
377 | + gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_STATUS_OK); | ||
378 | + draw_xbm(cr,rect,locked_width,locked_height,locked_bits); | ||
379 | + gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_STATUS_WARNING); | ||
380 | + draw_xbm(cr,rect,warning_width,warning_height,warning_bits); | ||
381 | + break; | ||
382 | + | ||
383 | + case LIB3270_SSL_SECURE: // Connection secure with CA check | ||
384 | + gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_STATUS_OK); | ||
385 | + draw_xbm(cr,rect,locked_width,locked_height,locked_bits); | ||
386 | + break; | ||
387 | + | ||
388 | + } | ||
389 | + | ||
390 | + | ||
391 | +} | ||
392 | + | ||
393 | +static void draw_status_message(cairo_t *cr, LIB3270_MESSAGE id, v3270FontInfo *font, GdkRGBA *color, const GdkRectangle *r) | ||
394 | +{ | ||
395 | + #ifdef DEBUG | ||
396 | + #define OIA_MESSAGE(x,c,y) { #x, c, y } | ||
397 | + #else | ||
398 | + #define OIA_MESSAGE(x,c,y) { c, y } | ||
399 | + #endif | ||
400 | + | ||
401 | + static const struct _message | ||
402 | + { | ||
403 | + #ifdef DEBUG | ||
404 | + const gchar * dbg; | ||
405 | + #endif | ||
406 | + enum V3270_COLOR | ||
407 | + color; | ||
408 | + const gchar * msg; | ||
409 | + } message[] = | ||
410 | + { | ||
411 | + OIA_MESSAGE( LIB3270_MESSAGE_NONE, | ||
412 | + V3270_COLOR_OIA_STATUS_OK, | ||
413 | + NULL ), | ||
414 | + | ||
415 | + OIA_MESSAGE( LIB3270_MESSAGE_SYSWAIT, | ||
416 | + V3270_COLOR_OIA_STATUS_OK, | ||
417 | + N_( "X System" ) ), | ||
418 | + | ||
419 | + OIA_MESSAGE( LIB3270_MESSAGE_TWAIT, | ||
420 | + V3270_COLOR_OIA_STATUS_OK, | ||
421 | + N_( "X Wait" ) ), | ||
422 | + | ||
423 | + OIA_MESSAGE( LIB3270_MESSAGE_CONNECTED, | ||
424 | + V3270_COLOR_OIA_STATUS_OK, | ||
425 | + NULL ), | ||
426 | + | ||
427 | + OIA_MESSAGE( LIB3270_MESSAGE_DISCONNECTED, | ||
428 | + V3270_COLOR_OIA_STATUS_INVALID, | ||
429 | + N_( "X Not Connected" ) ), | ||
430 | + | ||
431 | + OIA_MESSAGE( LIB3270_MESSAGE_AWAITING_FIRST, | ||
432 | + V3270_COLOR_OIA_STATUS_OK, | ||
433 | + N_( "X" ) ), | ||
434 | + | ||
435 | + OIA_MESSAGE( LIB3270_MESSAGE_MINUS, | ||
436 | + V3270_COLOR_OIA_STATUS_OK, | ||
437 | + N_( "X -f" ) ), | ||
438 | + | ||
439 | + OIA_MESSAGE( LIB3270_MESSAGE_PROTECTED, | ||
440 | + V3270_COLOR_OIA_STATUS_INVALID, | ||
441 | + N_( "X Protected" ) ), | ||
442 | + | ||
443 | + OIA_MESSAGE( LIB3270_MESSAGE_NUMERIC, | ||
444 | + V3270_COLOR_OIA_STATUS_INVALID, | ||
445 | + N_( "X Numeric" ) ), | ||
446 | + | ||
447 | + OIA_MESSAGE( LIB3270_MESSAGE_OVERFLOW, | ||
448 | + V3270_COLOR_OIA_STATUS_INVALID, | ||
449 | + N_( "X Overflow" ) ), | ||
450 | + | ||
451 | + OIA_MESSAGE( LIB3270_MESSAGE_INHIBIT, | ||
452 | + V3270_COLOR_OIA_STATUS_INVALID, | ||
453 | + N_( "X Inhibit" ) ), | ||
454 | + | ||
455 | + OIA_MESSAGE( LIB3270_MESSAGE_KYBDLOCK, | ||
456 | + V3270_COLOR_OIA_STATUS_INVALID, | ||
457 | + N_( "X") ), | ||
458 | + | ||
459 | + OIA_MESSAGE( LIB3270_MESSAGE_X, | ||
460 | + V3270_COLOR_OIA_STATUS_INVALID, | ||
461 | + N_( "X" ) ), | ||
462 | + | ||
463 | + OIA_MESSAGE( LIB3270_MESSAGE_RESOLVING, | ||
464 | + V3270_COLOR_OIA_STATUS_WARNING, | ||
465 | + N_( "X Resolving" ) ), | ||
466 | + | ||
467 | + OIA_MESSAGE( LIB3270_MESSAGE_CONNECTING, | ||
468 | + V3270_COLOR_OIA_STATUS_WARNING, | ||
469 | + N_( "X Connecting" ) ), | ||
470 | + | ||
471 | + | ||
472 | + }; | ||
473 | + | ||
474 | + GdkRectangle rect; | ||
475 | + const gchar * msg = message[0].msg; | ||
476 | + | ||
477 | + memcpy(&rect,r,sizeof(GdkRectangle)); | ||
478 | + | ||
479 | + if(id >= 0 && id < G_N_ELEMENTS(message)) | ||
480 | + { | ||
481 | + msg = message[id].msg; | ||
482 | +#ifdef DEBUG | ||
483 | + if(!msg) | ||
484 | + msg = message[id].dbg; | ||
485 | +#endif // DEBUG | ||
486 | + } | ||
487 | + | ||
488 | + // Limpa o bloco | ||
489 | + gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); | ||
490 | + cairo_rectangle(cr, rect.x, rect.y, rect.width, rect.height); | ||
491 | + cairo_fill(cr); | ||
492 | + | ||
493 | + if(msg && *msg) | ||
494 | + { | ||
495 | + msg = gettext(msg); | ||
496 | + } | ||
497 | + | ||
498 | + if(msg && *msg) | ||
499 | + { | ||
500 | + rect.x++; | ||
501 | + | ||
502 | +// debug("%s(%s)",__FUNCTION__,msg); | ||
503 | + | ||
504 | + gdk_cairo_set_source_rgba(cr,color+message[id].color); | ||
505 | + | ||
506 | + if(*msg == 'X') | ||
507 | + { | ||
508 | + cairo_save(cr); | ||
509 | + | ||
510 | + cairo_move_to(cr,rect.x+1,rect.y+(font->height)-(font->ascent)); | ||
511 | + cairo_rel_line_to(cr,font->width,font->ascent); | ||
512 | + cairo_rel_move_to(cr,-font->width,0); | ||
513 | + cairo_rel_line_to(cr,font->width,-font->ascent); | ||
514 | + | ||
515 | + cairo_stroke(cr); | ||
516 | + rect.x += font->width; | ||
517 | + msg++; | ||
518 | + | ||
519 | + cairo_restore(cr); | ||
520 | + } | ||
521 | + | ||
522 | + while(isspace(*msg)) | ||
523 | + { | ||
524 | + msg++; | ||
525 | + rect.x += font->width; | ||
526 | + } | ||
527 | + | ||
528 | + if(*msg) | ||
529 | + { | ||
530 | + v3270_draw_text(cr,&rect, font, msg); | ||
531 | +// cairo_move_to(cr,x,rect->y+metrics->height); | ||
532 | +// cairo_show_text(cr,msg); | ||
533 | + } | ||
534 | + | ||
535 | + } | ||
536 | + | ||
537 | +} | ||
538 | + | ||
539 | +static void draw_insert(cairo_t *cr, H3270 *host, GdkRGBA *color, GdkRectangle *rect) | ||
540 | +{ | ||
541 | + if(lib3270_get_toggle(host,LIB3270_TOGGLE_INSERT)) | ||
542 | + { | ||
543 | + double y = rect->y+(rect->height-2); | ||
544 | + | ||
545 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
546 | + cairo_clip(cr); | ||
547 | + | ||
548 | + gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_FOREGROUND); | ||
549 | + | ||
550 | + cairo_move_to(cr,rect->x,y); | ||
551 | + cairo_rel_line_to(cr,rect->width/2,-(rect->height/1.7)); | ||
552 | + cairo_line_to(cr,rect->x+rect->width,y); | ||
553 | + cairo_stroke(cr); | ||
554 | + } | ||
555 | + | ||
556 | +} | ||
557 | + | ||
558 | +// v3270_draw_oia(cr, terminal->host, rect.y, cols, &terminal->font, terminal->color,terminal->oia_rect); | ||
559 | +// void v3270_draw_oia(cairo_t *cr, H3270 *host, int row, int cols, v3270FontInfo *metrics, GdkRGBA *color, GdkRectangle *rect) | ||
560 | + | ||
561 | +void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols) | ||
562 | +{ | ||
563 | + static const struct _right_fields | ||
564 | + { | ||
565 | + V3270_OIA_FIELD id; | ||
566 | + void (*draw)(GdkRectangle *rect, v3270FontInfo *metrics, cairo_t *cr, H3270 *host, int cols, GdkRGBA *color); | ||
567 | + } right[] = | ||
568 | + { | ||
569 | + { V3270_OIA_CURSOR_POSITION, setup_cursor_position }, | ||
570 | + { V3270_OIA_TIMER, setup_ticking_position }, | ||
571 | + { V3270_OIA_SPINNER, setup_spinner_position }, | ||
572 | + { V3270_OIA_LUNAME, setup_luname_position }, | ||
573 | +#ifdef HAVE_PRINTER | ||
574 | + { V3270_OIA_PRINTER, setup_single_char_right }, | ||
575 | +#endif // HAVE_PRINTER | ||
576 | + { V3270_OIA_SCRIPT, setup_single_char_right }, | ||
577 | + { V3270_OIA_INSERT, setup_insert_position }, | ||
578 | + { V3270_OIA_TYPEAHEAD, setup_single_char_right }, | ||
579 | + { V3270_OIA_SHIFT, setup_double_char_position }, | ||
580 | +// { V3270_OIA_CAPS, setup_single_char_right }, | ||
581 | + { V3270_OIA_ALT, setup_single_char_right }, | ||
582 | + { V3270_OIA_SSL, setup_double_char_position }, | ||
583 | + }; | ||
584 | + | ||
585 | + int f; | ||
586 | + int rCol = terminal->font.margin.left+(cols*terminal->font.width); | ||
587 | + int lCol = terminal->font.margin.left+1; | ||
588 | + | ||
589 | + row += OIA_TOP_MARGIN; | ||
590 | + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_SEPARATOR); | ||
591 | + cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, 1); | ||
592 | + cairo_fill(cr); | ||
593 | + | ||
594 | + row += 2; | ||
595 | + | ||
596 | + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
597 | + cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, terminal->font.spacing); | ||
598 | + cairo_fill(cr); | ||
599 | + | ||
600 | + for(f=0;f< (int) G_N_ELEMENTS(right);f++) | ||
601 | + { | ||
602 | + GdkRectangle *r = terminal->oia.rect+right[f].id; | ||
603 | + | ||
604 | + memset(r,0,sizeof(GdkRectangle)); | ||
605 | + r->x = rCol; | ||
606 | + r->y = row; | ||
607 | + r->width = terminal->font.width; | ||
608 | + r->height = terminal->font.spacing; | ||
609 | + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
610 | + right[f].draw(r,&terminal->font,cr,terminal->host,cols,terminal->color); | ||
611 | + rCol = r->x - (terminal->font.width/3); | ||
612 | + } | ||
613 | + | ||
614 | + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
615 | + | ||
616 | + draw_centered_char(cr,&terminal->font,lCol,row,'4'); | ||
617 | + | ||
618 | + cairo_stroke(cr); | ||
619 | + cairo_rectangle(cr, lCol, row, terminal->font.width+2, terminal->font.spacing); | ||
620 | + cairo_stroke(cr); | ||
621 | + | ||
622 | + lCol += (terminal->font.width+5); | ||
623 | + | ||
624 | + // Undera indicator | ||
625 | + terminal->oia.rect[V3270_OIA_UNDERA].x = lCol; | ||
626 | + terminal->oia.rect[V3270_OIA_UNDERA].y = row; | ||
627 | + terminal->oia.rect[V3270_OIA_UNDERA].width = terminal->font.width+3; | ||
628 | + terminal->oia.rect[V3270_OIA_UNDERA].height = terminal->font.spacing; | ||
629 | + draw_undera(cr,terminal->host,&terminal->font,terminal->color,terminal->oia.rect+V3270_OIA_UNDERA); | ||
630 | + | ||
631 | + lCol += (3 + terminal->oia.rect[V3270_OIA_UNDERA].width); | ||
632 | + | ||
633 | + // Connection indicator | ||
634 | + terminal->oia.rect[V3270_OIA_CONNECTION].x = lCol; | ||
635 | + terminal->oia.rect[V3270_OIA_CONNECTION].y = row; | ||
636 | + terminal->oia.rect[V3270_OIA_CONNECTION].width = terminal->font.width+3; | ||
637 | + terminal->oia.rect[V3270_OIA_CONNECTION].height = terminal->font.spacing; | ||
638 | + v3270_draw_connection(cr,terminal->host,&terminal->font,terminal->color,terminal->oia.rect+V3270_OIA_CONNECTION); | ||
639 | + | ||
640 | + lCol += (4 + terminal->oia.rect[V3270_OIA_CONNECTION].width); | ||
641 | + | ||
642 | + memset(terminal->oia.rect+V3270_OIA_MESSAGE,0,sizeof(GdkRectangle)); | ||
643 | + | ||
644 | + if(lCol < rCol) | ||
645 | + { | ||
646 | + GdkRectangle *r = terminal->oia.rect+V3270_OIA_MESSAGE; | ||
647 | + r->x = lCol; | ||
648 | + r->y = row; | ||
649 | + r->width = rCol - lCol; | ||
650 | + r->height = terminal->font.spacing; | ||
651 | + draw_status_message(cr,lib3270_get_program_message(terminal->host),&terminal->font,terminal->color,r); | ||
652 | + } | ||
653 | + | ||
654 | + cairo_save(cr); | ||
655 | +// v3270_draw_ssl_status(cr,terminal->host,&terminal->font,terminal->color,terminal->oia.rect+V3270_OIA_SSL); | ||
656 | + v3270_draw_ssl_status(terminal,cr,terminal->oia.rect+V3270_OIA_SSL); | ||
657 | + cairo_restore(cr); | ||
658 | + | ||
659 | + cairo_save(cr); | ||
660 | + draw_insert(cr,terminal->host,terminal->color,terminal->oia.rect+V3270_OIA_INSERT); | ||
661 | + cairo_restore(cr); | ||
662 | +} | ||
663 | + | ||
664 | +/** | ||
665 | + * Begin update of a specific OIA field. | ||
666 | + * | ||
667 | + * @param terminal 3270 terminal widget. | ||
668 | + * @param r Rectangle to receive updated region. | ||
669 | + * @param id Field id. | ||
670 | + * | ||
671 | + * @return cairo object for drawing. | ||
672 | + * | ||
673 | + */ | ||
674 | +cairo_t * v3270_oia_set_update_region(v3270 * terminal, GdkRectangle **r, V3270_OIA_FIELD id) | ||
675 | +{ | ||
676 | + GdkRectangle * rect = terminal->oia.rect + id; | ||
677 | + cairo_t * cr = cairo_create(terminal->surface); | ||
678 | + | ||
679 | + cairo_set_scaled_font(cr,terminal->font.scaled); | ||
680 | + | ||
681 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
682 | + cairo_clip(cr); | ||
683 | + | ||
684 | + *r = rect; | ||
685 | + | ||
686 | +#ifdef DEBUG | ||
687 | + cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
688 | +#else | ||
689 | + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
690 | +#endif | ||
691 | + | ||
692 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
693 | + cairo_fill(cr); | ||
694 | + | ||
695 | + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
696 | + | ||
697 | + return cr; | ||
698 | +} | ||
699 | + | ||
700 | +void v3270_update_luname(GtkWidget *widget,const gchar *name) | ||
701 | +{ | ||
702 | + cairo_t * cr; | ||
703 | + GdkRectangle * rect; | ||
704 | + v3270 * terminal = GTK_V3270(widget); | ||
705 | + | ||
706 | + if(terminal->surface) | ||
707 | + { | ||
708 | + cr = v3270_oia_set_update_region(terminal,&rect,V3270_OIA_LUNAME); | ||
709 | + | ||
710 | + if(name) | ||
711 | + { | ||
712 | +// cairo_move_to(cr,rect->x,rect->y+terminal->font.height); | ||
713 | +// cairo_show_text(cr,name); | ||
714 | +// cairo_stroke(cr); | ||
715 | + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_LUNAME); | ||
716 | + v3270_draw_text_at(cr, rect->x, rect->y, &terminal->font, name); | ||
717 | + | ||
718 | + } | ||
719 | + | ||
720 | + cairo_destroy(cr); | ||
721 | + | ||
722 | + v3270_queue_draw_area(GTK_WIDGET(terminal),rect->x,rect->y,rect->width,rect->height); | ||
723 | + } | ||
724 | + | ||
725 | + g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.luname); | ||
726 | + | ||
727 | +} | ||
728 | + | ||
729 | +void v3270_update_message(v3270 *widget, LIB3270_MESSAGE id) | ||
730 | +{ | ||
731 | + cairo_t * cr; | ||
732 | + GdkRectangle * rect; | ||
733 | + | ||
734 | + if(!widget->surface) | ||
735 | + return; | ||
736 | + | ||
737 | + cr = v3270_oia_set_update_region(widget,&rect,V3270_OIA_MESSAGE); | ||
738 | + | ||
739 | + draw_status_message(cr,id,&widget->font,widget->color,rect); | ||
740 | + | ||
741 | + cairo_destroy(cr); | ||
742 | + | ||
743 | + v3270_queue_draw_area(GTK_WIDGET(widget),rect->x,rect->y,rect->width,rect->height); | ||
744 | + | ||
745 | + if(widget->accessible) | ||
746 | + v3270_acessible_set_state(widget->accessible,id); | ||
747 | + | ||
748 | +} | ||
749 | + | ||
750 | +static void draw_cursor_position(cairo_t *cr, GdkRectangle *rect, v3270FontInfo *metrics, int row, int col) | ||
751 | +{ | ||
752 | + cairo_text_extents_t extents; | ||
753 | + char buffer[10]; | ||
754 | + | ||
755 | + short2string(buffer,row+1,3); | ||
756 | + buffer[3] = '/'; | ||
757 | + short2string(buffer+4,col+1,3); | ||
758 | + buffer[7] = 0; | ||
759 | + | ||
760 | + cairo_text_extents(cr,buffer,&extents); | ||
761 | + v3270_draw_text_at(cr,(rect->x+rect->width)-(extents.width+2),rect->y,metrics,buffer); | ||
762 | +} | ||
763 | + | ||
764 | +void v3270_update_cursor(H3270 *session, unsigned short row, unsigned short col, unsigned char c, unsigned short attr) | ||
765 | +{ | ||
766 | + v3270 * terminal = GTK_V3270(lib3270_get_user_data(session)); | ||
767 | + GdkRectangle saved; | ||
768 | + | ||
769 | + if(!terminal->surface) | ||
770 | + return; | ||
771 | + | ||
772 | + // Update cursor rectangle | ||
773 | + saved = terminal->cursor.rect; | ||
774 | + | ||
775 | + terminal->cursor.rect.x = terminal->font.margin.left + (col * terminal->cursor.rect.width); | ||
776 | + terminal->cursor.rect.y = terminal->font.margin.top + (row * terminal->font.spacing); | ||
777 | + terminal->cursor.rect.width = terminal->font.width; | ||
778 | + terminal->cursor.rect.height = terminal->font.height+terminal->font.descent; | ||
779 | + terminal->cursor.show |= 1; | ||
780 | + | ||
781 | + v3270_queue_draw_area( GTK_WIDGET(terminal), saved.x, | ||
782 | + saved.y, | ||
783 | + saved.width, | ||
784 | + saved.height); | ||
785 | + | ||
786 | + | ||
787 | + v3270_update_cursor_surface(terminal,c,attr); | ||
788 | + | ||
789 | + v3270_queue_draw_area( GTK_WIDGET(terminal), | ||
790 | + terminal->cursor.rect.x,terminal->cursor.rect.y, | ||
791 | + terminal->cursor.rect.width,terminal->cursor.rect.height); | ||
792 | + | ||
793 | + if(lib3270_get_toggle(session,LIB3270_TOGGLE_CROSSHAIR)) | ||
794 | + { | ||
795 | + GtkAllocation allocation; | ||
796 | + gtk_widget_get_allocation(GTK_WIDGET(terminal), &allocation); | ||
797 | + | ||
798 | + v3270_queue_draw_area(GTK_WIDGET(terminal),0,saved.y+terminal->font.height,allocation.width,1); | ||
799 | + v3270_queue_draw_area(GTK_WIDGET(terminal),saved.x,0,1,terminal->oia.rect->y-3); | ||
800 | + | ||
801 | + v3270_queue_draw_area(GTK_WIDGET(terminal),0,terminal->cursor.rect.y+terminal->font.height,allocation.width,1); | ||
802 | + v3270_queue_draw_area(GTK_WIDGET(terminal),terminal->cursor.rect.x,0,1,terminal->oia.rect->y-3); | ||
803 | + } | ||
804 | + | ||
805 | + if(lib3270_get_toggle(session,LIB3270_TOGGLE_CURSOR_POS)) | ||
806 | + { | ||
807 | + // Update OIA | ||
808 | + GdkRectangle * rect; | ||
809 | + cairo_t * cr; | ||
810 | + | ||
811 | + cr = v3270_oia_set_update_region(terminal,&rect,V3270_OIA_CURSOR_POSITION); | ||
812 | + | ||
813 | + draw_cursor_position(cr,rect,&terminal->font,row,col); | ||
814 | + | ||
815 | + cairo_destroy(cr); | ||
816 | + | ||
817 | + v3270_queue_draw_area(GTK_WIDGET(terminal),rect->x,rect->y,rect->width,rect->height); | ||
818 | + } | ||
819 | + | ||
820 | + if(terminal->accessible) | ||
821 | + g_signal_emit_by_name(ATK_TEXT(terminal->accessible),"text-caret-moved",lib3270_get_cursor_address(session)); | ||
822 | + | ||
823 | +} | ||
824 | + | ||
825 | +struct timer_info | ||
826 | +{ | ||
827 | + time_t start; | ||
828 | + time_t last; | ||
829 | +#ifdef HAVE_LIBM | ||
830 | + gint step; | ||
831 | +#endif // HAVE_LIBM | ||
832 | + v3270 * terminal; | ||
833 | +}; | ||
834 | + | ||
835 | +static void release_timer(struct timer_info *info) | ||
836 | +{ | ||
837 | + info->terminal->timer = NULL; | ||
838 | + | ||
839 | + if(info->terminal->surface) | ||
840 | + { | ||
841 | + // Erase timer info | ||
842 | + static const int id[] = { V3270_OIA_TIMER, | ||
843 | +#ifdef HAVE_LIBM | ||
844 | + V3270_OIA_SPINNER | ||
845 | +#endif // HAVE_LIBM | ||
846 | + }; | ||
847 | + int f; | ||
848 | + | ||
849 | + cairo_t *cr = cairo_create(info->terminal->surface); | ||
850 | + | ||
851 | +#ifdef DEBUG | ||
852 | + cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
853 | +#else | ||
854 | + gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
855 | +#endif | ||
856 | + | ||
857 | + for(f=0;f< (int) G_N_ELEMENTS(id);f++) | ||
858 | + { | ||
859 | + GdkRectangle *rect = info->terminal->oia.rect + id[f]; | ||
860 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
861 | + cairo_fill(cr); | ||
862 | + v3270_queue_draw_area(GTK_WIDGET(info->terminal),rect->x,rect->y,rect->width,rect->height); | ||
863 | + } | ||
864 | + cairo_destroy(cr); | ||
865 | + } | ||
866 | + | ||
867 | + g_free(info); | ||
868 | +} | ||
869 | + | ||
870 | +void v3270_draw_shift_status(v3270 *terminal) | ||
871 | +{ | ||
872 | + GdkRectangle *r; | ||
873 | + cairo_t *cr; | ||
874 | + | ||
875 | + if(!terminal->surface) | ||
876 | + return; | ||
877 | + | ||
878 | + cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_SHIFT); | ||
879 | + cairo_translate(cr, r->x, r->y+1); | ||
880 | + | ||
881 | + if(r->width > 2 && r->height > 7 && (terminal->keyflags & KEY_FLAG_SHIFT)) | ||
882 | + { | ||
883 | + int b,x,y,w,h,l; | ||
884 | + int height = r->height-6; | ||
885 | + | ||
886 | + if(height > r->width) | ||
887 | + { | ||
888 | + w = r->width; | ||
889 | + h = w*1.5; | ||
890 | + } | ||
891 | + else // width > height | ||
892 | + { | ||
893 | + h = height; | ||
894 | + w = h/1.5; | ||
895 | + } | ||
896 | + | ||
897 | + // Set image position | ||
898 | + x = (r->width - w)/2; | ||
899 | + y = (height - h)/2; | ||
900 | + l = (w/3); | ||
901 | + b = y+(w/1.5); | ||
902 | + | ||
903 | + cairo_move_to(cr,x+(w/2),y); | ||
904 | + cairo_line_to(cr,x+w,b); | ||
905 | + cairo_line_to(cr,(x+w)-l,b); | ||
906 | + cairo_line_to(cr,(x+w)-l,y+h); | ||
907 | + cairo_line_to(cr,x+l,y+h); | ||
908 | + cairo_line_to(cr,x+l,b); | ||
909 | + cairo_line_to(cr,x,b); | ||
910 | + cairo_close_path(cr); | ||
911 | + | ||
912 | + cairo_stroke(cr); | ||
913 | + | ||
914 | + } | ||
915 | + | ||
916 | + cairo_destroy(cr); | ||
917 | + v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
918 | + | ||
919 | +} | ||
920 | + | ||
921 | +void v3270_oia_update_text_field(v3270 *terminal, gboolean flag, V3270_OIA_FIELD id, const gchar chr) | ||
922 | +{ | ||
923 | + GdkRectangle * r; | ||
924 | + cairo_t * cr; | ||
925 | + gchar text[] = { chr, 0 }; | ||
926 | + | ||
927 | + if(!terminal->surface) | ||
928 | + return; | ||
929 | + | ||
930 | + cr = v3270_oia_set_update_region(terminal,&r,id); | ||
931 | + cairo_translate(cr, r->x, r->y); | ||
932 | + | ||
933 | + if(flag) | ||
934 | + { | ||
935 | + v3270_draw_text_at(cr,0,0,&terminal->font,text); | ||
936 | +// cairo_move_to(cr,0,terminal->font.height); | ||
937 | +// cairo_show_text(cr, text); | ||
938 | +// cairo_stroke(cr); | ||
939 | + } | ||
940 | + | ||
941 | + cairo_destroy(cr); | ||
942 | + v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
943 | +} | ||
944 | + | ||
945 | +#ifdef KEY_FLAG_ALT | ||
946 | +void v3270_draw_alt_status(v3270 *terminal) | ||
947 | +{ | ||
948 | + v3270_oia_update_text_field(terminal,terminal->keyflags & KEY_FLAG_ALT,V3270_OIA_ALT,'A'); | ||
949 | +} | ||
950 | +#else | ||
951 | +void v3270_draw_alt_status(v3270 G_GNUC_UNUSED(*terminal)) | ||
952 | +{ | ||
953 | +} | ||
954 | +#endif // KEY_FLAG_ALT | ||
955 | + | ||
956 | +void v3270_draw_ins_status(v3270 *terminal) | ||
957 | +{ | ||
958 | + GdkRectangle *r; | ||
959 | + cairo_t *cr; | ||
960 | + | ||
961 | + if(!terminal->surface) | ||
962 | + return; | ||
963 | + | ||
964 | + cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_INSERT); | ||
965 | + | ||
966 | + draw_insert(cr,terminal->host,terminal->color,r); | ||
967 | + | ||
968 | + cairo_destroy(cr); | ||
969 | + v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
970 | + | ||
971 | +} | ||
972 | + | ||
973 | +static gboolean update_timer(struct timer_info *info) | ||
974 | +{ | ||
975 | + cairo_t * cr; | ||
976 | + time_t now = time(0); | ||
977 | + GdkRectangle * rect; | ||
978 | + | ||
979 | +// debug("%s %p",__FUNCTION__,info->terminal->surface); | ||
980 | + if(!info->terminal->surface) | ||
981 | + return TRUE; | ||
982 | + | ||
983 | + cr = cairo_create(info->terminal->surface); | ||
984 | + | ||
985 | + if(now != info->last) | ||
986 | + { | ||
987 | + time_t seconds = now - info->start; | ||
988 | + char buffer[7]; | ||
989 | + | ||
990 | + rect = info->terminal->oia.rect + V3270_OIA_TIMER; | ||
991 | + | ||
992 | + gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
993 | + | ||
994 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
995 | + cairo_fill(cr); | ||
996 | + | ||
997 | + gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
998 | + | ||
999 | + short2string(buffer,seconds/60,2); | ||
1000 | + buffer[2] = ':'; | ||
1001 | + short2string(buffer+3,seconds%60,2); | ||
1002 | + buffer[5] = 0; | ||
1003 | + | ||
1004 | + cairo_set_scaled_font(cr,info->terminal->font.scaled); | ||
1005 | +// cairo_move_to(cr,rect->x,rect->y+info->terminal->font.height); | ||
1006 | +// cairo_show_text(cr, buffer); | ||
1007 | + | ||
1008 | + v3270_draw_text(cr, rect, &info->terminal->font, buffer); | ||
1009 | + | ||
1010 | + cairo_stroke(cr); | ||
1011 | + | ||
1012 | + info->last = now; | ||
1013 | + v3270_queue_draw_area(GTK_WIDGET(info->terminal),rect->x,rect->y,rect->width,rect->height); | ||
1014 | + } | ||
1015 | + | ||
1016 | +#ifdef HAVE_LIBM | ||
1017 | + | ||
1018 | + rect = info->terminal->oia.rect + V3270_OIA_SPINNER; | ||
1019 | + | ||
1020 | +#ifdef DEBUG | ||
1021 | + cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
1022 | +#else | ||
1023 | + gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
1024 | +#endif | ||
1025 | + | ||
1026 | + cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
1027 | + cairo_fill(cr); | ||
1028 | + | ||
1029 | + gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
1030 | + | ||
1031 | + info->step = draw_spinner(cr, rect, info->terminal->color, info->step); | ||
1032 | + | ||
1033 | + v3270_queue_draw_area(GTK_WIDGET(info->terminal),rect->x,rect->y,rect->width,rect->height); | ||
1034 | + | ||
1035 | +#endif // HAVE_LIBM | ||
1036 | + | ||
1037 | + cairo_destroy(cr); | ||
1038 | + | ||
1039 | + return TRUE; | ||
1040 | +} | ||
1041 | + | ||
1042 | +void v3270_start_timer(GtkWidget *widget) | ||
1043 | +{ | ||
1044 | + struct timer_info *info; | ||
1045 | + v3270 *terminal = GTK_V3270(widget); | ||
1046 | + | ||
1047 | + if(terminal->timer) | ||
1048 | + { | ||
1049 | + g_source_ref(terminal->timer); | ||
1050 | + return; | ||
1051 | + } | ||
1052 | + | ||
1053 | + info = g_new0(struct timer_info,1); | ||
1054 | + info->terminal = terminal; | ||
1055 | + info->start = time(0); | ||
1056 | + | ||
1057 | + update_timer(info); | ||
1058 | + | ||
1059 | + terminal->timer = g_timeout_source_new(100); | ||
1060 | + g_source_set_callback(terminal->timer,(GSourceFunc) update_timer, info, (GDestroyNotify) release_timer); | ||
1061 | + | ||
1062 | + g_source_attach(terminal->timer,NULL); | ||
1063 | + g_source_unref(terminal->timer); | ||
1064 | + | ||
1065 | +} | ||
1066 | + | ||
1067 | +void v3270_stop_timer(GtkWidget *widget) | ||
1068 | +{ | ||
1069 | + v3270 *terminal = GTK_V3270(widget); | ||
1070 | + | ||
1071 | + if(terminal->timer) | ||
1072 | + { | ||
1073 | + if(terminal->timer->ref_count < 2) | ||
1074 | + { | ||
1075 | + g_source_destroy(terminal->timer); | ||
1076 | + } | ||
1077 | + else | ||
1078 | + { | ||
1079 | + g_source_unref(terminal->timer); | ||
1080 | + } | ||
1081 | + } | ||
1082 | + | ||
1083 | +} | ||
1084 | + | ||
1085 | +void v3270_blink_ssl(v3270 *terminal) | ||
1086 | +{ | ||
1087 | + if(terminal->surface) | ||
1088 | + { | ||
1089 | + GdkRectangle * r; | ||
1090 | + cairo_t * cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_SSL); | ||
1091 | + | ||
1092 | + v3270_draw_ssl_status(terminal,cr,r); | ||
1093 | + v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
1094 | + cairo_destroy(cr); | ||
1095 | + | ||
1096 | + } | ||
1097 | + | ||
1098 | +} | ||
1099 | + | ||
1100 | +void v3270_update_oia(v3270 *terminal, LIB3270_FLAG id, unsigned char on) | ||
1101 | +{ | ||
1102 | + cairo_t *cr; | ||
1103 | + GdkRectangle *r; | ||
1104 | + | ||
1105 | + if(!(terminal->surface && terminal->drawing)) | ||
1106 | + return; | ||
1107 | + | ||
1108 | + #pragma GCC diagnostic push | ||
1109 | + #pragma GCC diagnostic ignored "-Wswitch" | ||
1110 | + switch(id) | ||
1111 | + { | ||
1112 | + case LIB3270_FLAG_BOXSOLID: | ||
1113 | +// debug("%s LIB3270_FLAG_BOXSOLID",__FUNCTION__); | ||
1114 | + cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_CONNECTION); | ||
1115 | + v3270_draw_connection(cr,terminal->host,&terminal->font,terminal->color,r); | ||
1116 | + cairo_destroy(cr); | ||
1117 | + v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
1118 | + break; | ||
1119 | + | ||
1120 | + case LIB3270_FLAG_UNDERA: | ||
1121 | +// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1122 | + cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_UNDERA); | ||
1123 | +// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1124 | + draw_undera(cr,terminal->host,&terminal->font,terminal->color,r); | ||
1125 | +// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1126 | + cairo_destroy(cr); | ||
1127 | +// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1128 | + v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
1129 | +// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1130 | + break; | ||
1131 | + | ||
1132 | + case LIB3270_FLAG_TYPEAHEAD: | ||
1133 | +// debug("%s LIB3270_FLAG_TYPEAHEAD",__FUNCTION__); | ||
1134 | + v3270_oia_update_text_field(terminal,on,V3270_OIA_TYPEAHEAD,'T'); | ||
1135 | + break; | ||
1136 | + | ||
1137 | +#ifdef HAVE_PRINTER | ||
1138 | + case LIB3270_FLAG_PRINTER: | ||
1139 | +// debug("%s LIB3270_FLAG_PRINTER",__FUNCTION__); | ||
1140 | + v3270_oia_update_text_field(terminal,on,V3270_OIA_PRINTER,'P'); | ||
1141 | + break; | ||
1142 | +#endif // HAVE_PRINTER | ||
1143 | + | ||
1144 | +/* | ||
1145 | + case LIB3270_FLAG_SCRIPT: | ||
1146 | + v3270_oia_update_text_field(terminal,on,V3270_OIA_SCRIPT,terminal->script_id); | ||
1147 | + break; | ||
1148 | +*/ | ||
1149 | + | ||
1150 | + } | ||
1151 | + #pragma GCC diagnostic pop | ||
1152 | + | ||
1153 | +} | ||
1154 | + | ||
1155 | +int v3270_set_script(GtkWidget *widget, const gchar id) | ||
1156 | +{ | ||
1157 | + g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); | ||
1158 | + | ||
1159 | + v3270 * terminal = GTK_V3270(widget); | ||
1160 | + | ||
1161 | + if(id && terminal->script) | ||
1162 | + return EBUSY; | ||
1163 | + | ||
1164 | + terminal->script = id; | ||
1165 | + | ||
1166 | + if(terminal->script) | ||
1167 | + v3270_start_blinking(widget); | ||
1168 | + | ||
1169 | + return 0; | ||
1170 | +} |
@@ -0,0 +1,86 @@ | @@ -0,0 +1,86 @@ | ||
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 | + #include <terminal.h> | ||
32 | + | ||
33 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
34 | + | ||
35 | +/** | ||
36 | + * @brief Reconfigure widget surface. | ||
37 | + * | ||
38 | + * Called when the widget is resized or moved to regenerate the cairo surface: | ||
39 | + * | ||
40 | + * * Recreate the surface. | ||
41 | + * * Compute the new font size & metrics. | ||
42 | + * * Redraw contents. | ||
43 | + * * Emit "GDK_CONFIGURE" event. | ||
44 | + * | ||
45 | + */ | ||
46 | +void v3270_reconfigure(v3270 * terminal) | ||
47 | +{ | ||
48 | + GtkAllocation allocation; | ||
49 | + GtkWidget *widget; | ||
50 | + GdkEvent *event = gdk_event_new(GDK_CONFIGURE); | ||
51 | + | ||
52 | + widget = GTK_WIDGET(terminal); | ||
53 | + | ||
54 | + gtk_widget_get_allocation(widget, &allocation); | ||
55 | + | ||
56 | + event->configure.window = g_object_ref(gtk_widget_get_window(widget)); | ||
57 | + event->configure.send_event = TRUE; | ||
58 | + event->configure.x = allocation.x; | ||
59 | + event->configure.y = allocation.y; | ||
60 | + event->configure.width = allocation.width; | ||
61 | + event->configure.height = allocation.height; | ||
62 | + | ||
63 | + if(terminal->surface) | ||
64 | + cairo_surface_destroy(terminal->surface); | ||
65 | + | ||
66 | + terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,allocation.width,allocation.height); | ||
67 | + | ||
68 | + // Update the created image | ||
69 | + cairo_t * cr = cairo_create(terminal->surface); | ||
70 | + v3270_compute_font_size(terminal, cr, allocation.width, allocation.height); | ||
71 | + v3270_update_font_metrics(terminal, allocation.width, allocation.height); | ||
72 | + | ||
73 | + v3270_redraw(terminal, cr, allocation.width, allocation.height); | ||
74 | + | ||
75 | + cairo_destroy(cr); | ||
76 | + | ||
77 | +#if( !GTK_CHECK_VERSION(3,0,0)) | ||
78 | + terminal->width = allocation.width; | ||
79 | + terminal->height = allocation.height; | ||
80 | +#endif | ||
81 | + | ||
82 | + gtk_widget_event(widget, event); | ||
83 | + gdk_event_free(event); | ||
84 | +} | ||
85 | + | ||
86 | + |
src/terminal/oia.c
@@ -1,1168 +0,0 @@ | @@ -1,1168 +0,0 @@ | ||
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 oia.c 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 | - | ||
32 | - #define ENABLE_NLS | ||
33 | - #define GETTEXT_PACKAGE PACKAGE_NAME | ||
34 | - | ||
35 | - #include <gtk/gtk.h> | ||
36 | - #include <libintl.h> | ||
37 | - #include <glib/gi18n.h> | ||
38 | - | ||
39 | - #ifdef WIN32 | ||
40 | - #include <winsock2.h> | ||
41 | - #include <windows.h> | ||
42 | - #include <ws2tcpip.h> | ||
43 | - #endif // WIN32 | ||
44 | - | ||
45 | - #include <lib3270.h> | ||
46 | - #include <lib3270/session.h> | ||
47 | - #include <lib3270/log.h> | ||
48 | - #include <lib3270/toggle.h> | ||
49 | - #include <config.h> | ||
50 | - #include <string.h> | ||
51 | - #include <errno.h> | ||
52 | - #include <ctype.h> | ||
53 | - | ||
54 | - #ifdef HAVE_LIBM | ||
55 | - #include <math.h> | ||
56 | - #endif // HAVE_LIBM | ||
57 | - | ||
58 | - #include <v3270.h> | ||
59 | - #include <terminal.h> | ||
60 | - #include <internals.h> | ||
61 | - #include <v3270/accessible.h> | ||
62 | - | ||
63 | -/*--[ Prototipes ]-----------------------------------------------------------------------------------*/ | ||
64 | - | ||
65 | -static void draw_cursor_position(cairo_t *cr, GdkRectangle *rect, v3270FontInfo *metrics, int row, int col); | ||
66 | - | ||
67 | -/*--[ Statics ]--------------------------------------------------------------------------------------*/ | ||
68 | - | ||
69 | - #include "xbm/locked.xbm" | ||
70 | - #include "xbm/unlocked.xbm" | ||
71 | - #include "xbm/negotiated.xbm" | ||
72 | - #include "xbm/warning.xbm" | ||
73 | - | ||
74 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
75 | - | ||
76 | -static void short2string(char *ptr, unsigned short vlr, size_t sz) | ||
77 | -{ | ||
78 | - int f; | ||
79 | - | ||
80 | - for(f=sz-1;f>=0;f--) | ||
81 | - { | ||
82 | - ptr[f] = '0'+(vlr%10); | ||
83 | - vlr /= 10; | ||
84 | - } | ||
85 | -} | ||
86 | - | ||
87 | - | ||
88 | -#ifdef HAVE_LIBM | ||
89 | -static gint draw_spinner(cairo_t *cr, GdkRectangle *r, GdkRGBA *color, gint step) | ||
90 | -{ | ||
91 | - static const guint num_steps = 10; | ||
92 | - | ||
93 | - gdouble dx = r->width/2; | ||
94 | - gdouble dy = r->height/2; | ||
95 | - gdouble radius = MIN (r->width / 2, r->height / 2); | ||
96 | - gdouble half = num_steps / 2; | ||
97 | - gint i; | ||
98 | - | ||
99 | - cairo_save(cr); | ||
100 | - cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
101 | - | ||
102 | - cairo_rectangle(cr, r->x, r->y, r->width, r->height); | ||
103 | - cairo_clip(cr); | ||
104 | - cairo_translate(cr, r->x, r->y); | ||
105 | - | ||
106 | - step++; | ||
107 | - step %= num_steps; | ||
108 | - | ||
109 | -// debug("%s step=%d",__FUNCTION__,step); | ||
110 | - | ||
111 | - for (i = 0; i < ((gint) num_steps); i++) | ||
112 | - { | ||
113 | - gint inset = 0.7 * radius; | ||
114 | - | ||
115 | - /* transparency is a function of time and intial value */ | ||
116 | - gdouble t = (gdouble) ((i + num_steps - step) % num_steps) / num_steps; | ||
117 | - | ||
118 | - cairo_save(cr); | ||
119 | - | ||
120 | - cairo_set_source_rgba (cr, | ||
121 | - color[V3270_COLOR_OIA_SPINNER].red, | ||
122 | - color[V3270_COLOR_OIA_SPINNER].green, | ||
123 | - color[V3270_COLOR_OIA_SPINNER].blue, | ||
124 | - t); | ||
125 | - | ||
126 | - cairo_set_line_width (cr, 2.0); | ||
127 | - cairo_move_to (cr, | ||
128 | - dx + (radius - inset) * cos (i * G_PI / half), | ||
129 | - dy + (radius - inset) * sin (i * G_PI / half)); | ||
130 | - cairo_line_to (cr, | ||
131 | - dx + radius * cos (i * G_PI / half), | ||
132 | - dy + radius * sin (i * G_PI / half)); | ||
133 | - cairo_stroke (cr); | ||
134 | - | ||
135 | - cairo_restore (cr); | ||
136 | - } | ||
137 | - | ||
138 | - cairo_restore(cr); | ||
139 | - | ||
140 | - return step; | ||
141 | -} | ||
142 | -#endif // HAVE_LIBM | ||
143 | - | ||
144 | -static void setup_cursor_position(GdkRectangle *rect, v3270FontInfo *metrics, cairo_t *cr, H3270 *host, int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
145 | -{ | ||
146 | - rect->width = metrics->width * 8; | ||
147 | - rect->x -= rect->width; | ||
148 | - | ||
149 | - if(lib3270_get_toggle(host,LIB3270_TOGGLE_CURSOR_POS)) | ||
150 | - { | ||
151 | - int addr = lib3270_get_cursor_address(host); | ||
152 | - draw_cursor_position(cr,rect,metrics,addr/cols,addr%cols); | ||
153 | - } | ||
154 | -} | ||
155 | - | ||
156 | -static void setup_ticking_position(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
157 | -{ | ||
158 | - char buffer[7]; | ||
159 | - cairo_text_extents_t extents; | ||
160 | - | ||
161 | - short2string(buffer,0,2); | ||
162 | - buffer[2] = ':'; | ||
163 | - short2string(buffer+3,0,2); | ||
164 | - buffer[5] = 0; | ||
165 | - | ||
166 | - cairo_text_extents(cr,buffer,&extents); | ||
167 | - rect->width = ((int) extents.width + 2); | ||
168 | - rect->x -= rect->width; | ||
169 | -} | ||
170 | - | ||
171 | -static void setup_spinner_position(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, G_GNUC_UNUSED cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
172 | -{ | ||
173 | - rect->width = rect->height; | ||
174 | - rect->x -= rect->width; | ||
175 | -// draw_spinner(cr,rect,color,0); | ||
176 | -} | ||
177 | - | ||
178 | -static void setup_luname_position(GdkRectangle *rect, v3270FontInfo *font, cairo_t *cr, H3270 *host, G_GNUC_UNUSED int cols, GdkRGBA *color) | ||
179 | -{ | ||
180 | - const char *luname = lib3270_get_luname(host); | ||
181 | - | ||
182 | - rect->width *= 16; | ||
183 | - rect->x -= rect->width; | ||
184 | - | ||
185 | - cairo_save(cr); | ||
186 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
187 | - cairo_clip(cr); | ||
188 | - | ||
189 | -#ifdef DEBUG | ||
190 | - cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
191 | -#else | ||
192 | - gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); | ||
193 | -#endif | ||
194 | - | ||
195 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
196 | - cairo_fill(cr); | ||
197 | - | ||
198 | - if(luname) | ||
199 | - { | ||
200 | - gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_LUNAME); | ||
201 | - v3270_draw_text(cr,rect,font,luname); | ||
202 | - } | ||
203 | - | ||
204 | - cairo_restore(cr); | ||
205 | - | ||
206 | -} | ||
207 | - | ||
208 | -static void setup_single_char_right(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, G_GNUC_UNUSED cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
209 | -{ | ||
210 | - rect->x -= rect->width; | ||
211 | - | ||
212 | - /* | ||
213 | -#ifdef DEBUG | ||
214 | - cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
215 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
216 | - cairo_fill(cr); | ||
217 | -#endif | ||
218 | -*/ | ||
219 | - | ||
220 | -} | ||
221 | - | ||
222 | -static void setup_insert_position(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
223 | -{ | ||
224 | - if(rect->width > rect->height) | ||
225 | - { | ||
226 | - rect->width = rect->height; | ||
227 | - } | ||
228 | - else if(rect->height > rect->width) | ||
229 | - { | ||
230 | - rect->y += (rect->height - rect->width)/2; | ||
231 | - rect->height = rect->width; | ||
232 | - } | ||
233 | - | ||
234 | - rect->x -= rect->width; | ||
235 | - | ||
236 | -#ifdef DEBUG | ||
237 | - cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
238 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
239 | - cairo_fill(cr); | ||
240 | -#endif | ||
241 | - | ||
242 | -} | ||
243 | - | ||
244 | - | ||
245 | - | ||
246 | -static void setup_double_char_position(GdkRectangle *rect, G_GNUC_UNUSED v3270FontInfo *metrics, cairo_t *cr, G_GNUC_UNUSED H3270 *host, G_GNUC_UNUSED int cols, G_GNUC_UNUSED GdkRGBA *color) | ||
247 | -{ | ||
248 | - rect->width <<= 1; | ||
249 | - rect->x -= rect->width; | ||
250 | - | ||
251 | -#ifdef DEBUG | ||
252 | - cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
253 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
254 | - cairo_fill(cr); | ||
255 | -#endif | ||
256 | - | ||
257 | -} | ||
258 | - | ||
259 | -static int draw_centered_char(cairo_t *cr, v3270FontInfo *metrics, int x, int y, const gchar chr) | ||
260 | -{ | ||
261 | - char str[2] = { chr, 0 }; | ||
262 | -// cairo_text_extents_t extents; | ||
263 | - | ||
264 | - cairo_set_scaled_font(cr,metrics->scaled); | ||
265 | -// cairo_text_extents(cr,str,&extents); | ||
266 | - | ||
267 | - v3270_draw_text_at(cr, x, y, metrics, str); | ||
268 | - | ||
269 | - return y+metrics->height+2; | ||
270 | - | ||
271 | -} | ||
272 | - | ||
273 | -static void draw_undera(cairo_t *cr, H3270 *host, v3270FontInfo *metrics, GdkRGBA *color, GdkRectangle *rect) | ||
274 | -{ | ||
275 | - gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); | ||
276 | - | ||
277 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
278 | - cairo_fill(cr); | ||
279 | - | ||
280 | - if(lib3270_get_undera(host)) | ||
281 | - { | ||
282 | - int y; | ||
283 | - | ||
284 | - gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_FOREGROUND); | ||
285 | - | ||
286 | - y = draw_centered_char(cr, metrics,rect->x,rect->y, lib3270_in_e(host) ? 'B' : 'A'); | ||
287 | - | ||
288 | - cairo_move_to(cr,rect->x,y); | ||
289 | - cairo_rel_line_to(cr,10,0); | ||
290 | - cairo_stroke(cr); | ||
291 | - | ||
292 | - } | ||
293 | -// debug("%s",__FUNCTION__); | ||
294 | - | ||
295 | -} | ||
296 | - | ||
297 | -void v3270_draw_connection(cairo_t *cr, H3270 *host, v3270FontInfo *metrics, GdkRGBA *color, const GdkRectangle *rect) | ||
298 | -{ | ||
299 | - gchar str = ' '; | ||
300 | - | ||
301 | - gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); | ||
302 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
303 | - cairo_fill(cr); | ||
304 | - | ||
305 | - gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_FOREGROUND); | ||
306 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
307 | - cairo_stroke(cr); | ||
308 | - | ||
309 | - if(lib3270_get_oia_box_solid(host)) | ||
310 | - { | ||
311 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
312 | - cairo_fill(cr); | ||
313 | - return; | ||
314 | - } | ||
315 | - | ||
316 | - if(lib3270_in_ansi(host)) | ||
317 | - str = 'N'; | ||
318 | - else if(lib3270_in_sscp(host)) | ||
319 | - str = 'S'; | ||
320 | - else | ||
321 | - str = '?'; | ||
322 | - | ||
323 | - draw_centered_char(cr,metrics,rect->x,rect->y,str); | ||
324 | - | ||
325 | -} | ||
326 | - | ||
327 | -static void draw_xbm(cairo_t *cr, GdkRectangle *rect, int width, int height, unsigned char *bits) | ||
328 | -{ | ||
329 | - double sz = rect->width < rect->height ? rect->width : rect->height; | ||
330 | - cairo_surface_t * icon = cairo_image_surface_create_for_data( | ||
331 | - bits, | ||
332 | - CAIRO_FORMAT_A1, | ||
333 | - width,height, | ||
334 | - cairo_format_stride_for_width(CAIRO_FORMAT_A1,width)); | ||
335 | - | ||
336 | - cairo_save(cr); | ||
337 | - | ||
338 | - cairo_scale(cr, sz / ((double) width), | ||
339 | - sz / ((double) height)); | ||
340 | - | ||
341 | - cairo_mask_surface(cr,icon,(rect->width-sz)/2,(rect->height-sz)/2); | ||
342 | - | ||
343 | - cairo_surface_destroy(icon); | ||
344 | - | ||
345 | - cairo_restore(cr); | ||
346 | -} | ||
347 | - | ||
348 | -void v3270_draw_ssl_status(v3270 *widget, cairo_t *cr, GdkRectangle *rect) | ||
349 | -{ | ||
350 | - gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_BACKGROUND); | ||
351 | - | ||
352 | - cairo_translate(cr, rect->x, rect->y); | ||
353 | - cairo_rectangle(cr, 0, 0, rect->width, rect->height); | ||
354 | - cairo_fill(cr); | ||
355 | - | ||
356 | - switch(lib3270_get_ssl_state(widget->host)) | ||
357 | - { | ||
358 | - case LIB3270_SSL_UNDEFINED: // Undefined. | ||
359 | - break; | ||
360 | - | ||
361 | - case LIB3270_SSL_UNSECURE: // No secure connection | ||
362 | - gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_FOREGROUND); | ||
363 | - draw_xbm(cr,rect,unlocked_width,unlocked_height,unlocked_bits); | ||
364 | - break; | ||
365 | - | ||
366 | - case LIB3270_SSL_NEGOTIATING: // Negotiating SSL | ||
367 | - if(widget->blink.show) | ||
368 | - { | ||
369 | - gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_STATUS_WARNING); | ||
370 | - draw_xbm(cr,rect,negotiated_width,negotiated_height,negotiated_bits); | ||
371 | - } | ||
372 | - break; | ||
373 | - | ||
374 | - case LIB3270_SSL_NEGOTIATED: // Connection secure, no CA, self-signed or expired CRL | ||
375 | - gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_STATUS_OK); | ||
376 | - draw_xbm(cr,rect,locked_width,locked_height,locked_bits); | ||
377 | - gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_STATUS_WARNING); | ||
378 | - draw_xbm(cr,rect,warning_width,warning_height,warning_bits); | ||
379 | - break; | ||
380 | - | ||
381 | - case LIB3270_SSL_SECURE: // Connection secure with CA check | ||
382 | - gdk_cairo_set_source_rgba(cr,widget->color+V3270_COLOR_OIA_STATUS_OK); | ||
383 | - draw_xbm(cr,rect,locked_width,locked_height,locked_bits); | ||
384 | - break; | ||
385 | - | ||
386 | - } | ||
387 | - | ||
388 | - | ||
389 | -} | ||
390 | - | ||
391 | -static void draw_status_message(cairo_t *cr, LIB3270_MESSAGE id, v3270FontInfo *font, GdkRGBA *color, const GdkRectangle *r) | ||
392 | -{ | ||
393 | - #ifdef DEBUG | ||
394 | - #define OIA_MESSAGE(x,c,y) { #x, c, y } | ||
395 | - #else | ||
396 | - #define OIA_MESSAGE(x,c,y) { c, y } | ||
397 | - #endif | ||
398 | - | ||
399 | - static const struct _message | ||
400 | - { | ||
401 | - #ifdef DEBUG | ||
402 | - const gchar * dbg; | ||
403 | - #endif | ||
404 | - enum V3270_COLOR | ||
405 | - color; | ||
406 | - const gchar * msg; | ||
407 | - } message[] = | ||
408 | - { | ||
409 | - OIA_MESSAGE( LIB3270_MESSAGE_NONE, | ||
410 | - V3270_COLOR_OIA_STATUS_OK, | ||
411 | - NULL ), | ||
412 | - | ||
413 | - OIA_MESSAGE( LIB3270_MESSAGE_SYSWAIT, | ||
414 | - V3270_COLOR_OIA_STATUS_OK, | ||
415 | - N_( "X System" ) ), | ||
416 | - | ||
417 | - OIA_MESSAGE( LIB3270_MESSAGE_TWAIT, | ||
418 | - V3270_COLOR_OIA_STATUS_OK, | ||
419 | - N_( "X Wait" ) ), | ||
420 | - | ||
421 | - OIA_MESSAGE( LIB3270_MESSAGE_CONNECTED, | ||
422 | - V3270_COLOR_OIA_STATUS_OK, | ||
423 | - NULL ), | ||
424 | - | ||
425 | - OIA_MESSAGE( LIB3270_MESSAGE_DISCONNECTED, | ||
426 | - V3270_COLOR_OIA_STATUS_INVALID, | ||
427 | - N_( "X Not Connected" ) ), | ||
428 | - | ||
429 | - OIA_MESSAGE( LIB3270_MESSAGE_AWAITING_FIRST, | ||
430 | - V3270_COLOR_OIA_STATUS_OK, | ||
431 | - N_( "X" ) ), | ||
432 | - | ||
433 | - OIA_MESSAGE( LIB3270_MESSAGE_MINUS, | ||
434 | - V3270_COLOR_OIA_STATUS_OK, | ||
435 | - N_( "X -f" ) ), | ||
436 | - | ||
437 | - OIA_MESSAGE( LIB3270_MESSAGE_PROTECTED, | ||
438 | - V3270_COLOR_OIA_STATUS_INVALID, | ||
439 | - N_( "X Protected" ) ), | ||
440 | - | ||
441 | - OIA_MESSAGE( LIB3270_MESSAGE_NUMERIC, | ||
442 | - V3270_COLOR_OIA_STATUS_INVALID, | ||
443 | - N_( "X Numeric" ) ), | ||
444 | - | ||
445 | - OIA_MESSAGE( LIB3270_MESSAGE_OVERFLOW, | ||
446 | - V3270_COLOR_OIA_STATUS_INVALID, | ||
447 | - N_( "X Overflow" ) ), | ||
448 | - | ||
449 | - OIA_MESSAGE( LIB3270_MESSAGE_INHIBIT, | ||
450 | - V3270_COLOR_OIA_STATUS_INVALID, | ||
451 | - N_( "X Inhibit" ) ), | ||
452 | - | ||
453 | - OIA_MESSAGE( LIB3270_MESSAGE_KYBDLOCK, | ||
454 | - V3270_COLOR_OIA_STATUS_INVALID, | ||
455 | - N_( "X") ), | ||
456 | - | ||
457 | - OIA_MESSAGE( LIB3270_MESSAGE_X, | ||
458 | - V3270_COLOR_OIA_STATUS_INVALID, | ||
459 | - N_( "X" ) ), | ||
460 | - | ||
461 | - OIA_MESSAGE( LIB3270_MESSAGE_RESOLVING, | ||
462 | - V3270_COLOR_OIA_STATUS_WARNING, | ||
463 | - N_( "X Resolving" ) ), | ||
464 | - | ||
465 | - OIA_MESSAGE( LIB3270_MESSAGE_CONNECTING, | ||
466 | - V3270_COLOR_OIA_STATUS_WARNING, | ||
467 | - N_( "X Connecting" ) ), | ||
468 | - | ||
469 | - | ||
470 | - }; | ||
471 | - | ||
472 | - GdkRectangle rect; | ||
473 | - const gchar * msg = message[0].msg; | ||
474 | - | ||
475 | - memcpy(&rect,r,sizeof(GdkRectangle)); | ||
476 | - | ||
477 | - if(id >= 0 && id < G_N_ELEMENTS(message)) | ||
478 | - { | ||
479 | - msg = message[id].msg; | ||
480 | -#ifdef DEBUG | ||
481 | - if(!msg) | ||
482 | - msg = message[id].dbg; | ||
483 | -#endif // DEBUG | ||
484 | - } | ||
485 | - | ||
486 | - // Limpa o bloco | ||
487 | - gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); | ||
488 | - cairo_rectangle(cr, rect.x, rect.y, rect.width, rect.height); | ||
489 | - cairo_fill(cr); | ||
490 | - | ||
491 | - if(msg && *msg) | ||
492 | - { | ||
493 | - msg = gettext(msg); | ||
494 | - } | ||
495 | - | ||
496 | - if(msg && *msg) | ||
497 | - { | ||
498 | - rect.x++; | ||
499 | - | ||
500 | -// debug("%s(%s)",__FUNCTION__,msg); | ||
501 | - | ||
502 | - gdk_cairo_set_source_rgba(cr,color+message[id].color); | ||
503 | - | ||
504 | - if(*msg == 'X') | ||
505 | - { | ||
506 | - cairo_save(cr); | ||
507 | - | ||
508 | - cairo_move_to(cr,rect.x+1,rect.y+(font->height)-(font->ascent)); | ||
509 | - cairo_rel_line_to(cr,font->width,font->ascent); | ||
510 | - cairo_rel_move_to(cr,-font->width,0); | ||
511 | - cairo_rel_line_to(cr,font->width,-font->ascent); | ||
512 | - | ||
513 | - cairo_stroke(cr); | ||
514 | - rect.x += font->width; | ||
515 | - msg++; | ||
516 | - | ||
517 | - cairo_restore(cr); | ||
518 | - } | ||
519 | - | ||
520 | - while(isspace(*msg)) | ||
521 | - { | ||
522 | - msg++; | ||
523 | - rect.x += font->width; | ||
524 | - } | ||
525 | - | ||
526 | - if(*msg) | ||
527 | - { | ||
528 | - v3270_draw_text(cr,&rect, font, msg); | ||
529 | -// cairo_move_to(cr,x,rect->y+metrics->height); | ||
530 | -// cairo_show_text(cr,msg); | ||
531 | - } | ||
532 | - | ||
533 | - } | ||
534 | - | ||
535 | -} | ||
536 | - | ||
537 | -static void draw_insert(cairo_t *cr, H3270 *host, GdkRGBA *color, GdkRectangle *rect) | ||
538 | -{ | ||
539 | - if(lib3270_get_toggle(host,LIB3270_TOGGLE_INSERT)) | ||
540 | - { | ||
541 | - double y = rect->y+(rect->height-2); | ||
542 | - | ||
543 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
544 | - cairo_clip(cr); | ||
545 | - | ||
546 | - gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_FOREGROUND); | ||
547 | - | ||
548 | - cairo_move_to(cr,rect->x,y); | ||
549 | - cairo_rel_line_to(cr,rect->width/2,-(rect->height/1.7)); | ||
550 | - cairo_line_to(cr,rect->x+rect->width,y); | ||
551 | - cairo_stroke(cr); | ||
552 | - } | ||
553 | - | ||
554 | -} | ||
555 | - | ||
556 | -// v3270_draw_oia(cr, terminal->host, rect.y, cols, &terminal->font, terminal->color,terminal->oia_rect); | ||
557 | -// void v3270_draw_oia(cairo_t *cr, H3270 *host, int row, int cols, v3270FontInfo *metrics, GdkRGBA *color, GdkRectangle *rect) | ||
558 | - | ||
559 | -void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols) | ||
560 | -{ | ||
561 | - static const struct _right_fields | ||
562 | - { | ||
563 | - V3270_OIA_FIELD id; | ||
564 | - void (*draw)(GdkRectangle *rect, v3270FontInfo *metrics, cairo_t *cr, H3270 *host, int cols, GdkRGBA *color); | ||
565 | - } right[] = | ||
566 | - { | ||
567 | - { V3270_OIA_CURSOR_POSITION, setup_cursor_position }, | ||
568 | - { V3270_OIA_TIMER, setup_ticking_position }, | ||
569 | - { V3270_OIA_SPINNER, setup_spinner_position }, | ||
570 | - { V3270_OIA_LUNAME, setup_luname_position }, | ||
571 | -#ifdef HAVE_PRINTER | ||
572 | - { V3270_OIA_PRINTER, setup_single_char_right }, | ||
573 | -#endif // HAVE_PRINTER | ||
574 | - { V3270_OIA_SCRIPT, setup_single_char_right }, | ||
575 | - { V3270_OIA_INSERT, setup_insert_position }, | ||
576 | - { V3270_OIA_TYPEAHEAD, setup_single_char_right }, | ||
577 | - { V3270_OIA_SHIFT, setup_double_char_position }, | ||
578 | -// { V3270_OIA_CAPS, setup_single_char_right }, | ||
579 | - { V3270_OIA_ALT, setup_single_char_right }, | ||
580 | - { V3270_OIA_SSL, setup_double_char_position }, | ||
581 | - }; | ||
582 | - | ||
583 | - int f; | ||
584 | - int rCol = terminal->font.margin.left+(cols*terminal->font.width); | ||
585 | - int lCol = terminal->font.margin.left+1; | ||
586 | - | ||
587 | - row += OIA_TOP_MARGIN; | ||
588 | - gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_SEPARATOR); | ||
589 | - cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, 1); | ||
590 | - cairo_fill(cr); | ||
591 | - | ||
592 | - row += 2; | ||
593 | - | ||
594 | - gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
595 | - cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, terminal->font.spacing); | ||
596 | - cairo_fill(cr); | ||
597 | - | ||
598 | - for(f=0;f< (int) G_N_ELEMENTS(right);f++) | ||
599 | - { | ||
600 | - GdkRectangle *r = terminal->oia.rect+right[f].id; | ||
601 | - | ||
602 | - memset(r,0,sizeof(GdkRectangle)); | ||
603 | - r->x = rCol; | ||
604 | - r->y = row; | ||
605 | - r->width = terminal->font.width; | ||
606 | - r->height = terminal->font.spacing; | ||
607 | - gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
608 | - right[f].draw(r,&terminal->font,cr,terminal->host,cols,terminal->color); | ||
609 | - rCol = r->x - (terminal->font.width/3); | ||
610 | - } | ||
611 | - | ||
612 | - gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
613 | - | ||
614 | - draw_centered_char(cr,&terminal->font,lCol,row,'4'); | ||
615 | - | ||
616 | - cairo_stroke(cr); | ||
617 | - cairo_rectangle(cr, lCol, row, terminal->font.width+2, terminal->font.spacing); | ||
618 | - cairo_stroke(cr); | ||
619 | - | ||
620 | - lCol += (terminal->font.width+5); | ||
621 | - | ||
622 | - // Undera indicator | ||
623 | - terminal->oia.rect[V3270_OIA_UNDERA].x = lCol; | ||
624 | - terminal->oia.rect[V3270_OIA_UNDERA].y = row; | ||
625 | - terminal->oia.rect[V3270_OIA_UNDERA].width = terminal->font.width+3; | ||
626 | - terminal->oia.rect[V3270_OIA_UNDERA].height = terminal->font.spacing; | ||
627 | - draw_undera(cr,terminal->host,&terminal->font,terminal->color,terminal->oia.rect+V3270_OIA_UNDERA); | ||
628 | - | ||
629 | - lCol += (3 + terminal->oia.rect[V3270_OIA_UNDERA].width); | ||
630 | - | ||
631 | - // Connection indicator | ||
632 | - terminal->oia.rect[V3270_OIA_CONNECTION].x = lCol; | ||
633 | - terminal->oia.rect[V3270_OIA_CONNECTION].y = row; | ||
634 | - terminal->oia.rect[V3270_OIA_CONNECTION].width = terminal->font.width+3; | ||
635 | - terminal->oia.rect[V3270_OIA_CONNECTION].height = terminal->font.spacing; | ||
636 | - v3270_draw_connection(cr,terminal->host,&terminal->font,terminal->color,terminal->oia.rect+V3270_OIA_CONNECTION); | ||
637 | - | ||
638 | - lCol += (4 + terminal->oia.rect[V3270_OIA_CONNECTION].width); | ||
639 | - | ||
640 | - memset(terminal->oia.rect+V3270_OIA_MESSAGE,0,sizeof(GdkRectangle)); | ||
641 | - | ||
642 | - if(lCol < rCol) | ||
643 | - { | ||
644 | - GdkRectangle *r = terminal->oia.rect+V3270_OIA_MESSAGE; | ||
645 | - r->x = lCol; | ||
646 | - r->y = row; | ||
647 | - r->width = rCol - lCol; | ||
648 | - r->height = terminal->font.spacing; | ||
649 | - draw_status_message(cr,lib3270_get_program_message(terminal->host),&terminal->font,terminal->color,r); | ||
650 | - } | ||
651 | - | ||
652 | - cairo_save(cr); | ||
653 | -// v3270_draw_ssl_status(cr,terminal->host,&terminal->font,terminal->color,terminal->oia.rect+V3270_OIA_SSL); | ||
654 | - v3270_draw_ssl_status(terminal,cr,terminal->oia.rect+V3270_OIA_SSL); | ||
655 | - cairo_restore(cr); | ||
656 | - | ||
657 | - cairo_save(cr); | ||
658 | - draw_insert(cr,terminal->host,terminal->color,terminal->oia.rect+V3270_OIA_INSERT); | ||
659 | - cairo_restore(cr); | ||
660 | -} | ||
661 | - | ||
662 | -/** | ||
663 | - * Begin update of a specific OIA field. | ||
664 | - * | ||
665 | - * @param terminal 3270 terminal widget. | ||
666 | - * @param r Rectangle to receive updated region. | ||
667 | - * @param id Field id. | ||
668 | - * | ||
669 | - * @return cairo object for drawing. | ||
670 | - * | ||
671 | - */ | ||
672 | -cairo_t * v3270_oia_set_update_region(v3270 * terminal, GdkRectangle **r, V3270_OIA_FIELD id) | ||
673 | -{ | ||
674 | - GdkRectangle * rect = terminal->oia.rect + id; | ||
675 | - cairo_t * cr = cairo_create(terminal->surface); | ||
676 | - | ||
677 | - cairo_set_scaled_font(cr,terminal->font.scaled); | ||
678 | - | ||
679 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
680 | - cairo_clip(cr); | ||
681 | - | ||
682 | - *r = rect; | ||
683 | - | ||
684 | -#ifdef DEBUG | ||
685 | - cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
686 | -#else | ||
687 | - gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
688 | -#endif | ||
689 | - | ||
690 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
691 | - cairo_fill(cr); | ||
692 | - | ||
693 | - gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
694 | - | ||
695 | - return cr; | ||
696 | -} | ||
697 | - | ||
698 | -void v3270_update_luname(GtkWidget *widget,const gchar *name) | ||
699 | -{ | ||
700 | - cairo_t * cr; | ||
701 | - GdkRectangle * rect; | ||
702 | - v3270 * terminal = GTK_V3270(widget); | ||
703 | - | ||
704 | - if(terminal->surface) | ||
705 | - { | ||
706 | - cr = v3270_oia_set_update_region(terminal,&rect,V3270_OIA_LUNAME); | ||
707 | - | ||
708 | - if(name) | ||
709 | - { | ||
710 | -// cairo_move_to(cr,rect->x,rect->y+terminal->font.height); | ||
711 | -// cairo_show_text(cr,name); | ||
712 | -// cairo_stroke(cr); | ||
713 | - gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_LUNAME); | ||
714 | - v3270_draw_text_at(cr, rect->x, rect->y, &terminal->font, name); | ||
715 | - | ||
716 | - } | ||
717 | - | ||
718 | - cairo_destroy(cr); | ||
719 | - | ||
720 | - v3270_queue_draw_area(GTK_WIDGET(terminal),rect->x,rect->y,rect->width,rect->height); | ||
721 | - } | ||
722 | - | ||
723 | - g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.luname); | ||
724 | - | ||
725 | -} | ||
726 | - | ||
727 | -void v3270_update_message(v3270 *widget, LIB3270_MESSAGE id) | ||
728 | -{ | ||
729 | - cairo_t * cr; | ||
730 | - GdkRectangle * rect; | ||
731 | - | ||
732 | - if(!widget->surface) | ||
733 | - return; | ||
734 | - | ||
735 | - cr = v3270_oia_set_update_region(widget,&rect,V3270_OIA_MESSAGE); | ||
736 | - | ||
737 | - draw_status_message(cr,id,&widget->font,widget->color,rect); | ||
738 | - | ||
739 | - cairo_destroy(cr); | ||
740 | - | ||
741 | - v3270_queue_draw_area(GTK_WIDGET(widget),rect->x,rect->y,rect->width,rect->height); | ||
742 | - | ||
743 | - if(widget->accessible) | ||
744 | - v3270_acessible_set_state(widget->accessible,id); | ||
745 | - | ||
746 | -} | ||
747 | - | ||
748 | -static void draw_cursor_position(cairo_t *cr, GdkRectangle *rect, v3270FontInfo *metrics, int row, int col) | ||
749 | -{ | ||
750 | - cairo_text_extents_t extents; | ||
751 | - char buffer[10]; | ||
752 | - | ||
753 | - short2string(buffer,row+1,3); | ||
754 | - buffer[3] = '/'; | ||
755 | - short2string(buffer+4,col+1,3); | ||
756 | - buffer[7] = 0; | ||
757 | - | ||
758 | - cairo_text_extents(cr,buffer,&extents); | ||
759 | - v3270_draw_text_at(cr,(rect->x+rect->width)-(extents.width+2),rect->y,metrics,buffer); | ||
760 | -} | ||
761 | - | ||
762 | -void v3270_update_cursor(H3270 *session, unsigned short row, unsigned short col, unsigned char c, unsigned short attr) | ||
763 | -{ | ||
764 | - v3270 * terminal = GTK_V3270(lib3270_get_user_data(session)); | ||
765 | - GdkRectangle saved; | ||
766 | - | ||
767 | - if(!terminal->surface) | ||
768 | - return; | ||
769 | - | ||
770 | - // Update cursor rectangle | ||
771 | - saved = terminal->cursor.rect; | ||
772 | - | ||
773 | - terminal->cursor.rect.x = terminal->font.margin.left + (col * terminal->cursor.rect.width); | ||
774 | - terminal->cursor.rect.y = terminal->font.margin.top + (row * terminal->font.spacing); | ||
775 | - terminal->cursor.rect.width = terminal->font.width; | ||
776 | - terminal->cursor.rect.height = terminal->font.height+terminal->font.descent; | ||
777 | - terminal->cursor.show |= 1; | ||
778 | - | ||
779 | - v3270_queue_draw_area( GTK_WIDGET(terminal), saved.x, | ||
780 | - saved.y, | ||
781 | - saved.width, | ||
782 | - saved.height); | ||
783 | - | ||
784 | - | ||
785 | - v3270_update_cursor_surface(terminal,c,attr); | ||
786 | - | ||
787 | - v3270_queue_draw_area( GTK_WIDGET(terminal), | ||
788 | - terminal->cursor.rect.x,terminal->cursor.rect.y, | ||
789 | - terminal->cursor.rect.width,terminal->cursor.rect.height); | ||
790 | - | ||
791 | - if(lib3270_get_toggle(session,LIB3270_TOGGLE_CROSSHAIR)) | ||
792 | - { | ||
793 | - GtkAllocation allocation; | ||
794 | - gtk_widget_get_allocation(GTK_WIDGET(terminal), &allocation); | ||
795 | - | ||
796 | - v3270_queue_draw_area(GTK_WIDGET(terminal),0,saved.y+terminal->font.height,allocation.width,1); | ||
797 | - v3270_queue_draw_area(GTK_WIDGET(terminal),saved.x,0,1,terminal->oia.rect->y-3); | ||
798 | - | ||
799 | - v3270_queue_draw_area(GTK_WIDGET(terminal),0,terminal->cursor.rect.y+terminal->font.height,allocation.width,1); | ||
800 | - v3270_queue_draw_area(GTK_WIDGET(terminal),terminal->cursor.rect.x,0,1,terminal->oia.rect->y-3); | ||
801 | - } | ||
802 | - | ||
803 | - if(lib3270_get_toggle(session,LIB3270_TOGGLE_CURSOR_POS)) | ||
804 | - { | ||
805 | - // Update OIA | ||
806 | - GdkRectangle * rect; | ||
807 | - cairo_t * cr; | ||
808 | - | ||
809 | - cr = v3270_oia_set_update_region(terminal,&rect,V3270_OIA_CURSOR_POSITION); | ||
810 | - | ||
811 | - draw_cursor_position(cr,rect,&terminal->font,row,col); | ||
812 | - | ||
813 | - cairo_destroy(cr); | ||
814 | - | ||
815 | - v3270_queue_draw_area(GTK_WIDGET(terminal),rect->x,rect->y,rect->width,rect->height); | ||
816 | - } | ||
817 | - | ||
818 | - if(terminal->accessible) | ||
819 | - g_signal_emit_by_name(ATK_TEXT(terminal->accessible),"text-caret-moved",lib3270_get_cursor_address(session)); | ||
820 | - | ||
821 | -} | ||
822 | - | ||
823 | -struct timer_info | ||
824 | -{ | ||
825 | - time_t start; | ||
826 | - time_t last; | ||
827 | -#ifdef HAVE_LIBM | ||
828 | - gint step; | ||
829 | -#endif // HAVE_LIBM | ||
830 | - v3270 * terminal; | ||
831 | -}; | ||
832 | - | ||
833 | -static void release_timer(struct timer_info *info) | ||
834 | -{ | ||
835 | - info->terminal->timer = NULL; | ||
836 | - | ||
837 | - if(info->terminal->surface) | ||
838 | - { | ||
839 | - // Erase timer info | ||
840 | - static const int id[] = { V3270_OIA_TIMER, | ||
841 | -#ifdef HAVE_LIBM | ||
842 | - V3270_OIA_SPINNER | ||
843 | -#endif // HAVE_LIBM | ||
844 | - }; | ||
845 | - int f; | ||
846 | - | ||
847 | - cairo_t *cr = cairo_create(info->terminal->surface); | ||
848 | - | ||
849 | -#ifdef DEBUG | ||
850 | - cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
851 | -#else | ||
852 | - gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
853 | -#endif | ||
854 | - | ||
855 | - for(f=0;f< (int) G_N_ELEMENTS(id);f++) | ||
856 | - { | ||
857 | - GdkRectangle *rect = info->terminal->oia.rect + id[f]; | ||
858 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
859 | - cairo_fill(cr); | ||
860 | - v3270_queue_draw_area(GTK_WIDGET(info->terminal),rect->x,rect->y,rect->width,rect->height); | ||
861 | - } | ||
862 | - cairo_destroy(cr); | ||
863 | - } | ||
864 | - | ||
865 | - g_free(info); | ||
866 | -} | ||
867 | - | ||
868 | -void v3270_draw_shift_status(v3270 *terminal) | ||
869 | -{ | ||
870 | - GdkRectangle *r; | ||
871 | - cairo_t *cr; | ||
872 | - | ||
873 | - if(!terminal->surface) | ||
874 | - return; | ||
875 | - | ||
876 | - cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_SHIFT); | ||
877 | - cairo_translate(cr, r->x, r->y+1); | ||
878 | - | ||
879 | - if(r->width > 2 && r->height > 7 && (terminal->keyflags & KEY_FLAG_SHIFT)) | ||
880 | - { | ||
881 | - int b,x,y,w,h,l; | ||
882 | - int height = r->height-6; | ||
883 | - | ||
884 | - if(height > r->width) | ||
885 | - { | ||
886 | - w = r->width; | ||
887 | - h = w*1.5; | ||
888 | - } | ||
889 | - else // width > height | ||
890 | - { | ||
891 | - h = height; | ||
892 | - w = h/1.5; | ||
893 | - } | ||
894 | - | ||
895 | - // Set image position | ||
896 | - x = (r->width - w)/2; | ||
897 | - y = (height - h)/2; | ||
898 | - l = (w/3); | ||
899 | - b = y+(w/1.5); | ||
900 | - | ||
901 | - cairo_move_to(cr,x+(w/2),y); | ||
902 | - cairo_line_to(cr,x+w,b); | ||
903 | - cairo_line_to(cr,(x+w)-l,b); | ||
904 | - cairo_line_to(cr,(x+w)-l,y+h); | ||
905 | - cairo_line_to(cr,x+l,y+h); | ||
906 | - cairo_line_to(cr,x+l,b); | ||
907 | - cairo_line_to(cr,x,b); | ||
908 | - cairo_close_path(cr); | ||
909 | - | ||
910 | - cairo_stroke(cr); | ||
911 | - | ||
912 | - } | ||
913 | - | ||
914 | - cairo_destroy(cr); | ||
915 | - v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
916 | - | ||
917 | -} | ||
918 | - | ||
919 | -void v3270_oia_update_text_field(v3270 *terminal, gboolean flag, V3270_OIA_FIELD id, const gchar chr) | ||
920 | -{ | ||
921 | - GdkRectangle * r; | ||
922 | - cairo_t * cr; | ||
923 | - gchar text[] = { chr, 0 }; | ||
924 | - | ||
925 | - if(!terminal->surface) | ||
926 | - return; | ||
927 | - | ||
928 | - cr = v3270_oia_set_update_region(terminal,&r,id); | ||
929 | - cairo_translate(cr, r->x, r->y); | ||
930 | - | ||
931 | - if(flag) | ||
932 | - { | ||
933 | - v3270_draw_text_at(cr,0,0,&terminal->font,text); | ||
934 | -// cairo_move_to(cr,0,terminal->font.height); | ||
935 | -// cairo_show_text(cr, text); | ||
936 | -// cairo_stroke(cr); | ||
937 | - } | ||
938 | - | ||
939 | - cairo_destroy(cr); | ||
940 | - v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
941 | -} | ||
942 | - | ||
943 | -#ifdef KEY_FLAG_ALT | ||
944 | -void v3270_draw_alt_status(v3270 *terminal) | ||
945 | -{ | ||
946 | - v3270_oia_update_text_field(terminal,terminal->keyflags & KEY_FLAG_ALT,V3270_OIA_ALT,'A'); | ||
947 | -} | ||
948 | -#else | ||
949 | -void v3270_draw_alt_status(v3270 G_GNUC_UNUSED(*terminal)) | ||
950 | -{ | ||
951 | -} | ||
952 | -#endif // KEY_FLAG_ALT | ||
953 | - | ||
954 | -void v3270_draw_ins_status(v3270 *terminal) | ||
955 | -{ | ||
956 | - GdkRectangle *r; | ||
957 | - cairo_t *cr; | ||
958 | - | ||
959 | - if(!terminal->surface) | ||
960 | - return; | ||
961 | - | ||
962 | - cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_INSERT); | ||
963 | - | ||
964 | - draw_insert(cr,terminal->host,terminal->color,r); | ||
965 | - | ||
966 | - cairo_destroy(cr); | ||
967 | - v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
968 | - | ||
969 | -} | ||
970 | - | ||
971 | -static gboolean update_timer(struct timer_info *info) | ||
972 | -{ | ||
973 | - cairo_t * cr; | ||
974 | - time_t now = time(0); | ||
975 | - GdkRectangle * rect; | ||
976 | - | ||
977 | -// debug("%s %p",__FUNCTION__,info->terminal->surface); | ||
978 | - if(!info->terminal->surface) | ||
979 | - return TRUE; | ||
980 | - | ||
981 | - cr = cairo_create(info->terminal->surface); | ||
982 | - | ||
983 | - if(now != info->last) | ||
984 | - { | ||
985 | - time_t seconds = now - info->start; | ||
986 | - char buffer[7]; | ||
987 | - | ||
988 | - rect = info->terminal->oia.rect + V3270_OIA_TIMER; | ||
989 | - | ||
990 | - gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
991 | - | ||
992 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
993 | - cairo_fill(cr); | ||
994 | - | ||
995 | - gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
996 | - | ||
997 | - short2string(buffer,seconds/60,2); | ||
998 | - buffer[2] = ':'; | ||
999 | - short2string(buffer+3,seconds%60,2); | ||
1000 | - buffer[5] = 0; | ||
1001 | - | ||
1002 | - cairo_set_scaled_font(cr,info->terminal->font.scaled); | ||
1003 | -// cairo_move_to(cr,rect->x,rect->y+info->terminal->font.height); | ||
1004 | -// cairo_show_text(cr, buffer); | ||
1005 | - | ||
1006 | - v3270_draw_text(cr, rect, &info->terminal->font, buffer); | ||
1007 | - | ||
1008 | - cairo_stroke(cr); | ||
1009 | - | ||
1010 | - info->last = now; | ||
1011 | - v3270_queue_draw_area(GTK_WIDGET(info->terminal),rect->x,rect->y,rect->width,rect->height); | ||
1012 | - } | ||
1013 | - | ||
1014 | -#ifdef HAVE_LIBM | ||
1015 | - | ||
1016 | - rect = info->terminal->oia.rect + V3270_OIA_SPINNER; | ||
1017 | - | ||
1018 | -#ifdef DEBUG | ||
1019 | - cairo_set_source_rgb(cr,0.1,0.1,0.1); | ||
1020 | -#else | ||
1021 | - gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_BACKGROUND); | ||
1022 | -#endif | ||
1023 | - | ||
1024 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | ||
1025 | - cairo_fill(cr); | ||
1026 | - | ||
1027 | - gdk_cairo_set_source_rgba(cr,info->terminal->color+V3270_COLOR_OIA_FOREGROUND); | ||
1028 | - | ||
1029 | - info->step = draw_spinner(cr, rect, info->terminal->color, info->step); | ||
1030 | - | ||
1031 | - v3270_queue_draw_area(GTK_WIDGET(info->terminal),rect->x,rect->y,rect->width,rect->height); | ||
1032 | - | ||
1033 | -#endif // HAVE_LIBM | ||
1034 | - | ||
1035 | - cairo_destroy(cr); | ||
1036 | - | ||
1037 | - return TRUE; | ||
1038 | -} | ||
1039 | - | ||
1040 | -void v3270_start_timer(GtkWidget *widget) | ||
1041 | -{ | ||
1042 | - struct timer_info *info; | ||
1043 | - v3270 *terminal = GTK_V3270(widget); | ||
1044 | - | ||
1045 | - if(terminal->timer) | ||
1046 | - { | ||
1047 | - g_source_ref(terminal->timer); | ||
1048 | - return; | ||
1049 | - } | ||
1050 | - | ||
1051 | - info = g_new0(struct timer_info,1); | ||
1052 | - info->terminal = terminal; | ||
1053 | - info->start = time(0); | ||
1054 | - | ||
1055 | - update_timer(info); | ||
1056 | - | ||
1057 | - terminal->timer = g_timeout_source_new(100); | ||
1058 | - g_source_set_callback(terminal->timer,(GSourceFunc) update_timer, info, (GDestroyNotify) release_timer); | ||
1059 | - | ||
1060 | - g_source_attach(terminal->timer,NULL); | ||
1061 | - g_source_unref(terminal->timer); | ||
1062 | - | ||
1063 | -} | ||
1064 | - | ||
1065 | -void v3270_stop_timer(GtkWidget *widget) | ||
1066 | -{ | ||
1067 | - v3270 *terminal = GTK_V3270(widget); | ||
1068 | - | ||
1069 | - if(terminal->timer) | ||
1070 | - { | ||
1071 | - if(terminal->timer->ref_count < 2) | ||
1072 | - { | ||
1073 | - g_source_destroy(terminal->timer); | ||
1074 | - } | ||
1075 | - else | ||
1076 | - { | ||
1077 | - g_source_unref(terminal->timer); | ||
1078 | - } | ||
1079 | - } | ||
1080 | - | ||
1081 | -} | ||
1082 | - | ||
1083 | -void v3270_blink_ssl(v3270 *terminal) | ||
1084 | -{ | ||
1085 | - if(terminal->surface) | ||
1086 | - { | ||
1087 | - GdkRectangle * r; | ||
1088 | - cairo_t * cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_SSL); | ||
1089 | - | ||
1090 | - v3270_draw_ssl_status(terminal,cr,r); | ||
1091 | - v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
1092 | - cairo_destroy(cr); | ||
1093 | - | ||
1094 | - } | ||
1095 | - | ||
1096 | -} | ||
1097 | - | ||
1098 | -void v3270_update_oia(v3270 *terminal, LIB3270_FLAG id, unsigned char on) | ||
1099 | -{ | ||
1100 | - cairo_t *cr; | ||
1101 | - GdkRectangle *r; | ||
1102 | - | ||
1103 | - if(!(terminal->surface && terminal->drawing)) | ||
1104 | - return; | ||
1105 | - | ||
1106 | - #pragma GCC diagnostic push | ||
1107 | - #pragma GCC diagnostic ignored "-Wswitch" | ||
1108 | - switch(id) | ||
1109 | - { | ||
1110 | - case LIB3270_FLAG_BOXSOLID: | ||
1111 | -// debug("%s LIB3270_FLAG_BOXSOLID",__FUNCTION__); | ||
1112 | - cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_CONNECTION); | ||
1113 | - v3270_draw_connection(cr,terminal->host,&terminal->font,terminal->color,r); | ||
1114 | - cairo_destroy(cr); | ||
1115 | - v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
1116 | - break; | ||
1117 | - | ||
1118 | - case LIB3270_FLAG_UNDERA: | ||
1119 | -// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1120 | - cr = v3270_oia_set_update_region(terminal,&r,V3270_OIA_UNDERA); | ||
1121 | -// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1122 | - draw_undera(cr,terminal->host,&terminal->font,terminal->color,r); | ||
1123 | -// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1124 | - cairo_destroy(cr); | ||
1125 | -// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1126 | - v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | ||
1127 | -// debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | ||
1128 | - break; | ||
1129 | - | ||
1130 | - case LIB3270_FLAG_TYPEAHEAD: | ||
1131 | -// debug("%s LIB3270_FLAG_TYPEAHEAD",__FUNCTION__); | ||
1132 | - v3270_oia_update_text_field(terminal,on,V3270_OIA_TYPEAHEAD,'T'); | ||
1133 | - break; | ||
1134 | - | ||
1135 | -#ifdef HAVE_PRINTER | ||
1136 | - case LIB3270_FLAG_PRINTER: | ||
1137 | -// debug("%s LIB3270_FLAG_PRINTER",__FUNCTION__); | ||
1138 | - v3270_oia_update_text_field(terminal,on,V3270_OIA_PRINTER,'P'); | ||
1139 | - break; | ||
1140 | -#endif // HAVE_PRINTER | ||
1141 | - | ||
1142 | -/* | ||
1143 | - case LIB3270_FLAG_SCRIPT: | ||
1144 | - v3270_oia_update_text_field(terminal,on,V3270_OIA_SCRIPT,terminal->script_id); | ||
1145 | - break; | ||
1146 | -*/ | ||
1147 | - | ||
1148 | - } | ||
1149 | - #pragma GCC diagnostic pop | ||
1150 | - | ||
1151 | -} | ||
1152 | - | ||
1153 | -int v3270_set_script(GtkWidget *widget, const gchar id) | ||
1154 | -{ | ||
1155 | - g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); | ||
1156 | - | ||
1157 | - v3270 * terminal = GTK_V3270(widget); | ||
1158 | - | ||
1159 | - if(id && terminal->script) | ||
1160 | - return EBUSY; | ||
1161 | - | ||
1162 | - terminal->script = id; | ||
1163 | - | ||
1164 | - if(terminal->script) | ||
1165 | - v3270_start_blinking(widget); | ||
1166 | - | ||
1167 | - return 0; | ||
1168 | -} |
src/terminal/properties/get.c
@@ -111,3 +111,42 @@ | @@ -111,3 +111,42 @@ | ||
111 | } | 111 | } |
112 | 112 | ||
113 | } | 113 | } |
114 | + | ||
115 | +LIB3270_EXPORT const gchar * v3270_get_url(GtkWidget *widget) | ||
116 | +{ | ||
117 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
118 | + return lib3270_get_url(GTK_V3270(widget)->host); | ||
119 | +} | ||
120 | + | ||
121 | +LIB3270_EXPORT const gchar * v3270_get_luname(GtkWidget *widget) | ||
122 | +{ | ||
123 | + g_return_val_if_fail(GTK_IS_V3270(widget),""); | ||
124 | + return lib3270_get_luname(GTK_V3270(widget)->host); | ||
125 | +} | ||
126 | + | ||
127 | +LIB3270_EXPORT const gchar * v3270_get_session_name(GtkWidget *widget) | ||
128 | +{ | ||
129 | +#ifdef DEBUG | ||
130 | + v3270 * terminal = GTK_V3270(widget); | ||
131 | + debug("Session name: [%s] Application name: [%s]",terminal->session_name, g_get_application_name()); | ||
132 | +#endif // DEBUG | ||
133 | + | ||
134 | + if(!(GTK_IS_V3270(widget) && GTK_V3270(widget)->session_name)) | ||
135 | + return g_get_application_name(); | ||
136 | + | ||
137 | + return GTK_V3270(widget)->session_name; | ||
138 | +} | ||
139 | + | ||
140 | +LIB3270_EXPORT H3270 * v3270_get_session(GtkWidget *widget) | ||
141 | +{ | ||
142 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
143 | + | ||
144 | + return GTK_V3270(widget)->host; | ||
145 | +} | ||
146 | + | ||
147 | +LIB3270_EXPORT gboolean v3270_is_connected(GtkWidget *widget) | ||
148 | +{ | ||
149 | + g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); | ||
150 | + return lib3270_is_connected(GTK_V3270(widget)->host) ? TRUE : FALSE; | ||
151 | +} | ||
152 | + |
src/terminal/properties/set.c
@@ -132,3 +132,71 @@ | @@ -132,3 +132,71 @@ | ||
132 | 132 | ||
133 | } | 133 | } |
134 | 134 | ||
135 | +/** | ||
136 | + * v3270_set_url: | ||
137 | + * | ||
138 | + * @widget: V3270 widget. | ||
139 | + * @uri: a valid tn3270 URL. | ||
140 | + * | ||
141 | + * Set the default URL for the tn3270e host. | ||
142 | + * | ||
143 | + * Since: 5.0 | ||
144 | + **/ | ||
145 | +LIB3270_EXPORT void v3270_set_url(GtkWidget *widget, const gchar *uri) | ||
146 | +{ | ||
147 | + g_return_if_fail(GTK_IS_V3270(widget)); | ||
148 | + lib3270_set_url(GTK_V3270(widget)->host,uri); | ||
149 | +} | ||
150 | + | ||
151 | +LIB3270_EXPORT void v3270_set_session_name(GtkWidget *widget, const gchar *name) | ||
152 | +{ | ||
153 | + g_return_if_fail(GTK_IS_V3270(widget)); | ||
154 | + g_return_if_fail(name != NULL); | ||
155 | + | ||
156 | + if(GTK_V3270(widget)->session_name) { | ||
157 | + | ||
158 | + debug("Old session name was \"%s\"",GTK_V3270(widget)->session_name); | ||
159 | + | ||
160 | + if(!strcmp(GTK_V3270(widget)->session_name,name)) { | ||
161 | + // Same session name, keep it. | ||
162 | + return; | ||
163 | + } | ||
164 | + | ||
165 | + g_free(GTK_V3270(widget)->session_name); | ||
166 | + | ||
167 | + } | ||
168 | + | ||
169 | + GTK_V3270(widget)->session_name = g_strdup(name); | ||
170 | + | ||
171 | + debug("New session name is \"%s\"",GTK_V3270(widget)->session_name); | ||
172 | + | ||
173 | + g_signal_emit(GTK_WIDGET(widget), v3270_widget_signal[V3270_SIGNAL_SESSION_CHANGED], 0); | ||
174 | + | ||
175 | +} | ||
176 | + | ||
177 | +LIB3270_EXPORT int v3270_set_host_type(GtkWidget *widget, LIB3270_HOST_TYPE type) | ||
178 | +{ | ||
179 | + g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); | ||
180 | + return lib3270_set_host_type(GTK_V3270(widget)->host, type); | ||
181 | +} | ||
182 | + | ||
183 | +LIB3270_EXPORT int v3270_set_host_type_by_name(GtkWidget *widget, const char *name) | ||
184 | +{ | ||
185 | + g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); | ||
186 | + return lib3270_set_host_type_by_name(GTK_V3270(widget)->host,name); | ||
187 | +} | ||
188 | + | ||
189 | +LIB3270_EXPORT int v3270_set_host_charset(GtkWidget *widget, const gchar *name) | ||
190 | +{ | ||
191 | + g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); | ||
192 | + return lib3270_set_host_charset(GTK_V3270(widget)->host,name); | ||
193 | +} | ||
194 | + | ||
195 | +void v3270_set_cursor(GtkWidget *widget, LIB3270_POINTER id) | ||
196 | +{ | ||
197 | + gdk_window_set_cursor( | ||
198 | + gtk_widget_get_window(widget), | ||
199 | + GTK_V3270_GET_CLASS(widget)->cursors[id % LIB3270_POINTER_COUNT] | ||
200 | + ); | ||
201 | +} | ||
202 | + |
src/terminal/surface.c
@@ -1,86 +0,0 @@ | @@ -1,86 +0,0 @@ | ||
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 | - #include <terminal.h> | ||
32 | - | ||
33 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
34 | - | ||
35 | -/** | ||
36 | - * @brief Reconfigure widget surface. | ||
37 | - * | ||
38 | - * Called when the widget is resized or moved to regenerate the cairo surface: | ||
39 | - * | ||
40 | - * * Recreate the surface. | ||
41 | - * * Compute the new font size & metrics. | ||
42 | - * * Redraw contents. | ||
43 | - * * Emite "GDK_CONFIGURE" event. | ||
44 | - * | ||
45 | - */ | ||
46 | -void v3270_reconfigure(v3270 * terminal) | ||
47 | -{ | ||
48 | - GtkAllocation allocation; | ||
49 | - GtkWidget *widget; | ||
50 | - GdkEvent *event = gdk_event_new(GDK_CONFIGURE); | ||
51 | - | ||
52 | - widget = GTK_WIDGET(terminal); | ||
53 | - | ||
54 | - gtk_widget_get_allocation(widget, &allocation); | ||
55 | - | ||
56 | - event->configure.window = g_object_ref(gtk_widget_get_window(widget)); | ||
57 | - event->configure.send_event = TRUE; | ||
58 | - event->configure.x = allocation.x; | ||
59 | - event->configure.y = allocation.y; | ||
60 | - event->configure.width = allocation.width; | ||
61 | - event->configure.height = allocation.height; | ||
62 | - | ||
63 | - if(terminal->surface) | ||
64 | - cairo_surface_destroy(terminal->surface); | ||
65 | - | ||
66 | - terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,allocation.width,allocation.height); | ||
67 | - | ||
68 | - // Update the created image | ||
69 | - cairo_t * cr = cairo_create(terminal->surface); | ||
70 | - v3270_compute_font_size(terminal, cr, allocation.width, allocation.height); | ||
71 | - v3270_update_font_metrics(terminal, allocation.width, allocation.height); | ||
72 | - | ||
73 | - v3270_redraw(terminal, cr, allocation.width, allocation.height); | ||
74 | - | ||
75 | - cairo_destroy(cr); | ||
76 | - | ||
77 | -#if( !GTK_CHECK_VERSION(3,0,0)) | ||
78 | - terminal->width = allocation.width; | ||
79 | - terminal->height = allocation.height; | ||
80 | -#endif | ||
81 | - | ||
82 | - gtk_widget_event(widget, event); | ||
83 | - gdk_event_free(event); | ||
84 | -} | ||
85 | - | ||
86 | - |
src/terminal/widget.c
@@ -71,30 +71,13 @@ | @@ -71,30 +71,13 @@ | ||
71 | static void v3270_realize ( GtkWidget * widget) ; | 71 | static void v3270_realize ( GtkWidget * widget) ; |
72 | static void v3270_size_allocate ( GtkWidget * widget, | 72 | static void v3270_size_allocate ( GtkWidget * widget, |
73 | GtkAllocation * allocation ); | 73 | GtkAllocation * allocation ); |
74 | -// Signals | ||
75 | -static void v3270_activate (GtkWidget *widget); | 74 | +static gboolean v3270_focus_in_event(GtkWidget *widget, GdkEventFocus *event); |
75 | +static gboolean v3270_focus_out_event(GtkWidget *widget, GdkEventFocus *event); | ||
76 | 76 | ||
77 | -gboolean v3270_focus_in_event(GtkWidget *widget, GdkEventFocus *event); | ||
78 | -gboolean v3270_focus_out_event(GtkWidget *widget, GdkEventFocus *event); | ||
79 | - | ||
80 | -static void v3270_destroy (GtkWidget * object); | 77 | +static void v3270_destroy (GtkWidget * object); |
81 | 78 | ||
82 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 79 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
83 | 80 | ||
84 | -void v3270_cursor_draw(v3270 *widget) | ||
85 | -{ | ||
86 | - int pos = lib3270_get_cursor_address(widget->host); | ||
87 | - unsigned char c; | ||
88 | - unsigned short attr; | ||
89 | - | ||
90 | - lib3270_get_contents(widget->host,pos,pos,&c,&attr); | ||
91 | - v3270_update_cursor_surface(widget,c,attr); | ||
92 | - v3270_queue_draw_area( GTK_WIDGET(widget), | ||
93 | - widget->cursor.rect.x,widget->cursor.rect.y, | ||
94 | - widget->cursor.rect.width,widget->cursor.rect.height); | ||
95 | - | ||
96 | -} | ||
97 | - | ||
98 | static gboolean v3270_popup_menu(GtkWidget * widget) | 81 | static gboolean v3270_popup_menu(GtkWidget * widget) |
99 | { | 82 | { |
100 | GdkEventButton event; | 83 | GdkEventButton event; |
@@ -767,33 +750,6 @@ G_GNUC_INTERNAL void gtk_widget_get_allocation(GtkWidget *widget, GtkAllocation | @@ -767,33 +750,6 @@ G_GNUC_INTERNAL void gtk_widget_get_allocation(GtkWidget *widget, GtkAllocation | ||
767 | #endif // !GTK(2,18) | 750 | #endif // !GTK(2,18) |
768 | 751 | ||
769 | 752 | ||
770 | -LIB3270_EXPORT void v3270_disconnect(GtkWidget *widget) | ||
771 | -{ | ||
772 | - g_return_if_fail(GTK_IS_V3270(widget)); | ||
773 | - v3270_disable_updates(widget); | ||
774 | - debug("%s",__FUNCTION__); | ||
775 | - lib3270_unselect(GTK_V3270(widget)->host); | ||
776 | - debug("%s",__FUNCTION__); | ||
777 | - lib3270_disconnect(GTK_V3270(widget)->host); | ||
778 | - debug("%s",__FUNCTION__); | ||
779 | - v3270_enable_updates(widget); | ||
780 | - debug("%s",__FUNCTION__); | ||
781 | -} | ||
782 | - | ||
783 | -LIB3270_EXPORT H3270 * v3270_get_session(GtkWidget *widget) | ||
784 | -{ | ||
785 | - g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
786 | - | ||
787 | - return GTK_V3270(widget)->host; | ||
788 | -} | ||
789 | - | ||
790 | -LIB3270_EXPORT int v3270_reconnect(GtkWidget *widget) | ||
791 | -{ | ||
792 | - g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); | ||
793 | - | ||
794 | - return lib3270_reconnect(GTK_V3270(widget)->host,0); | ||
795 | -} | ||
796 | - | ||
797 | static gboolean notify_focus(GtkWidget *widget, GdkEventFocus *event) | 753 | static gboolean notify_focus(GtkWidget *widget, GdkEventFocus *event) |
798 | { | 754 | { |
799 | GtkAccessible *obj = GTK_V3270(widget)->accessible; | 755 | GtkAccessible *obj = GTK_V3270(widget)->accessible; |
@@ -803,6 +759,7 @@ static gboolean notify_focus(GtkWidget *widget, GdkEventFocus *event) | @@ -803,6 +759,7 @@ static gboolean notify_focus(GtkWidget *widget, GdkEventFocus *event) | ||
803 | 759 | ||
804 | return FALSE; | 760 | return FALSE; |
805 | } | 761 | } |
762 | + | ||
806 | gboolean v3270_focus_in_event(GtkWidget *widget, GdkEventFocus *event) | 763 | gboolean v3270_focus_in_event(GtkWidget *widget, GdkEventFocus *event) |
807 | { | 764 | { |
808 | v3270 * terminal = GTK_V3270(widget); | 765 | v3270 * terminal = GTK_V3270(widget); |
@@ -821,20 +778,6 @@ gboolean v3270_focus_out_event(GtkWidget *widget, GdkEventFocus *event) | @@ -821,20 +778,6 @@ gboolean v3270_focus_out_event(GtkWidget *widget, GdkEventFocus *event) | ||
821 | return notify_focus(widget,event); | 778 | return notify_focus(widget,event); |
822 | } | 779 | } |
823 | 780 | ||
824 | -static void v3270_activate(GtkWidget *widget) | ||
825 | -{ | ||
826 | - v3270 * terminal = GTK_V3270(widget); | ||
827 | - | ||
828 | - terminal->activity.timestamp = time(0); | ||
829 | - | ||
830 | - if(lib3270_is_connected(terminal->host)) | ||
831 | - lib3270_enter(terminal->host); | ||
832 | - else if(lib3270_get_url(terminal->host)) | ||
833 | - v3270_reconnect(widget); | ||
834 | - else | ||
835 | - g_warning("Terminal widget %p activated without connection or valid url",terminal); | ||
836 | -} | ||
837 | - | ||
838 | const GtkWidgetClass * v3270_get_parent_class(void) | 781 | const GtkWidgetClass * v3270_get_parent_class(void) |
839 | { | 782 | { |
840 | return GTK_WIDGET_CLASS(v3270_parent_class); | 783 | return GTK_WIDGET_CLASS(v3270_parent_class); |
@@ -845,125 +788,3 @@ LIB3270_EXPORT GtkIMContext * v3270_get_im_context(GtkWidget *widget) | @@ -845,125 +788,3 @@ LIB3270_EXPORT GtkIMContext * v3270_get_im_context(GtkWidget *widget) | ||
845 | return GTK_V3270(widget)->input_method; | 788 | return GTK_V3270(widget)->input_method; |
846 | } | 789 | } |
847 | 790 | ||
848 | -/** | ||
849 | - * v3270_set_url: | ||
850 | - * | ||
851 | - * @widget: V3270 widget. | ||
852 | - * @uri: a valid tn3270 URL. | ||
853 | - * | ||
854 | - * Set the default URL for the tn3270e host. | ||
855 | - * | ||
856 | - * Since: 5.0 | ||
857 | - **/ | ||
858 | -LIB3270_EXPORT void v3270_set_url(GtkWidget *widget, const gchar *uri) | ||
859 | -{ | ||
860 | - g_return_if_fail(GTK_IS_V3270(widget)); | ||
861 | - lib3270_set_url(GTK_V3270(widget)->host,uri); | ||
862 | -} | ||
863 | - | ||
864 | -LIB3270_EXPORT const gchar * v3270_get_url(GtkWidget *widget) | ||
865 | -{ | ||
866 | - g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
867 | - return lib3270_get_url(GTK_V3270(widget)->host); | ||
868 | -} | ||
869 | - | ||
870 | -LIB3270_EXPORT const gchar * v3270_get_luname(GtkWidget *widget) | ||
871 | -{ | ||
872 | - g_return_val_if_fail(GTK_IS_V3270(widget),""); | ||
873 | - return lib3270_get_luname(GTK_V3270(widget)->host); | ||
874 | -} | ||
875 | - | ||
876 | -LIB3270_EXPORT const gchar * v3270_get_session_name(GtkWidget *widget) | ||
877 | -{ | ||
878 | -#ifdef DEBUG | ||
879 | - v3270 * terminal = GTK_V3270(widget); | ||
880 | - debug("Session name: [%s] Application name: [%s]",terminal->session_name, g_get_application_name()); | ||
881 | -#endif // DEBUG | ||
882 | - | ||
883 | - if(!(GTK_IS_V3270(widget) && GTK_V3270(widget)->session_name)) | ||
884 | - return g_get_application_name(); | ||
885 | - | ||
886 | - return GTK_V3270(widget)->session_name; | ||
887 | -} | ||
888 | - | ||
889 | -LIB3270_EXPORT void v3270_set_session_name(GtkWidget *widget, const gchar *name) | ||
890 | -{ | ||
891 | - g_return_if_fail(GTK_IS_V3270(widget)); | ||
892 | - g_return_if_fail(name != NULL); | ||
893 | - | ||
894 | - if(GTK_V3270(widget)->session_name) { | ||
895 | - | ||
896 | - debug("Old session name was \"%s\"",GTK_V3270(widget)->session_name); | ||
897 | - | ||
898 | - if(!strcmp(GTK_V3270(widget)->session_name,name)) { | ||
899 | - // Same session name, keep it. | ||
900 | - return; | ||
901 | - } | ||
902 | - | ||
903 | - g_free(GTK_V3270(widget)->session_name); | ||
904 | - | ||
905 | - } | ||
906 | - | ||
907 | - GTK_V3270(widget)->session_name = g_strdup(name); | ||
908 | - | ||
909 | - debug("New session name is \"%s\"",GTK_V3270(widget)->session_name); | ||
910 | - | ||
911 | - g_signal_emit(GTK_WIDGET(widget), v3270_widget_signal[V3270_SIGNAL_SESSION_CHANGED], 0); | ||
912 | - | ||
913 | -} | ||
914 | - | ||
915 | -LIB3270_EXPORT int v3270_set_host_type(GtkWidget *widget, LIB3270_HOST_TYPE type) | ||
916 | -{ | ||
917 | - g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); | ||
918 | - return lib3270_set_host_type(GTK_V3270(widget)->host, type); | ||
919 | -} | ||
920 | - | ||
921 | -LIB3270_EXPORT int v3270_set_host_type_by_name(GtkWidget *widget, const char *name) | ||
922 | -{ | ||
923 | - g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); | ||
924 | - return lib3270_set_host_type_by_name(GTK_V3270(widget)->host,name); | ||
925 | -} | ||
926 | - | ||
927 | -LIB3270_EXPORT gboolean v3270_is_connected(GtkWidget *widget) | ||
928 | -{ | ||
929 | - g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); | ||
930 | - return lib3270_is_connected(GTK_V3270(widget)->host) ? TRUE : FALSE; | ||
931 | -} | ||
932 | - | ||
933 | -LIB3270_EXPORT int v3270_set_host_charset(GtkWidget *widget, const gchar *name) | ||
934 | -{ | ||
935 | - g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); | ||
936 | - return lib3270_set_host_charset(GTK_V3270(widget)->host,name); | ||
937 | -} | ||
938 | - | ||
939 | -/* | ||
940 | -LIB3270_EXPORT GtkWidget * v3270_get_default_widget(void) | ||
941 | -{ | ||
942 | - H3270 * hSession = lib3270_get_default_session_handle(); | ||
943 | - | ||
944 | - if(!hSession) | ||
945 | - { | ||
946 | - g_warning("%s: No default session available",__FUNCTION__); | ||
947 | - return NULL; | ||
948 | - } | ||
949 | - | ||
950 | - GtkWidget *widget = lib3270_get_user_data(hSession); | ||
951 | - | ||
952 | - if(!(widget && GTK_IS_V3270(widget))) | ||
953 | - { | ||
954 | - g_warning("%s: Can't determine default widget",__FUNCTION__); | ||
955 | - return NULL; | ||
956 | - } | ||
957 | - | ||
958 | - return GTK_WIDGET(widget); | ||
959 | -} | ||
960 | -*/ | ||
961 | - | ||
962 | -void v3270_set_cursor(GtkWidget *widget, LIB3270_POINTER id) | ||
963 | -{ | ||
964 | - gdk_window_set_cursor( | ||
965 | - gtk_widget_get_window(widget), | ||
966 | - GTK_V3270_GET_CLASS(widget)->cursors[id % LIB3270_POINTER_COUNT] | ||
967 | - ); | ||
968 | -} | ||
969 | - |
v3270.cbp
@@ -202,6 +202,9 @@ | @@ -202,6 +202,9 @@ | ||
202 | <Unit filename="src/terminal/accessible.c"> | 202 | <Unit filename="src/terminal/accessible.c"> |
203 | <Option compilerVar="CC" /> | 203 | <Option compilerVar="CC" /> |
204 | </Unit> | 204 | </Unit> |
205 | + <Unit filename="src/terminal/actions.c"> | ||
206 | + <Option compilerVar="CC" /> | ||
207 | + </Unit> | ||
205 | <Unit filename="src/terminal/blink.c"> | 208 | <Unit filename="src/terminal/blink.c"> |
206 | <Option compilerVar="CC" /> | 209 | <Option compilerVar="CC" /> |
207 | </Unit> | 210 | </Unit> |
@@ -214,7 +217,13 @@ | @@ -214,7 +217,13 @@ | ||
214 | <Unit filename="src/terminal/colors.c"> | 217 | <Unit filename="src/terminal/colors.c"> |
215 | <Option compilerVar="CC" /> | 218 | <Option compilerVar="CC" /> |
216 | </Unit> | 219 | </Unit> |
217 | - <Unit filename="src/terminal/draw.c"> | 220 | + <Unit filename="src/terminal/drawing/draw.c"> |
221 | + <Option compilerVar="CC" /> | ||
222 | + </Unit> | ||
223 | + <Unit filename="src/terminal/drawing/oia.c"> | ||
224 | + <Option compilerVar="CC" /> | ||
225 | + </Unit> | ||
226 | + <Unit filename="src/terminal/drawing/surface.c"> | ||
218 | <Option compilerVar="CC" /> | 227 | <Option compilerVar="CC" /> |
219 | </Unit> | 228 | </Unit> |
220 | <Unit filename="src/terminal/font/actions.c"> | 229 | <Unit filename="src/terminal/font/actions.c"> |
@@ -249,9 +258,6 @@ | @@ -249,9 +258,6 @@ | ||
249 | <Unit filename="src/terminal/mouse.c"> | 258 | <Unit filename="src/terminal/mouse.c"> |
250 | <Option compilerVar="CC" /> | 259 | <Option compilerVar="CC" /> |
251 | </Unit> | 260 | </Unit> |
252 | - <Unit filename="src/terminal/oia.c"> | ||
253 | - <Option compilerVar="CC" /> | ||
254 | - </Unit> | ||
255 | <Unit filename="src/terminal/properties/get.c"> | 261 | <Unit filename="src/terminal/properties/get.c"> |
256 | <Option compilerVar="CC" /> | 262 | <Option compilerVar="CC" /> |
257 | </Unit> | 263 | </Unit> |
@@ -268,9 +274,6 @@ | @@ -268,9 +274,6 @@ | ||
268 | <Unit filename="src/terminal/security.c"> | 274 | <Unit filename="src/terminal/security.c"> |
269 | <Option compilerVar="CC" /> | 275 | <Option compilerVar="CC" /> |
270 | </Unit> | 276 | </Unit> |
271 | - <Unit filename="src/terminal/surface.c"> | ||
272 | - <Option compilerVar="CC" /> | ||
273 | - </Unit> | ||
274 | <Unit filename="src/terminal/widget.c"> | 277 | <Unit filename="src/terminal/widget.c"> |
275 | <Option compilerVar="CC" /> | 278 | <Option compilerVar="CC" /> |
276 | </Unit> | 279 | </Unit> |