summaryrefslogtreecommitdiff
path: root/src/c_fl_box.cpp
blob: 3af626f2543b96d4a6cb595b82c2b3c7ff110147 (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


#include <FL/Fl_Box.H>
#include "c_fl_box.h"
#include "c_fl_type.h"




class My_Box : public Fl_Box {
    public:
        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();
        int handle(int e);
        int real_handle(int e);
        d_hook_p draw_hook;
        h_hook_p handle_hook;
};

void My_Box::draw() {
    (*draw_hook)(this->user_data());
}

void My_Box::real_draw() {
    Fl_Box::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<d_hook_p>(d);
}

void fl_box_draw(BOX n) {
    reinterpret_cast<My_Box*>(n)->real_draw();
}

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) {
    My_Box *b = new My_Box(x, y, w, h, label);
    return b;
}

void free_fl_box(BOX b) {
    delete reinterpret_cast<My_Box*>(b);
}