# Help on StyledTextCtrl's hotspots

**URL:** <https://www.ruby-forum.com/t/help-on-styledtextctrls-hotspots/165097>\
**Category:** wxRuby\
**Created:** [April 9, 2009, 2:00am UTC](https://www.ruby-forum.com/t/help-on-styledtextctrls-hotspots/165097 "2009-04-09T02:00:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zzhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7cd45c/32.png) [@zzhan](https://www.ruby-forum.com/u/zzhan)\
**Post date:** [April 9, 2009, 2:00am UTC](https://www.ruby-forum.com/t/help-on-styledtextctrls-hotspots/165097/1 "2009-04-09T02:00:55Z")

</div>

Hi

I want to implement a clickable link in StyledTextCtrl, seems hotspots  
is the way to go (when mouse hove on hotspot, cursor changed to ‘hand’,  
can fire a click event).

My code (below) only works when a lexer is not set!

Is there a way to dynamically set certain text to be hotspots?

def initialize

set\_lexer(STC\_LEX\_RUBY) # if set, the hotspot style is lost

# …

set\_hotspot\_active\_underline(true)  
style\_set\_hot\_spot(STYLE\_FUNCTION, true)  
evt\_stc\_hotspot\_click(self.id) { |event| puts “clicked hotspot” }

# …

end

# calling from controller when ready

def make\_function\_clickable(start\_pos, length)  
@style\_mask = 255  
self.start\_styling(start\_pos, @style\_mask)  
self.set\_styling(length, STYLE\_FUNCTION)  
end

Thanks,  
Zhimin

---

<div class="post-metadata">

**Author:** ![zzhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7cd45c/32.png) [@zzhan](https://www.ruby-forum.com/u/zzhan)\
**Post date:** [April 15, 2009, 1:10am UTC](https://www.ruby-forum.com/t/help-on-styledtextctrls-hotspots/165097/2 "2009-04-15T01:10:53Z")

</div>

Hi Zhimin

Zhimin Z. wrote:

> I want to implement a clickable link in StyledTextCtrl, seems hotspots  
> is the way to go (when mouse hove on hotspot, cursor changed to ‘hand’,  
> can fire a click event).
> 
> My code (below) only works when a lexer is not set!
> 
> Is there a way to dynamically set certain text to be hotspots?

To be honest, I’m not sure. I would look for help via Scintilla on this

- as you probably guessed, StyledTextCtrl is a pretty thin layer of this  
editing component.

This page here would suggest that if a lexer is present, it has control  
of setting hotspots:

[http://www.mail-archive.com/removed\_email\_address@domain.invalid/msg00210.html](http://www.mail-archive.com/removed_email_address@domain.invalid/msg00210.html)

This may mean it’s not possible, or not possible without writing your  
own lexer. Whether this is possible in Ruby with StyledTextCtrl I don’t  
know - I haven’t explored the (large) STC API enough to know. But it  
would be interesting…

alex

---

<div class="post-metadata">

**Author:** ![zzhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7cd45c/32.png) [@zzhan](https://www.ruby-forum.com/u/zzhan)\
**Post date:** [April 15, 2009, 1:38pm UTC](https://www.ruby-forum.com/t/help-on-styledtextctrls-hotspots/165097/3 "2009-04-15T13:38:47Z")

</div>

Thanks Alex.

The link you pointed out has most related information on this topic, it  
seems too low level for me, probably will be easier to write my own  
lexer.

Zhimin

---

<div class="post-metadata">

**Author:** ![zzhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7cd45c/32.png) [@zzhan](https://www.ruby-forum.com/u/zzhan)\
**Post date:** [April 15, 2009, 2:34pm UTC](https://www.ruby-forum.com/t/help-on-styledtextctrls-hotspots/165097/4 "2009-04-15T14:34:26Z")

</div>

Zhimin Z. wrote:

> The link you pointed out has most related information on this topic, it  
> seems too low level for me, probably will be easier to write my own  
> lexer.

In that case the following links might be helpful:

[http://aspn.activestate.com/ASPN/Mail/Message/wxpython-users/3645151](http://aspn.activestate.com/ASPN/Mail/Message/wxpython-users/3645151)

> **[Scintilla Documentation](https://www.scintilla.org/ScintillaDoc.html)**

In wxRuby the form of event handling for custom lexing will look  
something like

```
evt_stc_styleneeded(self) do | evt |
  start_pos = end_styled
  line_num = line_from_position( start_pos )
  start_pos = position_from_line( line_num )
  # start styling at position
  start_styling(start_pos, 31)
  # do whatever styling is needed to text chunks
  set_styling(evt.position - start_pos, 2)
end

```

good luck!

a
