canvsave.cxx

Go to the documentation of this file.
00001 //----------------------------------------------------
00002 //
00003 //    A small panel destined to provide graphical interface
00004 //    for "Canvas Save" action
00005 //
00006 //    Author: Dmitry Vasiliev (LNS, Catania)
00007 //
00008 //----------------------------------------------------
00009 //
00010 #include "canvsave.h"
00011 #include <TCollection.h>
00012 #include <TCanvas.h>
00013 #include <TROOT.h>
00014 
00015 ClassImp(CanvSave)
00016 
00017 
00018 CanvSave::CanvSave(const TGWindow *p, const TGWindow *main, UInt_t w,
00019                    UInt_t h, UInt_t options) :
00020       TGTransientFrame(p, main, w, h, options)
00021 {
00022    /*
00023    //--------------------------------------------------------
00024    //
00025    //     Constructor for the class CanvSave
00026    //
00027    //-------------------------------------------------------
00028    //
00029    //
00030    //                   -------------------------
00031    //                   |                       |
00032    //                   |-----------------------|
00033    //                   |         fFrame        |
00034    //                   |-----------------------|
00035    //                   |                       |
00036    //                   -------------------------
00037    //                   /         |              \
00038    //                  /          |               \
00039    //          ------------    ----------       ----------------
00040    //          |          |    |        |       |      |       |
00041    //          |   fF1    |    |  fF2   |       |     fF3      |
00042    //          |          |    |        |       |      |       |
00043    //          ------------    ----------       ----------------
00044    //               |              |             /            \
00045    //          ------------    ----------    ----------    -----------
00046    //          |          |    |        |    |        |    |         |
00047    //          |  fCombo  |    |  fText |    | fSave  |    | fCancel |
00048    //          |          |    |        |    |        |    |         |
00049    //          ------------    ----------    ----------    -----------
00050    //
00051    //
00052    //--------------------------------------------------------------------
00053    */
00054 
00055    fFrame = new TGCompositeFrame(this, 400, 200, kVerticalFrame);
00056    AddFrame(fFrame, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
00057 
00058    fF1 = new TGCompositeFrame(fFrame, 400, 50, kHorizontalFrame);
00059    fF1->SetLayoutManager(new TGMatrixLayout(fF1, 0, 2, 10));
00060    fFrame->AddFrame(fF1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
00061 
00062    fF2 = new TGCompositeFrame(fFrame, 400, 50, kHorizontalFrame);
00063    fF2->SetLayoutManager(new TGMatrixLayout(fF2, 0, 2, 10));
00064    fFrame->AddFrame(fF2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
00065 
00066    fF3 = new TGCompositeFrame(fFrame, 400, 100, kHorizontalFrame);
00067    fFrame->AddFrame(fF3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
00068 
00069    fF1->AddFrame(new TGLabel(fF1, new TGHotString("Save as")));
00070    fCombo = new TGComboBox(fF1, 10);
00071    fCombo->Associate(this);
00072    char tmp[20];
00073    snprintf(tmp,20, "%s", ".ps");
00074    fCombo->AddEntry(tmp, 1);
00075    snprintf(tmp,20, "%s", ".gif");
00076    fCombo->AddEntry(tmp, 2);
00077    fCombo->Resize(100, 20);
00078    fCombo->Select(1);
00079    fF1->AddFrame(fCombo);
00080 
00081    fF2->AddFrame(new TGLabel(fF2, new TGHotString("Enter file name")));
00082    fBuf = new TGTextBuffer(100);
00083    fText = new TGTextEntry(fF2, fBuf, -1);
00084    fText->Resize(100, 20);
00085    fBuf->AddText(0, "histo.ps");
00086    fF2->AddFrame(fText);
00087 
00088    fSave = new TGTextButton(fF3, " Save  ", 100);
00089    fSave->Associate(this);
00090    fSave->Resize(60, 20);
00091    fF3->AddFrame(fSave, new TGLayoutHints(kLHintsLeft | kLHintsTop, 60, 10, 2, 2));
00092 
00093    fCancel = new TGTextButton(fF3, "Cancel", 101);
00094    fCancel->Associate(this);
00095    fCancel->Resize(60, 20);
00096    fF3->AddFrame(fCancel, new TGLayoutHints(kLHintsLeft | kLHintsTop, 10, 5, 2, 2));
00097 
00098    MapSubwindows();
00099 
00100    Window_t wdum;
00101    Int_t ax, ay;
00102 
00103    //printf("GetWidth = %ld\tfWidth = %ld\n",((TGFrame*)main)->GetWidth(),fWidth);
00104 
00105    gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
00106                                    (((TGFrame *) main)->GetWidth() - fWidth) >> 1,
00107                                    (((TGFrame *) main)->GetHeight() - fHeight) >> 1,
00108                                    ax, ay, wdum);
00109    Move(ax, ay);
00110 
00111    SetWindowName("SAVE PANEL");
00112 
00113    Resize(GetDefaultSize());
00114    MapWindow();
00115    fClient->WaitFor(this); //otherwise the current directory in the file view
00116    //window is not always updated when a picture is saved
00117 }
00118 
00119 CanvSave::~CanvSave()
00120 {
00121    //-----------------------------------------------------
00122    //
00123    //      Destructor for the class CanvSave
00124    //
00125    //----------------------------------------------------
00126 
00127    delete fCancel;
00128    delete fSave;
00129    delete fText;
00130    delete fCombo;
00131    delete fF3;
00132    delete fF2;
00133    delete fF1;
00134    delete fFrame;
00135 }
00136 
00137 void CanvSave::CloseWindow()
00138 {
00139    //---------------------------------------------------
00140    //
00141    //                CloseWindow()
00142    //
00143    //    Closes the window "SAVE PANEL" (apparently)
00144    //
00145    //---------------------------------------------------
00146 
00147    delete this;
00148 }
00149 
00150 Bool_t CanvSave::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
00151 {
00152    //------------------------------------------------------------
00153    //
00154    //     ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
00155    //
00156    //   Processes information from GUI items of the panel
00157    //
00158    //------------------------------------------------------------
00159 
00160    TIter it(gROOT->GetListOfCanvases());
00161    TCanvas *c;
00162    while ((c = (TCanvas*) it()))  {
00163       if (!strcmp("canvasA", c->GetName())) break;
00164    }
00165 
00166    switch (GET_MSG(msg)) {
00167       case kC_COMMAND:
00168 
00169          switch (GET_SUBMSG(msg)) {
00170 
00171             case kCM_BUTTON:
00172 
00173                switch (parm1) {
00174                   case 100:
00175 
00176                      //'Save' button is clicked
00177 
00178                      if (!strcmp("canvasA", c->GetName())) {
00179                         c->cd();
00180                         c->Print(fBuf->GetString());
00181                      }
00182                      CloseWindow();
00183                      break;
00184 
00185                   case 101:
00186                      CloseWindow();
00187                      break;
00188 
00189                   default:
00190                      break;
00191                }
00192 
00193             case kCM_COMBOBOX:
00194 
00195                // Process Combo box
00196 
00197                switch (parm1) {
00198                   case 10:
00199                      if (parm2 == 1) {
00200                         fBuf->Clear();
00201                         fBuf->AddText(0, "hist.ps");
00202                         fClient->NeedRedraw(fText);
00203                      }
00204                      if (parm2 == 2) {
00205                         fBuf->Clear();
00206                         fBuf->AddText(0, "histo.gif");
00207                         fClient->NeedRedraw(fText);
00208                      }
00209                      break;
00210 
00211                   default:
00212                      break;
00213                }
00214 
00215             default:
00216                break;
00217          }
00218 
00219       default:
00220          break;
00221    }
00222 
00223    return kTRUE;
00224 }

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