#include "TGIcon.h"
#include "TGPicture.h"
#include "TSystem.h"
#include "TImage.h"
#include "Riostream.h"
#include "TMath.h"
#include "TGFileDialog.h"
#include "TGMsgBox.h"
#include "TVirtualDragManager.h"
ClassImp(TGIcon)
TGIcon::TGIcon(const TGWindow *p, const char *image) : TGFrame(p, 1, 1)
{
   
   fPic = 0;
   char *path;
   if (!image)
      image = "bld_rgb.xpm";
   path = StrDup(image);
   fPath = gSystem->DirName(path);
   fImage = TImage::Open(path);
   fPic = fClient->GetPicturePool()->GetPicture(gSystem->BaseName(path),
                                                fImage->GetPixmap(), fImage->GetMask());
   TGFrame::Resize(fImage->GetWidth(), fImage->GetHeight());
   SetWindowName();
   delete [] path;
}
TGIcon::~TGIcon()
{
   
   if (fPic) fClient->FreePicture(fPic);
}
void TGIcon::SetPicture(const TGPicture *pic)
{
   
   fPic = pic;
   gVirtualX->ClearWindow(fId);
   fClient->NeedRedraw(this);
}
void TGIcon::SetImage(const char *img)
{
   
   
   TImage *i = TImage::Open(img);
   fPath = gSystem->DirName(img);
   SetImage(i);
}
void TGIcon::SetImage(TImage *img)
{
   
   if (!img) {
      return;
   }
   delete fImage; 
   fImage = img;
   Resize(fImage->GetWidth(), fImage->GetHeight());
   fClient->NeedRedraw(this);
}
TGDimension TGIcon::GetDefaultSize() const
{
   
   return TGDimension((fPic) ? fPic->GetWidth()  : fWidth,
                      (fPic) ? fPic->GetHeight() : fHeight);
}
void TGIcon::DoRedraw()
{
   
   Bool_t border = (GetOptions() & kRaisedFrame) ||
                   (GetOptions() & kSunkenFrame) ||
                   (GetOptions() & kDoubleBorder);
   if (fPic) fPic->Draw(fId, GetBckgndGC()(), border, border);
   if (border)  DrawBorder();
}
void TGIcon::Resize(UInt_t w, UInt_t h)
{
   
   TGFrame::Resize(w, h);
   
   if (!fImage) {
      return;
   }
   gVirtualX->ClearWindow(fId);
   if (fPic) {
      fClient->FreePicture(fPic);
   }
   Bool_t border = (GetOptions() & kRaisedFrame) ||
                   (GetOptions() & kSunkenFrame) ||
                   (GetOptions() & kDoubleBorder);
   fImage->Scale(w - 2*border, h - 2*border);
   fPic = fClient->GetPicturePool()->GetPicture(fImage->GetName(),
                                                fImage->GetPixmap(), fImage->GetMask());
   DoRedraw();
}
void TGIcon::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
{
   
   Move(x, y);
   Resize(w, h);
}
void TGIcon::Reset()
{
   
   if (!fImage || !fClient->IsEditable()) return;
   TString name = fImage->GetName();
   name.Chop();
   char *path = gSystem->ConcatFileName(fPath.Data(), name.Data());
   SetImage(path);
   delete path;
}
void TGIcon::SetImagePath(const char *path)
{
   
   if (!path) {
      return;
   }
   fPath = gSystem->ExpandPathName(gSystem->UnixPathName(path));
}
void TGIcon::SavePrimitive(ostream &out, Option_t *option )
{
    
   char quote = '"';
   if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
   if (!fPic) {
      Error("SavePrimitive()", "icon pixmap not found ");
      return;
   }
   const char *picname = fPic->GetName();
   out <<"   TGIcon *";
   if (!fImage) {
      out << GetName() << " = new TGIcon(" << fParent->GetName()
         << ",gClient->GetPicture(" << quote
         << gSystem->ExpandPathName(gSystem->UnixPathName(picname))   
         << quote << ")" << "," << GetWidth() << "," << GetHeight();
      if (fBackground == GetDefaultFrameBackground()) {
         if (!GetOptions()) {
            out <<");" << endl;
         } else {
            out << "," << GetOptionString() <<");" << endl;
         }
      } else {
         out << "," << GetOptionString() << ",ucolor);" << endl;
      }
   } else {
      TString name = fPath;
      name += "/";
      name += fImage->GetName();
      name.Chop();
      out << GetName() << " = new TGIcon(" << fParent->GetName()  << ","
          << quote << name.Data() << quote << ");" << endl;
   }
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.