×
Namespaces

Variants
Actions

Clipboard Copy/Cut/Paste

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: symbianyucca (30 Mar 2007)
Last edited: hamishwillee (20 Jul 2012)
Reviewer Approved    Thumbs up icon sm.jpg

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;
}
This page was last modified on 20 July 2012, at 12:48.
68 page views in the last 30 days.
×