Emulating a block cursor in GtkSourceView
- From: Tony Houghton <h realh co uk>
- To: gnome-devtools gnome org
- Subject: Emulating a block cursor in GtkSourceView
- Date: Sun, 24 Aug 2008 21:14:34 +0100
I'm trying to emulate a block cursor in GtkSourceView by superimposing a
rectangle over it. 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
--
TH * http://www.realh.co.uk
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]