From e93b9bbc02e2791f3a35b6f077fcbb8514c28aed Mon Sep 17 00:00:00 2001 From: Jedidiah Barber 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_scrollbar.cpp | 70 +++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 38 deletions(-) (limited to 'src/c_fl_scrollbar.cpp') diff --git a/src/c_fl_scrollbar.cpp b/src/c_fl_scrollbar.cpp index 848d83f..ae20a25 100644 --- a/src/c_fl_scrollbar.cpp +++ b/src/c_fl_scrollbar.cpp @@ -6,7 +6,6 @@ #include #include "c_fl_scrollbar.h" -#include "c_fl_type.h" @@ -26,57 +25,40 @@ void fl_scrollbar_extra_final(void * adaobj) { -class My_Scrollbar : public Fl_Scrollbar { - public: - using Fl_Scrollbar::Fl_Scrollbar; - friend void scrollbar_set_draw_hook(SCROLLBAR s, void * d); - friend void fl_scrollbar_draw(SCROLLBAR s); - friend void scrollbar_set_handle_hook(SCROLLBAR s, void * h); - friend int fl_scrollbar_handle(SCROLLBAR s, 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_Scrollbar::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_Scrollbar::real_draw() { - Fl_Scrollbar::draw(); -} -int My_Scrollbar::handle(int e) { - return (*handle_hook)(this->user_data(), e); -} -int My_Scrollbar::real_handle(int e) { - return Fl_Scrollbar::handle(e); -} -void scrollbar_set_draw_hook(SCROLLBAR s, void * d) { - reinterpret_cast(s)->draw_hook = reinterpret_cast(d); -} +// Attaching all relevant hooks and friends -void fl_scrollbar_draw(SCROLLBAR s) { - reinterpret_cast(s)->real_draw(); -} +class My_Scrollbar : public Fl_Scrollbar { +public: + using Fl_Scrollbar::Fl_Scrollbar; + + friend void fl_scrollbar_draw(SCROLLBAR s); + friend int fl_scrollbar_handle(SCROLLBAR s, int e); + + void draw(); + int handle(int e); +}; -void scrollbar_set_handle_hook(SCROLLBAR s, void * h) { - reinterpret_cast(s)->handle_hook = reinterpret_cast(h); +void My_Scrollbar::draw() { + widget_draw_hook(this->user_data()); } -int fl_scrollbar_handle(SCROLLBAR s, int e) { - return reinterpret_cast(s)->real_handle(e); +int My_Scrollbar::handle(int e) { + return widget_handle_hook(this->user_data(), e); } +// Flattened C API + SCROLLBAR new_fl_scrollbar(int x, int y, int w, int h, char* label) { My_Scrollbar *s = new My_Scrollbar(x, y, w, h, label); return s; @@ -109,3 +91,15 @@ void fl_scrollbar_set_value2(SCROLLBAR s, int p, int w, int f, int t) { reinterpret_cast(s)->value(p,w,f,t); } + + + +void fl_scrollbar_draw(SCROLLBAR s) { + reinterpret_cast(s)->Fl_Scrollbar::draw(); +} + +int fl_scrollbar_handle(SCROLLBAR s, int e) { + return reinterpret_cast(s)->Fl_Scrollbar::handle(e); +} + + -- cgit