Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Native Development

Reply
Developer
p3pp3r
Posts: 157
Registered: ‎12-16-2010
My Carrier: I carry it myself

How can I programmatically copy and paste?

Subject says it all ;-)

----------
If you find this post helpful please "like" it and accept as a solution.
Please use plain text.
Developer
peter9477
Posts: 5,616
Registered: ‎12-08-2010
My Carrier: none

Re: How can I programmatically copy and paste?

Look in clipboard/clipboard.h and libclipboard.so

I don't see where the docs are yet though, but that may be enough for you.

Peter Hansen -- (PlayBook and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
BGmot
Posts: 956
Registered: ‎11-24-2011
My Carrier: x

Re: How can I programmatically copy and paste?

Just curious - what are you trying to copy paste in your app?

Please use plain text.
Trusted Contributor
bdaemon
Posts: 142
Registered: ‎02-23-2011
My Carrier: uc

Re: How can I programmatically copy and paste?

As I Need, copy pic to doc to go , I not sure it is possible.

copy Chinese to native app.
Please use plain text.
Developer
dbigham
Posts: 318
Registered: ‎04-01-2009
My Carrier: Rogers

Re: How can I programmatically copy and paste?

I tried:

 

if (is_clipboard_format_present("text/html"))
{
int len = get_clipboard_data("text/html", &data);

if (len == -1)
{
// Error
fprintf(stderr, "Error in get_clipboard_data: %s\n", strerror(errno));
}
else
{
fprintf("Length: %i\n", len);
}
}

 

...

 

And I get the error:

 

Error in get_clipboard_data: No such file or directory

 

Is there really no documentation on how to use the cipboard in the NDK? Oy.

 

Not sure if set_clipboard_path is required.  It's strange that is_clipboard_format_present returns true and yet get_clipboard_data blows up.

Please use plain text.
Developer
peter9477
Posts: 5,616
Registered: ‎12-08-2010
My Carrier: none

Re: How can I programmatically copy and paste?

Try using get_clipboard_data("text.html", &data) instead, without the forward slash.

 

If that works, I'll tell you how I figured that out...


Peter Hansen -- (PlayBook and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
dbigham
Posts: 318
Registered: ‎04-01-2009
My Carrier: Rogers

Re: How can I programmatically copy and paste?

Please use plain text.
Developer
dbigham
Posts: 318
Registered: ‎04-01-2009
My Carrier: Rogers

Re: How can I programmatically copy and paste?

Also to note that if I use get_clipboard_path, it gives:

 

/accounts/1000/clipboard

Please use plain text.
Developer
peter9477
Posts: 5,616
Registered: ‎12-08-2010
My Carrier: none

Re: How can I programmatically copy and paste?

Yeah, I was just catching up to you on that. Same path here.  Have you looked in it (via SSH) to see what's there?

 

On mine, when I've copied something in an AIR app text field, I get a file "text.plain" in that folder.  I also tried replying to an email in the Messages app and selected a range of text there and copied it, and "text.html" and "text.url" both showed up.  The text.url file contains "file:///" while the html one contains a bunch of HTML stuff containing what I clipped. Not sure what the text.url one is supposed to mean.

 

It's interesting you're getting a true result from is_clipboard_format_present(). I'm getting a zero result even with what I see in that folder.


Peter Hansen -- (PlayBook and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
peter9477
Posts: 5,616
Registered: ‎12-08-2010
My Carrier: none

Re: How can I programmatically copy and paste?

Ah... hah!  As soon as I wrote that I double-checked the clipboard.h file and you've mixed up the return value from that.  Getting a true value actually means the format is NOT present.  You get a zero if it's present.

 

 * @return
 *  0 if it exists, -1 otherwise. errno is set.

I'm getting a zero whether I use "text.plain" or "text/plain" so maybe it's not an issue of using "." vs "/".

 

And get_clipboard_data() is working fine for me with "text/plain" in there, as well as "text.plain".


Peter Hansen -- (PlayBook and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.