Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OK. I've limited experience with this but have some info for you. First is the code from Pitonyak. This gets you the methods you need to code. Copy this code:

   Sub InspectListenerMethods
      Dim sPrefix$
      Dim sService$
      Dim vService
      sPrefix = "sel_change_"
  ' sService = "com.sun.star.view.XSelectionChangeListener"
  ' sService = "com.sun.star.lang.XEventListener"
  ' sService = "com.sun.star.awt.XMenuListener"
   sService = "com.sun.star.awt.XKeyHandler"
  ' sService = "com.sun.star.awt.XButton"
   vService = CreateUnoListener(sPrefix, sService)
   DisplayDbgInfoStr(vService.dbg_methods, ";", 35, "Methods")
  End Sub
Sub DisplayDbgInfoStr(sInfo$, sSep$, nChunks, sHeading$)
Dim aInfo()
 'Array to hold each string
Dim i As Integer
 'Index variable
Dim j As Integer
'Junk integer variable for temporary values
Dim s As String
'holds the portion that is not completed
s = sInfo$
j = InStr(s, ":")
'Initial colon
If j > 0 Then Mid(s, 1, j, "") 'Remove portion up to the initial colon
    Do
        aInfo() = Split(s, sSep$, nChunks)
'Split string based on delimiter.
        s = aInfo(UBound(aInfo()))
 'Grab the last piece. Contains
        If InStr(s, sSep$) < 1 Then
 'the rest if there were too many.
            s = ""
 'If there were not, then clear s.
        Else
'If there was a delimiter then
            ReDim Preserve aInfo(nChunks - 2)
'change array dimension to
        End If
'remove the extra last piece.
        For i = LBound(aInfo()) To UBound(aInfo())'Look at each piece to remove
            aInfo(i) = Trim(aInfo(i))
'leading and trailing spaces.
            j = InStr(aInfo(i), CHR$(10))
'Some have an extra
            If j > 0 Then Mid(aInfo(i), j, 1, "") 'new line that should be removed.
        Next
        MsgBox Join(aInfo(), CHR$(10)), 0, sHeading$
    Loop Until Len(s) = 0
  End Sub

Running the macro InspectListenerMethods will display the methods you need to incorporate into your code. sService is the the only thing you need to modify. It is currently set for XKeyHandler with others commented out. Easier for later examination. So if you run this three items need definition even if they don't do anything (queryInterface can be ignored)- disposing, keyPressed and keyReleased. Knowing that, here is my key handler(working model):

   global oXKeyHandler as object
   sub sStartXKeyHandler
       if isNull(oXKeyHandler) then 'only if not jet running
           oXKeyHandler = CreateUnoListener("KeyHandler_", "com.sun.star.awt.XKeyHandler")
           ThisComponent.CurrentController.AddKeyHandler(oXKeyHandler)
       endif
   end sub

sub sStopXKeyHandler
    if not IsNull(oXKeyHandler) then 'only if still running
        ThisComponent.CurrentController.removeKeyHandler(oXKeyHandler)
        oXKeyHandler = Nothing 'To know later this handler has stopped.
    end if
end sub

sub XKeyHandler_Disposing(oEvent)
end sub

function KeyHandler_KeyPressed(oEvent) as boolean
 'The entire objective of the key handler:
 'On the menu, when the 'Enter' key is pressed
 'don't move to the next field(cancel)
    If (oEvent.KeyCode = 1280) Or (oEvent.KeyCode = 1284) Then
        KeyHandler_KeyPressed = True 'cancel KeyPressed
    Else
        KeyHandler_KeyPressed = False 'cancel KeyPressed
    End If
End function

function KeyHandler_KeyReleased(oEvent) as boolean
 'but when the 'Enter' key is released,
 'execute the 'Key Released' event assigned in the control
    If oEvent.KeyCode = 1280 Then
        KeyHandler_KeyReleased = False 'cancel KeyReleased
    Else
        KeyHandler_KeyReleased = True 'cancel KeyReleased
    End If
end function

This was used in a menuing form in which I wanted the normal function of the Enter key to be overridden (next field & select it).

As you can see, XButton is one of the service selections. Start there and try Pitonayaks' book again. This isn't the easiest of sections.

