Index

Package: Menu

Description

package Gtk.Menu is

This widget implements a drop-down menu.

This is basically a simple box that contains a series of Gtk_Menu_Item widgets, on which the user can click to perform actions.

Such a menu is usually part of a Gtk_Menu_Bar (at the top of the window), or activated by clicking on an item in another Gtk_Menu.

See Gtk.Option_Menu for another way of displaying menus.

All the menus in GtkAda can be "Tear off" menus, i.e you can detach them from their parent (either a menu bar or another menu) to keep them visible on the screen at all times).

It is worth noting that by default, the user of your application will be able to dynamically modify the shortcuts associated with each menu item.

For instance, selecting a menu item and pressing a key will assign this new shortcut to the item, possibly removing the shortcut from any other item it was associated with.

Note that pressing <backspace> will simply remove the shortcut.

This default behavior, somewhat unexpected, can be canceled.

There are two ways to control this behavior: you can lock a specific menu item by calling Gtk.Widget.Lock_Accelerators on it. But you can also lock all the menu items at once by calling Gtk.Accel_Group.Lock for all the accelerator groups that were used (the GUI builder gate generally creates a single one), as well as on the group returned by Gtk.Accel_Group.Get_Default, which is the one used for items that don't initially have a shortcut.

Binding from C File version 2.16.6

<testgtk>create_menu.adb</testgtk>

Packages

User_Menu_Popup (generic)

Classes

Gtk_Menu_Record

type Gtk_Menu_Record is new
     Gtk.Menu_Shell.Gtk_Menu_Shell_Record with private;

Ancestors:

Primitive operations:

