1 module bindbc.cocoa.dynloadappkit;
2 
3 import bindbc.cocoa.appkit;
4 import bindbc.cocoa.coreimage;
5 
6 import bindbc.loader;
7 
8 private {
9     SharedLib lib;
10     AppkitSupport loadedVersion;
11 }
12 
13 enum AppkitSupport {
14     noLibrary,
15     badLibrary,
16     appkitLibrary
17 }
18 
19 void unloadAppkit()
20 {
21     if(lib != invalidHandle) {
22         lib.unload();
23     }
24 }
25 
26 AppkitSupport loadedAppkitVersion() { return loadedVersion; }
27 
28 bool isAppkitLoaded() { return lib != invalidHandle; }
29 
30 AppkitSupport loadAppkit(const(char)* libName)
31 {
32     // If the library isn't yet loaded, load it now.
33     if(lib == invalidHandle) {
34         lib = load(libName);
35         if(lib == invalidHandle) {
36             return AppkitSupport.noLibrary;
37         }
38     }
39 
40     auto errCount = errorCount();
41 
42     lib.bindSymbol(cast(void**)&NSApplicationLoad, "NSApplicationLoad");
43     lib.bindSymbol(cast(void**)&NSApplicationMain, "NSApplicationMain");
44     // Core Image
45     // MAYDO load from proper global variables
46     kCIFormatARGB8 = 23;
47     kCIFormatRGBA16 = 27;
48     kCIFormatRGBAf = 34;
49     kCIFormatRGBAh = 31;
50     
51     if(errorCount() != errCount) loadedVersion = AppkitSupport.badLibrary;
52     else loadedVersion = AppkitSupport.appkitLibrary;
53 
54     return loadedVersion;
55 }