// myex34cView.cpp : implementation of the CMyex34cView class
//

#include "stdafx.h"
#include "myex34c.h"

#include "myex34cDoc.h"
#include "CntrItem.h"
#include "myex34cView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyex34cView

IMPLEMENT_DYNCREATE(CMyex34cView, CRichEditView)

BEGIN_MESSAGE_MAP(CMyex34cView, CRichEditView)
	//{{AFX_MSG_MAP(CMyex34cView)
	ON_WM_DESTROY()
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClearAll)
	ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR_ALL, OnUpdateEditClearAll)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyex34cView construction/destruction

CMyex34cView::CMyex34cView()
{
	// TODO: add construction code here

}

CMyex34cView::~CMyex34cView()
{
}

BOOL CMyex34cView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	BOOL bPreCreated = CRichEditView::PreCreateWindow(cs);
	cs.style |= ES_READONLY;
	return bPreCreated;
}

void CMyex34cView::OnInitialUpdate()
{
	CRichEditView::OnInitialUpdate();


	// Set the printing margins (720 twips = 1/2 inch).
	SetMargins(CRect(720, 720, 720, 720));
}

/////////////////////////////////////////////////////////////////////////////
// CMyex34cView printing

BOOL CMyex34cView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}


void CMyex34cView::OnDestroy()
{
	// Deactivate the item on destruction; this is important
	// when a splitter view is being used.
   CRichEditView::OnDestroy();
   COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
   if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
   {
      pActiveItem->Deactivate();
      ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
   }
}


/////////////////////////////////////////////////////////////////////////////
// CMyex34cView diagnostics

#ifdef _DEBUG
void CMyex34cView::AssertValid() const
{
	CRichEditView::AssertValid();
}

void CMyex34cView::Dump(CDumpContext& dc) const
{
	CRichEditView::Dump(dc);
}

CMyex34cDoc* CMyex34cView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyex34cDoc)));
	return (CMyex34cDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyex34cView message handlers

void CMyex34cView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	TRACE("CMyex34cView::OnRButtonDown\n");
	CMenu menu;
	menu.LoadMenu(IDR_MENUCONTEXT);
	ClientToScreen(&point);
	menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
		point.x, point.y, this);
}

void CMyex34cView::OnEditClearAll() 
{
	// TODO: Add your command handler code here
	CRichEditCtrl& re = GetRichEditCtrl();
	re.SetSel(0, -1);
	// won't let us clear unless we reset readonly flag
	re.SetOptions(ECOOP_XOR, ECO_READONLY);
	re.Clear();
	re.SetOptions(ECOOP_SET, ECO_READONLY);
}

void CMyex34cView::OnUpdateEditClearAll(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(GetRichEditCtrl().GetTextLength() > 0);
}

