1
1
-----------------------------------------------------------------------
2
2
-- GtkAda - Ada95 binding for Gtk+/Gnome --
4
-- Copyright (C) 2001-2008, AdaCore --
5
6
-- This library is free software; you can redistribute it and/or --
6
7
-- modify it under the terms of the GNU General Public --
25
25
with Unchecked_Deallocation;
27
27
with Glib.Type_Conversion_Hooks;
28
with Gtkada.Types; use Gtkada.Types;
28
with Gtkada.Bindings; use Gtkada.Bindings;
29
with Gtkada.C; use Gtkada.C;
30
with Gtkada.Types; use Gtkada.Types;
30
32
package body Glib.Object is
33
package Signal_Id_Arrays is new Gtkada.C.Unbounded_Arrays
34
(Glib.Signal_Id, Glib.Null_Signal_Id, Glib.Guint,
35
Glib.Object.Signal_Id_Array);
32
37
procedure Free_User_Data (Data : System.Address);
33
38
-- Free the user data Data. This function should not be called directly
39
44
Destroy : System.Address);
40
45
pragma Import (C, Set_User_Data, "g_object_set_qdata_full");
47
function To_Object is new Ada.Unchecked_Conversion
48
(System.Address, GObject);
56
-------------------------
57
-- Conversion_Function --
58
-------------------------
60
function Conversion_Function
61
(Obj : System.Address; Stub : GObject_Record'Class) return GObject
63
function Get_Type (Obj : System.Address) return GType;
64
pragma Import (C, Get_Type, "ada_gobject_get_type");
66
Name : constant String := Type_Name (Get_Type (Obj));
67
Hooks : Glib.Type_Conversion_Hooks.Hook_List_Access;
69
use type Glib.Type_Conversion_Hooks.Hook_List_Access;
72
Hooks := Glib.Type_Conversion_Hooks.Conversion_Hooks;
74
while Hooks /= null loop
76
R : constant GObject := Hooks.Func (Name);
86
return new GObject_Record'Class'(Stub);
87
end Conversion_Function;
89
64
--------------------
90
65
-- Free_User_Data --
91
66
--------------------
152
127
Stub : GObject_Record'Class) return GObject
154
129
function Internal
155
(Object : in System.Address;
156
Quark : in Glib.GQuark) return GObject;
130
(Object : System.Address;
131
Quark : Glib.GQuark) return System.Address;
157
132
pragma Import (C, Internal, "g_object_get_qdata");
159
134
use type System.Address;
169
144
GtkAda_String_Quark := Glib.Quark_From_String (GtkAda_String);
172
R := Internal (Obj, GtkAda_String_Quark);
147
R := To_Object (Internal (Obj, GtkAda_String_Quark));
175
R := Conversion_Function (Obj, Stub);
150
R := Glib.Type_Conversion_Hooks.Conversion_Function (Obj, Stub);
177
152
-- This function will either simply return what we expect (Stub), or
178
153
-- try to create the exact Ada type corresponding to the C type.
188
163
------------------------
190
165
function Get_User_Data_Fast
191
(Obj : in System.Address;
192
Stub : in GObject_Record'Class) return GObject
166
(Obj : System.Address;
167
Stub : GObject_Record'Class) return GObject
194
169
pragma Suppress (All_Checks);
196
171
function Internal
197
(Object : in System.Address;
198
Quark : in Glib.GQuark) return GObject;
172
(Object : System.Address;
173
Quark : Glib.GQuark) return System.Address;
199
174
pragma Import (C, Internal, "g_object_get_qdata");
201
176
use type System.Address;
211
186
GtkAda_String_Quark := Glib.Quark_From_String (GtkAda_String);
214
R := Internal (Obj, GtkAda_String_Quark);
189
R := To_Object (Internal (Obj, GtkAda_String_Quark));
217
192
R := new GObject_Record'Class'(Stub);
278
253
procedure Set_User_Data
279
254
(Obj : System.Address;
280
255
Quark : Glib.GQuark;
256
Data : System.Address;
282
257
Destroy : System.Address);
283
258
pragma Import (C, Set_User_Data, "g_object_set_qdata_full");
286
261
Result.Ptr := Obj.Ptr;
288
(Obj.Ptr, GtkAda_String_Quark, Result, Free_User_Data'Address);
263
(Obj.Ptr, GtkAda_String_Quark, Result'Address, Free_User_Data'Address);
289
264
Deallocate (Obj);
291
266
end Unchecked_Cast;
343
318
function List_Ids (Typ : Glib.GType) return Signal_Id_Array is
344
type Flat_Id_Array is array (Guint) of Signal_Id;
345
pragma Convention (C, Flat_Id_Array);
346
type Flat_Id_Array_Access is access all Flat_Id_Array;
319
use Signal_Id_Arrays;
348
320
function Internal
349
(Typ : GType; N_Ids : access Guint) return Flat_Id_Array_Access;
321
(Typ : GType; N_Ids : access Guint) return Unbounded_Array_Access;
350
322
pragma Import (C, Internal, "g_signal_list_ids");
352
N_Ids : aliased Guint;
353
Result : constant Flat_Id_Array_Access := Internal (Typ, N_Ids'Access);
325
Output : constant Unbounded_Array_Access := Internal (Typ, N'Access);
326
Result : constant Signal_Id_Array := To_Array (Output, N);
357
return (1 .. 0 => 0);
359
return Signal_Id_Array (Result (0 .. N_Ids - 1));
363
333
-----------------
364
334
-- Signal_Name --
365
335
-----------------
367
function Signal_Name (Q : Signal_Query) return String is
337
function Signal_Name (Q : Signal_Query) return Glib.Signal_Name is
368
338
function Internal
369
339
(Q : Signal_Query) return Interfaces.C.Strings.chars_ptr;
370
340
pragma Import (C, Internal, "ada_gsignal_query_signal_name");
373
return Interfaces.C.Strings.Value (Internal (Q));
343
return Glib.Signal_Name
344
(String'(Interfaces.C.Strings.Value (Internal (Q))));
380
351
function Params (Q : Signal_Query) return GType_Array is
381
type Flat_GType_Array is array (Guint) of GType;
382
pragma Convention (C, Flat_GType_Array);
383
type Flat_GType_Array_Access is access all Flat_GType_Array;
385
353
function Internal
386
354
(Q : Signal_Query;
387
N_Ids : access Guint) return Flat_GType_Array_Access;
355
N_Ids : access Guint) return Unbounded_Array_Access;
388
356
pragma Import (C, Internal, "ada_gsignal_query_params");
390
N_Ids : aliased Guint;
391
Result : constant Flat_GType_Array_Access := Internal (Q, N_Ids'Access);
359
Output : constant Unbounded_Array_Access := Internal (Q, N'Access);
360
Result : constant GType_Array := To_Array (Output, N);
395
return (1 .. 0 => GType_Invalid);
397
return GType_Array (Result (0 .. N_Ids - 1));
363
-- Do not free Output, it belongs to gtk+
477
444
Destroy : System.Address);
478
445
pragma Import (C, Set_Data_Internal_Id, "g_object_set_qdata_full");
447
function Get_Data_Internal
448
(Object : System.Address;
449
Key : String) return System.Address;
450
pragma Import (C, Get_Data_Internal, "g_object_get_data");
452
function Get_Data_Internal_Id
453
(Object : System.Address;
454
Key : Glib.GQuark) return System.Address;
455
pragma Import (C, Get_Data_Internal_Id, "g_object_get_qdata");
506
483
(Object : access GObject_Record'Class;
507
484
Id : String := "user_data") return Data_Type
510
(Object : System.Address;
511
Key : String) return System.Address;
512
pragma Import (C, Internal, "g_object_get_data");
514
486
D : constant Cb_Record_Access :=
515
Convert (Internal (Get_Object (Object), Id & ASCII.NUL));
487
Convert (Get_Data_Internal (Get_Object (Object), Id & ASCII.NUL));
518
489
if D = null or else D.Ptr = null then
519
490
raise Gtkada.Types.Data_Error;
501
(Object : access GObject_Record'Class;
502
Id : String := "user_data";
503
Default : Data_Type) return Data_Type
505
D : constant Cb_Record_Access :=
506
Convert (Get_Data_Internal (Get_Object (Object), Id & ASCII.NUL));
508
if D = null or else D.Ptr = null then
530
520
(Object : access GObject_Record'Class;
531
521
Id : Glib.GQuark) return Data_Type
534
(Object : System.Address;
535
Key : Glib.GQuark) return System.Address;
536
pragma Import (C, Internal, "g_object_get_qdata");
538
523
D : constant Cb_Record_Access :=
539
Convert (Internal (Get_Object (Object), Id));
524
Convert (Get_Data_Internal_Id (Get_Object (Object), Id));
542
526
if D = null or else D.Ptr = null then
543
527
raise Gtkada.Types.Data_Error;
538
(Object : access GObject_Record'Class;
540
Default : Data_Type) return Data_Type
542
D : constant Cb_Record_Access :=
543
Convert (Get_Data_Internal_Id (Get_Object (Object), Id));
545
if D = null or else D.Ptr = null then
692
695
Internal (Get_Object (Object), Notify, Data);
698
-------------------------------
699
-- Interface_List_Properties --
700
-------------------------------
702
function Interface_List_Properties
703
(Vtable : Interface_Vtable) return Glib.Param_Spec_Array
707
(Vtable : Interface_Vtable;
708
N_Props : access Guint) return Unbounded_Array_Access;
709
pragma Import (C, Internal, "g_object_interface_list_properties");
712
Output : constant Unbounded_Array_Access := Internal (Vtable, N'Access);
713
Result : constant Param_Spec_Array := To_Array (Output, Integer (N));
716
-- Doc says we should free, but that results in double-deallocation...
719
end Interface_List_Properties;
721
---------------------------
722
-- Class_List_Properties --
723
---------------------------
725
function Class_List_Properties
726
(Class : GObject_Class) return Glib.Param_Spec_Array
730
(Class : GObject_Class;
731
N_Props : access Guint) return Unbounded_Array_Access;
732
pragma Import (C, Internal, "g_object_class_list_properties");
735
Output : constant Unbounded_Array_Access := Internal (Class, N'Access);
736
Result : constant Param_Spec_Array := To_Array (Output, Integer (N));
738
-- Doc says we should free, but that results in double-deallocation...
741
end Class_List_Properties;