blob: 3f60d37589814dce3a1202843ba48e4aa734db45 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Win =========================== */
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 *);
18
19extern PyObject *WinObj_New(WindowPtr);
20extern int WinObj_Convert(PyObject *, WindowPtr *);
21
22extern PyObject *DlgObj_New(DialogPtr);
23extern int DlgObj_Convert(PyObject *, DialogPtr *);
24extern PyTypeObject Dialog_Type;
25#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
26
27extern PyObject *MenuObj_New(MenuHandle);
28extern int MenuObj_Convert(PyObject *, MenuHandle *);
29
30extern PyObject *CtlObj_New(ControlHandle);
31extern int CtlObj_Convert(PyObject *, ControlHandle *);
32
33extern PyObject *WinObj_WhichWindow(WindowPtr);
34
35#include <Windows.h>
36
37#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
38
39#ifdef __MWERKS__
40#define WindowPeek WindowPtr
41#endif
42
43extern PyObject *WinObj_WhichWindow(WindowPtr w); /* Forward */
44
45static PyObject *Win_Error;
46
47/* ----------------------- Object type Window ----------------------- */
48
49PyTypeObject Window_Type;
50
51#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
52
53typedef struct WindowObject {
54 PyObject_HEAD
55 WindowPtr ob_itself;
56} WindowObject;
57
58PyObject *WinObj_New(itself)
59 const WindowPtr itself;
60{
61 WindowObject *it;
62 if (itself == NULL) return PyMac_Error(resNotFound);
63 it = PyObject_NEW(WindowObject, &Window_Type);
64 if (it == NULL) return NULL;
65 it->ob_itself = itself;
66 SetWRefCon(itself, (long)it);
67 return (PyObject *)it;
68}
69WinObj_Convert(v, p_itself)
70 PyObject *v;
71 WindowPtr *p_itself;
72{
73 if (DlgObj_Check(v)) {
74 *p_itself = ((WindowObject *)v)->ob_itself;
75 return 1;
76 }
77
78 if (v == Py_None) { *p_itself = NULL; return 1; }
79 if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
80
81 if (!WinObj_Check(v))
82 {
83 PyErr_SetString(PyExc_TypeError, "Window required");
84 return 0;
85 }
86 *p_itself = ((WindowObject *)v)->ob_itself;
87 return 1;
88}
89
90static void WinObj_dealloc(self)
91 WindowObject *self;
92{
93 DisposeWindow(self->ob_itself);
94 PyMem_DEL(self);
95}
96
97static PyObject *WinObj_GetWTitle(_self, _args)
98 WindowObject *_self;
99 PyObject *_args;
100{
101 PyObject *_res = NULL;
102 Str255 title;
103 if (!PyArg_ParseTuple(_args, ""))
104 return NULL;
105 GetWTitle(_self->ob_itself,
106 title);
107 _res = Py_BuildValue("O&",
108 PyMac_BuildStr255, title);
109 return _res;
110}
111
112static PyObject *WinObj_SelectWindow(_self, _args)
113 WindowObject *_self;
114 PyObject *_args;
115{
116 PyObject *_res = NULL;
117 if (!PyArg_ParseTuple(_args, ""))
118 return NULL;
119 SelectWindow(_self->ob_itself);
120 Py_INCREF(Py_None);
121 _res = Py_None;
122 return _res;
123}
124
125static PyObject *WinObj_HideWindow(_self, _args)
126 WindowObject *_self;
127 PyObject *_args;
128{
129 PyObject *_res = NULL;
130 if (!PyArg_ParseTuple(_args, ""))
131 return NULL;
132 HideWindow(_self->ob_itself);
133 Py_INCREF(Py_None);
134 _res = Py_None;
135 return _res;
136}
137
138static PyObject *WinObj_ShowWindow(_self, _args)
139 WindowObject *_self;
140 PyObject *_args;
141{
142 PyObject *_res = NULL;
143 if (!PyArg_ParseTuple(_args, ""))
144 return NULL;
145 ShowWindow(_self->ob_itself);
146 Py_INCREF(Py_None);
147 _res = Py_None;
148 return _res;
149}
150
151static PyObject *WinObj_ShowHide(_self, _args)
152 WindowObject *_self;
153 PyObject *_args;
154{
155 PyObject *_res = NULL;
156 Boolean showFlag;
157 if (!PyArg_ParseTuple(_args, "b",
158 &showFlag))
159 return NULL;
160 ShowHide(_self->ob_itself,
161 showFlag);
162 Py_INCREF(Py_None);
163 _res = Py_None;
164 return _res;
165}
166
167static PyObject *WinObj_HiliteWindow(_self, _args)
168 WindowObject *_self;
169 PyObject *_args;
170{
171 PyObject *_res = NULL;
172 Boolean fHilite;
173 if (!PyArg_ParseTuple(_args, "b",
174 &fHilite))
175 return NULL;
176 HiliteWindow(_self->ob_itself,
177 fHilite);
178 Py_INCREF(Py_None);
179 _res = Py_None;
180 return _res;
181}
182
183static PyObject *WinObj_BringToFront(_self, _args)
184 WindowObject *_self;
185 PyObject *_args;
186{
187 PyObject *_res = NULL;
188 if (!PyArg_ParseTuple(_args, ""))
189 return NULL;
190 BringToFront(_self->ob_itself);
191 Py_INCREF(Py_None);
192 _res = Py_None;
193 return _res;
194}
195
196static PyObject *WinObj_SendBehind(_self, _args)
197 WindowObject *_self;
198 PyObject *_args;
199{
200 PyObject *_res = NULL;
201 WindowPtr behindWindow;
202 if (!PyArg_ParseTuple(_args, "O&",
203 WinObj_Convert, &behindWindow))
204 return NULL;
205 SendBehind(_self->ob_itself,
206 behindWindow);
207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
210}
211
212static PyObject *WinObj_DrawGrowIcon(_self, _args)
213 WindowObject *_self;
214 PyObject *_args;
215{
216 PyObject *_res = NULL;
217 if (!PyArg_ParseTuple(_args, ""))
218 return NULL;
219 DrawGrowIcon(_self->ob_itself);
220 Py_INCREF(Py_None);
221 _res = Py_None;
222 return _res;
223}
224
225static PyObject *WinObj_MoveWindow(_self, _args)
226 WindowObject *_self;
227 PyObject *_args;
228{
229 PyObject *_res = NULL;
230 short hGlobal;
231 short vGlobal;
232 Boolean front;
233 if (!PyArg_ParseTuple(_args, "hhb",
234 &hGlobal,
235 &vGlobal,
236 &front))
237 return NULL;
238 MoveWindow(_self->ob_itself,
239 hGlobal,
240 vGlobal,
241 front);
242 Py_INCREF(Py_None);
243 _res = Py_None;
244 return _res;
245}
246
247static PyObject *WinObj_SizeWindow(_self, _args)
248 WindowObject *_self;
249 PyObject *_args;
250{
251 PyObject *_res = NULL;
252 short w;
253 short h;
254 Boolean fUpdate;
255 if (!PyArg_ParseTuple(_args, "hhb",
256 &w,
257 &h,
258 &fUpdate))
259 return NULL;
260 SizeWindow(_self->ob_itself,
261 w,
262 h,
263 fUpdate);
264 Py_INCREF(Py_None);
265 _res = Py_None;
266 return _res;
267}
268
269static PyObject *WinObj_ZoomWindow(_self, _args)
270 WindowObject *_self;
271 PyObject *_args;
272{
273 PyObject *_res = NULL;
274 short partCode;
275 Boolean front;
276 if (!PyArg_ParseTuple(_args, "hb",
277 &partCode,
278 &front))
279 return NULL;
280 ZoomWindow(_self->ob_itself,
281 partCode,
282 front);
283 Py_INCREF(Py_None);
284 _res = Py_None;
285 return _res;
286}
287
288static PyObject *WinObj_BeginUpdate(_self, _args)
289 WindowObject *_self;
290 PyObject *_args;
291{
292 PyObject *_res = NULL;
293 if (!PyArg_ParseTuple(_args, ""))
294 return NULL;
295 BeginUpdate(_self->ob_itself);
296 Py_INCREF(Py_None);
297 _res = Py_None;
298 return _res;
299}
300
301static PyObject *WinObj_EndUpdate(_self, _args)
302 WindowObject *_self;
303 PyObject *_args;
304{
305 PyObject *_res = NULL;
306 if (!PyArg_ParseTuple(_args, ""))
307 return NULL;
308 EndUpdate(_self->ob_itself);
309 Py_INCREF(Py_None);
310 _res = Py_None;
311 return _res;
312}
313
314static PyObject *WinObj_SetWRefCon(_self, _args)
315 WindowObject *_self;
316 PyObject *_args;
317{
318 PyObject *_res = NULL;
319 long data;
320 if (!PyArg_ParseTuple(_args, "l",
321 &data))
322 return NULL;
323 SetWRefCon(_self->ob_itself,
324 data);
325 Py_INCREF(Py_None);
326 _res = Py_None;
327 return _res;
328}
329
330static PyObject *WinObj_GetWRefCon(_self, _args)
331 WindowObject *_self;
332 PyObject *_args;
333{
334 PyObject *_res = NULL;
335 long _rv;
336 if (!PyArg_ParseTuple(_args, ""))
337 return NULL;
338 _rv = GetWRefCon(_self->ob_itself);
339 _res = Py_BuildValue("l",
340 _rv);
341 return _res;
342}
343
344static PyObject *WinObj_ClipAbove(_self, _args)
345 WindowObject *_self;
346 PyObject *_args;
347{
348 PyObject *_res = NULL;
349 if (!PyArg_ParseTuple(_args, ""))
350 return NULL;
351 ClipAbove((WindowPeek)(_self->ob_itself));
352 Py_INCREF(Py_None);
353 _res = Py_None;
354 return _res;
355}
356
357static PyObject *WinObj_SaveOld(_self, _args)
358 WindowObject *_self;
359 PyObject *_args;
360{
361 PyObject *_res = NULL;
362 if (!PyArg_ParseTuple(_args, ""))
363 return NULL;
364 SaveOld((WindowPeek)(_self->ob_itself));
365 Py_INCREF(Py_None);
366 _res = Py_None;
367 return _res;
368}
369
370static PyObject *WinObj_DrawNew(_self, _args)
371 WindowObject *_self;
372 PyObject *_args;
373{
374 PyObject *_res = NULL;
375 Boolean update;
376 if (!PyArg_ParseTuple(_args, "b",
377 &update))
378 return NULL;
379 DrawNew((WindowPeek)(_self->ob_itself),
380 update);
381 Py_INCREF(Py_None);
382 _res = Py_None;
383 return _res;
384}
385
386static PyObject *WinObj_CalcVis(_self, _args)
387 WindowObject *_self;
388 PyObject *_args;
389{
390 PyObject *_res = NULL;
391 if (!PyArg_ParseTuple(_args, ""))
392 return NULL;
393 CalcVis((WindowPeek)(_self->ob_itself));
394 Py_INCREF(Py_None);
395 _res = Py_None;
396 return _res;
397}
398
399static PyObject *WinObj_GrowWindow(_self, _args)
400 WindowObject *_self;
401 PyObject *_args;
402{
403 PyObject *_res = NULL;
404 long _rv;
405 Point startPt;
406 Rect bBox;
407 if (!PyArg_ParseTuple(_args, "O&O&",
408 PyMac_GetPoint, &startPt,
409 PyMac_GetRect, &bBox))
410 return NULL;
411 _rv = GrowWindow(_self->ob_itself,
412 startPt,
413 &bBox);
414 _res = Py_BuildValue("l",
415 _rv);
416 return _res;
417}
418
419static PyObject *WinObj_TrackBox(_self, _args)
420 WindowObject *_self;
421 PyObject *_args;
422{
423 PyObject *_res = NULL;
424 Boolean _rv;
425 Point thePt;
426 short partCode;
427 if (!PyArg_ParseTuple(_args, "O&h",
428 PyMac_GetPoint, &thePt,
429 &partCode))
430 return NULL;
431 _rv = TrackBox(_self->ob_itself,
432 thePt,
433 partCode);
434 _res = Py_BuildValue("b",
435 _rv);
436 return _res;
437}
438
439static PyObject *WinObj_GetWVariant(_self, _args)
440 WindowObject *_self;
441 PyObject *_args;
442{
443 PyObject *_res = NULL;
444 short _rv;
445 if (!PyArg_ParseTuple(_args, ""))
446 return NULL;
447 _rv = GetWVariant(_self->ob_itself);
448 _res = Py_BuildValue("h",
449 _rv);
450 return _res;
451}
452
453static PyObject *WinObj_SetWTitle(_self, _args)
454 WindowObject *_self;
455 PyObject *_args;
456{
457 PyObject *_res = NULL;
458 Str255 title;
459 if (!PyArg_ParseTuple(_args, "O&",
460 PyMac_GetStr255, title))
461 return NULL;
462 SetWTitle(_self->ob_itself,
463 title);
464 Py_INCREF(Py_None);
465 _res = Py_None;
466 return _res;
467}
468
469static PyObject *WinObj_TrackGoAway(_self, _args)
470 WindowObject *_self;
471 PyObject *_args;
472{
473 PyObject *_res = NULL;
474 Boolean _rv;
475 Point thePt;
476 if (!PyArg_ParseTuple(_args, "O&",
477 PyMac_GetPoint, &thePt))
478 return NULL;
479 _rv = TrackGoAway(_self->ob_itself,
480 thePt);
481 _res = Py_BuildValue("b",
482 _rv);
483 return _res;
484}
485
486static PyObject *WinObj_DragWindow(_self, _args)
487 WindowObject *_self;
488 PyObject *_args;
489{
490 PyObject *_res = NULL;
491 Point startPt;
492 Rect boundsRect;
493 if (!PyArg_ParseTuple(_args, "O&O&",
494 PyMac_GetPoint, &startPt,
495 PyMac_GetRect, &boundsRect))
496 return NULL;
497 DragWindow(_self->ob_itself,
498 startPt,
499 &boundsRect);
500 Py_INCREF(Py_None);
501 _res = Py_None;
502 return _res;
503}
504
505static PyMethodDef WinObj_methods[] = {
506 {"GetWTitle", (PyCFunction)WinObj_GetWTitle, 1,
507 "() -> (Str255 title)"},
508 {"SelectWindow", (PyCFunction)WinObj_SelectWindow, 1,
509 "() -> None"},
510 {"HideWindow", (PyCFunction)WinObj_HideWindow, 1,
511 "() -> None"},
512 {"ShowWindow", (PyCFunction)WinObj_ShowWindow, 1,
513 "() -> None"},
514 {"ShowHide", (PyCFunction)WinObj_ShowHide, 1,
515 "(Boolean showFlag) -> None"},
516 {"HiliteWindow", (PyCFunction)WinObj_HiliteWindow, 1,
517 "(Boolean fHilite) -> None"},
518 {"BringToFront", (PyCFunction)WinObj_BringToFront, 1,
519 "() -> None"},
520 {"SendBehind", (PyCFunction)WinObj_SendBehind, 1,
521 "(WindowPtr behindWindow) -> None"},
522 {"DrawGrowIcon", (PyCFunction)WinObj_DrawGrowIcon, 1,
523 "() -> None"},
524 {"MoveWindow", (PyCFunction)WinObj_MoveWindow, 1,
525 "(short hGlobal, short vGlobal, Boolean front) -> None"},
526 {"SizeWindow", (PyCFunction)WinObj_SizeWindow, 1,
527 "(short w, short h, Boolean fUpdate) -> None"},
528 {"ZoomWindow", (PyCFunction)WinObj_ZoomWindow, 1,
529 "(short partCode, Boolean front) -> None"},
530 {"BeginUpdate", (PyCFunction)WinObj_BeginUpdate, 1,
531 "() -> None"},
532 {"EndUpdate", (PyCFunction)WinObj_EndUpdate, 1,
533 "() -> None"},
534 {"SetWRefCon", (PyCFunction)WinObj_SetWRefCon, 1,
535 "(long data) -> None"},
536 {"GetWRefCon", (PyCFunction)WinObj_GetWRefCon, 1,
537 "() -> (long _rv)"},
538 {"ClipAbove", (PyCFunction)WinObj_ClipAbove, 1,
539 "() -> None"},
540 {"SaveOld", (PyCFunction)WinObj_SaveOld, 1,
541 "() -> None"},
542 {"DrawNew", (PyCFunction)WinObj_DrawNew, 1,
543 "(Boolean update) -> None"},
544 {"CalcVis", (PyCFunction)WinObj_CalcVis, 1,
545 "() -> None"},
546 {"GrowWindow", (PyCFunction)WinObj_GrowWindow, 1,
547 "(Point startPt, Rect bBox) -> (long _rv)"},
548 {"TrackBox", (PyCFunction)WinObj_TrackBox, 1,
549 "(Point thePt, short partCode) -> (Boolean _rv)"},
550 {"GetWVariant", (PyCFunction)WinObj_GetWVariant, 1,
551 "() -> (short _rv)"},
552 {"SetWTitle", (PyCFunction)WinObj_SetWTitle, 1,
553 "(Str255 title) -> None"},
554 {"TrackGoAway", (PyCFunction)WinObj_TrackGoAway, 1,
555 "(Point thePt) -> (Boolean _rv)"},
556 {"DragWindow", (PyCFunction)WinObj_DragWindow, 1,
557 "(Point startPt, Rect boundsRect) -> None"},
558 {NULL, NULL, 0}
559};
560
561PyMethodChain WinObj_chain = { WinObj_methods, NULL };
562
563static PyObject *WinObj_getattr(self, name)
564 WindowObject *self;
565 char *name;
566{
567 return Py_FindMethodInChain(&WinObj_chain, (PyObject *)self, name);
568}
569
570#define WinObj_setattr NULL
571
572PyTypeObject Window_Type = {
573 PyObject_HEAD_INIT(&PyType_Type)
574 0, /*ob_size*/
575 "Window", /*tp_name*/
576 sizeof(WindowObject), /*tp_basicsize*/
577 0, /*tp_itemsize*/
578 /* methods */
579 (destructor) WinObj_dealloc, /*tp_dealloc*/
580 0, /*tp_print*/
581 (getattrfunc) WinObj_getattr, /*tp_getattr*/
582 (setattrfunc) WinObj_setattr, /*tp_setattr*/
583};
584
585/* --------------------- End object type Window --------------------- */
586
587
588static PyObject *Win_InitWindows(_self, _args)
589 PyObject *_self;
590 PyObject *_args;
591{
592 PyObject *_res = NULL;
593 if (!PyArg_ParseTuple(_args, ""))
594 return NULL;
595 InitWindows();
596 Py_INCREF(Py_None);
597 _res = Py_None;
598 return _res;
599}
600
601static PyObject *Win_NewWindow(_self, _args)
602 PyObject *_self;
603 PyObject *_args;
604{
605 PyObject *_res = NULL;
606 WindowPtr _rv;
607 Rect boundsRect;
608 Str255 title;
609 Boolean visible;
610 short theProc;
611 WindowPtr behind;
612 Boolean goAwayFlag;
613 long refCon;
614 if (!PyArg_ParseTuple(_args, "O&O&bhO&bl",
615 PyMac_GetRect, &boundsRect,
616 PyMac_GetStr255, title,
617 &visible,
618 &theProc,
619 WinObj_Convert, &behind,
620 &goAwayFlag,
621 &refCon))
622 return NULL;
623 _rv = NewWindow((void *)0,
624 &boundsRect,
625 title,
626 visible,
627 theProc,
628 behind,
629 goAwayFlag,
630 refCon);
631 _res = Py_BuildValue("O&",
632 WinObj_New, _rv);
633 return _res;
634}
635
636static PyObject *Win_GetNewWindow(_self, _args)
637 PyObject *_self;
638 PyObject *_args;
639{
640 PyObject *_res = NULL;
641 WindowPtr _rv;
642 short windowID;
643 WindowPtr behind;
644 if (!PyArg_ParseTuple(_args, "hO&",
645 &windowID,
646 WinObj_Convert, &behind))
647 return NULL;
648 _rv = GetNewWindow(windowID,
649 (void *)0,
650 behind);
651 _res = Py_BuildValue("O&",
652 WinObj_New, _rv);
653 return _res;
654}
655
656static PyObject *Win_FrontWindow(_self, _args)
657 PyObject *_self;
658 PyObject *_args;
659{
660 PyObject *_res = NULL;
661 WindowPtr _rv;
662 if (!PyArg_ParseTuple(_args, ""))
663 return NULL;
664 _rv = FrontWindow();
665 _res = Py_BuildValue("O&",
666 WinObj_New, _rv);
667 return _res;
668}
669
670static PyObject *Win_InvalRect(_self, _args)
671 PyObject *_self;
672 PyObject *_args;
673{
674 PyObject *_res = NULL;
675 Rect badRect;
676 if (!PyArg_ParseTuple(_args, "O&",
677 PyMac_GetRect, &badRect))
678 return NULL;
679 InvalRect(&badRect);
680 Py_INCREF(Py_None);
681 _res = Py_None;
682 return _res;
683}
684
685static PyObject *Win_ValidRect(_self, _args)
686 PyObject *_self;
687 PyObject *_args;
688{
689 PyObject *_res = NULL;
690 Rect goodRect;
691 if (!PyArg_ParseTuple(_args, "O&",
692 PyMac_GetRect, &goodRect))
693 return NULL;
694 ValidRect(&goodRect);
695 Py_INCREF(Py_None);
696 _res = Py_None;
697 return _res;
698}
699
700static PyObject *Win_CheckUpdate(_self, _args)
701 PyObject *_self;
702 PyObject *_args;
703{
704 PyObject *_res = NULL;
705 Boolean _rv;
706 EventRecord theEvent;
707 if (!PyArg_ParseTuple(_args, ""))
708 return NULL;
709 _rv = CheckUpdate(&theEvent);
710 _res = Py_BuildValue("bO&",
711 _rv,
712 PyMac_BuildEventRecord, &theEvent);
713 return _res;
714}
715
716static PyObject *Win_FindWindow(_self, _args)
717 PyObject *_self;
718 PyObject *_args;
719{
720 PyObject *_res = NULL;
721 short _rv;
722 Point thePoint;
723 WindowPtr theWindow;
724 if (!PyArg_ParseTuple(_args, "O&",
725 PyMac_GetPoint, &thePoint))
726 return NULL;
727 _rv = FindWindow(thePoint,
728 &theWindow);
729 _res = Py_BuildValue("hO&",
730 _rv,
731 WinObj_WhichWindow, theWindow);
732 return _res;
733}
734
735static PyObject *Win_PinRect(_self, _args)
736 PyObject *_self;
737 PyObject *_args;
738{
739 PyObject *_res = NULL;
740 long _rv;
741 Rect theRect;
742 Point thePt;
743 if (!PyArg_ParseTuple(_args, "O&O&",
744 PyMac_GetRect, &theRect,
745 PyMac_GetPoint, &thePt))
746 return NULL;
747 _rv = PinRect(&theRect,
748 thePt);
749 _res = Py_BuildValue("l",
750 _rv);
751 return _res;
752}
753
754static PyObject *Win_NewCWindow(_self, _args)
755 PyObject *_self;
756 PyObject *_args;
757{
758 PyObject *_res = NULL;
759 WindowPtr _rv;
760 Rect boundsRect;
761 Str255 title;
762 Boolean visible;
763 short procID;
764 WindowPtr behind;
765 Boolean goAwayFlag;
766 long refCon;
767 if (!PyArg_ParseTuple(_args, "O&O&bhO&bl",
768 PyMac_GetRect, &boundsRect,
769 PyMac_GetStr255, title,
770 &visible,
771 &procID,
772 WinObj_Convert, &behind,
773 &goAwayFlag,
774 &refCon))
775 return NULL;
776 _rv = NewCWindow((void *)0,
777 &boundsRect,
778 title,
779 visible,
780 procID,
781 behind,
782 goAwayFlag,
783 refCon);
784 _res = Py_BuildValue("O&",
785 WinObj_New, _rv);
786 return _res;
787}
788
789static PyObject *Win_GetNewCWindow(_self, _args)
790 PyObject *_self;
791 PyObject *_args;
792{
793 PyObject *_res = NULL;
794 WindowPtr _rv;
795 short windowID;
796 WindowPtr behind;
797 if (!PyArg_ParseTuple(_args, "hO&",
798 &windowID,
799 WinObj_Convert, &behind))
800 return NULL;
801 _rv = GetNewCWindow(windowID,
802 (void *)0,
803 behind);
804 _res = Py_BuildValue("O&",
805 WinObj_New, _rv);
806 return _res;
807}
808
809static PyMethodDef Win_methods[] = {
810 {"InitWindows", (PyCFunction)Win_InitWindows, 1,
811 "() -> None"},
812 {"NewWindow", (PyCFunction)Win_NewWindow, 1,
813 "(Rect boundsRect, Str255 title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"},
814 {"GetNewWindow", (PyCFunction)Win_GetNewWindow, 1,
815 "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"},
816 {"FrontWindow", (PyCFunction)Win_FrontWindow, 1,
817 "() -> (WindowPtr _rv)"},
818 {"InvalRect", (PyCFunction)Win_InvalRect, 1,
819 "(Rect badRect) -> None"},
820 {"ValidRect", (PyCFunction)Win_ValidRect, 1,
821 "(Rect goodRect) -> None"},
822 {"CheckUpdate", (PyCFunction)Win_CheckUpdate, 1,
823 "() -> (Boolean _rv, EventRecord theEvent)"},
824 {"FindWindow", (PyCFunction)Win_FindWindow, 1,
825 "(Point thePoint) -> (short _rv, WindowPtr theWindow)"},
826 {"PinRect", (PyCFunction)Win_PinRect, 1,
827 "(Rect theRect, Point thePt) -> (long _rv)"},
828 {"NewCWindow", (PyCFunction)Win_NewCWindow, 1,
829 "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"},
830 {"GetNewCWindow", (PyCFunction)Win_GetNewCWindow, 1,
831 "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"},
832 {NULL, NULL, 0}
833};
834
835
836
837/* Return the object corresponding to the window, or NULL */
838
839PyObject *
840WinObj_WhichWindow(w)
841 WindowPtr w;
842{
843 PyObject *it;
844
845 /* XXX What if we find a stdwin window or a window belonging
846 to some other package? */
847 it = (PyObject *) GetWRefCon(w);
848 if (it == NULL || ((WindowObject *)it)->ob_itself != w)
849 it = Py_None;
850 Py_INCREF(it);
851 return it;
852}
853
854
855void initWin()
856{
857 PyObject *m;
858 PyObject *d;
859
860
861
862
863 m = Py_InitModule("Win", Win_methods);
864 d = PyModule_GetDict(m);
865 Win_Error = PyMac_GetOSErrException();
866 if (Win_Error == NULL ||
867 PyDict_SetItemString(d, "Error", Win_Error) != 0)
868 Py_FatalError("can't initialize Win.Error");
869}
870
871/* ========================= End module Win ========================= */
872