File:  [mozdev] / chimera / BrowserWindowController.mm
Revision 1.57: download - view: text, annotated - select for diffs - revision graph
Tue Apr 9 01:11:32 2002 UTC (17 years, 8 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Chimera now shrinks and moves the window to accommodate the sidebar drawer.

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

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