1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
-----------------------------------------------------------------------
-- GtkAda - Ada95 binding for the Gimp Toolkit --
-- --
-- Copyright (C) 2006-2013, AdaCore --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU 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 --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public --
-- License along with this library; if not, write to the --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330, --
-- Boston, MA 02111-1307, USA. --
-- --
-----------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Glib; use Glib;
with Glib.Error; use Glib.Error;
with Gtk.Box; use Gtk.Box;
with Gtk.Frame; use Gtk.Frame;
with Gtk.Action; use Gtk.Action;
with Gtk.Action_Group; use Gtk.Action_Group;
with Gtk.Stock; use Gtk.Stock;
with Gtk.UI_Manager; use Gtk.UI_Manager;
with Gtk.Window; use Gtk.Window;
with System; use System;
package body Create_UI_Manager is
procedure Activate_Action (Action, User_Data : System.Address);
pragma Convention (C, Activate_Action);
-- Called when one of the actions has been selected
procedure Activate_Radio_Action
(Group, Current : access Gtk_Action_Record'Class;
User_Data : System.Address);
-- Called when a radio action is selected
-- First define all the actions that our application can perform. This is
-- unrelated to the layout of menus
Entries : constant Action_Entry_Array :=
(1 => Create (Name => "FileMenu", Label => "_File"),
2 => Create (Name => "PreferencesMenu", Label => "_Preferences"),
3 => Create (Name => "ColorMenu", Label => "_Color"),
4 => Create (Name => "ShapeMenu", Label => "_Shape"),
5 => Create (Name => "HelpMenu", Label => "_Help"),
6 => Create (Name => "New",
Stock_Id => Stock_New,
Label => "_New",
Accelerator => "<control>N",
Tooltip => "Create a new file",
Callback => Activate_Action'Access),
7 => Create (Name => "Open",
Stock_Id => Stock_Open,
Label => "_Open",
Accelerator => "<control>O",
Tooltip => "Open a file",
Callback => Activate_Action'Access),
8 => Create (Name => "Save",
Stock_Id => Stock_Save,
Label => "_Save",
Accelerator => "<control>S",
Tooltip => "Save current file",
Callback => Activate_Action'Access),
9 => Create (Name => "SaveAs",
Stock_Id => Stock_Save,
Label => "Save _As...",
Tooltip => "Save to a file",
Callback => Activate_Action'Access),
10 => Create (Name => "Quit",
Stock_Id => Stock_Quit,
Label => "_Quit",
Accelerator => "<control>Q",
Tooltip => "Quit",
Callback => Activate_Action'Access),
11 => Create (Name => "About",
Label => "_About",
Accelerator => "<control>A",
Tooltip => "About",
Callback => Activate_Action'Access),
12 => Create (Name => "Logo",
Stock_Id => "demo-gtk-logo",
Tooltip => "GTK+",
Callback => Activate_Action'Access));
Toggle_Entries : constant Toggle_Action_Entry_Array :=
(1 => Create (Name => "Bold",
Stock_Id => Stock_Bold,
Label => "_Bold",
Accelerator => "<control>B",
Tooltip => "Bold",
Callback => Activate_Action'Access,
Is_Active => True));
subtype Color is Gint;
Color_Red : constant Color := 1;
Color_Green : constant Color := 2;
Color_Blue : constant Color := 3;
Color_Entries : constant Radio_Action_Entry_Array :=
(1 => Create (Name => "Red",
Label => "_Red",
Accelerator => "<control>R",
Tooltip => "Blood",
Value => Color_Red),
2 => Create (Name => "Green",
Label => "_Green",
Accelerator => "<control>G",
Tooltip => "Grass",
Value => Color_Green),
3 => Create (Name => "Blue",
Label => "_Blue",
Accelerator => "<control>B",
Tooltip => "Sky",
Value => Color_Blue));
subtype Shape is Gint;
Shape_Square : constant Shape := 1;
Shape_Oval : constant Shape := 2;
Shape_Entries : constant Radio_Action_Entry_Array :=
(1 => Create (Name => "Square",
Label => "_Square",
Accelerator => "<control>S",
Tooltip => "Square",
Value => Shape_Square),
2 => Create (Name => "Oval",
Label => "_Oval",
Accelerator => "<control>O",
Tooltip => "Egg",
Value => Shape_Oval));
UI_Info : constant String :=
"<ui>"
& " <menubar name='MenuBar'>"
& " <menu action='FileMenu'>"
& " <menuitem action='New'/>"
& " <menuitem action='Open'/>"
& " <menuitem action='Save'/>"
& " <menuitem action='SaveAs'/>"
& " <separator/>"
& " <menuitem action='Quit'/>"
& " </menu>"
& " <menu action='PreferencesMenu'>"
& " <menu action='ColorMenu'>"
& " <menuitem action='Red'/>"
& " <menuitem action='Green'/>"
& " <menuitem action='Blue'/>"
& " </menu>"
& " <menu action='ShapeMenu'>"
& " <menuitem action='Square'/>"
& " <menuitem action='Oval'/>"
& " </menu>"
& " <menuitem action='Bold'/>"
& " </menu>"
& " <menu action='HelpMenu'>"
& " <menuitem action='About'/>"
& " </menu>"
& " </menubar>"
& " <toolbar name='ToolBar'>"
& " <toolitem action='Open'/>"
& " <toolitem action='Quit'/>"
& " <separator action='Sep1'/>"
& " <toolitem action='Logo'/>"
& " </toolbar>"
& "</ui>";
---------------------------
-- Activate_Radio_Action --
---------------------------
procedure Activate_Radio_Action
(Group, Current : access Gtk_Action_Record'Class;
User_Data : System.Address)
is
pragma Unreferenced (User_Data, Group);
begin
Put_Line ("Radio action " & Get_Name (Current) & " selected");
end Activate_Radio_Action;
---------------------
-- Activate_Action --
---------------------
procedure Activate_Action (Action, User_Data : System.Address) is
Act : constant Gtk_Action := Convert (Action);
pragma Unreferenced (User_Data);
begin
Put_Line ("Action " & Get_Name (Act) & " was activated");
end Activate_Action;
----------
-- Help --
----------
function Help return String is
begin
return "The @bGtk_UI_Manager@B widget is a convenient facility to"
& " create menu bars, toolbars and other high level widgets through"
& " a set of simple API calls, or through an XML description";
end Help;
---------
-- Run --
---------
procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
UI : Gtk_UI_Manager;
Actions : Gtk_Action_Group;
Box : Gtk_Box;
Error : aliased GError := null;
begin
Set_Label (Frame, "UI Manager");
Gtk_New (Actions, "Actions");
Add_Actions (Actions, Entries);
Add_Toggle_Actions (Actions, Toggle_Entries);
Add_Radio_Actions (Actions, Color_Entries, Color_Red,
Activate_Radio_Action'Access);
Add_Radio_Actions (Actions, Shape_Entries, Shape_Oval,
Activate_Radio_Action'Access);
Gtk_New (UI);
Insert_Action_Group (UI, Actions, 0);
Add_Accel_Group
(Gtk_Window (Get_Toplevel (Frame)), Get_Accel_Group (UI));
if Add_UI_From_String (UI, UI_Info, Error'Unchecked_Access) = 0 then
Put_Line ("Building menus failed: " & Get_Message (Error));
Error_Free (Error);
end if;
Gtk_New_Vbox (Box, Homogeneous => False);
Add (Frame, Box);
Pack_Start (Box, Get_Widget (UI, "/MenuBar"), Expand => False);
--
--
--
-- label = gtk_label_new ("Type\n<alt>\nto start");
-- gtk_widget_set_size_request (label, 200, 200);
-- gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
-- gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0);
--
--
-- separator = gtk_hseparator_new ();
-- gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
--
--
-- box2 = gtk_vbox_new (FALSE, 10);
-- gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
-- gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
--
-- button = gtk_button_new_with_label ("close");
-- g_signal_connect_swapped (button, "clicked",
-- G_CALLBACK (gtk_widget_destroy), window);
-- gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
-- GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
-- gtk_widget_grab_default (button);
--
-- gtk_widget_show_all (window);
Show_All (Frame);
end Run;
end Create_UI_Manager;
|