BOOL COlePasteSpecialDialog::CreateItem(COleClientItem *pNewItem) { ASSERT_VALID(this); ASSERT(pNewItem != NULL); ASSERT(m_ps.lpSrcDataObj != NULL); CWaitCursor wait; COleDataObject dataObject; dataObject.Attach(m_ps.lpSrcDataObj, FALSE); UINT selType = GetSelectionType(); BOOL bResult = TRUE; switch (selType) { case pasteLink: // paste link if (!pNewItem->CreateLinkFromData(&dataObject)) { TRACE0("Warning: CreateLinkFromData failed.\n"); bResult = FALSE; } break; case pasteStatic: if (!pNewItem->CreateStaticFromData(&dataObject)) { TRACE0("Warning: CreateStaticFromData failed.\n"); bResult = FALSE; } break; default: ASSERT(selType == pasteNormal); if (!pNewItem->CreateFromData(&dataObject)) { TRACE0("Warning: CreateFromData failed.\n"); bResult = FALSE; } break; } // deal with Display As Iconic option if (bResult && GetDrawAspect() == DVASPECT_ICON) { // setup iconic cache (it will draw iconic by default as well) if (!pNewItem->SetIconicMetafile(m_ps.hMetaPict)) { TRACE0("Warning: failed to set iconic aspect.\n"); bResult = FALSE; } else { // since picture was set OK, draw as iconic as well... pNewItem->SetDrawAspect(DVASPECT_ICON); } } return bResult; }
CLIPFORMAT CRulerRichEdit::GetAcceptableClipFormat(LPDATAOBJECT lpDataOb, CLIPFORMAT format) { if (m_bPasteSimple) #ifndef _UNICODE return CF_TEXT; #else return CF_UNICODETEXT; #endif static CLIPFORMAT cfRtf = (CLIPFORMAT)::RegisterClipboardFormat(CF_RTF); static CLIPFORMAT cfRtfObj = (CLIPFORMAT)::RegisterClipboardFormat(CF_RETEXTOBJ); CLIPFORMAT formats[] = { COutlookHelper::CF_OUTLOOK, CF_HDROP, cfRtf, cfRtfObj, CF_BITMAP, #ifndef _UNICODE CF_TEXT, #else CF_UNICODETEXT, #endif CF_METAFILEPICT, CF_SYLK, CF_DIF, CF_TIFF, CF_OEMTEXT, CF_DIB, CF_PALETTE, CF_PENDATA, CF_RIFF, CF_WAVE, CF_ENHMETAFILE }; const long nNumFmts = sizeof(formats) / sizeof(CLIPFORMAT); COleDataObject dataobj; dataobj.Attach(lpDataOb, FALSE); for (int nFmt = 0; nFmt < nNumFmts; nFmt++) { if (format && format == formats[nFmt]) return format; if (dataobj.IsDataAvailable(formats[nFmt])) return formats[nFmt]; } // all else return CF_HDROP; }
STDMETHODIMP CBmpCtxMenuExt::Initialize ( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDO, HKEY hkeyProgID ) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); COleDataObject dataobj; HGLOBAL hglobal; HDROP hdrop; bool bOK = false; dataobj.Attach ( pDO, FALSE ); // FALSE = don't release IDataObject interface when destroyed // Get the first selected file name. I'll keep this simple and just check // the first name to see if it's a .BMP. hglobal = dataobj.GetGlobalData ( CF_HDROP ); if ( NULL == hglobal ) return E_INVALIDARG; hdrop = (HDROP) GlobalLock ( hglobal ); if ( NULL == hdrop ) return E_INVALIDARG; // Get the name of the first selected file. if ( DragQueryFile ( hdrop, 0, m_szFile, MAX_PATH )) { // Is its extension .BMP? if ( PathMatchSpec ( m_szFile, _T("*.bmp") )) { // Load the bitmap and attach our CBitmap object to it. HBITMAP hbm = (HBITMAP) LoadImage ( NULL, m_szFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); if ( NULL != hbm ) { // We loaded the bitmap, so attach the CBitmap to it. VERIFY( m_bmp.Attach ( hbm ) ); bOK = true; } } } GlobalUnlock ( hglobal ); return bOK ? S_OK : E_FAIL; }
// without this, idiot will paste files and other objects into window HRESULT mfc_edit_view::QueryAcceptData(LPDATAOBJECT lpdataobj, CLIPFORMAT* lpcfFormat, DWORD reco, BOOL fReally, HGLOBAL hMetaPict) { if (*lpcfFormat == CF_TEXT) return S_OK; COleDataObject dataobj; dataobj.Attach(lpdataobj, FALSE); if (*lpcfFormat==0 && dataobj.IsDataAvailable(CF_TEXT)) { *lpcfFormat = CF_TEXT; return S_OK; } return S_FALSE; }
STDMETHODIMP CSite::Drop(IDataObject * pDataObject,DWORD grfKeyState, POINTL pt,DWORD * pdwEffect) { COleDataObject pData; pData.Attach(pDataObject,FALSE); FORMATETC stFormatTEXT = {CF_TEXT,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL}; STGMEDIUM outData = {0}; if(pData.GetData(CF_TEXT,&outData,&stFormatTEXT)) { _bstr_t strText = (LPCTSTR)GlobalLock(outData.hGlobal); m_pFR->InsertTEXT(strText); GlobalUnlock(outData.hGlobal); } return S_OK; }
STDMETHODIMP CSite::DragEnter(IDataObject * pDataObject, WORD grfKeyState, POINTL pt,DWORD * pdwEffect) { if(!pDataObject||!pdwEffect) return E_INVALIDARG; COleDataObject pData; pData.Attach(pDataObject,FALSE); FORMATETC stFormatTEXT = {CF_TEXT,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL}; if(pData.IsDataAvailable(CF_HDROP)) { *pdwEffect = DROPEFFECT_NONE; return E_INVALIDARG; } *pdwEffect = DROPEFFECT_COPY; return S_OK; }
HRESULT CvSqlQueryRichEditView::QueryAcceptData(LPDATAOBJECT lpdataobj, CLIPFORMAT* lpcfFormat, DWORD dwReco, BOOL bReally, HGLOBAL hMetaPict) { ASSERT(lpcfFormat != NULL); if (!bReally) // not actually pasting return S_OK; // if direct pasting a particular native format allow it if (IsRichEditFormat(*lpcfFormat)) return S_OK; COleDataObject dataobj; dataobj.Attach(lpdataobj, FALSE); // if format is 0, then force particular formats if available if (*lpcfFormat == 0 && (m_nPasteType == 0)) { if (dataobj.IsDataAvailable(CF_TEXT)) { *lpcfFormat = CF_TEXT; return S_OK; } } return S_FALSE; }
BOOL CEx27bView::MakeMetafilePict(COleDataSource* pSource) { CEx27bDoc* pDoc = GetDocument(); COleDataObject dataObject; LPDATAOBJECT pDataObj; // OLE object's IDataObject interface VERIFY(pDoc->m_lpOleObj->QueryInterface(IID_IDataObject, (void**) &pDataObj) == S_OK); dataObject.Attach(pDataObj); FORMATETC fmtem; SETFORMATETC(fmtem, CF_METAFILEPICT, DVASPECT_CONTENT, NULL, TYMED_MFPICT, -1); if (!dataObject.IsDataAvailable(CF_METAFILEPICT, &fmtem)) { TRACE("CF_METAFILEPICT format is unavailable\n"); return FALSE; } // Just copy the metafile handle from the OLE object // to the clipboard data object STGMEDIUM stgmm; VERIFY(dataObject.GetData(CF_METAFILEPICT, &stgmm, &fmtem)); pSource->CacheData(CF_METAFILEPICT, &stgmm, &fmtem); return TRUE; }
CLIPFORMAT CUrlRichEditCtrl::GetAcceptableClipFormat(LPDATAOBJECT lpDataOb, CLIPFORMAT format) { CLIPFORMAT formats[] = { CF_HDROP, #ifndef _UNICODE CF_TEXT, #else CF_UNICODETEXT, #endif }; const long nNumFmts = sizeof(formats) / sizeof(CLIPFORMAT); // check for outlook first if (COutlookHelper::IsOutlookObject(lpDataOb)) return COutlookHelper::CF_OUTLOOK; // else COleDataObject dataobj; dataobj.Attach(lpDataOb, FALSE); for (int nFmt = 0; nFmt < nNumFmts; nFmt++) { if (format && format == formats[nFmt]) return format; if (dataobj.IsDataAvailable(formats[nFmt])) return formats[nFmt]; } #ifndef _UNICODE return CF_TEXT; #else return CF_UNICODETEXT; #endif }
//IDropTarget STDMETHODIMP CDropT::DragEnter(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) { COleDataObject dataObj; HGLOBAL global = NULL; HDROP dropFile = NULL; dataObj.Attach(pDataObj, FALSE); if(global = dataObj.GetGlobalData(CF_HDROP)) { UINT numDropFile = 0; wchar_t buff[MAX_PATH] = {0}; dropFile = static_cast<HDROP>(GlobalLock(global)); numDropFile = DragQueryFile(dropFile, 0xFFFFFFFF, buff, MAX_PATH); for(UINT i = 0; i != numDropFile; ++i) { if(DragQueryFile(dropFile, i, buff, MAX_PATH)) { m_lsDroppedFiles.push_back(buff); } } GlobalUnlock(global); } dataObj.Detach(); if(!m_lsDroppedFiles.empty()) { *pdwEffect = DROPEFFECT_COPY; } else { *pdwEffect = DROPEFFECT_NONE; } return S_OK; }
// Update this later. For now, bail out (via the base class) DROPEFFECT SECEditCtrlOleDropTarget::OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint point) { //return COleDropTarget::OnDragScroll(pWnd, dwKeyState, point); ASSERT_VALID(this); ASSERT_VALID(pWnd); if (!pWnd->IsKindOf(RUNTIME_CLASS(SECEditCtrl))) return DROPEFFECT_NONE; SECEditCtrl* pSECEditCtrl = (SECEditCtrl*)pWnd; DROPEFFECT dropEffect = 0; // get client rectangle of destination window CRect rectClient; pWnd->GetClientRect(&rectClient); CRect rect = rectClient; // hit-test against inset region UINT nTimerID = MAKEWORD(-1, -1); rect.InflateRect(-nScrollInset, -nScrollInset); if (rectClient.PtInRect(point) && !rect.PtInRect(point)) { // determine which way to scroll along both X & Y axis if (point.x < rect.left) nTimerID = MAKEWORD(SB_LINEUP, HIBYTE(nTimerID)); else if (point.x >= rect.right) nTimerID = MAKEWORD(SB_LINEDOWN, HIBYTE(nTimerID)); if (point.y < rect.top) nTimerID = MAKEWORD(LOBYTE(nTimerID), SB_LINEUP); else if (point.y >= rect.bottom) nTimerID = MAKEWORD(LOBYTE(nTimerID), SB_LINEDOWN); ASSERT(nTimerID != MAKEWORD(-1, -1)); BOOL bEnableScroll = FALSE; bEnableScroll = pSECEditCtrl->OnScroll(nTimerID, 0, FALSE); if (!bEnableScroll) nTimerID = MAKEWORD(-1, -1); } if (nTimerID == MAKEWORD(-1, -1)) { if (m_nTimerID != MAKEWORD(-1, -1)) { // send fake OnDragEnter when transition from scroll->normal COleDataObject dataObject; dataObject.Attach(m_lpDataObject, FALSE); OnDragEnter(pWnd, &dataObject, dwKeyState, point); m_nTimerID = MAKEWORD(-1, -1); } return DROPEFFECT_NONE; } // save tick count when timer ID changes DWORD dwTick = GetTickCount(); if (nTimerID != m_nTimerID) { m_dwLastTick = dwTick; m_nScrollDelay = nScrollDelay; } // scroll if necessary if (dwTick - m_dwLastTick > m_nScrollDelay) { pSECEditCtrl->OnScroll(nTimerID, 0, TRUE); m_dwLastTick = dwTick; m_nScrollDelay = nScrollInterval; } if (m_nTimerID == MAKEWORD(-1, -1)) { // send fake OnDragLeave when transitioning from normal->scroll OnDragLeave(pWnd); } m_nTimerID = nTimerID; // check for force link if ((dwKeyState & (MK_CONTROL|MK_SHIFT)) == (MK_CONTROL|MK_SHIFT)) dropEffect = DROPEFFECT_SCROLL|DROPEFFECT_LINK; // check for force copy else if ((dwKeyState & MK_CONTROL) == MK_CONTROL) dropEffect = DROPEFFECT_SCROLL|DROPEFFECT_COPY; // check for force move else if ((dwKeyState & MK_ALT) == MK_ALT || (dwKeyState & MK_SHIFT) == MK_SHIFT) dropEffect = DROPEFFECT_SCROLL|DROPEFFECT_MOVE; // default -- recommended action is move else dropEffect = DROPEFFECT_SCROLL|DROPEFFECT_MOVE; return dropEffect; }
DROPEFFECT COleDropTarget::OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint point) { ASSERT_VALID(this); ASSERT_VALID(pWnd); // CWnds are allowed, but don't support autoscrolling if (!pWnd->IsKindOf(RUNTIME_CLASS(CView))) return DROPEFFECT_NONE; CView* pView = (CView*)pWnd; DROPEFFECT dropEffect = pView->OnDragScroll(dwKeyState, point); // DROPEFFECT_SCROLL means do the default if (dropEffect != DROPEFFECT_SCROLL) return dropEffect; // get client rectangle of destination window CRect rectClient; pWnd->GetClientRect(&rectClient); CRect rect = rectClient; // hit-test against inset region UINT nTimerID = 0xffff; rect.InflateRect(-nScrollInset, -nScrollInset); CSplitterWnd* pSplitter = NULL; if (rectClient.PtInRect(point) && !rect.PtInRect(point)) { // determine which way to scroll along both X & Y axis if (point.x < rect.left) nTimerID = MAKEWORD(SB_LINEUP, HIBYTE(nTimerID)); else if (point.x >= rect.right) nTimerID = MAKEWORD(SB_LINEDOWN, HIBYTE(nTimerID)); if (point.y < rect.top) nTimerID = MAKEWORD(LOBYTE(nTimerID), SB_LINEUP); else if (point.y >= rect.bottom) nTimerID = MAKEWORD(LOBYTE(nTimerID), SB_LINEDOWN); ASSERT(nTimerID != 0xffff); // check for valid scroll first pSplitter = CView::GetParentSplitter(pView, FALSE); BOOL bEnableScroll = FALSE; if (pSplitter != NULL) bEnableScroll = pSplitter->DoScroll(pView, nTimerID, FALSE); else bEnableScroll = pView->OnScroll(nTimerID, 0, FALSE); if (!bEnableScroll) nTimerID = 0xffff; } if (nTimerID == 0xffff) { if (m_nTimerID != 0xffff) { // send fake OnDragEnter when transition from scroll->normal COleDataObject dataObject; dataObject.Attach(m_lpDataObject, FALSE); OnDragEnter(pWnd, &dataObject, dwKeyState, point); m_nTimerID = 0xffff; } return DROPEFFECT_NONE; } // save tick count when timer ID changes DWORD dwTick = GetTickCount(); if (nTimerID != m_nTimerID) { m_dwLastTick = dwTick; m_nScrollDelay = nScrollDelay; } // scroll if necessary if (dwTick - m_dwLastTick > m_nScrollDelay) { if (pSplitter != NULL) pSplitter->DoScroll(pView, nTimerID, TRUE); else pView->OnScroll(nTimerID, 0, TRUE); m_dwLastTick = dwTick; m_nScrollDelay = nScrollInterval; } if (m_nTimerID == 0xffff) { // send fake OnDragLeave when transitioning from normal->scroll OnDragLeave(pWnd); } m_nTimerID = nTimerID; // check for force link if ((dwKeyState & (MK_CONTROL|MK_SHIFT)) == (MK_CONTROL|MK_SHIFT)) dropEffect = DROPEFFECT_SCROLL|DROPEFFECT_LINK; // check for force copy else if ((dwKeyState & MK_CONTROL) == MK_CONTROL) dropEffect = DROPEFFECT_SCROLL|DROPEFFECT_COPY; // check for force move else if ((dwKeyState & MK_ALT) == MK_ALT || (dwKeyState & MK_SHIFT) == MK_SHIFT) dropEffect = DROPEFFECT_SCROLL|DROPEFFECT_MOVE; // default -- recommended action is move else dropEffect = DROPEFFECT_SCROLL|DROPEFFECT_MOVE; return dropEffect; }
void SourceEdit::OnConvertPaste(NMHDR* hdr, LRESULT* res) { SCNXConvertPaste* cp = (SCNXConvertPaste*)hdr; *res = 0; // Get the source of the data COleDataObject data; if (cp->source) data.Attach((LPDATAOBJECT)(cp->source),FALSE); else data.AttachClipboard(); // Try to interpret tables and leading white space if (data.IsDataAvailable(CF_UNICODETEXT)) { CStringW theText(cp->utext,cp->ulen); CStringW newText, line; newText.Preallocate(theText.GetLength()); bool foundTable = false; bool inTable = false; int charPos = 0, lineCount = 0; while (GetNextLine(theText,line,charPos)) { if (inTable) { CArray<CStringW> tokens; TokenizeLine(line,tokens); // Separate multiple tokens with tabs: if less than two tokens, // we're at the end of the table if (tokens.GetSize() > 1) { line.Empty(); for (int j = 0; j < tokens.GetSize(); j++) { if (j > 0) line.AppendChar(L'\t'); line.Append(tokens.GetAt(j)); } } else inTable = false; } else { // Look for the start of a table if (line.Left(6).CompareNoCase(L"table ") == 0) { inTable = true; foundTable = true; } // Replace any leading blocks of 4 spaces int i = 0; while (i >= 0) { if (line.Mid(i,4).Compare(L" ") == 0) { line.Delete(i,3); line.SetAt(i,L'\t'); i++; } else i = -1; } } if (lineCount > 0) newText.AppendChar(L'\n'); newText.Append(line); lineCount++; } CString newTextUtf = TextFormat::UnicodeToUTF8(newText); cp->text = new char[newTextUtf.GetLength() + 1]; strcpy(cp->text,newTextUtf); *res = 1; } }
DROPEFFECT CBCGPPlannerDropTarget::OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint point) { if (m_pPlanner == NULL) { return DROPEFFECT_NONE; } ASSERT_VALID (m_pPlanner); DROPEFFECT dropEffect = m_pPlanner->OnDragScroll(dwKeyState, point); // DROPEFFECT_SCROLL means do the default if (dropEffect != DROPEFFECT_SCROLL) return dropEffect; // get client rectangle of destination window CRect rectClient; m_pPlanner->GetDragScrollRect(rectClient); CRect rect = rectClient; // hit-test against inset region UINT nTimerID = MAKEWORD(-1, -1); rect.InflateRect(-nScrollInset, -nScrollInset); if (rectClient.PtInRect(point) && !rect.PtInRect(point)) { // determine which way to scroll along both X & Y axis if (point.x < rect.left) { nTimerID = MAKEWORD(SB_LINEUP, HIBYTE(nTimerID)); } else if (point.x >= rect.right) { nTimerID = MAKEWORD(SB_LINEDOWN, HIBYTE(nTimerID)); } if (point.y < rect.top) { nTimerID = MAKEWORD(LOBYTE(nTimerID), SB_LINEUP); } else if (point.y >= rect.bottom) { nTimerID = MAKEWORD(LOBYTE(nTimerID), SB_LINEDOWN); } ASSERT(nTimerID != MAKEWORD(-1, -1)); BOOL bEnableScroll = m_pPlanner->OnScroll(nTimerID, 0, FALSE); if (!bEnableScroll) { nTimerID = MAKEWORD(-1, -1); } } if (m_nTimerID == MAKEWORD(-1, -1) && nTimerID != MAKEWORD(-1, -1)) { // send fake OnDragEnter when transition from scroll->normal COleDataObject dataObject; dataObject.Attach(m_lpDataObject, FALSE); OnDragEnter(pWnd, &dataObject, dwKeyState, point); } if (nTimerID == MAKEWORD(-1, -1)) { if (m_nTimerID != MAKEWORD(-1, -1)) { // send fake OnDragEnter when transition from scroll->normal //COleDataObject dataObject; //dataObject.Attach(m_lpDataObject, FALSE); //OnDragEnter(pWnd, &dataObject, dwKeyState, point); m_nTimerID = MAKEWORD(-1, -1); } return DROPEFFECT_NONE; } // save tick count when timer ID changes DWORD dwTick = GetTickCount(); if (nTimerID != m_nTimerID) { m_dwLastTick = dwTick; m_nScrollDelay = nScrollDelay; } // scroll if necessary if (dwTick - m_dwLastTick > m_nScrollDelay) { m_pPlanner->OnScroll(nTimerID, 0, TRUE); m_dwLastTick = dwTick; m_nScrollDelay = nScrollInterval; } if (m_nTimerID == MAKEWORD(-1, -1)) { // send fake OnDragLeave when transitioning from normal->scroll //OnDragLeave(pWnd); } m_nTimerID = nTimerID; /* // check for force link if ((dwKeyState & (MK_CONTROL | MK_SHIFT)) == (MK_CONTROL | MK_SHIFT)) dropEffect = DROPEFFECT_SCROLL|DROPEFFECT_LINK; // check for force copy else */if ((dwKeyState & MK_CONTROL) == MK_CONTROL) dropEffect = DROPEFFECT_SCROLL | DROPEFFECT_COPY; // check for force move else if ((dwKeyState & MK_ALT) == MK_ALT || (dwKeyState & MK_SHIFT) == MK_SHIFT) dropEffect = DROPEFFECT_SCROLL | DROPEFFECT_MOVE; // default -- recommended action is move else dropEffect = DROPEFFECT_SCROLL | DROPEFFECT_MOVE; return dropEffect; }
BOOL COleClientItem::FreezeLink() { ASSERT_VALID(this); ASSERT(m_lpObject != NULL); ASSERT(m_pDocument != NULL); ASSERT(GetType() == OT_LINK); // first save & close the item Close(); // get IDataObject interface LPDATAOBJECT lpDataObject = QUERYINTERFACE(m_lpObject, IDataObject); ASSERT(lpDataObject != NULL); COleDataObject dataObject; dataObject.Attach(lpDataObject, TRUE); // save important state of original item LPOLEOBJECT lpObject = m_lpObject; LPSTORAGE lpStorage = m_lpStorage; LPLOCKBYTES lpLockBytes = m_lpLockBytes; LPVIEWOBJECT2 lpViewObject = m_lpViewObject; DWORD dwConnection = m_dwConnection; DWORD dwItemNumber = m_dwItemNumber; m_lpObject = NULL; m_lpStorage = NULL; m_lpLockBytes = NULL; m_lpViewObject = NULL; m_dwConnection = 0; // attempt to create new object from data if (!CreateStaticFromData(&dataObject)) { m_lpObject = lpObject; m_lpStorage = lpStorage; m_lpLockBytes = lpLockBytes; m_lpViewObject = lpViewObject; m_dwConnection = dwConnection; return FALSE; } #ifdef _DEBUG UpdateItemType(); ASSERT(GetType() == OT_STATIC); #endif // save new state of that item LPOLEOBJECT lpNewObject = m_lpObject; LPSTORAGE lpNewStorage = m_lpStorage; LPLOCKBYTES lpNewLockBytes = m_lpLockBytes; LPVIEWOBJECT2 lpNewViewObject = m_lpViewObject; DWORD dwNewConnection = m_dwConnection; DWORD dwNewItemNumber = m_dwItemNumber; // shut down old item m_lpObject = lpObject; m_lpStorage = lpStorage; m_lpLockBytes = lpLockBytes; m_lpViewObject = lpViewObject; m_dwConnection = dwConnection; m_dwItemNumber = dwItemNumber; #ifdef _DEBUG UpdateItemType(); ASSERT(GetType() == OT_LINK); #endif Delete(FALSE); // revokes item & removes storage // switch to new item m_lpObject = lpNewObject; m_lpStorage = lpNewStorage; m_lpLockBytes = lpNewLockBytes; m_lpViewObject = lpNewViewObject; m_dwConnection = dwNewConnection; m_dwItemNumber = dwNewItemNumber; UpdateItemType(); ASSERT(GetType() == OT_STATIC); // send an on changed with same state to invalidate the item OnChange(OLE_CHANGED_STATE, (DWORD)GetItemState()); ASSERT_VALID(m_pDocument); m_pDocument->SetModifiedFlag(); return TRUE; }
HRESULT CUrlRichEditCtrl::QueryAcceptData(LPDATAOBJECT lpdataobj, CLIPFORMAT* lpcfFormat, DWORD /*reco*/, BOOL fReally, HGLOBAL /*hMetaPict*/) { BOOL bEnable = !(GetStyle() & ES_READONLY) && IsWindowEnabled(); // always clear drag object m_lpDragObject = NULL; if (bEnable) { // snap-shot drag object when dragging if (!fReally) m_lpDragObject = lpdataobj; *lpcfFormat = GetAcceptableClipFormat(lpdataobj, *lpcfFormat); // is this an outlook drop actually happening? if (fReally && (*lpcfFormat == COutlookHelper::CF_OUTLOOK)) { BOOL bEnable = !(GetStyle() & ES_READONLY) && IsWindowEnabled(); ASSERT(bEnable); if (!bEnable) return E_FAIL; // insert outlook links at the cursor position SetSel(m_crDropSel); COleDataObject dataobj; dataobj.Attach(lpdataobj, FALSE); ASSERT(COutlookHelper::IsOutlookObject(&dataobj)); COutlookHelper outlook; OutlookAPI::Selection* pSelection = outlook.GetSelection(); CString sLinks; int nNumSel = pSelection->GetCount(); // 1-based indexing for (short nSel = 1; nSel <= nNumSel; nSel++) { OutlookAPI::_MailItem item(pSelection->Item(COleVariant(nSel))); // format 'nicely' unless shift is pressed DWORD dwFlags = OAFMT_BRACED; if (!Misc::ModKeysArePressed(MKS_SHIFT)) dwFlags |= OAFMT_NICE; sLinks += COutlookHelper::FormatItemAsUrl(item, dwFlags); if ((nSel < nNumSel) || (nNumSel > 1)) sLinks += '\n'; } // cleanup delete pSelection; // trailing newline if (!sLinks.IsEmpty()) { // leading and trailing spaces if (m_crDropSel.cpMin > 0) { if (nNumSel == 1) sLinks = ' ' + sLinks + ' '; else sLinks = '\n' + sLinks; } ReplaceSel(sLinks, TRUE); ParseAndFormatText(); SetFocus(); return S_OK; } else return E_FAIL; } return S_OK; } // else return E_FAIL; }
BOOL CBCGPMSOffice2007DemoView::InsertBitmap (UINT uiBmpResID) { CWaitCursor wait; CBitmap bmp; if (!bmp.LoadBitmap(uiBmpResID)) { return FALSE; } COleDataSource* pDataSrc = new COleDataSource; COleDataObject* pData = new COleDataObject; CBCGPMSOffice2007DemoCntrItem* pItem = NULL; TRY { WPD_CHARFORMAT cf = GetCharFormatSelection(); STGMEDIUM stgm; stgm.hGlobal = bmp.GetSafeHandle(); stgm.tymed = TYMED_GDI; stgm.pUnkForRelease = NULL; pDataSrc->CacheData (CF_BITMAP, &stgm); LPDATAOBJECT lpdata; if (FAILED (pDataSrc->m_xDataObject.QueryInterface (IID_IDataObject, (LPVOID FAR*) &lpdata))) { AfxThrowUserException(); } pData->Attach (lpdata); CBCGPMSOffice2007DemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pItem = new CBCGPMSOffice2007DemoCntrItem (NULL, pDoc); ASSERT_VALID(pItem); if (!pItem->CreateStaticFromData (pData)) { AfxThrowUserException(); } pItem->m_uiCategoryID = uiBmpResID; InsertItem (pItem); pDoc->UpdateAllViews (this); SetCharFormat (cf); SyncFont (); } CATCH(CException, e) { if (pItem != NULL) { ASSERT_VALID(pItem); pItem->Delete (); } delete pData; delete pDataSrc; return FALSE; } END_CATCH delete pData; delete pDataSrc; CMainFrame* pMainFrame = ((CMainFrame*) GetTopLevelFrame ()); ASSERT_VALID (pMainFrame); pMainFrame->ActivateRibbonContextCategory (uiBmpResID); return TRUE; }