47 TGIcon::TGIcon(
const TGWindow *p,
const char *image) : TGFrame(p, 1, 1)
53 image =
"bld_rgb.xpm";
57 fPath = gSystem->DirName(path);
59 fImage = TImage::Open(path);
61 fPic = fClient->GetPicturePool()->GetPicture(gSystem->BaseName(path),
62 fImage->GetPixmap(), fImage->GetMask());
63 TGFrame::Resize(fImage->GetWidth(), fImage->GetHeight());
74 if (fPic) fClient->FreePicture(fPic);
80 void TGIcon::SetPicture(
const TGPicture *pic)
83 gVirtualX->ClearWindow(fId);
84 fClient->NeedRedraw(
this);
90 void TGIcon::SetImage(
const char *img)
93 TImage *i = TImage::Open(img);
94 fPath = gSystem->DirName(img);
102 void TGIcon::SetImage(TImage *img)
111 Resize(fImage->GetWidth(), fImage->GetHeight());
112 fClient->NeedRedraw(
this);
118 TGDimension TGIcon::GetDefaultSize()
const
120 return TGDimension((fPic) ? fPic->GetWidth() : fWidth,
121 (fPic) ? fPic->GetHeight() : fHeight);
127 void TGIcon::DoRedraw()
129 Bool_t border = (GetOptions() & kRaisedFrame) ||
130 (GetOptions() & kSunkenFrame) ||
131 (GetOptions() & kDoubleBorder);
133 if (fPic) fPic->Draw(fId, GetBckgndGC()(), border, border);
134 if (border) DrawBorder();
140 void TGIcon::Resize(UInt_t w, UInt_t h)
142 TGFrame::Resize(w, h);
149 gVirtualX->ClearWindow(fId);
152 fClient->FreePicture(fPic);
154 Bool_t border = (GetOptions() & kRaisedFrame) ||
155 (GetOptions() & kSunkenFrame) ||
156 (GetOptions() & kDoubleBorder);
158 fImage->Scale(w - 2*border, h - 2*border);
159 fPic = fClient->GetPicturePool()->GetPicture(fImage->GetName(),
160 fImage->GetPixmap(), fImage->GetMask());
167 void TGIcon::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
178 if (!fImage || !fClient->IsEditable())
return;
180 TString name = fImage->GetName();
182 char *path = gSystem->ConcatFileName(fPath.Data(), name.Data());
191 void TGIcon::SetImagePath(
const char *path)
196 fPath = gSystem->ExpandPathName(gSystem->UnixPathName(path));
202 void TGIcon::SavePrimitive(std::ostream &out, Option_t *option )
206 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
209 Error(
"SavePrimitive()",
"icon pixmap not found ");
213 const char *picname = fPic->GetName();
217 out << GetName() <<
" = new TGIcon(" << fParent->GetName()
218 <<
",gClient->GetPicture(" << quote
219 << gSystem->ExpandPathName(gSystem->UnixPathName(picname))
220 << quote <<
")" <<
"," << GetWidth() <<
"," << GetHeight();
221 if (fBackground == GetDefaultFrameBackground()) {
223 out <<
");" << std::endl;
225 out <<
"," << GetOptionString() <<
");" << std::endl;
228 out <<
"," << GetOptionString() <<
",ucolor);" << std::endl;
231 TString name = fPath;
233 name += fImage->GetName();
235 out << GetName() <<
" = new TGIcon(" << fParent->GetName() <<
","
236 << quote << name.Data() << quote <<
");" << std::endl;
238 if (option && strstr(option,
"keep_names"))
239 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;