From 1cd018b440f80601f60908c2e5675413f5c77e25 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Tue, 15 May 2018 14:52:00 +1000 Subject: Finished and polished FLTK.Widgets.Menus, fixed some off-by-one errors in Groups --- src/c_fl_menu.cpp | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-) (limited to 'src/c_fl_menu.cpp') 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 +#include #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(m)->add(t, s, reinterpret_cast(c), u, f); + return reinterpret_cast(m)->add(t,s,reinterpret_cast(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(m)->insert(p,t,s,reinterpret_cast(c),u,f); +} + +void fl_menu_remove(MENU m, int p) { + reinterpret_cast(m)->remove(p); +} + +void fl_menu_clear(MENU m) { + reinterpret_cast(m)->clear(); +} + + + + +const void * fl_menu_get_item(MENU m, int i) { + return &(reinterpret_cast(m)->menu()[i]); } const void * fl_menu_find_item(MENU m, const char * t) { return reinterpret_cast(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(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(m)->find_index(t); +} + +int fl_menu_find_index2(MENU m, void * i) { + return reinterpret_cast(m)->find_index(reinterpret_cast(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(m)->menu()[i].user_data() == cb) { + return i; + } + } + return -1; +} + +int fl_menu_size(MENU m) { + return reinterpret_cast(m)->size(); +} + + + + const void * fl_menu_mvalue(MENU m) { return reinterpret_cast(m)->mvalue(); } +const char * fl_menu_text(MENU m) { + return reinterpret_cast(m)->text(); +} + +int fl_menu_value(MENU m) { + return reinterpret_cast(m)->value(); +} + + + + +unsigned int fl_menu_get_textcolor(MENU m) { + return reinterpret_cast(m)->textcolor(); +} + +void fl_menu_set_textcolor(MENU m, unsigned int c) { + reinterpret_cast(m)->textcolor(c); +} + +int fl_menu_get_textfont(MENU m) { + return reinterpret_cast(m)->textfont(); +} + +void fl_menu_set_textfont(MENU m, int f) { + reinterpret_cast(m)->textfont(f); +} + +int fl_menu_get_textsize(MENU m) { + return reinterpret_cast(m)->textsize(); +} + +void fl_menu_set_textsize(MENU m, int s) { + reinterpret_cast(m)->textsize(s); +} + + + + +int fl_menu_get_down_box(MENU m) { + return reinterpret_cast(m)->down_box(); +} + +void fl_menu_set_down_box(MENU m, int t) { + reinterpret_cast(m)->down_box(static_cast(t)); +} + +void fl_menu_global(MENU m) { + reinterpret_cast(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(fl_menu_get_item(m,i)); + return item->measure(h,reinterpret_cast(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(fl_menu_get_item(m,0)); + const Fl_Menu_Item * item; + if (n >= 0) { + item = reinterpret_cast(fl_menu_get_item(m,n)); + } else { + item = 0; + } + return dummy->popup(x,y,t,item,reinterpret_cast(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(fl_menu_get_item(m,0)); + const Fl_Menu_Item * item; + if (n >= 0) { + item = reinterpret_cast(fl_menu_get_item(m,n)); + } else { + item = 0; + } + return dummy->pulldown(x,y,w,h,item,reinterpret_cast(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(fl_menu_get_item(m,i)); + item->draw(x,y,w,h,reinterpret_cast(m),s); +} + + -- cgit