#include "TMDisplayingCheckButton.h"
#include "TMHistogrammingCheckButton.h"
#include "TMControlSPD.h"
#include "SPDMood.h"
#include <TGButton.h>
#include <TCanvas.h>

ClassImp(TMDisplayingCheckButton)

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

  CreateTopFrame();
  CreateButtonFrame();
  CreateBottomFrame();

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

  TCanvas *canv = fTheCanvas->GetCanvas();
  fHist->Draw(canv);
  Update();
}
//_____________________________________________________________________
TMDisplayingCheckButton::~TMDisplayingCheckButton() {}
//_____________________________________________________________________
void TMDisplayingCheckButton::CreateButtonFrame() {
  TGCompositeFrame *tf = new TGCompositeFrame(this, 50, 21, kHorizontalFrame | kFixedSize);
  AddFrame(tf, new TGLayoutHints(kLHintsExpandX, 0,0,0,0));
  fCheckButton = new TGCheckButton(tf,fCheckLabel.Data(),ADD_ID_START);
  fCheckButton->Associate(this);
  tf->AddFrame(fCheckButton, new TGLayoutHints(kLHintsNormal, 0,0,0,0));
}
//______________________________________________________________________
Bool_t TMDisplayingCheckButton::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_CHECKBUTTON :
      if (parm1==ADD_ID_START) {
	ToggleCheckButton();
	return kTRUE;
      }
      break;

    }
  }
  return TMDisplaying::ProcessMessage(msg,parm1,parm2);
}
//_____________________________________________________________________
void TMDisplayingCheckButton::ToggleCheckButton() {
  if (fCheckButton->IsDown()) {
    fCheckButton->SetDown(kTRUE);
    ((TMHistogrammingCheckButton*) fHist) -> CheckButtonDown();
  }
  else {
    fCheckButton->SetDown(kFALSE);
    ((TMHistogrammingCheckButton*) fHist) -> CheckButtonUp();
  }
}
