Annotation of chimera/BrowserWindowController.mm, revision 1.58

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.58    ! hyatt      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: 
1.35      hyatt      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: 
1.41      macserv    92: - (id)initWithWindowNibName:(NSString *)windowNibName
1.4       hyatt      93: {
1.41      macserv    94:     if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
1.51      macserv    95:         if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
                     96:             [self setShouldCascadeWindows:NO];
                     97:         } else {
                     98:             [self setShouldCascadeWindows:YES];
                     99:         }
1.41      macserv   100:         mInitialized = NO;
                    101:         mMoveReentrant = NO;
1.48      hyatt     102:         mShouldAutosave = YES;
1.58    ! hyatt     103:         mChromeMask = 0;
1.41      macserv   104:     }
                    105:     return self;
1.4       hyatt     106: }
                    107: 
1.48      hyatt     108: -(void)autosaveWindowFrame
                    109: {
                    110:   if (mShouldAutosave)
                    111:     [[self window] saveFrameUsingName: @"NavigatorWindow"];
                    112: }
                    113: 
                    114: -(void)disableAutosave
                    115: {
                    116:   mShouldAutosave = NO;
                    117: }
                    118: 
1.17      hyatt     119: - (void)windowWillClose:(NSNotification *)notification
                    120: {
1.49      hyatt     121:   printf("Window will close notification.\n");
                    122:   [mSidebarBookmarksDataSource windowClosing];
1.48      hyatt     123: 
1.49      hyatt     124:   [self autosaveWindowFrame];
                    125:   [self autorelease];
1.17      hyatt     126: }
                    127: 
1.7       hyatt     128: - (void)dealloc
                    129: {
1.49      hyatt     130:   printf("Browser controller died.\n");
1.40      hyatt     131: 
1.49      hyatt     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];
1.7       hyatt     143: }
                    144: 
1.1       hyatt     145: - (void)windowDidLoad
                    146: {
1.35      hyatt     147:     [super windowDidLoad];
1.48      hyatt     148: 
                    149:     // Get our saved dimensions.
                    150:     [[self window] setFrameUsingName: @"NavigatorWindow"];
1.35      hyatt     151:     
1.39      hyatt     152:     if (mModalSession)
                    153:       [NSApp stopModal: mModalSession];
                    154:       
1.4       hyatt     155:     mInitialized = YES;
1.57      hyatt     156: 
                    157:     mDrawerCachedFrame = NO;
1.38      hyatt     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:     
1.34      hyatt     164:     [[self window] setAcceptsMouseMovedEvents: YES];
                    165:     
1.1       hyatt     166:     [self setupToolbar];
1.30      hyatt     167: 
1.41      macserv   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];
1.4       hyatt     174:     
                    175:     if (mURL) {
                    176:       [self loadURL: mURL];
                    177:       [mURL release];
                    178:     }
1.18      hyatt     179:     
                    180:     [mSidebarDrawer setDelegate: self];
1.50      macserv   181: 
1.52      macserv   182:     [self setupSidebarTabs];
1.18      hyatt     183: }
                    184: 
1.22      hyatt     185: - (void)drawerWillOpen: (NSNotification*)aNotification
                    186: {
1.57      hyatt     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:   }
1.22      hyatt     210: }
                    211: 
1.18      hyatt     212: - (void)drawerDidOpen:(NSNotification *)aNotification
                    213: {
1.57      hyatt     214:   // XXXdwh This is temporary.
1.56      hyatt     215:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
1.57      hyatt     216: 
                    217:   // Toggle the sidebar icon.
                    218:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
1.1       hyatt     219: }
                    220: 
1.19      hyatt     221: - (void)drawerDidClose:(NSNotification *)aNotification
                    222: {
1.57      hyatt     223:   // Unload the Gecko web page in "My Panels" to save memory.
                    224:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
                    225: 
                    226:   // XXXdwh ignore for now.
1.56      hyatt     227:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
1.57      hyatt     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:   }
1.19      hyatt     244: }
                    245: 
