| 1 |
/* File : Fl_Menu_Item.i */ |
| 2 |
//%module Fl_Menu_Item |
| 3 |
|
| 4 |
%feature("docstring") ::Fl_Menu_Item |
| 5 |
""" |
| 6 |
The Fl_Menu_Item structure defines a single menu item that is used by the |
| 7 |
Fl_Menu_ class. This structure is defined as |
| 8 |
|
| 9 |
Fl_Menu_Item : |
| 10 |
text -> character array # label() |
| 11 |
shortcut_ -> unsigned long |
| 12 |
callback_ -> Fl_Callback |
| 13 |
user_data_ |
| 14 |
flags -> int |
| 15 |
labeltype_ -> unsigned character |
| 16 |
labelfont_ -> unsigned character |
| 17 |
labelsize_ -> unsigned character |
| 18 |
labelcolor_ -> unsigned character |
| 19 |
|
| 20 |
|
| 21 |
enum: # values for flags: |
| 22 |
FL_MENU_INACTIVE = 1, |
| 23 |
FL_MENU_TOGGLE = 2, |
| 24 |
FL_MENU_VALUE = 4, |
| 25 |
FL_MENU_RADIO = 8, |
| 26 |
FL_MENU_INVISIBLE = 0x10, |
| 27 |
FL_SUBMENU_POINTER = 0x20, |
| 28 |
FL_SUBMENU = 0x40, |
| 29 |
FL_MENU_DIVIDER = 0x80, |
| 30 |
FL_MENU_HORIZONTAL = 0x100 |
| 31 |
|
| 32 |
|
| 33 |
Typically menu items are statically defined; for example: |
| 34 |
|
| 35 |
MenuTable = ( |
| 36 |
('&alpha', FL_ALT+ord('a'), the_cb, 1), |
| 37 |
('&beta', FL_ALT+ord('b'), the_cb, 2), |
| 38 |
('gamma', FL_ALT+ord('c'), the_cb, 3, FL_MENU_DIVIDER), |
| 39 |
('&strange', 0, strange_cb), |
| 40 |
('&charm', 0, charm_cb), |
| 41 |
('&truth', 0, truth_cb), |
| 42 |
('b&eauty', 0, beauty_cb), |
| 43 |
('sub&menu', 0, 0, 0, FL_SUBMENU), |
| 44 |
('one'), |
| 45 |
('two'), |
| 46 |
('three'), |
| 47 |
(None,), |
| 48 |
('inactive', FL_ALT+'i', 0, 0, FL_MENU_INACTIVE|FL_MENU_DIVIDER), |
| 49 |
('invisible',FL_ALT+'i', 0, 0, FL_MENU_INVISIBLE), |
| 50 |
('check', FL_ALT+'i', 0, 0, FL_MENU_TOGGLE|FL_MENU_VALUE), |
| 51 |
('box', FL_ALT+'i', 0, 0, FL_MENU_TOGGLE), |
| 52 |
(None,); |
| 53 |
|
| 54 |
A submenu title is identified by the bit FL_SUBMENU in the flags field, |
| 55 |
and ends with a label() that is NULL. You can nest menus to any depth. A |
| 56 |
pointer to the first item in the submenu can be treated as an Fl_Menu array |
| 57 |
itself. It is also possible to make seperate submenu arrays with |
| 58 |
FL_SUBMENU_POINTER flags. |
| 59 |
|
| 60 |
You should use the method functions to access structure members and not |
| 61 |
access them directly to avoid compatibility problems with future releases |
| 62 |
of FLTK. |
| 63 |
""" ; |
| 64 |
|
| 65 |
%{ |
| 66 |
#include "FL/Fl_Menu_Item.H" |
| 67 |
#include <CallbackStruct.h> |
| 68 |
#include "FL/Fl_Multi_Label.H" |
| 69 |
%} |
| 70 |
|
| 71 |
//%include "macros.i" |
| 72 |
//CHANGE_OWNERSHIP(Fl_Menu_Item) |
| 73 |
|
| 74 |
%pythonappend Fl_Menu_Item::add_multi_label %{ |
| 75 |
if len(args) > 0: |
| 76 |
args[0].this.disown() |
| 77 |
%} |
| 78 |
|
| 79 |
//%ignore Fl_Menu_Item::image(Fl_Image& a); |
| 80 |
%ignore fl_old_shortcut(const char*); |
| 81 |
%ignore Fl_Menu_Item::callback() const; |
| 82 |
//%ignore Fl_Menu_Item::user_data(); |
| 83 |
|
| 84 |
%pythonappend Fl_Menu_Item::image %{ |
| 85 |
if len(args) > 0: |
| 86 |
#delegate ownership to C++ |
| 87 |
self.my_image = args[0] |
| 88 |
args[0].this.disown() |
| 89 |
%} |
| 90 |
|
| 91 |
%ignore Fl_Menu_Item::user_data(void *); |
| 92 |
%ignore Fl_Menu_Item::user_data() const; |
| 93 |
|
| 94 |
%include "FL/Fl_Menu_Item.H" |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
%extend Fl_Menu_Item { |
| 99 |
PyObject* callback() { |
| 100 |
CallbackStruct *cb = (CallbackStruct*)self->user_data_; |
| 101 |
PyObject *o = Py_BuildValue("O", cb->func); |
| 102 |
return o; |
| 103 |
} |
| 104 |
|
| 105 |
PyObject* user_data() { |
| 106 |
CallbackStruct *cb = (CallbackStruct*)self->user_data_; |
| 107 |
PyObject *o = Py_BuildValue("O", cb->data); |
| 108 |
return o; |
| 109 |
} |
| 110 |
|
| 111 |
void add_multi_label(Fl_Pixmap* pixmap) { |
| 112 |
//save label text as self->image below clobbers it |
| 113 |
const char* itemtext= self->label(); |
| 114 |
|
| 115 |
//Assign image to menu item |
| 116 |
self->image(*pixmap); //clobbers self->label() |
| 117 |
Fl_Multi_Label *ml = new Fl_Multi_Label(); |
| 118 |
|
| 119 |
ml->typea = _FL_IMAGE_LABEL; |
| 120 |
ml->labela = (const char*)pixmap; |
| 121 |
ml->typeb = FL_NORMAL_LABEL; |
| 122 |
ml->labelb = itemtext; |
| 123 |
|
| 124 |
ml->label(self); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
%ignore Fl_Menu_Item::image(Fl_Image& a); |