blob: 42a82d9ac8c006b6eac7c84a1a21223fe0ac96a4 [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
1019PyTypeObject Control_Type = {
1020 PyObject_HEAD_INIT(&PyType_Type)
1021 0, /*ob_size*/
1022 "Control", /*tp_name*/
1023 sizeof(ControlObject), /*tp_basicsize*/
1024 0, /*tp_itemsize*/
1025 /* methods */
1026 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1027 0, /*tp_print*/
1028 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1029 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
1030};
1031
1032/* -------------------- End object type Control --------------------- */
1033
1034
1035static PyObject *Ctl_NewControl(_self, _args)
1036 PyObject *_self;
1037 PyObject *_args;
1038{
1039 PyObject *_res = NULL;
1040 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001041 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001042 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001043 Str255 controlTitle;
1044 Boolean initiallyVisible;
1045 SInt16 initialValue;
1046 SInt16 minimumValue;
1047 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001048 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001049 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001050 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001051 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001052 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001053 PyMac_GetStr255, controlTitle,
1054 &initiallyVisible,
1055 &initialValue,
1056 &minimumValue,
1057 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001058 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001059 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001060 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001061 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001062 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001063 controlTitle,
1064 initiallyVisible,
1065 initialValue,
1066 minimumValue,
1067 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001068 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001069 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001070 _res = Py_BuildValue("O&",
1071 CtlObj_New, _rv);
1072 return _res;
1073}
1074
1075static PyObject *Ctl_GetNewControl(_self, _args)
1076 PyObject *_self;
1077 PyObject *_args;
1078{
1079 PyObject *_res = NULL;
1080 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001081 SInt16 resourceID;
1082 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001083 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001084 &resourceID,
1085 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001086 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001087 _rv = GetNewControl(resourceID,
1088 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001089 _res = Py_BuildValue("O&",
1090 CtlObj_New, _rv);
1091 return _res;
1092}
1093
Guido van Rossum17448e21995-01-30 11:53:55 +00001094static PyObject *Ctl_DrawControls(_self, _args)
1095 PyObject *_self;
1096 PyObject *_args;
1097{
1098 PyObject *_res = NULL;
1099 WindowPtr theWindow;
1100 if (!PyArg_ParseTuple(_args, "O&",
1101 WinObj_Convert, &theWindow))
1102 return NULL;
1103 DrawControls(theWindow);
1104 Py_INCREF(Py_None);
1105 _res = Py_None;
1106 return _res;
1107}
1108
Guido van Rossum17448e21995-01-30 11:53:55 +00001109static PyObject *Ctl_UpdateControls(_self, _args)
1110 PyObject *_self;
1111 PyObject *_args;
1112{
1113 PyObject *_res = NULL;
1114 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001115 RgnHandle updateRegion;
1116 if (!PyArg_ParseTuple(_args, "O&O&",
1117 WinObj_Convert, &theWindow,
1118 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001119 return NULL;
1120 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001121 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001122 Py_INCREF(Py_None);
1123 _res = Py_None;
1124 return _res;
1125}
1126
1127static PyObject *Ctl_FindControl(_self, _args)
1128 PyObject *_self;
1129 PyObject *_args;
1130{
1131 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001132 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001133 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001134 WindowPtr theWindow;
1135 ControlHandle theControl;
1136 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001137 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001138 WinObj_Convert, &theWindow))
1139 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001140 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001141 theWindow,
1142 &theControl);
1143 _res = Py_BuildValue("hO&",
1144 _rv,
1145 CtlObj_WhichControl, theControl);
1146 return _res;
1147}
1148
Jack Jansen21f96871998-02-20 16:02:09 +00001149static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1150 PyObject *_self;
1151 PyObject *_args;
1152{
1153 PyObject *_res = NULL;
1154 ControlHandle _rv;
1155 Point inWhere;
1156 WindowPtr inWindow;
1157 SInt16 outPart;
1158 if (!PyArg_ParseTuple(_args, "O&O&",
1159 PyMac_GetPoint, &inWhere,
1160 WinObj_Convert, &inWindow))
1161 return NULL;
1162 _rv = FindControlUnderMouse(inWhere,
1163 inWindow,
1164 &outPart);
1165 _res = Py_BuildValue("O&h",
1166 CtlObj_New, _rv,
1167 outPart);
1168 return _res;
1169}
1170
1171static PyObject *Ctl_IdleControls(_self, _args)
1172 PyObject *_self;
1173 PyObject *_args;
1174{
1175 PyObject *_res = NULL;
1176 WindowPtr inWindow;
1177 if (!PyArg_ParseTuple(_args, "O&",
1178 WinObj_Convert, &inWindow))
1179 return NULL;
1180 IdleControls(inWindow);
1181 Py_INCREF(Py_None);
1182 _res = Py_None;
1183 return _res;
1184}
1185
1186static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1187 PyObject *_self;
1188 PyObject *_args;
1189{
1190 PyObject *_res = NULL;
1191 OSErr _err;
1192 WindowPtr inWindow;
1193 FSSpec inDumpFile;
1194 if (!PyArg_ParseTuple(_args, "O&O&",
1195 WinObj_Convert, &inWindow,
1196 PyMac_GetFSSpec, &inDumpFile))
1197 return NULL;
1198 _err = DumpControlHierarchy(inWindow,
1199 &inDumpFile);
1200 if (_err != noErr) return PyMac_Error(_err);
1201 Py_INCREF(Py_None);
1202 _res = Py_None;
1203 return _res;
1204}
1205
1206static PyObject *Ctl_CreateRootControl(_self, _args)
1207 PyObject *_self;
1208 PyObject *_args;
1209{
1210 PyObject *_res = NULL;
1211 OSErr _err;
1212 WindowPtr inWindow;
1213 ControlHandle outControl;
1214 if (!PyArg_ParseTuple(_args, "O&",
1215 WinObj_Convert, &inWindow))
1216 return NULL;
1217 _err = CreateRootControl(inWindow,
1218 &outControl);
1219 if (_err != noErr) return PyMac_Error(_err);
1220 _res = Py_BuildValue("O&",
1221 CtlObj_WhichControl, outControl);
1222 return _res;
1223}
1224
1225static PyObject *Ctl_GetRootControl(_self, _args)
1226 PyObject *_self;
1227 PyObject *_args;
1228{
1229 PyObject *_res = NULL;
1230 OSErr _err;
1231 WindowPtr inWindow;
1232 ControlHandle outControl;
1233 if (!PyArg_ParseTuple(_args, "O&",
1234 WinObj_Convert, &inWindow))
1235 return NULL;
1236 _err = GetRootControl(inWindow,
1237 &outControl);
1238 if (_err != noErr) return PyMac_Error(_err);
1239 _res = Py_BuildValue("O&",
1240 CtlObj_WhichControl, outControl);
1241 return _res;
1242}
1243
1244static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1245 PyObject *_self;
1246 PyObject *_args;
1247{
1248 PyObject *_res = NULL;
1249 OSErr _err;
1250 WindowPtr inWindow;
1251 ControlHandle outControl;
1252 if (!PyArg_ParseTuple(_args, "O&",
1253 WinObj_Convert, &inWindow))
1254 return NULL;
1255 _err = GetKeyboardFocus(inWindow,
1256 &outControl);
1257 if (_err != noErr) return PyMac_Error(_err);
1258 _res = Py_BuildValue("O&",
1259 CtlObj_WhichControl, outControl);
1260 return _res;
1261}
1262
1263static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1264 PyObject *_self;
1265 PyObject *_args;
1266{
1267 PyObject *_res = NULL;
1268 OSErr _err;
1269 WindowPtr inWindow;
1270 ControlHandle inControl;
1271 ControlFocusPart inPart;
1272 if (!PyArg_ParseTuple(_args, "O&O&h",
1273 WinObj_Convert, &inWindow,
1274 CtlObj_Convert, &inControl,
1275 &inPart))
1276 return NULL;
1277 _err = SetKeyboardFocus(inWindow,
1278 inControl,
1279 inPart);
1280 if (_err != noErr) return PyMac_Error(_err);
1281 Py_INCREF(Py_None);
1282 _res = Py_None;
1283 return _res;
1284}
1285
1286static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1287 PyObject *_self;
1288 PyObject *_args;
1289{
1290 PyObject *_res = NULL;
1291 OSErr _err;
1292 WindowPtr inWindow;
1293 if (!PyArg_ParseTuple(_args, "O&",
1294 WinObj_Convert, &inWindow))
1295 return NULL;
1296 _err = AdvanceKeyboardFocus(inWindow);
1297 if (_err != noErr) return PyMac_Error(_err);
1298 Py_INCREF(Py_None);
1299 _res = Py_None;
1300 return _res;
1301}
1302
1303static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1304 PyObject *_self;
1305 PyObject *_args;
1306{
1307 PyObject *_res = NULL;
1308 OSErr _err;
1309 WindowPtr inWindow;
1310 if (!PyArg_ParseTuple(_args, "O&",
1311 WinObj_Convert, &inWindow))
1312 return NULL;
1313 _err = ReverseKeyboardFocus(inWindow);
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_ClearKeyboardFocus(_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 = ClearKeyboardFocus(inWindow);
1331 if (_err != noErr) return PyMac_Error(_err);
1332 Py_INCREF(Py_None);
1333 _res = Py_None;
1334 return _res;
1335}
1336
Jack Jansene0581891999-02-07 14:02:03 +00001337static PyObject *Ctl_as_Control(_self, _args)
1338 PyObject *_self;
1339 PyObject *_args;
1340{
1341 PyObject *_res = NULL;
1342 ControlHandle _rv;
1343 Handle h;
1344 if (!PyArg_ParseTuple(_args, "O&",
1345 ResObj_Convert, &h))
1346 return NULL;
1347 _rv = as_Control(h);
1348 _res = Py_BuildValue("O&",
1349 CtlObj_New, _rv);
1350 return _res;
1351}
1352
Guido van Rossum17448e21995-01-30 11:53:55 +00001353static PyMethodDef Ctl_methods[] = {
1354 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001355 "(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 +00001356 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001357 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001358 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1359 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001360 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001361 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001362 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001363 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1364 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1365 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1366 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1367 "(WindowPtr inWindow) -> None"},
1368 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1369 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1370 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1371 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1372 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1373 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1374 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1375 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1376 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1377 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1378 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1379 "(WindowPtr inWindow) -> None"},
1380 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1381 "(WindowPtr inWindow) -> None"},
1382 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1383 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001384 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1385 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001386 {NULL, NULL, 0}
1387};
1388
1389
1390
1391PyObject *
1392CtlObj_WhichControl(ControlHandle c)
1393{
1394 PyObject *it;
1395
1396 /* XXX What if we find a control belonging to some other package? */
1397 if (c == NULL)
1398 it = NULL;
1399 else
Jack Jansen85ae4a81997-04-08 15:26:03 +00001400 it = (PyObject *) GetControlReference(c);
Guido van Rossum17448e21995-01-30 11:53:55 +00001401 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1402 it = Py_None;
1403 Py_INCREF(it);
1404 return it;
1405}
1406
Jack Jansen848250c1998-05-28 14:20:09 +00001407static int
1408settrackfunc(obj)
1409 PyObject *obj;
1410{
1411 if (tracker) {
1412 PyErr_SetString(Ctl_Error, "Tracker function in use");
1413 return 0;
1414 }
1415 tracker = obj;
1416 Py_INCREF(tracker);
1417}
1418
1419static void
1420clrtrackfunc()
1421{
1422 Py_XDECREF(tracker);
1423 tracker = 0;
1424}
1425
1426static pascal void
1427mytracker(ctl, part)
1428 ControlHandle ctl;
1429 short part;
1430{
1431 PyObject *args, *rv=0;
1432
1433 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1434 if (args && tracker) {
1435 rv = PyEval_CallObject(tracker, args);
1436 Py_DECREF(args);
1437 }
1438 if (rv)
1439 Py_DECREF(rv);
1440 else
Jack Jansendeff89c1998-10-12 20:53:15 +00001441 PySys_WriteStderr("TrackControl: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001442}
1443
Guido van Rossum17448e21995-01-30 11:53:55 +00001444
1445void initCtl()
1446{
1447 PyObject *m;
1448 PyObject *d;
1449
1450
1451
Jack Jansen848250c1998-05-28 14:20:09 +00001452 mytracker_upp = NewControlActionProc(mytracker);
1453
Guido van Rossum17448e21995-01-30 11:53:55 +00001454
1455 m = Py_InitModule("Ctl", Ctl_methods);
1456 d = PyModule_GetDict(m);
1457 Ctl_Error = PyMac_GetOSErrException();
1458 if (Ctl_Error == NULL ||
1459 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1460 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001461 Control_Type.ob_type = &PyType_Type;
1462 Py_INCREF(&Control_Type);
1463 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1464 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001465}
1466
1467/* ========================= End module Ctl ========================= */
1468