bump product version to 7.2.5.1
[LibreOffice.git] / vcl / workben / pasteboard.mm
blob6a28430831b425cb5b9c7931618a7deff8521a2b
1 // -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*-
3 /*
4  * This file is part of the LibreOffice project.
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9  */
11 // List the contents of the macOS pasteboard
13 // Build with: clang++ -Wall -o pasteboard vcl/workben/pasteboard.mm -framework AppKit
15 #import <unistd.h>
17 #import <iostream>
18 #import <AppKit/AppKit.h>
20 static void usage()
22     std::cout << "Usage: pasteboard\n"
23                  "          List the types on the pasteboard and in each pasteboard item.\n"
24                  "       pasteboard -a\n"
25                  "          Output the data for all types to stdout. Note: output will\n"
26                  "          in many cases be binary. The different types are separated by a textual header.\n"
27                  "       pasteboard -t type\n"
28                  "          Output the data for the type in question to stdout. Note: output will\n"
29                  "          in many cases be binary.\n";
32 int main(int argc, char** argv)
34     NSString* requestedType;
36     int ch;
38     while ((ch = getopt(argc, argv, "at:")) != -1)
39     {
40         switch (ch)
41         {
42             case 'a':
43                 requestedType = @"*";
44                 break;
45             case 't':
46                 requestedType = [NSString stringWithUTF8String:optarg];
47                 break;
48             case '?':
49                 usage();
50                 return 0;
51         }
52     }
54     argc -= optind;
55     argv += optind;
57     if (argc > 0)
58     {
59         usage();
60         return 1;
61     }
63     NSPasteboard* pb = [NSPasteboard generalPasteboard];
65     if ([requestedType isEqualToString:@"*"])
66     {
67         NSArray<NSPasteboardType>* types = [pb types];
68         for (unsigned i = 0; i < [types count]; i++)
69         {
70             NSData* data = [pb dataForType:types[i]];
71             std::cout << i << ": " << [types[i] UTF8String] << ": " << std::to_string([data length]) << " bytes:\n";
72             if (data != nil)
73             {
74                 std::cout.write((const char*)[data bytes], [data length]);
75                 std::cout << "\n";
76             }
77         }
78         return 0;
79     }
81     if ([requestedType length] > 0)
82     {
83         NSData* data = [pb dataForType:requestedType];
85         if (data == nil)
86             std::cerr << "No data for " << [requestedType UTF8String] << std::endl;
87         else
88             std::cout.write((const char*)[data bytes], [data length]);
90         return 0;
91     }
93     {
94         NSArray<NSPasteboardType>* types = [pb types];
95         std::cout << "Types directly on pasteboard:\n";
96         for (unsigned i = 0; i < [types count]; i++)
97         {
98             std::cout << "  " << i << ": " << [types[i] UTF8String] << "\n";
99         }
100     }
102     NSArray<NSPasteboardItem*>* items = [pb pasteboardItems];
103     std::cout << "New-style items on pasteboard:\n";
105     for (unsigned i = 0; i < [items count]; i++)
106     {
107         std::cout << "  Item " << i << ", types:\n";
108         NSArray<NSPasteboardType>* types = [items[i] types];
109         for (unsigned j = 0; j < [types count]; j++)
110         {
111             std::cout << "    " << j << ": " << [types[j] UTF8String];
113             if ([types[j] isEqualToString:(NSString*)kUTTypePlainText] ||
114                 [types[j] isEqualToString:(NSString*)kUTTypeUTF8PlainText] ||
115                 [types[j] isEqualToString:(NSString*)kUTTypeText] ||
116                 [types[j] isEqualToString:(NSString*)kUTTypeHTML] ||
117                 [types[j] isEqualToString:(NSString*)kUTTypeRTF] ||
118                 [types[j] isEqualToString:(NSString*)kUTTypeUTF16ExternalPlainText])
119             {
120                 NSString* string = [items[i] stringForType:NSPasteboardTypeString];
121                 if ([string length] > 500)
122                     string = [[string substringToIndex:501] stringByAppendingString:@"..."];
123                 std::cout << ": '" << [string UTF8String] << "'";
124             }
125             std::cout << "\n";
126         }
127     }
129     return 0;
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */