-
Notifications
You must be signed in to change notification settings - Fork 510
/
carbon_hook.c
88 lines (73 loc) · 2.37 KB
/
carbon_hook.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2022-2023
* All rights reserved
*
* This file is part of GPAC / gpac application
*
* GPAC is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GPAC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#if defined(__DARWIN__) || defined(__APPLE__)
#include <Carbon/Carbon.h>
#endif
#include <gpac/setup.h>
#ifndef GPAC_DISABLE_COMPOSITOR
//declare prototype, don't include gpac.h due to conflict in Fixed type between gpac and OSX
void carbon_remove_hook(void);
void carbon_set_hook(void);
void gpac_open_urls(const char *urls);
int gf_dynstrcat(char **str, const char *to_append, const char *sep);
static AEEventHandlerUPP open_doc_UPP;
void carbon_remove_hook()
{
AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, open_doc_UPP, false);
DisposeAEEventHandlerUPP(open_doc_UPP);
}
static pascal OSErr sdl_ae_open_doc(const AppleEvent *ae_event, AppleEvent *ae_reply, long ae_ref_count)
{
char path[4096];
OSErr err;
AEDescList docList;
long i, count;
char *urls = NULL;
err = AEGetParamDesc(ae_event, keyDirectObject, typeAEList, &docList);
if (err) goto exit;
err = AECountItems(&docList, &count);
if (err) goto exit;
for (i=0; i<count; i++) {
FSRef ref;
err = AEGetNthPtr(&docList, i+1, typeFSRef, NULL, NULL, &ref, sizeof(FSRef), NULL);
if (err) continue;
FSRefMakePath(&ref, (UInt8 *) path, 4096);
path[4095]=0;
gf_dynstrcat(&urls, path, ",");
}
if (urls) {
gpac_open_urls(urls);
gf_free(urls);
}
AEDisposeDesc(&docList);
exit:
return (noErr);
}
void carbon_set_hook()
{
open_doc_UPP = NewAEEventHandlerUPP(sdl_ae_open_doc);
AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, open_doc_UPP, 0L, false);
}
#endif // GPAC_DISABLE_COMPOSITOR