CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Fireworks/Core/src/FWDialogBuilder.cc

Go to the documentation of this file.
00001 #include "Fireworks/Core/src/FWDialogBuilder.h"
00002 #include "Fireworks/Core/interface/FWColorManager.h"
00003 #include "Fireworks/Core/src/FWGUIValidatingTextEntry.h"
00004 #include "Fireworks/Core/src/FWColorSelect.h"
00005 #include "Fireworks/TableWidget/interface/FWTableWidget.h"
00006 
00007 
00008 #include "TGFrame.h"
00009 #include "TGLabel.h"
00010 #include "TGButton.h"
00011 #include "TG3DLine.h"
00012 #include "TGLViewer.h"
00013 #include "TGSlider.h"
00014 #include "TGTab.h"
00015 #include "TGTextView.h"
00016 #include "TGTextEdit.h"
00017 #include "TGNumberEntry.h"
00018 #include "TGHtml.h"
00019 
00020 FWLayoutBuilder::FWLayoutBuilder(TGCompositeFrame *window)
00021    : m_window(window),
00022      m_currentFrame(0),
00023      m_floatLeft(false),
00024      m_topSpacing(0),
00025      m_leftSpacing(0),
00026      m_currentHints(0),
00027      m_currentFrameHints(0)
00028 {
00029    TGVerticalFrame *mainFrame = new TGVerticalFrame(window);
00030    TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 
00031                                             0, 0, 0, 0);
00032    m_window->AddFrame(mainFrame, hints);
00033    m_framesStack.push_back(mainFrame);
00034 }
00035 
00036 FWLayoutBuilder &
00037 FWLayoutBuilder::newRow(void)
00038 {
00039    m_currentFrameHints = m_currentHints = new TGLayoutHints(kLHintsExpandX);
00040    m_currentFrame = new TGHorizontalFrame(m_framesStack.back());
00041    m_framesStack.back()->AddFrame(m_currentFrame, m_currentHints);
00042    return *this;
00043 }
00044    
00045 FWLayoutBuilder &
00046 FWLayoutBuilder::indent(int left /*= 2*/, int right /* = -1*/)
00047 {
00048    if (right < 0)
00049       right = left;
00050       
00051    TGVerticalFrame *parent = m_framesStack.back();
00052    TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 
00053                                             left, right, 0, 0);
00054    m_currentHints = 0;
00055    m_framesStack.push_back(new TGVerticalFrame(parent));
00056    parent->AddFrame(m_framesStack.back(), hints);
00057    return newRow().expand(true, false);
00058 }
00059 
00061 TGVerticalFrame *
00062 FWLayoutBuilder::verticalFrame(void)
00063 {
00064    assert(m_framesStack.size());
00065    return m_framesStack.back();
00066 }
00067 
00069 FWLayoutBuilder &
00070 FWLayoutBuilder::unindent(void)
00071 {
00072    assert(!m_framesStack.empty());
00073    m_framesStack.pop_back();
00074    return *this;
00075 }
00076 
00080 FWLayoutBuilder &
00081 FWLayoutBuilder::floatLeft(size_t spacing)
00082 {
00083    m_floatLeft = true;
00084    m_leftSpacing = spacing;
00085    return *this;
00086 }
00087 
00088 FWLayoutBuilder &
00089 FWLayoutBuilder::spaceUp(size_t spacing)
00090 {
00091    if (m_currentHints)
00092       m_currentHints->SetPadTop(spacing);
00093    return *this;
00094 }
00095 
00096 FWLayoutBuilder &
00097 FWLayoutBuilder::spaceDown(size_t spacing)
00098 {
00099    if (m_currentHints)
00100       m_currentHints->SetPadBottom(spacing);
00101    return *this;
00102 }
00103 
00104 FWLayoutBuilder &
00105 FWLayoutBuilder::spaceLeft(size_t spacing)
00106 {
00107    if (m_currentHints)
00108       m_currentHints->SetPadLeft(spacing);
00109    return *this;
00110 }
00111 
00112 FWLayoutBuilder &
00113 FWLayoutBuilder::spaceRight(size_t spacing)
00114 {
00115    if (m_currentHints)
00116       m_currentHints->SetPadRight(spacing);
00117    return *this;
00118 }
00119 
00120 
00121 FWLayoutBuilder &
00122 FWLayoutBuilder::frameSpaceUp(size_t spacing)
00123 {
00124    if (m_currentFrameHints)
00125       m_currentFrameHints->SetPadTop(spacing);
00126    return *this;
00127 }
00128 
00129 FWLayoutBuilder &
00130 FWLayoutBuilder::frameSpaceDown(size_t spacing)
00131 {
00132    if (m_currentFrameHints)
00133       m_currentFrameHints->SetPadBottom(spacing);
00134    return *this;
00135 }
00136 
00137 FWLayoutBuilder &
00138 FWLayoutBuilder::frameSpaceLeft(size_t spacing)
00139 {
00140    if (m_currentFrameHints)
00141       m_currentFrameHints->SetPadLeft(spacing);
00142    return *this;
00143 }
00144 
00145 FWLayoutBuilder &
00146 FWLayoutBuilder::frameSpaceRight(size_t spacing)
00147 {
00148    if (m_currentFrameHints)
00149       m_currentFrameHints->SetPadRight(spacing);
00150    return *this;
00151 }
00152 
00156 FWLayoutBuilder &
00157 FWLayoutBuilder::expand(bool expandX /*= true*/, bool expandY /*= false*/)
00158 {
00159    UInt_t style = 0;
00160    style |= expandX ? kLHintsExpandX : 0;
00161    style |= expandY ? kLHintsExpandY : 0;
00162    
00163    if (m_currentHints)
00164       m_currentHints->SetLayoutHints(style);
00165    return *this;
00166 }
00167 
00168 // Returns the next layout to be used.
00169 TGLayoutHints *
00170 FWLayoutBuilder::nextHints()
00171 {
00172    if (m_floatLeft)
00173    {
00174       size_t left = m_leftSpacing;
00175       m_floatLeft = false;
00176       m_leftSpacing = 0;
00177       assert(m_currentHints);
00178       m_currentHints = new TGLayoutHints(kLHintsExpandX, left, 0, 
00179                                          m_currentHints->GetPadTop(), 0);
00180    }
00181    else
00182    {
00183       size_t top = m_topSpacing;
00184       m_topSpacing = 3;
00185       m_currentHints = new TGLayoutHints(kLHintsExpandX, 0, 0, top, 0);
00186    }
00187    return m_currentHints;
00188 }
00189 
00190 TGCompositeFrame *
00191 FWLayoutBuilder::nextFrame()
00192 {
00193    if (!isFloatingLeft())
00194       newRow();
00195 
00196    return currentFrame();
00197 }
00198 
00228 FWDialogBuilder::FWDialogBuilder(TGCompositeFrame *window, 
00229                                  FWDialogBuilder *parent /*= 0*/)
00230    : FWLayoutBuilder(window),
00231      m_parent(parent),
00232      m_tabs(0)
00233 {}
00234 
00235 FWDialogBuilder &
00236 FWDialogBuilder::newRow()
00237 {
00238    FWLayoutBuilder::newRow();
00239    return *this;
00240 }
00241 
00242 FWDialogBuilder &
00243 FWDialogBuilder::indent(int left /* = 2*/, int right /* = -1*/)
00244 {
00245    FWLayoutBuilder::indent(left, right);
00246    return *this;
00247 }
00248 
00249 FWDialogBuilder &
00250 FWDialogBuilder::unindent(void)
00251 {
00252    FWLayoutBuilder::unindent();
00253    return *this;
00254 }
00255 
00256 FWDialogBuilder &
00257 FWDialogBuilder::addLabel(const char *text, size_t fontSize /*= 12*/,
00258                           size_t weight /*= 0*/, TGLabel **out /*= 0*/)
00259 {
00260    TGLabel *label = new TGLabel(nextFrame(), text);
00261 
00262    if (fontSize != 0)
00263    {
00264       FontStruct_t defaultFontStruct = label->GetDefaultFontStruct();
00265       try
00266       {
00267          TGFontPool *pool = gClient->GetFontPool();
00268          TGFont* defaultFont = pool->GetFont(defaultFontStruct);
00269          FontAttributes_t attributes = defaultFont->GetFontAttributes();
00270          label->SetTextFont(pool->GetFont(attributes.fFamily, fontSize, 
00271                                           attributes.fWeight, attributes.fSlant));
00272       } 
00273       catch(...)
00274       {
00275          // Ignore exceptions.
00276       }
00277    }
00278 
00279    label->SetTextJustify(kTextLeft);
00280    
00281    TGLayoutHints *hints = nextHints();
00282    UInt_t style = hints->GetLayoutHints() | kLHintsCenterY;
00283    hints->SetLayoutHints(style);
00284    currentFrame()->AddFrame(label, hints);
00285    
00286    return extract(label, out);
00287 }
00288 
00289 FWDialogBuilder &
00290 FWDialogBuilder::addTextView(const char *defaultText /*= 0*/, 
00291                              TGTextView **out /*= 0*/)
00292 {
00293    TGTextView *view = new TGTextView(nextFrame(), 100, 100);
00294    if (defaultText)
00295       view->AddLine(defaultText);
00296    currentFrame()->AddFrame(view, nextHints());
00297    expand(true, true);
00298    return extract(view, out);
00299 }
00300 
00301 FWDialogBuilder &
00302 FWDialogBuilder::addHtml(TGHtml **out /*= 0*/)
00303 {
00304   TGHtml *html = new TGHtml(nextFrame(), 100, 100);
00305   currentFrame()->AddFrame(html, nextHints());   
00306   expand(true, true);
00307   return extract(html, out);
00308 }
00309 
00310 FWDialogBuilder &
00311 FWDialogBuilder::addTextEdit(const char *defaultText /*= 0*/,
00312                              TGTextEdit **out /*= 0 */)
00313 {
00314    TGTextEdit *edit = new TGTextEdit(nextFrame(), 100, 100);
00315    if (defaultText)
00316       edit->AddLine(defaultText);
00317    currentFrame()->AddFrame(edit, nextHints());
00318    expand(true, true);
00319    return extract(edit, out);
00320 }
00321 
00322 FWDialogBuilder &
00323 FWDialogBuilder::addColorPicker(const FWColorManager *manager,
00324                                 FWColorSelect **out /*= 0*/)
00325 {
00326    const char* graphicsLabel = " ";
00327    FWColorSelect *widget = new FWColorSelect(nextFrame(), graphicsLabel,
00328                                              0, manager, -1);
00329    
00330    currentFrame()->AddFrame(widget, nextHints());
00331    widget->SetEnabled(kFALSE);
00332    
00333    return extract(widget, out);
00334 }
00335 
00336 FWDialogBuilder &
00337 FWDialogBuilder::addHSlider(size_t size, TGHSlider **out /*= 0*/)
00338 {
00339    TGHSlider *slider = new TGHSlider(nextFrame(), size, kSlider1);
00340    currentFrame()->AddFrame(slider, nextHints());
00341    slider->SetRange(0, 100);
00342    slider->SetPosition(100);
00343    slider->SetEnabled(false);
00344    
00345    return extract(slider, out);
00346 }
00347 
00348 FWDialogBuilder &
00349 FWDialogBuilder::addTextButton(const char *text, TGTextButton **out /*= 0*/)
00350 {
00351    TGTextButton *button = new TGTextButton(nextFrame(), text);
00352    currentFrame()->AddFrame(button, nextHints());
00353    button->SetEnabled(false);
00354    
00355    return extract(button, out);
00356 }
00357 
00358 FWDialogBuilder &
00359 FWDialogBuilder::addValidatingTextEntry(const char *defaultText, 
00360                                         FWGUIValidatingTextEntry **out /*= 0*/)
00361 {
00362    FWGUIValidatingTextEntry *entry = new FWGUIValidatingTextEntry(nextFrame());
00363    currentFrame()->AddFrame(entry, nextHints());
00364    
00365    return extract(entry, out);
00366 }
00367 
00368 FWDialogBuilder &
00369 FWDialogBuilder::addTextEntry(const char *defaultText, 
00370                               TGTextEntry **out)
00371 {
00372    TGTextEntry *entry = new TGTextEntry(nextFrame());
00373    currentFrame()->AddFrame(entry, nextHints());
00374    entry->SetEnabled(kFALSE);
00375    
00376    return extract(entry, out);
00377 }
00378 
00379 FWDialogBuilder &
00380 FWDialogBuilder::addNumberEntry(float defaultValue, size_t digits,
00381                                 TGNumberFormat::EStyle style,
00382                                 int min, int max,
00383                                 TGNumberEntry **out /*= 0*/)
00384 {
00385    TGNumberEntry *entry = new TGNumberEntry(nextFrame(), defaultValue, 
00386                                             digits, -1, style,
00387                                             TGNumberFormat::kNEAAnyNumber,
00388                                             TGNumberFormat::kNELLimitMinMax,
00389                                             min, max);
00390    currentFrame()->AddFrame(entry, nextHints());
00391    entry->GetNumberEntry()->SetEnabled(kFALSE);
00392    entry->GetButtonUp()->SetEnabled(kFALSE);
00393    entry->GetButtonDown()->SetEnabled(kFALSE);
00394    return extract(entry, out);
00395 }
00396 
00397 FWDialogBuilder &
00398 FWDialogBuilder::addCheckbox(const char *text, TGCheckButton **out /*= 0*/)
00399 {
00400    TGCheckButton *button = new TGCheckButton(nextFrame(), text);
00401    button->SetState(kButtonDown, false);
00402    button->SetEnabled(false);
00403    currentFrame()->AddFrame(button, nextHints());
00404    
00405    return extract(button, out);
00406 }
00407 
00408 FWDialogBuilder &
00409 FWDialogBuilder::addTable(FWTableManagerBase *manager, 
00410                           FWTableWidget **out /*= 0*/)
00411 {
00412    expand(true, true);
00413    TGCompositeFrame *frame = verticalFrame();
00414    TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
00415    FWTableWidget *table = new FWTableWidget(manager, frame);
00416    frame->AddFrame(table, hints);
00417    return extract(table, out);
00418 }
00419 
00420 FWDialogBuilder &
00421 FWDialogBuilder::addHSeparator(size_t horizontalPadding /*= 4*/, 
00422                                size_t verticalPadding /*= 3*/)
00423 {
00424    TGLayoutHints *hints = new TGLayoutHints(kLHintsExpandX,
00425                                             horizontalPadding,
00426                                             horizontalPadding,
00427                                             verticalPadding,
00428                                             verticalPadding);
00429 
00430    TGHorizontal3DLine* separator = new TGHorizontal3DLine(nextFrame(), 200, 2);
00431    currentFrame()->AddFrame(separator, hints);
00432    return newRow();
00433 }
00434 
00453 FWDialogBuilder &
00454 FWDialogBuilder::tabs(TGTab **out)
00455 {
00456    // Calls to tabs cannot be nested within the same builder. Multiple
00457    // builders are used to support nested tabs.
00458    assert(!m_tabs);
00459    expand(true, true);
00460    m_tabs = new TGTab(nextFrame());
00461    currentFrame()->AddFrame(m_tabs, nextHints());
00462    expand(true, true);
00463    return extract(m_tabs, out);
00464 }
00465 
00466 FWDialogBuilder &
00467 FWDialogBuilder::untabs(void)
00468 {
00469    // No untabs() without tabs().
00470    assert(m_tabs);
00471    m_tabs = 0;
00472    return *this;
00473 }
00474 
00478 FWDialogBuilder &
00479 FWDialogBuilder::beginTab(const char *label)
00480 {
00481    TGCompositeFrame *tab = m_tabs->AddTab(label);
00482    
00483    FWDialogBuilder *builder = new FWDialogBuilder(tab, this);
00484    return builder->newRow();
00485 }
00486 
00489 FWDialogBuilder &
00490 FWDialogBuilder::endTab(void)
00491 {
00492    FWDialogBuilder *parent = m_parent;
00493    delete this;
00494    return *parent;
00495 }
00496 
00497 FWDialogBuilder &
00498 FWDialogBuilder::floatLeft(size_t spacing /*= 3*/)
00499 {
00500    FWLayoutBuilder::floatLeft(spacing);
00501    return *this;
00502 }
00503 
00504 FWDialogBuilder &
00505 FWDialogBuilder::spaceUp(size_t spacing /*= 3*/)
00506 {
00507    FWLayoutBuilder::spaceUp(spacing);
00508    return *this;
00509 }
00510 
00511 FWDialogBuilder &
00512 FWDialogBuilder::spaceDown(size_t spacing /*= 3*/)
00513 {
00514    FWLayoutBuilder::spaceDown(spacing);
00515    return *this;
00516 }
00517 
00518 FWDialogBuilder &
00519 FWDialogBuilder::spaceUpDown(size_t spacing /*= 3*/)
00520 {
00521    FWLayoutBuilder::spaceUp(spacing);
00522    FWLayoutBuilder::spaceDown(spacing);
00523    return *this;
00524 }
00525 
00526 FWDialogBuilder &
00527 FWDialogBuilder::spaceLeft(size_t spacing)
00528 {
00529    FWLayoutBuilder::spaceLeft(spacing);
00530    return *this;
00531 }
00532 
00533 FWDialogBuilder &
00534 FWDialogBuilder::spaceRight(size_t spacing)
00535 {
00536    FWLayoutBuilder::spaceRight(spacing);
00537    return *this;
00538 }
00539 
00540 FWDialogBuilder &
00541 FWDialogBuilder::spaceLeftRight(size_t spacing)
00542 {
00543    FWLayoutBuilder::spaceLeft(spacing);
00544    FWLayoutBuilder::spaceRight(spacing);
00545    return *this;
00546 }
00547 
00548 
00549 // Frame spacing
00550 
00551 FWDialogBuilder &
00552 FWDialogBuilder::frameSpaceUp(size_t spacing /*= 3*/)
00553 {
00554    FWLayoutBuilder::frameSpaceUp(spacing);
00555    return *this;
00556 }
00557 
00558 FWDialogBuilder &
00559 FWDialogBuilder::frameSpaceDown(size_t spacing /*= 3*/)
00560 {
00561    FWLayoutBuilder::frameSpaceDown(spacing);
00562    return *this;
00563 }
00564 
00565 FWDialogBuilder &
00566 FWDialogBuilder::frameSpaceUpDown(size_t spacing /*= 3*/)
00567 {
00568    FWLayoutBuilder::frameSpaceUp(spacing);
00569    FWLayoutBuilder::frameSpaceDown(spacing);
00570    return *this;
00571 }
00572 
00573 FWDialogBuilder &
00574 FWDialogBuilder::frameSpaceLeft(size_t spacing)
00575 {
00576    FWLayoutBuilder::frameSpaceLeft(spacing);
00577    return *this;
00578 }
00579 
00580 FWDialogBuilder &
00581 FWDialogBuilder::frameSpaceRight(size_t spacing)
00582 {
00583    FWLayoutBuilder::frameSpaceRight(spacing);
00584    return *this;
00585 }
00586 
00587 FWDialogBuilder &
00588 FWDialogBuilder::frameSpaceLeftRight(size_t spacing)
00589 {
00590    FWLayoutBuilder::frameSpaceLeft(spacing);
00591    FWLayoutBuilder::frameSpaceRight(spacing);
00592    return *this;
00593 }
00594 
00595 
00596 FWDialogBuilder &
00597 FWDialogBuilder::expand(size_t expandX /*= true*/, size_t expandY /*= false*/)
00598 {
00599    FWLayoutBuilder::expand(expandX, expandY);
00600    return *this;
00601 }
00602 
00603 FWDialogBuilder &
00604 FWDialogBuilder::vSpacer(size_t size /* = 0*/)
00605 {
00606    newRow().expand(true, true);
00607    
00608    TGFrame *frame;
00609    if (size) 
00610       frame = new TGFrame(nextFrame(), 1, size);
00611    else
00612       frame = new TGFrame(nextFrame());
00613    
00614    currentFrame()->AddFrame(frame, nextHints());
00615 
00616    expand(true, true);
00617    
00618    return *this;
00619 }
00620 
00621 
00622 FWDialogBuilder &
00623 FWDialogBuilder::hSpacer(size_t size /* = 0*/)
00624 {
00625    TGFrame *frame;
00626    if (size) 
00627       frame = new TGFrame(nextFrame(), size, 1);
00628    else
00629       frame = new TGFrame(nextFrame());
00630    
00631    currentFrame()->AddFrame(frame, nextHints());
00632    
00633    if (!size)
00634       expand(true, false);
00635    else
00636       expand(false, false);
00637    
00638    return *this;
00639 }