#include "starmenu.h"
#include "gui/button.h"
#include "starfsel.h"
#include "datawind.h"
#include "struc/starasso.h"
#include "gui/messageb.h"

@implementation WDCSTARMainMenu

- initWithName:(char*)aName managedBy:anObject
{
  [super initWithName:aName managedBy:anObject];
  _fileButton=[[WDCCascadeButton alloc] initWithName:"File" managedBy:self];
  _listButton=[[[WDCCascadeButton alloc] 
		initWithName : "List" managedBy : self] setSensitive:NO];
  _helpButton=[[WDCCascadeButton alloc] initWithName:"Help" managedBy:self];
  _fileMenu=[[WDCSTARFileMenu alloc] 
	   initWithName:"FileMenu" managedBy:_fileButton];
  _listMenu=[[WDCListMenu alloc] 
	   initWithName : "ListMenu" managedBy : _listButton];
  _helpMenu=[[WDCMenu alloc] initWithName:"HelpMenu" managedBy:_helpButton];
  [[[WDCHelpMessageBox alloc] 
    managedBy : [[WDCPushButton alloc] 
		 initWithName : "General" managedBy : _helpMenu]]
   setMessage : "Help is on the way."];
  return self;
}

- getButtonNamed:(char*)aName
{
  id button;
  switch (aName[0])
    {
    case 'F': button=_fileButton; break;
	    case 'L': button=_listButton; break;
	    case 'H': button=_helpButton; break;
	    }
  return button;
}

- getMenuNamed:(char*)aName
{
  id menu;
  switch (aName[0])
    {
    case 'F': menu=_fileMenu; break;
	    case 'L': menu=_listMenu; break;
	    case 'H': menu=_helpMenu; break;
	    }
  return menu;
}

@end


@implementation WDCSTARFileMenu

- initWithName:(char*)aName managedBy:anObject
{
  [super initWithName:aName managedBy:anObject];
  _openFileButton=[[WDCPushButton alloc] 
		 initWithName:"OpenFile" managedBy:self];
  [[[WDCSTARFileSelectBox alloc] 
    initWithName : "Open STAR File" managedBy : _openFileButton]
   setActionMessage : "parseStarFile:"];
  _quitButton=[[WDCQuitButton alloc] managedBy:self];
  return self;
}


@implementation WDCSTAROpenFileMenu

// not in use anymore

- initWithName:(char*)aName managedBy:anObject
{
  [super initWithName:aName managedBy:anObject];
  _openDictionaryButton=[[WDCPushButton alloc] 
			     initWithName : "Dictionary" managedBy:self];
  _openStarFileButton=[[WDCPushButton alloc] 
		       initWithName : "Star File" managedBy:self];
  [[[WDCSTARFileSelectBox alloc] 
    initWithName : "Open Dictionary" managedBy : _openDictionaryButton]
   setActionMessage : "parseDictionary:"];
  [[[WDCSTARFileSelectBox alloc] 
    initWithName : "Open STAR File" managedBy : _openStarFileButton]
   setActionMessage : "parseStarFile:"];
  return self;
}


@end

@implementation WDCListMenu

- setNumButtonManaged:(int)num
{
  _numButtonManaged=num;
  return self;
}

- (int)getNumButtonManaged
{
  return _numButtonManaged;
}

- setChildObject:anObject
{
  int num=[self getNumButtonManaged];
  if (!num) [[self getParentObject] setSensitive:YES];
  [super setChildObject:anObject];
  [self setNumButtonManaged:num+1];
  return self;
}

- unManageButton:button
{
  [button unManage];
  [self setNumButtonManaged:[self getNumButtonManaged]-1];
  if (![self getNumButtonManaged]) [[self getParentObject] setSensitive:NO];
  return self;
}
  
- addButtonBasedOn:anObject
{
  id tempId, viewButton, viewMenu;
  viewButton=[[WDCCascadeButton alloc] 
	      initWithName : ([anObject respondsTo:@selector(getName)]?
			      (char*)[anObject getName]:
			      "Anonymous")
	      managedBy : self];
  viewMenu=[[WDCMenu alloc] initWithName:"ViewMenu" managedBy: viewButton];
  tempId=[[WDCToggleButton alloc]
	  initWithName : "Open/Close View" managedBy : viewMenu];
  [tempId setArg:XmNvisibleWhenOff to:(char*)True];
  
//  [WDCDataWindow buildPopupWindowBasedOn : anObject managedBy : tempId];
  [anObject buildDataWindowNamed: (char*)[anObject getName]
   managedBy : tempId];

  tempId=[[WDCPushButton alloc]
	  initWithName : "Delete it" managedBy : viewMenu];
  [tempId setActionMessage : "unManageButton:" 
   withReceiver : self passObject: viewButton];
  return self;
}

@end

