ROOT logo
// @(#)root/ged:$Id$
// Author: Ilka Antcheva   10/05/04

/*************************************************************************
 * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  TGedFrame                                                           //
//                                                                      //
//  Base frame for implementing GUI - a service class.                  //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TGedFrame.h"
#include "TGedEditor.h"
#include "TG3DLine.h"
#include "TClass.h"
#include "TCanvas.h"
#include "TGLabel.h"
#include "TGToolTip.h"
#include "TGCanvas.h"
#include "TGScrollBar.h"


ClassImp(TGedFrame)

//______________________________________________________________________________
TGedFrame::TGedFrame(const TGWindow *p, Int_t width,
                     Int_t height, UInt_t options, Pixel_t back)
      : TGCompositeFrame(p, width, height, options, back),
        fInit(kTRUE),
        fGedEditor(0),
        fModelClass(0),
        fAvoidSignal(kFALSE),
        fExtraTabs(0),
        fPriority(50)
{
   // Constructor of the base GUI attribute frame.

   fName = "";
   fGedEditor = TGedEditor::GetFrameCreator();
   SetCleanup(kDeepCleanup);
}

//______________________________________________________________________________
TGedFrame::~TGedFrame()
{
   // Destructor of the base GUI attribute frame.

   if (fExtraTabs) {
      TGedSubFrame* sf;
      TIter next(fExtraTabs);
      while ((sf = (TGedSubFrame*) next()) != 0) {
         delete sf->fFrame;
         fExtraTabs->Remove(sf);
         delete sf;
      }
      delete fExtraTabs;
   }

   // Destructor of TGCompositeFrame will do the rest.
}

//______________________________________________________________________________
void TGedFrame::Update()
{
   // Update the current pad when an attribute is changed via GUI.

   fGedEditor->Update(this);
}

//______________________________________________________________________________
Option_t *TGedFrame::GetDrawOption() const
{
   // Get draw options of the selected object.

   if (!fGedEditor->GetPad()) return "";

   TListIter next(fGedEditor->GetPad()->GetListOfPrimitives());
   TObject *obj;
   while ((obj = next())) {
      if (obj == fGedEditor->GetModel()) return next.GetOption();
   }
   return "";
}

//______________________________________________________________________________
void TGedFrame::MakeTitle(const char *title)
{
   // Create attribute frame title.

   TGCompositeFrame *f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame |
                                                              kFitWidth |
                                                              kFixedWidth |
                                                              kOwnBackground);
   f1->AddFrame(new TGLabel(f1, title),
                new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
   f1->AddFrame(new TGHorizontal3DLine(f1),
                new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
   AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
}

//______________________________________________________________________________
void TGedFrame::AddExtraTab(TGedSubFrame* sf)
{
  // Adds tab container to list of extra tabs.

   if (fExtraTabs == 0) fExtraTabs = new TList();
   fExtraTabs->Add(sf);
   sf->fFrame->SetCleanup(kDeepCleanup);
}

//______________________________________________________________________________
TGVerticalFrame* TGedFrame::CreateEditorTabSubFrame(const char* name)
{
   // Create a vertical frame to be used by 'owner' in extra tab 'name'.
   // The new frame is registered into the sub-frame list.

   TGCompositeFrame* tabcont  = fGedEditor->GetEditorTab(name);

   TGVerticalFrame* newframe = new TGVerticalFrame(tabcont);
   AddExtraTab(new TGedFrame::TGedSubFrame(TString(name), newframe));
   return newframe;
}

//______________________________________________________________________________
void TGedFrame::Refresh(TObject* model)
{
   // Refresh the GUI info about the object attributes.

   SetModel(model);
}

//______________________________________________________________________________
void TGedFrame::SetDrawOption(Option_t *option)
{
   // Set drawing option for object. This option only affects
   // the drawing style and is stored in the option field of the
   // TObjOptLink supporting a TPad's primitive list (TList).

   if (!fGedEditor->GetPad() || !option) return;

   TListIter next(fGedEditor->GetPad()->GetListOfPrimitives());
   delete fGedEditor->GetPad()->FindObject("Tframe");
   TObject *obj;
   while ((obj = next())) {
      if (obj == fGedEditor->GetModel()) {
         next.SetOption(option);
         fGedEditor->GetPad()->Modified();
         fGedEditor->GetPad()->Update();
         return;
      }
   }
}

//______________________________________________________________________________
void TGedFrame::ActivateBaseClassEditors(TClass* cl)
{
   // Provide list of editors for base-classes.
   // In this class we return all classed with editors found via recursive
   // descent into list of base classes.
   // Override to control which editors are actually shown (see TH2Editor).

   // printf("%s::FillListOfBaseEditors %s\n", IsA()->GetName(), cl->GetName());
   if (cl->GetListOfBases()->IsEmpty() == kFALSE) {
      fGedEditor->ActivateEditors(cl->GetListOfBases(), kTRUE);
   }
}

//______________________________________________________________________________
TGedNameFrame::TGedNameFrame(const TGWindow *p, Int_t width,
                              Int_t height, UInt_t options, Pixel_t back)
   : TGedFrame(p, width, height, options | kVerticalFrame, back)
{
   // Create the frame containing the selected object name.

   fPriority = 0;

   f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame |
                                            kFixedWidth      |
                                            kOwnBackground);
   f1->AddFrame(new TGLabel(f1,"Name"),
                new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
   f1->AddFrame(new TGHorizontal3DLine(f1),
                new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
   AddFrame(f1, new TGLayoutHints(kLHintsTop));

   f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame | kFixedWidth);
   fLabel = new TGLabel(f2, "");
   f2->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
   AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));

   // Set red color for the name.
   Pixel_t color;
   gClient->GetColorByName("#ff0000", color);
   fLabel->SetTextColor(color, kFALSE);

   // create tool tip with delay 300 ms
   fTip = new TGToolTip(fClient->GetDefaultRoot(), this, "TGedNameFrame", 500);

   AddInput(kEnterWindowMask | kLeaveWindowMask | kKeyPressMask | kButtonPressMask);
}

//______________________________________________________________________________
TGedNameFrame::~TGedNameFrame()
{
   // Destructor.

   delete fTip;
}

//______________________________________________________________________________
Bool_t TGedNameFrame::HandleCrossing(Event_t *event)
{
   // Handle mouse crossing event for tooltip.

   if (event->fType == kEnterNotify)
      fTip->Reset();
   else
      fTip->Hide();

   return kFALSE;
}

//______________________________________________________________________________
Bool_t TGedNameFrame::HandleButton(Event_t * /*event*/)
{
   // Handle mouse button event.

   if (fTip) fTip->Hide();

   return kFALSE;
}

