Logo ROOT   master
Reference Guide
TCanvas.cxx
Go to the documentation of this file.
1 // @(#)root/gpad:$Id$
2 // Author: Rene Brun 12/12/94
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 #include <string.h>
13 #include <stdlib.h>
14 
15 #include "Riostream.h"
16 #include "TROOT.h"
17 #include "TCanvas.h"
18 #include "TClass.h"
19 #include "TStyle.h"
20 #include "TText.h"
21 #include "TBox.h"
22 #include "TCanvasImp.h"
23 #include "TDialogCanvas.h"
24 #include "TGuiFactory.h"
25 #include "TEnv.h"
26 #include "TError.h"
27 #include "TContextMenu.h"
28 #include "TControlBar.h"
29 #include "TInterpreter.h"
30 #include "TApplication.h"
31 #include "TColor.h"
32 #include "TVirtualPadEditor.h"
33 #include "TVirtualViewer3D.h"
34 #include "TPadPainter.h"
35 #include "TVirtualGL.h"
36 #include "TVirtualPS.h"
37 #include "TVirtualX.h"
38 #include "TAxis.h"
39 #include "TH1.h"
40 #include "TGraph.h"
41 #include "TView.h"
42 
43 #include "TVirtualMutex.h"
44 
45 class TCanvasInit {
46 public:
47  TCanvasInit() { TApplication::NeedGraphicsLibs(); }
48 };
49 static TCanvasInit gCanvasInit;
50 
51 
52 //*-*x16 macros/layout_canvas
53 
55 
57 
59 
60 
61 /** \class TCanvas
62 \ingroup gpad
63 
64 The Canvas class.
65 
66 A Canvas is an area mapped to a window directly under the control of the display
67 manager. A ROOT session may have several canvases open at any given time.
68 
69 A Canvas may be subdivided into independent graphical areas: the __Pads__.
70 A canvas has a default pad which has the name of the canvas itself.
71 An example of a Canvas layout is sketched in the picture below.
72 
73 \image html gpad_canvas.png
74 
75 This canvas contains two pads named P1 and P2. Both Canvas, P1 and P2 can be
76 moved, grown, shrunk using the normal rules of the Display manager.
77 
78 Once objects have been drawn in a canvas, they can be edited/moved by pointing
79 directly to them. The cursor shape is changed to suggest the type of action that
80 one can do on this object. Clicking with the right mouse button on an object
81 pops-up a contextmenu with a complete list of actions possible on this object.
82 
83 A graphical editor may be started from the canvas "View" menu under the menu
84 entry "Toolbar".
85 
86 An interactive HELP is available by clicking on the HELP button at the top right
87 of the canvas. It gives a short explanation about the canvas' menus.
88 
89 A canvas may be automatically divided into pads via `TPad::Divide`.
90 
91 At creation time, no matter if in interactive or batch mode, the canvas size
92 defines the size of the canvas window (including the size of the window
93 manager's decoration). To define precisely the graphics area size of a canvas in
94 the interactive mode, the following four lines of code should be used:
95 ~~~ {.cpp}
96  {
97  Double_t w = 600;
98  Double_t h = 600;
99  auto c = new TCanvas("c", "c", w, h);
100  c->SetWindowSize(w + (w - c->GetWw()), h + (h - c->GetWh()));
101  }
102 ~~~
103 and in the batch mode simply do:
104 ~~~ {.cpp}
105  c->SetCanvasSize(w,h);
106 ~~~
107 
108 If the canvas size this exceed the window size, scroll bars will be added to the canvas
109 This allows to display very large canvases (even bigger than the screen size). The
110 Following example shows how to proceed.
111 ~~~ {.cpp}
112  {
113  auto c = new TCanvas("c","c");
114  c->SetCanvasSize(1500, 1500);
115  c->SetWindowSize(500, 500);
116  }
117 ~~~
118 */
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Canvas default constructor.
122 
123 TCanvas::TCanvas(Bool_t build) : TPad(), fDoubleBuffer(0)
124 {
125  fPainter = 0;
126  fWindowTopX = 0;
127  fWindowTopY = 0;
128  fWindowWidth = 0;
129  fWindowHeight = 0;
130  fCw = 0;
131  fCh = 0;
132  fXsizeUser = 0;
133  fYsizeUser = 0;
134  fXsizeReal = kDefaultCanvasSize;
135  fYsizeReal = kDefaultCanvasSize;
136  fHighLightColor = gEnv->GetValue("Canvas.HighLightColor", kRed);
137  fEvent = -1;
138  fEventX = -1;
139  fEventY = -1;
140  fSelectedX = 0;
141  fSelectedY = 0;
142  fRetained = kTRUE;
143  fDrawn = kFALSE;
144  fSelected = 0;
145  fClickSelected = 0;
146  fSelectedPad = 0;
147  fClickSelectedPad = 0;
148  fPadSave = 0;
149  fCanvasImp = 0;
150  fContextMenu = 0;
151 
152  fUseGL = gStyle->GetCanvasPreferGL();
153 
154  if (!build || TClass::IsCallingNew() != TClass::kRealNew) {
155  Constructor();
156  } else {
157  const char *defcanvas = gROOT->GetDefCanvasName();
158  char *cdef;
159 
160  auto lc = (TList*)gROOT->GetListOfCanvases();
161  if (lc->FindObject(defcanvas)) {
162  Int_t n = lc->GetSize()+1;
163  while (lc->FindObject(Form("%s_n%d",defcanvas,n))) n++;
164  cdef = StrDup(Form("%s_n%d",defcanvas,n));
165  } else {
166  cdef = StrDup(Form("%s",defcanvas));
167  }
168  Constructor(cdef, cdef, 1);
169  delete [] cdef;
170  }
171 }
172 
173 ////////////////////////////////////////////////////////////////////////////////
174 /// Canvas default constructor
175 
177 {
178  if (gThreadXAR) {
179  void *arr[2];
180  arr[1] = this;
181  if ((*gThreadXAR)("CANV", 2, arr, 0)) return;
182  }
183 
184  fCanvas = 0;
185  fCanvasID = -1;
186  fCanvasImp = 0;
187  fBatch = kTRUE;
188  fUpdating = kFALSE;
189 
190  fContextMenu = 0;
191  fSelected = 0;
192  fClickSelected = 0;
193  fSelectedPad = 0;
194  fClickSelectedPad = 0;
195  fPadSave = 0;
196  SetBit(kAutoExec);
199 }
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 /// Create an embedded canvas, i.e. a canvas that is in a TGCanvas widget
203 /// which is placed in a TGFrame. This ctor is only called via the
204 /// TRootEmbeddedCanvas class.
205 ///
206 /// If "name" starts with "gl" the canvas is ready to receive GL output.
207 
208 TCanvas::TCanvas(const char *name, Int_t ww, Int_t wh, Int_t winid) : TPad(), fDoubleBuffer(0)
209 {
210  fCanvasImp = 0;
211  fPainter = 0;
212  Init();
213 
214  fCanvasID = winid;
215  fWindowTopX = 0;
216  fWindowTopY = 0;
217  fWindowWidth = ww;
218  fWindowHeight = wh;
219  fCw = ww + 4;
220  fCh = wh +28;
221  fBatch = kFALSE;
222  fUpdating = kFALSE;
223 
224  //This is a very special ctor. A window exists already!
225  //Can create painter now.
227 
228  if (fUseGL) {
229  fGLDevice = gGLManager->CreateGLContext(winid);
230  if (fGLDevice == -1)
231  fUseGL = kFALSE;
232  }
233 
235  if (!fCanvasImp) return;
236 
237  CreatePainter();
238  SetName(name);
239  Build();
240 }
241 
242 ////////////////////////////////////////////////////////////////////////////////
243 /// Create a new canvas with a predefined size form.
244 /// If form < 0 the menubar is not shown.
245 ///
246 /// - form = 1 700x500 at 10,10 (set by TStyle::SetCanvasDefH,W,X,Y)
247 /// - form = 2 500x500 at 20,20
248 /// - form = 3 500x500 at 30,30
249 /// - form = 4 500x500 at 40,40
250 /// - form = 5 500x500 at 50,50
251 ///
252 /// If "name" starts with "gl" the canvas is ready to receive GL output.
253 
254 TCanvas::TCanvas(const char *name, const char *title, Int_t form) : TPad(), fDoubleBuffer(0)
255 {
256  fPainter = 0;
258 
259  Constructor(name, title, form);
260 }
261 
262 ////////////////////////////////////////////////////////////////////////////////
263 /// Create a new canvas with a predefined size form.
264 /// If form < 0 the menubar is not shown.
265 ///
266 /// - form = 1 700x500 at 10,10 (set by TStyle::SetCanvasDefH,W,X,Y)
267 /// - form = 2 500x500 at 20,20
268 /// - form = 3 500x500 at 30,30
269 /// - form = 4 500x500 at 40,40
270 /// - form = 5 500x500 at 50,50
271 
272 void TCanvas::Constructor(const char *name, const char *title, Int_t form)
273 {
274  if (gThreadXAR) {
275  void *arr[6];
276  static Int_t ww = 500;
277  static Int_t wh = 500;
278  arr[1] = this; arr[2] = (void*)name; arr[3] = (void*)title; arr[4] =&ww; arr[5] = &wh;
279  if ((*gThreadXAR)("CANV", 6, arr, 0)) return;
280  }
281 
282  Init();
283  SetBit(kMenuBar,1);
284  if (form < 0) {
285  form = -form;
286  SetBit(kMenuBar,0);
287  }
288 
289  fCanvas = this;
290 
291  fCanvasID = -1;
292  TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(name);
293  if (old && old->IsOnHeap()) {
294  Warning("Constructor","Deleting canvas with same name: %s",name);
295  delete old;
296  }
297  if (gROOT->IsBatch()) { //We are in Batch mode
298  fWindowTopX = fWindowTopY = 0;
299  if (form == 1) {
302  } else {
303  fWindowWidth = 500;
304  fWindowHeight = 500;
305  }
306  fCw = fWindowWidth;
307  fCh = fWindowHeight;
309  if (!fCanvasImp) return;
310  fBatch = kTRUE;
311  } else { //normal mode with a screen window
313  if (form < 1 || form > 5) form = 1;
314  if (form == 1) {
315  UInt_t uh = UInt_t(cx*gStyle->GetCanvasDefH());
316  UInt_t uw = UInt_t(cx*gStyle->GetCanvasDefW());
317  Int_t ux = Int_t(cx*gStyle->GetCanvasDefX());
318  Int_t uy = Int_t(cx*gStyle->GetCanvasDefY());
319  fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, ux, uy, uw, uh);
320  }
321  fCw = 500;
322  fCh = 500;
323  if (form == 2) fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, 20, 20, UInt_t(cx*500), UInt_t(cx*500));
324  if (form == 3) fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, 30, 30, UInt_t(cx*500), UInt_t(cx*500));
325  if (form == 4) fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, 40, 40, UInt_t(cx*500), UInt_t(cx*500));
326  if (form == 5) fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, 50, 50, UInt_t(cx*500), UInt_t(cx*500));
327  if (!fCanvasImp) return;
328 
329  if (!gROOT->IsBatch() && fCanvasID == -1)
331 
333  fBatch = kFALSE;
334  }
335 
336  CreatePainter();
337 
338  SetName(name);
339  SetTitle(title); // requires fCanvasImp set
340  Build();
341 
342  // Popup canvas
343  fCanvasImp->Show();
344 }
345 
346 ////////////////////////////////////////////////////////////////////////////////
347 /// Create a new canvas at a random position.
348 ///
349 /// \param[in] name canvas name
350 /// \param[in] title canvas title
351 /// \param[in] ww is the canvas size in pixels along X
352 /// (if ww < 0 the menubar is not shown)
353 /// \param[in] wh is the canvas size in pixels along Y
354 ///
355 /// If "name" starts with "gl" the canvas is ready to receive GL output.
356 
357 TCanvas::TCanvas(const char *name, const char *title, Int_t ww, Int_t wh) : TPad(), fDoubleBuffer(0)
358 {
359  fPainter = 0;
361 
362  Constructor(name, title, ww, wh);
363 }
364 
365 ////////////////////////////////////////////////////////////////////////////////
366 /// Create a new canvas at a random position.
367 ///
368 /// \param[in] name canvas name
369 /// \param[in] title canvas title
370 /// \param[in] ww is the canvas size in pixels along X
371 /// (if ww < 0 the menubar is not shown)
372 /// \param[in] wh is the canvas size in pixels along Y
373 
374 void TCanvas::Constructor(const char *name, const char *title, Int_t ww, Int_t wh)
375 {
376  if (gThreadXAR) {
377  void *arr[6];
378  arr[1] = this; arr[2] = (void*)name; arr[3] = (void*)title; arr[4] =&ww; arr[5] = &wh;
379  if ((*gThreadXAR)("CANV", 6, arr, 0)) return;
380  }
381 
382  Init();
383  SetBit(kMenuBar,1);
384  if (ww < 0) {
385  ww = -ww;
386  SetBit(kMenuBar,0);
387  }
388  fCw = ww;
389  fCh = wh;
390  fCanvasID = -1;
391  TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(name);
392  if (old && old->IsOnHeap()) {
393  Warning("Constructor","Deleting canvas with same name: %s",name);
394  delete old;
395  }
396  if (gROOT->IsBatch()) { //We are in Batch mode
397  fWindowTopX = fWindowTopY = 0;
398  fWindowWidth = ww;
399  fWindowHeight = wh;
400  fCw = ww;
401  fCh = wh;
403  if (!fCanvasImp) return;
404  fBatch = kTRUE;
405  } else {
407  fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, UInt_t(cx*ww), UInt_t(cx*wh));
408  if (!fCanvasImp) return;
409 
410  if (!gROOT->IsBatch() && fCanvasID == -1)
412 
414  fBatch = kFALSE;
415  }
416 
417  CreatePainter();
418 
419  SetName(name);
420  SetTitle(title); // requires fCanvasImp set
421  Build();
422 
423  // Popup canvas
424  fCanvasImp->Show();
425 }
426 
427 ////////////////////////////////////////////////////////////////////////////////
428 /// Create a new canvas.
429 ///
430 /// \param[in] name canvas name
431 /// \param[in] title canvas title
432 /// \param[in] wtopx,wtopy are the pixel coordinates of the top left corner of
433 /// the canvas (if wtopx < 0) the menubar is not shown)
434 /// \param[in] ww is the canvas size in pixels along X
435 /// \param[in] wh is the canvas size in pixels along Y
436 ///
437 /// If "name" starts with "gl" the canvas is ready to receive GL output.
438 
439 TCanvas::TCanvas(const char *name, const char *title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh)
440  : TPad(), fDoubleBuffer(0)
441 {
442  fPainter = 0;
444 
445  Constructor(name, title, wtopx, wtopy, ww, wh);
446 }
447 
448 ////////////////////////////////////////////////////////////////////////////////
449 /// Create a new canvas.
450 ///
451 /// \param[in] name canvas name
452 /// \param[in] title canvas title
453 /// \param[in] wtopx,wtopy are the pixel coordinates of the top left corner of
454 /// the canvas (if wtopx < 0) the menubar is not shown)
455 /// \param[in] ww is the canvas size in pixels along X
456 /// \param[in] wh is the canvas size in pixels along Y
457 
458 void TCanvas::Constructor(const char *name, const char *title, Int_t wtopx,
459  Int_t wtopy, Int_t ww, Int_t wh)
460 {
461  if (gThreadXAR) {
462  void *arr[8];
463  arr[1] = this; arr[2] = (void*)name; arr[3] = (void*)title;
464  arr[4] = &wtopx; arr[5] = &wtopy; arr[6] = &ww; arr[7] = &wh;
465  if ((*gThreadXAR)("CANV", 8, arr, 0)) return;
466  }
467 
468  Init();
469  SetBit(kMenuBar,1);
470  if (wtopx < 0) {
471  wtopx = -wtopx;
472  SetBit(kMenuBar,0);
473  }
474  fCw = ww;
475  fCh = wh;
476  fCanvasID = -1;
477  TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(name);
478  if (old && old->IsOnHeap()) {
479  Warning("Constructor","Deleting canvas with same name: %s",name);
480  delete old;
481  }
482  if (gROOT->IsBatch()) { //We are in Batch mode
483  fWindowTopX = fWindowTopY = 0;
484  fWindowWidth = ww;
485  fWindowHeight = wh;
486  fCw = ww;
487  fCh = wh;
489  if (!fCanvasImp) return;
490  fBatch = kTRUE;
491  } else { //normal mode with a screen window
493  fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, Int_t(cx*wtopx), Int_t(cx*wtopy), UInt_t(cx*ww), UInt_t(cx*wh));
494  if (!fCanvasImp) return;
495 
496  if (!gROOT->IsBatch() && fCanvasID == -1)
498 
500  fBatch = kFALSE;
501  }
502 
503  CreatePainter();
504 
505  SetName(name);
506  SetTitle(title); // requires fCanvasImp set
507  Build();
508 
509  // Popup canvas
510  fCanvasImp->Show();
511 }
512 
513 ////////////////////////////////////////////////////////////////////////////////
514 /// Initialize the TCanvas members. Called by all constructors.
515 
517 {
518  // Make sure the application environment exists. It is need for graphics
519  // (colors are initialized in the TApplication ctor).
520  if (!gApplication)
522 
523  // Load and initialize graphics libraries if
524  // TApplication::NeedGraphicsLibs() has been called by a
525  // library static initializer.
526  if (gApplication)
528 
529  // Get some default from .rootrc. Used in fCanvasImp->InitWindow().
530  fHighLightColor = gEnv->GetValue("Canvas.HighLightColor", kRed);
531  SetBit(kMoveOpaque, gEnv->GetValue("Canvas.MoveOpaque", 0));
532  SetBit(kResizeOpaque, gEnv->GetValue("Canvas.ResizeOpaque", 0));
533  if (gEnv->GetValue("Canvas.ShowEventStatus", kFALSE)) SetBit(kShowEventStatus);
534  if (gEnv->GetValue("Canvas.ShowToolTips", kFALSE)) SetBit(kShowToolTips);
535  if (gEnv->GetValue("Canvas.ShowToolBar", kFALSE)) SetBit(kShowToolBar);
536  if (gEnv->GetValue("Canvas.ShowEditor", kFALSE)) SetBit(kShowEditor);
537  if (gEnv->GetValue("Canvas.AutoExec", kTRUE)) SetBit(kAutoExec);
538 
539  // Fill canvas ROOT data structure
540  fXsizeUser = 0;
541  fYsizeUser = 0;
544 
545  fDISPLAY = "$DISPLAY";
546  fUpdating = kFALSE;
547  fRetained = kTRUE;
548  fSelected = 0;
549  fClickSelected = 0;
550  fSelectedX = 0;
551  fSelectedY = 0;
552  fSelectedPad = 0;
554  fPadSave = 0;
555  fEvent = -1;
556  fEventX = -1;
557  fEventY = -1;
558  fContextMenu = 0;
559  fDrawn = kFALSE;
560 }
561 
562 ////////////////////////////////////////////////////////////////////////////////
563 /// Build a canvas. Called by all constructors.
564 
566 {
567  // Get window identifier
568  if (fCanvasID == -1 && fCanvasImp)
570  if (fCanvasID == -1) return;
571 
572  if (fCw !=0 && fCh !=0) {
575  }
576 
577  // Set Pad parameters
578  gPad = this;
579  fCanvas = this;
580  fMother = (TPad*)gPad;
581 
582  if (IsBatch()) {
583  // Make sure that batch interactive canvas sizes are the same
584  fCw -= 4;
585  fCh -= 28;
586  } else if (IsWeb()) {
587  // mark canvas as batch - avoid virtualx in many places
588  SetBatch(kTRUE);
589  } else {
590  //normal mode with a screen window
591  // Set default physical canvas attributes
592  //Should be done via gVirtualX, not via fPainter (at least now). No changes here.
593  gVirtualX->SelectWindow(fCanvasID);
594  gVirtualX->SetFillColor(1); //Set color index for fill area
595  gVirtualX->SetLineColor(1); //Set color index for lines
596  gVirtualX->SetMarkerColor(1); //Set color index for markers
597  gVirtualX->SetTextColor(1); //Set color index for text
598  // Clear workstation
599  gVirtualX->ClearWindow();
600 
601  // Set Double Buffer on by default
602  SetDoubleBuffer(1);
603 
604  // Get effective window parameters (with borders and menubar)
607 
608  // Get effective canvas parameters without borders
609  Int_t dum1, dum2;
610  gVirtualX->GetGeometry(fCanvasID, dum1, dum2, fCw, fCh);
611 
612  fContextMenu = new TContextMenu("ContextMenu");
613  }
614 
615  gROOT->GetListOfCanvases()->Add(this);
616 
617  if (!fPrimitives) {
618  fPrimitives = new TList;
620  SetFillStyle(1001);
632  fBorderMode=gStyle->GetCanvasBorderMode(); // do not call SetBorderMode (function redefined in TCanvas)
633  SetPad(0, 0, 1, 1);
634  Range(0, 0, 1, 1); //pad range is set by default to [0,1] in x and y
635 
637  if (vpp) vpp->SelectDrawable(fPixmapID);//gVirtualX->SelectPixmap(fPixmapID); //pixmap must be selected
638  PaintBorder(GetFillColor(), kTRUE); //paint background
639  }
640 
641  // transient canvases have typically no menubar and should not get
642  // by default the event status bar (if set by default)
643  if (TestBit(kMenuBar) && fCanvasImp) {
645  // ... and toolbar + editor
649  }
650 }
651 
652 ////////////////////////////////////////////////////////////////////////////////
653 /// Canvas destructor
654 
656 {
657  Destructor();
658 }
659 
660 ////////////////////////////////////////////////////////////////////////////////
661 /// Browse.
662 
664 {
665  Draw();
666  cd();
668 }
669 
670 ////////////////////////////////////////////////////////////////////////////////
671 /// Actual canvas destructor.
672 
674 {
675  if (gThreadXAR) {
676  void *arr[2];
677  arr[1] = this;
678  if ((*gThreadXAR)("CDEL", 2, arr, 0)) return;
679  }
680 
681  if (!TestBit(kNotDeleted)) return;
682 
683  if (fContextMenu) { delete fContextMenu; fContextMenu = 0; }
684  if (!gPad) return;
685 
686  Close();
687 
688  //If not yet (batch mode?).
689  delete fPainter;
690 }
691 
692 ////////////////////////////////////////////////////////////////////////////////
693 /// Set current canvas & pad. Returns the new current pad,
694 /// or 0 in case of failure.
695 /// See TPad::cd() for an explanation of the parameter.
696 
698 {
699  if (fCanvasID == -1) return 0;
700 
701  TPad::cd(subpadnumber);
702 
703  // in case doublebuffer is off, draw directly onto display window
704  if (!IsBatch()) {
705  if (!fDoubleBuffer)
706  gVirtualX->SelectWindow(fCanvasID);//Ok, does not matter for glpad.
707  }
708  return gPad;
709 }
710 
711 ////////////////////////////////////////////////////////////////////////////////
712 /// Remove all primitives from the canvas.
713 /// If option "D" is specified, direct sub-pads are cleared but not deleted.
714 /// This option is not recursive, i.e. pads in direct sub-pads are deleted.
715 
717 {
718  if (fCanvasID == -1) return;
719 
721 
722  TString opt = option;
723  opt.ToLower();
724  if (opt.Contains("d")) {
725  // clear subpads, but do not delete pads in case the canvas
726  // has been divided (note: option "D" is propagated so could cause
727  // conflicts for primitives using option "D" for something else)
728  if (fPrimitives) {
729  TIter next(fPrimitives);
730  TObject *obj;
731  while ((obj=next())) {
732  obj->Clear(option);
733  }
734  }
735  } else {
736  //default, clear everything in the canvas. Subpads are deleted
737  TPad::Clear(option); //Remove primitives from pad
738  }
739 
740  fSelected = 0;
741  fClickSelected = 0;
742  fSelectedPad = 0;
743  fClickSelectedPad = 0;
744 }
745 
746 ////////////////////////////////////////////////////////////////////////////////
747 /// Emit pad Cleared signal.
748 
750 {
751  Emit("Cleared(TVirtualPad*)", (Long_t)pad);
752 }
753 
754 ////////////////////////////////////////////////////////////////////////////////
755 /// Emit Closed signal.
756 
758 {
759  Emit("Closed()");
760 }
761 
762 ////////////////////////////////////////////////////////////////////////////////
763 /// Close canvas.
764 ///
765 /// Delete window/pads data structure
766 
768 {
769  TPad *padsave = (TPad*)gPad;
770  TCanvas *cansave = 0;
771  if (padsave) cansave = (TCanvas*)gPad->GetCanvas();
772 
773  if (fCanvasID != -1) {
774 
775  if ((!gROOT->IsLineProcessing()) && (!gVirtualX->IsCmdThread())) {
776  gInterpreter->Execute(this, IsA(), "Close", option);
777  return;
778  }
779 
781 
783 
784  cd();
785  TPad::Close(option);
786 
787  if (!IsBatch()) {
788  gVirtualX->SelectWindow(fCanvasID); //select current canvas
789 
791 
792  if (fCanvasImp)
793  fCanvasImp->Close();
794  }
795  fCanvasID = -1;
796  fBatch = kTRUE;
797 
798  gROOT->GetListOfCanvases()->Remove(this);
799 
800  // Close actual window on screen
802  }
803 
804  if (cansave == this) {
805  gPad = (TCanvas *) gROOT->GetListOfCanvases()->First();
806  } else {
807  gPad = padsave;
808  }
809 
810  Closed();
811 }
812 
813 ////////////////////////////////////////////////////////////////////////////////
814 /// Copy the canvas pixmap of the pad to the canvas.
815 
817 {
818  if (!IsBatch()) {
819  CopyPixmap();
821  }
822 }
823 
824 ////////////////////////////////////////////////////////////////////////////////
825 /// Draw a canvas.
826 /// If a canvas with the name is already on the screen, the canvas is repainted.
827 /// This function is useful when a canvas object has been saved in a Root file.
828 /// One can then do:
829 /// ~~~ {.cpp}
830 /// Root > Tfile f("file.root");
831 /// Root > canvas.Draw();
832 /// ~~~
833 
835 {
836  // Load and initialize graphics libraries if
837  // TApplication::NeedGraphicsLibs() has been called by a
838  // library static initializer.
839  if (gApplication)
841 
842  fDrawn = kTRUE;
843 
844  TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(GetName());
845  if (old == this) {
846  Paint();
847  return;
848  }
849  if (old) { gROOT->GetListOfCanvases()->Remove(old); delete old;}
850 
851  if (fWindowWidth == 0) {
852  if (fCw !=0) fWindowWidth = fCw+4;
853  else fWindowWidth = 800;
854  }
855  if (fWindowHeight == 0) {
856  if (fCh !=0) fWindowHeight = fCh+28;
857  else fWindowHeight = 600;
858  }
859  if (gROOT->IsBatch()) { //We are in Batch mode
861  if (!fCanvasImp) return;
862  fBatch = kTRUE;
863 
864  } else { //normal mode with a screen window
867  if (!fCanvasImp) return;
869  }
870  Build();
871  ResizePad();
873  fCanvasImp->Show();
874  Modified();
875 }
876 
877 ////////////////////////////////////////////////////////////////////////////////
878 /// Draw a clone of this canvas
879 /// A new canvas is created that is a clone of this canvas
880 
882 {
883  TCanvas *newCanvas = (TCanvas*)Clone();
884  newCanvas->SetName();
885 
886  newCanvas->Draw(option);
887  newCanvas->Update();
888  return newCanvas;
889 }
890 
891 ////////////////////////////////////////////////////////////////////////////////
892 /// Draw a clone of this canvas into the current pad
893 /// In an interactive session, select the destination/current pad
894 /// with the middle mouse button, then point to the canvas area to select
895 /// the canvas context menu item DrawClonePad.
896 /// Note that the original canvas may have subpads.
897 
899 {
900  TPad *padsav = (TPad*)gPad;
901  TPad *selpad = (TPad*)gROOT->GetSelectedPad();
902  TPad *pad = padsav;
903  if (pad == this) pad = selpad;
904  if (padsav == 0 || pad == 0 || pad == this) {
905  TCanvas *newCanvas = (TCanvas*)DrawClone();
907  return newCanvas;
908  }
909  if (fCanvasID == -1) {
912  if (!fCanvasImp) return 0;
915  }
916  this->cd();
917  TObject *obj, *clone;
918  //copy pad attributes
919  pad->Range(fX1,fY1,fX2,fY2);
920  pad->SetTickx(GetTickx());
921  pad->SetTicky(GetTicky());
922  pad->SetGridx(GetGridx());
923  pad->SetGridy(GetGridy());
924  pad->SetLogx(GetLogx());
925  pad->SetLogy(GetLogy());
926  pad->SetLogz(GetLogz());
929  TAttLine::Copy((TAttLine&)*pad);
930  TAttFill::Copy((TAttFill&)*pad);
931  TAttPad::Copy((TAttPad&)*pad);
932 
933  //copy primitives
934  TIter next(GetListOfPrimitives());
935  while ((obj=next())) {
936  pad->cd();
937  clone = obj->Clone();
938  pad->GetListOfPrimitives()->Add(clone,next.GetOption());
939  }
940  pad->ResizePad();
941  pad->Modified();
942  pad->Update();
943  if (padsav) padsav->cd();
944  return 0;
945 }
946 
947 ////////////////////////////////////////////////////////////////////////////////
948 /// Report name and title of primitive below the cursor.
949 ///
950 /// This function is called when the option "Event Status"
951 /// in the canvas menu "Options" is selected.
952 
953 void TCanvas::DrawEventStatus(Int_t event, Int_t px, Int_t py, TObject *selected)
954 {
955  const Int_t kTMAX=256;
956  static char atext[kTMAX];
957 
958  if (!TestBit(kShowEventStatus) || !selected) return;
959 
960  if (!fCanvasImp) return; //this may happen when closing a TAttCanvas
961 
962  TVirtualPad* savepad;
963  savepad = gPad;
964  gPad = GetSelectedPad();
965 
966  fCanvasImp->SetStatusText(selected->GetTitle(),0);
967  fCanvasImp->SetStatusText(selected->GetName(),1);
968  if (event == kKeyPress)
969  snprintf(atext, kTMAX, "%c", (char) px);
970  else
971  snprintf(atext, kTMAX, "%d,%d", px, py);
972  fCanvasImp->SetStatusText(atext,2);
973 
974  // Show date/time if TimeDisplay is selected
975  TAxis *xaxis = NULL;
976  if ( selected->InheritsFrom("TH1") )
977  xaxis = ((TH1*)selected)->GetXaxis();
978  else if ( selected->InheritsFrom("TGraph") )
979  xaxis = ((TGraph*)selected)->GetXaxis();
980  else if ( selected->InheritsFrom("TAxis") )
981  xaxis = (TAxis*)selected;
982  if ( xaxis != NULL && xaxis->GetTimeDisplay()) {
983  TString objinfo = selected->GetObjectInfo(px,py);
984  // check if user has overwritten GetObjectInfo and altered
985  // the default text from TObject::GetObjectInfo "x=.. y=.."
986  if (objinfo.Contains("x=") && objinfo.Contains("y=") ) {
987  UInt_t toff = 0;
988  TString time_format(xaxis->GetTimeFormat());
989  // TimeFormat may contain offset: %F2000-01-01 00:00:00
990  Int_t idF = time_format.Index("%F");
991  if (idF>=0) {
992  Int_t lnF = time_format.Length();
993  // minimal check for correct format
994  if (lnF - idF == 21) {
995  time_format = time_format(idF+2, lnF);
996  TDatime dtoff(time_format);
997  toff = dtoff.Convert();
998  }
999  } else {
1000  toff = (UInt_t)gStyle->GetTimeOffset();
1001  }
1002  TDatime dt((UInt_t)gPad->AbsPixeltoX(px) + toff);
1003  snprintf(atext, kTMAX, "%s, y=%g",
1004  dt.AsSQLString(),gPad->AbsPixeltoY(py));
1005  fCanvasImp->SetStatusText(atext,3);
1006  gPad = savepad;
1007  return;
1008  }
1009  }
1010  // default
1011  fCanvasImp->SetStatusText(selected->GetObjectInfo(px,py),3);
1012 
1013  gPad = savepad;
1014 }
1015 
1016 ////////////////////////////////////////////////////////////////////////////////
1017 /// Get editor bar.
1018 
1020 {
1022 }
1023 
1024 ////////////////////////////////////////////////////////////////////////////////
1025 /// Embedded a canvas into a TRootEmbeddedCanvas. This method is only called
1026 /// via TRootEmbeddedCanvas::AdoptCanvas.
1027 
1029 {
1030  // If fCanvasImp already exists, no need to go further.
1031  if(fCanvasImp) return;
1032 
1033  fCanvasID = winid;
1034  fWindowTopX = 0;
1035  fWindowTopY = 0;
1036  fWindowWidth = ww;
1037  fWindowHeight = wh;
1038  fCw = ww;
1039  fCh = wh;
1040  fBatch = kFALSE;
1041  fUpdating = kFALSE;
1042 
1044  if (!fCanvasImp) return;
1045  Build();
1046  Resize();
1047 }
1048 
1049 ////////////////////////////////////////////////////////////////////////////////
1050 /// Generate kMouseEnter and kMouseLeave events depending on the previously
1051 /// selected object and the currently selected object. Does nothing if the
1052 /// selected object does not change.
1053 
1054 void TCanvas::EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
1055 {
1056  if (prevSelObj == fSelected) return;
1057 
1058  TPad *padsav = (TPad *)gPad;
1059  Int_t sevent = fEvent;
1060 
1061  if (prevSelObj) {
1062  gPad = prevSelPad;
1063  prevSelObj->ExecuteEvent(kMouseLeave, fEventX, fEventY);
1064  fEvent = kMouseLeave;
1065  RunAutoExec();
1066  ProcessedEvent(kMouseLeave, fEventX, fEventY, prevSelObj); // emit signal
1067  }
1068 
1069  gPad = fSelectedPad;
1070 
1071  if (fSelected) {
1073  fEvent = kMouseEnter;
1074  RunAutoExec();
1075  ProcessedEvent(kMouseEnter, fEventX, fEventY, fSelected); // emit signal
1076  }
1077 
1078  fEvent = sevent;
1079  gPad = padsav;
1080 }
1081 
1082 ////////////////////////////////////////////////////////////////////////////////
1083 /// Execute action corresponding to one event.
1084 ///
1085 /// This member function must be implemented to realize the action
1086 /// corresponding to the mouse click on the object in the canvas
1087 ///
1088 /// Only handle mouse motion events in TCanvas, all other events are
1089 /// ignored for the time being
1090 
1092 {
1093  if (gROOT->GetEditorMode()) {
1094  TPad::ExecuteEvent(event,px,py);
1095  return;
1096  }
1097 
1098  switch (event) {
1099 
1100  case kMouseMotion:
1101  SetCursor(kCross);
1102  break;
1103  }
1104 }
1105 
1106 ////////////////////////////////////////////////////////////////////////////////
1107 /// Turn rubberband feedback mode on or off.
1108 
1110 {
1111  if (set) {
1112  SetDoubleBuffer(0); // turn off double buffer mode
1113  gVirtualX->SetDrawMode(TVirtualX::kInvert); // set the drawing mode to XOR mode
1114  } else {
1115  SetDoubleBuffer(1); // turn on double buffer mode
1116  gVirtualX->SetDrawMode(TVirtualX::kCopy); // set drawing mode back to normal (copy) mode
1117  }
1118 }
1119 
1120 ////////////////////////////////////////////////////////////////////////////////
1121 /// Flush canvas buffers.
1122 
1124 {
1125  if ((fCanvasID == -1) || IsWeb()) return;
1126 
1127  TPad *padsav = (TPad*)gPad;
1128  cd();
1129  if (!IsBatch()) {
1130  if (!UseGL()) {
1131  gVirtualX->SelectWindow(fCanvasID);
1132  gPad = padsav; //don't do cd() because than also the pixmap is changed
1133  CopyPixmaps();
1134  gVirtualX->UpdateWindow(1);
1135  } else {
1136  TVirtualPS *tvps = gVirtualPS;
1137  gVirtualPS = 0;
1138  gGLManager->MakeCurrent(fGLDevice);
1139  fPainter->InitPainter();
1140  Paint();
1141  if (padsav && padsav->GetCanvas() == this) {
1142  padsav->cd();
1143  padsav->HighLight(padsav->GetHighLightColor());
1144  //cd();
1145  }
1146  fPainter->LockPainter();
1147  gGLManager->Flush(fGLDevice);
1148  gVirtualPS = tvps;
1149  }
1150  }
1151  if (padsav) padsav->cd();
1152 }
1153 
1154 ////////////////////////////////////////////////////////////////////////////////
1155 /// Force a copy of current style for all objects in canvas.
1156 
1158 {
1159  if ((!gROOT->IsLineProcessing()) && (!gVirtualX->IsCmdThread())) {
1160  gInterpreter->Execute(this, IsA(), "UseCurrentStyle", "");
1161  return;
1162  }
1163 
1165 
1167 
1168  if (gStyle->IsReading()) {
1172  } else {
1176  }
1177 }
1178 
1179 ////////////////////////////////////////////////////////////////////////////////
1180 /// Returns current top x position of window on screen.
1181 
1183 {
1186 
1187  return fWindowTopX;
1188 }
1189 
1190 ////////////////////////////////////////////////////////////////////////////////
1191 /// Returns current top y position of window on screen.
1192 
1194 {
1197 
1198  return fWindowTopY;
1199 }
1200 
1201 ////////////////////////////////////////////////////////////////////////////////
1202 /// Handle Input Events.
1203 ///
1204 /// Handle input events, like button up/down in current canvas.
1205 
1207 {
1208  TPad *pad;
1209  TPad *prevSelPad = (TPad*) fSelectedPad;
1210  TObject *prevSelObj = fSelected;
1211 
1212  fPadSave = (TPad*)gPad;
1213  cd(); // make sure this canvas is the current canvas
1214 
1215  fEvent = event;
1216  fEventX = px;
1217  fEventY = py;
1218 
1219  switch (event) {
1220 
1221  case kMouseMotion:
1222  // highlight object tracked over
1223  pad = Pick(px, py, prevSelObj);
1224  if (!pad) return;
1225 
1226  EnterLeave(prevSelPad, prevSelObj);
1227 
1228  gPad = pad; // don't use cd() we will use the current
1229  // canvas via the GetCanvas member and not via
1230  // gPad->GetCanvas
1231 
1232  if (fSelected) {
1233  fSelected->ExecuteEvent(event, px, py);
1234  RunAutoExec();
1235  }
1236 
1237  break;
1238 
1239  case kMouseEnter:
1240  // mouse enters canvas
1242  break;
1243 
1244  case kMouseLeave:
1245  // mouse leaves canvas
1246  {
1247  // force popdown of tooltips
1248  TObject *sobj = fSelected;
1249  TPad *spad = fSelectedPad;
1250  fSelected = 0;
1251  fSelectedPad = 0;
1252  EnterLeave(prevSelPad, prevSelObj);
1253  fSelected = sobj;
1254  fSelectedPad = spad;
1256  }
1257  break;
1258 
1259  case kButton1Double:
1260  // triggered on the second button down within 350ms and within
1261  // 3x3 pixels of the first button down, button up finishes action
1262 
1263  case kButton1Down:
1264  // find pad in which input occurred
1265  pad = Pick(px, py, prevSelObj);
1266  if (!pad) return;
1267 
1268  gPad = pad; // don't use cd() because we won't draw in pad
1269  // we will only use its coordinate system
1270 
1271  if (fSelected) {
1272  FeedbackMode(kTRUE); // to draw in rubberband mode
1273  fSelected->ExecuteEvent(event, px, py);
1274 
1275  RunAutoExec();
1276  }
1277 
1278  break;
1279 
1280  case kArrowKeyPress:
1281  case kArrowKeyRelease:
1282  case kButton1Motion:
1283  case kButton1ShiftMotion: //8 == kButton1Motion + shift modifier
1284  if (fSelected) {
1285  gPad = fSelectedPad;
1286 
1287  fSelected->ExecuteEvent(event, px, py);
1288  gVirtualX->Update();
1290  Bool_t resize = kFALSE;
1292  resize = ((TBox*)fSelected)->IsBeingResized();
1294  resize = ((TVirtualPad*)fSelected)->IsBeingResized();
1295 
1296  if ((!resize && TestBit(kMoveOpaque)) || (resize && TestBit(kResizeOpaque))) {
1297  gPad = fPadSave;
1298  Update();
1300  }
1301  }
1302 
1303  RunAutoExec();
1304  }
1305 
1306  break;
1307 
1308  case kButton1Up:
1309 
1310  if (fSelected) {
1311  gPad = fSelectedPad;
1312 
1313  fSelected->ExecuteEvent(event, px, py);
1314 
1315  RunAutoExec();
1316 
1317  if (fPadSave)
1318  gPad = fPadSave;
1319  else {
1320  gPad = this;
1321  fPadSave = this;
1322  }
1323 
1324  Update(); // before calling update make sure gPad is reset
1325  }
1326  break;
1327 
1328 //*-*----------------------------------------------------------------------
1329 
1330  case kButton2Down:
1331  // find pad in which input occurred
1332  pad = Pick(px, py, prevSelObj);
1333  if (!pad) return;
1334 
1335  gPad = pad; // don't use cd() because we won't draw in pad
1336  // we will only use its coordinate system
1337 
1339 
1340  if (fSelected) fSelected->Pop(); // pop object to foreground
1341  pad->cd(); // and make its pad the current pad
1342  if (gDebug)
1343  printf("Current Pad: %s / %s\n", pad->GetName(), pad->GetTitle());
1344 
1345  // loop over all canvases to make sure that only one pad is highlighted
1346  {
1347  TIter next(gROOT->GetListOfCanvases());
1348  TCanvas *tc;
1349  while ((tc = (TCanvas *)next()))
1350  tc->Update();
1351  }
1352 
1353  //if (pad->GetGLDevice() != -1 && fSelected)
1354  // fSelected->ExecuteEvent(event, px, py);
1355 
1356  break; // don't want fPadSave->cd() to be executed at the end
1357 
1358  case kButton2Motion:
1359  //was empty!
1360  case kButton2Up:
1361  if (fSelected) {
1362  gPad = fSelectedPad;
1363 
1364  fSelected->ExecuteEvent(event, px, py);
1365  RunAutoExec();
1366  }
1367  break;
1368 
1369  case kButton2Double:
1370  break;
1371 
1372 //*-*----------------------------------------------------------------------
1373 
1374  case kButton3Down:
1375  // popup context menu
1376  pad = Pick(px, py, prevSelObj);
1377  if (!pad) return;
1378 
1380 
1383  fContextMenu->Popup(px, py, fSelected, this, pad);
1384 
1385  break;
1386 
1387  case kButton3Motion:
1388  break;
1389 
1390  case kButton3Up:
1392  break;
1393 
1394  case kButton3Double:
1395  break;
1396 
1397  case kKeyPress:
1398  if (!fSelectedPad || !fSelected) return;
1399  gPad = fSelectedPad; // don't use cd() because we won't draw in pad
1400  // we will only use its coordinate system
1401  fSelected->ExecuteEvent(event, px, py);
1402 
1403  RunAutoExec();
1404 
1405  break;
1406 
1407  case kButton1Shift:
1408  // Try to select
1409  pad = Pick(px, py, prevSelObj);
1410 
1411  if (!pad) return;
1412 
1413  EnterLeave(prevSelPad, prevSelObj);
1414 
1415  gPad = pad; // don't use cd() we will use the current
1416  // canvas via the GetCanvas member and not via
1417  // gPad->GetCanvas
1418  if (fSelected) {
1419  fSelected->ExecuteEvent(event, px, py);
1420  RunAutoExec();
1421  }
1422  break;
1423 
1424  case kWheelUp:
1425  case kWheelDown:
1426  pad = Pick(px, py, prevSelObj);
1427  if (!pad) return;
1428 
1429  gPad = pad;
1430  if (fSelected)
1431  fSelected->ExecuteEvent(event, px, py);
1432  break;
1433 
1434  default:
1435  break;
1436  }
1437 
1438  if (fPadSave && event != kButton2Down)
1439  fPadSave->cd();
1440 
1441  if (event != kMouseLeave) { // signal was already emitted for this event
1442  ProcessedEvent(event, px, py, fSelected); // emit signal
1443  DrawEventStatus(event, px, py, fSelected);
1444  }
1445 }
1446 
1447 ////////////////////////////////////////////////////////////////////////////////
1448 /// Is folder ?
1449 
1451 {
1452  return fgIsFolder;
1453 }
1454 
1455 ////////////////////////////////////////////////////////////////////////////////
1456 /// List all pads.
1457 
1458 void TCanvas::ls(Option_t *option) const
1459 {
1461  std::cout <<"Canvas Name=" <<GetName()<<" Title="<<GetTitle()<<" Option="<<option<<std::endl;
1463  TPad::ls(option);
1465 }
1466 
1467 ////////////////////////////////////////////////////////////////////////////////
1468 /// Static function to build a default canvas.
1469 
1471 {
1472  const char *defcanvas = gROOT->GetDefCanvasName();
1473  char *cdef;
1474 
1475  auto lc = (TList*)gROOT->GetListOfCanvases();
1476  if (lc->FindObject(defcanvas)) {
1477  Int_t n = lc->GetSize() + 1;
1478  cdef = new char[strlen(defcanvas)+15];
1479  do {
1480  strlcpy(cdef,Form("%s_n%d", defcanvas, n++),strlen(defcanvas)+15);
1481  } while (lc->FindObject(cdef));
1482  } else
1483  cdef = StrDup(Form("%s",defcanvas));
1484 
1485  TCanvas *c = new TCanvas(cdef, cdef, 1);
1486 
1487  ::Info("TCanvas::MakeDefCanvas"," created default TCanvas with name %s",cdef);
1488  delete [] cdef;
1489  return c;
1490 }
1491 
1492 ////////////////////////////////////////////////////////////////////////////////
1493 /// Set option to move objects/pads in a canvas.
1494 ///
1495 /// - set = 1 (default) graphics objects are moved in opaque mode
1496 /// - set = 0 only the outline of objects is drawn when moving them
1497 ///
1498 /// The option opaque produces the best effect. It requires however a
1499 /// a reasonably fast workstation or response time.
1500 
1502 {
1503  SetBit(kMoveOpaque,set);
1504 }
1505 
1506 ////////////////////////////////////////////////////////////////////////////////
1507 /// Paint canvas.
1508 
1510 {
1511  if (fCanvas)
1512  TPad::Paint(option);
1513 }
1514 
1515 ////////////////////////////////////////////////////////////////////////////////
1516 /// Prepare for pick, call TPad::Pick() and when selected object
1517 /// is different from previous then emit Picked() signal.
1518 
1519 TPad *TCanvas::Pick(Int_t px, Int_t py, TObject *prevSelObj)
1520 {
1521  TObjLink *pickobj = 0;
1522 
1523  fSelected = 0;
1524  fSelectedOpt = "";
1525  fSelectedPad = 0;
1526 
1527  TPad *pad = Pick(px, py, pickobj);
1528  if (!pad) return 0;
1529 
1530  if (!pickobj) {
1531  fSelected = pad;
1532  fSelectedOpt = "";
1533  } else {
1534  if (!fSelected) { // can be set via TCanvas::SetSelected()
1535  fSelected = pickobj->GetObject();
1536  fSelectedOpt = pickobj->GetOption();
1537  }
1538  }
1539  fSelectedPad = pad;
1540 
1541  if (fSelected != prevSelObj)
1542  Picked(fSelectedPad, fSelected, fEvent); // emit signal
1543 
1544  if ((fEvent == kButton1Down) || (fEvent == kButton2Down) || (fEvent == kButton3Down)) {
1548  Selected(fSelectedPad, fSelected, fEvent); // emit signal
1549  fSelectedX = px;
1550  fSelectedY = py;
1551  }
1552  }
1553  return pad;
1554 }
1555 
1556 ////////////////////////////////////////////////////////////////////////////////
1557 /// Emit Picked() signal.
1558 
1559 void TCanvas::Picked(TPad *pad, TObject *obj, Int_t event)
1560 {
1561  Long_t args[3];
1562 
1563  args[0] = (Long_t) pad;
1564  args[1] = (Long_t) obj;
1565  args[2] = event;
1566 
1567  Emit("Picked(TPad*,TObject*,Int_t)", args);
1568 }
1569 
1570 ////////////////////////////////////////////////////////////////////////////////
1571 /// Emit Highlighted() signal.
1572 ///
1573 /// - pad is pointer to pad with highlighted histogram or graph
1574 /// - obj is pointer to highlighted histogram or graph
1575 /// - x is highlighted x bin for 1D histogram or highlighted x-th point for graph
1576 /// - y is highlighted y bin for 2D histogram (for 1D histogram or graph not in use)
1577 
1579 {
1580  Long_t args[4];
1581 
1582  args[0] = (Long_t) pad;
1583  args[1] = (Long_t) obj;
1584  args[2] = x;
1585  args[3] = y;
1586 
1587  Emit("Highlighted(TVirtualPad*,TObject*,Int_t,Int_t)", args);
1588 }
1589 
1590 ////////////////////////////////////////////////////////////////////////////////
1591 /// This is "simplification" for function TCanvas::Connect with Highlighted
1592 /// signal for specific slot.
1593 ///
1594 /// Slot has to be defined "UserFunction(TVirtualPad *pad, TObject *obj, Int_t x, Int_t y)"
1595 /// all parameters of UserFunction are taken from TCanvas::Highlighted
1596 
1597 void TCanvas::HighlightConnect(const char *slot)
1598 {
1599  Connect("Highlighted(TVirtualPad*,TObject*,Int_t,Int_t)", 0, 0, slot);
1600 }
1601 
1602 ////////////////////////////////////////////////////////////////////////////////
1603 /// Emit Selected() signal.
1604 
1606 {
1607  Long_t args[3];
1608 
1609  args[0] = (Long_t) pad;
1610  args[1] = (Long_t) obj;
1611  args[2] = event;
1612 
1613  Emit("Selected(TVirtualPad*,TObject*,Int_t)", args);
1614 }
1615 
1616 ////////////////////////////////////////////////////////////////////////////////
1617 /// Emit ProcessedEvent() signal.
1618 
1620 {
1621  Long_t args[4];
1622 
1623  args[0] = event;
1624  args[1] = x;
1625  args[2] = y;
1626  args[3] = (Long_t) obj;
1627 
1628  Emit("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", args);
1629 }
1630 
1631 ////////////////////////////////////////////////////////////////////////////////
1632 /// Recompute canvas parameters following a X11 Resize.
1633 
1635 {
1636  if (fCanvasID == -1) return;
1637 
1638  if ((!gROOT->IsLineProcessing()) && (!gVirtualX->IsCmdThread())) {
1639  gInterpreter->Execute(this, IsA(), "Resize", "");
1640  return;
1641  }
1642 
1644 
1645  TPad *padsav = (TPad*)gPad;
1646  cd();
1647 
1648  if (!IsBatch()) {
1649  gVirtualX->SelectWindow(fCanvasID); //select current canvas
1650  gVirtualX->ResizeWindow(fCanvasID); //resize canvas and off-screen buffer
1651 
1652  // Get effective window parameters including menubar and borders
1655 
1656  // Get effective canvas parameters without borders
1657  Int_t dum1, dum2;
1658  gVirtualX->GetGeometry(fCanvasID, dum1, dum2, fCw, fCh);
1659  }
1660 
1661  if (fXsizeUser && fYsizeUser) {
1662  UInt_t nwh = fCh;
1663  UInt_t nww = fCw;
1665  if (rxy < 1) {
1666  UInt_t twh = UInt_t(Double_t(fCw)/rxy);
1667  if (twh > fCh)
1668  nww = UInt_t(Double_t(fCh)*rxy);
1669  else
1670  nwh = twh;
1671  if (nww > fCw) {
1672  nww = fCw; nwh = twh;
1673  }
1674  if (nwh > fCh) {
1675  nwh = fCh; nww = UInt_t(Double_t(fCh)/rxy);
1676  }
1677  } else {
1678  UInt_t twh = UInt_t(Double_t(fCw)*rxy);
1679  if (twh > fCh)
1680  nwh = UInt_t(Double_t(fCw)/rxy);
1681  else
1682  nww = twh;
1683  if (nww > fCw) {
1684  nww = fCw; nwh = twh;
1685  }
1686  if (nwh > fCh) {
1687  nwh = fCh; nww = UInt_t(Double_t(fCh)*rxy);
1688  }
1689  }
1690  fCw = nww;
1691  fCh = nwh;
1692  }
1693 
1694  if (fCw < fCh) {
1697  }
1698  else {
1701  }
1702 
1703 //*-*- Loop on all pads to recompute conversion coefficients
1704  TPad::ResizePad();
1705 
1706  if (padsav) padsav->cd();
1707 }
1708 
1709 ////////////////////////////////////////////////////////////////////////////////
1710 /// Set option to resize objects/pads in a canvas.
1711 ///
1712 /// - set = 1 (default) graphics objects are resized in opaque mode
1713 /// - set = 0 only the outline of objects is drawn when resizing them
1714 ///
1715 /// The option opaque produces the best effect. It requires however a
1716 /// a reasonably fast workstation or response time.
1717 
1719 {
1720  SetBit(kResizeOpaque,set);
1721 }
1722 
1723 ////////////////////////////////////////////////////////////////////////////////
1724 /// Execute the list of TExecs in the current pad.
1725 
1727 {
1728  if (!TestBit(kAutoExec)) return;
1729  if (!gPad) return;
1730  ((TPad*)gPad)->AutoExec();
1731 }
1732 
1733 
1734 ////////////////////////////////////////////////////////////////////////////////
1735 /// Save primitives in this canvas in C++ macro file with GUI.
1736 
1737 void TCanvas::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1738 {
1739  // Write canvas options (in $TROOT or $TStyle)
1740  if (gStyle->GetOptFit()) {
1741  out<<" gStyle->SetOptFit(1);"<<std::endl;
1742  }
1743  if (!gStyle->GetOptStat()) {
1744  out<<" gStyle->SetOptStat(0);"<<std::endl;
1745  }
1746  if (!gStyle->GetOptTitle()) {
1747  out<<" gStyle->SetOptTitle(0);"<<std::endl;
1748  }
1749  if (gROOT->GetEditHistograms()) {
1750  out<<" gROOT->SetEditHistograms();"<<std::endl;
1751  }
1752  if (GetShowEventStatus()) {
1753  out<<" "<<GetName()<<"->ToggleEventStatus();"<<std::endl;
1754  }
1755  if (GetShowToolTips()) {
1756  out<<" "<<GetName()<<"->ToggleToolTips();"<<std::endl;
1757  }
1758  if (GetShowToolBar()) {
1759  out<<" "<<GetName()<<"->ToggleToolBar();"<<std::endl;
1760  }
1761  if (GetHighLightColor() != 5) {
1762  if (GetHighLightColor() > 228) {
1764  out<<" "<<GetName()<<"->SetHighLightColor(ci);" << std::endl;
1765  } else
1766  out<<" "<<GetName()<<"->SetHighLightColor("<<GetHighLightColor()<<");"<<std::endl;
1767  }
1768 
1769  // Now recursively scan all pads of this canvas
1770  cd();
1771  TPad::SavePrimitive(out,option);
1772 }
1773 
1774 ////////////////////////////////////////////////////////////////////////////////
1775 /// Save primitives in this canvas as a C++ macro file.
1776 /// This function loops on all the canvas primitives and for each primitive
1777 /// calls the object SavePrimitive function.
1778 /// When outputting floating point numbers, the default precision is 7 digits.
1779 /// The precision can be changed (via system.rootrc) by changing the value
1780 /// of the environment variable "Canvas.SavePrecision"
1781 
1782 void TCanvas::SaveSource(const char *filename, Option_t *option)
1783 {
1784  // reset bit TClass::kClassSaved for all classes
1785  TIter next(gROOT->GetListOfClasses());
1786  TClass *cl;
1787  while((cl = (TClass*)next())) {
1789  }
1790 
1791  char quote = '"';
1792  std::ofstream out;
1793  Int_t lenfile = strlen(filename);
1794  char * fname;
1795  char lcname[10];
1796  const char *cname = GetName();
1797  Bool_t invalid = kFALSE;
1798  // if filename is given, open this file, otherwise create a file
1799  // with a name equal to the canvasname.C
1800  if (lenfile) {
1801  fname = (char*)filename;
1802  out.open(fname, std::ios::out);
1803  } else {
1804  Int_t nch = strlen(cname);
1805  if (nch < 10) {
1806  strlcpy(lcname,cname,10);
1807  for (Int_t k=1;k<=nch;k++) {if (lcname[nch-k] == ' ') lcname[nch-k] = 0;}
1808  if (lcname[0] == 0) {invalid = kTRUE; strlcpy(lcname,"c1",10); nch = 2;}
1809  cname = lcname;
1810  }
1811  fname = new char[nch+3];
1812  strlcpy(fname,cname,nch+3);
1813  strncat(fname,".C",3);
1814  out.open(fname, std::ios::out);
1815  }
1816  if (!out.good ()) {
1817  Error("SaveSource", "Cannot open file: %s",fname);
1818  if (!lenfile) delete [] fname;
1819  return;
1820  }
1821 
1822  //set precision
1823  Int_t precision = gEnv->GetValue("Canvas.SavePrecision",7);
1824  out.precision(precision);
1825 
1826  // Write macro header and date/time stamp
1827  TDatime t;
1828  Float_t cx = gStyle->GetScreenFactor();
1829  Int_t topx,topy;
1830  UInt_t w, h;
1831  if (!fCanvasImp) {
1832  Error("SaveSource", "Cannot open TCanvas");
1833  return;
1834  }
1835  UInt_t editorWidth = fCanvasImp->GetWindowGeometry(topx,topy,w,h);
1836  w = UInt_t((fWindowWidth - editorWidth)/cx);
1837  h = UInt_t((fWindowHeight)/cx);
1838  topx = GetWindowTopX();
1839  topy = GetWindowTopY();
1840 
1841  if (w == 0) {
1842  w = GetWw()+4; h = GetWh()+4;
1843  topx = 1; topy = 1;
1844  }
1845 
1846  TString mname(fname);
1847 // out <<"#ifdef __CLING__"<<std::endl;
1848 // out <<"#pragma cling optimize(0)"<<std::endl;
1849 // out <<"#endif"<<std::endl;
1850 // out <<""<<std::endl;
1851  Int_t p = mname.Last('.');
1852  Int_t s = mname.Last('/')+1;
1853 
1854  // A named macro is generated only if the function name is valid. If not, the
1855  // macro is unnamed.
1856  TString first(mname(s,s+1));
1857  if (!first.IsDigit()) out <<"void " << mname(s,p-s) << "()" << std::endl;
1858 
1859  out <<"{"<<std::endl;
1860  out <<"//=========Macro generated from canvas: "<<GetName()<<"/"<<GetTitle()<<std::endl;
1861  out <<"//========= ("<<t.AsString()<<") by ROOT version "<<gROOT->GetVersion()<<std::endl;
1862 
1863  if (gStyle->GetCanvasPreferGL())
1864  out <<std::endl<<" gStyle->SetCanvasPreferGL(kTRUE);"<<std::endl<<std::endl;
1865 
1866  // Write canvas parameters (TDialogCanvas case)
1868  out<<" "<<ClassName()<<" *"<<cname<<" = new "<<ClassName()<<"("<<quote<<GetName()
1869  <<quote<<", "<<quote<<GetTitle()<<quote<<","<<w<<","<<h<<");"<<std::endl;
1870  } else {
1871  // Write canvas parameters (TCanvas case)
1872  out<<" TCanvas *"<<cname<<" = new TCanvas("<<quote<<GetName()<<quote<<", "<<quote<<GetTitle()
1873  <<quote;
1874  if (!HasMenuBar())
1875  out<<",-"<<topx<<","<<topy<<","<<w<<","<<h<<");"<<std::endl;
1876  else
1877  out<<","<<topx<<","<<topy<<","<<w<<","<<h<<");"<<std::endl;
1878  }
1879  // Write canvas options (in $TROOT or $TStyle)
1880  if (gStyle->GetOptFit()) {
1881  out<<" gStyle->SetOptFit(1);"<<std::endl;
1882  }
1883  if (!gStyle->GetOptStat()) {
1884  out<<" gStyle->SetOptStat(0);"<<std::endl;
1885  }
1886  if (!gStyle->GetOptTitle()) {
1887  out<<" gStyle->SetOptTitle(0);"<<std::endl;
1888  }
1889  if (gROOT->GetEditHistograms()) {
1890  out<<" gROOT->SetEditHistograms();"<<std::endl;
1891  }
1892  if (GetShowEventStatus()) {
1893  out<<" "<<GetName()<<"->ToggleEventStatus();"<<std::endl;
1894  }
1895  if (GetShowToolTips()) {
1896  out<<" "<<GetName()<<"->ToggleToolTips();"<<std::endl;
1897  }
1898  if (GetHighLightColor() != 5) {
1899  if (GetHighLightColor() > 228) {
1901  out<<" "<<GetName()<<"->SetHighLightColor(ci);" << std::endl;
1902  } else
1903  out<<" "<<GetName()<<"->SetHighLightColor("<<GetHighLightColor()<<");"<<std::endl;
1904  }
1905 
1906  // Now recursively scan all pads of this canvas
1907  cd();
1908  if (invalid) SetName("c1");
1909  TPad::SavePrimitive(out,option);
1910  // Write canvas options related to pad editor
1911  out<<" "<<GetName()<<"->SetSelected("<<GetName()<<");"<<std::endl;
1912  if (GetShowToolBar()) {
1913  out<<" "<<GetName()<<"->ToggleToolBar();"<<std::endl;
1914  }
1915  if (invalid) SetName(" ");
1916 
1917  out <<"}"<<std::endl;
1918  out.close();
1919  Info("SaveSource","C++ Macro file: %s has been generated", fname);
1920 
1921  // reset bit TClass::kClassSaved for all classes
1922  next.Reset();
1923  while((cl = (TClass*)next())) {
1924  cl->ResetBit(TClass::kClassSaved);
1925  }
1926  if (!lenfile) delete [] fname;
1927 }
1928 
1929 ////////////////////////////////////////////////////////////////////////////////
1930 /// Toggle batch mode. However, if the canvas is created without a window
1931 /// then batch mode always stays set.
1932 
1934 {
1935  if (gROOT->IsBatch() || IsWeb())
1936  fBatch = kTRUE;
1937  else
1938  fBatch = batch;
1939 }
1940 
1941 ////////////////////////////////////////////////////////////////////////////////
1942 /// Set Width and Height of canvas to ww and wh respectively. If ww and/or wh
1943 /// are greater than the current canvas window a scroll bar is automatically
1944 /// generated. Use this function to zoom in a canvas and navigate via
1945 /// the scroll bars. The Width and Height in this method are different from those
1946 /// given in the TCanvas constructors where these two dimension include the size
1947 /// of the window decoration whereas they do not in this method.
1948 
1950 {
1951  if (fCanvasImp) {
1952  fCanvasImp->SetCanvasSize(ww, wh);
1953  fCw = ww;
1954  fCh = wh;
1955  ResizePad();
1956  }
1957 }
1958 
1959 ////////////////////////////////////////////////////////////////////////////////
1960 /// Set cursor.
1961 
1963 {
1964  if (IsBatch()) return;
1965  gVirtualX->SetCursor(fCanvasID, cursor);
1966 }
1967 
1968 ////////////////////////////////////////////////////////////////////////////////
1969 /// Set Double Buffer On/Off.
1970 
1972 {
1973  if (IsBatch()) return;
1974  fDoubleBuffer = mode;
1975  gVirtualX->SetDoubleBuffer(fCanvasID, mode);
1976 
1977  // depending of the buffer mode set the drawing window to either
1978  // the canvas pixmap or to the canvas on-screen window
1979  if (fDoubleBuffer) {
1981  } else
1983 }
1984 
1985 ////////////////////////////////////////////////////////////////////////////////
1986 /// Fix canvas aspect ratio to current value if fixed is true.
1987 
1989 {
1990  if (fixed) {
1991  if (!fFixedAspectRatio) {
1992  if (fCh != 0)
1994  else {
1995  Error("SetAspectRatio", "cannot fix aspect ratio, height of canvas is 0");
1996  return;
1997  }
1999  }
2000  } else {
2002  fAspectRatio = 0;
2003  }
2004 }
2005 
2006 ////////////////////////////////////////////////////////////////////////////////
2007 /// If isfolder=kTRUE, the canvas can be browsed like a folder
2008 /// by default a canvas is not browsable.
2009 
2011 {
2012  fgIsFolder = isfolder;
2013 }
2014 
2015 ////////////////////////////////////////////////////////////////////////////////
2016 /// Set canvas name. In case `name` is an empty string, a default name is set.
2017 
2018 void TCanvas::SetName(const char *name)
2019 {
2020  if (!name || !name[0]) {
2021  const char *defcanvas = gROOT->GetDefCanvasName();
2022  char *cdef;
2023  auto lc = (TList*)gROOT->GetListOfCanvases();
2024  if (lc->FindObject(defcanvas)) {
2025  cdef = Form("%s_n%d",defcanvas,lc->GetSize()+1);
2026  } else {
2027  cdef = Form("%s",defcanvas);
2028  }
2029  fName = cdef;
2030  } else {
2031  fName = name;
2032  }
2033  if (gPad && TestBit(kMustCleanup)) gPad->Modified();
2034 }
2035 
2036 ////////////////////////////////////////////////////////////////////////////////
2037 /// Set selected canvas.
2038 
2040 {
2041  fSelected = obj;
2042  if (obj) obj->SetBit(kMustCleanup);
2043 }
2044 
2045 ////////////////////////////////////////////////////////////////////////////////
2046 /// Set canvas title.
2047 
2048 void TCanvas::SetTitle(const char *title)
2049 {
2050  fTitle = title;
2051  if (fCanvasImp) fCanvasImp->SetWindowTitle(title);
2052 }
2053 
2054 ////////////////////////////////////////////////////////////////////////////////
2055 /// Set the canvas scale in centimeters.
2056 ///
2057 /// This information is used by PostScript to set the page size.
2058 ///
2059 /// \param[in] xsize size of the canvas in centimeters along X
2060 /// \param[in] ysize size of the canvas in centimeters along Y
2061 ///
2062 /// if xsize and ysize are not equal to 0, then the scale factors will
2063 /// be computed to keep the ratio ysize/xsize independently of the canvas
2064 /// size (parts of the physical canvas will be unused).
2065 ///
2066 /// if xsize = 0 and ysize is not zero, then xsize will be computed
2067 /// to fit to the current canvas scale. If the canvas is resized,
2068 /// a new value for xsize will be recomputed. In this case the aspect
2069 /// ratio is not preserved.
2070 ///
2071 /// if both xsize = 0 and ysize = 0, then the scaling is automatic.
2072 /// the largest dimension will be allocated a size of 20 centimeters.
2073 
2074 void TCanvas::Size(Float_t xsize, Float_t ysize)
2075 {
2076  fXsizeUser = xsize;
2077  fYsizeUser = ysize;
2078 
2079  Resize();
2080 }
2081 
2082 ////////////////////////////////////////////////////////////////////////////////
2083 /// Stream a class object.
2084 
2085 void TCanvas::Streamer(TBuffer &b)
2086 {
2087  UInt_t R__s, R__c;
2088  if (b.IsReading()) {
2089  Version_t v = b.ReadVersion(&R__s, &R__c);
2090  gPad = this;
2091  fCanvas = this;
2092  if (v>7) b.ClassBegin(TCanvas::IsA());
2093  if (v>7) b.ClassMember("TPad");
2094  TPad::Streamer(b);
2095  gPad = this;
2096  //restore the colors
2097  TObjArray *colors = (TObjArray*)fPrimitives->FindObject("ListOfColors");
2098  if (colors) {
2099  TIter next(colors);
2100  TColor *colold;
2101  while ((colold = (TColor*)next())) {
2102  if (colold) {
2103  Int_t cn = 0;
2104  if (colold) cn = colold->GetNumber();
2105  TColor *colcur = gROOT->GetColor(cn);
2106  if (colcur) {
2107  colcur->SetRGB(colold->GetRed(),colold->GetGreen(),colold->GetBlue());
2108  } else {
2109  colcur = new TColor(cn,colold->GetRed(),
2110  colold->GetGreen(),
2111  colold->GetBlue(),
2112  colold->GetName());
2113  if (!colcur) return;
2114  }
2115  }
2116  }
2117  //restore the palette if needed
2118  TObjArray *currentpalette = (TObjArray*)fPrimitives->FindObject("CurrentColorPalette");
2119  if (currentpalette) {
2120  TIter nextpal(currentpalette);
2121  Int_t n = currentpalette->GetEntries();
2122  TArrayI palcolors(n);
2123  TColor *col = 0;
2124  Int_t i = 0;
2125  while ((col = (TColor*)nextpal())) palcolors[i++] = col->GetNumber();
2126  gStyle->SetPalette(n,palcolors.GetArray());
2127  fPrimitives->Remove(currentpalette);
2128  delete currentpalette;
2129  }
2131  colors->Delete();
2132  delete colors;
2133  }
2134 
2135  if (v>7) b.ClassMember("fDISPLAY","TString");
2136  fDISPLAY.Streamer(b);
2137  if (v>7) b.ClassMember("fDoubleBuffer", "Int_t");
2138  b >> fDoubleBuffer;
2139  if (v>7) b.ClassMember("fRetained", "Bool_t");
2140  b >> fRetained;
2141  if (v>7) b.ClassMember("fXsizeUser", "Size_t");
2142  b >> fXsizeUser;
2143  if (v>7) b.ClassMember("fYsizeUser", "Size_t");
2144  b >> fYsizeUser;
2145  if (v>7) b.ClassMember("fXsizeReal", "Size_t");
2146  b >> fXsizeReal;
2147  if (v>7) b.ClassMember("fYsizeReal", "Size_t");
2148  b >> fYsizeReal;
2149  fCanvasID = -1;
2150  if (v>7) b.ClassMember("fWindowTopX", "Int_t");
2151  b >> fWindowTopX;
2152  if (v>7) b.ClassMember("fWindowTopY", "Int_t");
2153  b >> fWindowTopY;
2154  if (v > 2) {
2155  if (v>7) b.ClassMember("fWindowWidth", "UInt_t");
2156  b >> fWindowWidth;
2157  if (v>7) b.ClassMember("fWindowHeight", "UInt_t");
2158  b >> fWindowHeight;
2159  }
2160  if (v>7) b.ClassMember("fCw", "UInt_t");
2161  b >> fCw;
2162  if (v>7) b.ClassMember("fCh", "UInt_t");
2163  b >> fCh;
2164  if (v <= 2) {
2165  fWindowWidth = fCw;
2166  fWindowHeight = fCh;
2167  }
2168  if (v>7) b.ClassMember("fCatt", "TAttCanvas");
2169  fCatt.Streamer(b);
2170  Bool_t dummy;
2171  if (v>7) b.ClassMember("kMoveOpaque", "Bool_t");
2172  b >> dummy; if (dummy) MoveOpaque(1);
2173  if (v>7) b.ClassMember("kResizeOpaque", "Bool_t");
2174  b >> dummy; if (dummy) ResizeOpaque(1);
2175  if (v>7) b.ClassMember("fHighLightColor", "Color_t");
2176  b >> fHighLightColor;
2177  if (v>7) b.ClassMember("fBatch", "Bool_t");
2178  b >> dummy; //was fBatch
2179  if (v < 2) return;
2180  if (v>7) b.ClassMember("kShowEventStatus", "Bool_t");
2181  b >> dummy; if (dummy) SetBit(kShowEventStatus);
2182 
2183  if (v > 3) {
2184  if (v>7) b.ClassMember("kAutoExec", "Bool_t");
2185  b >> dummy; if (dummy) SetBit(kAutoExec);
2186  }
2187  if (v>7) b.ClassMember("kMenuBar", "Bool_t");
2188  b >> dummy; if (dummy) SetBit(kMenuBar);
2189  fBatch = gROOT->IsBatch();
2190  if (v>7) b.ClassEnd(TCanvas::IsA());
2191  b.CheckByteCount(R__s, R__c, TCanvas::IsA());
2192  } else {
2193  //save list of colors
2194  //we must protect the case when two or more canvases are saved
2195  //in the same buffer. If the list of colors has already been saved
2196  //in the buffer, do not add the list of colors to the list of primitives.
2197  TObjArray *colors = 0;
2198  TObjArray *CurrentColorPalette = 0;
2199  if (TColor::DefinedColors()) {
2200  if (!b.CheckObject(gROOT->GetListOfColors(),TObjArray::Class())) {
2201  colors = (TObjArray*)gROOT->GetListOfColors();
2203  }
2204  //save the current palette
2205  TArrayI pal = TColor::GetPalette();
2206  Int_t palsize = pal.GetSize();
2207  CurrentColorPalette = new TObjArray();
2208  CurrentColorPalette->SetName("CurrentColorPalette");
2209  for (Int_t i=0; i<palsize; i++) CurrentColorPalette->Add(gROOT->GetColor(pal[i]));
2210  fPrimitives->Add(CurrentColorPalette);
2211  }
2212 
2213  R__c = b.WriteVersion(TCanvas::IsA(), kTRUE);
2214  b.ClassBegin(TCanvas::IsA());
2215  b.ClassMember("TPad");
2216  TPad::Streamer(b);
2218  if (CurrentColorPalette) { fPrimitives->Remove(CurrentColorPalette); delete CurrentColorPalette; }
2219  b.ClassMember("fDISPLAY","TString");
2220  fDISPLAY.Streamer(b);
2221  b.ClassMember("fDoubleBuffer", "Int_t");
2222  b << fDoubleBuffer;
2223  b.ClassMember("fRetained", "Bool_t");
2224  b << fRetained;
2225  b.ClassMember("fXsizeUser", "Size_t");
2226  b << fXsizeUser;
2227  b.ClassMember("fYsizeUser", "Size_t");
2228  b << fYsizeUser;
2229  b.ClassMember("fXsizeReal", "Size_t");
2230  b << fXsizeReal;
2231  b.ClassMember("fYsizeReal", "Size_t");
2232  b << fYsizeReal;
2234  Int_t topx = fWindowTopX, topy = fWindowTopY;
2235  UInt_t editorWidth = 0;
2236  if(fCanvasImp) editorWidth = fCanvasImp->GetWindowGeometry(topx,topy,w,h);
2237  b.ClassMember("fWindowTopX", "Int_t");
2238  b << topx;
2239  b.ClassMember("fWindowTopY", "Int_t");
2240  b << topy;
2241  b.ClassMember("fWindowWidth", "UInt_t");
2242  b << (UInt_t)(w-editorWidth);
2243  b.ClassMember("fWindowHeight", "UInt_t");
2244  b << h;
2245  b.ClassMember("fCw", "UInt_t");
2246  b << fCw;
2247  b.ClassMember("fCh", "UInt_t");
2248  b << fCh;
2249  b.ClassMember("fCatt", "TAttCanvas");
2250  fCatt.Streamer(b);
2251  b.ClassMember("kMoveOpaque", "Bool_t");
2252  b << TestBit(kMoveOpaque); //please remove in ROOT version 6
2253  b.ClassMember("kResizeOpaque", "Bool_t");
2254  b << TestBit(kResizeOpaque); //please remove in ROOT version 6
2255  b.ClassMember("fHighLightColor", "Color_t");
2256  b << fHighLightColor;
2257  b.ClassMember("fBatch", "Bool_t");
2258  b << fBatch; //please remove in ROOT version 6
2259  b.ClassMember("kShowEventStatus", "Bool_t");
2260  b << TestBit(kShowEventStatus); //please remove in ROOT version 6
2261  b.ClassMember("kAutoExec", "Bool_t");
2262  b << TestBit(kAutoExec); //please remove in ROOT version 6
2263  b.ClassMember("kMenuBar", "Bool_t");
2264  b << TestBit(kMenuBar); //please remove in ROOT version 6
2265  b.ClassEnd(TCanvas::IsA());
2266  b.SetByteCount(R__c, kTRUE);
2267  }
2268 }
2269 
2270 ////////////////////////////////////////////////////////////////////////////////
2271 /// Toggle pad auto execution of list of TExecs.
2272 
2274 {
2275  Bool_t autoExec = TestBit(kAutoExec);
2276  SetBit(kAutoExec,!autoExec);
2277 }
2278 
2279 ////////////////////////////////////////////////////////////////////////////////
2280 /// Toggle event statusbar.
2281 
2283 {
2284  Bool_t showEventStatus = !TestBit(kShowEventStatus);
2285  SetBit(kShowEventStatus,showEventStatus);
2286 
2287  if (fCanvasImp) fCanvasImp->ShowStatusBar(showEventStatus);
2288 }
2289 
2290 ////////////////////////////////////////////////////////////////////////////////
2291 /// Toggle toolbar.
2292 
2294 {
2295  Bool_t showToolBar = !TestBit(kShowToolBar);
2296  SetBit(kShowToolBar,showToolBar);
2297 
2298  if (fCanvasImp) fCanvasImp->ShowToolBar(showToolBar);
2299 }
2300 
2301 ////////////////////////////////////////////////////////////////////////////////
2302 /// Toggle editor.
2303 
2305 {
2306  Bool_t showEditor = !TestBit(kShowEditor);
2307  SetBit(kShowEditor,showEditor);
2308 
2309  if (fCanvasImp) fCanvasImp->ShowEditor(showEditor);
2310 }
2311 
2312 ////////////////////////////////////////////////////////////////////////////////
2313 /// Toggle tooltip display.
2314 
2316 {
2317  Bool_t showToolTips = !TestBit(kShowToolTips);
2318  SetBit(kShowToolTips, showToolTips);
2319 
2320  if (fCanvasImp) fCanvasImp->ShowToolTips(showToolTips);
2321 }
2322 
2323 
2324 ////////////////////////////////////////////////////////////////////////////////
2325 /// Static function returning "true" if transparency is supported.
2326 
2328 {
2329  return gPad && (gVirtualX->InheritsFrom("TGQuartz") ||
2330  gPad->GetGLDevice() != -1);
2331 }
2332 
2333 extern "C" void ROOT_TCanvas_Update(void* TheCanvas) {
2334  static_cast<TCanvas*>(TheCanvas)->Update();
2335 }
2336 
2337 ////////////////////////////////////////////////////////////////////////////////
2338 /// Update canvas pad buffers.
2339 
2341 {
2342  if (fUpdating) return;
2343 
2344  if (fPixmapID == -1) return;
2345 
2346  static const union CastFromFuncToVoidPtr_t {
2347  CastFromFuncToVoidPtr_t(): fFuncPtr(ROOT_TCanvas_Update) {}
2348  void (*fFuncPtr)(void*);
2349  void* fVoidPtr;
2350  } castFromFuncToVoidPtr;
2351 
2352  if (gThreadXAR) {
2353  void *arr[3];
2354  arr[1] = this;
2355  arr[2] = castFromFuncToVoidPtr.fVoidPtr;
2356  if ((*gThreadXAR)("CUPD", 3, arr, 0)) return;
2357  }
2358 
2359  if (!fCanvasImp) return;
2360 
2361  if (!gVirtualX->IsCmdThread()) {
2362  // Why do we have this (which uses the interpreter to funnel the Update()
2363  // through the main thread) when the gThreadXAR mechanism does seemingly
2364  // the same?
2365  gInterpreter->Execute(this, IsA(), "Update", "");
2366  return;
2367  }
2368 
2370 
2371  fUpdating = kTRUE;
2372 
2373  if (!fCanvasImp->PerformUpdate()) {
2374 
2375  if (!IsBatch()) FeedbackMode(kFALSE); // Goto double buffer mode
2376 
2377  if (!UseGL()) PaintModified(); // Repaint all modified pad's
2378 
2379  Flush(); // Copy all pad pixmaps to the screen
2380 
2381  SetCursor(kCross);
2382  }
2383 
2384  fUpdating = kFALSE;
2385 }
2386 
2387 ////////////////////////////////////////////////////////////////////////////////
2388 /// Used by friend class TCanvasImp.
2389 
2391 {
2392  fCanvasID = 0;
2393  fContextMenu = 0;
2394 }
2395 
2396 ////////////////////////////////////////////////////////////////////////////////
2397 /// Check whether this canvas is to be drawn in grayscale mode.
2398 
2400 {
2401  return TestBit(kIsGrayscale);
2402 }
2403 
2404 ////////////////////////////////////////////////////////////////////////////////
2405 /// Set whether this canvas should be painted in grayscale, and re-paint
2406 /// it if necessary.
2407 
2408 void TCanvas::SetGrayscale(Bool_t set /*= kTRUE*/)
2409 {
2410  if (IsGrayscale() == set) return;
2411  SetBit(kIsGrayscale, set);
2412  Paint(); // update canvas and all sub-pads, unconditionally!
2413 }
2414 
2415 ////////////////////////////////////////////////////////////////////////////////
2416 /// Probably, TPadPainter must be placed in a separate ROOT module -
2417 /// "padpainter" (the same as "histpainter"). But now, it's directly in a
2418 /// gpad dir, so, in case of default painter, no *.so should be loaded,
2419 /// no need in plugin managers.
2420 /// May change in future.
2421 
2423 {
2424  //Even for batch mode painter is still required, just to delegate
2425  //some calls to batch "virtual X".
2426  if (!UseGL() || fBatch) {
2427  fPainter = 0;
2429  if (!fPainter) fPainter = new TPadPainter; // Do not need plugin manager for this!
2430  } else {
2432  if (!fPainter) {
2433  Error("CreatePainter", "GL Painter creation failed! Will use default!");
2434  fPainter = new TPadPainter;
2435  fUseGL = kFALSE;
2436  }
2437  }
2438 }
2439 
2440 ////////////////////////////////////////////////////////////////////////////////
2441 /// Access and (probably) creation of pad painter.
2442 
2444 {
2445  if (!fPainter) CreatePainter();
2446  return fPainter;
2447 }
2448 
2449 
2450 ////////////////////////////////////////////////////////////////////////////////
2451 ///assert on IsBatch() == false?
2452 
2454 {
2455  if (fGLDevice != -1) {
2456  //fPainter has a font manager.
2457  //Font manager will delete textures.
2458  //If context is wrong (we can have several canvases) -
2459  //wrong texture will be deleted, damaging some of our fonts.
2460  gGLManager->MakeCurrent(fGLDevice);
2461  }
2462 
2463  delete fPainter;
2464  fPainter = 0;
2465 
2466  if (fGLDevice != -1) {
2467  gGLManager->DeleteGLContext(fGLDevice);//?
2468  fGLDevice = -1;
2469  }
2470 }
virtual void Clear(Option_t *="")
Definition: TObject.h:100
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TCanvas.cxx:1091
void RunAutoExec()
Execute the list of TExecs in the current pad.
Definition: TCanvas.cxx:1726
void EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
Generate kMouseEnter and kMouseLeave events depending on the previously selected object and the curre...
Definition: TCanvas.cxx:1054
Bool_t GetShowToolBar() const
Definition: TCanvas.h:151
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void SetGridx(Int_t value=1)
Definition: TPad.h:331
void FeedbackMode(Bool_t set)
Turn rubberband feedback mode on or off.
Definition: TCanvas.cxx:1109
R__EXTERN TGuiFactory * gBatchGuiFactory
Definition: TGuiFactory.h:67
virtual void SetPad(const char *name, const char *title, Double_t xlow, Double_t ylow, Double_t xup, Double_t yup, Color_t color=35, Short_t bordersize=5, Short_t bordermode=-1)
Set all pad parameters.
Definition: TPad.cxx:5934
virtual void SetTickx(Int_t value=1)
Definition: TPad.h:351
virtual Bool_t PerformUpdate()
Definition: TCanvasImp.h:46
An array of TObjects.
Definition: TObjArray.h:37
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition: TROOT.cxx:2725
virtual void Selected(TVirtualPad *pad, TObject *obj, Int_t event)
Emit Selected() signal.
Definition: TCanvas.cxx:1605
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:861
TList * fPrimitives
->List of primitives (subpads)
Definition: TPad.h:106
void MoveOpaque(Int_t set=1)
Set option to move objects/pads in a canvas.
Definition: TCanvas.cxx:1501
virtual void ResizePad(Option_t *option="")
Compute pad conversion coefficients.
Definition: TPad.cxx:5430
TPad * fSelectedPad
! Pad containing currently selected object
Definition: TCanvas.h:57
virtual void SetCursor(ECursor cursor)
Set cursor.
Definition: TCanvas.cxx:1962
Float_t GetPadLeftMargin() const
Definition: TStyle.h:202
TCanvas(const TCanvas &canvas)
TVirtualPad * GetSelectedPad() const
Definition: TCanvas.h:148
Int_t fEvent
! Type of current or last handled event
Definition: TCanvas.h:48
TContextMenu * fContextMenu
! Context menu pointer
Definition: TCanvas.h:61
TList * GetListOfPrimitives() const
Definition: TPad.h:242
Float_t GetRed() const
Definition: TColor.h:57
TString fTitle
Pad title.
Definition: TPad.h:109
virtual void ToggleEventStatus()
Toggle event statusbar.
Definition: TCanvas.cxx:2282
virtual Short_t GetBorderSize() const
Definition: TPad.h:197
Bool_t fDrawn
! Set to True when the Draw method is called
Definition: TCanvas.h:66
Bool_t fUseGL
! True when rendering is with GL
Definition: TCanvas.h:65
short Version_t
Definition: RtypesCore.h:61
TPad * fPadSave
! Pointer to saved pad in HandleInput
Definition: TCanvas.h:59
const Size_t kDefaultCanvasSize
Definition: TCanvas.cxx:56
TVirtualPadPainter * GetCanvasPainter()
Access and (probably) creation of pad painter.
Definition: TCanvas.cxx:2443
float Float_t
Definition: RtypesCore.h:53
Size_t fYsizeReal
Current size of canvas along Y in CM.
Definition: TCanvas.h:39
Int_t GetTickx() const
Definition: TPad.h:235
static TCanvasInit gCanvasInit
Definition: TCanvas.cxx:49
float Size_t
Definition: RtypesCore.h:83
virtual void Paint(Option_t *option="")
Paint all primitives in pad.
Definition: TPad.cxx:3422
void SetTitle(const char *title="")
Set canvas title.
Definition: TCanvas.cxx:2048
const char Option_t
Definition: RtypesCore.h:62
Definition: Rtypes.h:64
void Build()
Build a canvas. Called by all constructors.
Definition: TCanvas.cxx:565
static const TArrayI & GetPalette()
Static function returning the current active palette.
Definition: TColor.cxx:1402
Manages default Pad attributes.
Definition: TAttPad.h:19
Create a Box.
Definition: TBox.h:24
R__EXTERN TStyle * gStyle
Definition: TStyle.h:410
TVirtualPadPainter * fPainter
! Canvas (pad) painter.
Definition: TCanvas.h:68
TObject * fSelected
! Currently selected object
Definition: TCanvas.h:52
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2108
Short_t fBorderSize
pad bordersize in pixels
Definition: TPad.h:96
Bool_t GetPadGridY() const
Definition: TStyle.h:205
Int_t GetTicky() const
Definition: TPad.h:236
virtual void SetBorderMode(Short_t bordermode)
Definition: TPad.h:320
static Bool_t fgIsFolder
Indicates if canvas can be browsed as a folder.
Definition: TCanvas.h:70
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:697
Int_t fCanvasID
! Canvas identifier
Definition: TCanvas.h:51
virtual Color_t GetHighLightColor() const
Get highlight color.
Definition: TPad.cxx:2692
static TVirtualPadPainter * PadPainter(Option_t *opt="")
Create a pad painter of specified type.
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual void CopyPixmap()
Copy the pixmap of the pad to the canvas.
Definition: TPad.cxx:1043
virtual void SetWindowTitle(const char *newTitle)
Definition: TCanvasImp.h:92
EEventType
Definition: Buttons.h:15
Int_t GetLogz() const
Definition: TPad.h:255
#define gROOT
Definition: TROOT.h:415
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
Int_t GetPadTickY() const
Definition: TStyle.h:207
virtual void ToggleToolTips()
Toggle tooltip display.
Definition: TCanvas.cxx:2315
Size_t fYsizeUser
User specified size of canvas along Y in CM.
Definition: TCanvas.h:37
void PaintBorder(Color_t color, Bool_t tops)
Paint the pad border.
Definition: TPad.cxx:3484
Basic string class.
Definition: TString.h:131
Int_t fWindowTopX
Top X position of window (in pixels)
Definition: TCanvas.h:42
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
Int_t fSelectedX
! X of selected object
Definition: TCanvas.h:54
Bool_t GetShowEventStatus() const
Definition: TCanvas.h:150
int Int_t
Definition: RtypesCore.h:41
virtual void Size(Float_t xsizeuser=0, Float_t ysizeuser=0)
Set the canvas scale in centimeters.
Definition: TCanvas.cxx:2074
bool Bool_t
Definition: RtypesCore.h:59
virtual void PaintModified()
Traverse pad hierarchy and (re)paint only modified pads.
Definition: TPad.cxx:3639
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:59
virtual void InitPainter()
Empty definition.
#define gInterpreter
Definition: TInterpreter.h:555
Option_t * GetOption() const
Definition: TCollection.h:251
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
void Constructor()
Canvas default constructor.
Definition: TCanvas.cxx:176
Float_t GetScreenFactor() const
Definition: TStyle.h:245
void DrawEventStatus(Int_t event, Int_t x, Int_t y, TObject *selected)
Report name and title of primitive below the cursor.
Definition: TCanvas.cxx:953
void Flush()
Flush canvas buffers.
Definition: TCanvas.cxx:1123
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Returns string containing info about the object at position (px,py).
Definition: TObject.cxx:385
static Bool_t DefinedColors()
Static function returning kTRUE if some new colors have been defined after initialisation or since th...
Definition: TColor.cxx:1420
Float_t GetBlue() const
Definition: TColor.h:59
Int_t GetCanvasDefW() const
Definition: TStyle.h:182
virtual void SetTopMargin(Float_t topmargin)
Set Pad top margin in fraction of the pad height.
Definition: TAttPad.cxx:130
Array of integers (32 bits per element).
Definition: TArrayI.h:27
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:693
Int_t GetCanvasDefX() const
Definition: TStyle.h:183
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:575
Int_t GetCanvasBorderMode() const
Definition: TStyle.h:180
virtual TPad * Pick(Int_t px, Int_t py, TObjLink *&pickobj)
Search for an object at pixel position px,py.
Definition: TCanvas.h:184
void SetCanvasColor(Color_t color=19)
Definition: TStyle.h:325
virtual void ProcessedEvent(Int_t event, Int_t x, Int_t y, TObject *selected)
Emit ProcessedEvent() signal.
Definition: TCanvas.cxx:1619
Bool_t IsWeb() const
Definition: TCanvas.h:178
Int_t GetLogx() const
Definition: TPad.h:253
Bool_t GetShowToolTips() const
Definition: TCanvas.h:153
Size_t fXsizeReal
Current size of canvas along X in CM.
Definition: TCanvas.h:38
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:592
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:127
virtual void Browse(TBrowser *b)
Browse.
Definition: TCanvas.cxx:663
TString fSelectedOpt
! Drawing option of selected object
Definition: TCanvas.h:56
Fill Area Attributes class.
Definition: TAttFill.h:19
Double_t x[n]
Definition: legend1.C:17
Int_t GetLogy() const
Definition: TPad.h:254
Int_t GetWindowTopY()
Returns current top y position of window on screen.
Definition: TCanvas.cxx:1193
virtual void Copy(TAttPad &attpad) const
copy function
Definition: TAttPad.cxx:45
virtual void SetFixedAspectRatio(Bool_t fixed=kTRUE)
Fix canvas aspect ratio to current value if fixed is true.
Definition: TCanvas.cxx:1988
virtual void Cleared(TVirtualPad *pad)
Emit pad Cleared signal.
Definition: TCanvas.cxx:749
virtual void Paint(Option_t *option="")
Paint canvas.
Definition: TCanvas.cxx:1509
static TVirtualPadEditor * GetPadEditor(Bool_t load=kTRUE)
Returns the pad editor dialog. Static method.
virtual void Resize(Option_t *option="")
Recompute canvas parameters following a X11 Resize.
Definition: TCanvas.cxx:1634
virtual void Close(Option_t *option="")
Delete all primitives in pad and pad itself.
Definition: TPad.cxx:986
void Class()
Definition: Class.C:29
R__EXTERN Int_t(* gThreadXAR)(const char *xact, Int_t nb, void **ar, Int_t *iret)
Definition: TVirtualPad.h:289
Bool_t GetPadGridX() const
Definition: TStyle.h:204
virtual Bool_t GetTimeDisplay() const
Definition: TAxis.h:126
Float_t GetGreen() const
Definition: TColor.h:58
Int_t GetPadTickX() const
Definition: TStyle.h:206
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition: TAttLine.cxx:172
void HighLight(Color_t col=kRed, Bool_t set=kTRUE)
Highlight pad.
Definition: TPad.cxx:2938
virtual void ShowEditor(Bool_t show=kTRUE)
Definition: TCanvasImp.h:99
UInt_t GetWindowHeight() const
Definition: TCanvas.h:164
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:330
virtual void Show()
Definition: TCanvasImp.h:66
TCanvas * fCanvas
! Pointer to mother canvas
Definition: TPad.h:105
Int_t GetOptFit() const
Definition: TStyle.h:233
TPad * fClickSelectedPad
! Pad containing currently click-selected object
Definition: TCanvas.h:58
const char * GetTitle() const
Returns title of object.
Definition: TPad.h:258
UInt_t GetWw() const
Get Ww.
Definition: TCanvas.h:165
void SetCanvasBorderSize(Width_t size=1)
Definition: TStyle.h:326
void DeleteCanvasPainter()
assert on IsBatch() == false?
Definition: TCanvas.cxx:2453
void Clear(Option_t *option="")
Remove all primitives from the canvas.
Definition: TCanvas.cxx:716
static void CreateApplication()
virtual void Pop()
Pop on object drawn in a pad to the top of the display list.
Definition: TObject.cxx:527
virtual void Close()
Definition: TCanvasImp.h:56
virtual void ShowToolBar(Bool_t show=kTRUE)
Definition: TCanvasImp.h:100
virtual void ls(Option_t *option="") const
List all primitives in pad.
Definition: TPad.cxx:2973
virtual ~TCanvas()
Canvas destructor.
Definition: TCanvas.cxx:655
static constexpr double s
virtual void SetLogx(Int_t value=1)
Set Lin/Log scale for X.
Definition: TPad.cxx:5867
static ENewType IsCallingNew()
Static method returning the defConstructor flag passed to TClass::New().
Definition: TClass.cxx:5697
virtual void ShowMenuBar(Bool_t show=kTRUE)
Definition: TCanvasImp.h:94
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:50
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:66
static void SetFolder(Bool_t isfolder=kTRUE)
If isfolder=kTRUE, the canvas can be browsed like a folder by default a canvas is not browsable...
Definition: TCanvas.cxx:2010
void SaveSource(const char *filename="", Option_t *option="")
Save primitives in this canvas as a C++ macro file.
Definition: TCanvas.cxx:1782
virtual void ls(Option_t *option="") const
List all pads.
Definition: TCanvas.cxx:1458
virtual const char * GetTimeFormat() const
Definition: TAxis.h:127
virtual void SetName(const char *name="")
Set canvas name. In case name is an empty string, a default name is set.
Definition: TCanvas.cxx:2018
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2327
Double_t fX2
X of upper X coordinate.
Definition: TPad.h:37
A doubly linked list.
Definition: TList.h:44
Bool_t fRetained
Retain structure flag.
Definition: TCanvas.h:64
virtual void CopyPixmaps()
Copy the sub-pixmaps of the pad to the canvas.
Definition: TPad.cxx:1057
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:867
UInt_t fCw
Width of the canvas along X (pixels)
Definition: TCanvas.h:46
void DisconnectWidget()
Used by friend class TCanvasImp.
Definition: TCanvas.cxx:2390
Bool_t GetGridy() const
Definition: TPad.h:233
TPad * fMother
! pointer to mother of the list
Definition: TPad.h:104
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TPad.cxx:1693
void CopyPixmaps()
Copy the canvas pixmap of the pad to the canvas.
Definition: TCanvas.cxx:816
virtual void ToggleToolBar()
Toggle toolbar.
Definition: TCanvas.cxx:2293
Int_t fSelectedY
! Y of selected object
Definition: TCanvas.h:55
void SetCanvasBorderMode(Int_t mode=1)
Definition: TStyle.h:327
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition: TAttPad.cxx:100
static void NeedGraphicsLibs()
Static method.
Int_t fPixmapID
! Off-screen pixmap identifier
Definition: TPad.h:83
void ResizeOpaque(Int_t set=1)
Set option to resize objects/pads in a canvas.
Definition: TCanvas.cxx:1718
Class to manage histogram axis.
Definition: TAxis.h:30
Int_t GetSize() const
Definition: TArray.h:47
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Set world coordinate system for the pad.
Definition: TPad.cxx:5164
UInt_t fWindowHeight
Height of window (including menubar, borders, etc.)
Definition: TCanvas.h:45
virtual void SetTicky(Int_t value=1)
Definition: TPad.h:352
Float_t GetPadBottomMargin() const
Definition: TStyle.h:200
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:819
Width_t GetCanvasBorderSize() const
Definition: TStyle.h:179
UInt_t GetWh() const
Get Wh.
Definition: TCanvas.h:166
virtual void UseCurrentStyle()
Force a copy of current style for all objects in pad.
Definition: TPad.cxx:6685
Float_t GetPadRightMargin() const
Definition: TStyle.h:203
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:442
This class provides an interface to context sensitive popup menus.
Definition: TContextMenu.h:40
TString fDISPLAY
Name of destination screen.
Definition: TCanvas.h:35
R__ALWAYS_INLINE Bool_t IsOnHeap() const
Definition: TObject.h:133
unsigned int UInt_t
Definition: RtypesCore.h:42
The most important graphics class in the ROOT system.
Definition: TPad.h:29
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:887
char * Form(const char *fmt,...)
Int_t GetOptLogy() const
Definition: TStyle.h:237
void CreatePainter()
Probably, TPadPainter must be placed in a separate ROOT module - "padpainter" (the same as "histpaint...
Definition: TCanvas.cxx:2422
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitives in this pad on the C++ source file out.
Definition: TPad.cxx:5632
static TCanvas * MakeDefCanvas()
Static function to build a default canvas.
Definition: TCanvas.cxx:1470
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2829
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
void ROOT_TCanvas_Update(void *TheCanvas)
Definition: TCanvas.cxx:2333
virtual void ToggleEditor()
Toggle editor.
Definition: TCanvas.cxx:2304
Bool_t fUpdating
! True when Updating the canvas
Definition: TCanvas.h:63
virtual void Popup(Int_t x, Int_t y, TObject *obj, TVirtualPad *c=nullptr, TVirtualPad *p=nullptr)
Popup context menu at given location in canvas c and pad p for selected object.
virtual TCanvas * GetCanvas() const
Definition: TPad.h:259
void SetName(const char *name)
Definition: TCollection.h:204
Int_t GetOptLogz() const
Definition: TStyle.h:238
virtual void ToggleAutoExec()
Toggle pad auto execution of list of TExecs.
Definition: TCanvas.cxx:2273
void Destructor()
Actual canvas destructor.
Definition: TCanvas.cxx:673
Bool_t IsBeingResized() const
Definition: TVirtualPad.h:144
Int_t GetOptLogx() const
Definition: TStyle.h:236
if object destructor must call RecursiveRemove()
Definition: TObject.h:60
#define gVirtualX
Definition: TVirtualX.h:338
#define h(i)
Definition: RSha256.hxx:106
virtual void ShowStatusBar(Bool_t show=kTRUE)
Definition: TCanvasImp.h:95
Color_t GetHighLightColor() const
Get highlight color.
Definition: TCanvas.h:140
virtual void SelectDrawable(Int_t device)=0
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2490
const Bool_t kFALSE
Definition: RtypesCore.h:88
Double_t fY2
Y of upper Y coordinate.
Definition: TPad.h:38
Double_t fAspectRatio
ratio of w/h in case of fixed ratio
Definition: TPad.h:81
Int_t GetWindowTopX()
Returns current top x position of window on screen.
Definition: TCanvas.cxx:1182
TAttCanvas fCatt
Canvas attributes.
Definition: TCanvas.h:34
void InitializeGraphics()
Initialize the graphics environment.
#define SafeDelete(p)
Definition: RConfig.hxx:543
if object does not want context menu
Definition: TObject.h:65
Bool_t GetGridx() const
Definition: TPad.h:232
long Long_t
Definition: RtypesCore.h:50
Color * colors
Definition: X3DBuffer.c:21
TCanvasImp * fCanvasImp
! Window system specific canvas implementation
Definition: TCanvas.h:60
The Canvas class.
Definition: TCanvas.h:27
Bool_t IsFolder() const
Is folder ?
Definition: TCanvas.cxx:1450
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to an event at (px,py).
Definition: TObject.cxx:310
double Double_t
Definition: RtypesCore.h:55
Int_t GetOptStat() const
Definition: TStyle.h:234
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:892
virtual void SetGridy(Int_t value=1)
Definition: TPad.h:332
UInt_t GetWindowWidth() const
Definition: TCanvas.h:163
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
void SetCanvasSize(UInt_t ww, UInt_t wh)
Set Width and Height of canvas to ww and wh respectively.
Definition: TCanvas.cxx:1949
virtual void SetFillStyle(Style_t fstyle)
Override TAttFill::FillStyle for TPad because we want to handle style=0 as style 4000.
Definition: TPad.cxx:5855
Bool_t IsBatch() const
Is pad in batch mode ?
Definition: TCanvas.h:173
Float_t GetPadTopMargin() const
Definition: TStyle.h:201
static RooMathCoreReg dummy
Double_t y[n]
Definition: legend1.C:17
void Init()
Initialize the TCanvas members. Called by all constructors.
Definition: TCanvas.cxx:516
virtual void SetRGB(Float_t r, Float_t g, Float_t b)
Initialize this color and its associated colors.
Definition: TColor.cxx:1702
Bool_t IsGrayscale()
Check whether this canvas is to be drawn in grayscale mode.
Definition: TCanvas.cxx:2399
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
virtual TCanvasImp * CreateCanvasImp(TCanvas *c, const char *title, UInt_t width, UInt_t height)
Create a batch version of TCanvasImp.
Definition: TGuiFactory.cxx:56
#define gGLManager
Definition: TVirtualGL.h:162
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
Color_t fHighLightColor
Highlight color of active pad.
Definition: TCanvas.h:40
The TH1 histogram class.
Definition: TH1.h:56
Size_t fXsizeUser
User specified size of canvas along X in CM.
Definition: TCanvas.h:36
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition: TDatime.cxx:101
#define R__LOCKGUARD(mutex)
The color creation and management class.
Definition: TColor.h:19
void Browse(TBrowser *b)
Browse this collection (called by TBrowser).
void SetWindowSize(UInt_t ww, UInt_t wh)
Definition: TCanvas.h:204
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:181
Int_t GetCanvasDefH() const
Definition: TStyle.h:181
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this canvas A new canvas is created that is a clone of this canvas.
Definition: TCanvas.cxx:881
virtual void SetTicks(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:350
virtual TVirtualPadPainter * CreatePadPainter()
Definition: TCanvasImp.h:47
virtual void HighlightConnect(const char *slot)
This is "simplification" for function TCanvas::Connect with Highlighted signal for specific slot...
Definition: TCanvas.cxx:1597
Int_t fWindowTopY
Top Y position of window (in pixels)
Definition: TCanvas.h:43
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition: TAttPad.cxx:120
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t fFixedAspectRatio
True if fixed aspect ratio.
Definition: TPad.h:103
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:143
void UseCurrentStyle()
Force a copy of current style for all objects in canvas.
Definition: TCanvas.cxx:1157
Bool_t IsReading() const
Definition: TStyle.h:280
void Clear(Option_t *option="")
Delete all pad primitives.
Definition: TPad.cxx:621
virtual void Draw(Option_t *option="")
Draw a canvas.
Definition: TCanvas.cxx:834
Int_t fDoubleBuffer
Double buffer flag (0=off, 1=on)
Definition: TCanvas.h:41
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition: TROOT.cxx:2821
virtual void SetDoubleBuffer(Int_t mode=1)
Set Double Buffer On/Off.
Definition: TCanvas.cxx:1971
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:400
typedef void((*Func_t)())
void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitives in this canvas in C++ macro file with GUI.
Definition: TCanvas.cxx:1737
virtual TObject * DrawClonePad()
Draw a clone of this canvas into the current pad In an interactive session, select the destination/cu...
Definition: TCanvas.cxx:898
const char * GetName() const
Returns name of object.
Definition: TPad.h:257
#define ClassImpQ(name)
Definition: TQObject.h:282
void EmbedInto(Int_t winid, Int_t ww, Int_t wh)
Embedded a canvas into a TRootEmbeddedCanvas.
Definition: TCanvas.cxx:1028
virtual void ShowToolTips(Bool_t show=kTRUE)
Definition: TCanvasImp.h:101
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual void LockPainter()
Empty definition.
Int_t fEventX
! Last X mouse position in canvas
Definition: TCanvas.h:49
TString fName
Pad name.
Definition: TPad.h:108
void SetSelected(TObject *obj)
Set selected canvas.
Definition: TCanvas.cxx:2039
virtual Short_t GetBorderMode() const
Definition: TPad.h:196
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
virtual void Highlighted(TVirtualPad *pad, TObject *obj, Int_t x, Int_t y)
Emit Highlighted() signal.
Definition: TCanvas.cxx:1578
Bool_t HasMenuBar() const
Definition: TCanvas.h:170
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
void Close(Option_t *option="")
Close canvas.
Definition: TCanvas.cxx:767
virtual void EditorBar()
Get editor bar.
Definition: TCanvas.cxx:1019
#define snprintf
Definition: civetweb.c:1540
R__EXTERN TVirtualPS * gVirtualPS
Definition: TVirtualPS.h:81
Int_t GetNumber() const
Definition: TColor.h:55
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:522
#define gPad
Definition: TVirtualPad.h:287
virtual Int_t InitWindow()
Definition: TCanvasImp.h:60
object has not been deleted
Definition: TObject.h:78
R__EXTERN Int_t gDebug
Definition: Rtypes.h:91
#define c(i)
Definition: RSha256.hxx:101
Implement TVirtualPadPainter which abstracts painting operations.
Definition: TPadPainter.h:26
Color_t GetCanvasColor() const
Definition: TStyle.h:178
TObject * fClickSelected
! Currently click-selected object
Definition: TCanvas.h:53
Int_t fEventY
! Last Y mouse position in canvas
Definition: TCanvas.h:50
void Add(TObject *obj)
Definition: TObjArray.h:74
void SetBatch(Bool_t batch=kTRUE)
Toggle batch mode.
Definition: TCanvas.cxx:1933
Int_t GetCanvasDefY() const
Definition: TStyle.h:184
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
void ResetBit(UInt_t f)
Definition: TObject.h:171
virtual UInt_t GetWindowGeometry(Int_t &x, Int_t &y, UInt_t &w, UInt_t &h)
Definition: TCanvasImp.h:87
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition: TVirtualPS.h:30
Definition: first.py:1
virtual void HandleInput(EEventType button, Int_t x, Int_t y)
Handle Input Events.
Definition: TCanvas.cxx:1206
Bool_t UseGL() const
Definition: TCanvas.h:232
virtual void SetBorderSize(Short_t bordersize)
Definition: TPad.h:321
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2340
Double_t fY1
Y of lower Y coordinate.
Definition: TPad.h:36
virtual void SetStatusText(const char *text=0, Int_t partidx=0)
Definition: TCanvasImp.h:89
Bool_t GetCanvasPreferGL() const
Definition: TStyle.h:177
ECursor
Definition: GuiTypes.h:371
Int_t fGLDevice
! OpenGL off-screen pixmap identifier
Definition: TPad.h:84
Bool_t fBatch
! True when in batchmode
Definition: TCanvas.h:62
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:356
virtual void SetCanvasSize(UInt_t w, UInt_t h)
Definition: TCanvasImp.h:93
Double_t fX1
X of lower X coordinate.
Definition: TPad.h:35
virtual void SetLogz(Int_t value=1)
Set Lin/Log scale for Z.
Definition: TPad.cxx:5892
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void Closed()
Emit Closed signal.
Definition: TCanvas.cxx:757
const Int_t n
Definition: legend1.C:16
Line Attributes class.
Definition: TAttLine.h:18
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1645
void Modified(Bool_t flag=1)
Definition: TPad.h:417
To make it possible to use GL for 2D graphic in a TPad/TCanvas.
char name[80]
Definition: TGX11.cxx:109
virtual void Picked(TPad *selpad, TObject *selected, Int_t event)
Emit Picked() signal.
Definition: TCanvas.cxx:1559
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:873
UInt_t fCh
Height of the canvas along Y (pixels)
Definition: TCanvas.h:47
Short_t fBorderMode
Bordermode (-1=down, 0 = no border, 1=up)
Definition: TPad.h:97
UInt_t fWindowWidth
Width of window (including borders, etc.)
Definition: TCanvas.h:44
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition: TAttFill.cxx:202
void SetGrayscale(Bool_t set=kTRUE)
Set whether this canvas should be painted in grayscale, and re-paint it if necessary.
Definition: TCanvas.cxx:2408
Int_t GetOptTitle() const
Definition: TStyle.h:235
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition: TAttPad.cxx:110
Double_t GetTimeOffset() const
Definition: TStyle.h:258
virtual void SetLogy(Int_t value=1)
Set Lin/Log scale for Y.
Definition: TPad.cxx:5881