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/** \class TGuiNameFrame
14 \ingroup guibuilder
15*/
16
17
18#include "TGuiBldNameFrame.h"
19#include "TGLabel.h"
20#include "TGTextEntry.h"
21#include "TGuiBldEditor.h"
22#include "TGLayout.h"
23#include "TG3DLine.h"
24#include "TColor.h"
25#include "TROOT.h"
26#include "TRootGuiBuilder.h"
27#include "TGButton.h"
28#include "TGFrame.h"
29#include "TGMdiFrame.h"
30#include "TGCanvas.h"
31#include "TGListTree.h"
32#include "TGuiBldDragManager.h"
33#include "TGMsgBox.h"
34
36
37////////////////////////////////////////////////////////////////////////////////
38/// Constructor.
39
41 TGCompositeFrame(p, 1, 1)
42{
43 fEditor = editor;
48 TGFrame *frame = 0;
49 TGFrame *fSelected = fEditor->GetSelected();
50 if (fSelected) frame = fSelected;
51
52 TGVerticalFrame *cf = new TGVerticalFrame(this, 180, 400);
53
54 //list tree
56 f->AddFrame(new TGLabel(f, "MDI Frame content"),
57 new TGLayoutHints(kLHintsLeft, 0, 1, 0, 0));
59 5, 5, 7, 7));
61
62 fCanvas = new TGCanvas(cf, 180, 110);
66
67 //nameframe
68 fTitleFrame = new TGHorizontalFrame(cf, 100, 30);
69 fTitleFrame->AddFrame(new TGLabel(fTitleFrame, "Variable name"),
71 0, 1, 0, 0));
74 1, 1, 1, 1));
76
77 TString name = "";
78 if (frame) {
79 name = frame->ClassName();
80 }
81 fLabel = new TGLabel(cf, name.Data());
82 cf->AddFrame(fLabel, new TGLayoutHints(kLHintsCenterX, 1, 1, 0, 0));
83
84 TGCompositeFrame *sub = new TGHorizontalFrame(cf, 100, 30);
85 fFrameName = new TGTextEntry(sub, frame ? frame->GetName() : "noname");
89 2, 2, 0, 0));
91
92 TGTextButton *btn = new TGTextButton(sub, " Set Name ");
93 sub->AddFrame(btn, new TGLayoutHints(kLHintsTop));
95 2, 2, 0, 0));
96
98
99 btn->Connect("Clicked()", "TGuiBldNameFrame", this, "UpdateName()");
100 btn->SetToolTipText("Set variable name");
101 fListTree->Connect("Clicked(TGListTreeItem*, Int_t)", "TGuiBldNameFrame",
102 this, "SelectFrameByItem(TGListTreeItem*, Int_t)");
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Redraw frame (just a prototype).
107
109{
110 //TColor *col = gROOT->GetColor(29);
111 //TRootGuiBuilder::SetBgndColor(fTitleFrame, col->GetPixel());
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Reset name frame.
117
119{
120 fFrameName->SetText("");
121 fLabel->SetText("");
122 DoRedraw();
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Change selected frame.
127
129{
131
132 if (!frame) {
133 Reset();
134 return;
135 }
136
137 TString name = frame->ClassName();
138
139 fLabel->SetText(name.Data());
140 fFrameName->SetText(frame->GetName());
141 Resize();
142
143 TGCompositeFrame *main = GetMdi(frame);
144
145 if (main) {
146 if (!fListTree->GetFirstItem())
147 MapItems(main);
148 else if ((fListTree->GetFirstItem()->GetUserData()) != main) {
149 //different MDI
150 //clear the list tree displayed
151 while (fListTree->GetFirstItem()) {
153 }
154 MapItems(main);
155 }
156 else // check if new items added or old ones reparented -> update tree
158 }
159
160 //highlight and open
161 TGListTreeItem *item = 0;
164 if (item) {
166 while (item->GetParent()) {
167 item = item->GetParent();
168 item->SetOpen(kTRUE);
169 }
170 }
173 DoRedraw();
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Set new name of frame, if it doesn't already exist in the same MDI frame.
178
180{
181 TGFrame *frame = fEditor->GetSelected();
182 TString ch = fFrameName->GetText();
183
184 if (!frame) {
185 return;
186 }
187
189 fBuilder->UpdateStatusBar("Variable name already exists.");
191 int retval;
194 "Name conflict", "Variable name already exists.",
195 kMBIconExclamation, kMBOk, &retval);
196 cf->SetEditable(kTRUE);
197 // hack against selecting the message box itself
199 frame->SetEditable(kTRUE);
200 }
201 else {
202 fBuilder->UpdateStatusBar("Variable name changed.");
203 frame->SetName(ch);
204 }
205
206 //clear the list tree displayed
207 while (fListTree->GetFirstItem()) {
209 }
210
211 TGCompositeFrame *main = GetMdi(frame);
212 MapItems(main);
213
216 DoRedraw();
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Find the parent mdi frame
221
223{
224 TGFrame *p = frame;
225
226 while (p && (p != fClient->GetDefaultRoot()) ) {
228 return (TGCompositeFrame*)p;
229 }
230 else if (p->InheritsFrom(TGMainFrame::Class())) {
231 return (TGCompositeFrame*)p;
232 }
233 p = (TGFrame*)p->GetParent();
234 }
235 return 0;
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Map all the frames and subframes in mdi frame to the list tree.
240
242{
243 if (!main) {
244 return;
245 }
246
247 TList *list = main->GetList(); //list of all elements in the frame
248 TGFrameElement *el = 0;
249 TIter next(list);
250
251 while ((el = (TGFrameElement *) next())) {
252 if (el->fFrame) {
253
254 if (main->InheritsFrom(TGMdiFrame::Class()) ||
255 main->InheritsFrom(TGMainFrame::Class())) {
256
257 // first loop, we're in the main frame -> add items directly
258 // to main frame folder of the tree list
259 if (!fListTree->FindChildByData(0, main)) {
260 // add main frame to root
261 fListTree->AddItem(0, main->GetName(), main);
262 }
263 //add other items to mainframe
265 el->fFrame->GetName(), el->fFrame);
266
267 } else { //means we're in recursion loop, browsing in subframe
268 // result is the name of the tree folder to which we want to
269 // place the element
271 TGFrame *par = (TGFrame*)el->fFrame->GetParent();
273 if (result)
275 }
276
278 (!(el->fFrame->InheritsFrom(TGMdiFrame::Class()))) ) {
279 //recursive call for composite subframes
280 main = (TGCompositeFrame*)(el->fFrame);
281 MapItems(main);
282 }
283 }
284 }
285}
286
287////////////////////////////////////////////////////////////////////////////////
288/// Check if items are in the list tree and at the same place.
289
291{
292 TList *list = main->GetList(); //list of all elements in the frame
293
294 TGFrameElement *el = 0;
295 TGListTreeItem *item = 0;
296 TIter next(list);
297 TGFrame *f = 0;
298 TGListTreeItem *par = 0;
299
300 while ((el = (TGFrameElement *) next())) {
301 if (el && (el->fFrame)) {
303 el->fFrame);
304 if (!item) {
305 f = (TGFrame*)el->fFrame->GetParent();
306 if (f) {
308 if (par)
309 fListTree->AddItem(par, el->fFrame->GetName(), el->fFrame);
310 }
311 //return kTRUE; //selected item not found = is newly created
312 }
313 else if (item->GetParent() && item->GetParent()->GetUserData() !=
314 el->fFrame->GetParent()) {
315 f = (TGFrame*)el->fFrame->GetParent();
316 if (f) {
318 if (par)
319 fListTree->Reparent(item, par);
320 }
321 //return kTRUE; //parent of the item changed
322 }
325 }
326 }
327 }
328 return kFALSE; //treelist remains the same
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Remove a frame.
333
335{
336 TGListTreeItem *item;
338 if (item) {
339 fListTree->DeleteItem(item);
340 }
341}
342
343////////////////////////////////////////////////////////////////////////////////
344/// Find item with GetText == name. Search tree downwards starting at item.
345
347 const char* name,
348 TGListTreeItem *item)
349{
350 TGListTreeItem *fitem;
351 if (item && name) {
352 if (!strcmp(item->GetText(), name)) { //if names are equal
353 return item;
354 }
355 else {
356 if (item->GetFirstChild()) {
357 fitem = FindItemByName(tree, name, item->GetFirstChild());
358 if (fitem) return fitem;
359 }
360 return FindItemByName(tree, name, item->GetNextSibling());
361 }
362 }
363 return 0;
364}
365
366////////////////////////////////////////////////////////////////////////////////
367/// When list tree item is clicked, frame with that name is selected.
368
370{
371 TGFrame *frame = (TGFrame*)item->GetUserData();
372 if (frame) {
373 ((TGFrame*)frame->GetParent())->SetEditable(kTRUE);
374 fManager->SelectFrame(frame);
375 frame->SetEditable(kTRUE);
376 fClient->NeedRedraw(frame);
377 }
378}
379
380
int main()
Definition Prototype.cxx:12
#define f(i)
Definition RSha256.hxx:104
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
@ kMBOk
Definition TGMsgBox.h:33
@ kMBIconExclamation
Definition TGMsgBox.h:24
@ kTextLeft
Definition TGWidget.h:23
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
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:445
A frame containing two scrollbars (a horizontal and a vertical) and a viewport.
Definition TGCanvas.h:192
void MapSubwindows() override
Map all canvas sub windows.
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:234
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:372
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1072
void SetEditable(Bool_t on=kTRUE) override
Switch ON/OFF edit mode.
Definition TGFrame.cxx:948
static TClass * Class()
TGFrame * fFrame
Definition TGLayout.h:112
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:430
UInt_t GetHeight() const
Definition TGFrame.h:225
void SetEditable(Bool_t) override
Definition TGFrame.h:214
A horizontal 3D line is a line that typically separates a toolbar from the menubar.
Definition TG3DLine.h:18
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
This class handles GUI labels.
Definition TGLabel.h:24
virtual void SetText(TGString *newText)
Set new text in label.
Definition TGLabel.cxx:180
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
TGListTreeItem * GetFirstChild() const
Definition TGListTree.h:59
virtual const char * GetText() const =0
TGListTreeItem * GetNextSibling() const
Definition TGListTree.h:62
TGListTreeItem * GetParent() const
Definition TGListTree.h:58
virtual void SetOpen(Bool_t o)
Definition TGListTree.h:65
virtual void * GetUserData() const =0
A list tree is a widget that can contain a number of items arranged in a tree structure.
Definition TGListTree.h:195
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:381
void HighlightItem(TGListTreeItem *item)
Highlight item.
TGListTreeItem * FindChildByData(TGListTreeItem *item, void *userData)
Find child of item by userData.
static TClass * Class()
static TClass * Class()
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
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.
A composite frame that layout their children in vertical way.
Definition TGFrame.h:374
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void SetName(const char *name)
Definition TGWindow.h:121
@ kEditDisable
disable edit of this window
Definition TGWindow.h:57
const TGWindow * GetParent() const
Definition TGWindow.h:83
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
void SelectFrame(TGFrame *frame, Bool_t add=kFALSE)
Grab/Select frame.
void SetEditable(Bool_t on=kTRUE) override
Grab server.
The property editor.
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.
TGListTreeItem * FindItemByName(TGListTree *tree, const char *name, TGListTreeItem *item=nullptr)
Find item with GetText == name. Search tree downwards starting at item.
void UpdateName()
Set new name of frame, if it doesn't already exist in the same MDI frame.
void RemoveFrame(TGFrame *frame) override
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.
void DoRedraw() override
Redraw frame (just a prototype).
TGuiBldEditor * fEditor
TGCompositeFrame * GetMdi(TGFrame *frame)
Find the parent mdi frame.
TGuiBldDragManager * fManager
void ChangeSelected(TGFrame *frame)
Change selected frame.
static TGuiBuilder * Instance()
return an instance of TGuiBuilder object
A doubly linked list.
Definition TList.h:38
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
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:869
Bool_t Disconnect(const char *signal=nullptr, void *receiver=nullptr, const char *slot=nullptr)
Disconnects signal of this object from slot of receiver.
virtual void UpdateStatusBar(const char *text=nullptr)
Update information shown on the status bar.
TGuiBldDragManager * GetManager() const
Basic string class.
Definition TString.h:139