22 ClassImp(TGItemContext);
 
   31 TGItemContext::TGItemContext()
 
   39 void TGItemContext::Draw(Option_t *)
 
   41    fItem->GetContainer()->GetViewer()->ProcessMessage(MK_MSG(kC_CONTAINER, kCT_ITEMDBLCLICK), kButton1, 0);
 
   47 void TGItemContext::EditExpression()
 
   49    fItem->GetContainer()->GetViewer()->EditExpression();
 
   55 void TGItemContext::Empty()
 
   63 void TGItemContext::RemoveItem()
 
   65    fItem->GetContainer()->GetViewer()->RemoveItem();
 
   71 void TGItemContext::Scan()
 
   73    fItem->GetContainer()->GetViewer()->SetScanMode();
 
   74    fItem->GetContainer()->GetViewer()->ProcessMessage(MK_MSG(kC_CONTAINER, kCT_ITEMDBLCLICK), kButton1, 0);
 
   80 void TGItemContext::SetExpression(
const char *name, 
const char *alias, Bool_t cut)
 
   82    fItem->SetExpression(name, alias, cut);
 
   96 TTVLVEntry::TTVLVEntry(
const TGWindow *p,
 
   97                              const TGPicture *bigpic, 
const TGPicture *smallpic,
 
   98                              TGString *name, TGString **subnames,
 
   99                              EListViewMode ViewMode)
 
  100               :TGLVEntry(p, bigpic, smallpic, name, subnames, ViewMode)
 
  103    fContainer = (TTVLVContainer *) p;
 
  107    fTrueName = name->GetString();
 
  108    fContext = 
new TGItemContext();
 
  109    fContext->Associate(
this);
 
  111    AddInput(kEnterWindowMask | kLeaveWindowMask);
 
  117 TTVLVEntry::~TTVLVEntry()
 
  119    if (fTip) 
