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/** \class TGIcon
25 \ingroup guiwidgets
26
27This class handles GUI icons.
28
29*/
30
31
32#include "TGIcon.h"
33#include "TGPicture.h"
34#include "TSystem.h"
35#include "TImage.h"
36#include "TVirtualDragManager.h"
37#include "TVirtualX.h"
38
39#include <iostream>
40
41
43
44////////////////////////////////////////////////////////////////////////////////
45/// Create icon.
46
47TGIcon::TGIcon(const TGWindow *p, const char *image) : TGFrame(p, 1, 1)
48{
49 fPic = nullptr;
50
51 if (!image)
52 image = "bld_rgb.xpm";
53
54 char *path = StrDup(image);
55
56 fPath = gSystem->GetDirName(path);
57
58 fImage = TImage::Open(path);
59 if (fImage) {
63 }
65 delete [] path;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Delete icon and free picture.
70
72{
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Set icon picture.
78
80{
81 fPic = pic;
82 gVirtualX->ClearWindow(fId);
83 fClient->NeedRedraw(this);
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Set icon image.
88
89void TGIcon::SetImage(const char *img)
90{
91 //delete fImage;
92 TImage *i = TImage::Open(img);
93 fPath = gSystem->GetDirName(img);
94
95 SetImage(i);
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Change icon image.
100
102{
103 if (!img) {
104 return;
105 }
106
107 delete fImage; // !! mem.leak!!
108 fImage = img;
109
111 fClient->NeedRedraw(this);
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Return size of icon.
116
118{
119 return TGDimension((fPic) ? fPic->GetWidth() : fWidth,
120 (fPic) ? fPic->GetHeight() : fHeight);
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Redraw picture.
125
127{
128 Bool_t border = (GetOptions() & kRaisedFrame) ||
129 (GetOptions() & kSunkenFrame) ||
131
132 if (fPic) fPic->Draw(fId, GetBckgndGC()(), border, border);
133 if (border) DrawBorder();
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Resize.
138
140{
141 TGFrame::Resize(w, h);
142
143 // allow scaled resize for icons with TImage
144 if (!fImage) {
145 return;
146 }
147
148 gVirtualX->ClearWindow(fId);
149
150 if (fPic) {
152 }
153 Bool_t border = (GetOptions() & kRaisedFrame) ||
154 (GetOptions() & kSunkenFrame) ||
156
157 fImage->Scale(w - 2*border, h - 2*border);
160 DoRedraw();
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// Move icon to (x,y) and resize it to (w,h).
165
167{
168 Move(x, y);
169 Resize(w, h);
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Reset icon to original image. It can be used only via context menu.
174
176{
177 if (!fImage || !fClient->IsEditable()) return;
178
180 name.Chop();
181 char *path = gSystem->ConcatFileName(fPath.Data(), name.Data());
182 SetImage(path);
183
184 delete [] path;
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// Set directory where image is located
189
190void TGIcon::SetImagePath(const char *path)
191{
192 if (!path) {
193 return;
194 }
195
196 fPath = gSystem->UnixPathName(path);
198}
199
200////////////////////////////////////////////////////////////////////////////////
201/// Save an icon widget as a C++ statement(s) on output stream out.
202
203void TGIcon::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
204{
205 char quote = '"';
206
208
209 if (!fPic) {
210 Error("SavePrimitive()", "icon pixmap not found ");
211 return;
212 }
213
214 TString picname = gSystem->UnixPathName(fPic->GetName());
215 gSystem->ExpandPathName(picname);
216
217 out <<" TGIcon *";
218 if (!fImage) {
219 out << GetName() << " = new TGIcon(" << fParent->GetName()
220 << ",gClient->GetPicture(" << quote
221 << picname // if no path
222 << quote << ")" << "," << GetWidth() << "," << GetHeight();
224 if (!GetOptions()) {
225 out <<");" << std::endl;
226 } else {
227 out << "," << GetOptionString() <<");" << std::endl;
228 }
229 } else {
230 out << "," << GetOptionString() << ",ucolor);" << std::endl;
231 }
232 } else {
234 name += "/";
235 name += fImage->GetName();
236 name.Chop();
237 out << GetName() << " = new TGIcon(" << fParent->GetName() << ","
238 << quote << name.Data() << quote << ");" << std::endl;
239 }
240 if (option && strstr(option, "keep_names"))
241 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
242}
@ 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:2515
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#define gVirtualX
Definition TVirtualX.h:338
Bool_t IsEditable() const
Definition TGClient.h:89
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:372
TGPicturePool * GetPicturePool() const
Definition TGClient.h:126
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:308
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
UInt_t fHeight
frame height
Definition TGFrame.h:88
virtual void DrawBorder()
Draw frame border.
Definition TGFrame.cxx:421
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:683
virtual UInt_t GetOptions() const
Definition TGFrame.h:197
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2504
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition TGFrame.cxx:593
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:605
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:225
UInt_t GetWidth() const
Definition TGFrame.h:224
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2477
Pixel_t fBackground
frame background color
Definition TGFrame.h:95
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:775
This class handles GUI icons.
Definition TGIcon.h:22
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:166
virtual void DoRedraw()
Redraw picture.
Definition TGIcon.cxx:126
virtual ~TGIcon()
Delete icon and free picture.
Definition TGIcon.cxx:71
virtual void SetPicture(const TGPicture *pic)
Set icon picture.
Definition TGIcon.cxx:79
virtual void SetImage(const char *img)
Set icon image.
Definition TGIcon.cxx:89
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:203
const TGPicture * fPic
icon picture
Definition TGIcon.h:25
TImage * fImage
image
Definition TGIcon.h:26
virtual TGDimension GetDefaultSize() const
Return size of icon.
Definition TGIcon.cxx:117
TString fPath
directory of image
Definition TGIcon.h:27
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize.
Definition TGIcon.cxx:139
TGIcon(const TGIcon &)=delete
virtual void Reset()
Reset icon to original image. It can be used only via context menu.
Definition TGIcon.cxx:175
virtual void SetImagePath(const char *path)
Set directory where image is located.
Definition TGIcon.cxx:190
TGClient * fClient
Connection to display server.
Definition TGObject.h:27
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:26
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition TGPicture.cxx:82
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
const char * GetName() const
Returns name of object.
Definition TGPicture.h:51
UInt_t GetHeight() const
Definition TGPicture.h:53
void Draw(Option_t *="")
Default Draw method for all objects.
Definition TGPicture.h:46
UInt_t GetWidth() const
Definition TGPicture.h:52
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void SetWindowName(const char *name=0)
Set window name.
Definition TGWindow.cxx:129
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
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:963
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:1274
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition TSystem.cxx:1071
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition TSystem.cxx:1063
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:935
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1032
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17