business-gnome.scm: add global preferences for the invoice dialog

dialog-invoice.c:   get the dialog to size itself properly, and save the
		    width between runs.
gnucash-sheet.c:    fix a bug where the "optimal size" is reporting the
		    wrong value.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6892 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2002-05-22 23:49:43 +00:00
parent ed76a1493e
commit cd8551e563
4 changed files with 141 additions and 67 deletions

View File

@ -298,3 +298,18 @@
) )
(gnc:hook-add-dangler gnc:*add-extension-hook* add-business-extensions) (gnc:hook-add-dangler gnc:*add-extension-hook* add-business-extensions)
(gnc:register-configuration-option
(gnc:make-internal-option
"__gui" "invoice_reg_width" 0))
(gnc:register-configuration-option
(gnc:make-number-range-option
(N_ "Invoice") (N_ "Number of Rows")
"d" (N_ "Default number of register rows to display.")
10.0 ;; default
1.0 ;; lower bound
200.0 ;; upper bound
0.0 ;; number of decimals
1.0 ;; step size
))

View File

@ -84,6 +84,8 @@ struct _invoice_window {
GtkWidget * billing_id_entry; GtkWidget * billing_id_entry;
GtkWidget * terms_entry; GtkWidget * terms_entry;
gint width;
GnucashRegister * reg; GnucashRegister * reg;
GncEntryLedger * ledger; GncEntryLedger * ledger;
@ -97,6 +99,9 @@ struct _invoice_window {
}; };
#define WIDTH_PREFIX "invoice_reg"
static int last_width = 0;
static void gnc_invoice_update_window (InvoiceWindow *iw); static void gnc_invoice_update_window (InvoiceWindow *iw);
static InvoiceWindow * gnc_ui_invoice_modify (GncInvoice *invoice); static InvoiceWindow * gnc_ui_invoice_modify (GncInvoice *invoice);
@ -633,6 +638,43 @@ gnc_invoice_window_create_popup_menu (InvoiceWindow *iw)
return popup; return popup;
} }
static void
gnc_invoice_save_size (InvoiceWindow *iw)
{
gdk_window_get_geometry (iw->dialog->window, NULL, NULL, &last_width,
NULL, NULL);
gnc_save_window_size (WIDTH_PREFIX, last_width, 0);
}
static void
size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
gpointer user_data)
{
InvoiceWindow *iw = user_data;
gboolean resize = FALSE;
/* HACK ALERT. this seems to be the only thing to get the
* freekin register window to stop freekin resizing itself
* all the freekin time.
*
* NOTE: Only resize on the SECOND time through. I don't know why,
* but this really seems to have an effect on the window the
* _second_ time you pop one up.
*/
if (iw->width == allocation->width)
return;
if (iw->width > 0)
resize = TRUE;
iw->width = allocation->width;
if (resize)
gtk_window_set_default_size (GTK_WINDOW(iw->dialog), iw->width, 0);
}
static int static int
gnc_invoice_job_changed_cb (GtkWidget *widget, gpointer data) gnc_invoice_job_changed_cb (GtkWidget *widget, gpointer data)
{ {
@ -781,7 +823,14 @@ gnc_invoice_window_close_handler (gpointer user_data)
InvoiceWindow *iw = user_data; InvoiceWindow *iw = user_data;
if (iw) { if (iw) {
/* XXX Save the register size */ switch (iw->dialog_type) {
case VIEW_INVOICE:
case EDIT_INVOICE:
gnc_invoice_save_size (iw);
break;
default:
break;
}
gtk_widget_destroy (iw->dialog); gtk_widget_destroy (iw->dialog);
} }
} }
@ -913,6 +962,19 @@ gnc_invoice_update_window (InvoiceWindow *iw)
gnc_invoice_update_job_choice (iw); gnc_invoice_update_job_choice (iw);
switch (iw->dialog_type) {
case VIEW_INVOICE:
case EDIT_INVOICE:
if (last_width == 0)
gnc_get_window_size (WIDTH_PREFIX, &last_width, NULL);
gtk_window_set_default_size (GTK_WINDOW (iw->dialog), last_width, 0);
break;
default:
break;
}
gtk_widget_show_all (iw->dialog); gtk_widget_show_all (iw->dialog);
acct_entry = glade_xml_get_widget (iw->xml, "acct_entry"); acct_entry = glade_xml_get_widget (iw->xml, "acct_entry");
@ -1064,6 +1126,7 @@ gnc_invoice_new_window (GNCBook *bookp, InvoiceDialogType type,
iw = g_new0 (InvoiceWindow, 1); iw = g_new0 (InvoiceWindow, 1);
iw->book = bookp; iw->book = bookp;
iw->dialog_type = type; iw->dialog_type = type;
iw->width = -1;
/* Save this for later */ /* Save this for later */
gncOwnerCopy (gncOwnerGetEndOwner (owner), &(iw->owner)); gncOwnerCopy (gncOwnerGetEndOwner (owner), &(iw->owner));
@ -1116,39 +1179,6 @@ gnc_invoice_new_window (GNCBook *bookp, InvoiceDialogType type,
/* Set the entry_ledger's invoice */ /* Set the entry_ledger's invoice */
gnc_entry_ledger_set_default_invoice (entry_ledger, invoice); gnc_entry_ledger_set_default_invoice (entry_ledger, invoice);
/* Create the register */
{
GtkWidget *regWidget, *vbox;
GtkWidget *popup;
guint num_rows;
num_rows = (guint) gnc_lookup_number_option ("Register",
"Number of Rows", 20.0);
gnucash_register_set_initial_rows( num_rows );
/* Watch the order of operations, here... */
regWidget = gnucash_register_new (gnc_entry_ledger_get_table
(entry_ledger));
gnc_table_init_gui( regWidget, entry_ledger );
vbox = glade_xml_get_widget (xml, "ledger_vbox");
gtk_box_pack_start (GTK_BOX(vbox), regWidget, TRUE, TRUE, 2);
iw->reg = GNUCASH_REGISTER (regWidget);
GNUCASH_SHEET (iw->reg->sheet)->window = GTK_WIDGET(iw->dialog);
gtk_signal_connect (GTK_OBJECT(regWidget), "activate_cursor",
GTK_SIGNAL_FUNC(recordCB), iw);
gtk_signal_connect (GTK_OBJECT(regWidget), "redraw_all",
GTK_SIGNAL_FUNC(gnc_invoice_redraw_all_cb), iw);
gtk_signal_connect (GTK_OBJECT(regWidget), "redraw_help",
GTK_SIGNAL_FUNC(gnc_invoice_redraw_help_cb), iw);
popup = gnc_invoice_window_create_popup_menu (iw);
gnucash_register_attach_popup (GNUCASH_REGISTER (regWidget),
popup, iw);
}
/* load the menu bar */ /* load the menu bar */
/* /*
{ {
@ -1184,12 +1214,50 @@ gnc_invoice_new_window (GNCBook *bookp, InvoiceDialogType type,
gtk_signal_connect (GTK_OBJECT (iw->dialog), "destroy", gtk_signal_connect (GTK_OBJECT (iw->dialog), "destroy",
GTK_SIGNAL_FUNC(gnc_invoice_window_destroy_cb), iw); GTK_SIGNAL_FUNC(gnc_invoice_window_destroy_cb), iw);
gtk_signal_connect (GTK_OBJECT (iw->dialog), "size-allocate",
GTK_SIGNAL_FUNC(size_allocate), iw);
/* Create the register */
{
GtkWidget *regWidget, *frame;
GtkWidget *popup;
guint num_rows;
num_rows = (guint) gnc_lookup_number_option ("Invoice",
"Number of Rows", 10.0);
gnucash_register_set_initial_rows( num_rows );
/* Watch the order of operations, here... */
regWidget = gnucash_register_new (gnc_entry_ledger_get_table
(entry_ledger));
gnc_table_init_gui( regWidget, entry_ledger );
frame = glade_xml_get_widget (xml, "ledger_frame");
gtk_container_add (GTK_CONTAINER (frame), regWidget);
iw->reg = GNUCASH_REGISTER (regWidget);
GNUCASH_SHEET (iw->reg->sheet)->window = iw->dialog;
gtk_signal_connect (GTK_OBJECT(regWidget), "activate_cursor",
GTK_SIGNAL_FUNC(recordCB), iw);
gtk_signal_connect (GTK_OBJECT(regWidget), "redraw_all",
GTK_SIGNAL_FUNC(gnc_invoice_redraw_all_cb), iw);
gtk_signal_connect (GTK_OBJECT(regWidget), "redraw_help",
GTK_SIGNAL_FUNC(gnc_invoice_redraw_help_cb), iw);
popup = gnc_invoice_window_create_popup_menu (iw);
gnucash_register_attach_popup (GNUCASH_REGISTER (regWidget),
popup, iw);
}
gnc_table_realize_gui (gnc_entry_ledger_get_table (entry_ledger)); gnc_table_realize_gui (gnc_entry_ledger_get_table (entry_ledger));
/* Now fill in a lot of the pieces and display properly */ /* Now fill in a lot of the pieces and display properly */
gnc_invoice_update_window (iw); gnc_invoice_update_window (iw);
gnc_table_refresh_gui (gnc_entry_ledger_get_table (iw->ledger), TRUE); gnc_table_refresh_gui (gnc_entry_ledger_get_table (iw->ledger), TRUE);
gnc_window_adjust_for_screen (GTK_WINDOW(iw->dialog));
return iw; return iw;
} }
@ -1203,17 +1271,10 @@ gnc_invoice_window_new_invoice (GNCBook *bookp, GncOwner *owner,
GnomeDialog *iwd; GnomeDialog *iwd;
GtkWidget *hbox; GtkWidget *hbox;
iw = g_new0 (InvoiceWindow, 1); if (invoice) {
if (invoice == NULL) {
iw->dialog_type = NEW_INVOICE;
invoice = gncInvoiceCreate (bookp);
gncInvoiceSetCommonCommodity (invoice, gnc_default_currency ()); /* XXX */
iw->book = bookp;
} else {
/* /*
* Find an existing window for this invoice. If found, bring it to * Try to find an existing window for this invoice. If found,
* the front. * bring it to the front.
*/ */
GUID invoice_guid; GUID invoice_guid;
@ -1224,11 +1285,20 @@ gnc_invoice_window_new_invoice (GNCBook *bookp, GncOwner *owner,
gtk_window_present (GTK_WINDOW(iw->dialog)); gtk_window_present (GTK_WINDOW(iw->dialog));
return(iw); return(iw);
} }
}
/* /*
* No existing invoice window found. Build a new one. * No existing invoice window found. Build a new one.
*/ */
iw = g_new0 (InvoiceWindow, 1);
if (invoice == NULL) {
iw->dialog_type = NEW_INVOICE;
invoice = gncInvoiceCreate (bookp);
gncInvoiceSetCommonCommodity (invoice, gnc_default_currency ()); /* XXX */
iw->book = bookp;
} else {
iw->dialog_type = MOD_INVOICE; iw->dialog_type = MOD_INVOICE;
owner = gncInvoiceGetOwner (invoice); owner = gncInvoiceGetOwner (invoice);
iw->book = gncInvoiceGetBook (invoice); iw->book = gncInvoiceGetBook (invoice);

View File

@ -425,10 +425,10 @@
<type>GTK_WINDOW_TOPLEVEL</type> <type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position> <position>GTK_WIN_POS_NONE</position>
<modal>False</modal> <modal>False</modal>
<allow_shrink>False</allow_shrink> <allow_shrink>True</allow_shrink>
<allow_grow>True</allow_grow> <allow_grow>True</allow_grow>
<auto_shrink>False</auto_shrink> <auto_shrink>False</auto_shrink>
<enable_layout_config>True</enable_layout_config> <enable_layout_config>False</enable_layout_config>
<widget> <widget>
<class>GnomeDock</class> <class>GnomeDock</class>
@ -496,7 +496,7 @@
<child> <child>
<padding>3</padding> <padding>3</padding>
<expand>False</expand> <expand>False</expand>
<fill>False</fill> <fill>True</fill>
</child> </child>
<widget> <widget>
@ -989,20 +989,9 @@
<fill>True</fill> <fill>True</fill>
</child> </child>
<widget>
<class>GtkVBox</class>
<name>ledger_vbox</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<widget> <widget>
<class>Placeholder</class> <class>Placeholder</class>
</widget> </widget>
<widget>
<class>Placeholder</class>
</widget>
</widget>
</widget> </widget>
</widget> </widget>
</widget> </widget>

View File

@ -647,8 +647,8 @@ compute_optimal_width (GnucashSheet *sheet)
if (!style) if (!style)
return DEFAULT_REGISTER_WIDTH; return DEFAULT_REGISTER_WIDTH;
if (sheet->window_width >= 0) // if (sheet->window_width >= 0)
return sheet->window_width; // return sheet->window_width;
if (!style->dimensions) if (!style->dimensions)
return DEFAULT_REGISTER_WIDTH; return DEFAULT_REGISTER_WIDTH;
@ -668,8 +668,8 @@ compute_optimal_height (GnucashSheet *sheet)
if (!sheet) if (!sheet)
return DEFAULT_REGISTER_HEIGHT; return DEFAULT_REGISTER_HEIGHT;
if (sheet->window_height >= 0) // if (sheet->window_height >= 0)
return sheet->window_height; // return sheet->window_height;
style = gnucash_sheet_get_style_from_cursor (sheet, CURSOR_HEADER); style = gnucash_sheet_get_style_from_cursor (sheet, CURSOR_HEADER);
if (!style) if (!style)