From a9b60753f9c7a57aae2af50943e3ad81203e73e1 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Thu, 13 Jan 2011 15:19:47 +0000 Subject: Implemented tree view/history window. svn path=/trunk/netsurf/; revision=11309 --- cocoa/NetSurf.xcodeproj/project.pbxproj | 12 ++ cocoa/ScrollableView.h | 29 +++++ cocoa/ScrollableView.m | 69 ++++++++++ cocoa/TreeView.h | 31 +++++ cocoa/TreeView.m | 131 +++++++++++++++++++ cocoa/res/MainMenu.xib | 219 +++++++++++++++++++++++++++++++- 6 files changed, 485 insertions(+), 6 deletions(-) create mode 100644 cocoa/ScrollableView.h create mode 100644 cocoa/ScrollableView.m create mode 100644 cocoa/TreeView.h create mode 100644 cocoa/TreeView.m (limited to 'cocoa') diff --git a/cocoa/NetSurf.xcodeproj/project.pbxproj b/cocoa/NetSurf.xcodeproj/project.pbxproj index e82c0dd0a..af16babf1 100644 --- a/cocoa/NetSurf.xcodeproj/project.pbxproj +++ b/cocoa/NetSurf.xcodeproj/project.pbxproj @@ -87,6 +87,7 @@ 2612265C12D7ACB500E10F91 /* quirks.css in Resources */ = {isa = PBXBuildFile; fileRef = 2612265912D7ACB500E10F91 /* quirks.css */; }; 2612266D12D7AD6800E10F91 /* adblock.css in Resources */ = {isa = PBXBuildFile; fileRef = 2612265D12D7AD6800E10F91 /* adblock.css */; }; 2612269112D7AE4100E10F91 /* Messages in Resources */ = {isa = PBXBuildFile; fileRef = 2612268F12D7AE4100E10F91 /* Messages */; }; + 2622F1D712DCD84600CD5A62 /* TreeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2622F1D612DCD84600CD5A62 /* TreeView.m */; }; 265F311A12D663F50048B600 /* gui.m in Sources */ = {isa = PBXBuildFile; fileRef = 265F311912D663F50048B600 /* gui.m */; }; 265F314812D666660048B600 /* plotter.m in Sources */ = {isa = PBXBuildFile; fileRef = 265F314712D666660048B600 /* plotter.m */; }; 265F315212D667060048B600 /* history.m in Sources */ = {isa = PBXBuildFile; fileRef = 265F315112D667060048B600 /* history.m */; }; @@ -110,6 +111,7 @@ 265F321412D66CD90048B600 /* utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 265F321312D66CD90048B600 /* utils.m */; }; 265F321F12D66D510048B600 /* font.m in Sources */ = {isa = PBXBuildFile; fileRef = 265F321E12D66D510048B600 /* font.m */; }; 26AFE63F12DDEB0A005AD082 /* NetSurf.icns in Resources */ = {isa = PBXBuildFile; fileRef = 26AFE63E12DDEB0A005AD082 /* NetSurf.icns */; }; + 26AFE8E412DF4200005AD082 /* ScrollableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 26AFE8E312DF4200005AD082 /* ScrollableView.m */; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; /* End PBXBuildFile section */ @@ -281,6 +283,8 @@ 2612269412D7AEA800E10F91 /* en */ = {isa = PBXFileReference; lastKnownFileType = text; name = en; path = en.lproj/Messages; sourceTree = ""; }; 2612269512D7AEB500E10F91 /* it */ = {isa = PBXFileReference; lastKnownFileType = text; name = it; path = it.lproj/Messages; sourceTree = ""; }; 2612269612D7AEBE00E10F91 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text; name = fr; path = fr.lproj/Messages; sourceTree = ""; }; + 2622F1D512DCD84600CD5A62 /* TreeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TreeView.h; sourceTree = ""; }; + 2622F1D612DCD84600CD5A62 /* TreeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TreeView.m; sourceTree = ""; }; 262711B212DDDCB800B2FA62 /* debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = debug.xcconfig; sourceTree = ""; }; 262711B412DDDCB800B2FA62 /* local.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = local.xcconfig; sourceTree = ""; }; 262711BE12DDDD1500B2FA62 /* release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = release.xcconfig; sourceTree = ""; }; @@ -322,6 +326,8 @@ 265F321312D66CD90048B600 /* utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = utils.m; sourceTree = ""; }; 265F321E12D66D510048B600 /* font.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = font.m; sourceTree = ""; }; 26AFE63E12DDEB0A005AD082 /* NetSurf.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = NetSurf.icns; sourceTree = ""; }; + 26AFE8E212DF4200005AD082 /* ScrollableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollableView.h; sourceTree = ""; }; + 26AFE8E312DF4200005AD082 /* ScrollableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScrollableView.m; sourceTree = ""; }; 8D1107320486CEB800E47090 /* NetSurf.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetSurf.app; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -595,6 +601,10 @@ 26121E3E12D70A1A00E10F91 /* BrowserWindow.m */, 26121EFB12D7132100E10F91 /* BrowserView.h */, 26121EFC12D7132100E10F91 /* BrowserView.m */, + 2622F1D512DCD84600CD5A62 /* TreeView.h */, + 2622F1D612DCD84600CD5A62 /* TreeView.m */, + 26AFE8E212DF4200005AD082 /* ScrollableView.h */, + 26AFE8E312DF4200005AD082 /* ScrollableView.m */, ); name = cocoa; sourceTree = ""; @@ -839,6 +849,8 @@ 26121DD912D703F400E10F91 /* NetSurfApp.m in Sources */, 26121E3F12D70A1A00E10F91 /* BrowserWindow.m in Sources */, 26121EFD12D7132100E10F91 /* BrowserView.m in Sources */, + 2622F1D712DCD84600CD5A62 /* TreeView.m in Sources */, + 26AFE8E412DF4200005AD082 /* ScrollableView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/cocoa/ScrollableView.h b/cocoa/ScrollableView.h new file mode 100644 index 000000000..1850fe58d --- /dev/null +++ b/cocoa/ScrollableView.h @@ -0,0 +1,29 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#import + + +@interface ScrollableView : NSView { + NSSize minimumSize; + NSView *observedSuperview; +} + +@property (readwrite, assign, nonatomic) NSSize minimumSize; + +@end diff --git a/cocoa/ScrollableView.m b/cocoa/ScrollableView.m new file mode 100644 index 000000000..d50ce5a15 --- /dev/null +++ b/cocoa/ScrollableView.m @@ -0,0 +1,69 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#import "ScrollableView.h" + +@interface ScrollableView () + +- (void) adjustFrame; +- (void) frameChangeNotification: (NSNotification *) note; + +@end + +@implementation ScrollableView +@synthesize minimumSize; + +- (void) setMinimumSize: (NSSize)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 ) )]; +} + +- (void) frameChangeNotification: (NSNotification *) note; +{ + [self adjustFrame]; +} + +- (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]; + } +} + +@end diff --git a/cocoa/TreeView.h b/cocoa/TreeView.h new file mode 100644 index 000000000..aee45bb3d --- /dev/null +++ b/cocoa/TreeView.h @@ -0,0 +1,31 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#import + +#import "ScrollableView.h" + +@interface TreeView : ScrollableView { + struct tree *treeHandle; + + BOOL isDragging; + NSPoint dragStart; + +} + +@end diff --git a/cocoa/TreeView.m b/cocoa/TreeView.m new file mode 100644 index 000000000..00fb4808c --- /dev/null +++ b/cocoa/TreeView.m @@ -0,0 +1,131 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#import "TreeView.h" + +#import "desktop/tree.h" +#import "desktop/plotters.h" +#import "desktop/history_global_core.h" + +#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ ) + +@implementation TreeView + +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 ); +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 +}; + +- (id)initWithFrame:(NSRect)frame +{ + if ((self = [super initWithFrame:frame]) == nil) return nil; + + treeHandle = tree_create( history_global_get_tree_flags(), &cocoa_tree_callbacks, self ); + if (NULL == treeHandle) { + [self release]; + self = nil; + } + history_global_initialise( treeHandle, "" ); + return self; +} + +- (void) dealloc; +{ + tree_delete( treeHandle ); + + [super dealloc]; +} + +- (void)drawRect:(NSRect)dirtyRect +{ + tree_set_redraw( treeHandle, true ); + tree_draw( treeHandle, 0, 0, NSMinX( dirtyRect ), NSMinY( dirtyRect ), NSWidth( dirtyRect ), NSHeight( dirtyRect ) ); +} + +- (BOOL) isFlipped; +{ + return YES; +} + +- (void) mouseDown: (NSEvent *)theEvent; +{ + NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil]; + dragStart = point; + + tree_mouse_action( treeHandle, BROWSER_MOUSE_PRESS_1, point.x, point.y ); +} + +- (void) mouseUp: (NSEvent *)theEvent; +{ + NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil]; + if (isDragging) { + tree_drag_end( treeHandle, BROWSER_MOUSE_DRAG_1, dragStart.x, dragStart.y, point.x, point.y ); + isDragging = NO; + } else { + tree_mouse_action( treeHandle, BROWSER_MOUSE_CLICK_1, point.x, point.y ); + } +} + + +#define squared(x) ((x)*(x)) +#define MinDragDistance (5.0) + +- (void) mouseDragged: (NSEvent *)theEvent; +{ + NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil]; + + if (!isDragging) { + const CGFloat distance = squared( dragStart.x - point.x ) + squared( dragStart.y - point.y ); + if (distance >= squared( MinDragDistance)) isDragging = YES; + } + + if (isDragging) { + tree_mouse_action( treeHandle, BROWSER_MOUSE_DRAG_1, point.x, point.y ); + } +} + +static void tree_redraw_request( int x, int y, int w, int h, void *data ) +{ + [(TreeView *)data setNeedsDisplayInRect: NSMakeRect( x, y, w, h )]; +} + +static void tree_resized( struct tree *tree, int w, int h, void *data ) +{ + [(TreeView *)data setMinimumSize: NSMakeSize( w, h )]; +} + +static void tree_scroll_visible( int y, int height, void *data ) +{ + [(TreeView *)data scrollPoint: NSMakePoint( 0, y )]; +} + +static void tree_get_window_dimensions( int *width, int *height, void *data ) +{ + NSSize size = [(TreeView *)data frame].size; + *width = size.width; + *height = size.height; +} + +@end diff --git a/cocoa/res/MainMenu.xib b/cocoa/res/MainMenu.xib index 01b7d134b..fae4184cc 100644 --- a/cocoa/res/MainMenu.xib +++ b/cocoa/res/MainMenu.xib @@ -12,7 +12,8 @@ YES - + + YES @@ -527,6 +528,24 @@ + + + YES + YES + + + 2147483647 + + + + + + History + + 2147483647 + + + YES @@ -577,6 +596,88 @@ _NSMainMenu + + 15 + 2 + {{196, 123}, {300, 387}} + 1685585920 + History + NSWindow + + {1.79769e+308, 1.79769e+308} + + + 256 + + YES + + + 274 + + YES + + + 2304 + + YES + + + 268 + {300, 387} + + TreeView + + + {{1, 1}, {300, 387}} + + + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + 4 + + + + -2147483392 + {{319, 1}, {15, 371}} + + + _doScroller: + 0.99741602067183466 + + + + -2147483392 + {{1, 373}, {500, 15}} + + 1 + + _doScroller: + 1 + + + {{-1, -1}, {302, 389}} + + + 562 + + + + + + {300, 387} + + + {{0, 0}, {1680, 1028}} + {1.79769e+308, 1.79769e+308} + @@ -829,6 +930,14 @@ 775 + + + makeKeyAndOrderFront: + + + + 819 + @@ -1078,6 +1187,8 @@ + + @@ -1284,6 +1395,60 @@ + + 811 + + + YES + + + + + + 812 + + + YES + + + + + + 813 + + + YES + + + + + + + + 814 + + + + + 815 + + + + + 816 + + + + + 817 + + + + + 818 + + + @@ -1401,6 +1566,17 @@ 81.IBPluginDependency 81.ImportedFromIB2 81.editorWindowContentRectSynchronizationRect + 811.IBEditorWindowLastContentRect + 811.IBPluginDependency + 811.IBWindowTemplateEditedContentRect + 811.NSWindowTemplate.visibleAtLaunch + 812.IBPluginDependency + 813.IBPluginDependency + 814.IBPluginDependency + 815.IBPluginDependency + 816.IBPluginDependency + 817.IBPluginDependency + 818.IBPluginDependency 82.IBPluginDependency 82.ImportedFromIB2 83.IBPluginDependency @@ -1413,7 +1589,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{533, 633}, {157, 23}} + {{881, 774}, {157, 23}} com.apple.InterfaceBuilder.CocoaPlugin {{596, 852}, {216, 23}} @@ -1451,11 +1627,11 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{462, 583}, {194, 73}} + {{810, 694}, {194, 103}} com.apple.InterfaceBuilder.CocoaPlugin {{525, 802}, {197, 73}} - {{242, 656}, {352, 20}} + {{590, 797}, {352, 20}} com.apple.InterfaceBuilder.CocoaPlugin {74, 862} @@ -1521,6 +1697,17 @@ com.apple.InterfaceBuilder.CocoaPlugin {{323, 672}, {199, 203}} + {{331, 320}, {300, 387}} + com.apple.InterfaceBuilder.CocoaPlugin + {{331, 320}, {300, 387}} + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1545,9 +1732,29 @@ - 810 + 819 + + + + YES + + ScrollableView + NSView + + IBProjectSource + ScrollableView.h + + + + TreeView + ScrollableView + + IBProjectSource + TreeView.h + + + - 0 IBCocoaFramework -- cgit v1.2.3