Steffen,

I learned only to use the dispatcher when there is no API code available :-). (performance they say) Java is not realy my cup of tea, i trie to translate to Basic, i was also told that for some documents there is no Viewcursor (draw) The bigest advantage of using the SystemClipboard instance stuff is the fact that the code can been been used without opening any document.

I comeback when translated to Basic

Thanks for your respons

Fernand


 Hi Fernand,

i wonder which method to copy contents is recommended. I achieve the same but I use a different approach with XSelectionSupplier in combination with XDispatchHelper and the XTextViewCursor.:

    public void copyContent(XCellRange cellRange, XTextRange textRange)
    {
        // Get current controller
        XController currController = this.xModel.getCurrentController();

        // Get selection supplier
XSelectionSupplier xSelectionSupplier = (XSelectionSupplier)UnoRuntime.queryInterface(XSelectionSupplier.class, currController);

            // Select the cell range constructed above
xSelectionSupplier.select(AnyConverter.toObject(XCellRange.class, cellRange)); // Here you could throw in any (selectable) object you want to copy!
            // Get Dispatch Helper to dispatch commands
            XFrame xFrame = xModel.getCurrentController().getFrame();
XDispatchProvider xDispatchProvider = (XDispatchProvider) UnoRuntime.queryInterface(
                    XDispatchProvider.class, xFrame);

Object dispatchHelperObject = this.xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.DispatchHelper", this.xComponentContext); XDispatchHelper xDispatchHelper = (com.sun.star.frame.XDispatchHelper) UnoRuntime.queryInterface( com.sun.star.frame.XDispatchHelper.class, dispatchHelperObject);

            // Excute copy command
xDispatchHelper.executeDispatch(xDispatchProvider, ".uno:Copy", "", 0, new PropertyValue[] { new PropertyValue() });

// IMPORTANT!! the textViewCursor has to be set AFTER the uno:copy command!!!
            // We have the target selection
this.xTextViewCursorSupplier.getViewCursor().gotoRange(textRange, false);

            // Perform Paste command
xDispatchHelper.executeDispatch(xDispatchProvider, ".uno:Paste", "", 0, new PropertyValue[] { new PropertyValue() });
    }

I encounter a serious performance issue if i use this approach for a few hundred cell ranges. Maybe your approach doesn't suffer from this. A comment from the devs would be great on which method is recommended for copying stuff around.

Greetings,
Steffen

Am 02.12.2010 12:15, schrieb Fernand Vanrie:
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|






---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org

Reply via email to