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
35
36////////////////////////////////////////////////////////////////////////////////
37/// Constructor.
38
40 TGCompositeFrame(p, 1, 1)
41{
47 TGFrame *frame = 0;
48 TGFrame *fSelected = fEditor->GetSelected();
49 if (fSelected) frame = fSelected;
50
51 TGVerticalFrame *cf = new TGVerticalFrame(this, 180, 400);
52
53 //list tree
55 f->AddFrame(new TGLabel(f, "MDI Frame content"),
56 new TGLayoutHints(kLHintsLeft, 0, 1, 0, 0));
58 5, 5, 7, 7));
59 cf->AddFrame(f, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
60
61 fCanvas = new TGCanvas(cf, 180, 110);
65
66 //nameframe
67 fTitleFrame = new TGHorizontalFrame(cf, 100, 30);
68 fTitleFrame->AddFrame(new TGLabel(fTitleFrame, "Variable name"),
70 0, 1, 0, 0));
73 1, 1, 1, 1));
75
76 TString name = "";
77 if (frame) {
78 name = frame->ClassName();
79 }
80 fLabel = new TGLabel(cf, name.Data());
81 cf->AddFrame(fLabel, new TGLayoutHints(kLHintsCenterX, 1, 1, 0, 0));
82
83 TGCompositeFrame *sub = new TGHorizontalFrame(cf, 100, 30);
84 fFrameName = new TGTextEntry(sub, frame ? frame->GetName() : "noname");
88 2, 2, 0, 0));
90
91 TGTextButton *btn = new TGTextButton(sub, " Set Name ");
93 cf->AddFrame(sub, new TGLayoutHints(kLHintsTop | kLHintsCenterX,
94 2, 2, 0, 0));
95
97
98 btn->Connect("Clicked()", "TGuiBldNameFrame", this, "UpdateName()");
99 btn->SetToolTipText("Set variable name");
100 fListTree->Connect("Clicked(TGListTreeItem*, Int_t)", "TGuiBldNameFrame",
101 this, "SelectFrameByItem(TGListTreeItem*, Int_t)");
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Redraw frame (just a prototype).
106
108{
109 //TColor *col = gROOT->GetColor(29);
110 //TRootGuiBuilder::SetBgndColor(fTitleFrame, col->GetPixel());
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Reset name frame.
116
118{
119 fFrameName->SetText("");
120 fLabel->SetText("");
121 DoRedraw();
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Change selected frame.
126
128{
130
131 if (!frame) {
132 Reset();
133 return;
134 }
135
136 TString name = frame->ClassName();
137
138 fLabel->SetText(name.Data());
139 fFrameName->SetText(frame->GetName());
140 Resize();
141
142 TGCompositeFrame *main = GetMdi(frame);
143
144 if (main) {
145 if (!fListTree->GetFirstItem())
146 MapItems(main);
147 else if ((fListTree->GetFirstItem()->GetUserData()) != main) {
148 //different MDI
149 //clear the list tree displayed
150 while (fListTree->GetFirstItem()) {
152 }
153 MapItems(main);
154 }
155 else // check if new items added or old ones reparented -> update tree
157 }
158
159 //highlight and open
160 TGListTreeItem *item = 0;
163 if (item) {
165 while (item->GetParent()) {
166 item = item->GetParent();
167 item->SetOpen(kTRUE);
168 }
169 }
172 DoRedraw();
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Set new name of frame, if it doesn't already exist in the same MDI frame.
177
179{
180 TGFrame *frame = fEditor->GetSelected();
181 TString ch = fFrameName->GetText();
182
183 if (!frame) {
184 return;
185 }
186
188 fBuilder->UpdateStatusBar("Variable name already exists.");
190 int retval;
193 "Name conflict", "Variable name already exists.",
195 cf->SetEditable(kTRUE);
196 // hack against selecting the message box itself
198 frame->SetEditable(kTRUE);
199 }
200 else {
201 fBuilder->UpdateStatusBar("Variable name changed.");
202 frame->SetName(ch);
203 }
204
205 //clear the list tree displayed
206 while (fListTree->GetFirstItem()) {
208 }
209
210 TGCompositeFrame *main = GetMdi(frame);
211 MapItems(main);
212
215 DoRedraw();
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Find the parent mdi frame
220
222{
223 TGFrame *p = frame;
224
225 while (p && (p != fClient->GetDefaultRoot()) ) {
226 if (p->InheritsFrom(TGMdiFrame::Class())) {
227 return (TGCompositeFrame*)p;
228 }
229 else if (p->InheritsFrom(TGMainFrame::Class())) {
230 return (TGCompositeFrame*)p;
231 }
232 p = (TGFrame*)p->GetParent();
233 }
234 return 0;
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Map all the frames and subframes in mdi frame to the list tree.
239
241{
242 if (!main) {
243 return;
244 }
245
246 TList *list = main->GetList(); //list of all elements in the frame
247 TGFrameElement *el = 0;
248 TIter next(list);
249
250 while ((el = (TGFrameElement *) next())) {
251 if (el->fFrame) {
252
253 if (main->InheritsFrom(TGMdiFrame::Class()) ||
254 main->InheritsFrom(TGMainFrame::Class())) {
255
256 // first loop, we're in the main frame -> add items directly
257 // to main frame folder of the tree list
258 if (!fListTree->FindChildByData(0, main)) {
259 // add main frame to root
260 fListTree->AddItem(0, main->GetName(), main);
261 }
262 //add other items to mainframe
264 el->fFrame->GetName(), el->fFrame);
265
266 } else { //means we're in recursion loop, browsing in subframe
267 // result is the name of the tree folder to which we want to
268 // place the element
270 TGFrame *par = (TGFrame*)el->fFrame->GetParent();
272 if (result)
273 fListTree->AddItem(result, el->fFrame->GetName(), el->fFrame);
274 }
275
276 if ( (el->fFrame->InheritsFrom(TGCompositeFrame::Class())) &&
277 (!(el->fFrame->InheritsFrom(TGMdiFrame::Class()))) ) {
278 //recursive call for composite subframes
279 main = (TGCompositeFrame*)(el->fFrame);
280 MapItems(main);
281 }
282 }
283 }
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Check if items are in the list tree and at the same place.
288
290{
291 TList *list = main->GetList(); //list of all elements in the frame
292
293 TGFrameElement *el = 0;
294 TGListTreeItem *item = 0;
295 TIter next(list);
296 TGFrame *f = 0;
297 TGListTreeItem *par = 0;
298
299 while ((el = (TGFrameElement *) next())) {
300 if (el && (el->fFrame)) {
302 el->fFrame);
303 if (!item) {
304 f = (TGFrame*)el->fFrame->GetParent();
305 if (f) {
307 if (par)
308 fListTree->AddItem(par, el->fFrame->GetName(), el->fFrame);
309 }
310 //return kTRUE; //selected item not found = is newly created
311 }
312 else if (item->GetParent() && item->GetParent()->GetUserData() !=
313 el->fFrame->GetParent()) {
314 f = (TGFrame*)el->fFrame->GetParent();
315 if (f) {
317 if (par)
318 fListTree->Reparent(item, par);
319 }
320 //return kTRUE; //parent of the item changed
321 }
322 if (el->fFrame->InheritsFrom(TGCompositeFrame::Class())) {
323 CheckItems((TGCompositeFrame*)el->fFrame);
324 }
325 }
326 }
327 return kFALSE; //treelist remains the same
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Remove a frame.
332
341
342////////////////////////////////////////////////////////////////////////////////
343/// Find item with GetText == name. Search tree downwards starting at item.
344
346 const char* name,
348{
350 if (item && name) {
351 if (!strcmp(item->GetText(), name)) { //if names are equal
352 return item;
353 }
354 else {
355 if (item->GetFirstChild()) {
356 fitem = FindItemByName(tree, name, item->GetFirstChild());
357 if (fitem) return fitem;
358 }
359 return FindItemByName(tree, name, item->GetNextSibling());
360 }
361 }
362 return 0;
363}
364
365////////////////////////////////////////////////////////////////////////////////
366/// When list tree item is clicked, frame with that name is selected.
367
369{
370 TGFrame *frame = (TGFrame*)item->GetUserData();
371 if (frame) {
372 ((TGFrame*)frame->GetParent())->SetEditable(kTRUE);
373 fManager->SelectFrame(frame);
374 frame->SetEditable(kTRUE);
375 fClient->NeedRedraw(frame);
376 }
377}
378
379
int main()
Definition Prototype.cxx:12
#define f(i)
Definition RSha256.hxx:104
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ 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
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:233
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:380
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:289
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1064
void SetEditable(Bool_t on=kTRUE) override
Switch ON/OFF edit mode.
Definition TGFrame.cxx:940
static TClass * Class()
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:597
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:422
UInt_t GetHeight() const
Definition TGFrame.h:227
void SetEditable(Bool_t) override
Definition TGFrame.h:216
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:387
This class handles GUI labels.
Definition TGLabel.h:24
virtual void SetText(TGString *newText)
Set new text in label.
Definition TGLabel.cxx:179
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
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:197
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:383
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:376
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:334
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:226
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:865
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:138