Annotation of chimera/MyBrowserView.mm, revision 1.7

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

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