From 0f9b0b9259ada50de7f8866f9591ce4ad3e7eadc Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 13 Nov 2016 14:41:26 +1100 Subject: Added word wrap feature --- c_fl_menu.cpp | 13 +++++++++++++ c_fl_menu.h | 5 +++++ c_fl_text_display.cpp | 5 +++++ c_fl_text_display.h | 1 + fltk-widgets-groups-text_displays.adb | 19 +++++++++++++++++++ fltk-widgets-groups-text_displays.ads | 9 +++++++++ fltk-widgets-menus.adb | 32 ++++++++++++++++++++++++++++++++ fltk-widgets-menus.ads | 19 +++++++++++++++---- 8 files changed, 99 insertions(+), 4 deletions(-) diff --git a/c_fl_menu.cpp b/c_fl_menu.cpp index e8cbe58..0455e51 100644 --- a/c_fl_menu.cpp +++ b/c_fl_menu.cpp @@ -1,6 +1,7 @@ #include +#include #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(m)->add(t, s, reinterpret_cast(c), u, f); } + +const void * fl_menu_mvalue(MENU m) { + return reinterpret_cast(m)->mvalue(); +} + + + + +int fl_menuitem_value(void * mi) { + return reinterpret_cast(mi)->value(); +} + diff --git a/c_fl_menu.h b/c_fl_menu.h index d8e8b90..1599334 100644 --- a/c_fl_menu.h +++ b/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/c_fl_text_display.cpp b/c_fl_text_display.cpp index 5104869..d1785e2 100644 --- a/c_fl_text_display.cpp +++ b/c_fl_text_display.cpp @@ -83,3 +83,8 @@ void fl_text_display_previous_word(TEXTDISPLAY td) { reinterpret_cast(td)->previous_word(); } + +void fl_text_display_wrap_mode(TEXTDISPLAY td, int w, int m) { + reinterpret_cast(td)->wrap_mode(w, m); +} + diff --git a/c_fl_text_display.h b/c_fl_text_display.h index f42ada9..2f8e089 100644 --- a/c_fl_text_display.h +++ b/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/fltk-widgets-groups-text_displays.adb b/fltk-widgets-groups-text_displays.adb index f8418d6..71aeee0 100644 --- a/fltk-widgets-groups-text_displays.adb +++ b/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/fltk-widgets-groups-text_displays.ads b/fltk-widgets-groups-text_displays.ads index 3eea299..a55b28f 100644 --- a/fltk-widgets-groups-text_displays.ads +++ b/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/fltk-widgets-menus.adb b/fltk-widgets-menus.adb index 0f50fc8..169e71d 100644 --- a/fltk-widgets-menus.adb +++ b/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/fltk-widgets-menus.ads b/fltk-widgets-menus.ads index 27b9d4a..cf6fcf7 100644 --- a/fltk-widgets-menus.ads +++ b/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 -- cgit