void CArtOleDropTarget::AddUntitledPictToBrowser(const CString& filename, CArtBrowserDialog* pBrowser) { // Add dropped or pasted art data file to browser... // Friendly name will be "Untitled n" - n being the number on the end of filename. // The filenames should be of the form "Artnnnnn.???", starting with "Art00001" CString friendlyName; friendlyName.LoadString(IDS_UNTITLED); CString strNum = filename.Mid(filename.ReverseFind('.') - 5, 5); strNum.Format(" %d", atoi(strNum)); friendlyName += strNum; // load the default art category CString strCategory; strCategory.LoadString(IDS_DEF_ART_CATEGORY); CPMWCollection* pCollection = pBrowser->GetCollectionManager()->GetUserCollection(CPMWCollection::typeArt); if (pCollection->ImportItem(filename, friendlyName, NULL, strCategory) == ERRORCODE_None) pBrowser->UpdateAllBrowsers(); }
BOOL CArtOleDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point) { CArtBrowserDialog* pBrowser = (CArtBrowserDialog*)pWnd; CPMWCollection* pCollection = pBrowser->GetCollectionManager()->GetUserCollection(CPMWCollection::typeArt); if (pDataObject->IsDataAvailable(Clipboard::m_uFilenameFormat)) { CString filename = GetUniqueUserArtFilename("pmo"); if (SaveClipObjectsToUserArt(pDataObject, filename)) AddUntitledPictToBrowser(filename, pBrowser); } else if (pDataObject->IsDataAvailable(CF_METAFILEPICT)) { CString filename = GetUniqueUserArtFilename("wmf"); if (Save_CF_METAFILEPICT_ToUserArt(pDataObject, filename)) AddUntitledPictToBrowser(filename, pBrowser); } else if (pDataObject->IsDataAvailable(CF_DIB)) { CString filename = GetUniqueUserArtFilename("bmp"); if (Save_CF_DIB_ToUserArt(pDataObject, filename)) AddUntitledPictToBrowser(filename, pBrowser); } else if (pDataObject->IsDataAvailable(CF_BITMAP)) { CString filename = GetUniqueUserArtFilename("bmp"); if (Save_CF_BITMAP_ToUserArt(pDataObject, filename)) AddUntitledPictToBrowser(filename, pBrowser); } else if (pDataObject->IsDataAvailable(CF_HDROP)) { HDROP hDropInfo; if ((hDropInfo = (HDROP)pDataObject->GetGlobalData(CF_HDROP)) != NULL) { UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); CBrowserProgressDialog ProgressDialog(IDD_BROWSER_IMPORT_PROGRESS, nFiles, pWnd, IDS_CONFIRM_CANCEL_BROWSER_IMPORT); BOOL fPromptForOverwrite = TRUE; // used for overwriting of local files // load the default art category CString strCategory; strCategory.LoadString(IDS_DEF_ART_CATEGORY); for (UINT iFile = 0; iFile < nFiles; iFile++) { TCHAR szFileName[_MAX_PATH]; ::DragQueryFile(hDropInfo, iFile, szFileName, _MAX_PATH); if (type_of_art_extension(szFileName) != GRAPHIC_TYPE_UNKNOWN) { BOOL fDoImport = TRUE; ProgressDialog.SetPosition(iFile, szFileName); if (ProgressDialog.CheckForAbort()) break; if (dropEffect == DROPEFFECT_COPY) { // copy file to user's Art directory CString csNewFileName; int overwriteRetVal = IDOK; if ((fDoImport = pBrowser->CopyFileToUserArtDir(szFileName, csNewFileName, fPromptForOverwrite, &overwriteRetVal))) { strcpy(szFileName, csNewFileName); } // see what needs to be done next if (overwriteRetVal == IDYESALL) fPromptForOverwrite = FALSE; // no more prompting else if (overwriteRetVal == IDNO) fDoImport = FALSE; // go on to next one else if (overwriteRetVal == IDCANCEL) break; // we're out 'o here } if (fDoImport) pCollection->ImportItem(szFileName, NULL, NULL, strCategory); } } // end for loop ProgressDialog.SetPosition(iFile, ""); pBrowser->UpdateAllBrowsers(); } } return TRUE; // We always return TRUE; else, the main frame takes over. }
void CPmwView::DoFileSaveAsGraphic() { BOOL fRet = FALSE; CPmwDoc *pDoc = GetDocument (); CString Filter; Filter.LoadString (IDS_SAVE_AS_GRAPHIC_FILT); // this array must match the order in the above string! SaveGraphicType graphicTypes[] = { None, Pmo, Bmp8, Bmp24, Jpeg, Png, Gif, Pcx, Tiff, WMeta }; CString InitialDir = pDoc->GetPathManager()->ExpandPath("[[P]]"); CString defExt = "*.pmo"; // This must match the first selection in the filter string CFileSaveAsGraphicDlg fileDlg(pDoc->something_selected(), Filter, defExt, InitialDir, this); PBOX WorldAll, WorldSel; pDoc->get_panel_world (&WorldAll, pDoc->get_current_panel()); if (pDoc->GetSelectBound (&WorldSel) != TRUE) WorldSel = WorldAll; CDC *pDC = GetDC(); if (!pDC) { return; // just bail... } int LogPixX = pDC->GetDeviceCaps (LOGPIXELSX); int LogPixY = pDC->GetDeviceCaps (LOGPIXELSY); fileDlg.SetDimensions(&WorldAll, &WorldSel, LogPixX, LogPixY); ReleaseDC (pDC); if (fileDlg.DoModal () == IDOK) { CString Filename = fileDlg.GetPathName (); CPoint cpDims; cpDims.x = fileDlg.m_Width; cpDims.y = fileDlg.m_Height; enum SaveGraphicType gt; gt = graphicTypes[fileDlg.GetGraphicTypeIndex ()]; ASSERT ((gt > None) && (gt < Invalid)); BOOL fSelected = fileDlg.IsSaveSelected(); ERRORCODE error = ERRORCODE_Memory; if (gt == Pmo) { // save as "PrintMaster Objects" file error = SavePMObjectsToFile(Filename, pDoc, fSelected); } else { CDibToGraphicFile pDibToGraphicFile(Filename); pDibToGraphicFile.CreateGraphicFile (pDoc, gt, cpDims, fSelected, NULL, LogPixX); error = pDibToGraphicFile.GetErrorCode(); } if (error != ERRORCODE_None) AfxMessageBox (IDS_ERROR_SAVING); else { if (fileDlg.AddToGallery() == TRUE) { CPMWCollection* pCollection = GetGlobalCollectionManager()->GetUserCollection(CPMWCollection::typeArt); if (pCollection != NULL) { int nResult = pCollection->ImportItem(Filename, NULL, NULL, fileDlg.m_strCategory, FALSE); if (nResult != ERRORCODE_None) AfxMessageBox (IDS_ERROR_SAVING); } } } } }