automatically checked boxes

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
vparis20e
Posts: 1
Joined: Tue May 27, 2008 12:46 am

automatically checked boxes

Post by vparis20e »

Hello!

I want to create a form in which, when certain boxes get checked/unchecked, others automatically also get checked/unchecked.

I thought the best is to write a macro to check the bunch of box that need to be "linked" to another and then set this macro for the proper event attached to the "main" checkbox

I tried to record a macro that goes to one checkbox to the other with TAB and checks the boxes with SPC but I can't get this %$!censured@!! macro to work (nothing gets recorded at all ) !!! the web says something about the dispach framework which can get the macro recorder not to work, the pb is I have no idea how to write the macro otherwise... (not familiar with object programming ...)

I use a french version of oo 2.4 with windows XP.

can someone please help either with the recording/writing of the marco or with another idea how to automatically check/uncheck checkboxes ?

many thanks in advance for any info !

V
pitonyak
Volunteer
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

Re: automatically checked boxes

Post by pitonyak »

Using a recorded macro is not likely to happen.

I have a great example, but it contains a lot of stuff that I can not make public (and it is unfortunately not easy to clean); very sad...

Consider the following, however:

Code: Select all

REM Not really safe, because it assumes the form name of "Standard".
Function GetControlByName(oDoc, oSheet, sName$)
  GetControlByName = oSheet.getDrawPage().getForms().getByName("Standard").getByName(sName$)
End Function

Function GetControlModelByName(oDoc, oSheet, sName$)
  GetControlModelByName = oDoc.CurrentController.getControl(GetControlByName(oDoc, oSheet, sName$))
End Function
Each macro assumes that they are given a reference to the Calc document and to the sheet containing the control. Consider the first macro, which returns a reference to the named control.
Each sheet contains a draw page. Each draw page contains forms. Each form contains controls. The usual default form name is Standard, so this might work for you. If you look at AndrewBase.odt, I have numerous examples accessing forms in Write documents along with a description of how this works. Things are similar for a Calc document.

OK, so you can get the Standard form by its name, and then obtain your named control. Most things that you want to do with a control, you really want to do to the model rather than the control itself.

Ask the Calc document (oDoc) for the currentController (the thing that interacts with the user, handles the keyboard, etc...) then ask the current controller for the model. Odd that the function name is getControl(), but that accepts a reference to the control, and returns the model. Then, you can modify the model.

If you take a look at AndrewMacro.odt, I have some material dealing with a few control types.
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
Post Reply