Activate document after finding it in component enumeration

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
VCAR79
Posts: 2
Joined: Wed Jun 01, 2022 5:14 pm

Activate document after finding it in component enumeration

Post by VCAR79 »

 Edit: Split from [Solved] Accessing to a file other that ThisComponent because that topic is solved so you need your own. If you had the same problem you could use the same solution. Please do not post in another's topic unless you are helping to solve their problem for them. 

Sorry. In this case, i would like to know when you find the document you want access (Flag = 1) how do you activate it? Thanks!
OpenOffice 3.12 on Windows 10
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: [Solved] Accessing to a file other that ThisComponent

Post by FJCC »

What do you mean by "activate it". The document is assigned to the variable oDoc2. All of the methods and properties of the document are available through oDoc2.
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.
VCAR79
Posts: 2
Joined: Wed Jun 01, 2022 5:14 pm

Re: [Solved] Accessing to a file other that ThisComponent

Post by VCAR79 »

FJCC wrote: Thu Jun 02, 2022 9:06 pm What do you mean by "activate it". The document is assigned to the variable oDoc2. All of the methods and properties of the document are available through oDoc2.
I mean make it current and visible, in front. It's clear?
OpenOffice 3.12 on Windows 10
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: [Solved] Accessing to a file other that ThisComponent

Post by FJCC »

Add this line at the point where you want oDoc2 to have the focus.

Code: Select all

oDoc2.CurrentController.ComponentWindow.setFocus()
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.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Activate document after finding it in component enumeration

Post by Villeroy »

Code: Select all

Sub Main()
doc1 = StarDesktop.loadComponentFromURL("private:factory/swriter", 0, "_default", Array())
f1 = doc1.CurrentController.Frame
w1 = f1.ContainerWindow
w1.setPosSize(0,0,600,400,15)

doc2 = StarDesktop.loadComponentFromURL("private:factory/scalc", 0, "_default", Array())
f2 = doc2.CurrentController.Frame
w2 = f2.ContainerWindow
w2.setPosSize(400,0,600,400,15)
af = Array(f1, f2)
aw = Array(w1,w2)
Dim b as Boolean
on error goto exitErr:
while true
	f = af(cInt(b)+1)
	w = aw(cInt(b)+1)
	f.activate()
	w.setFocus()
	b = not b
	wait 1000
wend
exitErr:
End sub
Close a document window to exit.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply