| 1 |
/* File : Fl_Browser.i */ |
| 2 |
//%module Fl_Browser |
| 3 |
|
| 4 |
%feature("docstring") ::Fl_Browser |
| 5 |
""" |
| 6 |
The Fl_Browser widget displays a scrolling list of text lines, and manages |
| 7 |
all the storage for the text. This is not a text editor or spreadsheet! But |
| 8 |
it is useful for showing a vertical list of named objects to the user. |
| 9 |
|
| 10 |
Each line in the browser is identified by number. The numbers start at one |
| 11 |
(this is so that zero can be reserved for 'no line' in the selective browsers). |
| 12 |
Unless otherwise noted, the methods do not check to see if the passed line |
| 13 |
number is in range and legal. It must always be greater than zero |
| 14 |
and <= size(). |
| 15 |
|
| 16 |
Each line contains a null-terminated string of text and a data pointer. |
| 17 |
The text string is displayed, the pointer can be used by the callbacks |
| 18 |
to reference the object the text describes. |
| 19 |
|
| 20 |
The base class does nothing when the user clicks on it. The subclasses |
| 21 |
Fl_Select_Browser, Fl_Hold_Browser, and Fl_Multi_Browser react to user |
| 22 |
clicks to select lines in the browser and do callbacks. |
| 23 |
|
| 24 |
The base class called Fl_Browser_ provides the scrolling and selection |
| 25 |
mechanisms of this and all the subclasses, but the dimensions and appearance |
| 26 |
of each item are determined by the subclass. You can use Fl_Browser_ to |
| 27 |
display information other than text, or text that is dynamically produced |
| 28 |
from your own data structures. If you find that loading the browser is a |
| 29 |
lot of work or is inefficient, you may want to make a subclass of Fl_Browser_. |
| 30 |
""" ; |
| 31 |
|
| 32 |
%{ |
| 33 |
#include "FL/Fl_Browser.H" |
| 34 |
%} |
| 35 |
|
| 36 |
|
| 37 |
%ignore Fl_Browser::add(const char*, void* = 0); |
| 38 |
%ignore Fl_Browser::insert(int, const char*, void* = 0); |
| 39 |
%ignore Fl_Browser::data(int) const ; |
| 40 |
%ignore Fl_Browser::data(int, void* v); |
| 41 |
%ignore Fl_Browser::column_widths(const int*); |
| 42 |
|
| 43 |
|
| 44 |
%include "macros.i" |
| 45 |
|
| 46 |
CHANGE_OWNERSHIP(Fl_Browser) |
| 47 |
|
| 48 |
%include "FL/Fl_Browser.H" |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
#ifdef PYTHON |
| 54 |
|
| 55 |
%include typemaps.i |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
%extend Fl_Browser { |
| 60 |
void add(const char *text, PyObject *data = 0) |
| 61 |
{ |
| 62 |
Py_XINCREF(data); |
| 63 |
if (data) { |
| 64 |
void *tmp = (void *) 0 ; |
| 65 |
if ((SWIG_ConvertPtr(data,(void **) &tmp, 0, SWIG_POINTER_EXCEPTION | 0 )) == -1) { |
| 66 |
PyErr_Clear(); |
| 67 |
// not a C object, just add it as is |
| 68 |
self->add( text, data ); |
| 69 |
} |
| 70 |
else { |
| 71 |
// found C object, add it instead of data |
| 72 |
self->add( text, tmp ); |
| 73 |
} |
| 74 |
} |
| 75 |
else |
| 76 |
self->add( text ); |
| 77 |
} |
| 78 |
void insert(int index, const char *text, PyObject *data = 0) |
| 79 |
{ |
| 80 |
Py_XINCREF(data); |
| 81 |
//self->insert( index, text, data); |
| 82 |
if (data) { |
| 83 |
void *tmp = (void *) 0 ; |
| 84 |
if ((SWIG_ConvertPtr(data,(void **) &tmp, 0, SWIG_POINTER_EXCEPTION | 0 )) == -1) { |
| 85 |
PyErr_Clear(); |
| 86 |
// not a C object, just add it as is |
| 87 |
self->insert( index, text, data ); |
| 88 |
} |
| 89 |
else { |
| 90 |
// found C object, add it instead of data |
| 91 |
self->insert( index, text, tmp ); |
| 92 |
} |
| 93 |
} |
| 94 |
else |
| 95 |
self->insert( index, text, 0 ); |
| 96 |
} |
| 97 |
|
| 98 |
// we keep this for back compatibility |
| 99 |
PyObject *get_data( int index) |
| 100 |
{ |
| 101 |
PyObject *data = (PyObject *)(self->data(index)); |
| 102 |
Py_XINCREF(data); |
| 103 |
return (PyObject *)data; |
| 104 |
} |
| 105 |
//PyObject *data( int index) |
| 106 |
//{ |
| 107 |
// PyObject *data = (PyObject *)(self->data(index)); |
| 108 |
// Py_XINCREF(data); |
| 109 |
// return (PyObject *)data; |
| 110 |
//} |
| 111 |
|
| 112 |
PyObject *data( int index, PyObject *data = 0) |
| 113 |
{ |
| 114 |
//Py_XDECREF((PyObject *)(self->data(index))); |
| 115 |
Py_XINCREF(data); |
| 116 |
|
| 117 |
if (data) { |
| 118 |
void *tmp = (void *) 0 ; |
| 119 |
if ((SWIG_ConvertPtr(data,(void **) &tmp, 0, SWIG_POINTER_EXCEPTION | 0 )) == -1) { |
| 120 |
PyErr_Clear(); |
| 121 |
// not a C object, just add it as is |
| 122 |
self->data( index, data ); |
| 123 |
} |
| 124 |
else { |
| 125 |
// found C object, add it instead of data |
| 126 |
self->data( index, tmp ); |
| 127 |
} |
| 128 |
} |
| 129 |
else { |
| 130 |
PyObject *data = (PyObject *)(self->data(index)); |
| 131 |
Py_XINCREF(data); |
| 132 |
return (PyObject *)data; |
| 133 |
} |
| 134 |
|
| 135 |
Py_XINCREF(Py_None); |
| 136 |
return Py_None; |
| 137 |
} |
| 138 |
|
| 139 |
void column_widths( PyObject *widths ) |
| 140 |
{ |
| 141 |
//static const int no_cols[] = { 0 }; |
| 142 |
|
| 143 |
if (PyTuple_Check(widths)) |
| 144 |
{ |
| 145 |
// the following lines should not be necessary? |
| 146 |
// commented out by ah, June 15, 2003 |
| 147 |
//if (self->column_widths()) |
| 148 |
//{ |
| 149 |
// // FLTK has its own no_cols... |
| 150 |
// if (*self->column_widths()) |
| 151 |
// { |
| 152 |
// //delete [] self->column_widths(); |
| 153 |
// self->column_widths(no_cols); |
| 154 |
// } |
| 155 |
//} |
| 156 |
|
| 157 |
Py_ssize_t sz = PyTuple_Size(widths); |
| 158 |
if (sz) |
| 159 |
{ |
| 160 |
int* cw = new int[sz+1]; |
| 161 |
cw[sz] = 0; |
| 162 |
for (int k = 0; k<sz; ++k) |
| 163 |
{ |
| 164 |
PyObject *obj = PyTuple_GetItem(widths, k); |
| 165 |
if (!obj) |
| 166 |
{ |
| 167 |
delete[] cw; |
| 168 |
return; |
| 169 |
} |
| 170 |
|
| 171 |
if (!PyInt_Check(obj)) |
| 172 |
{ |
| 173 |
delete[] cw; |
| 174 |
PyErr_SetString(PyExc_TypeError, "Integer needed"); |
| 175 |
return; |
| 176 |
} |
| 177 |
|
| 178 |
cw[k] = PyInt_AsLong(obj); |
| 179 |
} |
| 180 |
|
| 181 |
self->column_widths(cw); |
| 182 |
} |
| 183 |
else |
| 184 |
{ |
| 185 |
// nothing to do |
| 186 |
} |
| 187 |
} |
| 188 |
else |
| 189 |
{ |
| 190 |
PyErr_SetString(PyExc_TypeError, "Not a tuple"); |
| 191 |
return; |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
} |
| 196 |
#endif |