summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2018-05-15 14:52:00 +1000
committerJed Barber <jjbarber@y7mail.com>2018-05-15 14:52:00 +1000
commit1cd018b440f80601f60908c2e5675413f5c77e25 (patch)
tree765af2fb514b04ec270cdddc5100ba674a8bd0a8 /src
parentfefc9bf753a8595eaa75ce51eb71eb553f4bbaaf (diff)
Finished and polished FLTK.Widgets.Menus, fixed some off-by-one errors in Groups
Diffstat (limited to 'src')
-rw-r--r--src/c_fl_menu.cpp150
-rw-r--r--src/c_fl_menu.h37
-rw-r--r--src/c_fl_menuitem.cpp8
-rw-r--r--src/c_fl_menuitem.h2
-rw-r--r--src/fltk-menu_items.adb28
-rw-r--r--src/fltk-menu_items.ads10
-rw-r--r--src/fltk-widgets-groups.adb18
-rw-r--r--src/fltk-widgets-groups.ads4
-rw-r--r--src/fltk-widgets-menus.adb603
-rw-r--r--src/fltk-widgets-menus.ads257
10 files changed, 1074 insertions, 43 deletions
diff --git a/src/c_fl_menu.cpp b/src/c_fl_menu.cpp
index e68be4c..411efde 100644
--- a/src/c_fl_menu.cpp
+++ b/src/c_fl_menu.cpp
@@ -1,6 +1,7 @@
#include <FL/Fl_Menu_.H>
+#include <FL/Fl_Menu_Item.H>
#include "c_fl_menu.h"
#include "c_fl_type.h"
@@ -51,14 +52,161 @@ void free_fl_menu(MENU m) {
int fl_menu_add(MENU m, const char * t, unsigned long s, void * c, void * u, unsigned long f) {
- return reinterpret_cast<Fl_Menu_*>(m)->add(t, s, reinterpret_cast<Fl_Callback_p>(c), u, f);
+ return reinterpret_cast<Fl_Menu_*>(m)->add(t,s,reinterpret_cast<Fl_Callback_p>(c),u,f);
+}
+
+int fl_menu_insert(MENU m, int p, const char * t, unsigned long s, void * c, void * u, unsigned long f) {
+ return reinterpret_cast<Fl_Menu_*>(m)->insert(p,t,s,reinterpret_cast<Fl_Callback_p>(c),u,f);
+}
+
+void fl_menu_remove(MENU m, int p) {
+ reinterpret_cast<Fl_Menu_*>(m)->remove(p);
+}
+
+void fl_menu_clear(MENU m) {
+ reinterpret_cast<Fl_Menu_*>(m)->clear();
+}
+
+
+
+
+const void * fl_menu_get_item(MENU m, int i) {
+ return &(reinterpret_cast<Fl_Menu_*>(m)->menu()[i]);
}
const void * fl_menu_find_item(MENU m, const char * t) {
return reinterpret_cast<Fl_Menu_*>(m)->find_item(t);
}
+const void * fl_menu_find_item2(MENU m, void * cb) {
+ // have to loop through the array manually since callbacks are stored in userdata
+ for (int i=0; i<fl_menu_size(m); i++) {
+ if (reinterpret_cast<Fl_Menu_*>(m)->menu()[i].user_data() == cb) {
+ return fl_menu_get_item(m,i);
+ }
+ }
+ return 0;
+}
+
+int fl_menu_find_index(MENU m, const char * t) {
+ return reinterpret_cast<Fl_Menu_*>(m)->find_index(t);
+}
+
+int fl_menu_find_index2(MENU m, void * i) {
+ return reinterpret_cast<Fl_Menu_*>(m)->find_index(reinterpret_cast<Fl_Menu_Item*>(i));
+}
+
+int fl_menu_find_index3(MENU m, void * cb) {
+ // have to loop through the array manually since callbacks are stored in userdata
+ for (int i=0; i<fl_menu_size(m); i++) {
+ if (reinterpret_cast<Fl_Menu_*>(m)->menu()[i].user_data() == cb) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+int fl_menu_size(MENU m) {
+ return reinterpret_cast<Fl_Menu_*>(m)->size();
+}
+
+
+
+
const void * fl_menu_mvalue(MENU m) {
return reinterpret_cast<Fl_Menu_*>(m)->mvalue();
}
+const char * fl_menu_text(MENU m) {
+ return reinterpret_cast<Fl_Menu_*>(m)->text();
+}
+
+int fl_menu_value(MENU m) {
+ return reinterpret_cast<Fl_Menu_*>(m)->value();
+}
+
+
+
+
+unsigned int fl_menu_get_textcolor(MENU m) {
+ return reinterpret_cast<Fl_Menu_*>(m)->textcolor();
+}
+
+void fl_menu_set_textcolor(MENU m, unsigned int c) {
+ reinterpret_cast<Fl_Menu_*>(m)->textcolor(c);
+}
+
+int fl_menu_get_textfont(MENU m) {
+ return reinterpret_cast<Fl_Menu_*>(m)->textfont();
+}
+
+void fl_menu_set_textfont(MENU m, int f) {
+ reinterpret_cast<Fl_Menu_*>(m)->textfont(f);
+}
+
+int fl_menu_get_textsize(MENU m) {
+ return reinterpret_cast<Fl_Menu_*>(m)->textsize();
+}
+
+void fl_menu_set_textsize(MENU m, int s) {
+ reinterpret_cast<Fl_Menu_*>(m)->textsize(s);
+}
+
+
+
+
+int fl_menu_get_down_box(MENU m) {
+ return reinterpret_cast<Fl_Menu_*>(m)->down_box();
+}
+
+void fl_menu_set_down_box(MENU m, int t) {
+ reinterpret_cast<Fl_Menu_*>(m)->down_box(static_cast<Fl_Boxtype>(t));
+}
+
+void fl_menu_global(MENU m) {
+ reinterpret_cast<Fl_Menu_*>(m)->global();
+}
+
+int fl_menu_measure(MENU m, int i, int *h) {
+ // method actually belongs to Fl_Menu_Item
+ const Fl_Menu_Item * item = reinterpret_cast<const Fl_Menu_Item*>(fl_menu_get_item(m,i));
+ return item->measure(h,reinterpret_cast<Fl_Menu_*>(m));
+}
+
+
+
+
+const void * fl_menu_popup(MENU m, int x, int y, const char * t, int n) {
+ // method actually belongs to Fl_Menu_Item
+ const Fl_Menu_Item * dummy = reinterpret_cast<const Fl_Menu_Item*>(fl_menu_get_item(m,0));
+ const Fl_Menu_Item * item;
+ if (n >= 0) {
+ item = reinterpret_cast<const Fl_Menu_Item*>(fl_menu_get_item(m,n));
+ } else {
+ item = 0;
+ }
+ return dummy->popup(x,y,t,item,reinterpret_cast<Fl_Menu_*>(m));
+}
+
+const void * fl_menu_pulldown(MENU m, int x, int y, int w, int h, int n) {
+ // method actually belongs to Fl_Menu_Item
+ const Fl_Menu_Item * dummy = reinterpret_cast<const Fl_Menu_Item*>(fl_menu_get_item(m,0));
+ const Fl_Menu_Item * item;
+ if (n >= 0) {
+ item = reinterpret_cast<const Fl_Menu_Item*>(fl_menu_get_item(m,n));
+ } else {
+ item = 0;
+ }
+ return dummy->pulldown(x,y,w,h,item,reinterpret_cast<Fl_Menu_*>(m));
+}
+
+
+
+
+void fl_menu_draw_item(MENU m, int i, int x, int y, int w, int h, int s) {
+ // method actually belongs to Fl_Menu_Item
+ const Fl_Menu_Item * item = reinterpret_cast<const Fl_Menu_Item*>(fl_menu_get_item(m,i));
+ item->draw(x,y,w,h,reinterpret_cast<Fl_Menu_*>(m),s);
+}
+
+
diff --git a/src/c_fl_menu.h b/src/c_fl_menu.h
index e173e8e..79f64a8 100644
--- a/src/c_fl_menu.h
+++ b/src/c_fl_menu.h
@@ -7,7 +7,6 @@
typedef void* MENU;
-// typedef void* MENUITEM;
@@ -25,8 +24,44 @@ extern "C" void free_fl_menu(MENU m);
extern "C" int fl_menu_add(MENU m, const char * t, unsigned long s, void * c, void * u, unsigned long f);
+extern "C" int fl_menu_insert(MENU m, int p, const char * t, unsigned long s, void * c, void * u, unsigned long f);
+extern "C" void fl_menu_remove(MENU m, int p);
+extern "C" void fl_menu_clear(MENU m);
+
+
+extern "C" const void * fl_menu_get_item(MENU m, int i);
extern "C" const void * fl_menu_find_item(MENU m, const char * t);
+extern "C" const void * fl_menu_find_item2(MENU m, void * cb);
+extern "C" int fl_menu_find_index(MENU m, const char * t);
+extern "C" int fl_menu_find_index2(MENU m, void * i);
+extern "C" int fl_menu_find_index3(MENU m, void * cb);
+extern "C" int fl_menu_size(MENU m);
+
+
extern "C" const void * fl_menu_mvalue(MENU m);
+extern "C" const char * fl_menu_text(MENU m);
+extern "C" int fl_menu_value(MENU m);
+
+
+extern "C" unsigned int fl_menu_get_textcolor(MENU m);
+extern "C" void fl_menu_set_textcolor(MENU m, unsigned int c);
+extern "C" int fl_menu_get_textfont(MENU m);
+extern "C" void fl_menu_set_textfont(MENU m, int f);
+extern "C" int fl_menu_get_textsize(MENU m);
+extern "C" void fl_menu_set_textsize(MENU m, int s);
+
+
+extern "C" int fl_menu_get_down_box(MENU m);
+extern "C" void fl_menu_set_down_box(MENU m, int t);
+extern "C" void fl_menu_global(MENU m);
+extern "C" int fl_menu_measure(MENU m, int i, int *h);
+
+
+extern "C" const void * fl_menu_popup(MENU m, int x, int y, const char * t, int n);
+extern "C" const void * fl_menu_pulldown(MENU m, int x, int y, int w, int h, int n);
+
+
+extern "C" void fl_menu_draw_item(MENU m, int i, int x, int y, int w, int h, int s);
#endif
diff --git a/src/c_fl_menuitem.cpp b/src/c_fl_menuitem.cpp
index 342f98b..3a9565e 100644
--- a/src/c_fl_menuitem.cpp
+++ b/src/c_fl_menuitem.cpp
@@ -116,6 +116,14 @@ void fl_menu_item_set_shortcut(MENU_ITEM mi, int s) {
reinterpret_cast<Fl_Menu_Item*>(mi)->shortcut(s);
}
+unsigned long fl_menu_item_get_flags(MENU_ITEM mi) {
+ return reinterpret_cast<Fl_Menu_Item*>(mi)->flags;
+}
+
+void fl_menu_item_set_flags(MENU_ITEM mi, unsigned long f) {
+ reinterpret_cast<Fl_Menu_Item*>(mi)->flags = f;
+}
+
diff --git a/src/c_fl_menuitem.h b/src/c_fl_menuitem.h
index bf54cfa..ce90cbc 100644
--- a/src/c_fl_menuitem.h
+++ b/src/c_fl_menuitem.h
@@ -44,6 +44,8 @@ extern "C" void fl_menu_item_set_labeltype(MENU_ITEM mi, int t);
extern "C" int fl_menu_item_get_shortcut(MENU_ITEM mi);
extern "C" void fl_menu_item_set_shortcut(MENU_ITEM mi, int s);
+extern "C" unsigned long fl_menu_item_get_flags(MENU_ITEM mi);
+extern "C" void fl_menu_item_set_flags(MENU_ITEM mi, unsigned long f);
extern "C" void fl_menu_item_activate(MENU_ITEM mi);
diff --git a/src/fltk-menu_items.adb b/src/fltk-menu_items.adb
index a94293f..4c0e78c 100644
--- a/src/fltk-menu_items.adb
+++ b/src/fltk-menu_items.adb
@@ -161,6 +161,18 @@ package body FLTK.Menu_Items is
pragma Import (C, fl_menu_item_set_shortcut, "fl_menu_item_set_shortcut");
pragma Inline (fl_menu_item_set_shortcut);
+ function fl_menu_item_get_flags
+ (MI : in System.Address)
+ return Interfaces.C.unsigned_long;
+ pragma Import (C, fl_menu_item_get_flags, "fl_menu_item_get_flags");
+ pragma Inline (fl_menu_item_get_flags);
+
+ procedure fl_menu_item_set_flags
+ (MI : in System.Address;
+ F : in Interfaces.C.unsigned_long);
+ pragma Import (C, fl_menu_item_set_flags, "fl_menu_item_set_flags");
+ pragma Inline (fl_menu_item_set_flags);
+
@@ -414,6 +426,22 @@ package body FLTK.Menu_Items is
end Set_Shortcut;
+ function Get_Flags
+ (Item : in Menu_Item)
+ return Menu_Flag is
+ begin
+ return Menu_Flag (fl_menu_item_get_flags (Item.Void_Ptr));
+ end Get_Flags;
+
+
+ procedure Set_Flags
+ (Item : in out Menu_Item;
+ To : in Menu_Flag) is
+ begin
+ fl_menu_item_set_flags (Item.Void_Ptr, Interfaces.C.unsigned_long (To));
+ end Set_Flags;
+
+
procedure Activate
diff --git a/src/fltk-menu_items.ads b/src/fltk-menu_items.ads
index 9f02d27..5964a48 100644
--- a/src/fltk-menu_items.ads
+++ b/src/fltk-menu_items.ads
@@ -120,6 +120,14 @@ package FLTK.Menu_Items is
(Item : in out Menu_Item;
To : in Key_Combo);
+ function Get_Flags
+ (Item : in Menu_Item)
+ return Menu_Flag;
+
+ procedure Set_Flags
+ (Item : in out Menu_Item;
+ To : in Menu_Flag);
+
@@ -185,6 +193,8 @@ private
pragma Inline (Get_Shortcut);
pragma Inline (Set_Shortcut);
+ pragma Inline (Get_Flags);
+ pragma Inline (Set_Flags);
pragma Inline (Activate);
diff --git a/src/fltk-widgets-groups.adb b/src/fltk-widgets-groups.adb
index 973dabb..1994b29 100644
--- a/src/fltk-widgets-groups.adb
+++ b/src/fltk-widgets-groups.adb
@@ -7,6 +7,7 @@ with
use type
+ Interfaces.C.int,
System.Address;
@@ -215,7 +216,7 @@ package body FLTK.Widgets.Groups is
fl_group_insert
(This.Void_Ptr,
Item.Void_Ptr,
- Interfaces.C.int (Place));
+ Interfaces.C.int (Place) - 1);
end Insert;
@@ -243,7 +244,7 @@ package body FLTK.Widgets.Groups is
(This : in out Group;
Place : in Index) is
begin
- fl_group_remove2 (This.Void_Ptr, Interfaces.C.int (Place - 1));
+ fl_group_remove2 (This.Void_Ptr, Interfaces.C.int (Place) - 1);
end Remove;
@@ -281,7 +282,7 @@ package body FLTK.Widgets.Groups is
return Widget_Reference
is
Widget_Ptr : System.Address :=
- fl_group_child (This.Void_Ptr, Interfaces.C.int (Place - 1));
+ fl_group_child (This.Void_Ptr, Interfaces.C.int (Place) - 1);
Actual_Widget : access Widget'Class :=
Widget_Convert.To_Pointer (fl_widget_get_user_data (Widget_Ptr));
begin
@@ -301,10 +302,15 @@ package body FLTK.Widgets.Groups is
function Find
(This : in Group;
Item : in out Widget'Class)
- return Index is
+ return Extended_Index
+ is
+ Ret : Interfaces.C.int;
begin
- -- should set this up to throw an exception if not found
- return Index (fl_group_find (This.Void_Ptr, Item.Void_Ptr));
+ Ret := fl_group_find (This.Void_Ptr, Item.Void_Ptr);
+ if Ret = fl_group_children (This.Void_Ptr) then
+ return No_Index;
+ end if;
+ return Extended_Index (Ret + 1);
end Find;
diff --git a/src/fltk-widgets-groups.ads b/src/fltk-widgets-groups.ads
index 609ba5d..ec0ab2a 100644
--- a/src/fltk-widgets-groups.ads
+++ b/src/fltk-widgets-groups.ads
@@ -21,6 +21,8 @@ package FLTK.Widgets.Groups is
with Implicit_Dereference => Data;
subtype Index is Positive;
+ subtype Extended_Index is Natural;
+ No_Index : constant Extended_Index := Extended_Index'First;
-- type Clip_Mode is (No_Clip, Clip);
@@ -91,7 +93,7 @@ package FLTK.Widgets.Groups is
function Find
(This : in Group;
Item : in out Widget'Class)
- return Index;
+ return Extended_Index;
function Number_Of_Children
(This : in Group)
diff --git a/src/fltk-widgets-menus.adb b/src/fltk-widgets-menus.adb
index 3d8ea0c..d6148f2 100644
--- a/src/fltk-widgets-menus.adb
+++ b/src/fltk-widgets-menus.adb
@@ -2,9 +2,9 @@
with
- Interfaces.C,
- System,
- FLTK.Menu_Items;
+ Interfaces.C.Strings,
+ Ada.Unchecked_Deallocation,
+ System;
use type
@@ -19,10 +19,12 @@ package body FLTK.Widgets.Menus is
procedure menu_set_draw_hook
(W, D : in System.Address);
pragma Import (C, menu_set_draw_hook, "menu_set_draw_hook");
+ pragma Inline (menu_set_draw_hook);
procedure menu_set_handle_hook
(W, H : in System.Address);
pragma Import (C, menu_set_handle_hook, "menu_set_handle_hook");
+ pragma Inline (menu_set_handle_hook);
@@ -32,10 +34,12 @@ package body FLTK.Widgets.Menus is
Text : in Interfaces.C.char_array)
return System.Address;
pragma Import (C, new_fl_menu, "new_fl_menu");
+ pragma Inline (new_fl_menu);
procedure free_fl_menu
(F : in System.Address);
pragma Import (C, free_fl_menu, "free_fl_menu");
+ pragma Inline (free_fl_menu);
@@ -48,17 +52,196 @@ package body FLTK.Widgets.Menus is
F : in Interfaces.C.unsigned_long)
return Interfaces.C.int;
pragma Import (C, fl_menu_add, "fl_menu_add");
+ pragma Inline (fl_menu_add);
+
+ function fl_menu_insert
+ (M : in System.Address;
+ P : in Interfaces.C.int;
+ T : in Interfaces.C.char_array;
+ S : in Interfaces.C.unsigned_long;
+ C, U : in System.Address;
+ F : in Interfaces.C.unsigned_long)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_insert, "fl_menu_insert");
+ pragma Inline (fl_menu_insert);
+
+ procedure fl_menu_remove
+ (M : in System.Address;
+ P : in Interfaces.C.int);
+ pragma Import (C, fl_menu_remove, "fl_menu_remove");
+ pragma Inline (fl_menu_remove);
+
+ procedure fl_menu_clear
+ (M : in System.Address);
+ pragma Import (C, fl_menu_clear, "fl_menu_clear");
+ pragma Inline (fl_menu_clear);
+
+
+
+
+ function fl_menu_get_item
+ (M : in System.Address;
+ I : in Interfaces.C.int)
+ return System.Address;
+ pragma Import (C, fl_menu_get_item, "fl_menu_get_item");
+ pragma Inline (fl_menu_get_item);
function fl_menu_find_item
(M : in System.Address;
T : in Interfaces.C.char_array)
return System.Address;
pragma Import (C, fl_menu_find_item, "fl_menu_find_item");
+ pragma Inline (fl_menu_find_item);
+
+ function fl_menu_find_item2
+ (M, C : in System.Address)
+ return System.Address;
+ pragma Import (C, fl_menu_find_item2, "fl_menu_find_item2");
+ pragma Inline (fl_menu_find_item2);
+
+ function fl_menu_find_index
+ (M : in System.Address;
+ T : in Interfaces.C.char_array)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_find_index, "fl_menu_find_index");
+ pragma Inline (fl_menu_find_index);
+
+ function fl_menu_find_index2
+ (M, I : in System.Address)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_find_index2, "fl_menu_find_index2");
+ pragma Inline (fl_menu_find_index2);
+
+ function fl_menu_find_index3
+ (M, C : in System.Address)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_find_index3, "fl_menu_find_index3");
+ pragma Inline (fl_menu_find_index3);
+
+ function fl_menu_size
+ (M : in System.Address)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_size, "fl_menu_size");
+ pragma Inline (fl_menu_size);
+
+
+
function fl_menu_mvalue
(M : in System.Address)
return System.Address;
pragma Import (C, fl_menu_mvalue, "fl_menu_mvalue");
+ pragma Inline (fl_menu_mvalue);
+
+ function fl_menu_text
+ (M : in System.Address)
+ return Interfaces.C.Strings.chars_ptr;
+ pragma Import (C, fl_menu_text, "fl_menu_text");
+ pragma Inline (fl_menu_text);
+
+ function fl_menu_value
+ (M : in System.Address)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_value, "fl_menu_value");
+ pragma Inline (fl_menu_value);
+
+
+
+
+ function fl_menu_get_textcolor
+ (M : in System.Address)
+ return Interfaces.C.unsigned;
+ pragma Import (C, fl_menu_get_textcolor, "fl_menu_get_textcolor");
+ pragma Inline (fl_menu_get_textcolor);
+
+ procedure fl_menu_set_textcolor
+ (M : in System.Address;
+ C : in Interfaces.C.unsigned);
+ pragma Import (C, fl_menu_set_textcolor, "fl_menu_set_textcolor");
+ pragma Inline (fl_menu_set_textcolor);
+
+ function fl_menu_get_textfont
+ (M : in System.Address)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_get_textfont, "fl_menu_get_textfont");
+ pragma Inline (fl_menu_get_textfont);
+
+ procedure fl_menu_set_textfont
+ (M : in System.Address;
+ F : in Interfaces.C.int);
+ pragma Import (C, fl_menu_set_textfont, "fl_menu_set_textfont");
+ pragma Inline (fl_menu_set_textfont);
+
+ function fl_menu_get_textsize
+ (M : in System.Address)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_get_textsize, "fl_menu_get_textsize");
+ pragma Inline (fl_menu_get_textsize);
+
+ procedure fl_menu_set_textsize
+ (M : in System.Address;
+ S : in Interfaces.C.int);
+ pragma Import (C, fl_menu_set_textsize, "fl_menu_set_textsize");
+ pragma Inline (fl_menu_set_textsize);
+
+
+
+
+ function fl_menu_get_down_box
+ (M : in System.Address)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_get_down_box, "fl_menu_get_down_box");
+ pragma Inline (fl_menu_get_down_box);
+
+ procedure fl_menu_set_down_box
+ (M : in System.Address;
+ T : in Interfaces.C.int);
+ pragma Import (C, fl_menu_set_down_box, "fl_menu_set_down_box");
+ pragma Inline (fl_menu_set_down_box);
+
+ procedure fl_menu_global
+ (M : in System.Address);
+ pragma Import (C, fl_menu_global, "fl_menu_global");
+ pragma Inline (fl_menu_global);
+
+ function fl_menu_measure
+ (M : in System.Address;
+ I : in Interfaces.C.int;
+ H : out Interfaces.C.int)
+ return Interfaces.C.int;
+ pragma Import (C, fl_menu_measure, "fl_menu_measure");
+ pragma Inline (fl_menu_measure);
+
+
+
+
+ function fl_menu_popup
+ (M : in System.Address;
+ X, Y : in Interfaces.C.int;
+ T : in Interfaces.C.char_array;
+ N : in Interfaces.C.int)
+ return System.Address;
+ pragma Import (C, fl_menu_popup, "fl_menu_popup");
+ pragma Inline (fl_menu_popup);
+
+ function fl_menu_pulldown
+ (M : in System.Address;
+ X, Y, W, H : in Interfaces.C.int;
+ N : in Interfaces.C.int)
+ return System.Address;
+ pragma Import (C, fl_menu_pulldown, "fl_menu_pulldown");
+ pragma Inline (fl_menu_pulldown);
+
+
+
+
+ procedure fl_menu_draw_item
+ (M : in System.Address;
+ I : in Interfaces.C.int;
+ X, Y, W, H : in Interfaces.C.int;
+ S : in Interfaces.C.int);
+ pragma Import (C, fl_menu_draw_item, "fl_menu_draw_item");
+ pragma Inline (fl_menu_draw_item);
@@ -76,12 +259,21 @@ package body FLTK.Widgets.Menus is
+ procedure Free_Item is new Ada.Unchecked_Deallocation
+ (Object => FLTK.Menu_Items.Menu_Item, Name => Item_Access);
+
+
+
+
procedure Finalize
(This : in out Menu) is
begin
if This.Void_Ptr /= System.Null_Address and then
This in Menu'Class
then
+ for Item of This.My_Items loop
+ Free_Item (Item);
+ end loop;
free_fl_menu (This.Void_Ptr);
This.Void_Ptr := System.Null_Address;
end if;
@@ -110,6 +302,7 @@ package body FLTK.Widgets.Menus is
Widget_Convert.To_Address (This'Unchecked_Access));
menu_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
menu_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
+ This.My_Items := Item_Vectors.Empty_Vector;
end return;
end Create;
@@ -126,49 +319,407 @@ package body FLTK.Widgets.Menus is
Flags : in Menu_Flag := Flag_Normal)
is
Place : Interfaces.C.int;
- Callback, User_Data : System.Address;
+ Callback, User_Data : System.Address := System.Null_Address;
+ New_Item : Item_Access;
begin
- if Action = null then
- Callback := System.Null_Address;
- User_Data := System.Null_Address;
- else
+ if Action /= null then
Callback := Item_Hook'Address;
User_Data := Callback_Convert.To_Address (Action);
end if;
Place := fl_menu_add
- (This.Void_Ptr,
- Interfaces.C.To_C (Text),
- To_C (Shortcut),
- Callback,
- User_Data,
- Interfaces.C.unsigned_long (Flags));
+ (This.Void_Ptr,
+ Interfaces.C.To_C (Text),
+ To_C (Shortcut),
+ Callback,
+ User_Data,
+ Interfaces.C.unsigned_long (Flags));
+
+ New_Item := new FLTK.Menu_Items.Menu_Item;
+ Wrapper (New_Item.all).Void_Ptr := fl_menu_get_item (This.Void_Ptr, Place);
+ Wrapper (New_Item.all).Needs_Dealloc := False;
+ This.My_Items.Append (New_Item);
end Add;
+ procedure Insert
+ (This : in out Menu;
+ Place : in Index;
+ Text : in String;
+ Action : in Widget_Callback := null;
+ Shortcut : in Key_Combo := No_Key;
+ Flags : in Menu_Flag := Flag_Normal)
+ is
+ Ret_Place : Interfaces.C.int;
+ Callback, User_Data : System.Address := System.Null_Address;
+ New_Item : Item_Access;
+ begin
+ if Action /= null then
+ Callback := Item_Hook'Address;
+ User_Data := Callback_Convert.To_Address (Action);
+ end if;
+
+ Ret_Place := fl_menu_insert
+ (This.Void_Ptr,
+ Interfaces.C.int (Place) - 1,
+ Interfaces.C.To_C (Text),
+ To_C (Shortcut),
+ Callback,
+ User_Data,
+ Interfaces.C.unsigned_long (Flags));
+
+ New_Item := new FLTK.Menu_Items.Menu_Item;
+ Wrapper (New_Item.all).Void_Ptr := fl_menu_get_item (This.Void_Ptr, Ret_Place);
+ Wrapper (New_Item.all).Needs_Dealloc := False;
+ This.My_Items.Insert (Positive (Ret_Place + 1), New_Item);
+ end Insert;
+
+
+ procedure Remove
+ (This : in out Menu;
+ Place : in Index) is
+ begin
+ Free_Item (This.My_Items.Reference (Place));
+ This.My_Items.Delete (Place);
+ fl_menu_remove (This.Void_Ptr, Interfaces.C.int (Place) - 1);
+ end Remove;
+
+
+ procedure Clear
+ (This : in out Menu) is
+ begin
+ for Item of This.My_Items loop
+ Free_Item (Item);
+ end loop;
+ This.My_Items := Item_Vectors.Empty_Vector;
+ fl_menu_clear (This.Void_Ptr);
+ end Clear;
+
+
+
+
+ function Has_Item
+ (This : in Menu;
+ Place : in Index)
+ return Boolean is
+ begin
+ return Place in 1 .. This.Number_Of_Items;
+ end Has_Item;
+
+
+ function Has_Item
+ (Place : in Cursor)
+ return Boolean is
+ begin
+ return Place.My_Container.Has_Item (Place.My_Index);
+ end Has_Item;
+
+
+ function Item
+ (This : in Menu;
+ Place : in Index)
+ return FLTK.Menu_Items.Menu_Item_Reference is
+ begin
+ return (Data => This.My_Items.Element (Place));
+ end Item;
+
+
+ function Item
+ (This : in Menu;
+ Place : in Cursor)
+ return FLTK.Menu_Items.Menu_Item_Reference is
+ begin
+ return This.Item (Place.My_Index);
+ end Item;
+
+
function Find_Item
- (This : in Menu'Class;
+ (This : in Menu;
Name : in String)
- return FLTK.Menu_Items.Menu_Item is
+ return FLTK.Menu_Items.Menu_Item_Reference is
begin
- return Item : FLTK.Menu_Items.Menu_Item do
- Wrapper (Item).Void_Ptr := fl_menu_find_item
- (This.Void_Ptr,
- Interfaces.C.To_C (Name));
- end return;
+ return (Data => This.My_Items.Element (This.Find_Index (Name)));
end Find_Item;
+ function Find_Item
+ (This : in Menu;
+ Action : in Widget_Callback)
+ return FLTK.Menu_Items.Menu_Item_Reference is
+ begin
+ return (Data => This.My_Items.Element (This.Find_Index (Action)));
+ end Find_Item;
+
+
+ function Find_Index
+ (This : in Menu;
+ Name : in String)
+ return Extended_Index
+ is
+ Ret : Interfaces.C.int;
+ begin
+ Ret := fl_menu_find_index (This.Void_Ptr, Interfaces.C.To_C (Name));
+ return Extended_Index (Ret + 1);
+ end Find_Index;
+
+
+ function Find_Index
+ (This : in Menu;
+ Item : in FLTK.Menu_Items.Menu_Item)
+ return Extended_Index
+ is
+ Ret : Interfaces.C.int;
+ begin
+ Ret := fl_menu_find_index2 (This.Void_Ptr, Wrapper (Item).Void_Ptr);
+ return Extended_Index (Ret + 1);
+ end Find_Index;
+
+
+ function Find_Index
+ (This : in Menu;
+ Action : in Widget_Callback)
+ return Extended_Index
+ is
+ Ret : Interfaces.C.int;
+ begin
+ Ret := fl_menu_find_index3
+ (This.Void_Ptr,
+ Callback_Convert.To_Address (Action));
+ return Extended_Index (Ret + 1);
+ end Find_Index;
+
+
+ function Number_Of_Items
+ (This : in Menu)
+ return Natural is
+ begin
+ return Natural (fl_menu_size (This.Void_Ptr));
+ end Number_Of_Items;
+
+
+
+
+ function Iterate
+ (This : in Menu)
+ return Menu_Iterators.Reversible_Iterator'Class is
+ begin
+ return It : Iterator := (My_Container => This'Unrestricted_Access);
+ end Iterate;
+
+
+ function First
+ (Object : in Iterator)
+ return Cursor is
+ begin
+ return Cu : Cursor :=
+ (My_Container => Object.My_Container,
+ My_Index => 1);
+ end First;
+
+
+ function Next
+ (Object : in Iterator;
+ Place : in Cursor)
+ return Cursor is
+ begin
+ return Cu : Cursor :=
+ (My_Container => Place.My_Container,
+ My_Index => Place.My_Index + 1);
+ end Next;
+
+
+ function Last
+ (Object : in Iterator)
+ return Cursor is
+ begin
+ return Cu : Cursor :=
+ (My_Container => Object.My_Container,
+ My_Index => Object.My_Container.Number_Of_Items);
+ end Last;
+
+
+ function Previous
+ (Object : in Iterator;
+ Place : in Cursor)
+ return Cursor is
+ begin
+ return Cu : Cursor :=
+ (My_Container => Place.My_Container,
+ My_Index => Place.My_Index - 1);
+ end Previous;
+
+
+
+
function Chosen
- (This : in Menu'Class)
- return FLTK.Menu_Items.Menu_Item is
+ (This : in Menu)
+ return FLTK.Menu_Items.Menu_Item_Reference is
begin
- return Item : FLTK.Menu_Items.Menu_Item do
- Wrapper (Item).Void_Ptr := fl_menu_mvalue (This.Void_Ptr);
- end return;
+ return (Data => This.My_Items.Element (This.Chosen_Index));
end Chosen;
+ function Chosen_Label
+ (This : in Menu)
+ return String is
+ begin
+ -- no dealloc required?
+ return Interfaces.C.Strings.Value (fl_menu_text (This.Void_Ptr));
+ end Chosen_Label;
+
+
+ function Chosen_Index
+ (This : in Menu)
+ return Extended_Index is
+ begin
+ return Extended_Index (fl_menu_value (This.Void_Ptr) + 1);
+ end Chosen_Index;
+
+
+
+
+ function Get_Text_Color
+ (This : in Menu)
+ return Color is
+ begin
+ return Color (fl_menu_get_textcolor (This.Void_Ptr));
+ end Get_Text_Color;
+
+
+ procedure Set_Text_Color
+ (This : in out Menu;
+ To : in Color) is
+ begin
+ fl_menu_set_textcolor (This.Void_Ptr, Interfaces.C.unsigned (To));
+ end Set_Text_Color;
+
+
+ function Get_Text_Font
+ (This : in Menu)
+ return Font_Kind is
+ begin
+ return Font_Kind'Val (fl_menu_get_textfont (This.Void_Ptr));
+ end Get_Text_Font;
+
+
+ procedure Set_Text_Font
+ (This : in out Menu;
+ To : in Font_Kind) is
+ begin
+ fl_menu_set_textfont (This.Void_Ptr, Font_Kind'Pos (To));
+ end Set_Text_Font;
+
+
+ function Get_Text_Size
+ (This : in Menu)
+ return Font_Size is
+ begin
+ return Font_Size (fl_menu_get_textsize (This.Void_Ptr));
+ end Get_Text_Size;
+
+
+ procedure Set_Text_Size
+ (This : in out Menu;
+ To : in Font_Size) is
+ begin
+ fl_menu_set_textsize (This.Void_Ptr, Interfaces.C.int (To));
+ end Set_Text_Size;
+
+
+
+
+ function Get_Down_Box
+ (This : in Menu)
+ return Box_Kind is
+ begin
+ return Box_Kind'Val (fl_menu_get_down_box (This.Void_Ptr));
+ end Get_Down_Box;
+
+
+ procedure Set_Down_Box
+ (This : in out Menu;
+ To : in Box_Kind) is
+ begin
+ fl_menu_set_down_box (This.Void_Ptr, Box_Kind'Pos (To));
+ end Set_Down_Box;
+
+
+ procedure Make_Global
+ (This : in out Menu) is
+ begin
+ fl_menu_global (This.Void_Ptr);
+ end Make_Global;
+
+
+ procedure Measure_Item
+ (This : in Menu;
+ Item : in Index;
+ W, H : out Integer) is
+ begin
+ W := Integer (fl_menu_measure
+ (This.Void_Ptr,
+ Interfaces.C.int (Item) - 1,
+ Interfaces.C.int (H)));
+ end Measure_Item;
+
+
+
+
+ function Popup
+ (This : in Menu;
+ X, Y : in Integer;
+ Title : in String := "";
+ Initial : in Extended_Index := No_Index)
+ return FLTK.Menu_Items.Menu_Item_Reference
+ is
+ Ptr : System.Address := fl_menu_popup
+ (This.Void_Ptr,
+ Interfaces.C.int (X),
+ Interfaces.C.int (Y),
+ Interfaces.C.To_C (Title),
+ Interfaces.C.int (Initial) - 1);
+ Place : Index := Index (fl_menu_find_index2 (This.Void_Ptr, Ptr) + 1);
+ begin
+ return (Data => This.My_Items.Element (Place));
+ end Popup;
+
+
+ function Pulldown
+ (This : in Menu;
+ X, Y, W, H : in Integer;
+ Initial : in Extended_Index := No_Index)
+ return FLTK.Menu_Items.Menu_Item_Reference
+ is
+ Ptr : System.Address := fl_menu_pulldown
+ (This.Void_Ptr,
+ Interfaces.C.int (X),
+ Interfaces.C.int (Y),
+ Interfaces.C.int (W),
+ Interfaces.C.int (H),
+ Interfaces.C.int (Initial) - 1);
+ Place : Index := Index (fl_menu_find_index2 (This.Void_Ptr, Ptr) + 1);
+ begin
+ return (Data => This.My_Items.Element (Place));
+ end Pulldown;
+
+
+
+
+ procedure Draw_Item
+ (This : in out Menu;
+ Item : in Index;
+ X, Y, W, H : in Integer;
+ Selected : in Boolean := False) is
+ begin
+ fl_menu_draw_item
+ (This.Void_Ptr,
+ Interfaces.C.int (Item) - 1,
+ Interfaces.C.int (X),
+ Interfaces.C.int (Y),
+ Interfaces.C.int (W),
+ Interfaces.C.int (H),
+ Boolean'Pos (Selected));
+ end Draw_Item;
function Handle
diff --git a/src/fltk-widgets-menus.ads b/src/fltk-widgets-menus.ads
index 5d3e599..95e4528 100644
--- a/src/fltk-widgets-menus.ads
+++ b/src/fltk-widgets-menus.ads
@@ -2,10 +2,12 @@
with
- FLTK.Menu_Items;
+ FLTK.Menu_Items,
+ Ada.Iterator_Interfaces;
private with
+ Ada.Containers.Vectors,
Interfaces,
System;
@@ -13,12 +15,19 @@ private with
package FLTK.Widgets.Menus is
- type Menu is new Widget with private;
+ type Menu is new Widget with private
+ with Default_Iterator => Iterate,
+ Iterator_Element => FLTK.Menu_Items.Menu_Item_Reference,
+ Variable_Indexing => Item;
- type Menu_Cursor (Data : access Menu'Class) is limited null record
+ type Menu_Reference (Data : not null access Menu'Class) is limited null record
with Implicit_Dereference => Data;
subtype Index is Positive;
+ subtype Extended_Index is Natural;
+ No_Index : constant Extended_Index := Extended_Index'First;
+
+ type Cursor is private;
@@ -42,14 +51,158 @@ package FLTK.Widgets.Menus is
Shortcut : in Key_Combo := No_Key;
Flags : in Menu_Flag := Flag_Normal);
+ procedure Insert
+ (This : in out Menu;
+ Place : in Index;
+ Text : in String;
+ Action : in Widget_Callback := null;
+ Shortcut : in Key_Combo := No_Key;
+ Flags : in Menu_Flag := Flag_Normal);
+
+ procedure Remove
+ (This : in out Menu;
+ Place : in Index);
+
+ procedure Clear
+ (This : in out Menu);
+
+
+
+
+ function Has_Item
+ (This : in Menu;
+ Place : in Index)
+ return Boolean;
+
+ function Has_Item
+ (Place : in Cursor)
+ return Boolean;
+
+ function Item
+ (This : in Menu;
+ Place : in Index)
+ return FLTK.Menu_Items.Menu_Item_Reference;
+
+ function Item
+ (This : in Menu;
+ Place : in Cursor)
+ return FLTK.Menu_Items.Menu_Item_Reference;
+
function Find_Item
- (This : in Menu'Class;
+ (This : in Menu;
+ Name : in String)
+ return FLTK.Menu_Items.Menu_Item_Reference;
+
+ function Find_Item
+ (This : in Menu;
+ Action : in Widget_Callback)
+ return FLTK.Menu_Items.Menu_Item_Reference;
+
+ function Find_Index
+ (This : in Menu;
Name : in String)
- return FLTK.Menu_Items.Menu_Item;
+ return Extended_Index;
+
+ function Find_Index
+ (This : in Menu;
+ Item : in FLTK.Menu_Items.Menu_Item)
+ return Extended_Index;
+
+ function Find_Index
+ (This : in Menu;
+ Action : in Widget_Callback)
+ return Extended_Index;
+
+ function Number_Of_Items
+ (This : in Menu)
+ return Natural;
+
+
+
+
+ package Menu_Iterators is
+ new Ada.Iterator_Interfaces (Cursor, Has_Item);
+
+ function Iterate
+ (This : in Menu)
+ return Menu_Iterators.Reversible_Iterator'Class;
+
+
+
function Chosen
- (This : in Menu'Class)
- return FLTK.Menu_Items.Menu_Item;
+ (This : in Menu)
+ return FLTK.Menu_Items.Menu_Item_Reference;
+
+ function Chosen_Label
+ (This : in Menu)
+ return String;
+
+ function Chosen_Index
+ (This : in Menu)
+ return Extended_Index;
+
+
+
+
+ function Get_Text_Color
+ (This : in Menu)
+ return Color;
+
+ procedure Set_Text_Color
+ (This : in out Menu;
+ To : in Color);
+
+ function Get_Text_Font
+ (This : in Menu)
+ return Font_Kind;
+
+ procedure Set_Text_Font
+ (This : in out Menu;
+ To : in Font_Kind);
+
+ function Get_Text_Size
+ (This : in Menu)
+ return Font_Size;
+
+ procedure Set_Text_Size
+ (This : in out Menu;
+ To : in Font_Size);
+
+
+
+
+ function Get_Down_Box
+ (This : in Menu)
+ return Box_Kind;
+
+ procedure Set_Down_Box
+ (This : in out Menu;
+ To : in Box_Kind);
+
+ procedure Make_Global
+ (This : in out Menu);
+
+ procedure Measure_Item
+ (This : in Menu;
+ Item : in Index;
+ W, H : out Integer);
+
+
+
+
+ function Popup
+ (This : in Menu;
+ X, Y : in Integer;
+ Title : in String := "";
+ Initial : in Extended_Index := No_Index)
+ return FLTK.Menu_Items.Menu_Item_Reference;
+
+ function Pulldown
+ (This : in Menu;
+ X, Y, W, H : in Integer;
+ Initial : in Extended_Index := No_Index)
+ return FLTK.Menu_Items.Menu_Item_Reference;
@@ -57,6 +210,12 @@ package FLTK.Widgets.Menus is
procedure Draw
(This : in out Menu) is null;
+ procedure Draw_Item
+ (This : in out Menu;
+ Item : in Index;
+ X, Y, W, H : in Integer;
+ Selected : in Boolean := False);
+
function Handle
(This : in out Menu;
Event : in Event_Kind)
@@ -66,7 +225,19 @@ package FLTK.Widgets.Menus is
private
- type Menu is new Widget with null record;
+ -- I'm not very happy with using a Vector of dynamically allocated
+ -- Menu_Item wrappers like this, but I kinda painted myself into a
+ -- corner with use of Limited_Controlled and the way the Add method
+ -- works for Menus.
+
+ type Item_Access is access FLTK.Menu_Items.Menu_Item;
+
+ package Item_Vectors is new Ada.Containers.Vectors
+ (Index_Type => Positive, Element_Type => Item_Access);
+
+ type Menu is new Widget with record
+ My_Items : Item_Vectors.Vector;
+ end record;
overriding procedure Finalize
(This : in out Menu);
@@ -78,5 +249,75 @@ private
pragma Convention (C, Item_Hook);
+
+
+ type Cursor is record
+ My_Container : access Menu;
+ My_Index : Index'Base := Index'First;
+ end record;
+
+ type Iterator is new Menu_Iterators.Reversible_Iterator with record
+ My_Container : access Menu;
+ end record;
+
+ overriding function First
+ (Object : in Iterator)
+ return Cursor;
+
+ overriding function Next
+ (Object : in Iterator;
+ Place : in Cursor)
+ return Cursor;
+
+ overriding function Last
+ (Object : in Iterator)
+ return Cursor;
+
+ overriding function Previous
+ (Object : in Iterator;
+ Place : in Cursor)
+ return Cursor;
+
+
+
+
+ pragma Inline (Has_Item);
+ pragma Inline (Item);
+ pragma Inline (Find_Item);
+ pragma Inline (Find_Index);
+ pragma Inline (Number_Of_Items);
+
+
+ pragma Inline (Iterate);
+
+
+ pragma Inline (Chosen);
+ pragma Inline (Chosen_Label);
+ pragma Inline (Chosen_Index);
+
+
+ pragma Inline (Get_Text_Color);
+ pragma Inline (Set_Text_Color);
+ pragma Inline (Get_Text_Font);
+ pragma Inline (Set_Text_Font);
+ pragma Inline (Get_Text_Size);
+ pragma Inline (Set_Text_Size);
+
+
+ pragma Inline (Get_Down_Box);
+ pragma Inline (Set_Down_Box);
+ pragma Inline (Make_Global);
+ pragma Inline (Measure_Item);
+
+
+ pragma Inline (Popup);
+ pragma Inline (Pulldown);
+
+
+ pragma Inline (Draw);
+ pragma Inline (Draw_Item);
+ pragma Inline (Handle);
+
+
end FLTK.Widgets.Menus;