// OutputCOMEditorDoc.cpp : implementation of the COutputCOMEditorDoc class
//
#include "stdafx.h"
#include "OutputCOMEditor.h"
#include "MainFrm.h"
#include "OutputCOMEditorDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COutputCOMEditorDoc
IMPLEMENT_DYNCREATE(COutputCOMEditorDoc, CDocument)
BEGIN_MESSAGE_MAP(COutputCOMEditorDoc, CDocument)
//{{AFX_MSG_MAP(COutputCOMEditorDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(COutputCOMEditorDoc, CDocument)
//{{AFX_DISPATCH_MAP(COutputCOMEditorDoc)
DISP_FUNCTION(COutputCOMEditorDoc, "ShowWindow", ShowWindow, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(COutputCOMEditorDoc, "AddText", AddText, VT_EMPTY, VTS_BSTR)
DISP_FUNCTION(COutputCOMEditorDoc, "GetCursorPosition", GetCursorPosition, VT_I4, VTS_NONE)
DISP_FUNCTION(COutputCOMEditorDoc, "SetCursorAtPosition", SetCursorAtPosition, VT_EMPTY, VTS_I4)
DISP_FUNCTION(COutputCOMEditorDoc, "GetMaximalCursorPosition", GetMaximalCursorPosition, VT_I4, VTS_NONE)
DISP_FUNCTION(COutputCOMEditorDoc, "SetCursorAtStart", SetCursorAtStart, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(COutputCOMEditorDoc, "SetCursorAtEnd", SetCursorAtEnd, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(COutputCOMEditorDoc, "MoveCursorBy", MoveCursorBy, VT_EMPTY, VTS_I4)
DISP_FUNCTION(COutputCOMEditorDoc, "EndLine", EndLine, VT_EMPTY, VTS_NONE)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IOutputCOMEditor to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {DC714FBF-BA8D-49BB-978A-AA08FE10385B}
static const IID IID_IOutputCOMEditor =
{ 0xdc714fbf, 0xba8d, 0x49bb, { 0x97, 0x8a, 0xaa, 0x8, 0xfe, 0x10, 0x38, 0x5b } };
BEGIN_INTERFACE_MAP(COutputCOMEditorDoc, CDocument)
INTERFACE_PART(COutputCOMEditorDoc, IID_IOutputCOMEditor, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COutputCOMEditorDoc construction/destruction
COutputCOMEditorDoc::COutputCOMEditorDoc()
{
// TODO: add one-time construction code here
EnableAutomation();
AfxOleLockApp();
}
COutputCOMEditorDoc::~COutputCOMEditorDoc()
{
AfxOleUnlockApp();
}
//
BOOL COutputCOMEditorDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
SetModifiedFlag(FALSE);
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
if(pView!=NULL)
{
CFrameWnd* pFrameWnd1=pView->GetParentFrame();
CFrameWnd* pFrameWnd2=pFrameWnd1->GetParentFrame();
if( pFrameWnd2!=NULL )
{
ASSERT(pFrameWnd2->IsKindOf(RUNTIME_CLASS(CMainFrame)));
((CMainFrame *)pFrameWnd2)->MDIMaximize( pFrameWnd1 );
}
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// COutputCOMEditorDoc serialization
void COutputCOMEditorDoc::Serialize(CArchive& ar)
{
// CEditView contains an edit control which handles all serialization
((CEditView*)m_viewList.GetHead())->SerializeRaw(ar);
}
/////////////////////////////////////////////////////////////////////////////
// COutputCOMEditorDoc diagnostics
#ifdef _DEBUG
void COutputCOMEditorDoc::AssertValid() const
{
CDocument::AssertValid();
}
void COutputCOMEditorDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// COutputCOMEditorDoc commands
//
void COutputCOMEditorDoc::ShowWindow()
{
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
if(pView!=NULL)
{
CFrameWnd* pFrameWnd1=pView->GetParentFrame();
pFrameWnd1->ActivateFrame(SW_SHOW);
CFrameWnd* pFrameWnd2=pFrameWnd1->GetParentFrame();
if( pFrameWnd2!=NULL )
{
pFrameWnd2->ActivateFrame(SW_SHOW);
ASSERT(pFrameWnd2->IsKindOf(RUNTIME_CLASS(CMainFrame)));
((CMainFrame *)pFrameWnd2)->MDIMaximize( pFrameWnd1 );
}
}
SetModifiedFlag(FALSE);
}
using namespace kaBasicClasses;
using namespace std;
//
void COutputCOMEditorDoc::AddText(LPCTSTR text)
{
if( !controlStream.isSet() )
{
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
controlStream.set( (&((CEditView *)pView)->GetEditCtrl()) );
}
controlStream<<CString(text);
controlStream.flush();
}
//
long COutputCOMEditorDoc::GetCursorPosition()
{
if( !controlStream.isSet() )
{
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
controlStream.set( (&((CEditView *)pView)->GetEditCtrl()) );
}
return controlStream.getCursorPosition();
}
//
void COutputCOMEditorDoc::SetCursorAtPosition(long position)
{
if( !controlStream.isSet() )
{
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
controlStream.set( (&((CEditView *)pView)->GetEditCtrl()) );
}
controlStream.setCursorAtPosition(position);
}
//
long COutputCOMEditorDoc::GetMaximalCursorPosition()
{
if( !controlStream.isSet() )
{
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
controlStream.set( (&((CEditView *)pView)->GetEditCtrl()) );
}
return controlStream.getMaximalCursorPosition();
}
//
void COutputCOMEditorDoc::SetCursorAtStart()
{
if( !controlStream.isSet() )
{
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
controlStream.set( (&((CEditView *)pView)->GetEditCtrl()) );
}
controlStream.setCursorAtStart();
}
//
void COutputCOMEditorDoc::SetCursorAtEnd()
{
if( !controlStream.isSet() )
{
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
controlStream.set( (&((CEditView *)pView)->GetEditCtrl()) );
}
controlStream.setCursorAtEnd();
}
//
void COutputCOMEditorDoc::MoveCursorBy(long offset)
{
if( !controlStream.isSet() )
{
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
controlStream.set( (&((CEditView *)pView)->GetEditCtrl()) );
}
controlStream.moveCursorBy(offset);
}
//
void COutputCOMEditorDoc::EndLine()
{
if( !controlStream.isSet() )
{
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
controlStream.set( (&((CEditView *)pView)->GetEditCtrl()) );
}
controlStream<<endl;
SetModifiedFlag(TRUE);
}