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 "TGFrame.h"
13#include "TGLayout.h"
14#include "TString.h"
15#include "TGPicture.h"
16#include "TImage.h"
17#include "TGShapedFrame.h"
18#include "TVirtualX.h"
19#include "Riostream.h"
20
22
23////////////////////////////////////////////////////////////////////////////////
24/// Shaped window default constructor
25
26TGShapedFrame::TGShapedFrame(const char *pname, const TGWindow *p, UInt_t w,
27 UInt_t h, UInt_t options) :
28 TGCompositeFrame(p, w, h, options), fBgnd(0), fImage(0)
29{
30 TString picName;
31 // set a few attributes
32 if (options & kTempFrame) {
36 attr.fSaveUnder = kTRUE;
37 gVirtualX->ChangeWindowAttributes(fId, &attr);
38 }
39 // open the image file used as shape & background
40 if (pname)
41 picName = pname;
42 else
43 picName = "Default.png";
44 fImage = TImage::Open(picName.Data());
45 if (!fImage || !fImage->IsValid())
46 Error("TGShapedFrame", "%s not found", picName.Data());
49 // shape the window with the picture mask
50 gVirtualX->ShapeCombineMask(fId, 0, 0, fBgnd->GetMask());
51 // and finally set the background picture
53
55 Resize();
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Destructor.
61
63{
64 delete fImage;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Save a shaped frame as a C++ statement(s) on output stream out.
70
71void TGShapedFrame::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
72{
74
75 out << std::endl << " // shaped frame" << std::endl;
76 out << " TGShapedFrame *";
77 out << GetName() << " = new TGShapedFrame(" << fImage->GetName()
78 << "," << fParent->GetName() << "," << GetWidth() << ","
79 << GetHeight();
80
82 if (!GetOptions()) {
83 out << ");" << std::endl;
84 } else {
85 out << "," << GetOptionString() <<");" << std::endl;
86 }
87 } else {
88 out << "," << GetOptionString() << ",ucolor);" << std::endl;
89 }
90 if (option && strstr(option, "keep_names"))
91 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
92
93 // setting layout manager if it differs from the main frame type
94 // coverity[returned_null]
95 // coverity[dereference]
97 if ((GetOptions() & kHorizontalFrame) &&
99 ;
100 } else if ((GetOptions() & kVerticalFrame) &&
102 ;
103 } else {
104 out << " " << GetName() <<"->SetLayoutManager(";
105 lm->SavePrimitive(out, option);
106 out << ");"<< std::endl;
107 }
108
109 SavePrimitiveSubframes(out, option);
110}
void Class()
Definition: Class.C:29
const Mask_t kWAOverrideRedirect
Definition: GuiTypes.h:148
const Mask_t kWASaveUnder
Definition: GuiTypes.h:149
@ kTempFrame
Definition: GuiTypes.h:393
@ kVerticalFrame
Definition: GuiTypes.h:381
@ kHorizontalFrame
Definition: GuiTypes.h:382
#define h(i)
Definition: RSha256.hxx:106
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
#define gVirtualX
Definition: TVirtualX.h:338
TGPicturePool * GetPicturePool() const
Definition: TGClient.h:135
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:308
virtual TGLayoutManager * GetLayoutManager() const
Definition: TGFrame.h:375
virtual void SavePrimitiveSubframes(std::ostream &out, Option_t *option="")
Auxilary protected method used to save subframes.
Definition: TGFrame.cxx:2625
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1148
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:667
virtual UInt_t GetOptions() const
Definition: TGFrame.h:222
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2464
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:589
UInt_t GetHeight() const
Definition: TGFrame.h:250
UInt_t GetWidth() const
Definition: TGFrame.h:249
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition: TGFrame.cxx:2437
Pixel_t fBackground
Definition: TGFrame.h:120
TGClient * fClient
Definition: TGObject.h:37
Handle_t fId
Definition: TGObject.h:36
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
Pixmap_t GetMask() const
Definition: TGPicture.h:66
UInt_t GetHeight() const
Definition: TGPicture.h:64
Pixmap_t GetPicture() const
Definition: TGPicture.h:65
UInt_t GetWidth() const
Definition: TGPicture.h:63
TGShapedFrame(const TGShapedFrame &)
virtual ~TGShapedFrame()
Destructor.
TImage * fImage
Definition: TGShapedFrame.h:31
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a shaped frame as a C++ statement(s) on output stream out.
const TGPicture * fBgnd
Definition: TGShapedFrame.h:30
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:326
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition: TGWindow.cxx:238
const TGWindow * fParent
Definition: TGWindow.h:36
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:119
virtual Bool_t IsValid() const
Definition: TImage.h:230
virtual Pixmap_t GetPixmap()
Definition: TImage.h:235
virtual Pixmap_t GetMask()
Definition: TImage.h:236
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:664
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
Bool_t fOverrideRedirect
Definition: GuiTypes.h:106