Help on StyledTextCtrl's hotspots

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

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/[email protected]/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

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

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://www.scintilla.org/ScintillaDoc.html#SCN_STYLENEEDED

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