openoffice calc button mouse over event cursor change

2.4k views Asked by At

I have created an OpenOffice Calc spreadsheet and I have inserted a button into it. I can successfully call a macro with the button. I want to have a cursor hand when I mouse-over the button.

First, I switched to 'Design' mode, then I right-clicked on my button, and using the pop-up menu which appears, I selected the 'Events' tab. Then I clicked on the 'Mouse inside' dot dot dot button. In the 'Assign action' window that popped up, I clicked on the 'Macro..' button. I then got the 'Macro Selector' pop-up window, where I choose the 'OpenOffice Macros' folder in the left side pane. I expanded 'Tools'>'ModuleControls' from that 'Library' pane and then selected 'SwitchMousePointer' from the right side 'Macro name' pane, then clicked the 'Ok' 'Ok' buttons.

But now when I hover the mouse cursor over my button I get an OpenOffice Error window popping up "A Scripting Framework error occurred while running the Basic script Tools.ModuleControls.SwitchMousePointer."

I've very little OO experience but I have not found what I want here or on the OO Forum site. I would be very grateful to get some help, thanks, Nige.

1

There are 1 answers

7
Axel Richter On

The SwitchMousePointer needs attributes (oWindowPeer as Object, bDoEnable as Boolean). So you can't simply assign it to a event. And it will not do what you think.

You should better write you own Sub to change the Pointer. Also there is no need to do this on every mouse event. It should be done once on sheet activate for example.

For a introduce in OpenOffice.org BASIC Programming see https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide. And you will need a debugging tool, if you want to program your own BASIC macros. Therefore see especially: https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/UNO_Tools

Assuming on the sheet is a button named "Push Button 1" then:

Sub ChangeMousePointer
    oController = ThisComponent.CurrentController
    oButtonModel = oController.ActiveSheet.DrawPage.Forms(0).getByName("Push Button 1")
    oButtonControl = oController.getControl(oButtonModel)
    oWindowPointer = CreateUnoService("com.sun.star.awt.Pointer")
    oWindowPointer.SetType(com.sun.star.awt.SystemPointer.HAND)
    oButtonControl.Peer.setPointer(oWindowPointer)
End Sub

And assign this to the sheet event Activate Document. Right click the sheet tab and select Sheet Events from the context menu. Then: enter image description here

If, and only if, the button is on Sheets(0) then the sheet event Activate Document not occurs while opening the document and this sheet is in front. In this case we have to call the Sub ChangeMousePointer also on document event Open Document.

Sub Document_Open
    oController = ThisComponent.CurrentController 
    oSheet = oController.ActiveSheet
    if oSheet.Name = ThisComponent.Sheets(0).Name then 
        if oController.ActiveSheet.DrawPage.Forms.Count > 0 then
            if oController.ActiveSheet.DrawPage.Forms(0).hasByName("Push Button 1") then
               call ChangeMousePointer
            end if
        end if
    end if
End Sub

To assign the macro to the document event Open Document select Tools - Customize from the menu and: enter image description here