AmendHub

Download:

nulleric

/

Fix-a-Fork

/

amendments

/

2

Add open dialog. Fix crash due to not calling initgraf & initwindows.


eric made amendment 2 11 months ago
--- main.c Wed Nov 8 10:47:50 2023 +++ main.c Wed Nov 8 18:57:54 2023 @@ -3,15 +3,17 @@ #include <Events.h> #include <AppleEvents.h> #include <GestaltEqu.h> - +#include <Dialogs.h> #include <Types.h> // Globals -//OSType gType = 0; -//OSType gCreator = 0; -//Boolean gHandledByDnD = false; - +OSType gType = 0; +OSType gCreator = 0; +Boolean gHandledByDnD = false; +// main.h +void openFile(unsigned char *fName, short fRefNum, short vRefNum); pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent *reply, long handlerRefcon); + pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent *reply, long handlerRefcon) { FSSpec fss; @@ -23,7 +25,7 @@ pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent * DescType returnedType; //short frefNum; - //err = AEGetParamDesc(event, keyDirectObject, typeAEList, %docList); + err = AEGetParamDesc(event, keyDirectObject, typeAEList, &docList); if(err != noErr) return err; err = AECountItems(&docList, &itemsInList); if(err != noErr) return err; @@ -32,9 +34,9 @@ pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent * { err = AEGetNthPtr(&docList, index, typeFSS, &keywd, &returnedType, (Ptr)&fss, sizeof(fss), &actualSize); if(err != noErr) return err; - - // got file - //gHandledByDnD = true; + + // got file by drag and drop + gHandledByDnD = true; } AEDisposeDesc(&docList); return noErr; @@ -53,13 +55,52 @@ void InstallEventHandlers() } else { return; } - WaitNextEvent(highLevelEventMask, &event, 0, 0); + WaitNextEvent(highLevelEventMask, &event, 30, 0); if(event.what == kHighLevelEvent) AEProcessAppleEvent(&event); } +void OpenFileDialog() +{ + SFReply tr; + StandardFileReply reply; + Point where; + where.h = 100; + where.v = 50; + + do { + //SFGetFile(where, nil, nil, -1, nil, nil, &tr); + StandardGetFile(nil, -1, nil, &reply); + if(reply.sfGood) + { + openFile(reply.sfFile.name, 0, reply.sfFile.vRefNum); + } + } while(reply.sfGood); +} + +void openFile(unsigned char *fName, short fRefNum, short vRefNum) +{ + short err; + err = FSOpen(fName, vRefNum, &fRefNum); + ParamText(fName, "\p", "\p", "\p"); + Alert(128, nil); + FSClose(fRefNum); +} + void main() { + MaxApplZone(); + InitGraf(&qd.thePort); + InitFonts(); + InitWindows(); + InitMenus(); + TEInit(); + InitDialogs(nil); + InitCursor(); + + FlushEvents(everyEvent, 0); InstallEventHandlers(); + if(!gHandledByDnD) + OpenFileDialog(); return; }