summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <alex.merry@cs.ox.ac.uk>2012-12-04 12:02:12 +0000
committerAlex Merry <alex.merry@cs.ox.ac.uk>2012-12-04 12:02:12 +0000
commit134de8169993f23f2c3a733a7bf96622965e7d7d (patch)
treed9caeac0f95e658b6a2a2c409bc2098e8f72e1d4
parent94ff07fc9d728d97dde159e0c3e6ab80e29e0855 (diff)
Turn InputDelegate into a protocol
We require support for the @optional keyword, so we should make use of it.
-rw-r--r--tikzit/src/gtk/GraphInputHandler.h2
-rw-r--r--tikzit/src/gtk/InputDelegate.h3
-rw-r--r--tikzit/src/gtk/Surface.h4
-rw-r--r--tikzit/src/gtk/WidgetSurface.h7
-rw-r--r--tikzit/src/gtk/WidgetSurface.m16
5 files changed, 17 insertions, 15 deletions
diff --git a/tikzit/src/gtk/GraphInputHandler.h b/tikzit/src/gtk/GraphInputHandler.h
index caf1528..4dbe5ca 100644
--- a/tikzit/src/gtk/GraphInputHandler.h
+++ b/tikzit/src/gtk/GraphInputHandler.h
@@ -40,7 +40,7 @@ typedef enum {
CanvasDragState
} MouseState;
-@interface GraphInputHandler: NSObject {
+@interface GraphInputHandler: NSObject <InputDelegate> {
GraphRenderer *renderer;
InputMode mode;
MouseState state;
diff --git a/tikzit/src/gtk/InputDelegate.h b/tikzit/src/gtk/InputDelegate.h
index 1e35223..9f9b426 100644
--- a/tikzit/src/gtk/InputDelegate.h
+++ b/tikzit/src/gtk/InputDelegate.h
@@ -38,7 +38,8 @@ typedef enum {
ScrollRight = 4,
} ScrollDirection;
-@interface NSObject (InputDelegate)
+@protocol InputDelegate <NSObject>
+@optional
/**
* A mouse button was pressed.
*/
diff --git a/tikzit/src/gtk/Surface.h b/tikzit/src/gtk/Surface.h
index 449721f..b6d8d2e 100644
--- a/tikzit/src/gtk/Surface.h
+++ b/tikzit/src/gtk/Surface.h
@@ -33,7 +33,7 @@ typedef enum {
@protocol Surface;
-@protocol RenderDelegate
+@protocol RenderDelegate <NSObject>
- (void) renderWithContext:(id<RenderContext>)context onSurface:(id<Surface>)surface;
@end
@@ -47,7 +47,7 @@ typedef enum {
* The surface should send a "SurfaceSizeChanged" notification
* when the width or height changes.
*/
-@protocol Surface
+@protocol Surface <NSObject>
/**
* The width of the surface, in surface units
diff --git a/tikzit/src/gtk/WidgetSurface.h b/tikzit/src/gtk/WidgetSurface.h
index 32c8222..02f2cbf 100644
--- a/tikzit/src/gtk/WidgetSurface.h
+++ b/tikzit/src/gtk/WidgetSurface.h
@@ -17,6 +17,7 @@
#import "TZFoundation.h"
#import <gtk/gtk.h>
+#import <InputDelegate.h>
#import <Surface.h>
/**
@@ -26,7 +27,7 @@
GtkWidget *widget;
Transformer *transformer;
id <RenderDelegate> renderDelegate;
- id inputDelegate;
+ id <InputDelegate> inputDelegate;
BOOL keepCentered;
BOOL grabsFocusOnClick;
CGFloat defaultScale;
@@ -36,8 +37,8 @@
- (id) initWithWidget:(GtkWidget*)widget;
- (GtkWidget*) widget;
-- (id) inputDelegate;
-- (void) setInputDelegate:(id)delegate;
+- (id<InputDelegate>) inputDelegate;
+- (void) setInputDelegate:(id<InputDelegate>)delegate;
- (BOOL) keepCentered;
- (void) setKeepCentered:(BOOL)centered;
diff --git a/tikzit/src/gtk/WidgetSurface.m b/tikzit/src/gtk/WidgetSurface.m
index 14d799b..91e0218 100644
--- a/tikzit/src/gtk/WidgetSurface.m
+++ b/tikzit/src/gtk/WidgetSurface.m
@@ -170,11 +170,11 @@ static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, Widge
}
}
-- (id) inputDelegate {
+- (id<InputDelegate>) inputDelegate {
return inputDelegate;
}
-- (void) setInputDelegate:(id)delegate {
+- (void) setInputDelegate:(id<InputDelegate>)delegate {
if (delegate == inputDelegate) {
return;
}
@@ -471,7 +471,7 @@ static gboolean button_press_event_cb(GtkWidget *widget, GdkEventButton *event,
}
}
- id delegate = [surface inputDelegate];
+ id<InputDelegate> delegate = [surface inputDelegate];
if (delegate != nil) {
NSPoint pos = NSMakePoint (event->x, event->y);
MouseButton button = (MouseButton)event->button;
@@ -491,7 +491,7 @@ static gboolean button_press_event_cb(GtkWidget *widget, GdkEventButton *event,
static gboolean button_release_event_cb(GtkWidget *widget, GdkEventButton *event, WidgetSurface *surface) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- id delegate = [surface inputDelegate];
+ id<InputDelegate> delegate = [surface inputDelegate];
if (delegate != nil) {
if ([delegate respondsToSelector:@selector(mouseReleaseAt:withButton:andMask:)]) {
NSPoint pos = NSMakePoint (event->x, event->y);
@@ -508,7 +508,7 @@ static gboolean button_release_event_cb(GtkWidget *widget, GdkEventButton *event
static gboolean motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event, WidgetSurface *surface) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- id delegate = [surface inputDelegate];
+ id<InputDelegate> delegate = [surface inputDelegate];
if (delegate != nil) {
if ([delegate respondsToSelector:@selector(mouseMoveTo:withButtons:andMask:)]) {
NSPoint pos = NSMakePoint (event->x, event->y);
@@ -525,7 +525,7 @@ static gboolean motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event,
static gboolean key_press_event_cb(GtkWidget *widget, GdkEventKey *event, WidgetSurface *surface) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- id delegate = [surface inputDelegate];
+ id<InputDelegate> delegate = [surface inputDelegate];
if (delegate != nil) {
if ([delegate respondsToSelector:@selector(keyPressed:withMask:)]) {
InputMask mask = mask_from_gdk_modifier_state (event->state);
@@ -540,7 +540,7 @@ static gboolean key_press_event_cb(GtkWidget *widget, GdkEventKey *event, Widget
static gboolean key_release_event_cb(GtkWidget *widget, GdkEventKey *event, WidgetSurface *surface) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- id delegate = [surface inputDelegate];
+ id<InputDelegate> delegate = [surface inputDelegate];
if (delegate != nil) {
if ([delegate respondsToSelector:@selector(keyReleased:withMask:)]) {
InputMask mask = mask_from_gdk_modifier_state (event->state);
@@ -555,7 +555,7 @@ static gboolean key_release_event_cb(GtkWidget *widget, GdkEventKey *event, Widg
static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, WidgetSurface *surface) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- id delegate = [surface inputDelegate];
+ id<InputDelegate> delegate = [surface inputDelegate];
if (delegate != nil) {
if ([delegate respondsToSelector:@selector(mouseScrolledAt:inDirection:withMask:)]) {
NSPoint pos = NSMakePoint (event->x, event->y);