Creating SubMenus
- From: "Nicolas Raitman" <new_world radar com ar>
- To: "gtk app" <gtk-app-devel-list gnome org>
- Subject: Creating SubMenus
- Date: Sat, 2 Dec 2000 15:41:36 -0300
I have been trying to do what I told you:
<---MenuBar
Edit <---Menu
Font <---SubMenu
Italics <---Italics
Bold <---Bold
Do you understand... I have done the following but I have many mistakes, I
mean, it does not work.. can you look at the code to see what is going wrong
please??
I put all the code just in case, but look at the functions to create menus
and what other thing should I add to create what I described above...
Thanks a lot,
Nicolas
#include <gtk/gtk.h>
#include <glib.h>
struct objetos
{
GtkWidget * windowmain;
GtkWidget * table;
GtkWidget * hbox;
GtkWidget * vbox;
GtkWidget * menubar;
GtkWidget * filemenu;
GtkWidget * filelabel;
GtkWidget * editmenu;
GtkWidget * editlabel;
GtkWidget * menuitem;
GtkWidget * fontmenu;
GtkWidget * fontlabel;
GtkWidget * fontitalics;
GtkWidget * toolbar;
GtkWidget * button;
GtkAccelGroup * accelgroup;
};
gint destroyapp(void)
{
gtk_main_quit();
return(FALSE);
}
GtkWidget * CreateWindow(GtkWidget * window, char * title, int sizex, int
sizey)
{
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), title);
gtk_container_border_width(GTK_CONTAINER(window), 10);
gtk_widget_set_usize(window, sizex, sizey);
gtk_signal_connect(GTK_OBJECT(window), "delete_event",
GTK_SIGNAL_FUNC(destroyapp), NULL);
return window;
}
GtkWidget * CreateTable(GtkWidget * table, int filas, int columnas)
{
table = gtk_table_new(filas, columnas, TRUE);
return table;
}
GtkWidget * CreateHBox(GtkWidget * hbox, int spacing)
{
hbox = gtk_hbox_new(FALSE, spacing);
return hbox;
}
GtkWidget * CreateVBox(GtkWidget * vbox, int spacing)
{
vbox = gtk_vbox_new(FALSE, spacing);
return vbox;
}
void AddBoxToTable(GtkWidget * table, GtkWidget * box, int left, int right,
int top, int bottom)
{
gtk_table_attach(GTK_TABLE(table), box, left, right, top, bottom,
GTK_FILL, GTK_FILL, 0, 0);
}
GtkWidget * CreateButton(GtkWidget * button, char * label)
{
button = gtk_button_new_with_label(label);
return button;
}
GtkWidget * CreateListBox(GtkWidget * listbox, int selmult)
{
listbox = gtk_list_new();
if (selmult)
gtk_list_set_selection_mode(GTK_LIST(listbox), GTK_SELECTION_MULTIPLE);
return listbox;
}
void CreateAndAddItemToListBox(GtkWidget * listbox, char * text)
{
GtkWidget * item;
item = gtk_list_item_new_with_label(text);
gtk_container_add(GTK_CONTAINER(listbox), item);
gtk_widget_show(item);
}
void AddWidgetToBox(GtkWidget * box, GtkWidget * widget)
{
gtk_box_pack_start(GTK_BOX(box), widget, TRUE, TRUE, 5);
gtk_widget_show(widget);
}
GtkWidget * CreateMenuBar(GtkWidget * menubar)
{
menubar = gtk_menu_bar_new();
gtk_widget_show(menubar);
return menubar;
}
GtkWidget * CreateRootMenu(GtkWidget * rootmenu)
{
rootmenu = gtk_menu_new();
return rootmenu;
}
GtkWidget * CreateRootMenuLabel(GtkWidget * rootmenulabel, char * label)
{
rootmenulabel = gtk_menu_item_new_with_label(label);
gtk_widget_show(rootmenulabel);
return rootmenulabel;
}
void AddMenuToMenuBar(GtkWidget * menu, GtkWidget * rootmenu, GtkWidget *
menubar)
{
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), rootmenu);
gtk_menu_bar_append(GTK_MENU_BAR(menubar), menu);
}
void AddToolTips(GtkWidget * widget, char * text)
{
GtkTooltips * tooltips;
tooltips = gtk_tooltips_new();
gtk_tooltips_set_tip(tooltips, widget, text, NULL);
}
GtkAccelGroup * CreateAccelGroup (GtkWidget * mainwindow)
{
GtkAccelGroup * accel_group;
accel_group = gtk_accel_group_new();
gtk_accel_group_attach(accel_group, GTK_OBJECT(mainwindow));
return accel_group;
}
GtkWidget * CreateMenuItem( GtkWidget * menuitem,
GtkWidget * menu,
GtkAccelGroup * accel_group,
char * accel,
char * name,
char * tip,
GtkSignalFunc func,
gpointer data)
{
GtkTooltips * tooltips;
if (name && strlen(name))
{
menuitem = gtk_menu_item_new_with_label(name);
gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(func),
data);
} else {
/* crear un separador */
menuitem = gtk_menu_item_new();
}
gtk_menu_append(GTK_MENU(menu), menuitem);
gtk_widget_show(menuitem);
if (accel && strlen(accel))
{
gtk_widget_add_accelerator(menuitem,
"activate",
accel_group,
accel[1],
GDK_CONTROL_MASK,
GTK_ACCEL_VISIBLE);
}
if (tip && strlen(tip))
{
tooltips = gtk_tooltips_new();
gtk_tooltips_set_tip(tooltips, menuitem, tip, NULL);
}
return menuitem;
}
GtkWidget * CreateToolBar(GtkWidget * toolbar)
{
toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_TEXT);
return toolbar;
}
void test (GtkWidget * widget, char * texto)
{
g_print("Texto: %s\n", texto);
}
void CreateButtonOnToolbar(GtkWidget * toolbar,
int type,
GtkWidget * widget,
char * texto,
char * tooltip,
char * tooltip_private,
GtkWidget * icon,
GtkSignalFunc callback,
gpointer data)
{
gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
type,
NULL,
texto,
tooltip,
tooltip_private,
widget,
GTK_SIGNAL_FUNC(callback),
data);
}
int main (int argc, char * argv [])
{
struct objetos * widget;
gtk_init(&argc, &argv);
widget = (struct objetos *) malloc (sizeof(struct objetos));
widget->windowmain = CreateWindow(widget->windowmain, "Menu Test", 360,
260);
widget->table = CreateTable(widget->table, 5, 5);
widget->vbox = CreateVBox(widget->vbox, 5);
widget->menubar = CreateMenuBar(widget->menubar);
AddWidgetToBox(widget->vbox, widget->menubar);
widget->toolbar = CreateToolBar(widget->toolbar);
AddWidgetToBox(widget->vbox, widget->toolbar);
CreateButtonOnToolbar(widget->toolbar,
GTK_TOOLBAR_CHILD_BUTTON,
NULL,
"Exit",
"Just exit the program",
NULL,
NULL,
test,
"exit button on toolbar");
widget->accelgroup = CreateAccelGroup(widget->windowmain);
widget->filemenu = CreateRootMenu(widget->filemenu);
widget->filelabel = CreateRootMenuLabel(widget->filelabel, "File");
widget->menuitem = CreateMenuItem(widget->menuitem,
widget->filemenu,
widget->accelgroup,
"^N",
"New",
"Creates a new file",
test,
"new");
widget->menuitem = CreateMenuItem(widget->menuitem,
widget->filemenu,
widget->accelgroup,
"^S",
"Save",
"Save the current file",
test,
"save");
widget->menuitem = CreateMenuItem(widget->menuitem,
widget->filemenu,
widget->accelgroup,
"",
"",
"",
NULL,
NULL);
widget->menuitem = CreateMenuItem(widget->menuitem,
widget->filemenu,
widget->accelgroup,
"^E",
"Exit",
"What is more descriptive than EXIT?",
test,
"exiting...");
widget->editmenu = CreateRootMenu(widget->editmenu);
widget->editlabel = CreateRootMenuLabel(widget->editlabel, "Edit");
widget->fontlabel = CreateRootMenuLabel(widget->fontlabel, "Font");
widget->fontmenu = CreateRootMenu(widget->fontmenu);
widget->fontitalics = CreateMenuItem(widget->fontitalics,
widget->fontmenu,
NULL,
"",
"Italics",
"",
NULL,
NULL);
AddMenuToMenuBar(widget->filelabel, widget->filemenu, widget->menubar);
AddMenuToMenuBar(widget->editlabel, widget->editmenu, widget->menubar);
AddBoxToTable(widget->table, widget->vbox, 0, 4, 0, 4);
gtk_widget_show(widget->table);
gtk_widget_show(widget->vbox);
gtk_container_add(GTK_CONTAINER(widget->windowmain), widget->table);
gtk_widget_show(widget->windowmain);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]