#include "TMDisplayingShowClusterTypes.h"
#include "TMControlSPD.h"
#include "SPDMood.h"
#include <TGButton.h>
#include <TGTextView.h>
#include <TCanvas.h>

ClassImp(TMDisplayingShowClusterTypes)

//_____________________________________________________________________
TMDisplayingShowClusterTypes::TMDisplayingShowClusterTypes(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)
{
  gClient->GetColorByName("green", green);
  gClient->GetColorByName("gray", gray);

  CreateTopFrame();
  CreateShowFrame();
  CreateBottomFrame();

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

  TCanvas *canv = fTheCanvas->GetCanvas();
  fHist->Draw(canv);
  Update();
}
//_____________________________________________________________________
TMDisplayingShowClusterTypes::~TMDisplayingShowClusterTypes() {}
//_____________________________________________________________________
void TMDisplayingShowClusterTypes::CreateShowFrame() {
  TGCompositeFrame *tf = new TGCompositeFrame(this, 50, 21, kHorizontalFrame | kFixedSize);
  AddFrame(tf, new TGLayoutHints(kLHintsExpandX, 0,0,0,0));
  fShowButton = new TGTextButton(tf,"SHOW CLUSTER TYPES",SHOW);
  fShowButton->Associate(this);
  tf->AddFrame(fShowButton, new TGLayoutHints(kLHintsNormal, 0,0,0,0));
}
//______________________________________________________________________
Bool_t TMDisplayingShowClusterTypes::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==SHOW) {
	TMControlSPD::Instance()->HoldRunning();

	ProcessOpenClusterTypeFrame();

	TMControlSPD::Instance()->ContinueRunning();
	return kTRUE;
      }
    }
  }
  return TMDisplaying::ProcessMessage(msg,parm1,parm2);
}
//_____________________________________________________________________
void TMDisplayingShowClusterTypes::ProcessOpenClusterTypeFrame() {
  TGMainFrame *mF = new TGMainFrame(gClient->GetRoot(),220,500);
  mF->SetWindowName("Cluster Types");

  TGTextView *tv =  new TGTextView(mF, 220, 500, kHorizontalFrame | kFixedSize);
  
  mF->AddFrame(tv, new TGLayoutHints(kLHintsExpandX  | kLHintsExpandY,0,0,0,0));
  

  tv->AddLine("    0.       1.       2.   ");
  tv->AddLine("    Other    X        X    ");
  tv->AddLine("                      X    ");
  tv->AddLine("                           ");
  tv->AddLine("                           ");
  tv->AddLine("                           ");
	           	    	    	    
  tv->AddLine("    3.       4.       5.   ");
  tv->AddLine("    XX       X        XX   ");
  tv->AddLine("             X        X    ");
  tv->AddLine("             X             ");
  tv->AddLine("                           ");
  tv->AddLine("                           ");
	           	    	    	    
  tv->AddLine("    6.       7.       8.   ");
  tv->AddLine("    XXX      X        XX   ");
  tv->AddLine("             X        XX   ");
  tv->AddLine("             X             ");
  tv->AddLine("             X             ");
  tv->AddLine("                           ");
	           	    		    
  tv->AddLine("    9.      10.      11.   ");
  tv->AddLine("    XX       X        XXX  ");
  tv->AddLine("    X        XX       X    ");
  tv->AddLine("    X        X             ");
  tv->AddLine("                           ");
  tv->AddLine("                           ");
	          	    		 
  tv->AddLine("   12.      13.      14.   ");
  tv->AddLine("    XXX      X        X    ");
  tv->AddLine("     X        X       X    ");
  tv->AddLine("                       X   ");
  tv->AddLine("                           ");

  tv->AddLine("   15.                     ");
  tv->AddLine("    XX                     ");
  tv->AddLine("      X                    ");
  tv->AddLine("                           ");
  tv->AddLine("                           ");

  tv->Update();

  mF->MapSubwindows();
  mF->Resize();
  mF->MapWindow();
}

