Robert Graham Merkel's widgetization of the main window account tree.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3234 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas
2000-12-04 23:23:35 +00:00
parent bb7404ccd3
commit e38062ba65
9 changed files with 423 additions and 48 deletions

View File

@@ -1,3 +1,14 @@
2000-12-05 Robert Graham Merkel <rgmerk@mira.net>
* src/gnome/account-tree.[ch] (gnc_account_tree_unselect_account): Add unselect account functionality as required by mainwindow account tree
2000-12-04 Robert Graham Merkel <rgmerk@mira.net>
* src/gnome/mainwindow-account-tree.[ch]: new file. Widgetizes the current
contents of the main window in preparation for pane-ization.
* src/gnome/window-main.c: modified to take account of the above.
2000-11-17 James LewisMoss <dres@debian.org>
* src/doc/design/reports.texinfo (Reports): Reorder option

View File

@@ -149,14 +149,14 @@ po/gnucash.pot
po/Makefile.in.in
stamp-h.in
rpm/gnucash.spec
src/doc/design/gnucash-design.info
src/doc/design/gnucash-design.info-1
src/doc/design/gnucash-design.info-2
src/doc/design/texinfo.tex
src/doc/design/gnucash-design.info*
src/doc/design/stamp-vti
src/doc/design/version.texi
src/gnome/glade-cb-gnc-dialogs.c
src/gnome/glade-support-gnc-dialogs.c
src/gnucash
src/gnome/gnucash.keys
src/guile/gnc.c
src/guile/gnc.h
src/guile/gnc.html

View File

@@ -28,6 +28,7 @@ libgncgnome_a_SOURCES = \
gnc-datedelta.c \
gnc-dateedit.c \
gtkselect.c \
mainwindow-account-tree.c \
print-session.c \
query-user.c \
reconcile-list.c \

View File

