summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2016-11-18 20:29:13 +1100
committerJed Barber <jjbarber@y7mail.com>2016-11-18 20:29:13 +1100
commit5045c1fb020480ac1bcc2aca921f886c0057a73f (patch)
tree5b2961b3cbac755426089960b49d697b56b4504d
parent8fe1342dcbbc2fcad262f31ecf24f73ee08c1f1c (diff)
Added text buffer callback enable/disable, text range retrieval functions
-rw-r--r--src/fltk_binding/c_fl_text_buffer.cpp10
-rw-r--r--src/fltk_binding/c_fl_text_buffer.h2
-rw-r--r--src/fltk_binding/fltk-text_buffers.adb108
-rw-r--r--src/fltk_binding/fltk-text_buffers.ads20
4 files changed, 118 insertions, 22 deletions
diff --git a/src/fltk_binding/c_fl_text_buffer.cpp b/src/fltk_binding/c_fl_text_buffer.cpp
index 966f142..71f04d2 100644
--- a/src/fltk_binding/c_fl_text_buffer.cpp
+++ b/src/fltk_binding/c_fl_text_buffer.cpp
@@ -40,6 +40,11 @@ void fl_text_buffer_insert(TEXTBUFFER tb, int p, const char * item) {
}
+void fl_text_buffer_remove(TEXTBUFFER tb, int s, int f) {
+ reinterpret_cast<Fl_Text_Buffer*>(tb)->remove(s, f);
+}
+
+
int fl_text_buffer_length(TEXTBUFFER tb) {
return reinterpret_cast<Fl_Text_Buffer*>(tb)->length();
}
@@ -99,3 +104,8 @@ unsigned int fl_text_buffer_char_at(TEXTBUFFER tb, int p) {
return reinterpret_cast<Fl_Text_Buffer*>(tb)->char_at(p);
}
+
+char * fl_text_buffer_text_range(TEXTBUFFER tb, int s, int f) {
+ return reinterpret_cast<Fl_Text_Buffer*>(tb)->text_range(s, f);
+}
+
diff --git a/src/fltk_binding/c_fl_text_buffer.h b/src/fltk_binding/c_fl_text_buffer.h
index a7b954b..1551d2b 100644
--- a/src/fltk_binding/c_fl_text_buffer.h
+++ b/src/fltk_binding/c_fl_text_buffer.h
@@ -16,6 +16,7 @@ extern "C" void fl_text_buffer_add_predelete_callback(TEXTBUFFER tb, void * cb,
extern "C" void fl_text_buffer_call_modify_callbacks(TEXTBUFFER tb);
extern "C" void fl_text_buffer_call_predelete_callbacks(TEXTBUFFER tb);
extern "C" void fl_text_buffer_insert(TEXTBUFFER tb, int p, const char * item);
+extern "C" void fl_text_buffer_remove(TEXTBUFFER tb, int s, int f);
extern "C" int fl_text_buffer_length(TEXTBUFFER tb);
extern "C" int fl_text_buffer_loadfile(TEXTBUFFER tb, char * n);
extern "C" void fl_text_buffer_remove_selection(TEXTBUFFER tb);
@@ -28,6 +29,7 @@ extern "C" int fl_text_buffer_selected(TEXTBUFFER tb);
extern "C" int fl_text_buffer_skip_lines(TEXTBUFFER tb, int s, int l);
extern "C" int fl_text_buffer_rewind_lines(TEXTBUFFER tb, int s, int l);
extern "C" unsigned int fl_text_buffer_char_at(TEXTBUFFER tb, int p);
+extern "C" char * fl_text_buffer_text_range(TEXTBUFFER tb, int s, int f);
#endif
diff --git a/src/fltk_binding/fltk-text_buffers.adb b/src/fltk_binding/fltk-text_buffers.adb
index 38e6632..52f12e0 100644
--- a/src/fltk_binding/fltk-text_buffers.adb
+++ b/src/fltk_binding/fltk-text_buffers.adb
@@ -1,6 +1,5 @@
-with Interfaces.C;
with Interfaces.C.Strings;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Containers;
@@ -49,6 +48,11 @@ package body FLTK.Text_Buffers is
I : in Interfaces.C.char_array);
pragma Import (C, fl_text_buffer_insert, "fl_text_buffer_insert");
+ procedure fl_text_buffer_remove
+ (TB : in System.Address;
+ S, F : in Interfaces.C.int);
+ pragma Import (C, fl_text_buffer_remove, "fl_text_buffer_remove");
+
function fl_text_buffer_length
(TB : in System.Address)
return Interfaces.C.int;
@@ -122,6 +126,12 @@ package body FLTK.Text_Buffers is
return Interfaces.C.unsigned;
pragma Import (C, fl_text_buffer_char_at, "fl_text_buffer_char_at");
+ function fl_text_buffer_text_range
+ (TB : in System.Address;
+ S, F : in Interfaces.C.int)
+ return Interfaces.C.Strings.chars_ptr;
+ pragma Import (C, fl_text_buffer_text_range, "fl_text_buffer_text_range");
+
@@ -158,26 +168,28 @@ package body FLTK.Text_Buffers is
Ada_Text_Buffer : access Text_Buffer :=
Text_Buffer_Convert.To_Pointer (UD);
begin
- if Inserted > 0 then
- Length := Natural (Inserted);
- Action := Insert;
- elsif Deleted > 0 then
- Length := Natural (Deleted);
- Action := Delete;
- if Text /= Interfaces.C.Strings.Null_Ptr then
- Deleted_Text := To_Unbounded_String (Interfaces.C.Strings.Value (Text));
+ if Ada_Text_Buffer.CB_Active then
+ if Inserted > 0 then
+ Length := Natural (Inserted);
+ Action := Insert;
+ elsif Deleted > 0 then
+ Length := Natural (Deleted);
+ Action := Delete;
+ if Text /= Interfaces.C.Strings.Null_Ptr then
+ Deleted_Text := To_Unbounded_String (Interfaces.C.Strings.Value (Text));
+ end if;
+ elsif Restyled > 0 then
+ Length := Natural (Restyled);
+ Action := Restyle;
+ else
+ Length := 0;
+ Action := None;
end if;
- elsif Restyled > 0 then
- Length := Natural (Restyled);
- Action := Restyle;
- else
- Length := 0;
- Action := None;
- end if;
- for CB of Ada_Text_Buffer.Modify_CBs loop
- CB.all (Action, Place, Length, To_String (Deleted_Text));
- end loop;
+ for CB of Ada_Text_Buffer.Modify_CBs loop
+ CB.all (Action, Place, Length, To_String (Deleted_Text));
+ end loop;
+ end if;
end Modify_Callback_Hook;
@@ -198,9 +210,11 @@ package body FLTK.Text_Buffers is
Ada_Text_Buffer : access Text_Buffer :=
Text_Buffer_Convert.To_Pointer (UD);
begin
- for CB of Ada_Text_Buffer.Predelete_CBs loop
- CB.all (Place, Length);
- end loop;
+ if Ada_Text_Buffer.CB_Active then
+ for CB of Ada_Text_Buffer.Predelete_CBs loop
+ CB.all (Place, Length);
+ end loop;
+ end if;
end Predelete_Callback_Hook;
@@ -218,6 +232,7 @@ package body FLTK.Text_Buffers is
This.Modify_CBs := Modify_Vectors.Empty_Vector;
This.Predelete_CBs := Predelete_Vectors.Empty_Vector;
+ This.CB_Active := True;
end return;
end Create;
@@ -274,6 +289,24 @@ package body FLTK.Text_Buffers is
+ procedure Enable_Callbacks
+ (This : in out Text_Buffer) is
+ begin
+ This.CB_Active := True;
+ end Enable_Callbacks;
+
+
+
+
+ procedure Disable_Callbacks
+ (This : in out Text_Buffer) is
+ begin
+ This.CB_Active := False;
+ end Disable_Callbacks;
+
+
+
+
procedure Insert_Text
(This : in out Text_Buffer;
Pos : in Natural;
@@ -288,6 +321,19 @@ package body FLTK.Text_Buffers is
+ procedure Remove_Text
+ (This : in out Text_Buffer;
+ Start, Finish : in Natural) is
+ begin
+ fl_text_buffer_remove
+ (This.Void_Ptr,
+ Interfaces.C.int (Start),
+ Interfaces.C.int (Finish));
+ end Remove_Text;
+
+
+
+
function Length
(This : in Text_Buffer)
return Natural is
@@ -472,5 +518,23 @@ package body FLTK.Text_Buffers is
end Character_At;
+
+
+ function Text_At
+ (This : in Text_Buffer;
+ Start, Finish : in Natural)
+ return String
+ is
+ C_Str : Interfaces.C.Strings.chars_ptr := fl_text_buffer_text_range
+ (This.Void_Ptr,
+ Interfaces.C.int (Start),
+ Interfaces.C.int (Finish));
+ The_Text : String := Interfaces.C.Strings.Value (C_Str);
+ begin
+ Interfaces.C.Strings.Free (C_Str);
+ return The_Text;
+ end Text_At;
+
+
end FLTK.Text_Buffers;
diff --git a/src/fltk_binding/fltk-text_buffers.ads b/src/fltk_binding/fltk-text_buffers.ads
index c17b020..d3e1bab 100644
--- a/src/fltk_binding/fltk-text_buffers.ads
+++ b/src/fltk_binding/fltk-text_buffers.ads
@@ -52,12 +52,25 @@ package FLTK.Text_Buffers is
(This : in out Text_Buffer);
+ procedure Enable_Callbacks
+ (This : in out Text_Buffer);
+
+
+ procedure Disable_Callbacks
+ (This : in out Text_Buffer);
+
+
procedure Insert_Text
(This : in out Text_Buffer;
Pos : in Natural;
Item : in String);
+ procedure Remove_Text
+ (This : in out Text_Buffer;
+ Start, Finish : in Natural);
+
+
function Length
(This : in Text_Buffer)
return Natural;
@@ -131,6 +144,12 @@ package FLTK.Text_Buffers is
return Character;
+ function Text_At
+ (This : in Text_Buffer;
+ Start, Finish : in Natural)
+ return String;
+
+
private
@@ -144,6 +163,7 @@ private
type Text_Buffer is new Wrapper with
record
+ CB_Active : Boolean;
Modify_CBs : Modify_Vectors.Vector;
Predelete_CBs : Predelete_Vectors.Vector;
end record;