Annotation of chimera/BookmarksButton.mm, revision 1.8

1.8     ! macserv     1: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
        !             2: /* ***** BEGIN LICENSE BLOCK *****
        !             3: * Version: NPL 1.1/GPL 2.0/LGPL 2.1
        !             4: *
        !             5: * The contents of this file are subject to the Netscape Public License
        !             6: * Version 1.1 (the "License"); you may not use this file except in
        !             7: * compliance with the License. You may obtain a copy of the License at
        !             8: * http://www.mozilla.org/NPL/
        !             9: *
        !            10: * Software distributed under the License is distributed on an "AS IS" basis,
        !            11: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
        !            12: * for the specific language governing rights and limitations under the
        !            13: * License.
        !            14: *
        !            15: * The Original Code is mozilla.org code.
        !            16: *
        !            17: * The Initial Developer of the Original Code is
        !            18: * Netscape Communications Corporation.
        !            19: * Portions created by the Initial Developer are Copyright (C) 2002
        !            20: * the Initial Developer. All Rights Reserved.
        !            21: *
        !            22: * Contributor(s):
        !            23: *
        !            24: * Alternatively, the contents of this file may be used under the terms of
        !            25: * either the GNU General Public License Version 2 or later (the "GPL"), or
        !            26: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
        !            27: * in which case the provisions of the GPL or the LGPL are applicable instead
        !            28: * of those above. If you wish to allow use of your version of this file only
        !            29: * under the terms of either the GPL or the LGPL, and not to allow others to
        !            30: * use your version of this file under the terms of the NPL, indicate your
        !            31: * decision by deleting the provisions above and replace them with the notice
        !            32: * and other provisions required by the GPL or the LGPL. If you do not delete
        !            33: * the provisions above, a recipient may use your version of this file under
        !            34: * the terms of any one of the NPL, the GPL or the LGPL.
        !            35: *
        !            36: * ***** END LICENSE BLOCK ***** */
1.1       hyatt      37: 
                     38: #import "BookmarksButton.h"
1.2       hyatt      39: #include "nsIDOMElement.h"
1.6       hyatt      40: #include "nsIContent.h"
1.2       hyatt      41: #include "nsString.h"
1.6       hyatt      42: #import "BookmarksService.h"
1.1       hyatt      43: 
                     44: @implementation BookmarksButton
                     45: 
                     46: - (id)initWithFrame:(NSRect)frame {
1.8     ! macserv    47:     if ( (self = [super initWithFrame:frame]) ) {
        !            48:         mElement = nsnull;
        !            49:         [self setBezelStyle: NSRegularSquareBezelStyle];
        !            50:         [self setBordered: NO];
        !            51:         [self setImagePosition: NSImageLeft];
        !            52:         [self setRefusesFirstResponder: YES];
        !            53:         [self setFont: [NSFont labelFontOfSize: 11.0]];
        !            54:     }
1.2       hyatt      55:   return self;
                     56: }
1.1       hyatt      57: 
1.3       hyatt      58: -(IBAction)openBookmark:(id)aSender
                     59: {
                     60:   printf("Yo?\n");
                     61:   
                     62:   // Get the href attribute.  This is the URL we want to load.
                     63:   nsAutoString href;
                     64:   mElement->GetAttribute(NS_LITERAL_STRING("href"), href);
                     65:   nsCAutoString cref; cref.AssignWithConversion(href);
                     66:   if (cref.IsEmpty())
                     67:     return;
                     68: 
                     69:   NSString* url = [NSString stringWithCString: cref.get()];
                     70: 
                     71:   // Now load the URL in the window.
                     72:   [[[self window] windowController] loadURL:[NSURL URLWithString: url]];
                     73: 
                     74:   // Focus and activate our content area.
                     75:   [[[[[self window] windowController] getMyBrowserView] getBrowserView] setActive: YES];
                     76: }
                     77: 
1.5       hyatt      78: -(void)drawRect:(NSRect)aRect
1.4       hyatt      79: {
1.5       hyatt      80:   [super drawRect: aRect];
1.4       hyatt      81: }
                     82: 
1.7       hyatt      83: -(NSMenu*)menuForEvent:(NSEvent*)aEvent
                     84: {
                     85:   return [[self superview] menu];
                     86: }
                     87: 
1.6       hyatt      88: -(void)mouseDown:(NSEvent*)aEvent
                     89: {
                     90:   if (mIsFolder) {
                     91:     nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
                     92:     NSMenu* menu = BookmarksService::LocateMenu(content);
                     93:     [NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
                     94:   }
                     95:   else
                     96:     [super mouseDown: aEvent];
                     97: }
                     98: 
1.2       hyatt      99: -(void)setElement: (nsIDOMElement*)aElt
                    100: {
                    101:   mElement = aElt;
                    102:   nsAutoString tag;
                    103:   mElement->GetLocalName(tag);
1.6       hyatt     104:   if (tag.Equals(NS_LITERAL_STRING("folder"))) {
1.2       hyatt     105:     [self setImage: [NSImage imageNamed: @"folder"]];
1.6       hyatt     106:     mIsFolder = YES;
                    107:   }
1.3       hyatt     108:   else {
1.6       hyatt     109:     mIsFolder = NO;
1.2       hyatt     110:     [self setImage: [NSImage imageNamed: @"smallbookmark"]];
1.3       hyatt     111:     [self setAction: @selector(openBookmark:)];
                    112:     [self setTarget: self];
                    113:   }
                    114:   
1.2       hyatt     115:   nsAutoString name;
                    116:   mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
                    117:   [self setTitle: [NSString stringWithCharacters: name.get() length: nsCRT::strlen(name.get())]];
1.6       hyatt     118: }
                    119: 
                    120: -(nsIDOMElement*)element
                    121: {
                    122:   return mElement;
1.1       hyatt     123: }
                    124: 
                    125: @end

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