with FLTK.Enums; use FLTK.Enums; with FLTK.Widgets; use FLTK.Widgets; with FLTK.Widgets.Groups.Windows; use FLTK.Widgets.Groups.Windows; package body Editor_Windows is -- Editor_Window functions and procedures function Create (X, Y, W, H : in Integer; Label_Text : in String) return Editor_Window is Width, Height : Integer; begin if W < Min_Editor_Width then Width := Min_Editor_Width; else Width := W; end if; if H < Min_Editor_Height then Height := Min_Editor_Height; else Height := H; end if; return This : Editor_Window := (Double_Window'(Create (X, Y, Width, Height, Label_Text)) with Editor => Text_Editor'(Create (0, 30, Width, Height - 30, "")), Bar => Menu_Bar'(Create (0, 0, Width, 30, ""))) do This.Add (This.Editor); This.Add (This.Bar); This.Editor.Set_Text_Font (Courier); This.Set_Resizable (This.Editor); This.Set_Size_Range (Min_Editor_Width, Min_Editor_Height); end return; end Create; function Create (W, H : in Integer) return Editor_Window is begin return Create (0, 0, W, H, "(Untitled)"); end Create; function Get_Buffer (This : in Editor_Window) return Text_Buffer_Cursor is begin return This.Editor.Get_Buffer; end Get_Buffer; procedure Set_Buffer (This : in out Editor_Window; Buff : in out Text_Buffer) is begin This.Editor.Set_Buffer (Buff); end Set_Buffer; function Get_Menu (This : in out Editor_Window) return Menu_Cursor is begin return Ref : Menu_Cursor (This.Bar'Access); end Get_Menu; procedure Undo (This : in out Editor_Window) is begin This.Editor.Undo; end Undo; procedure Cut (This : in out Editor_Window) is begin This.Editor.Cut; end Cut; procedure Copy (This : in out Editor_Window) is begin This.Editor.Copy; end Copy; procedure Paste (This : in out Editor_Window) is begin This.Editor.Paste; end Paste; procedure Delete (This : in out Editor_Window) is begin This.Editor.Delete; end Delete; -- used to hide about/find/replace/etc windows instead -- of constantly creating and destroying them Hide_CB : aliased Hide_Callback; overriding procedure Call (This : in Hide_Callback; Item : in out Widget'Class) is 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; end if; end Call; -- About_Window functions and procedures function Create (X, Y, W, H : in Integer; Label_Text : in String) return About_Window is Heading_Text : String := "Adapad 0.5"; Blurb_Text : String := "FLTK based simple text editor written in Ada"; Author_Text : String := "Programmed by Jed Barber"; begin return This : About_Window := (Double_Window'(Create (X, Y, W, H, Label_Text)) with -- this layout could use fewer magic numbers Heading => Box'(Create (0, Integer (Float (H) * 0.36), W, 22, Heading_Text)), Blurb => Box'(Create (0, Integer (Float (H) * 0.53), W, 12, Blurb_Text)), Author => Box'(Create (0, Integer (Float (H) * 0.63), W, 12, Author_Text)), Dismiss => Enter_Button'(Create (W / 2 - 50, Integer (Float (H) * 0.76), 100, 40, "Close"))) do This.Add (This.Heading); This.Heading.Set_Label_Size (22); This.Add (This.Blurb); This.Add (This.Author); This.Add (This.Dismiss); This.Dismiss.Set_Callback (Hide_CB'Access); This.Set_Callback (Hide_CB'Access); end return; end Create; function Create (W, H : in Integer) return About_Window is begin return Create (0, 0, W, H, "About Adapad"); end Create; -- Find_Window functions and procedures function Create (X, Y, W, H : in Integer; Label_Text : in String) return Find_Window is begin return This : Find_Window := (Double_Window'(Create (X, Y, W, H, Label_Text)) with Placeholder => 0) do This.Set_Callback (Hide_CB'Access); end return; end Create; function Create (W, H : in Integer) return Find_Window is begin return Create (0, 0, W, H, "Find"); end Create; procedure Reset (This : in out Find_Window) is begin null; end Reset; -- Replace_Window functions and procedures function Create (X, Y, W, H : in Integer; Label_Text : in String) return Replace_Window is begin return This : Replace_Window := (Double_Window'(Create (X, Y, W, H, Label_Text)) with Placeholder => 0) do This.Set_Callback (Hide_CB'Access); end return; end Create; function Create (W, H : in Integer) return Replace_Window is begin return Create (0, 0, W, H, "Replace"); end Create; procedure Reset (This : in out Replace_Window) is begin null; end Reset; end Editor_Windows;