Attach_To_Widget
Get_Accel_Group
Get_Accel_Path
Get_Attach_Widget
Get_Tearoff_State
Glib.Object.Deallocate (Inherited)
Glib.Object.Get_Type (Inherited)
Glib.Object.Notify (Inherited)
Glib.Object.Ref (Inherited)
Glib.Object.Ref_Sink (Inherited)
Glib.Object.Unref (Inherited)
Gtk.Container.Add (Inherited)
Gtk.Container.Check_Resize (Inherited)
Gtk.Container.Child_Get_Property (Inherited)
Gtk.Container.Child_Set_Property (Inherited)
Gtk.Container.Child_Type (Inherited)
Gtk.Container.Forall (Inherited)
Gtk.Container.Foreach (Inherited)
Gtk.Container.Get_Border_Width (Inherited)
Gtk.Container.Get_Children (Inherited)
Gtk.Container.Get_Focus_Chain (Inherited)
Gtk.Container.Get_Focus_Child (Inherited)
Gtk.Container.Get_Focus_Hadjustment (Inherited)
Gtk.Container.Get_Focus_Vadjustment (Inherited)
Gtk.Container.Get_Resize_Mode (Inherited)
Gtk.Container.Propagate_Expose (Inherited)
Gtk.Container.Remove (Inherited)
Gtk.Container.Resize_Children (Inherited)
Gtk.Container.Set_Border_Width (Inherited)
Gtk.Container.Set_Focus_Chain (Inherited)
Gtk.Container.Set_Focus_Child (Inherited)
Gtk.Container.Set_Focus_Hadjustment (Inherited)
Gtk.Container.Set_Focus_Vadjustment (Inherited)
Gtk.Container.Set_Reallocate_Redraws (Inherited)
Gtk.Container.Set_Resize_Mode (Inherited)
Gtk.Container.Unset_Focus_Chain (Inherited)
Gtk.Menu_Shell.Activate_Item (Inherited)
Gtk.Menu_Shell.Append (Inherited)
Gtk.Menu_Shell.Cancel (Inherited)
Gtk.Menu_Shell.Deactivate (Inherited)
Gtk.Menu_Shell.Deselect (Inherited)
Gtk.Menu_Shell.Get_Take_Focus (Inherited)
Gtk.Menu_Shell.Insert (Inherited)
Gtk.Menu_Shell.Prepend (Inherited)
Gtk.Menu_Shell.Select_First (Inherited)
Gtk.Menu_Shell.Select_Item (Inherited)
Gtk.Menu_Shell.Set_Take_Focus (Inherited)
Gtk.Widget.Activate (Inherited)
Gtk.Widget.Add_Accelerator (Inherited)
Gtk.Widget.Add_Events (Inherited)
Gtk.Widget.Add_Mnemonic_Label (Inherited)
Gtk.Widget.Can_Activate_Accel (Inherited)
Gtk.Widget.Child_Notify (Inherited)
Gtk.Widget.Class_Path (Inherited)
Gtk.Widget.Class_Path_Reversed (Inherited)
Gtk.Widget.Create_Pango_Context (Inherited)
Gtk.Widget.Create_Pango_Layout (Inherited)
Gtk.Widget.Destroy (Inherited)
Gtk.Widget.Draw (Inherited)
Gtk.Widget.Ensure_Style (Inherited)
Gtk.Widget.Error_Bell (Inherited)
Gtk.Widget.Flag_Is_Set (Inherited)
Gtk.Widget.Flags (Inherited)
Gtk.Widget.Freeze_Child_Notify (Inherited)
Gtk.Widget.Get_Allocation_Height (Inherited)
Gtk.Widget.Get_Allocation_Width (Inherited)
Gtk.Widget.Get_Allocation_X (Inherited)
Gtk.Widget.Get_Allocation_Y (Inherited)
Gtk.Widget.Get_Ancestor (Inherited)
Gtk.Widget.Get_Child_Requisition (Inherited)
Gtk.Widget.Get_Child_Visible (Inherited)
Gtk.Widget.Get_Colormap (Inherited)
Gtk.Widget.Get_Composite_Name (Inherited)
Gtk.Widget.Get_Direction (Inherited)
Gtk.Widget.Get_Events (Inherited)
Gtk.Widget.Get_Extension_Events (Inherited)
Gtk.Widget.Get_Has_Tooltip (Inherited)
Gtk.Widget.Get_Name (Inherited)
Gtk.Widget.Get_No_Show_All (Inherited)
Gtk.Widget.Get_Pango_Context (Inherited)
Gtk.Widget.Get_Parent (Inherited)
Gtk.Widget.Get_Parent_Window (Inherited)
Gtk.Widget.Get_Pointer (Inherited)
Gtk.Widget.Get_Root_Window (Inherited)
Gtk.Widget.Get_Size_Request (Inherited)
Gtk.Widget.Get_Snapshot (Inherited)
Gtk.Widget.Get_State (Inherited)
Gtk.Widget.Get_Style (Inherited)
Gtk.Widget.Get_Tooltip_Markup (Inherited)
Gtk.Widget.Get_Tooltip_Text (Inherited)
Gtk.Widget.Get_Tooltip_Window (Inherited)
Gtk.Widget.Get_Toplevel (Inherited)
Gtk.Widget.Get_Visual (Inherited)
Gtk.Widget.Get_Window (Inherited)
Gtk.Widget.Grab_Default (Inherited)
Gtk.Widget.Grab_Focus (Inherited)
Gtk.Widget.Has_Screen (Inherited)
Gtk.Widget.Hide (Inherited)
Gtk.Widget.Hide_All (Inherited)
Gtk.Widget.Input_Shape_Combine_Mask (Inherited)
Gtk.Widget.Intersect (Inherited)
Gtk.Widget.Is_Ancestor (Inherited)
Gtk.Widget.Is_Composited (Inherited)
Gtk.Widget.Is_Focus (Inherited)
Gtk.Widget.Keynav_Failed (Inherited)
Gtk.Widget.List_Mnemonic_Labels (Inherited)
Gtk.Widget.Map (Inherited)
Gtk.Widget.Mnemonic_Activate (Inherited)
Gtk.Widget.Modify_Base (Inherited)
Gtk.Widget.Modify_Bg (Inherited)
Gtk.Widget.Modify_Cursor (Inherited)
Gtk.Widget.Modify_Fg (Inherited)
Gtk.Widget.Modify_Font (Inherited)
Gtk.Widget.Modify_Text (Inherited)
Gtk.Widget.Path (Inherited)
Gtk.Widget.Path_Reversed (Inherited)
Gtk.Widget.Queue_Clear (Inherited)
Gtk.Widget.Queue_Clear_Area (Inherited)
Gtk.Widget.Queue_Draw (Inherited)
Gtk.Widget.Queue_Draw_Area (Inherited)
Gtk.Widget.Queue_Resize (Inherited)
Gtk.Widget.Queue_Resize_No_Redraw (Inherited)
Gtk.Widget.Realize (Inherited)
Gtk.Widget.Region_Intersect (Inherited)
Gtk.Widget.Remove_Accelerator (Inherited)
Gtk.Widget.Remove_Mnemonic_Label (Inherited)
Gtk.Widget.Render_Icon (Inherited)
Gtk.Widget.Reparent (Inherited)
Gtk.Widget.Reset_Rc_Styles (Inherited)
Gtk.Widget.Reset_Shapes (Inherited)
Gtk.Widget.Restore_Default_Style (Inherited)
Gtk.Widget.Send_Expose (Inherited)
Gtk.Widget.Set_Accel_Path (Inherited)
Gtk.Widget.Set_App_Paintable (Inherited)
Gtk.Widget.Set_Child_Visible (Inherited)
Gtk.Widget.Set_Colormap (Inherited)
Gtk.Widget.Set_Composite_Name (Inherited)
Gtk.Widget.Set_Direction (Inherited)
Gtk.Widget.Set_Double_Buffered (Inherited)
Gtk.Widget.Set_Events (Inherited)
Gtk.Widget.Set_Extension_Events (Inherited)
Gtk.Widget.Set_Flags (Inherited)
Gtk.Widget.Set_Has_Tooltip (Inherited)
Gtk.Widget.Set_Name (Inherited)
Gtk.Widget.Set_No_Show_All (Inherited)
Gtk.Widget.Set_Parent (Inherited)
Gtk.Widget.Set_Parent_Window (Inherited)
Gtk.Widget.Set_Redraw_On_Allocate (Inherited)
Gtk.Widget.Set_Scroll_Adjustments (Inherited)
Gtk.Widget.Set_Sensitive (Inherited)
Gtk.Widget.Set_Size_Request (Inherited)
Gtk.Widget.Set_State (Inherited)
Gtk.Widget.Set_Style (Inherited)
Gtk.Widget.Set_Tooltip_Markup (Inherited)
Gtk.Widget.Set_Tooltip_Text (Inherited)
Gtk.Widget.Set_Tooltip_Window (Inherited)
Gtk.Widget.Set_UPosition (Inherited)
Gtk.Widget.Set_USize (Inherited)
Gtk.Widget.Set_Window (Inherited)
Gtk.Widget.Shape_Combine_Mask (Inherited)
Gtk.Widget.Show (Inherited)
Gtk.Widget.Show_All (Inherited)
Gtk.Widget.Show_Now (Inherited)
Gtk.Widget.Size_Allocate (Inherited)
Gtk.Widget.Size_Request (Inherited)
Gtk.Widget.Style_Get_Property (Inherited)
Gtk.Widget.Thaw_Child_Notify (Inherited)
Gtk.Widget.Trigger_Tooltip_Query (Inherited)
Gtk.Widget.Unmap (Inherited)
Gtk.Widget.Unrealize (Inherited)
Gtk.Widget.Unset_Flags (Inherited)
Reorder_Child
Set_Accel_Group
Set_Accel_Path
Set_Tearoff_State

