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 remove focus from a control?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
MooSHEL
Newbie
Newbie


Joined: 15 Jan 2005
Posts: 3

PostPosted: Tue Jan 25, 2005 6:11 pm    Post subject: How to remove focus from a control? Reply with quote

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
View user's profile Send private message
H'twOr
Newbie
Newbie


Joined: 16 Mar 2005
Posts: 1
Location: Ukraine

PostPosted: Wed Mar 16, 2005 1:12 am    Post subject: Reply with quote

I'm having same problem and not solved it yet.
Back to top
View user's profile Send private message
Peter
OOo Enthusiast
OOo Enthusiast


Joined: 28 May 2004
Posts: 105
Location: Berlin / Germany

PostPosted: Wed Mar 16, 2005 11:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
nova
General User
General User


Joined: 26 Mar 2006
Posts: 46

PostPosted: Sat Apr 22, 2006 5:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
nova
General User
General User


Joined: 26 Mar 2006
Posts: 46

PostPosted: Sun Apr 23, 2006 10:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
nova
General User
General User


Joined: 26 Mar 2006
Posts: 46

PostPosted: Sat May 06, 2006 12:50 pm    Post subject: Frozen Panes and setFocus for control (Window -> Freeze) Reply with quote

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
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