summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2016-09-21 23:34:15 +1000
committerJed Barber <jjbarber@y7mail.com>2016-09-21 23:34:15 +1000
commit678d77f43136347199e7d4bfddaca4e634e02dc3 (patch)
tree2fdfef2d9b1be0236de1a9b6a2db6fa578e3a2df
parentf8fc211b41dbfa43f9cace75ffdc1d43c0ab8114 (diff)
More progress on the little utility window layouts
-rw-r--r--src/adapad.adb18
-rw-r--r--src/editor_windows.adb48
-rw-r--r--src/editor_windows.ads21
-rw-r--r--src/fltk_binding/c_fl_group.cpp5
-rw-r--r--src/fltk_binding/c_fl_group.h1
-rw-r--r--src/fltk_binding/c_fl_window.cpp5
-rw-r--r--src/fltk_binding/c_fl_window.h1
-rw-r--r--src/fltk_binding/fltk-widgets-groups-windows.adb25
-rw-r--r--src/fltk_binding/fltk-widgets-groups-windows.ads7
-rw-r--r--src/fltk_binding/fltk-widgets-groups.adb14
-rw-r--r--src/fltk_binding/fltk-widgets-groups.ads5
11 files changed, 133 insertions, 17 deletions
diff --git a/src/adapad.adb b/src/adapad.adb
index d1f895f..03ace13 100644
--- a/src/adapad.adb
+++ b/src/adapad.adb
@@ -17,10 +17,7 @@ with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
-with Ada.Text_IO;
-
-
-function AdaPad return Integer is
+function Adapad return Integer is
-- forward declarations of helper functions
@@ -38,9 +35,9 @@ function AdaPad return Integer is
-- global state of the text editor
- Editor : Editor_Window := Create (0, 0, 640, 400, "(Untitled)");
+ Editor : Editor_Window := Create (800, 500);
Buffer : Text_Buffer := Create;
- About : About_Window := Create (250, 200);
+ About : About_Window := Create (350, 250);
Find : Find_Window := Create (200, 100);
Replace : Replace_Window := Create (200, 100);
@@ -124,6 +121,8 @@ function AdaPad return Integer is
Item : in out Widget'Class) is
begin
if not Safe_To_Discard then return; end if;
+ Find.Hide;
+ Replace.Hide;
About.Hide;
Editor.Hide;
end Call;
@@ -391,11 +390,11 @@ begin
Bar.Add ("File/&Quit", Quit_CB'Access, Mod_Ctrl + 'q');
Bar.Add (Text => "&Edit", Flags => Flag_Submenu);
- Bar.Add ("Edit/&Undo", Undo_CB'Access, Mod_Ctrl + 'z', Flag_Divider);
+ Bar.Add ("Edit/&Undo", Undo_CB'Access, Mod_Ctrl + 'z', Flag_Divider);
Bar.Add ("Edit/Cu&t", Cut_CB'Access, Mod_Ctrl + 'x');
Bar.Add ("Edit/&Copy", Copy_CB'Access, Mod_Ctrl + 'c');
Bar.Add ("Edit/&Paste", Paste_CB'Access, Mod_Ctrl + 'v');
- Bar.Add ("Edit/&Delete", Delete_CB'Access, No_Key, Flag_Divider);
+ Bar.Add ("Edit/&Delete", Delete_CB'Access, No_Key, Flag_Divider);
Bar.Add ("Edit/Select &All", Select_All_CB'Access, Mod_Ctrl + 'a');
Bar.Add (Text => "&Search", Flags => Flag_Submenu);
@@ -408,10 +407,11 @@ begin
Buffer.Add_Modify_Callback (Mod_CB'Access);
+ Editor.Set_Callback (Quit_CB'Access);
Editor.Set_Buffer (Buffer);
Editor.Show;
return FLTK.Run;
-end AdaPad;
+end Adapad;
diff --git a/src/editor_windows.adb b/src/editor_windows.adb
index 4fdf2ae..64b1cf0 100644
--- a/src/editor_windows.adb
+++ b/src/editor_windows.adb
@@ -21,8 +21,17 @@ package body Editor_Windows is
Width, Height : Integer;
begin
- if W < 300 then Width := 300; else Width := W; end if;
- if H < 60 then Height := 60; else Height := H; end if;
+ 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
@@ -31,6 +40,8 @@ package body Editor_Windows is
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;
@@ -131,8 +142,18 @@ package body Editor_Windows is
(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;
@@ -146,19 +167,30 @@ package body Editor_Windows is
Label_Text : in String)
return About_Window is
- Heading_Text : String := "AdaPad 0.9";
+ Heading_Text : String := "Adapad 0.5";
Blurb_Text : String := "FLTK based simple text editor written in Ada";
- Author_Text : String := "Written by Jed Barber";
+ Author_Text : String := "Programmed by Jed Barber";
begin
return This : About_Window :=
(Double_Window'(Create (X, Y, W, H, Label_Text)) with
- Heading => Box'(Create (0, Y * 7 / 16, W, H / 8, Heading_Text)),
- Blurb => Box'(Create (0, Y * 10 / 16, W, H / 8, Blurb_Text)),
- Author => Box'(Create (0, Y * 12 / 16, W, H / 8, Author_Text))) do
+
+ -- 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;
@@ -170,7 +202,7 @@ package body Editor_Windows is
(W, H : in Integer)
return About_Window is
begin
- return Create (0, 0, W, H, "About AdaPad");
+ return Create (0, 0, W, H, "About Adapad");
end Create;
diff --git a/src/editor_windows.ads b/src/editor_windows.ads
index 9665b02..d90b696 100644
--- a/src/editor_windows.ads
+++ b/src/editor_windows.ads
@@ -10,6 +10,10 @@ private with FLTK.Widgets.Groups.Text_Displays.Text_Editors;
private with FLTK.Widgets.Menus.Menu_Bars;
private with FLTK.Widgets.Boxes;
private with FLTK.Widgets;
+private with FLTK.Widgets.Inputs;
+private with FLTK.Widgets.Buttons;
+private with FLTK.Widgets.Buttons.Enter;
+private with FLTK.Widgets.Buttons.Light.Check;
package Editor_Windows is
@@ -18,6 +22,10 @@ package Editor_Windows is
type Editor_Window is new Double_Window with private;
+ Min_Editor_Height : Integer := 60;
+ Min_Editor_Width : Integer := 300;
+
+
function Create
(X, Y, W, H : in Integer;
Label_Text : in String)
@@ -112,6 +120,10 @@ private
use FLTK.Widgets.Menus.Menu_Bars;
use FLTK.Widgets.Boxes;
use FLTK.Widgets;
+ use FLTK.Widgets.Inputs;
+ use FLTK.Widgets.Buttons;
+ use FLTK.Widgets.Buttons.Enter;
+ use FLTK.Widgets.Buttons.Light.Check;
type Editor_Window is new Double_Window with
@@ -132,17 +144,26 @@ private
Heading : Box;
Blurb : Box;
Author : Box;
+ Dismiss : Enter_Button;
end record;
type Find_Window is new Double_Window with
record
+ -- Find_What : Input;
+ -- Match_Case : Check_Button;
+ -- Cancel : Button;
+ -- Start : Enter_Button;
Placeholder : Integer;
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;
end record;
diff --git a/src/fltk_binding/c_fl_group.cpp b/src/fltk_binding/c_fl_group.cpp
index 8adc9dd..9ea2764 100644
--- a/src/fltk_binding/c_fl_group.cpp
+++ b/src/fltk_binding/c_fl_group.cpp
@@ -51,6 +51,11 @@ void fl_group_remove2(GROUP g, int place) {
}
+void fl_group_resizable(GROUP g, WIDGET item) {
+ reinterpret_cast<Fl_Group*>(g)->resizable(reinterpret_cast<Fl_Widget*>(item));
+}
+
+
int fl_group_children(GROUP g) {
diff --git a/src/fltk_binding/c_fl_group.h b/src/fltk_binding/c_fl_group.h
index 3c7a8fb..9b58f8c 100644
--- a/src/fltk_binding/c_fl_group.h
+++ b/src/fltk_binding/c_fl_group.h
@@ -19,6 +19,7 @@ extern "C" int fl_group_find(GROUP g, WIDGET item);
extern "C" void fl_group_insert(GROUP g, WIDGET item, int place);
extern "C" void fl_group_remove(GROUP g, WIDGET item);
extern "C" void fl_group_remove2(GROUP g, int place);
+extern "C" void fl_group_resizable(GROUP g, WIDGET item);
extern "C" int fl_group_children(GROUP g);
extern "C" void * fl_group_child(GROUP g, int place);
diff --git a/src/fltk_binding/c_fl_window.cpp b/src/fltk_binding/c_fl_window.cpp
index 5b2d0ff..9c8dbc6 100644
--- a/src/fltk_binding/c_fl_window.cpp
+++ b/src/fltk_binding/c_fl_window.cpp
@@ -35,3 +35,8 @@ void fl_window_set_label(WINDOW n, char* text) {
reinterpret_cast<Fl_Window*>(n)->copy_label(text);
}
+
+void fl_window_size_range(WINDOW n, int lw, int lh, int hw, int hh, int dw, int dh, int a) {
+ reinterpret_cast<Fl_Window*>(n)->size_range(lw, lh, hw, hh, dw, dh, a);
+}
+
diff --git a/src/fltk_binding/c_fl_window.h b/src/fltk_binding/c_fl_window.h
index 8d38de0..526811a 100644
--- a/src/fltk_binding/c_fl_window.h
+++ b/src/fltk_binding/c_fl_window.h
@@ -14,6 +14,7 @@ extern "C" void free_fl_window(WINDOW n);
extern "C" void fl_window_show(WINDOW n);
extern "C" void fl_window_hide(WINDOW n);
extern "C" void fl_window_set_label(WINDOW n, char* text);
+extern "C" void fl_window_size_range(WINDOW n, int lw, int lh, int hw, int hh, int dw, int dh, int a);
#endif
diff --git a/src/fltk_binding/fltk-widgets-groups-windows.adb b/src/fltk_binding/fltk-widgets-groups-windows.adb
index 4ecda66..a0262e1 100644
--- a/src/fltk_binding/fltk-widgets-groups-windows.adb
+++ b/src/fltk_binding/fltk-widgets-groups-windows.adb
@@ -36,6 +36,11 @@ package body FLTK.Widgets.Groups.Windows is
T : in Interfaces.C.char_array);
pragma Import (C, fl_window_set_label, "fl_window_set_label");
+ procedure fl_window_size_range
+ (W : in System.Address;
+ LW, LH, HW, HH, DW, DH, A : in Interfaces.C.int);
+ pragma Import (C, fl_window_size_range, "fl_window_size_range");
+
@@ -119,5 +124,25 @@ package body FLTK.Widgets.Groups.Windows is
end Set_Label;
+
+
+ procedure Set_Size_Range
+ (This : in out Window;
+ Min_W, Min_H : in Integer;
+ Max_W, Max_H, Incre_W, Incre_H : in Integer := 0;
+ Keep_Aspect : in Boolean := False) is
+ begin
+ fl_window_size_range
+ (This.Void_Ptr,
+ Interfaces.C.int (Min_W),
+ Interfaces.C.int (Min_H),
+ Interfaces.C.int (Max_W),
+ Interfaces.C.int (Max_H),
+ Interfaces.C.int (Incre_W),
+ Interfaces.C.int (Incre_H),
+ Boolean'Pos (Keep_Aspect));
+ end Set_Size_Range;
+
+
end FLTK.Widgets.Groups.Windows;
diff --git a/src/fltk_binding/fltk-widgets-groups-windows.ads b/src/fltk_binding/fltk-widgets-groups-windows.ads
index 0999b21..2213563 100644
--- a/src/fltk_binding/fltk-widgets-groups-windows.ads
+++ b/src/fltk_binding/fltk-widgets-groups-windows.ads
@@ -30,6 +30,13 @@ package FLTK.Widgets.Groups.Windows is
Text : in String);
+ procedure Set_Size_Range
+ (This : in out Window;
+ Min_W, Min_H : in Integer;
+ Max_W, Max_H, Incre_W, Incre_H : in Integer := 0;
+ Keep_Aspect : in Boolean := False);
+
+
private
diff --git a/src/fltk_binding/fltk-widgets-groups.adb b/src/fltk_binding/fltk-widgets-groups.adb
index 32753ea..3ffd1e3 100644
--- a/src/fltk_binding/fltk-widgets-groups.adb
+++ b/src/fltk_binding/fltk-widgets-groups.adb
@@ -52,6 +52,10 @@ package body FLTK.Widgets.Groups is
return System.Address;
pragma Import (C, fl_group_child, "fl_group_child");
+ procedure fl_group_resizable
+ (G, W : in System.Address);
+ pragma Import (C, fl_group_resizable, "fl_group_resizable");
+
@@ -185,5 +189,15 @@ package body FLTK.Widgets.Groups is
end Remove;
+
+
+ procedure Set_Resizable
+ (This : in out Group;
+ Item : in Widget'Class) is
+ begin
+ fl_group_resizable (This.Void_Ptr, Item.Void_Ptr);
+ end Set_Resizable;
+
+
end FLTK.Widgets.Groups;
diff --git a/src/fltk_binding/fltk-widgets-groups.ads b/src/fltk_binding/fltk-widgets-groups.ads
index 7d6e59b..e777f04 100644
--- a/src/fltk_binding/fltk-widgets-groups.ads
+++ b/src/fltk_binding/fltk-widgets-groups.ads
@@ -58,6 +58,11 @@ package FLTK.Widgets.Groups is
Place : in Index);
+ procedure Set_Resizable
+ (This : in out Group;
+ Item : in Widget'Class);
+
+
private