#include "TMMsgBox.h"

ClassImp(TMMsgBox);


TMMsgBox::TMMsgBox(const TGWindow *p, const TGWindow *main, TGText *text)
  :TGTransientFrame(gClient->GetRoot(), main, 500, 400, kVerticalFrame) {
  // Constructor.

  fL = new TGLayoutHints( kLHintsLeft | kLHintsCenterY | kLHintsCenterX, 0, 0, 0, 0);
  
  Long_t nrRows = text->RowCount();
  Long_t longestLen = text->GetLineLength(text->GetLongestLine());

  fTextView = new TGTextView(this, longestLen*8+8, nrRows*25+25);
  AddFrame(fTextView, fL);
  fTextView->AddText(text);

  TString picture = Form("%s/src/images/button7long.xpm", getenv("SPDMOOD_SITE"));
  fPictureButton = new TGPictureButton(this, picture.Data(), BUTTON_CLOSE);
  fPictureButton->SetToolTipText("Close.", 0);
  fPictureButton->Associate(this);
  AddFrame(fPictureButton, fL);

  fLetUserCloseWindow = kFALSE;
    
  MapSubwindows();
  Resize();
  MapWindow();
    
  //  SetWMSizeHints(750, 540, 750, 540, 0, 0);
}

TMMsgBox::~TMMsgBox()
{
  // Destructor.
    
  delete   fTextView;
  delete   fPictureButton;
  delete   fL;
}

void TMMsgBox::CloseWindow()
{
  // Prevents window manager close window function.

  if (fLetUserCloseWindow == kFALSE)
    DontCallClose();
  else
    UnmapWindow();
}

Bool_t TMMsgBox::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
{
  // Event handler.

  switch(GET_MSG(msg)) {
  case kC_COMMAND :
    switch (GET_SUBMSG(msg)) {
    case kCM_BUTTON :
      switch (parm1) {
      case BUTTON_CLOSE :
	{
	  fLetUserCloseWindow = kTRUE;
	  CloseWindow();
	  break;
	}
      }
    }
  }
  return kTRUE;    
}
