Re: TDialogCanvas problem

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Jul 06 1998 - 12:45:59 MEST


mayer@ik1.fzk.de wrote:
> 
> Dear rooters
> 
> I tried to build a simple directory browser using TCanvas and TButton.
> In principle it works, but frequently I get access violations, followed
> by more access violations, when moving the mouse across the Canvas.
> What is wrong with it?
> 
> Another point. The TButton::SetTextAlign method does not work correctly for
> left and right alignment (12),(32).
> 

Your code cannot work. In your DialogCanvas, you create buttons.
When clicking on one button, you erase the DialogCanvas (including
the button currently executing!!).
The functionality to try to implement is already implemented
via the Root browser.
To invoke the Root browser, simply do
  TBrowser B;


Rene Brun



> Thanks in advance
>                   Hajo
> 
> -------------------------------------------------------------------------
> // invoke main() after opening a root file with a directory structure
> //
> TDialogCanvas *dirCanvas;
> 
> void doit(const char *dir)
> {
>    gDirectory->cd(dir);
>    drawdir();
> }
> void drawdir()
> {
>    Coord_t ylow = 0.94;
>    Coord_t yup  = 0.99;
>    Text_t cmd[40];
>    TKey *key;
> 
>    dirCanvas->Clear();
> 
>    TList *lkeys = gDirectory->GetListOfKeys();
>    TIter nextkey(lkeys);
>    while (key = (TKey*)nextkey()) {
>        printf("keyname %s\n",key->GetName());
>        printf("classname %s\n",key->GetClassName());
>        if (!strcmp(key->GetClassName(),"TDirectory")) {
>           sprintf(cmd,"doit(\"%s\")",key->GetName());
>           printf("keyname %s\n",key->GetTitle());
>           TButton *button = new TButton(key->GetTitle(),cmd,0.2,ylow,0.95,yup);
>           button->SetFillColor(10);
>           button->SetTextAlign(12);
>           button->Draw();
>           yup  += -0.05;
>           ylow += -0.05;
>        }
>    }
>    TButton *button = new TButton("back","doit("../")",0.5,0.1,0.6,0.2);
>    button->SetFillColor(18);
>    button->SetTextAlign(22);
>    button->Draw();
>    dirCanvas->Modified(kTRUE);
>    dirCanvas->Update();
>    dirCanvas->cd();
> }
> 
> int main()
> {
> 
>    dirCanvas = new TDialogCanvas("dirCanvas","",400,200);
>    dirCanvas->SetHighLightColor(2);
>    dirCanvas->Range(0,0,1,1);
>    dirCanvas->SetFillColor(10);
>    dirCanvas->SetBorderSize(2);
>    dirCanvas->SetDoubleBuffer(1);
>    gDirectory->pwd();
>    drawdir();
> 
> }



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:34 MET