File:  [mozdev] / chimera / BookmarksButton.mm
Revision 1.8: download - view: text, annotated - select for diffs - revision graph
Sat Apr 20 00:44:56 2002 UTC (17 years, 1 month ago) by macserv
Branches: MAIN
CVS tags: HEAD
A bunch of tweaks here... no changes in functionality.  Updated trilicense header on all files that were missing it.  Fixed initialization code syntax errors all over the place.  Put back fade code, and switched fading off for now...

    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 ***** */
   37: 
   38: #import "BookmarksButton.h"
   39: #include "nsIDOMElement.h"
   40: #include "nsIContent.h"
   41: #include "nsString.h"
   42: #import "BookmarksService.h"
   43: 
   44: @implementation BookmarksButton
   45: 
   46: - (id)initWithFrame:(NSRect)frame {
   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:     }
   55:   return self;
   56: }
   57: 
   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: 
   78: -(void)drawRect:(NSRect)aRect
   79: {
   80:   [super drawRect: aRect];
   81: }
   82: 
   83: -(NSMenu*)menuForEvent:(NSEvent*)aEvent
   84: {
   85:   return [[self superview] menu];
   86: }
   87: 
   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: 
   99: -(void)setElement: (nsIDOMElement*)aElt
  100: {
  101:   mElement = aElt;
  102:   nsAutoString tag;
  103:   mElement->GetLocalName(tag);
  104:   if (tag.Equals(NS_LITERAL_STRING("folder"))) {
  105:     [self setImage: [NSImage imageNamed: @"folder"]];
  106:     mIsFolder = YES;
  107:   }
  108:   else {
  109:     mIsFolder = NO;
  110:     [self setImage: [NSImage imageNamed: @"smallbookmark"]];
  111:     [self setAction: @selector(openBookmark:)];
  112:     [self setTarget: self];
  113:   }
  114:   
  115:   nsAutoString name;
  116:   mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
  117:   [self setTitle: [NSString stringWithCharacters: name.get() length: nsCRT::strlen(name.get())]];
  118: }
  119: 
  120: -(nsIDOMElement*)element
  121: {
  122:   return mElement;
  123: }
  124: 
  125: @end

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