I am trying
Code: Select all
pos = GetCaretPosition()
msgbox(pos)
Code: Select all
pos = GetCaretPosition()
msgbox(pos)
Code: Select all
mri thiscomponent.currentcontroller.componentwindow.accessiblecontext
JeJe wrote:I suspect you want something different from what you're asking. If what you really want is the viewcursor, the information is here:
https://wiki.openoffice.org/wiki/Writer/API/View_cursor
*
Thanks, I am going to download mriAs for the accessiblecontext, which is what you're asking about. I suggest getting Mri if you haven't got it already. Then take an object like the current componentwindow and explore its accessiblecontext by typing
Code: Select all
mri thiscomponent.currentcontroller.componentwindow.accessiblecontext
You need to go through the child windows till you find the one which supports XAccessibleText and explore that. The information is read only.
Code: Select all
vc=thiscomponent.currentcontroller.viewcursor
tc = vc.text.createtextcursorbyrange(vc)
tc.goright(1,true)
msgbox tc.string
tc.collapsetostart
tc.goleft(1,true)
msgbox tc.string
Hmm. That's sadJeJe wrote:It doesn't say on that page you linked to that getCharacterAttributes returns that information. I could be wrong but I presume it returns these:
https://www.openoffice.org/api/docs/com ... rties.html
But you can find out when you explore.
Well I can indeed compare the distance between my text cursor and every frame, but only if the character returned by your code is null. Still may me slow when looping with multilple frames.The viewcursor doesn't appear to give the information about the objects that are anchored to it either. It may be that that information can only be found from the object itself.
If that's the case the only way might be to create a list of textranges for your anchors and test the new cursor textrange against them every time you move the text caret/cursor. That might or might not be unacceptably slow.
Edit: slow and/or crash prone.
Code: Select all
anchstart = thiscomponent.textframes.getbyindex(0).getanchor.getstart
vcend = thiscomponent.currentcontroller.viewcursor.getend
msgbox thiscomponent.text.compareRegionStarts(anchstart,vcend)
Code: Select all
sub left
oDoc = thiscomponent
oVC = oDoc.getCurrentController.getViewCursor
vc=oDoc.currentcontroller.viewcursor
tc = vc.text.createtextcursorbyrange(vc)
tc.goright(1,true)
tc.collapsetostart
tc.goleft(1,true)
mychar = tc.string()
if(mychar = "") then
vcend = oDoc.currentcontroller.viewcursor.getend
myFrames = oDoc.textframes
count = myFrames .Count
For i = 0 to count - 1
anchstart = myFrames.getbyindex(i).getanchor.getstart
If (oDoc.text.compareRegionStarts(anchstart,vcend)= 1) then
target = myFrames.getbyindex(i)
end If
next i
oVC.gotoRange(shup, false)
oVC.goRight(1,false)
else
oVC.goLeft(1,false) 'We want the caret to move left since we unassigned the move left event from left button.
end if
end sub
Code: Select all
sub main
doc = thiscomponent
ctrl = doc.CurrentCOntroller
vc = ctrl.ViewCursor
anchor = following_anchor(vc)
if not isnull(anchor) then
mri anchor
end if
end sub
function following_anchor(vc)
following_anchor = Nothing
T = vc.Text
c = T.createTextCursorByRange(vc.End)
c.goRight(1, True)
e = c.createContentEnumeration("com.sun.star.text.TextContent")
on error resume next
following_anchor = e.nextElement()
end function
Code: Select all
compa = oDoc.text.compareRegionStarts(anchstart,vcend)
And then I can get the frame name withhubert lambert wrote:Hi,
If I understand correctly your need, here is a function that returns any object anchored right after the view cursor position:RegardsCode: Select all
sub main doc = thiscomponent ctrl = doc.CurrentCOntroller vc = ctrl.ViewCursor anchor = following_anchor(vc) if not isnull(anchor) then mri anchor end if end sub function following_anchor(vc) following_anchor = Nothing T = vc.Text c = T.createTextCursorByRange(vc.End) c.goRight(1, True) e = c.createContentEnumeration("com.sun.star.text.TextContent") on error resume next following_anchor = e.nextElement() end function
Code: Select all
anchor.getName()