big patches from jeremy collins

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@911 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-07-25 21:59:02 +00:00
parent 0d1cc9106a
commit b27610bf97
7 changed files with 863 additions and 217 deletions

415
src/gnome/Add_Dialog.c Normal file
View File

@ -0,0 +1,415 @@
/********************************************************************\
* Add_Dialog.c -- functions for creating add_account_dialog *
* and callback functions for GnuCash *
* Copyright (C) 1998 Jeremy Collins *
* *
* 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, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
\********************************************************************/
#include <gnome.h>
#include "Add_Dialog.h"
#include "MenuBar.h"
#include "messages.h"
#include "AccInfo.h"
#include <string.h>
/** Globals *********************************************************/
add_account_dialog
*add_account_dialog_init ( )
{
return ( g_malloc ( sizeof ( add_account_dialog ) ) );
}
/** Callback Functions **********************************************/
static void
add_account_toggle_callback (GtkWidget *widget, gpointer data)
{
int *val;
if (GTK_TOGGLE_BUTTON (widget)->active)
{
val = data;
*val = (long) gtk_object_get_user_data (GTK_OBJECT (widget));
}
}
static void
add_account_omenu_update ( GtkWidget *widget, gpointer data )
{
add_account_dialog *info = data;
Account *account = gtk_object_get_user_data(GTK_OBJECT(widget));
if (account) {
info->parent_account = account;
}
}
static void
add_account_dialog_okclicked_cb(GtkWidget * dialog, gpointer data)
{
Transaction *trans;
Account *account;
add_account_dialog *info = data;
/* Check to make sure something was entered */
if( strcmp( gtk_entry_get_text(GTK_ENTRY(info->textbox_name)), "" ) == 0 )
{
GtkWidget *msgbox;
msgbox = gnome_message_box_new ( "You must enter a filename",
GNOME_MESSAGE_BOX_ERROR, "Ok", NULL );
gtk_widget_show ( msgbox );
return;
}
account = xaccMallocAccount();
xaccAccountBeginEdit (account);
xaccAccountSetName (account, gtk_entry_get_text(GTK_ENTRY(info->textbox_name)));
xaccAccountSetDescription (account, gtk_entry_get_text(GTK_ENTRY(info->textbox_description)));
xaccAccountSetType ( account, info->type );
/* Add an opening balance transaction (as the first transaction) */
trans = xaccMallocTransaction();
xaccTransBeginEdit(trans);
xaccTransSetDateToday (trans);
xaccTransSetDescription (trans, OPEN_BALN_STR);
xaccTransCommitEdit(trans);
/* add the new transaction to the account */
xaccAccountInsertSplit (account, xaccTransGetSplit (trans, 0) );
/* once the account is set up, add it to account group
* If the user indicated a parent acccount, make it a
* sub account of that */
/* The g_print statements should be removed after we are sure
* everything is a ok with this callback
*/
if (info->parent_account) {
g_print( "Return Code (SUB): %d\n", xaccInsertSubAccount (info->parent_account, account));
} else {
g_print( "Return Code (TOPGROUP): %d\n", insertAccount( topgroup, account ));
}
xaccAccountCommitEdit (account);
refresh_tree();
gnome_dialog_close ( GNOME_DIALOG(info->dialog) );
}
static void
add_account_canceled_cb ( GtkWidget *ignore, gpointer data )
{
add_account_dialog *info = data;
gnome_dialog_close( GNOME_DIALOG(info->dialog));
}
void
add_account_dialog_destroy ( GtkWidget *ignore, GnomeDialog *dialog )
{
//gtk_widget_destroy ( GTK_WIDGET(dialog) );
}
static void
build_omenu ( GtkMenu *menu, add_account_dialog *accWindow, Account *acct,
int is_submenu )
{
/* Create an popup menu to select which account to add this new account too */
/* needs to create submenus for each Parent account that has subaccounts */
GtkWidget *omenu;
GtkWidget *submenu;
GtkWidget *menuitem;
int i;
int count = xaccGroupGetNumAccounts(acct);
GSList *omenu_group;
if ( is_submenu == -1 )
{
omenu = gtk_option_menu_new ();
menu = gtk_menu_new ();
submenu = NULL;
omenu_group = NULL;
}
menuitem = gtk_radio_menu_item_new_with_label (omenu_group, "New TopLevel Account" );
gtk_object_set_user_data(GTK_OBJECT(menuitem), NULL);
omenu_group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (add_account_omenu_update), accWindow);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
for ( i=0; i<count; i++ )
{
Account *account = xaccGroupGetAccount (acct, i );
gchar *account_name = xaccAccountGetName ( account );
menuitem = gtk_radio_menu_item_new_with_label (omenu_group, account_name);
gtk_object_set_user_data(GTK_OBJECT(menuitem), account);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (add_account_omenu_update), accWindow);
omenu_group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
gtk_box_pack_end ( GTK_BOX(accWindow->box2), omenu, FALSE, FALSE, 10 );
gtk_widget_show ( omenu );
}
void
create_add_account_dialog (AccountGroup *acct)
{
GtkWidget *button;
add_account_dialog *accWindow;
/* This should be in messages.h */
gchar *title = "Setup Account";
accWindow = add_account_dialog_init();
accWindow->parent_account = acct;
accWindow->dialog =
GNOME_DIALOG( gnome_dialog_new ( title,
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL,
NULL));
gtk_window_set_title ( GTK_WINDOW ( accWindow->dialog ), title );
gtk_window_position ( GTK_WINDOW ( accWindow->dialog ),
GTK_WIN_POS_CENTER );
accWindow->main_vbox = gtk_vbox_new ( FALSE, 2 );
gtk_container_add ( GTK_CONTAINER ( (accWindow->dialog)->vbox ), accWindow->main_vbox );
accWindow->frame = gtk_frame_new ( "Account Type" );
gtk_container_border_width (GTK_CONTAINER (accWindow->frame), 10);
gtk_box_pack_start ( GTK_BOX( accWindow->main_vbox ), accWindow->frame, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->frame );
accWindow->box2 = gtk_hbox_new ( FALSE, 2 );
gtk_container_add ( GTK_CONTAINER( accWindow->frame ), accWindow->box2 );
gtk_widget_show ( accWindow->box2 );
accWindow->box3 = gtk_vbox_new ( FALSE, 2 );
gtk_box_pack_start ( GTK_BOX( accWindow->box2 ), accWindow->box3, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->box3 );
accWindow->box4 = gtk_vbox_new ( FALSE, 2 );
gtk_box_pack_start ( GTK_BOX( accWindow->box2 ), accWindow->box4, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->box4 );
/* Create radio button group for Account Type **********************/
button = gtk_radio_button_new_with_label (NULL, "Bank");
gtk_box_pack_start (GTK_BOX (accWindow->box3), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) BANK);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == BANK)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
accWindow->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
button = gtk_radio_button_new_with_label(accWindow->group, "Cash");
gtk_box_pack_start (GTK_BOX (accWindow->box3), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) CASH);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == CASH)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
accWindow->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
button = gtk_radio_button_new_with_label(accWindow->group, "Asset");
gtk_box_pack_start (GTK_BOX (accWindow->box3), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) ASSET);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == ASSET)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
accWindow->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
button = gtk_radio_button_new_with_label(accWindow->group, "Credit Card");
gtk_box_pack_start (GTK_BOX (accWindow->box3), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) CREDIT);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == CREDIT)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
accWindow->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
button = gtk_radio_button_new_with_label(accWindow->group, "Liability");
gtk_box_pack_start (GTK_BOX (accWindow->box3), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) LIABILITY);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == LIABILITY)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
accWindow->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
button = gtk_radio_button_new_with_label(accWindow->group, "Stock");
gtk_box_pack_start (GTK_BOX (accWindow->box4), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) STOCK);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == STOCK)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
accWindow->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
button = gtk_radio_button_new_with_label(accWindow->group, "Mutual Fund");
gtk_box_pack_start (GTK_BOX (accWindow->box4), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) MUTUAL);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == MUTUAL)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
accWindow->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
button = gtk_radio_button_new_with_label(accWindow->group, "Income");
gtk_box_pack_start (GTK_BOX (accWindow->box4), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) INCOME);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == INCOME)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
accWindow->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
button = gtk_radio_button_new_with_label(accWindow->group, "Expense");
gtk_box_pack_start (GTK_BOX (accWindow->box4), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) EXPENSE);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == EXPENSE)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
accWindow->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
button = gtk_radio_button_new_with_label(accWindow->group, "Equity");
gtk_box_pack_start (GTK_BOX (accWindow->box4), button, TRUE, TRUE, 0 );
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) EQUITY);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) add_account_toggle_callback,
&accWindow->type);
if (accWindow->type == EQUITY)
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button);
/************************ END OF RADIOBUTTONS ***********************/
accWindow->box2 = gtk_hbox_new ( FALSE, 2 );
gtk_box_pack_start ( GTK_BOX( accWindow->main_vbox ), accWindow->box2, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->box2 );
accWindow->textbox_name = gtk_entry_new_with_max_length ( 25 );
gtk_box_pack_end ( GTK_BOX(accWindow->box2), accWindow->textbox_name, FALSE, FALSE, 10 );
gtk_widget_show ( accWindow->textbox_name );
{
accWindow->label = gtk_label_new ( "Account Name: " );
gtk_box_pack_end ( GTK_BOX(accWindow->box2), accWindow->label, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->label );
}
accWindow->box2 = gtk_hbox_new ( FALSE, 2 );
gtk_box_pack_start ( GTK_BOX( accWindow->main_vbox ), accWindow->box2, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->box2 );
accWindow->textbox_description = gtk_entry_new_with_max_length ( 25 );
gtk_box_pack_end ( GTK_BOX(accWindow->box2), accWindow->textbox_description, FALSE, FALSE, 10 );
gtk_widget_show ( accWindow->textbox_description );
{
accWindow->label = gtk_label_new ( "Account Description: " );
gtk_box_pack_end ( GTK_BOX(accWindow->box2), accWindow->label, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->label );
}
accWindow->box2 = gtk_hbox_new ( FALSE, 2 );
gtk_box_pack_start ( GTK_BOX( accWindow->main_vbox ), accWindow->box2, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->box2 );
/* Call build menu here */
/* {
GtkWidget *menu;
build_omenu ( menu, accWindow, acct, -1 );
}
{
accWindow->label = gtk_label_new ( "Parent Account: " );
gtk_box_pack_end ( GTK_BOX(accWindow->box2), accWindow->label, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->label );
}
*/
/*** Callbacks ****************************************************/
gnome_dialog_button_connect (GNOME_DIALOG (accWindow->dialog), 0,
GTK_SIGNAL_FUNC (add_account_dialog_okclicked_cb),
accWindow);
gnome_dialog_button_connect (GNOME_DIALOG (accWindow->dialog), 1,
GTK_SIGNAL_FUNC (add_account_canceled_cb),
accWindow->dialog);
/*** End of Callbacks *********************************************/
accWindow->box2 = gtk_hbox_new ( FALSE, 2 );
gtk_box_pack_start ( GTK_BOX ( accWindow->main_vbox ), accWindow->box2, FALSE, FALSE, 0 );
gtk_widget_show ( accWindow->box2 );
gtk_widget_show ( accWindow->main_vbox );
gtk_widget_show ( GTK_WIDGET(accWindow->dialog) );
/*gnome_dialog_set_close ( accWindow->dialog, TRUE );*/
}

