[ROOT] Layout of TG classes.

From: Brett Viren (bv@bnl.gov)
Date: Thu Nov 08 2001 - 21:58:30 MET


Hi,

Who ever wrote TGTableLayout must be pretty dumb! <grin>

I just noticed that if you try to nest TGCompositeFrames which are
layed out using TGTableLayout you have to be very careful to call
Layout() on those frames in the order from innermost table to outer
most table.

I haven't been able to understand why this is, but then I never really
understood the Layout protocol in the first place, so it isn't
surprising that TGTableLayout isn't robust in that area.

The appended example demonstrates what I mean.  It is a 2x1 table
holding a button and a 2x1 table holding 2 buttons.

Any ideas?

-Brett.

PS: Fons: thanks for the virtual signals.  Fast work!

/////////////////////////
// test-table.cxx
// compile like:
//
// g++ -g -Wall -o test-table test-table.cxx `root-config --cflags --glibs`
//
// and things work
// but compile like:
//
// g++ -DI_WANT_A_SEGV -g -Wall -o test-table test-table.cxx `root-config --cflags --glibs`
//
// and you will trigger the segfault
//
#include "TROOT.h"
#include "TApplication.h"
#include "TGFrame.h"
#include "TGTableLayout.h"
#include "TGButton.h"

int main (int argc, char *argv[])
{
    TApplication theApp("App", &argc, argv);

    TGMainFrame mf(gClient->GetRoot(),100,100);

    TGCompositeFrame table1(&mf,400,400,kSunkenFrame);
    table1.SetLayoutManager(new TGTableLayout(&table1, 2, 1));

    mf.AddFrame(&table1,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY));

    TGCompositeFrame table2(&table1,400,400,kSunkenFrame);
    table2.SetLayoutManager(new TGTableLayout(&table2, 2, 1));


    TGTextButton b1(&table1,"one");
    table1.AddFrame(&b1,new TGTableLayoutHints(0,1,0,1,
                                    kLHintsExpandX|kLHintsExpandY |
                                    kLHintsShrinkX|kLHintsShrinkY |
                                    kLHintsFillX|kLHintsFillY));

    table1.AddFrame(&table2,new TGTableLayoutHints(0,1,1,2,
                                    kLHintsExpandX|kLHintsExpandY |
                                    kLHintsShrinkX|kLHintsShrinkY |
                                    kLHintsFillX|kLHintsFillY));

    TGTextButton b2(&table2,"two");
    table2.AddFrame(&b2,new TGTableLayoutHints(0,1,0,1,
                                    kLHintsExpandX|kLHintsExpandY |
                                    kLHintsShrinkX|kLHintsShrinkY |
                                    kLHintsFillX|kLHintsFillY));

    TGTextButton b3(&table2,"three");
    table2.AddFrame(&b3,new TGTableLayoutHints(0,1,1,2,
                                    kLHintsExpandX|kLHintsExpandY |
                                    kLHintsShrinkX|kLHintsShrinkY |
                                    kLHintsFillX|kLHintsFillY));

    
#ifdef I_WANT_A_SEGV
    // This will segfault.  Also, if you have no Layout() called or
    // only one Layout called.
    table1.Layout();
    table2.Layout();
#else
    // Only combination which works.
    table2.Layout();
    table1.Layout();
#endif

    mf.MapSubwindows();
    mf.Layout();
    mf.MapWindow();

    theApp.Run();
    return 0;
} // end of main()



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:07 MET