Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : FLIST.HPP

 
Output of file : FLIST.HPP contained in archive : DOSUIT07.ZIP

// Lists of files and/or directories
#ifndef FLIST_HPP
#define FLIST_HPP
#ifdef __TURBOC__
#ifndef FIND
#include
#define FIND ffblk
#endif
#endif

#ifndef ITEMLIST_HPP
#include "list.hpp"
#endif
#ifndef TIME_HPP
#include "time.hpp"
#endif

/*
This enum is used for two purposes - to specify which FoundFiles
will appear in a Filelist, and to indicate the type of a particular
FoundFile.
*/
enum FileAttribute {
FAnone = 0,
FAreadable = BIT(0), // Set if you want non-readable files/dirs excluded.
FAwriteable = BIT(1), // Set if you want non-writeable files/dirs excluded.
FAfile = BIT(2), // Set if you want files included.
FAdirectory = BIT(3), // Set if you want directories included.
FAexcludedot = BIT(4), // Set if you DON'T want current dir included.
FAfixeddisk = BIT(5), // Set if you want hard disk letters including.
FAremovedisk = BIT(6), // Set if you want floppy disk letters including.
FAdisk = (FAfixeddisk|FAremovedisk),
FAdummy = BIT(7) // Used for dummy entries in FileList.
};

const int OSFileNameLen = 13;// Maximum length of the name part of a filename.
const int OSPathLen = 128; // Maximum length of a full path name.

/*
This class is used in FileLists, to hold information about a file,
directory or disk.
*/
class FoundFile : public ListElement {
public:
FoundFile(struct FIND *f); // Construct from findfirst().
FoundFile(char disk,int fixed); // Construct a disk entry.
FoundFile(const char *name,FileAttribute a = FAdummy,
const Time &time = Time::zero,unsigned long size = 0);
// Construct a user-defined FoundFile. The FAdummy attribute will
// always be set.
~FoundFile();
const char *fname() const
// Return the file name. Skips the first character of disk ([) and
// directory (\) names.
{ return attribute(FileAttribute(FAdirectory|FAdisk)) ? filename + 1 : filename; }
FileAttribute attribute(FileAttribute a = FileAttribute(~FAnone)) const { return FileAttribute(att & a); }
// Test to see if this FoundFile has any particular attributes. The
// default parameter returns all the attribute flags.
const Time &time() const { return tim; }
// Return the file time (zero for disk name entries).
unsigned long size() const { return siz; }
// Return the file size (0 for disk name entries).
virtual coord minwidth() const;
virtual void paint(const Rectangle &at, Window *w, const Rectangle &clip,
color col);

private:
void transfname(const char *fname);
char filename[OSFileNameLen + 1];
FileAttribute att;
Time tim;
unsigned long siz;
};

declare(LCollection,FoundFile);
declare(LIterator,FoundFile);

// Compare function for FileList::sort(). Sorts by name.
extern int sortname(const FoundFile *f1,const FoundFile *f2);

// Compare function for FileList::sort(). Sorts by extension.
extern int sortext(const FoundFile *f1,const FoundFile *f2);

// Compare function for FileList::sort(). Sorts by access time.
extern int sorttime(const FoundFile *f1,const FoundFile *f2);

// Compare function for FileList::sort(). Sortes by file size.
extern int sortsize(const FoundFile *f1,const FoundFile *f2);

// Return the directory part of a file name.
// Returns a pointer to an internal static buffer which is
// overwritten on the next call.
extern const char *dir(const char *p);

// Return the file part of a file name.
// Returns a pointer to the file part of its argument.
extern const char *file(const char *p);

// Construct a complete path name from the directory and file names.
// Returns a pointer to an internal static buffer which is
// overwritten on the next call.
extern const char *fullfilename(const char *directory,const char *file);

// Applies the DOS getfullname function to its argument.
// Overwrites the argument with DOS's idea of the correct file name.
extern void fixdirname(char *s);

/*
This is a list of FoundFiles, which can be displayed on the screen.
It is used to show the pop-down file/directory browse lists
associated with FileEdits and DirectoryEdits. It may also be used to
present a scrollable list of files in your own code.

If you are deriving a subclass to enable the user to pick a file or
directory from a list, you will probably want to override the pick
and escape virtual methods. They are called when the user selects an
item (by pressing or by double clicking on it), and when the
user presses Escape (or right-clicks on the list) respectively.
*/
class FileList : public List {
public:
FileList(coord height,
const char *fname = "*.*",
FileAttribute a = FileAttribute(FAfile|FAdirectory),
const char *n = "FileList",
const BorderFlag b = BorderFlag(BFsingle | BFtabstop));
// Fix the height. Include files matching fname, with attributes a. The
// default border is a single box, and the FileList is a tabstop.
FileList(const char *fname = "*.*",
FileAttribute a = FileAttribute(FAfile|FAdirectory),
const char *n = "FileList",
const BorderFlag b = BorderFlag(BFsingle | BFtabstop));
// As above, but the height will be set by a containing Cluster.
~FileList();
int addfiles(const char *fname = "*.*",
FileAttribute a = FileAttribute(FAfile|FAdirectory));
// Add files matching fname with attributes a to the FileList.
int addFile(FoundFile *f); // Add a single file to the list.
const FoundFile *selected() const { return files[line()]; }
// Return the FoundFile from the list that the user selected. Returns 0
// if no file is selected.
void sort(int (*compare)(const FoundFile *,const FoundFile *));
// Sort the FileList. The list will be maintained in order when new
// items are added to it. Suggested functions for compare are sortname,
// sortext, sorttime and sortsize.
int count() const { return files.size(); }
// Return the number of FoundFiles in the list.
protected:
LCollection(FoundFile) files;
};

#endif