00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "TGTextEditDialogs.h"
00035 #include "TGButton.h"
00036 #include "TGLabel.h"
00037 #include "TGTextEntry.h"
00038 #include "TGIcon.h"
00039 #include "TGMsgBox.h"
00040 #include "TGComboBox.h"
00041
00042 #include <stdlib.h>
00043
00044
00045 ClassImp(TGSearchDialog)
00046 ClassImp(TGPrintDialog)
00047 ClassImp(TGGotoDialog)
00048
00049 static TString gLastSearchString;
00050 TGSearchDialog *TGSearchDialog::fgSearchDialog = 0;
00051
00052
00053 TGSearchDialog::TGSearchDialog(const TGWindow *p, const TGWindow *main,
00054 UInt_t w, UInt_t h, TGSearchType *sstruct,
00055 Int_t *ret_code, UInt_t options) :
00056 TGTransientFrame(p, main, w, h, options)
00057 {
00058
00059
00060
00061
00062 if (!p && !main) {
00063 MakeZombie();
00064 return;
00065 }
00066 fRetCode = ret_code;
00067 fType = sstruct;
00068
00069 ChangeOptions((GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
00070
00071 fF1 = new TGCompositeFrame(this, 60, 20, kVerticalFrame | kFixedWidth);
00072 fF2 = new TGCompositeFrame(this, 60, 20, kVerticalFrame);
00073 fF3 = new TGCompositeFrame(fF2, 60, 20, kHorizontalFrame);
00074 fF4 = new TGCompositeFrame(fF2, 60, 20, kHorizontalFrame);
00075
00076 fSearchButton = new TGTextButton(fF1, new TGHotString("&Search"), 1);
00077 fCancelButton = new TGTextButton(fF1, new TGHotString("&Cancel"), 2);
00078 fF1->Resize(fSearchButton->GetDefaultWidth()+40, GetDefaultHeight());
00079
00080 fSearchButton->Associate(this);
00081 fCancelButton->Associate(this);
00082
00083 fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0);
00084 fL2 = new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandX,
00085 2, 5, 0, 2);
00086 fL21 = new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 5, 10, 0);
00087
00088 fF1->AddFrame(fSearchButton, fL1);
00089 fF1->AddFrame(fCancelButton, fL1);
00090
00091 AddFrame(fF1, fL21);
00092
00093 fLSearch = new TGLabel(fF3, new TGHotString("Search &for:"));
00094
00095 fBSearch = new TGTextBuffer(100);
00096 if (!gLastSearchString.IsNull())
00097 fBSearch->AddText(0, gLastSearchString.Data());
00098 else
00099 fSearchButton->SetState(kButtonDisabled);
00100
00101 fCombo = new TGComboBox(fF3, "");
00102 fSearch = fCombo->GetTextEntry();
00103 fBSearch = fSearch->GetBuffer();
00104 fSearch->Associate(this);
00105 fCombo->Resize(220, fSearch->GetDefaultHeight());
00106 fSearch->SelectAll();
00107
00108 fL5 = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 5, 0, 0);
00109 fL6 = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 2, 0, 0);
00110
00111 fF3->AddFrame(fLSearch, fL5);
00112 fF3->AddFrame(fCombo, fL6);
00113
00114 fG2 = new TGGroupFrame(fF4, new TGString("Direction"), kHorizontalFrame);
00115
00116 fL3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 2, 2, 2);
00117 fL9 = new TGLayoutHints(kLHintsBottom | kLHintsLeft, 0, 0, 0, 0);
00118 fL4 = new TGLayoutHints(kLHintsBottom | kLHintsLeft, 0, 0, 5, 0);
00119 fL10 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 0, 0, 5, 0);
00120
00121 fCaseCheck = new TGCheckButton(fF4, new TGHotString("&Case sensitive"), 1);
00122 fCaseCheck->Associate(this);
00123 fF4->AddFrame(fCaseCheck, fL9);
00124
00125 fDirectionRadio[0] = new TGRadioButton(fG2, new TGHotString("Forward"), 1);
00126 fDirectionRadio[1] = new TGRadioButton(fG2, new TGHotString("Backward"), 2);
00127
00128 fG2->AddFrame(fDirectionRadio[0], fL4);
00129 fG2->AddFrame(fDirectionRadio[1], fL10);
00130 fDirectionRadio[0]->Associate(this);
00131 fDirectionRadio[1]->Associate(this);
00132
00133 if (fType->fCaseSensitive == kFALSE)
00134 fCaseCheck->SetState(kButtonUp);
00135 else
00136 fCaseCheck->SetState(kButtonDown);
00137
00138 if (fType->fDirection)
00139 fDirectionRadio[0]->SetState(kButtonDown);
00140 else
00141 fDirectionRadio[1]->SetState(kButtonDown);
00142
00143 fF4->AddFrame(fG2, fL3);
00144
00145 fF2->AddFrame(fF3, fL1);
00146 fF2->AddFrame(fF4, fL1);
00147
00148 AddFrame(fF2, fL2);
00149
00150 MapSubwindows();
00151 Resize(GetDefaultSize());
00152 SetEditDisabled(kEditDisable);
00153
00154 CenterOnParent();
00155
00156 SetWindowName("Search");
00157 SetIconName("Search");
00158
00159 SetMWMHints(kMWMDecorAll | kMWMDecorMaximize | kMWMDecorMenu,
00160 kMWMFuncAll | kMWMFuncMaximize | kMWMFuncResize,
00161 kMWMInputModeless);
00162
00163 if (fType->fClose) {
00164 MapWindow();
00165 fSearch->RequestFocus();
00166 fClient->WaitFor(this);
00167 }
00168 }
00169
00170
00171 TGSearchDialog::~TGSearchDialog()
00172 {
00173
00174
00175 if (IsZombie()) return;
00176 delete fSearchButton;
00177 delete fCancelButton;
00178 delete fDirectionRadio[0]; delete fDirectionRadio[1];
00179 delete fCaseCheck;
00180 delete fCombo;
00181 delete fLSearch;
00182 delete fG2;
00183 delete fF1; delete fF2; delete fF3; delete fF4;
00184 delete fL1; delete fL2; delete fL3; delete fL4; delete fL5; delete fL6;
00185 delete fL21;delete fL9; delete fL10;
00186 }
00187
00188
00189 void TGSearchDialog::CloseWindow()
00190 {
00191
00192
00193
00194 if (fType->fClose) {
00195 DeleteWindow();
00196 } else {
00197 UnmapWindow();
00198 }
00199 }
00200
00201
00202 void TGSearchDialog::TextEntered(const char *text)
00203 {
00204
00205
00206 Emit("TextEntered(const char *)", text);
00207 }
00208
00209
00210 Bool_t TGSearchDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
00211 {
00212
00213
00214 const char *string;
00215
00216 switch (GET_MSG(msg)) {
00217 case kC_COMMAND:
00218 switch (GET_SUBMSG(msg)) {
00219 case kCM_BUTTON:
00220 switch (parm1) {
00221 case 1:
00222 string = fBSearch->GetString();
00223 if (fType->fBuffer)
00224 delete [] fType->fBuffer;
00225 fType->fBuffer = StrDup(string);
00226 gLastSearchString = string;
00227 *fRetCode = kTRUE;
00228 TextEntered(string);
00229 fCombo->ReturnPressed();
00230 if (fType->fClose) CloseWindow();
00231 break;
00232 case 2:
00233 *fRetCode = kFALSE;
00234 CloseWindow();
00235 break;
00236 }
00237 break;
00238
00239 case kCM_CHECKBUTTON:
00240 fType->fCaseSensitive = !fType->fCaseSensitive;
00241 break;
00242
00243 case kCM_RADIOBUTTON:
00244 switch (parm1) {
00245 case 1:
00246 fType->fDirection = kTRUE;
00247 fDirectionRadio[1]->SetState(kButtonUp);
00248 break;
00249 case 2:
00250 fType->fDirection = kFALSE;
00251 fDirectionRadio[0]->SetState(kButtonUp);
00252 break;
00253 }
00254 break;
00255
00256 default:
00257 break;
00258 }
00259 break;
00260
00261 case kC_TEXTENTRY:
00262 switch (GET_SUBMSG(msg)) {
00263 case kTE_TEXTCHANGED:
00264 string = fBSearch->GetString();
00265 if (strlen(string) == 0) {
00266 fSearchButton->SetState(kButtonDisabled);
00267 } else {
00268 fSearchButton->SetState(kButtonUp);
00269 }
00270 break;
00271 case kTE_ENTER:
00272 string = fBSearch->GetString();
00273 if (fType->fBuffer)
00274 delete [] fType->fBuffer;
00275 fType->fBuffer = StrDup(string);
00276 gLastSearchString = string;
00277 *fRetCode = kTRUE;
00278 TextEntered(string);
00279 if (fType->fClose) CloseWindow();
00280 break;
00281 default:
00282 break;
00283 }
00284 break;
00285
00286 default:
00287 break;
00288 }
00289
00290 return kTRUE;
00291 }
00292
00293
00294 TGSearchDialog *&TGSearchDialog::SearchDialog()
00295 {
00296
00297
00298 return fgSearchDialog;
00299 }
00300
00301
00302
00303 TGPrintDialog::TGPrintDialog(const TGWindow *p, const TGWindow *main,
00304 UInt_t w, UInt_t h, char **printerName,
00305 char **printProg, Int_t *ret_code,
00306 UInt_t options) :
00307 TGTransientFrame(p, main, w, h, options)
00308 {
00309
00310
00311
00312
00313 if (!p && !main) {
00314 MakeZombie();
00315 return;
00316 }
00317 fPrinter = printerName;
00318 fPrintCommand = printProg;
00319 fRetCode = ret_code;
00320 fEditDisabled = kEditDisable;
00321
00322 ChangeOptions((GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
00323
00324 fF1 = new TGCompositeFrame(this, 60, 20, kVerticalFrame | kFixedWidth);
00325 fF5 = new TGCompositeFrame(this, 60, 20, kHorizontalFrame);
00326 fF2 = new TGCompositeFrame(fF5, 60, 20, kVerticalFrame);
00327 fF3 = new TGCompositeFrame(fF2, 60, 20, kHorizontalFrame);
00328 fF4 = new TGCompositeFrame(fF2, 60, 20, kHorizontalFrame);
00329
00330 fPrintButton = new TGTextButton(fF1, new TGHotString("&Print"), 1);
00331 fCancelButton = new TGTextButton(fF1, new TGHotString("&Cancel"), 2);
00332 fF1->Resize(fPrintButton->GetDefaultWidth()+40, GetDefaultHeight());
00333
00334 fPrintButton->Associate(this);
00335 fCancelButton->Associate(this);
00336
00337 fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2);
00338 fL2 = new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandX,
00339 2, 5, 0, 2);
00340 fL3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 2, 4, 4);
00341 fL5 = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 5, 0, 0);
00342 fL6 = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 2, 0, 0);
00343 fL7 = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
00344
00345 fL21 = new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 5, 10, 0);
00346
00347 fF1->AddFrame(fPrintButton, fL1);
00348 fF1->AddFrame(fCancelButton, fL1);
00349 AddFrame(fF1, fL3);
00350
00351
00352 fLPrintCommand = new TGLabel(fF3, new TGHotString("Print command:"));
00353 fBPrintCommand = new TGTextBuffer(50);
00354 fBPrintCommand->AddText(0, *printProg);
00355 fPrintCommandEntry = new TGTextEntry(fF3, fBPrintCommand);
00356 fPrintCommandEntry->Associate(this);
00357 fPrintCommandEntry->Resize(100, fPrintCommandEntry->GetDefaultHeight());
00358
00359 fF3->AddFrame(fLPrintCommand, fL5);
00360 fF3->AddFrame(fPrintCommandEntry, fL6);
00361
00362 fLPrinter = new TGLabel(fF4, new TGHotString("Printer:"));
00363 fBPrinter = new TGTextBuffer(20);
00364 fBPrinter->AddText(0, *printerName);
00365 fPrinterEntry = new TGTextEntry(fF4, fBPrinter);
00366 fPrinterEntry->Associate(this);
00367 fPrinterEntry->Resize(100, fPrinterEntry->GetDefaultHeight());
00368 fF4->AddFrame(fLPrinter, fL5);
00369 fF4->AddFrame(fPrinterEntry, fL6);
00370
00371 fF2->AddFrame(fF3, fL1);
00372 fF2->AddFrame(fF4, fL1);
00373
00374 const TGPicture *printerPicture = fClient->GetPicture("printer_s.xpm");
00375 if (!printerPicture) {
00376 Error("TGPrintDialog", "printer_s.xpm not found");
00377 fPrinterIcon = 0;
00378 } else {
00379 fPrinterIcon = new TGIcon(fF5, printerPicture, 32, 32);
00380 fF5->AddFrame(fPrinterIcon, fL7);
00381 }
00382 fF5->AddFrame(fF2, fL1);
00383 AddFrame(fF5, fL1);
00384
00385 MapSubwindows();
00386 Resize(GetDefaultSize());
00387
00388 CenterOnParent();
00389
00390 SetWindowName("Print");
00391 SetIconName("Print");
00392
00393 SetMWMHints(kMWMDecorAll | kMWMDecorMaximize | kMWMDecorMenu,
00394 kMWMFuncAll | kMWMFuncMaximize | kMWMFuncResize,
00395 kMWMInputModeless);
00396
00397 fPrinterEntry->RequestFocus();
00398 MapWindow();
00399 fClient->WaitFor(this);
00400 }
00401
00402
00403 TGPrintDialog::~TGPrintDialog()
00404 {
00405
00406
00407 if (IsZombie()) return;
00408 delete fPrinterIcon;
00409 delete fPrintButton;
00410 delete fCancelButton;
00411 delete fPrinterEntry;
00412 delete fPrintCommandEntry;
00413 delete fLPrinter; delete fLPrintCommand;
00414 delete fF1; delete fF2; delete fF3; delete fF4; delete fF5;
00415 delete fL1; delete fL2; delete fL3; delete fL5; delete fL6; delete fL7;
00416 delete fL21;
00417 }
00418
00419
00420 void TGPrintDialog::CloseWindow()
00421 {
00422
00423
00424
00425 DeleteWindow();
00426 }
00427
00428
00429 Bool_t TGPrintDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
00430 {
00431
00432
00433 const char *string, *txt;
00434
00435 switch (GET_MSG(msg)) {
00436 case kC_COMMAND:
00437 switch (GET_SUBMSG(msg)) {
00438 case kCM_BUTTON:
00439 switch (parm1) {
00440 case 1:
00441 *fRetCode = kTRUE;
00442 string = fBPrinter->GetString();
00443 delete [] *fPrinter;
00444 *fPrinter = new char[strlen(string)+1];
00445 strlcpy(*fPrinter, string, strlen(string)+1);
00446
00447 string = fBPrintCommand->GetString();
00448 delete [] *fPrintCommand;
00449 *fPrintCommand = new char[strlen(string)+1];
00450 strlcpy(*fPrintCommand, string, strlen(string)+1);
00451
00452 if (fBPrintCommand->GetTextLength() == 0) {
00453 txt = "Please provide print command or use \"Cancel\"";
00454 new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
00455 "Missing Print Parameters", txt, kMBIconExclamation,
00456 kMBOk);
00457 return kTRUE;
00458 }
00459 CloseWindow();
00460 break;
00461 case 2:
00462 *fRetCode = kFALSE;
00463 CloseWindow();
00464 break;
00465 }
00466 break;
00467 }
00468 break;
00469
00470 default:
00471 break;
00472 }
00473
00474 return kTRUE;
00475 }
00476
00477
00478 TGGotoDialog::TGGotoDialog(const TGWindow *p, const TGWindow *main,
00479 UInt_t w, UInt_t h, Long_t *ret_code,
00480 UInt_t options) :
00481 TGTransientFrame(p, main, w, h, options)
00482 {
00483
00484
00485
00486
00487
00488 if (!p && !main) {
00489 MakeZombie();
00490 return;
00491 }
00492 fRetCode = ret_code;
00493 fEditDisabled = kEditDisable;
00494
00495 ChangeOptions((GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
00496
00497 fF1 = new TGCompositeFrame(this, 60, 20, kVerticalFrame | kFixedWidth);
00498 fF2 = new TGCompositeFrame(this, 60, 20, kHorizontalFrame);
00499
00500 fGotoButton = new TGTextButton(fF1, new TGHotString("&Goto"), 1);
00501 fCancelButton = new TGTextButton(fF1, new TGHotString("&Cancel"), 2);
00502 fF1->Resize(fGotoButton->GetDefaultWidth()+40, GetDefaultHeight());
00503
00504 fGotoButton->Associate(this);
00505 fCancelButton->Associate(this);
00506
00507 fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0);
00508 fL21 = new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 5, 10, 0);
00509
00510 fF1->AddFrame(fGotoButton, fL1);
00511 fF1->AddFrame(fCancelButton, fL1);
00512 AddFrame(fF1, fL21);
00513
00514 fLGoTo = new TGLabel(fF2, new TGHotString("&Goto Line:"));
00515
00516 fBGoTo = new TGTextBuffer(50);
00517 if (*fRetCode > 0) {
00518 char curline[32];
00519 snprintf(curline, 32, "%ld", *fRetCode);
00520 fBGoTo->AddText(0, curline);
00521 } else
00522 fGotoButton->SetState(kButtonDisabled);
00523 fGoTo = new TGTextEntry(fF2, fBGoTo);
00524 fGoTo->Associate(this);
00525 fGoTo->Resize(220, fGoTo->GetDefaultHeight());
00526 fGoTo->SelectAll();
00527
00528 fL5 = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 5, 0, 0);
00529 fL6 = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 2, 0, 0);
00530
00531 fF2->AddFrame(fLGoTo, fL5);
00532 fF2->AddFrame(fGoTo, fL5);
00533 AddFrame(fF2, fL1);
00534
00535 MapSubwindows();
00536 Resize(GetDefaultSize());
00537
00538 CenterOnParent();
00539
00540 SetWindowName("Goto");
00541 SetIconName("Print");
00542
00543 SetMWMHints(kMWMDecorAll | kMWMDecorMaximize | kMWMDecorMenu,
00544 kMWMFuncAll | kMWMFuncMaximize | kMWMFuncResize,
00545 kMWMInputModeless);
00546
00547 MapWindow();
00548 fGoTo->RequestFocus();
00549 fClient->WaitFor(this);
00550 }
00551
00552
00553 TGGotoDialog::~TGGotoDialog()
00554 {
00555
00556
00557 if (IsZombie()) return;
00558 delete fGotoButton;
00559 delete fCancelButton;
00560 delete fGoTo;
00561 delete fLGoTo;
00562 delete fF1; delete fF2;
00563 delete fL1; delete fL5; delete fL6; delete fL21;
00564 }
00565
00566
00567 void TGGotoDialog::CloseWindow()
00568 {
00569
00570
00571
00572 DeleteWindow();
00573 }
00574
00575
00576 Bool_t TGGotoDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
00577 {
00578
00579
00580 const char *string;
00581
00582 switch (GET_MSG(msg)) {
00583 case kC_COMMAND:
00584 switch (GET_SUBMSG(msg)) {
00585 case kCM_BUTTON:
00586 switch (parm1) {
00587 case 1:
00588 string = fBGoTo->GetString();
00589 *fRetCode = (Long_t) atof(string);
00590 CloseWindow();
00591 break;
00592 case 2:
00593 *fRetCode = -1;
00594 CloseWindow();
00595 break;
00596 }
00597 break;
00598
00599 default:
00600 break;
00601 }
00602 break;
00603
00604 case kC_TEXTENTRY:
00605 switch (GET_SUBMSG(msg)) {
00606 case kTE_TEXTCHANGED:
00607 string = fBGoTo->GetString();
00608 if (strlen(string) == 0)
00609 fGotoButton->SetState(kButtonDisabled);
00610 else
00611 fGotoButton->SetState(kButtonUp);
00612 break;
00613 case kTE_ENTER:
00614 string = fBGoTo->GetString();
00615 *fRetCode = (Long_t) atof(string);
00616 CloseWindow();
00617 break;
00618 default:
00619 break;
00620 }
00621 break;
00622
00623 default:
00624 break;
00625 }
00626
00627 return kTRUE;
00628 }
00629