Clipboard RawData on Mac

I read: http://developer.xojo.com/userguide/multimedia-clipboard and it say:

[quote]Dealing with Raw Data in the Clipboard
Raw data refers to any data that is not text or is not a picture. This allows you to put any type of data you want in the clipboard. Only your own apps will be able to parse this data, however.[/quote]

And I was wondering why only my own apps will be able to parse this data and not be able to paste the information on other app. So I did some tests.

On mac, this code:

c.AddRawData(TextArea1.StyledText.RTFData, "RTF") If c.RawDataAvailable("RTF") Then TextArea2.StyledText.RTFData = c.RawData("RTF") End If
will not let you Paste to other apps.

But this code:

c.AddRawData(TextArea1.StyledText.RTFData, "public.rtf") If c.RawDataAvailable("public.rtf") Then TextArea2.StyledText.RTFData = c.RawData("public.rtf") End If
will let you paste (tested with Word).

Don’t know if there are similar values for Windows or Linux.

Thanks to ShowClipboards app I found the “public.rtf” value.

1 Like

Good info, Albert. I’ve updated that page to make things clearer.

Thank you @Paul Lefebvre I read your changes and tried the code, I still needed to change:

If c.RawDataAvailable("RTF") Then

to

If c.RawDataAvailable("public.rtf") Then

to make it work

Missed that one! Should be fixed now.

Tip:

If you have a Styled TextArea and you use the mac’s Copy, the clipboard will have this values:

  • public.rtf
  • utf8
  • TEXT

but if you only do c.AddRawData(TextArea1.StyledText.RTFData, "public.rtf") you will only have public.rtf value there. If you want to have also utf8 and TEXT, you can add the line:

c.Text = TextArea1.Text

it must be after c.AddRawData

You do understand that the order in which you add items to the pasteboard does ALWAYS matter? You need to add the richest format first, i.e. if you have text both in rich (RTF) and plain text format, add the RTF first. Some for other alternative formats.

BTW, if you keep posting macOS-specific questions, please move them to the Targets / Mac channel.

Sorry, I was wrong and I can’t change my last post,

c.Text = TextArea1.Text

could go before or after

c.AddRawData(TextArea1.StyledText.RTFData, "public.rtf")

I can Paste the StyledText to Word either way and see both on the mac’s clipboard. The only difference that I can see is that ShowClipboards app list first whatever is put first. Interesting that TEXT is always listed in third place, maybe an internal thing.

Note: moved this and other thread to Targets / macOS

Try adding a space after the “RTF”

c.AddRawData(TextArea1.StyledText.RTFData, "RTF ")

Remember:
You put data in the Clipboard, but you cannot do anything on how applications (Word, your example) or the OS (macOS here) deal with the Clipboard.

Also, taking a Microsoft application for your test is not really a good example (this is a 30 years experiment result).
You better use a pannel of current versions (Mojave) of applications: differences can occured inside of the same application thru theiits versions.

I understand you are making tests for knowledge; but what happens in real life use (still using Mojave compatible ap^lications / with macOS Mojave) ?

If you get troubles with the way the text “return” is done, use ReplaceLineEndings to make your code working (that is why Xojo add that Method to the Xojo IDE).

