summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2016-10-03 20:22:29 +1100
committerJed Barber <jjbarber@y7mail.com>2016-10-03 20:22:29 +1100
commitff006c440b90f1fdcfc47f8d809e07fbe54951ac (patch)
tree8caedef72cc2fadef1b99ba684fccfa26b3684cb
parent678d77f43136347199e7d4bfddaca4e634e02dc3 (diff)
Find/Replace window appearance added
-rw-r--r--src/adapad.adb8
-rw-r--r--src/editor_windows.adb204
-rw-r--r--src/editor_windows.ads37
3 files changed, 192 insertions, 57 deletions
diff --git a/src/adapad.adb b/src/adapad.adb
index 03ace13..7ba743e 100644
--- a/src/adapad.adb
+++ b/src/adapad.adb
@@ -37,9 +37,9 @@ function Adapad return Integer is
Editor : Editor_Window := Create (800, 500);
Buffer : Text_Buffer := Create;
- About : About_Window := Create (350, 250);
- Find : Find_Window := Create (200, 100);
- Replace : Replace_Window := Create (200, 100);
+ About : About_Window := Create;
+ Find : Find_Window := Create;
+ Replace : Replace_Window := Create;
Changed : Boolean := False;
Filename : Unbounded_String := To_Unbounded_String (0);
@@ -216,7 +216,6 @@ function Adapad return Integer is
Item : in out Widget'Class) is
begin
Centre (Find);
- Find.Reset;
Find.Show;
end Call;
@@ -231,7 +230,6 @@ function Adapad return Integer is
Item : in out Widget'Class) is
begin
Centre (Replace);
- Replace.Reset;
Replace.Show;
end Call;
diff --git a/src/editor_windows.adb b/src/editor_windows.adb
index 64b1cf0..f4a1151 100644
--- a/src/editor_windows.adb
+++ b/src/editor_windows.adb
@@ -18,27 +18,30 @@ package body Editor_Windows is
Label_Text : in String)
return Editor_Window is
- Width, Height : Integer;
+ Width : Integer := Min_Editor_Width;
+ Height : Integer := Min_Editor_Height;
+ Menu_Height : Integer := 22;
begin
- if W < Min_Editor_Width then
- Width := Min_Editor_Width;
- else
+ if Width < W then
Width := W;
end if;
- if H < Min_Editor_Height then
- Height := Min_Editor_Height;
- else
+ if Height < H then
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
+
+ Editor => Text_Editor'(Create
+ (0, Menu_Height, Width, Height - Menu_Height, "")),
+ Bar => Menu_Bar'(Create
+ (0, 0, Width, Menu_Height, ""))) do
+
This.Add (This.Editor);
This.Add (This.Bar);
+ This.Bar.Set_Box (No_Box);
This.Editor.Set_Text_Font (Courier);
This.Set_Resizable (This.Editor);
This.Set_Size_Range (Min_Editor_Width, Min_Editor_Height);
@@ -162,31 +165,40 @@ package body Editor_Windows is
-- About_Window functions and procedures
- function Create
- (X, Y, W, H : in Integer;
- Label_Text : in String)
- return About_Window is
+ function Create return About_Window is
+ My_Width : Integer := 350;
+ My_Height : Integer := 250;
+
+ Button_Width : Integer := 140;
+ Button_Height : Integer := 40;
+
+ Heading_Line : Integer := 90;
+ Blurb_Line : Integer := 132;
+ Author_Line : Integer := 157;
+ Button_Line : Integer := 190;
+
+ Heading_Size : Integer := 22;
+ Text_Size : Integer := 12;
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
+ (Double_Window'(Create (0, 0, My_Width, My_Height, "About Adapad")) with
- -- this layout could use fewer magic numbers
Heading => Box'(Create
- (0, Integer (Float (H) * 0.36), W, 22, Heading_Text)),
+ (0, Heading_Line, My_Width, Heading_Size, Heading_Text)),
Blurb => Box'(Create
- (0, Integer (Float (H) * 0.53), W, 12, Blurb_Text)),
+ (0, Blurb_Line, My_Width, Text_Size, Blurb_Text)),
Author => Box'(Create
- (0, Integer (Float (H) * 0.63), W, 12, Author_Text)),
+ (0, Author_Line, My_Width, Text_Size, Author_Text)),
Dismiss => Enter_Button'(Create
- (W / 2 - 50, Integer (Float (H) * 0.76), 100, 40, "Close"))) do
+ ((My_Width - Button_Width) / 2,
+ Button_Line, Button_Width, Button_Height, "Close"))) do
This.Add (This.Heading);
- This.Heading.Set_Label_Size (22);
+ This.Heading.Set_Label_Size (Font_Size (Heading_Size));
This.Add (This.Blurb);
This.Add (This.Author);
This.Add (This.Dismiss);
@@ -199,10 +211,21 @@ package body Editor_Windows is
function Create
+ (X, Y, W, H : in Integer;
+ Label_Text : in String)
+ return About_Window is
+ begin
+ return Create;
+ end Create;
+
+
+
+
+ function Create
(W, H : in Integer)
return About_Window is
begin
- return Create (0, 0, W, H, "About Adapad");
+ return Create;
end Create;
@@ -210,16 +233,60 @@ package body Editor_Windows is
-- Find_Window functions and procedures
+ function Create return Find_Window is
+ My_Width : Integer := 350;
+ My_Height : Integer := 130;
+
+ Button_Width : Integer := 140;
+ Button_Height : Integer := 40;
+
+ Input_Line : Integer := 10;
+ Case_Line : Integer := 50;
+ Button_Line : Integer := 80;
+
+ Input_Width : Integer := 240;
+ Input_Height : Integer := 25;
+ Input_Margin_Right : Integer := 10;
+
+ Check_Width : Integer := 100;
+ Check_Height : Integer := 20;
+ Case_Margin_Left : Integer := 50;
+
+ Text_Size : Integer := 12;
+ begin
+ return This : Find_Window :=
+ (Double_Window'(Create (0, 0, My_Width, My_Height, "Find")) with
+
+ Find_What => Input'(Create
+ (My_Width - Input_Width - Input_Margin_Right,
+ Input_Line, Input_Width, Input_Height, "Find what:")),
+ Match_Case => Check_Button'(Create
+ (Case_Margin_Left, Case_Line, Check_Width, Check_Height, "Match case")),
+ Cancel => Button'(Create
+ ((My_Width - 2 * Button_Width) / 3,
+ 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
+
+ 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.Set_Callback (Hide_CB'Access);
+ end return;
+ end Create;
+
+
+
+
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;
+ return Create;
end Create;
@@ -229,33 +296,89 @@ package body Editor_Windows is
(W, H : in Integer)
return Find_Window is
begin
- return Create (0, 0, W, H, "Find");
+ return Create;
end Create;
- procedure Reset
- (This : in out Find_Window) is
+ procedure Set_Function
+ (This : in out Find_Window;
+ Func : access procedure (Item : in String)) is
begin
null;
- end Reset;
+ end Set_Function;
-- Replace_Window functions and procedures
+ function Create return Replace_Window is
+ My_Width : Integer := 350;
+ My_Height : Integer := 180;
+
+ Button_Width : Integer := 140;
+ Button_Height : Integer := 40;
+
+ Find_Line : Integer := 10;
+ Replace_Line : Integer := 40;
+ Match_Line : Integer := 80;
+ Rep_All_Line : Integer := 100;
+ Button_Line : Integer := 130;
+
+ Input_Width : Integer := 220;
+ Input_Height : Integer := 25;
+ Input_Margin_Right : Integer := 10;
+
+ Check_Width : Integer := 100;
+ Check_Height : Integer := 20;
+ Check_Margin_Left : Integer := 50;
+
+ Text_Size : Integer := 12;
+ begin
+ return This : Replace_Window :=
+ (Double_Window'(Create (0, 0, My_Width, My_Height, "Replace")) with
+
+ Find_What => Input'(Create
+ (My_Width - Input_Width - Input_Margin_Right,
+ Find_Line, Input_Width, Input_Height, "Find what:")),
+ Replace_With => Input'(Create
+ (My_Width - Input_Width - Input_Margin_Right,
+ Replace_Line, Input_Width, Input_Height, "Replace with:")),
+ Match_Case => Check_Button'(Create
+ (Check_Margin_Left, Match_Line,
+ Check_Width, Check_Height, "Match case")),
+ Replace_All => Check_Button'(Create
+ (Check_Margin_Left, Rep_All_Line,
+ Check_Width, Check_Height, "Replace all")),
+ Cancel => Button'(Create
+ ((My_Width - 2 * Button_Width) / 3,
+ 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
+
+ This.Add (This.Find_What);
+ This.Add (This.Replace_With);
+ This.Add (This.Match_Case);
+ This.Add (This.Replace_All);
+ This.Add (This.Cancel);
+ This.Cancel.Set_Callback (Hide_CB'Access);
+ This.Add (This.Start);
+ This.Set_Callback (Hide_CB'Access);
+ end return;
+ end Create;
+
+
+
+
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;
+ return Create;
end Create;
@@ -265,17 +388,18 @@ package body Editor_Windows is
(W, H : in Integer)
return Replace_Window is
begin
- return Create (0, 0, W, H, "Replace");
+ return Create;
end Create;
- procedure Reset
- (This : in out Replace_Window) is
+ procedure Set_Function
+ (This : in out Replace_Window;
+ Func : access procedure (Item : in String)) is
begin
null;
- end Reset;
+ end Set_Function;
end Editor_Windows;
diff --git a/src/editor_windows.ads b/src/editor_windows.ads
index d90b696..6fede6d 100644
--- a/src/editor_windows.ads
+++ b/src/editor_windows.ads
@@ -64,6 +64,9 @@ package Editor_Windows is
type About_Window is new Double_Window with private;
+ function Create return About_Window;
+
+
function Create
(X, Y, W, H : in Integer;
Label_Text : in String)
@@ -80,6 +83,9 @@ package Editor_Windows is
type Find_Window is new Double_Window with private;
+ function Create return Find_Window;
+
+
function Create
(X, Y, W, H : in Integer;
Label_Text : in String)
@@ -91,7 +97,9 @@ package Editor_Windows is
return Find_Window;
- procedure Reset (This : in out Find_Window);
+ procedure Set_Function
+ (This : in out Find_Window;
+ Func : access procedure (Item : in String));
@@ -99,6 +107,9 @@ package Editor_Windows is
type Replace_Window is new Double_Window with private;
+ function Create return Replace_Window;
+
+
function Create
(X, Y, W, H : in Integer;
Label_Text : in String)
@@ -110,7 +121,9 @@ package Editor_Windows is
return Replace_Window;
- procedure Reset (This : in out Replace_Window);
+ procedure Set_Function
+ (This : in out Replace_Window;
+ Func : access procedure (Item : in String));
private
@@ -150,21 +163,21 @@ private
type Find_Window is new Double_Window with
record
- -- Find_What : Input;
- -- Match_Case : Check_Button;
- -- Cancel : Button;
- -- Start : Enter_Button;
- Placeholder : Integer;
+ Find_What : Input;
+ Match_Case : Check_Button;
+ Cancel : Button;
+ Start : Enter_Button;
+ -- callback
end record;
type Replace_Window is new Double_Window with
record
- -- Find_What, Replace_With : Input;
- -- Match_Case, Replace_All : Check_Button;
- -- Cancel : Button;
- -- Start : Enter_Button;
- Placeholder : Integer;
+ Find_What, Replace_With : Input;
+ Match_Case, Replace_All : Check_Button;
+ Cancel : Button;
+ Start : Enter_Button;
+ -- callback
end record;