delete fTip;
 
  126 const char *TTVLVEntry::ConvertAliases()
 
  128    TList *list = GetContainer()->GetViewer()->ExpressionList();
 
  129    fConvName = fTrueName;
 
  130    TString start(fConvName);
 
  133    while (!FullConverted()) {
 
  136       while ((item=(TTVLVEntry*)next())) {
 
  138             fConvName.ReplaceAll(item->GetAlias(), item->GetTrueName());
 
  140       if (fConvName == start) {
 
  143          return(fConvName.Data());
 
  146    return(fConvName.Data());
 
  152 Bool_t TTVLVEntry::FullConverted()
 
  154    TList *list = GetContainer()->GetViewer()->ExpressionList();
 
  157    while ((item=(TTVLVEntry*)next())) {
 
  159          if (fConvName.Contains(item->GetAlias())) 
return kFALSE;
 
  168 void TTVLVEntry::CopyItem(TTVLVEntry *dest)
 
  171    dest->SetExpression(fTrueName.Data(), fAlias.Data(), fIsCut);
 
  172    TString alias = dest->GetAlias();
 
  173    if (!alias.BeginsWith(
"~") && !alias.Contains(
"empty")) dest->PrependTilde();
 
  179 Bool_t TTVLVEntry::HandleCrossing(Event_t *event)
 
  182       if (event->fType == kEnterNotify)
 
  193 Bool_t TTVLVEntry::HasAlias()
 
  195    if (fAlias.Length()) 
return kTRUE;
 
  202 void TTVLVEntry::PrependTilde()
 
  204    fAlias = 
"~" + fAlias;
 
  205    SetItemName(fAlias.Data());
 
  211 void TTVLVEntry::SetItemName(
const char* name)
 
  213    if (fItemName) 
delete fItemName;
 
  214    fItemName = 
new TGString(name);
 
  215    Int_t max_ascent, max_descent;
 
  216    fTWidth = gVirtualX->TextWidth(fFontStruct, fItemName->GetString(), fItemName->GetLength());
 
  217    gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
 
  218    fTHeight = max_ascent + max_descent;
 
  219    gVirtualX->ClearWindow(fId);
 
  220    Resize(GetDefaultSize());
 
  221    fClient->NeedRedraw(
this);
 
  227 void TTVLVEntry::SetCutType(Bool_t type)
 
  229    if (fIsCut && type) 
return;
 
  230    if (!fIsCut && !type) 
return;
 
  232       SetSmallPic(fClient->GetPicture(
"selection_t.xpm"));
 
  233       SetToolTipText(
"Selection expression. Drag to scissors to activate");
 
  235       SetSmallPic(fClient->GetPicture(
"expression_t.xpm"));
 
  242 void TTVLVEntry::SetExpression(
const char* name, 
const char* alias, Bool_t cutType)
 
  247    ULong_t *itemType = (ULong_t *) GetUserData();
 
  248    if (*itemType & TTreeViewer::kLTPackType) {
 
  250          SetSmallPic(fClient->GetPicture(
"pack_t.xpm"));
 
  252          SetSmallPic(fClient->GetPicture(
"pack-empty_t.xpm"));
 
  254    if ((*itemType & TTreeViewer::kLTDragType) && strlen(name) && !fIsCut)
 
  255       SetToolTipText(
"Double-click to draw. Drag and drop. Use Edit/Expression or context menu to edit.");
 
  256    if (*itemType & TTreeViewer::kLTDragType) SetCutType(cutType);
 
  262 void TTVLVEntry::Empty()
 
  264    SetExpression(
"",
"-empty-");
 
  265    ULong_t *itemType = (ULong_t *) GetUserData();
 
  266    if (itemType && (*itemType & TTreeViewer::kLTDragType))
 
  267       SetToolTipText(
"User-defined expression/cut. Double-click to edit");
 
  274 void TTVLVEntry::SetToolTipText(
const char *text, Long_t delayms)
 
  281    if (text && strlen(text))
 
  282       fTip = 
new TGToolTip(fClient->GetRoot(), 
this, text, delayms);
 
  287 void TTVLVEntry::SetSmallPic(
const TGPicture *spic)
 
  289    const TGPicture *cspic = fSmallPic;
 
  291    fCurrent = fSmallPic;
 
  292    if (fSelPic) 
delete fSelPic;
 
  295       fSelPic = 
new TGSelectedPicture(fClient, fCurrent);
 
  298    fClient->FreePicture(cspic);
 
  301 ClassImp(TTVLVContainer);
 
  312 TTVLVContainer::TTVLVContainer(
const TGWindow *p, UInt_t w, UInt_t h, UInt_t options)
 
  313           :TGLVContainer(p, w, h,options | kSunkenFrame)
 
  317    fExpressionList = 
new TList;
 
  318    fCursor = gVirtualX->CreateCursor(kMove);
 
  319    fDefaultCursor = gVirtualX->CreateCursor(kPointer);
 
  320    fMapSubwindows = kTRUE;
 
  326 TTVLVContainer::~TTVLVContainer()
 
  328    delete fExpressionList;
 
  334 const char* TTVLVContainer::Cut()
 
  336    TGFrameElement *el = (TGFrameElement *) fList->At(3);
 
  338       TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  339       if (f) 
return f->ConvertAliases();
 
  348 TTVLVEntry * TTVLVContainer::ExpressionItem(Int_t index)
 
  350    TGFrameElement *el = (TGFrameElement *) fList->At(index);
 
  352       TTVLVEntry *item = (TTVLVEntry *) el->fFrame;
 
  361 TList* TTVLVContainer::ExpressionList()
 
  363    fExpressionList->Clear();
 
  366    while ((el = (TGFrameElement*)next())) {
 
  367       TTVLVEntry *item = (TTVLVEntry *)el->fFrame;
 
  369          ULong_t *itemType = (ULong_t *) item->GetUserData();
 
  370          if ((*itemType & TTreeViewer::kLTExpressionType) &&
 
  371             (*itemType & TTreeViewer::kLTDragType)) fExpressionList->Add(item);
 
  374    return fExpressionList;
 
  380 const char* TTVLVContainer::Ex()
 
  382    TGFrameElement *el = (TGFrameElement *) fList->At(0);
 
  384       TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  385       if (f) 
return f->ConvertAliases();
 
  394 const char* TTVLVContainer::Ey()
 
  396    TGFrameElement *el = (TGFrameElement *) fList->At(1);
 
  398       TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  399       if (f) 
return f->ConvertAliases();
 
  408 const char* TTVLVContainer::Ez()
 
  410    TGFrameElement *el = (TGFrameElement *) fList->At(2);
 
  412       TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  413       if (f) 
return f->ConvertAliases();
 
  422 const char* TTVLVContainer::ScanList()
 
  424    TGFrameElement *el = (TGFrameElement *) fList->At(4);
 
  426       TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  427       if (f) 
return f->GetTrueName();
 
  436 Bool_t TTVLVContainer::HandleButton(Event_t *event)
 
  440    if (event->fType == kButtonPress) {
 
  444          fLastActive->Activate(kFALSE);
 
  447       total = selected = 0;
 
  451       while ((el = (TGFrameElement *) next())) {
 
  452          TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  454          if (f->GetId() == (Window_t)event->fUser[0]) {  
 
  456             if (f->GetTip()) (f->GetTip())->Hide();
 
  466       if (fTotal != total || fSelected != selected) {
 
  468          fSelected = selected;
 
  469          SendMessage(fMsgWindow, MK_MSG(kC_CONTAINER, kCT_SELCHANGED),
 
  473       if (selected == 1 && event->fCode == 1) {
 
  474          ULong_t *itemType = (ULong_t *) fLastActive->GetUserData();
 
  475          if (*itemType & TTreeViewer::kLTDragType) {
 
  477             gVirtualX->SetCursor(fId,fCursor);
 
  484    if (event->fType == kButtonRelease) {
 
  487          gVirtualX->SetCursor(fId,fDefaultCursor);
 
  488          fLastActive->Move(fX0,fY0);
 
  491          while ((el = (TGFrameElement *) next())) {
 
  492             TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  493             if ((f == fLastActive) || !f->IsActive()) 
continue;
 
  494             ULong_t *itemType = (ULong_t *) f->GetUserData();
 
  495             fLastActive->Activate(kFALSE);
 
  496             if (!(*itemType & TTreeViewer::kLTPackType)) {
 
  498                ((TTVLVEntry *) fLastActive)->CopyItem(f);
 
  499                if (*itemType & TTreeViewer::kLTDragType)
 
  500                   f->SetToolTipText(
"Double-click to draw. Drag and drop. Use Edit/Expression or context menu to edit.");
 
  502                if (strlen(((TTVLVEntry *) fLastActive)->GetTrueName())) {
 
  504                   if (!strlen(f->GetTrueName())) {
 
  505                      f->SetTrueName(((TTVLVEntry *)fLastActive)->GetTrueName());
 
  506                      f->SetSmallPic(fClient->GetPicture(
"pack_t.xpm"));
 
  509                      TString dragged = ((TTVLVEntry *)fLastActive)->ConvertAliases();
 
  510                      name  = f->GetTrueName();
 
  511                      if ((name.Length()+dragged.Length()) < 228) {
 
  514                         f->SetTrueName(name.Data());
 
  516                         Warning(
"HandleButton",
 
  517                                 "Name too long. Can not add any more items to scan box.");
 
  526                snprintf(msg,2000, 
"Content : %s", f->GetTrueName());
 
  527                fViewer->Message(msg);
 
  530          if ((TMath::Abs(event->fX - fXp) < 2) && (TMath::Abs(event->fY - fYp) < 2)) {
 
  531             SendMessage(fMsgWindow, MK_MSG(kC_CONTAINER, kCT_ITEMCLICK),
 
  532                         event->fCode, (event->fYRoot << 16) | event->fXRoot);
 
  535          SendMessage(fMsgWindow, MK_MSG(kC_CONTAINER, kCT_ITEMCLICK),
 
  536                      event->fCode, (event->fYRoot << 16) | event->fXRoot);
 
  545 Bool_t TTVLVContainer::HandleMotion(Event_t *event)
 
  547    Int_t xf0, xff, yf0, yff;
 
  548    Int_t xpos = 
event->fX - (fXp-fX0);
 
  549    Int_t ypos = 
event->fY - (fYp-fY0);
 
  555       while ((el = (TGFrameElement *) next())) {
 
  556          TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  557          if (f == fLastActive) {
 
  558             if (f->GetTip()) (f->GetTip())->Hide();
 
  563          xff = f->GetX() + f->GetWidth();
 
  564          yff = f->GetY() + f->GetHeight();
 
  565          itemType = (ULong_t *) f->GetUserData();
 
  566          if (*itemType & TTreeViewer::kLTExpressionType) {
 
  567             if (xpos>xf0 && xpos<xff && ypos>yf0 && ypos<yff) {
 
  574       if ((fXp - event->fX) > 10) {
 
  575          fListView->SetHsbPosition(0);
 
  576          fListView->SetVsbPosition(0);
 
  578       fLastActive->Move(xpos, ypos);
 
  579       gVirtualX->RaiseWindow(fLastActive->GetId());
 
  580       SendMessage(fMsgWindow, MK_MSG(kC_CONTAINER,(EWidgetMessageTypes)4),event->fX, event->fY);
 
  588 void TTVLVContainer::EmptyAll()
 
  592    while ((el = (TGFrameElement *) next())) {
 
  593       TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  594       UInt_t *userData = (UInt_t *) f->GetUserData();
 
  595       if (*userData & TTreeViewer::kLTExpressionType) {
 
  596          if (*userData & TTreeViewer::kLTPackType) {
 
  597             f->SetSmallPic(fClient->GetPicture(
"pack-empty_t.xpm"));
 
  609 void TTVLVContainer::RemoveNonStatic()
 
  613    while ((el = (TGFrameElement *) next())) {
 
  614       TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  615       UInt_t *userData = (UInt_t *) f->GetUserData();
 
  616       if (!((*userData) & TTreeViewer::kLTExpressionType)) {
 
  626 void TTVLVContainer::SelectItem(
const char* name)
 
  629       fLastActive->Activate(kFALSE);
 
  635    while ((el = (TGFrameElement *) next())) {
 
  636       TTVLVEntry *f = (TTVLVEntry *) el->fFrame;
 
  637       if (!strcmp(f->GetItemName()->GetString(),name)) {
 
  639          fLastActive = (TGLVEntry *) f;
 
  647 ClassImp(TGSelectBox);
 
  656 enum ETransientFrameCommands {
 
  661 TGSelectBox* TGSelectBox::fgInstance = 0;
 
  666 TGSelectBox::TGSelectBox(
const TGWindow *p, 
const TGWindow *main,
 
  668             :TGTransientFrame(p, main, w, h)
 
  672       fViewer = (TTreeViewer *)fMain;
 
  673       if (!fViewer) Error(
"TGSelectBox", 
"Must be started from viewer");
 
  675       fLayout = 
new TGLayoutHints(kLHintsTop | kLHintsCenterY | kLHintsExpandX, 0, 0, 0, 2);
 
  676       fBLayout = 
new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 2, 2, 2);
 
  677       fBLayout1= 
new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 0, 2, 2);
 
  679       fLabel = 
new TGLabel(
this, 
"");
 
  680       AddFrame(fLabel,fLayout);
 
  682       fTe = 
new TGTextEntry(
this, 
new TGTextBuffer(2000));
 
  683       fTe->SetToolTipText(
"Type an expression using C++ syntax. Click other expression/leaves to paste them here.");
 
  684       AddFrame(fTe, fLayout);
 
  686       fLabelAlias = 
new TGLabel(
this, 
"Alias");
 
  687       AddFrame(fLabelAlias,fLayout);
 
  689       fTeAlias = 
new TGTextEntry(
this, 
new TGTextBuffer(100));
 
  690       fTeAlias->SetToolTipText(
"Define an alias for this expression. Do NOT use leading strings of other aliases.");
 
  691       AddFrame(fTeAlias, fLayout);
 
  693       fBf = 
new TGHorizontalFrame(
this, 10, 10);
 
  695       fCANCEL = 
new TGTextButton(fBf, 
"&Cancel", kTFCancel);
 
  696       fCANCEL->Associate(
this);
 
  697       fBf->AddFrame(fCANCEL, fBLayout);
 
  699       fDONE = 
new TGTextButton(fBf, 
"&Done", kTFDone);
 
  700       fDONE->Associate(
this);
 
  701       fBf->AddFrame(fDONE, fBLayout1);
 
  703       AddFrame(fBf, fLayout);
 
  706       Resize(GetDefaultSize());
 
  711       gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(), 25,
 
  712                         (Int_t)(((TGFrame *) main)->GetHeight() - fHeight) >> 1,
 
  714       MoveResize(ax, ay, w, GetDefaultHeight());
 
  722 TGSelectBox::~TGSelectBox()
 
  740 void TGSelectBox::CloseWindow()
 
  742    gVirtualX->UnmapWindow(GetId());
 
  749 TGSelectBox * TGSelectBox::GetInstance()
 
  757 void TGSelectBox::GrabPointer()
 
  760    event.fType = kButtonPress;
 
  761    event.fCode = kButton1;
 
  762    event.fX = 
event.fY = 1;
 
  763    Int_t position = fTe->GetCursorPosition();
 
  764    fTe->HandleButton(&event);
 
  765    fTe->SetCursorPosition(position);
 
  771 void TGSelectBox::SetLabel(
const char* title)
 
  773    fLabel->SetText(
new TGString(title));
 
  779 void TGSelectBox::SaveText()
 
  784       TString name(fTe->GetText());
 
  786          fEntry->SetToolTipText(
"Double-click to draw. Drag and drop. Use Edit/Expression or context menu to edit.");
 
  788          fEntry->SetToolTipText(
"User-defined expression/cut. Double-click to edit");
 
  790       cutType = name.Contains(
"<") || name.Contains(
">") || name.Contains(
"=") ||
 
  791                 name.Contains(
"!") || name.Contains(
"&") || name.Contains(
"|");
 
  792       TString alias(fTeAlias->GetText());
 
  793       if (!alias.BeginsWith(
"~") && !alias.Contains(
"empty")) fTeAlias->InsertText(
"~", 0);
 
  794       fEntry->SetExpression(fTe->GetText(), fTeAlias->GetText(), cutType);
 
  796       if (fOldAlias.Contains(
"empty")) {
 
  797          fOldAlias = fTeAlias->GetText();
 
  800       TList *list = fViewer->ExpressionList();
 
  803       while ((item=(TTVLVEntry*)next())) {
 
  804          if (item != fEntry) {
 
  805             name = item->GetTrueName();
 
  806             name.ReplaceAll(fOldAlias.Data(), fTeAlias->GetText());
 
  807             item->SetTrueName(name.Data());
 
  816 void TGSelectBox::SetEntry(TTVLVEntry *entry)
 
  819    fTe->SetText(entry->GetTrueName());
 
  820    fTeAlias->SetText(entry->GetAlias());
 
  821    fOldAlias = entry->GetAlias();
 
  827 void TGSelectBox::InsertText(
const char* text)
 
  829    Int_t start = fTe->GetCursorPosition();
 
  830    fTe->InsertText(text, fTe->GetCursorPosition());
 
  831    fTe->SetCursorPosition(start+strlen(text));
 
  837 Bool_t TGSelectBox::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
 
  839    switch (GET_MSG(msg)) {
 
  841          switch (GET_SUBMSG(msg)) {
 
  843                if (ValidateAlias()) SaveText();
 
  850          switch (GET_SUBMSG(msg)) {
 
  854                      if (!ValidateAlias()) 
break;
 
  879 Bool_t TGSelectBox::ValidateAlias()
 
  881    if (!strcmp(fTeAlias->GetText(), 
"-empty-") || !strlen(fTeAlias->GetText())) {
 
  882       fViewer->Warning(
"ValidateAlias", 
"You should define the alias first.");
 
  885    TList *list = fViewer->ExpressionList();
 
  888    while ((item=(TTVLVEntry*)next())) {
 
  889       if (item != fEntry) {
 
  890          TString itemalias(item->GetAlias());
 
  891          if (itemalias.Contains(fTeAlias->GetText())) {
 
  892             fViewer->Warning(
"ValidAlias", 
"Alias can not be the leading string of other alias.");