00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Riostream.h"
00013 #include "TROOT.h"
00014 #include "TButton.h"
00015 #include "TCanvas.h"
00016 #include "TLatex.h"
00017
00018 #include <string.h>
00019
00020 ClassImp(TButton)
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 TButton::TButton(): TPad()
00092 {
00093
00094
00095 fFraming = 0;
00096 fMethod = "";
00097 fLogx = kFALSE;
00098 fLogy = kFALSE;
00099 SetEditable(kFALSE);
00100 fFocused = 0;
00101 }
00102
00103
00104
00105 TButton::TButton(const char *title, const char *method, Double_t x1, Double_t y1,Double_t x2, Double_t y2)
00106 :TPad("button",title,x1,y1,x2,y2,18,2,1), TAttText(22,0,1,61,0.65)
00107 {
00108
00109
00110
00111
00112 fFraming=0;
00113 SetBit(kCanDelete);
00114 fModified = kTRUE;
00115 fMethod = method;
00116 if (strlen(title)) {
00117 TLatex *text = new TLatex(0.5*(fX1+fX2),0.5*(fY1+fY2),title);
00118 fPrimitives->Add(text);
00119 }
00120 fLogx = kFALSE;
00121 fLogy = kFALSE;
00122 SetEditable(kFALSE);
00123 fFocused = 0;
00124 }
00125
00126
00127
00128 TButton::~TButton()
00129 {
00130
00131
00132 if (fPrimitives) fPrimitives->Delete();
00133 }
00134
00135
00136
00137 void TButton::Draw(Option_t *option)
00138 {
00139
00140
00141 if (fCanvas) AppendPad(option);
00142 }
00143
00144
00145
00146 void TButton::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00147 {
00148
00149
00150
00151
00152
00153 if (!TestBit(kNotDeleted)) return;
00154
00155 if (IsEditable()) {
00156 TPad::ExecuteEvent(event,px,py);
00157 return;
00158 }
00159
00160 TPad *cdpad = (TPad*)gROOT->GetSelectedPad();
00161 HideToolTip(event);
00162
00163 switch (event) {
00164
00165 case kMouseEnter:
00166 TPad::ExecuteEvent(event,px,py);
00167 break;
00168
00169 case kButton1Down:
00170 SetBorderMode(-1);
00171 fFocused=1;
00172 Modified();
00173 Update();
00174 break;
00175
00176 case kMouseMotion:
00177
00178 break;
00179
00180 case kButton1Motion:
00181 if (px<XtoAbsPixel(1) && px>XtoAbsPixel(0) &&
00182 py<YtoAbsPixel(0) && py>YtoAbsPixel(1)) {
00183 if (!fFocused) {
00184 SetBorderMode(-1);
00185 fFocused=1;
00186 Modified();
00187 GetCanvas()->Modified();
00188 Update();
00189 }
00190 } else if (fFocused) {
00191 SetBorderMode(1);
00192 fFocused=0;
00193 Modified();
00194 GetCanvas()->Modified();
00195 Update();
00196 }
00197 break;
00198
00199 case kButton1Up:
00200 SetCursor(kWatch);
00201 if (fFocused) {
00202 if (cdpad) cdpad->cd();
00203 gROOT->ProcessLine(GetMethod());
00204 }
00205
00206 if (!TestBit(kNotDeleted)) return;
00207 SetBorderMode(1);
00208 Modified();
00209 Update();
00210 SetCursor(kCross);
00211 break;
00212 }
00213 }
00214
00215
00216
00217 void TButton::Paint(Option_t *option)
00218 {
00219
00220
00221 TPad::Paint(option);
00222 }
00223
00224
00225
00226 void TButton::PaintModified()
00227 {
00228
00229
00230 if (!fCanvas) return;
00231 if (!fPrimitives) fPrimitives = new TList();
00232 TObject *obj = GetListOfPrimitives()->First();
00233 if (obj && obj->InheritsFrom(TText::Class())) {
00234 TLatex *text = (TLatex*)obj;
00235 text->SetTitle(GetTitle());
00236 text->SetTextSize(GetTextSize());
00237 text->SetTextFont(GetTextFont());
00238 text->SetTextAlign(GetTextAlign());
00239 text->SetTextColor(GetTextColor());
00240 text->SetTextAngle(GetTextAngle());
00241 }
00242 SetLogx(0);
00243 SetLogy(0);
00244 TPad::PaintModified();
00245 }
00246
00247
00248
00249 void TButton::Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
00250 {
00251
00252
00253 TPad::Range(x1,y1,x2,y2);
00254 }
00255
00256
00257
00258 void TButton::SavePrimitive(ostream &out, Option_t * )
00259 {
00260
00261
00262 TPad *padsav = (TPad*)gPad;
00263 char quote = '"';
00264 if (gROOT->ClassSaved(TButton::Class())) {
00265 out<<" ";
00266 } else {
00267 out<<" TButton *";
00268 }
00269 char *cm = (char*)GetMethod();
00270 Int_t nch = strlen(cm);
00271 char *cmethod = new char[nch+10];
00272 Int_t i = 0;
00273 while(*cm) {
00274 if (*cm == '"') {
00275 cmethod[i] = '\\';
00276 i++;
00277 }
00278 cmethod[i] = *cm;
00279 i++;
00280 cm++;
00281 }
00282 cmethod[i] = 0;
00283 out<<"button = new TButton("<<quote<<GetTitle()
00284 <<quote<<","<<quote<<cmethod<<quote
00285 <<","<<fXlowNDC
00286 <<","<<fYlowNDC
00287 <<","<<fXlowNDC+fWNDC
00288 <<","<<fYlowNDC+fHNDC
00289 <<");"<<endl;
00290 delete [] cmethod;
00291
00292 SaveFillAttributes(out,"button",0,1001);
00293 SaveLineAttributes(out,"button",1,1,1);
00294 SaveTextAttributes(out,"button",22,0,1,61,.65);
00295
00296 if (GetBorderSize() != 2) {
00297 out<<" button->SetBorderSize("<<GetBorderSize()<<");"<<endl;
00298 }
00299 if (GetBorderMode() != 1) {
00300 out<<" button->SetBorderMode("<<GetBorderMode()<<");"<<endl;
00301 }
00302
00303 if (GetFraming()) out<<"button->SetFraming();"<<endl;
00304 if (IsEditable()) out<<"button->SetEditable(kTRUE);"<<endl;
00305
00306 out<<" button->Draw();"<<endl;
00307
00308 TIter next(GetListOfPrimitives());
00309 TObject *obj = next();
00310
00311 Int_t nprim = 0;
00312 while ((obj = next())) {
00313 if (!nprim) out<<" button->cd();"<<endl;
00314 nprim++;
00315 obj->SavePrimitive(out, (Option_t *)next.GetOption());
00316 }
00317
00318 if (nprim) out<<" "<<padsav->GetName()<<"->cd();"<<endl;
00319 padsav->cd();
00320 }
00321
00322
00323
00324 void TButton::SetFraming(Bool_t f)
00325 {
00326
00327
00328 fFraming=f;
00329 if (f) SetBit(kFraming);
00330 else ResetBit(kFraming);
00331 }