loop through clipboard content ?

Hi there,

sometimes in a clipboard there are multiples items for representing a single value.
if you copy styled text, you have the styled text, but also the rtf or even the raw text in the clipboard.

how do you loop through all the items in the clipboard to choose the one you need ( to paste)
it seems the clipboard.rawdataavailable only checks the first item type
also clipboard.pictureavailable seems to returns false if the image type (jpg,png, or tiff) is not in the first position ?

is there a way to do this, just like you can do it with dragitems.

thanks.

Edit: macos (but would like win too) xojo 2019r11

In the example below:

[code]Dim s As String
s = TextArea1.Text // contains RTF

Dim c As Clipboard
c.AddRawData(s,“public.rtf”) // UTI
c.Close[/code]

You replacee public.rtf with the kind of data you want to set…

For getting Data, you use the “reverse instructions”:

If c.RawDataAvailable("public.text") Then TextField1.Text = c.RawData("public.text") End If c.Close

Is it clear ?

You cannot, as far as I’m aware, loop through all of the clipboard’s contents. I wish you could, but that’s currently not supported.

I do not talked about scanning (as in a loop): I only ask a kind of data (here rtf) from the Clipboard so the OS returned it to me, if available.

Edit:
Copy text in the Clipboard (from an application) and scan what there is in the Clipboard with the appropriate tool.

Example on MacOS El Capitan:
I copied the text above from Firefox,
fired the Apple Script Editor,$Typed clipboard info
and get:

{{«class utf8», 298}, {«class ut16», 598}, {string, 298}, {Unicode text, 596}}

First part: class kind of the data («class utf8[ and length of data 298 for example.

If you ask to get class ut16, you will get what you ask. You do not ask field #2 of the Clipboard contents.

And this is XPlatform (in the design); you only have to pass the correct type of data (above it was public.text or something else).

But they specifically asked about looping.

When I do not know how to ask, I ask what I think I have to do. In this case the question is wong and have this answer (to be refined with the kind of data you want to get back and it depends n the Platform).

I once get a totally different answer (regarding what I asked), and that was the correct answer, my question was not right (plain wrong, but the answer guy understoud what I wanted)…

I’m not saying you’re wrong, just that I’m not wrong, either. :wink:

2 not wrong’s don’t make a right :stuck_out_tongue:

(Sorry morning humor) :smiley:

No Brian, standard humor :wink:

Thanks for it !

[quote=449337:@Emile Schwarz]When I do not know how to ask, I ask what I think I have to do. In this case the question is wong and have this answer (to be refined with the kind of data you want to get back and it depends n the Platform).

I once get a totally different answer (regarding what I asked), and that was the correct answer, my question was not right (plain wrong, but the answer guy understoud what I wanted)…[/quote]

lol

The clipboard class in xojo is too basic to do something like that. You have to use Declares:

https://developer.apple.com/documentation/appkit/nspasteboard

https://docs.microsoft.com/en-us/windows/win32/dataxchg/clipboard

To summarize, there is no way to loop through all of the RawData stored in the clipboard with basic Xojo support. You need to get a list of the identifiers and check them using RawDataAvailable(Identifier), preferably in the order in which you would like to use them, until you find a suitable match. Then you’ll use RawData(Identifier) to retrieve the content for that identifier. Note that these identifiers will be different by platform. Just as an example:

On Windows, HTML is under the identifier “text/html”
On macOS, HTML is under the identifier “public.html”

I don’t think I’ve ever seen this issue. I’d open a Feedback Report.

Picture:
Same answer: the developer (Xojo developer) ask the OS the kind of object (Text or Picture) he want and the OS returns it if it exists in the Clipboard.

[quote=449350:@Emile Schwarz]Picture:
Same answer: the developer (Xojo developer) ask the OS the kind of object (Text or Picture) he want and the OS returns it if it exists in the Clipboard.[/quote]

I do believe they’re saying that there’s a picture object in the clipboard, but PictureAvailable is reporting false if something else is stored in the clipboard under a different identifier as well. This would be a bug.

@ Anthony:

You can add in the CLipboard a Text, a Picture, A Sound, (etc.) all at once. When you are not in charge of the development: say you use a text editor, the Text contents of the Clipboard will bepasted in the window.
Same apply for the Picture, Sound, etc.

There is no “I return the first object I have in the Clipboard” here.

If your application is in charge of the Clipboard and can deal with all of the above and there is all of the above: I do not knowwhat will be pasted, but I never get that in real life.

Now,
a after testing, if you can prove what you wrote, of course you can write a bug report,

b this is my experience based on more than 40 years of computing use. But I can be wrong, as some already understand using Cataline (as recent Conversations here shows).

c I only want to help, nothing else.

I’m going off of his statement that having multiple types of data stored, one of them being a picture, PictureAvailable returns False. I’m not sure what you’re driving at, but I’m just going to see myself out. Have fun.

to be clear.
I have a clipboard with “com.company.whatever”, then “public.tiff”, then “Next TIFF v4”
I want the tiff
if I ask c.pictureavailable I get false
if I ask rawdataavailable(“public.tiff”) I get false …
so I was hoping to be able to loop through the content of the clipboard.

or is it a bug ?

AFAIK, not really. But you can f.e. “store” RTF Text in the Clipboard and some OS will offer to “retrieve” it as RTF and as Plain Text f.e. There may be more cases which behave like this. But you App can only “store” 1 kind of object at once and multiple in multiple “store” tasks.

If the OS supports it or if an App is tied to the System Clipboard and stores each new item in a “cache”, the OS or the App can offer more then just the latests stored item.

this is precisely the problem I have

I would build a small example project and report it. This is definitely not a bug I’d like to bump up against.

[quote=449346:@Ivan Tellez]The clipboard class in xojo is too basic to do something like that. You have to use Declares:
https://developer.apple.com/documentation/appkit/nspasteboard
https://docs.microsoft.com/en-us/windows/win32/dataxchg/clipboard [/quote]
nice.
do you have one also for linux ? does even linux handle multiple clipboard content ?