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

    This file is part of Xclass95, a Win95-looking GUI toolkit.
    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 __OXLISTVIEW_H
#define __OXLISTVIEW_H

#include <X11/Xlib.h>

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


#define LV_LARGE_ICONS  0
#define LV_SMALL_ICONS  1
#define LV_LIST         2
#define LV_DETAILS      3


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

class OSelectedPicture : public OPicture {
protected:
  static GC _selectedGC;

public:
  OSelectedPicture(const OXClient *client, const OPicture *p);
  virtual ~OSelectedPicture();

  friend class OXClient;

protected:
  const OXClient *_client;
};

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

class OXListItem : public OXFrame {
protected:
  static unsigned int _selPixel;
  static GC _defaultGC;
  static XFontStruct *_defaultFontStruct;
  GC _normGC;
  XFontStruct *_fontStruct;

public:
  OXListItem(const OXWindow *p,
             const OPicture *bigpic, const OPicture *smallpic, 
             OString *name, OString **subnames, int ViewMode,
             unsigned int options = CHILD_FRAME,
             unsigned long back = _whitePixel);
  virtual ~OXListItem();

  virtual void SetViewMode(int ViewMode);

  void Activate(int a);
  int IsActive() const { return _active; }
  const OString *GetName() const { return _name; }
  const OPicture *GetPicture() const { return _current; }

  void SetColumns(int *cpos, int *jmode) { _cpos = cpos; _jmode = jmode; }

  virtual ODimension GetDefaultSize() const;

//  void DoEdit() { _label->DoEdit(); }

  friend class OXClient;

protected:
  virtual void _DoRedraw();

  OString *_name, **_subnames;
  int _active, _tw, _th, _viewMode, *_cpos, *_jmode, *_ctw;
  const OPicture *_bigpic, *_smallpic, *_current;
  OSelectedPicture *_selpic;
};

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

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

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

  virtual void AddItem(OXListItem *item)
    { AddFrame(item, _itemLayout); item->SetColumns(_cpos, _jmode); }
  virtual int HandleButton(XButtonEvent *event);
  virtual int HandleDoubleClick(XButtonEvent *event);
  virtual int HandleMotion(XMotionEvent *event);

  virtual void Associate(const OXWindow *w) { _msgWindow = w; }

  virtual void SelectAll();
  virtual void UnSelectAll();
  virtual void InvertSelection();
  virtual void RemoveAll();

  virtual void SetViewMode(int ViewMode);
  virtual void SetColumns(int *cpos, int *jmode);

  virtual const OXListItem *GetNextSelected(void **current);
  virtual int NumItems() const { return _total; }
  virtual int NumSelected() const { return _selected; }

  virtual ODimension GetMaxItemSize() const;

  friend class OXClient;

protected:
  const OXWindow *_msgWindow;
  OXListItem *_last_active;
  OLayoutHints *_itemLayout;
  int _viewMode, *_cpos, *_jmode;
  int _xp, _yp, _x0, _xf, _y0, _yf;
  int _total, _selected, _dragging;
};

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

class OXListView : public OXCanvas {
protected:
  static GC _defaultGC;
  static XFontStruct *_defaultFontStruct;

public:
  OXListView(const OXWindow *p, int w, int h,
             unsigned int options = SUNKEN_FRAME | DOUBLE_BORDER,
             unsigned long back = _defaultFrameBackground);
  virtual ~OXListView();

  virtual void Layout();
  virtual void SetViewMode(int ViewMode);
  virtual int ProcessMessage(long msg, long parm1, long parm2);
  virtual void SetContainer(OXFrame *f);

  friend class OXClient;

protected:
  int _viewMode, _columns[7], _jmode[7];
  ODimension _maxsize;
  OXTextButton *_col_header[7]; // for test only...
};


#endif  // __OXLISTVIEW_H
