FXRuby and clipboard contents

I’m experimenting with FXRuby, and would like to grab the contents of
whatever is on the clipboard and put it in a text box. I’m developing
on windows, and based on what I’ve found searching around it seems
like I might have to do some OLE-integration api calls.

That’s a little disappointing - is there a way to access the contents
of the clipboard in a portable way?

Regards,
Steve

Steve wrote:

I’m experimenting with FXRuby, and would like to grab the contents of
whatever is on the clipboard and put it in a text box. I’m developing
on windows, and based on what I’ve found searching around it seems
like I might have to do some OLE-integration api calls.

That’s a little disappointing - is there a way to access the contents
of the clipboard in a portable way?

If I understand what you want to do, FXRuby’s FXText and FXTextField
widgets already support pasting from the Windows clipboard out of the
box. For example, try starting up one of the FXRuby example programs
with a text field (maybe the splitter.rb example), then cut or copy some
text out of some other Windows application (say, NOTEPAD). Then click in
the FXRuby text field and press Ctrl+V (for paste). Note that you can
also go the other way (using Ctrl+C or Ctrl+X to copy or cut from an
FXRuby text widget onto the Windows clipboard).

Lyle Johnson wrote:

Steve wrote:

I’m experimenting with FXRuby, and would like to grab the contents of
whatever is on the clipboard and put it in a text box. I’m developing
on windows, and based on what I’ve found searching around it seems
like I might have to do some OLE-integration api calls.

That’s a little disappointing - is there a way to access the contents
of the clipboard in a portable way?

If I understand what you want to do, FXRuby’s FXText and FXTextField
widgets already support pasting from the Windows clipboard out of the
box. For example, try starting up one of the FXRuby example programs
with a text field (maybe the splitter.rb example), then cut or copy some
text out of some other Windows application (say, NOTEPAD). Then click in
the FXRuby text field and press Ctrl+V (for paste). Note that you can
also go the other way (using Ctrl+C or Ctrl+X to copy or cut from an
FXRuby text widget onto the Windows clipboard).

My impression was that he wanted to do it “programmatically” without
doing a paste, e.g.,

text = FXfoobarWindowsStuff.clipboard.get # or whatever
FXfoobarWindowsStuff.clipboard.copy(“Hello!”) # “Hello!” into clipbd

I’ve also been interested in this but have never asked.

Hal

Hal Fulton wrote:

My impression was that he wanted to do it “programmatically” without
doing a paste, e.g.,

text = FXfoobarWindowsStuff.clipboard.get # or whatever
FXfoobarWindowsStuff.clipboard.copy(“Hello!”) # “Hello!” into clipbd

I’ve also been interested in this but have never asked.

Oh, OK. Let me do some research and see exactly how that’s being done
and come up with some sample code. I think the basic data transfer
protocol is along the same lines as that described in the FXRuby
drag-and-drop tutorial, but simplified somewhat.

Hal Fulton hal9000@hypermetrics.com wrote in message news:3F512090.60105@hypermetrics.com

My impression was that he wanted to do it “programmatically” without
doing a paste, e.g.,

text = FXfoobarWindowsStuff.clipboard.get # or whatever
FXfoobarWindowsStuff.clipboard.copy(“Hello!”) # “Hello!” into clipbd

I’ve also been interested in this but have never asked.

Hal

Yep, that’s exactly what I’d like to do.

By the way Hal, I really enjoyed your book, it’s an excellent resource.

Regards,
Steve Conover

Lyle Johnson wrote:

Hal Fulton wrote:

My impression was that he wanted to do it “programmatically” without
doing a paste, e.g.,

text = FXfoobarWindowsStuff.clipboard.get # or whatever
FXfoobarWindowsStuff.clipboard.copy(“Hello!”) # “Hello!” into clipbd

I’ve also been interested in this but have never asked.

Oh, OK. Let me do some research and see exactly how that’s being done
and come up with some sample code. I think the basic data transfer
protocol is along the same lines as that described in the FXRuby
drag-and-drop tutorial, but simplified somewhat.

Well, I hope I didn’t misrepresent what the original poster
wanted.

FYI, the app I was thinking of is a simple one – a cut&paste program
that will allow me to cut on my Windows box and paste on my Linux
box (or vice versa). It’s on my to-do list. Could use drb for
communication, shouldn’t be hard. Hardest part (as usual) would be
the GUI.

