#import "GreenstoneButtonBar.h"
#import "GreenstoneApplication.h"

@implementation GreenstoneButtonBar

- (UIButtonBar*)initInView:(UIView*)view withFrame:(CGRect)frame
{
    self = [super initInView: view withFrame: frame
       withItemList: [self buttonBarItemList]];

    GreenstoneApplication* app = [GreenstoneApplication toplevelApp];

    [self setDelegate: app ];
    [self setBarStyle: UIBarStyleBlack ];
    [self setButtonBarTrackingMode: 2 ];

    int buttons[NUM_GSBAR_BUTTONS] = { GSBBBrowse, GSBBQuery, GSBBPref };

    [self registerButtonGroup: 0 withButtons: buttons withCount: NUM_GSBAR_BUTTONS ];
    [self showButtonGroup: 0 withDuration: 0.0 ];

    // *** This and the fact that BookmarkSelected.png seems to be back to front is a bit weird!
    [self showSelectionForButton: 1 ];

    return self;
}

- (NSArray *)buttonBarItemList 
{
    GreenstoneApplication* app = [GreenstoneApplication toplevelApp];

    NSArray* buts 
      = [ NSArray arrayWithObjects:
          [ NSDictionary dictionaryWithObjectsAndKeys:
            @"buttonBarClicked:", kUIButtonBarButtonAction,
            @"icons/BookmarkSelected.png", kUIButtonBarButtonInfo,
            @"icons/Bookmark.png", kUIButtonBarButtonSelectedInfo,
            [ NSNumber numberWithInt: 1], kUIButtonBarButtonTag,
              app, kUIButtonBarButtonTarget,
            @"Browse", kUIButtonBarButtonTitle,
            @"0", kUIButtonBarButtonType,
            nil
          ],

          [ NSDictionary dictionaryWithObjectsAndKeys:
            @"buttonBarClicked:", kUIButtonBarButtonAction,
            @"icons/Search.png", kUIButtonBarButtonInfo,
            @"icons/SearchSelected.png", kUIButtonBarButtonSelectedInfo,
            [ NSNumber numberWithInt: 2], kUIButtonBarButtonTag,
              app, kUIButtonBarButtonTarget,
            @"Search", kUIButtonBarButtonTitle,
            @"0", kUIButtonBarButtonType,
            nil
          ],
 
          [ NSDictionary dictionaryWithObjectsAndKeys:
            @"buttonBarClicked:", kUIButtonBarButtonAction,
            @"icons/Preferences.png", kUIButtonBarButtonInfo,
            @"icons/PreferencesSelected.png", kUIButtonBarButtonSelectedInfo,
            [ NSNumber numberWithInt: 3], kUIButtonBarButtonTag,
              app, kUIButtonBarButtonTarget,
            @"Settings", kUIButtonBarButtonTitle,
            @"0", kUIButtonBarButtonType,
            nil
          ],

          nil
      ];

    return buts;
}

@end
