summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2016-10-04 18:52:32 +1100
committerJed Barber <jjbarber@y7mail.com>2016-10-04 18:52:32 +1100
commit1f9e7a15d9414b1a96691111069523a70e107f16 (patch)
tree6a1a2642cf8936cd9bd2aa013229e6f9c2b79860
parent7a84d0f3d0d181196b24795592a260e05b63fa74 (diff)
Basic find functionality working
-rw-r--r--src/adapad.adb15
-rw-r--r--src/editor_windows.adb47
-rw-r--r--src/editor_windows.ads5
-rw-r--r--src/fltk_binding/c_fl_input.cpp5
-rw-r--r--src/fltk_binding/c_fl_input.h3
-rw-r--r--src/fltk_binding/c_fl_text_buffer.cpp5
-rw-r--r--src/fltk_binding/c_fl_text_buffer.h1
-rw-r--r--src/fltk_binding/c_fl_text_display.cpp15
-rw-r--r--src/fltk_binding/c_fl_text_display.h3
-rw-r--r--src/fltk_binding/fltk-text_buffers.adb34
-rw-r--r--src/fltk_binding/fltk-text_buffers.ads9
-rw-r--r--src/fltk_binding/fltk-widgets-buttons.ads2
-rw-r--r--src/fltk_binding/fltk-widgets-groups-text_displays.adb43
-rw-r--r--src/fltk_binding/fltk-widgets-groups-text_displays.ads14
-rw-r--r--src/fltk_binding/fltk-widgets-inputs.adb16
-rw-r--r--src/fltk_binding/fltk-widgets-inputs.ads5
16 files changed, 212 insertions, 10 deletions
diff --git a/src/adapad.adb b/src/adapad.adb
index 7440ce9..bea6b91 100644
--- a/src/adapad.adb
+++ b/src/adapad.adb
@@ -282,10 +282,19 @@ function Adapad return Integer is
(This : in Do_Find_Callback;
Item : in String;
Match_Case : in Boolean) is
+
+ Current_Position : Natural;
+ Found_At : Natural;
+
begin
- Ada.Text_IO.Put_Line ("Finding " & Item);
- if Match_Case then
- Ada.Text_IO.Put_Line ("Matching case");
+ Find.Hide;
+ Current_Position := Editor.Get_Insert_Position;
+ if Buffer.Search_Forward (Current_Position, Item, Found_At, Match_Case) then
+ Buffer.Set_Selection (Found_At, Found_At + Item'Length);
+ Editor.Set_Insert_Position (Found_At + Item'Length);
+ Editor.Show_Insert_Position;
+ else
+ Alert ("No occurrences of '" & Item & "' found!");
end if;
end Call;
diff --git a/src/editor_windows.adb b/src/editor_windows.adb
index dffad97..20ccbbd 100644
--- a/src/editor_windows.adb
+++ b/src/editor_windows.adb
@@ -138,6 +138,35 @@ package body Editor_Windows is
+ function Get_Insert_Position
+ (This : in Editor_Window)
+ return Natural is
+ begin
+ return This.Editor.Get_Insert_Position;
+ end Get_Insert_Position;
+
+
+
+
+ procedure Set_Insert_Position
+ (This : in out Editor_Window;
+ Pos : in Natural) is
+ begin
+ This.Editor.Set_Insert_Position (Pos);
+ end Set_Insert_Position;
+
+
+
+
+ procedure Show_Insert_Position
+ (This : in out Editor_Window) is
+ begin
+ This.Editor.Show_Insert_Position;
+ end Show_Insert_Position;
+
+
+
+
-- used to hide about/find/replace/etc windows instead
-- of constantly creating and destroying them
@@ -245,11 +274,13 @@ package body Editor_Windows is
Item : in out Widget'Class) is
type Find_Window_Access is access all Find_Window;
- The_Window : access Find_Window := Find_Window_Access (Item.Parent);
+ Dialog : access Find_Window := Find_Window_Access (Item.Parent);
begin
- if The_Window.Callback /= null then
- The_Window.Callback.Call ("Hello", True);
+ if Dialog.Callback /= null then
+ Dialog.Callback.Call
+ (Dialog.Find_What.Get_Value,
+ Dialog.Match_Case.Get_State = On);
end if;
end Call;
@@ -348,11 +379,15 @@ package body Editor_Windows is
Item : in out Widget'Class) is
type Replace_Window_Access is access all Replace_Window;
- The_Window : access Replace_Window := Replace_Window_Access (Item.Parent);
+ Dialog : access Replace_Window := Replace_Window_Access (Item.Parent);
begin
- if The_Window.Callback /= null then
- The_Window.Callback.Call ("Hello", "There", True, True);
+ if Dialog.Callback /= null then
+ Dialog.Callback.Call
+ (Dialog.Find_What.Get_Value,
+ Dialog.Replace_With.Get_Value,
+ Dialog.Match_Case.Get_State = On,
+ Dialog.Replace_All.Get_State = On);
end if;
end Call;
diff --git a/src/editor_windows.ads b/src/editor_windows.ads
index 3acec25..b6c6a00 100644
--- a/src/editor_windows.ads
+++ b/src/editor_windows.ads
@@ -59,6 +59,11 @@ package Editor_Windows is
procedure Delete (This : in out Editor_Window);
+ function Get_Insert_Position (This : in Editor_Window) return Natural;
+ procedure Set_Insert_Position (This : in out Editor_Window; Pos : in Natural);
+ procedure Show_Insert_Position (This : in out Editor_Window);
+
+
type About_Window is new Double_Window with private;
diff --git a/src/fltk_binding/c_fl_input.cpp b/src/fltk_binding/c_fl_input.cpp
index 4ee251c..4f19bd1 100644
--- a/src/fltk_binding/c_fl_input.cpp
+++ b/src/fltk_binding/c_fl_input.cpp
@@ -14,3 +14,8 @@ void free_fl_input(INPUT i) {
delete reinterpret_cast<Fl_Input*>(i);
}
+
+const char * fl_input_get_value(INPUT i) {
+ return reinterpret_cast<Fl_Input*>(i)->value();
+}
+
diff --git a/src/fltk_binding/c_fl_input.h b/src/fltk_binding/c_fl_input.h
index b3b1190..cb40d42 100644
--- a/src/fltk_binding/c_fl_input.h
+++ b/src/fltk_binding/c_fl_input.h
@@ -11,5 +11,8 @@ extern "C" INPUT new_fl_input(int x, int y, int w, int h, char* label);
extern "C" void free_fl_input(INPUT i);
+extern "C" const char * fl_input_get_value(INPUT i);
+
+
#endif
diff --git a/src/fltk_binding/c_fl_text_buffer.cpp b/src/fltk_binding/c_fl_text_buffer.cpp
index 089ca33..b0df365 100644
--- a/src/fltk_binding/c_fl_text_buffer.cpp
+++ b/src/fltk_binding/c_fl_text_buffer.cpp
@@ -55,6 +55,11 @@ int fl_text_buffer_savefile(TEXTBUFFER tb, char * n) {
}
+int fl_text_buffer_search_forward(TEXTBUFFER tb, int start, const char * item, int * found, int mcase) {
+ return reinterpret_cast<Fl_Text_Buffer*>(tb)->search_forward(start, item, found, mcase);
+}
+
+
void fl_text_buffer_select(TEXTBUFFER tb, int s, int e) {
reinterpret_cast<Fl_Text_Buffer*>(tb)->select(s, e);
}
diff --git a/src/fltk_binding/c_fl_text_buffer.h b/src/fltk_binding/c_fl_text_buffer.h
index 906ef8c..cd64112 100644
--- a/src/fltk_binding/c_fl_text_buffer.h
+++ b/src/fltk_binding/c_fl_text_buffer.h
@@ -19,6 +19,7 @@ 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);
extern "C" int fl_text_buffer_savefile(TEXTBUFFER tb, char * n);
+extern "C" int fl_text_buffer_search_forward(TEXTBUFFER tb, int start, const char * item, int * found, int mcase);
extern "C" void fl_text_buffer_select(TEXTBUFFER tb, int s, int e);
diff --git a/src/fltk_binding/c_fl_text_display.cpp b/src/fltk_binding/c_fl_text_display.cpp
index c45e778..94eb002 100644
--- a/src/fltk_binding/c_fl_text_display.cpp
+++ b/src/fltk_binding/c_fl_text_display.cpp
@@ -58,3 +58,18 @@ void fl_text_display_set_text_size(TEXTDISPLAY td, int s) {
reinterpret_cast<Fl_Text_Display*>(td)->textsize(static_cast<Fl_Fontsize>(s));
}
+
+int fl_text_display_get_insert_pos(TEXTDISPLAY td) {
+ return reinterpret_cast<Fl_Text_Display*>(td)->insert_position();
+}
+
+
+void fl_text_display_set_insert_pos(TEXTDISPLAY td, int p) {
+ reinterpret_cast<Fl_Text_Display*>(td)->insert_position(p);
+}
+
+
+void fl_text_display_show_insert_pos(TEXTDISPLAY td) {
+ reinterpret_cast<Fl_Text_Display*>(td)->show_insert_position();
+}
+
diff --git a/src/fltk_binding/c_fl_text_display.h b/src/fltk_binding/c_fl_text_display.h
index dba1706..5a91774 100644
--- a/src/fltk_binding/c_fl_text_display.h
+++ b/src/fltk_binding/c_fl_text_display.h
@@ -20,6 +20,9 @@ extern "C" int fl_text_display_get_text_font(TEXTDISPLAY td);
extern "C" void fl_text_display_set_text_font(TEXTDISPLAY td, int f);
extern "C" int fl_text_display_get_text_size(TEXTDISPLAY td);
extern "C" void fl_text_display_set_text_size(TEXTDISPLAY td, int s);
+extern "C" int fl_text_display_get_insert_pos(TEXTDISPLAY td);
+extern "C" void fl_text_display_set_insert_pos(TEXTDISPLAY td, int p);
+extern "C" void fl_text_display_show_insert_pos(TEXTDISPLAY td);
#endif
diff --git a/src/fltk_binding/fltk-text_buffers.adb b/src/fltk_binding/fltk-text_buffers.adb
index 6a25399..6df96cb 100644
--- a/src/fltk_binding/fltk-text_buffers.adb
+++ b/src/fltk_binding/fltk-text_buffers.adb
@@ -67,6 +67,15 @@ package body FLTK.Text_Buffers is
return Interfaces.C.int;
pragma Import (C, fl_text_buffer_savefile, "fl_text_buffer_savefile");
+ function fl_text_buffer_search_forward
+ (TB : in System.Address;
+ SP : in Interfaces.C.int;
+ IT : in Interfaces.C.char_array;
+ FP : out Interfaces.C.int;
+ CA : in Interfaces.C.int)
+ return Interfaces.C.int;
+ pragma Import (C, fl_text_buffer_search_forward, "fl_text_buffer_search_forward");
+
procedure fl_text_buffer_select
(TB : in System.Address;
S, E : in Interfaces.C.int);
@@ -281,6 +290,31 @@ package body FLTK.Text_Buffers is
+ function Search_Forward
+ (This : in Text_Buffer;
+ Start_At : in Natural;
+ Item : in String;
+ Found_At : out Natural;
+ Match_Case : in Boolean)
+ return Boolean is
+
+ Found_Raw : Interfaces.C.int;
+ Result : Interfaces.C.int;
+
+ begin
+ Result := fl_text_buffer_search_forward
+ (This.Void_Ptr,
+ Interfaces.C.int (Start_At),
+ Interfaces.C.To_C (Item),
+ Found_Raw,
+ Boolean'Pos (Match_Case));
+ Found_At := Natural (Found_Raw);
+ return Boolean'Val (Result);
+ end Search_Forward;
+
+
+
+
procedure Set_Selection
(This : in out Text_Buffer;
Start, Finish : in Natural) is
diff --git a/src/fltk_binding/fltk-text_buffers.ads b/src/fltk_binding/fltk-text_buffers.ads
index eea9b73..0bb881e 100644
--- a/src/fltk_binding/fltk-text_buffers.ads
+++ b/src/fltk_binding/fltk-text_buffers.ads
@@ -75,6 +75,15 @@ package FLTK.Text_Buffers is
Name : in String);
+ function Search_Forward
+ (This : in Text_Buffer;
+ Start_At : in Natural;
+ Item : in String;
+ Found_At : out Natural;
+ Match_Case : in Boolean)
+ return Boolean;
+
+
procedure Set_Selection
(This : in out Text_Buffer;
Start, Finish : in Natural);
diff --git a/src/fltk_binding/fltk-widgets-buttons.ads b/src/fltk_binding/fltk-widgets-buttons.ads
index a31ed79..403ad1a 100644
--- a/src/fltk_binding/fltk-widgets-buttons.ads
+++ b/src/fltk_binding/fltk-widgets-buttons.ads
@@ -6,7 +6,7 @@ package FLTK.Widgets.Buttons is
type Button is new Widget with private;
- type State is (On, Off);
+ type State is (Off, On);
function Create
diff --git a/src/fltk_binding/fltk-widgets-groups-text_displays.adb b/src/fltk_binding/fltk-widgets-groups-text_displays.adb
index 0151536..473ceea 100644
--- a/src/fltk_binding/fltk-widgets-groups-text_displays.adb
+++ b/src/fltk_binding/fltk-widgets-groups-text_displays.adb
@@ -57,6 +57,20 @@ package body FLTK.Widgets.Groups.Text_Displays is
S : in Interfaces.C.int);
pragma Import (C, fl_text_display_set_text_size, "fl_text_display_set_text_size");
+ function fl_text_display_get_insert_pos
+ (TD : in System.Address)
+ return Interfaces.C.int;
+ pragma Import (C, fl_text_display_get_insert_pos, "fl_text_display_get_insert_pos");
+
+ procedure fl_text_display_set_insert_pos
+ (TD : in System.Address;
+ P : in Interfaces.C.int);
+ pragma Import (C, fl_text_display_set_insert_pos, "fl_text_display_set_insert_pos");
+
+ procedure fl_text_display_show_insert_pos
+ (TD : in System.Address);
+ pragma Import (C, fl_text_display_show_insert_pos, "fl_text_display_show_insert_pos");
+
@@ -175,5 +189,34 @@ package body FLTK.Widgets.Groups.Text_Displays is
end Set_Text_Size;
+
+
+ function Get_Insert_Position
+ (This : in Text_Display)
+ return Natural is
+ begin
+ return Natural (fl_text_display_get_insert_pos (This.Void_Ptr));
+ end Get_Insert_Position;
+
+
+
+
+ procedure Set_Insert_Position
+ (This : in out Text_Display;
+ Pos : in Natural) is
+ begin
+ fl_text_display_set_insert_pos (This.Void_Ptr, Interfaces.C.int (Pos));
+ end Set_Insert_Position;
+
+
+
+
+ procedure Show_Insert_Position
+ (This : in out Text_Display) is
+ begin
+ fl_text_display_show_insert_pos (This.Void_Ptr);
+ end Show_Insert_Position;
+
+
end FLTK.Widgets.Groups.Text_Displays;
diff --git a/src/fltk_binding/fltk-widgets-groups-text_displays.ads b/src/fltk_binding/fltk-widgets-groups-text_displays.ads
index bb99e78..84c6551 100644
--- a/src/fltk_binding/fltk-widgets-groups-text_displays.ads
+++ b/src/fltk_binding/fltk-widgets-groups-text_displays.ads
@@ -56,6 +56,20 @@ package FLTK.Widgets.Groups.Text_Displays is
Size : in Font_Size);
+ function Get_Insert_Position
+ (This : in Text_Display)
+ return Natural;
+
+
+ procedure Set_Insert_Position
+ (This : in out Text_Display;
+ Pos : in Natural);
+
+
+ procedure Show_Insert_Position
+ (This : in out Text_Display);
+
+
private
diff --git a/src/fltk_binding/fltk-widgets-inputs.adb b/src/fltk_binding/fltk-widgets-inputs.adb
index 17ab621..9af8e87 100644
--- a/src/fltk_binding/fltk-widgets-inputs.adb
+++ b/src/fltk_binding/fltk-widgets-inputs.adb
@@ -1,6 +1,7 @@
with Interfaces.C;
+with Interfaces.C.Strings;
with System;
use type System.Address;
@@ -18,6 +19,11 @@ package body FLTK.Widgets.Inputs is
(F : in System.Address);
pragma Import (C, free_fl_input, "free_fl_input");
+ function fl_input_get_value
+ (F : in System.Address)
+ return Interfaces.C.Strings.chars_ptr;
+ pragma Import (C, fl_input_get_value, "fl_input_get_value");
+
@@ -54,5 +60,15 @@ package body FLTK.Widgets.Inputs is
end Create;
+
+
+ function Get_Value
+ (This : in Input)
+ return String is
+ begin
+ return Interfaces.C.Strings.Value (fl_input_get_value (This.Void_Ptr));
+ end Get_Value;
+
+
end FLTK.Widgets.Inputs;
diff --git a/src/fltk_binding/fltk-widgets-inputs.ads b/src/fltk_binding/fltk-widgets-inputs.ads
index c1ebfbb..0f818ac 100644
--- a/src/fltk_binding/fltk-widgets-inputs.ads
+++ b/src/fltk_binding/fltk-widgets-inputs.ads
@@ -12,6 +12,11 @@ package FLTK.Widgets.Inputs is
return Input;
+ function Get_Value
+ (This : in Input)
+ return String;
+
+
private