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
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
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;
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{
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 if (!fPic) {
205 Error("SavePrimitive()", "icon pixmap not found ");
206 return;
207 }
208
209 if (!fImage) {
210 // save options and color if necessary
211 auto extra_args = SaveCtorArgs(out);
212
213 TString picname = gSystem->UnixPathName(fPic->GetName());
215
216 out << " TGIcon *" << GetName() << " = new TGIcon(" << fParent->GetName() << ", gClient->GetPicture(\""
217 << picname.ReplaceSpecialCppChars() << "\"), " << GetWidth() << "," << GetHeight() << extra_args << ");\n";
218 } else {
220 name += "/";
221 name += fImage->GetName();
222 name.Chop();
223 out << " TGIcon *" << GetName() << " = new TGIcon(" << fParent->GetName() << ", \""
224 << name.ReplaceSpecialCppChars() << "\");\n";
225 }
226 if (option && strstr(option, "keep_names"))
227 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
228}
@ 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
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
char name[80]
Definition TGX11.cxx:110
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2563
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define gVirtualX
Definition TVirtualX.h:337
Bool_t IsEditable() const
Definition TGClient.h:89
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:380
TGPicturePool * GetPicturePool() const
Definition TGClient.h:126
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:316
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
UInt_t fHeight
frame height
Definition TGFrame.h:88
virtual void DrawBorder()
Draw frame border.
Definition TGFrame.cxx:413
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:585
virtual UInt_t GetOptions() const
Definition TGFrame.h:199
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
TString SaveCtorArgs(std::ostream &out, UInt_t dflt_options=kChildFrame, Bool_t check_white_pixel=kFALSE)
Return options and custom color as constructor args Used in the SavePrimitive methods,...
Definition TGFrame.cxx:2493
UInt_t GetWidth() const
Definition TGFrame.h:226
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:767
void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0) override
Move icon to (x,y) and resize it to (w,h).
Definition TGIcon.cxx:165
~TGIcon() override
Delete icon and free picture.
Definition TGIcon.cxx:70
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save an icon widget as a C++ statement(s) on output stream out.
Definition TGIcon.cxx:202
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
const TGPicture * fPic
icon picture
Definition TGIcon.h:25
TImage * fImage
image
Definition TGIcon.h:26
void DoRedraw() override
Redraw picture.
Definition TGIcon.cxx:125
TString fPath
directory of image
Definition TGIcon.h:27
void Resize(UInt_t w=0, UInt_t h=0) override
Resize.
Definition TGIcon.cxx:138
TGIcon(const TGIcon &)=delete
TGDimension GetDefaultSize() const override
Return size of icon.
Definition TGIcon.cxx:116
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
Connection to display server.
Definition TGObject.h:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition TGPicture.cxx:80
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
ROOT GUI Window base class.
Definition TGWindow.h:23
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:127
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:334
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:117
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
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1285
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1082
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition TSystem.cxx:1073
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:944
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1042
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17