| 1 | n/a | # This script generates a Python interface for an Apple Macintosh Manager. |
|---|
| 2 | n/a | # It uses the "bgen" package to generate C code. |
|---|
| 3 | n/a | # The function specifications are generated by scanning the mamager's header file, |
|---|
| 4 | n/a | # using the "scantools" package (customized for this particular manager). |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | import string |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | # Declarations that change for each manager |
|---|
| 9 | n/a | MACHEADERFILE = 'Controls.h' # The Apple header file |
|---|
| 10 | n/a | MODNAME = '_Ctl' # The name of the module |
|---|
| 11 | n/a | OBJECTNAME = 'Control' # The basic name of the objects used here |
|---|
| 12 | n/a | |
|---|
| 13 | n/a | # The following is *usually* unchanged but may still require tuning |
|---|
| 14 | n/a | MODPREFIX = 'Ctl' # The prefix for module-wide routines |
|---|
| 15 | n/a | OBJECTTYPE = OBJECTNAME + 'Handle' # The C type used to represent them |
|---|
| 16 | n/a | OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods |
|---|
| 17 | n/a | INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner |
|---|
| 18 | n/a | OUTPUTFILE = MODNAME + "module.c" # The file generated by this program |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | from macsupport import * |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | # Create the type objects |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | ControlHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) |
|---|
| 25 | n/a | ControlRef = ControlHandle |
|---|
| 26 | n/a | ExistingControlHandle = OpaqueByValueType(OBJECTTYPE, "CtlObj_WhichControl", "BUG") |
|---|
| 27 | n/a | |
|---|
| 28 | n/a | RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") |
|---|
| 29 | n/a | CCTabHandle = OpaqueByValueType("CCTabHandle", "ResObj") |
|---|
| 30 | n/a | AuxCtlHandle = OpaqueByValueType("AuxCtlHandle", "ResObj") |
|---|
| 31 | n/a | ControlPartCode = Type("ControlPartCode", "h") |
|---|
| 32 | n/a | DragConstraint = Type("DragConstraint", "H") |
|---|
| 33 | n/a | ControlVariant = Type("ControlVariant", "h") |
|---|
| 34 | n/a | IconTransformType = Type("IconTransformType", "h") |
|---|
| 35 | n/a | EventModifiers = Type("EventModifiers", "H") |
|---|
| 36 | n/a | ClickActivationResult = Type("ClickActivationResult", "l") |
|---|
| 37 | n/a | ControlButtonGraphicAlignment = Type("ControlButtonGraphicAlignment", "h") |
|---|
| 38 | n/a | ControlButtonTextAlignment = Type("ControlButtonTextAlignment", "h") |
|---|
| 39 | n/a | ControlButtonTextPlacement = Type("ControlButtonTextPlacement", "h") |
|---|
| 40 | n/a | ControlContentType = Type("ControlContentType", "h") |
|---|
| 41 | n/a | ControlFocusPart = Type("ControlFocusPart", "h") |
|---|
| 42 | n/a | |
|---|
| 43 | n/a | ControlFontStyleRec = OpaqueType('ControlFontStyleRec', 'ControlFontStyle') |
|---|
| 44 | n/a | ControlFontStyleRec_ptr = ControlFontStyleRec |
|---|
| 45 | n/a | ControlID = OpaqueType('ControlID', 'PyControlID') |
|---|
| 46 | n/a | ControlID_ptr = ControlID |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | DragTrackingMessage = Type("DragTrackingMessage", "h") |
|---|
| 49 | n/a | DragReference = OpaqueByValueType("DragReference", "DragObj") |
|---|
| 50 | n/a | |
|---|
| 51 | n/a | CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj") |
|---|
| 52 | n/a | CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj") |
|---|
| 53 | n/a | CFDataRef = OpaqueByValueType("CFDataRef", "CFDataRefObj") |
|---|
| 54 | n/a | |
|---|
| 55 | n/a | ControlTabSize = UInt16 |
|---|
| 56 | n/a | ControlTabDirection = UInt16 |
|---|
| 57 | n/a | ControlPopupArrowOrientation = UInt16 |
|---|
| 58 | n/a | ControlPopupArrowSize = UInt16 |
|---|
| 59 | n/a | ControlClockType = UInt16 |
|---|
| 60 | n/a | ControlClockFlags = UInt32 |
|---|
| 61 | n/a | ControlRoundButtonSize = SInt16 |
|---|
| 62 | n/a | DataBrowserViewStyle = OSType |
|---|
| 63 | n/a | DataBrowserItemID = UInt32 |
|---|
| 64 | n/a | DataBrowserEditCommand = UInt32 |
|---|
| 65 | n/a | DataBrowserSelectionAnchorDirection = UInt32 |
|---|
| 66 | n/a | DataBrowserItemState = UInt32 |
|---|
| 67 | n/a | DataBrowserPropertyID = UInt32 |
|---|
| 68 | n/a | DataBrowserRevealOptions = UInt8 |
|---|
| 69 | n/a | DataBrowserSortOrder = UInt16 |
|---|
| 70 | n/a | DataBrowserSelectionFlags = UInt32 |
|---|
| 71 | n/a | DataBrowserPropertyFlags = UInt32 |
|---|
| 72 | n/a | DataBrowserPropertyPart = OSType |
|---|
| 73 | n/a | DataBrowserTableViewColumnID = DataBrowserPropertyID |
|---|
| 74 | n/a | #DataBrowserTableViewColumnDesc = DataBrowserPropertyDesc |
|---|
| 75 | n/a | DataBrowserTableViewHiliteStyle = UInt32 |
|---|
| 76 | n/a | DataBrowserTableViewRowIndex = UInt32 |
|---|
| 77 | n/a | DataBrowserTableViewColumnIndex = UInt32 |
|---|
| 78 | n/a | DataBrowserPropertyType = OSType |
|---|
| 79 | n/a | ControlDisclosureTriangleOrientation = UInt16 |
|---|
| 80 | n/a | |
|---|
| 81 | n/a | DataBrowserTableViewColumnDesc = OpaqueType("DataBrowserTableViewColumnDesc", |
|---|
| 82 | n/a | "DataBrowserTableViewColumnDesc") |
|---|
| 83 | n/a | DataBrowserListViewColumnDesc = OpaqueType("DataBrowserListViewColumnDesc", |
|---|
| 84 | n/a | "DataBrowserListViewColumnDesc") |
|---|
| 85 | n/a | ControlButtonContentInfo = OpaqueType("ControlButtonContentInfo", |
|---|
| 86 | n/a | "ControlButtonContentInfo") |
|---|
| 87 | n/a | ControlButtonContentInfoPtr = ControlButtonContentInfo_ptr = ControlButtonContentInfo |
|---|
| 88 | n/a | |
|---|
| 89 | n/a | ControlTabEntry_ptr = OpaqueType("ControlTabEntry", "ControlTabEntry") |
|---|
| 90 | n/a | |
|---|
| 91 | n/a | ControlBevelThickness = UInt16 |
|---|
| 92 | n/a | ControlBevelButtonBehavior = UInt16 |
|---|
| 93 | n/a | ControlBevelButtonMenuBehavior = UInt16 |
|---|
| 94 | n/a | ControlBevelButtonMenuPlacement = UInt16 |
|---|
| 95 | n/a | ControlPushButtonIconAlignment = UInt16 |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | class ControlActionDefinition(Type): |
|---|
| 98 | n/a | def declare(self, name): |
|---|
| 99 | n/a | Output("%s %s;", self.typeName, name) |
|---|
| 100 | n/a | Output("UniversalProcPtr c_callback;") |
|---|
| 101 | n/a | def passInput(self, name): |
|---|
| 102 | n/a | return "myactionproc_upp" |
|---|
| 103 | n/a | def cleanup(self, name): |
|---|
| 104 | n/a | Output("setcallback((PyObject*)_self, kMyControlActionProcTag, actionProc, &c_callback);") |
|---|
| 105 | n/a | |
|---|
| 106 | n/a | class ControlActionDefinitionNewControl(ControlActionDefinition): |
|---|
| 107 | n/a | def cleanup(self, name): |
|---|
| 108 | n/a | Output("setcallback(_res, kMyControlActionProcTag, liveTrackingProc, &c_callback);") |
|---|
| 109 | n/a | |
|---|
| 110 | n/a | ControlActionUPP = ControlActionDefinition("PyObject*", "O") |
|---|
| 111 | n/a | ControlActionUPPNewControl = ControlActionDefinitionNewControl("PyObject*", "O") |
|---|
| 112 | n/a | ControlSliderOrientation = UInt16 |
|---|
| 113 | n/a | |
|---|
| 114 | n/a | |
|---|
| 115 | n/a | includestuff = includestuff + """ |
|---|
| 116 | n/a | #include <Carbon/Carbon.h> |
|---|
| 117 | n/a | |
|---|
| 118 | n/a | #ifdef USE_TOOLBOX_OBJECT_GLUE |
|---|
| 119 | n/a | extern PyObject *_CtlObj_New(ControlHandle); |
|---|
| 120 | n/a | extern int _CtlObj_Convert(PyObject *, ControlHandle *); |
|---|
| 121 | n/a | |
|---|
| 122 | n/a | #define CtlObj_New _CtlObj_New |
|---|
| 123 | n/a | #define CtlObj_Convert _CtlObj_Convert |
|---|
| 124 | n/a | #endif |
|---|
| 125 | n/a | |
|---|
| 126 | n/a | static PyObject *CtlObj_WhichControl(ControlHandle); |
|---|
| 127 | n/a | |
|---|
| 128 | n/a | #define as_Control(h) ((ControlHandle)h) |
|---|
| 129 | n/a | #define as_Resource(ctl) ((Handle)ctl) |
|---|
| 130 | n/a | #define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp) |
|---|
| 131 | n/a | |
|---|
| 132 | n/a | #define MAXTABS 32 /* maximum number of tabs that we support in a tabs control */ |
|---|
| 133 | n/a | /* |
|---|
| 134 | n/a | ** Parse/generate ControlFontStyleRec records |
|---|
| 135 | n/a | */ |
|---|
| 136 | n/a | #if 0 /* Not needed */ |
|---|
| 137 | n/a | static PyObject * |
|---|
| 138 | n/a | ControlFontStyle_New(ControlFontStyleRec *itself) |
|---|
| 139 | n/a | { |
|---|
| 140 | n/a | |
|---|
| 141 | n/a | return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font, |
|---|
| 142 | n/a | itself->size, itself->style, itself->mode, itself->just, |
|---|
| 143 | n/a | QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor); |
|---|
| 144 | n/a | } |
|---|
| 145 | n/a | #endif |
|---|
| 146 | n/a | |
|---|
| 147 | n/a | static int |
|---|
| 148 | n/a | ControlFontStyle_Convert(PyObject *v, ControlFontStyleRec *itself) |
|---|
| 149 | n/a | { |
|---|
| 150 | n/a | return PyArg_Parse(v, "(hhhhhhO&O&)", &itself->flags, |
|---|
| 151 | n/a | &itself->font, &itself->size, &itself->style, &itself->mode, |
|---|
| 152 | n/a | &itself->just, QdRGB_Convert, &itself->foreColor, |
|---|
| 153 | n/a | QdRGB_Convert, &itself->backColor); |
|---|
| 154 | n/a | } |
|---|
| 155 | n/a | |
|---|
| 156 | n/a | /* |
|---|
| 157 | n/a | ** Parse/generate ControlID records |
|---|
| 158 | n/a | */ |
|---|
| 159 | n/a | static PyObject * |
|---|
| 160 | n/a | PyControlID_New(ControlID *itself) |
|---|
| 161 | n/a | { |
|---|
| 162 | n/a | |
|---|
| 163 | n/a | return Py_BuildValue("O&l", PyMac_BuildOSType, itself->signature, itself->id); |
|---|
| 164 | n/a | } |
|---|
| 165 | n/a | |
|---|
| 166 | n/a | static int |
|---|
| 167 | n/a | PyControlID_Convert(PyObject *v, ControlID *itself) |
|---|
| 168 | n/a | { |
|---|
| 169 | n/a | return PyArg_Parse(v, "(O&l)", PyMac_GetOSType, &itself->signature, &itself->id); |
|---|
| 170 | n/a | } |
|---|
| 171 | n/a | |
|---|
| 172 | n/a | /* |
|---|
| 173 | n/a | ** generate DataBrowserListViewColumnDesc records |
|---|
| 174 | n/a | */ |
|---|
| 175 | n/a | static int |
|---|
| 176 | n/a | DataBrowserTableViewColumnDesc_Convert(PyObject *v, DataBrowserTableViewColumnDesc *itself) |
|---|
| 177 | n/a | { |
|---|
| 178 | n/a | return PyArg_Parse(v, "(lO&l)", |
|---|
| 179 | n/a | &itself->propertyID, |
|---|
| 180 | n/a | PyMac_GetOSType, &itself->propertyType, |
|---|
| 181 | n/a | &itself->propertyFlags); |
|---|
| 182 | n/a | } |
|---|
| 183 | n/a | |
|---|
| 184 | n/a | static int |
|---|
| 185 | n/a | ControlButtonContentInfo_Convert(PyObject *v, ControlButtonContentInfo *itself) |
|---|
| 186 | n/a | { |
|---|
| 187 | n/a | return PyArg_Parse(v, "(hO&)", |
|---|
| 188 | n/a | &itself->contentType, |
|---|
| 189 | n/a | OptResObj_Convert, &itself->u.iconSuite); |
|---|
| 190 | n/a | } |
|---|
| 191 | n/a | |
|---|
| 192 | n/a | static int |
|---|
| 193 | n/a | DataBrowserListViewHeaderDesc_Convert(PyObject *v, DataBrowserListViewHeaderDesc *itself) |
|---|
| 194 | n/a | { |
|---|
| 195 | n/a | itself->version = kDataBrowserListViewLatestHeaderDesc; |
|---|
| 196 | n/a | return PyArg_Parse(v, "(HHhO&HO&O&)", |
|---|
| 197 | n/a | &itself->minimumWidth, |
|---|
| 198 | n/a | &itself->maximumWidth, |
|---|
| 199 | n/a | &itself->titleOffset, |
|---|
| 200 | n/a | CFStringRefObj_Convert, &itself->titleString, |
|---|
| 201 | n/a | &itself->initialOrder, |
|---|
| 202 | n/a | ControlFontStyle_Convert, &itself->btnFontStyle, |
|---|
| 203 | n/a | ControlButtonContentInfo_Convert, &itself->btnContentInfo); |
|---|
| 204 | n/a | } |
|---|
| 205 | n/a | |
|---|
| 206 | n/a | static int |
|---|
| 207 | n/a | DataBrowserListViewColumnDesc_Convert(PyObject *v, DataBrowserListViewColumnDesc *itself) |
|---|
| 208 | n/a | { |
|---|
| 209 | n/a | return PyArg_Parse(v, "(O&O&)", |
|---|
| 210 | n/a | DataBrowserTableViewColumnDesc_Convert, &itself->propertyDesc, |
|---|
| 211 | n/a | DataBrowserListViewHeaderDesc_Convert, &itself->headerBtnDesc); |
|---|
| 212 | n/a | } |
|---|
| 213 | n/a | |
|---|
| 214 | n/a | /* TrackControl and HandleControlClick callback support */ |
|---|
| 215 | n/a | #define kMyControlActionProcTag 'ACTN' /* not an official tag, only for internal use */ |
|---|
| 216 | n/a | static PyObject *tracker; |
|---|
| 217 | n/a | static ControlActionUPP mytracker_upp; |
|---|
| 218 | n/a | static ControlActionUPP myactionproc_upp; |
|---|
| 219 | n/a | static ControlUserPaneKeyDownUPP mykeydownproc_upp; |
|---|
| 220 | n/a | static ControlUserPaneFocusUPP myfocusproc_upp; |
|---|
| 221 | n/a | static ControlUserPaneDrawUPP mydrawproc_upp; |
|---|
| 222 | n/a | static ControlUserPaneIdleUPP myidleproc_upp; |
|---|
| 223 | n/a | static ControlUserPaneHitTestUPP myhittestproc_upp; |
|---|
| 224 | n/a | static ControlUserPaneTrackingUPP mytrackingproc_upp; |
|---|
| 225 | n/a | |
|---|
| 226 | n/a | static int settrackfunc(PyObject *); /* forward */ |
|---|
| 227 | n/a | static void clrtrackfunc(void); /* forward */ |
|---|
| 228 | n/a | static int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *); |
|---|
| 229 | n/a | """ |
|---|
| 230 | n/a | |
|---|
| 231 | n/a | finalstuff = finalstuff + """ |
|---|
| 232 | n/a | static PyObject * |
|---|
| 233 | n/a | CtlObj_NewUnmanaged(ControlHandle itself) |
|---|
| 234 | n/a | { |
|---|
| 235 | n/a | ControlObject *it; |
|---|
| 236 | n/a | if (itself == NULL) return PyMac_Error(resNotFound); |
|---|
| 237 | n/a | it = PyObject_NEW(ControlObject, &Control_Type); |
|---|
| 238 | n/a | if (it == NULL) return NULL; |
|---|
| 239 | n/a | it->ob_itself = itself; |
|---|
| 240 | n/a | it->ob_callbackdict = NULL; |
|---|
| 241 | n/a | return (PyObject *)it; |
|---|
| 242 | n/a | } |
|---|
| 243 | n/a | |
|---|
| 244 | n/a | static PyObject * |
|---|
| 245 | n/a | CtlObj_WhichControl(ControlHandle c) |
|---|
| 246 | n/a | { |
|---|
| 247 | n/a | PyObject *it; |
|---|
| 248 | n/a | |
|---|
| 249 | n/a | if (c == NULL) |
|---|
| 250 | n/a | it = Py_None; |
|---|
| 251 | n/a | else { |
|---|
| 252 | n/a | it = (PyObject *) GetControlReference(c); |
|---|
| 253 | n/a | /* |
|---|
| 254 | n/a | ** If the refcon is zero or doesn't point back to the Python object |
|---|
| 255 | n/a | ** the control is not ours. Return a temporary object. |
|---|
| 256 | n/a | */ |
|---|
| 257 | n/a | if (it == NULL || ((ControlObject *)it)->ob_itself != c) |
|---|
| 258 | n/a | return CtlObj_NewUnmanaged(c); |
|---|
| 259 | n/a | } |
|---|
| 260 | n/a | Py_INCREF(it); |
|---|
| 261 | n/a | return it; |
|---|
| 262 | n/a | } |
|---|
| 263 | n/a | |
|---|
| 264 | n/a | static int |
|---|
| 265 | n/a | settrackfunc(PyObject *obj) |
|---|
| 266 | n/a | { |
|---|
| 267 | n/a | if (tracker) { |
|---|
| 268 | n/a | PyErr_SetString(Ctl_Error, "Tracker function in use"); |
|---|
| 269 | n/a | return 0; |
|---|
| 270 | n/a | } |
|---|
| 271 | n/a | tracker = obj; |
|---|
| 272 | n/a | Py_INCREF(tracker); |
|---|
| 273 | n/a | return 1; |
|---|
| 274 | n/a | } |
|---|
| 275 | n/a | |
|---|
| 276 | n/a | static void |
|---|
| 277 | n/a | clrtrackfunc(void) |
|---|
| 278 | n/a | { |
|---|
| 279 | n/a | Py_XDECREF(tracker); |
|---|
| 280 | n/a | tracker = 0; |
|---|
| 281 | n/a | } |
|---|
| 282 | n/a | |
|---|
| 283 | n/a | static pascal void |
|---|
| 284 | n/a | mytracker(ControlHandle ctl, short part) |
|---|
| 285 | n/a | { |
|---|
| 286 | n/a | PyObject *args, *rv=0; |
|---|
| 287 | n/a | |
|---|
| 288 | n/a | args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part); |
|---|
| 289 | n/a | if (args && tracker) { |
|---|
| 290 | n/a | rv = PyEval_CallObject(tracker, args); |
|---|
| 291 | n/a | Py_DECREF(args); |
|---|
| 292 | n/a | } |
|---|
| 293 | n/a | if (rv) |
|---|
| 294 | n/a | Py_DECREF(rv); |
|---|
| 295 | n/a | else { |
|---|
| 296 | n/a | PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\\n"); |
|---|
| 297 | n/a | PyErr_Print(); |
|---|
| 298 | n/a | } |
|---|
| 299 | n/a | } |
|---|
| 300 | n/a | |
|---|
| 301 | n/a | static int |
|---|
| 302 | n/a | setcallback(PyObject *myself, OSType which, PyObject *callback, UniversalProcPtr *uppp) |
|---|
| 303 | n/a | { |
|---|
| 304 | n/a | ControlObject *self = (ControlObject *)myself; |
|---|
| 305 | n/a | char keybuf[9]; |
|---|
| 306 | n/a | |
|---|
| 307 | n/a | if ( which == kMyControlActionProcTag ) |
|---|
| 308 | n/a | *uppp = (UniversalProcPtr)myactionproc_upp; |
|---|
| 309 | n/a | else if ( which == kControlUserPaneKeyDownProcTag ) |
|---|
| 310 | n/a | *uppp = (UniversalProcPtr)mykeydownproc_upp; |
|---|
| 311 | n/a | else if ( which == kControlUserPaneFocusProcTag ) |
|---|
| 312 | n/a | *uppp = (UniversalProcPtr)myfocusproc_upp; |
|---|
| 313 | n/a | else if ( which == kControlUserPaneDrawProcTag ) |
|---|
| 314 | n/a | *uppp = (UniversalProcPtr)mydrawproc_upp; |
|---|
| 315 | n/a | else if ( which == kControlUserPaneIdleProcTag ) |
|---|
| 316 | n/a | *uppp = (UniversalProcPtr)myidleproc_upp; |
|---|
| 317 | n/a | else if ( which == kControlUserPaneHitTestProcTag ) |
|---|
| 318 | n/a | *uppp = (UniversalProcPtr)myhittestproc_upp; |
|---|
| 319 | n/a | else if ( which == kControlUserPaneTrackingProcTag ) |
|---|
| 320 | n/a | *uppp = (UniversalProcPtr)mytrackingproc_upp; |
|---|
| 321 | n/a | else |
|---|
| 322 | n/a | return -1; |
|---|
| 323 | n/a | /* Only now do we test for clearing of the callback: */ |
|---|
| 324 | n/a | if ( callback == Py_None ) |
|---|
| 325 | n/a | *uppp = NULL; |
|---|
| 326 | n/a | /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */ |
|---|
| 327 | n/a | if ( self->ob_callbackdict == NULL ) |
|---|
| 328 | n/a | if ( (self->ob_callbackdict = PyDict_New()) == NULL ) |
|---|
| 329 | n/a | return -1; |
|---|
| 330 | n/a | /* And store the Python callback */ |
|---|
| 331 | n/a | sprintf(keybuf, "%x", (unsigned)which); |
|---|
| 332 | n/a | if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0) |
|---|
| 333 | n/a | return -1; |
|---|
| 334 | n/a | return 0; |
|---|
| 335 | n/a | } |
|---|
| 336 | n/a | |
|---|
| 337 | n/a | static PyObject * |
|---|
| 338 | n/a | callcallback(ControlObject *self, OSType which, PyObject *arglist) |
|---|
| 339 | n/a | { |
|---|
| 340 | n/a | char keybuf[9]; |
|---|
| 341 | n/a | PyObject *func, *rv; |
|---|
| 342 | n/a | |
|---|
| 343 | n/a | sprintf(keybuf, "%x", (unsigned)which); |
|---|
| 344 | n/a | if ( self->ob_callbackdict == NULL || |
|---|
| 345 | n/a | (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) { |
|---|
| 346 | n/a | PySys_WriteStderr("Control callback %x without callback object\\n", (unsigned)which); |
|---|
| 347 | n/a | return NULL; |
|---|
| 348 | n/a | } |
|---|
| 349 | n/a | rv = PyEval_CallObject(func, arglist); |
|---|
| 350 | n/a | if ( rv == NULL ) { |
|---|
| 351 | n/a | PySys_WriteStderr("Exception in control callback %x handler\\n", (unsigned)which); |
|---|
| 352 | n/a | PyErr_Print(); |
|---|
| 353 | n/a | } |
|---|
| 354 | n/a | return rv; |
|---|
| 355 | n/a | } |
|---|
| 356 | n/a | |
|---|
| 357 | n/a | static pascal void |
|---|
| 358 | n/a | myactionproc(ControlHandle control, SInt16 part) |
|---|
| 359 | n/a | { |
|---|
| 360 | n/a | ControlObject *ctl_obj; |
|---|
| 361 | n/a | PyObject *arglist, *rv; |
|---|
| 362 | n/a | |
|---|
| 363 | n/a | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
|---|
| 364 | n/a | arglist = Py_BuildValue("Oh", ctl_obj, part); |
|---|
| 365 | n/a | rv = callcallback(ctl_obj, kMyControlActionProcTag, arglist); |
|---|
| 366 | n/a | Py_XDECREF(arglist); |
|---|
| 367 | n/a | Py_XDECREF(rv); |
|---|
| 368 | n/a | } |
|---|
| 369 | n/a | |
|---|
| 370 | n/a | static pascal ControlPartCode |
|---|
| 371 | n/a | mykeydownproc(ControlHandle control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) |
|---|
| 372 | n/a | { |
|---|
| 373 | n/a | ControlObject *ctl_obj; |
|---|
| 374 | n/a | PyObject *arglist, *rv; |
|---|
| 375 | n/a | short c_rv = 0; |
|---|
| 376 | n/a | |
|---|
| 377 | n/a | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
|---|
| 378 | n/a | arglist = Py_BuildValue("Ohhh", ctl_obj, keyCode, charCode, modifiers); |
|---|
| 379 | n/a | rv = callcallback(ctl_obj, kControlUserPaneKeyDownProcTag, arglist); |
|---|
| 380 | n/a | Py_XDECREF(arglist); |
|---|
| 381 | n/a | if ( rv ) |
|---|
| 382 | n/a | if (!PyArg_Parse(rv, "h", &c_rv)) |
|---|
| 383 | n/a | PyErr_Clear(); |
|---|
| 384 | n/a | Py_XDECREF(rv); |
|---|
| 385 | n/a | return (ControlPartCode)c_rv; |
|---|
| 386 | n/a | } |
|---|
| 387 | n/a | |
|---|
| 388 | n/a | static pascal ControlPartCode |
|---|
| 389 | n/a | myfocusproc(ControlHandle control, ControlPartCode part) |
|---|
| 390 | n/a | { |
|---|
| 391 | n/a | ControlObject *ctl_obj; |
|---|
| 392 | n/a | PyObject *arglist, *rv; |
|---|
| 393 | n/a | short c_rv = kControlFocusNoPart; |
|---|
| 394 | n/a | |
|---|
| 395 | n/a | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
|---|
| 396 | n/a | arglist = Py_BuildValue("Oh", ctl_obj, part); |
|---|
| 397 | n/a | rv = callcallback(ctl_obj, kControlUserPaneFocusProcTag, arglist); |
|---|
| 398 | n/a | Py_XDECREF(arglist); |
|---|
| 399 | n/a | if ( rv ) |
|---|
| 400 | n/a | if (!PyArg_Parse(rv, "h", &c_rv)) |
|---|
| 401 | n/a | PyErr_Clear(); |
|---|
| 402 | n/a | Py_XDECREF(rv); |
|---|
| 403 | n/a | return (ControlPartCode)c_rv; |
|---|
| 404 | n/a | } |
|---|
| 405 | n/a | |
|---|
| 406 | n/a | static pascal void |
|---|
| 407 | n/a | mydrawproc(ControlHandle control, SInt16 part) |
|---|
| 408 | n/a | { |
|---|
| 409 | n/a | ControlObject *ctl_obj; |
|---|
| 410 | n/a | PyObject *arglist, *rv; |
|---|
| 411 | n/a | |
|---|
| 412 | n/a | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
|---|
| 413 | n/a | arglist = Py_BuildValue("Oh", ctl_obj, part); |
|---|
| 414 | n/a | rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist); |
|---|
| 415 | n/a | Py_XDECREF(arglist); |
|---|
| 416 | n/a | Py_XDECREF(rv); |
|---|
| 417 | n/a | } |
|---|
| 418 | n/a | |
|---|
| 419 | n/a | static pascal void |
|---|
| 420 | n/a | myidleproc(ControlHandle control) |
|---|
| 421 | n/a | { |
|---|
| 422 | n/a | ControlObject *ctl_obj; |
|---|
| 423 | n/a | PyObject *arglist, *rv; |
|---|
| 424 | n/a | |
|---|
| 425 | n/a | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
|---|
| 426 | n/a | arglist = Py_BuildValue("O", ctl_obj); |
|---|
| 427 | n/a | rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist); |
|---|
| 428 | n/a | Py_XDECREF(arglist); |
|---|
| 429 | n/a | Py_XDECREF(rv); |
|---|
| 430 | n/a | } |
|---|
| 431 | n/a | |
|---|
| 432 | n/a | static pascal ControlPartCode |
|---|
| 433 | n/a | myhittestproc(ControlHandle control, Point where) |
|---|
| 434 | n/a | { |
|---|
| 435 | n/a | ControlObject *ctl_obj; |
|---|
| 436 | n/a | PyObject *arglist, *rv; |
|---|
| 437 | n/a | short c_rv = -1; |
|---|
| 438 | n/a | |
|---|
| 439 | n/a | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
|---|
| 440 | n/a | arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where); |
|---|
| 441 | n/a | rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist); |
|---|
| 442 | n/a | Py_XDECREF(arglist); |
|---|
| 443 | n/a | /* Ignore errors, nothing we can do about them */ |
|---|
| 444 | n/a | if ( rv ) |
|---|
| 445 | n/a | if (!PyArg_Parse(rv, "h", &c_rv)) |
|---|
| 446 | n/a | PyErr_Clear(); |
|---|
| 447 | n/a | Py_XDECREF(rv); |
|---|
| 448 | n/a | return (ControlPartCode)c_rv; |
|---|
| 449 | n/a | } |
|---|
| 450 | n/a | |
|---|
| 451 | n/a | static pascal ControlPartCode |
|---|
| 452 | n/a | mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc) |
|---|
| 453 | n/a | { |
|---|
| 454 | n/a | ControlObject *ctl_obj; |
|---|
| 455 | n/a | PyObject *arglist, *rv; |
|---|
| 456 | n/a | short c_rv = -1; |
|---|
| 457 | n/a | |
|---|
| 458 | n/a | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
|---|
| 459 | n/a | /* We cannot pass the actionProc without lots of work */ |
|---|
| 460 | n/a | arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt); |
|---|
| 461 | n/a | rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist); |
|---|
| 462 | n/a | Py_XDECREF(arglist); |
|---|
| 463 | n/a | if ( rv ) |
|---|
| 464 | n/a | if (!PyArg_Parse(rv, "h", &c_rv)) |
|---|
| 465 | n/a | PyErr_Clear(); |
|---|
| 466 | n/a | Py_XDECREF(rv); |
|---|
| 467 | n/a | return (ControlPartCode)c_rv; |
|---|
| 468 | n/a | } |
|---|
| 469 | n/a | """ |
|---|
| 470 | n/a | |
|---|
| 471 | n/a | initstuff = initstuff + """ |
|---|
| 472 | n/a | mytracker_upp = NewControlActionUPP(mytracker); |
|---|
| 473 | n/a | myactionproc_upp = NewControlActionUPP(myactionproc); |
|---|
| 474 | n/a | mykeydownproc_upp = NewControlUserPaneKeyDownUPP(mykeydownproc); |
|---|
| 475 | n/a | myfocusproc_upp = NewControlUserPaneFocusUPP(myfocusproc); |
|---|
| 476 | n/a | mydrawproc_upp = NewControlUserPaneDrawUPP(mydrawproc); |
|---|
| 477 | n/a | myidleproc_upp = NewControlUserPaneIdleUPP(myidleproc); |
|---|
| 478 | n/a | myhittestproc_upp = NewControlUserPaneHitTestUPP(myhittestproc); |
|---|
| 479 | n/a | mytrackingproc_upp = NewControlUserPaneTrackingUPP(mytrackingproc); |
|---|
| 480 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(ControlHandle, CtlObj_New); |
|---|
| 481 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ControlHandle, CtlObj_Convert); |
|---|
| 482 | n/a | """ |
|---|
| 483 | n/a | |
|---|
| 484 | n/a | class MyObjectDefinition(PEP253Mixin, ObjectIdentityMixin, GlobalObjectDefinition): |
|---|
| 485 | n/a | def outputStructMembers(self): |
|---|
| 486 | n/a | GlobalObjectDefinition.outputStructMembers(self) |
|---|
| 487 | n/a | Output("PyObject *ob_callbackdict;") |
|---|
| 488 | n/a | def outputCheckNewArg(self): |
|---|
| 489 | n/a | Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|---|
| 490 | n/a | def outputInitStructMembers(self): |
|---|
| 491 | n/a | GlobalObjectDefinition.outputInitStructMembers(self) |
|---|
| 492 | n/a | Output("SetControlReference(itself, (long)it);") |
|---|
| 493 | n/a | Output("it->ob_callbackdict = NULL;") |
|---|
| 494 | n/a | def outputCleanupStructMembers(self): |
|---|
| 495 | n/a | Output("Py_XDECREF(self->ob_callbackdict);") |
|---|
| 496 | n/a | Output("if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */") |
|---|
| 497 | n/a | |
|---|
| 498 | n/a | # Create the generator groups and link them |
|---|
| 499 | n/a | module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) |
|---|
| 500 | n/a | object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) |
|---|
| 501 | n/a | module.addobject(object) |
|---|
| 502 | n/a | |
|---|
| 503 | n/a | # Create the generator classes used to populate the lists |
|---|
| 504 | n/a | Function = OSErrWeakLinkFunctionGenerator |
|---|
| 505 | n/a | Method = OSErrWeakLinkMethodGenerator |
|---|
| 506 | n/a | |
|---|
| 507 | n/a | # Create and populate the lists |
|---|
| 508 | n/a | functions = [] |
|---|
| 509 | n/a | methods = [] |
|---|
| 510 | n/a | execfile(INPUTFILE) |
|---|
| 511 | n/a | execfile('ctledit.py') |
|---|
| 512 | n/a | |
|---|
| 513 | n/a | # add the populated lists to the generator groups |
|---|
| 514 | n/a | for f in functions: module.add(f) |
|---|
| 515 | n/a | for f in methods: object.add(f) |
|---|
| 516 | n/a | |
|---|
| 517 | n/a | # Manual generator for TrackControl, due to callback ideosyncracies |
|---|
| 518 | n/a | trackcontrol_body = """ |
|---|
| 519 | n/a | ControlPartCode _rv; |
|---|
| 520 | n/a | Point startPoint; |
|---|
| 521 | n/a | ControlActionUPP upp = 0; |
|---|
| 522 | n/a | PyObject *callback = 0; |
|---|
| 523 | n/a | |
|---|
| 524 | n/a | if (!PyArg_ParseTuple(_args, "O&|O", |
|---|
| 525 | n/a | PyMac_GetPoint, &startPoint, &callback)) |
|---|
| 526 | n/a | return NULL; |
|---|
| 527 | n/a | if (callback && callback != Py_None) { |
|---|
| 528 | n/a | if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1) |
|---|
| 529 | n/a | upp = (ControlActionUPP)-1; |
|---|
| 530 | n/a | else { |
|---|
| 531 | n/a | settrackfunc(callback); |
|---|
| 532 | n/a | upp = mytracker_upp; |
|---|
| 533 | n/a | } |
|---|
| 534 | n/a | } |
|---|
| 535 | n/a | _rv = TrackControl(_self->ob_itself, |
|---|
| 536 | n/a | startPoint, |
|---|
| 537 | n/a | upp); |
|---|
| 538 | n/a | clrtrackfunc(); |
|---|
| 539 | n/a | _res = Py_BuildValue("h", |
|---|
| 540 | n/a | _rv); |
|---|
| 541 | n/a | return _res; |
|---|
| 542 | n/a | """ |
|---|
| 543 | n/a | |
|---|
| 544 | n/a | f = ManualGenerator("TrackControl", trackcontrol_body); |
|---|
| 545 | n/a | f.docstring = lambda: "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)" |
|---|
| 546 | n/a | object.add(f) |
|---|
| 547 | n/a | |
|---|
| 548 | n/a | # CJW - added 5/12/99 |
|---|
| 549 | n/a | # Manual generator for HandleControlClick, as for TrackControl |
|---|
| 550 | n/a | handlecontrolclick_body = """ |
|---|
| 551 | n/a | ControlPartCode _rv; |
|---|
| 552 | n/a | Point startPoint; |
|---|
| 553 | n/a | SInt16 modifiers; |
|---|
| 554 | n/a | ControlActionUPP upp = 0; |
|---|
| 555 | n/a | PyObject *callback = 0; |
|---|
| 556 | n/a | |
|---|
| 557 | n/a | if (!PyArg_ParseTuple(_args, "O&h|O", |
|---|
| 558 | n/a | PyMac_GetPoint, &startPoint, |
|---|
| 559 | n/a | &modifiers, |
|---|
| 560 | n/a | &callback)) |
|---|
| 561 | n/a | return NULL; |
|---|
| 562 | n/a | if (callback && callback != Py_None) { |
|---|
| 563 | n/a | if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1) |
|---|
| 564 | n/a | upp = (ControlActionUPP)-1; |
|---|
| 565 | n/a | else { |
|---|
| 566 | n/a | settrackfunc(callback); |
|---|
| 567 | n/a | upp = mytracker_upp; |
|---|
| 568 | n/a | } |
|---|
| 569 | n/a | } |
|---|
| 570 | n/a | _rv = HandleControlClick(_self->ob_itself, |
|---|
| 571 | n/a | startPoint, |
|---|
| 572 | n/a | modifiers, |
|---|
| 573 | n/a | upp); |
|---|
| 574 | n/a | clrtrackfunc(); |
|---|
| 575 | n/a | _res = Py_BuildValue("h", |
|---|
| 576 | n/a | _rv); |
|---|
| 577 | n/a | return _res; |
|---|
| 578 | n/a | """ |
|---|
| 579 | n/a | |
|---|
| 580 | n/a | f = ManualGenerator("HandleControlClick", handlecontrolclick_body); |
|---|
| 581 | n/a | f.docstring = lambda: "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)" |
|---|
| 582 | n/a | object.add(f) |
|---|
| 583 | n/a | |
|---|
| 584 | n/a | # Manual Generator for SetControlData |
|---|
| 585 | n/a | setcontroldata_body = """ |
|---|
| 586 | n/a | OSErr _err; |
|---|
| 587 | n/a | ControlPartCode inPart; |
|---|
| 588 | n/a | ResType inTagName; |
|---|
| 589 | n/a | Size bufferSize; |
|---|
| 590 | n/a | Ptr buffer; |
|---|
| 591 | n/a | |
|---|
| 592 | n/a | if (!PyArg_ParseTuple(_args, "hO&s#", |
|---|
| 593 | n/a | &inPart, |
|---|
| 594 | n/a | PyMac_GetOSType, &inTagName, |
|---|
| 595 | n/a | &buffer, &bufferSize)) |
|---|
| 596 | n/a | return NULL; |
|---|
| 597 | n/a | |
|---|
| 598 | n/a | _err = SetControlData(_self->ob_itself, |
|---|
| 599 | n/a | inPart, |
|---|
| 600 | n/a | inTagName, |
|---|
| 601 | n/a | bufferSize, |
|---|
| 602 | n/a | buffer); |
|---|
| 603 | n/a | |
|---|
| 604 | n/a | if (_err != noErr) |
|---|
| 605 | n/a | return PyMac_Error(_err); |
|---|
| 606 | n/a | _res = Py_None; |
|---|
| 607 | n/a | return _res; |
|---|
| 608 | n/a | """ |
|---|
| 609 | n/a | |
|---|
| 610 | n/a | f = ManualGenerator("SetControlData", setcontroldata_body); |
|---|
| 611 | n/a | f.docstring = lambda: "(stuff) -> None" |
|---|
| 612 | n/a | object.add(f) |
|---|
| 613 | n/a | |
|---|
| 614 | n/a | # Manual Generator for GetControlData |
|---|
| 615 | n/a | getcontroldata_body = """ |
|---|
| 616 | n/a | OSErr _err; |
|---|
| 617 | n/a | ControlPartCode inPart; |
|---|
| 618 | n/a | ResType inTagName; |
|---|
| 619 | n/a | Size bufferSize; |
|---|
| 620 | n/a | Ptr buffer; |
|---|
| 621 | n/a | Size outSize; |
|---|
| 622 | n/a | |
|---|
| 623 | n/a | if (!PyArg_ParseTuple(_args, "hO&", |
|---|
| 624 | n/a | &inPart, |
|---|
| 625 | n/a | PyMac_GetOSType, &inTagName)) |
|---|
| 626 | n/a | return NULL; |
|---|
| 627 | n/a | |
|---|
| 628 | n/a | /* allocate a buffer for the data */ |
|---|
| 629 | n/a | _err = GetControlDataSize(_self->ob_itself, |
|---|
| 630 | n/a | inPart, |
|---|
| 631 | n/a | inTagName, |
|---|
| 632 | n/a | &bufferSize); |
|---|
| 633 | n/a | if (_err != noErr) |
|---|
| 634 | n/a | return PyMac_Error(_err); |
|---|
| 635 | n/a | buffer = PyMem_NEW(char, bufferSize); |
|---|
| 636 | n/a | if (buffer == NULL) |
|---|
| 637 | n/a | return PyErr_NoMemory(); |
|---|
| 638 | n/a | |
|---|
| 639 | n/a | _err = GetControlData(_self->ob_itself, |
|---|
| 640 | n/a | inPart, |
|---|
| 641 | n/a | inTagName, |
|---|
| 642 | n/a | bufferSize, |
|---|
| 643 | n/a | buffer, |
|---|
| 644 | n/a | &outSize); |
|---|
| 645 | n/a | |
|---|
| 646 | n/a | if (_err != noErr) { |
|---|
| 647 | n/a | PyMem_DEL(buffer); |
|---|
| 648 | n/a | return PyMac_Error(_err); |
|---|
| 649 | n/a | } |
|---|
| 650 | n/a | _res = Py_BuildValue("s#", buffer, outSize); |
|---|
| 651 | n/a | PyMem_DEL(buffer); |
|---|
| 652 | n/a | return _res; |
|---|
| 653 | n/a | """ |
|---|
| 654 | n/a | |
|---|
| 655 | n/a | f = ManualGenerator("GetControlData", getcontroldata_body); |
|---|
| 656 | n/a | f.docstring = lambda: "(part, type) -> String" |
|---|
| 657 | n/a | object.add(f) |
|---|
| 658 | n/a | |
|---|
| 659 | n/a | # Manual Generator for SetControlData_Handle |
|---|
| 660 | n/a | setcontroldata_handle_body = """ |
|---|
| 661 | n/a | OSErr _err; |
|---|
| 662 | n/a | ControlPartCode inPart; |
|---|
| 663 | n/a | ResType inTagName; |
|---|
| 664 | n/a | Handle buffer; |
|---|
| 665 | n/a | |
|---|
| 666 | n/a | if (!PyArg_ParseTuple(_args, "hO&O&", |
|---|
| 667 | n/a | &inPart, |
|---|
| 668 | n/a | PyMac_GetOSType, &inTagName, |
|---|
| 669 | n/a | OptResObj_Convert, &buffer)) |
|---|
| 670 | n/a | return NULL; |
|---|
| 671 | n/a | |
|---|
| 672 | n/a | _err = SetControlData(_self->ob_itself, |
|---|
| 673 | n/a | inPart, |
|---|
| 674 | n/a | inTagName, |
|---|
| 675 | n/a | sizeof(buffer), |
|---|
| 676 | n/a | (Ptr)&buffer); |
|---|
| 677 | n/a | |
|---|
| 678 | n/a | if (_err != noErr) |
|---|
| 679 | n/a | return PyMac_Error(_err); |
|---|
| 680 | n/a | _res = Py_None; |
|---|
| 681 | n/a | return _res; |
|---|
| 682 | n/a | """ |
|---|
| 683 | n/a | |
|---|
| 684 | n/a | f = ManualGenerator("SetControlData_Handle", setcontroldata_handle_body); |
|---|
| 685 | n/a | f.docstring = lambda: "(ResObj) -> None" |
|---|
| 686 | n/a | object.add(f) |
|---|
| 687 | n/a | |
|---|
| 688 | n/a | # Manual Generator for GetControlData_Handle |
|---|
| 689 | n/a | getcontroldata_handle_body = """ |
|---|
| 690 | n/a | OSErr _err; |
|---|
| 691 | n/a | ControlPartCode inPart; |
|---|
| 692 | n/a | ResType inTagName; |
|---|
| 693 | n/a | Size bufferSize; |
|---|
| 694 | n/a | Handle hdl; |
|---|
| 695 | n/a | |
|---|
| 696 | n/a | if (!PyArg_ParseTuple(_args, "hO&", |
|---|
| 697 | n/a | &inPart, |
|---|
| 698 | n/a | PyMac_GetOSType, &inTagName)) |
|---|
| 699 | n/a | return NULL; |
|---|
| 700 | n/a | |
|---|
| 701 | n/a | /* Check it is handle-sized */ |
|---|
| 702 | n/a | _err = GetControlDataSize(_self->ob_itself, |
|---|
| 703 | n/a | inPart, |
|---|
| 704 | n/a | inTagName, |
|---|
| 705 | n/a | &bufferSize); |
|---|
| 706 | n/a | if (_err != noErr) |
|---|
| 707 | n/a | return PyMac_Error(_err); |
|---|
| 708 | n/a | if (bufferSize != sizeof(Handle)) { |
|---|
| 709 | n/a | PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)"); |
|---|
| 710 | n/a | return NULL; |
|---|
| 711 | n/a | } |
|---|
| 712 | n/a | |
|---|
| 713 | n/a | _err = GetControlData(_self->ob_itself, |
|---|
| 714 | n/a | inPart, |
|---|
| 715 | n/a | inTagName, |
|---|
| 716 | n/a | sizeof(Handle), |
|---|
| 717 | n/a | (Ptr)&hdl, |
|---|
| 718 | n/a | &bufferSize); |
|---|
| 719 | n/a | |
|---|
| 720 | n/a | if (_err != noErr) { |
|---|
| 721 | n/a | return PyMac_Error(_err); |
|---|
| 722 | n/a | } |
|---|
| 723 | n/a | _res = Py_BuildValue("O&", OptResObj_New, hdl); |
|---|
| 724 | n/a | return _res; |
|---|
| 725 | n/a | """ |
|---|
| 726 | n/a | |
|---|
| 727 | n/a | f = ManualGenerator("GetControlData_Handle", getcontroldata_handle_body); |
|---|
| 728 | n/a | f.docstring = lambda: "(part, type) -> ResObj" |
|---|
| 729 | n/a | object.add(f) |
|---|
| 730 | n/a | |
|---|
| 731 | n/a | # Manual Generator for SetControlData_Callback |
|---|
| 732 | n/a | setcontroldata_callback_body = """ |
|---|
| 733 | n/a | OSErr _err; |
|---|
| 734 | n/a | ControlPartCode inPart; |
|---|
| 735 | n/a | ResType inTagName; |
|---|
| 736 | n/a | PyObject *callback; |
|---|
| 737 | n/a | UniversalProcPtr c_callback; |
|---|
| 738 | n/a | |
|---|
| 739 | n/a | if (!PyArg_ParseTuple(_args, "hO&O", |
|---|
| 740 | n/a | &inPart, |
|---|
| 741 | n/a | PyMac_GetOSType, &inTagName, |
|---|
| 742 | n/a | &callback)) |
|---|
| 743 | n/a | return NULL; |
|---|
| 744 | n/a | |
|---|
| 745 | n/a | if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 ) |
|---|
| 746 | n/a | return NULL; |
|---|
| 747 | n/a | _err = SetControlData(_self->ob_itself, |
|---|
| 748 | n/a | inPart, |
|---|
| 749 | n/a | inTagName, |
|---|
| 750 | n/a | sizeof(c_callback), |
|---|
| 751 | n/a | (Ptr)&c_callback); |
|---|
| 752 | n/a | |
|---|
| 753 | n/a | if (_err != noErr) |
|---|
| 754 | n/a | return PyMac_Error(_err); |
|---|
| 755 | n/a | _res = Py_None; |
|---|
| 756 | n/a | return _res; |
|---|
| 757 | n/a | """ |
|---|
| 758 | n/a | |
|---|
| 759 | n/a | f = ManualGenerator("SetControlData_Callback", setcontroldata_callback_body); |
|---|
| 760 | n/a | f.docstring = lambda: "(callbackfunc) -> None" |
|---|
| 761 | n/a | object.add(f) |
|---|
| 762 | n/a | |
|---|
| 763 | n/a | |
|---|
| 764 | n/a | |
|---|
| 765 | n/a | createtabscontrol_body = """\ |
|---|
| 766 | n/a | OSStatus _err; |
|---|
| 767 | n/a | WindowPtr window; |
|---|
| 768 | n/a | Rect boundsRect; |
|---|
| 769 | n/a | UInt16 size; |
|---|
| 770 | n/a | UInt16 direction; |
|---|
| 771 | n/a | int i; |
|---|
| 772 | n/a | UInt16 numTabs; |
|---|
| 773 | n/a | ControlTabEntry tabArray[MAXTABS]; |
|---|
| 774 | n/a | ControlHandle outControl; |
|---|
| 775 | n/a | PyObject *tabArrayObj, *tabEntry; |
|---|
| 776 | n/a | |
|---|
| 777 | n/a | #ifndef CreateTabsControl |
|---|
| 778 | n/a | PyMac_PRECHECK(CreateTabsControl); |
|---|
| 779 | n/a | #endif |
|---|
| 780 | n/a | if (!PyArg_ParseTuple(_args, "O&O&HHO", |
|---|
| 781 | n/a | WinObj_Convert, &window, |
|---|
| 782 | n/a | PyMac_GetRect, &boundsRect, |
|---|
| 783 | n/a | &size, |
|---|
| 784 | n/a | &direction, |
|---|
| 785 | n/a | &tabArrayObj)) |
|---|
| 786 | n/a | return NULL; |
|---|
| 787 | n/a | |
|---|
| 788 | n/a | i = PySequence_Length(tabArrayObj); |
|---|
| 789 | n/a | if (i == -1) |
|---|
| 790 | n/a | return NULL; |
|---|
| 791 | n/a | if (i > MAXTABS) { |
|---|
| 792 | n/a | PyErr_SetString(Ctl_Error, "Too many tabs"); |
|---|
| 793 | n/a | return NULL; |
|---|
| 794 | n/a | } |
|---|
| 795 | n/a | numTabs = i; |
|---|
| 796 | n/a | for (i=0; i<numTabs; i++) { |
|---|
| 797 | n/a | tabEntry = PySequence_GetItem(tabArrayObj, i); |
|---|
| 798 | n/a | if (tabEntry == NULL) |
|---|
| 799 | n/a | return NULL; |
|---|
| 800 | n/a | if (!PyArg_Parse(tabEntry, "(O&O&B)", |
|---|
| 801 | n/a | ControlButtonContentInfo_Convert, &tabArray[i].icon, |
|---|
| 802 | n/a | CFStringRefObj_Convert, &tabArray[i].name, |
|---|
| 803 | n/a | &tabArray[i].enabled |
|---|
| 804 | n/a | )) |
|---|
| 805 | n/a | return NULL; |
|---|
| 806 | n/a | } |
|---|
| 807 | n/a | |
|---|
| 808 | n/a | _err = CreateTabsControl(window, |
|---|
| 809 | n/a | &boundsRect, |
|---|
| 810 | n/a | size, |
|---|
| 811 | n/a | direction, |
|---|
| 812 | n/a | numTabs, |
|---|
| 813 | n/a | tabArray, |
|---|
| 814 | n/a | &outControl); |
|---|
| 815 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 816 | n/a | _res = Py_BuildValue("O&", |
|---|
| 817 | n/a | CtlObj_New, outControl); |
|---|
| 818 | n/a | return _res;""" |
|---|
| 819 | n/a | |
|---|
| 820 | n/a | f = ManualGenerator("CreateTabsControl", createtabscontrol_body) |
|---|
| 821 | n/a | f.docstring = lambda: "(WindowPtr window, Rect boundsRect, UInt16 size, UInt16 direction, ControlTabEntry tabArray) -> (ControlHandle outControl)" |
|---|
| 822 | n/a | module.add(f) |
|---|
| 823 | n/a | |
|---|
| 824 | n/a | # generate output (open the output file as late as possible) |
|---|
| 825 | n/a | SetOutputFileName(OUTPUTFILE) |
|---|
| 826 | n/a | module.generate() |
|---|