diff -r f5050f1da672 -r 04becd199f91 javauis/lcdui_akn/javalcdui/src.nokialcdui/Clipboard.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javauis/lcdui_akn/javalcdui/src.nokialcdui/Clipboard.cpp Tue Apr 27 16:30:29 2010 +0300 @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: JNI implementation of Clipboard class +* +*/ + + +// INTERNAL INCLUDES +#include "com_nokia_mid_ui_Clipboard.h" + +// EXTERNAL INCLUDES +#include +#include +#include +#include +#include + +/** + * Local helper function for inserting the text to clipboard. + * + * @param aText The text to be copied to the clipboard. + */ +LOCAL_C void CopyToClipboardL(const TDesC* aText) +{ + CClipboard* clipboard = CClipboard::NewForWritingLC( + CCoeEnv::Static()->FsSession()); + + CPlainText* text = CPlainText::NewL(); + CleanupStack::PushL(text); + text->InsertL(0, *aText); + + text->CopyToStoreL(clipboard->Store(), clipboard->StreamDictionary(), 0, + text->DocumentLength()); + CleanupStack::PopAndDestroy(); // text + clipboard->CommitL(); + CleanupStack::PopAndDestroy(); // clipboard; +} + +/* + * Class: com_nokia_mid_ui_Clipboard + * Method: _copyToClipboard + * Signature: (IIZ)I + */ +JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_Clipboard__1copyToClipboard( + JNIEnv* aJniEnv, + jclass /* aPeer */, + jint aToolkitHandle, + jstring aText) +{ + DEBUG("Clipboard.cpp - copyToClipboard +"); + CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle); + + // Convert the content to a native descriptor. NULL indicates + // that an empty string is set as content. + const RJString content(*aJniEnv, aText); + const TDesC* nativeContent = (aText ? &content : &KNullDesC); + + jint error = toolkit->ExecuteTrap(&CopyToClipboardL, + nativeContent); + DEBUG("Clipboard.cpp - copyToClipboard -"); + return error; +} + +// End of file