Annotation of chimera/BrowserWindowController.mm, revision 1.57

1.44      hyatt       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 ***** */
1.1       hyatt      37: 
                     38: #import "BrowserWindowController.h"
                     39: #import "MyBrowserView.h"
1.50      macserv    40: #import "IconTabViewItem.h"
1.1       hyatt      41: 
1.37      hyatt      42: #include "nsIWebNavigation.h"
1.51      macserv    43: #include "nsCocoaBrowserService.h"
1.37      hyatt      44: 
1.1       hyatt      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";
1.11      macserv    53: static NSString *PrintToolbarItemIdentifier  = @"Print Toolbar Item";
1.1       hyatt      54: 
                     55: @interface BrowserWindowController(Private)
                     56: - (void)setupToolbar;
1.52      macserv    57: - (void)setupSidebarTabs;
1.1       hyatt      58: @end
                     59: 
                     60: @implementation BrowserWindowController
                     61: 
1.39      hyatt      62: -(void)enterModalSession
                     63: {
                     64:     mModalSession = [NSApp beginModalSessionForWindow: [self window]];
                     65:     [NSApp runModalSession: mModalSession];
                     66:     [NSApp endModalSession: mModalSession];
                     67:     mModalSession = nil;
                     68: }
                     69: 
1.35      hyatt      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: 
1.41      macserv    82: - (id)initWithWindowNibName:(NSString *)windowNibName
1.4       hyatt      83: {
1.41      macserv    84:     if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
1.51      macserv    85:         if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
                     86:             [self setShouldCascadeWindows:NO];
                     87:         } else {
                     88:             [self setShouldCascadeWindows:YES];
                     89:         }
1.41      macserv    90:         mInitialized = NO;
                     91:         mMoveReentrant = NO;
1.48      hyatt      92:         mShouldAutosave = YES;
1.41      macserv    93:     }
                     94:     return self;
1.4       hyatt      95: }
                     96: 
1.48      hyatt      97: -(void)autosaveWindowFrame
                     98: {
                     99:   if (mShouldAutosave)
                    100:     [[self window] saveFrameUsingName: @"NavigatorWindow"];
                    101: }
                    102: 
                    103: -(void)disableAutosave
                    104: {
                    105:   mShouldAutosave = NO;
                    106: }
                    107: 
1.17      hyatt     108: - (void)windowWillClose:(NSNotification *)notification
                    109: {
1.49      hyatt     110:   printf("Window will close notification.\n");
                    111:   [mSidebarBookmarksDataSource windowClosing];
1.48      hyatt     112: 
1.49      hyatt     113:   [self autosaveWindowFrame];
                    114:   [self autorelease];
1.17      hyatt     115: }
                    116: 
1.7       hyatt     117: - (void)dealloc
                    118: {
1.49      hyatt     119:   printf("Browser controller died.\n");
1.40      hyatt     120: 
1.49      hyatt     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];
1.7       hyatt     132: }
                    133: 
1.1       hyatt     134: - (void)windowDidLoad
                    135: {
1.35      hyatt     136:     [super windowDidLoad];
1.48      hyatt     137: 
                    138:     // Get our saved dimensions.
                    139:     [[self window] setFrameUsingName: @"NavigatorWindow"];
1.35      hyatt     140:     
1.39      hyatt     141:     if (mModalSession)
                    142:       [NSApp stopModal: mModalSession];
                    143:       
1.4       hyatt     144:     mInitialized = YES;
1.57    ! hyatt     145: 
        !           146:     mDrawerCachedFrame = NO;
1.38      hyatt     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:     
1.34      hyatt     153:     [[self window] setAcceptsMouseMovedEvents: YES];
                    154:     
1.1       hyatt     155:     [self setupToolbar];
1.30      hyatt     156: 
1.41      macserv   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];
1.4       hyatt     163:     
                    164:     if (mURL) {
                    165:       [self loadURL: mURL];
                    166:       [mURL release];
                    167:     }
1.18      hyatt     168:     
                    169:     [mSidebarDrawer setDelegate: self];
1.50      macserv   170: 
1.52      macserv   171:     [self setupSidebarTabs];
1.18      hyatt     172: }
                    173: 
