summaryrefslogtreecommitdiff
path: root/src/c_fl_text_display.cpp
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-01-12 01:14:58 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2025-01-12 01:14:58 +1300
commite93b9bbc02e2791f3a35b6f077fcbb8514c28aed (patch)
tree3661530027db6809a9cbad7b2477416009e00787 /src/c_fl_text_display.cpp
parent53aa8144851913994b963ed611cca8885b8f9a9e (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_display.cpp')
-rw-r--r--src/c_fl_text_display.cpp82
1 files changed, 40 insertions, 42 deletions
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 <FL/Fl_Text_Buffer.H>
#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<My_Text_Display*>(td)->draw_hook = reinterpret_cast<d_hook_p>(d);
-}
+// Attaching all relevant hooks and friends
-void fl_text_display_draw(TEXTDISPLAY td) {
- reinterpret_cast<My_Text_Display*>(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<My_Text_Display*>(td)->handle_hook = reinterpret_cast<h_hook_p>(h);
+void My_Text_Display::draw() {
+ widget_draw_hook(this->user_data());
}
-int fl_text_display_handle(TEXTDISPLAY td, int e) {
- return reinterpret_cast<My_Text_Display*>(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<Fl_Text_Display*>(td)->highlight_data
- (reinterpret_cast<Fl_Text_Buffer*>(tb), reinterpret_cast<Fl_Text_Display::Style_Table_Entry*>(st), len, 0, 0, 0);
+ (reinterpret_cast<Fl_Text_Buffer*>(tb),
+ reinterpret_cast<Fl_Text_Display::Style_Table_Entry*>(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<Fl_Text_Display*>(td)->highlight_data
- (reinterpret_cast<Fl_Text_Buffer*>(tb), reinterpret_cast<Fl_Text_Display::Style_Table_Entry*>(st), len,
- us, reinterpret_cast<Fl_Text_Display::Unfinished_Style_Cb>(cb), a);
+ (reinterpret_cast<Fl_Text_Buffer*>(tb),
+ reinterpret_cast<Fl_Text_Display::Style_Table_Entry*>(st),
+ len, us, reinterpret_cast<Fl_Text_Display::Unfinished_Style_Cb>(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<My_Text_Display*>(td)->Fl_Text_Display::draw();
+}
+
+int fl_text_display_handle(TEXTDISPLAY td, int e) {
+ return reinterpret_cast<My_Text_Display*>(td)->Fl_Text_Display::handle(e);
+}
+
+