blob: 91df945178f7658d9a2e67477ec92cb6f6c359a4 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Ctl =========================== */
3
4#include "Python.h"
5
6
7
Guido van Rossum17448e21995-01-30 11:53:55 +00008#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Guido van Rossum17448e21995-01-30 11:53:55 +000010
11#include <Controls.h>
Jack Jansenf7d5aa62000-12-10 23:43:49 +000012#ifndef kControlCheckBoxUncheckedValue
13#include <ControlDefinitions.h>
14#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000015
Jack Jansen9d8b96c2000-07-14 22:16:45 +000016staticforward PyObject *CtlObj_WhichControl(ControlHandle);
17
Jack Jansene0581891999-02-07 14:02:03 +000018#define as_Control(h) ((ControlHandle)h)
Jack Jansena1a0fef1999-12-23 14:32:06 +000019#define as_Resource(ctl) ((Handle)ctl)
Jack Jansen74a1e632000-07-14 22:37:27 +000020#if TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +000021#define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
22#else
Jack Jansen1a7d5b12000-03-21 16:25:23 +000023#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
Jack Jansene79dc762000-06-02 21:35:07 +000024#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000025
Jack Jansen21f96871998-02-20 16:02:09 +000026/*
27** Parse/generate ControlFontStyleRec records
28*/
29#if 0 /* Not needed */
Jack Jansen9d8b96c2000-07-14 22:16:45 +000030static PyObject *
31ControlFontStyle_New(itself)
Jack Jansen21f96871998-02-20 16:02:09 +000032 ControlFontStyleRec *itself;
33{
34
35 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
36 itself->size, itself->style, itself->mode, itself->just,
37 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
38}
39#endif
40
Jack Jansen9d8b96c2000-07-14 22:16:45 +000041static int
Jack Jansen21f96871998-02-20 16:02:09 +000042ControlFontStyle_Convert(v, itself)
43 PyObject *v;
44 ControlFontStyleRec *itself;
45{
46 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000047 &itself->font, &itself->size, &itself->style, &itself->mode,
48 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000049 QdRGB_Convert, &itself->backColor);
50}
51
Jack Jansenf7d5aa62000-12-10 23:43:49 +000052/*
53** Parse/generate ControlID records
54*/
55static PyObject *
56PyControlID_New(itself)
57 ControlID *itself;
58{
59
60 return Py_BuildValue("O&l", PyMac_BuildOSType, itself->signature, itself->id);
61}
62
63static int
64PyControlID_Convert(v, itself)
65 PyObject *v;
66 ControlID *itself;
67{
68 return PyArg_ParseTuple(v, "O&l", PyMac_GetOSType, &itself->signature, &itself->id);
69}
70
71
Jack Jansen24c35311999-12-09 22:49:51 +000072/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000073static PyObject *tracker;
74static ControlActionUPP mytracker_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +000075static ControlUserPaneDrawUPP mydrawproc_upp;
76static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +000077static ControlUserPaneHitTestUPP myhittestproc_upp;
78static ControlUserPaneTrackingUPP mytrackingproc_upp;
Jack Jansen848250c1998-05-28 14:20:09 +000079
80extern int settrackfunc(PyObject *); /* forward */
81extern void clrtrackfunc(void); /* forward */
Jack Jansen85152b92000-07-11 21:12:55 +000082staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *);
Jack Jansen848250c1998-05-28 14:20:09 +000083
Guido van Rossum17448e21995-01-30 11:53:55 +000084static PyObject *Ctl_Error;
85
86/* ---------------------- Object type Control ----------------------- */
87
88PyTypeObject Control_Type;
89
90#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
91
92typedef struct ControlObject {
93 PyObject_HEAD
94 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +000095 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +000096} ControlObject;
97
98PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +000099 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000100{
101 ControlObject *it;
102 if (itself == NULL) return PyMac_Error(resNotFound);
103 it = PyObject_NEW(ControlObject, &Control_Type);
104 if (it == NULL) return NULL;
105 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000106 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000107 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000108 return (PyObject *)it;
109}
110CtlObj_Convert(v, p_itself)
111 PyObject *v;
112 ControlHandle *p_itself;
113{
114 if (!CtlObj_Check(v))
115 {
116 PyErr_SetString(PyExc_TypeError, "Control required");
117 return 0;
118 }
119 *p_itself = ((ControlObject *)v)->ob_itself;
120 return 1;
121}
122
123static void CtlObj_dealloc(self)
124 ControlObject *self;
125{
Jack Jansenabc411b2000-03-20 16:09:09 +0000126 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000127 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000128 PyMem_DEL(self);
129}
130
Jack Jansen21f96871998-02-20 16:02:09 +0000131static PyObject *CtlObj_HiliteControl(_self, _args)
132 ControlObject *_self;
133 PyObject *_args;
134{
135 PyObject *_res = NULL;
136 ControlPartCode hiliteState;
137 if (!PyArg_ParseTuple(_args, "h",
138 &hiliteState))
139 return NULL;
140 HiliteControl(_self->ob_itself,
141 hiliteState);
142 Py_INCREF(Py_None);
143 _res = Py_None;
144 return _res;
145}
146
Jack Jansen7d0bc831995-06-09 20:56:31 +0000147static PyObject *CtlObj_ShowControl(_self, _args)
148 ControlObject *_self;
149 PyObject *_args;
150{
151 PyObject *_res = NULL;
152 if (!PyArg_ParseTuple(_args, ""))
153 return NULL;
154 ShowControl(_self->ob_itself);
155 Py_INCREF(Py_None);
156 _res = Py_None;
157 return _res;
158}
159
160static PyObject *CtlObj_HideControl(_self, _args)
161 ControlObject *_self;
162 PyObject *_args;
163{
164 PyObject *_res = NULL;
165 if (!PyArg_ParseTuple(_args, ""))
166 return NULL;
167 HideControl(_self->ob_itself);
168 Py_INCREF(Py_None);
169 _res = Py_None;
170 return _res;
171}
172
Jack Jansen21f96871998-02-20 16:02:09 +0000173static PyObject *CtlObj_IsControlActive(_self, _args)
174 ControlObject *_self;
175 PyObject *_args;
176{
177 PyObject *_res = NULL;
178 Boolean _rv;
179 if (!PyArg_ParseTuple(_args, ""))
180 return NULL;
181 _rv = IsControlActive(_self->ob_itself);
182 _res = Py_BuildValue("b",
183 _rv);
184 return _res;
185}
186
187static PyObject *CtlObj_IsControlVisible(_self, _args)
188 ControlObject *_self;
189 PyObject *_args;
190{
191 PyObject *_res = NULL;
192 Boolean _rv;
193 if (!PyArg_ParseTuple(_args, ""))
194 return NULL;
195 _rv = IsControlVisible(_self->ob_itself);
196 _res = Py_BuildValue("b",
197 _rv);
198 return _res;
199}
200
201static PyObject *CtlObj_ActivateControl(_self, _args)
202 ControlObject *_self;
203 PyObject *_args;
204{
205 PyObject *_res = NULL;
206 OSErr _err;
207 if (!PyArg_ParseTuple(_args, ""))
208 return NULL;
209 _err = ActivateControl(_self->ob_itself);
210 if (_err != noErr) return PyMac_Error(_err);
211 Py_INCREF(Py_None);
212 _res = Py_None;
213 return _res;
214}
215
216static PyObject *CtlObj_DeactivateControl(_self, _args)
217 ControlObject *_self;
218 PyObject *_args;
219{
220 PyObject *_res = NULL;
221 OSErr _err;
222 if (!PyArg_ParseTuple(_args, ""))
223 return NULL;
224 _err = DeactivateControl(_self->ob_itself);
225 if (_err != noErr) return PyMac_Error(_err);
226 Py_INCREF(Py_None);
227 _res = Py_None;
228 return _res;
229}
230
231static PyObject *CtlObj_SetControlVisibility(_self, _args)
232 ControlObject *_self;
233 PyObject *_args;
234{
235 PyObject *_res = NULL;
236 OSErr _err;
237 Boolean inIsVisible;
238 Boolean inDoDraw;
239 if (!PyArg_ParseTuple(_args, "bb",
240 &inIsVisible,
241 &inDoDraw))
242 return NULL;
243 _err = SetControlVisibility(_self->ob_itself,
244 inIsVisible,
245 inDoDraw);
246 if (_err != noErr) return PyMac_Error(_err);
247 Py_INCREF(Py_None);
248 _res = Py_None;
249 return _res;
250}
251
Jack Jansen7d0bc831995-06-09 20:56:31 +0000252static PyObject *CtlObj_Draw1Control(_self, _args)
253 ControlObject *_self;
254 PyObject *_args;
255{
256 PyObject *_res = NULL;
257 if (!PyArg_ParseTuple(_args, ""))
258 return NULL;
259 Draw1Control(_self->ob_itself);
260 Py_INCREF(Py_None);
261 _res = Py_None;
262 return _res;
263}
264
Jack Jansen21f96871998-02-20 16:02:09 +0000265static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000266 ControlObject *_self;
267 PyObject *_args;
268{
269 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000270 OSErr _err;
271 Rect outRect;
272 SInt16 outBaseLineOffset;
273 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000274 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000275 _err = GetBestControlRect(_self->ob_itself,
276 &outRect,
277 &outBaseLineOffset);
278 if (_err != noErr) return PyMac_Error(_err);
279 _res = Py_BuildValue("O&h",
280 PyMac_BuildRect, &outRect,
281 outBaseLineOffset);
282 return _res;
283}
284
285static PyObject *CtlObj_SetControlFontStyle(_self, _args)
286 ControlObject *_self;
287 PyObject *_args;
288{
289 PyObject *_res = NULL;
290 OSErr _err;
291 ControlFontStyleRec inStyle;
292 if (!PyArg_ParseTuple(_args, "O&",
293 ControlFontStyle_Convert, &inStyle))
294 return NULL;
295 _err = SetControlFontStyle(_self->ob_itself,
296 &inStyle);
297 if (_err != noErr) return PyMac_Error(_err);
298 Py_INCREF(Py_None);
299 _res = Py_None;
300 return _res;
301}
302
303static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
304 ControlObject *_self;
305 PyObject *_args;
306{
307 PyObject *_res = NULL;
308 if (!PyArg_ParseTuple(_args, ""))
309 return NULL;
310 DrawControlInCurrentPort(_self->ob_itself);
311 Py_INCREF(Py_None);
312 _res = Py_None;
313 return _res;
314}
315
316static PyObject *CtlObj_SetUpControlBackground(_self, _args)
317 ControlObject *_self;
318 PyObject *_args;
319{
320 PyObject *_res = NULL;
321 OSErr _err;
322 SInt16 inDepth;
323 Boolean inIsColorDevice;
324 if (!PyArg_ParseTuple(_args, "hb",
325 &inDepth,
326 &inIsColorDevice))
327 return NULL;
328 _err = SetUpControlBackground(_self->ob_itself,
329 inDepth,
330 inIsColorDevice);
331 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000332 Py_INCREF(Py_None);
333 _res = Py_None;
334 return _res;
335}
336
Jack Jansena05ac601999-12-12 21:41:51 +0000337static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
338 ControlObject *_self;
339 PyObject *_args;
340{
341 PyObject *_res = NULL;
342 OSErr _err;
343 SInt16 inDepth;
344 Boolean inIsColorDevice;
345 if (!PyArg_ParseTuple(_args, "hb",
346 &inDepth,
347 &inIsColorDevice))
348 return NULL;
349 _err = SetUpControlTextColor(_self->ob_itself,
350 inDepth,
351 inIsColorDevice);
352 if (_err != noErr) return PyMac_Error(_err);
353 Py_INCREF(Py_None);
354 _res = Py_None;
355 return _res;
356}
357
Jack Jansen7d0bc831995-06-09 20:56:31 +0000358static PyObject *CtlObj_DragControl(_self, _args)
359 ControlObject *_self;
360 PyObject *_args;
361{
362 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000363 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000364 Rect limitRect;
365 Rect slopRect;
366 DragConstraint axis;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000367 if (!PyArg_ParseTuple(_args, "O&O&O&H",
Jack Jansen754d4a41995-11-14 10:41:55 +0000368 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000369 PyMac_GetRect, &limitRect,
370 PyMac_GetRect, &slopRect,
371 &axis))
372 return NULL;
373 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000374 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000375 &limitRect,
376 &slopRect,
377 axis);
378 Py_INCREF(Py_None);
379 _res = Py_None;
380 return _res;
381}
382
383static PyObject *CtlObj_TestControl(_self, _args)
384 ControlObject *_self;
385 PyObject *_args;
386{
387 PyObject *_res = NULL;
388 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000389 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000390 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000391 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000392 return NULL;
393 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000394 testPoint);
395 _res = Py_BuildValue("h",
396 _rv);
397 return _res;
398}
399
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000400#if TARGET_API_MAC_CARBON
401
402static PyObject *CtlObj_HandleControlContextualMenuClick(_self, _args)
403 ControlObject *_self;
404 PyObject *_args;
405{
406 PyObject *_res = NULL;
407 OSStatus _err;
408 Point inWhere;
409 Boolean menuDisplayed;
410 if (!PyArg_ParseTuple(_args, "O&",
411 PyMac_GetPoint, &inWhere))
412 return NULL;
413 _err = HandleControlContextualMenuClick(_self->ob_itself,
414 inWhere,
415 &menuDisplayed);
416 if (_err != noErr) return PyMac_Error(_err);
417 _res = Py_BuildValue("b",
418 menuDisplayed);
419 return _res;
420}
421#endif
422
423#if TARGET_API_MAC_CARBON
424
425static PyObject *CtlObj_GetControlClickActivation(_self, _args)
426 ControlObject *_self;
427 PyObject *_args;
428{
429 PyObject *_res = NULL;
430 OSStatus _err;
431 Point inWhere;
432 EventModifiers inModifiers;
433 ClickActivationResult outResult;
434 if (!PyArg_ParseTuple(_args, "O&H",
435 PyMac_GetPoint, &inWhere,
436 &inModifiers))
437 return NULL;
438 _err = GetControlClickActivation(_self->ob_itself,
439 inWhere,
440 inModifiers,
441 &outResult);
442 if (_err != noErr) return PyMac_Error(_err);
443 _res = Py_BuildValue("l",
444 outResult);
445 return _res;
446}
447#endif
448
Jack Jansen21f96871998-02-20 16:02:09 +0000449static PyObject *CtlObj_HandleControlKey(_self, _args)
450 ControlObject *_self;
451 PyObject *_args;
452{
453 PyObject *_res = NULL;
454 SInt16 _rv;
455 SInt16 inKeyCode;
456 SInt16 inCharCode;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000457 EventModifiers inModifiers;
458 if (!PyArg_ParseTuple(_args, "hhH",
Jack Jansen21f96871998-02-20 16:02:09 +0000459 &inKeyCode,
460 &inCharCode,
461 &inModifiers))
462 return NULL;
463 _rv = HandleControlKey(_self->ob_itself,
464 inKeyCode,
465 inCharCode,
466 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000467 _res = Py_BuildValue("h",
468 _rv);
469 return _res;
470}
471
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000472#if TARGET_API_MAC_CARBON
473
474static PyObject *CtlObj_HandleControlSetCursor(_self, _args)
475 ControlObject *_self;
476 PyObject *_args;
477{
478 PyObject *_res = NULL;
479 OSStatus _err;
480 Point localPoint;
481 EventModifiers modifiers;
482 Boolean cursorWasSet;
483 if (!PyArg_ParseTuple(_args, "O&H",
484 PyMac_GetPoint, &localPoint,
485 &modifiers))
486 return NULL;
487 _err = HandleControlSetCursor(_self->ob_itself,
488 localPoint,
489 modifiers,
490 &cursorWasSet);
491 if (_err != noErr) return PyMac_Error(_err);
492 _res = Py_BuildValue("b",
493 cursorWasSet);
494 return _res;
495}
496#endif
497
Jack Jansen7d0bc831995-06-09 20:56:31 +0000498static PyObject *CtlObj_MoveControl(_self, _args)
499 ControlObject *_self;
500 PyObject *_args;
501{
502 PyObject *_res = NULL;
503 SInt16 h;
504 SInt16 v;
505 if (!PyArg_ParseTuple(_args, "hh",
506 &h,
507 &v))
508 return NULL;
509 MoveControl(_self->ob_itself,
510 h,
511 v);
512 Py_INCREF(Py_None);
513 _res = Py_None;
514 return _res;
515}
516
517static PyObject *CtlObj_SizeControl(_self, _args)
518 ControlObject *_self;
519 PyObject *_args;
520{
521 PyObject *_res = NULL;
522 SInt16 w;
523 SInt16 h;
524 if (!PyArg_ParseTuple(_args, "hh",
525 &w,
526 &h))
527 return NULL;
528 SizeControl(_self->ob_itself,
529 w,
530 h);
531 Py_INCREF(Py_None);
532 _res = Py_None;
533 return _res;
534}
535
Jack Jansenae8a68f1995-06-06 12:55:40 +0000536static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000537 ControlObject *_self;
538 PyObject *_args;
539{
540 PyObject *_res = NULL;
541 Str255 title;
542 if (!PyArg_ParseTuple(_args, "O&",
543 PyMac_GetStr255, title))
544 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000545 SetControlTitle(_self->ob_itself,
546 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000547 Py_INCREF(Py_None);
548 _res = Py_None;
549 return _res;
550}
551
Jack Jansenae8a68f1995-06-06 12:55:40 +0000552static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000553 ControlObject *_self;
554 PyObject *_args;
555{
556 PyObject *_res = NULL;
557 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000558 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000559 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000560 GetControlTitle(_self->ob_itself,
561 title);
Jack Jansen41009001999-03-07 20:05:20 +0000562 _res = Py_BuildValue("O&",
563 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000564 return _res;
565}
566
Jack Jansenae8a68f1995-06-06 12:55:40 +0000567static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000568 ControlObject *_self;
569 PyObject *_args;
570{
571 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000572 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000573 if (!PyArg_ParseTuple(_args, ""))
574 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000575 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000576 _res = Py_BuildValue("h",
577 _rv);
578 return _res;
579}
580
Jack Jansen7d0bc831995-06-09 20:56:31 +0000581static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000582 ControlObject *_self;
583 PyObject *_args;
584{
585 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000586 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000587 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000588 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000589 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000590 SetControlValue(_self->ob_itself,
591 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000592 Py_INCREF(Py_None);
593 _res = Py_None;
594 return _res;
595}
596
Jack Jansenae8a68f1995-06-06 12:55:40 +0000597static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000598 ControlObject *_self;
599 PyObject *_args;
600{
601 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000602 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000603 if (!PyArg_ParseTuple(_args, ""))
604 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000605 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000606 _res = Py_BuildValue("h",
607 _rv);
608 return _res;
609}
610
Jack Jansen7d0bc831995-06-09 20:56:31 +0000611static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000612 ControlObject *_self;
613 PyObject *_args;
614{
615 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000616 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000617 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000618 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000619 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000620 SetControlMinimum(_self->ob_itself,
621 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000622 Py_INCREF(Py_None);
623 _res = Py_None;
624 return _res;
625}
626
Jack Jansenae8a68f1995-06-06 12:55:40 +0000627static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000628 ControlObject *_self;
629 PyObject *_args;
630{
631 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000632 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000633 if (!PyArg_ParseTuple(_args, ""))
634 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000635 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000636 _res = Py_BuildValue("h",
637 _rv);
638 return _res;
639}
640
Jack Jansen7d0bc831995-06-09 20:56:31 +0000641static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000642 ControlObject *_self;
643 PyObject *_args;
644{
645 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000646 SInt16 newMaximum;
647 if (!PyArg_ParseTuple(_args, "h",
648 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000649 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000650 SetControlMaximum(_self->ob_itself,
651 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000652 Py_INCREF(Py_None);
653 _res = Py_None;
654 return _res;
655}
656
Jack Jansena05ac601999-12-12 21:41:51 +0000657static PyObject *CtlObj_GetControlViewSize(_self, _args)
658 ControlObject *_self;
659 PyObject *_args;
660{
661 PyObject *_res = NULL;
662 SInt32 _rv;
663 if (!PyArg_ParseTuple(_args, ""))
664 return NULL;
665 _rv = GetControlViewSize(_self->ob_itself);
666 _res = Py_BuildValue("l",
667 _rv);
668 return _res;
669}
670
671static PyObject *CtlObj_SetControlViewSize(_self, _args)
672 ControlObject *_self;
673 PyObject *_args;
674{
675 PyObject *_res = NULL;
676 SInt32 newViewSize;
677 if (!PyArg_ParseTuple(_args, "l",
678 &newViewSize))
679 return NULL;
680 SetControlViewSize(_self->ob_itself,
681 newViewSize);
682 Py_INCREF(Py_None);
683 _res = Py_None;
684 return _res;
685}
686
687static PyObject *CtlObj_GetControl32BitValue(_self, _args)
688 ControlObject *_self;
689 PyObject *_args;
690{
691 PyObject *_res = NULL;
692 SInt32 _rv;
693 if (!PyArg_ParseTuple(_args, ""))
694 return NULL;
695 _rv = GetControl32BitValue(_self->ob_itself);
696 _res = Py_BuildValue("l",
697 _rv);
698 return _res;
699}
700
701static PyObject *CtlObj_SetControl32BitValue(_self, _args)
702 ControlObject *_self;
703 PyObject *_args;
704{
705 PyObject *_res = NULL;
706 SInt32 newValue;
707 if (!PyArg_ParseTuple(_args, "l",
708 &newValue))
709 return NULL;
710 SetControl32BitValue(_self->ob_itself,
711 newValue);
712 Py_INCREF(Py_None);
713 _res = Py_None;
714 return _res;
715}
716
717static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
718 ControlObject *_self;
719 PyObject *_args;
720{
721 PyObject *_res = NULL;
722 SInt32 _rv;
723 if (!PyArg_ParseTuple(_args, ""))
724 return NULL;
725 _rv = GetControl32BitMaximum(_self->ob_itself);
726 _res = Py_BuildValue("l",
727 _rv);
728 return _res;
729}
730
731static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
732 ControlObject *_self;
733 PyObject *_args;
734{
735 PyObject *_res = NULL;
736 SInt32 newMaximum;
737 if (!PyArg_ParseTuple(_args, "l",
738 &newMaximum))
739 return NULL;
740 SetControl32BitMaximum(_self->ob_itself,
741 newMaximum);
742 Py_INCREF(Py_None);
743 _res = Py_None;
744 return _res;
745}
746
747static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
748 ControlObject *_self;
749 PyObject *_args;
750{
751 PyObject *_res = NULL;
752 SInt32 _rv;
753 if (!PyArg_ParseTuple(_args, ""))
754 return NULL;
755 _rv = GetControl32BitMinimum(_self->ob_itself);
756 _res = Py_BuildValue("l",
757 _rv);
758 return _res;
759}
760
761static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
762 ControlObject *_self;
763 PyObject *_args;
764{
765 PyObject *_res = NULL;
766 SInt32 newMinimum;
767 if (!PyArg_ParseTuple(_args, "l",
768 &newMinimum))
769 return NULL;
770 SetControl32BitMinimum(_self->ob_itself,
771 newMinimum);
772 Py_INCREF(Py_None);
773 _res = Py_None;
774 return _res;
775}
776
777static PyObject *CtlObj_IsValidControlHandle(_self, _args)
778 ControlObject *_self;
779 PyObject *_args;
780{
781 PyObject *_res = NULL;
782 Boolean _rv;
783 if (!PyArg_ParseTuple(_args, ""))
784 return NULL;
785 _rv = IsValidControlHandle(_self->ob_itself);
786 _res = Py_BuildValue("b",
787 _rv);
788 return _res;
789}
790
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000791#if TARGET_API_MAC_CARBON
792
793static PyObject *CtlObj_SetControlID(_self, _args)
794 ControlObject *_self;
795 PyObject *_args;
796{
797 PyObject *_res = NULL;
798 OSStatus _err;
799 ControlID inID;
800 if (!PyArg_ParseTuple(_args, "O&",
801 PyControlID_Convert, &inID))
802 return NULL;
803 _err = SetControlID(_self->ob_itself,
804 &inID);
805 if (_err != noErr) return PyMac_Error(_err);
806 Py_INCREF(Py_None);
807 _res = Py_None;
808 return _res;
809}
810#endif
811
812#if TARGET_API_MAC_CARBON
813
814static PyObject *CtlObj_GetControlID(_self, _args)
815 ControlObject *_self;
816 PyObject *_args;
817{
818 PyObject *_res = NULL;
819 OSStatus _err;
820 ControlID outID;
821 if (!PyArg_ParseTuple(_args, ""))
822 return NULL;
823 _err = GetControlID(_self->ob_itself,
824 &outID);
825 if (_err != noErr) return PyMac_Error(_err);
826 _res = Py_BuildValue("O&",
827 PyControlID_New, &outID);
828 return _res;
829}
830#endif
831
Jack Jansena05ac601999-12-12 21:41:51 +0000832static PyObject *CtlObj_RemoveControlProperty(_self, _args)
833 ControlObject *_self;
834 PyObject *_args;
835{
836 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000837 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000838 OSType propertyCreator;
839 OSType propertyTag;
840 if (!PyArg_ParseTuple(_args, "O&O&",
841 PyMac_GetOSType, &propertyCreator,
842 PyMac_GetOSType, &propertyTag))
843 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000844 _err = RemoveControlProperty(_self->ob_itself,
845 propertyCreator,
846 propertyTag);
847 if (_err != noErr) return PyMac_Error(_err);
848 Py_INCREF(Py_None);
849 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000850 return _res;
851}
852
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000853#if TARGET_API_MAC_CARBON
854
855static PyObject *CtlObj_GetControlPropertyAttributes(_self, _args)
856 ControlObject *_self;
857 PyObject *_args;
858{
859 PyObject *_res = NULL;
860 OSStatus _err;
861 OSType propertyCreator;
862 OSType propertyTag;
863 UInt32 attributes;
864 if (!PyArg_ParseTuple(_args, "O&O&",
865 PyMac_GetOSType, &propertyCreator,
866 PyMac_GetOSType, &propertyTag))
867 return NULL;
868 _err = GetControlPropertyAttributes(_self->ob_itself,
869 propertyCreator,
870 propertyTag,
871 &attributes);
872 if (_err != noErr) return PyMac_Error(_err);
873 _res = Py_BuildValue("l",
874 attributes);
875 return _res;
876}
877#endif
878
879#if TARGET_API_MAC_CARBON
880
881static PyObject *CtlObj_ChangeControlPropertyAttributes(_self, _args)
882 ControlObject *_self;
883 PyObject *_args;
884{
885 PyObject *_res = NULL;
886 OSStatus _err;
887 OSType propertyCreator;
888 OSType propertyTag;
889 UInt32 attributesToSet;
890 UInt32 attributesToClear;
891 if (!PyArg_ParseTuple(_args, "O&O&ll",
892 PyMac_GetOSType, &propertyCreator,
893 PyMac_GetOSType, &propertyTag,
894 &attributesToSet,
895 &attributesToClear))
896 return NULL;
897 _err = ChangeControlPropertyAttributes(_self->ob_itself,
898 propertyCreator,
899 propertyTag,
900 attributesToSet,
901 attributesToClear);
902 if (_err != noErr) return PyMac_Error(_err);
903 Py_INCREF(Py_None);
904 _res = Py_None;
905 return _res;
906}
907#endif
908
Jack Jansena05ac601999-12-12 21:41:51 +0000909static PyObject *CtlObj_GetControlRegion(_self, _args)
910 ControlObject *_self;
911 PyObject *_args;
912{
913 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000914 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000915 ControlPartCode inPart;
916 RgnHandle outRegion;
917 if (!PyArg_ParseTuple(_args, "hO&",
918 &inPart,
919 ResObj_Convert, &outRegion))
920 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000921 _err = GetControlRegion(_self->ob_itself,
922 inPart,
923 outRegion);
924 if (_err != noErr) return PyMac_Error(_err);
925 Py_INCREF(Py_None);
926 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000927 return _res;
928}
929
Jack Jansen7d0bc831995-06-09 20:56:31 +0000930static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000931 ControlObject *_self;
932 PyObject *_args;
933{
934 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000935 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000936 if (!PyArg_ParseTuple(_args, ""))
937 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000938 _rv = GetControlVariant(_self->ob_itself);
939 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000940 _rv);
941 return _res;
942}
943
Jack Jansen7d0bc831995-06-09 20:56:31 +0000944static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000945 ControlObject *_self;
946 PyObject *_args;
947{
948 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000949 SInt32 data;
950 if (!PyArg_ParseTuple(_args, "l",
951 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000952 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000953 SetControlReference(_self->ob_itself,
954 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000955 Py_INCREF(Py_None);
956 _res = Py_None;
957 return _res;
958}
959
Jack Jansen7d0bc831995-06-09 20:56:31 +0000960static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000961 ControlObject *_self;
962 PyObject *_args;
963{
964 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000965 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000966 if (!PyArg_ParseTuple(_args, ""))
967 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000968 _rv = GetControlReference(_self->ob_itself);
969 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000970 _rv);
971 return _res;
972}
973
Jack Jansen74a1e632000-07-14 22:37:27 +0000974#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000975
Jack Jansenc7fefed1997-08-15 14:32:18 +0000976static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
977 ControlObject *_self;
978 PyObject *_args;
979{
980 PyObject *_res = NULL;
981 Boolean _rv;
982 AuxCtlHandle acHndl;
983 if (!PyArg_ParseTuple(_args, ""))
984 return NULL;
985 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
986 &acHndl);
987 _res = Py_BuildValue("bO&",
988 _rv,
989 ResObj_New, acHndl);
990 return _res;
991}
Jack Jansene79dc762000-06-02 21:35:07 +0000992#endif
993
Jack Jansen74a1e632000-07-14 22:37:27 +0000994#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +0000995
996static PyObject *CtlObj_SetControlColor(_self, _args)
997 ControlObject *_self;
998 PyObject *_args;
999{
1000 PyObject *_res = NULL;
1001 CCTabHandle newColorTable;
1002 if (!PyArg_ParseTuple(_args, "O&",
1003 ResObj_Convert, &newColorTable))
1004 return NULL;
1005 SetControlColor(_self->ob_itself,
1006 newColorTable);
1007 Py_INCREF(Py_None);
1008 _res = Py_None;
1009 return _res;
1010}
Jack Jansene79dc762000-06-02 21:35:07 +00001011#endif
1012
Jack Jansen21f96871998-02-20 16:02:09 +00001013static PyObject *CtlObj_SendControlMessage(_self, _args)
1014 ControlObject *_self;
1015 PyObject *_args;
1016{
1017 PyObject *_res = NULL;
1018 SInt32 _rv;
1019 SInt16 inMessage;
1020 SInt32 inParam;
1021 if (!PyArg_ParseTuple(_args, "hl",
1022 &inMessage,
1023 &inParam))
1024 return NULL;
1025 _rv = SendControlMessage(_self->ob_itself,
1026 inMessage,
1027 inParam);
1028 _res = Py_BuildValue("l",
1029 _rv);
1030 return _res;
1031}
1032
1033static PyObject *CtlObj_EmbedControl(_self, _args)
1034 ControlObject *_self;
1035 PyObject *_args;
1036{
1037 PyObject *_res = NULL;
1038 OSErr _err;
1039 ControlHandle inContainer;
1040 if (!PyArg_ParseTuple(_args, "O&",
1041 CtlObj_Convert, &inContainer))
1042 return NULL;
1043 _err = EmbedControl(_self->ob_itself,
1044 inContainer);
1045 if (_err != noErr) return PyMac_Error(_err);
1046 Py_INCREF(Py_None);
1047 _res = Py_None;
1048 return _res;
1049}
1050
1051static PyObject *CtlObj_AutoEmbedControl(_self, _args)
1052 ControlObject *_self;
1053 PyObject *_args;
1054{
1055 PyObject *_res = NULL;
1056 OSErr _err;
1057 WindowPtr inWindow;
1058 if (!PyArg_ParseTuple(_args, "O&",
1059 WinObj_Convert, &inWindow))
1060 return NULL;
1061 _err = AutoEmbedControl(_self->ob_itself,
1062 inWindow);
1063 if (_err != noErr) return PyMac_Error(_err);
1064 Py_INCREF(Py_None);
1065 _res = Py_None;
1066 return _res;
1067}
1068
1069static PyObject *CtlObj_GetSuperControl(_self, _args)
1070 ControlObject *_self;
1071 PyObject *_args;
1072{
1073 PyObject *_res = NULL;
1074 OSErr _err;
1075 ControlHandle outParent;
1076 if (!PyArg_ParseTuple(_args, ""))
1077 return NULL;
1078 _err = GetSuperControl(_self->ob_itself,
1079 &outParent);
1080 if (_err != noErr) return PyMac_Error(_err);
1081 _res = Py_BuildValue("O&",
1082 CtlObj_WhichControl, outParent);
1083 return _res;
1084}
1085
1086static PyObject *CtlObj_CountSubControls(_self, _args)
1087 ControlObject *_self;
1088 PyObject *_args;
1089{
1090 PyObject *_res = NULL;
1091 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001092 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +00001093 if (!PyArg_ParseTuple(_args, ""))
1094 return NULL;
1095 _err = CountSubControls(_self->ob_itself,
1096 &outNumChildren);
1097 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001098 _res = Py_BuildValue("H",
Jack Jansen21f96871998-02-20 16:02:09 +00001099 outNumChildren);
1100 return _res;
1101}
1102
1103static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
1104 ControlObject *_self;
1105 PyObject *_args;
1106{
1107 PyObject *_res = NULL;
1108 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001109 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +00001110 ControlHandle outSubControl;
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001111 if (!PyArg_ParseTuple(_args, "H",
Jack Jansen21f96871998-02-20 16:02:09 +00001112 &inIndex))
1113 return NULL;
1114 _err = GetIndexedSubControl(_self->ob_itself,
1115 inIndex,
1116 &outSubControl);
1117 if (_err != noErr) return PyMac_Error(_err);
1118 _res = Py_BuildValue("O&",
1119 CtlObj_WhichControl, outSubControl);
1120 return _res;
1121}
1122
1123static PyObject *CtlObj_SetControlSupervisor(_self, _args)
1124 ControlObject *_self;
1125 PyObject *_args;
1126{
1127 PyObject *_res = NULL;
1128 OSErr _err;
1129 ControlHandle inBoss;
1130 if (!PyArg_ParseTuple(_args, "O&",
1131 CtlObj_Convert, &inBoss))
1132 return NULL;
1133 _err = SetControlSupervisor(_self->ob_itself,
1134 inBoss);
1135 if (_err != noErr) return PyMac_Error(_err);
1136 Py_INCREF(Py_None);
1137 _res = Py_None;
1138 return _res;
1139}
1140
1141static PyObject *CtlObj_GetControlFeatures(_self, _args)
1142 ControlObject *_self;
1143 PyObject *_args;
1144{
1145 PyObject *_res = NULL;
1146 OSErr _err;
1147 UInt32 outFeatures;
1148 if (!PyArg_ParseTuple(_args, ""))
1149 return NULL;
1150 _err = GetControlFeatures(_self->ob_itself,
1151 &outFeatures);
1152 if (_err != noErr) return PyMac_Error(_err);
1153 _res = Py_BuildValue("l",
1154 outFeatures);
1155 return _res;
1156}
1157
1158static PyObject *CtlObj_GetControlDataSize(_self, _args)
1159 ControlObject *_self;
1160 PyObject *_args;
1161{
1162 PyObject *_res = NULL;
1163 OSErr _err;
1164 ControlPartCode inPart;
1165 ResType inTagName;
1166 Size outMaxSize;
1167 if (!PyArg_ParseTuple(_args, "hO&",
1168 &inPart,
1169 PyMac_GetOSType, &inTagName))
1170 return NULL;
1171 _err = GetControlDataSize(_self->ob_itself,
1172 inPart,
1173 inTagName,
1174 &outMaxSize);
1175 if (_err != noErr) return PyMac_Error(_err);
1176 _res = Py_BuildValue("l",
1177 outMaxSize);
1178 return _res;
1179}
1180
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001181#if TARGET_API_MAC_CARBON
1182
Jack Jansen723ad8a2000-12-12 22:10:21 +00001183static PyObject *CtlObj_HandleControlDragTracking(_self, _args)
1184 ControlObject *_self;
1185 PyObject *_args;
1186{
1187 PyObject *_res = NULL;
1188 OSStatus _err;
1189 DragTrackingMessage inMessage;
1190 DragReference inDrag;
1191 Boolean outLikesDrag;
1192 if (!PyArg_ParseTuple(_args, "hO&",
1193 &inMessage,
1194 DragObj_Convert, &inDrag))
1195 return NULL;
1196 _err = HandleControlDragTracking(_self->ob_itself,
1197 inMessage,
1198 inDrag,
1199 &outLikesDrag);
1200 if (_err != noErr) return PyMac_Error(_err);
1201 _res = Py_BuildValue("b",
1202 outLikesDrag);
1203 return _res;
1204}
1205#endif
1206
1207#if TARGET_API_MAC_CARBON
1208
1209static PyObject *CtlObj_HandleControlDragReceive(_self, _args)
1210 ControlObject *_self;
1211 PyObject *_args;
1212{
1213 PyObject *_res = NULL;
1214 OSStatus _err;
1215 DragReference inDrag;
1216 if (!PyArg_ParseTuple(_args, "O&",
1217 DragObj_Convert, &inDrag))
1218 return NULL;
1219 _err = HandleControlDragReceive(_self->ob_itself,
1220 inDrag);
1221 if (_err != noErr) return PyMac_Error(_err);
1222 Py_INCREF(Py_None);
1223 _res = Py_None;
1224 return _res;
1225}
1226#endif
1227
1228#if TARGET_API_MAC_CARBON
1229
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001230static PyObject *CtlObj_SetControlDragTrackingEnabled(_self, _args)
1231 ControlObject *_self;
1232 PyObject *_args;
1233{
1234 PyObject *_res = NULL;
1235 OSStatus _err;
1236 Boolean tracks;
1237 if (!PyArg_ParseTuple(_args, "b",
1238 &tracks))
1239 return NULL;
1240 _err = SetControlDragTrackingEnabled(_self->ob_itself,
1241 tracks);
1242 if (_err != noErr) return PyMac_Error(_err);
1243 Py_INCREF(Py_None);
1244 _res = Py_None;
1245 return _res;
1246}
1247#endif
1248
1249#if TARGET_API_MAC_CARBON
1250
1251static PyObject *CtlObj_IsControlDragTrackingEnabled(_self, _args)
1252 ControlObject *_self;
1253 PyObject *_args;
1254{
1255 PyObject *_res = NULL;
1256 OSStatus _err;
1257 Boolean tracks;
1258 if (!PyArg_ParseTuple(_args, ""))
1259 return NULL;
1260 _err = IsControlDragTrackingEnabled(_self->ob_itself,
1261 &tracks);
1262 if (_err != noErr) return PyMac_Error(_err);
1263 _res = Py_BuildValue("b",
1264 tracks);
1265 return _res;
1266}
1267#endif
1268
1269#if ACCESSOR_CALLS_ARE_FUNCTIONS
1270
1271static PyObject *CtlObj_GetControlBounds(_self, _args)
1272 ControlObject *_self;
1273 PyObject *_args;
1274{
1275 PyObject *_res = NULL;
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001276 Rect bounds;
1277 if (!PyArg_ParseTuple(_args, ""))
1278 return NULL;
Jack Jansena9e3db32001-01-09 22:10:16 +00001279 GetControlBounds(_self->ob_itself,
1280 &bounds);
1281 _res = Py_BuildValue("O&",
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001282 PyMac_BuildRect, &bounds);
1283 return _res;
1284}
1285#endif
1286
1287#if ACCESSOR_CALLS_ARE_FUNCTIONS
1288
1289static PyObject *CtlObj_IsControlHilited(_self, _args)
1290 ControlObject *_self;
1291 PyObject *_args;
1292{
1293 PyObject *_res = NULL;
1294 Boolean _rv;
1295 if (!PyArg_ParseTuple(_args, ""))
1296 return NULL;
1297 _rv = IsControlHilited(_self->ob_itself);
1298 _res = Py_BuildValue("b",
1299 _rv);
1300 return _res;
1301}
1302#endif
1303
1304#if ACCESSOR_CALLS_ARE_FUNCTIONS
1305
1306static PyObject *CtlObj_GetControlHilite(_self, _args)
1307 ControlObject *_self;
1308 PyObject *_args;
1309{
1310 PyObject *_res = NULL;
1311 UInt16 _rv;
1312 if (!PyArg_ParseTuple(_args, ""))
1313 return NULL;
1314 _rv = GetControlHilite(_self->ob_itself);
1315 _res = Py_BuildValue("H",
1316 _rv);
1317 return _res;
1318}
1319#endif
1320
1321#if ACCESSOR_CALLS_ARE_FUNCTIONS
1322
1323static PyObject *CtlObj_GetControlOwner(_self, _args)
1324 ControlObject *_self;
1325 PyObject *_args;
1326{
1327 PyObject *_res = NULL;
1328 WindowPtr _rv;
1329 if (!PyArg_ParseTuple(_args, ""))
1330 return NULL;
1331 _rv = GetControlOwner(_self->ob_itself);
1332 _res = Py_BuildValue("O&",
1333 WinObj_New, _rv);
1334 return _res;
1335}
1336#endif
1337
1338#if ACCESSOR_CALLS_ARE_FUNCTIONS
1339
1340static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1341 ControlObject *_self;
1342 PyObject *_args;
1343{
1344 PyObject *_res = NULL;
1345 Handle _rv;
1346 if (!PyArg_ParseTuple(_args, ""))
1347 return NULL;
1348 _rv = GetControlDataHandle(_self->ob_itself);
1349 _res = Py_BuildValue("O&",
1350 ResObj_New, _rv);
1351 return _res;
1352}
1353#endif
1354
1355#if ACCESSOR_CALLS_ARE_FUNCTIONS
1356
1357static PyObject *CtlObj_GetControlPopupMenuHandle(_self, _args)
1358 ControlObject *_self;
1359 PyObject *_args;
1360{
1361 PyObject *_res = NULL;
1362 MenuHandle _rv;
1363 if (!PyArg_ParseTuple(_args, ""))
1364 return NULL;
1365 _rv = GetControlPopupMenuHandle(_self->ob_itself);
1366 _res = Py_BuildValue("O&",
1367 MenuObj_New, _rv);
1368 return _res;
1369}
1370#endif
1371
1372#if ACCESSOR_CALLS_ARE_FUNCTIONS
1373
1374static PyObject *CtlObj_GetControlPopupMenuID(_self, _args)
1375 ControlObject *_self;
1376 PyObject *_args;
1377{
1378 PyObject *_res = NULL;
1379 short _rv;
1380 if (!PyArg_ParseTuple(_args, ""))
1381 return NULL;
1382 _rv = GetControlPopupMenuID(_self->ob_itself);
1383 _res = Py_BuildValue("h",
1384 _rv);
1385 return _res;
1386}
1387#endif
1388
1389#if ACCESSOR_CALLS_ARE_FUNCTIONS
1390
1391static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1392 ControlObject *_self;
1393 PyObject *_args;
1394{
1395 PyObject *_res = NULL;
1396 Handle dataHandle;
1397 if (!PyArg_ParseTuple(_args, "O&",
1398 ResObj_Convert, &dataHandle))
1399 return NULL;
1400 SetControlDataHandle(_self->ob_itself,
1401 dataHandle);
1402 Py_INCREF(Py_None);
1403 _res = Py_None;
1404 return _res;
1405}
1406#endif
1407
1408#if ACCESSOR_CALLS_ARE_FUNCTIONS
1409
1410static PyObject *CtlObj_SetControlBounds(_self, _args)
1411 ControlObject *_self;
1412 PyObject *_args;
1413{
1414 PyObject *_res = NULL;
1415 Rect bounds;
1416 if (!PyArg_ParseTuple(_args, "O&",
1417 PyMac_GetRect, &bounds))
1418 return NULL;
1419 SetControlBounds(_self->ob_itself,
1420 &bounds);
1421 Py_INCREF(Py_None);
1422 _res = Py_None;
1423 return _res;
1424}
1425#endif
1426
1427#if ACCESSOR_CALLS_ARE_FUNCTIONS
1428
1429static PyObject *CtlObj_SetControlPopupMenuHandle(_self, _args)
1430 ControlObject *_self;
1431 PyObject *_args;
1432{
1433 PyObject *_res = NULL;
1434 MenuHandle popupMenu;
1435 if (!PyArg_ParseTuple(_args, "O&",
1436 MenuObj_Convert, &popupMenu))
1437 return NULL;
1438 SetControlPopupMenuHandle(_self->ob_itself,
1439 popupMenu);
1440 Py_INCREF(Py_None);
1441 _res = Py_None;
1442 return _res;
1443}
1444#endif
1445
1446#if ACCESSOR_CALLS_ARE_FUNCTIONS
1447
1448static PyObject *CtlObj_SetControlPopupMenuID(_self, _args)
1449 ControlObject *_self;
1450 PyObject *_args;
1451{
1452 PyObject *_res = NULL;
1453 short menuID;
1454 if (!PyArg_ParseTuple(_args, "h",
1455 &menuID))
1456 return NULL;
1457 SetControlPopupMenuID(_self->ob_itself,
1458 menuID);
1459 Py_INCREF(Py_None);
1460 _res = Py_None;
1461 return _res;
1462}
1463#endif
1464
1465static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args)
1466 ControlObject *_self;
1467 PyObject *_args;
1468{
1469 PyObject *_res = NULL;
1470 OSErr _err;
1471 SInt16 outValue;
1472 if (!PyArg_ParseTuple(_args, ""))
1473 return NULL;
1474 _err = GetBevelButtonMenuValue(_self->ob_itself,
1475 &outValue);
1476 if (_err != noErr) return PyMac_Error(_err);
1477 _res = Py_BuildValue("h",
1478 outValue);
1479 return _res;
1480}
1481
1482static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args)
1483 ControlObject *_self;
1484 PyObject *_args;
1485{
1486 PyObject *_res = NULL;
1487 OSErr _err;
1488 SInt16 inValue;
1489 if (!PyArg_ParseTuple(_args, "h",
1490 &inValue))
1491 return NULL;
1492 _err = SetBevelButtonMenuValue(_self->ob_itself,
1493 inValue);
1494 if (_err != noErr) return PyMac_Error(_err);
1495 Py_INCREF(Py_None);
1496 _res = Py_None;
1497 return _res;
1498}
1499
1500static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args)
1501 ControlObject *_self;
1502 PyObject *_args;
1503{
1504 PyObject *_res = NULL;
1505 OSErr _err;
1506 MenuHandle outHandle;
1507 if (!PyArg_ParseTuple(_args, ""))
1508 return NULL;
1509 _err = GetBevelButtonMenuHandle(_self->ob_itself,
1510 &outHandle);
1511 if (_err != noErr) return PyMac_Error(_err);
1512 _res = Py_BuildValue("O&",
1513 MenuObj_New, outHandle);
1514 return _res;
1515}
1516
1517static PyObject *CtlObj_SetBevelButtonTransform(_self, _args)
1518 ControlObject *_self;
1519 PyObject *_args;
1520{
1521 PyObject *_res = NULL;
1522 OSErr _err;
1523 IconTransformType transform;
1524 if (!PyArg_ParseTuple(_args, "h",
1525 &transform))
1526 return NULL;
1527 _err = SetBevelButtonTransform(_self->ob_itself,
1528 transform);
1529 if (_err != noErr) return PyMac_Error(_err);
1530 Py_INCREF(Py_None);
1531 _res = Py_None;
1532 return _res;
1533}
1534
1535static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args)
1536 ControlObject *_self;
1537 PyObject *_args;
1538{
1539 PyObject *_res = NULL;
1540 OSErr _err;
1541 SInt16 inValue;
1542 if (!PyArg_ParseTuple(_args, "h",
1543 &inValue))
1544 return NULL;
1545 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
1546 inValue);
1547 if (_err != noErr) return PyMac_Error(_err);
1548 Py_INCREF(Py_None);
1549 _res = Py_None;
1550 return _res;
1551}
1552
1553static PyObject *CtlObj_GetTabContentRect(_self, _args)
1554 ControlObject *_self;
1555 PyObject *_args;
1556{
1557 PyObject *_res = NULL;
1558 OSErr _err;
1559 Rect outContentRect;
1560 if (!PyArg_ParseTuple(_args, ""))
1561 return NULL;
1562 _err = GetTabContentRect(_self->ob_itself,
1563 &outContentRect);
1564 if (_err != noErr) return PyMac_Error(_err);
1565 _res = Py_BuildValue("O&",
1566 PyMac_BuildRect, &outContentRect);
1567 return _res;
1568}
1569
1570static PyObject *CtlObj_SetTabEnabled(_self, _args)
1571 ControlObject *_self;
1572 PyObject *_args;
1573{
1574 PyObject *_res = NULL;
1575 OSErr _err;
1576 SInt16 inTabToHilite;
1577 Boolean inEnabled;
1578 if (!PyArg_ParseTuple(_args, "hb",
1579 &inTabToHilite,
1580 &inEnabled))
1581 return NULL;
1582 _err = SetTabEnabled(_self->ob_itself,
1583 inTabToHilite,
1584 inEnabled);
1585 if (_err != noErr) return PyMac_Error(_err);
1586 Py_INCREF(Py_None);
1587 _res = Py_None;
1588 return _res;
1589}
1590
1591static PyObject *CtlObj_SetImageWellTransform(_self, _args)
1592 ControlObject *_self;
1593 PyObject *_args;
1594{
1595 PyObject *_res = NULL;
1596 OSErr _err;
1597 IconTransformType inTransform;
1598 if (!PyArg_ParseTuple(_args, "h",
1599 &inTransform))
1600 return NULL;
1601 _err = SetImageWellTransform(_self->ob_itself,
1602 inTransform);
1603 if (_err != noErr) return PyMac_Error(_err);
1604 Py_INCREF(Py_None);
1605 _res = Py_None;
1606 return _res;
1607}
1608
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001609static PyObject *CtlObj_as_Resource(_self, _args)
1610 ControlObject *_self;
1611 PyObject *_args;
1612{
1613 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001614 Handle _rv;
1615 if (!PyArg_ParseTuple(_args, ""))
1616 return NULL;
1617 _rv = as_Resource(_self->ob_itself);
1618 _res = Py_BuildValue("O&",
1619 ResObj_New, _rv);
1620 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001621}
1622
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001623static PyObject *CtlObj_GetControlRect(_self, _args)
1624 ControlObject *_self;
1625 PyObject *_args;
1626{
1627 PyObject *_res = NULL;
1628 Rect rect;
1629 if (!PyArg_ParseTuple(_args, ""))
1630 return NULL;
1631 GetControlRect(_self->ob_itself,
1632 &rect);
1633 _res = Py_BuildValue("O&",
1634 PyMac_BuildRect, &rect);
1635 return _res;
1636}
1637
Jack Jansencfb60ee1996-10-01 10:46:46 +00001638static PyObject *CtlObj_DisposeControl(_self, _args)
1639 ControlObject *_self;
1640 PyObject *_args;
1641{
1642 PyObject *_res = NULL;
1643
1644 if (!PyArg_ParseTuple(_args, ""))
1645 return NULL;
1646 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001647 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001648 DisposeControl(_self->ob_itself);
1649 _self->ob_itself = NULL;
1650 }
1651 Py_INCREF(Py_None);
1652 _res = Py_None;
1653 return _res;
1654
1655}
1656
Jack Jansen848250c1998-05-28 14:20:09 +00001657static PyObject *CtlObj_TrackControl(_self, _args)
1658 ControlObject *_self;
1659 PyObject *_args;
1660{
1661 PyObject *_res = NULL;
1662
1663 ControlPartCode _rv;
1664 Point startPoint;
1665 ControlActionUPP upp = 0;
1666 PyObject *callback = 0;
1667
1668 if (!PyArg_ParseTuple(_args, "O&|O",
1669 PyMac_GetPoint, &startPoint, &callback))
1670 return NULL;
1671 if (callback && callback != Py_None) {
1672 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1673 upp = (ControlActionUPP)-1;
1674 else {
1675 settrackfunc(callback);
1676 upp = mytracker_upp;
1677 }
1678 }
1679 _rv = TrackControl(_self->ob_itself,
1680 startPoint,
1681 upp);
1682 clrtrackfunc();
1683 _res = Py_BuildValue("h",
1684 _rv);
1685 return _res;
1686
1687}
1688
Jack Jansen24c35311999-12-09 22:49:51 +00001689static PyObject *CtlObj_HandleControlClick(_self, _args)
1690 ControlObject *_self;
1691 PyObject *_args;
1692{
1693 PyObject *_res = NULL;
1694
1695 ControlPartCode _rv;
1696 Point startPoint;
1697 SInt16 modifiers;
1698 ControlActionUPP upp = 0;
1699 PyObject *callback = 0;
1700
1701 if (!PyArg_ParseTuple(_args, "O&h|O",
1702 PyMac_GetPoint, &startPoint,
1703 &modifiers,
1704 &callback))
1705 return NULL;
1706 if (callback && callback != Py_None) {
1707 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1708 upp = (ControlActionUPP)-1;
1709 else {
1710 settrackfunc(callback);
1711 upp = mytracker_upp;
1712 }
1713 }
1714 _rv = HandleControlClick(_self->ob_itself,
1715 startPoint,
1716 modifiers,
1717 upp);
1718 clrtrackfunc();
1719 _res = Py_BuildValue("h",
1720 _rv);
1721 return _res;
1722
1723}
1724
1725static PyObject *CtlObj_SetControlData(_self, _args)
1726 ControlObject *_self;
1727 PyObject *_args;
1728{
1729 PyObject *_res = NULL;
1730
1731 OSErr _err;
1732 ControlPartCode inPart;
1733 ResType inTagName;
1734 Size bufferSize;
1735 Ptr buffer;
1736
1737 if (!PyArg_ParseTuple(_args, "hO&s#",
1738 &inPart,
1739 PyMac_GetOSType, &inTagName,
1740 &buffer, &bufferSize))
1741 return NULL;
1742
1743 _err = SetControlData(_self->ob_itself,
1744 inPart,
1745 inTagName,
1746 bufferSize,
1747 buffer);
1748
1749 if (_err != noErr)
1750 return PyMac_Error(_err);
1751 _res = Py_None;
1752 return _res;
1753
1754}
1755
1756static PyObject *CtlObj_GetControlData(_self, _args)
1757 ControlObject *_self;
1758 PyObject *_args;
1759{
1760 PyObject *_res = NULL;
1761
1762 OSErr _err;
1763 ControlPartCode inPart;
1764 ResType inTagName;
1765 Size bufferSize;
1766 Ptr buffer;
1767 Size outSize;
1768
1769 if (!PyArg_ParseTuple(_args, "hO&",
1770 &inPart,
1771 PyMac_GetOSType, &inTagName))
1772 return NULL;
1773
1774 /* allocate a buffer for the data */
1775 _err = GetControlDataSize(_self->ob_itself,
1776 inPart,
1777 inTagName,
1778 &bufferSize);
1779 if (_err != noErr)
1780 return PyMac_Error(_err);
1781 buffer = PyMem_NEW(char, bufferSize);
1782 if (buffer == NULL)
1783 return PyErr_NoMemory();
1784
1785 _err = GetControlData(_self->ob_itself,
1786 inPart,
1787 inTagName,
1788 bufferSize,
1789 buffer,
1790 &outSize);
1791
1792 if (_err != noErr) {
1793 PyMem_DEL(buffer);
1794 return PyMac_Error(_err);
1795 }
1796 _res = Py_BuildValue("s#", buffer, outSize);
1797 PyMem_DEL(buffer);
1798 return _res;
1799
1800}
1801
Jack Jansena9e3db32001-01-09 22:10:16 +00001802static PyObject *CtlObj_SetControlData_Handle(_self, _args)
Jack Jansen1f9249c1999-12-19 00:05:50 +00001803 ControlObject *_self;
1804 PyObject *_args;
1805{
1806 PyObject *_res = NULL;
1807
1808 OSErr _err;
1809 ControlPartCode inPart;
1810 ResType inTagName;
1811 Handle buffer;
1812
1813 if (!PyArg_ParseTuple(_args, "hO&O&",
1814 &inPart,
1815 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001816 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001817 return NULL;
1818
1819 _err = SetControlData(_self->ob_itself,
1820 inPart,
1821 inTagName,
1822 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001823 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001824
1825 if (_err != noErr)
1826 return PyMac_Error(_err);
1827 _res = Py_None;
1828 return _res;
1829
1830}
1831
Jack Jansena9e3db32001-01-09 22:10:16 +00001832static PyObject *CtlObj_GetControlData_Handle(_self, _args)
Jack Jansen1f9249c1999-12-19 00:05:50 +00001833 ControlObject *_self;
1834 PyObject *_args;
1835{
1836 PyObject *_res = NULL;
1837
1838 OSErr _err;
1839 ControlPartCode inPart;
1840 ResType inTagName;
1841 Size bufferSize;
1842 Handle hdl;
1843
1844 if (!PyArg_ParseTuple(_args, "hO&",
1845 &inPart,
1846 PyMac_GetOSType, &inTagName))
1847 return NULL;
1848
1849 /* Check it is handle-sized */
1850 _err = GetControlDataSize(_self->ob_itself,
1851 inPart,
1852 inTagName,
1853 &bufferSize);
1854 if (_err != noErr)
1855 return PyMac_Error(_err);
1856 if (bufferSize != sizeof(Handle)) {
1857 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1858 return NULL;
1859 }
1860
1861 _err = GetControlData(_self->ob_itself,
1862 inPart,
1863 inTagName,
1864 sizeof(Handle),
1865 (Ptr)&hdl,
1866 &bufferSize);
1867
1868 if (_err != noErr) {
1869 return PyMac_Error(_err);
1870 }
1871 return Py_BuildValue("O&", OptResObj_New, hdl);
1872
1873}
1874
Jack Jansena9e3db32001-01-09 22:10:16 +00001875static PyObject *CtlObj_SetControlData_Callback(_self, _args)
Jack Jansenabc411b2000-03-20 16:09:09 +00001876 ControlObject *_self;
1877 PyObject *_args;
1878{
1879 PyObject *_res = NULL;
1880
1881 OSErr _err;
1882 ControlPartCode inPart;
1883 ResType inTagName;
1884 PyObject *callback;
Jack Jansen85152b92000-07-11 21:12:55 +00001885 UniversalProcPtr c_callback;
Jack Jansenabc411b2000-03-20 16:09:09 +00001886
1887 if (!PyArg_ParseTuple(_args, "hO&O",
1888 &inPart,
1889 PyMac_GetOSType, &inTagName,
1890 &callback))
1891 return NULL;
1892
Jack Jansen85152b92000-07-11 21:12:55 +00001893 if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
Jack Jansenabc411b2000-03-20 16:09:09 +00001894 return NULL;
1895 _err = SetControlData(_self->ob_itself,
1896 inPart,
1897 inTagName,
1898 sizeof(c_callback),
1899 (Ptr)&c_callback);
1900
1901 if (_err != noErr)
1902 return PyMac_Error(_err);
1903 _res = Py_None;
1904 return _res;
1905
1906}
Jack Jansene79dc762000-06-02 21:35:07 +00001907
Jack Jansen736b51d2001-01-12 23:39:00 +00001908#if !TARGET_API_MAC_CARBON
Jack Jansenabc411b2000-03-20 16:09:09 +00001909
Jack Jansen4c704131998-06-19 13:35:14 +00001910static PyObject *CtlObj_GetPopupData(_self, _args)
1911 ControlObject *_self;
1912 PyObject *_args;
1913{
1914 PyObject *_res = NULL;
1915
1916 PopupPrivateDataHandle hdl;
1917
1918 if ( (*_self->ob_itself)->contrlData == NULL ) {
1919 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1920 return 0;
1921 }
1922 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1923 HLock((Handle)hdl);
1924 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1925 HUnlock((Handle)hdl);
1926 return _res;
1927
1928}
Jack Jansene79dc762000-06-02 21:35:07 +00001929#endif
1930
Jack Jansen736b51d2001-01-12 23:39:00 +00001931#if !TARGET_API_MAC_CARBON
Jack Jansen4c704131998-06-19 13:35:14 +00001932
1933static PyObject *CtlObj_SetPopupData(_self, _args)
1934 ControlObject *_self;
1935 PyObject *_args;
1936{
1937 PyObject *_res = NULL;
1938
1939 PopupPrivateDataHandle hdl;
1940 MenuHandle mHandle;
1941 short mID;
1942
1943 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1944 return 0;
1945 if ( (*_self->ob_itself)->contrlData == NULL ) {
1946 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1947 return 0;
1948 }
1949 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1950 (*hdl)->mHandle = mHandle;
1951 (*hdl)->mID = mID;
1952 Py_INCREF(Py_None);
1953 return Py_None;
1954
1955}
Jack Jansene79dc762000-06-02 21:35:07 +00001956#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001957
Guido van Rossum17448e21995-01-30 11:53:55 +00001958static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001959 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1960 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001961 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1962 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001963 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1964 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001965 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1966 "() -> (Boolean _rv)"},
1967 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1968 "() -> (Boolean _rv)"},
1969 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1970 "() -> None"},
1971 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1972 "() -> None"},
1973 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1974 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001975 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1976 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001977 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1978 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1979 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1980 "(ControlFontStyleRec inStyle) -> None"},
1981 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1982 "() -> None"},
1983 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1984 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001985 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1986 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001987 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001988 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001989 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001990 "(Point testPoint) -> (ControlPartCode _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001991
1992#if TARGET_API_MAC_CARBON
1993 {"HandleControlContextualMenuClick", (PyCFunction)CtlObj_HandleControlContextualMenuClick, 1,
1994 "(Point inWhere) -> (Boolean menuDisplayed)"},
1995#endif
1996
1997#if TARGET_API_MAC_CARBON
1998 {"GetControlClickActivation", (PyCFunction)CtlObj_GetControlClickActivation, 1,
1999 "(Point inWhere, EventModifiers inModifiers) -> (ClickActivationResult outResult)"},
2000#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002001 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002002 "(SInt16 inKeyCode, SInt16 inCharCode, EventModifiers inModifiers) -> (SInt16 _rv)"},
2003
2004#if TARGET_API_MAC_CARBON
2005 {"HandleControlSetCursor", (PyCFunction)CtlObj_HandleControlSetCursor, 1,
2006 "(Point localPoint, EventModifiers modifiers) -> (Boolean cursorWasSet)"},
2007#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002008 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002009 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002010 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002011 "(SInt16 w, SInt16 h) -> None"},
2012 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
2013 "(Str255 title) -> None"},
2014 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00002015 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002016 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002017 "() -> (SInt16 _rv)"},
2018 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
2019 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002020 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002021 "() -> (SInt16 _rv)"},
2022 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
2023 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002024 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002025 "() -> (SInt16 _rv)"},
2026 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
2027 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00002028 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
2029 "() -> (SInt32 _rv)"},
2030 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
2031 "(SInt32 newViewSize) -> None"},
2032 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
2033 "() -> (SInt32 _rv)"},
2034 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
2035 "(SInt32 newValue) -> None"},
2036 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
2037 "() -> (SInt32 _rv)"},
2038 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
2039 "(SInt32 newMaximum) -> None"},
2040 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
2041 "() -> (SInt32 _rv)"},
2042 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
2043 "(SInt32 newMinimum) -> None"},
2044 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
2045 "() -> (Boolean _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002046
2047#if TARGET_API_MAC_CARBON
2048 {"SetControlID", (PyCFunction)CtlObj_SetControlID, 1,
2049 "(ControlID inID) -> None"},
2050#endif
2051
2052#if TARGET_API_MAC_CARBON
2053 {"GetControlID", (PyCFunction)CtlObj_GetControlID, 1,
2054 "() -> (ControlID outID)"},
2055#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002056 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002057 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002058
2059#if TARGET_API_MAC_CARBON
2060 {"GetControlPropertyAttributes", (PyCFunction)CtlObj_GetControlPropertyAttributes, 1,
2061 "(OSType propertyCreator, OSType propertyTag) -> (UInt32 attributes)"},
2062#endif
2063
2064#if TARGET_API_MAC_CARBON
2065 {"ChangeControlPropertyAttributes", (PyCFunction)CtlObj_ChangeControlPropertyAttributes, 1,
2066 "(OSType propertyCreator, OSType propertyTag, UInt32 attributesToSet, UInt32 attributesToClear) -> None"},
2067#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002068 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002069 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002070 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002071 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002072 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
2073 "(SInt32 data) -> None"},
2074 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
2075 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002076
Jack Jansen74a1e632000-07-14 22:37:27 +00002077#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002078 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
2079 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002080#endif
2081
Jack Jansen74a1e632000-07-14 22:37:27 +00002082#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002083 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
2084 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002085#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002086 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
2087 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
2088 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
2089 "(ControlHandle inContainer) -> None"},
2090 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
2091 "(WindowPtr inWindow) -> None"},
2092 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
2093 "() -> (ControlHandle outParent)"},
2094 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002095 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002096 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002097 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002098 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
2099 "(ControlHandle inBoss) -> None"},
2100 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
2101 "() -> (UInt32 outFeatures)"},
2102 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
2103 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002104
2105#if TARGET_API_MAC_CARBON
Jack Jansen723ad8a2000-12-12 22:10:21 +00002106 {"HandleControlDragTracking", (PyCFunction)CtlObj_HandleControlDragTracking, 1,
2107 "(DragTrackingMessage inMessage, DragReference inDrag) -> (Boolean outLikesDrag)"},
2108#endif
2109
2110#if TARGET_API_MAC_CARBON
2111 {"HandleControlDragReceive", (PyCFunction)CtlObj_HandleControlDragReceive, 1,
2112 "(DragReference inDrag) -> None"},
2113#endif
2114
2115#if TARGET_API_MAC_CARBON
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002116 {"SetControlDragTrackingEnabled", (PyCFunction)CtlObj_SetControlDragTrackingEnabled, 1,
2117 "(Boolean tracks) -> None"},
2118#endif
2119
2120#if TARGET_API_MAC_CARBON
2121 {"IsControlDragTrackingEnabled", (PyCFunction)CtlObj_IsControlDragTrackingEnabled, 1,
2122 "() -> (Boolean tracks)"},
2123#endif
2124
2125#if ACCESSOR_CALLS_ARE_FUNCTIONS
2126 {"GetControlBounds", (PyCFunction)CtlObj_GetControlBounds, 1,
Jack Jansena9e3db32001-01-09 22:10:16 +00002127 "() -> (Rect bounds)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002128#endif
2129
2130#if ACCESSOR_CALLS_ARE_FUNCTIONS
2131 {"IsControlHilited", (PyCFunction)CtlObj_IsControlHilited, 1,
2132 "() -> (Boolean _rv)"},
2133#endif
2134
2135#if ACCESSOR_CALLS_ARE_FUNCTIONS
2136 {"GetControlHilite", (PyCFunction)CtlObj_GetControlHilite, 1,
2137 "() -> (UInt16 _rv)"},
2138#endif
2139
2140#if ACCESSOR_CALLS_ARE_FUNCTIONS
2141 {"GetControlOwner", (PyCFunction)CtlObj_GetControlOwner, 1,
2142 "() -> (WindowPtr _rv)"},
2143#endif
2144
2145#if ACCESSOR_CALLS_ARE_FUNCTIONS
2146 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
2147 "() -> (Handle _rv)"},
2148#endif
2149
2150#if ACCESSOR_CALLS_ARE_FUNCTIONS
2151 {"GetControlPopupMenuHandle", (PyCFunction)CtlObj_GetControlPopupMenuHandle, 1,
2152 "() -> (MenuHandle _rv)"},
2153#endif
2154
2155#if ACCESSOR_CALLS_ARE_FUNCTIONS
2156 {"GetControlPopupMenuID", (PyCFunction)CtlObj_GetControlPopupMenuID, 1,
2157 "() -> (short _rv)"},
2158#endif
2159
2160#if ACCESSOR_CALLS_ARE_FUNCTIONS
2161 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
2162 "(Handle dataHandle) -> None"},
2163#endif
2164
2165#if ACCESSOR_CALLS_ARE_FUNCTIONS
2166 {"SetControlBounds", (PyCFunction)CtlObj_SetControlBounds, 1,
2167 "(Rect bounds) -> None"},
2168#endif
2169
2170#if ACCESSOR_CALLS_ARE_FUNCTIONS
2171 {"SetControlPopupMenuHandle", (PyCFunction)CtlObj_SetControlPopupMenuHandle, 1,
2172 "(MenuHandle popupMenu) -> None"},
2173#endif
2174
2175#if ACCESSOR_CALLS_ARE_FUNCTIONS
2176 {"SetControlPopupMenuID", (PyCFunction)CtlObj_SetControlPopupMenuID, 1,
2177 "(short menuID) -> None"},
2178#endif
2179 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
2180 "() -> (SInt16 outValue)"},
2181 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
2182 "(SInt16 inValue) -> None"},
2183 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
2184 "() -> (MenuHandle outHandle)"},
2185 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
2186 "(IconTransformType transform) -> None"},
2187 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
2188 "(SInt16 inValue) -> None"},
2189 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
2190 "() -> (Rect outContentRect)"},
2191 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
2192 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
2193 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
2194 "(IconTransformType inTransform) -> None"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00002195 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00002196 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002197 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
2198 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00002199 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
2200 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00002201 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002202 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
2203 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
2204 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
2205 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
2206 "(stuff) -> None"},
2207 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
2208 "(part, type) -> String"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002209 {"SetControlData_Handle", (PyCFunction)CtlObj_SetControlData_Handle, 1,
Jack Jansen1f9249c1999-12-19 00:05:50 +00002210 "(ResObj) -> None"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002211 {"GetControlData_Handle", (PyCFunction)CtlObj_GetControlData_Handle, 1,
Jack Jansen1f9249c1999-12-19 00:05:50 +00002212 "(part, type) -> ResObj"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002213 {"SetControlData_Callback", (PyCFunction)CtlObj_SetControlData_Callback, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00002214 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002215
Jack Jansen736b51d2001-01-12 23:39:00 +00002216#if !TARGET_API_MAC_CARBON
Jack Jansen4c704131998-06-19 13:35:14 +00002217 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
2218 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002219#endif
2220
Jack Jansen736b51d2001-01-12 23:39:00 +00002221#if !TARGET_API_MAC_CARBON
Jack Jansen4c704131998-06-19 13:35:14 +00002222 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
2223 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002224#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002225 {NULL, NULL, 0}
2226};
2227
2228PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
2229
2230static PyObject *CtlObj_getattr(self, name)
2231 ControlObject *self;
2232 char *name;
2233{
2234 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
2235}
2236
2237#define CtlObj_setattr NULL
2238
Jack Jansen8387af61999-03-13 23:07:32 +00002239static int CtlObj_compare(self, other)
2240 ControlObject *self, *other;
2241{
2242 unsigned long v, w;
2243
2244 if (!CtlObj_Check((PyObject *)other))
2245 {
2246 v=(unsigned long)self;
2247 w=(unsigned long)other;
2248 }
2249 else
2250 {
2251 v=(unsigned long)self->ob_itself;
2252 w=(unsigned long)other->ob_itself;
2253 }
2254 if( v < w ) return -1;
2255 if( v > w ) return 1;
2256 return 0;
2257}
2258
2259#define CtlObj_repr NULL
2260
2261static long CtlObj_hash(self)
2262 ControlObject *self;
2263{
2264 return (long)self->ob_itself;
2265}
2266
Guido van Rossum17448e21995-01-30 11:53:55 +00002267PyTypeObject Control_Type = {
2268 PyObject_HEAD_INIT(&PyType_Type)
2269 0, /*ob_size*/
2270 "Control", /*tp_name*/
2271 sizeof(ControlObject), /*tp_basicsize*/
2272 0, /*tp_itemsize*/
2273 /* methods */
2274 (destructor) CtlObj_dealloc, /*tp_dealloc*/
2275 0, /*tp_print*/
2276 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
2277 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00002278 (cmpfunc) CtlObj_compare, /*tp_compare*/
2279 (reprfunc) CtlObj_repr, /*tp_repr*/
2280 (PyNumberMethods *)0, /* tp_as_number */
2281 (PySequenceMethods *)0, /* tp_as_sequence */
2282 (PyMappingMethods *)0, /* tp_as_mapping */
2283 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00002284};
2285
2286/* -------------------- End object type Control --------------------- */
2287
2288
2289static PyObject *Ctl_NewControl(_self, _args)
2290 PyObject *_self;
2291 PyObject *_args;
2292{
2293 PyObject *_res = NULL;
2294 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002295 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002296 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00002297 Str255 controlTitle;
2298 Boolean initiallyVisible;
2299 SInt16 initialValue;
2300 SInt16 minimumValue;
2301 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002302 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00002303 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00002304 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00002305 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002306 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002307 PyMac_GetStr255, controlTitle,
2308 &initiallyVisible,
2309 &initialValue,
2310 &minimumValue,
2311 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002312 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002313 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00002314 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002315 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002316 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002317 controlTitle,
2318 initiallyVisible,
2319 initialValue,
2320 minimumValue,
2321 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002322 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002323 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00002324 _res = Py_BuildValue("O&",
2325 CtlObj_New, _rv);
2326 return _res;
2327}
2328
2329static PyObject *Ctl_GetNewControl(_self, _args)
2330 PyObject *_self;
2331 PyObject *_args;
2332{
2333 PyObject *_res = NULL;
2334 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002335 SInt16 resourceID;
2336 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002337 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00002338 &resourceID,
2339 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00002340 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002341 _rv = GetNewControl(resourceID,
2342 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00002343 _res = Py_BuildValue("O&",
2344 CtlObj_New, _rv);
2345 return _res;
2346}
2347
Guido van Rossum17448e21995-01-30 11:53:55 +00002348static PyObject *Ctl_DrawControls(_self, _args)
2349 PyObject *_self;
2350 PyObject *_args;
2351{
2352 PyObject *_res = NULL;
2353 WindowPtr theWindow;
2354 if (!PyArg_ParseTuple(_args, "O&",
2355 WinObj_Convert, &theWindow))
2356 return NULL;
2357 DrawControls(theWindow);
2358 Py_INCREF(Py_None);
2359 _res = Py_None;
2360 return _res;
2361}
2362
Guido van Rossum17448e21995-01-30 11:53:55 +00002363static PyObject *Ctl_UpdateControls(_self, _args)
2364 PyObject *_self;
2365 PyObject *_args;
2366{
2367 PyObject *_res = NULL;
2368 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00002369 RgnHandle updateRegion;
2370 if (!PyArg_ParseTuple(_args, "O&O&",
2371 WinObj_Convert, &theWindow,
2372 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00002373 return NULL;
2374 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00002375 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00002376 Py_INCREF(Py_None);
2377 _res = Py_None;
2378 return _res;
2379}
2380
2381static PyObject *Ctl_FindControl(_self, _args)
2382 PyObject *_self;
2383 PyObject *_args;
2384{
2385 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002386 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002387 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00002388 WindowPtr theWindow;
2389 ControlHandle theControl;
2390 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00002391 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002392 WinObj_Convert, &theWindow))
2393 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002394 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002395 theWindow,
2396 &theControl);
2397 _res = Py_BuildValue("hO&",
2398 _rv,
2399 CtlObj_WhichControl, theControl);
2400 return _res;
2401}
2402
Jack Jansen21f96871998-02-20 16:02:09 +00002403static PyObject *Ctl_FindControlUnderMouse(_self, _args)
2404 PyObject *_self;
2405 PyObject *_args;
2406{
2407 PyObject *_res = NULL;
2408 ControlHandle _rv;
2409 Point inWhere;
2410 WindowPtr inWindow;
2411 SInt16 outPart;
2412 if (!PyArg_ParseTuple(_args, "O&O&",
2413 PyMac_GetPoint, &inWhere,
2414 WinObj_Convert, &inWindow))
2415 return NULL;
2416 _rv = FindControlUnderMouse(inWhere,
2417 inWindow,
2418 &outPart);
2419 _res = Py_BuildValue("O&h",
2420 CtlObj_New, _rv,
2421 outPart);
2422 return _res;
2423}
2424
2425static PyObject *Ctl_IdleControls(_self, _args)
2426 PyObject *_self;
2427 PyObject *_args;
2428{
2429 PyObject *_res = NULL;
2430 WindowPtr inWindow;
2431 if (!PyArg_ParseTuple(_args, "O&",
2432 WinObj_Convert, &inWindow))
2433 return NULL;
2434 IdleControls(inWindow);
2435 Py_INCREF(Py_None);
2436 _res = Py_None;
2437 return _res;
2438}
2439
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002440#if TARGET_API_MAC_CARBON
2441
2442static PyObject *Ctl_GetControlByID(_self, _args)
2443 PyObject *_self;
2444 PyObject *_args;
2445{
2446 PyObject *_res = NULL;
2447 OSStatus _err;
2448 WindowPtr inWindow;
2449 ControlID inID;
2450 ControlHandle outControl;
2451 if (!PyArg_ParseTuple(_args, "O&O&",
2452 WinObj_Convert, &inWindow,
2453 PyControlID_Convert, &inID))
2454 return NULL;
2455 _err = GetControlByID(inWindow,
2456 &inID,
2457 &outControl);
2458 if (_err != noErr) return PyMac_Error(_err);
2459 _res = Py_BuildValue("O&",
2460 CtlObj_WhichControl, outControl);
2461 return _res;
2462}
2463#endif
2464
Jack Jansen21f96871998-02-20 16:02:09 +00002465static PyObject *Ctl_DumpControlHierarchy(_self, _args)
2466 PyObject *_self;
2467 PyObject *_args;
2468{
2469 PyObject *_res = NULL;
2470 OSErr _err;
2471 WindowPtr inWindow;
2472 FSSpec inDumpFile;
2473 if (!PyArg_ParseTuple(_args, "O&O&",
2474 WinObj_Convert, &inWindow,
2475 PyMac_GetFSSpec, &inDumpFile))
2476 return NULL;
2477 _err = DumpControlHierarchy(inWindow,
2478 &inDumpFile);
2479 if (_err != noErr) return PyMac_Error(_err);
2480 Py_INCREF(Py_None);
2481 _res = Py_None;
2482 return _res;
2483}
2484
2485static PyObject *Ctl_CreateRootControl(_self, _args)
2486 PyObject *_self;
2487 PyObject *_args;
2488{
2489 PyObject *_res = NULL;
2490 OSErr _err;
2491 WindowPtr inWindow;
2492 ControlHandle outControl;
2493 if (!PyArg_ParseTuple(_args, "O&",
2494 WinObj_Convert, &inWindow))
2495 return NULL;
2496 _err = CreateRootControl(inWindow,
2497 &outControl);
2498 if (_err != noErr) return PyMac_Error(_err);
2499 _res = Py_BuildValue("O&",
2500 CtlObj_WhichControl, outControl);
2501 return _res;
2502}
2503
2504static PyObject *Ctl_GetRootControl(_self, _args)
2505 PyObject *_self;
2506 PyObject *_args;
2507{
2508 PyObject *_res = NULL;
2509 OSErr _err;
2510 WindowPtr inWindow;
2511 ControlHandle outControl;
2512 if (!PyArg_ParseTuple(_args, "O&",
2513 WinObj_Convert, &inWindow))
2514 return NULL;
2515 _err = GetRootControl(inWindow,
2516 &outControl);
2517 if (_err != noErr) return PyMac_Error(_err);
2518 _res = Py_BuildValue("O&",
2519 CtlObj_WhichControl, outControl);
2520 return _res;
2521}
2522
2523static PyObject *Ctl_GetKeyboardFocus(_self, _args)
2524 PyObject *_self;
2525 PyObject *_args;
2526{
2527 PyObject *_res = NULL;
2528 OSErr _err;
2529 WindowPtr inWindow;
2530 ControlHandle outControl;
2531 if (!PyArg_ParseTuple(_args, "O&",
2532 WinObj_Convert, &inWindow))
2533 return NULL;
2534 _err = GetKeyboardFocus(inWindow,
2535 &outControl);
2536 if (_err != noErr) return PyMac_Error(_err);
2537 _res = Py_BuildValue("O&",
2538 CtlObj_WhichControl, outControl);
2539 return _res;
2540}
2541
2542static PyObject *Ctl_SetKeyboardFocus(_self, _args)
2543 PyObject *_self;
2544 PyObject *_args;
2545{
2546 PyObject *_res = NULL;
2547 OSErr _err;
2548 WindowPtr inWindow;
2549 ControlHandle inControl;
2550 ControlFocusPart inPart;
2551 if (!PyArg_ParseTuple(_args, "O&O&h",
2552 WinObj_Convert, &inWindow,
2553 CtlObj_Convert, &inControl,
2554 &inPart))
2555 return NULL;
2556 _err = SetKeyboardFocus(inWindow,
2557 inControl,
2558 inPart);
2559 if (_err != noErr) return PyMac_Error(_err);
2560 Py_INCREF(Py_None);
2561 _res = Py_None;
2562 return _res;
2563}
2564
2565static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
2566 PyObject *_self;
2567 PyObject *_args;
2568{
2569 PyObject *_res = NULL;
2570 OSErr _err;
2571 WindowPtr inWindow;
2572 if (!PyArg_ParseTuple(_args, "O&",
2573 WinObj_Convert, &inWindow))
2574 return NULL;
2575 _err = AdvanceKeyboardFocus(inWindow);
2576 if (_err != noErr) return PyMac_Error(_err);
2577 Py_INCREF(Py_None);
2578 _res = Py_None;
2579 return _res;
2580}
2581
2582static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
2583 PyObject *_self;
2584 PyObject *_args;
2585{
2586 PyObject *_res = NULL;
2587 OSErr _err;
2588 WindowPtr inWindow;
2589 if (!PyArg_ParseTuple(_args, "O&",
2590 WinObj_Convert, &inWindow))
2591 return NULL;
2592 _err = ReverseKeyboardFocus(inWindow);
2593 if (_err != noErr) return PyMac_Error(_err);
2594 Py_INCREF(Py_None);
2595 _res = Py_None;
2596 return _res;
2597}
2598
2599static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
2600 PyObject *_self;
2601 PyObject *_args;
2602{
2603 PyObject *_res = NULL;
2604 OSErr _err;
2605 WindowPtr inWindow;
2606 if (!PyArg_ParseTuple(_args, "O&",
2607 WinObj_Convert, &inWindow))
2608 return NULL;
2609 _err = ClearKeyboardFocus(inWindow);
2610 if (_err != noErr) return PyMac_Error(_err);
2611 Py_INCREF(Py_None);
2612 _res = Py_None;
2613 return _res;
2614}
2615
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002616#if TARGET_API_MAC_CARBON
2617
2618static PyObject *Ctl_SetAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2619 PyObject *_self;
2620 PyObject *_args;
2621{
2622 PyObject *_res = NULL;
2623 OSStatus _err;
2624 WindowPtr theWindow;
2625 Boolean tracks;
2626 if (!PyArg_ParseTuple(_args, "O&b",
2627 WinObj_Convert, &theWindow,
2628 &tracks))
2629 return NULL;
2630 _err = SetAutomaticControlDragTrackingEnabledForWindow(theWindow,
2631 tracks);
2632 if (_err != noErr) return PyMac_Error(_err);
2633 Py_INCREF(Py_None);
2634 _res = Py_None;
2635 return _res;
2636}
2637#endif
2638
2639#if TARGET_API_MAC_CARBON
2640
2641static PyObject *Ctl_IsAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2642 PyObject *_self;
2643 PyObject *_args;
2644{
2645 PyObject *_res = NULL;
2646 OSStatus _err;
2647 WindowPtr theWindow;
2648 Boolean tracks;
2649 if (!PyArg_ParseTuple(_args, "O&",
2650 WinObj_Convert, &theWindow))
2651 return NULL;
2652 _err = IsAutomaticControlDragTrackingEnabledForWindow(theWindow,
2653 &tracks);
2654 if (_err != noErr) return PyMac_Error(_err);
2655 _res = Py_BuildValue("b",
2656 tracks);
2657 return _res;
2658}
2659#endif
2660
Jack Jansene0581891999-02-07 14:02:03 +00002661static PyObject *Ctl_as_Control(_self, _args)
2662 PyObject *_self;
2663 PyObject *_args;
2664{
2665 PyObject *_res = NULL;
2666 ControlHandle _rv;
2667 Handle h;
2668 if (!PyArg_ParseTuple(_args, "O&",
2669 ResObj_Convert, &h))
2670 return NULL;
2671 _rv = as_Control(h);
2672 _res = Py_BuildValue("O&",
2673 CtlObj_New, _rv);
2674 return _res;
2675}
2676
Guido van Rossum17448e21995-01-30 11:53:55 +00002677static PyMethodDef Ctl_methods[] = {
2678 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002679 "(WindowPtr owningWindow, Rect boundsRect, Str255 controlTitle, Boolean initiallyVisible, SInt16 initialValue, SInt16 minimumValue, SInt16 maximumValue, SInt16 procID, SInt32 controlReference) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002680 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002681 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002682 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2683 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002684 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002685 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002686 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002687 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2688 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2689 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2690 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2691 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002692
2693#if TARGET_API_MAC_CARBON
2694 {"GetControlByID", (PyCFunction)Ctl_GetControlByID, 1,
2695 "(WindowPtr inWindow, ControlID inID) -> (ControlHandle outControl)"},
2696#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002697 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2698 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2699 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2700 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2701 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2702 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2703 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2704 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2705 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2706 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2707 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2708 "(WindowPtr inWindow) -> None"},
2709 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2710 "(WindowPtr inWindow) -> None"},
2711 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2712 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002713
2714#if TARGET_API_MAC_CARBON
2715 {"SetAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_SetAutomaticControlDragTrackingEnabledForWindow, 1,
2716 "(WindowPtr theWindow, Boolean tracks) -> None"},
2717#endif
2718
2719#if TARGET_API_MAC_CARBON
2720 {"IsAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_IsAutomaticControlDragTrackingEnabledForWindow, 1,
2721 "(WindowPtr theWindow) -> (Boolean tracks)"},
2722#endif
Jack Jansene0581891999-02-07 14:02:03 +00002723 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2724 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002725 {NULL, NULL, 0}
2726};
2727
2728
2729
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002730static PyObject *
2731CtlObj_NewUnmanaged(itself)
Jack Jansen8387af61999-03-13 23:07:32 +00002732 ControlHandle itself;
2733{
2734 ControlObject *it;
2735 if (itself == NULL) return PyMac_Error(resNotFound);
2736 it = PyObject_NEW(ControlObject, &Control_Type);
2737 if (it == NULL) return NULL;
2738 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002739 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002740 return (PyObject *)it;
2741}
2742
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002743static PyObject *
Guido van Rossum17448e21995-01-30 11:53:55 +00002744CtlObj_WhichControl(ControlHandle c)
2745{
2746 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002747
Guido van Rossum17448e21995-01-30 11:53:55 +00002748 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002749 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002750 else {
2751 it = (PyObject *) GetControlReference(c);
2752 /*
2753 ** If the refcon is zero or doesn't point back to the Python object
2754 ** the control is not ours. Return a temporary object.
2755 */
2756 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2757 return CtlObj_NewUnmanaged(c);
2758 }
Guido van Rossum17448e21995-01-30 11:53:55 +00002759 Py_INCREF(it);
2760 return it;
2761}
2762
Jack Jansen848250c1998-05-28 14:20:09 +00002763static int
2764settrackfunc(obj)
2765 PyObject *obj;
2766{
2767 if (tracker) {
2768 PyErr_SetString(Ctl_Error, "Tracker function in use");
2769 return 0;
2770 }
2771 tracker = obj;
2772 Py_INCREF(tracker);
2773}
2774
2775static void
2776clrtrackfunc()
2777{
2778 Py_XDECREF(tracker);
2779 tracker = 0;
2780}
2781
2782static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002783mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002784{
2785 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002786
Jack Jansen848250c1998-05-28 14:20:09 +00002787 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2788 if (args && tracker) {
2789 rv = PyEval_CallObject(tracker, args);
2790 Py_DECREF(args);
2791 }
2792 if (rv)
2793 Py_DECREF(rv);
2794 else
Jack Jansen24c35311999-12-09 22:49:51 +00002795 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002796}
2797
Jack Jansenabc411b2000-03-20 16:09:09 +00002798static int
Jack Jansen85152b92000-07-11 21:12:55 +00002799setcallback(myself, which, callback, uppp)
2800 PyObject *myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002801 OSType which;
2802 PyObject *callback;
2803 UniversalProcPtr *uppp;
2804{
Jack Jansen85152b92000-07-11 21:12:55 +00002805 ControlObject *self = (ControlObject *)myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002806 char keybuf[9];
2807
2808 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002809 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002810 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002811 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002812 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002813 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002814 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002815 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002816 else
2817 return -1;
2818 /* Only now do we test for clearing of the callback: */
2819 if ( callback == Py_None )
2820 *uppp = NULL;
2821 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2822 if ( self->ob_callbackdict == NULL )
2823 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2824 return -1;
2825 /* And store the Python callback */
2826 sprintf(keybuf, "%x", which);
2827 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2828 return -1;
2829 return 0;
2830}
2831
2832static PyObject *
2833callcallback(self, which, arglist)
2834 ControlObject *self;
2835 OSType which;
2836 PyObject *arglist;
2837{
2838 char keybuf[9];
2839 PyObject *func, *rv;
2840
2841 sprintf(keybuf, "%x", which);
2842 if ( self->ob_callbackdict == NULL ||
2843 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002844 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002845 return NULL;
2846 }
2847 rv = PyEval_CallObject(func, arglist);
2848 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002849 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002850 return rv;
2851}
2852
2853static pascal void
2854mydrawproc(ControlHandle control, SInt16 part)
2855{
2856 ControlObject *ctl_obj;
2857 PyObject *arglist, *rv;
2858
2859 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2860 arglist = Py_BuildValue("Oh", ctl_obj, part);
2861 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2862 Py_XDECREF(arglist);
2863 Py_XDECREF(rv);
2864}
2865
2866static pascal void
2867myidleproc(ControlHandle control)
2868{
2869 ControlObject *ctl_obj;
2870 PyObject *arglist, *rv;
2871
2872 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2873 arglist = Py_BuildValue("O", ctl_obj);
2874 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2875 Py_XDECREF(arglist);
2876 Py_XDECREF(rv);
2877}
2878
Jack Jansena27e9fb2000-03-21 23:03:02 +00002879static pascal ControlPartCode
2880myhittestproc(ControlHandle control, Point where)
2881{
2882 ControlObject *ctl_obj;
2883 PyObject *arglist, *rv;
2884 short c_rv = -1;
2885
2886 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002887 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002888 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2889 Py_XDECREF(arglist);
2890 /* Ignore errors, nothing we can do about them */
2891 if ( rv )
2892 PyArg_Parse(rv, "h", &c_rv);
2893 Py_XDECREF(rv);
2894 return (ControlPartCode)c_rv;
2895}
2896
2897static pascal ControlPartCode
2898mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2899{
2900 ControlObject *ctl_obj;
2901 PyObject *arglist, *rv;
2902 short c_rv = -1;
2903
2904 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2905 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002906 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002907 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2908 Py_XDECREF(arglist);
2909 if ( rv )
2910 PyArg_Parse(rv, "h", &c_rv);
2911 Py_XDECREF(rv);
2912 return (ControlPartCode)c_rv;
2913}
Jack Jansenabc411b2000-03-20 16:09:09 +00002914
Guido van Rossum17448e21995-01-30 11:53:55 +00002915
2916void initCtl()
2917{
2918 PyObject *m;
2919 PyObject *d;
2920
2921
2922
Jack Jansen848250c1998-05-28 14:20:09 +00002923 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansenabc411b2000-03-20 16:09:09 +00002924 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
Jack Jansen1b6e8212000-04-05 21:30:57 +00002925 myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002926 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2927 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansen848250c1998-05-28 14:20:09 +00002928
Guido van Rossum17448e21995-01-30 11:53:55 +00002929
2930 m = Py_InitModule("Ctl", Ctl_methods);
2931 d = PyModule_GetDict(m);
2932 Ctl_Error = PyMac_GetOSErrException();
2933 if (Ctl_Error == NULL ||
2934 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002935 return;
Jack Jansena755e681997-09-20 17:40:22 +00002936 Control_Type.ob_type = &PyType_Type;
2937 Py_INCREF(&Control_Type);
2938 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2939 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002940}
2941
2942/* ========================= End module Ctl ========================= */
2943