Exemplo n.º 1
0
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();
}
Exemplo n.º 2
0
BOOL CDCache::file_is_cacheable(LPCSTR name, BOOL fCheckSize /*=FALSE*/)
{
	BOOL fCacheable = FALSE;

	// If we don't have a database, we don't have anything.
	if (m_database != NULL)
	{
		long lMaxSize = m_database->get_maximum_size()/3;

		switch (m_pPathManager->GetPathBindingType(name))
		{
			case PBT_HomeDataPath:
			case PBT_RemovableDrive:
			case PBT_CDDrive:
			{
				if (fCheckSize)
				{
					// The file is of the correct type.
					// Make sure it is not too big.
					// If the file gets an error, say we can cache it (this allows
					// us to still read missing files from the cache).
					CString csName;
					TRY
					{
						// Build a real name.
						csName = m_pPathManager->ExpandPath(name);

						CFileStatus Status;
						if (!CFile::GetStatus(csName, Status)
								|| Status.m_size < lMaxSize)
						{
							fCacheable = TRUE;
						}
					}
					END_TRY
				}
				else
				{
					// Assume size is OK.
					fCacheable = TRUE;
				}
				break;
			}
			case PBT_CollectionItem:
			{
				if (fCheckSize)
				{
					// Extract the collection name.
					CString csName;
					CString csCollection;
					VERIFY(m_pPathManager->BindPath(name, csName, &csCollection) == PBT_CollectionItem);
					CPMWCollection* pCollection = GetGlobalCollectionManager()->FindCollection(csCollection);

					// Lookup the file to get its size.
					if (pCollection != NULL)
					{
						CFileContent* pContent;
						if (pCollection->NewContentStream(&pContent) == ERRORCODE_None)
						{
							CContentDirEntry Dir;
							CContentDataEntry Data;

							Dir.SetKey(csName);
							TRY
							{
								if (pContent->Find(&Dir, &Data) == ERRORCODE_None)
								{
									long lSize = (long)((CCompressInfo*)Data.GetHeader())->GetUnCompressedSize();
									fCacheable = (lSize < lMaxSize);
								}
							}
							END_TRY
							pCollection->ReleaseContentStream(pContent);
						}
					}
				}
Exemplo n.º 3
0
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.
}
Exemplo n.º 4
0
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);
            }
         }
      }
   }
}