File:  [mozdev] / chimera / BrowserWindowController.mm
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Thu Jan 31 03:13:19 2002 UTC (17 years, 10 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Open file now works!

    1: /*
    2:  *  BrowserWindowController.mm
    3:  */
    4: 
    5: #import "BrowserWindowController.h"
    6: #import "MyBrowserView.h"
    7: 
    8: static NSString *BrowserToolbarIdentifier	= @"Browser Window Toolbar";
    9: static NSString *BackToolbarItemIdentifier	= @"Back Toolbar Item";
   10: static NSString *ForwardToolbarItemIdentifier	= @"Forward Toolbar Item";
   11: static NSString *ReloadToolbarItemIdentifier	= @"Reload Toolbar Item";
   12: static NSString *StopToolbarItemIdentifier	= @"Stop Toolbar Item";
   13: static NSString *HomeToolbarItemIdentifier	= @"Home Toolbar Item";
   14: static NSString *LocationToolbarItemIdentifier	= @"Location Toolbar Item";
   15: static NSString *SidebarToolbarItemIdentifier	= @"Sidebar Toolbar Item";
   16: 
   17: @interface BrowserWindowController(Private)
   18: - (void)setupToolbar;
   19: @end
   20: 
   21: @implementation BrowserWindowController
   22: 
   23: - (id)init 
   24: {
   25:     mInitialized = NO;
   26:     return [super init];
   27: }
   28: 
   29: - (void)windowDidLoad
   30: {
   31:     mInitialized = YES;
   32:     [self setupToolbar];
   33:     
   34:     if (mURL) {
   35:       [self loadURL: mURL];
   36:       [mURL release];
   37:     }
   38: }
   39: 
   40: - (void)setupToolbar
   41: {
   42:     NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
   43:     
   44:     [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
   45:     [toolbar setAllowsUserCustomization:YES];
   46:     [toolbar setAutosavesConfiguration:YES];
   47:     [toolbar setDelegate:self];
   48:     [[self window] setToolbar:toolbar];
   49: }
   50: 
   51: 
   52: - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
   53: {
   54:     return [NSArray arrayWithObjects:	BackToolbarItemIdentifier,
   55:                                         ForwardToolbarItemIdentifier,
   56:                                         ReloadToolbarItemIdentifier,
   57:                                         StopToolbarItemIdentifier,
   58:                                         HomeToolbarItemIdentifier,
   59:                                         LocationToolbarItemIdentifier,
   60:                                         SidebarToolbarItemIdentifier,
   61:                                         NSToolbarCustomizeToolbarItemIdentifier,
   62:                                         NSToolbarFlexibleSpaceItemIdentifier,
   63:                                         NSToolbarSpaceItemIdentifier,
   64:                                         NSToolbarSeparatorItemIdentifier,
   65:                                         nil];
   66: }
   67: 
   68: - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
   69: {
   70:     return [NSArray arrayWithObjects:	BackToolbarItemIdentifier,
   71:                                         ForwardToolbarItemIdentifier,
   72:                                         ReloadToolbarItemIdentifier,
   73:                                         StopToolbarItemIdentifier,
   74:                                         HomeToolbarItemIdentifier,
   75:                                         LocationToolbarItemIdentifier,
   76:                                         SidebarToolbarItemIdentifier,
   77:                                         nil];
   78: }
   79: 
   80: - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
   81:       itemForItemIdentifier:(NSString *)itemIdent
   82:   willBeInsertedIntoToolbar:(BOOL)willBeInserted
   83: {
   84:     NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
   85:     if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
   86:         [toolbarItem setLabel:@"Back"];
   87:         [toolbarItem setPaletteLabel:@"Go Back"];
   88:         [toolbarItem setToolTip:@"Go back one page"];
   89:         [toolbarItem setImage:[NSImage imageNamed:@"back"]];
   90:         [toolbarItem setTarget:self];
   91:         [toolbarItem setAction:@selector(back:)];
   92:     } else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
   93:         [toolbarItem setLabel:@"Forward"];
   94:         [toolbarItem setPaletteLabel:@"Go Forward"];
   95:         [toolbarItem setToolTip:@"Go forward one page"];
   96:         [toolbarItem setImage:[NSImage imageNamed:@"forward"]];
   97:         [toolbarItem setTarget:self];
   98:         [toolbarItem setAction:@selector(forward:)];
   99:     } else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
  100:         [toolbarItem setLabel:@"Reload"];
  101:         [toolbarItem setPaletteLabel:@"Reload Page"];
  102:         [toolbarItem setToolTip:@"Reload current page"];
  103:         [toolbarItem setImage:[NSImage imageNamed:@"reload"]];
  104:         [toolbarItem setTarget:self];
  105:         [toolbarItem setAction:@selector(reload:)];
  106:     } else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
  107:         [toolbarItem setLabel:@"Stop"];
  108:         [toolbarItem setPaletteLabel:@"Stop Loading"];
  109:         [toolbarItem setToolTip:@"Stop loading this page"];
  110:         [toolbarItem setImage:[NSImage imageNamed:@"stop"]];
  111:         [toolbarItem setTarget:self];
  112:         [toolbarItem setAction:@selector(stop:)];
  113:     } else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
  114:         [toolbarItem setLabel:@"Home"];
  115:         [toolbarItem setPaletteLabel:@"Go Home"];
  116:         [toolbarItem setToolTip:@"Go to home page"];
  117:         [toolbarItem setImage:[NSImage imageNamed:@"home"]];
  118:         [toolbarItem setTarget:self];
  119:         [toolbarItem setAction:@selector(home:)];
  120:     } else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
  121:         [toolbarItem setLabel:@"Sidebar"];
  122:         [toolbarItem setPaletteLabel:@"Toggle Sidebar"];
  123:         [toolbarItem setToolTip:@"Show or hide the Sidebar"];
  124:         [toolbarItem setImage:[NSImage imageNamed:@"sidebar"]];
  125:         [toolbarItem setTarget:self];
  126:         [toolbarItem setAction:@selector(toggleSidebar:)];
  127:     } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
  128:         
  129:         NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
  130:         
  131:         [toolbarItem setLabel:@"Location"];
  132:         [toolbarItem setPaletteLabel:@"Location"];
  133:         [toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
  134:         [toolbarItem setView:mLocationToolbarView];
  135:         [toolbarItem setMinSize:NSMakeSize(128,32)];
  136:         [toolbarItem setMaxSize:NSMakeSize(2560,32)];
  137:         
  138:         [menuFormRep setTarget:self];
  139:         [menuFormRep setAction:@selector(displayLocationSheet:)];
  140:         [menuFormRep setTitle:[toolbarItem label]];
  141:         
  142:         [toolbarItem setMenuFormRepresentation:menuFormRep];
  143:         
  144:     } else {
  145:         toolbarItem = nil;
  146:     }
  147:         
  148:     return toolbarItem;
  149: }
  150: 
  151: // This method handles the enabling/disabling of the toolbar buttons.
  152: - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
  153: {
  154:   // Check the action and see if it matches.
  155:   SEL action = [theItem action];
  156:   if (action == @selector(back:))
  157:     return [[mBrowserView getBrowserView] canGoBack];
  158:   else if (action == @selector(forward:))
  159:     return [[mBrowserView getBrowserView] canGoForward];
  160:   else if (action == @selector(reload:))
  161:     return [mBrowserView isBusy] == NO;
  162:   else if (action == @selector(stop:))
  163:     return [mBrowserView isBusy];
  164:   else
  165:     return YES;
  166: }
  167:    
  168: -(void)updateToolbarItems
  169: {
  170:   [[[self window] toolbar] validateVisibleItems];
  171: }
  172: 
  173: -(void) focusURLBar
  174: {
  175:     [mURLBar selectText: self];
  176: }
  177: 
  178: -(IBAction) back:(id)aSender
  179: {
  180:   [[mBrowserView getBrowserView] goBack];
  181: }
  182: 
  183: -(IBAction) forward:(id)aSender
  184: {
  185:   [[mBrowserView getBrowserView] goForward];
  186: }
  187: 
  188: -(IBAction) reload:(id)aSender
  189: {
  190:   [[mBrowserView getBrowserView] reload: 0];
  191: }
  192: 
  193: -(IBAction) stop:(id)aSender
  194: {
  195:   [[mBrowserView getBrowserView] stop: 0];
  196: }
  197: 
  198: -(IBAction) home:(id)aSender
  199: {
  200:   NSURL* url = [NSURL URLWithString:@"about:blank"];
  201:   [[mBrowserView getBrowserView] loadURI:url flags:NSLoadFlagsNone];
  202: }
  203: 
  204: -(IBAction) toggleSidebar:(id)aSender
  205: {
  206:     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) {
  207:         [mSidebarDrawer open];
  208:     } else {
  209:         [mSidebarDrawer close];
  210:     }
  211: }
  212: 
  213: -(void)loadURL:(NSURL*)aURL
  214: {
  215:     if (mInitialized)
  216:         [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
  217:     else {
  218:         mURL = aURL;
  219:         [mURL retain];
  220:     }
  221: }
  222: @end
  223: 

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