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

    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 __OXVIEW_H
#define __OXVIEW_H

#include<xclass/OXFrame.h>
#include<X11/Xatom.h>
#include<xclass/OXWidgets.h>
#include<xclass/ODimension.h>
#include<stdio.h>
#define VERTICAL   True
#define HORIZONTAL False

#define XC_VIEW 90
#define VIEW_ISMARKED 1
#define VIEW_CLICK2    2
#define VIEW_CLICK3    3
#define VIEW_DATACHANGE 4

#define NOHSB 1 << 1
#define NOVSB 1 << 2


class OXViewFrame;

class OXView : public OXCompositeFrame {

protected:
 OPosition _markedStart, _markedEnd;
 OPosition _visible;
 OPosition _mousePos;
 OPosition _scrollVal;
 bool _isMarked;
 bool _isSaved;
 int _scrolling;
 bool _isMarking; 
 Atom _selProperty;
 unsigned int _xMargin, _yMargin;
 OXViewFrame *_canvas;
 OXHScrollBar *_hsb;
 OXVScrollBar *_vsb;
 OTimer *_scrollTimer;
 long _ID;
public:

  OXView(OXWindow *p, int w, int h, long id,
         unsigned int xMargin = 0, unsigned int yMargin = 0, 
         unsigned int options = SUNKEN_FRAME | DOUBLE_BORDER, unsigned int sboptions = 0);

  ~OXView(); 

 virtual ODimension GetDefaultSize() const { return ODimension(_w, _h); }

 virtual void Clear();
 virtual void SetVisibleStart (long newTop, bool direction);
 virtual void ScrollCanvas (long newTop, bool direction);
 virtual int ProcessMessage(long msg, long parm1, long parm2);
 virtual void DrawBorder();
 virtual void Layout();
 virtual void HLayout();
 virtual void VLayout();
 virtual void SetSBRange(bool direction);
 virtual void SetHsbPosition(long newPos);
 virtual void SetVsbPosition(long newPos);

 virtual long ToObjXCoord(long xCoord, long line) {return xCoord;}
 virtual long ToObjYCoord(long yCoord) {return yCoord;}
 virtual long ToScrXCoord(long xCoord, long line) {return xCoord;}
 virtual long ToScrYCoord(long yCoord) {return yCoord;}

 virtual void Mark(long xPos, long yPos) {};
 virtual void UnMark() {};
 virtual void DrawRegion(int x, int y, int width,int height) {};

 virtual long ReturnLineLength(long line) {return 0;}
 virtual long ReturnLineCount(){return 0;}
 virtual long ReturnHeighestColHeight() {return 0;}
 virtual long ReturnLongestLineWidth()  {return 0;}
 
 bool IsMarked() {return _isMarked;}
 bool IsSaved()  {return _isSaved;}

 virtual int HandleMotion(XMotionEvent *event);
 virtual int HandleButton(XButtonEvent *event);
 virtual int HandleExpose(XExposeEvent *event);
 virtual int HandleGraphicsExpose(XGraphicsExposeEvent *event);
 virtual int HandleCrossing(XCrossingEvent *event);
 virtual int HandleTimer (OTimer *t);
};

class OXViewFrame : public OXCompositeFrame
{
public:
 OXViewFrame(const OXWindow *p, int w, int h,
          unsigned int options = 0);

 virtual int HandleSelectionRequest(XSelectionRequestEvent *event)
        {((OXView *)_parent)->HandleSelectionRequest(event);return True;} 
 virtual int HandleSelectionClear(XSelectionClearEvent *event) 
        {((OXView *)_parent)->HandleSelectionClear(event);return True;}
 virtual int HandleSelection(XSelectionEvent *event) 
        {((OXView *)_parent)->HandleSelection(event);return True;}
 virtual int HandleButton(XButtonEvent *event)
        {((OXView *)_parent)->HandleButton(event);return True;}
 virtual int HandleExpose(XExposeEvent *event)
        {((OXView *)_parent)->HandleExpose(event);return True;}
 virtual int HandleGraphicsExpose(XGraphicsExposeEvent *event)
        {((OXView *)_parent)->HandleGraphicsExpose(event);return True;}
 virtual int HandleCrossing(XCrossingEvent *event)
        {((OXView *)_parent)->HandleCrossing(event);return True;}
 virtual int HandleMotion(XMotionEvent *event)
        {((OXView *)_parent)->HandleMotion(event);return True;} 
 virtual int HandleKey(XKeyEvent *event) 
        {((OXView *)_parent)->HandleKey(event);return True;} 
};

#endif // __OXVIEW_H