Hal

text = FXfoobarWindowsStuff.clipboard.get # or whatever
FXfoobarWindowsStuff.clipboard.copy(“Hello!”) # “Hello!” into clipbd

Yep, that’s exactly what I’d like to do.

To roll your own Ruby extension in C –

If you are just talking about cut and pasting “plain text” (i.e. Windows
clipboard format CF_TEXT), then it should be relatively straightforward.

To get data, you’ll need some low-level code to open the clipboard, get the
handle to the clipboard data you want in the format you want, copy the data
as a string, unlock the handle, and close the clipboard. The FOX C++ source
code will show you the basic game plan.

In the FOX world –

In the underlying FOX C++ code, there are the below FXApp methods:

clipboardSetData
clipboardGetData
clipboardGetTypes

For example, from fxpriv.cpp –

void FXApp::clipboardGetData(const FXWindow* window,FXDragType
type,FXuchar*& data,FXuint& size){
data=NULL;
size=0;
if(IsClipboardFormatAvailable(type)){
if(OpenClipboard((HWND)window->id())){
HANDLE hClipMemory=GetClipboardData(type);
if(hClipMemory){
size=(FXuint)GlobalSize(hClipMemory);
if(FXMALLOC(&data,FXuchar,size)){
void pClipMemory=GlobalLock(hClipMemory);
FXASSERT(pClipMemory);
memcpy((void
)data,pClipMemory,size);
GlobalUnlock(hClipMemory);
CloseClipboard();
FXTRACE((100,“Window %d requested CLIPBOARD DATA of type %d from
remote; got %d bytes\n”,window->id(),type,size));
}
}
}
}
}

In the FXRuby world –

Reading the online API documentation (www.fxruby.org), it looks like
FXRuby’s implementation of FXApp doesn’t include the clipboard methods from
FOX C++.

In the FXRuby distribution, the textedit.rb sample does support Copy and
Paste, both to and from the Windows clipboard. So there definitely is some
sort of FXText-based (and possibly FXWindow-based) cut/copy/paste clipboard
support in the current FXRuby. I’d look into the methods onClipboardRequest,
onClipboardGained, and onClipboardLost (and what events they are associated
with) to gain further understanding. The methods are referenced in the SWIG
wrapper FXText.i and FXWindow.i.

Lyle Johnson of FXRuby (a rather amazing effort, by the way) would be the
one to talk to about getting the proper methods and other little pieces you
need added from the base FOX toolkit into FXRuby. I’m afraid I can’t help
much as I’m already lost in the jungle of SWIGly code :wink:

–ms

Steve wrote:

Hal Fulton hal9000@hypermetrics.com wrote in message news:3F512090.60105@hypermetrics.com

My impression was that he wanted to do it “programmatically” without
doing a paste, e.g.,

text = FXfoobarWindowsStuff.clipboard.get # or whatever
FXfoobarWindowsStuff.clipboard.copy(“Hello!”) # “Hello!” into clipbd

I’ve also been interested in this but have never asked.

Hal

Yep, that’s exactly what I’d like to do.

By the way Hal, I really enjoyed your book, it’s an excellent resource.

Thanks, Steve. Credit also goes to the five people who contributed
code or text to it, to the two tech editors, and several other people at
the publisher.

I’d like to think there’ll be a second edition. As things stand now,
that’s not likely. Cross your fingers for me.

Hal

In the FXRuby distribution, the textedit.rb sample does support Copy and
Paste, both to and from the Windows clipboard. So there definitely is some
sort of FXText-based (and possibly FXWindow-based) cut/copy/paste clipboard
support in the current FXRuby. I’d look into the methods onClipboardRequest,
onClipboardGained, and onClipboardLost (and what events they are associated
with) to gain further understanding. The methods are referenced in the SWIG
wrapper FXText.i and FXWindow.i.

I tested this with an FXText object:

textwidget.handle(textwidget, MKUINT(FXText::ID_PASTE_SEL,
SEL_COMMAND), nil)

and it works great. I’ve only used this on windows, maybe someone can
confirm that it works on Linux too…

This is what I was looking for - thanks everyone.

Regards,
Steve