OK. I've limited experience with this but have some info for you. First is the code from Pitonyak. This gets you the methods you need to code. Copy this code:

   Sub InspectListenerMethods
      Dim sPrefix$
      Dim sService$
      Dim vService
      sPrefix = "sel_change_"
  ' sService = "com.sun.star.view.XSelectionChangeListener"
  ' sService = "com.sun.star.lang.XEventListener"
  ' sService = "com.sun.star.awt.XMenuListener"
   sService = "com.sun.star.awt.XKeyHandler"
  ' sService = "com.sun.star.awt.XButton"
   vService = CreateUnoListener(sPrefix, sService)
   DisplayDbgInfoStr(vService.dbg_methods, ";", 35, "Methods")
  End Sub
Sub DisplayDbgInfoStr(sInfo$, sSep$, nChunks, sHeading$)
Dim aInfo()
 'Array to hold each string
Dim i As Integer
 'Index variable
Dim j As Integer
'Junk integer variable for temporary values
Dim s As String
'holds the portion that is not completed
s = sInfo$
j = InStr(s, ":")
'Initial colon
If j > 0 Then Mid(s, 1, j, "") 'Remove portion up to the initial colon
    Do
        aInfo() = Split(s, sSep$, nChunks)
'Split string based on delimiter.
        s = aInfo(UBound(aInfo()))
 'Grab the last piece. Contains
        If InStr(s, sSep$) < 1 Then
 'the rest if there were too many.
            s = ""
 'If there were not, then clear s.
        Else
'If there was a delimiter then
            ReDim Preserve aInfo(nChunks - 2)
'change array dimension to
        End If
'remove the extra last piece.
        For i = LBound(aInfo()) To UBound(aInfo())'Look at each piece to remove
            aInfo(i) = Trim(aInfo(i))
'leading and trailing spaces.
            j = InStr(aInfo(i), CHR$(10))
'Some have an extra
            If j > 0 Then Mid(aInfo(i), j, 1, "") 'new line that should be removed.
        Next
        MsgBox Join(aInfo(), CHR$(10)), 0, sHeading$
    Loop Until Len(s) = 0
  End Sub

Running the macro InspectListenerMethods will display the methods you need to incorporate into your code. sService is the the only thing you need to modify. It is currently set for XKeyHandler with others commented out. Easier for later examination. So if you run this three items need definition even if they don't do anything (queryInterface can be ignored)- disposing, keyPressed and keyReleased. Knowing that, here is my key handler(working model):

   global oXKeyHandler as object
   sub sStartXKeyHandler
       if isNull(oXKeyHandler) then 'only if not jet running
           oXKeyHandler = CreateUnoListener("KeyHandler_", "com.sun.star.awt.XKeyHandler")
           ThisComponent.CurrentController.AddKeyHandler(oXKeyHandler)
       endif
   end sub

sub sStopXKeyHandler
    if not IsNull(oXKeyHandler) then 'only if still running
        ThisComponent.CurrentController.removeKeyHandler(oXKeyHandler)
        oXKeyHandler = Nothing 'To know later this handler has stopped.
    end if
end sub

sub XKeyHandler_Disposing(oEvent)
end sub

function KeyHandler_KeyPressed(oEvent) as boolean
 'The entire objective of the key handler:
 'On the menu, when the 'Enter' key is pressed
 'don't move to the next field(cancel)
    If (oEvent.KeyCode = 1280) Or (oEvent.KeyCode = 1284) Then
        KeyHandler_KeyPressed = True 'cancel KeyPressed
    Else
        KeyHandler_KeyPressed = False 'cancel KeyPressed
    End If
End function

function KeyHandler_KeyReleased(oEvent) as boolean
 'but when the 'Enter' key is released,
 'execute the 'Key Released' event assigned in the control
    If oEvent.KeyCode = 1280 Then
        KeyHandler_KeyReleased = False 'cancel KeyReleased
    Else
        KeyHandler_KeyReleased = True 'cancel KeyReleased
    End If
end function

This was used in a menuing form in which I wanted the normal function of the Enter key to be overridden (next field & select it).

As you can see, XButton is one of the service selections. Start there and try Pitonayaks' book again. This isn't the easiest of sections.

ADDITIONAL INFO!!

Not sure why you are taking this approach. I should have realized this earlier. I've eluded to this in one of our previous posts but let you lead me astray with your mention of listeners & such. If your looking to see which button is doind the calling you can just set a variable. I've attached a (dumb) sample but it does display what I mean. The button pushed will only record the answer once and a different button pushed will add to the answer.Test Button.odt

