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_help_view.cpp | 89 ++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 46 deletions(-) (limited to 'src/c_fl_help_view.cpp') diff --git a/src/c_fl_help_view.cpp b/src/c_fl_help_view.cpp index 33f1e5f..50d5d58 100644 --- a/src/c_fl_help_view.cpp +++ b/src/c_fl_help_view.cpp @@ -8,70 +8,44 @@ #include #include #include "c_fl_help_view.h" -#include "c_fl_type.h" -class My_Help_View : public Fl_Help_View { - public: - using Fl_Help_View::Fl_Help_View; - friend void help_view_set_draw_hook(HELPVIEW v, void * d); - friend void fl_help_view_draw(HELPVIEW v); - friend void help_view_set_handle_hook(HELPVIEW v, void * h); - friend int fl_help_view_handle(HELPVIEW v, 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_Help_View::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_Help_View::real_draw() { - #if FL_ABI_VERSION >= 10303 - Fl_Help_View::draw(); - #else - Fl_Group::draw(); - #endif -} -int My_Help_View::handle(int e) { - return (*handle_hook)(this->user_data(), e); -} -int My_Help_View::real_handle(int e) { - #if FL_ABI_VERSION >= 10303 - return Fl_Help_View::handle(e); - #else - return Fl_Group::handle(e); - #endif -} -void help_view_set_draw_hook(HELPVIEW v, void * d) { - reinterpret_cast(v)->draw_hook = reinterpret_cast(d); -} +// Attaching all relevant hooks and friends -void fl_help_view_draw(HELPVIEW v) { - reinterpret_cast(v)->real_draw(); -} +class My_Help_View : public Fl_Help_View { +public: + using Fl_Help_View::Fl_Help_View; + + friend void fl_help_view_draw(HELPVIEW v); + friend int fl_help_view_handle(HELPVIEW v, int e); + + void draw(); + int handle(int e); +}; -void help_view_set_handle_hook(HELPVIEW v, void * h) { - reinterpret_cast(v)->handle_hook = reinterpret_cast(h); +void My_Help_View::draw() { + widget_draw_hook(this->user_data()); } -int fl_help_view_handle(HELPVIEW v, int e) { - return reinterpret_cast(v)->real_handle(e); +int My_Help_View::handle(int e) { + return widget_handle_hook(this->user_data(), e); } +// Flattened C API + HELPVIEW new_fl_help_view(int x, int y, int w, int h, char * label) { My_Help_View *v = new My_Help_View(x, y, w, h, label); return v; @@ -169,6 +143,10 @@ void fl_help_view_set_size(HELPVIEW v, int w, int h) { reinterpret_cast(v)->size(w, h); } +void fl_help_view_resize(HELPVIEW v, int x, int y, int w, int h) { + reinterpret_cast(v)->resize(x, y, w, h); +} + unsigned int fl_help_view_get_textcolor(HELPVIEW v) { return reinterpret_cast(v)->textcolor(); } @@ -194,3 +172,22 @@ void fl_help_view_set_textsize(HELPVIEW v, int s) { } + + +void fl_help_view_draw(HELPVIEW v) { + #if FL_ABI_VERSION >= 10303 + reinterpret_cast(v)->Fl_Help_View::draw(); + #else + reinterpret_cast(v)->Fl_Group::draw(); + #endif +} + +int fl_help_view_handle(HELPVIEW v, int e) { + #if FL_ABI_VERSION >= 10303 + return reinterpret_cast(v)->Fl_Help_View::handle(e); + #else + return reinterpret_cast(v)->Fl_Group::handle(e); + #endif +} + + -- cgit