Пример #1
0
JBoolean
TestWidget::WillAcceptDrop
(
    const JArray<Atom>&	typeList,
    Atom*				action,
    const Time			time,
    const JXWidget*		source
)
{
    JXDNDManager* dndMgr = GetDNDManager();

    if (typeList.GetFirstElement() == (GetSelectionManager())->GetURLXAtom())
    {
        cout << endl;
        cout << "Accepting the drop of type text/uri-list" << endl;
        cout << endl;

        *action = dndMgr->GetDNDActionPrivateXAtom();
        return kJTrue;
    }
    else if (*action == dndMgr->GetDNDActionCopyXAtom())
    {
        cout << endl;
        cout << "Accepting the drop" << endl;
        cout << endl;

        PrintSelectionText(dndMgr->GetDNDSelectionName(), time,
                           (GetSelectionManager())->GetMimePlainTextXAtom());
        return kJTrue;
    }
    else
    {
        JXDisplay* display = GetDisplay();

        cout << endl;
        cout << "Not accepting the drop because the action isn't copy" << endl;
        cout << "Action: " << XGetAtomName(*display, *action) << endl;
        cout << endl;
        cout << "Data types available from DND source:" << endl;
        cout << endl;

        const JSize typeCount = typeList.GetElementCount();
        for (JIndex i=1; i<=typeCount; i++)
        {
            const Atom type = typeList.GetElement(i);
            cout << XGetAtomName(*display, type) << endl;
        }
        cout << endl;

        PrintSelectionText(dndMgr->GetDNDSelectionName(), time,
                           (GetSelectionManager())->GetMimePlainTextXAtom());

        return kJFalse;
    }
}
void
ClipboardWidget::HandleEditMenu
	(
	const JIndex index
	)
{
	if (index == kCopyCmd)
		{
		// We instantiate a selection object that is appropriate for
		// our data. 
		JXTextSelection* data = new JXTextSelection(GetDisplay(), itsText);
		assert(data != NULL);

		// The selection data is then given to the selection manager.
		if (!(GetSelectionManager())->SetData(kJXClipboardName, data))
			{
			(JGetUserNotification())->ReportError("Unable to copy to the X Clipboard.");
			}
		}
	else if (index == kPasteCmd)
		{
		// Paste if the clipboard has the type we need.
		Paste();
		}
}
void
SVNListBase::CopySelectedItems
	(
	const JBoolean fullPath
	)
{
	JPtrArray<JString> list(JPtrArrayT::kDeleteAll);
	GetSelectedFiles(&list, kJTrue);
	if (list.IsEmpty())
		{
		return;
		}

	if (!fullPath)
		{
		const JSize count       = list.GetElementCount();
		const JString& basePath = GetPath();
		JString fullPath;
		for (JIndex i=1; i<=count; i++)
			{
			JString* path = list.NthElement(i);
			*path         = JConvertToRelativePath(*path, basePath);
			}
		}

	JXTextSelection* data = new JXTextSelection(GetDisplay(), list);
	assert( data != NULL );

	(GetSelectionManager())->SetData(kJXClipboardName, data);
}
void
SVNPropertiesList::CopySelectedItems
	(
	const JBoolean fullPath
	)
{
	JTableSelection& s = GetTableSelection();
	if (!s.HasSelection())
		{
		return;
		}

	JPtrArray<JString> list(JPtrArrayT::kDeleteAll);
	JTableSelectionIterator iter(&s);
	JPoint cell;
	while (iter.Next(&cell))
		{
		list.Append(*((GetStringList()).NthElement(cell.y)));
		}

	JXTextSelection* data = new JXTextSelection(GetDisplay(), list);
	assert( data != NULL );

	(GetSelectionManager())->SetData(kJXClipboardName, data);
}
JBoolean
JXPathInput::WillAcceptDrop
	(
	const JArray<Atom>&	typeList,
	Atom*				action,
	const JPoint&		pt,
	const Time			time,
	const JXWidget*		source
	)
{
	itsExpectURLDropFlag = kJFalse;

	const Atom urlXAtom = (GetSelectionManager())->GetURLXAtom();

	JString dirName;
	const JSize typeCount = typeList.GetElementCount();
	for (JIndex i=1; i<=typeCount; i++)
		{
		if (typeList.GetElement(i) == urlXAtom &&
			GetDroppedDirectory(time, kJFalse, &dirName))
			{
			*action = (GetDNDManager())->GetDNDActionPrivateXAtom();
			itsExpectURLDropFlag = kJTrue;
			return kJTrue;
			}
		}

	return JXInputField::WillAcceptDrop(typeList, action, pt, time, source);
}
void
CBSymbolTable::CopySelectedSymbolNames()
	const
{
	itsKeyBuffer.Clear();

	const JTableSelection& s = GetTableSelection();
	if (s.HasSelection())
		{
		JPtrArray<JString> list(JPtrArrayT::kForgetAll);

		CBLanguage lang;
		CBSymbolList::Type type;

		JTableSelectionIterator iter(&s);
		JPoint cell;
		while (iter.Next(&cell))
			{
			const JString& name = itsSymbolList->GetSymbol(CellToSymbolIndex(cell), &lang, &type);
			list.Append(const_cast<JString*>(&name));
			}

		JXTextSelection* data = new JXTextSelection(GetDisplay(), list);
		assert( data != NULL );

		(GetSelectionManager())->SetData(kJXClipboardName, data);
		}
}
Пример #7
0
void touchmind::win::CanvasPanel::OnDeleteLink() {
    auto selectedLink
        = std::dynamic_pointer_cast<touchmind::model::link::LinkModel>(GetSelectionManager()->GetSelected());
    if (selectedLink != nullptr) {
        m_pMapModel->RemoveLink(selectedLink);
    }
    Invalidate();
}
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;
}
Пример #9
0
void touchmind::win::CanvasPanel::OnEditCopy() {
    auto selectedNode
        = std::dynamic_pointer_cast<touchmind::model::node::NodeModel>(GetSelectionManager()->GetSelected());
    if (selectedNode != nullptr) {
        m_pNodeViewManager->SyncFontAttributesFromTextLayout();
        m_pClipboard->CopyNodeModel(m_hwnd, selectedNode);
    }
    Invalidate();
}
Пример #10
0
void touchmind::win::CanvasPanel::OnEditPaste() {
    auto node = touchmind::model::node::NodeModel::Create(GetSelectionManager());
    std::vector<std::shared_ptr<model::link::LinkModel>> links;
    m_pClipboard->PasteNodeModel(m_hwnd, node, links);
    auto selectedNode
        = std::dynamic_pointer_cast<touchmind::model::node::NodeModel>(GetSelectionManager()->GetSelected());
    if (selectedNode != nullptr) {
        m_pNodeViewManager->SyncFontAttributesFromTextLayout();
        m_pTouchMindApp->GetMapModel()->BeginTransaction();
        selectedNode->AddChild(node);
        m_pMapModel->AddLinks(links);
        m_pTouchMindApp->GetMapModel()->EndTransaction();

        ArrangeNodes();

        m_pNodeViewManager->SynchronizeWithModel();
        m_pNodeViewManager->SyncFontAttributesToTextLayout();
        m_pNodeViewManager->SynchronizeWithModel();
    }
    Invalidate();
}
Пример #11
0
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);
		}
}
Пример #12
0
void
JXExprEditor::EIPClipboardChanged()
{
	const JFunction* f;
	if (GetClipboard(&f))
		{
		const JString text = f->Print();

		JXTextSelection* data = jnew JXTextSelection(GetDisplay(), text);
		assert( data != NULL );

		GetSelectionManager()->SetData(kJXClipboardName, data);
		}
}
Пример #13
0
void
TestWidget::HandleDNDDrop
	(
	const JPoint&		pt,
	const JArray<Atom>&	typeList,
	const Atom			action,
	const Time			time,
	const JXWidget*		source
	)
{
	JXDisplay* display         = GetDisplay();
	JXSelectionManager* selMgr = GetSelectionManager();

	std::cout << std::endl;
	std::cout << "Data types available from DND source:" << std::endl;
	std::cout << std::endl;

//	(JGetUserNotification())->DisplayMessage("testing");

	Atom textType = None;
	JBoolean url  = kJFalse;
	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;
		if (type == selMgr->GetMimePlainTextXAtom())
			{
			textType = type;
			}
		else if (type == selMgr->GetURLXAtom())
			{
			url = kJTrue;
			}
		}
	std::cout << std::endl;

	if (textType != None)
		{
		PrintSelectionText(GetDNDManager()->GetDNDSelectionName(), time, textType);
		}

	if (url)
		{
		PrintFileNames(GetDNDManager()->GetDNDSelectionName(), time);
		}
}
Пример #14
0
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();
}
Пример #15
0
void touchmind::win::CanvasPanel::OnEditDelete() {
    auto selectedNode
        = std::dynamic_pointer_cast<touchmind::model::node::NodeModel>(GetSelectionManager()->GetSelected());
    if (selectedNode != nullptr) {
        auto parent = selectedNode->GetParent();
        if (parent != nullptr) {
            m_pNodeViewManager->SyncFontAttributesFromTextLayout();
            m_pMapModel->BeginTransaction();
            parent->RemoveChild(selectedNode);
            m_pMapModel->NormalizeLinks();
            m_pMapModel->EndTransaction();
            ArrangeNodes();
        }
    }

    Invalidate();
}
Пример #16
0
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;
		}
}
Пример #17
0
void touchmind::win::CanvasPanel::SetSelectedNode(const std::shared_ptr<touchmind::model::node::NodeModel> &node) {
    if (node != nullptr) {
        node->SetSelected();
        auto editControlIndex = m_pNodeViewManager->GetEditControlIndexFromNodeId(node->GetId());
        m_pEditControlManager->SetSelectedNode(editControlIndex);
    } else {
        GetSelectionManager()->ClearSelected();
        m_pEditControlManager->CancelSelectedNode();
    }
    m_pTouchMindApp->GetUIFramework()->InvalidateUICommand(cmdFontControl, UI_INVALIDATIONS_ALLPROPERTIES, 0);
    m_pTouchMindApp->GetUIFramework()->InvalidateUICommand(cmdBackgroundColor, UI_INVALIDATIONS_PROPERTY,
            &UI_PKEY_Enabled);
    m_pTouchMindApp->GetUIFramework()->InvalidateUICommand(cmdBackgroundColor, UI_INVALIDATIONS_PROPERTY,
            &UI_PKEY_ColorType);
    m_pTouchMindApp->GetUIFramework()->InvalidateUICommand(cmdBackgroundColor, UI_INVALIDATIONS_PROPERTY, &UI_PKEY_Color);
    m_pTouchMindApp->GetUIFramework()->InvalidateUICommand(cmdBackgroundColor, UI_INVALIDATIONS_PROPERTY,
            &UI_PKEY_LargeImage);
}
void
CMArray2DTable::HandleEditMenu
	(
	const JIndex index
	)
{
	JTextEditor::CmdIndex cmd;
	JPoint cell;
	if (GetEditMenuHandler()->EditMenuIndexToCmd(index, &cmd) &&
		cmd == JTextEditor::kCopyCmd &&
		(GetTableSelection()).GetSingleSelectedCell(&cell))
		{
		JXTextSelection* data =
			jnew JXTextSelection(GetDisplay(), GetStringData()->GetString(cell));
		assert( data != NULL );

		GetSelectionManager()->SetData(kJXClipboardName, data);
		}
}
Пример #19
0
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;
		}
}
void
TestWidget::PrintSelectionTargets
	(
	const Time time
	)
{
	JXDisplay* display         = GetDisplay();
	JXSelectionManager* selMgr = GetSelectionManager();
	JXDNDManager* dndMgr       = GetDNDManager();

	JArray<Atom> typeList;
	if (selMgr->GetAvailableTypes(kJXClipboardName, time, &typeList))
		{
		cout << endl;
		cout << "Data types available from the clipboard:" << endl;
		cout << endl;

		Atom textType = None;
		const JSize typeCount = typeList.GetElementCount();
		for (JIndex i=1; i<=typeCount; i++)
			{
			const Atom type = typeList.GetElement(i);
			cout << XGetAtomName(*display, type) << endl;
			if (type == XA_STRING)
				{
				textType = type;
				}
			}
		cout << endl;

		if (textType != None)
			{
			PrintSelectionText(kJXClipboardName, time, textType);
			}
		}
	else
		{
		cout << endl;
		cout << "Unable to access the clipboard." << endl;
		cout << endl;
		}
}
JBoolean
JXSelectionData::Convert
	(
	const Atom		requestType,
	Atom*			returnType,
	unsigned char**	data,
	JSize*			dataLength,
	JSize*			bitsPerBlock
	)
	const
{
	JXSelectionManager* selMgr = GetSelectionManager();

	// TARGETS

	if (requestType == selMgr->GetTargetsXAtom())
		{
		const JSize atomCount = itsTypeList->GetElementCount();
		assert( atomCount > 0 );

		*returnType   = XA_ATOM;
		*bitsPerBlock = 32;		// XXXATOM: sizeof(Atom)*8; -- fails on 64-bit systems
		*dataLength   = sizeof(Atom)*atomCount;

		*data = jnew unsigned char [ *dataLength ];
		if (*data == NULL)
			{
			return kJFalse;
			}

		Atom* atomData = reinterpret_cast<Atom*>(*data);
		for (JIndex i=1; i<=atomCount; i++)
			{
			atomData[i-1] = itsTypeList->GetElement(i);
			}

		return kJTrue;
		}

	// TIMESTAMP

	else if (requestType == selMgr->GetTimeStampXAtom())
Пример #22
0
void
JXSelectionData::SetSelectionInfo
	(
	const Atom	selectionName,
	const Time	startTime
	)
{
	assert( selectionName != None );

	itsSelectionName = selectionName;
	itsStartTime     = startTime;

	if (selectionName != GetDNDSelectionName())
		{
		JXSelectionManager* selMgr = GetSelectionManager();
		AddType(selMgr->GetTargetsXAtom());
		AddType(selMgr->GetTimeStampXAtom());
		}

	AddTypes(selectionName);
}
Пример #23
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() );
}
Пример #24
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.");
		}
}
Пример #27
0
JBoolean
JXSelectionData::Convert
	(
	const Atom		requestType,
	Atom*			returnType,
	unsigned char**	data,
	JSize*			dataLength,
	JSize*			bitsPerBlock
	)
	const
{
	JXSelectionManager* selMgr = GetSelectionManager();

	// TARGETS

	if (requestType == selMgr->GetTargetsXAtom())
		{
		const JSize atomCount = itsTypeList->GetElementCount();
		assert( atomCount > 0 );

		*returnType   = XA_ATOM;
		*bitsPerBlock = sizeof(Atom)*8;
		*dataLength   = sizeof(Atom)*atomCount;

		*data = new unsigned char [ *dataLength ];
		if (*data == NULL)
			{
			return kJFalse;
			}

		Atom* atomData = reinterpret_cast<Atom*>(*data);
		for (JIndex i=1; i<=atomCount; i++)
			{
			atomData[i-1] = itsTypeList->GetElement(i);
			}

		return kJTrue;
		}

	// TIMESTAMP

	else if (requestType == selMgr->GetTimeStampXAtom())
		{
		*returnType   = XA_INTEGER;
		*bitsPerBlock = sizeof(Time)*8;
		*dataLength   = sizeof(Time);

		*data = new unsigned char [ *dataLength ];
		if (*data == NULL)
			{
			return kJFalse;
			}

		*(reinterpret_cast<Time*>(*data)) = itsStartTime;

		return kJTrue;
		}

	// everything else

	else
		{
		Resolve();
		return ConvertData(requestType, returnType,
						   data, dataLength, bitsPerBlock);
		}
}