blob: 627ca8ff8debddc502600c5890d33de658098e68 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Ctl =========================== */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
17extern int ResObj_Convert(PyObject *, Handle *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000018extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
Guido van Rossum17448e21995-01-30 11:53:55 +000020
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000023extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
Guido van Rossum17448e21995-01-30 11:53:55 +000025
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
Jack Jansen425e9eb1995-12-12 15:02:03 +000037extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
Guido van Rossum17448e21995-01-30 11:53:55 +000043extern PyObject *WinObj_WhichWindow(WindowPtr);
44
45#include <Controls.h>
46
Jack Jansene0581891999-02-07 14:02:03 +000047#define as_Control(h) ((ControlHandle)h)
48
Guido van Rossum17448e21995-01-30 11:53:55 +000049#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
50
51extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000052extern PyObject *QdRGB_New(RGBColorPtr);
53extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000054
55#ifdef THINK_C
56#define ControlActionUPP ProcPtr
57#endif
58
Jack Jansen21f96871998-02-20 16:02:09 +000059/*
60** Parse/generate ControlFontStyleRec records
61*/
62#if 0 /* Not needed */
63PyObject *ControlFontStyle_New(itself)
64 ControlFontStyleRec *itself;
65{
66
67 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
68 itself->size, itself->style, itself->mode, itself->just,
69 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
70}
71#endif
72
73ControlFontStyle_Convert(v, itself)
74 PyObject *v;
75 ControlFontStyleRec *itself;
76{
77 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000078 &itself->font, &itself->size, &itself->style, &itself->mode,
79 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000080 QdRGB_Convert, &itself->backColor);
81}
82
Jack Jansen24c35311999-12-09 22:49:51 +000083/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000084static PyObject *tracker;
85static ControlActionUPP mytracker_upp;
86
87extern int settrackfunc(PyObject *); /* forward */
88extern void clrtrackfunc(void); /* forward */
89
Guido van Rossum17448e21995-01-30 11:53:55 +000090static PyObject *Ctl_Error;
91
92/* ---------------------- Object type Control ----------------------- */
93
94PyTypeObject Control_Type;
95
96#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
97
98typedef struct ControlObject {
99 PyObject_HEAD
100 ControlHandle ob_itself;
101} ControlObject;
102
103PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000104 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000105{
106 ControlObject *it;
107 if (itself == NULL) return PyMac_Error(resNotFound);
108 it = PyObject_NEW(ControlObject, &Control_Type);
109 if (it == NULL) return NULL;
110 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000111 SetControlReference(itself, (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000112 return (PyObject *)it;
113}
114CtlObj_Convert(v, p_itself)
115 PyObject *v;
116 ControlHandle *p_itself;
117{
118 if (!CtlObj_Check(v))
119 {
120 PyErr_SetString(PyExc_TypeError, "Control required");
121 return 0;
122 }
123 *p_itself = ((ControlObject *)v)->ob_itself;
124 return 1;
125}
126
127static void CtlObj_dealloc(self)
128 ControlObject *self;
129{
Jack Jansen24c35311999-12-09 22:49:51 +0000130 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000131 PyMem_DEL(self);
132}
133
Jack Jansen21f96871998-02-20 16:02:09 +0000134static PyObject *CtlObj_HiliteControl(_self, _args)
135 ControlObject *_self;
136 PyObject *_args;
137{
138 PyObject *_res = NULL;
139 ControlPartCode hiliteState;
140 if (!PyArg_ParseTuple(_args, "h",
141 &hiliteState))
142 return NULL;
143 HiliteControl(_self->ob_itself,
144 hiliteState);
145 Py_INCREF(Py_None);
146 _res = Py_None;
147 return _res;
148}
149
Jack Jansen7d0bc831995-06-09 20:56:31 +0000150static PyObject *CtlObj_ShowControl(_self, _args)
151 ControlObject *_self;
152 PyObject *_args;
153{
154 PyObject *_res = NULL;
155 if (!PyArg_ParseTuple(_args, ""))
156 return NULL;
157 ShowControl(_self->ob_itself);
158 Py_INCREF(Py_None);
159 _res = Py_None;
160 return _res;
161}
162
163static PyObject *CtlObj_HideControl(_self, _args)
164 ControlObject *_self;
165 PyObject *_args;
166{
167 PyObject *_res = NULL;
168 if (!PyArg_ParseTuple(_args, ""))
169 return NULL;
170 HideControl(_self->ob_itself);
171 Py_INCREF(Py_None);
172 _res = Py_None;
173 return _res;
174}
175
Jack Jansen21f96871998-02-20 16:02:09 +0000176static PyObject *CtlObj_IsControlActive(_self, _args)
177 ControlObject *_self;
178 PyObject *_args;
179{
180 PyObject *_res = NULL;
181 Boolean _rv;
182 if (!PyArg_ParseTuple(_args, ""))
183 return NULL;
184 _rv = IsControlActive(_self->ob_itself);
185 _res = Py_BuildValue("b",
186 _rv);
187 return _res;
188}
189
190static PyObject *CtlObj_IsControlVisible(_self, _args)
191 ControlObject *_self;
192 PyObject *_args;
193{
194 PyObject *_res = NULL;
195 Boolean _rv;
196 if (!PyArg_ParseTuple(_args, ""))
197 return NULL;
198 _rv = IsControlVisible(_self->ob_itself);
199 _res = Py_BuildValue("b",
200 _rv);
201 return _res;
202}
203
204static PyObject *CtlObj_ActivateControl(_self, _args)
205 ControlObject *_self;
206 PyObject *_args;
207{
208 PyObject *_res = NULL;
209 OSErr _err;
210 if (!PyArg_ParseTuple(_args, ""))
211 return NULL;
212 _err = ActivateControl(_self->ob_itself);
213 if (_err != noErr) return PyMac_Error(_err);
214 Py_INCREF(Py_None);
215 _res = Py_None;
216 return _res;
217}
218
219static PyObject *CtlObj_DeactivateControl(_self, _args)
220 ControlObject *_self;
221 PyObject *_args;
222{
223 PyObject *_res = NULL;
224 OSErr _err;
225 if (!PyArg_ParseTuple(_args, ""))
226 return NULL;
227 _err = DeactivateControl(_self->ob_itself);
228 if (_err != noErr) return PyMac_Error(_err);
229 Py_INCREF(Py_None);
230 _res = Py_None;
231 return _res;
232}
233
234static PyObject *CtlObj_SetControlVisibility(_self, _args)
235 ControlObject *_self;
236 PyObject *_args;
237{
238 PyObject *_res = NULL;
239 OSErr _err;
240 Boolean inIsVisible;
241 Boolean inDoDraw;
242 if (!PyArg_ParseTuple(_args, "bb",
243 &inIsVisible,
244 &inDoDraw))
245 return NULL;
246 _err = SetControlVisibility(_self->ob_itself,
247 inIsVisible,
248 inDoDraw);
249 if (_err != noErr) return PyMac_Error(_err);
250 Py_INCREF(Py_None);
251 _res = Py_None;
252 return _res;
253}
254
Jack Jansen7d0bc831995-06-09 20:56:31 +0000255static PyObject *CtlObj_Draw1Control(_self, _args)
256 ControlObject *_self;
257 PyObject *_args;
258{
259 PyObject *_res = NULL;
260 if (!PyArg_ParseTuple(_args, ""))
261 return NULL;
262 Draw1Control(_self->ob_itself);
263 Py_INCREF(Py_None);
264 _res = Py_None;
265 return _res;
266}
267
Jack Jansen21f96871998-02-20 16:02:09 +0000268static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000269 ControlObject *_self;
270 PyObject *_args;
271{
272 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000273 OSErr _err;
274 Rect outRect;
275 SInt16 outBaseLineOffset;
276 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000277 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000278 _err = GetBestControlRect(_self->ob_itself,
279 &outRect,
280 &outBaseLineOffset);
281 if (_err != noErr) return PyMac_Error(_err);
282 _res = Py_BuildValue("O&h",
283 PyMac_BuildRect, &outRect,
284 outBaseLineOffset);
285 return _res;
286}
287
288static PyObject *CtlObj_SetControlFontStyle(_self, _args)
289 ControlObject *_self;
290 PyObject *_args;
291{
292 PyObject *_res = NULL;
293 OSErr _err;
294 ControlFontStyleRec inStyle;
295 if (!PyArg_ParseTuple(_args, "O&",
296 ControlFontStyle_Convert, &inStyle))
297 return NULL;
298 _err = SetControlFontStyle(_self->ob_itself,
299 &inStyle);
300 if (_err != noErr) return PyMac_Error(_err);
301 Py_INCREF(Py_None);
302 _res = Py_None;
303 return _res;
304}
305
306static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
307 ControlObject *_self;
308 PyObject *_args;
309{
310 PyObject *_res = NULL;
311 if (!PyArg_ParseTuple(_args, ""))
312 return NULL;
313 DrawControlInCurrentPort(_self->ob_itself);
314 Py_INCREF(Py_None);
315 _res = Py_None;
316 return _res;
317}
318
319static PyObject *CtlObj_SetUpControlBackground(_self, _args)
320 ControlObject *_self;
321 PyObject *_args;
322{
323 PyObject *_res = NULL;
324 OSErr _err;
325 SInt16 inDepth;
326 Boolean inIsColorDevice;
327 if (!PyArg_ParseTuple(_args, "hb",
328 &inDepth,
329 &inIsColorDevice))
330 return NULL;
331 _err = SetUpControlBackground(_self->ob_itself,
332 inDepth,
333 inIsColorDevice);
334 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000335 Py_INCREF(Py_None);
336 _res = Py_None;
337 return _res;
338}
339
Jack Jansen7d0bc831995-06-09 20:56:31 +0000340static PyObject *CtlObj_DragControl(_self, _args)
341 ControlObject *_self;
342 PyObject *_args;
343{
344 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000345 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000346 Rect limitRect;
347 Rect slopRect;
348 DragConstraint axis;
349 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000350 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000351 PyMac_GetRect, &limitRect,
352 PyMac_GetRect, &slopRect,
353 &axis))
354 return NULL;
355 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000356 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000357 &limitRect,
358 &slopRect,
359 axis);
360 Py_INCREF(Py_None);
361 _res = Py_None;
362 return _res;
363}
364
365static PyObject *CtlObj_TestControl(_self, _args)
366 ControlObject *_self;
367 PyObject *_args;
368{
369 PyObject *_res = NULL;
370 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000371 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000372 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000373 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000374 return NULL;
375 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000376 testPoint);
377 _res = Py_BuildValue("h",
378 _rv);
379 return _res;
380}
381
382static PyObject *CtlObj_HandleControlKey(_self, _args)
383 ControlObject *_self;
384 PyObject *_args;
385{
386 PyObject *_res = NULL;
387 SInt16 _rv;
388 SInt16 inKeyCode;
389 SInt16 inCharCode;
390 SInt16 inModifiers;
391 if (!PyArg_ParseTuple(_args, "hhh",
392 &inKeyCode,
393 &inCharCode,
394 &inModifiers))
395 return NULL;
396 _rv = HandleControlKey(_self->ob_itself,
397 inKeyCode,
398 inCharCode,
399 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000400 _res = Py_BuildValue("h",
401 _rv);
402 return _res;
403}
404
405static PyObject *CtlObj_MoveControl(_self, _args)
406 ControlObject *_self;
407 PyObject *_args;
408{
409 PyObject *_res = NULL;
410 SInt16 h;
411 SInt16 v;
412 if (!PyArg_ParseTuple(_args, "hh",
413 &h,
414 &v))
415 return NULL;
416 MoveControl(_self->ob_itself,
417 h,
418 v);
419 Py_INCREF(Py_None);
420 _res = Py_None;
421 return _res;
422}
423
424static PyObject *CtlObj_SizeControl(_self, _args)
425 ControlObject *_self;
426 PyObject *_args;
427{
428 PyObject *_res = NULL;
429 SInt16 w;
430 SInt16 h;
431 if (!PyArg_ParseTuple(_args, "hh",
432 &w,
433 &h))
434 return NULL;
435 SizeControl(_self->ob_itself,
436 w,
437 h);
438 Py_INCREF(Py_None);
439 _res = Py_None;
440 return _res;
441}
442
Jack Jansenae8a68f1995-06-06 12:55:40 +0000443static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000444 ControlObject *_self;
445 PyObject *_args;
446{
447 PyObject *_res = NULL;
448 Str255 title;
449 if (!PyArg_ParseTuple(_args, "O&",
450 PyMac_GetStr255, title))
451 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000452 SetControlTitle(_self->ob_itself,
453 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000454 Py_INCREF(Py_None);
455 _res = Py_None;
456 return _res;
457}
458
Jack Jansenae8a68f1995-06-06 12:55:40 +0000459static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000460 ControlObject *_self;
461 PyObject *_args;
462{
463 PyObject *_res = NULL;
464 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000465 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000466 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000467 GetControlTitle(_self->ob_itself,
468 title);
Jack Jansen41009001999-03-07 20:05:20 +0000469 _res = Py_BuildValue("O&",
470 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000471 return _res;
472}
473
Jack Jansenae8a68f1995-06-06 12:55:40 +0000474static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000475 ControlObject *_self;
476 PyObject *_args;
477{
478 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000479 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000480 if (!PyArg_ParseTuple(_args, ""))
481 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000482 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000483 _res = Py_BuildValue("h",
484 _rv);
485 return _res;
486}
487
Jack Jansen7d0bc831995-06-09 20:56:31 +0000488static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000489 ControlObject *_self;
490 PyObject *_args;
491{
492 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000493 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000494 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000495 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000496 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000497 SetControlValue(_self->ob_itself,
498 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000499 Py_INCREF(Py_None);
500 _res = Py_None;
501 return _res;
502}
503
Jack Jansenae8a68f1995-06-06 12:55:40 +0000504static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000505 ControlObject *_self;
506 PyObject *_args;
507{
508 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000509 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000510 if (!PyArg_ParseTuple(_args, ""))
511 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000512 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000513 _res = Py_BuildValue("h",
514 _rv);
515 return _res;
516}
517
Jack Jansen7d0bc831995-06-09 20:56:31 +0000518static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000519 ControlObject *_self;
520 PyObject *_args;
521{
522 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000523 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000524 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000525 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000526 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000527 SetControlMinimum(_self->ob_itself,
528 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000529 Py_INCREF(Py_None);
530 _res = Py_None;
531 return _res;
532}
533
Jack Jansenae8a68f1995-06-06 12:55:40 +0000534static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000535 ControlObject *_self;
536 PyObject *_args;
537{
538 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000539 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000540 if (!PyArg_ParseTuple(_args, ""))
541 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000542 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000543 _res = Py_BuildValue("h",
544 _rv);
545 return _res;
546}
547
Jack Jansen7d0bc831995-06-09 20:56:31 +0000548static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000549 ControlObject *_self;
550 PyObject *_args;
551{
552 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000553 SInt16 newMaximum;
554 if (!PyArg_ParseTuple(_args, "h",
555 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000556 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000557 SetControlMaximum(_self->ob_itself,
558 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000559 Py_INCREF(Py_None);
560 _res = Py_None;
561 return _res;
562}
563
Jack Jansen7d0bc831995-06-09 20:56:31 +0000564static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000565 ControlObject *_self;
566 PyObject *_args;
567{
568 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000569 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000570 if (!PyArg_ParseTuple(_args, ""))
571 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000572 _rv = GetControlVariant(_self->ob_itself);
573 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000574 _rv);
575 return _res;
576}
577
Jack Jansen7d0bc831995-06-09 20:56:31 +0000578static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000579 ControlObject *_self;
580 PyObject *_args;
581{
582 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000583 SInt32 data;
584 if (!PyArg_ParseTuple(_args, "l",
585 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000586 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000587 SetControlReference(_self->ob_itself,
588 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000589 Py_INCREF(Py_None);
590 _res = Py_None;
591 return _res;
592}
593
Jack Jansen7d0bc831995-06-09 20:56:31 +0000594static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000595 ControlObject *_self;
596 PyObject *_args;
597{
598 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000599 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000600 if (!PyArg_ParseTuple(_args, ""))
601 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000602 _rv = GetControlReference(_self->ob_itself);
603 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000604 _rv);
605 return _res;
606}
607
Jack Jansenc7fefed1997-08-15 14:32:18 +0000608static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
609 ControlObject *_self;
610 PyObject *_args;
611{
612 PyObject *_res = NULL;
613 Boolean _rv;
614 AuxCtlHandle acHndl;
615 if (!PyArg_ParseTuple(_args, ""))
616 return NULL;
617 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
618 &acHndl);
619 _res = Py_BuildValue("bO&",
620 _rv,
621 ResObj_New, acHndl);
622 return _res;
623}
624
625static PyObject *CtlObj_SetControlColor(_self, _args)
626 ControlObject *_self;
627 PyObject *_args;
628{
629 PyObject *_res = NULL;
630 CCTabHandle newColorTable;
631 if (!PyArg_ParseTuple(_args, "O&",
632 ResObj_Convert, &newColorTable))
633 return NULL;
634 SetControlColor(_self->ob_itself,
635 newColorTable);
636 Py_INCREF(Py_None);
637 _res = Py_None;
638 return _res;
639}
640
Jack Jansen21f96871998-02-20 16:02:09 +0000641static PyObject *CtlObj_SendControlMessage(_self, _args)
642 ControlObject *_self;
643 PyObject *_args;
644{
645 PyObject *_res = NULL;
646 SInt32 _rv;
647 SInt16 inMessage;
648 SInt32 inParam;
649 if (!PyArg_ParseTuple(_args, "hl",
650 &inMessage,
651 &inParam))
652 return NULL;
653 _rv = SendControlMessage(_self->ob_itself,
654 inMessage,
655 inParam);
656 _res = Py_BuildValue("l",
657 _rv);
658 return _res;
659}
660
661static PyObject *CtlObj_EmbedControl(_self, _args)
662 ControlObject *_self;
663 PyObject *_args;
664{
665 PyObject *_res = NULL;
666 OSErr _err;
667 ControlHandle inContainer;
668 if (!PyArg_ParseTuple(_args, "O&",
669 CtlObj_Convert, &inContainer))
670 return NULL;
671 _err = EmbedControl(_self->ob_itself,
672 inContainer);
673 if (_err != noErr) return PyMac_Error(_err);
674 Py_INCREF(Py_None);
675 _res = Py_None;
676 return _res;
677}
678
679static PyObject *CtlObj_AutoEmbedControl(_self, _args)
680 ControlObject *_self;
681 PyObject *_args;
682{
683 PyObject *_res = NULL;
684 OSErr _err;
685 WindowPtr inWindow;
686 if (!PyArg_ParseTuple(_args, "O&",
687 WinObj_Convert, &inWindow))
688 return NULL;
689 _err = AutoEmbedControl(_self->ob_itself,
690 inWindow);
691 if (_err != noErr) return PyMac_Error(_err);
692 Py_INCREF(Py_None);
693 _res = Py_None;
694 return _res;
695}
696
697static PyObject *CtlObj_GetSuperControl(_self, _args)
698 ControlObject *_self;
699 PyObject *_args;
700{
701 PyObject *_res = NULL;
702 OSErr _err;
703 ControlHandle outParent;
704 if (!PyArg_ParseTuple(_args, ""))
705 return NULL;
706 _err = GetSuperControl(_self->ob_itself,
707 &outParent);
708 if (_err != noErr) return PyMac_Error(_err);
709 _res = Py_BuildValue("O&",
710 CtlObj_WhichControl, outParent);
711 return _res;
712}
713
714static PyObject *CtlObj_CountSubControls(_self, _args)
715 ControlObject *_self;
716 PyObject *_args;
717{
718 PyObject *_res = NULL;
719 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000720 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +0000721 if (!PyArg_ParseTuple(_args, ""))
722 return NULL;
723 _err = CountSubControls(_self->ob_itself,
724 &outNumChildren);
725 if (_err != noErr) return PyMac_Error(_err);
726 _res = Py_BuildValue("h",
727 outNumChildren);
728 return _res;
729}
730
731static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
732 ControlObject *_self;
733 PyObject *_args;
734{
735 PyObject *_res = NULL;
736 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000737 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +0000738 ControlHandle outSubControl;
739 if (!PyArg_ParseTuple(_args, "h",
740 &inIndex))
741 return NULL;
742 _err = GetIndexedSubControl(_self->ob_itself,
743 inIndex,
744 &outSubControl);
745 if (_err != noErr) return PyMac_Error(_err);
746 _res = Py_BuildValue("O&",
747 CtlObj_WhichControl, outSubControl);
748 return _res;
749}
750
751static PyObject *CtlObj_SetControlSupervisor(_self, _args)
752 ControlObject *_self;
753 PyObject *_args;
754{
755 PyObject *_res = NULL;
756 OSErr _err;
757 ControlHandle inBoss;
758 if (!PyArg_ParseTuple(_args, "O&",
759 CtlObj_Convert, &inBoss))
760 return NULL;
761 _err = SetControlSupervisor(_self->ob_itself,
762 inBoss);
763 if (_err != noErr) return PyMac_Error(_err);
764 Py_INCREF(Py_None);
765 _res = Py_None;
766 return _res;
767}
768
769static PyObject *CtlObj_GetControlFeatures(_self, _args)
770 ControlObject *_self;
771 PyObject *_args;
772{
773 PyObject *_res = NULL;
774 OSErr _err;
775 UInt32 outFeatures;
776 if (!PyArg_ParseTuple(_args, ""))
777 return NULL;
778 _err = GetControlFeatures(_self->ob_itself,
779 &outFeatures);
780 if (_err != noErr) return PyMac_Error(_err);
781 _res = Py_BuildValue("l",
782 outFeatures);
783 return _res;
784}
785
786static PyObject *CtlObj_GetControlDataSize(_self, _args)
787 ControlObject *_self;
788 PyObject *_args;
789{
790 PyObject *_res = NULL;
791 OSErr _err;
792 ControlPartCode inPart;
793 ResType inTagName;
794 Size outMaxSize;
795 if (!PyArg_ParseTuple(_args, "hO&",
796 &inPart,
797 PyMac_GetOSType, &inTagName))
798 return NULL;
799 _err = GetControlDataSize(_self->ob_itself,
800 inPart,
801 inTagName,
802 &outMaxSize);
803 if (_err != noErr) return PyMac_Error(_err);
804 _res = Py_BuildValue("l",
805 outMaxSize);
806 return _res;
807}
808
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000809static PyObject *CtlObj_as_Resource(_self, _args)
810 ControlObject *_self;
811 PyObject *_args;
812{
813 PyObject *_res = NULL;
814
815 return ResObj_New((Handle)_self->ob_itself);
816
817}
818
Jack Jansencfb60ee1996-10-01 10:46:46 +0000819static PyObject *CtlObj_DisposeControl(_self, _args)
820 ControlObject *_self;
821 PyObject *_args;
822{
823 PyObject *_res = NULL;
824
825 if (!PyArg_ParseTuple(_args, ""))
826 return NULL;
827 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +0000828 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +0000829 DisposeControl(_self->ob_itself);
830 _self->ob_itself = NULL;
831 }
832 Py_INCREF(Py_None);
833 _res = Py_None;
834 return _res;
835
836}
837
Jack Jansen848250c1998-05-28 14:20:09 +0000838static PyObject *CtlObj_TrackControl(_self, _args)
839 ControlObject *_self;
840 PyObject *_args;
841{
842 PyObject *_res = NULL;
843
844 ControlPartCode _rv;
845 Point startPoint;
846 ControlActionUPP upp = 0;
847 PyObject *callback = 0;
848
849 if (!PyArg_ParseTuple(_args, "O&|O",
850 PyMac_GetPoint, &startPoint, &callback))
851 return NULL;
852 if (callback && callback != Py_None) {
853 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
854 upp = (ControlActionUPP)-1;
855 else {
856 settrackfunc(callback);
857 upp = mytracker_upp;
858 }
859 }
860 _rv = TrackControl(_self->ob_itself,
861 startPoint,
862 upp);
863 clrtrackfunc();
864 _res = Py_BuildValue("h",
865 _rv);
866 return _res;
867
868}
869
Jack Jansen24c35311999-12-09 22:49:51 +0000870static PyObject *CtlObj_HandleControlClick(_self, _args)
871 ControlObject *_self;
872 PyObject *_args;
873{
874 PyObject *_res = NULL;
875
876 ControlPartCode _rv;
877 Point startPoint;
878 SInt16 modifiers;
879 ControlActionUPP upp = 0;
880 PyObject *callback = 0;
881
882 if (!PyArg_ParseTuple(_args, "O&h|O",
883 PyMac_GetPoint, &startPoint,
884 &modifiers,
885 &callback))
886 return NULL;
887 if (callback && callback != Py_None) {
888 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
889 upp = (ControlActionUPP)-1;
890 else {
891 settrackfunc(callback);
892 upp = mytracker_upp;
893 }
894 }
895 _rv = HandleControlClick(_self->ob_itself,
896 startPoint,
897 modifiers,
898 upp);
899 clrtrackfunc();
900 _res = Py_BuildValue("h",
901 _rv);
902 return _res;
903
904}
905
906static PyObject *CtlObj_SetControlData(_self, _args)
907 ControlObject *_self;
908 PyObject *_args;
909{
910 PyObject *_res = NULL;
911
912 OSErr _err;
913 ControlPartCode inPart;
914 ResType inTagName;
915 Size bufferSize;
916 Ptr buffer;
917
918 if (!PyArg_ParseTuple(_args, "hO&s#",
919 &inPart,
920 PyMac_GetOSType, &inTagName,
921 &buffer, &bufferSize))
922 return NULL;
923
924 _err = SetControlData(_self->ob_itself,
925 inPart,
926 inTagName,
927 bufferSize,
928 buffer);
929
930 if (_err != noErr)
931 return PyMac_Error(_err);
932 _res = Py_None;
933 return _res;
934
935}
936
937static PyObject *CtlObj_GetControlData(_self, _args)
938 ControlObject *_self;
939 PyObject *_args;
940{
941 PyObject *_res = NULL;
942
943 OSErr _err;
944 ControlPartCode inPart;
945 ResType inTagName;
946 Size bufferSize;
947 Ptr buffer;
948 Size outSize;
949
950 if (!PyArg_ParseTuple(_args, "hO&",
951 &inPart,
952 PyMac_GetOSType, &inTagName))
953 return NULL;
954
955 /* allocate a buffer for the data */
956 _err = GetControlDataSize(_self->ob_itself,
957 inPart,
958 inTagName,
959 &bufferSize);
960 if (_err != noErr)
961 return PyMac_Error(_err);
962 buffer = PyMem_NEW(char, bufferSize);
963 if (buffer == NULL)
964 return PyErr_NoMemory();
965
966 _err = GetControlData(_self->ob_itself,
967 inPart,
968 inTagName,
969 bufferSize,
970 buffer,
971 &outSize);
972
973 if (_err != noErr) {
974 PyMem_DEL(buffer);
975 return PyMac_Error(_err);
976 }
977 _res = Py_BuildValue("s#", buffer, outSize);
978 PyMem_DEL(buffer);
979 return _res;
980
981}
982
Jack Jansen4c704131998-06-19 13:35:14 +0000983static PyObject *CtlObj_GetPopupData(_self, _args)
984 ControlObject *_self;
985 PyObject *_args;
986{
987 PyObject *_res = NULL;
988
989 PopupPrivateDataHandle hdl;
990
991 if ( (*_self->ob_itself)->contrlData == NULL ) {
992 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
993 return 0;
994 }
995 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
996 HLock((Handle)hdl);
997 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
998 HUnlock((Handle)hdl);
999 return _res;
1000
1001}
1002
1003static PyObject *CtlObj_SetPopupData(_self, _args)
1004 ControlObject *_self;
1005 PyObject *_args;
1006{
1007 PyObject *_res = NULL;
1008
1009 PopupPrivateDataHandle hdl;
1010 MenuHandle mHandle;
1011 short mID;
1012
1013 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1014 return 0;
1015 if ( (*_self->ob_itself)->contrlData == NULL ) {
1016 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1017 return 0;
1018 }
1019 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1020 (*hdl)->mHandle = mHandle;
1021 (*hdl)->mID = mID;
1022 Py_INCREF(Py_None);
1023 return Py_None;
1024
1025}
1026
Guido van Rossum17448e21995-01-30 11:53:55 +00001027static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001028 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1029 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001030 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1031 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001032 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1033 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001034 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1035 "() -> (Boolean _rv)"},
1036 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1037 "() -> (Boolean _rv)"},
1038 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1039 "() -> None"},
1040 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1041 "() -> None"},
1042 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1043 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001044 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1045 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001046 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1047 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1048 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1049 "(ControlFontStyleRec inStyle) -> None"},
1050 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1051 "() -> None"},
1052 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1053 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001054 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001055 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001056 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001057 "(Point testPoint) -> (ControlPartCode _rv)"},
1058 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1059 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001060 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001061 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001062 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001063 "(SInt16 w, SInt16 h) -> None"},
1064 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1065 "(Str255 title) -> None"},
1066 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001067 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001068 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001069 "() -> (SInt16 _rv)"},
1070 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1071 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001072 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001073 "() -> (SInt16 _rv)"},
1074 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1075 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001076 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001077 "() -> (SInt16 _rv)"},
1078 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1079 "(SInt16 newMaximum) -> None"},
1080 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001081 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001082 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1083 "(SInt32 data) -> None"},
1084 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1085 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +00001086 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1087 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
1088 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1089 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001090 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1091 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1092 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1093 "(ControlHandle inContainer) -> None"},
1094 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1095 "(WindowPtr inWindow) -> None"},
1096 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1097 "() -> (ControlHandle outParent)"},
1098 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001099 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001100 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001101 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001102 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1103 "(ControlHandle inBoss) -> None"},
1104 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1105 "() -> (UInt32 outFeatures)"},
1106 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1107 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001108 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
1109 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001110 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1111 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001112 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001113 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1114 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1115 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1116 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1117 "(stuff) -> None"},
1118 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1119 "(part, type) -> String"},
Jack Jansen4c704131998-06-19 13:35:14 +00001120 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1121 NULL},
1122 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1123 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001124 {NULL, NULL, 0}
1125};
1126
1127PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1128
1129static PyObject *CtlObj_getattr(self, name)
1130 ControlObject *self;
1131 char *name;
1132{
1133 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1134}
1135
1136#define CtlObj_setattr NULL
1137
Jack Jansen8387af61999-03-13 23:07:32 +00001138static int CtlObj_compare(self, other)
1139 ControlObject *self, *other;
1140{
1141 unsigned long v, w;
1142
1143 if (!CtlObj_Check((PyObject *)other))
1144 {
1145 v=(unsigned long)self;
1146 w=(unsigned long)other;
1147 }
1148 else
1149 {
1150 v=(unsigned long)self->ob_itself;
1151 w=(unsigned long)other->ob_itself;
1152 }
1153 if( v < w ) return -1;
1154 if( v > w ) return 1;
1155 return 0;
1156}
1157
1158#define CtlObj_repr NULL
1159
1160static long CtlObj_hash(self)
1161 ControlObject *self;
1162{
1163 return (long)self->ob_itself;
1164}
1165
Guido van Rossum17448e21995-01-30 11:53:55 +00001166PyTypeObject Control_Type = {
1167 PyObject_HEAD_INIT(&PyType_Type)
1168 0, /*ob_size*/
1169 "Control", /*tp_name*/
1170 sizeof(ControlObject), /*tp_basicsize*/
1171 0, /*tp_itemsize*/
1172 /* methods */
1173 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1174 0, /*tp_print*/
1175 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1176 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001177 (cmpfunc) CtlObj_compare, /*tp_compare*/
1178 (reprfunc) CtlObj_repr, /*tp_repr*/
1179 (PyNumberMethods *)0, /* tp_as_number */
1180 (PySequenceMethods *)0, /* tp_as_sequence */
1181 (PyMappingMethods *)0, /* tp_as_mapping */
1182 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001183};
1184
1185/* -------------------- End object type Control --------------------- */
1186
1187
1188static PyObject *Ctl_NewControl(_self, _args)
1189 PyObject *_self;
1190 PyObject *_args;
1191{
1192 PyObject *_res = NULL;
1193 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001194 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001195 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001196 Str255 controlTitle;
1197 Boolean initiallyVisible;
1198 SInt16 initialValue;
1199 SInt16 minimumValue;
1200 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001201 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001202 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001203 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001204 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001205 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001206 PyMac_GetStr255, controlTitle,
1207 &initiallyVisible,
1208 &initialValue,
1209 &minimumValue,
1210 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001211 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001212 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001213 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001214 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001215 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001216 controlTitle,
1217 initiallyVisible,
1218 initialValue,
1219 minimumValue,
1220 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001221 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001222 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001223 _res = Py_BuildValue("O&",
1224 CtlObj_New, _rv);
1225 return _res;
1226}
1227
1228static PyObject *Ctl_GetNewControl(_self, _args)
1229 PyObject *_self;
1230 PyObject *_args;
1231{
1232 PyObject *_res = NULL;
1233 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001234 SInt16 resourceID;
1235 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001236 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001237 &resourceID,
1238 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001239 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001240 _rv = GetNewControl(resourceID,
1241 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001242 _res = Py_BuildValue("O&",
1243 CtlObj_New, _rv);
1244 return _res;
1245}
1246
Guido van Rossum17448e21995-01-30 11:53:55 +00001247static PyObject *Ctl_DrawControls(_self, _args)
1248 PyObject *_self;
1249 PyObject *_args;
1250{
1251 PyObject *_res = NULL;
1252 WindowPtr theWindow;
1253 if (!PyArg_ParseTuple(_args, "O&",
1254 WinObj_Convert, &theWindow))
1255 return NULL;
1256 DrawControls(theWindow);
1257 Py_INCREF(Py_None);
1258 _res = Py_None;
1259 return _res;
1260}
1261
Guido van Rossum17448e21995-01-30 11:53:55 +00001262static PyObject *Ctl_UpdateControls(_self, _args)
1263 PyObject *_self;
1264 PyObject *_args;
1265{
1266 PyObject *_res = NULL;
1267 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001268 RgnHandle updateRegion;
1269 if (!PyArg_ParseTuple(_args, "O&O&",
1270 WinObj_Convert, &theWindow,
1271 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001272 return NULL;
1273 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001274 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001275 Py_INCREF(Py_None);
1276 _res = Py_None;
1277 return _res;
1278}
1279
1280static PyObject *Ctl_FindControl(_self, _args)
1281 PyObject *_self;
1282 PyObject *_args;
1283{
1284 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001285 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001286 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001287 WindowPtr theWindow;
1288 ControlHandle theControl;
1289 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001290 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001291 WinObj_Convert, &theWindow))
1292 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001293 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001294 theWindow,
1295 &theControl);
1296 _res = Py_BuildValue("hO&",
1297 _rv,
1298 CtlObj_WhichControl, theControl);
1299 return _res;
1300}
1301
Jack Jansen21f96871998-02-20 16:02:09 +00001302static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1303 PyObject *_self;
1304 PyObject *_args;
1305{
1306 PyObject *_res = NULL;
1307 ControlHandle _rv;
1308 Point inWhere;
1309 WindowPtr inWindow;
1310 SInt16 outPart;
1311 if (!PyArg_ParseTuple(_args, "O&O&",
1312 PyMac_GetPoint, &inWhere,
1313 WinObj_Convert, &inWindow))
1314 return NULL;
1315 _rv = FindControlUnderMouse(inWhere,
1316 inWindow,
1317 &outPart);
1318 _res = Py_BuildValue("O&h",
1319 CtlObj_New, _rv,
1320 outPart);
1321 return _res;
1322}
1323
1324static PyObject *Ctl_IdleControls(_self, _args)
1325 PyObject *_self;
1326 PyObject *_args;
1327{
1328 PyObject *_res = NULL;
1329 WindowPtr inWindow;
1330 if (!PyArg_ParseTuple(_args, "O&",
1331 WinObj_Convert, &inWindow))
1332 return NULL;
1333 IdleControls(inWindow);
1334 Py_INCREF(Py_None);
1335 _res = Py_None;
1336 return _res;
1337}
1338
1339static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1340 PyObject *_self;
1341 PyObject *_args;
1342{
1343 PyObject *_res = NULL;
1344 OSErr _err;
1345 WindowPtr inWindow;
1346 FSSpec inDumpFile;
1347 if (!PyArg_ParseTuple(_args, "O&O&",
1348 WinObj_Convert, &inWindow,
1349 PyMac_GetFSSpec, &inDumpFile))
1350 return NULL;
1351 _err = DumpControlHierarchy(inWindow,
1352 &inDumpFile);
1353 if (_err != noErr) return PyMac_Error(_err);
1354 Py_INCREF(Py_None);
1355 _res = Py_None;
1356 return _res;
1357}
1358
1359static PyObject *Ctl_CreateRootControl(_self, _args)
1360 PyObject *_self;
1361 PyObject *_args;
1362{
1363 PyObject *_res = NULL;
1364 OSErr _err;
1365 WindowPtr inWindow;
1366 ControlHandle outControl;
1367 if (!PyArg_ParseTuple(_args, "O&",
1368 WinObj_Convert, &inWindow))
1369 return NULL;
1370 _err = CreateRootControl(inWindow,
1371 &outControl);
1372 if (_err != noErr) return PyMac_Error(_err);
1373 _res = Py_BuildValue("O&",
1374 CtlObj_WhichControl, outControl);
1375 return _res;
1376}
1377
1378static PyObject *Ctl_GetRootControl(_self, _args)
1379 PyObject *_self;
1380 PyObject *_args;
1381{
1382 PyObject *_res = NULL;
1383 OSErr _err;
1384 WindowPtr inWindow;
1385 ControlHandle outControl;
1386 if (!PyArg_ParseTuple(_args, "O&",
1387 WinObj_Convert, &inWindow))
1388 return NULL;
1389 _err = GetRootControl(inWindow,
1390 &outControl);
1391 if (_err != noErr) return PyMac_Error(_err);
1392 _res = Py_BuildValue("O&",
1393 CtlObj_WhichControl, outControl);
1394 return _res;
1395}
1396
1397static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1398 PyObject *_self;
1399 PyObject *_args;
1400{
1401 PyObject *_res = NULL;
1402 OSErr _err;
1403 WindowPtr inWindow;
1404 ControlHandle outControl;
1405 if (!PyArg_ParseTuple(_args, "O&",
1406 WinObj_Convert, &inWindow))
1407 return NULL;
1408 _err = GetKeyboardFocus(inWindow,
1409 &outControl);
1410 if (_err != noErr) return PyMac_Error(_err);
1411 _res = Py_BuildValue("O&",
1412 CtlObj_WhichControl, outControl);
1413 return _res;
1414}
1415
1416static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1417 PyObject *_self;
1418 PyObject *_args;
1419{
1420 PyObject *_res = NULL;
1421 OSErr _err;
1422 WindowPtr inWindow;
1423 ControlHandle inControl;
1424 ControlFocusPart inPart;
1425 if (!PyArg_ParseTuple(_args, "O&O&h",
1426 WinObj_Convert, &inWindow,
1427 CtlObj_Convert, &inControl,
1428 &inPart))
1429 return NULL;
1430 _err = SetKeyboardFocus(inWindow,
1431 inControl,
1432 inPart);
1433 if (_err != noErr) return PyMac_Error(_err);
1434 Py_INCREF(Py_None);
1435 _res = Py_None;
1436 return _res;
1437}
1438
1439static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1440 PyObject *_self;
1441 PyObject *_args;
1442{
1443 PyObject *_res = NULL;
1444 OSErr _err;
1445 WindowPtr inWindow;
1446 if (!PyArg_ParseTuple(_args, "O&",
1447 WinObj_Convert, &inWindow))
1448 return NULL;
1449 _err = AdvanceKeyboardFocus(inWindow);
1450 if (_err != noErr) return PyMac_Error(_err);
1451 Py_INCREF(Py_None);
1452 _res = Py_None;
1453 return _res;
1454}
1455
1456static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1457 PyObject *_self;
1458 PyObject *_args;
1459{
1460 PyObject *_res = NULL;
1461 OSErr _err;
1462 WindowPtr inWindow;
1463 if (!PyArg_ParseTuple(_args, "O&",
1464 WinObj_Convert, &inWindow))
1465 return NULL;
1466 _err = ReverseKeyboardFocus(inWindow);
1467 if (_err != noErr) return PyMac_Error(_err);
1468 Py_INCREF(Py_None);
1469 _res = Py_None;
1470 return _res;
1471}
1472
1473static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1474 PyObject *_self;
1475 PyObject *_args;
1476{
1477 PyObject *_res = NULL;
1478 OSErr _err;
1479 WindowPtr inWindow;
1480 if (!PyArg_ParseTuple(_args, "O&",
1481 WinObj_Convert, &inWindow))
1482 return NULL;
1483 _err = ClearKeyboardFocus(inWindow);
1484 if (_err != noErr) return PyMac_Error(_err);
1485 Py_INCREF(Py_None);
1486 _res = Py_None;
1487 return _res;
1488}
1489
Jack Jansene0581891999-02-07 14:02:03 +00001490static PyObject *Ctl_as_Control(_self, _args)
1491 PyObject *_self;
1492 PyObject *_args;
1493{
1494 PyObject *_res = NULL;
1495 ControlHandle _rv;
1496 Handle h;
1497 if (!PyArg_ParseTuple(_args, "O&",
1498 ResObj_Convert, &h))
1499 return NULL;
1500 _rv = as_Control(h);
1501 _res = Py_BuildValue("O&",
1502 CtlObj_New, _rv);
1503 return _res;
1504}
1505
Guido van Rossum17448e21995-01-30 11:53:55 +00001506static PyMethodDef Ctl_methods[] = {
1507 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001508 "(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 +00001509 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001510 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001511 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1512 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001513 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001514 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001515 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001516 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1517 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1518 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1519 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1520 "(WindowPtr inWindow) -> None"},
1521 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1522 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1523 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1524 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1525 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1526 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1527 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1528 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1529 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1530 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1531 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1532 "(WindowPtr inWindow) -> None"},
1533 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1534 "(WindowPtr inWindow) -> None"},
1535 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1536 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001537 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1538 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001539 {NULL, NULL, 0}
1540};
1541
1542
1543
Jack Jansen8387af61999-03-13 23:07:32 +00001544PyObject *CtlObj_NewUnmanaged(itself)
1545 ControlHandle itself;
1546{
1547 ControlObject *it;
1548 if (itself == NULL) return PyMac_Error(resNotFound);
1549 it = PyObject_NEW(ControlObject, &Control_Type);
1550 if (it == NULL) return NULL;
1551 it->ob_itself = itself;
1552 return (PyObject *)it;
1553}
1554
Guido van Rossum17448e21995-01-30 11:53:55 +00001555PyObject *
1556CtlObj_WhichControl(ControlHandle c)
1557{
1558 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00001559
Guido van Rossum17448e21995-01-30 11:53:55 +00001560 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00001561 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00001562 else {
1563 it = (PyObject *) GetControlReference(c);
1564 /*
1565 ** If the refcon is zero or doesn't point back to the Python object
1566 ** the control is not ours. Return a temporary object.
1567 */
1568 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1569 return CtlObj_NewUnmanaged(c);
1570 }
Guido van Rossum17448e21995-01-30 11:53:55 +00001571 Py_INCREF(it);
1572 return it;
1573}
1574
Jack Jansen848250c1998-05-28 14:20:09 +00001575static int
1576settrackfunc(obj)
1577 PyObject *obj;
1578{
1579 if (tracker) {
1580 PyErr_SetString(Ctl_Error, "Tracker function in use");
1581 return 0;
1582 }
1583 tracker = obj;
1584 Py_INCREF(tracker);
1585}
1586
1587static void
1588clrtrackfunc()
1589{
1590 Py_XDECREF(tracker);
1591 tracker = 0;
1592}
1593
1594static pascal void
1595mytracker(ctl, part)
1596 ControlHandle ctl;
1597 short part;
1598{
1599 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00001600
Jack Jansen848250c1998-05-28 14:20:09 +00001601 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1602 if (args && tracker) {
1603 rv = PyEval_CallObject(tracker, args);
1604 Py_DECREF(args);
1605 }
1606 if (rv)
1607 Py_DECREF(rv);
1608 else
Jack Jansen24c35311999-12-09 22:49:51 +00001609 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001610}
1611
Guido van Rossum17448e21995-01-30 11:53:55 +00001612
1613void initCtl()
1614{
1615 PyObject *m;
1616 PyObject *d;
1617
1618
1619
Jack Jansen848250c1998-05-28 14:20:09 +00001620 mytracker_upp = NewControlActionProc(mytracker);
1621
Guido van Rossum17448e21995-01-30 11:53:55 +00001622
1623 m = Py_InitModule("Ctl", Ctl_methods);
1624 d = PyModule_GetDict(m);
1625 Ctl_Error = PyMac_GetOSErrException();
1626 if (Ctl_Error == NULL ||
1627 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1628 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001629 Control_Type.ob_type = &PyType_Type;
1630 Py_INCREF(&Control_Type);
1631 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1632 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001633}
1634
1635/* ========================= End module Ctl ========================= */
1636