Commit d144f89f7f6708e451ae0f303446044b190077e1

Authored by Perry Werneck
1 parent 84d8d202
Exists in master and in 1 other branch develop

Updating print dialog.

src/dialogs/print/print.c
... ... @@ -136,14 +136,23 @@
136 136  
137 137 V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object);
138 138  
139   - if(operation->contents.text)
140   - g_strfreev(operation->contents.text);
141   -
142 139 if(operation->font.info.scaled)
143 140 cairo_scaled_font_destroy(operation->font.info.scaled);
144 141  
145 142 g_free(operation->font.name);
146 143  
  144 + if(operation->contents.text)
  145 + {
  146 + size_t row;
  147 +
  148 + for(row = 0; operation->contents.text[row]; row++)
  149 + {
  150 + g_free(operation->contents.text[row]);
  151 + }
  152 + g_free(operation->contents.text);
  153 +
  154 + }
  155 +
147 156 }
148 157  
149 158 static void V3270PrintOperation_class_init(V3270PrintOperationClass *klass)
... ... @@ -191,7 +200,7 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT
191 200 operation->widget = GTK_V3270(widget);
192 201 operation->session = v3270_get_session(widget);
193 202  
194   - V3270PrintOperation_set_mode(operation, mode);
  203 + V3270PrintOperation_set_text_by_mode(operation, mode);
195 204  
196 205 return operation;
197 206 }
... ... @@ -223,16 +232,33 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT
223 232 v3270_print(widget,LIB3270_PRINT_COPY);
224 233 }
225 234  
226   - void V3270PrintOperation_set_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode)
  235 + void V3270PrintOperation_set_text_by_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode)
227 236 {
228 237 operation->mode = mode;
229 238  
230   - // Text rectangle (in characters).
231 239 switch(mode)
232 240 {
233 241 case LIB3270_PRINT_ALL:
234   - operation->contents.height = lib3270_get_height(operation->session);
235   - operation->contents.width = lib3270_get_width(operation->session);
  242 + {
  243 + size_t row, col;
  244 + int baddr = 0;
  245 + column * text;
  246 +
  247 + operation->contents.height = lib3270_get_height(operation->session);
  248 + operation->contents.width = lib3270_get_width(operation->session);
  249 +
  250 + operation->contents.text = g_new0(column *, operation->contents.height+1);
  251 +
  252 + for(row = 0; row < operation->contents.height; row++)
  253 + {
  254 + operation->contents.text[row] = text = g_new0(column, operation->contents.width);
  255 + for(col = 0; col < operation->contents.width; col++)
  256 + {
  257 + lib3270_get_element(operation->session,baddr++,&text[col].c,&text[col].attr);
  258 + }
  259 + }
  260 +
  261 + }
236 262 break;
237 263  
238 264 case LIB3270_PRINT_SELECTED:
... ... @@ -260,28 +286,29 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT
260 286 }
261 287 }
262 288  
263   - operation->contents.height = rect.height;
264   - operation->contents.width = rect.width;
  289 + operation->contents.height = rect.height - rect.y;
  290 + operation->contents.width = rect.width - rect.x;
265 291  
266 292 }
267 293 break;
268 294  
269 295 case LIB3270_PRINT_COPY:
270 296 {
271   - lib3270_autoptr(char) text = v3270_get_copy(GTK_WIDGET(operation->widget));
272   - if(text)
  297 + lib3270_autoptr(char) copy = v3270_get_copy(GTK_WIDGET(operation->widget));
  298 + if(copy)
273 299 {
274 300 size_t r;
275   -
276   - operation->contents.text = g_strsplit(text,"\n",-1);
277   - operation->contents.height = g_strv_length(operation->contents.text);
  301 + gchar ** text = g_strsplit(copy,"\n",-1);
  302 + operation->contents.height = g_strv_length(text);
278 303 operation->contents.width = 0;
279 304  
280 305 for(r=0;r < operation->contents.height;r++)
281 306 {
282   - operation->contents.width = MAX(operation->contents.width,strlen(operation->contents.text[r]));
  307 + operation->contents.width = MAX(operation->contents.width,strlen(text[r]));
283 308 }
284 309  
  310 + g_strfreev(text);
  311 +
285 312 }
286 313 }
287 314 break;
... ...
src/dialogs/print/private.h
... ... @@ -40,6 +40,12 @@
40 40  
41 41 };
42 42  
  43 + typedef struct _column
  44 + {
  45 + unsigned char c;
  46 + unsigned short attr;
  47 + } column;
  48 +
43 49 struct _V3270PrintOperation
44 50 {
45 51 GtkPrintOperation parent;
... ... @@ -55,7 +61,7 @@
55 61 {
56 62 size_t width; ///< @brief Width of the contents (in columns);
57 63 size_t height; ///< @brief Height of the contents (in rows);
58   - gchar **text; ///< @brief Text contents;
  64 + column **text; ///< @brief Report contents.
59 65 } contents;
60 66  
61 67 struct
... ...
src/include/v3270/print.h
... ... @@ -52,7 +52,7 @@
52 52 /*--[ Prototipes ]-----------------------------------------------------------------------------------*/
53 53  
54 54 LIB3270_EXPORT V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode);
55   - LIB3270_EXPORT void V3270PrintOperation_set_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode);
  55 + LIB3270_EXPORT void V3270PrintOperation_set_text_by_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode);
56 56  
57 57 LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname);
58 58  
... ...