Commit 5abc7156 authored by BST 2002  Tony Gale's avatar BST 2002 Tony Gale Committed by Tony Gale

cleanups

Mon Aug 26 12:21:16 BST 2002  Tony Gale <gale@gtk.org>

        * docs/tutorial/package-db-tutorial.sh: cleanups

        * docs/tutorial/gtk-tut.sgml: new content for the
        ItemFactory section. Originally from Robert Cleaver Ancell.
parent 7049e0cb
Mon Aug 26 12:21:16 BST 2002 Tony Gale <gale@gtk.org>
* docs/tutorial/package-db-tutorial.sh: cleanups
* docs/tutorial/gtk-tut.sgml: new content for the
ItemFactory section. Originally from Robert Cleaver Ancell.
2002-08-25 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Don't include <winsock.h> on Cygwin (#91654,
......
Mon Aug 26 12:21:16 BST 2002 Tony Gale <gale@gtk.org>
* docs/tutorial/package-db-tutorial.sh: cleanups
* docs/tutorial/gtk-tut.sgml: new content for the
ItemFactory section. Originally from Robert Cleaver Ancell.
2002-08-25 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Don't include <winsock.h> on Cygwin (#91654,
......
Mon Aug 26 12:21:16 BST 2002 Tony Gale <gale@gtk.org>
* docs/tutorial/package-db-tutorial.sh: cleanups
* docs/tutorial/gtk-tut.sgml: new content for the
ItemFactory section. Originally from Robert Cleaver Ancell.
2002-08-25 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Don't include <winsock.h> on Cygwin (#91654,
......
Mon Aug 26 12:21:16 BST 2002 Tony Gale <gale@gtk.org>
* docs/tutorial/package-db-tutorial.sh: cleanups
* docs/tutorial/gtk-tut.sgml: new content for the
ItemFactory section. Originally from Robert Cleaver Ancell.
2002-08-25 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Don't include <winsock.h> on Cygwin (#91654,
......
Mon Aug 26 12:21:16 BST 2002 Tony Gale <gale@gtk.org>
* docs/tutorial/package-db-tutorial.sh: cleanups
* docs/tutorial/gtk-tut.sgml: new content for the
ItemFactory section. Originally from Robert Cleaver Ancell.
2002-08-25 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Don't include <winsock.h> on Cygwin (#91654,
......
Mon Aug 26 12:21:16 BST 2002 Tony Gale <gale@gtk.org>
* docs/tutorial/package-db-tutorial.sh: cleanups
* docs/tutorial/gtk-tut.sgml: new content for the
ItemFactory section. Originally from Robert Cleaver Ancell.
2002-08-25 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Don't include <winsock.h> on Cygwin (#91654,
......
This diff is collapsed.
......@@ -10,6 +10,7 @@
TARGET=`pwd`/gtk-tut.sgml
IMAGES="`pwd`/images"
IMAGESDIR="images"
EXAMPLES=`pwd`/../../examples
PATH=`pwd`:$PATH
......@@ -46,7 +47,7 @@ if [ ! -d sgml ]; then
mkdir sgml
fi
(cd sgml ; cp $TARGET . ; cp -R $IMAGES . ; rm -rf images/CVS)
(cd sgml ; cp $TARGET . ; cp -R $IMAGES . ; rm -rf $IMAGESDIR/CVS)
echo "done"
# HTML Format
......@@ -59,8 +60,8 @@ if [ ! -d html ]; then
mkdir html
fi
(db2html gtk-tut.sgml ; mv gtk-tut/* html ; cp -R $IMAGES html ; rm -rf gtk-tut) > /dev/null
(cd html ; ln -s book1.html index.html ; rm -rf images/CVS)
(db2html gtk-tut.sgml ; mv gtk-tut/* html ; cp -R $IMAGES html ; rm html/$IMAGESDIR/*.eps ; rm -rf gtk-tut) > /dev/null
(cd html ; ln -s book1.html index.html ; rm -rf $IMAGESDIR/CVS)
echo "done"
# PS, PDF and DVI Format
......@@ -81,29 +82,12 @@ if [ ! -d pdf ]; then
mkdir pdf
fi
#sed 's/gtk_tut_packbox1.jpg/gtk_tut_packbox1.eps/ ; s/gtk_tut_packbox2.jpg/gtk_tut_packbox2.eps/ ; s/gtk_tut_table.jpg/gtk_tut_table.eps/' gtk-tut.sgml > ps/gtk-tut.sgml
sed "s/images\/\(.*\)\.png/images\/\1.eps/g" gtk-tut.sgml > ps/gtk-tut.sgml
cp -R ../images ps
cp -R $IMAGES ps
(cd ps ; db2dvi gtk-tut.sgml ; dvips gtk-tut.dvi -o gtk-tut.ps ; dvipdf gtk-tut.dvi ../pdf/gtk-tut.pdf) > /dev/null 2>&1
#sed 's/gtk_tut_packbox1.jpg/gtk_tut_packbox1.eps/ ; s/gtk_tut_packbox2.jpg/gtk_tut_packbox2.eps/ ; s/gtk_tut_table.jpg/gtk_tut_table.eps/' gtk-tut.sgml > ps/gtk-tut.sgml
#sed "s/images\/\(.*\)\.png/images\/\1.eps/g" gtk-tut.sgml > ps/gtk-tut.sgml
#cp -R images ps
(cd ps ; rm gtk-tut.aux gtk-tut.log gtk-tut.sgml gtk-tut.tex ; rm -Rf images) > /dev/null 2>&1
(cd ps ; rm gtk-tut.aux gtk-tut.log gtk-tut.sgml gtk-tut.tex ; rm -Rf $IMAGESDIR) > /dev/null 2>&1
echo "done"
# PDF Format
#echo -n "Formatting into PDF.... "
#if [ ! -d pdf ]; then
# if [ -e pdf ]; then
# echo "ERROR: pdf is not a directory"
# exit
# fi
# mkdir pdf
#fi
#(db2pdf gtk-tut.sgml ; mv gtk-tut.pdf pdf) > /dev/null
#echo "done"
# RTF Format
echo -n "Formatting into RTF.... "
if [ ! -d rtf ]; then
......@@ -115,7 +99,7 @@ if [ ! -d rtf ]; then
fi
(db2rtf gtk-tut.sgml ; mv gtk-tut.rtf rtf) > /dev/null
cp -R $IMAGES rtf
(cd rtf ; cp -R $IMAGES . ; rm -f $IMAGESDIR/*.eps ; rm -rf $IMAGESDIR/CVS)
echo "done"
# Copy examples
......@@ -125,7 +109,7 @@ cp -R $EXAMPLES .
echo "done"
rm -f *
rm -rf images
rm -rf $IMAGESDIR
# Package it all up
echo -n "Creating packages.... "
......
......@@ -9,61 +9,56 @@ static void print_hello( GtkWidget *w,
g_message ("Hello, World!\n");
}
/* This is the GtkItemFactoryEntry structure used to generate new menus.
Item 1: The menu path. The letter after the underscore indicates an
accelerator key once the menu is open.
Item 2: The accelerator key for the entry
Item 3: The callback function.
Item 4: The callback action. This changes the parameters with
which the function is called. The default is 0.
Item 5: The item type, used to define what kind of an item it is.
Here are the possible values:
NULL -> "<Item>"
"" -> "<Item>"
"<Title>" -> create a title item
"<Item>" -> create a simple item
"<CheckItem>" -> create a check item
"<ToggleItem>" -> create a toggle item
"<RadioItem>" -> create a radio item
<path> -> path of a radio item to link against
"<Separator>" -> create a separator
"<Branch>" -> create an item to hold sub items (optional)
"<LastBranch>" -> create a right justified branch
*/
/* For the check button */
static void print_toggle(gpointer callback_data,
guint callback_action,
GtkWidget *menu_item)
{
g_message ("Check button state - %d\n",
GTK_CHECK_MENU_ITEM(menu_item)->active);
}
/* For the radio buttons */
static void print_selected(gpointer callback_data,
guint callback_action,
GtkWidget *menu_item)
{
if(GTK_CHECK_MENU_ITEM(menu_item)->active)
g_message("Radio button %d selected\n", callback_action);
}
/* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */
static GtkItemFactoryEntry menu_items[] = {
{ "/_File", NULL, NULL, 0, "<Branch>" },
{ "/File/_New", "<control>N", print_hello, 0, NULL },
{ "/File/_Open", "<control>O", print_hello, 0, NULL },
{ "/File/_Save", "<control>S", print_hello, 0, NULL },
{ "/File/Save _As", NULL, NULL, 0, NULL },
{ "/File/_New", "<control>N", print_hello, 0, "<Item>" },
{ "/File/_Open", "<control>O", print_hello, 0, "<Item>" },
{ "/File/_Save", "<control>S", print_hello, 0, "<Item>" },
{ "/File/Save _As", NULL, NULL, 0, "<Item>" },
{ "/File/sep1", NULL, NULL, 0, "<Separator>" },
{ "/File/Quit", "<control>Q", gtk_main_quit, 0, NULL },
{ "/File/Quit", "<control>Q", gtk_main_quit, 0, "<Item>" },
{ "/_Options", NULL, NULL, 0, "<Branch>" },
{ "/Options/Test", NULL, NULL, 0, NULL },
{ "/Options/tear", NULL, NULL, 0, "<Tearoff>" },
{ "/Options/Check", NULL, print_toggle, 1, "<CheckItem>" },
{ "/Options/sep", NULL, NULL, 0, "<Separator>" },
{ "/Options/Rad1", NULL, print_selected, 1, "<RadioItem>" },
{ "/Options/Rad2", NULL, print_selected, 2, "/Options/Rad1" },
{ "/Options/Rad3", NULL, print_selected, 3, "/Options/Rad1" },
{ "/_Help", NULL, NULL, 0, "<LastBranch>" },
{ "/_Help/About", NULL, NULL, 0, NULL },
{ "/_Help/About", NULL, NULL, 0, "<Item>" },
};
static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
void get_main_menu( GtkWidget *window,
GtkWidget **menubar )
/* Returns a menubar widget made from the above menu */
GtkWidget *get_menubar_menu( GtkWidget *window)
{
GtkItemFactory *item_factory;
GtkAccelGroup *accel_group;
gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
/* Make an accelerator group (shortcut keys) */
accel_group = gtk_accel_group_new ();
/* This function initializes the item factory.
Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
or GTK_TYPE_OPTION_MENU.
Param 2: The path of the menu.
Param 3: A pointer to a gtk_accel_group. The item factory sets up
the accelerator table while generating menus.
*/
/* Make an ItemFactory (that makes a menubar) */
item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
accel_group);
......@@ -75,39 +70,106 @@ void get_main_menu( GtkWidget *window,
/* Attach the new accelerator group to the window. */
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
if (menubar)
/* Finally, return the actual menu bar created by the item factory. */
*menubar = gtk_item_factory_get_widget (item_factory, "<main>");
return gtk_item_factory_get_widget (item_factory, "<main>");
}
/* Popup the menu when the popup button is pressed */
static gint popup_cb(GtkWidget *widget, GdkEvent *event, GtkWidget *menu)
{
GdkEventButton *bevent = (GdkEventButton *)event;
/* Only take button presses */
if(event->type != GDK_BUTTON_PRESS)
return FALSE;
/* Show the menu */
gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
NULL, NULL, bevent->button, bevent->time);
return TRUE;
}
/* Same as with get_menubar_menu() but just return a button with a signal to
call a popup menu */
GtkWidget *get_popup_menu(void)
{
GtkItemFactory *item_factory;
GtkWidget *button, *menu;
/* Same as before but don't bother with the accelerators */
item_factory = gtk_item_factory_new (GTK_TYPE_MENU, "<main>",
NULL);
gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);
menu = gtk_item_factory_get_widget(item_factory, "<main>");
/* Make a button to activate the popup menu */
button = gtk_button_new_with_label("Popup");
/* Make the menu popup when clicked */
g_signal_connect(G_OBJECT(button),
"event",
G_CALLBACK(popup_cb),
(gpointer) menu);
return button;
}
/* Same again but return an option menu */
GtkWidget *get_option_menu(void)
{
GtkItemFactory *item_factory;
GtkWidget *option_menu;
/* Same again, not bothering with the accelerators */
item_factory = gtk_item_factory_new (GTK_TYPE_OPTION_MENU, "<main>",
NULL);
gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);
option_menu = gtk_item_factory_get_widget(item_factory, "<main>");
return option_menu;
}
/* You have to start somewhere */
int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *main_vbox;
GtkWidget *menubar;
GtkWidget *menubar, *option_menu, *popup_button;
/* Initialize GTK */
gtk_init (&argc, &argv);
/* Make a window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit),
NULL);
gtk_window_set_title (GTK_WINDOW (window), "Item Factory");
gtk_widget_set_size_request (GTK_WIDGET (window), 300, 200);
gtk_window_set_title (GTK_WINDOW(window), "Item Factory");
gtk_widget_set_size_request (GTK_WIDGET(window), 300, 200);
/* Make a vbox to put the three menus in */
main_vbox = gtk_vbox_new (FALSE, 1);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 1);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
gtk_widget_show (main_vbox);
get_main_menu (window, &menubar);
/* Get the three types of menu */
/* Note: all three menus are separately created, so they are not the
same menu */
menubar = get_menubar_menu (window);
popup_button = get_popup_menu();
option_menu = get_option_menu();
/* Pack it all together */
gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, TRUE, 0);
gtk_widget_show (menubar);
gtk_box_pack_end (GTK_BOX (main_vbox), popup_button, FALSE, TRUE, 0);
gtk_box_pack_end (GTK_BOX (main_vbox), option_menu, FALSE, TRUE, 0);
gtk_widget_show (window);
/* Show the widgets */
gtk_widget_show_all (window);
/* Finished! */
gtk_main ();
return 0;
return(0);
}
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