#include "TGDoubleSlider.h"
#include "TGTripleSlider.h"
#include "TGPicture.h"
#include "Riostream.h"
#include "TSystem.h"
#include <stdlib.h>
ClassImp(TGTripleVSlider)
ClassImp(TGTripleHSlider)
TGTripleVSlider::TGTripleVSlider(const TGWindow *p, UInt_t h, UInt_t type, Int_t id,
                                 UInt_t options, ULong_t back,
                                 Bool_t reversed, Bool_t mark_ends,
                                 Bool_t constrained, Bool_t relative)
    : TGDoubleVSlider(p, h, type, id, options, back, reversed, mark_ends)
{
   
   fPointerPic = fClient->GetPicture("slider1h.xpm");
   if (!fPointerPic)
      Error("TGTripleVSlider", "slider1h.xpm not found");
   fConstrained = constrained;
   fRelative = relative;
   fCz = 0;
   fSCz = 0;
   AddInput(kStructureNotifyMask);
   SetWindowName();
}
TGTripleVSlider::~TGTripleVSlider()
{
   
   if (fPointerPic) fClient->FreePicture(fPointerPic);
}
void TGTripleVSlider::DoRedraw()
{
   
   TGDoubleVSlider::DoRedraw();
   
   DrawPointer();
}
void TGTripleVSlider::DrawPointer()
{
   
   if (fPointerPic) fPointerPic->Draw(fId, GetBckgndGC()(), fWidth/2-7, fCz-5);
}
Bool_t TGTripleVSlider::HandleButton(Event_t *event)
{
   
   if (event->fType == kButtonPress && event->fCode == kButton1) {
      
      if (event->fX < (Int_t)fWidth/2-7 || event->fX > (Int_t)fWidth/2+7) {
         return kTRUE;
      }
      fPressPoint = event->fY;
      fPressSmin  = fSmin;
      fPressSmax  = fSmax;
      int relMin = (int)((fHeight-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
      int relMax = (int)((fHeight-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
      if (fPressPoint > (fCz - 5) && fPressPoint < (fCz + 5) &&
          event->fX > ((Int_t)fWidth / 2) - 7 && event->fX < ((Int_t)fWidth / 2) + 5)
         
         fMove = 4;
      else if (fPressPoint < (relMax - relMin) / 4 + relMin)
         
         fMove = 1;
      else if (fPressPoint > (relMax - relMin) / 4 * 3 + relMin)
         
         fMove = 2;
      else
         
         fMove = 3;
      SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_PRESS), fWidgetId, 0);
      fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_PRESS), fWidgetId, 0);
      Pressed();
      
      gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
                             kPointerMotionMask, kNone, kNone,
                             kTRUE, kFALSE);
   } else if (event->fType == kButtonRelease && event->fCode == kButton1) {
      SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
      fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
      Released();
      fMove = 0;
      gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);  
   } else
      fMove = 0;
   return kTRUE;
}
Bool_t TGTripleVSlider::HandleConfigureNotify(Event_t* event)
{
   
   TGFrame::HandleConfigureNotify(event);
   SetPointerPosition(fSCz);
   return kTRUE;
}
Bool_t TGTripleVSlider::HandleMotion(Event_t *event)
{
   
   if (fMove < 3) {
      
      
      
      if (event->fY > (fCz - 5) && event->fY < (fCz + 5) &&
          event->fX > ((Int_t)fWidth / 2) - 7 &&
          event->fX < ((Int_t)fWidth / 2) + 5 &&
          fMove == 0)
         gVirtualX->SetCursor(fId, kNone);
      else
         ChangeCursor(event);
   }
   static int oldDiff = 0;
   static Long_t was = gSystem->Now();
   Long_t now = (long)gSystem->Now();
   if (fMove == 0)  return kTRUE;
   if ((now-was) < 50) return kTRUE;
   was = now;
   int     diff;
   Float_t oldMin, oldMax;
   diff    = event->fY - fPressPoint;
   oldMin  = fSmin;
   oldMax  = fSmax;
   if (fMove == 1) {
      
      oldDiff = 0;
      fSmin = fPressSmin + diff * (fVmax - fVmin) / (fHeight-16);
      if (fSmin < fVmin) fSmin = fVmin;
      if (fSmin > fSmax) fSmin = fSmax;
   } else if (fMove == 2) {
      
      oldDiff = 0;
      fSmax = fPressSmax + diff * (fVmax - fVmin) / (fHeight-16);
      if (fSmax > fVmax) fSmax = fVmax;
      if (fSmax < fSmin) fSmax = fSmin;
   } else if (fMove == 3) {
      
      Float_t logicalDiff;
      logicalDiff = diff * (fVmax - fVmin) / (fHeight-16);
      if (fPressSmax + logicalDiff > fVmax)
         logicalDiff = fVmax - fPressSmax;
      if (fPressSmin + logicalDiff < fVmin)
         logicalDiff = fVmin - fPressSmin;
      fSmax = fPressSmax + logicalDiff;
      fSmin = fPressSmin + logicalDiff;
      if (fRelative) {
         if (abs(diff) < 3) oldDiff = diff;
         SetPointerPos(diff - oldDiff, 3);
         oldDiff = diff;
      }
   }
   else if (fMove == 4) {
      
      oldDiff = 0;
      SetPointerPos(event->fY, 1);
   }
   if (fMove != 4){
      SetPointerPos(0, 2);
   }
   
   if (fMove != 0 && (fSmax != oldMax || fSmin != oldMin)) {
      fClient->NeedRedraw(this);
      SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_POS), fWidgetId, 0);
      fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_POS), fWidgetId, 0);
      PositionChanged();
   }
   return kTRUE;
}
void TGTripleVSlider::SetConstrained(Bool_t on) 
{
   
   fConstrained = on;
   if (fConstrained) {
      if (GetPointerPosition() <= GetMinPosition()) 
         SetPointerPos((Int_t)GetMinPosition(), 3);
      else if (GetPointerPosition() >= GetMaxPosition()) 
         SetPointerPos((Int_t)GetMaxPosition(), 3);
   }
}
void TGTripleVSlider::SetPointerPos(Int_t z, Int_t opt)
{
   
   
   static Long_t was = gSystem->Now();
   Bool_t lcheck = (opt == 1);
   Int_t oldPos = fCz;
   if (opt < 2) {
      fCz = z;
      if (fCz < 7)
         fCz = 7;
      else if (fCz >= (Int_t)fHeight - 7)
         fCz = (Int_t)fHeight - 7;
   }
   if (opt == 3) {
      lcheck = kTRUE;
      fCz += z;
      if (fCz < 7)
         fCz = 7;
      else if (fCz >= (Int_t)fHeight-7)
         fCz = (Int_t)fHeight - 7;
   }
   if (fConstrained) {
      int relMin = (int)((fHeight-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
      int relMax = (int)((fHeight-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
      if(fCz < relMin+7) {
         fCz = relMin+7;
         lcheck = kTRUE;
      }
      if(fCz > relMax-7) {
         fCz = relMax-7;
         lcheck = kTRUE;
      }
   }
   if (lcheck)
      fSCz = fVmin + ((Float_t)(fCz-8) * (fVmax - fVmin) / (Float_t)(fHeight-16));
   if(fSCz < fVmin) fSCz = fVmin;
   if(fSCz > fVmax) fSCz = fVmax;
   if (fConstrained) {
      if(fSCz < fSmin) fSCz = fSmin;
      if(fSCz > fSmax) fSCz = fSmax;
   }
   DrawPointer();
   fClient->NeedRedraw(this);
   if (fCz != oldPos) {
      Long_t now = (long)gSystem->Now();
      if ((fMove != 4) && ((now-was) < 150)) return;
      was = now;
      SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_POINTER), fWidgetId, 0);
      fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_POINTER), fWidgetId, 0);
      PointerPositionChanged();
      fClient->NeedRedraw(this);
   }
}
void TGTripleVSlider::SetPointerPosition(Float_t pos)
{
   
   if (fReversedScale) {
      fSCz = fVmin + fVmax - pos;
   }
   else {
      fSCz = pos;
   }
   Float_t absPos = (fSCz - fVmin) * (fHeight-16) / (fVmax - fVmin);
   SetPointerPos((int)(absPos+5.0), 0);
}
TGTripleHSlider::TGTripleHSlider(const TGWindow *p, UInt_t w, UInt_t type, Int_t id,
                                 UInt_t options, ULong_t back,
                                 Bool_t reversed, Bool_t mark_ends,
                                 Bool_t constrained, Bool_t relative)
    : TGDoubleHSlider(p, w, type, id, options, back, reversed, mark_ends)
{
   
   fPointerPic = fClient->GetPicture("slider1v.xpm");
   if (!fPointerPic)
      Error("TGTripleVSlider", "slider1v.xpm not found");
   fConstrained = constrained;
   fRelative = relative;
   fCz = 0;
   fSCz = 0;
   AddInput(kStructureNotifyMask);
   SetWindowName();
}
TGTripleHSlider::~TGTripleHSlider()
{
   
   if (fPointerPic) fClient->FreePicture(fPointerPic);
}
void TGTripleHSlider::DoRedraw()
{
   
   TGDoubleHSlider::DoRedraw();
   
   DrawPointer();
}
void TGTripleHSlider::DrawPointer()
{
   
   if (fPointerPic) fPointerPic->Draw(fId, GetBckgndGC()(), fCz-5, fHeight/2-7);
}
Bool_t TGTripleHSlider::HandleButton(Event_t *event)
{
   
   if (event->fType == kButtonPress && event->fCode == kButton1) {
      
      if (event->fY < (Int_t)fHeight/2-7 || event->fY > (Int_t)fHeight/2+7) {
         return kTRUE;
      }
      fPressPoint = event->fX;
      fPressSmin  = fSmin;
      fPressSmax  = fSmax;
      int relMin = (int)((fWidth-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
      int relMax = (int)((fWidth-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
      if (fPressPoint > (fCz - 5) && fPressPoint < (fCz + 5) &&
          event->fY > ((Int_t)fHeight / 2) - 7 && event->fY < ((Int_t)fHeight / 2) + 5)
         
         fMove = 4;
      else if (fPressPoint < (relMax - relMin) / 4 + relMin)
         
         fMove = 1;
      else if (fPressPoint > (relMax - relMin) / 4 * 3 + relMin)
         
         fMove = 2;
      else
         
         fMove = 3;
      SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_PRESS), fWidgetId, 0);
      fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_PRESS), fWidgetId, 0);
      Pressed();
      
      gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
                             kPointerMotionMask, kNone, kNone,
                             kTRUE, kFALSE);
   } else if (event->fType == kButtonRelease && event->fCode == kButton1) {
      SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
      fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
      Released();
      fMove = 0;
      gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);  
   } else
      fMove = 0;
   return kTRUE;
}
Bool_t TGTripleHSlider::HandleConfigureNotify(Event_t* event)
{
   
   TGFrame::HandleConfigureNotify(event);
   SetPointerPosition(fSCz);
   return kTRUE;
}
Bool_t TGTripleHSlider::HandleMotion(Event_t *event)
{
   
   if (fMove < 3) {
      
      
      
      if (event->fX > (fCz - 5) && event->fX < (fCz + 5) &&
          event->fY > ((Int_t)fHeight / 2) - 7 && 
          event->fY < ((Int_t)fHeight / 2) + 5 &&
          fMove == 0)
         gVirtualX->SetCursor(fId, kNone);
      else
         ChangeCursor(event);
   }
   static int oldDiff = 0;
   static Long_t was = gSystem->Now();
   Long_t now = (long)gSystem->Now();
   if (fMove == 0)  return kTRUE;
   if ((now-was) < 50) return kTRUE;
   was = now;
   int     diff;
   Float_t oldMin, oldMax;
   diff    = event->fX - fPressPoint;
   oldMin  = fSmin;
   oldMax  = fSmax;
   if (fMove == 1) {
      
      oldDiff = 0;
      fSmin = fPressSmin + diff * (fVmax - fVmin) / (fWidth-16);
      if (fSmin < fVmin) fSmin = fVmin;
      if (fSmin > fSmax) fSmin = fSmax;
   } else if (fMove == 2) {
      
      oldDiff = 0;
      fSmax = fPressSmax + diff * (fVmax - fVmin) / (fWidth-16);
      if (fSmax > fVmax) fSmax = fVmax;
      if (fSmax < fSmin) fSmax = fSmin;
   } else if (fMove == 3) {
      
      Float_t logicalDiff;
      logicalDiff = diff * (fVmax - fVmin) / (fWidth-16);
      if (fPressSmax + logicalDiff > fVmax)
         logicalDiff = fVmax - fPressSmax;
      if (fPressSmin + logicalDiff < fVmin)
         logicalDiff = fVmin - fPressSmin;
      fSmax = fPressSmax + logicalDiff;
      fSmin = fPressSmin + logicalDiff;
      if (fRelative) {
         if (abs(diff) < 3) oldDiff = diff;
         SetPointerPos(diff - oldDiff, 3);
         oldDiff = diff;
      }
   }
   else if (fMove == 4) {
      
      oldDiff = 0;
      SetPointerPos(event->fX, 1);
   }
   if (fMove != 4) {
      SetPointerPos(0, 2);
   }
   
   if (fMove != 0 && (fSmax != oldMax || fSmin != oldMin)) {
      fClient->NeedRedraw(this);
      SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POS), fWidgetId, 0);
      fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS), fWidgetId, 0);
      PositionChanged();
   }
   return kTRUE;
}
void TGTripleHSlider::SetConstrained(Bool_t on) 
{
   
   fConstrained = on;
   if (fConstrained) {
      if (GetPointerPosition() <= GetMinPosition()) 
         SetPointerPos((Int_t)GetMinPosition(), 3);
      else if (GetPointerPosition() >= GetMaxPosition()) 
         SetPointerPos((Int_t)GetMaxPosition(), 3);
   }
}
void TGTripleHSlider::SetPointerPos(Int_t z, Int_t opt)
{
   
   static Long_t was = gSystem->Now();
   Bool_t lcheck = (opt == 1);
   Int_t oldPos = fCz;
   if (opt < 2) {
      fCz = z;
      if (fCz < 7)
         fCz = 7;
      else if (fCz >= (Int_t)fWidth-7)
         fCz = (Int_t)fWidth-7;
   }
   if (opt == 3) {
      lcheck = kTRUE;
      fCz += z;
      if (fCz < 7)
         fCz = 7;
      else if (fCz >= (Int_t)fWidth-7)
         fCz = (Int_t)fWidth-7;
   }
   if (fConstrained) {
      int relMin = (int)((fWidth-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
      int relMax = (int)((fWidth-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
      if(fCz < relMin+7) {
         fCz = relMin+7;
         lcheck = kTRUE;
      }
      if(fCz > relMax-7) {
         fCz = relMax-7;
         lcheck = kTRUE;
      }
   }
   if (lcheck)
      fSCz = fVmin + ((Float_t)(fCz-8) * (fVmax - fVmin) / (Float_t)(fWidth-16));
   if(fSCz < fVmin) fSCz = fVmin;
   if(fSCz > fVmax) fSCz = fVmax;
   if (fConstrained) {
      if(fSCz < fSmin) fSCz = fSmin;
      if(fSCz > fSmax) fSCz = fSmax;
   }
   DrawPointer();
   fClient->NeedRedraw(this);
   if (fCz != oldPos) {
      Long_t now = (long)gSystem->Now();
      if ((fMove != 4) && ((now-was) < 150)) return;
      was = now;
      SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POINTER), fWidgetId, 0);
      fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POINTER), fWidgetId, 0);
      PointerPositionChanged();
      fClient->NeedRedraw(this);
   }
}
void TGTripleHSlider::SetPointerPosition(Float_t pos) 
{
   
   if (fReversedScale) {
      fSCz = fVmin + fVmax - pos;
   }
   else {
      fSCz = pos;
   }
   Float_t absPos = (fSCz - fVmin) * (fWidth-16) / (fVmax - fVmin);
   SetPointerPos((int)(absPos+5.0), 0);
}
void TGTripleHSlider::SavePrimitive(ostream &out, Option_t *option )
{
    
   SaveUserColor(out, option);
   out <<"   TGTripleHSlider *";
   out << GetName() << " = new TGTripleHSlider(" << fParent->GetName()
       << "," << GetWidth() << ",";
   out << GetSString() << "," << WidgetId() << ",";
   out << GetOptionString() << ",ucolor";
   if (fMarkEnds) {
      switch (fReversedScale) {
         case kTRUE:
            out << ",kTRUE,kTRUE";
            break;
         case kFALSE:
            out << ",kFALSE,kTRUE";
            break;
      }
   } else if (fReversedScale) {
      out << ",kTRUE,kFALSE";
   } else {
      out << ",kFALSE,kFALSE";
   }
   if (!fConstrained) {
      switch (fRelative) {
         case kTRUE:
            out << ",kFALSE,kTRUE);" << endl;
            break;
         case kFALSE:
            out << ",kFALSE,kFALSE);" << endl;
            break;
      }
   }
   else if (fRelative) {
      out << ",kTRUE);" << endl;
   }
   else {
      out << ");" << endl;
   }
   if (fVmin != 0 || fVmax != (Int_t)fWidth)
      out << "   " << GetName() << "->SetRange(" << fVmin << "," << fVmax
          << ");" << endl;
   if (fSmin != fWidth/8*3 || fSmax != fWidth/8*5)
      out << "   " << GetName() << "->SetPosition(" << GetMinPosition()
          << "," << GetMaxPosition() << ");" << endl;
   if (fScale != 10)
      out << "   " << GetName() << "->SetScale(" << fScale << ");" << endl;
   out << "   " << GetName() << "->SetPointerPosition(" << fSCz << ");" << endl;
}
void TGTripleVSlider::SavePrimitive(ostream &out, Option_t *option )
{
    
   
   SaveUserColor(out, option);
   out<<"   TGTripleVSlider *";
   out << GetName() << " = new TGTripleVSlider("<< fParent->GetName()
       << "," << GetHeight() << ",";
   out << GetSString() << "," << WidgetId() << ",";
   out << GetOptionString() << ",ucolor";
   if (fMarkEnds) {
      switch (fReversedScale) {
         case kTRUE:
            out << ",kTRUE,kTRUE";
            break;
         case kFALSE:
            out << ",kFALSE,kTRUE";
            break;
      }
   } else if (fReversedScale) {
      out << ",kTRUE,kFALSE";
   } else {
      out << ",kFALSE,kFALSE";
   }
   if (!fConstrained) {
      switch (fRelative) {
         case kTRUE:
            out << ",kFALSE,kTRUE);" << endl;
            break;
         case kFALSE:
            out << ",kFALSE,kFALSE);" << endl;
            break;
      }
   }
   else if (fRelative) {
      out << ",kTRUE);" << endl;
   }
   else {
      out << ");" << endl;
   }
   if (fVmin != 0 || fVmax != (Int_t)fHeight)
      out << "   " << GetName() <<"->SetRange(" << fVmin << "," << fVmax
          << ");" << endl;
   if (fSmin != fHeight/8*3 || fSmax != fHeight/8*5)
      out << "   " << GetName() << "->SetPosition(" << GetMinPosition()
          << "," << GetMaxPosition() << ");" << endl;
   if (fScale != 10)
      out << "   " << GetName() << "->SetScale(" << fScale << ");" << endl;
   out << "   " << GetName() << "->SetPointerPosition(" << fSCz << ");" << endl;
}
Last change: Tue Nov 25 12:04:14 2008
Last generated: 2008-11-25 12:04
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.