📄 document.cpp
字号:
}
/*
* CCosmoDoc::Clip
*
* Purpose:
* Places a private format, a metafile, and a bitmap of the display
* on the clipboard, optionally implementing Cut by deleting the
* data in the current window after rendering.
*
* Parameters:
* hWndFrame HWND of the main window.
* fCut BOOL indicating cut (TRUE) or copy (FALSE).
*
* Return Value:
* BOOL TRUE if successful, FALSE otherwise.
*/
BOOL CCosmoDoc::Clip(HWND hWndFrame, BOOL fCut)
{
BOOL fRet=TRUE;
HGLOBAL hMem;
UINT i;
//This array is so we can loop over the formats we provide.
static UINT rgcf[3]={0, CF_METAFILEPICT, CF_BITMAP};
const UINT cFormats=3;
if (!OpenClipboard(hWndFrame))
return FALSE;
//Clean out whatever junk is in the clipboard.
EmptyClipboard();
rgcf[0]=m_cf;
for (i=0; i < cFormats; i++)
{
//Copy private data first.
hMem=RenderFormat(rgcf[i]);
if (NULL!=hMem)
SetClipboardData(rgcf[i], hMem);
else
fRet &=FALSE;
}
//Free clipboard ownership.
CloseClipboard();
//Delete our current data if "cut" succeeded.
if (fRet && fCut)
{
m_pPL->New();
FDirtySet(TRUE);
}
return fRet;
}
/*
* CCosmoDoc::RenderFormat
*
* Purpose:
* Renders a specific clipboard format into global memory.
*
* Parameters:
* cf UINT format to render.
*
* Return Value:
* HGLOBAL Global memory handle containing the data.
*/
HGLOBAL CCosmoDoc::RenderFormat(UINT cf)
{
HGLOBAL hMem;
if (cf==m_cf)
{
m_pPL->DataGetMem(VERSIONCURRENT, &hMem);
return hMem;
}
switch (cf)
{
case CF_METAFILEPICT:
return m_pPL->RenderMetafilePict();
case CF_BITMAP:
return (HGLOBAL)m_pPL->RenderBitmap();
}
return NULL;
}
/*
* CCosmoDoc::FQueryPaste
*
* Purpose:
* Determines if we can paste data from the clipboard.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if data is available, FALSE otherwise.
*/
BOOL CCosmoDoc::FQueryPaste(void)
{
return IsClipboardFormatAvailable(m_cf);
}
/*
* CCosmoDoc::Paste
*
* Purpose:
* Retrieves the private data format from the clipboard and sets it
* to the current figure in the editor window.
*
* Note that if this function is called, then the clipboard format
* is available because the Paste menu item is only enabled if the
* format is present.
*
* Parameters:
* hWndFrame HWND of the main window.
*
* Return Value:
* BOOL TRUE if successful, FALSE otherwise.
*/
BOOL CCosmoDoc::Paste(HWND hWndFrame)
{
HGLOBAL hMem;
PPOLYLINEDATA ppl;
BOOL fRet=FALSE;
if (!OpenClipboard(hWndFrame))
return FALSE;
hMem=GetClipboardData(m_cf);
if (NULL!=hMem)
{
ppl=(PPOLYLINEDATA)GlobalLock(hMem);
//TRUE in wParam to cause PLN_SIZECHANGE notification
m_pPL->DataSet(ppl, FALSE, TRUE);
GlobalUnlock(hMem);
FDirtySet(TRUE);
fRet=TRUE;
}
CloseClipboard();
return fRet;
}
/*
* CCosmoDoc::ColorSet
*
* Purpose:
* Changes a color used in our contained Polyline.
*
* Parameters:
* iColor UINT index of the color to change.
* cr COLORREF new color.
*
* Return Value:
* COLORREF Previous color for the given index.
*/
COLORREF CCosmoDoc::ColorSet(UINT iColor, COLORREF cr)
{
return m_pPL->ColorSet(iColor, cr);
}
/*
* CCosmoDoc::ColorGet
*
* Purpose:
* Retrieves a color currently in use in the Polyline.
*
* Parameters:
* iColor UINT index of the color to retrieve.
*
* Return Value:
* COLORREF Current color for the given index.
*/
COLORREF CCosmoDoc::ColorGet(UINT iColor)
{
return m_pPL->ColorGet(iColor);
}
/*
* CCosmoDoc::LineStyleSet
*
* Purpose:
* Changes the line style currently used in the Polyline
*
* Parameters:
* iStyle UINT index of the new line style to use.
*
* Return Value:
* UINT Previous line style.
*/
UINT CCosmoDoc::LineStyleSet(UINT iStyle)
{
return m_pPL->LineStyleSet(iStyle);
}
/*
* CCosmoDoc::LineStyleGet
*
* Purpose:
* Retrieves the line style currently used in the Polyline
*
* Parameters:
* None
*
* Return Value:
* UINT Current line style.
*/
UINT CCosmoDoc::LineStyleGet(void)
{
if (NULL==m_pPL) //m_pPL might not be valid yet
return 0L;
return m_pPL->LineStyleGet();
}
/*
* CPolylineAdviseSink::CPolylineAdviseSink
* CPolylineAdviseSink::~CPolylineAdviseSink
*
* Constructor Parameters:
* pv LPVOID to store in this object
*/
CPolylineAdviseSink::CPolylineAdviseSink(LPVOID pv)
{
m_pv=pv;
return;
}
CPolylineAdviseSink::~CPolylineAdviseSink(void)
{
return;
}
/*
* CPolylineAdviseSink::OnPointChange
*
* Purpose:
* Informs the document that the polyline added or removed a point.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CPolylineAdviseSink::OnPointChange(void)
{
PCDocument pDoc=(PCDocument)m_pv;
pDoc->FDirtySet(TRUE);
return;
}
/*
* CPolylineAdviseSink::OnSizeChange
*
* Purpose:
* Informs the document that the polyline changed size.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CPolylineAdviseSink::OnSizeChange(void)
{
PCCosmoDoc pDoc=(PCCosmoDoc)m_pv;
RECT rc;
DWORD dwStyle;
/*
* Polyline window is informing us that it changed size in
* response to setting it's data. Therefore we have to
* size ourselves accordingly but without moving the screen
* position of the polyline window.
*/
pDoc->m_fNoSize=TRUE;
//Set the document window size.
GetWindowRect(pDoc->m_pPL->Window(), &rc);
InflateRect(&rc, 8, 8);
//Adjust for a window sans menu
dwStyle=GetWindowLong(pDoc->m_hWnd, GWL_STYLE);
AdjustWindowRect(&rc, dwStyle, FALSE);
SetWindowPos(pDoc->m_hWnd, NULL, 0, 0, rc.right-rc.left
, rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
if (NULL!=pDoc->m_pAdv)
pDoc->m_pAdv->OnSizeChange(pDoc, &rc);
pDoc->m_fNoSize=FALSE;
pDoc->FDirtySet(TRUE);
return;
}
/*
* CPolylineAdviseSink::OnDataChange
*
* Purpose:
* Informs the document that the polyline data changed.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CPolylineAdviseSink::OnDataChange(void)
{
PCCosmoDoc pDoc=(PCCosmoDoc)m_pv;
if (NULL!=pDoc->m_pAdv)
pDoc->m_pAdv->OnDataChange(pDoc);
pDoc->FDirtySet(TRUE);
return;
}
/*
* CPolylineAdviseSink::OnColorChange
*
* Purpose:
* Informs the document that the polyline data changed a color.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CPolylineAdviseSink::OnColorChange(void)
{
PCCosmoDoc pDoc=(PCCosmoDoc)m_pv;
pDoc->FDirtySet(TRUE);
return;
}
/*
* CPolylineAdviseSink::OnLineStyleChange
*
* Purpose:
* Informs the document that the polyline changed its line style.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CPolylineAdviseSink::OnLineStyleChange(void)
{
PCCosmoDoc pDoc=(PCCosmoDoc)m_pv;
pDoc->FDirtySet(TRUE);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -