From 7a84d0f3d0d181196b24795592a260e05b63fa74 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Tue, 4 Oct 2016 00:32:30 +1100 Subject: Find/Replace marshalling back to Adapad Main done, some Group/Widget_Cursor stuff removed --- src/editor_windows.adb | 87 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 19 deletions(-) (limited to 'src/editor_windows.adb') diff --git a/src/editor_windows.adb b/src/editor_windows.adb index f4a1151..dffad97 100644 --- a/src/editor_windows.adb +++ b/src/editor_windows.adb @@ -4,6 +4,8 @@ with FLTK.Enums; use FLTK.Enums; with FLTK.Widgets; use FLTK.Widgets; +with FLTK.Widgets.Groups; +use FLTK.Widgets.Groups; with FLTK.Widgets.Groups.Windows; use FLTK.Widgets.Groups.Windows; @@ -144,19 +146,22 @@ package body Editor_Windows is overriding procedure Call (This : in Hide_Callback; Item : in out Widget'Class) is + + P : access Group'Class; + begin - -- - -- this is an ugly hack - -- - -- it only works because the Item will either be the About/Find/Replace window - -- directly or it'll be a close/cancel button in said window - -- - -- need to figure out how to properly loop up via Widget Parent method - -- if Item in Window'Class then Window (Item).Hide; else - Window (Item.Parent.Data.all).Hide; + P := Item.Parent; + loop + if P = null then + return; + end if; + exit when P.all in Window'Class; + P := P.Parent; + end loop; + Window (P.all).Hide; end if; end Call; @@ -233,6 +238,24 @@ package body Editor_Windows is -- Find_Window functions and procedures + Find_M : aliased Find_Marshaller; + + overriding procedure Call + (This : in Find_Marshaller; + 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); + + begin + if The_Window.Callback /= null then + The_Window.Callback.Call ("Hello", True); + end if; + end Call; + + + + function Create return Find_Window is My_Width : Integer := 350; My_Height : Integer := 130; @@ -267,13 +290,17 @@ package body Editor_Windows is Button_Line, Button_Width, Button_Height, "Cancel")), Start => Enter_Button'(Create ((My_Width - 2 * Button_Width) * 2 / 3 + Button_Width, - Button_Line, Button_Width, Button_Height, "Find"))) do + Button_Line, Button_Width, Button_Height, "Find")), + + Callback => null) do This.Add (This.Find_What); This.Add (This.Match_Case); This.Add (This.Cancel); This.Cancel.Set_Callback (Hide_CB'Access); This.Add (This.Start); + This.Start.Set_Callback (Find_M'Access); + This.Set_Callback (Hide_CB'Access); end return; end Create; @@ -302,18 +329,36 @@ package body Editor_Windows is - procedure Set_Function + procedure Set_Find_Callback (This : in out Find_Window; - Func : access procedure (Item : in String)) is + Func : not null access Find_Callback'Class) is begin - null; - end Set_Function; + This.Callback := Func; + end Set_Find_Callback; -- Replace_Window functions and procedures + Replace_M : aliased Replace_Marshaller; + + overriding procedure Call + (This : in Replace_Marshaller; + 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); + + begin + if The_Window.Callback /= null then + The_Window.Callback.Call ("Hello", "There", True, True); + end if; + end Call; + + + + function Create return Replace_Window is My_Width : Integer := 350; My_Height : Integer := 180; @@ -357,7 +402,9 @@ package body Editor_Windows is Button_Line, Button_Width, Button_Height, "Cancel")), Start => Enter_Button'(Create ((My_Width - 2 * Button_Width) * 2 / 3 + Button_Width, - Button_Line, Button_Width, Button_Height, "Replace"))) do + Button_Line, Button_Width, Button_Height, "Replace")), + + Callback => null) do This.Add (This.Find_What); This.Add (This.Replace_With); @@ -366,6 +413,8 @@ package body Editor_Windows is This.Add (This.Cancel); This.Cancel.Set_Callback (Hide_CB'Access); This.Add (This.Start); + This.Start.Set_Callback (Replace_M'Access); + This.Set_Callback (Hide_CB'Access); end return; end Create; @@ -394,12 +443,12 @@ package body Editor_Windows is - procedure Set_Function + procedure Set_Replace_Callback (This : in out Replace_Window; - Func : access procedure (Item : in String)) is + Func : not null access Replace_Callback'Class) is begin - null; - end Set_Function; + This.Callback := Func; + end Set_Replace_Callback; end Editor_Windows; -- cgit