00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00038
00039
00040
00041
00042 fPad = 0;
00043
00044
00045 SetWindowName("Style Manager's Preview");
00046 SetCleanup(kNoCleanup);
00047 DontCallClose();
00048
00049
00050 fTrashListLayout = new TList();
00051
00052
00053 TGLayoutHints *layoutXY = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
00054 fTrashListLayout->Add(layoutXY);
00055
00056
00057 fEcan = new TRootEmbeddedCanvas("TSMPreviewCanvas", this, 10, 10);
00058 AddFrame(fEcan, layoutXY);
00059
00060
00061 Update(style, currentPad);
00062
00063
00064 MapTheWindow();
00065
00066
00067 fEcan->GetCanvas()->SetEditable(kFALSE);
00068 fEcan->GetCanvas()->SetBit(kNoContextMenu);
00069 }
00070
00071
00072 TStylePreview::~TStylePreview()
00073 {
00074
00075
00076
00077 delete fEcan;
00078
00079
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
00096
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
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
00124
00125 MapSubwindows();
00126 TCanvas *c = fPad->GetCanvas();
00127 UInt_t w = c->GetWw() + 4;
00128 UInt_t h = c->GetWh() + 4;
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
00142
00143 return fEcan->GetCanvas();
00144 }