72
src/gnome/Add_Dialog.h Normal file
View File

@ -0,0 +1,72 @@
/********************************************************************\
* MainWindow.h -- the main window, and associated helper functions *
* and callback functions for xacc (X-Accountant *
* Copyright (C) 1997 Robin D. Clark *
* *
* 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, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
* Author: Rob Clark *
* Internet: rclark@cs.hmc.edu *
* Address: 609 8th Street *
* Huntington Beach, CA 92648-4632 *
\********************************************************************/
#ifndef __ADD_DIALOG_H__
#define __ADD_DIALOG_H__
#include "Group.h"
#include "Account.h"
#include "main.h"
#include "MainWindow.h"
struct _add_account_dialog
{
GnomeDialog *dialog;
GtkWidget *main_vbox;
GtkWidget *box2;
GtkWidget *box3;
GtkWidget *box4;
GtkWidget *frame;
GSList *group;
GtkWidget *label;
GtkWidget *textbox_name;
GtkWidget *textbox_description;
GtkWidget *separator;
Account *parent_account;
gint *type;
};
typedef struct _add_account_dialog add_account_dialog;
void create_add_account_dialog ( AccountGroup * );
add_account_dialog *add_account_dialog_init ( void );
void add_account_dialog_destroy ( GtkWidget *, GnomeDialog * );
#endif
/*
Local Variables:
tab-width: 2
indent-tabs-mode: nil
mode: c-mode
c-indentation-style: gnu
eval: (c-set-offset 'block-open '-)
End:
*/

