[Solved] Append in input mode, leave in input mode

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
belchergb
Posts: 37
Joined: Sun Mar 24, 2013 4:08 am

[Solved] Append in input mode, leave in input mode

Post by belchergb »

I am editting a cell (it is in input mode). I want a macro (mapped to a key combination) that will:

1> retrieve the characters so far entered
2> append a fixed string to them
3> exit leaving the cell in input mode

Then I will finish typing in the cell and press enter. The cell would now have what I typed with the appended string effectively inserted at the point where I pressed the mapped key(s).

I have been unable to find a way to accomplish 1> while in input mode. I imagine I will need to find the data in the controller, but have not been able to so far. I suspect there may be some other trickery required, as well.

I also have been unable to find how to switch a cell in or out of input mode short of using DispatchHelper (ugh!).

Any ideas? Thanks.
Last edited by belchergb on Thu Jan 29, 2015 4:35 am, edited 1 time in total.
LibreOffice 3.5.7.2 Ubuntu 12.04
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Append in input mode, leave in input mode

Post by B Marcelly »

Paste from clipboard works well in input mode.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Append in input mode, leave in input mode

Post by hanya »

Code: Select all

Sub AppendSuffixOnCellInputMode
  oSelection = ThisComponent.getCurrentSelection()
  if oSelection.supportsService("com.sun.star.sheet.SheetCell") then
    oFound = GetCellAccessibleEditableParagraph()
    If not IsNull(oFound) Then
      oFound.insertText("_suffix", oFound.getCharacterCount())
    End If
  end if
End Sub

Function GetCellAccessibleEditableParagraph() As Variant
  oResult = Null
  oAccCtx = ThisComponent.getCurrentController().getFrame().getComponentWindow().getAccessibleContext()
  oDocumentPanelAcc = FindChildByRole(oAccCtx, com.sun.star.accessibility.AccessibleRole.SCROLL_PANE)
  If not IsNull(oDocumentPanelAcc) Then
    oDocumentAcc = FindChildByRole(oDocumentPanelAcc.getAccessibleContext(), com.sun.star.accessibility.AccessibleRole.DOCUMENT)
    If IsNull(oDocumentAcc) Then oDocumentAcc = FindChildByRole(oDocumentPanelAcc.getAccessibleContext(), com.sun.star.accessibility.AccessibleRole.DOCUMENT_SPREADSHEET)
    For i = 0 to oDocumentAcc.getAccessibleChildCount() -1 step 1
      oAccChild = oDocumentAcc.getAccessibleChild(i)
      If oAccChild.getAccessibleRole() = com.sun.star.accessibility.AccessibleRole.TEXT_FRAME Then
        if oAccChild.getAccessibleChildCount() = 1 then
          oAccPara = oAccChild.getAccessibleChild(0)
          if oAccPara.getAccessibleRole() = com.sun.star.accessibility.AccessibleRole.PARAGRAPH Then
            oResult = oAccPara
            exit for
          End If
        end if
      End If
    next
  End If
  GetCellAccessibleEditableParagraph = oResult
End Function

Function FindChildByRole(oCtx As Variant, nRole As Integer) As Variant
  oFound = NULL
  For i = 0 to oCtx.getAccessibleChildCount() - 1 step 1
    oChild = oCtx.getAccessibleChild(i)
    oChildCtx = oChild.getAccessibleContext()
    If oChildCtx.getAccessibleRole() = nRole then
      oFound = oChild
      exit for
    End If
  next
  FindChildByRole = oFound
End Function
I do not know the way for >3, exit from input mode.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
belchergb
Posts: 37
Joined: Sun Mar 24, 2013 4:08 am

Re: Append in input mode, leave in input mode

Post by belchergb »

My gawd! If that is what it takes to do what I want, it is no wonder I could not figure out how. I am going to have to study this just to see what it does.

It needs one thing more, if it can be done.

If I type "ASDF^" in the cell, where the carat, ^, represents the cursor or text entry point, then press my mapped key calling the macro, then "_suffix" is appended at the cursor point, giving "ASDF^_suffix", and it is still in input mode. Fabulous!

The problem is that when I continue typing, "MORE" for example, the characters go in at the cursor point, like "ASDFMORE^_suffix". The result I want is "ASDF_suffixMORE". I want the cursor moved to the end of the appended "_suffix" when the macro exits.

Is that possible?
LibreOffice 3.5.7.2 Ubuntu 12.04
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Append in input mode, leave in input mode

Post by hanya »

belchergb wrote:The problem is that when I continue typing, "MORE" for example, the characters go in at the cursor point, like "ASDFMORE^_suffix". The result I want is "ASDF_suffixMORE". I want the cursor moved to the end of the appended "_suffix" when the macro exits.
Add the following after the insertText call:

Code: Select all

oFound.setCaretPosition(oFound.getCharacterCount())
Useful interfaces on this object are:
http://www.openoffice.org/api/docs/comm ... eText.html
http://www.openoffice.org/api/docs/comm ... eText.html
Please Inspect the object for additional interfaces.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
belchergb
Posts: 37
Joined: Sun Mar 24, 2013 4:08 am

Re: [Solved] Append in input mode, leave in input mode

Post by belchergb »

Thank you, thank you! It is perfect.
LibreOffice 3.5.7.2 Ubuntu 12.04
Post Reply