[Solved] [Base] Get position of a Control ListBox (Macro)

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
bcf179en
Posts: 3
Joined: Thu Mar 17, 2016 12:35 pm

[Solved] [Base] Get position of a Control ListBox (Macro)

Post by bcf179en »

Hello everybody,

Désolé de mon anglais

I have already managed to place some controls by programming ( ListBox and Labels )

Here is the file .odb
essai2.odb
(17.22 KiB) Downloaded 186 times
Now what I want is to affect "post-it", that is to say, to move each ListBox programmatically.
To reach my goal, I start slowly. For now, what I want is that once having placed my 20 ListBox and Labels (4 x 5) by clicking on the "New Group" button, be able to click on the ListBox and have (display) coordinates.

After making clicking a Control (ListBox), I get to see the name that I decided to give it.

Then I wanted to show just the X coordinate of control. But I am told that the getPosition method is not found. Yet for each control, I did well setPosition (Point) at the time of creation.
I do not see at all what the problem is.
For contact information for controls, I used the same procedure:
deplaceCercle.odg
(55.67 KiB) Downloaded 188 times
I wish I had an answer to my question. and I thank you even before the answer.

Cordially.
Last edited by bcf179en on Mon Mar 21, 2016 3:43 pm, edited 1 time in total.
LibreOffice Version: 4.2.8.2 Ubun 14.04
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: [Base]-Get position of a Control ListBox (Macro)

Post by MTP »

If you're looking for position information, you need the object from the DrawPage, not the Forms.

So change the assignment for oObj to

Code: Select all

oObj = FindObjectByName(ThisComponent.DrawPage, oControl.Name)
and the function to

Code: Select all

Function FindObjectByName(oDrawPage As Object, nomObj as String) As Object
 Dim objX As Object
 Dim    x As Long
 
 For x = 0 To oDrawPage.Count - 1
  objX = oDrawPage.getByIndex(x)
  If objX.Control.Name = nomObj Then
   FindObjectByName = objX ' objet trouvé
   MsgBox objX.Control.Name
   Exit Function
  EndIf
 Next x
End Function     
And now this will work:

Code: Select all

MsgBox oObj.getposition.x
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: [Base]-Get position of a Control ListBox (Macro)

Post by UnklDonald418 »

In your "Sub DamePosition(oEvt as Object)"

try

Code: Select all

Xpos = oEvt.Source.PosSize.X
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
bcf179en
Posts: 3
Joined: Thu Mar 17, 2016 12:35 pm

Re: [Base]-Get position of a Control ListBox (Macro)

Post by bcf179en »

Hello,

Thank you.

What is the difference between

Code: Select all

oEvt.X


and

Code: Select all

oEvt.Source.X
.

In my opinion the first one get the position in the ListBox, yes or not?
LibreOffice Version: 4.2.8.2 Ubun 14.04
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: [Base]-Get position of a Control ListBox (Macro)

Post by UnklDonald418 »

The Event that triggers your macro is a mouse click so it reports the position of the mouse inside the control/ListBox.

Code: Select all

Xpos = oEvt.X 
For the ListBoxes on your form Xpos will always be somewhere between 0-189 (the Width is 190), regardless of which one you select.

whereas

Code: Select all

Xpos = oEvt.Source.PosSize.X
gets the position on the form of the control/ListBox so Xpos only changes if you select a Listbox in a different column. On your form Groupe5 will report the same value for Xpos as Groupe1, but Groupe2 will be different.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
bcf179en
Posts: 3
Joined: Thu Mar 17, 2016 12:35 pm

[Solved][Base] Get position of a Control ListBox (Macro)

Post by bcf179en »

Thank you!!!!
LibreOffice Version: 4.2.8.2 Ubun 14.04
Post Reply