Logo ROOT   master
Reference Guide
TGScrollBar.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 10/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 /**************************************************************************
12 
13  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // TGScrollBar and TGScrollBarElement //
26 // //
27 // The classes in this file implement scrollbars. Scrollbars can be //
28 // either placed horizontal or vertical. A scrollbar contains three //
29 // TGScrollBarElements: The "head", "tail" and "slider". The head and //
30 // tail are fixed at either end and have the typical arrows in them. //
31 // //
32 // The TGHScrollBar will generate the following event messages: //
33 // kC_HSCROLL, kSB_SLIDERPOS, position, 0 //
34 // kC_HSCROLL, kSB_SLIDERTRACK, position, 0 //
35 // //
36 // The TGVScrollBar will generate the following event messages: //
37 // kC_VSCROLL, kSB_SLIDERPOS, position, 0 //
38 // kC_VSCROLL, kSB_SLIDERTRACK, position, 0 //
39 // //
40 //////////////////////////////////////////////////////////////////////////
41 
42 #include "TGScrollBar.h"
43 #include "TGResourcePool.h"
44 #include "TGPicture.h"
45 #include "TImage.h"
46 #include "TSystem.h"
47 #include "TTimer.h"
48 #include "TEnv.h"
49 #include "Riostream.h"
50 #include "TVirtualX.h"
51 
52 
55 
60 
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 
64 class TSBRepeatTimer : public TTimer {
65 private:
66  TGScrollBar *fScrollBar; // scroll bar
67  Int_t fSmallInc; // step
68 public:
69  TSBRepeatTimer(TGScrollBar *s, Long_t ms, Int_t inc) : TTimer(ms, kTRUE)
70  { fScrollBar = s; fSmallInc = inc; }
71 
72  Bool_t Notify();
73  Int_t GetSmallInc() const { return fSmallInc; }
74 };
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Notify when timer times out and reset the timer.
78 
79 Bool_t TSBRepeatTimer::Notify()
80 {
81  fScrollBar->HandleTimer(this);
82  Reset();
83  return kFALSE;
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Constructor.
88 
90  UInt_t w, UInt_t h, UInt_t options, Pixel_t back) :
91  TGFrame(p, w, h, options | kOwnBackground, back)
92 {
93  fPic = fPicN = pic;
94  fState = kButtonUp;
95  fPicD = 0;
96  fStyle = 0;
97  if ((gClient->GetStyle() > 1) || (p && p->InheritsFrom("TGScrollBar")))
98  fStyle = gClient->GetStyle();
99 
101  fHighColor = gClient->GetResourcePool()->GetHighLightColor();
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// destructor
107 
109 {
110  if (fPicD) {
112  }
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Change state of scrollbar element (either up or down).
117 
119 {
120  if (state != fState) {
121  switch (state) {
122  case kButtonDown:
125  break;
126  case kButtonUp:
127  case kButtonDisabled:
130  break;
131  }
132  fState = state;
133  fClient->NeedRedraw(this);
134  }
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Enable/Disable scroll bar button chaging the state.
139 
141 {
142  if (on) {
143  if (fState == kButtonUp) {
144  return;
145  }
147  fPic = fPicN;
148  } else {
149  if (fState == kButtonDisabled) {
150  return;
151  }
153 
154  if (!fPicD) {
155  TImage *img = TImage::Create();
156  if (!img) return;
157  TImage *img2 = TImage::Create();
158  if (!img2) {
159  if (img) delete img;
160  return;
161  }
162  TString back = gEnv->GetValue("Gui.BackgroundColor", "#c0c0c0");
163  img2->FillRectangle(back.Data(), 0, 0, fPic->GetWidth(), fPic->GetHeight());
164  img->SetImage(fPicN->GetPicture(), fPicN->GetMask());
165  Pixmap_t mask = img->GetMask();
166  img2->Merge(img, "overlay");
167 
168  TString name = "disbl_";
169  name += fPic->GetName();
170  fPicD = fClient->GetPicturePool()->GetPicture(name.Data(), img2->GetPixmap(),
171  mask);
172  delete img;
173  delete img2;
174  }
175  fPic = fPicD;
176  }
177  fClient->NeedRedraw(this);
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Draw border around scollbar element.
182 
184 {
185  switch (fOptions & (kSunkenFrame | kRaisedFrame)) {
186  case kSunkenFrame: // pressed
187  gVirtualX->DrawLine(fId, GetBlackGC()(), 0, 0, fWidth-2, 0);
188  gVirtualX->DrawLine(fId, GetBlackGC()(), 0, 0, 0, fHeight-2);
189  gVirtualX->DrawLine(fId, GetShadowGC()(), 1, 1, fWidth-3, 1);
190  gVirtualX->DrawLine(fId, GetShadowGC()(), 1, 1, 1, fHeight-3);
191 
192  gVirtualX->DrawLine(fId, GetWhiteGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
193  gVirtualX->DrawLine(fId, GetWhiteGC()(), fWidth-1, fHeight-1, fWidth-1, 1);
194  gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
195  gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, fHeight-2, fWidth-2, 2);
196 
197  if (fPic) {
198  int x = (fWidth - fPic->GetWidth()) >> 1;
199  int y = (fHeight - fPic->GetHeight()) >> 1;
200  fPic->Draw(fId, GetBckgndGC()(), x+1, y+1); // 3, 3
201  }
202  break;
203 
204  case kRaisedFrame: // normal
205  case kButtonDisabled:
206  if (fStyle > 0) {
207  // new modern (flat) version
208  if (fBackground == fHighColor) {
209  gVirtualX->DrawRectangle(fId, GetShadowGC()(), 0, 0, fWidth-1, fHeight-1);
210  }
211  else {
212  if (fPic == 0)
213  gVirtualX->DrawRectangle(fId, GetShadowGC()(), 0, 0, fWidth-1, fHeight-1);
214  else
215  gVirtualX->DrawRectangle(fId, GetBckgndGC()(), 0, 0, fWidth-1, fHeight-1);
216  }
217  if (fParent && fParent->InheritsFrom("TGHScrollBar")) {
218  if (fWidth > 20) {
219  gVirtualX->DrawLine(fId, GetShadowGC()(), (fWidth/2)-3, 4, (fWidth/2)-3, fHeight-5);
220  gVirtualX->DrawLine(fId, GetShadowGC()(), (fWidth/2), 4, (fWidth/2), fHeight-5);
221  gVirtualX->DrawLine(fId, GetShadowGC()(), (fWidth/2)+3, 4, (fWidth/2)+3, fHeight-5);
222  }
223  }
224  else if (fParent && fParent->InheritsFrom("TGVScrollBar")) {
225  if (fHeight > 20) {
226  gVirtualX->DrawLine(fId, GetShadowGC()(), 4, (fHeight/2)-3, fWidth-5, (fHeight/2)-3);
227  gVirtualX->DrawLine(fId, GetShadowGC()(), 4, (fHeight/2) , fWidth-5, (fHeight/2));
228  gVirtualX->DrawLine(fId, GetShadowGC()(), 4, (fHeight/2)+3, fWidth-5, (fHeight/2)+3);
229  }
230  }
231  else { // not used in a scroll bar (e.g. in a combo box)
232  gVirtualX->DrawRectangle(fId, GetShadowGC()(), 0, 0, fWidth-1, fHeight-1);
233  }
234  }
235  else {
236  gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, fWidth-2, 0);
237  gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, 0, fHeight-2);
238  gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, fWidth-3, 1);
239  gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, 1, fHeight-3);
240 
241  gVirtualX->DrawLine(fId, GetShadowGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
242  gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-2, fHeight-2, fWidth-2, 1);
243  gVirtualX->DrawLine(fId, GetBlackGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
244  gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
245  }
246  if (fPic) {
247  int x = (fWidth - fPic->GetWidth()) >> 1;
248  int y = (fHeight - fPic->GetHeight()) >> 1;
249  fPic->Draw(fId, GetBckgndGC()(), x, y); // 2, 2
250  }
251  break;
252 
253  default:
254  break;
255  }
256 }
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 /// Handle mouse crossing event.
260 
262 {
263  if (fStyle > 0) {
264  TGScrollBarElement *el = 0;
265  TGScrollBar *bar = 0;
266  if ((event->fType == kEnterNotify) && (fState != kButtonDisabled)) {
268  } else {
270  }
271  if (event->fType == kLeaveNotify) {
273  }
274  gVirtualX->SetWindowBackground(fId, fBgndColor);
276  DrawBorder();
277  if (fParent && fParent->InheritsFrom("TGScrollBar")) {
278  bar = (TGScrollBar *)fParent;
279  if ((el = bar->GetHead()) != this) {
281  el->DrawBorder();
282  }
283  if ((el = bar->GetTail()) != this) {
285  el->DrawBorder();
286  }
287  if ((el = bar->GetSlider()) != this) {
289  el->DrawBorder();
290  }
291  }
292  }
293  return kTRUE;
294 }
295 
296 ////////////////////////////////////////////////////////////////////////////////
297 /// Constructor.
298 
300  UInt_t options, Pixel_t back) :
301  TGFrame(p, w, h, options | kOwnBackground, back),
302  fX0(0), fY0(0), fXp(0), fYp(0), fDragging(kFALSE), fGrabPointer(kTRUE),
303  fRange(0), fPsize(0), fPos(0), fSliderSize(0), fSliderRange(0),
304  fSmallInc(1), fHead(0), fTail(0), fSlider(0), fHeadPic(0),
305  fTailPic(0), fRepeat(0), fSubw()
306 {
308 
310  fHighColor = gClient->GetResourcePool()->GetHighLightColor();
311 
312  fMsgWindow = p;
313  if (gClient->GetStyle() == 0)
315  SetWindowName();
317 }
318 
319 ////////////////////////////////////////////////////////////////////////////////
320 /// Delete a scrollbar (either horizontal or vertical).
321 
323 {
324  delete fHead;
325  delete fTail;
326  delete fSlider;
329  if (fRepeat) { delete fRepeat; fRepeat = 0; }
330 }
331 
332 ////////////////////////////////////////////////////////////////////////////////
333 /// Handle mouse crossing event.
334 
336 {
337  if (gClient->GetStyle() > 0) {
338  if (event->fType == kEnterNotify) {
340  } else {
342  }
343  if (event->fType == kLeaveNotify) {
345  }
349  fHead->DrawBorder();
350  fTail->DrawBorder();
351  fSlider->DrawBorder();
352  }
353  return kTRUE;
354 }
355 
356 ////////////////////////////////////////////////////////////////////////////////
357 /// Handle repeat timer for horizontal or vertical scrollbar. Every time
358 /// timer times out we move slider.
359 
361 {
362  // shorten time out time to 50 milli seconds
363  t->SetTime(50);
364 
365  Window_t dum1, dum2;
366  Event_t ev;
367 
368  ev.fCode = kButton1;
369  ev.fType = kButtonPress;
370  ev.fUser[0] = fSubw;
371 
372  if (IsAccelerated()) {
373  ++fSmallInc;
374  if (fSmallInc > 100) fSmallInc = 100;
375  }
376 
377  gVirtualX->QueryPointer(fId, dum1, dum2, ev.fXRoot, ev.fYRoot, ev.fX, ev.fY,
378  ev.fState);
379 
380  HandleButton(&ev);
381 
382  return kTRUE;
383 }
384 
385 ////////////////////////////////////////////////////////////////////////////////
386 /// Static method returning scrollbar background pixmap.
387 
389 {
390  static Bool_t init = kFALSE;
391  if (!init) {
392  fgBckgndPixmap = gClient->GetResourcePool()->GetCheckeredPixmap();
393  init = kTRUE;
394  }
395  return fgBckgndPixmap;
396 }
397 
398 ////////////////////////////////////////////////////////////////////////////////
399 /// Static method returning the scrollbar width.
400 
402 {
403  return fgScrollBarWidth;
404 }
405 
406 ////////////////////////////////////////////////////////////////////////////////
407 /// Change background color
408 
410 {
412  fHead->ChangeBackground(back);
413  fTail->ChangeBackground(back);
414  fSlider->ChangeBackground(back);
415 }
416 
417 ////////////////////////////////////////////////////////////////////////////////
418 /// Create a horizontal scrollbar widget.
419 
421  UInt_t options, ULong_t back) :
422  TGScrollBar(p, w, h, options, back)
423 {
424  fHeadPic = fClient->GetPicture("arrow_left.xpm");
425  fTailPic = fClient->GetPicture("arrow_right.xpm");
426 
427  if (!fHeadPic || !fTailPic) {
428  Error("TGHScrollBar", "arrow_*.xpm not found");
429  return;
430  }
432  kRaisedFrame);
434  kRaisedFrame);
435  fSlider = new TGScrollBarElement(this, 0, fgScrollBarWidth, 50,
436  kRaisedFrame);
437 
440 
441  fDragging = kFALSE;
443  fPos = 0;
444 
445  fRange = TMath::Max((Int_t) w - (fgScrollBarWidth << 1), 1);
446  fPsize = fRange >> 1;
447 
448  fSliderSize = 50;
449  fSliderRange = 1;
450 
455 }
456 
457 ////////////////////////////////////////////////////////////////////////////////
458 /// Layout and move horizontal scrollbar components.
459 
461 {
462  // Should also recalculate the slider size and range, etc.
463  fHead->Move(0, 0);
467 
468  if (fSlider->GetX() != fX0) {
469  fSlider->Move(fX0, 0);
472  }
473 }
474 
475 ////////////////////////////////////////////////////////////////////////////////
476 /// Handle a mouse button event in a horizontal scrolbar.
477 
479 {
480  Int_t newpos;
481 
482  if (event->fCode == kButton4) {
483  if (!fHead->IsEnabled()) {
484  return kFALSE;
485  }
486  //scroll left
487  newpos = fPos - fPsize;
488  if (newpos<0) newpos = 0;
489  SetPosition(newpos);
490  return kTRUE;
491  }
492  if (event->fCode == kButton5) {
493  if (!fTail->IsEnabled()) {
494  return kFALSE;
495  }
496  // scroll right
497  newpos = fPos + fPsize;
498  SetPosition(newpos);
499  return kTRUE;
500  }
501 
502  if (event->fType == kButtonPress) {
503  if (event->fCode == kButton3) {
504  fX0 = event->fX - fSliderSize/2;
508  fPos = (Int_t)pos;
509 
510  fPos = TMath::Max(fPos, 0);
512  fSlider->Move(fX0, 0);
513 
516  return kTRUE;
517  }
518 
519  // fUser[0] contains the subwindow (child) in which the event occured
520  // (see GX11Gui.cxx)
521  Window_t subw = (Window_t)event->fUser[0];
522 
523  if (subw == fSlider->GetId()) {
524  fXp = event->fX - fX0;
525  fYp = event->fY - fY0;
526  fDragging = kTRUE;
527 
528  } else {
529 
530  if (!fRepeat)
531  fRepeat = new TSBRepeatTimer(this, 400, fSmallInc); // 500
532  fRepeat->Reset();
534  fSubw = subw;
535 
536  if (subw == fHead->GetId()) {
537  //if (!fHead->IsEnabled()) {
538  // return kFALSE;
539  //}
541  fPos -= fSmallInc;
542  } else if (subw == fTail->GetId()) {
543  //if (!fTail->IsEnabled()) {
544  // return kFALSE;
545  // }
547  fPos += fSmallInc;
548  } else if (event->fX > fgScrollBarWidth && event->fX < fX0)
549  fPos -= fPsize;
550  else if (event->fX > fX0+fSliderSize && event->fX < (Int_t)fWidth-fgScrollBarWidth)
551  fPos += fPsize;
552 
553  fPos = TMath::Max(fPos, 0);
555 
557 
560 
561  fSlider->Move(fX0, 0);
562 
565  }
566 
567  // last argument kFALSE forces all specified events to this window
568  if (fGrabPointer && !fClient->IsEditable())
571  kTRUE, kFALSE);
572  } else {
575 
576  if (fRepeat) {
577  fRepeat->Remove();
578  fRepeat->SetTime(400); // might have been shortened in HandleTimer()
579  fSmallInc = ((TSBRepeatTimer*)fRepeat)->GetSmallInc();
580  }
581 
582  fDragging = kFALSE;
583 
584  fPos = TMath::Max(fPos, 0);
586 
589 
590  if (fGrabPointer)
591  gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
592  }
593  return kTRUE;
594 }
595 
596 ////////////////////////////////////////////////////////////////////////////////
597 /// Handle mouse motion event in a horizontal scrollbar.
598 
600 {
601  if (fDragging) {
602  fX0 = event->fX - fXp;
603  fY0 = event->fY - fYp;
604 
607  fSlider->Move(fX0, 0);
609  fPos = (Int_t)pos;
610 
611  fPos = TMath::Max(fPos, 0);
613 
616  }
617  return kTRUE;
618 }
619 
620 ////////////////////////////////////////////////////////////////////////////////
621 /// Set range of horizontal scrollbar.
622 
623 void TGHScrollBar::SetRange(Int_t range, Int_t page_size)
624 {
625  fRange = TMath::Max(range, 1);
626  fPsize = TMath::Max(page_size, 0);
627  fPos = TMath::Max(fPos, 0);
629 
631  fRange, (UInt_t) 6);
633 
635  (UInt_t) 1);
636 
640 
641  fSlider->Move(fX0, 0);
644 
645  // fPos = (fX0 - fgScrollBarWidth) * (fRange-fPsize) / fSliderRange;
646 
651 }
652 
653 ////////////////////////////////////////////////////////////////////////////////
654 /// Set logical slider position of horizontal scrollbar.
655 
657 {
658  fPos = TMath::Max(pos, 0);
659  fPos = TMath::Min(pos, fRange-fPsize);
660 
664 
665  fSlider->Move(fX0, 0);
668 
671 }
672 
673 
674 ////////////////////////////////////////////////////////////////////////////////
675 /// Create a vertical scrollbar.
676 
678  UInt_t options, ULong_t back) :
679  TGScrollBar(p, w, h, options, back)
680 {
681  fHeadPic = fClient->GetPicture("arrow_up.xpm");
682  fTailPic = fClient->GetPicture("arrow_down.xpm");
683 
684  if (!fHeadPic || !fTailPic) {
685  Error("TGVScrollBar", "arrow_*.xpm not found");
686  return;
687  }
689  kRaisedFrame);
691  kRaisedFrame);
692  fSlider = new TGScrollBarElement(this, 0, fgScrollBarWidth, 50,
693  kRaisedFrame);
694 
697 
698  fDragging = kFALSE;
700  fPos = 0;
701 
702  fRange = TMath::Max((Int_t) h - (fgScrollBarWidth << 1), 1);
703  fPsize = fRange >> 1;
704 
705  fSliderSize = 50;
706  fSliderRange = 1;
707 
712 }
713 
714 ////////////////////////////////////////////////////////////////////////////////
715 /// Layout and move vertical scrollbar components.
716 
718 {
719  // Should recalculate fSliderSize, fSliderRange, fX0, fY0, etc. too...
720  fHead->Move(0, 0);
724 
725  if (fSlider->GetY() != fY0) {
726  fSlider->Move(0, fY0);
729  }
730 }
731 
732 ////////////////////////////////////////////////////////////////////////////////
733 /// Handle mouse button event in vertical scrollbar.
734 
736 {
737  Int_t newpos;
738 
739  if (event->fCode == kButton4) {
740  if (!fHead->IsEnabled()) {
741  return kFALSE;
742  }
743  //scroll up
744  newpos = fPos - fPsize;
745  if (newpos<0) newpos = 0;
746  SetPosition(newpos);
747  return kTRUE;
748  }
749  if (event->fCode == kButton5) {
750  if (!fTail->IsEnabled()) {
751  return kFALSE;
752  }
753 
754  // scroll down
755  newpos = fPos + fPsize;
756  SetPosition(newpos);
757  return kTRUE;
758  }
759 
760  if (event->fType == kButtonPress) {
761  if (event->fCode == kButton3) {
762  fY0 = event->fY - fSliderSize/2;
766  fPos = (Int_t)pos;
767 
768  fPos = TMath::Max(fPos, 0);
770  fSlider->Move(0, fY0);
771 
774  return kTRUE;
775  }
776 
777  // fUser[0] contains the subwindow (child) in which the event occured
778  // (see GX11Gui.cxx)
779  Window_t subw = (Window_t)event->fUser[0];
780 
781  if (subw == fSlider->GetId()) {
782  fXp = event->fX - fX0;
783  fYp = event->fY - fY0;
784  fDragging = kTRUE;
785 
786  } else {
787 
788  if (!fRepeat)
789  fRepeat = new TSBRepeatTimer(this, 400, fSmallInc); // 500
790  fRepeat->Reset();
792  fSubw = subw;
793 
794  if (subw == fHead->GetId()) {
795  //if (!fHead->IsEnabled()) {
796  // return kFALSE;
797  // }
799  fPos -= fSmallInc;
800  } else if (subw == fTail->GetId()) {
801  //if (!fTail->IsEnabled()) {
802  // return kFALSE;
803  //}
805  fPos += fSmallInc;
806  } else if (event->fY > fgScrollBarWidth && event->fY < fY0)
807  fPos -= fPsize;
808  else if (event->fY > fY0+fSliderSize && event->fY < (Int_t)fHeight-fgScrollBarWidth)
809  fPos += fPsize;
810 
811  fPos = TMath::Max(fPos, 0);
813 
815  fY0 = (Int_t)y0;
816 
819 
820  fSlider->Move(0, fY0);
821 
824  }
825 
826  // last argument kFALSE forces all specified events to this window
827  if (fGrabPointer && !fClient->IsEditable())
830  kTRUE, kFALSE);
831  } else {
834 
835  if (fRepeat) {
836  fRepeat->Remove();
837  fRepeat->SetTime(400); // might have been shortened in HandleTimer()
838  fSmallInc = ((TSBRepeatTimer*)fRepeat)->GetSmallInc();
839  }
840 
841  fDragging = kFALSE;
842 
843  fPos = TMath::Max(fPos, 0);
845 
848 
849  if (fGrabPointer) {
850  gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
851  }
852  }
853  return kTRUE;
854 }
855 
856 ////////////////////////////////////////////////////////////////////////////////
857 /// Handle mouse motion in a vertical scrollbar.
858 
860 {
861  if (fDragging) {
862  fX0 = event->fX - fXp;
863  fY0 = event->fY - fYp;
864 
867  fSlider->Move(0, fY0);
869  fPos = (Int_t)pos;
870 
871  fPos = TMath::Max(fPos, 0);
873 
876  }
877  return kTRUE;
878 }
879 
880 ////////////////////////////////////////////////////////////////////////////////
881 /// Set range of vertical scrollbar.
882 
883 void TGVScrollBar::SetRange(Int_t range, Int_t page_size)
884 {
885  fRange = TMath::Max(range, 1);
886  fPsize = TMath::Max(page_size, 0);
887  fPos = TMath::Max(fPos, 0);
889 
891  fRange, (UInt_t) 6);
893 
895  (UInt_t)1);
896 
898  fY0 = (Int_t)y0;
901 
902  fSlider->Move(0, fY0);
905 
906  // fPos = (fY0 - fgScrollBarWidth) * (fRange-fPsize) / fSliderRange;
907 
908 
913 }
914 
915 ////////////////////////////////////////////////////////////////////////////////
916 /// Set logical slider position of vertical scrollbar.
917 
919 {
920  fPos = TMath::Max(pos, 0);
921  fPos = TMath::Min(pos, fRange-fPsize);
922 
924  fY0 = (Int_t)y0;
927 
928  fSlider->Move(0, fY0);
931 
934 }
935 
936 ////////////////////////////////////////////////////////////////////////////////
937 /// Save an horizontal scrollbar as a C++ statement(s) on output stream out.
938 
939 void TGHScrollBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
940 {
941  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
942 
943  out <<" TGHScrollBar *";
944  out << GetName() << " = new TGHScrollBar(" << fParent->GetName()
945  << "," << GetWidth() << "," << GetHeight();
946 
948  if (!GetOptions()) {
949  out <<");" << std::endl;
950  } else {
951  out << "," << GetOptionString() <<");" << std::endl;
952  }
953  } else {
954  out << "," << GetOptionString() << ",ucolor);" << std::endl;
955  }
956  if (option && strstr(option, "keep_names"))
957  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
958 
959  out << " " << GetName() <<"->SetRange(" << GetRange() << "," << GetPageSize() << ");" << std::endl;
960  out << " " << GetName() <<"->SetPosition(" << GetPosition() << ");" << std::endl;
961 }
962 
963 ////////////////////////////////////////////////////////////////////////////////
964 /// Save an vertical scrollbar as a C++ statement(s) on output stream out.
965 
966 void TGVScrollBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
967 {
968  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
969 
970  out<<" TGVScrollBar *";
971  out << GetName() <<" = new TGVScrollBar("<< fParent->GetName()
972  << "," << GetWidth() << "," << GetHeight();
973 
975 
976  if (!GetOptions()) {
977  out <<");" << std::endl;
978  } else {
979  out << "," << GetOptionString() <<");" << std::endl;
980  }
981  } else {
982  out << "," << GetOptionString() << ",ucolor);" << std::endl;
983  }
984  if (option && strstr(option, "keep_names"))
985  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
986 
987  out << " " << GetName() <<"->SetRange(" << GetRange() << "," << GetPageSize() << ");" << std::endl;
988  out << " " << GetName() <<"->SetPosition(" << GetPosition() << ");" << std::endl;
989 }
TGScrollBarElement * fTail
Definition: TGScrollBar.h:98
const TGWindow * fParent
Definition: TGWindow.h:36
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:589
Pixel_t fHighColor
Definition: TGScrollBar.h:106
virtual void SetPosition(Int_t pos)
Set logical slider position of vertical scrollbar.
virtual Int_t GetPageSize() const
Definition: TGScrollBar.h:133
TGScrollBarElement * fSlider
Definition: TGScrollBar.h:99
virtual UInt_t GetOptions() const
Definition: TGFrame.h:222
const char * GetName() const
Returns name of object.
Definition: TGPicture.h:62
void Reset()
Reset the timer.
Definition: TTimer.cxx:157
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:323
const char Option_t
Definition: RtypesCore.h:64
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
virtual void Layout()
Layout and move horizontal scrollbar components.
Int_t GetY() const
Definition: TGFrame.h:257
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition: TGFrame.cxx:739
UInt_t GetHeight() const
Definition: TGFrame.h:250
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:167
static Int_t GetScrollBarWidth()
Static method returning the scrollbar width.
TGScrollBarElement * fHead
Definition: TGScrollBar.h:97
Int_t fY
Definition: GuiTypes.h:177
Basic string class.
Definition: TString.h:131
Pixel_t fBackground
Definition: TGFrame.h:120
#define gClient
Definition: TGClient.h:166
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
int Int_t
Definition: RtypesCore.h:43
bool Bool_t
Definition: RtypesCore.h:61
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
TGHScrollBar(const TGWindow *p=0, UInt_t w=4, UInt_t h=2, UInt_t options=kHorizontalFrame, Pixel_t back=GetDefaultFrameBackground())
Create a horizontal scrollbar widget.
const TGPicture * fTailPic
Definition: TGScrollBar.h:101
An abstract interface to image processing library.
Definition: TImage.h:29
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:172
virtual void SetEnabled(Bool_t on=kTRUE)
Enable/Disable scroll bar button chaging the state.
virtual Bool_t HandleButton(Event_t *event)
Handle a mouse button event in a horizontal scrolbar.
UInt_t GetWidth() const
Definition: TGFrame.h:249
virtual Bool_t IsEnabled() const
Definition: TGScrollBar.h:73
UInt_t GetHeight() const
Definition: TGPicture.h:64
virtual void DrawBorder()
Draw border around scollbar element.
Handle_t GetId() const
Definition: TGObject.h:47
Int_t fPsize
Definition: TGScrollBar.h:92
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:116
virtual Pixmap_t GetPixmap()
Definition: TImage.h:235
void Draw(Option_t *="")
Default Draw method for all objects.
Definition: TGPicture.h:57
Bool_t fGrabPointer
Definition: TGScrollBar.h:90
const Mask_t kPointerMotionMask
Definition: GuiTypes.h:162
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:414
virtual void ChangeBackground(Pixel_t back)
Change frame background color.
Definition: TGFrame.cxx:277
virtual void FillRectangle(const char *=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:192
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition: TGWindow.cxx:230
Double_t x[n]
Definition: legend1.C:17
TGPicturePool * GetPicturePool() const
Definition: TGClient.h:135
ULong_t Pixel_t
Definition: GuiTypes.h:39
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:667
virtual void SetRange(Int_t range, Int_t page_size)
Set range of horizontal scrollbar.
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:308
const TGPicture * fHeadPic
Definition: TGScrollBar.h:100
Bool_t fDragging
Definition: TGScrollBar.h:89
Int_t fXRoot
Definition: GuiTypes.h:178
virtual Int_t GetPosition() const
Definition: TGScrollBar.h:132
TGScrollBar(const TGScrollBar &)
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:629
const TGPicture * fPicN
Definition: TGScrollBar.h:57
static constexpr double s
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in a horizontal scrollbar.
const TGWindow * fMsgWindow
Definition: TGWidget.h:60
virtual ~TGScrollBar()
Delete a scrollbar (either horizontal or vertical).
virtual Bool_t Notify()
Notify when timer times out.
Definition: TTimer.cxx:143
virtual void SetPosition(Int_t pos)
Set logical slider position of horizontal scrollbar.
static Int_t fgScrollBarWidth
Definition: TGScrollBar.h:109
const Mask_t kButtonPressMask
Definition: GuiTypes.h:160
Pixmap_t GetPicture() const
Definition: TGPicture.h:65
void Remove()
Definition: TTimer.h:85
static Pixmap_t GetBckgndPixmap()
Static method returning scrollbar background pixmap.
Int_t GetX() const
Definition: TGFrame.h:256
Int_t fRange
Definition: TGScrollBar.h:91
UInt_t fOptions
Definition: TGFrame.h:119
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
virtual void PageSizeChanged(Int_t range)
Definition: TGScrollBar.h:150
Bool_t IsEditable() const
Definition: TGClient.h:98
EGEventType fType
Definition: GuiTypes.h:174
virtual Int_t GetRange() const
Definition: TGScrollBar.h:134
static const TGGC & GetWhiteGC()
Get white graphics context.
Definition: TGFrame.cxx:729
virtual Bool_t HandleTimer(TTimer *t)
Handle repeat timer for horizontal or vertical scrollbar.
static Pixmap_t fgBckgndPixmap
Definition: TGScrollBar.h:108
static constexpr double ms
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:318
Int_t fSliderRange
Definition: TGScrollBar.h:95
unsigned int UInt_t
Definition: RtypesCore.h:44
EvaluateInfo init(std::vector< RooRealProxy > parameters, std::vector< ArrayWrapper * > wrappers, std::vector< double *> arrays, size_t begin, size_t batchSize)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:888
const Handle_t kNone
Definition: GuiTypes.h:87
Bool_t fAccelerated
Definition: TGScrollBar.h:104
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
virtual void RangeChanged(Int_t range)
Definition: TGScrollBar.h:149
Int_t fYRoot
Definition: GuiTypes.h:178
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
TTimer * fRepeat
Definition: TGScrollBar.h:102
TGScrollBarElement(const TGScrollBarElement &)
const TGPicture * fPic
Definition: TGScrollBar.h:56
static const TGGC & GetBlackGC()
Get black graphics context.
Definition: TGFrame.cxx:719
Int_t fPos
Definition: TGScrollBar.h:93
#define gVirtualX
Definition: TVirtualX.h:338
#define h(i)
Definition: RSha256.hxx:106
UInt_t fWidth
Definition: TGFrame.h:112
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:577
const Bool_t kFALSE
Definition: RtypesCore.h:90
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:166
long Long_t
Definition: RtypesCore.h:52
virtual void Layout()
Layout and move vertical scrollbar components.
#define ClassImp(name)
Definition: Rtypes.h:361
virtual Pixmap_t GetMask()
Definition: TImage.h:236
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:161
UInt_t fCode
Definition: GuiTypes.h:179
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:289
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
virtual void SetRange(Int_t range, Int_t page_size)
Set range of vertical scrollbar.
unsigned long ULong_t
Definition: RtypesCore.h:53
Double_t y[n]
Definition: legend1.C:17
Int_t fSmallInc
Definition: TGScrollBar.h:96
UInt_t GetWidth() const
Definition: TGPicture.h:63
UInt_t fHeight
Definition: TGFrame.h:113
TGVScrollBar(const TGWindow *p=0, UInt_t w=2, UInt_t h=4, UInt_t options=kVerticalFrame, Pixel_t back=GetDefaultFrameBackground())
Create a vertical scrollbar.
Long_t fUser[5]
Definition: GuiTypes.h:186
Handle_t fId
Definition: TGObject.h:36
virtual ~TGScrollBarElement()
destructor
static constexpr double bar
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion in a vertical scrollbar.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save an vertical scrollbar as a C++ statement(s) on output stream out.
Handle_t Window_t
Definition: GuiTypes.h:28
virtual void SetEditDisabled(UInt_t on=kEditDisable)
Definition: TGWindow.h:114
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:469
TGClient * fClient
Definition: TGObject.h:37
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Int_t fSliderSize
Definition: TGScrollBar.h:94
virtual Bool_t HandleButton(Event_t *event)=0
Handle_t Pixmap_t
Definition: GuiTypes.h:29
virtual void PositionChanged(Int_t pos)
Definition: TGScrollBar.h:148
Pixmap_t GetMask() const
Definition: TGPicture.h:66
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:372
UInt_t fState
Definition: GuiTypes.h:180
UInt_t fEditDisabled
Definition: TGWindow.h:40
virtual void ChangeBackground(Pixel_t back)
Change background color.
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition: TGFrame.cxx:2437
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2464
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in vertical scrollbar.
static TImage * Create()
Create an image.
Definition: TImage.cxx:36
const TGPicture * fPicD
Definition: TGScrollBar.h:58
const Mask_t kAnyModifier
Definition: GuiTypes.h:209
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
virtual void SetState(Int_t state)
Change state of scrollbar element (either up or down).
const Bool_t kTRUE
Definition: RtypesCore.h:89
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:749
Int_t fX
Definition: GuiTypes.h:177
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save an horizontal scrollbar as a C++ statement(s) on output stream out.
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition: TGFrame.cxx:759
char name[80]
Definition: TGX11.cxx:109
Window_t fSubw
Definition: TGScrollBar.h:103
Bool_t IsAccelerated() const
Definition: TGScrollBar.h:141
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:119
void SetTime(Long_t milliSec)
Definition: TTimer.h:90
Pixel_t fBgndColor
Definition: TGScrollBar.h:105
const char * Data() const
Definition: TString.h:364