Logo ROOT  
Reference Guide
TLink.cxx
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Rene Brun 05/03/95
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 <cstdio>
13 
14 #include "TVirtualPad.h"
15 #include "TClass.h"
16 #include "TLink.h"
17 #include "snprintf.h"
18 
20 
21 /** \class TLink
22 \ingroup BasicGraphics
23 
24 Special TText object used to show hyperlinks.
25 
26 In the example below created by TObject::Inspect, TLinks are used
27 to show pointers to other objects.
28 Clicking on one link, inspect the corresponding object.
29 */
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// Link default constructor.
33 
35 {
36  fLink = 0;
37 }
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Constructor to define a link object.
41 ///
42 /// pointer points to any kind of object.
43 
44 TLink::TLink(Double_t x, Double_t y, void *pointer)
45  : TText(x, y, "")
46 {
47  fLink = pointer;
48  static char line[16];
49  snprintf(line,16,"->%lx ", (Long_t)pointer);
50  SetTitle(line);
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Link default destructor.
55 
57 {
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Execute action corresponding to one event.
62 ///
63 /// This member function is called when a link is clicked with the locator
64 ///
65 /// If mouse is clicked on a link text, the object pointed by the link
66 /// is Inspected
67 
69 {
70  if (!gPad) return;
71 
72  if (event == kMouseMotion)
73  gPad->SetCursor(kHand);
74 
75  if (event != kButton1Up) return;
76 
77  if (TestBit(kIsStarStar)) return;
78  TObject *idcur = (TObject*)fLink;
79  if (!idcur) return;
81  if (!cl) return;
82 
83  // check if link points to a TObject
84  TClass *c1 = (TClass*)cl->GetBaseClass("TObject");
85  if (!c1) return;
86 
87  idcur->Inspect();
88 }
TObject::TestBit
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
snprintf
#define snprintf
Definition: civetweb.c:1540
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
kButton1Up
@ kButton1Up
Definition: Buttons.h:25
x
Double_t x[n]
Definition: legend1.C:17
TClass.h
TClass::GetBaseClass
TClass * GetBaseClass(const char *classname)
Return pointer to the base class "classname".
Definition: TClass.cxx:2612
kMouseMotion
@ kMouseMotion
Definition: Buttons.h:29
Long_t
long Long_t
Definition: RtypesCore.h:54
TVirtualPad.h
TClass::GetClass
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2925
y
Double_t y[n]
Definition: legend1.C:17
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
line
TLine * line
Definition: entrylistblock_figure1.C:235
kHand
@ kHand
Definition: GuiTypes.h:373
TText
Definition: TText.h:22
Double_t
double Double_t
Definition: RtypesCore.h:59
TClass
Definition: TClass.h:80
TObject
Definition: TObject.h:37
TObject::Inspect
virtual void Inspect() const
Dump contents of this object in a graphics canvas.
Definition: TObject.cxx:466
gPad
#define gPad
Definition: TVirtualPad.h:287
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
int
c1
return c1
Definition: legend1.C:41