Apache OpenOffice (AOO) Bugzilla – Issue 80762
XEnumerationAccess of TextRange inside TextTable returns incorrect enumeration
Last modified: 2013-11-21 01:32:33 UTC
the code below doesn't work as it should. when used within a table it also gets all the text in the next cell in the table. I'm using it to apply bold (as well as other character attributes) and it works perfectly fine outside of tables. oVC = thisComponent.currentController.ViewCursor oTextCursor = oVC.Text.createTextCursorByRange(oVC) If oVC.isCollapsed() Then oTextCursor.gotoStartOfWord (False) oTextCursor.gotoEndOfWord (True) End If I've put this under the most recent version that I've observed it in (WinXP). I have also observed it on a Mac.
MRU->JSK: could you please have a look? Thanks!
to cn
cn: I can not reproduce this behavior in ooh680_m3, which will be the OOo 2.4
whoops. i didn't trace it properly. the code as a whole is what does it. sorry. subToggleCharacterStyles("i-code", array("CharFontCharSet","CharFontFamily","CharFontName","CharFontPitch")) ... Sub subToggleCharacterStyles(sStyle, mResetProps) oCurSelection = thisComponent.getCurrentSelection() If oCurSelection.supportsService("com.sun.star.text.TextRanges") Then nCount = oCurSelection.Count If nCount = 1 Then 'If nothing selected then select current word oVC = thisComponent.CurrentController.ViewCursor oTextCursor = oVC.Text.createTextCursorByRange(oVC) If oVC.isCollapsed() Then oTextCursor.gotoStartOfWord (False) oTextCursor.gotoEndOfWord (True) End If 'oTextRange = oCurSelection.getByIndex(0) subProcessTextRange(oTextCursor, sStyle, mResetProps) Else For i = 1 To nCount - 1 oTextRange = oCurSelection.getByIndex(i) subProcessTextRange(oTextRange, sStyle, mResetProps) Next End If End If End Sub Sub subProcessTextRange(oTextRange, sStyle, mResetProps) oTextElementEnum = oTextRange.createEnumeration While oTextElementEnum.hasMoreElements() oTextElement = oTextElementEnum.nextElement() If oTextElement.supportsService("com.sun.star.text.Paragraph") Then subProcessParagraph(oTextElement, sStyle, mResetProps) Else 'if oTextElement.supportsService("com.sun.star.text.TextTable") then subProcessTable(oTextElement, sStyle, mResetProps) End If Wend End Sub Sub subProcessTable(oTextElement, sStyle, mResetProps) mCells = oTextElement.getCellNames() For i = 0 To UBound(mCells) oCell = oTextElement.getCellByName(mCells(i)) subProcessTextRange(oCell.text, sStyle, mResetProps) Next End Sub Sub subProcessParagraph(oTextElement, sStyle, mResetProps) oCharStyles = thisComponent.styleFamilies.getByName("CharacterStyles") If Not oCharStyles.hasByName(sStyle) Then subCreateMissingStyle (sStyle) End If oPortionEnum = oTextElement.createEnumeration While oPortionEnum.hasMoreElements() oPortion = oPortionEnum.nextElement() subResetProperties(oPortion, mResetProps) mCharStyleNames = oPortion.getPropertyValue("CharStyleNames") sCharStyleNames = "" If IsEmpty(mCharStyleNames) Then sCharStyleNames = sStyle ElseIf UBound(mCharStyleNames) < 0 Then sCharStyleNames = sStyle Else sCharStyleNames = Join(mCharStyleNames, ",") & "," nLoc = InStr(sCharStyleNames, sStyle & ",") If nLoc > 0 Then sCharStyleNames = Left(sCharStyleNames, nLoc - 1) & Right(sCharStyleNames, Len(sCharStyleNames) - (nLoc + Len(sStyle))) If Right(sCharStyleNames, 1) = "," Then sCharStyleNames = Left(sCharStyleNames, Len(sCharStyleNames) - 1) Else sCharStyleNames = sCharStyleNames & sStyle End If End If mCharStyleNames = Split(sCharStyleNames, ",") If IsEmpty(mCharStyleNames) Then oPortion.setPropertyToDefault ("CharStyleNames") ElseIf UBound(mCharStyleNames) < 0 Then oPortion.setPropertyToDefault ("CharStyleNames") Else oPortion.setPropertyToDefault ("CharStyleNames") oPortion.setPropertyValue("CharStyleNames", mCharStyleNames) End If Wend End Sub Sub subResetProperties(oPortion, mResetProps) For i = 0 To UBound(mResetProps) oPortion.setPropertyToDefault (mResetProps(i)) Next End Sub
The summary is misleading. This bug is unrelated to createTextCursorByRange. I suggest to change the summary to "XEnumerationAccess of TextRange inside TextTable returns incorrect enumeration". The general issue is that any TextRange inside a TextTable will always return (via its XEnumerationAccess interface) an enumeration that contains only the complete table rather than just the paragraphs contained in the range. This is not limited to cursors. It can also be reproduced with a Bookmark's anchor text range.
changed summary.
Created attachment 54973 [details] Demonstrates that TextRange inside TextTable always returns the whole table when enumerating.
I've attached a simpler test case for the issue. The document contains 2 bookmarks, "test" and "test1". The first is inside the table (on the text "bookmark"), the 2nd is outside of the table. If you press the button push me, a macro spits out the getString() value of the corresponding text ranges as well as the implementation name of the 1st element of the corresponding enumeration. The macro shows that the text ranges do know what they contain (the getString() value is correct in both cases), but the textrange inside the table returns the complete table when enumerating.
cn->tl: one for you
Created attachment 63335 [details] Demonstrates problem and workarround
Maybe there is a connection between this problem and Issue 98552?
Hi, Stumbled on this, as I was building a macro to reformat note anchors (i.e. between brackets or parentheses, with leading space or not...) Not likely to be solved soon, is it ? And why is it impossible to vote ?