View File

@ -22,13 +22,16 @@
#include "MainWindow.h"
#include "MenuBar.h"
#include "Dialogs.h"
#include "Add_Dialog.h"
#include "messages.h"
#include "version.h"
#include "RegWindow.h"
#include "main.h"
/** GLOBALS **********************************************************/
main_window *mwindow;
gchar *clist_titles[] =
{
ACC_NAME_STR,
@ -36,10 +39,6 @@ gchar *clist_titles[] =
BALN_STR
};
struct main_window {
};
static void
acct_tree_open_selected(GtkWidget *child) {
Account *acct = gtk_object_get_user_data(GTK_OBJECT(child));
@ -47,62 +46,315 @@ acct_tree_open_selected(GtkWidget *child) {
regWindowSimple(acct);
}
static void
acct_tree_select(GtkTree *tree, GtkWidget *child) {
//if(bevent && bevent->type == GDK_2BUTTON_PRESS) {
acct_tree_open_selected(child);
//}
static gint
acct_tree_select(GtkWidget *widget, GdkEventButton *event, GtkWidget *child)
{
/* Catch a double or single click */
if (GTK_IS_TREE_ITEM(widget) &&
(event->type==GDK_2BUTTON_PRESS ||
event->type==GDK_3BUTTON_PRESS) )
{
acct_tree_open_selected(child);
}
return FALSE;
}
static void
cram_accts_into_tree(GtkTree *maintree, AccountGroup *accts) {
int count = xaccGetNumAccounts(accts);
int i;
/********************************************************************\
* refresh_tree *
* refreshes the main window *
* *
* Args: tree - the tree that will get destroyed.. *
* Returns: nothing *
\********************************************************************/
void
refresh_tree()
{
/** This is ugly... how do we do this nicer? */
GList *items;
for(i=0; i<count; i++)
{
Account *acc = xaccGroupGetAccount(accts, i);
mwindow->maintree = GTK_TREE_ROOT_TREE ( mwindow->maintree );
items = GTK_TREE_SELECTION ( mwindow->maintree );
gtk_tree_clear_items ( mwindow->maintree, 0, g_list_length(items) );
mwindow->root_item = mwindow->maintree;
gchar *rowstrs[3];
acct_tree_fill(GTK_TREE_ITEM(mwindow->root_item), topgroup, -1);
GtkWidget *tree_item;
}
/********************************************************************\
* acct_tree_fill *
* fills the tree with accounts, name ($balance) *
* *
* Args: item - top level of tree *
* accts - the account group to use in filling tree *
* subtree - whether this is the toplevel, or a subtree *
* Returns: nothing *
\********************************************************************/
void
acct_tree_fill(GtkWidget *item, AccountGroup *accts, int subtree)
{
int accounts_in_group = xaccGroupGetNumAccounts(accts);
int current_account;
GtkWidget* item_subtree;
GtkWidget* tree_item;
int no_root_item;
if ( subtree == -1 )
{
item_subtree = item;
no_root_item = 1;
}
else
{
item_subtree = gtk_tree_new();
no_root_item = 0;
}
for( current_account=0;
current_account < accounts_in_group;
current_account++ )
{
Account *acc = xaccGroupGetAccount(accts, current_account);
AccountGroup *acc_children;
char buffer[255];
gchar *rowstrs[3];
rowstrs[0] = xaccAccountGetName (acc);
rowstrs[1] = xaccAccountGetDescription (acc);
rowstrs[2] = xaccAccountGetNotes (acc);
tree_item = gtk_tree_item_new_with_label( rowstrs[0] );
sprintf (buffer, "%s ($%.2f)", rowstrs[0], xaccAccountGetBalance(acc));
tree_item = gtk_tree_item_new_with_label( buffer );
/* Set the tree item to point to the actual account so we can reach it
trivially when the user selects the row. (Should we use
gtk_*_data_full and have a destroy notify?) */
gtk_object_set_user_data(GTK_OBJECT(tree_item), acc);
gtk_tree_append(GTK_TREE(maintree), tree_item );
gtk_tree_append(GTK_TREE(item_subtree), tree_item );
gtk_signal_connect (GTK_OBJECT (tree_item),
"button_press_event",
(GtkSignalFunc) acct_tree_select,
GTK_WIDGET(tree_item));
acc_children = xaccAccountGetChildren(acc);
if ( acc_children )
{
acct_tree_fill ( GTK_TREE(tree_item), acc_children, 1 );
}
gtk_widget_show ( tree_item );
}
gtk_signal_connect (GTK_OBJECT (maintree),
"select_child",
(GtkSignalFunc) acct_tree_select,
NULL);
if(!no_root_item)
{
gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), item_subtree);
}
}
/* Standard Gnome About Dialog, need I say more? */
static void
about_cb (GtkWidget *widget, gpointer data)
{
GtkWidget *about;
gchar *authors[] = {
/* Here should be your names */
"Rob Clark",
"Linas Vepsta",
"Jeremy Collins",
"Rob Browning",
"For more see http://www.gnucash.org/developers.html",
NULL
};
about = gnome_about_new ( "GnuCash", VERSION,
"(C) 1998 The GnuCash Project",
authors,
"GnuCash: The GNU way to manage your money!",
NULL);
gtk_widget_show (about);
}
/* Help system callback */
static void
help_cb ( GtkWidget *widget, gpointer data )
{
/* We need some config menus to setup were the docs are located */
/* for now I just set it to be $HOME/xacc-docs/ */
gchar *docs_path = HELP_ROOT;
docs_path = gnome_util_prepend_user_home( docs_path );
gnome_help_goto( NULL, docs_path );
g_free( docs_path );
}
/* Some dialog stubs to be worked on */
/* We might want to move these to there own file =\ */
static void
file_new_cb ( GtkWidget *widget, gpointer data )
{
}
/* Options dialog... this should house all of the config options */
/* like where the docs reside, and whatever else is deemed necessary */
static void
options_cb ( GtkWidget *widget, gpointer data )
{
GnomePropertyBox *box;
GtkWidget *w, *label, *box2;
box = GNOME_PROPERTY_BOX(gnome_property_box_new());
w = gtk_button_new_with_label("Click me (Page #1)");
box2 = gtk_vbox_new ( FALSE, 1 );
gtk_box_pack_start(GTK_BOX(box2), w, FALSE, FALSE, 0);
gtk_widget_show ( box2 );
gtk_widget_show(w);
label = gtk_label_new("Config Box 1");
gtk_widget_show(label);
gnome_property_box_append_page(box, box2, label);
w = gtk_button_new_with_label("Click me (Page #2)");
gtk_widget_show(w);
label = gtk_label_new("Config Box 2");
gtk_widget_show(label);
gnome_property_box_append_page(box, w, label);
gtk_widget_set_usize ( GTK_WIDGET(box), 500, 400 );
gtk_widget_set_usize ( GTK_WIDGET(box2), 225, 225 );
gtk_widget_show(GTK_WIDGET(box));
}
static void
add_account ( GtkWidget *widget, gpointer data )
{
GtkWidget *tree = data;
GList *selection;
selection = GTK_TREE_SELECTION ( tree );
if ( selection )
{
if ( selection->data != NULL )
{
AccountGroup *acc = gtk_object_get_user_data(GTK_OBJECT(selection->data));
create_add_account_dialog(acc);
}
}
else
{
create_add_account_dialog(NULL);
}
}
static void
delete_account_finish_cb ( GtkWidget *widget, gpointer data )
{
Account *account = data;
/* Did I delete this correctly? */
xaccRemoveAccount ( account );
xaccFreeAccount ( account );
refresh_tree ();
}
static void
delete_account_cb ( GtkWidget *widget, gpointer data )
{
GtkWidget *tree = data;
GList *selection;
selection = GTK_TREE_SELECTION ( tree );
if ( selection )
{
if ( selection->data != NULL )
{
Account *acc = gtk_object_get_user_data(GTK_OBJECT(selection->data));
GtkWidget *msgbox;
msgbox = gnome_message_box_new ( " Are you sure you want to delete this account. ",
GNOME_MESSAGE_BOX_WARNING,
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL, NULL );
gnome_dialog_button_connect (GNOME_DIALOG (msgbox), 0,
GTK_SIGNAL_FUNC (delete_account_finish_cb),
acc);
gtk_widget_show ( msgbox );
}
}
else
{
GtkWidget *msgbox;
msgbox = gnome_message_box_new ( " You must select an account to delete. ",
GNOME_MESSAGE_BOX_ERROR, "Ok", NULL );
gtk_widget_show ( msgbox );
}
}
static void
gnucash_mainwindow_toolbar_open ( GtkWidget *widget, gpointer data )
{
GtkWidget *tree = data;
GList *selection;
selection = GTK_TREE_SELECTION ( tree );
if ( selection )
{
if ( selection->data != NULL )
{
Account *acc = gtk_object_get_user_data(GTK_OBJECT(selection->data));
fprintf(stderr, "calling regWindowSimple(%p)\n", acct);
regWindowSimple ( acc );
}
}
else
{
GtkWidget *msgbox;
msgbox = gnome_message_box_new ( " You must select an account to open first. ",
GNOME_MESSAGE_BOX_ERROR, "Ok", NULL );
gtk_widget_show ( msgbox );
}
}
void
main_window_init(AccountGroup *accts)
{
GtkWidget *scrolled_win;
GtkWidget *toolBar[5];
GtkTooltips *tooltip;
GtkWidget *main_vbox;
GtkWidget *clist_vbox;
GtkWidget *button_bar;
GtkWidget *menubar;
GtkWidget *maintree;
GtkWidget *clist;
GtkWidget *notebook;
GtkWidget *scrolled_win;
GtkWidget *main_vbox;
GtkWidget *clist_vbox;
GtkWidget *menubar;
GtkWidget *clist;
GtkWidget *notebook;
int nmenu_items;
GtkAcceleratorTable *accel;
/* this is the GtkMenuEntry structure used to create new menus. The
first member is the menu definition string. The second, the default
accelerator key used to access this menu function with the keyboard.
@ -117,22 +369,51 @@ main_window_init(AccountGroup *accts)
{"<Main>/File/Save", "<control>S", file_cmd_save, NULL},
{"<Main>/File/Save as", NULL, NULL, NULL},
{"<Main>/File/<separator>", NULL, NULL, NULL},
{"<Main>/File/Quit", "<control>Q", file_cmd_quit, NULL },
{"<Main>/File/Quit", "<control>Q", gnucash_shutdown, NULL },
{"<Main>/Options/Preferences..", "<control>A", options_cb, NULL},
{"<Main>/Help/Help", NULL, help_cb, NULL},
{"<Main>/Help/<separator>", NULL, NULL, NULL},
{"<Main>/Help/About..", NULL, about_cb, NULL}
};
/* calculate the number of menu_item's */
int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
MenuBar *main_menu_bar;
maintree = gtk_tree_new ( );
mwindow = g_malloc ( sizeof ( main_window ) );
mwindow->maintree = gtk_tree_new ( );
mwindow->root_item = GTK_WIDGET ( mwindow->maintree );
/* Create the toolbar, and hook up the buttons to the tree widget */
{
GnomeUIInfo toolbar[] =
{
GNOMEUIINFO_ITEM_DATA(N_("Open"),
N_("Open selected account."),
gnucash_mainwindow_toolbar_open,
mwindow->root_item,
GNOME_APP_PIXMAP_NONE),
GNOMEUIINFO_ITEM_DATA(N_("New"),
N_("Create a new account."),
add_account, mwindow->root_item, GNOME_APP_PIXMAP_NONE),
GNOMEUIINFO_ITEM_DATA(N_("Edit"),
N_("Edit account information."),
NULL, NULL, GNOME_APP_PIXMAP_NONE),
GNOMEUIINFO_ITEM_DATA(N_("Delete"), N_("Delete selected account."),
delete_account_cb, mwindow->root_item, GNOME_APP_PIXMAP_NONE),
GNOMEUIINFO_ITEM(N_("Exit"), N_("Exit GnuCash."),
gnucash_shutdown, GNOME_APP_PIXMAP_NONE),
GNOMEUIINFO_END
};
/* calculate the number of menu_item's */
nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
gnome_app_create_toolbar(GNOME_APP(app), toolbar);
}
/* Cram accounts into the tree widget */
cram_accts_into_tree(GTK_TREE(maintree), accts);
acct_tree_fill(GTK_TREE(mwindow->root_item), accts, -1);
/* Create the notebook */
notebook = gtk_notebook_new ();
@ -215,74 +496,32 @@ main_window_init(AccountGroup *accts)
#endif
//gtk_window_add_accelerator_table(GTK_WINDOW(window), accel);
gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0);
gnome_app_set_menus ( GNOME_APP (app), GTK_MENU_BAR (menubar));
gtk_container_add( GTK_CONTAINER( main_vbox ), notebook );
// gtk_box_pack_start (GTK_BOX (main_vbox), scrolled_win, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(scrolled_win), maintree);
// gtk_container_add(GTK_CONTAINER(notebook), clist_vbox );
gtk_container_add(GTK_CONTAINER(scrolled_win), mwindow->maintree);
/* Append some pages to notebook */
{
GtkWidget *label;
label = gtk_label_new ( " All Accounts " );
gtk_notebook_append_page (GTK_NOTEBOOK(notebook), clist_vbox, label);
// label = gtk_label_new ( " All Accounts " );
// gtk_notebook_append_page (GTK_NOTEBOOK(notebook), clist_vbox, label);
label = gtk_label_new ( " Bank Accounts " );
gtk_notebook_append_page (GTK_NOTEBOOK(notebook), scrolled_win, label);
}
gtk_widget_show(clist_vbox);
//gtk_widget_show(clist_vbox);
gtk_widget_show(menubar);
/* create a bunch of buttons */
button_bar = gtk_hbox_new(FALSE, 1);
toolBar[open] = gtk_button_new_with_label ( OPEN_STR );
toolBar[close] = gtk_button_new_with_label ( NEW_STR );
toolBar[button3] = gtk_button_new_with_label ( EDIT_STR );
toolBar[button4] = gtk_button_new_with_label ( DELETE_STR );
toolBar[exit] = gtk_button_new_with_label (" Exit ");
/* Initialize callbacks */
gtk_signal_connect(GTK_OBJECT(toolBar[exit]), "clicked",
GTK_SIGNAL_FUNC (file_cmd_quit), NULL);
/* Initilize ToolTips */
tooltip = gtk_tooltips_new ();
gtk_tooltips_set_tip (tooltip, toolBar[open], TOOLTIP_OPEN, NULL);
gtk_tooltips_set_tip (tooltip, toolBar[close], TOOLTIP_NEW , NULL);
gtk_tooltips_set_tip (tooltip, toolBar[button3], TOOLTIP_EDIT, NULL);
gtk_tooltips_set_tip (tooltip, toolBar[button4], TOOLTIP_DELETE, NULL);
gtk_tooltips_set_tip (tooltip, toolBar[exit], TOOLTIP_EDIT, NULL);
/* Pack the buttons into the toolbar */
gtk_box_pack_start(GTK_BOX(button_bar), toolBar[0], FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(button_bar), toolBar[1], FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(button_bar), toolBar[2], FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(button_bar), toolBar[3], FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(button_bar), toolBar[4], FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(main_vbox), button_bar, FALSE, TRUE, 1);
gtk_widget_show(toolBar[open]);
gtk_widget_show(toolBar[close]);
gtk_widget_show(toolBar[button3]);
gtk_widget_show(toolBar[button4]);
gtk_widget_show(toolBar[exit]);
gtk_widget_show(button_bar);
gtk_widget_show(maintree);
gtk_widget_show(mwindow->maintree);
/* Setup some callbacks */
gtk_signal_connect (GTK_OBJECT (toolBar[1]), "clicked",
GTK_SIGNAL_FUNC (add_account), accts);
//gtk_signal_connect (GTK_OBJECT(window), "destroy",
// GTK_SIGNAL_FUNC (gnucash_shutdown), NULL);
//gtk_signal_connect (GTK_OBJECT (window), "delete_event",
// GTK_SIGNAL_FUNC (gnucash_shutdown), NULL);
gtk_widget_set_usize ( app, 400, 400 );
gtk_widget_set_usize ( GTK_WIDGET(app), 400, 400 );
/* Show everything now that it is created */
@ -291,108 +530,6 @@ main_window_init(AccountGroup *accts)
}
/* Standard Gnome About Dialog, need I say more? */
void
about_cb (GtkWidget *widget, void *data)
{
GtkWidget *about;
gchar *authors[] = {
/* Here should be your names */
"Rob Clark",
"Linas Vepsta",
"Jeremy Collins",
"Rob Browning",
"For more see http://gnucash.ml.org/developers.html",
NULL
};
about = gnome_about_new ( "GnuCash", VERSION,
"(C) 1998 The GnuCash Project",
authors,
"GnuCash: The GNU way to manage your money!",
NULL);
gtk_widget_show (about);
}
/* Help system callback */
void
help_cb ( GtkWidget *widget, void *data )
{
/* We need some config menus to setup were the docs are located */
/* for now I just set it to be $HOME/xacc-docs/ */
gchar *docs_path = "xacc-docs/xacc-main.html";
docs_path = gnome_util_prepend_user_home( docs_path );
gnome_help_goto( NULL, docs_path );
g_free( docs_path );
}
/* Some dialog stubs to be worked on */
/* We might want to move these to there own file =\ */
void
file_new_cb ( GtkWidget *widget, void *data )
{
}
/* Options dialog... this should house all of the config options */
/* like where the docs reside, and whatever else is deemed necessary */
void
options_cb ( GtkWidget *widget, void *data )
{
GnomePropertyBox *box;
GtkWidget *w, *label, *box2;
box = GNOME_PROPERTY_BOX(gnome_property_box_new());
w = gtk_button_new_with_label("Click me (Page #1)");
box2 = gtk_vbox_new ( FALSE, 1 );
gtk_box_pack_start(GTK_BOX(box2), w, FALSE, FALSE, 0);
gtk_widget_show ( box2 );
gtk_widget_show(w);
label = gtk_label_new("Config Box 1");
gtk_widget_show(label);
gnome_property_box_append_page(box, box2, label);
w = gtk_button_new_with_label("Click me (Page #2)");
gtk_widget_show(w);
label = gtk_label_new("Config Box 2");
gtk_widget_show(label);
gnome_property_box_append_page(box, w, label);
gtk_widget_set_usize ( box, 500, 400 );
gtk_widget_set_usize ( box2, 225, 225 );
gtk_widget_show(GTK_WIDGET(box));
}
void
add_account ( AccountGroup *acct )
{
GtkWidget *add_dialog;
add_dialog = create_add_account_dialog();
/* Callbacks */
// gtk_signal_connect (GTK_OBJECT (add_dialog->Ok), "clicked",
// GTK_SIGNAL_FUNC (add_account_finish), accts);
g_print ("New Account\n");
}
/********************* END OF FILE **********************************/
/*

View File

@ -31,16 +31,21 @@
#include "Account.h"
#include "config.h"
/** STRUCTURES ******************************************************/
struct _main_window
{
GtkWidget *maintree;
GtkWidget *root_item;
};
typedef struct _main_window main_window;
/** PROTOTYPES ******************************************************/
void refreshMainWindow( void );
void main_window_init(AccountGroup *);
void xaccMainWindowAddAccount ( GtkWidget * );
void about_cb (GtkWidget *widget, void *data);
void help_cb (GtkWidget *, void *);
void file_new_cb (GtkWidget *, void *);
void options_cb (GtkWidget *, void *);
void add_account ( AccountGroup * );
void refresh_tree ( void );
void acct_tree_fill ( GtkWidget *, AccountGroup *, int );
/** GLOBALS *********************************************************/
enum {
@ -72,15 +77,6 @@ enum {
HMB_LIC,
};
/* The following defines need to be changed later to reflect
* changes in the buttons.
*/
#define open 0
#define close 1
#define button3 2
#define button4 3
#define exit 4
#endif
/*

View File

@ -32,7 +32,7 @@ INCLPATH = -I.. -I../.. -I../engine -I../register -I@srcdir@/../../include
CFLAGS = @CFLAGS@ @X_CFLAGS@ ${INCLPATH}
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@ @X_PRE_LIBS@ @X_LIBS@ $(shell gtk-config --libs) \
LIBS = -lgif @LIBS@ @X_PRE_LIBS@ @X_LIBS@ $(shell gtk-config --libs) \
@X_EXTRA_LIBS@ -lgnomeui -lgnome -lgnomesupport -lgdk_imlib -ltiff -ldl
TARGET = ../../xacc.gtk.bin
@ -42,7 +42,7 @@ OTHER_OBJS := ../obj/gnome/*.o ../engine/obj/*.o ../register/obj/gnome/*.o
######################################################################
# See Makefile.common for information about these variables.
GNOME_SRCS := main.c MainWindow.c MenuBar.c RegWindow.c Dialogs.c xtutil.c \
GNOME_SRCS := main.c MainWindow.c MenuBar.c RegWindow.c Add_Dialog.c xtutil.c \
RecnWindow.c
# AccWindow.c AccountMenu.c AdjBWindow.c \
# BuildMenu.c Destroy.c FileBox.c HelpWindow.c \

View File

@ -120,7 +120,7 @@ recnRefresh(Account *acc)
GtkWidget *check_button = gtk_check_button_new_with_label(item_str);
gtk_signal_connect(GTK_OBJECT(check_button), "toggled",
recnCB, (gpointer) recnData);
(GtkSignalFunc)recnCB, (gpointer) recnData);
gtk_container_add(GTK_CONTAINER(list_item), check_button);
gtk_widget_show(list_item);
@ -381,7 +381,7 @@ startRecnWindow(GtkWidget *parent, Account *acc, double *diff)
}
}
}
gnome_dialog_close(dialog);
gnome_dialog_close(GNOME_DIALOG(dialog));
}
fprintf(stderr, "Returning result: %d\n", result);
return result;
@ -527,7 +527,7 @@ xaccDestroyRecnWindow(Account *acc)
FIND_IN_LIST(RecnWindow, recnList, acc, acc, recnData);
if(!recnData) return;
gnome_dialog_close(recnData->dialog);
gnome_dialog_close(GNOME_DIALOG(recnData->dialog));
}
@ -590,7 +590,7 @@ recnOkCB(GtkWidget *w, gpointer data)
/* refresh the register window */
accRefresh(recnData->acc);
gnome_dialog_close(recnData->dialog);
gnome_dialog_close(GNOME_DIALOG(recnData->dialog));
}
@ -599,7 +599,7 @@ recnCancelCB(GtkWidget *w, gpointer data)
{
RecnWindow *recnData = (RecnWindow *) data;
fprintf(stderr, "X\n");
gnome_dialog_close(recnData->dialog);
gnome_dialog_close(GNOME_DIALOG(recnData->dialog));
fprintf(stderr, "Y\n");
}

View File

@ -33,15 +33,16 @@
#include "Group.h"
#include "util.h"
#include "MainWindow.h"
#include "messages.h"
/** PROTOTYPES ******************************************************/
/** GLOBALS *********************************************************/
char *datafile = NULL;
char *helpPath = NULL;
GtkWidget *toplevel;
GtkWidget *filebox;
char *datafile = NULL;
GtkWidget *app;
@ -79,13 +80,36 @@ file_ok_sel (GtkWidget *w, GtkFileSelection *fs)
topgroup = xaccMallocAccountGroup();
}
xaccAccountGroupMarkSaved(topgroup);
main_window_init(topgroup);
}
void
gnucash_shutdown (GtkWidget *widget, gpointer *data)
{
gtk_main_quit ();
if ( xaccAccountGroupNotSaved(topgroup) )
{
GtkWidget *msgbox;
msgbox = gnome_message_box_new ( FMB_SAVE_MSG,
GNOME_MESSAGE_BOX_ERROR,
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL, NULL );
gnome_dialog_button_connect (GNOME_DIALOG (msgbox), 0,
GTK_SIGNAL_FUNC (file_cmd_save),
NULL);
gnome_dialog_button_connect (GNOME_DIALOG (msgbox), 0,
GTK_SIGNAL_FUNC (file_cmd_quit),
NULL);
gnome_dialog_button_connect (GNOME_DIALOG (msgbox), 1,
GTK_SIGNAL_FUNC (file_cmd_quit),
NULL);
gtk_widget_show ( msgbox );
}
else
{
gtk_main_quit ();
}
}
void
@ -108,6 +132,7 @@ file_cmd_save(GtkWidget *widget, gpointer data)
void file_cmd_quit (GtkWidget *widget, gpointer data)
{
//gnucash_shutdown(NULL, NULL);
gtk_main_quit();
}
@ -225,6 +250,7 @@ main( int argc, char *argv[] )
topgroup = xaccMallocAccountGroup();
}
/* Create main window */
xaccAccountGroupMarkSaved(topgroup);
main_window_init(topgroup);
} else {
/* Filebox code here */