Copy string / listbox item to clipboard?

BlitzMax Forums/MaxGUI Module/Copy string / listbox item to clipboard?

Grisu(Posted 2014) [#1]
Hi!

I know that there's the gadgetcopy command for textareas. The following simple example code demonstrates one can copy the selected text to the clipboard under Windows:



Is there a way to copy a custom string / listbox item to the clipboard (Windows/Mac/Linux) directly?

I could create a hidden textarea, add my custom text, select the text and copy it to the clipboard afterwards. But that's not very elegant nor effective. The current code only works for Windows!

|Edit2| MacOS code further down, Linux support via Brucey's GTK Module.

Grisu


SebHoll(Posted 2014) [#2]
It shouldn't be too hard to add a SetClipboardText(), ClipboardText() API on Mac OS X and Windows. Linux would need some research though.


Grisu(Posted 2014) [#3]
I managed to set up the code for Windows (see first post).

Has anyone some code for Mac?


Brucey(Posted 2014) [#4]
These functions should really be part of a system/gui driver, rather than adding more global functions.


And on the other hand, UserName$() and ComputerName$() have *nothing* to do with being in a MaxGUI driver...
Or does one really only have access to that information when you have a window open? hmmm...


Grisu(Posted 2014) [#5]
I see your point.

But before adding such stuff to the system driver, we would need a cross-platform solution first?!


d-bug(Posted 2014) [#6]
For MacOS we need a Objective-C solution:


Save this file as "macos_clipboard.m" next to the saved sample.

Modified sample from first post:



Thats it!


Henri(Posted 2014) [#7]
Nicely done. Do we still need one for Linux ?

-Henri


Brucey(Posted 2014) [#8]
Do we still need one for Linux ?

No, I don't think anyone uses BlitzMax on Linux, so I wouldn't worry about it.


Henri(Posted 2014) [#9]
The problem with Linux is that there is no standard package (core + gui) AFAIK. I tried to setup Linux for Blitzmax a year ago, but didn't succeed and lost a bit of interest. Maybe I'll try again sometime.

To be honest, I don't know what is the percentige of Linux users in Blitzmax, or does Linux even have a clipboard, but certainly someone with knowlegde might try.

-Henri


Derron(Posted 2014) [#10]
a) there is a clipboard
b) I know at least 2 active board users using linux: dawlane and myself.

There are others using Linux too - but not as "main dev platform" (feel free to correct me here).

With the aroused interest because of SteamOS people might feel more comfortable if the linux platform is getting a better support state again.



PS: Brucey your post was not that easy to interpret as sarcasm - too many people think "nobody but servers use linux".

But hey... linux is for tinkers - some parts of BlitzMax too - so they should feel comfortable with each other :D

bye
Ron


Brucey(Posted 2014) [#11]
Pah, you should just interpret everything I say as sarcasm. :-p

b) I'm pretty sure I've used Linux before too...


degac(Posted 2014) [#12]
[ot]
Not related with this topic, but there's a way to know WHAT Linux distribution (I mean: SteamOS, Mint, Ubuntu ecc.. not Linux core) the application is running on?
So *maybe* (I'm a completely ignorant about linux...) it could be easy (or less difficult...) to determine what lib the app can use (not only for GUI, but also for sound and so on...)
I know you can install Ubuntu and THEN add lib you want so this could be not so useful... but for a newbee user that starts with a 'out-of-stock' installation it could be interesting. (The Linux section is full of script to fix/install libs... nobody today wants to open terminal to type commands...)
[/ot]

Brucey's sarcasm is easily recognizable...


Henri(Posted 2014) [#13]
Me I always take things seriously :-)

-Henri


John G(Posted 2014) [#14]
Linux: The bigger issue is not whether the BlitzMax user can get Linux to work (I failed) but whether your game/app runs on most/many/any Linux PCs. I suggest the BM community pick only one distribution to support -- say Ubuntu 13 or bet on the beta SteamOS.


Derron(Posted 2014) [#15]
@sarcasm
compared to tones in a spoken phrase it is hard to recognize it sometimes if you only get written words... that is why people (like I) overuse smileys to take a bit of the seriousness words could have (especially if not writing in the Mother language).


@distribution:
cat /etc/*-release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=16
DISTRIB_CODENAME=petra
DISTRIB_DESCRIPTION="Linux Mint 16 Petra"
NAME="Ubuntu"
VERSION="13.10, Saucy Salamander"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 13.10"
VERSION_ID="13.10"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"



lsb_release -a
No LSB modules are available.
Distributor ID:	LinuxMint
Description:	Linux Mint 16 Petra
Release:	16
Codename:	petra



@distribution to choose:
I think the community has to use the solutions provided by the community ... I doubt those committers will change their distros just for the sake of some others in a community.

bye
Ron


degac(Posted 2014) [#16]
@derron... thank you. This means there are already the right tools!


Brucey(Posted 2014) [#17]
whether your game/app runs on most/many/any Linux PCs

If you package your game properly (that is, in the correct way for a package for a given Linux distro) then your game/app should work, as the package will contain the list of required 3rd-party/system packages that need to be installed for your game/app to work.

If you ship your pre-compiled binaries in a zip/tar.gz, then there's nothing to help the end-user set up their system correctly to use the software.

Of course, if you are not willing to spend time to learn how to correctly package your stuff for distribution I doubt your potential users would feel like spending much time trying to set up their system to play/use it.

And if you can't get so far as to get BlitzMax working on Linux, it's probably better to stick to Windows and OS X instead.


Grisu(Posted 2014) [#18]

No, I don't think anyone uses BlitzMax on Linux, so I wouldn't worry about it.
-+ Brucey +-



I do! ;) So a full cross-platform solution would be nice.


Brucey(Posted 2014) [#19]
So a full cross-platform solution would be nice.

Well, it's already part of TGTKGUIDriver.

As for fltk, I'm with skid on that - it's pointless. (ein totes Pferd schlagen)


Grisu(Posted 2014) [#20]
That takes me back into the loop of getting the GTK driver to work on my system. :)

So now that we have a solution on all platforms, can Skid add it to the Windows and Mac driver modules?


Derron(Posted 2014) [#21]
The benefit of FLTK is - that it does not have that requirements GTK or QT add to a distribution ... but FLTK misses much of the things the normal "consumer" wants to see when starting your app.

@Ein totes Pferd schlagen
That "Flogging a Dead Horse" is better not directly translated but "converted" to "Ein totes Pferd reiten" (riding dead horses) but even this is coming from the Dakota natives in America... so hmm time to just use Bruceys translation and make it a wide success in Germany ... (to cite a user of this board: spread the word).


bye
Ron


Brucey(Posted 2014) [#22]
but FLTK misses much of the things the normal "consumer" wants to see when starting your app.

That and the fact MaxIDE and fltk don't work very well together - use Undo/Redo at your peril ...


Derron(Posted 2014) [#23]
Isn't the undo/redo-part coded in the app as the app is the only one knowing about the actions done in different gadgets/widgets.

If the textbox of fltk does something strange this of course is another story.

Somehow I doubt that fltk made mistakes concerning undo/redo - maybe it does it different (have a look at the input widget ... the undo is not only undoing the last character ... it concenates changes so it might "undo more than wanted"). It is like watching this post-textbox when posting an answer to my post here... if you CTRL+Z there... it mostly will delete a bigger part (an paragraph) instead of character by character.
Using this in a normal text editor ... you can CTRL+Z 50 times and then CTRL+Y to redo - seeing you "typing" :D.


Maybe of interest:
http://www.blitzbasic.com/Community/posts.php?topic=93486


bye
Ron


Brucey(Posted 2014) [#24]
Isn't the undo/redo-part coded in the app

Yes, it's completely driven by MaxIDE. The reason it isn't working is because the fltk/BlitzMax glue is really broken - especially the handling of text selection. One fun thing to do is to select some text and then scroll down so the start of the selection goes out of view... ooer.

But fair enough, it did take me a day or two to get it working correctly with my drop-in Scintilla textarea gadget.


c h i e f y(Posted 2014) [#25]
AppTitle = "Clpboard Example"

?Win32

Extern "Win32"
Function OpenClipboard(hwnd%)
Function CloseClipboard()
Function EmptyClipboard()
Function SetClipboardData(format%,hMem@ Ptr)
Function GetClipboardData@ Ptr(format%)
Function GlobalAlloc@ Ptr(uflags%,bytes%)
'Function GlobalFree(buf@ Ptr)
Function IsClipboardFormatAvailable%(format%)
End Extern
------------------------------------
I am getting getting "Expecting end of file" with ?Win32 highlighted


Chalky(Posted 2014) [#26]
Are you using all the code from the OP - or a fragment? It's possible the error is due to no ? to close the first conditional ?Win32 block (was after GlobalAllocString@ function in OP).


c h i e f y(Posted 2014) [#27]
all, I just used a few lines to show where I'm at :)


Chalky(Posted 2014) [#28]
That's odd - I pasted Grisu's code into Max and it compiled/ran fine. Maybe the highlighted line is a red herring and the error is actually in code you've added (in which case it would help if you posted it here)?


Grisu(Posted 2014) [#29]
Chiefy, can you please post a simple full example code. This way it's easier to identify the issue.

As said, the code I posted works fine. :)


markcw(Posted 2014) [#30]
I am getting getting "Expecting end of file" with ?Win32 highlighted

You need to follow each "?blah" with an ending "?" ie. with nothing after the question ends that preprocessor section. So it goes:
?Win32
blah
?
' or...
?Win32
blah
?Linux
blah
?



c h i e f y(Posted 2014) [#31]
I think I hit the buffers at Line 2 : Import MaxGui.Drivers

hoooo boy! never mind