Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 "Riostream.h"
19 
20 ClassImp(TGShapedFrame);
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) {
32  SetWindowAttributes_t attr;
33  attr.fMask = kWAOverrideRedirect | kWASaveUnder;
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(),
47  fImage->GetPixmap(), fImage->GetMask());
48  // shape the window with the picture mask
49  gVirtualX->ShapeCombineMask(fId, 0, 0, fBgnd->GetMask());
50  // and finally set the background picture
51  SetBackgroundPixmap(fBgnd->GetPicture());
52 
53  MapSubwindows();
54  Resize();
55  Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Destructor.
60 
61 TGShapedFrame::~TGShapedFrame()
62 {
63  delete fImage;
64  fClient->FreePicture(fBgnd);
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 {
72  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
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 
80  if (fBackground == GetDefaultFrameBackground()) {
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]
95  TGLayoutManager * lm = GetLayoutManager();
96  if ((GetOptions() & kHorizontalFrame) &&
97  (lm->InheritsFrom(TGHorizontalLayout::Class()))) {
98  ;
99  } else if ((GetOptions() & kVerticalFrame) &&
100  (lm->InheritsFrom(TGVerticalLayout::Class()))) {
101  ;
102  } else {
103  out << " " << GetName() <<"->SetLayoutManager(";
104  lm->SavePrimitive(out, option);
105  out << ");"<< std::endl;
106  }
107 
108  SavePrimitiveSubframes(out, option);
109 }