File: Fl_Widget.i

package info (click to toggle)
pyfltk 1.4.4.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,556 kB
  • sloc: python: 7,769; cpp: 356; makefile: 24
file content (105 lines) | stat: -rw-r--r-- 2,764 bytes parent folder | download
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
/* File : Fl_Widget.i */
//%module Fl_Widget

%feature("docstring") ::Fl_Widget
"""
Fl_Widget is the base class for all widgets in FLTK. You can't create one of 
these because the constructor is not public. However you can subclass it.

All 'property' accessing methods, such as color(), parent(), or argument() 
are implemented as trivial inline functions and thus are as fast and small 
as accessing fields in a structure. Unless otherwise noted, the property 
setting methods such as color(n) or label(s) are also trivial inline 
functions, even if they change the widget's appearance. It is up to the user 
code to call redraw() after these. 
""" ;

%{
#include <FL/Fl.H>
#include "FL/Fl_Widget.H"
%}

%include "macros.i"

CHANGE_OWNERSHIP(Fl_Widget)

%pythonappend Fl_Widget::image(Fl_Image *a) %{
        if len(args) > 0:
            #delegate ownership to C++
            self.my_image = args[0]
%}
%pythonappend Fl_Widget::deimage(Fl_Image *a) %{
        if len(args) > 0:
            #delegate ownership to C++
            self.my_deimage = args[0]
%}

%pythonappend Fl_Widget::label %{
        if len(args) > 0:
            self.my_label = args[len(args)-1]
%}

DEFINE_CALLBACK(Fl_Widget)
  
%ignore Fl_Widget::image(Fl_Image& a);
%ignore Fl_Widget::deimage(Fl_Image& a);
//%ignore Fl_Widget::label;
%ignore Fl_Widget::user_data(void *);
%ignore Fl_Widget::user_data() const;

// typemap for Fl_Label::measure
%apply int *INOUT { int &w };
%apply int *INOUT { int &h };

// typemap for Fl_Widget::measure_label
%apply int *INOUT { int& ww };
%apply int *INOUT { int& hh };

%include "FL/Fl_Widget.H"

%clear int &w;
%clear int &h;
%clear int& ww;
%clear int& hh;

%extend Fl_Widget {
#include <FL/Fl_Window.H>
#include <FL/Fl_Image.H>

 // reimplementing protected member draw_label()
 void draw_label()
 {
   int X = self->x()+Fl::box_dx(self->box());
   int W = self->w()-Fl::box_dw(self->box());
   if (W > 11 && self->align()&(FL_ALIGN_LEFT|FL_ALIGN_RIGHT)) {X += 3; W -= 6;}
   self->draw_label(X, self->y()+Fl::box_dy(self->box()), W, self->h()-Fl::box_dh(self->box()),self->align());
 }

 // reimplementing protected member draw_label()
 void draw_backdrop()
 {
   if (self->align() & FL_ALIGN_IMAGE_BACKDROP) {
    const Fl_Image *img = self->image();
    // if there is no image, we will not draw the deimage either
    if (img && self->deimage() && !self->active_r())
      img = self->deimage();
    if (img) 
      ((Fl_Image*)img)->draw(self->x()+(self->w()-img->w())/2, self->y()+(self->h()-img->h())/2);
   }
 }
}

ADD_CALLBACK(Fl_Widget)
ADD_USERDATA(Fl_Widget)


%typemap(in) PyObject *PyFunc {
  if (!PyCallable_Check($input)) {
    PyErr_SetString(PyExc_TypeError, "Need a callable object!");
    return NULL;
  }
  $1 = $input;
}