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
29
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 "TASUtils.h"
55#include "TSystem.h"
56#include "TTimer.h"
57#include "TEnv.h"
58#include "TVirtualX.h"
59
60#include <iostream>
61
62
65
66
67
68////////////////////////////////////////////////////////////////////////////////
69
70class TSBRepeatTimer : public TTimer {
71private:
72 TGScrollBar *fScrollBar; // scroll bar
74public:
76 { fScrollBar = s; fSmallInc = inc; }
77
78 Bool_t Notify() override;
79 Int_t GetSmallInc() const { return fSmallInc; }
80};
81
82////////////////////////////////////////////////////////////////////////////////
83/// Notify when timer times out and reset the timer.
84
86{
88 Reset();
89 return kFALSE;
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Constructor.
94
96 UInt_t w, UInt_t h, UInt_t options, Pixel_t back) :
97 TGFrame(p, w, h, options | kOwnBackground, back)
98{
99 fPic = fPicN = pic;
101 fPicD = 0;
102 fStyle = 0;
103 if ((gClient->GetStyle() > 1) || (p && p->InheritsFrom("TGScrollBar")))
104 fStyle = gClient->GetStyle();
105
107 fHighColor = gClient->GetResourcePool()->GetHighLightColor();
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// destructor
113
120
121////////////////////////////////////////////////////////////////////////////////
122/// Change state of scrollbar element (either up or down).
123
125{
126 if (state != fState) {
127 switch (state) {
128 case kButtonDown:
129 fOptions &= ~kRaisedFrame;
131 break;
132 case kButtonUp:
133 case kButtonDisabled:
134 fOptions &= ~kSunkenFrame;
136 break;
137 }
138 fState = state;
139 fClient->NeedRedraw(this);
140 }
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Enable/Disable scroll bar button chaging the state.
145
147{
148 if (on) {
149 if (fState == kButtonUp) {
150 return;
151 }
153 fPic = fPicN;
154 } else {
155 if (fState == kButtonDisabled) {
156 return;
157 }
159
160 if (!fPicD) {
161 std::unique_ptr<TImage> img2(TImage::Create());
162 if (!img2)
163 return;
164 TString back = gEnv->GetValue("Gui.BackgroundColor", "#c0c0c0");
165 img2->FillRectangle(back.Data(), 0, 0, fPic->GetWidth(), fPic->GetHeight());
167 if (!img)
168 return;
169 Pixmap_t mask = TASUtils::GetMask(img.get());
170 img2->Merge(img.get(), "overlay");
171
172 TString name = "disbl_";
173 name += fPic->GetName();
175 mask);
176 }
177 fPic = fPicD;
178 }
179 fClient->NeedRedraw(this);
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Draw border around scollbar element.
184
186{
187 switch (fOptions & (kSunkenFrame | kRaisedFrame)) {
188 case kSunkenFrame: // pressed
189 gVirtualX->DrawLine(fId, GetBlackGC()(), 0, 0, fWidth-2, 0);
190 gVirtualX->DrawLine(fId, GetBlackGC()(), 0, 0, 0, fHeight-2);
191 gVirtualX->DrawLine(fId, GetShadowGC()(), 1, 1, fWidth-3, 1);
192 gVirtualX->DrawLine(fId, GetShadowGC()(), 1, 1, 1, fHeight-3);
193
194 gVirtualX->DrawLine(fId, GetWhiteGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
195 gVirtualX->DrawLine(fId, GetWhiteGC()(), fWidth-1, fHeight-1, fWidth-1, 1);
196 gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
197 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, fHeight-2, fWidth-2, 2);
198
199 if (fPic) {
200 int x = (fWidth - fPic->GetWidth()) >> 1;
201 int y = (fHeight - fPic->GetHeight()) >> 1;
202 fPic->Draw(fId, GetBckgndGC()(), x+1, y+1); // 3, 3
203 }
204 break;
205
206 case kRaisedFrame: // normal
207 case kButtonDisabled:
208 if (fStyle > 0) {
209 // new modern (flat) version
210 if (fBackground == fHighColor) {
211 gVirtualX->DrawRectangle(fId, GetShadowGC()(), 0, 0, fWidth-1, fHeight-1);
212 }
213 else {
214 if (fPic == 0)
215 gVirtualX->DrawRectangle(fId, GetShadowGC()(), 0, 0, fWidth-1, fHeight-1);
216 else
217 gVirtualX->DrawRectangle(fId, GetBckgndGC()(), 0, 0, fWidth-1, fHeight-1);
218 }
219 if (fParent && fParent->InheritsFrom("TGHScrollBar")) {
220 if (fWidth > 20) {
221 gVirtualX->DrawLine(fId, GetShadowGC()(), (fWidth/2)-3, 4, (fWidth/2)-3, fHeight-5);
222 gVirtualX->DrawLine(fId, GetShadowGC()(), (fWidth/2), 4, (fWidth/2), fHeight-5);
223 gVirtualX->DrawLine(fId, GetShadowGC()(), (fWidth/2)+3, 4, (fWidth/2)+3, fHeight-5);
224 }
225 }
226 else if (fParent && fParent->InheritsFrom("TGVScrollBar")) {
227 if (fHeight > 20) {
228 gVirtualX->DrawLine(fId, GetShadowGC()(), 4, (fHeight/2)-3, fWidth-5, (fHeight/2)-3);
229 gVirtualX->DrawLine(fId, GetShadowGC()(), 4, (fHeight/2) , fWidth-5, (fHeight/2));
230 gVirtualX->DrawLine(fId, GetShadowGC()(), 4, (fHeight/2)+3, fWidth-5, (fHeight/2)+3);
231 }
232 }
233 else { // not used in a scroll bar (e.g. in a combo box)
234 gVirtualX->DrawRectangle(fId, GetShadowGC()(), 0, 0, fWidth-1, fHeight-1);
235 }
236 }
237 else {
238 gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, fWidth-2, 0);
239 gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, 0, fHeight-2);
240 gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, fWidth-3, 1);
241 gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, 1, fHeight-3);
242
243 gVirtualX->DrawLine(fId, GetShadowGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
244 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-2, fHeight-2, fWidth-2, 1);
245 gVirtualX->DrawLine(fId, GetBlackGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
246 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
247 }
248 if (fPic) {
249 int x = (fWidth - fPic->GetWidth()) >> 1;
250 int y = (fHeight - fPic->GetHeight()) >> 1;
251 fPic->Draw(fId, GetBckgndGC()(), x, y); // 2, 2
252 }
253 break;
254
255 default:
256 break;
257 }
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Handle mouse crossing event.
262
264{
265 if (fStyle > 0) {
266 TGScrollBarElement *el = 0;
267 TGScrollBar *bar = 0;
268 if ((event->fType == kEnterNotify) && (fState != kButtonDisabled)) {
270 } else {
272 }
273 if (event->fType == kLeaveNotify) {
275 }
276 gVirtualX->SetWindowBackground(fId, fBgndColor);
278 DrawBorder();
279 if (fParent && fParent->InheritsFrom("TGScrollBar")) {
280 bar = (TGScrollBar *)fParent;
281 if ((el = bar->GetHead()) != this) {
283 el->DrawBorder();
284 }
285 if ((el = bar->GetTail()) != this) {
287 el->DrawBorder();
288 }
289 if ((el = bar->GetSlider()) != this) {
291 el->DrawBorder();
292 }
293 }
294 }
295 return kTRUE;
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Constructor.
300/// \param p The parent window
301/// \param w The scrollbar width
302/// \param h The scrollbar height
303/// \param options A bitmask of options (see EFrameType)
304/// \param back The background color
305/// \param headPicName Filename of the "head" picture (e.g. left arrow for a horizontal scrollbar)
306/// \param tailPicName Filename of the "tail" picture (e.g. right arrow for a horizontal scrollbar)
308 UInt_t options, Pixel_t back, const char *headPicName, const char *tailPicName) :
309 TGFrame(p, w, h, options | kOwnBackground, back),
310 fX0(0), fY0(0), fXp(0), fYp(0), fDragging(kFALSE), fGrabPointer(kTRUE),
311 fRange(0), fPsize(0), fPos(0), fSliderSize(0), fSliderRange(0),
312 fSmallInc(1), fHead(0), fTail(0), fSlider(0), fHeadPic(0),
313 fTailPic(0), fRepeat(0), fSubw()
314{
316
318 fHighColor = gClient->GetResourcePool()->GetHighLightColor();
319
320 fMsgWindow = p;
321 if (gClient->GetStyle() == 0)
325
326 fHeadPic = fClient->GetPictureOrEmpty(headPicName);
327 fTailPic = fClient->GetPictureOrEmpty(tailPicName);
328
335
338
340 fX0 = fY0 = (fgScrollBarWidth = std::max(fgScrollBarWidth, 5));
341 fPos = 0;
342
343 fSliderSize = 50;
344 fSliderRange = 1;
345
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// Delete a scrollbar (either horizontal or vertical).
354
356{
357 delete fHead;
358 delete fTail;
359 delete fSlider;
362 if (fRepeat) { delete fRepeat; fRepeat = 0; }
363}
364
365////////////////////////////////////////////////////////////////////////////////
366/// Handle mouse crossing event.
367
369{
370 if (gClient->GetStyle() > 0) {
371 if (event->fType == kEnterNotify) {
373 } else {
375 }
376 if (event->fType == kLeaveNotify) {
378 }
382 fHead->DrawBorder();
383 fTail->DrawBorder();
385 }
386 return kTRUE;
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// Handle repeat timer for horizontal or vertical scrollbar. Every time
391/// timer times out we move slider.
392
394{
395 // shorten time out time to 50 milli seconds
396 t->SetTime(50);
397
398 Window_t dum1, dum2;
399 Event_t ev;
400
401 ev.fCode = kButton1;
402 ev.fType = kButtonPress;
403 ev.fUser[0] = fSubw;
404
405 if (IsAccelerated()) {
406 ++fSmallInc;
407 if (fSmallInc > 100) fSmallInc = 100;
408 }
409
410 gVirtualX->QueryPointer(fId, dum1, dum2, ev.fXRoot, ev.fYRoot, ev.fX, ev.fY,
411 ev.fState);
412
413 HandleButton(&ev);
414
415 return kTRUE;
416}
417
418////////////////////////////////////////////////////////////////////////////////
419/// Static method returning scrollbar background pixmap.
420
422{
423 static Bool_t init = kFALSE;
424 if (!init) {
425 fgBckgndPixmap = gClient->GetResourcePool()->GetCheckeredPixmap();
426 init = kTRUE;
427 }
428 return fgBckgndPixmap;
429}
430
431////////////////////////////////////////////////////////////////////////////////
432/// Static method returning the scrollbar width.
433
438
439////////////////////////////////////////////////////////////////////////////////
440/// Change background color
441
449
450////////////////////////////////////////////////////////////////////////////////
451/// Create a horizontal scrollbar widget.
452
454 UInt_t options, ULong_t back) :
455 TGScrollBar(p, w, h, options, back, "arrow_left.xpm", "arrow_right.xpm")
456{
457 fRange = std::max((Int_t) w - (fgScrollBarWidth << 1), 1);
458 fPsize = fRange >> 1;
460}
461
462////////////////////////////////////////////////////////////////////////////////
463/// Layout and move horizontal scrollbar components.
464
466{
467 // Should also recalculate the slider size and range, etc.
468 fHead->Move(0, 0);
472
473 if (fSlider->GetX() != fX0) {
474 fSlider->Move(fX0, 0);
477 }
478}
479
480////////////////////////////////////////////////////////////////////////////////
481/// Handle a mouse button event in a horizontal scrolbar.
482
484{
485 Int_t newpos;
486
487 if (event->fCode == kButton4) {
488 if (!fHead->IsEnabled()) {
489 return kFALSE;
490 }
491 //scroll left
492 newpos = fPos - fPsize;
493 if (newpos<0) newpos = 0;
494 SetPosition(newpos);
495 return kTRUE;
496 }
497 if (event->fCode == kButton5) {
498 if (!fTail->IsEnabled()) {
499 return kFALSE;
500 }
501 // scroll right
502 newpos = fPos + fPsize;
503 SetPosition(newpos);
504 return kTRUE;
505 }
506
507 if (event->fType == kButtonPress) {
508 if (event->fCode == kButton3) {
509 fX0 = event->fX - fSliderSize/2;
510 fX0 = std::max(fX0, fgScrollBarWidth);
511 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
513 fPos = (Int_t)pos;
514
515 fPos = std::max(fPos, 0);
516 fPos = std::min(fPos, fRange-fPsize);
517 fSlider->Move(fX0, 0);
518
521 return kTRUE;
522 }
523
524 // fUser[0] contains the subwindow (child) in which the event occurred
525 // (see GX11Gui.cxx)
526 Window_t subw = (Window_t)event->fUser[0];
527
528 if (subw == fSlider->GetId()) {
529 fXp = event->fX - fX0;
530 fYp = event->fY - fY0;
532
533 } else {
534
535 if (!fRepeat)
536 fRepeat = new TSBRepeatTimer(this, 400, fSmallInc); // 500
537 fRepeat->Reset();
539 fSubw = subw;
540
541 if (subw == fHead->GetId()) {
542 //if (!fHead->IsEnabled()) {
543 // return kFALSE;
544 //}
546 fPos -= fSmallInc;
547 } else if (subw == fTail->GetId()) {
548 //if (!fTail->IsEnabled()) {
549 // return kFALSE;
550 // }
552 fPos += fSmallInc;
553 } else if (event->fX > fgScrollBarWidth && event->fX < fX0)
554 fPos -= fPsize;
555 else if (event->fX > fX0+fSliderSize && event->fX < (Int_t)fWidth-fgScrollBarWidth)
556 fPos += fPsize;
557
558 fPos = std::max(fPos, 0);
559 fPos = std::min(fPos, fRange-fPsize);
560
561 fX0 = fgScrollBarWidth + fPos * fSliderRange / std::max(fRange-fPsize, 1);
562
563 fX0 = std::max(fX0, fgScrollBarWidth);
564 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
565
566 fSlider->Move(fX0, 0);
567
570 }
571
572 // last argument kFALSE forces all specified events to this window
576 kTRUE, kFALSE);
577 } else {
580
581 if (fRepeat) {
582 fRepeat->Remove();
583 fRepeat->SetTime(400); // might have been shortened in HandleTimer()
584 fSmallInc = ((TSBRepeatTimer*)fRepeat)->GetSmallInc();
585 }
586
588
589 fPos = std::max(fPos, 0);
590 fPos = std::min(fPos, fRange-fPsize);
591
594
595 if (fGrabPointer)
596 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
597 }
598 return kTRUE;
599}
600
601////////////////////////////////////////////////////////////////////////////////
602/// Handle mouse motion event in a horizontal scrollbar.
603
605{
606 if (fDragging) {
607 fX0 = event->fX - fXp;
608 fY0 = event->fY - fYp;
609
610 fX0 = std::max(fX0, fgScrollBarWidth);
611 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
612 fSlider->Move(fX0, 0);
614 fPos = (Int_t)pos;
615
616 fPos = std::max(fPos, 0);
617 fPos = std::min(fPos, fRange-fPsize);
618
621 }
622 return kTRUE;
623}
624
625////////////////////////////////////////////////////////////////////////////////
626/// Set range of horizontal scrollbar.
627
628void TGHScrollBar::SetRange(Int_t range, Int_t page_size)
629{
630 fRange = std::max(range, 1);
631 fPsize = std::max(page_size, 0);
632 fPos = std::max(fPos, 0);
633 fPos = std::min(fPos, fRange-fPsize);
634
635 fSliderSize = std::max(fPsize * (fWidth - (fgScrollBarWidth << 1)) /
636 fRange, (UInt_t) 6);
638
639 fSliderRange = std::max(fWidth - (fgScrollBarWidth << 1) - fSliderSize,
640 (UInt_t) 1);
641
642 fX0 = fgScrollBarWidth + fPos * fSliderRange / std::max(fRange-fPsize, 1);
643 fX0 = std::max(fX0, fgScrollBarWidth);
644 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
645
646 fSlider->Move(fX0, 0);
649
650 // fPos = (fX0 - fgScrollBarWidth) * (fRange-fPsize) / fSliderRange;
651
656}
657
658////////////////////////////////////////////////////////////////////////////////
659/// Set logical slider position of horizontal scrollbar.
660
662{
663 fPos = std::max(pos, 0);
664 fPos = std::min(pos, fRange-fPsize);
665
666 fX0 = fgScrollBarWidth + fPos * fSliderRange / std::max(fRange-fPsize, 1);
667 fX0 = std::max(fX0, fgScrollBarWidth);
668 fX0 = std::min(fX0, fgScrollBarWidth + fSliderRange);
669
670 fSlider->Move(fX0, 0);
673
676}
677
678
679////////////////////////////////////////////////////////////////////////////////
680/// Create a vertical scrollbar.
681
683 UInt_t options, ULong_t back) :
684 TGScrollBar(p, w, h, options, back, "arrow_up.xpm", "arrow_down.xpm")
685{
686 fRange = std::max((Int_t) h - (fgScrollBarWidth << 1), 1);
687 fPsize = fRange >> 1;
689}
690
691////////////////////////////////////////////////////////////////////////////////
692/// Layout and move vertical scrollbar components.
693
695{
696 // Should recalculate fSliderSize, fSliderRange, fX0, fY0, etc. too...
697 fHead->Move(0, 0);
701
702 if (fSlider->GetY() != fY0) {
703 fSlider->Move(0, fY0);
706 }
707}
708
709////////////////////////////////////////////////////////////////////////////////
710/// Handle mouse button event in vertical scrollbar.
711
713{
714 Int_t newpos;
715
716 if (event->fCode == kButton4) {
717 if (!fHead->IsEnabled()) {
718 return kFALSE;
719 }
720 //scroll up
721 newpos = fPos - fPsize;
722 if (newpos<0) newpos = 0;
723 SetPosition(newpos);
724 return kTRUE;
725 }
726 if (event->fCode == kButton5) {
727 if (!fTail->IsEnabled()) {
728 return kFALSE;
729 }
730
731 // scroll down
732 newpos = fPos + fPsize;
733 SetPosition(newpos);
734 return kTRUE;
735 }
736
737 if (event->fType == kButtonPress) {
738 if (event->fCode == kButton3) {
739 fY0 = event->fY - fSliderSize/2;
740 fY0 = std::max(fY0, fgScrollBarWidth);
741 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
743 fPos = (Int_t)pos;
744
745 fPos = std::max(fPos, 0);
746 fPos = std::min(fPos, fRange-fPsize);
747 fSlider->Move(0, fY0);
748
751 return kTRUE;
752 }
753
754 // fUser[0] contains the subwindow (child) in which the event occurred
755 // (see GX11Gui.cxx)
756 Window_t subw = (Window_t)event->fUser[0];
757
758 if (subw == fSlider->GetId()) {
759 fXp = event->fX - fX0;
760 fYp = event->fY - fY0;
762
763 } else {
764
765 if (!fRepeat)
766 fRepeat = new TSBRepeatTimer(this, 400, fSmallInc); // 500
767 fRepeat->Reset();
769 fSubw = subw;
770
771 if (subw == fHead->GetId()) {
772 //if (!fHead->IsEnabled()) {
773 // return kFALSE;
774 // }
776 fPos -= fSmallInc;
777 } else if (subw == fTail->GetId()) {
778 //if (!fTail->IsEnabled()) {
779 // return kFALSE;
780 //}
782 fPos += fSmallInc;
783 } else if (event->fY > fgScrollBarWidth && event->fY < fY0)
784 fPos -= fPsize;
785 else if (event->fY > fY0+fSliderSize && event->fY < (Int_t)fHeight-fgScrollBarWidth)
786 fPos += fPsize;
787
788 fPos = std::max(fPos, 0);
789 fPos = std::min(fPos, fRange-fPsize);
790
792 fY0 = (Int_t)y0;
793
794 fY0 = std::max(fY0, fgScrollBarWidth);
795 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
796
797 fSlider->Move(0, fY0);
798
801 }
802
803 // last argument kFALSE forces all specified events to this window
807 kTRUE, kFALSE);
808 } else {
811
812 if (fRepeat) {
813 fRepeat->Remove();
814 fRepeat->SetTime(400); // might have been shortened in HandleTimer()
815 fSmallInc = ((TSBRepeatTimer*)fRepeat)->GetSmallInc();
816 }
817
819
820 fPos = std::max(fPos, 0);
821 fPos = std::min(fPos, fRange-fPsize);
822
825
826 if (fGrabPointer) {
827 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
828 }
829 }
830 return kTRUE;
831}
832
833////////////////////////////////////////////////////////////////////////////////
834/// Handle mouse motion in a vertical scrollbar.
835
837{
838 if (fDragging) {
839 fX0 = event->fX - fXp;
840 fY0 = event->fY - fYp;
841
842 fY0 = std::max(fY0, fgScrollBarWidth);
843 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
844 fSlider->Move(0, fY0);
846 fPos = (Int_t)pos;
847
848 fPos = std::max(fPos, 0);
849 fPos = std::min(fPos, fRange-fPsize);
850
853 }
854 return kTRUE;
855}
856
857////////////////////////////////////////////////////////////////////////////////
858/// Set range of vertical scrollbar.
859
860void TGVScrollBar::SetRange(Int_t range, Int_t page_size)
861{
862 fRange = std::max(range, 1);
863 fPsize = std::max(page_size, 0);
864 fPos = std::max(fPos, 0);
865 fPos = std::min(fPos, fRange-fPsize);
866
867 fSliderSize = std::max(fPsize * (fHeight - (fgScrollBarWidth << 1)) /
868 fRange, (UInt_t) 6);
870
871 fSliderRange = std::max(fHeight - (fgScrollBarWidth << 1) - fSliderSize,
872 (UInt_t)1);
873
875 fY0 = (Int_t)y0;
876 fY0 = std::max(fY0, fgScrollBarWidth);
877 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
878
879 fSlider->Move(0, fY0);
882
883 // fPos = (fY0 - fgScrollBarWidth) * (fRange-fPsize) / fSliderRange;
884
885
890}
891
892////////////////////////////////////////////////////////////////////////////////
893/// Set logical slider position of vertical scrollbar.
894
896{
897 fPos = std::max(pos, 0);
898 fPos = std::min(pos, fRange-fPsize);
899
901 fY0 = (Int_t)y0;
902 fY0 = std::max(fY0, fgScrollBarWidth);
903 fY0 = std::min(fY0, fgScrollBarWidth + fSliderRange);
904
905 fSlider->Move(0, fY0);
908
911}
912
913////////////////////////////////////////////////////////////////////////////////
914/// Save an horizontal scrollbar as a C++ statement(s) on output stream out.
915
916void TGHScrollBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
917{
918 // save options and custom color if not default
919 auto extra_args = SaveCtorArgs(out);
920
921 out << " TGHScrollBar *" << GetName() << " = new TGHScrollBar(" << fParent->GetName() << "," << GetWidth() << ","
922 << GetHeight() << extra_args << ");\n";
923
924 if (option && strstr(option, "keep_names"))
925 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
926
927 out << " " << GetName() << "->SetRange(" << GetRange() << "," << GetPageSize() << ");\n";
928 out << " " << GetName() << "->SetPosition(" << GetPosition() << ");\n";
929}
930
931////////////////////////////////////////////////////////////////////////////////
932/// Save an vertical scrollbar as a C++ statement(s) on output stream out.
933
934void TGVScrollBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
935{
936 // save options and custom color if not default
937 auto extra_args = SaveCtorArgs(out);
938
939 out << " TGVScrollBar *" << GetName() << " = new TGVScrollBar(" << fParent->GetName() << "," << GetWidth() << ","
940 << GetHeight() << extra_args << ");\n";
941
942 if (option && strstr(option, "keep_names"))
943 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
944
945 out << " " << GetName() << "->SetRange(" << GetRange() << "," << GetPageSize() << ");\n";
946 out << " " << GetName() << "->SetPosition(" << GetPosition() << ");\n";
947}
@ kButtonPress
Definition GuiTypes.h:61
@ kEnterNotify
Definition GuiTypes.h:62
@ kLeaveNotify
Definition GuiTypes.h:62
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:31
const Mask_t kButtonPressMask
Definition GuiTypes.h:162
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
const Mask_t kAnyModifier
Definition GuiTypes.h:211
const Mask_t kPointerMotionMask
Definition GuiTypes.h:164
@ kDefaultScrollBarWidth
Definition GuiTypes.h:87
@ 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
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
#define h(i)
Definition RSha256.hxx:106
cudaEvent_t event
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:70
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:157
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
char name[80]
Definition TGX11.cxx:142
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#define gVirtualX
Definition TVirtualX.h:379
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kSB_SLIDERTRACK
@ kSB_SLIDERPOS
@ kC_VSCROLL
@ kC_HSCROLL
static Pixmap_t GetPixmap(TImage *timg)
Returns image pixmap.
Definition TASUtils.cxx:135
static Pixmap_t GetMask(TImage *timg)
Returns image mask pixmap (alpha channel).
Definition TASUtils.cxx:181
static std::unique_ptr< TImage > FromPixmap(Pixmap_t pxm, Pixmap_t mask)
Create image from pixmap.
Definition TASUtils.cxx:271
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:511
Bool_t IsEditable() const
Definition TGClient.h:89
const TGPicture * GetPictureOrEmpty(const char *name)
Like TGPicturePool::GetPicture() but, instead of returning null when the picture is not found,...
Definition TGClient.cxx:297
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:381
TGPicturePool * GetPicturePool() const
Definition TGClient.h:126
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:317
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:333
static const TGGC & GetBlackGC()
Get black graphics context.
Definition TGFrame.cxx:729
UInt_t fOptions
frame options
Definition TGFrame.h:94
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:599
UInt_t fHeight
frame height
Definition TGFrame.h:88
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:424
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:749
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:587
Int_t GetX() const
Definition TGFrame.h:233
virtual void ChangeBackground(Pixel_t back)
Change frame background color.
Definition TGFrame.cxx:287
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:639
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:759
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:2494
Int_t GetY() const
Definition TGFrame.h:234
static const TGGC & GetWhiteGC()
Get white graphics context.
Definition TGFrame.cxx:739
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:769
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 GetId() const
Definition TGObject.h:41
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition TGPicture.cxx:81
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
Pixmap_t GetMask() const
Definition TGPicture.h:55
void Draw(Option_t *="") override
Default Draw method for all objects.
Definition TGPicture.h:46
UInt_t GetHeight() const
Definition TGPicture.h:53
const char * GetName() const override
Returns name of object.
Definition TGPicture.h:51
Pixmap_t GetPicture() const
Definition TGPicture.h:54
UInt_t GetWidth() const
Definition TGPicture.h:52
virtual Bool_t IsEnabled() const
Definition TGScrollBar.h:54
~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
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition TGWindow.cxx:249
virtual void SetEditDisabled(UInt_t on=kEditDisable)
Definition TGWindow.h:113
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
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:130
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:337
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
virtual void Option_t *static TImage * Create()
Create an image.
Definition TImage.cxx:34
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:548
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:137
const char * Data() const
Definition TString.h:385
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:474
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
void Remove() override
Definition TTimer.h:86
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