How to get XTextRange showing on the screen

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
kwalcock
Posts: 24
Joined: Thu Oct 09, 2014 11:54 am

How to get XTextRange showing on the screen

Post by kwalcock »

For a watermarking application I need to figure out what portion of a Writer document the user can see so that I can watermark other portions without disturbing the user. I can even assume a simple document with no frames or tables, etc.

So far the closest I have found is to use an XTextViewCursor, do a screenUp(), and then take the range from there to the beginning of the document. Likewise, I can do a screenDown() and then take the range to the end of the document. The part in between, approximately, is to be avoided.

Unfortunately, with the XTextViewCursor, the results of screenUp() and screenDown() are actually visible, which won't be good for the user trying to type. I can use lockControllers() to prevent some screen updates, but the page margins and the window background still show the flicker of the text scrolling up and down.

Does anyone else know of a better way to get the range(s) of text showing on the screen or of a way to prevent the flicker? Are there other controllers than need to be locked?

The current code is something like

ThisComponent.lockControllers()
viewCursor = ThisComponent.getCurrentController().getViewCursor()
viewCursor.screenDown()
MsgBox("Check for flicker in case it doesn't show")
viewCursor.screenUp()
ThisComponent.unlockControllers()

Thanks
Apache OpenOffice 4.0.1
Windows, Linux, MacOS
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How to get XTextRange showing on the screen

Post by FJCC »

If I run the macro GetData, then go to the document and move the view to elsewhere, running RestoreVdata makes the view jump back to the state stored in Vdata.

Code: Select all

Global Vdata
Sub GetData
Vdata = ThisComponent.CurrentController.getViewData()
End Sub

Sub RestoreVdata
ThisComponent.CurrentController.restoreViewData(Vdata)
End Sub

The content of Vdata is
5860;17826;120;0;15500;13675;22863;0;0
but I don't know what the various numbers mean. The information you want must be in there somewhere.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
kwalcock
Posts: 24
Joined: Thu Oct 09, 2014 11:54 am

Re: How to get XTextRange showing on the screen

Post by kwalcock »

Thanks for alerting me to the interesting possibility. The values returned are

ViewId, ViewLeft, ViewTop, VisibleLeft, VisibleTop, VisibleRight, VisibleBottom, ZoomType, ViewLayoutColumns, ViewLayoutBookMode, ZoomFactor, and IsSelectedFrame.

If I scroll around in the document without changing cursor position, the returned values do not change. I therefore do not think they can be used to figure out what text the user is seeing.
Apache OpenOffice 4.0.1
Windows, Linux, MacOS
Post Reply