Logo ROOT   6.16/01
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");
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.
65
66 // No modifications allowed in the preview.
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);
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{
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}
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
#define ClassImp(name)
Definition: Rtypes.h:363
@ kNoCleanup
Definition: TGFrame.h:49
@ kLHintsExpandY
Definition: TGLayout.h:38
@ kLHintsExpandX
Definition: TGLayout.h:37
#define gROOT
Definition: TROOT.h:410
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
The Canvas class.
Definition: TCanvas.h:31
virtual TObject * DrawClonePad()
Draw a clone of this canvas into the current pad In an interactive session, select the destination/cu...
Definition: TCanvas.cxx:904
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1054
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
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
virtual void MapWindow()
Definition: TGFrame.h:251
void DontCallClose()
Typically call this method in the slot connected to the CloseWindow() signal to prevent the calling o...
Definition: TGFrame.cxx:1738
void SetWMPosition(Int_t x, Int_t y)
Give the window manager a window position hint.
Definition: TGFrame.cxx:1837
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1746
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
Definition: TList.cxx:327
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:655
Mother of all ROOT objects.
Definition: TObject.h:37
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
@ kNoContextMenu
if object does not want context menu
Definition: TObject.h:65
virtual void SetEditable(Bool_t mode=kTRUE)
Set pad editable yes/no If a pad is not editable:
Definition: TPad.cxx:5806
void AdoptCanvas(TCanvas *c)
Canvas c is adopted from this embedded canvas.
TCanvas * GetCanvas() const
Int_t GetCanvasWindowId() const
TStylePreview(const TGWindow *p, TStyle *style, TVirtualPad *currentPad)
Constructor.
TCanvas * GetMainCanvas()
Return pointer to the selected canvas.
void MapTheWindow()
Initialize the layout algorithm.
TVirtualPad * fPad
Definition: TStylePreview.h:37
void Update(TStyle *style, TVirtualPad *pad)
Update the preview with possibly another style and another object than previously.
TList * fTrashListLayout
Definition: TStylePreview.h:38
virtual ~TStylePreview()
Destructor.
TRootEmbeddedCanvas * fEcan
Definition: TStylePreview.h:36
TStyle objects may be created to define special styles.
Definition: TStyle.h:27
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:50
virtual TCanvas * GetCanvas() const =0
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
TCanvas * style()
Definition: style.C:1