Clipboard Copy/Cut/Paste
Article Metadata
You can use the clipboard directly with a CEikEdwin derived editor by first letting the user set a selection or setting the selection by using the SetSelectionL()method. Then to use the clipboard CEikEdwin implements the ClipboardL() method. To cut the selection to the clipboard use CEikEdwin::ECut as argument for the function, CEikEdwin::ECopy for copying and CEikEdwin::EPaste for pasting the text to the currently selected location.
To set text to the clipboard without using CEikEdwin you can use the following code:
void SetTextToClipBoardL(const TDesC& aText)
{
CClipboard* cb =
CClipboard::NewForWritingLC(CCoeEnv::Static()->FsSession());
cb->StreamDictionary().At(KClipboardUidTypePlainText);
CPlainText* BPlainText = CPlainText::NewL();
CleanupStack::PushL(BPlainText);
BPlainText->InsertL(0,aText);
BPlainText->CopyToStoreL(cb->Store(), cb->StreamDictionary(), 0,
BPlainText->DocumentLength());
CleanupStack::PopAndDestroy(); // BPlainText
cb->CommitL();
CleanupStack::PopAndDestroy(); // cb
}
And to get text from the clipboard you could utilize following example code:
CPlainText* GetTextFromClipBoardL(void)
{
CPlainText* BPlainText = CPlainText::NewL();
CleanupStack::PushL(BPlainText);
CClipboard* cb =
CClipboard::NewForReadingL(CCoeEnv::Static()->FsSession());
CleanupStack::PushL(cb);
cb->StreamDictionary().At(KClipboardUidTypePlainText);
BPlainText->PasteFromStoreL(cb->Store(), cb->StreamDictionary(), 0);
// the text is now inside the BPlainText
cb->CommitL();
CleanupStack::PopAndDestroy(); // cb
CleanupStack::Pop(); // BPlainText
return BPlainText;
}


(no comments yet)