Commit 9fef2dc0 authored by Bastien Nocera's avatar Bastien Nocera

gtkmenubutton: Add menu button widget

As used in Totem and gnome-contacts. The widget
takes either a GtkMenu or a GMenuModel to construct
its menu, and can be given a parent widget to use to
position the drop-down (as used in GtkMenuToolButton).

https://bugzilla.gnome.org/show_bug.cgi?id=668013
parent ffe1e31a
......@@ -43,6 +43,7 @@ IGNORE_HFILES= \
gtkintl.h \
gtkkeyhash.h \
gtkmarshal.h \
gtkmenuprivate.h \
gtkmnemonichash.h \
gtkpathbar.h \
gtkplugprivate.h \
......
......@@ -118,6 +118,7 @@
<xi:include href="xml/gtkvolumebutton.xml" />
<xi:include href="xml/gtkswitch.xml" />
<xi:include href="xml/gtklockbutton.xml" />
<xi:include href="xml/gtkmenubutton.xml" />
</chapter>
<chapter id="NumericEntry">
......
......@@ -2124,6 +2124,31 @@ GtkMenuBarPrivate
gtk_menu_bar_get_type
</SECTION>
<SECTION>
<FILE>gtkmenubutton</FILE>
<TITLE>GtkMenuButton</TITLE>
GtkMenuButton
gtk_menu_button_new
gtk_menu_button_set_menu
gtk_menu_button_get_menu
gtk_menu_button_set_menu_model
gtk_menu_button_get_menu_model
gtk_menu_button_set_direction
gtk_menu_button_get_direction
gtk_menu_button_set_align_widget
gtk_menu_button_get_align_widget
<SUBSECTION Standard>
GTK_TYPE_MENU_BUTTON
GTK_MENU_BUTTON
GTK_MENU_BUTTON_CLASS
GTK_IS_MENU_BUTTON
GTK_IS_MENU_BUTTON_CLASS
GTK_MENU_BUTTON_GET_CLASS
<SUBSECTION Private>
GtkMenuButtonrPrivate
gtk_menu_button_get_type
</SECTION>
<SECTION>
<FILE>gtkmenuitem</FILE>
<TITLE>GtkMenuItem</TITLE>
......
......@@ -271,6 +271,7 @@ gtk_public_h_sources = \
gtkmain.h \
gtkmenu.h \
gtkmenubar.h \
gtkmenubutton.h \
gtkmenuitem.h \
gtkmenushell.h \
gtkmenutoolbutton.h \
......@@ -480,6 +481,7 @@ gtk_private_h_sources = \
gtkimcontextsimpleseqs.h \
gtkintl.h \
gtkkeyhash.h \
gtkmenubuttonprivate.h \
gtkmenuprivate.h \
gtkmenuitemprivate.h \
gtkmenushellprivate.h \
......@@ -733,6 +735,7 @@ gtk_base_c_sources = \
gtkmarshalers.c \
gtkmenu.c \
gtkmenubar.c \
gtkmenubutton.c \
gtkmenuitem.c \
gtkmenushell.c \
gtkmenutoolbutton.c \
......
......@@ -128,6 +128,7 @@
#include <gtk/gtkmain.h>
#include <gtk/gtkmenu.h>
#include <gtk/gtkmenubar.h>
#include <gtk/gtkmenubutton.h>
#include <gtk/gtkmenuitem.h>
#include <gtk/gtkmenushell.h>
#include <gtk/gtkmenutoolbutton.h>
......
......@@ -1549,6 +1549,16 @@ gtk_menu_bar_new
gtk_menu_bar_new_from_model
gtk_menu_bar_set_child_pack_direction
gtk_menu_bar_set_pack_direction
gtk_menu_button_get_type
gtk_menu_button_new
gtk_menu_button_get_align_widget
gtk_menu_button_get_direction
gtk_menu_button_get_menu
gtk_menu_button_get_menu_model
gtk_menu_button_set_align_widget
gtk_menu_button_set_direction
gtk_menu_button_set_menu
gtk_menu_button_set_menu_model
gtk_menu_detach
gtk_menu_direction_type_get_type
gtk_menu_get_accel_group
......
This diff is collapsed.
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2003 Ricardo Fernandez Pascual
* Copyright (C) 2004 Paolo Borelli
* Copyright (C) 2012 Bastien Nocera
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#ifndef __GTK_MENU_BUTTON_H__
#define __GTK_MENU_BUTTON_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GTK_TYPE_MENU_BUTTON (gtk_menu_button_get_type ())
#define GTK_MENU_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_MENU_BUTTON, GtkMenuButton))
#define GTK_MENU_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_MENU_BUTTON, GtkMenuButtonClass))
#define GTK_IS_MENU_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_MENU_BUTTON))
#define GTK_IS_MENU_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MENU_BUTTON))
#define GTK_MENU_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_MENU_BUTTON, GtkMenuButtonClass))
typedef struct _GtkMenuButton GtkMenuButton;
typedef struct _GtkMenuButtonClass GtkMenuButtonClass;
typedef struct _GtkMenuButtonPrivate GtkMenuButtonPrivate;
struct _GtkMenuButton
{
GtkToggleButton parent;
/*< private >*/
GtkMenuButtonPrivate *priv;
};
struct _GtkMenuButtonClass
{
GtkToggleButtonClass parent_class;
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
};
GDK_AVAILABLE_IN_3_6
GType gtk_menu_button_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_3_6
GtkWidget *gtk_menu_button_new (void);
GDK_AVAILABLE_IN_3_6
void gtk_menu_button_set_menu (GtkMenuButton *menu_button,
GtkWidget *menu);
GDK_AVAILABLE_IN_3_6
GtkMenu *gtk_menu_button_get_menu (GtkMenuButton *menu_button);
GDK_AVAILABLE_IN_3_6
void gtk_menu_button_set_direction (GtkMenuButton *menu_button,
GtkArrowType direction);
GDK_AVAILABLE_IN_3_6
GtkArrowType gtk_menu_button_get_direction (GtkMenuButton *menu_button);
GDK_AVAILABLE_IN_3_6
void gtk_menu_button_set_menu_model (GtkMenuButton *menu_button,
GMenuModel *menu_model);
GDK_AVAILABLE_IN_3_6
GMenuModel *gtk_menu_button_get_menu_model (GtkMenuButton *menu_button);
GDK_AVAILABLE_IN_3_6
void gtk_menu_button_set_align_widget (GtkMenuButton *menu_button,
GtkWidget *align_widget);
GDK_AVAILABLE_IN_3_6
GtkWidget *gtk_menu_button_get_align_widget (GtkMenuButton *menu_button);
G_END_DECLS
#endif /* __GTK_MENU_BUTTON_H__ */
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2003 Ricardo Fernandez Pascual
* Copyright (C) 2004 Paolo Borelli
* Copyright (C) 2012 Bastien Nocera
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_MENU_BUTTON_PRIVATE_H__
#define __GTK_MENU_BUTTON_PRIVATE_H__
#include <gtk/gtkmenubutton.h>
G_BEGIN_DECLS
typedef void (* GtkMenuButtonShowMenuCallback) (gpointer user_data);
void _gtk_menu_button_set_menu_with_func (GtkMenuButton *menu_button,
GtkWidget *menu,
GtkMenuButtonShowMenuCallback func,
gpointer user_data);
G_END_DECLS
#endif /* __GTK_MENU_BUTTON_PRIVATE_H__ */
......@@ -67,6 +67,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testkineticscrolling \
testlockbutton \
testmenubars \
testmenubutton \
testmountoperation \
testmultidisplay \
testmultiscreen \
......@@ -186,6 +187,7 @@ testimage_DEPENDENCIES = $(TEST_DEPS)
testkineticscrolling_DEPENDENCIES = $(TEST_DEPS)
testlockbutton_DEPENDENCIES = $(TEST_DEPS)
testmenubars_DEPENDENCIES = $(TEST_DEPS)
testmenubutton_DEPENDENCIES = $(TEST_DEPS)
testmountoperation_DEPENDENCIES = $(TEST_DEPS)
testmultidisplay_DEPENDENCIES = $(TEST_DEPS)
testmultiscreen_DEPENDENCIES = $(TEST_DEPS)
......@@ -305,6 +307,10 @@ testtoolbar_SOURCES = \
testtoolbar.c \
prop-editor.c
testmenubutton_SOURCES = \
testmenubutton.c \
prop-editor.c
testprint_SOURCES = \
testprint.c \
testprintfileoperation.h \
......
#include <gtk/gtk.h>
#include "prop-editor.h"
int main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *grid;
GtkWidget *entry;
GtkWidget *menu_widget;
guint i;
GMenu *menu;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_resize (GTK_WINDOW (window), 400, 300);
grid = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (window), grid);
/* Button next to entry */
entry = gtk_entry_new ();
gtk_grid_attach (GTK_GRID (grid),
entry,
0, 0,
1, 1);
button = gtk_menu_button_new ();
gtk_grid_attach (GTK_GRID (grid),
button,
1, 0,
1, 1);
/* Button with GtkMenu */
menu_widget = gtk_menu_new ();
for (i = 5; i > 0; i--) {
GtkWidget *item;
char *label;
label = g_strdup_printf ("Item %d", i);
item = gtk_menu_item_new_with_label (label);
g_free (label);
gtk_menu_attach (GTK_MENU (menu_widget),
item,
0, 1,
i - 1, i);
}
gtk_widget_show_all (menu_widget);
button = gtk_menu_button_new ();
gtk_menu_button_set_menu (GTK_MENU_BUTTON (button), menu_widget);
gtk_grid_attach (GTK_GRID (grid),
button,
1, 1,
1, 1);
gtk_widget_show (create_prop_editor (G_OBJECT (button), 0));
/* Button with GMenuModel */
menu = g_menu_new ();
for (i = 5; i > 0; i--) {
char *label;
label = g_strdup_printf ("Item %d", i);
g_menu_insert (menu, i - 1, label, NULL);
g_free (label);
}
button = gtk_menu_button_new ();
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (menu));
gtk_grid_attach (GTK_GRID (grid),
button,
1, 2,
1, 1);
gtk_widget_show_all (window);
gtk_main ();
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