summaryrefslogtreecommitdiff
path: root/src/c_fl_button.cpp
blob: 1cff342e1b8c6b67bcf8a1720de0f4b66b0ec6bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133


//  Programmed by Jedidiah Barber
//  Released into the public domain


#include <FL/Fl_Button.H>
#include "c_fl_button.h"




//  Telprot stopovers

extern "C" void button_extra_init_hook(void * aobj, int x, int y, int w, int h, const char * l);
void fl_button_extra_init(void * adaobj, int x, int y, int w, int h, const char * label) {
    button_extra_init_hook(adaobj, x, y, w, h, label);
}

extern "C" void button_extra_final_hook(void * aobj);
void fl_button_extra_final(void * adaobj) {
    button_extra_final_hook(adaobj);
}




//  Exports from Ada

extern "C" void widget_draw_hook(void * ud);
extern "C" int widget_handle_hook(void * ud, int e);




//  Non-friend protected access

class Friend_Button : Fl_Button {
public:
    using Fl_Button::simulate_key_action;
};




//  Attaching all relevant hooks and friends

class My_Button : public Fl_Button {
public:
    using Fl_Button::Fl_Button;

    friend void fl_button_draw(BUTTON b);
    friend int fl_button_handle(BUTTON b, int e);

    void draw();
    int handle(int e);
};

void My_Button::draw() {
    widget_draw_hook(this->user_data());
}

int My_Button::handle(int e) {
    return widget_handle_hook(this->user_data(), e);
}




//  Flattened C API

BUTTON new_fl_button(int x, int y, int w, int h, char* label) {
    My_Button *b = new My_Button(x, y, w, h, label);
    return b;
}

void free_fl_button(BUTTON b) {
    delete reinterpret_cast<My_Button*>(b);
}




int fl_button_get_state(BUTTON b) {
    return reinterpret_cast<Fl_Button*>(b)->Fl_Button::value();
}

void fl_button_set_state(BUTTON b, int s) {
    reinterpret_cast<Fl_Button*>(b)->Fl_Button::value(s);
}

void fl_button_set_only(BUTTON b) {
    reinterpret_cast<Fl_Button*>(b)->Fl_Button::setonly();
}




int fl_button_get_down_box(BUTTON b) {
    return reinterpret_cast<Fl_Button*>(b)->Fl_Button::down_box();
}

void fl_button_set_down_box(BUTTON b, int t) {
    reinterpret_cast<Fl_Button*>(b)->Fl_Button::down_box(static_cast<Fl_Boxtype>(t));
}

int fl_button_get_shortcut(BUTTON b) {
    return reinterpret_cast<Fl_Button*>(b)->Fl_Button::shortcut();
}

void fl_button_set_shortcut(BUTTON b, int k) {
    reinterpret_cast<Fl_Button*>(b)->Fl_Button::shortcut(k);
}




void fl_button_draw(BUTTON b) {
    reinterpret_cast<My_Button*>(b)->Fl_Button::draw();
}

int fl_button_handle(BUTTON b, int e) {
    return reinterpret_cast<My_Button*>(b)->Fl_Button::handle(e);
}




void fl_button_simulate_key_action(BUTTON b) {
    (reinterpret_cast<Fl_Button*>(b)->*(&Friend_Button::simulate_key_action))();
}