diff options
author | Jedidiah Barber <contact@jedbarber.id.au> | 2025-01-12 01:14:58 +1300 |
---|---|---|
committer | Jedidiah Barber <contact@jedbarber.id.au> | 2025-01-12 01:14:58 +1300 |
commit | e93b9bbc02e2791f3a35b6f077fcbb8514c28aed (patch) | |
tree | 3661530027db6809a9cbad7b2477416009e00787 /src/c_fl_text_editor.cpp | |
parent | 53aa8144851913994b963ed611cca8885b8f9a9e (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_text_editor.cpp')
-rw-r--r-- | src/c_fl_text_editor.cpp | 70 |
1 files changed, 32 insertions, 38 deletions
diff --git a/src/c_fl_text_editor.cpp b/src/c_fl_text_editor.cpp index 41729bd..8c33afa 100644 --- a/src/c_fl_text_editor.cpp +++ b/src/c_fl_text_editor.cpp @@ -6,62 +6,44 @@ #include <FL/Fl_Text_Editor.H> #include "c_fl_text_editor.h" -#include "c_fl_type.h" -class My_Text_Editor : public Fl_Text_Editor { - public: - using Fl_Text_Editor::Fl_Text_Editor; - friend void text_editor_set_draw_hook(TEXTEDITOR te, void * d); - friend void fl_text_editor_draw(TEXTEDITOR te); - friend void text_editor_set_handle_hook(TEXTEDITOR te, void * h); - friend int fl_text_editor_handle(TEXTEDITOR te, 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_Editor::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_Editor::real_draw() { - Fl_Text_Editor::draw(); -} -int My_Text_Editor::handle(int e) { - return (*handle_hook)(this->user_data(), e); -} -int My_Text_Editor::real_handle(int e) { - return Fl_Text_Editor::handle(e); -} -void text_editor_set_draw_hook(TEXTEDITOR te, void * d) { - reinterpret_cast<My_Text_Editor*>(te)->draw_hook = reinterpret_cast<d_hook_p>(d); -} +// Attaching all relevant hooks and friends -void fl_text_editor_draw(TEXTEDITOR te) { - reinterpret_cast<My_Text_Editor*>(te)->real_draw(); -} +class My_Text_Editor : public Fl_Text_Editor { +public: + using Fl_Text_Editor::Fl_Text_Editor; + + friend void fl_text_editor_draw(TEXTEDITOR te); + friend int fl_text_editor_handle(TEXTEDITOR te, int e); + + void draw(); + int handle(int e); +}; -void text_editor_set_handle_hook(TEXTEDITOR te, void * h) { - reinterpret_cast<My_Text_Editor*>(te)->handle_hook = reinterpret_cast<h_hook_p>(h); +void My_Text_Editor::draw() { + widget_draw_hook(this->user_data()); } -int fl_text_editor_handle(TEXTEDITOR te, int e) { - return reinterpret_cast<My_Text_Editor*>(te)->real_handle(e); +int My_Text_Editor::handle(int e) { + return widget_handle_hook(this->user_data(), e); } +// Flattened C API + TEXTEDITOR new_fl_text_editor(int x, int y, int w, int h, char* label) { My_Text_Editor *te = new My_Text_Editor(x, y, w, h, label); return te; @@ -305,3 +287,15 @@ void fl_text_editor_set_insert_mode(TEXTEDITOR te, int i) { // reinterpret_cast<Fl_Text_Editor*>(te)->tab_nav(t); //} + + + +void fl_text_editor_draw(TEXTEDITOR te) { + reinterpret_cast<My_Text_Editor*>(te)->Fl_Text_Editor::draw(); +} + +int fl_text_editor_handle(TEXTEDITOR te, int e) { + return reinterpret_cast<My_Text_Editor*>(te)->Fl_Text_Editor::handle(e); +} + + |