1.1       hyatt     246: - (void)setupToolbar
                    247: {
1.58    ! hyatt     248:   if (mChromeMask) {
        !           249:     printf("Uh-oh. %d\n", mChromeMask);
        !           250:   }
        !           251:   
1.1       hyatt     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,
1.11      macserv   271:                                         PrintToolbarItemIdentifier,
1.1       hyatt     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"];
1.54      macserv   335:         [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
1.1       hyatt     336:         [toolbarItem setTarget:self];
                    337:         [toolbarItem setAction:@selector(toggleSidebar:)];
1.54      macserv   338:         mSidebarToolbarItem = toolbarItem;
1.1       hyatt     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];
1.5       macserv   351:         [menuFormRep setAction:@selector(performAppropriateLocationAction)];
1.1       hyatt     352:         [menuFormRep setTitle:[toolbarItem label]];
                    353:         
                    354:         [toolbarItem setMenuFormRepresentation:menuFormRep];
1.5       macserv   355:         mLocationToolbarItem = toolbarItem;
1.11      macserv   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)];
1.1       hyatt     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:    
1.5       macserv   388: - (void)updateToolbarItems
1.1       hyatt     389: {
                    390:   [[[self window] toolbar] validateVisibleItems];
                    391: }
                    392: 
1.5       macserv   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
1.3       hyatt     408: {
                    409:     [mURLBar selectText: self];
                    410: }
                    411: 
1.5       macserv   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]]];
1.32      hyatt     426:     
                    427:     // Focus and activate our content area.
                    428:     [[mBrowserView getBrowserView] setActive: YES];
1.5       macserv   429: }
                    430: 
                    431: - (IBAction)goToLocationFromToolbarURLField:(id)sender
                    432: {
                    433:     [self loadURL:[NSURL URLWithString:[sender stringValue]]];
1.32      hyatt     434:     
                    435:     // Focus and activate our content area.
                    436:     [[mBrowserView getBrowserView] setActive: YES];
1.5       macserv   437: }
                    438: 
1.7       hyatt     439: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
1.6       hyatt     440: {
1.7       hyatt     441:     [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
1.6       hyatt     442: }
                    443: 
1.12      hyatt     444: - (void)printDocument
                    445: {
                    446:     [[mBrowserView getBrowserView] printDocument];
                    447: }
                    448: 
1.15      hyatt     449: - (void)printPreview
                    450: {
                    451:     [[mBrowserView getBrowserView] printPreview];
                    452: }
                    453: 
1.55      pinkerto  454: - (void)findInPage:(NSString*)text
1.16      hyatt     455: {
1.55      pinkerto  456:     [[mBrowserView getBrowserView] findInPage:text];
1.16      hyatt     457: }
                    458: 
                    459: - (void)findAgain
                    460: {
                    461:     [[mBrowserView getBrowserView] findAgain];
1.22      hyatt     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];
1.16      hyatt     470: }
                    471: 
1.5       macserv   472: - (IBAction)back:(id)aSender
1.1       hyatt     473: {
                    474:   [[mBrowserView getBrowserView] goBack];
                    475: }
                    476: 
1.5       macserv   477: - (IBAction)forward:(id)aSender
1.1       hyatt     478: {
                    479:   [[mBrowserView getBrowserView] goForward];
                    480: }
                    481: 
1.5       macserv   482: - (IBAction)reload:(id)aSender
1.1       hyatt     483: {
                    484:   [[mBrowserView getBrowserView] reload: 0];
                    485: }
                    486: 
