The New


GUI Classes


Fons Rademakers

GSI Darmstadt / Hewlett-Packard


The New ROOT GUI Classes

Features of the new GUI classes in a nutshell:



Originally written by Hector Peraza

Complete set of widgets:

label, icon, button, check button, radio button, picture button, list box, combo box, list view, icon view, text entry, text view, tree view, tab view, scrollbar, slider, menubar, popup menu, cascading menu, statusbar, toolbar, message dialogs, file selection dialog, ...

The widgets are shown in frames:

frame, composite frame, main frame, transient frame, group frame

And arranged by layout managers:

horizontal layout, vertical layout, row layout, list layout, tile layout, matrix layout, ...

Using a combination of layout hints:

left, center x, right, top, center y, bottom, expand x, expand y and fixed offsets

Event handling by messaging (as opposed to callbacks):

in response to actions widgets send messages (SendMessage()) to associated frames (ProcessMessage())


ROOT Integration (1)

Replaced all calls to X11 by calls to the ROOT abstract graphics base class TGXW

Currently concrete implementations of TGXW exist for:

In the near future we plan to provide: Thanks to this single graphics interface porting ROOT to a new platform (BeOS, Rhapsody, etc.) requires only the implementation of TGXW (and TSystem).


Abstract Graphics Base Class TGXW


Concrete implementations of TGXW are TGX11, for X Windows, TGWin32 for Win95/NT. The TGXClient implementation provides a network interface allowing for remote display via the rootdisp servers.


ROOT Integration (2)

Further changes:

GUI Example (1)


// File: main.cxx

#include <TApplication.h> 
#include <TGClient.h>
#include "MyMain.h"
int main(int argc, char **argv) 
    TApplication theApp("App", &argc, argv);
    MyMainFrame mainWin(gClient->GetRoot(), 200, 220);
    return 0;

Compile example using:
g++ `root-config --cflags --glibs` -o main main.cxx MyMain.cxx

GUI Example (2)


// File: MyMain.h

#include <TGClient.h>
#include <TGButton.h>
class MyMainFrame : public TGMainFrame {
    TGTextButton    *fButton1, *fButton2;
    TGPictureButton *fPicBut;
    TGCheckButton   *fChkBut;
    TGRadioButton   *fRBut1, *fRBut2;
    TGLayoutHints   *fLayout;
    MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
    ~MyMainFrame() { } // need to delete here created widgets
    Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);

GUI Example (3)


// File: MyMain.cxx

#include "MyMain.h"

MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
    : TGMainFrame(p, w, h)
    // Create a main frame with a number of different buttons.

    fButton1 = new TGTextButton(this, "&Version", 1);
    fButton1->SetCommand("printf(\"This is ROOT version %s\\n\","
    fButton2 = new TGTextButton(this, "&Exit", 2);
    fButton2->SetCommand(".q" );
    fPicBut = new TGPictureButton(this, gClient->GetPicture("world.xpm"), 3);
    fPicBut->SetCommand("printf(\"hello world!\\n\");");
    fChkBut = new TGCheckButton(this, "Check Button", 4);
    fRBut1 = new TGRadioButton(this, "Radio Button 1", 5);
    fRBut2 = new TGRadioButton(this, "Radio Button 2", 6);
    fLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY);
    AddFrame(fButton1, fLayout);
    AddFrame(fPicBut, fLayout);
    AddFrame(fButton2, fLayout);
    AddFrame(fChkBut, fLayout);
    AddFrame(fRBut1, fLayout);
    AddFrame(fRBut2, fLayout);
    SetWindowName("Button Example");
    SetIconName("Button Example");

GUI Example (4)


// Continuation of MyMain.cxx

Bool_t MyMainFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
    // Process events generated by the buttons in the frame.
    switch (GET_MSG(msg)) {
        case kC_COMMAND:
            switch (GET_SUBMSG(msg)) {
                case kCM_BUTTON:
                    printf("text button id %ld pressed\n", parm1);
                case kCM_CHECKBUTTON:
                    printf("check button id %ld pressed\n", parm1);
                case kCM_RADIOBUTTON:
                    if (parm1 == 5)
                    if (parm1 == 6)
                    printf("radio button id %ld pressed\n", parm1);
    return kTRUE;

Output of GUI Example