summaryrefslogtreecommitdiff
path: root/cocoa
diff options
context:
space:
mode:
authorSven Weidauer <sven.weidauer@gmail.com>2011-02-28 15:24:15 +0000
committerSven Weidauer <sven.weidauer@gmail.com>2011-02-28 15:24:15 +0000
commit8eda3390daa58ac60b1e2b36dd227e37632a3225 (patch)
tree5f51abe8384e74f7995106933522484e81d93daa /cocoa
parentf47026114173a51802e8915b1f49888eb4367b46 (diff)
downloadnetsurf-8eda3390daa58ac60b1e2b36dd227e37632a3225.tar.gz
netsurf-8eda3390daa58ac60b1e2b36dd227e37632a3225.tar.bz2
Adding tool tips and changing the cursor in the local history view.
svn path=/trunk/netsurf/; revision=11855
Diffstat (limited to 'cocoa')
-rw-r--r--cocoa/HistoryView.h1
-rw-r--r--cocoa/HistoryView.m72
2 files changed, 70 insertions, 3 deletions
diff --git a/cocoa/HistoryView.h b/cocoa/HistoryView.h
index d3062b6f1..6ef061321 100644
--- a/cocoa/HistoryView.h
+++ b/cocoa/HistoryView.h
@@ -24,6 +24,7 @@
@interface HistoryView : NSView {
struct browser_window *browser;
BrowserView *browserView;
+ NSMutableArray *toolTips;
}
@property (readwrite, assign, nonatomic) BrowserView *browser;
diff --git a/cocoa/HistoryView.m b/cocoa/HistoryView.m
index bf38b7716..6c1c44587 100644
--- a/cocoa/HistoryView.m
+++ b/cocoa/HistoryView.m
@@ -40,12 +40,10 @@
- (NSSize) size;
{
- const CGFloat padding = 10;
-
int width, height;
history_size( browser->history, &width, &height );
- return NSMakeSize( cocoa_px_to_pt( width ) + padding, cocoa_px_to_pt( height ) + padding );
+ return cocoa_size( width, height );
}
- (void) updateHistory;
@@ -56,6 +54,9 @@
- (void) drawRect: (NSRect)rect;
{
+ [[NSColor clearColor] set];
+ [NSBezierPath fillRect: rect];
+
cocoa_set_font_scale_factor( 1.0 );
cocoa_set_clip( rect );
@@ -78,4 +79,69 @@
return YES;
}
+- (void) mouseEntered: (NSEvent *) event;
+{
+ [[NSCursor pointingHandCursor] set];
+}
+
+- (void) mouseExited: (NSEvent *) event;
+{
+ [[NSCursor arrowCursor] set];
+}
+
+static bool cursor_rects_cb( const struct history *history, int x0, int y0, int x1, int y1,
+ const struct history_entry *page, void *user_data )
+{
+ HistoryView *view = user_data;
+
+ NSRect rect = NSIntersectionRect( [view visibleRect], cocoa_rect( x0, y0, x1, y1 ) );
+ if (!NSIsEmptyRect( rect )) {
+
+ NSString *toolTip = [NSString stringWithFormat: @"%s\n%s", history_entry_get_title(page),
+ history_entry_get_url( page )];
+
+ [view addToolTipRect: rect owner: toolTip userData: nil];
+ NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect: rect
+ options: NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp
+ owner: view userInfo: nil];
+ [view addTrackingArea: area];
+ [area release];
+ }
+
+ return true;
+}
+
+- (NSToolTipTag)addToolTipRect: (NSRect) rect owner: (id) owner userData: (void *) userData;
+{
+ if (toolTips == nil) toolTips = [[NSMutableArray alloc] init];
+ [toolTips addObject: owner];
+
+ return [super addToolTipRect: rect owner: owner userData: userData];
+}
+
+- (void) removeAllToolTips;
+{
+ [super removeAllToolTips];
+ [toolTips removeAllObjects];
+}
+
+- (void) updateTrackingAreas;
+{
+ [self removeAllToolTips];
+
+ for (NSTrackingArea *area in [self trackingAreas]) {
+ [self removeTrackingArea: area];
+ }
+
+ history_enumerate( browser->history, cursor_rects_cb, self );
+
+ [super updateTrackingAreas];
+}
+
+- (void) dealloc;
+{
+ [self removeAllToolTips];
+ [super dealloc];
+}
+
@end