2

In Writer, I would like to search for some text and when found position the view to the top of the view/window.

Using the following code,

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.SearchString"
args1(0).Value = ":"

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

the view changes and it shows the selection but it is not in any particular place. I want it to be at the top of the window/view.

I've also found elsewhere the use of ThisComponent.currentController.getViewData() and restoreViewData(). So I experimented and determined how to change the data returned in order to get a vertical scroll but nothing happens. For example...

vd = ThisComponent.currentController.getViewData()
vdParts = Split(vd, ";")
vdParts(6) = CLng(vdParts(6)) + 1000
vd = join(vdParts, ";")
ThisComponent.currentController.restoreViewData(vd)

Any suggestions?

PS: I am running version 5.0.5.2 on Windows 7 x64

Dude named Ben
  • 507
  • 3
  • 16

1 Answers1

1

Spreadsheets have View Panes that can be manipulated, but it does not look like there is a similar interface in Writer.

Instead, use the View Cursor to go down one or two pages, then move back to the location of the search result.

Also, do not use the dispatcher for the search. Use the API instead, like in section 7.14 of Andrew Pitonyak's macro document.

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • Thx Jim. I did try a view cursor but in my experiments the view cursor did not change the view in order to display the selection. I then remembered the dispatcher examples and thought to try it, and I was pleasantly surprised that _it_ did. – Dude named Ben Apr 05 '16 at 12:44
  • After posting previous comment and seeing your suggestion Jim made by others, I realised that the view is not being refreshed when a macro is run from the editor. I had to assign a Keyboard Shortcut and run the macro that way to get it to change the view... a design flaw??? – Dude named Ben Apr 05 '16 at 13:02
  • I normally do not run macros from the editor, because that makes the editor the current component (which can be useful, but not what we want in this case). Instead, I normally go to `Tools -> Macros -> Run Macro` using keyboard shortcuts. To make it possible to run from the editor, instead of using ThisComponent, use the component of the text document, starting with [desktop.getComponents()](https://www.openoffice.org/api/docs/common/ref/com/sun/star/frame/XDesktop.html#getComponents). – Jim K Apr 05 '16 at 18:37
  • Jim, checking with [Andrew's macro document](http://www.pitonyak.org/AndrewMacro.pdf), it says on more than one place that `ThisComponent` does not change when the IDE is in use (see section 3.6.9.2), it continues to point to the last document. It has been this way since v2 of OOo. `StarDesktop.getCurrentComponent()` on the other hand will point to the IDE when it is in use. – Dude named Ben Apr 06 '16 at 01:30