Annotation of chimera/MyBrowserView.mm, revision 1.3

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

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