mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 12:12:35 +03:00
Adding tool tips and changing the cursor in the local history view.
svn path=/trunk/netsurf/; revision=11855
This commit is contained in:
parent
f470261141
commit
8eda3390da
@ -24,6 +24,7 @@
|
||||
@interface HistoryView : NSView {
|
||||
struct browser_window *browser;
|
||||
BrowserView *browserView;
|
||||
NSMutableArray *toolTips;
|
||||
}
|
||||
|
||||
@property (readwrite, assign, nonatomic) BrowserView *browser;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user