1.5       macserv   487: - (IBAction)stop:(id)aSender
1.1       hyatt     488: {
1.37      hyatt     489:   [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
1.1       hyatt     490: }
                    491: 
1.5       macserv   492: - (IBAction)home:(id)aSender
1.1       hyatt     493: {
1.5       macserv   494:   [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.1       hyatt     495: }
                    496: 
1.5       macserv   497: - (IBAction)toggleSidebar:(id)aSender
1.1       hyatt     498: {
1.36      hyatt     499:     NSResponder* resp = [[self window] firstResponder];
                    500:     [[self window] makeFirstResponder: nil];
                    501:     
1.31      hyatt     502:     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) )   {
1.34      hyatt     503:         // XXXHack to bypass sidebar crashes.
1.57      hyatt     504:         [mSidebarDrawer openOnEdge: NSMaxXEdge];
1.1       hyatt     505:     } else {
                    506:         [mSidebarDrawer close];
                    507:     }
1.36      hyatt     508:     
                    509:     [[self window] makeFirstResponder: resp];
1.1       hyatt     510: }
1.54      macserv   511: 
1.1       hyatt     512: 
1.4       hyatt     513: -(void)loadURL:(NSURL*)aURL
1.1       hyatt     514: {
1.32      hyatt     515:     if (mInitialized) {
1.4       hyatt     516:         [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
1.32      hyatt     517:     }
1.4       hyatt     518:     else {
                    519:         mURL = aURL;
                    520:         [mURL retain];
                    521:     }
1.1       hyatt     522: }
1.5       macserv   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];
1.8       hyatt     541: }
1.27      hyatt     542: 
                    543: -(void)newTab
                    544: {
1.28      hyatt     545:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
1.47      hyatt     546:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
                    547:     [newView setTab: newTab];
1.41      macserv   548: 
                    549:     [newTab setLabel: @"Untitled"];
                    550:     [newTab setView: newView];
                    551: 
1.28      hyatt     552:     [mTabBrowser addTabViewItem: newTab];
1.42      macserv   553: 
1.28      hyatt     554:     [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.42      macserv   555: 
1.28      hyatt     556:     [mTabBrowser selectLastTabViewItem: self];
1.42      macserv   557: 
1.29      hyatt     558:     if ( [[[self window] toolbar] isVisible] ) {
                    559:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
                    560:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
1.58    ! hyatt     561:           [[mBrowserView getBrowserView] setActive: NO];
        !           562:           [self focusURLBar];
1.42      macserv   563:         }
1.29      hyatt     564:     }
1.42      macserv   565: }
                    566: 
                    567: -(void)closeTab
                    568: {
1.49      hyatt     569:   if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
                    570:     [[[mTabBrowser selectedTabViewItem] view] windowClosed];
                    571:     [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
                    572:   }
1.42      macserv   573: }
                    574: 
                    575: - (void)previousTab
                    576: {
                    577:     [mTabBrowser selectPreviousTabViewItem:self];
                    578: }
                    579: 
                    580: - (void)nextTab
                    581: {
                    582:     [mTabBrowser selectNextTabViewItem:self];
1.28      hyatt     583: }
1.27      hyatt     584: 
1.28      hyatt     585: - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
                    586: {
1.41      macserv   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:     }
1.28      hyatt     592:     // Connect up the new view
                    593:     mBrowserView = [aTabViewItem view];
1.30      hyatt     594:        
1.28      hyatt     595:     // Make the new view the primary content area.
1.47      hyatt     596:     [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
1.28      hyatt     597:         progress: mProgress windowController: self];
1.27      hyatt     598: }
1.28      hyatt     599: 
1.31      hyatt     600: -(MyBrowserView*)getMyBrowserView
                    601: {
                    602:     return mBrowserView;
                    603: }
1.45      hyatt     604: 
                    605: -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
                    606: {
1.48      hyatt     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.
1.47      hyatt     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.
1.45      hyatt     640: }
1.52      macserv   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];
1.53      macserv   658: 
                    659:     [mSidebarTabView selectFirstTabViewItem:self];
1.52      macserv   660: }
                    661: 
1.58    ! hyatt     662: -(void)setChromeMask:(int)aMask
        !           663: {
        !           664:   mChromeMask = aMask;
        !           665: }
1.52      macserv   666: 
1.1       hyatt     667: @end
                    668: 

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