Example #1
0
GnucashSheet *gnucash_register_get_sheet (GnucashRegister *reg)
{
    g_return_val_if_fail (reg != NULL, NULL);
    g_return_val_if_fail (GNUCASH_IS_REGISTER(reg), NULL);

    return GNUCASH_SHEET(reg->sheet);
}
Example #2
0
static void
gnc_header_set_property (GObject *object,
                         guint param_id,
                         const GValue *value,
                         GParamSpec *pspec)
{
    GncHeader *header = GNC_HEADER (object);
    GtkLayout *layout = GTK_LAYOUT (GNOME_CANVAS_ITEM (header)->canvas);
    gboolean needs_update = FALSE;
    gchar *old_name;

    switch (param_id)
    {
    case PROP_SHEET:
        header->sheet = GNUCASH_SHEET (g_value_get_object (value));
        gtk_layout_set_hadjustment (layout, header->sheet->hadj);
        needs_update = TRUE;
        break;
    case PROP_CURSOR_NAME:
        old_name = header->cursor_name;

        header->cursor_name = g_value_dup_string (value);
        needs_update = !old_name || !header->cursor_name ||
                       strcmp (old_name, header->cursor_name) != 0;
        g_free (old_name);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
        break;
    }

    if ((header->sheet != NULL) && needs_update)
        gnc_header_reconfigure (header);
}
Example #3
0
static void
gnc_table_refresh_cursor_gnome (Table * table,
                                VirtualCellLocation vcell_loc,
                                gboolean do_scroll)
{
    GnucashSheet *sheet;

    if (!table || !table->ui_data)
        return;

    g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));

    if (gnc_table_virtual_cell_out_of_bounds (table, vcell_loc))
        return;

    sheet = GNUCASH_SHEET (table->ui_data);

    gnucash_sheet_cursor_set_from_table (sheet, do_scroll);

    if (gnucash_sheet_block_set_from_table (sheet, vcell_loc))
    {
        gnucash_sheet_recompute_block_offsets (sheet);
        gnucash_sheet_set_scroll_region (sheet);
        gnucash_sheet_compute_visible_range (sheet);
        gnucash_sheet_redraw_all (sheet);
    }
    else
        gnucash_sheet_redraw_block (sheet, vcell_loc);
}
Example #4
0
void
gnucash_register_goto_next_virt_row (GnucashRegister *reg)
{
    GnucashSheet *sheet;
    VirtualLocation virt_loc;
    int start_virt_row;

    g_return_if_fail (reg != NULL);
    g_return_if_fail (GNUCASH_IS_REGISTER(reg));

    sheet = GNUCASH_SHEET(reg->sheet);

    gnucash_cursor_get_virt (GNUCASH_CURSOR(sheet->cursor), &virt_loc);

    /* Move down one physical row at a time until we
     * reach the next visible virtual cell. */
    start_virt_row = virt_loc.vcell_loc.virt_row;
    do
    {
        if (!gnc_table_move_vertical_position (sheet->table, &virt_loc, 1))
            return;
    }
    while (start_virt_row == virt_loc.vcell_loc.virt_row);

    if (virt_loc.vcell_loc.virt_row >= sheet->num_virt_rows)
        return;

    virt_loc.phys_row_offset = 0;
    virt_loc.phys_col_offset = 0;

    gnucash_sheet_goto_virt_loc (sheet, virt_loc);
}
Example #5
0
void gnucash_register_set_moved_cb (GnucashRegister *reg,
                                    GFunc cb, gpointer cb_data)
{
    GnucashSheet *sheet;

    if (!reg || !reg->sheet)
        return;
    sheet = GNUCASH_SHEET(reg->sheet);
    sheet->moved_cb = cb;
    sheet->moved_cb_data = cb_data;
}
Example #6
0
void
gnucash_register_attach_popup (GnucashRegister *reg,
                               GtkWidget *popup,
                               gpointer data)
{
    g_return_if_fail (GNUCASH_IS_REGISTER(reg));
    g_return_if_fail (reg->sheet != NULL);
    if (popup)
        g_return_if_fail (GTK_IS_WIDGET(popup));

    gnucash_sheet_set_popup (GNUCASH_SHEET (reg->sheet), popup, data);
}
Example #7
0
void
gnucash_register_refresh_from_prefs (GnucashRegister *reg)
{
    GnucashSheet *sheet;

    g_return_if_fail(reg != NULL);
    g_return_if_fail(GNUCASH_IS_REGISTER(reg));

    sheet = GNUCASH_SHEET(reg->sheet);
    gnucash_sheet_refresh_from_prefs(sheet);
    gnc_header_request_redraw (GNC_HEADER(sheet->header_item));
}
Example #8
0
void
gnucash_register_goto_virt_loc (GnucashRegister *reg,
                                VirtualLocation virt_loc)
{
    GnucashSheet *sheet;

    g_return_if_fail(reg != NULL);
    g_return_if_fail(GNUCASH_IS_REGISTER(reg));

    sheet = GNUCASH_SHEET(reg->sheet);

    gnucash_sheet_goto_virt_loc(sheet, virt_loc);
}
Example #9
0
GtkWidget *
gnucash_register_new (Table *table, gchar *state_section)
{
    GnucashRegister *reg;
    GtkWidget *widget;

    widget = gnucash_register_create_widget(table);
    reg = GNUCASH_REGISTER(widget);

    gnucash_register_configure (GNUCASH_SHEET(reg->sheet), state_section);

    return widget;
}
Example #10
0
gboolean
gnucash_register_has_selection (GnucashRegister *reg)
{
    GnucashSheet *sheet;
    GncItemEdit *item_edit;

    g_return_val_if_fail((reg != NULL), FALSE);
    g_return_val_if_fail(GNUCASH_IS_REGISTER(reg), FALSE);

    sheet = GNUCASH_SHEET(reg->sheet);
    item_edit = GNC_ITEM_EDIT(sheet->item_editor);

    return gnc_item_edit_get_has_selection(item_edit);
}
Example #11
0
void
gnucash_register_paste_clipboard (GnucashRegister *reg)
{
    GnucashSheet *sheet;
    GncItemEdit *item_edit;

    g_return_if_fail(reg != NULL);
    g_return_if_fail(GNUCASH_IS_REGISTER(reg));

    sheet = GNUCASH_SHEET(reg->sheet);
    item_edit = GNC_ITEM_EDIT(sheet->item_editor);

    gnc_item_edit_paste_clipboard (item_edit);
}
Example #12
0
static void
table_ui_redraw_cb (Table *table)
{
    GnucashSheet *sheet;

    if (table == NULL)
        return;

    if (table->ui_data == NULL)
        return;

    sheet = GNUCASH_SHEET (table->ui_data);

    gnucash_sheet_redraw_help (sheet);
}
Example #13
0
void
gnc_header_reconfigure (GncHeader *header)
{
    GnomeCanvas *canvas;
    GtkWidget *widget;
    GnucashSheet *sheet;
    SheetBlockStyle *old_style;
    int w, h;

    g_return_if_fail (header != NULL);
    g_return_if_fail (GNC_IS_HEADER (header));

    canvas = GNOME_CANVAS_ITEM(header)->canvas;
    widget = GTK_WIDGET (header->sheet);
    sheet = GNUCASH_SHEET(header->sheet);
    old_style = header->style;

    header->style = gnucash_sheet_get_style_from_cursor
                    (sheet, header->cursor_name);

    if (header->style == NULL)
        return;

    sheet->width = header->style->dimensions->width;

    w = header->style->dimensions->width;
    h = header->style->dimensions->height;
    h *= header->num_phys_rows;
    h /= header->style->nrows;
    h += 2;

    if (header->height != h ||
            header->width != w  ||
            header->style != old_style)
    {
        header->height = h;
        header->width = w;

        gnome_canvas_set_scroll_region (GNOME_CANVAS(canvas),
                                        0, 0, w, h);

        gtk_widget_set_size_request (GTK_WIDGET(canvas), -1, h);

        gnc_header_request_redraw (header);
    }
}
Example #14
0
static void
table_destroy_cb (Table *table)
{
    GnucashSheet *sheet;

    if (table == NULL)
        return;

    if (table->ui_data == NULL)
        return;

    sheet = GNUCASH_SHEET (table->ui_data);

    g_object_unref (sheet);

    table->ui_data = NULL;
}
static void
gnc_item_edit_set_property (GObject *object,
                            guint param_id,
                            const GValue *value,
                            GParamSpec *pspec)
{
    GncItemEdit *item_edit = GNC_ITEM_EDIT (object);

    switch (param_id)
    {
    case PROP_SHEET:
        item_edit->sheet = GNUCASH_SHEET (g_value_get_object (value));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
        break;
    }
}
Example #16
0
void
gnc_table_refresh_gui (Table * table, gboolean do_scroll)
{
    GnucashSheet *sheet;

    if (!table)
        return;
    if (!table->ui_data)
        return;

    g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));

    sheet = GNUCASH_SHEET(table->ui_data);

    gnucash_sheet_styles_recompile (sheet);
    gnucash_sheet_table_load (sheet, do_scroll);
    gnucash_sheet_redraw_all (sheet);
}
Example #17
0
void
gnucash_register_goto_virt_cell (GnucashRegister *reg,
                                 VirtualCellLocation vcell_loc)
{
    GnucashSheet *sheet;
    VirtualLocation virt_loc;

    g_return_if_fail(reg != NULL);
    g_return_if_fail(GNUCASH_IS_REGISTER(reg));

    sheet = GNUCASH_SHEET(reg->sheet);

    virt_loc.vcell_loc = vcell_loc;
    virt_loc.phys_row_offset = 0;
    virt_loc.phys_col_offset = 0;

    gnucash_sheet_goto_virt_loc(sheet, virt_loc);
}
Example #18
0
void
gnc_table_save_state (Table *table, gchar * state_key)
{
    GnucashSheet *sheet;
    GNCHeaderWidths widths;
    GList *node;
    gchar *key;
    
    if (!table)
        return;

    if (table->ui_data == NULL)
        return;

    if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
        return;

    sheet = GNUCASH_SHEET (table->ui_data);

    widths = gnc_header_widths_new ();

    gnucash_sheet_get_header_widths (sheet, widths);

    node = gnc_table_layout_get_cells (table->layout);
    for (; node; node = node->next)
    {
        BasicCell *cell = node->data;
        int width;

        width = gnc_header_widths_get_width (widths, cell->cell_name);
        if (width <= 0)
            continue;

        if (cell->expandable)
            continue;

        /* Remember whether the column is visible */
        key = g_strdup_printf("%s_width", cell->cell_name);
        // FIXME the actual state saving is currently not implemented
        g_free(key);
    }

    gnc_header_widths_destroy (widths);
}
Example #19
0
static void
gnucash_cursor_set_property (GObject         *object,
                             guint            prop_id,
                             const GValue    *value,
                             GParamSpec      *pspec)
{
    GnucashCursor *cursor;

    cursor = GNUCASH_CURSOR (object);

    switch (prop_id)
    {
    case PROP_SHEET:
        cursor->sheet =
            GNUCASH_SHEET (g_value_get_object (value));
        break;
    default:
        break;
    }
}
Example #20
0
void
gnc_table_show_range (Table *table,
                      VirtualCellLocation start_loc,
                      VirtualCellLocation end_loc)
{
    GnucashSheet *sheet;

    if (!table || !table->ui_data)
        return;

    g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));

    if (gnc_table_virtual_cell_out_of_bounds (table, start_loc))
        return;

    if (gnc_table_virtual_cell_out_of_bounds (table, end_loc))
        return;

    sheet = GNUCASH_SHEET (table->ui_data);

    gnucash_sheet_show_range (sheet, start_loc, end_loc);
}
Example #21
0
void
gnc_header_reconfigure (GncHeader *header)
{
    GnucashSheet *sheet;
    SheetBlockStyle *old_style;
    int w, h;

    g_return_if_fail (header != NULL);
    g_return_if_fail (GNC_IS_HEADER (header));

    sheet = GNUCASH_SHEET(header->sheet);
    old_style = header->style;

    header->style = gnucash_sheet_get_style_from_cursor
                    (sheet, header->cursor_name);

    if (header->style == NULL)
        return;

    sheet->width = header->style->dimensions->width;

    w = header->style->dimensions->width;
    h = header->style->dimensions->height;
    h *= header->num_phys_rows;
    h /= header->style->nrows;
    h += 2;

    if (header->height != h ||
            header->width != w  ||
            header->style != old_style)
    {
        header->height = h;
        header->width = w;
        gtk_layout_set_size(GTK_LAYOUT(header), w, h);
        gtk_widget_set_size_request(GTK_WIDGET(header), -1, h);
        gnc_header_request_redraw (header);
    }
}
Example #22
0
void
gnucash_register_goto_next_matching_row (GnucashRegister *reg,
        VirtualLocationMatchFunc match,
        gpointer user_data)
{
    GnucashSheet *sheet;
    SheetBlockStyle *style;
    VirtualLocation virt_loc;

    g_return_if_fail (reg != NULL);
    g_return_if_fail (GNUCASH_IS_REGISTER(reg));
    g_return_if_fail (match != NULL);

    sheet = GNUCASH_SHEET (reg->sheet);

    gnucash_cursor_get_virt (GNUCASH_CURSOR(sheet->cursor), &virt_loc);

    do
    {
        if (!gnc_table_move_vertical_position (sheet->table,
                                               &virt_loc, 1))
            return;

        if (virt_loc.vcell_loc.virt_row >= sheet->num_virt_rows)
            return;

        style = gnucash_sheet_get_style (sheet, virt_loc.vcell_loc);
        if (!style || !style->cursor)
            return;
    }
    while (!match (virt_loc, user_data));

    virt_loc.phys_row_offset = 0;
    virt_loc.phys_col_offset = 0;

    gnucash_sheet_goto_virt_loc (sheet, virt_loc);
}
Example #23
0
static gboolean
gnucash_register_enter_scrollbar (GtkWidget *widget,
                                  GdkEvent *event, gpointer user_data)
{
    GnucashRegister *reg = user_data;
    GnucashSheet *sheet = GNUCASH_SHEET(reg->sheet);
    GtkWidget *vscrollbar = sheet->vscrollbar;
    GtkWidget *hscrollbar = sheet->hscrollbar;

    // There seems to be a problem with the scrollbar slider not being
    // updated as the mouse moves possibly related to the following bug
    // https://bugzilla.gnome.org/show_bug.cgi?id=765410
    // If they are hidden and shown it seems to fix it.

    gtk_widget_hide (GTK_WIDGET(vscrollbar));
    gtk_widget_show (GTK_WIDGET(vscrollbar));

    if (gtk_widget_is_visible (hscrollbar))
    {
        gtk_widget_hide (GTK_WIDGET(hscrollbar));
        gtk_widget_show (GTK_WIDGET(hscrollbar));
    }
    return FALSE;
}
Example #24
0
void
gnc_table_init_gui (GtkWidget *widget, gchar * state_key)
{
    GNCHeaderWidths widths;
    GnucashSheet *sheet;
    GnucashRegister *greg;
    Table *table;
    GList *node;
    gchar *key;
    guint value;
 
    // Stuff for per-register settings load.
    g_return_if_fail (widget != NULL);
    g_return_if_fail (GNUCASH_IS_REGISTER (widget));
    
    PINFO("state_key=%s",state_key);
    
    ENTER("widget=%p, data=%p", widget, "");
    

    greg = GNUCASH_REGISTER (widget);
    sheet = GNUCASH_SHEET (greg->sheet);
    table = sheet->table;

    table->gui_handlers.redraw_help = table_ui_redraw_cb;
    table->gui_handlers.destroy = table_destroy_cb;
    table->ui_data = sheet;

    g_object_ref (sheet);

    /* config the cell-block styles */

    widths = gnc_header_widths_new ();

    if (gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
    {
        node = gnc_table_layout_get_cells (table->layout);
        for (; node; node = node->next)
        {
            BasicCell *cell = node->data;

            if (cell->expandable)
                continue;

            /* Remember whether the column is visible */
            key = g_strdup_printf("%s_width", cell->cell_name);
            // FIXME the actual state loading is currently not implemented
            value = 0;
            if (value != 0)
                gnc_header_widths_set_width (widths, cell->cell_name, value);
            g_free(key);
        }
    }

    gnucash_sheet_create_styles (sheet);

    gnucash_sheet_set_header_widths (sheet, widths);

    gnucash_sheet_compile_styles (sheet);

    gnucash_sheet_table_load (sheet, TRUE);
    gnucash_sheet_cursor_set_from_table (sheet, TRUE);
    gnucash_sheet_redraw_all (sheet);

    gnc_header_widths_destroy (widths);

    LEAVE(" ");
}
Example #25
0
static GtkWidget *
gnucash_register_create_widget (Table *table)
{
    GnucashRegister *reg;
    GtkWidget *header;
    GtkWidget *widget;
    GtkWidget *sheet;
    GtkWidget *scrollbar;
    GtkWidget *box;

    reg = g_object_new (GNUCASH_TYPE_REGISTER, NULL);
    widget = GTK_WIDGET(reg);

    sheet = gnucash_sheet_new (table);
    reg->sheet = sheet;
    GNUCASH_SHEET(sheet)->reg = widget;

    header = gnc_header_new (GNUCASH_SHEET(sheet));

    gtk_grid_attach (GTK_GRID(widget), header, 0, 0, 1, 1);
    gtk_widget_set_hexpand (header, TRUE);
    gtk_widget_set_halign (header, GTK_ALIGN_FILL);
    gtk_widget_set_vexpand (header, FALSE);
    gtk_widget_set_valign (header, GTK_ALIGN_FILL);
    g_object_set (header, "margin", 0, NULL);
    gtk_widget_show (header);

    gtk_grid_attach (GTK_GRID(widget), sheet, 0, 1, 1, 1);
    gtk_widget_set_hexpand (sheet, TRUE);
    gtk_widget_set_halign (sheet, GTK_ALIGN_FILL);
    gtk_widget_set_vexpand (sheet, TRUE);
    gtk_widget_set_valign (sheet, GTK_ALIGN_FILL);
    g_object_set (sheet, "margin", 0, NULL);
    gtk_widget_show (sheet);

    scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, GNUCASH_SHEET(sheet)->vadj);
    gtk_grid_attach (GTK_GRID(widget), GTK_WIDGET(scrollbar), 1, 0, 1, 2);
    gtk_widget_set_hexpand (GTK_WIDGET(scrollbar), FALSE);
    gtk_widget_set_halign (GTK_WIDGET(scrollbar), GTK_ALIGN_FILL);
    gtk_widget_set_vexpand (GTK_WIDGET(scrollbar), TRUE);
    gtk_widget_set_valign (GTK_WIDGET(scrollbar), GTK_ALIGN_FILL);
    g_object_set (GTK_WIDGET(scrollbar), "margin", 0, NULL);
    gtk_widget_show (scrollbar);
    GNUCASH_SHEET(sheet)->vscrollbar = scrollbar;

    g_signal_connect(G_OBJECT(scrollbar), "enter-notify-event",
                      G_CALLBACK(gnucash_register_enter_scrollbar), reg);

    scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, GNUCASH_SHEET(sheet)->hadj);
    gtk_grid_attach (GTK_GRID(widget), GTK_WIDGET(scrollbar), 0, 2, 1, 1);
    gtk_widget_set_hexpand (GTK_WIDGET(scrollbar), TRUE);
    gtk_widget_set_halign (GTK_WIDGET(scrollbar), GTK_ALIGN_FILL);
    gtk_widget_set_vexpand (GTK_WIDGET(scrollbar), FALSE);
    gtk_widget_set_valign (GTK_WIDGET(scrollbar), GTK_ALIGN_FILL);
    g_object_set (GTK_WIDGET(scrollbar), "margin", 0, NULL);
    reg->hscrollbar = scrollbar;
    gtk_widget_show (reg->hscrollbar);
    reg->hscrollbar_visible = TRUE;
    GNUCASH_SHEET(sheet)->hscrollbar = scrollbar;

    g_signal_connect(G_OBJECT(scrollbar), "enter-notify-event",
                      G_CALLBACK(gnucash_register_enter_scrollbar), reg);

    g_signal_connect (GNUCASH_SHEET(sheet)->hadj, "changed",
                      G_CALLBACK (gnucash_register_update_hadjustment), reg);

    return widget;
}