Diff for /chimera/BrowserWindowController.mm between versions 1.47 and 1.58

version 1.47, 2002/03/08 03:18:00 version 1.58, 2002/04/12 08:45:17
Line 37 Line 37
   
 #import "BrowserWindowController.h"  #import "BrowserWindowController.h"
 #import "MyBrowserView.h"  #import "MyBrowserView.h"
   #import "IconTabViewItem.h"
   
 #include "nsIWebNavigation.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 52  static NSString *PrintToolbarItemIdentif Line 54  static NSString *PrintToolbarItemIdentif
   
 @interface BrowserWindowController(Private)  @interface BrowserWindowController(Private)
 - (void)setupToolbar;  - (void)setupToolbar;
   - (void)setupSidebarTabs;
 @end  @end
   
 @implementation BrowserWindowController  @implementation BrowserWindowController
Line 64  static NSString *PrintToolbarItemIdentif Line 67  static NSString *PrintToolbarItemIdentif
     mModalSession = nil;      mModalSession = nil;
 }  }
   
   -(void)windowDidBecomeKey: (NSNotification*)aNotification
   {
     // May become necessary later.
   }
   
   -(void)windowDidResignKey: (NSNotification*)aNotification
   {
     // May be needed later.
   }
   
 -(void)mouseMoved:(NSEvent*)aEvent  -(void)mouseMoved:(NSEvent*)aEvent
 {  {
     if (mMoveReentrant)      if (mMoveReentrant)
Line 79  static NSString *PrintToolbarItemIdentif Line 92  static NSString *PrintToolbarItemIdentif
 - (id)initWithWindowNibName:(NSString *)windowNibName  - (id)initWithWindowNibName:(NSString *)windowNibName
 {  {
     if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {      if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
           if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
               [self setShouldCascadeWindows:NO];
           } else {
               [self setShouldCascadeWindows:YES];
           }
         mInitialized = NO;          mInitialized = NO;
         mMoveReentrant = NO;          mMoveReentrant = NO;
           mShouldAutosave = YES;
           mChromeMask = 0;
     }      }
     return self;      return self;
 }  }
   
   -(void)autosaveWindowFrame
   {
     if (mShouldAutosave)
       [[self window] saveFrameUsingName: @"NavigatorWindow"];
   }
   
   -(void)disableAutosave
   {
     mShouldAutosave = NO;
   }
   
 - (void)windowWillClose:(NSNotification *)notification  - (void)windowWillClose:(NSNotification *)notification
 {  {
    printf("Window will close notification.\n");  printf("Window will close notification.\n");
    [self autorelease];  [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++) {
    [mProgress release];    NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
          [[item view] windowClosed];
    [super dealloc];  }
   [mSidebarBrowserView windowClosed];
 
   [mProgress release];
   
   [super dealloc];
 }  }
   
 - (void)windowDidLoad  - (void)windowDidLoad
 {  {
     [super windowDidLoad];      [super windowDidLoad];
   
       // Get our saved dimensions.
       [[self window] setFrameUsingName: @"NavigatorWindow"];
           
     if (mModalSession)      if (mModalSession)
       [NSApp stopModal: mModalSession];        [NSApp stopModal: mModalSession];
               
     mInitialized = YES;      mInitialized = YES;
   
       mDrawerCachedFrame = NO;
           
     // Retain with a single extra refcount.  This allows the MyBrowserViews      // Retain with a single extra refcount.  This allows the MyBrowserViews
     // to remove the progress meter from its superview without having to       // to remove the progress meter from its superview without having to 
Line 135  static NSString *PrintToolbarItemIdentif Line 178  static NSString *PrintToolbarItemIdentif
     }      }
           
     [mSidebarDrawer setDelegate: self];      [mSidebarDrawer setDelegate: self];
   
       [self setupSidebarTabs];
 }  }
   
 - (void)drawerWillOpen: (NSNotification*)aNotification  - (void)drawerWillOpen: (NSNotification*)aNotification
 {  {
    [mSidebarBookmarksDataSource ensureBookmarks];  [mSidebarBookmarksDataSource ensureBookmarks];
 
   // Force the window to shrink and move if necessary in order to accommodate the sidebar.
   NSRect screenFrame = [[[self window] screen] frame];
   NSRect windowFrame = [[self window] frame];
   NSSize drawerSize = [mSidebarDrawer contentSize];
   int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.
   drawerSize.width += fudgeFactor;
   if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >
       screenFrame.size.width) {
     // We need to adjust the window so that it can fit.
     int shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
     if (shrinkDelta < 0) shrinkDelta = 0;
     int newWidth = (windowFrame.size.width - shrinkDelta);
     int newPosition = screenFrame.size.width - newWidth - drawerSize.width;
     if (newPosition < 0) newPosition = 0;
     mCachedFrameBeforeDrawerOpen = windowFrame;
     windowFrame.origin.x = newPosition;
     windowFrame.size.width = newWidth;
     mCachedFrameAfterDrawerOpen = windowFrame;
     [[self window] setFrame: windowFrame display: YES];
     mDrawerCachedFrame = YES;
   }
 }  }
   
 - (void)drawerDidOpen:(NSNotification *)aNotification  - (void)drawerDidOpen:(NSNotification *)aNotification
 {  {
    // XXXdwh This is temporary.  // XXXdwh This is temporary.
    [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];  //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
 
   // Toggle the sidebar icon.
   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
 }  }
   
 - (void)drawerDidClose:(NSNotification *)aNotification  - (void)drawerDidClose:(NSNotification *)aNotification
 {  {
    // Unload the Gecko web page in "My Panels" to save memory.  // Unload the Gecko web page in "My Panels" to save memory.
    [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];  [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
 
   // XXXdwh ignore for now.
   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
 
   if (mDrawerCachedFrame) {
     printf("Got here.\n");
     mDrawerCachedFrame = NO;
     NSRect frame = [[self window] frame];
     if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x &&
         frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y &&
         frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&
         frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {
       printf("Got here too.\n");
       printf("Xes are %d %d\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
       printf("Widths are %d %d\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
       // Restore the original frame.
       [[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
     }
   }
 }  }
   
 - (void)setupToolbar  - (void)setupToolbar
 {  {
     if (mChromeMask) {
       printf("Uh-oh. %d\n", mChromeMask);
     }
     
     NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];      NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
           
     [toolbar setDisplayMode:NSToolbarDisplayModeDefault];      [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
Line 239  static NSString *PrintToolbarItemIdentif Line 332  static NSString *PrintToolbarItemIdentif
         [toolbarItem setLabel:@"Sidebar"];          [toolbarItem setLabel:@"Sidebar"];
         [toolbarItem setPaletteLabel:@"Toggle Sidebar"];          [toolbarItem setPaletteLabel:@"Toggle Sidebar"];
         [toolbarItem setToolTip:@"Show or hide the Sidebar"];          [toolbarItem setToolTip:@"Show or hide the Sidebar"];
        [toolbarItem setImage:[NSImage imageNamed:@"sidebar"]];        [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
         [toolbarItem setTarget:self];          [toolbarItem setTarget:self];
         [toolbarItem setAction:@selector(toggleSidebar:)];          [toolbarItem setAction:@selector(toggleSidebar:)];
           mSidebarToolbarItem = toolbarItem;
     } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {      } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
                   
         NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];          NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
Line 357  static NSString *PrintToolbarItemIdentif Line 451  static NSString *PrintToolbarItemIdentif
     [[mBrowserView getBrowserView] printPreview];      [[mBrowserView getBrowserView] printPreview];
 }  }
   
- (void)findInPage- (void)findInPage:(NSString*)text
 {  {
    [[mBrowserView getBrowserView] findInPage];    [[mBrowserView getBrowserView] findInPage:text];
 }  }
   
 - (void)findAgain  - (void)findAgain
Line 407  static NSString *PrintToolbarItemIdentif Line 501  static NSString *PrintToolbarItemIdentif
           
     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) )  {      if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) )  {
         // XXXHack to bypass sidebar crashes.          // XXXHack to bypass sidebar crashes.
        [mSidebarDrawer open];        [mSidebarDrawer openOnEdge: NSMaxXEdge];
     } else {      } else {
         [mSidebarDrawer close];          [mSidebarDrawer close];
     }      }
