diff options
author | Jed Barber <jjbarber@y7mail.com> | 2016-11-11 08:00:48 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2016-11-11 08:00:48 +1100 |
commit | bee437918713d9fc2213a5a554ac02f4e7af3249 (patch) | |
tree | 948f17dbde91d057669575e50c6f2e885026b27e | |
parent | faabff73b74307cdec73264116291857d679aef7 (diff) |
Simplified text_buffer callbacks
-rw-r--r-- | fltk-text_buffers.adb | 16 | ||||
-rw-r--r-- | fltk-text_buffers.ads | 32 |
2 files changed, 19 insertions, 29 deletions
diff --git a/fltk-text_buffers.adb b/fltk-text_buffers.adb index 736e32e..7529c1c 100644 --- a/fltk-text_buffers.adb +++ b/fltk-text_buffers.adb @@ -2,7 +2,7 @@ with Interfaces.C; with Interfaces.C.Strings; -with Ada.Strings.Unbounded; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Containers; with System; use type System.Address; @@ -112,12 +112,10 @@ package body FLTK.Text_Buffers is Text : in Interfaces.C.Strings.chars_ptr; UD : in System.Address) is - package UStr renames Ada.Strings.Unbounded; - Action : Modification; Place : Position := Position (Pos); Length : Natural; - Deleted_Text : UStr.Unbounded_String := UStr.To_Unbounded_String (""); + Deleted_Text : Unbounded_String := To_Unbounded_String (""); Ada_Text_Buffer : access Text_Buffer := Text_Buffer_Convert.To_Pointer (UD); @@ -129,7 +127,7 @@ package body FLTK.Text_Buffers is Length := Natural (Deleted); Action := Delete; if Text /= Interfaces.C.Strings.Null_Ptr then - Deleted_Text := UStr.To_Unbounded_String (Interfaces.C.Strings.Value (Text)); + Deleted_Text := To_Unbounded_String (Interfaces.C.Strings.Value (Text)); end if; elsif Restyled > 0 then Length := Natural (Restyled); @@ -140,7 +138,7 @@ package body FLTK.Text_Buffers is end if; for CB of Ada_Text_Buffer.Modify_CBs loop - CB.Call (Action, Place, Length, UStr.To_String (Deleted_Text)); + CB.all (Action, Place, Length, To_String (Deleted_Text)); end loop; end Modify_Callback_Hook; @@ -163,7 +161,7 @@ package body FLTK.Text_Buffers is Text_Buffer_Convert.To_Pointer (UD); begin for CB of Ada_Text_Buffer.Predelete_CBs loop - CB.Call (Place, Length); + CB.all (Place, Length); end loop; end Predelete_Callback_Hook; @@ -190,7 +188,7 @@ package body FLTK.Text_Buffers is procedure Add_Modify_Callback (This : in out Text_Buffer; - Func : not null access Modify_Callback'Class) is + Func : in Modify_Callback) is begin if This.Modify_CBs.Length = 0 then fl_text_buffer_add_modify_callback @@ -206,7 +204,7 @@ package body FLTK.Text_Buffers is procedure Add_Predelete_Callback (This : in out Text_Buffer; - Func : not null access Predelete_Callback'Class) is + Func : in Predelete_Callback) is begin if This.Predelete_CBs.Length = 0 then fl_text_buffer_add_predelete_callback diff --git a/fltk-text_buffers.ads b/fltk-text_buffers.ads index a560076..a021dbf 100644 --- a/fltk-text_buffers.ads +++ b/fltk-text_buffers.ads @@ -13,23 +13,19 @@ package FLTK.Text_Buffers is type Position is new Natural; + type Modification is (Insert, Restyle, Delete, None); - type Modification is (Insert, Restyle, Delete, None); - type Modify_Callback is interface; - procedure Call - (This : in Modify_Callback; - Action : in Modification; + type Modify_Callback is access procedure + (Action : in Modification; Place : in Position; Length : in Natural; - Deleted_Text : in String) is abstract; + Deleted_Text : in String); - type Predelete_Callback is interface; - procedure Call - (This : in Predelete_Callback; - Place : in Position; - Length : in Natural) is abstract; + type Predelete_Callback is access procedure + (Place : in Position; + Length : in Natural); function Create @@ -40,12 +36,12 @@ package FLTK.Text_Buffers is procedure Add_Modify_Callback (This : in out Text_Buffer; - Func : not null access Modify_Callback'Class); + Func : in Modify_Callback); procedure Add_Predelete_Callback (This : in out Text_Buffer; - Func : not null access Predelete_Callback'Class); + Func : in Predelete_Callback); procedure Call_Modify_Callbacks @@ -98,21 +94,17 @@ package FLTK.Text_Buffers is private - type Modify_Access is access all Modify_Callback'Class; - type Predelete_Access is access all Predelete_Callback'Class; - - package Modify_Vectors is new Ada.Containers.Vectors (Index_Type => Positive, - Element_Type => Modify_Access); + Element_Type => Modify_Callback); package Predelete_Vectors is new Ada.Containers.Vectors (Index_Type => Positive, - Element_Type => Predelete_Access); + Element_Type => Predelete_Callback); type Text_Buffer is new Wrapper with record - Modify_CBs : Modify_Vectors.Vector; + Modify_CBs : Modify_Vectors.Vector; Predelete_CBs : Predelete_Vectors.Vector; end record; |