/***********************************************************************
 * 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;


// File List options
enum {
  FILELIST_SHOWHIDDEN   = 0x04000000, /// Show hidden files or directories
  FILELIST_SHOWDIRS     = 0x08000000, /// Show only directories
  FILELIST_NO_OWN_ASSOC = 0x10000000  /// Do not create associations for files
  };


/// File item
class FXFileItem : public FXIconItem {
protected:
  FXFileAssoc   *assoc;                       /// File association record
  unsigned long  size;                        /// File size
  FXTime         date;                        /// File time
protected:
  FXFileItem();
protected:
  enum{
    FOLDER     = 64,                        /// Directory item
    EXECUTABLE = 128,                       /// Executable item
    SYMLINK    = 256,                       /// Symbolic linked item
    CHARDEV    = 512,                       /// Character special item
    BLOCKDEV   = 1024,                      /// Block special item
    FIFO       = 2048,                      /// FIFO item
    SOCK       = 4096                       /// Socket item
    };
public:
  %extend {
    /// Constructor
    FXFileItem(const FXString& text,FXIcon* bi=NULL,FXIcon* mi=NULL,void* ptr=NULL){
      return new FXRbFileItem(text,bi,mi,ptr);
      }
    }

  /// Return true if this is a file item
  FXbool isFile() const;

  /// Return true if this is a directory item
  FXbool isDirectory() const;

  /// Return true if this is an executable item
  FXbool isExecutable() const;

  /// Return true if this is a symbolic link item
  FXbool isSymlink() const;

  /// Return true if this is a character device item
  FXbool isChardev() const;

  /// Return true if this is a block device item
  FXbool isBlockdev() const;

  /// Return true if this is an FIFO item
  FXbool isFifo() const;

  /// Return true if this is a socket
  FXbool isSocket() const;

  /// Return the file-association object for this item
  FXFileAssoc* getAssoc() const;

  /// Return the file size for this item
  unsigned long getSize() const;

  /// Return the date for this item
  FXTime getDate() const;
  
  /// Destructor
  virtual ~FXFileItem();
  };


DECLARE_FXOBJECT_VIRTUALS(FXFileItem)
DECLARE_FXICONITEM_VIRTUALS(FXFileItem)


// Rename these methods
%rename(getHiddenFilesShown) FXFileList::showHiddenFiles() const;
%rename(setHiddenFilesShown) FXFileList::showHiddenFiles(FXbool showing);
%rename(getOnlyDirectoriesShown) FXFileList::showOnlyDirectories() const;
%rename(setOnlyDirectoriesShown) FXFileList::showOnlyDirectories(FXbool shown);

%typemap(check) FXint FILELIST_ITEM_INDEX {
  if ($1 < 0 || $1 >= arg1->getNumItems()) {
    rb_raise(rb_eIndexError, "file list item index out of bounds");
  }
}

%apply FXint FILELIST_ITEM_INDEX { FXint index };

/// File List object
class FXFileList : public FXIconList {
protected:
  FXString     directory;             // Current directory
  FXString     orgdirectory;          // Original directory
  FXString     dropdirectory;         // Drop directory
  FXDragAction dropaction;            // Drop action
  FXString     dragfiles;             // Dragged files
  FXFileDict  *associations;          // Association table
  FXString     pattern;               // Pattern of file names
  FXuint       matchmode;             // File wildcard match mode
  FXTime       timestamp;             // Time when last refreshed
  FXTimer     *refreshtimer;          // Refresh timer
  FXTimer     *opentimer;             // Open up folder when hovering
  FXIcon      *big_folder;            // Big folder icon
  FXIcon      *mini_folder;           // Mini folder icon
  FXIcon      *big_doc;               // Big document icon
  FXIcon      *mini_doc;              // Mini document icon
  FXIcon      *big_app;               // Big application icon
  FXIcon      *mini_app;              // Mini application icon
protected:
  FXFileList();
  virtual FXIconItem *createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr);
  void listDirectory();
public:
  long onRefreshTimer(FXObject*,FXSelector,void* PTR_IGNORE);
  long onOpenTimer(FXObject*,FXSelector,void* PTR_IGNORE);
  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 onBeginDrag(FXObject*,FXSelector,void* PTR_EVENT);
  long onEndDrag(FXObject*,FXSelector,void* PTR_EVENT);
  long onDragged(FXObject*,FXSelector,void* PTR_EVENT);
  long onCmdSetValue(FXObject*,FXSelector,void* PTR_CSTRING);
  long onCmdGetStringValue(FXObject*,FXSelector,void* PTR_STRING);
  long onCmdSetStringValue(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdDirectoryUp(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdDirectoryUp(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdSortByName(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdSortByName(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdSortByType(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdSortByType(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdSortBySize(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdSortBySize(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdSortByTime(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdSortByTime(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdSortByUser(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdSortByUser(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdSortByGroup(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdSortByGroup(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdSortReverse(FXObject*,FXSelector,void* PTR_IGNORE);
  long onUpdSortReverse(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdSetPattern(FXObject*,FXSelector,void* PTR_CSTRING);
  long onUpdSetPattern(FXObject*,FXSelector,void* PTR_IGNORE);
  long onCmdSetDirectory(FXObject*,FXSelector,void* PTR_CSTRING);
  long onUpdSetDirectory(FXObject*,FXSelector,void* PTR_IGNORE);
  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 onCmdHeader(FXObject*,FXSelector,void* PTR_UINT);
  long onUpdHeader(FXObject*,FXSelector,void* PTR_IGNORE);
public:
  static FXint cmpFName(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpRName(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpFType(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpRType(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpFSize(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpRSize(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpFTime(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpRTime(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpFUser(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpRUser(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpFGroup(const FXIconItem* pa,const FXIconItem* pb);
  static FXint cmpRGroup(const FXIconItem* pa,const FXIconItem* pb);
public:
  enum {
    ID_SORT_BY_NAME=FXIconList::ID_LAST,
    ID_SORT_BY_TYPE,
    ID_SORT_BY_SIZE,
    ID_SORT_BY_TIME,
    ID_SORT_BY_USER,
    ID_SORT_BY_GROUP,
    ID_SORT_REVERSE,
    ID_DIRECTORY_UP,
    ID_SET_PATTERN,
    ID_SET_DIRECTORY,
    ID_SHOW_HIDDEN,
    ID_HIDE_HIDDEN,
    ID_TOGGLE_HIDDEN,
    ID_REFRESHTIMER,
    ID_OPENTIMER,
    ID_LAST
    };
public:
  %extend {
    /// Construct a file list
    FXFileList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0){
      return new FXRbFileList(p,tgt,sel,opts,x,y,w,h);
      }
    }

  /// 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;

  /// Change wildcard matching pattern
  void setPattern(const FXString& ptrn);

  /// Return wildcard pattern
  FXString getPattern() const;

  /// Return TRUE if item is a directory
  FXbool isItemDirectory(FXint index) const;

  /// Return TRUE if item is a file
  FXbool isItemFile(FXint index) const;

  /// Return TRUE if item is executable
  FXbool isItemExecutable(FXint index) const;

  /// Return name of item at index
  FXString getItemFilename(FXint index) const;

  /// Return full pathname of item at index
  FXString getItemPathname(FXint index) const;
  
  /// Return file association of item
  FXFileAssoc* getItemAssoc(FXint index) const;

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

  /// Change wildcard matching mode
  void setMatchMode(FXuint mode);

  /// Return TRUE if showing hidden files 
  %name(getHiddenFilesShown) FXbool showHiddenFiles() const;
  
  /// Show or hide hidden files
  %name(setHiddenFilesShown) void showHiddenFiles(FXbool showing);
  
  /// Return TRUE if showing directories only
  %name(getOnlyDirectoriesShown) FXbool showOnlyDirectories() const;
  
  /// Show directories only
  %name(setOnlyDirectoriesShown) void showOnlyDirectories(FXbool shown);
  
  /// Change file associations
  void setAssociations(FXFileDict* assoc);
  
  /// Return file associations
  FXFileDict* getAssociations() const;

  /// Destructor
  virtual ~FXFileList();
  };

%clear FXint index;

DECLARE_FXOBJECT_VIRTUALS(FXFileList)
DECLARE_FXID_VIRTUALS(FXFileList)
DECLARE_FXDRAWABLE_VIRTUALS(FXFileList)
DECLARE_FXWINDOW_VIRTUALS(FXFileList)
DECLARE_FXSCROLLAREA_VIRTUALS(FXFileList)

