TGXYLayout.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGXYLayout.h 23115 2008-04-10 13:35:37Z rdm $
00002 // Author: Reiner Rohlfs   24/03/2002
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2002, Rene Brun, Fons Rademakers and Reiner Rohlfs *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TGXYLayout                                                           //
00015 //                                                                      //
00016 // Is a layout manager where the position and the size of each widget   //
00017 // in the frame are defined by X / Y - coordinates. The coordinates     //
00018 // for each widget are defined by the TGXYLayoutHints. Therefore it     //
00019 // is not possible to share a layout hint for several widgets.          //
00020 //                                                                      //
00021 // The coordinates (X, Y) and the size (W, H) are defined in units      //
00022 // of the size of a typical character. Also the size of the             //
00023 // TGCompositeFrame for which a TGXYLayout manager is used has to be    //
00024 // defined in its constructor in units of the size of a character!      //
00025 //                                                                      //
00026 // It is not possible to use any other layout hint than the             //
00027 // TGXYLayoutHints for this layout manager!                             //
00028 //                                                                      //
00029 // The rubberFlag in the constructor of the TGLXYLayoutHints defines    //
00030 // how the position and the size of a widget is recalculated if the     //
00031 // size of the frame is increased:                                      //
00032 // - kLRubberX: The X - position (left edge) is increased by the same   //
00033 //              factor as the width of the frame increases.             //
00034 // - kLRubberY: The Y - position (upper edge) is increased by the same  //
00035 //              factor as the height of the frame increases.            //
00036 // - kLRubberW: The width of the widget is increased by the same        //
00037 //              factor as the width of the frame increases.             //
00038 // - kLRubberY: The height of the widget is increased by the same       //
00039 //              factor as the height of the frame increases.            //
00040 // But the size never becomes smaller than defined by the               //
00041 // TGXYLayoutHints and the X and Y coordinates becomes never smaller    //
00042 // than defined by the layout hints.                                    //
00043 //                                                                      //
00044 // TGXYLayoutHints                                                      //
00045 //                                                                      //
00046 // This layout hint must be used for the TGXYLouyout manager!           //
00047 //                                                                      //
00048 //                                                                      //
00049 // Example how to use this layout manager:                              //
00050 //                                                                      //
00051 // TGMyFrame::TGMyFrame()                                               //
00052 //    : TGMainFrame(gClient->GetRoot(), 30, 12)                         //
00053 //    // frame is 30 characters wide and 12 characters high             //
00054 // {                                                                    //
00055 //    SetLayoutManager(new TGXYLayout(this));                           //
00056 //                                                                      //
00057 //    // create a button of size 8 X 1.8 at position 20 / 1             //
00058 //    TGTextButton * button;                                            //
00059 //    button = new TGTextButton(this, "&Apply", 1);                     //
00060 //    AddFrame(button, new TGXYLayoutHints(20, 1, 8, 1.8));             //
00061 //                                                                      //
00062 //    // create a listbox of size 18 X 10 at position 1 / 1.            //
00063 //    // The height will increase if the frame height increases         //
00064 //    TGListBox *listBox;                                               //
00065 //    listBox = new TGListBox(this, 2);                                 //
00066 //    AddFrame(listBox, new TGXYLayoutHints(1, 1, 18, 10,               //
00067 //             TGXYLayoutHints::kLRubberX |                             //
00068 //             TGXYLayoutHints::kLRubberY |                             //
00069 //             TGXYLayoutHints::kLRubberH));                            //
00070 //    .                                                                 //
00071 //    .                                                                 //
00072 //    .                                                                 //
00073 // }                                                                    //
00074 //                                                                      //
00075 // Normaly there is one layout hint per widget. Therefore these         //
00076 // can be deleted like in the following example in the desctuctor       //
00077 // of the frame:                                                        //
00078 //                                                                      //
00079 // TGMyFrame::~TGMyFrame()                                              //
00080 // {                                                                    //
00081 //    // Destructor, deletes all frames and their layout hints.         //
00082 //                                                                      //
00083 //    // delete all frames and layout hints                             //
00084 //    Cleanup();                                                        //
00085 // }                                                                    //
00086 //                                                                      //
00087 //////////////////////////////////////////////////////////////////////////
00088 
00089 #ifndef ROOT_TGXYLayout
00090 #define ROOT_TGXYLayout
00091 
00092 #ifndef ROOT_TGLayout
00093 #include "TGLayout.h"
00094 #endif
00095 
00096 
00097 class TGXYLayoutHints : public TGLayoutHints {
00098 
00099 protected:
00100    Double_t   fX;    // x - position of widget
00101    Double_t   fY;    // y - position of widget
00102    Double_t   fW;    // width of widget
00103    Double_t   fH;    // height of widget
00104    UInt_t     fFlag; // rubber flag
00105 
00106 public:
00107 
00108    enum ERubberFlag {
00109       kLRubberX   = BIT(0),
00110       kLRubberY   = BIT(1),
00111       kLRubberW   = BIT(2),
00112       kLRubberH   = BIT(3)
00113    };
00114 
00115    TGXYLayoutHints(Double_t x, Double_t y, Double_t w, Double_t h,
00116                    UInt_t rubberFlag = kLRubberX | kLRubberY);
00117 
00118    Double_t  GetX() const { return fX; };
00119    Double_t  GetY() const { return fY; };
00120    Double_t  GetW() const { return fW; };
00121    Double_t  GetH() const { return fH; };
00122    UInt_t    GetFlag() const { return fFlag; };
00123 
00124    void      SetX(Double_t x) { fX = x; }
00125    void      SetY(Double_t y) { fY = y; }
00126    void      SetW(Double_t w) { fW = w; }
00127    void      SetH(Double_t h) { fH = h; }
00128    void      SetFlag(UInt_t flag) { fFlag = flag; }
00129 
00130    virtual void SavePrimitive(ostream &out, Option_t * = "");
00131 
00132    ClassDef(TGXYLayoutHints,0)  // Hits for the X / Y - layout manager
00133 };
00134 
00135 
00136 class TGXYLayout : public TGLayoutManager {
00137 
00138 protected:
00139    TList            *fList;           // list of frames to arrange
00140    TGCompositeFrame *fMain;           // container frame
00141 
00142    Bool_t            fFirst;          // flag to determine the first call of Layout()
00143    UInt_t            fFirstWidth;     // original width of the frame fMain
00144    UInt_t            fFirstHeight;    // original height of the fram fMain
00145 
00146    Int_t             fTWidth;         // text width of a default character "1234567890" / 10
00147    Int_t             fTHeight;        // text height
00148 
00149    TGXYLayout(const TGXYLayout&); 
00150    TGXYLayout& operator=(const TGXYLayout&); 
00151 
00152 public:
00153    TGXYLayout(TGCompositeFrame *main);
00154 
00155    virtual void Layout();
00156    virtual TGDimension GetDefaultSize() const;
00157    virtual void SavePrimitive(ostream &out, Option_t * = "");
00158 
00159    void NewSize() { fFirst = kTRUE; }
00160 
00161    ClassDef(TGXYLayout,0)  // X / Y - layout manager
00162 };
00163 
00164 #endif

Generated on Tue Jul 5 14:20:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1