summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cocoa/BlackScroller.m219
-rw-r--r--cocoa/BookmarksController.m237
-rw-r--r--cocoa/BrowserView.m821
-rw-r--r--cocoa/BrowserViewController.h2
-rw-r--r--cocoa/BrowserViewController.m440
-rw-r--r--cocoa/BrowserWindow.m4
-rw-r--r--cocoa/DownloadWindowController.h29
-rw-r--r--cocoa/DownloadWindowController.m479
-rw-r--r--cocoa/FormSelectMenu.h13
-rw-r--r--cocoa/FormSelectMenu.m111
-rw-r--r--cocoa/LocalHistoryController.h2
-rw-r--r--cocoa/ScrollableView.m55
-rw-r--r--cocoa/Tree.h6
-rw-r--r--cocoa/Tree.m104
-rw-r--r--cocoa/TreeView.m202
15 files changed, 1426 insertions, 1298 deletions
diff --git a/cocoa/BlackScroller.m b/cocoa/BlackScroller.m
index 3e711376c..2ee739f3a 100644
--- a/cocoa/BlackScroller.m
+++ b/cocoa/BlackScroller.m
@@ -1,141 +1,154 @@
/* Copyright (c) 1011 Sven Weidauer
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
#import "BlackScroller.h"
-
@implementation BlackScroller
-- (void) setFrame: (NSRect)frameRect;
+- (void) setFrame: (NSRect)frameRect
{
- [super setFrame: frameRect];
- if (tag != 0) [self removeTrackingRect: tag];
- tag = [self addTrackingRect: [self bounds] owner: self userData: NULL assumeInside: NO];
+ [super setFrame: frameRect];
+ if (tag != 0) [self removeTrackingRect: tag];
+ tag = [self addTrackingRect: [self bounds] owner: self userData: NULL assumeInside: NO];
}
-- (void) drawRect: (NSRect)dirtyRect;
+- (void) drawRect: (NSRect)dirtyRect
{
- [[NSColor clearColor] set];
- [NSBezierPath fillRect: dirtyRect];
-
- if (drawTrack) [self drawKnobSlotInRect: [self rectForPart: NSScrollerKnobSlot]
- highlight: NO];
- [self drawKnob];
+ [[NSColor clearColor] set];
+ [NSBezierPath fillRect: dirtyRect];
+
+ if (drawTrack) [self drawKnobSlotInRect: [self rectForPart: NSScrollerKnobSlot]
+ highlight: NO];
+ [self drawKnob];
}
-- (void) drawKnobSlotInRect: (NSRect)slotRect highlight: (BOOL)flag;
+- (void) drawKnobSlotInRect: (NSRect)slotRect highlight: (BOOL)flag
{
- slotRect = NSInsetRect( slotRect, 2, 2 );
- slotRect = [self convertRectToBase: slotRect];
- slotRect.origin.x = floor( slotRect.origin.x ) + 0.5;
- slotRect.origin.y = floor( slotRect.origin.y ) + 0.5;
- slotRect.size.width = floor( slotRect.size.width );
- slotRect.size.height = floor( slotRect.size.height );
- slotRect = [self convertRectFromBase: slotRect];
-
- NSGradient *gradient = [[[NSGradient alloc] initWithColorsAndLocations:
- [NSColor clearColor], 0.0,
- [NSColor clearColor], 0.4,
- [NSColor whiteColor], 1.0,
- nil] autorelease];
- [[NSColor whiteColor] set];
- const float radius = 0.5 * ([self isHorizontal] ? NSHeight( slotRect ) : NSWidth( slotRect ));
- NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: slotRect
- xRadius: radius
- yRadius: radius];
- [gradient drawInBezierPath: path angle: [self isHorizontal] ? 90 : 0];
-
- [path stroke];
+ slotRect = NSInsetRect( slotRect, 2, 2 );
+ slotRect = [self convertRectToBase: slotRect];
+ slotRect.origin.x = floor( slotRect.origin.x ) + 0.5;
+ slotRect.origin.y = floor( slotRect.origin.y ) + 0.5;
+ slotRect.size.width = floor( slotRect.size.width );
+ slotRect.size.height = floor( slotRect.size.height );
+ slotRect = [self convertRectFromBase: slotRect];
+
+ NSGradient *gradient = [[[NSGradient alloc] initWithColorsAndLocations:
+ [NSColor clearColor], 0.0,
+ [NSColor clearColor], 0.4,
+ [NSColor whiteColor], 1.0,
+ nil] autorelease];
+ [[NSColor whiteColor] set];
+ const float radius = 0.5 * ([self isHorizontal] ? NSHeight( slotRect ) : NSWidth( slotRect ));
+ NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: slotRect
+ xRadius: radius
+ yRadius: radius];
+ [gradient drawInBezierPath: path angle: [self isHorizontal] ? 90 : 0];
+
+ [path stroke];
}
-- (NSUsableScrollerParts) usableParts;
+- (NSUsableScrollerParts) usableParts
{
- return NSScrollerKnob|NSScrollerKnobSlot;
+ return NSScrollerKnob | NSScrollerKnobSlot;
}
-- (void) drawKnob;
+- (void) drawKnob
{
- NSRect rect = NSInsetRect( [self rectForPart: NSScrollerKnob], 2, 2 );
-
- rect = [self convertRectToBase: rect];
- rect.origin.x = floor( rect.origin.x ) + 0.5;
- rect.origin.y = floor( rect.origin.y ) + 0.5;
- rect.size.width = floor( rect.size.width );
- rect.size.height = floor( rect.size.height );
- rect = [self convertRectFromBase: rect];
-
- [[NSColor colorWithDeviceWhite: 1.0 alpha: drawTrack ? 1.0 : 0.6] set];
-
- const float radius = 0.5 * ([self isHorizontal] ? NSHeight( rect ) : NSWidth( rect ));
- NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: rect
- xRadius: radius
- yRadius: radius];
- [path fill];
- [path stroke];
+ NSRect rect = NSInsetRect( [self rectForPart: NSScrollerKnob], 2, 2 );
+
+ rect = [self convertRectToBase: rect];
+ rect.origin.x = floor( rect.origin.x ) + 0.5;
+ rect.origin.y = floor( rect.origin.y ) + 0.5;
+ rect.size.width = floor( rect.size.width );
+ rect.size.height = floor( rect.size.height );
+ rect = [self convertRectFromBase: rect];
+
+ [[NSColor colorWithDeviceWhite: 1.0 alpha: drawTrack ? 1.0 : 0.6] set];
+
+ const float radius = 0.5 * ([self isHorizontal] ? NSHeight( rect ) : NSWidth( rect ));
+ NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: rect
+ xRadius: radius
+ yRadius: radius];
+ [path fill];
+ [path stroke];
}
-- (NSRect) rectForPart: (NSScrollerPart)partCode;
+- (NSRect) rectForPart: (NSScrollerPart)partCode
{
- const bool horizontal = [self isHorizontal];
-
- NSRect rect = horizontal ? NSInsetRect( [self bounds], 4, 0 ) : NSInsetRect( [self bounds], 0, 4 );
-
- switch (partCode) {
- case NSScrollerKnobSlot:
- return rect;
-
- case NSScrollerKnob: {
- const CGFloat len = horizontal ? NSWidth( rect ) : NSHeight( rect );
- CGFloat knobLen = [self knobProportion] * len;
- const CGFloat minKnobLen = horizontal ? NSHeight( rect ) : NSWidth( rect );
- if (knobLen < minKnobLen) knobLen = minKnobLen;
-
- const CGFloat start = [self doubleValue] * (len - knobLen);
-
- if (horizontal) {
- rect.origin.x += start;
- rect.size.width = knobLen;
- } else {
- rect.origin.y += start;
- rect.size.height = knobLen;
- }
-
- return rect;
- }
-
- default:
- return [super rectForPart: partCode];
- }
+ const bool horizontal = [self isHorizontal];
+
+ NSRect rect = horizontal ? NSInsetRect( [self bounds], 4, 0 ) : NSInsetRect( [self bounds], 0, 4 );
+
+ switch (partCode) {
+ case NSScrollerKnobSlot:
+ return rect;
+
+ case NSScrollerKnob: {
+ const CGFloat len = horizontal ? NSWidth( rect ) : NSHeight( rect );
+ CGFloat knobLen = [self knobProportion] * len;
+ const CGFloat minKnobLen = horizontal ? NSHeight( rect ) : NSWidth( rect );
+ if (knobLen < minKnobLen) knobLen = minKnobLen;
+
+ const CGFloat start = [self doubleValue] * (len - knobLen);
+
+ if (horizontal) {
+ rect.origin.x += start;
+ rect.size.width = knobLen;
+ } else {
+ rect.origin.y += start;
+ rect.size.height = knobLen;
+ }
+
+ return rect;
+ }
+
+ default:
+ return [super rectForPart: partCode];
+ }
}
-- (BOOL) isOpaque;
+- (BOOL) isOpaque
{
- return NO;
+ return NO;
}
-- (BOOL) isHorizontal;
+- (BOOL) isHorizontal
{
- NSRect bounds = [self bounds];
- return NSWidth( bounds ) > NSHeight( bounds );
+ NSRect bounds = [self bounds];
+ return NSWidth( bounds ) > NSHeight( bounds );
}
-- (void) mouseEntered: (NSEvent *)theEvent;
+- (void) mouseEntered: (NSEvent *)theEvent
{
- drawTrack = YES;
- [self setNeedsDisplay: YES];
+ drawTrack = YES;
+ [self setNeedsDisplay: YES];
}
-- (void) mouseExited: (NSEvent *)theEvent;
+- (void) mouseExited: (NSEvent *)theEvent
{
- drawTrack = NO;
- [self setNeedsDisplay: YES];
+ drawTrack = NO;
+ [self setNeedsDisplay: YES];
}
@end
diff --git a/cocoa/BookmarksController.m b/cocoa/BookmarksController.m
index aba50a8a3..4b15d3740 100644
--- a/cocoa/BookmarksController.m
+++ b/cocoa/BookmarksController.m
@@ -42,172 +42,181 @@
static const char *cocoa_hotlist_path( void )
{
- NSString *path = [[NSUserDefaults standardUserDefaults] stringForKey: kHotlistFileOption];
- return [path UTF8String];
+ NSString *path = [[NSUserDefaults standardUserDefaults]
+ stringForKey: kHotlistFileOption];
+ return [path UTF8String];
}
-- init;
+- (id)init
{
- if ((self = [super initWithWindowNibName: @"BookmarksWindow"]) == nil) return nil;
- tree_hotlist_path = cocoa_hotlist_path();
- tree = [[Tree alloc] initWithFlags: TREE_HOTLIST];
- nodeForMenu = NSCreateMapTable( NSNonOwnedPointerMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0 );
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector( noteAppWillTerminate: )
- name:NSApplicationWillTerminateNotification
- object:NSApp];
-
- return self;
+ if ((self = [super initWithWindowNibName: @"BookmarksWindow"]) == nil) {
+ return nil;
+ }
+ tree_hotlist_path = cocoa_hotlist_path();
+ tree = [[Tree alloc] initWithFlags: TREE_HOTLIST];
+ nodeForMenu = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
+ NSNonOwnedPointerMapValueCallBacks,
+ 0);
+
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(noteAppWillTerminate:)
+ name:NSApplicationWillTerminateNotification
+ object:NSApp];
+
+ return self;
}
-- (void) noteAppWillTerminate: (NSNotification *) note;
+- (void) noteAppWillTerminate: (NSNotification *)note
{
- [self save];
+ [self save];
}
-- (void) save;
+- (void) save
{
- hotlist_export( cocoa_hotlist_path(), NULL );
+ hotlist_export( cocoa_hotlist_path(), NULL );
}
-- (void) dealloc;
+- (void) dealloc
{
- [self setView: nil];
- NSFreeMapTable( nodeForMenu );
- [tree release];
-
- [[NSNotificationCenter defaultCenter] removeObserver: self];
-
- [super dealloc];
+ [self setView: nil];
+ NSFreeMapTable( nodeForMenu );
+ [tree release];
+
+ [[NSNotificationCenter defaultCenter] removeObserver: self];
+
+ [super dealloc];
}
- (void) menuNeedsUpdate: (NSMenu *)menu
{
#if 0
- for (NSMenuItem *item in [menu itemArray]) {
- if ([item hasSubmenu]) NSMapRemove( nodeForMenu, [item submenu] );
- [menu removeItem: item];
- }
-
- bool hasSeparator = true;
- struct node *node = (struct node *)NSMapGet( nodeForMenu, menu );
- if (node == NULL) {
- for (NSMenuItem *item in [defaultMenu itemArray]) {
- [menu addItem: [[item copy] autorelease]];
- }
- hasSeparator = false;
- }
-
- for (struct node *child = tree_node_get_child( node );
- child != NULL;
- child = tree_node_get_next( child )) {
-
- if (tree_node_is_deleted( child )) continue;
-
- if (!hasSeparator) {
- [menu addItem: [NSMenuItem separatorItem]];
- hasSeparator = true;
- }
-
- NSString *title = [NSString stringWithUTF8String: tree_url_node_get_title( child )];
-
- NSMenuItem *item = [menu addItemWithTitle: title action: NULL keyEquivalent: @""];
- if (tree_node_is_folder( child )) {
- NSMenu *subMenu = [[[NSMenu alloc] initWithTitle: title] autorelease];
- NSMapInsert( nodeForMenu, subMenu, child );
- [subMenu setDelegate: self];
- [menu setSubmenu: subMenu forItem: item];
- } else {
- [item setRepresentedObject: [NSString stringWithUTF8String: tree_url_node_get_url( child )]];
- [item setTarget: self];
- [item setAction: @selector( openBookmarkURL: )];
- }
- }
+ for (NSMenuItem *item in [menu itemArray]) {
+ if ([item hasSubmenu]) NSMapRemove( nodeForMenu, [item submenu] );
+ [menu removeItem: item];
+ }
+
+ bool hasSeparator = true;
+ struct node *node = (struct node *)NSMapGet( nodeForMenu, menu );
+ if (node == NULL) {
+ for (NSMenuItem *item in [defaultMenu itemArray]) {
+ [menu addItem: [[item copy] autorelease]];
+ }
+ hasSeparator = false;
+ }
+
+ for (struct node *child = tree_node_get_child( node );
+ child != NULL;
+ child = tree_node_get_next( child )) {
+
+ if (tree_node_is_deleted( child )) continue;
+
+ if (!hasSeparator) {
+ [menu addItem: [NSMenuItem separatorItem]];
+ hasSeparator = true;
+ }
+
+ NSString *title = [NSString stringWithUTF8String: tree_url_node_get_title( child )];
+
+ NSMenuItem *item = [menu addItemWithTitle: title action: NULL keyEquivalent: @""];
+ if (tree_node_is_folder( child )) {
+ NSMenu *subMenu = [[[NSMenu alloc] initWithTitle: title] autorelease];
+ NSMapInsert( nodeForMenu, subMenu, child );
+ [subMenu setDelegate: self];
+ [menu setSubmenu: subMenu forItem: item];
+ } else {
+ [item setRepresentedObject: [NSString stringWithUTF8String: tree_url_node_get_url( child )]];
+ [item setTarget: self];
+ [item setAction: @selector( openBookmarkURL: )];
+ }
+ }
#endif
}
-- (IBAction) openBookmarkURL: (id) sender;
+- (IBAction) openBookmarkURL: (id)sender
{
- const char *urltxt = [[sender representedObject] UTF8String];
- NSParameterAssert( urltxt != NULL );
+ const char *urltxt = [[sender representedObject] UTF8String];
+ NSParameterAssert( urltxt != NULL );
- nsurl *url;
- nserror error;
+ nsurl *url;
+ nserror error;
- error = nsurl_create(urltxt, &url);
- if (error == NSERROR_OK) {
+ error = nsurl_create(urltxt, &url);
+ if (error == NSERROR_OK) {
BrowserViewController *tab = [(NetSurfApp *)NSApp frontTab];
if (tab != nil) {
error = browser_window_navigate([tab browser],
- url,
- NULL,
- BW_NAVIGATE_HISTORY,
- NULL,
- NULL,
- NULL);
+ url,
+ NULL,
+ BW_NAVIGATE_HISTORY,
+ NULL,
+ NULL,
+ NULL);
} else {
error = browser_window_create(BW_CREATE_HISTORY,
- url,
- NULL,
- NULL,
- NULL);
+ url,
+ NULL,
+ NULL,
+ NULL);
}
nsurl_unref(url);
- }
- if (error != NSERROR_OK) {
- warn_user(messages_get_errorcode(error), 0);
- }
+ }
+ if (error != NSERROR_OK) {
+ warn_user(messages_get_errorcode(error), 0);
+ }
}
-- (IBAction) addBookmark: (id) sender;
+- (IBAction) addBookmark: (id)sender
{
- struct browser_window *bw = [[(NetSurfApp *)NSApp frontTab] browser];
- if (bw != NULL) {
- hotlist_add_url(browser_window_get_url(bw));
- }
+ struct browser_window *bw = [[(NetSurfApp *)NSApp frontTab] browser];
+ if (bw != NULL) {
+ hotlist_add_url(browser_window_get_url(bw));
+ }
}
-- (BOOL) validateUserInterfaceItem: (id) item;
+- (BOOL) validateUserInterfaceItem: (id)item
{
- SEL action = [item action];
-
- if (action == @selector( addBookmark: )) {
- return [(NetSurfApp *)NSApp frontTab] != nil;
- }
-
- return YES;
+ SEL action = [item action];
+
+ if (action == @selector( addBookmark: )) {
+ return [(NetSurfApp *)NSApp frontTab] != nil;
+ }
+
+ return YES;
}
-- (void) windowDidLoad;
+- (void) windowDidLoad
{
- hotlist_expand(false);
- hotlist_contract(true);
-
- [view setTree: tree];
+ hotlist_expand(false);
+ hotlist_contract(true);
+
+ [view setTree: tree];
}
-+ (void) initialize;
++ (void) initialize
{
- [[NSUserDefaults standardUserDefaults] registerDefaults: [NSDictionary dictionaryWithObjectsAndKeys:
- cocoa_get_user_path( @"Bookmarks.html" ), kHotlistFileOption,
- nil]];
+ [[NSUserDefaults standardUserDefaults]
+ registerDefaults:
+ [NSDictionary
+ dictionaryWithObjectsAndKeys:cocoa_get_user_path( @"Bookmarks.html" ),
+ kHotlistFileOption,
+ nil]];
}
-- (IBAction) editSelected: (id) sender;
+- (IBAction) editSelected: (id)sender
{
- hotlist_edit_selection();
+ hotlist_edit_selection();
}
-- (IBAction) deleteSelected: (id) sender;
+- (IBAction) deleteSelected: (id)sender
{
- hotlist_keypress(NS_KEY_DELETE_LEFT);
+ hotlist_keypress(NS_KEY_DELETE_LEFT);
}
-- (IBAction) addFolder: (id) sender;
+- (IBAction) addFolder: (id)sender
{
- hotlist_add_folder(NULL, false, 0);
+ hotlist_add_folder(NULL, false, 0);
}
@end
diff --git a/cocoa/BrowserView.m b/cocoa/BrowserView.m
index c9f70cd67..ceb21ef0c 100644
--- a/cocoa/BrowserView.m
+++ b/cocoa/BrowserView.m
@@ -60,539 +60,562 @@
static const CGFloat CaretWidth = 1.0;
static const NSTimeInterval CaretBlinkTime = 0.8;
-- initWithFrame: (NSRect) frame;
+- initWithFrame: (NSRect) frame
{
- if ((self = [super initWithFrame: frame]) == nil) return nil;
-
- [self registerForDraggedTypes: [NSArray arrayWithObjects: NSURLPboardType, @"public.url", nil]];
-
- return self;
+ if ((self = [super initWithFrame: frame]) == nil) {
+ return nil;
+ }
+
+ [self registerForDraggedTypes: [NSArray arrayWithObjects: NSURLPboardType, @"public.url", nil]];
+
+ return self;
}
-- (void) dealloc;
+- (void) dealloc
{
- [self setCaretTimer: nil];
- [self setMarkedText: nil];
- [history release];
-
- [super dealloc];
+ [self setCaretTimer: nil];
+ [self setMarkedText: nil];
+ [history release];
+
+ [super dealloc];
}
-- (void) setCaretTimer: (NSTimer *)newTimer;
+- (void) setCaretTimer: (NSTimer *)newTimer
{
- if (newTimer != caretTimer) {
- [caretTimer invalidate];
- [caretTimer release];
- caretTimer = [newTimer retain];
- }
+ if (newTimer != caretTimer) {
+ [caretTimer invalidate];
+ [caretTimer release];
+ caretTimer = [newTimer retain];
+ }
}
-- (void) updateHistory;
+- (void) updateHistory
{
- [history redraw];
+ [history redraw];
}
static inline NSRect cocoa_get_caret_rect( BrowserView *view )
{
float bscale = browser_window_get_scale(view->browser);
- NSRect caretRect = {
- .origin = NSMakePoint( view->caretPoint.x * bscale, view->caretPoint.y * bscale ),
- .size = NSMakeSize( CaretWidth, view->caretHeight * bscale )
- };
-
- return caretRect;
+ NSRect caretRect = {
+ .origin = NSMakePoint( view->caretPoint.x * bscale, view->caretPoint.y * bscale ),
+ .size = NSMakeSize( CaretWidth, view->caretHeight * bscale )
+ };
+
+ return caretRect;
}
-- (void) removeCaret;
+- (void) removeCaret
{
- hasCaret = NO;
- [self setNeedsDisplayInRect: cocoa_get_caret_rect( self )];
+ hasCaret = NO;
+ [self setNeedsDisplayInRect: cocoa_get_caret_rect( self )];
- [self setCaretTimer: nil];
+ [self setCaretTimer: nil];
}
-- (void) addCaretAt: (NSPoint) point height: (CGFloat) height;
+- (void) addCaretAt: (NSPoint) point height: (CGFloat) height
{
- if (hasCaret) {
- [self setNeedsDisplayInRect: cocoa_get_caret_rect( self )];
- }
-
- caretPoint = point;
- caretHeight = height;
- hasCaret = YES;
- caretVisible = YES;
-
- if (nil == caretTimer) {
- [self setCaretTimer: [NSTimer scheduledTimerWithTimeInterval: CaretBlinkTime target: self selector: @selector(caretBlink:) userInfo: nil repeats: YES]];
- } else {
- [caretTimer setFireDate: [NSDate dateWithTimeIntervalSinceNow: CaretBlinkTime]];
- }
-
- [self setNeedsDisplayInRect: cocoa_get_caret_rect( self )];
+ if (hasCaret) {
+ [self setNeedsDisplayInRect: cocoa_get_caret_rect( self )];
+ }
+
+ caretPoint = point;
+ caretHeight = height;
+ hasCaret = YES;
+ caretVisible = YES;
+
+ if (nil == caretTimer) {
+ [self setCaretTimer: [NSTimer scheduledTimerWithTimeInterval: CaretBlinkTime target: self selector: @selector(caretBlink:) userInfo: nil repeats: YES]];
+ } else {
+ [caretTimer setFireDate: [NSDate dateWithTimeIntervalSinceNow: CaretBlinkTime]];
+ }
+
+ [self setNeedsDisplayInRect: cocoa_get_caret_rect( self )];
}
-
-
-- (void) caretBlink: (NSTimer *)timer;
+
+
+- (void) caretBlink: (NSTimer *)timer
{
- if (hasCaret) {
- caretVisible = !caretVisible;
- [self setNeedsDisplayInRect: cocoa_get_caret_rect( self )];
- }
+ if (hasCaret) {
+ caretVisible = !caretVisible;
+ [self setNeedsDisplayInRect: cocoa_get_caret_rect( self )];
+ }
}
-- (void)drawRect:(NSRect)dirtyRect;
+- (void)drawRect:(NSRect)dirtyRect
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &cocoa_plotters
+ };
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = &cocoa_plotters
- };
-
- const NSRect *rects = NULL;
- NSInteger count = 0;
- [self getRectsBeingDrawn: &rects count: &count];
-
- for (NSInteger i = 0; i < count; i++) {
- const struct rect clip = {
- .x0 = cocoa_pt_to_px( NSMinX( rects[i] ) ),
- .y0 = cocoa_pt_to_px( NSMinY( rects[i] ) ),
- .x1 = cocoa_pt_to_px( NSMaxX( rects[i] ) ),
- .y1 = cocoa_pt_to_px( NSMaxY( rects[i] ) )
- };
+ const NSRect *rects = NULL;
+ NSInteger count = 0;
+ [self getRectsBeingDrawn: &rects count: &count];
- browser_window_redraw(browser, 0, 0, &clip, &ctx);
- }
+ for (NSInteger i = 0; i < count; i++) {
+ const struct rect clip = {
+ .x0 = cocoa_pt_to_px( NSMinX( rects[i] ) ),
+ .y0 = cocoa_pt_to_px( NSMinY( rects[i] ) ),
+ .x1 = cocoa_pt_to_px( NSMaxX( rects[i] ) ),
+ .y1 = cocoa_pt_to_px( NSMaxY( rects[i] ) )
+ };
- NSRect caretRect = cocoa_get_caret_rect( self );
- if (hasCaret && caretVisible && [self needsToDrawRect: caretRect]) {
- [[NSColor blackColor] set];
- [NSBezierPath fillRect: caretRect];
- }
-
- [pool release];
+ browser_window_redraw(browser, 0, 0, &clip, &ctx);
+ }
+
+ NSRect caretRect = cocoa_get_caret_rect( self );
+ if (hasCaret && caretVisible && [self needsToDrawRect: caretRect]) {
+ [[NSColor blackColor] set];
+ [NSBezierPath fillRect: caretRect];
+ }
+
+ [pool release];
}
-- (BOOL) isFlipped;
+- (BOOL) isFlipped
{
- return YES;
+ return YES;
}
-- (void) viewDidMoveToWindow;
+- (void) viewDidMoveToWindow
{
- NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect: [self visibleRect]
- options: NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect
- owner: self
- userInfo: nil];
- [self addTrackingArea: area];
- [area release];
+ NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect: [self visibleRect]
+ options: NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect
+ owner: self
+ userInfo: nil];
+ [self addTrackingArea: area];
+ [area release];
}
static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt )
{
- browser_mouse_state result = 0;
- NSUInteger flags = [evt modifierFlags];
-
- if (flags & NSShiftKeyMask) result |= BROWSER_MOUSE_MOD_1;
- if (flags & NSAlternateKeyMask) result |= BROWSER_MOUSE_MOD_2;
-
- return result;
+ browser_mouse_state result = 0;
+ NSUInteger flags = [evt modifierFlags];
+
+ if (flags & NSShiftKeyMask) result |= BROWSER_MOUSE_MOD_1;
+ if (flags & NSAlternateKeyMask) result |= BROWSER_MOUSE_MOD_2;
+
+ return result;
}
-- (NSPoint) convertMousePoint: (NSEvent *)event;
+- (NSPoint) convertMousePoint: (NSEvent *)event
{
- NSPoint location = [self convertPoint: [event locationInWindow] fromView: nil];
+ NSPoint location = [self convertPoint: [event locationInWindow] fromView: nil];
float bscale = browser_window_get_scale(browser);
location.x /= bscale;
location.y /= bscale;
- location.x = cocoa_pt_to_px( location.x );
- location.y = cocoa_pt_to_px( location.y );
- return location;
+ location.x = cocoa_pt_to_px( location.x );
+ location.y = cocoa_pt_to_px( location.y );
+ return location;
}
-- (void) mouseDown: (NSEvent *)theEvent;
+- (void) mouseDown: (NSEvent *)theEvent
{
- if ([theEvent modifierFlags] & NSControlKeyMask) {
- [self popUpContextMenuForEvent: theEvent];
- return;
- }
-
- dragStart = [self convertMousePoint: theEvent];
+ if ([theEvent modifierFlags] & NSControlKeyMask) {
+ [self popUpContextMenuForEvent: theEvent];
+ return;
+ }
- browser_window_mouse_click( browser, BROWSER_MOUSE_PRESS_1 | cocoa_mouse_flags_for_event( theEvent ), dragStart.x, dragStart.y );
+ dragStart = [self convertMousePoint: theEvent];
+
+ browser_window_mouse_click(browser,
+ BROWSER_MOUSE_PRESS_1 | cocoa_mouse_flags_for_event( theEvent ),
+ dragStart.x,
+ dragStart.y );
}
-- (void) rightMouseDown: (NSEvent *)theEvent;
+- (void) rightMouseDown: (NSEvent *)theEvent
{
- [self popUpContextMenuForEvent: theEvent];
+ [self popUpContextMenuForEvent: theEvent];
}
-- (void) mouseUp: (NSEvent *)theEvent;
+- (void) mouseUp: (NSEvent *)theEvent
{
- if (historyVisible) {
- [self setHistoryVisible: NO];
- return;
- }
-
- NSPoint location = [self convertMousePoint: theEvent];
+ if (historyVisible) {
+ [self setHistoryVisible: NO];
+ return;
+ }
- browser_mouse_state modifierFlags = cocoa_mouse_flags_for_event( theEvent );
-
- if (isDragging) {
- isDragging = NO;
- browser_window_mouse_track( browser, (browser_mouse_state)0, location.x, location.y );
- } else {
- modifierFlags |= BROWSER_MOUSE_CLICK_1;
- if ([theEvent clickCount] == 2) modifierFlags |= BROWSER_MOUSE_DOUBLE_CLICK;
- browser_window_mouse_click( browser, modifierFlags, location.x, location.y );
- }
+ NSPoint location = [self convertMousePoint: theEvent];
+
+ browser_mouse_state modifierFlags = cocoa_mouse_flags_for_event( theEvent );
+
+ if (isDragging) {
+ isDragging = NO;
+ browser_window_mouse_track( browser, (browser_mouse_state)0, location.x, location.y );
+ } else {
+ modifierFlags |= BROWSER_MOUSE_CLICK_1;
+ if ([theEvent clickCount] == 2) modifierFlags |= BROWSER_MOUSE_DOUBLE_CLICK;
+ browser_window_mouse_click( browser, modifierFlags, location.x, location.y );
+ }
}
#define squared(x) ((x)*(x))
#define MinDragDistance (5.0)
-- (void) mouseDragged: (NSEvent *)theEvent;
+- (void) mouseDragged: (NSEvent *)theEvent
{
- NSPoint location = [self convertMousePoint: theEvent];
- browser_mouse_state modifierFlags = cocoa_mouse_flags_for_event( theEvent );
+ NSPoint location = [self convertMousePoint: theEvent];
+ browser_mouse_state modifierFlags = cocoa_mouse_flags_for_event( theEvent );
- if (!isDragging) {
- const CGFloat distance = squared( dragStart.x - location.x ) + squared( dragStart.y - location.y );
+ if (!isDragging) {
+ const CGFloat distance = squared( dragStart.x - location.x ) + squared( dragStart.y - location.y );
+
+ if (distance >= squared( MinDragDistance)) {
+ isDragging = YES;
+ browser_window_mouse_click(browser,
+ BROWSER_MOUSE_DRAG_1 | modifierFlags,
+ dragStart.x,
+ dragStart.y);
+ }
+ }
- if (distance >= squared( MinDragDistance)) {
- isDragging = YES;
- browser_window_mouse_click( browser, BROWSER_MOUSE_DRAG_1 | modifierFlags, dragStart.x, dragStart.y );
- }
- }
-
- if (isDragging) {
- browser_window_mouse_track( browser, BROWSER_MOUSE_HOLDING_1 | BROWSER_MOUSE_DRAG_ON | modifierFlags, location.x, location.y );
- }
+ if (isDragging) {
+ browser_window_mouse_track(browser,
+ BROWSER_MOUSE_HOLDING_1 | BROWSER_MOUSE_DRAG_ON | modifierFlags,
+ location.x,
+ location.y );
+ }
}
-- (void) mouseMoved: (NSEvent *)theEvent;
+- (void) mouseMoved: (NSEvent *)theEvent
{
- if (historyVisible) return;
-
- NSPoint location = [self convertMousePoint: theEvent];
+ if (historyVisible) return;
+
+ NSPoint location = [self convertMousePoint: theEvent];
- browser_window_mouse_track( browser, cocoa_mouse_flags_for_event( theEvent ), location.x, location.y );
+ browser_window_mouse_track(browser,
+ cocoa_mouse_flags_for_event(theEvent),
+ location.x,
+ location.y);
}
-- (void) mouseExited: (NSEvent *) theEvent;
+- (void) mouseExited: (NSEvent *) theEvent
{
- [[NSCursor arrowCursor] set];
+ [[NSCursor arrowCursor] set];
}
-- (void) keyDown: (NSEvent *)theEvent;
+- (void) keyDown: (NSEvent *)theEvent
{
- if (!historyVisible) {
- [self interpretKeyEvents: [NSArray arrayWithObject: theEvent]];
- } else {
- [history keyDown: theEvent];
- }
+ if (!historyVisible) {
+ [self interpretKeyEvents: [NSArray arrayWithObject: theEvent]];
+ } else {
+ [history keyDown: theEvent];
+ }
}
-- (void) insertText: (id)string;
+- (void) insertText: (id)string
{
- for (NSUInteger i = 0, length = [string length]; i < length; i++) {
- unichar ch = [string characterAtIndex: i];
- if (!browser_window_key_press( browser, ch )) {
- if (ch == ' ') [self scrollPageDown: self];
- break;
- }
- }
- [self setMarkedText: nil];
+ for (NSUInteger i = 0, length = [string length]; i < length; i++) {
+ unichar ch = [string characterAtIndex: i];
+ if (!browser_window_key_press( browser, ch )) {
+ if (ch == ' ') [self scrollPageDown: self];
+ break;
+ }
+ }
+ [self setMarkedText: nil];
}
-- (void) moveLeft: (id)sender;
+- (void) moveLeft: (id)sender
{
- if (browser_window_key_press( browser, NS_KEY_LEFT )) return;
- [self scrollHorizontal: -[[self enclosingScrollView] horizontalLineScroll]];
+ if (browser_window_key_press( browser, NS_KEY_LEFT )) return;
+ [self scrollHorizontal: -[[self enclosingScrollView] horizontalLineScroll]];
}
-- (void) moveRight: (id)sender;
+- (void) moveRight: (id)sender
{
- if (browser_window_key_press( browser, NS_KEY_RIGHT )) return;
- [self scrollHorizontal: [[self enclosingScrollView] horizontalLineScroll]];
+ if (browser_window_key_press( browser, NS_KEY_RIGHT )) return;
+ [self scrollHorizontal: [[self enclosingScrollView] horizontalLineScroll]];
}
-- (void) moveUp: (id)sender;
+- (void) moveUp: (id)sender
{
- if (browser_window_key_press( browser, NS_KEY_UP )) return;
- [self scrollVertical: -[[self enclosingScrollView] lineScroll]];
+ if (browser_window_key_press( browser, NS_KEY_UP )) return;
+ [self scrollVertical: -[[self enclosingScrollView] lineScroll]];
}
-- (void) moveDown: (id)sender;
+- (void) moveDown: (id)sender
{
- if (browser_window_key_press( browser, NS_KEY_DOWN )) return;
- [self scrollVertical: [[self enclosingScrollView] lineScroll]];
+ if (browser_window_key_press( browser, NS_KEY_DOWN )) return;
+ [self scrollVertical: [[self enclosingScrollView] lineScroll]];
}
-- (void) deleteBackward: (id)sender;
+- (void) deleteBackward: (id)sender
{
- if (!browser_window_key_press( browser, NS_KEY_DELETE_LEFT )) {
- [NSApp sendAction: @selector( goBack: ) to: nil from: self];
- }
+ if (!browser_window_key_press( browser, NS_KEY_DELETE_LEFT )) {
+ [NSApp sendAction: @selector( goBack: ) to: nil from: self];
+ }
}
-- (void) deleteForward: (id)sender;
+- (void) deleteForward: (id)sender
{
- browser_window_key_press( browser, NS_KEY_DELETE_RIGHT );
+ browser_window_key_press( browser, NS_KEY_DELETE_RIGHT );
}
-- (void) cancelOperation: (id)sender;
+- (void) cancelOperation: (id)sender
{
- browser_window_key_press( browser, NS_KEY_ESCAPE );
+ browser_window_key_press( browser, NS_KEY_ESCAPE );
}
-- (void) scrollPageUp: (id)sender;
+- (void) scrollPageUp: (id)sender
{
- if (browser_window_key_press( browser, NS_KEY_PAGE_UP )) return;
- [self scrollVertical: -[self pageScroll]];
+ if (browser_window_key_press( browser, NS_KEY_PAGE_UP )) {
+ return;
+ }
+ [self scrollVertical: -[self pageScroll]];
}
-- (void) scrollPageDown: (id)sender;
+- (void) scrollPageDown: (id)sender
{
- if (browser_window_key_press( browser, NS_KEY_PAGE_DOWN )) return;
- [self scrollVertical: [self pageScroll]];
+ if (browser_window_key_press( browser, NS_KEY_PAGE_DOWN )) {
+ return;
+ }
+ [self scrollVertical: [self pageScroll]];
}
-- (void) insertTab: (id)sender;
+- (void) insertTab: (id)sender
{
- browser_window_key_press( browser, NS_KEY_TAB );
+ browser_window_key_press( browser, NS_KEY_TAB );
}
-- (void) insertBacktab: (id)sender;
+- (void) insertBacktab: (id)sender
{
- browser_window_key_press( browser, NS_KEY_SHIFT_TAB );
+ browser_window_key_press( browser, NS_KEY_SHIFT_TAB );
}
-- (void) moveToBeginningOfLine: (id)sender;
+- (void) moveToBeginningOfLine: (id)sender
{
- browser_window_key_press( browser, NS_KEY_LINE_START );
+ browser_window_key_press( browser, NS_KEY_LINE_START );
}
-- (void) moveToEndOfLine: (id)sender;
+- (void) moveToEndOfLine: (id)sender
{
- browser_window_key_press( browser, NS_KEY_LINE_END );
+ browser_window_key_press( browser, NS_KEY_LINE_END );
}
-- (void) moveToBeginningOfDocument: (id)sender;
+- (void) moveToBeginningOfDocument: (id)sender
{
- if (browser_window_key_press( browser, NS_KEY_TEXT_START )) return;
+ if (browser_window_key_press( browser, NS_KEY_TEXT_START )) return;
}
-- (void) scrollToBeginningOfDocument: (id) sender;
+- (void) scrollToBeginningOfDocument: (id) sender
{
- NSPoint origin = [self visibleRect].origin;
- origin.y = 0;
- [self scrollPoint: origin];
+ NSPoint origin = [self visibleRect].origin;
+ origin.y = 0;
+ [self scrollPoint: origin];
}
-- (void) moveToEndOfDocument: (id)sender;
+- (void) moveToEndOfDocument: (id)sender
{
- browser_window_key_press( browser, NS_KEY_TEXT_END );
+ browser_window_key_press( browser, NS_KEY_TEXT_END );
}
-- (void) scrollToEndOfDocument: (id) sender;
+- (void) scrollToEndOfDocument: (id) sender
{
- NSPoint origin = [self visibleRect].origin;
- origin.y = NSHeight( [self frame] );
- [self scrollPoint: origin];
+ NSPoint origin = [self visibleRect].origin;
+ origin.y = NSHeight( [self frame] );
+ [self scrollPoint: origin];
}
-- (void) insertNewline: (id)sender;
+- (void) insertNewline: (id)sender
{
- browser_window_key_press( browser, NS_KEY_NL );
+ browser_window_key_press( browser, NS_KEY_NL );
}
-- (void) selectAll: (id)sender;
+- (void) selectAll: (id)sender
{
- browser_window_key_press( browser, NS_KEY_SELECT_ALL );
+ browser_window_key_press( browser, NS_KEY_SELECT_ALL );
}
-- (void) copy: (id) sender;
+- (void) copy: (id)sender
{
- browser_window_key_press( browser, NS_KEY_COPY_SELECTION );
+ browser_window_key_press( browser, NS_KEY_COPY_SELECTION );
}
-- (void) cut: (id) sender;
+- (void) cut: (id)sender
{
- browser_window_key_press( browser, NS_KEY_CUT_SELECTION );
+ browser_window_key_press( browser, NS_KEY_CUT_SELECTION );
}
-- (void) paste: (id) sender;
+- (void) paste: (id)sender
{
- browser_window_key_press( browser, NS_KEY_PASTE );
+ browser_window_key_press( browser, NS_KEY_PASTE );
}
-- (BOOL) acceptsFirstResponder;
+- (BOOL) acceptsFirstResponder
{
- return YES;
+ return YES;
}
-- (void) adjustFrame;
+- (void) adjustFrame
{
browser_window_schedule_reformat(browser);
-
- [super adjustFrame];
+
+ [super adjustFrame];
}
-- (BOOL) isHistoryVisible;
+- (BOOL) isHistoryVisible
{
- return historyVisible;
+ return historyVisible;
}
-- (void) setHistoryVisible: (BOOL) newVisible;
+- (void) setHistoryVisible: (BOOL)newVisible
{
- if (newVisible == historyVisible) return;
- historyVisible = newVisible;
-
- if (historyVisible) {
- if (nil == history) history = [[LocalHistoryController alloc] initWithBrowser: self];
- [history attachToView: [(BrowserWindowController *)[[self window] windowController] historyButton]];
- } else {
- [history detach];
- }
+ if (newVisible == historyVisible) return;
+ historyVisible = newVisible;
+
+ if (historyVisible) {
+ if (nil == history) {
+ history = [[LocalHistoryController alloc] initWithBrowser: self];
+ }
+ [history attachToView: [(BrowserWindowController *)[[self window] windowController] historyButton]];
+ } else {
+ [history detach];
+ }
}
-- (void) scrollHorizontal: (CGFloat) amount;
+- (void) scrollHorizontal: (CGFloat) amount
{
- NSPoint currentPoint = [self visibleRect].origin;
- currentPoint.x += amount;
- [self scrollPoint: currentPoint];
+ NSPoint currentPoint = [self visibleRect].origin;
+ currentPoint.x += amount;
+ [self scrollPoint: currentPoint];
}
-- (void) scrollVertical: (CGFloat) amount;
+- (void) scrollVertical: (CGFloat) amount
{
- NSPoint currentPoint = [self visibleRect].origin;
- currentPoint.y += amount;
- [self scrollPoint: currentPoint];
+ NSPoint currentPoint = [self visibleRect].origin;
+ currentPoint.y += amount;
+ [self scrollPoint: currentPoint];
}
-- (CGFloat) pageScroll;
+- (CGFloat) pageScroll
{
- return NSHeight( [[self superview] frame] ) - [[self enclosingScrollView] pageScroll];
+ return NSHeight( [[self superview] frame] ) - [[self enclosingScrollView] pageScroll];
}
-- (void) reformat;
+- (void) reformat
{
- NSRect size = [[self superview] frame];
- browser_window_reformat( browser, false, cocoa_pt_to_px( NSWidth( size ) ), cocoa_pt_to_px( NSHeight( size ) ) );
+ NSRect size = [[self superview] frame];
+ browser_window_reformat(browser,
+ false,
+ cocoa_pt_to_px( NSWidth( size ) ),
+ cocoa_pt_to_px( NSHeight( size ) ) );
}
-- (void) popUpContextMenuForEvent: (NSEvent *) event;
+- (void) popUpContextMenuForEvent: (NSEvent *) event
{
- NSMenu *popupMenu = [[NSMenu alloc] initWithTitle: @""];
- NSPoint point = [self convertMousePoint: event];
-
- struct browser_window_features cont;
-
- browser_window_get_features(browser, point.x, point.y, &cont);
-
- if (cont.object != NULL) {
- NSString *imageURL = [NSString stringWithUTF8String: nsurl_access(hlcache_handle_get_url( cont.object ))];
-
- [[popupMenu addItemWithTitle: NSLocalizedString( @"Open image in new tab", @"Context menu" )
- action: @selector(cmOpenURLInTab:)
- keyEquivalent: @""] setRepresentedObject: imageURL];
- [[popupMenu addItemWithTitle: NSLocalizedString( @"Open image in new window", @"Context menu" )
- action: @selector(cmOpenURLInWindow:)
- keyEquivalent: @""] setRepresentedObject: imageURL];
- [[popupMenu addItemWithTitle: NSLocalizedString( @"Save image as", @"Context menu" )
- action: @selector(cmDownloadURL:)
- keyEquivalent: @""] setRepresentedObject: imageURL];
- [[popupMenu addItemWithTitle: NSLocalizedString( @"Copy image", @"Context menu" )
- action: @selector(cmImageCopy:)
- keyEquivalent: @""] setRepresentedObject: (id)content_get_bitmap( cont.object )];
-
- [popupMenu addItem: [NSMenuItem separatorItem]];
- }
-
- if (cont.link != NULL) {
- NSString *target = [NSString stringWithUTF8String: nsurl_access(cont.link)];
-
- [[popupMenu addItemWithTitle: NSLocalizedString( @"Open link in new tab", @"Context menu" )
- action: @selector(cmOpenURLInTab:)
- keyEquivalent: @""] setRepresentedObject: target];
- [[popupMenu addItemWithTitle: NSLocalizedString( @"Open link in new window", @"Context menu" )
- action: @selector(cmOpenURLInWindow:)
- keyEquivalent: @""] setRepresentedObject: target];
- [[popupMenu addItemWithTitle: NSLocalizedString( @"Save link target", @"Context menu" )
- action: @selector(cmDownloadURL:)
- keyEquivalent: @""] setRepresentedObject: target];
- [[popupMenu addItemWithTitle: NSLocalizedString( @"Copy link", @"Context menu" )
- action: @selector(cmLinkCopy:)
- keyEquivalent: @""] setRepresentedObject: target];
-
- [popupMenu addItem: [NSMenuItem separatorItem]];
- }
-
- [popupMenu addItemWithTitle: NSLocalizedString( @"Back", @"Context menu" )
- action: @selector(goBack:) keyEquivalent: @""];
- [popupMenu addItemWithTitle: NSLocalizedString( @"Reload", @"Context menu" )
- action: @selector(reloadPage:) keyEquivalent: @""];
- [popupMenu addItemWithTitle: NSLocalizedString( @"Forward", @"Context menu" )
- action: @selector(goForward:) keyEquivalent: @""];
- [popupMenu addItemWithTitle: NSLocalizedString( @"View Source", @"Context menu" )
- action: @selector(viewSource:) keyEquivalent: @""];
-
- [NSMenu popUpContextMenu: popupMenu withEvent: event forView: self];
-
- [popupMenu release];
+ NSMenu *popupMenu = [[NSMenu alloc] initWithTitle: @""];
+ NSPoint point = [self convertMousePoint: event];
+
+ struct browser_window_features cont;
+
+ browser_window_get_features(browser, point.x, point.y, &cont);
+
+ if (cont.object != NULL) {
+ NSString *imageURL = [NSString stringWithUTF8String: nsurl_access(hlcache_handle_get_url( cont.object ))];
+
+ [[popupMenu addItemWithTitle: NSLocalizedString( @"Open image in new tab", @"Context menu" )
+ action: @selector(cmOpenURLInTab:)
+ keyEquivalent: @""] setRepresentedObject: imageURL];
+ [[popupMenu addItemWithTitle: NSLocalizedString( @"Open image in new window", @"Context menu" )
+ action: @selector(cmOpenURLInWindow:)
+ keyEquivalent: @""] setRepresentedObject: imageURL];
+ [[popupMenu addItemWithTitle: NSLocalizedString( @"Save image as", @"Context menu" )
+ action: @selector(cmDownloadURL:)
+ keyEquivalent: @""] setRepresentedObject: imageURL];
+ [[popupMenu addItemWithTitle: NSLocalizedString( @"Copy image", @"Context menu" )
+ action: @selector(cmImageCopy:)
+ keyEquivalent: @""] setRepresentedObject: (id)content_get_bitmap( cont.object )];
+
+ [popupMenu addItem: [NSMenuItem separatorItem]];
+ }
+
+ if (cont.link != NULL) {
+ NSString *target = [NSString stringWithUTF8String: nsurl_access(cont.link)];
+
+ [[popupMenu addItemWithTitle: NSLocalizedString( @"Open link in new tab", @"Context menu" )
+ action: @selector(cmOpenURLInTab:)
+ keyEquivalent: @""] setRepresentedObject: target];
+ [[popupMenu addItemWithTitle: NSLocalizedString( @"Open link in new window", @"Context menu" )
+ action: @selector(cmOpenURLInWindow:)
+ keyEquivalent: @""] setRepresentedObject: target];
+ [[popupMenu addItemWithTitle: NSLocalizedString( @"Save link target", @"Context menu" )
+ action: @selector(cmDownloadURL:)
+ keyEquivalent: @""] setRepresentedObject: target];
+ [[popupMenu addItemWithTitle: NSLocalizedString( @"Copy link", @"Context menu" )
+ action: @selector(cmLinkCopy:)
+ keyEquivalent: @""] setRepresentedObject: target];
+
+ [popupMenu addItem: [NSMenuItem separatorItem]];
+ }
+
+ [popupMenu addItemWithTitle: NSLocalizedString( @"Back", @"Context menu" )
+ action: @selector(goBack:) keyEquivalent: @""];
+ [popupMenu addItemWithTitle: NSLocalizedString( @"Reload", @"Context menu" )
+ action: @selector(reloadPage:) keyEquivalent: @""];
+ [popupMenu addItemWithTitle: NSLocalizedString( @"Forward", @"Context menu" )
+ action: @selector(goForward:) keyEquivalent: @""];
+ [popupMenu addItemWithTitle: NSLocalizedString( @"View Source", @"Context menu" )
+ action: @selector(viewSource:) keyEquivalent: @""];
+
+ [NSMenu popUpContextMenu: popupMenu withEvent: event forView: self];
+
+ [popupMenu release];
}
-- (IBAction) cmOpenURLInTab: (id) sender;
+- (IBAction) cmOpenURLInTab: (id)sender
{
- nsurl *url;
- nserror error;
+ nsurl *url;
+ nserror error;
- error = nsurl_create([[sender representedObject] UTF8String], &url);
- if (error == NSERROR_OK) {
- error = browser_window_create(BW_CREATE_HISTORY |
+ error = nsurl_create([[sender representedObject] UTF8String], &url);
+ if (error == NSERROR_OK) {
+ error = browser_window_create(BW_CREATE_HISTORY |
BW_CREATE_TAB |
BW_CREATE_CLONE,
- url,
- NULL,
- browser,
- NULL);
- nsurl_unref(url);
- }
- if (error != NSERROR_OK) {
- warn_user(messages_get_errorcode(error), 0);
- }
+ url,
+ NULL,
+ browser,
+ NULL);
+ nsurl_unref(url);
+ }
+ if (error != NSERROR_OK) {
+ warn_user(messages_get_errorcode(error), 0);
+ }
}
-- (IBAction) cmOpenURLInWindow: (id) sender;
+- (IBAction) cmOpenURLInWindow: (id)sender
{
- nsurl *url;
- nserror error;
+ nsurl *url;
+ nserror error;
- error = nsurl_create([[sender representedObject] UTF8String], &url);
- if (error == NSERROR_OK) {
- error = browser_window_create(BW_CREATE_HISTORY |
+ error = nsurl_create([[sender representedObject] UTF8String], &url);
+ if (error == NSERROR_OK) {
+ error = browser_window_create(BW_CREATE_HISTORY |
BW_CREATE_CLONE,
- url,
- NULL,
- browser,
- NULL);
- nsurl_unref(url);
- }
- if (error != NSERROR_OK) {
- warn_user(messages_get_errorcode(error), 0);
- }
+ url,
+ NULL,
+ browser,
+ NULL);
+ nsurl_unref(url);
+ }
+ if (error != NSERROR_OK) {
+ warn_user(messages_get_errorcode(error), 0);
+ }
}
-- (IBAction) cmDownloadURL: (id) sender;
+- (IBAction) cmDownloadURL: (id)sender
{
- nsurl *url;
+ nsurl *url;
- if (nsurl_create([[sender representedObject] UTF8String], &url) == NSERROR_OK) {
+ if (nsurl_create([[sender representedObject] UTF8String], &url) == NSERROR_OK) {
browser_window_navigate(browser,
url,
NULL,
@@ -600,22 +623,22 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt )
NULL,
NULL,
NULL);
- nsurl_unref(url);
- }
+ nsurl_unref(url);
+ }
}
-- (IBAction) cmImageCopy: (id) sender;
+- (IBAction) cmImageCopy: (id)sender
{
- NSPasteboard *pb = [NSPasteboard generalPasteboard];
- [pb declareTypes: [NSArray arrayWithObject: NSTIFFPboardType] owner: nil];
- [pb setData: [[sender representedObject] TIFFRepresentation] forType: NSTIFFPboardType];
+ NSPasteboard *pb = [NSPasteboard generalPasteboard];
+ [pb declareTypes: [NSArray arrayWithObject: NSTIFFPboardType] owner: nil];
+ [pb setData: [[sender representedObject] TIFFRepresentation] forType: NSTIFFPboardType];
}
-- (IBAction) cmLinkCopy: (id) sender;
+- (IBAction) cmLinkCopy: (id)sender
{
- NSPasteboard *pb = [NSPasteboard generalPasteboard];
- [pb declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil];
- [pb setString: [sender representedObject] forType: NSStringPboardType];
+ NSPasteboard *pb = [NSPasteboard generalPasteboard];
+ [pb declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil];
+ [pb setString: [sender representedObject] forType: NSStringPboardType];
}
@@ -624,109 +647,109 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt )
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
- if ((NSDragOperationCopy | NSDragOperationGeneric) & [sender draggingSourceOperationMask]) {
- return NSDragOperationCopy;
- }
+ if ((NSDragOperationCopy | NSDragOperationGeneric) & [sender draggingSourceOperationMask]) {
+ return NSDragOperationCopy;
+ }
- return NSDragOperationNone;
+ return NSDragOperationNone;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
- return YES;
+ return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
- nsurl *url;
- nserror error;
+ nsurl *url;
+ nserror error;
NSPasteboard *pb = [sender draggingPasteboard];
NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObjects: @"public.url", NSURLPboardType, nil]];
- NSString *urlstr = nil;
+ NSString *urlstr = nil;
- if ([type isEqualToString: NSURLPboardType]) {
+ if ([type isEqualToString: NSURLPboardType]) {
urlstr = [[NSURL URLFromPasteboard: pb] absoluteString];
- } else {
+ } else {
urlstr = [pb stringForType: type];
}
-
- error = nsurl_create([urlstr UTF8String], &url);
- if (error != NSERROR_OK) {
- warn_user(messages_get_errorcode(error), 0);
- } else {
- browser_window_navigate(browser,
- url,
- NULL,
+
+ error = nsurl_create([urlstr UTF8String], &url);
+ if (error != NSERROR_OK) {
+ warn_user(messages_get_errorcode(error), 0);
+ } else {
+ browser_window_navigate(browser,
+ url,
+ NULL,
BW_NAVIGATE_DOWNLOAD,
- NULL,
- NULL,
- NULL);
- nsurl_unref(url);
- }
-
+ NULL,
+ NULL,
+ NULL);
+ nsurl_unref(url);
+ }
+
return YES;
}
// MARK: -
// MARK: NSTextInput protocol implementation
-- (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange
+- (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange
{
- [markedText release];
- markedText = [aString isEqualToString: @""] ? nil : [aString copy];
+ [markedText release];
+ markedText = [aString isEqualToString: @""] ? nil : [aString copy];
}
-- (void) unmarkText
+- (void) unmarkText
{
- [self setMarkedText: nil];
+ [self setMarkedText: nil];
}
-- (BOOL) hasMarkedText
+- (BOOL) hasMarkedText
{
- return markedText != nil;
+ return markedText != nil;
}
-- (NSInteger) conversationIdentifier
+- (NSInteger) conversationIdentifier
{
- return (NSInteger)self;
+ return (NSInteger)self;
}
-- (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange
+- (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange
{
- return [[[NSAttributedString alloc] initWithString: @""] autorelease];
+ return [[[NSAttributedString alloc] initWithString: @""] autorelease];
}
-- (NSRange) markedRange
+- (NSRange) markedRange
{
- return NSMakeRange( NSNotFound, 0 );
+ return NSMakeRange( NSNotFound, 0 );
}
-- (NSRange) selectedRange
+- (NSRange) selectedRange
{
- return NSMakeRange( NSNotFound, 0 );
+ return NSMakeRange( NSNotFound, 0 );
}
-- (NSRect) firstRectForCharacterRange: (NSRange) theRange
+- (NSRect) firstRectForCharacterRange: (NSRange) theRange
{
- return NSZeroRect;
+ return NSZeroRect;
}
-- (NSUInteger) characterIndexForPoint: (NSPoint) thePoint
+- (NSUInteger) characterIndexForPoint: (NSPoint) thePoint
{
- return 0;
+ return 0;
}
-- (NSArray *) validAttributesForMarkedText
+- (NSArray *) validAttributesForMarkedText
{
- return [NSArray array];
+ return [NSArray array];
}
- (void) doCommandBySelector: (SEL) sel;
{
- [super doCommandBySelector: sel];
+ [super doCommandBySelector: sel];
}
@end
diff --git a/cocoa/BrowserViewController.h b/cocoa/BrowserViewController.h
index 6c498766e..6b4c3e79c 100644
--- a/cocoa/BrowserViewController.h
+++ b/cocoa/BrowserViewController.h
@@ -47,7 +47,7 @@ struct browser_window;
@property (readwrite, assign, nonatomic) BOOL canGoBack;
@property (readwrite, assign, nonatomic) BOOL canGoForward;
-- initWithBrowser: (struct browser_window *) bw;
+- (id) initWithBrowser: (struct browser_window *) bw;
- (void) contentUpdated;
- (void) updateBackForward;
diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m
index e751fd9b0..559f99894 100644
--- a/cocoa/BrowserViewController.m
+++ b/cocoa/BrowserViewController.m
@@ -47,91 +47,110 @@
@synthesize canGoBack;
@synthesize canGoForward;
-- (void) dealloc;
+- (void) dealloc
{
- [self setUrl: nil];
- [self setBrowserView: nil];
- [self setWindowController: nil];
- [self setTitle: nil];
- [self setStatus: nil];
- [self setFavicon: nil];
-
- [super dealloc];
+ [self setUrl: nil];
+ [self setBrowserView: nil];
+ [self setWindowController: nil];
+ [self setTitle: nil];
+ [self setStatus: nil];
+ [self setFavicon: nil];
+
+ [super dealloc];
}
-- initWithBrowser: (struct browser_window *) bw;
+- initWithBrowser: (struct browser_window *) bw
{
- if ((self = [super initWithNibName: @"Browser" bundle: nil]) == nil) return nil;
-
- browser = bw;
-
- return self;
+ if ((self = [super initWithNibName: @"Browser" bundle: nil]) == nil) {
+ return nil;
+ }
+
+ browser = bw;
+
+ return self;
}
-- (IBAction) navigate: (id) sender;
+
+- (IBAction) navigate: (id) sender
{
- nsurl *urlns;
- nserror error;
-
- error = nsurl_create([url UTF8String], &urlns);
- if (error != NSERROR_OK) {
- warn_user(messages_get_errorcode(error), 0);
- } else {
- browser_window_navigate(browser,
- urlns,
- NULL,
- BW_NAVIGATE_HISTORY,
- NULL,
- NULL,
- NULL);
- nsurl_unref(urlns);
- }
+ nsurl *urlns;
+ nserror error;
+
+ error = nsurl_create([url UTF8String], &urlns);
+ if (error != NSERROR_OK) {
+ warn_user(messages_get_errorcode(error), 0);
+ } else {
+ browser_window_navigate(browser,
+ urlns,
+ NULL,
+ BW_NAVIGATE_HISTORY,
+ NULL,
+ NULL,
+ NULL);
+ nsurl_unref(urlns);
+ }
}
-- (void) awakeFromNib;
+
+- (void) awakeFromNib
{
- [browserView setBrowser: browser];
+ [browserView setBrowser: browser];
}
-- (IBAction) zoomIn: (id) sender;
+- (IBAction) zoomIn: (id) sender
{
- browser_window_set_scale( browser, browser_window_get_scale(browser) * 1.1, true );
+ browser_window_set_scale(browser,
+ browser_window_get_scale(browser) * 1.1,
+ true);
}
-- (IBAction) zoomOut: (id) sender;
+
+- (IBAction) zoomOut: (id) sender
{
- browser_window_set_scale( browser, browser_window_get_scale(browser) * 0.9, true );
+ browser_window_set_scale(browser,
+ browser_window_get_scale(browser) * 0.9,
+ true);
}
-- (IBAction) zoomOriginal: (id) sender;
+
+- (IBAction) zoomOriginal: (id) sender
{
- browser_window_set_scale( browser, (float)nsoption_int(scale) / 100.0, true );
+ browser_window_set_scale(browser,
+ (float)nsoption_int(scale) / 100.0,
+ true);
}
-- (IBAction) backForwardSelected: (id) sender;
+
+- (IBAction) backForwardSelected: (id) sender
{
- if ([sender selectedSegment] == 0) [self goBack: sender];
- else [self goForward: sender];
+ if ([sender selectedSegment] == 0) {
+ [self goBack: sender];
+ } else {
+ [self goForward: sender];
+ }
}
-- (IBAction) goBack: (id) sender;
+
+- (IBAction) goBack: (id) sender
{
- if (browser && browser_window_history_back_available( browser )) {
- browser_window_history_back(browser, false);
- [self updateBackForward];
- }
+ if (browser && browser_window_history_back_available( browser )) {
+ browser_window_history_back(browser, false);
+ [self updateBackForward];
+ }
}
-- (IBAction) goForward: (id) sender;
+
+- (IBAction) goForward: (id) sender
{
- if (browser && browser_window_history_forward_available( browser )) {
- browser_window_history_forward(browser, false);
- [self updateBackForward];
- }
+ if (browser && browser_window_history_forward_available( browser )) {
+ browser_window_history_forward(browser, false);
+ [self updateBackForward];
+ }
}
-- (IBAction) goHome: (id) sender;
+
+- (IBAction) goHome: (id) sender
{
nsurl *urlns;
nserror error;
@@ -141,7 +160,7 @@
error = browser_window_navigate(browser,
urlns,
NULL,
- BW_NAVIGATE_HISTORY,
+ BW_NAVIGATE_HISTORY,
NULL,
NULL,
NULL);
@@ -152,186 +171,207 @@
}
}
-- (IBAction) reloadPage: (id) sender;
+
+- (IBAction) reloadPage: (id) sender
{
- browser_window_reload( browser, true );
+ browser_window_reload( browser, true );
}
-- (IBAction) stopLoading: (id) sender;
+
+- (IBAction) stopLoading: (id) sender
{
- browser_window_stop( browser );
+ browser_window_stop( browser );
}
-- (IBAction) viewSource: (id) sender;
+
+- (IBAction) viewSource: (id) sender
{
- struct hlcache_handle *content;
- size_t size;
- const char *source;
- char *path = NULL;
-
- if (browser == NULL)
- return;
- content = browser_window_get_content(browser);
- if (content == NULL)
- return;
- source = content_get_source_data(content, &size);
- if (source == NULL)
- return;
-
- /* try to load local files directly. */
- netsurf_nsurl_to_path(hlcache_handle_get_url(content), &path);
-
- if (path == NULL) {
- /* We cannot release the requested filename until after it
- * has finished being used. As we can't easily find out when
- * this is, we simply don't bother releasing it and simply
- * allow it to be re-used next time NetSurf is started. The
- * memory overhead from doing this is under 1 byte per
- * filename. */
- const char *filename = filename_request();
- const char *extension = "txt";
- fprintf(stderr, "filename '%p'\n", filename);
- if (filename == NULL)
- return;
- lwc_string *str = content_get_mime_type(content);
- if (str) {
- NSString *mime = [NSString stringWithUTF8String:lwc_string_data(str)];
- NSString *uti = (NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mime, NULL);
- NSString *ext = (NSString *)UTTypeCopyPreferredTagWithClass((CFStringRef)uti, kUTTagClassFilenameExtension);
- extension = [ext UTF8String];
- lwc_string_unref(str);
- }
-
- NSURL *dataUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%s.%s", filename, extension]
- relativeToURL:[NSURL fileURLWithPath:@TEMP_FILENAME_PREFIX]];
-
-
- NSData *data = [NSData dataWithBytes:source length:size];
- [data writeToURL:dataUrl atomically:NO];
- path = [[dataUrl path] UTF8String];
- }
-
- if (path) {
- NSString * p = [NSString stringWithUTF8String: path];
- NSWorkspace * ws = [NSWorkspace sharedWorkspace];
- [ws openFile:p withApplication:@"Xcode"];
- }
+ struct hlcache_handle *content;
+ size_t size;
+ const char *source;
+ char *path = NULL;
+
+ if (browser == NULL) {
+ return;
+ }
+ content = browser_window_get_content(browser);
+ if (content == NULL) {
+ return;
+ }
+ source = content_get_source_data(content, &size);
+ if (source == NULL) {
+ return;
+ }
+
+ /* try to load local files directly. */
+ netsurf_nsurl_to_path(hlcache_handle_get_url(content), &path);
+
+ if (path == NULL) {
+ /* We cannot release the requested filename until after it
+ * has finished being used. As we can't easily find out when
+ * this is, we simply don't bother releasing it and simply
+ * allow it to be re-used next time NetSurf is started. The
+ * memory overhead from doing this is under 1 byte per
+ * filename. */
+ const char *filename = filename_request();
+ const char *extension = "txt";
+ fprintf(stderr, "filename '%p'\n", filename);
+ if (filename == NULL)
+ return;
+ lwc_string *str = content_get_mime_type(content);
+ if (str) {
+ NSString *mime = [NSString stringWithUTF8String:lwc_string_data(str)];
+ NSString *uti = (NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mime, NULL);
+ NSString *ext = (NSString *)UTTypeCopyPreferredTagWithClass((CFStringRef)uti, kUTTagClassFilenameExtension);
+ extension = [ext UTF8String];
+ lwc_string_unref(str);
+ }
+
+ NSURL *dataUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%s.%s", filename, extension]
+ relativeToURL:[NSURL fileURLWithPath:@TEMP_FILENAME_PREFIX]];
+
+
+ NSData *data = [NSData dataWithBytes:source length:size];
+ [data writeToURL:dataUrl atomically:NO];
+ path = [[dataUrl path] UTF8String];
+ }
+
+ if (path) {
+ NSString * p = [NSString stringWithUTF8String: path];
+ NSWorkspace * ws = [NSWorkspace sharedWorkspace];
+ [ws openFile:p withApplication:@"Xcode"];
+ }
}
-static inline bool compare_float( float a, float b )
+
+static inline bool
+compare_float( float a, float b )
{
- const float epsilon = 0.00001;
-
- if (a == b) return true;
-
- return fabs( (a - b) / b ) <= epsilon;
+ const float epsilon = 0.00001;
+
+ if (a == b) {
+ return true;
+ }
+
+ return fabs( (a - b) / b ) <= epsilon;
}
-- (BOOL) validateUserInterfaceItem: (id) item;
+- (BOOL) validateUserInterfaceItem: (id) item
{
- SEL action = [item action];
-
- if (action == @selector(copy:)) {
- return browser_window_get_editor_flags( browser ) & BW_EDITOR_CAN_COPY;
- }
-
- if (action == @selector(cut:)) {
- return browser_window_get_editor_flags( browser ) & BW_EDITOR_CAN_CUT;
- }
-
- if (action == @selector(paste:)) {
- return browser_window_get_editor_flags( browser ) & BW_EDITOR_CAN_PASTE;
- }
-
- if (action == @selector( stopLoading: )) {
- return browser_window_stop_available( browser );
- }
-
- if (action == @selector( zoomOriginal: )) {
- return !compare_float( browser_window_get_scale(browser), (float)nsoption_int(scale) / 100.0 );
- }
-
- if (action == @selector( goBack: )) {
- return canGoBack;
- }
-
- if (action == @selector( goForward: )) {
- return canGoForward;
- }
-
- return YES;
+ SEL action = [item action];
+
+ if (action == @selector(copy:)) {
+ return browser_window_get_editor_flags( browser ) & BW_EDITOR_CAN_COPY;
+ }
+
+ if (action == @selector(cut:)) {
+ return browser_window_get_editor_flags( browser ) & BW_EDITOR_CAN_CUT;
+ }
+
+ if (action == @selector(paste:)) {
+ return browser_window_get_editor_flags( browser ) & BW_EDITOR_CAN_PASTE;
+ }
+
+ if (action == @selector( stopLoading: )) {
+ return browser_window_stop_available( browser );
+ }
+
+ if (action == @selector( zoomOriginal: )) {
+ return !compare_float( browser_window_get_scale(browser), (float)nsoption_int(scale) / 100.0 );
+ }
+
+ if (action == @selector( goBack: )) {
+ return canGoBack;
+ }
+
+ if (action == @selector( goForward: )) {
+ return canGoForward;
+ }
+
+ return YES;
}
-- (void) updateBackForward;
+- (void) updateBackForward
{
- [browserView updateHistory];
- [self setCanGoBack: browser != NULL && browser_window_history_back_available( browser )];
- [self setCanGoForward: browser != NULL && browser_window_history_forward_available( browser )];
+ [browserView updateHistory];
+ [self setCanGoBack: browser != NULL && browser_window_history_back_available( browser )];
+ [self setCanGoForward: browser != NULL && browser_window_history_forward_available( browser )];
}
-- (void) contentUpdated;
+- (void) contentUpdated
{
- [browserView updateHistory];
+ [browserView updateHistory];
}
struct history_add_menu_item_data {
- NSInteger index;
- NSMenu *menu;
- id target;
+ NSInteger index;
+ NSMenu *menu;
+ id target;
};
-static bool history_add_menu_item_cb( const struct browser_window *bw, int x0, int y0, int x1, int y1,
- const struct history_entry *page, void *user_data )
+static bool
+history_add_menu_item_cb(const struct browser_window *bw,
+ int x0, int y0, int x1, int y1,
+ const struct history_entry *page,
+ void *user_data )
{
- struct history_add_menu_item_data *data = user_data;
-
- NSMenuItem *item = nil;
- if (data->index < [data->menu numberOfItems]) {
- item = [data->menu itemAtIndex: data->index];
- } else {
- item = [[NSMenuItem alloc] initWithTitle: @""
- action: @selector( historyItemSelected: )
- keyEquivalent: @""];
- [data->menu addItem: item];
- [item release];
- }
- ++data->index;
-
- [item setTarget: data->target];
- [item setTitle: [NSString stringWithUTF8String: browser_window_history_entry_get_title( page )]];
- [item setRepresentedObject: [NSValue valueWithPointer: page]];
-
- return true;
+ struct history_add_menu_item_data *data = user_data;
+
+ NSMenuItem *item = nil;
+ if (data->index < [data->menu numberOfItems]) {
+ item = [data->menu itemAtIndex: data->index];
+ } else {
+ item = [[NSMenuItem alloc] initWithTitle: @""
+ action: @selector( historyItemSelected: )
+ keyEquivalent: @""];
+ [data->menu addItem: item];
+ [item release];
+ }
+ ++data->index;
+
+ [item setTarget: data->target];
+ [item setTitle: [NSString stringWithUTF8String: browser_window_history_entry_get_title( page )]];
+ [item setRepresentedObject: [NSValue valueWithPointer: page]];
+
+ return true;
}
-- (IBAction) historyItemSelected: (id) sender;
+- (IBAction) historyItemSelected: (id) sender
{
- struct history_entry *entry = [[sender representedObject] pointerValue];
- browser_window_history_go( browser, entry, false );
- [self updateBackForward];
+ struct history_entry *entry = [[sender representedObject] pointerValue];
+ browser_window_history_go( browser, entry, false );
+ [self updateBackForward];
}
-- (void) buildBackMenu: (NSMenu *)menu;
+- (void) buildBackMenu: (NSMenu *)menu
{
- struct history_add_menu_item_data data = {
- .index = 0,
- .menu = menu,
- .target = self
- };
- browser_window_history_enumerate_back( browser, history_add_menu_item_cb, &data );
- while (data.index < [menu numberOfItems]) [menu removeItemAtIndex: data.index];
+ struct history_add_menu_item_data data = {
+ .index = 0,
+ .menu = menu,
+ .target = self
+ };
+ browser_window_history_enumerate_back(browser,
+ history_add_menu_item_cb,
+ &data);
+ while (data.index < [menu numberOfItems]) {
+ [menu removeItemAtIndex: data.index];
+ }
}
-- (void) buildForwardMenu: (NSMenu *)menu;
+- (void) buildForwardMenu: (NSMenu *)menu
{
- struct history_add_menu_item_data data = {
- .index = 0,
- .menu = menu,
- .target = self
- };
- browser_window_history_enumerate_forward( browser, history_add_menu_item_cb, &data );
- while (data.index < [menu numberOfItems]) [menu removeItemAtIndex: data.index];
+ struct history_add_menu_item_data data = {
+ .index = 0,
+ .menu = menu,
+ .target = self
+ };
+ browser_window_history_enumerate_forward(browser,
+ history_add_menu_item_cb,
+ &data);
+ while (data.index < [menu numberOfItems]) {
+ [menu removeItemAtIndex: data.index];
+ }
}
@end
diff --git a/cocoa/BrowserWindow.m b/cocoa/BrowserWindow.m
index ce31787f2..f01b17a25 100644
--- a/cocoa/BrowserWindow.m
+++ b/cocoa/BrowserWindow.m
@@ -21,9 +21,9 @@
@implementation BrowserWindow
-- (void) performClose: (id) sender;
+- (void) performClose: (id) sender
{
- [[self windowController] closeCurrentTab: sender];
+ [[self windowController] closeCurrentTab: sender];
}
@end
diff --git a/cocoa/DownloadWindowController.h b/cocoa/DownloadWindowController.h
index 798ebd1b6..47a05be39 100644
--- a/cocoa/DownloadWindowController.h
+++ b/cocoa/DownloadWindowController.h
@@ -21,19 +21,19 @@
struct gui_download_table *cocoa_download_table;
@interface DownloadWindowController : NSWindowController {
- struct download_context *context;
- unsigned long totalSize;
- unsigned long receivedSize;
-
- NSURL *url;
- NSString *mimeType;
- NSURL *saveURL;
- NSFileHandle *outputFile;
- NSMutableData *savedData;
- NSDate *startDate;
-
- BOOL canClose;
- BOOL shouldClose;
+ struct download_context *context;
+ unsigned long totalSize;
+ unsigned long receivedSize;
+
+ NSURL *url;
+ NSString *mimeType;
+ NSURL *saveURL;
+ NSFileHandle *outputFile;
+ NSMutableData *savedData;
+ NSDate *startDate;
+
+ BOOL canClose;
+ BOOL shouldClose;
}
@property (readwrite, copy, nonatomic) NSURL *URL;
@@ -46,9 +46,8 @@ struct gui_download_table *cocoa_download_table;
@property (readonly, nonatomic) NSImage *icon;
@property (readonly, nonatomic) NSString *statusText;
-- initWithContext: (struct download_context *)ctx;
+- (id)initWithContext: (struct download_context *)ctx;
- (void) abort;
@end
-
diff --git a/cocoa/DownloadWindowController.m b/cocoa/DownloadWindowController.m
index cb6117e0f..1241e5094 100644
--- a/cocoa/DownloadWindowController.m
+++ b/cocoa/DownloadWindowController.m
@@ -48,166 +48,174 @@ static void cocoa_register_download( DownloadWindowController *download );
@implementation DownloadWindowController
-- initWithContext: (struct download_context *)ctx;
+- (id) initWithContext: (struct download_context *)ctx
{
- if ((self = [super initWithWindowNibName: @"DownloadWindow"]) == nil) return nil;
-
- context = ctx;
- totalSize = download_context_get_total_length( context );
- [self setURL: [NSURL URLWithString: [NSString stringWithUTF8String: nsurl_access(download_context_get_url( context ))]]];
- [self setMIMEType: [NSString stringWithUTF8String: download_context_get_mime_type( context )]];
- [self setStartDate: [NSDate date]];
-
- return self;
+ if ((self = [super initWithWindowNibName: @"DownloadWindow"]) == nil) {
+ return nil;
+ }
+
+ context = ctx;
+ totalSize = download_context_get_total_length( context );
+ [self setURL: [NSURL URLWithString: [NSString stringWithUTF8String: nsurl_access(download_context_get_url( context ))]]];
+ [self setMIMEType: [NSString stringWithUTF8String: download_context_get_mime_type( context )]];
+ [self setStartDate: [NSDate date]];
+
+ return self;
}
-- (void) dealloc;
+- (void) dealloc
{
- download_context_destroy( context );
-
- [self setURL: nil];
- [self setMIMEType: nil];
- [self setSaveURL: nil];
- [self setOutputFile: nil];
- [self setSavedData: nil];
- [self setStartDate: nil];
-
- [super dealloc];
+ download_context_destroy( context );
+
+ [self setURL: nil];
+ [self setMIMEType: nil];
+ [self setSaveURL: nil];
+ [self setOutputFile: nil];
+ [self setSavedData: nil];
+ [self setStartDate: nil];
+
+ [super dealloc];
}
-- (void) abort;
+- (void) abort
{
- download_context_abort( context );
- [self removeIfPossible];
+ download_context_abort( context );
+ [self removeIfPossible];
}
-- (void) askForSave;
+- (void) askForSave
{
- canClose = NO;
- [[NSSavePanel savePanel] beginSheetForDirectory: nil
- file: [NSString stringWithUTF8String: download_context_get_filename( context )]
- modalForWindow: [self window]
- modalDelegate: self
- didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
- contextInfo: NULL];
+ canClose = NO;
+ [[NSSavePanel savePanel]
+ beginSheetForDirectory: nil
+ file: [NSString stringWithUTF8String: download_context_get_filename( context )]
+ modalForWindow: [self window]
+ modalDelegate: self
+ didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
+ contextInfo: NULL];
}
-- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
+- (void) savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
- canClose = YES;
-
- if (returnCode == NSCancelButton) {
- [self abort];
- return;
- }
-
- NSURL *targetURL = [sheet URL];
- NSString *path = [targetURL path];
-
- [[NSFileManager defaultManager] createFileAtPath: path contents: nil attributes: nil];
-
- FSRef ref;
- if (CFURLGetFSRef( (CFURLRef)targetURL, &ref )) {
- NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
- url, (NSString *)kLSQuarantineDataURLKey,
- (NSString *)kLSQuarantineTypeWebDownload, (NSString *)kLSQuarantineTypeKey,
- nil];
- LSSetItemAttribute( &ref, kLSRolesAll, kLSItemQuarantineProperties, (CFDictionaryRef)attributes );
- LOG("Set quarantine attributes on file %s", [path UTF8String]);
- }
-
- [self setOutputFile: [NSFileHandle fileHandleForWritingAtPath: path]];
- [self setSaveURL: targetURL];
-
- NSWindow *win = [self window];
- [win setRepresentedURL: targetURL];
- [win setTitle: [self fileName]];
-
- if (nil == outputFile) {
- [self performSelector: @selector(showError:) withObject: @"Cannot create file" afterDelay: 0];
- return;
- }
-
- if (nil != savedData) {
- [outputFile writeData: savedData];
- [self setSavedData: nil];
- }
-
- [self removeIfPossible];
+ canClose = YES;
+
+ if (returnCode == NSCancelButton) {
+ [self abort];
+ return;
+ }
+
+ NSURL *targetURL = [sheet URL];
+ NSString *path = [targetURL path];
+
+ [[NSFileManager defaultManager] createFileAtPath: path contents: nil attributes: nil];
+
+ FSRef ref;
+ if (CFURLGetFSRef( (CFURLRef)targetURL, &ref )) {
+ NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
+ url, (NSString *)kLSQuarantineDataURLKey,
+ (NSString *)kLSQuarantineTypeWebDownload, (NSString *)kLSQuarantineTypeKey,
+ nil];
+ LSSetItemAttribute( &ref, kLSRolesAll, kLSItemQuarantineProperties, (CFDictionaryRef)attributes );
+ LOG("Set quarantine attributes on file %s", [path UTF8String]);
+ }
+
+ [self setOutputFile: [NSFileHandle fileHandleForWritingAtPath: path]];
+ [self setSaveURL: targetURL];
+
+ NSWindow *win = [self window];
+ [win setRepresentedURL: targetURL];
+ [win setTitle: [self fileName]];
+
+ if (nil == outputFile) {
+ [self performSelector: @selector(showError:) withObject: @"Cannot create file" afterDelay: 0];
+ return;
+ }
+
+ if (nil != savedData) {
+ [outputFile writeData: savedData];
+ [self setSavedData: nil];
+ }
+
+ [self removeIfPossible];
}
-- (BOOL) receivedData: (NSData *)data;
+- (BOOL) receivedData: (NSData *)data
{
- if (outputFile) {
- [outputFile writeData: data];
- } else {
- if (nil == savedData) [self setSavedData: [NSMutableData data]];
- [savedData appendData: data];
- }
-
- [self setReceivedSize: receivedSize + [data length]];
-
- return YES;
+ if (outputFile) {
+ [outputFile writeData: data];
+ } else {
+ if (nil == savedData) {
+ [self setSavedData: [NSMutableData data]];
+ }
+ [savedData appendData: data];
+ }
+
+ [self setReceivedSize: receivedSize + [data length]];
+
+ return YES;
}
-- (void) showError: (NSString *)error;
+- (void) showError: (NSString *)error
{
- canClose = NO;
- NSAlert *alert = [NSAlert alertWithMessageText: NSLocalizedString( @"Error", @"show error" )
- defaultButton: NSLocalizedString( @"OK", @"'OK' button" )
- alternateButton: nil otherButton: nil
- informativeTextWithFormat: @"%@", error];
-
- [alert beginSheetModalForWindow: [self window] modalDelegate: self
- didEndSelector: @selector(alertDidEnd:returnCode:contextInfo:)
- contextInfo: NULL];
+ canClose = NO;
+ NSAlert *alert = [NSAlert alertWithMessageText: NSLocalizedString( @"Error", @"show error" )
+ defaultButton: NSLocalizedString( @"OK", @"'OK' button" )
+ alternateButton: nil otherButton: nil
+ informativeTextWithFormat: @"%@", error];
+
+ [alert beginSheetModalForWindow: [self window] modalDelegate: self
+ didEndSelector: @selector(alertDidEnd:returnCode:contextInfo:)
+ contextInfo: NULL];
}
-- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
+- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
- [self abort];
+ [self abort];
}
-- (void) removeIfPossible;
+- (void) removeIfPossible
{
- if (canClose && shouldClose) {
- cocoa_unregister_download( self );
- }
+ if (canClose && shouldClose) {
+ cocoa_unregister_download( self );
+ }
}
-- (void) downloadDone;
+- (void) downloadDone
{
- shouldClose = YES;
- [self removeIfPossible];
+ shouldClose = YES;
+ [self removeIfPossible];
}
-- (BOOL) windowShouldClose: (id)sender;
+- (BOOL) windowShouldClose: (id)sender
{
- if ([[NSUserDefaults standardUserDefaults] boolForKey: kAlwaysCancelDownload]) return YES;
-
- NSAlert *ask = [NSAlert alertWithMessageText: NSLocalizedString( @"Cancel download?", @"Download" )
- defaultButton: NSLocalizedString( @"Yes", @"" )
- alternateButton: NSLocalizedString( @"No", @"" )
- otherButton: nil
- informativeTextWithFormat: NSLocalizedString( @"Should the download of '%@' really be cancelled?", @"Download" ),
- [self fileName]];
- [ask setShowsSuppressionButton: YES];
- [ask beginSheetModalForWindow: [self window] modalDelegate: self
- didEndSelector: @selector(askCancelDidEnd:returnCode:contextInfo:) contextInfo: NULL];
- return NO;
+ if ([[NSUserDefaults standardUserDefaults] boolForKey: kAlwaysCancelDownload]) {
+ return YES;
+ }
+
+ NSAlert *ask = [NSAlert alertWithMessageText: NSLocalizedString( @"Cancel download?", @"Download" )
+ defaultButton: NSLocalizedString( @"Yes", @"" )
+ alternateButton: NSLocalizedString( @"No", @"" )
+ otherButton: nil
+ informativeTextWithFormat: NSLocalizedString( @"Should the download of '%@' really be cancelled?", @"Download" ),
+ [self fileName]];
+ [ask setShowsSuppressionButton: YES];
+ [ask beginSheetModalForWindow: [self window] modalDelegate: self
+ didEndSelector: @selector(askCancelDidEnd:returnCode:contextInfo:) contextInfo: NULL];
+ return NO;
}
-- (void) windowWillClose: (NSNotification *)notification;
+- (void) windowWillClose: (NSNotification *)notification
{
- [self abort];
+ [self abort];
}
-- (void)askCancelDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
+- (void) askCancelDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
- if (returnCode == NSOKButton) {
- [[NSUserDefaults standardUserDefaults] setBool: [[alert suppressionButton] state] == NSOnState
- forKey: kAlwaysCancelDownload];
- [self close];
- }
+ if (returnCode == NSOKButton) {
+ [[NSUserDefaults standardUserDefaults]
+ setBool: [[alert suppressionButton] state] == NSOnState
+ forKey: kAlwaysCancelDownload];
+ [self close];
+ }
}
#pragma mark -
@@ -222,141 +230,158 @@ static void cocoa_register_download( DownloadWindowController *download );
@synthesize receivedSize;
@synthesize startDate;
-+ (NSSet *) keyPathsForValuesAffectingStatusText;
++ (NSSet *) keyPathsForValuesAffectingStatusText
{
- return [NSSet setWithObjects: @"totalSize", @"receivedSize", nil];
+ return [NSSet setWithObjects: @"totalSize", @"receivedSize", nil];
}
#ifndef NSAppKitVersionNumber10_5
#define NSAppKitVersionNumber10_5 949
-#endif
+#endif
static NSString *cocoa_file_size_string( float size )
{
- static unsigned factor = 0;
- if (factor == 0) {
- if (floor( NSAppKitVersionNumber ) > NSAppKitVersionNumber10_5) factor = 1000;
- else factor = 1024;
- }
-
- if (size == 0) return @"nothing";
- if (size <= 1.0) return @"1 byte";
-
- if (size < factor - 1) return [NSString stringWithFormat:@"%1.0f bytes",size];
-
- size /= factor;
- if (size < factor - 1) return [NSString stringWithFormat:@"%1.1f KB", size];
-
- size /= factor;
- if (size < factor - 1) return [NSString stringWithFormat:@"%1.1f MB", size];
-
- size /= factor;
- if (size < factor - 1) return [NSString stringWithFormat:@"%1.1f GB", size];
-
- size /= factor;
- return [NSString stringWithFormat:@"%1.1f TB", size];
+ static unsigned factor = 0;
+ if (factor == 0) {
+ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
+ factor = 1000;
+ } else {
+ factor = 1024;
+ }
+ }
+
+ if (size == 0) return @"nothing";
+ if (size <= 1.0) return @"1 byte";
+
+ if (size < factor - 1) return [NSString stringWithFormat:@"%1.0f bytes",size];
+
+ size /= factor;
+ if (size < factor - 1) return [NSString stringWithFormat:@"%1.1f KB", size];
+
+ size /= factor;
+ if (size < factor - 1) return [NSString stringWithFormat:@"%1.1f MB", size];
+
+ size /= factor;
+ if (size < factor - 1) return [NSString stringWithFormat:@"%1.1f GB", size];
+
+ size /= factor;
+ return [NSString stringWithFormat:@"%1.1f TB", size];
}
static NSString *cocoa_time_string( unsigned seconds )
{
- if (seconds <= 10) return NSLocalizedString( @"less than 10 seconds", @"time remaining" );
-
- if (seconds < 60) return [NSString stringWithFormat: NSLocalizedString( @"%u seconds", @"time remaining" ), seconds];
-
- unsigned minutes = seconds / 60;
- seconds = seconds % 60;
-
- if (minutes < 60) return [NSString stringWithFormat: NSLocalizedString( @"%u:%02u minutes", @"time remaining: minutes, seconds" ) , minutes, seconds];
-
- unsigned hours = minutes / 60;
- minutes = minutes % 60;
-
- return [NSString stringWithFormat: NSLocalizedString( @"%2:%02u hours", @"time remaining: hours, minutes" ), hours, minutes];
+ if (seconds <= 10) {
+ return NSLocalizedString(@"less than 10 seconds",
+ @"time remaining" );
+ }
+
+ if (seconds < 60) {
+ return [NSString stringWithFormat: NSLocalizedString( @"%u seconds",
+ @"time remaining" ), seconds];
+ }
+
+ unsigned minutes = seconds / 60;
+ seconds = seconds % 60;
+
+ if (minutes < 60) {
+ return [NSString stringWithFormat: NSLocalizedString( @"%u:%02u minutes",
+ @"time remaining: minutes, seconds" ) , minutes, seconds];
+ }
+
+ unsigned hours = minutes / 60;
+ minutes = minutes % 60;
+
+ return [NSString stringWithFormat: NSLocalizedString( @"%2:%02u hours", @"time remaining: hours, minutes" ), hours, minutes];
}
-- (NSString *) statusText;
+- (NSString *) statusText
{
- NSString *speedString = @"";
-
- float speed = 0.0;
- NSTimeInterval elapsedTime = [[NSDate date] timeIntervalSinceDate: startDate];
- if (elapsedTime >= 0.1) {
- speed = (float)receivedSize / elapsedTime;
- speedString = [NSString stringWithFormat: @" (%@/s)", cocoa_file_size_string( speed )];
- }
-
- NSString *timeRemainingString = @"";
- NSString *totalSizeString = @"";
- if (totalSize != 0) {
- if (speed > 0.0) {
- float timeRemaining = (float)(totalSize - receivedSize) / speed;
- timeRemainingString = [NSString stringWithFormat: @": %@", cocoa_time_string( timeRemaining )];
- }
- totalSizeString = [NSString stringWithFormat: NSLocalizedString( @" of %@", @"... of (total size)" ), cocoa_file_size_string( totalSize )];
- }
-
- return [NSString stringWithFormat: @"%@%@%@%@", cocoa_file_size_string( receivedSize ),
- totalSizeString, speedString, timeRemainingString];
+ NSString *speedString = @"";
+
+ float speed = 0.0;
+ NSTimeInterval elapsedTime = [[NSDate date] timeIntervalSinceDate: startDate];
+ if (elapsedTime >= 0.1) {
+ speed = (float)receivedSize / elapsedTime;
+ speedString = [NSString stringWithFormat: @" (%@/s)", cocoa_file_size_string( speed )];
+ }
+
+ NSString *timeRemainingString = @"";
+ NSString *totalSizeString = @"";
+ if (totalSize != 0) {
+ if (speed > 0.0) {
+ float timeRemaining = (float)(totalSize - receivedSize) / speed;
+ timeRemainingString = [NSString stringWithFormat: @": %@", cocoa_time_string( timeRemaining )];
+ }
+ totalSizeString = [NSString stringWithFormat: NSLocalizedString( @" of %@", @"... of (total size)" ), cocoa_file_size_string( totalSize )];
+ }
+
+ return [NSString stringWithFormat: @"%@%@%@%@", cocoa_file_size_string( receivedSize ),
+ totalSizeString, speedString, timeRemainingString];
}
-+ (NSSet *) keyPathsForValuesAffectingFileName;
++ (NSSet *) keyPathsForValuesAffectingFileName
{
- return [NSSet setWithObject: @"saveURL"];
+ return [NSSet setWithObject: @"saveURL"];
}
-- (NSString *) fileName;
+- (NSString *) fileName
{
- return [[saveURL path] lastPathComponent];
+ return [[saveURL path] lastPathComponent];
}
-+ (NSSet *) keyPathsForValuesAffectingIcon;
++ (NSSet *) keyPathsForValuesAffectingIcon
{
- return [NSSet setWithObjects: @"mimeType", @"URL", nil];
+ return [NSSet setWithObjects: @"mimeType", @"URL", nil];
}
- (NSImage *) icon;
{
- NSString *type = [(NSString *)UTTypeCreatePreferredIdentifierForTag( kUTTagClassMIMEType, (CFStringRef)mimeType, NULL ) autorelease];
- if ([type hasPrefix: @"dyn."] || [type isEqualToString: (NSString *)kUTTypeData]) {
- NSString *pathExt = [[url path] pathExtension];
- type = [(NSString *)UTTypeCreatePreferredIdentifierForTag( kUTTagClassFilenameExtension, (CFStringRef)pathExt, NULL ) autorelease];
- }
- return [[NSWorkspace sharedWorkspace] iconForFileType: type];
+ NSString *type = [(NSString *)UTTypeCreatePreferredIdentifierForTag( kUTTagClassMIMEType, (CFStringRef)mimeType, NULL ) autorelease];
+ if ([type hasPrefix: @"dyn."] || [type isEqualToString: (NSString *)kUTTypeData]) {
+ NSString *pathExt = [[url path] pathExtension];
+ type = [(NSString *)UTTypeCreatePreferredIdentifierForTag( kUTTagClassFilenameExtension, (CFStringRef)pathExt, NULL ) autorelease];
+ }
+ return [[NSWorkspace sharedWorkspace] iconForFileType: type];
}
#pragma mark -
#pragma mark NetSurf interface functions
-static struct gui_download_window *gui_download_window_create(download_context *ctx,
- struct gui_window *parent)
+static struct gui_download_window *
+gui_download_window_create(download_context *ctx,
+ struct gui_window *parent)
{
- DownloadWindowController * const window = [[DownloadWindowController alloc] initWithContext: ctx];
- cocoa_register_download( window );
- [window askForSave];
- [window release];
-
- return (struct gui_download_window *)window;
+ DownloadWindowController * const window = [[DownloadWindowController alloc] initWithContext: ctx];
+ cocoa_register_download( window );
+ [window askForSave];
+ [window release];
+
+ return (struct gui_download_window *)window;
}
-static nserror gui_download_window_data(struct gui_download_window *dw,
- const char *data, unsigned int size)
+static nserror
+gui_download_window_data(struct gui_download_window *dw,
+ const char *data,
+ unsigned int size)
{
- DownloadWindowController * const window = (DownloadWindowController *)dw;
- return [window receivedData: [NSData dataWithBytes: data length: size]] ? NSERROR_OK : NSERROR_SAVE_FAILED;
+ DownloadWindowController * const window = (DownloadWindowController *)dw;
+ return [window receivedData: [NSData dataWithBytes: data length: size]] ? NSERROR_OK : NSERROR_SAVE_FAILED;
}
-static void gui_download_window_error(struct gui_download_window *dw,
- const char *error_msg)
+static void
+gui_download_window_error(struct gui_download_window *dw,
+ const char *error_msg)
{
- DownloadWindowController * const window = (DownloadWindowController *)dw;
- [window showError: [NSString stringWithUTF8String: error_msg]];
+ DownloadWindowController * const window = (DownloadWindowController *)dw;
+ [window showError: [NSString stringWithUTF8String: error_msg]];
}
-static void gui_download_window_done(struct gui_download_window *dw)
+static void
+gui_download_window_done(struct gui_download_window *dw)
{
- DownloadWindowController * const window = (DownloadWindowController *)dw;
- [window downloadDone];
+ DownloadWindowController * const window = (DownloadWindowController *)dw;
+ [window downloadDone];
}
@end
@@ -364,25 +389,27 @@ static void gui_download_window_done(struct gui_download_window *dw)
#pragma mark -
static NSMutableSet *cocoa_all_downloads = nil;
-static void cocoa_register_download( DownloadWindowController *download )
+static void
+cocoa_register_download( DownloadWindowController *download )
{
- if (cocoa_all_downloads == nil) {
- cocoa_all_downloads = [[NSMutableSet alloc] init];
- }
- [cocoa_all_downloads addObject: download];
+ if (cocoa_all_downloads == nil) {
+ cocoa_all_downloads = [[NSMutableSet alloc] init];
+ }
+ [cocoa_all_downloads addObject: download];
}
-static void cocoa_unregister_download( DownloadWindowController *download )
+static void
+cocoa_unregister_download( DownloadWindowController *download )
{
- [cocoa_all_downloads removeObject: download];
+ [cocoa_all_downloads removeObject: download];
}
static struct gui_download_table download_table = {
- .create = gui_download_window_create,
- .data = gui_download_window_data,
- .error = gui_download_window_error,
- .done = gui_download_window_done,
+ .create = gui_download_window_create,
+ .data = gui_download_window_data,
+ .error = gui_download_window_error,
+ .done = gui_download_window_done,
};
struct gui_download_table *cocoa_download_table = &download_table;
diff --git a/cocoa/FormSelectMenu.h b/cocoa/FormSelectMenu.h
index 54f226fed..cec519296 100644
--- a/cocoa/FormSelectMenu.h
+++ b/cocoa/FormSelectMenu.h
@@ -18,16 +18,15 @@
#import <Cocoa/Cocoa.h>
-
@interface FormSelectMenu : NSObject {
- NSMenu *menu;
- NSPopUpButtonCell *cell;
-
- struct browser_window *browser;
- struct form_control *control;
+ NSMenu *menu;
+ NSPopUpButtonCell *cell;
+
+ struct browser_window *browser;
+ struct form_control *control;
}
-- initWithControl: (struct form_control *) control forWindow: (struct browser_window *) window;
+- (id)initWithControl: (struct form_control *) control forWindow: (struct browser_window *) window;
- (void) runInView: (NSView *) view;
@end
diff --git a/cocoa/FormSelectMenu.m b/cocoa/FormSelectMenu.m
index 27156bcae..84e04cd25 100644
--- a/cocoa/FormSelectMenu.m
+++ b/cocoa/FormSelectMenu.m
@@ -24,9 +24,13 @@
static inline NSRect cocoa_rect_for_control( struct browser_window *bw, struct form_control *control)
{
- struct rect r;
- form_control_bounding_rect(control, &r);
- return cocoa_scaled_rect(browser_window_get_scale(bw), r.x0, r.y0, r.x1, r.y1 );
+ struct rect r;
+ form_control_bounding_rect(control, &r);
+ return cocoa_scaled_rect(browser_window_get_scale(bw),
+ r.x0,
+ r.y0,
+ r.x1,
+ r.y1);
}
@interface FormSelectMenu ()
@@ -38,69 +42,72 @@ static inline NSRect cocoa_rect_for_control( struct browser_window *bw, struct f
@implementation FormSelectMenu
-
-- initWithControl: (struct form_control *) c forWindow: (struct browser_window *) w;
+- (id) initWithControl: (struct form_control *) c forWindow: (struct browser_window *) w
{
- if ((self = [super init]) == nil) return nil;
-
- control = c;
- browser = w;
-
- menu = [[NSMenu alloc] initWithTitle: @"Select"];
- if (menu == nil) {
- [self release];
- return nil;
- }
-
- [menu addItemWithTitle: @"" action: NULL keyEquivalent: @""];
-
- NSInteger currentItemIndex = 0;
+ if ((self = [super init]) == nil) return nil;
+
+ control = c;
+ browser = w;
+
+ menu = [[NSMenu alloc] initWithTitle: @"Select"];
+ if (menu == nil) {
+ [self release];
+ return nil;
+ }
+
+ [menu addItemWithTitle: @"" action: NULL keyEquivalent: @""];
+
+ NSInteger currentItemIndex = 0;
struct form_option *opt;
- for (opt = form_select_get_option(control, 0); opt != NULL; opt = opt->next) {
- NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: opt->text]
- action: @selector( itemSelected: )
- keyEquivalent: @""];
- if (opt->selected) [item setState: NSOnState];
- [item setTarget: self];
- [item setTag: currentItemIndex++];
- [menu addItem: item];
- [item release];
- }
-
- [menu setDelegate: self];
-
- return self;
+ for (opt = form_select_get_option(control, 0);
+ opt != NULL;
+ opt = opt->next) {
+ NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: opt->text]
+ action: @selector( itemSelected: )
+ keyEquivalent: @""];
+ if (opt->selected) {
+ [item setState: NSOnState];
+ }
+ [item setTarget: self];
+ [item setTag: currentItemIndex++];
+ [menu addItem: item];
+ [item release];
+ }
+
+ [menu setDelegate: self];
+
+ return self;
}
-- (void) dealloc;
+- (void) dealloc
{
- [cell release];
- [menu release];
-
- [super dealloc];
+ [cell release];
+ [menu release];
+
+ [super dealloc];
}
-- (void) runInView: (NSView *) view;
+- (void) runInView: (NSView *) view
{
- [self retain];
-
- cell = [[NSPopUpButtonCell alloc] initTextCell: @"" pullsDown: YES];
- [cell setMenu: menu];
-
- const NSRect rect = cocoa_rect_for_control(browser, control);
-
- [cell attachPopUpWithFrame: rect inView: view];
- [cell performClickWithFrame: rect inView: view];
+ [self retain];
+
+ cell = [[NSPopUpButtonCell alloc] initTextCell: @"" pullsDown: YES];
+ [cell setMenu: menu];
+
+ const NSRect rect = cocoa_rect_for_control(browser, control);
+
+ [cell attachPopUpWithFrame: rect inView: view];
+ [cell performClickWithFrame: rect inView: view];
}
-- (void) itemSelected: (id) sender;
+- (void) itemSelected: (id) sender
{
- form_select_process_selection( control, [sender tag] );
+ form_select_process_selection( control, [sender tag] );
}
-- (void) menuDidClose: (NSMenu *) sender;
+- (void) menuDidClose: (NSMenu *) sender
{
- [self release];
+ [self release];
}
@end
diff --git a/cocoa/LocalHistoryController.h b/cocoa/LocalHistoryController.h
index 8b8018c88..3e6d1775e 100644
--- a/cocoa/LocalHistoryController.h
+++ b/cocoa/LocalHistoryController.h
@@ -29,7 +29,7 @@
@property (readwrite, assign, nonatomic) BrowserView *browser;
@property (readwrite, assign, nonatomic) IBOutlet HistoryView *history;
-- initWithBrowser: (BrowserView *) bw;
+- (id)initWithBrowser: (BrowserView *) bw;
- (void) attachToView: (NSView *) view;
- (void) detach;
diff --git a/cocoa/ScrollableView.m b/cocoa/ScrollableView.m
index 63a675323..8f27b2b56 100644
--- a/cocoa/ScrollableView.m
+++ b/cocoa/ScrollableView.m
@@ -27,42 +27,45 @@
@implementation ScrollableView
@synthesize minimumSize;
-- (void) setMinimumSize: (NSSize)newSize;
+- (void) setMinimumSize: (NSSize)newSize
{
- minimumSize = newSize;
- [self adjustFrame];
+ minimumSize = newSize;
+ [self adjustFrame];
}
-- (void) adjustFrame;
+- (void) adjustFrame
{
- NSSize frameSize = [[self superview] frame].size;
- [self setFrameSize: NSMakeSize( MAX( minimumSize.width, frameSize.width ),
- MAX( minimumSize.height, frameSize.height ) )];
+ NSSize frameSize = [[self superview] frame].size;
+ [self setFrameSize: NSMakeSize( MAX( minimumSize.width, frameSize.width ),
+ MAX( minimumSize.height, frameSize.height ) )];
}
-- (void) frameChangeNotification: (NSNotification *) note;
+- (void) frameChangeNotification: (NSNotification *) note
{
- [self adjustFrame];
+ [self adjustFrame];
}
-- (void) viewDidMoveToSuperview;
+- (void) viewDidMoveToSuperview
{
- if (observedSuperview) {
- [[NSNotificationCenter defaultCenter] removeObserver: self
- name: NSViewFrameDidChangeNotification
- object: observedSuperview];
- observedSuperview = nil;
- }
-
- NSView *newSuperView = [self superview];
-
- if (nil != newSuperView) {
- observedSuperview = newSuperView;
- [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(frameChangeNotification:)
- name: NSViewFrameDidChangeNotification
- object: observedSuperview];
- [observedSuperview setPostsFrameChangedNotifications: YES];
- }
+ if (observedSuperview) {
+ [[NSNotificationCenter defaultCenter]
+ removeObserver: self
+ name: NSViewFrameDidChangeNotification
+ object: observedSuperview];
+ observedSuperview = nil;
+ }
+
+ NSView *newSuperView = [self superview];
+
+ if (nil != newSuperView) {
+ observedSuperview = newSuperView;
+ [[NSNotificationCenter defaultCenter]
+ addObserver: self
+ selector: @selector(frameChangeNotification:)
+ name: NSViewFrameDidChangeNotification
+ object: observedSuperview];
+ [observedSuperview setPostsFrameChangedNotifications: YES];
+ }
}
@end
diff --git a/cocoa/Tree.h b/cocoa/Tree.h
index fbdb7f70e..422478182 100644
--- a/cocoa/Tree.h
+++ b/cocoa/Tree.h
@@ -33,13 +33,13 @@
@interface Tree : NSObject {
- id <TreeDelegate> delegate;
- struct tree *tree;
+ id <TreeDelegate> delegate;
+ struct tree *tree;
}
@property (readwrite, assign, nonatomic) id <TreeDelegate> delegate;
-- initWithFlags: (unsigned int) flags;
+- (id)initWithFlags: (unsigned int) flags;
- (struct tree *) tree;
diff --git a/cocoa/Tree.m b/cocoa/Tree.m
index 05a52c802..5cd796ceb 100644
--- a/cocoa/Tree.m
+++ b/cocoa/Tree.m
@@ -34,43 +34,43 @@ static void tree_scroll_visible( int y, int height, void *data );
static void tree_get_window_dimensions( int *width, int *height, void *data );
static const struct treeview_table cocoa_tree_callbacks = {
- .redraw_request = tree_redraw_request,
- .resized = tree_resized,
- .scroll_visible = tree_scroll_visible,
- .get_window_dimensions = tree_get_window_dimensions
+ .redraw_request = tree_redraw_request,
+ .resized = tree_resized,
+ .scroll_visible = tree_scroll_visible,
+ .get_window_dimensions = tree_get_window_dimensions
};
-- initWithFlags: (unsigned int)flags;
+- (id)initWithFlags: (unsigned int)flags
{
- if ((self = [super init]) == nil) return nil;
-
- tree = tree_create( flags, &cocoa_tree_callbacks, self );
- if (tree == NULL) {
- [self release];
- return nil;
- }
-
- return self;
+ if ((self = [super init]) == nil) return nil;
+
+ tree = tree_create( flags, &cocoa_tree_callbacks, self );
+ if (tree == NULL) {
+ [self release];
+ return nil;
+ }
+
+ return self;
}
-- (void) dealloc;
+- (void) dealloc
{
- tree_delete( tree );
- [super dealloc];
+ tree_delete( tree );
+ [super dealloc];
}
-- (struct tree *) tree;
+- (struct tree *) tree
{
- return tree;
+ return tree;
}
-- (void) setRedrawing: (BOOL) newRedrawing;
+- (void) setRedrawing: (BOOL) newRedrawing
{
}
-+ (void) initialize;
++ (void) initialize
{
}
@@ -79,65 +79,69 @@ static const struct treeview_table cocoa_tree_callbacks = {
static void tree_redraw_request( int x, int y, int w, int h, void *data )
{
- id <TreeDelegate> delegate = ((Tree *)data)->delegate;
- [delegate tree: (Tree *)data requestedRedrawInRect: cocoa_rect_wh( x, y, w, h )];
+ id <TreeDelegate> delegate = ((Tree *)data)->delegate;
+ [delegate tree: (Tree *)data requestedRedrawInRect: cocoa_rect_wh( x, y, w, h )];
}
static void tree_resized( struct tree *tree, int w, int h, void *data )
{
- id <TreeDelegate> delegate = ((Tree *)data)->delegate;
- [delegate tree: (Tree *)data resized: cocoa_size( w, h )];
+ id <TreeDelegate> delegate = ((Tree *)data)->delegate;
+ [delegate tree: (Tree *)data resized: cocoa_size( w, h )];
}
static void tree_scroll_visible( int y, int height, void *data )
{
- id <TreeDelegate> delegate = ((Tree *)data)->delegate;
- [delegate tree: (Tree *)data scrollPoint: cocoa_point( 0, y )];
+ id <TreeDelegate> delegate = ((Tree *)data)->delegate;
+ [delegate tree: (Tree *)data scrollPoint: cocoa_point( 0, y )];
}
static void tree_get_window_dimensions( int *width, int *height, void *data )
{
- id <TreeDelegate> delegate = ((Tree *)data)->delegate;
- if (delegate == nil) return;
-
- NSSize size = [delegate treeWindowSize: (Tree *)data];
+ id <TreeDelegate> delegate = ((Tree *)data)->delegate;
+ if (delegate == nil) return;
- if (width != NULL) *width = cocoa_pt_to_px( size.width );
- if (height != NULL) *height = cocoa_pt_to_px( size.height );
+ NSSize size = [delegate treeWindowSize: (Tree *)data];
+
+ if (width != NULL) *width = cocoa_pt_to_px( size.width );
+ if (height != NULL) *height = cocoa_pt_to_px( size.height );
}
@end
@implementation Tree (ViewInterface)
-- (void) drawRect: (NSRect) rect inView: (NSView *) view;
+- (void) drawRect: (NSRect) rect inView: (NSView *) view
{
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = &cocoa_plotters
- };
-
- tree_draw( tree, 0, 0, cocoa_pt_to_px( NSMinX( rect ) ), cocoa_pt_to_px( NSMinY( rect )),
- cocoa_pt_to_px( NSWidth( rect ) ), cocoa_pt_to_px( NSHeight( rect ) ), &ctx );
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &cocoa_plotters
+ };
+
+ tree_draw(tree, 0, 0,
+ cocoa_pt_to_px(NSMinX( rect )),
+ cocoa_pt_to_px(NSMinY( rect )),
+ cocoa_pt_to_px(NSWidth( rect )),
+ cocoa_pt_to_px(NSHeight( rect )),
+ &ctx );
}
-- (void) mouseAction: (browser_mouse_state)state atPoint: (NSPoint)point;
+- (void) mouseAction: (browser_mouse_state)state atPoint: (NSPoint)point
{
- tree_mouse_action( tree, state, cocoa_pt_to_px( point.x ), cocoa_pt_to_px( point.y ) );
+ tree_mouse_action(tree, state,
+ cocoa_pt_to_px( point.x ), cocoa_pt_to_px( point.y ));
}
-- (void) mouseDragEnd: (browser_mouse_state)state fromPoint: (NSPoint)p0 toPoint: (NSPoint) p1;
+- (void) mouseDragEnd: (browser_mouse_state)state fromPoint: (NSPoint)p0 toPoint: (NSPoint) p1
{
- tree_drag_end( tree, state,
- cocoa_pt_to_px( p0.x ), cocoa_pt_to_px( p0.y ),
- cocoa_pt_to_px( p1.x ), cocoa_pt_to_px( p1.y ) );
+ tree_drag_end(tree, state,
+ cocoa_pt_to_px( p0.x ), cocoa_pt_to_px( p0.y ),
+ cocoa_pt_to_px( p1.x ), cocoa_pt_to_px( p1.y ));
}
- (void) keyPress: (uint32_t) key;
{
- tree_keypress( tree, key );
+ tree_keypress( tree, key );
}
@end
-
diff --git a/cocoa/TreeView.m b/cocoa/TreeView.m
index 0c7f3e0b3..a58a49623 100644
--- a/cocoa/TreeView.m
+++ b/cocoa/TreeView.m
@@ -29,217 +29,221 @@
@synthesize tree;
-- (void)drawRect:(NSRect)dirtyRect
+- (void)drawRect:(NSRect)dirtyRect
{
- [tree drawRect: dirtyRect inView: self];
+ [tree drawRect: dirtyRect inView: self];
}
-- (BOOL) isFlipped;
+- (BOOL) isFlipped
{
- return YES;
+ return YES;
}
-- (BOOL) acceptsFirstResponder;
+- (BOOL) acceptsFirstResponder
{
- return YES;
+ return YES;
}
-- (void) dealloc;
+- (void) dealloc
{
- [self setTree: nil];
- [super dealloc];
+ [self setTree: nil];
+ [super dealloc];
}
-- (void) setTree: (Tree *)newTree;
+- (void) setTree: (Tree *)newTree
{
- if (tree != newTree) {
- [tree setRedrawing: NO];
- [tree setDelegate: nil];
- [tree release];
-
- tree = [newTree retain];
- [tree setDelegate: self];
- [tree setRedrawing: YES];
-
- [self setNeedsDisplay: YES];
- }
+ if (tree != newTree) {
+ [tree setRedrawing: NO];
+ [tree setDelegate: nil];
+ [tree release];
+
+ tree = [newTree retain];
+ [tree setDelegate: self];
+ [tree setRedrawing: YES];
+
+ [self setNeedsDisplay: YES];
+ }
}
//MARK: -
//MARK: Event handlers
-- (void)mouseDown: (NSEvent *)event;
+- (void)mouseDown: (NSEvent *)event
{
- isDragging = NO;
- dragStart = [self convertPoint: [event locationInWindow] fromView: nil];
- [tree mouseAction: BROWSER_MOUSE_PRESS_1 atPoint: dragStart];
+ isDragging = NO;
+ dragStart = [self convertPoint: [event locationInWindow] fromView: nil];
+ [tree mouseAction: BROWSER_MOUSE_PRESS_1 atPoint: dragStart];
}
#define squared(x) ((x)*(x))
#define MinDragDistance (5.0)
-- (void) mouseDragged: (NSEvent *)event;
+- (void) mouseDragged: (NSEvent *)event
{
- const NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
-
- if (!isDragging) {
- const CGFloat distance = squared( dragStart.x - point.x ) + squared( dragStart.y - point.y );
- if (distance >= squared( MinDragDistance)) isDragging = YES;
- }
+ const NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
+
+ if (!isDragging) {
+ const CGFloat distance = squared( dragStart.x - point.x ) + squared( dragStart.y - point.y );
+ if (distance >= squared( MinDragDistance)) {
+ isDragging = YES;
+ }
+ }
}
-- (void) mouseUp: (NSEvent *)event;
+- (void) mouseUp: (NSEvent *)event
{
- const NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
+ const NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
+
+ browser_mouse_state modifierFlags = 0;
- browser_mouse_state modifierFlags = 0;
-
- if (isDragging) {
- isDragging = NO;
- [tree mouseDragEnd: modifierFlags fromPoint: dragStart toPoint: point];
- } else {
- modifierFlags |= BROWSER_MOUSE_CLICK_1;
- if ([event clickCount] == 2) modifierFlags |= BROWSER_MOUSE_DOUBLE_CLICK;
- [tree mouseAction: modifierFlags atPoint: point];
- }
+ if (isDragging) {
+ isDragging = NO;
+ [tree mouseDragEnd: modifierFlags fromPoint: dragStart toPoint: point];
+ } else {
+ modifierFlags |= BROWSER_MOUSE_CLICK_1;
+ if ([event clickCount] == 2) {
+ modifierFlags |= BROWSER_MOUSE_DOUBLE_CLICK;
+ }
+ [tree mouseAction: modifierFlags atPoint: point];
+ }
}
//MARK: Keyboard events
-- (void) keyDown: (NSEvent *)theEvent;
+- (void) keyDown: (NSEvent *)theEvent
{
- [self interpretKeyEvents: [NSArray arrayWithObject: theEvent]];
+ [self interpretKeyEvents: [NSArray arrayWithObject: theEvent]];
}
-- (void) insertText: (id)string;
+- (void) insertText: (id)string
{
- for (NSUInteger i = 0, length = [string length]; i < length; i++) {
- unichar ch = [string characterAtIndex: i];
- [tree keyPress: ch];
- }
+ for (NSUInteger i = 0, length = [string length]; i < length; i++) {
+ unichar ch = [string characterAtIndex: i];
+ [tree keyPress: ch];
+ }
}
-- (void) moveLeft: (id)sender;
+- (void) moveLeft: (id)sender
{
- [tree keyPress: NS_KEY_LEFT];
+ [tree keyPress: NS_KEY_LEFT];
}
-- (void) moveRight: (id)sender;
+- (void) moveRight: (id)sender
{
- [tree keyPress: NS_KEY_RIGHT];
+ [tree keyPress: NS_KEY_RIGHT];
}
-- (void) moveUp: (id)sender;
+- (void) moveUp: (id)sender
{
- [tree keyPress: NS_KEY_UP];
+ [tree keyPress: NS_KEY_UP];
}
-- (void) moveDown: (id)sender;
+- (void) moveDown: (id)sender
{
- [tree keyPress: NS_KEY_DOWN];
+ [tree keyPress: NS_KEY_DOWN];
}
-- (void) deleteBackward: (id)sender;
+- (void) deleteBackward: (id)sender
{
- [tree keyPress: NS_KEY_DELETE_LEFT];
+ [tree keyPress: NS_KEY_DELETE_LEFT];
}
-- (void) deleteForward: (id)sender;
+- (void) deleteForward: (id)sender
{
- [tree keyPress: NS_KEY_DELETE_RIGHT];
+ [tree keyPress: NS_KEY_DELETE_RIGHT];
}
-- (void) cancelOperation: (id)sender;
+- (void) cancelOperation: (id)sender
{
- [tree keyPress: NS_KEY_ESCAPE];
+ [tree keyPress: NS_KEY_ESCAPE];
}
-- (void) scrollPageUp: (id)sender;
+- (void) scrollPageUp: (id)sender
{
- [tree keyPress: NS_KEY_PAGE_UP];
+ [tree keyPress: NS_KEY_PAGE_UP];
}
-- (void) scrollPageDown: (id)sender;
+- (void) scrollPageDown: (id)sender
{
- [tree keyPress: NS_KEY_PAGE_DOWN];
+ [tree keyPress: NS_KEY_PAGE_DOWN];
}
-- (void) insertTab: (id)sender;
+- (void) insertTab: (id)sender
{
- [tree keyPress: NS_KEY_TAB];
+ [tree keyPress: NS_KEY_TAB];
}
-- (void) insertBacktab: (id)sender;
+- (void) insertBacktab: (id)sender
{
- [tree keyPress: NS_KEY_SHIFT_TAB];
+ [tree keyPress: NS_KEY_SHIFT_TAB];
}
-- (void) moveToBeginningOfLine: (id)sender;
+- (void) moveToBeginningOfLine: (id)sender
{
- [tree keyPress: NS_KEY_LINE_START];
+ [tree keyPress: NS_KEY_LINE_START];
}
-- (void) moveToEndOfLine: (id)sender;
+- (void) moveToEndOfLine: (id)sender
{
- [tree keyPress: NS_KEY_LINE_END];
+ [tree keyPress: NS_KEY_LINE_END];
}
-- (void) moveToBeginningOfDocument: (id)sender;
+- (void) moveToBeginningOfDocument: (id)sender
{
- [tree keyPress: NS_KEY_TEXT_START];
+ [tree keyPress: NS_KEY_TEXT_START];
}
-- (void) moveToEndOfDocument: (id)sender;
+- (void) moveToEndOfDocument: (id)sender
{
- [tree keyPress: NS_KEY_TEXT_END];
+ [tree keyPress: NS_KEY_TEXT_END];
}
-- (void) insertNewline: (id)sender;
+- (void) insertNewline: (id)sender
{
- [tree keyPress: NS_KEY_NL];
+ [tree keyPress: NS_KEY_NL];
}
-- (void) selectAll: (id)sender;
+- (void) selectAll: (id)sender
{
- [tree keyPress: NS_KEY_SELECT_ALL];
+ [tree keyPress: NS_KEY_SELECT_ALL];
}
-- (void) copy: (id) sender;
+- (void) copy: (id) sender
{
- [tree keyPress: NS_KEY_COPY_SELECTION];
+ [tree keyPress: NS_KEY_COPY_SELECTION];
}
-- (void) cut: (id) sender;
+- (void) cut: (id) sender
{
- [tree keyPress: NS_KEY_CUT_SELECTION];
+ [tree keyPress: NS_KEY_CUT_SELECTION];
}
-- (void) paste: (id) sender;
+- (void) paste: (id) sender
{
- [tree keyPress: NS_KEY_PASTE];
+ [tree keyPress: NS_KEY_PASTE];
}
//MARK: -
//MARK: Tree delegate methods
-- (void) tree: (Tree *)t requestedRedrawInRect: (NSRect) rect;
+- (void) tree: (Tree *)t requestedRedrawInRect: (NSRect) rect
{
- [self setNeedsDisplayInRect: rect];
+ [self setNeedsDisplayInRect: rect];
}
-- (void) tree: (Tree *)t resized: (NSSize) size;
+- (void) tree: (Tree *)t resized: (NSSize) size
{
- [self setMinimumSize: size];
+ [self setMinimumSize: size];
}
-- (void) tree: (Tree *)t scrollPoint: (NSPoint) point;
+- (void) tree: (Tree *)t scrollPoint: (NSPoint) point
{
- [self scrollPoint: point];
+ [self scrollPoint: point];
}
-- (NSSize) treeWindowSize: (Tree *)t;
+- (NSSize) treeWindowSize: (Tree *)t
{
- return [self frame].size;
+ return [self frame].size;
}
@end