Logo ROOT  
Reference Guide
TGShapedFrame.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Bertrand Bellenot 23/01/2008
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2008, 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 "TGLayout.h"
13 #include "TString.h"
14 #include "TImage.h"
15 #include "TGShapedFrame.h"
16 #include "TVirtualX.h"
17 
18 #include <iostream>
19 
21 
22 ////////////////////////////////////////////////////////////////////////////////
23 /// Shaped window default constructor
24 
25 TGShapedFrame::TGShapedFrame(const char *pname, const TGWindow *p, UInt_t w,
26  UInt_t h, UInt_t options) :
27  TGCompositeFrame(p, w, h, options), fBgnd(0), fImage(0)
28 {
29  TString picName;
30  // set a few attributes
31  if (options & kTempFrame) {
34  attr.fOverrideRedirect = kTRUE;
35  attr.fSaveUnder = kTRUE;
36  gVirtualX->ChangeWindowAttributes(fId, &attr);
37  }
38  // open the image file used as shape & background
39  if (pname)
40  picName = pname;
41  else
42  picName = "Default.png";
43  fImage = TImage::Open(picName.Data());
44  if (!fImage || !fImage->IsValid())
45  Error("TGShapedFrame", "%s not found", picName.Data());
46  fBgnd = fClient->GetPicturePool()->GetPicture(picName.Data(),
48  // shape the window with the picture mask
49  gVirtualX->ShapeCombineMask(fId, 0, 0, fBgnd->GetMask());
50  // and finally set the background picture
52 
53  MapSubwindows();
54  Resize();
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Destructor.
60 
62 {
63  delete fImage;
65 }
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Save a shaped frame as a C++ statement(s) on output stream out.
69 
70 void TGShapedFrame::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
71 {
73 
74  out << std::endl << " // shaped frame" << std::endl;
75  out << " TGShapedFrame *";
76  out << GetName() << " = new TGShapedFrame(" << fImage->GetName()
77  << "," << fParent->GetName() << "," << GetWidth() << ","
78  << GetHeight();
79 
81  if (!GetOptions()) {
82  out << ");" << std::endl;
83  } else {
84  out << "," << GetOptionString() <<");" << std::endl;
85  }
86  } else {
87  out << "," << GetOptionString() << ",ucolor);" << std::endl;
88  }
89  if (option && strstr(option, "keep_names"))
90  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
91 
92  // setting layout manager if it differs from the main frame type
93  // coverity[returned_null]
94  // coverity[dereference]
96  if ((GetOptions() & kHorizontalFrame) &&
98  ;
99  } else if ((GetOptions() & kVerticalFrame) &&
101  ;
102  } else {
103  out << " " << GetName() <<"->SetLayoutManager(";
104  lm->SavePrimitive(out, option);
105  out << ");"<< std::endl;
106  }
107 
108  SavePrimitiveSubframes(out, option);
109 }
SetWindowAttributes_t::fSaveUnder
Bool_t fSaveUnder
Definition: GuiTypes.h:103
TGFrame::GetHeight
UInt_t GetHeight() const
Definition: TGFrame.h:250
TObject::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:666
TGWindow
Definition: TGWindow.h:31
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGShapedFrame.h
TGCompositeFrame::GetLayoutManager
virtual TGLayoutManager * GetLayoutManager() const
Definition: TGFrame.h:375
TGPicture::GetWidth
UInt_t GetWidth() const
Definition: TGPicture.h:63
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
TString::Data
const char * Data() const
Definition: TString.h:369
TGLayout.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TGPicture::GetMask
Pixmap_t GetMask() const
Definition: TGPicture.h:66
kTempFrame
@ kTempFrame
Definition: GuiTypes.h:393
TGFrame::GetDefaultFrameBackground
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:668
TVirtualX.h
TGClient::FreePicture
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:309
TGWindow::SetBackgroundPixmap
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition: TGWindow.cxx:229
TImage::Open
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:118
TGShapedFrame::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a shaped frame as a C++ statement(s) on output stream out.
Definition: TGShapedFrame.cxx:70
TString
Definition: TString.h:136
SetWindowAttributes_t::fMask
Mask_t fMask
Definition: GuiTypes.h:109
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
TGClient::GetPicturePool
TGPicturePool * GetPicturePool() const
Definition: TGClient.h:135
TString.h
TGCompositeFrame::SavePrimitiveSubframes
virtual void SavePrimitiveSubframes(std::ostream &out, Option_t *option="")
Auxilary protected method used to save subframes.
Definition: TGFrame.cxx:2626
TGFrame::GetWidth
UInt_t GetWidth() const
Definition: TGFrame.h:249
kWASaveUnder
const Mask_t kWASaveUnder
Definition: GuiTypes.h:149
TImage.h
TGLayoutManager
Definition: TGLayout.h:142
TGFrame::GetOptionString
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2465
TGFrame::GetOptions
virtual UInt_t GetOptions() const
Definition: TGFrame.h:222
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TGPicturePool::GetPicture
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
h
#define h(i)
Definition: RSha256.hxx:124
TGWindow::GetName
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:317
TGCompositeFrame::MapSubwindows
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1149
SetWindowAttributes_t::fOverrideRedirect
Bool_t fOverrideRedirect
Definition: GuiTypes.h:106
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:590
TGObject::fId
Handle_t fId
Definition: TGObject.h:36
TGShapedFrame::fImage
TImage * fImage
Definition: TGShapedFrame.h:35
TImage::GetMask
virtual Pixmap_t GetMask()
Definition: TImage.h:236
TGFrame::SaveUserColor
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition: TGFrame.cxx:2438
TGShapedFrame
Definition: TGShapedFrame.h:21
unsigned int
TGShapedFrame::~TGShapedFrame
virtual ~TGShapedFrame()
Destructor.
Definition: TGShapedFrame.cxx:61
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGShapedFrame::fBgnd
const TGPicture * fBgnd
Definition: TGShapedFrame.h:34
TGObject::fClient
TGClient * fClient
Definition: TGObject.h:37
TGPicture::GetPicture
Pixmap_t GetPicture() const
Definition: TGPicture.h:65
TImage::GetPixmap
virtual Pixmap_t GetPixmap()
Definition: TImage.h:235
TGFrame::fBackground
Pixel_t fBackground
Definition: TGFrame.h:120
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
kWAOverrideRedirect
const Mask_t kWAOverrideRedirect
Definition: GuiTypes.h:148
Class
void Class()
Definition: Class.C:29
TGCompositeFrame
Definition: TGFrame.h:324
TGPicture::GetHeight
UInt_t GetHeight() const
Definition: TGPicture.h:64
TGWindow::fParent
const TGWindow * fParent
Definition: TGWindow.h:36
TImage::IsValid
virtual Bool_t IsValid() const
Definition: TImage.h:230
TGShapedFrame::TGShapedFrame
TGShapedFrame(const TGShapedFrame &)=delete
SetWindowAttributes_t
Definition: GuiTypes.h:92