/***********************************************************************
 * 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".
 ***********************************************************************/

/***********************************************************************
 * $Id: FXRbList.h,v 1.6.2.4 2003/02/20 16:43:06 lyle Exp $
 ***********************************************************************/

#ifndef FXRBLIST_H
#define FXRBLIST_H

#define DECLARE_FXLISTITEM_STUBS(klass) \
inline void klass ## _create(klass* self){ \
  self->klass::create(); \
  } \
inline void klass ## _detach(klass* self){ \
  self->klass::detach(); \
  } \
inline void klass ## _destroy(klass* self){ \
  self->klass::destroy(); \
  } \
inline void klass ## _setText(klass* self,const FXString& text){ \
  self->klass::setText(text); \
  } \
inline void klass ## _setIcon(klass* self,FXIcon* icn){ \
  self->klass::setIcon(icn); \
  } \
inline void klass ## _setFocus(klass* self,FXbool focus){ \
  self->klass::setFocus(focus); \
  } \
inline void klass ## _setSelected(klass* self,FXbool selected){ \
  self->klass::setSelected(selected); \
  } \
inline void klass ## _setEnabled(klass* self,FXbool enabled){ \
  self->klass::setEnabled(enabled); \
  } \
inline void klass ## _setDraggable(klass* self,FXbool draggable){ \
  self->klass::setDraggable(draggable); \
  } \
inline void klass ## _setIconOwned(klass* self,FXuint owned){ \
  self->klass::setIconOwned(owned); \
  } \
inline FXint klass ## _getWidth(const klass* self,const FXList* list){ \
  return self->klass::getWidth(list); \
  } \
inline FXint klass ## _getHeight(const klass* self,const FXList* list){ \
  return self->klass::getHeight(list); \
  }


#define IMPLEMENT_FXLISTITEM_STUBS(cls) \
  void cls::create(){ \
    FXRbCallVoidMethod(this,rb_intern("create")); \
    } \
  void cls::detach(){ \
    FXRbCallVoidMethod(this,rb_intern("detach")); \
    } \
  void cls::destroy(){ \
    FXRbCallVoidMethod(this,rb_intern("destroy")); \
    } \
  void cls::setText(const FXString& txt){ \
    FXRbCallVoidMethod(this,rb_intern("setText"),txt); \
    } \
  void cls::setIcon(FXIcon* icn){ \
    FXRbCallVoidMethod(this,rb_intern("setIcon"),icn); \
    } \
  void cls::setFocus(FXbool focus){ \
    FXRbCallVoidMethod(this,rb_intern("setFocus"),focus); \
    } \
  void cls::setSelected(FXbool selected){ \
    FXRbCallVoidMethod(this,rb_intern("setSelected"),selected); \
    } \
  void cls::setEnabled(FXbool enabled){ \
    FXRbCallVoidMethod(this,rb_intern("setEnabled"),enabled); \
    } \
  void cls::setDraggable(FXbool draggable){ \
    FXRbCallVoidMethod(this,rb_intern("setDraggable"),draggable); \
    } \
  void cls::setIconOwned(FXuint owned){ \
    FXRbCallVoidMethod(this,rb_intern("setIconOwned"),owned); \
    } \
  FXint cls::getWidth(const FXList* list) const { \
    return FXRbCallIntMethod(this,rb_intern("getWidth"),list); \
    } \
  FXint cls::getHeight(const FXList* list) const { \
    return FXRbCallIntMethod(this,rb_intern("getHeight"),list); \
    }


class FXRbListItem : public FXListItem {
  FXDECLARE(FXRbListItem)
protected:
  FXRbListItem(){}
#include "FXRbObjectVirtuals.h"
#include "FXRbListItemVirtuals.h"
public:
  // Is this list item owned by an FXList yet?
  FXbool owned;
public:
  // Constructor
  FXRbListItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL) : FXListItem(text,ic,ptr),owned(FALSE){}

  // Mark dependencies for the GC
  static void markfunc(FXListItem* self);

  // Destroy this object if it's not owned
  static void freefunc(FXListItem* self);

  // Destructor
  virtual ~FXRbListItem(){
    FXRbUnregisterRubyObj(this);
    }
  };


class FXRbList : public FXList {
  FXDECLARE(FXRbList)
protected:
  FXRbList(){}
#include "FXRbObjectVirtuals.h"
#include "FXRbIdVirtuals.h"
#include "FXRbDrawableVirtuals.h"
#include "FXRbWindowVirtuals.h"
#include "FXRbScrollAreaVirtuals.h"
public:
  /// Construct a list with nvis visible items; the list is initially empty
  FXRbList(FXComposite *p,FXint nvis,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=LIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0) : FXList(p,nvis,tgt,sel,opts,x,y,w,h){
    setSortFunc(FXRbList::sortFunc);
    }

  // Sort function stand-in
  static FXint sortFunc(const FXListItem* a,const FXListItem* b);

  // Mark dependencies for the GC
  static void markfunc(FXList* self);

  // Destructor
  virtual ~FXRbList(){
    FXRbUnregisterRubyObj(this);
    }
  };

#endif
