File:  [mozdev] / chimera / BrowserWindowController.mm
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Wed Jan 30 04:52:38 2002 UTC (17 years, 10 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
Chimera: Header comments modified for consistency

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

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