summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-05-13 12:35:40 +1000
committerJed Barber <jjbarber@y7mail.com>2017-05-13 12:35:40 +1000
commit1c0ddbf9eeb33f6bedc1fb9156e124b3a7b17bbc (patch)
treed662c3fb080042625696734c194328a78f81de1b
parent40d66b087fcf846c84da53c111ecbeb75bdd29ce (diff)
Handle method added for Boxes, Buttons, Widgets
-rw-r--r--src/c_fl_box.cpp39
-rw-r--r--src/c_fl_box.h3
-rw-r--r--src/c_fl_button.cpp39
-rw-r--r--src/c_fl_button.h2
-rw-r--r--src/c_fl_widget.cpp27
-rw-r--r--src/c_fl_widget.h1
-rw-r--r--src/fltk-enums.ads29
-rw-r--r--src/fltk-widgets-boxes.adb23
-rw-r--r--src/fltk-widgets-boxes.ads6
-rw-r--r--src/fltk-widgets-buttons.adb23
-rw-r--r--src/fltk-widgets-buttons.ads6
-rw-r--r--src/fltk-widgets.adb30
-rw-r--r--src/fltk-widgets.ads16
13 files changed, 232 insertions, 12 deletions
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<My_Box*>(n)->draw_hook = reinterpret_cast<hook_p>(d);
+ reinterpret_cast<My_Box*>(n)->draw_hook = reinterpret_cast<d_hook_p>(d);
}
@@ -42,6 +63,16 @@ void fl_box_draw(BOX n) {
}
+void box_set_handle_hook(BOX n, void * h) {
+ reinterpret_cast<My_Box*>(n)->handle_hook = reinterpret_cast<h_hook_p>(h);
+}
+
+
+int fl_box_handle(BOX n, int e) {
+ return reinterpret_cast<My_Box*>(n)->real_handle(e);
+}
+
+
BOX new_fl_box(int x, int y, int w, int h, char* label) {
diff --git a/src/c_fl_box.h b/src/c_fl_box.h
index d1b69b1..22ab587 100644
--- a/src/c_fl_box.h
+++ b/src/c_fl_box.h
@@ -9,6 +9,9 @@ typedef void* BOX;
extern "C" void box_set_draw_hook(BOX n, void * d);
extern "C" void fl_box_draw(BOX n);
+extern "C" void box_set_handle_hook(BOX n, void * h);
+extern "C" int fl_box_handle(BOX n, int e);
+
extern "C" BOX new_fl_box(int x, int y, int w, int h, char * label);
extern "C" void free_fl_box(BOX b);
diff --git a/src/c_fl_button.cpp b/src/c_fl_button.cpp
index f031ff9..725a0bc 100644
--- a/src/c_fl_button.cpp
+++ b/src/c_fl_button.cpp
@@ -4,8 +4,14 @@
#include "c_fl_button.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_Button : public Fl_Button {
using Fl_Button::Fl_Button;
friend void button_set_draw_hook(BUTTON b, void * d);
friend void fl_button_draw(BUTTON b);
+ friend void button_set_handle_hook(BUTTON b, void * h);
+ friend int fl_button_handle(BUTTON b, 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_Button::real_draw() {
}
+int My_Button::handle(int e) {
+ return (*handle_hook)(this->user_data(), e);
+}
+
+
+int My_Button::real_handle(int e) {
+ return Fl_Button::handle(e);
+}
+
+
void button_set_draw_hook(BUTTON b, void * d) {
- reinterpret_cast<My_Button*>(b)->draw_hook = reinterpret_cast<hook_p>(d);
+ reinterpret_cast<My_Button*>(b)->draw_hook = reinterpret_cast<d_hook_p>(d);
}
@@ -42,6 +63,16 @@ void fl_button_draw(BUTTON b) {
}
+void button_set_handle_hook(BUTTON b, void * h) {
+ reinterpret_cast<My_Button*>(b)->handle_hook = reinterpret_cast<h_hook_p>(h);
+}
+
+
+int fl_button_handle(BUTTON b, int e) {
+ return reinterpret_cast<My_Button*>(b)->real_handle(e);
+}
+
+
BUTTON new_fl_button(int x, int y, int w, int h, char* label) {
diff --git a/src/c_fl_button.h b/src/c_fl_button.h
index 14faa2b..002c173 100644
--- a/src/c_fl_button.h
+++ b/src/c_fl_button.h
@@ -9,6 +9,8 @@ typedef void* BUTTON;
extern "C" void button_set_draw_hook(BUTTON b, void * d);
extern "C" void fl_button_draw(BUTTON b);
+extern "C" void button_set_handle_hook(BUTTON b, void * h);
+extern "C" int fl_button_handle(BUTTON b, int e);
extern "C" BUTTON new_fl_button(int x, int y, int w, int h, char* label);
extern "C" void free_fl_button(BUTTON b);
diff --git a/src/c_fl_widget.cpp b/src/c_fl_widget.cpp
index 6dab9fa..d13d612 100644
--- a/src/c_fl_widget.cpp
+++ b/src/c_fl_widget.cpp
@@ -5,8 +5,14 @@
#include "c_fl_widget.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,13 @@ class My_Widget : public Fl_Widget {
public:
using Fl_Widget::Fl_Widget;
friend void widget_set_draw_hook(WIDGET w, void * d);
+ friend void widget_set_handle_hook(WIDGET w, void * h);
friend WIDGET new_fl_widget(int x, int y, int w, int h, char* label);
protected:
void draw();
- hook_p draw_hook;
+ int handle(int e);
+ d_hook_p draw_hook;
+ h_hook_p handle_hook;
};
@@ -27,8 +36,18 @@ void My_Widget::draw() {
}
+int My_Widget::handle(int e) {
+ return (*handle_hook)(this->user_data(), e);
+}
+
+
void widget_set_draw_hook(WIDGET w, void * d) {
- reinterpret_cast<My_Widget*>(w)->draw_hook = reinterpret_cast<hook_p>(d);
+ reinterpret_cast<My_Widget*>(w)->draw_hook = reinterpret_cast<d_hook_p>(d);
+}
+
+
+void widget_set_handle_hook(WIDGET w, void * h) {
+ reinterpret_cast<My_Widget*>(w)->handle_hook = reinterpret_cast<h_hook_p>(h);
}
diff --git a/src/c_fl_widget.h b/src/c_fl_widget.h
index b56d3e9..edb7ed3 100644
--- a/src/c_fl_widget.h
+++ b/src/c_fl_widget.h
@@ -8,6 +8,7 @@ typedef void* WIDGET;
extern "C" void widget_set_draw_hook(WIDGET w, void * d);
+extern "C" void widget_set_handle_hook(WIDGET w, void * h);
extern "C" WIDGET new_fl_widget(int x, int y, int w, int h, char* label);
diff --git a/src/fltk-enums.ads b/src/fltk-enums.ads
index 91f7353..0057cec 100644
--- a/src/fltk-enums.ads
+++ b/src/fltk-enums.ads
@@ -99,6 +99,35 @@ package FLTK.Enums is
Free_Label);
+ type Event_Kind is
+ (No_Event,
+ Push,
+ Release,
+ Enter,
+ Leave,
+ Drag,
+ Focus,
+ Unfocus,
+ Keydown,
+ Keyup,
+ Close,
+ Move,
+ Shortcut,
+ Deactivate,
+ Activate,
+ Hide,
+ Show,
+ Paste,
+ Selection_Clear,
+ Mouse_Wheel,
+ DnD_Enter,
+ DnD_Drag,
+ DnD_Leave,
+ DnD_Release,
+ Screen_Config_Changed,
+ Fullscreen);
+
+
-- type Modifier_Key is private;
type Modifier_Key is new Interfaces.Unsigned_8;
diff --git a/src/fltk-widgets-boxes.adb b/src/fltk-widgets-boxes.adb
index ed61168..a2d2335 100644
--- a/src/fltk-widgets-boxes.adb
+++ b/src/fltk-widgets-boxes.adb
@@ -12,10 +12,20 @@ package body FLTK.Widgets.Boxes is
(W, D : in System.Address);
pragma Import (C, box_set_draw_hook, "box_set_draw_hook");
+ procedure box_set_handle_hook
+ (W, H : in System.Address);
+ pragma Import (C, box_set_handle_hook, "box_set_handle_hook");
+
procedure fl_box_draw
(W : in System.Address);
pragma Import (C, fl_box_draw, "fl_box_draw");
+ function fl_box_handle
+ (W : in System.Address;
+ E : in Interfaces.C.int)
+ return Interfaces.C.int;
+ pragma Import (C, fl_box_handle, "fl_box_handle");
+
function new_fl_box
(X, Y, W, H : in Interfaces.C.int;
Text : in Interfaces.C.char_array)
@@ -55,6 +65,18 @@ package body FLTK.Widgets.Boxes is
+ function Handle
+ (This : in out Box;
+ Event : in Event_Kind)
+ return Event_Outcome is
+ begin
+ return Event_Outcome'Val
+ (fl_box_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
+ end Handle;
+
+
+
+
procedure Finalize
(This : in out Box) is
begin
@@ -86,6 +108,7 @@ package body FLTK.Widgets.Boxes is
(This.Void_Ptr,
Widget_Convert.To_Address (This'Unchecked_Access));
box_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
+ box_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
end return;
end Create;
diff --git a/src/fltk-widgets-boxes.ads b/src/fltk-widgets-boxes.ads
index 8fd5571..b3d2abd 100644
--- a/src/fltk-widgets-boxes.ads
+++ b/src/fltk-widgets-boxes.ads
@@ -16,6 +16,12 @@ package FLTK.Widgets.Boxes is
(This : in out Box);
+ function Handle
+ (This : in out Box;
+ Event : in Event_Kind)
+ return Event_Outcome;
+
+
private
diff --git a/src/fltk-widgets-buttons.adb b/src/fltk-widgets-buttons.adb
index bdc4810..aa9e7f3 100644
--- a/src/fltk-widgets-buttons.adb
+++ b/src/fltk-widgets-buttons.adb
@@ -12,10 +12,20 @@ package body FLTK.Widgets.Buttons is
(W, D : in System.Address);
pragma Import (C, button_set_draw_hook, "button_set_draw_hook");
+ procedure button_set_handle_hook
+ (W, H : in System.Address);
+ pragma Import (C, button_set_handle_hook, "button_set_handle_hook");
+
procedure fl_button_draw
(W : in System.Address);
pragma Import (C, fl_button_draw, "fl_button_draw");
+ function fl_button_handle
+ (W : in System.Address;
+ E : in Interfaces.C.int)
+ return Interfaces.C.int;
+ pragma Import (C, fl_button_handle, "fl_button_handle");
+
function new_fl_button
(X, Y, W, H : in Interfaces.C.int;
Text : in Interfaces.C.char_array)
@@ -69,6 +79,18 @@ package body FLTK.Widgets.Buttons is
+ function Handle
+ (This : in out Button;
+ Event : in Event_Kind)
+ return Event_Outcome is
+ begin
+ return Event_Outcome'Val
+ (fl_button_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
+ end Handle;
+
+
+
+
procedure Finalize
(This : in out Button) is
begin
@@ -100,6 +122,7 @@ package body FLTK.Widgets.Buttons is
(This.Void_Ptr,
Widget_Convert.To_Address (This'Unchecked_Access));
button_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
+ button_set_handle_hook (This.Void_Ptr, Draw_Hook'Address);
end return;
end Create;
diff --git a/src/fltk-widgets-buttons.ads b/src/fltk-widgets-buttons.ads
index f21fed4..981c313 100644
--- a/src/fltk-widgets-buttons.ads
+++ b/src/fltk-widgets-buttons.ads
@@ -33,6 +33,12 @@ package FLTK.Widgets.Buttons is
(This : in out Button);
+ function Handle
+ (This : in out Button;
+ Event : in Event_Kind)
+ return Event_Outcome;
+
+
private
diff --git a/src/fltk-widgets.adb b/src/fltk-widgets.adb
index 458a88c..6fee044 100644
--- a/src/fltk-widgets.adb
+++ b/src/fltk-widgets.adb
@@ -22,6 +22,10 @@ package body FLTK.Widgets is
(W, D : in System.Address);
pragma Import (C, widget_set_draw_hook, "widget_set_draw_hook");
+ procedure widget_set_handle_hook
+ (W, H : in System.Address);
+ pragma Import (C, widget_set_handle_hook, "widget_set_handle_hook");
+
function new_fl_widget
(X, Y, W, H : in Interfaces.C.int;
Text : in Interfaces.C.char_array)
@@ -143,6 +147,31 @@ package body FLTK.Widgets is
+ function Handle_Hook
+ (U : in System.Address;
+ E : in Interfaces.C.int)
+ return Interfaces.C.int
+ is
+ Ada_Widget : access Widget'Class :=
+ Widget_Convert.To_Pointer (U);
+ begin
+ return Event_Outcome'Pos (Ada_Widget.Handle (Event_Kind'Val (E)));
+ end Handle_Hook;
+
+
+
+
+ function Handle
+ (This : in out Widget;
+ Event : in Event_Kind)
+ return Event_Outcome is
+ begin
+ return Not_Handled;
+ end Handle;
+
+
+
+
procedure Finalize
(This : in out Widget) is
begin
@@ -173,6 +202,7 @@ package body FLTK.Widgets is
(This.Void_Ptr,
Widget_Convert.To_Address (This'Unchecked_Access));
widget_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
+ widget_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
end return;
end Create;
diff --git a/src/fltk-widgets.ads b/src/fltk-widgets.ads
index 56bad0a..f724507 100644
--- a/src/fltk-widgets.ads
+++ b/src/fltk-widgets.ads
@@ -6,6 +6,7 @@ limited with FLTK.Widgets.Groups;
private with System;
private with System.Address_To_Access_Conversions;
private with Ada.Unchecked_Conversion;
+private with Interfaces.C;
package FLTK.Widgets is
@@ -22,6 +23,8 @@ package FLTK.Widgets is
Normal_Size : constant Font_Size := 14;
type Color is new Natural;
+ type Event_Outcome is (Not_Handled, Handled);
+
function Create
(X, Y, W, H : in Integer;
@@ -133,6 +136,12 @@ package FLTK.Widgets is
(This : in out Widget) is null;
+ function Handle
+ (This : in out Widget;
+ Event : in Event_Kind)
+ return Event_Outcome;
+
+
private
@@ -143,6 +152,13 @@ private
end record;
+ function Handle_Hook
+ (U : in System.Address;
+ E : in Interfaces.C.int)
+ return Interfaces.C.int;
+ pragma Convention (C, Handle_Hook);
+
+
overriding procedure Finalize
(This : in out Widget);