TGShapedFrame.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGShapedFrame.cxx 35582 2010-09-22 13:38:27Z bellenot $
00002 // Author: Bertrand Bellenot 23/01/2008
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TGFrame.h"
00013 #include "TGLayout.h"
00014 #include "TString.h"
00015 #include "TGPicture.h"
00016 #include "TImage.h"
00017 #include "TGShapedFrame.h"
00018 #include "Riostream.h"
00019 
00020 ClassImp(TGShapedFrame)
00021 
00022 //______________________________________________________________________________
00023 TGShapedFrame::TGShapedFrame(const char *pname, const TGWindow *p, UInt_t w,
00024                              UInt_t h, UInt_t options) :
00025       TGCompositeFrame(p, w, h, options), fBgnd(0), fImage(0)
00026 {
00027    // Shaped window default constructor
00028 
00029    TString picName;
00030    // set a few attributes
00031    if (options & kTempFrame) {
00032       SetWindowAttributes_t attr;
00033       attr.fMask             = kWAOverrideRedirect | kWASaveUnder;
00034       attr.fOverrideRedirect = kTRUE;
00035       attr.fSaveUnder        = kTRUE;
00036       gVirtualX->ChangeWindowAttributes(fId, &attr);
00037    }
00038    // open the image file used as shape & background
00039    if (pname)
00040       picName = pname;
00041    else
00042       picName = "Default.png";
00043    fImage = TImage::Open(picName.Data());
00044    if (!fImage || !fImage->IsValid())
00045       Error("TGShapedFrame", "%s not found", picName.Data());
00046    fBgnd = fClient->GetPicturePool()->GetPicture(picName.Data(),
00047            fImage->GetPixmap(), fImage->GetMask());
00048    // shape the window with the picture mask
00049    gVirtualX->ShapeCombineMask(fId, 0, 0, fBgnd->GetMask());
00050    // and finally set the background picture
00051    SetBackgroundPixmap(fBgnd->GetPicture());
00052 
00053    MapSubwindows();
00054    Resize();
00055    Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
00056 }
00057 
00058 //______________________________________________________________________________
00059 TGShapedFrame::~TGShapedFrame()
00060 {
00061    // Destructor.
00062 
00063    delete fImage;
00064    fClient->FreePicture(fBgnd);
00065 }
00066 
00067 //______________________________________________________________________________
00068 void TGShapedFrame::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00069 {
00070    // Save a shaped frame as a C++ statement(s) on output stream out.
00071 
00072    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
00073 
00074    out << endl << "   // shaped frame" << endl;
00075    out << "   TGShapedFrame *";
00076    out << GetName() << " = new TGShapedFrame(" << fImage->GetName()
00077        << "," << fParent->GetName() << "," << GetWidth() << ","
00078        << GetHeight();
00079 
00080    if (fBackground == GetDefaultFrameBackground()) {
00081       if (!GetOptions()) {
00082          out << ");" << endl;
00083       } else {
00084          out << "," << GetOptionString() <<");" << endl;
00085       }
00086    } else {
00087       out << "," << GetOptionString() << ",ucolor);" << endl;
00088    }
00089    if (option && strstr(option, "keep_names"))
00090       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00091 
00092    // setting layout manager if it differs from the main frame type
00093    TGLayoutManager * lm = GetLayoutManager();
00094    if ((GetOptions() & kHorizontalFrame) &&
00095        (lm->InheritsFrom(TGHorizontalLayout::Class()))) {
00096       ;
00097    } else if ((GetOptions() & kVerticalFrame) &&
00098               (lm->InheritsFrom(TGVerticalLayout::Class()))) {
00099       ;
00100    } else {
00101       out << "   " << GetName() <<"->SetLayoutManager(";
00102       lm->SavePrimitive(out, option);
00103       out << ");"<< endl;
00104    }
00105 
00106    SavePrimitiveSubframes(out, option);
00107 }

Generated on Tue Jul 5 14:22:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1