BASIC - Howto handle selected text in a textbox ?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

BASIC - Howto handle selected text in a textbox ?

Post by arfgh »

just that, how to handle the selected text into the textbox field. For example if we want to select the two first characters on the text.

thx in advance
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Apollo102
Posts: 8
Joined: Tue Mar 11, 2014 12:32 am

Re: BASIC - Howto handle selected text in a textbox ?

Post by Apollo102 »

Hi,

as a beginning :

Code: Select all

Sub TextBox()
	Dim oDoc As Object
	Dim oShapes As Object
	Dim oShape As Object
	Dim oTextBox As Object
	
	Dim oTextCursor As Object
   
	Dim s As Integer 'Shape-No
  
  	oDoc = ThisComponent	
  	oShapes = oDoc.DrawPage
   
	for s = 0 to oShapes.getCount() - 1
		oShape = oShapes.getByIndex(s)
				
			If (oShape.getShapeType() = "com.sun.star.drawing.TextShape") then
				oTextBox = oShape
	
				oTextCursor = oTextBox.Text.createTextCursor()
				
				oTextCursor.gotoStart(false)
				oTextCursor.goRight(2,true)
				
				MsgBox oTextCursor.getString()
				
				oTextCursor.setString("22")
								
				' oTextBox.setString("Hi")
				'  MsgBox oTextBox.getString()		
			End if
	Next s   
End Sub  

Apollo102
OpenOffice 4.2 MacOS
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: BASIC - Howto handle selected text in a textbox ?

Post by arfgh »

so isnt there the SelStart and SelLength procedures like in vb ?
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: BASIC - Howto handle selected text in a textbox ?

Post by FJCC »

OpenOffice has its own method's and you can't just use function names from MS Office.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Apollo102
Posts: 8
Joined: Tue Mar 11, 2014 12:32 am

Re: BASIC - Howto handle selected text in a textbox ?

Post by Apollo102 »

I don't know a way. You also could not go through the detour of a bookmark, because you can not paste it into a text shape.
OpenOffice 4.2 MacOS
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: BASIC - Howto handle selected text in a textbox ?

Post by RPG »

Hello

I think this interface is the best to use.
http://www.openoffice.org/api/docs/comm ... onent.html

The reason it can be used for a single line and a multiline texstbox. The interface is part of the view of the control and not of the model.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: BASIC - Howto handle selected text in a textbox ?

Post by arfgh »

yes, i want to use the text selection to handle a predictive text from a table. I did it with vb6 ages ago, but with specific functions for the text select...
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Apollo102
Posts: 8
Joined: Tue Mar 11, 2014 12:32 am

Re: BASIC - Howto handle selected text in a textbox ?

Post by Apollo102 »

RPG wrote:Hello

I think this interface is the best to use.
http://www.openoffice.org/api/docs/comm ... onent.html

The reason it can be used for a single line and a multiline texstbox. The interface is part of the view of the control and not of the model.

Romke
Do you have an example of this? I still do not understand how to achieve that.

Thank you
OpenOffice 4.2 MacOS
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: BASIC - Howto handle selected text in a textbox ?

Post by RPG »

Hello

A textbox does have the property "hide selection". Maybe you have to test how to set it for you. Do test it after the macro is working when the focus is on the control.

Code: Select all

sub selecttextincontrol(oEvent as object)
'I did use the event : Mouse out side
dim strucselection as new com.sun.star.awt.Selection
dim oTextControl
oTextControl=oEvent.source
'mri oTextControl
strucselection.min=1
strucselection.max=3
oTextControl.setSelection(strucselection)
exit sub
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Apollo102
Posts: 8
Joined: Tue Mar 11, 2014 12:32 am

Re: BASIC - Howto handle selected text in a textbox ?

Post by Apollo102 »

I'm very sorry. But I still do not understand how it is applied to a textshape. I would be interested to see how that goes.

THX
OpenOffice 4.2 MacOS
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: BASIC - Howto handle selected text in a textbox ?

Post by RPG »

Hello

I understand this topic as: How do we select text in a text control in a data-form for a database form.

I have little knowledge of shapes but I have the idea they do not contain text. A textcontrol does have a a shape but this is most of the time not important for the programmer.

The topic starter works with database forms and controls in data-forms.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: BASIC - Howto handle selected text in a textbox ?

Post by arfgh »

yes, this is what i need. Just to be able to select the number of characters that i want into a textbox field.

example, if the textbox contains 'Apache OpenOffice', i want to select just 'Apache'
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: BASIC - Howto handle selected text in a textbox ?

Post by Villeroy »

"Text shape" may refer to something from the "Drawing" toolbar.
"Text box" may refer to something from Insert>Fields>Other... or a form control.
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
Apollo102
Posts: 8
Joined: Tue Mar 11, 2014 12:32 am

Re: BASIC - Howto handle selected text in a textbox ?

Post by Apollo102 »

Sorry then I was wrong. I've always thought about a textshape in a DrawPage. A DrawPage which is included in a writer document. I misunderstood the topic.
OpenOffice 4.2 MacOS
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: BASIC - Howto handle selected text in a textbox ?

Post by Villeroy »

Apollo102 wrote:Sorry then I was wrong. I've always thought about a textshape in a DrawPage. A DrawPage which is included in a writer document. I misunderstood the topic.
From toolbar "Drawing" or from toolbar "Form Controls"?
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
Apollo102
Posts: 8
Joined: Tue Mar 11, 2014 12:32 am

