TGTextDialog.cxx

Go to the documentation of this file.
00001 /*********************************************************************
00002 
00003   Name:         TGTextDialog.cxx
00004   Created by:   Stephan Ritt
00005   $Id$
00006   
00007 *********************************************************************/
00008 //////////////////////////////////////////////////////////////////////
00009 // This Code is written by Stephan Ritt                             //
00010 // found in rmidas.c, a component of the MIDAS                      //
00011 // (see http://midas.triumf.ca/)                                    //
00012 //////////////////////////////////////////////////////////////////////
00013 
00014 #include "TGTextDialog.h"
00015 
00016 ClassImp(TGTextDialog)
00017 
00018 TGTextDialog::TGTextDialog( TGWindow const *p, const TGWindow *main,
00019                             UInt_t w, UInt_t h, const char *label, const char *preLoad,
00020                             TObjString *ret_str,
00021                             UInt_t options)
00022     : TGTransientFrame(p, main, w, h, options)
00023 {
00024   // Create a dialog to enter a single line text entry
00025   //
00026   fRetObjStr = ret_str;
00027   //
00028   ChangeOptions( (GetOptions()&~kVerticalFrame)|kHorizontalFrame );
00029   //
00030   fF1 = new TGCompositeFrame( this, 60, 20, kVerticalFrame | kFixedWidth );
00031   fF2 = new TGCompositeFrame( this, 60, 20, kHorizontalFrame );
00032   //
00033   fOkButton = new TGTextButton( fF1, new TGHotString("Ok"), 1 );
00034   fCancelButton = new TGTextButton( fF1, new TGHotString("Cancel"), 2 );
00035   fF1->Resize( fOkButton->GetDefaultWidth()+40, GetDefaultHeight() );
00036   //
00037   fOkButton->Associate(this);
00038   fCancelButton->Associate(this);
00039   //
00040   fL1 = new TGLayoutHints( kLHintsTop | kLHintsExpandX, 2, 2, 3, 0 );
00041   fL21 = new TGLayoutHints( kLHintsTop | kLHintsRight, 2, 5, 10, 0 );
00042   //
00043   fF1->AddFrame( fOkButton, fL1 );
00044   fF1->AddFrame( fCancelButton, fL1 );
00045   AddFrame( fF1, fL21 );
00046   //
00047   fLabel = new TGLabel( fF2, new TGHotString(label) );
00048   //
00049   fBLabel = new TGTextBuffer(200);
00050   fOkButton->SetState(kButtonDisabled);
00051   //
00052   fText = new TGTextEntry( fF2, fBLabel );
00053   fText->Associate(this);
00054   fText->Resize( 220, fText->GetDefaultHeight() );
00055   fText->SelectAll();
00056   if( strlen(preLoad) )fText->SetText( preLoad );
00057   //
00058   fL5 = new TGLayoutHints( kLHintsLeft|kLHintsCenterY, 3, 5, 0, 0 );
00059   fL6 = new TGLayoutHints( kLHintsLeft|kLHintsCenterY, 0, 2, 0, 0 );
00060   //
00061   fF2->AddFrame( fLabel, fL5 );
00062   fF2->AddFrame( fText, fL5 );
00063   AddFrame( fF2, fL1 );
00064   //
00065   MapSubwindows();
00066   Resize( GetDefaultSize() );
00067   //
00068   // position relative to the parent's window
00069   Int_t ax, ay;
00070   if( main )
00071   {
00072     Window_t wdum;
00073     gVirtualX->TranslateCoordinates(
00074      main->GetId(), GetParent()->GetId(),
00075      (Int_t)(((TGFrame *)main)->GetWidth()-fWidth)>>1,
00076      (Int_t)(((TGFrame *)main)->GetHeight()-fHeight)>>1,
00077      ax, ay, wdum );
00078   }
00079   else
00080   {
00081     UInt_t root_w, root_h;
00082     gVirtualX->GetWindowSize( fClient->GetRoot()->GetId(), ax, ay,
00083                               root_w, root_h );
00084     ax = (root_w-fWidth) >> 1;
00085     ay = (root_h-fHeight) >> 1;
00086   }
00087   //
00088   Move( ax, ay );
00089   SetWMPosition( ax, ay );
00090   //
00091   SetWindowName("Enter Text");
00092   //
00093   SetMWMHints( kMWMDecorAll|kMWMDecorMaximize|kMWMDecorMenu,
00094                kMWMFuncAll|kMWMFuncMaximize|kMWMFuncResize,
00095                kMWMInputModeless );
00096   //
00097   MapWindow();
00098   fClient->WaitFor(this);
00099 }
00100 
00101 TGTextDialog::~TGTextDialog()
00102 {
00103   // Clean up text dialog
00104   delete fCancelButton;
00105   delete fOkButton;
00106   delete fText;
00107   delete fLabel;
00108   delete fF1; delete fF2;
00109   delete fL1; delete fL5; delete fL6; delete fL21;
00110 }
00111 
00112 void TGTextDialog::CloseWindow()
00113 {
00114   // Close the dialog.
00115   // On close the dialog will be deleted and cannot be re-used.
00116   //
00117   DeleteWindow();
00118 }
00119 
00120 Bool_t TGTextDialog::ProcessMessage( Long_t msg, Long_t parm1, Long_t dummy )
00121 {
00122   switch (GET_MSG(msg))
00123   {
00124     case kC_COMMAND:
00125     {
00126       switch (GET_SUBMSG(msg))
00127       {
00128         case kCM_BUTTON:
00129         {
00130           switch (parm1)
00131           {
00132             case 1:
00133             {
00134               fRetObjStr->SetString(fText->GetText());
00135               CloseWindow();
00136               break;
00137             }
00138             case 2:
00139             {
00140               fRetObjStr->SetString("-1");
00141               CloseWindow();
00142               break;
00143             }
00144           }
00145           break;
00146         }
00147         default:
00148         {
00149           break;
00150         }
00151       }
00152       break;  
00153     }
00154     case kC_TEXTENTRY:
00155     {
00156       switch (GET_SUBMSG(msg))
00157       {
00158         case kTE_TEXTCHANGED:
00159         {
00160           char const *string = fBLabel->GetString();
00161           strlen(string)==0 ? fOkButton->SetState(kButtonDisabled) :
00162                               fOkButton->SetState(kButtonUp);
00163           break;
00164         }
00165         case kTE_ENTER:
00166         {
00167           char const *string = fBLabel->GetString();
00168           if( strlen(string) != 0 )
00169           {
00170             fRetObjStr->SetString(fText->GetText());
00171             CloseWindow();
00172           }
00173           break;
00174         }
00175         default:
00176         {
00177           break;
00178         }
00179       }
00180       break;
00181     }
00182     default:
00183     {
00184       break;
00185     }
00186   }
00187   return kTRUE;
00188 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends

Generated on 15 Nov 2016 for Roody by  doxygen 1.6.1