Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to figure out the correct format? #26

Open
AsafMah opened this issue Feb 20, 2023 · 3 comments
Open

How to figure out the correct format? #26

AsafMah opened this issue Feb 20, 2023 · 3 comments

Comments

@AsafMah
Copy link

AsafMah commented Feb 20, 2023

There are a few formats to choose from, how can I know which ones are available before extracting?

I saw EnumFormats in the raw crate, but that seems too low level - it returns the underlying formats and not the ones defined in this crate.

@DoumanAsh
Copy link
Owner

DoumanAsh commented Feb 20, 2023

Actually, your approach normally is to be on look out for particular formats, that you need.
But if you really want to enumerate all (currently on clipboard, not just all), then you have to use EnumFormats.

it is iterator that returns raw id of format and you can compare it with constants
On side note, winapi guarantees that EnumFormats will yield formats in order of placement on clipboard.
So if for example you'd want to fetch data in ordered manner you could start fetching from first value within this iterator would be format that you look for.
For more details, please read winapi documentation on EnumClipboardFormats

Aside from some specific esoteric formats, most are pretty much self-explatory

So if you have list of formats that you want to look out for, you can use: is_format_avail to query every format on list
But if you just want to enumerate all available then you use EnumFormats

@AsafMah
Copy link
Author

AsafMah commented Feb 20, 2023

What I was looking for is some mapping from these lower level formats to the higher level ones, It says bitmap corresponds to CF_BITMAP, but it would be nice to have the same EnumFormats and is_format_avail also at the higher level module, that would work with FileList and such.

Maybe even a method that returns all of the data in each available format.

I can implement it myself for my project, but I think it's a bit of a hole in the API.

@DoumanAsh
Copy link
Owner

I can create API like this:

pub trait OnEnumerator {
    fn on_string(text: String) -> {}
    fn on_file_list(...) -> {}
    //etc
}

But that's not exactly convenient for use, but anything else would be inherently wasteful or overly complicated, and there is honestly little reason to enumerate all possible formats.
Outside of text, images or file lists, there is really not a lot of useful stuff in clipboard
Not to memtion issue of custom formats that every application can create makes it inherently impossible to make API that would fit it all.

If you can come up with API feel free to propose, but I do not really see much use when you can just iterate over formats and match on format identifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants