Annotation of chimera/BookmarksButton.mm, revision 1.6

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.6     ! hyatt      56: -(void)mouseDown:(NSEvent*)aEvent
        !            57: {
        !            58:   if (mIsFolder) {
        !            59:     nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
        !            60:     NSMenu* menu = BookmarksService::LocateMenu(content);
        !            61:     [NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
        !            62:   }
        !            63:   else
        !            64:     [super mouseDown: aEvent];
        !            65: }
        !            66: 
1.2       hyatt      67: -(void)setElement: (nsIDOMElement*)aElt
                     68: {
                     69:   mElement = aElt;
                     70:   nsAutoString tag;
                     71:   mElement->GetLocalName(tag);
1.6     ! hyatt      72:   if (tag.Equals(NS_LITERAL_STRING("folder"))) {
1.2       hyatt      73:     [self setImage: [NSImage imageNamed: @"folder"]];
1.6     ! hyatt      74:     mIsFolder = YES;
        !            75:   }
1.3       hyatt      76:   else {
1.6     ! hyatt      77:     mIsFolder = NO;
1.2       hyatt      78:     [self setImage: [NSImage imageNamed: @"smallbookmark"]];
1.3       hyatt      79:     [self setAction: @selector(openBookmark:)];
                     80:     [self setTarget: self];
                     81:   }
                     82:   
1.2       hyatt      83:   nsAutoString name;
                     84:   mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
                     85:   [self setTitle: [NSString stringWithCharacters: name.get() length: nsCRT::strlen(name.get())]];
1.6     ! hyatt      86: }
        !            87: 
        !            88: -(nsIDOMElement*)element
        !            89: {
        !            90:   return mElement;
1.1       hyatt      91: }
                     92: 
                     93: @end

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