From: Andrea Zagli Date: Sun, 9 Oct 2011 09:34:46 +0000 (+0200) Subject: Adjustments on RptReport::new_from_gtktreeview. X-Git-Tag: 0.5.0~25 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=f74e49b05f2f69b20391262ef3671820a6cd8a25;p=reptool%2Flibreptool Adjustments on RptReport::new_from_gtktreeview. Test under win32. --- diff --git a/src/rptreport.c b/src/rptreport.c index 1e0b4e3..932f8bd 100644 --- a/src/rptreport.c +++ b/src/rptreport.c @@ -558,7 +558,15 @@ RptReport g_return_val_if_fail (GTK_IS_TREE_VIEW (view), NULL); style = gtk_widget_get_style (GTK_WIDGET (view)); - pango_font = style->font_desc; + pango_font = pango_font_description_copy (style->font_desc); + if (pango_font == NULL) + { + g_warning ("No font from GtkTreeView. Default to Arial 10."); + + pango_font = pango_font_description_new (); + pango_font_description_set_family (pango_font, "Arial"); + pango_font_description_set_size (pango_font, 10); + } ret = rpt_report_new (); @@ -595,7 +603,6 @@ RptReport g_free (point); g_free (size); - g_free (font); rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_PAGE_HEADER); } @@ -612,7 +619,15 @@ RptReport col_width = rpt_common_points_to_value (RPT_UNIT_MILLIMETRE, gtk_tree_view_column_get_width (col) / 96 * 72); point = rpt_common_rptpoint_new_with_values (x, 15); - size = rpt_common_rptsize_new_with_values (col_width, 10); + if (columns->next == NULL && x < page_size->width) + { + /* the last column is always large until the end of the page */ + size = rpt_common_rptsize_new_with_values (page_size->width - x, 10); + } + else + { + size = rpt_common_rptsize_new_with_values (col_width, 10); + } font = rpt_common_rptfont_from_pango_description (pango_font); font->bold = TRUE; @@ -627,7 +642,6 @@ RptReport rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_PAGE_HEADER); g_free (point); - g_free (font); point = rpt_common_rptpoint_new_with_values (x, 0); font = rpt_common_rptfont_from_pango_description (pango_font); @@ -645,7 +659,6 @@ RptReport g_free (point); g_free (size); - g_free (font); g_hash_table_insert (columns_names, field_name, g_strdup_printf ("%d", idx)); @@ -704,7 +717,6 @@ RptReport g_free (point); g_free (size); - g_free (font); rpt_report_add_object_to_section (ret, obj, RPTREPORT_SECTION_PAGE_FOOTER); diff --git a/tests/rptreport_gtktreeview.c b/tests/rptreport_gtktreeview.c index fe92265..178ad77 100644 --- a/tests/rptreport_gtktreeview.c +++ b/tests/rptreport_gtktreeview.c @@ -27,12 +27,46 @@ enum N_COLUMNS }; -int -main (int argc, char **argv) +GtkWidget *tree; + +gboolean +on_w_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + return FALSE; +} + +void +on_btn_stampa_clicked (GtkButton *button, gpointer user_data) { RptReport *rptr; RptPrint *rptp; + rptr = rpt_report_new_from_gtktreeview (GTK_TREE_VIEW (tree), "\"Report's Title\""); + + if (rptr != NULL) + { + xmlDoc *report = rpt_report_get_xml (rptr); + xmlSaveFormatFile ("test_report.rpt", report, 2); + + xmlDoc *rptprint = rpt_report_get_xml_rptprint (rptr); + xmlSaveFormatFile ("test_report.rptr", rptprint, 2); + + rptp = rpt_print_new_from_xml (rptprint); + if (rptp != NULL) + { + g_object_set (G_OBJECT (rptp), "path-relatives-to", "..", NULL); + rpt_print_set_output_type (rptp, RPT_OUTPUT_PDF); + rpt_print_set_output_filename (rptp, "rptreport.pdf"); + rpt_print_print (rptp, NULL); + } + } +} + +int +main (int argc, char **argv) +{ gtk_init (&argc, &argv); GtkListStore *store = gtk_list_store_new (N_COLUMNS, /* Total number of columns */ @@ -57,8 +91,6 @@ main (int argc, char **argv) CHECKED_COLUMN, FALSE, -1); - GtkWidget *tree; - tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); GtkCellRenderer *renderer; @@ -69,6 +101,7 @@ main (int argc, char **argv) renderer, "text", TITLE_COLUMN, NULL); + gtk_tree_view_column_set_resizable (column, TRUE); gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); renderer = gtk_cell_renderer_text_new (); @@ -76,34 +109,29 @@ main (int argc, char **argv) renderer, "text", AUTHOR_COLUMN, NULL); + gtk_tree_view_column_set_resizable (column, TRUE); gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); GtkWidget *w = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (w), 500, 400); - gtk_container_add (GTK_CONTAINER (w), tree); + g_signal_connect (w, "delete-event", G_CALLBACK (on_w_delete_event), NULL); + g_signal_connect (w, "destroy", gtk_main_quit, NULL); - gtk_widget_show_all (w); + GtkWidget *box = gtk_vbox_new (FALSE, 5); - rptr = rpt_report_new_from_gtktreeview (GTK_TREE_VIEW (tree), "\"Report's Title\""); + gtk_container_add (GTK_CONTAINER (w), box); - if (rptr != NULL) - { - xmlDoc *report = rpt_report_get_xml (rptr); - xmlSaveFormatFile ("test_report.rpt", report, 2); + gtk_box_pack_start (GTK_BOX (box), tree, TRUE, TRUE, 0); - xmlDoc *rptprint = rpt_report_get_xml_rptprint (rptr); - xmlSaveFormatFile ("test_report.rptr", rptprint, 2); - - rptp = rpt_print_new_from_xml (rptprint); - if (rptp != NULL) - { - g_object_set (G_OBJECT (rptp), "path-relatives-to", "..", NULL); - rpt_print_set_output_type (rptp, RPT_OUTPUT_PDF); - rpt_print_set_output_filename (rptp, "rptreport.pdf"); - rpt_print_print (rptp, NULL); - } - } + GtkWidget *btn_stampa = gtk_button_new_from_stock ("gtk-print"); + + gtk_box_pack_start (GTK_BOX (box), btn_stampa, FALSE, FALSE, 0); + + g_signal_connect (G_OBJECT (btn_stampa), "clicked", + G_CALLBACK (on_btn_stampa_clicked), NULL); + + gtk_widget_show_all (w); gtk_main ();