Types

Gtk_Menu

type Gtk_Menu is access all Gtk_Menu_Record'Class;

Gtk_Menu_Detach_Func

type Gtk_Menu_Detach_Func is access procedure
     (Attach_Widget : access Gtk.Widget.Gtk_Widget_Record'Class;
      Menu          : access Gtk_Menu_Record'Class);

Gtk_Menu_Position_Func

type Gtk_Menu_Position_Func is access procedure
     (Menu : access Gtk_Menu_Record'Class;
      X    : out Gint;
      Y    : out Gint);
This function is called when displaying a popup menu on the screen. It should return the (X, Y) coordinates of the menu. Note that you might want to attach the menu to a widget first if you want to display the menu relative to its attached widget. Note that there is a second version of this function (with added user data in the package User_Menu_Popup below

C_Gtk_Menu_Position_Func

type C_Gtk_Menu_Position_Func is access procedure
     (Menu      : System.Address;
      X         : out Gint;
      Y         : out Gint;
      Push_In   : out Gboolean;
      User_Data : System.Address);

Constants & Global variables

Accel_Group_Property (Glib.Properties.Property_Object)

Accel_Group_Property   : constant Glib.Properties.Property_Object;

Attach_Widget_Property (Glib.Properties.Property_Object)

Attach_Widget_Property : constant Glib.Properties.Property_Object;

Tearoff_State_Property (Glib.Properties.Property_Boolean)

Tearoff_State_Property : constant Glib.Properties.Property_Boolean;

Tearoff_Title_Property (Glib.Properties.Property_String)

Tearoff_Title_Property : constant Glib.Properties.Property_String;

Bottom_Attach_Property (Glib.Properties.Property_Int)

Bottom_Attach_Property : constant Glib.Properties.Property_Int;

Left_Attach_Property (Glib.Properties.Property_Int)

Left_Attach_Property   : constant Glib.Properties.Property_Int;

Right_Attach_Property (Glib.Properties.Property_Int)

Right_Attach_Property  : constant Glib.Properties.Property_Int;

Top_Attach_Property (Glib.Properties.Property_Int)

Top_Attach_Property    : constant Glib.Properties.Property_Int;

Arrow_Placement_Property (Glib.Properties.Property_Enum)

Arrow_Placement_Property    : constant Glib.Properties.Property_Enum;

Arrow_Scaling_Property (Glib.Properties.Property_Float)

Arrow_Scaling_Property      : constant Glib.Properties.Property_Float;

Double_Arrows_Property (Glib.Properties.Property_Boolean)

Double_Arrows_Property      : constant Glib.Properties.Property_Boolean;

Horizontal_Offset_Property (Glib.Properties.Property_Int)

Horizontal_Offset_Property  : constant Glib.Properties.Property_Int;

Horizontal_Padding_Property (Glib.Properties.Property_Int)

Horizontal_Padding_Property : constant Glib.Properties.Property_Int;

Vertical_Offset_Property (Glib.Properties.Property_Int)

Vertical_Offset_Property    : constant Glib.Properties.Property_Int;

Vertical_Padding_Property (Glib.Properties.Property_Int)

Vertical_Padding_Property   : constant Glib.Properties.Property_Int;

Signal_Move_Scroll (Glib.Signal_Name)

Signal_Move_Scroll : constant Glib.Signal_Name := "move_scroll";

Subprograms & Entries

Gtk_New

procedure Gtk_New 
(Widget: out Gtk_Menu);
Create a new empty menu.

Initialize

procedure Initialize 
(Widget: access Gtk_Menu_Record'Class);
Internal initialization function. See the section "Creating your own widgets" in the documentation.

Get_Type

function Get_Type return Gtk.Gtk_Type;
Return the internal value associated with a Gtk_Menu.

Set_Active

procedure Set_Active 
(Menu: access Gtk_Menu_Record;
Index: Guint);

Get_Active

function Get_Active 
(Menu: access Gtk_Menu_Record) return Gtk.Menu_Item.Gtk_Menu_Item;
Select a specified item in the menu. You will almost never need this function, it is used internally by Gtk_Option_Menu, for which it is the item that is currently selected. Note that the item is not considered as being pressed by the user when you call Set_Active, and thus no callback is called as a result.

Set_Tearoff_State

procedure Set_Tearoff_State 
(Menu: access Gtk_Menu_Record;
Torn_Off: Boolean);

Get_Tearoff_State

function Get_Tearoff_State 
(Menu: access Gtk_Menu_Record) return Boolean;
Modify the tearoff status of the menu. If Torn_Off is False, the menu is displayed as a drop down menu which disappears when the menu is not active. If Torn_Off is True, the menu persists until it is closed or reattached. Note that you can give the user access to this functionality by inserting a Gtk_Tearoff_Menu_Item in the menu.

Set_Title

procedure Set_Title 
(Menu: access Gtk_Menu_Record;
Title: UTF8_String);

Get_Title

function Get_Title  
(Menu: access Gtk_Menu_Record) return UTF8_String;
Set the title of the menu. Title is displayed when the menu is displayed as a tearoff menu in an independent window.

Reorder_Child

procedure Reorder_Child 
(Menu: access Gtk_Menu_Record;
Child: access Gtk.Widget.Gtk_Widget_Record'Class;
Position: Gint);
Move an existing menu_item within the menu. Its new position is given by Position, 0 being the first item in the menu. If Child does not exist in the menu, nothing is done.

Attach

procedure Attach 
(Menu: access Gtk_Menu_Record;
Child: access Gtk.Menu_Item.Gtk_Menu_Item_Record'Class;
Left_Attach: Guint;
Right_Attach: Guint;
Top_Attach: Guint;
Bottom_Attach: Guint);
Adds a new #GtkMenuItem to a (table) menu. The number of 'cells' that an item will occupy is specified by left_attach, right_attach, top_attach and bottom_attach. These each represent the leftmost, rightmost, uppermost and lower column and row numbers of the table. (Columns and rows are indexed from zero). Note that this function is not related to Detach(). Adding items to a standard menu is simply done by calling Add().

Popup

procedure Popup 
(Menu: access Gtk_Menu_Record;
Parent_Menu_Shell: Gtk.Menu_Shell.Gtk_Menu_Shell := null;
Parent_Menu_Item: Gtk.Menu_Item.Gtk_Menu_Item := null;
Func: Gtk_Menu_Position_Func := null;
Button: Guint := 1;
Activate_Time: Guint32 := 0);
Display a menu on the screen. This is the function to use to create contextual menus. Most of the time, the parameters can have a null value. Parent_Menu_Shell is the Gtk_Menu_Shell that contains Parent_Menu_Item, i.e. the widget that triggered the display of the menu. Func is a function that returns the coordinates for the menu. If it is null, then a default function that positions the menu at the pointer location is used. Button is the mouse button that was pressed to initiate the event. Activate_Time is the time at which the event occurred (you can get it directly from the Gdk_Event structure). Note that a variant of this function is given in the generic package User_Menu_Popup.

Popup

procedure Popup 
(Menu: access Gtk_Menu_Record;
Parent_Menu_Shell: Gtk.Menu_Shell.Gtk_Menu_Shell := null;
Parent_Menu_Item: Gtk.Menu_Item.Gtk_Menu_Item := null;
Func: C_Gtk_Menu_Position_Func := null;
User_Data: System.Address;
Button: Guint := 1;
Activate_Time: Guint32 := 0);
Similar to the Popup function above, but exposes a lower level interface to a C positioning function (C_Gtk_Menu_Position_Func).

Popdown

procedure Popdown 
(Menu: access Gtk_Menu_Record);
Remove the menu from the screen

Reposition

procedure Reposition 
(Menu: access Gtk_Menu_Record);
Reposition a menu according to its position function. This function is set when Popup is called.

Set_Monitor

procedure Set_Monitor 
(Menu: access Gtk_Menu_Record;
Monitor_Num: Gint);
Informs GTK+ on which monitor a menu should be popped up. See Gdk.Screen.Get_Monitor_Geometry. This function should be called from a Gtk_Menu_Position_Func if the menu should not appear on the same monitor as the pointer. This information can't be reliably inferred from the coordinates returned by a Gtk_Menu_Position_Func, since, for very long menus, these coordinates may extend beyond the monitor boundaries or even the screen boundaries.

Get_Monitor

function Get_Monitor 
(Menu: access Gtk_Menu_Record) return Gint;
Retrieves the number of the monitor on which to show the menu, or -1 if no monitor has been set.

Set_Screen

procedure Set_Screen 
(Menu: access Gtk_Menu_Record;
Screen: access Gdk.Screen.Gdk_Screen_Record'Class);
Sets the Gdk_Screen on which the menu will be displayed.

Set_Accel_Group

procedure Set_Accel_Group 
(Menu: access Gtk_Menu_Record;
Accel: Accel_Group.Gtk_Accel_Group);

Get_Accel_Group

function Get_Accel_Group 
(Menu: access Gtk_Menu_Record) return Accel_Group.Gtk_Accel_Group;
Set the Accel_Group that holds the global accelerators and key bindings for the menu.

Set_Accel_Path

procedure Set_Accel_Path 
(Menu: access Gtk_Menu_Record;
Accel_Path: UTF8_String);

Get_Accel_Path

function Get_Accel_Path 
(Menu: access Gtk_Menu_Record) return String;
Set an accelerator path for this menu from which accelerator paths for its immediate children, its menu items, can be constructed. The main purpose of this function is to spare the programmer the inconvenience of having to call Gtk.Menu_Item.Set_Accel_Path on each menu item that should support runtime user changable accelerators. Instead, by just calling Gtk.Menu.Set_Accel_Path on their parent, each menu item of this menu, that contains a label describing its purpose, automatically gets an accel path assigned. For example, a menu containing menu items "New" and "Exit", will, after Set_Accel_Path (menu, "<Gnumeric-Sheet>/File"); has been called, assign its items the accel paths: "<Gnumeric-Sheet>/File/New" and "<Gnumeric-Sheet>/File/Exit". Assigning accel paths to menu items then enables the user to change their accelerators at runtime.

Attach_To_Widget

procedure Attach_To_Widget 
(Menu: access Gtk_Menu_Record;
Attach_Widget: access Gtk.Widget.Gtk_Widget_Record'Class;
Detacher: Gtk_Menu_Detach_Func);
Attach a menu to the widget. When the menu is detached from the widget (for instance when it is destroyed), the procedure Detacher will be called. You will almost never need to use this function, unless you specifically want a call back when a widget becomes unavailable. If Attach_Widget is a menu_item with a single label in it, the name of the window created when Menu is teared-off will be the label in the menu_item.

Detach

procedure Detach 
(Menu: access Gtk_Menu_Record);
Detach the menu from its widget, and call the Detacher set in Attach_To_Widget.

Get_Attach_Widget

function Get_Attach_Widget 
(Menu: access Gtk_Menu_Record) return Gtk.Widget.Gtk_Widget;
Return the widget to which the menu was attached. If the menu was not attached, this function returns null.

Get_For_Attach_Widget

function Get_For_Attach_Widget 
(Widget: access Gtk.Widget.Gtk_Widget_Record'Class) return Gtk.Widget.Widget_List.Glist;
Returns a list of the menus which are attached to this widget. This list is owned by GTK+ and must not be modified.