1.22      hyatt     174: - (void)drawerWillOpen: (NSNotification*)aNotification
                    175: {
1.57    ! hyatt     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:   }
1.22      hyatt     199: }
                    200: 
1.18      hyatt     201: - (void)drawerDidOpen:(NSNotification *)aNotification
                    202: {
1.57    ! hyatt     203:   // XXXdwh This is temporary.
1.56      hyatt     204:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
1.57    ! hyatt     205: 
        !           206:   // Toggle the sidebar icon.
        !           207:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
1.1       hyatt     208: }
                    209: 
1.19      hyatt     210: - (void)drawerDidClose:(NSNotification *)aNotification
                    211: {
1.57    ! hyatt     212:   // Unload the Gecko web page in "My Panels" to save memory.
        !           213:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
        !           214: 
        !           215:   // XXXdwh ignore for now.
1.56      hyatt     216:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
1.57    ! hyatt     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:   }
1.19      hyatt     233: }
                    234: 
1.1       hyatt     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,
1.11      macserv   256:                                         PrintToolbarItemIdentifier,
1.1       hyatt     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"];
1.54      macserv   320:         [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
1.1       hyatt     321:         [toolbarItem setTarget:self];
                    322:         [toolbarItem setAction:@selector(toggleSidebar:)];
1.54      macserv   323:         mSidebarToolbarItem = toolbarItem;
1.1       hyatt     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];
1.5       macserv   336:         [menuFormRep setAction:@selector(performAppropriateLocationAction)];
1.1       hyatt     337:         [menuFormRep setTitle:[toolbarItem label]];
                    338:         
                    339:         [toolbarItem setMenuFormRepresentation:menuFormRep];
1.5       macserv   340:         mLocationToolbarItem = toolbarItem;
1.11      macserv   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)];
1.1       hyatt     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:    
1.5       macserv   373: - (void)updateToolbarItems
1.1       hyatt     374: {
                    375:   [[[self window] toolbar] validateVisibleItems];
                    376: }
                    377: 
1.5       macserv   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
1.3       hyatt     393: {
                    394:     [mURLBar selectText: self];
                    395: }
                    396: 
1.5       macserv   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]]];
1.32      hyatt     411:     
                    412:     // Focus and activate our content area.
                    413:     [[mBrowserView getBrowserView] setActive: YES];
1.5       macserv   414: }
                    415: 
                    416: - (IBAction)goToLocationFromToolbarURLField:(id)sender
                    417: {
                    418:     [self loadURL:[NSURL URLWithString:[sender stringValue]]];
1.32      hyatt     419:     
                    420:     // Focus and activate our content area.
                    421:     [[mBrowserView getBrowserView] setActive: YES];
1.5       macserv   422: }
                    423: 
1.7       hyatt     424: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
1.6       hyatt     425: {
1.7       hyatt     426:     [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
1.6       hyatt     427: }
                    428: 
1.12      hyatt     429: - (void)printDocument
                    430: {
                    431:     [[mBrowserView getBrowserView] printDocument];
                    432: }
                    433: 
1.15      hyatt     434: - (void)printPreview
                    435: {
                    436:     [[mBrowserView getBrowserView] printPreview];
                    437: }
                    438: 
1.55      pinkerto  439: - (void)findInPage:(NSString*)text
1.16      hyatt     440: {
1.55      pinkerto  441:     [[mBrowserView getBrowserView] findInPage:text];
1.16      hyatt     442: }
                    443: 
                    444: - (void)findAgain
                    445: {
                    446:     [[mBrowserView getBrowserView] findAgain];
1.22      hyatt     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];
1.16      hyatt     455: }
                    456: 
1.5       macserv   457: - (IBAction)back:(id)aSender
1.1       hyatt     458: {
                    459:   [[mBrowserView getBrowserView] goBack];
                    460: }
                    461: 
1.5       macserv   462: - (IBAction)forward:(id)aSender
1.1       hyatt     463: {
                    464:   [[mBrowserView getBrowserView] goForward];
                    465: }
                    466: 
1.5       macserv   467: - (IBAction)reload:(id)aSender
1.1       hyatt     468: {
                    469:   [[mBrowserView getBrowserView] reload: 0];
                    470: }
                    471: 
