File:  [mozdev] / chimera / BookmarksButton.mm
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Wed Apr 17 10:30:13 2002 UTC (17 years, 6 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Adding a page proxy icon to the location bar.

    1: //
    2: //  BookmarksButton.mm
    3: //  Chimera
    4: //
    5: //  Created by David Hyatt on Mon Apr 15 2002.
    6: //  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
    7: //
    8: 
    9: #import "BookmarksButton.h"
   10: #include "nsIDOMElement.h"
   11: #include "nsString.h"
   12: 
   13: @implementation BookmarksButton
   14: 
   15: - (id)initWithFrame:(NSRect)frame {
   16:   self = [super initWithFrame:frame];
   17:   if (self) {
   18:     // Initialization code here.
   19:     mElement = nsnull;
   20:     [self setBezelStyle: NSRegularSquareBezelStyle];
   21:     [self setBordered: NO];
   22:     [self setImagePosition: NSImageLeft];
   23:     [self setRefusesFirstResponder: YES];
   24:     [self setFont: [NSFont labelFontOfSize: 11.0]];
   25:   }
   26:   return self;
   27: }
   28: 
   29: -(IBAction)openBookmark:(id)aSender
   30: {
   31:   printf("Yo?\n");
   32:   
   33:   // Get the href attribute.  This is the URL we want to load.
   34:   nsAutoString href;
   35:   mElement->GetAttribute(NS_LITERAL_STRING("href"), href);
   36:   nsCAutoString cref; cref.AssignWithConversion(href);
   37:   if (cref.IsEmpty())
   38:     return;
   39: 
   40:   NSString* url = [NSString stringWithCString: cref.get()];
   41: 
   42:   // Now load the URL in the window.
   43:   [[[self window] windowController] loadURL:[NSURL URLWithString: url]];
   44: 
   45:   // Focus and activate our content area.
   46:   [[[[[self window] windowController] getMyBrowserView] getBrowserView] setActive: YES];
   47: }
   48: 
   49: -(void)drawRect:(NSRect)aRect
   50: {
   51:   [super drawRect: aRect];
   52: }
   53: 
   54: -(void)setElement: (nsIDOMElement*)aElt
   55: {
   56:   mElement = aElt;
   57:   nsAutoString tag;
   58:   mElement->GetLocalName(tag);
   59:   if (tag.Equals(NS_LITERAL_STRING("folder")))
   60:     [self setImage: [NSImage imageNamed: @"folder"]];
   61:   else {
   62:     [self setImage: [NSImage imageNamed: @"smallbookmark"]];
   63:     [self setAction: @selector(openBookmark:)];
   64:     [self setTarget: self];
   65:   }
   66:   
   67:   nsAutoString name;
   68:   mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
   69:   [self setTitle: [NSString stringWithCharacters: name.get() length: nsCRT::strlen(name.get())]];
   70: }
   71: 
   72: @end

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