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,
113 GContext_t norm,
114 FontStruct_t font,
115 ULong_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,
139 GContext_t norm ,
140 FontStruct_t font ,
141 ULong_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
201 UInt_t tw = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
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) {
273 fText->Draw(fId, fNormGC, x, y + max_ascent);
274 } else {
275 fText->Draw(fId, GetHilightGC()(), x, y + 1 + max_ascent);
276 fText->Draw(fId, GetShadowGC()(), x, y + max_ascent);
277 }
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Makes border to be visible/invisible.
282
284{
285 if (enable != IsBorderDrawn()) {
286 fDrawBorder = enable;
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()) {
302 fExclGroup = enable;
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{
315 if (enable != IsRadioButtonExclusive()) {
316 fRadioExcl = enable;
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 {
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;
387 Longptr_t bid;
388
389 if (id < -1) bid = seq_no--;
390 else if (id == -1) bid = GetCount()+1;
391 else bid = id;
392
393 fMapOfButtons->Add(button, (TObject*)bid);
394 AddFrame(button);
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{
413 TGButton *item = (TGButton*) fMapOfButtons->Remove(button);
414 if (item) {
415 button->SetGroup(0);
416 button->Disconnect(this);
417 button->DestroyWindow();
418 }
419
420 RemoveFrame(button);
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{
453 TPair *a = (TPair*) fMapOfButtons->FindObject(button);
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
479 TGButton *btn = (TGButton*)gTQSender;
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{
495 TGButton *btn = (TGButton*)gTQSender;
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{
510 TGButton *btn = (TGButton*)gTQSender;
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
527 TGButton *btn = (TGButton*)gTQSender;
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{
605 TGFrameElement *el;
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 char quote ='"';
622
623 // font + GC
624 option = GetName()+5; // unique digit id of the name
625 TString parGC, parFont;
626 // coverity[returned_null]
627 // coverity[dereference]
628 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
629 // coverity[returned_null]
630 // coverity[dereference]
631 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
632
633 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
634 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
635 if (ufont) {
636 ufont->SavePrimitive(out, option);
637 parFont.Form("ufont->GetFontStruct()");
638 }
639
640 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
641 if (userGC) {
642 userGC->SavePrimitive(out, option);
643 parGC.Form("uGC->GetGC()");
644 }
645 }
646
648
649 out << std::endl << " // buttongroup frame" << std::endl;
650
651 out << " TGButtonGroup *";
652 out << GetName() << " = new TGButtonGroup(" << fParent->GetName()
653 << ","<< quote << fText->GetString() << quote;
654
657 if (fNormGC == GetDefaultGC()()) {
658 if (!GetOptions()) {
659 out <<");" << std::endl;
660 } else {
661 out << "," << GetOptionString() <<");" << std::endl;
662 }
663 } else {
664 out << "," << GetOptionString() << "," << parGC.Data() <<");" << std::endl;
665 }
666 } else {
667 out << "," << GetOptionString() << "," << parGC.Data() << "," << parFont.Data() <<");" << std::endl;
668 }
669 } else {
670 out << "," << GetOptionString() << "," << parGC.Data() << "," << parFont.Data() << ",ucolor);" << std::endl;
671 }
672 if (option && strstr(option, "keep_names"))
673 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
674
675 // setting layout manager
676 out << " " << GetName() <<"->SetLayoutManager(";
677 // coverity[returned_null]
678 // coverity[dereference]
679 GetLayoutManager()->SavePrimitive(out, option);
680 out << ");"<< std::endl;
681
683 TIter next(GetList());
684 while ((f = (TGFrameElement *)next())) {
685 f->fFrame->SavePrimitive(out,option);
686 if (f->fFrame->InheritsFrom("TGButton")) continue;
687 else {
688 out << " " << GetName() << "->AddFrame(" << f->fFrame->GetName();
689 f->fLayout->SavePrimitive(out, option);
690 out << ");"<< std::endl;
691 }
692 }
693
694 if (IsExclusive())
695 out << " " << GetName() <<"->SetExclusive(kTRUE);" << std::endl;
696
698 out << " " << GetName() <<"->SetRadioButtonExclusive(kTRUE);" << std::endl;
699
700 if (!IsBorderDrawn())
701 out << " " << GetName() <<"->SetBorderDrawn(kFALSE);" << std::endl;
702
703
704 out << " " << GetName() << "->Resize(" << GetWidth()
705 << "," << GetHeight() << ");" << std::endl;
706
707 if (!IsEnabled())
708 out << " " << GetName() <<"->SetState(kFALSE);" << std::endl;
709
710 out << " " << GetName() << "->Show();" << std::endl;
711}
712
713////////////////////////////////////////////////////////////////////////////////
714/// Save a button group widget as a C++ statement(s) on output stream out.
715
716void TGHButtonGroup::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
717{
718 char quote ='"';
719
720 // font + GC
721 option = GetName()+5; // unique digit id of the name
722 TString parGC, parFont;
723 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
724 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
725
726 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
727 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
728 if (ufont) {
729 ufont->SavePrimitive(out, option);
730 parFont.Form("ufont->GetFontStruct()");
731 }
732
733 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
734 if (userGC) {
735 userGC->SavePrimitive(out, option);
736 parGC.Form("uGC->GetGC()");
737 }
738 }
739
741
742 out << std::endl << " // horizontal buttongroup frame" << std::endl;
743
744 out << " TGHButtonGroup *";
745 out << GetName() << " = new TGHButtonGroup(" << fParent->GetName()
746 << "," << quote << fText->GetString() << quote;
748
750
751 if (fNormGC == GetDefaultGC()()) {
752 out << ");" << std::endl;
753 } else {
754 out << "," << parGC.Data() <<");" << std::endl;
755 }
756 } else {
757 out << "," << parGC.Data() << "," << parFont.Data() <<");" << std::endl;
758 }
759 } else {
760 out << "," << parGC.Data() << "," << parFont.Data() << ",ucolor);" << std::endl;
761 }
762 if (option && strstr(option, "keep_names"))
763 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
764
766 TIter next(GetList());
767 while ((f = (TGFrameElement *)next())) {
768 f->fFrame->SavePrimitive(out,option);
769 if (f->fFrame->InheritsFrom("TGButton")){
770 out << " " << GetName() << "->SetLayoutHints(";
771 f->fLayout->SavePrimitive(out, "nocoma");
772 out << "," << f->fFrame->GetName();
773 out << ");"<< std::endl;
774 }
775 else {
776 out << " " << GetName() << "->AddFrame(" << f->fFrame->GetName();
777 f->fLayout->SavePrimitive(out, option);
778 out << ");"<< std::endl;
779 }
780 }
781
782 if (!IsEnabled())
783 out << " " << GetName() <<"->SetState(kFALSE);" << std::endl;
784
785 if (IsExclusive())
786 out << " " << GetName() <<"->SetExclusive(kTRUE);" << std::endl;
787
789 out << " " << GetName() <<"->SetRadioButtonExclusive(kTRUE);" << std::endl;
790
791 if (!IsBorderDrawn())
792 out << " " << GetName() <<"->SetBorderDrawn(kFALSE);" << std::endl;
793
794 out << " " << GetName() <<"->Resize(" << GetWidth() << ","
795 << GetHeight() << ");" << std::endl;
796
797 out << " " << GetName() << "->Show();" << std::endl;
798}
799
800////////////////////////////////////////////////////////////////////////////////
801/// Save a button group widget as a C++ statement(s) on output stream out.
802
803void TGVButtonGroup::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
804{
805 char quote ='"';
806
807 // font + GC
808 option = GetName()+5; // unique digit id of the name
809 TString parGC, parFont;
810 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
811 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
812
813 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
814 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
815 if (ufont) {
816 ufont->SavePrimitive(out, option);
817 parFont.Form("ufont->GetFontStruct()");
818 }
819
820 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
821 if (userGC) {
822 userGC->SavePrimitive(out, option);
823 parGC.Form("uGC->GetGC()");
824 }
825 }
826
828
829 out << std::endl << " // vertical buttongroup frame" << std::endl;
830
831 out << " TGVButtonGroup *";
832 out << GetName() << " = new TGVButtonGroup(" << fParent->GetName()
833 << "," << quote << fText->GetString() << quote;
834
837 if (fNormGC == GetDefaultGC()()) {
838 out <<");" << std::endl;
839 } else {
840 out << "," << parGC.Data() <<");" << std::endl;
841 }
842 } else {
843 out << "," << parGC.Data() << "," << parFont.Data() <<");" << std::endl;
844 }
845 } else {
846 out << "," << parGC.Data() << "," << parFont.Data() << ",ucolor);" << std::endl;
847 }
848 if (option && strstr(option, "keep_names"))
849 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
850
852 TIter next(GetList());
853 while ((f = (TGFrameElement *)next())) {
854 f->fFrame->SavePrimitive(out,option);
855 if (f->fFrame->InheritsFrom("TGButton")) continue;
856 else {
857 out << " " << GetName() << "->AddFrame(" << f->fFrame->GetName();
858 f->fLayout->SavePrimitive(out, option);
859 out << ");"<< std::endl;
860 }
861 }
862
863 if (!IsEnabled())
864 out << " " << GetName() <<"->SetState(kFALSE);" << std::endl;
865
866 if (IsExclusive())
867 out << " " << GetName() <<"->SetExclusive(kTRUE);" << std::endl;
868
870 out << " " << GetName() <<"->SetRadioButtonExclusive(kTRUE);" << std::endl;
871
872 if (!IsBorderDrawn())
873 out << " " << GetName() <<"->SetBorderDrawn(kFALSE);" << std::endl;
874
875 out << " " << GetName() << "->Resize(" << GetWidth()
876 << "," << GetHeight() << ");"<< std::endl;
877
878 out << " " << GetName() << "->Show();" << std::endl;
879}
@ kRaisedFrame
Definition GuiTypes.h:384
@ kSunkenFrame
Definition GuiTypes.h:383
@ kVerticalFrame
Definition GuiTypes.h:381
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
ROOT::R::TRInterface & r
Definition Object.C:4
#define SafeDelete(p)
Definition RConfig.hxx:537
#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:82
const Bool_t kFALSE
Definition RtypesCore.h:101
unsigned long ULong_t
Definition RtypesCore.h:55
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:157
XFontStruct * id
Definition TGX11.cxx:109
R__EXTERN void * gTQSender
Definition TQObject.h:46
#define gVirtualX
Definition TVirtualX.h:338
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Organizes TGButton widgets in a group.
virtual ~TGButtonGroup()
Destructor, we do not delete the buttons.
Int_t GetCount() const
Returns number of buttons in group.
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,...
virtual void Show()
Show group of buttons.
virtual void DrawBorder()
Draw border of around the group frame.
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
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.
Bool_t fDrawBorder
kTRUE if border and title are drawn
Bool_t IsRadioButtonExclusive() const
virtual void DoRedraw()
Redraw the group frame.
virtual void SetLayoutHints(TGLayoutHints *l, TGButton *button=0)
Set layout hints for the specified button or if button=0 for all buttons.
Bool_t IsBorderDrawn() const
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
virtual void SetTitle(TGString *title)
Set or change title.
virtual void Hide()
Hide group of buttons.
virtual void Remove(TGButton *button)
Removes a button from the button group.
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 SavePrimitive(std::ostream &out, Option_t *option="")
Save a button group widget as a C++ statement(s) on output stream out.
virtual void Released(Int_t id)
A button abstract base class.
Definition TGButton.h:68
virtual void SetGroup(TGButtonGroup *gr)
Sets new button-group for this button.
Definition TGButton.cxx:322
TGButtonGroup * fGroup
button group this button belongs to
Definition TGButton.h:80
virtual void SetOn(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition TGButton.h:120
virtual Bool_t IsToggleButton() const
Definition TGButton.h:121
virtual Bool_t IsOn() const
Definition TGButton.h:119
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition TGButton.cxx:235
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:372
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition TGFrame.cxx:1000
virtual TList * GetList() const
Definition TGFrame.h:310
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual TGLayoutManager * GetLayoutManager() const
Definition TGFrame.h:338
virtual void Layout()
Layout the elements of the composite frame.
Definition TGFrame.cxx:1257
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
TList * fList
container of frame elements
Definition TGFrame.h:292
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition TGFrame.cxx:1149
static TGLayoutHints * fgDefaultHints
Definition TGFrame.h:297
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save the used font as a C++ statement(s) on output stream out.
Definition TGFont.cxx:1884
TGLayoutHints * fLayout
Definition TGLayout.h:114
TGFrame * fFrame
Definition TGLayout.h:112
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
virtual void MapRaised()
map raised
Definition TGFrame.h:205
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:197
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2504
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:765
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:605
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:225
UInt_t GetWidth() const
Definition TGFrame.h:224
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2477
Pixel_t fBackground
frame background color
Definition TGFrame.h:95
virtual void UnmapWindow()
unmap window
Definition TGFrame.h:206
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
void SavePrimitive(std::ostream &out, Option_t *option="")
Save graphics context info as a C++ statement(s) on output stream out.
Definition TGGC.cxx:627
A composite frame with a border and a title.
Definition TGFrame.h:523
TGString * fText
title text
Definition TGFrame.h:526
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Definition TGFrame.cxx:2345
Int_t fTitlePos
OPTION={GetMethod="GetTitlePos";SetMethod="SetTitlePos";Items=(-1="Left",0="Center",...
Definition TGFrame.h:529
FontStruct_t fFontStruct
title fontstruct
Definition TGFrame.h:527
GContext_t fNormGC
title graphics context
Definition TGFrame.h:528
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Definition TGFrame.cxx:2335
virtual void SetTitle(TGString *title)
Set or change title of the group frame.
Definition TGFrame.cxx:2306
Organizes TGButton widgets in a group with one horizontal row.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a button group widget as a C++ statement(s) on output stream out.
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
TGClient * fClient
Connection to display server.
Definition TGObject.h:27
Handle_t GetId() const
Definition TGObject.h:37
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:26
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.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a button group widget as a C++ statement(s) on output stream out.
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void SetWindowName(const char *name=0)
Set window name.
Definition TGWindow.cxx:129
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
virtual void DestroyWindow()
destroy window
Definition TGWindow.cxx:192
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition TMap.h:40
void Add(TObject *obj)
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 * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition TMap.cxx:236
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition TMap.cxx:215
TObject * Remove(TObject *key)
Remove the (key,value) pair with key from the map.
Definition TMap.cxx:296
Mother of all ROOT objects.
Definition TObject.h:41
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition TObject.cxx:736
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:515
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:198
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
Bool_t IsNull() const
Definition TString.h:407
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2314
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
TGraphErrors * gr
Definition legend1.C:25
auto * l
Definition textangle.C:4