diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 18c8735..0f922ba 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -763,14 +763,16 @@ LIB3270_EXPORT void * lib3270_malloc(int len); LIB3270_EXPORT void * lib3270_realloc(void *p, int len); + LIB3270_EXPORT void * lib3270_replace(void **p, void *ptr); /** * Release allocated memory. * * @param p Memory block to release (can be NULL) * + * @return NULL */ - LIB3270_EXPORT void lib3270_free(void *p); + LIB3270_EXPORT void * lib3270_free(void *p); /** diff --git a/src/lib3270/actions.c b/src/lib3270/actions.c index 84e7f82..08727b3 100644 --- a/src/lib3270/actions.c +++ b/src/lib3270/actions.c @@ -134,44 +134,4 @@ check_usage(XtActionProc action, Cardinal nargs, Cardinal nargs_min, return -1; } */ -/* - * Wrapper for calling an action internally. - */ - /* -void -action_internal(XtActionProc action, enum iaction cause, const char *parm1, - const char *parm2) -{ - Cardinal count = 0; - String parms[2]; - - // Duplicate the parms, because XtActionProc doesn't grok 'const'. - if (parm1 != CN) { - parms[0] = NewString(parm1); - count++; - if (parm2 != CN) { - parms[1] = NewString(parm2); - count++; - } - } - - ia_cause = cause; - (*action)((Widget) NULL, (XEvent *) NULL, - count ? parms : (String *) NULL, - &count); - - // Free the parm copies. - switch (count) { - case 2: - lib3270_free(parms[1]); - // fall through... - case 1: - lib3270_free(parms[0]); - break; - default: - break; - } -} -*/ - diff --git a/src/lib3270/ctlrc.h b/src/lib3270/ctlrc.h index df8df2a..058d4be 100644 --- a/src/lib3270/ctlrc.h +++ b/src/lib3270/ctlrc.h @@ -78,6 +78,8 @@ enum dbcs_state { #define IS_LEFT(d) ((d) == DBCS_LEFT || (d) == DBCS_LEFT_WRAP) #define IS_RIGHT(d) ((d) == DBCS_RIGHT || (d) == DBCS_RIGHT_WRAP) #define IS_DBCS(d) (IS_LEFT(d) || IS_RIGHT(d)) + +/* #define MAKE_LEFT(b) { \ if (((b) % COLS) == ((ROWS * COLS) - 1)) \ ea_buf[(b)].db = DBCS_LEFT_WRAP; \ @@ -90,6 +92,8 @@ enum dbcs_state { else \ ea_buf[(b)].db = DBCS_RIGHT; \ } +*/ + #define SOSI(c) (((c) == EBC_so)? EBC_si: EBC_so) enum dbcs_why { DBCS_FIELD, DBCS_SUBFIELD, DBCS_ATTRIBUTE }; diff --git a/src/lib3270/globals.h b/src/lib3270/globals.h index 5cc7a6e..43c5011 100644 --- a/src/lib3270/globals.h +++ b/src/lib3270/globals.h @@ -106,7 +106,6 @@ * Prerequisite #includes. */ #include /* Unix standard I/O library */ -// #include /* Other Unix library functions */ #include /* Unix system calls */ #include /* Character classes */ #include /* String manipulations */ @@ -123,33 +122,11 @@ #undef X3270_MENUS #endif /*]*/ -/* Local process (-e) header files. */ /* -#if defined(X3270_LOCAL_PROCESS) && defined(HAVE_LIBUTIL) - #define LOCAL_PROCESS 1 - #include - - #if defined(HAVE_PTY_H) - #include - #endif - - #if defined(HAVE_LIBUTIL_H) - #include - #endif - - #if defined(HAVE_UTIL_H) - #include - #endif -#endif -*/ - /* Functions we may need to supply. */ #if defined(NEED_STRTOK_R) /*[*/ extern char *strtok_r(char *str, const char *sep, char **last); #endif /*]*/ -/* Stop conflicting with curses' COLS, even if we don't link with it. */ -// #define COLS cCOLS - #define CHECK_SESSION_HANDLE(x) if(!x) x = &h3270; @@ -162,9 +139,10 @@ enum iaction { IA_IDLE }; -LIB3270_INTERNAL int COLS; -LIB3270_INTERNAL int ROWS; -extern H3270 h3270; +// LIB3270_INTERNAL int COLS; +// LIB3270_INTERNAL int ROWS; + +LIB3270_INTERNAL H3270 h3270; #if defined(X3270_DISPLAY) /*[*/ LIB3270_INTERNAL Atom a_3270, a_registry, a_encoding; @@ -232,14 +210,14 @@ LIB3270_INTERNAL Boolean exiting; // LIB3270_INTERNAL int maxROWS; // LIB3270_INTERNAL char *model_name; // LIB3270_INTERNAL int model_num; -LIB3270_INTERNAL Boolean no_login_host; -LIB3270_INTERNAL Boolean non_tn3270e_host; +// LIB3270_INTERNAL Boolean no_login_host; +// LIB3270_INTERNAL Boolean non_tn3270e_host; // LIB3270_INTERNAL int ov_cols, ov_rows; - LIB3270_INTERNAL Boolean passthru_host; -extern const char *programname; -LIB3270_INTERNAL char *qualified_host; -LIB3270_INTERNAL char *reconnect_host; -LIB3270_INTERNAL int screen_depth; +// LIB3270_INTERNAL Boolean passthru_host; +// extern const char *programname; +// LIB3270_INTERNAL char *qualified_host; +// LIB3270_INTERNAL char *reconnect_host; +// LIB3270_INTERNAL int screen_depth; LIB3270_INTERNAL Boolean scroll_initted; //#if defined(HAVE_LIBSSL) /*[*/ @@ -247,13 +225,13 @@ LIB3270_INTERNAL Boolean scroll_initted; //#endif /*]*/ LIB3270_INTERNAL Boolean shifted; -LIB3270_INTERNAL Boolean ssl_host; +// LIB3270_INTERNAL Boolean ssl_host; LIB3270_INTERNAL Boolean *standard_font; -LIB3270_INTERNAL Boolean std_ds_host; -LIB3270_INTERNAL char *termtype; -LIB3270_INTERNAL Widget toplevel; +// LIB3270_INTERNAL Boolean std_ds_host; +// LIB3270_INTERNAL char *termtype; +// LIB3270_INTERNAL Widget toplevel; // LIB3270_INTERNAL Boolean visible_control; -LIB3270_INTERNAL int *xtra_width; +// LIB3270_INTERNAL int *xtra_width; /* #if defined(X3270_DISPLAY) @@ -318,7 +296,7 @@ LIB3270_INTERNAL struct trans_list *trans_list; #define CN ((char *) NULL) #define PN ((XtPointer) NULL) -#define Replace(var, value) { lib3270_free(var); var = (value); } +#define Replace(var, value) { lib3270_free(var); var = (value); }; /* Configuration change masks. */ #define NO_CHANGE 0x0000 /* no change */ diff --git a/src/lib3270/util.c b/src/lib3270/util.c index bd5e6d6..fbe69d4 100644 --- a/src/lib3270/util.c +++ b/src/lib3270/util.c @@ -880,10 +880,11 @@ rpf_free(rpf_t *r) r->cur_len = 0; } -LIB3270_EXPORT void lib3270_free(void *p) +LIB3270_EXPORT void * lib3270_free(void *p) { if(p) free(p); + return NULL; } LIB3270_EXPORT void * lib3270_realloc(void *p, int len) diff --git a/src/pw3270/print.c b/src/pw3270/print.c index f25625f..72e2b21 100644 --- a/src/pw3270/print.c +++ b/src/pw3270/print.c @@ -49,12 +49,15 @@ int rows; int cols; int pages; + int lpp; /**< Lines per page */ cairo_font_extents_t extents; double left; - double width; - double height; + double width; /**< Report width */ + double height; /**< Report height (all pages) */ cairo_scaled_font_t * font_scaled; + gchar **text; + } PRINT_INFO; /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -83,10 +86,16 @@ static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) { setup_font(context,info); - gtk_print_operation_set_n_pages(prt,1); + + info->lpp = (gtk_print_context_get_height(context) / (info->extents.height + info->extents.descent)); + info->pages = (info->rows / info->lpp)+1; + + trace("%d lines per page, %d pages to print",info->lpp,info->pages); + + gtk_print_operation_set_n_pages(prt,info->pages); } - static void draw_page(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) + static void draw_screen(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) { int row; int col; @@ -101,6 +110,7 @@ rect.height = (info->extents.height + info->extents.descent); rect.width = info->extents.max_x_advance; + // Clear page gdk_cairo_set_source_color(cr,info->color+V3270_COLOR_BACKGROUND); cairo_rectangle(cr, info->left-2, 0, (rect.width*info->cols)+4, (rect.height*info->rows)+4); cairo_fill(cr); @@ -244,6 +254,9 @@ static gchar * enum_to_string(GType type, guint enum_value) if(info->font) g_free(info->font); + if(info->text) + g_strfreev(info->text); + g_free(info); } @@ -478,13 +491,15 @@ static gchar * enum_to_string(GType type, guint enum_value) PRINT_INFO * info = NULL; GtkPrintOperation * print = begin_print_operation(action,widget,&info); - trace("Action %s activated on widget %p print=%p",gtk_action_get_name(action),widget,print); + #ifdef X3270_TRACE + lib3270_trace_event(NULL,"Action %s activated on widget %p\n",gtk_action_get_name(action),widget); + #endif lib3270_get_screen_size(info->session,&info->rows,&info->cols); info->all = 1; g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info); - g_signal_connect(print,"draw_page",G_CALLBACK(draw_page),info); + g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info); // Run Print dialog gtk_print_operation_run(print,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),NULL); @@ -499,7 +514,9 @@ static gchar * enum_to_string(GType type, guint enum_value) int start, end, rows; GtkPrintOperation * print = begin_print_operation(action,widget,&info);; - trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); + #ifdef X3270_TRACE + lib3270_trace_event(NULL,"Action %s activated on widget %p\n",gtk_action_get_name(action),widget); + #endif if(!lib3270_get_selection_bounds(info->session,&start,&end)) { @@ -517,18 +534,55 @@ static gchar * enum_to_string(GType type, guint enum_value) info->all = 0; g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info); - g_signal_connect(print,"draw_page",G_CALLBACK(draw_page),info); + g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info); // Run Print dialog gtk_print_operation_run(print,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),NULL); - g_object_unref(print); } + static void draw_text(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) + { + cairo_t * cr = gtk_print_context_get_cairo_context(context); + + cairo_set_scaled_font(cr,info->font_scaled); + + + + } + void print_copy_action(GtkAction *action, GtkWidget *widget) { - trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); + PRINT_INFO * info = NULL; + GtkPrintOperation * print; + const gchar * text = v3270_get_copy(widget); + int r; + + #ifdef X3270_TRACE + lib3270_trace_event(NULL,"Action %s activated on widget %p\n",gtk_action_get_name(action),widget); + #endif + + if(!text) + return; + + print = begin_print_operation(action,widget,&info); + info->text = g_strsplit(text,"\n",-1); + info->rows = g_strv_length(info->text); + + for(r=0;r < info->rows;r++) + { + size_t sz = strlen(info->text[r]); + if(sz > info->cols) + info->cols = sz; + } + + g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info); + g_signal_connect(print,"draw_page",G_CALLBACK(draw_text),info); + // Run Print dialog + gtk_print_operation_run(print,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),NULL); + + g_object_unref(print); } -- libgit2 0.21.2