blob: 07fff2990411351c641b99b6b4b51eecda5e97df [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;
465 if (!PyArg_ParseTuple(_args, "O&",
466 PyMac_GetStr255, title))
467 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000468 GetControlTitle(_self->ob_itself,
469 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000470 Py_INCREF(Py_None);
471 _res = Py_None;
472 return _res;
473}
474
Jack Jansenae8a68f1995-06-06 12:55:40 +0000475static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000476 ControlObject *_self;
477 PyObject *_args;
478{
479 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000480 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000481 if (!PyArg_ParseTuple(_args, ""))
482 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000483 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000484 _res = Py_BuildValue("h",
485 _rv);
486 return _res;
487}
488
Jack Jansen7d0bc831995-06-09 20:56:31 +0000489static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000490 ControlObject *_self;
491 PyObject *_args;
492{
493 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000494 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000495 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000496 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000497 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000498 SetControlValue(_self->ob_itself,
499 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000500 Py_INCREF(Py_None);
501 _res = Py_None;
502 return _res;
503}
504
Jack Jansenae8a68f1995-06-06 12:55:40 +0000505static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000506 ControlObject *_self;
507 PyObject *_args;
508{
509 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000510 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000511 if (!PyArg_ParseTuple(_args, ""))
512 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000513 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000514 _res = Py_BuildValue("h",
515 _rv);
516 return _res;
517}
518
Jack Jansen7d0bc831995-06-09 20:56:31 +0000519static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000520 ControlObject *_self;
521 PyObject *_args;
522{
523 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000524 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000525 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000526 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000527 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000528 SetControlMinimum(_self->ob_itself,
529 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000530 Py_INCREF(Py_None);
531 _res = Py_None;
532 return _res;
533}
534
Jack Jansenae8a68f1995-06-06 12:55:40 +0000535static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000536 ControlObject *_self;
537 PyObject *_args;
538{
539 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000540 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000541 if (!PyArg_ParseTuple(_args, ""))
542 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000543 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000544 _res = Py_BuildValue("h",
545 _rv);
546 return _res;
547}
548
Jack Jansen7d0bc831995-06-09 20:56:31 +0000549static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000550 ControlObject *_self;
551 PyObject *_args;
552{
553 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000554 SInt16 newMaximum;
555 if (!PyArg_ParseTuple(_args, "h",
556 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000557 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000558 SetControlMaximum(_self->ob_itself,
559 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000560 Py_INCREF(Py_None);
561 _res = Py_None;
562 return _res;
563}
564
Jack Jansen7d0bc831995-06-09 20:56:31 +0000565static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000566 ControlObject *_self;
567 PyObject *_args;
568{
569 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000570 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000571 if (!PyArg_ParseTuple(_args, ""))
572 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000573 _rv = GetControlVariant(_self->ob_itself);
574 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000575 _rv);
576 return _res;
577}
578
Jack Jansen7d0bc831995-06-09 20:56:31 +0000579static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000580 ControlObject *_self;
581 PyObject *_args;
582{
583 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000584 SInt32 data;
585 if (!PyArg_ParseTuple(_args, "l",
586 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000587 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000588 SetControlReference(_self->ob_itself,
589 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000590 Py_INCREF(Py_None);
591 _res = Py_None;
592 return _res;
593}
594
Jack Jansen7d0bc831995-06-09 20:56:31 +0000595static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000596 ControlObject *_self;
597 PyObject *_args;
598{
599 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000600 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000601 if (!PyArg_ParseTuple(_args, ""))
602 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000603 _rv = GetControlReference(_self->ob_itself);
604 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000605 _rv);
606 return _res;
607}
608
Jack Jansenc7fefed1997-08-15 14:32:18 +0000609static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
610 ControlObject *_self;
611 PyObject *_args;
612{
613 PyObject *_res = NULL;
614 Boolean _rv;
615 AuxCtlHandle acHndl;
616 if (!PyArg_ParseTuple(_args, ""))
617 return NULL;
618 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
619 &acHndl);
620 _res = Py_BuildValue("bO&",
621 _rv,
622 ResObj_New, acHndl);
623 return _res;
624}
625
626static PyObject *CtlObj_SetControlColor(_self, _args)
627 ControlObject *_self;
628 PyObject *_args;
629{
630 PyObject *_res = NULL;
631 CCTabHandle newColorTable;
632 if (!PyArg_ParseTuple(_args, "O&",
633 ResObj_Convert, &newColorTable))
634 return NULL;
635 SetControlColor(_self->ob_itself,
636 newColorTable);
637 Py_INCREF(Py_None);
638 _res = Py_None;
639 return _res;
640}
641
Jack Jansen21f96871998-02-20 16:02:09 +0000642static PyObject *CtlObj_SendControlMessage(_self, _args)
643 ControlObject *_self;
644 PyObject *_args;
645{
646 PyObject *_res = NULL;
647 SInt32 _rv;
648 SInt16 inMessage;
649 SInt32 inParam;
650 if (!PyArg_ParseTuple(_args, "hl",
651 &inMessage,
652 &inParam))
653 return NULL;
654 _rv = SendControlMessage(_self->ob_itself,
655 inMessage,
656 inParam);
657 _res = Py_BuildValue("l",
658 _rv);
659 return _res;
660}
661
662static PyObject *CtlObj_EmbedControl(_self, _args)
663 ControlObject *_self;
664 PyObject *_args;
665{
666 PyObject *_res = NULL;
667 OSErr _err;
668 ControlHandle inContainer;
669 if (!PyArg_ParseTuple(_args, "O&",
670 CtlObj_Convert, &inContainer))
671 return NULL;
672 _err = EmbedControl(_self->ob_itself,
673 inContainer);
674 if (_err != noErr) return PyMac_Error(_err);
675 Py_INCREF(Py_None);
676 _res = Py_None;
677 return _res;
678}
679
680static PyObject *CtlObj_AutoEmbedControl(_self, _args)
681 ControlObject *_self;
682 PyObject *_args;
683{
684 PyObject *_res = NULL;
685 OSErr _err;
686 WindowPtr inWindow;
687 if (!PyArg_ParseTuple(_args, "O&",
688 WinObj_Convert, &inWindow))
689 return NULL;
690 _err = AutoEmbedControl(_self->ob_itself,
691 inWindow);
692 if (_err != noErr) return PyMac_Error(_err);
693 Py_INCREF(Py_None);
694 _res = Py_None;
695 return _res;
696}
697
698static PyObject *CtlObj_GetSuperControl(_self, _args)
699 ControlObject *_self;
700 PyObject *_args;
701{
702 PyObject *_res = NULL;
703 OSErr _err;
704 ControlHandle outParent;
705 if (!PyArg_ParseTuple(_args, ""))
706 return NULL;
707 _err = GetSuperControl(_self->ob_itself,
708 &outParent);
709 if (_err != noErr) return PyMac_Error(_err);
710 _res = Py_BuildValue("O&",
711 CtlObj_WhichControl, outParent);
712 return _res;
713}
714
715static PyObject *CtlObj_CountSubControls(_self, _args)
716 ControlObject *_self;
717 PyObject *_args;
718{
719 PyObject *_res = NULL;
720 OSErr _err;
721 SInt16 outNumChildren;
722 if (!PyArg_ParseTuple(_args, ""))
723 return NULL;
724 _err = CountSubControls(_self->ob_itself,
725 &outNumChildren);
726 if (_err != noErr) return PyMac_Error(_err);
727 _res = Py_BuildValue("h",
728 outNumChildren);
729 return _res;
730}
731
732static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
733 ControlObject *_self;
734 PyObject *_args;
735{
736 PyObject *_res = NULL;
737 OSErr _err;
738 SInt16 inIndex;
739 ControlHandle outSubControl;
740 if (!PyArg_ParseTuple(_args, "h",
741 &inIndex))
742 return NULL;
743 _err = GetIndexedSubControl(_self->ob_itself,
744 inIndex,
745 &outSubControl);
746 if (_err != noErr) return PyMac_Error(_err);
747 _res = Py_BuildValue("O&",
748 CtlObj_WhichControl, outSubControl);
749 return _res;
750}
751
752static PyObject *CtlObj_SetControlSupervisor(_self, _args)
753 ControlObject *_self;
754 PyObject *_args;
755{
756 PyObject *_res = NULL;
757 OSErr _err;
758 ControlHandle inBoss;
759 if (!PyArg_ParseTuple(_args, "O&",
760 CtlObj_Convert, &inBoss))
761 return NULL;
762 _err = SetControlSupervisor(_self->ob_itself,
763 inBoss);
764 if (_err != noErr) return PyMac_Error(_err);
765 Py_INCREF(Py_None);
766 _res = Py_None;
767 return _res;
768}
769
770static PyObject *CtlObj_GetControlFeatures(_self, _args)
771 ControlObject *_self;
772 PyObject *_args;
773{
774 PyObject *_res = NULL;
775 OSErr _err;
776 UInt32 outFeatures;
777 if (!PyArg_ParseTuple(_args, ""))
778 return NULL;
779 _err = GetControlFeatures(_self->ob_itself,
780 &outFeatures);
781 if (_err != noErr) return PyMac_Error(_err);
782 _res = Py_BuildValue("l",
783 outFeatures);
784 return _res;
785}
786
787static PyObject *CtlObj_GetControlDataSize(_self, _args)
788 ControlObject *_self;
789 PyObject *_args;
790{
791 PyObject *_res = NULL;
792 OSErr _err;
793 ControlPartCode inPart;
794 ResType inTagName;
795 Size outMaxSize;
796 if (!PyArg_ParseTuple(_args, "hO&",
797 &inPart,
798 PyMac_GetOSType, &inTagName))
799 return NULL;
800 _err = GetControlDataSize(_self->ob_itself,
801 inPart,
802 inTagName,
803 &outMaxSize);
804 if (_err != noErr) return PyMac_Error(_err);
805 _res = Py_BuildValue("l",
806 outMaxSize);
807 return _res;
808}
809
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000810static PyObject *CtlObj_as_Resource(_self, _args)
811 ControlObject *_self;
812 PyObject *_args;
813{
814 PyObject *_res = NULL;
815
816 return ResObj_New((Handle)_self->ob_itself);
817
818}
819
Jack Jansencfb60ee1996-10-01 10:46:46 +0000820static PyObject *CtlObj_DisposeControl(_self, _args)
821 ControlObject *_self;
822 PyObject *_args;
823{
824 PyObject *_res = NULL;
825
826 if (!PyArg_ParseTuple(_args, ""))
827 return NULL;
828 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +0000829 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +0000830 DisposeControl(_self->ob_itself);
831 _self->ob_itself = NULL;
832 }
833 Py_INCREF(Py_None);
834 _res = Py_None;
835 return _res;
836
837}
838
Jack Jansen848250c1998-05-28 14:20:09 +0000839static PyObject *CtlObj_TrackControl(_self, _args)
840 ControlObject *_self;
841 PyObject *_args;
842{
843 PyObject *_res = NULL;
844
845 ControlPartCode _rv;
846 Point startPoint;
847 ControlActionUPP upp = 0;
848 PyObject *callback = 0;
849
850 if (!PyArg_ParseTuple(_args, "O&|O",
851 PyMac_GetPoint, &startPoint, &callback))
852 return NULL;
853 if (callback && callback != Py_None) {
854 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
855 upp = (ControlActionUPP)-1;
856 else {
857 settrackfunc(callback);
858 upp = mytracker_upp;
859 }
860 }
861 _rv = TrackControl(_self->ob_itself,
862 startPoint,
863 upp);
864 clrtrackfunc();
865 _res = Py_BuildValue("h",
866 _rv);
867 return _res;
868
869}
870
Jack Jansen4c704131998-06-19 13:35:14 +0000871static PyObject *CtlObj_GetPopupData(_self, _args)
872 ControlObject *_self;
873 PyObject *_args;
874{
875 PyObject *_res = NULL;
876
877 PopupPrivateDataHandle hdl;
878
879 if ( (*_self->ob_itself)->contrlData == NULL ) {
880 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
881 return 0;
882 }
883 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
884 HLock((Handle)hdl);
885 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
886 HUnlock((Handle)hdl);
887 return _res;
888
889}
890
891static PyObject *CtlObj_SetPopupData(_self, _args)
892 ControlObject *_self;
893 PyObject *_args;
894{
895 PyObject *_res = NULL;
896
897 PopupPrivateDataHandle hdl;
898 MenuHandle mHandle;
899 short mID;
900
901 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
902 return 0;
903 if ( (*_self->ob_itself)->contrlData == NULL ) {
904 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
905 return 0;
906 }
907 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
908 (*hdl)->mHandle = mHandle;
909 (*hdl)->mID = mID;
910 Py_INCREF(Py_None);
911 return Py_None;
912
913}
914
Guido van Rossum17448e21995-01-30 11:53:55 +0000915static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +0000916 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
917 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000918 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
919 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000920 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
921 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000922 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
923 "() -> (Boolean _rv)"},
924 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
925 "() -> (Boolean _rv)"},
926 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
927 "() -> None"},
928 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
929 "() -> None"},
930 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
931 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000932 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
933 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000934 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
935 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
936 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
937 "(ControlFontStyleRec inStyle) -> None"},
938 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
939 "() -> None"},
940 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
941 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000942 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000943 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000944 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000945 "(Point testPoint) -> (ControlPartCode _rv)"},
946 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
947 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000948 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000949 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000950 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000951 "(SInt16 w, SInt16 h) -> None"},
952 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
953 "(Str255 title) -> None"},
954 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
955 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000956 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000957 "() -> (SInt16 _rv)"},
958 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
959 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000960 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000961 "() -> (SInt16 _rv)"},
962 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
963 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000964 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000965 "() -> (SInt16 _rv)"},
966 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
967 "(SInt16 newMaximum) -> None"},
968 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000969 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000970 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
971 "(SInt32 data) -> None"},
972 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
973 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +0000974 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
975 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
976 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
977 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000978 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
979 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
980 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
981 "(ControlHandle inContainer) -> None"},
982 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
983 "(WindowPtr inWindow) -> None"},
984 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
985 "() -> (ControlHandle outParent)"},
986 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
987 "() -> (SInt16 outNumChildren)"},
988 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
989 "(SInt16 inIndex) -> (ControlHandle outSubControl)"},
990 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
991 "(ControlHandle inBoss) -> None"},
992 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
993 "() -> (UInt32 outFeatures)"},
994 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
995 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000996 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
997 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +0000998 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
999 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001000 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
1001 NULL},
Jack Jansen4c704131998-06-19 13:35:14 +00001002 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1003 NULL},
1004 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1005 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001006 {NULL, NULL, 0}
1007};
1008
1009PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1010
1011static PyObject *CtlObj_getattr(self, name)
1012 ControlObject *self;
1013 char *name;
1014{
1015 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1016}
1017
1018#define CtlObj_setattr NULL
1019
1020PyTypeObject Control_Type = {
1021 PyObject_HEAD_INIT(&PyType_Type)
1022 0, /*ob_size*/
1023 "Control", /*tp_name*/
1024 sizeof(ControlObject), /*tp_basicsize*/
1025 0, /*tp_itemsize*/
1026 /* methods */
1027 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1028 0, /*tp_print*/
1029 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1030 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
1031};
1032
1033/* -------------------- End object type Control --------------------- */
1034
1035
1036static PyObject *Ctl_NewControl(_self, _args)
1037 PyObject *_self;
1038 PyObject *_args;
1039{
1040 PyObject *_res = NULL;
1041 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001042 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001043 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001044 Str255 controlTitle;
1045 Boolean initiallyVisible;
1046 SInt16 initialValue;
1047 SInt16 minimumValue;
1048 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001049 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001050 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001051 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001052 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001053 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001054 PyMac_GetStr255, controlTitle,
1055 &initiallyVisible,
1056 &initialValue,
1057 &minimumValue,
1058 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001059 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001060 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001061 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001062 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001063 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001064 controlTitle,
1065 initiallyVisible,
1066 initialValue,
1067 minimumValue,
1068 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001069 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001070 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001071 _res = Py_BuildValue("O&",
1072 CtlObj_New, _rv);
1073 return _res;
1074}
1075
1076static PyObject *Ctl_GetNewControl(_self, _args)
1077 PyObject *_self;
1078 PyObject *_args;
1079{
1080 PyObject *_res = NULL;
1081 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001082 SInt16 resourceID;
1083 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001084 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001085 &resourceID,
1086 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001087 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001088 _rv = GetNewControl(resourceID,
1089 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001090 _res = Py_BuildValue("O&",
1091 CtlObj_New, _rv);
1092 return _res;
1093}
1094
Guido van Rossum17448e21995-01-30 11:53:55 +00001095static PyObject *Ctl_DrawControls(_self, _args)
1096 PyObject *_self;
1097 PyObject *_args;
1098{
1099 PyObject *_res = NULL;
1100 WindowPtr theWindow;
1101 if (!PyArg_ParseTuple(_args, "O&",
1102 WinObj_Convert, &theWindow))
1103 return NULL;
1104 DrawControls(theWindow);
1105 Py_INCREF(Py_None);
1106 _res = Py_None;
1107 return _res;
1108}
1109
Guido van Rossum17448e21995-01-30 11:53:55 +00001110static PyObject *Ctl_UpdateControls(_self, _args)
1111 PyObject *_self;
1112 PyObject *_args;
1113{
1114 PyObject *_res = NULL;
1115 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001116 RgnHandle updateRegion;
1117 if (!PyArg_ParseTuple(_args, "O&O&",
1118 WinObj_Convert, &theWindow,
1119 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001120 return NULL;
1121 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001122 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001123 Py_INCREF(Py_None);
1124 _res = Py_None;
1125 return _res;
1126}
1127
1128static PyObject *Ctl_FindControl(_self, _args)
1129 PyObject *_self;
1130 PyObject *_args;
1131{
1132 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001133 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001134 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001135 WindowPtr theWindow;
1136 ControlHandle theControl;
1137 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001138 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001139 WinObj_Convert, &theWindow))
1140 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001141 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001142 theWindow,
1143 &theControl);
1144 _res = Py_BuildValue("hO&",
1145 _rv,
1146 CtlObj_WhichControl, theControl);
1147 return _res;
1148}
1149
Jack Jansen21f96871998-02-20 16:02:09 +00001150static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1151 PyObject *_self;
1152 PyObject *_args;
1153{
1154 PyObject *_res = NULL;
1155 ControlHandle _rv;
1156 Point inWhere;
1157 WindowPtr inWindow;
1158 SInt16 outPart;
1159 if (!PyArg_ParseTuple(_args, "O&O&",
1160 PyMac_GetPoint, &inWhere,
1161 WinObj_Convert, &inWindow))
1162 return NULL;
1163 _rv = FindControlUnderMouse(inWhere,
1164 inWindow,
1165 &outPart);
1166 _res = Py_BuildValue("O&h",
1167 CtlObj_New, _rv,
1168 outPart);
1169 return _res;
1170}
1171
1172static PyObject *Ctl_IdleControls(_self, _args)
1173 PyObject *_self;
1174 PyObject *_args;
1175{
1176 PyObject *_res = NULL;
1177 WindowPtr inWindow;
1178 if (!PyArg_ParseTuple(_args, "O&",
1179 WinObj_Convert, &inWindow))
1180 return NULL;
1181 IdleControls(inWindow);
1182 Py_INCREF(Py_None);
1183 _res = Py_None;
1184 return _res;
1185}
1186
1187static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1188 PyObject *_self;
1189 PyObject *_args;
1190{
1191 PyObject *_res = NULL;
1192 OSErr _err;
1193 WindowPtr inWindow;
1194 FSSpec inDumpFile;
1195 if (!PyArg_ParseTuple(_args, "O&O&",
1196 WinObj_Convert, &inWindow,
1197 PyMac_GetFSSpec, &inDumpFile))
1198 return NULL;
1199 _err = DumpControlHierarchy(inWindow,
1200 &inDumpFile);
1201 if (_err != noErr) return PyMac_Error(_err);
1202 Py_INCREF(Py_None);
1203 _res = Py_None;
1204 return _res;
1205}
1206
1207static PyObject *Ctl_CreateRootControl(_self, _args)
1208 PyObject *_self;
1209 PyObject *_args;
1210{
1211 PyObject *_res = NULL;
1212 OSErr _err;
1213 WindowPtr inWindow;
1214 ControlHandle outControl;
1215 if (!PyArg_ParseTuple(_args, "O&",
1216 WinObj_Convert, &inWindow))
1217 return NULL;
1218 _err = CreateRootControl(inWindow,
1219 &outControl);
1220 if (_err != noErr) return PyMac_Error(_err);
1221 _res = Py_BuildValue("O&",
1222 CtlObj_WhichControl, outControl);
1223 return _res;
1224}
1225
1226static PyObject *Ctl_GetRootControl(_self, _args)
1227 PyObject *_self;
1228 PyObject *_args;
1229{
1230 PyObject *_res = NULL;
1231 OSErr _err;
1232 WindowPtr inWindow;
1233 ControlHandle outControl;
1234 if (!PyArg_ParseTuple(_args, "O&",
1235 WinObj_Convert, &inWindow))
1236 return NULL;
1237 _err = GetRootControl(inWindow,
1238 &outControl);
1239 if (_err != noErr) return PyMac_Error(_err);
1240 _res = Py_BuildValue("O&",
1241 CtlObj_WhichControl, outControl);
1242 return _res;
1243}
1244
1245static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1246 PyObject *_self;
1247 PyObject *_args;
1248{
1249 PyObject *_res = NULL;
1250 OSErr _err;
1251 WindowPtr inWindow;
1252 ControlHandle outControl;
1253 if (!PyArg_ParseTuple(_args, "O&",
1254 WinObj_Convert, &inWindow))
1255 return NULL;
1256 _err = GetKeyboardFocus(inWindow,
1257 &outControl);
1258 if (_err != noErr) return PyMac_Error(_err);
1259 _res = Py_BuildValue("O&",
1260 CtlObj_WhichControl, outControl);
1261 return _res;
1262}
1263
1264static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1265 PyObject *_self;
1266 PyObject *_args;
1267{
1268 PyObject *_res = NULL;
1269 OSErr _err;
1270 WindowPtr inWindow;
1271 ControlHandle inControl;
1272 ControlFocusPart inPart;
1273 if (!PyArg_ParseTuple(_args, "O&O&h",
1274 WinObj_Convert, &inWindow,
1275 CtlObj_Convert, &inControl,
1276 &inPart))
1277 return NULL;
1278 _err = SetKeyboardFocus(inWindow,
1279 inControl,
1280 inPart);
1281 if (_err != noErr) return PyMac_Error(_err);
1282 Py_INCREF(Py_None);
1283 _res = Py_None;
1284 return _res;
1285}
1286
1287static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1288 PyObject *_self;
1289 PyObject *_args;
1290{
1291 PyObject *_res = NULL;
1292 OSErr _err;
1293 WindowPtr inWindow;
1294 if (!PyArg_ParseTuple(_args, "O&",
1295 WinObj_Convert, &inWindow))
1296 return NULL;
1297 _err = AdvanceKeyboardFocus(inWindow);
1298 if (_err != noErr) return PyMac_Error(_err);
1299 Py_INCREF(Py_None);
1300 _res = Py_None;
1301 return _res;
1302}
1303
1304static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1305 PyObject *_self;
1306 PyObject *_args;
1307{
1308 PyObject *_res = NULL;
1309 OSErr _err;
1310 WindowPtr inWindow;
1311 if (!PyArg_ParseTuple(_args, "O&",
1312 WinObj_Convert, &inWindow))
1313 return NULL;
1314 _err = ReverseKeyboardFocus(inWindow);
1315 if (_err != noErr) return PyMac_Error(_err);
1316 Py_INCREF(Py_None);
1317 _res = Py_None;
1318 return _res;
1319}
1320
1321static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1322 PyObject *_self;
1323 PyObject *_args;
1324{
1325 PyObject *_res = NULL;
1326 OSErr _err;
1327 WindowPtr inWindow;
1328 if (!PyArg_ParseTuple(_args, "O&",
1329 WinObj_Convert, &inWindow))
1330 return NULL;
1331 _err = ClearKeyboardFocus(inWindow);
1332 if (_err != noErr) return PyMac_Error(_err);
1333 Py_INCREF(Py_None);
1334 _res = Py_None;
1335 return _res;
1336}
1337
Jack Jansene0581891999-02-07 14:02:03 +00001338static PyObject *Ctl_as_Control(_self, _args)
1339 PyObject *_self;
1340 PyObject *_args;
1341{
1342 PyObject *_res = NULL;
1343 ControlHandle _rv;
1344 Handle h;
1345 if (!PyArg_ParseTuple(_args, "O&",
1346 ResObj_Convert, &h))
1347 return NULL;
1348 _rv = as_Control(h);
1349 _res = Py_BuildValue("O&",
1350 CtlObj_New, _rv);
1351 return _res;
1352}
1353
Guido van Rossum17448e21995-01-30 11:53:55 +00001354static PyMethodDef Ctl_methods[] = {
1355 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001356 "(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 +00001357 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001358 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001359 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1360 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001361 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001362 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001363 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001364 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1365 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1366 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1367 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1368 "(WindowPtr inWindow) -> None"},
1369 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1370 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1371 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1372 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1373 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1374 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1375 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1376 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1377 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1378 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1379 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1380 "(WindowPtr inWindow) -> None"},
1381 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1382 "(WindowPtr inWindow) -> None"},
1383 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1384 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001385 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1386 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001387 {NULL, NULL, 0}
1388};
1389
1390
1391
1392PyObject *
1393CtlObj_WhichControl(ControlHandle c)
1394{
1395 PyObject *it;
1396
1397 /* XXX What if we find a control belonging to some other package? */
1398 if (c == NULL)
1399 it = NULL;
1400 else
Jack Jansen85ae4a81997-04-08 15:26:03 +00001401 it = (PyObject *) GetControlReference(c);
Guido van Rossum17448e21995-01-30 11:53:55 +00001402 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1403 it = Py_None;
1404 Py_INCREF(it);
1405 return it;
1406}
1407
Jack Jansen848250c1998-05-28 14:20:09 +00001408static int
1409settrackfunc(obj)
1410 PyObject *obj;
1411{
1412 if (tracker) {
1413 PyErr_SetString(Ctl_Error, "Tracker function in use");
1414 return 0;
1415 }
1416 tracker = obj;
1417 Py_INCREF(tracker);
1418}
1419
1420static void
1421clrtrackfunc()
1422{
1423 Py_XDECREF(tracker);
1424 tracker = 0;
1425}
1426
1427static pascal void
1428mytracker(ctl, part)
1429 ControlHandle ctl;
1430 short part;
1431{
1432 PyObject *args, *rv=0;
1433
1434 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1435 if (args && tracker) {
1436 rv = PyEval_CallObject(tracker, args);
1437 Py_DECREF(args);
1438 }
1439 if (rv)
1440 Py_DECREF(rv);
1441 else
Jack Jansendeff89c1998-10-12 20:53:15 +00001442 PySys_WriteStderr("TrackControl: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001443}
1444
Guido van Rossum17448e21995-01-30 11:53:55 +00001445
1446void initCtl()
1447{
1448 PyObject *m;
1449 PyObject *d;
1450
1451
1452
Jack Jansen848250c1998-05-28 14:20:09 +00001453 mytracker_upp = NewControlActionProc(mytracker);
1454
Guido van Rossum17448e21995-01-30 11:53:55 +00001455
1456 m = Py_InitModule("Ctl", Ctl_methods);
1457 d = PyModule_GetDict(m);
1458 Ctl_Error = PyMac_GetOSErrException();
1459 if (Ctl_Error == NULL ||
1460 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1461 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001462 Control_Type.ob_type = &PyType_Type;
1463 Py_INCREF(&Control_Type);
1464 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1465 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001466}
1467
1468/* ========================= End module Ctl ========================= */
1469