blob: 9b39f1a1efffd6b440deba7bdb0a4c620cbb2c35 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Ctl =========================== */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
17extern int ResObj_Convert(PyObject *, Handle *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000018extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
Guido van Rossum17448e21995-01-30 11:53:55 +000020
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000023extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
Guido van Rossum17448e21995-01-30 11:53:55 +000025
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
Jack Jansen425e9eb1995-12-12 15:02:03 +000037extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
Guido van Rossum17448e21995-01-30 11:53:55 +000043extern PyObject *WinObj_WhichWindow(WindowPtr);
44
45#include <Controls.h>
46
Jack Jansene0581891999-02-07 14:02:03 +000047#define as_Control(h) ((ControlHandle)h)
Jack Jansena1a0fef1999-12-23 14:32:06 +000048#define as_Resource(ctl) ((Handle)ctl)
Jack Jansene0581891999-02-07 14:02:03 +000049
Guido van Rossum17448e21995-01-30 11:53:55 +000050#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
51
52extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000053extern PyObject *QdRGB_New(RGBColorPtr);
54extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000055
56#ifdef THINK_C
57#define ControlActionUPP ProcPtr
58#endif
59
Jack Jansen21f96871998-02-20 16:02:09 +000060/*
61** Parse/generate ControlFontStyleRec records
62*/
63#if 0 /* Not needed */
64PyObject *ControlFontStyle_New(itself)
65 ControlFontStyleRec *itself;
66{
67
68 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
69 itself->size, itself->style, itself->mode, itself->just,
70 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
71}
72#endif
73
74ControlFontStyle_Convert(v, itself)
75 PyObject *v;
76 ControlFontStyleRec *itself;
77{
78 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000079 &itself->font, &itself->size, &itself->style, &itself->mode,
80 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000081 QdRGB_Convert, &itself->backColor);
82}
83
Jack Jansen24c35311999-12-09 22:49:51 +000084/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000085static PyObject *tracker;
86static ControlActionUPP mytracker_upp;
87
88extern int settrackfunc(PyObject *); /* forward */
89extern void clrtrackfunc(void); /* forward */
90
Guido van Rossum17448e21995-01-30 11:53:55 +000091static PyObject *Ctl_Error;
92
93/* ---------------------- Object type Control ----------------------- */
94
95PyTypeObject Control_Type;
96
97#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
98
99typedef struct ControlObject {
100 PyObject_HEAD
101 ControlHandle ob_itself;
102} ControlObject;
103
104PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000105 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000106{
107 ControlObject *it;
108 if (itself == NULL) return PyMac_Error(resNotFound);
109 it = PyObject_NEW(ControlObject, &Control_Type);
110 if (it == NULL) return NULL;
111 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000112 SetControlReference(itself, (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000113 return (PyObject *)it;
114}
115CtlObj_Convert(v, p_itself)
116 PyObject *v;
117 ControlHandle *p_itself;
118{
119 if (!CtlObj_Check(v))
120 {
121 PyErr_SetString(PyExc_TypeError, "Control required");
122 return 0;
123 }
124 *p_itself = ((ControlObject *)v)->ob_itself;
125 return 1;
126}
127
128static void CtlObj_dealloc(self)
129 ControlObject *self;
130{
Jack Jansen24c35311999-12-09 22:49:51 +0000131 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000132 PyMem_DEL(self);
133}
134
Jack Jansen21f96871998-02-20 16:02:09 +0000135static PyObject *CtlObj_HiliteControl(_self, _args)
136 ControlObject *_self;
137 PyObject *_args;
138{
139 PyObject *_res = NULL;
140 ControlPartCode hiliteState;
141 if (!PyArg_ParseTuple(_args, "h",
142 &hiliteState))
143 return NULL;
144 HiliteControl(_self->ob_itself,
145 hiliteState);
146 Py_INCREF(Py_None);
147 _res = Py_None;
148 return _res;
149}
150
Jack Jansen7d0bc831995-06-09 20:56:31 +0000151static PyObject *CtlObj_ShowControl(_self, _args)
152 ControlObject *_self;
153 PyObject *_args;
154{
155 PyObject *_res = NULL;
156 if (!PyArg_ParseTuple(_args, ""))
157 return NULL;
158 ShowControl(_self->ob_itself);
159 Py_INCREF(Py_None);
160 _res = Py_None;
161 return _res;
162}
163
164static PyObject *CtlObj_HideControl(_self, _args)
165 ControlObject *_self;
166 PyObject *_args;
167{
168 PyObject *_res = NULL;
169 if (!PyArg_ParseTuple(_args, ""))
170 return NULL;
171 HideControl(_self->ob_itself);
172 Py_INCREF(Py_None);
173 _res = Py_None;
174 return _res;
175}
176
Jack Jansen21f96871998-02-20 16:02:09 +0000177static PyObject *CtlObj_IsControlActive(_self, _args)
178 ControlObject *_self;
179 PyObject *_args;
180{
181 PyObject *_res = NULL;
182 Boolean _rv;
183 if (!PyArg_ParseTuple(_args, ""))
184 return NULL;
185 _rv = IsControlActive(_self->ob_itself);
186 _res = Py_BuildValue("b",
187 _rv);
188 return _res;
189}
190
191static PyObject *CtlObj_IsControlVisible(_self, _args)
192 ControlObject *_self;
193 PyObject *_args;
194{
195 PyObject *_res = NULL;
196 Boolean _rv;
197 if (!PyArg_ParseTuple(_args, ""))
198 return NULL;
199 _rv = IsControlVisible(_self->ob_itself);
200 _res = Py_BuildValue("b",
201 _rv);
202 return _res;
203}
204
205static PyObject *CtlObj_ActivateControl(_self, _args)
206 ControlObject *_self;
207 PyObject *_args;
208{
209 PyObject *_res = NULL;
210 OSErr _err;
211 if (!PyArg_ParseTuple(_args, ""))
212 return NULL;
213 _err = ActivateControl(_self->ob_itself);
214 if (_err != noErr) return PyMac_Error(_err);
215 Py_INCREF(Py_None);
216 _res = Py_None;
217 return _res;
218}
219
220static PyObject *CtlObj_DeactivateControl(_self, _args)
221 ControlObject *_self;
222 PyObject *_args;
223{
224 PyObject *_res = NULL;
225 OSErr _err;
226 if (!PyArg_ParseTuple(_args, ""))
227 return NULL;
228 _err = DeactivateControl(_self->ob_itself);
229 if (_err != noErr) return PyMac_Error(_err);
230 Py_INCREF(Py_None);
231 _res = Py_None;
232 return _res;
233}
234
235static PyObject *CtlObj_SetControlVisibility(_self, _args)
236 ControlObject *_self;
237 PyObject *_args;
238{
239 PyObject *_res = NULL;
240 OSErr _err;
241 Boolean inIsVisible;
242 Boolean inDoDraw;
243 if (!PyArg_ParseTuple(_args, "bb",
244 &inIsVisible,
245 &inDoDraw))
246 return NULL;
247 _err = SetControlVisibility(_self->ob_itself,
248 inIsVisible,
249 inDoDraw);
250 if (_err != noErr) return PyMac_Error(_err);
251 Py_INCREF(Py_None);
252 _res = Py_None;
253 return _res;
254}
255
Jack Jansen7d0bc831995-06-09 20:56:31 +0000256static PyObject *CtlObj_Draw1Control(_self, _args)
257 ControlObject *_self;
258 PyObject *_args;
259{
260 PyObject *_res = NULL;
261 if (!PyArg_ParseTuple(_args, ""))
262 return NULL;
263 Draw1Control(_self->ob_itself);
264 Py_INCREF(Py_None);
265 _res = Py_None;
266 return _res;
267}
268
Jack Jansen21f96871998-02-20 16:02:09 +0000269static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000270 ControlObject *_self;
271 PyObject *_args;
272{
273 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000274 OSErr _err;
275 Rect outRect;
276 SInt16 outBaseLineOffset;
277 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000278 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000279 _err = GetBestControlRect(_self->ob_itself,
280 &outRect,
281 &outBaseLineOffset);
282 if (_err != noErr) return PyMac_Error(_err);
283 _res = Py_BuildValue("O&h",
284 PyMac_BuildRect, &outRect,
285 outBaseLineOffset);
286 return _res;
287}
288
289static PyObject *CtlObj_SetControlFontStyle(_self, _args)
290 ControlObject *_self;
291 PyObject *_args;
292{
293 PyObject *_res = NULL;
294 OSErr _err;
295 ControlFontStyleRec inStyle;
296 if (!PyArg_ParseTuple(_args, "O&",
297 ControlFontStyle_Convert, &inStyle))
298 return NULL;
299 _err = SetControlFontStyle(_self->ob_itself,
300 &inStyle);
301 if (_err != noErr) return PyMac_Error(_err);
302 Py_INCREF(Py_None);
303 _res = Py_None;
304 return _res;
305}
306
307static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
308 ControlObject *_self;
309 PyObject *_args;
310{
311 PyObject *_res = NULL;
312 if (!PyArg_ParseTuple(_args, ""))
313 return NULL;
314 DrawControlInCurrentPort(_self->ob_itself);
315 Py_INCREF(Py_None);
316 _res = Py_None;
317 return _res;
318}
319
320static PyObject *CtlObj_SetUpControlBackground(_self, _args)
321 ControlObject *_self;
322 PyObject *_args;
323{
324 PyObject *_res = NULL;
325 OSErr _err;
326 SInt16 inDepth;
327 Boolean inIsColorDevice;
328 if (!PyArg_ParseTuple(_args, "hb",
329 &inDepth,
330 &inIsColorDevice))
331 return NULL;
332 _err = SetUpControlBackground(_self->ob_itself,
333 inDepth,
334 inIsColorDevice);
335 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000336 Py_INCREF(Py_None);
337 _res = Py_None;
338 return _res;
339}
340
Jack Jansena05ac601999-12-12 21:41:51 +0000341static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
342 ControlObject *_self;
343 PyObject *_args;
344{
345 PyObject *_res = NULL;
346 OSErr _err;
347 SInt16 inDepth;
348 Boolean inIsColorDevice;
349 if (!PyArg_ParseTuple(_args, "hb",
350 &inDepth,
351 &inIsColorDevice))
352 return NULL;
353 _err = SetUpControlTextColor(_self->ob_itself,
354 inDepth,
355 inIsColorDevice);
356 if (_err != noErr) return PyMac_Error(_err);
357 Py_INCREF(Py_None);
358 _res = Py_None;
359 return _res;
360}
361
Jack Jansen7d0bc831995-06-09 20:56:31 +0000362static PyObject *CtlObj_DragControl(_self, _args)
363 ControlObject *_self;
364 PyObject *_args;
365{
366 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000367 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000368 Rect limitRect;
369 Rect slopRect;
370 DragConstraint axis;
371 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000372 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000373 PyMac_GetRect, &limitRect,
374 PyMac_GetRect, &slopRect,
375 &axis))
376 return NULL;
377 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000378 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000379 &limitRect,
380 &slopRect,
381 axis);
382 Py_INCREF(Py_None);
383 _res = Py_None;
384 return _res;
385}
386
387static PyObject *CtlObj_TestControl(_self, _args)
388 ControlObject *_self;
389 PyObject *_args;
390{
391 PyObject *_res = NULL;
392 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000393 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000394 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000395 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000396 return NULL;
397 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000398 testPoint);
399 _res = Py_BuildValue("h",
400 _rv);
401 return _res;
402}
403
404static PyObject *CtlObj_HandleControlKey(_self, _args)
405 ControlObject *_self;
406 PyObject *_args;
407{
408 PyObject *_res = NULL;
409 SInt16 _rv;
410 SInt16 inKeyCode;
411 SInt16 inCharCode;
412 SInt16 inModifiers;
413 if (!PyArg_ParseTuple(_args, "hhh",
414 &inKeyCode,
415 &inCharCode,
416 &inModifiers))
417 return NULL;
418 _rv = HandleControlKey(_self->ob_itself,
419 inKeyCode,
420 inCharCode,
421 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000422 _res = Py_BuildValue("h",
423 _rv);
424 return _res;
425}
426
427static PyObject *CtlObj_MoveControl(_self, _args)
428 ControlObject *_self;
429 PyObject *_args;
430{
431 PyObject *_res = NULL;
432 SInt16 h;
433 SInt16 v;
434 if (!PyArg_ParseTuple(_args, "hh",
435 &h,
436 &v))
437 return NULL;
438 MoveControl(_self->ob_itself,
439 h,
440 v);
441 Py_INCREF(Py_None);
442 _res = Py_None;
443 return _res;
444}
445
446static PyObject *CtlObj_SizeControl(_self, _args)
447 ControlObject *_self;
448 PyObject *_args;
449{
450 PyObject *_res = NULL;
451 SInt16 w;
452 SInt16 h;
453 if (!PyArg_ParseTuple(_args, "hh",
454 &w,
455 &h))
456 return NULL;
457 SizeControl(_self->ob_itself,
458 w,
459 h);
460 Py_INCREF(Py_None);
461 _res = Py_None;
462 return _res;
463}
464
Jack Jansenae8a68f1995-06-06 12:55:40 +0000465static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000466 ControlObject *_self;
467 PyObject *_args;
468{
469 PyObject *_res = NULL;
470 Str255 title;
471 if (!PyArg_ParseTuple(_args, "O&",
472 PyMac_GetStr255, title))
473 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000474 SetControlTitle(_self->ob_itself,
475 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000476 Py_INCREF(Py_None);
477 _res = Py_None;
478 return _res;
479}
480
Jack Jansenae8a68f1995-06-06 12:55:40 +0000481static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000482 ControlObject *_self;
483 PyObject *_args;
484{
485 PyObject *_res = NULL;
486 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000487 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000488 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000489 GetControlTitle(_self->ob_itself,
490 title);
Jack Jansen41009001999-03-07 20:05:20 +0000491 _res = Py_BuildValue("O&",
492 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000493 return _res;
494}
495
Jack Jansenae8a68f1995-06-06 12:55:40 +0000496static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000497 ControlObject *_self;
498 PyObject *_args;
499{
500 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000501 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000502 if (!PyArg_ParseTuple(_args, ""))
503 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000504 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000505 _res = Py_BuildValue("h",
506 _rv);
507 return _res;
508}
509
Jack Jansen7d0bc831995-06-09 20:56:31 +0000510static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000511 ControlObject *_self;
512 PyObject *_args;
513{
514 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000515 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000516 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000517 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000518 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000519 SetControlValue(_self->ob_itself,
520 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000521 Py_INCREF(Py_None);
522 _res = Py_None;
523 return _res;
524}
525
Jack Jansenae8a68f1995-06-06 12:55:40 +0000526static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000527 ControlObject *_self;
528 PyObject *_args;
529{
530 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000531 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000532 if (!PyArg_ParseTuple(_args, ""))
533 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000534 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000535 _res = Py_BuildValue("h",
536 _rv);
537 return _res;
538}
539
Jack Jansen7d0bc831995-06-09 20:56:31 +0000540static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000541 ControlObject *_self;
542 PyObject *_args;
543{
544 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000545 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000546 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000547 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000548 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000549 SetControlMinimum(_self->ob_itself,
550 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000551 Py_INCREF(Py_None);
552 _res = Py_None;
553 return _res;
554}
555
Jack Jansenae8a68f1995-06-06 12:55:40 +0000556static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000557 ControlObject *_self;
558 PyObject *_args;
559{
560 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000561 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000562 if (!PyArg_ParseTuple(_args, ""))
563 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000564 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000565 _res = Py_BuildValue("h",
566 _rv);
567 return _res;
568}
569
Jack Jansen7d0bc831995-06-09 20:56:31 +0000570static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000571 ControlObject *_self;
572 PyObject *_args;
573{
574 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000575 SInt16 newMaximum;
576 if (!PyArg_ParseTuple(_args, "h",
577 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000578 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000579 SetControlMaximum(_self->ob_itself,
580 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000581 Py_INCREF(Py_None);
582 _res = Py_None;
583 return _res;
584}
585
Jack Jansena05ac601999-12-12 21:41:51 +0000586static PyObject *CtlObj_GetControlViewSize(_self, _args)
587 ControlObject *_self;
588 PyObject *_args;
589{
590 PyObject *_res = NULL;
591 SInt32 _rv;
592 if (!PyArg_ParseTuple(_args, ""))
593 return NULL;
594 _rv = GetControlViewSize(_self->ob_itself);
595 _res = Py_BuildValue("l",
596 _rv);
597 return _res;
598}
599
600static PyObject *CtlObj_SetControlViewSize(_self, _args)
601 ControlObject *_self;
602 PyObject *_args;
603{
604 PyObject *_res = NULL;
605 SInt32 newViewSize;
606 if (!PyArg_ParseTuple(_args, "l",
607 &newViewSize))
608 return NULL;
609 SetControlViewSize(_self->ob_itself,
610 newViewSize);
611 Py_INCREF(Py_None);
612 _res = Py_None;
613 return _res;
614}
615
616static PyObject *CtlObj_GetControl32BitValue(_self, _args)
617 ControlObject *_self;
618 PyObject *_args;
619{
620 PyObject *_res = NULL;
621 SInt32 _rv;
622 if (!PyArg_ParseTuple(_args, ""))
623 return NULL;
624 _rv = GetControl32BitValue(_self->ob_itself);
625 _res = Py_BuildValue("l",
626 _rv);
627 return _res;
628}
629
630static PyObject *CtlObj_SetControl32BitValue(_self, _args)
631 ControlObject *_self;
632 PyObject *_args;
633{
634 PyObject *_res = NULL;
635 SInt32 newValue;
636 if (!PyArg_ParseTuple(_args, "l",
637 &newValue))
638 return NULL;
639 SetControl32BitValue(_self->ob_itself,
640 newValue);
641 Py_INCREF(Py_None);
642 _res = Py_None;
643 return _res;
644}
645
646static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
647 ControlObject *_self;
648 PyObject *_args;
649{
650 PyObject *_res = NULL;
651 SInt32 _rv;
652 if (!PyArg_ParseTuple(_args, ""))
653 return NULL;
654 _rv = GetControl32BitMaximum(_self->ob_itself);
655 _res = Py_BuildValue("l",
656 _rv);
657 return _res;
658}
659
660static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
661 ControlObject *_self;
662 PyObject *_args;
663{
664 PyObject *_res = NULL;
665 SInt32 newMaximum;
666 if (!PyArg_ParseTuple(_args, "l",
667 &newMaximum))
668 return NULL;
669 SetControl32BitMaximum(_self->ob_itself,
670 newMaximum);
671 Py_INCREF(Py_None);
672 _res = Py_None;
673 return _res;
674}
675
676static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
677 ControlObject *_self;
678 PyObject *_args;
679{
680 PyObject *_res = NULL;
681 SInt32 _rv;
682 if (!PyArg_ParseTuple(_args, ""))
683 return NULL;
684 _rv = GetControl32BitMinimum(_self->ob_itself);
685 _res = Py_BuildValue("l",
686 _rv);
687 return _res;
688}
689
690static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
691 ControlObject *_self;
692 PyObject *_args;
693{
694 PyObject *_res = NULL;
695 SInt32 newMinimum;
696 if (!PyArg_ParseTuple(_args, "l",
697 &newMinimum))
698 return NULL;
699 SetControl32BitMinimum(_self->ob_itself,
700 newMinimum);
701 Py_INCREF(Py_None);
702 _res = Py_None;
703 return _res;
704}
705
706static PyObject *CtlObj_IsValidControlHandle(_self, _args)
707 ControlObject *_self;
708 PyObject *_args;
709{
710 PyObject *_res = NULL;
711 Boolean _rv;
712 if (!PyArg_ParseTuple(_args, ""))
713 return NULL;
714 _rv = IsValidControlHandle(_self->ob_itself);
715 _res = Py_BuildValue("b",
716 _rv);
717 return _res;
718}
719
720static PyObject *CtlObj_RemoveControlProperty(_self, _args)
721 ControlObject *_self;
722 PyObject *_args;
723{
724 PyObject *_res = NULL;
725 OSStatus _err;
726 OSType propertyCreator;
727 OSType propertyTag;
728 if (!PyArg_ParseTuple(_args, "O&O&",
729 PyMac_GetOSType, &propertyCreator,
730 PyMac_GetOSType, &propertyTag))
731 return NULL;
732 _err = RemoveControlProperty(_self->ob_itself,
733 propertyCreator,
734 propertyTag);
735 if (_err != noErr) return PyMac_Error(_err);
736 Py_INCREF(Py_None);
737 _res = Py_None;
738 return _res;
739}
740
741static PyObject *CtlObj_GetControlRegion(_self, _args)
742 ControlObject *_self;
743 PyObject *_args;
744{
745 PyObject *_res = NULL;
746 OSStatus _err;
747 ControlPartCode inPart;
748 RgnHandle outRegion;
749 if (!PyArg_ParseTuple(_args, "hO&",
750 &inPart,
751 ResObj_Convert, &outRegion))
752 return NULL;
753 _err = GetControlRegion(_self->ob_itself,
754 inPart,
755 outRegion);
756 if (_err != noErr) return PyMac_Error(_err);
757 Py_INCREF(Py_None);
758 _res = Py_None;
759 return _res;
760}
761
Jack Jansen7d0bc831995-06-09 20:56:31 +0000762static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000763 ControlObject *_self;
764 PyObject *_args;
765{
766 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000767 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000768 if (!PyArg_ParseTuple(_args, ""))
769 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000770 _rv = GetControlVariant(_self->ob_itself);
771 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000772 _rv);
773 return _res;
774}
775
Jack Jansen7d0bc831995-06-09 20:56:31 +0000776static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000777 ControlObject *_self;
778 PyObject *_args;
779{
780 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000781 SInt32 data;
782 if (!PyArg_ParseTuple(_args, "l",
783 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000784 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000785 SetControlReference(_self->ob_itself,
786 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000787 Py_INCREF(Py_None);
788 _res = Py_None;
789 return _res;
790}
791
Jack Jansen7d0bc831995-06-09 20:56:31 +0000792static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000793 ControlObject *_self;
794 PyObject *_args;
795{
796 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000797 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000798 if (!PyArg_ParseTuple(_args, ""))
799 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000800 _rv = GetControlReference(_self->ob_itself);
801 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000802 _rv);
803 return _res;
804}
805
Jack Jansenc7fefed1997-08-15 14:32:18 +0000806static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
807 ControlObject *_self;
808 PyObject *_args;
809{
810 PyObject *_res = NULL;
811 Boolean _rv;
812 AuxCtlHandle acHndl;
813 if (!PyArg_ParseTuple(_args, ""))
814 return NULL;
815 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
816 &acHndl);
817 _res = Py_BuildValue("bO&",
818 _rv,
819 ResObj_New, acHndl);
820 return _res;
821}
822
823static PyObject *CtlObj_SetControlColor(_self, _args)
824 ControlObject *_self;
825 PyObject *_args;
826{
827 PyObject *_res = NULL;
828 CCTabHandle newColorTable;
829 if (!PyArg_ParseTuple(_args, "O&",
830 ResObj_Convert, &newColorTable))
831 return NULL;
832 SetControlColor(_self->ob_itself,
833 newColorTable);
834 Py_INCREF(Py_None);
835 _res = Py_None;
836 return _res;
837}
838
Jack Jansen21f96871998-02-20 16:02:09 +0000839static PyObject *CtlObj_SendControlMessage(_self, _args)
840 ControlObject *_self;
841 PyObject *_args;
842{
843 PyObject *_res = NULL;
844 SInt32 _rv;
845 SInt16 inMessage;
846 SInt32 inParam;
847 if (!PyArg_ParseTuple(_args, "hl",
848 &inMessage,
849 &inParam))
850 return NULL;
851 _rv = SendControlMessage(_self->ob_itself,
852 inMessage,
853 inParam);
854 _res = Py_BuildValue("l",
855 _rv);
856 return _res;
857}
858
859static PyObject *CtlObj_EmbedControl(_self, _args)
860 ControlObject *_self;
861 PyObject *_args;
862{
863 PyObject *_res = NULL;
864 OSErr _err;
865 ControlHandle inContainer;
866 if (!PyArg_ParseTuple(_args, "O&",
867 CtlObj_Convert, &inContainer))
868 return NULL;
869 _err = EmbedControl(_self->ob_itself,
870 inContainer);
871 if (_err != noErr) return PyMac_Error(_err);
872 Py_INCREF(Py_None);
873 _res = Py_None;
874 return _res;
875}
876
877static PyObject *CtlObj_AutoEmbedControl(_self, _args)
878 ControlObject *_self;
879 PyObject *_args;
880{
881 PyObject *_res = NULL;
882 OSErr _err;
883 WindowPtr inWindow;
884 if (!PyArg_ParseTuple(_args, "O&",
885 WinObj_Convert, &inWindow))
886 return NULL;
887 _err = AutoEmbedControl(_self->ob_itself,
888 inWindow);
889 if (_err != noErr) return PyMac_Error(_err);
890 Py_INCREF(Py_None);
891 _res = Py_None;
892 return _res;
893}
894
895static PyObject *CtlObj_GetSuperControl(_self, _args)
896 ControlObject *_self;
897 PyObject *_args;
898{
899 PyObject *_res = NULL;
900 OSErr _err;
901 ControlHandle outParent;
902 if (!PyArg_ParseTuple(_args, ""))
903 return NULL;
904 _err = GetSuperControl(_self->ob_itself,
905 &outParent);
906 if (_err != noErr) return PyMac_Error(_err);
907 _res = Py_BuildValue("O&",
908 CtlObj_WhichControl, outParent);
909 return _res;
910}
911
912static PyObject *CtlObj_CountSubControls(_self, _args)
913 ControlObject *_self;
914 PyObject *_args;
915{
916 PyObject *_res = NULL;
917 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000918 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +0000919 if (!PyArg_ParseTuple(_args, ""))
920 return NULL;
921 _err = CountSubControls(_self->ob_itself,
922 &outNumChildren);
923 if (_err != noErr) return PyMac_Error(_err);
924 _res = Py_BuildValue("h",
925 outNumChildren);
926 return _res;
927}
928
929static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
930 ControlObject *_self;
931 PyObject *_args;
932{
933 PyObject *_res = NULL;
934 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000935 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +0000936 ControlHandle outSubControl;
937 if (!PyArg_ParseTuple(_args, "h",
938 &inIndex))
939 return NULL;
940 _err = GetIndexedSubControl(_self->ob_itself,
941 inIndex,
942 &outSubControl);
943 if (_err != noErr) return PyMac_Error(_err);
944 _res = Py_BuildValue("O&",
945 CtlObj_WhichControl, outSubControl);
946 return _res;
947}
948
949static PyObject *CtlObj_SetControlSupervisor(_self, _args)
950 ControlObject *_self;
951 PyObject *_args;
952{
953 PyObject *_res = NULL;
954 OSErr _err;
955 ControlHandle inBoss;
956 if (!PyArg_ParseTuple(_args, "O&",
957 CtlObj_Convert, &inBoss))
958 return NULL;
959 _err = SetControlSupervisor(_self->ob_itself,
960 inBoss);
961 if (_err != noErr) return PyMac_Error(_err);
962 Py_INCREF(Py_None);
963 _res = Py_None;
964 return _res;
965}
966
967static PyObject *CtlObj_GetControlFeatures(_self, _args)
968 ControlObject *_self;
969 PyObject *_args;
970{
971 PyObject *_res = NULL;
972 OSErr _err;
973 UInt32 outFeatures;
974 if (!PyArg_ParseTuple(_args, ""))
975 return NULL;
976 _err = GetControlFeatures(_self->ob_itself,
977 &outFeatures);
978 if (_err != noErr) return PyMac_Error(_err);
979 _res = Py_BuildValue("l",
980 outFeatures);
981 return _res;
982}
983
984static PyObject *CtlObj_GetControlDataSize(_self, _args)
985 ControlObject *_self;
986 PyObject *_args;
987{
988 PyObject *_res = NULL;
989 OSErr _err;
990 ControlPartCode inPart;
991 ResType inTagName;
992 Size outMaxSize;
993 if (!PyArg_ParseTuple(_args, "hO&",
994 &inPart,
995 PyMac_GetOSType, &inTagName))
996 return NULL;
997 _err = GetControlDataSize(_self->ob_itself,
998 inPart,
999 inTagName,
1000 &outMaxSize);
1001 if (_err != noErr) return PyMac_Error(_err);
1002 _res = Py_BuildValue("l",
1003 outMaxSize);
1004 return _res;
1005}
1006
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001007static PyObject *CtlObj_as_Resource(_self, _args)
1008 ControlObject *_self;
1009 PyObject *_args;
1010{
1011 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001012 Handle _rv;
1013 if (!PyArg_ParseTuple(_args, ""))
1014 return NULL;
1015 _rv = as_Resource(_self->ob_itself);
1016 _res = Py_BuildValue("O&",
1017 ResObj_New, _rv);
1018 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001019}
1020
Jack Jansencfb60ee1996-10-01 10:46:46 +00001021static PyObject *CtlObj_DisposeControl(_self, _args)
1022 ControlObject *_self;
1023 PyObject *_args;
1024{
1025 PyObject *_res = NULL;
1026
1027 if (!PyArg_ParseTuple(_args, ""))
1028 return NULL;
1029 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001030 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001031 DisposeControl(_self->ob_itself);
1032 _self->ob_itself = NULL;
1033 }
1034 Py_INCREF(Py_None);
1035 _res = Py_None;
1036 return _res;
1037
1038}
1039
Jack Jansen848250c1998-05-28 14:20:09 +00001040static PyObject *CtlObj_TrackControl(_self, _args)
1041 ControlObject *_self;
1042 PyObject *_args;
1043{
1044 PyObject *_res = NULL;
1045
1046 ControlPartCode _rv;
1047 Point startPoint;
1048 ControlActionUPP upp = 0;
1049 PyObject *callback = 0;
1050
1051 if (!PyArg_ParseTuple(_args, "O&|O",
1052 PyMac_GetPoint, &startPoint, &callback))
1053 return NULL;
1054 if (callback && callback != Py_None) {
1055 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1056 upp = (ControlActionUPP)-1;
1057 else {
1058 settrackfunc(callback);
1059 upp = mytracker_upp;
1060 }
1061 }
1062 _rv = TrackControl(_self->ob_itself,
1063 startPoint,
1064 upp);
1065 clrtrackfunc();
1066 _res = Py_BuildValue("h",
1067 _rv);
1068 return _res;
1069
1070}
1071
Jack Jansen24c35311999-12-09 22:49:51 +00001072static PyObject *CtlObj_HandleControlClick(_self, _args)
1073 ControlObject *_self;
1074 PyObject *_args;
1075{
1076 PyObject *_res = NULL;
1077
1078 ControlPartCode _rv;
1079 Point startPoint;
1080 SInt16 modifiers;
1081 ControlActionUPP upp = 0;
1082 PyObject *callback = 0;
1083
1084 if (!PyArg_ParseTuple(_args, "O&h|O",
1085 PyMac_GetPoint, &startPoint,
1086 &modifiers,
1087 &callback))
1088 return NULL;
1089 if (callback && callback != Py_None) {
1090 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1091 upp = (ControlActionUPP)-1;
1092 else {
1093 settrackfunc(callback);
1094 upp = mytracker_upp;
1095 }
1096 }
1097 _rv = HandleControlClick(_self->ob_itself,
1098 startPoint,
1099 modifiers,
1100 upp);
1101 clrtrackfunc();
1102 _res = Py_BuildValue("h",
1103 _rv);
1104 return _res;
1105
1106}
1107
1108static PyObject *CtlObj_SetControlData(_self, _args)
1109 ControlObject *_self;
1110 PyObject *_args;
1111{
1112 PyObject *_res = NULL;
1113
1114 OSErr _err;
1115 ControlPartCode inPart;
1116 ResType inTagName;
1117 Size bufferSize;
1118 Ptr buffer;
1119
1120 if (!PyArg_ParseTuple(_args, "hO&s#",
1121 &inPart,
1122 PyMac_GetOSType, &inTagName,
1123 &buffer, &bufferSize))
1124 return NULL;
1125
1126 _err = SetControlData(_self->ob_itself,
1127 inPart,
1128 inTagName,
1129 bufferSize,
1130 buffer);
1131
1132 if (_err != noErr)
1133 return PyMac_Error(_err);
1134 _res = Py_None;
1135 return _res;
1136
1137}
1138
1139static PyObject *CtlObj_GetControlData(_self, _args)
1140 ControlObject *_self;
1141 PyObject *_args;
1142{
1143 PyObject *_res = NULL;
1144
1145 OSErr _err;
1146 ControlPartCode inPart;
1147 ResType inTagName;
1148 Size bufferSize;
1149 Ptr buffer;
1150 Size outSize;
1151
1152 if (!PyArg_ParseTuple(_args, "hO&",
1153 &inPart,
1154 PyMac_GetOSType, &inTagName))
1155 return NULL;
1156
1157 /* allocate a buffer for the data */
1158 _err = GetControlDataSize(_self->ob_itself,
1159 inPart,
1160 inTagName,
1161 &bufferSize);
1162 if (_err != noErr)
1163 return PyMac_Error(_err);
1164 buffer = PyMem_NEW(char, bufferSize);
1165 if (buffer == NULL)
1166 return PyErr_NoMemory();
1167
1168 _err = GetControlData(_self->ob_itself,
1169 inPart,
1170 inTagName,
1171 bufferSize,
1172 buffer,
1173 &outSize);
1174
1175 if (_err != noErr) {
1176 PyMem_DEL(buffer);
1177 return PyMac_Error(_err);
1178 }
1179 _res = Py_BuildValue("s#", buffer, outSize);
1180 PyMem_DEL(buffer);
1181 return _res;
1182
1183}
1184
Jack Jansen1f9249c1999-12-19 00:05:50 +00001185static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1186 ControlObject *_self;
1187 PyObject *_args;
1188{
1189 PyObject *_res = NULL;
1190
1191 OSErr _err;
1192 ControlPartCode inPart;
1193 ResType inTagName;
1194 Handle buffer;
1195
1196 if (!PyArg_ParseTuple(_args, "hO&O&",
1197 &inPart,
1198 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001199 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001200 return NULL;
1201
1202 _err = SetControlData(_self->ob_itself,
1203 inPart,
1204 inTagName,
1205 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001206 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001207
1208 if (_err != noErr)
1209 return PyMac_Error(_err);
1210 _res = Py_None;
1211 return _res;
1212
1213}
1214
1215static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1216 ControlObject *_self;
1217 PyObject *_args;
1218{
1219 PyObject *_res = NULL;
1220
1221 OSErr _err;
1222 ControlPartCode inPart;
1223 ResType inTagName;
1224 Size bufferSize;
1225 Handle hdl;
1226
1227 if (!PyArg_ParseTuple(_args, "hO&",
1228 &inPart,
1229 PyMac_GetOSType, &inTagName))
1230 return NULL;
1231
1232 /* Check it is handle-sized */
1233 _err = GetControlDataSize(_self->ob_itself,
1234 inPart,
1235 inTagName,
1236 &bufferSize);
1237 if (_err != noErr)
1238 return PyMac_Error(_err);
1239 if (bufferSize != sizeof(Handle)) {
1240 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1241 return NULL;
1242 }
1243
1244 _err = GetControlData(_self->ob_itself,
1245 inPart,
1246 inTagName,
1247 sizeof(Handle),
1248 (Ptr)&hdl,
1249 &bufferSize);
1250
1251 if (_err != noErr) {
1252 return PyMac_Error(_err);
1253 }
1254 return Py_BuildValue("O&", OptResObj_New, hdl);
1255
1256}
1257
Jack Jansen4c704131998-06-19 13:35:14 +00001258static PyObject *CtlObj_GetPopupData(_self, _args)
1259 ControlObject *_self;
1260 PyObject *_args;
1261{
1262 PyObject *_res = NULL;
1263
1264 PopupPrivateDataHandle hdl;
1265
1266 if ( (*_self->ob_itself)->contrlData == NULL ) {
1267 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1268 return 0;
1269 }
1270 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1271 HLock((Handle)hdl);
1272 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1273 HUnlock((Handle)hdl);
1274 return _res;
1275
1276}
1277
1278static PyObject *CtlObj_SetPopupData(_self, _args)
1279 ControlObject *_self;
1280 PyObject *_args;
1281{
1282 PyObject *_res = NULL;
1283
1284 PopupPrivateDataHandle hdl;
1285 MenuHandle mHandle;
1286 short mID;
1287
1288 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1289 return 0;
1290 if ( (*_self->ob_itself)->contrlData == NULL ) {
1291 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1292 return 0;
1293 }
1294 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1295 (*hdl)->mHandle = mHandle;
1296 (*hdl)->mID = mID;
1297 Py_INCREF(Py_None);
1298 return Py_None;
1299
1300}
1301
Guido van Rossum17448e21995-01-30 11:53:55 +00001302static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001303 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1304 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001305 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1306 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001307 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1308 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001309 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1310 "() -> (Boolean _rv)"},
1311 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1312 "() -> (Boolean _rv)"},
1313 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1314 "() -> None"},
1315 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1316 "() -> None"},
1317 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1318 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001319 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1320 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001321 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1322 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1323 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1324 "(ControlFontStyleRec inStyle) -> None"},
1325 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1326 "() -> None"},
1327 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1328 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001329 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1330 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001331 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001332 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001333 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001334 "(Point testPoint) -> (ControlPartCode _rv)"},
1335 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1336 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001337 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001338 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001339 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001340 "(SInt16 w, SInt16 h) -> None"},
1341 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1342 "(Str255 title) -> None"},
1343 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001344 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001345 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001346 "() -> (SInt16 _rv)"},
1347 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1348 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001349 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001350 "() -> (SInt16 _rv)"},
1351 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1352 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001353 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001354 "() -> (SInt16 _rv)"},
1355 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1356 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001357 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1358 "() -> (SInt32 _rv)"},
1359 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1360 "(SInt32 newViewSize) -> None"},
1361 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1362 "() -> (SInt32 _rv)"},
1363 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1364 "(SInt32 newValue) -> None"},
1365 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1366 "() -> (SInt32 _rv)"},
1367 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1368 "(SInt32 newMaximum) -> None"},
1369 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1370 "() -> (SInt32 _rv)"},
1371 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1372 "(SInt32 newMinimum) -> None"},
1373 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1374 "() -> (Boolean _rv)"},
1375 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
1376 "(OSType propertyCreator, OSType propertyTag) -> None"},
1377 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
1378 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001379 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001380 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001381 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1382 "(SInt32 data) -> None"},
1383 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1384 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +00001385 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1386 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
1387 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1388 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001389 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1390 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1391 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1392 "(ControlHandle inContainer) -> None"},
1393 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1394 "(WindowPtr inWindow) -> None"},
1395 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1396 "() -> (ControlHandle outParent)"},
1397 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001398 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001399 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001400 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001401 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1402 "(ControlHandle inBoss) -> None"},
1403 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1404 "() -> (UInt32 outFeatures)"},
1405 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1406 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001407 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00001408 "() -> (Handle _rv)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001409 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1410 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001411 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001412 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1413 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1414 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1415 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1416 "(stuff) -> None"},
1417 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1418 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00001419 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1420 "(ResObj) -> None"},
1421 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1422 "(part, type) -> ResObj"},
Jack Jansen4c704131998-06-19 13:35:14 +00001423 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1424 NULL},
1425 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1426 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001427 {NULL, NULL, 0}
1428};
1429
1430PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1431
1432static PyObject *CtlObj_getattr(self, name)
1433 ControlObject *self;
1434 char *name;
1435{
1436 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1437}
1438
1439#define CtlObj_setattr NULL
1440
Jack Jansen8387af61999-03-13 23:07:32 +00001441static int CtlObj_compare(self, other)
1442 ControlObject *self, *other;
1443{
1444 unsigned long v, w;
1445
1446 if (!CtlObj_Check((PyObject *)other))
1447 {
1448 v=(unsigned long)self;
1449 w=(unsigned long)other;
1450 }
1451 else
1452 {
1453 v=(unsigned long)self->ob_itself;
1454 w=(unsigned long)other->ob_itself;
1455 }
1456 if( v < w ) return -1;
1457 if( v > w ) return 1;
1458 return 0;
1459}
1460
1461#define CtlObj_repr NULL
1462
1463static long CtlObj_hash(self)
1464 ControlObject *self;
1465{
1466 return (long)self->ob_itself;
1467}
1468
Guido van Rossum17448e21995-01-30 11:53:55 +00001469PyTypeObject Control_Type = {
1470 PyObject_HEAD_INIT(&PyType_Type)
1471 0, /*ob_size*/
1472 "Control", /*tp_name*/
1473 sizeof(ControlObject), /*tp_basicsize*/
1474 0, /*tp_itemsize*/
1475 /* methods */
1476 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1477 0, /*tp_print*/
1478 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1479 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001480 (cmpfunc) CtlObj_compare, /*tp_compare*/
1481 (reprfunc) CtlObj_repr, /*tp_repr*/
1482 (PyNumberMethods *)0, /* tp_as_number */
1483 (PySequenceMethods *)0, /* tp_as_sequence */
1484 (PyMappingMethods *)0, /* tp_as_mapping */
1485 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001486};
1487
1488/* -------------------- End object type Control --------------------- */
1489
1490
1491static PyObject *Ctl_NewControl(_self, _args)
1492 PyObject *_self;
1493 PyObject *_args;
1494{
1495 PyObject *_res = NULL;
1496 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001497 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001498 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001499 Str255 controlTitle;
1500 Boolean initiallyVisible;
1501 SInt16 initialValue;
1502 SInt16 minimumValue;
1503 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001504 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001505 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001506 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001507 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001508 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001509 PyMac_GetStr255, controlTitle,
1510 &initiallyVisible,
1511 &initialValue,
1512 &minimumValue,
1513 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001514 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001515 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001516 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001517 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001518 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001519 controlTitle,
1520 initiallyVisible,
1521 initialValue,
1522 minimumValue,
1523 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001524 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001525 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001526 _res = Py_BuildValue("O&",
1527 CtlObj_New, _rv);
1528 return _res;
1529}
1530
1531static PyObject *Ctl_GetNewControl(_self, _args)
1532 PyObject *_self;
1533 PyObject *_args;
1534{
1535 PyObject *_res = NULL;
1536 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001537 SInt16 resourceID;
1538 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001539 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001540 &resourceID,
1541 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001542 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001543 _rv = GetNewControl(resourceID,
1544 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001545 _res = Py_BuildValue("O&",
1546 CtlObj_New, _rv);
1547 return _res;
1548}
1549
Guido van Rossum17448e21995-01-30 11:53:55 +00001550static PyObject *Ctl_DrawControls(_self, _args)
1551 PyObject *_self;
1552 PyObject *_args;
1553{
1554 PyObject *_res = NULL;
1555 WindowPtr theWindow;
1556 if (!PyArg_ParseTuple(_args, "O&",
1557 WinObj_Convert, &theWindow))
1558 return NULL;
1559 DrawControls(theWindow);
1560 Py_INCREF(Py_None);
1561 _res = Py_None;
1562 return _res;
1563}
1564
Guido van Rossum17448e21995-01-30 11:53:55 +00001565static PyObject *Ctl_UpdateControls(_self, _args)
1566 PyObject *_self;
1567 PyObject *_args;
1568{
1569 PyObject *_res = NULL;
1570 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001571 RgnHandle updateRegion;
1572 if (!PyArg_ParseTuple(_args, "O&O&",
1573 WinObj_Convert, &theWindow,
1574 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001575 return NULL;
1576 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001577 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001578 Py_INCREF(Py_None);
1579 _res = Py_None;
1580 return _res;
1581}
1582
1583static PyObject *Ctl_FindControl(_self, _args)
1584 PyObject *_self;
1585 PyObject *_args;
1586{
1587 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001588 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001589 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001590 WindowPtr theWindow;
1591 ControlHandle theControl;
1592 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001593 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001594 WinObj_Convert, &theWindow))
1595 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001596 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001597 theWindow,
1598 &theControl);
1599 _res = Py_BuildValue("hO&",
1600 _rv,
1601 CtlObj_WhichControl, theControl);
1602 return _res;
1603}
1604
Jack Jansen21f96871998-02-20 16:02:09 +00001605static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1606 PyObject *_self;
1607 PyObject *_args;
1608{
1609 PyObject *_res = NULL;
1610 ControlHandle _rv;
1611 Point inWhere;
1612 WindowPtr inWindow;
1613 SInt16 outPart;
1614 if (!PyArg_ParseTuple(_args, "O&O&",
1615 PyMac_GetPoint, &inWhere,
1616 WinObj_Convert, &inWindow))
1617 return NULL;
1618 _rv = FindControlUnderMouse(inWhere,
1619 inWindow,
1620 &outPart);
1621 _res = Py_BuildValue("O&h",
1622 CtlObj_New, _rv,
1623 outPart);
1624 return _res;
1625}
1626
1627static PyObject *Ctl_IdleControls(_self, _args)
1628 PyObject *_self;
1629 PyObject *_args;
1630{
1631 PyObject *_res = NULL;
1632 WindowPtr inWindow;
1633 if (!PyArg_ParseTuple(_args, "O&",
1634 WinObj_Convert, &inWindow))
1635 return NULL;
1636 IdleControls(inWindow);
1637 Py_INCREF(Py_None);
1638 _res = Py_None;
1639 return _res;
1640}
1641
1642static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1643 PyObject *_self;
1644 PyObject *_args;
1645{
1646 PyObject *_res = NULL;
1647 OSErr _err;
1648 WindowPtr inWindow;
1649 FSSpec inDumpFile;
1650 if (!PyArg_ParseTuple(_args, "O&O&",
1651 WinObj_Convert, &inWindow,
1652 PyMac_GetFSSpec, &inDumpFile))
1653 return NULL;
1654 _err = DumpControlHierarchy(inWindow,
1655 &inDumpFile);
1656 if (_err != noErr) return PyMac_Error(_err);
1657 Py_INCREF(Py_None);
1658 _res = Py_None;
1659 return _res;
1660}
1661
1662static PyObject *Ctl_CreateRootControl(_self, _args)
1663 PyObject *_self;
1664 PyObject *_args;
1665{
1666 PyObject *_res = NULL;
1667 OSErr _err;
1668 WindowPtr inWindow;
1669 ControlHandle outControl;
1670 if (!PyArg_ParseTuple(_args, "O&",
1671 WinObj_Convert, &inWindow))
1672 return NULL;
1673 _err = CreateRootControl(inWindow,
1674 &outControl);
1675 if (_err != noErr) return PyMac_Error(_err);
1676 _res = Py_BuildValue("O&",
1677 CtlObj_WhichControl, outControl);
1678 return _res;
1679}
1680
1681static PyObject *Ctl_GetRootControl(_self, _args)
1682 PyObject *_self;
1683 PyObject *_args;
1684{
1685 PyObject *_res = NULL;
1686 OSErr _err;
1687 WindowPtr inWindow;
1688 ControlHandle outControl;
1689 if (!PyArg_ParseTuple(_args, "O&",
1690 WinObj_Convert, &inWindow))
1691 return NULL;
1692 _err = GetRootControl(inWindow,
1693 &outControl);
1694 if (_err != noErr) return PyMac_Error(_err);
1695 _res = Py_BuildValue("O&",
1696 CtlObj_WhichControl, outControl);
1697 return _res;
1698}
1699
1700static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1701 PyObject *_self;
1702 PyObject *_args;
1703{
1704 PyObject *_res = NULL;
1705 OSErr _err;
1706 WindowPtr inWindow;
1707 ControlHandle outControl;
1708 if (!PyArg_ParseTuple(_args, "O&",
1709 WinObj_Convert, &inWindow))
1710 return NULL;
1711 _err = GetKeyboardFocus(inWindow,
1712 &outControl);
1713 if (_err != noErr) return PyMac_Error(_err);
1714 _res = Py_BuildValue("O&",
1715 CtlObj_WhichControl, outControl);
1716 return _res;
1717}
1718
1719static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1720 PyObject *_self;
1721 PyObject *_args;
1722{
1723 PyObject *_res = NULL;
1724 OSErr _err;
1725 WindowPtr inWindow;
1726 ControlHandle inControl;
1727 ControlFocusPart inPart;
1728 if (!PyArg_ParseTuple(_args, "O&O&h",
1729 WinObj_Convert, &inWindow,
1730 CtlObj_Convert, &inControl,
1731 &inPart))
1732 return NULL;
1733 _err = SetKeyboardFocus(inWindow,
1734 inControl,
1735 inPart);
1736 if (_err != noErr) return PyMac_Error(_err);
1737 Py_INCREF(Py_None);
1738 _res = Py_None;
1739 return _res;
1740}
1741
1742static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1743 PyObject *_self;
1744 PyObject *_args;
1745{
1746 PyObject *_res = NULL;
1747 OSErr _err;
1748 WindowPtr inWindow;
1749 if (!PyArg_ParseTuple(_args, "O&",
1750 WinObj_Convert, &inWindow))
1751 return NULL;
1752 _err = AdvanceKeyboardFocus(inWindow);
1753 if (_err != noErr) return PyMac_Error(_err);
1754 Py_INCREF(Py_None);
1755 _res = Py_None;
1756 return _res;
1757}
1758
1759static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1760 PyObject *_self;
1761 PyObject *_args;
1762{
1763 PyObject *_res = NULL;
1764 OSErr _err;
1765 WindowPtr inWindow;
1766 if (!PyArg_ParseTuple(_args, "O&",
1767 WinObj_Convert, &inWindow))
1768 return NULL;
1769 _err = ReverseKeyboardFocus(inWindow);
1770 if (_err != noErr) return PyMac_Error(_err);
1771 Py_INCREF(Py_None);
1772 _res = Py_None;
1773 return _res;
1774}
1775
1776static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1777 PyObject *_self;
1778 PyObject *_args;
1779{
1780 PyObject *_res = NULL;
1781 OSErr _err;
1782 WindowPtr inWindow;
1783 if (!PyArg_ParseTuple(_args, "O&",
1784 WinObj_Convert, &inWindow))
1785 return NULL;
1786 _err = ClearKeyboardFocus(inWindow);
1787 if (_err != noErr) return PyMac_Error(_err);
1788 Py_INCREF(Py_None);
1789 _res = Py_None;
1790 return _res;
1791}
1792
Jack Jansene0581891999-02-07 14:02:03 +00001793static PyObject *Ctl_as_Control(_self, _args)
1794 PyObject *_self;
1795 PyObject *_args;
1796{
1797 PyObject *_res = NULL;
1798 ControlHandle _rv;
1799 Handle h;
1800 if (!PyArg_ParseTuple(_args, "O&",
1801 ResObj_Convert, &h))
1802 return NULL;
1803 _rv = as_Control(h);
1804 _res = Py_BuildValue("O&",
1805 CtlObj_New, _rv);
1806 return _res;
1807}
1808
Guido van Rossum17448e21995-01-30 11:53:55 +00001809static PyMethodDef Ctl_methods[] = {
1810 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001811 "(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 +00001812 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001813 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001814 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1815 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001816 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001817 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001818 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001819 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1820 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1821 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1822 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1823 "(WindowPtr inWindow) -> None"},
1824 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1825 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1826 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1827 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1828 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1829 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1830 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1831 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1832 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1833 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1834 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1835 "(WindowPtr inWindow) -> None"},
1836 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1837 "(WindowPtr inWindow) -> None"},
1838 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1839 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001840 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1841 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001842 {NULL, NULL, 0}
1843};
1844
1845
1846
Jack Jansen8387af61999-03-13 23:07:32 +00001847PyObject *CtlObj_NewUnmanaged(itself)
1848 ControlHandle itself;
1849{
1850 ControlObject *it;
1851 if (itself == NULL) return PyMac_Error(resNotFound);
1852 it = PyObject_NEW(ControlObject, &Control_Type);
1853 if (it == NULL) return NULL;
1854 it->ob_itself = itself;
1855 return (PyObject *)it;
1856}
1857
Guido van Rossum17448e21995-01-30 11:53:55 +00001858PyObject *
1859CtlObj_WhichControl(ControlHandle c)
1860{
1861 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00001862
Guido van Rossum17448e21995-01-30 11:53:55 +00001863 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00001864 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00001865 else {
1866 it = (PyObject *) GetControlReference(c);
1867 /*
1868 ** If the refcon is zero or doesn't point back to the Python object
1869 ** the control is not ours. Return a temporary object.
1870 */
1871 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1872 return CtlObj_NewUnmanaged(c);
1873 }
Guido van Rossum17448e21995-01-30 11:53:55 +00001874 Py_INCREF(it);
1875 return it;
1876}
1877
Jack Jansen848250c1998-05-28 14:20:09 +00001878static int
1879settrackfunc(obj)
1880 PyObject *obj;
1881{
1882 if (tracker) {
1883 PyErr_SetString(Ctl_Error, "Tracker function in use");
1884 return 0;
1885 }
1886 tracker = obj;
1887 Py_INCREF(tracker);
1888}
1889
1890static void
1891clrtrackfunc()
1892{
1893 Py_XDECREF(tracker);
1894 tracker = 0;
1895}
1896
1897static pascal void
1898mytracker(ctl, part)
1899 ControlHandle ctl;
1900 short part;
1901{
1902 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00001903
Jack Jansen848250c1998-05-28 14:20:09 +00001904 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1905 if (args && tracker) {
1906 rv = PyEval_CallObject(tracker, args);
1907 Py_DECREF(args);
1908 }
1909 if (rv)
1910 Py_DECREF(rv);
1911 else
Jack Jansen24c35311999-12-09 22:49:51 +00001912 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001913}
1914
Guido van Rossum17448e21995-01-30 11:53:55 +00001915
1916void initCtl()
1917{
1918 PyObject *m;
1919 PyObject *d;
1920
1921
1922
Jack Jansen848250c1998-05-28 14:20:09 +00001923 mytracker_upp = NewControlActionProc(mytracker);
1924
Guido van Rossum17448e21995-01-30 11:53:55 +00001925
1926 m = Py_InitModule("Ctl", Ctl_methods);
1927 d = PyModule_GetDict(m);
1928 Ctl_Error = PyMac_GetOSErrException();
1929 if (Ctl_Error == NULL ||
1930 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1931 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001932 Control_Type.ob_type = &PyType_Type;
1933 Py_INCREF(&Control_Type);
1934 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1935 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001936}
1937
1938/* ========================= End module Ctl ========================= */
1939