/***********************************************************************
 * FXRuby -- the Ruby language bindings for the FOX GUI toolkit.
 * Copyright (c) 2001-2003 by J. Lyle Johnson. All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * For further information please contact the author by e-mail
 * at "lyle@users.sourceforge.net".
 ***********************************************************************/

struct FXFileAssoc;
class  FXFileDict; 
class  FXIcon;


/// Directory List options
enum {
  DIRLIST_SHOWFILES     = 0x08000000, /// Show files as well as directories
  DIRLIST_SHOWHIDDEN    = 0x10000000, /// Show hidden files or directories
  DIRLIST_NO_OWN_ASSOC  = 0x20000000  /// Do not create associations for files
  };


/// Directory item
class FXDirItem : public FXTreeItem {
protected:
  FXDirItem    *iprev;
  FXDirItem    *inext;
  FXDirItem    *list;
  FXFileAssoc  *assoc;
  unsigned long size;
  FXTime        date;
protected:
  FXDirItem():iprev(NULL),inext(NULL),list(NULL),assoc(NULL),date(0){}
protected:
  enum {
    FOLDER      = 512,                // Directory item
    EXECUTABLE  = 1024,               // Executable item
    SYMLINK     = 2048,               // Symbolic linked item
    CHARDEV     = 4096,               // Character special item
    BLOCKDEV    = 8192,               // Block special item
    FIFO        = 16384,              // FIFO item
    SOCK        = 32768               // Socket item
    };
public:
  %extend {
    /// Constructor
    FXDirItem(const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL){
      return new FXRbDirItem(text,oi,ci,ptr);
      }
    }
  FXbool isDirectory() const;
  FXbool isExecutable() const;
  FXbool isSymlink() const;
  FXbool isChardev() const;
  FXbool isBlockdev() const;
  FXbool isFifo() const;
  FXbool isSocket() const;
  FXFileAssoc* getAssoc() const;
  unsigned long getSize() const;
  FXTime getDate() const;
  virtual ~FXDirItem();
  };


DECLARE_FXOBJECT_VIRTUALS(FXDirItem)
DECLARE_FXTREEITEM_VIRTUALS(FXDirItem)


// Rename these methods
%rename(getShowFiles) FXDirList::showFiles() const;
%rename(setShowFiles) FXDirList::showFiles(FXbool showing);
%rename(getShowHiddenFiles) FXDirList::showHiddenFiles() const;
%rename(setShowHiddenFiles) FXDirList::showHiddenFiles(FXbool showing);


