Forum: wxRuby Help on StyledTextCtrl's hotspots

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
01a68e65c05c8751d75dbf957ea4fa23?d=identicon&s=25 Zhimin Zhan (zzhan)
on 2009-04-09 02:00
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
06f6780c99d4a8dd71f2b474082ea9ce?d=identicon&s=25 Alex Fenton (Guest)
on 2009-04-15 01:10
(Received via mailing list)
Hi Zhimin

Zhimin Zhan 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/scintilla-interest@lyr...

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
01a68e65c05c8751d75dbf957ea4fa23?d=identicon&s=25 Zhimin Zhan (zzhan)
on 2009-04-15 13:38
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
06f6780c99d4a8dd71f2b474082ea9ce?d=identicon&s=25 Alex Fenton (Guest)
on 2009-04-15 14:34
(Received via mailing list)
Zhimin Zhan 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/wxpy...
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
This topic is locked and can not be replied to.