blob: d1deee8684b2f9c035b69fee847b593dd7e0ef5d [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)
48
Guido van Rossum17448e21995-01-30 11:53:55 +000049#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
50
51extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000052extern PyObject *QdRGB_New(RGBColorPtr);
53extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000054
55#ifdef THINK_C
56#define ControlActionUPP ProcPtr
57#endif
58
Jack Jansen21f96871998-02-20 16:02:09 +000059/*
60** Parse/generate ControlFontStyleRec records
61*/
62#if 0 /* Not needed */
63PyObject *ControlFontStyle_New(itself)
64 ControlFontStyleRec *itself;
65{
66
67 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
68 itself->size, itself->style, itself->mode, itself->just,
69 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
70}
71#endif
72
73ControlFontStyle_Convert(v, itself)
74 PyObject *v;
75 ControlFontStyleRec *itself;
76{
77 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000078 &itself->font, &itself->size, &itself->style, &itself->mode,
79 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000080 QdRGB_Convert, &itself->backColor);
81}
82
Jack Jansen24c35311999-12-09 22:49:51 +000083/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000084static PyObject *tracker;
85static ControlActionUPP mytracker_upp;
86
87extern int settrackfunc(PyObject *); /* forward */
88extern void clrtrackfunc(void); /* forward */
89
Guido van Rossum17448e21995-01-30 11:53:55 +000090static PyObject *Ctl_Error;
91
92/* ---------------------- Object type Control ----------------------- */
93
94PyTypeObject Control_Type;
95
96#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
97
98typedef struct ControlObject {
99 PyObject_HEAD
100 ControlHandle ob_itself;
101} ControlObject;
102
103PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000104 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000105{
106 ControlObject *it;
107 if (itself == NULL) return PyMac_Error(resNotFound);
108 it = PyObject_NEW(ControlObject, &Control_Type);
109 if (it == NULL) return NULL;
110 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000111 SetControlReference(itself, (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000112 return (PyObject *)it;
113}
114CtlObj_Convert(v, p_itself)
115 PyObject *v;
116 ControlHandle *p_itself;
117{
118 if (!CtlObj_Check(v))
119 {
120 PyErr_SetString(PyExc_TypeError, "Control required");
121 return 0;
122 }
123 *p_itself = ((ControlObject *)v)->ob_itself;
124 return 1;
125}
126
127static void CtlObj_dealloc(self)
128 ControlObject *self;
129{
Jack Jansen24c35311999-12-09 22:49:51 +0000130 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000131 PyMem_DEL(self);
132}
133
Jack Jansen21f96871998-02-20 16:02:09 +0000134static PyObject *CtlObj_HiliteControl(_self, _args)
135 ControlObject *_self;
136 PyObject *_args;
137{
138 PyObject *_res = NULL;
139 ControlPartCode hiliteState;
140 if (!PyArg_ParseTuple(_args, "h",
141 &hiliteState))
142 return NULL;
143 HiliteControl(_self->ob_itself,
144 hiliteState);
145 Py_INCREF(Py_None);
146 _res = Py_None;
147 return _res;
148}
149
Jack Jansen7d0bc831995-06-09 20:56:31 +0000150static PyObject *CtlObj_ShowControl(_self, _args)
151 ControlObject *_self;
152 PyObject *_args;
153{
154 PyObject *_res = NULL;
155 if (!PyArg_ParseTuple(_args, ""))
156 return NULL;
157 ShowControl(_self->ob_itself);
158 Py_INCREF(Py_None);
159 _res = Py_None;
160 return _res;
161}
162
163static PyObject *CtlObj_HideControl(_self, _args)
164 ControlObject *_self;
165 PyObject *_args;
166{
167 PyObject *_res = NULL;
168 if (!PyArg_ParseTuple(_args, ""))
169 return NULL;
170 HideControl(_self->ob_itself);
171 Py_INCREF(Py_None);
172 _res = Py_None;
173 return _res;
174}
175
Jack Jansen21f96871998-02-20 16:02:09 +0000176static PyObject *CtlObj_IsControlActive(_self, _args)
177 ControlObject *_self;
178 PyObject *_args;
179{
180 PyObject *_res = NULL;
181 Boolean _rv;
182 if (!PyArg_ParseTuple(_args, ""))
183 return NULL;
184 _rv = IsControlActive(_self->ob_itself);
185 _res = Py_BuildValue("b",
186 _rv);
187 return _res;
188}
189
190static PyObject *CtlObj_IsControlVisible(_self, _args)
191 ControlObject *_self;
192 PyObject *_args;
193{
194 PyObject *_res = NULL;
195 Boolean _rv;
196 if (!PyArg_ParseTuple(_args, ""))
197 return NULL;
198 _rv = IsControlVisible(_self->ob_itself);
199 _res = Py_BuildValue("b",
200 _rv);
201 return _res;
202}
203
204static PyObject *CtlObj_ActivateControl(_self, _args)
205 ControlObject *_self;
206 PyObject *_args;
207{
208 PyObject *_res = NULL;
209 OSErr _err;
210 if (!PyArg_ParseTuple(_args, ""))
211 return NULL;
212 _err = ActivateControl(_self->ob_itself);
213 if (_err != noErr) return PyMac_Error(_err);
214 Py_INCREF(Py_None);
215 _res = Py_None;
216 return _res;
217}
218
219static PyObject *CtlObj_DeactivateControl(_self, _args)
220 ControlObject *_self;
221 PyObject *_args;
222{
223 PyObject *_res = NULL;
224 OSErr _err;
225 if (!PyArg_ParseTuple(_args, ""))
226 return NULL;
227 _err = DeactivateControl(_self->ob_itself);
228 if (_err != noErr) return PyMac_Error(_err);
229 Py_INCREF(Py_None);
230 _res = Py_None;
231 return _res;
232}
233
234static PyObject *CtlObj_SetControlVisibility(_self, _args)
235 ControlObject *_self;
236 PyObject *_args;
237{
238 PyObject *_res = NULL;
239 OSErr _err;
240 Boolean inIsVisible;
241 Boolean inDoDraw;
242 if (!PyArg_ParseTuple(_args, "bb",
243 &inIsVisible,
244 &inDoDraw))
245 return NULL;
246 _err = SetControlVisibility(_self->ob_itself,
247 inIsVisible,
248 inDoDraw);
249 if (_err != noErr) return PyMac_Error(_err);
250 Py_INCREF(Py_None);
251 _res = Py_None;
252 return _res;
253}
254
Jack Jansen7d0bc831995-06-09 20:56:31 +0000255static PyObject *CtlObj_Draw1Control(_self, _args)
256 ControlObject *_self;
257 PyObject *_args;
258{
259 PyObject *_res = NULL;
260 if (!PyArg_ParseTuple(_args, ""))
261 return NULL;
262 Draw1Control(_self->ob_itself);
263 Py_INCREF(Py_None);
264 _res = Py_None;
265 return _res;
266}
267
Jack Jansen21f96871998-02-20 16:02:09 +0000268static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000269 ControlObject *_self;
270 PyObject *_args;
271{
272 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000273 OSErr _err;
274 Rect outRect;
275 SInt16 outBaseLineOffset;
276 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000277 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000278 _err = GetBestControlRect(_self->ob_itself,
279 &outRect,
280 &outBaseLineOffset);
281 if (_err != noErr) return PyMac_Error(_err);
282 _res = Py_BuildValue("O&h",
283 PyMac_BuildRect, &outRect,
284 outBaseLineOffset);
285 return _res;
286}
287
288static PyObject *CtlObj_SetControlFontStyle(_self, _args)
289 ControlObject *_self;
290 PyObject *_args;
291{
292 PyObject *_res = NULL;
293 OSErr _err;
294 ControlFontStyleRec inStyle;
295 if (!PyArg_ParseTuple(_args, "O&",
296 ControlFontStyle_Convert, &inStyle))
297 return NULL;
298 _err = SetControlFontStyle(_self->ob_itself,
299 &inStyle);
300 if (_err != noErr) return PyMac_Error(_err);
301 Py_INCREF(Py_None);
302 _res = Py_None;
303 return _res;
304}
305
306static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
307 ControlObject *_self;
308 PyObject *_args;
309{
310 PyObject *_res = NULL;
311 if (!PyArg_ParseTuple(_args, ""))
312 return NULL;
313 DrawControlInCurrentPort(_self->ob_itself);
314 Py_INCREF(Py_None);
315 _res = Py_None;
316 return _res;
317}
318
319static PyObject *CtlObj_SetUpControlBackground(_self, _args)
320 ControlObject *_self;
321 PyObject *_args;
322{
323 PyObject *_res = NULL;
324 OSErr _err;
325 SInt16 inDepth;
326 Boolean inIsColorDevice;
327 if (!PyArg_ParseTuple(_args, "hb",
328 &inDepth,
329 &inIsColorDevice))
330 return NULL;
331 _err = SetUpControlBackground(_self->ob_itself,
332 inDepth,
333 inIsColorDevice);
334 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000335 Py_INCREF(Py_None);
336 _res = Py_None;
337 return _res;
338}
339
Jack Jansena05ac601999-12-12 21:41:51 +0000340static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
341 ControlObject *_self;
342 PyObject *_args;
343{
344 PyObject *_res = NULL;
345 OSErr _err;
346 SInt16 inDepth;
347 Boolean inIsColorDevice;
348 if (!PyArg_ParseTuple(_args, "hb",
349 &inDepth,
350 &inIsColorDevice))
351 return NULL;
352 _err = SetUpControlTextColor(_self->ob_itself,
353 inDepth,
354 inIsColorDevice);
355 if (_err != noErr) return PyMac_Error(_err);
356 Py_INCREF(Py_None);
357 _res = Py_None;
358 return _res;
359}
360
Jack Jansen7d0bc831995-06-09 20:56:31 +0000361static PyObject *CtlObj_DragControl(_self, _args)
362 ControlObject *_self;
363 PyObject *_args;
364{
365 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000366 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000367 Rect limitRect;
368 Rect slopRect;
369 DragConstraint axis;
370 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000371 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000372 PyMac_GetRect, &limitRect,
373 PyMac_GetRect, &slopRect,
374 &axis))
375 return NULL;
376 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000377 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000378 &limitRect,
379 &slopRect,
380 axis);
381 Py_INCREF(Py_None);
382 _res = Py_None;
383 return _res;
384}
385
386static PyObject *CtlObj_TestControl(_self, _args)
387 ControlObject *_self;
388 PyObject *_args;
389{
390 PyObject *_res = NULL;
391 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000392 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000393 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000394 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000395 return NULL;
396 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000397 testPoint);
398 _res = Py_BuildValue("h",
399 _rv);
400 return _res;
401}
402
403static PyObject *CtlObj_HandleControlKey(_self, _args)
404 ControlObject *_self;
405 PyObject *_args;
406{
407 PyObject *_res = NULL;
408 SInt16 _rv;
409 SInt16 inKeyCode;
410 SInt16 inCharCode;
411 SInt16 inModifiers;
412 if (!PyArg_ParseTuple(_args, "hhh",
413 &inKeyCode,
414 &inCharCode,
415 &inModifiers))
416 return NULL;
417 _rv = HandleControlKey(_self->ob_itself,
418 inKeyCode,
419 inCharCode,
420 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000421 _res = Py_BuildValue("h",
422 _rv);
423 return _res;
424}
425
426static PyObject *CtlObj_MoveControl(_self, _args)
427 ControlObject *_self;
428 PyObject *_args;
429{
430 PyObject *_res = NULL;
431 SInt16 h;
432 SInt16 v;
433 if (!PyArg_ParseTuple(_args, "hh",
434 &h,
435 &v))
436 return NULL;
437 MoveControl(_self->ob_itself,
438 h,
439 v);
440 Py_INCREF(Py_None);
441 _res = Py_None;
442 return _res;
443}
444
445static PyObject *CtlObj_SizeControl(_self, _args)
446 ControlObject *_self;
447 PyObject *_args;
448{
449 PyObject *_res = NULL;
450 SInt16 w;
451 SInt16 h;
452 if (!PyArg_ParseTuple(_args, "hh",
453 &w,
454 &h))
455 return NULL;
456 SizeControl(_self->ob_itself,
457 w,
458 h);
459 Py_INCREF(Py_None);
460 _res = Py_None;
461 return _res;
462}
463
Jack Jansenae8a68f1995-06-06 12:55:40 +0000464static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000465 ControlObject *_self;
466 PyObject *_args;
467{
468 PyObject *_res = NULL;
469 Str255 title;
470 if (!PyArg_ParseTuple(_args, "O&",
471 PyMac_GetStr255, title))
472 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000473 SetControlTitle(_self->ob_itself,
474 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000475 Py_INCREF(Py_None);
476 _res = Py_None;
477 return _res;
478}
479
Jack Jansenae8a68f1995-06-06 12:55:40 +0000480static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000481 ControlObject *_self;
482 PyObject *_args;
483{
484 PyObject *_res = NULL;
485 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000486 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000487 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000488 GetControlTitle(_self->ob_itself,
489 title);
Jack Jansen41009001999-03-07 20:05:20 +0000490 _res = Py_BuildValue("O&",
491 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000492 return _res;
493}
494
Jack Jansenae8a68f1995-06-06 12:55:40 +0000495static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000496 ControlObject *_self;
497 PyObject *_args;
498{
499 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000500 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000501 if (!PyArg_ParseTuple(_args, ""))
502 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000503 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000504 _res = Py_BuildValue("h",
505 _rv);
506 return _res;
507}
508
Jack Jansen7d0bc831995-06-09 20:56:31 +0000509static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000510 ControlObject *_self;
511 PyObject *_args;
512{
513 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000514 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000515 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000516 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000517 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000518 SetControlValue(_self->ob_itself,
519 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000520 Py_INCREF(Py_None);
521 _res = Py_None;
522 return _res;
523}
524
Jack Jansenae8a68f1995-06-06 12:55:40 +0000525static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000526 ControlObject *_self;
527 PyObject *_args;
528{
529 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000530 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000531 if (!PyArg_ParseTuple(_args, ""))
532 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000533 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000534 _res = Py_BuildValue("h",
535 _rv);
536 return _res;
537}
538
Jack Jansen7d0bc831995-06-09 20:56:31 +0000539static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000540 ControlObject *_self;
541 PyObject *_args;
542{
543 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000544 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000545 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000546 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000547 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000548 SetControlMinimum(_self->ob_itself,
549 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000550 Py_INCREF(Py_None);
551 _res = Py_None;
552 return _res;
553}
554
Jack Jansenae8a68f1995-06-06 12:55:40 +0000555static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000556 ControlObject *_self;
557 PyObject *_args;
558{
559 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000560 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000561 if (!PyArg_ParseTuple(_args, ""))
562 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000563 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000564 _res = Py_BuildValue("h",
565 _rv);
566 return _res;
567}
568
Jack Jansen7d0bc831995-06-09 20:56:31 +0000569static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000570 ControlObject *_self;
571 PyObject *_args;
572{
573 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000574 SInt16 newMaximum;
575 if (!PyArg_ParseTuple(_args, "h",
576 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000577 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000578 SetControlMaximum(_self->ob_itself,
579 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000580 Py_INCREF(Py_None);
581 _res = Py_None;
582 return _res;
583}
584
Jack Jansena05ac601999-12-12 21:41:51 +0000585static PyObject *CtlObj_GetControlViewSize(_self, _args)
586 ControlObject *_self;
587 PyObject *_args;
588{
589 PyObject *_res = NULL;
590 SInt32 _rv;
591 if (!PyArg_ParseTuple(_args, ""))
592 return NULL;
593 _rv = GetControlViewSize(_self->ob_itself);
594 _res = Py_BuildValue("l",
595 _rv);
596 return _res;
597}
598
599static PyObject *CtlObj_SetControlViewSize(_self, _args)
600 ControlObject *_self;
601 PyObject *_args;
602{
603 PyObject *_res = NULL;
604 SInt32 newViewSize;
605 if (!PyArg_ParseTuple(_args, "l",
606 &newViewSize))
607 return NULL;
608 SetControlViewSize(_self->ob_itself,
609 newViewSize);
610 Py_INCREF(Py_None);
611 _res = Py_None;
612 return _res;
613}
614
615static PyObject *CtlObj_GetControl32BitValue(_self, _args)
616 ControlObject *_self;
617 PyObject *_args;
618{
619 PyObject *_res = NULL;
620 SInt32 _rv;
621 if (!PyArg_ParseTuple(_args, ""))
622 return NULL;
623 _rv = GetControl32BitValue(_self->ob_itself);
624 _res = Py_BuildValue("l",
625 _rv);
626 return _res;
627}
628
629static PyObject *CtlObj_SetControl32BitValue(_self, _args)
630 ControlObject *_self;
631 PyObject *_args;
632{
633 PyObject *_res = NULL;
634 SInt32 newValue;
635 if (!PyArg_ParseTuple(_args, "l",
636 &newValue))
637 return NULL;
638 SetControl32BitValue(_self->ob_itself,
639 newValue);
640 Py_INCREF(Py_None);
641 _res = Py_None;
642 return _res;
643}
644
645static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
646 ControlObject *_self;
647 PyObject *_args;
648{
649 PyObject *_res = NULL;
650 SInt32 _rv;
651 if (!PyArg_ParseTuple(_args, ""))
652 return NULL;
653 _rv = GetControl32BitMaximum(_self->ob_itself);
654 _res = Py_BuildValue("l",
655 _rv);
656 return _res;
657}
658
659static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
660 ControlObject *_self;
661 PyObject *_args;
662{
663 PyObject *_res = NULL;
664 SInt32 newMaximum;
665 if (!PyArg_ParseTuple(_args, "l",
666 &newMaximum))
667 return NULL;
668 SetControl32BitMaximum(_self->ob_itself,
669 newMaximum);
670 Py_INCREF(Py_None);
671 _res = Py_None;
672 return _res;
673}
674
675static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
676 ControlObject *_self;
677 PyObject *_args;
678{
679 PyObject *_res = NULL;
680 SInt32 _rv;
681 if (!PyArg_ParseTuple(_args, ""))
682 return NULL;
683 _rv = GetControl32BitMinimum(_self->ob_itself);
684 _res = Py_BuildValue("l",
685 _rv);
686 return _res;
687}
688
689static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
690 ControlObject *_self;
691 PyObject *_args;
692{
693 PyObject *_res = NULL;
694 SInt32 newMinimum;
695 if (!PyArg_ParseTuple(_args, "l",
696 &newMinimum))
697 return NULL;
698 SetControl32BitMinimum(_self->ob_itself,
699 newMinimum);
700 Py_INCREF(Py_None);
701 _res = Py_None;
702 return _res;
703}
704
705static PyObject *CtlObj_IsValidControlHandle(_self, _args)
706 ControlObject *_self;
707 PyObject *_args;
708{
709 PyObject *_res = NULL;
710 Boolean _rv;
711 if (!PyArg_ParseTuple(_args, ""))
712 return NULL;
713 _rv = IsValidControlHandle(_self->ob_itself);
714 _res = Py_BuildValue("b",
715 _rv);
716 return _res;
717}
718
719static PyObject *CtlObj_RemoveControlProperty(_self, _args)
720 ControlObject *_self;
721 PyObject *_args;
722{
723 PyObject *_res = NULL;
724 OSStatus _err;
725 OSType propertyCreator;
726 OSType propertyTag;
727 if (!PyArg_ParseTuple(_args, "O&O&",
728 PyMac_GetOSType, &propertyCreator,
729 PyMac_GetOSType, &propertyTag))
730 return NULL;
731 _err = RemoveControlProperty(_self->ob_itself,
732 propertyCreator,
733 propertyTag);
734 if (_err != noErr) return PyMac_Error(_err);
735 Py_INCREF(Py_None);
736 _res = Py_None;
737 return _res;
738}
739
740static PyObject *CtlObj_GetControlRegion(_self, _args)
741 ControlObject *_self;
742 PyObject *_args;
743{
744 PyObject *_res = NULL;
745 OSStatus _err;
746 ControlPartCode inPart;
747 RgnHandle outRegion;
748 if (!PyArg_ParseTuple(_args, "hO&",
749 &inPart,
750 ResObj_Convert, &outRegion))
751 return NULL;
752 _err = GetControlRegion(_self->ob_itself,
753 inPart,
754 outRegion);
755 if (_err != noErr) return PyMac_Error(_err);
756 Py_INCREF(Py_None);
757 _res = Py_None;
758 return _res;
759}
760
Jack Jansen7d0bc831995-06-09 20:56:31 +0000761static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000762 ControlObject *_self;
763 PyObject *_args;
764{
765 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000766 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000767 if (!PyArg_ParseTuple(_args, ""))
768 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000769 _rv = GetControlVariant(_self->ob_itself);
770 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000771 _rv);
772 return _res;
773}
774
Jack Jansen7d0bc831995-06-09 20:56:31 +0000775static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000776 ControlObject *_self;
777 PyObject *_args;
778{
779 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000780 SInt32 data;
781 if (!PyArg_ParseTuple(_args, "l",
782 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000783 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000784 SetControlReference(_self->ob_itself,
785 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000786 Py_INCREF(Py_None);
787 _res = Py_None;
788 return _res;
789}
790
Jack Jansen7d0bc831995-06-09 20:56:31 +0000791static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000792 ControlObject *_self;
793 PyObject *_args;
794{
795 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000796 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000797 if (!PyArg_ParseTuple(_args, ""))
798 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000799 _rv = GetControlReference(_self->ob_itself);
800 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000801 _rv);
802 return _res;
803}
804
Jack Jansenc7fefed1997-08-15 14:32:18 +0000805static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
806 ControlObject *_self;
807 PyObject *_args;
808{
809 PyObject *_res = NULL;
810 Boolean _rv;
811 AuxCtlHandle acHndl;
812 if (!PyArg_ParseTuple(_args, ""))
813 return NULL;
814 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
815 &acHndl);
816 _res = Py_BuildValue("bO&",
817 _rv,
818 ResObj_New, acHndl);
819 return _res;
820}
821
822static PyObject *CtlObj_SetControlColor(_self, _args)
823 ControlObject *_self;
824 PyObject *_args;
825{
826 PyObject *_res = NULL;
827 CCTabHandle newColorTable;
828 if (!PyArg_ParseTuple(_args, "O&",
829 ResObj_Convert, &newColorTable))
830 return NULL;
831 SetControlColor(_self->ob_itself,
832 newColorTable);
833 Py_INCREF(Py_None);
834 _res = Py_None;
835 return _res;
836}
837
Jack Jansen21f96871998-02-20 16:02:09 +0000838static PyObject *CtlObj_SendControlMessage(_self, _args)
839 ControlObject *_self;
840 PyObject *_args;
841{
842 PyObject *_res = NULL;
843 SInt32 _rv;
844 SInt16 inMessage;
845 SInt32 inParam;
846 if (!PyArg_ParseTuple(_args, "hl",
847 &inMessage,
848 &inParam))
849 return NULL;
850 _rv = SendControlMessage(_self->ob_itself,
851 inMessage,
852 inParam);
853 _res = Py_BuildValue("l",
854 _rv);
855 return _res;
856}
857
858static PyObject *CtlObj_EmbedControl(_self, _args)
859 ControlObject *_self;
860 PyObject *_args;
861{
862 PyObject *_res = NULL;
863 OSErr _err;
864 ControlHandle inContainer;
865 if (!PyArg_ParseTuple(_args, "O&",
866 CtlObj_Convert, &inContainer))
867 return NULL;
868 _err = EmbedControl(_self->ob_itself,
869 inContainer);
870 if (_err != noErr) return PyMac_Error(_err);
871 Py_INCREF(Py_None);
872 _res = Py_None;
873 return _res;
874}
875
876static PyObject *CtlObj_AutoEmbedControl(_self, _args)
877 ControlObject *_self;
878 PyObject *_args;
879{
880 PyObject *_res = NULL;
881 OSErr _err;
882 WindowPtr inWindow;
883 if (!PyArg_ParseTuple(_args, "O&",
884 WinObj_Convert, &inWindow))
885 return NULL;
886 _err = AutoEmbedControl(_self->ob_itself,
887 inWindow);
888 if (_err != noErr) return PyMac_Error(_err);
889 Py_INCREF(Py_None);
890 _res = Py_None;
891 return _res;
892}
893
894static PyObject *CtlObj_GetSuperControl(_self, _args)
895 ControlObject *_self;
896 PyObject *_args;
897{
898 PyObject *_res = NULL;
899 OSErr _err;
900 ControlHandle outParent;
901 if (!PyArg_ParseTuple(_args, ""))
902 return NULL;
903 _err = GetSuperControl(_self->ob_itself,
904 &outParent);
905 if (_err != noErr) return PyMac_Error(_err);
906 _res = Py_BuildValue("O&",
907 CtlObj_WhichControl, outParent);
908 return _res;
909}
910
911static PyObject *CtlObj_CountSubControls(_self, _args)
912 ControlObject *_self;
913 PyObject *_args;
914{
915 PyObject *_res = NULL;
916 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000917 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +0000918 if (!PyArg_ParseTuple(_args, ""))
919 return NULL;
920 _err = CountSubControls(_self->ob_itself,
921 &outNumChildren);
922 if (_err != noErr) return PyMac_Error(_err);
923 _res = Py_BuildValue("h",
924 outNumChildren);
925 return _res;
926}
927
928static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
929 ControlObject *_self;
930 PyObject *_args;
931{
932 PyObject *_res = NULL;
933 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000934 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +0000935 ControlHandle outSubControl;
936 if (!PyArg_ParseTuple(_args, "h",
937 &inIndex))
938 return NULL;
939 _err = GetIndexedSubControl(_self->ob_itself,
940 inIndex,
941 &outSubControl);
942 if (_err != noErr) return PyMac_Error(_err);
943 _res = Py_BuildValue("O&",
944 CtlObj_WhichControl, outSubControl);
945 return _res;
946}
947
948static PyObject *CtlObj_SetControlSupervisor(_self, _args)
949 ControlObject *_self;
950 PyObject *_args;
951{
952 PyObject *_res = NULL;
953 OSErr _err;
954 ControlHandle inBoss;
955 if (!PyArg_ParseTuple(_args, "O&",
956 CtlObj_Convert, &inBoss))
957 return NULL;
958 _err = SetControlSupervisor(_self->ob_itself,
959 inBoss);
960 if (_err != noErr) return PyMac_Error(_err);
961 Py_INCREF(Py_None);
962 _res = Py_None;
963 return _res;
964}
965
966static PyObject *CtlObj_GetControlFeatures(_self, _args)
967 ControlObject *_self;
968 PyObject *_args;
969{
970 PyObject *_res = NULL;
971 OSErr _err;
972 UInt32 outFeatures;
973 if (!PyArg_ParseTuple(_args, ""))
974 return NULL;
975 _err = GetControlFeatures(_self->ob_itself,
976 &outFeatures);
977 if (_err != noErr) return PyMac_Error(_err);
978 _res = Py_BuildValue("l",
979 outFeatures);
980 return _res;
981}
982
983static PyObject *CtlObj_GetControlDataSize(_self, _args)
984 ControlObject *_self;
985 PyObject *_args;
986{
987 PyObject *_res = NULL;
988 OSErr _err;
989 ControlPartCode inPart;
990 ResType inTagName;
991 Size outMaxSize;
992 if (!PyArg_ParseTuple(_args, "hO&",
993 &inPart,
994 PyMac_GetOSType, &inTagName))
995 return NULL;
996 _err = GetControlDataSize(_self->ob_itself,
997 inPart,
998 inTagName,
999 &outMaxSize);
1000 if (_err != noErr) return PyMac_Error(_err);
1001 _res = Py_BuildValue("l",
1002 outMaxSize);
1003 return _res;
1004}
1005
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001006static PyObject *CtlObj_as_Resource(_self, _args)
1007 ControlObject *_self;
1008 PyObject *_args;
1009{
1010 PyObject *_res = NULL;
1011
1012 return ResObj_New((Handle)_self->ob_itself);
1013
1014}
1015
Jack Jansencfb60ee1996-10-01 10:46:46 +00001016static PyObject *CtlObj_DisposeControl(_self, _args)
1017 ControlObject *_self;
1018 PyObject *_args;
1019{
1020 PyObject *_res = NULL;
1021
1022 if (!PyArg_ParseTuple(_args, ""))
1023 return NULL;
1024 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001025 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001026 DisposeControl(_self->ob_itself);
1027 _self->ob_itself = NULL;
1028 }
1029 Py_INCREF(Py_None);
1030 _res = Py_None;
1031 return _res;
1032
1033}
1034
Jack Jansen848250c1998-05-28 14:20:09 +00001035static PyObject *CtlObj_TrackControl(_self, _args)
1036 ControlObject *_self;
1037 PyObject *_args;
1038{
1039 PyObject *_res = NULL;
1040
1041 ControlPartCode _rv;
1042 Point startPoint;
1043 ControlActionUPP upp = 0;
1044 PyObject *callback = 0;
1045
1046 if (!PyArg_ParseTuple(_args, "O&|O",
1047 PyMac_GetPoint, &startPoint, &callback))
1048 return NULL;
1049 if (callback && callback != Py_None) {
1050 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1051 upp = (ControlActionUPP)-1;
1052 else {
1053 settrackfunc(callback);
1054 upp = mytracker_upp;
1055 }
1056 }
1057 _rv = TrackControl(_self->ob_itself,
1058 startPoint,
1059 upp);
1060 clrtrackfunc();
1061 _res = Py_BuildValue("h",
1062 _rv);
1063 return _res;
1064
1065}
1066
Jack Jansen24c35311999-12-09 22:49:51 +00001067static PyObject *CtlObj_HandleControlClick(_self, _args)
1068 ControlObject *_self;
1069 PyObject *_args;
1070{
1071 PyObject *_res = NULL;
1072
1073 ControlPartCode _rv;
1074 Point startPoint;
1075 SInt16 modifiers;
1076 ControlActionUPP upp = 0;
1077 PyObject *callback = 0;
1078
1079 if (!PyArg_ParseTuple(_args, "O&h|O",
1080 PyMac_GetPoint, &startPoint,
1081 &modifiers,
1082 &callback))
1083 return NULL;
1084 if (callback && callback != Py_None) {
1085 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1086 upp = (ControlActionUPP)-1;
1087 else {
1088 settrackfunc(callback);
1089 upp = mytracker_upp;
1090 }
1091 }
1092 _rv = HandleControlClick(_self->ob_itself,
1093 startPoint,
1094 modifiers,
1095 upp);
1096 clrtrackfunc();
1097 _res = Py_BuildValue("h",
1098 _rv);
1099 return _res;
1100
1101}
1102
1103static PyObject *CtlObj_SetControlData(_self, _args)
1104 ControlObject *_self;
1105 PyObject *_args;
1106{
1107 PyObject *_res = NULL;
1108
1109 OSErr _err;
1110 ControlPartCode inPart;
1111 ResType inTagName;
1112 Size bufferSize;
1113 Ptr buffer;
1114
1115 if (!PyArg_ParseTuple(_args, "hO&s#",
1116 &inPart,
1117 PyMac_GetOSType, &inTagName,
1118 &buffer, &bufferSize))
1119 return NULL;
1120
1121 _err = SetControlData(_self->ob_itself,
1122 inPart,
1123 inTagName,
1124 bufferSize,
1125 buffer);
1126
1127 if (_err != noErr)
1128 return PyMac_Error(_err);
1129 _res = Py_None;
1130 return _res;
1131
1132}
1133
1134static PyObject *CtlObj_GetControlData(_self, _args)
1135 ControlObject *_self;
1136 PyObject *_args;
1137{
1138 PyObject *_res = NULL;
1139
1140 OSErr _err;
1141 ControlPartCode inPart;
1142 ResType inTagName;
1143 Size bufferSize;
1144 Ptr buffer;
1145 Size outSize;
1146
1147 if (!PyArg_ParseTuple(_args, "hO&",
1148 &inPart,
1149 PyMac_GetOSType, &inTagName))
1150 return NULL;
1151
1152 /* allocate a buffer for the data */
1153 _err = GetControlDataSize(_self->ob_itself,
1154 inPart,
1155 inTagName,
1156 &bufferSize);
1157 if (_err != noErr)
1158 return PyMac_Error(_err);
1159 buffer = PyMem_NEW(char, bufferSize);
1160 if (buffer == NULL)
1161 return PyErr_NoMemory();
1162
1163 _err = GetControlData(_self->ob_itself,
1164 inPart,
1165 inTagName,
1166 bufferSize,
1167 buffer,
1168 &outSize);
1169
1170 if (_err != noErr) {
1171 PyMem_DEL(buffer);
1172 return PyMac_Error(_err);
1173 }
1174 _res = Py_BuildValue("s#", buffer, outSize);
1175 PyMem_DEL(buffer);
1176 return _res;
1177
1178}
1179
Jack Jansen1f9249c1999-12-19 00:05:50 +00001180static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1181 ControlObject *_self;
1182 PyObject *_args;
1183{
1184 PyObject *_res = NULL;
1185
1186 OSErr _err;
1187 ControlPartCode inPart;
1188 ResType inTagName;
1189 Handle buffer;
1190
1191 if (!PyArg_ParseTuple(_args, "hO&O&",
1192 &inPart,
1193 PyMac_GetOSType, &inTagName,
1194 OptResObj_Convert, buffer))
1195 return NULL;
1196
1197 _err = SetControlData(_self->ob_itself,
1198 inPart,
1199 inTagName,
1200 sizeof(buffer),
1201 (Ptr)buffer);
1202
1203 if (_err != noErr)
1204 return PyMac_Error(_err);
1205 _res = Py_None;
1206 return _res;
1207
1208}
1209
1210static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1211 ControlObject *_self;
1212 PyObject *_args;
1213{
1214 PyObject *_res = NULL;
1215
1216 OSErr _err;
1217 ControlPartCode inPart;
1218 ResType inTagName;
1219 Size bufferSize;
1220 Handle hdl;
1221
1222 if (!PyArg_ParseTuple(_args, "hO&",
1223 &inPart,
1224 PyMac_GetOSType, &inTagName))
1225 return NULL;
1226
1227 /* Check it is handle-sized */
1228 _err = GetControlDataSize(_self->ob_itself,
1229 inPart,
1230 inTagName,
1231 &bufferSize);
1232 if (_err != noErr)
1233 return PyMac_Error(_err);
1234 if (bufferSize != sizeof(Handle)) {
1235 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1236 return NULL;
1237 }
1238
1239 _err = GetControlData(_self->ob_itself,
1240 inPart,
1241 inTagName,
1242 sizeof(Handle),
1243 (Ptr)&hdl,
1244 &bufferSize);
1245
1246 if (_err != noErr) {
1247 return PyMac_Error(_err);
1248 }
1249 return Py_BuildValue("O&", OptResObj_New, hdl);
1250
1251}
1252
Jack Jansen4c704131998-06-19 13:35:14 +00001253static PyObject *CtlObj_GetPopupData(_self, _args)
1254 ControlObject *_self;
1255 PyObject *_args;
1256{
1257 PyObject *_res = NULL;
1258
1259 PopupPrivateDataHandle hdl;
1260
1261 if ( (*_self->ob_itself)->contrlData == NULL ) {
1262 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1263 return 0;
1264 }
1265 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1266 HLock((Handle)hdl);
1267 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1268 HUnlock((Handle)hdl);
1269 return _res;
1270
1271}
1272
1273static PyObject *CtlObj_SetPopupData(_self, _args)
1274 ControlObject *_self;
1275 PyObject *_args;
1276{
1277 PyObject *_res = NULL;
1278
1279 PopupPrivateDataHandle hdl;
1280 MenuHandle mHandle;
1281 short mID;
1282
1283 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1284 return 0;
1285 if ( (*_self->ob_itself)->contrlData == NULL ) {
1286 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1287 return 0;
1288 }
1289 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1290 (*hdl)->mHandle = mHandle;
1291 (*hdl)->mID = mID;
1292 Py_INCREF(Py_None);
1293 return Py_None;
1294
1295}
1296
Guido van Rossum17448e21995-01-30 11:53:55 +00001297static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001298 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1299 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001300 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1301 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001302 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1303 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001304 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1305 "() -> (Boolean _rv)"},
1306 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1307 "() -> (Boolean _rv)"},
1308 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1309 "() -> None"},
1310 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1311 "() -> None"},
1312 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1313 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001314 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1315 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001316 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1317 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1318 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1319 "(ControlFontStyleRec inStyle) -> None"},
1320 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1321 "() -> None"},
1322 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1323 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001324 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1325 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001326 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001327 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001328 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001329 "(Point testPoint) -> (ControlPartCode _rv)"},
1330 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1331 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001332 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001333 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001334 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001335 "(SInt16 w, SInt16 h) -> None"},
1336 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1337 "(Str255 title) -> None"},
1338 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001339 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001340 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001341 "() -> (SInt16 _rv)"},
1342 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1343 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001344 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001345 "() -> (SInt16 _rv)"},
1346 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1347 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001348 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001349 "() -> (SInt16 _rv)"},
1350 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1351 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001352 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1353 "() -> (SInt32 _rv)"},
1354 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1355 "(SInt32 newViewSize) -> None"},
1356 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1357 "() -> (SInt32 _rv)"},
1358 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1359 "(SInt32 newValue) -> None"},
1360 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1361 "() -> (SInt32 _rv)"},
1362 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1363 "(SInt32 newMaximum) -> None"},
1364 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1365 "() -> (SInt32 _rv)"},
1366 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1367 "(SInt32 newMinimum) -> None"},
1368 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1369 "() -> (Boolean _rv)"},
1370 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
1371 "(OSType propertyCreator, OSType propertyTag) -> None"},
1372 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
1373 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001374 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001375 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001376 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1377 "(SInt32 data) -> None"},
1378 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1379 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +00001380 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1381 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
1382 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1383 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001384 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1385 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1386 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1387 "(ControlHandle inContainer) -> None"},
1388 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1389 "(WindowPtr inWindow) -> None"},
1390 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1391 "() -> (ControlHandle outParent)"},
1392 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001393 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001394 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001395 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001396 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1397 "(ControlHandle inBoss) -> None"},
1398 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1399 "() -> (UInt32 outFeatures)"},
1400 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1401 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001402 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
1403 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001404 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1405 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001406 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001407 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1408 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1409 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1410 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1411 "(stuff) -> None"},
1412 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1413 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00001414 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1415 "(ResObj) -> None"},
1416 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1417 "(part, type) -> ResObj"},
Jack Jansen4c704131998-06-19 13:35:14 +00001418 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1419 NULL},
1420 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1421 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001422 {NULL, NULL, 0}
1423};
1424
1425PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1426
1427static PyObject *CtlObj_getattr(self, name)
1428 ControlObject *self;
1429 char *name;
1430{
1431 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1432}
1433
1434#define CtlObj_setattr NULL
1435
Jack Jansen8387af61999-03-13 23:07:32 +00001436static int CtlObj_compare(self, other)
1437 ControlObject *self, *other;
1438{
1439 unsigned long v, w;
1440
1441 if (!CtlObj_Check((PyObject *)other))
1442 {
1443 v=(unsigned long)self;
1444 w=(unsigned long)other;
1445 }
1446 else
1447 {
1448 v=(unsigned long)self->ob_itself;
1449 w=(unsigned long)other->ob_itself;
1450 }
1451 if( v < w ) return -1;
1452 if( v > w ) return 1;
1453 return 0;
1454}
1455
1456#define CtlObj_repr NULL
1457
1458static long CtlObj_hash(self)
1459 ControlObject *self;
1460{
1461 return (long)self->ob_itself;
1462}
1463
Guido van Rossum17448e21995-01-30 11:53:55 +00001464PyTypeObject Control_Type = {
1465 PyObject_HEAD_INIT(&PyType_Type)
1466 0, /*ob_size*/
1467 "Control", /*tp_name*/
1468 sizeof(ControlObject), /*tp_basicsize*/
1469 0, /*tp_itemsize*/
1470 /* methods */
1471 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1472 0, /*tp_print*/
1473 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1474 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001475 (cmpfunc) CtlObj_compare, /*tp_compare*/
1476 (reprfunc) CtlObj_repr, /*tp_repr*/
1477 (PyNumberMethods *)0, /* tp_as_number */
1478 (PySequenceMethods *)0, /* tp_as_sequence */
1479 (PyMappingMethods *)0, /* tp_as_mapping */
1480 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001481};
1482
1483/* -------------------- End object type Control --------------------- */
1484
1485
1486static PyObject *Ctl_NewControl(_self, _args)
1487 PyObject *_self;
1488 PyObject *_args;
1489{
1490 PyObject *_res = NULL;
1491 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001492 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001493 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001494 Str255 controlTitle;
1495 Boolean initiallyVisible;
1496 SInt16 initialValue;
1497 SInt16 minimumValue;
1498 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001499 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001500 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001501 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001502 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001503 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001504 PyMac_GetStr255, controlTitle,
1505 &initiallyVisible,
1506 &initialValue,
1507 &minimumValue,
1508 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001509 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001510 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001511 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001512 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001513 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001514 controlTitle,
1515 initiallyVisible,
1516 initialValue,
1517 minimumValue,
1518 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001519 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001520 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001521 _res = Py_BuildValue("O&",
1522 CtlObj_New, _rv);
1523 return _res;
1524}
1525
1526static PyObject *Ctl_GetNewControl(_self, _args)
1527 PyObject *_self;
1528 PyObject *_args;
1529{
1530 PyObject *_res = NULL;
1531 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001532 SInt16 resourceID;
1533 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001534 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001535 &resourceID,
1536 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001537 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001538 _rv = GetNewControl(resourceID,
1539 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001540 _res = Py_BuildValue("O&",
1541 CtlObj_New, _rv);
1542 return _res;
1543}
1544
Guido van Rossum17448e21995-01-30 11:53:55 +00001545static PyObject *Ctl_DrawControls(_self, _args)
1546 PyObject *_self;
1547 PyObject *_args;
1548{
1549 PyObject *_res = NULL;
1550 WindowPtr theWindow;
1551 if (!PyArg_ParseTuple(_args, "O&",
1552 WinObj_Convert, &theWindow))
1553 return NULL;
1554 DrawControls(theWindow);
1555 Py_INCREF(Py_None);
1556 _res = Py_None;
1557 return _res;
1558}
1559
Guido van Rossum17448e21995-01-30 11:53:55 +00001560static PyObject *Ctl_UpdateControls(_self, _args)
1561 PyObject *_self;
1562 PyObject *_args;
1563{
1564 PyObject *_res = NULL;
1565 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001566 RgnHandle updateRegion;
1567 if (!PyArg_ParseTuple(_args, "O&O&",
1568 WinObj_Convert, &theWindow,
1569 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001570 return NULL;
1571 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001572 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001573 Py_INCREF(Py_None);
1574 _res = Py_None;
1575 return _res;
1576}
1577
1578static PyObject *Ctl_FindControl(_self, _args)
1579 PyObject *_self;
1580 PyObject *_args;
1581{
1582 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001583 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001584 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001585 WindowPtr theWindow;
1586 ControlHandle theControl;
1587 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001588 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001589 WinObj_Convert, &theWindow))
1590 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001591 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001592 theWindow,
1593 &theControl);
1594 _res = Py_BuildValue("hO&",
1595 _rv,
1596 CtlObj_WhichControl, theControl);
1597 return _res;
1598}
1599
Jack Jansen21f96871998-02-20 16:02:09 +00001600static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1601 PyObject *_self;
1602 PyObject *_args;
1603{
1604 PyObject *_res = NULL;
1605 ControlHandle _rv;
1606 Point inWhere;
1607 WindowPtr inWindow;
1608 SInt16 outPart;
1609 if (!PyArg_ParseTuple(_args, "O&O&",
1610 PyMac_GetPoint, &inWhere,
1611 WinObj_Convert, &inWindow))
1612 return NULL;
1613 _rv = FindControlUnderMouse(inWhere,
1614 inWindow,
1615 &outPart);
1616 _res = Py_BuildValue("O&h",
1617 CtlObj_New, _rv,
1618 outPart);
1619 return _res;
1620}
1621
1622static PyObject *Ctl_IdleControls(_self, _args)
1623 PyObject *_self;
1624 PyObject *_args;
1625{
1626 PyObject *_res = NULL;
1627 WindowPtr inWindow;
1628 if (!PyArg_ParseTuple(_args, "O&",
1629 WinObj_Convert, &inWindow))
1630 return NULL;
1631 IdleControls(inWindow);
1632 Py_INCREF(Py_None);
1633 _res = Py_None;
1634 return _res;
1635}
1636
1637static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1638 PyObject *_self;
1639 PyObject *_args;
1640{
1641 PyObject *_res = NULL;
1642 OSErr _err;
1643 WindowPtr inWindow;
1644 FSSpec inDumpFile;
1645 if (!PyArg_ParseTuple(_args, "O&O&",
1646 WinObj_Convert, &inWindow,
1647 PyMac_GetFSSpec, &inDumpFile))
1648 return NULL;
1649 _err = DumpControlHierarchy(inWindow,
1650 &inDumpFile);
1651 if (_err != noErr) return PyMac_Error(_err);
1652 Py_INCREF(Py_None);
1653 _res = Py_None;
1654 return _res;
1655}
1656
1657static PyObject *Ctl_CreateRootControl(_self, _args)
1658 PyObject *_self;
1659 PyObject *_args;
1660{
1661 PyObject *_res = NULL;
1662 OSErr _err;
1663 WindowPtr inWindow;
1664 ControlHandle outControl;
1665 if (!PyArg_ParseTuple(_args, "O&",
1666 WinObj_Convert, &inWindow))
1667 return NULL;
1668 _err = CreateRootControl(inWindow,
1669 &outControl);
1670 if (_err != noErr) return PyMac_Error(_err);
1671 _res = Py_BuildValue("O&",
1672 CtlObj_WhichControl, outControl);
1673 return _res;
1674}
1675
1676static PyObject *Ctl_GetRootControl(_self, _args)
1677 PyObject *_self;
1678 PyObject *_args;
1679{
1680 PyObject *_res = NULL;
1681 OSErr _err;
1682 WindowPtr inWindow;
1683 ControlHandle outControl;
1684 if (!PyArg_ParseTuple(_args, "O&",
1685 WinObj_Convert, &inWindow))
1686 return NULL;
1687 _err = GetRootControl(inWindow,
1688 &outControl);
1689 if (_err != noErr) return PyMac_Error(_err);
1690 _res = Py_BuildValue("O&",
1691 CtlObj_WhichControl, outControl);
1692 return _res;
1693}
1694
1695static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1696 PyObject *_self;
1697 PyObject *_args;
1698{
1699 PyObject *_res = NULL;
1700 OSErr _err;
1701 WindowPtr inWindow;
1702 ControlHandle outControl;
1703 if (!PyArg_ParseTuple(_args, "O&",
1704 WinObj_Convert, &inWindow))
1705 return NULL;
1706 _err = GetKeyboardFocus(inWindow,
1707 &outControl);
1708 if (_err != noErr) return PyMac_Error(_err);
1709 _res = Py_BuildValue("O&",
1710 CtlObj_WhichControl, outControl);
1711 return _res;
1712}
1713
1714static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1715 PyObject *_self;
1716 PyObject *_args;
1717{
1718 PyObject *_res = NULL;
1719 OSErr _err;
1720 WindowPtr inWindow;
1721 ControlHandle inControl;
1722 ControlFocusPart inPart;
1723 if (!PyArg_ParseTuple(_args, "O&O&h",
1724 WinObj_Convert, &inWindow,
1725 CtlObj_Convert, &inControl,
1726 &inPart))
1727 return NULL;
1728 _err = SetKeyboardFocus(inWindow,
1729 inControl,
1730 inPart);
1731 if (_err != noErr) return PyMac_Error(_err);
1732 Py_INCREF(Py_None);
1733 _res = Py_None;
1734 return _res;
1735}
1736
1737static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1738 PyObject *_self;
1739 PyObject *_args;
1740{
1741 PyObject *_res = NULL;
1742 OSErr _err;
1743 WindowPtr inWindow;
1744 if (!PyArg_ParseTuple(_args, "O&",
1745 WinObj_Convert, &inWindow))
1746 return NULL;
1747 _err = AdvanceKeyboardFocus(inWindow);
1748 if (_err != noErr) return PyMac_Error(_err);
1749 Py_INCREF(Py_None);
1750 _res = Py_None;
1751 return _res;
1752}
1753
1754static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1755 PyObject *_self;
1756 PyObject *_args;
1757{
1758 PyObject *_res = NULL;
1759 OSErr _err;
1760 WindowPtr inWindow;
1761 if (!PyArg_ParseTuple(_args, "O&",
1762 WinObj_Convert, &inWindow))
1763 return NULL;
1764 _err = ReverseKeyboardFocus(inWindow);
1765 if (_err != noErr) return PyMac_Error(_err);
1766 Py_INCREF(Py_None);
1767 _res = Py_None;
1768 return _res;
1769}
1770
1771static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1772 PyObject *_self;
1773 PyObject *_args;
1774{
1775 PyObject *_res = NULL;
1776 OSErr _err;
1777 WindowPtr inWindow;
1778 if (!PyArg_ParseTuple(_args, "O&",
1779 WinObj_Convert, &inWindow))
1780 return NULL;
1781 _err = ClearKeyboardFocus(inWindow);
1782 if (_err != noErr) return PyMac_Error(_err);
1783 Py_INCREF(Py_None);
1784 _res = Py_None;
1785 return _res;
1786}
1787
Jack Jansene0581891999-02-07 14:02:03 +00001788static PyObject *Ctl_as_Control(_self, _args)
1789 PyObject *_self;
1790 PyObject *_args;
1791{
1792 PyObject *_res = NULL;
1793 ControlHandle _rv;
1794 Handle h;
1795 if (!PyArg_ParseTuple(_args, "O&",
1796 ResObj_Convert, &h))
1797 return NULL;
1798 _rv = as_Control(h);
1799 _res = Py_BuildValue("O&",
1800 CtlObj_New, _rv);
1801 return _res;
1802}
1803
Guido van Rossum17448e21995-01-30 11:53:55 +00001804static PyMethodDef Ctl_methods[] = {
1805 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001806 "(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 +00001807 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001808 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001809 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1810 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001811 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001812 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001813 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001814 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1815 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1816 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1817 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1818 "(WindowPtr inWindow) -> None"},
1819 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1820 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1821 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1822 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1823 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1824 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1825 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1826 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1827 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1828 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1829 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1830 "(WindowPtr inWindow) -> None"},
1831 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1832 "(WindowPtr inWindow) -> None"},
1833 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1834 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001835 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1836 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001837 {NULL, NULL, 0}
1838};
1839
1840
1841
Jack Jansen8387af61999-03-13 23:07:32 +00001842PyObject *CtlObj_NewUnmanaged(itself)
1843 ControlHandle itself;
1844{
1845 ControlObject *it;
1846 if (itself == NULL) return PyMac_Error(resNotFound);
1847 it = PyObject_NEW(ControlObject, &Control_Type);
1848 if (it == NULL) return NULL;
1849 it->ob_itself = itself;
1850 return (PyObject *)it;
1851}
1852
Guido van Rossum17448e21995-01-30 11:53:55 +00001853PyObject *
1854CtlObj_WhichControl(ControlHandle c)
1855{
1856 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00001857
Guido van Rossum17448e21995-01-30 11:53:55 +00001858 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00001859 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00001860 else {
1861 it = (PyObject *) GetControlReference(c);
1862 /*
1863 ** If the refcon is zero or doesn't point back to the Python object
1864 ** the control is not ours. Return a temporary object.
1865 */
1866 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1867 return CtlObj_NewUnmanaged(c);
1868 }
Guido van Rossum17448e21995-01-30 11:53:55 +00001869 Py_INCREF(it);
1870 return it;
1871}
1872
Jack Jansen848250c1998-05-28 14:20:09 +00001873static int
1874settrackfunc(obj)
1875 PyObject *obj;
1876{
1877 if (tracker) {
1878 PyErr_SetString(Ctl_Error, "Tracker function in use");
1879 return 0;
1880 }
1881 tracker = obj;
1882 Py_INCREF(tracker);
1883}
1884
1885static void
1886clrtrackfunc()
1887{
1888 Py_XDECREF(tracker);
1889 tracker = 0;
1890}
1891
1892static pascal void
1893mytracker(ctl, part)
1894 ControlHandle ctl;
1895 short part;
1896{
1897 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00001898
Jack Jansen848250c1998-05-28 14:20:09 +00001899 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1900 if (args && tracker) {
1901 rv = PyEval_CallObject(tracker, args);
1902 Py_DECREF(args);
1903 }
1904 if (rv)
1905 Py_DECREF(rv);
1906 else
Jack Jansen24c35311999-12-09 22:49:51 +00001907 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001908}
1909
Guido van Rossum17448e21995-01-30 11:53:55 +00001910
1911void initCtl()
1912{
1913 PyObject *m;
1914 PyObject *d;
1915
1916
1917
Jack Jansen848250c1998-05-28 14:20:09 +00001918 mytracker_upp = NewControlActionProc(mytracker);
1919
Guido van Rossum17448e21995-01-30 11:53:55 +00001920
1921 m = Py_InitModule("Ctl", Ctl_methods);
1922 d = PyModule_GetDict(m);
1923 Ctl_Error = PyMac_GetOSErrException();
1924 if (Ctl_Error == NULL ||
1925 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1926 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001927 Control_Type.ob_type = &PyType_Type;
1928 Py_INCREF(&Control_Type);
1929 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1930 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001931}
1932
1933/* ========================= End module Ctl ========================= */
1934