| View previous topic :: View next topic |
| Author |
Message |
Vanished General User

Joined: 21 Jan 2005 Posts: 9
|
Posted: Fri Jan 21, 2005 5:49 am Post subject: How to use enter-key instead of tab-key in a dialog |
|
|
Please apologize my bad english, but it is already a long time ago, that i went to school, however, I hope you'll understand my problem.
I have a dialog with several controls (textfields, comboboxes and buttons). When the dialog is in use, normaly the tab-key is used to jump from one control to the next. Now my need is to jump with the enter-key. Everything I tried missed. It seems to me that the enter-key is not recognized as long as the dialog is active (except a commandbutton is focused).
I tried to achieve my aim by registering a keylistener but I can't get it work. (Hmmm, to be true: I am not very familiar with such things...)
Greetings,
Vanished |
|
| Back to top |
|
 |
Iannz OOo Advocate

Joined: 14 Feb 2004 Posts: 494 Location: Christchurch, New Zealand
|
Posted: Mon Jan 24, 2005 2:10 pm Post subject: Re: How to use enter-key instead of tab-key in a dialog |
|
|
| Vanished wrote: | | I tried to achieve my aim by registering a keylistener but I can't get it work. (Hmmm, to be true: I am not very familiar with such things...) |
Post here the relevant code and I or someone else may be able to help you. _________________ Cheers, Ian
http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions. |
|
| Back to top |
|
 |
Vanished General User

Joined: 21 Jan 2005 Posts: 9
|
Posted: Tue Jan 25, 2005 12:31 am Post subject: |
|
|
Thanks for your answer. For now the only code I have is based on the example for a keyhandler in chapter 11.2.6 of Andrew Pitonyaks "Useful macro information for open office". I changed it to a keylistener but still have some problems.
Here is the code, asteriksed (*) lines cause problems:
'-lines show what I want to do
| Code: | Sub RegisterKeyListener
*(1) oListenerObject = oDialog.getControl("tfef") *
'wanted: something like:
'for i=1 to 25
'oDialog.getControl.getByIndex(i)
oKeyListener = createUnoListener("oKey_", "com.sun.star.awt.XKeyListener")
oListenerObject.addKeyListener(oKeyListener)
'next i
End Sub
Sub UnregisterKeyListener
oListenerObject.removeKeyListener(oKeyListener)
End Sub
Function oKey_KeyPressed(oEvt) As Boolean
select case oEvt.KeyChar
case chr(13)
oKey_KeyPressed = True
*(2) oDialog.getControl("CommandButton1").setFocus() *
'wanted something like: oDialog.getControl(currentTabIndex+1).setFocus()
case else
oKey_KeyPressed = False
end select
End Function
Function oKey_KeyReleased(oEvt) As Boolean
oKey_KeyReleased = False
End Function |
*(1) I have a dialog with nearly 30 controls. The listener should be registered to the first 25 controls in the order of the tabindex. I know how to register to one control (as shown above) but how can I register it to all controls by index? (I am searching for this for days...)
*(2) I know, how to get access to a control by its name. But to solve my problem I have to access the control by its index because by hitting the returnkey (chr(13)) I want to focus the control with the next higher tabindex. So how can I receive the number of the current active control and how can I access the control "current TabIndex"+1 to set the focus?
I think there are enough questions, aren't they?
Greetings
Vanished |
|
| Back to top |
|
 |
Iannz OOo Advocate

Joined: 14 Feb 2004 Posts: 494 Location: Christchurch, New Zealand
|
Posted: Tue Jan 25, 2005 2:31 pm Post subject: |
|
|
I don't have a lot of time right now but here is a quick idea to help.
mControls = oDialog.Controls
for i = 0 to Ubound(mControls)
xray.xray mControls(i)
next _________________ Cheers, Ian
http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions. |
|
| Back to top |
|
 |
Vanished General User

Joined: 21 Jan 2005 Posts: 9
|
Posted: Tue Jan 25, 2005 11:44 pm Post subject: |
|
|
Hmmm, is it right you are speaking about a lib delivered with the xray-tool? Unfortunately my employer has not installed this piece of software. In addition to that I don't have the necessary rights to install it myself.
All the same. I found a solution for my first problem (the one called *(1) before) with this code:
| Code: | Sub RegisterKeyListener
for i=1 to 25
oListenerObject = oDialog.AccessibleContext.getAccessibleChild(i)
oKeyListener = createUnoListener("oKey_", "com.sun.star.awt.XKeyListener")
oListenerObject.addKeyListener(oKeyListener)
next i
End Sub |
So now it would be greate if we could focus on the second problem. Again: How can I receive the indexnumber of the current active control and how can I access the control "current TabIndex"+1 to set the focus?
Thanks for your patience
Vanished |
|
| Back to top |
|
 |
