├── .gitignore ├── Cocoa++.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── Cocoa++.xccheckout ├── DESIGN PRINCIPALS.md ├── Eonil ├── LICENSE.md ├── Metadata └── Common.xcconfig ├── README.md ├── Sources └── Eonil │ └── Platform │ ├── Apple │ ├── AppKit │ │ ├── Application.h │ │ ├── Application.mm │ │ ├── Cell.h │ │ ├── Cell.mm │ │ ├── Color.h │ │ ├── Color.mm │ │ ├── Common.cpp │ │ ├── Common.h │ │ ├── Control.h │ │ ├── Control.mm │ │ ├── Cursor.h │ │ ├── Cursor.mm │ │ ├── Document.cpp │ │ ├── Document.h │ │ ├── DraggingDestination.h │ │ ├── DraggingDestination.mm │ │ ├── FileManager.h │ │ ├── FileManager.mm │ │ ├── Font.h │ │ ├── Font.mm │ │ ├── Image.h │ │ ├── Image.mm │ │ ├── ImageView.h │ │ ├── ImageView.mm │ │ ├── Menu.h │ │ ├── Menu.mm │ │ ├── Pasteboard.h │ │ ├── Pasteboard.mm │ │ ├── Responder.h │ │ ├── Responder.mm │ │ ├── ScrollView.h │ │ ├── ScrollView.mm │ │ ├── Scroller.h │ │ ├── Scroller.mm │ │ ├── SplitView.h │ │ ├── SplitView.mm │ │ ├── TableView.h │ │ ├── TableView.mm │ │ ├── Text.h │ │ ├── Text.mm │ │ ├── TextField.h │ │ ├── TextField.mm │ │ ├── TextView.h │ │ ├── TextView.mm │ │ ├── View.h │ │ ├── View.mm │ │ ├── Window.h │ │ ├── Window.mm │ │ ├── WindowController.h │ │ └── WindowController.mm │ ├── Cocoa.cpp │ ├── Cocoa.h │ ├── Common.h │ ├── Common.mm │ ├── CoreAnimation │ │ ├── Layer.h │ │ └── Layer.mm │ ├── CoreFoundation │ │ ├── Data.cpp │ │ ├── Data.h │ │ ├── String.cpp │ │ ├── String.h │ │ ├── Type.cpp │ │ └── Type.h │ ├── CoreGraphics │ │ ├── Color.cpp │ │ ├── Color.h │ │ ├── ColorSpace.cpp │ │ ├── ColorSpace.h │ │ ├── DataProvider.cpp │ │ ├── DataProvider.h │ │ ├── Image.cpp │ │ ├── Image.h │ │ ├── ImageDestination.cpp │ │ ├── ImageDestination.h │ │ ├── Rect.cpp │ │ └── Rect.h │ ├── Foundation │ │ ├── Array.h │ │ ├── Array.mm │ │ ├── Data.h │ │ ├── Data.mm │ │ ├── Date.h │ │ ├── Date.mm │ │ ├── Object.h │ │ ├── Object.mm │ │ ├── String.h │ │ ├── String.mm │ │ ├── URL.h │ │ └── URL.mm │ ├── ObjectiveC │ │ ├── Any.h │ │ ├── Any.mm │ │ ├── InternalRawStuffs │ │ │ ├── ClassTemplate.cpp │ │ │ ├── ClassTemplate.h │ │ │ ├── ErrorCheck.h │ │ │ └── ErrorCheck.mm │ │ ├── None.h │ │ └── None.mm │ └── UIKit │ │ ├── Application.cpp │ │ ├── Application.h │ │ ├── Color.cpp │ │ ├── Color.h │ │ ├── Common.cpp │ │ ├── Common.h │ │ ├── Control.cpp │ │ ├── Control.h │ │ ├── Responder.cpp │ │ ├── Responder.h │ │ ├── ScrollView.cpp │ │ ├── ScrollView.h │ │ ├── TextView.cpp │ │ ├── TextView.h │ │ ├── View.cpp │ │ ├── View.h │ │ ├── Window.cpp │ │ └── Window.h │ └── Debugging │ ├── Exception.cpp │ └── Exception.h ├── TestApp ├── Test1.cpp ├── Test1.h ├── TestApp-Prefix.pch └── main.cpp └── WEIRD STUFF EXPLANATIONS.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | xcuserdata 3 | build 4 | -------------------------------------------------------------------------------- /Cocoa++.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Cocoa++.xcodeproj/project.xcworkspace/xcshareddata/Cocoa++.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | E860D4C1-A08C-4205-A5CF-B0CF2E8BF871 9 | IDESourceControlProjectName 10 | Cocoa++ 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 0CBBAEF7-B6A5-4C23-BE9A-B9A296C79ADC 14 | https://github.com/Eonil/CommonRealtimeGameAlgorithms.git 15 | 40DBD4D2-3B8B-4F01-9959-437A799122B3 16 | https://github.com/Eonil/CocoaPlusPlus.git 17 | 18 | IDESourceControlProjectPath 19 | Cocoa++.xcodeproj/project.xcworkspace 20 | IDESourceControlProjectRelativeInstallPathDictionary 21 | 22 | 0CBBAEF7-B6A5-4C23-BE9A-B9A296C79ADC 23 | ../../../CommonRealtimeGameAlgorithms 24 | 40DBD4D2-3B8B-4F01-9959-437A799122B3 25 | ../.. 26 | 27 | IDESourceControlProjectURL 28 | https://github.com/Eonil/CocoaPlusPlus.git 29 | IDESourceControlProjectVersion 30 | 110 31 | IDESourceControlProjectWCCIdentifier 32 | 40DBD4D2-3B8B-4F01-9959-437A799122B3 33 | IDESourceControlProjectWCConfigurations 34 | 35 | 36 | IDESourceControlRepositoryExtensionIdentifierKey 37 | public.vcs.git 38 | IDESourceControlWCCIdentifierKey 39 | 40DBD4D2-3B8B-4F01-9959-437A799122B3 40 | IDESourceControlWCCName 41 | Cocoa++ 42 | 43 | 44 | IDESourceControlRepositoryExtensionIdentifierKey 45 | public.vcs.git 46 | IDESourceControlWCCIdentifierKey 47 | 0CBBAEF7-B6A5-4C23-BE9A-B9A296C79ADC 48 | IDESourceControlWCCName 49 | CommonRealtimeGameAlgorithms 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /DESIGN PRINCIPALS.md: -------------------------------------------------------------------------------- 1 | DESIGN PRINCIPALS 2 | ================= 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | - For convenience. Not for performance. 12 | 13 | This library is designed to provide better and earlier error check and organization. 14 | Not for performance. 15 | 16 | Major reason of this library is avoiding mistakes. Objective-C is too much mistake-prone 17 | language, and overriding a method by mistake is too easy, and there's no warning. 18 | As a result, managing those feature overriding are very hard. 19 | 20 | Also, encapsulation is hard in Objective-C. There's no private method, and all the classes 21 | are always public. No namespace. It's hard to structure complex program in hierarchical way. 22 | C++ can provide better way of program structuring. 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | - All wrapper classes are just thin wrappers around Objective-C object pointers. 34 | Conceptually, a class is something like this; 35 | 36 | typedef NSView* View; 37 | 38 | or something like this; 39 | 40 | class 41 | View 42 | { 43 | NSView* _raw_ptr{nullptr}; 44 | }; 45 | 46 | 47 | Then, copy is bare pointer copy, not a semantic deep copy. If you want to perform semantic copy, 48 | then you have to call `copy` method just like an Objective-C object. 49 | 50 | Unlike Objective-C classes, copying feature is not provided by default. Only appropriate classes 51 | will provide semantic copy method. 52 | 53 | Semantic equality is also same. Equality comparison operator just performs pointer equality check. 54 | And you need to call explicit equals method to perform semantic equality. 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | - Classes wrapping `CFType` objects are also just a pointer wrapper. 64 | Conceptually, a `CFType` wrappers are something like this; 65 | 66 | typedef CGColorRef Color; 67 | 68 | 69 | Or; 70 | 71 | class 72 | Color 73 | { 74 | CGColorRef _raw_ptr{nullptr}; 75 | }; 76 | 77 | `CFType` object wrappers performs automatic reference-counting. (yes, it works exactly like how 78 | Objective-C ARC works!) 79 | 80 | 81 | 82 | 83 | 84 | - Type Checks. 85 | `CFType` based classes are checked by imported CoreFoundation C symbols. 86 | Objective-C classes are not checked when creating (yet), but will be checked 87 | when calling any method. This is mainly to avoid importing Objective-C symbols. 88 | I hope to add type-checks when creating object instances. 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | - No toll-free bridging by default. 103 | Cocoa supports toll-free bridging between some CF types and some Cocoa classes. 104 | It seems possible to support toll-free bridging, but there're bunch of stuffs to care about to support 105 | the feature. So currently, I don't support it. 106 | 107 | 108 | 109 | - Direct constructors are allowed only on final classes. 110 | Constructor may cause hard-to-find bugs. Do not use them on intermediate classes. 111 | On intermediate classes, always use factory method. 112 | The best way is not instantiating intermediate classes. 113 | 114 | 115 | 116 | - No bi-directional roundtripping. 117 | If you created a Cocoa object using this library, the object is fully roundtrippable between C++ and Objective-C. 118 | Otherwise, some object will not be converted into corresponding C++ class. 119 | Because some classes are created in subclassed form for event handling and etc.. 120 | If you're not sure, just remember these rules. 121 | 122 | - Cast an Objective-C object into C++ class only if the object was created by C++ class. 123 | - Do not cast Objective-C object into C++ class if it was not created by C++ class. 124 | 125 | 126 | 127 | 128 | - No reflection. 129 | Though it is possible to expose Objective-C reflection facility into C++, but there's no C++ counterpart. 130 | I just decided not to expose reflection stuff. 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | - Every pointer wrappers passed by value-copy. 139 | 140 | Definition of function parameter type doesn't need to be known then compiling. 141 | Forward declaration is enough. Every Objective-C pointer wrappers will be passed by value-copy. 142 | 143 | As a result, inline object creation will become impossible — yes, that is not a goal of this library. 144 | Goal of this library is providing consistent and simple API. Objective-C object will never be passed 145 | as reference. Anyway, if there's a corresponding C++ type, it may can be passed as a `const&` to allow 146 | inline object creation. 147 | 148 | For example, there can be this sort of overloadings. 149 | 150 | auto test1(String) -> void; 151 | auto test1(std::string const&) -> void; 152 | 153 | But these are not allowed. 154 | 155 | auto test1(String const&) -> void; 156 | auto test1(String&) -> void; 157 | auto test1(String&&) -> void; 158 | 159 | Anyway pointing is allowed, and it represents weak reference. 160 | Pointer passing is usually used for delegate. 161 | 162 | auto setDelegate(Delegate*) -> void; 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | Keep it simple by decomposing each features 182 | ------------------------------------------- 183 | 184 | 185 | 186 | - Base classes are not exposed directly by default. 187 | 188 | To keep simplicity, all base class functionalities will not be exposed directly. 189 | Instead, classes may have `as~` series method to provide access to base class features. 190 | Where appropriate, some base class features may be exposed directly. This is fully case-by-case, 191 | and hiding is the default choice. 192 | 193 | 194 | 195 | - No direct overriding. 196 | 197 | Cocoa uses observer pattern primarily rather then overriding, and 198 | usually overriding is wrong pattern. In most cases we don't need method overriding. 199 | Anyway some ancient Cocoa classes are still using method overriding to implement observer 200 | pattern (which seems to be wrong), and those classes needs special treatment. 201 | 202 | I am currently using several different approaches to provide method overriding mechanism, 203 | but none of them are overriding C++ method directly. Every features will be separated into 204 | a separated observer class. Usually they will become a part of delegate object. I believe 205 | this is patching a design bugs of old Cocoa classes. 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | Observer Pattern Policy 220 | ----------------------- 221 | Cocoa is relying heavily on MVC/observer pattern. It's crucial to support observer pattern easily 222 | and correctly. 223 | 224 | In large, Cocoa uses a few different approaches on observing message. 225 | 226 | - Target-action. 227 | - Explicit messaging. (sending message selector to an object) 228 | - Delegate. 229 | - Subclassing and overriding. (including responder) 230 | - Notification. 231 | 232 | All these are relying on Objective-C dynamic messaging feature. 233 | 234 | - Target-action. 235 | Subclass the Objective-C object, add C++ lambda variable. 236 | Catch event by target itself, and call the lambda. 237 | 238 | - Explicit messaging. 239 | **NO SUPPORT** I think there's some possible trick, but too dirty. 240 | 241 | - Delegate. 242 | Make an pure virtual class (interface) which declares all delegate methods. 243 | Subclass `Any` class and inherits all needed interfaces. 244 | Delegate is set by pointer to represent no-ownership. 245 | 246 | - Subclassing and overriding. 247 | Make a separated class for overriden class. Install hools on all possible methods. 248 | Take lambda table which are mapped to each methods. (see `OverridableView` class). 249 | 250 | - Responder. 251 | Resolve just like subclassing case. 252 | 253 | - Notification. 254 | Use lambda. 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | -------------------------------------------------------------------------------- /Eonil: -------------------------------------------------------------------------------- 1 | Sources/Eonil -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Hoon H. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /Metadata/Common.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Common.xcconfig 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/20. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | OTHER_CFLAGS = -Winline -Weverything -Wno-c++98-compat -Wno-direct-ivar-access -Wno-mismatched-tags -Wno-c++98-compat-pedantic -Wno-objc-missing-property-synthesis -Wno-padded 10 | OTHER_CPLUSPLUSFLAGS = $OTHER_CFLAGS 11 | WARNING_CFLAGS = $OTHER_CFLAGS 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | README 2 | ====== 3 | 2014/04/25 4 | Hoon H. 5 | 6 | 7 | 8 | 9 | 10 | 11 | What is this 12 | ------------ 13 | This is a thin C++ wrapper around Cocoa. 14 | Primary goal is providing these; 15 | 16 | - Namespace, inline member definition, and private members. 17 | - Native and fast integration of Cocoa features into C++. 18 | - More and better error detection (runtime assertion, type-check) 19 | - More robust and structured program by using C++. (less dynamics, better abstraction) 20 | - In most cases, no actual extra performance/memory loss. (essentially just a wrapped pointer) 21 | But extra cost for event handling structure. 22 | - Keep original API names and styles as much as possible. 23 | 24 | It's far easier to design and maintain a correct program in C++. 25 | 26 | 27 | 28 | 29 | 30 | 31 | Please don't be serious on this! This is just a personal project ;) 32 | 33 | 34 | 35 | 36 | 37 | License 38 | ------- 39 | This library is licensed under MIT License. -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Application.h: -------------------------------------------------------------------------------- 1 | // 2 | // Application.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "Responder.h" 12 | #include "DraggingDestination.h" 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | class Menu; 16 | 17 | 18 | 19 | 20 | 21 | /*! 22 | Wraps `NSApplication`. 23 | */ 24 | class 25 | Application : Responder 26 | { 27 | public: 28 | struct 29 | Delegate : Any 30 | { 31 | Delegate(); 32 | Delegate(Delegate const&) = delete; 33 | Delegate(Delegate&&) = delete; 34 | virtual ~Delegate(); 35 | 36 | virtual inline auto applicationWillFinishLaunching() -> void {} 37 | virtual inline auto applicationDidFinishLaunching() -> void {} 38 | }; 39 | 40 | public: 41 | using Responder::Responder; 42 | 43 | static auto sharingApplication() -> Application; 44 | 45 | public: 46 | auto delegate() const -> Delegate*; 47 | auto setDelegate(Delegate*) -> void; 48 | auto unsetDelegate() -> void; 49 | 50 | auto setMainMenu(Menu) -> void; 51 | 52 | auto run() -> void; 53 | auto stop() -> void; 54 | auto terminate() -> void; 55 | 56 | public: 57 | auto asResponder() const -> Responder const&; 58 | auto asResponder() -> Responder&; 59 | }; 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 71 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Application.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Application.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Application.h" 10 | #include "Menu.h" 11 | using namespace Eonil::CocoaCPP; 12 | using namespace Eonil::CocoaCPP::Foundation; 13 | using namespace Eonil::CocoaCPP::AppKit; 14 | 15 | @interface ____Eonil_Cocoa_AppDelegate : NSObject 16 | @end 17 | @implementation ____Eonil_Cocoa_AppDelegate 18 | { 19 | @public 20 | struct 21 | { 22 | Application::Delegate* cpp_delegate {nullptr}; 23 | } 24 | slots; 25 | } 26 | - (void)applicationWillFinishLaunching:(NSNotification *)notification 27 | { 28 | slots.cpp_delegate->applicationWillFinishLaunching(); 29 | } 30 | - (void)applicationDidFinishLaunching:(NSNotification *)notification 31 | { 32 | slots.cpp_delegate->applicationDidFinishLaunching(); 33 | } 34 | @end 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 44 | 45 | 46 | 47 | Application::Delegate::Delegate() : Any([[____Eonil_Cocoa_AppDelegate alloc] init]) 48 | { 49 | auto self = get_objc_object<____Eonil_Cocoa_AppDelegate>(); 50 | self->slots.cpp_delegate = this; 51 | } 52 | Application::Delegate::~Delegate() 53 | { 54 | } 55 | 56 | 57 | 58 | 59 | auto 60 | Application::sharingApplication() -> Application 61 | { 62 | return [NSApplication sharedApplication]; 63 | } 64 | 65 | 66 | 67 | auto 68 | Application::delegate() const -> Delegate* 69 | { 70 | auto self = get_objc_object(); 71 | ____Eonil_Cocoa_AppDelegate* d1 = [self delegate]; 72 | Application::Delegate* d2 = d1->slots.cpp_delegate; 73 | 74 | return d2; 75 | } 76 | auto 77 | Application::setDelegate(Delegate *o) -> void 78 | { 79 | __unsafe_unretained NSWindow* self = operator __unsafe_unretained id(); 80 | [self setDelegate:*o]; 81 | } 82 | auto 83 | Application::unsetDelegate() -> void 84 | { 85 | __unsafe_unretained NSWindow* self = operator __unsafe_unretained id(); 86 | [self setDelegate:nil]; 87 | } 88 | 89 | 90 | auto 91 | Application::setMainMenu(Eonil::CocoaCPP::AppKit::Menu o) -> void 92 | { 93 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSMenu); 94 | 95 | //// 96 | 97 | auto self = get_objc_object(); 98 | [self setMainMenu:o]; 99 | } 100 | 101 | 102 | 103 | 104 | 105 | 106 | auto 107 | Application:: 108 | run() -> void 109 | { 110 | auto& self = *this; 111 | [self run]; 112 | } 113 | auto 114 | Application:: 115 | stop() -> void 116 | { 117 | auto& self = *this; 118 | [self stop:nil]; 119 | } 120 | auto 121 | Application:: 122 | terminate() -> void 123 | { 124 | auto self = get_objc_object(); 125 | [self terminate:nil]; 126 | } 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | auto 135 | Application::asResponder() const -> Responder const& 136 | { 137 | return *this; 138 | } 139 | auto 140 | Application::asResponder() -> Responder& 141 | { 142 | return *this; 143 | } 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 160 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Cell.h: -------------------------------------------------------------------------------- 1 | // 2 | // Cell.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | 18 | class 19 | Cell : public Object 20 | { 21 | using BASE = Object; 22 | protected: 23 | using BASE::BASE; 24 | 25 | public: 26 | auto stringValue() const -> String; 27 | auto setStringValue(String) -> void; 28 | auto setStringValue(String const&) -> void; 29 | }; 30 | 31 | 32 | 33 | 34 | 35 | class 36 | ActionCell : public Cell 37 | { 38 | using BASE = Cell; 39 | protected: 40 | using BASE::BASE; 41 | }; 42 | 43 | 44 | 45 | 46 | 47 | class 48 | TextFieldCell : public ActionCell 49 | { 50 | using BASE = ActionCell; 51 | protected: 52 | using BASE::BASE; 53 | }; 54 | 55 | 56 | 57 | 58 | 59 | class 60 | TableHeaderCell final : public TextFieldCell 61 | { 62 | using BASE = TextFieldCell; 63 | public: 64 | using BASE::BASE; 65 | 66 | public: 67 | TableHeaderCell(); 68 | }; 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 78 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Cell.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Cell.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Cell.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | 16 | 17 | auto 18 | Cell:: 19 | stringValue() const -> String 20 | { 21 | auto self = get_objc_object(); 22 | return [self stringValue]; 23 | } 24 | auto 25 | Cell:: 26 | setStringValue(String o) -> void 27 | { 28 | auto self = get_objc_object(); 29 | [self setStringValue:o]; 30 | } 31 | auto 32 | Cell:: 33 | setStringValue(const String &o) -> void 34 | { 35 | auto self = get_objc_object(); 36 | [self setStringValue:o]; 37 | } 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | TableHeaderCell::TableHeaderCell() : BASE([[NSTableHeaderCell alloc] init]) 46 | { 47 | } 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Color.h: -------------------------------------------------------------------------------- 1 | // 2 | // Color.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | class 21 | Color final : public Foundation::Object 22 | { 23 | public: 24 | struct 25 | Components 26 | { 27 | Float red {}; 28 | Float green {}; 29 | Float blue {}; 30 | Float alpha {}; 31 | 32 | Components() 33 | { 34 | } 35 | Components(Float red, Float green, Float blue, Float alpha) : red(red), green(green), blue(blue), alpha(alpha) 36 | { 37 | } 38 | }; 39 | 40 | public: 41 | static auto color(Components const&) -> Color; 42 | 43 | public: 44 | using Object::Object; 45 | 46 | public: 47 | auto components() const -> Components; 48 | auto CGColor() const -> CoreGraphics::Color; 49 | }; 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 62 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Color.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Color.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Color.h" 10 | #include "../CoreGraphics/Color.h" 11 | 12 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | auto 23 | Color::color(Eonil::CocoaCPP::AppKit::Color::Components const& cs) -> Color 24 | { 25 | return {[NSColor colorWithDeviceRed:cs.red green:cs.green blue:cs.blue alpha:cs.alpha]}; 26 | } 27 | 28 | auto 29 | Color::components() const -> Components 30 | { 31 | auto self = get_objc_object(); 32 | 33 | Components cs {}; 34 | [self getRed:&cs.red green:&cs.green blue:&cs.blue alpha:&cs.alpha]; 35 | return cs; 36 | } 37 | 38 | auto 39 | Color::CGColor() const -> CoreGraphics::Color 40 | { 41 | auto self = get_objc_object(); 42 | 43 | return CoreGraphics::Color([self CGColor]); 44 | } 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Common.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Common.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Common.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | DelegateBase::~DelegateBase() 12 | { 13 | } 14 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 15 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Common.h: -------------------------------------------------------------------------------- 1 | // 2 | // Common.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | #include "../Foundation/Data.h" 13 | #include "../Foundation/String.h" 14 | #include "../Foundation/Array.h" 15 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 16 | 17 | using Object = Foundation::Object; 18 | using Data = Foundation::Data; 19 | using String = Foundation::String; 20 | using Array = Foundation::AnytypeArray; 21 | 22 | struct 23 | NonInstantiatable 24 | { 25 | NonInstantiatable() = delete; 26 | }; 27 | 28 | class Responder; 29 | class View; 30 | class Control; 31 | class Text; 32 | class TextView; 33 | class ScrollView; 34 | class SplitView; 35 | class Window; 36 | class WindowController; 37 | class Document; 38 | class DocumentController; 39 | 40 | class 41 | DelegateBase : public Any 42 | { 43 | public: 44 | using Any::Any; 45 | virtual ~DelegateBase(); 46 | }; 47 | 48 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 49 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Control.h: -------------------------------------------------------------------------------- 1 | // 2 | // Control.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "View.h" 12 | 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | class 21 | Control : public View 22 | { 23 | public: 24 | using View::View; 25 | }; 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Control.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Control.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Control.h" 10 | 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 29 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Cursor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Cursor.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | class 18 | Cursor final : public Object 19 | { 20 | using base = Object; 21 | public: 22 | using base::base; 23 | 24 | public: 25 | struct 26 | Utility 27 | { 28 | Utility() = delete; 29 | 30 | //// 31 | 32 | static auto hide() -> void; 33 | static auto unhide() -> void; 34 | 35 | static auto setHideUntilMouseMove(bool const) -> void; 36 | 37 | //// 38 | 39 | static auto current() -> Cursor; 40 | static auto currentSystem() -> Cursor; 41 | 42 | //// 43 | 44 | static auto arrow() -> Cursor; 45 | static auto IBeam() -> Cursor; 46 | static auto IBeamForVerticalLayout() -> Cursor; 47 | static auto crossHair() -> Cursor; 48 | 49 | /*! 50 | @todo 51 | There're many more. Add when you needed... 52 | */ 53 | }; 54 | }; 55 | 56 | 57 | 58 | 59 | 60 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 61 | 62 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Cursor.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Cursor.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Cursor.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | auto 19 | Cursor::Utility:: 20 | hide() -> void 21 | { 22 | [NSCursor hide]; 23 | } 24 | auto 25 | Cursor::Utility:: 26 | unhide() -> void 27 | { 28 | [NSCursor unhide]; 29 | } 30 | auto 31 | Cursor::Utility:: 32 | setHideUntilMouseMove(const bool o) -> void 33 | { 34 | [NSCursor setHiddenUntilMouseMoves:toOBJC(o)]; 35 | } 36 | 37 | 38 | 39 | auto 40 | Cursor::Utility:: 41 | current() -> Cursor 42 | { 43 | return [NSCursor currentCursor]; 44 | } 45 | auto 46 | Cursor::Utility:: 47 | currentSystem() -> Cursor 48 | { 49 | return [NSCursor currentSystemCursor]; 50 | } 51 | 52 | 53 | 54 | auto 55 | Cursor::Utility:: 56 | arrow() -> Cursor 57 | { 58 | return [NSCursor arrowCursor]; 59 | } 60 | auto 61 | Cursor::Utility:: 62 | IBeam() -> Cursor 63 | { 64 | return [NSCursor IBeamCursor]; 65 | } 66 | auto 67 | Cursor::Utility:: 68 | crossHair() -> Cursor 69 | { 70 | return [NSCursor crosshairCursor]; 71 | } 72 | auto 73 | Cursor::Utility:: 74 | IBeamForVerticalLayout() -> Cursor 75 | { 76 | return [NSCursor IBeamCursorForVerticalLayout]; 77 | } 78 | 79 | 80 | 81 | 82 | 83 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 84 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Document.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Document.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Document.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 31 | 32 | 33 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Document.h: -------------------------------------------------------------------------------- 1 | // 2 | // Document.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | class 22 | Document : public Object 23 | { 24 | using super = Object; 25 | 26 | public: 27 | using super::super; 28 | 29 | public: 30 | }; 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 43 | 44 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/DraggingDestination.h: -------------------------------------------------------------------------------- 1 | // 2 | // DraggingDestination.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | 11 | #include "../Common.h" 12 | #include "../ObjectiveC/Any.h" 13 | 14 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | enum class 23 | DRAG_OPERATION : UInteger 24 | { 25 | NONE = 0, 26 | COPY = 1, 27 | LINK = 2, 28 | GENERIC = 4, 29 | PRIVATE = 8, 30 | MOVE = 16, 31 | DELETE = 32, 32 | EVERY = UIntegerMax, 33 | }; 34 | 35 | 36 | class 37 | DraggingInfo : protected Any 38 | { 39 | public: 40 | using Any::Any; 41 | 42 | public: 43 | 44 | public: 45 | auto draggingPasteboard() const -> Pasteboard; 46 | // auto draggingSequenceNumber() const -> Integer; 47 | auto draggingSource() const -> Any; 48 | }; 49 | 50 | 51 | 52 | 53 | /*! 54 | Wraps `NSDraggingDestination` protocol. 55 | */ 56 | struct 57 | DraggingDestination 58 | { 59 | virtual ~DraggingDestination(); 60 | 61 | virtual auto draggingEntered(DraggingInfo info) -> DRAG_OPERATION { return DRAG_OPERATION::NONE; } 62 | virtual auto draggingUpdated(DraggingInfo info) -> DRAG_OPERATION { return DRAG_OPERATION::NONE; } 63 | virtual auto draggingEnded(DraggingInfo info) -> void {} 64 | virtual auto draggingExited(DraggingInfo info) -> void {} 65 | 66 | virtual auto prepareForDragOperation(DraggingInfo info) -> bool { return false; } 67 | virtual auto performDragOperation(DraggingInfo info) -> bool { return false; } 68 | virtual auto concludeDragOperation(DraggingInfo info) -> void {} 69 | 70 | virtual auto updateDraggingItemsForDrag(DraggingInfo info) -> void {} 71 | }; 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 82 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/DraggingDestination.mm: -------------------------------------------------------------------------------- 1 | // 2 | // DraggingDestination.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "DraggingDestination.h" 10 | #include "Pasteboard.h" 11 | 12 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | auto 19 | DraggingInfo::draggingPasteboard() const -> Pasteboard 20 | { 21 | id self = *this; 22 | return [self draggingPasteboard]; 23 | } 24 | auto 25 | DraggingInfo::draggingSource() const -> Any 26 | { 27 | id self = *this; 28 | return [self draggingSource]; 29 | } 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | DraggingDestination::~DraggingDestination() 40 | { 41 | } 42 | 43 | 44 | 45 | 46 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 47 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/FileManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // FileManager.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | #include "../Foundation/Date.h" 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | class 21 | FileManager : public Foundation::Object 22 | { 23 | //public: 24 | // FileManager(FileManager const&) = delete; 25 | // FileManager(FileManager&&) = delete; 26 | 27 | public: 28 | // static auto defaultManager() -> FileManager; // Disabled because there's some unknown memory leak. I will enabled this again as soon as I fix the leak. 29 | static auto fileManager() -> FileManager; 30 | 31 | public: 32 | class 33 | DirectoryEnumerator : public Foundation::Object 34 | { 35 | public: 36 | using Object::Object; 37 | 38 | auto nextObject() -> Foundation::String; 39 | 40 | auto level() const -> UInteger; 41 | auto skipDescendants() -> void; 42 | }; 43 | 44 | class 45 | Attributes : public Object 46 | { 47 | friend class FileManager; 48 | Attributes(id infoDictionary); 49 | 50 | public: 51 | Attributes() = delete; 52 | 53 | auto creationDate() const -> Foundation::Date; 54 | auto modificationDate() const -> Foundation::Date; 55 | auto size() const -> uint64_t; 56 | }; 57 | 58 | public: 59 | auto fileExistsAtPath(Foundation::String) const -> bool; 60 | auto fileExistsAtPathAsDirectory(Foundation::String) const -> bool; 61 | auto attributesOfItemAtPath(Foundation::String path) const -> Attributes; 62 | 63 | auto enumeratorAtPath(Foundation::String path) const -> DirectoryEnumerator; 64 | 65 | private: 66 | using Object::Object; 67 | }; 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 80 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/FileManager.mm: -------------------------------------------------------------------------------- 1 | // 2 | // FileManager.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "FileManager.h" 10 | #include "../Foundation/String.h" 11 | #include "../Foundation/Date.h" 12 | 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | using namespace Foundation; 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | FileManager::Attributes::Attributes(id dict1) : Object(dict1) 34 | { 35 | } 36 | auto 37 | FileManager::Attributes::creationDate() const -> Date 38 | { 39 | auto self = get_objc_object(); 40 | EONIL_COCOA_ASSERT_OBJC_TYPE(self[NSFileCreationDate], NSDate); 41 | return self[NSFileCreationDate]; 42 | } 43 | auto 44 | FileManager::Attributes::modificationDate() const -> Date 45 | { 46 | auto self = get_objc_object(); 47 | EONIL_COCOA_ASSERT_OBJC_TYPE(self[NSFileModificationDate], NSDate); 48 | return self[NSFileModificationDate]; 49 | } 50 | auto 51 | FileManager::Attributes::size() const -> uint64_t 52 | { 53 | auto self = get_objc_object(); 54 | EONIL_COCOA_ASSERT_OBJC_TYPE(self[NSFileSize], NSNumber); 55 | return [self[NSFileSize] unsignedLongLongValue]; 56 | } 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | auto 72 | FileManager::DirectoryEnumerator::nextObject() -> Foundation::String 73 | { 74 | @autoreleasepool 75 | { 76 | auto self = get_objc_object(); 77 | id obj1 = [self nextObject]; 78 | 79 | return obj1; 80 | } 81 | } 82 | auto 83 | FileManager::DirectoryEnumerator::level() const -> UInteger 84 | { 85 | auto self = get_objc_object(); 86 | return [self level]; 87 | } 88 | auto 89 | FileManager::DirectoryEnumerator::skipDescendants() -> void 90 | { 91 | auto self = get_objc_object(); 92 | [self skipDescendants]; 93 | } 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | //auto 105 | //FileManager::defaultManager() -> FileManager 106 | //{ 107 | // return [NSFileManager defaultManager]; 108 | //} 109 | auto 110 | FileManager::fileManager() -> FileManager 111 | { 112 | return [[NSFileManager alloc] init]; 113 | } 114 | 115 | 116 | auto 117 | FileManager::fileExistsAtPath(Foundation::String o) const -> bool 118 | { 119 | auto self = get_objc_object(); 120 | return toCPP([self fileExistsAtPath:o]); 121 | } 122 | auto 123 | FileManager::fileExistsAtPathAsDirectory(Foundation::String o) const -> bool 124 | { 125 | auto self = get_objc_object(); 126 | BOOL isdir = NO; 127 | BOOL res1 = [self fileExistsAtPath:o isDirectory:&isdir]; 128 | return toCPP(res1 && isdir); 129 | } 130 | auto 131 | FileManager::attributesOfItemAtPath(Foundation::String path) const -> Attributes 132 | { 133 | auto self = get_objc_object(); 134 | 135 | //// 136 | 137 | NSError* err1 = nil; 138 | NSDictionary* att1 = [self attributesOfItemAtPath:path error:&err1]; 139 | 140 | return att1; 141 | } 142 | 143 | auto 144 | FileManager::enumeratorAtPath(Foundation::String path) const -> DirectoryEnumerator 145 | { 146 | @autoreleasepool 147 | { 148 | auto self = get_objc_object(); 149 | auto direnum = [self enumeratorAtPath:path]; 150 | 151 | return DirectoryEnumerator(direnum); 152 | } 153 | } 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 165 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Font.h: -------------------------------------------------------------------------------- 1 | // 2 | // Font.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Font.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Font.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Font.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 16 | 17 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Image.h: -------------------------------------------------------------------------------- 1 | // 2 | // Image.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | class 21 | Image : public Foundation::Object 22 | { 23 | public: 24 | using Object::Object; 25 | 26 | public: 27 | static auto imageWithSize(Size) -> Image; 28 | static auto image(CoreGraphics::Image) -> Image; 29 | }; 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Image.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Image.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Image.h" 10 | #include "../CoreGraphics/Rect.h" 11 | #include "../CoreGraphics/Image.h" 12 | 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | auto 19 | Image::imageWithSize(Size o) -> Image 20 | { 21 | return [[NSImage alloc] initWithSize:o]; 22 | } 23 | 24 | auto 25 | Image::image(CoreGraphics::Image image) -> Image 26 | { 27 | return [[NSImage alloc] initWithCGImage:image size:CGSizeZero]; 28 | } 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/ImageView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ImageView.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "Control.h" 12 | 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | /*! 20 | @note 21 | `NSImageView` registers itself as a dragging destination by default. 22 | This class removes the behavior, to become just like any other plain views. 23 | If you want to make it droppable for images, register these types. 24 | 25 | [NSImage imagePasteboardTypes] 26 | 27 | */ 28 | class 29 | ImageView : public Control 30 | { 31 | public: 32 | using Control::Control; 33 | 34 | public: 35 | static auto imageView() -> ImageView; 36 | 37 | public: 38 | auto image() const -> Image; 39 | auto setImage(Image) -> void; 40 | }; 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 50 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/ImageView.mm: -------------------------------------------------------------------------------- 1 | // 2 | // ImageView.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "ImageView.h" 10 | #include "Image.h" 11 | 12 | 13 | 14 | 15 | 16 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 17 | 18 | 19 | auto 20 | ImageView::imageView() -> ImageView 21 | { 22 | auto self = [[NSImageView alloc] init]; 23 | [self unregisterDraggedTypes]; 24 | return self; 25 | } 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | auto 37 | ImageView::image() const -> Image 38 | { 39 | auto self = get_objc_object(); 40 | return [self image]; 41 | } 42 | auto 43 | ImageView::setImage(Eonil::CocoaCPP::AppKit::Image o) -> void 44 | { 45 | auto self = get_objc_object(); 46 | [self setImage:o]; 47 | } 48 | 49 | 50 | 51 | 52 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Menu.h: -------------------------------------------------------------------------------- 1 | // 2 | // Menu.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | class Menu; 19 | class MenuItem; 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | /*! 31 | Wraps `NSMenu`. 32 | */ 33 | class 34 | Menu : public Foundation::Object 35 | { 36 | public: 37 | using Foundation::Object::Object; 38 | 39 | auto addItem(MenuItem) -> void; 40 | 41 | public: 42 | static auto menu() -> Menu; 43 | }; 44 | 45 | 46 | 47 | 48 | 49 | 50 | /*! 51 | Wraps `NSMenuItem`. 52 | 53 | @warning 54 | You cannot use this class to examine existing Objective-C object instances. 55 | This class can be used only for objects craeted by this class. 56 | */ 57 | class 58 | MenuItem : public Foundation::Object 59 | { 60 | public: 61 | using ACTION = std::function; 62 | 63 | public: 64 | using Foundation::Object::Object; 65 | 66 | auto setTitle(Foundation::String) -> void; 67 | auto setKeyEquivalent(Foundation::String) -> void; 68 | auto setSubmenu(Menu) -> void; 69 | auto setAction(ACTION) -> void; // Action will be copied. 70 | 71 | public: 72 | static auto menuItem() -> MenuItem; 73 | static auto menuItem(Foundation::String const& title, ACTION const& action, Foundation::String const& keyEquivalent) -> MenuItem; 74 | }; 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 83 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Menu.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Menu.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Menu.h" 10 | #include "../Foundation/String.h" 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | 18 | auto 19 | Menu::addItem(MenuItem o) -> void 20 | { 21 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSMenuItem); 22 | 23 | //// 24 | 25 | auto self = get_objc_object(); 26 | [self addItem:o]; 27 | } 28 | 29 | auto 30 | Menu::menu() -> Menu 31 | { 32 | return [[NSMenu alloc] init]; 33 | } 34 | 35 | 36 | 37 | 38 | 39 | 40 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 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 | @interface ____Eonil_Cocoa_MenuItem_2 : NSMenuItem 71 | - (void)____on_action:(id)sender; 72 | @end 73 | @implementation ____Eonil_Cocoa_MenuItem_2 74 | { 75 | @public 76 | std::function action; 77 | } 78 | - (void)____on_action:(id)sender 79 | { 80 | using namespace Eonil::Platform::Debugging; 81 | 82 | if (USE_EXCEPTION_CHECKINGS) 83 | { 84 | error_if(action == nullptr, "Menu has no action closure. It is not harmful, but very likely to be a bug."); 85 | } 86 | 87 | //// 88 | 89 | if (action != nullptr) 90 | { 91 | action(); 92 | } 93 | } 94 | @end 95 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 96 | using MENU_ITEM = ____Eonil_Cocoa_MenuItem_2; 97 | 98 | auto 99 | MenuItem::setTitle(Foundation::String o) -> void 100 | { 101 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSString); 102 | 103 | //// 104 | 105 | auto self = get_objc_object(); 106 | [self setTitle:o]; 107 | } 108 | auto 109 | MenuItem::setKeyEquivalent(Foundation::String o) -> void 110 | { 111 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSString); 112 | 113 | //// 114 | 115 | auto self = get_objc_object(); 116 | [self setKeyEquivalent:o]; 117 | } 118 | auto 119 | MenuItem::setSubmenu(Eonil::CocoaCPP::AppKit::Menu o) -> void 120 | { 121 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSMenu); 122 | 123 | //// 124 | 125 | auto self = get_objc_object(); 126 | [self setSubmenu:o]; 127 | } 128 | auto 129 | MenuItem::setAction(ACTION o) -> void 130 | { 131 | auto self = get_objc_object(); 132 | self->action = o; 133 | } 134 | 135 | auto 136 | MenuItem::menuItem() -> MenuItem 137 | { 138 | MENU_ITEM* item1 = [[MENU_ITEM alloc] init]; 139 | [item1 setTarget:item1]; 140 | [item1 setAction:@selector(____on_action:)]; 141 | return item1; 142 | } 143 | auto 144 | MenuItem::menuItem(const Foundation::String &title, const ACTION &action, const Foundation::String &keyEquivalent) -> MenuItem 145 | { 146 | MENU_ITEM* item1 = menuItem(); 147 | item1->action = action; 148 | [item1 setTitle:title]; 149 | [item1 setKeyEquivalent:keyEquivalent]; 150 | return item1; 151 | } 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 160 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Pasteboard.h: -------------------------------------------------------------------------------- 1 | // 2 | // Pasteboard.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "../Foundation/Object.h" 12 | 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | class 22 | PasteboardItem : protected Foundation::Object 23 | { 24 | public: 25 | using Object::Object; 26 | 27 | operator __unsafe_unretained id() const; 28 | 29 | public: 30 | auto types() const -> Foundation::SpecificTypeArray; //! Returns UTI strings. 31 | auto dataForType(String const& type) const -> Foundation::Data; 32 | auto stringForType(String const& type) const -> String; 33 | }; 34 | 35 | 36 | 37 | 38 | /*! 39 | Wraps `NSPasteboard`. 40 | */ 41 | class 42 | Pasteboard : protected Foundation::Object 43 | { 44 | public: 45 | using Object::Object; 46 | 47 | public: 48 | struct 49 | Type 50 | { 51 | static auto string() -> String; 52 | static auto PDF() -> String; 53 | static auto TIFF() -> String; 54 | static auto PNG() -> String; 55 | static auto RTF() -> String; 56 | static auto RTFD() -> String; 57 | static auto HTML() -> String; 58 | static auto tabularText() -> String; 59 | static auto font() -> String; 60 | static auto ruler() -> String; 61 | static auto color() -> String; 62 | static auto sound() -> String; 63 | static auto multipleTextSelection() -> String; 64 | static auto findPanelSearchOptions() -> String; 65 | }; 66 | 67 | public: 68 | auto pasteboardItems() const -> Foundation::SpecificTypeArray; 69 | }; 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 81 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Pasteboard.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Pasteboard.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Pasteboard.h" 10 | #include "../Foundation/String.h" 11 | #include "../Foundation/Array.h" 12 | #include "../Foundation/Data.h" 13 | 14 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 15 | 16 | using namespace Foundation; 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | PasteboardItem::operator __unsafe_unretained id() const 30 | { 31 | return get_objc_object(); 32 | } 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | auto 43 | PasteboardItem::types() const -> SpecificTypeArray 44 | { 45 | auto self = get_objc_object(); 46 | return [self types]; 47 | } 48 | auto 49 | PasteboardItem::dataForType(const Foundation::String &type) const -> Data 50 | { 51 | auto self = get_objc_object(); 52 | return [self dataForType:type]; 53 | } 54 | auto 55 | PasteboardItem::stringForType(const Foundation::String &type) const -> String 56 | { 57 | auto self = get_objc_object(); 58 | return [self stringForType:type]; 59 | } 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | auto 70 | Pasteboard::Type::string() -> String 71 | { 72 | return String{NSPasteboardTypeString}; 73 | } 74 | auto 75 | Pasteboard::Type::PDF() -> String 76 | { 77 | return String{NSPasteboardTypePDF}; 78 | } 79 | auto 80 | Pasteboard::Type::TIFF() -> String 81 | { 82 | return String{NSPasteboardTypeTIFF}; 83 | } 84 | auto 85 | Pasteboard::Type::PNG() -> String 86 | { 87 | return String{NSPasteboardTypePNG}; 88 | } 89 | auto 90 | Pasteboard::Type::RTF() -> String 91 | { 92 | return String{NSPasteboardTypeRTF}; 93 | } 94 | auto 95 | Pasteboard::Type::RTFD() -> String 96 | { 97 | return String{NSPasteboardTypeRTFD}; 98 | } 99 | auto 100 | Pasteboard::Type::HTML() -> String 101 | { 102 | return String{NSPasteboardTypeHTML}; 103 | } 104 | auto 105 | Pasteboard::Type::tabularText() -> String 106 | { 107 | return String{NSPasteboardTypeTabularText}; 108 | } 109 | auto 110 | Pasteboard::Type::font() -> String 111 | { 112 | return String{NSPasteboardTypeFont}; 113 | } 114 | auto 115 | Pasteboard::Type::ruler() -> String 116 | { 117 | return String{NSPasteboardTypeRuler}; 118 | } 119 | auto 120 | Pasteboard::Type::color() -> String 121 | { 122 | return String{NSPasteboardTypeColor}; 123 | } 124 | auto 125 | Pasteboard::Type::sound() -> String 126 | { 127 | return String{NSPasteboardTypeSound}; 128 | } 129 | auto 130 | Pasteboard::Type::multipleTextSelection() -> String 131 | { 132 | return String{NSPasteboardTypeMultipleTextSelection}; 133 | } 134 | auto 135 | Pasteboard::Type::findPanelSearchOptions() -> String 136 | { 137 | return String{NSPasteboardTypeFindPanelSearchOptions}; 138 | } 139 | 140 | 141 | 142 | 143 | 144 | 145 | auto 146 | Pasteboard::pasteboardItems() const -> SpecificTypeArray 147 | { 148 | auto self = get_objc_object(); 149 | return [self pasteboardItems]; 150 | } 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 161 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Responder.h: -------------------------------------------------------------------------------- 1 | // 2 | // Responder.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | /*! 18 | Wraps `NSResponder`. 19 | Take care that you have to order to show the window. 20 | */ 21 | class 22 | Responder : public Object 23 | { 24 | using super = Object; 25 | 26 | public: 27 | using super::super; 28 | }; 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Responder.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Responder.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Responder.h" 10 | 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | //Responder::Responder() : Object([[NSResponder alloc] init]) 18 | //{ 19 | //} 20 | //Responder::Responder(id o) : Object(o) 21 | //{ 22 | // EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSResponder); 23 | //} 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/ScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ScrollView.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "View.h" 12 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | 19 | class 20 | ScrollView : public View 21 | { 22 | using super = View; 23 | 24 | public: 25 | struct 26 | Parameters 27 | { 28 | struct 29 | { 30 | bool vertical = false; 31 | bool horizontal = false; 32 | } 33 | scrollers{}; 34 | 35 | View document = nullptr; 36 | }; 37 | 38 | public: 39 | using super::super; 40 | 41 | public: 42 | auto setDocumentView(View) -> void; 43 | 44 | public: 45 | static auto scrollView() -> ScrollView; 46 | static auto scrollViewWithParameters(Parameters) -> ScrollView; 47 | }; 48 | 49 | 50 | 51 | 52 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/ScrollView.mm: -------------------------------------------------------------------------------- 1 | // 2 | // ScrollView.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "ScrollView.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | 16 | auto 17 | ScrollView:: 18 | setDocumentView(Eonil::CocoaCPP::AppKit::View o) -> void 19 | { 20 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSView); 21 | 22 | //// 23 | 24 | auto self = get_objc_object(); 25 | [self setDocumentView:o]; 26 | } 27 | 28 | 29 | auto 30 | ScrollView:: 31 | scrollView() -> ScrollView 32 | { 33 | return scrollViewWithParameters({}); 34 | } 35 | auto 36 | ScrollView:: 37 | scrollViewWithParameters(Eonil::CocoaCPP::AppKit::ScrollView::Parameters p1) -> ScrollView 38 | { 39 | auto sv1 = [[NSScrollView alloc] init]; 40 | 41 | [sv1 setHasVerticalScroller:toOBJC(p1.scrollers.vertical)]; 42 | [sv1 setHasHorizontalScroller:toOBJC(p1.scrollers.horizontal)]; 43 | 44 | if (p1.document != nullptr) 45 | { 46 | [sv1 setDocumentView:p1.document]; 47 | } 48 | 49 | return sv1; 50 | } 51 | 52 | 53 | 54 | 55 | 56 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 57 | 58 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Scroller.h: -------------------------------------------------------------------------------- 1 | // 2 | // Scroller.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Scroller.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Scroller.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Scroller.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 16 | 17 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/SplitView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SplitView.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "View.h" 12 | 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | class 23 | SplitView : public View 24 | { 25 | public: 26 | using View::View; 27 | 28 | public: 29 | enum class DIVIDER_ORIENTATION : bool; 30 | enum class DIVIDER_STYLE : Integer; 31 | 32 | // static auto splitView() -> SplitView; 33 | static auto splitView(DIVIDER_ORIENTATION, DIVIDER_STYLE) -> SplitView; 34 | 35 | public: 36 | 37 | enum class 38 | DIVIDER_ORIENTATION : bool 39 | { 40 | HORIZONTAL = false, 41 | VERTICAL = true, 42 | }; 43 | 44 | enum class 45 | DIVIDER_STYLE : Integer 46 | { 47 | THICK = 1, 48 | THIN = 2, 49 | PANE_SPLITTER = 3, 50 | }; 51 | 52 | struct 53 | Delegate : Any 54 | { 55 | virtual auto splitViewResizeSubviewsWithOldSize(SplitView, Size const& oldsize) -> void {} 56 | }; 57 | 58 | auto delegate() const -> Delegate*; 59 | auto setDelegate(Delegate*) -> void; 60 | auto unsetDelegate() -> void; 61 | 62 | //// 63 | 64 | auto adjustSubviews() -> void; 65 | auto isSubviewCollapsed(View) const -> bool; 66 | 67 | auto dividerOrientation() const -> DIVIDER_ORIENTATION; 68 | auto setDividerOrientation(DIVIDER_ORIENTATION) -> void; 69 | 70 | auto dividerStyle() const -> DIVIDER_STYLE; 71 | auto setDividerStyle(DIVIDER_STYLE) -> void; 72 | 73 | auto dividerThickness() const -> Float; 74 | auto dividerColor() const -> Color; 75 | 76 | auto setPositionOfDividerAtIndex(Integer const index, Float const position) -> void; 77 | }; 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 87 | 88 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/SplitView.mm: -------------------------------------------------------------------------------- 1 | // 2 | // SplitView.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "SplitView.h" 10 | #include "Color.h" 11 | 12 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | 19 | //auto 20 | //SplitView::splitView() -> SplitView 21 | //{ 22 | // return [[NSSplitView alloc] init]; 23 | //} 24 | auto 25 | SplitView::splitView(Eonil::CocoaCPP::AppKit::SplitView::DIVIDER_ORIENTATION o, Eonil::CocoaCPP::AppKit::SplitView::DIVIDER_STYLE ds) -> SplitView 26 | { 27 | SplitView sv1 = [[NSSplitView alloc] init]; 28 | sv1.setDividerOrientation(o); 29 | sv1.setDividerStyle(ds); 30 | return sv1; 31 | } 32 | 33 | 34 | 35 | 36 | 37 | 38 | auto 39 | SplitView::adjustSubviews() -> void 40 | { 41 | auto self = get_objc_object(); 42 | [self adjustSubviews]; 43 | } 44 | auto 45 | SplitView::isSubviewCollapsed(Eonil::CocoaCPP::AppKit::View o) const -> bool 46 | { 47 | auto self = get_objc_object(); 48 | return toCPP([self isSubviewCollapsed:o]); 49 | } 50 | 51 | auto 52 | SplitView::dividerOrientation() const -> DIVIDER_ORIENTATION 53 | { 54 | auto self = get_objc_object(); 55 | BOOL vert = [self isVertical]; 56 | return DIVIDER_ORIENTATION(toCPP(vert)); 57 | } 58 | auto 59 | SplitView::setDividerOrientation(Eonil::CocoaCPP::AppKit::SplitView::DIVIDER_ORIENTATION o) -> void 60 | { 61 | auto self = get_objc_object(); 62 | [self setVertical:toOBJC(bool(o))]; 63 | } 64 | 65 | auto 66 | SplitView::dividerStyle() const -> DIVIDER_STYLE 67 | { 68 | auto self = get_objc_object(); 69 | return DIVIDER_STYLE([self dividerStyle]); 70 | } 71 | auto 72 | SplitView::setDividerStyle(Eonil::CocoaCPP::AppKit::SplitView::DIVIDER_STYLE o) -> void 73 | { 74 | auto self = get_objc_object(); 75 | [self setDividerStyle:NSSplitViewDividerStyle(o)]; 76 | } 77 | 78 | auto 79 | SplitView::dividerThickness() const -> Float 80 | { 81 | auto self = get_objc_object(); 82 | return [self dividerThickness]; 83 | } 84 | auto 85 | SplitView::dividerColor() const -> Color 86 | { 87 | auto self = get_objc_object(); 88 | return [self dividerColor]; 89 | } 90 | 91 | auto 92 | SplitView::setPositionOfDividerAtIndex(const Integer index, const Float position) -> void 93 | { 94 | auto self = get_objc_object(); 95 | [self setPosition:position ofDividerAtIndex:index]; 96 | } 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 106 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/TableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableView.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "Control.h" 12 | #include "Cell.h" 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | class 23 | TableColumn : public Foundation::Object 24 | { 25 | public: 26 | static auto tableColume() -> TableColumn; 27 | 28 | public: 29 | using Object::Object; 30 | 31 | public: 32 | auto width() const -> Float; 33 | auto setWidth(Float) -> void; 34 | 35 | auto headerCell() const -> Cell; 36 | auto setHeaderCell(Cell) -> void; 37 | }; 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | class 46 | TableView : public Control 47 | { 48 | public: 49 | using Control::Control; 50 | 51 | public: 52 | static auto tableView() -> TableView; 53 | 54 | public: 55 | struct 56 | Delegate : Any 57 | { 58 | virtual ~Delegate(); 59 | virtual auto heightOfRow(TableView, Integer row) -> Float { return 0; } 60 | }; 61 | 62 | auto delegate() const -> Delegate*; 63 | auto setDelegate(Delegate*) -> void; 64 | auto unsetDelegate() -> void; 65 | 66 | auto addTableColumn(TableColumn) -> void; 67 | auto removeTableColumn(TableColumn) -> void; 68 | // auto createTableColumn() -> TableColumn*; 69 | // auto createTableColumn(TableColumn&&) -> TableColumn*; 70 | // auto deleteTableColumn(TableColumn*) -> void; 71 | 72 | auto beginUpdates() -> void; 73 | auto endUpdates() -> void; 74 | }; 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 84 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/TableView.mm: -------------------------------------------------------------------------------- 1 | // 2 | // TableView.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "TableView.h" 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | using namespace Eonil::CocoaCPP; 23 | using namespace Eonil::CocoaCPP::AppKit; 24 | 25 | @interface ____Eonil_Cocoa_TableView_Delegate : NSObject 26 | @end 27 | 28 | @implementation ____Eonil_Cocoa_TableView_Delegate 29 | { 30 | @public 31 | struct 32 | { 33 | TableView::Delegate* cpp_delegate; 34 | } 35 | slots; 36 | } 37 | - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row 38 | { 39 | return slots.cpp_delegate->heightOfRow(tableView, row); 40 | } 41 | @end 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 59 | 60 | auto 61 | TableColumn::tableColume() -> TableColumn 62 | { 63 | return {[[NSTableColumn alloc] init]}; 64 | } 65 | 66 | auto 67 | TableColumn::width() const -> Float 68 | { 69 | auto self = get_objc_object(); 70 | return [self width]; 71 | } 72 | auto 73 | TableColumn::setWidth(Float o) -> void 74 | { 75 | auto self = get_objc_object(); 76 | [self setWidth:o]; 77 | } 78 | 79 | auto 80 | TableColumn:: 81 | headerCell() const -> Cell 82 | { 83 | auto self = get_objc_object(); 84 | return [self headerCell]; 85 | } 86 | auto 87 | TableColumn:: 88 | setHeaderCell(Cell o) -> void 89 | { 90 | auto self = get_objc_object(); 91 | [self setHeaderCell:o]; 92 | } 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | TableView::Delegate::~Delegate() 120 | { 121 | } 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | auto 130 | TableView::tableView() -> TableView 131 | { 132 | return [[NSTableView alloc] init]; 133 | } 134 | 135 | auto 136 | TableView::delegate() const -> Delegate* 137 | { 138 | auto self = get_objc_object(); 139 | ____Eonil_Cocoa_TableView_Delegate* d1 = [self delegate]; 140 | Delegate* d2 = d1->slots.cpp_delegate; 141 | return d2; 142 | } 143 | auto 144 | TableView::setDelegate(TableView::Delegate *o) -> void 145 | { 146 | auto self = get_objc_object(); 147 | [self setDelegate:*o]; 148 | } 149 | auto 150 | TableView::unsetDelegate() -> void 151 | { 152 | auto self = get_objc_object(); 153 | [self setDelegate:nil]; 154 | } 155 | 156 | auto 157 | TableView:: 158 | addTableColumn(TableColumn o) -> void 159 | { 160 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSTableColumn); 161 | 162 | auto self = get_objc_object(); 163 | [self addTableColumn:o]; 164 | } 165 | auto 166 | TableView:: 167 | removeTableColumn(TableColumn o) -> void 168 | { 169 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSTableColumn); 170 | 171 | auto self = get_objc_object(); 172 | [self removeTableColumn:o]; 173 | } 174 | 175 | auto 176 | TableView:: 177 | beginUpdates() -> void 178 | { 179 | auto self = get_objc_object(); 180 | [self beginUpdates]; 181 | } 182 | auto 183 | TableView:: 184 | endUpdates() -> void 185 | { 186 | auto self = get_objc_object(); 187 | [self endUpdates]; 188 | } 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 197 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Text.h: -------------------------------------------------------------------------------- 1 | // 2 | // Text.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "View.h" 12 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | class 17 | Text : public View 18 | { 19 | using super = View; 20 | public: 21 | using super::super; 22 | }; 23 | 24 | 25 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Text.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Text.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Text.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 16 | 17 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/TextField.h: -------------------------------------------------------------------------------- 1 | // 2 | // TextField.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/TextField.mm: -------------------------------------------------------------------------------- 1 | // 2 | // TextField.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "TextField.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 16 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/TextView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TextView.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "Text.h" 12 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | /*! 18 | @classdesign 19 | All overriding point will be provided 20 | 21 | @note 22 | Take care that `TextView` needs to be wrapped in a `ScrollView` to be 23 | spanned over multiple lines. 24 | */ 25 | class 26 | TextView : public Text 27 | { 28 | using super = Text; 29 | public: 30 | using super::super; 31 | 32 | public: 33 | struct 34 | Utility : NonInstantiatable 35 | { 36 | static auto textView() -> TextView; 37 | }; 38 | }; 39 | 40 | 41 | 42 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 43 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/TextView.mm: -------------------------------------------------------------------------------- 1 | // 2 | // TextView.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "TextView.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | auto 19 | TextView::Utility:: 20 | textView() -> TextView 21 | { 22 | return [[NSTextView alloc] init]; 23 | } 24 | 25 | 26 | 27 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/View.h: -------------------------------------------------------------------------------- 1 | // 2 | // View.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "Responder.h" 12 | #include "DraggingDestination.h" 13 | 14 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 15 | 16 | 17 | 18 | 19 | 20 | 21 | class 22 | View : public Responder 23 | { 24 | public: 25 | static auto view() -> View; 26 | 27 | public: 28 | using Responder::Responder; 29 | 30 | public: 31 | auto frame() const -> Rect; 32 | auto setFrame(Rect) -> void; 33 | 34 | auto addSubview(View) -> void; 35 | auto removeFromSuperview() -> void; 36 | 37 | auto wantsLayer() const -> bool; 38 | auto setWantsLayer(bool) -> void; 39 | 40 | auto layer() const -> CoreAnimation::Layer; 41 | auto setLayer(CoreAnimation::Layer) -> void; 42 | 43 | /*! 44 | See `Pasteboard::Type` for generic UTIs. 45 | */ 46 | auto registerForDraggedTypes(vec const& UTIs) -> void; 47 | auto unregisterDraggedTypes() -> void; 48 | 49 | }; 50 | 51 | 52 | 53 | 54 | /*! 55 | If you want to override some methods of a view, you should use this class. 56 | */ 57 | class 58 | OverridableView : public View 59 | { 60 | public: 61 | struct 62 | Hooks : DraggingDestination 63 | { 64 | virtual ~Hooks(); 65 | 66 | virtual auto didMoveToSuperview() -> void {} 67 | }; 68 | 69 | public: 70 | OverridableView(uptr&& overridings); 71 | }; 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 82 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/View.mm: -------------------------------------------------------------------------------- 1 | // 2 | // View.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "View.h" 10 | #include "../CoreGraphics/Rect.h" 11 | #include "../Foundation/String.h" 12 | #include "../CoreAnimation/Layer.h" 13 | 14 | 15 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 16 | 17 | using namespace CoreGraphics; 18 | 19 | 20 | 21 | 22 | 23 | auto 24 | View::view() -> View 25 | { 26 | return {[[NSView alloc] init]}; 27 | } 28 | 29 | auto 30 | View::frame() const -> Rect 31 | { 32 | auto self = get_objc_object(); 33 | return [self frame]; 34 | } 35 | auto 36 | View::setFrame(Rect frame) -> void 37 | { 38 | auto self = get_objc_object(); 39 | [self setFrame:frame]; 40 | } 41 | 42 | auto 43 | View::addSubview(Eonil::CocoaCPP::AppKit::View o) -> void 44 | { 45 | auto self = get_objc_object(); 46 | [self addSubview:o]; 47 | } 48 | auto 49 | View::removeFromSuperview() -> void 50 | { 51 | auto self = get_objc_object(); 52 | [self removeFromSuperview]; 53 | } 54 | 55 | auto 56 | View::wantsLayer() const -> bool 57 | { 58 | auto self = get_objc_object(); 59 | return [self wantsLayer]; 60 | } 61 | auto 62 | View::setWantsLayer(bool o) -> void 63 | { 64 | auto self = get_objc_object(); 65 | 66 | [self setWantsLayer:toOBJC(o)]; 67 | } 68 | 69 | auto 70 | View::layer() const -> CoreAnimation::Layer 71 | { 72 | auto self = get_objc_object(); 73 | return [self layer]; 74 | } 75 | auto 76 | View::setLayer(CoreAnimation::Layer o) -> void 77 | { 78 | EONIL_COCOA_DEBUG_ASSERT((o != nullptr and wantsLayer()) or o == nullptr); 79 | 80 | auto self = get_objc_object(); 81 | 82 | [self setLayer:o]; 83 | } 84 | //auto 85 | //View::unsetLayer() -> void 86 | //{ 87 | // auto self = get_objc_object(); 88 | // 89 | // [self setLayer:nil]; 90 | //} 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | auto 103 | View::registerForDraggedTypes(const vec &UTIs) -> void 104 | { 105 | NSMutableArray* a1 = [[NSMutableArray alloc] init]; 106 | for (Foundation::String const& s1: UTIs) 107 | { 108 | [a1 addObject:s1]; 109 | } 110 | 111 | //// 112 | 113 | auto self = get_objc_object(); 114 | [self registerForDraggedTypes:a1]; 115 | } 116 | auto 117 | View::unregisterDraggedTypes() -> void 118 | { 119 | auto self = get_objc_object(); 120 | [self unregisterDraggedTypes]; 121 | } 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | using namespace Eonil::CocoaCPP; 167 | using namespace Eonil::CocoaCPP::AppKit; 168 | 169 | @interface ____CPP_Eonil_Cocoa_OverridableView1 : NSView 170 | @end 171 | @implementation ____CPP_Eonil_Cocoa_OverridableView1 172 | { 173 | @public 174 | uptr hooks; 175 | } 176 | - (NSDragOperation)draggingEntered:(id)sender 177 | { 178 | EONIL_COCOA_DEBUG_ASSERT(hooks != nullptr); 179 | return NSDragOperation(hooks->draggingEntered(DraggingInfo{sender})); 180 | } 181 | - (NSDragOperation)draggingUpdated:(id)sender 182 | { 183 | EONIL_COCOA_DEBUG_ASSERT(hooks != nullptr); 184 | return NSDragOperation(hooks->draggingUpdated(sender)); 185 | } 186 | - (void)draggingEnded:(id)sender 187 | { 188 | EONIL_COCOA_DEBUG_ASSERT(hooks != nullptr); 189 | hooks->draggingEnded(sender); 190 | } 191 | - (void)draggingExited:(id)sender 192 | { 193 | EONIL_COCOA_DEBUG_ASSERT(hooks != nullptr); 194 | hooks->draggingExited(sender); 195 | } 196 | - (BOOL)prepareForDragOperation:(id)sender 197 | { 198 | EONIL_COCOA_DEBUG_ASSERT(hooks != nullptr); 199 | return toOBJC(hooks->prepareForDragOperation(sender)); 200 | } 201 | - (BOOL)performDragOperation:(id)sender 202 | { 203 | EONIL_COCOA_DEBUG_ASSERT(hooks != nullptr); 204 | return toOBJC(hooks->performDragOperation(sender)); 205 | } 206 | - (void)concludeDragOperation:(id)sender 207 | { 208 | EONIL_COCOA_DEBUG_ASSERT(hooks != nullptr); 209 | hooks->concludeDragOperation(sender); 210 | } 211 | - (void)updateDraggingItemsForDrag:(id)sender 212 | { 213 | EONIL_COCOA_DEBUG_ASSERT(hooks != nullptr); 214 | hooks->updateDraggingItemsForDrag(sender); 215 | } 216 | - (void)viewDidMoveToSuperview 217 | { 218 | EONIL_COCOA_DEBUG_ASSERT(hooks != nullptr); 219 | [super viewDidMoveToSuperview]; 220 | if (self->hooks != nullptr) 221 | { 222 | self->hooks->didMoveToSuperview(); 223 | } 224 | } 225 | @end 226 | 227 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 228 | 229 | OverridableView::Hooks::~Hooks() 230 | { 231 | } 232 | 233 | OverridableView::OverridableView(uptr&&o) : View([[____CPP_Eonil_Cocoa_OverridableView1 alloc] init]) 234 | { 235 | __unsafe_unretained ____CPP_Eonil_Cocoa_OverridableView1* v1 = operator __unsafe_unretained id(); 236 | EONIL_COCOA_ASSERT_OBJC_TYPE(v1, ____CPP_Eonil_Cocoa_OverridableView1); 237 | v1->hooks = std::move(o); 238 | } 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 256 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Window.h: -------------------------------------------------------------------------------- 1 | // 2 | // Window.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "Responder.h" 12 | #include "DraggingDestination.h" 13 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | /*! 19 | Wraps `NSWindow`. 20 | Take care that you have to order to show the window. 21 | */ 22 | class 23 | Window : public Responder 24 | { 25 | using super = Responder; 26 | 27 | public: 28 | using super::super; 29 | 30 | public: 31 | enum class 32 | STYLE : UInteger 33 | { 34 | BORDERLESS = 0, 35 | TITLED = 1 << 0, 36 | CLOSABLE = 1 << 1, 37 | MINIATURIZABLE = 1 << 2, 38 | RESIZABLE = 1 << 3, 39 | TEXTURED_BACKGROUND = 1 << 8, 40 | }; 41 | 42 | struct 43 | Delegate : Any, virtual DraggingDestination 44 | { 45 | Delegate(); 46 | Delegate(Delegate const&) = delete; 47 | Delegate(Delegate&&) = delete; 48 | virtual ~Delegate(); 49 | 50 | virtual inline auto windowShouldClose(Window) -> bool { return NO; } 51 | }; 52 | 53 | public: 54 | static auto window() -> Window; 55 | 56 | public: 57 | auto delegate() const -> Delegate*; 58 | auto setDelegate(Delegate*) -> void; 59 | auto unsetDelegate() -> void; 60 | 61 | auto styleMask() const -> STYLE; 62 | auto setStyleMask(STYLE) -> void; 63 | 64 | auto isVisible() const -> bool; 65 | auto orderOut() -> void; //! Hide the window. 66 | auto orderFront() -> void; //! Show the window. 67 | 68 | auto isKeyWindow() const -> bool; 69 | auto makeKey() -> void; //! Become focused window. 70 | 71 | auto frame() const -> Rect; 72 | auto setFrame(Rect, bool animated) -> void; 73 | auto setContentSize(Size) -> void; //! Resize by content size. 74 | 75 | auto title() const -> Foundation::String; 76 | auto setTitle(Foundation::String) -> void; 77 | auto setTitleWithRepresentativeFilename(Foundation::String filename) -> void; 78 | 79 | auto contentView() const -> View; 80 | auto setContentView(View) -> void; 81 | 82 | /*! 83 | See `Pasteboard::Type` for generic UTIs. 84 | */ 85 | auto registerForDraggedTypes(vec const& UTIs) -> void; 86 | auto unregisterDraggedTypes() -> void; 87 | 88 | auto performClose() -> void; //! Simulates user clicking of close button. 89 | auto performMiniaturize() -> void; //! Simulates user clicking of miniaturize button. 90 | auto performZoom() -> void; //! Simulates user clicking of zoom button. 91 | 92 | public: 93 | auto asResponder() const -> Responder const&; 94 | auto asResponder() -> Responder&; 95 | }; 96 | 97 | template 98 | inline auto 99 | operator|(T const a, T const b) -> T 100 | { 101 | using UT1 = typename std::underlying_type::type; 102 | using UT2 = typename std::underlying_type::type; 103 | return static_cast(static_cast(a) | static_cast(b)); 104 | } 105 | template 106 | inline auto 107 | operator&(T const a, T const b) -> T 108 | { 109 | using UT1 = typename std::underlying_type::type; 110 | using UT2 = typename std::underlying_type::type; 111 | return static_cast(static_cast(a) & static_cast(b)); 112 | } 113 | 114 | //inline auto 115 | //operator|(Window::STYLE a, Window::STYLE b) -> Window::STYLE 116 | //{ 117 | // using UT1 = typename std::underlying_type::type; 118 | // using UT2 = typename std::underlying_type::type; 119 | // return static_cast(static_cast(a) | static_cast(b)); 120 | //} 121 | 122 | 123 | 124 | 125 | ///*! 126 | // If you want to override some methods of a window, you should use this class. 127 | // */ 128 | //class 129 | //OverridableWindow : public Window 130 | //{ 131 | //public: 132 | // struct 133 | // Observer 134 | // { 135 | // virtual auto didResize() -> void; 136 | // }; 137 | // 138 | //public: 139 | // OverridableWindow(); 140 | // 141 | // auto setObserver(Observer*) -> void; 142 | // 143 | //private: 144 | // struct Extras; 145 | // sptr _extras {}; 146 | //}; 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 157 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/Window.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Window.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Window.h" 10 | #include "../CoreGraphics/Rect.h" 11 | #include "../Foundation/String.h" 12 | #include "View.h" 13 | 14 | using namespace Eonil::Platform::Debugging; 15 | using namespace Eonil::CocoaCPP; 16 | using namespace Eonil::CocoaCPP::Foundation; 17 | using namespace Eonil::CocoaCPP::AppKit; 18 | 19 | @interface ____Eonil_Cocoa_WindowDelegate : NSObject 20 | @end 21 | @implementation ____Eonil_Cocoa_WindowDelegate 22 | { 23 | @public 24 | struct 25 | { 26 | Window::Delegate* cpp_delegate {nullptr}; 27 | } 28 | slots; 29 | } 30 | - (BOOL)windowShouldClose:(id)sender 31 | { 32 | return toOBJC(slots.cpp_delegate->windowShouldClose(sender)); 33 | } 34 | 35 | - (NSDragOperation)draggingEntered:(id)sender 36 | { 37 | EONIL_COCOA_DEBUG_ASSERT(self->slots.cpp_delegate != nullptr); 38 | return NSDragOperation(self->slots.cpp_delegate->draggingEntered(sender)); 39 | } 40 | - (NSDragOperation)draggingUpdated:(id)sender 41 | { 42 | EONIL_COCOA_DEBUG_ASSERT(self->slots.cpp_delegate != nullptr); 43 | return NSDragOperation(self->slots.cpp_delegate->draggingUpdated(sender)); 44 | } 45 | - (void)draggingEnded:(id)sender 46 | { 47 | EONIL_COCOA_DEBUG_ASSERT(self->slots.cpp_delegate != nullptr); 48 | self->slots.cpp_delegate->draggingEnded(sender); 49 | } 50 | - (void)draggingExited:(id)sender 51 | { 52 | EONIL_COCOA_DEBUG_ASSERT(self->slots.cpp_delegate != nullptr); 53 | self->slots.cpp_delegate->draggingExited(sender); 54 | } 55 | - (BOOL)prepareForDragOperation:(id)sender 56 | { 57 | EONIL_COCOA_DEBUG_ASSERT(self->slots.cpp_delegate != nullptr); 58 | return toOBJC(self->slots.cpp_delegate->prepareForDragOperation(sender)); 59 | } 60 | - (BOOL)performDragOperation:(id)sender 61 | { 62 | EONIL_COCOA_DEBUG_ASSERT(self->slots.cpp_delegate != nullptr); 63 | return toOBJC(self->slots.cpp_delegate->performDragOperation(sender)); 64 | } 65 | - (void)concludeDragOperation:(id)sender 66 | { 67 | EONIL_COCOA_DEBUG_ASSERT(self->slots.cpp_delegate != nullptr); 68 | self->slots.cpp_delegate->concludeDragOperation(sender); 69 | } 70 | - (void)updateDraggingItemsForDrag:(id)sender 71 | { 72 | EONIL_COCOA_DEBUG_ASSERT(self->slots.cpp_delegate != nullptr); 73 | self->slots.cpp_delegate->updateDraggingItemsForDrag(sender); 74 | } 75 | @end 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 85 | 86 | 87 | 88 | Window::Delegate::Delegate() : Any([[____Eonil_Cocoa_WindowDelegate alloc] init]) 89 | { 90 | auto self = get_objc_object<____Eonil_Cocoa_WindowDelegate>(); 91 | self->slots.cpp_delegate = this; 92 | } 93 | Window::Delegate::~Delegate() 94 | { 95 | } 96 | 97 | 98 | 99 | 100 | auto 101 | Window::window() -> Window 102 | { 103 | if (USE_EXCEPTION_CHECKINGS) 104 | { 105 | crash_if(NSApp == nil, "You must create `Application` object first before creating any `Window` object."); 106 | } 107 | 108 | //// 109 | 110 | return {[[NSWindow alloc] init]}; 111 | } 112 | 113 | 114 | 115 | 116 | 117 | auto 118 | Window::styleMask() const -> STYLE 119 | { 120 | auto self = get_objc_object(); 121 | 122 | return STYLE([self styleMask]); 123 | } 124 | auto 125 | Window::setStyleMask(Eonil::CocoaCPP::AppKit::Window::STYLE o) -> void 126 | { 127 | EONIL_COCOA_DEBUG_ASSERT(UInteger(STYLE::BORDERLESS) == NSBorderlessWindowMask); 128 | EONIL_COCOA_DEBUG_ASSERT(UInteger(STYLE::TITLED) == NSTitledWindowMask); 129 | EONIL_COCOA_DEBUG_ASSERT(UInteger(STYLE::CLOSABLE) == NSClosableWindowMask); 130 | EONIL_COCOA_DEBUG_ASSERT(UInteger(STYLE::MINIATURIZABLE) == NSMiniaturizableWindowMask); 131 | EONIL_COCOA_DEBUG_ASSERT(UInteger(STYLE::RESIZABLE) == NSResizableWindowMask); 132 | EONIL_COCOA_DEBUG_ASSERT(UInteger(STYLE::TEXTURED_BACKGROUND) == NSTexturedBackgroundWindowMask); 133 | 134 | EONIL_COCOA_DEBUG_ASSERT(o == STYLE::BORDERLESS or (o & STYLE::TITLED) == STYLE::TITLED); 135 | 136 | //// 137 | 138 | auto self = get_objc_object(); 139 | 140 | [self setStyleMask:UInteger(o)]; 141 | } 142 | 143 | 144 | 145 | auto 146 | Window::delegate() const -> Delegate* 147 | { 148 | auto self = get_objc_object(); 149 | ____Eonil_Cocoa_WindowDelegate* d1 = [self delegate]; 150 | Window::Delegate* d2 = d1->slots.cpp_delegate; 151 | 152 | return d2; 153 | } 154 | auto 155 | Window::setDelegate(Delegate *o) -> void 156 | { 157 | __unsafe_unretained NSWindow* self = operator __unsafe_unretained id(); 158 | [self setDelegate:*o]; 159 | } 160 | auto 161 | Window::unsetDelegate() -> void 162 | { 163 | __unsafe_unretained NSWindow* self = operator __unsafe_unretained id(); 164 | [self setDelegate:nil]; 165 | } 166 | 167 | auto 168 | Window::isVisible() const -> bool 169 | { 170 | auto self = get_objc_object(); 171 | return toCPP([self isVisible]); 172 | } 173 | auto 174 | Window::orderFront() -> void 175 | { 176 | auto self = get_objc_object(); 177 | [self orderFront:nil]; 178 | } 179 | auto 180 | Window::orderOut() -> void 181 | { 182 | auto self = get_objc_object(); 183 | [self orderOut:nil]; 184 | } 185 | 186 | auto 187 | Window::isKeyWindow() const -> bool 188 | { 189 | auto self = get_objc_object(); 190 | return toCPP([self isKeyWindow]); 191 | } 192 | auto 193 | Window::makeKey() -> void 194 | { 195 | auto self = get_objc_object(); 196 | [self makeKeyWindow]; 197 | } 198 | 199 | auto 200 | Window::frame() const -> Rect 201 | { 202 | auto self = get_objc_object(); 203 | return [self frame]; 204 | } 205 | auto 206 | Window::setFrame(Rect f1, bool animated) -> void 207 | { 208 | auto self = get_objc_object(); 209 | [self setFrame:f1 display:isVisible() animate:animated]; 210 | } 211 | 212 | auto 213 | Window::setContentSize(Size o) -> void 214 | { 215 | auto self = get_objc_object(); 216 | [self setContentSize:o]; 217 | } 218 | 219 | auto 220 | Window::contentView() const -> View 221 | { 222 | auto self = get_objc_object(); 223 | return [self contentView]; 224 | } 225 | auto 226 | Window::setContentView(Eonil::CocoaCPP::AppKit::View o) -> void 227 | { 228 | auto self = get_objc_object(); 229 | [self setContentView:o]; 230 | } 231 | 232 | auto 233 | Window::title() const -> String 234 | { 235 | auto self = get_objc_object(); 236 | return [self title]; 237 | } 238 | auto 239 | Window::setTitle(Foundation::String o) -> void 240 | { 241 | auto self = get_objc_object(); 242 | [self setTitle:o]; 243 | } 244 | auto 245 | Window::setTitleWithRepresentativeFilename(Foundation::String filename) -> void 246 | { 247 | auto self = get_objc_object(); 248 | [self setTitleWithRepresentedFilename:filename]; 249 | } 250 | 251 | auto 252 | Window::registerForDraggedTypes(const vec &UTIs) -> void 253 | { 254 | NSMutableArray* a1 = [[NSMutableArray alloc] init]; 255 | for (Foundation::String const& s1: UTIs) 256 | { 257 | [a1 addObject:s1]; 258 | } 259 | 260 | //// 261 | 262 | auto self = get_objc_object(); 263 | [self registerForDraggedTypes:a1]; 264 | } 265 | auto 266 | Window::unregisterDraggedTypes() -> void 267 | { 268 | auto self = get_objc_object(); 269 | [self unregisterDraggedTypes]; 270 | } 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | auto 281 | Window:: 282 | performClose() -> void 283 | { 284 | auto self = get_objc_object(); 285 | [self performClose:nil]; 286 | } 287 | auto 288 | Window:: 289 | performMiniaturize() -> void 290 | { 291 | auto self = get_objc_object(); 292 | [self performMiniaturize:nil]; 293 | } 294 | auto 295 | Window:: 296 | performZoom() -> void 297 | { 298 | auto self = get_objc_object(); 299 | [self performZoom:nil]; 300 | } 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | auto 314 | Window::asResponder() const -> Responder const& 315 | { 316 | return *this; 317 | } 318 | auto 319 | Window::asResponder() -> Responder& 320 | { 321 | return *this; 322 | } 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | //@interface ____OverridableWindow1 : NSWindow 365 | //@end 366 | //@implementation ____OverridableWindow1 367 | //@end 368 | // 369 | //EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 370 | // 371 | // 372 | // 373 | //auto 374 | //OverridableWindow::Observer::didResize() -> void 375 | //{ 376 | //} 377 | // 378 | //struct 379 | //OverridableWindow::Extras 380 | //{ 381 | // OverridableWindow::Observer* observer {}; 382 | //}; 383 | // 384 | //OverridableWindow::OverridableWindow() : _extras(new Extras()) 385 | //{ 386 | //} 387 | // 388 | //auto 389 | //OverridableWindow::setObserver(Eonil::Cocoa::OverridableWindow::Observer *o) -> void 390 | //{ 391 | // _extras->observer = o; 392 | //} 393 | // 394 | // 395 | // 396 | //EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 397 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/WindowController.h: -------------------------------------------------------------------------------- 1 | // 2 | // WindowController.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "Responder.h" 12 | #include "Window.h" 13 | #include "Document.h" 14 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 15 | 16 | 17 | 18 | 19 | 20 | /*! 21 | @classdesign 22 | NIB related stuffs are not supported at all. 23 | Duplicated methods and event handlers are not supported. 24 | 25 | - `close` Not for UI manipulation. See Cocoa manual. Use `Window::performClose` method. 26 | 27 | */ 28 | class 29 | WindowController final : public Responder 30 | { 31 | template using query = std::functionT>; 32 | 33 | using super = Responder; 34 | 35 | public: 36 | using super::super; 37 | 38 | public: 39 | struct 40 | Hooks 41 | { 42 | query windowTitleForDocumentDisplayName = nullptr; 43 | }; 44 | 45 | public: 46 | WindowController(Hooks); 47 | 48 | public: 49 | auto document() -> Document; 50 | auto setDocument(Document) -> void; 51 | auto unsetDocument() -> void; 52 | 53 | auto window() -> Window; 54 | auto setWindow(Window) -> void; 55 | auto unsetWindow() -> void; 56 | }; 57 | 58 | 59 | 60 | 61 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 62 | 63 | 64 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/AppKit/WindowController.mm: -------------------------------------------------------------------------------- 1 | // 2 | // WindowController.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "WindowController.h" 10 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | auto 19 | WindowController:: 20 | document() -> Document 21 | { 22 | auto self = get_objc_object(); 23 | return [self document]; 24 | } 25 | 26 | auto 27 | WindowController:: 28 | setDocument(Eonil::CocoaCPP::AppKit::Document o) -> void 29 | { 30 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSDocument); 31 | 32 | //// 33 | 34 | auto self = get_objc_object(); 35 | [self setDocument:o]; 36 | } 37 | 38 | auto 39 | WindowController:: 40 | unsetDocument() -> void 41 | { 42 | auto self = get_objc_object(); 43 | [self setDocument:nil]; 44 | } 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | auto 59 | WindowController:: 60 | window() -> Window 61 | { 62 | auto self = get_objc_object(); 63 | return [self window]; 64 | } 65 | 66 | auto 67 | WindowController:: 68 | setWindow(Eonil::CocoaCPP::AppKit::Window o) -> void 69 | { 70 | EONIL_COCOA_ASSERT_OBJC_TYPE(o, NSWindow); 71 | 72 | //// 73 | 74 | auto self = get_objc_object(); 75 | [self setWindow:o]; 76 | } 77 | 78 | auto 79 | WindowController:: 80 | unsetWindow() -> void 81 | { 82 | auto self = get_objc_object(); 83 | [self setWindow:nil]; 84 | } 85 | 86 | 87 | 88 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 89 | 90 | 91 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Cocoa.cpp: -------------------------------------------------------------------------------- 1 | //// 2 | //// Cocoa.cpp 3 | //// Cocoa++ 4 | //// 5 | //// Created by Hoon H. on 14/4/24. 6 | //// Copyright (c) 2014 Eonil. All rights reserved. 7 | //// 8 | // 9 | //#include "Cocoa.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Cocoa.h: -------------------------------------------------------------------------------- 1 | // 2 | // Cocoa.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | 11 | #ifndef __cplusplus 12 | #error "This library is C++ only library. Include only in a C++ code context." 13 | #endif 14 | 15 | 16 | 17 | #include "Common.h" 18 | 19 | #include "CoreFoundation/Type.h" 20 | #include "CoreFoundation/Data.h" 21 | #include "CoreGraphics/Rect.h" 22 | #include "CoreGraphics/Color.h" 23 | #include "CoreGraphics/DataProvider.h" 24 | #include "CoreGraphics/Image.h" 25 | #include "CoreGraphics/ImageDestination.h" 26 | 27 | #include "ObjectiveC/Any.h" 28 | #include "ObjectiveC/None.h" 29 | #include "Foundation/Object.h" 30 | #include "Foundation/Data.h" 31 | #include "Foundation/String.h" 32 | #include "Foundation/Array.h" 33 | #include "Foundation/URL.h" 34 | 35 | #include "CoreAnimation/Layer.h" 36 | #include "AppKit/Common.h" 37 | #include "AppKit/Pasteboard.h" 38 | #include "AppKit/DraggingDestination.h" 39 | #include "AppKit/FileManager.h" 40 | #include "AppKit/Color.h" 41 | #include "AppKit/Image.h" 42 | #include "AppKit/Responder.h" 43 | #include "AppKit/View.h" 44 | #include "AppKit/Control.h" 45 | #include "AppKit/ImageView.h" 46 | #include "AppKit/TextView.h" 47 | #include "AppKit/ScrollView.h" 48 | #include "AppKit/SplitView.h" 49 | #include "AppKit/TableView.h" 50 | #include "AppKit/Menu.h" 51 | #include "AppKit/Window.h" 52 | #include "AppKit/WindowController.h" 53 | #include "AppKit/Application.h" 54 | #include "AppKit/Document.h" 55 | //#include "AppKit/DocumentController.h" 56 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Common.h: -------------------------------------------------------------------------------- 1 | // 2 | // Common.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | 11 | #define EONIL_PLATFORM_APPLE_NAMESPACE_BEGIN namespace Eonil { namespace CocoaCPP { 12 | #define EONIL_PLATFORM_APPLE_NAMESPACE_END } } 13 | 14 | #define EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_BEGIN namespace Eonil { namespace CocoaCPP { namespace CoreFoundation { 15 | #define EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_END } } } 16 | 17 | #define EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN namespace Eonil { namespace CocoaCPP { namespace CoreGraphics { 18 | #define EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END } } } 19 | 20 | #define EONIL_PLATFORM_APPLE_CORE_ANIMATION_NAMESPACE_BEGIN namespace Eonil { namespace CocoaCPP { namespace CoreAnimation { 21 | #define EONIL_PLATFORM_APPLE_CORE_ANIMATION_NAMESPACE_END } } } 22 | 23 | #define EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN namespace Eonil { namespace CocoaCPP { namespace Foundation { 24 | #define EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END } } } 25 | 26 | #define EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN namespace Eonil { namespace CocoaCPP { namespace AppKit { 27 | #define EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END } } } 28 | 29 | #define EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN namespace Eonil { namespace CocoaCPP { namespace UIKit { 30 | #define EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END } } } 31 | 32 | 33 | 34 | #ifdef __cplusplus 35 | #include 36 | #include 37 | #include 38 | #include 39 | #endif 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #ifdef __OBJC__ 48 | #import 49 | #endif 50 | 51 | #include "../Debugging/Exception.h" 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | #ifdef __cplusplus 69 | 70 | EONIL_PLATFORM_APPLE_NAMESPACE_BEGIN 71 | 72 | using Integer = NSInteger; 73 | using UInteger = NSUInteger; 74 | UInteger const UIntegerMax = NSUIntegerMax; 75 | 76 | template using uptr = std::unique_ptr; 77 | template using sptr = std::shared_ptr; 78 | template using set = std::set; 79 | template using vec = std::vector; 80 | 81 | using PROC = std::function void>; 82 | 83 | 84 | class Any; 85 | class Object; 86 | 87 | static inline void 88 | EONIL_COCOA_DEBUG_ASSERT(bool cond) 89 | { 90 | if (not cond) 91 | { 92 | std::terminate(); 93 | } 94 | } 95 | 96 | 97 | 98 | 99 | 100 | 101 | #ifdef __OBJC__ 102 | #define EONIL_COCOA_ASSERT_OBJC_TYPE(object,type) {EONIL_COCOA_DEBUG_ASSERT([object isKindOfClass:[type class]] == YES);} 103 | #define EONIL_COCOA_ASSERT_OBJC_TYPE_OR_NIL(object,type) {EONIL_COCOA_DEBUG_ASSERT(object == nil or [object isKindOfClass:[type class]] == YES);} 104 | #else 105 | #define EONIL_COCOA_ASSERT_OBJC_TYPE(object,type) 106 | #define EONIL_COCOA_ASSERT_OBJC_TYPE_OR_NIL(object,type) 107 | #endif 108 | 109 | 110 | 111 | 112 | 113 | #ifdef __OBJC__ 114 | 115 | static inline auto 116 | toOBJC(bool o) -> BOOL 117 | { 118 | return o ? YES : NO; 119 | } 120 | static inline auto 121 | toCPP(BOOL o) -> bool 122 | { 123 | return o ? true : false; 124 | } 125 | #endif 126 | 127 | EONIL_PLATFORM_APPLE_NAMESPACE_END 128 | 129 | 130 | 131 | 132 | 133 | 134 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_BEGIN 135 | using Index = CFIndex; 136 | class Type; 137 | class Data; 138 | class MutableData; 139 | class String; 140 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_END 141 | 142 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 143 | using Float = CGFloat; 144 | class Point; 145 | class Size; 146 | class Rect; 147 | class Color; 148 | class ColorSpace; 149 | class DataProvider; 150 | class Image; 151 | class ImageDestination; 152 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 153 | 154 | EONIL_PLATFORM_APPLE_CORE_ANIMATION_NAMESPACE_BEGIN 155 | class Layer; 156 | EONIL_PLATFORM_APPLE_CORE_ANIMATION_NAMESPACE_END 157 | 158 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 159 | class Object; 160 | class String; 161 | class Data; 162 | class AnytypeArray; 163 | template class SpecificTypeArray; 164 | class URL; 165 | class Date; 166 | using TimeInterval = double; 167 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 168 | 169 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_BEGIN 170 | class Color; 171 | class Image; 172 | class View; 173 | class Control; 174 | class ImageView; 175 | class Window; 176 | class WindowController; 177 | using Float = CoreGraphics::Float; 178 | using Size = CoreGraphics::Size; 179 | using Rect = CoreGraphics::Rect; 180 | class Pasteboard; 181 | EONIL_PLATFORM_APPLE_APPKIT_NAMESPACE_END 182 | 183 | #endif 184 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Common.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Common.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Common.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreAnimation/Layer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Layer.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | 13 | EONIL_PLATFORM_APPLE_CORE_ANIMATION_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | /*! 20 | Wraps `CALayer`. 21 | */ 22 | class 23 | Layer : public Foundation::Object 24 | { 25 | public: 26 | static auto layer() -> Layer; 27 | 28 | public: 29 | using Object::Object; 30 | 31 | public: 32 | // auto backgroundColor() const -> CoreGraphics::Color const&; 33 | // auto setBackgroundColor(CoreGraphics::Color&&) -> void; 34 | 35 | auto frame() const -> CoreGraphics::Rect; 36 | auto setFrame(CoreGraphics::Rect) -> void; 37 | 38 | auto backgroundColor() const -> CoreGraphics::Color; 39 | auto setBackgroundColor(CoreGraphics::Color) -> void; 40 | 41 | //private: 42 | // struct Extras; 43 | // uptr _extras {}; 44 | // 45 | // Layer( 46 | }; 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | EONIL_PLATFORM_APPLE_CORE_ANIMATION_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreAnimation/Layer.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Layer.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Layer.h" 10 | #include "../CoreGraphics/Rect.h" 11 | #include "../CoreGraphics/Color.h" 12 | 13 | EONIL_PLATFORM_APPLE_CORE_ANIMATION_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | //struct 19 | //Layer::Extras 20 | //{ 21 | // CoreGraphics::Color _bg_color {nullptr}; 22 | //}; 23 | // 24 | //auto 25 | //Layer::backgroundColor() const -> CoreGraphics::Color const& 26 | //{ 27 | // auto self = get_objc_object(); 28 | // 29 | // _extras->_bg_color = [self backgroundColor]; 30 | // 31 | // return _extras->_bg_color; 32 | //} 33 | //auto 34 | //Layer::setBackgroundColor(CoreGraphics::Color &&o) -> void 35 | //{ 36 | // _extras->_bg_color = std::move(o); 37 | // 38 | // //// 39 | // 40 | // auto self = get_objc_object(); 41 | // 42 | // [self setBackgroundColor:_extras->_bg_color]; 43 | //} 44 | 45 | 46 | 47 | auto 48 | Layer::layer() -> Layer 49 | { 50 | return {[[CALayer alloc] init]}; 51 | } 52 | 53 | auto 54 | Layer::frame() const -> CoreGraphics::Rect 55 | { 56 | auto self = get_objc_object(); 57 | return [self frame]; 58 | } 59 | auto 60 | Layer::setFrame(CoreGraphics::Rect o) -> void 61 | { 62 | auto self = get_objc_object(); 63 | [self setFrame:o]; 64 | } 65 | 66 | auto 67 | Layer::backgroundColor() const -> CoreGraphics::Color 68 | { 69 | auto self = get_objc_object(); 70 | return [self backgroundColor]; 71 | } 72 | auto 73 | Layer::setBackgroundColor(CoreGraphics::Color o) -> void 74 | { 75 | auto self = get_objc_object(); 76 | [self setBackgroundColor:o]; 77 | } 78 | 79 | 80 | 81 | 82 | EONIL_PLATFORM_APPLE_CORE_ANIMATION_NAMESPACE_END 83 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreFoundation/Data.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Data.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Data.h" 10 | 11 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Data::Data(CFDataRef o) : Type(o) 22 | { 23 | } 24 | 25 | Data::operator CFDataRef() const 26 | { 27 | return (CFDataRef)operator CFTypeRef(); 28 | } 29 | 30 | auto 31 | Data::length() const -> Index 32 | { 33 | return CFDataGetLength(*this); 34 | } 35 | auto 36 | Data::bytePtr() const -> UInt8 const* 37 | { 38 | return CFDataGetBytePtr(*this); 39 | } 40 | 41 | auto 42 | Data::mutableCopy() const -> MutableData 43 | { 44 | return MutableData::mutableCopy(*this, length()); 45 | } 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | MutableData::MutableData(CFMutableDataRef o) : Data(o) 64 | { 65 | } 66 | 67 | MutableData::operator CFMutableDataRef() const 68 | { 69 | return (CFMutableDataRef)operator CFTypeRef(); 70 | } 71 | 72 | auto 73 | MutableData::mutableBytePtr() -> UInt8* 74 | { 75 | return CFDataGetMutableBytePtr(*this); 76 | } 77 | auto 78 | MutableData::setLength(Index o) -> void 79 | { 80 | CFDataSetLength(*this, o); 81 | } 82 | 83 | auto 84 | MutableData::mutableData() -> MutableData 85 | { 86 | return CFDataCreateMutable(NULL, 0); 87 | } 88 | //auto 89 | //MutableData::mutableDataWithCapacity(Index capacity) -> MutableData 90 | //{ 91 | // return CFDataCreateMutable(NULL, capacity); 92 | //} 93 | auto 94 | MutableData::mutableCopy(Eonil::CocoaCPP::CoreFoundation::Data o, Index capacity) -> MutableData 95 | { 96 | return CFDataCreateMutableCopy(NULL, capacity, o); 97 | } 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_END 106 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreFoundation/Data.h: -------------------------------------------------------------------------------- 1 | // 2 | // Data.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../CoreFoundation/Type.h" 12 | 13 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | class 19 | Data : public CoreFoundation::Type 20 | { 21 | public: 22 | using Type::Type; 23 | 24 | Data(CFDataRef); 25 | 26 | public: 27 | operator CFDataRef() const; 28 | 29 | public: 30 | auto length() const -> Index; 31 | auto bytePtr() const -> UInt8 const*; 32 | 33 | public: 34 | auto mutableCopy() const -> MutableData; 35 | }; 36 | 37 | 38 | 39 | 40 | 41 | class 42 | MutableData : public Data 43 | { 44 | public: 45 | MutableData(CFMutableDataRef); 46 | 47 | operator CFMutableDataRef() const; 48 | 49 | public: 50 | auto mutableBytePtr() -> UInt8*; 51 | auto setLength(Index) -> void; 52 | 53 | public: 54 | static auto mutableData() -> MutableData; 55 | // static auto mutableDataWithCapacity(Index capacity) -> MutableData; 56 | static auto mutableCopy(Data, Index capacity) -> MutableData; 57 | }; 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_END 68 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreFoundation/String.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // String.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "String.h" 10 | 11 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | String::String(CFStringRef o) : Type(o) 23 | { 24 | } 25 | 26 | String::operator CFStringRef() const 27 | { 28 | return (CFStringRef)operator CFTypeRef(); 29 | } 30 | 31 | 32 | 33 | 34 | auto 35 | String::cStringPtr() const -> char const* 36 | { 37 | return CFStringGetCStringPtr(*this, kCFStringEncodingUTF8); 38 | } 39 | //auto 40 | //String::CppString() const -> str 41 | //{ 42 | // 43 | //} 44 | 45 | 46 | 47 | 48 | 49 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_END 50 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreFoundation/String.h: -------------------------------------------------------------------------------- 1 | // 2 | // String.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../CoreFoundation/Type.h" 12 | 13 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | class 19 | String : public CoreFoundation::Type 20 | { 21 | public: 22 | using Type::Type; 23 | 24 | String(CFStringRef); 25 | 26 | public: 27 | operator CFStringRef() const; 28 | 29 | public: 30 | auto cStringPtr() const -> char const*; 31 | // auto cppString() const -> str; //! Returns a copy. 32 | }; 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_END 49 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreFoundation/Type.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Type.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Type.h" 10 | 11 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | Type::Type(std::nullptr_t) : _cftype(NULL) 31 | { 32 | } 33 | Type::Type(Type const& o) : _cftype(o._cftype) 34 | { 35 | CFRetain(_cftype); 36 | } 37 | Type::Type(Type&& o) : _cftype(o._cftype) 38 | { 39 | o._cftype = NULL; 40 | } 41 | Type::Type(CFTypeRef o) : _cftype(o) 42 | { 43 | EONIL_COCOA_DEBUG_ASSERT(o != NULL); // If you want to make NULL state, use `Type(std::nullptr_t)` constructor explicitly. 44 | CFRetain(_cftype); 45 | } 46 | Type::~Type() 47 | { 48 | if (_cftype != NULL) 49 | { 50 | CFRelease(_cftype); 51 | _cftype = NULL; 52 | } 53 | } 54 | 55 | 56 | 57 | 58 | 59 | auto 60 | Type::operator=(Eonil::CocoaCPP::CoreFoundation::Type const& o) -> Type& 61 | { 62 | _cftype = o._cftype; 63 | CFRetain(_cftype); 64 | return *this; 65 | } 66 | auto 67 | Type::operator=(Eonil::CocoaCPP::CoreFoundation::Type &&o) -> Type& 68 | { 69 | _cftype = o._cftype; 70 | o._cftype = NULL; 71 | return *this; 72 | } 73 | 74 | auto 75 | Type::operator==(std::nullptr_t) const -> bool 76 | { 77 | return _cftype == NULL; 78 | } 79 | auto 80 | Type::operator!=(std::nullptr_t) const -> bool 81 | { 82 | return _cftype != NULL; 83 | } 84 | 85 | 86 | 87 | 88 | Type::operator CFTypeRef() const 89 | { 90 | return _cftype; 91 | } 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | //Type::Type(std::nullptr_t) : _cftype(NULL) 124 | //{ 125 | //} 126 | //Type::Type(Type&& o) : _cftype(o._cftype) 127 | //{ 128 | // o._cftype = NULL; 129 | //} 130 | //Type::Type(CFTypeRef o) : _cftype(o) 131 | //{ 132 | // CFRetain(_cftype); 133 | //} 134 | //Type::~Type() 135 | //{ 136 | // CFRelease(_cftype); 137 | // _cftype = NULL; 138 | //} 139 | // 140 | // 141 | // 142 | // 143 | // 144 | // 145 | //auto 146 | //Type::operator==(std::nullptr_t) const -> bool 147 | //{ 148 | // return _cftype == NULL; 149 | //} 150 | //auto 151 | //Type::operator!=(std::nullptr_t) const -> bool 152 | //{ 153 | // return _cftype != NULL; 154 | //} 155 | // 156 | // 157 | // 158 | //auto 159 | //Type::operator=(Type&& o) -> Type& 160 | //{ 161 | // /* 162 | // No change on ownership. 163 | // */ 164 | // _cftype = o._cftype; 165 | // o._cftype = NULL; 166 | // return *this; 167 | //} 168 | // 169 | // 170 | // 171 | // 172 | //Type::operator CFTypeRef() 173 | //{ 174 | // return _cftype; 175 | //} 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_END 187 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreFoundation/Type.h: -------------------------------------------------------------------------------- 1 | // 2 | // Type.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | 12 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | /*! 22 | Provides `CFType` features. 23 | 24 | @discussion 25 | Represents CoreFoundation object type. 26 | */ 27 | class 28 | Type 29 | { 30 | public: 31 | Type() = delete; 32 | Type(Type const&); 33 | Type(Type&&); 34 | ~Type(); 35 | 36 | Type(std::nullptr_t); 37 | Type(CFTypeRef); 38 | 39 | public: 40 | auto operator=(Type const&) -> Type&; 41 | auto operator=(Type&&) -> Type&; 42 | 43 | auto operator==(std::nullptr_t) const -> bool; 44 | auto operator!=(std::nullptr_t) const -> bool; 45 | 46 | public: 47 | operator CFTypeRef() const; 48 | 49 | protected: 50 | 51 | private: 52 | CFTypeRef _cftype {NULL}; 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 | // Provides `CFType` features. 85 | // */ 86 | //class 87 | //Type 88 | //{ 89 | //public: 90 | // Type() = delete; 91 | // Type(std::nullptr_t); 92 | // Type(Type&&); 93 | // Type(CFTypeRef); 94 | // virtual ~Type(); 95 | // 96 | // Type(Type const&) = delete; //! Generic copy is not allowed. 97 | // 98 | //public: 99 | // auto operator==(std::nullptr_t) const -> bool; 100 | // auto operator!=(std::nullptr_t) const -> bool; 101 | // 102 | // auto operator=(Type&&) -> Type&; 103 | // 104 | //public: 105 | // operator CFTypeRef(); 106 | // 107 | //private: 108 | // CFTypeRef _cftype {NULL}; 109 | //}; 110 | 111 | 112 | 113 | EONIL_PLATFORM_APPLE_CORE_FOUNDATION_NAMESPACE_END 114 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/Color.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Color.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Color.h" 10 | 11 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Color::Color(CGColorRef o) : Type(o) 22 | { 23 | } 24 | 25 | Color::operator CGColorRef() 26 | { 27 | return (CGColorRef)operator CFTypeRef(); 28 | } 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/Color.h: -------------------------------------------------------------------------------- 1 | // 2 | // Color.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../CoreFoundation/Type.h" 12 | 13 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | class 19 | Color : CoreFoundation::Type 20 | { 21 | public: 22 | using Type::Type; 23 | 24 | Color(CGColorRef); 25 | 26 | public: 27 | operator CGColorRef(); 28 | }; 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/ColorSpace.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ColorSpace.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "ColorSpace.h" 10 | #include "../CoreFoundation/String.h" 11 | 12 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ColorSpace::ColorSpace(CGColorSpaceRef o) : Type(o) 22 | { 23 | } 24 | 25 | ColorSpace::operator CGColorSpaceRef() const 26 | { 27 | return (CGColorSpaceRef)operator CFTypeRef(); 28 | } 29 | 30 | 31 | 32 | auto 33 | ColorSpace::name() const -> CoreFoundation::String 34 | { 35 | return CGColorSpaceCopyName(*this); 36 | } 37 | auto 38 | ColorSpace::model() const -> MODEL 39 | { 40 | return MODEL(CGColorSpaceGetModel(*this)); 41 | } 42 | 43 | 44 | 45 | 46 | 47 | auto 48 | ColorSpace::calibratedGray(const Float *whitePoint, const Float *blackPoint, Float gamma) -> ColorSpace 49 | { 50 | return CGColorSpaceCreateCalibratedGray(whitePoint, blackPoint, gamma); 51 | } 52 | auto 53 | ColorSpace::calibratedRGB(const Float *whitePoint, const Float *blackPoint, Float const* gamma, const Float *matrix) -> ColorSpace 54 | { 55 | return CGColorSpaceCreateCalibratedRGB(whitePoint, blackPoint, gamma, matrix); 56 | } 57 | 58 | auto 59 | ColorSpace::deviceGray() -> ColorSpace 60 | { 61 | return CGColorSpaceCreateDeviceGray(); 62 | } 63 | auto 64 | ColorSpace::deviceRGB() -> ColorSpace 65 | { 66 | return CGColorSpaceCreateDeviceRGB(); 67 | } 68 | 69 | 70 | 71 | 72 | 73 | 74 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 75 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/ColorSpace.h: -------------------------------------------------------------------------------- 1 | // 2 | // ColorSpace.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../CoreFoundation/Type.h" 12 | 13 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | class 27 | ColorSpace : CoreFoundation::Type 28 | { 29 | public: 30 | using Type::Type; 31 | 32 | ColorSpace(CGColorSpaceRef); 33 | 34 | public: 35 | operator CGColorSpaceRef() const; 36 | 37 | //public: 38 | // ColorSpace(str const& name); 39 | 40 | public: 41 | // enum class 42 | // NAME 43 | // { 44 | // GENERIC_GRAY, 45 | // GENERIC_RGB, 46 | // SRGB, 47 | // GENERIC_GRAY_GAMMA_2_2, 48 | // }; 49 | 50 | enum class 51 | MODEL : int32_t 52 | { 53 | UNKNOWN = kCGColorSpaceModelUnknown, 54 | MONOCHROME = kCGColorSpaceModelMonochrome, 55 | RGB = kCGColorSpaceModelRGB, 56 | CMYK = kCGColorSpaceModelCMYK, 57 | LAB = kCGColorSpaceModelLab, 58 | DEVICE_N = kCGColorSpaceModelDeviceN, 59 | INDEXES = kCGColorSpaceModelIndexed, 60 | PATTERN = kCGColorSpaceModelPattern, 61 | }; 62 | 63 | 64 | enum class 65 | RENDERING_INTENT 66 | { 67 | DEFAULT = kCGRenderingIntentDefault, 68 | ABSOLUTE_COLORIMETRIC = kCGRenderingIntentAbsoluteColorimetric, 69 | RELATIVE_COLORIMETRIC = kCGRenderingIntentRelativeColorimetric, 70 | PERCEPTUAL = kCGRenderingIntentPerceptual, 71 | SATURATION = kCGRenderingIntentSaturation, 72 | }; 73 | 74 | 75 | public: 76 | auto name() const -> CoreFoundation::String; 77 | auto model() const -> MODEL; 78 | 79 | public: 80 | static auto calibratedGray(Float const* whitePoint, Float const* blackPoint, Float gamma) -> ColorSpace; 81 | static auto calibratedRGB(Float const* whitePoint, Float const* blackPoint, Float const* gamma, Float const* matrix) -> ColorSpace; 82 | 83 | static auto deviceGray() -> ColorSpace; 84 | static auto deviceRGB() -> ColorSpace; 85 | 86 | // static auto withName(NAME const& name) -> ColorSpace; 87 | // static auto withPlatformColorSpace(void* platformColorSpaceReference) -> ColorSpace; 88 | }; 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 105 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/DataProvider.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // DataProvider.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "DataProvider.h" 10 | #include "../CoreFoundation/Data.h" 11 | 12 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | DataProvider::DataProvider(CGDataProviderRef o) : Type(o) 22 | { 23 | } 24 | 25 | DataProvider::operator CGDataProviderRef() const 26 | { 27 | return (CGDataProviderRef)operator CFTypeRef(); 28 | } 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | DataProvider::DataProvider(CoreFoundation::Data o) : Type(CGDataProviderCreateWithCFData(o)) 46 | { 47 | } 48 | 49 | 50 | auto 51 | DataProvider::copyData() const -> CoreFoundation::Data 52 | { 53 | return CGDataProviderCopyData(*this); 54 | } 55 | 56 | 57 | 58 | 59 | 60 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 61 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/DataProvider.h: -------------------------------------------------------------------------------- 1 | // 2 | // DataProvider.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../CoreFoundation/Type.h" 12 | 13 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | class 26 | DataProvider final : protected CoreFoundation::Type 27 | { 28 | public: 29 | using Type::Type; 30 | 31 | DataProvider(CGDataProviderRef); 32 | 33 | operator CGDataProviderRef() const; 34 | 35 | public: 36 | DataProvider(CoreFoundation::Data); 37 | 38 | public: 39 | auto copyData() const -> CoreFoundation::Data; 40 | }; 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/Image.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Image.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Image.h" 10 | #include "DataProvider.h" 11 | #include "ColorSpace.h" 12 | 13 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Image::Image(CGImageRef o) : Type(o) 23 | { 24 | } 25 | 26 | Image::operator CGImageRef() const 27 | { 28 | return (CGImageRef)operator CFTypeRef(); 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 | auto 64 | Image::Metadata::deviceAlphaOnly8(const Eonil::CocoaCPP::CoreGraphics::Image::Metadata::Dimension &dimension) -> Metadata 65 | { 66 | Metadata inf2 {}; 67 | 68 | inf2.dimension = dimension; 69 | inf2.layout.bitsPerComponent = 8; 70 | inf2.layout.bitsPerPixel = 8 * 1; 71 | inf2.layout.bytesPerRow = 1 * dimension.width; 72 | inf2.colorSpace = ColorSpace::deviceGray(); 73 | inf2.bitmapInfo.alphaInfo = Image::ALPHA_INFO::ONLY; 74 | inf2.bitmapInfo.floatComponents = false; 75 | inf2.bitmapInfo.byteOrder = Image::BYTE_ORDER_INFO::DEFAULT; 76 | inf2.decode = nullptr; 77 | inf2.shouldInterpolate = false; 78 | inf2.renderingIntent = ColorSpace::RENDERING_INTENT::DEFAULT; 79 | 80 | return inf2; 81 | } 82 | 83 | auto 84 | Image::Metadata::deviceRGB888(const Eonil::CocoaCPP::CoreGraphics::Image::Metadata::Dimension &dimension) -> Metadata 85 | { 86 | Metadata inf2 {}; 87 | 88 | inf2.dimension = dimension; 89 | inf2.layout.bitsPerComponent = 8; 90 | inf2.layout.bitsPerPixel = 8 * 3; 91 | inf2.layout.bytesPerRow = 3 * dimension.width; 92 | inf2.colorSpace = ColorSpace::deviceRGB(); 93 | inf2.bitmapInfo.alphaInfo = Image::ALPHA_INFO::NONE; 94 | inf2.bitmapInfo.floatComponents = false; 95 | inf2.bitmapInfo.byteOrder = Image::BYTE_ORDER_INFO::DEFAULT; 96 | inf2.decode = nullptr; 97 | inf2.shouldInterpolate = false; 98 | inf2.renderingIntent = ColorSpace::RENDERING_INTENT::DEFAULT; 99 | 100 | return inf2; 101 | } 102 | auto 103 | Image::Metadata::deviceRGBA8888(const Eonil::CocoaCPP::CoreGraphics::Image::Metadata::Dimension &dimension) -> Metadata 104 | { 105 | Metadata inf2 {}; 106 | 107 | inf2.dimension = dimension; 108 | inf2.layout.bitsPerComponent = 8; 109 | inf2.layout.bitsPerPixel = 8 * 4; 110 | inf2.layout.bytesPerRow = 4 * dimension.width; 111 | inf2.colorSpace = ColorSpace::deviceRGB(); 112 | inf2.bitmapInfo.alphaInfo = Image::ALPHA_INFO::LAST; 113 | inf2.bitmapInfo.floatComponents = false; 114 | inf2.bitmapInfo.byteOrder = Image::BYTE_ORDER_INFO::DEFAULT; 115 | inf2.decode = nullptr; 116 | inf2.shouldInterpolate = false; 117 | inf2.renderingIntent = ColorSpace::RENDERING_INTENT::DEFAULT; 118 | 119 | return inf2; 120 | } 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | namespace 136 | { 137 | static inline auto 138 | _to_cg(Image::BitmapInfo const& info) -> CGBitmapInfo 139 | { 140 | CGBitmapInfo v = CGBitmapInfo(info.alphaInfo) | CGBitmapInfo(info.byteOrder); 141 | 142 | if (info.floatComponents) 143 | { 144 | v |= kCGBitmapFloatComponents; 145 | } 146 | 147 | return v; 148 | } 149 | static inline auto 150 | _to_ee(CGBitmapInfo const& info) -> Image::BitmapInfo 151 | { 152 | CGBitmapInfo alpha_ch = info & kCGBitmapAlphaInfoMask; 153 | CGBitmapInfo byte_order = info & kCGBitmapByteOrderMask; 154 | 155 | Image::BitmapInfo inf1 {}; 156 | inf1.floatComponents = (info & kCGBitmapFloatComponents) == kCGBitmapFloatComponents; 157 | inf1.alphaInfo = Image::ALPHA_INFO(alpha_ch); 158 | inf1.byteOrder = Image::BYTE_ORDER_INFO(byte_order); 159 | 160 | return inf1; 161 | } 162 | 163 | static inline auto 164 | _makeup(Image::Metadata const& info, DataProvider& content) -> CGImageRef 165 | { 166 | CGColorRenderingIntent rend_intent = CGColorRenderingIntent(info.renderingIntent); 167 | return CGImageCreate(info.dimension.width, info.dimension.height, info.layout.bitsPerComponent, info.layout.bitsPerPixel, info.layout.bytesPerRow, info.colorSpace, _to_cg(info.bitmapInfo), content, info.decode, info.shouldInterpolate, rend_intent); 168 | } 169 | } 170 | 171 | Image::Image(Metadata const& info, DataProvider& content) : Type(_makeup(info, content)) 172 | { 173 | 174 | } 175 | 176 | 177 | auto 178 | Image::copy() const -> Image 179 | { 180 | return CGImageCreateCopy(*this); 181 | } 182 | 183 | auto 184 | Image::width() const -> size_t 185 | { 186 | return CGImageGetWidth(*this); 187 | } 188 | auto 189 | Image::height() const -> size_t 190 | { 191 | return CGImageGetHeight(*this); 192 | } 193 | 194 | auto 195 | Image::bitsPerComponent() const -> size_t 196 | { 197 | return CGImageGetBitsPerComponent(*this); 198 | } 199 | auto 200 | Image::bitsPerPixel() const -> size_t 201 | { 202 | return CGImageGetBitsPerPixel(*this); 203 | } 204 | auto 205 | Image::bytesPerRow() const -> size_t 206 | { 207 | return CGImageGetBytesPerRow(*this); 208 | } 209 | 210 | auto 211 | Image::isMask() const -> bool 212 | { 213 | return CGImageIsMask(*this); 214 | } 215 | auto 216 | Image::shouldInterpolate() const -> bool 217 | { 218 | return CGImageGetShouldInterpolate(*this); 219 | } 220 | 221 | auto 222 | Image::dataProvider() const -> DataProvider 223 | { 224 | return CGImageGetDataProvider(*this); 225 | } 226 | auto 227 | Image::colorSpace() const -> ColorSpace 228 | { 229 | return CGImageGetColorSpace(*this); 230 | } 231 | 232 | 233 | 234 | 235 | 236 | 237 | auto 238 | Image::metadata() const -> Metadata 239 | { 240 | Metadata inf3 {}; 241 | 242 | inf3.dimension.width = width(); 243 | inf3.dimension.height = height(); 244 | inf3.layout.bitsPerComponent = bitsPerComponent(); 245 | inf3.layout.bitsPerPixel = bitsPerPixel(); 246 | inf3.layout.bytesPerRow = bytesPerRow(); 247 | inf3.colorSpace = colorSpace(); 248 | inf3.bitmapInfo = _to_ee(CGImageGetBitmapInfo(*this)); 249 | inf3.decode = CGImageGetDecode(*this); 250 | inf3.shouldInterpolate = shouldInterpolate(); 251 | inf3.renderingIntent = ColorSpace::RENDERING_INTENT(CGImageGetRenderingIntent(*this)); 252 | 253 | return inf3; 254 | } 255 | 256 | 257 | 258 | 259 | 260 | 261 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 262 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/Image.h: -------------------------------------------------------------------------------- 1 | // 2 | // Image.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../CoreFoundation/Type.h" 12 | #include "ColorSpace.h" 13 | #include "DataProvider.h" 14 | 15 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 16 | 17 | 18 | 19 | 20 | 21 | 22 | class 23 | Image : public CoreFoundation::Type 24 | { 25 | public: 26 | using Type::Type; 27 | 28 | Image(CGImageRef); 29 | 30 | public: 31 | operator CGImageRef() const; 32 | 33 | public: 34 | enum class 35 | ALPHA_INFO : uint32_t 36 | { 37 | NONE = kCGImageAlphaNone, 38 | NONE_SKIP_FIRST = kCGImageAlphaNoneSkipFirst, 39 | NONE_SKIP_LAST = kCGImageAlphaNoneSkipLast, 40 | ONLY = kCGImageAlphaOnly, // No color channel. Alpha-only single channled image. 41 | LAST = kCGImageAlphaLast, // Straight alpha. 42 | FIRST = kCGImageAlphaFirst, // Straight alpha. 43 | PREMULTIPLIED_LAST = kCGImageAlphaPremultipliedLast, 44 | PREMULTIPLIED_FIRST = kCGImageAlphaPremultipliedFirst, 45 | 46 | MASK = kCGBitmapAlphaInfoMask, 47 | }; 48 | enum class 49 | BYTE_ORDER_INFO : uint32_t 50 | { 51 | DEFAULT = kCGBitmapByteOrderDefault, 52 | LITTLE_16_BIT = kCGBitmapByteOrder16Little, 53 | LITTLE_32_BIT = kCGBitmapByteOrder32Little, 54 | BIG_16_BIT = kCGBitmapByteOrder16Big, 55 | BIG_32_BIT = kCGBitmapByteOrder32Big, 56 | 57 | MASK = kCGBitmapByteOrderMask, 58 | }; 59 | struct 60 | BitmapInfo 61 | { 62 | ALPHA_INFO alphaInfo {ALPHA_INFO::NONE}; 63 | bool floatComponents {false}; 64 | BYTE_ORDER_INFO byteOrder {BYTE_ORDER_INFO::DEFAULT}; 65 | }; 66 | 67 | struct 68 | Metadata 69 | { 70 | struct 71 | Dimension 72 | { 73 | size_t width {}; 74 | size_t height {}; 75 | 76 | Dimension() {} 77 | Dimension(size_t width, size_t height) : width(width), height(height) {} 78 | }; 79 | 80 | struct 81 | Layout 82 | { 83 | size_t bitsPerComponent {}; 84 | size_t bitsPerPixel {}; 85 | size_t bytesPerRow {}; 86 | }; 87 | 88 | Dimension dimension {}; 89 | Layout layout {}; 90 | ColorSpace colorSpace {nullptr}; 91 | BitmapInfo bitmapInfo {}; 92 | 93 | Float const* decode {}; 94 | bool shouldInterpolate {false}; 95 | ColorSpace::RENDERING_INTENT renderingIntent {ColorSpace::RENDERING_INTENT::DEFAULT}; 96 | 97 | //// 98 | 99 | static auto deviceAlphaOnly8(Dimension const& dimension) -> Metadata; //! Single channel image info. 100 | static auto deviceRGB888(Dimension const& dimension) -> Metadata; 101 | static auto deviceRGBA8888(Dimension const& dimension) -> Metadata; //! Alpha channel is straight-alpha at last. 102 | }; 103 | 104 | public: 105 | Image(Metadata const& metadata, DataProvider& content); 106 | 107 | auto copy() const -> Image; 108 | 109 | auto width() const -> size_t; 110 | auto height() const -> size_t; 111 | 112 | auto bitsPerComponent() const -> size_t; 113 | auto bitsPerPixel() const -> size_t; 114 | auto bytesPerRow() const -> size_t; 115 | 116 | auto isMask() const -> bool; 117 | auto shouldInterpolate() const -> bool; 118 | 119 | auto dataProvider() const -> DataProvider; 120 | auto colorSpace() const -> ColorSpace; 121 | 122 | public: 123 | auto metadata() const -> Metadata; 124 | 125 | }; 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 142 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/ImageDestination.cpp: -------------------------------------------------------------------------------- 1 | //// 2 | //// ImageDestination.cpp 3 | //// Cocoa++ 4 | //// 5 | //// Created by Hoon H. on 14/4/25. 6 | //// Copyright (c) 2014 Eonil. All rights reserved. 7 | //// 8 | // 9 | //#include "ImageDestination.h" 10 | //#include "Image.h" 11 | //#include "../CoreFoundation/String.h" 12 | //#include "../CoreFoundation/Data.h" 13 | // 14 | //EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 15 | // 16 | //using namespace CoreFoundation; 17 | // 18 | // 19 | // 20 | //ImageDestination::ImageDestination(CGImageDestinationRef o) : Type(o) 21 | //{ 22 | //} 23 | //ImageDestination::operator CGImageDestinationRef() const 24 | //{ 25 | // return (CGImageDestinationRef)CFTypeRef(); 26 | //} 27 | // 28 | // 29 | // 30 | //namespace 31 | //{ 32 | //// static auto 33 | //// _make( 34 | //} 35 | // 36 | //ImageDestination::ImageDestination(MutableData buffer, CoreFoundation::String UTI, size_t count) : Type(CGImageDestinationCreateWithData(buffer, UTI, count, NULL)) 37 | //{ 38 | // EONIL_COCOA_DEBUG_ASSERT(count >= 1); 39 | // EONIL_COCOA_DEBUG_ASSERT(buffer != nullptr); 40 | // EONIL_COCOA_DEBUG_ASSERT(UTI != nullptr); 41 | //} 42 | //auto 43 | //ImageDestination::addImage(Image o) -> void 44 | //{ 45 | // CGImageDestinationAddImage(*this, o, NULL); 46 | //} 47 | //auto 48 | //ImageDestination::finalize() -> void 49 | //{ 50 | // CGImageDestinationFinalize(*this); 51 | //} 52 | // 53 | // 54 | //auto 55 | //ImageDestination::dataOfImage(Eonil::CocoaCPP::CoreGraphics::Image image, CoreFoundation::String UTI) -> Data 56 | //{ 57 | // EONIL_COCOA_DEBUG_ASSERT(image != nullptr); 58 | // EONIL_COCOA_DEBUG_ASSERT(UTI != nullptr); 59 | // 60 | // MutableData d1 {MutableData::mutableData()}; 61 | // ImageDestination dst1 {d1, UTI, 1}; 62 | // dst1.addImage(image); 63 | // dst1.finalize(); 64 | // 65 | // return d1; 66 | //} 67 | //auto 68 | //ImageDestination::PNGDataOfImage(Eonil::CocoaCPP::CoreGraphics::Image image) -> Data 69 | //{ 70 | // return dataOfImage(image, String(kUTTypePNG)); 71 | //} 72 | // 73 | // 74 | // 75 | // 76 | // 77 | // 78 | //EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 79 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/ImageDestination.h: -------------------------------------------------------------------------------- 1 | // 2 | // ImageDestination.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../CoreFoundation/Type.h" 12 | 13 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | /* 20 | DO NOT MAKE wrapper of `CGImageDestination`. The feature doesn't work as I expected, 21 | and it's too hard to figure out how to use it. Use PNG features in `Eonil::Aliens`. 22 | */ 23 | 24 | 25 | //class 26 | //ImageDestination : CoreFoundation::Type 27 | //{ 28 | //public: 29 | // using Type::Type; 30 | // 31 | // ImageDestination(CGImageDestinationRef); 32 | // 33 | //public: 34 | // operator CGImageDestinationRef() const; 35 | // 36 | //public: 37 | // ImageDestination(CoreFoundation::MutableData buffer, CoreFoundation::String UTI, size_t count); 38 | // 39 | // auto addImage(Image) -> void; 40 | // auto finalize() -> void; 41 | // 42 | //public: 43 | // static auto dataOfImage(Image image, CoreFoundation::String UTI) -> CoreFoundation::Data; 44 | // static auto PNGDataOfImage(Image image) -> CoreFoundation::Data; 45 | //}; 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/Rect.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Rect.cpp 3 | // CocoaTouch++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Rect.h" 10 | 11 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | //using namespace ___C_API; 16 | 17 | 18 | 19 | 20 | Point::Point(Float const x, Float const y) : _cgpoint(CGPointMake(x, y)) 21 | { 22 | } 23 | Point::Point(CGPoint const cgpoint) : _cgpoint(cgpoint) 24 | { 25 | } 26 | Point::operator CGPoint() const 27 | { 28 | return _cgpoint; 29 | } 30 | auto 31 | Point::x() const -> Float 32 | { 33 | return _cgpoint.x; 34 | } 35 | auto 36 | Point::setX(Float o) -> void 37 | { 38 | _cgpoint.x = o; 39 | } 40 | auto 41 | Point::y() const -> Float 42 | { 43 | return _cgpoint.y; 44 | } 45 | auto 46 | Point::setY(Float o) -> void 47 | { 48 | _cgpoint.x = o; 49 | } 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | Size::Size(Float const w, Float const h) : _cgsize(CGSizeMake(w, h)) 58 | { 59 | } 60 | Size::Size(CGSize const cgsize) : _cgsize(cgsize) 61 | { 62 | } 63 | Size::operator CGSize() const 64 | { 65 | return _cgsize; 66 | } 67 | auto 68 | Size::width() const -> Float 69 | { 70 | return _cgsize.width; 71 | } 72 | auto 73 | Size::setWidth(Float o) -> void 74 | { 75 | _cgsize.width = o; 76 | } 77 | auto 78 | Size::height() const -> Float 79 | { 80 | return _cgsize.height; 81 | } 82 | auto 83 | Size::setHeight(Float o) -> void 84 | { 85 | _cgsize.height = o; 86 | } 87 | 88 | 89 | 90 | 91 | Rect::Rect(Point const pt, Size const sz) : _cgrect(CGRectMake(pt.x(), pt.y(), sz.width(), sz.height())) 92 | { 93 | } 94 | Rect::Rect(Float const x, Float const y, Float const width, Float const height) : _cgrect(CGRectMake(x, y, width, height)) 95 | { 96 | } 97 | Rect::Rect(CGRect const cgrect) : _cgrect(cgrect) 98 | { 99 | } 100 | 101 | Rect::operator CGRect() const 102 | { 103 | return _cgrect; 104 | } 105 | 106 | auto 107 | Rect::origin() const -> Point 108 | { 109 | return _cgrect.origin; 110 | } 111 | auto 112 | Rect::size() const -> Size 113 | { 114 | return _cgrect.size; 115 | } 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 126 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/CoreGraphics/Rect.h: -------------------------------------------------------------------------------- 1 | // 2 | // Rect.h 3 | // CocoaTouch++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | 12 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | class 21 | Point 22 | { 23 | CGPoint _cgpoint = CGPointZero; 24 | 25 | public: 26 | Point() = default; 27 | 28 | Point(Float const x, Float const y); 29 | Point(CGPoint const); 30 | 31 | operator CGPoint() const; 32 | 33 | auto x() const -> Float; 34 | auto setX(Float) -> void; 35 | 36 | auto y() const -> Float; 37 | auto setY(Float) -> void; 38 | 39 | }; 40 | 41 | class 42 | Size 43 | { 44 | CGSize _cgsize = CGSizeZero; 45 | 46 | public: 47 | Size(Float const width, Float const height); 48 | Size(CGSize const); 49 | 50 | operator CGSize() const; 51 | 52 | auto width() const -> Float; 53 | auto setWidth(Float) -> void; 54 | 55 | auto height() const -> Float; 56 | auto setHeight(Float) -> void; 57 | }; 58 | 59 | class 60 | Rect 61 | { 62 | CGRect _cgrect = CGRectZero; 63 | 64 | public: 65 | Rect(); 66 | Rect(Point const pt, Size const sz); 67 | Rect(Float const x, Float const y, Float const width, Float const height); 68 | Rect(CGRect const); 69 | 70 | auto origin() const -> Point; 71 | auto size() const -> Size; 72 | 73 | operator CGRect() const; 74 | }; 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | EONIL_PLATFORM_APPLE_CORE_GRAPHICS_NAMESPACE_END 94 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/Array.h: -------------------------------------------------------------------------------- 1 | // 2 | // Array.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | 13 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | /*! 20 | Wraps `NSArray`. 21 | */ 22 | class 23 | AnytypeArray : protected Object 24 | { 25 | public: 26 | using Object::Object; 27 | 28 | operator __unsafe_unretained id() const; 29 | 30 | public: 31 | AnytypeArray(vec const& objects); 32 | 33 | auto equals(AnytypeArray) const -> bool; 34 | auto copy() const -> AnytypeArray; 35 | 36 | auto vector() const -> vec; 37 | 38 | public: 39 | static auto anytypeArray() -> AnytypeArray; 40 | }; 41 | 42 | 43 | 44 | /*! 45 | Provides type-specialization for `AnytypeArray`. 46 | */ 47 | template 48 | class 49 | SpecificTypeArray : public AnytypeArray 50 | { 51 | public: 52 | using AnytypeArray::AnytypeArray; 53 | 54 | public: 55 | SpecificTypeArray(vec const& objects) : AnytypeArray(static_cast const&>(objects)) 56 | { 57 | } 58 | 59 | auto 60 | equals(SpecificTypeArray o) const -> bool 61 | { 62 | return AnytypeArray::equals(o); 63 | } 64 | auto 65 | copy() const -> SpecificTypeArray 66 | { 67 | return AnytypeArray::copy(); 68 | } 69 | 70 | auto 71 | vector() const -> vec 72 | { 73 | vec a1 {AnytypeArray::vector()}; 74 | vec a2 {}; 75 | a2.reserve(a1.size()); 76 | for (Any o1: a1) 77 | { 78 | T o2 = (id)o1; 79 | a2.push_back(o2); 80 | } 81 | return a2; 82 | } 83 | }; 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 94 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/Array.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Array.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Array.h" 10 | #include "../ObjectiveC/InternalRawStuffs/ErrorCheck.h" 11 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 12 | 13 | using namespace Platform::Debugging; 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | AnytypeArray::operator __unsafe_unretained id() const 23 | { 24 | if (USE_EXCEPTION_CHECKINGS) 25 | { 26 | InternalRawStuffs::ErrorCheck::crash_if_not_a_kind_of_class(*this); 27 | } 28 | 29 | //// 30 | 31 | return get_objc_object(); 32 | } 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | namespace 47 | { 48 | static inline auto 49 | _make(vec const& objects) -> NSArray* 50 | { 51 | vec v2 {}; 52 | v2.reserve(objects.size()); 53 | for (Any a1 : objects) 54 | { 55 | v2.push_back(a1); 56 | } 57 | return [NSArray arrayWithObjects:v2.data() count:objects.size()]; 58 | } 59 | } 60 | 61 | AnytypeArray::AnytypeArray(vec const& objects) : Object(_make(objects)) 62 | { 63 | } 64 | 65 | 66 | auto 67 | AnytypeArray::equals(Eonil::CocoaCPP::Foundation::AnytypeArray o) const -> bool 68 | { 69 | id o1 = *this; 70 | return [o1 isEqualToArray:o]; 71 | } 72 | auto 73 | AnytypeArray::copy() const -> AnytypeArray 74 | { 75 | id o1 = *this; 76 | return [o1 copy]; 77 | } 78 | 79 | auto 80 | AnytypeArray::vector() const -> vec 81 | { 82 | auto self = get_objc_object(); 83 | 84 | vec a1 {}; 85 | a1.reserve([self count]); 86 | for (id o1 in self) 87 | { 88 | a1.push_back(o1); 89 | } 90 | return a1; 91 | } 92 | 93 | auto 94 | AnytypeArray::anytypeArray() -> AnytypeArray 95 | { 96 | return [[NSArray alloc] init]; 97 | } 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 108 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/Data.h: -------------------------------------------------------------------------------- 1 | // 2 | // Data.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | 13 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | /*! 20 | Wraps `NSData`. 21 | */ 22 | class 23 | Data : protected Object 24 | { 25 | public: 26 | using Object::Object; 27 | 28 | operator __unsafe_unretained id() const; 29 | 30 | public: 31 | auto equals(Data) const -> bool; 32 | auto copy() const -> Data; 33 | 34 | auto writeToURLAtomically(URL) const -> bool; 35 | 36 | public: 37 | static auto dataWithBytes(void const* bytes, UInteger length) -> Data; //! Memory content will be copied. 38 | }; 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 50 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/Data.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Data.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Data.h" 10 | #include "URL.h" 11 | #include "../ObjectiveC/InternalRawStuffs/ErrorCheck.h" 12 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 13 | 14 | using namespace Platform::Debugging; 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Data::operator __unsafe_unretained id() const 24 | { 25 | if (USE_EXCEPTION_CHECKINGS) 26 | { 27 | InternalRawStuffs::ErrorCheck::crash_if_not_a_kind_of_class(*this); 28 | } 29 | 30 | //// 31 | 32 | return get_objc_object(); 33 | } 34 | 35 | 36 | 37 | auto 38 | Data::equals(Eonil::CocoaCPP::Foundation::Data o) const -> bool 39 | { 40 | id o1 = *this; 41 | return [o1 isEqualToData:o]; 42 | } 43 | auto 44 | Data::copy() const -> Data 45 | { 46 | id o1 = *this; 47 | return [o1 copy]; 48 | } 49 | auto 50 | Data::writeToURLAtomically(Eonil::CocoaCPP::Foundation::URL o) const -> bool 51 | { 52 | auto self = get_objc_object(); 53 | return toCPP([self writeToURL:o atomically:YES]); 54 | } 55 | 56 | 57 | 58 | 59 | 60 | auto 61 | Data::dataWithBytes(const void *bytes, UInteger length) -> Data 62 | { 63 | return [[NSData alloc] initWithBytes:bytes length:length]; 64 | } 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 74 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/Date.h: -------------------------------------------------------------------------------- 1 | // 2 | // Date.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/28. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | 13 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | /*! 20 | Wraps `NSDate`. 21 | */ 22 | class 23 | Date final : protected Object 24 | { 25 | public: 26 | using Object::Object; 27 | 28 | operator __unsafe_unretained id() const; 29 | 30 | public: 31 | 32 | auto equals(Date) const -> bool; 33 | auto copy() const -> Date; 34 | 35 | /*! 36 | This returns Unix timestamp (seconds since 00:00:00 UTC January 1, 1970) in `double` type. 37 | Cast this into `time_t` with proper value range test. 38 | */ 39 | auto timeIntervalSince1970() const -> TimeInterval; 40 | 41 | public: 42 | static auto dateOfNow() -> Date; 43 | static auto dateWithString(String expression) -> Date; 44 | }; 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 56 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/Date.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Date.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/28. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Date.h" 10 | #include "String.h" 11 | #include "../ObjectiveC/InternalRawStuffs/ErrorCheck.h" 12 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 13 | 14 | using namespace Platform::Debugging; 15 | 16 | 17 | 18 | Date::operator __unsafe_unretained id() const 19 | { 20 | if (USE_EXCEPTION_CHECKINGS) 21 | { 22 | InternalRawStuffs::ErrorCheck::crash_if_not_a_kind_of_class(*this); 23 | } 24 | 25 | //// 26 | 27 | return Object::operator __unsafe_unretained id(); 28 | } 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | auto 37 | Date::equals(Eonil::CocoaCPP::Foundation::Date o) const -> bool 38 | { 39 | auto self = get_objc_object(); 40 | return [self isEqualToDate:o]; 41 | } 42 | auto 43 | Date::copy() const -> Date 44 | { 45 | auto self = get_objc_object(); 46 | return [self copy]; 47 | } 48 | auto 49 | Date::timeIntervalSince1970() const -> TimeInterval 50 | { 51 | auto self = get_objc_object(); 52 | return [self timeIntervalSince1970]; 53 | } 54 | 55 | 56 | 57 | 58 | auto 59 | Date::dateOfNow() -> Date 60 | { 61 | return [[NSDate alloc] init]; 62 | } 63 | auto 64 | Date::dateWithString(Eonil::CocoaCPP::Foundation::String expression) -> Date 65 | { 66 | return [[NSDate alloc] initWithString:expression]; 67 | } 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 78 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/Object.h: -------------------------------------------------------------------------------- 1 | // 2 | // Object.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../ObjectiveC/Any.h" 12 | #include "../ObjectiveC/None.h" 13 | 14 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 15 | 16 | 17 | 18 | 19 | 20 | 21 | ///*! 22 | // Virtual Objective-C semantic object. 23 | // */ 24 | //class 25 | //Semantic 26 | //{ 27 | //public: 28 | // Semantic(Semantic const&); 29 | // 30 | // auto operator==(Semantic) const -> bool; 31 | // auto operator!=(Semantic) const -> bool; 32 | //}; 33 | 34 | 35 | 36 | 37 | 38 | class 39 | Object : public Any 40 | { 41 | using super = Any; 42 | 43 | public: 44 | using super::super; 45 | 46 | // Object(id); 47 | 48 | public: 49 | static auto object() -> Object; 50 | }; 51 | 52 | 53 | //class 54 | //Copying : virtual public Any 55 | //{ 56 | //public: 57 | // NoCopy() = default; 58 | // NoCopy(NoCopy const&) = delete; 59 | // virtual ~NoCopy() = default; 60 | // 61 | // virtual auto copy() const -> Any = delete; 62 | //}; 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 71 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/Object.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Object.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Object.h" 10 | #include "../ObjectiveC/InternalRawStuffs/ErrorCheck.h" 11 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | 18 | //Object::Object() : Any([[NSObject alloc] init]) 19 | //{ 20 | //} 21 | //Object::Object(id o) : Any(o) 22 | //{ 23 | //} 24 | //Object::Object(Object const&o) : Any(o) 25 | //{ 26 | //} 27 | // 28 | //Object::Object(Object&&o) : Any(std::move(o)) 29 | //{ 30 | //} 31 | 32 | 33 | 34 | 35 | auto 36 | Object::object() -> Object 37 | { 38 | return Object([[NSObject alloc] init]); 39 | } 40 | 41 | 42 | 43 | 44 | 45 | 46 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 47 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/String.h: -------------------------------------------------------------------------------- 1 | // 2 | // String.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | /*! 19 | Wraps `NSString`. 20 | */ 21 | class 22 | String : protected Object 23 | { 24 | public: 25 | using UNICHAR = uint16_t; 26 | 27 | public: 28 | using Object::Object; 29 | 30 | operator __unsafe_unretained id() const; 31 | 32 | public: 33 | String(char const* utf8String); //! This copies the string. 34 | String(std::string const& utf8String); //! This copies the string. 35 | 36 | auto equals(String) const -> bool; 37 | auto copy() const -> String; 38 | 39 | auto UTF8String() const -> char const*; 40 | 41 | public: 42 | auto length() const -> UInteger; 43 | auto characterAtIndex(UInteger) const -> UNICHAR; 44 | auto hasPrefix(String) const -> bool; 45 | auto hasSuffix(String) const -> bool; 46 | auto stringByAppendingString(String) const -> String; 47 | auto stringByAppendingPathComponent(String) const -> String; 48 | auto substringFromIndex(UInteger) const -> String; 49 | auto substringToIndex(UInteger) const -> String; 50 | 51 | public: 52 | static auto stringWithUTF8String(char const*) -> String; 53 | static auto stringWithUTF8String(std::string const&) -> String; 54 | }; 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 66 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/String.mm: -------------------------------------------------------------------------------- 1 | // 2 | // String.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "String.h" 10 | #include "../ObjectiveC/InternalRawStuffs/ErrorCheck.h" 11 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 12 | 13 | using namespace Platform::Debugging; 14 | static_assert(std::is_same::value, "Objective-C `unichar` must be same with String::UNICHAR type."); 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | String::operator __unsafe_unretained id() const 24 | { 25 | if (USE_EXCEPTION_CHECKINGS) 26 | { 27 | InternalRawStuffs::ErrorCheck::crash_if_not_a_kind_of_class(*this); 28 | } 29 | 30 | //// 31 | 32 | return get_objc_object(); 33 | } 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | String::String(char const* utf8string) : Object([NSString stringWithUTF8String:utf8string]) 44 | { 45 | } 46 | String::String(std::string const& utf8string) : String(utf8string.c_str()) 47 | { 48 | } 49 | 50 | 51 | auto 52 | String::equals(Eonil::CocoaCPP::Foundation::String o) const -> bool 53 | { 54 | id o1 = *this; 55 | return [o1 isEqualToString:o]; 56 | } 57 | auto 58 | String::copy() const -> String 59 | { 60 | id o1 = *this; 61 | return [o1 copy]; 62 | } 63 | 64 | auto 65 | String::UTF8String() const -> char const* 66 | { 67 | auto self = get_objc_object(); 68 | return [self UTF8String]; 69 | } 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | auto 80 | String::length() const -> UInteger 81 | { 82 | auto self = get_objc_object(); 83 | return [self length]; 84 | } 85 | auto 86 | String::characterAtIndex(UInteger o) const -> UNICHAR 87 | { 88 | auto self = get_objc_object(); 89 | return [self characterAtIndex:o]; 90 | } 91 | auto 92 | String::hasPrefix(Eonil::CocoaCPP::Foundation::String o) const -> bool 93 | { 94 | auto self = get_objc_object(); 95 | return [self hasPrefix:o]; 96 | } 97 | auto 98 | String::hasSuffix(Eonil::CocoaCPP::Foundation::String o) const -> bool 99 | { 100 | auto self = get_objc_object(); 101 | return [self hasSuffix:o]; 102 | } 103 | auto 104 | String::stringByAppendingString(Eonil::CocoaCPP::Foundation::String o) const -> String 105 | { 106 | auto self = get_objc_object(); 107 | return [self stringByAppendingString:o]; 108 | } 109 | auto 110 | String::stringByAppendingPathComponent(Eonil::CocoaCPP::Foundation::String o) const -> String 111 | { 112 | auto self = get_objc_object(); 113 | return [self stringByAppendingPathComponent:o]; 114 | } 115 | auto 116 | String::substringFromIndex(UInteger o) const -> String 117 | { 118 | auto self = get_objc_object(); 119 | return [self substringFromIndex:o]; 120 | } 121 | auto 122 | String::substringToIndex(UInteger o) const -> String 123 | { 124 | auto self = get_objc_object(); 125 | return [self substringToIndex:o]; 126 | } 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | auto 141 | String::stringWithUTF8String(char const* o) -> String 142 | { 143 | return String{[[NSString alloc] initWithUTF8String:o]}; 144 | } 145 | auto 146 | String::stringWithUTF8String(std::string const& o) -> String 147 | { 148 | return stringWithUTF8String(o.c_str()); 149 | } 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 160 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/URL.h: -------------------------------------------------------------------------------- 1 | // 2 | // URL.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | 13 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 14 | 15 | 16 | 17 | 18 | 19 | /*! 20 | Wraps `NSURL`. 21 | */ 22 | class 23 | URL : protected Object 24 | { 25 | public: 26 | using Object::Object; 27 | 28 | operator __unsafe_unretained id() const; 29 | 30 | public: 31 | // URL(String); //! This copies the string. 32 | 33 | auto equals(URL) const -> bool; 34 | auto copy() const -> URL; 35 | 36 | auto path() const -> String; 37 | 38 | public: 39 | static auto urlWithString(String) -> URL; 40 | }; 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 52 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/Foundation/URL.mm: -------------------------------------------------------------------------------- 1 | // 2 | // URL.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/25. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "URL.h" 10 | #include "String.h" 11 | #include "../ObjectiveC/InternalRawStuffs/ErrorCheck.h" 12 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_BEGIN 13 | 14 | using namespace Platform::Debugging; 15 | 16 | 17 | 18 | 19 | 20 | 21 | URL::operator __unsafe_unretained id() const 22 | { 23 | if (USE_EXCEPTION_CHECKINGS) 24 | { 25 | InternalRawStuffs::ErrorCheck::crash_if_not_a_kind_of_class(*this); 26 | } 27 | 28 | //// 29 | 30 | return Object::operator __unsafe_unretained id(); 31 | } 32 | 33 | 34 | 35 | 36 | auto 37 | URL::equals(URL o) const -> bool 38 | { 39 | auto self = get_objc_object(); 40 | return toCPP([self isEqual:o]); 41 | } 42 | auto 43 | URL::copy() const -> URL 44 | { 45 | auto self = get_objc_object(); 46 | return [self copy]; 47 | } 48 | 49 | auto 50 | URL::path() const -> String 51 | { 52 | auto self = get_objc_object(); 53 | return [self path]; 54 | } 55 | 56 | auto 57 | URL::urlWithString(Eonil::CocoaCPP::Foundation::String o) -> URL 58 | { 59 | return [[NSURL alloc] initWithString:o]; 60 | } 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | EONIL_PLATFORM_APPLE_FOUNDATION_NAMESPACE_END 73 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/ObjectiveC/Any.h: -------------------------------------------------------------------------------- 1 | // 2 | // Any.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | 12 | EONIL_PLATFORM_APPLE_NAMESPACE_BEGIN 13 | 14 | 15 | ///*! 16 | // Represents semantical behavior of an Objective-C object. 17 | // */ 18 | //class 19 | //Content 20 | //{ 21 | // 22 | //}; 23 | 24 | 25 | /*! 26 | Wraps semantics of Objective-C `id` type. 27 | Each object uniquely owns an underlying Objective-C object. 28 | 29 | @note 30 | You must use `nullptr` explicitly to make `nil` state. 31 | */ 32 | class 33 | Any 34 | { 35 | public: 36 | Any() = delete; 37 | Any(std::nullptr_t); 38 | Any(__unsafe_unretained id); 39 | ~Any(); 40 | 41 | operator __unsafe_unretained id() const; 42 | 43 | public: 44 | Any(Any const&); 45 | Any(Any&&); 46 | 47 | auto operator=(Any const&) -> Any&; 48 | auto operator=(Any&&) -> Any&; 49 | 50 | public: 51 | // auto copy() const -> Any; 52 | 53 | protected: 54 | template auto 55 | get_objc_object() const -> __unsafe_unretained T* 56 | { 57 | #ifndef __OBJC__ 58 | /*! 59 | This method is available only for Objective-C context. 60 | */ 61 | EONIL_COCOA_DEBUG_ASSERT(false); 62 | #endif 63 | 64 | /*! 65 | This assertion is activated only on Objective-C context. 66 | */ 67 | EONIL_COCOA_ASSERT_OBJC_TYPE_OR_NIL(_objc_object_ptr, T); 68 | return _objc_object_ptr; 69 | } 70 | 71 | private: 72 | __strong id _objc_object_ptr {}; 73 | }; 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | EONIL_PLATFORM_APPLE_NAMESPACE_END 85 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/ObjectiveC/Any.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Any.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Any.h" 10 | #include "../ObjectiveC/InternalRawStuffs/ErrorCheck.h" 11 | #include 12 | EONIL_PLATFORM_APPLE_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | Any::Any(std::nullptr_t) : _objc_object_ptr(nil) 19 | { 20 | } 21 | Any::Any(__unsafe_unretained id o) : _objc_object_ptr(o) 22 | { 23 | [_objc_object_ptr retain]; 24 | } 25 | Any::~Any() 26 | { 27 | [_objc_object_ptr release]; 28 | _objc_object_ptr = nil; 29 | } 30 | 31 | Any::operator __unsafe_unretained id() const 32 | { 33 | return _objc_object_ptr; 34 | } 35 | 36 | 37 | 38 | 39 | 40 | Any::Any(Any const& o) : _objc_object_ptr(o._objc_object_ptr) 41 | { 42 | [_objc_object_ptr retain]; 43 | } 44 | Any::Any(Any&& o) : _objc_object_ptr(o._objc_object_ptr) 45 | { 46 | o._objc_object_ptr = nil; 47 | } 48 | 49 | auto 50 | Any::operator=(const Eonil::CocoaCPP::Any &o) -> Any& 51 | { 52 | /* 53 | Retain first to be safe on self-assignment situation. 54 | */ 55 | 56 | [o._objc_object_ptr retain]; 57 | [_objc_object_ptr release]; 58 | 59 | _objc_object_ptr = o._objc_object_ptr; 60 | 61 | return *this; 62 | } 63 | auto 64 | Any::operator=(Eonil::CocoaCPP::Any &&o) -> Any& 65 | { 66 | /* 67 | No need to change ref-count if two objects are same. 68 | */ 69 | 70 | if (_objc_object_ptr != o._objc_object_ptr) 71 | { 72 | [_objc_object_ptr release]; 73 | } 74 | 75 | _objc_object_ptr = o._objc_object_ptr; 76 | o._objc_object_ptr = nil; 77 | 78 | return *this; 79 | } 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | //auto 88 | //Any::copy() const -> Any 89 | //{ 90 | // return Any([_objc_object_ptr copy]); 91 | //} 92 | //auto 93 | //Any::operator==(const Any &o) const -> bool 94 | //{ 95 | // return toCPP([_objc_object_ptr isEqual:o._objc_object_ptr]); 96 | //} 97 | //auto 98 | //Any::operator!=(const Any &o) const -> bool 99 | //{ 100 | // return not toCPP([_objc_object_ptr isEqual:o._objc_object_ptr]); 101 | //} 102 | 103 | 104 | 105 | 106 | 107 | 108 | EONIL_PLATFORM_APPLE_NAMESPACE_END 109 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/ObjectiveC/InternalRawStuffs/ClassTemplate.cpp: -------------------------------------------------------------------------------- 1 | //// 2 | //// ClassTemplate.cpp 3 | //// Cocoa++ 4 | //// 5 | //// Created by Hoon H. on 14/5/19. 6 | //// Copyright (c) 2014 Eonil. All rights reserved. 7 | //// 8 | // 9 | //#include "ClassTemplate.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/ObjectiveC/InternalRawStuffs/ClassTemplate.h: -------------------------------------------------------------------------------- 1 | //// 2 | //// ClassTemplate.h 3 | //// Cocoa++ 4 | //// 5 | //// Created by Hoon H. on 14/5/19. 6 | //// Copyright (c) 2014 Eonil. All rights reserved. 7 | //// 8 | // 9 | //#pragma once 10 | //#include "../Any.h" 11 | //EONIL_PLATFORM_APPLE_NAMESPACE_BEGIN 12 | //namespace 13 | //InternalRawStuffs 14 | //{ 15 | // 16 | // 17 | // 18 | // /*! 19 | // */ 20 | // template 21 | // class 22 | // ClassTemplate : public Any 23 | // { 24 | // 25 | // }; 26 | // 27 | // 28 | // 29 | //} 30 | //EONIL_PLATFORM_APPLE_NAMESPACE_END 31 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/ObjectiveC/InternalRawStuffs/ErrorCheck.h: -------------------------------------------------------------------------------- 1 | // 2 | // ErrorCheck.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../../Common.h" 11 | #include "../Any.h" 12 | EONIL_PLATFORM_APPLE_NAMESPACE_BEGIN 13 | namespace 14 | InternalRawStuffs 15 | { 16 | namespace 17 | ErrorCheck 18 | { 19 | using namespace Platform::Debugging; 20 | 21 | 22 | template 23 | inline auto 24 | crash_if_not_a_kind_of_class(Any anyone) -> void 25 | { 26 | id obj = anyone; 27 | BOOL ok = [obj isKindOfClass:[OBJC_TYPE class]]; 28 | crash_if(not ok, "The object is not expected type."); 29 | } 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | } 40 | } 41 | EONIL_PLATFORM_APPLE_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/ObjectiveC/InternalRawStuffs/ErrorCheck.mm: -------------------------------------------------------------------------------- 1 | // 2 | // ErrorCheck.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "ErrorCheck.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/ObjectiveC/None.h: -------------------------------------------------------------------------------- 1 | //// 2 | //// None.h 3 | //// Cocoa++ 4 | //// 5 | //// Created by Hoon H. on 4/20/14. 6 | //// Copyright (c) 2014 Eonil. All rights reserved. 7 | //// 8 | // 9 | //#pragma once 10 | //#include "../Common.h" 11 | //#include "Any.h" 12 | // 13 | //EONIL_PLATFORM_APPLE_NAMESPACE_BEGIN 14 | // 15 | // 16 | // 17 | // 18 | // 19 | // 20 | ///*! 21 | // Wraps semantics of Objective-C `nil` type. 22 | // */ 23 | //class 24 | //None : virtual public Any 25 | //{ 26 | //public: 27 | // None(); 28 | // None(None const&) = delete; 29 | // None(None&&) = delete; 30 | // 31 | //// auto operator=(None const&) -> None& = delete; 32 | //// auto operator=(None&&) -> None& = delete; 33 | //}; 34 | // 35 | // 36 | // 37 | // 38 | // 39 | // 40 | // 41 | // 42 | // 43 | // 44 | //EONIL_PLATFORM_APPLE_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/ObjectiveC/None.mm: -------------------------------------------------------------------------------- 1 | //// 2 | //// None.cpp 3 | //// Cocoa++ 4 | //// 5 | //// Created by Hoon H. on 4/20/14. 6 | //// Copyright (c) 2014 Eonil. All rights reserved. 7 | //// 8 | // 9 | //#include "None.h" 10 | // 11 | //EONIL_PLATFORM_APPLE_NAMESPACE_BEGIN 12 | // 13 | // 14 | // 15 | // 16 | // 17 | // 18 | // 19 | //None::None() : Any(nil) 20 | //{ 21 | //} 22 | // 23 | // 24 | // 25 | // 26 | // 27 | // 28 | // 29 | // 30 | // 31 | // 32 | //EONIL_PLATFORM_APPLE_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Application.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Application.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Application.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Application.h: -------------------------------------------------------------------------------- 1 | // 2 | // Application.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "Responder.h" 12 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | class 19 | Application : public Responder 20 | { 21 | 22 | }; 23 | 24 | 25 | 26 | 27 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Color.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Color.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Color.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Color.h: -------------------------------------------------------------------------------- 1 | // 2 | // Color.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | class 18 | Color : public Object 19 | { 20 | }; 21 | 22 | 23 | 24 | 25 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Common.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Common.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Common.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Common.h: -------------------------------------------------------------------------------- 1 | // 2 | // Common.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "../Common.h" 11 | #include "../Foundation/Object.h" 12 | #include "../Foundation/Data.h" 13 | #include "../Foundation/String.h" 14 | #include "../Foundation/Array.h" 15 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN 16 | 17 | 18 | 19 | 20 | 21 | using Object = Foundation::Object; 22 | using Data = Foundation::Data; 23 | using String = Foundation::String; 24 | using Array = Foundation::AnytypeArray; 25 | 26 | struct 27 | NonInstantiatable 28 | { 29 | NonInstantiatable() = delete; 30 | }; 31 | 32 | class Responder; 33 | class View; 34 | class TextView; 35 | class ScrollView; 36 | class Window; 37 | class Application; 38 | 39 | class 40 | DelegateBase : public Any 41 | { 42 | public: 43 | using Any::Any; 44 | virtual ~DelegateBase(); 45 | }; 46 | 47 | 48 | 49 | 50 | 51 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END 52 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Control.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Control.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Control.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Control.h: -------------------------------------------------------------------------------- 1 | // 2 | // Control.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "View.h" 12 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | class 19 | Control : public View 20 | { 21 | }; 22 | 23 | 24 | 25 | 26 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END 27 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Responder.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Responder.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Responder.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Responder.h: -------------------------------------------------------------------------------- 1 | // 2 | // Responder.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN 12 | 13 | 14 | 15 | 16 | 17 | class 18 | Responder : public Object 19 | { 20 | }; 21 | 22 | 23 | 24 | 25 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/ScrollView.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ScrollView.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "ScrollView.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/ScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ScrollView.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "View.h" 12 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | class 19 | ScrollView : public View 20 | { 21 | 22 | }; 23 | 24 | 25 | 26 | 27 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/TextView.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // TextView.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "TextView.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/TextView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TextView.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "ScrollView.h" 12 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | class 19 | Textview : public ScrollView 20 | { 21 | 22 | }; 23 | 24 | 25 | 26 | 27 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/View.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // View.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "View.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/View.h: -------------------------------------------------------------------------------- 1 | // 2 | // View.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "Responder.h" 12 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | class 19 | View : public Responder 20 | { 21 | 22 | }; 23 | 24 | 25 | 26 | 27 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Window.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Window.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Window.h" 10 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Apple/UIKit/Window.h: -------------------------------------------------------------------------------- 1 | // 2 | // Window.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/24. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include "Common.h" 11 | #include "View.h" 12 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_BEGIN 13 | 14 | 15 | 16 | 17 | 18 | class 19 | Window : public View 20 | { 21 | 22 | }; 23 | 24 | 25 | 26 | 27 | EONIL_PLATFORM_APPLE_UIKIT_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Debugging/Exception.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Exception.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Exception.h" 10 | #include 11 | namespace 12 | Eonil 13 | { 14 | namespace 15 | Platform 16 | { 17 | namespace 18 | Debugging 19 | { 20 | 21 | 22 | 23 | 24 | static char const* DOMAIN_NAME = "Eonil::Cococa"; 25 | 26 | 27 | 28 | 29 | 30 | 31 | auto 32 | error_if(bool const condition, std::string const& message) -> void 33 | { 34 | if (condition) 35 | { 36 | Error exc = Error(DOMAIN_NAME, message); 37 | std::cout << exc.what() << "\n"; 38 | throw exc; 39 | } 40 | } 41 | 42 | auto 43 | crash_if(bool const condition, std::string const& message) -> void 44 | { 45 | if (condition) 46 | { 47 | Crash exc = Crash(DOMAIN_NAME, message); 48 | std::cout << exc.what() << "\n"; 49 | throw exc; 50 | } 51 | } 52 | 53 | 54 | 55 | 56 | 57 | 58 | Error::~Error() 59 | { 60 | } 61 | 62 | Crash::~Crash() 63 | { 64 | } 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Sources/Eonil/Platform/Debugging/Exception.h: -------------------------------------------------------------------------------- 1 | // 2 | // Exception.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/5/19. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include 11 | 12 | namespace 13 | Eonil 14 | { 15 | namespace 16 | Platform 17 | { 18 | namespace 19 | Debugging 20 | { 21 | class 22 | Error : public Eonil::CommonRealtimeGameAlgorithms::Error 23 | { 24 | public: 25 | using Eonil::CommonRealtimeGameAlgorithms::Error::Error; 26 | 27 | Error(Error const&) = default; 28 | ~Error(); 29 | }; 30 | 31 | class 32 | Crash : public Eonil::CommonRealtimeGameAlgorithms::Crash 33 | { 34 | public: 35 | using Eonil::CommonRealtimeGameAlgorithms::Crash::Crash; 36 | 37 | Crash(Crash const&) = default; 38 | ~Crash(); 39 | }; 40 | 41 | 42 | static bool const USE_EXCEPTION_CHECKINGS = (EONIL_COMMON_REALTIME_GAME_ALGORITHMS_DEBUG_MODE == 1); // Performs only checkings with O(1) complexity. 43 | 44 | 45 | auto error_if(bool const cond, std::string const& message = Eonil::CommonRealtimeGameAlgorithms::EXCEPTION_DEFAULT_MESSAGE) -> void; 46 | auto crash_if(bool const cond, std::string const& message = Eonil::CommonRealtimeGameAlgorithms::EXCEPTION_DEFAULT_MESSAGE) -> void; 47 | 48 | 49 | 50 | } 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /TestApp/Test1.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Test1.cpp 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/27. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #include "Test1.h" 10 | #include "../Sources/Eonil/Platform/Apple/Cocoa.h" 11 | //#include "../Sources/Eonil/Platform/Apple/Cocoa.h" 12 | //#include "../Sources/Eonil/Platform/Apple/Cocoa.h" 13 | 14 | using namespace Eonil::CocoaCPP; 15 | using namespace Eonil::CocoaCPP::Foundation; 16 | using namespace Eonil::CocoaCPP::CoreAnimation; 17 | using namespace Eonil::CocoaCPP::AppKit; 18 | 19 | 20 | struct 21 | Test1::Core 22 | { 23 | using Rect = Eonil::CocoaCPP::AppKit::Rect; 24 | 25 | Window w1 {Window::window()}; 26 | View v2 {View::view()}; 27 | TableView tv3 {TableView::tableView()}; 28 | 29 | Core() 30 | { 31 | w1.setStyleMask(Window::STYLE::RESIZABLE | Window::STYLE::CLOSABLE | Window::STYLE::TITLED); 32 | w1.orderFront(); 33 | w1.makeKey(); 34 | w1.setFrame(Rect{0,0,300,300}, YES); 35 | 36 | // w1.contentView().addSubview(v2); 37 | // 38 | // v2.setFrame({0,0,200,200}); 39 | // v2.addSubview(tv3); 40 | // 41 | //// Layer l1 {Layer::layer()}; 42 | //// l1.setFrame({0,0,100,100}); 43 | //// l1.setBackgroundColor(Color::color({1,1,0,1}).CGColor()); 44 | //// v2.setWantsLayer(true); 45 | //// v2.setLayer(l1); 46 | // 47 | // TableColumn c1 {TableColumn::tableColume()}; 48 | // c1.setWidth(100); 49 | // c1.setHeaderCell(TableHeaderCell()); 50 | // tv3.addTableColumn(c1); 51 | // 52 | // tv3.setFrame({0,0,200,200}); 53 | 54 | TextView tv1 = TextView::Utility::textView(); 55 | tv1.setFrame({0,0,300,300}); 56 | 57 | ScrollView::Parameters sv1p = {}; 58 | sv1p.document = tv1; 59 | sv1p.scrollers.vertical = true; 60 | 61 | ScrollView sv1 = ScrollView::scrollViewWithParameters(sv1p); 62 | sv1.setFrame({0,0,300,300}); 63 | w1.contentView().addSubview(sv1); 64 | 65 | 66 | } 67 | }; 68 | 69 | 70 | 71 | Test1::Test1() : _core(new Core()) 72 | { 73 | } 74 | Test1::~Test1() 75 | { 76 | } 77 | -------------------------------------------------------------------------------- /TestApp/Test1.h: -------------------------------------------------------------------------------- 1 | // 2 | // Test1.h 3 | // Cocoa++ 4 | // 5 | // Created by Hoon H. on 14/4/27. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | #pragma once 10 | #include 11 | 12 | class 13 | Test1 14 | { 15 | struct Core; 16 | std::unique_ptr _core {}; 17 | 18 | public: 19 | Test1(); 20 | ~Test1(); 21 | }; 22 | 23 | 24 | -------------------------------------------------------------------------------- /TestApp/TestApp-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | 11 | #ifdef __cplusplus 12 | //#include "../Sources/Eonil/Platform/Apple/Cocoa.h" 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /TestApp/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TestApp 4 | // 5 | // Created by Hoon H. on 4/20/14. 6 | // Copyright (c) 2014 Eonil. All rights reserved. 7 | // 8 | 9 | 10 | #include "Test1.h" 11 | #include "../Sources/Eonil/Platform/Apple/Cocoa.h" 12 | 13 | 14 | using namespace Eonil::CocoaCPP::Foundation; 15 | using namespace Eonil::CocoaCPP::AppKit; 16 | 17 | struct 18 | AppDelegate1 : Application::Delegate 19 | { 20 | std::unique_ptr test1 = nullptr; 21 | 22 | MenuItem::ACTION quit = []() 23 | { 24 | Application::sharingApplication().terminate(); 25 | }; 26 | 27 | //// 28 | 29 | AppDelegate1() 30 | { 31 | } 32 | 33 | virtual ~AppDelegate1(); 34 | 35 | virtual inline auto 36 | applicationWillFinishLaunching() -> void 37 | { 38 | Menu m1 = Menu::menu(); 39 | Menu m2 = Menu::menu(); 40 | MenuItem mi1 = MenuItem::menuItem(); 41 | MenuItem mi2 = MenuItem::menuItem("Quit", quit, "q"); 42 | 43 | m1.addItem(mi1); 44 | mi1.setSubmenu(m2); 45 | m2.addItem(mi2); 46 | 47 | Application::sharingApplication().setMainMenu(m1); 48 | } 49 | virtual inline auto 50 | applicationDidFinishLaunching() -> void 51 | { 52 | test1 = std::unique_ptr(new Test1()); 53 | } 54 | }; 55 | 56 | 57 | AppDelegate1::~AppDelegate1() 58 | { 59 | } 60 | 61 | 62 | 63 | int main(int argc, const char * argv[]) 64 | { 65 | AppDelegate1 del1 = {}; 66 | Application app1 = Application::sharingApplication(); 67 | app1.setDelegate(&del1); 68 | app1.run(); 69 | } 70 | -------------------------------------------------------------------------------- /WEIRD STUFF EXPLANATIONS.md: -------------------------------------------------------------------------------- 1 | WEIRD STUFF EXPLANATIONS 2 | ======================== 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Why is there no direct method overriding? 14 | ---------------------------------------- 15 | First, the classes just a pointer wrapper, it's simple impossible to provide method overriding 16 | at the pointer level. The `this` pointer doesn't point actual Objective-C object. 17 | 18 | Method overriding is a real bad practice unless the method is pure virtual. (abstract/interface) 19 | I removed all the method overriding intentionally, and converted them all into observer pattern. 20 | Instead of method overriding, these stuffs will be provided. 21 | 22 | - Installable hooks. (instead of method overriding) 23 | - Event observer. (for delegate) 24 | - Callback lambda. (for target-action) 25 | 26 | You supply hooking map when creating an object, and the hooks will be called when the method is being called. 27 | I know this design has some limitation, but this provides far better robustness. 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 | --------------------------------------------------------------------------------