author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:23:59 +0300 | |
branch | RCL_3 |
changeset 83 | 26b2b12093af |
parent 66 | 2455ef1f5bbc |
permissions | -rw-r--r-- |
66 | 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: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// PACKAGE |
|
19 |
package com.nokia.mid.ui; |
|
20 |
||
21 |
// EXTERNAL IMPORTS |
|
22 |
import com.nokia.mj.impl.rt.legacy.NativeError; |
|
23 |
import com.nokia.mj.impl.rt.legacy.ToolkitInvoker; |
|
24 |
||
25 |
/** |
|
26 |
* Class to provide extra functionality that is related to text-editing |
|
27 |
* |
|
28 |
* @since 1.4 |
|
29 |
*/ |
|
30 |
public abstract class Clipboard |
|
31 |
{ |
|
32 |
||
33 |
// Private constructor. |
|
34 |
private Clipboard() |
|
35 |
{ |
|
36 |
} |
|
37 |
||
38 |
/** |
|
39 |
* Copies characters into the system clipboard. |
|
40 |
* <P> |
|
41 |
* If <code>text</code> parameter is <code>null</code> or empty string, |
|
42 |
* it clears the system clipboard. |
|
43 |
* |
|
44 |
* @param text the text to be copied |
|
45 |
*/ |
|
46 |
public static void copyToClipboard(String text) |
|
47 |
{ |
|
48 |
// Toolkit invoker is needed for accessing javax.microedition.lcdui |
|
49 |
// package |
|
50 |
ToolkitInvoker toolkitInvoker = ToolkitInvoker.getToolkitInvoker(); |
|
51 |
||
52 |
Object toolkit = toolkitInvoker.getToolkit(); |
|
53 |
||
54 |
synchronized (toolkit) |
|
55 |
{ |
|
56 |
if ((text != null) && (text.length() == 0)) |
|
57 |
{ |
|
58 |
text = null; |
|
59 |
} |
|
60 |
NativeError.check(_copyToClipboard( |
|
61 |
toolkitInvoker.toolkitGetHandle(toolkit), text)); |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
/** |
|
66 |
* Copies characters from the system clipboard. |
|
67 |
* <P> |
|
68 |
* Returns empty string when there is nothing in the system clipboard. |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
69 |
* |
66 | 70 |
* @return the content in clipboard |
71 |
*/ |
|
72 |
public static String copyFromClipboard() |
|
73 |
{ |
|
74 |
String text = null; |
|
75 |
||
76 |
int[] error = new int[1]; |
|
77 |
// Toolkit invoker is needed for accessing javax.microedition.lcdui |
|
78 |
// package |
|
79 |
ToolkitInvoker toolkitInvoker = ToolkitInvoker.getToolkitInvoker(); |
|
80 |
||
81 |
Object toolkit = toolkitInvoker.getToolkit(); |
|
82 |
||
83 |
synchronized (toolkit) |
|
84 |
{ |
|
85 |
text = _copyFromClipboard( |
|
86 |
toolkitInvoker.toolkitGetHandle(toolkit), |
|
87 |
error); |
|
88 |
} |
|
89 |
||
90 |
NativeError.check(error[0]); |
|
91 |
if (text == null) |
|
92 |
{ |
|
93 |
text = ""; |
|
94 |
} |
|
95 |
return text; |
|
96 |
} |
|
97 |
||
98 |
/* |
|
99 |
* Stores the text into the clipboard. |
|
100 |
* |
|
101 |
* @param toolkitHandle A handle to the LCDUI toolkit. |
|
102 |
* |
|
103 |
* @param text A text to be copied into the system-clipboard. |
|
104 |
* |
|
105 |
* @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
106 |
* a system-wide error code is returned. |
|
107 |
*/ |
|
108 |
private static native int _copyToClipboard(int toolkit, String text); |
|
109 |
||
110 |
/* |
|
111 |
* Copies characters from the system-clipboard. |
|
112 |
* |
|
113 |
* @param toolkit A handle to the LCDUI toolkit. |
|
114 |
* |
|
115 |
* @param error On return contains the error code for the operation. |
|
116 |
* |
|
117 |
* @return The content of clipboard. |
|
118 |
*/ |
|
119 |
private static native String _copyFromClipboard( |
|
120 |
int toolkit, |
|
121 |
int[] error); |
|
122 |
||
123 |
} |
|
124 |
||
125 |
// END OF FILE |