Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGFSContainer.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 19/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 #ifndef ROOT_TGFSContainer
13 #define ROOT_TGFSContainer
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGFileIcon, TGFileEntry, TGFSContainer //
19 // //
20 // Utility classes used by the file selection dialog (TGFileDialog). //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TGListView.h"
25 #include "TGDNDManager.h"
26 #include "TBufferFile.h"
27 
28 //----- file sort mode
29 enum EFSSortMode {
30  kSortByName,
31  kSortByType,
32  kSortBySize,
33  kSortByDate,
34  kSortByOwner,
35  kSortByGroup
36 };
37 
38 
39 class TRegexp;
40 class TGPicture;
41 class TGFileContainer;
42 class TViewUpdateTimer;
43 class TGFileIcon;
44 class TGFileItem;
45 class TTimer;
46 class TString;
47 struct FileStat_t;
48 
49 
50 class TGFileItem : public TGLVEntry {
51 
52 protected:
53  const TGPicture *fBlpic; // big icon
54  const TGPicture *fSlpic; // small icon
55  const TGPicture *fLcurrent; // current icon
56  Int_t fType; // file type
57  Int_t fUid, fGid; // file uid and gid
58  Bool_t fIsLink; // true if symbolic link
59  Long_t fModTime; // modification time
60  Long64_t fSize; // file size
61  TBufferFile *fBuf; // buffer used for Drag and Drop
62  TDNDData fDNDData; // Drag and Drop data
63 
64  void Init(const TGPicture *blpic, const TGPicture *slpic,
65  FileStat_t &stat, EListViewMode viewMode);
66  virtual void DoRedraw();
67 
68 public:
69  TGFileItem(const TGWindow *p = 0,
70  const TGPicture *bpic = 0, const TGPicture *blpic = 0,
71  const TGPicture *spic = 0, const TGPicture *slpic = 0,
72  TGString *name = 0, Int_t type = 0, Long64_t size = 1,
73  Int_t uid = 0, Int_t gid = 0, Long_t modtime = 0,
74  EListViewMode viewMode = kLVList, UInt_t options = kVerticalFrame,
75  Pixel_t back = GetWhitePixel());
76 
77  TGFileItem(const TGWindow *p,
78  const TGPicture *bpic, const TGPicture *blpic,
79  const TGPicture *spic, const TGPicture *slpic,
80  TGString *name, FileStat_t &stat,
81  EListViewMode viewMode = kLVList, UInt_t options = kVerticalFrame,
82  Pixel_t back = GetWhitePixel());
83 
84  virtual ~TGFileItem();
85 
86  virtual void SetViewMode(EListViewMode viewMode);
87 
88  Bool_t IsActive() const { return fActive; }
89  Bool_t IsSymLink() const { return fIsLink; }
90  Int_t GetType() const { return fType; }
91  Long64_t GetSize() const { return fSize; }
92  Long_t GetModTime() const { return fModTime; }
93  Int_t GetUid() const { return fUid; }
94  Int_t GetGid() const { return fGid; }
95 
96  virtual TDNDData *GetDNDdata(Atom_t) {
97  return &fDNDData;
98  }
99 
100  virtual Atom_t HandleDNDEnter(Atom_t *) {
101  if (!IsDNDTarget()) return kNone;
102  return gVirtualX->InternAtom("application/root", kFALSE);
103  }
104 
105  virtual Bool_t HandleDNDLeave() {
106  return kTRUE;
107  }
108 
109  virtual Atom_t HandleDNDPosition(int, int, Atom_t action, int, int) {
110  if (action == TGDNDManager::GetDNDActionCopy()) return action;
111  return kNone;
112  }
113 
114  virtual Bool_t HandleDNDFinished() {
115  return ((TGFrame *)(const_cast<TGWindow*>(GetParent())))->HandleDNDFinished();
116  }
117 
118  void SetDNDData(TDNDData *data) {
119  if (fDNDData.fDataLength > 0)
120  free(fDNDData.fData);
121  fDNDData.fData = calloc(sizeof(unsigned char), data->fDataLength);
122  if (fDNDData.fData)
123  memcpy(fDNDData.fData, data->fData, data->fDataLength);
124  fDNDData.fDataLength = data->fDataLength;
125  fDNDData.fDataType = data->fDataType;
126  }
127 
128  void SetDNDObject(TObject *obj) {
129  if (fDNDData.fDataLength)
130  free(fDNDData.fData);
131  fBuf->WriteObject(obj);
132  fDNDData.fData = fBuf->Buffer();
133  fDNDData.fDataLength = fBuf->Length();
134  fDNDData.fDataType = gVirtualX->InternAtom("application/root", kFALSE);
135  }
136 
137  ClassDef(TGFileItem,0) // Class representing file system object
138 };
139 
140 
141 class TGFileContainer : public TGLVContainer {
142 
143 friend class TGFSFrameElement;
144 
145 protected:
146  EFSSortMode fSortType; // sorting mode of contents
147  TRegexp *fFilter; // file filter
148  TViewUpdateTimer *fRefresh; // refresh timer
149  ULong_t fMtime; // directory modification time
150  TString fDirectory; // current directory
151  TList *fCleanups; // list of pictures to cleanup
152  const TGPicture *fFolder_t; // small folder icon
153  const TGPicture *fFolder_s; // big folder icon
154  const TGPicture *fApp_t; // small application icon
155  const TGPicture *fApp_s; // big application icon
156  const TGPicture *fDoc_t; // small document icon
157  const TGPicture *fDoc_s; // big document icon
158  const TGPicture *fSlink_t; // small symbolic link icon
159  const TGPicture *fSlink_s; // big symbolic link icon
160  Bool_t fCachePictures; // kTRUE use caching
161  Bool_t fDisplayStat; // kFALSE to interrupt display directory
162  // contents in case of many files inside
163 
164  void CreateFileList();
165 
166 public:
167  TGFileContainer(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
168  UInt_t options = kSunkenFrame,
169  Pixel_t back = GetDefaultFrameBackground());
170  TGFileContainer(TGCanvas *p, UInt_t options = kSunkenFrame,
171  Pixel_t back = GetDefaultFrameBackground());
172 
173  virtual ~TGFileContainer();
174 
175  virtual Bool_t HandleTimer(TTimer *t);
176  void StopRefreshTimer();
177  void StartRefreshTimer(ULong_t msec=1000);
178 
179  virtual TGFileItem *AddFile(const char *name, const TGPicture *pic = 0, const TGPicture *lpic = 0);
180  virtual TGFileItem *AddRemoteFile(TObject *obj, const TGPicture *ipic = 0, const TGPicture *ilpic = 0);
181  virtual void AddFrame(TGFrame *f, TGLayoutHints *l = 0);
182  virtual void Sort(EFSSortMode sortType);
183  virtual void SetFilter(const char *filter);
184  virtual void ChangeDirectory(const char *path);
185  virtual void DisplayDirectory();
186  virtual void SetDisplayStat(Bool_t stat = kTRUE) { fDisplayStat = stat; }
187  Bool_t GetDisplayStat() { return fDisplayStat; }
188 
189  const char *GetDirectory() const { return fDirectory.Data(); }
190 
191  virtual void GetFilePictures(const TGPicture **pic, const TGPicture **lpic,
192  Int_t file_type, Bool_t is_link, const char *ext,
193  Bool_t small);
194 
195  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
196 
197  ClassDef(TGFileContainer,0) // Container containing file system objects
198 };
199 
200 #endif