Diff for /chimera/BrowserWindowController.mm between versions 1.36 and 1.51

version 1.36, 2002/02/22 09:16:48 version 1.51, 2002/03/11 23:38:05
Line 1 Line 1
/*/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 *  BrowserWindowController.mm/* ***** 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 "BrowserWindowController.h"
 #import "MyBrowserView.h"  #import "MyBrowserView.h"
   #import "IconTabViewItem.h"
   
   #include "nsIWebNavigation.h"
   #include "nsCocoaBrowserService.h"
   
 static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";  static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
 static NSString *BackToolbarItemIdentifier  = @"Back Toolbar Item";  static NSString *BackToolbarItemIdentifier  = @"Back Toolbar Item";
Line 21  static NSString *PrintToolbarItemIdentif Line 58  static NSString *PrintToolbarItemIdentif
   
 @implementation BrowserWindowController  @implementation BrowserWindowController
   
   -(void)enterModalSession
   {
       mModalSession = [NSApp beginModalSessionForWindow: [self window]];
       [NSApp runModalSession: mModalSession];
       [NSApp endModalSession: mModalSession];
       mModalSession = nil;
   }
   
 -(void)mouseMoved:(NSEvent*)aEvent  -(void)mouseMoved:(NSEvent*)aEvent
 {  {
     if (mMoveReentrant)      if (mMoveReentrant)
Line 33  static NSString *PrintToolbarItemIdentif Line 78  static NSString *PrintToolbarItemIdentif
     mMoveReentrant = NO;      mMoveReentrant = NO;
 }  }
   
- (id)init - (id)initWithWindowNibName:(NSString *)windowNibName
 {  {
    mInitialized = NO;    if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
    mMoveReentrant = NO;        if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
    return [super init];            [self setShouldCascadeWindows:NO];
         } else {
             [self setShouldCascadeWindows:YES];
         }
         mInitialized = NO;
         mMoveReentrant = NO;
         mShouldAutosave = YES;
     }
     return self;
 }
 
 -(void)autosaveWindowFrame
 {
   if (mShouldAutosave)
     [[self window] saveFrameUsingName: @"NavigatorWindow"];
 }
 
 -(void)disableAutosave
 {
   mShouldAutosave = NO;
 }  }
   
 - (void)windowWillClose:(NSNotification *)notification  - (void)windowWillClose:(NSNotification *)notification
 {  {
    [self autorelease];  printf("Window will close notification.\n");
    [mSidebarBookmarksDataSource windowClosing];  [mSidebarBookmarksDataSource windowClosing];
 
   [self autosaveWindowFrame];
   [self autorelease];
 }  }
   
 - (void)dealloc  - (void)dealloc
 {  {
    printf("Browser controller died.\n");  printf("Browser controller died.\n");
    
    [mBrowserView windowClosed];  // Loop over all tabs, and tell them that the window is closed.
    [mSidebarBrowserView windowClosed];  int numTabs = [mTabBrowser numberOfTabViewItems];
      for (int i = 0; i < numTabs; i++) {
    [super dealloc];    NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
     [[item view] windowClosed];
   }
   [mSidebarBrowserView windowClosed];
 
   [mProgress release];
   
   [super dealloc];
 }  }
   
 - (void)windowDidLoad  - (void)windowDidLoad
 {  {
     [super windowDidLoad];      [super windowDidLoad];
   
       // Get our saved dimensions.
       [[self window] setFrameUsingName: @"NavigatorWindow"];
           
       if (mModalSession)
         [NSApp stopModal: mModalSession];
         
     mInitialized = YES;      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 window] setAcceptsMouseMovedEvents: YES];
           
     [self setupToolbar];      [self setupToolbar];
   
    // Our initial view is our primary view.  Connect it up.//  03/03/2002 mlj Changing strategy a bit here.  The addTab: method was
    NSTabViewItem* tab = [mTabBrowser tabViewItemAtIndex: 0];//      duplicating a lot of the code found here.  I have moved it to that method.
    NSView* view = [tab view];//      We now remove the IB tab, then add one of our own.
    
    MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [view frame]] autorelease];    [mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
    [tab setView: newView];    [self newTab];
    mBrowserView = newView; 
           
     if (mURL) {      if (mURL) {
       [self loadURL: mURL];        [self loadURL: mURL];
Line 79  static NSString *PrintToolbarItemIdentif Line 164  static NSString *PrintToolbarItemIdentif
     }      }
           
     [mSidebarDrawer setDelegate: self];      [mSidebarDrawer setDelegate: self];
    
    [mBrowserView makePrimaryBrowserView: tab urlbar: mURLBar status: mStatus    [mSidebarTabView addTabViewItem: //testing...
        progress: mProgress windowController: self];        [[[IconTabViewItem alloc] initWithIdentifier:nil withTabIcon:[NSImage imageNamed:@"bookicon"]] autorelease]];
 }  }
   
 - (void)drawerWillOpen: (NSNotification*)aNotification  - (void)drawerWillOpen: (NSNotification*)aNotification
Line 339  static NSString *PrintToolbarItemIdentif Line 424  static NSString *PrintToolbarItemIdentif
   
 - (IBAction)stop:(id)aSender  - (IBAction)stop:(id)aSender
 {  {
  [[mBrowserView getBrowserView] stop: 0];  [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
 }  }
   
 - (IBAction)home:(id)aSender  - (IBAction)home:(id)aSender
Line 395  static NSString *PrintToolbarItemIdentif Line 480  static NSString *PrintToolbarItemIdentif
 -(void)newTab  -(void)newTab
 {  {
     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];      NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
     [mTabBrowser addTabViewItem: newTab];  
       
     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];      MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
    [newTab setView: newView];    [newView setTab: newTab];
 
     [newTab setLabel: @"Untitled"];      [newTab setLabel: @"Untitled"];
        [newTab setView: newView];
 
     [mTabBrowser addTabViewItem: newTab];
 
     [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];      [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
    
     [mTabBrowser selectLastTabViewItem: self];      [mTabBrowser selectLastTabViewItem: self];
    
     if ( [[[self window] toolbar] isVisible] ) {      if ( [[[self window] toolbar] isVisible] ) {
         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||          if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {               ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
             [self focusURLBar];              [self focusURLBar];
        }         }
     }      }
    }
    //XXXdwh Do this if we ever support auto-hide.
    //if ([mTabBrowser numberOfTabViewItems] == 2)-(void)closeTab
    //    [mTabBrowser setTabViewType: NSTopTabsBezelBorder];{
   if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
     [[[mTabBrowser selectedTabViewItem] view] windowClosed];
     [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
   }
 }
 
 - (void)previousTab
 {
     [mTabBrowser selectPreviousTabViewItem:self];
 }
 
 - (void)nextTab
 {
     [mTabBrowser selectNextTabViewItem:self];
 }  }
   
 - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem  - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
 {  {
    // Disconnect the old view.    // Disconnect the old view, if one has been designated.
    [mBrowserView disconnectView];    // If the window has just been opened, none has been.
        if ( mBrowserView ) {
         [mBrowserView disconnectView];
     }
     // Connect up the new view      // Connect up the new view
     mBrowserView = [aTabViewItem view];      mBrowserView = [aTabViewItem view];
                 
     // Make the new view the primary content area.      // Make the new view the primary content area.
    [mBrowserView makePrimaryBrowserView: aTabViewItem urlbar: mURLBar status: mStatus    [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
         progress: mProgress windowController: self];          progress: mProgress windowController: self];
 }  }
   
Line 434  static NSString *PrintToolbarItemIdentif Line 537  static NSString *PrintToolbarItemIdentif
 {  {
     return mBrowserView;      return mBrowserView;
 }  }
   
   -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
   {
     // Autosave our dimensions before we open a new window.  That ensures the size ends up matching.
     [self autosaveWindowFrame];
   
     BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
     [browser loadURL: aURL];
     if (aLoadInBG)
       [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
     else
       [browser showWindow: self];
   
     // XXXdwh Focus the content area.
   }
   
   -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
   {
       NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
       
       NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
       int index = [mTabBrowser indexOfTabViewItem: selectedTab];
       [mTabBrowser insertTabViewItem: newTab atIndex: index+1];
       
       MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
       [newView setTab: newTab];
       
       [newTab setLabel: @"Loading..."];
       [newTab setView: newView];
   
       [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
   
       if (!aLoadInBG)
           [mTabBrowser selectTabViewItem: newTab];
           
       // XXXdwh Focus the content area.
   }
 @end  @end
   

Removed from v.1.36  
changed lines
  Added in v.1.51


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>