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