| View previous topic :: View next topic |
| Author |
Message |
MooSHEL Newbie

Joined: 15 Jan 2005 Posts: 3
|
Posted: Tue Jan 25, 2005 6:11 pm Post subject: How to remove focus from a control? |
|
|
Hi All,
How do I remove focus from the control?
I build a sheet that tries to workaround the lack of Excel data validation function. On my spreadsheet I have a listbox control that, whith the usage of XSelectionChangeListener moves the listbox to currently active (edited) cell. The listbox entries are the ones that are allowed for input in this cell. So basicly, the user moves around the sheet with arrow keys and the listbox moves too. If a user wants the edit the cell the focus has to be set to the control, a choice is being done, and the listbox, responding to its "changed" event, set's the cell value to a chosen item. Up to that point it works fine.
But when the editing is done, the focus from the control has to be removed, and placed back to the active cell (the one under the listbox), in order for the user to be able to move the cell selection with the usage of arrow keys around the sheet. If the focus is not removed from the listbox, pressing the down/up keys select items from the listbox, rather than moving the cell selection down/up.
I already tried the dispatcher's "GoToCell" command, and it moves the active cell to wherever I want but it keeps the listbox stil focused
How do I achieve it?
Thanks,
MooSHEL
I set the focus to my listbox with the usage of the following code:
| Code: |
Function KeyPressListener_KeyPressed(oEvt) As Boolean
Select Case oEvt.KeyCode
Case 0 '`
FocusAListBox
KeyPressListener_KeyPressed = True
Case 1281 'Esc
' Here I should "unfocus" my ListBox and select a cell
KeyPressListener_KeyPressed = True
Case Else
KeyPressListener_KeyPressed = False
End Select
End Function
Function FocusAListBox As Boolean
Dim oCurrSel as object
oCurrSel = ThisComponent.GetCurrentSelection
Dim oDocView As Object
oDocView = ThisComponent.getCurrentController
Dim oCurrSheet As Object
oCurrSheet = oDocView.getActiveSheet
If Len(oCurrSheet.Name) = 2 And (oCurrSel.RangeAddress.StartColumn = 3 Or oCurrSel.RangeAddress.StartColumn = 4) And _
oCurrSel.RangeAddress.StartRow > 4 And oCurrSel.RangeAddress.EndRow < 85 Then
Dim sListBoxName As String
Select Case oCurrSel.RangeAddress.StartColumn
Case 3: sListBoxName = "ListBox1"
Case 4: sListBoxName = "ListBox2"
End Select
Dim oForm As Object
oForm = oCurrSheet.DrawPage.Forms.GetByIndex(0)
Dim oListBox As Object
oListBox = oForm.GetByName(sListBoxName)
Dim oListBoxView As Object
oListBoxView = oDocView.GetControl(oListBox)
oListBoxView.SetFocus
End If
End Function
|
|
|
| Back to top |
|
 |
H'twOr Newbie

Joined: 16 Mar 2005 Posts: 1 Location: Ukraine
|
Posted: Wed Mar 16, 2005 1:12 am Post subject: |
|
|
| I'm having same problem and not solved it yet. |
|
| Back to top |
|
 |
Peter OOo Enthusiast

Joined: 28 May 2004 Posts: 105 Location: Berlin / Germany
|
Posted: Wed Mar 16, 2005 11:17 pm Post subject: |
|
|
The same problem occurs in writer, when the user pushs a button triggering a macro that selects a XTextRange and the user wants to write straight after that.
Any hints?
Regards Peter |
|
| Back to top |
|
 |
nova General User


Joined: 26 Mar 2006 Posts: 46
|
Posted: Sat Apr 22, 2006 5:25 pm Post subject: |
|
|
I'm having same problem and not solved it yet.
Nice and useful code otherwise.
I've tested:
| Code: |
oListBoxView.setFocus()
|
TextBox gets focus, but losts cursor. So when typing I do not see cursor.
| Code: |
oListBoxView.setVisible(FALSE)
|
It does Not become invisible (nothing is changed).
| Code: |
oListBoxView.setText("aaaaa")
|
Text is writen to box, so the address is proper. |
|
| Back to top |
|
 |
nova General User


Joined: 26 Mar 2006 Posts: 46
|
Posted: Sun Apr 23, 2006 10:15 pm Post subject: |
|
|
| Quote: |
How do I remove focus from the control?
|
huh, SOLVED:
| Code: |
ThisComponent.CurrentController.Frame.ComponentWindow.setFocus
|
And this one works with frozen Panes too... | Code: |
ThisComponent.CurrentController.Frame.getContainerWindow.setFocus(TRUE)
|
Thanx to XrayTool + API doc
Not solved:
| Quote: | | TextBox gets focus, but losts cursor. So when typing I do not see cursor. |
| Code: |
oModel = ThisComponent.CurrentController.ActiveSheet.DrawPage.Forms(0).getByName("TextBox")
oControl = ThisComponent.CurrentController.getControl(oModel)
oControl.setFocus(TRUE)
|
It hapens only when table has Frozen panes (Window -> Freeze).
Last edited by nova on Fri Dec 08, 2006 2:19 am; edited 1 time in total |
|
| Back to top |
|
 |
nova General User


Joined: 26 Mar 2006 Posts: 46
|
Posted: Sat May 06, 2006 12:50 pm Post subject: Frozen Panes and setFocus for control (Window -> Freeze) |
|
|
Solved:
| Code: |
oControl = ThisComponent.CurrentController.getByIndex(0).getControl(oModel)
|
getByIndex after CurrentController calls proper “frozen pane”. There could be up to four of them (index 0 to 3). |
|
| Back to top |
|
 |
|