Apache OpenOffice (AOO) Bugzilla – Issue 22746
Cursor "lost" after .uno:InsertGraphic
Last modified: 2013-02-24 21:07:55 UTC
After dispatching .uno:InsertGraphic to a text document, the cursor is "lost": it's no longer visible and createTextCursorByRange will crash when used this way: Reference<text::XTextViewCursor> xViewCursor = xViewCursorSupplier->getViewCursor (); Reference<text::XTextRange> xStart = xViewCursor->getStart (); Reference<text::XTextCursor> xTextCursor = xText->createTextCursorByRange (xStart);
forwarding to responsible developer
Need to check: The following macro results in a runtime exception when some text is selected: sub Main oDoc = thiscomponent oVC = oDOc.getCurrentController.getViewCursor 'msgbox IsNull(oVc) 'msgbox oVc.getString InsertGrafik oStart =oVC.getStart oTC = oDoc.getText.createTextCursorByRange( oStart ) end sub sub InsertGrafik rem ---------------------------------------------------------------------- rem define variables dim document as object dim dispatcher as object rem ---------------------------------------------------------------------- rem get access to the document document = ThisComponent.CurrentController.Frame dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") rem ---------------------------------------------------------------------- dim args1(3) as new com.sun.star.beans.PropertyValue args1(0).Name = "FileName" args1(0).Value = "file:///C:/office-prox-src680_m32-1/share/gallery/apples.gif" args1(1).Name = "FilterName" args1(1).Value = "<All formats>" args1(2).Name = "AsLink" args1(2).Value = false args1(3).Name = "Style" args1(3).Value = "Graphics" dispatcher.executeDispatch(document, ".uno:InsertGraphic", "", 0, args1()) end sub
Set target to OOo 2.0
When running the macro the following code in unoobj2.cxx SwXTextRange::CreateTextRangeFromPosition will be reached: : case SwFlyStartNode: : { : SwFrmFmt* pFmt; : if(0 != (pFmt = pSttNode->GetFlyFmt())) : { : aRet = new SwXTextRange(*pFmt, *pNewCrsr); : : } : } The pNewCrsr has the attribute bRemainInSection set and thus should not move out of the section (and in the graphic as it effectively does). TL->FME: Please have a look. Thanks!
FME->TL: I cannot see a problem here. The view cursor will be modified by the InsertGraphic operation. The only problem according to OS is that the getStart() call should already throw the exception.
.
Since the view is selecting the graphic after the InsertGrafic call it is not possible to create a TextCursor from the ViewCursor (especially since if the grafik is anchored to the page there is no guessing what the text before or after might be). If you want to go on with a TextCursor you need to remember it before inserting the grafic or create a new cursor, but not via passing the view cursor (which is currently not selecting any text) as argument to the createTextCursorByRange funcrion. Fixed in CWS tl03. Files changed: - unotxvw.hxx new revision: 1.7.664.1 - unotxvw.cxx new revision: 1.48.40.1 I added code to the SwXTextViewCursor to check if there is a text selection when functions are called that need a working text cursor. This is the case for all functions from the interfaces - XLineCursor - XTextCursor - XTextRange - XViewCursor those functions will now throw a RuntimeException when there is no text selection. For the example this means the call to xViewCursor->getStart() will now fail.
OK in CWS tl03.
can't see any changes in tl03 and so will remove it from the cws
back to you to take a second look
TL->MBU: Please have a look.
fix had a bug :-) SwXTextViewCursor::IsTextSelection in /sw/ui/uno/unotxvw.cxx is now working as expected...
to me for verification
sw->mbu: the given macro still throws a runtime exception at oStart =oVC.getStart ... seems there is still a bug in the fix for the fix ... or do I miss something ?
as thomas wrote somewhere above "For the example this means the call to xViewCursor->getStart() will now fail." the runtime exception is the correct behavior. see his full explanation for further reference. originally the call to "createTextCursorByRange " caused a crash which now has been fixed.
ok in cws_mbu2 => fixed
verified
TL->QA: Please not that #i22746# should still be Ok.
ok in src680_m73 => closed