JBoolean JXExprEditor::EIPGetExternalClipboard ( JString* text ) { text->Clear(); JBoolean gotData = kJFalse; JXSelectionManager* selManager = GetSelectionManager(); JArray<Atom> typeList; if (selManager->GetAvailableTypes(kJXClipboardName, CurrentTime, &typeList)) { JBoolean canGetText = kJFalse; Atom textType = None; const JSize typeCount = typeList.GetElementCount(); for (JIndex i=1; i<=typeCount; i++) { Atom type = typeList.GetElement(i); if (type == XA_STRING || (!canGetText && type == selManager->GetUtf8StringXAtom())) { canGetText = kJTrue; textType = type; break; } } Atom returnType; unsigned char* data = NULL; JSize dataLength; JXSelectionManager::DeleteMethod delMethod; if (canGetText && selManager->GetData(kJXClipboardName, CurrentTime, textType, &returnType, &data, &dataLength, &delMethod)) { if (returnType == XA_STRING) { *text = JString(reinterpret_cast<JCharacter*>(data), dataLength); gotData = kJTrue; } selManager->DeleteData(&data, delMethod); } else { (JGetUserNotification())->ReportError( "Unable to paste the current contents of the X Clipboard."); } } else { (JGetUserNotification())->ReportError("The X Clipboard is empty."); } return gotData; }
void TestWidget::PrintSelectionText ( const Atom selectionName, const Time time, const Atom type ) const { JXDisplay* display = GetDisplay(); JXSelectionManager* selMgr = GetSelectionManager(); Atom returnType; unsigned char* data; JSize dataLength; JXSelectionManager::DeleteMethod delMethod; if (selMgr->GetData(selectionName, time, type, &returnType, &data, &dataLength, &delMethod)) { if (returnType == XA_STRING || returnType == selMgr->GetUtf8StringXAtom() || returnType == selMgr->GetMimePlainTextXAtom()) { std::cout << "Data is available as " << XGetAtomName(*display, type) << ":" << std::endl << std::endl; std::cout.write((char*) data, dataLength); std::cout << std::endl << std::endl; } else { std::cout << "Data has unrecognized return type: "; std::cout << XGetAtomName(*(GetDisplay()), returnType) << std::endl; std::cout << "Trying to print it anyway:" << std::endl << std::endl; std::cout.write((char*) data, dataLength); std::cout << std::endl << std::endl; } selMgr->DeleteData(&data, delMethod); } else { std::cout << "Data could not be retrieved as " << XGetAtomName(*display, type) << "." << std::endl << std::endl; } }
void TestWidget::PrintSelectionTargets ( const Time time ) { JXDisplay* display = GetDisplay(); JXSelectionManager* selMgr = GetSelectionManager(); JXDNDManager* dndMgr = GetDNDManager(); JArray<Atom> typeList; if (selMgr->GetAvailableTypes(kJXClipboardName, time, &typeList)) { std::cout << std::endl; std::cout << "Data types available from the clipboard:" << std::endl; std::cout << std::endl; const JSize typeCount = typeList.GetElementCount(); for (JIndex i=1; i<=typeCount; i++) { const Atom type = typeList.GetElement(i); std::cout << XGetAtomName(*display, type) << std::endl; } for (JIndex i=1; i<=typeCount; i++) { const Atom type = typeList.GetElement(i); if (type == XA_STRING || type == selMgr->GetUtf8StringXAtom() || type == selMgr->GetMimePlainTextXAtom()) { std::cout << std::endl; PrintSelectionText(kJXClipboardName, time, type); } } } else { std::cout << std::endl; std::cout << "Unable to access the clipboard." << std::endl; std::cout << std::endl; } }