Esempio n. 1
0
/**
 * draw the title if asked
 *
 * \param context           the GtkPrintContext
 * \param line_position     the position to insert the title
 * \param page_width        the page width
 *
 * \return the new line_position to continue to fill the page
 * */
static gint print_tree_view_list_draw_title ( GtkPrintContext *context,
                        gint line_position )
{
    if ( title_string && strlen ( title_string ) )
    {
        PangoLayout *layout;
        devel_debug_int (line_position);

        cairo_move_to ( cr, 0, line_position );

        /* create the new layout */
        layout = gtk_print_context_create_pango_layout ( context );

        pango_layout_set_text ( layout, title_string, -1 );
        pango_layout_set_font_description ( layout, gsb_data_print_config_get_font_title () );
        pango_layout_set_width ( layout, page_width * PANGO_SCALE );
        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 );

        /* add title line and blank line */
        line_position = line_position + size_title;
    }

    return line_position;
}
Esempio n. 2
0
static gint print_tree_view_list_get_title_size ( void )
{
    gint size_tmp = 0;
    gint size_line;
    gint nbre_lines = 1;

    if ( g_utf8_strchr ( title_string, -1, '\n' ) )
        nbre_lines = utils_str_get_nbre_motifs ( title_string, "\n" ) + 1;

    /* Add a blank line */
    nbre_lines++;

    size_line = pango_font_description_get_size ( gsb_data_print_config_get_font_title () );

    size_tmp =  size_line * nbre_lines / PANGO_SCALE;

    return size_tmp;
}
/**
 * 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;
}