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_text_display.cpp | 82 +++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 42 deletions(-) (limited to 'src/c_fl_text_display.cpp') diff --git a/src/c_fl_text_display.cpp b/src/c_fl_text_display.cpp index 5b507e9..7323049 100644 --- a/src/c_fl_text_display.cpp +++ b/src/c_fl_text_display.cpp @@ -8,62 +8,44 @@ #include #include "c_fl_text_display.h" #include "c_fl_text_buffer.h" -#include "c_fl_type.h" -class My_Text_Display : public Fl_Text_Display { - public: - using Fl_Text_Display::Fl_Text_Display; - friend void text_display_set_draw_hook(TEXTDISPLAY td, void * d); - friend void fl_text_display_draw(TEXTDISPLAY td); - friend void text_display_set_handle_hook(TEXTDISPLAY td, void * h); - friend int fl_text_display_handle(TEXTDISPLAY td, 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_Text_Display::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_Text_Display::real_draw() { - Fl_Text_Display::draw(); -} -int My_Text_Display::handle(int e) { - return (*handle_hook)(this->user_data(), e); -} -int My_Text_Display::real_handle(int e) { - return Fl_Text_Display::handle(e); -} -void text_display_set_draw_hook(TEXTDISPLAY td, void * d) { - reinterpret_cast(td)->draw_hook = reinterpret_cast(d); -} +// Attaching all relevant hooks and friends -void fl_text_display_draw(TEXTDISPLAY td) { - reinterpret_cast(td)->real_draw(); -} +class My_Text_Display : public Fl_Text_Display { +public: + using Fl_Text_Display::Fl_Text_Display; + + friend void fl_text_display_draw(TEXTDISPLAY td); + friend int fl_text_display_handle(TEXTDISPLAY td, int e); + + void draw(); + int handle(int e); +}; -void text_display_set_handle_hook(TEXTDISPLAY td, void * h) { - reinterpret_cast(td)->handle_hook = reinterpret_cast(h); +void My_Text_Display::draw() { + widget_draw_hook(this->user_data()); } -int fl_text_display_handle(TEXTDISPLAY td, int e) { - return reinterpret_cast(td)->real_handle(e); +int My_Text_Display::handle(int e) { + return widget_handle_hook(this->user_data(), e); } +// Flattened C API + TEXTDISPLAY new_fl_text_display(int x, int y, int w, int h, char* label) { My_Text_Display *td = new My_Text_Display(x, y, w, h, label); return td; @@ -91,13 +73,18 @@ void fl_text_display_set_buffer(TEXTDISPLAY td, TEXTBUFFER tb) { void fl_text_display_highlight_data(TEXTDISPLAY td, TEXTBUFFER tb, void * st, int len) { reinterpret_cast(td)->highlight_data - (reinterpret_cast(tb), reinterpret_cast(st), len, 0, 0, 0); + (reinterpret_cast(tb), + reinterpret_cast(st), + len, 0, 0, 0); } -void fl_text_display_highlight_data2(TEXTDISPLAY td, TEXTBUFFER tb, void * st, int len, char us, void * cb, void * a) { +void fl_text_display_highlight_data2(TEXTDISPLAY td, TEXTBUFFER tb, void * st, int len, + char us, void * cb, void * a) +{ reinterpret_cast(td)->highlight_data - (reinterpret_cast(tb), reinterpret_cast(st), len, - us, reinterpret_cast(cb), a); + (reinterpret_cast(tb), + reinterpret_cast(st), + len, us, reinterpret_cast(cb), a); } @@ -339,3 +326,14 @@ void fl_text_display_redisplay_range(TEXTDISPLAY td, int s, int f) { } + + +void fl_text_display_draw(TEXTDISPLAY td) { + reinterpret_cast(td)->Fl_Text_Display::draw(); +} + +int fl_text_display_handle(TEXTDISPLAY td, int e) { + return reinterpret_cast(td)->Fl_Text_Display::handle(e); +} + + -- cgit