blob: bfa88a11b56f82bc1c4d210c5ed3440f86191d61 [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
47#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
48
49extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000050extern PyObject *QdRGB_New(RGBColorPtr);
51extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000052
53#ifdef THINK_C
54#define ControlActionUPP ProcPtr
55#endif
56
Jack Jansen21f96871998-02-20 16:02:09 +000057/*
58** Parse/generate ControlFontStyleRec records
59*/
60#if 0 /* Not needed */
61PyObject *ControlFontStyle_New(itself)
62 ControlFontStyleRec *itself;
63{
64
65 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
66 itself->size, itself->style, itself->mode, itself->just,
67 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
68}
69#endif
70
71ControlFontStyle_Convert(v, itself)
72 PyObject *v;
73 ControlFontStyleRec *itself;
74{
75 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
76 &itself->font, &itself->size, &itself->style, &itself->mode,
77 &itself->just, QdRGB_Convert, &itself->foreColor,
78 QdRGB_Convert, &itself->backColor);
79}
80
Jack Jansen848250c1998-05-28 14:20:09 +000081/* TrackControl callback support */
82static PyObject *tracker;
83static ControlActionUPP mytracker_upp;
84
85extern int settrackfunc(PyObject *); /* forward */
86extern void clrtrackfunc(void); /* forward */
87
Guido van Rossum17448e21995-01-30 11:53:55 +000088static PyObject *Ctl_Error;
89
90/* ---------------------- Object type Control ----------------------- */
91
92PyTypeObject Control_Type;
93
94#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
95
96typedef struct ControlObject {
97 PyObject_HEAD
98 ControlHandle ob_itself;
99} ControlObject;
100
101PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000102 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000103{
104 ControlObject *it;
105 if (itself == NULL) return PyMac_Error(resNotFound);
106 it = PyObject_NEW(ControlObject, &Control_Type);
107 if (it == NULL) return NULL;
108 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000109 SetControlReference(itself, (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000110 return (PyObject *)it;
111}
112CtlObj_Convert(v, p_itself)
113 PyObject *v;
114 ControlHandle *p_itself;
115{
116 if (!CtlObj_Check(v))
117 {
118 PyErr_SetString(PyExc_TypeError, "Control required");
119 return 0;
120 }
121 *p_itself = ((ControlObject *)v)->ob_itself;
122 return 1;
123}
124
125static void CtlObj_dealloc(self)
126 ControlObject *self;
127{
Jack Jansen85ae4a81997-04-08 15:26:03 +0000128 if (self->ob_itself) SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000129 PyMem_DEL(self);
130}
131
Jack Jansen21f96871998-02-20 16:02:09 +0000132static PyObject *CtlObj_HiliteControl(_self, _args)
133 ControlObject *_self;
134 PyObject *_args;
135{
136 PyObject *_res = NULL;
137 ControlPartCode hiliteState;
138 if (!PyArg_ParseTuple(_args, "h",
139 &hiliteState))
140 return NULL;
141 HiliteControl(_self->ob_itself,
142 hiliteState);
143 Py_INCREF(Py_None);
144 _res = Py_None;
145 return _res;
146}
147
Jack Jansen7d0bc831995-06-09 20:56:31 +0000148static PyObject *CtlObj_ShowControl(_self, _args)
149 ControlObject *_self;
150 PyObject *_args;
151{
152 PyObject *_res = NULL;
153 if (!PyArg_ParseTuple(_args, ""))
154 return NULL;
155 ShowControl(_self->ob_itself);
156 Py_INCREF(Py_None);
157 _res = Py_None;
158 return _res;
159}
160
161static PyObject *CtlObj_HideControl(_self, _args)
162 ControlObject *_self;
163 PyObject *_args;
164{
165 PyObject *_res = NULL;
166 if (!PyArg_ParseTuple(_args, ""))
167 return NULL;
168 HideControl(_self->ob_itself);
169 Py_INCREF(Py_None);
170 _res = Py_None;
171 return _res;
172}
173
Jack Jansen21f96871998-02-20 16:02:09 +0000174static PyObject *CtlObj_IsControlActive(_self, _args)
175 ControlObject *_self;
176 PyObject *_args;
177{
178 PyObject *_res = NULL;
179 Boolean _rv;
180 if (!PyArg_ParseTuple(_args, ""))
181 return NULL;
182 _rv = IsControlActive(_self->ob_itself);
183 _res = Py_BuildValue("b",
184 _rv);
185 return _res;
186}
187
188static PyObject *CtlObj_IsControlVisible(_self, _args)
189 ControlObject *_self;
190 PyObject *_args;
191{
192 PyObject *_res = NULL;
193 Boolean _rv;
194 if (!PyArg_ParseTuple(_args, ""))
195 return NULL;
196 _rv = IsControlVisible(_self->ob_itself);
197 _res = Py_BuildValue("b",
198 _rv);
199 return _res;
200}
201
202static PyObject *CtlObj_ActivateControl(_self, _args)
203 ControlObject *_self;
204 PyObject *_args;
205{
206 PyObject *_res = NULL;
207 OSErr _err;
208 if (!PyArg_ParseTuple(_args, ""))
209 return NULL;
210 _err = ActivateControl(_self->ob_itself);
211 if (_err != noErr) return PyMac_Error(_err);
212 Py_INCREF(Py_None);
213 _res = Py_None;
214 return _res;
215}
216
217static PyObject *CtlObj_DeactivateControl(_self, _args)
218 ControlObject *_self;
219 PyObject *_args;
220{
221 PyObject *_res = NULL;
222 OSErr _err;
223 if (!PyArg_ParseTuple(_args, ""))
224 return NULL;
225 _err = DeactivateControl(_self->ob_itself);
226 if (_err != noErr) return PyMac_Error(_err);
227 Py_INCREF(Py_None);
228 _res = Py_None;
229 return _res;
230}
231
232static PyObject *CtlObj_SetControlVisibility(_self, _args)
233 ControlObject *_self;
234 PyObject *_args;
235{
236 PyObject *_res = NULL;
237 OSErr _err;
238 Boolean inIsVisible;
239 Boolean inDoDraw;
240 if (!PyArg_ParseTuple(_args, "bb",
241 &inIsVisible,
242 &inDoDraw))
243 return NULL;
244 _err = SetControlVisibility(_self->ob_itself,
245 inIsVisible,
246 inDoDraw);
247 if (_err != noErr) return PyMac_Error(_err);
248 Py_INCREF(Py_None);
249 _res = Py_None;
250 return _res;
251}
252
Jack Jansen7d0bc831995-06-09 20:56:31 +0000253static PyObject *CtlObj_Draw1Control(_self, _args)
254 ControlObject *_self;
255 PyObject *_args;
256{
257 PyObject *_res = NULL;
258 if (!PyArg_ParseTuple(_args, ""))
259 return NULL;
260 Draw1Control(_self->ob_itself);
261 Py_INCREF(Py_None);
262 _res = Py_None;
263 return _res;
264}
265
Jack Jansen21f96871998-02-20 16:02:09 +0000266static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000267 ControlObject *_self;
268 PyObject *_args;
269{
270 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000271 OSErr _err;
272 Rect outRect;
273 SInt16 outBaseLineOffset;
274 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000275 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000276 _err = GetBestControlRect(_self->ob_itself,
277 &outRect,
278 &outBaseLineOffset);
279 if (_err != noErr) return PyMac_Error(_err);
280 _res = Py_BuildValue("O&h",
281 PyMac_BuildRect, &outRect,
282 outBaseLineOffset);
283 return _res;
284}
285
286static PyObject *CtlObj_SetControlFontStyle(_self, _args)
287 ControlObject *_self;
288 PyObject *_args;
289{
290 PyObject *_res = NULL;
291 OSErr _err;
292 ControlFontStyleRec inStyle;
293 if (!PyArg_ParseTuple(_args, "O&",
294 ControlFontStyle_Convert, &inStyle))
295 return NULL;
296 _err = SetControlFontStyle(_self->ob_itself,
297 &inStyle);
298 if (_err != noErr) return PyMac_Error(_err);
299 Py_INCREF(Py_None);
300 _res = Py_None;
301 return _res;
302}
303
304static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
305 ControlObject *_self;
306 PyObject *_args;
307{
308 PyObject *_res = NULL;
309 if (!PyArg_ParseTuple(_args, ""))
310 return NULL;
311 DrawControlInCurrentPort(_self->ob_itself);
312 Py_INCREF(Py_None);
313 _res = Py_None;
314 return _res;
315}
316
317static PyObject *CtlObj_SetUpControlBackground(_self, _args)
318 ControlObject *_self;
319 PyObject *_args;
320{
321 PyObject *_res = NULL;
322 OSErr _err;
323 SInt16 inDepth;
324 Boolean inIsColorDevice;
325 if (!PyArg_ParseTuple(_args, "hb",
326 &inDepth,
327 &inIsColorDevice))
328 return NULL;
329 _err = SetUpControlBackground(_self->ob_itself,
330 inDepth,
331 inIsColorDevice);
332 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000333 Py_INCREF(Py_None);
334 _res = Py_None;
335 return _res;
336}
337
Jack Jansen7d0bc831995-06-09 20:56:31 +0000338static PyObject *CtlObj_DragControl(_self, _args)
339 ControlObject *_self;
340 PyObject *_args;
341{
342 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000343 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000344 Rect limitRect;
345 Rect slopRect;
346 DragConstraint axis;
347 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000348 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000349 PyMac_GetRect, &limitRect,
350 PyMac_GetRect, &slopRect,
351 &axis))
352 return NULL;
353 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000354 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000355 &limitRect,
356 &slopRect,
357 axis);
358 Py_INCREF(Py_None);
359 _res = Py_None;
360 return _res;
361}
362
363static PyObject *CtlObj_TestControl(_self, _args)
364 ControlObject *_self;
365 PyObject *_args;
366{
367 PyObject *_res = NULL;
368 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000369 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000370 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000371 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000372 return NULL;
373 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000374 testPoint);
375 _res = Py_BuildValue("h",
376 _rv);
377 return _res;
378}
379
380static PyObject *CtlObj_HandleControlKey(_self, _args)
381 ControlObject *_self;
382 PyObject *_args;
383{
384 PyObject *_res = NULL;
385 SInt16 _rv;
386 SInt16 inKeyCode;
387 SInt16 inCharCode;
388 SInt16 inModifiers;
389 if (!PyArg_ParseTuple(_args, "hhh",
390 &inKeyCode,
391 &inCharCode,
392 &inModifiers))
393 return NULL;
394 _rv = HandleControlKey(_self->ob_itself,
395 inKeyCode,
396 inCharCode,
397 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000398 _res = Py_BuildValue("h",
399 _rv);
400 return _res;
401}
402
403static PyObject *CtlObj_MoveControl(_self, _args)
404 ControlObject *_self;
405 PyObject *_args;
406{
407 PyObject *_res = NULL;
408 SInt16 h;
409 SInt16 v;
410 if (!PyArg_ParseTuple(_args, "hh",
411 &h,
412 &v))
413 return NULL;
414 MoveControl(_self->ob_itself,
415 h,
416 v);
417 Py_INCREF(Py_None);
418 _res = Py_None;
419 return _res;
420}
421
422static PyObject *CtlObj_SizeControl(_self, _args)
423 ControlObject *_self;
424 PyObject *_args;
425{
426 PyObject *_res = NULL;
427 SInt16 w;
428 SInt16 h;
429 if (!PyArg_ParseTuple(_args, "hh",
430 &w,
431 &h))
432 return NULL;
433 SizeControl(_self->ob_itself,
434 w,
435 h);
436 Py_INCREF(Py_None);
437 _res = Py_None;
438 return _res;
439}
440
Jack Jansenae8a68f1995-06-06 12:55:40 +0000441static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000442 ControlObject *_self;
443 PyObject *_args;
444{
445 PyObject *_res = NULL;
446 Str255 title;
447 if (!PyArg_ParseTuple(_args, "O&",
448 PyMac_GetStr255, title))
449 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000450 SetControlTitle(_self->ob_itself,
451 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000452 Py_INCREF(Py_None);
453 _res = Py_None;
454 return _res;
455}
456
Jack Jansenae8a68f1995-06-06 12:55:40 +0000457static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000458 ControlObject *_self;
459 PyObject *_args;
460{
461 PyObject *_res = NULL;
462 Str255 title;
463 if (!PyArg_ParseTuple(_args, "O&",
464 PyMac_GetStr255, title))
465 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000466 GetControlTitle(_self->ob_itself,
467 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000468 Py_INCREF(Py_None);
469 _res = Py_None;
470 return _res;
471}
472
Jack Jansenae8a68f1995-06-06 12:55:40 +0000473static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000474 ControlObject *_self;
475 PyObject *_args;
476{
477 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000478 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000479 if (!PyArg_ParseTuple(_args, ""))
480 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000481 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000482 _res = Py_BuildValue("h",
483 _rv);
484 return _res;
485}
486
Jack Jansen7d0bc831995-06-09 20:56:31 +0000487static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000488 ControlObject *_self;
489 PyObject *_args;
490{
491 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000492 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000493 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000494 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000495 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000496 SetControlValue(_self->ob_itself,
497 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000498 Py_INCREF(Py_None);
499 _res = Py_None;
500 return _res;
501}
502
Jack Jansenae8a68f1995-06-06 12:55:40 +0000503static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000504 ControlObject *_self;
505 PyObject *_args;
506{
507 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000508 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000509 if (!PyArg_ParseTuple(_args, ""))
510 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000511 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000512 _res = Py_BuildValue("h",
513 _rv);
514 return _res;
515}
516
Jack Jansen7d0bc831995-06-09 20:56:31 +0000517static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000518 ControlObject *_self;
519 PyObject *_args;
520{
521 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000522 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000523 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000524 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000525 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000526 SetControlMinimum(_self->ob_itself,
527 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000528 Py_INCREF(Py_None);
529 _res = Py_None;
530 return _res;
531}
532
Jack Jansenae8a68f1995-06-06 12:55:40 +0000533static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000534 ControlObject *_self;
535 PyObject *_args;
536{
537 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000538 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000539 if (!PyArg_ParseTuple(_args, ""))
540 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000541 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000542 _res = Py_BuildValue("h",
543 _rv);
544 return _res;
545}
546
Jack Jansen7d0bc831995-06-09 20:56:31 +0000547static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000548 ControlObject *_self;
549 PyObject *_args;
550{
551 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000552 SInt16 newMaximum;
553 if (!PyArg_ParseTuple(_args, "h",
554 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000555 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000556 SetControlMaximum(_self->ob_itself,
557 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000558 Py_INCREF(Py_None);
559 _res = Py_None;
560 return _res;
561}
562
Jack Jansen7d0bc831995-06-09 20:56:31 +0000563static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000564 ControlObject *_self;
565 PyObject *_args;
566{
567 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000568 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000569 if (!PyArg_ParseTuple(_args, ""))
570 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000571 _rv = GetControlVariant(_self->ob_itself);
572 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000573 _rv);
574 return _res;
575}
576
Jack Jansen7d0bc831995-06-09 20:56:31 +0000577static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000578 ControlObject *_self;
579 PyObject *_args;
580{
581 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000582 SInt32 data;
583 if (!PyArg_ParseTuple(_args, "l",
584 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000585 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000586 SetControlReference(_self->ob_itself,
587 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000588 Py_INCREF(Py_None);
589 _res = Py_None;
590 return _res;
591}
592
Jack Jansen7d0bc831995-06-09 20:56:31 +0000593static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000594 ControlObject *_self;
595 PyObject *_args;
596{
597 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000598 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000599 if (!PyArg_ParseTuple(_args, ""))
600 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000601 _rv = GetControlReference(_self->ob_itself);
602 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000603 _rv);
604 return _res;
605}
606
Jack Jansenc7fefed1997-08-15 14:32:18 +0000607static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
608 ControlObject *_self;
609 PyObject *_args;
610{
611 PyObject *_res = NULL;
612 Boolean _rv;
613 AuxCtlHandle acHndl;
614 if (!PyArg_ParseTuple(_args, ""))
615 return NULL;
616 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
617 &acHndl);
618 _res = Py_BuildValue("bO&",
619 _rv,
620 ResObj_New, acHndl);
621 return _res;
622}
623
624static PyObject *CtlObj_SetControlColor(_self, _args)
625 ControlObject *_self;
626 PyObject *_args;
627{
628 PyObject *_res = NULL;
629 CCTabHandle newColorTable;
630 if (!PyArg_ParseTuple(_args, "O&",
631 ResObj_Convert, &newColorTable))
632 return NULL;
633 SetControlColor(_self->ob_itself,
634 newColorTable);
635 Py_INCREF(Py_None);
636 _res = Py_None;
637 return _res;
638}
639
Jack Jansen21f96871998-02-20 16:02:09 +0000640static PyObject *CtlObj_SendControlMessage(_self, _args)
641 ControlObject *_self;
642 PyObject *_args;
643{
644 PyObject *_res = NULL;
645 SInt32 _rv;
646 SInt16 inMessage;
647 SInt32 inParam;
648 if (!PyArg_ParseTuple(_args, "hl",
649 &inMessage,
650 &inParam))
651 return NULL;
652 _rv = SendControlMessage(_self->ob_itself,
653 inMessage,
654 inParam);
655 _res = Py_BuildValue("l",
656 _rv);
657 return _res;
658}
659
660static PyObject *CtlObj_EmbedControl(_self, _args)
661 ControlObject *_self;
662 PyObject *_args;
663{
664 PyObject *_res = NULL;
665 OSErr _err;
666 ControlHandle inContainer;
667 if (!PyArg_ParseTuple(_args, "O&",
668 CtlObj_Convert, &inContainer))
669 return NULL;
670 _err = EmbedControl(_self->ob_itself,
671 inContainer);
672 if (_err != noErr) return PyMac_Error(_err);
673 Py_INCREF(Py_None);
674 _res = Py_None;
675 return _res;
676}
677
678static PyObject *CtlObj_AutoEmbedControl(_self, _args)
679 ControlObject *_self;
680 PyObject *_args;
681{
682 PyObject *_res = NULL;
683 OSErr _err;
684 WindowPtr inWindow;
685 if (!PyArg_ParseTuple(_args, "O&",
686 WinObj_Convert, &inWindow))
687 return NULL;
688 _err = AutoEmbedControl(_self->ob_itself,
689 inWindow);
690 if (_err != noErr) return PyMac_Error(_err);
691 Py_INCREF(Py_None);
692 _res = Py_None;
693 return _res;
694}
695
696static PyObject *CtlObj_GetSuperControl(_self, _args)
697 ControlObject *_self;
698 PyObject *_args;
699{
700 PyObject *_res = NULL;
701 OSErr _err;
702 ControlHandle outParent;
703 if (!PyArg_ParseTuple(_args, ""))
704 return NULL;
705 _err = GetSuperControl(_self->ob_itself,
706 &outParent);
707 if (_err != noErr) return PyMac_Error(_err);
708 _res = Py_BuildValue("O&",
709 CtlObj_WhichControl, outParent);
710 return _res;
711}
712
713static PyObject *CtlObj_CountSubControls(_self, _args)
714 ControlObject *_self;
715 PyObject *_args;
716{
717 PyObject *_res = NULL;
718 OSErr _err;
719 SInt16 outNumChildren;
720 if (!PyArg_ParseTuple(_args, ""))
721 return NULL;
722 _err = CountSubControls(_self->ob_itself,
723 &outNumChildren);
724 if (_err != noErr) return PyMac_Error(_err);
725 _res = Py_BuildValue("h",
726 outNumChildren);
727 return _res;
728}
729
730static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
731 ControlObject *_self;
732 PyObject *_args;
733{
734 PyObject *_res = NULL;
735 OSErr _err;
736 SInt16 inIndex;
737 ControlHandle outSubControl;
738 if (!PyArg_ParseTuple(_args, "h",
739 &inIndex))
740 return NULL;
741 _err = GetIndexedSubControl(_self->ob_itself,
742 inIndex,
743 &outSubControl);
744 if (_err != noErr) return PyMac_Error(_err);
745 _res = Py_BuildValue("O&",
746 CtlObj_WhichControl, outSubControl);
747 return _res;
748}
749
750static PyObject *CtlObj_SetControlSupervisor(_self, _args)
751 ControlObject *_self;
752 PyObject *_args;
753{
754 PyObject *_res = NULL;
755 OSErr _err;
756 ControlHandle inBoss;
757 if (!PyArg_ParseTuple(_args, "O&",
758 CtlObj_Convert, &inBoss))
759 return NULL;
760 _err = SetControlSupervisor(_self->ob_itself,
761 inBoss);
762 if (_err != noErr) return PyMac_Error(_err);
763 Py_INCREF(Py_None);
764 _res = Py_None;
765 return _res;
766}
767
768static PyObject *CtlObj_GetControlFeatures(_self, _args)
769 ControlObject *_self;
770 PyObject *_args;
771{
772 PyObject *_res = NULL;
773 OSErr _err;
774 UInt32 outFeatures;
775 if (!PyArg_ParseTuple(_args, ""))
776 return NULL;
777 _err = GetControlFeatures(_self->ob_itself,
778 &outFeatures);
779 if (_err != noErr) return PyMac_Error(_err);
780 _res = Py_BuildValue("l",
781 outFeatures);
782 return _res;
783}
784
785static PyObject *CtlObj_GetControlDataSize(_self, _args)
786 ControlObject *_self;
787 PyObject *_args;
788{
789 PyObject *_res = NULL;
790 OSErr _err;
791 ControlPartCode inPart;
792 ResType inTagName;
793 Size outMaxSize;
794 if (!PyArg_ParseTuple(_args, "hO&",
795 &inPart,
796 PyMac_GetOSType, &inTagName))
797 return NULL;
798 _err = GetControlDataSize(_self->ob_itself,
799 inPart,
800 inTagName,
801 &outMaxSize);
802 if (_err != noErr) return PyMac_Error(_err);
803 _res = Py_BuildValue("l",
804 outMaxSize);
805 return _res;
806}
807
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000808static PyObject *CtlObj_as_Resource(_self, _args)
809 ControlObject *_self;
810 PyObject *_args;
811{
812 PyObject *_res = NULL;
813
814 return ResObj_New((Handle)_self->ob_itself);
815
816}
817
Jack Jansencfb60ee1996-10-01 10:46:46 +0000818static PyObject *CtlObj_DisposeControl(_self, _args)
819 ControlObject *_self;
820 PyObject *_args;
821{
822 PyObject *_res = NULL;
823
824 if (!PyArg_ParseTuple(_args, ""))
825 return NULL;
826 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +0000827 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +0000828 DisposeControl(_self->ob_itself);
829 _self->ob_itself = NULL;
830 }
831 Py_INCREF(Py_None);
832 _res = Py_None;
833 return _res;
834
835}
836
Jack Jansen848250c1998-05-28 14:20:09 +0000837static PyObject *CtlObj_TrackControl(_self, _args)
838 ControlObject *_self;
839 PyObject *_args;
840{
841 PyObject *_res = NULL;
842
843 ControlPartCode _rv;
844 Point startPoint;
845 ControlActionUPP upp = 0;
846 PyObject *callback = 0;
847
848 if (!PyArg_ParseTuple(_args, "O&|O",
849 PyMac_GetPoint, &startPoint, &callback))
850 return NULL;
851 if (callback && callback != Py_None) {
852 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
853 upp = (ControlActionUPP)-1;
854 else {
855 settrackfunc(callback);
856 upp = mytracker_upp;
857 }
858 }
859 _rv = TrackControl(_self->ob_itself,
860 startPoint,
861 upp);
862 clrtrackfunc();
863 _res = Py_BuildValue("h",
864 _rv);
865 return _res;
866
867}
868
Guido van Rossum17448e21995-01-30 11:53:55 +0000869static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +0000870 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
871 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000872 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
873 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000874 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
875 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000876 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
877 "() -> (Boolean _rv)"},
878 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
879 "() -> (Boolean _rv)"},
880 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
881 "() -> None"},
882 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
883 "() -> None"},
884 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
885 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000886 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
887 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000888 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
889 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
890 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
891 "(ControlFontStyleRec inStyle) -> None"},
892 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
893 "() -> None"},
894 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
895 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000896 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000897 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000898 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000899 "(Point testPoint) -> (ControlPartCode _rv)"},
900 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
901 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000902 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000903 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000904 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000905 "(SInt16 w, SInt16 h) -> None"},
906 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
907 "(Str255 title) -> None"},
908 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
909 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000910 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000911 "() -> (SInt16 _rv)"},
912 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
913 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000914 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000915 "() -> (SInt16 _rv)"},
916 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
917 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000918 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000919 "() -> (SInt16 _rv)"},
920 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
921 "(SInt16 newMaximum) -> None"},
922 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000923 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000924 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
925 "(SInt32 data) -> None"},
926 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
927 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +0000928 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
929 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
930 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
931 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000932 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
933 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
934 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
935 "(ControlHandle inContainer) -> None"},
936 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
937 "(WindowPtr inWindow) -> None"},
938 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
939 "() -> (ControlHandle outParent)"},
940 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
941 "() -> (SInt16 outNumChildren)"},
942 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
943 "(SInt16 inIndex) -> (ControlHandle outSubControl)"},
944 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
945 "(ControlHandle inBoss) -> None"},
946 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
947 "() -> (UInt32 outFeatures)"},
948 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
949 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000950 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
951 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +0000952 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
953 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +0000954 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
955 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +0000956 {NULL, NULL, 0}
957};
958
959PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
960
961static PyObject *CtlObj_getattr(self, name)
962 ControlObject *self;
963 char *name;
964{
965 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
966}
967
968#define CtlObj_setattr NULL
969
970PyTypeObject Control_Type = {
971 PyObject_HEAD_INIT(&PyType_Type)
972 0, /*ob_size*/
973 "Control", /*tp_name*/
974 sizeof(ControlObject), /*tp_basicsize*/
975 0, /*tp_itemsize*/
976 /* methods */
977 (destructor) CtlObj_dealloc, /*tp_dealloc*/
978 0, /*tp_print*/
979 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
980 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
981};
982
983/* -------------------- End object type Control --------------------- */
984
985
986static PyObject *Ctl_NewControl(_self, _args)
987 PyObject *_self;
988 PyObject *_args;
989{
990 PyObject *_res = NULL;
991 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000992 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +0000993 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +0000994 Str255 controlTitle;
995 Boolean initiallyVisible;
996 SInt16 initialValue;
997 SInt16 minimumValue;
998 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000999 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001000 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001001 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001002 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001003 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001004 PyMac_GetStr255, controlTitle,
1005 &initiallyVisible,
1006 &initialValue,
1007 &minimumValue,
1008 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001009 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001010 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001011 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001012 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001013 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001014 controlTitle,
1015 initiallyVisible,
1016 initialValue,
1017 minimumValue,
1018 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001019 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001020 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001021 _res = Py_BuildValue("O&",
1022 CtlObj_New, _rv);
1023 return _res;
1024}
1025
1026static PyObject *Ctl_GetNewControl(_self, _args)
1027 PyObject *_self;
1028 PyObject *_args;
1029{
1030 PyObject *_res = NULL;
1031 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001032 SInt16 resourceID;
1033 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001034 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001035 &resourceID,
1036 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001037 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001038 _rv = GetNewControl(resourceID,
1039 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001040 _res = Py_BuildValue("O&",
1041 CtlObj_New, _rv);
1042 return _res;
1043}
1044
Guido van Rossum17448e21995-01-30 11:53:55 +00001045static PyObject *Ctl_DrawControls(_self, _args)
1046 PyObject *_self;
1047 PyObject *_args;
1048{
1049 PyObject *_res = NULL;
1050 WindowPtr theWindow;
1051 if (!PyArg_ParseTuple(_args, "O&",
1052 WinObj_Convert, &theWindow))
1053 return NULL;
1054 DrawControls(theWindow);
1055 Py_INCREF(Py_None);
1056 _res = Py_None;
1057 return _res;
1058}
1059
Guido van Rossum17448e21995-01-30 11:53:55 +00001060static PyObject *Ctl_UpdateControls(_self, _args)
1061 PyObject *_self;
1062 PyObject *_args;
1063{
1064 PyObject *_res = NULL;
1065 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001066 RgnHandle updateRegion;
1067 if (!PyArg_ParseTuple(_args, "O&O&",
1068 WinObj_Convert, &theWindow,
1069 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001070 return NULL;
1071 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001072 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001073 Py_INCREF(Py_None);
1074 _res = Py_None;
1075 return _res;
1076}
1077
1078static PyObject *Ctl_FindControl(_self, _args)
1079 PyObject *_self;
1080 PyObject *_args;
1081{
1082 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001083 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001084 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001085 WindowPtr theWindow;
1086 ControlHandle theControl;
1087 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001088 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001089 WinObj_Convert, &theWindow))
1090 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001091 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001092 theWindow,
1093 &theControl);
1094 _res = Py_BuildValue("hO&",
1095 _rv,
1096 CtlObj_WhichControl, theControl);
1097 return _res;
1098}
1099
Jack Jansen21f96871998-02-20 16:02:09 +00001100static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1101 PyObject *_self;
1102 PyObject *_args;
1103{
1104 PyObject *_res = NULL;
1105 ControlHandle _rv;
1106 Point inWhere;
1107 WindowPtr inWindow;
1108 SInt16 outPart;
1109 if (!PyArg_ParseTuple(_args, "O&O&",
1110 PyMac_GetPoint, &inWhere,
1111 WinObj_Convert, &inWindow))
1112 return NULL;
1113 _rv = FindControlUnderMouse(inWhere,
1114 inWindow,
1115 &outPart);
1116 _res = Py_BuildValue("O&h",
1117 CtlObj_New, _rv,
1118 outPart);
1119 return _res;
1120}
1121
1122static PyObject *Ctl_IdleControls(_self, _args)
1123 PyObject *_self;
1124 PyObject *_args;
1125{
1126 PyObject *_res = NULL;
1127 WindowPtr inWindow;
1128 if (!PyArg_ParseTuple(_args, "O&",
1129 WinObj_Convert, &inWindow))
1130 return NULL;
1131 IdleControls(inWindow);
1132 Py_INCREF(Py_None);
1133 _res = Py_None;
1134 return _res;
1135}
1136
1137static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1138 PyObject *_self;
1139 PyObject *_args;
1140{
1141 PyObject *_res = NULL;
1142 OSErr _err;
1143 WindowPtr inWindow;
1144 FSSpec inDumpFile;
1145 if (!PyArg_ParseTuple(_args, "O&O&",
1146 WinObj_Convert, &inWindow,
1147 PyMac_GetFSSpec, &inDumpFile))
1148 return NULL;
1149 _err = DumpControlHierarchy(inWindow,
1150 &inDumpFile);
1151 if (_err != noErr) return PyMac_Error(_err);
1152 Py_INCREF(Py_None);
1153 _res = Py_None;
1154 return _res;
1155}
1156
1157static PyObject *Ctl_CreateRootControl(_self, _args)
1158 PyObject *_self;
1159 PyObject *_args;
1160{
1161 PyObject *_res = NULL;
1162 OSErr _err;
1163 WindowPtr inWindow;
1164 ControlHandle outControl;
1165 if (!PyArg_ParseTuple(_args, "O&",
1166 WinObj_Convert, &inWindow))
1167 return NULL;
1168 _err = CreateRootControl(inWindow,
1169 &outControl);
1170 if (_err != noErr) return PyMac_Error(_err);
1171 _res = Py_BuildValue("O&",
1172 CtlObj_WhichControl, outControl);
1173 return _res;
1174}
1175
1176static PyObject *Ctl_GetRootControl(_self, _args)
1177 PyObject *_self;
1178 PyObject *_args;
1179{
1180 PyObject *_res = NULL;
1181 OSErr _err;
1182 WindowPtr inWindow;
1183 ControlHandle outControl;
1184 if (!PyArg_ParseTuple(_args, "O&",
1185 WinObj_Convert, &inWindow))
1186 return NULL;
1187 _err = GetRootControl(inWindow,
1188 &outControl);
1189 if (_err != noErr) return PyMac_Error(_err);
1190 _res = Py_BuildValue("O&",
1191 CtlObj_WhichControl, outControl);
1192 return _res;
1193}
1194
1195static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1196 PyObject *_self;
1197 PyObject *_args;
1198{
1199 PyObject *_res = NULL;
1200 OSErr _err;
1201 WindowPtr inWindow;
1202 ControlHandle outControl;
1203 if (!PyArg_ParseTuple(_args, "O&",
1204 WinObj_Convert, &inWindow))
1205 return NULL;
1206 _err = GetKeyboardFocus(inWindow,
1207 &outControl);
1208 if (_err != noErr) return PyMac_Error(_err);
1209 _res = Py_BuildValue("O&",
1210 CtlObj_WhichControl, outControl);
1211 return _res;
1212}
1213
1214static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1215 PyObject *_self;
1216 PyObject *_args;
1217{
1218 PyObject *_res = NULL;
1219 OSErr _err;
1220 WindowPtr inWindow;
1221 ControlHandle inControl;
1222 ControlFocusPart inPart;
1223 if (!PyArg_ParseTuple(_args, "O&O&h",
1224 WinObj_Convert, &inWindow,
1225 CtlObj_Convert, &inControl,
1226 &inPart))
1227 return NULL;
1228 _err = SetKeyboardFocus(inWindow,
1229 inControl,
1230 inPart);
1231 if (_err != noErr) return PyMac_Error(_err);
1232 Py_INCREF(Py_None);
1233 _res = Py_None;
1234 return _res;
1235}
1236
1237static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1238 PyObject *_self;
1239 PyObject *_args;
1240{
1241 PyObject *_res = NULL;
1242 OSErr _err;
1243 WindowPtr inWindow;
1244 if (!PyArg_ParseTuple(_args, "O&",
1245 WinObj_Convert, &inWindow))
1246 return NULL;
1247 _err = AdvanceKeyboardFocus(inWindow);
1248 if (_err != noErr) return PyMac_Error(_err);
1249 Py_INCREF(Py_None);
1250 _res = Py_None;
1251 return _res;
1252}
1253
1254static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1255 PyObject *_self;
1256 PyObject *_args;
1257{
1258 PyObject *_res = NULL;
1259 OSErr _err;
1260 WindowPtr inWindow;
1261 if (!PyArg_ParseTuple(_args, "O&",
1262 WinObj_Convert, &inWindow))
1263 return NULL;
1264 _err = ReverseKeyboardFocus(inWindow);
1265 if (_err != noErr) return PyMac_Error(_err);
1266 Py_INCREF(Py_None);
1267 _res = Py_None;
1268 return _res;
1269}
1270
1271static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1272 PyObject *_self;
1273 PyObject *_args;
1274{
1275 PyObject *_res = NULL;
1276 OSErr _err;
1277 WindowPtr inWindow;
1278 if (!PyArg_ParseTuple(_args, "O&",
1279 WinObj_Convert, &inWindow))
1280 return NULL;
1281 _err = ClearKeyboardFocus(inWindow);
1282 if (_err != noErr) return PyMac_Error(_err);
1283 Py_INCREF(Py_None);
1284 _res = Py_None;
1285 return _res;
1286}
1287
Guido van Rossum17448e21995-01-30 11:53:55 +00001288static PyMethodDef Ctl_methods[] = {
1289 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001290 "(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 +00001291 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001292 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001293 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1294 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001295 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001296 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001297 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001298 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1299 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1300 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1301 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1302 "(WindowPtr inWindow) -> None"},
1303 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1304 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1305 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1306 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1307 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1308 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1309 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1310 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1311 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1312 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1313 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1314 "(WindowPtr inWindow) -> None"},
1315 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1316 "(WindowPtr inWindow) -> None"},
1317 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1318 "(WindowPtr inWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001319 {NULL, NULL, 0}
1320};
1321
1322
1323
1324PyObject *
1325CtlObj_WhichControl(ControlHandle c)
1326{
1327 PyObject *it;
1328
1329 /* XXX What if we find a control belonging to some other package? */
1330 if (c == NULL)
1331 it = NULL;
1332 else
Jack Jansen85ae4a81997-04-08 15:26:03 +00001333 it = (PyObject *) GetControlReference(c);
Guido van Rossum17448e21995-01-30 11:53:55 +00001334 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1335 it = Py_None;
1336 Py_INCREF(it);
1337 return it;
1338}
1339
Jack Jansen848250c1998-05-28 14:20:09 +00001340static int
1341settrackfunc(obj)
1342 PyObject *obj;
1343{
1344 if (tracker) {
1345 PyErr_SetString(Ctl_Error, "Tracker function in use");
1346 return 0;
1347 }
1348 tracker = obj;
1349 Py_INCREF(tracker);
1350}
1351
1352static void
1353clrtrackfunc()
1354{
1355 Py_XDECREF(tracker);
1356 tracker = 0;
1357}
1358
1359static pascal void
1360mytracker(ctl, part)
1361 ControlHandle ctl;
1362 short part;
1363{
1364 PyObject *args, *rv=0;
1365
1366 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1367 if (args && tracker) {
1368 rv = PyEval_CallObject(tracker, args);
1369 Py_DECREF(args);
1370 }
1371 if (rv)
1372 Py_DECREF(rv);
1373 else
1374 fprintf(stderr, "TrackControl: exception in tracker function\n");
1375}
1376
Guido van Rossum17448e21995-01-30 11:53:55 +00001377
1378void initCtl()
1379{
1380 PyObject *m;
1381 PyObject *d;
1382
1383
1384
Jack Jansen848250c1998-05-28 14:20:09 +00001385 mytracker_upp = NewControlActionProc(mytracker);
1386
Guido van Rossum17448e21995-01-30 11:53:55 +00001387
1388 m = Py_InitModule("Ctl", Ctl_methods);
1389 d = PyModule_GetDict(m);
1390 Ctl_Error = PyMac_GetOSErrException();
1391 if (Ctl_Error == NULL ||
1392 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1393 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001394 Control_Type.ob_type = &PyType_Type;
1395 Py_INCREF(&Control_Type);
1396 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1397 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001398}
1399
1400/* ========================= End module Ctl ========================= */
1401