Diff for /chimera/MyBrowserView.mm between versions 1.2 and 1.21

version 1.2, 2002/01/30 04:52:38 version 1.21, 2002/02/25 08:44:17
Line 3 Line 3
  */   */
   
 #import "MyBrowserView.h"  #import "MyBrowserView.h"
   #import "BrowserWindowController.h"
   
   #include "nsCOMPtr.h"
   #include "nsIServiceManager.h"
   #include "nsIIOService.h"
   
 #define DOCUMENT_DONE_STRING @"Document: Done"  #define DOCUMENT_DONE_STRING @"Document: Done"
 #define LOADING_STRING @"Loading..."  #define LOADING_STRING @"Loading..."
   
   static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
   
 @implementation MyBrowserView  @implementation MyBrowserView
   
   -(void)windowClosed
   {
       // Break the cycle.
       [browserView setContainer: nil];
       [browserView removeListener: self];
       [browserView destroyWebBrowser];
   }
   
 -(void)dealloc  -(void)dealloc
 {  {
  // May need to override in the future.    printf("My browser view died.\n");
  [super dealloc];    
     [[NSNotificationCenter defaultCenter] removeObserver: self];
     
         [defaultStatus release];
     [loadingStatus release];
     
         [super dealloc];
 }  }
   
 - (IBAction)load:(id)sender  - (IBAction)load:(id)sender
 {  {
  NSString* str = [urlbar stringValue];  [browserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
  NSURL* url = [NSURL URLWithString:str]; 
  [browserView loadURI:url flags:NSLoadFlagsNone]; 
 }  }
   
- (void)awakeFromNib -(void)disconnectView
 {  {
  NSRect bounds = [self bounds];    urlbar = nil;
  browserView = [[NSBrowserView alloc] initWithFrame:bounds];    status = nil;
  [self addSubview:browserView];    progress = nil;
  [browserView setContainer:self];    progressSuper = nil;
  [browserView addListener:self];    mIsPrimary = NO;
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     
     [browserView setActive: NO];
 }
 
 - (id)initWithFrame:(NSRect)frameRect
 {
     [super initWithFrame: frameRect];
      browserView = [[[NSBrowserView alloc] initWithFrame:[self bounds]] autorelease];
     [self addSubview:browserView];
     [browserView setContainer:self];
     [browserView addListener:self];
     mIsBusy = NO;
     return self;
 }
   
   -(void)makePrimaryBrowserView: (NSTabViewItem*)tab urlbar: (id)aUrlbar status: (id)aStatus
       progress: (id)aProgress windowController: aWindowController
   {
     mTab = tab;
     urlbar = aUrlbar;
     status = aStatus;
     progress = aProgress;
     progressSuper = [aProgress superview];
     mWindowController = aWindowController;
     
     if (!mIsBusy)
         [progress removeFromSuperview];
     
   defaultStatus = NULL;    defaultStatus = NULL;
   loadingStatus = DOCUMENT_DONE_STRING;    loadingStatus = DOCUMENT_DONE_STRING;
   [status setStringValue:loadingStatus];    [status setStringValue:loadingStatus];
   mIsBusy = NO;  
       
  [progress retain];  mIsPrimary = YES;
  [progress removeFromSuperview]; 
   nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
   if (!ioService)
     return;
   PRBool offline = PR_FALSE;
   ioService->GetOffline(&offline);
   mOffline = offline;
   
   if (mWindowController) // Only register if we're the content area.
     [[NSNotificationCenter defaultCenter] addObserver:self
         selector:@selector(offlineModeChanged:)
         name:@"offlineModeChanged"
         object:nil];
         
   // Update the URL bar.
   [mWindowController updateLocationFields:[self getCurrentURLSpec]];
 }
 
 -(NSString*)getCurrentURLSpec
 {
   return [browserView getCurrentURLSpec];
 }
 
 - (void)awakeFromNib 
 {
 }  }
   
 - (void)setFrame:(NSRect)frameRect  - (void)setFrame:(NSRect)frameRect
Line 59 Line 129
   }    }
   
   [progressSuper addSubview:progress];    [progressSuper addSubview:progress];
   [progress release];  
   [progress setIndeterminate:YES];    [progress setIndeterminate:YES];
   [progress startAnimation:self];    [progress startAnimation:self];
   
