ROOT  6.06/09
Reference Guide
TGuiBldNameFrame.cxx
Go to the documentation of this file.
1 // @(#)root/guibuilder:$Id$
2 // Author: Valeriy Onuchin 12/09/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TGuiNameFrame //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 
18 
19 #include "TGuiBldNameFrame.h"
20 #include "TGLabel.h"
21 #include "TGTextEntry.h"
22 #include "TGuiBldEditor.h"
23 #include "TGLayout.h"
24 #include "TG3DLine.h"
25 #include "TColor.h"
26 #include "TROOT.h"
27 #include "TRootGuiBuilder.h"
28 #include "TGButton.h"
29 #include "TGFrame.h"
30 #include "TGMdiFrame.h"
31 #include "TGCanvas.h"
32 #include "TGListTree.h"
33 #include "TGuiBldDragManager.h"
34 #include "TGMsgBox.h"
35 #include "TGSplitter.h"
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Constructor.
41 
43  TGCompositeFrame(p, 1, 1)
44 {
45  fEditor = editor;
47  fManager = fBuilder->GetManager();
50  TGFrame *frame = 0;
52  if (fSelected) frame = fSelected;
53 
54  TGVerticalFrame *cf = new TGVerticalFrame(this, 180, 400);
55 
56  //list tree
58  f->AddFrame(new TGLabel(f, "MDI Frame content"),
59  new TGLayoutHints(kLHintsLeft, 0, 1, 0, 0));
61  5, 5, 7, 7));
63 
64  fCanvas = new TGCanvas(cf, 180, 110);
65  fListTree = new TGListTree(fCanvas, 0);
66  fCanvas->MapSubwindows();
68 
69  //nameframe
70  fTitleFrame = new TGHorizontalFrame(cf, 100, 30);
71  fTitleFrame->AddFrame(new TGLabel(fTitleFrame, "Variable name"),
73  0, 1, 0, 0));
74  fTitleFrame->AddFrame(new TGHorizontal3DLine(fTitleFrame),
76  1, 1, 1, 1));
77  cf->AddFrame(fTitleFrame, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
78 
79  TString name = "";
80  if (frame) {
81  name = frame->ClassName();
82  }
83  fLabel = new TGLabel(cf, name.Data());
84  cf->AddFrame(fLabel, new TGLayoutHints(kLHintsCenterX, 1, 1, 0, 0));
85 
86  TGCompositeFrame *sub = new TGHorizontalFrame(cf, 100, 30);
87  fFrameName = new TGTextEntry(sub, frame ? frame->GetName() : "noname");
88  fFrameName->SetAlignment(kTextLeft);
89  fFrameName->Resize(120, fFrameName->GetHeight());
90  sub->AddFrame(fFrameName, new TGLayoutHints(kLHintsTop | kLHintsCenterX,
91  2, 2, 0, 0));
92  fFrameName->SetEnabled(kTRUE);
93 
94  TGTextButton *btn = new TGTextButton(sub, " Set Name ");
95  sub->AddFrame(btn, new TGLayoutHints(kLHintsTop));
97  2, 2, 0, 0));
98 
99  AddFrame(cf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
100 
101  btn->Connect("Clicked()", "TGuiBldNameFrame", this, "UpdateName()");
102  btn->SetToolTipText("Set variable name");
103  fListTree->Connect("Clicked(TGListTreeItem*, Int_t)", "TGuiBldNameFrame",
104  this, "SelectFrameByItem(TGListTreeItem*, Int_t)");
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Redraw frame (just a prototype).
109 
111 {
112  //TColor *col = gROOT->GetColor(29);
113  //TRootGuiBuilder::SetBgndColor(fTitleFrame, col->GetPixel());
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Reset name frame.
119 
121 {
122  fFrameName->SetText("");
123  fLabel->SetText("");
124  DoRedraw();
125 }
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 /// Change selected frame.
129 
131 {
133 
134  if (!frame) {
135  Reset();
136  return;
137  }
138 
139  TString name = frame->ClassName();
140 
141  fLabel->SetText(name.Data());
142  fFrameName->SetText(frame->GetName());
143  Resize();
144 
145  TGCompositeFrame *main = GetMdi(frame);
146 
147  if (main) {
148  if (!fListTree->GetFirstItem())
149  MapItems(main);
150  else if ((fListTree->GetFirstItem()->GetUserData()) != main) {
151  //different MDI
152  //clear the list tree displayed
153  while (fListTree->GetFirstItem()) {
155  }
156  MapItems(main);
157  }
158  else // check if new items added or old ones reparented -> update tree
159  CheckItems(main);
160  }
161 
162  //highlight and open
163  TGListTreeItem *item = 0;
165  item = fListTree->FindItemByObj(fListTree->GetFirstItem(), frame);
166  if (item) {
167  fListTree->HighlightItem(item);
168  while (item->GetParent()) {
169  item = item->GetParent();
170  item->SetOpen(kTRUE);
171  }
172  }
175  DoRedraw();
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Set new name of frame, if it doesn't already exist in the same MDI frame.
180 
182 {
183  TGFrame *frame = fEditor->GetSelected();
184  TString ch = fFrameName->GetText();
185 
186  if (!frame) {
187  return;
188  }
189 
191  fBuilder->UpdateStatusBar("Variable name already exists.");
193  int retval;
196  "Name conflict", "Variable name already exists.",
197  kMBIconExclamation, kMBOk, &retval);
198  cf->SetEditable(kTRUE);
199  // hack against selecting the message box itself
200  fBuilder->GetManager()->SelectFrame(frame);
201  frame->SetEditable(kTRUE);
202  }
203  else {
204  fBuilder->UpdateStatusBar("Variable name changed.");
205  frame->SetName(ch);
206  }
207 
208  //clear the list tree displayed
209  while (fListTree->GetFirstItem()) {
211  }
212 
213  TGCompositeFrame *main = GetMdi(frame);
214  MapItems(main);
215 
218  DoRedraw();
219 }
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 /// Find the parent mdi frame
223 
225 {
226  TGFrame *p = frame;
227 
228  while (p && (p != fClient->GetDefaultRoot()) ) {
229  if (p->InheritsFrom(TGMdiFrame::Class())) {
230  return (TGCompositeFrame*)p;
231  }
232  else if (p->InheritsFrom(TGMainFrame::Class())) {
233  return (TGCompositeFrame*)p;
234  }
235  p = (TGFrame*)p->GetParent();
236  }
237  return 0;
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 /// Map all the frames and subframes in mdi frame to the list tree.
242 
244 {
245  if (!main) {
246  return;
247  }
248 
249  TList *list = main->GetList(); //list of all elements in the frame
250  TGFrameElement *el = 0;
251  TIter next(list);
252 
253  while ((el = (TGFrameElement *) next())) {
254  if (el->fFrame) {
255 
256  if (main->InheritsFrom(TGMdiFrame::Class()) ||
257  main->InheritsFrom(TGMainFrame::Class())) {
258 
259  // first loop, we're in the main frame -> add items directly
260  // to main frame folder of the tree list
261  if (!fListTree->FindChildByData(0, main)) {
262  // add main frame to root
263  fListTree->AddItem(0, main->GetName(), main);
264  }
265  //add other items to mainframe
267  el->fFrame->GetName(), el->fFrame);
268 
269  } else { //means we're in recursion loop, browsing in subframe
270  // result is the name of the tree folder to which we want to
271  // place the element
272  TGListTreeItem *result = 0;
273  TGFrame *par = (TGFrame*)el->fFrame->GetParent();
275  if (result)
276  fListTree->AddItem(result, el->fFrame->GetName(), el->fFrame);
277  }
278 
280  (!(el->fFrame->InheritsFrom(TGMdiFrame::Class()))) ) {
281  //recursive call for composite subframes
282  main = (TGCompositeFrame*)(el->fFrame);
283  MapItems(main);
284  }
285  }
286  }
287 }
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Check if items are in the list tree and at the same place.
291 
293 {
294  TList *list = main->GetList(); //list of all elements in the frame
295 
296  TGFrameElement *el = 0;
297  TGListTreeItem *item = 0;
298  TIter next(list);
299  TGFrame *f = 0;
300  TGListTreeItem *par = 0;
301 
302  while ((el = (TGFrameElement *) next())) {
303  if (el && (el->fFrame)) {
305  el->fFrame);
306  if (!item) {
307  f = (TGFrame*)el->fFrame->GetParent();
308  if (f) {
310  if (par)
311  fListTree->AddItem(par, el->fFrame->GetName(), el->fFrame);
312  }
313  //return kTRUE; //selected item not found = is newly created
314  }
315  else if (item->GetParent() && item->GetParent()->GetUserData() !=
316  el->fFrame->GetParent()) {
317  f = (TGFrame*)el->fFrame->GetParent();
318  if (f) {
320  if (par)
321  fListTree->Reparent(item, par);
322  }
323  //return kTRUE; //parent of the item changed
324  }
327  }
328  }
329  }
330  return kFALSE; //treelist remains the same
331 }
332 
333 ////////////////////////////////////////////////////////////////////////////////
334 /// Remove a frame.
335 
337 {
338  TGListTreeItem *item;
339  item = fListTree->FindItemByObj(fListTree->GetFirstItem(), frame);
340  if (item) {
341  fListTree->DeleteItem(item);
342  }
343 }
344 
345 ////////////////////////////////////////////////////////////////////////////////
346 /// Find item with GetText == name. Search tree downwards starting at item.
347 
349  const char* name,
350  TGListTreeItem *item)
351 {
352  TGListTreeItem *fitem;
353  if (item && name) {
354  if (!strcmp(item->GetText(), name)) { //if names are equal
355  return item;
356  }
357  else {
358  if (item->GetFirstChild()) {
359  fitem = FindItemByName(tree, name, item->GetFirstChild());
360  if (fitem) return fitem;
361  }
362  return FindItemByName(tree, name, item->GetNextSibling());
363  }
364  }
365  return 0;
366 }
367 
368 ////////////////////////////////////////////////////////////////////////////////
369 /// When list tree item is clicked, frame with that name is selected.
370 
372 {
373  TGFrame *frame = (TGFrame*)item->GetUserData();
374  if (frame) {
375  ((TGFrame*)frame->GetParent())->SetEditable(kTRUE);
376  fManager->SelectFrame(frame);
377  frame->SetEditable(kTRUE);
378  fClient->NeedRedraw(frame);
379  }
380 }
381 
382 
TRootGuiBuilder * fBuilder
TGuiBldEditor * fEditor
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
double par[1]
Definition: unuranDistr.cxx:38
TGFrame * GetSelected() const
Definition: TGuiBldEditor.h:73
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
void SelectFrame(TGFrame *frame, Bool_t add=kFALSE)
Grab/Select frame.
virtual void * GetUserData() const =0
TGListTreeItem * FindChildByData(TGListTreeItem *item, void *userData)
Find child of item by userData.
TGListTreeItem * FindItemByObj(TGListTreeItem *item, void *ptr)
Find item with fUserData == ptr.
TGListTreeItem * FindItemByName(TGListTree *tree, const char *name, TGListTreeItem *item=0)
Find item with GetText == name. Search tree downwards starting at item.
virtual void SetAlignment(ETextJustification mode=kTextLeft)
Sets the alignment of the text entry.
Int_t DeleteItem(TGListTreeItem *item)
Delete item from list tree.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
const TGWindow * GetParent() const
Definition: TGWindow.h:87
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
void Reset()
Reset name frame.
TGuiBldDragManager * fManager
Basic string class.
Definition: TString.h:137
virtual TList * GetList() const
Definition: TGFrame.h:385
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TGuiBldDragManager * GetManager() const
TGTextEntry * fFrameName
void UpdateName()
Set new name of frame, if it doesn't already exist in the same MDI frame.
TGCompositeFrame * GetMdi(TGFrame *frame)
Find the parent mdi frame.
TGuiBldEditor * fEditor
TRootGuiBuilder * fBuilder
const char * Data() const
Definition: TString.h:349
TGListTreeItem * GetParent() const
Definition: TGListTree.h:79
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:412
void Class()
Definition: Class.C:29
virtual void SetText(TGString *newText)
Set new text in label.
Definition: TGLabel.cxx:177
const char * GetText() const
Definition: TGTextEntry.h:140
virtual void SetName(const char *name)
Definition: TGWindow.h:127
void RemoveFrame(TGFrame *frame)
Remove a frame.
TGListTreeItem * GetFirstItem() const
Definition: TGListTree.h:402
A doubly linked list.
Definition: TList.h:47
virtual void UpdateStatusBar(const char *text=0)
Update information shown on the status bar.
void OpenItem(TGListTreeItem *item)
Open item in list tree (i.e. show child items).
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:1135
ClassImp(TGuiBldNameFrame) TGuiBldNameFrame
Constructor.
TGListTree * fListTree
TGListTreeItem * GetNextSibling() const
Definition: TGListTree.h:83
TGListTreeItem * GetFirstChild() const
Definition: TGListTree.h:80
void MapItems(TGCompositeFrame *main)
Map all the frames and subframes in mdi frame to the list tree.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
void AddItem(TGListTreeItem *parent, TGListTreeItem *item)
Add given item to list tree.
virtual void SetOpen(Bool_t o)
Definition: TGListTree.h:86
virtual const char * GetText() const =0
void SetEditable(Bool_t on=kTRUE)
Grab server.
TGFrame * fFrame
Definition: TGLayout.h:125
TGFrame * fSelected
int main(int argc, char *argv[])
Definition: python64.c:14
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:232
double f(double x)
virtual void SetEditable(Bool_t)
Definition: TGFrame.h:277
void SelectFrameByItem(TGListTreeItem *item, Int_t i=0)
When list tree item is clicked, frame with that name is selected.
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Definition: TQObject.cxx:1293
virtual void SetCleanup(Int_t=kLocalCleanup)
Definition: TGFrame.h:280
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
#define name(a, b)
Definition: linkTestLib0.cpp:5
void DoRedraw()
Redraw frame (just a prototype).
Int_t Reparent(TGListTreeItem *item, TGListTreeItem *newparent)
Make newparent the new parent of item.
static TGuiBuilder * Instance()
return an instance of TGuiBuilder object
TGClient * fClient
Definition: TGObject.h:41
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
UInt_t fEditDisabled
Definition: TGWindow.h:47
double result[121]
void ChangeSelected(TGFrame *frame)
Change selected frame.
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line...
virtual void SetEditable(Bool_t on=kTRUE)
Switch ON/OFF edit mode.
Definition: TGFrame.cxx:930
Bool_t CheckItems(TGCompositeFrame *main)
Check if items are in the list tree and at the same place.
void HighlightItem(TGListTreeItem *item)
Highlight item.
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
Definition: TGMsgBox.h:52