Copy textstring to Clipboard <SOLVED>

Fernand Vanrie <[email protected]> Thu, 02 Dec 2010 12:15:28 +0100
Newsgroups gmane.comp.openoffice.devel.api
Message-ID <[email protected]>
Somewhere on the web (http://hermione.s41.xrea.com/pukiwiki/) i found 
finaly the correct Basic code to copy a text to the clipboard without 
opening ghidden docs etc...
I hope its usefull for others as well

Fernand

|Global sTxtCString AsString

Sub  clipboard_1
   sText ="123456"
   CopyToClipBoard(sText)
End  Sub

Sub  CopyToClipBoard( sText )
   ' create SystemClipboard instance
   oClip = CreateUnoService("com.sun.star.datatransfer.clipboard.SystemClipboard")
   oTR = createUnoListener("Tr_", _
       "com.sun.star.datatransfer.XTransferable")
   ' set data
   oClip.setContents(oTR,Null)
   sTxtCString = sText
   'oClip.flushClipboard() ' does not work
End  Sub

Function  Tr_getTransferData(aFlavor as com.sun.star.datatransfer.DataFlavor)
   If  (aFlavor.MimeType ="text/plain;charset=utf-16")Then
     Tr_getTransferData() = sTxtCString
   End  If
End  Function

Function  Tr_getTransferDataFlavors()
   Dim  aFlavor As new com.sun.star.datatransfer.DataFlavor
   aFlavor.MimeType ="text/plain;charset=utf-16"
   aFlavor.HumanPresentableName ="Unicode-Text"
   Tr_getTransferDataFlavors() = array(aFlavor)
End  Function

Function  Tr_isDataFlavorSupported(aFlavor as com.sun.star.datatransfer.DataFlavor) as Boolean
   If  aFlavor.MimeType ="text/plain;charset=utf-16"  Then
     Tr_isDataFlavorSupported = true
   Else
     Tr_isDataFlavorSupported = false
   End  If
End  Function|