TStylePreview.cxx

Go to the documentation of this file.
00001 // @(#)root/ged:$Id: TStylePreview.cxx,v 1.0 2005/09/08
00002 // Author: Denis Favre-Miville   08/09/05
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 //  TStylePreview                                                       //
00015 //                                                                      //
00016 //  This class may be used to preview the result of applying a style    //
00017 //       to a canvas. The result is shown on a clone of the object,     //
00018 //       in a different shown over the initial canvas.                  //
00019 //                                                                      //
00020 //////////////////////////////////////////////////////////////////////////
00021 
00022 #include "TStylePreview.h"
00023 #include "TStyleManager.h"
00024 
00025 #include <TCanvas.h>
00026 #include <TRootEmbeddedCanvas.h>
00027 #include <TStyle.h>
00028 #include <TROOT.h>
00029 
00030 ClassImp(TStylePreview)
00031 
00032 //______________________________________________________________________________
00033 TStylePreview::TStylePreview(const TGWindow *p, TStyle *style,
00034                               TVirtualPad *currentPad)
00035                      : TGTransientFrame(0, p)
00036 {
00037    //  Constructor. Create a new window and draw a clone of
00038    // currentPad->GetCanvas() in it, using the style 'style'.
00039    //  Thanks to that method, one can have a preview of any
00040    // style with any object.
00041 
00042    fPad = 0;
00043 
00044    // Create the main window.
00045    SetWindowName("Style Manager's Preview");
00046    SetCleanup(kNoCleanup);
00047    DontCallClose();
00048 
00049    // Create the trash lists to have an effective deletion of every object.
00050    fTrashListLayout = new TList();
00051 
00052    // Create the layouts and add them to the layout trash list.
00053    TGLayoutHints *layoutXY = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
00054    fTrashListLayout->Add(layoutXY);
00055 
00056    // Create a canvas for the preview.
00057    fEcan = new TRootEmbeddedCanvas("TSMPreviewCanvas", this, 10, 10);
00058    AddFrame(fEcan, layoutXY);
00059 
00060    // Draw the preview.
00061    Update(style, currentPad);
00062 
00063    // Map main frame.
00064    MapTheWindow();
00065 
00066    // No modifications allowed in the preview.
00067    fEcan->GetCanvas()->SetEditable(kFALSE);
00068    fEcan->GetCanvas()->SetBit(kNoContextMenu);
00069 }
00070 
00071 //______________________________________________________________________________
00072 TStylePreview::~TStylePreview()
00073 {
00074    // Destructor.
00075 
00076    // Delete all the widgets created in this class.
00077    delete fEcan;
00078 
00079    // Delete all the layouts.
00080    TObject *obj1;
00081    TObject *obj2;
00082    obj1 = fTrashListLayout->First();
00083    while (obj1) {
00084       obj2 = fTrashListLayout->After(obj1);
00085       fTrashListLayout->Remove(obj1);
00086       delete obj1;
00087       obj1 = obj2;
00088    }
00089    delete fTrashListLayout;
00090 }
00091 
00092 //______________________________________________________________________________
00093 void TStylePreview::Update(TStyle *style, TVirtualPad *pad)
00094 {
00095    // Update the preview with possibly another style and 
00096    // another object than previously.
00097 
00098    TCanvas *c;
00099    if (pad != fPad) {
00100       delete fEcan->GetCanvas();
00101       fEcan->AdoptCanvas(new TCanvas("TSMPreviewCanvas", 10, 10,
00102                                        fEcan->GetCanvasWindowId()));
00103       c = fEcan->GetCanvas();
00104       gROOT->SetSelectedPad(c);
00105       pad->GetCanvas()->DrawClonePad();
00106       gROOT->SetSelectedPad(pad);
00107       fPad = pad;
00108    }
00109 
00110    // Apply the 'style' to the clone of 'pad'.
00111    c = fEcan->GetCanvas();
00112    TStyle *tmpStyle = gStyle;
00113    gStyle = style;
00114    c->UseCurrentStyle();
00115    gStyle = tmpStyle;
00116    c->Modified();
00117    c->Update();
00118 }
00119 
00120 //______________________________________________________________________________
00121 void TStylePreview::MapTheWindow()
00122 {
00123    // Initialize the layout algorithm.
00124    
00125    MapSubwindows();
00126    TCanvas *c = fPad->GetCanvas();
00127    UInt_t w = c->GetWw() + 4; //4 pixels of borders
00128    UInt_t h = c->GetWh() + 4; //4 pixels of borders
00129    UInt_t x = (UInt_t) c->GetWindowTopX() + 60;
00130    UInt_t y = (UInt_t) c->GetWindowTopY() + 100;
00131 
00132    MoveResize(x, y, w, h);
00133    SetWMPosition(x, y);
00134 
00135    MapWindow();
00136 }
00137 
00138 //______________________________________________________________________________
00139 TCanvas *TStylePreview::GetMainCanvas()
00140 {
00141    // Return pointer to the selected canvas.
00142    
00143    return fEcan->GetCanvas();
00144 }

Generated on Tue Jul 5 14:19:49 2011 for ROOT_528-00b_version by  doxygen 1.5.1