#ifndef TMMAINFRAME_H
#define TMMAINFRAME_H

#include "SPDMood.h"
#include "TMToolBar.h"
#include "TMSetupDisplays.h"
#include "TMMenuBar.h"
#include <TGFrame.h>
#include <TGTab.h>
#include <TGStatusBar.h>

const UInt_t gNrTopButtons = 10;

class TMMainFrame : public TGMainFrame {

  public :

  virtual ~TMMainFrame();
  static TMMainFrame* Instance();
  virtual void   CreateFrame();
  virtual void   CloseWindow();
  virtual Bool_t RemoveAllViews();

  virtual void   LoadConfigAs();
  virtual void   SaveConfigAs();
  virtual void   DumpConfig();

  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
  virtual void   ChangeWindowName(const Char_t* newName);

  virtual Bool_t IsAutoUpdate();
  virtual Bool_t IsAutoReset();
  virtual Bool_t IsSkipPixel();
  virtual Bool_t IsSkipCluster();
  virtual Bool_t IsSkipEventCountCheck();
  virtual Bool_t IsShowErrorEvents();
  virtual Bool_t IsStopOnError();

  virtual void   LoginSuccess();
  virtual void   LogoutSuccess();

  virtual void   ProcessLogin1();
  virtual void   ProcessLogin2();
  virtual void   ProcessLoginInterrupt();
  virtual void   ProcessLogout1();
  virtual void   ProcessLogout2();
  virtual void   ProcessStartDumpC();
  virtual void   ProcessStartDump2();
  virtual void   ProcessStartDump22();
  virtual void   ProcessStartDumpN();
  virtual void   ProcessStartDumpN2();
  virtual void   ProcessStartDump1();
  virtual void   ProcessClose();
  virtual void   ProcessCloneDisplay(UInt_t d_id, UInt_t plotNr, TMHistogramming *hist);
  virtual void   ProcessAutoResetDisplay(UInt_t d_id, UInt_t plotNr, Bool_t autoreset);
  virtual void   ProcessPauseDisplay(UInt_t d_id, UInt_t plotNr, Bool_t pause);
  virtual void   ProcessKillDisplay(UInt_t d_id, UInt_t plotNr);
  virtual void   ProcessCloseDisplay(UInt_t d_id, UInt_t plotNr);
  virtual void   ProcessCloseDisplay(UInt_t d_id, UInt_t plotNr, UInt_t cloneId);
  virtual void   ProcessCloseAllDisplays();
  virtual void   ProcessOpenDisplay(UInt_t d_id);
  virtual void   ProcessOpenDisplay(UInt_t d_id, UInt_t plotNr, UInt_t cloneId, TMHistogramming *hist);
  virtual void   ProcessResetDisplays();
  virtual void   ProcessUpdateDisplays();
  virtual void   ProcessResetErrorFlag();
  virtual void   ProcessUpdateSupprError();
  virtual void   ProcessDeadNoisy();

  //!!!  virtual Bool_t ProcessGridSourceEnv();
  virtual void   ProcessGridConnect();

  virtual UInt_t GetNewCloneId();

  virtual void   FinishRunning();

  virtual void   FreezeTopButtons();
  virtual void   DeFreezeTopButtons();

  virtual void   UpdateStatusBar(const Char_t *msg, UInt_t view);
  virtual void   UpdateStatusBarBG(const Char_t *msg, UInt_t col, UInt_t view);
  virtual void   UpdateStatusMask(const Char_t *msg, UInt_t view);


  protected :

  TMMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
  static Bool_t instanceFlag;
  static TMMainFrame *single;

  void   EnableTopButtons();
  void   DisableTopButtons();
  //!!!  void   DisableTopButtonsSpecial();
  void   RestoreTopButtons();
  void   TopButtonsSnap();
  void   RestoreTopButtonsSnap();

  TMMenuBar             *fMenuBar;
  TMToolBar		*fToolBar;
  TMSetupDisplays       *fSetupDisplays;
  TGCompositeFrame	*fTopButtons1, *fTopButtons2;
  TGTextButton		*fB[gNrTopButtons];
  TGTab			*fMainTab;
  TGTab			*fHitDisplayTab;
  TGCompositeFrame      *fMenu;
  TGCompositeFrame      *fClose;
  TGPicturePool		*fPicturePool;
  TGPicture             *fPictureClose, *fp_PictureClose, *fd_PictureClose;
  TGButton 		*fButtonClose;  
  TGLayoutHints		*fL[11];
  TGStatusBar           *fStatusMask;
  TGStatusBar		*fStatusBar;
  TGTextButton          *fTestButton, *fTestButton2;

  TString               fWindowNamePartOne;
  UInt_t                fHeight;
  UInt_t                fWidth;
  Pixel_t               yellow, brown, green, red, gray;
  UInt_t                fTopState[gNrTopButtons];
  Bool_t                fLoggedIn;

  ClassDef(TMMainFrame, 0)
};

#endif
