Reimplement dialog-options for C++.

This commit is contained in:
John Ralls 2020-12-15 10:26:26 -08:00
parent 3b4785e744
commit 67508ea039
9 changed files with 2957 additions and 91 deletions

View File

@ -36,7 +36,7 @@ set (gnome_utils_SOURCES
dialog-dup-trans.c
dialog-file-access.c
dialog-object-references.c
dialog-options.c
dialog-options.cpp
dialog-preferences.c
dialog-query-view.c
dialog-reset-warnings.c
@ -59,7 +59,7 @@ set (gnome_utils_SOURCES
gnc-currency-edit.c
gnc-date-delta.c
gnc-date-edit.c
gnc-date-format.c
gnc-date-format.c
gnc-dense-cal.c
gnc-dense-cal-model.c
gnc-dense-cal-store.c

File diff suppressed because it is too large Load Diff

View File

@ -24,12 +24,23 @@
#define OPTIONS_DIALOG_H
#include <libguile.h>
#include "option-util.h"
#include <gtk/gtk.h>
#ifdef __cplusplus
class GncOption;
class GncOptionDB;
using GNCOption = GncOption;
using GNCOptionDB = GncOptionDB;
extern "C"
{
#else
#include "option-util.h"
typedef GNCOption GncOption;
typedef GNCOptionDB GncOptionDB;
#endif
/** A simple wrapper that casts the gpointer result of
* gnc_option_get_widget() already into a GtkWidget*. */
GtkWidget *gnc_option_get_gtk_widget (GNCOption *option);
GtkWidget* const gnc_option_get_gtk_widget (GncOption *option);
typedef struct gnc_option_win GNCOptionWin;
@ -39,7 +50,6 @@ GNCOptionWin * gnc_options_dialog_new_modal (gboolean modal, gchar *title,
const char *component_class,
GtkWindow *parent);
GNCOptionWin * gnc_options_dialog_new (gchar *title, GtkWindow *parent);
GNCOptionWin * gnc_options_dialog_new_w_dialog (gchar *title, GtkWidget *dialog);
void gnc_options_dialog_destroy (GNCOptionWin * win);
void gnc_options_register_stocks (void);
@ -49,8 +59,8 @@ GtkWidget * gnc_options_dialog_notebook (GNCOptionWin * win);
void gnc_options_dialog_changed (GNCOptionWin *win);
void gnc_option_changed_widget_cb (GtkWidget *widget, GNCOption *option);
void gnc_option_changed_option_cb (GtkWidget *dummy, GNCOption *option);
void gnc_option_changed_widget_cb (GtkWidget *widget, GncOption *option);
void gnc_option_changed_option_cb (GtkWidget *dummy, GncOption *option);
void gnc_options_dialog_set_apply_cb (GNCOptionWin * win,
GNCOptionWinCallback thunk,
@ -67,50 +77,21 @@ void gnc_options_dialog_set_global_help_cb (GNCOptionWinCallback thunk,
void gnc_options_dialog_build_contents (GNCOptionWin *win,
GNCOptionDB *odb);
void gnc_options_dialog_build_contents_full (GNCOptionWin *win,
GNCOptionDB *odb,
gboolean show_dialog);
/* Both apply_cb and close_cb should be scheme functions with 0 arguments.
* References to these functions will be held until the close_cb is called
*/
void gnc_options_dialog_set_scm_callbacks (GNCOptionWin *win,
SCM apply_cb,
SCM close_cb);
/*****************************************************************/
/* Option Registration */
/* Function to set the UI widget based upon the option */
typedef GtkWidget *
(*GNCOptionUISetWidget) (GNCOption *option, GtkGrid *page_box,
GtkLabel *name_label, char *documentation,
/* Return values */
GtkWidget **enclosing, gboolean *packed);
/* Function to set the UI Value for a particular option */
typedef gboolean
(*GNCOptionUISetValue) (GNCOption *option, gboolean use_default,
GtkWidget *widget, SCM value);
/* Function to get the UI Value for a particular option */
typedef SCM
(*GNCOptionUIGetValue) (GNCOption *option, GtkWidget *widget);
typedef struct gnc_option_def
{
const char * option_name;
GNCOptionUISetWidget set_widget;
GNCOptionUISetValue set_value;
GNCOptionUIGetValue get_value;
} GNCOptionDef_t;
/* Register a new option type in the UI */
void gnc_options_ui_initialize (void);
void gnc_options_ui_register_option (GNCOptionDef_t *option);
GNCOptionDef_t * gnc_options_ui_get_option (const char *option_name);
/** Set the help callback to 'gnc_book_options_help_cb' to open a help browser
* and point it to the Book Options link in the Help file.
*/
void gnc_options_dialog_set_book_options_help_cb (GNCOptionWin *win);
/** Set the initial values of new book options to values specified in user
* preferences.
*/
void gnc_options_dialog_set_new_book_option_values (GNCOptionDB *odb);
#ifdef __cplusplus
}
#endif
#endif /* OPTIONS_DIALOG_H */

View File

@ -99,6 +99,7 @@ gnc_book_options_help_cb (GNCOptionWin *win, gpointer dat)
gnc_gnome_help (GTK_WINDOW(gnc_options_dialog_widget (win)), HF_HELP, HL_BOOK_OPTIONS);
}
#if 0 // Reimplemented in dialog-options.cpp
void
gnc_options_dialog_set_book_options_help_cb (GNCOptionWin *win)
{
@ -129,6 +130,7 @@ gnc_options_dialog_set_new_book_option_values (GNCOptionDB *odb)
num_source_is_split_action);
}
}
#endif
static void
gnc_style_sheet_options_help_cb (GNCOptionWin *win, gpointer dat)

View File

@ -42,9 +42,10 @@
#include "dialog-invoice.h"
#define FUNC_NAME G_STRFUNC
/* To be consolidated into dialog-options.cpp later. */
#if 0
static GtkWidget *
create_owner_widget (GNCOption *option, GncOwnerType type, GtkWidget *hbox)
create_owner_widget (GncOption *option, GncOwnerType type, GtkWidget *hbox)
{
GtkWidget *widget;
GncOwner owner;
@ -91,7 +92,7 @@ make_name_label (char *name)
static GncOwnerType
get_owner_type_from_option (GNCOption *option)
get_owner_type_from_option (GncOption *option)
{
SCM odata = gnc_option_get_option_data (option);
@ -102,7 +103,7 @@ get_owner_type_from_option (GNCOption *option)
/* Function to set the UI widget based upon the option */
static GtkWidget *
owner_set_widget (GNCOption *option, GtkGrid *page_box,
owner_set_widget (GncOption *option, GtkGrid *page_box,
GtkLabel *name_label, char *documentation,
/* Return values */
GtkWidget **enclosing, gboolean *packed)
@ -123,7 +124,7 @@ owner_set_widget (GNCOption *option, GtkGrid *page_box,
/* Function to set the UI Value for a particular option */
static gboolean
owner_set_value (GNCOption *option, gboolean use_default,
owner_set_value (GncOption *option, gboolean use_default,
GtkWidget *widget, SCM value)
{
GncOwner owner_def;
@ -150,7 +151,7 @@ owner_set_value (GNCOption *option, gboolean use_default,
/* Function to get the UI Value for a particular option */
static SCM
owner_get_value (GNCOption *option, GtkWidget *widget)
owner_get_value (GncOption *option, GtkWidget *widget)
{
static GncOwner owner; /* XXX: might cause trouble? */
GncOwnerType type;
@ -169,7 +170,7 @@ owner_get_value (GNCOption *option, GtkWidget *widget)
/* Function to set the UI widget based upon the option */
static GtkWidget *
customer_set_widget (GNCOption *option, GtkGrid *page_box,
customer_set_widget (GncOption *option, GtkGrid *page_box,
GtkLabel *name_label, char *documentation,
/* Return values */
GtkWidget **enclosing, gboolean *packed)
@ -189,7 +190,7 @@ customer_set_widget (GNCOption *option, GtkGrid *page_box,
/* Function to set the UI Value for a particular option */
static gboolean
customer_set_value (GNCOption *option, gboolean use_default,
customer_set_value (GncOption *option, gboolean use_default,
GtkWidget *widget, SCM value)
{
GncOwner owner;
@ -209,7 +210,7 @@ customer_set_value (GNCOption *option, gboolean use_default,
/* Function to get the UI Value for a particular option */
static SCM
customer_get_value (GNCOption *option, GtkWidget *widget)
customer_get_value (GncOption *option, GtkWidget *widget)
{
GncOwner owner;
@ -225,7 +226,7 @@ customer_get_value (GNCOption *option, GtkWidget *widget)
/* Function to set the UI widget based upon the option */
static GtkWidget *
vendor_set_widget (GNCOption *option, GtkGrid *page_box,
vendor_set_widget (GncOption *option, GtkGrid *page_box,
GtkLabel *name_label, char *documentation,
/* Return values */
GtkWidget **enclosing, gboolean *packed)
@ -245,7 +246,7 @@ vendor_set_widget (GNCOption *option, GtkGrid *page_box,
/* Function to set the UI Value for a particular option */
static gboolean
vendor_set_value (GNCOption *option, gboolean use_default,
vendor_set_value (GncOption *option, gboolean use_default,
GtkWidget *widget, SCM value)
{
GncOwner owner;
@ -265,7 +266,7 @@ vendor_set_value (GNCOption *option, gboolean use_default,
/* Function to get the UI Value for a particular option */
static SCM
vendor_get_value (GNCOption *option, GtkWidget *widget)
vendor_get_value (GncOption *option, GtkWidget *widget)
{
GncOwner owner;
@ -280,7 +281,7 @@ vendor_get_value (GNCOption *option, GtkWidget *widget)
/* Function to set the UI widget based upon the option */
static GtkWidget *
employee_set_widget (GNCOption *option, GtkGrid *page_box,
employee_set_widget (GncOption *option, GtkGrid *page_box,
GtkLabel *name_label, char *documentation,
/* Return values */
GtkWidget **enclosing, gboolean *packed)
@ -300,7 +301,7 @@ employee_set_widget (GNCOption *option, GtkGrid *page_box,
/* Function to set the UI Value for a particular option */
static gboolean
employee_set_value (GNCOption *option, gboolean use_default,
employee_set_value (GncOption *option, gboolean use_default,
GtkWidget *widget, SCM value)
{
GncOwner owner;
@ -320,7 +321,7 @@ employee_set_value (GNCOption *option, gboolean use_default,
/* Function to get the UI Value for a particular option */
static SCM
employee_get_value (GNCOption *option, GtkWidget *widget)
employee_get_value (GncOption *option, GtkWidget *widget)
{
GncOwner owner;
@ -335,7 +336,7 @@ employee_get_value (GNCOption *option, GtkWidget *widget)
static GtkWidget *
create_invoice_widget (GNCOption *option, GtkWidget *hbox)
create_invoice_widget (GncOption *option, GtkWidget *hbox)
{
GtkWidget *widget;
@ -352,7 +353,7 @@ create_invoice_widget (GNCOption *option, GtkWidget *hbox)
/* Function to set the UI widget based upon the option */
static GtkWidget *
invoice_set_widget (GNCOption *option, GtkGrid *page_box,
invoice_set_widget (GncOption *option, GtkGrid *page_box,
GtkLabel *name_label, char *documentation,
/* Return values */
GtkWidget **enclosing, gboolean *packed)
@ -372,7 +373,7 @@ invoice_set_widget (GNCOption *option, GtkGrid *page_box,
/* Function to set the UI Value for a particular option */
static gboolean
invoice_set_value (GNCOption *option, gboolean use_default,
invoice_set_value (GncOption *option, gboolean use_default,
GtkWidget *widget, SCM value)
{
GncInvoice *invoice;
@ -390,7 +391,7 @@ invoice_set_value (GNCOption *option, gboolean use_default,
/* Function to get the UI Value for a particular option */
static SCM
invoice_get_value (GNCOption *option, GtkWidget *widget)
invoice_get_value (GncOption *option, GtkWidget *widget)
{
GncInvoice *invoice;
@ -404,7 +405,7 @@ invoice_get_value (GNCOption *option, GtkWidget *widget)
static GtkWidget *
create_taxtable_widget (GNCOption *option, GtkWidget *hbox)
create_taxtable_widget (GncOption *option, GtkWidget *hbox)
{
GtkWidget *widget;
GtkBuilder *builder;
@ -428,7 +429,7 @@ create_taxtable_widget (GNCOption *option, GtkWidget *hbox)
/* Function to set the UI widget based upon the option */
static GtkWidget *
taxtable_set_widget (GNCOption *option, GtkGrid *page_box,
taxtable_set_widget (GncOption *option, GtkGrid *page_box,
GtkLabel *name_label, char *documentation,
/* Return values */
GtkWidget **enclosing, gboolean *packed)
@ -448,7 +449,7 @@ taxtable_set_widget (GNCOption *option, GtkGrid *page_box,
/* Function to set the UI Value for a particular option */
static gboolean
taxtable_set_value (GNCOption *option, gboolean use_default,
taxtable_set_value (GncOption *option, gboolean use_default,
GtkWidget *widget, SCM value)
{
GncTaxTable *taxtable;
@ -466,7 +467,7 @@ taxtable_set_value (GNCOption *option, gboolean use_default,
/* Function to get the UI Value for a particular option */
static SCM
taxtable_get_value (GNCOption *option, GtkWidget *widget)
taxtable_get_value (GncOption *option, GtkWidget *widget)
{
GncTaxTable *taxtable;
@ -474,28 +475,11 @@ taxtable_get_value (GNCOption *option, GtkWidget *widget)
return SWIG_NewPointerObj(taxtable, SWIG_TypeQuery("_p__gncTaxTable"), 0);
}
#endif
void
gnc_business_options_gnome_initialize (void)
{
int i;
static GNCOptionDef_t options[] =
{
{ "owner", owner_set_widget, owner_set_value, owner_get_value },
{
"customer", customer_set_widget, customer_set_value,
customer_get_value
},
{ "vendor", vendor_set_widget, vendor_set_value, vendor_get_value },
{ "employee", employee_set_widget, employee_set_value, employee_get_value },
{ "invoice", invoice_set_widget, invoice_set_value, invoice_get_value },
{ "taxtable", taxtable_set_widget, taxtable_set_value, taxtable_get_value },
{ NULL }
};
SWIG_GetModule(NULL); /* Work-around for SWIG bug. */
for (i = 0; options[i].option_name; i++)
gnc_options_ui_register_option (&(options[i]));
/* Create the above option types. */
}

View File

@ -33,12 +33,15 @@
#include "gnucash-core-app.hpp"
extern "C" {
#include <glib/gi18n.h>
#include <dialog-new-user.h>
#include <gfec.h>
#include <gnc-engine.h> // For define GNC_MOD_GUI
#include <gnc-file.h>
#include <gnc-filepath-utils.h>
#include <gnc-gnome-utils.h>
#include <gnc-gsettings.h>
#include <gnc-hooks.h>
#include <gnc-module.h>
#include <gnc-path.h>
#include <gnc-plugin-bi-import.h>

View File

@ -505,7 +505,6 @@ GncOption::from_scheme(std::istream& iss)
* the template implementation in the public header.
*/
using GncOptionAccountList = std::vector<const Account*>;
template class GncOptionValidatedValue<const QofInstance*>;
@ -544,17 +543,20 @@ template const char* GncOption::get_default_value<const char*>() const;
template std::string GncOption::get_default_value<std::string>() const;
template const QofInstance* GncOption::get_default_value<const QofInstance*>() const;
template RelativeDatePeriod GncOption::get_default_value<RelativeDatePeriod>() const;
template GncOptionAccountList GncOption::get_default_value<GncOptionAccountList>() const;
template GncMultichoiceOptionIndexVec GncOption::get_default_value<GncMultichoiceOptionIndexVec>() const;
template void GncOption::set_value(bool);
template void GncOption::set_value(int);
template void GncOption::set_value(int64_t);
template void GncOption::set_value(double);
template void GncOption::set_value(char*);
template void GncOption::set_value(const char*);
template void GncOption::set_value(std::string);
template void GncOption::set_value(const QofInstance*);
template void GncOption::set_value(RelativeDatePeriod);
template void GncOption::set_value(size_t);
template void GncOption::set_value(GncOptionAccountList);
template void GncOption::set_value(GncMultichoiceOptionIndexVec);
template void GncOption::get_limits(double&, double&, double&) const noexcept;

View File

@ -74,7 +74,12 @@ typedef struct KvpValueImpl KvpValue;
typedef void (*QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data);
#ifdef __cplusplus
class GncOptionDB;
using GNCOptionDB = GncOptionDB;
#else
typedef struct gnc_option_db GNCOptionDB;
#endif
typedef void (*GNCOptionSave) (GNCOptionDB*, QofBook*, gboolean);
typedef void (*GNCOptionLoad) (GNCOptionDB*, QofBook*);

View File

@ -136,6 +136,7 @@ gnucash/gnome-utils/dialog-dup-trans.c
gnucash/gnome-utils/dialog-file-access.c
gnucash/gnome-utils/dialog-object-references.c
gnucash/gnome-utils/dialog-options.c
gnucash/gnome-utils/dialog-options.cpp
gnucash/gnome-utils/dialog-preferences.c
gnucash/gnome-utils/dialog-query-view.c
gnucash/gnome-utils/dialog-reset-warnings.c
@ -528,6 +529,7 @@ libgnucash/app-utils/gnc-gsettings.c
libgnucash/app-utils/gnc-helpers.c
libgnucash/app-utils/gnc-help-utils.c
libgnucash/app-utils/gnc-option.cpp
libgnucash/app-utils/gnc-option-date.cpp
libgnucash/app-utils/gnc-optiondb.cpp
libgnucash/app-utils/gnc-option-impl.cpp
libgnucash/app-utils/gnc-prefs-utils.c