Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:30

0001 #ifndef Fireworks_Core_FWDialogBuilder_h
0002 #define Fireworks_Core_FWDialogBuilder_h
0003 
0004 #include "TGNumberEntry.h"
0005 
0006 class TGCompositeFrame;
0007 class TGLayoutHints;
0008 class TGVerticalFrame;
0009 class TGLabel;
0010 class FWColorSelect;
0011 class TGTextView;
0012 class TGTextEntry;
0013 class TGTextButton;
0014 class TGHSlider;
0015 class FWTableManagerBase;
0016 class FWTableWidget;
0017 class TGCheckButton;
0018 class FWGUIValidatingTextEntry;
0019 class TGTab;
0020 class FWColorManager;
0021 class TGTextEdit;
0022 class TGHtml;
0023 
0024 class FWLayoutBuilder {
0025 protected:
0026   FWLayoutBuilder(TGCompositeFrame *window, bool expandY = true);
0027   FWLayoutBuilder &newRow();
0028 
0029   FWLayoutBuilder &indent(int left = 2, int right = -1);
0030 
0031   FWLayoutBuilder &unindent(void);
0032   TGCompositeFrame *currentFrame(void) { return m_currentFrame; }
0033   FWLayoutBuilder &floatLeft(size_t spacing);
0034   FWLayoutBuilder &spaceUp(size_t spacing);
0035   FWLayoutBuilder &spaceDown(size_t spacing);
0036   FWLayoutBuilder &spaceLeft(size_t spacing);
0037   FWLayoutBuilder &spaceRight(size_t spacing);
0038   FWLayoutBuilder &frameSpaceUp(size_t spacing);
0039   FWLayoutBuilder &frameSpaceDown(size_t spacing);
0040   FWLayoutBuilder &frameSpaceLeft(size_t spacing);
0041   FWLayoutBuilder &frameSpaceRight(size_t spacing);
0042   FWLayoutBuilder &expand(bool expandX = true, bool expandY = false);
0043 
0044   bool isFloatingLeft() { return m_floatLeft; }
0045   TGLayoutHints *nextHints();
0046   TGCompositeFrame *nextFrame();
0047   TGVerticalFrame *verticalFrame();
0048   void frameForTab();
0049 
0050 private:
0051   TGCompositeFrame *m_window;
0052 
0053   std::vector<TGVerticalFrame *> m_framesStack;
0054   //  TGCompositeFrame *m_lastFrame;
0055   TGCompositeFrame *m_currentFrame;
0056 
0057   bool m_floatLeft;
0058   size_t m_topSpacing;
0059   size_t m_leftSpacing;
0060   TGLayoutHints *m_currentHints;
0061   TGLayoutHints *m_currentFrameHints;
0062 };
0063 
0064 /** Helper class to construct dialogs in a more readable ways.
0065 
0066     Encapsulated TGUI layout hiccups and exposes the developer an API which
0067     allows to layout items in a top->bottom, right->left manner.
0068     
0069     Example:
0070     
0071       FWDialogBuilder builder(parent);
0072       parent.newRow(2)              // New row which has a 2 pixel padding on top.
0073             .addLabel("MyLabel:")    // A new label.
0074             .indent(20)             // Whatever follows is indented 20 pixels 
0075                                     // on the right.
0076             .addLabel("MyLabel2")   // Another label.
0077             .spaceDown(4)
0078             .addTextButton("Aligned to MyLabel2 ").floatLeft()
0079             .addTextButton("Same Row as previous")
0080             .unindent()              // back one level in the indentation.
0081             .addLabel("Aligned to MyLabel:")
0082             
0083     Because in ROOT layout and parenting of widgets are mixed we need to take
0084     responsibility for creating the widget objects (sigh!), so we have one
0085     "addXYZ" method per widget that can be added. If we find our way around
0086     this it would be better to have a generic "addWidget()" method and create
0087     widgets outside this class.
0088     
0089     TODO: For higher configurability we should have an 
0090           "addWithCallback(Callbak)"  method which can be used to specify a 
0091           generic widget creation action.
0092   */
0093 class FWDialogBuilder : public FWLayoutBuilder {
0094 public:
0095   FWDialogBuilder(TGCompositeFrame *window, FWDialogBuilder *parent = nullptr, bool expandY = true);
0096 
0097   FWDialogBuilder &newRow();
0098   FWDialogBuilder &indent(int left = 2, int right = -1);
0099   FWDialogBuilder &unindent(void);
0100 
0101   FWDialogBuilder &addLabel(const char *text, size_t fontSize = 12, size_t weight = 0, TGLabel **out = nullptr);
0102 
0103   FWDialogBuilder &addTextView(const char *defaultText = nullptr, TGTextView **out = nullptr);
0104 
0105   // Is default text meaningful here as the html is
0106   // a document with structure?
0107   FWDialogBuilder &addHtml(TGHtml **out = nullptr);
0108 
0109   FWDialogBuilder &addTextEdit(const char *defaultText = nullptr, TGTextEdit **out = nullptr);
0110   FWDialogBuilder &addColorPicker(const FWColorManager *manager, FWColorSelect **out = nullptr);
0111 
0112   FWDialogBuilder &addHSlider(size_t size, TGHSlider **out = nullptr);
0113 
0114   FWDialogBuilder &addTextButton(const char *text, TGTextButton **out = nullptr);
0115   FWDialogBuilder &addValidatingTextEntry(const char *defaultText, FWGUIValidatingTextEntry **out);
0116   FWDialogBuilder &addTextEntry(const char *defaultText, TGTextEntry **out);
0117   FWDialogBuilder &addNumberEntry(
0118       float defaultValue, size_t digits, TGNumberFormat::EStyle style, int min, int max, TGNumberEntry **out);
0119 
0120   FWDialogBuilder &addCheckbox(const char *text, TGCheckButton **out = nullptr);
0121   FWDialogBuilder &addTable(FWTableManagerBase *manager, FWTableWidget **out = nullptr);
0122 
0123   FWDialogBuilder &addHSeparator(size_t horizontalPadding = 4, size_t verticalPadding = 3);
0124 
0125   FWDialogBuilder &tabs(TGTab **out);
0126   FWDialogBuilder &untabs(void);
0127   FWDialogBuilder &beginTab(const char *label);
0128   FWDialogBuilder &endTab(void);
0129 
0130   FWDialogBuilder &floatLeft(size_t spacing = 3);
0131 
0132   FWDialogBuilder &spaceUp(size_t spacing = 3);
0133   FWDialogBuilder &spaceDown(size_t spacing = 3);
0134   FWDialogBuilder &spaceUpDown(size_t spacing = 3);
0135   FWDialogBuilder &spaceLeft(size_t spacing = 3);
0136   FWDialogBuilder &spaceRight(size_t spacing = 3);
0137   FWDialogBuilder &spaceLeftRight(size_t spacing = 3);
0138 
0139   FWDialogBuilder &frameSpaceUp(size_t spacing = 3);
0140   FWDialogBuilder &frameSpaceDown(size_t spacing = 3);
0141   FWDialogBuilder &frameSpaceUpDown(size_t spacing = 3);
0142   FWDialogBuilder &frameSpaceLeft(size_t spacing = 3);
0143   FWDialogBuilder &frameSpaceRight(size_t spacing = 3);
0144   FWDialogBuilder &frameSpaceLeftRight(size_t spacing = 3);
0145 
0146   FWDialogBuilder &expand(size_t expandX = true, size_t expandY = false);
0147   FWDialogBuilder &vSpacer(size_t size = 0);
0148   FWDialogBuilder &hSpacer(size_t size = 0);
0149 
0150 protected:
0151   template <class T>
0152   FWDialogBuilder &extract(T *in, T **out) {
0153     if (out)
0154       *out = in;
0155     return *this;
0156   }
0157 
0158 private:
0159   FWDialogBuilder *m_parent;
0160   TGTab *m_tabs;
0161 };
0162 
0163 #endif