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 "TASUtils.h"
16#include "TGShapedFrame.h"
17#include "TVirtualX.h"
18
19#include <iostream>
20
21/** \class TGShapedFrame
22 \ingroup guiwidgets
23A Shaped window
24*/
25
26
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(nullptr), fImage(nullptr)
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 }
55 // shape the window with the picture mask
56 gVirtualX->ShapeCombineMask(fId, 0, 0, fBgnd->GetMask());
57 // and finally set the background picture
59
61 Resize();
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Destructor.
67
73
74////////////////////////////////////////////////////////////////////////////////
75/// Save a shaped frame as a C++ statement(s) on output stream out.
76
77void TGShapedFrame::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
78{
79 // save options and custom color if not default
80 auto extra_args = SaveCtorArgs(out);
81
82 out << "\n // shaped frame\n";
83 out << " TGShapedFrame *" << GetName() << " = new TGShapedFrame(" << fImage->GetName() << "," << fParent->GetName()
84 << "," << GetWidth() << "," << GetHeight() << extra_args << ");\n";
85
86 if (option && strstr(option, "keep_names"))
87 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
88
89 // setting layout manager if it differs from the main frame type
90 // coverity[returned_null]
91 // coverity[dereference]
95 out << " " << GetName() << "->SetLayoutManager(";
96 lm->SavePrimitive(out, option);
97 out << ");\n";
98 }
99
101}
const Mask_t kWAOverrideRedirect
Definition GuiTypes.h:150
const Mask_t kWASaveUnder
Definition GuiTypes.h:151
@ kTempFrame
Definition GuiTypes.h:394
@ kVerticalFrame
Definition GuiTypes.h:382
@ kHorizontalFrame
Definition GuiTypes.h:383
#define h(i)
Definition RSha256.hxx:106
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
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:379
static Pixmap_t GetPixmap(TImage *timg)
Returns image pixmap.
Definition TASUtils.cxx:135
static Pixmap_t GetMask(TImage *timg)
Returns image mask pixmap (alpha channel).
Definition TASUtils.cxx:181
TGPicturePool * GetPicturePool() const
Definition TGClient.h:126
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:317
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:289
virtual TGLayoutManager * GetLayoutManager() const
Definition TGFrame.h:340
virtual void SavePrimitiveSubframes(std::ostream &out, Option_t *option="")
Auxiliary protected method used to save subframes.
Definition TGFrame.cxx:2642
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1158
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:599
virtual UInt_t GetOptions() const
Definition TGFrame.h:199
UInt_t GetHeight() const
Definition TGFrame.h:227
TString SaveCtorArgs(std::ostream &out, UInt_t dflt_options=kChildFrame, Bool_t check_white_pixel=kFALSE)
Return options and custom color as constructor args Used in the SavePrimitive methods,...
Definition TGFrame.cxx:2494
UInt_t GetWidth() const
Definition TGFrame.h:226
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:81
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
~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:249
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:337
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:123
virtual Bool_t IsValid() const
Definition TImage.h:247
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition TObject.cxx:857
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:548
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
Attributes that can be used when creating or changing a window.
Definition GuiTypes.h:94