45 TGMsgBox::TGMsgBox(
const TGWindow *p,
const TGWindow *main,
46 const char *title,
const char *msg,
const TGPicture *icon,
47 Int_t buttons, Int_t *ret_code, UInt_t options,
49 TGTransientFrame(p, main, 10, 10, options)
52 PMsgBox(title, msg, icon, buttons, ret_code, text_align);
72 TGMsgBox::TGMsgBox(
const TGWindow *p,
const TGWindow *main,
73 const char *title,
const char *msg, EMsgBoxIcon icon,
74 Int_t buttons, Int_t *ret_code, UInt_t options,
76 TGTransientFrame(p, main, 10, 10, options)
78 const TGPicture *icon_pic;
82 icon_pic = fClient->GetPicture(
"mb_stop_s.xpm");
83 if (!icon_pic) Error(
"TGMsgBox",
"mb_stop_s.xpm not found");
87 icon_pic = fClient->GetPicture(
"mb_question_s.xpm");
88 if (!icon_pic) Error(
"TGMsgBox",
"mb_question_s.xpm not found");
91 case kMBIconExclamation:
92 icon_pic = fClient->GetPicture(
"mb_exclamation_s.xpm");
93 if (!icon_pic) Error(
"TGMsgBox",
"mb_exclamation_s.xpm not found");
97 icon_pic = fClient->GetPicture(
"mb_asterisk_s.xpm");
98 if (!icon_pic) Error(
"TGMsgBox",
"mb_asterisk_s.xpm not found");
107 PMsgBox(title, msg, icon_pic, buttons, ret_code, text_align);
115 void TGMsgBox::PMsgBox(
const char *title,
const char *msg,
116 const TGPicture *icon, Int_t buttons, Int_t *ret_code,
119 UInt_t nb, width, height;
121 fYes = fNo = fOK = fApply = fRetry = fIgnore = fCancel = fClose =
122 fYesAll = fNoAll = fNewer = fAppend = fDismiss = 0;
124 fMsgList =
new TList;
130 fButtonFrame =
new TGHorizontalFrame(
this, 60, 20, kFixedWidth);
131 fL1 =
new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 3, 3, 0, 0);
133 buttons &= (kMBYes | kMBNo | kMBOk | kMBApply |
134 kMBRetry | kMBIgnore | kMBCancel | kMBClose | kMBDismiss |
135 kMBYesAll | kMBNoAll | kMBAppend | kMBNewer);
136 if (buttons == 0) buttons = kMBDismiss;
138 if (buttons & kMBYes) {
139 fYes =
new TGTextButton(fButtonFrame,
new TGHotString(
"&Yes"), kMBYes);
140 fYes->Associate(
this);
141 fButtonFrame->AddFrame(fYes, fL1);
142 width = TMath::Max(width, fYes->GetDefaultWidth()); ++nb;
145 if (buttons & kMBNo) {
146 fNo =
new TGTextButton(fButtonFrame,
new TGHotString(
"&No"), kMBNo);
147 fNo->Associate(
this);
148 fButtonFrame->AddFrame(fNo, fL1);
149 width = TMath::Max(width, fNo->GetDefaultWidth()); ++nb;
152 if (buttons & kMBOk) {
153 fOK =
new TGTextButton(fButtonFrame,
new TGHotString(
"&OK"), kMBOk);
154 fOK->Associate(
this);
155 fButtonFrame->AddFrame(fOK, fL1);
156 width = TMath::Max(width, fOK->GetDefaultWidth()); ++nb;
159 if (buttons & kMBApply) {
160 fApply =
new TGTextButton(fButtonFrame,
new TGHotString(
"&Apply"), kMBApply);
161 fApply->Associate(
this);
162 fButtonFrame->AddFrame(fApply, fL1);
163 width = TMath::Max(width, fApply->GetDefaultWidth()); ++nb;
166 if (buttons & kMBRetry) {
167 fRetry =
new TGTextButton(fButtonFrame,
new TGHotString(
"&Retry"), kMBRetry);
168 fRetry->Associate(
this);
169 fButtonFrame->AddFrame(fRetry, fL1);
170 width = TMath::Max(width, fRetry->GetDefaultWidth()); ++nb;
173 if (buttons & kMBIgnore) {
174 fIgnore =
new TGTextButton(fButtonFrame,
new TGHotString(
"&Ignore"), kMBIgnore);
175 fIgnore->Associate(
this);
176 fButtonFrame->AddFrame(fIgnore, fL1);
177 width = TMath::Max(width, fIgnore->GetDefaultWidth()); ++nb;
180 if (buttons & kMBCancel) {
181 fCancel =
new TGTextButton(fButtonFrame,
new TGHotString(
"&Cancel"), kMBCancel);
182 fCancel->Associate(
this);
183 fButtonFrame->AddFrame(fCancel, fL1);
184 width = TMath::Max(width, fCancel->GetDefaultWidth()); ++nb;
187 if (buttons & kMBClose) {
188 fClose =
new TGTextButton(fButtonFrame,
new TGHotString(
"C&lose"), kMBClose);
189 fClose->Associate(
this);
190 fButtonFrame->AddFrame(fClose, fL1);
191 width = TMath::Max(width, fClose->GetDefaultWidth()); ++nb;
194 if (buttons & kMBYesAll) {
195 fYesAll =
new TGTextButton(fButtonFrame,
new TGHotString(
"Y&es to All"), kMBYesAll);
196 fYesAll->Associate(
this);
197 fButtonFrame->AddFrame(fYesAll, fL1);
198 width = TMath::Max(width, fYesAll->GetDefaultWidth()); ++nb;
201 if (buttons & kMBNoAll) {
202 fNoAll =
new TGTextButton(fButtonFrame,
new TGHotString(
"No &to All"), kMBNoAll);
203 fNoAll->Associate(
this);
204 fButtonFrame->AddFrame(fNoAll, fL1);
205 width = TMath::Max(width, fNoAll->GetDefaultWidth()); ++nb;
208 if (buttons & kMBNewer) {
209 fNewer =
new TGTextButton(fButtonFrame,
new TGHotString(
"Ne&wer Only"), kMBNewer);
210 fNewer->Associate(
this);
211 fButtonFrame->AddFrame(fNewer, fL1);
212 width = TMath::Max(width, fNewer->GetDefaultWidth()); ++nb;
215 if (buttons & kMBAppend) {
216 fAppend =
new TGTextButton(fButtonFrame,
new TGHotString(
"A&ppend"), kMBAppend);
217 fAppend->Associate(
this);
218 fButtonFrame->AddFrame(fAppend, fL1);
219 width = TMath::Max(width, fAppend->GetDefaultWidth()); ++nb;
222 if (buttons & kMBDismiss) {
223 fDismiss =
new TGTextButton(fButtonFrame,
new TGHotString(
"&Dismiss"), kMBDismiss);
224 fDismiss->Associate(
this);
225 fButtonFrame->AddFrame(fDismiss, fL1);
226 width = TMath::Max(width, fDismiss->GetDefaultWidth()); ++nb;
231 fL2 =
new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
232 AddFrame(fButtonFrame, fL2);
236 fButtonFrame->Resize((width + 20) * nb, GetDefaultHeight());
238 fIconFrame =
new TGHorizontalFrame(
this, 60, 20);
240 fL3 =
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2);
243 fIcon =
new TGIcon(fIconFrame, icon, icon->GetWidth(), icon->GetHeight());
244 fIconFrame->AddFrame(fIcon, fL3);
247 fLabelFrame =
new TGVerticalFrame(fIconFrame, 60, 20);
249 fL4 =
new TGLayoutHints(kLHintsCenterY | kLHintsLeft | kLHintsExpandX,
251 fL5 =
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 10, 10, 7, 2);
257 char *tmpMsg, *nextLine;
259 int len = strlen(msg) + 1;
260 tmpMsg =
new char[len];
264 strlcpy(nextLine, msg, len);
265 while ((nextLine = strchr(line,
'\n'))) {
267 label =
new TGLabel(fLabelFrame, line);
268 label->SetTextJustify(text_align);
269 fMsgList->Add(label);
270 fLabelFrame->AddFrame(label, fL4);
274 label =
new TGLabel(fLabelFrame, line);
275 label->SetTextJustify(text_align);
276 fMsgList->Add(label);
277 fLabelFrame->AddFrame(label, fL4);
280 fIconFrame->AddFrame(fLabelFrame, fL4);
281 AddFrame(fIconFrame, fL5);
285 width = GetDefaultWidth();
286 height = GetDefaultHeight();
288 Resize(width, height);
289 AddInput(kKeyPressMask);
297 SetWMSize(width, height);
298 SetWMSizeHints(width, height, width, height, 0, 0);
302 SetWindowName(title);
304 SetClassHints(
"ROOT",
"MsgBox");
306 SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
307 kMWMDecorMinimize | kMWMDecorMenu,
308 kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize |
313 fClient->WaitFor(
this);
319 TGMsgBox::~TGMsgBox()
321 if (IsZombie())
return;
322 if (fYes)
delete fYes;
325 if (fApply)
delete fApply;
326 if (fRetry)
delete fRetry;
327 if (fIgnore)
delete fIgnore;
328 if (fCancel)
delete fCancel;
329 if (fClose)
delete fClose;
330 if (fDismiss)
delete fDismiss;
331 if (fYesAll)
delete fYesAll;
332 if (fNoAll)
delete fNoAll;
333 if (fNewer)
delete fNewer;
334 if (fAppend)
delete fAppend;
336 if (fIcon)
delete fIcon;
342 delete fL1;
delete fL2;
delete fL3;
delete fL4;
delete fL5;
349 void TGMsgBox::CloseWindow()
351 if (fRetCode) *fRetCode = kMBClose;
358 Bool_t TGMsgBox::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
360 switch (GET_MSG(msg)) {
362 switch (GET_SUBMSG(msg)) {
364 if (fRetCode) *fRetCode = (Int_t) parm1;
381 Bool_t TGMsgBox::HandleKey(Event_t* event)
383 if (event->fType == kGKeyPress) {
386 gVirtualX->LookupString(event, input,
sizeof(input), keysym);
388 if ((EKeySym)keysym == kKey_Escape) {
390 if (fRetCode) *fRetCode = (Int_t) kMBCancel;
395 else if ((EKeySym)keysym == kKey_Enter || (EKeySym)keysym == kKey_Return) {
397 if (fRetCode) *fRetCode = (Int_t) kMBOk;
403 return TGMainFrame::HandleKey(event);