Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
37
38////////////////////////////////////////////////////////////////////////////////
39/// Constructor.
40
42 TGCompositeFrame(p, 1, 1)
43{
44 fEditor = editor;
49 TGFrame *frame = 0;
50 TGFrame *fSelected = fEditor->GetSelected();
51 if (fSelected) frame = fSelected;
52
53 TGVerticalFrame *cf = new TGVerticalFrame(this, 180, 400);
54
55 //list tree
57 f->AddFrame(new TGLabel(f, "MDI Frame content"),
58 new TGLayoutHints(kLHintsLeft, 0, 1, 0, 0));
60 5, 5, 7, 7));
62
63 fCanvas = new TGCanvas(cf, 180, 110);
67
68 //nameframe
69 fTitleFrame = new TGHorizontalFrame(cf, 100, 30);
70 fTitleFrame->AddFrame(new TGLabel(fTitleFrame, "Variable name"),
72 0, 1, 0, 0));
75 1, 1, 1, 1));
77
78 TString name = "";
79 if (frame) {
80 name = frame->ClassName();
81 }
82 fLabel = new TGLabel(cf, name.Data());
83 cf->AddFrame(fLabel, new TGLayoutHints(kLHintsCenterX, 1, 1, 0, 0));
84
85 TGCompositeFrame *sub = new TGHorizontalFrame(cf, 100, 30);
86 fFrameName = new TGTextEntry(sub, frame ? frame->GetName() : "noname");
90 2, 2, 0, 0));
92
93 TGTextButton *btn = new TGTextButton(sub, " Set Name ");
94 sub->AddFrame(btn, new TGLayoutHints(kLHintsTop));
96 2, 2, 0, 0));
97
99
100 btn->Connect("Clicked()", "TGuiBldNameFrame", this, "UpdateName()");
101 btn->SetToolTipText("Set variable name");
102 fListTree->Connect("Clicked(TGListTreeItem*, Int_t)", "TGuiBldNameFrame",
103 this, "SelectFrameByItem(TGListTreeItem*, Int_t)");
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Redraw frame (just a prototype).
108
110{
111 //TColor *col = gROOT->GetColor(29);
112 //TRootGuiBuilder::SetBgndColor(fTitleFrame, col->GetPixel());
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Reset name frame.
118
120{
121 fFrameName->SetText("");
122 fLabel->SetText("");
123 DoRedraw();
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// Change selected frame.
128
130{
132
133 if (!frame) {
134 Reset();
135 return;
136 }
137
138 TString name = frame->ClassName();
139
140 fLabel->SetText(name.Data());
141 fFrameName->SetText(frame->GetName());
142 Resize();
143
144 TGCompositeFrame *main = GetMdi(frame);
145
146 if (main) {
147 if (!fListTree->GetFirstItem())
148 MapItems(main);
149 else if ((fListTree->GetFirstItem()->GetUserData()) != main) {
150 //different MDI
151 //clear the list tree displayed
152 while (fListTree->GetFirstItem()) {
154 }
155 MapItems(main);
156 }
157 else // check if new items added or old ones reparented -> update tree
159 }
160
161 //highlight and open
162 TGListTreeItem *item = 0;
165 if (item) {
167 while (item->GetParent()) {
168 item = item->GetParent();
169 item->SetOpen(kTRUE);
170 }
171 }
174 DoRedraw();
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Set new name of frame, if it doesn't already exist in the same MDI frame.
179
181{
182 TGFrame *frame = fEditor->GetSelected();
183 TString ch = fFrameName->GetText();
184
185 if (!frame) {
186 return;
187 }
188
190 fBuilder->UpdateStatusBar("Variable name already exists.");
192 int retval;
195 "Name conflict", "Variable name already exists.",
196 kMBIconExclamation, kMBOk, &retval);
197 cf->SetEditable(kTRUE);
198 // hack against selecting the message box itself
200 frame->SetEditable(kTRUE);
201 }
202 else {
203 fBuilder->UpdateStatusBar("Variable name changed.");
204 frame->SetName(ch);
205 }
206
207 //clear the list tree displayed
208 while (fListTree->GetFirstItem()) {
210 }
211
212 TGCompositeFrame *main = GetMdi(frame);
213 MapItems(main);
214
217 DoRedraw();
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Find the parent mdi frame
222
224{
225 TGFrame *p = frame;
226
227 while (p && (p != fClient->GetDefaultRoot()) ) {
228 if (p->InheritsFrom(TGMdiFrame::Class())) {
229 return (TGCompositeFrame*)p;
230 }
231 else if (p->InheritsFrom(TGMainFrame::Class())) {
232 return (TGCompositeFrame*)p;
233 }
234 p = (TGFrame*)p->GetParent();
235 }
236 return 0;
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Map all the frames and subframes in mdi frame to the list tree.
241
243{
244 if (!main) {
245 return;
246 }
247
248 TList *list = main->GetList(); //list of all elements in the frame
249 TGFrameElement *el = 0;
250 TIter next(list);
251
252 while ((el = (TGFrameElement *) next())) {
253 if (el->fFrame) {
254
255 if (main->InheritsFrom(TGMdiFrame::Class()) ||
256 main->InheritsFrom(TGMainFrame::Class())) {
257
258 // first loop, we're in the main frame -> add items directly
259 // to main frame folder of the tree list
260 if (!fListTree->FindChildByData(0, main)) {
261 // add main frame to root
262 fListTree->AddItem(0, main->GetName(), main);
263 }
264 //add other items to mainframe
266 el->fFrame->GetName(), el->fFrame);
267
268 } else { //means we're in recursion loop, browsing in subframe
269 // result is the name of the tree folder to which we want to
270 // place the element
271 TGListTreeItem *result = 0;
272 TGFrame *par = (TGFrame*)el->fFrame->GetParent();
274 if (result)
275 fListTree->AddItem(result, el->fFrame->GetName(), el->fFrame);
276 }
277
278 if ( (el->fFrame->InheritsFrom(TGCompositeFrame::Class())) &&
279 (!(el->fFrame->InheritsFrom(TGMdiFrame::Class()))) ) {
280 //recursive call for composite subframes
281 main = (TGCompositeFrame*)(el->fFrame);
282 MapItems(main);
283 }
284 }
285 }
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Check if items are in the list tree and at the same place.
290
292{
293 TList *list = main->GetList(); //list of all elements in the frame
294
295 TGFrameElement *el = 0;
296 TGListTreeItem *item = 0;
297 TIter next(list);
298 TGFrame *f = 0;
299 TGListTreeItem *par = 0;
300
301 while ((el = (TGFrameElement *) next())) {
302 if (el && (el->fFrame)) {
304 el->fFrame);
305 if (!item) {
306 f = (TGFrame*)el->fFrame->GetParent();
307 if (f) {
309 if (par)
310 fListTree->AddItem(par, el->fFrame->GetName(), el->fFrame);
311 }
312 //return kTRUE; //selected item not found = is newly created
313 }
314 else if (item->GetParent() && item->GetParent()->GetUserData() !=
315 el->fFrame->GetParent()) {
316 f = (TGFrame*)el->fFrame->GetParent();
317 if (f) {
319 if (par)
320 fListTree->Reparent(item, par);
321 }
322 //return kTRUE; //parent of the item changed
323 }
324 if (el->fFrame->InheritsFrom(TGCompositeFrame::Class())) {
326 }
327 }
328 }
329 return kFALSE; //treelist remains the same
330}
331
332////////////////////////////////////////////////////////////////////////////////
333/// Remove a frame.
334
336{
337 TGListTreeItem *item;
339 if (item) {
340 fListTree->DeleteItem(item);
341 }
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Find item with GetText == name. Search tree downwards starting at item.
346
348 const char* name,
349 TGListTreeItem *item)
350{
351 TGListTreeItem *fitem;
352 if (item && name) {
353 if (!strcmp(item->GetText(), name)) { //if names are equal
354 return item;
355 }
356 else {
357 if (item->GetFirstChild()) {
358 fitem = FindItemByName(tree, name, item->GetFirstChild());
359 if (fitem) return fitem;
360 }
361 return FindItemByName(tree, name, item->GetNextSibling());
362 }
363 }
364 return 0;
365}
366
367////////////////////////////////////////////////////////////////////////////////
368/// When list tree item is clicked, frame with that name is selected.
369
371{
372 TGFrame *frame = (TGFrame*)item->GetUserData();
373 if (frame) {
374 ((TGFrame*)frame->GetParent())->SetEditable(kTRUE);
375 fManager->SelectFrame(frame);
376 frame->SetEditable(kTRUE);
377 fClient->NeedRedraw(frame);
378 }
379}
380
381
#define f(i)
Definition RSha256.hxx:104
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
@ kDeepCleanup
Definition TGFrame.h:50
@ kLHintsExpandY
Definition TGLayout.h:38
@ kLHintsLeft
Definition TGLayout.h:31
@ kLHintsCenterY
Definition TGLayout.h:35
@ kLHintsCenterX
Definition TGLayout.h:32
@ kLHintsTop
Definition TGLayout.h:34
@ kLHintsExpandX
Definition TGLayout.h:37
@ kMBOk
Definition TGMsgBox.h:40
@ kMBIconExclamation
Definition TGMsgBox.h:31
@ kTextLeft
Definition TGWidget.h:33
char name[80]
Definition TGX11.cxx:110
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:398
virtual void MapSubwindows()
Map all canvas sub windows.
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:233
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:371
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1102
virtual void SetEditable(Bool_t on=kTRUE)
Switch ON/OFF edit mode.
Definition TGFrame.cxx:933
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1057
TGFrame * fFrame
Definition TGLayout.h:119
virtual void DoRedraw()
Redraw the frame.
Definition TGFrame.cxx:415
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:590
virtual void SetEditable(Bool_t)
Definition TGFrame.h:238
UInt_t GetHeight() const
Definition TGFrame.h:249
virtual void SetText(TGString *newText)
Set new text in label.
Definition TGLabel.cxx:179
TGListTreeItem * GetFirstChild() const
Definition TGListTree.h:74
virtual const char * GetText() const =0
TGListTreeItem * GetNextSibling() const
Definition TGListTree.h:77
TGListTreeItem * GetParent() const
Definition TGListTree.h:73
virtual void SetOpen(Bool_t o)
Definition TGListTree.h:80
virtual void * GetUserData() const =0
TGListTreeItem * FindItemByObj(TGListTreeItem *item, void *ptr)
Find item with fUserData == ptr.
void AddItem(TGListTreeItem *parent, TGListTreeItem *item)
Add given item to list tree.
void OpenItem(TGListTreeItem *item)
Open item in list tree (i.e. show child items).
Int_t Reparent(TGListTreeItem *item, TGListTreeItem *newparent)
Make newparent the new parent of item.
Int_t DeleteItem(TGListTreeItem *item)
Delete item from list tree.
TGListTreeItem * GetFirstItem() const
Definition TGListTree.h:396
void HighlightItem(TGListTreeItem *item)
Highlight item.
TGListTreeItem * FindChildByData(TGListTreeItem *item, void *userData)
Find child of item by userData.
TGClient * fClient
Definition TGObject.h:37
const char * GetText() const
void SetEnabled(Bool_t flag=kTRUE)
virtual void SetAlignment(ETextJustification mode=kTextLeft)
Sets the alignment of the text entry.
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 const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:335
virtual void SetName(const char *name)
Definition TGWindow.h:122
@ kEditDisable
Definition TGWindow.h:58
const TGWindow * GetParent() const
Definition TGWindow.h:84
UInt_t fEditDisabled
Definition TGWindow.h:40
void SelectFrame(TGFrame *frame, Bool_t add=kFALSE)
Grab/Select frame.
void SetEditable(Bool_t on=kTRUE)
Grab server.
TGFrame * GetSelected() const
void Reset()
Reset name frame.
Bool_t CheckItems(TGCompositeFrame *main)
Check if items are in the list tree and at the same place.
void UpdateName()
Set new name of frame, if it doesn't already exist in the same MDI frame.
void RemoveFrame(TGFrame *frame)
Remove a frame.
TGListTree * fListTree
TRootGuiBuilder * fBuilder
TGCompositeFrame * fTitleFrame
void MapItems(TGCompositeFrame *main)
Map all the frames and subframes in mdi frame to the list tree.
void SelectFrameByItem(TGListTreeItem *item, Int_t i=0)
When list tree item is clicked, frame with that name is selected.
TGTextEntry * fFrameName
TGuiBldNameFrame(const TGWindow *p, TGuiBldEditor *editor)
Constructor.
TGuiBldEditor * fEditor
void DoRedraw()
Redraw frame (just a prototype).
TGCompositeFrame * GetMdi(TGFrame *frame)
Find the parent mdi frame.
TGuiBldDragManager * fManager
void ChangeSelected(TGFrame *frame)
Change selected frame.
TGListTreeItem * FindItemByName(TGListTree *tree, const char *name, TGListTreeItem *item=0)
Find item with GetText == name. Search tree downwards starting at item.
static TGuiBuilder * Instance()
return an instance of TGuiBuilder object
A doubly linked list.
Definition TList.h:44
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:130
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
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:866
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
virtual void UpdateStatusBar(const char *text=0)
Update information shown on the status bar.
TGuiBldDragManager * GetManager() const
Basic string class.
Definition TString.h:136
int main()
Definition tree.py:1