Commit 2d3ee143241e94cad65afb91a3c84897ecb39f3a
1 parent
e5b11a32
Exists in
master
and in
1 other branch
Adjustments on trace widget.
Showing
9 changed files
with
299 additions
and
173 deletions
Show diff stats
src/dialogs/togglebutton.c
... | ... | @@ -65,6 +65,8 @@ |
65 | 65 | widget->hListener = NULL; |
66 | 66 | } |
67 | 67 | |
68 | + widget->hSession = NULL; | |
69 | + | |
68 | 70 | G_OBJECT_CLASS(V3270ToggleButton_parent_class)->dispose(object); |
69 | 71 | |
70 | 72 | } |
... | ... | @@ -104,22 +106,57 @@ |
104 | 106 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),(state == 0 ? FALSE : TRUE)); |
105 | 107 | } |
106 | 108 | |
107 | - GtkWidget * v3270_toggle_button_new(GtkWidget *terminal, LIB3270_TOGGLE_ID toggle) | |
109 | + GtkWidget * v3270_toggle_button_new(LIB3270_TOGGLE_ID id) | |
108 | 110 | { |
109 | - g_return_val_if_fail(GTK_IS_V3270(terminal),NULL); | |
111 | + const LIB3270_TOGGLE * toggle = lib3270_toggle_get_from_id(id); | |
112 | + | |
113 | + if(!toggle) | |
114 | + return NULL; | |
110 | 115 | |
111 | 116 | V3270ToggleButton * widget = GTK_V3270_TOGGLE_BUTTON(g_object_new(GTK_TYPE_V3270_TOGGLE_BUTTON, NULL)); |
112 | 117 | |
113 | - widget->hSession = v3270_get_session(terminal); | |
114 | - widget->id = toggle; | |
118 | + widget->id = id; | |
115 | 119 | |
116 | - widget->hListener = lib3270_register_toggle_listener(widget->hSession, widget->id,toggle_listener,widget); | |
120 | + gtk_widget_set_name(GTK_WIDGET(widget),toggle->name); | |
121 | + gtk_button_set_label(GTK_BUTTON(widget),gettext(toggle->label)); | |
117 | 122 | |
118 | - gtk_widget_set_name(GTK_WIDGET(widget),lib3270_get_toggle_name(toggle)); | |
119 | - gtk_button_set_label(GTK_BUTTON(widget),gettext(lib3270_get_toggle_label(toggle))); | |
120 | - gtk_widget_set_tooltip_text(GTK_WIDGET(widget),gettext(lib3270_get_toggle_description(toggle))); | |
123 | + if(toggle->description) | |
124 | + gtk_widget_set_tooltip_text(GTK_WIDGET(widget),gettext(toggle->description)); | |
125 | + else if(toggle->summary) | |
126 | + gtk_widget_set_tooltip_text(GTK_WIDGET(widget),gettext(toggle->summary)); | |
121 | 127 | |
122 | - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),lib3270_get_toggle(widget->hSession, widget->id)); | |
128 | + gtk_widget_set_sensitive(GTK_WIDGET(widget),FALSE); | |
123 | 129 | |
124 | 130 | return GTK_WIDGET(widget); |
125 | 131 | } |
132 | + | |
133 | + G_GNUC_INTERNAL void v3270_toggle_button_set_session(GtkWidget *button, H3270 *hSession) | |
134 | + { | |
135 | + V3270ToggleButton * toggle = GTK_V3270_TOGGLE_BUTTON(button); | |
136 | + | |
137 | + if(toggle->hSession == hSession) | |
138 | + return; | |
139 | + | |
140 | + // Disconnect from current session | |
141 | + if(toggle->hListener) | |
142 | + { | |
143 | + lib3270_unregister_toggle_listener(toggle->hSession,toggle->id,toggle->hListener); | |
144 | + toggle->hListener = NULL; | |
145 | + } | |
146 | + | |
147 | + // Replace session. | |
148 | + toggle->hSession = hSession; | |
149 | + | |
150 | + // Connect to new session. | |
151 | + if(toggle->hSession) | |
152 | + { | |
153 | + toggle->hListener = lib3270_register_toggle_listener(toggle->hSession, toggle->id,toggle_listener,toggle); | |
154 | + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle),lib3270_get_toggle(toggle->hSession, toggle->id)); | |
155 | + gtk_widget_set_sensitive(GTK_WIDGET(toggle),TRUE); | |
156 | + } | |
157 | + else | |
158 | + { | |
159 | + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle),FALSE); | |
160 | + gtk_widget_set_sensitive(GTK_WIDGET(toggle),FALSE); | |
161 | + } | |
162 | + } | ... | ... |
src/include/internals.h
... | ... | @@ -160,7 +160,8 @@ |
160 | 160 | typedef struct _V3270ToggleButton V3270ToggleButton; |
161 | 161 | typedef struct _V3270ToggleButtonClass V3270ToggleButtonClass; |
162 | 162 | |
163 | - G_GNUC_INTERNAL GtkWidget * v3270_toggle_button_new(GtkWidget *widget, LIB3270_TOGGLE_ID toggle); | |
163 | + G_GNUC_INTERNAL GtkWidget * v3270_toggle_button_new(LIB3270_TOGGLE_ID toggle); | |
164 | + G_GNUC_INTERNAL void v3270_toggle_button_set_session(GtkWidget *button, H3270 *hSession); | |
164 | 165 | |
165 | 166 | // Activity list widget. |
166 | 167 | #define GTK_TYPE_V3270_FT_ACTIVITY_LIST (V3270FTActivityList_get_type ()) | ... | ... |
src/include/terminal.h
... | ... | @@ -114,15 +114,6 @@ G_BEGIN_DECLS |
114 | 114 | int scaled_fonts : 1; /**< Use scaled fonts */ |
115 | 115 | int drawing : 1; /**< Draw widget? */ |
116 | 116 | |
117 | - /* | |
118 | -#if GTK_CHECK_VERSION(3,0,0) | |
119 | - | |
120 | -#else | |
121 | - gint width; | |
122 | - gint height; | |
123 | -#endif // GTK_CHECK_VERSION(3,0,0) | |
124 | - */ | |
125 | - | |
126 | 117 | GSource * timer; |
127 | 118 | GtkIMContext * input_method; |
128 | 119 | unsigned short keyflags; |
... | ... | @@ -186,15 +177,17 @@ G_BEGIN_DECLS |
186 | 177 | GSource * timer; /**< Auto disconnect timer */ |
187 | 178 | } activity; |
188 | 179 | |
189 | - char script; /**< @brief Script ID */ | |
180 | + char script; ///< @brief Script ID. | |
190 | 181 | |
191 | 182 | // Blink |
192 | 183 | struct |
193 | 184 | { |
194 | - int show : 1; /**< @brief Show element? */ | |
195 | - GSource * timer; /**< @brief Timer source. */ | |
185 | + int show : 1; ///< @brief Show element? | |
186 | + GSource * timer; ///< @brief Timer source. | |
196 | 187 | } blink; |
197 | 188 | |
189 | + GtkWidget * trace; ///< @brief Trace window handle. | |
190 | + | |
198 | 191 | }; |
199 | 192 | |
200 | 193 | G_GNUC_INTERNAL void v3270_activate(GtkWidget *widget); | ... | ... |
src/include/v3270/trace.h
... | ... | @@ -49,6 +49,9 @@ |
49 | 49 | |
50 | 50 | LIB3270_EXPORT GType V3270Trace_get_type(void); |
51 | 51 | |
52 | + LIB3270_EXPORT gboolean v3270_get_trace(GtkWidget *terminal); | |
53 | + LIB3270_EXPORT void v3270_set_trace(GtkWidget *terminal, gboolean trace); | |
54 | + | |
52 | 55 | LIB3270_EXPORT GtkWidget * v3270_trace_new(GtkWidget *terminal); |
53 | 56 | LIB3270_EXPORT void v3270_trace_append_text(GtkWidget *widget, const gchar *text); |
54 | 57 | LIB3270_EXPORT void v3270_trace_vprintf(GtkWidget *widget, const char *fmt, va_list args); | ... | ... |
src/trace/exec.c
... | ... | @@ -149,8 +149,8 @@ |
149 | 149 | |
150 | 150 | g_return_val_if_fail(GTK_IS_V3270_TRACE(t),EINVAL); |
151 | 151 | |
152 | - V3270Trace * trace = GTK_V3270_TRACE(t); | |
153 | - H3270 * hSession = v3270_get_session(trace->terminal); | |
152 | + GtkWidget * terminal = v3270_trace_get_terminal(t); | |
153 | + H3270 * hSession = v3270_trace_get_session(t); | |
154 | 154 | g_autofree gchar * cmdline = g_strdup(text); |
155 | 155 | |
156 | 156 | g_strstrip(cmdline); |
... | ... | @@ -159,13 +159,13 @@ |
159 | 159 | |
160 | 160 | if(g_str_has_prefix(cmdline,"reload")) |
161 | 161 | { |
162 | - v3270_reload(trace->terminal); | |
162 | + v3270_reload(terminal); | |
163 | 163 | return 0; |
164 | 164 | } |
165 | 165 | |
166 | 166 | if(g_str_has_prefix(cmdline,"reconfigure")) |
167 | 167 | { |
168 | - v3270_reconfigure(GTK_V3270(trace->terminal)); | |
168 | + v3270_reconfigure(GTK_V3270(terminal)); | |
169 | 169 | return 0; |
170 | 170 | } |
171 | 171 | |
... | ... | @@ -184,15 +184,15 @@ |
184 | 184 | if(!(*arg && g_ascii_strcasecmp(arg,"text"))) |
185 | 185 | { |
186 | 186 | // No argument or "text" copy text. |
187 | - v3270_clipboard_set(trace->terminal, V3270_COPY_TEXT, FALSE); | |
187 | + v3270_clipboard_set(terminal, V3270_COPY_TEXT, FALSE); | |
188 | 188 | } |
189 | 189 | else if(!g_ascii_strcasecmp(arg,"table")) |
190 | 190 | { |
191 | - v3270_clipboard_set(trace->terminal, V3270_COPY_TABLE, FALSE); | |
191 | + v3270_clipboard_set(terminal, V3270_COPY_TABLE, FALSE); | |
192 | 192 | } |
193 | 193 | else if(!g_ascii_strcasecmp(arg,"append")) |
194 | 194 | { |
195 | - v3270_clipboard_set(trace->terminal, V3270_COPY_APPEND, FALSE); | |
195 | + v3270_clipboard_set(terminal, V3270_COPY_APPEND, FALSE); | |
196 | 196 | } |
197 | 197 | else |
198 | 198 | { |
... | ... | @@ -212,15 +212,15 @@ |
212 | 212 | if(!(*arg && g_ascii_strcasecmp(arg,"all"))) |
213 | 213 | { |
214 | 214 | // No argument or "text" copy text. |
215 | - v3270_print_all(trace->terminal,NULL); | |
215 | + v3270_print_all(terminal,NULL); | |
216 | 216 | } |
217 | 217 | else if(!g_ascii_strcasecmp(arg,"selected")) |
218 | 218 | { |
219 | - v3270_print_selected(trace->terminal,NULL); | |
219 | + v3270_print_selected(terminal,NULL); | |
220 | 220 | } |
221 | 221 | else if(!g_ascii_strcasecmp(arg,"copy")) |
222 | 222 | { |
223 | - v3270_print_copy(trace->terminal,NULL); | |
223 | + v3270_print_copy(terminal,NULL); | |
224 | 224 | } |
225 | 225 | else |
226 | 226 | { |
... | ... | @@ -237,7 +237,7 @@ |
237 | 237 | gchar * arg = cmdline+5; |
238 | 238 | g_strstrip(arg); |
239 | 239 | |
240 | - v3270_clipboard_get_from_url(trace->terminal,arg); | |
240 | + v3270_clipboard_get_from_url(terminal,arg); | |
241 | 241 | |
242 | 242 | return 0; |
243 | 243 | } |
... | ... | @@ -247,7 +247,7 @@ |
247 | 247 | gchar * str = strchr(cmdline,'?'); |
248 | 248 | *str = 0; |
249 | 249 | g_strstrip(cmdline); |
250 | - return get_property(trace->terminal,cmdline); | |
250 | + return get_property(terminal,cmdline); | |
251 | 251 | } |
252 | 252 | |
253 | 253 | if(strchr(cmdline,'=')) |
... | ... | @@ -256,14 +256,14 @@ |
256 | 256 | *(value++) = 0; |
257 | 257 | g_strstrip(cmdline); |
258 | 258 | g_strstrip(value); |
259 | - return set_property(trace->terminal,cmdline,value); | |
259 | + return set_property(terminal,cmdline,value); | |
260 | 260 | } |
261 | 261 | |
262 | 262 | if(g_str_has_prefix(cmdline,"remap")) |
263 | 263 | { |
264 | 264 | gchar *txtptr = cmdline+5; |
265 | 265 | g_strstrip(txtptr); |
266 | - v3270_set_remap_filename(trace->terminal,txtptr); | |
266 | + v3270_set_remap_filename(terminal,txtptr); | |
267 | 267 | return 0; |
268 | 268 | } |
269 | 269 | |
... | ... | @@ -272,7 +272,7 @@ |
272 | 272 | gchar *txtptr = cmdline+3; |
273 | 273 | const gchar * name = get_word(&txtptr); |
274 | 274 | g_strstrip(txtptr); |
275 | - return set_property(trace->terminal,name,(*txtptr ? txtptr : "1")); | |
275 | + return set_property(terminal,name,(*txtptr ? txtptr : "1")); | |
276 | 276 | } |
277 | 277 | |
278 | 278 | if(g_str_has_prefix(cmdline,"get")) |
... | ... | @@ -280,7 +280,7 @@ |
280 | 280 | gchar *txtptr = cmdline+3; |
281 | 281 | const gchar * name = get_word(&txtptr); |
282 | 282 | g_strstrip(txtptr); |
283 | - return get_property(trace->terminal,name); | |
283 | + return get_property(terminal,name); | |
284 | 284 | } |
285 | 285 | |
286 | 286 | if(g_str_has_prefix(cmdline,"reset")) |
... | ... | @@ -288,14 +288,14 @@ |
288 | 288 | gchar *txtptr = cmdline+3; |
289 | 289 | const gchar * name = get_word(&txtptr); |
290 | 290 | g_strstrip(txtptr); |
291 | - return set_property(trace->terminal,name,(*txtptr ? txtptr : "0")); | |
291 | + return set_property(terminal,name,(*txtptr ? txtptr : "0")); | |
292 | 292 | } |
293 | 293 | |
294 | 294 | gchar * sep = strchr(cmdline,'='); |
295 | 295 | if(sep) |
296 | 296 | { |
297 | 297 | *(sep++) = 0; |
298 | - return set_property(trace->terminal,g_strstrip(cmdline),g_strstrip(sep)); | |
298 | + return set_property(terminal,g_strstrip(cmdline),g_strstrip(sep)); | |
299 | 299 | } |
300 | 300 | else |
301 | 301 | { |
... | ... | @@ -316,7 +316,7 @@ |
316 | 316 | if(*args) |
317 | 317 | *(args++) = 0; |
318 | 318 | |
319 | - g_signal_emit(GTK_WIDGET(trace), v3270_trace_signal[V3270_TRACE_SIGNAL_COMMAND], 0, cmdline, args, &handled); | |
319 | + g_signal_emit(GTK_WIDGET(t), v3270_trace_signal[V3270_TRACE_SIGNAL_COMMAND], 0, cmdline, args, &handled); | |
320 | 320 | |
321 | 321 | if(handled) |
322 | 322 | return 0; | ... | ... |
src/trace/private.h
... | ... | @@ -56,40 +56,15 @@ |
56 | 56 | |
57 | 57 | G_GNUC_INTERNAL guint v3270_trace_signal[V3270_TRACE_SIGNAL_LAST]; |
58 | 58 | |
59 | - G_BEGIN_DECLS | |
60 | - | |
61 | - struct _V3270TraceClass | |
62 | - { | |
63 | - GtkBoxClass parent_class; | |
64 | - | |
65 | - }; | |
66 | - | |
67 | - struct _V3270Trace | |
68 | - { | |
59 | + G_GNUC_INTERNAL H3270 * v3270_trace_get_session(GtkWidget *widget); | |
60 | + G_GNUC_INTERNAL GtkWidget * v3270_trace_get_terminal(GtkWidget *widget); | |
61 | + G_GNUC_INTERNAL GtkTextBuffer * v3270_trace_get_text_buffer(GtkWidget *widget); | |
62 | + G_GNUC_INTERNAL GtkScrolledWindow * v3270_trace_get_scrolled_window(GtkWidget *widget); | |
69 | 63 | |
70 | - GtkBox parent; | |
71 | - H3270 * hSession; ///< @brief TN3270 Session. | |
72 | - GtkWidget * terminal; ///< @brief V3270 Widget. | |
73 | - GtkScrolledWindow * scroll; | |
74 | - | |
75 | - GtkTextView * view; ///< @brief Text view; | |
76 | - GtkTextBuffer * text; ///< @brief Trace window contents. | |
77 | - GtkEntry * entry; ///< @brief Command line entry. | |
78 | - GtkWidget * buttons; ///< @brief Button bar. | |
79 | - | |
80 | - gchar * filename; ///< @brief Selected file name. | |
81 | - | |
82 | - guint log_handler; ///< @brief GTK Log Handler. | |
83 | - | |
84 | - /// @brief lib3270's saved trace handler. | |
85 | - struct { | |
86 | - void (*handler)(H3270 *session, void *userdata, const char *fmt, va_list args); | |
87 | - void *userdata; | |
88 | - } trace; | |
64 | + G_BEGIN_DECLS | |
89 | 65 | |
90 | - }; | |
91 | 66 | |
92 | - G_END_DECLS | |
67 | + G_END_DECLS | |
93 | 68 | |
94 | 69 | |
95 | 70 | ... | ... |
... | ... | @@ -0,0 +1,94 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como - e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * | |
28 | + */ | |
29 | + | |
30 | + #include "private.h" | |
31 | + | |
32 | + #include <lib3270/toggle.h> | |
33 | + #include <lib3270/properties.h> | |
34 | + #include <internals.h> | |
35 | + #include <v3270/dialogs.h> | |
36 | + | |
37 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
38 | + | |
39 | + struct _append_text | |
40 | + { | |
41 | + GtkWidget * widget; | |
42 | + gchar text[1]; | |
43 | + }; | |
44 | + | |
45 | + static gboolean bg_append_text(struct _append_text *cfg) | |
46 | + { | |
47 | + GtkTextBuffer * buffer = v3270_trace_get_text_buffer(cfg->widget); | |
48 | + | |
49 | + GtkTextIter itr; | |
50 | + gtk_text_buffer_get_end_iter(buffer,&itr); | |
51 | + | |
52 | + if(g_utf8_validate(cfg->text,strlen(cfg->text),NULL)) | |
53 | + gtk_text_buffer_insert(buffer,&itr,cfg->text,strlen(cfg->text)); | |
54 | + else | |
55 | + gtk_text_buffer_insert(buffer,&itr,"** Invalid UTF8 String **",-1); | |
56 | + | |
57 | + // Move window | |
58 | + GtkScrolledWindow * scrolled = v3270_trace_get_scrolled_window(cfg->widget); | |
59 | + GtkAdjustment * vadj = gtk_scrolled_window_get_vadjustment(scrolled); | |
60 | + | |
61 | + gtk_adjustment_set_value(vadj,gtk_adjustment_get_upper(vadj)); | |
62 | + gtk_scrolled_window_set_vadjustment(scrolled, vadj); | |
63 | + | |
64 | + return FALSE; | |
65 | + | |
66 | + } | |
67 | + | |
68 | + LIB3270_EXPORT void v3270_trace_append_text(GtkWidget *widget, const gchar *text) | |
69 | + { | |
70 | + g_return_if_fail(GTK_IS_V3270_TRACE(widget)); | |
71 | + | |
72 | + // Enqueue update. | |
73 | + struct _append_text * cfg = g_malloc0(sizeof(struct _append_text)+strlen(text)+1); | |
74 | + cfg->widget = GTK_V3270_TRACE(widget); | |
75 | + strcpy(cfg->text,text); | |
76 | + | |
77 | + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,(GSourceFunc) bg_append_text, cfg, g_free); | |
78 | + | |
79 | + } | |
80 | + | |
81 | + LIB3270_EXPORT void v3270_trace_vprintf(GtkWidget *widget, const char *fmt, va_list args) | |
82 | + { | |
83 | + g_autofree gchar * text = g_strdup_vprintf(fmt,args); | |
84 | + v3270_trace_append_text(widget,text); | |
85 | + } | |
86 | + | |
87 | + LIB3270_EXPORT void v3270_trace_printf(GtkWidget *widget, const char *fmt, ... ) | |
88 | + { | |
89 | + va_list arg_ptr; | |
90 | + va_start(arg_ptr, fmt); | |
91 | + v3270_trace_vprintf(widget,fmt,arg_ptr); | |
92 | + va_end(arg_ptr); | |
93 | + } | |
94 | + | ... | ... |
src/trace/trace.c
... | ... | @@ -38,13 +38,58 @@ |
38 | 38 | |
39 | 39 | #include "private.h" |
40 | 40 | |
41 | + #include <terminal.h> | |
41 | 42 | #include <lib3270/toggle.h> |
42 | 43 | #include <lib3270/properties.h> |
43 | 44 | #include <internals.h> |
44 | 45 | #include <v3270/dialogs.h> |
45 | 46 | #include "marshal.h" |
46 | 47 | |
47 | -/*--[ Widget definition ]----------------------------------------------------------------------------*/ | |
48 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
49 | + | |
50 | + static const LIB3270_TOGGLE_ID toggles[] = { | |
51 | + LIB3270_TOGGLE_DS_TRACE, | |
52 | + LIB3270_TOGGLE_NETWORK_TRACE, | |
53 | + LIB3270_TOGGLE_EVENT_TRACE, | |
54 | + LIB3270_TOGGLE_SSL_TRACE, | |
55 | + LIB3270_TOGGLE_SCREEN_TRACE | |
56 | + }; | |
57 | + | |
58 | + struct _V3270TraceClass | |
59 | + { | |
60 | + GtkBoxClass parent_class; | |
61 | + | |
62 | + }; | |
63 | + | |
64 | + struct _V3270Trace | |
65 | + { | |
66 | + | |
67 | + GtkBox parent; | |
68 | + H3270 * hSession; ///< @brief TN3270 Session. | |
69 | + GtkWidget * terminal; ///< @brief V3270 Widget. | |
70 | + GtkScrolledWindow * scroll; | |
71 | + | |
72 | + GtkTextView * view; ///< @brief Text view; | |
73 | + GtkTextBuffer * text; ///< @brief Trace window contents. | |
74 | + GtkEntry * entry; ///< @brief Command line entry. | |
75 | + | |
76 | + struct | |
77 | + { | |
78 | + GtkWidget * box; ///< @brief Button box. | |
79 | + GtkWidget * widgets[G_N_ELEMENTS(toggles)]; | |
80 | + } buttons; | |
81 | + | |
82 | + gchar * filename; ///< @brief Selected file name. | |
83 | + | |
84 | + guint log_handler; ///< @brief GTK Log Handler. | |
85 | + | |
86 | + /// @brief lib3270's saved trace handler. | |
87 | + struct { | |
88 | + void (*handler)(H3270 *session, void *userdata, const char *fmt, va_list args); | |
89 | + void *userdata; | |
90 | + } trace; | |
91 | + | |
92 | + }; | |
48 | 93 | |
49 | 94 | guint v3270_trace_signal[V3270_TRACE_SIGNAL_LAST] = { 0 }; |
50 | 95 | |
... | ... | @@ -80,6 +125,11 @@ |
80 | 125 | lib3270_set_trace_handler(hSession,trace_handler,(void *) widget); |
81 | 126 | } |
82 | 127 | |
128 | + // v3270_toggle_button_set_session | |
129 | + size_t ix; | |
130 | + for(ix = 0; ix < G_N_ELEMENTS(toggles); ix++) | |
131 | + v3270_toggle_button_set_session(widget->buttons.widgets[ix],hSession); | |
132 | + | |
83 | 133 | } |
84 | 134 | |
85 | 135 | static void finalize(GObject *object) |
... | ... | @@ -100,7 +150,17 @@ |
100 | 150 | trace->log_handler = 0; |
101 | 151 | } |
102 | 152 | |
103 | - set_session(trace,NULL); | |
153 | + if(trace->terminal && GTK_V3270(trace->terminal)->trace == GTK_WIDGET(object)) | |
154 | + { | |
155 | + debug("V3270Trace::%s - Removing trace widget association",__FUNCTION__); | |
156 | + GTK_V3270(trace->terminal)->trace = NULL; | |
157 | + } | |
158 | + | |
159 | + if(trace->hSession) { | |
160 | + lib3270_set_trace_handler(trace->hSession,trace->trace.handler,trace->trace.userdata); | |
161 | + trace->hSession = NULL; | |
162 | + } | |
163 | + | |
104 | 164 | g_clear_object(&trace->terminal); |
105 | 165 | |
106 | 166 | G_OBJECT_CLASS(V3270Trace_parent_class)->finalize(object); |
... | ... | @@ -224,17 +284,16 @@ |
224 | 284 | gtk_orientable_set_orientation(GTK_ORIENTABLE(widget),GTK_ORIENTATION_VERTICAL); |
225 | 285 | |
226 | 286 | // Create toolbar |
287 | + GtkWidget *buttons = widget->buttons.box = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); | |
227 | 288 | { |
228 | - widget->buttons = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); | |
229 | - | |
230 | 289 | // https://developer.gnome.org/hig/stable/visual-layout.html.en |
231 | - gtk_container_set_border_width(GTK_CONTAINER(widget->buttons), 12); | |
232 | - gtk_box_set_spacing(GTK_BOX(widget->buttons),12); | |
290 | + gtk_container_set_border_width(GTK_CONTAINER(buttons), 12); | |
291 | + gtk_box_set_spacing(GTK_BOX(buttons),12); | |
233 | 292 | |
234 | - gtk_button_box_set_layout(GTK_BUTTON_BOX(widget->buttons), GTK_BUTTONBOX_START); | |
293 | + gtk_button_box_set_layout(GTK_BUTTON_BOX(buttons), GTK_BUTTONBOX_START); | |
235 | 294 | |
236 | - gtk_widget_set_valign(widget->buttons,GTK_ALIGN_START); | |
237 | - gtk_box_pack_start(GTK_BOX(widget),widget->buttons,FALSE,FALSE,0); | |
295 | + gtk_widget_set_valign(buttons,GTK_ALIGN_START); | |
296 | + gtk_box_pack_start(GTK_BOX(widget),buttons,FALSE,FALSE,0); | |
238 | 297 | |
239 | 298 | } |
240 | 299 | |
... | ... | @@ -282,6 +341,26 @@ |
282 | 341 | |
283 | 342 | } |
284 | 343 | |
344 | + // Create toggle buttons | |
345 | + { | |
346 | + size_t ix; | |
347 | + | |
348 | + for(ix = 0; ix < G_N_ELEMENTS(toggles); ix++) | |
349 | + { | |
350 | + GtkWidget * item = widget->buttons.widgets[ix] = v3270_toggle_button_new(toggles[ix]); | |
351 | + | |
352 | + gtk_widget_set_can_focus(item,FALSE); | |
353 | + gtk_widget_set_can_default(item,FALSE); | |
354 | + | |
355 | +#if GTK_CHECK_VERSION(3,20,0) | |
356 | + gtk_widget_set_focus_on_click(item,FALSE); | |
357 | +#endif // GTK 3,20,0 | |
358 | + | |
359 | + gtk_box_pack_start(GTK_BOX(buttons),item,FALSE,FALSE,0); | |
360 | + | |
361 | + } | |
362 | + } | |
363 | + | |
285 | 364 | // Grab GTK messages. |
286 | 365 | widget->log_handler = g_log_set_handler(NULL,G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,(GLogFunc) log_handler, widget); |
287 | 366 | |
... | ... | @@ -292,7 +371,7 @@ |
292 | 371 | { |
293 | 372 | g_return_val_if_fail(GTK_IS_V3270_TRACE(widget),NULL); |
294 | 373 | |
295 | - return GTK_V3270_TRACE(widget)->buttons; | |
374 | + return GTK_V3270_TRACE(widget)->buttons.box; | |
296 | 375 | |
297 | 376 | } |
298 | 377 | |
... | ... | @@ -307,7 +386,7 @@ |
307 | 386 | gtk_widget_set_focus_on_click(button,FALSE); |
308 | 387 | #endif // GTK 3,20,0 |
309 | 388 | |
310 | - gtk_box_pack_start(GTK_BOX(GTK_V3270_TRACE(widget)->buttons),button,FALSE,FALSE,0); | |
389 | + gtk_box_pack_start(GTK_BOX(GTK_V3270_TRACE(widget)->buttons.box),button,FALSE,FALSE,0); | |
311 | 390 | |
312 | 391 | } |
313 | 392 | |
... | ... | @@ -321,101 +400,12 @@ |
321 | 400 | widget->terminal = terminal; |
322 | 401 | g_object_ref_sink(G_OBJECT(terminal)); |
323 | 402 | set_session(widget, v3270_get_session(widget->terminal)); |
403 | + GTK_V3270(terminal)->trace = GTK_WIDGET(widget); | |
324 | 404 | } |
325 | 405 | |
326 | - // Create toggle buttons | |
327 | - { | |
328 | - size_t ix; | |
329 | - | |
330 | - static const LIB3270_TOGGLE_ID toggles[] = { | |
331 | - LIB3270_TOGGLE_DS_TRACE, | |
332 | - LIB3270_TOGGLE_NETWORK_TRACE, | |
333 | - LIB3270_TOGGLE_EVENT_TRACE, | |
334 | - LIB3270_TOGGLE_SSL_TRACE, | |
335 | - LIB3270_TOGGLE_SCREEN_TRACE | |
336 | - }; | |
337 | - | |
338 | - for(ix = 0; ix < G_N_ELEMENTS(toggles); ix++) | |
339 | - { | |
340 | - GtkWidget * item = v3270_toggle_button_new(widget->terminal,toggles[ix]); | |
341 | - | |
342 | - gtk_widget_set_can_focus(item,FALSE); | |
343 | - gtk_widget_set_can_default(item,FALSE); | |
344 | - | |
345 | -#if GTK_CHECK_VERSION(3,20,0) | |
346 | - gtk_widget_set_focus_on_click(item,FALSE); | |
347 | -#endif // GTK 3,20,0 | |
348 | - | |
349 | - gtk_box_pack_start(GTK_BOX(widget->buttons),item,FALSE,FALSE,0); | |
350 | - | |
351 | - } | |
352 | - } | |
353 | - | |
354 | - | |
355 | 406 | return GTK_WIDGET(widget); |
356 | 407 | } |
357 | 408 | |
358 | - struct _append_text | |
359 | - { | |
360 | - V3270Trace *widget; | |
361 | - gchar text[1]; | |
362 | - }; | |
363 | - | |
364 | - static gboolean bg_append_text(struct _append_text *cfg) | |
365 | - { | |
366 | - if(!GTK_IS_TEXT_BUFFER(cfg->widget->text)) | |
367 | - return FALSE; | |
368 | - | |
369 | - GtkTextIter itr; | |
370 | - gtk_text_buffer_get_end_iter(cfg->widget->text,&itr); | |
371 | - | |
372 | - if(g_utf8_validate(cfg->text,strlen(cfg->text),NULL)) | |
373 | - { | |
374 | - gtk_text_buffer_insert(cfg->widget->text,&itr,cfg->text,strlen(cfg->text)); | |
375 | - } | |
376 | - else | |
377 | - { | |
378 | - gtk_text_buffer_insert(cfg->widget->text,&itr,"** Invalid UTF8 String **",-1); | |
379 | - } | |
380 | - | |
381 | - // gtk_text_buffer_get_end_iter(cfg->widget->text,&itr); | |
382 | - // gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(cfg->widget->view), &itr, 0.0, FALSE, 0.0, 0.0); | |
383 | - | |
384 | - GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(cfg->widget->scroll); | |
385 | - gtk_adjustment_set_value(vadj,gtk_adjustment_get_upper(vadj)); | |
386 | - gtk_scrolled_window_set_vadjustment(cfg->widget->scroll, vadj); | |
387 | - | |
388 | - return FALSE; | |
389 | - | |
390 | - } | |
391 | - | |
392 | - LIB3270_EXPORT void v3270_trace_append_text(GtkWidget *widget, const gchar *text) | |
393 | - { | |
394 | - g_return_if_fail(GTK_IS_V3270_TRACE(widget)); | |
395 | - | |
396 | - // Enqueue update. | |
397 | - struct _append_text * cfg = g_malloc0(sizeof(struct _append_text)+strlen(text)+1); | |
398 | - cfg->widget = GTK_V3270_TRACE(widget); | |
399 | - strcpy(cfg->text,text); | |
400 | - | |
401 | - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,(GSourceFunc) bg_append_text, cfg, g_free); | |
402 | - | |
403 | - } | |
404 | - | |
405 | - LIB3270_EXPORT void v3270_trace_vprintf(GtkWidget *widget, const char *fmt, va_list args) | |
406 | - { | |
407 | - g_autofree gchar * text = g_strdup_vprintf(fmt,args); | |
408 | - v3270_trace_append_text(widget,text); | |
409 | - } | |
410 | - | |
411 | - LIB3270_EXPORT void v3270_trace_printf(GtkWidget *widget, const char *fmt, ... ) | |
412 | - { | |
413 | - va_list arg_ptr; | |
414 | - va_start(arg_ptr, fmt); | |
415 | - v3270_trace_vprintf(widget,fmt,arg_ptr); | |
416 | - va_end(arg_ptr); | |
417 | - } | |
418 | - | |
419 | 409 | const gchar * v3270_trace_get_filename(GtkWidget *widget) |
420 | 410 | { |
421 | 411 | g_return_val_if_fail(GTK_IS_V3270_TRACE(widget),NULL); |
... | ... | @@ -479,3 +469,33 @@ |
479 | 469 | } |
480 | 470 | |
481 | 471 | } |
472 | + | |
473 | + H3270 * v3270_trace_get_session(GtkWidget *widget) | |
474 | + { | |
475 | + return GTK_V3270_TRACE(widget)->hSession; | |
476 | + } | |
477 | + | |
478 | + GtkWidget * v3270_trace_get_terminal(GtkWidget *widget) | |
479 | + { | |
480 | + return GTK_V3270_TRACE(widget)->terminal; | |
481 | + } | |
482 | + | |
483 | + GtkTextBuffer * v3270_trace_get_text_buffer(GtkWidget *widget) | |
484 | + { | |
485 | + return GTK_V3270_TRACE(widget)->text; | |
486 | + } | |
487 | + | |
488 | + GtkScrolledWindow * v3270_trace_get_scrolled_window(GtkWidget *widget) | |
489 | + { | |
490 | + return GTK_V3270_TRACE(widget)->scroll; | |
491 | + } | |
492 | + | |
493 | + gboolean v3270_get_trace(GtkWidget *terminal) | |
494 | + { | |
495 | + return GTK_V3270(terminal)->trace != NULL; | |
496 | + } | |
497 | + | |
498 | + void v3270_set_trace(GtkWidget *terminal, gboolean trace) | |
499 | + { | |
500 | + | |
501 | + } | ... | ... |
v3270.cbp
... | ... | @@ -307,6 +307,9 @@ |
307 | 307 | <Option compilerVar="CC" /> |
308 | 308 | </Unit> |
309 | 309 | <Unit filename="src/trace/private.h" /> |
310 | + <Unit filename="src/trace/text.c"> | |
311 | + <Option compilerVar="CC" /> | |
312 | + </Unit> | |
310 | 313 | <Unit filename="src/trace/trace.c"> |
311 | 314 | <Option compilerVar="CC" /> |
312 | 315 | </Unit> | ... | ... |