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