Change foreground color a piece of fieldText

62 views
Skip to first unread message

Mario Carrera

unread,
Nov 18, 2011, 10:42:49 AM11/18/11
to va-sma...@googlegroups.com
Hi, I need to change the foreground color to a piece of AbtTextView.
I try to explain me  better: I have in a widget some fields (AbtTextView). In one of them, when the length of string is grater than 10 then changeForegroundColor.Es.  So from 1 to 10 text is black, from 11 to end of entrie text, it will be red.
How to do?
Im using vast 6.01
Thanks  

Sebastian Heidbrink

unread,
Nov 18, 2011, 11:49:56 AM11/18/11
to va-sma...@googlegroups.com
Hi Mario,

I don't have access to a 6.01 installation, but I don't expect changes
since then.
If you have trouble I'll check this on an old version, too.

I attached one very simple, no thought on performance, sense, GCs and so
on...
I assume your problem is the non responding change on setting the
foreground: , anyway... it's the widget you have to access.

Have fun,
Sebastian

> --
> You received this message because you are subscribed to the Google
> Groups "VA Smalltalk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/va-smalltalk/-/f5SR1CA6I7QJ.
> To post to this group, send email to va-sma...@googlegroups.com.
> To unsubscribe from this group, send email to
> va-smalltalk...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/va-smalltalk?hl=en.

MyApplication1.app

Sebastian Heidbrink

unread,
Nov 18, 2011, 11:54:16 AM11/18/11
to va-sma...@googlegroups.com
Ups ;-)

You mean two colors within one TextView?

Okay,... that's not it,...

I'll have alook, but, never tried it.
From a first thought, you might need a new Part.

Sebastian

Am 18.11.2011 16:42, schrieb Mario Carrera:

Sebastian Heidbrink

unread,
Nov 18, 2011, 1:39:50 PM11/18/11
to va-sma...@googlegroups.com
Hi Mario,

With AbtTextView you won't be able to have two Colors within your widget.
AbtTextView uses OSEditWidget and this widget sets the whole text at a time.

What you might have to consider. is searching an other widgetclass under
VAST 6.0.1 which uses the method

OSWidget>>#drawText: aString x: anX y: aY width: aWidth height: aHeight
flags: flags

You may then try to override this method like this.

drawText: aString x: anX y: aY width: aWidth height: aHeight flags: flags
"Private - Draw aString using the platform dependant flags within
the rectangle described by the anX, aY, aWidth and aHeight
parameters. "
| text rect border nLeft nTop nRight nBottom |

aString isNil ifTrue:[^self].

self dcDo: [:hDC |
"Create the drawing rectangle for the text."
border := self borderWidth.
nLeft := anX - border.
nTop := aY - border.
nRight := (nLeft + aWidth min: width - (border * 2)).
nBottom := (nTop + aHeight min: height - (border * 2)).
(rect := OSRect new)
setRect: nLeft
nTop: nTop
nRight: nRight
nBottom: nBottom.

"Convert to a platform string before drawing."
text := PlatformString fromString: aString.

hDC
drawText: (text copyFrom: 1 to: (text size min: 10))
cb: (text size min: 10)
lprc: rect
fuFormat: flags.

text size > 10
ifTrue:[ hDC setTextColor: 16r000000 .

hDC
drawText: (text copyFrom: 10 to: text size)
cb: text size
lprc: rect
fuFormat: flags].

hDC setTextColor: 16rFFFFFF.

].

Im not 100% sure if this will work properly, but it should.
This means in the end that you will end up with a new
Abt/Cw/OSTextWidget-kombination.

Or you search for senders of setTextColor: ,.. maybe you find another
solution or existing class.

Cheers!
Sebastian

Am 18.11.2011 16:42, schrieb Mario Carrera:

Mario Carrera

unread,
Nov 21, 2011, 5:21:18 AM11/21/11
to va-sma...@googlegroups.com
Thank you Sebastian I will try...but let me understand, you mind to try create a new kind of CwText?

SebastianHC

unread,
Nov 21, 2011, 10:36:05 AM11/21/11
to va-sma...@googlegroups.com
yes,... new Classes for all three layers OS/Cw/Abt...

You may want to add new attributes to all layers,... position of color
change and colors,...

If this is too much work for you, you could also use a MulitlineEditWidget.
There's codecoloring in VAST,.... StsPowertools include the coding. I'm not
to sure if you have those implementatiosn inyou VAST 6.0.1

Or, it is simply time to upgrade ;-)
John will love to assist you!

Sebastian

--
View this message in context: http://forum.world.st/Change-foreground-color-a-piece-of-fieldText-tp4083701p4091910.html
Sent from the Instantiations mailing list archive at Nabble.com.

Reply all
Reply to author
Forward
0 new messages