Guido van Rossum | b340466 | 1995-01-22 18:36:13 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Jack Jansen | 42218ce | 1997-01-31 16:15:11 +0000 | [diff] [blame] | 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
Guido van Rossum | b340466 | 1995-01-22 18:36:13 +0000 | [diff] [blame] | 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 24 | |
Jack Jansen | bf05d4c | 1996-08-19 15:11:45 +0000 | [diff] [blame] | 25 | |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 26 | #include "Python.h" |
Guido van Rossum | becdbec | 1995-02-14 01:27:24 +0000 | [diff] [blame] | 27 | |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 28 | #include "macglue.h" |
Jack Jansen | 74162f3 | 1995-02-15 22:58:33 +0000 | [diff] [blame] | 29 | #include "marshal.h" |
| 30 | #include "import.h" |
Jack Jansen | eda7863 | 1997-06-12 15:29:46 +0000 | [diff] [blame] | 31 | #include "importdl.h" |
Jack Jansen | 8bb1dc1 | 2001-05-19 12:31:09 +0000 | [diff] [blame] | 32 | #include "pymactoolbox.h" |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 33 | |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 34 | #include "pythonresources.h" |
| 35 | |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 36 | #ifdef WITHOUT_FRAMEWORKS |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 37 | #include <OSUtils.h> /* for Set(Current)A5 */ |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 38 | #include <Files.h> |
Jack Jansen | 8cd2b72 | 1995-02-13 11:33:28 +0000 | [diff] [blame] | 39 | #include <StandardFile.h> |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 40 | #include <Resources.h> |
| 41 | #include <Memory.h> |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 42 | #include <Windows.h> |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 43 | #include <Traps.h> |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 44 | #include <Processes.h> |
Guido van Rossum | c3d1c8e | 1995-02-18 15:01:31 +0000 | [diff] [blame] | 45 | #include <Fonts.h> |
| 46 | #include <Menus.h> |
Jack Jansen | 0830550 | 1995-06-18 20:03:40 +0000 | [diff] [blame] | 47 | #include <TextUtils.h> |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 48 | #include <LowMem.h> |
| 49 | #ifdef __CFM68K__ |
| 50 | /* cfm68k InterfaceLib exports GetEventQueue, but Events.h doesn't know this |
| 51 | ** and defines it as GetEvQHdr (which is correct for PPC). This fix is for |
| 52 | ** CW9, check that the workaround is still needed for the next release. |
| 53 | */ |
| 54 | #define GetEvQHdr GetEventQueue |
| 55 | #endif /* __CFM68K__ */ |
| 56 | |
| 57 | #include <Events.h> |
| 58 | |
| 59 | #ifdef __CFM68K__ |
| 60 | #undef GetEventQueue |
| 61 | #endif /* __CFM68K__ */ |
| 62 | #else |
| 63 | #include <Carbon/Carbon.h> |
| 64 | #endif |
| 65 | |
| 66 | #if !TARGET_API_MAC_OS8 |
| 67 | /* Unfortunately this call is probably slower... */ |
| 68 | #define LMGetTicks() TickCount() |
| 69 | #endif |
| 70 | |
Jack Jansen | 16df2aa | 1995-02-27 16:17:28 +0000 | [diff] [blame] | 71 | #ifdef __MWERKS__ |
| 72 | #include <SIOUX.h> |
Jack Jansen | 9ae898b | 2000-07-11 21:16:03 +0000 | [diff] [blame] | 73 | extern void SIOUXSetupMenus(void); |
| 74 | extern void SIOUXDoAboutBox(void); |
Jack Jansen | 16df2aa | 1995-02-27 16:17:28 +0000 | [diff] [blame] | 75 | #endif |
Jack Jansen | 9ae898b | 2000-07-11 21:16:03 +0000 | [diff] [blame] | 76 | #ifdef USE_GUSI |
| 77 | /* Functions we redefine because they're in obscure libraries */ |
| 78 | extern void SpinCursor(short x); |
| 79 | extern void RotateCursor(short x); |
| 80 | extern pascal void PLstrcpy(unsigned char *, unsigned char *); |
| 81 | extern pascal int PLstrcmp(unsigned char *, unsigned char *); |
| 82 | extern pascal unsigned char *PLstrrchr(unsigned char *, unsigned char); |
| 83 | |
| 84 | #endif |
| 85 | |
Jack Jansen | 2d1306b | 2000-04-07 09:10:49 +0000 | [diff] [blame] | 86 | #ifdef USE_GUSI1 |
Jack Jansen | 911ad6b | 1996-03-05 16:56:24 +0000 | [diff] [blame] | 87 | #include <TFileSpec.h> /* For Path2FSSpec */ |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 88 | #include <GUSI.h> |
Jack Jansen | 911ad6b | 1996-03-05 16:56:24 +0000 | [diff] [blame] | 89 | #endif |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 90 | |
Jack Jansen | 3469e99 | 1996-09-06 00:30:45 +0000 | [diff] [blame] | 91 | /* The ID of the Sioux apple menu */ |
| 92 | #define SIOUX_APPLEID 32000 |
| 93 | |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 94 | #include <signal.h> |
Jack Jansen | 74162f3 | 1995-02-15 22:58:33 +0000 | [diff] [blame] | 95 | #include <stdio.h> |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 96 | |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 97 | /* |
Jack Jansen | d1f0631 | 1996-08-01 15:23:54 +0000 | [diff] [blame] | 98 | ** When less than this amount of stackspace is left we |
| 99 | ** raise a MemoryError. |
| 100 | */ |
| 101 | #ifndef MINIMUM_STACK_SIZE |
| 102 | #ifdef __powerc |
| 103 | #define MINIMUM_STACK_SIZE 8192 |
| 104 | #else |
| 105 | #define MINIMUM_STACK_SIZE 4096 |
| 106 | #endif |
| 107 | #endif |
| 108 | |
Jack Jansen | 340eb88 | 2001-02-02 22:40:28 +0000 | [diff] [blame] | 109 | #if TARGET_API_MAC_CARBON |
| 110 | /* |
| 111 | ** On MacOSX StackSpace() lies: it gives the distance from heap end to stack pointer, |
| 112 | ** but the stack cannot grow that far due to rlimit values. We cannot get at this value |
| 113 | ** from Carbon, so we set a maximum to the stack here that is based on the default |
| 114 | ** stack limit of 512K. |
| 115 | */ |
| 116 | #define MAXIMUM_STACK_SIZE (256*1024) |
| 117 | #endif |
| 118 | |
Jack Jansen | d1f0631 | 1996-08-01 15:23:54 +0000 | [diff] [blame] | 119 | /* |
Jack Jansen | 16df2aa | 1995-02-27 16:17:28 +0000 | [diff] [blame] | 120 | ** We have to be careful, since we can't handle |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 121 | ** things like updates (and they'll keep coming back if we don't |
Jack Jansen | 16df2aa | 1995-02-27 16:17:28 +0000 | [diff] [blame] | 122 | ** handle them). Note that we don't know who has windows open, so |
| 123 | ** even handing updates off to SIOUX under MW isn't going to work. |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 124 | */ |
Jack Jansen | 0c96887 | 1997-08-26 13:20:34 +0000 | [diff] [blame] | 125 | #define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask|activMask) |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 126 | |
| 127 | #include <signal.h> |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 128 | |
Guido van Rossum | b340466 | 1995-01-22 18:36:13 +0000 | [diff] [blame] | 129 | /* XXX We should include Errors.h here, but it has a name conflict |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 130 | ** with the python errors.h. */ |
| 131 | #define fnfErr -43 |
| 132 | |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 133 | /* Declared in macfsmodule.c: */ |
Jack Jansen | 9ae898b | 2000-07-11 21:16:03 +0000 | [diff] [blame] | 134 | extern FSSpec *mfs_GetFSSpecFSSpec(PyObject *); |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 135 | extern PyObject *newmfssobject(FSSpec *); |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 136 | |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 137 | /* Interrupt code variables: */ |
| 138 | static int interrupted; /* Set to true when cmd-. seen */ |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 139 | static RETSIGTYPE intcatcher(int); |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 140 | |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 141 | #if !TARGET_API_MAC_OSX |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 142 | static int PyMac_Yield(void); |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 143 | #endif |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 144 | |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 145 | /* |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 146 | ** These are the real scheduling parameters that control what we check |
| 147 | ** in the event loop, and how often we check. The values are initialized |
| 148 | ** from pyMac_SchedParamStruct. |
| 149 | */ |
| 150 | |
| 151 | struct real_sched_param_struct { |
| 152 | int check_interrupt; /* if true check for command-dot */ |
| 153 | int process_events; /* if nonzero enable evt processing, this mask */ |
| 154 | int besocial; /* if nonzero be a little social with CPU */ |
| 155 | unsigned long check_interval; /* how often to check, in ticks */ |
| 156 | unsigned long bg_yield; /* yield so long when in background */ |
| 157 | /* these are computed from previous and clock and such */ |
| 158 | int enabled; /* check_interrupt OR process_event OR yield */ |
| 159 | unsigned long next_check; /* when to check/yield next, in ticks */ |
| 160 | }; |
| 161 | |
| 162 | static struct real_sched_param_struct schedparams = |
| 163 | { 1, MAINLOOP_EVENTMASK, 1, 15, 15, 1, 0}; |
| 164 | |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 165 | /* |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 166 | ** Workaround for sioux/gusi combo: set when we are exiting |
| 167 | */ |
| 168 | int PyMac_ConsoleIsDead; |
| 169 | |
| 170 | /* |
Jack Jansen | caa7c46 | 1997-06-12 10:49:13 +0000 | [diff] [blame] | 171 | ** Sioux menu bar, saved early so we can restore it |
| 172 | */ |
Jack Jansen | 657ba27 | 2001-02-17 22:02:07 +0000 | [diff] [blame] | 173 | static MenuBarHandle sioux_mbar; |
Jack Jansen | caa7c46 | 1997-06-12 10:49:13 +0000 | [diff] [blame] | 174 | |
| 175 | /* |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 176 | ** Some stuff for our GetDirectory and PromptGetFile routines |
| 177 | */ |
| 178 | struct hook_args { |
| 179 | int selectcur_hit; /* Set to true when "select current" selected */ |
| 180 | char *prompt; /* The prompt */ |
| 181 | }; |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 182 | #if !TARGET_API_MAC_OS8 |
Jack Jansen | bb6d83a | 2000-06-02 21:27:11 +0000 | [diff] [blame] | 183 | /* The StandardFile hooks don't exist in Carbon. This breaks GetDirectory, |
| 184 | ** but the macfsn code will replace it by a NavServices version anyway. |
| 185 | */ |
| 186 | #define myhook_upp NULL |
| 187 | #else |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 188 | static DlgHookYDUPP myhook_upp; |
| 189 | static int upp_inited = 0; |
Jack Jansen | bb6d83a | 2000-06-02 21:27:11 +0000 | [diff] [blame] | 190 | #endif |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 191 | |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 192 | /* |
| 193 | ** The python-code event handler |
| 194 | */ |
| 195 | static PyObject *python_event_handler; |
| 196 | |
Jack Jansen | 8f5725a | 1999-12-07 23:08:10 +0000 | [diff] [blame] | 197 | /* |
| 198 | ** Set to true if we're appearance-compliant |
| 199 | */ |
| 200 | int PyMac_AppearanceCompliant; |
| 201 | |
Jack Jansen | 1f9f2f4 | 2000-07-24 19:50:16 +0000 | [diff] [blame] | 202 | /* |
| 203 | ** Find out what the current script is. |
| 204 | ** Donated by Fredrik Lund. |
| 205 | */ |
| 206 | char *PyMac_getscript() |
| 207 | { |
| 208 | int font, script, lang; |
| 209 | font = 0; |
| 210 | font = GetSysFont(); |
| 211 | script = FontToScript(font); |
| 212 | switch (script) { |
| 213 | case smRoman: |
| 214 | lang = GetScriptVariable(script, smScriptLang); |
| 215 | if (lang == langIcelandic) |
| 216 | return "mac-iceland"; |
| 217 | else if (lang == langTurkish) |
| 218 | return "mac-turkish"; |
| 219 | else if (lang == langGreek) |
| 220 | return "mac-greek"; |
| 221 | else |
| 222 | return "mac-roman"; |
| 223 | break; |
unknown | f428aef | 2001-07-04 22:36:27 +0000 | [diff] [blame] | 224 | #if 0 |
| 225 | /* We don't have a codec for this, so don't return it */ |
Jack Jansen | 1f9f2f4 | 2000-07-24 19:50:16 +0000 | [diff] [blame] | 226 | case smJapanese: |
| 227 | return "mac-japan"; |
unknown | f428aef | 2001-07-04 22:36:27 +0000 | [diff] [blame] | 228 | #endif |
Jack Jansen | 1f9f2f4 | 2000-07-24 19:50:16 +0000 | [diff] [blame] | 229 | case smGreek: |
| 230 | return "mac-greek"; |
| 231 | case smCyrillic: |
| 232 | return "mac-cyrillic"; |
| 233 | default: |
| 234 | return "mac-roman"; /* better than nothing */ |
| 235 | } |
| 236 | } |
| 237 | |
Jack Jansen | 741e037 | 2001-05-19 12:55:57 +0000 | [diff] [blame] | 238 | /* Given an FSSpec, return the FSSpec of the parent folder */ |
| 239 | |
| 240 | static OSErr |
| 241 | get_folder_parent (FSSpec * fss, FSSpec * parent) |
| 242 | { |
| 243 | CInfoPBRec rec; |
| 244 | short err; |
| 245 | |
| 246 | * parent = * fss; |
| 247 | rec.hFileInfo.ioNamePtr = parent->name; |
| 248 | rec.hFileInfo.ioVRefNum = parent->vRefNum; |
| 249 | rec.hFileInfo.ioDirID = parent->parID; |
| 250 | rec.hFileInfo.ioFDirIndex = -1; |
| 251 | rec.hFileInfo.ioFVersNum = 0; |
| 252 | if (err = PBGetCatInfoSync (& rec)) |
| 253 | return err; |
| 254 | parent->parID = rec.dirInfo.ioDrParID; |
| 255 | /* parent->name[0] = 0; */ |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | /* Given an FSSpec return a full, colon-separated pathname */ |
| 260 | |
| 261 | OSErr |
| 262 | PyMac_GetFullPath (FSSpec *fss, char *buf) |
| 263 | { |
| 264 | short err; |
| 265 | FSSpec fss_parent, fss_current; |
| 266 | char tmpbuf[1024]; |
| 267 | int plen; |
| 268 | |
| 269 | fss_current = *fss; |
| 270 | plen = fss_current.name[0]; |
| 271 | memcpy(buf, &fss_current.name[1], plen); |
| 272 | buf[plen] = 0; |
| 273 | /* Special case for disk names */ |
| 274 | if ( fss_current.parID <= 1 ) { |
| 275 | buf[plen++] = ':'; |
| 276 | buf[plen] = 0; |
| 277 | return 0; |
| 278 | } |
| 279 | while (fss_current.parID > 1) { |
| 280 | /* Get parent folder name */ |
| 281 | if (err = get_folder_parent(&fss_current, &fss_parent)) |
| 282 | return err; |
| 283 | fss_current = fss_parent; |
| 284 | /* Prepend path component just found to buf */ |
| 285 | plen = fss_current.name[0]; |
| 286 | if (strlen(buf) + plen + 1 > 1024) { |
| 287 | /* Oops... Not enough space (shouldn't happen) */ |
| 288 | *buf = 0; |
| 289 | return -1; |
| 290 | } |
| 291 | memcpy(tmpbuf, &fss_current.name[1], plen); |
| 292 | tmpbuf[plen] = ':'; |
| 293 | strcpy(&tmpbuf[plen+1], buf); |
| 294 | strcpy(buf, tmpbuf); |
| 295 | } |
| 296 | return 0; |
| 297 | } |
Jack Jansen | 1f9f2f4 | 2000-07-24 19:50:16 +0000 | [diff] [blame] | 298 | |
Jack Jansen | 2d1306b | 2000-04-07 09:10:49 +0000 | [diff] [blame] | 299 | #ifdef USE_GUSI1 |
Jack Jansen | 378815c | 1996-03-06 16:21:34 +0000 | [diff] [blame] | 300 | /* |
| 301 | ** GUSI (1.6.0 and earlier, at the least) do not set the MacOS idea of |
| 302 | ** the working directory. Hence, we call this routine after each call |
| 303 | ** to chdir() to rectify things. |
| 304 | */ |
| 305 | void |
| 306 | PyMac_FixGUSIcd() |
| 307 | { |
| 308 | WDPBRec pb; |
| 309 | FSSpec curdirfss; |
| 310 | |
| 311 | if ( Path2FSSpec(":x", &curdirfss) != noErr ) |
| 312 | return; |
| 313 | |
| 314 | /* Set MacOS "working directory" */ |
| 315 | pb.ioNamePtr= "\p"; |
| 316 | pb.ioVRefNum= curdirfss.vRefNum; |
| 317 | pb.ioWDDirID= curdirfss.parID; |
Jack Jansen | 08c3be3 | 1997-04-08 15:27:00 +0000 | [diff] [blame] | 318 | if (PBHSetVolSync(&pb) != noErr) |
Jack Jansen | 378815c | 1996-03-06 16:21:34 +0000 | [diff] [blame] | 319 | return; |
Jack Jansen | 378815c | 1996-03-06 16:21:34 +0000 | [diff] [blame] | 320 | } |
Jack Jansen | 2d1306b | 2000-04-07 09:10:49 +0000 | [diff] [blame] | 321 | #endif |
Jack Jansen | 7ac70af | 1996-08-19 11:01:05 +0000 | [diff] [blame] | 322 | |
Jack Jansen | 2d1306b | 2000-04-07 09:10:49 +0000 | [diff] [blame] | 323 | #ifdef USE_GUSI |
Jack Jansen | 7d5f9e8 | 1996-09-07 17:09:31 +0000 | [diff] [blame] | 324 | /* |
| 325 | ** SpinCursor (needed by GUSI) drags in heaps of stuff, so we |
| 326 | ** provide a dummy here. |
| 327 | */ |
Jack Jansen | cfadbd4 | 1996-08-19 11:36:25 +0000 | [diff] [blame] | 328 | void SpinCursor(short x) { /* Dummy */ } |
Jack Jansen | efaada7 | 1998-02-20 16:03:15 +0000 | [diff] [blame] | 329 | void RotateCursor(short x) { /* Dummy */ } |
Jack Jansen | cfadbd4 | 1996-08-19 11:36:25 +0000 | [diff] [blame] | 330 | |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 331 | /* |
| 332 | ** Replacement GUSI Spin function |
| 333 | */ |
Jack Jansen | 2d1306b | 2000-04-07 09:10:49 +0000 | [diff] [blame] | 334 | #ifdef USE_GUSI1 |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 335 | static int |
| 336 | PyMac_GUSISpin(spin_msg msg, long arg) |
| 337 | { |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 338 | static Boolean inForeground = true; |
| 339 | int maxsleep = 6; /* 6 ticks is "normal" sleeptime */ |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 340 | |
| 341 | if (PyMac_ConsoleIsDead) return 0; |
| 342 | #if 0 |
| 343 | if (inForeground) |
| 344 | SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1); |
| 345 | #endif |
| 346 | |
| 347 | if (interrupted) return -1; |
| 348 | |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 349 | if ( msg == SP_AUTO_SPIN ) |
| 350 | maxsleep = 0; |
| 351 | if ( msg==SP_SLEEP||msg==SP_SELECT ) |
| 352 | maxsleep = arg; |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 353 | |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 354 | PyMac_DoYield(maxsleep, 0); /* XXXX or is it safe to call python here? */ |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | void |
| 360 | PyMac_SetGUSISpin() { |
| 361 | GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin); |
| 362 | } |
Jack Jansen | 2d1306b | 2000-04-07 09:10:49 +0000 | [diff] [blame] | 363 | #endif |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 364 | |
Jack Jansen | a39f1b0 | 1997-05-23 15:35:14 +0000 | [diff] [blame] | 365 | /* Called at exit() time thru atexit(), to stop event processing */ |
| 366 | void |
| 367 | PyMac_StopGUSISpin() { |
| 368 | PyMac_ConsoleIsDead = 1; |
| 369 | } |
| 370 | |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 371 | #if TARGET_API_MAC_OS8 |
Jack Jansen | a39f1b0 | 1997-05-23 15:35:14 +0000 | [diff] [blame] | 372 | /* |
| 373 | ** Replacement routines for the PLstr... functions so we don't need |
Jack Jansen | 6ba34aa | 2001-01-11 23:03:56 +0000 | [diff] [blame] | 374 | ** StdCLib. |
Jack Jansen | a39f1b0 | 1997-05-23 15:35:14 +0000 | [diff] [blame] | 375 | */ |
Jack Jansen | 8bb573e | 1999-12-12 21:37:14 +0000 | [diff] [blame] | 376 | pascal void |
Jack Jansen | 9ae898b | 2000-07-11 21:16:03 +0000 | [diff] [blame] | 377 | PLstrcpy(unsigned char *to, unsigned char *fr) |
Jack Jansen | a39f1b0 | 1997-05-23 15:35:14 +0000 | [diff] [blame] | 378 | { |
| 379 | memcpy(to, fr, fr[0]+1); |
| 380 | } |
| 381 | |
Jack Jansen | 8bb573e | 1999-12-12 21:37:14 +0000 | [diff] [blame] | 382 | pascal int |
Jack Jansen | 9ae898b | 2000-07-11 21:16:03 +0000 | [diff] [blame] | 383 | PLstrcmp(unsigned char *s1, unsigned char *s2) |
Jack Jansen | a39f1b0 | 1997-05-23 15:35:14 +0000 | [diff] [blame] | 384 | { |
| 385 | int res; |
| 386 | int l = s1[0] < s2[0] ? s1[0] : s2[0]; |
| 387 | |
| 388 | res = memcmp(s1+1, s2+1, l); |
| 389 | if ( res != 0 ) |
| 390 | return res; |
| 391 | |
Jack Jansen | 7e1fb7c | 1998-07-31 09:36:30 +0000 | [diff] [blame] | 392 | if ( s1[0] < s2[0] ) |
Jack Jansen | a39f1b0 | 1997-05-23 15:35:14 +0000 | [diff] [blame] | 393 | return -1; |
Jack Jansen | 7e1fb7c | 1998-07-31 09:36:30 +0000 | [diff] [blame] | 394 | else if ( s1[0] > s2[0] ) |
Jack Jansen | a39f1b0 | 1997-05-23 15:35:14 +0000 | [diff] [blame] | 395 | return 1; |
| 396 | else |
| 397 | return 0; |
| 398 | } |
| 399 | |
Jack Jansen | 8bb573e | 1999-12-12 21:37:14 +0000 | [diff] [blame] | 400 | pascal unsigned char * |
Jack Jansen | 9ae898b | 2000-07-11 21:16:03 +0000 | [diff] [blame] | 401 | PLstrrchr(unsigned char *str, unsigned char chr) |
Jack Jansen | a39f1b0 | 1997-05-23 15:35:14 +0000 | [diff] [blame] | 402 | { |
| 403 | unsigned char *ptr = 0; |
| 404 | unsigned char *p; |
| 405 | |
| 406 | for(p=str+1; p<str+str[0]; p++) |
| 407 | if ( *p == chr ) |
| 408 | ptr = p; |
| 409 | return ptr; |
| 410 | } |
| 411 | |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 412 | #endif /* TARGET_API_MAC_OS8 */ |
Jack Jansen | a39f1b0 | 1997-05-23 15:35:14 +0000 | [diff] [blame] | 413 | #endif /* USE_GUSI */ |
Jack Jansen | 378815c | 1996-03-06 16:21:34 +0000 | [diff] [blame] | 414 | |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 415 | |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 416 | /* Convert C to Pascal string. Returns pointer to static buffer. */ |
| 417 | unsigned char * |
| 418 | Pstring(char *str) |
| 419 | { |
| 420 | static Str255 buf; |
| 421 | int len; |
| 422 | |
| 423 | len = strlen(str); |
Guido van Rossum | 9aa3d13 | 1995-01-21 13:46:04 +0000 | [diff] [blame] | 424 | if (len > 255) |
| 425 | len = 255; |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 426 | buf[0] = (unsigned char)len; |
| 427 | strncpy((char *)buf+1, str, len); |
| 428 | return buf; |
| 429 | } |
| 430 | |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 431 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 5afad83 | 2000-12-12 22:12:14 +0000 | [diff] [blame] | 432 | void |
| 433 | c2pstrcpy(unsigned char *dst, const char *src) |
| 434 | { |
| 435 | int len; |
| 436 | |
| 437 | len = strlen(src); |
| 438 | if ( len > 255 ) len = 255; |
| 439 | strncpy((char *)dst+1, src, len); |
| 440 | dst[0] = len; |
| 441 | } |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 442 | #endif /* TARGET_API_MAC_OS8 */ |
Jack Jansen | 5afad83 | 2000-12-12 22:12:14 +0000 | [diff] [blame] | 443 | |
Guido van Rossum | c3d1c8e | 1995-02-18 15:01:31 +0000 | [diff] [blame] | 444 | /* Like strerror() but for Mac OS error numbers */ |
| 445 | char *PyMac_StrError(int err) |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 446 | { |
| 447 | static char buf[256]; |
| 448 | Handle h; |
| 449 | char *str; |
| 450 | |
| 451 | h = GetResource('Estr', err); |
| 452 | if ( h ) { |
| 453 | HLock(h); |
| 454 | str = (char *)*h; |
| 455 | memcpy(buf, str+1, (unsigned char)str[0]); |
Guido van Rossum | cc9bc8f | 1995-02-13 16:17:03 +0000 | [diff] [blame] | 456 | buf[(unsigned char)str[0]] = '\0'; |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 457 | HUnlock(h); |
| 458 | ReleaseResource(h); |
| 459 | } else { |
| 460 | sprintf(buf, "Mac OS error code %d", err); |
| 461 | } |
| 462 | return buf; |
| 463 | } |
| 464 | |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 465 | /* Exception object shared by all Mac specific modules for Mac OS errors */ |
| 466 | PyObject *PyMac_OSErrException; |
| 467 | |
| 468 | /* Initialize and return PyMac_OSErrException */ |
| 469 | PyObject * |
| 470 | PyMac_GetOSErrException() |
| 471 | { |
| 472 | if (PyMac_OSErrException == NULL) |
unknown | f428aef | 2001-07-04 22:36:27 +0000 | [diff] [blame] | 473 | PyMac_OSErrException = PyString_FromString("MacOS.Error"); |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 474 | return PyMac_OSErrException; |
| 475 | } |
| 476 | |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 477 | /* Set a MAC-specific error from errno, and return NULL; return None if no error */ |
| 478 | PyObject * |
Guido van Rossum | fffb8bb | 1995-01-12 12:37:24 +0000 | [diff] [blame] | 479 | PyErr_Mac(PyObject *eobj, int err) |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 480 | { |
| 481 | char *msg; |
| 482 | PyObject *v; |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 483 | |
Guido van Rossum | 8f69179 | 1995-01-18 23:57:26 +0000 | [diff] [blame] | 484 | if (err == 0 && !PyErr_Occurred()) { |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 485 | Py_INCREF(Py_None); |
| 486 | return Py_None; |
| 487 | } |
Guido van Rossum | 8f69179 | 1995-01-18 23:57:26 +0000 | [diff] [blame] | 488 | if (err == -1 && PyErr_Occurred()) |
| 489 | return NULL; |
Guido van Rossum | c3d1c8e | 1995-02-18 15:01:31 +0000 | [diff] [blame] | 490 | msg = PyMac_StrError(err); |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 491 | v = Py_BuildValue("(is)", err, msg); |
| 492 | PyErr_SetObject(eobj, v); |
| 493 | Py_DECREF(v); |
| 494 | return NULL; |
| 495 | } |
| 496 | |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 497 | /* Call PyErr_Mac with PyMac_OSErrException */ |
| 498 | PyObject * |
| 499 | PyMac_Error(OSErr err) |
| 500 | { |
| 501 | return PyErr_Mac(PyMac_GetOSErrException(), err); |
| 502 | } |
| 503 | |
Jack Jansen | 1ed9529 | 1996-07-22 15:25:10 +0000 | [diff] [blame] | 504 | #ifdef USE_STACKCHECK |
| 505 | /* Check for stack overflow */ |
| 506 | int |
| 507 | PyOS_CheckStack() |
| 508 | { |
Jack Jansen | 14a9171 | 2000-08-25 21:57:23 +0000 | [diff] [blame] | 509 | char here; |
| 510 | static char *sentinel = 0; |
Jack Jansen | 53bafd9 | 2000-09-08 22:05:48 +0000 | [diff] [blame] | 511 | static PyThreadState *thread_for_sentinel = 0; |
Jack Jansen | 1ed9529 | 1996-07-22 15:25:10 +0000 | [diff] [blame] | 512 | |
Jack Jansen | 340eb88 | 2001-02-02 22:40:28 +0000 | [diff] [blame] | 513 | if ( sentinel == 0 ) { |
| 514 | unsigned long stackspace = StackSpace(); |
| 515 | |
| 516 | #ifdef MAXIMUM_STACK_SIZE |
| 517 | /* See the comment at the definition */ |
| 518 | if ( stackspace > MAXIMUM_STACK_SIZE ) |
| 519 | stackspace = MAXIMUM_STACK_SIZE; |
| 520 | #endif |
| 521 | sentinel = &here - stackspace + MINIMUM_STACK_SIZE; |
Jack Jansen | 14a9171 | 2000-08-25 21:57:23 +0000 | [diff] [blame] | 522 | } |
Jack Jansen | 53bafd9 | 2000-09-08 22:05:48 +0000 | [diff] [blame] | 523 | if ( thread_for_sentinel == 0 ) { |
| 524 | thread_for_sentinel = PyThreadState_Get(); |
| 525 | } |
| 526 | if ( &here < sentinel ) { |
| 527 | if (thread_for_sentinel == PyThreadState_Get()) { |
| 528 | return -1; |
| 529 | #if 0 |
| 530 | } else { |
| 531 | /* Else we are unsure... */ |
| 532 | fprintf(stderr, "Stackcheck in other thread (was %x now %x)\n", thread_for_sentinel,PyThreadState_Get()); |
| 533 | #endif |
| 534 | } |
| 535 | } |
Jack Jansen | 1ed9529 | 1996-07-22 15:25:10 +0000 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | #endif /* USE_STACKCHECK */ |
| 539 | |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 540 | #if !TARGET_API_MAC_OSX |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 541 | /* The catcher routine (which may not be used for all compilers) */ |
| 542 | static RETSIGTYPE |
| 543 | intcatcher(sig) |
| 544 | int sig; |
| 545 | { |
| 546 | interrupted = 1; |
| 547 | signal(SIGINT, intcatcher); |
| 548 | } |
| 549 | |
| 550 | void |
| 551 | PyOS_InitInterrupts() |
| 552 | { |
| 553 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) |
| 554 | signal(SIGINT, intcatcher); |
| 555 | } |
| 556 | |
Jack Jansen | a8441de | 1997-08-08 14:57:37 +0000 | [diff] [blame] | 557 | void |
| 558 | PyOS_FiniInterrupts() |
| 559 | { |
| 560 | } |
| 561 | |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 562 | /* |
| 563 | ** This routine scans the event queue looking for cmd-. |
| 564 | ** This is the only way to get an interrupt under THINK (since it |
| 565 | ** doesn't do SIGINT handling), but is also used under MW, when |
| 566 | ** the full-fledged event loop is disabled. This way, we can at least |
| 567 | ** interrupt a runaway python program. |
| 568 | */ |
| 569 | static void |
| 570 | scan_event_queue(flush) |
| 571 | int flush; |
| 572 | { |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 573 | #if !TARGET_API_MAC_OS8 |
Jack Jansen | d7b6802 | 2001-01-12 23:42:28 +0000 | [diff] [blame] | 574 | if ( CheckEventQueueForUserCancel() ) |
| 575 | interrupted = 1; |
Jack Jansen | bb6d83a | 2000-06-02 21:27:11 +0000 | [diff] [blame] | 576 | #else |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 577 | register EvQElPtr q; |
| 578 | |
Jack Jansen | efaada7 | 1998-02-20 16:03:15 +0000 | [diff] [blame] | 579 | q = (EvQElPtr) LMGetEventQueue()->qHead; |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 580 | |
| 581 | for (; q; q = (EvQElPtr)q->qLink) { |
| 582 | if (q->evtQWhat == keyDown && |
| 583 | (char)q->evtQMessage == '.' && |
| 584 | (q->evtQModifiers & cmdKey) != 0) { |
| 585 | if ( flush ) |
| 586 | FlushEvents(keyDownMask, 0); |
| 587 | interrupted = 1; |
| 588 | break; |
| 589 | } |
| 590 | } |
Jack Jansen | bb6d83a | 2000-06-02 21:27:11 +0000 | [diff] [blame] | 591 | #endif |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | int |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 595 | PyErr_CheckSignals() |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 596 | { |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 597 | if (schedparams.enabled) { |
| 598 | if ( (unsigned long)LMGetTicks() > schedparams.next_check ) { |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 599 | if ( PyMac_Yield() < 0) |
| 600 | return -1; |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 601 | schedparams.next_check = (unsigned long)LMGetTicks() |
| 602 | + schedparams.check_interval; |
| 603 | if (interrupted) { |
Jack Jansen | caa7c46 | 1997-06-12 10:49:13 +0000 | [diff] [blame] | 604 | scan_event_queue(1); /* Eat events up to cmd-. */ |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 605 | interrupted = 0; |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 606 | PyErr_SetNone(PyExc_KeyboardInterrupt); |
| 607 | return -1; |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 608 | } |
| 609 | } |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 610 | } |
| 611 | return 0; |
| 612 | } |
| 613 | |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 614 | int |
| 615 | PyOS_InterruptOccurred() |
| 616 | { |
| 617 | scan_event_queue(1); |
| 618 | return interrupted; |
| 619 | } |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 620 | |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 621 | /* Check whether we are in the foreground */ |
Jack Jansen | 9ae898b | 2000-07-11 21:16:03 +0000 | [diff] [blame] | 622 | static int |
| 623 | PyMac_InForeground(void) |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 624 | { |
| 625 | static ProcessSerialNumber ours; |
| 626 | static inited; |
| 627 | ProcessSerialNumber curfg; |
| 628 | Boolean eq; |
| 629 | |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 630 | if ( inited == 0 ) { |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 631 | (void)GetCurrentProcess(&ours); |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 632 | inited = 1; |
| 633 | } |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 634 | if ( GetFrontProcess(&curfg) < 0 ) |
| 635 | eq = 1; |
| 636 | else if ( SameProcess(&ours, &curfg, &eq) < 0 ) |
| 637 | eq = 1; |
| 638 | return (int)eq; |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 639 | } |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 640 | #endif |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 641 | |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 642 | int |
| 643 | PyMac_SetEventHandler(PyObject *evh) |
| 644 | { |
| 645 | if ( evh && python_event_handler ) { |
| 646 | PyErr_SetString(PyExc_RuntimeError, "Python event handler already set"); |
| 647 | return 0; |
| 648 | } |
| 649 | if ( python_event_handler ) |
| 650 | Py_DECREF(python_event_handler); |
| 651 | if ( evh ) |
| 652 | Py_INCREF(evh); |
| 653 | python_event_handler = evh; |
| 654 | return 1; |
| 655 | } |
| 656 | |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 657 | /* |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 658 | ** Handle an event, either one found in the mainloop eventhandler or |
| 659 | ** one passed back from the python program. |
| 660 | */ |
| 661 | void |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 662 | PyMac_HandleEventIntern(evp) |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 663 | EventRecord *evp; |
| 664 | { |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 665 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 0c96887 | 1997-08-26 13:20:34 +0000 | [diff] [blame] | 666 | if ( evp->what == mouseDown ) { |
| 667 | WindowPtr wp; |
| 668 | |
| 669 | if ( FindWindow(evp->where, &wp) == inSysWindow ) { |
| 670 | SystemClick(evp, wp); |
| 671 | return; |
| 672 | } |
| 673 | } |
Jack Jansen | bb6d83a | 2000-06-02 21:27:11 +0000 | [diff] [blame] | 674 | #endif |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 675 | #ifdef __MWERKS__ |
Jack Jansen | 38e9766 | 1995-11-10 14:53:00 +0000 | [diff] [blame] | 676 | { |
| 677 | int siouxdidit; |
| 678 | |
| 679 | /* If SIOUX wants it we're done */ |
| 680 | siouxdidit = SIOUXHandleOneEvent(evp); |
| 681 | if ( siouxdidit ) |
| 682 | return; |
| 683 | } |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 684 | #else |
Jack Jansen | 0c96887 | 1997-08-26 13:20:34 +0000 | [diff] [blame] | 685 | /* Other compilers are just unlucky... */ |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 686 | #endif /* !__MWERKS__ */ |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /* |
| 690 | ** Handle an event, either through HandleEvent or by passing it to the Python |
| 691 | ** event handler. |
| 692 | */ |
| 693 | int |
| 694 | PyMac_HandleEvent(evp) |
| 695 | EventRecord *evp; |
| 696 | { |
| 697 | PyObject *rv; |
| 698 | |
| 699 | if ( python_event_handler ) { |
| 700 | rv = PyObject_CallFunction(python_event_handler, "(O&)", |
| 701 | PyMac_BuildEventRecord, evp); |
| 702 | if ( rv ) |
| 703 | Py_DECREF(rv); |
| 704 | else |
| 705 | return -1; /* Propagate exception */ |
| 706 | } else { |
| 707 | PyMac_HandleEventIntern(evp); |
| 708 | } |
| 709 | return 0; |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 712 | #if !TARGET_API_MAC_OSX |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 713 | /* |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 714 | ** Yield the CPU to other tasks without processing events. |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 715 | */ |
Jack Jansen | 2d1306b | 2000-04-07 09:10:49 +0000 | [diff] [blame] | 716 | int |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 717 | PyMac_DoYield(int maxsleep, int maycallpython) |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 718 | { |
| 719 | EventRecord ev; |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 720 | int gotone; |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 721 | long latest_time_ready; |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 722 | static int in_here = 0; |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 723 | |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 724 | in_here++; |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 725 | /* |
| 726 | ** First check for interrupts, if wanted. |
| 727 | ** This sets a flag that will be picked up at an appropriate |
| 728 | ** moment in the mainloop. |
| 729 | */ |
| 730 | if (schedparams.check_interrupt) |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 731 | scan_event_queue(0); |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 732 | |
| 733 | /* XXXX Implementing an idle routine goes here */ |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 734 | |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 735 | /* |
| 736 | ** Check which of the eventloop cases we have: |
| 737 | ** - process events |
| 738 | ** - don't process events but do yield |
| 739 | ** - do neither |
| 740 | */ |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 741 | if( in_here > 1 || !schedparams.process_events || |
| 742 | (python_event_handler && !maycallpython) ) { |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 743 | if ( maxsleep >= 0 ) { |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 744 | #if TARGET_API_MAC_OS8 |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 745 | SystemTask(); |
Jack Jansen | 15f1c08 | 2001-04-25 22:07:27 +0000 | [diff] [blame] | 746 | #else |
| 747 | int xxx = 0; |
Jack Jansen | bb6d83a | 2000-06-02 21:27:11 +0000 | [diff] [blame] | 748 | #endif |
Jack Jansen | 15f1c08 | 2001-04-25 22:07:27 +0000 | [diff] [blame] | 749 | } |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 750 | } else { |
| 751 | latest_time_ready = LMGetTicks() + maxsleep; |
Jack Jansen | 2d1306b | 2000-04-07 09:10:49 +0000 | [diff] [blame] | 752 | do { |
Jack Jansen | 0c96887 | 1997-08-26 13:20:34 +0000 | [diff] [blame] | 753 | /* XXXX Hack by Jack. |
| 754 | ** In time.sleep() you can click to another application |
| 755 | ** once only. If you come back to Python you cannot get away |
| 756 | ** again. |
| 757 | **/ |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 758 | gotone = WaitNextEvent(schedparams.process_events, &ev, maxsleep, NULL); |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 759 | /* Get out quickly if nothing interesting is happening */ |
| 760 | if ( !gotone || ev.what == nullEvent ) |
| 761 | break; |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 762 | if ( PyMac_HandleEvent(&ev) < 0 ) { |
| 763 | in_here--; |
| 764 | return -1; |
| 765 | } |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 766 | maxsleep = latest_time_ready - LMGetTicks(); |
Jack Jansen | 2d1306b | 2000-04-07 09:10:49 +0000 | [diff] [blame] | 767 | } while ( maxsleep > 0 ); |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 768 | } |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 769 | in_here--; |
| 770 | return 0; |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | /* |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 774 | ** Process events and/or yield the CPU to other tasks if opportune |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 775 | */ |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 776 | int |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 777 | PyMac_Yield() { |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 778 | unsigned long maxsleep; |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 779 | |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 780 | if( PyMac_InForeground() ) |
| 781 | maxsleep = 0; |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 782 | else |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 783 | maxsleep = schedparams.bg_yield; |
| 784 | |
Jack Jansen | 36ed506 | 1997-06-20 16:18:15 +0000 | [diff] [blame] | 785 | return PyMac_DoYield(maxsleep, 1); |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | /* |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 789 | ** Return current scheduler parameters |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 790 | */ |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 791 | void |
| 792 | PyMac_GetSchedParams(PyMacSchedParams *sp) |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 793 | { |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 794 | sp->check_interrupt = schedparams.check_interrupt; |
| 795 | sp->process_events = schedparams.process_events; |
| 796 | sp->besocial = schedparams.besocial; |
| 797 | sp->check_interval = schedparams.check_interval / 60.0; |
| 798 | sp->bg_yield = schedparams.bg_yield / 60.0; |
Jack Jansen | f93c72a | 1994-12-14 14:07:50 +0000 | [diff] [blame] | 799 | } |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame] | 800 | |
Jack Jansen | 74162f3 | 1995-02-15 22:58:33 +0000 | [diff] [blame] | 801 | /* |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 802 | ** Set current scheduler parameters |
| 803 | */ |
| 804 | void |
| 805 | PyMac_SetSchedParams(PyMacSchedParams *sp) |
| 806 | { |
| 807 | schedparams.check_interrupt = sp->check_interrupt; |
| 808 | schedparams.process_events = sp->process_events; |
| 809 | schedparams.besocial = sp->besocial; |
| 810 | schedparams.check_interval = (unsigned long)(sp->check_interval*60); |
| 811 | schedparams.bg_yield = (unsigned long)(sp->bg_yield*60); |
| 812 | if ( schedparams.check_interrupt || schedparams.process_events || |
| 813 | schedparams.besocial ) |
| 814 | schedparams.enabled = 1; |
| 815 | else |
| 816 | schedparams.enabled = 0; |
| 817 | schedparams.next_check = 0; /* Check immedeately */ |
| 818 | } |
Jack Jansen | caa7c46 | 1997-06-12 10:49:13 +0000 | [diff] [blame] | 819 | |
Jack Jansen | e3ae0df | 1997-06-03 15:28:29 +0000 | [diff] [blame] | 820 | /* |
Jack Jansen | 3469e99 | 1996-09-06 00:30:45 +0000 | [diff] [blame] | 821 | ** Install our menu bar. |
| 822 | */ |
| 823 | void |
| 824 | PyMac_InitMenuBar() |
| 825 | { |
Jack Jansen | 3469e99 | 1996-09-06 00:30:45 +0000 | [diff] [blame] | 826 | MenuHandle applemenu; |
| 827 | |
Jack Jansen | 15f1c08 | 2001-04-25 22:07:27 +0000 | [diff] [blame] | 828 | if ( sioux_mbar ) return; |
Jack Jansen | caa7c46 | 1997-06-12 10:49:13 +0000 | [diff] [blame] | 829 | if ( (sioux_mbar=GetMenuBar()) == NULL ) { |
| 830 | /* Sioux menu not installed yet. Do so */ |
| 831 | SIOUXSetupMenus(); |
| 832 | if ( (sioux_mbar=GetMenuBar()) == NULL ) |
| 833 | return; |
| 834 | } |
Jack Jansen | 08c3be3 | 1997-04-08 15:27:00 +0000 | [diff] [blame] | 835 | if ( (applemenu=GetMenuHandle(SIOUX_APPLEID)) == NULL ) return; |
Jack Jansen | 3469e99 | 1996-09-06 00:30:45 +0000 | [diff] [blame] | 836 | SetMenuItemText(applemenu, 1, "\pAbout Python..."); |
| 837 | } |
| 838 | |
| 839 | /* |
Jack Jansen | caa7c46 | 1997-06-12 10:49:13 +0000 | [diff] [blame] | 840 | ** Restore sioux menu bar |
| 841 | */ |
| 842 | void |
| 843 | PyMac_RestoreMenuBar() |
| 844 | { |
Jack Jansen | 15f1c08 | 2001-04-25 22:07:27 +0000 | [diff] [blame] | 845 | #if 1 |
Jack Jansen | 657ba27 | 2001-02-17 22:02:07 +0000 | [diff] [blame] | 846 | /* This doesn't seem to work anymore? Or only for Carbon? */ |
| 847 | MenuBarHandle curmenubar; |
| 848 | |
| 849 | curmenubar = GetMenuBar(); |
Jack Jansen | eda7863 | 1997-06-12 15:29:46 +0000 | [diff] [blame] | 850 | if ( sioux_mbar ) { |
Jack Jansen | caa7c46 | 1997-06-12 10:49:13 +0000 | [diff] [blame] | 851 | SetMenuBar(sioux_mbar); |
Jack Jansen | eda7863 | 1997-06-12 15:29:46 +0000 | [diff] [blame] | 852 | DrawMenuBar(); |
Jack Jansen | 657ba27 | 2001-02-17 22:02:07 +0000 | [diff] [blame] | 853 | } else { |
Jack Jansen | efaada7 | 1998-02-20 16:03:15 +0000 | [diff] [blame] | 854 | PyMac_InitMenuBar(); |
Jack Jansen | 657ba27 | 2001-02-17 22:02:07 +0000 | [diff] [blame] | 855 | DrawMenuBar(); |
| 856 | } |
| 857 | #endif |
Jack Jansen | caa7c46 | 1997-06-12 10:49:13 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Jack Jansen | 15f1c08 | 2001-04-25 22:07:27 +0000 | [diff] [blame] | 860 | void |
| 861 | PyMac_RaiseConsoleWindow() |
| 862 | { |
| 863 | /* Note: this is a hack. SIOUXTextWindow is SIOUX's internal structure |
| 864 | ** and we happen to know that the first entry is the window pointer. |
| 865 | */ |
| 866 | extern WindowRef *SIOUXTextWindow; |
| 867 | |
| 868 | if ( SIOUXTextWindow == NULL || *SIOUXTextWindow == NULL ) |
| 869 | return; |
| 870 | if ( FrontWindow() != *SIOUXTextWindow ) |
| 871 | BringToFront(*SIOUXTextWindow); |
| 872 | } |
Jack Jansen | caa7c46 | 1997-06-12 10:49:13 +0000 | [diff] [blame] | 873 | |
| 874 | /* |
Jack Jansen | 3469e99 | 1996-09-06 00:30:45 +0000 | [diff] [blame] | 875 | ** Our replacement about box |
| 876 | */ |
Jack Jansen | 7e1fb7c | 1998-07-31 09:36:30 +0000 | [diff] [blame] | 877 | |
| 878 | #include "patchlevel.h" |
| 879 | |
Jack Jansen | 3469e99 | 1996-09-06 00:30:45 +0000 | [diff] [blame] | 880 | void |
| 881 | SIOUXDoAboutBox(void) |
| 882 | { |
| 883 | DialogPtr theDialog; |
Jack Jansen | 7e1fb7c | 1998-07-31 09:36:30 +0000 | [diff] [blame] | 884 | WindowPtr theWindow; |
Jack Jansen | 3469e99 | 1996-09-06 00:30:45 +0000 | [diff] [blame] | 885 | short item; |
Jack Jansen | 7e1fb7c | 1998-07-31 09:36:30 +0000 | [diff] [blame] | 886 | short fontID; |
Jack Jansen | 3469e99 | 1996-09-06 00:30:45 +0000 | [diff] [blame] | 887 | |
| 888 | if( (theDialog = GetNewDialog(ABOUT_ID, NULL, (WindowPtr)-1)) == NULL ) |
| 889 | return; |
Jack Jansen | d617c57 | 1996-09-22 22:14:30 +0000 | [diff] [blame] | 890 | theWindow = GetDialogWindow(theDialog); |
Jack Jansen | 7e1fb7c | 1998-07-31 09:36:30 +0000 | [diff] [blame] | 891 | SetPortWindowPort(theWindow); |
| 892 | GetFNum("\pPython-Sans", &fontID); |
| 893 | if (fontID == 0) |
| 894 | fontID = kFontIDGeneva; |
| 895 | TextFont(fontID); |
| 896 | TextSize(9); |
| 897 | ParamText(Pstring(PATCHLEVEL), "\p", "\p", "\p"); |
Jack Jansen | d617c57 | 1996-09-22 22:14:30 +0000 | [diff] [blame] | 898 | ShowWindow(theWindow); |
Jack Jansen | 3469e99 | 1996-09-06 00:30:45 +0000 | [diff] [blame] | 899 | ModalDialog(NULL, &item); |
| 900 | DisposeDialog(theDialog); |
| 901 | } |
| 902 | |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 903 | #endif /* !TARGET_API_MAC_OSX */ |
Jack Jansen | eda7863 | 1997-06-12 15:29:46 +0000 | [diff] [blame] | 904 | |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 905 | #if TARGET_API_MAC_OS8 |
Jack Jansen | eda7863 | 1997-06-12 15:29:46 +0000 | [diff] [blame] | 906 | /* |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 907 | ** Helper routine for GetDirectory |
| 908 | */ |
Guido van Rossum | 24a45e3 | 1995-02-20 23:45:53 +0000 | [diff] [blame] | 909 | static pascal short |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 910 | myhook_proc(short item, DialogPtr theDialog, struct hook_args *dataptr) |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 911 | { |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 912 | if ( item == sfHookFirstCall && dataptr->prompt) { |
| 913 | Handle prompth; |
| 914 | short type; |
| 915 | Rect rect; |
| 916 | |
| 917 | GetDialogItem(theDialog, PROMPT_ITEM, &type, &prompth, &rect); |
| 918 | if ( prompth ) |
| 919 | SetDialogItemText(prompth, (unsigned char *)dataptr->prompt); |
| 920 | } else |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 921 | if ( item == SELECTCUR_ITEM ) { |
| 922 | item = sfItemCancelButton; |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 923 | dataptr->selectcur_hit = 1; |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 924 | } |
| 925 | return item; |
| 926 | } |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 927 | |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 928 | /* |
| 929 | ** Ask the user for a directory. I still can't understand |
| 930 | ** why Apple doesn't provide a standard solution for this... |
| 931 | */ |
| 932 | int |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 933 | PyMac_GetDirectory(dirfss, prompt) |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 934 | FSSpec *dirfss; |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 935 | char *prompt; |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 936 | { |
| 937 | static SFTypeList list = {'fldr', 0, 0, 0}; |
| 938 | static Point where = {-1, -1}; |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 939 | StandardFileReply reply; |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 940 | struct hook_args hook_args; |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 941 | |
| 942 | if ( !upp_inited ) { |
| 943 | myhook_upp = NewDlgHookYDProc(myhook_proc); |
| 944 | upp_inited = 1; |
| 945 | } |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 946 | if ( prompt && *prompt ) |
| 947 | hook_args.prompt = (char *)Pstring(prompt); |
| 948 | else |
| 949 | hook_args.prompt = NULL; |
| 950 | hook_args.selectcur_hit = 0; |
Guido van Rossum | 24a45e3 | 1995-02-20 23:45:53 +0000 | [diff] [blame] | 951 | CustomGetFile((FileFilterYDUPP)0, 1, list, &reply, GETDIR_ID, where, myhook_upp, |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 952 | NULL, NULL, NULL, (void *)&hook_args); |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 953 | |
| 954 | reply.sfFile.name[0] = 0; |
| 955 | if( FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, dirfss) ) |
| 956 | return 0; |
Jack Jansen | 819f177 | 1995-08-14 12:35:10 +0000 | [diff] [blame] | 957 | return hook_args.selectcur_hit; |
| 958 | } |
| 959 | |
| 960 | /* |
| 961 | ** Slightly extended StandardGetFile: accepts a prompt */ |
| 962 | void PyMac_PromptGetFile(short numTypes, ConstSFTypeListPtr typeList, |
| 963 | StandardFileReply *reply, char *prompt) |
| 964 | { |
| 965 | static Point where = {-1, -1}; |
| 966 | struct hook_args hook_args; |
| 967 | |
| 968 | if ( !upp_inited ) { |
| 969 | myhook_upp = NewDlgHookYDProc(myhook_proc); |
| 970 | upp_inited = 1; |
| 971 | } |
| 972 | if ( prompt && *prompt ) |
| 973 | hook_args.prompt = (char *)Pstring(prompt); |
| 974 | else |
| 975 | hook_args.prompt = NULL; |
| 976 | hook_args.selectcur_hit = 0; |
| 977 | CustomGetFile((FileFilterYDUPP)0, numTypes, typeList, reply, GETFILEPROMPT_ID, where, |
| 978 | myhook_upp, NULL, NULL, NULL, (void *)&hook_args); |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 979 | } |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 980 | #endif /* TARGET_API_MAC_OS8 */ |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 981 | |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 982 | /* Convert a 4-char string object argument to an OSType value */ |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 983 | int |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 984 | PyMac_GetOSType(PyObject *v, OSType *pr) |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 985 | { |
| 986 | if (!PyString_Check(v) || PyString_Size(v) != 4) { |
| 987 | PyErr_SetString(PyExc_TypeError, |
| 988 | "OSType arg must be string of 4 chars"); |
| 989 | return 0; |
| 990 | } |
| 991 | memcpy((char *)pr, PyString_AsString(v), 4); |
| 992 | return 1; |
| 993 | } |
| 994 | |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 995 | /* Convert an OSType value to a 4-char string object */ |
| 996 | PyObject * |
| 997 | PyMac_BuildOSType(OSType t) |
| 998 | { |
| 999 | return PyString_FromStringAndSize((char *)&t, 4); |
| 1000 | } |
| 1001 | |
Jack Jansen | d1f0631 | 1996-08-01 15:23:54 +0000 | [diff] [blame] | 1002 | /* Convert an NumVersion value to a 4-element tuple */ |
| 1003 | PyObject * |
| 1004 | PyMac_BuildNumVersion(NumVersion t) |
| 1005 | { |
| 1006 | return Py_BuildValue("(hhhh)", t.majorRev, t.minorAndBugRev, t.stage, t.nonRelRev); |
| 1007 | } |
| 1008 | |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1009 | |
| 1010 | /* Convert a Python string object to a Str255 */ |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1011 | int |
Guido van Rossum | 8f69179 | 1995-01-18 23:57:26 +0000 | [diff] [blame] | 1012 | PyMac_GetStr255(PyObject *v, Str255 pbuf) |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1013 | { |
| 1014 | int len; |
| 1015 | if (!PyString_Check(v) || (len = PyString_Size(v)) > 255) { |
| 1016 | PyErr_SetString(PyExc_TypeError, |
| 1017 | "Str255 arg must be string of at most 255 chars"); |
| 1018 | return 0; |
| 1019 | } |
| 1020 | pbuf[0] = len; |
| 1021 | memcpy((char *)(pbuf+1), PyString_AsString(v), len); |
| 1022 | return 1; |
| 1023 | } |
| 1024 | |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1025 | /* Convert a Str255 to a Python string object */ |
| 1026 | PyObject * |
| 1027 | PyMac_BuildStr255(Str255 s) |
| 1028 | { |
Jack Jansen | b734ade | 1999-12-17 17:15:50 +0000 | [diff] [blame] | 1029 | if ( s == NULL ) { |
| 1030 | PyErr_SetString(PyExc_SystemError, "Str255 pointer is NULL"); |
| 1031 | return NULL; |
| 1032 | } |
| 1033 | return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); |
| 1034 | } |
| 1035 | |
| 1036 | PyObject * |
| 1037 | PyMac_BuildOptStr255(Str255 s) |
| 1038 | { |
| 1039 | if ( s == NULL ) { |
| 1040 | Py_INCREF(Py_None); |
| 1041 | return Py_None; |
| 1042 | } |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1043 | return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); |
| 1044 | } |
| 1045 | |
| 1046 | |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1047 | /* |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1048 | ** Convert a Python object to an FSSpec. |
| 1049 | ** The object may either be a full pathname or a triple |
| 1050 | ** (vrefnum, dirid, path). |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1051 | ** NOTE: This routine will fail on pre-sys7 machines. |
| 1052 | ** The caller is responsible for not calling this routine |
| 1053 | ** in those cases (which is fine, since everyone calling |
| 1054 | ** this is probably sys7 dependent anyway). |
| 1055 | */ |
| 1056 | int |
Guido van Rossum | 8f69179 | 1995-01-18 23:57:26 +0000 | [diff] [blame] | 1057 | PyMac_GetFSSpec(PyObject *v, FSSpec *fs) |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1058 | { |
| 1059 | Str255 path; |
| 1060 | short refnum; |
| 1061 | long parid; |
| 1062 | OSErr err; |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 1063 | FSSpec *fs2; |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1064 | |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 1065 | #if !TARGET_API_MAC_OSX |
| 1066 | /* XXX This #if is temporary */ |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 1067 | /* first check whether it already is an FSSpec */ |
| 1068 | fs2 = mfs_GetFSSpecFSSpec(v); |
| 1069 | if ( fs2 ) { |
Jack Jansen | 3ec804a | 1995-02-20 15:56:10 +0000 | [diff] [blame] | 1070 | (void)FSMakeFSSpec(fs2->vRefNum, fs2->parID, fs2->name, fs); |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 1071 | return 1; |
| 1072 | } |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 1073 | #endif |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1074 | if ( PyString_Check(v) ) { |
| 1075 | /* It's a pathname */ |
Guido van Rossum | 9aa3d13 | 1995-01-21 13:46:04 +0000 | [diff] [blame] | 1076 | if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) ) |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1077 | return 0; |
Jack Jansen | 378815c | 1996-03-06 16:21:34 +0000 | [diff] [blame] | 1078 | refnum = 0; /* XXXX Should get CurWD here?? */ |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1079 | parid = 0; |
| 1080 | } else { |
Guido van Rossum | 9aa3d13 | 1995-01-21 13:46:04 +0000 | [diff] [blame] | 1081 | if( !PyArg_Parse(v, "(hlO&); FSSpec should be fullpath or (vrefnum,dirid,path)", |
| 1082 | &refnum, &parid, PyMac_GetStr255, &path)) { |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1083 | return 0; |
Guido van Rossum | 9aa3d13 | 1995-01-21 13:46:04 +0000 | [diff] [blame] | 1084 | } |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1085 | } |
| 1086 | err = FSMakeFSSpec(refnum, parid, path, fs); |
| 1087 | if ( err && err != fnfErr ) { |
Jack Jansen | 3d75754 | 2000-01-24 09:56:06 +0000 | [diff] [blame] | 1088 | PyMac_Error(err); |
Jack Jansen | 5f65309 | 1995-01-18 13:53:49 +0000 | [diff] [blame] | 1089 | return 0; |
| 1090 | } |
| 1091 | return 1; |
| 1092 | } |
| 1093 | |
Jack Jansen | 8bb573e | 1999-12-12 21:37:14 +0000 | [diff] [blame] | 1094 | /* Convert FSSpec to PyObject */ |
| 1095 | PyObject *PyMac_BuildFSSpec(FSSpec *v) |
| 1096 | { |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 1097 | #if TARGET_API_MAC_OSX |
| 1098 | PyErr_SetString(PyExc_NotImplementedError, "FSSpec not yet done for OSX"); |
| 1099 | return NULL; |
| 1100 | #else |
Jack Jansen | 8bb573e | 1999-12-12 21:37:14 +0000 | [diff] [blame] | 1101 | return newmfssobject(v); |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 1102 | #endif |
Jack Jansen | 8bb573e | 1999-12-12 21:37:14 +0000 | [diff] [blame] | 1103 | } |
Guido van Rossum | 8f69179 | 1995-01-18 23:57:26 +0000 | [diff] [blame] | 1104 | |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1105 | /* Convert a Python object to a Rect. |
Guido van Rossum | 5279ec6 | 1995-01-26 22:56:59 +0000 | [diff] [blame] | 1106 | The object must be a (left, top, right, bottom) tuple. |
| 1107 | (This differs from the order in the struct but is consistent with |
| 1108 | the arguments to SetRect(), and also with STDWIN). */ |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1109 | int |
| 1110 | PyMac_GetRect(PyObject *v, Rect *r) |
Guido van Rossum | 8f69179 | 1995-01-18 23:57:26 +0000 | [diff] [blame] | 1111 | { |
Guido van Rossum | 5279ec6 | 1995-01-26 22:56:59 +0000 | [diff] [blame] | 1112 | return PyArg_Parse(v, "(hhhh)", &r->left, &r->top, &r->right, &r->bottom); |
Guido van Rossum | 8f69179 | 1995-01-18 23:57:26 +0000 | [diff] [blame] | 1113 | } |
Guido van Rossum | b340466 | 1995-01-22 18:36:13 +0000 | [diff] [blame] | 1114 | |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1115 | /* Convert a Rect to a Python object */ |
Guido van Rossum | b340466 | 1995-01-22 18:36:13 +0000 | [diff] [blame] | 1116 | PyObject * |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1117 | PyMac_BuildRect(Rect *r) |
Guido van Rossum | b340466 | 1995-01-22 18:36:13 +0000 | [diff] [blame] | 1118 | { |
Guido van Rossum | 5279ec6 | 1995-01-26 22:56:59 +0000 | [diff] [blame] | 1119 | return Py_BuildValue("(hhhh)", r->left, r->top, r->right, r->bottom); |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | |
| 1123 | /* Convert a Python object to a Point. |
Guido van Rossum | 5279ec6 | 1995-01-26 22:56:59 +0000 | [diff] [blame] | 1124 | The object must be a (h, v) tuple. |
| 1125 | (This differs from the order in the struct but is consistent with |
| 1126 | the arguments to SetPoint(), and also with STDWIN). */ |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1127 | int |
| 1128 | PyMac_GetPoint(PyObject *v, Point *p) |
| 1129 | { |
Guido van Rossum | 5279ec6 | 1995-01-26 22:56:59 +0000 | [diff] [blame] | 1130 | return PyArg_Parse(v, "(hh)", &p->h, &p->v); |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | /* Convert a Point to a Python object */ |
| 1134 | PyObject * |
| 1135 | PyMac_BuildPoint(Point p) |
| 1136 | { |
Guido van Rossum | 5279ec6 | 1995-01-26 22:56:59 +0000 | [diff] [blame] | 1137 | return Py_BuildValue("(hh)", p.h, p.v); |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | |
| 1141 | /* Convert a Python object to an EventRecord. |
| 1142 | The object must be a (what, message, when, (v, h), modifiers) tuple. */ |
| 1143 | int |
| 1144 | PyMac_GetEventRecord(PyObject *v, EventRecord *e) |
| 1145 | { |
| 1146 | return PyArg_Parse(v, "(hll(hh)h)", |
| 1147 | &e->what, |
| 1148 | &e->message, |
| 1149 | &e->when, |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1150 | &e->where.h, |
Guido van Rossum | 5279ec6 | 1995-01-26 22:56:59 +0000 | [diff] [blame] | 1151 | &e->where.v, |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1152 | &e->modifiers); |
| 1153 | } |
| 1154 | |
| 1155 | /* Convert a Rect to an EventRecord object */ |
| 1156 | PyObject * |
| 1157 | PyMac_BuildEventRecord(EventRecord *e) |
| 1158 | { |
| 1159 | return Py_BuildValue("(hll(hh)h)", |
| 1160 | e->what, |
| 1161 | e->message, |
| 1162 | e->when, |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1163 | e->where.h, |
Guido van Rossum | 5279ec6 | 1995-01-26 22:56:59 +0000 | [diff] [blame] | 1164 | e->where.v, |
Guido van Rossum | cf27c2d | 1995-01-25 23:06:44 +0000 | [diff] [blame] | 1165 | e->modifiers); |
Guido van Rossum | b340466 | 1995-01-22 18:36:13 +0000 | [diff] [blame] | 1166 | } |
Jack Jansen | fa4d5d0 | 1995-11-15 15:19:29 +0000 | [diff] [blame] | 1167 | |
| 1168 | /* Convert Python object to Fixed */ |
| 1169 | int |
| 1170 | PyMac_GetFixed(PyObject *v, Fixed *f) |
| 1171 | { |
| 1172 | double d; |
| 1173 | |
| 1174 | if( !PyArg_Parse(v, "d", &d)) |
| 1175 | return 0; |
| 1176 | *f = (Fixed)(d * 0x10000); |
Jack Jansen | 31dd5c0 | 1996-05-31 13:01:39 +0000 | [diff] [blame] | 1177 | return 1; |
Jack Jansen | fa4d5d0 | 1995-11-15 15:19:29 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | /* Convert a Point to a Python object */ |
| 1181 | PyObject * |
| 1182 | PyMac_BuildFixed(Fixed f) |
| 1183 | { |
| 1184 | double d; |
| 1185 | |
| 1186 | d = f; |
| 1187 | d = d / 0x10000; |
| 1188 | return Py_BuildValue("d", d); |
| 1189 | } |
| 1190 | |
Jack Jansen | d58cd63 | 1998-04-21 15:24:39 +0000 | [diff] [blame] | 1191 | /* Convert wide to/from Python int or (hi, lo) tuple. XXXX Should use Python longs */ |
| 1192 | int |
| 1193 | PyMac_Getwide(PyObject *v, wide *rv) |
| 1194 | { |
| 1195 | if (PyInt_Check(v)) { |
| 1196 | rv->hi = 0; |
| 1197 | rv->lo = PyInt_AsLong(v); |
| 1198 | if( rv->lo & 0x80000000 ) |
| 1199 | rv->hi = -1; |
| 1200 | return 1; |
| 1201 | } |
| 1202 | return PyArg_Parse(v, "(ll)", &rv->hi, &rv->lo); |
| 1203 | } |
| 1204 | |
| 1205 | |
| 1206 | PyObject * |
Jack Jansen | bbf4be2 | 1998-04-23 13:20:17 +0000 | [diff] [blame] | 1207 | PyMac_Buildwide(wide *w) |
Jack Jansen | d58cd63 | 1998-04-21 15:24:39 +0000 | [diff] [blame] | 1208 | { |
Jack Jansen | bbf4be2 | 1998-04-23 13:20:17 +0000 | [diff] [blame] | 1209 | if ( (w->hi == 0 && (w->lo & 0x80000000) == 0) || |
| 1210 | (w->hi == -1 && (w->lo & 0x80000000) ) ) |
| 1211 | return PyInt_FromLong(w->lo); |
| 1212 | return Py_BuildValue("(ll)", w->hi, w->lo); |
Jack Jansen | d58cd63 | 1998-04-21 15:24:39 +0000 | [diff] [blame] | 1213 | } |
Jack Jansen | 8bb1dc1 | 2001-05-19 12:31:09 +0000 | [diff] [blame] | 1214 | |
| 1215 | #ifdef USE_TOOLBOX_OBJECT_GLUE |
| 1216 | /* |
| 1217 | ** Glue together the toolbox objects. |
| 1218 | ** |
| 1219 | ** Because toolbox modules interdepend on each other, they use each others |
| 1220 | ** object types, on MacOSX/MachO this leads to the situation that they |
| 1221 | ** cannot be dynamically loaded (or they would all have to be lumped into |
| 1222 | ** a single .so, but this would be bad for extensibility). |
| 1223 | ** |
| 1224 | ** This file defines wrappers for all the _New and _Convert functions, |
| 1225 | ** which are the Py_BuildValue and PyArg_ParseTuple helpers. The wrappers |
| 1226 | ** check an indirection function pointer, and if it isn't filled in yet |
| 1227 | ** they import the appropriate module, whose init routine should fill in |
| 1228 | ** the pointer. |
| 1229 | */ |
| 1230 | |
| 1231 | #define GLUE_NEW(object, routinename, module) \ |
| 1232 | PyObject *(*PyMacGluePtr_##routinename)(object); \ |
| 1233 | \ |
| 1234 | PyObject *routinename(object cobj) { \ |
| 1235 | if (!PyMacGluePtr_##routinename) { \ |
| 1236 | if (!PyImport_ImportModule(module)) return NULL; \ |
| 1237 | if (!PyMacGluePtr_##routinename) { \ |
| 1238 | PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ |
| 1239 | return NULL; \ |
| 1240 | } \ |
| 1241 | } \ |
| 1242 | return (*PyMacGluePtr_##routinename)(cobj); \ |
| 1243 | } |
| 1244 | |
| 1245 | #define GLUE_CONVERT(object, routinename, module) \ |
| 1246 | int (*PyMacGluePtr_##routinename)(PyObject *, object *); \ |
| 1247 | \ |
| 1248 | int routinename(PyObject *pyobj, object *cobj) { \ |
| 1249 | if (!PyMacGluePtr_##routinename) { \ |
| 1250 | if (!PyImport_ImportModule(module)) return NULL; \ |
| 1251 | if (!PyMacGluePtr_##routinename) { \ |
| 1252 | PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ |
| 1253 | return NULL; \ |
| 1254 | } \ |
| 1255 | } \ |
| 1256 | return (*PyMacGluePtr_##routinename)(pyobj, cobj); \ |
| 1257 | } |
| 1258 | |
| 1259 | GLUE_NEW(AppleEvent *, AEDesc_New, "AE") /* XXXX Why by address? */ |
| 1260 | GLUE_CONVERT(AppleEvent, AEDesc_Convert, "AE") |
| 1261 | |
| 1262 | GLUE_NEW(Component, CmpObj_New, "Cm") |
| 1263 | GLUE_CONVERT(Component, CmpObj_Convert, "Cm") |
| 1264 | GLUE_NEW(ComponentInstance, CmpInstObj_New, "Cm") |
| 1265 | GLUE_CONVERT(ComponentInstance, CmpInstObj_Convert, "Cm") |
| 1266 | |
| 1267 | GLUE_NEW(ControlHandle, CtlObj_New, "Ctl") |
| 1268 | GLUE_CONVERT(ControlHandle, CtlObj_Convert, "Ctl") |
| 1269 | |
| 1270 | GLUE_NEW(DialogPtr, DlgObj_New, "Dlg") |
| 1271 | GLUE_CONVERT(DialogPtr, DlgObj_Convert, "Dlg") |
| 1272 | GLUE_NEW(DialogPtr, DlgObj_WhichDialog, "Dlg") |
| 1273 | |
| 1274 | GLUE_NEW(DragReference, DragObj_New, "Drag") |
| 1275 | GLUE_CONVERT(DragReference, DragObj_Convert, "Drag") |
| 1276 | |
| 1277 | GLUE_NEW(ListHandle, ListObj_New, "List") |
| 1278 | GLUE_CONVERT(ListHandle, ListObj_Convert, "List") |
| 1279 | |
| 1280 | GLUE_NEW(MenuHandle, MenuObj_New, "Menu") |
| 1281 | GLUE_CONVERT(MenuHandle, MenuObj_Convert, "Menu") |
| 1282 | |
| 1283 | GLUE_NEW(GrafPtr, GrafObj_New, "Qd") |
| 1284 | GLUE_CONVERT(GrafPtr, GrafObj_Convert, "Qd") |
| 1285 | GLUE_NEW(BitMapPtr, BMObj_New, "Qd") |
| 1286 | GLUE_CONVERT(BitMapPtr, BMObj_Convert, "Qd") |
| 1287 | GLUE_NEW(RGBColor *, QdRGB_New, "Qd") /* XXXX Why? */ |
| 1288 | GLUE_CONVERT(RGBColor, QdRGB_Convert, "Qd") |
| 1289 | |
| 1290 | GLUE_NEW(GWorldPtr, GWorldObj_New, "Qdoffs") |
| 1291 | GLUE_CONVERT(GWorldPtr, GWorldObj_Convert, "Qdoffs") |
| 1292 | |
| 1293 | GLUE_NEW(Track, TrackObj_New, "Qt") |
| 1294 | GLUE_CONVERT(Track, TrackObj_Convert, "Qt") |
| 1295 | GLUE_NEW(Movie, MovieObj_New, "Qt") |
| 1296 | GLUE_CONVERT(Movie, MovieObj_Convert, "Qt") |
| 1297 | GLUE_NEW(MovieController, MovieCtlObj_New, "Qt") |
| 1298 | GLUE_CONVERT(MovieController, MovieCtlObj_Convert, "Qt") |
| 1299 | GLUE_NEW(TimeBase, TimeBaseObj_New, "Qt") |
| 1300 | GLUE_CONVERT(TimeBase, TimeBaseObj_Convert, "Qt") |
| 1301 | GLUE_NEW(UserData, UserDataObj_New, "Qt") |
| 1302 | GLUE_CONVERT(UserData, UserDataObj_Convert, "Qt") |
| 1303 | GLUE_NEW(Media, MediaObj_New, "Qt") |
| 1304 | GLUE_CONVERT(Media, MediaObj_Convert, "Qt") |
| 1305 | |
| 1306 | GLUE_NEW(Handle, ResObj_New, "Res") |
| 1307 | GLUE_CONVERT(Handle, ResObj_Convert, "Res") |
| 1308 | GLUE_NEW(Handle, OptResObj_New, "Res") |
| 1309 | GLUE_CONVERT(Handle, OptResObj_Convert, "Res") |
| 1310 | |
| 1311 | GLUE_NEW(TEHandle, TEObj_New, "TE") |
| 1312 | GLUE_CONVERT(TEHandle, TEObj_Convert, "TE") |
| 1313 | |
| 1314 | GLUE_NEW(WindowPtr, WinObj_New, "Win") |
| 1315 | GLUE_CONVERT(WindowPtr, WinObj_Convert, "Win") |
| 1316 | GLUE_NEW(WindowPtr, WinObj_WhichWindow, "Win") |
| 1317 | |
| 1318 | #endif /* USE_TOOLBOX_OBJECT_GLUE */ |