BASIC - Howto handle selected text in a textbox ?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
eibo
Posts: 9
Joined: Mon May 10, 2010 1:08 pm

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

Post by eibo »

Could you please explain, why you think my example script is not OK? It appears to do everything that was asked for, as an extra I added modification of the selected text, which is actually quite easy to accomplish.

Code: Select all

Sub SelectionInUnformattedTextfield()
       Dim Sel as new com.sun.star.awt.Selection
       Sel.Min = ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Min").Value
       Sel.Max = ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Max").Value
       ThisComponent.getCurrentController.getControl(_
          ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Unformatted")_
       ).setFocus
       ThisComponent.getCurrentController.getControl(_
          ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Unformatted")_
       ).setSelection(Sel)
       ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Old").String = ThisComponent.getCurrentController.getControl(_
          ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Unformatted")_
       ).SelectedText
end sub
Sub OverwriteSelection
	Dim Sel as new com.sun.star.awt.Selection

	Sel = ThisComponent.getCurrentController.getControl(_
		ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Unformatted")_
	).getSelection()

	ThisComponent.getCurrentController.getControl(_
		ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Unformatted")_
	).insertText(Sel, ThisComponent.Drawpage.Forms.getByName("Demo").getByName("New").String )
	
	Rem Place cursor
	ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Min").Value = _
		ThisComponent.Drawpage.Forms.getByName("Demo").getByName("NewCursorPosition").Value
	ThisComponent.Drawpage.Forms.getByName("Demo").getByName("Max").Value = _
		ThisComponent.Drawpage.Forms.getByName("Demo").getByName("NewCursorPosition").Value
	SelectionInUnformattedTextfield
end sub
You mentioned HideInactiveSelection, this property is nice if you need to see the selection without giving the focus to the textfield, it does not change the selection though. Even if there might be situations, where this feature is helpful, I would only set it in a macro while neeeded, never permanently on a textfield, as actions will not work on it when inactive, leading to confusion.
Attachments
SelectInTextfield.odt
2 version
(14.63 KiB) Downloaded 242 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

I cannot explain why the setselection and also more methodes of that interfaces do not work.

When the textbox is set to multiline with formatted text it means as far I know the RichText property has the value true it is different then when the value is false.
http://www.openoffice.org/api/docs/comm ... ntrol.html

I can not tell more. I donot know if there are also bugs who will possible not be repaired. You can see when you select some parts in a text box - multi-line with formatted text then the colour is different of the use of the text box without using multi-line with formatted text.

You can modify the textbox with the createTextCursor. The createTextCursor does not change the selection.

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 »

Now I see, you thought this was about my question in the other thread. It is not, it is solution to the question in this thread, namely to select a specific part of a textbox, to change this selection and to place the cursor on some customizable position, all in case of an unformatted textfield, which I presumed was all that was asked for. Have a look at the second version of my example file.
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 wrote:Now I see, you thought this was about my question in the other thread.
Yes you are right. Playing with these things can be real good to learn how you can program in the API of OOo.

You did asked for "hide selection" on that moment I choose for skipping but I can tell you that it was important for me and for an user that it was possible. When I set "hide selection" to the good value then I can use a dialog for a complex search in a text control and hight light the result. When it is not set to the good value then the result is not high lighted.

Here you can see why.
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, still with the second question.. how to set the cursor position in the first character of the text control... i see it not clear...
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 »

arfgh wrote:how to set the cursor position in the first character of the text control.
It seems a simple question but as in the API we have a lot of simple questions but in this case we have no details. On the moment we have no details then the question is: what are the details.

I think start a new thread with a question and add an example to the question.

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 »

RPG the question is just the same as was exposed on the current thread, i dont think that is necesary to start other thread...
The text selection handle was easy to understand, but i dont see yet the way to move the text cursor to other desired position into the text control.
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 »

arfgh wrote:The text selection handle was easy to understand, but i dont see yet the way to move the text cursor to other desired position into the text control.
You can change the selection parameters. So you have to change the MIN and MAX value. Searching is not done

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 »

maybe i dont understand it. Are you saying that handle just the text selection to match certain position, the text cursor will be there ?
Saying it by other way, the text selection move the text cursor ?
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 »

As far I understand there is no text cursor in a text-control. I have never studied in detail what is the relation between Simpletext and the Selection. But I have the idea that Simpletext is paragraph based and Selection is based on characters.

The next is a little off topic but when people want do such complicated things as you want do then an Office program is not the best tool. What tool is better? I do not know but I think that a program what can display good HTML code is better. It must a program in which you can use also easy a database program. But as a simple user it is not to me to give advice on this problem.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
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 »

1. Read more documentation including some of the abstract concepts (model, view, frame etc.). I only know a small part of that shit which is the small part I understand.
2. Use MRI

Anything related to selections in a GUI is done by a controller. Every (sub-)form has its own controller which can be derived from the document's controller.
 Edit: P.S. Property "Hide Selection"=No shows the text selection even when the edit box does not have the focus 
Attachments
EditBoxSelection.odt
Select text snippet in .awt.EditControl
(12.1 KiB) Downloaded 171 times
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 »

Hey there again Villeroy, thx for your example :)

RPG, i dont understand your doubt with the text cursor in text controls, but you had the reason. Adjusting the text selection to the same pos we obtain just that, the text cursor blinking on that position. I never figured it. And, AOO is perfect for the messing and learning about databases.
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Post Reply