blob: 6b43b68975e73c4acff1528e21b461166346f53c [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
Jack Jansen4c704131998-06-19 13:35:14 +0000869static PyObject *CtlObj_GetPopupData(_self, _args)
870 ControlObject *_self;
871 PyObject *_args;
872{
873 PyObject *_res = NULL;
874
875 PopupPrivateDataHandle hdl;
876
877 if ( (*_self->ob_itself)->contrlData == NULL ) {
878 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
879 return 0;
880 }
881 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
882 HLock((Handle)hdl);
883 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
884 HUnlock((Handle)hdl);
885 return _res;
886
887}
888
889static PyObject *CtlObj_SetPopupData(_self, _args)
890 ControlObject *_self;
891 PyObject *_args;
892{
893 PyObject *_res = NULL;
894
895 PopupPrivateDataHandle hdl;
896 MenuHandle mHandle;
897 short mID;
898
899 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
900 return 0;
901 if ( (*_self->ob_itself)->contrlData == NULL ) {
902 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
903 return 0;
904 }
905 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
906 (*hdl)->mHandle = mHandle;
907 (*hdl)->mID = mID;
908 Py_INCREF(Py_None);
909 return Py_None;
910
911}
912
Guido van Rossum17448e21995-01-30 11:53:55 +0000913static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +0000914 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
915 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000916 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
917 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000918 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
919 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000920 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
921 "() -> (Boolean _rv)"},
922 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
923 "() -> (Boolean _rv)"},
924 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
925 "() -> None"},
926 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
927 "() -> None"},
928 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
929 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000930 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
931 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000932 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
933 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
934 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
935 "(ControlFontStyleRec inStyle) -> None"},
936 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
937 "() -> None"},
938 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
939 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000940 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000941 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000942 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000943 "(Point testPoint) -> (ControlPartCode _rv)"},
944 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
945 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000946 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000947 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000948 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000949 "(SInt16 w, SInt16 h) -> None"},
950 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
951 "(Str255 title) -> None"},
952 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
953 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000954 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000955 "() -> (SInt16 _rv)"},
956 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
957 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000958 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000959 "() -> (SInt16 _rv)"},
960 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
961 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000962 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000963 "() -> (SInt16 _rv)"},
964 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
965 "(SInt16 newMaximum) -> None"},
966 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000967 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000968 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
969 "(SInt32 data) -> None"},
970 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
971 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +0000972 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
973 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
974 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
975 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000976 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
977 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
978 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
979 "(ControlHandle inContainer) -> None"},
980 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
981 "(WindowPtr inWindow) -> None"},
982 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
983 "() -> (ControlHandle outParent)"},
984 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
985 "() -> (SInt16 outNumChildren)"},
986 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
987 "(SInt16 inIndex) -> (ControlHandle outSubControl)"},
988 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
989 "(ControlHandle inBoss) -> None"},
990 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
991 "() -> (UInt32 outFeatures)"},
992 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
993 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000994 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
995 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +0000996 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
997 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +0000998 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
999 NULL},
Jack Jansen4c704131998-06-19 13:35:14 +00001000 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1001 NULL},
1002 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1003 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001004 {NULL, NULL, 0}
1005};
1006
1007PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1008
1009static PyObject *CtlObj_getattr(self, name)
1010 ControlObject *self;
1011 char *name;
1012{
1013 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1014}
1015
1016#define CtlObj_setattr NULL
1017
1018PyTypeObject Control_Type = {
1019 PyObject_HEAD_INIT(&PyType_Type)
1020 0, /*ob_size*/
1021 "Control", /*tp_name*/
1022 sizeof(ControlObject), /*tp_basicsize*/
1023 0, /*tp_itemsize*/
1024 /* methods */
1025 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1026 0, /*tp_print*/
1027 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1028 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
1029};
1030
1031/* -------------------- End object type Control --------------------- */
1032
1033
1034static PyObject *Ctl_NewControl(_self, _args)
1035 PyObject *_self;
1036 PyObject *_args;
1037{
1038 PyObject *_res = NULL;
1039 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001040 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001041 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001042 Str255 controlTitle;
1043 Boolean initiallyVisible;
1044 SInt16 initialValue;
1045 SInt16 minimumValue;
1046 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001047 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001048 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001049 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001050 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001051 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001052 PyMac_GetStr255, controlTitle,
1053 &initiallyVisible,
1054 &initialValue,
1055 &minimumValue,
1056 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001057 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001058 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001059 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001060 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001061 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001062 controlTitle,
1063 initiallyVisible,
1064 initialValue,
1065 minimumValue,
1066 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001067 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001068 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001069 _res = Py_BuildValue("O&",
1070 CtlObj_New, _rv);
1071 return _res;
1072}
1073
1074static PyObject *Ctl_GetNewControl(_self, _args)
1075 PyObject *_self;
1076 PyObject *_args;
1077{
1078 PyObject *_res = NULL;
1079 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001080 SInt16 resourceID;
1081 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001082 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001083 &resourceID,
1084 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001085 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001086 _rv = GetNewControl(resourceID,
1087 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001088 _res = Py_BuildValue("O&",
1089 CtlObj_New, _rv);
1090 return _res;
1091}
1092
Guido van Rossum17448e21995-01-30 11:53:55 +00001093static PyObject *Ctl_DrawControls(_self, _args)
1094 PyObject *_self;
1095 PyObject *_args;
1096{
1097 PyObject *_res = NULL;
1098 WindowPtr theWindow;
1099 if (!PyArg_ParseTuple(_args, "O&",
1100 WinObj_Convert, &theWindow))
1101 return NULL;
1102 DrawControls(theWindow);
1103 Py_INCREF(Py_None);
1104 _res = Py_None;
1105 return _res;
1106}
1107
Guido van Rossum17448e21995-01-30 11:53:55 +00001108static PyObject *Ctl_UpdateControls(_self, _args)
1109 PyObject *_self;
1110 PyObject *_args;
1111{
1112 PyObject *_res = NULL;
1113 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001114 RgnHandle updateRegion;
1115 if (!PyArg_ParseTuple(_args, "O&O&",
1116 WinObj_Convert, &theWindow,
1117 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001118 return NULL;
1119 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001120 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001121 Py_INCREF(Py_None);
1122 _res = Py_None;
1123 return _res;
1124}
1125
1126static PyObject *Ctl_FindControl(_self, _args)
1127 PyObject *_self;
1128 PyObject *_args;
1129{
1130 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001131 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001132 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001133 WindowPtr theWindow;
1134 ControlHandle theControl;
1135 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001136 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001137 WinObj_Convert, &theWindow))
1138 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001139 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001140 theWindow,
1141 &theControl);
1142 _res = Py_BuildValue("hO&",
1143 _rv,
1144 CtlObj_WhichControl, theControl);
1145 return _res;
1146}
1147
Jack Jansen21f96871998-02-20 16:02:09 +00001148static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1149 PyObject *_self;
1150 PyObject *_args;
1151{
1152 PyObject *_res = NULL;
1153 ControlHandle _rv;
1154 Point inWhere;
1155 WindowPtr inWindow;
1156 SInt16 outPart;
1157 if (!PyArg_ParseTuple(_args, "O&O&",
1158 PyMac_GetPoint, &inWhere,
1159 WinObj_Convert, &inWindow))
1160 return NULL;
1161 _rv = FindControlUnderMouse(inWhere,
1162 inWindow,
1163 &outPart);
1164 _res = Py_BuildValue("O&h",
1165 CtlObj_New, _rv,
1166 outPart);
1167 return _res;
1168}
1169
1170static PyObject *Ctl_IdleControls(_self, _args)
1171 PyObject *_self;
1172 PyObject *_args;
1173{
1174 PyObject *_res = NULL;
1175 WindowPtr inWindow;
1176 if (!PyArg_ParseTuple(_args, "O&",
1177 WinObj_Convert, &inWindow))
1178 return NULL;
1179 IdleControls(inWindow);
1180 Py_INCREF(Py_None);
1181 _res = Py_None;
1182 return _res;
1183}
1184
1185static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1186 PyObject *_self;
1187 PyObject *_args;
1188{
1189 PyObject *_res = NULL;
1190 OSErr _err;
1191 WindowPtr inWindow;
1192 FSSpec inDumpFile;
1193 if (!PyArg_ParseTuple(_args, "O&O&",
1194 WinObj_Convert, &inWindow,
1195 PyMac_GetFSSpec, &inDumpFile))
1196 return NULL;
1197 _err = DumpControlHierarchy(inWindow,
1198 &inDumpFile);
1199 if (_err != noErr) return PyMac_Error(_err);
1200 Py_INCREF(Py_None);
1201 _res = Py_None;
1202 return _res;
1203}
1204
1205static PyObject *Ctl_CreateRootControl(_self, _args)
1206 PyObject *_self;
1207 PyObject *_args;
1208{
1209 PyObject *_res = NULL;
1210 OSErr _err;
1211 WindowPtr inWindow;
1212 ControlHandle outControl;
1213 if (!PyArg_ParseTuple(_args, "O&",
1214 WinObj_Convert, &inWindow))
1215 return NULL;
1216 _err = CreateRootControl(inWindow,
1217 &outControl);
1218 if (_err != noErr) return PyMac_Error(_err);
1219 _res = Py_BuildValue("O&",
1220 CtlObj_WhichControl, outControl);
1221 return _res;
1222}
1223
1224static PyObject *Ctl_GetRootControl(_self, _args)
1225 PyObject *_self;
1226 PyObject *_args;
1227{
1228 PyObject *_res = NULL;
1229 OSErr _err;
1230 WindowPtr inWindow;
1231 ControlHandle outControl;
1232 if (!PyArg_ParseTuple(_args, "O&",
1233 WinObj_Convert, &inWindow))
1234 return NULL;
1235 _err = GetRootControl(inWindow,
1236 &outControl);
1237 if (_err != noErr) return PyMac_Error(_err);
1238 _res = Py_BuildValue("O&",
1239 CtlObj_WhichControl, outControl);
1240 return _res;
1241}
1242
1243static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1244 PyObject *_self;
1245 PyObject *_args;
1246{
1247 PyObject *_res = NULL;
1248 OSErr _err;
1249 WindowPtr inWindow;
1250 ControlHandle outControl;
1251 if (!PyArg_ParseTuple(_args, "O&",
1252 WinObj_Convert, &inWindow))
1253 return NULL;
1254 _err = GetKeyboardFocus(inWindow,
1255 &outControl);
1256 if (_err != noErr) return PyMac_Error(_err);
1257 _res = Py_BuildValue("O&",
1258 CtlObj_WhichControl, outControl);
1259 return _res;
1260}
1261
1262static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1263 PyObject *_self;
1264 PyObject *_args;
1265{
1266 PyObject *_res = NULL;
1267 OSErr _err;
1268 WindowPtr inWindow;
1269 ControlHandle inControl;
1270 ControlFocusPart inPart;
1271 if (!PyArg_ParseTuple(_args, "O&O&h",
1272 WinObj_Convert, &inWindow,
1273 CtlObj_Convert, &inControl,
1274 &inPart))
1275 return NULL;
1276 _err = SetKeyboardFocus(inWindow,
1277 inControl,
1278 inPart);
1279 if (_err != noErr) return PyMac_Error(_err);
1280 Py_INCREF(Py_None);
1281 _res = Py_None;
1282 return _res;
1283}
1284
1285static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1286 PyObject *_self;
1287 PyObject *_args;
1288{
1289 PyObject *_res = NULL;
1290 OSErr _err;
1291 WindowPtr inWindow;
1292 if (!PyArg_ParseTuple(_args, "O&",
1293 WinObj_Convert, &inWindow))
1294 return NULL;
1295 _err = AdvanceKeyboardFocus(inWindow);
1296 if (_err != noErr) return PyMac_Error(_err);
1297 Py_INCREF(Py_None);
1298 _res = Py_None;
1299 return _res;
1300}
1301
1302static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1303 PyObject *_self;
1304 PyObject *_args;
1305{
1306 PyObject *_res = NULL;
1307 OSErr _err;
1308 WindowPtr inWindow;
1309 if (!PyArg_ParseTuple(_args, "O&",
1310 WinObj_Convert, &inWindow))
1311 return NULL;
1312 _err = ReverseKeyboardFocus(inWindow);
1313 if (_err != noErr) return PyMac_Error(_err);
1314 Py_INCREF(Py_None);
1315 _res = Py_None;
1316 return _res;
1317}
1318
1319static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1320 PyObject *_self;
1321 PyObject *_args;
1322{
1323 PyObject *_res = NULL;
1324 OSErr _err;
1325 WindowPtr inWindow;
1326 if (!PyArg_ParseTuple(_args, "O&",
1327 WinObj_Convert, &inWindow))
1328 return NULL;
1329 _err = ClearKeyboardFocus(inWindow);
1330 if (_err != noErr) return PyMac_Error(_err);
1331 Py_INCREF(Py_None);
1332 _res = Py_None;
1333 return _res;
1334}
1335
Guido van Rossum17448e21995-01-30 11:53:55 +00001336static PyMethodDef Ctl_methods[] = {
1337 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001338 "(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 +00001339 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001340 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001341 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1342 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001343 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001344 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001345 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001346 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1347 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1348 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1349 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1350 "(WindowPtr inWindow) -> None"},
1351 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1352 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1353 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1354 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1355 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1356 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1357 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1358 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1359 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1360 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1361 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1362 "(WindowPtr inWindow) -> None"},
1363 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1364 "(WindowPtr inWindow) -> None"},
1365 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1366 "(WindowPtr inWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001367 {NULL, NULL, 0}
1368};
1369
1370
1371
1372PyObject *
1373CtlObj_WhichControl(ControlHandle c)
1374{
1375 PyObject *it;
1376
1377 /* XXX What if we find a control belonging to some other package? */
1378 if (c == NULL)
1379 it = NULL;
1380 else
Jack Jansen85ae4a81997-04-08 15:26:03 +00001381 it = (PyObject *) GetControlReference(c);
Guido van Rossum17448e21995-01-30 11:53:55 +00001382 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1383 it = Py_None;
1384 Py_INCREF(it);
1385 return it;
1386}
1387
Jack Jansen848250c1998-05-28 14:20:09 +00001388static int
1389settrackfunc(obj)
1390 PyObject *obj;
1391{
1392 if (tracker) {
1393 PyErr_SetString(Ctl_Error, "Tracker function in use");
1394 return 0;
1395 }
1396 tracker = obj;
1397 Py_INCREF(tracker);
1398}
1399
1400static void
1401clrtrackfunc()
1402{
1403 Py_XDECREF(tracker);
1404 tracker = 0;
1405}
1406
1407static pascal void
1408mytracker(ctl, part)
1409 ControlHandle ctl;
1410 short part;
1411{
1412 PyObject *args, *rv=0;
1413
1414 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1415 if (args && tracker) {
1416 rv = PyEval_CallObject(tracker, args);
1417 Py_DECREF(args);
1418 }
1419 if (rv)
1420 Py_DECREF(rv);
1421 else
1422 fprintf(stderr, "TrackControl: exception in tracker function\n");
1423}
1424
Guido van Rossum17448e21995-01-30 11:53:55 +00001425
1426void initCtl()
1427{
1428 PyObject *m;
1429 PyObject *d;
1430
1431
1432
Jack Jansen848250c1998-05-28 14:20:09 +00001433 mytracker_upp = NewControlActionProc(mytracker);
1434
Guido van Rossum17448e21995-01-30 11:53:55 +00001435
1436 m = Py_InitModule("Ctl", Ctl_methods);
1437 d = PyModule_GetDict(m);
1438 Ctl_Error = PyMac_GetOSErrException();
1439 if (Ctl_Error == NULL ||
1440 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1441 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001442 Control_Type.ob_type = &PyType_Type;
1443 Py_INCREF(&Control_Type);
1444 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1445 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001446}
1447
1448/* ========================= End module Ctl ========================= */
1449