summaryrefslogtreecommitdiff
path: root/frontends/cocoa
diff options
context:
space:
mode:
authorSven Weidauer <sven@5sw.de>2017-06-05 12:43:11 +0200
committerSven Weidauer <sven@5sw.de>2017-06-05 12:43:11 +0200
commite51c739bfc8e0c50161172952c99b8796703c6fe (patch)
tree1b3a47b5123aad511bc91a2b589a2dd2949549e3 /frontends/cocoa
parent2ba97ae0dbd01a4f46c543ae025249e5349e0585 (diff)
downloadnetsurf-e51c739bfc8e0c50161172952c99b8796703c6fe.tar.gz
netsurf-e51c739bfc8e0c50161172952c99b8796703c6fe.tar.bz2
Start modernising ObjC
Diffstat (limited to 'frontends/cocoa')
-rw-r--r--frontends/cocoa/.clang-format1
-rw-r--r--frontends/cocoa/BrowserWindow.h5
-rw-r--r--frontends/cocoa/BrowserWindow.m2
-rw-r--r--frontends/cocoa/FormSelectMenu.h13
-rw-r--r--frontends/cocoa/FormSelectMenu.m42
-rw-r--r--frontends/cocoa/HistoryWindowController.h7
-rw-r--r--frontends/cocoa/HistoryWindowController.m12
-rw-r--r--frontends/cocoa/LocalHistoryController.m17
-rw-r--r--frontends/cocoa/NetSurfAppDelegate.h22
-rw-r--r--frontends/cocoa/NetSurfAppDelegate.m30
-rw-r--r--frontends/cocoa/NetsurfApp.h4
-rw-r--r--frontends/cocoa/ScrollableView.h10
-rw-r--r--frontends/cocoa/ScrollableView.m22
-rw-r--r--frontends/cocoa/SearchWindowController.h33
-rw-r--r--frontends/cocoa/SearchWindowController.m40
-rw-r--r--frontends/cocoa/Tree.h30
-rw-r--r--frontends/cocoa/Tree.m55
-rw-r--r--frontends/cocoa/TreeView.h10
-rw-r--r--frontends/cocoa/TreeView.m93
-rw-r--r--frontends/cocoa/URLFieldCell.h12
-rw-r--r--frontends/cocoa/URLFieldCell.m45
21 files changed, 232 insertions, 273 deletions
diff --git a/frontends/cocoa/.clang-format b/frontends/cocoa/.clang-format
index 1b3e2b921..4beec6630 100644
--- a/frontends/cocoa/.clang-format
+++ b/frontends/cocoa/.clang-format
@@ -1,5 +1,4 @@
---
-Language: ObjC
BasedOnStyle: WebKit
PointerAlignment: Right
SortIncludes: false
diff --git a/frontends/cocoa/BrowserWindow.h b/frontends/cocoa/BrowserWindow.h
index e0b83017f..44f23f699 100644
--- a/frontends/cocoa/BrowserWindow.h
+++ b/frontends/cocoa/BrowserWindow.h
@@ -19,8 +19,5 @@
#import <Cocoa/Cocoa.h>
-@interface BrowserWindow : NSWindow {
-
-}
-
+@interface BrowserWindow : NSWindow
@end
diff --git a/frontends/cocoa/BrowserWindow.m b/frontends/cocoa/BrowserWindow.m
index f30dc17a7..c50e66a87 100644
--- a/frontends/cocoa/BrowserWindow.m
+++ b/frontends/cocoa/BrowserWindow.m
@@ -23,7 +23,7 @@
- (void)performClose:(id)sender
{
- [[self windowController] closeCurrentTab:sender];
+ [self.windowController closeCurrentTab:sender];
}
@end
diff --git a/frontends/cocoa/FormSelectMenu.h b/frontends/cocoa/FormSelectMenu.h
index cec519296..3ed86e315 100644
--- a/frontends/cocoa/FormSelectMenu.h
+++ b/frontends/cocoa/FormSelectMenu.h
@@ -18,15 +18,12 @@
#import <Cocoa/Cocoa.h>
-@interface FormSelectMenu : NSObject {
- NSMenu *menu;
- NSPopUpButtonCell *cell;
+struct form_control;
+struct browser_window;
- struct browser_window *browser;
- struct form_control *control;
-}
+@interface FormSelectMenu : NSObject
-- (id)initWithControl: (struct form_control *) control forWindow: (struct browser_window *) window;
-- (void) runInView: (NSView *) view;
+- (instancetype)initWithControl:(struct form_control *)control forWindow:(struct browser_window *)window;
+- (void)runInView:(NSView *)view;
@end
diff --git a/frontends/cocoa/FormSelectMenu.m b/frontends/cocoa/FormSelectMenu.m
index e089b0f59..c849ba0c2 100644
--- a/frontends/cocoa/FormSelectMenu.m
+++ b/frontends/cocoa/FormSelectMenu.m
@@ -36,44 +36,50 @@ static inline NSRect cocoa_rect_for_control(struct browser_window *bw, struct fo
@interface FormSelectMenu () <NSMenuDelegate>
+@property (nonatomic) NSMenu *menu;
+@property (nonatomic) NSPopUpButtonCell *cell;
+
+@property (nonatomic) struct browser_window *browser;
+@property (nonatomic) struct form_control *control;
+
- (void)itemSelected:(id)sender;
@end
@implementation FormSelectMenu
-- (id)initWithControl:(struct form_control *)c forWindow:(struct browser_window *)w
+- (instancetype)initWithControl:(struct form_control *)c forWindow:(struct browser_window *)w
{
if ((self = [super init]) == nil)
return nil;
- control = c;
- browser = w;
+ _control = c;
+ _browser = w;
- menu = [[NSMenu alloc] initWithTitle:@"Select"];
- if (menu == nil) {
+ _menu = [[NSMenu alloc] initWithTitle:@"Select"];
+ if (_menu == nil) {
return nil;
}
- [menu addItemWithTitle:@"" action:NULL keyEquivalent:@""];
+ [_menu addItemWithTitle:@"" action:NULL keyEquivalent:@""];
NSInteger currentItemIndex = 0;
struct form_option *opt;
- for (opt = form_select_get_option(control, 0);
+ 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.state = NSOnState;
}
- [item setTarget:self];
- [item setTag:currentItemIndex++];
- [menu addItem:item];
+ item.target = self;
+ item.tag = currentItemIndex++;
+ [_menu addItem:item];
}
- [menu setDelegate:self];
+ _menu.delegate = self;
return self;
}
@@ -82,18 +88,18 @@ static inline NSRect cocoa_rect_for_control(struct browser_window *bw, struct fo
{
(void)(__bridge_retained void *) self;
- cell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES];
- [cell setMenu:menu];
+ _cell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES];
+ _cell.menu = _menu;
- const NSRect rect = cocoa_rect_for_control(browser, control);
+ const NSRect rect = cocoa_rect_for_control(_browser, _control);
- [cell attachPopUpWithFrame:rect inView:view];
- [cell performClickWithFrame:rect inView:view];
+ [_cell attachPopUpWithFrame:rect inView:view];
+ [_cell performClickWithFrame:rect inView:view];
}
- (void)itemSelected:(id)sender
{
- form_select_process_selection(control, (int)[sender tag]);
+ form_select_process_selection(_control, (int)[sender tag]);
}
- (void)menuDidClose:(NSMenu *)sender
diff --git a/frontends/cocoa/HistoryWindowController.h b/frontends/cocoa/HistoryWindowController.h
index 3b1d97679..c16236c2d 100644
--- a/frontends/cocoa/HistoryWindowController.h
+++ b/frontends/cocoa/HistoryWindowController.h
@@ -18,13 +18,10 @@
#import <Cocoa/Cocoa.h>
-@class Tree;
@class TreeView;
-@interface HistoryWindowController : NSWindowController {
- Tree *tree;
-}
+@interface HistoryWindowController : NSWindowController
-@property (readwrite, nonatomic) IBOutlet TreeView *view;
+@property (nonatomic) IBOutlet TreeView *view;
@end
diff --git a/frontends/cocoa/HistoryWindowController.m b/frontends/cocoa/HistoryWindowController.m
index 1a30bb573..8b7067c24 100644
--- a/frontends/cocoa/HistoryWindowController.m
+++ b/frontends/cocoa/HistoryWindowController.m
@@ -22,23 +22,27 @@
#import "desktop/global_history.h"
-@implementation HistoryWindowController
+@interface HistoryWindowController ()
+
+@property (nonatomic) Tree *tree;
-@synthesize view;
+@end
+
+@implementation HistoryWindowController
- (instancetype)init
{
if ((self = [super initWithWindowNibName:@"HistoryWindow"]) == nil)
return nil;
- tree = [[Tree alloc] initWithFlags:TREE_HISTORY];
+ _tree = [[Tree alloc] initWithFlags:TREE_HISTORY];
return self;
}
- (void)awakeFromNib
{
- [view setTree:tree];
+ self.view.tree = self.tree;
[[self window] setExcludedFromWindowsMenu:YES];
}
diff --git a/frontends/cocoa/LocalHistoryController.m b/frontends/cocoa/LocalHistoryController.m
index 805539669..b54359ffc 100644
--- a/frontends/cocoa/LocalHistoryController.m
+++ b/frontends/cocoa/LocalHistoryController.m
@@ -24,15 +24,12 @@
@implementation LocalHistoryController
-@synthesize browser;
-@synthesize history;
-
- (instancetype)initWithBrowser:(BrowserView *)bw
{
if ((self = [super initWithWindowNibName:@"LocalHistoryPanel"]) == nil)
return nil;
- browser = bw;
+ _browser = bw;
return self;
}
@@ -43,9 +40,9 @@
ArrowWindow *box = (ArrowWindow *)[self window];
- [box setContentSize:[history size]];
+ box.contentSize = self.history.size;
[box setArrowPosition:50];
- [history updateHistory];
+ [self.history updateHistory];
[box attachToView:view];
NSRect frame = [box frame];
@@ -95,12 +92,14 @@
- (void)windowDidLoad
{
- [history setBrowser:browser];
+ [super windowDidLoad];
+
+ self.history.browser = self.browser;
}
- (void)redraw
{
- [history setNeedsDisplay:YES];
+ [self.history setNeedsDisplay:YES];
}
- (void)keyDown:(NSEvent *)theEvent
@@ -108,7 +107,7 @@
unichar key = [[theEvent characters] characterAtIndex:0];
switch (key) {
case 27:
- [browser setHistoryVisible:NO];
+ [self.browser setHistoryVisible:NO];
break;
default:
diff --git a/frontends/cocoa/NetSurfAppDelegate.h b/frontends/cocoa/NetSurfAppDelegate.h
index a22c4ceee..37d07a4d2 100644
--- a/frontends/cocoa/NetSurfAppDelegate.h
+++ b/frontends/cocoa/NetSurfAppDelegate.h
@@ -22,21 +22,17 @@
@class PreferencesWindowController;
@class HistoryWindowController;
-@interface NetSurfAppDelegate : NSObject {
- SearchWindowController *search;
- PreferencesWindowController *preferences;
- HistoryWindowController *history;
-}
+@interface NetSurfAppDelegate : NSObject
-@property (readwrite, retain, nonatomic) SearchWindowController *search;
-@property (readwrite, retain, nonatomic) PreferencesWindowController *preferences;
-@property (readwrite, retain, nonatomic) HistoryWindowController *history;
+@property (nonatomic) SearchWindowController *search;
+@property (nonatomic) PreferencesWindowController *preferences;
+@property (nonatomic) HistoryWindowController *history;
-- (IBAction) showSearchWindow: (id) sender;
-- (IBAction) searchForward: (id) sender;
-- (IBAction) searchBackward: (id) sender;
+- (IBAction)showSearchWindow:(id)sender;
+- (IBAction)searchForward:(id)sender;
+- (IBAction)searchBackward:(id)sender;
-- (IBAction) showPreferences: (id) sender;
-- (IBAction) showGlobalHistory: (id) sender;
+- (IBAction)showPreferences:(id)sender;
+- (IBAction)showGlobalHistory:(id)sender;
@end
diff --git a/frontends/cocoa/NetSurfAppDelegate.m b/frontends/cocoa/NetSurfAppDelegate.m
index 55cd714f0..013b77a8d 100644
--- a/frontends/cocoa/NetSurfAppDelegate.m
+++ b/frontends/cocoa/NetSurfAppDelegate.m
@@ -36,10 +36,6 @@
@implementation NetSurfAppDelegate
-@synthesize history;
-@synthesize search;
-@synthesize preferences;
-
- (void)newDocument:(id)sender
{
nsurl *url;
@@ -111,20 +107,20 @@
- (IBAction)showSearchWindow:(id)sender
{
- if (search == nil) {
- [self setSearch:[[SearchWindowController alloc] init]];
+ if (self.search == nil) {
+ self.search = [[SearchWindowController alloc] init];
}
- [[search window] makeKeyAndOrderFront:self];
+ [self.search.window makeKeyAndOrderFront:self];
}
- (IBAction)searchForward:(id)sender
{
- [search search:SearchForward];
+ [self.search search:SearchForward];
}
- (IBAction)searchBackward:(id)sender
{
- [search search:SearchBackward];
+ [self.search search:SearchBackward];
}
- (BOOL)validateMenuItem:(id)item
@@ -132,9 +128,9 @@
SEL action = [item action];
if (action == @selector(searchForward:)) {
- return [search canGoForward];
+ return [self.search canGoForward];
} else if (action == @selector(searchBackward:)) {
- return [search canGoBack];
+ return [self.search canGoBack];
}
return YES;
@@ -142,18 +138,18 @@
- (IBAction)showPreferences:(id)sender
{
- if (preferences == nil) {
- [self setPreferences:[[PreferencesWindowController alloc] init]];
+ if (self.preferences == nil) {
+ self.preferences = [[PreferencesWindowController alloc] init];
}
- [preferences showWindow:sender];
+ [self.preferences showWindow:sender];
}
- (IBAction)showGlobalHistory:(id)sender
{
- if (history == nil) {
- [self setHistory:[[HistoryWindowController alloc] init]];
+ if (self.history == nil) {
+ self.history = [[HistoryWindowController alloc] init];
}
- [history showWindow:sender];
+ [self.history showWindow:sender];
}
// Application delegate methods
diff --git a/frontends/cocoa/NetsurfApp.h b/frontends/cocoa/NetsurfApp.h
index ea2802aee..03bf45446 100644
--- a/frontends/cocoa/NetsurfApp.h
+++ b/frontends/cocoa/NetsurfApp.h
@@ -22,8 +22,8 @@
@interface NetSurfApp : NSApplication
-@property (readwrite, nonatomic) BrowserViewController *frontTab;
+@property (nonatomic) BrowserViewController *frontTab;
@end
-NSString *cocoa_get_user_path( NSString *fileName );
+NSString *cocoa_get_user_path(NSString *fileName);
diff --git a/frontends/cocoa/ScrollableView.h b/frontends/cocoa/ScrollableView.h
index 071a11825..f8605f137 100644
--- a/frontends/cocoa/ScrollableView.h
+++ b/frontends/cocoa/ScrollableView.h
@@ -18,14 +18,10 @@
#import <Cocoa/Cocoa.h>
+@interface ScrollableView : NSView
-@interface ScrollableView : NSView {
- NSSize minimumSize;
- NSView *observedSuperview;
-}
+@property (nonatomic) NSSize minimumSize;
-@property (readwrite, assign, nonatomic) NSSize minimumSize;
-
-- (void) adjustFrame;
+- (void)adjustFrame;
@end
diff --git a/frontends/cocoa/ScrollableView.m b/frontends/cocoa/ScrollableView.m
index e31d90ade..b2210d059 100644
--- a/frontends/cocoa/ScrollableView.m
+++ b/frontends/cocoa/ScrollableView.m
@@ -20,24 +20,25 @@
@interface ScrollableView ()
+@property (weak, nonatomic) NSView *observedSuperview;
+
- (void)frameChangeNotification:(NSNotification *)note;
@end
@implementation ScrollableView
-@synthesize minimumSize;
- (void)setMinimumSize:(NSSize)newSize
{
- minimumSize = newSize;
+ _minimumSize = newSize;
[self adjustFrame];
}
- (void)adjustFrame
{
NSSize frameSize = [[self superview] frame].size;
- [self setFrameSize:NSMakeSize(MAX(minimumSize.width, frameSize.width),
- MAX(minimumSize.height, frameSize.height))];
+ [self setFrameSize:NSMakeSize(MAX(self.minimumSize.width, frameSize.width),
+ MAX(self.minimumSize.height, frameSize.height))];
}
- (void)frameChangeNotification:(NSNotification *)note
@@ -47,24 +48,25 @@
- (void)viewDidMoveToSuperview
{
- if (observedSuperview) {
+ NSView *oldSuperview = _observedSuperview;
+ _observedSuperview = nil;
+ if (oldSuperview) {
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:NSViewFrameDidChangeNotification
- object:observedSuperview];
- observedSuperview = nil;
+ object:oldSuperview];
}
NSView *newSuperView = [self superview];
if (nil != newSuperView) {
- observedSuperview = newSuperView;
+ _observedSuperview = newSuperView;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(frameChangeNotification:)
name:NSViewFrameDidChangeNotification
- object:observedSuperview];
- [observedSuperview setPostsFrameChangedNotifications:YES];
+ object:newSuperView];
+ newSuperView.postsFrameChangedNotifications = YES;
}
}
diff --git a/frontends/cocoa/SearchWindowController.h b/frontends/cocoa/SearchWindowController.h
index 9d7b5b290..a1e84c364 100644
--- a/frontends/cocoa/SearchWindowController.h
+++ b/frontends/cocoa/SearchWindowController.h
@@ -16,37 +16,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#import <Cocoa/Cocoa.h>
@class BrowserViewController;
typedef enum {
- SearchBackward,
- SearchForward
+ SearchBackward,
+ SearchForward
} SearchDirection;
-@interface SearchWindowController : NSWindowController {
- BOOL caseSensitive;
- BOOL selectAll;
- BOOL canGoBack;
- BOOL canGoForward;
- NSString *searchString;
-}
+@interface SearchWindowController : NSWindowController
-@property (readwrite, nonatomic) BOOL caseSensitive;
-@property (readwrite, nonatomic) BOOL selectAll;
-@property (readwrite, nonatomic) BOOL canGoBack;
-@property (readwrite, nonatomic) BOOL canGoForward;
-@property (readwrite, copy, nonatomic) NSString *searchString;
-@property (readwrite, nonatomic) BrowserViewController *browser;
+@property (nonatomic) BOOL caseSensitive;
+@property (nonatomic) BOOL selectAll;
+@property (nonatomic) BOOL canGoBack;
+@property (nonatomic) BOOL canGoForward;
+@property (copy, nonatomic) NSString *searchString;
+@property (nonatomic) BrowserViewController *browser;
-- (IBAction) searchNext: (id) sender;
-- (IBAction) searchPrevious: (id) sender;
+- (IBAction)searchNext:(id)sender;
+- (IBAction)searchPrevious:(id)sender;
-- (IBAction) searchStringDidChange: (id) sender;
+- (IBAction)searchStringDidChange:(id)sender;
-- (void) search: (SearchDirection)direction;
+- (void)search:(SearchDirection)direction;
@end
diff --git a/frontends/cocoa/SearchWindowController.m b/frontends/cocoa/SearchWindowController.m
index 5dccc5950..347fb1cb9 100644
--- a/frontends/cocoa/SearchWindowController.m
+++ b/frontends/cocoa/SearchWindowController.m
@@ -35,20 +35,14 @@ struct gui_search_table *cocoa_search_table = &search_table;
@implementation SearchWindowController
-@synthesize caseSensitive;
-@synthesize selectAll;
-@synthesize canGoBack;
-@synthesize canGoForward;
-@synthesize searchString;
-@synthesize browser;
-
- (instancetype)init
{
if ((self = [super initWithWindowNibName:@"SearchWindow"]) == nil)
return nil;
[self bind:@"browser" toObject:NSApp withKeyPath:@"frontTab" options:nil];
- canGoBack = canGoForward = YES;
+ _canGoBack = YES;
+ _canGoForward = YES;
return self;
}
@@ -71,18 +65,22 @@ struct gui_search_table *cocoa_search_table = &search_table;
- (void)search:(SearchDirection)direction
{
search_flags_t flags = (direction == SearchForward) ? SEARCH_FLAG_FORWARDS : 0;
- if (caseSensitive)
+
+ if (self.caseSensitive) {
flags |= SEARCH_FLAG_CASE_SENSITIVE;
- if (selectAll)
+ }
+
+ if (self.selectAll) {
flags |= SEARCH_FLAG_SHOWALL;
+ }
- struct browser_window *bw = [browser browser];
- browser_window_search(bw, (__bridge void *)self, flags, [searchString UTF8String]);
+ struct browser_window *bw = self.browser.browser;
+ browser_window_search(bw, (__bridge void *)self, flags, self.searchString.UTF8String);
}
- (IBAction)searchStringDidChange:(id)sender
{
- struct browser_window *bw = [browser browser];
+ struct browser_window *bw = self.browser.browser;
browser_window_search_clear(bw);
[self setCanGoBack:YES];
@@ -91,19 +89,19 @@ struct gui_search_table *cocoa_search_table = &search_table;
- (void)setCaseSensitive:(BOOL)newValue
{
- if (caseSensitive != newValue) {
- caseSensitive = newValue;
- [self setCanGoBack:YES];
- [self setCanGoForward:YES];
+ if (_caseSensitive != newValue) {
+ _caseSensitive = newValue;
+ self.canGoBack = YES;
+ self.canGoForward = YES;
}
}
- (void)setSelectAll:(BOOL)newValue
{
- if (selectAll != newValue) {
- selectAll = newValue;
- [self setCanGoBack:YES];
- [self setCanGoForward:YES];
+ if (_selectAll != newValue) {
+ _selectAll = newValue;
+ self.canGoBack = YES;
+ self.canGoForward = YES;
}
}
diff --git a/frontends/cocoa/Tree.h b/frontends/cocoa/Tree.h
index 2143a704b..d898f4e4b 100644
--- a/frontends/cocoa/Tree.h
+++ b/frontends/cocoa/Tree.h
@@ -24,33 +24,29 @@
@protocol TreeDelegate
-- (void) tree: (Tree *)tree requestedRedrawInRect: (NSRect) rect;
-- (void) tree: (Tree *)tree resized: (NSSize) size;
-- (void) tree: (Tree *)tree scrollPoint: (NSPoint) point;
-- (NSSize) treeWindowSize: (Tree *)tree;
+- (void)tree:(Tree *)tree requestedRedrawInRect:(NSRect)rect;
+- (void)tree:(Tree *)tree resized:(NSSize)size;
+- (void)tree:(Tree *)tree scrollPoint:(NSPoint)point;
+- (NSSize)treeWindowSize:(Tree *)tree;
@end
+@interface Tree : NSObject
-@interface Tree : NSObject {
- struct tree *tree;
-}
+@property (weak, nonatomic) id<TreeDelegate> delegate;
+@property (readonly) struct tree *tree;
-@property (readwrite, weak, nonatomic) id <TreeDelegate> delegate;
+- (instancetype)initWithFlags:(unsigned int)flags;
-- (id)initWithFlags: (unsigned int) flags;
-
-- (struct tree *) tree;
-- (void) setRedrawing: (BOOL) newRedrawing;
+- (void)setRedrawing:(BOOL)newRedrawing;
@end
-
@interface Tree (ViewInterface)
-- (void) drawRect: (NSRect) rect inView: (NSView *) view;
-- (void) mouseAction: (browser_mouse_state)state atPoint: (NSPoint)point;
-- (void) mouseDragEnd: (browser_mouse_state)state fromPoint: (NSPoint)p0 toPoint: (NSPoint) p1;
-- (void) keyPress: (uint32_t) key;
+- (void)drawRect:(NSRect)rect inView:(NSView *)view;
+- (void)mouseAction:(browser_mouse_state)state atPoint:(NSPoint)point;
+- (void)mouseDragEnd:(browser_mouse_state)state fromPoint:(NSPoint)p0 toPoint:(NSPoint)p1;
+- (void)keyPress:(uint32_t)key;
@end
diff --git a/frontends/cocoa/Tree.m b/frontends/cocoa/Tree.m
index 0fa397665..1b834691e 100644
--- a/frontends/cocoa/Tree.m
+++ b/frontends/cocoa/Tree.m
@@ -27,8 +27,6 @@
@implementation Tree
-@synthesize delegate;
-
static void tree_redraw_request(int x, int y, int w, int h, void *data);
static void tree_resized(struct tree *tree, int w, int h, void *data);
static void tree_scroll_visible(int y, int height, void *data);
@@ -41,13 +39,13 @@ static const struct treeview_table cocoa_tree_callbacks = {
.get_window_dimensions = tree_get_window_dimensions
};
-- (id)initWithFlags:(unsigned int)flags
+- (instancetype)initWithFlags:(unsigned int)flags
{
if ((self = [super init]) == nil)
return nil;
- tree = tree_create(flags, &cocoa_tree_callbacks, (__bridge void *)self);
- if (tree == NULL) {
+ _tree = tree_create(flags, &cocoa_tree_callbacks, (__bridge void *)self);
+ if (_tree == NULL) {
return nil;
}
@@ -56,55 +54,52 @@ static const struct treeview_table cocoa_tree_callbacks = {
- (void)dealloc
{
- tree_delete(tree);
-}
-
-- (struct tree *)tree
-{
- return tree;
+ tree_delete(_tree);
}
- (void)setRedrawing:(BOOL)newRedrawing
{
}
-+ (void)initialize
-{
-}
-
//MARK: -
//MARK: Callbacks
static void tree_redraw_request(int x, int y, int w, int h, void *data)
{
- id<TreeDelegate> delegate = ((__bridge Tree *)data)->delegate;
- [delegate tree:(__bridge Tree *)data requestedRedrawInRect:cocoa_rect_wh(x, y, w, h)];
+ Tree *tree = (__bridge Tree *)data;
+ [tree.delegate tree:tree requestedRedrawInRect:cocoa_rect_wh(x, y, w, h)];
}
static void tree_resized(struct tree *tree, int w, int h, void *data)
{
- id<TreeDelegate> delegate = ((__bridge Tree *)data)->delegate;
- [delegate tree:(__bridge Tree *)data resized:cocoa_size(w, h)];
+ Tree *cocoaTree = (__bridge Tree *)data;
+ [cocoaTree.delegate tree:cocoaTree resized:cocoa_size(w, h)];
}
static void tree_scroll_visible(int y, int height, void *data)
{
- id<TreeDelegate> delegate = ((__bridge Tree *)data)->delegate;
- [delegate tree:(__bridge Tree *)data scrollPoint:cocoa_point(0, y)];
+ Tree *tree = (__bridge Tree *)data;
+ [tree.delegate tree:tree scrollPoint:cocoa_point(0, y)];
}
static void tree_get_window_dimensions(int *width, int *height, void *data)
{
- id<TreeDelegate> delegate = ((__bridge Tree *)data)->delegate;
- if (delegate == nil)
+ Tree *tree = (__bridge Tree *)data;
+ id<TreeDelegate> delegate = tree.delegate;
+
+ if (delegate == nil) {
return;
+ }
- NSSize size = [delegate treeWindowSize:(__bridge Tree *)data];
+ NSSize size = [delegate treeWindowSize:tree];
- if (width != NULL)
+ if (width != NULL) {
*width = cocoa_pt_to_px(size.width);
- if (height != NULL)
+ }
+
+ if (height != NULL) {
*height = cocoa_pt_to_px(size.height);
+ }
}
@end
@@ -119,7 +114,7 @@ static void tree_get_window_dimensions(int *width, int *height, void *data)
.plot = &cocoa_plotters
};
- tree_draw(tree, 0, 0,
+ tree_draw(self.tree, 0, 0,
cocoa_pt_to_px(NSMinX(rect)),
cocoa_pt_to_px(NSMinY(rect)),
cocoa_pt_to_px(NSWidth(rect)),
@@ -129,20 +124,20 @@ static void tree_get_window_dimensions(int *width, int *height, void *data)
- (void)mouseAction:(browser_mouse_state)state atPoint:(NSPoint)point
{
- tree_mouse_action(tree, state,
+ tree_mouse_action(self.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
{
- tree_drag_end(tree, state,
+ tree_drag_end(self.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(self.tree, key);
}
@end
diff --git a/frontends/cocoa/TreeView.h b/frontends/cocoa/TreeView.h
index 31dedbb0f..518bf5c69 100644
--- a/frontends/cocoa/TreeView.h
+++ b/frontends/cocoa/TreeView.h
@@ -21,14 +21,8 @@
#import "cocoa/ScrollableView.h"
@class Tree;
-@interface TreeView : ScrollableView {
- Tree *tree;
-
- BOOL isDragging;
- NSPoint dragStart;
-
-}
+@interface TreeView : ScrollableView
-@property (readwrite, retain, nonatomic) Tree *tree;
+@property (nonatomic) Tree *tree;
@end
diff --git a/frontends/cocoa/TreeView.m b/frontends/cocoa/TreeView.m
index a00e48fd3..8fe3767fb 100644
--- a/frontends/cocoa/TreeView.m
+++ b/frontends/cocoa/TreeView.m
@@ -26,15 +26,17 @@
#import "Tree.h"
@interface TreeView () <TreeDelegate>
+
+@property (nonatomic) BOOL isDragging;
+@property (nonatomic) CGPoint dragStart;
+
@end
@implementation TreeView
-@synthesize tree;
-
- (void)drawRect:(NSRect)dirtyRect
{
- [tree drawRect:dirtyRect inView:self];
+ [self.tree drawRect:dirtyRect inView:self];
}
- (BOOL)isFlipped
@@ -47,20 +49,15 @@
return YES;
}
-- (void)dealloc
-{
- [self setTree:nil];
-}
-
- (void)setTree:(Tree *)newTree
{
- if (tree != newTree) {
- [tree setRedrawing:NO];
- [tree setDelegate:nil];
+ if (_tree != newTree) {
+ _tree.redrawing = NO;
+ _tree.delegate = nil;
- tree = newTree;
- [tree setDelegate:self];
- [tree setRedrawing:YES];
+ _tree = newTree;
+ _tree.delegate = self;
+ _tree.redrawing = YES;
[self setNeedsDisplay:YES];
}
@@ -71,9 +68,9 @@
- (void)mouseDown:(NSEvent *)event
{
- isDragging = NO;
- dragStart = [self convertPoint:[event locationInWindow] fromView:nil];
- [tree mouseAction:BROWSER_MOUSE_PRESS_1 atPoint:dragStart];
+ self.isDragging = NO;
+ self.dragStart = [self convertPoint:[event locationInWindow] fromView:nil];
+ [self.tree mouseAction:BROWSER_MOUSE_PRESS_1 atPoint:self.dragStart];
}
#define squared(x) ((x) * (x))
@@ -83,10 +80,10 @@
{
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 (!self.isDragging) {
+ const CGFloat distance = squared(self.dragStart.x - point.x) + squared(self.dragStart.y - point.y);
if (distance >= squared(MinDragDistance)) {
- isDragging = YES;
+ self.isDragging = YES;
}
}
}
@@ -97,15 +94,15 @@
browser_mouse_state modifierFlags = 0;
- if (isDragging) {
- isDragging = NO;
- [tree mouseDragEnd:modifierFlags fromPoint:dragStart toPoint:point];
+ if (self.isDragging) {
+ self.isDragging = NO;
+ [self.tree mouseDragEnd:modifierFlags fromPoint:self.dragStart toPoint:point];
} else {
modifierFlags |= BROWSER_MOUSE_CLICK_1;
if ([event clickCount] == 2) {
modifierFlags |= BROWSER_MOUSE_DOUBLE_CLICK;
}
- [tree mouseAction:modifierFlags atPoint:point];
+ [self.tree mouseAction:modifierFlags atPoint:point];
}
}
@@ -113,115 +110,115 @@
- (void)keyDown:(NSEvent *)theEvent
{
- [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
+ [self interpretKeyEvents:@[ theEvent ]];
}
- (void)insertText:(id)string
{
for (NSUInteger i = 0, length = [string length]; i < length; i++) {
unichar ch = [string characterAtIndex:i];
- [tree keyPress:ch];
+ [self.tree keyPress:ch];
}
}
- (void)moveLeft:(id)sender
{
- [tree keyPress:NS_KEY_LEFT];
+ [self.tree keyPress:NS_KEY_LEFT];
}
- (void)moveRight:(id)sender
{
- [tree keyPress:NS_KEY_RIGHT];
+ [self.tree keyPress:NS_KEY_RIGHT];
}
- (void)moveUp:(id)sender
{
- [tree keyPress:NS_KEY_UP];
+ [self.tree keyPress:NS_KEY_UP];
}
- (void)moveDown:(id)sender
{
- [tree keyPress:NS_KEY_DOWN];
+ [self.tree keyPress:NS_KEY_DOWN];
}
- (void)deleteBackward:(id)sender
{
- [tree keyPress:NS_KEY_DELETE_LEFT];
+ [self.tree keyPress:NS_KEY_DELETE_LEFT];
}
- (void)deleteForward:(id)sender
{
- [tree keyPress:NS_KEY_DELETE_RIGHT];
+ [self.tree keyPress:NS_KEY_DELETE_RIGHT];
}
- (void)cancelOperation:(id)sender
{
- [tree keyPress:NS_KEY_ESCAPE];
+ [self.tree keyPress:NS_KEY_ESCAPE];
}
- (void)scrollPageUp:(id)sender
{
- [tree keyPress:NS_KEY_PAGE_UP];
+ [self.tree keyPress:NS_KEY_PAGE_UP];
}
- (void)scrollPageDown:(id)sender
{
- [tree keyPress:NS_KEY_PAGE_DOWN];
+ [self.tree keyPress:NS_KEY_PAGE_DOWN];
}
- (void)insertTab:(id)sender
{
- [tree keyPress:NS_KEY_TAB];
+ [self.tree keyPress:NS_KEY_TAB];
}
- (void)insertBacktab:(id)sender
{
- [tree keyPress:NS_KEY_SHIFT_TAB];
+ [self.tree keyPress:NS_KEY_SHIFT_TAB];
}
- (void)moveToBeginningOfLine:(id)sender
{
- [tree keyPress:NS_KEY_LINE_START];
+ [self.tree keyPress:NS_KEY_LINE_START];
}
- (void)moveToEndOfLine:(id)sender
{
- [tree keyPress:NS_KEY_LINE_END];
+ [self.tree keyPress:NS_KEY_LINE_END];
}
- (void)moveToBeginningOfDocument:(id)sender
{
- [tree keyPress:NS_KEY_TEXT_START];
+ [self.tree keyPress:NS_KEY_TEXT_START];
}
- (void)moveToEndOfDocument:(id)sender
{
- [tree keyPress:NS_KEY_TEXT_END];
+ [self.tree keyPress:NS_KEY_TEXT_END];
}
- (void)insertNewline:(id)sender
{
- [tree keyPress:NS_KEY_NL];
+ [self.tree keyPress:NS_KEY_NL];
}
- (void)selectAll:(id)sender
{
- [tree keyPress:NS_KEY_SELECT_ALL];
+ [self.tree keyPress:NS_KEY_SELECT_ALL];
}
- (void)copy:(id)sender
{
- [tree keyPress:NS_KEY_COPY_SELECTION];
+ [self.tree keyPress:NS_KEY_COPY_SELECTION];
}
- (void)cut:(id)sender
{
- [tree keyPress:NS_KEY_CUT_SELECTION];
+ [self.tree keyPress:NS_KEY_CUT_SELECTION];
}
- (void)paste:(id)sender
{
- [tree keyPress:NS_KEY_PASTE];
+ [self.tree keyPress:NS_KEY_PASTE];
}
//MARK: -
@@ -234,7 +231,7 @@
- (void)tree:(Tree *)t resized:(NSSize)size
{
- [self setMinimumSize:size];
+ self.minimumSize = size;
}
- (void)tree:(Tree *)t scrollPoint:(NSPoint)point
@@ -244,7 +241,7 @@
- (NSSize)treeWindowSize:(Tree *)t
{
- return [self frame].size;
+ return self.frame.size;
}
@end
diff --git a/frontends/cocoa/URLFieldCell.h b/frontends/cocoa/URLFieldCell.h
index 38a75a139..c7e35f04e 100644
--- a/frontends/cocoa/URLFieldCell.h
+++ b/frontends/cocoa/URLFieldCell.h
@@ -18,14 +18,10 @@
#import <Cocoa/Cocoa.h>
+@interface URLFieldCell : NSTextFieldCell
-@interface URLFieldCell : NSTextFieldCell {
- NSButtonCell *refreshCell;
- NSImage *favicon;
-}
-
-@property (readwrite, assign, nonatomic) SEL refreshAction;
-@property (readwrite, assign, nonatomic) id refreshTarget;
-@property (readwrite, retain, nonatomic) NSImage *favicon;
+@property (nonatomic) SEL refreshAction;
+@property (nonatomic) id refreshTarget;
+@property (nonatomic) NSImage *favicon;
@end
diff --git a/frontends/cocoa/URLFieldCell.m b/frontends/cocoa/URLFieldCell.m
index 6c36f17c4..760052e38 100644
--- a/frontends/cocoa/URLFieldCell.m
+++ b/frontends/cocoa/URLFieldCell.m
@@ -23,7 +23,7 @@
@interface URLFieldCell ()
-@property (readonly, retain, nonatomic) NSButtonCell *refreshCell;
+@property (nonatomic) NSButtonCell *refreshCell;
- (NSRect)buttonFrame:(NSRect)cellFrame;
- (NSRect)urlFrame:(NSRect)cellFrame;
@@ -33,13 +33,13 @@
@implementation URLFieldCell
-@synthesize favicon;
+@synthesize refreshCell = _refreshCell;
- (void)setFavicon:(NSImage *)newIcon
{
- if (favicon != newIcon) {
- favicon = newIcon;
- [[self controlView] setNeedsDisplay:YES];
+ if (_favicon != newIcon) {
+ _favicon = newIcon;
+ [self.controlView setNeedsDisplay:YES];
}
}
@@ -48,10 +48,10 @@
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
- [favicon drawInRect:[self iconFrame:cellFrame]
- fromRect:NSZeroRect
- operation:NSCompositingOperationSourceOver
- fraction:1.0];
+ [self.favicon drawInRect:[self iconFrame:cellFrame]
+ fromRect:NSZeroRect
+ operation:NSCompositingOperationSourceOver
+ fraction:1.0];
[super drawInteriorWithFrame:[self urlFrame:cellFrame] inView:controlView];
@@ -117,10 +117,10 @@
NSImage *image = [[NSImage alloc] initWithSize:urlBounds.size];
[image lockFocus];
- [favicon drawInRect:NSMakeRect(urlBounds.origin.x, urlBounds.origin.y, urlBounds.size.height, urlBounds.size.height)
- fromRect:NSZeroRect
- operation:NSCompositingOperationCopy
- fraction:1.0];
+ [self.favicon drawInRect:NSMakeRect(urlBounds.origin.x, urlBounds.origin.y, urlBounds.size.height, urlBounds.size.height)
+ fromRect:NSZeroRect
+ operation:NSCompositingOperationCopy
+ fraction:1.0];
urlBounds.origin.x += urlBounds.size.height + 2;
[title drawInRect:urlBounds withAttributes:nil];
[image unlockFocus];
@@ -190,32 +190,33 @@
- (NSButtonCell *)refreshCell
{
- if (nil == refreshCell) {
- refreshCell = [[NSButtonCell alloc] initImageCell:[NSImage imageNamed:NSImageNameRefreshTemplate]];
- [refreshCell setButtonType:NSMomentaryPushInButton];
- [refreshCell setBordered:NO];
+ if (nil == _refreshCell) {
+ _refreshCell = [[NSButtonCell alloc] initImageCell:[NSImage imageNamed:NSImageNameRefreshTemplate]];
+ _refreshCell.buttonType = NSMomentaryPushInButton;
+ _refreshCell.bordered = NO;
}
- return refreshCell;
+
+ return _refreshCell;
}
- (void)setRefreshTarget:(id)newTarget
{
- [[self refreshCell] setTarget:newTarget];
+ self.refreshCell.target = newTarget;
}
- (id)refreshTarget
{
- return [[self refreshCell] target];
+ return self.refreshCell.target;
}
- (void)setRefreshAction:(SEL)newAction
{
- [[self refreshCell] setAction:newAction];
+ self.refreshCell.action = newAction;
}
- (SEL)refreshAction
{
- return [[self refreshCell] action];
+ return self.refreshCell.action;
}
@end