blob: 895187e80dde8d48b037c4d9f20eb87223bb6693 [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,
78 &itself->font, &itself->size, &itself->style, &itself->mode,
79 &itself->just, QdRGB_Convert, &itself->foreColor,
80 QdRGB_Convert, &itself->backColor);
81}
82
Jack Jansen848250c1998-05-28 14:20:09 +000083/* TrackControl callback support */
84static 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 Jansen85ae4a81997-04-08 15:26:03 +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;
720 SInt16 outNumChildren;
721 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;
737 SInt16 inIndex;
738 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 Jansen4c704131998-06-19 13:35:14 +0000870static PyObject *CtlObj_GetPopupData(_self, _args)
871 ControlObject *_self;
872 PyObject *_args;
873{
874 PyObject *_res = NULL;
875
876 PopupPrivateDataHandle hdl;
877
878 if ( (*_self->ob_itself)->contrlData == NULL ) {
879 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
880 return 0;
881 }
882 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
883 HLock((Handle)hdl);
884 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
885 HUnlock((Handle)hdl);
886 return _res;
887
888}
889
890static PyObject *CtlObj_SetPopupData(_self, _args)
891 ControlObject *_self;
892 PyObject *_args;
893{
894 PyObject *_res = NULL;
895
896 PopupPrivateDataHandle hdl;
897 MenuHandle mHandle;
898 short mID;
899
900 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
901 return 0;
902 if ( (*_self->ob_itself)->contrlData == NULL ) {
903 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
904 return 0;
905 }
906 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
907 (*hdl)->mHandle = mHandle;
908 (*hdl)->mID = mID;
909 Py_INCREF(Py_None);
910 return Py_None;
911
912}
913
Guido van Rossum17448e21995-01-30 11:53:55 +0000914static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +0000915 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
916 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000917 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
918 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000919 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
920 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000921 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
922 "() -> (Boolean _rv)"},
923 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
924 "() -> (Boolean _rv)"},
925 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
926 "() -> None"},
927 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
928 "() -> None"},
929 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
930 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000931 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
932 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000933 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
934 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
935 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
936 "(ControlFontStyleRec inStyle) -> None"},
937 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
938 "() -> None"},
939 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
940 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000941 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000942 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000943 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000944 "(Point testPoint) -> (ControlPartCode _rv)"},
945 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
946 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000947 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000948 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000949 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000950 "(SInt16 w, SInt16 h) -> None"},
951 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
952 "(Str255 title) -> None"},
953 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +0000954 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000955 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000956 "() -> (SInt16 _rv)"},
957 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
958 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000959 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000960 "() -> (SInt16 _rv)"},
961 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
962 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000963 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000964 "() -> (SInt16 _rv)"},
965 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
966 "(SInt16 newMaximum) -> None"},
967 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000968 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000969 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
970 "(SInt32 data) -> None"},
971 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
972 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +0000973 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
974 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
975 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
976 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000977 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
978 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
979 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
980 "(ControlHandle inContainer) -> None"},
981 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
982 "(WindowPtr inWindow) -> None"},
983 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
984 "() -> (ControlHandle outParent)"},
985 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
986 "() -> (SInt16 outNumChildren)"},
987 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
988 "(SInt16 inIndex) -> (ControlHandle outSubControl)"},
989 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
990 "(ControlHandle inBoss) -> None"},
991 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
992 "() -> (UInt32 outFeatures)"},
993 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
994 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000995 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
996 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +0000997 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
998 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +0000999 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
1000 NULL},
Jack Jansen4c704131998-06-19 13:35:14 +00001001 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1002 NULL},
1003 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1004 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001005 {NULL, NULL, 0}
1006};
1007
1008PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1009
1010static PyObject *CtlObj_getattr(self, name)
1011 ControlObject *self;
1012 char *name;
1013{
1014 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1015}
1016
1017#define CtlObj_setattr NULL
1018
Jack Jansen8387af61999-03-13 23:07:32 +00001019static int CtlObj_compare(self, other)
1020 ControlObject *self, *other;
1021{
1022 unsigned long v, w;
1023
1024 if (!CtlObj_Check((PyObject *)other))
1025 {
1026 v=(unsigned long)self;
1027 w=(unsigned long)other;
1028 }
1029 else
1030 {
1031 v=(unsigned long)self->ob_itself;
1032 w=(unsigned long)other->ob_itself;
1033 }
1034 if( v < w ) return -1;
1035 if( v > w ) return 1;
1036 return 0;
1037}
1038
1039#define CtlObj_repr NULL
1040
1041static long CtlObj_hash(self)
1042 ControlObject *self;
1043{
1044 return (long)self->ob_itself;
1045}
1046
Guido van Rossum17448e21995-01-30 11:53:55 +00001047PyTypeObject Control_Type = {
1048 PyObject_HEAD_INIT(&PyType_Type)
1049 0, /*ob_size*/
1050 "Control", /*tp_name*/
1051 sizeof(ControlObject), /*tp_basicsize*/
1052 0, /*tp_itemsize*/
1053 /* methods */
1054 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1055 0, /*tp_print*/
1056 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1057 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001058 (cmpfunc) CtlObj_compare, /*tp_compare*/
1059 (reprfunc) CtlObj_repr, /*tp_repr*/
1060 (PyNumberMethods *)0, /* tp_as_number */
1061 (PySequenceMethods *)0, /* tp_as_sequence */
1062 (PyMappingMethods *)0, /* tp_as_mapping */
1063 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001064};
1065
1066/* -------------------- End object type Control --------------------- */
1067
1068
1069static PyObject *Ctl_NewControl(_self, _args)
1070 PyObject *_self;
1071 PyObject *_args;
1072{
1073 PyObject *_res = NULL;
1074 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001075 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001076 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001077 Str255 controlTitle;
1078 Boolean initiallyVisible;
1079 SInt16 initialValue;
1080 SInt16 minimumValue;
1081 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001082 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001083 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001084 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001085 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001086 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001087 PyMac_GetStr255, controlTitle,
1088 &initiallyVisible,
1089 &initialValue,
1090 &minimumValue,
1091 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001092 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001093 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001094 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001095 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001096 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001097 controlTitle,
1098 initiallyVisible,
1099 initialValue,
1100 minimumValue,
1101 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001102 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001103 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001104 _res = Py_BuildValue("O&",
1105 CtlObj_New, _rv);
1106 return _res;
1107}
1108
1109static PyObject *Ctl_GetNewControl(_self, _args)
1110 PyObject *_self;
1111 PyObject *_args;
1112{
1113 PyObject *_res = NULL;
1114 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001115 SInt16 resourceID;
1116 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001117 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001118 &resourceID,
1119 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001120 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001121 _rv = GetNewControl(resourceID,
1122 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001123 _res = Py_BuildValue("O&",
1124 CtlObj_New, _rv);
1125 return _res;
1126}
1127
Guido van Rossum17448e21995-01-30 11:53:55 +00001128static PyObject *Ctl_DrawControls(_self, _args)
1129 PyObject *_self;
1130 PyObject *_args;
1131{
1132 PyObject *_res = NULL;
1133 WindowPtr theWindow;
1134 if (!PyArg_ParseTuple(_args, "O&",
1135 WinObj_Convert, &theWindow))
1136 return NULL;
1137 DrawControls(theWindow);
1138 Py_INCREF(Py_None);
1139 _res = Py_None;
1140 return _res;
1141}
1142
Guido van Rossum17448e21995-01-30 11:53:55 +00001143static PyObject *Ctl_UpdateControls(_self, _args)
1144 PyObject *_self;
1145 PyObject *_args;
1146{
1147 PyObject *_res = NULL;
1148 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001149 RgnHandle updateRegion;
1150 if (!PyArg_ParseTuple(_args, "O&O&",
1151 WinObj_Convert, &theWindow,
1152 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001153 return NULL;
1154 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001155 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001156 Py_INCREF(Py_None);
1157 _res = Py_None;
1158 return _res;
1159}
1160
1161static PyObject *Ctl_FindControl(_self, _args)
1162 PyObject *_self;
1163 PyObject *_args;
1164{
1165 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001166 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001167 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001168 WindowPtr theWindow;
1169 ControlHandle theControl;
1170 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001171 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001172 WinObj_Convert, &theWindow))
1173 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001174 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001175 theWindow,
1176 &theControl);
1177 _res = Py_BuildValue("hO&",
1178 _rv,
1179 CtlObj_WhichControl, theControl);
1180 return _res;
1181}
1182
Jack Jansen21f96871998-02-20 16:02:09 +00001183static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1184 PyObject *_self;
1185 PyObject *_args;
1186{
1187 PyObject *_res = NULL;
1188 ControlHandle _rv;
1189 Point inWhere;
1190 WindowPtr inWindow;
1191 SInt16 outPart;
1192 if (!PyArg_ParseTuple(_args, "O&O&",
1193 PyMac_GetPoint, &inWhere,
1194 WinObj_Convert, &inWindow))
1195 return NULL;
1196 _rv = FindControlUnderMouse(inWhere,
1197 inWindow,
1198 &outPart);
1199 _res = Py_BuildValue("O&h",
1200 CtlObj_New, _rv,
1201 outPart);
1202 return _res;
1203}
1204
1205static PyObject *Ctl_IdleControls(_self, _args)
1206 PyObject *_self;
1207 PyObject *_args;
1208{
1209 PyObject *_res = NULL;
1210 WindowPtr inWindow;
1211 if (!PyArg_ParseTuple(_args, "O&",
1212 WinObj_Convert, &inWindow))
1213 return NULL;
1214 IdleControls(inWindow);
1215 Py_INCREF(Py_None);
1216 _res = Py_None;
1217 return _res;
1218}
1219
1220static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1221 PyObject *_self;
1222 PyObject *_args;
1223{
1224 PyObject *_res = NULL;
1225 OSErr _err;
1226 WindowPtr inWindow;
1227 FSSpec inDumpFile;
1228 if (!PyArg_ParseTuple(_args, "O&O&",
1229 WinObj_Convert, &inWindow,
1230 PyMac_GetFSSpec, &inDumpFile))
1231 return NULL;
1232 _err = DumpControlHierarchy(inWindow,
1233 &inDumpFile);
1234 if (_err != noErr) return PyMac_Error(_err);
1235 Py_INCREF(Py_None);
1236 _res = Py_None;
1237 return _res;
1238}
1239
1240static PyObject *Ctl_CreateRootControl(_self, _args)
1241 PyObject *_self;
1242 PyObject *_args;
1243{
1244 PyObject *_res = NULL;
1245 OSErr _err;
1246 WindowPtr inWindow;
1247 ControlHandle outControl;
1248 if (!PyArg_ParseTuple(_args, "O&",
1249 WinObj_Convert, &inWindow))
1250 return NULL;
1251 _err = CreateRootControl(inWindow,
1252 &outControl);
1253 if (_err != noErr) return PyMac_Error(_err);
1254 _res = Py_BuildValue("O&",
1255 CtlObj_WhichControl, outControl);
1256 return _res;
1257}
1258
1259static PyObject *Ctl_GetRootControl(_self, _args)
1260 PyObject *_self;
1261 PyObject *_args;
1262{
1263 PyObject *_res = NULL;
1264 OSErr _err;
1265 WindowPtr inWindow;
1266 ControlHandle outControl;
1267 if (!PyArg_ParseTuple(_args, "O&",
1268 WinObj_Convert, &inWindow))
1269 return NULL;
1270 _err = GetRootControl(inWindow,
1271 &outControl);
1272 if (_err != noErr) return PyMac_Error(_err);
1273 _res = Py_BuildValue("O&",
1274 CtlObj_WhichControl, outControl);
1275 return _res;
1276}
1277
1278static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1279 PyObject *_self;
1280 PyObject *_args;
1281{
1282 PyObject *_res = NULL;
1283 OSErr _err;
1284 WindowPtr inWindow;
1285 ControlHandle outControl;
1286 if (!PyArg_ParseTuple(_args, "O&",
1287 WinObj_Convert, &inWindow))
1288 return NULL;
1289 _err = GetKeyboardFocus(inWindow,
1290 &outControl);
1291 if (_err != noErr) return PyMac_Error(_err);
1292 _res = Py_BuildValue("O&",
1293 CtlObj_WhichControl, outControl);
1294 return _res;
1295}
1296
1297static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1298 PyObject *_self;
1299 PyObject *_args;
1300{
1301 PyObject *_res = NULL;
1302 OSErr _err;
1303 WindowPtr inWindow;
1304 ControlHandle inControl;
1305 ControlFocusPart inPart;
1306 if (!PyArg_ParseTuple(_args, "O&O&h",
1307 WinObj_Convert, &inWindow,
1308 CtlObj_Convert, &inControl,
1309 &inPart))
1310 return NULL;
1311 _err = SetKeyboardFocus(inWindow,
1312 inControl,
1313 inPart);
1314 if (_err != noErr) return PyMac_Error(_err);
1315 Py_INCREF(Py_None);
1316 _res = Py_None;
1317 return _res;
1318}
1319
1320static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1321 PyObject *_self;
1322 PyObject *_args;
1323{
1324 PyObject *_res = NULL;
1325 OSErr _err;
1326 WindowPtr inWindow;
1327 if (!PyArg_ParseTuple(_args, "O&",
1328 WinObj_Convert, &inWindow))
1329 return NULL;
1330 _err = AdvanceKeyboardFocus(inWindow);
1331 if (_err != noErr) return PyMac_Error(_err);
1332 Py_INCREF(Py_None);
1333 _res = Py_None;
1334 return _res;
1335}
1336
1337static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1338 PyObject *_self;
1339 PyObject *_args;
1340{
1341 PyObject *_res = NULL;
1342 OSErr _err;
1343 WindowPtr inWindow;
1344 if (!PyArg_ParseTuple(_args, "O&",
1345 WinObj_Convert, &inWindow))
1346 return NULL;
1347 _err = ReverseKeyboardFocus(inWindow);
1348 if (_err != noErr) return PyMac_Error(_err);
1349 Py_INCREF(Py_None);
1350 _res = Py_None;
1351 return _res;
1352}
1353
1354static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1355 PyObject *_self;
1356 PyObject *_args;
1357{
1358 PyObject *_res = NULL;
1359 OSErr _err;
1360 WindowPtr inWindow;
1361 if (!PyArg_ParseTuple(_args, "O&",
1362 WinObj_Convert, &inWindow))
1363 return NULL;
1364 _err = ClearKeyboardFocus(inWindow);
1365 if (_err != noErr) return PyMac_Error(_err);
1366 Py_INCREF(Py_None);
1367 _res = Py_None;
1368 return _res;
1369}
1370
Jack Jansene0581891999-02-07 14:02:03 +00001371static PyObject *Ctl_as_Control(_self, _args)
1372 PyObject *_self;
1373 PyObject *_args;
1374{
1375 PyObject *_res = NULL;
1376 ControlHandle _rv;
1377 Handle h;
1378 if (!PyArg_ParseTuple(_args, "O&",
1379 ResObj_Convert, &h))
1380 return NULL;
1381 _rv = as_Control(h);
1382 _res = Py_BuildValue("O&",
1383 CtlObj_New, _rv);
1384 return _res;
1385}
1386
Guido van Rossum17448e21995-01-30 11:53:55 +00001387static PyMethodDef Ctl_methods[] = {
1388 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001389 "(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 +00001390 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001391 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001392 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1393 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001394 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001395 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001396 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001397 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1398 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1399 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1400 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1401 "(WindowPtr inWindow) -> None"},
1402 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1403 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1404 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1405 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1406 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1407 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1408 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1409 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1410 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1411 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1412 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1413 "(WindowPtr inWindow) -> None"},
1414 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1415 "(WindowPtr inWindow) -> None"},
1416 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1417 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001418 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1419 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001420 {NULL, NULL, 0}
1421};
1422
1423
1424
Jack Jansen8387af61999-03-13 23:07:32 +00001425PyObject *CtlObj_NewUnmanaged(itself)
1426 ControlHandle itself;
1427{
1428 ControlObject *it;
1429 if (itself == NULL) return PyMac_Error(resNotFound);
1430 it = PyObject_NEW(ControlObject, &Control_Type);
1431 if (it == NULL) return NULL;
1432 it->ob_itself = itself;
1433 return (PyObject *)it;
1434}
1435
Guido van Rossum17448e21995-01-30 11:53:55 +00001436PyObject *
1437CtlObj_WhichControl(ControlHandle c)
1438{
1439 PyObject *it;
1440
Guido van Rossum17448e21995-01-30 11:53:55 +00001441 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00001442 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00001443 else {
1444 it = (PyObject *) GetControlReference(c);
1445 /*
1446 ** If the refcon is zero or doesn't point back to the Python object
1447 ** the control is not ours. Return a temporary object.
1448 */
1449 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1450 return CtlObj_NewUnmanaged(c);
1451 }
Guido van Rossum17448e21995-01-30 11:53:55 +00001452 Py_INCREF(it);
1453 return it;
1454}
1455
Jack Jansen848250c1998-05-28 14:20:09 +00001456static int
1457settrackfunc(obj)
1458 PyObject *obj;
1459{
1460 if (tracker) {
1461 PyErr_SetString(Ctl_Error, "Tracker function in use");
1462 return 0;
1463 }
1464 tracker = obj;
1465 Py_INCREF(tracker);
1466}
1467
1468static void
1469clrtrackfunc()
1470{
1471 Py_XDECREF(tracker);
1472 tracker = 0;
1473}
1474
1475static pascal void
1476mytracker(ctl, part)
1477 ControlHandle ctl;
1478 short part;
1479{
1480 PyObject *args, *rv=0;
1481
1482 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1483 if (args && tracker) {
1484 rv = PyEval_CallObject(tracker, args);
1485 Py_DECREF(args);
1486 }
1487 if (rv)
1488 Py_DECREF(rv);
1489 else
Jack Jansendeff89c1998-10-12 20:53:15 +00001490 PySys_WriteStderr("TrackControl: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001491}
1492
Guido van Rossum17448e21995-01-30 11:53:55 +00001493
1494void initCtl()
1495{
1496 PyObject *m;
1497 PyObject *d;
1498
1499
1500
Jack Jansen848250c1998-05-28 14:20:09 +00001501 mytracker_upp = NewControlActionProc(mytracker);
1502
Guido van Rossum17448e21995-01-30 11:53:55 +00001503
1504 m = Py_InitModule("Ctl", Ctl_methods);
1505 d = PyModule_GetDict(m);
1506 Ctl_Error = PyMac_GetOSErrException();
1507 if (Ctl_Error == NULL ||
1508 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1509 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001510 Control_Type.ob_type = &PyType_Type;
1511 Py_INCREF(&Control_Type);
1512 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1513 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001514}
1515
1516/* ========================= End module Ctl ========================= */
1517