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::PrintFileNames
	(
	const Atom selectionName,
	const Time time
	)
	const
{
	JXSelectionManager* selMgr = GetSelectionManager();

	Atom returnType;
	unsigned char* data;
	JSize dataLength;
	JXSelectionManager::DeleteMethod delMethod;
	if (selMgr->GetData(selectionName, time, selMgr->GetURLXAtom(),
						&returnType, &data, &dataLength, &delMethod))
		{
		if (returnType == selMgr->GetURLXAtom())
			{
			JPtrArray<JString> fileNameList(JPtrArrayT::kDeleteAll),
							   urlList(JPtrArrayT::kDeleteAll);
			JXUnpackFileNames((char*) data, dataLength, &fileNameList, &urlList);

			const JSize fileCount = fileNameList.GetElementCount();
			if (fileCount > 0)
				{
				std::cout << "File/directory names:" << std::endl << std::endl;
				for (JIndex i=1; i<=fileCount; i++)
					{
					std::cout << *(fileNameList.NthElement(i)) << std::endl;
					}
				std::cout << std::endl << std::endl;
				}

			const JSize urlCount = urlList.GetElementCount();
			if (urlCount > 0)
				{
				std::cout << "Unconvertable URLs:" << std::endl << std::endl;
				for (JIndex i=1; i<=urlCount; i++)
					{
					std::cout << *(urlList.NthElement(i)) << std::endl;
					}
				std::cout << std::endl << std::endl;
				}

			JXReportUnreachableHosts(urlList);
			}

		selMgr->DeleteData(&data, delMethod);
		}
}
JBoolean
JXPathInput::GetDroppedDirectory
	(
	const Time		time,
	const JBoolean	reportErrors,
	JString*		dirName
	)
{
	dirName->Clear();

	JXSelectionManager* selMgr = GetSelectionManager();

	Atom returnType;
	unsigned char* data;
	JSize dataLength;
	JXSelectionManager::DeleteMethod delMethod;
	if (selMgr->GetData(GetDNDManager()->GetDNDSelectionName(),
						time, selMgr->GetURLXAtom(),
						&returnType, &data, &dataLength, &delMethod))
		{
		if (returnType == selMgr->GetURLXAtom())
			{
			JPtrArray<JString> fileNameList(JPtrArrayT::kDeleteAll),
							   urlList(JPtrArrayT::kDeleteAll);
			JXUnpackFileNames((char*) data, dataLength, &fileNameList, &urlList);
			if (fileNameList.GetElementCount() == 1 &&
				(JDirectoryExists(*(fileNameList.FirstElement())) ||
				 JFileExists(*(fileNameList.FirstElement()))))
				{
				*dirName = *(fileNameList.FirstElement());

				JString homeDir;
				if (JGetHomeDirectory(&homeDir) &&
					dirName->BeginsWith(homeDir))
					{
					dirName->ReplaceSubstring(1, homeDir.GetLength(), "~" ACE_DIRECTORY_SEPARATOR_STR);
					}
				}
			JXReportUnreachableHosts(urlList);
			}

		selMgr->DeleteData(&data, delMethod);
		}

	return !dirName->IsEmpty();
}
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;
		}
}
Example #5
0
JBoolean
JXFileInput::GetDroppedFileName
	(
	const Time		time,
	const JBoolean	reportErrors,
	JString*		fileName
	)
{
	fileName->Clear();

	JXSelectionManager* selMgr = GetSelectionManager();

	Atom returnType;
	unsigned char* data;
	JSize dataLength;
	JXSelectionManager::DeleteMethod delMethod;
	if (selMgr->GetData((GetDNDManager())->GetDNDSelectionName(),
						time, selMgr->GetURLXAtom(),
						&returnType, &data, &dataLength, &delMethod))
		{
		if (returnType == selMgr->GetURLXAtom())
			{
			JPtrArray<JString> fileNameList(JPtrArrayT::kDeleteAll),
							   urlList(JPtrArrayT::kDeleteAll);
			JXUnpackFileNames((char*) data, dataLength, &fileNameList, &urlList);
			if (fileNameList.GetElementCount() == 1 &&
				(JFileExists(*(fileNameList.FirstElement())) ||
				 JDirectoryExists(*(fileNameList.FirstElement()))))
				{
				*fileName = *(fileNameList.FirstElement());
				}
			JXReportUnreachableHosts(urlList);
			}

		selMgr->DeleteData(&data, delMethod);
		}

	return JNegate( fileName->IsEmpty() );
}
Example #6
0
void
TestWidget::PrintSelectionText
(
    const Atom selectionName,
    const Time time,
    const Atom type
)
const
{
    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 == type)
        {
            cout << "Data is available as text:" << endl << endl;

            cout.write((char*) data, dataLength);
            cout << endl << endl;
        }
        else
        {
            cout << "Data has unrecognized return type:  ";
            cout << XGetAtomName(*(GetDisplay()), returnType) << endl << endl;
        }

        selMgr->DeleteData(&data, delMethod);
    }
    else
    {
        cout << "Data could not be retrieved." << endl << endl;
    }
}
void
CBCommandTable::HandleDNDDrop
	(
	const JPoint&		pt,
	const JArray<Atom>&	typeList,
	const Atom			action,
	const Time			time,
	const JXWidget*		source
	)
{
	JXSelectionManager* selMgr = GetSelectionManager();
	JXDNDManager* dndMgr       = GetDNDManager();
	const Atom selName         = dndMgr->GetDNDSelectionName();

	if (source == this && action == dndMgr->GetDNDActionMoveXAtom())
		{
		JPoint cell;
		if ((GetTableSelection()).GetSingleSelectedCell(&cell) &&
			itsDNDRowIndex != JIndex(cell.y) && itsDNDRowIndex != JIndex(cell.y)+1)
			{
			JIndex newIndex = itsDNDRowIndex;
			if (newIndex > JIndex(cell.y))
				{
				newIndex--;
				}
			newIndex = JMin(newIndex, GetRowCount());

			itsCmdList->MoveElementToIndex(cell.y, newIndex);
			MoveRow(cell.y, newIndex);
			SelectSingleCell(JPoint(1, newIndex));
			}
		}
	else if (source == this)
		{
		JPoint cell;
		if ((GetTableSelection()).GetSingleSelectedCell(&cell))
			{
			itsCmdList->InsertElementAtIndex(
				itsDNDRowIndex, (itsCmdList->GetElement(cell.y)).Copy());
			InsertRows(itsDNDRowIndex, 1);
			SelectSingleCell(JPoint(1, itsDNDRowIndex));
			}
		}
	else
		{
		Atom returnType;
		unsigned char* data;
		JSize dataLength;
		JXSelectionManager::DeleteMethod delMethod;
		if (selMgr->GetData(selName, time, itsCommandXAtom,
							&returnType, &data, &dataLength, &delMethod))
			{
			if (returnType == itsCommandXAtom)
				{
				const std::string s((char*) data, dataLength);
				std::istringstream input(s);

				CBCommandManager::CmdInfo cmdInfo =
					CBCommandManager::ReadCmdInfo(input, CBCommandManager::GetCurrentCmdInfoFileVersion());
				if (!input.fail())
					{
					const JIndex newIndex = JMax(JIndex(1), itsDNDRowIndex);
					itsCmdList->InsertElementAtIndex(newIndex, cmdInfo);
					InsertRows(newIndex, 1);
					SelectSingleCell(JPoint(1, newIndex));

					if (action == dndMgr->GetDNDActionMoveXAtom())
						{
						selMgr->SendDeleteRequest(selName, time);
						}
					}
				}

			selMgr->DeleteData(&data, delMethod);
			}
		}

	HandleDNDLeave();
}
void
ClipboardWidget::Paste()
{
	// Get the window and selection manager for use below.
	JXWindow* window           = GetWindow();
	JXSelectionManager* selMgr = GetSelectionManager();

	// If the clipboard is not empty, retrieve the available types.
	JArray<Atom> typeList;
	if (selMgr->GetAvailableTypes(kJXClipboardName, CurrentTime, &typeList))
		{

		// Loop through the available types to see if the clipboard has
		// one that we want.
		const JSize typeCount = typeList.GetElementCount();
		for (JIndex i=1; i<=typeCount; i++)
			{
			const Atom atom = typeList.GetElement(i);

			// Check if the i-th type is one we can use.
			if (atom == XA_STRING || atom == selMgr->GetTextXAtom())
				{
				// Get the data of the appropriate type.
				unsigned char* data = NULL;
				JSize dataLength;
				Atom returnType;
				JXSelectionManager::DeleteMethod dMethod;
				if (selMgr->GetData(kJXClipboardName, CurrentTime,
						atom, &returnType, &data, &dataLength,
						&dMethod))
					{
					// We can only handle the simplest format.
					if (returnType == XA_STRING)
						{
						// Copy the data into our text.
						itsText.Set(reinterpret_cast<JCharacter*>(data), dataLength);

						// Our text changed, so we need to refresh.
						Refresh();
						}

					// This is required to delete the allocated data.
					// Forgetting to do this will cause a memory leak!
					selMgr->DeleteData(&data, dMethod);

					if (returnType == XA_STRING)
						{
						// We succeeded, so we return.
						return;
						}
					}
				else
					{
					(JGetUserNotification())->ReportError(
						"Unable to retrieve text from the clipboard.");
					}
				}
			}

		// If we got this far, the data type that we want wasn't on the
		// clipboard.
		(JGetUserNotification())->ReportError("Unable to paste from clipboard.");
		}
	else
		{
		// There isn't anything on the clipboard.
		(JGetUserNotification())->ReportError("Clipboard is empty.");
		}
}