Commit e8e76925 authored by BST 1998  Tony Gale's avatar BST 1998 Tony Gale Committed by Tony Gale
Browse files

- Tidy up of the menufactory example from Andy Kahn <kahn@zk3.dec.com> -

Thu Aug 13 09:11:11 BST 1998  Tony Gale  <gale@gtk.org>

        * docs/gtk_tut.sgml:
          - Tidy up of the menufactory example from
            Andy Kahn <kahn@zk3.dec.com>
          - New section on Range Widgets from
            David Huggins-Daines <bn711@freenet.carleton.ca>
          - Started a new section on 'Advanced Event and Signal
            Handling' - used an email from Owen.
          - New appendix on Gdk Event Types
          - Added the tictactoe full example code to the
            'Code Examples' appendix
parent 7a235648
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
* docs/gtk_tut.sgml:
- Tidy up of the menufactory example from
Andy Kahn <kahn@zk3.dec.com>
- New section on Range Widgets from
David Huggins-Daines <bn711@freenet.carleton.ca>
- Started a new section on 'Advanced Event and Signal
Handling' - used an email from Owen.
- New appendix on Gdk Event Types
- Added the tictactoe full example code to the
'Code Examples' appendix
Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com>
* gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() -
......
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
* docs/gtk_tut.sgml:
- Tidy up of the menufactory example from
Andy Kahn <kahn@zk3.dec.com>
- New section on Range Widgets from
David Huggins-Daines <bn711@freenet.carleton.ca>
- Started a new section on 'Advanced Event and Signal
Handling' - used an email from Owen.
- New appendix on Gdk Event Types
- Added the tictactoe full example code to the
'Code Examples' appendix
Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com>
* gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() -
......
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
* docs/gtk_tut.sgml:
- Tidy up of the menufactory example from
Andy Kahn <kahn@zk3.dec.com>
- New section on Range Widgets from
David Huggins-Daines <bn711@freenet.carleton.ca>
- Started a new section on 'Advanced Event and Signal
Handling' - used an email from Owen.
- New appendix on Gdk Event Types
- Added the tictactoe full example code to the
'Code Examples' appendix
Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com>
* gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() -
......
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
* docs/gtk_tut.sgml:
- Tidy up of the menufactory example from
Andy Kahn <kahn@zk3.dec.com>
- New section on Range Widgets from
David Huggins-Daines <bn711@freenet.carleton.ca>
- Started a new section on 'Advanced Event and Signal
Handling' - used an email from Owen.
- New appendix on Gdk Event Types
- Added the tictactoe full example code to the
'Code Examples' appendix
Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com>
* gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() -
......
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
* docs/gtk_tut.sgml:
- Tidy up of the menufactory example from
Andy Kahn <kahn@zk3.dec.com>
- New section on Range Widgets from
David Huggins-Daines <bn711@freenet.carleton.ca>
- Started a new section on 'Advanced Event and Signal
Handling' - used an email from Owen.
- New appendix on Gdk Event Types
- Added the tictactoe full example code to the
'Code Examples' appendix
Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com>
* gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() -
......
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
* docs/gtk_tut.sgml:
- Tidy up of the menufactory example from
Andy Kahn <kahn@zk3.dec.com>
- New section on Range Widgets from
David Huggins-Daines <bn711@freenet.carleton.ca>
- Started a new section on 'Advanced Event and Signal
Handling' - used an email from Owen.
- New appendix on Gdk Event Types
- Added the tictactoe full example code to the
'Code Examples' appendix
Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com>
* gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() -
......
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
* docs/gtk_tut.sgml:
- Tidy up of the menufactory example from
Andy Kahn <kahn@zk3.dec.com>
- New section on Range Widgets from
David Huggins-Daines <bn711@freenet.carleton.ca>
- Started a new section on 'Advanced Event and Signal
Handling' - used an email from Owen.
- New appendix on Gdk Event Types
- Added the tictactoe full example code to the
'Code Examples' appendix
Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com>
* gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() -
......
This diff is collapsed.
This diff is collapsed.
/* This file extracted from the GTK tutorial. */ /* example-start menu menufactory.c */
/* menufactory.c */
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <strings.h> #include <strings.h>
#include "mfmain.h" #include "mfmain.h"
static void print_hello(GtkWidget *widget, gpointer data);
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 /* this is the GtkMenuEntry structure used to create new menus. The
...@@ -24,128 +18,37 @@ void menus_create(GtkMenuEntry * entries, int nmenu_entries); ...@@ -24,128 +18,37 @@ void menus_create(GtkMenuEntry * entries, int nmenu_entries);
static GtkMenuEntry menu_items[] = static GtkMenuEntry menu_items[] =
{ {
{"<Main>/File/New", "<control>N", NULL, NULL}, {"<Main>/File/New", "<control>N", print_hello, NULL},
{"<Main>/File/Open", "<control>O", NULL, NULL}, {"<Main>/File/Open", "<control>O", print_hello, NULL},
{"<Main>/File/Save", "<control>S", NULL, NULL}, {"<Main>/File/Save", "<control>S", print_hello, NULL},
{"<Main>/File/Save as", NULL, NULL, NULL}, {"<Main>/File/Save as", NULL, NULL, NULL},
{"<Main>/File/<separator>", NULL, NULL, NULL}, {"<Main>/File/<separator>", NULL, NULL, NULL},
{"<Main>/File/Quit", "<control>Q", file_quit_cmd_callback, "OK, I'll quit"}, {"<Main>/File/Quit", "<control>Q", file_quit_cmd_callback, "OK, I'll quit"},
{"<Main>/Options/Test", NULL, NULL, NULL} {"<Main>/Options/Test", 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 void
static GtkMenuFactory *factory = NULL; print_hello(GtkWidget *widget, gpointer data)
static GtkMenuFactory *subfactory[1];
static GHashTable *entry_ht = NULL;
void get_main_menu(GtkWidget ** menubar, GtkAcceleratorTable ** table)
{ {
if (initialize) printf("hello!\n");
menus_init();
if (menubar)
*menubar = subfactory[0]->widget;
if (table)
*table = subfactory[0]->table;
} }
void menus_init(void) void get_main_menu(GtkWidget *window, GtkWidget ** menubar)
{ {
if (initialize) { int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
initialize = FALSE; GtkMenuFactory *factory;
GtkMenuFactory *subfactory;
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) factory = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
{ subfactory = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
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",
(GtkSignalFunc) menus_install_accel,
entries[i].path);
gtk_signal_connect(GTK_OBJECT(entries[i].widget), "remove_accelerator",
(GtkSignalFunc) menus_remove_accel,
entries[i].path);
}
}
static gint menus_install_accel(GtkWidget * widget, gchar * signal_name, gchar key, gchar modifiers, gchar * path) gtk_menu_factory_add_subfactory(factory, subfactory, "<Main>");
{ gtk_menu_factory_add_entries(factory, menu_items, nmenu_items);
char accel[64]; gtk_window_add_accelerator_table(GTK_WINDOW(window), subfactory->table);
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>");
t2[0] = key; if (menubar)
t2[1] = '\0'; *menubar = subfactory->widget;
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;
}
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) /* example-end */
{
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);
}
/* This file extracted from the GTK tutorial. */ /* example-start menu menufactory.h */
/* menufactory.h */
#ifndef __MENUFACTORY_H__ #ifndef __MENUFACTORY_H__
#define __MENUFACTORY_H__ #define __MENUFACTORY_H__
...@@ -9,11 +7,12 @@ ...@@ -9,11 +7,12 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
void get_main_menu (GtkWidget **menubar, GtkAcceleratorTable **table); void get_main_menu (GtkWidget *, GtkWidget **menubar);
void menus_create(GtkMenuEntry *entries, int nmenu_entries);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __MENUFACTORY_H__ */ #endif /* __MENUFACTORY_H__ */
/* example-end */
/* This file extracted from the GTK tutorial. */ /* example-start menu mfmain.c */
/* mfmain.c */
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "mfmain.h" #include "mfmain.h"
#include "menufactory.h" #include "menufactory.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
GtkWidget *window; GtkWidget *window;
GtkWidget *main_vbox; GtkWidget *main_vbox;
GtkWidget *menubar; GtkWidget *menubar;
GtkAcceleratorTable *accel;
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
...@@ -30,8 +25,7 @@ int main(int argc, char *argv[]) ...@@ -30,8 +25,7 @@ int main(int argc, char *argv[])
gtk_container_add(GTK_CONTAINER(window), main_vbox); gtk_container_add(GTK_CONTAINER(window), main_vbox);
gtk_widget_show(main_vbox); gtk_widget_show(main_vbox);
get_main_menu(&menubar, &accel); get_main_menu(window, &menubar);
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);
...@@ -50,3 +44,5 @@ void file_quit_cmd_callback (GtkWidget *widget, gpointer data) ...@@ -50,3 +44,5 @@ void file_quit_cmd_callback (GtkWidget *widget, gpointer data)
g_print ("%s\n", (char *) data); g_print ("%s\n", (char *) data);
gtk_exit(0); gtk_exit(0);
} }
/* example-end */
/* This file extracted from the GTK tutorial. */ /* example-start menu mfmain.h */
/* mfmain.h */
#ifndef __MFMAIN_H__ #ifndef __MFMAIN_H__
#define __MFMAIN_H__ #define __MFMAIN_H__
...@@ -17,3 +15,5 @@ void file_quit_cmd_callback(GtkWidget *widget, gpointer data); ...@@ -17,3 +15,5 @@ void file_quit_cmd_callback(GtkWidget *widget, gpointer data);
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __MFMAIN_H__ */ #endif /* __MFMAIN_H__ */
/* example-end */
CC = gcc
rangewidgets: rangewidgets.c
$(CC) `gtk-config --cflags` `gtk-config --libs` rangewidgets.c -o rangewidgets
clean:
rm -f *.o rangewidgets
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment