ROOT logo
// @(#)root/gui:$Id: TGFSContainer.h 36090 2010-10-05 17:32:34Z rdm $
// Author: Fons Rademakers   19/01/98

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGFSContainer
#define ROOT_TGFSContainer


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGFileIcon, TGFileEntry, TGFSContainer                               //
//                                                                      //
// Utility classes used by the file selection dialog (TGFileDialog).    //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGListView
#include "TGListView.h"
#endif
#ifndef ROOT_TDNDManager
#include "TGDNDManager.h"
#endif
#ifndef ROOT_TBufferFile
#include "TBufferFile.h"
#endif
#include <stdlib.h>

//----- file sort mode
enum EFSSortMode {
   kSortByName,
   kSortByType,
   kSortBySize,
   kSortByDate,
   kSortByOwner,
   kSortByGroup
};


class TRegexp;
class TGPicture;
class TGFileContainer;
class TViewUpdateTimer;
class TGFileIcon;
class TGFileItem;
class TTimer;
class TString;
struct FileStat_t;


class TGFileItem : public TGLVEntry {

protected:
   const TGPicture  *fBlpic;        // big icon
   const TGPicture  *fSlpic;        // small icon
   const TGPicture  *fLcurrent;     // current icon
   Int_t             fType;         // file type
   Int_t             fUid, fGid;    // file uid and gid
   Bool_t            fIsLink;       // true if symbolic link
   Long_t            fModTime;      // modification time
   Long64_t          fSize;         // file size
   TBufferFile      *fBuf;          // buffer used for Drag and Drop
   TDNDData          fDNDData;      // Drag and Drop data

   void         Init(const TGPicture *blpic, const TGPicture *slpic,
                     FileStat_t &stat, EListViewMode viewMode);
   virtual void DoRedraw();

public:
   TGFileItem(const TGWindow *p = 0,
              const TGPicture *bpic = 0, const TGPicture *blpic = 0,
              const TGPicture *spic = 0, const TGPicture *slpic = 0,
              TGString *name = 0, Int_t type = 0, Long64_t size = 1,
              Int_t uid = 0, Int_t gid = 0, Long_t modtime = 0,
              EListViewMode viewMode = kLVList, UInt_t options = kVerticalFrame,
              Pixel_t back = GetWhitePixel());

   TGFileItem(const TGWindow *p,
              const TGPicture *bpic, const TGPicture *blpic,
              const TGPicture *spic, const TGPicture *slpic,
              TGString *name, FileStat_t &stat,
              EListViewMode viewMode = kLVList, UInt_t options = kVerticalFrame,
              Pixel_t back = GetWhitePixel());

   virtual ~TGFileItem();

   virtual void SetViewMode(EListViewMode viewMode);

   Bool_t   IsActive() const { return fActive; }
   Bool_t   IsSymLink() const { return fIsLink; }
   Int_t    GetType() const { return fType; }
   Long64_t GetSize() const { return fSize; }
   Long_t   GetModTime() const { return fModTime; }
   Int_t    GetUid() const { return fUid; }
   Int_t    GetGid() const { return fGid; }

   virtual TDNDData *GetDNDdata(Atom_t) {
      return &fDNDData;
   }

   virtual Atom_t HandleDNDEnter(Atom_t *) {
      if (!IsDNDTarget()) return kNone;
      return gVirtualX->InternAtom("application/root", kFALSE);
   }

   virtual Bool_t HandleDNDLeave() {
      return kTRUE;
   }

   virtual Atom_t HandleDNDPosition(int, int, Atom_t action, int, int) {
      if (action == TGDNDManager::GetDNDActionCopy()) return action;
      return kNone;
   }

   virtual Bool_t HandleDNDFinished() {
      return ((TGFrame *)(const_cast<TGWindow*>(GetParent())))->HandleDNDFinished();
   }

   void SetDNDData(TDNDData *data) {
      if (fDNDData.fDataLength > 0)
         free(fDNDData.fData);
      fDNDData.fData = calloc(sizeof(unsigned char), data->fDataLength);
      memcpy(fDNDData.fData, data->fData, data->fDataLength);
      fDNDData.fDataLength = data->fDataLength;
      fDNDData.fDataType = data->fDataType;
   }

   void SetDNDObject(TObject *obj) {
      if (fDNDData.fDataLength)
         free(fDNDData.fData);
      fBuf->WriteObject(obj);
      fDNDData.fData = fBuf->Buffer();
      fDNDData.fDataLength = fBuf->Length();
      fDNDData.fDataType = gVirtualX->InternAtom("application/root", kFALSE);
   }

   ClassDef(TGFileItem,0)   // Class representing file system object
};


