Re: Emulating a block cursor in GtkSourceView
- From: Paolo Borelli <pborelli katamail com>
- To: Tony Houghton <h realh co uk>
- Cc: gnome-devtools gnome org
- Subject: Re: Emulating a block cursor in GtkSourceView
- Date: Mon, 25 Aug 2008 02:47:39 +0200
Il giorno dom, 24/08/2008 alle 21.14 +0100, Tony Houghton ha scritto:
> I'm trying to emulate a block cursor in GtkSourceView by superimposing a
> rectangle over it.
Which version of gtk are you using? Block cursor when pressing INS has
been included since gtk 2.12 (or maybe even 2.10, I do not recall the
details). I guess you can simply require that version of gtk or take a
look at gtk itself to see how it is implemented
ciao
Paolo
> I registered a handler for expose-event with
> g_signal_connect_after, and it does get called with expected
> coordinates, but no rectangle appears. I'm trying to draw it with
> gdk_draw_rectangle on the widget's window field.
>
> I don't know whether the reason for the failure is because I haven't set
> up the GdkGC properly (do I need to set a clip mask pixmap? - I don't
> understand how; does leaving it blank draw everything?) or something or
> if you just can't draw on top of widgets this way.
>
> Can anyone help? Is this a generic widget issue so I'd be better off
> asking in the gtk-app-devel list? The essentials of my code (in python)
> are below.
>
> @staticmethod
> def eor_colours(c1, c2):
> return gtk.gdk.Color(c1.red ^ c2.red, \
> c1.green ^ c2.green, c1.blue ^ c2.blue)
>
> ...
>
> def set_style(self, widget = None, old_style = None):
> ...
> # self.view is the gtksourceview2.View
> self.win = self.view.get_window(gtk.TEXT_WINDOW_WIDGET)
> ...
> c = self.eor_colours(style.base[gtk.STATE_NORMAL], self.colour)
> self.norm_gc = gtk.gdk.GC(self.win, c, c, None,
> gtk.gdk.XOR, gtk.gdk.SOLID,
> line_width = 1, line_style = gtk.gdk.LINE_SOLID)
>
> ...
>
> def enable(self):
> ...
> if self.expose_tag == None:
> self.expose_tag = self.view.connect_after("expose-event",
> self.expose_handler)
> ...
>
> # ... there's some code to work out the cursor position and store it
> # in self.rect and call self.win.invalidate_rect() whenever it
> # moves, blinks or otherwise needs updating
>
> def expose_handler(self, widget, event):
> if self.blinked_off or not self.rect or not self.enabled:
> return True
> intersect = event.area.intersect(self.rect)
> if intersect.width and intersect.height:
> if not self.norm_gc:
> self.set_style()
> if self.in_selection:
> gc = self.sel_gc
> else:
> gc = self.norm_gc
> self.win.draw_rectangle(gc, self.has_focus,
> self.rect.x, self.rect.y, self.rect.width, self.rect.height)
> return True # I've tried False here, no apparent difference
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]