Return is not always Chr(13); End of Paragraph is not Return (even if visually it can looks the same.
Here I will use Word to explain: in Word you had (still have ?) a command to display the invisible characters. In a document, add a Return, an end of paragraph character and look at their visual look: they are different. (their hex value too).

Thank you Emile for taking the time to post, all valid points and good recommendations.

[quote=409207:@Emile Schwarz]Remember:
You put data in the Clipboard, but you cannot do anything on how applications (Word, your example) or the OS (macOS here) deal with the Clipboard.[/quote]
Correct, I just found a way to put RTF data into the clipboard for other apps to use. Thanks to Jonathan I found out that it was easier to do just be using "RTF " and not “RTF”, so no need of “public.rtf” (but that works too). If the other apps in macOS can handle the RTF copied from Styled TextArea is another issue, some may fail.

[quote]Also, taking a Microsoft application for your test is not really a good example (this is a 30 years experiment result).
You better use a pannel of current versions (Mojave) of applications: differences can occured inside of the same application thru theiits versions.[/quote]
I’m not a professional programmer, so testing Mojave is not a priority. I understand what you are saying, I dedicated many hours documenting a “bug” that was macOS 10.12.6 problem and not Xojo’s. When I was able to test the code with High Sierra I was not able to reproduce the problem while with Sierra I can reproduce it at will.

Yes, test is how I understand things and once I understand them I can learn/remember things more easily. Also I can find other ways to do things if the “as designed” is not the same as “what I expect”.

ReplaceLineEndings is a great thing to have but I think that also helps to keep some bugs without fixing. More about this on next paragraph.

[quote]Return is not always Chr(13); End of Paragraph is not Return (even if visually it can looks the same.
Here I will use Word to explain: in Word you had (still have ?) a command to display the invisible characters. In a document, add a Return, an end of paragraph character and look at their visual look: they are different. (their hex value too).[/quote]
It was hard for me to understand all the EndOfLine options, mostly because I never knew there were several and because I can’t see them as I can see the character ‘a’. After reading EndOfLine docs I expected EndOfLine on mac to be Chr(10), at least most of the time. To my surprise, if I use Xojo’s Clipboard to put Chr(10) there it always return as Chr(13). Thanks to my tests and ShowClipboards app, I found that this code:

Dim c as New Clipboard c.Text = "1" + EndOfLine + "2"
will create 2 clipboard objects, “utf8” and “TEXT”. utf8 has the expected chr(10) as EndOfLine and TEXT has chr(13).
utf8 is also named public.utf8-plain-text and TEXT com.apple.traditional-mac-plain-text
I expected this code to get chr(10) but always got back chr(13) on mac (Windows and Linux work ok):

Dim s As String = c.Text

I guess Xojo’s mac clipboard check the TEXT value and not the utf8 value. I reported that with a Feedback case and I know they can close it “as designed”, but know is not a problem for me, because I know that it creates the utf8 value on the clipboard, so I can get the value from there, just have to change the previous code to:

Dim s As String = DefineEncoding(c.RawData("utf8"), Encodings.UTF8)

this way I get chr(10), the same EndOFLine copied originally to the clipboard. So even if Xojo say “as designed” I can change my code to make it work as I expect.

This will work on Windows, Linux and Mac:

Dim c As New Clipboard c.Text = "1" + EndOfLine + "2" #if TargetMacOS Then Dim s As String = DefineEncoding(c.RawData("utf8"), Encodings.UTF8) #Else Dim s As String = c.Text #Endif
Mac, expected chr(10) and now I get chr(10) instead of chr(13).
Linux, expected chr(10), chr(10) returned
Windows, expected chr(13)+chr(10), and I get that.

If Xojo say, yes, newer macOS use chr(10) and we should check utf8 instead of TEXT, then great, I can use c.Text directly, if not, then there is a way.

I may never use the clipboard in one of my apps, and just use the system’s copy/paste, but because I want to learn more about things that Xojo offer, that’s why my interest to learn about the clipboard, line endings, #If and other things. If I found something that I don’t understand/expect, then I do tests until it make sense or report my findings so Xojo can decide if things are working like they want or they could change something to make it work more like I initially expected to work.

As far as I understand, you do not read Apple programming documentation :frowning:

One cannot understand by looking at the code what I meant by Return and EndOfParagraph excepted:

a. if you ask Word to display invisible characters (you have to search and reach the correct nae in your Word),
b. actually use it when working with Word (writing books for example).

Just like the Tab character. Its value is Chr(9), but how is it coded in Word (for example) when you use the Alignment tags ?
a. Left Align (standard alignment in our Roman script)
b. Right Align,
c. Centered,
d. Decimal point Align ?
(And I may forget some)

Again, the documentation is welcome.

There exists a file Reference for RTF (from Microsoft) that is around 1MB…
This string will return valid URLs:
Microsoft RTF Reference Manual

Only download Microsoft documents; other sourced documentation my not be accurate (usually is not, but exceptionsmay occured).

At last, User Documentation was nice too, but they do not exists nowadays (if you find a “macOS User’s Guide” for MacOS 6, 7, 8, or 9 flavors… take it).

Remember: errors un deductions (wrongly understanding what you read) is common.

I walked that road when I started in computing (Apple Computers) in the early 80s. I never do that for Windows nor Linux.

Regards,
Emile

Thank you Emile for your information, I think we are talking about different things and at different levels, or just simply I don’t understand what you are trying to tell me.

I’m not a professional programmer and will never be one. I will be, at most, a citizen programmer (I hope that is the correct definition). So no, I haven’t read Apple programming documentation.

I’m not trying to create a complete compatible RTF clipboard control application that can work on macOS. I’m not even creating the RTF, I just used StyledText example and used Xojo’s clipboard commands. I don’t even fully understand the StyledText example.

What I did is just simple tests and report what I found:

  • Xojo clipboard.text always return chr(13) when Xojo or mac’s Edit-Copy put chr(10) there, and documented my findings
  • Xojo multimedia-clipboard documentation said that Raw Data is only available on your (Xojo) apps, and I found that the StyledText of a TextArea could be put on mac’s pasteboard/clipboard for other apps to use (yes, tested on Word and Notes, for Notes I had to use ‘Paste and Retain Style’ for the text to match Xojo’s TextArea StyledText), I don’t know if it will work for other apps or even if Xojo’s RTF is the same as what macOS detect. At least Paul found it interesting enough to change that document.

So no, I don’t understand why I want to read Apple programming documentation or Microsoft RTF Reference Manual. I don’t know if I will ever use RTF, in fact I’m changing TextArea Styled to OFF.

I’m sorry I don’t understand, maybe when I learn more things about Xojo and programming will get it.

Best regards,
Alberto