OK. I've limited experience with this but have some info for you. First is the code from Pitonyak. This gets you the methods you need to code. Copy this code:

   Sub InspectListenerMethods
      Dim sPrefix$
      Dim sService$
      Dim vService
      sPrefix = "sel_change_"
  ' sService = "com.sun.star.view.XSelectionChangeListener"
  ' sService = "com.sun.star.lang.XEventListener"
  ' sService = "com.sun.star.awt.XMenuListener"
   sService = "com.sun.star.awt.XKeyHandler"
  ' sService = "com.sun.star.awt.XButton"
   vService = CreateUnoListener(sPrefix, sService)
   DisplayDbgInfoStr(vService.dbg_methods, ";", 35, "Methods")
  End Sub
Sub DisplayDbgInfoStr(sInfo$, sSep$, nChunks, sHeading$)
Dim aInfo()
 'Array to hold each string
Dim i As Integer
 'Index variable
Dim j As Integer
'Junk integer variable for temporary values
Dim s As String
'holds the portion that is not completed
s = sInfo$
j = InStr(s, ":")
'Initial colon
If j > 0 Then Mid(s, 1, j, "") 'Remove portion up to the initial colon
    Do
        aInfo() = Split(s, sSep$, nChunks)
'Split string based on delimiter.
        s = aInfo(UBound(aInfo()))
 'Grab the last piece. Contains
        If InStr(s, sSep$) < 1 Then
 'the rest if there were too many.
            s = ""
 'If there were not, then clear s.
        Else
'If there was a delimiter then
            ReDim Preserve aInfo(nChunks - 2)
'change array dimension to
        End If
'remove the extra last piece.
        For i = LBound(aInfo()) To UBound(aInfo())'Look at each piece to remove
            aInfo(i) = Trim(aInfo(i))
'leading and trailing spaces.
            j = InStr(aInfo(i), CHR$(10))
'Some have an extra
            If j > 0 Then Mid(aInfo(i), j, 1, "") 'new line that should be removed.
        Next
        MsgBox Join(aInfo(), CHR$(10)), 0, sHeading$
    Loop Until Len(s) = 0
  End Sub

Running the macro InspectListenerMethods will display the methods you need to incorporate into your code. sService is the the only thing you need to modify. It is currently set for XKeyHandler with others commented out. Easier for later examination. So if you run this three items need definition even if they don't do anything (queryInterface can be ignored)- disposing, keyPressed and keyReleased. Knowing that, here is my key handler(working model):

   global oXKeyHandler as object
   sub sStartXKeyHandler
       if isNull(oXKeyHandler) then 'only if not jet running
           oXKeyHandler = CreateUnoListener("KeyHandler_", "com.sun.star.awt.XKeyHandler")
           ThisComponent.CurrentController.AddKeyHandler(oXKeyHandler)
       endif
   end sub

sub sStopXKeyHandler
    if not IsNull(oXKeyHandler) then 'only if still running
        ThisComponent.CurrentController.removeKeyHandler(oXKeyHandler)
        oXKeyHandler = Nothing 'To know later this handler has stopped.
    end if
end sub

sub XKeyHandler_Disposing(oEvent)
end sub

function KeyHandler_KeyPressed(oEvent) as boolean
 'The entire objective of the key handler:
 'On the menu, when the 'Enter' key is pressed
 'don't move to the next field(cancel)
    If (oEvent.KeyCode = 1280) Or (oEvent.KeyCode = 1284) Then
        KeyHandler_KeyPressed = True 'cancel KeyPressed
    Else
        KeyHandler_KeyPressed = False 'cancel KeyPressed
    End If
End function

function KeyHandler_KeyReleased(oEvent) as boolean
 'but when the 'Enter' key is released,
 'execute the 'Key Released' event assigned in the control
    If oEvent.KeyCode = 1280 Then
        KeyHandler_KeyReleased = False 'cancel KeyReleased
    Else
        KeyHandler_KeyReleased = True 'cancel KeyReleased
    End If
end function

This was used in a menuing form in which I wanted the normal function of the Enter key to be overridden (next field & select it).

As you can see, XButton is one of the service selections. Start there and try Pitonayaks' book again. This isn't the easiest of sections.

ADDITIONAL INFO!!

Not sure why you are taking this approach. I should have realized this earlier. I've eluded to this in one of our previous posts but let you lead me astray (my fault not yours) with your mention of listeners & such. If your looking to see which button is doind doing the calling you can just set a variable. I've attached a (dumb) sample but it does display what I mean. The button pushed will only record the answer once and a different button pushed will add to the answer.Test Button.odtanswer. PBTest.odb