Logo ROOT   6.12/07
Reference Guide
TGObject.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 27/12/97
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 
13  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // TGObject //
26 // //
27 // This class is the baseclass for all ROOT GUI widgets. //
28 // The ROOT GUI components emulate the Win95 look and feel and the code //
29 // is based on the XClass'95 code (see Copyleft in source). //
30 // //
31 //////////////////////////////////////////////////////////////////////////
32 
33 #include "TGObject.h"
34 #include "TVirtualX.h"
35 #include "TImage.h"
36 #include "TROOT.h"
37 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// TGObject destructor.
42 
44 {
45  // Required since we overload TObject::Hash.
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Write this TGObject to a file using TImage, if filename's extension signals
51 /// a valid TImage::EImageFileType, as defined by TImage::GetImageFileTypeFromFilename().
52 /// Otherwise forward to TObject::SaveAs().
53 
54 void TGObject::SaveAs(const char* filename /*= ""*/, Option_t* option /*= ""*/) const
55 {
57  if (type != TImage::kUnknown) {
58  WindowAttributes_t wattr;
59  gVirtualX->GetWindowAttributes(GetId(), wattr);
60  TImage* img = TImage::Create();
61  if (img) {
62  img->FromWindow(GetId(), 0, 0, wattr.fWidth, wattr.fHeight);
63  img->WriteImage(filename, type);
64  delete img;
65  }
66  return;
67  }
68 
69  TObject::SaveAs(filename, option);
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Equal comparison (TGObjects are equal if they have the same
74 /// window identifier). If the TGObjects have not been created by
75 /// the Window manager (e.g. a TGLVEntry), then fall back to the
76 /// default TObject equal comparison
77 
78 Bool_t TGObject::IsEqual(const TObject *obj) const
79 {
80  if ((fId == 0) && (((const TGObject *) obj)->fId == 0))
81  return TObject::IsEqual(obj);
82  return fId == ((const TGObject *) obj)->fId;
83 }
84 
EImageFileTypes
Definition: TImage.h:36
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.
Definition: TROOT.h:391
const char Option_t
Definition: RtypesCore.h:62
virtual void WriteImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition: TImage.h:115
bool Bool_t
Definition: RtypesCore.h:59
An abstract interface to image processing library.
Definition: TImage.h:29
Handle_t GetId() const
Definition: TGObject.h:47
Bool_t IsEqual(const TObject *obj) const
Equal comparison (TGObjects are equal if they have the same window identifier).
Definition: TGObject.cxx:78
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save this object in the file specified by filename.
Definition: TObject.cxx:599
virtual void FromWindow(Drawable_t, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:244
virtual Bool_t IsEqual(const TObject *obj) const
Default equal comparison (objects are equal if they have the same address in memory).
Definition: TObject.cxx:483
virtual ~TGObject()
TGObject destructor.
Definition: TGObject.cxx:43
#define gVirtualX
Definition: TVirtualX.h:350
#define ClassImp(name)
Definition: Rtypes.h:359
int type
Definition: TGX11.cxx:120
Handle_t fId
Definition: TGObject.h:36
Mother of all ROOT objects.
Definition: TObject.h:37
static EImageFileTypes GetImageFileTypeFromFilename(const char *opt)
Return the image type for the extension specified in filename.
Definition: TImage.cxx:60
static TImage * Create()
Create an image.
Definition: TImage.cxx:36
virtual void SaveAs(const char *filename="", Option_t *option="") const
Write this TGObject to a file using TImage, if filename's extension signals a valid TImage::EImageFil...
Definition: TGObject.cxx:54