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 /** \class TGButtonGroup
14  \ingroup guiwidgets
15 
16 Organizes TGButton widgets in a group.
17 A button group widget makes it easier to deal with groups of buttons.
18 A button in a button group is associated with a unique identifier.
19 The button group emits a Clicked() signal with this identifier when
20 the button is clicked. Thus, a button group is an ideal solution
21 when you have several similar buttons and want to connect all their
22 Clicked() signals, for example, to one slot.
23 
24 An exclusive button group switches off all toggle buttons except
25 the one that was clicked. A button group is by default non-exclusive.
26 All radio buttons that are inserted, will be mutually exclusive even
27 if the button group is non-exclusive.
28 
29 
30 There 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 
39 Example:
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 
55 NOTE: there is no need to call AddFrame() since the buttons are
56 automatically added with a default layout hint to their parent,
57 i.e. the buttongroup. To override the default layout hints use the
58 SetLayoutHints() 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 
76 Organizes TGButton widgets in a group with one horizontal row. TGHButtonGroup is a
77 convenience class that offers a thin layer on top of TGButtonGroup. It inherits from
78 TGButtonGroup.
79 
80 
81 \class TGVButtonGroup
82 \ingroup guiwidgets
83 
84 Organizes TGButton widgets in a group with one vertical column. TGVButtonGroup is a
85 convenience class that offers a thin layer on top of TGButtonGroup. It inherits from
86 TGButtonGroup.
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
156  fExclGroup = kFALSE;
157  fRadioExcl = kFALSE;
158  fDrawBorder = kTRUE;
159 
160  SetWindowName();
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]
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 {
335  item->SetState(kButtonDisabled);
336  }
337  }
338  DoRedraw();
339 }
340 ////////////////////////////////////////////////////////////////////////////////
341 /// Sets the button with id to be on/down, and if this is an
342 /// exclusive group, all other button in the group to be off/up.
343 
345 {
346  TGButton *b = Find(id);
347 
348  if (b && (b->IsDown() != down)) {
349  b->SetState(kButtonDown, kTRUE);
350  }
351 }
352 
353 ////////////////////////////////////////////////////////////////////////////////
354 /// Inserts a button with the identifier id into the button group.
355 /// Returns the button identifier.
356 ///
357 /// It is not necessary to manually insert buttons that have this button
358 /// group as their parent widget. An exception is when you want custom
359 /// identifiers instead of the default 1, 2, 3 etc.
360 ///
361 /// The button is assigned the identifier id or an automatically
362 /// generated identifier. It works as follows: If id > 0, this
363 /// identifier is assigned. If id == -1 (default), the identifier is
364 /// equal to the number of buttons in the group+1. If id is any other
365 /// negative integer, for instance -2, a unique identifier (negative
366 /// integer <= -2) is generated.
367 ///
368 /// Inserting several buttons with id = -1 assigns the identifiers 1,
369 /// 2, 3, etc.
370 
372 {
373  if (button->fGroup && button->fGroup != this)
374  button->fGroup->Remove(button);
375 
376  if (button->fGroup == this) {
377  if (id == -1)
378  return GetId(button); // the button is already in group
379  else
380  button->fGroup->Remove(button); // want to set a new id
381  }
382 
383  button->fGroup = this;
384  button->Associate(this);
385 
386  static Int_t seq_no = -2;
387  Long_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]
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 ((Long_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)Long_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 
482  TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
483  if (a) {
484  Int_t id = (Int_t)Long_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 
497  TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
498  if (a) {
499  Int_t id = (Int_t)Long_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 
512  TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
513  if (a) {
514  Int_t id = (Int_t)Long_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 {
551  MapSubwindows();
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);
577  TGGroupFrame::SetTitle(title);
578  ChangedBy("SetTitle");
579  }
580 }
581 
582 ////////////////////////////////////////////////////////////////////////////////
583 /// Set or change title.
584 
585 void 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));
594  TGGroupFrame::SetTitle(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 
619 void 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 
647  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
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 
682  TGFrameElement *f;
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 
716 void 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 
740  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
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 
765  TGFrameElement *f;
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 
803 void 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 
827  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
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 
851  TGFrameElement *f;
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 }
TGWindow::SetWindowName
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:129
TPair
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:102
c
#define c(i)
Definition: RSha256.hxx:101
l
auto * l
Definition: textangle.C:4
TQObject::ChangedBy
virtual void ChangedBy(const char *method)
Definition: TQObject.h:198
TGButtonGroup::Insert
virtual Int_t Insert(TGButton *button, int id=-1)
Inserts a button with the identifier id into the button group.
Definition: TGButtonGroup.cxx:371
TGButtonGroup::SetButton
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...
Definition: TGButtonGroup.cxx:344
TGFrame::GetHeight
UInt_t GetHeight() const
Definition: TGFrame.h:225
TGButtonGroup::ButtonReleased
virtual void ButtonReleased()
This slot is activated when one of the buttons in the group emits the Released() signal.
Definition: TGButtonGroup.cxx:493
TQObject::Disconnect
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:1027
TObject::SavePrimitive
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
TGFrameElement::fLayout
TGLayoutHints * fLayout
Definition: TGLayout.h:114
TGWindow
ROOT GUI Window base class.
Definition: TGWindow.h:23
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
TGButtonGroup::TGButtonGroup
TGButtonGroup(const TGButtonGroup &)=delete
TGGroupFrame::fTitlePos
Int_t fTitlePos
OPTION={GetMethod="GetTitlePos";SetMethod="SetTitlePos";Items=(-1="Left",0="Center",...
Definition: TGFrame.h:528
TGCompositeFrame::GetList
virtual TList * GetList() const
Definition: TGFrame.h:310
TGButtonGroup::Pressed
virtual void Pressed(Int_t id)
Definition: TGButtonGroup.h:56
TGCompositeFrame::GetLayoutManager
virtual TGLayoutManager * GetLayoutManager() const
Definition: TGFrame.h:338
TGButtonGroup::Released
virtual void Released(Int_t id)
Definition: TGButtonGroup.h:57
f
#define f(i)
Definition: RSha256.hxx:104
Option_t
const char Option_t
Definition: RtypesCore.h:66
TGButtonGroup::Show
virtual void Show()
Show group of buttons.
Definition: TGButtonGroup.cxx:549
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
kButtonDown
@ kButtonDown
Definition: TGButton.h:54
TString::Data
const char * Data() const
Definition: TString.h:369
TGLayout.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGFrame::fWidth
UInt_t fWidth
frame width
Definition: TGFrame.h:87
TGGC::SavePrimitive
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
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
FontStruct_t
Handle_t FontStruct_t
Pointer to font structure.
Definition: GuiTypes.h:39
TGButtonGroup::DrawBorder
virtual void DrawBorder()
Draw border of around the group frame.
Definition: TGButtonGroup.cxx:195
r
ROOT::R::TRInterface & r
Definition: Object.C:4
TGHorizontalLayout
Definition: TGLayout.h:187
TGButtonGroup::Clicked
virtual void Clicked(Int_t id)
Definition: TGButtonGroup.h:58
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
kButtonUp
@ kButtonUp
Definition: TGButton.h:53
TGFrame::fOptions
UInt_t fOptions
frame options
Definition: TGFrame.h:94
TMap::GetValue
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition: TMap.cxx:236
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
gTQSender
R__EXTERN void * gTQSender
Definition: TQObject.h:44
TGButtonGroup::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a button group widget as a C++ statement(s) on output stream out.
Definition: TGButtonGroup.cxx:619
Int_t
int Int_t
Definition: RtypesCore.h:45
SafeDelete
#define SafeDelete(p)
Definition: RConfig.hxx:536
x
Double_t x[n]
Definition: legend1.C:17
TGButtonGroup::fState
Bool_t fState
kTRUE if group is enabled
Definition: TGButtonGroup.h:30
TClass.h
TList.h
TGFrame::GetDefaultFrameBackground
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:683
TVirtualX.h
TGButtonGroup::SetLayoutHints
virtual void SetLayoutHints(TGLayoutHints *l, TGButton *button=0)
Set layout hints for the specified button or if button=0 for all buttons.
Definition: TGButtonGroup.cxx:603
TGButton::IsOn
virtual Bool_t IsOn() const
Definition: TGButton.h:119
TGButtonGroup
Organizes TGButton widgets in a group.
Definition: TGButtonGroup.h:21
TGGroupFrame::kRight
@ kRight
Definition: TGFrame.h:541
TMap::Add
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
TString
Basic string class.
Definition: TString.h:136
TGFrame
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition: TGFrame.h:80
TGObject::GetId
Handle_t GetId() const
Definition: TGObject.h:37
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
b
#define b(i)
Definition: RSha256.hxx:100
TGButtonGroup::Remove
virtual void Remove(TGButton *button)
Removes a button from the button group.
Definition: TGButtonGroup.cxx:411
TGHButtonGroup
Organizes TGButton widgets in a group with one horizontal row.
Definition: TGButtonGroup.h:112
TGButtonGroup::GetCount
Int_t GetCount() const
Returns number of buttons in group.
Definition: TGButtonGroup.cxx:442
bool
TGFrame::GetWidth
UInt_t GetWidth() const
Definition: TGFrame.h:224
TGButton::fGroup
TGButtonGroup * fGroup
button group this button belongs to
Definition: TGButton.h:80
TGCompositeFrame::fList
TList * fList
container of frame elements
Definition: TGFrame.h:292
TGGroupFrame::SetTitle
virtual void SetTitle(TGString *title)
Set or change title of the group frame.
Definition: TGFrame.cxx:2282
id
XFontStruct * id
Definition: TGX11.cxx:109
TGButtonGroup::ButtonClicked
virtual void ButtonClicked()
This slot is activated when one of the buttons in the group emits the Clicked() signal.
Definition: TGButtonGroup.cxx:508
TGFrameElement::fFrame
TGFrame * fFrame
Definition: TGLayout.h:112
TGFrame::GetOptionString
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2480
TGLayoutManager
Frame layout manager.
Definition: TGLayout.h:135
TGFrame::GetOptions
virtual UInt_t GetOptions() const
Definition: TGFrame.h:197
TGWindow::DestroyWindow
virtual void DestroyWindow()
destroy window
Definition: TGWindow.cxx:192
GContext_t
Handle_t GContext_t
Graphics context handle.
Definition: GuiTypes.h:38
gClient
#define gClient
Definition: TGClient.h:157
TGString::GetLength
Int_t GetLength() const
Definition: TGString.h:29
TGVButtonGroup
Organizes TGButton widgets in a group with one vertical column.
Definition: TGButtonGroup.h:94
TString::Form
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2314
TGFrame::GetHilightGC
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition: TGFrame.cxx:755
TGButtonGroup::SetExclusive
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.
Definition: TGButtonGroup.cxx:299
TGButtonGroup::IsExclusive
Bool_t IsExclusive() const
Definition: TGButtonGroup.h:66
TQObject
This is the ROOT implementation of the Qt object communication mechanism (see also http://www....
Definition: TQObject.h:48
TGMatrixLayout
This layout managers does not make use of TGLayoutHints.
Definition: TGLayout.h:269
TGButtonGroup::ReleaseButtons
virtual void ReleaseButtons()
This slot is activated when one of the buttons in the exclusive group emits the Pressed() signal.
Definition: TGButtonGroup.cxx:523
TGButtonGroup::fDrawBorder
Bool_t fDrawBorder
kTRUE if border and title are drawn
Definition: TGButtonGroup.h:33
TGButtonGroup::SetBorderDrawn
virtual void SetBorderDrawn(Bool_t enable=kTRUE)
Makes border to be visible/invisible.
Definition: TGButtonGroup.cxx:283
TGButtonGroup::SetTitle
virtual void SetTitle(TGString *title)
Set or change title.
Definition: TGButtonGroup.cxx:568
kSunkenFrame
@ kSunkenFrame
Definition: GuiTypes.h:383
TGGroupFrame::fNormGC
GContext_t fNormGC
title graphics context
Definition: TGFrame.h:527
h
#define h(i)
Definition: RSha256.hxx:106
TGWindow::GetName
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:336
TGCompositeFrame::MapSubwindows
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1164
TGGC
Encapsulate a graphics context used in the low level graphics.
Definition: TGGC.h:22
TGWidget::Associate
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:72
gr
TGraphErrors * gr
Definition: legend1.C:25
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:605
TGObject::fId
Handle_t fId
X11/Win32 Window identifier.
Definition: TGObject.h:26
a
auto * a
Definition: textangle.C:12
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
Long_t
long Long_t
Definition: RtypesCore.h:54
TMap::FindObject
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:215
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition: TGLayout.h:50
TGFrame::SaveUserColor
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition: TGFrame.cxx:2453
TMap::Remove
TObject * Remove(TObject *key)
Remove the (key,value) pair with key from the map.
Definition: TMap.cxx:296
TGGroupFrame
A composite frame with a border and a title.
Definition: TGFrame.h:522
TGFrame::MapRaised
virtual void MapRaised()
map raised
Definition: TGFrame.h:205
TGButtonGroup.h
TGGroupFrame::GetDefaultFontStruct
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Definition: TGFrame.cxx:2311
y
Double_t y[n]
Definition: legend1.C:17
TGVButtonGroup::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a button group widget as a C++ statement(s) on output stream out.
Definition: TGButtonGroup.cxx:803
TGButtonGroup::fMapOfButtons
TMap * fMapOfButtons
map of button/id pairs in this group
Definition: TGButtonGroup.h:34
TGButtonGroup::SetState
virtual void SetState(Bool_t state=kTRUE)
Sets the state of all the buttons in the group to enable or disable.
Definition: TGButtonGroup.cxx:324
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TGCompositeFrame::RemoveFrame
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1149
TGButtonGroup::ButtonPressed
virtual void ButtonPressed()
This slot is activated when one of the buttons in the group emits the Pressed() signal.
Definition: TGButtonGroup.cxx:464
TGButtonGroup::SetRadioButtonExclusive
virtual void SetRadioButtonExclusive(Bool_t flag=kTRUE)
If enable is kTRUE, this button group will treat radio buttons as mutually exclusive,...
Definition: TGButtonGroup.cxx:313
TGCompositeFrame::SetLayoutManager
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition: TGFrame.cxx:1000
kRaisedFrame
@ kRaisedFrame
Definition: GuiTypes.h:384
unsigned int
TGButton::SetState
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition: TGButton.cxx:235
TGButtonGroup::Find
virtual TGButton * Find(Int_t id) const
Finds and returns a pointer to the button with the specified identifier id.
Definition: TGButtonGroup.cxx:427
TGButtonGroup::~TGButtonGroup
virtual ~TGButtonGroup()
Destructor, we do not delete the buttons.
Definition: TGButtonGroup.cxx:166
TGClient::NeedRedraw
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:374
TString::IsNull
Bool_t IsNull() const
Definition: TString.h:407
TGButtonGroup::IsRadioButtonExclusive
Bool_t IsRadioButtonExclusive() const
Definition: TGButtonGroup.h:67
TQObject::Connect
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
TGButtonGroup::Hide
virtual void Hide()
Hide group of buttons.
Definition: TGButtonGroup.cxx:560
TGFrame::UnmapWindow
virtual void UnmapWindow()
unmap window
Definition: TGFrame.h:206
TGButtonGroup::DoRedraw
virtual void DoRedraw()
Redraw the group frame.
Definition: TGButtonGroup.cxx:182
TGCompositeFrame::fgDefaultHints
static TGLayoutHints * fgDefaultHints
Definition: TGFrame.h:297
TGButton::SetGroup
virtual void SetGroup(TGButtonGroup *gr)
Sets new button-group for this button.
Definition: TGButton.cxx:322
TGObject::fClient
TGClient * fClient
Connection to display server.
Definition: TGObject.h:27
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TGGroupFrame::fFontStruct
FontStruct_t fFontStruct
title fontstruct
Definition: TGFrame.h:526
TGButtonGroup::IsBorderDrawn
Bool_t IsBorderDrawn() const
Definition: TGButtonGroup.h:68
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TGVerticalLayout
Definition: TGLayout.h:159
TGButton.h
TMap.h
TGString::Draw
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition: TGString.cxx:56
TGFrameElement
Definition: TGLayout.h:105
TGButtonGroup::fExclGroup
Bool_t fExclGroup
kTRUE if group is exclusive
Definition: TGButtonGroup.h:31
TGFrame::GetShadowGC
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:765
TGString::GetString
const char * GetString() const
Definition: TGString.h:30
TIter
Definition: TCollection.h:233
TGButton::SetOn
virtual void SetOn(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition: TGButton.h:120
TGGroupFrame::kCenter
@ kCenter
Definition: TGFrame.h:541
TGFont::SavePrimitive
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
TGResourcePool.h
TGButtonGroup::fRadioExcl
Bool_t fRadioExcl
kTRUE if radio buttons are exclusive
Definition: TGButtonGroup.h:32
TGFrame::fHeight
UInt_t fHeight
frame height
Definition: TGFrame.h:88
TGFrame::fBackground
Pixel_t fBackground
frame background color
Definition: TGFrame.h:95
TGButton
A button abstract base class.
Definition: TGButton.h:68
TGFont
Encapsulate fonts used in the GUI system.
Definition: TGFont.h:140
TGGroupFrame::fText
TGString * fText
title text
Definition: TGFrame.h:525
Class
void Class()
Definition: Class.C:29
ROOT::Math::detail::sep
@ sep
Definition: GenVectorIO.h:35
TGGroupFrame::kLeft
@ kLeft
Definition: TGFrame.h:541
TGGroupFrame::GetDefaultGC
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Definition: TGFrame.cxx:2321
TGButtonGroup::Init
void Init()
Default init.
Definition: TGButtonGroup.cxx:152
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1117
TGButtonGroup::IsEnabled
Bool_t IsEnabled() const
Definition: TGButtonGroup.h:65
TGString
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition: TGString.h:20
TGCompositeFrame::Layout
virtual void Layout()
Layout the elements of the composite frame.
Definition: TGFrame.cxx:1257
TGButton::IsToggleButton
virtual Bool_t IsToggleButton() const
Definition: TGButton.h:121
TGWindow::fParent
const TGWindow * fParent
Parent window.
Definition: TGWindow.h:28
kButtonDisabled
@ kButtonDisabled
Definition: TGButton.h:56
TGHButtonGroup::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a button group widget as a C++ statement(s) on output stream out.
Definition: TGButtonGroup.cxx:716
int
TMap
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:40