Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
20/** \class TGShapedFrame
21 \ingroup guiwidgets
22A Shaped window
23*/
24
25
27
28////////////////////////////////////////////////////////////////////////////////
29/// Shaped window default constructor
30
31TGShapedFrame::TGShapedFrame(const char *pname, const TGWindow *p, UInt_t w,
32 UInt_t h, UInt_t options) :
33 TGCompositeFrame(p, w, h, options), fBgnd(0), fImage(0)
34{
35 TString picName;
36 // set a few attributes
37 if (options & kTempFrame) {
40 attr.fOverrideRedirect = kTRUE;
41 attr.fSaveUnder = kTRUE;
42 gVirtualX->ChangeWindowAttributes(fId, &attr);
43 }
44 // open the image file used as shape & background
45 if (pname)
46 picName = pname;
47 else
48 picName = "Default.png";
49 fImage = TImage::Open(picName.Data());
50 if (!fImage || !fImage->IsValid()) {
51 Error("TGShapedFrame", "%s not found", picName.Data());
52 return;
53 }
56 // shape the window with the picture mask
57 gVirtualX->ShapeCombineMask(fId, 0, 0, fBgnd->GetMask());
58 // and finally set the background picture
60
62 Resize();
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Destructor.
68
70{
71 delete fImage;
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Save a shaped frame as a C++ statement(s) on output stream out.
77
78void TGShapedFrame::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
79{
81
82 out << std::endl << " // shaped frame" << std::endl;
83 out << " TGShapedFrame *";
84 out << GetName() << " = new TGShapedFrame(" << fImage->GetName()
85 << "," << fParent->GetName() << "," << GetWidth() << ","
86 << GetHeight();
87
89 if (!GetOptions()) {
90 out << ");" << std::endl;
91 } else {
92 out << "," << GetOptionString() <<");" << std::endl;
93 }
94 } else {
95 out << "," << GetOptionString() << ",ucolor);" << std::endl;
96 }
97 if (option && strstr(option, "keep_names"))
98 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
99
100 // setting layout manager if it differs from the main frame type
101 // coverity[returned_null]
102 // coverity[dereference]
104 if ((GetOptions() & kHorizontalFrame) &&
106 ;
107 } else if ((GetOptions() & kVerticalFrame) &&
109 ;
110 } else {
111 out << " " << GetName() <<"->SetLayoutManager(";
112 lm->SavePrimitive(out, option);
113 out << ");"<< std::endl;
114 }
115
117}
const Mask_t kWAOverrideRedirect
Definition GuiTypes.h:149
const Mask_t kWASaveUnder
Definition GuiTypes.h:150
@ kTempFrame
Definition GuiTypes.h:393
@ kVerticalFrame
Definition GuiTypes.h:381
@ kHorizontalFrame
Definition GuiTypes.h:382
#define h(i)
Definition RSha256.hxx:106
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
#define gVirtualX
Definition TVirtualX.h:338
TGPicturePool * GetPicturePool() const
Definition TGClient.h:126
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:308
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
virtual TGLayoutManager * GetLayoutManager() const
Definition TGFrame.h:338
virtual void SavePrimitiveSubframes(std::ostream &out, Option_t *option="")
Auxiliary protected method used to save subframes.
Definition TGFrame.cxx:2667
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:683
virtual UInt_t GetOptions() const
Definition TGFrame.h:197
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2506
UInt_t GetHeight() const
Definition TGFrame.h:225
UInt_t GetWidth() const
Definition TGFrame.h:224
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2479
Pixel_t fBackground
frame background color
Definition TGFrame.h:95
static TClass * Class()
Frame layout manager.
Definition TGLayout.h:135
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition TGPicture.cxx:82
Pixmap_t GetMask() const
Definition TGPicture.h:55
UInt_t GetHeight() const
Definition TGPicture.h:53
Pixmap_t GetPicture() const
Definition TGPicture.h:54
UInt_t GetWidth() const
Definition TGPicture.h:52
A Shaped window.
~TGShapedFrame() override
Destructor.
TGShapedFrame(const TGShapedFrame &)=delete
TImage * fImage
image used as background/shape
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a shaped frame as a C++ statement(s) on output stream out.
const TGPicture * fBgnd
picture used as background/shape
static TClass * Class()
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition TGWindow.cxx:248
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:118
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
const char * GetName() const override
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:751
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:380
Attributes that can be used when creating or changing a window.
Definition GuiTypes.h:93