--- chimera/BrowserWindowController.mm 2002/02/07 05:11:38 1.18 +++ chimera/BrowserWindowController.mm 2002/03/07 18:42:42 1.44 @@ -1,10 +1,45 @@ -/* - * BrowserWindowController.mm - */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ #import "BrowserWindowController.h" #import "MyBrowserView.h" +#include "nsIWebNavigation.h" + static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar"; static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item"; static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item"; @@ -21,27 +56,78 @@ static NSString *PrintToolbarItemIdentif @implementation BrowserWindowController -- (id)init +-(void)enterModalSession +{ + mModalSession = [NSApp beginModalSessionForWindow: [self window]]; + [NSApp runModalSession: mModalSession]; + [NSApp endModalSession: mModalSession]; + mModalSession = nil; +} + +-(void)mouseMoved:(NSEvent*)aEvent { - mInitialized = NO; - return [super init]; + if (mMoveReentrant) + return; + + mMoveReentrant = YES; + NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]]; + [view mouseMoved: aEvent]; + [super mouseMoved: aEvent]; + mMoveReentrant = NO; +} + +- (id)initWithWindowNibName:(NSString *)windowNibName +{ + if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) { + mInitialized = NO; + mMoveReentrant = NO; + } + return self; } - (void)windowWillClose:(NSNotification *)notification { + printf("Window will close notification.\n"); [self autorelease]; + [mSidebarBookmarksDataSource windowClosing]; } - (void)dealloc { + printf("Browser controller died.\n"); + [mBrowserView windowClosed]; + [mSidebarBrowserView windowClosed]; + + [mProgress release]; + [super dealloc]; } - (void)windowDidLoad { + [super windowDidLoad]; + + if (mModalSession) + [NSApp stopModal: mModalSession]; + mInitialized = YES; + + // Retain with a single extra refcount. This allows the MyBrowserViews + // to remove the progress meter from its superview without having to + // worry about retaining and releasing it. + [mProgress retain]; + + [[self window] setAcceptsMouseMovedEvents: YES]; + [self setupToolbar]; + +// 03/03/2002 mlj Changing strategy a bit here. The addTab: method was +// duplicating a lot of the code found here. I have moved it to that method. +// We now remove the IB tab, then add one of our own. + + [mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]]; + [self newTab]; if (mURL) { [self loadURL: mURL]; @@ -49,13 +135,28 @@ static NSString *PrintToolbarItemIdentif } [mSidebarDrawer setDelegate: self]; + +// [mBrowserView makePrimaryBrowserView: tab urlbar: mURLBar status: mStatus + // progress: mProgress windowController: self]; +} + +- (void)drawerWillOpen: (NSNotification*)aNotification +{ + [mSidebarBookmarksDataSource ensureBookmarks]; } - (void)drawerDidOpen:(NSNotification *)aNotification { + // XXXdwh This is temporary. [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone]; } +- (void)drawerDidClose:(NSNotification *)aNotification +{ + // Unload the Gecko web page in "My Panels" to save memory. + [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone]; +} + - (void)setupToolbar { NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease]; @@ -231,11 +332,17 @@ static NSString *PrintToolbarItemIdentif [mLocationSheetWindow orderOut:self]; [NSApp endSheet:mLocationSheetWindow returnCode:1]; [self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]]; + + // Focus and activate our content area. + [[mBrowserView getBrowserView] setActive: YES]; } - (IBAction)goToLocationFromToolbarURLField:(id)sender { [self loadURL:[NSURL URLWithString:[sender stringValue]]]; + + // Focus and activate our content area. + [[mBrowserView getBrowserView] setActive: YES]; } - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList @@ -263,6 +370,14 @@ static NSString *PrintToolbarItemIdentif [[mBrowserView getBrowserView] findAgain]; } +- (void)addBookmark +{ + // XXXdwh Hack. Just go to the sidebar for now until we get our + // menu data source going. + [mSidebarBookmarksDataSource ensureBookmarks]; + [mSidebarBookmarksDataSource addBookmark: self]; +} + - (IBAction)back:(id)aSender { [[mBrowserView getBrowserView] goBack]; @@ -280,7 +395,7 @@ static NSString *PrintToolbarItemIdentif - (IBAction)stop:(id)aSender { - [[mBrowserView getBrowserView] stop: 0]; + [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL]; } - (IBAction)home:(id)aSender @@ -290,17 +405,24 @@ static NSString *PrintToolbarItemIdentif - (IBAction)toggleSidebar:(id)aSender { - if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) { + NSResponder* resp = [[self window] firstResponder]; + [[self window] makeFirstResponder: nil]; + + if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) { + // XXXHack to bypass sidebar crashes. [mSidebarDrawer open]; } else { [mSidebarDrawer close]; } + + [[self window] makeFirstResponder: resp]; } -(void)loadURL:(NSURL*)aURL { - if (mInitialized) + if (mInitialized) { [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone]; + } else { mURL = aURL; [mURL retain]; @@ -325,5 +447,64 @@ static NSString *PrintToolbarItemIdentif [[self window] update]; [[self window] display]; } + +-(void)newTab +{ + NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease]; + MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [[newTab view] frame]] autorelease]; + + [newTab setLabel: @"Untitled"]; + [newTab setView: newView]; + + [mTabBrowser addTabViewItem: newTab]; + + [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone]; + + [mTabBrowser selectLastTabViewItem: self]; + + if ( [[[self window] toolbar] isVisible] ) { + if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) || + ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) { + [self focusURLBar]; + } + } +} + +-(void)closeTab +{ + if ( [mTabBrowser numberOfTabViewItems] > 1 ) { + [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]]; + } +} + +- (void)previousTab +{ + [mTabBrowser selectPreviousTabViewItem:self]; +} + +- (void)nextTab +{ + [mTabBrowser selectNextTabViewItem:self]; +} + +- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem +{ + // Disconnect the old view, if one has been designated. + // If the window has just been opened, none has been. + if ( mBrowserView ) { + [mBrowserView disconnectView]; + } + // Connect up the new view + mBrowserView = [aTabViewItem view]; + + // Make the new view the primary content area. + [mBrowserView makePrimaryBrowserView: aTabViewItem urlbar: mURLBar status: mStatus + progress: mProgress windowController: self]; +} + +-(MyBrowserView*)getMyBrowserView +{ + return mBrowserView; +} @end