47 ClassImp(TGSearchDialog);
48 ClassImp(TGPrintDialog);
49 ClassImp(TGGotoDialog);
51 static TString gLastSearchString;
52 TGSearchDialog *TGSearchDialog::fgSearchDialog = 0;
59 TGSearchDialog::TGSearchDialog(
const TGWindow *p,
const TGWindow *main,
60 UInt_t w, UInt_t h, TGSearchType *sstruct,
61 Int_t *ret_code, UInt_t options) :
62 TGTransientFrame(p, main, w, h, options)
72 ChangeOptions((GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
74 fF1 =
new TGCompositeFrame(
this, 60, 20, kVerticalFrame | kFixedWidth);
75 fF2 =
new TGCompositeFrame(
this, 60, 20, kVerticalFrame);
76 fF3 =
new TGCompositeFrame(fF2, 60, 20, kHorizontalFrame);
77 fF4 =
new TGCompositeFrame(fF2, 60, 20, kHorizontalFrame);
79 fSearchButton =
new TGTextButton(fF1,
new TGHotString(
"&Search"), 1);
80 fCancelButton =
new TGTextButton(fF1,
new TGHotString(
"&Cancel"), 2);
81 fF1->Resize(fSearchButton->GetDefaultWidth()+40, GetDefaultHeight());
83 fSearchButton->Associate(
this);
84 fCancelButton->Associate(
this);
86 fL1 =
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0);
87 fL2 =
new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandX,
89 fL21 =
new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 5, 10, 0);
91 fF1->AddFrame(fSearchButton, fL1);
92 fF1->AddFrame(fCancelButton, fL1);
96 fLSearch =
new TGLabel(fF3,
new TGHotString(
"Search &for:"));
98 fCombo =
new TGComboBox(fF3,
"");
99 fSearch = fCombo->GetTextEntry();
100 fBSearch = fSearch->GetBuffer();
101 if (sstruct && sstruct->fBuffer)
102 fBSearch->AddText(0, sstruct->fBuffer);
103 else if (!gLastSearchString.IsNull())
104 fBSearch->AddText(0, gLastSearchString.Data());
106 fSearchButton->SetState(kButtonDisabled);
107 fSearch->Associate(
this);
108 fCombo->Resize(220, fSearch->GetDefaultHeight());
109 fSearch->SelectAll();
111 fL5 =
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 5, 0, 0);
112 fL6 =
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 2, 0, 0);
114 fF3->AddFrame(fLSearch, fL5);
115 fF3->AddFrame(fCombo, fL6);
117 fG2 =
new TGGroupFrame(fF4,
new TGString(
"Direction"), kHorizontalFrame);
119 fL3 =
new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 2, 2, 2);
120 fL9 =
new TGLayoutHints(kLHintsBottom | kLHintsLeft, 0, 0, 0, 0);
121 fL4 =
new TGLayoutHints(kLHintsBottom | kLHintsLeft, 0, 0, 5, 0);
122 fL10 =
new TGLayoutHints(kLHintsBottom | kLHintsRight, 0, 0, 5, 0);
124 fCaseCheck =
new TGCheckButton(fF4,
new TGHotString(
"&Case sensitive"), 1);
125 fCaseCheck->Associate(
this);
126 fF4->AddFrame(fCaseCheck, fL9);
128 fDirectionRadio[0] =
new TGRadioButton(fG2,
new TGHotString(
"Forward"), 1);
129 fDirectionRadio[1] =
new TGRadioButton(fG2,
new TGHotString(
"Backward"), 2);
131 fG2->AddFrame(fDirectionRadio[0], fL4);
132 fG2->AddFrame(fDirectionRadio[1], fL10);
133 fDirectionRadio[0]->Associate(
this);
134 fDirectionRadio[1]->Associate(
this);
136 if (fType->fCaseSensitive == kFALSE)
137 fCaseCheck->SetState(kButtonUp);
139 fCaseCheck->SetState(kButtonDown);
141 if (fType->fDirection)
142 fDirectionRadio[0]->SetState(kButtonDown);
144 fDirectionRadio[1]->SetState(kButtonDown);
146 fF4->AddFrame(fG2, fL3);
148 fF2->AddFrame(fF3, fL1);
149 fF2->AddFrame(fF4, fL1);
154 Resize(GetDefaultSize());
155 SetEditDisabled(kEditDisable);
159 SetWindowName(
"Search");
160 SetIconName(
"Search");
162 SetMWMHints(kMWMDecorAll | kMWMDecorMaximize | kMWMDecorMenu,
163 kMWMFuncAll | kMWMFuncMaximize | kMWMFuncResize,
168 fSearch->RequestFocus();
169 fClient->WaitFor(
this);
176 TGSearchDialog::~TGSearchDialog()
178 if (IsZombie())
return;
179 delete fSearchButton;
180 delete fCancelButton;
181 delete fDirectionRadio[0];
delete fDirectionRadio[1];
186 delete fF1;
delete fF2;
delete fF3;
delete fF4;
187 delete fL1;
delete fL2;
delete fL3;
delete fL4;
delete fL5;
delete fL6;
188 delete fL21;
delete fL9;
delete fL10;
195 void TGSearchDialog::CloseWindow()
207 void TGSearchDialog::TextEntered(
const char *text)
209 Emit(
"TextEntered(const char *)", text);
215 Bool_t TGSearchDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
219 switch (GET_MSG(msg)) {
221 switch (GET_SUBMSG(msg)) {
225 string = fBSearch->GetString();
227 delete [] fType->fBuffer;
228 fType->fBuffer = StrDup(
string);
229 gLastSearchString = string;
232 fCombo->ReturnPressed();
233 if (fType->fClose) CloseWindow();
242 case kCM_CHECKBUTTON:
243 fType->fCaseSensitive = !fType->fCaseSensitive;
246 case kCM_RADIOBUTTON:
249 fType->fDirection = kTRUE;
250 fDirectionRadio[1]->SetState(kButtonUp);
253 fType->fDirection = kFALSE;
254 fDirectionRadio[0]->SetState(kButtonUp);
265 switch (GET_SUBMSG(msg)) {
266 case kTE_TEXTCHANGED:
267 string = fBSearch->GetString();
269 fSearchButton->SetState(kButtonDisabled);
271 fSearchButton->SetState(kButtonUp);
275 string = fBSearch->GetString();
277 delete [] fType->fBuffer;
278 fType->fBuffer = StrDup(
string);
279 gLastSearchString = string;
282 if (fType->fClose) CloseWindow();
299 TGSearchDialog *&TGSearchDialog::SearchDialog()
301 return fgSearchDialog;
310 TGPrintDialog::TGPrintDialog(
const TGWindow *p,
const TGWindow *main,
311 UInt_t w, UInt_t h,
char **printerName,
312 char **printProg, Int_t *ret_code,
314 TGTransientFrame(p, main, w, h, options)
321 fPrinter = printerName;
322 fPrintCommand = printProg;
324 fEditDisabled = kEditDisable;
326 ChangeOptions((GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
328 fF1 =
new TGCompositeFrame(
this, 60, 20, kVerticalFrame | kFixedWidth);
329 fF5 =
new TGCompositeFrame(
this, 60, 20, kHorizontalFrame);
330 fF2 =
new TGCompositeFrame(fF5, 60, 20, kVerticalFrame);
331 fF3 =
new TGCompositeFrame(fF2, 60, 20, kHorizontalFrame);
332 fF4 =
new TGCompositeFrame(fF2, 60, 20, kHorizontalFrame);
334 fPrintButton =
new TGTextButton(fF1,
new TGHotString(
"&Print"), 1);
335 fCancelButton =
new TGTextButton(fF1,
new TGHotString(
"&Cancel"), 2);
336 fF1->Resize(fPrintButton->GetDefaultWidth()+40, GetDefaultHeight());
338 fPrintButton->Associate(
this);
339 fCancelButton->Associate(
this);
341 fL1 =
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2);
342 fL2 =
new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandX,
344 fL3 =
new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 2, 4, 4);
345 fL5 =
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 5, 0, 0);
346 fL6 =
new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 0, 2, 0, 0);
347 fL7 =
new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
349 fL21 =
new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 5, 10, 0);
351 fF1->AddFrame(fPrintButton, fL1);
352 fF1->AddFrame(fCancelButton, fL1);
356 fLPrintCommand =
new TGLabel(fF3,
new TGHotString(
"Print command:"));
357 fBPrintCommand =
new TGTextBuffer(50);
358 if ((printProg) && (*printProg))
359 fBPrintCommand->AddText(0, *printProg);
360 fPrintCommandEntry =
new TGTextEntry(fF3, fBPrintCommand);
361 fPrintCommandEntry->Associate(
this);
362 fPrintCommandEntry->Resize(150, fPrintCommandEntry->GetDefaultHeight());
364 fF3->AddFrame(fLPrintCommand, fL5);
365 fF3->AddFrame(fPrintCommandEntry, fL6);
367 fLPrinter =
new TGLabel(fF4,
new TGHotString(
"Printer:"));
368 if ((printerName) && (*printerName))
369 fPrinterEntry =
new TGComboBox(fF4, *printerName);
370 fBPrinter = fPrinterEntry->GetTextEntry()->GetBuffer();
371 fPrinterEntry->Resize(150, fPrinterEntry->GetTextEntry()->GetDefaultHeight());
372 fF4->AddFrame(fLPrinter, fL5);
373 fF4->AddFrame(fPrinterEntry, fL6);
375 fF2->AddFrame(fF3, fL1);
376 fF2->AddFrame(fF4, fL1);
378 const TGPicture *printerPicture = fClient->GetPicture(
"printer_s.xpm");
379 if (!printerPicture) {
380 Error(
"TGPrintDialog",
"printer_s.xpm not found");
383 fPrinterIcon =
new TGIcon(fF5, printerPicture, 32, 32);
384 fF5->AddFrame(fPrinterIcon, fL7);
386 fF5->AddFrame(fF2, fL1);
390 Resize(GetDefaultSize());
395 SetWindowName(
"Print");
396 SetIconName(
"Print");
398 SetMWMHints(kMWMDecorAll | kMWMDecorMaximize | kMWMDecorMenu,
399 kMWMFuncAll | kMWMFuncMaximize | kMWMFuncResize,
402 fPrinterEntry->RequestFocus();
404 fClient->WaitFor(
this);
410 TGPrintDialog::~TGPrintDialog()
412 if (IsZombie())
return;
415 delete fCancelButton;
416 delete fPrinterEntry;
417 delete fPrintCommandEntry;
418 delete fLPrinter;
delete fLPrintCommand;
419 delete fF1;
delete fF2;
delete fF3;
delete fF4;
delete fF5;
420 delete fL1;
delete fL2;
delete fL3;
delete fL5;
delete fL6;
delete fL7;
428 void TGPrintDialog::CloseWindow()
437 void TGPrintDialog::GetPrinters()
440 Int_t idx = 1, dflt =1;
442 if (gVirtualX->InheritsFrom(
"TGX11") || gVirtualX->InheritsFrom(
"TGCocoa")) {
443 char *lpstat = gSystem->Which(gSystem->Getenv(
"PATH"),
"lpstat",
445 if (lpstat == 0)
return;
446 TString defaultprinter = gSystem->GetFromPipe(
"lpstat -d");
447 TString printerlist = gSystem->GetFromPipe(
"lpstat -v");
448 TObjArray *tokens = printerlist.Tokenize(
"\n");
450 while((obj = iter())) {
451 TString line = obj->GetName();
452 TObjArray *tk = line.Tokenize(
" ");
453 TString pname = ((TObject*)tk->At(2))->GetName();
454 if (pname.EndsWith(
":")) pname.Remove(pname.Last(
':'));
456 if (defaultprinter.Contains(pname)) {
458 fPrinterEntry->GetTextEntry()->SetText(pname.Data(), kFALSE);
460 fPrinterEntry->AddEntry(pname.Data(), idx++);
465 TString defaultprinter = gSystem->GetFromPipe(
"WMIC Path Win32_Printer where Default=TRUE Get DeviceID");
466 TString printerlist = gSystem->GetFromPipe(
"WMIC Path Win32_Printer Get DeviceID");
467 defaultprinter.Remove(0, defaultprinter.First(
'\n'));
468 printerlist.Remove(0, printerlist.First(
'\n'));
469 printerlist.ReplaceAll(
"\r",
"");
470 TObjArray *tokens = printerlist.Tokenize(
"\n");
472 while((obj = iter())) {
473 TString pname = obj->GetName();
474 pname.Remove(TString::kTrailing,
' ');
475 if (defaultprinter.Contains(pname)) {
477 fPrinterEntry->GetTextEntry()->SetText(pname.Data(), kFALSE);
479 fPrinterEntry->AddEntry(pname.Data(), idx++);
482 fPrinterEntry->Select(dflt, kFALSE);
483 fPrinterEntry->Layout();
489 Bool_t TGPrintDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
491 const char *string, *txt;
493 switch (GET_MSG(msg)) {
495 switch (GET_SUBMSG(msg)) {
501 string = fBPrinter->GetString();
503 const size_t prSize = strlen(
string) + 1;
504 *fPrinter =
new char[prSize];
505 strlcpy(*fPrinter,
string, prSize);
508 string = fBPrintCommand->GetString();
509 delete [] *fPrintCommand;
510 const size_t cmdSize = strlen(
string) + 1;
511 *fPrintCommand =
new char[cmdSize];
512 strlcpy(*fPrintCommand,
string, cmdSize);
515 if (fBPrintCommand->GetTextLength() == 0) {
516 txt =
"Please provide print command or use \"Cancel\"";
517 new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
518 "Missing Print Parameters", txt, kMBIconExclamation,
546 TGGotoDialog::TGGotoDialog(
const TGWindow *p,
const TGWindow *main,
547 UInt_t w, UInt_t h, Long_t *ret_code,
549 TGTransientFrame(p, main, w, h, options)
557 fEditDisabled = kEditDisable;
559 ChangeOptions((GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
561 fF1 =
new TGCompositeFrame(
this, 60, 20, kVerticalFrame | kFixedWidth);
562 fF2 =
new TGCompositeFrame(
this, 60, 20, kHorizontalFrame);
564 fGotoButton =
new TGTextButton(fF1,
new TGHotString(
"&Goto"), 1);
565 fCancelButton =
new TGTextButton(fF1,
new TGHotString(
"&Cancel"), 2);
566 fF1->Resize(fGotoButton->GetDefaultWidth()+40, GetDefaultHeight());
568 fGotoButton->Associate(
this);
569 fCancelButton->Associate(
this);
571 fL1 =
new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 2, 2, 3, 0);
572 fL21 =
new TGLayoutHints(kLHintsCenterY | kLHintsRight, 2, 5, 10, 0);
574 fF1->AddFrame(fGotoButton, fL1);
575 fF1->AddFrame(fCancelButton, fL1);
578 fLGoTo =
new TGLabel(fF2,
new TGHotString(
"&Goto Line:"));
580 fBGoTo =
new TGTextBuffer(50);
583 snprintf(curline, 32,
"%ld", *fRetCode);
584 fBGoTo->AddText(0, curline);
586 fGotoButton->SetState(kButtonDisabled);
587 fGoTo =
new TGTextEntry(fF2, fBGoTo);
588 fGoTo->Associate(
this);
589 fGoTo->Resize(220, fGoTo->GetDefaultHeight());
592 fL5 =
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 5, 0, 0);
593 fL6 =
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 2, 0, 0);
595 fF2->AddFrame(fLGoTo, fL5);
596 fF2->AddFrame(fGoTo, fL5);
600 Resize(GetDefaultSize());
604 SetWindowName(
"Goto");
605 SetIconName(
"Print");
607 SetMWMHints(kMWMDecorAll | kMWMDecorMaximize | kMWMDecorMenu,
608 kMWMFuncAll | kMWMFuncMaximize | kMWMFuncResize,
612 fGoTo->RequestFocus();
613 fClient->WaitFor(
this);
619 TGGotoDialog::~TGGotoDialog()
621 if (IsZombie())
return;
623 delete fCancelButton;
626 delete fF1;
delete fF2;
627 delete fL1;
delete fL5;
delete fL6;
delete fL21;
634 void TGGotoDialog::CloseWindow()
642 Bool_t TGGotoDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
646 switch (GET_MSG(msg)) {
648 switch (GET_SUBMSG(msg)) {
652 string = fBGoTo->GetString();
653 *fRetCode = (Long_t) atof(
string);
669 switch (GET_SUBMSG(msg)) {
670 case kTE_TEXTCHANGED:
671 string = fBGoTo->GetString();
673 fGotoButton->SetState(kButtonDisabled);
675 fGotoButton->SetState(kButtonUp);
678 string = fBGoTo->GetString();
679 *fRetCode = (Long_t) atof(
string);