/// Directory tree List
class FXDirList : public FXTreeList {
protected:
  FXFileDict   *associations;         // Association table
  FXString      dropdirectory;        // Drop directory
  FXDragAction  dropaction;           // Drop action
  FXString      dragfiles;            // Dragged files
  FXString      pattern;              // Pattern of file names
  FXuint        matchmode;            // File wildcard match mode
  FXTimer      *refresh;              // Refresh timer
  FXIcon       *closed_folder;        // Closed folder icon
  FXIcon       *open_folder;          // Open folder icon
  FXIcon       *mini_doc;             // Document icon
  FXIcon       *mini_app;             // Application icon
  FXIcon       *cdromicon;
  FXIcon       *harddiskicon;
  FXIcon       *networkicon;
  FXIcon       *floppyicon;
  FXIcon       *zipdiskicon;
  FXuint        counter;              // Refresh counter
protected:
  FXDirList();
  virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
  FXchar *getpath(const FXTreeItem* item,FXchar* pathname) const;
  FXTreeItem* getitem(FXchar* pathname);
  FXbool scanRootDir(FXbool relist);
  FXbool scanSubDir(FXDirItem *par,FXchar *pathname,FXbool relist);
  FXbool listSubDir(FXDirItem *par,FXchar *pathname);
  FXbool listRoots();
public:
  long onRefresh(FXObject*,FXSelector,void* PTR_IGNORE);
  long onBeginDrag(FXObject*,FXSelector,void* PTR_EVENT);
  long onEndDrag(FXObject*,FXSelector,void* PTR_EVENT);
  long onDragged(FXObject*,FXSelector,void* PTR_EVENT);
  long onDNDEnter(FXObject*,FXSelector,void* PTR_EVENT);
  long onDNDLeave(FXObject*,FXSelector,void* PTR_EVENT);
  long onDNDMotion(FXObject*,FXSelector,void* PTR_EVENT);
  long onDNDDrop(FXObject*,FXSelector,void* PTR_EVENT);
  long onDNDRequest(FXObject*,FXSelector,void* PTR_EVENT);
  long onOpened(FXObject*,FXSelector,void* PTR_DIRITEM);
  long onClosed(FXObject*,FXSelector,void* PTR_DIRITEM);
  long onExpanded(FXObject*,FXSelector,void* PTR_DIRITEM);
  long onCollapsed(FXObject*,FXSelector,void* PTR_DIRITEM);
  long onCmdSetValue(FXObject*,FXSelector,void* PTR_CSTRING);
  long onCmdSetStringValue(FXObject*,FXSelector,void* PTR_STRING);
  long onCmdGetStringValue(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdToggleHidden(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdToggleHidden(FXObject*,FXSelector,void* PTR_IGNORE);
  long onCmdShowHidden(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdShowHidden(FXObject*,FXSelector,void* PTR_IGNORE);
  long onCmdHideHidden(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdHideHidden(FXObject*,FXSelector,void* PTR_IGNORE);
  long onCmdToggleFiles(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdToggleFiles(FXObject*,FXSelector,void* PTR_IGNORE);
  long onCmdShowFiles(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdShowFiles(FXObject*,FXSelector,void* PTR_IGNORE);
  long onCmdHideFiles(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdHideFiles(FXObject*,FXSelector,void* PTR_IGNORE);
  long onCmdSetPattern(FXObject*,FXSelector,void* PTR_CSTRING);
  long onUpdSetPattern(FXObject*,FXSelector,void* PTR_IGNORE);
  long onCmdSortReverse(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdSortReverse(FXObject*,FXSelector,void* PTR_NULL); // FIXME
public:
  static FXint cmpFName(const FXTreeItem* a,const FXTreeItem* b);
  static FXint cmpRName(const FXTreeItem* pa,const FXTreeItem* pb);
public:
  enum {
    ID_REFRESH=FXTreeList::ID_LAST,
    ID_SHOW_FILES,
    ID_HIDE_FILES,
    ID_TOGGLE_FILES,
    ID_SHOW_HIDDEN,
    ID_HIDE_HIDDEN,
    ID_TOGGLE_HIDDEN,
    ID_SET_PATTERN,
    ID_SORT_REVERSE,
    ID_LAST
    };
public:
  %extend {
    /// Construct a directory list
    FXDirList(FXComposite *p,FXint nvis,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0){
      return new FXRbDirList(p,nvis,tgt,sel,opts,x,y,w,h);
      }
    }

  /// Return TRUE if item is a directory
  FXbool isItemDirectory(const FXTreeItem* item) const;
  
  /// Return TRUE if item is a file
  FXbool isItemFile(const FXTreeItem* item) const;
  
  /// Return TRUE if item is executable
  FXbool isItemExecutable(const FXTreeItem* item) const;
  
  /// Set current file
  void setCurrentFile(const FXString& file);
  
  /// Return current file
  FXString getCurrentFile() const;
  
  /// Set current directory
  void setDirectory(const FXString& path);
  
  /// Return current directory
  FXString getDirectory() const;
  
  /// Return name of item 
  FXString getItemFilename(const FXTreeItem* item) const;
  
  /// Return full pathname of item
  FXString getItemPathname(const FXTreeItem* item) const;
  
  /// Change wildcard matching pattern
  void setPattern(const FXString& ptrn);
  
  /// Return wildcard pattern
  FXString getPattern() const;

  /// Return wildcard matching mode
  FXuint getMatchMode() const;

  /// Change wildcard matching mode
  void setMatchMode(FXuint mode);
  
  /// Return TRUE if showing files as well as directories
  FXbool showFiles() const;
  
  /// Show or hide normal files
  void showFiles(FXbool showing);

  /// Return TRUE if showing hidden files and directories
  FXbool showHiddenFiles() const;
  
  /// Show or hide hidden files and directories
  void showHiddenFiles(FXbool showing);
  
  /// Change file associations
  void setAssociations(FXFileDict* assoc);
  
  /// Return file associations
  FXFileDict* getAssociations() const;
  
  /// Destructor
  virtual ~FXDirList();
  };


DECLARE_FXOBJECT_VIRTUALS(FXDirList)
DECLARE_FXID_VIRTUALS(FXDirList)
DECLARE_FXDRAWABLE_VIRTUALS(FXDirList)
DECLARE_FXWINDOW_VIRTUALS(FXDirList)
DECLARE_FXSCROLLAREA_VIRTUALS(FXDirList)
DECLARE_FXTREELIST_VIRTUALS(FXDirList)