//______________________________________________________________________________
void TGedNameFrame::SetModel(TObject* obj)
{
   // Sets text for the label.

   TString string;

   if (obj == 0) {
      fLabel->SetText(new TGString("Object not selected"));
      return;
   }
   string.Append(obj->GetName());
   string.Append("::");
   string.Append(obj->ClassName());

   fLabel->SetText(new TGString(string));
   string = TString::Format("Name: %s\nTitle:   %s\nClass: %s",
                            obj->GetName(), obj->GetTitle(), obj->ClassName());
   fTip->SetText(string);

   // Resize label-frame to a reasonable width.
   {
      TGCanvas     *canvas = fGedEditor->GetTGCanvas();
      TGVScrollBar *vsb    = canvas->GetVScrollbar();

      Int_t hscrollw = (vsb && vsb->IsMapped()) ? vsb->GetWidth() : 0;
      Int_t labwidth = TMath::Min(fLabel->GetDefaultSize().fWidth,
                                  canvas->GetWidth() - 10 - hscrollw);
      f2->SetWidth(TMath::Max(labwidth, 80));
   }
}
 TGedFrame.cxx:1
 TGedFrame.cxx:2
 TGedFrame.cxx:3
 TGedFrame.cxx:4
 TGedFrame.cxx:5
 TGedFrame.cxx:6
 TGedFrame.cxx:7
 TGedFrame.cxx:8
 TGedFrame.cxx:9
 TGedFrame.cxx:10
 TGedFrame.cxx:11
 TGedFrame.cxx:12
 TGedFrame.cxx:13
 TGedFrame.cxx:14
 TGedFrame.cxx:15
 TGedFrame.cxx:16
 TGedFrame.cxx:17
 TGedFrame.cxx:18
 TGedFrame.cxx:19
 TGedFrame.cxx:20
 TGedFrame.cxx:21
 TGedFrame.cxx:22
 TGedFrame.cxx:23
 TGedFrame.cxx:24
 TGedFrame.cxx:25
 TGedFrame.cxx:26
 TGedFrame.cxx:27
 TGedFrame.cxx:28
 TGedFrame.cxx:29
 TGedFrame.cxx:30
 TGedFrame.cxx:31
 TGedFrame.cxx:32
 TGedFrame.cxx:33
 TGedFrame.cxx:34
 TGedFrame.cxx:35
 TGedFrame.cxx:36
 TGedFrame.cxx:37
 TGedFrame.cxx:38
 TGedFrame.cxx:39
 TGedFrame.cxx:40
 TGedFrame.cxx:41
 TGedFrame.cxx:42
 TGedFrame.cxx:43
 TGedFrame.cxx:44
 TGedFrame.cxx:45
 TGedFrame.cxx:46
 TGedFrame.cxx:47
 TGedFrame.cxx:48
 TGedFrame.cxx:49
 TGedFrame.cxx:50
 TGedFrame.cxx:51
 TGedFrame.cxx:52
 TGedFrame.cxx:53
 TGedFrame.cxx:54
 TGedFrame.cxx:55
 TGedFrame.cxx:56
 TGedFrame.cxx:57
 TGedFrame.cxx:58
 TGedFrame.cxx:59
 TGedFrame.cxx:60
 TGedFrame.cxx:61
 TGedFrame.cxx:62
 TGedFrame.cxx:63
 TGedFrame.cxx:64
 TGedFrame.cxx:65
 TGedFrame.cxx:66
 TGedFrame.cxx:67
 TGedFrame.cxx:68
 TGedFrame.cxx:69
 TGedFrame.cxx:70
 TGedFrame.cxx:71
 TGedFrame.cxx:72
 TGedFrame.cxx:73
 TGedFrame.cxx:74
 TGedFrame.cxx:75
 TGedFrame.cxx:76
 TGedFrame.cxx:77
 TGedFrame.cxx:78
 TGedFrame.cxx:79
 TGedFrame.cxx:80
 TGedFrame.cxx:81
 TGedFrame.cxx:82
 TGedFrame.cxx:83
 TGedFrame.cxx:84
 TGedFrame.cxx:85
 TGedFrame.cxx:86
 TGedFrame.cxx:87
 TGedFrame.cxx:88
 TGedFrame.cxx:89
 TGedFrame.cxx:90
 TGedFrame.cxx:91
 TGedFrame.cxx:92
 TGedFrame.cxx:93
 TGedFrame.cxx:94
 TGedFrame.cxx:95
 TGedFrame.cxx:96
 TGedFrame.cxx:97
 TGedFrame.cxx:98
 TGedFrame.cxx:99
 TGedFrame.cxx:100
 TGedFrame.cxx:101
 TGedFrame.cxx:102
 TGedFrame.cxx:103
 TGedFrame.cxx:104
 TGedFrame.cxx:105
 TGedFrame.cxx:106
 TGedFrame.cxx:107
 TGedFrame.cxx:108
 TGedFrame.cxx:109
 TGedFrame.cxx:110
 TGedFrame.cxx:111
 TGedFrame.cxx:112
 TGedFrame.cxx:113
 TGedFrame.cxx:114
 TGedFrame.cxx:115
 TGedFrame.cxx:116
 TGedFrame.cxx:117
 TGedFrame.cxx:118
 TGedFrame.cxx:119
 TGedFrame.cxx:120
 TGedFrame.cxx:121
 TGedFrame.cxx:122
 TGedFrame.cxx:123
 TGedFrame.cxx:124
 TGedFrame.cxx:125
 TGedFrame.cxx:126
 TGedFrame.cxx:127
 TGedFrame.cxx:128
 TGedFrame.cxx:129
 TGedFrame.cxx:130
 TGedFrame.cxx:131
 TGedFrame.cxx:132
 TGedFrame.cxx:133
 TGedFrame.cxx:134
 TGedFrame.cxx:135
 TGedFrame.cxx:136
 TGedFrame.cxx:137
 TGedFrame.cxx:138
 TGedFrame.cxx:139
 TGedFrame.cxx:140
 TGedFrame.cxx:141
 TGedFrame.cxx:142
 TGedFrame.cxx:143
 TGedFrame.cxx:144
 TGedFrame.cxx:145
 TGedFrame.cxx:146
 TGedFrame.cxx:147
 TGedFrame.cxx:148
 TGedFrame.cxx:149
 TGedFrame.cxx:150
 TGedFrame.cxx:151
 TGedFrame.cxx:152
 TGedFrame.cxx:153
 TGedFrame.cxx:154
 TGedFrame.cxx:155
 TGedFrame.cxx:156
 TGedFrame.cxx:157
 TGedFrame.cxx:158
 TGedFrame.cxx:159
 TGedFrame.cxx:160
 TGedFrame.cxx:161
 TGedFrame.cxx:162
 TGedFrame.cxx:163
 TGedFrame.cxx:164
 TGedFrame.cxx:165
 TGedFrame.cxx:166
 TGedFrame.cxx:167
 TGedFrame.cxx:168
 TGedFrame.cxx:169
 TGedFrame.cxx:170
 TGedFrame.cxx:171
 TGedFrame.cxx:172
 TGedFrame.cxx:173
 TGedFrame.cxx:174
 TGedFrame.cxx:175
 TGedFrame.cxx:176
 TGedFrame.cxx:177
 TGedFrame.cxx:178
 TGedFrame.cxx:179
 TGedFrame.cxx:180
 TGedFrame.cxx:181
 TGedFrame.cxx:182
 TGedFrame.cxx:183
 TGedFrame.cxx:184
 TGedFrame.cxx:185
 TGedFrame.cxx:186
 TGedFrame.cxx:187
 TGedFrame.cxx:188
 TGedFrame.cxx:189
 TGedFrame.cxx:190
 TGedFrame.cxx:191
 TGedFrame.cxx:192
 TGedFrame.cxx:193
 TGedFrame.cxx:194
 TGedFrame.cxx:195
 TGedFrame.cxx:196
 TGedFrame.cxx:197
 TGedFrame.cxx:198
 TGedFrame.cxx:199
 TGedFrame.cxx:200
 TGedFrame.cxx:201
 TGedFrame.cxx:202
 TGedFrame.cxx:203
 TGedFrame.cxx:204
 TGedFrame.cxx:205
 TGedFrame.cxx:206
 TGedFrame.cxx:207
 TGedFrame.cxx:208
 TGedFrame.cxx:209
 TGedFrame.cxx:210
 TGedFrame.cxx:211
 TGedFrame.cxx:212
 TGedFrame.cxx:213
 TGedFrame.cxx:214
 TGedFrame.cxx:215
 TGedFrame.cxx:216
 TGedFrame.cxx:217
 TGedFrame.cxx:218
 TGedFrame.cxx:219
 TGedFrame.cxx:220
 TGedFrame.cxx:221
 TGedFrame.cxx:222
 TGedFrame.cxx:223
 TGedFrame.cxx:224
 TGedFrame.cxx:225
 TGedFrame.cxx:226
 TGedFrame.cxx:227
 TGedFrame.cxx:228
 TGedFrame.cxx:229
 TGedFrame.cxx:230
 TGedFrame.cxx:231
 TGedFrame.cxx:232
 TGedFrame.cxx:233
 TGedFrame.cxx:234
 TGedFrame.cxx:235
 TGedFrame.cxx:236
 TGedFrame.cxx:237
 TGedFrame.cxx:238
 TGedFrame.cxx:239
 TGedFrame.cxx:240
 TGedFrame.cxx:241
 TGedFrame.cxx:242
 TGedFrame.cxx:243
 TGedFrame.cxx:244
 TGedFrame.cxx:245
 TGedFrame.cxx:246
 TGedFrame.cxx:247
 TGedFrame.cxx:248
 TGedFrame.cxx:249
 TGedFrame.cxx:250
 TGedFrame.cxx:251
 TGedFrame.cxx:252
 TGedFrame.cxx:253
 TGedFrame.cxx:254
 TGedFrame.cxx:255
 TGedFrame.cxx:256
 TGedFrame.cxx:257
 TGedFrame.cxx:258
 TGedFrame.cxx:259
 TGedFrame.cxx:260
 TGedFrame.cxx:261
 TGedFrame.cxx:262
 TGedFrame.cxx:263
 TGedFrame.cxx:264
 TGedFrame.cxx:265
 TGedFrame.cxx:266
 TGedFrame.cxx:267
 TGedFrame.cxx:268
 TGedFrame.cxx:269
 TGedFrame.cxx:270
 TGedFrame.cxx:271