| 
									
										
										
										
											1995-01-22 18:36:13 +00:00
										 |  |  | /***********************************************************
 | 
					
						
							| 
									
										
										
										
											1997-01-31 16:15:11 +00:00
										 |  |  | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, | 
					
						
							| 
									
										
										
										
											1995-01-22 18:36:13 +00:00
										 |  |  | The Netherlands. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         All Rights Reserved | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Permission to use, copy, modify, and distribute this software and its  | 
					
						
							|  |  |  | documentation for any purpose and without fee is hereby granted,  | 
					
						
							|  |  |  | provided that the above copyright notice appear in all copies and that | 
					
						
							|  |  |  | both that copyright notice and this permission notice appear in  | 
					
						
							|  |  |  | supporting documentation, and that the names of Stichting Mathematisch | 
					
						
							|  |  |  | Centrum or CWI not be used in advertising or publicity pertaining to | 
					
						
							|  |  |  | distribution of the software without specific, written prior permission. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | 
					
						
							|  |  |  | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | 
					
						
							|  |  |  | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | 
					
						
							|  |  |  | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
					
						
							|  |  |  | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 
					
						
							|  |  |  | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | 
					
						
							|  |  |  | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ******************************************************************/ | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-19 15:11:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | #include "Python.h"
 | 
					
						
							| 
									
										
										
										
											1995-02-14 01:27:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | #include "macglue.h"
 | 
					
						
							| 
									
										
										
										
											1995-02-15 22:58:33 +00:00
										 |  |  | #include "marshal.h"
 | 
					
						
							|  |  |  | #include "import.h"
 | 
					
						
							| 
									
										
										
										
											1997-06-12 15:29:46 +00:00
										 |  |  | #include "importdl.h"
 | 
					
						
							| 
									
										
										
										
											2001-05-19 12:31:09 +00:00
										 |  |  | #include "pymactoolbox.h"
 | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | #include "pythonresources.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #ifdef WITHOUT_FRAMEWORKS
 | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | #include <OSUtils.h> /* for Set(Current)A5 */
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | #include <Files.h>
 | 
					
						
							| 
									
										
										
										
											1995-02-13 11:33:28 +00:00
										 |  |  | #include <StandardFile.h>
 | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | #include <Resources.h>
 | 
					
						
							|  |  |  | #include <Memory.h>
 | 
					
						
							|  |  |  | #include <Windows.h>
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | #include <Traps.h>
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | #include <Processes.h>
 | 
					
						
							| 
									
										
										
										
											1995-02-18 15:01:31 +00:00
										 |  |  | #include <Fonts.h>
 | 
					
						
							|  |  |  | #include <Menus.h>
 | 
					
						
							| 
									
										
										
										
											1995-06-18 20:03:40 +00:00
										 |  |  | #include <TextUtils.h>
 | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #include <LowMem.h>
 | 
					
						
							|  |  |  | #ifdef __CFM68K__
 | 
					
						
							|  |  |  | /* cfm68k InterfaceLib exports GetEventQueue, but Events.h doesn't know this
 | 
					
						
							|  |  |  | ** and defines it as GetEvQHdr (which is correct for PPC). This fix is for | 
					
						
							|  |  |  | ** CW9, check that the workaround is still needed for the next release. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | #define GetEvQHdr GetEventQueue
 | 
					
						
							|  |  |  | #endif /* __CFM68K__ */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Events.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __CFM68K__
 | 
					
						
							|  |  |  | #undef GetEventQueue
 | 
					
						
							|  |  |  | #endif /* __CFM68K__ */
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #include <Carbon/Carbon.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !TARGET_API_MAC_OS8
 | 
					
						
							|  |  |  | /* Unfortunately this call is probably slower... */ | 
					
						
							|  |  |  | #define LMGetTicks() TickCount()
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-02-27 16:17:28 +00:00
										 |  |  | #ifdef __MWERKS__
 | 
					
						
							|  |  |  | #include <SIOUX.h>
 | 
					
						
							| 
									
										
										
										
											2000-07-11 21:16:03 +00:00
										 |  |  | extern void SIOUXSetupMenus(void); | 
					
						
							|  |  |  | extern void SIOUXDoAboutBox(void); | 
					
						
							| 
									
										
										
										
											1995-02-27 16:17:28 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-07-11 21:16:03 +00:00
										 |  |  | #ifdef USE_GUSI
 | 
					
						
							|  |  |  | /* Functions we redefine because they're in obscure libraries */ | 
					
						
							|  |  |  | extern void SpinCursor(short x); | 
					
						
							|  |  |  | extern void RotateCursor(short x); | 
					
						
							|  |  |  | extern pascal void PLstrcpy(unsigned char *, unsigned char *); | 
					
						
							|  |  |  | extern pascal int PLstrcmp(unsigned char *, unsigned char *); | 
					
						
							|  |  |  | extern pascal unsigned char *PLstrrchr(unsigned char *, unsigned char); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-07 09:10:49 +00:00
										 |  |  | #ifdef USE_GUSI1
 | 
					
						
							| 
									
										
										
										
											1996-03-05 16:56:24 +00:00
										 |  |  | #include <TFileSpec.h> /* For Path2FSSpec */
 | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | #include <GUSI.h>
 | 
					
						
							| 
									
										
										
										
											1996-03-05 16:56:24 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-09-06 00:30:45 +00:00
										 |  |  | /* The ID of the Sioux apple menu */ | 
					
						
							|  |  |  | #define SIOUX_APPLEID	32000
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | #include <signal.h>
 | 
					
						
							| 
									
										
										
										
											1995-02-15 22:58:33 +00:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-01 15:23:54 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** When less than this amount of stackspace is left we | 
					
						
							|  |  |  | ** raise a MemoryError. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | #ifndef MINIMUM_STACK_SIZE
 | 
					
						
							|  |  |  | #ifdef __powerc
 | 
					
						
							|  |  |  | #define MINIMUM_STACK_SIZE 8192
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define MINIMUM_STACK_SIZE 4096
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-02 22:40:28 +00:00
										 |  |  | #if TARGET_API_MAC_CARBON
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** On MacOSX StackSpace() lies: it gives the distance from heap end to stack pointer, | 
					
						
							|  |  |  | ** but the stack cannot grow that far due to rlimit values. We cannot get at this value | 
					
						
							|  |  |  | ** from Carbon, so we set a maximum to the stack here that is based on the default | 
					
						
							|  |  |  | ** stack limit of 512K. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | #define MAXIMUM_STACK_SIZE (256*1024)
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											1995-02-27 16:17:28 +00:00
										 |  |  | ** We have to be careful, since we can't handle | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | ** things like updates (and they'll keep coming back if we don't | 
					
						
							| 
									
										
										
										
											1995-02-27 16:17:28 +00:00
										 |  |  | ** handle them). Note that we don't know who has windows open, so | 
					
						
							|  |  |  | ** even handing updates off to SIOUX under MW isn't going to work. | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											1997-08-26 13:20:34 +00:00
										 |  |  | #define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask|activMask)
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <signal.h>
 | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-22 18:36:13 +00:00
										 |  |  | /* XXX We should include Errors.h here, but it has a name conflict
 | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | ** with the python errors.h. */ | 
					
						
							|  |  |  | #define fnfErr -43
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | /* Declared in macfsmodule.c: */ | 
					
						
							| 
									
										
										
										
											2000-07-11 21:16:03 +00:00
										 |  |  | extern FSSpec *mfs_GetFSSpecFSSpec(PyObject *); | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | extern PyObject *newmfssobject(FSSpec *); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | /* Interrupt code variables: */ | 
					
						
							|  |  |  | static int interrupted;			/* Set to true when cmd-. seen */ | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | static RETSIGTYPE intcatcher(int); | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #if !TARGET_API_MAC_OSX
 | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | static int PyMac_Yield(void); | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** These are the real scheduling parameters that control what we check | 
					
						
							|  |  |  | ** in the event loop, and how often we check. The values are initialized | 
					
						
							|  |  |  | ** from pyMac_SchedParamStruct. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct real_sched_param_struct { | 
					
						
							|  |  |  | 	int		check_interrupt;	/* if true check for command-dot */ | 
					
						
							|  |  |  | 	int		process_events;		/* if nonzero enable evt processing, this mask */ | 
					
						
							|  |  |  | 	int		besocial;		/* if nonzero be a little social with CPU */ | 
					
						
							|  |  |  | 	unsigned long	check_interval;		/* how often to check, in ticks */ | 
					
						
							|  |  |  | 	unsigned long	bg_yield;		/* yield so long when in background */ | 
					
						
							|  |  |  | 	/* these are computed from previous and clock and such */ | 
					
						
							|  |  |  | 	int		enabled;		/* check_interrupt OR process_event OR yield */ | 
					
						
							|  |  |  | 	unsigned long	next_check;		/* when to check/yield next, in ticks */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct real_sched_param_struct schedparams = | 
					
						
							|  |  |  | 	{ 1, MAINLOOP_EVENTMASK, 1, 15, 15, 1, 0}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Workaround for sioux/gusi combo: set when we are exiting | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | int PyMac_ConsoleIsDead; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-12 10:49:13 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Sioux menu bar, saved early so we can restore it | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2001-02-17 22:02:07 +00:00
										 |  |  | static MenuBarHandle sioux_mbar; | 
					
						
							| 
									
										
										
										
											1997-06-12 10:49:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Some stuff for our GetDirectory and PromptGetFile routines | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | struct hook_args { | 
					
						
							|  |  |  | 	int selectcur_hit;		/* Set to true when "select current" selected */ | 
					
						
							|  |  |  | 	char *prompt;			/* The prompt */ | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2001-05-12 21:31:34 +00:00
										 |  |  | #if !TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											2000-06-02 21:27:11 +00:00
										 |  |  | /* The StandardFile hooks don't exist in Carbon. This breaks GetDirectory,
 | 
					
						
							|  |  |  | ** but the macfsn code will replace it by a NavServices version anyway. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | #define myhook_upp NULL
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | static DlgHookYDUPP myhook_upp; | 
					
						
							|  |  |  | static int upp_inited = 0; | 
					
						
							| 
									
										
										
										
											2000-06-02 21:27:11 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** The python-code event handler | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static PyObject *python_event_handler; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-12-07 23:08:10 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Set to true if we're appearance-compliant | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | int PyMac_AppearanceCompliant; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-24 19:50:16 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Find out what the current script is. | 
					
						
							|  |  |  | ** Donated by Fredrik Lund. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | char *PyMac_getscript() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    int font, script, lang; | 
					
						
							|  |  |  |     font = 0; | 
					
						
							|  |  |  |     font = GetSysFont(); | 
					
						
							|  |  |  |     script = FontToScript(font); | 
					
						
							|  |  |  |     switch (script) { | 
					
						
							|  |  |  |     case smRoman: | 
					
						
							|  |  |  |         lang = GetScriptVariable(script, smScriptLang); | 
					
						
							|  |  |  |         if (lang == langIcelandic) | 
					
						
							|  |  |  |             return "mac-iceland"; | 
					
						
							|  |  |  |         else if (lang == langTurkish) | 
					
						
							|  |  |  |             return "mac-turkish"; | 
					
						
							|  |  |  |         else if (lang == langGreek) | 
					
						
							|  |  |  |             return "mac-greek"; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             return "mac-roman"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case smJapanese: | 
					
						
							|  |  |  |         return "mac-japan"; | 
					
						
							|  |  |  |     case smGreek: | 
					
						
							|  |  |  |         return "mac-greek"; | 
					
						
							|  |  |  |     case smCyrillic: | 
					
						
							|  |  |  |         return "mac-cyrillic"; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         return "mac-roman"; /* better than nothing */ | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-19 12:55:57 +00:00
										 |  |  | /* Given an FSSpec, return the FSSpec of the parent folder */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static OSErr | 
					
						
							|  |  |  | get_folder_parent (FSSpec * fss, FSSpec * parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CInfoPBRec rec; | 
					
						
							|  |  |  | 	short err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         * parent = * fss; | 
					
						
							|  |  |  |         rec.hFileInfo.ioNamePtr = parent->name; | 
					
						
							|  |  |  |         rec.hFileInfo.ioVRefNum = parent->vRefNum; | 
					
						
							|  |  |  |         rec.hFileInfo.ioDirID = parent->parID; | 
					
						
							|  |  |  | 		rec.hFileInfo.ioFDirIndex = -1; | 
					
						
							|  |  |  |         rec.hFileInfo.ioFVersNum = 0; | 
					
						
							|  |  |  |         if (err = PBGetCatInfoSync (& rec)) | 
					
						
							|  |  |  |         	return err; | 
					
						
							|  |  |  |         parent->parID = rec.dirInfo.ioDrParID; | 
					
						
							|  |  |  | /*	parent->name[0] = 0; */ | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Given an FSSpec return a full, colon-separated pathname */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSErr | 
					
						
							|  |  |  | PyMac_GetFullPath (FSSpec *fss, char *buf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	short err; | 
					
						
							|  |  |  | 	FSSpec fss_parent, fss_current; | 
					
						
							|  |  |  | 	char tmpbuf[1024]; | 
					
						
							|  |  |  | 	int plen; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fss_current = *fss; | 
					
						
							|  |  |  | 	plen = fss_current.name[0]; | 
					
						
							|  |  |  | 	memcpy(buf, &fss_current.name[1], plen); | 
					
						
							|  |  |  | 	buf[plen] = 0; | 
					
						
							|  |  |  | 	/* Special case for disk names */ | 
					
						
							|  |  |  | 	if ( fss_current.parID <= 1 ) { | 
					
						
							|  |  |  | 		buf[plen++] = ':'; | 
					
						
							|  |  |  | 		buf[plen] = 0; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	while (fss_current.parID > 1) { | 
					
						
							|  |  |  |     		/* Get parent folder name */ | 
					
						
							|  |  |  |                 if (err = get_folder_parent(&fss_current, &fss_parent)) | 
					
						
							|  |  |  |              		return err; | 
					
						
							|  |  |  |                 fss_current = fss_parent; | 
					
						
							|  |  |  |                 /* Prepend path component just found to buf */ | 
					
						
							|  |  |  |     			plen = fss_current.name[0]; | 
					
						
							|  |  |  |     			if (strlen(buf) + plen + 1 > 1024) { | 
					
						
							|  |  |  |     				/* Oops... Not enough space (shouldn't happen) */ | 
					
						
							|  |  |  |     				*buf = 0; | 
					
						
							|  |  |  |     				return -1; | 
					
						
							|  |  |  |     			} | 
					
						
							|  |  |  |     			memcpy(tmpbuf, &fss_current.name[1], plen); | 
					
						
							|  |  |  |     			tmpbuf[plen] = ':'; | 
					
						
							|  |  |  |     			strcpy(&tmpbuf[plen+1], buf); | 
					
						
							|  |  |  |     			strcpy(buf, tmpbuf); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2000-07-24 19:50:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-07 09:10:49 +00:00
										 |  |  | #ifdef USE_GUSI1
 | 
					
						
							| 
									
										
										
										
											1996-03-06 16:21:34 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** GUSI (1.6.0 and earlier, at the least) do not set the MacOS idea of | 
					
						
							|  |  |  | ** the working directory. Hence, we call this routine after each call | 
					
						
							|  |  |  | ** to chdir() to rectify things. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | PyMac_FixGUSIcd() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	WDPBRec pb; | 
					
						
							|  |  |  | 	FSSpec curdirfss; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( Path2FSSpec(":x", &curdirfss) != noErr )  | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Set MacOS "working directory" */ | 
					
						
							|  |  |  | 	pb.ioNamePtr= "\p"; | 
					
						
							|  |  |  | 	pb.ioVRefNum= curdirfss.vRefNum; | 
					
						
							|  |  |  | 	pb.ioWDDirID= curdirfss.parID; | 
					
						
							| 
									
										
										
										
											1997-04-08 15:27:00 +00:00
										 |  |  | 	if (PBHSetVolSync(&pb) != noErr) | 
					
						
							| 
									
										
										
										
											1996-03-06 16:21:34 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2000-04-07 09:10:49 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1996-08-19 11:01:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-07 09:10:49 +00:00
										 |  |  | #ifdef USE_GUSI
 | 
					
						
							| 
									
										
										
										
											1996-09-07 17:09:31 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** SpinCursor (needed by GUSI) drags in heaps of stuff, so we | 
					
						
							|  |  |  | ** provide a dummy here. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											1996-08-19 11:36:25 +00:00
										 |  |  | void SpinCursor(short x) { /* Dummy */ } | 
					
						
							| 
									
										
										
										
											1998-02-20 16:03:15 +00:00
										 |  |  | void RotateCursor(short x) { /* Dummy */ } | 
					
						
							| 
									
										
										
										
											1996-08-19 11:36:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Replacement GUSI Spin function | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2000-04-07 09:10:49 +00:00
										 |  |  | #ifdef USE_GUSI1
 | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | PyMac_GUSISpin(spin_msg msg, long arg) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	static Boolean	inForeground = true; | 
					
						
							|  |  |  | 	int		maxsleep = 6;	/* 6 ticks is "normal" sleeptime */ | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (PyMac_ConsoleIsDead) return 0; | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	if (inForeground) | 
					
						
							|  |  |  | 		SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (interrupted) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	if ( msg == SP_AUTO_SPIN ) | 
					
						
							|  |  |  | 		maxsleep = 0; | 
					
						
							|  |  |  | 	if ( msg==SP_SLEEP||msg==SP_SELECT ) | 
					
						
							|  |  |  | 		maxsleep = arg; | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	PyMac_DoYield(maxsleep, 0); /* XXXX or is it safe to call python here? */ | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | PyMac_SetGUSISpin() { | 
					
						
							|  |  |  | 	GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2000-04-07 09:10:49 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-23 15:35:14 +00:00
										 |  |  | /* Called at exit() time thru atexit(), to stop event processing */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | PyMac_StopGUSISpin() { | 
					
						
							|  |  |  | 	PyMac_ConsoleIsDead = 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-12 21:31:34 +00:00
										 |  |  | #if TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											1997-05-23 15:35:14 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Replacement routines for the PLstr... functions so we don't need | 
					
						
							| 
									
										
										
										
											2001-01-11 23:03:56 +00:00
										 |  |  | ** StdCLib. | 
					
						
							| 
									
										
										
										
											1997-05-23 15:35:14 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											1999-12-12 21:37:14 +00:00
										 |  |  | pascal void | 
					
						
							| 
									
										
										
										
											2000-07-11 21:16:03 +00:00
										 |  |  | PLstrcpy(unsigned char *to, unsigned char *fr) | 
					
						
							| 
									
										
										
										
											1997-05-23 15:35:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	memcpy(to, fr, fr[0]+1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-12-12 21:37:14 +00:00
										 |  |  | pascal int | 
					
						
							| 
									
										
										
										
											2000-07-11 21:16:03 +00:00
										 |  |  | PLstrcmp(unsigned char *s1, unsigned char *s2) | 
					
						
							| 
									
										
										
										
											1997-05-23 15:35:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 	int l = s1[0] < s2[0] ? s1[0] : s2[0]; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	res = memcmp(s1+1, s2+1, l); | 
					
						
							|  |  |  | 	if ( res != 0 ) | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1998-07-31 09:36:30 +00:00
										 |  |  | 	if ( s1[0] < s2[0] ) | 
					
						
							| 
									
										
										
										
											1997-05-23 15:35:14 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											1998-07-31 09:36:30 +00:00
										 |  |  | 	else if ( s1[0] > s2[0] ) | 
					
						
							| 
									
										
										
										
											1997-05-23 15:35:14 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-12-12 21:37:14 +00:00
										 |  |  | pascal unsigned char * | 
					
						
							| 
									
										
										
										
											2000-07-11 21:16:03 +00:00
										 |  |  | PLstrrchr(unsigned char *str, unsigned char chr) | 
					
						
							| 
									
										
										
										
											1997-05-23 15:35:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned char *ptr = 0; | 
					
						
							|  |  |  | 	unsigned char *p; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	for(p=str+1; p<str+str[0]; p++) | 
					
						
							|  |  |  | 		if ( *p == chr ) | 
					
						
							|  |  |  | 			ptr = p; | 
					
						
							|  |  |  | 	return ptr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2001-05-12 21:31:34 +00:00
										 |  |  | #endif /* TARGET_API_MAC_OS8 */
 | 
					
						
							| 
									
										
										
										
											1997-05-23 15:35:14 +00:00
										 |  |  | #endif /* USE_GUSI */
 | 
					
						
							| 
									
										
										
										
											1996-03-06 16:21:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | /* Convert C to Pascal string. Returns pointer to static buffer. */ | 
					
						
							|  |  |  | unsigned char * | 
					
						
							|  |  |  | Pstring(char *str) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static Str255 buf; | 
					
						
							|  |  |  | 	int len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = strlen(str); | 
					
						
							| 
									
										
										
										
											1995-01-21 13:46:04 +00:00
										 |  |  | 	if (len > 255) | 
					
						
							|  |  |  | 		len = 255; | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | 	buf[0] = (unsigned char)len; | 
					
						
							|  |  |  | 	strncpy((char *)buf+1, str, len); | 
					
						
							|  |  |  | 	return buf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-12 21:31:34 +00:00
										 |  |  | #if TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											2000-12-12 22:12:14 +00:00
										 |  |  | void | 
					
						
							|  |  |  | c2pstrcpy(unsigned char *dst, const char *src) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int len; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	len = strlen(src); | 
					
						
							|  |  |  | 	if ( len > 255 ) len = 255; | 
					
						
							|  |  |  | 	strncpy((char *)dst+1, src, len); | 
					
						
							|  |  |  | 	dst[0] = len; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-05-12 21:31:34 +00:00
										 |  |  | #endif /* TARGET_API_MAC_OS8 */
 | 
					
						
							| 
									
										
										
										
											2000-12-12 22:12:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-02-18 15:01:31 +00:00
										 |  |  | /* Like strerror() but for Mac OS error numbers */ | 
					
						
							|  |  |  | char *PyMac_StrError(int err) | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	static char buf[256]; | 
					
						
							|  |  |  | 	Handle h; | 
					
						
							|  |  |  | 	char *str; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	h = GetResource('Estr', err); | 
					
						
							|  |  |  | 	if ( h ) { | 
					
						
							|  |  |  | 		HLock(h); | 
					
						
							|  |  |  | 		str = (char *)*h; | 
					
						
							|  |  |  | 		memcpy(buf, str+1, (unsigned char)str[0]); | 
					
						
							| 
									
										
										
										
											1995-02-13 16:17:03 +00:00
										 |  |  | 		buf[(unsigned char)str[0]] = '\0'; | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | 		HUnlock(h); | 
					
						
							|  |  |  | 		ReleaseResource(h); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		sprintf(buf, "Mac OS error code %d", err); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return buf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | /* Exception object shared by all Mac specific modules for Mac OS errors */ | 
					
						
							|  |  |  | PyObject *PyMac_OSErrException; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Initialize and return PyMac_OSErrException */ | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyMac_GetOSErrException() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (PyMac_OSErrException == NULL) | 
					
						
							|  |  |  | 		PyMac_OSErrException = PyString_FromString("Mac OS Error"); | 
					
						
							|  |  |  | 	return PyMac_OSErrException; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | /* Set a MAC-specific error from errno, and return NULL; return None if no error */ | 
					
						
							|  |  |  | PyObject *  | 
					
						
							| 
									
										
										
										
											1995-01-12 12:37:24 +00:00
										 |  |  | PyErr_Mac(PyObject *eobj, int err) | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *msg; | 
					
						
							|  |  |  | 	PyObject *v; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1995-01-18 23:57:26 +00:00
										 |  |  | 	if (err == 0 && !PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1995-01-18 23:57:26 +00:00
										 |  |  | 	if (err == -1 && PyErr_Occurred()) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1995-02-18 15:01:31 +00:00
										 |  |  | 	msg = PyMac_StrError(err); | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | 	v = Py_BuildValue("(is)", err, msg); | 
					
						
							|  |  |  | 	PyErr_SetObject(eobj, v); | 
					
						
							|  |  |  | 	Py_DECREF(v); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | /* Call PyErr_Mac with PyMac_OSErrException */ | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyMac_Error(OSErr err) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyErr_Mac(PyMac_GetOSErrException(), err); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-07-22 15:25:10 +00:00
										 |  |  | #ifdef USE_STACKCHECK
 | 
					
						
							|  |  |  | /* Check for stack overflow */ | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | PyOS_CheckStack() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-08-25 21:57:23 +00:00
										 |  |  | 	char here; | 
					
						
							|  |  |  | 	static char *sentinel = 0; | 
					
						
							| 
									
										
										
										
											2000-09-08 22:05:48 +00:00
										 |  |  | 	static PyThreadState *thread_for_sentinel = 0; | 
					
						
							| 
									
										
										
										
											1996-07-22 15:25:10 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2001-02-02 22:40:28 +00:00
										 |  |  | 	if ( sentinel == 0 ) { | 
					
						
							|  |  |  | 		unsigned long stackspace = StackSpace(); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | #ifdef MAXIMUM_STACK_SIZE
 | 
					
						
							|  |  |  | 	/* See the comment at the definition */ | 
					
						
							|  |  |  | 	if ( stackspace > MAXIMUM_STACK_SIZE ) | 
					
						
							|  |  |  | 		stackspace = MAXIMUM_STACK_SIZE; | 
					
						
							|  |  |  | #endif	
 | 
					
						
							|  |  |  | 		sentinel = &here - stackspace + MINIMUM_STACK_SIZE; | 
					
						
							| 
									
										
										
										
											2000-08-25 21:57:23 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-09-08 22:05:48 +00:00
										 |  |  | 	if ( thread_for_sentinel == 0 ) { | 
					
						
							|  |  |  | 		thread_for_sentinel = PyThreadState_Get(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ( &here < sentinel ) { | 
					
						
							|  |  |  | 		if (thread_for_sentinel == PyThreadState_Get()) { | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			/* Else we are unsure... */ | 
					
						
							|  |  |  | 			fprintf(stderr, "Stackcheck in other thread (was %x now %x)\n", thread_for_sentinel,PyThreadState_Get());  | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-07-22 15:25:10 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif /* USE_STACKCHECK */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #if !TARGET_API_MAC_OSX
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | /* The catcher routine (which may not be used for all compilers) */ | 
					
						
							|  |  |  | static RETSIGTYPE | 
					
						
							|  |  |  | intcatcher(sig) | 
					
						
							|  |  |  | 	int sig; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	interrupted = 1; | 
					
						
							|  |  |  | 	signal(SIGINT, intcatcher); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | PyOS_InitInterrupts() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (signal(SIGINT, SIG_IGN) != SIG_IGN) | 
					
						
							|  |  |  | 		signal(SIGINT, intcatcher); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-08 14:57:37 +00:00
										 |  |  | void | 
					
						
							|  |  |  | PyOS_FiniInterrupts() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** This routine scans the event queue looking for cmd-. | 
					
						
							|  |  |  | ** This is the only way to get an interrupt under THINK (since it | 
					
						
							|  |  |  | ** doesn't do SIGINT handling), but is also used under MW, when | 
					
						
							|  |  |  | ** the full-fledged event loop is disabled. This way, we can at least | 
					
						
							|  |  |  | ** interrupt a runaway python program. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | scan_event_queue(flush) | 
					
						
							|  |  |  | 	int flush; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-05-12 21:31:34 +00:00
										 |  |  | #if !TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											2001-01-12 23:42:28 +00:00
										 |  |  | 	if ( CheckEventQueueForUserCancel() ) | 
					
						
							|  |  |  | 		interrupted = 1; | 
					
						
							| 
									
										
										
										
											2000-06-02 21:27:11 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 	register EvQElPtr q; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1998-02-20 16:03:15 +00:00
										 |  |  | 	q = (EvQElPtr) LMGetEventQueue()->qHead; | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	for (; q; q = (EvQElPtr)q->qLink) { | 
					
						
							|  |  |  | 		if (q->evtQWhat == keyDown && | 
					
						
							|  |  |  | 				(char)q->evtQMessage == '.' && | 
					
						
							|  |  |  | 				(q->evtQModifiers & cmdKey) != 0) { | 
					
						
							|  |  |  | 			if ( flush ) | 
					
						
							|  |  |  | 				FlushEvents(keyDownMask, 0); | 
					
						
							|  |  |  | 			interrupted = 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-06-02 21:27:11 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | PyErr_CheckSignals() | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	if (schedparams.enabled) { | 
					
						
							|  |  |  | 		if ( (unsigned long)LMGetTicks() > schedparams.next_check ) { | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | 			if ( PyMac_Yield() < 0) | 
					
						
							|  |  |  | 				return -1; | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 			schedparams.next_check = (unsigned long)LMGetTicks() | 
					
						
							|  |  |  | 					 + schedparams.check_interval; | 
					
						
							|  |  |  | 			if (interrupted) { | 
					
						
							| 
									
										
										
										
											1997-06-12 10:49:13 +00:00
										 |  |  | 				scan_event_queue(1);	/* Eat events up to cmd-. */ | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 				interrupted = 0; | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | 				PyErr_SetNone(PyExc_KeyboardInterrupt); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | int | 
					
						
							|  |  |  | PyOS_InterruptOccurred() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	scan_event_queue(1); | 
					
						
							|  |  |  | 	return interrupted; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | /* Check whether we are in the foreground */ | 
					
						
							| 
									
										
										
										
											2000-07-11 21:16:03 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | PyMac_InForeground(void) | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	static ProcessSerialNumber ours; | 
					
						
							|  |  |  | 	static inited; | 
					
						
							|  |  |  | 	ProcessSerialNumber curfg; | 
					
						
							|  |  |  | 	Boolean eq; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	if ( inited == 0 ) { | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 		(void)GetCurrentProcess(&ours); | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 		inited = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 	if ( GetFrontProcess(&curfg) < 0 ) | 
					
						
							|  |  |  | 		eq = 1; | 
					
						
							|  |  |  | 	else if ( SameProcess(&ours, &curfg, &eq) < 0 ) | 
					
						
							|  |  |  | 		eq = 1; | 
					
						
							|  |  |  | 	return (int)eq; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | int | 
					
						
							|  |  |  | PyMac_SetEventHandler(PyObject *evh) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ( evh && python_event_handler ) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_RuntimeError, "Python event handler already set"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ( python_event_handler ) | 
					
						
							|  |  |  | 		Py_DECREF(python_event_handler); | 
					
						
							|  |  |  | 	if ( evh ) | 
					
						
							|  |  |  | 		Py_INCREF(evh); | 
					
						
							|  |  |  | 	python_event_handler = evh; | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-02-02 14:25:56 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Handle an event, either one found in the mainloop eventhandler or | 
					
						
							|  |  |  | ** one passed back from the python program. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | PyMac_HandleEventIntern(evp) | 
					
						
							| 
									
										
										
										
											1995-02-02 14:25:56 +00:00
										 |  |  | 	EventRecord *evp; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-05-12 21:31:34 +00:00
										 |  |  | #if TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											1997-08-26 13:20:34 +00:00
										 |  |  | 	if ( evp->what == mouseDown ) { | 
					
						
							|  |  |  | 		WindowPtr wp; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if ( FindWindow(evp->where, &wp) == inSysWindow ) { | 
					
						
							|  |  |  | 			SystemClick(evp, wp); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-06-02 21:27:11 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-02-02 14:25:56 +00:00
										 |  |  | #ifdef __MWERKS__
 | 
					
						
							| 
									
										
										
										
											1995-11-10 14:53:00 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		int siouxdidit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* If SIOUX wants it we're done */ | 
					
						
							|  |  |  | 		siouxdidit = SIOUXHandleOneEvent(evp); | 
					
						
							|  |  |  | 		if ( siouxdidit ) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1995-02-02 14:25:56 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											1997-08-26 13:20:34 +00:00
										 |  |  | 	/* Other compilers are just unlucky... */ | 
					
						
							| 
									
										
										
										
											1995-02-02 14:25:56 +00:00
										 |  |  | #endif /* !__MWERKS__ */
 | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** Handle an event, either through HandleEvent or by passing it to the Python | 
					
						
							|  |  |  | ** event handler. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | PyMac_HandleEvent(evp) | 
					
						
							|  |  |  | 	EventRecord *evp; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( python_event_handler ) { | 
					
						
							|  |  |  | 		rv = PyObject_CallFunction(python_event_handler, "(O&)",  | 
					
						
							|  |  |  | 			PyMac_BuildEventRecord, evp); | 
					
						
							|  |  |  | 		if ( rv ) | 
					
						
							|  |  |  | 			Py_DECREF(rv); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			return -1;	/* Propagate exception */ | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		PyMac_HandleEventIntern(evp); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											1995-02-02 14:25:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #if !TARGET_API_MAC_OSX
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | ** Yield the CPU to other tasks without processing events. | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2000-04-07 09:10:49 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | PyMac_DoYield(int maxsleep, int maycallpython) | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	EventRecord ev; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 	int gotone; | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	long latest_time_ready; | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | 	static int in_here = 0; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | 	in_here++; | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	** First check for interrupts, if wanted. | 
					
						
							|  |  |  | 	** This sets a flag that will be picked up at an appropriate | 
					
						
							|  |  |  | 	** moment in the mainloop. | 
					
						
							|  |  |  | 	*/ | 
					
						
							|  |  |  | 	if (schedparams.check_interrupt) | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 		scan_event_queue(0); | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* XXXX Implementing an idle routine goes here */ | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	** Check which of the eventloop cases we have: | 
					
						
							|  |  |  | 	** - process events | 
					
						
							|  |  |  | 	** - don't process events but do yield | 
					
						
							|  |  |  | 	** - do neither | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | 	if( in_here > 1 || !schedparams.process_events ||  | 
					
						
							|  |  |  | 	    (python_event_handler && !maycallpython) ) { | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 		if ( maxsleep >= 0 ) { | 
					
						
							| 
									
										
										
										
											2001-05-12 21:31:34 +00:00
										 |  |  | #if TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 			SystemTask(); | 
					
						
							| 
									
										
										
										
											2001-04-25 22:07:27 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 			int xxx = 0; | 
					
						
							| 
									
										
										
										
											2000-06-02 21:27:11 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-25 22:07:27 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		latest_time_ready = LMGetTicks() + maxsleep; | 
					
						
							| 
									
										
										
										
											2000-04-07 09:10:49 +00:00
										 |  |  | 		do { | 
					
						
							| 
									
										
										
										
											1997-08-26 13:20:34 +00:00
										 |  |  | 			/* XXXX Hack by Jack.
 | 
					
						
							|  |  |  | 			** In time.sleep() you can click to another application | 
					
						
							|  |  |  | 			** once only. If you come back to Python you cannot get away | 
					
						
							|  |  |  | 			** again. | 
					
						
							|  |  |  | 			**/ | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | 			gotone = WaitNextEvent(schedparams.process_events, &ev, maxsleep, NULL);	 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 			/* Get out quickly if nothing interesting is happening */ | 
					
						
							|  |  |  | 			if ( !gotone || ev.what == nullEvent ) | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | 			if ( PyMac_HandleEvent(&ev) < 0 ) { | 
					
						
							|  |  |  | 				in_here--; | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 			maxsleep = latest_time_ready - LMGetTicks(); | 
					
						
							| 
									
										
										
										
											2000-04-07 09:10:49 +00:00
										 |  |  | 		} while ( maxsleep > 0 ); | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | 	in_here--; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | ** Process events and/or yield the CPU to other tasks if opportune | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | PyMac_Yield() { | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	unsigned long maxsleep; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	if( PyMac_InForeground() ) | 
					
						
							|  |  |  | 		maxsleep = 0; | 
					
						
							| 
									
										
										
										
											1995-01-27 14:43:25 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 		maxsleep = schedparams.bg_yield; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-20 16:18:15 +00:00
										 |  |  | 	return PyMac_DoYield(maxsleep, 1); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | ** Return current scheduler parameters | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | void | 
					
						
							|  |  |  | PyMac_GetSchedParams(PyMacSchedParams *sp) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | 	sp->check_interrupt = schedparams.check_interrupt; | 
					
						
							|  |  |  | 	sp->process_events = schedparams.process_events; | 
					
						
							|  |  |  | 	sp->besocial = schedparams.besocial; | 
					
						
							|  |  |  | 	sp->check_interval = schedparams.check_interval / 60.0; | 
					
						
							|  |  |  | 	sp->bg_yield = schedparams.bg_yield / 60.0; | 
					
						
							| 
									
										
										
										
											1994-12-14 14:07:50 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1996-09-04 15:24:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-03 15:28:29 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Set current scheduler parameters | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | PyMac_SetSchedParams(PyMacSchedParams *sp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	schedparams.check_interrupt = sp->check_interrupt; | 
					
						
							|  |  |  | 	schedparams.process_events = sp->process_events; | 
					
						
							|  |  |  | 	schedparams.besocial = sp->besocial; | 
					
						
							|  |  |  | 	schedparams.check_interval = (unsigned long)(sp->check_interval*60); | 
					
						
							|  |  |  | 	schedparams.bg_yield = (unsigned long)(sp->bg_yield*60); | 
					
						
							|  |  |  | 	if ( schedparams.check_interrupt || schedparams.process_events || | 
					
						
							|  |  |  | 	     schedparams.besocial ) | 
					
						
							|  |  |  | 	     	schedparams.enabled = 1; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		schedparams.enabled = 0; | 
					
						
							|  |  |  | 	schedparams.next_check = 0;	/* Check immedeately */ | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1997-06-12 10:49:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-09-06 00:30:45 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Install our menu bar. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | PyMac_InitMenuBar() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	MenuHandle applemenu; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2001-04-25 22:07:27 +00:00
										 |  |  | 	if ( sioux_mbar ) return; | 
					
						
							| 
									
										
										
										
											1997-06-12 10:49:13 +00:00
										 |  |  | 	if ( (sioux_mbar=GetMenuBar()) == NULL )  { | 
					
						
							|  |  |  | 		/* Sioux menu not installed yet. Do so */ | 
					
						
							|  |  |  | 		SIOUXSetupMenus(); | 
					
						
							|  |  |  | 		if ( (sioux_mbar=GetMenuBar()) == NULL ) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-04-08 15:27:00 +00:00
										 |  |  | 	if ( (applemenu=GetMenuHandle(SIOUX_APPLEID)) == NULL ) return; | 
					
						
							| 
									
										
										
										
											1996-09-06 00:30:45 +00:00
										 |  |  | 	SetMenuItemText(applemenu, 1, "\pAbout Python..."); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-12 10:49:13 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Restore sioux menu bar | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | PyMac_RestoreMenuBar() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-04-25 22:07:27 +00:00
										 |  |  | #if 1
 | 
					
						
							| 
									
										
										
										
											2001-02-17 22:02:07 +00:00
										 |  |  | 	/* This doesn't seem to work anymore? Or only for Carbon? */ | 
					
						
							|  |  |  | 	MenuBarHandle curmenubar; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	curmenubar = GetMenuBar(); | 
					
						
							| 
									
										
										
										
											1997-06-12 15:29:46 +00:00
										 |  |  | 	if ( sioux_mbar ) { | 
					
						
							| 
									
										
										
										
											1997-06-12 10:49:13 +00:00
										 |  |  | 		SetMenuBar(sioux_mbar); | 
					
						
							| 
									
										
										
										
											1997-06-12 15:29:46 +00:00
										 |  |  | 		DrawMenuBar(); | 
					
						
							| 
									
										
										
										
											2001-02-17 22:02:07 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											1998-02-20 16:03:15 +00:00
										 |  |  | 		PyMac_InitMenuBar(); | 
					
						
							| 
									
										
										
										
											2001-02-17 22:02:07 +00:00
										 |  |  | 		DrawMenuBar(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1997-06-12 10:49:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-25 22:07:27 +00:00
										 |  |  | void | 
					
						
							|  |  |  | PyMac_RaiseConsoleWindow() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* Note: this is a hack. SIOUXTextWindow is SIOUX's internal structure
 | 
					
						
							|  |  |  | 	** and we happen to know that the first entry is the window pointer. | 
					
						
							|  |  |  | 	*/ | 
					
						
							|  |  |  | 	extern WindowRef *SIOUXTextWindow; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( SIOUXTextWindow == NULL || *SIOUXTextWindow == NULL ) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	if ( FrontWindow() != *SIOUXTextWindow ) | 
					
						
							|  |  |  | 		BringToFront(*SIOUXTextWindow); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1997-06-12 10:49:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-09-06 00:30:45 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Our replacement about box | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											1998-07-31 09:36:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "patchlevel.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-09-06 00:30:45 +00:00
										 |  |  | void | 
					
						
							|  |  |  | SIOUXDoAboutBox(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	DialogPtr theDialog; | 
					
						
							| 
									
										
										
										
											1998-07-31 09:36:30 +00:00
										 |  |  | 	WindowPtr theWindow; | 
					
						
							| 
									
										
										
										
											1996-09-06 00:30:45 +00:00
										 |  |  | 	short item; | 
					
						
							| 
									
										
										
										
											1998-07-31 09:36:30 +00:00
										 |  |  | 	short fontID; | 
					
						
							| 
									
										
										
										
											1996-09-06 00:30:45 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if( (theDialog = GetNewDialog(ABOUT_ID, NULL, (WindowPtr)-1)) == NULL ) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											1996-09-22 22:14:30 +00:00
										 |  |  | 	theWindow = GetDialogWindow(theDialog); | 
					
						
							| 
									
										
										
										
											1998-07-31 09:36:30 +00:00
										 |  |  | 	SetPortWindowPort(theWindow); | 
					
						
							|  |  |  | 	GetFNum("\pPython-Sans", &fontID); | 
					
						
							|  |  |  | 	if (fontID == 0) | 
					
						
							|  |  |  | 		fontID = kFontIDGeneva; | 
					
						
							|  |  |  | 	TextFont(fontID); | 
					
						
							|  |  |  | 	TextSize(9); | 
					
						
							|  |  |  | 	ParamText(Pstring(PATCHLEVEL), "\p", "\p", "\p"); | 
					
						
							| 
									
										
										
										
											1996-09-22 22:14:30 +00:00
										 |  |  | 	ShowWindow(theWindow); | 
					
						
							| 
									
										
										
										
											1996-09-06 00:30:45 +00:00
										 |  |  | 	ModalDialog(NULL, &item); | 
					
						
							|  |  |  | 	DisposeDialog(theDialog); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #endif /* !TARGET_API_MAC_OSX */
 | 
					
						
							| 
									
										
										
										
											1997-06-12 15:29:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #if TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Helper routine for GetDirectory | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											1995-02-20 23:45:53 +00:00
										 |  |  | static pascal short | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | myhook_proc(short item, DialogPtr theDialog, struct hook_args *dataptr) | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | 	if ( item == sfHookFirstCall && dataptr->prompt) { | 
					
						
							|  |  |  | 		Handle prompth; | 
					
						
							|  |  |  | 		short type; | 
					
						
							|  |  |  | 		Rect rect; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		GetDialogItem(theDialog, PROMPT_ITEM, &type, &prompth, &rect); | 
					
						
							|  |  |  | 		if ( prompth ) | 
					
						
							|  |  |  | 			SetDialogItemText(prompth, (unsigned char *)dataptr->prompt); | 
					
						
							|  |  |  | 	} else | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | 	if ( item == SELECTCUR_ITEM ) { | 
					
						
							|  |  |  | 		item = sfItemCancelButton; | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | 		dataptr->selectcur_hit = 1; | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return item; | 
					
						
							|  |  |  | }	 | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Ask the user for a directory. I still can't understand | 
					
						
							|  |  |  | ** why Apple doesn't provide a standard solution for this... | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | int | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | PyMac_GetDirectory(dirfss, prompt) | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | 	FSSpec *dirfss; | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | 	char *prompt; | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	static SFTypeList list = {'fldr', 0, 0, 0}; | 
					
						
							|  |  |  | 	static Point where = {-1, -1}; | 
					
						
							|  |  |  | 	StandardFileReply reply; | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | 	struct hook_args hook_args; | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if ( !upp_inited ) { | 
					
						
							|  |  |  | 		myhook_upp = NewDlgHookYDProc(myhook_proc); | 
					
						
							|  |  |  | 		upp_inited = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | 	if ( prompt && *prompt ) | 
					
						
							|  |  |  | 		hook_args.prompt = (char *)Pstring(prompt); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		hook_args.prompt = NULL; | 
					
						
							|  |  |  | 	hook_args.selectcur_hit = 0; | 
					
						
							| 
									
										
										
										
											1995-02-20 23:45:53 +00:00
										 |  |  | 	CustomGetFile((FileFilterYDUPP)0, 1, list, &reply, GETDIR_ID, where, myhook_upp, | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | 				NULL, NULL, NULL, (void *)&hook_args); | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | 	reply.sfFile.name[0] = 0; | 
					
						
							|  |  |  | 	if( FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, dirfss) ) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											1995-08-14 12:35:10 +00:00
										 |  |  | 	return hook_args.selectcur_hit; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** Slightly extended StandardGetFile: accepts a prompt */ | 
					
						
							|  |  |  | void PyMac_PromptGetFile(short numTypes, ConstSFTypeListPtr typeList,  | 
					
						
							|  |  |  | 		StandardFileReply *reply, char *prompt) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static Point where = {-1, -1}; | 
					
						
							|  |  |  | 	struct hook_args hook_args; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( !upp_inited ) { | 
					
						
							|  |  |  | 		myhook_upp = NewDlgHookYDProc(myhook_proc); | 
					
						
							|  |  |  | 		upp_inited = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ( prompt && *prompt ) | 
					
						
							|  |  |  | 		hook_args.prompt = (char *)Pstring(prompt); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		hook_args.prompt = NULL; | 
					
						
							|  |  |  | 	hook_args.selectcur_hit = 0; | 
					
						
							|  |  |  | 	CustomGetFile((FileFilterYDUPP)0, numTypes, typeList, reply, GETFILEPROMPT_ID, where, | 
					
						
							|  |  |  | 				myhook_upp, NULL, NULL, NULL, (void *)&hook_args); | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2001-05-12 21:31:34 +00:00
										 |  |  | #endif /* TARGET_API_MAC_OS8 */
 | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | /* Convert a 4-char string object argument to an OSType value */ | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | PyMac_GetOSType(PyObject *v, OSType *pr) | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!PyString_Check(v) || PyString_Size(v) != 4) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  | 			"OSType arg must be string of 4 chars"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	memcpy((char *)pr, PyString_AsString(v), 4); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | /* Convert an OSType value to a 4-char string object */ | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyMac_BuildOSType(OSType t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyString_FromStringAndSize((char *)&t, 4); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-01 15:23:54 +00:00
										 |  |  | /* Convert an NumVersion value to a 4-element tuple */ | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyMac_BuildNumVersion(NumVersion t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return Py_BuildValue("(hhhh)", t.majorRev, t.minorAndBugRev, t.stage, t.nonRelRev); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Convert a Python string object to a Str255 */ | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											1995-01-18 23:57:26 +00:00
										 |  |  | PyMac_GetStr255(PyObject *v, Str255 pbuf) | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int len; | 
					
						
							|  |  |  | 	if (!PyString_Check(v) || (len = PyString_Size(v)) > 255) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  | 			"Str255 arg must be string of at most 255 chars"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	pbuf[0] = len; | 
					
						
							|  |  |  | 	memcpy((char *)(pbuf+1), PyString_AsString(v), len); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | /* Convert a Str255 to a Python string object */ | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyMac_BuildStr255(Str255 s) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1999-12-17 17:15:50 +00:00
										 |  |  | 	if ( s == NULL ) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_SystemError, "Str255 pointer is NULL"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyMac_BuildOptStr255(Str255 s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ( s == NULL ) { | 
					
						
							|  |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | 	return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | ** Convert a Python object to an FSSpec. | 
					
						
							|  |  |  | ** The object may either be a full pathname or a triple | 
					
						
							|  |  |  | ** (vrefnum, dirid, path). | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | ** NOTE: This routine will fail on pre-sys7 machines.  | 
					
						
							|  |  |  | ** The caller is responsible for not calling this routine | 
					
						
							|  |  |  | ** in those cases (which is fine, since everyone calling | 
					
						
							|  |  |  | ** this is probably sys7 dependent anyway). | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | int | 
					
						
							| 
									
										
										
										
											1995-01-18 23:57:26 +00:00
										 |  |  | PyMac_GetFSSpec(PyObject *v, FSSpec *fs) | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Str255 path; | 
					
						
							|  |  |  | 	short refnum; | 
					
						
							|  |  |  | 	long parid; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 	FSSpec *fs2; | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #if !TARGET_API_MAC_OSX
 | 
					
						
							|  |  |  | 	/* XXX This #if is temporary */ | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 	/* first check whether it already is an FSSpec */ | 
					
						
							|  |  |  | 	fs2 = mfs_GetFSSpecFSSpec(v); | 
					
						
							|  |  |  | 	if ( fs2 ) { | 
					
						
							| 
									
										
										
										
											1995-02-20 15:56:10 +00:00
										 |  |  | 		(void)FSMakeFSSpec(fs2->vRefNum, fs2->parID, fs2->name, fs); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:36:45 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | 	if ( PyString_Check(v) ) { | 
					
						
							|  |  |  | 		/* It's a pathname */ | 
					
						
							| 
									
										
										
										
											1995-01-21 13:46:04 +00:00
										 |  |  | 		if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) ) | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											1996-03-06 16:21:34 +00:00
										 |  |  | 		refnum = 0; /* XXXX Should get CurWD here?? */ | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | 		parid = 0; | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											1995-01-21 13:46:04 +00:00
										 |  |  | 		if( !PyArg_Parse(v, "(hlO&); FSSpec should be fullpath or (vrefnum,dirid,path)", | 
					
						
							|  |  |  | 							&refnum, &parid, PyMac_GetStr255, &path)) { | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											1995-01-21 13:46:04 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	err = FSMakeFSSpec(refnum, parid, path, fs); | 
					
						
							|  |  |  | 	if ( err && err != fnfErr ) { | 
					
						
							| 
									
										
										
										
											2000-01-24 09:56:06 +00:00
										 |  |  | 		PyMac_Error(err); | 
					
						
							| 
									
										
										
										
											1995-01-18 13:53:49 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-12-12 21:37:14 +00:00
										 |  |  | /* Convert FSSpec to PyObject */ | 
					
						
							|  |  |  | PyObject *PyMac_BuildFSSpec(FSSpec *v) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #if TARGET_API_MAC_OSX
 | 
					
						
							|  |  |  | 	PyErr_SetString(PyExc_NotImplementedError, "FSSpec not yet done for OSX"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											1999-12-12 21:37:14 +00:00
										 |  |  | 	return newmfssobject(v); | 
					
						
							| 
									
										
										
										
											2001-05-12 22:46:35 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1999-12-12 21:37:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1995-01-18 23:57:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | /* Convert a Python object to a Rect.
 | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:59 +00:00
										 |  |  |    The object must be a (left, top, right, bottom) tuple. | 
					
						
							|  |  |  |    (This differs from the order in the struct but is consistent with | 
					
						
							|  |  |  |    the arguments to SetRect(), and also with STDWIN). */ | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | int | 
					
						
							|  |  |  | PyMac_GetRect(PyObject *v, Rect *r) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:59 +00:00
										 |  |  | 	return PyArg_Parse(v, "(hhhh)", &r->left, &r->top, &r->right, &r->bottom); | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Convert a Rect to a Python object */ | 
					
						
							| 
									
										
										
										
											1995-01-18 23:57:26 +00:00
										 |  |  | PyObject * | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | PyMac_BuildRect(Rect *r) | 
					
						
							| 
									
										
										
										
											1995-01-18 23:57:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:59 +00:00
										 |  |  | 	return Py_BuildValue("(hhhh)", r->left, r->top, r->right, r->bottom); | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Convert a Python object to a Point.
 | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:59 +00:00
										 |  |  |    The object must be a (h, v) tuple. | 
					
						
							|  |  |  |    (This differs from the order in the struct but is consistent with | 
					
						
							|  |  |  |    the arguments to SetPoint(), and also with STDWIN). */ | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | int | 
					
						
							|  |  |  | PyMac_GetPoint(PyObject *v, Point *p) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:59 +00:00
										 |  |  | 	return PyArg_Parse(v, "(hh)", &p->h, &p->v); | 
					
						
							| 
									
										
										
										
											1995-01-18 23:57:26 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1995-01-22 18:36:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | /* Convert a Point to a Python object */ | 
					
						
							| 
									
										
										
										
											1995-01-22 18:36:13 +00:00
										 |  |  | PyObject * | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | PyMac_BuildPoint(Point p) | 
					
						
							| 
									
										
										
										
											1995-01-22 18:36:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:59 +00:00
										 |  |  | 	return Py_BuildValue("(hh)", p.h, p.v); | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Convert a Python object to an EventRecord.
 | 
					
						
							|  |  |  |    The object must be a (what, message, when, (v, h), modifiers) tuple. */ | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | PyMac_GetEventRecord(PyObject *v, EventRecord *e) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyArg_Parse(v, "(hll(hh)h)", | 
					
						
							|  |  |  | 	                   &e->what, | 
					
						
							|  |  |  | 	                   &e->message, | 
					
						
							|  |  |  | 	                   &e->when, | 
					
						
							|  |  |  | 	                   &e->where.h, | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:59 +00:00
										 |  |  | 	                   &e->where.v,                    | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | 	                   &e->modifiers); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Convert a Rect to an EventRecord object */ | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyMac_BuildEventRecord(EventRecord *e) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return Py_BuildValue("(hll(hh)h)", | 
					
						
							|  |  |  | 	                     e->what, | 
					
						
							|  |  |  | 	                     e->message, | 
					
						
							|  |  |  | 	                     e->when, | 
					
						
							|  |  |  | 	                     e->where.h, | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:59 +00:00
										 |  |  | 	                     e->where.v, | 
					
						
							| 
									
										
										
										
											1995-01-25 23:06:44 +00:00
										 |  |  | 	                     e->modifiers); | 
					
						
							| 
									
										
										
										
											1995-01-22 18:36:13 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1995-11-15 15:19:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Convert Python object to Fixed */ | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | PyMac_GetFixed(PyObject *v, Fixed *f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	double d; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( !PyArg_Parse(v, "d", &d)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	*f = (Fixed)(d * 0x10000); | 
					
						
							| 
									
										
										
										
											1996-05-31 13:01:39 +00:00
										 |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											1995-11-15 15:19:29 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Convert a Point to a Python object */ | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyMac_BuildFixed(Fixed f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	double d; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	d = f; | 
					
						
							|  |  |  | 	d = d / 0x10000; | 
					
						
							|  |  |  | 	return Py_BuildValue("d", d); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-21 15:24:39 +00:00
										 |  |  | /* Convert wide to/from Python int or (hi, lo) tuple. XXXX Should use Python longs */ | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | PyMac_Getwide(PyObject *v, wide *rv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (PyInt_Check(v)) { | 
					
						
							|  |  |  | 		rv->hi = 0; | 
					
						
							|  |  |  | 		rv->lo = PyInt_AsLong(v); | 
					
						
							|  |  |  | 		if( rv->lo & 0x80000000 ) | 
					
						
							|  |  |  | 			rv->hi = -1; | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return PyArg_Parse(v, "(ll)", &rv->hi, &rv->lo); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							| 
									
										
										
										
											1998-04-23 13:20:17 +00:00
										 |  |  | PyMac_Buildwide(wide *w) | 
					
						
							| 
									
										
										
										
											1998-04-21 15:24:39 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1998-04-23 13:20:17 +00:00
										 |  |  | 	if ( (w->hi == 0 && (w->lo & 0x80000000) == 0) || | 
					
						
							|  |  |  | 	     (w->hi == -1 && (w->lo & 0x80000000) ) ) | 
					
						
							|  |  |  | 		return PyInt_FromLong(w->lo); | 
					
						
							|  |  |  | 	return Py_BuildValue("(ll)", w->hi, w->lo); | 
					
						
							| 
									
										
										
										
											1998-04-21 15:24:39 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2001-05-19 12:31:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef USE_TOOLBOX_OBJECT_GLUE
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** Glue together the toolbox objects. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Because toolbox modules interdepend on each other, they use each others | 
					
						
							|  |  |  | ** object types, on MacOSX/MachO this leads to the situation that they | 
					
						
							|  |  |  | ** cannot be dynamically loaded (or they would all have to be lumped into | 
					
						
							|  |  |  | ** a single .so, but this would be bad for extensibility). | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file defines wrappers for all the _New and _Convert functions, | 
					
						
							|  |  |  | ** which are the Py_BuildValue and PyArg_ParseTuple helpers. The wrappers | 
					
						
							|  |  |  | ** check an indirection function pointer, and if it isn't filled in yet | 
					
						
							|  |  |  | ** they import the appropriate module, whose init routine should fill in | 
					
						
							|  |  |  | ** the pointer. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GLUE_NEW(object, routinename, module) \
 | 
					
						
							|  |  |  | PyObject *(*PyMacGluePtr_##routinename)(object); \ | 
					
						
							|  |  |  | \ | 
					
						
							|  |  |  | PyObject *routinename(object cobj) { \ | 
					
						
							|  |  |  |     if (!PyMacGluePtr_##routinename) { \ | 
					
						
							|  |  |  |        if (!PyImport_ImportModule(module)) return NULL; \ | 
					
						
							|  |  |  |        if (!PyMacGluePtr_##routinename) { \ | 
					
						
							|  |  |  |            PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ | 
					
						
							|  |  |  |            return NULL; \ | 
					
						
							|  |  |  |        } \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |     return (*PyMacGluePtr_##routinename)(cobj); \ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GLUE_CONVERT(object, routinename, module) \
 | 
					
						
							|  |  |  | int (*PyMacGluePtr_##routinename)(PyObject *, object *); \ | 
					
						
							|  |  |  | \ | 
					
						
							|  |  |  | int routinename(PyObject *pyobj, object *cobj) { \ | 
					
						
							|  |  |  |     if (!PyMacGluePtr_##routinename) { \ | 
					
						
							|  |  |  |        if (!PyImport_ImportModule(module)) return NULL; \ | 
					
						
							|  |  |  |        if (!PyMacGluePtr_##routinename) { \ | 
					
						
							|  |  |  |            PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ | 
					
						
							|  |  |  |            return NULL; \ | 
					
						
							|  |  |  |        } \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |     return (*PyMacGluePtr_##routinename)(pyobj, cobj); \ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(AppleEvent *, AEDesc_New, "AE") /* XXXX Why by address? */ | 
					
						
							|  |  |  | GLUE_CONVERT(AppleEvent, AEDesc_Convert, "AE") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(Component, CmpObj_New, "Cm") | 
					
						
							|  |  |  | GLUE_CONVERT(Component, CmpObj_Convert, "Cm") | 
					
						
							|  |  |  | GLUE_NEW(ComponentInstance, CmpInstObj_New, "Cm") | 
					
						
							|  |  |  | GLUE_CONVERT(ComponentInstance, CmpInstObj_Convert, "Cm") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(ControlHandle, CtlObj_New, "Ctl") | 
					
						
							|  |  |  | GLUE_CONVERT(ControlHandle, CtlObj_Convert, "Ctl") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(DialogPtr, DlgObj_New, "Dlg") | 
					
						
							|  |  |  | GLUE_CONVERT(DialogPtr, DlgObj_Convert, "Dlg") | 
					
						
							|  |  |  | GLUE_NEW(DialogPtr, DlgObj_WhichDialog, "Dlg") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(DragReference, DragObj_New, "Drag") | 
					
						
							|  |  |  | GLUE_CONVERT(DragReference, DragObj_Convert, "Drag") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(ListHandle, ListObj_New, "List") | 
					
						
							|  |  |  | GLUE_CONVERT(ListHandle, ListObj_Convert, "List") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(MenuHandle, MenuObj_New, "Menu") | 
					
						
							|  |  |  | GLUE_CONVERT(MenuHandle, MenuObj_Convert, "Menu") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(GrafPtr, GrafObj_New, "Qd") | 
					
						
							|  |  |  | GLUE_CONVERT(GrafPtr, GrafObj_Convert, "Qd") | 
					
						
							|  |  |  | GLUE_NEW(BitMapPtr, BMObj_New, "Qd") | 
					
						
							|  |  |  | GLUE_CONVERT(BitMapPtr, BMObj_Convert, "Qd") | 
					
						
							|  |  |  | GLUE_NEW(RGBColor *, QdRGB_New, "Qd") /* XXXX Why? */ | 
					
						
							|  |  |  | GLUE_CONVERT(RGBColor, QdRGB_Convert, "Qd") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(GWorldPtr, GWorldObj_New, "Qdoffs") | 
					
						
							|  |  |  | GLUE_CONVERT(GWorldPtr, GWorldObj_Convert, "Qdoffs") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(Track, TrackObj_New, "Qt") | 
					
						
							|  |  |  | GLUE_CONVERT(Track, TrackObj_Convert, "Qt") | 
					
						
							|  |  |  | GLUE_NEW(Movie, MovieObj_New, "Qt") | 
					
						
							|  |  |  | GLUE_CONVERT(Movie, MovieObj_Convert, "Qt") | 
					
						
							|  |  |  | GLUE_NEW(MovieController, MovieCtlObj_New, "Qt") | 
					
						
							|  |  |  | GLUE_CONVERT(MovieController, MovieCtlObj_Convert, "Qt") | 
					
						
							|  |  |  | GLUE_NEW(TimeBase, TimeBaseObj_New, "Qt") | 
					
						
							|  |  |  | GLUE_CONVERT(TimeBase, TimeBaseObj_Convert, "Qt") | 
					
						
							|  |  |  | GLUE_NEW(UserData, UserDataObj_New, "Qt") | 
					
						
							|  |  |  | GLUE_CONVERT(UserData, UserDataObj_Convert, "Qt") | 
					
						
							|  |  |  | GLUE_NEW(Media, MediaObj_New, "Qt") | 
					
						
							|  |  |  | GLUE_CONVERT(Media, MediaObj_Convert, "Qt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(Handle, ResObj_New, "Res") | 
					
						
							|  |  |  | GLUE_CONVERT(Handle, ResObj_Convert, "Res") | 
					
						
							|  |  |  | GLUE_NEW(Handle, OptResObj_New, "Res") | 
					
						
							|  |  |  | GLUE_CONVERT(Handle, OptResObj_Convert, "Res") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(TEHandle, TEObj_New, "TE") | 
					
						
							|  |  |  | GLUE_CONVERT(TEHandle, TEObj_Convert, "TE") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GLUE_NEW(WindowPtr, WinObj_New, "Win") | 
					
						
							|  |  |  | GLUE_CONVERT(WindowPtr, WinObj_Convert, "Win") | 
					
						
							|  |  |  | GLUE_NEW(WindowPtr, WinObj_WhichWindow, "Win") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* USE_TOOLBOX_OBJECT_GLUE */
 |