Changing the mouse pointer

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Ove
Posts: 10
Joined: Sun Oct 27, 2019 6:46 pm

Changing the mouse pointer

Post by Ove »

I'm trying to change the mouse pointer due to a lengthy operation, but the pointer does not change although the macro seems to work.
Can anyone tell me what I'm doing wrong?

Thanks in advance
\Ove

Code: Select all

sub Worker
	...
	...
	setWindowPointer(ThisComponent.CurrentController.Frame.GetContainerWindow(), True)
	...
	...
	setWindowPointer(ThisComponent.CurrentController.Frame.GetContainerWindow(), False)
end sub


Sub setWindowPointer(oWin As Object, bWait As Boolean)
	Dim oPointer As Object
		
	oPointer = CreateUnoService("com.sun.star.awt.Pointer")
   	If bWait Then
      		oPointer.SetType(com.sun.star.awt.SystemPointer.WAIT)
  	Else
    		oPointer.SetType(com.sun.star.awt.SystemPointer.ARROW)
   	Endif
   		oWin.SetPointer(oPointer)
End Sub
Last edited by robleyd on Wed Jan 22, 2020 11:56 pm, edited 1 time in total.
Reason: Added Code tags
OpenOffice 4.1.7 on Windows 7
JeJe
Volunteer
Posts: 2781
Joined: Wed Mar 09, 2016 2:40 pm

Re: Changing the mouse pointer

Post by JeJe »

Is the lengthy operation in between the two changes?
Dots aside, your code as is sets the window pointer to wait then immediately back to arrow.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2781
Joined: Wed Mar 09, 2016 2:40 pm

Re: Changing the mouse pointer

Post by JeJe »

The only other thing I can think of is is your operation on a hidden document?
As the code is fine its perhaps something to do with the code you haven't posted (no-one can help you there).

Edit: you can see that the code is fine on its own by putting wait 1000 in between the two changes.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Ove
Posts: 10
Joined: Sun Oct 27, 2019 6:46 pm

Solved: Changing the mouse pointer

Post by Ove »

Andrew Pitonyak had the answer: this operation is not supported as of OOo version 1.1.3.

" You can not set the mouse pointer of a document window via UNO-API. VCL manages the mouse pointer based on the window, not the top window. Any VCL window can have its own mouse pointer set. If you want to change the mouse pointer of the document window, you must access its XWindowPeer (not the peer of the frame window), and this is not available in the API. Another problem might be that OOo changes the mouse pointer internally and overrides your setting."

Thanks anyway, to all who responded

\Ove
OpenOffice 4.1.7 on Windows 7
JeJe
Volunteer
Posts: 2781
Joined: Wed Mar 09, 2016 2:40 pm

Re: Changing the mouse pointer

Post by JeJe »

?

Works for me.

Code: Select all

sub Worker
   setWindowPointer(ThisComponent.CurrentController.Frame.GetContainerWindow(), True)
   wait 1000
   setWindowPointer(ThisComponent.CurrentController.Frame.GetContainerWindow(), False)
end sub


Sub setWindowPointer(oWin As Object, bWait As Boolean)
   Dim oPointer As Object
      
   oPointer = CreateUnoService("com.sun.star.awt.Pointer")
      If bWait Then
            oPointer.SetType(com.sun.star.awt.SystemPointer.WAIT)
     Else
          oPointer.SetType(com.sun.star.awt.SystemPointer.ARROW)
      Endif
         oWin.SetPointer(oPointer)
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 34617
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Changing the mouse pointer

Post by RoryOF »

OOo 1.1.3 is a long time ago!

I' suggest trying JeJe's code.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2781
Joined: Wed Mar 09, 2016 2:40 pm

Re: Changing the mouse pointer

Post by JeJe »

My code is just the original with a wait statement in. If you move the mouse it will revert to an I pointer. You could try something like this... changing the for next to a do loop with your code in.

Code: Select all

sub Worker
for i = 0 to 1000
   setWindowPointer(ThisComponent.CurrentController.Frame.GetContainerWindow(), True)
   wait 50 ' or your code here 
      next

   setWindowPointer(ThisComponent.CurrentController.Frame.GetContainerWindow(), False)
end sub


Sub setWindowPointer(oWin As Object, bWait As Boolean)
   Dim oPointer As Object
      
   oPointer = CreateUnoService("com.sun.star.awt.Pointer")
      If bWait Then
            oPointer.SetType(com.sun.star.awt.SystemPointer.WAIT)
     Else
          oPointer.SetType(com.sun.star.awt.SystemPointer.ARROW)
      Endif
         oWin.SetPointer(oPointer)
         
         
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2781
Joined: Wed Mar 09, 2016 2:40 pm

Re: Changing the mouse pointer

Post by JeJe »

Two alternatives are to show your own dialog, perhaps with a progress bar, or to show progress in the status bar:

viewtopic.php?f=21&t=10104
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply