Commit c6eb5985cdadf9ad3324ec7584bfb31f44b7eb69
1 parent
317eaeb8
Exists in
master
and in
1 other branch
Simple trace window now restore handler on closing.
Showing
2 changed files
with
29 additions
and
5 deletions
Show diff stats
src/include/v3270/trace.h
| ... | ... | @@ -51,6 +51,7 @@ |
| 51 | 51 | |
| 52 | 52 | LIB3270_EXPORT GtkWidget * v3270_trace_new(); |
| 53 | 53 | LIB3270_EXPORT GtkWidget * v3270_trace_new_from_session(H3270 *hSession); |
| 54 | + LIB3270_EXPORT void v3270_trace_set_session(GtkWidget *widget, H3270 *hSession); | |
| 54 | 55 | LIB3270_EXPORT GType v3270_trace_get_type(void); |
| 55 | 56 | LIB3270_EXPORT void v3270_trace_vprintf(GtkWidget *widget, const char *fmt, va_list args); |
| 56 | 57 | LIB3270_EXPORT void v3270_trace_printf(GtkWidget *widget, const char *fmt, ... ); | ... | ... |
src/trace/trace.c
| ... | ... | @@ -65,6 +65,13 @@ |
| 65 | 65 | guint log_handler; |
| 66 | 66 | gboolean * enabled; |
| 67 | 67 | gboolean destroy_on_close; |
| 68 | + | |
| 69 | + /// @brief lib3270's saved trace handler. | |
| 70 | + struct { | |
| 71 | + void (*handler)(H3270 *session, void *userdata, const char *fmt, va_list args); | |
| 72 | + void *userdata; | |
| 73 | + } trace; | |
| 74 | + | |
| 68 | 75 | }; |
| 69 | 76 | |
| 70 | 77 | const GtkWindowClass * v3270_trace_get_parent_class(void); |
| ... | ... | @@ -109,7 +116,7 @@ static void destroy(GtkObject *widget) |
| 109 | 116 | |
| 110 | 117 | if(hwnd->hSession) |
| 111 | 118 | { |
| 112 | - lib3270_set_trace_handler(hwnd->hSession,NULL,NULL); | |
| 119 | + lib3270_set_trace_handler(hwnd->hSession,hwnd->trace.handler,hwnd->trace.userdata); | |
| 113 | 120 | } |
| 114 | 121 | |
| 115 | 122 | if(hwnd->log_handler) |
| ... | ... | @@ -393,7 +400,7 @@ static void destroy(GtkObject *widget) |
| 393 | 400 | window->button = gtk_button_new_from_stock(GTK_STOCK_OK); |
| 394 | 401 | gtk_box_pack_end(GTK_BOX(widget),window->button,FALSE,FALSE,4); |
| 395 | 402 | gtk_widget_set_sensitive(window->button,FALSE); |
| 396 | - gtk_widget_set_focus_on_click(GTK_BUTTON(window->button),FALSE); | |
| 403 | + gtk_widget_set_focus_on_click(GTK_WIDGET(window->button),FALSE); | |
| 397 | 404 | |
| 398 | 405 | g_signal_connect(G_OBJECT(window->button),"clicked",G_CALLBACK(activate),window); |
| 399 | 406 | |
| ... | ... | @@ -403,7 +410,6 @@ static void destroy(GtkObject *widget) |
| 403 | 410 | |
| 404 | 411 | gtk_container_add(GTK_CONTAINER(window),vbox); |
| 405 | 412 | |
| 406 | - | |
| 407 | 413 | window->log_handler = g_log_set_handler(NULL,G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,(GLogFunc) glog,window); |
| 408 | 414 | |
| 409 | 415 | } |
| ... | ... | @@ -427,12 +433,29 @@ static void destroy(GtkObject *widget) |
| 427 | 433 | g_free(ptr); |
| 428 | 434 | } |
| 429 | 435 | |
| 436 | + void v3270_trace_set_session(GtkWidget *widget, H3270 *hSession) { | |
| 437 | + | |
| 438 | + v3270_trace * trace = V3270_TRACE(widget); | |
| 439 | + | |
| 440 | + if(trace->hSession) { | |
| 441 | + lib3270_set_trace_handler(trace->hSession,trace->trace.handler,trace->trace.userdata); | |
| 442 | + } | |
| 443 | + | |
| 444 | + trace->hSession = hSession; | |
| 445 | + | |
| 446 | + if(hSession) { | |
| 447 | + lib3270_get_trace_handler(hSession,&trace->trace.handler,&trace->trace.userdata); | |
| 448 | + lib3270_set_trace_handler(hSession,trace_handler,(void *) widget); | |
| 449 | + } | |
| 450 | + | |
| 451 | + } | |
| 452 | + | |
| 430 | 453 | LIB3270_EXPORT GtkWidget * v3270_trace_new_from_session(H3270 *hSession) { |
| 431 | 454 | |
| 432 | 455 | GtkWidget * widget = g_object_new(V3270_TYPE_TRACE, NULL); |
| 433 | 456 | void * terminal = lib3270_get_user_data(hSession); |
| 434 | 457 | |
| 435 | - V3270_TRACE(widget)->hSession = hSession; | |
| 458 | + V3270_TRACE(widget)->hSession = NULL; | |
| 436 | 459 | |
| 437 | 460 | gtk_window_set_default_size(GTK_WINDOW(widget),590,430); |
| 438 | 461 | |
| ... | ... | @@ -441,7 +464,7 @@ static void destroy(GtkObject *widget) |
| 441 | 464 | gtk_window_set_attached_to(GTK_WINDOW(widget),GTK_WIDGET(terminal)); |
| 442 | 465 | } |
| 443 | 466 | |
| 444 | - lib3270_set_trace_handler(hSession,trace_handler,(void *) widget); | |
| 467 | + v3270_trace_set_session(widget, hSession); | |
| 445 | 468 | |
| 446 | 469 | return widget; |
| 447 | 470 | } | ... | ... |