XSElementDlg.cxx

Go to the documentation of this file.
00001 /*
00002  * $Header$
00003  * $Log$
00004  */
00005 
00006 #include <ctype.h>
00007 #include <stdlib.h>
00008 
00009 #include <TGTab.h>
00010 #include <TGFrame.h>
00011 #include <TGButton.h>
00012 #include <TGWindow.h>
00013 #include <TGButton.h>
00014 #include <TGMsgBox.h>
00015 
00016 #include "XSElementList.h"
00017 #include "XSPeriodicTable.h"
00018 #include "XSElementDlg.h"
00019 
00020 //ClassImp(XSElementDlg)
00021 
00022 enum    XSElementDlgEnum {
00023                 ELEM_OK=900,
00024                 ELEM_CANCEL
00025         };
00026 
00027 static  Int_t   activeTab=0;            // Remember last active Tab
00028 static  Int_t   LastWinX = -1;
00029 static  Int_t   LastWinY = -1;
00030 
00031 
00032 /* ----- XSElementDlg ----- */
00033 XSElementDlg::XSElementDlg( const TGWindow *p, const TGWindow *main,
00034                 UInt_t *retZ, UInt_t w, UInt_t h)
00035         : TGTransientFrame(p,main,w,h)
00036 {
00037         selectedZ = retZ;       // Save Address
00038 
00039         lHints = new TGLayoutHints( kLHintsTop | kLHintsLeft |
00040                         kLHintsExpandX | kLHintsExpandY,
00041                         2, 2, 2, 2);
00042 
00043         buttonFrame = new TGHorizontalFrame(this, 120, 20, kFixedWidth);
00044         okButton = new TGTextButton(buttonFrame, "&Ok", ELEM_OK);
00045         okButton->Associate(this);
00046         closeButton = new TGTextButton(buttonFrame, "&Close", ELEM_CANCEL);
00047         closeButton->Associate(this);
00048 
00049         buttonLayoutHints = new TGLayoutHints(
00050                                 kLHintsTop | kLHintsLeft | kLHintsExpandX,
00051                                 2, 2, 5, 1);
00052         buttonFrame->AddFrame(okButton, buttonLayoutHints);
00053         buttonFrame->AddFrame(closeButton, buttonLayoutHints);
00054 
00055         frameLayoutHints = new TGLayoutHints(kLHintsBottom | kLHintsRight,
00056                         2, 2, 2, 2);
00057         AddFrame(buttonFrame, frameLayoutHints);
00058 
00059         // ---------- Add Periodic table -------------
00060         TGCompositeFrame *tf;
00061         tabMenu = new TGTab(this, w, h);
00062 
00063         tf = tabMenu->AddTab("Periodic Table");
00064 
00065         pTable = new XSPeriodicTable(this,tf,w,h);
00066         pTable->SelectZ(*selectedZ);
00067         tf->AddFrame(pTable, lHints);
00068 
00069         // ------------- Table Sorted by Name ------------
00070         tf = tabMenu->AddTab("Name");
00071 
00072         nameFrame = new TGCompositeFrame(tf,w,h, kVerticalFrame);
00073         nameListBox = new XSElementList(nameFrame,XSEL_SORTBY_NAME);
00074         nameListBox->SelectZ(*selectedZ);
00075         nameFrame->AddFrame(nameListBox,lHints);
00076 
00077         tf->AddFrame(nameFrame,lHints);
00078 
00079         // ------------- Table Sorted by Mnemonic -------------
00080         tf = tabMenu->AddTab("Mnemonic");
00081 
00082         mnemonicFrame = new TGCompositeFrame(tf,w,h,kVerticalFrame);
00083         mnemonicListBox = new XSElementList(mnemonicFrame,XSEL_SORTBY_MNEMONIC);
00084         mnemonicListBox->SelectZ(*selectedZ);
00085         mnemonicFrame->AddFrame(mnemonicListBox, lHints);
00086 
00087         tf->AddFrame(mnemonicFrame, lHints);
00088 
00089         // ------------- Table Sorted by Charge -------------
00090         tf = tabMenu->AddTab("Z (Charge)");
00091 
00092         zFrame = new TGCompositeFrame(tf,w,h,kVerticalFrame);
00093         zListBox = new XSElementList(zFrame,XSEL_SORTBY_Z);
00094         zListBox->SelectZ(*selectedZ);
00095         zFrame->AddFrame(zListBox, lHints);
00096         tf->AddFrame(zFrame, lHints);
00097 
00098         // ------------- Finalise settings -----------------
00099         lHints2 = new TGLayoutHints(
00100                         kLHintsBottom | kLHintsExpandX | kLHintsExpandY,
00101                         2, 2, 5, 1);
00102         AddFrame(tabMenu, lHints2);
00103 
00104         tabMenu->SetTab(activeTab);
00105 
00106         /* --------- Set Windows Position --------- */
00107         int     ax, ay;
00108         if (LastWinX == -1) {   // Go to the middle of parent window
00109                 Window_t wdum;
00110                 gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
00111                         (((TGFrame *) main)->GetWidth() - fWidth) >> 1,
00112                         (((TGFrame *) main)->GetHeight() - fHeight) >> 1,
00113                         ax, ay, wdum);
00114         } else {
00115                 ax = LastWinX;
00116                 ay = LastWinY;
00117         }
00118         Move(ax,ay);
00119         SetWMPosition(ax,ay);
00120 
00121         MapSubwindows();
00122         Resize(GetDefaultSize());
00123         SetWindowName("Select Element");
00124         MapWindow();
00125 
00126         fClient->WaitFor(this);
00127 } // XSElementDlg
00128 
00129 /* ----- ~XSElementDlg ----- */
00130 XSElementDlg::~XSElementDlg()
00131 {
00132         activeTab = tabMenu->GetCurrent();
00133 
00134         delete  closeButton;
00135         delete  buttonFrame;
00136         delete  buttonLayoutHints;
00137         delete  frameLayoutHints;
00138         delete  lHints;
00139         delete  tabMenu;
00140         delete  pTable;
00141         delete  nameListBox;
00142         delete  nameFrame;
00143         delete  mnemonicListBox;
00144         delete  mnemonicFrame;
00145         delete  zListBox;
00146         delete  zFrame;
00147         delete  lHints2;
00148 } // ~XSElementDlg
00149 
00150 /* ----- CloseWindow ----- */
00151 void
00152 XSElementDlg::CloseWindow()
00153 {
00154         // --- Remember old position ---
00155         Window_t wdum;
00156         gVirtualX->TranslateCoordinates(GetId(), GetParent()->GetId(),
00157                 0, 0, LastWinX, LastWinY, wdum);
00158 
00159         delete this;
00160 } // CloseWindow
00161 
00162 /* ----- ProcessButton ----- */
00163 Bool_t
00164 XSElementDlg::ProcessButton(Long_t param)
00165 {
00166         Int_t   activeTab;
00167 
00168         switch (param) {
00169                 case ELEM_OK:
00170                         // Find active Tab
00171                         activeTab = tabMenu->GetCurrent();
00172                         if (activeTab==0)
00173                                 goto LERROR;
00174                         else {
00175                                 switch (activeTab) {
00176                                         case 1:
00177                                                 *selectedZ =
00178                                                    nameListBox->CurrentZ();
00179                                                 break;
00180                                         case 2:
00181                                                 *selectedZ =
00182                                                    mnemonicListBox->CurrentZ();
00183                                                 break;
00184                                         case 3:
00185                                                 *selectedZ =
00186                                                    zListBox->CurrentZ();
00187                                                 break;
00188                                 }
00189                                 if (*selectedZ==0)
00190                                         goto LERROR;
00191                         }
00192                         break;
00193 
00194                 case ELEM_CANCEL:
00195                         *selectedZ = 0;
00196                         break;
00197                 default:
00198                         *selectedZ = param;
00199                         break;
00200         }
00201         CloseWindow();
00202         return kTRUE;
00203 
00204 LERROR:
00205         // Issue a message to select an Element
00206         int     retval;
00207         new TGMsgBox(fClient->GetRoot(), this, "Info",
00208                 "Please Select one Element!",
00209                 kMBIconAsterisk, kMBOk, &retval );
00210         return kFALSE;
00211 } // ProcessButton
00212 
00213 /* ----- ProcessMessage ----- */
00214 Bool_t
00215 XSElementDlg::ProcessMessage(Long_t msg, Long_t param1, Long_t /*param2*/)
00216 {
00217         switch (GET_MSG(msg)) {
00218                 case kC_COMMAND:
00219                         switch (GET_SUBMSG(msg)) {
00220                                 case kCM_BUTTON:
00221                                         ProcessButton(param1);
00222                                         break;
00223 
00224                                 default:
00225                                         break;
00226                         }
00227                 default:
00228                         break;
00229         }
00230         return kTRUE;
00231 } // ProcessMessage

Generated on Tue Jul 5 15:15:04 2011 for ROOT_528-00b_version by  doxygen 1.5.1