Logo ROOT   6.08/07
Reference Guide
TStylePreview.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Denis Favre-Miville 08/09/05
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TStylePreview //
15 // //
16 // This class may be used to preview the result of applying a style //
17 // to a canvas. The result is shown on a clone of the object, //
18 // in a different shown over the initial canvas. //
19 // //
20 //////////////////////////////////////////////////////////////////////////
21 
22 #include "TStylePreview.h"
23 #include "TStyleManager.h"
24 
25 #include <TCanvas.h>
26 #include <TRootEmbeddedCanvas.h>
27 #include <TStyle.h>
28 #include <TROOT.h>
29 
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// Constructor. Create a new window and draw a clone of
34 /// currentPad->GetCanvas() in it, using the style 'style'.
35 /// Thanks to that method, one can have a preview of any
36 /// style with any object.
37 
39  TVirtualPad *currentPad)
40  : TGTransientFrame(0, p)
41 {
42  fPad = 0;
43 
44  // Create the main window.
45  SetWindowName("Style Manager's Preview");
46  SetCleanup(kNoCleanup);
47  DontCallClose();
48 
49  // Create the trash lists to have an effective deletion of every object.
50  fTrashListLayout = new TList();
51 
52  // Create the layouts and add them to the layout trash list.
54  fTrashListLayout->Add(layoutXY);
55 
56  // Create a canvas for the preview.
57  fEcan = new TRootEmbeddedCanvas("TSMPreviewCanvas", this, 10, 10);
58  AddFrame(fEcan, layoutXY);
59 
60  // Draw the preview.
61  Update(style, currentPad);
62 
63  // Map main frame.
64  MapTheWindow();
65 
66  // No modifications allowed in the preview.
67  fEcan->GetCanvas()->SetEditable(kFALSE);
68  fEcan->GetCanvas()->SetBit(kNoContextMenu);
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Destructor.
73 
75 {
76  // Delete all the widgets created in this class.
77  delete fEcan;
78 
79  // Delete all the layouts.
80  TObject *obj1;
81  TObject *obj2;
82  obj1 = fTrashListLayout->First();
83  while (obj1) {
84  obj2 = fTrashListLayout->After(obj1);
85  fTrashListLayout->Remove(obj1);
86  delete obj1;
87  obj1 = obj2;
88  }
89  delete fTrashListLayout;
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Update the preview with possibly another style and
94 /// another object than previously.
95 
97 {
98  TCanvas *c;
99  if (pad != fPad) {
100  delete fEcan->GetCanvas();
101  fEcan->AdoptCanvas(new TCanvas("TSMPreviewCanvas", 10, 10,
103  c = fEcan->GetCanvas();
104  gROOT->SetSelectedPad(c);
105  if (pad->GetCanvas())
106  pad->GetCanvas()->DrawClonePad();
107  gROOT->SetSelectedPad(pad);
108  fPad = pad;
109  }
110 
111  // Apply the 'style' to the clone of 'pad'.
112  c = fEcan->GetCanvas();
113  TStyle *tmpStyle = gStyle;
114  gStyle = style;
115  c->UseCurrentStyle();
116  gStyle = tmpStyle;
117  c->Modified();
118  c->Update();
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Initialize the layout algorithm.
123 
125 {
126  MapSubwindows();
127  TCanvas *c = fPad->GetCanvas();
128  if (c) {
129  UInt_t w = c->GetWw() + 4; //4 pixels of borders
130  UInt_t h = c->GetWh() + 4; //4 pixels of borders
131  UInt_t x = (UInt_t) c->GetWindowTopX() + 60;
132  UInt_t y = (UInt_t) c->GetWindowTopY() + 100;
133 
134  MoveResize(x, y, w, h);
135  SetWMPosition(x, y);
136  }
137  MapWindow();
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Return pointer to the selected canvas.
142 
144 {
145  return fEcan->GetCanvas();
146 }
virtual void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0)
Move and/or resize the frame.
Definition: TGFrame.cxx:611
return c
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
TH1 * h
Definition: legend2.C:5
#define gROOT
Definition: TROOT.h:364
void MapTheWindow()
Initialize the layout algorithm.
const Bool_t kFALSE
Definition: Rtypes.h:92
void Update(TStyle *style, TVirtualPad *pad)
Update the preview with possibly another style and another object than previously.
void AdoptCanvas(TCanvas *c)
Canvas c is adopted from this embedded canvas.
Double_t x[n]
Definition: legend1.C:17
Int_t GetWindowTopY()
Returns current top y position of window on screen.
Definition: TCanvas.cxx:1124
UInt_t GetWw() const
Get Ww.
Definition: TCanvas.h:179
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
A doubly linked list.
Definition: TList.h:47
TRootEmbeddedCanvas * fEcan
Definition: TStylePreview.h:38
TCanvas * GetMainCanvas()
Return pointer to the selected canvas.
TStyle objects may be created to define special styles.
Definition: TStyle.h:43
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:557
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:675
UInt_t GetWh() const
Get Wh.
Definition: TCanvas.h:180
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
Definition: TList.cxx:289
Int_t GetCanvasWindowId() const
Int_t GetWindowTopX()
Returns current top x position of window on screen.
Definition: TCanvas.cxx:1113
virtual ~TStylePreview()
Destructor.
The Canvas class.
Definition: TCanvas.h:41
#define ClassImp(name)
Definition: Rtypes.h:279
TCanvas * GetCanvas() const
TCanvas * style()
Definition: style.C:1
Double_t y[n]
Definition: legend1.C:17
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
Mother of all ROOT objects.
Definition: TObject.h:37
void UseCurrentStyle()
Force a copy of current style for all objects in canvas.
Definition: TCanvas.cxx:1088
TList * fTrashListLayout
Definition: TStylePreview.h:40
void SetWMPosition(Int_t x, Int_t y)
Give the window manager a window position hint.
Definition: TGFrame.cxx:1837
virtual TObject * DrawClonePad()
Draw a clone of this canvas into the current pad In an interactive session, select the destination/cu...
Definition: TCanvas.cxx:868
virtual void MapWindow()
Definition: TGFrame.h:267
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2183
TVirtualPad * fPad
Definition: TStylePreview.h:39
void Modified(Bool_t flag=1)
Definition: TPad.h:399
virtual TCanvas * GetCanvas() const =0