Esempio n. 1
0
/**
 * draw the background of the row
 *
 * \param cr                cairo context
 * \param tree_view         get_model
 * \param line_position     position where drawing the line
 *
 * \return
 * */
static void print_tree_view_list_draw_background ( GtkPrintContext *context,
                        GtkTreeView *tree_view,
                        gint line_position )
{
    GtkTreeModel *model;
    GtkTreeIter iter;
    gint col_origin = 0;
    gint origin;

    if ( !gsb_data_print_config_get_draw_background () )
        return;

    model = gtk_tree_view_get_model ( tree_view );
    if ( !gtk_tree_model_get_iter ( model, &iter, tree_path_to_print ) )
        return;

    col_origin = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( tree_view ), "origin_data_model" ) );
    if ( col_origin == 0 )
        return;

    gtk_tree_model_get ( model, &iter, col_origin, &origin, -1 );

    if ( origin == SPP_ORIGIN_ACCOUNT || origin == SPP_ORIGIN_FUTURE || origin == SPP_ORIGIN_HISTORICAL )
    {
        gchar *str_color;
        gint col_color;
        GdkColor color;

        col_color = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( tree_view ), "color_data_model" ) );
        gtk_tree_model_get ( model, &iter, col_color, &str_color, -1 );
        gdk_color_parse ( str_color, &color );

        cairo_rectangle ( cr, 0, line_position, page_width, size_row + 2 * gsb_data_print_config_get_draw_lines () );
        cairo_set_source_rgb ( cr,
                        (gdouble) color.red/65535,
                        (gdouble) color.green/65535,
                        (gdouble) color.blue/65535 );

        cairo_fill (cr);
        cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
    }
}
/**
 * draw the background of all the rows of the transaction
 *
 * \param cr		cairo context
 * \param record	record to draw
 * \param color_bg	TRUE to colorize, FALSE to let blank
 * \param line_position	position where drawing the line
 *
 * \return
 * */
static void print_transactions_list_draw_background ( CustomRecord *record,
						      gboolean color_bg,
						      gint line_position )
{
    if (!gsb_data_print_config_get_draw_background ())
        return;

    if (record -> what_is_line == IS_ARCHIVE)
    {
        GdkColor *color;

        color = gsb_color_get_couleur ( "archive_background_color" );
        cairo_rectangle ( cr, 0, line_position, page_width, size_row + 2*gsb_data_print_config_get_draw_lines ( ) );
        cairo_set_source_rgb ( cr,
                        (gdouble) color -> red/65535,
                        (gdouble) color -> green/65535,
                        (gdouble) color -> blue/65535 );
    }
    else
    {
        CustomList *custom_list = transaction_model_get_model ( );
        GdkColor *color;

        if ( color_bg )
            color = gsb_color_get_couleur_with_indice ( "couleur_fond", 0 );
        else
            color = gsb_color_get_couleur_with_indice ( "couleur_fond", 1 );

        cairo_rectangle (cr, 0, line_position, page_width,
                        custom_list -> nb_rows_by_transaction * size_row + 2*gsb_data_print_config_get_draw_lines ( ) );
        cairo_set_source_rgb (cr,
                        (gdouble) color -> red/65535,
                        (gdouble) color -> green/65535,
                        (gdouble) color -> blue/65535 );
    }
    cairo_fill ( cr );
    cairo_set_source_rgb ( cr, 0.0, 0.0, 0.0 );
}
/**
 * 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;
}