File:  [mozdev] / chimera / BrowserWindowController.mm
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Tue Jan 29 10:01:11 2002 UTC (17 years, 4 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Initial commit of Chimera, a Gecko-based browser with a native Cocoa front end.

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

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