Copy and paste editbox
« on: 07 March 2017, 14:25:41 »
Hello,
sorry if this has been already discussed, I have used the search function but have not found anything.
My problem is to have an editbox where I can paste the string from the clipboard.

Any advice?

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Copy and paste editbox
« Reply #1 on: 07 March 2017, 14:31:56 »
TGUI has an internal clipboard that allows copying and pasting from one edit box to the other by just selecting text and pressing ctrl+c and ctrl+v.
On windows the system clipboard is also accessed so that you can copy things from other applications. On linux and mac accessing the system clipboard it is currently not supported so you can't paste things other than what you copied in tgui.

Re: Copy and paste editbox
« Reply #2 on: 07 March 2017, 14:34:05 »
Thank you, I use Windows.

Re: Copy and paste editbox
« Reply #3 on: 08 March 2017, 11:39:01 »
Sorry again, but I am only able to copy and paste from tgui editboxes. If I copy data from an externat text editor (for example) the paste is not performed on editbox. Is there something that I must enable?

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Copy and paste editbox
« Reply #4 on: 08 March 2017, 12:31:51 »
It should work out of the box, but it hasn't been tested for a long time (only briefly when the feature was added).

First of all make sure you are copying plain text data only by copying some text from notepad. Although I doubt it is the case, I think it is technically possible for a program to only put the formatted text in the clipboard without including the plain text.

What OS and compiler are you using?
Edit: could you also show a minimal example code that I can just copy-paste to test with?
« Last Edit: 08 March 2017, 12:34:08 by texus »

Re: Copy and paste editbox
« Reply #5 on: 08 March 2017, 13:49:53 »
I have made a simple test application, but it works perfectly, so I need to check in my code.
Btw running on Windows10 with Visual studio 2015 and tgui 0.7.3

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Copy and paste editbox
« Reply #6 on: 08 March 2017, 13:51:24 »
Do you set an sf::RendererWindow to the Gui in your code?

I realized that the clipboard won't work if you draw to an sf::RenderTexture as it needs a window to work.

Re: Copy and paste editbox
« Reply #7 on: 08 March 2017, 13:59:00 »
Yes, I set a RenderWindow. I noted that the "internal" tgui clipboard works, but not the windows one. So I can't even copy a string from the tgui editbox and paste in notepad.

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Copy and paste editbox
« Reply #8 on: 08 March 2017, 14:03:18 »
The gui should take care of attaching the system clipboard when you pass an sf::RenderWindow as parameter to gui.setWindow.
The only two reasons why this would not be done that I can think of is when you run the code on linux or mac or when you set a RenderTexture instead of a RenderWindow. But neither should be the case here.

You may want to try calling the following function in your own code and see if it helps:
tgui::Clipboard::setWindowHandle(yourSfmlRenderWindow.getSystemHandle());

Re: Copy and paste editbox
« Reply #9 on: 08 March 2017, 14:06:26 »
Adding

tgui::Clipboard::setWindowHandle(gui.getWindowHandle());

make it works.

Thank you very much.