|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="menubutton.c" xml:lang="pt-BR">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">MenuButton</title>
|
|
Packit |
1470ea |
<link type="guide" xref="c#buttons"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2013-07-01" status="review"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2013</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>A widget that shows a menu when clicked on</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Rafael Ferreira</mal:name>
|
|
Packit |
1470ea |
<mal:email>rafael.f.f1@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>MenuButton</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/menubutton.png"/>
|
|
Packit |
1470ea |
The GtkMenuButton widget is used to display a menu when clicked on. This menu can be provided either as a GtkMenu, or an abstract GMenuModel. The GtkMenuButton widget can hold any valid child widget. That is, it can hold almost any other standard GtkWidget. The most commonly used child is the provided GtkArrow.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<note>You need to be running GNOME 3.6 or later for the MenuButton to work. </note>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="section"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>Code used to generate this example</title>
|
|
Packit |
1470ea |
#include <gtk/gtk.h>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback function for the undo action */
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
about_callback (GSimpleAction *simple,
|
|
Packit |
1470ea |
GVariant *parameter,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
g_print ("You clicked \"About\"\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
activate (GtkApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GMenu *submenu;
|
|
Packit |
1470ea |
GtkWidget *grid;
|
|
Packit |
1470ea |
GMenu *menumodel;
|
|
Packit |
1470ea |
GtkWidget *window;
|
|
Packit |
1470ea |
GtkWidget *menubutton;
|
|
Packit |
1470ea |
GSimpleAction *about_action;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
window = gtk_application_window_new (app);
|
|
Packit |
1470ea |
grid = gtk_grid_new ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_window_set_title (GTK_WINDOW (window), "MenuButton Example");
|
|
Packit |
1470ea |
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
menubutton = gtk_menu_button_new ();
|
|
Packit |
1470ea |
gtk_widget_set_size_request (menubutton, 80, 35);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_grid_attach (GTK_GRID (grid), menubutton, 0, 0, 1, 1);
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (window), grid);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
menumodel = g_menu_new ();
|
|
Packit |
1470ea |
g_menu_append (menumodel, "New", "app.new");
|
|
Packit |
1470ea |
g_menu_append (menumodel, "About", "win.about");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
submenu = g_menu_new ();
|
|
Packit |
1470ea |
g_menu_append_submenu (menumodel, "Other", G_MENU_MODEL (submenu));
|
|
Packit |
1470ea |
g_menu_append (submenu, "Quit", "app.quit");
|
|
Packit |
1470ea |
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menubutton), G_MENU_MODEL (menumodel));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
about_action = g_simple_action_new ("about", NULL);
|
|
Packit |
1470ea |
g_signal_connect (about_action, "activate", G_CALLBACK (about_callback),
|
|
Packit |
1470ea |
GTK_WINDOW (window));
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (about_action));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_widget_show_all (window);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
new_callback (GSimpleAction *simple,
|
|
Packit |
1470ea |
GVariant *parameter,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
g_print ("You clicked \"New\"\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
quit_callback (GSimpleAction *simple,
|
|
Packit |
1470ea |
GVariant *parameter,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GApplication *application = user_data;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
g_application_quit (application);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
startup (GApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GSimpleAction *new_action;
|
|
Packit |
1470ea |
GSimpleAction *quit_action;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
new_action = g_simple_action_new ("new", NULL);
|
|
Packit |
1470ea |
g_signal_connect (new_action, "activate", G_CALLBACK (new_callback), app);
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (new_action));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
quit_action = g_simple_action_new ("quit", NULL);
|
|
Packit |
1470ea |
g_signal_connect (quit_action, "activate", G_CALLBACK (quit_callback), app);
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (quit_action));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
int
|
|
Packit |
1470ea |
main (int argc, char **argv)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkApplication *app;
|
|
Packit |
1470ea |
int status;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
|
Packit |
1470ea |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
|
Packit |
1470ea |
g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
|
|
Packit |
1470ea |
status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
Packit |
1470ea |
g_object_unref (app);
|
|
Packit |
1470ea |
return status;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="references">
|
|
Packit |
1470ea |
<title>API References</title>
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkMenuButton.html">GtkMenuButton</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkMenu.html">GtkMenu</link> </item>
|
|
Packit |
1470ea |
<item><link href="https://developer.gnome.org/gio/unstable/GMenuModel.html">GMenuModel</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkArrow.html">GtkArrow</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|