OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to assign a macro to a TextGraphicObject event

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Markus B.
General User
General User


Joined: 08 Mar 2004
Posts: 7
Location: Münster Germany

PostPosted: Tue Apr 26, 2005 10:29 am    Post subject: How to assign a macro to a TextGraphicObject event Reply with quote

Hi,

I try to assign a macro to the "OnClick"- event of a TextGraphicObject object via a macro but such an assignment works only with the events of the document.
I use the following code

Code:

Sub AttachBasicMacroToEvent(oDocument as Object, EventName as String, SubPath as String)
Dim PropValue(1) as new com.sun.star.beans.PropertyValue
PropValue(0).Name = "EventType"
PropValue(0).Value = "StarBasic"
PropValue(1).Name = "Script"
PropValue(1).Value = "macro:///" & SubPath
oDocument.Events.ReplaceByName(EventName, PropValue())
End Sub

Sub Main
Dim oDoc As Object
Dim I As Integer
Dim Graphics As Object
Dim Graphic As Object

oDoc = ThisComponent
rem this assignment works fine
AttachBasicMacroToEvent(oDoc,"OnCloseApp","tests.Module1.Main()")
rem this assignment does nothing
Graphics = oDoc.getGraphicObjects()
For I = 0 to Graphics.count - 1
 Graphic = Graphics(I)
 AttachBasicMacroToEvent(Graphic,"OnClick","tests.Module1.Main()")
Next I
End Sub



The "OnClick"-event exists in the TextGraphicObject. The following code list all events of the TextGraphicObject.
Code:

...
 msgbox Join(Graphic.getEvents().getElementNames(),CHR$(10))
...



Any ideas ?
Thanks a lot! Markus B.

References
http://www.oooforum.org/forum/viewtopic.phtml?t=9258&highlight=replacebyname&sid=7d0d00db79b5ade00c4a94f29168c7b0]
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Tue Apr 26, 2005 2:34 pm    Post subject: Reply with quote

You assign a macro to those events by using OnClick on the shape.
See http://api.openoffice.org/docs/common/ref/com/sun/star/presentation/Shape.html#OnClick

Side note:
I know that the way you specifiy the macro is somewhat akward: You need to write the name the other way around, not "<library>.<module>.<function>" but "<function>.<module>.<library". Why this is so I have no idea Wink.

Christian
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
Markus B.
General User
General User


Joined: 08 Mar 2004
Posts: 7
Location: Münster Germany

PostPosted: Wed Apr 27, 2005 11:29 am    Post subject: Reply with quote

thank you for your answer
but I don' t understand exactly how I reach the OnClick property of the shape in a writer document. My code was for a writer document. Sorry I have forgotten to mention this.

I know how I reach the shapes via the DrawPage of the document.
Code:

...
oDrawPage = ThisComponent.getDrawPage()
nNumShapes = oDrawPage.getCount()
For I = 0 To oDrawPage.getCount() - 1
      oShape = oDrawPage.getByIndex( I )
      msgbox Join(oShape.getEvents().getElementNames(),CHR$(10))
      rem error no such object
      oShape.OnClick = xxx
      rem  no result
      AttachBasicMacroToEvent(oShape,"OnClick","test.Module1.Main()")
      rem  here I have tried to change the order to  <function>.<module>.<library> but     
      rem also with no result
      AttachBasicMacroToEvent(oShape,"OnClick","Main().Module1.test")
Next I

but also with no result

It is curious that this assignment
Code:

AttachBasicMacroToEvent(oDoc,"OnCloseApp","tests.Module1.Main()")

works (also in the order <library>.<module>.<function>)
and this assignments not
Code:

AttachBasicMacroToEvent(Graphic,"OnClick","tests.Module1.Main()")
AttachBasicMacroToEvent(oShape,"OnClick","test.Module1.Main()")


Any other ideas?
Thanks a lot! Markus B.
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Wed Apr 27, 2005 3:33 pm    Post subject: Reply with quote

I have written it down into a small prototype (it requires that there is at least one shape already inserted into the currently active impress document).
Code:
Sub Main
odoc = thisComponent
page = odoc.getDrawPages().getByIndex(0) 'first page
shape = page.getByIndex(0) 'first drawing-object
shape.onClick = com.sun.star.presentation.ClickAction.MACRO
shape.Bookmark = "Hello.Module1.Standard"

End Sub

Function Hello()
msgbox "Hello"
End Function


Christian
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
Markus B.
General User
General User


Joined: 08 Mar 2004
Posts: 7
Location: Münster Germany

PostPosted: Fri Apr 29, 2005 12:08 pm    Post subject: Reply with quote

Thank you Christian for the example but it works only in impress and I need a solution which works with a writer document.
meanwhile i have found a kludge to solve my problem

Code:


Sub SetupMouseClickHandler
oDoc =  StarDesktop.CurrentComponent
oController = oDoc.currentController
MouseClickHandler = CreateUnoListener("MouseClickHandler_","com.sun.star.awt.XMouseClickHandler")
oController.addMouseClickHandler(MouseClickHandler)
End Sub


Sub Main
 SetupMouseClickHandler()
End Sub

Sub MouseClickHandler_MousePressed(Event As Object)
 SetupMouseClickHandler()
End Sub

Sub MouseClickHandler_mouseReleased(Event As Object)
osel = ThisComponent.getCurrentController().getSelection()
if osel.supportsService( "com.sun.star.text.TextGraphicObject" ) Then
 rem do something with the graphic in osel ....
End if
 SetupMouseClickHandler()
End Sub

Sub MouseClickHandler_disposing(Event As Object)
  SetupMouseClickHandler()
End Sub


although I' am still interested in a better solution.

Thanks a lot!
Markus B.
Back to top
View user's profile Send private message
darkspheremy
Newbie
Newbie


Joined: 13 Dec 2010
Posts: 3

PostPosted: Sat Feb 19, 2011 9:56 am    Post subject: Reply with quote

hi guys, i'm using C# to develop an add in to openoffice writer..

can you help me how to use Markus' code in C#?

Code:
Sub SetupMouseClickHandler
oDoc =  StarDesktop.CurrentComponent
oController = oDoc.currentController
MouseClickHandler = CreateUnoListener("MouseClickHandler_","com.sun.star.awt.XMouseClickHandler")
oController.addMouseClickHandler(MouseClickHandler)
End Sub
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group