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.

inside custom component

Native Development

Reply
Developer
Posts: 157
Registered: ‎12-16-2010
My Device: Torch 9800, PlayBook
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.
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
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 -- (BB10 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!
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: How can I programmatically copy and paste?

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

Trusted Contributor
Posts: 152
Registered: ‎02-23-2011
My Device: dev alpha playbook 9500 8300
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.
Developer
Posts: 580
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

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.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
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 -- (BB10 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!
Developer
Posts: 580
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: How can I programmatically copy and paste?

Developer
Posts: 580
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: How can I programmatically copy and paste?

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

 

/accounts/1000/clipboard

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
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 -- (BB10 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!
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
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 -- (BB10 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!