From e93b9bbc02e2791f3a35b6f077fcbb8514c28aed Mon Sep 17 00:00:00 2001
From: Jedidiah Barber <contact@jedbarber.id.au>
Date: Sun, 12 Jan 2025 01:14:58 +1300
Subject: Refactored draw/handle methods in Widgets hierarchy, improved docs,
 added a few minor method bindings here and there

---
 src/c_fl_toggle_button.cpp | 70 +++++++++++++++++++++-------------------------
 1 file changed, 32 insertions(+), 38 deletions(-)

(limited to 'src/c_fl_toggle_button.cpp')

diff --git a/src/c_fl_toggle_button.cpp b/src/c_fl_toggle_button.cpp
index a6195af..631fc21 100644
--- a/src/c_fl_toggle_button.cpp
+++ b/src/c_fl_toggle_button.cpp
@@ -6,62 +6,44 @@
 
 #include <FL/Fl_Toggle_Button.H>
 #include "c_fl_toggle_button.h"
-#include "c_fl_type.h"
 
 
 
 
-class My_Toggle_Button : public Fl_Toggle_Button {
-    public:
-        using Fl_Toggle_Button::Fl_Toggle_Button;
-        friend void toggle_button_set_draw_hook(TOGGLEBUTTON b, void * d);
-        friend void fl_toggle_button_draw(TOGGLEBUTTON b);
-        friend void toggle_button_set_handle_hook(TOGGLEBUTTON b, void * h);
-        friend int fl_toggle_button_handle(TOGGLEBUTTON b, int e);
-    protected:
-        void draw();
-        void real_draw();
-        int handle(int e);
-        int real_handle(int e);
-        d_hook_p draw_hook;
-        h_hook_p handle_hook;
-};
+//  Exports from Ada
 
-void My_Toggle_Button::draw() {
-    (*draw_hook)(this->user_data());
-}
+extern "C" void widget_draw_hook(void * ud);
+extern "C" int widget_handle_hook(void * ud, int e);
 
-void My_Toggle_Button::real_draw() {
-    Fl_Toggle_Button::draw();
-}
 
-int My_Toggle_Button::handle(int e) {
-    return (*handle_hook)(this->user_data(), e);
-}
 
-int My_Toggle_Button::real_handle(int e) {
-    return Fl_Toggle_Button::handle(e);
-}
 
-void toggle_button_set_draw_hook(TOGGLEBUTTON b, void * d) {
-    reinterpret_cast<My_Toggle_Button*>(b)->draw_hook = reinterpret_cast<d_hook_p>(d);
-}
+//  Attaching all relevant hooks and friends
 
-void fl_toggle_button_draw(TOGGLEBUTTON b) {
-    reinterpret_cast<My_Toggle_Button*>(b)->real_draw();
-}
+class My_Toggle_Button : public Fl_Toggle_Button {
+public:
+    using Fl_Toggle_Button::Fl_Toggle_Button;
+
+    friend void fl_toggle_button_draw(TOGGLEBUTTON b);
+    friend int fl_toggle_button_handle(TOGGLEBUTTON b, int e);
+
+    void draw();
+    int handle(int e);
+};
 
-void toggle_button_set_handle_hook(TOGGLEBUTTON b, void * h) {
-    reinterpret_cast<My_Toggle_Button*>(b)->handle_hook = reinterpret_cast<h_hook_p>(h);
+void My_Toggle_Button::draw() {
+    widget_draw_hook(this->user_data());
 }
 
-int fl_toggle_button_handle(TOGGLEBUTTON b, int e) {
-    return reinterpret_cast<My_Toggle_Button*>(b)->real_handle(e);
+int My_Toggle_Button::handle(int e) {
+    return widget_handle_hook(this->user_data(), e);
 }
 
 
 
 
+//  Flattened C API
+
 TOGGLEBUTTON new_fl_toggle_button(int x, int y, int w, int h, char* label) {
     My_Toggle_Button *b = new My_Toggle_Button(x, y, w, h, label);
     return b;
@@ -71,3 +53,15 @@ void free_fl_toggle_button(TOGGLEBUTTON b) {
     delete reinterpret_cast<My_Toggle_Button*>(b);
 }
 
+
+
+
+void fl_toggle_button_draw(TOGGLEBUTTON b) {
+    reinterpret_cast<My_Toggle_Button*>(b)->Fl_Toggle_Button::draw();
+}
+
+int fl_toggle_button_handle(TOGGLEBUTTON b, int e) {
+    return reinterpret_cast<My_Toggle_Button*>(b)->Fl_Toggle_Button::handle(e);
+}
+
+
-- 
cgit