CMS 3D CMS Logo

FWDialogBuilder.cc
Go to the documentation of this file.
6 
7 #include "TGFrame.h"
8 #include "TGLabel.h"
9 #include "TGButton.h"
10 #include "TG3DLine.h"
11 #include "TGLViewer.h"
12 #include "TGSlider.h"
13 #include "TGTab.h"
14 #include "TGTextView.h"
15 #include "TGTextEdit.h"
16 #include "TGNumberEntry.h"
17 #include "TGHtml.h"
18 
19 FWLayoutBuilder::FWLayoutBuilder(TGCompositeFrame *window, bool expandY)
20  : m_window(window),
21  m_currentFrame(nullptr),
22  m_floatLeft(false),
23  m_topSpacing(0),
24  m_leftSpacing(0),
25  m_currentHints(nullptr),
26  m_currentFrameHints(nullptr) {
27  TGVerticalFrame *mainFrame = new TGVerticalFrame(window);
28  TGLayoutHints *hints = new TGLayoutHints(expandY ? kLHintsExpandX | kLHintsExpandY : kLHintsExpandX, 0, 0, 0, 0);
29  m_window->AddFrame(mainFrame, hints);
30  m_framesStack.push_back(mainFrame);
31 }
32 
34  m_currentFrameHints = m_currentHints = new TGLayoutHints(kLHintsExpandX);
35  m_currentFrame = new TGHorizontalFrame(m_framesStack.back());
36  m_framesStack.back()->AddFrame(m_currentFrame, m_currentHints);
37  return *this;
38 }
39 
40 FWLayoutBuilder &FWLayoutBuilder::indent(int left /*= 2*/, int right /* = -1*/) {
41  if (right < 0)
42  right = left;
43 
44  TGVerticalFrame *parent = m_framesStack.back();
45  TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, left, right, 0, 0);
46  m_currentHints = nullptr;
47  m_framesStack.push_back(new TGVerticalFrame(parent));
48  parent->AddFrame(m_framesStack.back(), hints);
49  return newRow().expand(true, false);
50 }
51 
53 TGVerticalFrame *FWLayoutBuilder::verticalFrame(void) {
54  assert(!m_framesStack.empty());
55  return m_framesStack.back();
56 }
57 
60  assert(!m_framesStack.empty());
61  m_framesStack.pop_back();
62  return *this;
63 }
64 
69  m_floatLeft = true;
70  m_leftSpacing = spacing;
71  return *this;
72 }
73 
75  if (m_currentHints)
76  m_currentHints->SetPadTop(spacing);
77  return *this;
78 }
79 
81  if (m_currentHints)
82  m_currentHints->SetPadBottom(spacing);
83  return *this;
84 }
85 
87  if (m_currentHints)
88  m_currentHints->SetPadLeft(spacing);
89  return *this;
90 }
91 
93  if (m_currentHints)
94  m_currentHints->SetPadRight(spacing);
95  return *this;
96 }
97 
100  m_currentFrameHints->SetPadTop(spacing);
101  return *this;
102 }
103 
106  m_currentFrameHints->SetPadBottom(spacing);
107  return *this;
108 }
109 
112  m_currentFrameHints->SetPadLeft(spacing);
113  return *this;
114 }
115 
118  m_currentFrameHints->SetPadRight(spacing);
119  return *this;
120 }
121 
125 FWLayoutBuilder &FWLayoutBuilder::expand(bool expandX /*= true*/, bool expandY /*= false*/) {
126  UInt_t style = 0;
127  style |= expandX ? kLHintsExpandX : 0;
128  style |= expandY ? kLHintsExpandY : 0;
129 
130  if (m_currentHints)
131  m_currentHints->SetLayoutHints(style);
132  return *this;
133 }
134 
135 // Returns the next layout to be used.
136 TGLayoutHints *FWLayoutBuilder::nextHints() {
137  if (m_floatLeft) {
138  size_t left = m_leftSpacing;
139  m_floatLeft = false;
140  m_leftSpacing = 0;
142  m_currentHints = new TGLayoutHints(kLHintsExpandX, left, 0, m_currentHints->GetPadTop(), 0);
143  } else {
144  size_t top = m_topSpacing;
145  m_topSpacing = 3;
146  m_currentHints = new TGLayoutHints(kLHintsExpandX, 0, 0, top, 0);
147  }
148  return m_currentHints;
149 }
150 
151 TGCompositeFrame *FWLayoutBuilder::nextFrame() {
152  if (!isFloatingLeft())
153  newRow();
154 
155  return currentFrame();
156 }
157 
159  m_currentFrame = new TGVerticalFrame(m_framesStack.back());
160  m_currentFrame->SetBackgroundColor(0x000000);
161  m_framesStack.back()->AddFrame(m_currentFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
162  // m_frameStack.push_back(m_currentFrame);
163 }
164 
194 FWDialogBuilder::FWDialogBuilder(TGCompositeFrame *window, FWDialogBuilder *parent /*= 0*/, bool expandY)
195  : FWLayoutBuilder(window, expandY), m_parent(parent), m_tabs(nullptr) {}
196 
199  return *this;
200 }
201 
202 FWDialogBuilder &FWDialogBuilder::indent(int left /* = 2*/, int right /* = -1*/) {
203  FWLayoutBuilder::indent(left, right);
204  return *this;
205 }
206 
209  return *this;
210 }
211 
213  size_t fontSize /*= 12*/,
214  size_t weight /*= 0*/,
215  TGLabel **out /*= 0*/) {
216  TGLabel *label = new TGLabel(nextFrame(), text);
217 
218  if (fontSize != 0) {
219  FontStruct_t defaultFontStruct = label->GetDefaultFontStruct();
220  try {
221  TGFontPool *pool = gClient->GetFontPool();
222  TGFont *defaultFont = pool->GetFont(defaultFontStruct);
223  FontAttributes_t attributes = defaultFont->GetFontAttributes();
224  label->SetTextFont(pool->GetFont(attributes.fFamily, fontSize, attributes.fWeight, attributes.fSlant));
225  } catch (...) {
226  // Ignore exceptions.
227  }
228  }
229 
230  label->SetTextJustify(kTextLeft);
231 
232  TGLayoutHints *hints = nextHints();
233  UInt_t style = hints->GetLayoutHints() | kLHintsCenterY;
234  hints->SetLayoutHints(style);
235  currentFrame()->AddFrame(label, hints);
236 
237  return extract(label, out);
238 }
239 
240 FWDialogBuilder &FWDialogBuilder::addTextView(const char *defaultText /*= 0*/, TGTextView **out /*= 0*/) {
241  TGTextView *view = new TGTextView(nextFrame(), 100, 100);
242  if (defaultText)
243  view->AddLine(defaultText);
244  currentFrame()->AddFrame(view, nextHints());
245  expand(true, true);
246  return extract(view, out);
247 }
248 
250  TGHtml *html = new TGHtml(nextFrame(), 100, 100);
251  currentFrame()->AddFrame(html, nextHints());
252  expand(true, true);
253  return extract(html, out);
254 }
255 
256 FWDialogBuilder &FWDialogBuilder::addTextEdit(const char *defaultText /*= 0*/, TGTextEdit **out /*= 0 */) {
257  TGTextEdit *edit = new TGTextEdit(nextFrame(), 100, 100);
258  if (defaultText)
259  edit->AddLine(defaultText);
260  currentFrame()->AddFrame(edit, nextHints());
261  expand(true, true);
262  return extract(edit, out);
263 }
264 
266  const char *graphicsLabel = " ";
267  FWColorSelect *widget = new FWColorSelect(nextFrame(), graphicsLabel, 0, manager, -1);
268 
269  currentFrame()->AddFrame(widget, nextHints());
270  widget->SetEnabled(kFALSE);
271 
272  return extract(widget, out);
273 }
274 
275 FWDialogBuilder &FWDialogBuilder::addHSlider(size_t size, TGHSlider **out /*= 0*/) {
276  TGHSlider *slider = new TGHSlider(nextFrame(), size, kSlider1);
277  currentFrame()->AddFrame(slider, nextHints());
278  slider->SetRange(0, 100);
279  slider->SetPosition(100);
280  slider->SetEnabled(false);
281 
282  return extract(slider, out);
283 }
284 
285 FWDialogBuilder &FWDialogBuilder::addTextButton(const char *text, TGTextButton **out /*= 0*/) {
286  TGTextButton *button = new TGTextButton(nextFrame(), text);
287  currentFrame()->AddFrame(button, nextHints());
288  button->SetEnabled(false);
289 
290  return extract(button, out);
291 }
292 
294  FWGUIValidatingTextEntry **out /*= 0*/) {
296  currentFrame()->AddFrame(entry, nextHints());
297 
298  return extract(entry, out);
299 }
300 
301 FWDialogBuilder &FWDialogBuilder::addTextEntry(const char *defaultText, TGTextEntry **out) {
302  TGTextEntry *entry = new TGTextEntry(nextFrame());
303  currentFrame()->AddFrame(entry, nextHints());
304  entry->SetEnabled(kFALSE);
305 
306  return extract(entry, out);
307 }
308 
310  float defaultValue, size_t digits, TGNumberFormat::EStyle style, int min, int max, TGNumberEntry **out /*= 0*/) {
311  TGNumberEntry *entry = new TGNumberEntry(nextFrame(),
312  defaultValue,
313  digits,
314  -1,
315  style,
316  TGNumberFormat::kNEAAnyNumber,
317  TGNumberFormat::kNELLimitMinMax,
318  min,
319  max);
320  currentFrame()->AddFrame(entry, nextHints());
321  entry->GetNumberEntry()->SetEnabled(kFALSE);
322  entry->GetButtonUp()->SetEnabled(kFALSE);
323  entry->GetButtonDown()->SetEnabled(kFALSE);
324  return extract(entry, out);
325 }
326 
327 FWDialogBuilder &FWDialogBuilder::addCheckbox(const char *text, TGCheckButton **out /*= 0*/) {
328  TGCheckButton *button = new TGCheckButton(nextFrame(), text);
329  button->SetState(kButtonDown, false);
330  button->SetEnabled(false);
331  currentFrame()->AddFrame(button, nextHints());
332 
333  return extract(button, out);
334 }
335 
337  expand(true, true);
338  TGCompositeFrame *frame = verticalFrame();
339  TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
340  FWTableWidget *table = new FWTableWidget(manager, frame);
341  frame->AddFrame(table, hints);
342  return extract(table, out);
343 }
344 
345 FWDialogBuilder &FWDialogBuilder::addHSeparator(size_t horizontalPadding /*= 4*/, size_t verticalPadding /*= 3*/) {
346  TGLayoutHints *hints =
347  new TGLayoutHints(kLHintsExpandX, horizontalPadding, horizontalPadding, verticalPadding, verticalPadding);
348 
349  TGHorizontal3DLine *separator = new TGHorizontal3DLine(nextFrame(), 200, 2);
350  currentFrame()->AddFrame(separator, hints);
351  return newRow();
352 }
353 
373  // m_currentFrame = new TGVerticalFrame(m_framesStack.back());
374  //m_framesStack.back()->AddFrame(m_currentFrame, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY));
375  frameForTab();
376 
377  m_tabs = new TGTab(currentFrame());
378  currentFrame()->AddFrame(m_tabs, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
379  //expand(true, true);
380  return extract(m_tabs, out);
381 }
382 
384  // No untabs() without tabs().
385  assert(m_tabs);
386  m_tabs = nullptr;
387  return *this;
388 }
389 
394  TGCompositeFrame *tab = m_tabs->AddTab(label);
395 
396  FWDialogBuilder *builder = new FWDialogBuilder(tab, this, false);
397  return builder->newRow();
398 }
399 
404  delete this;
405  return *parent;
406 }
407 
408 FWDialogBuilder &FWDialogBuilder::floatLeft(size_t spacing /*= 3*/) {
410  return *this;
411 }
412 
413 FWDialogBuilder &FWDialogBuilder::spaceUp(size_t spacing /*= 3*/) {
414  FWLayoutBuilder::spaceUp(spacing);
415  return *this;
416 }
417 
418 FWDialogBuilder &FWDialogBuilder::spaceDown(size_t spacing /*= 3*/) {
420  return *this;
421 }
422 
424  FWLayoutBuilder::spaceUp(spacing);
426  return *this;
427 }
428 
431  return *this;
432 }
433 
436  return *this;
437 }
438 
442  return *this;
443 }
444 
445 // Frame spacing
446 
449  return *this;
450 }
451 
454  return *this;
455 }
456 
460  return *this;
461 }
462 
465  return *this;
466 }
467 
470  return *this;
471 }
472 
476  return *this;
477 }
478 
479 FWDialogBuilder &FWDialogBuilder::expand(size_t expandX /*= true*/, size_t expandY /*= false*/) {
480  FWLayoutBuilder::expand(expandX, expandY);
481  return *this;
482 }
483 
485  newRow().expand(true, true);
486 
487  TGFrame *frame;
488  if (size)
489  frame = new TGFrame(nextFrame(), 1, size);
490  else
491  frame = new TGFrame(nextFrame());
492 
493  currentFrame()->AddFrame(frame, nextHints());
494 
495  expand(true, true);
496 
497  return *this;
498 }
499 
501  TGFrame *frame;
502  if (size)
503  frame = new TGFrame(nextFrame(), size, 1);
504  else
505  frame = new TGFrame(nextFrame());
506 
507  currentFrame()->AddFrame(frame, nextHints());
508 
509  if (!size)
510  expand(true, false);
511  else
512  expand(false, false);
513 
514  return *this;
515 }
FWDialogBuilder & spaceUp(size_t spacing=3)
size
Write out results.
TGVerticalFrame * verticalFrame()
TGCompositeFrame * m_window
string separator
Definition: mps_merge.py:79
FWDialogBuilder & frameSpaceUp(size_t spacing=3)
FWDialogBuilder & extract(T *in, T **out)
FWDialogBuilder(TGCompositeFrame *window, FWDialogBuilder *parent=nullptr, bool expandY=true)
TGCompositeFrame * nextFrame()
FWDialogBuilder & endTab(void)
FWDialogBuilder & frameSpaceRight(size_t spacing=3)
FWDialogBuilder & addTextButton(const char *text, TGTextButton **out=nullptr)
FWDialogBuilder & addHSlider(size_t size, TGHSlider **out=nullptr)
FWDialogBuilder & spaceLeftRight(size_t spacing=3)
FWLayoutBuilder & frameSpaceRight(size_t spacing)
FWDialogBuilder & addTextView(const char *defaultText=nullptr, TGTextView **out=nullptr)
FWLayoutBuilder & spaceRight(size_t spacing)
Definition: weight.py:1
std::vector< TGVerticalFrame * > m_framesStack
FWLayoutBuilder(TGCompositeFrame *window, bool expandY=true)
TGLayoutHints * m_currentHints
FWLayoutBuilder & frameSpaceDown(size_t spacing)
FWDialogBuilder & addLabel(const char *text, size_t fontSize=12, size_t weight=0, TGLabel **out=nullptr)
assert(be >=bs)
FWDialogBuilder & addCheckbox(const char *text, TGCheckButton **out=nullptr)
FWDialogBuilder & vSpacer(size_t size=0)
Definition: html.py:1
FWDialogBuilder & untabs(void)
FWDialogBuilder & addTextEdit(const char *defaultText=nullptr, TGTextEdit **out=nullptr)
char const * label
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)
Definition: style.py:1
FWLayoutBuilder & floatLeft(size_t spacing)
FWDialogBuilder & frameSpaceUpDown(size_t spacing=3)
TGLayoutHints * m_currentFrameHints
FWDialogBuilder & addHtml(TGHtml **out=nullptr)
FWLayoutBuilder & unindent(void)
FWDialogBuilder & spaceUpDown(size_t spacing=3)
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:643
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)
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 & addTable(FWTableManagerBase *manager, FWTableWidget **out=nullptr)
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 & indent(int left=2, int right=-1)
FWDialogBuilder & addNumberEntry(float defaultValue, size_t digits, TGNumberFormat::EStyle style, int min, int max, TGNumberEntry **out)
FWDialogBuilder & addColorPicker(const FWColorManager *manager, FWColorSelect **out=nullptr)
FWDialogBuilder & spaceDown(size_t spacing=3)
FWLayoutBuilder & spaceLeft(size_t spacing)
FWLayoutBuilder & frameSpaceLeft(size_t spacing)
FWDialogBuilder & spaceRight(size_t spacing=3)