Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TStyleDialog.cxx
Go to the documentation of this file.
1// @(#)root/ged:$Id$
2// Author: Denis Favre-Miville 08/09/05
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 TStyleDialog
14\ingroup ged
15
16This small class is useful to ask the user for a name and a title,
17 in order to rename a style, create a new style or import a
18 style from a canvas.
19
20*/
21
22
23#include "TStyleDialog.h"
24#include "TStyleManager.h"
25
26#include <TCanvas.h>
27#include <TGButton.h>
28#include <TGLabel.h>
29#include <TGLayout.h>
30#include <TGTextEntry.h>
31#include <TROOT.h>
32#include <TStyle.h>
33#include <TVirtualMutex.h>
34
35#include <cstdlib>
36
38
44};
45
46////////////////////////////////////////////////////////////////////////////////
47/// Constructor. Create the dialog window and draw it centered over the
48/// main window 'mf'. A pointer to the style to copy or rename is given
49/// by 'cur' and the parameter 'mode' specify the mode:
50/// 1 = copy | 2 = rename | 3 = import from canvas.
51
53 TVirtualPad *currentPad)
54 : TGTransientFrame(0, sm)
55{
56 fStyleManager = sm;
57
58 // Create the main frame.
60 fCurStyle = cur;
61 fMode = mode;
62 fCurPad = currentPad;
63
64 switch (fMode) {
65 case 1: SetWindowName("Create a New Style"); break;
66 case 2: SetWindowName("Rename the Selected Style"); break;
67 case 3: SetWindowName("Import a New Style from Canvas");
68 }
69
70 // Create the trash lists to have an effective deletion of every object.
71 fTrashListLayout = new TList();
72 fTrashListFrame = new TList();
73
74 // Create the layouts and add them to the layout trash list.
75 TGLayoutHints *layoutNameLabel = new TGLayoutHints(kLHintsNormal, 0, 70, 3);
76 fTrashListLayout->Add(layoutNameLabel);
77 TGLayoutHints *layoutTitleLabel = new TGLayoutHints(kLHintsNormal, 0, 39, 3);
78 fTrashListLayout->Add(layoutTitleLabel);
79 TGLayoutHints *layoutWarningLabel = new TGLayoutHints(kLHintsExpandX);
80 fTrashListLayout->Add(layoutWarningLabel);
81 TGLayoutHints *layoutOKButton = new TGLayoutHints(kLHintsExpandX, 0, 5);
82 fTrashListLayout->Add(layoutOKButton);
83 TGLayoutHints *layoutCancelButton = new TGLayoutHints(kLHintsExpandX, 5);
84 fTrashListLayout->Add(layoutCancelButton);
85 TGLayoutHints *layoutH1 = new TGLayoutHints(kLHintsExpandX, 10, 10, 10, 5);
86 fTrashListLayout->Add(layoutH1);
87 TGLayoutHints *layoutH2 = new TGLayoutHints(kLHintsExpandX, 10, 10, 5, 5);
88 fTrashListLayout->Add(layoutH2);
89 TGLayoutHints *layoutH4 = new TGLayoutHints(kLHintsExpandX, 10, 10, 5, 10);
90 fTrashListLayout->Add(layoutH4);
91
92 // Create and place the widgets in the main window.
93 // Every frame created here must be added to the frame trash list.
96 fNameLabel = new TGLabel(h1, "Name:");
97 h1->AddFrame(fNameLabel, layoutNameLabel);
98
99 if (fMode == 1) {
100 TString newName;
101 newName.Form("%s_1", fCurStyle->GetName());
102 fName = new TGTextEntry(h1, newName.Data(), kName);
103 } else if (fMode == 2) {
104 // The names of the 5 basics styles can not be modified.
106 if ((!strcmp(fName->GetText(), "Default"))
107 || (!strcmp(fName->GetText(), "Plain" ))
108 || (!strcmp(fName->GetText(), "Bold" ))
109 || (!strcmp(fName->GetText(), "Video" ))
110 || (!strcmp(fName->GetText(), "Pub" ))) fName->SetEnabled(kFALSE);
111 } else
112 fName = new TGTextEntry(h1, "Imported_Style", kName);
113 fName->Associate(this);
114 fName->Resize(200, 22);
115 h1->AddFrame(fName);
116 AddFrame(h1, layoutH1);
117
118 TGHorizontalFrame *h2 = new TGHorizontalFrame(this);
119 fTrashListFrame->Add(h2);
120 fTitleLabel = new TGLabel(h2, "Description:");
121 h2->AddFrame(fTitleLabel, layoutTitleLabel);
122 switch (fMode) {
123 case 1:
124 case 2:
126 break;
127 case 3: {
128 TString newTitle("Imported from canvas ");
129 if (fCurPad->GetCanvas())
130 newTitle += fCurPad->GetCanvas()->GetName();
131 fTitle = new TGTextEntry(h2, newTitle.Data(), kTitle);
132 }
133 }
134 fTitle->Associate(this);
135 fTitle->Resize(200, 22);
136 h2->AddFrame(fTitle);
137 fTitle->Associate(h2);
138 AddFrame(h2, layoutH2);
139
140 TGHorizontalFrame *h3 = new TGHorizontalFrame(this);
141 fTrashListFrame->Add(h3);
142 fWarnLabel = new TGLabel(h3);
143 Pixel_t red;
144 gClient->GetColorByName("#FF0000", red);
146 fWarnLabel->Resize(200, 22);
147 h3->AddFrame(fWarnLabel, layoutWarningLabel);
148 AddFrame(h3, layoutH2);
149
150 TGHorizontalFrame *h4 = new TGHorizontalFrame(this);
151 fTrashListFrame->Add(h4);
152 fOK = new TGTextButton(h4, "&OK", kButOK);
153 fOK->Associate(this);
154 h4->AddFrame(fOK, layoutOKButton);
155 fOK->Associate(h4);
156 fCancel = new TGTextButton(h4, "&Cancel", kButCancel);
157 fCancel->Associate(this);
158 h4->AddFrame(fCancel, layoutCancelButton);
159 fCancel->Associate(h4);
160 AddFrame(h4, layoutH4);
161
162 // Refresh the warning message.
163 DoUpdate();
164
165 Resize();
170 SetWMSizeHints(w, h, w, h, 0, 0);
171 MapWindow();
172
173 switch (fMode) {
174 case 1:
175 fOK->SetToolTipText("Create this new style");
176 fCancel->SetToolTipText("Cancel the creation ");
177 break;
178 case 2:
179 fOK->SetToolTipText("Rename the selected style");
180 fCancel->SetToolTipText("Cancel the rename ");
181 break;
182 case 3:
183 fOK->SetToolTipText("Import this new style from the canvas");
184 fCancel->SetToolTipText("Cancel the import");
185 break;
186 }
187
188 Connect("CloseWindow()", "TStyleDialog", this, "DoCloseWindow()");
189 fName->Connect("TextChanged(const char *)", "TStyleDialog", this, "DoUpdate()");
190 fOK->Connect("Clicked()", "TStyleDialog", this, "DoOK()");
191 fCancel->Connect("Clicked()", "TStyleDialog", this, "DoCancel()");
192
193 gClient->WaitFor(this);
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// Destructor.
198
200{
201 Disconnect("DoCloseWindow()");
202 fName->Disconnect("TextChanged(const char *)");
203 fOK->Disconnect("Clicked()");
204 fCancel->Disconnect("Clicked()");
205
206 delete fName;
207 delete fNameLabel;
208 delete fTitle;
209 delete fTitleLabel;
210 delete fWarnLabel;
211 delete fOK;
212 delete fCancel;
213
214 TObject *obj1;
215 TObject *obj2;
216
217 obj1 = fTrashListFrame->First();
218 while (obj1) {
219 obj2 = fTrashListFrame->After(obj1);
220 fTrashListFrame->Remove(obj1);
221 delete obj1;
222 obj1 = obj2;
223 }
224 delete fTrashListFrame;
225
226 obj1 = fTrashListLayout->First();
227 while (obj1) {
228 obj2 = fTrashListLayout->After(obj1);
230 delete obj1;
231 obj1 = obj2;
232 }
233 delete fTrashListLayout;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Slot called when the Cancel button is clicked. Close the window
238/// without saving submitted changes.
239
241{
243
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Slot called when the window is closed via the window manager.
249/// Close the window without saving submitted changes.
250
252{
253 delete this;
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Slot called when the OK button is clicked. Rename or create the style
258/// before closing the window.
259
261{
262 if (fMode == 2) {
263 // Update the name and the title of the style.
266 } else {
267 // Create a new style (copy of fCurStyle), with the given name and title.
268 TStyle *tmpStyle = new TStyle(*fCurStyle);
269 tmpStyle->SetName(fName->GetText());
270 tmpStyle->SetTitle(fTitle->GetText());
271 {
273 gROOT->GetListOfStyles()->Add(tmpStyle);
274 }
275 if (fMode == 3) {
276 // Import the properties of the canvas.
277 TStyle *tmp = gStyle;
278 gStyle = tmpStyle;
280 if (fCurPad->GetCanvas())
283 gStyle = tmp;
284 }
285 }
286
288
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// Slot called every time the name is changed. Provide some protection
294/// to avoid letting the user use an empty name or an already used one.
295/// A warning message can be shown and the OK button disabled.
296
298{
299 if (!strlen(fName->GetText())) {
300 fWarnLabel->SetText("That name is empty");
302 return;
303 }
304
305 if (strstr(fName->GetText(), " ") != 0) {
306 fWarnLabel->SetText("That name contains some spaces");
308 return;
309 }
310
311 switch (fMode) {
312 case 1:
313 case 3:
314 if (gROOT->GetStyle(fName->GetText())) {
315 fWarnLabel->SetText("That name is already used by another style.");
317 return;
318 }
319 break;
320 case 2:
321 TStyle *tmp = gROOT->GetStyle(fName->GetText());
322 if (tmp && (tmp != fCurStyle)) {
323 fWarnLabel->SetText("That name is already used by another style.");
325 return;
326 }
327 }
328
329 fWarnLabel->SetText("");
331}
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define h(i)
Definition RSha256.hxx:106
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
#define gClient
Definition TGClient.h:157
@ kNoCleanup
Definition TGFrame.h:40
@ kLHintsNormal
Definition TGLayout.h:32
@ kLHintsExpandX
Definition TGLayout.h:30
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t SetWMSizeHints
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:407
EStyleDialogWid
@ kName
@ kButOK
@ kButCancel
@ kTitle
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
#define R__LOCKGUARD(mutex)
void UseCurrentStyle() override
Force a copy of current style for all objects in canvas.
Definition TCanvas.cxx:1183
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:445
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition TGButton.cxx:459
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:312
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:314
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1072
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
void MapWindow() override
map window
Definition TGFrame.h:204
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 SetTextColor(Pixel_t color, Bool_t global=kFALSE)
Changes text color.
Definition TGLabel.cxx:362
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
virtual void SendCloseMessage()
Send close message to self.
Definition TGFrame.cxx:1744
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
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)
Defines transient windows that typically are used for dialogs windows.
Definition TGFrame.h:498
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition TGFrame.cxx:1957
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
A doubly linked list.
Definition TList.h:38
TObject * After(const TObject *obj) const override
Returns the object after object obj.
Definition TList.cxx:330
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:822
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:659
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
Mother of all ROOT objects.
Definition TObject.h:41
const char * GetName() const override
Returns name of object.
Definition TPad.h:258
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.
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:380
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2334
This small class is useful to ask the user for a name and a title, in order to rename a style,...
void DoCancel()
Slot called when the Cancel button is clicked.
TList * fTrashListLayout
to avoid memory leak
void DoOK()
Slot called when the OK button is clicked.
~TStyleDialog() override
Destructor.
TStyleDialog(TStyleManager *sm, TStyle *cur, Int_t mode, TVirtualPad *currentPad=nullptr)
Constructor.
Int_t fMode
1=new, 2=rename, 3=import
TGTextEntry * fTitle
TStyle title text entry.
void DoCloseWindow()
Slot called when the window is closed via the window manager.
TVirtualPad * fCurPad
current pad from which to import
TList * fTrashListFrame
to avoid memory leak
TStyle * fCurStyle
style to copy or to rename
TGTextButton * fOK
save button
TGTextEntry * fName
TStyle name text entry.
TGTextButton * fCancel
cancel button
TStyleManager * fStyleManager
parent style manager
TGLabel * fTitleLabel
title label
TGLabel * fNameLabel
name label
void DoUpdate()
Slot called every time the name is changed.
TGLabel * fWarnLabel
label for warnings
This class provides a Graphical User Interface to manage styles in ROOT.
void SetLastChoice(Bool_t choice)
TStyle objects may be created to define special styles.
Definition TStyle.h:29
void SetIsReading(Bool_t reading=kTRUE)
Sets the fIsReading member to reading (default=kTRUE).
Definition TStyle.cxx:1370
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual TCanvas * GetCanvas() const =0
TH1F * h1
Definition legend1.C:5