File:  [mozdev] / chimera / BrowserWindowController.mm
Revision 1.58: download - view: text, annotated - select for diffs - revision graph
Fri Apr 12 08:45:17 2002 UTC (17 years, 8 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Fix a slew of activation issues.

    1: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
    2: /* ***** BEGIN LICENSE BLOCK *****
    3:  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
    4:  *
    5:  * The contents of this file are subject to the Netscape Public License
    6:  * Version 1.1 (the "License"); you may not use this file except in
    7:  * compliance with the License. You may obtain a copy of the License at
    8:  * http://www.mozilla.org/NPL/
    9:  *
   10:  * Software distributed under the License is distributed on an "AS IS" basis,
   11:  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   12:  * for the specific language governing rights and limitations under the
   13:  * License.
   14:  *
   15:  * The Original Code is mozilla.org code.
   16:  *
   17:  * The Initial Developer of the Original Code is 
   18:  * Netscape Communications Corporation.
   19:  * Portions created by the Initial Developer are Copyright (C) 2002
   20:  * the Initial Developer. All Rights Reserved.
   21:  *
   22:  * Contributor(s):
   23:  *
   24:  * Alternatively, the contents of this file may be used under the terms of
   25:  * either the GNU General Public License Version 2 or later (the "GPL"), or 
   26:  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
   27:  * in which case the provisions of the GPL or the LGPL are applicable instead
   28:  * of those above. If you wish to allow use of your version of this file only
   29:  * under the terms of either the GPL or the LGPL, and not to allow others to
   30:  * use your version of this file under the terms of the NPL, indicate your
   31:  * decision by deleting the provisions above and replace them with the notice
   32:  * and other provisions required by the GPL or the LGPL. If you do not delete
   33:  * the provisions above, a recipient may use your version of this file under
   34:  * the terms of any one of the NPL, the GPL or the LGPL.
   35:  *
   36:  * ***** END LICENSE BLOCK ***** */
   37: 
   38: #import "BrowserWindowController.h"
   39: #import "MyBrowserView.h"
   40: #import "IconTabViewItem.h"
   41: 
   42: #include "nsIWebNavigation.h"
   43: #include "nsCocoaBrowserService.h"
   44: 
   45: static NSString *BrowserToolbarIdentifier	= @"Browser Window Toolbar";
   46: static NSString *BackToolbarItemIdentifier	= @"Back Toolbar Item";
   47: static NSString *ForwardToolbarItemIdentifier	= @"Forward Toolbar Item";
   48: static NSString *ReloadToolbarItemIdentifier	= @"Reload Toolbar Item";
   49: static NSString *StopToolbarItemIdentifier	= @"Stop Toolbar Item";
   50: static NSString *HomeToolbarItemIdentifier	= @"Home Toolbar Item";
   51: static NSString *LocationToolbarItemIdentifier	= @"Location Toolbar Item";
   52: static NSString *SidebarToolbarItemIdentifier	= @"Sidebar Toolbar Item";
   53: static NSString *PrintToolbarItemIdentifier	= @"Print Toolbar Item";
   54: 
   55: @interface BrowserWindowController(Private)
   56: - (void)setupToolbar;
   57: - (void)setupSidebarTabs;
   58: @end
   59: 
   60: @implementation BrowserWindowController
   61: 
   62: -(void)enterModalSession
   63: {
   64:     mModalSession = [NSApp beginModalSessionForWindow: [self window]];
   65:     [NSApp runModalSession: mModalSession];
   66:     [NSApp endModalSession: mModalSession];
   67:     mModalSession = nil;
   68: }
   69: 
   70: -(void)windowDidBecomeKey: (NSNotification*)aNotification
   71: {
   72:   // May become necessary later.
   73: }
   74: 
   75: -(void)windowDidResignKey: (NSNotification*)aNotification
   76: {
   77:   // May be needed later.
   78: }
   79: 
   80: -(void)mouseMoved:(NSEvent*)aEvent
   81: {
   82:     if (mMoveReentrant)
   83:         return;
   84:         
   85:     mMoveReentrant = YES;
   86:     NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]];
   87:     [view mouseMoved: aEvent];
   88:     [super mouseMoved: aEvent];
   89:     mMoveReentrant = NO;
   90: }
   91: 
   92: - (id)initWithWindowNibName:(NSString *)windowNibName
   93: {
   94:     if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
   95:         if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
   96:             [self setShouldCascadeWindows:NO];
   97:         } else {
   98:             [self setShouldCascadeWindows:YES];
   99:         }
  100:         mInitialized = NO;
  101:         mMoveReentrant = NO;
  102:         mShouldAutosave = YES;
  103:         mChromeMask = 0;
  104:     }
  105:     return self;
  106: }
  107: 
  108: -(void)autosaveWindowFrame
  109: {
  110:   if (mShouldAutosave)
  111:     [[self window] saveFrameUsingName: @"NavigatorWindow"];
  112: }
  113: 
  114: -(void)disableAutosave
  115: {
  116:   mShouldAutosave = NO;
  117: }
  118: 
  119: - (void)windowWillClose:(NSNotification *)notification
  120: {
  121:   printf("Window will close notification.\n");
  122:   [mSidebarBookmarksDataSource windowClosing];
  123: 
  124:   [self autosaveWindowFrame];
  125:   [self autorelease];
  126: }
  127: 
  128: - (void)dealloc
  129: {
  130:   printf("Browser controller died.\n");
  131: 
  132:   // Loop over all tabs, and tell them that the window is closed.
  133:   int numTabs = [mTabBrowser numberOfTabViewItems];
  134:   for (int i = 0; i < numTabs; i++) {
  135:     NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
  136:     [[item view] windowClosed];
  137:   }
  138:   [mSidebarBrowserView windowClosed];
  139: 
  140:   [mProgress release];
  141:   
  142:   [super dealloc];
  143: }
  144: 
  145: - (void)windowDidLoad
  146: {
  147:     [super windowDidLoad];
  148: 
  149:     // Get our saved dimensions.
  150:     [[self window] setFrameUsingName: @"NavigatorWindow"];
  151:     
  152:     if (mModalSession)
  153:       [NSApp stopModal: mModalSession];
  154:       
  155:     mInitialized = YES;
  156: 
  157:     mDrawerCachedFrame = NO;
  158:     
  159:     // Retain with a single extra refcount.  This allows the MyBrowserViews
  160:     // to remove the progress meter from its superview without having to 
  161:     // worry about retaining and releasing it.
  162:     [mProgress retain];
  163:     
  164:     [[self window] setAcceptsMouseMovedEvents: YES];
  165:     
  166:     [self setupToolbar];
  167: 
  168: //  03/03/2002 mlj Changing strategy a bit here.  The addTab: method was
  169: //	duplicating a lot of the code found here.  I have moved it to that method.
  170: //	We now remove the IB tab, then add one of our own.
  171: 
  172:     [mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
  173:     [self newTab];
  174:     
  175:     if (mURL) {
  176:       [self loadURL: mURL];
  177:       [mURL release];
  178:     }
  179:     
  180:     [mSidebarDrawer setDelegate: self];
  181: 
  182:     [self setupSidebarTabs];
  183: }
  184: 
  185: - (void)drawerWillOpen: (NSNotification*)aNotification
  186: {
  187:   [mSidebarBookmarksDataSource ensureBookmarks];
  188: 
  189:   // Force the window to shrink and move if necessary in order to accommodate the sidebar.
  190:   NSRect screenFrame = [[[self window] screen] frame];
  191:   NSRect windowFrame = [[self window] frame];
  192:   NSSize drawerSize = [mSidebarDrawer contentSize];
  193:   int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.
  194:   drawerSize.width += fudgeFactor;
  195:   if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >
  196:       screenFrame.size.width) {
  197:     // We need to adjust the window so that it can fit.
  198:     int shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
  199:     if (shrinkDelta < 0) shrinkDelta = 0;
  200:     int newWidth = (windowFrame.size.width - shrinkDelta);
  201:     int newPosition = screenFrame.size.width - newWidth - drawerSize.width;
  202:     if (newPosition < 0) newPosition = 0;
  203:     mCachedFrameBeforeDrawerOpen = windowFrame;
  204:     windowFrame.origin.x = newPosition;
  205:     windowFrame.size.width = newWidth;
  206:     mCachedFrameAfterDrawerOpen = windowFrame;
  207:     [[self window] setFrame: windowFrame display: YES];
  208:     mDrawerCachedFrame = YES;
  209:   }
  210: }
  211: 
  212: - (void)drawerDidOpen:(NSNotification *)aNotification
  213: {
  214:   // XXXdwh This is temporary.
  215:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
  216: 
  217:   // Toggle the sidebar icon.
  218:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
  219: }
  220: 
  221: - (void)drawerDidClose:(NSNotification *)aNotification
  222: {
  223:   // Unload the Gecko web page in "My Panels" to save memory.
  224:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
  225: 
  226:   // XXXdwh ignore for now.
  227:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
  228: 
  229:   if (mDrawerCachedFrame) {
  230:     printf("Got here.\n");
  231:     mDrawerCachedFrame = NO;
  232:     NSRect frame = [[self window] frame];
  233:     if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x &&
  234:         frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y &&
  235:         frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&
  236:         frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {
  237:       printf("Got here too.\n");
  238:       printf("Xes are %d %d\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
  239:       printf("Widths are %d %d\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
  240:       // Restore the original frame.
  241:       [[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
  242:     }
  243:   }
  244: }
  245: 
  246: - (void)setupToolbar
  247: {
  248:   if (mChromeMask) {
  249:     printf("Uh-oh. %d\n", mChromeMask);
  250:   }
  251:   
  252:     NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
  253:     
  254:     [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
  255:     [toolbar setAllowsUserCustomization:YES];
  256:     [toolbar setAutosavesConfiguration:YES];
  257:     [toolbar setDelegate:self];
  258:     [[self window] setToolbar:toolbar];
  259: }
  260: 
  261: 
  262: - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
  263: {
  264:     return [NSArray arrayWithObjects:	BackToolbarItemIdentifier,
  265:                                         ForwardToolbarItemIdentifier,
  266:                                         ReloadToolbarItemIdentifier,
  267:                                         StopToolbarItemIdentifier,
  268:                                         HomeToolbarItemIdentifier,
  269:                                         LocationToolbarItemIdentifier,
  270:                                         SidebarToolbarItemIdentifier,
  271:                                         PrintToolbarItemIdentifier,
  272:                                         NSToolbarCustomizeToolbarItemIdentifier,
  273:                                         NSToolbarFlexibleSpaceItemIdentifier,
  274:                                         NSToolbarSpaceItemIdentifier,
  275:                                         NSToolbarSeparatorItemIdentifier,
  276:                                         nil];
  277: }
  278: 
  279: - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
  280: {
  281:     return [NSArray arrayWithObjects:	BackToolbarItemIdentifier,
  282:                                         ForwardToolbarItemIdentifier,
  283:                                         ReloadToolbarItemIdentifier,
  284:                                         StopToolbarItemIdentifier,
  285:                                         HomeToolbarItemIdentifier,
  286:                                         LocationToolbarItemIdentifier,
  287:                                         SidebarToolbarItemIdentifier,
  288:                                         nil];
  289: }
  290: 
  291: - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
  292:       itemForItemIdentifier:(NSString *)itemIdent
  293:   willBeInsertedIntoToolbar:(BOOL)willBeInserted
  294: {
  295:     NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
  296:     if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
  297:         [toolbarItem setLabel:@"Back"];
  298:         [toolbarItem setPaletteLabel:@"Go Back"];
  299:         [toolbarItem setToolTip:@"Go back one page"];
  300:         [toolbarItem setImage:[NSImage imageNamed:@"back"]];
  301:         [toolbarItem setTarget:self];
  302:         [toolbarItem setAction:@selector(back:)];
  303:     } else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
  304:         [toolbarItem setLabel:@"Forward"];
  305:         [toolbarItem setPaletteLabel:@"Go Forward"];
  306:         [toolbarItem setToolTip:@"Go forward one page"];
  307:         [toolbarItem setImage:[NSImage imageNamed:@"forward"]];
  308:         [toolbarItem setTarget:self];
  309:         [toolbarItem setAction:@selector(forward:)];
  310:     } else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
  311:         [toolbarItem setLabel:@"Reload"];
  312:         [toolbarItem setPaletteLabel:@"Reload Page"];
  313:         [toolbarItem setToolTip:@"Reload current page"];
  314:         [toolbarItem setImage:[NSImage imageNamed:@"reload"]];
  315:         [toolbarItem setTarget:self];
  316:         [toolbarItem setAction:@selector(reload:)];
  317:     } else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
  318:         [toolbarItem setLabel:@"Stop"];
  319:         [toolbarItem setPaletteLabel:@"Stop Loading"];
  320:         [toolbarItem setToolTip:@"Stop loading this page"];
  321:         [toolbarItem setImage:[NSImage imageNamed:@"stop"]];
  322:         [toolbarItem setTarget:self];
  323:         [toolbarItem setAction:@selector(stop:)];
  324:     } else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
  325:         [toolbarItem setLabel:@"Home"];
  326:         [toolbarItem setPaletteLabel:@"Go Home"];
  327:         [toolbarItem setToolTip:@"Go to home page"];
  328:         [toolbarItem setImage:[NSImage imageNamed:@"home"]];
  329:         [toolbarItem setTarget:self];
  330:         [toolbarItem setAction:@selector(home:)];
  331:     } else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
  332:         [toolbarItem setLabel:@"Sidebar"];
  333:         [toolbarItem setPaletteLabel:@"Toggle Sidebar"];
  334:         [toolbarItem setToolTip:@"Show or hide the Sidebar"];
  335:         [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
  336:         [toolbarItem setTarget:self];
  337:         [toolbarItem setAction:@selector(toggleSidebar:)];
  338:         mSidebarToolbarItem = toolbarItem;
  339:     } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
  340:         
  341:         NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
  342:         
  343:         [toolbarItem setLabel:@"Location"];
  344:         [toolbarItem setPaletteLabel:@"Location"];
  345:         [toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
  346:         [toolbarItem setView:mLocationToolbarView];
  347:         [toolbarItem setMinSize:NSMakeSize(128,32)];
  348:         [toolbarItem setMaxSize:NSMakeSize(2560,32)];
  349:         
  350:         [menuFormRep setTarget:self];
  351:         [menuFormRep setAction:@selector(performAppropriateLocationAction)];
  352:         [menuFormRep setTitle:[toolbarItem label]];
  353:         
  354:         [toolbarItem setMenuFormRepresentation:menuFormRep];
  355:         mLocationToolbarItem = toolbarItem;
  356: 
  357:     } else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
  358:         [toolbarItem setLabel:@"Print"];
  359:         [toolbarItem setPaletteLabel:@"Print"];
  360:         [toolbarItem setToolTip:@"Print this page"];
  361:         [toolbarItem setImage:[NSImage imageNamed:@"print"]];
  362:         [toolbarItem setTarget:self];
  363:         [toolbarItem setAction:@selector(printDocument)];
  364:     } else {
  365:         toolbarItem = nil;
  366:     }
  367:         
  368:     return toolbarItem;
  369: }
  370: 
  371: // This method handles the enabling/disabling of the toolbar buttons.
  372: - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
  373: {
  374:   // Check the action and see if it matches.
  375:   SEL action = [theItem action];
  376:   if (action == @selector(back:))
  377:     return [[mBrowserView getBrowserView] canGoBack];
  378:   else if (action == @selector(forward:))
  379:     return [[mBrowserView getBrowserView] canGoForward];
  380:   else if (action == @selector(reload:))
  381:     return [mBrowserView isBusy] == NO;
  382:   else if (action == @selector(stop:))
  383:     return [mBrowserView isBusy];
  384:   else
  385:     return YES;
  386: }
  387:    
  388: - (void)updateToolbarItems
  389: {
  390:   [[[self window] toolbar] validateVisibleItems];
  391: }
  392: 
  393: - (void)performAppropriateLocationAction
  394: {
  395:     if ( [[[self window] toolbar] isVisible] ) {
  396:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
  397:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
  398:             [self focusURLBar];
  399:         } else {
  400:             [self beginLocationSheet];
  401:         }
  402:     } else {
  403:         [self beginLocationSheet];
  404:     }
  405: }
  406: 
  407: - (void)focusURLBar
  408: {
  409:     [mURLBar selectText: self];
  410: }
  411: 
  412: - (void)beginLocationSheet
  413: {
  414:     [NSApp beginSheet:	mLocationSheetWindow
  415:        modalForWindow:	[self window]
  416:         modalDelegate:	nil
  417:        didEndSelector:	nil
  418:           contextInfo:	nil];
  419: }
  420: 
  421: - (IBAction)endLocationSheet:(id)sender
  422: {
  423:     [mLocationSheetWindow orderOut:self];
  424:     [NSApp endSheet:mLocationSheetWindow returnCode:1];
  425:     [self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
  426:     
  427:     // Focus and activate our content area.
  428:     [[mBrowserView getBrowserView] setActive: YES];
  429: }
  430: 
  431: - (IBAction)goToLocationFromToolbarURLField:(id)sender
  432: {
  433:     [self loadURL:[NSURL URLWithString:[sender stringValue]]];
  434:     
  435:     // Focus and activate our content area.
  436:     [[mBrowserView getBrowserView] setActive: YES];
  437: }
  438: 
  439: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
  440: {
  441:     [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
  442: }
  443: 
  444: - (void)printDocument
  445: {
  446:     [[mBrowserView getBrowserView] printDocument];
  447: }
  448: 
  449: - (void)printPreview
  450: {
  451:     [[mBrowserView getBrowserView] printPreview];
  452: }
  453: 
  454: - (void)findInPage:(NSString*)text
  455: {
  456:     [[mBrowserView getBrowserView] findInPage:text];
  457: }
  458: 
  459: - (void)findAgain
  460: {
  461:     [[mBrowserView getBrowserView] findAgain];
  462: }
  463: 
  464: - (void)addBookmark
  465: {
  466:     // XXXdwh Hack.  Just go to the sidebar for now until we get our
  467:     // menu data source going.
  468:     [mSidebarBookmarksDataSource ensureBookmarks];
  469:     [mSidebarBookmarksDataSource addBookmark: self];
  470: }
  471: 
  472: - (IBAction)back:(id)aSender
  473: {
  474:   [[mBrowserView getBrowserView] goBack];
  475: }
  476: 
  477: - (IBAction)forward:(id)aSender
  478: {
  479:   [[mBrowserView getBrowserView] goForward];
  480: }
  481: 
  482: - (IBAction)reload:(id)aSender
  483: {
  484:   [[mBrowserView getBrowserView] reload: 0];
  485: }
  486: 
  487: - (IBAction)stop:(id)aSender
  488: {
  489:   [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
  490: }
  491: 
  492: - (IBAction)home:(id)aSender
  493: {
  494:   [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
  495: }
  496: 
  497: - (IBAction)toggleSidebar:(id)aSender
  498: {
  499:     NSResponder* resp = [[self window] firstResponder];
  500:     [[self window] makeFirstResponder: nil];
  501:     
  502:     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) 	{
  503:         // XXXHack to bypass sidebar crashes.
  504:         [mSidebarDrawer openOnEdge: NSMaxXEdge];
  505:     } else {
  506:         [mSidebarDrawer close];
  507:     }
  508:     
  509:     [[self window] makeFirstResponder: resp];
  510: }
  511: 
  512: 
  513: -(void)loadURL:(NSURL*)aURL
  514: {
  515:     if (mInitialized) {
  516:         [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
  517:     }
  518:     else {
  519:         mURL = aURL;
  520:         [mURL retain];
  521:     }
  522: }
  523: 
  524: - (void)updateLocationFields:(NSString *)locationString
  525: {
  526: /* //commenting this out because it doesn't work right yet.
  527:     if ( [locationString length] > 30 ) {
  528:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
  529:             [NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
  530:     } else {
  531:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
  532:             [NSString stringWithFormat:@"Location: %@", locationString]];
  533:     }
  534: */
  535: 
  536:     [mURLBar setStringValue:locationString];
  537:     [mLocationSheetURLField setStringValue:locationString];
  538: 
  539:     [[self window] update];
  540:     [[self window] display];
  541: }
  542: 
  543: -(void)newTab
  544: {
  545:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
  546:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
  547:     [newView setTab: newTab];
  548: 
  549:     [newTab setLabel: @"Untitled"];
  550:     [newTab setView: newView];
  551: 
  552:     [mTabBrowser addTabViewItem: newTab];
  553: 
  554:     [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
  555: 
  556:     [mTabBrowser selectLastTabViewItem: self];
  557: 
  558:     if ( [[[self window] toolbar] isVisible] ) {
  559:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
  560:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
  561:           [[mBrowserView getBrowserView] setActive: NO];
  562:           [self focusURLBar];
  563:         }
  564:     }
  565: }
  566: 
  567: -(void)closeTab
  568: {
  569:   if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
  570:     [[[mTabBrowser selectedTabViewItem] view] windowClosed];
  571:     [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
  572:   }
  573: }
  574: 
  575: - (void)previousTab
  576: {
  577:     [mTabBrowser selectPreviousTabViewItem:self];
  578: }
  579: 
  580: - (void)nextTab
  581: {
  582:     [mTabBrowser selectNextTabViewItem:self];
  583: }
  584: 
  585: - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
  586: {
  587:     // Disconnect the old view, if one has been designated.
  588:     // If the window has just been opened, none has been.
  589:     if ( mBrowserView ) {
  590:         [mBrowserView disconnectView];
  591:     }
  592:     // Connect up the new view
  593:     mBrowserView = [aTabViewItem view];
  594:        
  595:     // Make the new view the primary content area.
  596:     [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
  597:         progress: mProgress windowController: self];
  598: }
  599: 
  600: -(MyBrowserView*)getMyBrowserView
  601: {
  602:     return mBrowserView;
  603: }
  604: 
  605: -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
  606: {
  607:   // Autosave our dimensions before we open a new window.  That ensures the size ends up matching.
  608:   [self autosaveWindowFrame];
  609: 
  610:   BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
  611:   [browser loadURL: aURL];
  612:   if (aLoadInBG)
  613:     [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
  614:   else
  615:     [browser showWindow: self];
  616: 
  617:   // XXXdwh Focus the content area.
  618: }
  619: 
  620: -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
  621: {
  622:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
  623:     
  624:     NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
  625:     int index = [mTabBrowser indexOfTabViewItem: selectedTab];
  626:     [mTabBrowser insertTabViewItem: newTab atIndex: index+1];
  627:     
  628:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
  629:     [newView setTab: newTab];
  630:     
  631:     [newTab setLabel: @"Loading..."];
  632:     [newTab setView: newView];
  633: 
  634:     [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
  635: 
  636:     if (!aLoadInBG)
  637:         [mTabBrowser selectTabViewItem: newTab];
  638:         
  639:     // XXXdwh Focus the content area.
  640: }
  641: 
  642: -(void)setupSidebarTabs
  643: {
  644:     IconTabViewItem   *bookItem = [[IconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarIconTabViewItem"
  645:                                   withTabIcon:[NSImage imageNamed:@"bookicon"]];
  646:     IconTabViewItem   *histItem = [[IconTabViewItem alloc] initWithIdentifier:@"historySidebarIconTabViewItem"
  647:                                   withTabIcon:[NSImage imageNamed:@"historyicon"]];
  648:     IconTabViewItem *searchItem = [[IconTabViewItem alloc] initWithIdentifier:@"searchSidebarIconTabViewItem"
  649:                                   withTabIcon:[NSImage imageNamed:@"searchicon"]];
  650: 
  651:     [bookItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
  652:     [histItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
  653:     [searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
  654: 
  655:     [mSidebarTabView insertTabViewItem:bookItem   atIndex:0];
  656:     [mSidebarTabView insertTabViewItem:histItem   atIndex:1];
  657:     [mSidebarTabView insertTabViewItem:searchItem atIndex:2];
  658: 
  659:     [mSidebarTabView selectFirstTabViewItem:self];
  660: }
  661: 
  662: -(void)setChromeMask:(int)aMask
  663: {
  664:   mChromeMask = aMask;
  665: }
  666: 
  667: @end
  668: 

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