Line 67 Line 136
   [status setStringValue:loadingStatus];    [status setStringValue:loadingStatus];
   
   mIsBusy = YES;    mIsBusy = YES;
     [mTab setLabel: LOADING_STRING];
     
   if (mWindowController)    if (mWindowController)
     [mWindowController updateToolbarItems];      [mWindowController updateToolbarItems];
       
 #ifdef DEBUG_vidur  
   printf("Starting to load\n");  
 #endif  
 }  }
   
 - (void)onLoadingCompleted:(BOOL)succeeded  - (void)onLoadingCompleted:(BOOL)succeeded
 {  {
   [progress setIndeterminate:YES];    [progress setIndeterminate:YES];
   [progress stopAnimation:self];    [progress stopAnimation:self];
   [progress retain];  
   [progress removeFromSuperview];    [progress removeFromSuperview];
   
   loadingStatus = DOCUMENT_DONE_STRING;    loadingStatus = DOCUMENT_DONE_STRING;
Line 94 Line 160
       
   if (mWindowController)    if (mWindowController)
     [mWindowController updateToolbarItems];      [mWindowController updateToolbarItems];
     
 #ifdef DEBUG_vidur  
   printf("Loading completed\n");  
 #endif  
 }  }
   
 - (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes   - (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes 
Line 109 Line 171
     }      }
     double val = ((double)currentBytes / (double)maxBytes) * 100.0;      double val = ((double)currentBytes / (double)maxBytes) * 100.0;
     [progress setDoubleValue:val];      [progress setDoubleValue:val];
 #ifdef DEBUG_vidur  
     printf("Progress notification: %f%%\n", val);  
 #endif  
   }    }
 }  }
   
 - (void)onLocationChange:(NSURL*)url   - (void)onLocationChange:(NSURL*)url 
 {  {
   NSString* spec = [url absoluteString];    NSString* spec = [url absoluteString];
  [urlbar setStringValue:spec];  [mWindowController updateLocationFields:spec];
  }
#ifdef DEBUG_vidur
  const char* str = [spec cString];- (void)onStatusChange:(NSString*)aStatusString
  printf("Location changed to: %s\n", str);{
#endif  [status setStringValue: aStatusString];
 }  }
   
 - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type   - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type 
Line 152 Line 211
   
 - (NSString *)title   - (NSString *)title 
 {  {
  NSWindow* window = [self window];  return [[mWindowController window] title];
  NSString* str = [window title]; 
  return str; 
 }  }
   
 - (void)setTitle:(NSString *)title  - (void)setTitle:(NSString *)title
 {  {
  NSWindow* window = [self window];    if (!mWindowController)
  [window setTitle:title];        return; // Sidebar panels can't affect the window title.
     
     // We must be the primary content area.
     if (mIsPrimary) {
         if (mOffline) {
             NSString* newTitle;
             if (title && ![title isEqualToString:@""])
                 newTitle = [title stringByAppendingString: @" [Working Offline]"];
             else
                 newTitle = @"Untitled [Working Offline]";
             [[mWindowController window] setTitle: newTitle];
         }
         else {
             if (title && ![title isEqualToString:@""])
                 [[mWindowController window] setTitle:title];
             else
                 [[mWindowController window] setTitle:@"Untitled"];
         }
     }
     
     // Always set the tab.
     if (title && ![title isEqualToString:@""])
         [mTab setLabel:title];
     else
         [mTab setLabel:@"Untitled"];
 }
 
 - (void)offlineModeChanged: (NSNotification*)aNotification
 {
     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
     if (!ioService)
         return;
     PRBool offline = PR_FALSE;
     ioService->GetOffline(&offline);
     mOffline = offline;
     
     if (mOffline) {
         NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"];
         [[mWindowController window] setTitle: newTitle];
     }
     else {
         NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"];
         [[mWindowController window] setTitle: [titleItems objectAtIndex: 0]];
     }
 }  }
   
 - (void)sizeBrowserTo:(NSSize)dimensions  - (void)sizeBrowserTo:(NSSize)dimensions
Line 169 Line 269
   float dx = dimensions.width - bounds.size.width;    float dx = dimensions.width - bounds.size.width;
   float dy = dimensions.height - bounds.size.height;    float dy = dimensions.height - bounds.size.height;
   
  NSWindow* window = [self window];  NSRect frame = [[self window] frame];
  NSRect frame = [window frame]; 
   frame.size.width += dx;    frame.size.width += dx;
   frame.size.height += dy;    frame.size.height += dy;
   
  [window setFrame:frame display:YES];  [[self window] setFrame:frame display:YES];
 }  }
   
 - (NSBrowserView*)createBrowserWindow:(unsigned int)mask  - (NSBrowserView*)createBrowserWindow:(unsigned int)mask
 {  {
  // XXX not implemented   BrowserWindowController* controller = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
  return NULL;  [controller enterModalSession];
   return [[controller getMyBrowserView] getBrowserView];
 }  }
   
 - (NSBrowserView*)getBrowserView  - (NSBrowserView*)getBrowserView

Removed from v.1.2  
changed lines
  Added in v.1.21


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