0

I have several shapes in LO Calc and I need those shapes to change their sizes when they are mouse clicked: the first click enlarges the shape, the second click restores the original size.

I'm trying to do this with a macro assigned to those shapes. My problem and my question: how to determine within a macro which shape has been clicked?

I know how to get the current selected shape:

dim doc as object
doc = ThisComponent
someVar = doc.CurrentSelection...

But a shape when clicked is not getting selected and this method is not working.

I tried to add a parameter for the event object to the macro:

sub ChangeSize( oEvent )

But this produces a message about wrong number of parameters.

Is there a way to detect the caller of a macro in LO Basic? Or maybe another way to implement size changing with a mouse click?

P.S. One can use a separate button for calling the macro and click this button after selecting the needed shape, but this way is less convenient.

EDIT: As I guessed below in the comments, the described task can be solved via the mouse and shape coordinates. The key points for the solution I found here: How to get Document-Coordinates from a Mouse Click in an OpenOffice BASIC Macro

Al Berger
  • 1,048
  • 14
  • 35

1 Answers1

0

Instead of detecting the caller, assign a different one-line macro for each shape clicked event.

Sub ShapeClickedA
    ChangeSize("ShapeA")
End Sub
Sub ShapeClickedB
    ChangeSize("ShapeB")
End Sub

Related: LibreOffice macro showing simple TextBox shape

P.S. After answering, I realized you asked the linked question as well. How is this different, and is the other answer not satisfactory?

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • Hello Jim. Your previous answer is very satisfactory and I'm using that method very often. But this question is about a different use case. In the previous case one manually creates each associated shape and conjugates it with the parent shape. I use it for permanent richly formatted textual data in diagrams. In this case I need to deal with tens of small shapes (in a table) the text in which need not to be specially formatted and which can be easily added and removed. So in this case it's more convenient not to create an additional shape for each small shape, but – Al Berger Jul 22 '20 at 19:34
  • to enlarge and shrink the original one. I guess that one could try somehow to use the mouse cursor coordinates to find the clicked shape, because as I guess, to the moment when the macro is running the information about the clicked shape is already lost. – Al Berger Jul 22 '20 at 19:34
  • @AlBerger: It feels like I am missing something about what you are trying to do. What shape is getting clicked, what shape has the macro assigned to it, and what do you want to happen as a result? If these small shapes have macros assigned to them, then I don't understand why you can't assign them to something like `ShapeClickedA` as in my answer. Maybe it would help to edit your question and provide instructions to create a reproducible example. – Jim K Jul 22 '20 at 21:45
  • Also, you mentioned a couple of times about not wanting to edit the text of the shape, but I don't understand how that is relevant. In my other answer, I suggested you give them a name by right-clicking and choosing `Name...` But that should not affect the text. Are you trying to avoid having to assign a unique name? Perhaps you could write a macro to assign the names. – Jim K Jul 22 '20 at 21:56
  • Actually, that may be the answer you're looking for. Write a macro to go through each shape on the drawpage and assign a name and a corresponding event handler. So whenever a new transient shape gets added, run the macro to redo the names and event handlers. If this sounds right, I may be able to suggest how to write code like that. – Jim K Jul 22 '20 at 22:03
  • Hi, Jim. I updated the question. Basically, the described functionality is fully achieved: after clicking a shape it toggles its size Although a minor new question appeared: how to programmatically bring the enlarged shapes to foreground (after enlargement they may be partly covered by neighbour shapes). – Al Berger Jul 24 '20 at 18:54
  • UPDATE: the shape's z order is also sorted out. Thanks for helping! – Al Berger Jul 24 '20 at 19:28
  • @AlBerger: Instead of the edit to the question, maybe you should post an answer explaining your solution. – Jim K Jul 24 '20 at 20:53