Subversion Repositories filter_foundry

Rev

Rev 193 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.         This file is part of a common library
  3.     Copyright (C) 1990-2006 Toby Thain, toby@telegraphics.com.au
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by  
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License  
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #include "ae.h"
  21.  
  22. #pragma segment AE
  23.  
  24. OSErr got_required_params(const AppleEvent *ae){
  25.         DescType typeCode;
  26.         Size actualSize;
  27.         OSErr e;
  28.  
  29.         e = AEGetAttributePtr(ae,keyMissedKeywordAttr,typeWildCard,&typeCode,0,0,&actualSize);
  30.         return e == errAEDescNotFound ? noErr : (e ? e : errAEEventNotHandled);
  31. }
  32.  
  33. AE_HANDLER(handle_open_app){ OSErr e;
  34.         if(!(e = got_required_params(theAppleEvent)))
  35.                 e = open_app();
  36.         return e;
  37. }
  38.  
  39. OSErr doc_list(const AppleEvent *theAppleEvent,OSErr (*f)(FSSpec *fss)){
  40.         AEDescList docList;
  41.         long i;
  42.         AEKeyword theAEKeyword;
  43.         DescType typeCode;
  44.         FSSpec fss;
  45.         Size actualSize;
  46.         OSErr e;
  47.  
  48.         if(!(e = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList))){
  49.                 if(!(e = got_required_params(theAppleEvent)) && !(e = AECountItems(&docList,&i)))
  50.                         while(i)
  51.                                 if( (e = AEGetNthPtr(&docList,i--,typeFSS,&theAEKeyword,
  52.                                                                          &typeCode,(Ptr)&fss,sizeof(fss),&actualSize))
  53.                                  || (e = f(&fss)) )
  54.                                         break;
  55.                 AEDisposeDesc(&docList);
  56.         }
  57.         return e;
  58. }
  59.  
  60. AE_HANDLER(handle_open_doc){
  61.         return doc_list(theAppleEvent,open_doc);
  62. }
  63.  
  64. AE_HANDLER(handle_print_doc){
  65.         return doc_list(theAppleEvent,print_doc);
  66. }
  67.  
  68. AE_HANDLER(handle_quit_app){ OSErr e;
  69.         if(!(e = got_required_params(theAppleEvent)))
  70.                 e = quit_app();
  71.         return e;
  72. }
  73.  
  74. OSErr init_AE(struct AE_handler *h){ OSErr e = noErr;
  75.         for(;h->theAEEventClass;h++)
  76.                 if(e = AEInstallEventHandler(h->theAEEventClass,h->theAEEventID,
  77.                                                                          NewAEEventHandlerUPP(h->handler),0,false))
  78.                         break;
  79.         return e;
  80. }
  81.