blob: 071e140aade77be4af6dd4dd27129e8c7cc563f3 [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 Jansen4c704131998-06-19 13:35:14 +00001180static PyObject *CtlObj_GetPopupData(_self, _args)
1181 ControlObject *_self;
1182 PyObject *_args;
1183{
1184 PyObject *_res = NULL;
1185
1186 PopupPrivateDataHandle hdl;
1187
1188 if ( (*_self->ob_itself)->contrlData == NULL ) {
1189 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1190 return 0;
1191 }
1192 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1193 HLock((Handle)hdl);
1194 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1195 HUnlock((Handle)hdl);
1196 return _res;
1197
1198}
1199
1200static PyObject *CtlObj_SetPopupData(_self, _args)
1201 ControlObject *_self;
1202 PyObject *_args;
1203{
1204 PyObject *_res = NULL;
1205
1206 PopupPrivateDataHandle hdl;
1207 MenuHandle mHandle;
1208 short mID;
1209
1210 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1211 return 0;
1212 if ( (*_self->ob_itself)->contrlData == NULL ) {
1213 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1214 return 0;
1215 }
1216 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1217 (*hdl)->mHandle = mHandle;
1218 (*hdl)->mID = mID;
1219 Py_INCREF(Py_None);
1220 return Py_None;
1221
1222}
1223
Guido van Rossum17448e21995-01-30 11:53:55 +00001224static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001225 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1226 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001227 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1228 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001229 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1230 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001231 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1232 "() -> (Boolean _rv)"},
1233 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1234 "() -> (Boolean _rv)"},
1235 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1236 "() -> None"},
1237 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1238 "() -> None"},
1239 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1240 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001241 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1242 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001243 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1244 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1245 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1246 "(ControlFontStyleRec inStyle) -> None"},
1247 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1248 "() -> None"},
1249 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1250 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001251 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1252 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001253 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001254 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001255 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001256 "(Point testPoint) -> (ControlPartCode _rv)"},
1257 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1258 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001259 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001260 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001261 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001262 "(SInt16 w, SInt16 h) -> None"},
1263 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1264 "(Str255 title) -> None"},
1265 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001266 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001267 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001268 "() -> (SInt16 _rv)"},
1269 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1270 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001271 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001272 "() -> (SInt16 _rv)"},
1273 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1274 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001275 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001276 "() -> (SInt16 _rv)"},
1277 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1278 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001279 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1280 "() -> (SInt32 _rv)"},
1281 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1282 "(SInt32 newViewSize) -> None"},
1283 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1284 "() -> (SInt32 _rv)"},
1285 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1286 "(SInt32 newValue) -> None"},
1287 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1288 "() -> (SInt32 _rv)"},
1289 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1290 "(SInt32 newMaximum) -> None"},
1291 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1292 "() -> (SInt32 _rv)"},
1293 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1294 "(SInt32 newMinimum) -> None"},
1295 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1296 "() -> (Boolean _rv)"},
1297 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
1298 "(OSType propertyCreator, OSType propertyTag) -> None"},
1299 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
1300 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001301 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001302 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001303 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1304 "(SInt32 data) -> None"},
1305 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1306 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +00001307 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1308 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
1309 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1310 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001311 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1312 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1313 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1314 "(ControlHandle inContainer) -> None"},
1315 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1316 "(WindowPtr inWindow) -> None"},
1317 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1318 "() -> (ControlHandle outParent)"},
1319 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001320 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001321 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001322 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001323 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1324 "(ControlHandle inBoss) -> None"},
1325 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1326 "() -> (UInt32 outFeatures)"},
1327 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1328 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001329 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
1330 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001331 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1332 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001333 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001334 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1335 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1336 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1337 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1338 "(stuff) -> None"},
1339 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1340 "(part, type) -> String"},
Jack Jansen4c704131998-06-19 13:35:14 +00001341 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1342 NULL},
1343 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1344 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001345 {NULL, NULL, 0}
1346};
1347
1348PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1349
1350static PyObject *CtlObj_getattr(self, name)
1351 ControlObject *self;
1352 char *name;
1353{
1354 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1355}
1356
1357#define CtlObj_setattr NULL
1358
Jack Jansen8387af61999-03-13 23:07:32 +00001359static int CtlObj_compare(self, other)
1360 ControlObject *self, *other;
1361{
1362 unsigned long v, w;
1363
1364 if (!CtlObj_Check((PyObject *)other))
1365 {
1366 v=(unsigned long)self;
1367 w=(unsigned long)other;
1368 }
1369 else
1370 {
1371 v=(unsigned long)self->ob_itself;
1372 w=(unsigned long)other->ob_itself;
1373 }
1374 if( v < w ) return -1;
1375 if( v > w ) return 1;
1376 return 0;
1377}
1378
1379#define CtlObj_repr NULL
1380
1381static long CtlObj_hash(self)
1382 ControlObject *self;
1383{
1384 return (long)self->ob_itself;
1385}
1386
Guido van Rossum17448e21995-01-30 11:53:55 +00001387PyTypeObject Control_Type = {
1388 PyObject_HEAD_INIT(&PyType_Type)
1389 0, /*ob_size*/
1390 "Control", /*tp_name*/
1391 sizeof(ControlObject), /*tp_basicsize*/
1392 0, /*tp_itemsize*/
1393 /* methods */
1394 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1395 0, /*tp_print*/
1396 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1397 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001398 (cmpfunc) CtlObj_compare, /*tp_compare*/
1399 (reprfunc) CtlObj_repr, /*tp_repr*/
1400 (PyNumberMethods *)0, /* tp_as_number */
1401 (PySequenceMethods *)0, /* tp_as_sequence */
1402 (PyMappingMethods *)0, /* tp_as_mapping */
1403 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001404};
1405
1406/* -------------------- End object type Control --------------------- */
1407
1408
1409static PyObject *Ctl_NewControl(_self, _args)
1410 PyObject *_self;
1411 PyObject *_args;
1412{
1413 PyObject *_res = NULL;
1414 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001415 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001416 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001417 Str255 controlTitle;
1418 Boolean initiallyVisible;
1419 SInt16 initialValue;
1420 SInt16 minimumValue;
1421 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001422 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001423 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001424 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001425 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001426 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001427 PyMac_GetStr255, controlTitle,
1428 &initiallyVisible,
1429 &initialValue,
1430 &minimumValue,
1431 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001432 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001433 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001434 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001435 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001436 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001437 controlTitle,
1438 initiallyVisible,
1439 initialValue,
1440 minimumValue,
1441 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001442 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001443 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001444 _res = Py_BuildValue("O&",
1445 CtlObj_New, _rv);
1446 return _res;
1447}
1448
1449static PyObject *Ctl_GetNewControl(_self, _args)
1450 PyObject *_self;
1451 PyObject *_args;
1452{
1453 PyObject *_res = NULL;
1454 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001455 SInt16 resourceID;
1456 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001457 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001458 &resourceID,
1459 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001460 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001461 _rv = GetNewControl(resourceID,
1462 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001463 _res = Py_BuildValue("O&",
1464 CtlObj_New, _rv);
1465 return _res;
1466}
1467
Guido van Rossum17448e21995-01-30 11:53:55 +00001468static PyObject *Ctl_DrawControls(_self, _args)
1469 PyObject *_self;
1470 PyObject *_args;
1471{
1472 PyObject *_res = NULL;
1473 WindowPtr theWindow;
1474 if (!PyArg_ParseTuple(_args, "O&",
1475 WinObj_Convert, &theWindow))
1476 return NULL;
1477 DrawControls(theWindow);
1478 Py_INCREF(Py_None);
1479 _res = Py_None;
1480 return _res;
1481}
1482
Guido van Rossum17448e21995-01-30 11:53:55 +00001483static PyObject *Ctl_UpdateControls(_self, _args)
1484 PyObject *_self;
1485 PyObject *_args;
1486{
1487 PyObject *_res = NULL;
1488 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001489 RgnHandle updateRegion;
1490 if (!PyArg_ParseTuple(_args, "O&O&",
1491 WinObj_Convert, &theWindow,
1492 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001493 return NULL;
1494 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001495 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001496 Py_INCREF(Py_None);
1497 _res = Py_None;
1498 return _res;
1499}
1500
1501static PyObject *Ctl_FindControl(_self, _args)
1502 PyObject *_self;
1503 PyObject *_args;
1504{
1505 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001506 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001507 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001508 WindowPtr theWindow;
1509 ControlHandle theControl;
1510 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001511 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001512 WinObj_Convert, &theWindow))
1513 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001514 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001515 theWindow,
1516 &theControl);
1517 _res = Py_BuildValue("hO&",
1518 _rv,
1519 CtlObj_WhichControl, theControl);
1520 return _res;
1521}
1522
Jack Jansen21f96871998-02-20 16:02:09 +00001523static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1524 PyObject *_self;
1525 PyObject *_args;
1526{
1527 PyObject *_res = NULL;
1528 ControlHandle _rv;
1529 Point inWhere;
1530 WindowPtr inWindow;
1531 SInt16 outPart;
1532 if (!PyArg_ParseTuple(_args, "O&O&",
1533 PyMac_GetPoint, &inWhere,
1534 WinObj_Convert, &inWindow))
1535 return NULL;
1536 _rv = FindControlUnderMouse(inWhere,
1537 inWindow,
1538 &outPart);
1539 _res = Py_BuildValue("O&h",
1540 CtlObj_New, _rv,
1541 outPart);
1542 return _res;
1543}
1544
1545static PyObject *Ctl_IdleControls(_self, _args)
1546 PyObject *_self;
1547 PyObject *_args;
1548{
1549 PyObject *_res = NULL;
1550 WindowPtr inWindow;
1551 if (!PyArg_ParseTuple(_args, "O&",
1552 WinObj_Convert, &inWindow))
1553 return NULL;
1554 IdleControls(inWindow);
1555 Py_INCREF(Py_None);
1556 _res = Py_None;
1557 return _res;
1558}
1559
1560static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1561 PyObject *_self;
1562 PyObject *_args;
1563{
1564 PyObject *_res = NULL;
1565 OSErr _err;
1566 WindowPtr inWindow;
1567 FSSpec inDumpFile;
1568 if (!PyArg_ParseTuple(_args, "O&O&",
1569 WinObj_Convert, &inWindow,
1570 PyMac_GetFSSpec, &inDumpFile))
1571 return NULL;
1572 _err = DumpControlHierarchy(inWindow,
1573 &inDumpFile);
1574 if (_err != noErr) return PyMac_Error(_err);
1575 Py_INCREF(Py_None);
1576 _res = Py_None;
1577 return _res;
1578}
1579
1580static PyObject *Ctl_CreateRootControl(_self, _args)
1581 PyObject *_self;
1582 PyObject *_args;
1583{
1584 PyObject *_res = NULL;
1585 OSErr _err;
1586 WindowPtr inWindow;
1587 ControlHandle outControl;
1588 if (!PyArg_ParseTuple(_args, "O&",
1589 WinObj_Convert, &inWindow))
1590 return NULL;
1591 _err = CreateRootControl(inWindow,
1592 &outControl);
1593 if (_err != noErr) return PyMac_Error(_err);
1594 _res = Py_BuildValue("O&",
1595 CtlObj_WhichControl, outControl);
1596 return _res;
1597}
1598
1599static PyObject *Ctl_GetRootControl(_self, _args)
1600 PyObject *_self;
1601 PyObject *_args;
1602{
1603 PyObject *_res = NULL;
1604 OSErr _err;
1605 WindowPtr inWindow;
1606 ControlHandle outControl;
1607 if (!PyArg_ParseTuple(_args, "O&",
1608 WinObj_Convert, &inWindow))
1609 return NULL;
1610 _err = GetRootControl(inWindow,
1611 &outControl);
1612 if (_err != noErr) return PyMac_Error(_err);
1613 _res = Py_BuildValue("O&",
1614 CtlObj_WhichControl, outControl);
1615 return _res;
1616}
1617
1618static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1619 PyObject *_self;
1620 PyObject *_args;
1621{
1622 PyObject *_res = NULL;
1623 OSErr _err;
1624 WindowPtr inWindow;
1625 ControlHandle outControl;
1626 if (!PyArg_ParseTuple(_args, "O&",
1627 WinObj_Convert, &inWindow))
1628 return NULL;
1629 _err = GetKeyboardFocus(inWindow,
1630 &outControl);
1631 if (_err != noErr) return PyMac_Error(_err);
1632 _res = Py_BuildValue("O&",
1633 CtlObj_WhichControl, outControl);
1634 return _res;
1635}
1636
1637static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1638 PyObject *_self;
1639 PyObject *_args;
1640{
1641 PyObject *_res = NULL;
1642 OSErr _err;
1643 WindowPtr inWindow;
1644 ControlHandle inControl;
1645 ControlFocusPart inPart;
1646 if (!PyArg_ParseTuple(_args, "O&O&h",
1647 WinObj_Convert, &inWindow,
1648 CtlObj_Convert, &inControl,
1649 &inPart))
1650 return NULL;
1651 _err = SetKeyboardFocus(inWindow,
1652 inControl,
1653 inPart);
1654 if (_err != noErr) return PyMac_Error(_err);
1655 Py_INCREF(Py_None);
1656 _res = Py_None;
1657 return _res;
1658}
1659
1660static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1661 PyObject *_self;
1662 PyObject *_args;
1663{
1664 PyObject *_res = NULL;
1665 OSErr _err;
1666 WindowPtr inWindow;
1667 if (!PyArg_ParseTuple(_args, "O&",
1668 WinObj_Convert, &inWindow))
1669 return NULL;
1670 _err = AdvanceKeyboardFocus(inWindow);
1671 if (_err != noErr) return PyMac_Error(_err);
1672 Py_INCREF(Py_None);
1673 _res = Py_None;
1674 return _res;
1675}
1676
1677static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1678 PyObject *_self;
1679 PyObject *_args;
1680{
1681 PyObject *_res = NULL;
1682 OSErr _err;
1683 WindowPtr inWindow;
1684 if (!PyArg_ParseTuple(_args, "O&",
1685 WinObj_Convert, &inWindow))
1686 return NULL;
1687 _err = ReverseKeyboardFocus(inWindow);
1688 if (_err != noErr) return PyMac_Error(_err);
1689 Py_INCREF(Py_None);
1690 _res = Py_None;
1691 return _res;
1692}
1693
1694static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1695 PyObject *_self;
1696 PyObject *_args;
1697{
1698 PyObject *_res = NULL;
1699 OSErr _err;
1700 WindowPtr inWindow;
1701 if (!PyArg_ParseTuple(_args, "O&",
1702 WinObj_Convert, &inWindow))
1703 return NULL;
1704 _err = ClearKeyboardFocus(inWindow);
1705 if (_err != noErr) return PyMac_Error(_err);
1706 Py_INCREF(Py_None);
1707 _res = Py_None;
1708 return _res;
1709}
1710
Jack Jansene0581891999-02-07 14:02:03 +00001711static PyObject *Ctl_as_Control(_self, _args)
1712 PyObject *_self;
1713 PyObject *_args;
1714{
1715 PyObject *_res = NULL;
1716 ControlHandle _rv;
1717 Handle h;
1718 if (!PyArg_ParseTuple(_args, "O&",
1719 ResObj_Convert, &h))
1720 return NULL;
1721 _rv = as_Control(h);
1722 _res = Py_BuildValue("O&",
1723 CtlObj_New, _rv);
1724 return _res;
1725}
1726
Guido van Rossum17448e21995-01-30 11:53:55 +00001727static PyMethodDef Ctl_methods[] = {
1728 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001729 "(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 +00001730 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001731 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001732 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1733 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001734 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001735 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001736 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001737 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1738 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1739 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1740 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1741 "(WindowPtr inWindow) -> None"},
1742 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1743 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1744 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1745 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1746 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1747 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1748 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1749 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1750 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1751 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1752 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1753 "(WindowPtr inWindow) -> None"},
1754 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1755 "(WindowPtr inWindow) -> None"},
1756 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1757 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001758 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1759 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001760 {NULL, NULL, 0}
1761};
1762
1763
1764
Jack Jansen8387af61999-03-13 23:07:32 +00001765PyObject *CtlObj_NewUnmanaged(itself)
1766 ControlHandle itself;
1767{
1768 ControlObject *it;
1769 if (itself == NULL) return PyMac_Error(resNotFound);
1770 it = PyObject_NEW(ControlObject, &Control_Type);
1771 if (it == NULL) return NULL;
1772 it->ob_itself = itself;
1773 return (PyObject *)it;
1774}
1775
Guido van Rossum17448e21995-01-30 11:53:55 +00001776PyObject *
1777CtlObj_WhichControl(ControlHandle c)
1778{
1779 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00001780
Guido van Rossum17448e21995-01-30 11:53:55 +00001781 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00001782 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00001783 else {
1784 it = (PyObject *) GetControlReference(c);
1785 /*
1786 ** If the refcon is zero or doesn't point back to the Python object
1787 ** the control is not ours. Return a temporary object.
1788 */
1789 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1790 return CtlObj_NewUnmanaged(c);
1791 }
Guido van Rossum17448e21995-01-30 11:53:55 +00001792 Py_INCREF(it);
1793 return it;
1794}
1795
Jack Jansen848250c1998-05-28 14:20:09 +00001796static int
1797settrackfunc(obj)
1798 PyObject *obj;
1799{
1800 if (tracker) {
1801 PyErr_SetString(Ctl_Error, "Tracker function in use");
1802 return 0;
1803 }
1804 tracker = obj;
1805 Py_INCREF(tracker);
1806}
1807
1808static void
1809clrtrackfunc()
1810{
1811 Py_XDECREF(tracker);
1812 tracker = 0;
1813}
1814
1815static pascal void
1816mytracker(ctl, part)
1817 ControlHandle ctl;
1818 short part;
1819{
1820 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00001821
Jack Jansen848250c1998-05-28 14:20:09 +00001822 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1823 if (args && tracker) {
1824 rv = PyEval_CallObject(tracker, args);
1825 Py_DECREF(args);
1826 }
1827 if (rv)
1828 Py_DECREF(rv);
1829 else
Jack Jansen24c35311999-12-09 22:49:51 +00001830 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001831}
1832
Guido van Rossum17448e21995-01-30 11:53:55 +00001833
1834void initCtl()
1835{
1836 PyObject *m;
1837 PyObject *d;
1838
1839
1840
Jack Jansen848250c1998-05-28 14:20:09 +00001841 mytracker_upp = NewControlActionProc(mytracker);
1842
Guido van Rossum17448e21995-01-30 11:53:55 +00001843
1844 m = Py_InitModule("Ctl", Ctl_methods);
1845 d = PyModule_GetDict(m);
1846 Ctl_Error = PyMac_GetOSErrException();
1847 if (Ctl_Error == NULL ||
1848 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1849 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001850 Control_Type.ob_type = &PyType_Type;
1851 Py_INCREF(&Control_Type);
1852 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1853 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001854}
1855
1856/* ========================= End module Ctl ========================= */
1857