|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: JNI implementation of Clipboard class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INTERNAL INCLUDES |
|
20 #include "com_nokia_mid_ui_Clipboard.h" |
|
21 |
|
22 // EXTERNAL INCLUDES |
|
23 #include <CMIDToolkit.h> |
|
24 #include <jutils.h> |
|
25 #include <jdebug.h> |
|
26 #include <txtetext.h> |
|
27 #include <baclipb.h> |
|
28 |
|
29 /** |
|
30 * Local helper function for inserting the text to clipboard. |
|
31 * |
|
32 * @param aText The text to be copied to the clipboard. |
|
33 */ |
|
34 LOCAL_C void CopyToClipboardL(const TDesC* aText) |
|
35 { |
|
36 CClipboard* clipboard = CClipboard::NewForWritingLC( |
|
37 CCoeEnv::Static()->FsSession()); |
|
38 |
|
39 CPlainText* text = CPlainText::NewL(); |
|
40 CleanupStack::PushL(text); |
|
41 text->InsertL(0, *aText); |
|
42 |
|
43 text->CopyToStoreL(clipboard->Store(), clipboard->StreamDictionary(), 0, |
|
44 text->DocumentLength()); |
|
45 CleanupStack::PopAndDestroy(); // text |
|
46 clipboard->CommitL(); |
|
47 CleanupStack::PopAndDestroy(); // clipboard; |
|
48 } |
|
49 |
|
50 /* |
|
51 * Class: com_nokia_mid_ui_Clipboard |
|
52 * Method: _copyToClipboard |
|
53 * Signature: (IIZ)I |
|
54 */ |
|
55 JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_Clipboard__1copyToClipboard( |
|
56 JNIEnv* aJniEnv, |
|
57 jclass /* aPeer */, |
|
58 jint aToolkitHandle, |
|
59 jstring aText) |
|
60 { |
|
61 DEBUG("Clipboard.cpp - copyToClipboard +"); |
|
62 CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle); |
|
63 |
|
64 // Convert the content to a native descriptor. NULL indicates |
|
65 // that an empty string is set as content. |
|
66 const RJString content(*aJniEnv, aText); |
|
67 const TDesC* nativeContent = (aText ? &content : &KNullDesC); |
|
68 |
|
69 jint error = toolkit->ExecuteTrap(&CopyToClipboardL, |
|
70 nativeContent); |
|
71 DEBUG("Clipboard.cpp - copyToClipboard -"); |
|
72 return error; |
|
73 } |
|
74 |
|
75 // End of file |