Form control and text cursor

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
thorn
Posts: 5
Joined: Mon Sep 05, 2016 3:46 pm

Form control and text cursor

Post by thorn »

I am coding a combobox with a few entries. The form control is added programmatically. So, I provided a event-listener routine which gets executed on selection change. The problem is that I would like to manage the text cursor within this routine but it seems not possible. In fact, the cursor keeps staying inside the combobox even after select(cellAddress) has been called at the end. Actually, the cell of cellAddress gets activated but if i try to type anything the combobox is written and not the cell.
I tried to workaround this issue in several ways by using a different strategy other than text cursor management but the fact that the text cursor sticks to the combobox seems to be restrictive. Has someone any ideas on how to cope with it?
OpenOffice 3.1 on Windows Vista
User avatar
Zizi64
Volunteer
Posts: 11360
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Form control and text cursor

Post by Zizi64 »

Please upload here your example ODF file and the embedded macro code.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
thorn
Posts: 5
Joined: Mon Sep 05, 2016 3:46 pm

Re: Form control and text cursor

Post by thorn »

Here it is (see comment under "sub onOnceForAllSelect")

Code: Select all

sScriptURL = "vnd.sun.star.script:Standard.Module1.onOnceForAllSelect?language=Basic&location=document"
controlId = GetControlIdx (onceCombo, formObj)
AssignAction(controlId, sScriptURL , formObj, "itemStateChanged", "XItemListener")

' assign sScriptURL event as css.awt.XActionListener::actionPerformed.
' event is assigned to the control described by the nIndex in the oForm container
Sub AssignAction(nIndex As Integer, sScriptURL As String, oForm As Object, sMethod as string, sListener as string)
	aEvent = CreateUnoStruct("com.sun.star.script.ScriptEventDescriptor")
	With aEvent
	.AddListenerParam = ""
	.EventMethod = sMethod '"actionPerformed"
	.ListenerType = sListener    '"XActionListener"
	.ScriptCode = sScriptURL
	.ScriptType = "Script"
	End With

	oForm.registerScriptEvent(nIndex, aEvent)
End Sub


sub onOnceForAllSelect( oClickEvent as com.sun.star.awt.ActionEvent )
	'----> BOTH FOLLOWING ATTEMPTS DON'T MOVE THE TEXT CURSOR OUT OF
	'----> THIS COMBO BOX DINAMICALLY CREATED AS ABOVE
	thisCell = thisComponent.getSheets().getByIndex(2).getCellByPosition(0,0)
	ThisComponent.CurrentController.select(thisCell)

	oDoc = ThisComponent.CurrentController.Frame
	dim args(1) as new com.sun.star.beans.PropertyValue
	args(0).Name = "ToPoint"
	args(0).Value = thisCell.CellAddress
	dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	dispatcher.executeDispatch(oDoc, ".uno:GoToCell", "", 0, args())
end sub
OpenOffice 3.1 on Windows Vista
User avatar
Zizi64
Volunteer
Posts: 11360
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Form control and text cursor

Post by Zizi64 »

'----> BOTH FOLLOWING ATTEMPTS DON'T MOVE THE TEXT CURSOR OUT OF
'----> THIS COMBO BOX DINAMICALLY CREATED AS ABOVE
Please upload a full example together with the ODF file.

Actually, the cell of cellAddress gets activated but if i try to type anything the Combobox is written and not the cell.
Why you want to place the cursor into a cell while the control is on the combobox? Do you want to assign different cells (more than one cells) to the selection result of the Combobox?
You can modify the content of a cell by your macro without placing cursor into the cell.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
thorn
Posts: 5
Joined: Mon Sep 05, 2016 3:46 pm

Re: Form control and text cursor

Post by thorn »

The sample code I provided says it all about my issue. Maybe it just lacks the answer to your last question: I am trying to copy (partially) formatted text (i.e. cell strings with some bold chars) from an external spreadsheet to the one containing the combobox in context. I guess I have only 2 options to do this:
- dispatching copy-and-paste commands
- using quite complicated text-cursor jobs
Both of these ways don't seem to be allowed if the text cursor is stuck inside the combobox and there is no way to take it outside following a selection from the same combobox.
OpenOffice 3.1 on Windows Vista
User avatar
Zizi64
Volunteer
Posts: 11360
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Form control and text cursor

Post by Zizi64 »

Tips:

- Use local Cell styles instead of the copying the format properties.
- You can copy the cell contents without using the Clipboard and the Dispatcher (by API functions)
Just a short example:

Code: Select all

Sub CopyData(MySourceName as string, MyTargetName as string) 


Dim oSourceRange as object
Dim oTargetRange as object

	oSourceRange = ThisComponent.NamedRanges.getByName(MySourceName)
	oTargetRange = ThisComponent.NamedRanges.getByName(MyTargetName)

	oTargetRange.getReferredCells().setDataArray(oSourceRange.getReferredCells().getDataArray())

End sub
'____________________________________________________________________________________
This sub can copy the data (only the date) from a named range to an another named range (in same document). But you can handle two different documents (source document and target document), and the absolut name of the sheets and cellranges too by a modified macro)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
thorn
Posts: 5
Joined: Mon Sep 05, 2016 3:46 pm

Re: Form control and text cursor

Post by thorn »

- Use local Cell Styles instead of the copying the format properties.
- You can copy the cell contents without using the Clipboard and the Dispatcher (by API functions)
DataArray doesn't copy styles.
So, I might apply "local Cell Styles". However, my problem is about replicating bold characters within a longer cell string. I guess (I really don't know for sure) that Cell Styles concern a cell string as a whole and don't allow to format single characters within it.
OpenOffice 3.1 on Windows Vista
User avatar
Zizi64
Volunteer
Posts: 11360
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Form control and text cursor

Post by Zizi64 »

However, my problem is about replicating bold characters within a longer cell string. I guess (I really don't know for sure) that Cell Styles concern a cell string as a whole and don't allow to format single characters within it.
It is not a good idea to use different character format properties inside a cell...
You can try to use (if it appropriate for you) real UNICODE sub- and supersript characters for the indexes; capital letters or special UNICODE characters for empasize a part of the cell content.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Form control and text cursor

Post by Villeroy »

Copy formatted cell contents? Has nothing to do with form controls.
viewtopic.php?f=45&t=82224&p=380557#p380552
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
thorn
Posts: 5
Joined: Mon Sep 05, 2016 3:46 pm

Re: Form control and text cursor

Post by thorn »

Villeroy,
your code use "cell.createTextCursor()" which doesn't seem to be useful if the text cursor is inside the combobox textbox.
Any way to "setFocus" on a spreadsheet cell from the code running inside a control?
I tried comboBox.commit = true and I also see forms have a setFocus method but it doesn't seem to help to focus on a spreadsheet cell.
OpenOffice 3.1 on Windows Vista
User avatar
Zizi64
Volunteer
Posts: 11360
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Form control and text cursor

Post by Zizi64 »

I do not understand, why you want to control the cells, in same time when you type-in something into the combobox...


Try to use a Form with a Combobox AND a Button, and assign the macro to the button event.

And please, please upload your example ODS file/s/ here...
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply