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, 3 months 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.

    1: /*
    2:  *  MyBrowserView.mm
    3:  */
    4: 
    5: #import "MyBrowserView.h"
    6: 
    7: #define DOCUMENT_DONE_STRING @"Document: Done"
    8: #define LOADING_STRING @"Loading..."
    9: 
   10: @implementation MyBrowserView
   11: 
   12: -(void)dealloc
   13: {
   14: 	[browserView release];
   15: 	[defaultStatus release];
   16:     [loadingStatus release];
   17:     
   18: 	[super dealloc];
   19: }
   20: 
   21: - (IBAction)load:(id)sender
   22: {
   23:   [browserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
   24: }
   25: 
   26: - (void)awakeFromNib 
   27: {
   28:   browserView = [[NSBrowserView alloc] initWithFrame:[self bounds]];
   29:   [self addSubview:browserView];
   30:   [browserView setContainer:self];
   31:   [browserView addListener:self];
   32: 
   33:   defaultStatus = NULL;
   34:   loadingStatus = DOCUMENT_DONE_STRING;
   35:   [status setStringValue:loadingStatus];
   36:   mIsBusy = NO;
   37:   
   38:   [progress retain];
   39:   [progress removeFromSuperview];
   40: }
   41: 
   42: - (void)setFrame:(NSRect)frameRect
   43: {
   44:   [super setFrame:frameRect];
   45:   NSRect bounds = [self bounds];
   46:   [browserView setFrame:bounds];
   47: }
   48: 
   49: -(BOOL)isBusy
   50: {
   51:   return mIsBusy;
   52: }
   53: 
   54: - (void)onLoadingStarted 
   55: {
   56:   if (defaultStatus) {
   57:     [defaultStatus release];
   58:     defaultStatus = NULL;
   59:   }
   60: 
   61:   [progressSuper addSubview:progress];
   62:   [progress release];
   63:   [progress setIndeterminate:YES];
   64:   [progress startAnimation:self];
   65: 
   66:   loadingStatus = LOADING_STRING;
   67:   [status setStringValue:loadingStatus];
   68: 
   69:   mIsBusy = YES;
   70:   if (mWindowController)
   71:     [mWindowController updateToolbarItems];
   72:     
   73: #ifdef DEBUG_vidur
   74:   printf("Starting to load\n");
   75: #endif
   76: }
   77: 
   78: - (void)onLoadingCompleted:(BOOL)succeeded
   79: {
   80:   [progress setIndeterminate:YES];
   81:   [progress stopAnimation:self];
   82:   [progress retain];
   83:   [progress removeFromSuperview];
   84: 
   85:   loadingStatus = DOCUMENT_DONE_STRING;
   86:   if (defaultStatus) {
   87:     [status setStringValue:defaultStatus];
   88:   }
   89:   else {
   90:     [status setStringValue:loadingStatus];
   91:   }
   92: 
   93:   mIsBusy = NO;
   94:   
   95:   if (mWindowController)
   96:     [mWindowController updateToolbarItems];
   97:   
   98: #ifdef DEBUG_vidur
   99:   printf("Loading completed\n");
  100: #endif
  101: }
  102: 
  103: - (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes 
  104: {
  105:   if (maxBytes > 0) {
  106:     BOOL isIndeterminate = [progress isIndeterminate];
  107:     if (isIndeterminate) {
  108:       [progress setIndeterminate:NO];
  109:     }
  110:     double val = ((double)currentBytes / (double)maxBytes) * 100.0;
  111:     [progress setDoubleValue:val];
  112: #ifdef DEBUG_vidur
  113:     printf("Progress notification: %f%%\n", val);
  114: #endif
  115:   }
  116: }
  117: 
  118: - (void)onLocationChange:(NSURL*)url 
  119: {
  120:   NSString* spec = [url absoluteString];
  121:   [mWindowController updateLocationFields:spec];
  122:   
  123: #ifdef DEBUG_vidur
  124:   const char* str = [spec cString];
  125:   printf("Location changed to: %s\n", str);
  126: #endif
  127: }
  128: 
  129: - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type 
  130: {
  131:   if (type == NSStatusTypeScriptDefault) {
  132:     if (defaultStatus) {
  133:       [defaultStatus release];
  134:     }
  135:     defaultStatus = statusString;
  136:     if (defaultStatus) {
  137:       [defaultStatus retain];
  138:     }
  139:   }
  140:   else if (!statusString) {
  141:     if (defaultStatus) {
  142:       [status setStringValue:defaultStatus];
  143:     }
  144:     else {
  145:       [status setStringValue:loadingStatus];
  146:     }      
  147:   }
  148:   else {
  149:     [status setStringValue:statusString];
  150:   }
  151: }
  152: 
  153: - (NSString *)title 
  154: {
  155:   return [[mWindowController window] title];
  156: }
  157: 
  158: - (void)setTitle:(NSString *)title
  159: {
  160:     if ( (title) && (! [title isEqualToString:@""]) ) {
  161:         [[mWindowController window] setTitle:title];
  162:     } else {
  163:         [[mWindowController window] setTitle:@"Untitled"];
  164:     }
  165: }
  166: 
  167: - (void)sizeBrowserTo:(NSSize)dimensions
  168: {
  169:   NSRect bounds = [self bounds];
  170:   float dx = dimensions.width - bounds.size.width;
  171:   float dy = dimensions.height - bounds.size.height;
  172: 
  173:   NSRect frame = [[self window] frame];
  174:   frame.size.width += dx;
  175:   frame.size.height += dy;
  176: 
  177:   [[self window] setFrame:frame display:YES];
  178: }
  179: 
  180: - (NSBrowserView*)createBrowserWindow:(unsigned int)mask
  181: {
  182:   // XXX not implemented 
  183:   return NULL;
  184: }
  185: 
  186: - (NSBrowserView*)getBrowserView
  187: {
  188:   return browserView;
  189: }
  190: 
  191: @end

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