@@ -69,7 +69,9 @@ package body Gtkada.Canvas_View is
69
69
4 => New_String (String (Signal_Item_Destroyed)));
70
70
View_Signals : constant Gtkada.Types.Chars_Ptr_Array :=
71
71
(1 => New_String (String (Signal_Viewport_Changed)),
72
- 2 => New_String (String (Signal_Item_Event)));
72
+ 2 => New_String (String (Signal_Item_Event)),
73
+ 3 => New_String (String (Signal_Inline_Editing_Started)),
74
+ 4 => New_String (String (Signal_Inline_Editing_Finished)));
73
75
74
76
Model_Class_Record : Glib.Object.Ada_GObject_Class :=
75
77
Glib.Object.Uninitialized_Class;
@@ -102,6 +104,10 @@ package body Gtkada.Canvas_View is
102
104
pragma Convention (C, On_Size_Allocate);
103
105
-- default handler for "size_allocate" on views.
104
106
107
+ procedure Move_Inline_Edit_Widget
108
+ (Self : not null access Canvas_View_Record'Class);
109
+ -- Move the inline editing widget, if one exists
110
+
105
111
function GValue_To_Abstract_Item (Value : GValue) return Abstract_Item;
106
112
function Abstract_Item_To_Address is new Ada.Unchecked_Conversion
107
113
(Abstract_Item, System.Address);
@@ -508,6 +514,8 @@ package body Gtkada.Canvas_View is
508
514
Set_Adjustment_Values (Self);
509
515
Self.Queue_Draw;
510
516
end if ;
517
+
518
+ Move_Inline_Edit_Widget (Self);
511
519
end On_Layout_Changed_For_View ;
512
520
513
521
-- ---------------------------------
@@ -1136,7 +1144,9 @@ package body Gtkada.Canvas_View is
1136
1144
Class_Record => View_Class_Record'Access ,
1137
1145
Type_Name => " GtkadaCanvasView" ,
1138
1146
Parameters => (1 => (1 => GType_None),
1139
- 2 => (1 => GType_Pointer)),
1147
+ 2 => (1 => GType_Pointer),
1148
+ 3 => (1 => GType_Pointer),
1149
+ 4 => (1 => GType_Pointer)),
1140
1150
Returns => (1 => GType_None,
1141
1151
2 => GType_Boolean),
1142
1152
Class_Init => View_Class_Init'Access )
@@ -1357,6 +1367,36 @@ package body Gtkada.Canvas_View is
1357
1367
return 0 ;
1358
1368
end On_View_Draw ;
1359
1369
1370
+ -- ---------------------------
1371
+ -- Move_Inline_Edit_Widget --
1372
+ -- ---------------------------
1373
+
1374
+ procedure Move_Inline_Edit_Widget
1375
+ (Self : not null access Canvas_View_Record'Class)
1376
+ is
1377
+ Edit : Gtk_Widget;
1378
+ Box : View_Rectangle;
1379
+ SAlloc : Gtk_Allocation;
1380
+ WMin, WNat, HMin, HNat : Gint;
1381
+ begin
1382
+ if Self.Inline_Edit.Item /= null then
1383
+ Edit := Self.Get_Child;
1384
+ Box := Self.Model_To_View (Self.Inline_Edit.Item.Model_Bounding_Box);
1385
+
1386
+ -- SAlloc is relative to the view, so we should not add Alloc.{X,Y}
1387
+ SAlloc.X := Gint (Box.X);
1388
+ SAlloc.Y := Gint (Box.Y);
1389
+
1390
+ Edit.Get_Preferred_Height (HMin, HNat);
1391
+ SAlloc.Height := Gint'Max (HMin, Gint (Box.Height));
1392
+
1393
+ Edit.Get_Preferred_Width_For_Height (SAlloc.Height, WMin, WNat);
1394
+ SAlloc.Width := Gint'Max (WMin, Gint (Box.Width));
1395
+
1396
+ Edit.Size_Allocate (SAlloc);
1397
+ end if ;
1398
+ end Move_Inline_Edit_Widget ;
1399
+
1360
1400
-- --------------------
1361
1401
-- On_Size_Allocate --
1362
1402
-- --------------------
@@ -1366,9 +1406,6 @@ package body Gtkada.Canvas_View is
1366
1406
is
1367
1407
Self : constant Canvas_View := Canvas_View (Glib.Object.Convert (View));
1368
1408
SAlloc : Gtk_Allocation := Alloc;
1369
- Edit : Gtk_Widget;
1370
- Box : View_Rectangle;
1371
- WMin, WNat, HMin, HNat : Gint;
1372
1409
begin
1373
1410
-- For some reason, when we maximize the toplevel window in testgtk, or
1374
1411
-- at least enlarge it horizontally, we are starting to see an alloc
@@ -1393,22 +1430,7 @@ package body Gtkada.Canvas_View is
1393
1430
end if ;
1394
1431
1395
1432
-- Are we in the middle of inline-editing ?
1396
- if Self.Inline_Edit.Item /= null then
1397
- Edit := Self.Get_Child;
1398
- Box := Self.Model_To_View (Self.Inline_Edit.Item.Model_Bounding_Box);
1399
-
1400
- -- SAlloc is relative to the view, so we should not add Alloc.{X,Y}
1401
- SAlloc.X := Gint (Box.X);
1402
- SAlloc.Y := Gint (Box.Y);
1403
-
1404
- Edit.Get_Preferred_Height (HMin, HNat);
1405
- SAlloc.Height := Gint'Max (HMin, Gint (Box.Height));
1406
-
1407
- Edit.Get_Preferred_Width_For_Height (SAlloc.Height, WMin, WNat);
1408
- SAlloc.Width := Gint'Max (WMin, Gint (Box.Width));
1409
-
1410
- Edit.Size_Allocate (SAlloc);
1411
- end if ;
1433
+ Move_Inline_Edit_Widget (Self);
1412
1434
1413
1435
if Self.Scale_To_Fit_Requested /= 0.0 then
1414
1436
Self.Scale_To_Fit
@@ -1830,6 +1852,76 @@ package body Gtkada.Canvas_View is
1830
1852
end if ;
1831
1853
end On_Item_Event ;
1832
1854
1855
+ -- --------------------------
1856
+ -- Inline_Editing_Started --
1857
+ -- --------------------------
1858
+
1859
+ procedure Inline_Editing_Started
1860
+ (Self : not null access Canvas_View_Record'Class;
1861
+ Item : not null access Abstract_Item_Record'Class) is
1862
+ begin
1863
+ Abstract_Item_Emit
1864
+ (Self, Signal_Inline_Editing_Started & ASCII.NUL,
1865
+ Abstract_Item (Item));
1866
+ end Inline_Editing_Started ;
1867
+
1868
+ -- -----------------------------
1869
+ -- On_Inline_Editing_Started --
1870
+ -- -----------------------------
1871
+
1872
+ function On_Inline_Editing_Started
1873
+ (Self : not null access Canvas_View_Record'Class;
1874
+ Call : not null access procedure
1875
+ (Self : access GObject_Record'Class; Item : Abstract_Item);
1876
+ Slot : access GObject_Record'Class := null )
1877
+ return Gtk.Handlers.Handler_Id is
1878
+ begin
1879
+ if Slot = null then
1880
+ return Object_Callback.Connect
1881
+ (Self, Signal_Inline_Editing_Started,
1882
+ Abstract_Item_Marshallers.To_Marshaller (Call));
1883
+ else
1884
+ return Object_Callback.Object_Connect
1885
+ (Self, Signal_Inline_Editing_Started,
1886
+ Abstract_Item_Marshallers.To_Marshaller (Call), Slot);
1887
+ end if ;
1888
+ end On_Inline_Editing_Started ;
1889
+
1890
+ -- ---------------------------
1891
+ -- Inline_Editing_Finished --
1892
+ -- ---------------------------
1893
+
1894
+ procedure Inline_Editing_Finished
1895
+ (Self : not null access Canvas_View_Record'Class;
1896
+ Item : not null access Abstract_Item_Record'Class) is
1897
+ begin
1898
+ Abstract_Item_Emit
1899
+ (Self, Signal_Inline_Editing_Finished & ASCII.NUL,
1900
+ Abstract_Item (Item));
1901
+ end Inline_Editing_Finished ;
1902
+
1903
+ -- ------------------------------
1904
+ -- On_Inline_Editing_Finished --
1905
+ -- ------------------------------
1906
+
1907
+ function On_Inline_Editing_Finished
1908
+ (Self : not null access Canvas_View_Record'Class;
1909
+ Call : not null access procedure
1910
+ (Self : access GObject_Record'Class; Item : Abstract_Item);
1911
+ Slot : access GObject_Record'Class := null )
1912
+ return Gtk.Handlers.Handler_Id is
1913
+ begin
1914
+ if Slot = null then
1915
+ return Object_Callback.Connect
1916
+ (Self, Signal_Inline_Editing_Finished,
1917
+ Abstract_Item_Marshallers.To_Marshaller (Call));
1918
+ else
1919
+ return Object_Callback.Object_Connect
1920
+ (Self, Signal_Inline_Editing_Finished,
1921
+ Abstract_Item_Marshallers.To_Marshaller (Call), Slot);
1922
+ end if ;
1923
+ end On_Inline_Editing_Finished ;
1924
+
1833
1925
-- -----------
1834
1926
-- Refresh --
1835
1927
-- -----------
0 commit comments