Skip to content

Commit c46a361

Browse files
committed
Fix Jira #ROOT-8404 macro Dialogs.C does not compile and crashes
1 parent 24a1193 commit c46a361

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

macros/Dialogs.C

+10-19
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
// }
3131
//
3232

33+
#include "TList.h"
34+
#include "TGLabel.h"
35+
#include "TGButton.h"
36+
#include "TGText.h"
37+
#include "TGFileDialog.h"
38+
#include "TGTextEntry.h"
39+
3340
///////////////////////////////////////////////////////////////////////////
3441
// //
3542
// Input Dialog Widget //
@@ -41,7 +48,6 @@ class InputDialog {
4148
private:
4249
TGTransientFrame *fDialog; // transient frame, main dialog window
4350
TGTextEntry *fTE; // text entry widget containing
44-
TList *fWidgets; // keep track of widgets to be deleted in dtor
4551
char *fRetStr; // address to store return string
4652

4753
public:
@@ -54,29 +60,23 @@ InputDialog::~InputDialog()
5460
{
5561
// Cleanup dialog.
5662

57-
fWidgets->Delete();
58-
delete fWidgets;
59-
60-
delete fTE;
61-
delete fDialog;
63+
fDialog->DeleteWindow(); // cleanup and delete fDialog
6264
}
6365

6466
InputDialog::InputDialog(const char *prompt, const char *defval, char *retstr)
6567
{
6668
// Create simple input dialog.
6769

68-
fWidgets = new TList;
69-
70-
TGWindow *main = gClient->GetRoot();
70+
const TGWindow *main = gClient->GetRoot();
7171
fDialog = new TGTransientFrame(main, main, 10, 10);
72+
fDialog->SetCleanup(kDeepCleanup);
7273

7374
// command to be executed by buttons and text entry widget
7475
char cmd[128];
7576
sprintf(cmd, "{long r__ptr=0x%lx; ((InputDialog*)r__ptr)->ProcessMessage($MSG,$PARM1,$PARM2);}", (Long_t)this);
7677

7778
// create prompt label and textentry widget
7879
TGLabel *label = new TGLabel(fDialog, prompt);
79-
fWidgets->Add(label);
8080

8181
TGTextBuffer *tbuf = new TGTextBuffer(256); //will be deleted by TGtextEntry
8282
tbuf->AddText(0, defval);
@@ -87,8 +87,6 @@ InputDialog::InputDialog(const char *prompt, const char *defval, char *retstr)
8787

8888
TGLayoutHints *l1 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 0);
8989
TGLayoutHints *l2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
90-
fWidgets->Add(l1);
91-
fWidgets->Add(l2);
9290

9391
fDialog->AddFrame(label, l1);
9492
fDialog->AddFrame(fTE, l2);
@@ -97,31 +95,24 @@ InputDialog::InputDialog(const char *prompt, const char *defval, char *retstr)
9795
TGHorizontalFrame *hf = new TGHorizontalFrame(fDialog, 60, 20, kFixedWidth);
9896
TGLayoutHints *l3 = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0);
9997

100-
// put hf as last in list to be deleted
101-
fWidgets->Add(l3);
102-
10398
// create OK and Cancel buttons in their own frame (hf)
10499
UInt_t nb = 0, width = 0, height = 0;
105100
TGTextButton *b;
106101

107102
b = new TGTextButton(hf, "&Ok", cmd, 1);
108-
fWidgets->Add(b);
109103
b->Associate(fDialog);
110104
hf->AddFrame(b, l3);
111105
height = b->GetDefaultHeight();
112106
width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
113107

114108
b = new TGTextButton(hf, "&Cancel", cmd, 2);
115-
fWidgets->Add(b);
116109
b->Associate(fDialog);
117110
hf->AddFrame(b, l3);
118111
height = b->GetDefaultHeight();
119112
width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
120113

121114
// place button frame (hf) at the bottom
122115
TGLayoutHints *l4 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
123-
fWidgets->Add(l4);
124-
fWidgets->Add(hf);
125116

126117
fDialog->AddFrame(hf, l4);
127118

0 commit comments

Comments
 (0)