@@ -135,6 +135,7 @@ gnc_account_tree_new()
* *
* Returns: the account tree widget, or NULL if there was a problem.*
\********************************************************************/
GtkWidget *
gnc_account_tree_new_with_root(Account * root)
{
@@ -526,7 +527,33 @@ gnc_account_tree_select_account(GNCAccountTree *tree,
return TRUE;
}
/********************************************************************\
* gnc_account_tree_unselect_account *
* unselect an account in the tree *
* *
* Args: tree - tree to be modified *
* account - account to be selected *
* show - if true, scroll the tree *
* Returns: true if the account was found *
\********************************************************************/
gboolean
gnc_account_tree_unselect_account(GNCAccountTree *tree,
Account *account)
{
GtkCTree *ctree = GTK_CTREE(tree);
GtkCTreeNode *node;
/* Get the node with the account */
node = gtk_ctree_find_by_row_data(ctree, NULL, account);
if (node == NULL)
return FALSE;
/* unselect it */
gtk_ctree_unselect(ctree, node);
return TRUE;
}
/********************************************************************\
* gnc_account_tree_select_accounts *

View File

@@ -149,7 +149,9 @@ void gnc_account_tree_get_view_info (GNCAccountTree *tree,
void gnc_account_tree_set_filter (GNCAccountTree *tree,
AccountFilter filter,
gpointer user_data);
gboolean
gnc_account_tree_unselect_account(GNCAccountTree *tree,
Account *account);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@@ -0,0 +1,288 @@
/********************************************************************\
* mainwindow-account-list.c -- composite account selection widget *
* wrapped up for the main window *
* and callback functions for GnuCash *
* Copyright (C) 2000 Gnumatic, Inc. *
* Written by Robert Merkel <rgmerk@mira.net> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
\********************************************************************/
#include "config.h"
#include <gnome.h>
#include "mainwindow-account-tree.h"
static GList *mw_acc_trees = NULL;
enum {
SELECT_ACCOUNT_SIGNAL,
UNSELECT_ACCOUNT_SIGNAL,
ACTIVATE_ACCOUNT_SIGNAL,
LAST_SIGNAL
};
static gint mainwinaccounttree_signals[LAST_SIGNAL] = { 0 };
static void
unselect_account_callback(GNCAccountTree *tree, Account *account, gpointer user_data)
{
GNCMainWinAccountTree *mw_tree = (GNCMainWinAccountTree *) user_data;
gtk_signal_emit(GTK_OBJECT(mw_tree),
mainwinaccounttree_signals[UNSELECT_ACCOUNT_SIGNAL],
account);
return;
}
static void
activate_account_callback(GNCAccountTree *tree, Account *account, gpointer user_data)
{
GNCMainWinAccountTree *mw_tree = (GNCMainWinAccountTree *) user_data;
gtk_signal_emit(GTK_OBJECT(mw_tree),
mainwinaccounttree_signals[ACTIVATE_ACCOUNT_SIGNAL],
account);
return;
}
static void
select_account_callback(GNCAccountTree *tree, Account *account, gpointer user_data)
{
GNCMainWinAccountTree *clicked_window = (GNCMainWinAccountTree *) user_data;
GList *list_iterator;
GNCMainWinAccountTree *current_window;
for(list_iterator = mw_acc_trees; list_iterator; list_iterator=g_list_next(list_iterator))
{
current_window = list_iterator->data;
if(current_window != clicked_window)
{
gnc_account_tree_unselect_account(current_window->acc_tree,
gnc_account_tree_get_current_account(current_window->acc_tree));
}
}
gtk_signal_emit(GTK_OBJECT(clicked_window),
mainwinaccounttree_signals[SELECT_ACCOUNT_SIGNAL],
account);
return;
}
static void
gnc_mainwin_account_tree_class_init (GNCMainWinAccountTreeClass *klass)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass*) klass;
mainwinaccounttree_signals[SELECT_ACCOUNT_SIGNAL] =
gtk_signal_new("select_account",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET(GNCMainWinAccountTreeClass,
select_account),
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
mainwinaccounttree_signals[UNSELECT_ACCOUNT_SIGNAL] =
gtk_signal_new("unselect_account",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET(GNCMainWinAccountTreeClass,
unselect_account),
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
mainwinaccounttree_signals[ACTIVATE_ACCOUNT_SIGNAL] =
gtk_signal_new("activate_account",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET(GNCMainWinAccountTreeClass,
activate_account),
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
gtk_object_class_add_signals(object_class,
mainwinaccounttree_signals,
LAST_SIGNAL);
klass->select_account = NULL;
klass->unselect_account = NULL;
klass->activate_account = NULL;
}
static void
gnc_mainwin_account_tree_init(GNCMainWinAccountTree *mwac_tree)
{
mwac_tree->acc_tree = GNC_ACCOUNT_TREE(gnc_account_tree_new());
mwac_tree->scrolled_window = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
gtk_signal_connect(GTK_OBJECT(mwac_tree->acc_tree), "activate_account",
GTK_SIGNAL_FUNC (activate_account_callback), mwac_tree);
gtk_signal_connect(GTK_OBJECT(mwac_tree->acc_tree), "select_account",
GTK_SIGNAL_FUNC(select_account_callback), mwac_tree);
gtk_signal_connect(GTK_OBJECT(mwac_tree->acc_tree), "unselect_account",
GTK_SIGNAL_FUNC(unselect_account_callback), mwac_tree);
gtk_container_add(GTK_CONTAINER(mwac_tree->scrolled_window), GTK_WIDGET(mwac_tree->acc_tree));
gtk_box_pack_start(GTK_BOX(mwac_tree), GTK_WIDGET(mwac_tree->scrolled_window), TRUE, TRUE, 0);
gtk_widget_show(GTK_WIDGET(mwac_tree->acc_tree));
gtk_widget_show(GTK_WIDGET(mwac_tree->scrolled_window));
}
guint
gnc_mainwin_account_tree_get_type ()
{
static guint mwactree = 0;
if (!mwactree)
{
static const GtkTypeInfo mwactree_info =
{
"GNCMainWinAccountTree",
sizeof (GNCMainWinAccountTree),
sizeof (GNCMainWinAccountTreeClass),
(GtkClassInitFunc) gnc_mainwin_account_tree_class_init,
(GtkObjectInitFunc) gnc_mainwin_account_tree_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
(GtkClassInitFunc) NULL
};
mwactree = gtk_type_unique (gtk_hbox_get_type (), &mwactree_info);
}
return mwactree;
}
/*
* Note that the interface was chosen purely because it's the calls needed to
* get this working with the existing window-main.c
* This is all subject to change
*/
/*******************************************************************************\
* gnc_mainwin_account_tree_attach_popup *
* attaches a popup window *
* *
* Args: mwac_trec - the mainwindow account tree to attach to *
* popup_info - the popup to attach *
* Returns: Nothing *
\*******************************************************************************/
void
gnc_mainwin_account_tree_attach_popup(GNCMainWinAccountTree *mwac_tree, GnomeUIInfo *popup_info)
{
GtkWidget *popup = gnome_popup_menu_new(popup_info);
gnome_popup_menu_attach(popup, GTK_WIDGET(mwac_tree->acc_tree), NULL);
return;
}
/*******************************************************************************\
* gnc_mainwin_account_tree_set_view_info *
* set which accounts get viewed *
* *
* Args: mwac_tree - the mainwindow account tree to attach to *
* new_info - the new view info (see account-tree.c for more details) *
* Returns: Nothing *
\*******************************************************************************/
void
gnc_mainwin_account_tree_set_view_info(GNCMainWinAccountTree *mwac_tree, AccountViewInfo new_info)
{
AccountViewInfo old_info;
gnc_account_tree_get_view_info(mwac_tree->acc_tree, &old_info);
if(memcmp(&new_info, &old_info, sizeof(AccountViewInfo)) != 0)
{
gnc_account_tree_set_view_info(mwac_tree->acc_tree, &new_info);
}
return;
}
/*******************************************************************************\
* gnc_mainwin_account_tree_new *
* create a new mainwindow_account_tree *
* *
* Args: nothing *
* Returns : a new fresh-baked mainwindow_account_tree *
\*******************************************************************************/
GtkWidget *
gnc_mainwin_account_tree_new()
{
GtkWidget *tree;
guint type_of;
type_of = gnc_mainwin_account_tree_get_type();
tree = gtk_widget_new(type_of, NULL);
return tree;
}
/*******************************************************************************\
* gnc_mainwin_account_tree_get_current_acount *
* get the current account selected in a mainwindow_account_tree *
* *
* Args: the account tree *
* Returns : a pointer to the selected account *
\*******************************************************************************/
Account *
gnc_mainwin_account_tree_get_current_account(GNCMainWinAccountTree *list)
{
return gnc_account_tree_get_current_account(list->acc_tree);
}
/*******************************************************************************\
* gnc_mainwin_account_tree_get_current_accounts *
* get the current account(s) selected in a mainwindow_account_tree *
* *
* Args: the account tree *
* Returns : a Glist of selected accounts *
\*******************************************************************************/
GList *
gnc_mainwin_account_tree_get_current_accounts(GNCMainWinAccountTree *list)
{
return gnc_account_tree_get_current_accounts(list->acc_tree);
}
/*******************************************************************************\
* gnc_mainwin_account_tree_toggle_account_expansion *
* toggle expans the nominated account to show children (or not) *
* *
* Args: the account tree *
* the account whose children to show/not show *
* Returns : nothing *
\*******************************************************************************/
void
gnc_mainwin_account_tree_toggle_account_expansion(
GNCMainWinAccountTree *mwac_tree, Account *account)
{
GNCAccountTree *tree = mwac_tree->acc_tree;
gnc_account_tree_toggle_account_expansion(tree, account);
return;
}

View File

@@ -0,0 +1,52 @@
#ifndef __GNC_MAINWIN_ACCOUNT_TREE_H
#define __GNC_MAINWIN_ACCOUNT_TREE_H
#include <gnome.h>
#include "account-tree.h"
#include "Account.h"
#define GNC_MAINWIN_ACCOUNT_TREE(obj) GTK_CHECK_CAST (obj, gnc_mainwin_account_tree_get_type (), GNCMainWinAccountTree)
#define GNC_MAINWIN_ACCOUNT_TREE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnc_mainwin_account_tree_get_type(), GNCMainWinAccountTreeClass)
#define IS_GNC_MAINWIN_ACCOUNT_TREE(obj) GTK_CHECK_TYPE (obj, gnc_mainwin_account_tree_get_type ())
typedef struct _GNCMainWinAccountTree GNCMainWinAccountTree;
typedef struct _GNCMainWinAccountTreeClass GNCMainWinAccountTreeClass;
struct _GNCMainWinAccountTree
{
GtkVBox vbox;
GtkScrolledWindow *scrolled_window;
GNCAccountTree *acc_tree;
};
struct _GNCMainWinAccountTreeClass
{
GtkVBoxClass parent_class;
void (*select_account) (GNCMainWinAccountTree *tree,
Account *account);
void (*unselect_account) (GNCMainWinAccountTree *tree,
Account *account);
void (*activate_account) (GNCMainWinAccountTree *tree,
Account *account);
};
guint gnc_mainwin_account_tree_get_type(void);
GtkWidget* gnc_mainwin_account_tree_new(void);
void
gnc_mainwin_account_tree_attach_popup(GNCMainWinAccountTree *tree, GnomeUIInfo *popup_info);
void
gnc_mainwin_account_tree_set_view_info(GNCMainWinAccountTree *tree, AccountViewInfo new_info);
Account *
gnc_mainwin_account_tree_get_current_account(GNCMainWinAccountTree *tree);
GList *
gnc_mainwin_account_tree_get_current_accounts(GNCMainWinAccountTree *tree);
void gnc_mainwin_account_tree_toggle_account_expansion(GNCMainWinAccountTree *tree, Account *account);
#endif /* __GNC_MAINWINDOW_ACCOUNT_TREE_H */

View File

@@ -53,6 +53,7 @@
#include "gnucash.h"
#include "gtkselect.h"
#include "messages.h"
#include "mainwindow-account-tree.h"
#include "window-help.h"
#include "window-main.h"
#include "window-reconcile.h"
@@ -820,7 +821,7 @@ gnc_ui_mainWindow_destroy_cb(GtkObject *object, gpointer user_data)
g_free(main_info);
}
GNCAccountTree *
GNCMainWinAccountTree *
gnc_get_current_account_tree(void)
{
GNCMainInfo *main_info;
@@ -829,25 +830,25 @@ gnc_get_current_account_tree(void)
if (main_info == NULL)
return NULL;
return GNC_ACCOUNT_TREE(main_info->account_tree);
return GNC_MAINWIN_ACCOUNT_TREE(main_info->account_tree);
}
Account *
gnc_get_current_account(void)
{
GNCAccountTree * tree = gnc_get_current_account_tree();
return gnc_account_tree_get_current_account(tree);
GNCMainWinAccountTree *list = gnc_get_current_account_tree();
return gnc_mainwin_account_tree_get_current_account(list);
}
GList *
gnc_get_current_accounts(void)
{
GNCAccountTree * tree = gnc_get_current_account_tree();
return gnc_account_tree_get_current_accounts(tree);
}
GNCMainWinAccountTree *tree = gnc_get_current_account_tree();
return gnc_mainwin_account_tree_get_current_accounts(tree);
}
static void
gnc_account_tree_activate_cb(GNCAccountTree *tree,
gnc_account_tree_activate_cb(GNCMainWinAccountTree *tree,
Account *account,
gpointer user_data)
{
@@ -865,7 +866,7 @@ gnc_account_tree_activate_cb(GNCAccountTree *tree,
group = xaccAccountGetChildren(account);
if (xaccGroupGetNumAccounts(group) > 0)
{
gnc_account_tree_toggle_account_expansion(tree, account);
gnc_mainwin_account_tree_toggle_account_expansion(tree, account);
return;
}
}
@@ -878,18 +879,17 @@ static void
gnc_configure_account_tree(void *data)
{
GtkObject *app;
GNCAccountTree *tree;
GNCMainInfo *info;
GNCMainWinAccountTree *tree;
AccountViewInfo new_avi;
AccountViewInfo old_avi;
GSList *list, *node;
memset(&new_avi, 0, sizeof(new_avi));
app = GTK_OBJECT(gnc_get_ui_data());
tree = gnc_get_current_account_tree();
if (tree == NULL)
return;
info = gnc_get_main_info();
tree = GNC_MAINWIN_ACCOUNT_TREE(info->account_tree);
list = gnc_lookup_list_option("Main Window",
"Account types to display",
@@ -978,10 +978,9 @@ gnc_configure_account_tree(void *data)
new_avi.show_field[ACCOUNT_NAME] = TRUE;
gnc_account_tree_get_view_info(tree, &old_avi);
gnc_mainwin_account_tree_set_view_info(tree, new_avi);
if (memcmp(&old_avi, &new_avi, sizeof(AccountViewInfo)) != 0)
gnc_account_tree_set_view_info(tree, &new_avi);
return;
}
static void
@@ -1301,8 +1300,7 @@ gnc_main_create_menus(GnomeApp *app, GtkWidget *account_tree,
list = g_slist_prepend(list, accountsmenu[6].widget);
list = g_slist_prepend(list, accountsmenu[9].widget);
popup = gnome_popup_menu_new(accountsmenu);
gnome_popup_menu_attach(popup, account_tree, NULL);
gnc_mainwin_account_tree_attach_popup(account_tree, accountsmenu);
list = g_slist_prepend(list, scrubmenu[0].widget);
list = g_slist_prepend(list, scrubmenu[1].widget);
@@ -1364,11 +1362,11 @@ gnc_account_set_sensititives(GNCMainInfo *main_info, gboolean sensitive)
}
static void
gnc_account_cb(GNCAccountTree *tree, Account *account, gpointer data)
gnc_account_cb(GNCMainWinAccountTree *tree, Account *account, gpointer data)
{
gboolean sensitive;
account = gnc_account_tree_get_current_account(tree);
account = gnc_mainwin_account_tree_get_current_account(tree);
sensitive = account != NULL;
gnc_account_set_sensititives(gnc_get_main_info(), sensitive);
@@ -1379,7 +1377,7 @@ mainWindow()
{
GNCMainInfo *main_info;
GtkWidget *app = gnc_get_ui_data();
GtkWidget *scrolled_win;
GtkWidget *account_tree;
GtkWidget *statusbar;
int width = 0;
int height = 0;
@@ -1392,8 +1390,6 @@ mainWindow()
main_info = g_new0(GNCMainInfo, 1);
gtk_object_set_data(GTK_OBJECT(app), "gnc_main_info", main_info);
main_info->account_tree = gnc_account_tree_new();
main_info->main_window_change_callback_id =
gnc_register_option_change_callback(gnc_configure_account_tree, NULL,
"Main Window", NULL);
@@ -1403,14 +1399,6 @@ mainWindow()
"International",
"Enable EURO support");
gtk_signal_connect(GTK_OBJECT(main_info->account_tree), "activate_account",
GTK_SIGNAL_FUNC (gnc_account_tree_activate_cb), NULL);
gtk_signal_connect(GTK_OBJECT(main_info->account_tree), "select_account",
GTK_SIGNAL_FUNC(gnc_account_cb), NULL);
gtk_signal_connect(GTK_OBJECT(main_info->account_tree), "unselect_account",
GTK_SIGNAL_FUNC(gnc_account_cb), NULL);
/* create statusbar and add it to the application. */
statusbar = gnome_appbar_new(FALSE, /* no progress bar, maybe later? */
@@ -1419,7 +1407,7 @@ mainWindow()
gnome_app_set_statusbar(GNOME_APP(app), GTK_WIDGET(statusbar));
gnc_main_create_menus(GNOME_APP(app), main_info->account_tree, main_info);
gnc_main_create_toolbar(GNOME_APP(app), main_info);
gnc_configure_toolbar(NULL);
@@ -1449,15 +1437,23 @@ mainWindow()
}
/* create scrolled window */
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gnome_app_set_contents(GNOME_APP(app), scrolled_win);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
account_tree = gnc_mainwin_account_tree_new();
main_info->account_tree = account_tree;
gnome_app_set_contents(GNOME_APP(app), account_tree);
gnc_main_create_menus(GNOME_APP(app), main_info->account_tree, main_info);
gtk_signal_connect(GTK_OBJECT(main_info->account_tree), "activate_account",
GTK_SIGNAL_FUNC (gnc_account_tree_activate_cb), NULL);
gtk_signal_connect(GTK_OBJECT(main_info->account_tree), "select_account",
GTK_SIGNAL_FUNC(gnc_account_cb), NULL);
gtk_signal_connect(GTK_OBJECT(main_info->account_tree), "unselect_account",
GTK_SIGNAL_FUNC(gnc_account_cb), NULL);
gtk_container_add(GTK_CONTAINER(scrolled_win),
GTK_WIDGET(main_info->account_tree));
/* Attach delete and destroy signals to the main window */
gtk_signal_connect (GTK_OBJECT (app), "delete_event",
@@ -1475,7 +1471,6 @@ mainWindow()
/* Show everything now that it is created */
gtk_widget_show_all(statusbar);
gtk_widget_show(main_info->account_tree);
gtk_widget_show(scrolled_win);
gnc_configure_account_tree(NULL);

View File

@@ -23,14 +23,13 @@
#ifndef __WINDOW_MAIN_H__
#define __WINDOW_MAIN_H__
#include "account-tree.h"
#include "mainwindow-account-tree.h"
/** PROTOTYPES ******************************************************/
void mainWindow(void);
GNCAccountTree * gnc_get_current_account_tree(void);
GNCMainWinAccountTree * gnc_get_current_account_tree(void);
void gnc_ui_mainWindow_save_size(void);