Symbian
Symbian OS Library

FAQ-0515 How do I check if the Clipboard is empty?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: BAFL & Resources
Created: 08/10/2000 Modified: 12/11/2001
Number: FAQ-0515
Platform: ER5

Question:
How can an application successfully check if appropriate information is available on the system clipboard?

Answer:
Checking if the clipboard contains information of interest to the application should be done in two stages:

The first stage is to open the clipboard and check for errors. This may be done with the CClipboard::NewForReadingL method. If the file underpinning the Store being used by the CClipboard is unavailable for any reason (e.g. is corrupt, does not exist,…) the NewForReadingL function does not Leave. It returns KErrNotFound (-1).

The second stage is to check that the clipboard contains information relevant to the application. The way to find out whether there is actually anything on the clipboard for you is to search for its stream UID. Remember, the clipboard can hold all sorts of different things, and it is up to your app to determine which types it wants.

For example,
To open the clipboard:

CClipboard* cb=NULL;
TRAPD(err,cb=CClipboard::NewForReadingL(iTempAppUi->Application()->Process()->FsSession()));
CleanupStack::PushL(cb);
if (err==KErrPathNotFound || err==KErrNotFound)
{
// Cannot paste, dim menu item
aMenuPane->SetItemDimmed(KAppUiCmdEditPaste,ETrue);
}

To check the existence of KInterestingUid:

TStreamId stid = (cb->StreamDictionary()).At(KInterestingUid);
if (stid == KNullStreamId)
{
User::InfoPrint(_L("Nothing to paste "));
User::Leave(0);
}
CleanupStack::PopAndDestroy(); // cb