Changeset 699

Show
Ignore:
Timestamp:
02/08/08 08:20:08 (10 months ago)
Author:
takkaria
Message:

Reflow logic inside the "open" apple event handler function, allowing it to function again; also, fix typos in Angband.xml (Rowan Beentje). Closes #380.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main-crb.c

    r694 r699  
    27802780        return cmd;  
    27812781}  
    2782  
    2783  
    2784 /* Open Document is only remaining apple event that needs to be handled 
    2785    explicitly */ 
    2786 static OSStatus AppleCommand(EventHandlerCallRef inCallRef, 
    2787                                                         EventRef inEvent, void *inUserData ) 
    2788 { 
    2789         EventRecord aevent; 
    2790         (void) AEProcessAppleEvent(&aevent); 
    2791         if(open_when_ready) { 
    2792                 game_in_progress = TRUE; 
    2793         } 
    2794         return noErr; 
    2795 } 
    27962782 
    27972783 
     
    34613447        FSSpec myFSS; 
    34623448        AEDescList docList; 
     3449        long fileindex; 
     3450        long filecount; 
    34633451        OSErr err; 
    3464         Size actualSize; 
    3465         AEKeyword keywd; 
    3466         DescType returnedType; 
    3467         char msg[128]; 
    34683452        FInfo myFileInfo; 
    34693453 
    34703454        /* Put the direct parameter (a descriptor list) into a docList */ 
    3471         err = AEGetParamDesc( 
    3472                 theAppleEvent, keyDirectObject, typeAEList, &docList); 
     3455        err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList); 
    34733456        if (err) return err; 
    3474  
    3475         /* 
    3476          * We ignore the validity check, because we trust the FInder, and we only 
    3477          * allow one savefile to be opened, so we ignore the depth of the list. 
    3478          */ 
    3479         err = AEGetNthPtr( 
    3480                 &docList, 1L, typeFSS, &keywd, &returnedType, 
    3481                 (Ptr) &myFSS, sizeof(myFSS), &actualSize); 
     3457         
     3458        err = AECountItems(&docList, &filecount); 
    34823459        if (err) return err; 
    34833460 
    3484         /* Only needed to check savefile type below */ 
    3485         err = FSpGetFInfo(&myFSS, &myFileInfo); 
    3486         if (err) 
    3487         { 
    3488                 strnfmt(msg, sizeof(msg), "Argh!  FSpGetFInfo failed with code %d", err); 
    3489                 mac_warning(msg); 
    3490                 return err; 
    3491         } 
    3492  
    3493         /* Ignore non 'SAVE' files */ 
    3494         if (myFileInfo.fdType != 'SAVE') return noErr; 
    3495  
    3496         /* Extract a file name */ 
    3497         (void)spec_to_path(&myFSS, savefile, sizeof(savefile)); 
    3498  
    3499         /* Delay actual open */ 
    3500         open_when_ready = TRUE; 
     3461        /* Only open one file, but check for the first valid file in the list */ 
     3462        for (fileindex = 1; fileindex <= filecount; fileindex++) 
     3463        { 
     3464                err = AEGetNthPtr(&docList, fileindex, typeFSS, NULL, NULL, &myFSS, sizeof(myFSS), NULL); 
     3465                if (err) continue; 
     3466                 
     3467                err = FSpGetFInfo(&myFSS, &myFileInfo); 
     3468                if (err) continue; 
     3469                 
     3470                if (myFileInfo.fdType == 'SAVE') 
     3471                { 
     3472                         
     3473                        /* Extract the filename and delay the open */ 
     3474                        (void)spec_to_path(&myFSS, savefile, sizeof(savefile)); 
     3475                        cmd.command = CMD_LOADFILE; 
     3476                         
     3477                        break; 
     3478                } 
     3479        } 
    35013480 
    35023481        /* Dispose */ 
     
    35053484        /* Success */ 
    35063485        return noErr; 
    3507 } 
    3508  
    3509 /* 
    3510  * Apple Event Handler -- Re-open Application 
    3511  * 
    3512  * If no windows are currently open, show the Angband window. 
    3513  * This required AppleEvent was introduced by System 8 -- pelpel 
    3514  */ 
    3515 static OSErr AEH_Reopen(const AppleEvent *theAppleEvent, 
    3516                              AppleEvent* reply, long handlerRefCon) 
    3517 { 
    3518 #pragma unused(theAppleEvent, reply, handlerRefCon) 
    3519  
    3520         term_data *td = NULL; 
    3521  
    3522         /* No open windows */ 
    3523         if (NULL == FrontWindow()) 
    3524         { 
    3525                 /* Obtain the Angband window */ 
    3526                 td = &data[0]; 
    3527  
    3528                 /* Mapped */ 
    3529                 td->mapped = TRUE; 
    3530  
    3531                 /* Link */ 
    3532                 term_data_link(0); 
    3533  
    3534                 /* Mapped (?) */ 
    3535                 td->t->mapped_flag = TRUE; 
    3536  
    3537                 /* Show the window */ 
    3538                 ShowWindow(td->w); 
    3539  
    3540                 /* Bring to the front */ 
    3541                 SelectWindow(td->w); 
    3542  
    3543                 /* Make it active */ 
    3544                 activate(td->w); 
    3545         } 
    3546         /* Event handled */ 
    3547         return (noErr); 
    35483486} 
    35493487 
     
    38033741        init_windows(); 
    38043742 
    3805 #if 0 
    3806         /* Handle 'apple' events */ 
    3807     /* Install the open event hook (ignore error codes) */ 
     3743    /* Install the 'Apple Event' handler hook (ignore error codes) */ 
    38083744    (void)AEInstallEventHandler( 
    38093745        kCoreEventClass, 
     
    38123748        0L, 
    38133749        FALSE); 
    3814 #endif 
    38153750 
    38163751        /* Install menu and application handlers */ 
     
    38573792        CreateEvent ( nil, 'Play', 'Band', GetCurrentEventTime(),     
    38583793                                                                        kEventAttributeNone, &newGameEvent );  
    3859         PostEventToQueue(GetMainEventQueue(), newGameEvent, kEventPriorityHigh); 
     3794        PostEventToQueue(GetMainEventQueue(), newGameEvent, kEventPriorityLow); 
    38603795 
    38613796        RunApplicationEventLoop();