From fc036f2c97c84a02647d85ba54b1db1e1aa76a9c Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Tue, 23 Jul 2019 18:15:56 +0200 Subject: [PATCH] Implement Application::copyToClipboard for iOS --- docs/docs/reference/foundation/application.md | 4 ++++ framework/foundation/include/bdn/Application.h | 1 + framework/foundation/include/bdn/GenericApplication.h | 2 ++ framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh | 2 ++ framework/ui/platforms/ios/src/UIApplication.mm | 6 ++++++ 5 files changed, 15 insertions(+) diff --git a/docs/docs/reference/foundation/application.md b/docs/docs/reference/foundation/application.md index 431fff31..eaf77a07 100644 --- a/docs/docs/reference/foundation/application.md +++ b/docs/docs/reference/foundation/application.md @@ -74,6 +74,10 @@ namespace bdn { Opens the given URL in a suitable external application. Web URLs will be opened in the system's standard web browser. Application-specific URLs will open in the respective application. +* **virtual void copyToClipboard(const String &str)** + + Copies the given string to the clipboard. + ## Resources * **virtual String uriToBundledFileUri(const String &uri)** diff --git a/framework/foundation/include/bdn/Application.h b/framework/foundation/include/bdn/Application.h index 39707475..b09f24f9 100644 --- a/framework/foundation/include/bdn/Application.h +++ b/framework/foundation/include/bdn/Application.h @@ -53,6 +53,7 @@ namespace bdn public: virtual void openURL(const String &url) = 0; virtual String uriToBundledFileUri(const String &uri) { return uri; } + virtual void copyToClipboard(const String &str) = 0; protected: virtual void platformSpecificInit() {} diff --git a/framework/foundation/include/bdn/GenericApplication.h b/framework/foundation/include/bdn/GenericApplication.h index ead0984b..790ef11d 100644 --- a/framework/foundation/include/bdn/GenericApplication.h +++ b/framework/foundation/include/bdn/GenericApplication.h @@ -70,6 +70,8 @@ namespace bdn void openURL(const String &url) override {} + void copyToClipboard(const String &str) override {} + protected: virtual bool shouldExit() const { diff --git a/framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh b/framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh index 6d8e4fa2..0ef7ab85 100644 --- a/framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh +++ b/framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh @@ -22,6 +22,8 @@ namespace bdn::ui::ios String uriToBundledFileUri(const String &uri) override; + void copyToClipboard(const String &str) override; + public: bool _applicationWillFinishLaunching(NSDictionary *launchOptions); bool _applicationDidFinishLaunching(NSDictionary *launchOptions); diff --git a/framework/ui/platforms/ios/src/UIApplication.mm b/framework/ui/platforms/ios/src/UIApplication.mm index dd9b7411..0687d8cc 100644 --- a/framework/ui/platforms/ios/src/UIApplication.mm +++ b/framework/ui/platforms/ios/src/UIApplication.mm @@ -150,6 +150,12 @@ - (void)applicationWillTerminate:(UIApplication *)application return "file:///" + result; } + void UIApplication::copyToClipboard(const String &str) + { + UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; + pasteboard.string = [NSString stringWithUTF8String:str.c_str()]; + } + bool UIApplication::_applicationWillFinishLaunching(NSDictionary *launchOptions) { bdn::platformEntryWrapper(