Annotation of chimera/MyBrowserView.mm, revision 1.2

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: {
                     14:   // May need to override in the future.
                     15:   [super dealloc];
                     16: }
                     17: 
                     18: - (IBAction)load:(id)sender
                     19: {
                     20:   NSString* str = [urlbar stringValue];
                     21:   NSURL* url = [NSURL URLWithString:str];
                     22:   [browserView loadURI:url flags:NSLoadFlagsNone];
                     23: }
                     24: 
                     25: - (void)awakeFromNib 
                     26: {
                     27:   NSRect bounds = [self bounds];
                     28:   browserView = [[NSBrowserView alloc] initWithFrame: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:   [urlbar setStringValue: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:   NSWindow* window = [self window];
                    156:   NSString* str = [window title];
                    157:   return str;
                    158: }
                    159: 
                    160: - (void)setTitle:(NSString *)title
                    161: {
                    162:   NSWindow* window = [self window];
                    163:   [window setTitle:title];
                    164: }
                    165: 
                    166: - (void)sizeBrowserTo:(NSSize)dimensions
                    167: {
                    168:   NSRect bounds = [self bounds];
                    169:   float dx = dimensions.width - bounds.size.width;
                    170:   float dy = dimensions.height - bounds.size.height;
                    171: 
                    172:   NSWindow* window = [self window];
                    173:   NSRect frame = [window frame];
                    174:   frame.size.width += dx;
                    175:   frame.size.height += dy;
                    176: 
                    177:   [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>