From 48fdfbb5c497037eccebdd5de168de995401771a Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Mon, 4 Feb 2013 15:08:16 +0000 Subject: GTK: show focus indicator for graph surface --- tikzit/TODO | 1 - tikzit/src/gtk/GraphRenderer.m | 5 ++++- tikzit/src/gtk/Surface.h | 3 +++ tikzit/src/gtk/WidgetSurface.m | 24 ++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tikzit/TODO b/tikzit/TODO index 3ecc9b2..ca1a1b9 100644 --- a/tikzit/TODO +++ b/tikzit/TODO @@ -1,5 +1,4 @@ GTK port: - - possibly indicate when the graph surface has focus? - Use GooCanvas for the graph display diff --git a/tikzit/src/gtk/GraphRenderer.m b/tikzit/src/gtk/GraphRenderer.m index 76fe551..4278551 100644 --- a/tikzit/src/gtk/GraphRenderer.m +++ b/tikzit/src/gtk/GraphRenderer.m @@ -91,8 +91,11 @@ void graph_renderer_expose_event(GtkWidget *widget, GdkEventExpose *event); [self invalidateGraph]; } -- (void) renderWithContext:(id)context onSurface:(id)surface { +- (void) renderWithContext:(id)context onSurface:(id)s { [self renderWithContext:context]; + if ([s hasFocus]) { + [s renderFocus]; + } } - (void) renderWithContext:(id)context { diff --git a/tikzit/src/gtk/Surface.h b/tikzit/src/gtk/Surface.h index b6d8d2e..db4288e 100644 --- a/tikzit/src/gtk/Surface.h +++ b/tikzit/src/gtk/Surface.h @@ -99,6 +99,9 @@ typedef enum { - (void) zoomResetAboutPoint:(NSPoint)p; - (void) setCursor:(Cursor)c; + +- (BOOL) hasFocus; +- (void) renderFocus; @end // vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/WidgetSurface.m b/tikzit/src/gtk/WidgetSurface.m index 64adc25..680cf90 100644 --- a/tikzit/src/gtk/WidgetSurface.m +++ b/tikzit/src/gtk/WidgetSurface.m @@ -225,6 +225,30 @@ static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, Widge } } +- (BOOL) hasFocus { + return gtk_widget_has_focus (widget); +} + +- (void) renderFocus { + GdkWindow *window = gtk_widget_get_window (widget); + if (window) { + int width = 0; + int height = 0; + gdk_drawable_get_size (window, &width, &height); + gtk_paint_focus (gtk_widget_get_style (widget), + window, + GTK_STATE_NORMAL, + NULL, + widget, + NULL, + 0, + 0, + width, + height + ); + } +} + - (CGFloat) defaultScale { return defaultScale; } -- cgit v1.2.3