Line 415  static NSString *PrintToolbarItemIdentif Line 509  static NSString *PrintToolbarItemIdentif
     [[self window] makeFirstResponder: resp];      [[self window] makeFirstResponder: resp];
 }  }
   
   
 -(void)loadURL:(NSURL*)aURL  -(void)loadURL:(NSURL*)aURL
 {  {
     if (mInitialized) {      if (mInitialized) {
Line 463  static NSString *PrintToolbarItemIdentif Line 558  static NSString *PrintToolbarItemIdentif
     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];          [[mBrowserView getBrowserView] setActive: NO];
           [self focusURLBar];
         }          }
     }      }
 }  }
   
 -(void)closeTab  -(void)closeTab
 {  {
    if ( [mTabBrowser numberOfTabViewItems] > 1 ) {  if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
        [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];    [[[mTabBrowser selectedTabViewItem] view] windowClosed];
    }    [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
   }
 }  }
   
 - (void)previousTab  - (void)previousTab
Line 507  static NSString *PrintToolbarItemIdentif Line 604  static NSString *PrintToolbarItemIdentif
   
 -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG  -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
 {  {
    BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];  // Autosave our dimensions before we open a new window.  That ensures the size ends up matching.
    [browser loadURL: aURL];  [self autosaveWindowFrame];
    if (aLoadInBG)
      [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];  BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
        else  [browser loadURL: aURL];
      [browser showWindow: self];  if (aLoadInBG)
          [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
    // XXXdwh Focus the content area.  else
     [browser showWindow: self];
 
   // XXXdwh Focus the content area.
 }  }
   
 -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG  -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
Line 538  static NSString *PrintToolbarItemIdentif Line 638  static NSString *PrintToolbarItemIdentif
                   
     // XXXdwh Focus the content area.      // XXXdwh Focus the content area.
 }  }
   
   -(void)setupSidebarTabs
   {
       IconTabViewItem   *bookItem = [[IconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarIconTabViewItem"
                                     withTabIcon:[NSImage imageNamed:@"bookicon"]];
       IconTabViewItem   *histItem = [[IconTabViewItem alloc] initWithIdentifier:@"historySidebarIconTabViewItem"
                                     withTabIcon:[NSImage imageNamed:@"historyicon"]];
       IconTabViewItem *searchItem = [[IconTabViewItem alloc] initWithIdentifier:@"searchSidebarIconTabViewItem"
                                     withTabIcon:[NSImage imageNamed:@"searchicon"]];
   
       [bookItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
       [histItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
       [searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
   
       [mSidebarTabView insertTabViewItem:bookItem   atIndex:0];
       [mSidebarTabView insertTabViewItem:histItem   atIndex:1];
       [mSidebarTabView insertTabViewItem:searchItem atIndex:2];
   
       [mSidebarTabView selectFirstTabViewItem:self];
   }
   
   -(void)setChromeMask:(int)aMask
   {
     mChromeMask = aMask;
   }
   
 @end  @end
   

Removed from v.1.47  
changed lines
  Added in v.1.58


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