javauis/lcdui_akn/javalcdui/javasrc.nokialcdui/com/nokia/mid/ui/Clipboard.java
branchRCL_3
changeset 21 4376525cdefb
parent 14 04becd199f91
child 23 e5618cc85d74
--- a/javauis/lcdui_akn/javalcdui/javasrc.nokialcdui/com/nokia/mid/ui/Clipboard.java	Wed Jun 09 09:34:07 2010 +0300
+++ b/javauis/lcdui_akn/javalcdui/javasrc.nokialcdui/com/nokia/mid/ui/Clipboard.java	Mon Jun 21 15:32:50 2010 +0300
@@ -22,7 +22,6 @@
 import com.nokia.mj.impl.rt.legacy.NativeError;
 import com.nokia.mj.impl.rt.legacy.ToolkitInvoker;
 
-
 /**
  * Class to provide extra functionality that is related to text-editing
  *
@@ -37,7 +36,10 @@
     }
 
     /**
-     * Copies characters into the system-clipboard
+     * Copies characters into the system clipboard.
+     * <P>
+     * If <code>text</code> parameter is <code>null</code> or empty string,
+     * it clears the system clipboard.
      *
      * @param text the text to be copied
      */
@@ -48,13 +50,53 @@
         ToolkitInvoker toolkitInvoker = ToolkitInvoker.getToolkitInvoker();
 
         Object toolkit = toolkitInvoker.getToolkit();
+
         synchronized (toolkit)
         {
+            if ((text != null) && (text.length() == 0))
+            {
+                text = null;
+            }
             NativeError.check(_copyToClipboard(
                                   toolkitInvoker.toolkitGetHandle(toolkit), text));
         }
     }
 
+    /**
+     * Copies characters from the system clipboard.
+     * <P>
+     * Returns empty string when there is nothing in the system clipboard.
+     * <P>
+     * This method is not supported on S40 platform, returns <code>null</code>.
+     * <P>
+     * @return the content in clipboard
+     */
+    public static String copyFromClipboard()
+    {
+        String text = null;
+
+        int[] error = new int[1];
+        // Toolkit invoker is needed for accessing javax.microedition.lcdui
+        // package
+        ToolkitInvoker toolkitInvoker = ToolkitInvoker.getToolkitInvoker();
+
+        Object toolkit = toolkitInvoker.getToolkit();
+
+        synchronized (toolkit)
+        {
+            text = _copyFromClipboard(
+                       toolkitInvoker.toolkitGetHandle(toolkit),
+                       error);
+        }
+
+        NativeError.check(error[0]);
+        if (text == null)
+        {
+            text = "";
+        }
+        return text;
+    }
+
     /*
      * Stores the text into the clipboard.
      *
@@ -67,6 +109,19 @@
      */
     private static native int _copyToClipboard(int toolkit, String text);
 
+    /*
+     * Copies characters from the system-clipboard.
+     *
+     * @param toolkit A handle to the LCDUI toolkit.
+     *
+     * @param error On return contains the error code for the operation.
+     *
+     * @return The content of clipboard.
+     */
+    private static native String _copyFromClipboard(
+        int toolkit,
+        int[] error);
+
 }
 
 // END OF FILE
\ No newline at end of file