#include "TMDisplayingShowDet.h"
#include "TMHistogrammingShowDet.h"
#include "TMControlSPD.h"
#include "SPDMood.h"
#include <TGButton.h>
#include <TCanvas.h>

ClassImp(TMDisplayingShowDet)

//_____________________________________________________________________
TMDisplayingShowDet::TMDisplayingShowDet(const Char_t *frameName, const TGWindow *p, UInt_t width, UInt_t height, TMHistogramming *hist, UInt_t id, UInt_t plotNr, UInt_t cloneId) :
  TMDisplaying(frameName,p,width,height,hist,id,plotNr,cloneId,kTRUE), 
  fShow(kFALSE)
{
  gClient->GetColorByName("green", green);
  gClient->GetColorByName("gray", gray);

  CreateTopFrame();
  CreateShowHideFrame();
  CreateBottomFrame();

  MapSubwindows();
  Resize();
  MapWindow();

  TCanvas *canv = fTheCanvas->GetCanvas();
  fHist->Draw(canv);
  Update();
}
//_____________________________________________________________________
TMDisplayingShowDet::~TMDisplayingShowDet() {}
//_____________________________________________________________________
void TMDisplayingShowDet::CreateShowHideFrame() {
  TGCompositeFrame *tf = new TGCompositeFrame(this, 50, 21, kHorizontalFrame | kFixedSize);
  AddFrame(tf, new TGLayoutHints(kLHintsExpandX, 0,0,0,0));
  fShowHideButton = new TGTextButton(tf,"SHOW DETECTOR",SHOWHIDE);
  fShowHideButton->Associate(this);
  tf->AddFrame(fShowHideButton, new TGLayoutHints(kLHintsNormal, 0,0,0,0));
}
//______________________________________________________________________
Bool_t TMDisplayingShowDet::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2) {
  //  printf("%d,%ld,%ld\n",GET_MSG(msg),parm1,parm2);
  switch(GET_MSG(msg)) {
  case kC_COMMAND :
    switch (GET_SUBMSG(msg)) {

    case kCM_BUTTON :
      if (parm1==SHOWHIDE) {
	TMControlSPD::Instance()->HoldRunning();
	if (fShow==kTRUE) {
	  TCanvas *canv = fTheCanvas->GetCanvas();
	  ((TMHistogrammingShowDet*)fHist)->HideDetector(canv);
	  fShowHideButton->SetText("SHOW DETECTOR");
	  fShow=kFALSE;
	}
	else {
	  TCanvas *canv = fTheCanvas->GetCanvas();
	  ((TMHistogrammingShowDet*)fHist)->DrawDetector(canv);
	  fShowHideButton->SetText("HIDE DETECTOR");
	  fShow=kTRUE;
	}
	Update();
	TMControlSPD::Instance()->ContinueRunning();
	return kTRUE;
      }
    }
  }
  return TMDisplaying::ProcessMessage(msg,parm1,parm2);
}
