/////////////////////////////////////////////////////////////////////////////
// Name:        No names yet.
// Purpose:     Contrib. demo
// Author:      Aleksandras Gluchovas
// Modified by:
// Created:     2000/02/08
// RCS-ID:      $Id: srceditordoc.h,v 1.4 2001/04/22 19:58:14 aleksandras Exp $
// Copyright:   (c) Aleksandras Gluchovas
// Licence:   	GPL (version 2.0 or later)
/////////////////////////////////////////////////////////////////////////////

#ifndef __SRCEDITORDOC_G__
#define __SRCEDITORDOC_G__

#include "wx/pmf/pm_doc.h"
#include "wx/pmf/inf/textediting.h"

// will be impoted from "tdefs.h"
class wxTextEditorModel;
class wxTextEditorView;

class wxSourceCodeDocument : public wxPMDocument,
							 public I_ContainingText,
							 public I_MarkableText,
							 public I_EditableText
{
public:
	wxSourceCodeDocument();
	~wxSourceCodeDocument();

	// overriden methods of wxPMDocument
	virtual bool SavePMDocument( wxOutputStream& s );
	virtual bool LoadPMDocument( wxInputStream& s );

	// accessed by views
	wxTextEditorModel* GetModel() { return mpModel; }

	// text-manipulations
	wxString GetAllText();
	void ReplaceAllText( const wxString& withText );
	void GotoLine( int line, int column );

	// overriden method of wxDocument
	virtual bool IsModified() const;
	virtual void Modify(bool modify);

	// override method of wxPMService

	virtual void* GetInterface( const char* infName, const char* version = NULL );

	/* implementation of wxPMInf_ContainingText interface */

	virtual bool GetAllText( wxString* toStr );

	virtual bool GetTextRange( wxString* toStr, int line1, int column1,
							   int line2, int column2 );

	virtual void GetEndPosition( int* line, int* column );

	virtual void GetCursorPosition( int* line, int* column );

	/* implementation of wxPMInf_MarkableText interface */

	virtual long AddMark( int type, int line );
	virtual bool IsMarked( int type, int line );

	virtual void RemoveAllMarks( int type );
	virtual bool JumpToMark( long markId );

	virtual bool RemoveMarkAt( int type, int line );
	virtual bool GetMarkInfo( long markId, int* type, int* line );
	virtual bool RemoveMark( long markId );

	/* implementation of wxPMInf_MarkableText interface */

	virtual void StartTextUpdateBatch();
	virtual void FinishTextUpdateBatch();

	virtual void InsertText( wxString& text, int line, int column );
	
	virtual void GetSelection( int* line1, int* column1, int* line2, int* column2 );
	virtual void SetSelection( int line1, int column1, int line2, int column2 );

	virtual void TextPosToScreenPos( int line, int column, int* x, int* y );
	virtual void SetCursorPosition( int line, int column );
	virtual void GetPagePosition( int* line, int* column );
	
	virtual bool DeleteRenage( int line1, int column1, int line2, int column2 );

	virtual wxWindow* GetTextWidgetWindow();
	virtual wxSize GetCharacterSize();
	virtual void HoldCursor( bool hold );
	
	DECLARE_DYNAMIC_CLASS( wxSourceCodeDocument )

protected: 
	int ToModelPinType( int infPinType );

protected:
	wxTextEditorModel* mpModel;
};

class wxSourceCodeView : public wxPMView
{
public:
	wxSourceCodeView();
	~wxSourceCodeView();

	// overriden method wxView and wxPMView
	virtual bool OnCreate(wxDocument* doc, long flags);

	wxTextEditorView* GetEditorView() { return mpView; }

	// overriden method of wxPMService

	virtual wxPMMergableMenuChain* GetMergableMenuChain();

	/*** command events ***/

	enum SOURCE_CODE_EDITOR_COMMANDS
	{
		ID_UNDO = 300,
		ID_REDO,
		ID_FIND,
		ID_FIND_NEXT,
		ID_FIND_PREV,
		ID_TOGGLE_BOOKMARK,
		ID_NEXT_BOOKMARK,
		ID_PREV_BOOKMARK,
		ID_TOGGLE_BREAKPOINT,
		ID_SELECT_ALL,
		ID_COPY,
		ID_PASTE,
		ID_CUT,
		ID_REMOVE_LINE,
		ID_GOTO_LINE,
		ID_INC_INDENT,
		ID_DEC_INDENT
	};

	void OnCmdUndo( wxCommandEvent& event );
	void OnCmdRedo( wxCommandEvent& event );
	void OnCmdFind( wxCommandEvent& event );
	void OnCmdFindNext( wxCommandEvent& event );
	void OnCmdFindPrev( wxCommandEvent& event );
	void OnCmdToggleBookmark( wxCommandEvent& event );
	void OnCmdNextBookmark( wxCommandEvent& event );
	void OnCmdPrevBookmark( wxCommandEvent& event );
	void OnCmdToggleBreakpoint( wxCommandEvent& event );
	void OnCmdSelectAll( wxCommandEvent& event );
	void OnCmdCopy( wxCommandEvent& event );
	void OnCmdPaste( wxCommandEvent& event );
	void OnCmdCut( wxCommandEvent& event );
	void OnCmdRemoveLine( wxCommandEvent& event );
	void OnCmdGotoLine( wxCommandEvent& event );
	void OnCmdIncIndent( wxCommandEvent& event );
	void OnCmdDecIndent( wxCommandEvent& event );

	DECLARE_EVENT_TABLE()
	DECLARE_DYNAMIC_CLASS( wxSourceCodeView )

protected:
	wxTextEditorView*  mpView;
	wxTextEditorModel* mpModel;
};


#endif // __SRCEDITORDOC_G__