Annotation of chimera/BookmarksButton.mm, revision 1.7

1.1       hyatt       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"
1.2       hyatt      10: #include "nsIDOMElement.h"
1.6       hyatt      11: #include "nsIContent.h"
1.2       hyatt      12: #include "nsString.h"
1.6       hyatt      13: #import "BookmarksService.h"
1.1       hyatt      14: 
                     15: @implementation BookmarksButton
                     16: 
                     17: - (id)initWithFrame:(NSRect)frame {
                     18:   self = [super initWithFrame:frame];
                     19:   if (self) {
                     20:     // Initialization code here.
1.2       hyatt      21:     mElement = nsnull;
                     22:     [self setBezelStyle: NSRegularSquareBezelStyle];
                     23:     [self setBordered: NO];
                     24:     [self setImagePosition: NSImageLeft];
                     25:     [self setRefusesFirstResponder: YES];
                     26:     [self setFont: [NSFont labelFontOfSize: 11.0]];
1.1       hyatt      27:   }
1.2       hyatt      28:   return self;
                     29: }
1.1       hyatt      30: 
1.3       hyatt      31: -(IBAction)openBookmark:(id)aSender
                     32: {
                     33:   printf("Yo?\n");
                     34:   
                     35:   // Get the href attribute.  This is the URL we want to load.
                     36:   nsAutoString href;
                     37:   mElement->GetAttribute(NS_LITERAL_STRING("href"), href);
                     38:   nsCAutoString cref; cref.AssignWithConversion(href);
                     39:   if (cref.IsEmpty())
                     40:     return;
                     41: 
                     42:   NSString* url = [NSString stringWithCString: cref.get()];
                     43: 
                     44:   // Now load the URL in the window.
                     45:   [[[self window] windowController] loadURL:[NSURL URLWithString: url]];
                     46: 
                     47:   // Focus and activate our content area.
                     48:   [[[[[self window] windowController] getMyBrowserView] getBrowserView] setActive: YES];
                     49: }
                     50: 
1.5       hyatt      51: -(void)drawRect:(NSRect)aRect
1.4       hyatt      52: {
1.5       hyatt      53:   [super drawRect: aRect];
1.4       hyatt      54: }
                     55: 
1.7     ! hyatt      56: -(NSMenu*)menuForEvent:(NSEvent*)aEvent
        !            57: {
        !            58:   return [[self superview] menu];
        !            59: }
        !            60: 
1.6       hyatt      61: -(void)mouseDown:(NSEvent*)aEvent
                     62: {
                     63:   if (mIsFolder) {
                     64:     nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
                     65:     NSMenu* menu = BookmarksService::LocateMenu(content);
                     66:     [NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
                     67:   }
                     68:   else
                     69:     [super mouseDown: aEvent];
                     70: }
                     71: 
1.2       hyatt      72: -(void)setElement: (nsIDOMElement*)aElt
                     73: {
                     74:   mElement = aElt;
                     75:   nsAutoString tag;
                     76:   mElement->GetLocalName(tag);
1.6       hyatt      77:   if (tag.Equals(NS_LITERAL_STRING("folder"))) {
1.2       hyatt      78:     [self setImage: [NSImage imageNamed: @"folder"]];
1.6       hyatt      79:     mIsFolder = YES;
                     80:   }
1.3       hyatt      81:   else {
1.6       hyatt      82:     mIsFolder = NO;
1.2       hyatt      83:     [self setImage: [NSImage imageNamed: @"smallbookmark"]];
1.3       hyatt      84:     [self setAction: @selector(openBookmark:)];
                     85:     [self setTarget: self];
                     86:   }
                     87:   
1.2       hyatt      88:   nsAutoString name;
                     89:   mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
                     90:   [self setTitle: [NSString stringWithCharacters: name.get() length: nsCRT::strlen(name.get())]];
1.6       hyatt      91: }
                     92: 
                     93: -(nsIDOMElement*)element
                     94: {
                     95:   return mElement;
1.1       hyatt      96: }
                     97: 
                     98: @end

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