Debian Codegraph @

swig/Fl_Text_Buffer.i

raw
1 /* File : Fl_Text_Buffer.i */
2 //%module Fl_Text_Buffer
3
4 %feature("docstring") ::Fl_Text_Buffer
5 """
6 The Fl_Text_Buffer class is used by the Fl_Text_Display and Fl_Text_Editor
7 to manage complex text data and is based upon the excellent NEdit text
8 editor engine - see http://www.nedit.org/.
9 """ ;
10
11 %{
12 #include "FL/Fl_Text_Buffer.H"
13 %}
14
15 //ToDo
16 %ignore Fl_Text_Buffer::vprintf;
17
18 // deprecated in fltk-1.4
19 %ignore Fl_Text_Selection::position;
20
21 %{
22 #include "CallbackStruct.h"
23
24 struct modify_link {
25 CallbackStruct *handle;
26 modify_link *next;
27 Fl_Text_Buffer* widget;
28 };
29
30 static modify_link *py_modify_funcs = NULL;
31
32 static void PythonModifyCallBack(int pos, int nInserted, int nDeleted, int nRestyled, const char* deletedText, void* cbArg)
33 {
34 PyObject *func, *arglist;
35 PyObject *result;
36 PyObject *obj;
37 CallbackStruct *cb = (CallbackStruct*)cbArg;
38
39 if (cb != NULL) {
40 func = cb->func;
41
42
43 // the user data
44 obj = cb->data;
45
46 if (obj == NULL) {
47 arglist = Py_BuildValue("(iiiis)", pos, nInserted, nDeleted, nRestyled, deletedText );
48 }
49 else {
50 arglist = Py_BuildValue("(iiiisO)", pos, nInserted, nDeleted, nRestyled, deletedText, obj );
51 }
52 result = PyObject_CallObject(func, arglist);
53
54 Py_XDECREF(arglist); // Trash arglist
55 Py_XDECREF(result);
56 if (PyErr_Occurred())
57 {
58 PyErr_Print();
59 }
60
61 }
62 else
63 PyErr_SetString(PyExc_TypeError, "PythonModifyCallBack: need a valid callback!");
64
65 return;
66 }
67 %}
68
69 %apply int *OUTPUT { int* foundPos };
70
71
72
73
74 %include "FL/Fl_Text_Buffer.H"
75
76 %extend Fl_Text_Buffer {
77
78 void add_modify_callback(PyObject *PyFunc, PyObject *PyTarget=0)
79 {
80 if (!PyCallable_Check(PyFunc))
81 {
82 PyErr_SetString(PyExc_TypeError, "Need a callable object!");
83 }
84 else
85 {
86 CallbackStruct *cb = new CallbackStruct( PyFunc, PyTarget, 0, 0 );
87 self->add_modify_callback(PythonModifyCallBack, (void *)cb);
88
89
90 Py_INCREF(PyFunc); /* Add a reference to new callback */
91 Py_XINCREF(PyTarget);
92
93 // add it to global list and also add the widget!
94 modify_link *cb_link = new modify_link;
95 cb_link->next = py_modify_funcs;
96 cb_link->handle = cb;
97 cb_link->widget = self;
98 py_modify_funcs = cb_link;
99 }
100 }
101
102 void remove_modify_callback(PyObject *PyFunc, PyObject *PyWidget, PyObject *PyTarget)
103 {
104 // Search for the handler in the list...
105 modify_link *l, *p;
106 for (l = py_modify_funcs, p = 0; l && !(l->handle->func == PyFunc && (0==PyObject_RichCompareBool(l->handle->data,PyTarget, Py_EQ)) && l->widget == self); p = l, l = l->next);
107 if (l) {
108 // Found it, so remove it from the list...
109 if (p)
110 p->next = l->next;
111 else
112 py_modify_funcs = l->next;
113
114 // remove the callback
115 self->remove_modify_callback(PythonModifyCallBack, (void*)l->handle);
116
117 // reference count
118 Py_DECREF(l->handle->func);
119 Py_XDECREF(l->handle->data);
120
121 // And free the record...
122 delete l->handle;
123 delete l;
124 }
125
126 }
127 }
128
129
130 %typemap(in) PyObject *PyFunc {
131 if (!PyCallable_Check($input)) {
132 PyErr_SetString(PyExc_TypeError, "Need a callable object!");
133 return NULL;
134 }
135 $1 = $input;
136 }
137