Re: BASIC - Howto handle selected text in a textbox ?

Post by Apollo102 »

From toolbar "Drawing" . But I'm not the one who has casually asked the question. I just misunderstood the topic.
OpenOffice 4.2 MacOS
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: BASIC - Howto handle selected text in a textbox ?

Post by arfgh »

so exist no way to control the text selection on AOO ?
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: BASIC - Howto handle selected text in a textbox ?

Post by Villeroy »

If it happens to be a http://www.openoffice.org/api/docs/comm ... lEdit.html having an interface http://www.openoffice.org/api/docs/comm ... onent.html with method setSelection(aSelection) taking a struct http://www.openoffice.org/api/docs/comm ... ction.html then RPG gave a perfect example in the Basic language.
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
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: BASIC - Howto handle selected text in a textbox ?

Post by RPG »

Hello

The topic starter does try for a long time to mak macro in BASIC for OOo. I think you cannot understand a lot of the macro examples when you do not under stand how the UNO API is organized

For me the BASIC Programming guide is the best guide.
https://wiki.openoffice.org/wiki/Docume ... ASIC_Guide

https://wiki.openoffice.org/wiki/Docume ... Interfaces
The part about Modules, Services and Interfaces and the following is seen by me always as important.Until the moment I did understand it and knew how to use I did get more progress in understanding. An other part was understanding that an object as a Textcontrol does have different services how to work with that object. A textcontrol does have:
a) A shape
b) The model
c) the view

https://wiki.openoffice.org/wiki/Docume ... With_Forms

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: BASIC - Howto handle selected text in a textbox ?

Post by arfgh »

the RPG example works like a charm. But i want to rescue this thread because want to point the follow:

Now we know how to handle the txt selection, but, how to handle the cursor position ? It has its interesting to be able to edit the cursor position in order to perform a little sub that will predicts the user entry data conforming with stored data.

and also...

exist a way to know what keyboard button is pressed from the RPG event sub ? for example, detect the return key, etc.

thx in advance
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: BASIC - Howto handle selected text in a textbox ?

Post by Villeroy »

I bind the key press event of a text box to MRILib.Module1.mri and get the answer to all your questions as soon as I type any char into the box.
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
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: BASIC - Howto handle selected text in a textbox ?

Post by RPG »

Hello

Did you have study the view of the control you use? Try to understand all the methods, properties and the interfaces belonging to the service what is exported by the object you use.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: BASIC - Howto handle selected text in a textbox ?

Post by arfgh »

well

the key detect was easy.

sub autoFill(event as object)
if event.KeyCode = 1283 then blabla

anyways, what about the cursor position into a text field ? Can someone point the interface or some help ?

thx in advance
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: BASIC - Howto handle selected text in a textbox ?

Post by Villeroy »

Referring to RPGs code above:

Code: Select all

strucselection.min=3
strucselection.max=3
min=max. No text range selected. Input cursor at position 3.
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
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: BASIC - Howto handle selected text in a textbox ?

Post by arfgh »

no, these parameters passed with the struct handle the text selected, i want to position the cursor, on certain position.
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: BASIC - Howto handle selected text in a textbox ?

Post by RPG »

Hello

It does not work it that way at least as far I understand it.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: BASIC - Howto handle selected text in a textbox ?

Post by RPG »

Hello

I did look again to those things I knew from text in a textbox in a form. As far I knew you want work with the complete textbox and it is not easy to modify some part of the textbox text.

There is an interface xsimpletext for the model and also the view of the control export some methods and properties. When we want work with the text in the control and maybe also with the other part of the form document then we have to set a special property: Hide selection.

When you want show the selection always then it must be set to no.

I assume we want seen what we do on the screen. As far I understand we have to work with the view of the control and not the model.

Apollo102 give some code and that code does not work in the way he expect but that code can be used when you use the xsimpletext. I can work with xsimpletext but we do not see anything on screen.

What means this all: it is real difficult to work with the text in a textbox and show it on screen. You need knowledge about several interfaces and those interfaces seems not work together as far I understand.

Xsimpletext is:
http://www.openoffice.org/api/docs/comm ... eText.html

What export:
http://www.openoffice.org/api/docs/comm ... ursor.html

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: BASIC - Howto handle selected text in a textbox ?

Post by RPG »

Hello

For you information:
You read and write the min and the max of the selection.

Code: Select all

print oTextboxControl.selection.max
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
eibo
Posts: 9
Joined: Mon May 10, 2010 1:08 pm

Re: BASIC - Howto handle selected text in a textbox ?

Post by eibo »

Villeroy wrote:Referring to RPGs code above:

Code: Select all

strucselection.min=3
strucselection.max=3
min=max. No text range selected. Input cursor at position 3.
It is just as Villeroy says, a cursor position is a textrange which has its end on the same position as its beginning. See the attached example. The cursor in a textfield is somewhat different than the regular viewcursor, as you can only select one contiguous part of the text. Furthermore this only works with unformatted textfields, please see my question in the forum viewtopic.php?f=20&t=71091.
eibo
Attachments
SelectInTextfield.odt
(12.77 KiB) Downloaded 335 times
AOO 4.0 on Debian Wheezy
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: BASIC - Howto handle selected text in a textbox ?

Post by RPG »

Hello Eibo

I have the idea you can better search for an other solution.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Post Reply