Iannz OOo Advocate

Joined: 14 Feb 2004 Posts: 494 Location: Christchurch, New Zealand
|
Posted: Wed Jan 26, 2005 12:33 am Post subject: |
|
|
| Vanished wrote: | | Hmmm, is it right you are speaking about a lib delivered with the xray-tool? Unfortunately my employer has not installed this piece of software. In addition to that I don't have the necessary rights to install it myself. |
Xray is OOo basic macro available from http://ooomacros.org/dev.php#101416 Installation instructions are included. In my view programming in OOo without this almost imposible!
| Vanished wrote: |
So now it would be greate if we could focus on the second problem. Again: How can I receive the indexnumber of the current active control and how can I access the control "current TabIndex"+1 to set the focus? |
| Code: | mControls=oDialog.tabControllers(0).controls
|
This code creates an array of controls in tab order.
You will need to check if the next control is enabled and is indeed a tabStop control. These properties are available from the model.
| Code: | oControlModel = mControls(i).model
while not (oControlModel.enabled and oControlModel.tabStop)
i = i +1
if i > uBound(mControls) then i = 0
wend
|
I confess I haven't checked this code as I don't have the time but I think the idea is right. Hope this helps. _________________ Cheers, Ian
http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions. |
|
| Back to top |
|
 |
Vanished General User

Joined: 21 Jan 2005 Posts: 9
|
Posted: Thu Jan 27, 2005 2:32 am Post subject: |
|
|
| Iannz wrote: | | Xray is OOo basic macro available from http://ooomacros.org/dev.php#101416 Installation instructions are included. In my view programming in OOo without this almost imposible! |
Thanks, I'll take this as a compliment. I think you didn't catch my problem. At work I am not allowed - and even don't have the used proxyrights - to download any kind of file.
| Iannz wrote: |
You will need to check if the next control is enabled and is indeed a tabStop control. These properties are available from the model. |
I couldn't get this to work. I was able to set controls with this method enabled or disabled but I wasn't able to query this property. Therfore I decided to use the "isEditable"-property.
| Iannz wrote: | | I confess I haven't checked this code as I don't have the time but I think the idea is right. Hope this helps. |
At least i hadn't solved my problem without. For all having a similiar problem like mine here is the full code. Perhaps (probably) someone will find a better way to solve this. Improvement suggestions are very welcome.
| Code: | Sub RegisterKeyListener
'get the dialog's controls in an array
mControls=oDialog.tabControllers(0).controls
for i=1 to 25
'define the listener
oKeyListener = createUnoListener("oKey_", "com.sun.star.awt.XKeyListener")
'add the listener to controls
mControls(i).addKeyListener(oKeyListener)
next i
End Sub
Sub UnregisterKeyListener
'get the dialog's controls in an array
mControls=oDialog.tabControllers(0).controls
for i=1 to 25
'remove the listener from controls
mControls(i).removeKeyListener(oKeyListener)
next i
End Sub
Function oKey_KeyPressed(oEvt) As Boolean
select case oEvt.KeyChar
case chr(13)
oKey_KeyPressed = True
Dim actControl as Integer
'get tabindex from actual control (the control that raised the keypressed = true)
actControl = oEvt.Source.getModel().TabIndex
if actControl < 25 Then
'Search for the next control which isn't not editable
Do while oDialog.AccessibleContext.getAccessibleChild(actControl+1).isEditable = "False"
actcontrol = actControl + 1
if actControl > 25 then actControl = 0
Loop
End If
oDialog.AccessibleContext.getAccessibleChild(actControl+1).setFocus()
case else
oKey_KeyPressed = False
end select
End Function
Function oKey_KeyReleased(oEvt) As Boolean
oKey_KeyReleased = False
End Function
Sub oKey_disposing(oEvt)
'Sub has to be written even when without function!
End Sub |
Especially thanks half around the world to Iannz for his help!
Greetings
Vanished |
|
| Back to top |
|
 |
|