Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGIcon.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 05/01/98
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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
13 This source is based on Xclass95, a Win95-looking GUI toolkit.
14 Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15
16 Xclass95 is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License as published by the Free Software Foundation; either
19 version 2 of the License, or (at your option) any later version.
20
21**************************************************************************/
22
23//////////////////////////////////////////////////////////////////////////
24// //
25// TGIcon //
26// //
27// This class handles GUI icons. //
28// //
29//////////////////////////////////////////////////////////////////////////
30
31#include "TGIcon.h"
32#include "TGPicture.h"
33#include "TSystem.h"
34#include "TImage.h"
35#include "TVirtualDragManager.h"
36#include "TVirtualX.h"
37
38#include <iostream>
39
40
42
43////////////////////////////////////////////////////////////////////////////////
44/// Create icon.
45
46TGIcon::TGIcon(const TGWindow *p, const char *image) : TGFrame(p, 1, 1)
47{
48 fPic = nullptr;
49
50 if (!image)
51 image = "bld_rgb.xpm";
52
53 char *path = StrDup(image);
54
55 fPath = gSystem->GetDirName(path);
56
57 fImage = TImage::Open(path);
58 if (fImage) {
62 }
64 delete [] path;
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Delete icon and free picture.
69
71{
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Set icon picture.
77
79{
80 fPic = pic;
81 gVirtualX->ClearWindow(fId);
82 fClient->NeedRedraw(this);
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Set icon image.
87
88void TGIcon::SetImage(const char *img)
89{
90 //delete fImage;
91 TImage *i = TImage::Open(img);
92 fPath = gSystem->GetDirName(img);
93
94 SetImage(i);
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Change icon image.
99
101{
102 if (!img) {
103 return;
104 }
105
106 delete fImage; // !! mem.leak!!
107 fImage = img;
108
110 fClient->NeedRedraw(this);
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Return size of icon.
115
117{
118 return TGDimension((fPic) ? fPic->GetWidth() : fWidth,
119 (fPic) ? fPic->GetHeight() : fHeight);
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Redraw picture.
124
126{
127 Bool_t border = (GetOptions() & kRaisedFrame) ||
128 (GetOptions() & kSunkenFrame) ||
130
131 if (fPic) fPic->Draw(fId, GetBckgndGC()(), border, border);
132 if (border) DrawBorder();
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Resize.
137
139{
140 TGFrame::Resize(w, h);
141
142 // allow scaled resize for icons with TImage
143 if (!fImage) {
144 return;
145 }
146
147 gVirtualX->ClearWindow(fId);
148
149 if (fPic) {
151 }
152 Bool_t border = (GetOptions() & kRaisedFrame) ||
153 (GetOptions() & kSunkenFrame) ||
155
156 fImage->Scale(w - 2*border, h - 2*border);
159 DoRedraw();
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Move icon to (x,y) and resize it to (w,h).
164
166{
167 Move(x, y);
168 Resize(w, h);
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// Reset icon to original image. It can be used only via context menu.
173
175{
176 if (!fImage || !fClient->IsEditable()) return;
177
179 name.Chop();
180 char *path = gSystem->ConcatFileName(fPath.Data(), name.Data());
181 SetImage(path);
182
183 delete [] path;
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Set directory where image is located
188
189void TGIcon::SetImagePath(const char *path)
190{
191 if (!path) {
192 return;
193 }
194
195 fPath = gSystem->UnixPathName(path);
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Save an icon widget as a C++ statement(s) on output stream out.
201
202void TGIcon::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
203{
204 char quote = '"';
205
207
208 if (!fPic) {
209 Error("SavePrimitive()", "icon pixmap not found ");
210 return;
211 }
212
213 TString picname = gSystem->UnixPathName(fPic->GetName());
214 gSystem->ExpandPathName(picname);
215
216 out <<" TGIcon *";
217 if (!fImage) {
218 out << GetName() << " = new TGIcon(" << fParent->GetName()
219 << ",gClient->GetPicture(" << quote
220 << picname // if no path
221 << quote << ")" << "," << GetWidth() << "," << GetHeight();
223 if (!GetOptions()) {
224 out <<");" << std::endl;
225 } else {
226 out << "," << GetOptionString() <<");" << std::endl;
227 }
228 } else {
229 out << "," << GetOptionString() << ",ucolor);" << std::endl;
230 }
231 } else {
233 name += "/";
234 name += fImage->GetName();
235 name.Chop();
236 out << GetName() << " = new TGIcon(" << fParent->GetName() << ","
237 << quote << name.Data() << quote << ");" << std::endl;
238 }
239 if (option && strstr(option, "keep_names"))
240 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
241}
@ kRaisedFrame
Definition GuiTypes.h:384
@ kSunkenFrame
Definition GuiTypes.h:383
@ kDoubleBorder
Definition GuiTypes.h:385
#define h(i)
Definition RSha256.hxx:106
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2510
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#define gVirtualX
Definition TVirtualX.h:338
Bool_t IsEditable() const
Definition TGClient.h:98
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:371
TGPicturePool * GetPicturePool() const
Definition TGClient.h:135
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:307
UInt_t fHeight
Definition TGFrame.h:112
virtual void DrawBorder()
Draw frame border.
Definition TGFrame.cxx:406
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:668
virtual UInt_t GetOptions() const
Definition TGFrame.h:221
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2465
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition TGFrame.cxx:578
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:590
UInt_t fWidth
Definition TGFrame.h:111
UInt_t GetHeight() const
Definition TGFrame.h:249
UInt_t GetWidth() const
Definition TGFrame.h:248
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2438
Pixel_t fBackground
Definition TGFrame.h:119
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:760
virtual void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0)
Move icon to (x,y) and resize it to (w,h).
Definition TGIcon.cxx:165
virtual void DoRedraw()
Redraw picture.
Definition TGIcon.cxx:125
virtual ~TGIcon()
Delete icon and free picture.
Definition TGIcon.cxx:70
virtual void SetPicture(const TGPicture *pic)
Set icon picture.
Definition TGIcon.cxx:78
virtual void SetImage(const char *img)
Set icon image.
Definition TGIcon.cxx:88
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save an icon widget as a C++ statement(s) on output stream out.
Definition TGIcon.cxx:202
const TGPicture * fPic
Definition TGIcon.h:33
TImage * fImage
Definition TGIcon.h:34
virtual TGDimension GetDefaultSize() const
Return size of icon.
Definition TGIcon.cxx:116
TString fPath
Definition TGIcon.h:35
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize.
Definition TGIcon.cxx:138
TGIcon(const TGIcon &)=delete
virtual void Reset()
Reset icon to original image. It can be used only via context menu.
Definition TGIcon.cxx:174
virtual void SetImagePath(const char *path)
Set directory where image is located.
Definition TGIcon.cxx:189
TGClient * fClient
Definition TGObject.h:37
Handle_t fId
Definition TGObject.h:36
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition TGPicture.cxx:80
const char * GetName() const
Returns name of object.
Definition TGPicture.h:62
UInt_t GetHeight() const
Definition TGPicture.h:64
void Draw(Option_t *="")
Default Draw method for all objects.
Definition TGPicture.h:57
UInt_t GetWidth() const
Definition TGPicture.h:63
virtual void SetWindowName(const char *name=0)
Set window name.
Definition TGWindow.cxx:128
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:335
const TGWindow * fParent
Definition TGWindow.h:36
An abstract interface to image processing library.
Definition TImage.h:29
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:118
virtual UInt_t GetWidth() const
Definition TImage.h:228
virtual void Scale(UInt_t, UInt_t)
Definition TImage.h:141
virtual Pixmap_t GetPixmap()
Definition TImage.h:235
virtual Pixmap_t GetMask()
Definition TImage.h:236
virtual UInt_t GetHeight() const
Definition TImage.h:229
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:893
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1272
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition TSystem.cxx:1069
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition TSystem.cxx:1061
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:933
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1030
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17