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).
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();
}