Debian Codegraph @

swig/Fl_Text_Display.i

raw
1 /* File : Fl_Text_Display.i */
2 //%module Fl_Text_Display
3
4 %feature("docstring") ::Fl_Text_Display
5 """
6 This is the FLTK text display widget. It allows the user to view multiple
7 lines of text and supports highlighting and scrolling. The buffer that is
8 displayed in the widget is managed by the Fl_Text_Buffer class.
9 """ ;
10
11 // Redefine nested struct in global scope in order for SWIG to generate
12 // a proxy class. Only SWIG parses this definition.
13 struct Style_Table_Entry {
14 Fl_Color color;
15 Fl_Font font;
16 int size;
17 unsigned attr;
18 };
19
20
21 %{
22 #include "FL/Fl_Text_Display.H"
23 %}
24
25 %include "macros.i"
26
27 CHANGE_OWNERSHIP(Fl_Text_Display)
28
29 %ignore Fl_Text_Display::buffer(Fl_Text_Buffer& buf);
30 %ignore fl_text_drag_me(int pos, Fl_Text_Display* d);
31 // because of problems with Style_Table_Entry
32 %ignore Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer,const Style_Table_Entry *styleTable,int nStyles, char unfinishedStyle,Unfinished_Style_Cb unfinishedHighlightCB,void *cbArg);
33 %ignore Fl_Text_Display::Style_Table_Entry;
34
35 //ToDo
36 %ignore fl_text_drag_prepare;
37
38 // delegate ownership of passed argument (Fl_Text_Buffer)
39 %pythonappend Fl_Text_Display::buffer %{
40 if len(args) > 0 and args[0] != None:
41 #delegate ownership to C++
42 args[0].this.disown()
43 %}
44
45 // typemap to convert a Python array to
46 // an array of Style_Table_Entry
47 %typemap(in) Fl_Text_Display::Style_Table_Entry const * {
48 // Check if it is a list
49 if (PyList_Check($input)) {
50 Py_ssize_t size = PyList_Size($input);
51 int i = 0;
52 $1 = (Style_Table_Entry*) malloc((size)*sizeof(Style_Table_Entry));
53 for (i = 0; i < size; i++) {
54 PyObject *o = PyList_GetItem($input,i);
55 if (PyList_Check(o)) {
56 Py_ssize_t item_size = PyList_Size(o);
57 $1[i].color = (Fl_Color)PyInt_AsLong(PyList_GetItem(o,0));
58 $1[i].font = (Fl_Font)PyInt_AsLong(PyList_GetItem(o,1));
59 $1[i].size = PyInt_AsLong(PyList_GetItem(o,2));
60 if (item_size > 3)
61 $1[i].attr = PyInt_AsLong(PyList_GetItem(o,3));
62 }
63 }
64 }
65 else {
66 PyErr_SetString(PyExc_TypeError,"not a list");
67 return NULL;
68 }
69 }
70
71 // This cleans up the Style_Table_Entry array we malloc'd before the function call
72 %typemap(freearg) Style_Table_Entry const * {
73 //free((char *) $1);
74 }
75
76
77 // callback handling
78 %{
79 static void UnfinishedStyleCB(int arg1, void *clientdata) {
80 PyObject *func, *arglist;
81 PyObject *result;
82
83 // This is the function ....
84 func = (PyObject *)( ((CallbackStruct *)clientdata)->func);
85 if (((CallbackStruct *)clientdata)->data)
86 {
87 arglist = Py_BuildValue("(iO)", arg1, (PyObject *)(((CallbackStruct *)clientdata)->data) );
88 }
89 else
90 {
91 arglist = Py_BuildValue("(iO)", arg1 );
92 }
93
94 result = PyObject_CallObject(func, arglist);
95
96 Py_DECREF(arglist); // Trash arglist
97 Py_XDECREF(result);
98 if (PyErr_Occurred())
99 {
100 PyErr_Print();
101 }
102
103 return /*void*/;
104
105 }
106 %}
107
108
109
110
111
112 %{
113 // SWIG thinks that Style_Table_Entry is a global class, so we need to trick the C++
114 // compiler into understanding this so called global type.
115 typedef Fl_Text_Display::Style_Table_Entry Style_Table_Entry;
116 %}
117
118 %include "FL/Fl_Text_Display.H"
119
120 %extend Fl_Text_Display {
121 %rename(highlight_data) highlight_data_new;
122 void highlight_data_new(Fl_Text_Buffer *styleBuffer,
123 //const Fl_Text_Display::Style_Table_Entry *styleTable,
124 const Style_Table_Entry *styleTable,
125 int nStyles, char unfinishedStyle,
126 PyObject *func,
127 PyObject *cbArg) {
128 if (!PyCallable_Check(func)) {
129 PyErr_SetString(PyExc_TypeError, "Need a callable object!");
130 }
131 else {
132 CallbackStruct *cb = new CallbackStruct( func , cbArg, (PyObject*)0 );
133 // add reference
134
135 Py_INCREF(func);
136 Py_XINCREF(cbArg);
137 self->highlight_data(styleBuffer, styleTable, nStyles, unfinishedStyle, UnfinishedStyleCB, (void*)cb);
138 }
139
140 }
141 //%rename(highlight_data) highlight_data_new;
142 }
143
144 %typemap(in) PyObject *PyFunc {
145 if (!PyCallable_Check($input)) {
146 PyErr_SetString(PyExc_TypeError, "Need a callable object!");
147 return NULL;
148 }
149 $1 = $input;
150 }