1.5       macserv   472: - (IBAction)stop:(id)aSender
1.1       hyatt     473: {
1.37      hyatt     474:   [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
1.1       hyatt     475: }
                    476: 
1.5       macserv   477: - (IBAction)home:(id)aSender
1.1       hyatt     478: {
1.5       macserv   479:   [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.1       hyatt     480: }
                    481: 
1.5       macserv   482: - (IBAction)toggleSidebar:(id)aSender
1.1       hyatt     483: {
1.36      hyatt     484:     NSResponder* resp = [[self window] firstResponder];
                    485:     [[self window] makeFirstResponder: nil];
                    486:     
1.31      hyatt     487:     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) )   {
1.34      hyatt     488:         // XXXHack to bypass sidebar crashes.
1.57    ! hyatt     489:         [mSidebarDrawer openOnEdge: NSMaxXEdge];
1.1       hyatt     490:     } else {
                    491:         [mSidebarDrawer close];
                    492:     }
1.36      hyatt     493:     
                    494:     [[self window] makeFirstResponder: resp];
1.1       hyatt     495: }
1.54      macserv   496: 
1.1       hyatt     497: 
1.4       hyatt     498: -(void)loadURL:(NSURL*)aURL
1.1       hyatt     499: {
1.32      hyatt     500:     if (mInitialized) {
1.4       hyatt     501:         [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
1.32      hyatt     502:     }
1.4       hyatt     503:     else {
                    504:         mURL = aURL;
                    505:         [mURL retain];
                    506:     }
1.1       hyatt     507: }
1.5       macserv   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];
1.8       hyatt     526: }
1.27      hyatt     527: 
                    528: -(void)newTab
                    529: {
1.28      hyatt     530:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
1.47      hyatt     531:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
                    532:     [newView setTab: newTab];
1.41      macserv   533: 
                    534:     [newTab setLabel: @"Untitled"];
                    535:     [newTab setView: newView];
                    536: 
1.28      hyatt     537:     [mTabBrowser addTabViewItem: newTab];
1.42      macserv   538: 
1.28      hyatt     539:     [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.42      macserv   540: 
1.28      hyatt     541:     [mTabBrowser selectLastTabViewItem: self];
1.42      macserv   542: 
1.29      hyatt     543:     if ( [[[self window] toolbar] isVisible] ) {
                    544:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
                    545:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
                    546:             [self focusURLBar];
1.42      macserv   547:         }
1.29      hyatt     548:     }
1.42      macserv   549: }
                    550: 
                    551: -(void)closeTab
                    552: {
1.49      hyatt     553:   if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
                    554:     [[[mTabBrowser selectedTabViewItem] view] windowClosed];
                    555:     [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
                    556:   }
1.42      macserv   557: }
                    558: 
                    559: - (void)previousTab
                    560: {
                    561:     [mTabBrowser selectPreviousTabViewItem:self];
                    562: }
                    563: 
                    564: - (void)nextTab
                    565: {
                    566:     [mTabBrowser selectNextTabViewItem:self];
1.28      hyatt     567: }
1.27      hyatt     568: 
1.28      hyatt     569: - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
                    570: {
1.41      macserv   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:     }
1.28      hyatt     576:     // Connect up the new view
                    577:     mBrowserView = [aTabViewItem view];
1.30      hyatt     578:        
1.28      hyatt     579:     // Make the new view the primary content area.
1.47      hyatt     580:     [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
1.28      hyatt     581:         progress: mProgress windowController: self];
1.27      hyatt     582: }
1.28      hyatt     583: 
1.31      hyatt     584: -(MyBrowserView*)getMyBrowserView
                    585: {
                    586:     return mBrowserView;
                    587: }
1.45      hyatt     588: 
                    589: -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
                    590: {
1.48      hyatt     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.
1.47      hyatt     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.
1.45      hyatt     624: }
1.52      macserv   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];
1.53      macserv   642: 
                    643:     [mSidebarTabView selectFirstTabViewItem:self];
1.52      macserv   644: }
                    645: 
                    646: 
1.1       hyatt     647: @end
                    648: 

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