class TGFileContainer : public TGLVContainer {

friend class TGFSFrameElement;

protected:
   EFSSortMode       fSortType;       // sorting mode of contents
   TRegexp          *fFilter;         // file filter
   TViewUpdateTimer *fRefresh;        // refresh timer
   ULong_t           fMtime;          // directory modification time
   TString           fDirectory;      // current directory
   TList            *fCleanups;       // list of pictures to cleanup
   const TGPicture  *fFolder_t;       // small folder icon
   const TGPicture  *fFolder_s;       // big folder icon
   const TGPicture  *fApp_t;          // small application icon
   const TGPicture  *fApp_s;          // big application icon
   const TGPicture  *fDoc_t;          // small document icon
   const TGPicture  *fDoc_s;          // big document icon
   const TGPicture  *fSlink_t;        // small symbolic link icon
   const TGPicture  *fSlink_s;        // big symbolic link icon
   Bool_t            fCachePictures;  // kTRUE use caching
   Bool_t            fDisplayStat;    // kFALSE to interrupt display directory
                                      // contents in case of many files inside

   void CreateFileList();

public:
   TGFileContainer(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
                   UInt_t options = kSunkenFrame,
                   Pixel_t back = GetDefaultFrameBackground());
   TGFileContainer(TGCanvas *p, UInt_t options = kSunkenFrame,
                   Pixel_t back = GetDefaultFrameBackground());

   virtual ~TGFileContainer();

   virtual Bool_t HandleTimer(TTimer *t);
   void StopRefreshTimer();
   void StartRefreshTimer(ULong_t msec=1000);

   virtual TGFileItem *AddFile(const char *name, const TGPicture *pic = 0, const TGPicture *lpic = 0);
   virtual TGFileItem *AddRemoteFile(TObject *obj, const TGPicture *ipic = 0, const TGPicture *ilpic = 0);
   virtual void AddFrame(TGFrame *f, TGLayoutHints *l = 0);
   virtual void Sort(EFSSortMode sortType);
   virtual void SetFilter(const char *filter);
   virtual void ChangeDirectory(const char *path);
   virtual void DisplayDirectory();
   virtual void SetDisplayStat(Bool_t stat = kTRUE) { fDisplayStat = stat; }
   Bool_t       GetDisplayStat() { return fDisplayStat; }

   const char *GetDirectory() const { return fDirectory.Data(); }

   virtual void GetFilePictures(const TGPicture **pic, const TGPicture **lpic,
                                Int_t file_type, Bool_t is_link, const char *ext,
                                Bool_t small);

   virtual void SavePrimitive(ostream &out, Option_t *option = "");

   ClassDef(TGFileContainer,0)  // Container containing file system objects
};

