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
26
27////////////////////////////////////////////////////////////////////////////////
28/// Shaped window default constructor
29
30TGShapedFrame::TGShapedFrame(const char *pname, const TGWindow *p, UInt_t w,
31 UInt_t h, UInt_t options) :
32 TGCompositeFrame(p, w, h, options), fBgnd(0), fImage(0)
33{
34 TString picName;
35 // set a few attributes
36 if (options & kTempFrame) {
40 attr.fSaveUnder = kTRUE;
41 gVirtualX->ChangeWindowAttributes(fId, &attr);
42 }
43 // open the image file used as shape & background
44 if (pname)
45 picName = pname;
46 else
47 picName = "Default.png";
48 fImage = TImage::Open(picName.Data());
49 if (!fImage || !fImage->IsValid()) {
50 Error("TGShapedFrame", "%s not found", picName.Data());
51 return;
52 }
53 fBgnd = fClient->GetPicturePool()->GetPicture(picName.Data(),
54 fImage->GetPixmap(), fImage->GetMask());
55 // shape the window with the picture mask
56 gVirtualX->ShapeCombineMask(fId, 0, 0, fBgnd->GetMask());
57 // and finally set the background picture
58 SetBackgroundPixmap(fBgnd->GetPicture());
59
61 Resize();
62 Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Destructor.
67
69{
70 delete fImage;
71 fClient->FreePicture(fBgnd);
72}
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
100 SavePrimitiveSubframes(out, option);
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
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
#define gVirtualX
Definition TVirtualX.h:375
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:2641
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
TGCompositeFrame(const TGCompositeFrame &)=delete
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
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:2493
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
~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()
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition TGWindow.cxx:246
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
TGWindow(Window_t id)
Definition TGWindow.h:34
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:334
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:117
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition TObject.cxx:858
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
Attributes that can be used when creating or changing a window.
Definition GuiTypes.h:94
Bool_t fOverrideRedirect
boolean value for override-redirect
Definition GuiTypes.h:108
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:111
Bool_t fSaveUnder
should bits under be saved (popups)?
Definition GuiTypes.h:105