Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGButtonGroup.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Valeriy Onuchin & Fons Rademakers 16/10/2000
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/** \class TGButtonGroup
14 \ingroup guiwidgets
15
16Organizes TGButton widgets in a group.
17A button group widget makes it easier to deal with groups of buttons.
18A button in a button group is associated with a unique identifier.
19The button group emits a Clicked() signal with this identifier when
20the button is clicked. Thus, a button group is an ideal solution
21when you have several similar buttons and want to connect all their
22Clicked() signals, for example, to one slot.
23
24An exclusive button group switches off all toggle buttons except
25the one that was clicked. A button group is by default non-exclusive.
26All radio buttons that are inserted, will be mutually exclusive even
27if the button group is non-exclusive.
28
29
30There are two ways of using a button group:
31
32 The button group is a parent widget of a number of buttons,
33 i.e. the button group is the parent argument in the button
34 constructor. The buttons are assigned identifiers 1, 2, 3 etc.
35 in the order they are created or you can specify button id in
36 the button constructor. A TGButtonGroup can display a frame and
37 a title because it inherits from TGGroupFrame.
38
39Example:
40
41```
42 // vertical frame without border and title
43 TGVButtonGroup *bg = new TGVButtonGroup(main_frame);
44
45 // create text button with id=1
46 TGTextButton *button1 = new TGTextButton(bg,"some text");
47
48 // create another text button with id=2
49 TGTextButton *button2 = new TGTextButton(bg,"another text");
50
51 // map all buttons
52 bg->Show();
53```
54
55NOTE: there is no need to call AddFrame() since the buttons are
56automatically added with a default layout hint to their parent,
57i.e. the buttongroup. To override the default layout hints use the
58SetLayoutHints() method.
59
60 ButtonGroup Signals:
61
62 - Pressed(Int_t id) --> is emitted when a button in the group is
63 pressed down. The id argument is the
64 button's identifier.
65 - Released(Int_t id) --> is emitted when a button in the group is
66 released. The id argument is the button's
67 identifier.
68 - Clicked(Int_t id) --> is emitted when a button in the group is
69 clicked. The id argument is the button's
70 identifier.
71
72
73\class TGHButtonGroup
74\ingroup guiwidgets
75
76Organizes TGButton widgets in a group with one horizontal row. TGHButtonGroup is a
77convenience class that offers a thin layer on top of TGButtonGroup. It inherits from
78TGButtonGroup.
79
80
81\class TGVButtonGroup
82\ingroup guiwidgets
83
84Organizes TGButton widgets in a group with one vertical column. TGVButtonGroup is a
85convenience class that offers a thin layer on top of TGButtonGroup. It inherits from
86TGButtonGroup.
87
88*/
89
90
91#include "TGButtonGroup.h"
92#include "TGButton.h"
93#include "TClass.h"
94#include "TGLayout.h"
95#include "TList.h"
96#include "TGResourcePool.h"
97#include "TVirtualX.h"
98#include "TMap.h"
99
100#include <iostream>
101
102
106
107////////////////////////////////////////////////////////////////////////////////
108/// Constructor. Layout 1 row or 1 column.
109
111 const TString &title,
112 UInt_t options,
114 FontStruct_t font,
115 Pixel_t back) :
116 TGGroupFrame(parent, new TGString(title), options, norm, font, back)
117{
118 Init();
119 if (options & kVerticalFrame) {
121 } else {
123 }
124
125 fDrawBorder = !title.IsNull();
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Constructor. Layout defined by TGMatrixLayout:
130/// r = number of rows
131/// c = number of columns
132/// s = interval between frames
133/// h = layout hints
134
136 UInt_t r, UInt_t c,
137 Int_t s, Int_t h,
138 const TString &title,
140 FontStruct_t font ,
141 Pixel_t back) :
142 TGGroupFrame(parent, new TGString(title), 0, norm, font, back)
143{
144 Init();
145 fDrawBorder = !title.IsNull();
146 SetLayoutManager(new TGMatrixLayout(this,r,c,s,h));
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Default init.
151
153{
154 fState = kTRUE;
155 fMapOfButtons = new TMap(); // map of button/id pairs
159
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// Destructor, we do not delete the buttons.
165
167{
168 TIter next(fMapOfButtons);
169 TGButton *item = 0;
170
171 while ((item = (TGButton*)next())) {
172 item->SetGroup(0);
173 }
174
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Redraw the group frame. Need special DoRedraw() since we need to
180/// redraw with fBorderWidth=0.
181
183{
184 gVirtualX->ClearArea(fId, 0, 0, fWidth, fHeight);
185
186 DrawBorder();
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Draw border of around the group frame.
191///
192/// if frame is kRaisedFrame - a frame border is of "wall style",
193/// otherwise of "groove style".
194
196{
197 if (!fDrawBorder) return;
198
199 Int_t x, y, l, t, r, b, gl, gr, sep, max_ascent, max_descent;
200
202 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
203
204 l = 0;
205 t = (max_ascent + max_descent + 2) >> 1;
206 r = fWidth - 1;
207 // next three lines are for backward compatibility in case of horizontal layout
209 // coverity[returned_null]
210 // coverity[dereference]
211 if ((lm->InheritsFrom(TGHorizontalLayout::Class())) ||
212 (lm->InheritsFrom(TGMatrixLayout::Class())))
213 b = fHeight - 1;
214 else
215 b = fHeight - t;
216
217 sep = 3;
218 UInt_t rr = 5 + (sep << 1) + tw;
219
220 switch (fTitlePos) {
221 case kRight:
222 gl = fWidth>rr ? Int_t(fWidth - rr) : 5 + sep;
223 break;
224 case kCenter:
225 gl = fWidth>tw ? Int_t((fWidth - tw)>>1) - sep : 5 + sep;
226 break;
227 case kLeft:
228 default:
229 gl = 5 + sep;
230 }
231 gr = gl + tw + (sep << 1);
232
233 switch (fOptions & (kSunkenFrame | kRaisedFrame)) {
234 case kRaisedFrame:
235 gVirtualX->DrawLine(fId, GetHilightGC()(), l, t, gl, t);
236 gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, t+1, gl, t+1);
237
238 gVirtualX->DrawLine(fId, GetHilightGC()(), gr, t, r-1, t);
239 gVirtualX->DrawLine(fId, GetShadowGC()(), gr, t+1, r-2, t+1);
240
241 gVirtualX->DrawLine(fId, GetHilightGC()(), r-1, t, r-1, b-1);
242 gVirtualX->DrawLine(fId, GetShadowGC()(), r, t, r, b);
243
244 gVirtualX->DrawLine(fId, GetHilightGC()(), r-1, b-1, l, b-1);
245 gVirtualX->DrawLine(fId, GetShadowGC()(), r, b, l, b);
246
247 gVirtualX->DrawLine(fId, GetHilightGC()(), l, b-1, l, t);
248 gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, b-2, l+1, t+1);
249 break;
250 case kSunkenFrame:
251 default:
252 gVirtualX->DrawLine(fId, GetShadowGC()(), l, t, gl, t);
253 gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, t+1, gl, t+1);
254
255 gVirtualX->DrawLine(fId, GetShadowGC()(), gr, t, r-1, t);
256 gVirtualX->DrawLine(fId, GetHilightGC()(), gr, t+1, r-2, t+1);
257
258 gVirtualX->DrawLine(fId, GetShadowGC()(), r-1, t, r-1, b-1);
259 gVirtualX->DrawLine(fId, GetHilightGC()(), r, t, r, b);
260
261 gVirtualX->DrawLine(fId, GetShadowGC()(), r-1, b-1, l, b-1);
262 gVirtualX->DrawLine(fId, GetHilightGC()(), r, b, l, b);
263
264 gVirtualX->DrawLine(fId, GetShadowGC()(), l, b-1, l, t);
265 gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, b-2, l+1, t+1);
266 break;
267 }
268
269 x = gl + sep;
270 y = 1;
271
272 if (fState) {
274 } else {
275 fText->Draw(fId, GetHilightGC()(), x, y + 1 + max_ascent);
277 }
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Makes border to be visible/invisible.
282
284{
285 if (enable != IsBorderDrawn()) {
287 ChangedBy("SetBorderDrawn"); // emit signal
288 }
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Sets the button group to be exclusive if enable is kTRUE,
293/// or to be non-exclusive if enable is kFALSE.
294/// An exclusive button group switches off all other toggle buttons when
295/// one is switched on. This is ideal for groups of radio-buttons
296/// A non-exclusive group allow many buttons to be switched on at the same
297/// time. The default setting is kFALSE.
298
300{
301 if (enable != IsExclusive()) {
303 ChangedBy("SetExclusive"); // emit signal
304 }
305}
306
307////////////////////////////////////////////////////////////////////////////////
308/// If enable is kTRUE, this button group will treat radio buttons as
309/// mutually exclusive, and other buttons according to IsExclusive().
310/// This function is called automatically whenever a TGRadioButton
311/// is inserted, so you should normally never have to call it.
312
314{
317 ChangedBy("SetRadioButtonExclusive"); // emit signal
318 }
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Sets the state of all the buttons in the group to enable or disable.
323
325{
326 fState = state;
327
328 TIter next(fMapOfButtons);
329 TGButton *item = 0;
330
331 while ((item = (TGButton*)next())) { // loop over all buttons
332 if (state) {
333 item->SetState(kButtonUp);
334 } else {
335 item->SetState(kButtonDisabled);
336 }
337 }
338 DoRedraw();
339}
340////////////////////////////////////////////////////////////////////////////////
341/// Sets the button with id to be on/down, and if this is an
342/// exclusive group, all other button in the group to be off/up.
343
345{
346 TGButton *b = Find(id);
347
348 if (b && (b->IsDown() != down)) {
349 b->SetState(kButtonDown, kTRUE);
350 }
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Inserts a button with the identifier id into the button group.
355/// Returns the button identifier.
356///
357/// It is not necessary to manually insert buttons that have this button
358/// group as their parent widget. An exception is when you want custom
359/// identifiers instead of the default 1, 2, 3 etc.
360///
361/// The button is assigned the identifier id or an automatically
362/// generated identifier. It works as follows: If id > 0, this
363/// identifier is assigned. If id == -1 (default), the identifier is
364/// equal to the number of buttons in the group+1. If id is any other
365/// negative integer, for instance -2, a unique identifier (negative
366/// integer <= -2) is generated.
367///
368/// Inserting several buttons with id = -1 assigns the identifiers 1,
369/// 2, 3, etc.
370
372{
373 if (button->fGroup && button->fGroup != this)
374 button->fGroup->Remove(button);
375
376 if (button->fGroup == this) {
377 if (id == -1)
378 return GetId(button); // the button is already in group
379 else
380 button->fGroup->Remove(button); // want to set a new id
381 }
382
383 button->fGroup = this;
384 button->Associate(this);
385
386 static Int_t seq_no = -2;
388
389 if (id < -1) bid = seq_no--;
390 else if (id == -1) bid = GetCount()+1;
391 else bid = id;
392
395
396 // coverity[returned_null]
397 // coverity[dereference]
398 SetRadioButtonExclusive(button->IsA()->InheritsFrom(TGRadioButton::Class()));
399
400 Connect(button, "Clicked()" , "TGButtonGroup", this, "ReleaseButtons()");
401 Connect(button, "Pressed()" , "TGButtonGroup", this, "ButtonPressed()");
402 Connect(button, "Released()", "TGButtonGroup", this, "ButtonReleased()");
403 Connect(button, "Clicked()" , "TGButtonGroup", this, "ButtonClicked()");
404
405 return (Int_t) bid;
406}
407
408////////////////////////////////////////////////////////////////////////////////
409/// Removes a button from the button group.
410
412{
414 if (item) {
415 button->SetGroup(0);
416 button->Disconnect(this);
417 button->DestroyWindow();
418 }
419
421}
422
423////////////////////////////////////////////////////////////////////////////////
424/// Finds and returns a pointer to the button with the specified
425/// identifier id. Returns null if the button was not found.
426
428{
429 TIter next(fMapOfButtons);
430 TGButton *item = 0;
431
432 while ((item = (TGButton*)next())) {
433 if ((Longptr_t)fMapOfButtons->GetValue(item) == id) break; // found
434 }
435
436 return item;
437}
438
439////////////////////////////////////////////////////////////////////////////////
440/// Returns number of buttons in group
441
443{
444 return fMapOfButtons->GetSize();
445}
446
447////////////////////////////////////////////////////////////////////////////////
448/// Finds and returns the id of the button.
449/// Returns -1 if the button is not a member of this group.
450
452{
454 if (a)
455 return (Int_t)Longptr_t(a->Value());
456 else
457 return -1;
458}
459
460////////////////////////////////////////////////////////////////////////////////
461/// This slot is activated when one of the buttons in the group emits the
462/// Pressed() signal.
463
465{
466#if 0
467 // Is here for historical purposes and example. Now this is not needed
468 // anymore since TGButton has has its own GetSender() method returning
469 // the TGButton proper.
470
471 // This is needed since gTQSender points to TQObject part of TGButton
472 TGButton *btn = dynamic_cast<TGButton*>((TQObject*)gTQSender);
473
474 if (!btn) {
475 Error("ButtonPressed", "gTQSender not a TGButton");
476 return;
477 }
478#else
480#endif
481
483 if (a) {
484 Int_t id = (Int_t)Longptr_t(a->Value());
485 Pressed(id);
486 }
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// This slot is activated when one of the buttons in the group emits the
491/// Released() signal.
492
494{
496
498 if (a) {
499 Int_t id = (Int_t)Longptr_t(a->Value());
500 Released(id);
501 }
502}
503
504////////////////////////////////////////////////////////////////////////////////
505/// This slot is activated when one of the buttons in the group emits the
506/// Clicked() signal.
507
509{
511
513 if (a) {
514 Int_t id = (Int_t)Longptr_t(a->Value());
515 Clicked(id);
516 }
517}
518
519////////////////////////////////////////////////////////////////////////////////
520/// This slot is activated when one of the buttons in the
521/// exclusive group emits the Pressed() signal.
522
524{
525 if (!fExclGroup && !fRadioExcl) return;
526
528
529 if (!fExclGroup && !btn)
530 return;
531
532 TIter next(fMapOfButtons);
533 TGButton *item = 0;
534
535 while ((item = (TGButton*)next())) { // loop over all buttons
536 // coverity[returned_null]
537 // coverity[dereference]
538 if (btn != item && item->IsToggleButton() && item->IsOn() &&
539 (fExclGroup || (item->IsA()->InheritsFrom(TGRadioButton::Class())
540 && btn->IsA()->InheritsFrom(TGRadioButton::Class())))) {
541 item->SetOn(kFALSE);
542 }
543 }
544}
545
546////////////////////////////////////////////////////////////////////////////////
547/// Show group of buttons.
548
550{
552 Resize();
553 MapRaised();
554 fClient->NeedRedraw(this);
555}
556
557////////////////////////////////////////////////////////////////////////////////
558/// Hide group of buttons.
559
561{
562 UnmapWindow();
563}
564
565////////////////////////////////////////////////////////////////////////////////
566/// Set or change title.
567
569{
570 if (!title) {
571 Error("SetTitle", "title cannot be 0, try \"\"");
572 return;
573 }
574
575 if (strcmp(fText->GetString(), title->GetString())) {
576 SetBorderDrawn(title->GetLength() ? kTRUE : kFALSE);
578 ChangedBy("SetTitle");
579 }
580}
581
582////////////////////////////////////////////////////////////////////////////////
583/// Set or change title.
584
585void TGButtonGroup::SetTitle(const char *title)
586{
587 if (!title) {
588 Error("SetTitle", "title cannot be 0, try \"\"");
589 return;
590 }
591
592 if (strcmp(fText->GetString(), title)) {
593 SetBorderDrawn(title && strlen(title));
595 ChangedBy("SetTitle");
596 }
597}
598
599////////////////////////////////////////////////////////////////////////////////
600/// Set layout hints for the specified button or if button=0 for all
601/// buttons.
602
604{
606 TIter next(fList);
607
608 while ((el = (TGFrameElement *)next())) {
609 if ((el->fFrame==(TGFrame*)button) || !button) {
610 el->fLayout = l ? l : fgDefaultHints;
611 }
612 }
613 Layout();
614}
615
616////////////////////////////////////////////////////////////////////////////////
617/// Save a button group widget as a C++ statement(s) on output stream out.
618
619void TGButtonGroup::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
620{
621 // font + GC
622 option = GetName() + 5; // unique digit id of the name
624 // coverity[returned_null]
625 // coverity[dereference]
626 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
627 // coverity[returned_null]
628 // coverity[dereference]
629 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
630
631 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
632 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
633 if (ufont) {
634 ufont->SavePrimitive(out, option);
635 parFont.Form("ufont->GetFontStruct()");
636 }
637
638 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
639 if (userGC) {
640 userGC->SavePrimitive(out, option);
641 parGC.Form("uGC->GetGC()");
642 }
643 }
644
646 SaveUserColor(out, option);
647
648 out << "\n // buttongroup frame\n";
649
650 out << " TGButtonGroup *" << GetName() << " = new TGButtonGroup(" << fParent->GetName()
651 << ", \"" << TString(fText->GetString()).ReplaceSpecialCppChars() << "\"";
652
655 if (fNormGC == GetDefaultGC()()) {
656 if (!GetOptions()) {
657 out <<");\n";
658 } else {
659 out << "," << GetOptionString() <<");\n";
660 }
661 } else {
662 out << "," << GetOptionString() << ", " << parGC <<");\n";
663 }
664 } else {
665 out << "," << GetOptionString() << ", " << parGC << "," << parFont <<");\n";
666 }
667 } else {
668 out << "," << GetOptionString() << "," << parGC << "," << parFont << ", ucolor);\n";
669 }
670 if (option && strstr(option, "keep_names"))
671 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
672
673 // setting layout manager
674 out << " " << GetName() <<"->SetLayoutManager(";
675 // coverity[returned_null]
676 // coverity[dereference]
677 GetLayoutManager()->SavePrimitive(out, option);
678 out << ");\n";
679
680 TIter next(GetList());
681 while (auto f = static_cast<TGFrameElement *>(next())) {
682 f->fFrame->SavePrimitive(out, option);
683 if (f->fFrame->InheritsFrom("TGButton"))
684 continue;
685 else {
686 out << " " << GetName() << "->AddFrame(" << f->fFrame->GetName();
687 f->fLayout->SavePrimitive(out, option);
688 out << ");\n";
689 }
690 }
691
692 if (IsExclusive())
693 out << " " << GetName() <<"->SetExclusive(kTRUE);\n";
694
696 out << " " << GetName() <<"->SetRadioButtonExclusive(kTRUE);\n";
697
698 if (!IsBorderDrawn())
699 out << " " << GetName() <<"->SetBorderDrawn(kFALSE);\n";
700
701
702 out << " " << GetName() << "->Resize(" << GetWidth()
703 << "," << GetHeight() << ");\n";
704
705 if (!IsEnabled())
706 out << " " << GetName() <<"->SetState(kFALSE);\n";
707
708 out << " " << GetName() << "->Show();\n";
709}
710
711////////////////////////////////////////////////////////////////////////////////
712/// Save a button group widget as a C++ statement(s) on output stream out.
713
714void TGHButtonGroup::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
715{
716 // font + GC
717 option = GetName() + 5; // unique digit id of the name
719 parFont.Form("%s::GetDefaultFontStruct()", IsA()->GetName());
720 parGC.Form("%s::GetDefaultGC()()", IsA()->GetName());
721
722 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
723 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
724 if (ufont) {
725 ufont->SavePrimitive(out, option);
726 parFont.Form("ufont->GetFontStruct()");
727 }
728
729 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
730 if (userGC) {
731 userGC->SavePrimitive(out, option);
732 parGC.Form("uGC->GetGC()");
733 }
734 }
735
737 SaveUserColor(out, option);
738
739 out << "\n // horizontal buttongroup frame\n";
740
741 out << " TGHButtonGroup *" << GetName() << " = new TGHButtonGroup(" << fParent->GetName() << ", \""
744
746
747 if (fNormGC == GetDefaultGC()()) {
748 out << ");\n";
749 } else {
750 out << "," << parGC << ");\n";
751 }
752 } else {
753 out << "," << parGC << "," << parFont << ");\n";
754 }
755 } else {
756 out << "," << parGC << "," << parFont << ", ucolor);\n";
757 }
758 if (option && strstr(option, "keep_names"))
759 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
760
761 TIter next(GetList());
762 while (auto f = (TGFrameElement *)next()) {
763 f->fFrame->SavePrimitive(out, option);
764 if (f->fFrame->InheritsFrom("TGButton")) {
765 out << " " << GetName() << "->SetLayoutHints(";
766 f->fLayout->SavePrimitive(out, "nocoma");
767 out << "," << f->fFrame->GetName() << ");\n";
768 } else {
769 out << " " << GetName() << "->AddFrame(" << f->fFrame->GetName();
770 f->fLayout->SavePrimitive(out, option);
771 out << ");\n";
772 }
773 }
774
775 if (!IsEnabled())
776 out << " " << GetName() << "->SetState(kFALSE);\n";
777
778 if (IsExclusive())
779 out << " " << GetName() << "->SetExclusive(kTRUE);\n";
780
782 out << " " << GetName() << "->SetRadioButtonExclusive(kTRUE);\n";
783
784 if (!IsBorderDrawn())
785 out << " " << GetName() << "->SetBorderDrawn(kFALSE);\n";
786
787 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
788
789 out << " " << GetName() << "->Show();\n";
790}
791
792////////////////////////////////////////////////////////////////////////////////
793/// Save a button group widget as a C++ statement(s) on output stream out.
794
795void TGVButtonGroup::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
796{
797 // font + GC
798 option = GetName() + 5; // unique digit id of the name
800 parFont.Form("%s::GetDefaultFontStruct()", IsA()->GetName());
801 parGC.Form("%s::GetDefaultGC()()", IsA()->GetName());
802
803 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
804 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
805 if (ufont) {
806 ufont->SavePrimitive(out, option);
807 parFont.Form("ufont->GetFontStruct()");
808 }
809
810 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
811 if (userGC) {
812 userGC->SavePrimitive(out, option);
813 parGC.Form("uGC->GetGC()");
814 }
815 }
816
818 SaveUserColor(out, option);
819
820 out << "\n // vertical buttongroup frame\n";
821
822 out << " TGVButtonGroup *" << GetName() << " = new TGVButtonGroup(" << fParent->GetName()
823 << ", \"" << TString(fText->GetString()).ReplaceSpecialCppChars() << "\"";
824
827 if (fNormGC == GetDefaultGC()()) {
828 out << ");\n";
829 } else {
830 out << "," << parGC << ");\n";
831 }
832 } else {
833 out << "," << parGC << "," << parFont << ");\n";
834 }
835 } else {
836 out << "," << parGC << "," << parFont << ", ucolor);\n";
837 }
838 if (option && strstr(option, "keep_names"))
839 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
840
841 TIter next(GetList());
842 while (auto f = static_cast<TGFrameElement *>(next())) {
843 f->fFrame->SavePrimitive(out, option);
844 if (f->fFrame->InheritsFrom("TGButton"))
845 continue;
846 out << " " << GetName() << "->AddFrame(" << f->fFrame->GetName();
847 f->fLayout->SavePrimitive(out, option);
848 out << ");\n";
849 }
850
851 if (!IsEnabled())
852 out << " " << GetName() <<"->SetState(kFALSE);\n";
853
854 if (IsExclusive())
855 out << " " << GetName() <<"->SetExclusive(kTRUE);\n";
856
858 out << " " << GetName() <<"->SetRadioButtonExclusive(kTRUE);\n";
859
860 if (!IsBorderDrawn())
861 out << " " << GetName() <<"->SetBorderDrawn(kFALSE);\n";
862
863 out << " " << GetName() << "->Resize(" << GetWidth()
864 << "," << GetHeight() << ");\n";
865
866 out << " " << GetName() << "->Show();\n";
867}
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
@ kRaisedFrame
Definition GuiTypes.h:384
@ kSunkenFrame
Definition GuiTypes.h:383
@ kVerticalFrame
Definition GuiTypes.h:381
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
#define SafeDelete(p)
Definition RConfig.hxx:541
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
long Longptr_t
Definition RtypesCore.h:75
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:157
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 r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t button
R__EXTERN void * gTQSender
Definition TQObject.h:46
#define gVirtualX
Definition TVirtualX.h:337
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Organizes TGButton widgets in a group.
Int_t GetCount() const
Returns number of buttons in group.
virtual void SetLayoutHints(TGLayoutHints *l, TGButton *button=nullptr)
Set layout hints for the specified button or if button=0 for all buttons.
virtual void Clicked(Int_t id)
virtual void ButtonClicked()
This slot is activated when one of the buttons in the group emits the Clicked() signal.
virtual void SetRadioButtonExclusive(Bool_t flag=kTRUE)
If enable is kTRUE, this button group will treat radio buttons as mutually exclusive,...
void DoRedraw() override
Redraw the group frame.
virtual void Show()
Show group of buttons.
Bool_t fState
kTRUE if group is enabled
virtual void SetExclusive(Bool_t flag=kTRUE)
Sets the button group to be exclusive if enable is kTRUE, or to be non-exclusive if enable is kFALSE.
virtual void Pressed(Int_t id)
virtual void ButtonPressed()
This slot is activated when one of the buttons in the group emits the Pressed() signal.
TGButtonGroup(const TGButtonGroup &)=delete
Bool_t IsEnabled() const
void DrawBorder() override
Draw border of around the group frame.
Bool_t IsExclusive() const
virtual void SetState(Bool_t state=kTRUE)
Sets the state of all the buttons in the group to enable or disable.
virtual void ReleaseButtons()
This slot is activated when one of the buttons in the exclusive group emits the Pressed() signal.
virtual TGButton * Find(Int_t id) const
Finds and returns a pointer to the button with the specified identifier id.
TClass * IsA() const override
Bool_t fDrawBorder
kTRUE if border and title are drawn
Bool_t IsRadioButtonExclusive() const
Bool_t IsBorderDrawn() const
void SetTitle(TGString *title) override
Set or change title.
virtual void SetButton(Int_t id, Bool_t down=kTRUE)
Sets the button with id to be on/down, and if this is an exclusive group, all other button in the gro...
Bool_t fExclGroup
kTRUE if group is exclusive
void Init()
Default init.
virtual void ButtonReleased()
This slot is activated when one of the buttons in the group emits the Released() signal.
TMap * fMapOfButtons
map of button/id pairs in this group
~TGButtonGroup() override
Destructor, we do not delete the buttons.
virtual void Hide()
Hide group of buttons.
virtual void Remove(TGButton *button)
Removes a button from the button group.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a button group widget as a C++ statement(s) on output stream out.
virtual Int_t Insert(TGButton *button, int id=-1)
Inserts a button with the identifier id into the button group.
virtual void SetBorderDrawn(Bool_t enable=kTRUE)
Makes border to be visible/invisible.
Bool_t fRadioExcl
kTRUE if radio buttons are exclusive
virtual void Released(Int_t id)
A button abstract base class.
Definition TGButton.h:68
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:381
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition TGFrame.cxx:1000
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual TList * GetList() const
Definition TGFrame.h:312
virtual TGLayoutManager * GetLayoutManager() const
Definition TGFrame.h:340
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
void Layout() override
Layout the elements of the composite frame.
Definition TGFrame.cxx:1257
TList * fList
container of frame elements
Definition TGFrame.h:294
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition TGFrame.cxx:1149
static TGLayoutHints * fgDefaultHints
Definition TGFrame.h:299
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
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:605
UInt_t fHeight
frame height
Definition TGFrame.h:88
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:755
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:683
virtual UInt_t GetOptions() const
Definition TGFrame.h:199
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2520
void UnmapWindow() override
unmap window
Definition TGFrame.h:208
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:765
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
UInt_t GetWidth() const
Definition TGFrame.h:226
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2479
Pixel_t fBackground
frame background color
Definition TGFrame.h:95
void MapRaised() override
map raised
Definition TGFrame.h:207
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
A composite frame with a border and a title.
Definition TGFrame.h:524
TGString * fText
title text
Definition TGFrame.h:527
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Definition TGFrame.cxx:2347
Int_t fTitlePos
OPTION={GetMethod="GetTitlePos";SetMethod="SetTitlePos";Items=(-1="Left",0="Center",...
Definition TGFrame.h:530
FontStruct_t fFontStruct
title fontstruct
Definition TGFrame.h:528
GContext_t fNormGC
title graphics context
Definition TGFrame.h:529
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Definition TGFrame.cxx:2337
virtual void SetTitle(TGString *title)
Set or change title of the group frame.
Definition TGFrame.cxx:2308
Organizes TGButton widgets in a group with one horizontal row.
TClass * IsA() const override
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a button group widget as a C++ statement(s) on output stream out.
static TClass * Class()
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Frame layout manager.
Definition TGLayout.h:135
This layout managers does not make use of TGLayoutHints.
Definition TGLayout.h:269
static TClass * Class()
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
static TClass * Class()
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition TGString.h:20
Int_t GetLength() const
Definition TGString.h:29
const char * GetString() const
Definition TGString.h:30
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition TGString.cxx:56
Organizes TGButton widgets in a group with one vertical column.
TClass * IsA() const override
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a button group widget as a C++ statement(s) on output stream out.
ROOT GUI Window base class.
Definition TGWindow.h:23
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:129
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition TMap.h:40
void Add(TObject *obj) override
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
Definition TMap.cxx:54
TObject * FindObject(const char *keyname) const override
Check if a (key,value) pair exists with keyname as name of the key.
Definition TMap.cxx:215
TObject * Remove(TObject *key) override
Remove the (key,value) pair with key from the map.
Definition TMap.cxx:296
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition TMap.cxx:236
Mother of all ROOT objects.
Definition TObject.h:41
Class used by TMap to store (key,value) pairs.
Definition TMap.h:102
This is the ROOT implementation of the Qt object communication mechanism (see also http://www....
Definition TQObject.h:48
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:869
virtual void ChangedBy(const char *method)
Definition TQObject.h:199
Basic string class.
Definition TString.h:139
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1114
Bool_t IsNull() const
Definition TString.h:414
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
TGraphErrors * gr
Definition legend1.C:25
TLine l
Definition textangle.C:4