/** * 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; }
/** * print the page * * \param operation GtkPrintOperation * \param context GtkPrintContext * \param page page to print * \param null * * \return FALSE * */ gboolean print_tree_view_list_draw_page ( GtkPrintOperation *operation, GtkPrintContext *context, gint page, gpointer data ) { GtkTreeView *tree_view = ( GtkTreeView * ) data; gint line_position = 0; devel_debug_int (page); /* draw the title */ if ( !page && title_string && strlen ( title_string ) ) line_position = print_tree_view_list_draw_title ( context, line_position ); /* draw the columns titles */ if ( gsb_data_print_config_get_draw_columns_name () ) line_position = print_tree_view_list_draw_columns_title ( context, line_position, tree_view ); /* draw the lines */ line_position = print_tree_view_list_draw_rows_data ( context, line_position, tree_view, page ); return FALSE; }
/** * print the page * * \param operation GtkPrintOperation * \param context GtkPrintContext * \param page page to print * \param null * * \return FALSE * */ gboolean print_transactions_list_draw_page ( GtkPrintOperation *operation, GtkPrintContext *context, gint page, gpointer null ) { CustomList *custom_list; gboolean color_bg = TRUE; gint line_position = 0; gint transactions_to_draw; devel_debug_int (page); /* draw the title */ if (!page) line_position = print_transactions_list_draw_title (context, line_position); /* draw the columns titles */ if (gsb_data_print_config_get_draw_columns_name ()) line_position = print_transactions_list_draw_columns_title (context, line_position); /* draw the transactions lines */ custom_list = transaction_model_get_model (); if (page) transactions_to_draw = transactions_per_page; else transactions_to_draw = transactions_in_first_page; if (transactions_to_draw > (total_transactions_to_print - total_transactions_printed)) transactions_to_draw = total_transactions_to_print - total_transactions_printed; while (transactions_to_draw) { gint i; CustomRecord *record = NULL; /* begin a transaction : fill the line before the transaction */ line_position = print_transactions_list_draw_line (line_position); /* print the transaction */ for (i=0 ; i<custom_list -> nb_rows_by_transaction ; i++) { record = custom_list -> visibles_rows[current_row_to_print]; /* if it's an archive, check we want it */ if (record -> what_is_line == IS_ARCHIVE && !gsb_data_print_config_get_draw_archives ()) { /* go to the next row but come back to the first line of transaction */ current_row_to_print++; i--; continue; } /* if we use the dates, it's here */ if (gsb_data_print_config_get_draw_interval_dates () && draw_initial_date && draw_final_date && record -> what_is_line == IS_TRANSACTION) { /* we want an interval, so check the transaction */ gint transaction_number; const GDate *date = NULL; transaction_number = gsb_data_transaction_get_transaction_number (record -> transaction_pointer); if (gsb_data_print_config_get_draw_dates_are_value_dates ()) date = gsb_data_transaction_get_value_date (transaction_number); /* if no value date, get the date */ if (!date) date = gsb_data_transaction_get_date (transaction_number); if (g_date_compare (date, draw_initial_date) < 0 || g_date_compare (date, draw_final_date) > 0) { /* the transaction is not into the dates, go to the next transaction */ current_row_to_print = current_row_to_print + custom_list -> nb_rows_by_transaction; i--; continue; } } /* begin the transaction, fill the background */ if (!i) print_transactions_list_draw_background (record, color_bg, line_position ); /* draw the last column */ print_transactions_list_draw_column (page_width, line_position); line_position = print_transactions_list_draw_row (context, record, line_position); current_row_to_print++; /* an archive is 1 line */ if (record -> what_is_line == IS_ARCHIVE) break; } /* we are on the last record of the transaction or archive, * decrease the number of transactions to draw */ if (record -> what_is_line == IS_TRANSACTION) { transactions_to_draw--; total_transactions_printed++; } /* add a space between 2 transactions */ line_position++; color_bg = !color_bg; } /* draw the last line */ print_transactions_list_draw_line (line_position); return FALSE; }
/** * 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; }
/** * draw the title of the columns * * \param context the GtkPrintContext * \param line_position the position to insert the titles * * \return the new line_position to continue to fill the page * */ static gint print_tree_view_list_draw_columns_title ( GtkPrintContext *context, gint line_position, GtkTreeView *tree_view ) { GList *list; GList *list_tmp; gint column = 0; gint column_position; devel_debug_int ( line_position ); if ( !gsb_data_print_config_get_draw_columns_name () ) return line_position; /* begin a row : fill the line before the row */ line_position = print_tree_view_list_draw_line ( line_position ); list = gtk_tree_view_get_columns ( tree_view ); if ( nbre_lines_col_title == 1 ) { /* draw the last column */ print_tree_view_list_draw_column ( page_width, line_position ); list_tmp = list; while ( list_tmp ) { GtkTreeViewColumn *col; const gchar *text; col = ( GtkTreeViewColumn * ) list_tmp -> data; column_position = columns_position[column]; /* get the text */ text = gtk_tree_view_column_get_title ( col ); if (!text) { list_tmp = list_tmp -> next; column++; continue; } print_tree_view_list_draw_cell ( context, line_position, column_position, column, text ); list_tmp = list_tmp -> next; column++; } line_position = line_position + size_columns_title; } else { gchar **tab; gchar *str_tmp; gint i = 0; for ( i = 0; i < nbre_lines_col_title; i ++ ) { /* draw the last column */ print_tree_view_list_draw_column ( page_width, line_position ); list_tmp = list; while ( list_tmp ) { GtkTreeViewColumn *col; const gchar *text; col = ( GtkTreeViewColumn * ) list_tmp -> data; column_position = columns_position[column]; /* get the text */ text = gtk_tree_view_column_get_title ( col ); if ( text == NULL || strlen ( text ) == 0 ) { print_tree_view_list_draw_column ( column_position, line_position ); list_tmp = list_tmp -> next; column++; continue; } str_tmp = gsb_string_uniform_new_line ( text, strlen ( text ) ); if ( str_tmp == NULL ) { if ( i == 0 ) print_tree_view_list_draw_cell ( context, line_position, column_position, column, text ); else print_tree_view_list_draw_column ( column_position, line_position ); list_tmp = list_tmp -> next; column++; continue; } tab = g_strsplit ( str_tmp, "\n", 0 ); if ( tab[i] && strlen ( tab[i] ) ) print_tree_view_list_draw_cell ( context, line_position, column_position, column, tab[i] ); else print_tree_view_list_draw_column ( column_position, line_position ); list_tmp = list_tmp -> next; column++; g_strfreev ( tab ); g_free ( str_tmp ); } line_position = line_position + size_row + gsb_data_print_config_get_draw_lines ( ); column = 0; } } return line_position; }
/** * 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; }