37 ClassImp(TStyleDialog);
39 enum EStyleDialogWid {
52 TStyleDialog::TStyleDialog(TStyleManager *sm, TStyle *cur, Int_t mode,
53 TVirtualPad *currentPad)
54 : TGTransientFrame(0, sm)
59 SetCleanup(kNoCleanup);
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");
71 fTrashListLayout =
new TList();
72 fTrashListFrame =
new TList();
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);
94 TGHorizontalFrame *h1 =
new TGHorizontalFrame(
this);
95 fTrashListFrame->Add(h1);
96 fNameLabel =
new TGLabel(h1,
"Name:");
97 h1->AddFrame(fNameLabel, layoutNameLabel);
101 newName.Form(
"%s_1", fCurStyle->GetName());
102 fName =
new TGTextEntry(h1, newName.Data(), kName);
103 }
else if (fMode == 2) {
105 fName =
new TGTextEntry(h1, fCurStyle->GetName(), kName);
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);
112 fName =
new TGTextEntry(h1,
"Imported_Style", kName);
113 fName->Associate(
this);
114 fName->Resize(200, 22);
116 AddFrame(h1, layoutH1);
118 TGHorizontalFrame *h2 =
new TGHorizontalFrame(
this);
119 fTrashListFrame->Add(h2);
120 fTitleLabel =
new TGLabel(h2,
"Description:");
121 h2->AddFrame(fTitleLabel, layoutTitleLabel);
125 fTitle =
new TGTextEntry(h2, fCurStyle->GetTitle(), kTitle);
128 TString newTitle(
"Imported from canvas ");
129 if (fCurPad->GetCanvas())
130 newTitle += fCurPad->GetCanvas()->GetName();
131 fTitle =
new TGTextEntry(h2, newTitle.Data(), kTitle);
134 fTitle->Associate(
this);
135 fTitle->Resize(200, 22);
136 h2->AddFrame(fTitle);
137 fTitle->Associate(h2);
138 AddFrame(h2, layoutH2);
140 TGHorizontalFrame *h3 =
new TGHorizontalFrame(
this);
141 fTrashListFrame->Add(h3);
142 fWarnLabel =
new TGLabel(h3);
144 gClient->GetColorByName(
"#FF0000", red);
145 fWarnLabel->SetTextColor(red, kFALSE);
146 fWarnLabel->Resize(200, 22);
147 h3->AddFrame(fWarnLabel, layoutWarningLabel);
148 AddFrame(h3, layoutH2);
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);
156 fCancel =
new TGTextButton(h4,
"&Cancel", kButCancel);
157 fCancel->Associate(
this);
158 h4->AddFrame(fCancel, layoutCancelButton);
159 fCancel->Associate(h4);
160 AddFrame(h4, layoutH4);
168 Int_t w = GetDefaultWidth();
169 Int_t h = GetDefaultHeight();
170 SetWMSizeHints(w, h, w, h, 0, 0);
175 fOK->SetToolTipText(
"Create this new style");
176 fCancel->SetToolTipText(
"Cancel the creation ");
179 fOK->SetToolTipText(
"Rename the selected style");
180 fCancel->SetToolTipText(
"Cancel the rename ");
183 fOK->SetToolTipText(
"Import this new style from the canvas");
184 fCancel->SetToolTipText(
"Cancel the import");
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()");
193 gClient->WaitFor(
this);
199 TStyleDialog::~TStyleDialog()
201 Disconnect(
"DoCloseWindow()");
202 fName->Disconnect(
"TextChanged(const char *)");
203 fOK->Disconnect(
"Clicked()");
204 fCancel->Disconnect(
"Clicked()");
217 obj1 = fTrashListFrame->First();
219 obj2 = fTrashListFrame->After(obj1);
220 fTrashListFrame->Remove(obj1);
224 delete fTrashListFrame;
226 obj1 = fTrashListLayout->First();
228 obj2 = fTrashListLayout->After(obj1);
229 fTrashListLayout->Remove(obj1);
233 delete fTrashListLayout;
240 void TStyleDialog::DoCancel()
242 fStyleManager->SetLastChoice(kFALSE);
251 void TStyleDialog::DoCloseWindow()
260 void TStyleDialog::DoOK()
264 fCurStyle->SetName(fName->GetText());
265 fCurStyle->SetTitle(fTitle->GetText());
268 TStyle *tmpStyle =
new TStyle(*fCurStyle);
269 tmpStyle->SetName(fName->GetText());
270 tmpStyle->SetTitle(fTitle->GetText());
272 R__LOCKGUARD(gROOTMutex);
273 gROOT->GetListOfStyles()->Add(tmpStyle);
277 TStyle *tmp = gStyle;
279 gStyle->SetIsReading(kFALSE);
280 if (fCurPad->GetCanvas())
281 fCurPad->GetCanvas()->UseCurrentStyle();
282 gStyle->SetIsReading(kTRUE);
287 fStyleManager->SetLastChoice(kTRUE);
297 void TStyleDialog::DoUpdate()
299 if (!strlen(fName->GetText())) {
300 fWarnLabel->SetText(
"That name is empty");
301 fOK->SetEnabled(kFALSE);
305 if (strstr(fName->GetText(),
" ") != 0) {
306 fWarnLabel->SetText(
"That name contains some spaces");
307 fOK->SetEnabled(kFALSE);
314 if (gROOT->GetStyle(fName->GetText())) {
315 fWarnLabel->SetText(
"That name is already used by another style.");
316 fOK->SetEnabled(kFALSE);
321 TStyle *tmp = gROOT->GetStyle(fName->GetText());
322 if (tmp && (tmp != fCurStyle)) {
323 fWarnLabel->SetText(
"That name is already used by another style.");
324 fOK->SetEnabled(kFALSE);
329 fWarnLabel->SetText(
"");
330 fOK->SetEnabled(kTRUE);