comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Text Widget Confession
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Text Widget Confession [message #26626] Fri, 21 September 2001 09:08 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Folks,

Alright, I confess. Text widgets have always confused
the hell out of me. And for years I have avoided using
them, except in the very simplest way, and then only
when I could find no alternative. (I've found mind-
reading only partially successful.)

Here is the deal. I have a text widget with
a three-element string array in it:

theText = ['Dog', 'Cow', 'Coyote']

When displayed in the text widget it looks like this:

Dog
Cow
Coyote

I want to make a selection in the text widget.
Then, when the user says "Do It", I want to
delete any lines that are in the selection.

For example, if the user selects the word "Cow"
and clicks "Do It", I want to delete the second
line in the text widget. If the user selects
"g Cow", I want to delete the first two lines, etc.

Pretty straightforward, don't you think?

But I've been fooling around with this for two hours
now and haven't come up with anything remotely useful.

I can get the selection offset and length:

selection = Widget_Info(textID, /Text_Select)

In the case in which the word "Cow" is selected,
the offset is 5 and the length of the selection
is 3. An offset of 5!? Into what array?

Check the number of characters in the text widget:

numchar = Widget_Info(textID, /Text_Number)

I get 18. Wait a minute. d-o-g-... I have 12
characters. But I have three elements in my
string array, and the longest of these elements
is 6 characters. 3 times 6 = 18. Can it be!?

No, I convert the text to a byte array and use
the selection offsets and length to try to fish
the selection out. No luck. An offset of 5
still doesn't compute.

OK, let's convert the offset to "column and line"
values. That "line" business sounds promising.

cl = Widget_Info(textID, Text_Offset_To_XY=selection[0])
Print, cl
2 1

Well, column equals 2 is confusing. But line 1 looks
promising. I'm definitely in line 1!!! But, if I select
"ow" instead of "Cow" I now get the values 0 and 2 for
column and line. Sigh...

Here is some example code I'm using to explore the
possibilities. Does anyone have any ideas?

Cheers,

David

************************************************************
PRO Example_Event, event
Widget_Control, event.top, Get_UValue=textID

; Get the current text selection.

selection = Widget_Info(textID, /Text_Select)
Print, ""
Print, 'Selection Offset: ', selection[0]
Print, 'Selection Length: ', selection[1]

; Print the number of characters in the text value.

numchar = Widget_Info(textID, /Text_Number)
Print, 'Number of Characters in Text Widget: ', numchar

; Try to find the word using the offsets and lengths.
; No luck

Widget_Control, textID, Get_Value=theText
array = Byte(theText)
IF selection[1] NE 0 THEN BEGIN
word = array[selection[0]:selection[0]+selection[1]-1]
Print, 'Bytes Selected: ', word
Print, 'Selected Word: ', String(word)
ENDIF ELSE Print, 'No Selection'

; Get the selected text. OK, I can find the selected
; text, but what lines do I have?

Widget_Control, textID, Get_Value=selectText, /Use_Text_Select
Print, 'Selected Text: ', selectText

; Try to convert text offset to columns and lines (?).

cl = Widget_Info(textID, Text_Offset_To_XY=selection[0])
Print, 'Offset starts in this column: ', cl[0]
Print, 'Offset starts in this line: ', cl[1]

END; -----------------------------------

PRO Example
tlb = Widget_Base(Column=1)
button = Widget_Button(tlb, Value='Do It')
textID = Widget_Text(tlb, Scr_XSize=100, $
YSize=20,Value=['Dog', 'Cow', 'Coyote'])
Widget_Control, tlb, /Realize, Set_UValue=textID
XManager, 'example', tlb, /No_Block
END; -----------------------------------
************************************************************

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: A distracting puzzle
Next Topic: Xmanager R US

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 15:34:13 PDT 2025

Total time taken to generate the page: 1.52001 seconds