/usr/share/ada/adainclude/gtkada/gtkada-builder.adb is in libgtkada2.24.1-dev 2.24.1-14.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | -----------------------------------------------------------------------
-- GtkAda - Ada95 binding for Gtk+/Gnome --
-- --
-- Copyright (C) 2011, 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 Interfaces.C.Strings; use Interfaces.C.Strings;
with System; use System;
with System.Assertions; use System.Assertions;
with Ada.Exceptions;
with Ada.Text_IO;
with Ada.Unchecked_Deallocation;
with Glib; use Glib;
with Gtk.Handlers; use Gtk.Handlers;
with Gtkada.Handlers; use Gtkada.Handlers;
package body Gtkada.Builder is
use Handlers_Map;
package Builder_Callback is new Gtk.Handlers.Callback
(Gtkada_Builder_Record);
package Builder_Return_Callback is new Gtk.Handlers.Return_Callback
(Gtkada_Builder_Record, Boolean);
procedure Wrapper_Callback
(C_Builder : System.Address;
C_Object : System.Address;
C_Signal_Name : Interfaces.C.Strings.chars_ptr;
C_Handler_Name : Interfaces.C.Strings.chars_ptr;
C_Connect_Object : System.Address;
Flags : Glib.G_Connect_Flags;
User_Data : System.Address);
pragma Convention (C, Wrapper_Callback);
-- Low-level subprogram to perform signal connections.
procedure Connect
(Handler_Name : String;
Handler : Universal_Marshaller;
Base_Object : GObject;
Signal : Glib.Signal_Name;
After : Boolean;
The_Builder : Gtkada_Builder;
Slot_Object : GObject);
-- Connect object to handler
procedure Free (Builder : access Gtkada_Builder_Record'Class);
-- Called when the Builder is destroyed
procedure On_Destroy
(Data : System.Address;
Builder_Addr : System.Address);
pragma Convention (C, On_Destroy);
-------------
-- Connect --
-------------
procedure Connect
(Handler_Name : String;
Handler : Universal_Marshaller;
Base_Object : GObject;
Signal : Glib.Signal_Name;
After : Boolean;
The_Builder : Gtkada_Builder;
Slot_Object : GObject) is
begin
-- Sanity checks
case Handler.T is
when Object | Object_Return =>
if Slot_Object = null then
Raise_Assert_Failure
("Error when connecting handler """ & Handler_Name & """:"
& ASCII.LF
& " attempting to connect a callback of type """ &
Handler_Type'Image (Handler.T)
& """, but no User_Data was specified in glade-3");
end if;
when Builder | Builder_Return =>
null;
end case;
-- Do the connect
case Handler.T is
when Object =>
Object_Callback.Object_Connect
(Widget => Base_Object,
Name => Signal,
Marsh => Object_Callback.To_Marshaller
(Object_Callback.Marshallers.Void_Marshaller.Handler
(Handler.The_Object_Handler)),
Slot_Object => Slot_Object,
After => After);
when Object_Return =>
Object_Return_Callback.Object_Connect
(Widget => Base_Object,
Name => Signal,
Marsh => Object_Return_Callback.To_Marshaller
(Object_Return_Callback.Marshallers.Void_Marshaller.Handler
(Handler.The_Object_Return_Handler)),
Slot_Object => Slot_Object,
After => After);
when Builder =>
Builder_Callback.Object_Connect
(Widget => Base_Object,
Name => Signal,
Marsh => Builder_Callback.To_Marshaller
(Builder_Callback.Marshallers.Void_Marshaller.Handler
(Handler.The_Builder_Handler)),
Slot_Object => The_Builder,
After => After);
when Builder_Return =>
Builder_Return_Callback.Object_Connect
(Widget => Base_Object,
Name => Signal,
Marsh => Builder_Return_Callback.To_Marshaller
(Builder_Return_Callback.Marshallers.Void_Marshaller.Handler
(Handler.The_Builder_Return_Handler)),
Slot_Object => The_Builder,
After => After);
end case;
end Connect;
----------------------
-- Wrapper_Callback --
----------------------
procedure Wrapper_Callback
(C_Builder : System.Address;
C_Object : System.Address;
C_Signal_Name : Interfaces.C.Strings.chars_ptr;
C_Handler_Name : Interfaces.C.Strings.chars_ptr;
C_Connect_Object : System.Address;
Flags : Glib.G_Connect_Flags;
User_Data : System.Address)
is
pragma Unreferenced (User_Data);
Object : constant GObject := Convert (C_Object);
Signal_Name : constant String := Value (C_Signal_Name);
After : constant Boolean := (Flags and G_Connect_After) /= 0;
Builder : constant Gtkada_Builder :=
Gtkada_Builder (Convert (C_Builder));
The_Marshaller : Universal_Marshaller_Access;
-- The universal marshaller
Handler_Name : constant String := Value (C_Handler_Name);
C : Cursor;
begin
-- Find the marshaller corresponding to the handler name.
C := Find (Builder.Handlers, To_Unbounded_String (Handler_Name));
if C = No_Element then
Raise_Assert_Failure
("Attempting to connect a callback to a handler ("""
& Handler_Name
& ")"" for which no callback has been registered.");
end if;
The_Marshaller := Element (C);
-- Now do the actual connect
Connect (Handler_Name => Handler_Name,
Handler => The_Marshaller.all,
Base_Object => Object,
Signal => Glib.Signal_Name (Signal_Name),
After => After,
The_Builder => Builder,
Slot_Object => Convert (C_Connect_Object));
end Wrapper_Callback;
----------------------
-- Register_Handler --
----------------------
procedure Register_Handler
(Builder : access Gtkada_Builder_Record'Class;
Handler_Name : String;
Handler : Object_Handler)
is
Item : Universal_Marshaller_Access;
begin
Item := new Universal_Marshaller (Object);
Item.The_Object_Handler := Handler;
Insert
(Builder.Handlers,
Key => To_Unbounded_String (Handler_Name),
New_Item => Item);
end Register_Handler;
----------------------
-- Register_Handler --
----------------------
procedure Register_Handler
(Builder : access Gtkada_Builder_Record'Class;
Handler_Name : String;
Handler : Object_Return_Handler)
is
Item : Universal_Marshaller_Access;
begin
Item := new Universal_Marshaller (Object_Return);
Item.The_Object_Return_Handler := Handler;
Insert
(Builder.Handlers,
Key => To_Unbounded_String (Handler_Name),
New_Item => Item);
end Register_Handler;
----------------------
-- Register_Handler --
----------------------
procedure Register_Handler
(Builder : access Gtkada_Builder_Record'Class;
Handler_Name : String;
Handler : Builder_Handler)
is
Item : Universal_Marshaller_Access;
begin
Item := new Universal_Marshaller (Gtkada.Builder.Builder);
Item.The_Builder_Handler := Handler;
Insert
(Builder.Handlers,
Key => To_Unbounded_String (Handler_Name),
New_Item => Item);
end Register_Handler;
----------------------
-- Register_Handler --
----------------------
procedure Register_Handler
(Builder : access Gtkada_Builder_Record'Class;
Handler_Name : String;
Handler : Builder_Return_Handler)
is
Item : Universal_Marshaller_Access;
begin
Item := new Universal_Marshaller (Builder_Return);
Item.The_Builder_Return_Handler := Handler;
Insert
(Builder.Handlers,
Key => To_Unbounded_String (Handler_Name),
New_Item => Item);
end Register_Handler;
----------------
-- Do_Connect --
----------------
procedure Do_Connect (Builder : access Gtkada_Builder_Record'Class) is
begin
Connect_Signals_Full
(Builder,
Wrapper_Callback'Access,
User_Data => Glib.Object.Get_Object (Builder));
end Do_Connect;
----------------
-- On_Destroy --
----------------
procedure Free (Builder : access Gtkada_Builder_Record'Class) is
C : Cursor;
E : Universal_Marshaller_Access;
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
(Universal_Marshaller, Universal_Marshaller_Access);
begin
-- Free memory associated to handlers
C := First (Builder.Handlers);
while Has_Element (C) loop
E := Element (C);
Unchecked_Free (E);
Next (C);
end loop;
exception
when E : others =>
Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E));
end Free;
-------------
-- Gtk_New --
-------------
procedure Gtk_New (Builder : out Gtkada_Builder) is
begin
Builder := new Gtkada_Builder_Record;
Gtkada.Builder.Initialize (Builder);
end Gtk_New;
----------------
-- On_Destroy --
----------------
procedure On_Destroy
(Data : System.Address;
Builder_Addr : System.Address)
is
pragma Unreferenced (Data);
Stub : Gtkada_Builder_Record;
Builder : constant Gtkada_Builder := Gtkada_Builder
(Get_User_Data (Builder_Addr, Stub));
begin
Free (Builder);
end On_Destroy;
----------------
-- Initialize --
----------------
procedure Initialize (Builder : access Gtkada_Builder_Record'Class) is
begin
Gtk.Builder.Initialize (Builder);
Weak_Ref (Builder, On_Destroy'Access);
end Initialize;
end Gtkada.Builder;
|