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
37
44
45////////////////////////////////////////////////////////////////////////////////
46/// Constructor. Create the dialog window and draw it centered over the
47/// main window 'mf'. A pointer to the style to copy or rename is given
48/// by 'cur' and the parameter 'mode' specify the mode:
49/// 1 = copy | 2 = rename | 3 = import from canvas.
50
54{
56
57 // Create the main frame.
59 fCurStyle = cur;
60 fMode = mode;
62
63 switch (fMode) {
64 case 1: SetWindowName("Create a New Style"); break;
65 case 2: SetWindowName("Rename the Selected Style"); break;
66 case 3: SetWindowName("Import a New Style from Canvas");
67 }
68
69 // Create the trash lists to have an effective deletion of every object.
70 fTrashListLayout = new TList();
71 fTrashListFrame = new TList();
72
73 // Create the layouts and add them to the layout trash list.
90
91 // Create and place the widgets in the main window.
92 // Every frame created here must be added to the frame trash list.
95 fNameLabel = new TGLabel(h1, "Name:");
96 h1->AddFrame(fNameLabel, layoutNameLabel);
97
98 if (fMode == 1) {
100 newName.Form("%s_1", fCurStyle->GetName());
101 fName = new TGTextEntry(h1, newName.Data(), kName);
102 } else if (fMode == 2) {
103 // The names of the 5 basics styles can not be modified.
105 if ((!strcmp(fName->GetText(), "Default"))
106 || (!strcmp(fName->GetText(), "Plain" ))
107 || (!strcmp(fName->GetText(), "Bold" ))
108 || (!strcmp(fName->GetText(), "Video" ))
109 || (!strcmp(fName->GetText(), "Pub" ))) fName->SetEnabled(kFALSE);
110 } else
111 fName = new TGTextEntry(h1, "Imported_Style", kName);
112 fName->Associate(this);
113 fName->Resize(200, 22);
114 h1->AddFrame(fName);
116
117 TGHorizontalFrame *h2 = new TGHorizontalFrame(this);
118 fTrashListFrame->Add(h2);
119 fTitleLabel = new TGLabel(h2, "Description:");
120 h2->AddFrame(fTitleLabel, layoutTitleLabel);
121 switch (fMode) {
122 case 1:
123 case 2:
125 break;
126 case 3: {
127 TString newTitle("Imported from canvas ");
128 if (fCurPad->GetCanvas())
129 newTitle += fCurPad->GetCanvas()->GetName();
130 fTitle = new TGTextEntry(h2, newTitle.Data(), kTitle);
131 }
132 }
133 fTitle->Associate(this);
134 fTitle->Resize(200, 22);
135 h2->AddFrame(fTitle);
136 fTitle->Associate(h2);
137 AddFrame(h2, layoutH2);
138
139 TGHorizontalFrame *h3 = new TGHorizontalFrame(this);
140 fTrashListFrame->Add(h3);
141 fWarnLabel = new TGLabel(h3);
142 Pixel_t red;
143 gClient->GetColorByName("#FF0000", red);
145 fWarnLabel->Resize(200, 22);
146 h3->AddFrame(fWarnLabel, layoutWarningLabel);
147 AddFrame(h3, layoutH2);
148
151 fOK = new TGTextButton(h4, "&OK", kButOK);
152 fOK->Associate(this);
153 h4->AddFrame(fOK, layoutOKButton);
154 fOK->Associate(h4);
155 fCancel = new TGTextButton(h4, "&Cancel", kButCancel);
156 fCancel->Associate(this);
157 h4->AddFrame(fCancel, layoutCancelButton);
160
161 // Refresh the warning message.
162 DoUpdate();
163
164 Resize();
169 SetWMSizeHints(w, h, w, h, 0, 0);
170 MapWindow();
171
172 switch (fMode) {
173 case 1:
174 fOK->SetToolTipText("Create this new style");
175 fCancel->SetToolTipText("Cancel the creation ");
176 break;
177 case 2:
178 fOK->SetToolTipText("Rename the selected style");
179 fCancel->SetToolTipText("Cancel the rename ");
180 break;
181 case 3:
182 fOK->SetToolTipText("Import this new style from the canvas");
183 fCancel->SetToolTipText("Cancel the import");
184 break;
185 }
186
187 Connect("CloseWindow()", "TStyleDialog", this, "DoCloseWindow()");
188 fName->Connect("TextChanged(const char *)", "TStyleDialog", this, "DoUpdate()");
189 fOK->Connect("Clicked()", "TStyleDialog", this, "DoOK()");
190 fCancel->Connect("Clicked()", "TStyleDialog", this, "DoCancel()");
191
192 gClient->WaitFor(this);
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Destructor.
197
199{
200 Disconnect("DoCloseWindow()");
201 fName->Disconnect("TextChanged(const char *)");
202 fOK->Disconnect("Clicked()");
203 fCancel->Disconnect("Clicked()");
204
205 delete fName;
206 delete fNameLabel;
207 delete fTitle;
208 delete fTitleLabel;
209 delete fWarnLabel;
210 delete fOK;
211 delete fCancel;
212
213 TObject *obj1;
214 TObject *obj2;
215
217 while (obj1) {
220 delete obj1;
221 obj1 = obj2;
222 }
223 delete fTrashListFrame;
224
226 while (obj1) {
229 delete obj1;
230 obj1 = obj2;
231 }
232 delete fTrashListLayout;
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// Slot called when the Cancel button is clicked. Close the window
237/// without saving submitted changes.
238
245
246////////////////////////////////////////////////////////////////////////////////
247/// Slot called when the window is closed via the window manager.
248/// Close the window without saving submitted changes.
249
251{
252 delete this;
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// Slot called when the OK button is clicked. Rename or create the style
257/// before closing the window.
258
260{
261 if (fMode == 2) {
262 // Update the name and the title of the style.
265 } else {
266 // Create a new style (copy of fCurStyle), with the given name and title.
268 tmpStyle->SetName(fName->GetText());
269 tmpStyle->SetTitle(fTitle->GetText());
270 {
272 gROOT->GetListOfStyles()->Add(tmpStyle);
273 }
274 if (fMode == 3) {
275 // Import the properties of the canvas.
276 TStyle *tmp = gStyle;
279 if (fCurPad->GetCanvas())
280 fCurPad->GetCanvas()->UseCurrentStyle();
282 gStyle = tmp;
283 }
284 }
285
287
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Slot called every time the name is changed. Provide some protection
293/// to avoid letting the user use an empty name or an already used one.
294/// A warning message can be shown and the OK button disabled.
295
297{
298 if (!strlen(fName->GetText())) {
299 fWarnLabel->SetText("That name is empty");
301 return;
302 }
303
304 if (strstr(fName->GetText(), " ") != 0) {
305 fWarnLabel->SetText("That name contains some spaces");
307 return;
308 }
309
310 switch (fMode) {
311 case 1:
312 case 3:
313 if (gROOT->GetStyle(fName->GetText())) {
314 fWarnLabel->SetText("That name is already used by another style.");
316 return;
317 }
318 break;
319 case 2:
320 TStyle *tmp = gROOT->GetStyle(fName->GetText());
321 if (tmp && (tmp != fCurStyle)) {
322 fWarnLabel->SetText("That name is already used by another style.");
324 return;
325 }
326 }
327
328 fWarnLabel->SetText("");
330}
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define h(i)
Definition RSha256.hxx:106
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.
#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:411
EStyleDialogWid
@ kName
@ kButOK
@ kButCancel
@ kTitle
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define R__LOCKGUARD(mutex)
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:439
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition TGButton.cxx:453
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:314
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:316
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1064
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
void MapWindow() override
map window
Definition TGFrame.h:206
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 SetTextColor(Pixel_t color, Bool_t global=kFALSE)
Changes text color.
Definition TGLabel.cxx:361
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 SendCloseMessage()
Send close message to self.
Definition TGFrame.cxx:1736
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1780
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:500
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition TGFrame.cxx:1949
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:327
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:819
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:656
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
Mother of all ROOT objects.
Definition TObject.h:41
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.
Basic string class.
Definition TString.h:138
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:1375
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