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

    This file is part of Xclass95, a Win95-looking GUI toolkit.
    Copyright (C) 1996, 1997 David Barth, Hector Peraza.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 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
    Library General Public License for more details.

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

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

#ifndef __OXCANVAS_H
#define __OXCANVAS_H

#include <X11/Xlib.h>

#include <xclass/OXFrame.h>
#include <xclass/ODimension.h>


#ifndef min
#define min(a,b) (((a)<(b)) ? (a) : (b))
#endif

#ifndef max
#define max(a,b) (((a)>(b)) ? (a) : (b))
#endif


//-------------------- This frame acts as the window through which we look
//                     at the contents of the container frame

class OXViewPort : public OXCompositeFrame {
public:
  OXViewPort(const OXWindow *p, int w, int h,
           unsigned int options = CHILD_FRAME,
           unsigned long back = _defaultFrameBackground);

  OXFrame *GetContainer() const { return _container; }
  void SetContainer(OXFrame *f) { 
    if (!_container) {
      _container = f;
      AddFrame(f, NULL);
    }
  }

  virtual void DrawBorder() {};
  virtual void Layout() {}
  virtual ODimension GetDefaultSize() const { return ODimension(_w, _h); }
  
  void SetHPos(int xpos) { if (_container) _container->Move(_x0 = xpos, _y0); }
  void SetVPos(int ypos) { if (_container) _container->Move(_x0, _y0 = ypos); }
  void SetPos(int xpos, int ypos) { if (_container) _container->Move(_x0 = xpos, _y0 = ypos); }

protected:
  int _x0, _y0;
  OXFrame *_container;
};

//-------------------- This is the scrollable canvas frame arrangement

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

  void AddFrame(OXFrame *f, OLayoutHints *l);
  OXFrame *GetContainer() const { return _vport->GetContainer(); }
  OXFrame *GetViewPort()  const { return ((OXFrame *) _vport); }
  virtual void SetContainer(OXFrame *f) { _vport->SetContainer(f); }
  virtual void MapSubwindows();
  virtual void DrawBorder();
  virtual void Layout();
  virtual ODimension GetDefaultSize() const { return ODimension(_w, _h); }

  virtual int ProcessMessage(long msg, long parm1, long parm2);

protected:
  OXViewPort   *_vport;
  OXHScrollBar *_hscrollbar;
  OXVScrollBar *_vscrollbar;
};


#endif  // __OXCANVAS_H
