#ifndef __OXVIEW_H
#define __OXVIEW_H

#include <stdio.h>

#include <xclass/OXClient.h>
#include <xclass/OXFrame.h>
#include <xclass/OXWidgets.h>
#include <xclass/OXScrollBar.h>

#include "OViewDoc.h"

class OXView;

class OXViewDocFrame : public OXFrame, public OXWidget {
friend class OXView;

protected:
  OViewDoc *_document;

  GC _backgc;

public:
  OXViewDocFrame(OXWindow *parent, int w, int h, unsigned int options,
              unsigned long back = _defaultFrameBackground);
  virtual ~OXViewDocFrame();

  void SetDocument(OViewDoc * d) {_document = d;}

  void Clear();
  int  GetDocHeight() { return _document->GetHeight(); }
  int  GetDocWidth() { return _document->GetWidth(); }
  void HScrollWindow(int x);
  void VScrollWindow(int y);

  virtual int HandleExpose(XExposeEvent *event) {
    DrawRegion(event->x, event->y, event->width, event->height);
    return True;
  }
  virtual int HandleGraphicsExpose(XGraphicsExposeEvent *event) {
    DrawRegion(event->x, event->y, event->width, event->height);
    return True;
  }

  virtual void Layout();

protected:
  virtual void DrawRegion(int x, int y, int w, int h);

  int _tx, _ty;
};

#define NO_HSCROLL    1
#define NO_VSCROLL    2
#define FORCE_HSCROLL 4
#define FORCE_VSCROLL 8

class OXView : public OXCompositeFrame {

protected:
  unsigned long _background;

public:
  OXView(const OXWindow *parent, OViewDoc * d,
         int w, int h, unsigned int options,
         unsigned long back = _defaultFrameBackground);
  virtual ~OXView();
  void SetScrollOptions(int o) {_scroll_options = o;}

  int  LoadFile(char *fname);
  void Clear();
  virtual int ProcessMessage(long msg, long parm1, long parm2);
  virtual void AdjustScrollbars();
  virtual void Layout();
  virtual void DrawBorder();
  virtual ODimension GetDefaultSize() const { return ODimension(_w, _h); }

  int GetBackground() {return _background;}

  void ScrollDown();
protected:
  OViewDoc *_document;
  OXViewDocFrame  *_canvas;
  OXHScrollBar *_hscrollbar;
  OXVScrollBar *_vscrollbar;

  int _scroll_options;
};

#endif
