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 "MenuBar.h"
#include "messages.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;
@ -56,15 +82,40 @@ void main_window_init()
GtkWidget *clist;
GtkWidget *list_item;
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);
/* Fix the column widths */
gtk_clist_set_column_width ( GTK_CLIST(clist), 1, 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);
gtk_window_set_title(GTK_WINDOW(window), "GnoMoney");
@ -72,7 +123,57 @@ void main_window_init()
gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
gtk_container_add(GTK_CONTAINER(window), main_vbox);
get_main_menu(&menubar, &accel);
{
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
gtk_window_add_accelerator_table(GTK_WINDOW(window), accel);
gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0);
gtk_widget_show(menubar);
@ -134,10 +235,17 @@ void main_window_init()
gtk_widget_show(main_vbox);
gtk_container_border_width (GTK_CONTAINER (window), 2);
gtk_widget_show(window);
}
/********************* 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 ******************************************************/
void refreshMainWindow( void );
void main_window_init( );
void main_window_init(AccountGroup *);
void xaccMainWindowAddAccount ( GtkWidget * );
@ -78,3 +78,13 @@ enum {
#define exit 4
#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,134 +1,61 @@
// WaterMark/GnoMoney
// mainMenu.c
// from Gtk tutorial
/* MenuBar.c -- GTK menu functions for xacc (X-Accountant) Copyright
(C) 1998 Jeremy Collins <linux@cyberramp.net>
(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 <strings.h>
#include "MenuBar.h"
#include "main.h"
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];
#if 0
static GHashTable *entry_ht = NULL;
void get_main_menu(GtkWidget ** menubar, GtkAcceleratorTable ** table)
{
if (initialize)
menus_init();
if (menubar)
*menubar = subfactory[0]->widget;
if (table)
*table = subfactory[0]->table;
}
void menus_init(void)
{
if (initialize) {
initialize = FALSE;
factory = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
subfactory[0] = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
gtk_menu_factory_add_subfactory(factory, subfactory[0], "<Main>");
menus_create(menu_items, nmenu_items);
}
}
void menus_create(GtkMenuEntry * entries, int nmenu_entries)
{
char *accelerator;
int i;
if (initialize)
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
static gint
menus_install_accel(GtkWidget * widget, gchar * signal_name, gchar
key, gchar modifiers, gchar * path)
{
char accel[64];
char *t1, t2[2];
accel[0] = '\0';
if (modifiers & GDK_CONTROL_MASK)
strcat(accel, "<control>");
if (modifiers & GDK_SHIFT_MASK)
strcat(accel, "<shift>");
if (modifiers & GDK_MOD1_MASK)
strcat(accel, "<alt>");
if (modifiers & GDK_CONTROL_MASK) strcat(accel, "<control>");
if (modifiers & GDK_SHIFT_MASK) strcat(accel, "<shift>");
if (modifiers & GDK_MOD1_MASK) strcat(accel, "<alt>");
t2[0] = key;
t2[1] = '\0';
strcat(accel, t2);
/* if (entry_ht) {
if (entry_ht) {
t1 = g_hash_table_lookup(entry_ht, path);
g_free(t1);
} else
entry_ht = g_hash_table_new(g_string_hash, g_string_equal);
*/
} 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;
}
static void menus_remove_accel(GtkWidget * widget, gchar * signal_name, gchar *
path)
static void
menus_remove_accel(GtkWidget * widget, gchar * signal_name, gchar *path)
{
char *t;
@ -140,17 +67,85 @@ static void menus_remove_accel(GtkWidget * widget, gchar * signal_name, gchar *
}
}
void menus_set_sensitive(char *path, int sensitive)
#endif
MenuBarGroup *menuBarGroupCreate()
{
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);
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
}
MenuBar *menuBarCreate(MenuBarGroup *group, const gchar menuBarName[])
{
GtkMenuFactory *subfactory = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
gtk_menu_factory_add_subfactory(group, subfactory, menuBarName);
return(subfactory);
}
GtkWidget *menuBarGroupFindItem(MenuBarGroup *group, const gchar path[])
{
GtkMenuPath *mp;
mp = gtk_menu_factory_find(group, path);
if(mp) {
return(mp->widget);
} else {
return NULL;
}
}
GtkWidget *menuBarGetWidget(MenuBar *mb)
{
return mb->widget;
}
/*
Local Variables:
tab-width: 2
indent-tabs-mode: nil
mode: c-mode
c-indentation-style: gnu
eval: (c-set-offset 'block-open '-)
End:
*/

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;
}
main_window_init ();
main_window_init(topgroup);
}
void destroy (GtkWidget *widget, gpointer *data)
@ -85,7 +84,7 @@ void destroy (GtkWidget *widget, gpointer *data)
gtk_main_quit ();
}
void file_cmd_open ()
void file_cmd_open (GtkWidget *widget, gpointer data)
{
g_print ( "Menu Command: file open\n" );
}
@ -107,6 +106,16 @@ main( int argc, char *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..." );
/* read in the filename (should be the first arg after all
@ -145,7 +154,7 @@ main( int argc, char *argv[] )
}
}
/* Create main window */
main_window_init();
main_window_init(topgroup);
}
else
{
@ -180,3 +189,12 @@ main( int argc, char *argv[] )
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 ******************************************************/
void destroy (GtkWidget *widget, gpointer *data);
void file_cmd_open (void);
void file_cmd_open (GtkWidget *widget, gpointer data);
/** GLOBALS *********************************************************/
extern char *helpPath;
#endif
/*
Local Variables:
tab-width: 2
indent-tabs-mode: nil
mode: c-mode
c-indentation-style: gnu
eval: (c-set-offset 'block-open '-)
End:
*/