|
22 | 22 |
|
23 | 23 | #include <ApplicationServices/ApplicationServices.h> |
24 | 24 |
|
25 | | -#if !TARGET_API_MAC_OSX |
26 | | - /* This code is adapted from the CallMachOFramework demo at: |
27 | | - http://developer.apple.com/samplecode/Sample_Code/Runtime_Architecture/CallMachOFramework.htm |
28 | | - It allows us to call Mach-O functions from CFM apps. */ |
29 | | - |
30 | | - #include <Folders.h> |
31 | | - #include "CFMLateImport.h" |
32 | | - |
33 | | - static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr) |
34 | | - // This routine finds a the named framework and creates a CFBundle |
35 | | - // object for it. It looks for the framework in the frameworks folder, |
36 | | - // as defined by the Folder Manager. Currently this is |
37 | | - // "/System/Library/Frameworks", but we recommend that you avoid hard coded |
38 | | - // paths to ensure future compatibility. |
39 | | - // |
40 | | - // You might think that you could use CFBundleGetBundleWithIdentifier but |
41 | | - // that only finds bundles that are already loaded into your context. |
42 | | - // That would work in the case of the System framework but it wouldn't |
43 | | - // work if you're using some other, less-obvious, framework. |
44 | | - { |
45 | | - OSStatus err; |
46 | | - FSRef frameworksFolderRef; |
47 | | - CFURLRef baseURL; |
48 | | - CFURLRef bundleURL; |
49 | | - |
50 | | - *bundlePtr = nil; |
51 | | - |
52 | | - baseURL = nil; |
53 | | - bundleURL = nil; |
54 | | - |
55 | | - // Find the frameworks folder and create a URL for it. |
56 | | - |
57 | | - err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef); |
58 | | - if (err == noErr) { |
59 | | - baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef); |
60 | | - if (baseURL == nil) { |
61 | | - err = coreFoundationUnknownErr; |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - // Append the name of the framework to the URL. |
66 | | - |
67 | | - if (err == noErr) { |
68 | | - bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false); |
69 | | - if (bundleURL == nil) { |
70 | | - err = coreFoundationUnknownErr; |
71 | | - } |
72 | | - } |
73 | | - |
74 | | - // Create a bundle based on that URL and load the bundle into memory. |
75 | | - // We never unload the bundle, which is reasonable in this case because |
76 | | - // the sample assumes that you'll be calling functions from this |
77 | | - // framework throughout the life of your application. |
78 | | - |
79 | | - if (err == noErr) { |
80 | | - *bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL); |
81 | | - if (*bundlePtr == nil) { |
82 | | - err = coreFoundationUnknownErr; |
83 | | - } |
84 | | - } |
85 | | - if (err == noErr) { |
86 | | - if ( ! CFBundleLoadExecutable( *bundlePtr ) ) { |
87 | | - err = coreFoundationUnknownErr; |
88 | | - } |
89 | | - } |
90 | | - |
91 | | - // Clean up. |
92 | | - |
93 | | - if (err != noErr && *bundlePtr != nil) { |
94 | | - CFRelease(*bundlePtr); |
95 | | - *bundlePtr = nil; |
96 | | - } |
97 | | - if (bundleURL != nil) { |
98 | | - CFRelease(bundleURL); |
99 | | - } |
100 | | - if (baseURL != nil) { |
101 | | - CFRelease(baseURL); |
102 | | - } |
103 | | - |
104 | | - return err; |
105 | | - } |
106 | | - |
107 | | - |
108 | | - |
109 | | - // The CFMLateImport approach requires that you define a fragment |
110 | | - // initialisation routine that latches the fragment's connection |
111 | | - // ID and locator. If your code already has a fragment initialiser |
112 | | - // you will have to integrate the following into it. |
113 | | - |
114 | | - static CFragConnectionID gFragToFixConnID; |
115 | | - static FSSpec gFragToFixFile; |
116 | | - static CFragSystem7DiskFlatLocator gFragToFixLocator; |
117 | | - |
118 | | - extern OSErr FragmentInit(const CFragInitBlock *initBlock); |
119 | | - extern OSErr FragmentInit(const CFragInitBlock *initBlock) |
120 | | - { |
121 | | - __initialize(initBlock); /* call the "original" initializer */ |
122 | | - gFragToFixConnID = (CFragConnectionID) initBlock->closureID; |
123 | | - gFragToFixFile = *(initBlock->fragLocator.u.onDisk.fileSpec); |
124 | | - gFragToFixLocator = initBlock->fragLocator.u.onDisk; |
125 | | - gFragToFixLocator.fileSpec = &gFragToFixFile; |
126 | | - |
127 | | - return noErr; |
128 | | - } |
129 | | - |
130 | | -#endif |
131 | | - |
132 | 25 | extern int GrafObj_Convert(PyObject *, GrafPtr *); |
133 | 26 |
|
134 | 27 | /* |
@@ -1369,23 +1262,6 @@ void init_CG(void) |
1369 | 1262 |
|
1370 | 1263 |
|
1371 | 1264 |
|
1372 | | -#if !TARGET_API_MAC_OSX |
1373 | | - CFBundleRef sysBundle; |
1374 | | - OSStatus err; |
1375 | | - |
1376 | | - if (&LoadFrameworkBundle == NULL) { |
1377 | | - PyErr_SetString(PyExc_ImportError, "CoreCraphics not supported"); |
1378 | | - return; |
1379 | | - } |
1380 | | - err = LoadFrameworkBundle(CFSTR("ApplicationServices.framework"), &sysBundle); |
1381 | | - if (err == noErr) |
1382 | | - err = CFMLateImportBundle(&gFragToFixLocator, gFragToFixConnID, FragmentInit, "\pCGStubLib", sysBundle); |
1383 | | - if (err != noErr) { |
1384 | | - PyErr_SetString(PyExc_ImportError, "CoreCraphics not supported"); |
1385 | | - return; |
1386 | | - }; |
1387 | | -#endif /* !TARGET_API_MAC_OSX */ |
1388 | | - |
1389 | 1265 |
|
1390 | 1266 | m = Py_InitModule("_CG", CG_methods); |
1391 | 1267 | d = PyModule_GetDict(m); |
|
0 commit comments