patches from rob browning

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@656 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-03-18 04:23:34 +00:00
parent 25805a8062
commit a8f15f1aa7
6 changed files with 338 additions and 158 deletions

View File

@ -24,6 +24,7 @@
\********************************************************************/ \********************************************************************/
#include "MainWindow.h" #include "MainWindow.h"
#include "MenuBar.h"
#include "messages.h" #include "messages.h"
#include "main.h" #include "main.h"
@ -39,7 +40,32 @@ struct main_window {
}; };
void main_window_init() /* This should most likely be rewritting to use a Tree, not a Clist so
we can represent the heirarchical account structure */
static void
cram_accts_into_clist(GtkCList *list, AccountGroup *accts) {
int count = xaccGetNumAccounts(accts);
int i;
GtkWidget *item;
for(i=0; i<count; i++) {
Account *acc = getAccount(accts, i);
gchar *rowstrs[] = { acc->accountName,
acc->description,
acc->notes };
gint new_row = gtk_clist_append(GTK_CLIST(list), rowstrs);
/* Set the row 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_clist_set_row_data(GTK_CLIST(list), new_row, acc);
}
}
void
main_window_init(AccountGroup *accts)
{ {
GtkWidget *window; GtkWidget *window;
@ -56,23 +82,98 @@ void main_window_init()
GtkWidget *clist; GtkWidget *clist;
GtkWidget *list_item; GtkWidget *list_item;
GtkAcceleratorTable *accel; 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.
The third is the callback function to call when this menu item is
selected (by the accelerator key, or with the mouse.) The last
member is the data to pass to your callback function. */
GtkMenuEntry menu_items[] =
{
{"<Main>/File/New", "<control>N", NULL, NULL},
{"<Main>/File/Open", "<control>O", file_cmd_open, NULL},
{"<Main>/File/Save", "<control>S", NULL, NULL},
{"<Main>/File/Save as", NULL, NULL, NULL},
{"<Main>/File/<separator>", NULL, NULL, NULL},
{"<Main>/File/Quit", "<control>Q", gtk_main_quit, "OK, I'll quit"},
{"<Main>/Options/General..", "<control>A", NULL, NULL},
{"<Main>/Help/About..", NULL, NULL, NULL}
};
/* calculate the number of menu_item's */
int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
MenuBar *main_menu_bar;
clist = gtk_clist_new_with_titles(3, clist_titles); clist = gtk_clist_new_with_titles(3, clist_titles);
/* Fix the column widths */ /* Fix the column widths */
gtk_clist_set_column_width ( GTK_CLIST(clist), 1, 85 ); gtk_clist_set_column_width ( GTK_CLIST(clist), 1, 85 );
gtk_clist_set_column_width ( GTK_CLIST(clist), 0, 85 ); gtk_clist_set_column_width ( GTK_CLIST(clist), 0, 85 );
cram_accts_into_clist(GTK_CLIST(clist), accts);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GnoMoney"); gtk_window_set_title(GTK_WINDOW(window), "GnoMoney");
main_vbox = gtk_vbox_new(FALSE, 1); main_vbox = gtk_vbox_new(FALSE, 1);
gtk_container_border_width(GTK_CONTAINER(main_vbox), 1); gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
gtk_container_add(GTK_CONTAINER(window), main_vbox); gtk_container_add(GTK_CONTAINER(window), main_vbox);
{
MenuBarGroup *mbg = menuBarGroupCreate();
main_menu_bar = menuBarCreate(mbg, "<Main>");
menuBarGroupAddItems(mbg, menu_items, nmenu_items);
}
menubar = main_menu_bar->widget;
accel = main_menu_bar->table;
#if 0
{
/* Here's how to use the new MenBar stuff to create multiple menu
bars */
GtkWidget *test_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
GtkWidget *test_vbox = gtk_vbox_new(FALSE, 1);
MenuBarGroup *mbg = menuBarGroupCreate();
MenuBar *mb1;
MenuBar *mb2;
GtkMenuEntry items[] =
{
{"<Stumpy>/Eat/Grubs", "<control>N", NULL, NULL},
{"<Stumpy>/Eat/Gravel", "<control>O", NULL, NULL},
{"<Stumpy>/So/Scary", "<control>S", NULL, NULL},
{"<Stumpy2>/Eat-2/Grubs", "<control>N", NULL, NULL},
{"<Stumpy2>/Eat-2/Gravel", "<control>O", NULL, NULL},
{"<Stumpy2>/So-2/Scary/Err/Umm", "<control>S", NULL, NULL}
};
int nitems = sizeof(items) / sizeof(items[0]);
mb1 = menuBarCreate(mbg, "<Stumpy>");
mb2 = menuBarCreate(mbg, "<Stumpy2>");
menuBarGroupAddItems(mbg, items, nitems);
gtk_window_set_title(GTK_WINDOW(test_win), "Stumpy");
gtk_container_add(GTK_CONTAINER(test_win), test_vbox);
gtk_box_pack_start(GTK_BOX(test_vbox), menuBarGetWidget(mb1),
FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(test_vbox), menuBarGetWidget(mb2),
FALSE, TRUE, 0);
gtk_widget_show(menuBarGetWidget(mb1));
gtk_widget_show(menuBarGetWidget(mb2));
gtk_widget_show(test_vbox);
gtk_widget_show(test_win);
}
#endif
get_main_menu(&menubar, &accel);
gtk_window_add_accelerator_table(GTK_WINDOW(window), accel); gtk_window_add_accelerator_table(GTK_WINDOW(window), accel);
gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0);
gtk_widget_show(menubar); gtk_widget_show(menubar);
@ -133,11 +234,18 @@ void main_window_init()
/* Show everything now that it is created */ /* Show everything now that it is created */
gtk_widget_show(main_vbox); gtk_widget_show(main_vbox);
gtk_container_border_width (GTK_CONTAINER (window), 2); gtk_container_border_width (GTK_CONTAINER (window), 2);
gtk_widget_show(window); gtk_widget_show(window);
} }
/********************* END OF FILE **********************************/ /********************* END OF FILE **********************************/
/*
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

@ -34,7 +34,7 @@
/** PROTOTYPES ******************************************************/ /** PROTOTYPES ******************************************************/
void refreshMainWindow( void ); void refreshMainWindow( void );
void main_window_init( ); void main_window_init(AccountGroup *);
void xaccMainWindowAddAccount ( GtkWidget * ); void xaccMainWindowAddAccount ( GtkWidget * );
@ -78,3 +78,13 @@ enum {
#define exit 4 #define exit 4
#endif #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

@ -1,156 +1,151 @@
// WaterMark/GnoMoney /* MenuBar.c -- GTK menu functions for xacc (X-Accountant) Copyright
// mainMenu.c (C) 1998 Jeremy Collins <linux@cyberramp.net>
// from Gtk tutorial (C) 1998 Rob Browning <rlb@cs.utexas.edu>
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: Jeremy Collins
Internet: linux@cyberramp.net
*/
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <strings.h> #include <strings.h>
#include "MenuBar.h"
#include "main.h" #if 0
static void menus_remove_accel(GtkWidget * widget, gchar * signal_name, gchar *
path);
static gint menus_install_accel(GtkWidget * widget, gchar * signal_name, gchar
key, gchar modifiers, gchar * path);
void menus_init(void);
void menus_create(GtkMenuEntry * entries, int nmenu_entries);
/* 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. The third is the callback function to call when
* this menu item is selected (by the accelerator key, or with the
* mouse.) The last member is the data to pass to your callback function.
*/
static GtkMenuEntry menu_items[] =
{
{"<Main>/File/New", "<control>N", NULL, NULL},
{"<Main>/File/Open", "<control>O", file_cmd_open, NULL},
{"<Main>/File/Save", "<control>S", NULL, NULL},
{"<Main>/File/Save as", NULL, NULL, NULL},
{"<Main>/File/<separator>", NULL, NULL, NULL},
{"<Main>/File/Quit", "<control>Q", gtk_main_quit, "OK, I'll quit"},
{"<Main>/Account/General..", "<control>A", NULL, NULL},
{"<Main>/Help/About..", NULL, NULL, NULL}
};
/* calculate the number of menu_item's */
static int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
static int initialize = TRUE;
static GtkMenuFactory *factory = NULL;
static GtkMenuFactory *subfactory[1];
static GHashTable *entry_ht = NULL; static GHashTable *entry_ht = NULL;
void get_main_menu(GtkWidget ** menubar, GtkAcceleratorTable ** table) static gint
menus_install_accel(GtkWidget * widget, gchar * signal_name, gchar
key, gchar modifiers, gchar * path)
{ {
if (initialize) char accel[64];
menus_init(); char *t1, t2[2];
if (menubar) accel[0] = '\0';
*menubar = subfactory[0]->widget; if (modifiers & GDK_CONTROL_MASK) strcat(accel, "<control>");
if (table) if (modifiers & GDK_SHIFT_MASK) strcat(accel, "<shift>");
*table = subfactory[0]->table; if (modifiers & GDK_MOD1_MASK) strcat(accel, "<alt>");
t2[0] = key;
t2[1] = '\0';
strcat(accel, t2);
if (entry_ht) {
t1 = g_hash_table_lookup(entry_ht, path);
g_free(t1);
} else {
entry_ht = g_hash_table_new(g_str_hash, g_str_equal);
}
g_hash_table_insert(entry_ht, path, g_strdup(accel));
return TRUE;
} }
void menus_init(void) static void
menus_remove_accel(GtkWidget * widget, gchar * signal_name, gchar *path)
{ {
if (initialize) { char *t;
initialize = FALSE;
if (entry_ht) {
t = g_hash_table_lookup(entry_ht, path);
g_free(t);
g_hash_table_insert(entry_ht, path, g_strdup(""));
}
}
factory = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR); #endif
subfactory[0] = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
gtk_menu_factory_add_subfactory(factory, subfactory[0], "<Main>"); MenuBarGroup *menuBarGroupCreate()
menus_create(menu_items, nmenu_items); {
GtkMenuFactory * f;
f = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
return(f);
}
void
menuBarGroupAddItems(MenuBarGroup *group,
GtkMenuEntry items[], guint nitems)
{
#if 0
int i;
char *accelerator;
if (entry_ht) {
for (i = 0; i < nitems; i++) {
accelerator = g_hash_table_lookup(entry_ht, items[i].path);
if (accelerator) {
if (accelerator[0] == '\0')
items[i].accelerator = NULL;
else
items[i].accelerator = accelerator;
}
} }
}
#endif
gtk_menu_factory_add_entries(group, items, nitems);
#if 0
for(i = 0; i < nitems; i++)
{
if (items[i].widget) {
gtk_signal_connect(GTK_OBJECT(items[i].widget), "install_accelerator",
GTK_SIGNAL_FUNC(menus_install_accel),
items[i].path);
gtk_signal_connect(GTK_OBJECT(items[i].widget), "remove_accelerator",
GTK_SIGNAL_FUNC(menus_remove_accel),
items[i].path);
}
}
#endif
} }
void menus_create(GtkMenuEntry * entries, int nmenu_entries) MenuBar *menuBarCreate(MenuBarGroup *group, const gchar menuBarName[])
{ {
char *accelerator; GtkMenuFactory *subfactory = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
int i; gtk_menu_factory_add_subfactory(group, subfactory, menuBarName);
if (initialize) return(subfactory);
menus_init();
if (entry_ht)
for (i = 0; i < nmenu_entries; i++) {
accelerator = g_hash_table_lookup(entry_ht, entries[i].path);
if (accelerator) {
if (accelerator[0] == '\0')
entries[i].accelerator = NULL;
else
entries[i].accelerator = accelerator;
}
}
gtk_menu_factory_add_entries(factory, entries, nmenu_entries);
for (i = 0; i < nmenu_entries; i++)
if (entries[i].widget) {
gtk_signal_connect(GTK_OBJECT(entries[i].widget), "install_accelerator",
GTK_SIGNAL_FUNC(menus_install_accel),
entries[i].path);
gtk_signal_connect(GTK_OBJECT(entries[i].widget), "remove_accelerator",
GTK_SIGNAL_FUNC(menus_remove_accel),
entries[i].path);
}
} }
static gint menus_install_accel(GtkWidget * widget, gchar * signal_name, gchar
key, gchar modifiers, gchar * path) GtkWidget *menuBarGroupFindItem(MenuBarGroup *group, const gchar path[])
{ {
char accel[64]; GtkMenuPath *mp;
char *t1, t2[2]; mp = gtk_menu_factory_find(group, path);
if(mp) {
return(mp->widget);
} else {
return NULL;
}
}
accel[0] = '\0'; GtkWidget *menuBarGetWidget(MenuBar *mb)
if (modifiers & GDK_CONTROL_MASK) {
strcat(accel, "<control>"); return mb->widget;
if (modifiers & GDK_SHIFT_MASK) }
strcat(accel, "<shift>");
if (modifiers & GDK_MOD1_MASK)
strcat(accel, "<alt>");
t2[0] = key; /*
t2[1] = '\0'; Local Variables:
strcat(accel, t2); tab-width: 2
indent-tabs-mode: nil
/* if (entry_ht) { mode: c-mode
t1 = g_hash_table_lookup(entry_ht, path); c-indentation-style: gnu
g_free(t1); eval: (c-set-offset 'block-open '-)
} else End:
entry_ht = g_hash_table_new(g_string_hash, g_string_equal);
*/ */
g_hash_table_insert(entry_ht, path, g_strdup(accel));
return TRUE;
}
static void menus_remove_accel(GtkWidget * widget, gchar * signal_name, gchar *
path)
{
char *t;
if (entry_ht) {
t = g_hash_table_lookup(entry_ht, path);
g_free(t);
g_hash_table_insert(entry_ht, path, g_strdup(""));
}
}
void menus_set_sensitive(char *path, int sensitive)
{
GtkMenuPath *menu_path;
if (initialize)
menus_init();
menu_path = gtk_menu_factory_find(factory, path);
if (menu_path)
gtk_widget_set_sensitive(menu_path->widget, sensitive);
else
g_warning("Unable to set sensitivity for menu which doesn't exist:
%s", path);
}

39
src/gnome/MenuBar.h Normal file
View File

@ -0,0 +1,39 @@
/* MenuBar.h -- GTK menu functions for xacc (X-Accountant) Copyright
(C) 1998 Rob Browning <rlb@cs.utexas.edu>
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 Browning
Internet: rlb@cs.utexas.edu
*/
#ifndef __MENUBAR_H__
#define __MENUBAR_H__
typedef GtkMenuFactory MenuBarGroup;
typedef GtkMenuFactory MenuBar;
/* Order must be: create group, create menu bar, add items. */
MenuBarGroup *menuBarGroupCreate();
void menuBarGroupAddItems(MenuBarGroup *group,
GtkMenuEntry items[], guint nitems);
MenuBar *menuBarCreate(MenuBarGroup *group, const gchar menuBarName[]);
GtkWidget *menuBarGroupFindItem(MenuBarGroup *group, const gchar path[]);
GtkWidget *menuBarGetWidget(MenuBar *mb);
#endif

View File

@ -76,8 +76,7 @@ void file_ok_sel (GtkWidget *w, GtkFileSelection *fs)
topgroup->new = TRUE; topgroup->new = TRUE;
} }
main_window_init (); main_window_init(topgroup);
} }
void destroy (GtkWidget *widget, gpointer *data) void destroy (GtkWidget *widget, gpointer *data)
@ -85,7 +84,7 @@ void destroy (GtkWidget *widget, gpointer *data)
gtk_main_quit (); gtk_main_quit ();
} }
void file_cmd_open () void file_cmd_open (GtkWidget *widget, gpointer data)
{ {
g_print ( "Menu Command: file open\n" ); g_print ( "Menu Command: file open\n" );
} }
@ -107,6 +106,16 @@ main( int argc, char *argv[] )
{ {
gtk_init (&argc, &argv); gtk_init (&argc, &argv);
{
/* Use a nicer font IMO, if available */
char font[] = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*";
GtkStyle *st = gtk_widget_get_default_style();
GdkFont *f = gdk_font_load(font);
if(st && f) {
st->font = f;
}
}
filebox = gtk_file_selection_new ( "Open..." ); filebox = gtk_file_selection_new ( "Open..." );
/* read in the filename (should be the first arg after all /* read in the filename (should be the first arg after all
@ -145,7 +154,7 @@ main( int argc, char *argv[] )
} }
} }
/* Create main window */ /* Create main window */
main_window_init(); main_window_init(topgroup);
} }
else else
{ {
@ -156,27 +165,36 @@ main( int argc, char *argv[] )
/* Check to see if this is a valid datafile */ /* Check to see if this is a valid datafile */
if ( datafile != NULL ) if ( datafile != NULL )
topgroup = xaccReadAccountGroup (datafile); topgroup = xaccReadAccountGroup (datafile);
/* Callbacks for File Box and Stuff */ /* Callbacks for File Box and Stuff */
gtk_signal_connect (GTK_OBJECT (filebox), "delete_event", gtk_signal_connect (GTK_OBJECT (filebox), "delete_event",
(GtkSignalFunc) gtk_widget_destroy, (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT(filebox)); GTK_OBJECT(filebox));
/* Connect the ok_button to file_ok_sel function */ /* Connect the ok_button to file_ok_sel function */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filebox)->ok_button), gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filebox)->ok_button),
"clicked", (GtkSignalFunc) file_ok_sel, filebox ); "clicked", (GtkSignalFunc) file_ok_sel, filebox );
/* Connect the cancel_button to also kill the app */ /* Connect the cancel_button to also kill the app */
gtk_signal_connect_object ( GTK_OBJECT (GTK_FILE_SELECTION (filebox)->cancel_button), gtk_signal_connect_object ( GTK_OBJECT (GTK_FILE_SELECTION (filebox)->cancel_button),
"clicked", (GtkSignalFunc) gtk_exit, NULL ); "clicked", (GtkSignalFunc) gtk_exit, NULL );
/* Enter event loop */ /* Enter event loop */
gtk_main(); gtk_main();
return 0; return 0;
} }
/*
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

@ -51,9 +51,19 @@
/** PROTOTYPES ******************************************************/ /** PROTOTYPES ******************************************************/
void destroy (GtkWidget *widget, gpointer *data); void destroy (GtkWidget *widget, gpointer *data);
void file_cmd_open (void); void file_cmd_open (GtkWidget *widget, gpointer data);
/** GLOBALS *********************************************************/ /** GLOBALS *********************************************************/
extern char *helpPath; extern char *helpPath;
#endif #endif
/*
Local Variables:
tab-width: 2
indent-tabs-mode: nil
mode: c-mode
c-indentation-style: gnu
eval: (c-set-offset 'block-open '-)
End:
*/