/** * draw a cell of a model * * \param context the GtkPrintContext * \param line_position the position to insert the column * \param column_position the position to insert the data * * \return the new column_position * */ static gint print_tree_view_list_draw_cell ( GtkPrintContext *context, gint line_position, gint column_position, gint column, const gchar *text ) { PangoLayout *layout; /* draw first the column */ column_position = print_tree_view_list_draw_column ( column_position, line_position ); cairo_move_to (cr, column_position, line_position); /* create the new layout */ layout = gtk_print_context_create_pango_layout (context); pango_layout_set_text ( layout, text, -1 ); pango_layout_set_font_description ( layout, gsb_data_print_config_get_font_transactions () ); pango_layout_set_width ( layout,columns_width[column] ); pango_layout_set_alignment ( layout, alignment[column] ); pango_layout_set_ellipsize ( layout, PANGO_ELLIPSIZE_END ); pango_cairo_show_layout ( cr, layout ); g_object_unref ( layout ); return column_position; }
/** * draw a line of a transaction * * \param * * \return the new line_position * */ static gint print_transactions_list_draw_row ( GtkPrintContext *context, CustomRecord *record, gint line_position ) { gint column; gfloat alignment[] = { PANGO_ALIGN_CENTER, PANGO_ALIGN_CENTER, PANGO_ALIGN_LEFT, PANGO_ALIGN_CENTER, PANGO_ALIGN_RIGHT, PANGO_ALIGN_RIGHT, PANGO_ALIGN_RIGHT }; for (column=0 ; column<CUSTOM_MODEL_VISIBLE_COLUMNS ; column++) { PangoLayout *layout; gchar *text; gint column_position; column_position = columns_position[column]; /* draw first the column */ column_position = print_transactions_list_draw_column (column_position, line_position); /* get the text */ text = record -> visible_col[column]; if (!text) continue; cairo_move_to (cr, column_position, line_position); /* create the new layout */ layout = gtk_print_context_create_pango_layout (context); pango_layout_set_text (layout, text, -1); pango_layout_set_font_description (layout, gsb_data_print_config_get_font_transactions ()); pango_layout_set_width (layout,columns_width[column]); pango_layout_set_alignment (layout, alignment[column]); pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); pango_cairo_show_layout (cr, layout); g_object_unref (layout); } /* go to the next row */ line_position = line_position + size_row; return line_position; }
/** * draw the title of the columns * * \param line_position the position to insert the titles * * \return the new line_position to continue to fill the page * */ static gint print_transactions_list_draw_columns_title ( GtkPrintContext *context, gint line_position) { gint column; if (!gsb_data_print_config_get_draw_columns_name ()) return line_position; for (column=0 ; column<CUSTOM_MODEL_VISIBLE_COLUMNS ; column++) { PangoLayout *layout; gchar *text; gint column_position; column_position = columns_position[column]; /* get the text */ text = _(titres_colonnes_liste_operations[column]); if (!text) continue; cairo_move_to (cr, column_position, line_position); /* create the new layout */ layout = gtk_print_context_create_pango_layout (context); pango_layout_set_text (layout, text, -1); pango_layout_set_font_description (layout, gsb_data_print_config_get_font_transactions ()); pango_layout_set_width (layout,columns_width[column]); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); pango_cairo_show_layout (cr, layout); g_object_unref (layout); } line_position = line_position + size_row + gsb_data_print_config_get_draw_lines (); return line_position; }
/** * Function called first when try to print the transaction list * initialize the variables and calculate the number of pages * * \param operation GtkPrintOperation * \param context GtkPrintContext * \param null * * \return FALSE * */ gboolean print_transactions_list_begin ( GtkPrintOperation *operation, GtkPrintContext *context, gpointer null ) { CustomList *custom_list; gint size_transaction; gint size_title = 0; gint size_archive = 0; gdouble transactions_per_page_double; gint nb_pages; gint number_of_archives = 0; devel_debug (NULL); /* we need to calculate the number of pages */ cr = gtk_print_context_get_cairo_context (context); custom_list = transaction_model_get_model (); /* get the size of the title */ if (gsb_data_print_config_get_draw_title () && title_string && strlen (title_string)) size_title = pango_font_description_get_size (gsb_data_print_config_get_font_title ())/PANGO_SCALE; /* we need the number of archives and of transactions to print * number_of_archives will be set to 0 if no draw archives */ print_transactions_list_get_visibles_lines (&number_of_archives, &total_transactions_to_print ); /* xxx mk_include 2 fois de suite modifie qd même des fichiers */ /* get the size of a complete transaction and an archive */ size_row = pango_font_description_get_size (gsb_data_print_config_get_font_transactions ())/PANGO_SCALE; size_transaction = size_row * custom_list -> nb_rows_by_transaction + 2*gsb_data_print_config_get_draw_lines (); size_archive = size_row + 2*gsb_data_print_config_get_draw_lines (); /* the heigh of a page decrease of 1 line if we use the columns titles */ page_height = gtk_print_context_get_height (context) - gsb_data_print_config_get_draw_columns_name ()*size_transaction; /* how much transactions we can show in a page : */ transactions_per_page_double = page_height / size_transaction; if (!size_title && !gsb_data_print_config_get_draw_archives ()) { /* simple way : no archives and no title */ nb_pages = ceil ( total_transactions_to_print / transactions_per_page_double ); transactions_in_first_page = floor (transactions_per_page_double); } else { /* there are title or archives, it's more complex because it will have less transactions * on the first page */ gint first_page_height = page_height - size_title - size_archive*number_of_archives; transactions_in_first_page = floor (first_page_height / size_transaction); nb_pages = 1 + ceil ( (total_transactions_to_print - transactions_in_first_page)/ transactions_per_page_double ); } /* set the number of page */ gtk_print_operation_set_n_pages ( GTK_PRINT_OPERATION (operation), nb_pages ); /* save the nb of transactions per page */ transactions_per_page = floor (transactions_per_page_double); /* calculate the size and position of the columns */ page_width = gtk_print_context_get_width (context); print_transactions_list_calculate_columns (page_width); total_transactions_printed = 0; current_row_to_print = 0; return FALSE; }
/** * Show a dialog to set wether we want the rows/columns lines, * the background color, the titles... * * \param operation GtkPrintOperation responsible of this job. * \param null Not used. * * \return A newly allocated widget. */ GtkWidget * print_transactions_list_layout_config ( GtkPrintOperation * operation, gpointer null ) { GtkWidget *check_button; GtkWidget *label; GtkWidget *hbox; GtkWidget *entry; GtkWidget *font_button_transactions; GtkWidget *font_button_title; gchar *fontname_transactions; gchar *fontname_title; GtkWidget *init_date_entry; GtkWidget *final_date_entry; GtkWidget *vbox; GtkWidget *paddingbox; GtkSizeGroup * size_group; size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); vbox = gtk_vbox_new ( FALSE, 6 ); gtk_container_set_border_width ( GTK_CONTAINER(vbox), 12 ); paddingbox = new_paddingbox_with_title ( vbox, FALSE, _("Layout") ); /* set up the title and dates, this is never saved, so ask each time */ /* title line */ hbox = gtk_hbox_new (FALSE, 10); gtk_box_pack_start (GTK_BOX (paddingbox), hbox, FALSE, FALSE, 0); entry = gsb_automem_entry_new (&title_string, NULL, NULL); check_button = gsb_autofunc_checkbutton_new (_("Print a title: "), gsb_data_print_config_get_draw_title (), G_CALLBACK (sens_desensitive_pointeur), entry, G_CALLBACK (gsb_data_print_config_set_draw_title), 0); gtk_box_pack_start (GTK_BOX (hbox), check_button, FALSE, FALSE, 0); gtk_widget_set_sensitive (entry, gsb_data_print_config_get_draw_title ()); gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); /* add the dates interval */ hbox = gtk_hbox_new (FALSE, 10); check_button = gsb_autofunc_checkbutton_new (_("Select dates interval: "), gsb_data_print_config_get_draw_interval_dates (), G_CALLBACK (sens_desensitive_pointeur), hbox, G_CALLBACK (gsb_data_print_config_set_draw_interval_dates), 0); gtk_box_pack_start (GTK_BOX (paddingbox), check_button, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (paddingbox), hbox, FALSE, FALSE, 0); label = gtk_label_new (_("Initial date : ")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); init_date_entry = gsb_calendar_entry_new (FALSE); if (draw_initial_date) gsb_calendar_entry_set_date (init_date_entry, draw_initial_date); gtk_box_pack_start (GTK_BOX (hbox), init_date_entry, FALSE, FALSE, 0); label = gtk_label_new (_("Final date : ")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); final_date_entry = gsb_calendar_entry_new (FALSE); if (draw_final_date) gsb_calendar_entry_set_date (final_date_entry, draw_final_date); gtk_box_pack_start (GTK_BOX (hbox), final_date_entry, FALSE, FALSE, 0); g_object_set_data ( G_OBJECT ( operation ), "init_date_entry", init_date_entry ); g_object_set_data ( G_OBJECT ( operation ), "final_date_entry", final_date_entry ); check_button = gsb_autofunc_checkbutton_new (_("Use value date"), gsb_data_print_config_get_draw_dates_are_value_dates (), NULL, NULL, G_CALLBACK (gsb_data_print_config_set_draw_dates_are_value_dates), 0); gtk_box_pack_start (GTK_BOX (hbox), check_button, FALSE, FALSE, 0); if (!gsb_data_print_config_get_draw_interval_dates ()) gtk_widget_set_sensitive (hbox, FALSE); /* set up all the checkbuttons */ check_button = gsb_autofunc_checkbutton_new (_("Draw the lines between transactions"), gsb_data_print_config_get_draw_lines (), NULL, NULL, G_CALLBACK (gsb_data_print_config_set_draw_lines), 0); gtk_box_pack_start (GTK_BOX (paddingbox), check_button, FALSE, FALSE, 0); check_button = gsb_autofunc_checkbutton_new (_("Draw the lines between the columns"), gsb_data_print_config_get_draw_column (), NULL, NULL, G_CALLBACK (gsb_data_print_config_set_draw_column), 0); gtk_box_pack_start (GTK_BOX (paddingbox), check_button, FALSE, FALSE, 0); check_button = gsb_autofunc_checkbutton_new (_("Fill the background as the transactions list"), gsb_data_print_config_get_draw_background (), NULL, NULL, G_CALLBACK (gsb_data_print_config_set_draw_background), 0); gtk_box_pack_start (GTK_BOX (paddingbox), check_button, FALSE, FALSE, 0); check_button = gsb_autofunc_checkbutton_new (_("Print the archives lines"), gsb_data_print_config_get_draw_archives (), NULL, NULL, G_CALLBACK (gsb_data_print_config_set_draw_archives), 0); gtk_box_pack_start (GTK_BOX (paddingbox), check_button, FALSE, FALSE, 0); check_button = gsb_autofunc_checkbutton_new (_("Print the names of the columns"), gsb_data_print_config_get_draw_columns_name (), NULL, NULL, G_CALLBACK (gsb_data_print_config_set_draw_columns_name), 0); gtk_box_pack_start (GTK_BOX (paddingbox), check_button, FALSE, FALSE, 0); paddingbox = new_paddingbox_with_title ( vbox, FALSE, _("Fonts") ); /* set up the font of the transactions, * by default use the font of the lists */ hbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (paddingbox), hbox, FALSE, FALSE, 0); label = gtk_label_new (_("Transactions font")); gtk_label_set_justify ( GTK_LABEL (label), GTK_JUSTIFY_LEFT ); gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5); gtk_size_group_add_widget ( size_group, label ); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); fontname_transactions = pango_font_description_to_string (gsb_data_print_config_get_font_transactions ()); font_button_transactions = gtk_font_button_new_with_font ( fontname_transactions ); gtk_font_button_set_use_font ( GTK_FONT_BUTTON(font_button_transactions), TRUE ); gtk_font_button_set_use_size ( GTK_FONT_BUTTON(font_button_transactions), TRUE ); gtk_font_button_set_title ( GTK_FONT_BUTTON(font_button_transactions), _("Choosing font") ); gtk_box_pack_start (GTK_BOX (hbox), font_button_transactions, TRUE, TRUE, 0); /* set up the font for the title */ hbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (paddingbox), hbox, FALSE, FALSE, 0); label = gtk_label_new (_("Title font")); gtk_label_set_justify ( GTK_LABEL (label), GTK_JUSTIFY_LEFT ); gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5); gtk_size_group_add_widget ( size_group, label ); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); fontname_title = pango_font_description_to_string (gsb_data_print_config_get_font_title ()); font_button_title = gtk_font_button_new_with_font ( fontname_title ); gtk_font_button_set_use_font ( GTK_FONT_BUTTON(font_button_title), TRUE ); gtk_font_button_set_use_size ( GTK_FONT_BUTTON(font_button_title), TRUE ); gtk_font_button_set_title ( GTK_FONT_BUTTON(font_button_title), _("Choosing font") ); gtk_box_pack_start (GTK_BOX (hbox), font_button_title, TRUE, TRUE, 0); /* save what we have done in all cases, so if we cancel and come back, our values * come back */ gsb_data_print_config_set_font_transaction (pango_font_description_from_string (fontname_transactions)); gsb_data_print_config_set_font_title (pango_font_description_from_string (fontname_title)); draw_initial_date = gsb_calendar_entry_get_date (init_date_entry); draw_final_date = gsb_calendar_entry_get_date (final_date_entry); g_object_set_data ( G_OBJECT(operation), "font_transaction_button", font_button_transactions ); g_object_set_data ( G_OBJECT(operation), "font_title_button", font_button_title ); gtk_widget_show_all ( vbox ); return vbox; }
/** * Function called first when try to print the list * initialize the variables and calculate the number of pages * * \param operation GtkPrintOperation * \param context GtkPrintContext * \param null * * \return FALSE * */ gboolean print_tree_view_list_begin ( GtkPrintOperation *operation, GtkPrintContext *context, gpointer data ) { GtkTreeView *tree_view = ( GtkTreeView * ) data; gint size_line; gdouble lines_per_page_double; gint nbre_pages; devel_debug (NULL); /* we need to calculate the number of pages */ cr = gtk_print_context_get_cairo_context ( context ); /* get the size of the title */ if ( title_string && strlen ( title_string ) ) size_title = print_tree_view_list_get_title_size ( ); else size_title = 0; /* get the size of a row */ size_row = pango_font_description_get_size ( gsb_data_print_config_get_font_transactions () ) / PANGO_SCALE; size_line = size_row + gsb_data_print_config_get_draw_lines ( ); /* get the size of the titles of columns */ if ( gsb_data_print_config_get_draw_columns_name () ) { nbre_lines_col_title = print_tree_view_list_get_columns_title_nbre_lines ( tree_view ); size_columns_title = print_tree_view_list_get_columns_title_size ( nbre_lines_col_title ); } else size_columns_title = 0; /* the heigh of a page decrease size_columns_title */ page_height = gtk_print_context_get_height ( context ); /* get total lines to print */ total_lines_to_print = 0; total_lines_to_print = print_tree_view_list_set_rows_to_print ( tree_view ); /* how much transactions we can show in a page : */ lines_per_page_double = page_height / size_line; /* on enlève les lignes des titres des colonnes */ lines_per_page_double -= nbre_lines_col_title; if ( !size_title ) /* no title */ { nbre_pages = ceil ( total_lines_to_print / lines_per_page_double ); lines_in_first_page = floor ( lines_per_page_double ); } else { gint first_page_height; first_page_height = page_height - size_title; lines_in_first_page = floor ( first_page_height / size_line ) - nbre_lines_col_title; nbre_pages = 1 + ceil ( ( total_lines_to_print - lines_in_first_page ) / lines_per_page_double ); } /* set the number of page */ gtk_print_operation_set_n_pages ( GTK_PRINT_OPERATION ( operation ), nbre_pages ); /* save the nb of rows per page */ lines_per_page = floor ( lines_per_page_double ); /* calculate the size and position of the columns */ page_width = gtk_print_context_get_width ( context ); print_tree_view_list_calculate_columns_width ( tree_view, page_width ); if ( tree_path_to_print ) gtk_tree_path_free ( tree_path_to_print ); tree_path_to_print = gtk_tree_path_new_first ( ); total_lines_printed = 0; current_row_to_print = 0; return FALSE; }