Skip to content

Commit 319f887

Browse files
committedSep 30, 2016
("inline_editing_started", "inline_editing_finished"): new signals
New signals added to the canvas view, so that GPS can invalidate the current context whenever something occurs on the canvas that might change which actions are applicable. When an item is edited inline, and moved at the time, we now also move the editing widget to keep overlapping the item. Change-Id: I458ef32a90e607aa3e86bd588d1c0ea62cbfa69e
1 parent bd38850 commit 319f887

4 files changed

+158
-23
lines changed
 

‎features-17

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ of the feature.
1313
New features in GtkAda 17
1414
-------------------------
1515

16+
NF-17-P930-028 Gtkada.Canvas_View: inline editing improvements (2016-09-30)
17+
18+
New signals have been aded:
19+
Signal_Inline_Editing_Started
20+
Signal_Inline_Editing_Finished
21+
New subprograms have been added:
22+
Set_Editable, Is_Editable
23+
Inline_Editing_In_Progress
24+
When an item that is edited interactively by the user is moved, we now
25+
also move the editing widget (generally a GtkTextView). This text view
26+
now also inherits the font size and attributes from the edited item.
27+
End of editing is done via a simple <return>, since the previous
28+
<ctrl-return> was impossible to guess by the user. Preselect the whole
29+
text when editing, so that the user can more easily change it all.
30+
1631
NF-17-P722-028 New MDI child signals (2016-07-22)
1732

1833
New signals have been introduced in the MDI

‎src/gtkada-canvas_view-views.adb

+3-2
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ package body Gtkada.Canvas_View.Views is
310310
---------------------------
311311

312312
procedure Cancel_Inline_Editing
313-
(Self : not null access Canvas_View_Record'Class)
314-
is
313+
(Self : not null access Canvas_View_Record'Class) is
315314
begin
316315
if Self.Inline_Edit.Item /= null then
316+
Self.Inline_Editing_Finished (Self.Inline_Edit.Item);
317317
Self.Inline_Edit.Item := null;
318318
Self.Remove (Self.Get_Child);
319319
end if;
@@ -347,6 +347,7 @@ package body Gtkada.Canvas_View.Views is
347347
Self.Add (W); -- also queues a resize, so calls On_Size_Allocate
348348
W.Show_All;
349349
W.Grab_Focus;
350+
Self.Inline_Editing_Started (Item);
350351
end if;
351352
end Start_Inline_Editing;
352353

‎src/gtkada-canvas_view.adb

+113-21
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ package body Gtkada.Canvas_View is
6969
4 => New_String (String (Signal_Item_Destroyed)));
7070
View_Signals : constant Gtkada.Types.Chars_Ptr_Array :=
7171
(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)));
7375

7476
Model_Class_Record : Glib.Object.Ada_GObject_Class :=
7577
Glib.Object.Uninitialized_Class;
@@ -102,6 +104,10 @@ package body Gtkada.Canvas_View is
102104
pragma Convention (C, On_Size_Allocate);
103105
-- default handler for "size_allocate" on views.
104106

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+
105111
function GValue_To_Abstract_Item (Value : GValue) return Abstract_Item;
106112
function Abstract_Item_To_Address is new Ada.Unchecked_Conversion
107113
(Abstract_Item, System.Address);
@@ -508,6 +514,8 @@ package body Gtkada.Canvas_View is
508514
Set_Adjustment_Values (Self);
509515
Self.Queue_Draw;
510516
end if;
517+
518+
Move_Inline_Edit_Widget (Self);
511519
end On_Layout_Changed_For_View;
512520

513521
-----------------------------------
@@ -1136,7 +1144,9 @@ package body Gtkada.Canvas_View is
11361144
Class_Record => View_Class_Record'Access,
11371145
Type_Name => "GtkadaCanvasView",
11381146
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)),
11401150
Returns => (1 => GType_None,
11411151
2 => GType_Boolean),
11421152
Class_Init => View_Class_Init'Access)
@@ -1357,6 +1367,36 @@ package body Gtkada.Canvas_View is
13571367
return 0;
13581368
end On_View_Draw;
13591369

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+
13601400
----------------------
13611401
-- On_Size_Allocate --
13621402
----------------------
@@ -1366,9 +1406,6 @@ package body Gtkada.Canvas_View is
13661406
is
13671407
Self : constant Canvas_View := Canvas_View (Glib.Object.Convert (View));
13681408
SAlloc : Gtk_Allocation := Alloc;
1369-
Edit : Gtk_Widget;
1370-
Box : View_Rectangle;
1371-
WMin, WNat, HMin, HNat : Gint;
13721409
begin
13731410
-- For some reason, when we maximize the toplevel window in testgtk, or
13741411
-- at least enlarge it horizontally, we are starting to see an alloc
@@ -1393,22 +1430,7 @@ package body Gtkada.Canvas_View is
13931430
end if;
13941431

13951432
-- 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);
14121434

14131435
if Self.Scale_To_Fit_Requested /= 0.0 then
14141436
Self.Scale_To_Fit
@@ -1830,6 +1852,76 @@ package body Gtkada.Canvas_View is
18301852
end if;
18311853
end On_Item_Event;
18321854

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+
18331925
-------------
18341926
-- Refresh --
18351927
-------------

‎src/gtkada-canvas_view.ads

+27
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,33 @@ package Gtkada.Canvas_View is
12951295
-- compatible callbacks which enable behaviors such as a moving items,
12961296
-- scrolling the canvas by dragging the background,...
12971297

1298+
procedure Inline_Editing_Started
1299+
(Self : not null access Canvas_View_Record'Class;
1300+
Item : not null access Abstract_Item_Record'Class);
1301+
function On_Inline_Editing_Started
1302+
(Self : not null access Canvas_View_Record'Class;
1303+
Call : not null access procedure
1304+
(Self : access GObject_Record'Class; Item : Abstract_Item);
1305+
Slot : access GObject_Record'Class := null)
1306+
return Gtk.Handlers.Handler_Id;
1307+
Signal_Inline_Editing_Started : constant Glib.Signal_Name :=
1308+
"inline_editing_started";
1309+
-- Called when the user starts inline editing of items.
1310+
1311+
procedure Inline_Editing_Finished
1312+
(Self : not null access Canvas_View_Record'Class;
1313+
Item : not null access Abstract_Item_Record'Class);
1314+
function On_Inline_Editing_Finished
1315+
(Self : not null access Canvas_View_Record'Class;
1316+
Call : not null access procedure
1317+
(Self : access GObject_Record'Class; Item : Abstract_Item);
1318+
Slot : access GObject_Record'Class := null)
1319+
return Gtk.Handlers.Handler_Id;
1320+
Signal_Inline_Editing_Finished : constant Glib.Signal_Name :=
1321+
"inline_editing_finished";
1322+
-- Called when the user finishes (cancels ot validates) inline
1323+
-- editing of items.
1324+
12981325
------------------------
12991326
-- Object hierarchies --
13001327
------------------------

0 commit comments

Comments
 (0)
Please sign in to comment.