#endif
 TGFSContainer.h:1
 TGFSContainer.h:2
 TGFSContainer.h:3
 TGFSContainer.h:4
 TGFSContainer.h:5
 TGFSContainer.h:6
 TGFSContainer.h:7
 TGFSContainer.h:8
 TGFSContainer.h:9
 TGFSContainer.h:10
 TGFSContainer.h:11
 TGFSContainer.h:12
 TGFSContainer.h:13
 TGFSContainer.h:14
 TGFSContainer.h:15
 TGFSContainer.h:16
 TGFSContainer.h:17
 TGFSContainer.h:18
 TGFSContainer.h:19
 TGFSContainer.h:20
 TGFSContainer.h:21
 TGFSContainer.h:22
 TGFSContainer.h:23
 TGFSContainer.h:24
 TGFSContainer.h:25
 TGFSContainer.h:26
 TGFSContainer.h:27
 TGFSContainer.h:28
 TGFSContainer.h:29
 TGFSContainer.h:30
 TGFSContainer.h:31
 TGFSContainer.h:32
 TGFSContainer.h:33
 TGFSContainer.h:34
 TGFSContainer.h:35
 TGFSContainer.h:36
 TGFSContainer.h:37
 TGFSContainer.h:38
 TGFSContainer.h:39
 TGFSContainer.h:40
 TGFSContainer.h:41
 TGFSContainer.h:42
 TGFSContainer.h:43
 TGFSContainer.h:44
 TGFSContainer.h:45
 TGFSContainer.h:46
 TGFSContainer.h:47
 TGFSContainer.h:48
 TGFSContainer.h:49
 TGFSContainer.h:50
 TGFSContainer.h:51
 TGFSContainer.h:52
 TGFSContainer.h:53
 TGFSContainer.h:54
 TGFSContainer.h:55
 TGFSContainer.h:56
 TGFSContainer.h:57
 TGFSContainer.h:58
 TGFSContainer.h:59
 TGFSContainer.h:60
 TGFSContainer.h:61
 TGFSContainer.h:62
 TGFSContainer.h:63
 TGFSContainer.h:64
 TGFSContainer.h:65
 TGFSContainer.h:66
 TGFSContainer.h:67
 TGFSContainer.h:68
 TGFSContainer.h:69
 TGFSContainer.h:70
 TGFSContainer.h:71
 TGFSContainer.h:72
 TGFSContainer.h:73
 TGFSContainer.h:74
 TGFSContainer.h:75
 TGFSContainer.h:76
 TGFSContainer.h:77
 TGFSContainer.h:78
 TGFSContainer.h:79
 TGFSContainer.h:80
 TGFSContainer.h:81
 TGFSContainer.h:82
 TGFSContainer.h:83
 TGFSContainer.h:84
 TGFSContainer.h:85
 TGFSContainer.h:86
 TGFSContainer.h:87
 TGFSContainer.h:88
 TGFSContainer.h:89
 TGFSContainer.h:90
 TGFSContainer.h:91
 TGFSContainer.h:92
 TGFSContainer.h:93
 TGFSContainer.h:94
 TGFSContainer.h:95
 TGFSContainer.h:96
 TGFSContainer.h:97
 TGFSContainer.h:98
 TGFSContainer.h:99
 TGFSContainer.h:100
 TGFSContainer.h:101
 TGFSContainer.h:102
 TGFSContainer.h:103
 TGFSContainer.h:104
 TGFSContainer.h:105
 TGFSContainer.h:106
 TGFSContainer.h:107
 TGFSContainer.h:108
 TGFSContainer.h:109
 TGFSContainer.h:110
 TGFSContainer.h:111
 TGFSContainer.h:112
 TGFSContainer.h:113
 TGFSContainer.h:114
 TGFSContainer.h:115
 TGFSContainer.h:116
 TGFSContainer.h:117
 TGFSContainer.h:118
 TGFSContainer.h:119
 TGFSContainer.h:120
 TGFSContainer.h:121
 TGFSContainer.h:122
 TGFSContainer.h:123
 TGFSContainer.h:124
 TGFSContainer.h:125
 TGFSContainer.h:126
 TGFSContainer.h:127
 TGFSContainer.h:128
 TGFSContainer.h:129
 TGFSContainer.h:130
 TGFSContainer.h:131
 TGFSContainer.h:132
 TGFSContainer.h:133
 TGFSContainer.h:134
 TGFSContainer.h:135
 TGFSContainer.h:136
 TGFSContainer.h:137
 TGFSContainer.h:138
 TGFSContainer.h:139
 TGFSContainer.h:140
 TGFSContainer.h:141
 TGFSContainer.h:142
 TGFSContainer.h:143
 TGFSContainer.h:144
 TGFSContainer.h:145
 TGFSContainer.h:146
 TGFSContainer.h:147
 TGFSContainer.h:148
 TGFSContainer.h:149
 TGFSContainer.h:150
 TGFSContainer.h:151
 TGFSContainer.h:152
 TGFSContainer.h:153
 TGFSContainer.h:154
 TGFSContainer.h:155
 TGFSContainer.h:156
 TGFSContainer.h:157
 TGFSContainer.h:158
 TGFSContainer.h:159
 TGFSContainer.h:160
 TGFSContainer.h:161
 TGFSContainer.h:162
 TGFSContainer.h:163
 TGFSContainer.h:164
 TGFSContainer.h:165
 TGFSContainer.h:166
 TGFSContainer.h:167
 TGFSContainer.h:168
 TGFSContainer.h:169
 TGFSContainer.h:170
 TGFSContainer.h:171
 TGFSContainer.h:172
 TGFSContainer.h:173
 TGFSContainer.h:174
 TGFSContainer.h:175
 TGFSContainer.h:176
 TGFSContainer.h:177
 TGFSContainer.h:178
 TGFSContainer.h:179
 TGFSContainer.h:180
 TGFSContainer.h:181
 TGFSContainer.h:182
 TGFSContainer.h:183
 TGFSContainer.h:184
 TGFSContainer.h:185
 TGFSContainer.h:186
 TGFSContainer.h:187
 TGFSContainer.h:188
 TGFSContainer.h:189
 TGFSContainer.h:190
 TGFSContainer.h:191
 TGFSContainer.h:192
 TGFSContainer.h:193
 TGFSContainer.h:194
 TGFSContainer.h:195
 TGFSContainer.h:196
 TGFSContainer.h:197
 TGFSContainer.h:198
 TGFSContainer.h:199
 TGFSContainer.h:200
 TGFSContainer.h:201
 TGFSContainer.h:202
 TGFSContainer.h:203
 TGFSContainer.h:204
 TGFSContainer.h:205
 TGFSContainer.h:206