#include<stdio.h>

#include "pimenubarx.h"
#include PIAPP_H

#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <Xm/ToggleB.h>
#include <Xm/CascadeB.h>

/************* PIMenubarX ************/

#define NBITEMB  10

/* --Methode-- */
PIMenubarX::PIMenubarX(PIApplicationGen* par, char* nom)
: PIMenubarGen(par, nom)
{
mNItem = 0;  mNItemMax = NBITEMB; 
mMbb = new _pimbxit_[mNItemMax];

XtWdg() = XmCreateMenuBar( ((PIApplicationX *)par)->MBCont()->XtWdg(), 
                            nom, NULL, 0); 

wmis = k_wmi_normal ;
stmng = 0;

SetPos(0,0);
SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);

Manage();
}


/* --Methode-- */
PIMenubarX::~PIMenubarX()
{
for(int i=0; i<mNItem; i++)
  XtDestroyWidget(mMbb[i].itb);
delete[] mMbb ;
}

/* --Methode-- */
void PIMenubarX::AppendMenu(PIMenu *pdm)
{
_pimbxit_ *buto;
Arg  wargs[2];

if (mNItem >= mNItemMax)
  {
  buto = mMbb;
  mNItemMax += NBITEMB;
  mMbb = new _pimbxit_[mNItemMax];
  for(int i=0; i<mNItem; i++)   mMbb[i] = buto[i];
  delete[] buto;
  }
XtSetArg(wargs[0], XmNsubMenuId, pdm->XtWdg());
mMbb[mNItem].itb = XtCreateManagedWidget(pdm->Nom().c_str(), xmCascadeButtonWidgetClass, 
                                         this->XtWdg(), wargs, 1) ;
mMbb[mNItem].pdm = pdm;
mNItem++;

pdm->SetMsgParent(this);
return;
}

/* --Methode-- */
void PIMenubarX::RemoveMenu(PIMenu *pdm)
{
int i,j;
for(i=0; i<mNItem; i++) 
  if ( mMbb[i].pdm == pdm ) { 
    XtDestroyWidget(mMbb[i].itb);
    for(j=i; j<mNItem-1; j++) mMbb[j] = mMbb[j+1]; 
    mNItem--;  break;  
    }
return;
}

/* --Methode-- */
void PIMenubarX::SetSensitivity(PIMenu *pdm, bool sens)
{
int i;
for(i=0; i<mNItem; i++) 
  if ( mMbb[i].pdm == pdm ) { 
    if (sens) XtSetSensitive(mMbb[i].itb, TRUE);
    else XtSetSensitive(mMbb[i].itb, FALSE);
    break;  
    }
return;
}

/* --Methode-- */
bool PIMenubarX::IsSensitive(PIMenu *pdm)
{
int i;
for(i=0; i<mNItem; i++) 
  if ( mMbb[i].pdm == pdm ) { 
    if (XtIsSensitive(mMbb[i].itb) == TRUE)  return(true);
    else return(false);
    break; 
    }
return(false);
}
