summaryrefslogtreecommitdiff
path: root/src/c_fl_menu.cpp
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-01-12 01:14:58 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2025-01-12 01:14:58 +1300
commite93b9bbc02e2791f3a35b6f077fcbb8514c28aed (patch)
tree3661530027db6809a9cbad7b2477416009e00787 /src/c_fl_menu.cpp
parent53aa8144851913994b963ed611cca8885b8f9a9e (diff)
Refactored draw/handle methods in Widgets hierarchy, improved docs, added a few minor method bindings here and there
Diffstat (limited to 'src/c_fl_menu.cpp')
-rw-r--r--src/c_fl_menu.cpp56
1 files changed, 36 insertions, 20 deletions
diff --git a/src/c_fl_menu.cpp b/src/c_fl_menu.cpp
index 0b55e5d..8aa82f2 100644
--- a/src/c_fl_menu.cpp
+++ b/src/c_fl_menu.cpp
@@ -7,41 +7,43 @@
#include <FL/Fl_Menu_.H>
#include <FL/Fl_Menu_Item.H>
#include "c_fl_menu.h"
-#include "c_fl_type.h"
+// Exports from Ada
+
+extern "C" void widget_draw_hook(void * ud);
+extern "C" int widget_handle_hook(void * ud, int e);
+
+
+
+
+// Attaching all relevant hooks and friends
+
class My_Menu : public Fl_Menu_ {
- public:
- using Fl_Menu_::Fl_Menu_;
- friend void menu_set_draw_hook(MENU m, void * d);
- friend void menu_set_handle_hook(MENU m, void * h);
- protected:
- void draw();
- int handle(int e);
- d_hook_p draw_hook;
- h_hook_p handle_hook;
+public:
+ using Fl_Menu_::Fl_Menu_;
+
+ friend void fl_menu_draw(MENU m);
+ friend int fl_menu_handle(MENU m, int e);
+
+ void draw();
+ int handle(int e);
};
void My_Menu::draw() {
- (*draw_hook)(this->user_data());
+ widget_draw_hook(this->user_data());
}
int My_Menu::handle(int e) {
- return (*handle_hook)(this->user_data(), e);
+ return widget_handle_hook(this->user_data(), e);
}
-void menu_set_draw_hook(MENU m, void * d) {
- reinterpret_cast<My_Menu*>(m)->draw_hook = reinterpret_cast<d_hook_p>(d);
-}
-
-void menu_set_handle_hook(MENU m, void * h) {
- reinterpret_cast<My_Menu*>(m)->handle_hook = reinterpret_cast<h_hook_p>(h);
-}
+// Flattened C API
MENU new_fl_menu(int x, int y, int w, int h, char* label) {
My_Menu *m = new My_Menu(x, y, w, h, label);
@@ -59,7 +61,9 @@ 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);
}
-int fl_menu_insert(MENU m, int p, const char * t, unsigned long s, void * c, void * u, unsigned long 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);
}
@@ -221,4 +225,16 @@ void fl_menu_draw_item(MENU m, int i, int x, int y, int w, int h, int s) {
item->draw(x,y,w,h,reinterpret_cast<Fl_Menu_*>(m),s);
}
+void fl_menu_draw(MENU m) {
+ // The Fl_Menu_ draw method doesn't technically exist, so...
+ (void)(m);
+ // It is more convenient for this function to exist, however,
+ // even though it will likely never be called, because it simplifies
+ // and makes uniform the implementation of the Ada Menu Draw subprogram.
+}
+
+int fl_menu_handle(MENU m, int e) {
+ return reinterpret_cast<My_Menu*>(m)->Fl_Menu_::handle(e);
+}
+