/**************************************************************************

    This file is part of desktop95, a desktop manager for fvwm95.
    Copyright (C) 1996, 1997 David Barth, Hector Peraza.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

**************************************************************************/

#ifndef __OXFOLDER_H
#define __OXFOLDER_H

#include <X11/Xlib.h>

#include <xclass/OXFrame.h>
#include <xclass/OXWidgets.h>
#include <xclass/OXListView.h>
#include <xclass/OString.h>
#include <xclass/OPicture.h>
#include <xclass/OMimeTypes.h>


#define PRESSED       1
#define RELEASED      2


//----- sort types

#define SORT_BY_NAME  0
#define SORT_BY_TYPE  1
#define SORT_BY_SIZE  2
#define SORT_BY_DATE  3


extern OXPopupMenu *objectMenu;

//-------------------------------------------------------------------

class OXFolderIcon : public OXIcon {
public:
  OXFolderIcon(const OXWindow *p, const OPicture *pic, int w, int h,
               unsigned int options = VERTICAL_FRAME,
               unsigned long back = _whitePixel) :
    OXIcon(p, pic, w, h, options, back) { _active = False; _selpic = NULL; }
  virtual ~OXFolderIcon();

  void Activate(int a);

protected:
  virtual void _DoRedraw();

  OSelectedPicture *_selpic;
  int _active;
};

class OXFolderLabel : public OXLabel {
protected:
  static GC _defaultGC;
  static XFontStruct *_defaultFontStruct;

public:
  OXFolderLabel(const OXWindow *p, OString *text,
                GC norm = _defaultGC,
                XFontStruct *font = _defaultFontStruct,
                unsigned int options = VERTICAL_FRAME,
                unsigned long back = _whitePixel) :
    OXLabel(p, text, norm, font, options, back) { _active = False; }

  void Activate(int a);

  friend class OXDesktopClient;

protected:
  virtual void _DoRedraw();
     
  int _active;
};

//-------------------------------------------------------------------

class OXFolder : public OXCompositeFrame {
protected:
  static Cursor _defaultCursor;

public:
  OXFolder(const OXWindow *p, const OPicture *pic, OString *name, char *fname,
           int type, unsigned long size, int w, int h,
           unsigned int options = VERTICAL_FRAME,
           unsigned long back = _whitePixel);
  virtual ~OXFolder();

  void Activate(int a);
  int IsActive() const { return _active; }
  const OString *GetName() const { return _label->GetText(); }
  int GetType() const { return _type; }
  int GetSize() const { return _size; }
  virtual void Layout();

//+++
  virtual int HandleButton(XButtonEvent *event);
  virtual int HandleMotion(XMotionEvent *event);
  virtual int HandleDoubleClick(XButtonEvent *event);

  void SetFileWindow(OXFrame *f) { _fw = f; }
  void InitPos();

  friend class OXDesktopClient;

protected:
  OXFolderIcon *_icon;
  OXFolderLabel *_label;
  int _active, _type;
  int x0, y0, bx, by, _buttonState;
  unsigned long _size;
  char *_myname;

  OXFrame *_fw;

  void Init();
  void SaveNewPos();
};

//-------------------------------------------------------------------

typedef struct folderlist_type {
  OXFolder *folder;
  folderlist_type *next;
} folderList;

class OXFolderContainer : public OXCompositeFrame {
protected:
  static GC _lineGC;

public:
  OXFolderContainer(const OXWindow *p, int w, int h,
                    unsigned int options = SUNKEN_FRAME,
                    unsigned long back = _defaultFrameBackground);

  virtual void AddFolder(const OPicture *icon, OString *name, char *fname,
                         int type, unsigned long size);
  virtual int HandleButton(XButtonEvent *event);
  virtual int HandleDoubleClick(XButtonEvent *event);
  virtual int HandleMotion(XMotionEvent *event);

  void Sort(int sortType);
  void ChangeDirectory(OString *path);
  void DisplayDirectory();
  void RemoveAllFolders();
  void UnselectAll();

  void ArrangeFolders();

  friend class OXDesktopClient;

private:
  const OPicture *FolderPic(char *f_name, int *type, unsigned long *size);
  SListFrameElt **_doSort(SListFrameElt **head, int n);
  int _compare(SListFrameElt *p1, SListFrameElt *p2);
  void CreateFolders();

protected:
  OMimeTypes *MimeTypesList;       // currently we need this for OXFileDialog
  folderList *_firstfolder;

  OXFolder *_last_active;
  OXPopupMenu *_popup, *_subpopup;

  int _xp, _yp, _x0, _xf, _y0, _yf;
  int _total, _selected, _dragging;
  int _sortType;
};


#endif
