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 
46 FWLayoutBuilder::indent(int left /*= 2*/, int right /* = -1*/)
47 {
48  if (right < 0)
49  right = left;
50 
51  TGVerticalFrame *parent = m_framesStack.back();
52  TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY,
53  left, right, 0, 0);
54  m_currentHints = 0;
55  m_framesStack.push_back(new TGVerticalFrame(parent));
56  parent->AddFrame(m_framesStack.back(), hints);
57  return newRow().expand(true, false);
58 }
59 
61 TGVerticalFrame *
63 {
64  assert(m_framesStack.size());
65  return m_framesStack.back();
66 }
67 
71 {
72  assert(!m_framesStack.empty());
73  m_framesStack.pop_back();
74  return *this;
75 }
76 
82 {
83  m_floatLeft = true;
84  m_leftSpacing = spacing;
85  return *this;
86 }
87 
89 FWLayoutBuilder::spaceUp(size_t spacing)
90 {
91  if (m_currentHints)
92  m_currentHints->SetPadTop(spacing);
93  return *this;
94 }
95 
98 {
99  if (m_currentHints)
100  m_currentHints->SetPadBottom(spacing);
101  return *this;
102 }
103 
106 {
107  if (m_currentHints)
108  m_currentHints->SetPadLeft(spacing);
109  return *this;
110 }
111 
114 {
115  if (m_currentHints)
116  m_currentHints->SetPadRight(spacing);
117  return *this;
118 }
119 
120 
123 {
125  m_currentFrameHints->SetPadTop(spacing);
126  return *this;
127 }
128 
131 {
133  m_currentFrameHints->SetPadBottom(spacing);
134  return *this;
135 }
136 
139 {
141  m_currentFrameHints->SetPadLeft(spacing);
142  return *this;
143 }
144 
147 {
149  m_currentFrameHints->SetPadRight(spacing);
150  return *this;
151 }
152 
157 FWLayoutBuilder::expand(bool expandX /*= true*/, bool expandY /*= false*/)
158 {
159  UInt_t style = 0;
160  style |= expandX ? kLHintsExpandX : 0;
161  style |= expandY ? kLHintsExpandY : 0;
162 
163  if (m_currentHints)
164  m_currentHints->SetLayoutHints(style);
165  return *this;
166 }
167 
168 // Returns the next layout to be used.
169 TGLayoutHints *
171 {
172  if (m_floatLeft)
173  {
174  size_t left = m_leftSpacing;
175  m_floatLeft = false;
176  m_leftSpacing = 0;
177  assert(m_currentHints);
178  m_currentHints = new TGLayoutHints(kLHintsExpandX, left, 0,
179  m_currentHints->GetPadTop(), 0);
180  }
181  else
182  {
183  size_t top = m_topSpacing;
184  m_topSpacing = 3;
185  m_currentHints = new TGLayoutHints(kLHintsExpandX, 0, 0, top, 0);
186  }
187  return m_currentHints;
188 }
189 
190 TGCompositeFrame *
192 {
193  if (!isFloatingLeft())
194  newRow();
195 
196  return currentFrame();
197 }
198 
229  FWDialogBuilder *parent /*= 0*/, bool expandY)
230  : FWLayoutBuilder(window, expandY),
231  m_parent(parent),
232  m_tabs(0)
233 {}
234 
237 {
239  return *this;
240 }
241 
243 FWDialogBuilder::indent(int left /* = 2*/, int right /* = -1*/)
244 {
245  FWLayoutBuilder::indent(left, right);
246  return *this;
247 }
248 
251 {
253  return *this;
254 }
255 
257 FWDialogBuilder::addLabel(const char *text, size_t fontSize /*= 12*/,
258  size_t weight /*= 0*/, TGLabel **out /*= 0*/)
259 {
260  TGLabel *label = new TGLabel(nextFrame(), text);
261 
262  if (fontSize != 0)
263  {
264  FontStruct_t defaultFontStruct = label->GetDefaultFontStruct();
265  try
266  {
267  TGFontPool *pool = gClient->GetFontPool();
268  TGFont* defaultFont = pool->GetFont(defaultFontStruct);
269  FontAttributes_t attributes = defaultFont->GetFontAttributes();
270  label->SetTextFont(pool->GetFont(attributes.fFamily, fontSize,
271  attributes.fWeight, attributes.fSlant));
272  }
273  catch(...)
274  {
275  // Ignore exceptions.
276  }
277  }
278 
279  label->SetTextJustify(kTextLeft);
280 
281  TGLayoutHints *hints = nextHints();
282  UInt_t style = hints->GetLayoutHints() | kLHintsCenterY;
283  hints->SetLayoutHints(style);
284  currentFrame()->AddFrame(label, hints);
285 
286  return extract(label, out);
287 }
288 
290 FWDialogBuilder::addTextView(const char *defaultText /*= 0*/,
291  TGTextView **out /*= 0*/)
292 {
293  TGTextView *view = new TGTextView(nextFrame(), 100, 100);
294  if (defaultText)
295  view->AddLine(defaultText);
296  currentFrame()->AddFrame(view, nextHints());
297  expand(true, true);
298  return extract(view, out);
299 }
300 
302 FWDialogBuilder::addHtml(TGHtml **out /*= 0*/)
303 {
304  TGHtml *html = new TGHtml(nextFrame(), 100, 100);
305  currentFrame()->AddFrame(html, nextHints());
306  expand(true, true);
307  return extract(html, out);
308 }
309 
311 FWDialogBuilder::addTextEdit(const char *defaultText /*= 0*/,
312  TGTextEdit **out /*= 0 */)
313 {
314  TGTextEdit *edit = new TGTextEdit(nextFrame(), 100, 100);
315  if (defaultText)
316  edit->AddLine(defaultText);
317  currentFrame()->AddFrame(edit, nextHints());
318  expand(true, true);
319  return extract(edit, out);
320 }
321 
324  FWColorSelect **out /*= 0*/)
325 {
326  const char* graphicsLabel = " ";
327  FWColorSelect *widget = new FWColorSelect(nextFrame(), graphicsLabel,
328  0, manager, -1);
329 
330  currentFrame()->AddFrame(widget, nextHints());
331  widget->SetEnabled(kFALSE);
332 
333  return extract(widget, out);
334 }
335 
337 FWDialogBuilder::addHSlider(size_t size, TGHSlider **out /*= 0*/)
338 {
339  TGHSlider *slider = new TGHSlider(nextFrame(), size, kSlider1);
340  currentFrame()->AddFrame(slider, nextHints());
341  slider->SetRange(0, 100);
342  slider->SetPosition(100);
343  slider->SetEnabled(false);
344 
345  return extract(slider, out);
346 }
347 
349 FWDialogBuilder::addTextButton(const char *text, TGTextButton **out /*= 0*/)
350 {
351  TGTextButton *button = new TGTextButton(nextFrame(), text);
352  currentFrame()->AddFrame(button, nextHints());
353  button->SetEnabled(false);
354 
355  return extract(button, out);
356 }
357 
360  FWGUIValidatingTextEntry **out /*= 0*/)
361 {
363  currentFrame()->AddFrame(entry, nextHints());
364 
365  return extract(entry, out);
366 }
367 
369 FWDialogBuilder::addTextEntry(const char *defaultText,
370  TGTextEntry **out)
371 {
372  TGTextEntry *entry = new TGTextEntry(nextFrame());
373  currentFrame()->AddFrame(entry, nextHints());
374  entry->SetEnabled(kFALSE);
375 
376  return extract(entry, out);
377 }
378 
380 FWDialogBuilder::addNumberEntry(float defaultValue, size_t digits,
381  TGNumberFormat::EStyle style,
382  int min, int max,
383  TGNumberEntry **out /*= 0*/)
384 {
385  TGNumberEntry *entry = new TGNumberEntry(nextFrame(), defaultValue,
386  digits, -1, style,
387  TGNumberFormat::kNEAAnyNumber,
388  TGNumberFormat::kNELLimitMinMax,
389  min, max);
390  currentFrame()->AddFrame(entry, nextHints());
391  entry->GetNumberEntry()->SetEnabled(kFALSE);
392  entry->GetButtonUp()->SetEnabled(kFALSE);
393  entry->GetButtonDown()->SetEnabled(kFALSE);
394  return extract(entry, out);
395 }
396 
398 FWDialogBuilder::addCheckbox(const char *text, TGCheckButton **out /*= 0*/)
399 {
400  TGCheckButton *button = new TGCheckButton(nextFrame(), text);
401  button->SetState(kButtonDown, false);
402  button->SetEnabled(false);
403  currentFrame()->AddFrame(button, nextHints());
404 
405  return extract(button, out);
406 }
407 
410  FWTableWidget **out /*= 0*/)
411 {
412  expand(true, true);
413  TGCompositeFrame *frame = verticalFrame();
414  TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
415  FWTableWidget *table = new FWTableWidget(manager, frame);
416  frame->AddFrame(table, hints);
417  return extract(table, out);
418 }
419 
421 FWDialogBuilder::addHSeparator(size_t horizontalPadding /*= 4*/,
422  size_t verticalPadding /*= 3*/)
423 {
424  TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX,
425  horizontalPadding,
426  horizontalPadding,
427  verticalPadding,
428  verticalPadding);
429 
430  TGHorizontal3DLine* separator = new TGHorizontal3DLine(nextFrame(), 200, 2);
431  currentFrame()->AddFrame(separator, hints);
432  return newRow();
433 }
434 
455 {
456  // Calls to tabs cannot be nested within the same builder. Multiple
457  // builders are used to support nested tabs.
458  assert(!m_tabs);
459  expand(true, true);
460  m_tabs = new TGTab(nextFrame());
461  currentFrame()->AddFrame(m_tabs, nextHints());
462  expand(true, true);
463  return extract(m_tabs, out);
464 }
465 
468 {
469  // No untabs() without tabs().
470  assert(m_tabs);
471  m_tabs = 0;
472  return *this;
473 }
474 
480 {
481  TGCompositeFrame *tab = m_tabs->AddTab(label);
482 
483  FWDialogBuilder *builder = new FWDialogBuilder(tab, this, false);
484  return builder->newRow();
485 }
486 
491 {
493  delete this;
494  return *parent;
495 }
496 
498 FWDialogBuilder::floatLeft(size_t spacing /*= 3*/)
499 {
501  return *this;
502 }
503 
505 FWDialogBuilder::spaceUp(size_t spacing /*= 3*/)
506 {
507  FWLayoutBuilder::spaceUp(spacing);
508  return *this;
509 }
510 
512 FWDialogBuilder::spaceDown(size_t spacing /*= 3*/)
513 {
515  return *this;
516 }
517 
519 FWDialogBuilder::spaceUpDown(size_t spacing /*= 3*/)
520 {
521  FWLayoutBuilder::spaceUp(spacing);
523  return *this;
524 }
525 
528 {
530  return *this;
531 }
532 
535 {
537  return *this;
538 }
539 
542 {
545  return *this;
546 }
547 
548 
549 // Frame spacing
550 
552 FWDialogBuilder::frameSpaceUp(size_t spacing /*= 3*/)
553 {
555  return *this;
556 }
557 
559 FWDialogBuilder::frameSpaceDown(size_t spacing /*= 3*/)
560 {
562  return *this;
563 }
564 
566 FWDialogBuilder::frameSpaceUpDown(size_t spacing /*= 3*/)
567 {
570  return *this;
571 }
572 
575 {
577  return *this;
578 }
579 
582 {
584  return *this;
585 }
586 
589 {
592  return *this;
593 }
594 
595 
597 FWDialogBuilder::expand(size_t expandX /*= true*/, size_t expandY /*= false*/)
598 {
599  FWLayoutBuilder::expand(expandX, expandY);
600  return *this;
601 }
602 
605 {
606  newRow().expand(true, true);
607 
608  TGFrame *frame;
609  if (size)
610  frame = new TGFrame(nextFrame(), 1, size);
611  else
612  frame = new TGFrame(nextFrame());
613 
614  currentFrame()->AddFrame(frame, nextHints());
615 
616  expand(true, true);
617 
618  return *this;
619 }
620 
621 
624 {
625  TGFrame *frame;
626  if (size)
627  frame = new TGFrame(nextFrame(), size, 1);
628  else
629  frame = new TGFrame(nextFrame());
630 
631  currentFrame()->AddFrame(frame, nextHints());
632 
633  if (!size)
634  expand(true, false);
635  else
636  expand(false, false);
637 
638  return *this;
639 }
FWDialogBuilder & spaceUp(size_t spacing=3)
list table
Definition: asciidump.py:386
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)
list parent
Definition: dbtoconf.py:74
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)
FWLayoutBuilder & frameSpaceRight(size_t spacing)
FWLayoutBuilder & spaceRight(size_t spacing)
std::vector< TGVerticalFrame * > m_framesStack
#define min(a, b)
Definition: mlp_lapack.h:161
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)
const T & max(const T &a, const T &b)
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)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
TGLayoutHints * m_currentFrameHints
list attributes
Definition: asciidump.py:415
FWDialogBuilder & addTextView(const char *defaultText=0, TGTextView **out=0)
tuple tab
Definition: accesses.py:4
FWLayoutBuilder & unindent(void)
FWDialogBuilder & spaceUpDown(size_t spacing=3)
tuple text
Definition: runonSM.py:42
FWDialogBuilder & newRow()
TGCompositeFrame * currentFrame(void)
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)
tuple out
Definition: dbtoconf.py:99
unsigned int UInt_t
Definition: FUTypes.h:12
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
FWLayoutBuilder & expand(bool expandX=true, bool expandY=false)
FWDialogBuilder & beginTab(const char *label)
FWDialogBuilder & addHtml(TGHtml **out=0)
int weight
Definition: histoStyle.py:50
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)