File:  [mozdev] / chimera / MyBrowserView.mm
Revision 1.6: download - view: text, annotated - select for diffs - revision graph
Thu Jan 31 07:14:20 2002 UTC (17 years, 1 month ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Remove title prefix on windows.  It isn't necessary (and makes the list in the Window menu look goofy).  Got link coloring working for visited links, but it doesn't persist across sessions. Not sure why yet.

/*
 *  MyBrowserView.mm
 */

#import "MyBrowserView.h"

#define DOCUMENT_DONE_STRING @"Document: Done"
#define LOADING_STRING @"Loading..."

@implementation MyBrowserView

-(void)dealloc
{
	[browserView release];
	[defaultStatus release];
    [loadingStatus release];
    
	[super dealloc];
}

- (IBAction)load:(id)sender
{
  [browserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
}

- (void)awakeFromNib 
{
  browserView = [[NSBrowserView alloc] initWithFrame:[self bounds]];
  [self addSubview:browserView];
  [browserView setContainer:self];
  [browserView addListener:self];

  defaultStatus = NULL;
  loadingStatus = DOCUMENT_DONE_STRING;
  [status setStringValue:loadingStatus];
  mIsBusy = NO;
  
  [progress retain];
  [progress removeFromSuperview];
}

- (void)setFrame:(NSRect)frameRect
{
  [super setFrame:frameRect];
  NSRect bounds = [self bounds];
  [browserView setFrame:bounds];
}

-(BOOL)isBusy
{
  return mIsBusy;
}

- (void)onLoadingStarted 
{
  if (defaultStatus) {
    [defaultStatus release];
    defaultStatus = NULL;
  }

  [progressSuper addSubview:progress];
  [progress release];
  [progress setIndeterminate:YES];
  [progress startAnimation:self];

  loadingStatus = LOADING_STRING;
  [status setStringValue:loadingStatus];

  mIsBusy = YES;
  if (mWindowController)
    [mWindowController updateToolbarItems];
    
#ifdef DEBUG_vidur
  printf("Starting to load\n");
#endif
}

- (void)onLoadingCompleted:(BOOL)succeeded
{
  [progress setIndeterminate:YES];
  [progress stopAnimation:self];
  [progress retain];
  [progress removeFromSuperview];

  loadingStatus = DOCUMENT_DONE_STRING;
  if (defaultStatus) {
    [status setStringValue:defaultStatus];
  }
  else {
    [status setStringValue:loadingStatus];
  }

  mIsBusy = NO;
  
  if (mWindowController)
    [mWindowController updateToolbarItems];
  
#ifdef DEBUG_vidur
  printf("Loading completed\n");
#endif
}

- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes 
{
  if (maxBytes > 0) {
    BOOL isIndeterminate = [progress isIndeterminate];
    if (isIndeterminate) {
      [progress setIndeterminate:NO];
    }
    double val = ((double)currentBytes / (double)maxBytes) * 100.0;
    [progress setDoubleValue:val];
#ifdef DEBUG_vidur
    printf("Progress notification: %f%%\n", val);
#endif
  }
}

- (void)onLocationChange:(NSURL*)url 
{
  NSString* spec = [url absoluteString];
  [mWindowController updateLocationFields:spec];
  
#ifdef DEBUG_vidur
  const char* str = [spec cString];
  printf("Location changed to: %s\n", str);
#endif
}

- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type 
{
  if (type == NSStatusTypeScriptDefault) {
    if (defaultStatus) {
      [defaultStatus release];
    }
    defaultStatus = statusString;
    if (defaultStatus) {
      [defaultStatus retain];
    }
  }
  else if (!statusString) {
    if (defaultStatus) {
      [status setStringValue:defaultStatus];
    }
    else {
      [status setStringValue:loadingStatus];
    }      
  }
  else {
    [status setStringValue:statusString];
  }
}

- (NSString *)title 
{
  return [[mWindowController window] title];
}

- (void)setTitle:(NSString *)title
{
    if ( (title) && (! [title isEqualToString:@""]) ) {
        [[mWindowController window] setTitle:title];
    } else {
        [[mWindowController window] setTitle:@"Untitled"];
    }
}

- (void)sizeBrowserTo:(NSSize)dimensions
{
  NSRect bounds = [self bounds];
  float dx = dimensions.width - bounds.size.width;
  float dy = dimensions.height - bounds.size.height;

  NSRect frame = [[self window] frame];
  frame.size.width += dx;
  frame.size.height += dy;

  [[self window] setFrame:frame display:YES];
}

- (NSBrowserView*)createBrowserWindow:(unsigned int)mask
{
  // XXX not implemented 
  return NULL;
}

- (NSBrowserView*)getBrowserView
{
  return browserView;
}

@end

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