From 1c0ddbf9eeb33f6bedc1fb9156e124b3a7b17bbc Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 13 May 2017 12:35:40 +1000 Subject: Handle method added for Boxes, Buttons, Widgets --- src/c_fl_box.cpp | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/c_fl_box.cpp') diff --git a/src/c_fl_box.cpp b/src/c_fl_box.cpp index 18afb1a..40e527d 100644 --- a/src/c_fl_box.cpp +++ b/src/c_fl_box.cpp @@ -4,8 +4,14 @@ #include "c_fl_box.h" -typedef void (hook)(void*); -typedef hook* hook_p; + + +typedef void (d_hook)(void*); +typedef d_hook* d_hook_p; + + +typedef int (h_hook)(void*,int); +typedef h_hook* h_hook_p; @@ -15,10 +21,15 @@ class My_Box : public Fl_Box { using Fl_Box::Fl_Box; friend void box_set_draw_hook(BOX n, void * d); friend void fl_box_draw(BOX n); + friend void box_set_handle_hook(BOX n, void * h); + friend int fl_box_handle(BOX n, int e); protected: void draw(); void real_draw(); - hook_p draw_hook; + int handle(int e); + int real_handle(int e); + d_hook_p draw_hook; + h_hook_p handle_hook; }; @@ -32,8 +43,18 @@ void My_Box::real_draw() { } +int My_Box::handle(int e) { + return (*handle_hook)(this->user_data(), e); +} + + +int My_Box::real_handle(int e) { + return Fl_Box::handle(e); +} + + void box_set_draw_hook(BOX n, void * d) { - reinterpret_cast(n)->draw_hook = reinterpret_cast(d); + reinterpret_cast(n)->draw_hook = reinterpret_cast(d); } @@ -42,6 +63,16 @@ void fl_box_draw(BOX n) { } +void box_set_handle_hook(BOX n, void * h) { + reinterpret_cast(n)->handle_hook = reinterpret_cast(h); +} + + +int fl_box_handle(BOX n, int e) { + return reinterpret_cast(n)->real_handle(e); +} + + BOX new_fl_box(int x, int y, int w, int h, char* label) { -- cgit