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