Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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/** \class TGScrollBar
25 \ingroup guiwidgets
26
27The classes in this file implement scrollbars. Scrollbars can be
28either placed horizontal or vertical. A scrollbar contains three
30\class TGScrollBarElements
31\ingroup guiwidgets
32The "head", "tail" and "slider". The head and
33tail are fixed at either end and have the typical arrows in them.
34
35\class TGHScrollBar
36\ingroup guiwidgets
37The TGHScrollBar will generate the following event messages:
38kC_HSCROLL, kSB_SLIDERPOS, position, 0
39kC_HSCROLL, kSB_SLIDERTRACK, position, 0
40
41\class TGVScrollBar
42\ingroup guiwidgets
43The TGVScrollBar will generate the following event messages:
44kC_VSCROLL, kSB_SLIDERPOS, position, 0
45kC_VSCROLL, kSB_SLIDERTRACK, position, 0
46
47*/
48
49
50#include "TGScrollBar.h"
51#include "TGResourcePool.h"
52#include "TGPicture.h"
53#include "TImage.h"
54#include "TSystem.h"
55#include "TTimer.h"
56#include "TEnv.h"
57#include "TVirtualX.h"
58
59#include <iostream>
60
61
64
65
66
67////////////////////////////////////////////////////////////////////////////////
68
69class TSBRepeatTimer : public TTimer {
70private:
71 TGScrollBar *fScrollBar; // scroll bar
73public:
75 { fScrollBar = s; fSmallInc = inc; }
76
77 Bool_t Notify() override;
78 Int_t GetSmallInc() const { return fSmallInc; }
79};
80
81////////////////////////////////////////////////////////////////////////////////
82/// Notify when timer times out and reset the timer.
83
85{
86 fScrollBar->HandleTimer(this);
87 Reset();
88 return kFALSE;
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Constructor.
93
95 UInt_t w, UInt_t h, UInt_t options, Pixel_t back) :
96 TGFrame(p, w, h, options | kOwnBackground, back)
97{
98 fPic = fPicN = pic;
100 fPicD = 0;
101 fStyle = 0;
102 if ((gClient->GetStyle() > 1) || (p && p->InheritsFrom("TGScrollBar")))
103 fStyle = gClient->GetStyle();
104
106 fHighColor = gClient->GetResourcePool()->GetHighLightColor();
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// destructor
112
114{
115 if (fPicD) {
116 fClient->FreePicture(fPicD);
117 }
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Change state of scrollbar element (either up or down).
122
124{
125 if (state != fState) {
126 switch (state) {
127 case kButtonDown:
130 break;
131 case kButtonUp:
132 case kButtonDisabled:
135 break;
136 }
137 fState = state;
138 fClient->NeedRedraw(this);
139 }
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Enable/Disable scroll bar button chaging the state.
144
146{
147 if (on) {
148 if (fState == kButtonUp) {
149 return;
150 }
152 fPic = fPicN;
153 } else {
154 if (fState == kButtonDisabled) {
155 return;
156 }
158
159 if (!fPicD) {
160 TImage *img = TImage::Create();
161 if (!img) return;
162 TImage *img2 = TImage::Create();
163 if (!img2) {
164 if (img) delete img;
165 return;
166 }
167 TString back = gEnv->GetValue("Gui.BackgroundColor", "#c0c0c0");
168 img2->FillRectangle(back.Data(), 0, 0, fPic->GetWidth(), fPic->GetHeight());
169 img->SetImage(fPicN->GetPicture(), fPicN->GetMask());
170 Pixmap_t mask = img->GetMask();
171 img2->Merge(img, "overlay");
172
173 TString name = "disbl_";
174 name += fPic->GetName();
175 fPicD = fClient->GetPicturePool()->GetPicture(name.Data(), img2->GetPixmap(),
176 mask);
177 delete img;
178 delete img2;
179 }
180 fPic = fPicD;
181 }
182 fClient->NeedRedraw(this);
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Draw border around scollbar element.
187
189{
190 switch (fOptions & (kSunkenFrame | kRaisedFrame)) {
191 case kSunkenFrame: // pressed
192 gVirtualX->DrawLine(fId, GetBlackGC()(), 0, 0, fWidth-2, 0);
193 gVirtualX->DrawLine(fId, GetBlackGC()(), 0, 0, 0, fHeight-2);
194 gVirtualX->DrawLine(fId, GetShadowGC()(), 1, 1, fWidth-3, 1);
195 gVirtualX->DrawLine(fId, GetShadowGC()(), 1, 1, 1, fHeight-3);
196
197 gVirtualX->DrawLine(fId, GetWhiteGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
198 gVirtualX->DrawLine(fId, GetWhiteGC()(), fWidth-1, fHeight-1, fWidth-1, 1);
199 gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
200 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, fHeight-2, fWidth-2, 2);
201
202 if (fPic) {
203 int x = (fWidth - fPic->GetWidth()) >> 1;
204 int y = (fHeight - fPic->GetHeight()) >> 1;
205 fPic->Draw(fId, GetBckgndGC()(), x+1, y+1); // 3, 3
206 }
207 break;
208
209 case kRaisedFrame: // normal
210 case kButtonDisabled:
211 if (fStyle > 0) {
212 // new modern (flat) version
213 if (fBackground == fHighColor) {
214 gVirtualX->DrawRectangle(fId, GetShadowGC()(), 0, 0, fWidth-1, fHeight-1);
215 }
216 else {
217 if (fPic == 0)
218 gVirtualX->DrawRectangle(fId, GetShadowGC()(), 0, 0, fWidth-1, fHeight-1);
219 else
220 gVirtualX->DrawRectangle(fId, GetBckgndGC()(), 0, 0, fWidth-1, fHeight-1);
221 }
222 if (fParent && fParent->InheritsFrom("TGHScrollBar")) {
223 if (fWidth > 20) {
224 gVirtualX->DrawLine(fId, GetShadowGC()(), (fWidth/2)-3, 4, (fWidth/2)-3, fHeight-5);
225 gVirtualX->DrawLine(fId, GetShadowGC()(), (fWidth/2), 4, (fWidth/2), fHeight-5);
226 gVirtualX->DrawLine(fId, GetShadowGC()(), (fWidth/2)+3, 4, (fWidth/2)+3, fHeight-5);
227 }
228 }
229 else if (fParent && fParent->InheritsFrom("TGVScrollBar")) {
230 if (fHeight > 20) {
231 gVirtualX->DrawLine(fId, GetShadowGC()(), 4, (fHeight/2)-3, fWidth-5, (fHeight/2)-3);
232 gVirtualX->DrawLine(fId, GetShadowGC()(), 4, (fHeight/2) , fWidth-5, (fHeight/2));
233 gVirtualX->DrawLine(fId, GetShadowGC()(), 4, (fHeight/2)+3, fWidth-5, (fHeight/2)+3);
234 }
235 }
236 else { // not used in a scroll bar (e.g. in a combo box)
237 gVirtualX->DrawRectangle(fId, GetShadowGC()(), 0, 0, fWidth-1, fHeight-1);
238 }
239 }
240 else {
241 gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, fWidth-2, 0);
242 gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, 0, fHeight-2);
243 gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, fWidth-3, 1);
244 gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, 1, fHeight-3);
245
246 gVirtualX->DrawLine(fId, GetShadowGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
247 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-2, fHeight-2, fWidth-2, 1);
248 gVirtualX->DrawLine(fId, GetBlackGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
249 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
250 }
251 if (fPic) {
252 int x = (fWidth - fPic->GetWidth()) >> 1;
253 int y = (fHeight - fPic->GetHeight()) >> 1;
254 fPic->Draw(fId, GetBckgndGC()(), x, y); // 2, 2
255 }
256 break;
257
258 default:
259 break;
260 }
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Handle mouse crossing event.
265
267{
268 if (fStyle > 0) {
269 TGScrollBarElement *el = 0;
270 TGScrollBar *bar = 0;
271 if ((event->fType == kEnterNotify) && (fState != kButtonDisabled)) {
273 } else {
275 }
276 if (event->fType == kLeaveNotify) {
278 }
279 gVirtualX->SetWindowBackground(fId, fBgndColor);
281 DrawBorder();
282 if (fParent && fParent->InheritsFrom("TGScrollBar")) {
283 bar = (TGScrollBar *)fParent;
284 if ((el = bar->GetHead()) != this) {
286 el->DrawBorder();
287 }
288 if ((el = bar->GetTail()) != this) {
290 el->DrawBorder();
291 }
292 if ((el = bar->GetSlider()) != this) {
294 el->DrawBorder();
295 }
296 }
297 }
298 return kTRUE;
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// Constructor.
303/// \param p The parent window
304/// \param w The scrollbar width
305/// \param h The scrollbar height
306/// \param options A bitmask of options (see EFrameType)
307/// \param back The background color
308/// \param headPicName Filename of the "head" picture (e.g. left arrow for a horizontal scrollbar)
309/// \param tailPicName Filename of the "tail" picture (e.g. right arrow for a horizontal scrollbar)
311 UInt_t options, Pixel_t back, const char *headPicName, const char *tailPicName) :
312 TGFrame(p, w, h, options | kOwnBackground, back),
313 fX0(0), fY0(0), fXp(0), fYp(0), fDragging(kFALSE), fGrabPointer(kTRUE),
314 fRange(0), fPsize(0), fPos(0), fSliderSize(0), fSliderRange(0),
315 fSmallInc(1), fHead(0), fTail(0), fSlider(0), fHeadPic(0),
316 fTailPic(0), fRepeat(0), fSubw()
317{
319
321 fHighColor = gClient->GetResourcePool()->GetHighLightColor();
322
323 fMsgWindow = p;
324 if (gClient->GetStyle() == 0)
328
329 fHeadPic = fClient->GetPictureOrEmpty(headPicName);
330 fTailPic = fClient->GetPictureOrEmpty(tailPicName);
331
338
341
343 fX0 = fY0 = (fgScrollBarWidth = std::max(fgScrollBarWidth, 5));
344 fPos = 0;
345
346 fSliderSize = 50;
347 fSliderRange = 1;
348
349 fHead->SetEditDisabled(kEditDisable | kEditDisableGrab);
350 fTail->SetEditDisabled(kEditDisable | kEditDisableGrab);
351 fSlider->SetEditDisabled(kEditDisable | kEditDisableGrab);
353}
354
355////////////////////////////////////////////////////////////////////////////////
356/// Delete a scrollbar (either horizontal or vertical).
357
359{
360 delete fHead;
361 delete fTail;
362 delete fSlider;
363 if (fHeadPic) fClient->FreePicture(fHeadPic);
364 if (fTailPic) fClient->FreePicture(fTailPic);
365 if (fRepeat) { delete fRepeat; fRepeat = 0; }
366}
367
368////////////////////////////////////////////////////////////////////////////////
369/// Handle mouse crossing event.
370
372{
373 if (gClient->GetStyle() > 0) {
374 if (event->fType == kEnterNotify) {
376 } else {
378 }
379 if (event->fType == kLeaveNotify) {
381 }
382 fHead->ChangeBackground(fBgndColor);
383 fTail->ChangeBackground(fBgndColor);
384 fSlider->ChangeBackground(fBgndColor);
385 fHead->DrawBorder();
386 fTail->DrawBorder();
387 fSlider->DrawBorder();
388 }
389 return kTRUE;
390}
391
392////////////////////////////////////////////////////////////////////////////////
393/// Handle repeat timer for horizontal or vertical scrollbar. Every time
394/// timer times out we move slider.
395
397{
398 // shorten time out time to 50 milli seconds
399 t->SetTime(50);
400
401 Window_t dum1, dum2;
402 Event_t ev;
403
404 ev.fCode = kButton1;
405 ev.fType = kButtonPress;
406 ev.fUser[0] = fSubw;
407
408 if (IsAccelerated()) {
409 ++fSmallInc;
410 if (fSmallInc > 100) fSmallInc = 100;
411 }
412
413 gVirtualX->QueryPointer(fId, dum1, dum2, ev.fXRoot, ev.fYRoot, ev.fX, ev.fY,
414 ev.fState);
415
416 HandleButton(&ev);
417
418 return kTRUE;
419}
420
421////////////////////////////////////////////////////////////////////////////////
422/// Static method returning scrollbar background pixmap.
423
425{
426 static Bool_t init = kFALSE;
427 if (!init) {
428 fgBckgndPixmap = gClient->GetResourcePool()->GetCheckeredPixmap();
429 init = kTRUE;
430 }
431 return fgBckgndPixmap;
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// Static method returning the scrollbar width.
436
441
442////////////////////////////////////////////////////////////////////////////////
443/// Change background color
444
446{
448 fHead->ChangeBackground(back);
449 fTail->ChangeBackground(back);
450 fSlider->ChangeBackground(back);
451}
452
453////////////////////////////////////////////////////////////////////////////////
454/// Create a horizontal scrollbar widget.
455
457 UInt_t options, ULong_t back) :
458 TGScrollBar(p, w, h, options, back, "arrow_left.xpm", "arrow_right.xpm")
459{
460 fRange = std::max((Int_t) w - (fgScrollBarWidth << 1), 1);
461 fPsize = fRange >> 1;
463}
464
465////////////////////////////////////////////////////////////////////////////////
466/// Layout and move horizontal scrollbar components.
467
469{
470 // Should also recalculate the slider size and range, etc.
471 fHead->Move(0, 0);
473 fTail->Move(fWidth-fgScrollBarWidth, 0);
475
476 if (fSlider->GetX() != fX0) {
477 fSlider->Move(fX0, 0);
478 fSlider->Resize(50, fgScrollBarWidth);
479 fClient->NeedRedraw(fSlider);
480 }
481}
482
483////////////////////////////////////////////////////////////////////////////////
484/// Handle a mouse button event in a horizontal scrolbar.
485
487{
488 Int_t newpos;
489
490 if (event->fCode == kButton4) {
491 if (!fHead->IsEnabled()) {
492 return kFALSE;
493 }
494 //scroll left
495 newpos = fPos - fPsize;
496 if (newpos<0) newpos = 0;
497 SetPosition(newpos);
498 return kTRUE;
499 }
500 if (event->fCode == kButton5) {
501 if (!fTail->IsEnabled()) {
502 return kFALSE;
503 }
504 // scroll right
505 newpos = fPos + fPsize;
506 SetPosition(newpos);
507 return kTRUE;
508 }
509
510 if (event->fType == kButtonPress) {
511 if (event->fCode == kButton3) {
512 fX0 = event->fX - fSliderSize/2;
513 fX0 = std::max(fX0, fgScrollBarWidth);
514 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
516 fPos = (Int_t)pos;
517
518 fPos = std::max(fPos, 0);
519 fPos = std::min(fPos, fRange-fPsize);
520 fSlider->Move(fX0, 0);
521
524 return kTRUE;
525 }
526
527 // fUser[0] contains the subwindow (child) in which the event occurred
528 // (see GX11Gui.cxx)
529 Window_t subw = (Window_t)event->fUser[0];
530
531 if (subw == fSlider->GetId()) {
532 fXp = event->fX - fX0;
533 fYp = event->fY - fY0;
535
536 } else {
537
538 if (!fRepeat)
539 fRepeat = new TSBRepeatTimer(this, 400, fSmallInc); // 500
540 fRepeat->Reset();
541 gSystem->AddTimer(fRepeat);
542 fSubw = subw;
543
544 if (subw == fHead->GetId()) {
545 //if (!fHead->IsEnabled()) {
546 // return kFALSE;
547 //}
548 fHead->SetState(kButtonDown);
549 fPos -= fSmallInc;
550 } else if (subw == fTail->GetId()) {
551 //if (!fTail->IsEnabled()) {
552 // return kFALSE;
553 // }
554 fTail->SetState(kButtonDown);
555 fPos += fSmallInc;
556 } else if (event->fX > fgScrollBarWidth && event->fX < fX0)
557 fPos -= fPsize;
558 else if (event->fX > fX0+fSliderSize && event->fX < (Int_t)fWidth-fgScrollBarWidth)
559 fPos += fPsize;
560
561 fPos = std::max(fPos, 0);
562 fPos = std::min(fPos, fRange-fPsize);
563
564 fX0 = fgScrollBarWidth + fPos * fSliderRange / std::max(fRange-fPsize, 1);
565
566 fX0 = std::max(fX0, fgScrollBarWidth);
567 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
568
569 fSlider->Move(fX0, 0);
570
573 }
574
575 // last argument kFALSE forces all specified events to this window
576 if (fGrabPointer && !fClient->IsEditable())
579 kTRUE, kFALSE);
580 } else {
581 fHead->SetState(kButtonUp);
582 fTail->SetState(kButtonUp);
583
584 if (fRepeat) {
585 fRepeat->Remove();
586 fRepeat->SetTime(400); // might have been shortened in HandleTimer()
587 fSmallInc = ((TSBRepeatTimer*)fRepeat)->GetSmallInc();
588 }
589
591
592 fPos = std::max(fPos, 0);
593 fPos = std::min(fPos, fRange-fPsize);
594
597
598 if (fGrabPointer)
599 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
600 }
601 return kTRUE;
602}
603
604////////////////////////////////////////////////////////////////////////////////
605/// Handle mouse motion event in a horizontal scrollbar.
606
608{
609 if (fDragging) {
610 fX0 = event->fX - fXp;
611 fY0 = event->fY - fYp;
612
613 fX0 = std::max(fX0, fgScrollBarWidth);
614 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
615 fSlider->Move(fX0, 0);
617 fPos = (Int_t)pos;
618
619 fPos = std::max(fPos, 0);
620 fPos = std::min(fPos, fRange-fPsize);
621
624 }
625 return kTRUE;
626}
627
628////////////////////////////////////////////////////////////////////////////////
629/// Set range of horizontal scrollbar.
630
631void TGHScrollBar::SetRange(Int_t range, Int_t page_size)
632{
633 fRange = std::max(range, 1);
634 fPsize = std::max(page_size, 0);
635 fPos = std::max(fPos, 0);
636 fPos = std::min(fPos, fRange-fPsize);
637
638 fSliderSize = std::max(fPsize * (fWidth - (fgScrollBarWidth << 1)) /
639 fRange, (UInt_t) 6);
641
642 fSliderRange = std::max(fWidth - (fgScrollBarWidth << 1) - fSliderSize,
643 (UInt_t) 1);
644
645 fX0 = fgScrollBarWidth + fPos * fSliderRange / std::max(fRange-fPsize, 1);
646 fX0 = std::max(fX0, fgScrollBarWidth);
647 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
648
649 fSlider->Move(fX0, 0);
651 fClient->NeedRedraw(fSlider);
652
653 // fPos = (fX0 - fgScrollBarWidth) * (fRange-fPsize) / fSliderRange;
654
659}
660
661////////////////////////////////////////////////////////////////////////////////
662/// Set logical slider position of horizontal scrollbar.
663
665{
666 fPos = std::max(pos, 0);
667 fPos = std::min(pos, fRange-fPsize);
668
669 fX0 = fgScrollBarWidth + fPos * fSliderRange / std::max(fRange-fPsize, 1);
670 fX0 = std::max(fX0, fgScrollBarWidth);
671 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
672
673 fSlider->Move(fX0, 0);
675 fClient->NeedRedraw(fSlider);
676
679}
680
681
682////////////////////////////////////////////////////////////////////////////////
683/// Create a vertical scrollbar.
684
686 UInt_t options, ULong_t back) :
687 TGScrollBar(p, w, h, options, back, "arrow_up.xpm", "arrow_down.xpm")
688{
689 fRange = std::max((Int_t) h - (fgScrollBarWidth << 1), 1);
690 fPsize = fRange >> 1;
692}
693
694////////////////////////////////////////////////////////////////////////////////
695/// Layout and move vertical scrollbar components.
696
698{
699 // Should recalculate fSliderSize, fSliderRange, fX0, fY0, etc. too...
700 fHead->Move(0, 0);
704
705 if (fSlider->GetY() != fY0) {
706 fSlider->Move(0, fY0);
707 fSlider->Resize(fgScrollBarWidth, 50);
708 fClient->NeedRedraw(fSlider);
709 }
710}
711
712////////////////////////////////////////////////////////////////////////////////
713/// Handle mouse button event in vertical scrollbar.
714
716{
717 Int_t newpos;
718
719 if (event->fCode == kButton4) {
720 if (!fHead->IsEnabled()) {
721 return kFALSE;
722 }
723 //scroll up
724 newpos = fPos - fPsize;
725 if (newpos<0) newpos = 0;
726 SetPosition(newpos);
727 return kTRUE;
728 }
729 if (event->fCode == kButton5) {
730 if (!fTail->IsEnabled()) {
731 return kFALSE;
732 }
733
734 // scroll down
735 newpos = fPos + fPsize;
736 SetPosition(newpos);
737 return kTRUE;
738 }
739
740 if (event->fType == kButtonPress) {
741 if (event->fCode == kButton3) {
742 fY0 = event->fY - fSliderSize/2;
743 fY0 = std::max(fY0, fgScrollBarWidth);
744 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
746 fPos = (Int_t)pos;
747
748 fPos = std::max(fPos, 0);
749 fPos = std::min(fPos, fRange-fPsize);
750 fSlider->Move(0, fY0);
751
754 return kTRUE;
755 }
756
757 // fUser[0] contains the subwindow (child) in which the event occurred
758 // (see GX11Gui.cxx)
759 Window_t subw = (Window_t)event->fUser[0];
760
761 if (subw == fSlider->GetId()) {
762 fXp = event->fX - fX0;
763 fYp = event->fY - fY0;
765
766 } else {
767
768 if (!fRepeat)
769 fRepeat = new TSBRepeatTimer(this, 400, fSmallInc); // 500
770 fRepeat->Reset();
771 gSystem->AddTimer(fRepeat);
772 fSubw = subw;
773
774 if (subw == fHead->GetId()) {
775 //if (!fHead->IsEnabled()) {
776 // return kFALSE;
777 // }
778 fHead->SetState(kButtonDown);
779 fPos -= fSmallInc;
780 } else if (subw == fTail->GetId()) {
781 //if (!fTail->IsEnabled()) {
782 // return kFALSE;
783 //}
784 fTail->SetState(kButtonDown);
785 fPos += fSmallInc;
786 } else if (event->fY > fgScrollBarWidth && event->fY < fY0)
787 fPos -= fPsize;
788 else if (event->fY > fY0+fSliderSize && event->fY < (Int_t)fHeight-fgScrollBarWidth)
789 fPos += fPsize;
790
791 fPos = std::max(fPos, 0);
792 fPos = std::min(fPos, fRange-fPsize);
793
795 fY0 = (Int_t)y0;
796
797 fY0 = std::max(fY0, fgScrollBarWidth);
798 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
799
800 fSlider->Move(0, fY0);
801
804 }
805
806 // last argument kFALSE forces all specified events to this window
807 if (fGrabPointer && !fClient->IsEditable())
810 kTRUE, kFALSE);
811 } else {
812 fHead->SetState(kButtonUp);
813 fTail->SetState(kButtonUp);
814
815 if (fRepeat) {
816 fRepeat->Remove();
817 fRepeat->SetTime(400); // might have been shortened in HandleTimer()
818 fSmallInc = ((TSBRepeatTimer*)fRepeat)->GetSmallInc();
819 }
820
822
823 fPos = std::max(fPos, 0);
824 fPos = std::min(fPos, fRange-fPsize);
825
828
829 if (fGrabPointer) {
830 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
831 }
832 }
833 return kTRUE;
834}
835
836////////////////////////////////////////////////////////////////////////////////
837/// Handle mouse motion in a vertical scrollbar.
838
840{
841 if (fDragging) {
842 fX0 = event->fX - fXp;
843 fY0 = event->fY - fYp;
844
845 fY0 = std::max(fY0, fgScrollBarWidth);
846 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
847 fSlider->Move(0, fY0);
849 fPos = (Int_t)pos;
850
851 fPos = std::max(fPos, 0);
852 fPos = std::min(fPos, fRange-fPsize);
853
856 }
857 return kTRUE;
858}
859
860////////////////////////////////////////////////////////////////////////////////
861/// Set range of vertical scrollbar.
862
863void TGVScrollBar::SetRange(Int_t range, Int_t page_size)
864{
865 fRange = std::max(range, 1);
866 fPsize = std::max(page_size, 0);
867 fPos = std::max(fPos, 0);
868 fPos = std::min(fPos, fRange-fPsize);
869
870 fSliderSize = std::max(fPsize * (fHeight - (fgScrollBarWidth << 1)) /
871 fRange, (UInt_t) 6);
873
874 fSliderRange = std::max(fHeight - (fgScrollBarWidth << 1) - fSliderSize,
875 (UInt_t)1);
876
878 fY0 = (Int_t)y0;
879 fY0 = std::max(fY0, fgScrollBarWidth);
880 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
881
882 fSlider->Move(0, fY0);
884 fClient->NeedRedraw(fSlider);
885
886 // fPos = (fY0 - fgScrollBarWidth) * (fRange-fPsize) / fSliderRange;
887
888
893}
894
895////////////////////////////////////////////////////////////////////////////////
896/// Set logical slider position of vertical scrollbar.
897
899{
900 fPos = std::max(pos, 0);
901 fPos = std::min(pos, fRange-fPsize);
902
904 fY0 = (Int_t)y0;
905 fY0 = std::max(fY0, fgScrollBarWidth);
906 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
907
908 fSlider->Move(0, fY0);
910 fClient->NeedRedraw(fSlider);
911
914}
915
916////////////////////////////////////////////////////////////////////////////////
917/// Save an horizontal scrollbar as a C++ statement(s) on output stream out.
918
919void TGHScrollBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
920{
921 // save options and custom color if not default
922 auto extra_args = SaveCtorArgs(out);
923
924 out << " TGHScrollBar *" << GetName() << " = new TGHScrollBar(" << fParent->GetName() << "," << GetWidth() << ","
925 << GetHeight() << extra_args << ");\n";
926
927 if (option && strstr(option, "keep_names"))
928 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
929
930 out << " " << GetName() << "->SetRange(" << GetRange() << "," << GetPageSize() << ");\n";
931 out << " " << GetName() << "->SetPosition(" << GetPosition() << ");\n";
932}
933
934////////////////////////////////////////////////////////////////////////////////
935/// Save an vertical scrollbar as a C++ statement(s) on output stream out.
936
937void TGVScrollBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
938{
939 // save options and custom color if not default
940 auto extra_args = SaveCtorArgs(out);
941
942 out << " TGVScrollBar *" << GetName() << " = new TGVScrollBar(" << fParent->GetName() << "," << GetWidth() << ","
943 << GetHeight() << extra_args << ");\n";
944
945 if (option && strstr(option, "keep_names"))
946 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
947
948 out << " " << GetName() << "->SetRange(" << GetRange() << "," << GetPageSize() << ");\n";
949 out << " " << GetName() << "->SetPosition(" << GetPosition() << ");\n";
950}
@ kButtonPress
Definition GuiTypes.h:61
@ kEnterNotify
Definition GuiTypes.h:62
@ kLeaveNotify
Definition GuiTypes.h:62
const Mask_t kButtonPressMask
Definition GuiTypes.h:162
const Mask_t kAnyModifier
Definition GuiTypes.h:211
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:31
const Mask_t kPointerMotionMask
Definition GuiTypes.h:164
@ kRaisedFrame
Definition GuiTypes.h:385
@ kSunkenFrame
Definition GuiTypes.h:384
@ kOwnBackground
Definition GuiTypes.h:392
const Handle_t kNone
Definition GuiTypes.h:89
const Mask_t kLeaveWindowMask
Definition GuiTypes.h:169
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:163
const Mask_t kEnterWindowMask
Definition GuiTypes.h:168
@ kDefaultScrollBarWidth
Definition GuiTypes.h:87
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
@ kButton4
Definition GuiTypes.h:216
@ kButton5
Definition GuiTypes.h:216
@ kButton3
Definition GuiTypes.h:215
@ kButton1
Definition GuiTypes.h:215
@ kAnyButton
Definition GuiTypes.h:215
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
externTEnv * gEnv
Definition TEnv.h:170
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:157
char name[80]
Definition TGX11.cxx:148
externTSystem * gSystem
Definition TSystem.h:582
#define gVirtualX
Definition TVirtualX.h:375
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kSB_SLIDERTRACK
@ kSB_SLIDERPOS
@ kC_VSCROLL
@ kC_HSCROLL
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:331
static const TGGC & GetBlackGC()
Get black graphics context.
Definition TGFrame.cxx:727
UInt_t fOptions
frame options
Definition TGFrame.h:94
TGFrame(const TGFrame &)=delete
UInt_t fHeight
frame height
Definition TGFrame.h:88
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:422
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:747
virtual void ChangeBackground(Pixel_t back)
Change frame background color.
Definition TGFrame.cxx:285
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:637
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:757
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
TString SaveCtorArgs(std::ostream &out, UInt_t dflt_options=kChildFrame, Bool_t check_white_pixel=kFALSE)
Return options and custom color as constructor args Used in the SavePrimitive methods,...
Definition TGFrame.cxx:2493
static const TGGC & GetWhiteGC()
Get white graphics context.
Definition TGFrame.cxx:737
UInt_t GetWidth() const
Definition TGFrame.h:226
Pixel_t fBackground
frame background color
Definition TGFrame.h:95
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:767
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save an horizontal scrollbar as a C++ statement(s) on output stream out.
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion event in a horizontal scrollbar.
void Layout() override
Layout and move horizontal scrollbar components.
Bool_t HandleButton(Event_t *event) override
Handle a mouse button event in a horizontal scrolbar.
void SetRange(Int_t range, Int_t page_size) override
Set range of horizontal scrollbar.
TGHScrollBar(const TGWindow *p=nullptr, UInt_t w=4, UInt_t h=2, UInt_t options=kHorizontalFrame, Pixel_t back=GetDefaultFrameBackground())
Create a horizontal scrollbar widget.
void SetPosition(Int_t pos) override
Set logical slider position of horizontal scrollbar.
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
~TGScrollBarElement() override
destructor
const TGPicture * fPic
picture in scrollbar element
Definition TGScrollBar.h:37
Pixel_t fBgndColor
background color
Definition TGScrollBar.h:40
void DrawBorder() override
Draw border around scollbar element.
const TGPicture * fPicD
picture for disabled state of scrollbar element
Definition TGScrollBar.h:39
Int_t fStyle
modern or classic style
Definition TGScrollBar.h:42
virtual void SetEnabled(Bool_t on=kTRUE)
Enable/Disable scroll bar button chaging the state.
virtual void SetState(Int_t state)
Change state of scrollbar element (either up or down).
Pixel_t fHighColor
highlight color
Definition TGScrollBar.h:41
const TGPicture * fPicN
picture for normal state of scrollbar element
Definition TGScrollBar.h:38
Int_t fState
state of scrollbar element (button up or down)
Definition TGScrollBar.h:36
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
TGScrollBarElement(const TGScrollBarElement &)=delete
The classes in this file implement scrollbars.
Definition TGScrollBar.h:61
virtual void RangeChanged(Int_t range)
static Pixmap_t fgBckgndPixmap
Definition TGScrollBar.h:89
TTimer * fRepeat
repeat rate timer (when mouse stays pressed)
Definition TGScrollBar.h:83
TGScrollBarElement * GetTail() const
Int_t fPsize
logical page size of scrollbar
Definition TGScrollBar.h:73
Bool_t IsAccelerated() const
static Pixmap_t GetBckgndPixmap()
Static method returning scrollbar background pixmap.
Bool_t fAccelerated
kFALSE - normal, kTRUE - accelerated
Definition TGScrollBar.h:85
Int_t fSliderSize
logical slider size
Definition TGScrollBar.h:75
static Int_t fgScrollBarWidth
Definition TGScrollBar.h:90
Bool_t fDragging
in dragging mode?
Definition TGScrollBar.h:70
virtual Int_t GetRange() const
const TGPicture * fTailPic
picture in tail (down or right arrow)
Definition TGScrollBar.h:82
Bool_t HandleButton(Event_t *event) override=0
TGScrollBarElement * GetSlider() const
TGScrollBarElement * fSlider
slider
Definition TGScrollBar.h:80
TGScrollBarElement * GetHead() const
virtual void PageSizeChanged(Int_t range)
Int_t fY0
current slider position in pixels
Definition TGScrollBar.h:68
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
virtual Int_t GetPageSize() const
virtual Int_t GetPosition() const
Window_t fSubw
sub window in which mouse is pressed
Definition TGScrollBar.h:84
static Int_t GetScrollBarWidth()
Static method returning the scrollbar width.
Int_t fSmallInc
Small Increment in the sliding algorithm.
Definition TGScrollBar.h:77
Bool_t fGrabPointer
grab pointer when dragging
Definition TGScrollBar.h:71
Int_t fPos
logical current position
Definition TGScrollBar.h:74
Pixel_t fBgndColor
background color
Definition TGScrollBar.h:86
TGScrollBarElement * fHead
head button of scrollbar
Definition TGScrollBar.h:78
Int_t fYp
previous slider position in pixels
Definition TGScrollBar.h:69
void ChangeBackground(Pixel_t back) override
Change background color.
Pixel_t fHighColor
highlight color
Definition TGScrollBar.h:87
Bool_t HandleTimer(TTimer *t) override
Handle repeat timer for horizontal or vertical scrollbar.
TGScrollBar(const TGScrollBar &)=delete
TGScrollBarElement * fTail
tail button of scrollbar
Definition TGScrollBar.h:79
Int_t fRange
logical upper range of scrollbar
Definition TGScrollBar.h:72
Int_t fSliderRange
logical slider range
Definition TGScrollBar.h:76
virtual void PositionChanged(Int_t pos)
~TGScrollBar() override
Delete a scrollbar (either horizontal or vertical).
const TGPicture * fHeadPic
picture in head (up or left arrow)
Definition TGScrollBar.h:81
TGVScrollBar(const TGWindow *p=nullptr, UInt_t w=2, UInt_t h=4, UInt_t options=kVerticalFrame, Pixel_t back=GetDefaultFrameBackground())
Create a vertical scrollbar.
void SetRange(Int_t range, Int_t page_size) override
Set range of vertical scrollbar.
void SetPosition(Int_t pos) override
Set logical slider position of vertical scrollbar.
Bool_t HandleButton(Event_t *event) override
Handle mouse button event in vertical scrollbar.
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion in a vertical scrollbar.
void Layout() override
Layout and move vertical scrollbar components.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save an vertical scrollbar as a C++ statement(s) on output stream out.
const TGWindow * fMsgWindow
window which handles widget events
Definition TGWidget.h:48
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition TGWindow.cxx:246
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
@ kEditDisableHeight
window height cannot be edited
Definition TGWindow.h:62
@ kEditDisableLayout
window layout cannot be edited
Definition TGWindow.h:60
@ kEditDisableBtnEnable
window can handle mouse button events
Definition TGWindow.h:64
@ kEditDisableWidth
window width cannot be edited
Definition TGWindow.h:63
@ kEditDisableGrab
window grab cannot be edited
Definition TGWindow.h:59
@ kEditDisable
disable edit of this window
Definition TGWindow.h:57
TGWindow(Window_t id)
Definition TGWindow.h:34
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:127
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:334
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
An abstract interface to image processing library.
Definition TImage.h:29
virtual void FillRectangle(const char *=nullptr, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition TImage.h:192
static TImage * Create()
Create an image.
Definition TImage.cxx:34
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition TImage.h:172
virtual Pixmap_t GetPixmap()
Definition TImage.h:236
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=nullptr)
Definition TImage.h:116
virtual Pixmap_t GetMask()
Definition TImage.h:237
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
Bool_t Notify() override
Notify when timer times out and reset the timer.
TSBRepeatTimer(TGScrollBar *s, Long_t ms, Int_t inc)
Int_t GetSmallInc() const
TGScrollBar * fScrollBar
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:162
void SetTime(Long_t milliSec)
Definition TTimer.h:91
TTimer(const TTimer &)=delete
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Event structure.
Definition GuiTypes.h:175
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:176
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:179
Int_t fXRoot
Definition GuiTypes.h:180
UInt_t fState
key or button mask
Definition GuiTypes.h:182
Int_t fYRoot
coordinates relative to root
Definition GuiTypes.h:180
Int_t fX
Definition GuiTypes.h:179
UInt_t fCode
key or button code
Definition GuiTypes.h:181
Longptr_t fUser[5]
5 longs can be used by client message events NOTE: only [0], [1] and [2] may be used.
Definition GuiTypes.h:188