Have created a Gtk based app. It can Cut/Copy/Paste (CCP) "internally" and across to/from other apps via the GtkClipboard.
One concern arise when CCP'ing from an another app into ours, say from Excel or Firefox, into ours. Out Gtk code can determine the full list of available "formats" (i.e. Atoms/Targets) that each external app is capable for providing.
That list, of course, depends on the "owner app" (i.e. where the CCP originated).
Unfortunately, we can't find a way to determine the actual "owner app" that send/owns the CCP'd material. For example, we can't figure out if it came from Excel of Firefox (of course one can analyse the last of Atoms/Targets and have a "guess" (e.g. if the Atoms/Targets include BIFF's, its probably from a spreadsheet etc.
What is actually required is a direct and explicit way to obtain the "owner app". That is, if the CCP came from "Excel", then we should be able to (hopeful) use some Gtk strategy to extract that information.
It appears to be possible with pyGkt, and possibly only on X, such seen on this page (http://commonsmachinery.se/2013/07/copy-paste-linux/) where the clipboard owner returns the "app" (e.g. Firefox, etc).
Is that also possible with standard Gtk+? We note:
1) the following:
gtk_clipboard_get_owner (GtkClipboard *clipboard);
is not of much help, if we understood it correctly, since it returns only "owners" that are actually set explicitly within Gtk (e.g. by
gtk_clipboard_set_text (GtkClipboard *clipboard, const gchar *text, gint len);
etc.
Yes, we have tested the code, it doesn't work (or at least not in the sense we would like it). Have tried many variations directly with the different types of callbacks (since different callbacks provide different data). For example "owner-change" provide GtkSelectionData, but the "owner" component of that is just the Atom/Target of the owner ... and so on, and so forth, with many permutations/combinations (e.g. request_content(), request_target(), etc etc, each with their specific callbacks).
So is it possible in standard Gtk, and on Windows, to determine the explicit name of the "ownder" of the selection on the clipboard, or is it only available, say, on pyGtk on X etc ... we fear we may have missed something all too simple?
Please advise.
OK, we think we have arrived at "one answer", though it is not very satisfactory (but it may be as good as it gets).
CAVEAT: we are "end users/math geeks", not "developers/IT geeks", and would invite Gtk and WinAPI "Gods" to comment/verify.
The "answer":
1) Taking together our research prior to posting, andlabs comments above, and more research since ... we believe that Gtk CANNOT actually determine the App from which the current clipboard's content originate.
2) That looks fairly likely the case on Windows, and it seems that perhaps even on Linux, Gtk does not have such means.
We corresponded with Jonas (the author of this page (http://commonsmachinery.se/2013/07/copy-paste-linux/) cited above) where it seemed that Gtk (at least pyGtk) did manage this. In fact, it did not. Jonas wrote to us with:
"this isn't a feature of neither pyGtk or anything other Gtk. It's merely making use of the Xlib method get_wm_name(). Whether Windows has something similar in its equivalent of Xlib, I'm afraid that we do not know."
3) Accepting that Gtk can't do it, we took andlabs indication and Jonas' comments that we would need to look to the WinAPI for our solution. We did the following:
a) Create a standard GtkClipboard signal for "owner-change".
b) In the callback function for that signal we inserted (first creating the appropriate "interface blocks" to the WinAPI function) a couple of WinAPI functions, namely of the form:
OwnerHandle = GetClipboardOwner() ! GetClipboardOwner() is the WinAPI for the "Windows HANDLE" of the current clipboard ownder
We could not find a WinAPI that returned the "app" that owns the current clipboard. The best we could find is a WinAPI that returns the "Title" of the Window from which the "bits" were Cut/Copy'd, which is the function GetWindowText().
Unfortunately, the OwnerHandle could be the Handle of a "child window" in the owner app, as we discovered from the comments of Syed Waqas at this SO posting (Get Clipboard owners Title/Caption). So, we wrote a loop that checked if the "current owner Handle" is a child, by implementing the WinAPI GetParent(), creating code that roughly looks like this (we have aliased the WinAPI routines to have local names that begin with "w32_" etc., and this example omits the overloading of both ANSI and UNICODE, showing only the ANSI variant) :
!
w32_GetClipboardOwner_Test = w32_GetClipboardOwner()
w32_GetClipboardOwner_cInt = w32_GetClipboardOwner_Test
!
Do While ( w32_GetClipboardOwner_Test > 0_c_IntPtr_t )
!
w32_GetClipboardOwner_Test = w32_GetParent(w32_GetClipboardOwner_Test)
!
! the "If" portion of the next line may be pedantic
! with some compilers/languages,
If( w32_GetClipboardOwner_Test > 0_c_IntPtr_t ) w32_GetClipboardOwner_cInt = w32_GetClipboardOwner_Test
!
End Do
!
! Get length of text in buffer, ir there is a valid Handle
!
If( w32_GetClipboardOwner_cInt > 0_c_IntPtr_t ) Then
w32_GetWindowText_nAct_cInt = w32_GetWindowTextLengthA(w32_GetClipboardOwner_cInt)
End If
!
! get the text (window title) and put in the buffer implied by lpString
!
w32_GetWindowText_nAct_cInt = w32_GetWindowTextA(hWnd = w32_GetClipboardOwner_cInt, &
lpString = w32_GetWindowText_Str_cPtr, &
nMaxCount = w32_GetWindowText_nMax_cInt)
, where the type c_IntPtr_t has been stated to form an "equivalent" to the Windows HANDLE "pointer/entity", at least for these purposes (yes, we know it's more complicated compared to traditional pointer, but likely not an issue here, as suggested by other sources).
Unfortunately, and as indicated by Syed Waqas, even with this extra care, there is no guarantee that the owner can be identified, since it is possible for apps to own data on the clipboard without having a "connection" to their "Window Title".
Bizarrely, none of the "big name apps" actually worked in this process (e.g. Excel, Word, FireFox, etc.), whereas many "no name" apps at least return the "app.exe" or "something".
We also discovered that MS Office also has the OfficeClipboard, and the OLEClipboard, which "attaches itself" to the "standard" clipboard somehow. We don't know how that works, and could use some much appreciated help.
Of course, we were looking the get the "owner app" (not some window title), but this is as far as we got toward "a not so satisfactory solution".
This is rather unsatisfactory for us, since for example, once there has been a Cut/Copy, the Paste step has many possibilities based on all the formats (Atoms/Targets) the clipboard data can be converted to. While we have written a "Paste Special" routine to list all the Targets, so the user can choose the format of the Paste, we were looking to be able to provide a "default" choice, but which (of course) would depend on the owner App (e.g. the default for Excel CCP might be BIFF8 or XML etc, while for Notepad, UTF8 etc.)
The Excel connection is a bit more important for our specific Gtk app, since it too has spreadsheet component, and would like to be able to CCP between Excel and our Gtk spreadsheet in a sensible manner.
ASIDE: A question for the SO moderators. As this issue has now morphed from a GtkClipboard matter to a WinAPI/OLE etc matter, should we post a new question purely in the WinAPI context, and with the new issues?
I had another question about processing and a project i'm making. I would like to play a movie in a loop on the background. I managed to do this by initializing a Movie and putting it in an image the size of my app. But now I would like to load in multiple movies and add a button to change the background when pressed with the leap motion. Is this possible ? Or should I use a different library for this ?
Thanks in advance!
Kind regards,
DarthSwedo
It's really hard to answer general "how do I do this" type questions. Stack Overflow is designed more for specific "I tried X, expected Y, but got Z instead" type questions. You'll have much better luck if you just try something and post an MCVE if you get stuck.
That being said, I'm going to try to clear up some of the general confusion you seem to have.
Step 1: You need to figure out what library or libraries you're using. In all of your questions, you seem to not be sure which library you're using. Which Leap Motion library are you using? How did you set it up? Where is its documentation? You say you're using a Movie class. Where is that coming from? Are you sure it's not from the Video library?
If you have more specific questions in the future, please provide this information. We can't really help you without it. But more importantly, you need to know the answers to these questions if any of this is ever going to make any sense.
Step 2: Read the documentation for those libraries. Processing comes with the reference. The Video library comes with its own documentation page. I'm sure whatever Leap Motion library you're using has something similar. You need to read about the functions available to you. That's a huge part of programming. Right now your question is just asking whether something possible, and the honest answer to that is, well, what happened when you googled it?
Step 3: Try something. After you read through the documentation, just try something. Write some code based on the examples in the documentation. Even if that code doesn't work, that's okay, because then you can use it as an MCVE and ask a more specific question.
Good luck.
I'm trying to use IDI_INFORMATION with wxWidgets 2.8.11 (from wx/version.h) (for wxMemoryDC::DrawIcon). But first I have to load the icon: wxICON(IDI_INFORMATION) fails, LoadFile(wxT("IDI_INFORMATION")) also fails ( but LoadFile(IDI_INFORMATION) compiles and crashes, IDI_INFORMATION is a fake string pointer too tricky for wxWidgets). Hmmm, then I add some ifdefs to use Windows API: ::LoadIcon(NULL, IDI_INFORMATION) works, then wxIcon::SetHICON. While DrawIcon apparently works, the nasty surprise is that wxIcon::GetWidth, wxIcon::GetHeight return 0. Hmmm, let's get the size and use wxIcon::SetSize. Now it is finally done... wait!, but who's gonna destroy my icon? Not sure, so add the ifdef, SetHICON(NULL) and DestroyIcon.
The small question: do I have to destroy the icon myself?
The big question: is wxIcon entirely useless in this case?
PS After some debugging I discover that LoadFile(wxT("wxICON_INFORMATION")) works, wow!, but is it really multi-platform? Do I have read all the wx sources for drawing a standard icon?
The cross-platform solution is provided by wxArtProvider, just use its GetIcon() method with wxART_INFORMATION argument.
I just installed the scheme48 package from macports and have started experiencing. I was watching this youtube video, link here and was attempting to perform some of the examples. In the lecture the professor is running scheme on a Sun terminal. For example, I attempt to do '(first 473)' and get 'Error: undefined variable first'. Now, I'm assuming I haven't loaded the correct package / library or what ever it is called in scheme but am not sure what the syntax and library is. I believe that scheme48 and the scheme version on that sun terminal in the video are not the same and could be part of the problem.
So, what library do I need to use and how do I load it?
Those lecture notes are based on a book called Simply Scheme, and you can find the library code that is used in the book here. Specifically, you need simply.scm.
(But whether it is a good idea to have these kind of overloading functions is debatable. Specifically, note that first is used in a way that is different from many other languages.)
What are the possible solutions for finding the current active language which appears on the Windows language bar ?
CultureInfo.CurrentCulture. This has information on the language and culture. If you just want the language name, try CultureInfo.CurrentCulture.ThreeLetterISOLanguageName.
You should look at the Multilingual APIs in Win32 as a starting point. It's not entirely obvious from the documentation which call will provide you what you want, but I think the answer may lie with the calls relating to processes and threads, or preferred languages. You may need to do some experimentation to see which calls give the expected result of matching the language bar selection.
I suspect that the best call to try would be GetThreadUILanguage.