#include "pioptmenumac.h"
#include "pippoptmenu.h"

/* --Methode-- */
PIOptMenuMac::PIOptMenuMac(PIContainerGen* par, PIPUMenu *pdm,
                     int sx, int sy, int px, int py)
: PIOptMenuGen(par, pdm, sx, sy, px, py), mPUMenu(pdm)
{
  delete mPane;
  //LStr255 titre(Nom().c_str());
  LStr255 titre("");
  
  StTextState textState;
  ::TextFont(systemFont);
  ::TextSize(12);
  ::TextFace(0);
  int titleWidth = ::StringWidth(titre);
  
  //mPane = new LStdPopupMenu(mPaneInfo, msg_Click, 0, 200, titleWidth+5, popupMenuProc/*+popupVariableWidth*/, 130, titre, 0, 1);
  mPane = new PIPPOptMenu(mPaneInfo, msg_Click, 0, 200, titleWidth+5, popupMenuProc/*+popupVariableWidth*/, 130, titre, 0, 1);
  //macMenu = ((LStdPopupMenu*)mPane)->GetMacMenuH();
  
  // On va changer la resource de menu au passage...
//  InsertMenu(pdm->GetMacMenuHandle(), hierMenu);
//  PopupPrivateDataHandle	dataH =
////		(PopupPrivateDataHandle) (**((LStdPopupMenu*)mPane)->GetMacControl()).contrlData;
//  (**dataH).mHandle = pdm->GetMacMenuHandle();
//  (**dataH).mID = pdm->GetMacMenuID();
  
  ((PIPPOptMenu*)mPane)->SetMenu(pdm);
  ((LStdPopupMenu*)mPane)->AddListener(this);
  
  Manage();
}

/* --Methode-- */
PIOptMenuMac::~PIOptMenuMac()
{
}

/* --Methode-- */
void PIOptMenuMac::Process(PIMessage msg, PIMsgHandler* sender, void* data)
{
Select((char *)data, UserMsg(msg));  //  Reza 17/10/96 $CHECK$ ???
ReSend(msg, sender, data);
}

void
PIOptMenuMac::ListenToMessage(MessageT /*inMessage*/, void *)
{
//  if (inMessage == msg_Click)
    mPUMenu->ItemSelected(((LStdPopupMenu*)mPane)->GetValue()-1);
}

void
PIOptMenuMac::Select(char *txt, PIMessage msg)
{ // Ca doit faire quoi ????
mStext = txt;  mSmsg = msg;
}

/* --Methode-- */
void PIOptMenuMac::SetValueStr(string & s)
{
int n;
n=mPUMenu->FindItemByName((char *)s.c_str());
if (n < 0)  return;  

((LStdPopupMenu*)mPane)->SetValue(n+1);
mStext = s;
mSmsg  = mPUMenu->GetMenuItemMsg(n);

return;
}

/* --Methode-- */
void PIOptMenuMac::SetValue(PIMessage msg)
{
int n;
n=mPUMenu->FindItemByMsg(msg);
if (n < 0)  return;
  
StopListening();
((LStdPopupMenu*)mPane)->SetValue(n+1);
StartListening();
mStext = mPUMenu->GetMenuItemText(n);
mSmsg  = msg;

return;
}

