Annotation of chimera/BookmarksToolbar.mm, revision 1.4

1.1       hyatt       1: //
                      2: //  BookmarksToolbar.mm
                      3: //  Chimera
                      4: //
                      5: //  Created by David Hyatt on Mon Apr 15 2002.
                      6: //  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
                      7: //
                      8: 
1.2       hyatt       9: #import "BookmarksButton.h"
1.1       hyatt      10: #import "BookmarksToolbar.h"
1.3       hyatt      11: #import "BookmarksService.h"
1.4     ! hyatt      12: #include "nsIDOMElement.h"
1.1       hyatt      13: 
                     14: @implementation BookmarksToolbar
                     15: 
                     16: - (id)initWithFrame:(NSRect)frame {
                     17:   self = [super initWithFrame:frame];
                     18:   if (self) {
1.3       hyatt      19:     mBookmarks = nsnull;
1.1       hyatt      20:   }
                     21:   return self;
1.3       hyatt      22: }
                     23: 
                     24: -(void)initializeToolbar
                     25: {
                     26:   // Initialization code here.
                     27:   mBookmarks = new BookmarksService(self);
                     28:   mBookmarks->AddObserver();
1.4     ! hyatt      29:   mBookmarks->EnsureToolbarRoot();
        !            30:   [self buildButtonList];
1.3       hyatt      31: }
                     32: 
                     33: -(void) dealloc
                     34: {
                     35:   mBookmarks->RemoveObserver();
                     36:   delete mBookmarks;
                     37:   [super dealloc];
1.1       hyatt      38: }
                     39: 
                     40: - (void)drawRect:(NSRect)aRect {
                     41:   // Fill the background with our background color.
1.2       hyatt      42: //  [[NSColor colorWithCalibratedWhite: 0.98 alpha: 1.0] set];
                     43: //  NSRectFill(aRect);
1.1       hyatt      44: 
                     45:   //printf("The rect is: %f %f %f %f\n", aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height);
                     46:   
                     47:   if (aRect.origin.y + aRect.size.height ==
                     48:       [self bounds].size.height) {
                     49:     // The personal toolbar is 21 pixels tall.  The bottom two pixels
                     50:     // are a separator.
                     51:     [[NSColor colorWithCalibratedWhite: 0.92 alpha: 1.0] set];
                     52:     NSRectFill(NSMakeRect(aRect.origin.x, aRect.origin.y, aRect.size.width, 2));
                     53:   }
                     54: 
1.2       hyatt      55:   // The buttons will paint themselves.
1.1       hyatt      56: }
                     57: 
1.4     ! hyatt      58: -(void)buildButtonList
        !            59: {
        !            60:   // Build the buttons, and then lay them all out.
        !            61:   nsCOMPtr<nsIDOMNode> child;
        !            62:   BookmarksService::gToolbarRoot->GetFirstChild(getter_AddRefs(child));
        !            63:   while (child) {
        !            64:     nsCOMPtr<nsIDOMElement> childElt(do_QueryInterface(child));
        !            65:     if (childElt) {
        !            66:       BookmarksButton* button = [[[BookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17)] autorelease];
        !            67:       [button setElement: childElt];
        !            68:       [self addSubview: button];
        !            69:     }
        !            70: 
        !            71:     nsCOMPtr<nsIDOMNode> temp = child;
        !            72:     temp->GetNextSibling(getter_AddRefs(child));
        !            73:   }
        !            74: 
        !            75:   [self reflowButtons];
        !            76: }
        !            77: 
        !            78: -(void)reflowButtons
        !            79: {
        !            80: }
1.1       hyatt      81: @end

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