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

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


#include <stdio.h>

#include <xclass/OXClient.h>
#include <xclass/OTimer.h>
#include "OXTextView.h"

#define VIEW_F3        5

class OXTextEdit : public OXTextView {

protected:
  GC _gc_crs0, _gc_crs1;;
  int cursorstate;
  bool pasteok;
  OTimer *csr_timer;
  OLongPosition _current;
  void _OXTextEdit();
  void DrawCursor(int mode);
  void SetCurrent(OLongPosition new_coord);
  void AdjustPos();

  void InsChar(char character);
  void DelChar();
  void BreakLine();
  void TabKey();  
  void PrevChar();
  void NextChar();
  void LineUp();
  void LineDown();
  void ScreenUp();
  void ScreenDown();
  void Home();
  void End();

public:
  OXTextEdit(OXWindow *parent, int w, int h, long id, unsigned int sboptions=0);
  OXTextEdit(OXWindow *parent, int w, int h, long id, OText *text, unsigned int sboptions=0);
  OXTextEdit(OXWindow *parent, int w, int h, long id, char *string, unsigned int sboptions=0);
  virtual ~OXTextEdit();
  bool SaveFile(char *fname);
  void Clear();
  bool Cut();
  bool Paste();
  bool Delete();
  virtual bool Search(char *string, bool direction, bool caseSensitive);
  bool Replace(OLongPosition pos, char *oldText, char *newText, bool direction, bool caseSensitive);
  bool Goto(long line);
  OLongPosition GetCurrentPos() {return _current;}
  virtual int HandleTimer (OTimer *t);
  virtual long ReturnLongestLineWidth(); 
  virtual int HandleSelection (XSelectionEvent *event);
  virtual int HandleButton(XButtonEvent *event);
  virtual int HandleKey(XKeyEvent *event);
  virtual int HandleMotion(XMotionEvent *event);  
  friend class OXClient;
};

#endif // __TEXTEDIT_H
