?? autofig.cpp
字號:
/*
* AUTOFIG.CPP
* Cosmo Chapter 14
*
* "Figure" object for Cosmo's OLE Automation support, derived
* from CAutoBase.
*
* Copyright (c)1993-1995 Microsoft Corporation, All Right Reserved.
*
* Kraig Brockschmidt, Microsoft
* Internet : kraigb@microsoft.com
* Compuserve: INTERNET>kraigb@microsoft.com
*/
#include "cosmo.h"
/*
* CAutoFigure::CAutoFigure
* CAutoFigure::~CAutoFigure
*
* Constructor Parameters:
* pDoc PCCosmoDoc to the dpcument object that we
* use to implement much of this interface.
*/
CAutoFigure::CAutoFigure(PCCosmoDoc pDoc)
: CAutoBase(pDoc, pDoc->m_hInst, IID_ICosmoFigure
, DIID_DICosmoFigure, ObjectDestroyed)
{
return;
}
/*
* CAutoFigure::QueryInterface
* CAutoFigure::AddRef
* CAutoFigure::Release
*/
STDMETHODIMP CAutoFigure::QueryInterface(REFIID riid, PPVOID ppv)
{
*ppv=NULL;
if (IID_IUnknown==riid || IID_ICosmoFigure==riid)
*ppv=(IUnknown *)this;
if (IID_IDispatch==riid || m_diid==riid)
*ppv=m_pImpIDispatch;
if (IID_IExternalConnection==riid)
*ppv=m_pImpIExtConn;
if (NULL!=*ppv)
{
((LPUNKNOWN)*ppv)->AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP_(ULONG) CAutoFigure::AddRef(void)
{
return ++m_cRef;
}
STDMETHODIMP_(ULONG) CAutoFigure::Release(void)
{
/*
* Since this object might have come from a class factory,
* we count it's existence (see NewFigure below) for
* controlling shutdown of the application when we call
* ObjectDestroyed. Otherwise we always close the document.
*/
if (0L!=--m_cRef)
return m_cRef;
put_Visible(FALSE);
SendMessage(m_pDoc->Window(), WM_CLOSE, 0, 0L);
if (NULL!=m_pfnDestroy)
(*m_pfnDestroy)();
return 0L;
}
/*
* CAutoFigure::VTableInterface
*
* Purpose:
* Returns the right vtable pointer to use when calling
* ITypeInfo::Invoke (see CImpIDispatch::Invoke in AUTOBASE.CPP).
*/
void *CAutoFigure::VTableInterface(void)
{
return (ICosmoFigure *)this;
}
//All that follows is the ICosmoFigure implementation
/*
* CAutoFigure::Application
* CAutoFigure::Parent
* Properties, read-only
*
* The application object (CAutoApp) in which we're contained,
* which is stored in the frame object
*/
STDMETHODIMP_(IDispatch *) CAutoFigure::get_Application(void)
{
PCCosmoFrame pFR;
pFR=(PCCosmoFrame)m_pDoc->m_pFR;
return pFR->AutoApp()->get_Application();
}
STDMETHODIMP_(IDispatch *) CAutoFigure::get_Parent(void)
{
return get_Application();
}
/*
* CAutoFigure::FullName, Name, Path
* Properties, read-only
*
* Retrieve the full pathname of the figure file (FullName),
* just the file name (Name), or just the path (Path).
*
* Note that these functions are very similar to the same
* ones in CAutoApp, and there is probably some code that could
* be shared between them, but this sample won't bother with
* such an optimization.
*/
STDMETHODIMP_(BSTR) CAutoFigure::get_FullName(void)
{
if ((TCHAR)0==m_pDoc->m_szFile[0])
return NULL;
#ifdef WIN32ANSI
OLECHAR szTemp[512];
MultiByteToWideChar(CP_ACP, 0, m_pDoc->m_szFile, -1, szTemp, 512);
return SysAllocString(szTemp);
#else
return SysAllocString(m_pDoc->m_szFile);
#endif
}
STDMETHODIMP_(BSTR) CAutoFigure::get_Name(void)
{
BSTR bstrFull=NULL;
BSTR bstrName=NULL;
const int cch=256;
TCHAR szName[256];
//Get the full path
bstrFull=get_FullName();
if (NULL==bstrFull)
return NULL;
//Now retrieve just the filename
#ifdef WIN32ANSI
char szTemp[cch];
OLECHAR szTempW[cch];
WideCharToMultiByte(CP_ACP, 0, bstrFull, -1, szTemp
, cch, NULL, NULL);
if (0==GetFileTitle(szTemp, szName, cch))
{
MultiByteToWideChar(CP_ACP, 0, szName, -1, szTempW, cch);
bstrName=SysAllocString(szTempW);
}
#else
if (0==GetFileTitle(bstrFull, szName, cch))
bstrName=SysAllocString(szName);
#endif
SysFreeString(bstrFull);
return bstrName;
}
STDMETHODIMP_(BSTR) CAutoFigure::get_Path(void)
{
BSTR bstrFull=NULL;
BSTR bstrName=NULL;
BSTR bstrPath=NULL;
bstrFull=get_FullName();
if (NULL==bstrFull)
return NULL;
bstrName=get_Name();
if (NULL!=bstrName)
{
LPOLESTR psz;
/*
* Find the position of bstrName in bstrFull then copy
* only charaters up to that point into bstrPath.
*/
#ifdef WIN32ANSI
psz=wcsstr(bstrFull, bstrName);
#else
psz=_tcsstr(bstrFull, bstrName);
#endif
//The -1 accounts for the \ before the filename
bstrPath=SysAllocStringLen(bstrFull
, ((psz-bstrFull)/sizeof(TCHAR))-1);
SysFreeString(bstrName);
}
SysFreeString(bstrFull);
return bstrPath;
}
/*
* CAutoFigure::Saved
* Property, read-only
*
* TRUE if the document is clean, FALSE otherwise.
*/
STDMETHODIMP_(VARIANT_BOOL) CAutoFigure::get_Saved(void)
{
return !m_pDoc->FDirtyGet();
}
/*
* CAutoFigure::NumberOfPoints
* Property, read-only
*
* Number of points in the current figure.
*/
STDMETHODIMP_(short)CAutoFigure::get_NumberOfPoints(void)
{
POLYLINEDATA pl;
m_pDoc->m_pPL->DataGet(&pl, VERSIONCURRENT);
return pl.cPoints;
}
/*
* CAutoFigure::BackColor
* CAutoFigure::LineColor
* Properties, read-write
*
* Colors used in the figure.
*/
STDMETHODIMP_(long) CAutoFigure::get_BackColor(void)
{
return m_pDoc->ColorGet(POLYLINECOLOR_BACKGROUND);
}
STDMETHODIMP_(void) CAutoFigure::put_BackColor(long clrBack)
{
m_pDoc->ColorSet(POLYLINECOLOR_BACKGROUND, clrBack);
return;
}
STDMETHODIMP_(long) CAutoFigure::get_LineColor(void)
{
return m_pDoc->ColorGet(POLYLINECOLOR_LINE);
}
STDMETHODIMP_(void) CAutoFigure::put_LineColor(long clrLine)
{
m_pDoc->ColorSet(POLYLINECOLOR_LINE, clrLine);
return;
}
/*
* CAutoFigure::LineStyle
* Property, read-write
*
* Line style used to draw the figure
*/
STDMETHODIMP_(short)CAutoFigure::get_LineStyle(void)
{
return m_pDoc->LineStyleGet();
}
STDMETHODIMP_(void) CAutoFigure::put_LineStyle(short iStyle)
{
m_pDoc->LineStyleSet(iStyle);
return;
}
/*
* CAutoFigure::Left, Top, Width, Height
* Properties, read-write
*
* Horizontal (Left) and vertical (Top) positions of the frame
* window from the left and top edges of the application client
* area; horizontal (Width) and vertical (Height) dimensions of
* document window. All of these functions call our private member
* MoveSize, a helper function.
*/
STDMETHODIMP_(long) CAutoFigure::get_Left(void)
{
return MoveSize(MOVESIZEACTION_GETLEFT, 0, 0, 0, 0);
}
STDMETHODIMP_(void) CAutoFigure::put_Left(long x)
{
MoveSize(MOVESIZEACTION_LEFT, x, 0, 0, 0);
return;
}
STDMETHODIMP_(long) CAutoFigure::get_Top(void)
{
return MoveSize(MOVESIZEACTION_GETTOP, 0, 0, 0, 0);
}
STDMETHODIMP_(void) CAutoFigure::put_Top(long y)
{
MoveSize(MOVESIZEACTION_TOP, 0, y, 0, 0);
return;
}
STDMETHODIMP_(long) CAutoFigure::get_Width(void)
{
return MoveSize(MOVESIZEACTION_GETWIDTH, 0, 0, 0, 0);
}
STDMETHODIMP_(void) CAutoFigure::put_Width(long cx)
{
MoveSize(MOVESIZEACTION_WIDTH, 0, 0, cx, 0);
return;
}
STDMETHODIMP_(long) CAutoFigure::get_Height(void)
{
return MoveSize(MOVESIZEACTION_GETHEIGHT, 0, 0, 0, 0);
}
STDMETHODIMP_(void) CAutoFigure::put_Height(long cy)
{
MoveSize(MOVESIZEACTION_HEIGHT, 0, 0, 0, cy);
return;
}
/*
* CAutoFigure::Visible
* Properties, read-write
*
* Controls visibility of the figure window (which is hidden by
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -