GTK+ 2 Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces | Properties | Style Properties | Signals |
#include <gtk/gtk.h> struct GtkMenuItem; GtkWidget * gtk_menu_item_new (void
); GtkWidget * gtk_menu_item_new_with_label (const gchar *label
); GtkWidget * gtk_menu_item_new_with_mnemonic (const gchar *label
); void gtk_menu_item_set_right_justified (GtkMenuItem *menu_item
,gboolean right_justified
); gboolean gtk_menu_item_get_right_justified (GtkMenuItem *menu_item
); const gchar * gtk_menu_item_get_label (GtkMenuItem *menu_item
); void gtk_menu_item_set_label (GtkMenuItem *menu_item
,const gchar *label
); gboolean gtk_menu_item_get_use_underline (GtkMenuItem *menu_item
); void gtk_menu_item_set_use_underline (GtkMenuItem *menu_item
,gboolean setting
); void gtk_menu_item_set_submenu (GtkMenuItem *menu_item
,GtkWidget *submenu
); GtkWidget * gtk_menu_item_get_submenu (GtkMenuItem *menu_item
); void gtk_menu_item_remove_submenu (GtkMenuItem *menu_item
); void gtk_menu_item_set_accel_path (GtkMenuItem *menu_item
,const gchar *accel_path
); const gchar * gtk_menu_item_get_accel_path (GtkMenuItem *menu_item
); void gtk_menu_item_select (GtkMenuItem *menu_item
); void gtk_menu_item_deselect (GtkMenuItem *menu_item
); void gtk_menu_item_activate (GtkMenuItem *menu_item
); void gtk_menu_item_toggle_size_request (GtkMenuItem *menu_item
,gint *requisition
); void gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item
,gint allocation
); #define gtk_menu_item_right_justify (menu_item)
GObject +----GInitiallyUnowned +----GtkObject +----GtkWidget +----GtkContainer +----GtkBin +----GtkItem +----GtkMenuItem +----GtkCheckMenuItem +----GtkImageMenuItem +----GtkSeparatorMenuItem +----GtkTearoffMenuItem
"accel-path" gchar* : Read / Write "label" gchar* : Read / Write "right-justified" gboolean : Read / Write "submenu" GtkMenu* : Read / Write "use-underline" gboolean : Read / Write
"arrow-scaling" gfloat : Read "arrow-spacing" gint : Read "horizontal-padding" gint : Read "selected-shadow-type" GtkShadowType : Read "toggle-spacing" gint : Read "width-chars" gint : Read
"activate" :Action
"activate-item" :Run First
"toggle-size-allocate" :Run First
"toggle-size-request" :Run First
The GtkMenuItem widget and the derived widgets are the only valid childs for menus. Their function is to correctly handle highlighting, alignment, events and submenus.
As it derives from GtkBin it can hold any valid child widget, altough only a few are really useful.
The GtkMenuItem implementation of the GtkBuildable interface supports adding a submenu by specifying "submenu" as the "type" attribute of a <child> element.
Example 33. A UI definition fragment with submenus
1 2 3 4 5 |
<object class="GtkMenuItem"> <child type="submenu"> <object class="GtkMenu"/> </child> </object> |
GtkWidget * gtk_menu_item_new (void
);
Creates a new GtkMenuItem.
Returns : |
the newly created GtkMenuItem |
GtkWidget * gtk_menu_item_new_with_label (const gchar *label
);
Creates a new GtkMenuItem whose child is a GtkLabel.
|
the text for the label |
Returns : |
the newly created GtkMenuItem |
GtkWidget * gtk_menu_item_new_with_mnemonic (const gchar *label
);
Creates a new GtkMenuItem containing a label. The label
will be created using gtk_label_new_with_mnemonic()
, so underscores
in label
indicate the mnemonic for the menu item.
|
The text of the button, with an underscore in front of the mnemonic character |
Returns : |
a new GtkMenuItem |
void gtk_menu_item_set_right_justified (GtkMenuItem *menu_item
,gboolean right_justified
);
Sets whether the menu item appears justified at the right side of a menu bar. This was traditionally done for "Help" menu items, but is now considered a bad idea. (If the widget layout is reversed for a right-to-left language like Hebrew or Arabic, right-justified-menu-items appear at the left.)
|
a GtkMenuItem. |
|
if TRUE the menu item will appear at the
far right if added to a menu bar. |
gboolean gtk_menu_item_get_right_justified (GtkMenuItem *menu_item
);
Gets whether the menu item appears justified at the right side of the menu bar.
|
a GtkMenuItem |
Returns : |
TRUE if the menu item will appear at the
far right if added to a menu bar. |
const gchar * gtk_menu_item_get_label (GtkMenuItem *menu_item
);
Sets text
on the menu_item
label
|
a GtkMenuItem |
Returns : |
The text in the menu_item label. This is the internal
string used by the label, and must not be modified. |
Since 2.16
void gtk_menu_item_set_label (GtkMenuItem *menu_item
,const gchar *label
);
Sets text
on the menu_item
label
|
a GtkMenuItem |
|
the text you want to set |
Since 2.16
gboolean gtk_menu_item_get_use_underline (GtkMenuItem *menu_item
);
Checks if an underline in the text indicates the next character should be used for the mnemonic accelerator key.
|
a GtkMenuItem |
Returns : |
TRUE if an embedded underline in the label indicates
the mnemonic accelerator key. |
Since 2.16
void gtk_menu_item_set_use_underline (GtkMenuItem *menu_item
,gboolean setting
);
If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
|
a GtkMenuItem |
|
TRUE if underlines in the text indicate mnemonics |
Since 2.16
void gtk_menu_item_set_submenu (GtkMenuItem *menu_item
,GtkWidget *submenu
);
Sets or replaces the menu item's submenu, or removes it when a NULL
submenu is passed.
|
a GtkMenuItem |
|
the submenu, or NULL . [allow-none]
|
GtkWidget * gtk_menu_item_get_submenu (GtkMenuItem *menu_item
);
Gets the submenu underneath this menu item, if any.
See gtk_menu_item_set_submenu()
.
|
a GtkMenuItem |
Returns : |
submenu for this menu item, or NULL if none. [transfer none]
|
void gtk_menu_item_remove_submenu (GtkMenuItem *menu_item
);
gtk_menu_item_remove_submenu
has been deprecated since version 2.12 and should not be used in newly-written code. gtk_menu_item_remove_submenu()
is deprecated and
should not be used in newly written code. Use
gtk_menu_item_set_submenu()
instead.
Removes the widget's submenu.
|
a GtkMenuItem |
void gtk_menu_item_set_accel_path (GtkMenuItem *menu_item
,const gchar *accel_path
);
Set the accelerator path on menu_item
, through which runtime changes of the
menu item's accelerator caused by the user can be identified and saved to
persistant storage (see gtk_accel_map_save()
on this).
To setup a default accelerator for this menu item, call
gtk_accel_map_add_entry()
with the same accel_path
.
See also gtk_accel_map_add_entry()
on the specifics of accelerator paths,
and gtk_menu_set_accel_path()
for a more convenient variant of this function.
This function is basically a convenience wrapper that handles calling
gtk_widget_set_accel_path()
with the appropriate accelerator group for
the menu item.
Note that you do need to set an accelerator on the parent menu with
gtk_menu_set_accel_group()
for this to work.
Note that accel_path
string will be stored in a GQuark. Therefore, if you
pass a static string, you can save some memory by interning it first with
g_intern_static_string()
.
|
a valid GtkMenuItem |
|
accelerator path, corresponding to this menu item's
functionality, or NULL to unset the current path. [allow-none]
|
const gchar * gtk_menu_item_get_accel_path (GtkMenuItem *menu_item
);
Retrieve the accelerator path that was previously set on menu_item
.
See gtk_menu_item_set_accel_path()
for details.
|
a valid GtkMenuItem |
Returns : |
the accelerator path corresponding to this menu item's
functionality, or NULL if not set |
Since 2.14
void gtk_menu_item_select (GtkMenuItem *menu_item
);
Emits the "select" signal on the given item. Behaves exactly like gtk_item_select.
|
the menu item |
void gtk_menu_item_deselect (GtkMenuItem *menu_item
);
Emits the "deselect" signal on the given item. Behaves exactly like gtk_item_deselect.
|
the menu item |
void gtk_menu_item_activate (GtkMenuItem *menu_item
);
Emits the "activate" signal on the given item
|
the menu item |
void gtk_menu_item_toggle_size_request (GtkMenuItem *menu_item
,gint *requisition
);
Emits the "toggle_size_request" signal on the given item.
|
the menu item |
|
the requisition to use as signal data. |
void gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item
,gint allocation
);
Emits the "toggle_size_allocate" signal on the given item.
|
the menu item. |
|
the allocation to use as signal data. |
#define gtk_menu_item_right_justify(menu_item) gtk_menu_item_set_right_justified ((menu_item), TRUE)
gtk_menu_item_right_justify
is deprecated and should not be used in newly-written code.
Sets the menu item to be right-justified. Only useful for menu bars.
|
the menu item |
"accel-path"
property"accel-path" gchar* : Read / Write
Sets the accelerator path of the menu item, through which runtime changes of the menu item's accelerator caused by the user can be identified and saved to persistant storage.
Default value: NULL
Since 2.14
"label"
property"label" gchar* : Read / Write
The text for the child label.
Default value: ""
Since 2.16
"right-justified"
property"right-justified" gboolean : Read / Write
Sets whether the menu item appears justified at the right side of a menu bar.
Default value: FALSE
Since 2.14
"submenu"
property"submenu" GtkMenu* : Read / Write
The submenu attached to the menu item, or NULL if it has none.
Since 2.12
"arrow-scaling"
style property"arrow-scaling" gfloat : Read
Amount of space used up by arrow, relative to the menu item's font size.
Allowed values: [0,2]
Default value: 0.8
"arrow-spacing"
style property"arrow-spacing" gint : Read
Space between label and arrow.
Allowed values: >= 0
Default value: 10
"horizontal-padding"
style property"horizontal-padding" gint : Read
Padding to left and right of the menu item.
Allowed values: >= 0
Default value: 3
"selected-shadow-type"
style property"selected-shadow-type" GtkShadowType : Read
Shadow type when item is selected.
Default value: GTK_SHADOW_NONE
"toggle-spacing"
style property"toggle-spacing" gint : Read
Space between icon and label.
Allowed values: >= 0
Default value: 5
"width-chars"
style property"width-chars" gint : Read
The minimum desired width of the menu item in characters.
Allowed values: >= 0
Default value: 12
Since 2.14
"activate"
signalvoid user_function (GtkMenuItem *menuitem,
gpointer user_data) : Action
Emitted when the item is activated.
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"activate-item"
signalvoid user_function (GtkMenuItem *menuitem,
gpointer user_data) : Run First
Emitted when the item is activated, but also if the menu item has a submenu. For normal applications, the relevant signal is "activate".
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"toggle-size-allocate"
signalvoid user_function (GtkMenuItem *menuitem,
gint arg1,
gpointer user_data) : Run First
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"toggle-size-request"
signalvoid user_function (GtkMenuItem *menuitem,
gpointer arg1,
gpointer user_data) : Run First
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
for how to handle the child. |
|
is the abstract class for all sorts of items. |
|
is always the parent of GtkMenuItem. |