TGTripleSlider.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGTripleSlider.cxx 35582 2010-09-22 13:38:27Z bellenot $
00002 // Author: Bertrand Bellenot   20/01/06
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 /**************************************************************************
00012 
00013     This source is based on Xclass95, a Win95-looking GUI toolkit.
00014     Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
00015 
00016     Xclass95 is free software; you can redistribute it and/or
00017     modify it under the terms of the GNU Library General Public
00018     License as published by the Free Software Foundation; either
00019     version 2 of the License, or (at your option) any later version.
00020 
00021 **************************************************************************/
00022 
00023 //////////////////////////////////////////////////////////////////////////
00024 //                                                                      //
00025 // TGTripleVSlider and TGTripleHSlider                                  //
00026 //                                                                      //
00027 // TripleSlider inherit from DoubleSlider widgets and allow easy        //
00028 // selection of a min, max and pointer value out of a range.            //
00029 // The pointer position can be constrained to edges of slider and / or  //
00030 // can be relative to the slider position.                              //
00031 //                                                                      //
00032 // To change the min value press the mouse near to the left / bottom    //
00033 // edge of the slider.                                                  //
00034 // To change the max value press the mouse near to the right / top      //
00035 // edge of the slider.                                                  //
00036 // To change both values simultaneously press the mouse near to the     //
00037 // center of the slider.                                                //
00038 // To change pointer value press the mouse on the pointer and drag it   //
00039 // to the desired position                                              //
00040 //                                                                      //
00041 // Dragging the slider will generate the event:                         //
00042 // kC_VSLIDER, kSL_POS, slider id, 0  (for vertical slider)             //
00043 // kC_HSLIDER, kSL_POS, slider id, 0  (for horizontal slider)           //
00044 //                                                                      //
00045 // Pressing the mouse will generate the event:                          //
00046 // kC_VSLIDER, kSL_PRESS, slider id, 0  (for vertical slider)           //
00047 // kC_HSLIDER, kSL_PRESS, slider id, 0  (for horizontal slider)         //
00048 //                                                                      //
00049 // Releasing the mouse will generate the event:                         //
00050 // kC_VSLIDER, kSL_RELEASE, slider id, 0  (for vertical slider)         //
00051 // kC_HSLIDER, kSL_RELEASE, slider id, 0  (for horizontal slider)       //
00052 //                                                                      //
00053 // Moving the pointer will generate the event:                          //
00054 // kC_VSLIDER, kSL_POINTER, slider id, 0  (for vertical slider)         //
00055 // kC_HSLIDER, kSL_POINTER, slider id, 0  (for horizontal slider)       //
00056 //                                                                      //
00057 // Use the functions GetMinPosition(), GetMaxPosition() and             //
00058 // GetPosition() to retrieve the position of the slider.                //
00059 // Use the function GetPointerPosition() to retrieve the position of    //
00060 // the pointer                                                          //
00061 //                                                                      //
00062 //////////////////////////////////////////////////////////////////////////
00063 
00064 #include "TGDoubleSlider.h"
00065 #include "TGTripleSlider.h"
00066 #include "TGPicture.h"
00067 #include "Riostream.h"
00068 #include "TSystem.h"
00069 #include <stdlib.h>
00070 
00071 ClassImp(TGTripleVSlider)
00072 ClassImp(TGTripleHSlider)
00073 
00074 //______________________________________________________________________________
00075 TGTripleVSlider::TGTripleVSlider(const TGWindow *p, UInt_t h, UInt_t type, Int_t id,
00076                                  UInt_t options, ULong_t back,
00077                                  Bool_t reversed, Bool_t mark_ends,
00078                                  Bool_t constrained, Bool_t relative)
00079     : TGDoubleVSlider(p, h, type, id, options, back, reversed, mark_ends)
00080 {
00081    // Create a vertical slider widget.
00082 
00083    fPointerPic = fClient->GetPicture("slider1h.xpm");
00084    if (!fPointerPic)
00085       Error("TGTripleVSlider", "slider1h.xpm not found");
00086    fConstrained = constrained;
00087    fRelative = relative;
00088    fCz = 0;
00089    fSCz = 0;
00090    AddInput(kStructureNotifyMask);
00091    SetWindowName();
00092 }
00093 
00094 //______________________________________________________________________________
00095 TGTripleVSlider::~TGTripleVSlider()
00096 {
00097    // Delete vertical slider widget.
00098 
00099    if (fPointerPic) fClient->FreePicture(fPointerPic);
00100 }
00101 
00102 //______________________________________________________________________________
00103 void TGTripleVSlider::DoRedraw()
00104 {
00105    // Redraw vertical slider widget.
00106 
00107    TGDoubleVSlider::DoRedraw();
00108    // Draw Pointer
00109    DrawPointer();
00110 }
00111 
00112 //________________________________________________________________________________
00113 void TGTripleVSlider::DrawPointer()
00114 {
00115    // Draw slider pointer
00116 
00117    if (fPointerPic) fPointerPic->Draw(fId, GetBckgndGC()(), fWidth/2-7, fCz-5);
00118 }
00119 
00120 //______________________________________________________________________________
00121 Bool_t TGTripleVSlider::HandleButton(Event_t *event)
00122 {
00123    // Handle mouse button event in vertical slider.
00124 
00125    if (event->fType == kButtonPress && event->fCode == kButton1) {
00126       // constrain to the slider width
00127       if (event->fX < (Int_t)fWidth/2-7 || event->fX > (Int_t)fWidth/2+7) {
00128          return kTRUE;
00129       }
00130       fPressPoint = event->fY;
00131       fPressSmin  = fSmin;
00132       fPressSmax  = fSmax;
00133 
00134       int relMin = (int)((fHeight-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
00135       int relMax = (int)((fHeight-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
00136       if (fPressPoint > (fCz - 5) && fPressPoint < (fCz + 5) &&
00137           event->fX > ((Int_t)fWidth / 2) - 7 && event->fX < ((Int_t)fWidth / 2) + 5)
00138          // move pointer
00139          fMove = 4;
00140       else if (fPressPoint < (relMax - relMin) / 4 + relMin)
00141          // move only min value
00142          fMove = 1;
00143       else if (fPressPoint > (relMax - relMin) / 4 * 3 + relMin)
00144          // move only max value
00145          fMove = 2;
00146       else
00147          // move min and max value
00148          fMove = 3;
00149 
00150       SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_PRESS), fWidgetId, 0);
00151       fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_PRESS), fWidgetId, 0);
00152       Pressed();
00153 
00154       // last argument kFALSE forces all specified events to this window
00155       gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
00156                              kPointerMotionMask, kNone, kNone,
00157                              kTRUE, kFALSE);
00158    } else if (event->fType == kButtonRelease && event->fCode == kButton1) {
00159       SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
00160       fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
00161       Released();
00162       fMove = 0;
00163       gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);  // ungrab pointer
00164    } else
00165       fMove = 0;
00166 
00167    return kTRUE;
00168 }
00169 
00170 //______________________________________________________________________________
00171 Bool_t TGTripleVSlider::HandleConfigureNotify(Event_t* event)
00172 {
00173    // Handles resize events for this widget.
00174 
00175    TGFrame::HandleConfigureNotify(event);
00176    SetPointerPosition(fSCz);
00177    return kTRUE;
00178 }
00179 
00180 //______________________________________________________________________________
00181 Bool_t TGTripleVSlider::HandleMotion(Event_t *event)
00182 {
00183    // Handle mouse motion event in vertical slider.
00184 
00185    if (fMove < 3) {
00186       // if the mouse pointer is on the cursor,
00187       // and we are not moving anything,
00188       // set the cursor shape as Pointer
00189       if (event->fY > (fCz - 5) && event->fY < (fCz + 5) &&
00190           event->fX > ((Int_t)fWidth / 2) - 7 &&
00191           event->fX < ((Int_t)fWidth / 2) + 5 &&
00192           fMove == 0)
00193          gVirtualX->SetCursor(fId, kNone);
00194       else
00195          ChangeCursor(event);
00196    }
00197    static int oldDiff = 0;
00198    static Long64_t was = gSystem->Now();
00199    Long64_t now = gSystem->Now();
00200 
00201    if (fMove == 0)  return kTRUE;
00202    if ((now-was) < 50) return kTRUE;
00203    was = now;
00204 
00205    int     diff;
00206    Float_t oldMin, oldMax;
00207 
00208    diff    = event->fY - fPressPoint;
00209    oldMin  = fSmin;
00210    oldMax  = fSmax;
00211 
00212    if (fMove == 1) {
00213       // change of min value
00214       oldDiff = 0;
00215       fSmin = fPressSmin + diff * (fVmax - fVmin) / (fHeight-16);
00216       if (fSmin < fVmin) fSmin = fVmin;
00217       if (fSmin > fSmax) fSmin = fSmax;
00218    } else if (fMove == 2) {
00219       // change of max value
00220       oldDiff = 0;
00221       fSmax = fPressSmax + diff * (fVmax - fVmin) / (fHeight-16);
00222       if (fSmax > fVmax) fSmax = fVmax;
00223       if (fSmax < fSmin) fSmax = fSmin;
00224    } else if (fMove == 3) {
00225       // change of min and of max value
00226       Float_t logicalDiff;
00227       logicalDiff = diff * (fVmax - fVmin) / (fHeight-16);
00228       if (fPressSmax + logicalDiff > fVmax)
00229          logicalDiff = fVmax - fPressSmax;
00230       if (fPressSmin + logicalDiff < fVmin)
00231          logicalDiff = fVmin - fPressSmin;
00232       fSmax = fPressSmax + logicalDiff;
00233       fSmin = fPressSmin + logicalDiff;
00234       if (fRelative) {
00235          if (abs(diff) < 3) oldDiff = diff;
00236          SetPointerPos(diff - oldDiff, 3);
00237          oldDiff = diff;
00238       }
00239    }
00240    else if (fMove == 4) {
00241       // change pointer position
00242       oldDiff = 0;
00243       SetPointerPos(event->fY, 1);
00244    }
00245    if (fMove != 4){
00246       SetPointerPos(0, 2);
00247    }
00248    // check if position has changed
00249    if (fMove != 0 && (fSmax != oldMax || fSmin != oldMin)) {
00250       fClient->NeedRedraw(this);
00251       SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_POS), fWidgetId, 0);
00252       fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_POS), fWidgetId, 0);
00253       PositionChanged();
00254    }
00255    return kTRUE;
00256 }
00257 
00258 //________________________________________________________________________________
00259 void TGTripleVSlider::SetConstrained(Bool_t on)
00260 {
00261    // Set pointer position constrained in the slider range.
00262 
00263    fConstrained = on;
00264 
00265    if (fConstrained) {
00266       if (GetPointerPosition() <= GetMinPosition())
00267          SetPointerPos((Int_t)GetMinPosition(), 3);
00268       else if (GetPointerPosition() >= GetMaxPosition())
00269          SetPointerPos((Int_t)GetMaxPosition(), 3);
00270    }
00271 }
00272 
00273 //________________________________________________________________________________
00274 void TGTripleVSlider::SetPointerPos(Int_t z, Int_t opt)
00275 {
00276    // Set slider pointer position in pixel value.
00277 
00278    static Long64_t was = gSystem->Now();
00279    Bool_t lcheck = (opt == 1);
00280    Int_t oldPos = fCz;
00281 
00282    if (opt < 2) {
00283       fCz = z;
00284 
00285       if (fCz < 7)
00286          fCz = 7;
00287       else if (fCz >= (Int_t)fHeight - 7)
00288          fCz = (Int_t)fHeight - 7;
00289    }
00290    if (opt == 3) {
00291       lcheck = kTRUE;
00292       fCz += z;
00293       if (fCz < 7)
00294          fCz = 7;
00295       else if (fCz >= (Int_t)fHeight-7)
00296          fCz = (Int_t)fHeight - 7;
00297    }
00298    if (fConstrained) {
00299       int relMin = (int)((fHeight-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
00300       int relMax = (int)((fHeight-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
00301       if(fCz < relMin+7) {
00302          fCz = relMin+7;
00303          lcheck = kTRUE;
00304       }
00305       if(fCz > relMax-7) {
00306          fCz = relMax-7;
00307          lcheck = kTRUE;
00308       }
00309    }
00310    if (lcheck)
00311       fSCz = fVmin + ((Float_t)(fCz-8) * (fVmax - fVmin) / (Float_t)(fHeight-16));
00312    if(fSCz < fVmin) fSCz = fVmin;
00313    if(fSCz > fVmax) fSCz = fVmax;
00314    if (fConstrained) {
00315       if(fSCz < fSmin) fSCz = fSmin;
00316       if(fSCz > fSmax) fSCz = fSmax;
00317    }
00318 
00319    DrawPointer();
00320    fClient->NeedRedraw(this);
00321    if (fCz != oldPos) {
00322       Long64_t now = gSystem->Now();
00323       if ((fMove != 4) && ((now-was) < 150)) return;
00324       was = now;
00325       SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_POINTER), fWidgetId, 0);
00326       fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_POINTER), fWidgetId, 0);
00327       PointerPositionChanged();
00328       fClient->NeedRedraw(this);
00329    }
00330 }
00331 
00332 //________________________________________________________________________________
00333 void TGTripleVSlider::SetPointerPosition(Float_t pos)
00334 {
00335    // Set pointer position in scaled (real) value
00336 
00337    if (fReversedScale) {
00338       fSCz = fVmin + fVmax - pos;
00339    }
00340    else {
00341       fSCz = pos;
00342    }
00343    Float_t absPos = (fSCz - fVmin) * (fHeight-16) / (fVmax - fVmin);
00344    SetPointerPos((int)(absPos+5.0), 0);
00345 }
00346 
00347 //______________________________________________________________________________
00348 TGTripleHSlider::TGTripleHSlider(const TGWindow *p, UInt_t w, UInt_t type, Int_t id,
00349                                  UInt_t options, ULong_t back,
00350                                  Bool_t reversed, Bool_t mark_ends,
00351                                  Bool_t constrained, Bool_t relative)
00352     : TGDoubleHSlider(p, w, type, id, options, back, reversed, mark_ends)
00353 {
00354    // Create horizontal slider widget.
00355 
00356    fPointerPic = fClient->GetPicture("slider1v.xpm");
00357    if (!fPointerPic)
00358       Error("TGTripleVSlider", "slider1v.xpm not found");
00359    fConstrained = constrained;
00360    fRelative = relative;
00361    fCz = 0;
00362    fSCz = 0;
00363    AddInput(kStructureNotifyMask);
00364    SetWindowName();
00365 }
00366 
00367 //______________________________________________________________________________
00368 TGTripleHSlider::~TGTripleHSlider()
00369 {
00370    // Delete a horizontal slider widget.
00371 
00372    if (fPointerPic) fClient->FreePicture(fPointerPic);
00373 }
00374 
00375 //______________________________________________________________________________
00376 void TGTripleHSlider::DoRedraw()
00377 {
00378    // Redraw horizontal slider widget.
00379 
00380    TGDoubleHSlider::DoRedraw();
00381    // Draw Pointer
00382    DrawPointer();
00383 }
00384 
00385 //________________________________________________________________________________
00386 void TGTripleHSlider::DrawPointer()
00387 {
00388    // Draw slider pointer
00389 
00390    if (fPointerPic) fPointerPic->Draw(fId, GetBckgndGC()(), fCz-5, fHeight/2-7);
00391 }
00392 
00393 //______________________________________________________________________________
00394 Bool_t TGTripleHSlider::HandleButton(Event_t *event)
00395 {
00396    // Handle mouse button event in horizontal slider widget.
00397 
00398    if (event->fType == kButtonPress && event->fCode == kButton1) {
00399       // constrain to the slider height
00400       if (event->fY < (Int_t)fHeight/2-7 || event->fY > (Int_t)fHeight/2+7) {
00401          return kTRUE;
00402       }
00403       fPressPoint = event->fX;
00404       fPressSmin  = fSmin;
00405       fPressSmax  = fSmax;
00406 
00407       int relMin = (int)((fWidth-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
00408       int relMax = (int)((fWidth-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
00409       if (fPressPoint > (fCz - 5) && fPressPoint < (fCz + 5) &&
00410           event->fY > ((Int_t)fHeight / 2) - 7 && event->fY < ((Int_t)fHeight / 2) + 5)
00411          // move pointer
00412          fMove = 4;
00413       else if (fPressPoint < (relMax - relMin) / 4 + relMin)
00414          // move only min value
00415          fMove = 1;
00416       else if (fPressPoint > (relMax - relMin) / 4 * 3 + relMin)
00417          // move only max value
00418          fMove = 2;
00419       else
00420          // move min and max value
00421          fMove = 3;
00422 
00423       SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_PRESS), fWidgetId, 0);
00424       fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_PRESS), fWidgetId, 0);
00425       Pressed();
00426 
00427       // last argument kFALSE forces all specified events to this window
00428       gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
00429                              kPointerMotionMask, kNone, kNone,
00430                              kTRUE, kFALSE);
00431    } else if (event->fType == kButtonRelease && event->fCode == kButton1) {
00432       SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
00433       fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
00434       Released();
00435       fMove = 0;
00436       gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);  // ungrab pointer
00437    } else
00438       fMove = 0;
00439 
00440    return kTRUE;
00441 }
00442 
00443 //______________________________________________________________________________
00444 Bool_t TGTripleHSlider::HandleConfigureNotify(Event_t* event)
00445 {
00446    // Handles resize events for this widget.
00447 
00448    TGFrame::HandleConfigureNotify(event);
00449    SetPointerPosition(fSCz);
00450    return kTRUE;
00451 }
00452 
00453 //______________________________________________________________________________
00454 Bool_t TGTripleHSlider::HandleMotion(Event_t *event)
00455 {
00456    // Handle mouse motion event in horizontal slide widget.
00457 
00458    if (fMove < 3) {
00459       // if the mouse pointer is on the cursor,
00460       // and we are not moving anything,
00461       // set the cursor shape as Pointer
00462       if (event->fX > (fCz - 5) && event->fX < (fCz + 5) &&
00463           event->fY > ((Int_t)fHeight / 2) - 7 &&
00464           event->fY < ((Int_t)fHeight / 2) + 5 &&
00465           fMove == 0)
00466          gVirtualX->SetCursor(fId, kNone);
00467       else
00468          ChangeCursor(event);
00469    }
00470    static int oldDiff = 0;
00471    static Long64_t was = gSystem->Now();
00472    Long64_t now = gSystem->Now();
00473 
00474    if (fMove == 0)  return kTRUE;
00475    if ((now-was) < 50) return kTRUE;
00476    was = now;
00477 
00478    int     diff;
00479    Float_t oldMin, oldMax;
00480 
00481    diff    = event->fX - fPressPoint;
00482    oldMin  = fSmin;
00483    oldMax  = fSmax;
00484 
00485    if (fMove == 1) {
00486       // change of min value
00487       oldDiff = 0;
00488       fSmin = fPressSmin + diff * (fVmax - fVmin) / (fWidth-16);
00489       if (fSmin < fVmin) fSmin = fVmin;
00490       if (fSmin > fSmax) fSmin = fSmax;
00491    } else if (fMove == 2) {
00492       // change of max value
00493       oldDiff = 0;
00494       fSmax = fPressSmax + diff * (fVmax - fVmin) / (fWidth-16);
00495       if (fSmax > fVmax) fSmax = fVmax;
00496       if (fSmax < fSmin) fSmax = fSmin;
00497    } else if (fMove == 3) {
00498       // change of min and of max value
00499       Float_t logicalDiff;
00500       logicalDiff = diff * (fVmax - fVmin) / (fWidth-16);
00501       if (fPressSmax + logicalDiff > fVmax)
00502          logicalDiff = fVmax - fPressSmax;
00503       if (fPressSmin + logicalDiff < fVmin)
00504          logicalDiff = fVmin - fPressSmin;
00505       fSmax = fPressSmax + logicalDiff;
00506       fSmin = fPressSmin + logicalDiff;
00507       if (fRelative) {
00508          if (abs(diff) < 3) oldDiff = diff;
00509          SetPointerPos(diff - oldDiff, 3);
00510          oldDiff = diff;
00511       }
00512    }
00513    else if (fMove == 4) {
00514       // change pointer position
00515       oldDiff = 0;
00516       SetPointerPos(event->fX, 1);
00517    }
00518    if (fMove != 4) {
00519       SetPointerPos(0, 2);
00520    }
00521    // check if position has changed
00522    if (fMove != 0 && (fSmax != oldMax || fSmin != oldMin)) {
00523       fClient->NeedRedraw(this);
00524       SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POS), fWidgetId, 0);
00525       fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS), fWidgetId, 0);
00526       PositionChanged();
00527    }
00528    return kTRUE;
00529 }
00530 
00531 //________________________________________________________________________________
00532 void TGTripleHSlider::SetConstrained(Bool_t on)
00533 {
00534    // Set pointer position constrained in the slider range.
00535 
00536    fConstrained = on;
00537 
00538    if (fConstrained) {
00539       if (GetPointerPosition() <= GetMinPosition())
00540          SetPointerPos((Int_t)GetMinPosition(), 3);
00541       else if (GetPointerPosition() >= GetMaxPosition())
00542          SetPointerPos((Int_t)GetMaxPosition(), 3);
00543    }
00544 }
00545 
00546 //________________________________________________________________________________
00547 void TGTripleHSlider::SetPointerPos(Int_t z, Int_t opt)
00548 {
00549    // Set slider pointer position in pixel value.
00550 
00551    static Long64_t was = gSystem->Now();
00552    Bool_t lcheck = (opt == 1);
00553    Int_t oldPos = fCz;
00554 
00555    if (opt < 2) {
00556       fCz = z;
00557 
00558       if (fCz < 7)
00559          fCz = 7;
00560       else if (fCz >= (Int_t)fWidth-7)
00561          fCz = (Int_t)fWidth-7;
00562    }
00563    if (opt == 3) {
00564       lcheck = kTRUE;
00565       fCz += z;
00566       if (fCz < 7)
00567          fCz = 7;
00568       else if (fCz >= (Int_t)fWidth-7)
00569          fCz = (Int_t)fWidth-7;
00570    }
00571    if (fConstrained) {
00572       int relMin = (int)((fWidth-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
00573       int relMax = (int)((fWidth-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
00574       if(fCz < relMin+7) {
00575          fCz = relMin+7;
00576          lcheck = kTRUE;
00577       }
00578       if(fCz > relMax-7) {
00579          fCz = relMax-7;
00580          lcheck = kTRUE;
00581       }
00582    }
00583    if (lcheck)
00584       fSCz = fVmin + ((Float_t)(fCz-8) * (fVmax - fVmin) / (Float_t)(fWidth-16));
00585    if(fSCz < fVmin) fSCz = fVmin;
00586    if(fSCz > fVmax) fSCz = fVmax;
00587    if (fConstrained) {
00588       if(fSCz < fSmin) fSCz = fSmin;
00589       if(fSCz > fSmax) fSCz = fSmax;
00590    }
00591 
00592    DrawPointer();
00593    fClient->NeedRedraw(this);
00594    if (fCz != oldPos) {
00595       Long64_t now = gSystem->Now();
00596       if ((fMove != 4) && ((now-was) < 150)) return;
00597       was = now;
00598       SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POINTER), fWidgetId, 0);
00599       fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POINTER), fWidgetId, 0);
00600       PointerPositionChanged();
00601       fClient->NeedRedraw(this);
00602    }
00603 }
00604 
00605 //________________________________________________________________________________
00606 void TGTripleHSlider::SetPointerPosition(Float_t pos)
00607 {
00608    // Set pointer position in scaled (real) value
00609 
00610    if (fReversedScale) {
00611       fSCz = fVmin + fVmax - pos;
00612    }
00613    else {
00614       fSCz = pos;
00615    }
00616    Float_t absPos = (fSCz - fVmin) * (fWidth-16) / (fVmax - fVmin);
00617    SetPointerPos((int)(absPos+5.0), 0);
00618 }
00619 
00620 //______________________________________________________________________________
00621 void TGTripleHSlider::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00622 {
00623     // Save an horizontal slider as a C++ statement(s) on output stream out.
00624 
00625    SaveUserColor(out, option);
00626 
00627    out <<"   TGTripleHSlider *";
00628    out << GetName() << " = new TGTripleHSlider(" << fParent->GetName()
00629        << "," << GetWidth() << ",";
00630    out << GetSString() << "," << WidgetId() << ",";
00631    out << GetOptionString() << ",ucolor";
00632    if (fMarkEnds) {
00633       if (fReversedScale)
00634          out << ",kTRUE,kTRUE";
00635       else
00636          out << ",kFALSE,kTRUE";
00637    } else if (fReversedScale) {
00638       out << ",kTRUE,kFALSE";
00639    } else {
00640       out << ",kFALSE,kFALSE";
00641    }
00642    if (!fConstrained) {
00643       if (fRelative)
00644          out << ",kFALSE,kTRUE);" << endl;
00645       else
00646          out << ",kFALSE,kFALSE);" << endl;
00647    }
00648    else if (fRelative) {
00649       out << ",kTRUE);" << endl;
00650    }
00651    else {
00652       out << ");" << endl;
00653    }
00654    if (option && strstr(option, "keep_names"))
00655       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00656 
00657    if (fVmin != 0 || fVmax != (Int_t)fWidth)
00658       out << "   " << GetName() << "->SetRange(" << fVmin << "," << fVmax
00659           << ");" << endl;
00660 
00661    if (fSmin != fWidth/8*3 || fSmax != fWidth/8*5)
00662       out << "   " << GetName() << "->SetPosition(" << GetMinPosition()
00663           << "," << GetMaxPosition() << ");" << endl;
00664 
00665    if (fScale != 10)
00666       out << "   " << GetName() << "->SetScale(" << fScale << ");" << endl;
00667 
00668    out << "   " << GetName() << "->SetPointerPosition(" << fSCz << ");" << endl;
00669 }
00670 
00671 //______________________________________________________________________________
00672 void TGTripleVSlider::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00673 {
00674     // Save an horizontal slider as a C++ statement(s) on output stream out.
00675 
00676    SaveUserColor(out, option);
00677 
00678    out<<"   TGTripleVSlider *";
00679    out << GetName() << " = new TGTripleVSlider("<< fParent->GetName()
00680        << "," << GetHeight() << ",";
00681    out << GetSString() << "," << WidgetId() << ",";
00682    out << GetOptionString() << ",ucolor";
00683    if (fMarkEnds) {
00684       if (fReversedScale)
00685          out << ",kTRUE,kTRUE";
00686       else
00687          out << ",kFALSE,kTRUE";
00688    } else if (fReversedScale) {
00689       out << ",kTRUE,kFALSE";
00690    } else {
00691       out << ",kFALSE,kFALSE";
00692    }
00693    if (!fConstrained) {
00694       if (fRelative)
00695          out << ",kFALSE,kTRUE);" << endl;
00696       else
00697          out << ",kFALSE,kFALSE);" << endl;
00698    }
00699    else if (fRelative) {
00700       out << ",kTRUE);" << endl;
00701    }
00702    else {
00703       out << ");" << endl;
00704    }
00705    if (option && strstr(option, "keep_names"))
00706       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00707 
00708    if (fVmin != 0 || fVmax != (Int_t)fHeight)
00709       out << "   " << GetName() <<"->SetRange(" << fVmin << "," << fVmax
00710           << ");" << endl;
00711 
00712    if (fSmin != fHeight/8*3 || fSmax != fHeight/8*5)
00713       out << "   " << GetName() << "->SetPosition(" << GetMinPosition()
00714           << "," << GetMaxPosition() << ");" << endl;
00715 
00716    if (fScale != 10)
00717       out << "   " << GetName() << "->SetScale(" << fScale << ");" << endl;
00718 
00719    out << "   " << GetName() << "->SetPointerPosition(" << fSCz << ");" << endl;
00720 }

Generated on Tue Jul 5 14:22:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1