Logo ROOT   6.08/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 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Write this TGObject to a file using TImage, if filename's extension signals
41 /// a valid TImage::EImageFileType, as defined by TImage::GetImageFileTypeFromFilename().
42 /// Otherwise forward to TObject::SaveAs().
43 
44 void TGObject::SaveAs(const char* filename /*= ""*/, Option_t* option /*= ""*/) const
45 {
47  if (type != TImage::kUnknown) {
48  WindowAttributes_t wattr;
49  gVirtualX->GetWindowAttributes(GetId(), wattr);
50  TImage* img = TImage::Create();
51  if (img) {
52  img->FromWindow(GetId(), 0, 0, wattr.fWidth, wattr.fHeight);
53  img->WriteImage(filename, type);
54  delete img;
55  }
56  return;
57  }
58 
59  TObject::SaveAs(filename, option);
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Equal comparison (TGObjects are equal if they have the same
64 /// window identifier). If the TGObjects have not been created by
65 /// the Window manager (e.g. a TGLVEntry), then fall back to the
66 /// default TObject equal comparison
67 
68 Bool_t TGObject::IsEqual(const TObject *obj) const
69 {
70  if ((fId == 0) && (((const TGObject *) obj)->fId == 0))
71  return TObject::IsEqual(obj);
72  return fId == ((const TGObject *) obj)->fId;
73 }
74 
EImageFileTypes
Definition: TImage.h:44
const char Option_t
Definition: RtypesCore.h:62
virtual void WriteImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition: TImage.h:123
bool Bool_t
Definition: RtypesCore.h:59
An abstract interface to image processing library.
Definition: TImage.h:37
Bool_t IsEqual(const TObject *obj) const
Equal comparison (TGObjects are equal if they have the same window identifier).
Definition: TGObject.cxx:68
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save this object in the file specified by filename.
Definition: TObject.cxx:644
virtual void FromWindow(Drawable_t, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:252
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:528
#define gVirtualX
Definition: TVirtualX.h:362
#define ClassImp(name)
Definition: Rtypes.h:279
int type
Definition: TGX11.cxx:120
Handle_t fId
Definition: TGObject.h:40
Mother of all ROOT objects.
Definition: TObject.h:37
typedef void((*Func_t)())
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