AppKitPrivate.hpp
1 /* 2 * 3 * Copyright 2020-2021 Apple Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 19 // 20 // AppKit/AppKitPrivate.hpp 21 // 22 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 23 24 #pragma once 25 26 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 27 28 #include <objc/runtime.h> 29 30 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 31 32 #define _APPKIT_PRIVATE_CLS( symbol ) ( Private::Class::s_k ## symbol ) 33 #define _APPKIT_PRIVATE_SEL( accessor ) ( Private::Selector::s_k ## accessor ) 34 35 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 36 37 #if defined( NS_PRIVATE_IMPLEMENTATION ) 38 39 #define _APPKIT_PRIVATE_VISIBILITY __attribute__( ( visibility( "default" ) ) ) 40 #define _APPKIT_PRIVATE_IMPORT __attribute__( ( weak_import ) ) 41 42 #if __OBJC__ 43 #define _APPKIT_PRIVATE_OBJC_LOOKUP_CLASS( symbol ) ( ( __bridge void* ) objc_lookUpClass( # symbol ) ) 44 #else 45 #define _APPKIT_PRIVATE_OBJC_LOOKUP_CLASS( symbol ) objc_lookUpClass( # symbol ) 46 #endif // __OBJC__ 47 48 #define _APPKIT_PRIVATE_DEF_CLS( symbol ) void* s_k ## symbol _NS_PRIVATE_VISIBILITY = _NS_PRIVATE_OBJC_LOOKUP_CLASS( symbol ); 49 #define _APPKIT_PRIVATE_DEF_SEL( accessor, symbol ) SEL s_k ## accessor _NS_PRIVATE_VISIBILITY = sel_registerName( symbol ); 50 #define _APPKIT_PRIVATE_DEF_CONST( type, symbol ) _NS_EXTERN type const NS ## symbol _NS_PRIVATE_IMPORT; \ 51 type const NS::symbol = ( nullptr != &NS ## symbol ) ? NS ## symbol : nullptr; 52 53 54 #else 55 56 #define _APPKIT_PRIVATE_DEF_CLS( symbol ) extern void* s_k ## symbol; 57 #define _APPKIT_PRIVATE_DEF_SEL( accessor, symbol ) extern SEL s_k ## accessor; 58 #define _APPKIT_PRIVATE_DEF_CONST( type, symbol ) 59 60 61 #endif // NS_PRIVATE_IMPLEMENTATION 62 63 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 64 65 namespace NS::Private::Class { 66 67 _APPKIT_PRIVATE_DEF_CLS( NSApplication ); 68 _APPKIT_PRIVATE_DEF_CLS( NSRunningApplication ); 69 _APPKIT_PRIVATE_DEF_CLS( NSView ); 70 _APPKIT_PRIVATE_DEF_CLS( NSWindow ); 71 _APPKIT_PRIVATE_DEF_CLS( NSMenu ); 72 _APPKIT_PRIVATE_DEF_CLS( NSMenuItem ); 73 74 } // Class 75 76 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 77 78 namespace NS::Private::Selector 79 { 80 81 _APPKIT_PRIVATE_DEF_SEL( addItem_, 82 "addItem:" ); 83 84 _APPKIT_PRIVATE_DEF_SEL( addItemWithTitle_action_keyEquivalent_, 85 "addItemWithTitle:action:keyEquivalent:" ); 86 87 _APPKIT_PRIVATE_DEF_SEL( applicationDidFinishLaunching_, 88 "applicationDidFinishLaunching:" ); 89 90 _APPKIT_PRIVATE_DEF_SEL( applicationShouldTerminateAfterLastWindowClosed_, 91 "applicationShouldTerminateAfterLastWindowClosed:" ); 92 93 _APPKIT_PRIVATE_DEF_SEL( applicationWillFinishLaunching_, 94 "applicationWillFinishLaunching:" ); 95 96 _APPKIT_PRIVATE_DEF_SEL( close, 97 "close" ); 98 99 _APPKIT_PRIVATE_DEF_SEL( currentApplication, 100 "currentApplication" ); 101 102 _APPKIT_PRIVATE_DEF_SEL( keyEquivalentModifierMask, 103 "keyEquivalentModifierMask" ); 104 105 _APPKIT_PRIVATE_DEF_SEL( localizedName, 106 "localizedName" ); 107 108 _APPKIT_PRIVATE_DEF_SEL( sharedApplication, 109 "sharedApplication" ); 110 111 _APPKIT_PRIVATE_DEF_SEL( setDelegate_, 112 "setDelegate:" ); 113 114 _APPKIT_PRIVATE_DEF_SEL( setActivationPolicy_, 115 "setActivationPolicy:" ); 116 117 _APPKIT_PRIVATE_DEF_SEL( activateIgnoringOtherApps_, 118 "activateIgnoringOtherApps:" ); 119 120 _APPKIT_PRIVATE_DEF_SEL( run, 121 "run" ); 122 123 _APPKIT_PRIVATE_DEF_SEL( terminate_, 124 "terminate:" ); 125 126 _APPKIT_PRIVATE_DEF_SEL( initWithContentRect_styleMask_backing_defer_, 127 "initWithContentRect:styleMask:backing:defer:" ); 128 129 _APPKIT_PRIVATE_DEF_SEL( initWithFrame_, 130 "initWithFrame:" ); 131 132 _APPKIT_PRIVATE_DEF_SEL( initWithTitle_, 133 "initWithTitle:" ); 134 135 _APPKIT_PRIVATE_DEF_SEL( setContentView_, 136 "setContentView:" ); 137 138 _APPKIT_PRIVATE_DEF_SEL( makeKeyAndOrderFront_, 139 "makeKeyAndOrderFront:" ); 140 141 _APPKIT_PRIVATE_DEF_SEL( setKeyEquivalentModifierMask_, 142 "setKeyEquivalentModifierMask:" ); 143 144 _APPKIT_PRIVATE_DEF_SEL( setMainMenu_, 145 "setMainMenu:" ); 146 147 _APPKIT_PRIVATE_DEF_SEL( setSubmenu_, 148 "setSubmenu:" ); 149 150 _APPKIT_PRIVATE_DEF_SEL( setTitle_, 151 "setTitle:" ); 152 153 _APPKIT_PRIVATE_DEF_SEL( windows, 154 "windows" ); 155 156 } 157 158 //-------------------------------------------------------------------------------------------------------------------------------------------------------------