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