ROOT logo
// @(#)root/gui:$Id: TGXYLayout.h 23115 2008-04-10 13:35:37Z rdm $
// Author: Reiner Rohlfs   24/03/2002

/*************************************************************************
 * Copyright (C) 1995-2002, Rene Brun, Fons Rademakers and Reiner Rohlfs *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGXYLayout                                                           //
//                                                                      //
// Is a layout manager where the position and the size of each widget   //
// in the frame are defined by X / Y - coordinates. The coordinates     //
// for each widget are defined by the TGXYLayoutHints. Therefore it     //
// is not possible to share a layout hint for several widgets.          //
//                                                                      //
// The coordinates (X, Y) and the size (W, H) are defined in units      //
// of the size of a typical character. Also the size of the             //
// TGCompositeFrame for which a TGXYLayout manager is used has to be    //
// defined in its constructor in units of the size of a character!      //
//                                                                      //
// It is not possible to use any other layout hint than the             //
// TGXYLayoutHints for this layout manager!                             //
//                                                                      //
// The rubberFlag in the constructor of the TGLXYLayoutHints defines    //
// how the position and the size of a widget is recalculated if the     //
// size of the frame is increased:                                      //
// - kLRubberX: The X - position (left edge) is increased by the same   //
//              factor as the width of the frame increases.             //
// - kLRubberY: The Y - position (upper edge) is increased by the same  //
//              factor as the height of the frame increases.            //
// - kLRubberW: The width of the widget is increased by the same        //
//              factor as the width of the frame increases.             //
// - kLRubberY: The height of the widget is increased by the same       //
//              factor as the height of the frame increases.            //
// But the size never becomes smaller than defined by the               //
// TGXYLayoutHints and the X and Y coordinates becomes never smaller    //
// than defined by the layout hints.                                    //
//                                                                      //
// TGXYLayoutHints                                                      //
//                                                                      //
// This layout hint must be used for the TGXYLouyout manager!           //
//                                                                      //
//                                                                      //
// Example how to use this layout manager:                              //
//                                                                      //
// TGMyFrame::TGMyFrame()                                               //
//    : TGMainFrame(gClient->GetRoot(), 30, 12)                         //
//    // frame is 30 characters wide and 12 characters high             //
// {                                                                    //
//    SetLayoutManager(new TGXYLayout(this));                           //
//                                                                      //
//    // create a button of size 8 X 1.8 at position 20 / 1             //
//    TGTextButton * button;                                            //
//    button = new TGTextButton(this, "&Apply", 1);                     //
//    AddFrame(button, new TGXYLayoutHints(20, 1, 8, 1.8));             //
//                                                                      //
//    // create a listbox of size 18 X 10 at position 1 / 1.            //
//    // The height will increase if the frame height increases         //
//    TGListBox *listBox;                                               //
//    listBox = new TGListBox(this, 2);                                 //
//    AddFrame(listBox, new TGXYLayoutHints(1, 1, 18, 10,               //
//             TGXYLayoutHints::kLRubberX |                             //
//             TGXYLayoutHints::kLRubberY |                             //
//             TGXYLayoutHints::kLRubberH));                            //
//    .                                                                 //
//    .                                                                 //
//    .                                                                 //
// }                                                                    //
//                                                                      //
// Normaly there is one layout hint per widget. Therefore these         //
// can be deleted like in the following example in the desctuctor       //
// of the frame:                                                        //
//                                                                      //
// TGMyFrame::~TGMyFrame()                                              //
// {                                                                    //
//    // Destructor, deletes all frames and their layout hints.         //
//                                                                      //
//    // delete all frames and layout hints                             //
//    Cleanup();                                                        //
// }                                                                    //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGXYLayout
#define ROOT_TGXYLayout

#ifndef ROOT_TGLayout
#include "TGLayout.h"
#endif


class TGXYLayoutHints : public TGLayoutHints {

protected:
   Double_t   fX;    // x - position of widget
   Double_t   fY;    // y - position of widget
   Double_t   fW;    // width of widget
   Double_t   fH;    // height of widget
   UInt_t     fFlag; // rubber flag

public:

   enum ERubberFlag {
      kLRubberX   = BIT(0),
      kLRubberY   = BIT(1),
      kLRubberW   = BIT(2),
      kLRubberH   = BIT(3)
   };

   TGXYLayoutHints(Double_t x, Double_t y, Double_t w, Double_t h,
                   UInt_t rubberFlag = kLRubberX | kLRubberY);

   Double_t  GetX() const { return fX; };
   Double_t  GetY() const { return fY; };
   Double_t  GetW() const { return fW; };
   Double_t  GetH() const { return fH; };
   UInt_t    GetFlag() const { return fFlag; };

   void      SetX(Double_t x) { fX = x; }
   void      SetY(Double_t y) { fY = y; }
   void      SetW(Double_t w) { fW = w; }
   void      SetH(Double_t h) { fH = h; }
   void      SetFlag(UInt_t flag) { fFlag = flag; }

   virtual void SavePrimitive(ostream &out, Option_t * = "");

   ClassDef(TGXYLayoutHints,0)  // Hits for the X / Y - layout manager
};


class TGXYLayout : public TGLayoutManager {

protected:
   TList            *fList;           // list of frames to arrange
   TGCompositeFrame *fMain;           // container frame

   Bool_t            fFirst;          // flag to determine the first call of Layout()
   UInt_t            fFirstWidth;     // original width of the frame fMain
   UInt_t            fFirstHeight;    // original height of the fram fMain

   Int_t             fTWidth;         // text width of a default character "1234567890" / 10
   Int_t             fTHeight;        // text height

   TGXYLayout(const TGXYLayout&); 
   TGXYLayout& operator=(const TGXYLayout&); 

public:
   TGXYLayout(TGCompositeFrame *main);

   virtual void Layout();
   virtual TGDimension GetDefaultSize() const;
   virtual void SavePrimitive(ostream &out, Option_t * = "");

   void NewSize() { fFirst = kTRUE; }

   ClassDef(TGXYLayout,0)  // X / Y - layout manager
};

#endif
 TGXYLayout.h:1
 TGXYLayout.h:2
 TGXYLayout.h:3
 TGXYLayout.h:4
 TGXYLayout.h:5
 TGXYLayout.h:6
 TGXYLayout.h:7
 TGXYLayout.h:8
 TGXYLayout.h:9
 TGXYLayout.h:10
 TGXYLayout.h:11
 TGXYLayout.h:12
 TGXYLayout.h:13
 TGXYLayout.h:14
 TGXYLayout.h:15
 TGXYLayout.h:16
 TGXYLayout.h:17
 TGXYLayout.h:18
 TGXYLayout.h:19
 TGXYLayout.h:20
 TGXYLayout.h:21
 TGXYLayout.h:22
 TGXYLayout.h:23
 TGXYLayout.h:24
 TGXYLayout.h:25
 TGXYLayout.h:26
 TGXYLayout.h:27
 TGXYLayout.h:28
 TGXYLayout.h:29
 TGXYLayout.h:30
 TGXYLayout.h:31
 TGXYLayout.h:32
 TGXYLayout.h:33
 TGXYLayout.h:34
 TGXYLayout.h:35
 TGXYLayout.h:36
 TGXYLayout.h:37
 TGXYLayout.h:38
 TGXYLayout.h:39
 TGXYLayout.h:40
 TGXYLayout.h:41
 TGXYLayout.h:42
 TGXYLayout.h:43
 TGXYLayout.h:44
 TGXYLayout.h:45
 TGXYLayout.h:46
 TGXYLayout.h:47
 TGXYLayout.h:48
 TGXYLayout.h:49
 TGXYLayout.h:50
 TGXYLayout.h:51
 TGXYLayout.h:52
 TGXYLayout.h:53
 TGXYLayout.h:54
 TGXYLayout.h:55
 TGXYLayout.h:56
 TGXYLayout.h:57
 TGXYLayout.h:58
 TGXYLayout.h:59
 TGXYLayout.h:60
 TGXYLayout.h:61
 TGXYLayout.h:62
 TGXYLayout.h:63
 TGXYLayout.h:64
 TGXYLayout.h:65
 TGXYLayout.h:66
 TGXYLayout.h:67
 TGXYLayout.h:68
 TGXYLayout.h:69
 TGXYLayout.h:70
 TGXYLayout.h:71
 TGXYLayout.h:72
 TGXYLayout.h:73
 TGXYLayout.h:74
 TGXYLayout.h:75
 TGXYLayout.h:76
 TGXYLayout.h:77
 TGXYLayout.h:78
 TGXYLayout.h:79
 TGXYLayout.h:80
 TGXYLayout.h:81
 TGXYLayout.h:82
 TGXYLayout.h:83
 TGXYLayout.h:84
 TGXYLayout.h:85
 TGXYLayout.h:86
 TGXYLayout.h:87
 TGXYLayout.h:88
 TGXYLayout.h:89
 TGXYLayout.h:90
 TGXYLayout.h:91
 TGXYLayout.h:92
 TGXYLayout.h:93
 TGXYLayout.h:94
 TGXYLayout.h:95
 TGXYLayout.h:96
 TGXYLayout.h:97
 TGXYLayout.h:98
 TGXYLayout.h:99
 TGXYLayout.h:100
 TGXYLayout.h:101
 TGXYLayout.h:102
 TGXYLayout.h:103
 TGXYLayout.h:104
 TGXYLayout.h:105
 TGXYLayout.h:106
 TGXYLayout.h:107
 TGXYLayout.h:108
 TGXYLayout.h:109
 TGXYLayout.h:110
 TGXYLayout.h:111
 TGXYLayout.h:112
 TGXYLayout.h:113
 TGXYLayout.h:114
 TGXYLayout.h:115
 TGXYLayout.h:116
 TGXYLayout.h:117
 TGXYLayout.h:118
 TGXYLayout.h:119
 TGXYLayout.h:120
 TGXYLayout.h:121
 TGXYLayout.h:122
 TGXYLayout.h:123
 TGXYLayout.h:124
 TGXYLayout.h:125
 TGXYLayout.h:126
 TGXYLayout.h:127
 TGXYLayout.h:128
 TGXYLayout.h:129
 TGXYLayout.h:130
 TGXYLayout.h:131
 TGXYLayout.h:132
 TGXYLayout.h:133
 TGXYLayout.h:134
 TGXYLayout.h:135
 TGXYLayout.h:136
 TGXYLayout.h:137
 TGXYLayout.h:138
 TGXYLayout.h:139
 TGXYLayout.h:140
 TGXYLayout.h:141
 TGXYLayout.h:142
 TGXYLayout.h:143
 TGXYLayout.h:144
 TGXYLayout.h:145
 TGXYLayout.h:146
 TGXYLayout.h:147
 TGXYLayout.h:148
 TGXYLayout.h:149
 TGXYLayout.h:150
 TGXYLayout.h:151
 TGXYLayout.h:152
 TGXYLayout.h:153
 TGXYLayout.h:154
 TGXYLayout.h:155
 TGXYLayout.h:156
 TGXYLayout.h:157
 TGXYLayout.h:158
 TGXYLayout.h:159
 TGXYLayout.h:160
 TGXYLayout.h:161
 TGXYLayout.h:162
 TGXYLayout.h:163
 TGXYLayout.h:164