vcl/workben/pasteboard.mm | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
New commits: commit feb6a4b2c52edcf1da198c98e96fb11fe88deb66 Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Thu Jan 14 13:18:22 2021 +0200 Commit: Tor Lillqvist <t...@collabora.com> CommitDate: Thu Jan 14 12:27:24 2021 +0100 Add a tiny program to list the contents of the macOS pasteboard Change-Id: I78933f18a80140e9ccacabd6243716205b530c43 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109271 Tested-by: Tor Lillqvist <t...@collabora.com> Reviewed-by: Tor Lillqvist <t...@collabora.com> diff --git a/vcl/workben/pasteboard.mm b/vcl/workben/pasteboard.mm new file mode 100644 index 000000000000..b38b19387602 --- /dev/null +++ b/vcl/workben/pasteboard.mm @@ -0,0 +1,61 @@ +// -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- + +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// List the contents of the macOS pasteboard + +// Build with: clang++ -Wall -o pasteboard vcl/workben/pasteboard.mm -framework AppKit + +#import <iostream> +#import <AppKit/AppKit.h> + +int main(int argc, char** argv) +{ + NSPasteboard* pb = [NSPasteboard generalPasteboard]; + + { + NSArray<NSPasteboardType>* types = [pb types]; + std::cout << "Types directly on pasteboard:\n"; + for (unsigned i = 0; i < [types count]; i++) + { + std::cout << " " << i << ": " << [types[i] UTF8String] << "\n"; + } + } + + NSArray<NSPasteboardItem*>* items = [pb pasteboardItems]; + std::cout << "New-style items on pasteboard:\n"; + + for (unsigned i = 0; i < [items count]; i++) + { + std::cout << " Item " << i << ", types:\n"; + NSArray<NSPasteboardType>* types = [items[i] types]; + for (unsigned j = 0; j < [types count]; j++) + { + std::cout << " " << j << ": " << [types[j] UTF8String]; + + if ([types[j] isEqualToString:(NSString*)kUTTypePlainText] || + [types[j] isEqualToString:(NSString*)kUTTypeUTF8PlainText] || + [types[j] isEqualToString:(NSString*)kUTTypeText] || + [types[j] isEqualToString:(NSString*)kUTTypeHTML] || + [types[j] isEqualToString:(NSString*)kUTTypeRTF] || + [types[j] isEqualToString:(NSString*)kUTTypeUTF16ExternalPlainText]) + { + NSString* string = [items[i] stringForType:NSPasteboardTypeString]; + if ([string length] > 500) + string = [[string substringToIndex:501] stringByAppendingString:@"..."]; + std::cout << ": '" << [string UTF8String] << "'"; + } + std::cout << "\n"; + } + } + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits