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
103
104////////////////////////////////////////////////////////////////////////////////
105/// Constructor. Layout 1 row or 1 column.
106
108 const TString &title,
109 UInt_t options,
111 FontStruct_t font,
112 Pixel_t back) :
113 TGGroupFrame(parent, new TGString(title), options, norm, font, back)
114{
115 Init();
116 if (options & kVerticalFrame) {
118 } else {
120 }
121
122 fDrawBorder = !title.IsNull();
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Constructor. Layout defined by TGMatrixLayout:
127/// r = number of rows
128/// c = number of columns
129/// s = interval between frames
130/// h = layout hints
131
133 UInt_t r, UInt_t c,
134 Int_t s, Int_t h,
135 const TString &title,
137 FontStruct_t font ,
138 Pixel_t back) :
139 TGGroupFrame(parent, new TGString(title), 0, norm, font, back)
140{
141 Init();
142 fDrawBorder = !title.IsNull();
143 SetLayoutManager(new TGMatrixLayout(this,r,c,s,h));
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Default init.
148
150{
151 fState = kTRUE;
152 fMapOfButtons = new TMap(); // map of button/id pairs
156
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Destructor, we do not delete the buttons.
162
164{
165 TIter next(fMapOfButtons);
166 TGButton *item = 0;
167
168 while ((item = (TGButton*)next())) {
169 item->SetGroup(0);
170 }
171
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Redraw the group frame. Need special DoRedraw() since we need to
177/// redraw with fBorderWidth=0.
178
180{
181 gVirtualX->ClearArea(fId, 0, 0, fWidth, fHeight);
182
183 DrawBorder();
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Draw border of around the group frame.
188///
189/// if frame is kRaisedFrame - a frame border is of "wall style",
190/// otherwise of "groove style".
191
193{
194 if (!fDrawBorder) return;
195
196 Int_t x, y, l, t, r, b, gl, gr, sep, max_ascent, max_descent;
197
199 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
200
201 l = 0;
202 t = (max_ascent + max_descent + 2) >> 1;
203 r = fWidth - 1;
204 // next three lines are for backward compatibility in case of horizontal layout
206 // coverity[returned_null]
207 // coverity[dereference]
208 if ((lm->InheritsFrom(TGHorizontalLayout::Class())) ||
209 (lm->InheritsFrom(TGMatrixLayout::Class())))
210 b = fHeight - 1;
211 else
212 b = fHeight - t;
213
214 sep = 3;
215 UInt_t rr = 5 + (sep << 1) + tw;
216
217 switch (fTitlePos) {
218 case kRight:
219 gl = fWidth>rr ? Int_t(fWidth - rr) : 5 + sep;
220 break;
221 case kCenter:
222 gl = fWidth>tw ? Int_t((fWidth - tw)>>1) - sep : 5 + sep;
223 break;
224 case kLeft:
225 default:
226 gl = 5 + sep;
227 }
228 gr = gl + tw + (sep << 1);
229
230 switch (fOptions & (kSunkenFrame | kRaisedFrame)) {
231 case kRaisedFrame:
232 gVirtualX->DrawLine(fId, GetHilightGC()(), l, t, gl, t);
233 gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, t+1, gl, t+1);
234
235 gVirtualX->DrawLine(fId, GetHilightGC()(), gr, t, r-1, t);
236 gVirtualX->DrawLine(fId, GetShadowGC()(), gr, t+1, r-2, t+1);
237
238 gVirtualX->DrawLine(fId, GetHilightGC()(), r-1, t, r-1, b-1);
239 gVirtualX->DrawLine(fId, GetShadowGC()(), r, t, r, b);
240
241 gVirtualX->DrawLine(fId, GetHilightGC()(), r-1, b-1, l, b-1);
242 gVirtualX->DrawLine(fId, GetShadowGC()(), r, b, l, b);
243
244 gVirtualX->DrawLine(fId, GetHilightGC()(), l, b-1, l, t);
245 gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, b-2, l+1, t+1);
246 break;
247 case kSunkenFrame:
248 default:
249 gVirtualX->DrawLine(fId, GetShadowGC()(), l, t, gl, t);
250 gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, t+1, gl, t+1);
251
252 gVirtualX->DrawLine(fId, GetShadowGC()(), gr, t, r-1, t);
253 gVirtualX->DrawLine(fId, GetHilightGC()(), gr, t+1, r-2, t+1);
254
255 gVirtualX->DrawLine(fId, GetShadowGC()(), r-1, t, r-1, b-1);
256 gVirtualX->DrawLine(fId, GetHilightGC()(), r, t, r, b);
257
258 gVirtualX->DrawLine(fId, GetShadowGC()(), r-1, b-1, l, b-1);
259 gVirtualX->DrawLine(fId, GetHilightGC()(), r, b, l, b);
260
261 gVirtualX->DrawLine(fId, GetShadowGC()(), l, b-1, l, t);
262 gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, b-2, l+1, t+1);
263 break;
264 }
265
266 x = gl + sep;
267 y = 1;
268
269 if (fState) {
271 } else {
272 fText->Draw(fId, GetHilightGC()(), x, y + 1 + max_ascent);
274 }
275}
276
277////////////////////////////////////////////////////////////////////////////////
278/// Makes border to be visible/invisible.
279
281{
282 if (enable != IsBorderDrawn()) {
284 ChangedBy("SetBorderDrawn"); // emit signal
285 }
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Sets the button group to be exclusive if enable is kTRUE,
290/// or to be non-exclusive if enable is kFALSE.
291/// An exclusive button group switches off all other toggle buttons when
292/// one is switched on. This is ideal for groups of radio-buttons
293/// A non-exclusive group allow many buttons to be switched on at the same
294/// time. The default setting is kFALSE.
295
297{
298 if (enable != IsExclusive()) {
300 ChangedBy("SetExclusive"); // emit signal
301 }
302}
303
304////////////////////////////////////////////////////////////////////////////////
305/// If enable is kTRUE, this button group will treat radio buttons as
306/// mutually exclusive, and other buttons according to IsExclusive().
307/// This function is called automatically whenever a TGRadioButton
308/// is inserted, so you should normally never have to call it.
309
311{
314 ChangedBy("SetRadioButtonExclusive"); // emit signal
315 }
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Sets the state of all the buttons in the group to enable or disable.
320
322{
323 fState = state;
324
325 TIter next(fMapOfButtons);
326 TGButton *item = 0;
327
328 while ((item = (TGButton*)next())) { // loop over all buttons
329 if (state) {
330 item->SetState(kButtonUp);
331 } else {
332 item->SetState(kButtonDisabled);
333 }
334 }
335 DoRedraw();
336}
337////////////////////////////////////////////////////////////////////////////////
338/// Sets the button with id to be on/down, and if this is an
339/// exclusive group, all other button in the group to be off/up.
340
342{
343 TGButton *b = Find(id);
344
345 if (b && (b->IsDown() != down)) {
346 b->SetState(kButtonDown, kTRUE);
347 }
348}
349
350////////////////////////////////////////////////////////////////////////////////
351/// Inserts a button with the identifier id into the button group.
352/// Returns the button identifier.
353///
354/// It is not necessary to manually insert buttons that have this button
355/// group as their parent widget. An exception is when you want custom
356/// identifiers instead of the default 1, 2, 3 etc.
357///
358/// The button is assigned the identifier id or an automatically
359/// generated identifier. It works as follows: If id > 0, this
360/// identifier is assigned. If id == -1 (default), the identifier is
361/// equal to the number of buttons in the group+1. If id is any other
362/// negative integer, for instance -2, a unique identifier (negative
363/// integer <= -2) is generated.
364///
365/// Inserting several buttons with id = -1 assigns the identifiers 1,
366/// 2, 3, etc.
367
369{
370 if (button->fGroup && button->fGroup != this)
371 button->fGroup->Remove(button);
372
373 if (button->fGroup == this) {
374 if (id == -1)
375 return GetId(button); // the button is already in group
376 else
377 button->fGroup->Remove(button); // want to set a new id
378 }
379
380 button->fGroup = this;
381 button->Associate(this);
382
383 static Int_t seq_no = -2;
385
386 if (id < -1) bid = seq_no--;
387 else if (id == -1) bid = GetCount()+1;
388 else bid = id;
389
392
393 // coverity[returned_null]
394 // coverity[dereference]
395 SetRadioButtonExclusive(button->IsA()->InheritsFrom(TGRadioButton::Class()));
396
397 Connect(button, "Clicked()" , "TGButtonGroup", this, "ReleaseButtons()");
398 Connect(button, "Pressed()" , "TGButtonGroup", this, "ButtonPressed()");
399 Connect(button, "Released()", "TGButtonGroup", this, "ButtonReleased()");
400 Connect(button, "Clicked()" , "TGButtonGroup", this, "ButtonClicked()");
401
402 return (Int_t) bid;
403}
404
405////////////////////////////////////////////////////////////////////////////////
406/// Removes a button from the button group.
407
409{
411 if (item) {
412 button->SetGroup(0);
413 button->Disconnect(this);
414 button->DestroyWindow();
415 }
416
418}
419
420////////////////////////////////////////////////////////////////////////////////
421/// Finds and returns a pointer to the button with the specified
422/// identifier id. Returns null if the button was not found.
423
425{
426 TIter next(fMapOfButtons);
427 TGButton *item = 0;
428
429 while ((item = (TGButton*)next())) {
430 if ((Longptr_t)fMapOfButtons->GetValue(item) == id) break; // found
431 }
432
433 return item;
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// Returns number of buttons in group
438
440{
441 return fMapOfButtons->GetSize();
442}
443
444////////////////////////////////////////////////////////////////////////////////
445/// Finds and returns the id of the button.
446/// Returns -1 if the button is not a member of this group.
447
449{
451 if (a)
452 return (Int_t)Longptr_t(a->Value());
453 else
454 return -1;
455}
456
457////////////////////////////////////////////////////////////////////////////////
458/// This slot is activated when one of the buttons in the group emits the
459/// Pressed() signal.
460
462{
463#if 0
464 // Is here for historical purposes and example. Now this is not needed
465 // anymore since TGButton has has its own GetSender() method returning
466 // the TGButton proper.
467
468 // This is needed since gTQSender points to TQObject part of TGButton
469 TGButton *btn = dynamic_cast<TGButton*>((TQObject*)gTQSender);
470
471 if (!btn) {
472 Error("ButtonPressed", "gTQSender not a TGButton");
473 return;
474 }
475#else
477#endif
478
480 if (a) {
481 Int_t id = (Int_t)Longptr_t(a->Value());
482 Pressed(id);
483 }
484}
485
486////////////////////////////////////////////////////////////////////////////////
487/// This slot is activated when one of the buttons in the group emits the
488/// Released() signal.
489
491{
493
495 if (a) {
496 Int_t id = (Int_t)Longptr_t(a->Value());
497 Released(id);
498 }
499}
500
501////////////////////////////////////////////////////////////////////////////////
502/// This slot is activated when one of the buttons in the group emits the
503/// Clicked() signal.
504
506{
508
510 if (a) {
511 Int_t id = (Int_t)Longptr_t(a->Value());
512 Clicked(id);
513 }
514}
515
516////////////////////////////////////////////////////////////////////////////////
517/// This slot is activated when one of the buttons in the
518/// exclusive group emits the Pressed() signal.
519
521{
522 if (!fExclGroup && !fRadioExcl) return;
523
525
526 if (!fExclGroup && !btn)
527 return;
528
529 TIter next(fMapOfButtons);
530 TGButton *item = 0;
531
532 while ((item = (TGButton*)next())) { // loop over all buttons
533 // coverity[returned_null]
534 // coverity[dereference]
535 if (btn != item && item->IsToggleButton() && item->IsOn() &&
536 (fExclGroup || (item->IsA()->InheritsFrom(TGRadioButton::Class())
537 && btn->IsA()->InheritsFrom(TGRadioButton::Class())))) {
538 item->SetOn(kFALSE);
539 }
540 }
541}
542
543////////////////////////////////////////////////////////////////////////////////
544/// Show group of buttons.
545
547{
549 Resize();
550 MapRaised();
551 fClient->NeedRedraw(this);
552}
553
554////////////////////////////////////////////////////////////////////////////////
555/// Hide group of buttons.
556
558{
559 UnmapWindow();
560}
561
562////////////////////////////////////////////////////////////////////////////////
563/// Set or change title.
564
566{
567 if (!title) {
568 Error("SetTitle", "title cannot be 0, try \"\"");
569 return;
570 }
571
572 if (strcmp(fText->GetString(), title->GetString())) {
573 SetBorderDrawn(title->GetLength() ? kTRUE : kFALSE);
575 ChangedBy("SetTitle");
576 }
577}
578
579////////////////////////////////////////////////////////////////////////////////
580/// Set or change title.
581
582void TGButtonGroup::SetTitle(const char *title)
583{
584 if (!title) {
585 Error("SetTitle", "title cannot be 0, try \"\"");
586 return;
587 }
588
589 if (strcmp(fText->GetString(), title)) {
590 SetBorderDrawn(title && strlen(title));
592 ChangedBy("SetTitle");
593 }
594}
595
596////////////////////////////////////////////////////////////////////////////////
597/// Set layout hints for the specified button or if button=0 for all
598/// buttons.
599
601{
603 TIter next(fList);
604
605 while ((el = (TGFrameElement *)next())) {
606 if ((el->fFrame==(TGFrame*)button) || !button) {
607 el->fLayout = l ? l : fgDefaultHints;
608 }
609 }
610 Layout();
611}
612
613////////////////////////////////////////////////////////////////////////////////
614/// Save a button group widget as a C++ statement(s) on output stream out.
615
616void TGButtonGroup::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
617{
618 // font + GC
619 option = GetName() + 5; // unique digit id of the name
621 // coverity[returned_null]
622 // coverity[dereference]
623 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
624 // coverity[returned_null]
625 // coverity[dereference]
626 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
627
628 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
629 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
630 if (ufont) {
631 ufont->SavePrimitive(out, option);
632 parFont.Form("ufont->GetFontStruct()");
633 }
634
635 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
636 if (userGC) {
637 userGC->SavePrimitive(out, option);
638 parGC.Form("uGC->GetGC()");
639 }
640 }
641
643 SaveUserColor(out, option);
644
645 out << "\n // buttongroup frame\n";
646
647 out << " TGButtonGroup *" << GetName() << " = new TGButtonGroup(" << fParent->GetName()
648 << ", \"" << TString(fText->GetString()).ReplaceSpecialCppChars() << "\"";
649
652 if (fNormGC == GetDefaultGC()()) {
653 if (!GetOptions()) {
654 out <<");\n";
655 } else {
656 out << "," << GetOptionString() <<");\n";
657 }
658 } else {
659 out << "," << GetOptionString() << ", " << parGC <<");\n";
660 }
661 } else {
662 out << "," << GetOptionString() << ", " << parGC << "," << parFont <<");\n";
663 }
664 } else {
665 out << "," << GetOptionString() << "," << parGC << "," << parFont << ", ucolor);\n";
666 }
667 if (option && strstr(option, "keep_names"))
668 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
669
670 // setting layout manager
671 out << " " << GetName() <<"->SetLayoutManager(";
672 // coverity[returned_null]
673 // coverity[dereference]
674 GetLayoutManager()->SavePrimitive(out, option);
675 out << ");\n";
676
677 TIter next(GetList());
678 while (auto f = static_cast<TGFrameElement *>(next())) {
679 f->fFrame->SavePrimitive(out, option);
680 if (f->fFrame->InheritsFrom("TGButton"))
681 continue;
682 else {
683 out << " " << GetName() << "->AddFrame(" << f->fFrame->GetName();
684 f->fLayout->SavePrimitive(out, option);
685 out << ");\n";
686 }
687 }
688
689 if (IsExclusive())
690 out << " " << GetName() <<"->SetExclusive(kTRUE);\n";
691
693 out << " " << GetName() <<"->SetRadioButtonExclusive(kTRUE);\n";
694
695 if (!IsBorderDrawn())
696 out << " " << GetName() <<"->SetBorderDrawn(kFALSE);\n";
697
698
699 out << " " << GetName() << "->Resize(" << GetWidth()
700 << "," << GetHeight() << ");\n";
701
702 if (!IsEnabled())
703 out << " " << GetName() <<"->SetState(kFALSE);\n";
704
705 out << " " << GetName() << "->Show();\n";
706}
707
708////////////////////////////////////////////////////////////////////////////////
709/// Save a button group widget as a C++ statement(s) on output stream out.
710
711void TGHButtonGroup::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
712{
713 // font + GC
714 option = GetName() + 5; // unique digit id of the name
716 parFont.Form("%s::GetDefaultFontStruct()", IsA()->GetName());
717 parGC.Form("%s::GetDefaultGC()()", IsA()->GetName());
718
719 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
720 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
721 if (ufont) {
722 ufont->SavePrimitive(out, option);
723 parFont.Form("ufont->GetFontStruct()");
724 }
725
726 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
727 if (userGC) {
728 userGC->SavePrimitive(out, option);
729 parGC.Form("uGC->GetGC()");
730 }
731 }
732
734 SaveUserColor(out, option);
735
736 out << "\n // horizontal buttongroup frame\n";
737
738 out << " TGHButtonGroup *" << GetName() << " = new TGHButtonGroup(" << fParent->GetName() << ", \""
741
743
744 if (fNormGC == GetDefaultGC()()) {
745 out << ");\n";
746 } else {
747 out << "," << parGC << ");\n";
748 }
749 } else {
750 out << "," << parGC << "," << parFont << ");\n";
751 }
752 } else {
753 out << "," << parGC << "," << parFont << ", ucolor);\n";
754 }
755 if (option && strstr(option, "keep_names"))
756 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
757
758 TIter next(GetList());
759 while (auto f = (TGFrameElement *)next()) {
760 f->fFrame->SavePrimitive(out, option);
761 if (f->fFrame->InheritsFrom("TGButton")) {
762 out << " " << GetName() << "->SetLayoutHints(";
763 f->fLayout->SavePrimitive(out, "nocoma");
764 out << "," << f->fFrame->GetName() << ");\n";
765 } else {
766 out << " " << GetName() << "->AddFrame(" << f->fFrame->GetName();
767 f->fLayout->SavePrimitive(out, option);
768 out << ");\n";
769 }
770 }
771
772 if (!IsEnabled())
773 out << " " << GetName() << "->SetState(kFALSE);\n";
774
775 if (IsExclusive())
776 out << " " << GetName() << "->SetExclusive(kTRUE);\n";
777
779 out << " " << GetName() << "->SetRadioButtonExclusive(kTRUE);\n";
780
781 if (!IsBorderDrawn())
782 out << " " << GetName() << "->SetBorderDrawn(kFALSE);\n";
783
784 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
785
786 out << " " << GetName() << "->Show();\n";
787}
788
789////////////////////////////////////////////////////////////////////////////////
790/// Save a button group widget as a C++ statement(s) on output stream out.
791
792void TGVButtonGroup::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
793{
794 // font + GC
795 option = GetName() + 5; // unique digit id of the name
797 parFont.Form("%s::GetDefaultFontStruct()", IsA()->GetName());
798 parGC.Form("%s::GetDefaultGC()()", IsA()->GetName());
799
800 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
801 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
802 if (ufont) {
803 ufont->SavePrimitive(out, option);
804 parFont.Form("ufont->GetFontStruct()");
805 }
806
807 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
808 if (userGC) {
809 userGC->SavePrimitive(out, option);
810 parGC.Form("uGC->GetGC()");
811 }
812 }
813
815 SaveUserColor(out, option);
816
817 out << "\n // vertical buttongroup frame\n";
818
819 out << " TGVButtonGroup *" << GetName() << " = new TGVButtonGroup(" << fParent->GetName()
820 << ", \"" << TString(fText->GetString()).ReplaceSpecialCppChars() << "\"";
821
824 if (fNormGC == GetDefaultGC()()) {
825 out << ");\n";
826 } else {
827 out << "," << parGC << ");\n";
828 }
829 } else {
830 out << "," << parGC << "," << parFont << ");\n";
831 }
832 } else {
833 out << "," << parGC << "," << parFont << ", ucolor);\n";
834 }
835 if (option && strstr(option, "keep_names"))
836 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
837
838 TIter next(GetList());
839 while (auto f = static_cast<TGFrameElement *>(next())) {
840 f->fFrame->SavePrimitive(out, option);
841 if (f->fFrame->InheritsFrom("TGButton"))
842 continue;
843 out << " " << GetName() << "->AddFrame(" << f->fFrame->GetName();
844 f->fLayout->SavePrimitive(out, option);
845 out << ");\n";
846 }
847
848 if (!IsEnabled())
849 out << " " << GetName() <<"->SetState(kFALSE);\n";
850
851 if (IsExclusive())
852 out << " " << GetName() <<"->SetExclusive(kTRUE);\n";
853
855 out << " " << GetName() <<"->SetRadioButtonExclusive(kTRUE);\n";
856
857 if (!IsBorderDrawn())
858 out << " " << GetName() <<"->SetBorderDrawn(kFALSE);\n";
859
860 out << " " << GetName() << "->Resize(" << GetWidth()
861 << "," << GetHeight() << ");\n";
862
863 out << " " << GetName() << "->Show();\n";
864}
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:533
#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
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
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
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:208
@ 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.
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:380
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition TGFrame.cxx:992
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
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:1156
void Layout() override
Layout the elements of the composite frame.
Definition TGFrame.cxx:1249
TList * fList
container of frame elements
Definition TGFrame.h:294
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition TGFrame.cxx:1141
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:597
UInt_t fHeight
frame height
Definition TGFrame.h:88
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:747
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:675
virtual UInt_t GetOptions() const
Definition TGFrame.h:199
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2512
void UnmapWindow() override
unmap window
Definition TGFrame.h:208
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
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:2471
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:2339
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:2329
virtual void SetTitle(TGString *title)
Set or change title of the group frame.
Definition TGFrame.cxx:2300
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:54
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:127
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:334
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:53
TObject * FindObject(const char *keyname) const override
Check if a (key,value) pair exists with keyname as name of the key.
Definition TMap.cxx:214
TObject * Remove(TObject *key) override
Remove the (key,value) pair with key from the map.
Definition TMap.cxx:295
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition TMap.cxx:235
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:865
virtual void ChangedBy(const char *method)
Definition TQObject.h:199
Basic string class.
Definition TString.h:138
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1121
Bool_t IsNull() const
Definition TString.h:422
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