Updated for hfsplus module, new gusi libs.
[python/dscho.git] / Mac / Python / macglue.c
blobe66ab837e5110e1837316b38724f39141993c116
1 /***********************************************************
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
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.
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.
23 ******************************************************************/
26 #include "Python.h"
28 #include "macglue.h"
29 #include "marshal.h"
30 #include "import.h"
31 #include "importdl.h"
32 #include "pymactoolbox.h"
34 #include "pythonresources.h"
36 #ifdef WITHOUT_FRAMEWORKS
37 #include <OSUtils.h> /* for Set(Current)A5 */
38 #include <Files.h>
39 #include <StandardFile.h>
40 #include <Resources.h>
41 #include <Memory.h>
42 #include <Windows.h>
43 #include <Traps.h>
44 #include <Processes.h>
45 #include <Fonts.h>
46 #include <Menus.h>
47 #include <TextUtils.h>
48 #include <LowMem.h>
49 #include <Events.h>
50 #else
51 #include <Carbon/Carbon.h>
52 #endif
54 #if !TARGET_API_MAC_OS8
55 /* Unfortunately this call is probably slower... */
56 #define LMGetTicks() TickCount()
57 #endif
59 #ifdef __MWERKS__
60 #include <SIOUX.h>
61 extern void SIOUXSetupMenus(void);
62 extern void SIOUXDoAboutBox(void);
63 #endif
64 #ifdef USE_GUSI
65 /* Functions we redefine because they're in obscure libraries */
66 extern void SpinCursor(short x);
67 extern void RotateCursor(short x);
68 extern pascal void PLstrcpy(unsigned char *, unsigned char *);
69 extern pascal int PLstrcmp(unsigned char *, unsigned char *);
70 extern pascal unsigned char *PLstrrchr(unsigned char *, unsigned char);
72 #endif
74 #ifdef USE_GUSI1
75 #include <TFileSpec.h> /* For Path2FSSpec */
76 #include <GUSI.h>
77 #endif
79 /* The ID of the Sioux apple menu */
80 #define SIOUX_APPLEID 32000
82 #include <signal.h>
83 #include <stdio.h>
86 ** When less than this amount of stackspace is left we
87 ** raise a MemoryError.
89 #ifndef MINIMUM_STACK_SIZE
90 #define MINIMUM_STACK_SIZE 8192
91 #endif
93 #if TARGET_API_MAC_CARBON
95 ** On MacOSX StackSpace() lies: it gives the distance from heap end to stack pointer,
96 ** but the stack cannot grow that far due to rlimit values. We cannot get at this value
97 ** from Carbon, so we set a maximum to the stack here that is based on the default
98 ** stack limit of 512K.
100 #define MAXIMUM_STACK_SIZE (256*1024)
101 #endif
104 ** We have to be careful, since we can't handle
105 ** things like updates (and they'll keep coming back if we don't
106 ** handle them). Note that we don't know who has windows open, so
107 ** even handing updates off to SIOUX under MW isn't going to work.
109 #define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask|activMask)
111 #include <signal.h>
113 /* XXX We should include Errors.h here, but it has a name conflict
114 ** with the python errors.h. */
115 #define fnfErr -43
117 /* Interrupt code variables: */
118 static int interrupted; /* Set to true when cmd-. seen */
119 static RETSIGTYPE intcatcher(int);
121 #if !TARGET_API_MAC_OSX
122 static int PyMac_Yield(void);
123 #endif
126 ** These are the real scheduling parameters that control what we check
127 ** in the event loop, and how often we check. The values are initialized
128 ** from pyMac_SchedParamStruct.
131 struct real_sched_param_struct {
132 int check_interrupt; /* if true check for command-dot */
133 int process_events; /* if nonzero enable evt processing, this mask */
134 int besocial; /* if nonzero be a little social with CPU */
135 unsigned long check_interval; /* how often to check, in ticks */
136 unsigned long bg_yield; /* yield so long when in background */
137 /* these are computed from previous and clock and such */
138 int enabled; /* check_interrupt OR process_event OR yield */
139 unsigned long next_check; /* when to check/yield next, in ticks */
142 static struct real_sched_param_struct schedparams =
143 { 1, MAINLOOP_EVENTMASK, 1, 15, 15, 1, 0};
146 ** Workaround for sioux/gusi combo: set when we are exiting
148 int PyMac_ConsoleIsDead;
151 ** Sioux menu bar, saved early so we can restore it
153 static MenuBarHandle sioux_mbar;
156 ** Some stuff for our GetDirectory and PromptGetFile routines
158 struct hook_args {
159 int selectcur_hit; /* Set to true when "select current" selected */
160 char *prompt; /* The prompt */
162 #if !TARGET_API_MAC_OS8
163 /* The StandardFile hooks don't exist in Carbon. This breaks GetDirectory,
164 ** but the macfsn code will replace it by a NavServices version anyway.
166 #define myhook_upp NULL
167 #else
168 static DlgHookYDUPP myhook_upp;
169 static int upp_inited = 0;
170 #endif
173 ** The python-code event handler
175 static PyObject *python_event_handler;
178 ** Set to true if we're appearance-compliant
180 int PyMac_AppearanceCompliant;
182 /* Given an FSSpec, return the FSSpec of the parent folder */
184 static OSErr
185 get_folder_parent (FSSpec * fss, FSSpec * parent)
187 CInfoPBRec rec;
188 short err;
190 * parent = * fss;
191 rec.hFileInfo.ioNamePtr = parent->name;
192 rec.hFileInfo.ioVRefNum = parent->vRefNum;
193 rec.hFileInfo.ioDirID = parent->parID;
194 rec.hFileInfo.ioFDirIndex = -1;
195 rec.hFileInfo.ioFVersNum = 0;
196 if (err = PBGetCatInfoSync (& rec))
197 return err;
198 parent->parID = rec.dirInfo.ioDrParID;
199 /* parent->name[0] = 0; */
200 return 0;
203 /* Given an FSSpec return a full, colon-separated pathname */
205 OSErr
206 PyMac_GetFullPathname (FSSpec *fss, char *buf, int length)
208 short err;
209 FSSpec fss_parent, fss_current;
210 char tmpbuf[1024];
211 int plen;
213 fss_current = *fss;
214 plen = fss_current.name[0];
215 if ( plen+2 > length ) {
216 *buf = 0;
217 return errFSNameTooLong;
219 memcpy(buf, &fss_current.name[1], plen);
220 buf[plen] = 0;
221 /* Special case for disk names */
222 if ( fss_current.parID <= 1 ) {
223 buf[plen++] = ':';
224 buf[plen] = 0;
225 return 0;
227 while (fss_current.parID > 1) {
228 /* Get parent folder name */
229 if (err = get_folder_parent(&fss_current, &fss_parent)) {
230 *buf = 0;
231 return err;
233 fss_current = fss_parent;
234 /* Prepend path component just found to buf */
235 plen = fss_current.name[0];
236 if (strlen(buf) + plen + 1 > 1024) {
237 /* Oops... Not enough space (shouldn't happen) */
238 *buf = 0;
239 return errFSNameTooLong;
241 memcpy(tmpbuf, &fss_current.name[1], plen);
242 tmpbuf[plen] = ':';
243 strcpy(&tmpbuf[plen+1], buf);
244 if ( strlen(tmpbuf) > length ) {
245 *buf = 0;
246 return errFSNameTooLong;
248 strcpy(buf, tmpbuf);
250 return 0;
253 #ifdef USE_GUSI1
255 ** GUSI (1.6.0 and earlier, at the least) do not set the MacOS idea of
256 ** the working directory. Hence, we call this routine after each call
257 ** to chdir() to rectify things.
259 void
260 PyMac_FixGUSIcd()
262 WDPBRec pb;
263 FSSpec curdirfss;
265 if ( Path2FSSpec(":x", &curdirfss) != noErr )
266 return;
268 /* Set MacOS "working directory" */
269 pb.ioNamePtr= "\p";
270 pb.ioVRefNum= curdirfss.vRefNum;
271 pb.ioWDDirID= curdirfss.parID;
272 if (PBHSetVolSync(&pb) != noErr)
273 return;
275 #endif
277 #ifdef USE_GUSI
279 ** SpinCursor (needed by GUSI) drags in heaps of stuff, so we
280 ** provide a dummy here.
282 void SpinCursor(short x) { /* Dummy */ }
283 void RotateCursor(short x) { /* Dummy */ }
286 ** Replacement GUSI Spin function
288 #ifdef USE_GUSI1
289 static int
290 PyMac_GUSISpin(spin_msg msg, long arg)
292 static Boolean inForeground = true;
293 int maxsleep = 6; /* 6 ticks is "normal" sleeptime */
295 if (PyMac_ConsoleIsDead) return 0;
296 #if 0
297 if (inForeground)
298 SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1);
299 #endif
302 if ( msg == SP_AUTO_SPIN )
303 maxsleep = 0;
304 if ( msg==SP_SLEEP||msg==SP_SELECT ) {
305 maxsleep = arg;
307 ** We force-scan for interrupts. Not pretty, but otherwise
308 ** a program may hang in select or sleep forever.
310 scan_event_queue(1);
312 if (interrupted) {
313 interrupted = 0;
314 return -1;
317 PyMac_DoYield(maxsleep, 0); /* XXXX or is it safe to call python here? */
319 return 0;
322 void
323 PyMac_SetGUSISpin() {
324 GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin);
326 #endif
328 /* Called at exit() time thru atexit(), to stop event processing */
329 void
330 PyMac_StopGUSISpin() {
331 PyMac_ConsoleIsDead = 1;
334 #if TARGET_API_MAC_OS8
336 ** Replacement routines for the PLstr... functions so we don't need
337 ** StdCLib.
339 pascal void
340 PLstrcpy(unsigned char *to, unsigned char *fr)
342 memcpy(to, fr, fr[0]+1);
345 pascal int
346 PLstrcmp(unsigned char *s1, unsigned char *s2)
348 int res;
349 int l = s1[0] < s2[0] ? s1[0] : s2[0];
351 res = memcmp(s1+1, s2+1, l);
352 if ( res != 0 )
353 return res;
355 if ( s1[0] < s2[0] )
356 return -1;
357 else if ( s1[0] > s2[0] )
358 return 1;
359 else
360 return 0;
363 pascal unsigned char *
364 PLstrrchr(unsigned char *str, unsigned char chr)
366 unsigned char *ptr = 0;
367 unsigned char *p;
369 for(p=str+1; p<str+str[0]; p++)
370 if ( *p == chr )
371 ptr = p;
372 return ptr;
375 #endif /* TARGET_API_MAC_OS8 */
376 #endif /* USE_GUSI */
379 /* Convert C to Pascal string. Returns pointer to static buffer. */
380 unsigned char *
381 Pstring(char *str)
383 static Str255 buf;
384 int len;
386 len = strlen(str);
387 if (len > 255)
388 len = 255;
389 buf[0] = (unsigned char)len;
390 strncpy((char *)buf+1, str, len);
391 return buf;
394 #if TARGET_API_MAC_OS8
395 void
396 c2pstrcpy(unsigned char *dst, const char *src)
398 int len;
400 len = strlen(src);
401 if ( len > 255 ) len = 255;
402 strncpy((char *)dst+1, src, len);
403 dst[0] = len;
405 #endif /* TARGET_API_MAC_OS8 */
407 #ifdef USE_STACKCHECK
408 /* Check for stack overflow */
410 PyOS_CheckStack()
412 char here;
413 static char *sentinel = 0;
414 static PyThreadState *thread_for_sentinel = 0;
416 if ( sentinel == 0 ) {
417 unsigned long stackspace = StackSpace();
419 #ifdef MAXIMUM_STACK_SIZE
420 /* See the comment at the definition */
421 if ( stackspace > MAXIMUM_STACK_SIZE )
422 stackspace = MAXIMUM_STACK_SIZE;
423 #endif
424 sentinel = &here - stackspace + MINIMUM_STACK_SIZE;
426 if ( thread_for_sentinel == 0 ) {
427 thread_for_sentinel = PyThreadState_Get();
429 if ( &here < sentinel ) {
430 if (thread_for_sentinel == PyThreadState_Get()) {
431 return -1;
432 #if 0
433 } else {
434 /* Else we are unsure... */
435 fprintf(stderr, "Stackcheck in other thread (was %x now %x)\n", thread_for_sentinel,PyThreadState_Get());
436 #endif
439 return 0;
441 #endif /* USE_STACKCHECK */
443 #if !TARGET_API_MAC_OSX
444 /* The catcher routine (which may not be used for all compilers) */
445 static RETSIGTYPE
446 intcatcher(sig)
447 int sig;
449 interrupted = 1;
450 signal(SIGINT, intcatcher);
453 void
454 PyOS_InitInterrupts()
456 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
457 signal(SIGINT, intcatcher);
460 void
461 PyOS_FiniInterrupts()
465 /* Check whether we are in the foreground */
466 static int
467 PyMac_InForeground(void)
469 static ProcessSerialNumber ours;
470 static inited;
471 ProcessSerialNumber curfg;
472 Boolean eq;
474 if ( inited == 0 ) {
475 (void)GetCurrentProcess(&ours);
476 inited = 1;
478 if ( GetFrontProcess(&curfg) < 0 )
479 eq = 1;
480 else if ( SameProcess(&ours, &curfg, &eq) < 0 )
481 eq = 1;
482 return (int)eq;
486 ** This routine scans the event queue looking for cmd-.
488 static void
489 scan_event_queue(force)
490 int force;
492 #if !TARGET_API_MAC_OS8
493 if ( interrupted || (!schedparams.check_interrupt && !force) )
494 return;
495 if ( CheckEventQueueForUserCancel() )
496 interrupted = 1;
497 #else
498 register EvQElPtr q;
500 if ( interrupted || (!schedparams.check_interrupt && !force) || !PyMac_InForeground() )
501 return;
502 q = (EvQElPtr) LMGetEventQueue()->qHead;
504 for (; q; q = (EvQElPtr)q->qLink) {
505 if (q->evtQWhat == keyDown &&
506 (char)q->evtQMessage == '.' &&
507 (q->evtQModifiers & cmdKey) != 0) {
508 FlushEvents(keyDownMask, 0);
509 interrupted = 1;
510 break;
513 #endif
517 PyErr_CheckSignals()
519 if (schedparams.enabled) {
520 if ( interrupted || (unsigned long)LMGetTicks() > schedparams.next_check ) {
521 scan_event_queue(0);
522 if (interrupted) {
523 interrupted = 0;
524 PyErr_SetNone(PyExc_KeyboardInterrupt);
525 return -1;
527 if ( PyMac_Yield() < 0)
528 return -1;
529 schedparams.next_check = (unsigned long)LMGetTicks()
530 + schedparams.check_interval;
533 return 0;
537 PyOS_InterruptOccurred()
539 scan_event_queue(0);
540 if ( !interrupted )
541 return 0;
542 interrupted = 0;
543 return 1;
545 #endif
548 PyMac_SetEventHandler(PyObject *evh)
550 if ( evh && python_event_handler ) {
551 PyErr_SetString(PyExc_RuntimeError, "Python event handler already set");
552 return 0;
554 if ( python_event_handler )
555 Py_DECREF(python_event_handler);
556 if ( evh )
557 Py_INCREF(evh);
558 python_event_handler = evh;
559 return 1;
563 ** Handle an event, either one found in the mainloop eventhandler or
564 ** one passed back from the python program.
566 void
567 PyMac_HandleEventIntern(evp)
568 EventRecord *evp;
570 #if TARGET_API_MAC_OS8
571 if ( evp->what == mouseDown ) {
572 WindowPtr wp;
574 if ( FindWindow(evp->where, &wp) == inSysWindow ) {
575 SystemClick(evp, wp);
576 return;
579 #endif
580 #ifdef __MWERKS__
582 int siouxdidit;
584 /* If SIOUX wants it we're done */
585 siouxdidit = SIOUXHandleOneEvent(evp);
586 if ( siouxdidit )
587 return;
589 #else
590 /* Other compilers are just unlucky... */
591 #endif /* !__MWERKS__ */
595 ** Handle an event, either through HandleEvent or by passing it to the Python
596 ** event handler.
599 PyMac_HandleEvent(evp)
600 EventRecord *evp;
602 PyObject *rv;
604 if ( python_event_handler ) {
605 rv = PyObject_CallFunction(python_event_handler, "(O&)",
606 PyMac_BuildEventRecord, evp);
607 if ( rv )
608 Py_DECREF(rv);
609 else
610 return -1; /* Propagate exception */
611 } else {
612 PyMac_HandleEventIntern(evp);
614 return 0;
617 #if !TARGET_API_MAC_OSX
619 ** Yield the CPU to other tasks without processing events.
622 PyMac_DoYield(int maxsleep, int maycallpython)
624 EventRecord ev;
625 int gotone;
626 long latest_time_ready;
627 static int in_here = 0;
629 in_here++;
632 ** Check which of the eventloop cases we have:
633 ** - process events
634 ** - don't process events but do yield
635 ** - do neither
637 if( in_here > 1 || !schedparams.process_events ||
638 (python_event_handler && !maycallpython) ) {
639 if ( maxsleep >= 0 ) {
640 #if TARGET_API_MAC_OS8
641 SystemTask();
642 #else
643 int xxx = 0;
644 #endif
646 } else {
647 latest_time_ready = LMGetTicks() + maxsleep;
648 do {
649 /* XXXX Hack by Jack.
650 ** In time.sleep() you can click to another application
651 ** once only. If you come back to Python you cannot get away
652 ** again.
654 gotone = WaitNextEvent(schedparams.process_events, &ev, maxsleep, NULL);
655 /* Get out quickly if nothing interesting is happening */
656 if ( !gotone || ev.what == nullEvent )
657 break;
658 if ( PyMac_HandleEvent(&ev) < 0 ) {
659 in_here--;
660 return -1;
662 maxsleep = latest_time_ready - LMGetTicks();
663 } while ( maxsleep > 0 );
665 in_here--;
666 return 0;
670 ** Process events and/or yield the CPU to other tasks if opportune
673 PyMac_Yield() {
674 unsigned long maxsleep;
676 if( PyMac_InForeground() )
677 maxsleep = 0;
678 else
679 maxsleep = schedparams.bg_yield;
681 return PyMac_DoYield(maxsleep, 1);
685 ** Return current scheduler parameters
687 void
688 PyMac_GetSchedParams(PyMacSchedParams *sp)
690 sp->check_interrupt = schedparams.check_interrupt;
691 sp->process_events = schedparams.process_events;
692 sp->besocial = schedparams.besocial;
693 sp->check_interval = schedparams.check_interval / 60.0;
694 sp->bg_yield = schedparams.bg_yield / 60.0;
698 ** Set current scheduler parameters
700 void
701 PyMac_SetSchedParams(PyMacSchedParams *sp)
703 schedparams.check_interrupt = sp->check_interrupt;
704 schedparams.process_events = sp->process_events;
705 schedparams.besocial = sp->besocial;
706 schedparams.check_interval = (unsigned long)(sp->check_interval*60);
707 schedparams.bg_yield = (unsigned long)(sp->bg_yield*60);
708 if ( schedparams.check_interrupt || schedparams.process_events ||
709 schedparams.besocial )
710 schedparams.enabled = 1;
711 else
712 schedparams.enabled = 0;
713 schedparams.next_check = 0; /* Check immedeately */
717 ** Install our menu bar.
719 void
720 PyMac_InitMenuBar()
722 MenuHandle applemenu;
723 Str255 about_text;
724 static unsigned char about_sioux[] = "\pAbout SIOUX";
726 if ( sioux_mbar ) return;
727 #if 0
728 /* This code does not seem to work anymore: apparently
729 ** we now always have a menubar (since MacOS9?).
730 ** So we simply always setup the Sioux menus here.
732 if ( (sioux_mbar=GetMenuBar()) == NULL ) {
733 #else
734 if ( (sioux_mbar=GetMenuBar()) == NULL || GetMenuHandle(SIOUX_APPLEID) == NULL) {
735 #endif
736 /* Sioux menu not installed yet. Do so */
737 SIOUXSetupMenus();
738 if ( (sioux_mbar=GetMenuBar()) == NULL )
739 return;
741 if ( (applemenu=GetMenuHandle(SIOUX_APPLEID)) == NULL ) return;
742 GetMenuItemText(applemenu, 1, about_text);
743 if ( about_text[0] == about_sioux[0] &&
744 strncmp((char *)(about_text+1), (char *)(about_sioux+1), about_text[0]) == 0 )
745 SetMenuItemText(applemenu, 1, "\pAbout Python...");
749 ** Restore sioux menu bar
751 void
752 PyMac_RestoreMenuBar()
754 #if 1
755 /* This doesn't seem to work anymore? Or only for Carbon? */
756 MenuBarHandle curmenubar;
758 curmenubar = GetMenuBar();
759 if ( sioux_mbar ) {
760 SetMenuBar(sioux_mbar);
761 DrawMenuBar();
762 } else {
763 PyMac_InitMenuBar();
764 DrawMenuBar();
766 #endif
769 void
770 PyMac_RaiseConsoleWindow()
772 /* Note: this is a hack. SIOUXTextWindow is SIOUX's internal structure
773 ** and we happen to know that the first entry is the window pointer.
775 extern WindowRef *SIOUXTextWindow;
777 if ( SIOUXTextWindow == NULL || *SIOUXTextWindow == NULL )
778 return;
779 if ( FrontWindow() != *SIOUXTextWindow )
780 BringToFront(*SIOUXTextWindow);
784 ** Our replacement about box
787 #include "patchlevel.h"
789 void
790 SIOUXDoAboutBox(void)
792 DialogPtr theDialog;
793 WindowPtr theWindow;
794 short item;
795 short fontID;
797 if( (theDialog = GetNewDialog(ABOUT_ID, NULL, (WindowPtr)-1)) == NULL )
798 return;
799 theWindow = GetDialogWindow(theDialog);
800 SetPortWindowPort(theWindow);
801 GetFNum("\pPython-Sans", &fontID);
802 if (fontID == 0)
803 fontID = kFontIDGeneva;
804 TextFont(fontID);
805 TextSize(9);
806 ParamText(Pstring(PY_VERSION), "\p", "\p", "\p");
807 ShowWindow(theWindow);
808 ModalDialog(NULL, &item);
809 DisposeDialog(theDialog);
812 #endif /* !TARGET_API_MAC_OSX */
814 #if TARGET_API_MAC_OS8
816 ** Helper routine for GetDirectory
818 static pascal short
819 myhook_proc(short item, DialogPtr theDialog, struct hook_args *dataptr)
821 if ( item == sfHookFirstCall && dataptr->prompt) {
822 Handle prompth;
823 short type;
824 Rect rect;
826 GetDialogItem(theDialog, PROMPT_ITEM, &type, &prompth, &rect);
827 if ( prompth )
828 SetDialogItemText(prompth, (unsigned char *)dataptr->prompt);
829 } else
830 if ( item == SELECTCUR_ITEM ) {
831 item = sfItemCancelButton;
832 dataptr->selectcur_hit = 1;
834 return item;
838 ** Ask the user for a directory. I still can't understand
839 ** why Apple doesn't provide a standard solution for this...
842 PyMac_GetDirectory(dirfss, prompt)
843 FSSpec *dirfss;
844 char *prompt;
846 static SFTypeList list = {'fldr', 0, 0, 0};
847 static Point where = {-1, -1};
848 StandardFileReply reply;
849 struct hook_args hook_args;
851 if ( !upp_inited ) {
852 myhook_upp = NewDlgHookYDProc(myhook_proc);
853 upp_inited = 1;
855 if ( prompt && *prompt )
856 hook_args.prompt = (char *)Pstring(prompt);
857 else
858 hook_args.prompt = NULL;
859 hook_args.selectcur_hit = 0;
860 CustomGetFile((FileFilterYDUPP)0, 1, list, &reply, GETDIR_ID, where, myhook_upp,
861 NULL, NULL, NULL, (void *)&hook_args);
863 reply.sfFile.name[0] = 0;
864 if( FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, dirfss) )
865 return 0;
866 return hook_args.selectcur_hit;
870 ** Slightly extended StandardGetFile: accepts a prompt */
871 void PyMac_PromptGetFile(short numTypes, ConstSFTypeListPtr typeList,
872 StandardFileReply *reply, char *prompt)
874 static Point where = {-1, -1};
875 struct hook_args hook_args;
877 if ( !upp_inited ) {
878 myhook_upp = NewDlgHookYDProc(myhook_proc);
879 upp_inited = 1;
881 if ( prompt && *prompt )
882 hook_args.prompt = (char *)Pstring(prompt);
883 else
884 hook_args.prompt = NULL;
885 hook_args.selectcur_hit = 0;
886 CustomGetFile((FileFilterYDUPP)0, numTypes, typeList, reply, GETFILEPROMPT_ID, where,
887 myhook_upp, NULL, NULL, NULL, (void *)&hook_args);
889 #endif /* TARGET_API_MAC_OS8 */