 | OO-Snippets: Read a text string out of the systems clipboardCommons| Keywords | read, text, string, system, systems, clipboard |
|---|
| Language | ooRexx |
|---|
| Application | Office |
|---|
| Authors | Josef Frysak (initial)
|
|---|
| Supported Versions | 2.4.1 |
|---|
| Supported OS | Win32 |
|---|
| Question | How to read a string out of the systems clipboard?
|
|---|
| Answer | Create an instance of the "SystemClipboard" service and its "XSystemClipboard" interface. Next check the clipboard for a valid text entry by searching the list of all supported data types. If the content is a text string convert it to a simple string using the "Converter" service. For further details see http://wi.wu-wien.ac.at/rgf/diplomarbeiten/BakkStuff/2008/200809_Frysak/200809_Frysak_Automating_OOo_ooRexx_Nutshells.pdf. |
|---|
x_ScriptContext = uno.getScriptContext()
if (x_ScriptContext <> .nil) then
do
x_ComponentContext = x_ScriptContext~getComponentContext
x_Desktop = x_ScriptContext~getDesktop
x_Document = x_ScriptContext~getDocument
end
else
do
x_ComponentContext = UNO.connect()
service = "com.sun.star.frame.Desktop"
s_Desktop = x_ComponentContext~getServiceManager~XMultiServiceFactory~createInstance(service)
x_Desktop = s_Desktop~XDesktop
x_Document = x_Desktop~getCurrentComponent()
end
cliptext = ""
x_MultiServiceFactory = x_ComponentContext~getServiceManager()~XMultiServiceFactory
clipboard = "com.sun.star.datatransfer.clipboard.SystemClipboard"
s_Clipboard = x_MultiServiceFactory~createInstance(clipboard)
x_Clipboard = s_Clipboard~XClipboard
x_Transferable = x_Clipboard~getContents()
flavorslist = x_Transferable~getTransferDataFlavors()
flavorslistlength = bsf('arrayLength', flavorslist)
counter = 1
found = false;
do while (counter <= flavorslistlength) & (found = false)
found = (flavorslist[counter]~bsf.getFieldValue("MimeType") = "text/plain;charset=utf-16")
counter = counter + 1
end
if found then
do
counter = counter - 1
s_Converter = x_MultiServiceFactory~createInstance("com.sun.star.script.Converter")
x_TypeConverter = s_Converter~XTypeConverter
content = x_Transferable~getTransferData(flavorslist[counter])
stringtype = bsf.getConstant("com.sun.star.uno.TypeClass", "STRING")
cliptext = x_TypeConverter~convertToSimpleType(content, stringtype)
end
cliptext = cliptext || DATE("E",,,".")
x_TextDocument = x_Document~XTextDocument
x_Text = x_TextDocument~getText
s_CurrentController = x_TextDocument~getCurrentController()
x_TextViewCursorSupplier = s_CurrentController~XTextViewCursorSupplier
x_CurrentCursor = x_TextViewCursorSupplier~getViewCursor()
x_TextCursor = x_Text~createTextCursorByRange(x_CurrentCursor~getStart())
x_SimpleText = x_Text~XSimpleText
x_SimpleText~insertString(x_TextCursor, cliptext, .false)
::requires UNO.CLS
|
Changelog| Date | User | Modification |
|---|
| 2008-10-13 | 1 | Initial version |
|