summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2016-11-13 14:41:26 +1100
committerJed Barber <jjbarber@y7mail.com>2016-11-13 14:41:26 +1100
commit1ff0512b833a2d310783e4373483a603b91d2707 (patch)
treed319fd9efc48bca6d1510084ebc5f0b70077f9d7
parent8908535c7dc9fc7adf3c56b96aecc49b319c5a9e (diff)
Added word wrap feature
-rw-r--r--src/adapad.adb19
-rw-r--r--src/fltk_binding/c_fl_menu.cpp13
-rw-r--r--src/fltk_binding/c_fl_menu.h5
-rw-r--r--src/fltk_binding/c_fl_text_display.cpp5
-rw-r--r--src/fltk_binding/c_fl_text_display.h1
-rw-r--r--src/fltk_binding/fltk-widgets-groups-text_displays.adb19
-rw-r--r--src/fltk_binding/fltk-widgets-groups-text_displays.ads9
-rw-r--r--src/fltk_binding/fltk-widgets-menus.adb32
-rw-r--r--src/fltk_binding/fltk-widgets-menus.ads19
-rw-r--r--src/windows-editor.adb12
-rw-r--r--src/windows-editor.ads10
-rw-r--r--to_do.txt3
12 files changed, 142 insertions, 5 deletions
diff --git a/src/adapad.adb b/src/adapad.adb
index 5f8e7d8..71b0a0b 100644
--- a/src/adapad.adb
+++ b/src/adapad.adb
@@ -11,6 +11,9 @@ with Windows.Replace;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
+with Ada.Text_IO;
+
+
package body Adapad is
@@ -218,6 +221,19 @@ package body Adapad is
+ procedure Wrap_CB
+ (Item : in out FLTK.Widgets.Widget'Class) is
+ begin
+ if FLTK.Widgets.Menus.Menu (Item).Chosen.Value then
+ Editor.Set_Wrap_Mode (Windows.Editor.Wrap_At_Bounds);
+ else
+ Editor.Set_Wrap_Mode (Windows.Editor.Wrap_None);
+ end if;
+ end Wrap_CB;
+
+
+
+
procedure About_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -443,6 +459,9 @@ begin
Bar.Add ("Search/&Replace...", Replace_CB'Access, Mod_Ctrl + 'h', Flag_Divider);
Bar.Add ("Search/&Word Count", Count_CB'Access);
+ Bar.Add (Text => "&Options", Flags => Flag_Submenu);
+ Bar.Add ("Options/&Word Wrap", Wrap_CB'Access, No_Key, Flag_Toggle);
+
Bar.Add (Text => "&Help", Flags => Flag_Submenu);
Bar.Add ("Help/&About", About_CB'Access);
end;
diff --git a/src/fltk_binding/c_fl_menu.cpp b/src/fltk_binding/c_fl_menu.cpp
index e8cbe58..0455e51 100644
--- a/src/fltk_binding/c_fl_menu.cpp
+++ b/src/fltk_binding/c_fl_menu.cpp
@@ -1,6 +1,7 @@
#include <FL/Fl_Menu_.H>
+#include <FL/Fl_Menu_Item.H>
#include "c_fl_menu.h"
@@ -8,3 +9,15 @@ int fl_menu_add(MENU m, const char * t, unsigned long s, void * c, void * u, uns
return reinterpret_cast<Fl_Menu_*>(m)->add(t, s, reinterpret_cast<Fl_Callback_p>(c), u, f);
}
+
+const void * fl_menu_mvalue(MENU m) {
+ return reinterpret_cast<Fl_Menu_*>(m)->mvalue();
+}
+
+
+
+
+int fl_menuitem_value(void * mi) {
+ return reinterpret_cast<Fl_Menu_Item*>(mi)->value();
+}
+
diff --git a/src/fltk_binding/c_fl_menu.h b/src/fltk_binding/c_fl_menu.h
index d8e8b90..1599334 100644
--- a/src/fltk_binding/c_fl_menu.h
+++ b/src/fltk_binding/c_fl_menu.h
@@ -5,9 +5,14 @@
typedef void* MENU;
+// typedef void* MENUITEM;
extern "C" int fl_menu_add(MENU m, const char * t, unsigned long s, void * c, void * u, unsigned long f);
+extern "C" const void * fl_menu_mvalue(MENU m);
+
+
+extern "C" int fl_menuitem_value(void * mi);
#endif
diff --git a/src/fltk_binding/c_fl_text_display.cpp b/src/fltk_binding/c_fl_text_display.cpp
index 5104869..d1785e2 100644
--- a/src/fltk_binding/c_fl_text_display.cpp
+++ b/src/fltk_binding/c_fl_text_display.cpp
@@ -83,3 +83,8 @@ void fl_text_display_previous_word(TEXTDISPLAY td) {
reinterpret_cast<Fl_Text_Display*>(td)->previous_word();
}
+
+void fl_text_display_wrap_mode(TEXTDISPLAY td, int w, int m) {
+ reinterpret_cast<Fl_Text_Display*>(td)->wrap_mode(w, m);
+}
+
diff --git a/src/fltk_binding/c_fl_text_display.h b/src/fltk_binding/c_fl_text_display.h
index f42ada9..2f8e089 100644
--- a/src/fltk_binding/c_fl_text_display.h
+++ b/src/fltk_binding/c_fl_text_display.h
@@ -25,6 +25,7 @@ extern "C" void fl_text_display_set_insert_pos(TEXTDISPLAY td, int p);
extern "C" void fl_text_display_show_insert_pos(TEXTDISPLAY td);
extern "C" void fl_text_display_next_word(TEXTDISPLAY td);
extern "C" void fl_text_display_previous_word(TEXTDISPLAY td);
+extern "C" void fl_text_display_wrap_mode(TEXTDISPLAY td, int w, int m);
#endif
diff --git a/src/fltk_binding/fltk-widgets-groups-text_displays.adb b/src/fltk_binding/fltk-widgets-groups-text_displays.adb
index f8418d6..71aeee0 100644
--- a/src/fltk_binding/fltk-widgets-groups-text_displays.adb
+++ b/src/fltk_binding/fltk-widgets-groups-text_displays.adb
@@ -80,6 +80,11 @@ package body FLTK.Widgets.Groups.Text_Displays is
(TD : in System.Address);
pragma Import (C, fl_text_display_previous_word, "fl_text_display_previous_word");
+ procedure fl_text_display_wrap_mode
+ (TD : in System.Address;
+ W, M : in Interfaces.C.int);
+ pragma Import (C, fl_text_display_wrap_mode, "fl_text_display_wrap_mode");
+
@@ -245,5 +250,19 @@ package body FLTK.Widgets.Groups.Text_Displays is
end Previous_Word;
+
+
+ procedure Set_Wrap_Mode
+ (This : in out Text_Display;
+ Mode : in Wrap_Mode;
+ Margin : in Natural := 0) is
+ begin
+ fl_text_display_wrap_mode
+ (This.Void_Ptr,
+ Wrap_Mode'Pos (Mode),
+ Interfaces.C.int (Margin));
+ end Set_Wrap_Mode;
+
+
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 3eea299..a55b28f 100644
--- a/src/fltk_binding/fltk-widgets-groups-text_displays.ads
+++ b/src/fltk_binding/fltk-widgets-groups-text_displays.ads
@@ -10,6 +10,9 @@ package FLTK.Widgets.Groups.Text_Displays is
type Text_Display is new Group with private;
+ type Wrap_Mode is (Wrap_None, Wrap_At_Column, Wrap_At_Pixel, Wrap_At_Bounds);
+
+
function Create
(X, Y, W, H : in Integer;
Text : in String)
@@ -78,6 +81,12 @@ package FLTK.Widgets.Groups.Text_Displays is
(This : in out Text_Display);
+ procedure Set_Wrap_Mode
+ (This : in out Text_Display;
+ Mode : in Wrap_Mode;
+ Margin : in Natural := 0);
+
+
private
diff --git a/src/fltk_binding/fltk-widgets-menus.adb b/src/fltk_binding/fltk-widgets-menus.adb
index 0f50fc8..169e71d 100644
--- a/src/fltk_binding/fltk-widgets-menus.adb
+++ b/src/fltk_binding/fltk-widgets-menus.adb
@@ -91,6 +91,16 @@ package body FLTK.Widgets.Menus is
return Interfaces.C.int;
pragma Import (C, fl_menu_add, "fl_menu_add");
+ function fl_menu_mvalue
+ (M : in System.Address)
+ return System.Address;
+ pragma Import (C, fl_menu_mvalue, "fl_menu_mvalue");
+
+ function fl_menuitem_value
+ (MI : in System.Address)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menuitem_value, "fl_menuitem_value");
+
@@ -138,5 +148,27 @@ package body FLTK.Widgets.Menus is
end Add;
+
+
+ function Chosen
+ (This : in Menu'Class)
+ return Menu_Item is
+ begin
+ return Item : Menu_Item do
+ Item.Void_Ptr := fl_menu_mvalue (This.Void_Ptr);
+ end return;
+ end Chosen;
+
+
+
+
+ function Value
+ (Item : in Menu_Item)
+ return Boolean is
+ begin
+ return fl_menuitem_value (Item.Void_Ptr) /= 0;
+ end Value;
+
+
end FLTK.Widgets.Menus;
diff --git a/src/fltk_binding/fltk-widgets-menus.ads b/src/fltk_binding/fltk-widgets-menus.ads
index 27b9d4a..cf6fcf7 100644
--- a/src/fltk_binding/fltk-widgets-menus.ads
+++ b/src/fltk_binding/fltk-widgets-menus.ads
@@ -12,9 +12,7 @@ package FLTK.Widgets.Menus is
with Implicit_Dereference => Data;
- type Menu_Item is private;
- type Menu_Item_Cursor (Data : access Menu_Item) is limited null record
- with Implicit_Dereference => Data;
+ type Menu_Item is tagged limited private;
type Index is new Positive;
@@ -62,13 +60,26 @@ package FLTK.Widgets.Menus is
Flags : in Menu_Flag := Flag_Normal);
+ function Chosen
+ (This : in Menu'Class)
+ return Menu_Item;
+
+
+ function Value
+ (Item : in Menu_Item)
+ return Boolean;
+
+
private
type Menu is abstract new Widget with null record;
- type Menu_Item is new System.Address;
+ type Menu_Item is tagged limited
+ record
+ Void_Ptr : System.Address;
+ end record;
-- these values designed to align with FLTK enumeration types
diff --git a/src/windows-editor.adb b/src/windows-editor.adb
index bbaa069..e9195dd 100644
--- a/src/windows-editor.adb
+++ b/src/windows-editor.adb
@@ -11,6 +11,7 @@ package body Windows.Editor is
package WD renames FLTK.Widgets.Groups.Windows.Double;
+ package TD renames FLTK.Widgets.Groups.Text_Displays;
package TE renames FLTK.Widgets.Groups.Text_Displays.Text_Editors;
package MB renames FLTK.Widgets.Menus.Menu_Bars;
@@ -185,5 +186,16 @@ package body Windows.Editor is
end Previous_Word;
+
+
+ procedure Set_Wrap_Mode
+ (This : in out Editor_Window;
+ Mode : in Wrap_Mode;
+ Margin : in Natural := 0) is
+ begin
+ This.Editor.Set_Wrap_Mode (TD.Wrap_Mode (Mode), Margin);
+ end Set_Wrap_Mode;
+
+
end Windows.Editor;
diff --git a/src/windows-editor.ads b/src/windows-editor.ads
index 46e0fe6..d2874ed 100644
--- a/src/windows-editor.ads
+++ b/src/windows-editor.ads
@@ -3,6 +3,7 @@
with FLTK.Widgets.Groups.Windows.Double;
with FLTK.Widgets.Menus;
with FLTK.Text_Buffers;
+with FLTK.Widgets.Groups.Text_Displays;
private with FLTK.Widgets.Groups.Text_Displays.Text_Editors;
private with FLTK.Widgets.Menus.Menu_Bars;
@@ -13,6 +14,9 @@ package Windows.Editor is
type Editor_Window is new FLTK.Widgets.Groups.Windows.Double.Double_Window with private;
+ type Wrap_Mode is new FLTK.Widgets.Groups.Text_Displays.Wrap_Mode;
+
+
Min_Editor_Height : Integer := 60;
Min_Editor_Width : Integer := 300;
@@ -85,6 +89,12 @@ package Windows.Editor is
(This : in out Editor_Window);
+ procedure Set_Wrap_Mode
+ (This : in out Editor_Window;
+ Mode : in Wrap_Mode;
+ Margin : in Natural := 0);
+
+
private
diff --git a/to_do.txt b/to_do.txt
index 402f395..8b27742 100644
--- a/to_do.txt
+++ b/to_do.txt
@@ -4,9 +4,10 @@ To Do:
- change build to be dynamically linked
- improve find, replace, undo/redo, word count
-- add jump to, line numbers, word wrap
+- add jump to, line numbers
- suppress unnecessary left/right scrollbar
- make logo colours lighter to stand out more
+- clean up menu widget code
- separate fltk binding into its own repo
- add license