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