33 #include <glib/gprintf.h> 34 #include <gdk/gdkkeysyms.h> 36 #include "gnucash-register.h" 50 #include "completioncell.h" 53 #include "pricecell-gnome.h" 54 #include "quickfillcell-gnome.h" 55 #include "table-gnome.h" 72 static QofLogModule log_module = GNC_MOD_REGISTER;
73 static guint register_signals[LAST_SIGNAL];
80 GtkWidget *hscrollbar;
82 gboolean hscrollbar_visible;
88 GtkGridClass parent_class;
90 void (*activate_cursor) (GnucashRegister *reg);
91 void (*redraw_all) (GnucashRegister *reg);
92 void (*redraw_help) (GnucashRegister *reg);
93 void (*show_popup_menu) (GnucashRegister *reg);
98 G_DEFINE_TYPE (GnucashRegister, gnucash_register, GTK_TYPE_GRID)
103 gnc_register_add_cell_type (COMBO_CELL_TYPE_NAME, gnc_combo_cell_new);
104 gnc_register_add_cell_type (COMPLETION_CELL_TYPE_NAME, gnc_completion_cell_new);
106 gnc_register_add_cell_type (PRICE_CELL_TYPE_NAME,
107 gnc_price_cell_gnome_new);
108 gnc_register_add_cell_type (QUICKFILL_CELL_TYPE_NAME,
109 gnc_quickfill_cell_gnome_new);
110 gnc_register_add_cell_type( FORMULA_CELL_TYPE_NAME,
111 gnc_formula_cell_gnome_new );
112 gnc_table_gnome_init ();
116 gnucash_register_has_selection (GnucashRegister *reg)
121 g_return_val_if_fail((reg != NULL), FALSE);
122 g_return_val_if_fail(GNUCASH_IS_REGISTER(reg), FALSE);
124 sheet = GNUCASH_SHEET(reg->sheet);
125 item_edit = GNC_ITEM_EDIT(sheet->item_editor);
127 return gnc_item_edit_get_has_selection(item_edit);
131 gnucash_register_cut_clipboard (GnucashRegister *reg)
136 g_return_if_fail(reg != NULL);
137 g_return_if_fail(GNUCASH_IS_REGISTER(reg));
139 sheet = GNUCASH_SHEET(reg->sheet);
140 item_edit = GNC_ITEM_EDIT(sheet->item_editor);
142 gnc_item_edit_cut_clipboard(item_edit);
146 gnucash_register_copy_clipboard (GnucashRegister *reg)
151 g_return_if_fail(reg != NULL);
152 g_return_if_fail(GNUCASH_IS_REGISTER(reg));
154 sheet = GNUCASH_SHEET(reg->sheet);
155 item_edit = GNC_ITEM_EDIT(sheet->item_editor);
157 gnc_item_edit_copy_clipboard(item_edit);
161 gnucash_register_paste_clipboard (GnucashRegister *reg)
166 g_return_if_fail(reg != NULL);
167 g_return_if_fail(GNUCASH_IS_REGISTER(reg));
169 sheet = GNUCASH_SHEET(reg->sheet);
170 item_edit = GNC_ITEM_EDIT(sheet->item_editor);
172 gnc_item_edit_paste_clipboard (item_edit);
176 gnucash_register_refresh_from_prefs (GnucashRegister *reg)
180 g_return_if_fail(reg != NULL);
181 g_return_if_fail(GNUCASH_IS_REGISTER(reg));
183 sheet = GNUCASH_SHEET(reg->sheet);
184 gnucash_sheet_refresh_from_prefs(sheet);
185 gnc_header_request_redraw (GNC_HEADER(sheet->header_item));
189 gnucash_register_reset_sheet_layout (GnucashRegister *reg)
191 GNCHeaderWidths widths;
195 g_return_if_fail (reg != NULL);
197 sheet = GNUCASH_SHEET(reg->sheet);
199 g_return_if_fail (sheet != NULL);
200 g_return_if_fail (GNUCASH_IS_SHEET (sheet));
202 current_width = sheet->window_width - 1;
204 widths = gnc_header_widths_new ();
205 gnucash_sheet_set_header_widths (sheet, widths);
207 gnucash_sheet_styles_set_dimensions (sheet, current_width);
209 gnucash_sheet_compile_styles (sheet);
210 gnucash_sheet_table_load (sheet, TRUE);
211 gnucash_sheet_cursor_set_from_table (sheet, TRUE);
212 gnucash_sheet_redraw_all (sheet);
213 gnc_header_widths_destroy (widths);
217 gnucash_register_goto_virt_cell (GnucashRegister *reg,
218 VirtualCellLocation vcell_loc)
221 VirtualLocation virt_loc;
223 g_return_if_fail(reg != NULL);
224 g_return_if_fail(GNUCASH_IS_REGISTER(reg));
226 sheet = GNUCASH_SHEET(reg->sheet);
228 virt_loc.vcell_loc = vcell_loc;
229 virt_loc.phys_row_offset = 0;
230 virt_loc.phys_col_offset = 0;
232 gnucash_sheet_goto_virt_loc(sheet, virt_loc);
236 gnucash_register_goto_virt_loc (GnucashRegister *reg,
237 VirtualLocation virt_loc)
241 g_return_if_fail(reg != NULL);
242 g_return_if_fail(GNUCASH_IS_REGISTER(reg));
244 sheet = GNUCASH_SHEET(reg->sheet);
246 gnucash_sheet_goto_virt_loc(sheet, virt_loc);
250 gnucash_register_goto_next_virt_row (GnucashRegister *reg)
253 VirtualLocation virt_loc;
256 g_return_if_fail (reg != NULL);
257 g_return_if_fail (GNUCASH_IS_REGISTER(reg));
259 sheet = GNUCASH_SHEET(reg->sheet);
261 gnucash_cursor_get_virt (GNUCASH_CURSOR(sheet->cursor), &virt_loc);
265 start_virt_row = virt_loc.vcell_loc.virt_row;
271 while (start_virt_row == virt_loc.vcell_loc.virt_row);
273 if (virt_loc.vcell_loc.virt_row >= sheet->num_virt_rows)
276 virt_loc.phys_row_offset = 0;
277 virt_loc.phys_col_offset = 0;
279 gnucash_sheet_goto_virt_loc (sheet, virt_loc);
283 gnucash_register_goto_next_matching_row (GnucashRegister *reg,
284 VirtualLocationMatchFunc match,
288 SheetBlockStyle *style;
289 VirtualLocation virt_loc;
291 g_return_if_fail (reg != NULL);
292 g_return_if_fail (GNUCASH_IS_REGISTER(reg));
293 g_return_if_fail (match != NULL);
295 sheet = GNUCASH_SHEET (reg->sheet);
297 gnucash_cursor_get_virt (GNUCASH_CURSOR(sheet->cursor), &virt_loc);
305 if (virt_loc.vcell_loc.virt_row >= sheet->num_virt_rows)
308 style = gnucash_sheet_get_style (sheet, virt_loc.vcell_loc);
309 if (!style || !style->cursor)
312 while (!match (virt_loc, user_data));
314 virt_loc.phys_row_offset = 0;
315 virt_loc.phys_col_offset = 0;
317 gnucash_sheet_goto_virt_loc (sheet, virt_loc);
321 gnucash_register_sheet_resize (GnucashRegister *reg)
325 if (!reg->hscrollbar_visible)
326 gtk_widget_queue_resize (GTK_WIDGET (reg->sheet));
332 gnucash_register_update_hadjustment (GtkAdjustment *adj,
333 GnucashRegister *reg)
335 g_return_if_fail (reg != NULL);
336 g_return_if_fail (GNUCASH_IS_REGISTER(reg));
338 if (gtk_adjustment_get_upper (adj) - gtk_adjustment_get_lower (adj)
339 > gtk_adjustment_get_page_size (adj))
341 if (!reg->hscrollbar_visible)
343 gtk_widget_show(reg->hscrollbar);
344 reg->hscrollbar_visible = TRUE;
349 if (reg->hscrollbar_visible)
351 gtk_widget_hide(reg->hscrollbar);
352 reg->hscrollbar_visible = FALSE;
356 g_idle_add ((GSourceFunc) gnucash_register_sheet_resize, reg);
365 gnucash_register_class_init (GnucashRegisterClass *klass)
367 GObjectClass *gobject_class;
369 gobject_class = G_OBJECT_CLASS (klass);
371 gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(klass),
"gnc-id-register");
373 register_signals[ACTIVATE_CURSOR] =
374 g_signal_new(
"activate_cursor",
375 G_TYPE_FROM_CLASS(gobject_class),
377 G_STRUCT_OFFSET(GnucashRegisterClass,
380 g_cclosure_marshal_VOID__VOID,
383 register_signals[REDRAW_ALL] =
384 g_signal_new(
"redraw_all",
385 G_TYPE_FROM_CLASS(gobject_class),
387 G_STRUCT_OFFSET(GnucashRegisterClass,
390 g_cclosure_marshal_VOID__VOID,
393 register_signals[REDRAW_HELP] =
394 g_signal_new(
"redraw_help",
395 G_TYPE_FROM_CLASS(gobject_class),
397 G_STRUCT_OFFSET(GnucashRegisterClass,
400 g_cclosure_marshal_VOID__VOID,
403 register_signals[SHOW_POPUP_MENU] =
404 g_signal_new(
"show_popup_menu",
405 G_TYPE_FROM_CLASS(gobject_class),
407 G_STRUCT_OFFSET(GnucashRegisterClass,
410 g_cclosure_marshal_VOID__VOID,
413 klass->activate_cursor = NULL;
414 klass->redraw_all = NULL;
415 klass->redraw_help = NULL;
416 klass->show_popup_menu = NULL;
421 gnucash_register_init (GnucashRegister *g_reg)
423 GtkGrid *
table = GTK_GRID(g_reg);
425 gtk_widget_set_can_focus (GTK_WIDGET(
table), FALSE);
426 gtk_widget_set_can_default (GTK_WIDGET(
table), FALSE);
428 gtk_grid_set_row_homogeneous (GTK_GRID(
table), FALSE);
429 gtk_grid_set_column_homogeneous (GTK_GRID(
table), FALSE);
433 gnucash_register_attach_popup (GnucashRegister *reg,
437 g_return_if_fail (GNUCASH_IS_REGISTER(reg));
438 g_return_if_fail (reg->sheet != NULL);
440 g_return_if_fail (GTK_IS_WIDGET(popup));
442 gnucash_sheet_set_popup (GNUCASH_SHEET (reg->sheet), popup, data);
455 gnucash_register_configure (GnucashSheet *sheet,
const gchar * state_section)
457 GNCHeaderWidths widths;
465 g_return_if_fail (sheet != NULL);
466 g_return_if_fail (GNUCASH_IS_SHEET (sheet));
468 PINFO(
"state_section=%s",state_section);
470 ENTER(
"sheet=%p, data=%p", sheet,
"");
472 table = sheet->table;
474 table->ui_data = sheet;
476 g_object_ref (sheet);
480 widths = gnc_header_widths_new ();
482 if (state_section &&
gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
484 node = gnc_table_layout_get_cells (
table->layout);
485 for (; node; node = node->next)
487 BasicCell *cell = node->data;
489 if (cell->expandable)
493 key = g_strdup_printf(
"%s_width", cell->cell_name);
494 value = g_key_file_get_integer (state_file, state_section, key, NULL);
496 gnc_header_widths_set_width (widths, cell->cell_name, value);
501 gnucash_sheet_create_styles (sheet);
503 gnucash_sheet_set_header_widths (sheet, widths);
505 gnucash_sheet_compile_styles (sheet);
507 gnucash_sheet_table_load (sheet, TRUE);
508 gnucash_sheet_cursor_set_from_table (sheet, TRUE);
509 gnucash_sheet_redraw_all (sheet);
511 gnc_header_widths_destroy (widths);
518 gnucash_register_create_widget (Table *
table)
520 GnucashRegister *reg;
524 GtkWidget *scrollbar;
526 reg = g_object_new (GNUCASH_TYPE_REGISTER, NULL);
527 widget = GTK_WIDGET(reg);
529 sheet = gnucash_sheet_new (
table);
531 GNUCASH_SHEET(sheet)->reg = widget;
533 header = gnc_header_new (GNUCASH_SHEET(sheet));
535 gtk_grid_attach (GTK_GRID(widget), header, 0, 0, 1, 1);
536 gtk_widget_set_hexpand (header, TRUE);
537 gtk_widget_set_halign (header, GTK_ALIGN_FILL);
538 gtk_widget_set_vexpand (header, FALSE);
539 gtk_widget_set_valign (header, GTK_ALIGN_FILL);
540 g_object_set (header,
"margin", 0, NULL);
541 gtk_widget_show (header);
543 gtk_grid_attach (GTK_GRID(widget), sheet, 0, 1, 1, 1);
544 gtk_widget_set_hexpand (sheet, TRUE);
545 gtk_widget_set_halign (sheet, GTK_ALIGN_FILL);
546 gtk_widget_set_vexpand (sheet, TRUE);
547 gtk_widget_set_valign (sheet, GTK_ALIGN_FILL);
548 g_object_set (sheet,
"margin", 0, NULL);
549 gtk_widget_show (sheet);
551 scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, GNUCASH_SHEET(sheet)->vadj);
552 gtk_grid_attach (GTK_GRID(widget), GTK_WIDGET(scrollbar), 1, 0, 1, 2);
553 gtk_widget_set_hexpand (GTK_WIDGET(scrollbar), FALSE);
554 gtk_widget_set_halign (GTK_WIDGET(scrollbar), GTK_ALIGN_FILL);
555 gtk_widget_set_vexpand (GTK_WIDGET(scrollbar), TRUE);
556 gtk_widget_set_valign (GTK_WIDGET(scrollbar), GTK_ALIGN_FILL);
557 g_object_set (GTK_WIDGET(scrollbar),
"margin", 0, NULL);
558 gtk_widget_show (scrollbar);
559 GNUCASH_SHEET(sheet)->vscrollbar = scrollbar;
561 scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, GNUCASH_SHEET(sheet)->hadj);
562 gtk_grid_attach (GTK_GRID(widget), GTK_WIDGET(scrollbar), 0, 2, 1, 1);
563 gtk_widget_set_hexpand (GTK_WIDGET(scrollbar), TRUE);
564 gtk_widget_set_halign (GTK_WIDGET(scrollbar), GTK_ALIGN_FILL);
565 gtk_widget_set_vexpand (GTK_WIDGET(scrollbar), FALSE);
566 gtk_widget_set_valign (GTK_WIDGET(scrollbar), GTK_ALIGN_FILL);
567 g_object_set (GTK_WIDGET(scrollbar),
"margin", 0, NULL);
568 reg->hscrollbar = scrollbar;
569 gtk_widget_show (reg->hscrollbar);
570 reg->hscrollbar_visible = TRUE;
571 GNUCASH_SHEET(sheet)->hscrollbar = scrollbar;
573 g_signal_connect (GNUCASH_SHEET(sheet)->hadj,
"changed",
574 G_CALLBACK (gnucash_register_update_hadjustment), reg);
583 GnucashRegister *reg;
586 widget = gnucash_register_create_widget(
table);
587 reg = GNUCASH_REGISTER(widget);
589 gnucash_register_configure (GNUCASH_SHEET(reg->sheet), state_section);
595 void gnucash_register_set_moved_cb (GnucashRegister *reg,
596 GFunc cb, gpointer cb_data)
600 if (!reg || !reg->sheet)
602 sheet = GNUCASH_SHEET(reg->sheet);
603 sheet->moved_cb = cb;
604 sheet->moved_cb_data = cb_data;
608 GnucashSheet *gnucash_register_get_sheet (GnucashRegister *reg)
610 g_return_val_if_fail (reg != NULL, NULL);
611 g_return_val_if_fail (GNUCASH_IS_REGISTER(reg), NULL);
613 return GNUCASH_SHEET(reg->sheet);
618 gnucash_register_set_open_doclink_cb (GnucashRegister *reg,
619 GFunc cb, gpointer cb_data)
623 if (!reg || !reg->sheet)
625 sheet = GNUCASH_SHEET(reg->sheet);
626 sheet->open_doclink_cb = cb;
627 sheet->open_doclink_cb_data = cb_data;
Functions to load, save and get gui state.
#define PINFO(format, args...)
Print an informational note.
GtkWidget * gnucash_register_new(Table *table, const gchar *state_section)
this already has scrollbars attached
#define ENTER(format, args...)
Print a function entry debugging message.
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
void gnc_table_init_gui(Table *table)
UI-specific functions.
Public declarations for GnucashCursor class.
BasicCell * gnc_date_cell_new(void)
installs a callback to handle date recording
Public declarations of GnucashRegister class.
Private declarations for GnucashSheet class.
gboolean gnc_table_move_vertical_position(Table *table, VirtualLocation *virt_loc, int phys_row_offset)
Moves away from virtual location virt_loc by phys_row_offset physical rows.
All type declarations for the whole Gnucash engine.
API for checkbook register display area.
Generic api to store and retrieve preferences.
Public declarations for GncItemEdit class.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
#define LEAVE(format, args...)
Print a function exit debugging message.
Styling functions for RegisterGnome.
void gnucash_register_add_cell_types(void)
Implementation.