// myex35aView.cpp : implementation of the CMyex35aView class
//

#include "stdafx.h"
#include "myex35a.h"

#include "myex35aDoc.h"
#include "CntrItem.h"
#include "myex35aView.h"
#include "Urlthread.h"
#include "MainFrm.h"
#include "IpFrame.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyex35aView

IMPLEMENT_DYNCREATE(CMyex35aView, CRichEditView)

BEGIN_MESSAGE_MAP(CMyex35aView, CRichEditView)
	//{{AFX_MSG_MAP(CMyex35aView)
	ON_COMMAND(ID_CANCEL_EDIT_SRVR, OnCancelEditSrvr)
	ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClearAll)
	ON_COMMAND(IDC_START, OnStart)
	ON_COMMAND(IDC_STOP, OnStop)
	ON_WM_DESTROY()
	ON_UPDATE_COMMAND_UI(IDC_START, OnUpdateStart)
	ON_UPDATE_COMMAND_UI(IDC_STOP, OnUpdateStop)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyex35aView construction/destruction

CMyex35aView::CMyex35aView()
{
	// TODO: add construction code here

}

CMyex35aView::~CMyex35aView()
{
}

BOOL CMyex35aView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CRichEditView::PreCreateWindow(cs);
}

void CMyex35aView::OnInitialUpdate()
{
	CRichEditView::OnInitialUpdate();


	// Set the printing margins (720 twips = 1/2 inch).
	SetMargins(CRect(720, 720, 720, 720));
}

/////////////////////////////////////////////////////////////////////////////
// CMyex35aView printing

BOOL CMyex35aView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}


// void CMyex35aView::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);
//   }
// }


/////////////////////////////////////////////////////////////////////////////
// OLE Server support

// The following command handler provides the standard keyboard
//  user interface to cancel an in-place editing session.  Here,
//  the server (not the container) causes the deactivation.
void CMyex35aView::OnCancelEditSrvr()
{
	GetDocument()->OnDeactivateUI(FALSE);
}

/////////////////////////////////////////////////////////////////////////////
// CMyex35aView diagnostics

#ifdef _DEBUG
void CMyex35aView::AssertValid() const
{
	CRichEditView::AssertValid();
}

void CMyex35aView::Dump(CDumpContext& dc) const
{
	CRichEditView::Dump(dc);
}

CMyex35aDoc* CMyex35aView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyex35aDoc)));
	return (CMyex35aDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyex35aView message handlers

void CMyex35aView::OnEditClearAll() 
{
	// Not so useable here, coz of the save as...
	SetWindowText("");
}

void CMyex35aView::OnStart() 
{
	CWnd* pFrm = GetParent(); // SDI only
	CWnd* pBar;
	if(pFrm->IsKindOf(RUNTIME_CLASS(CMainFrame))) {
		pBar = &((CMainFrame*) pFrm)->m_wndDialogBar;
	}
	else {
		pBar = &((CInPlaceFrame*) pFrm)->m_wndDialogBar;
	}
	// g_strURL: thread sync?
	pBar->GetDlgItemText(IDC_URL, g_strURL);
	TRACE("CMyex35aView::OnRequest -- URL = %s\n", g_strURL);
	AfxBeginThread(UrlThreadProc, GetSafeHwnd(), THREAD_PRIORITY_NORMAL);
}

void CMyex35aView::OnStop() 
{
	g_eKill.SetEvent();
}

void CMyex35aView::OnUpdateStop(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(g_bThreadStarted);
}

void CMyex35aView::OnUpdateStart(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(!g_bThreadStarted);
}



