Debian Codegraph @

swig/Fl_Menu_.i

raw
1 /* File : Fl_Menu_.i */
2 //%module Fl_Menu_
3
4 %feature("docstring") ::Fl_Menu_
5 """
6 All widgets that have a menu in FLTK are subclassed off of this class.
7 Currently FLTK provides you with Fl_Menu_Button, Fl_Menu_Bar, and Fl_Choice .
8
9 The class contains a pointer to an array of structures of type Fl_Menu_Item.
10 The array may either be supplied directly by the user program, or it may be
11 'private': a dynamically allocated array managed by the Fl_Menu_.
12 """ ;
13
14 %{
15 #include "FL/Fl_Menu_.H"
16 #include <menu_item.h>
17 %}
18
19 %include "macros.i"
20
21 CHANGE_OWNERSHIP(Fl_Menu_)
22
23
24 %ignore Fl_Menu_::global();
25 %ignore Fl_Menu_::menu(const Fl_Menu_Item *m);
26 //%ignore Fl_Menu_::menu();
27 %ignore Fl_Menu_::add(const char* label, const char* shortcut, Fl_Callback*, void *user_data, int flags);
28 %ignore Fl_Menu_::menu(const Fl_Menu_Item*);
29 %ignore Fl_Menu_::copy(const Fl_Menu_Item*);
30 %ignore Fl_Menu_::value(const Fl_Menu_Item*);
31
32 DEFINE_CALLBACK(Fl_Menu_)
33
34 %include "FL/Fl_Menu_.H"
35
36
37 %extend Fl_Menu_ {
38
39 void copy(PyObject *args, PyObject *user_data = 0) {
40 PyObject *menuList;
41 if (!PyTuple_Check(args))
42 {
43 printf("Fl_Menu_.menu: not a tuple\n");
44 return;
45 }
46
47 menuList = args;
48 Fl_Menu_Item *theMenuItems = createFl_Menu_Item_Array( NULL, menuList);
49
50 // call the C++ object to add the menu
51 self->copy(theMenuItems, user_data);
52
53 delete [] theMenuItems;
54
55 }
56
57 void menu(PyObject *args) {
58 PyObject *menuList;
59 if (!PyTuple_Check(args))
60 {
61 printf("Fl_Menu_.menu: not a tuple\n");
62 return;
63 }
64
65 menuList = args;
66 Fl_Menu_Item *theMenuItems = createFl_Menu_Item_Array( NULL, menuList);
67
68 // call the C++ object to add the menu
69 self->copy(theMenuItems);
70
71 delete [] theMenuItems;
72
73 }
74
75 int add(PyObject *lObj, PyObject *sObj, PyObject *cObj, PyObject* uObj=0, PyObject* fObj=0) {
76
77 //char *pyLabel=PyString_AsString(lObj);
78 //char* pyLabel = SWIG_Python_str_AsChar(lObj);
79 const char* pyLabel = PyUnicode_AsUTF8(lObj);
80
81 int shortcut=PyInt_AsLong(sObj);
82 PyObject *callback=cObj;
83 PyObject *userData=uObj;
84 int flags=0;
85 if (fObj)
86 flags=PyInt_AsLong(fObj);
87 Fl_Callback *callback_=(Fl_Callback*)0;
88 void *user_data_=0;
89
90
91 // got all the values
92 if (callback && PyCallable_Check(callback))
93 {
94 CallbackStruct *cb = new CallbackStruct( callback, userData, SWIGTYPE_p_Fl_Menu_Item );
95 Py_INCREF(callback);
96 //self->callback(PythonCallBack, (void *)cb);
97 callback_ = (Fl_Callback *)Fl_Menu__PythonCallBack;
98 user_data_ = (void *)cb;
99 }
100
101 return self->add(pyLabel, shortcut, callback_, user_data_, flags);
102 }
103
104 PyObject* menu() {
105 // returns the Fl_Menu_Item structure of the menu
106 // as a Python list
107 const Fl_Menu_Item* items = self->menu();
108 int length = self->size();
109 PyObject *result = PyList_New(length);
110 for (int i = 0; i < length; i++) {
111 PyObject *o = Py_None;
112 if (items[i].text != NULL) {
113 if (items[i].callback_) {
114 // registered callback,
115 // caution, callback information is in user_data
116 CallbackStruct *cb = (CallbackStruct*)items[i].user_data_;
117 o = Py_BuildValue("zlOOl", items[i].text, items[i].shortcut_, cb->func, cb->data, items[i].flags);
118 }
119 else {
120 // no callback, return Py_None
121 o = Py_BuildValue("zlOOl", items[i].text, items[i].shortcut_, Py_None, Py_None, items[i].flags);
122 }
123 }
124 else {
125 // empty item
126 o = Py_BuildValue("OOOOO", Py_None, Py_None, Py_None, Py_None, Py_None);
127 }
128 PyList_SetItem(result, i, o);
129 }
130 return result;
131 }
132 }
133
134
135
136
137