//=--------------------------------------------------------------------------=
// (C) Copyright 1997-1998 Microsoft Corporation. All Rights Reserved.
//=--------------------------------------------------------------------------=
// Implementation of the CCEditView class
#include "stdafx.h"
#include "CEdit.h"
#include <AFXPRIV.H>
#include <afxdisp.h>
#include "CrtDoc.h"
#include "CrtView.h"
#include "site.h"
#include <TRIEDIID.h>
#include <triedcid.h>
#include "mainfrm.h"
#include "insHTML.h"
#include "insScrpt.h"
#include "insTable.h"
#include "align.h"
#include "nudge.h"
#include "DocEvent.h"
#include "tagmenu.h"
#include "optfiltr.h"
#include "optglyph.h"
#include "optuiact.h"
#include "optmisc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCEditView
IMPLEMENT_DYNCREATE(CCEditView, CView)
BEGIN_MESSAGE_MAP(CCEditView, CView)
//{{AFX_MSG_MAP(CCEditView)
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_SETFOCUS()
ON_WM_ERASEBKGND()
ON_COMMAND(ID_BGCOLOR, OnBgcolor)
ON_COMMAND(ID_INSERT_HTML, OnEditInserthtml)
ON_COMMAND_RANGE(ID_TRIEDIT_CMD_START, ID_TRIEDIT_CMD_END, OnTriEditCommand)
ON_UPDATE_COMMAND_UI_RANGE(ID_TRIEDIT_CMD_START, ID_TRIEDIT_CMD_END, OnUpdateTriEditUI)
ON_CBN_SELENDOK(ID_FMTBAR_FONTNAME, OnFontNameChange)
ON_CBN_SELENDOK(ID_FMTBAR_FONTSIZE, OnFontSizeChange)
ON_COMMAND_RANGE(ID_TAGMENU_BASE, ID_TAGMENU_END, OnTagMenu)
ON_COMMAND_RANGE(ID_COLOR0, ID_COLOR16, OnColorMenu)
ON_COMMAND_RANGE(ID_BGCOLOR0, ID_BGCOLOR16, OnBgColorMenu)
ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR , OnFmtbarTBNotify)
ON_UPDATE_COMMAND_UI(ID_FORMAT_STYLE, OnUpdateFormatStyle)
ON_UPDATE_COMMAND_UI(ID_TAGMENU_BASE, OnUpdateFormatStyleTagMenu)
ON_UPDATE_COMMAND_UI(ID_FMTBAR_COLORMENU, OnUpdateFmtbarColormenu)
ON_UPDATE_COMMAND_UI(ID_FMTBAR_TAGMENU, OnUpdateFmtbarTagmenu)
ON_UPDATE_COMMAND_UI(ID_FORMAT_BACKGROUND_COLOR, OnUpdateFormatBackgroundColor)
ON_UPDATE_COMMAND_UI(ID_BGCOLOR0, OnUpdateBgColorMenu)
ON_COMMAND(ID_VIEW_OPTIONS, OnViewOptions)
ON_COMMAND(ID_FILE_SAVEASFILEWITHFILTER, OnFileSaveAsWithFilter)
ON_COMMAND(ID_FILE_SAVEAS, OnFileSaveAs)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVEAS, OnUpdateFileSaveas)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVEASFILEWITHFILTER, OnUpdateFileSaveasFileWithFilter)
ON_COMMAND(ID_VIEW_FORMATBAR, OnViewFormatbar)
ON_UPDATE_COMMAND_UI(ID_VIEW_FORMATBAR, OnUpdateViewFormatbar)
ON_COMMAND(ID_VIEW_OBJECTBAR, OnViewObjectbar)
ON_UPDATE_COMMAND_UI(ID_VIEW_OBJECTBAR, OnUpdateViewObjectbar)
ON_COMMAND(ID_INSERT_SCRIPT, OnInsertScript)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCEditView construction/destruction
CCEditView::CCEditView()
{
m_cRef = 0;
m_hWndObj = NULL;
m_pSite = NULL;
m_pIOleIPActiveObject = NULL;
m_fCreated = FALSE;
m_pDocEvents = NULL;
m_tagCount = 0;
m_pColorMenu = ((CCEditApp *)AfxGetApp())->m_pColorMenu;
m_fFilterIn = FALSE;
m_fConstrain = FALSE;
m_uiX = 0;
m_uiY = 0;
}
CCEditView::~CCEditView()
{
if (m_pDocEvents != NULL )
{
// We'll be polite and Unadvise the connectionpoint
m_pConnectionPoint->Unadvise( m_dwConnectCookie );
m_pConnectionPoint->Release();
delete m_pDocEvents;
}
if (m_pColorMenu)
m_pColorMenu = NULL;
// Debug check that nobody is trying to hang onto us!
ASSERT( m_cRef == 0 );
}
/////////////////////////////////////////////////////////////////////////////
// CCEditView drawing
void CCEditView::OnDraw(CDC* /*pDC*/)
{
// If this is the first time draw get's called then
// let's create the MSHTML Active Document
if ( m_fCreated == FALSE )
{
m_fCreated = TRUE;
CCEditApp* pApp = (CCEditApp*)AfxGetApp();
TCHAR* pchPath = (TCHAR*)LPCTSTR(pApp->m_strPath);
m_fFilterIn = pApp->m_fFilterIn;
pApp->m_fFilterIn = FALSE;
if ( !CreateDocObject( pchPath ) )
{
// Destroy this window
MessageBox( "Path Name Invalid", "Error", MB_ICONEXCLAMATION );
GetParent()->PostMessage( WM_CLOSE, 0, 0);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CCEditView diagnostics
#ifdef _DEBUG
void CCEditView::AssertValid() const
{
CView::AssertValid();
}
void CCEditView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCEditDoc* CCEditView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCEditDoc)));
return (CCEditDoc*)m_pDocument;
}
#endif //_DEBUG
// Helper Methods
CMainFrame*
CCEditView::GetMainFrame()
{
CMainFrame* pFrame = (CMainFrame*) ((CMDIChildWnd*) GetParentFrame())->GetMDIFrame();
return pFrame;
}
/*
* IUnknown implementation
*/
/*
* CCEditView::QueryInterface
* CCEditView::AddRef
* CCEditView::Release
*/
STDMETHODIMP CCEditView::QueryInterface( REFIID riid, void **ppv )
{
AFX_MANAGE_STATE(this->m_pModuleState);
/*
* We provide IOleInPlaceFrame and IOleCommandTarget
* interfaces here for the ActiveX Document hosting
*/
*ppv = NULL;
if ( IID_IUnknown == riid || IID_IOleInPlaceUIWindow == riid
|| IID_IOleWindow == riid || IID_IOleInPlaceFrame == riid )
{
*ppv = (IOleInPlaceFrame *)this;
}
if ( IID_IOleCommandTarget == riid )
{
*ppv = (IOleCommandTarget *)this;
}
if ( NULL != *ppv )
{
((LPUNKNOWN)*ppv)->AddRef();
return NOERROR;
}
return E_NOINTERFACE;
}
STDMETHODIMP_(ULONG) CCEditView::AddRef( void )
{
AFX_MANAGE_STATE(this->m_pModuleState);
return ++m_cRef;
}
STDMETHODIMP_(ULONG) CCEditView::Release( void )
{
AFX_MANAGE_STATE(this->m_pModuleState);
//Nothing special happening here-- life if user-controlled.
// Debug check to see we don't fall below 0
ASSERT( m_cRef != 0 );
return --m_cRef;
}
/*
* IOleInPlaceFrame implementation
*/
/*
* CCEditView::GetWindow
*
* Purpose:
* Retrieves the handle of the window associated with the object
* on which this interface is implemented.
*
* Parameters:
* phWnd HWND * in which to store the window handle.
*
* Return Value:
* HRESULT NOERROR if successful, E_FAIL if there is no
* window.
*/
STDMETHODIMP CCEditView::GetWindow( HWND* phWnd )
{
AFX_MANAGE_STATE(this->m_pModuleState);
CFrameWnd* pFrame = GetParentFrame();
if ( pFrame != NULL )
{
*phWnd = pFrame->m_hWnd;
}
return NOERROR;
}
/*
* CCEditView::ContextSensitiveHelp
*
* Purpose:
* Instructs the object on which this interface is implemented to
* enter or leave a context-sensitive help mode.
*
* Parameters:
* fEnterMode BOOL TRUE to enter the mode, FALSE otherwise.
*
* Return Value:
* HRESULT NOERROR
*/
STDMETHODIMP CCEditView::ContextSensitiveHelp( BOOL fEnterMode )
{
AFX_MANAGE_STATE(this->m_pModuleState);
return NOERROR;
}
/*
* CCEditView::GetBorder
*
* Purpose:
* Returns the rectangle in which the container is willing to
* negotiate about an object's adornments.
*
* Parameters:
* prcBorder LPRECT in which to store the rectangle.
*
* Return Value:
* HRESULT NOERROR if all is well, INPLACE_E_NOTOOLSPACE
* if there is no negotiable space.
*/
STDMETHODIMP CCEditView::GetBorder( LPRECT prcBorder )
{
AFX_MANAGE_STATE(this->m_pModuleState);
if ( NULL == prcBorder )
{
return E_INVALIDARG;
}
//We return all the client area space
GetClientRect( prcBorder );
return NOERROR;
}
/*
* CCEditView::RequestBorderSpace
*
* Purpose:
* Asks the container i
评论0