CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWDialogBuilder.cc
Go to the documentation of this file.
6 
7 
8 #include "TGFrame.h"
9 #include "TGLabel.h"
10 #include "TGButton.h"
11 #include "TG3DLine.h"
12 #include "TGLViewer.h"
13 #include "TGSlider.h"
14 #include "TGTab.h"
15 #include "TGTextView.h"
16 #include "TGTextEdit.h"
17 #include "TGNumberEntry.h"
18 #include "TGHtml.h"
19 
20 FWLayoutBuilder::FWLayoutBuilder(TGCompositeFrame *window, bool expandY)
21  : m_window(window),
22  m_currentFrame(0),
23  m_floatLeft(false),
24  m_topSpacing(0),
25  m_leftSpacing(0),
26  m_currentHints(0),
27  m_currentFrameHints(0)
28 {
29  TGVerticalFrame *mainFrame = new TGVerticalFrame(window);
30  TGLayoutHints *hints = new TGLayoutHints(expandY ? kLHintsExpandX|kLHintsExpandY : kLHintsExpandX,
31  0, 0, 0, 0);
32  m_window->AddFrame(mainFrame, hints);
33  m_framesStack.push_back(mainFrame);
34 }
35 
38 {
39  m_currentFrameHints = m_currentHints = new TGLayoutHints(kLHintsExpandX);
40  m_currentFrame = new TGHorizontalFrame(m_framesStack.back());
41  m_framesStack.back()->AddFrame(m_currentFrame, m_currentHints);
42  return *this;
43 }
44 
45 
46 
48 FWLayoutBuilder::indent(int left /*= 2*/, int right /* = -1*/)
49 {
50  if (right < 0)
51  right = left;
52 
53  TGVerticalFrame *parent = m_framesStack.back();
54  TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY,
55  left, right, 0, 0);
56  m_currentHints = 0;
57  m_framesStack.push_back(new TGVerticalFrame(parent));
58  parent->AddFrame(m_framesStack.back(), hints);
59  return newRow().expand(true, false);
60 }
61 
63 TGVerticalFrame *
65 {
66  assert(m_framesStack.size());
67  return m_framesStack.back();
68 }
69 
73 {
74  assert(!m_framesStack.empty());
75  m_framesStack.pop_back();
76  return *this;
77 }
78 
84 {
85  m_floatLeft = true;
86  m_leftSpacing = spacing;
87  return *this;
88 }
89 
91 FWLayoutBuilder::spaceUp(size_t spacing)
92 {
93  if (m_currentHints)
94  m_currentHints->SetPadTop(spacing);
95  return *this;
96 }
97 
100 {
101  if (m_currentHints)
102  m_currentHints->SetPadBottom(spacing);
103  return *this;
104 }
105 
108 {
109  if (m_currentHints)
110  m_currentHints->SetPadLeft(spacing);
111  return *this;
112 }
113 
116 {
117  if (m_currentHints)
118  m_currentHints->SetPadRight(spacing);
119  return *this;
120 }
121 
122 
125 {
127  m_currentFrameHints->SetPadTop(spacing);
128  return *this;
129 }
130 
133 {
135  m_currentFrameHints->SetPadBottom(spacing);
136  return *this;
137 }
138 
141 {
143  m_currentFrameHints->SetPadLeft(spacing);
144  return *this;
145 }
146 
149 {
151  m_currentFrameHints->SetPadRight(spacing);
152  return *this;
153 }
154 
159 FWLayoutBuilder::expand(bool expandX /*= true*/, bool expandY /*= false*/)
160 {
161  UInt_t style = 0;
162  style |= expandX ? kLHintsExpandX : 0;
163  style |= expandY ? kLHintsExpandY : 0;
164 
165  if (m_currentHints)
166  m_currentHints->SetLayoutHints(style);
167  return *this;
168 }
169 
170 // Returns the next layout to be used.
171 TGLayoutHints *
173 {
174  if (m_floatLeft)
175  {
176  size_t left = m_leftSpacing;
177  m_floatLeft = false;
178  m_leftSpacing = 0;
180  m_currentHints = new TGLayoutHints(kLHintsExpandX, left, 0,
181  m_currentHints->GetPadTop(), 0);
182  }
183  else
184  {
185  size_t top = m_topSpacing;
186  m_topSpacing = 3;
187  m_currentHints = new TGLayoutHints(kLHintsExpandX, 0, 0, top, 0);
188  }
189  return m_currentHints;
190 }
191 
192 TGCompositeFrame *
194 {
195  if (!isFloatingLeft())
196  newRow();
197 
198  return currentFrame();
199 }
200 
201 void
203 {
204  m_currentFrame = new TGVerticalFrame(m_framesStack.back());
205  m_currentFrame->SetBackgroundColor(0x000000);
206  m_framesStack.back()->AddFrame(m_currentFrame, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY));
207  // m_frameStack.push_back(m_currentFrame);
208 }
209 
210 
211 
242  FWDialogBuilder *parent /*= 0*/, bool expandY)
243  : FWLayoutBuilder(window, expandY),
244  m_parent(parent),
245  m_tabs(0)
246 {}
247 
250 {
252  return *this;
253 }
254 
256 FWDialogBuilder::indent(int left /* = 2*/, int right /* = -1*/)
257 {
258  FWLayoutBuilder::indent(left, right);
259  return *this;
260 }
261 
264 {
266  return *this;
267 }
268 
270 FWDialogBuilder::addLabel(const char *text, size_t fontSize /*= 12*/,
271  size_t weight /*= 0*/, TGLabel **out /*= 0*/)
272 {
273  TGLabel *label = new TGLabel(nextFrame(), text);
274 
275  if (fontSize != 0)
276  {
277  FontStruct_t defaultFontStruct = label->GetDefaultFontStruct();
278  try
279  {
280  TGFontPool *pool = gClient->GetFontPool();
281  TGFont* defaultFont = pool->GetFont(defaultFontStruct);
282  FontAttributes_t attributes = defaultFont->GetFontAttributes();
283  label->SetTextFont(pool->GetFont(attributes.fFamily, fontSize,
284  attributes.fWeight, attributes.fSlant));
285  }
286  catch(...)
287  {
288  // Ignore exceptions.
289  }
290  }
291 
292  label->SetTextJustify(kTextLeft);
293 
294  TGLayoutHints *hints = nextHints();
295  UInt_t style = hints->GetLayoutHints() | kLHintsCenterY;
296  hints->SetLayoutHints(style);
297  currentFrame()->AddFrame(label, hints);
298 
299  return extract(label, out);
300 }
301 
303 FWDialogBuilder::addTextView(const char *defaultText /*= 0*/,
304  TGTextView **out /*= 0*/)
305 {
306  TGTextView *view = new TGTextView(nextFrame(), 100, 100);
307  if (defaultText)
308  view->AddLine(defaultText);
309  currentFrame()->AddFrame(view, nextHints());
310  expand(true, true);
311  return extract(view, out);
312 }
313 
315 FWDialogBuilder::addHtml(TGHtml **out /*= 0*/)
316 {
317  TGHtml *html = new TGHtml(nextFrame(), 100, 100);
318  currentFrame()->AddFrame(html, nextHints());
319  expand(true, true);
320  return extract(html, out);
321 }
322 
324 FWDialogBuilder::addTextEdit(const char *defaultText /*= 0*/,
325  TGTextEdit **out /*= 0 */)
326 {
327  TGTextEdit *edit = new TGTextEdit(nextFrame(), 100, 100);
328  if (defaultText)
329  edit->AddLine(defaultText);
330  currentFrame()->AddFrame(edit, nextHints());
331  expand(true, true);
332  return extract(edit, out);
333 }
334 
337  FWColorSelect **out /*= 0*/)
338 {
339  const char* graphicsLabel = " ";
340  FWColorSelect *widget = new FWColorSelect(nextFrame(), graphicsLabel,
341  0, manager, -1);
342 
343  currentFrame()->AddFrame(widget, nextHints());
344  widget->SetEnabled(kFALSE);
345 
346  return extract(widget, out);
347 }
348 
350 FWDialogBuilder::addHSlider(size_t size, TGHSlider **out /*= 0*/)
351 {
352  TGHSlider *slider = new TGHSlider(nextFrame(), size, kSlider1);
353  currentFrame()->AddFrame(slider, nextHints());
354  slider->SetRange(0, 100);
355  slider->SetPosition(100);
356  slider->SetEnabled(false);
357 
358  return extract(slider, out);
359 }
360 
362 FWDialogBuilder::addTextButton(const char *text, TGTextButton **out /*= 0*/)
363 {
364  TGTextButton *button = new TGTextButton(nextFrame(), text);
365  currentFrame()->AddFrame(button, nextHints());
366  button->SetEnabled(false);
367 
368  return extract(button, out);
369 }
370 
373  FWGUIValidatingTextEntry **out /*= 0*/)
374 {
376  currentFrame()->AddFrame(entry, nextHints());
377 
378  return extract(entry, out);
379 }
380 
382 FWDialogBuilder::addTextEntry(const char *defaultText,
383  TGTextEntry **out)
384 {
385  TGTextEntry *entry = new TGTextEntry(nextFrame());
386  currentFrame()->AddFrame(entry, nextHints());
387  entry->SetEnabled(kFALSE);
388 
389  return extract(entry, out);
390 }
391 
393 FWDialogBuilder::addNumberEntry(float defaultValue, size_t digits,
394  TGNumberFormat::EStyle style,
395  int min, int max,
396  TGNumberEntry **out /*= 0*/)
397 {
398  TGNumberEntry *entry = new TGNumberEntry(nextFrame(), defaultValue,
399  digits, -1, style,
400  TGNumberFormat::kNEAAnyNumber,
401  TGNumberFormat::kNELLimitMinMax,
402  min, max);
403  currentFrame()->AddFrame(entry, nextHints());
404  entry->GetNumberEntry()->SetEnabled(kFALSE);
405  entry->GetButtonUp()->SetEnabled(kFALSE);
406  entry->GetButtonDown()->SetEnabled(kFALSE);
407  return extract(entry, out);
408 }
409 
411 FWDialogBuilder::addCheckbox(const char *text, TGCheckButton **out /*= 0*/)
412 {
413  TGCheckButton *button = new TGCheckButton(nextFrame(), text);
414  button->SetState(kButtonDown, false);
415  button->SetEnabled(false);
416  currentFrame()->AddFrame(button, nextHints());
417 
418  return extract(button, out);
419 }
420 
423  FWTableWidget **out /*= 0*/)
424 {
425  expand(true, true);
426  TGCompositeFrame *frame = verticalFrame();
427  TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
428  FWTableWidget *table = new FWTableWidget(manager, frame);
429  frame->AddFrame(table, hints);
430  return extract(table, out);
431 }
432 
434 FWDialogBuilder::addHSeparator(size_t horizontalPadding /*= 4*/,
435  size_t verticalPadding /*= 3*/)
436 {
437  TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX,
438  horizontalPadding,
439  horizontalPadding,
440  verticalPadding,
441  verticalPadding);
442 
443  TGHorizontal3DLine* separator = new TGHorizontal3DLine(nextFrame(), 200, 2);
444  currentFrame()->AddFrame(separator, hints);
445  return newRow();
446 }
447 
468 {
469 
470  // m_currentFrame = new TGVerticalFrame(m_framesStack.back());
471  //m_framesStack.back()->AddFrame(m_currentFrame, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY));
472  frameForTab();
473 
474  m_tabs = new TGTab(currentFrame());
475  currentFrame()->AddFrame(m_tabs, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY));
476  //expand(true, true);
477  return extract(m_tabs, out);
478 }
479 
482 {
483  // No untabs() without tabs().
484  assert(m_tabs);
485  m_tabs = 0;
486  return *this;
487 }
488 
494 {
495  TGCompositeFrame *tab = m_tabs->AddTab(label);
496 
497  FWDialogBuilder *builder = new FWDialogBuilder(tab, this, false);
498  return builder->newRow();
499 }
500 
505 {
506  FWDialogBuilder *parent = m_parent;
507  delete this;
508  return *parent;
509 }
510 
512 FWDialogBuilder::floatLeft(size_t spacing /*= 3*/)
513 {
515  return *this;
516 }
517 
519 FWDialogBuilder::spaceUp(size_t spacing /*= 3*/)
520 {
521  FWLayoutBuilder::spaceUp(spacing);
522  return *this;
523 }
524 
526 FWDialogBuilder::spaceDown(size_t spacing /*= 3*/)
527 {
529  return *this;
530 }
531 
533 FWDialogBuilder::spaceUpDown(size_t spacing /*= 3*/)
534 {
535  FWLayoutBuilder::spaceUp(spacing);
537  return *this;
538 }
539 
542 {
544  return *this;
545 }
546 
549 {
551  return *this;
552 }
553 
556 {
559  return *this;
560 }
561 
562 
563 // Frame spacing
564 
566 FWDialogBuilder::frameSpaceUp(size_t spacing /*= 3*/)
567 {
569  return *this;
570 }
571 
573 FWDialogBuilder::frameSpaceDown(size_t spacing /*= 3*/)
574 {
576  return *this;
577 }
578 
580 FWDialogBuilder::frameSpaceUpDown(size_t spacing /*= 3*/)
581 {
584  return *this;
585 }
586 
589 {
591  return *this;
592 }
593 
596 {
598  return *this;
599 }
600 
603 {
606  return *this;
607 }
608 
609 
611 FWDialogBuilder::expand(size_t expandX /*= true*/, size_t expandY /*= false*/)
612 {
613  FWLayoutBuilder::expand(expandX, expandY);
614  return *this;
615 }
616 
619 {
620  newRow().expand(true, true);
621 
622  TGFrame *frame;
623  if (size)
624  frame = new TGFrame(nextFrame(), 1, size);
625  else
626  frame = new TGFrame(nextFrame());
627 
628  currentFrame()->AddFrame(frame, nextHints());
629 
630  expand(true, true);
631 
632  return *this;
633 }
634 
635 
638 {
639  TGFrame *frame;
640  if (size)
641  frame = new TGFrame(nextFrame(), size, 1);
642  else
643  frame = new TGFrame(nextFrame());
644 
645  currentFrame()->AddFrame(frame, nextHints());
646 
647  if (!size)
648  expand(true, false);
649  else
650  expand(false, false);
651 
652  return *this;
653 }
FWDialogBuilder & spaceUp(size_t spacing=3)
TGVerticalFrame * verticalFrame()
TGCompositeFrame * m_window
def window
Definition: svgfig.py:642
FWDialogBuilder & addHSlider(size_t size, TGHSlider **out=0)
FWDialogBuilder & frameSpaceUp(size_t spacing=3)
FWDialogBuilder & extract(T *in, T **out)
FWDialogBuilder(TGCompositeFrame *window, FWDialogBuilder *parent=0, bool expandY=true)
TGCompositeFrame * nextFrame()
FWDialogBuilder & endTab(void)
FWDialogBuilder & frameSpaceRight(size_t spacing=3)
FWDialogBuilder & addLabel(const char *text, size_t fontSize=12, size_t weight=0, TGLabel **out=0)
FWDialogBuilder & spaceLeftRight(size_t spacing=3)
assert(m_qm.get())
FWLayoutBuilder & frameSpaceRight(size_t spacing)
FWLayoutBuilder & spaceRight(size_t spacing)
std::vector< TGVerticalFrame * > m_framesStack
FWLayoutBuilder(TGCompositeFrame *window, bool expandY=true)
TGLayoutHints * m_currentHints
FWLayoutBuilder & frameSpaceDown(size_t spacing)
FWDialogBuilder & addTable(FWTableManagerBase *manager, FWTableWidget **out=0)
FWDialogBuilder & vSpacer(size_t size=0)
FWDialogBuilder & untabs(void)
FWLayoutBuilder & frameSpaceUp(size_t spacing)
FWLayoutBuilder & spaceUp(size_t spacing)
FWDialogBuilder & frameSpaceLeftRight(size_t spacing=3)
TGCompositeFrame * m_currentFrame
FWDialogBuilder & frameSpaceDown(size_t spacing=3)
FWLayoutBuilder & floatLeft(size_t spacing)
FWDialogBuilder & addTextButton(const char *text, TGTextButton **out=0)
FWDialogBuilder & frameSpaceUpDown(size_t spacing=3)
FWDialogBuilder & addTextEdit(const char *defaultText=0, TGTextEdit **out=0)
TGLayoutHints * m_currentFrameHints
FWDialogBuilder & addTextView(const char *defaultText=0, TGTextView **out=0)
FWLayoutBuilder & unindent(void)
FWDialogBuilder & spaceUpDown(size_t spacing=3)
tuple text
Definition: runonSM.py:42
FWDialogBuilder & newRow()
TGCompositeFrame * currentFrame(void)
T min(T a, T b)
Definition: MathUtil.h:58
FWDialogBuilder & addHSeparator(size_t horizontalPadding=4, size_t verticalPadding=3)
FWLayoutBuilder & indent(int left=2, int right=-1)
FWDialogBuilder & tabs(TGTab **out)
FWDialogBuilder & spaceLeft(size_t spacing=3)
FWDialogBuilder & addValidatingTextEntry(const char *defaultText, FWGUIValidatingTextEntry **out)
FWDialogBuilder & hSpacer(size_t size=0)
FWDialogBuilder & addTextEntry(const char *defaultText, TGTextEntry **out)
FWLayoutBuilder & newRow()
FWDialogBuilder & frameSpaceLeft(size_t spacing=3)
FWDialogBuilder & unindent(void)
FWDialogBuilder & floatLeft(size_t spacing=3)
FWDialogBuilder & expand(size_t expandX=true, size_t expandY=false)
TGLayoutHints * nextHints()
FWLayoutBuilder & spaceDown(size_t spacing)
FWDialogBuilder * m_parent
list entry
Definition: mps_splice.py:62
FWLayoutBuilder & expand(bool expandX=true, bool expandY=false)
FWDialogBuilder & beginTab(const char *label)
FWDialogBuilder & addHtml(TGHtml **out=0)
volatile std::atomic< bool > shutdown_flag false
FWDialogBuilder & addCheckbox(const char *text, TGCheckButton **out=0)
FWDialogBuilder & indent(int left=2, int right=-1)
FWDialogBuilder & addNumberEntry(float defaultValue, size_t digits, TGNumberFormat::EStyle style, int min, int max, TGNumberEntry **out)
tuple size
Write out results.
FWDialogBuilder & spaceDown(size_t spacing=3)
FWLayoutBuilder & spaceLeft(size_t spacing)
FWLayoutBuilder & frameSpaceLeft(size_t spacing)
FWDialogBuilder & spaceRight(size_t spacing=3)
FWDialogBuilder & addColorPicker(const FWColorManager *manager, FWColorSelect **out=0)