BOOL OpMenuLoad::LoadFile(CCLexFile* pFileToLoad, UINT32 nPrefFilter) { // Make sure we have a valid file to load. /* TRACEUSER( "JustinF", _T("In OpMenuLoad::LoadFile(%p, %u)\n"), (LPVOID) pFileToLoad, nPrefFilter); */ ERROR3IF(!pFileToLoad, "Null CCLexFile* in OpMenuLoad::LoadFile"); // Find out the position of the filter selected by the user in the open dialog INT32 SelectedPos = 0; #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX) SelectedPos = BaseFileDialog::SelectedFilter; #endif // Go get the first filter in the list Filter* pFilter = Filter::GetFirst(); // Do we know which filter was used? (we know nothing about things in the recent file // list). If we don't, then use the preferred one, by default the generic filter. if (nPrefFilter != FILTERID_USERCHOICE || SelectedPos == 0) { // We know nothing. We will have to go and have a look at all the possibles // We will find the Filter Family and ask it to try and load the file. UINT32 nID = (nPrefFilter != FILTERID_USERCHOICE) ? nPrefFilter : FILTERID_GENERIC; while (pFilter != NULL && pFilter->FilterID != nID) { // Try the next filter pFilter = Filter::GetNext(pFilter); } } else { // We know which type of filter the user had selected in the file dialog // Find the filter that the user chose. while (pFilter != NULL) { // This is the filter? if (pFilter->GetFlags().CanImport && pFilter->pOILFilter->Position == SelectedPos) break; // Try the next filter pFilter = Filter::GetNext(pFilter); } } // Check that the Filter existed if (pFilter == NULL) { // It did not... InformError(_R(IDT_CANT_FIND_FILTER)); return FALSE; } // Get pointer to current doc 'cos we'll need it several times... Document* pCurDoc = Document::GetCurrent(); // If this is not a filter family, check for compatibility before asking // filter to load the file. // This means the user has chosen an explicit filter to handle the import PathName Path = pFileToLoad->GetPathName(); String_256 FilePath = Path.GetPath(); // FilePath will be null if a pathname is not valid if (!pFilter->IS_KIND_OF(FilterFamily) && !FilePath.IsEmpty()) { UINT32 Size = 1024; size_t FileSize; ADDR FilterBuf = pFilter->LoadInitialSegment(Path, &Size, &FileSize); // If there has been a problem in the load initial segment then fail now. if (FilterBuf == NULL) { // Tell the user about the problem and get out now while the goings good InformError(); return FALSE; } // Inform any filters that we are about to do a HowCompatible call. // This would allow a set of filters which have common functionality hidden in a // filter that cannot import and cannot export handle this call and hence set // itself up. This would allow it to maybe cache a result which should only be // checked by the first filter in the group. pFilter->PreHowCompatible(); // Change this to be less than 8 as the filters like the Accusoft forms return // 8 and 9 to make sure that they are last in the chain. if (pFilter->HowCompatible(Path, FilterBuf, Size, UINT32(FileSize)) < 8) { // Not 100% happy with this file - ask for confirmation. ErrorInfo Question; Question.ErrorMsg = _R(IDW_OPENQUERY_NOTSURE); Question.Button[0] = _R(IDB_OPENQUERY_OPEN); Question.Button[1] = _R(IDB_OPENQUERY_DONTOPEN); if ((ResourceID)AskQuestion(&Question) != _R(IDB_OPENQUERY_OPEN)) { // User asked for this to be cancelled. TRACEUSER( "Tim", _T("Filter compatibility was less than 10\n")); // Close the file, report the abort and finish. CCFree(FilterBuf); //InformMessage(_R(IDT_IMP_USERABORT)); return FALSE; } } // Get rid of initial file header CCFree(FilterBuf); } // we have to try and open the file try { // Found the Filter, so ask it to import the file please if (!pFilter->DoImport(this, pFileToLoad, pCurDoc)) { // Something went a bit wrong - tell the user what it was. // Only tell them if not special user cancelled error message if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED)) { // Only supress the error if not the special user abort error // ***** For now use the native EPS filter if (pFilter->FilterID == FILTERID_NATIVE_EPS && Error::GetErrorNumber() != _R(IDT_IMPORT_USERABORT)) { Error::ClearError(); InformError(_R(IDS_ERRORINARTFILE)); } else { // Tell the user what the problem was InformError(); wxMessageDialog dlg( NULL, _T( "Xara LX failed to load the design.\n\n") _T( "This is an early demonstration version of the program which does ") _T( "not yet support all of the data types that can appear in XAR designs."), _T("Load failed"), wxOK ); dlg.ShowModal() ; } } else { // otherwise remove the error so it won't get reported Error::ClearError(); } // and fail return FALSE; } } // See if there was a file io errir catch( CFileException ) { // Report the error if no one else did, otherwise clear it. if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED)) InformError(); else Error::ClearError(); // and fail return FALSE; } // Success. return TRUE; }
BOOL SGThumbs::LoadThumbnailIntoSlot(UINT32 Slot, UINT32 ID, PathName *ActualFile) { /* String_256 P(ActualFile->GetPath()); ERROR3_PF(("Actual file: %s", (TCHAR *)P));*/ PORTNOTETRACE("dialog","SGThumbs::LoadThumbnailIntoSlot - do nothing"); #ifndef EXCLUDE_FROM_XARALX if(Directory == NULL || ActualFile == NULL) { ERROR3("SGThumbs::LoadThumbnailIntoSlot Directory == NULL || ActualFile == NULL"); return FALSE; } // Return any memory that would otherwise go down the toilet, and block the drains if(Thumbnails[Slot].Valid && Thumbnails[Slot].buffer) { delete Thumbnails[Slot].buffer; Thumbnails[Slot].buffer=NULL; } // Just in case we jump out in a state of unhappy rampantness Thumbnails[Slot].Valid = FALSE; BOOL CheckFilenameBmp = TRUE; BOOL CheckFilenamePng = TRUE; BOOL CheckFilenameReversed = TRUE; BOOL CheckFilenameTif = TRUE; BOOL CheckEncodedBmp = TRUE; BOOL CheckEncodedPng = TRUE; BOOL CheckEncodedTif = TRUE; BOOL UseActualFile = FALSE; BOOL IsRIFFTypeFile = FALSE; BOOL IsPCDTypeFile = FALSE; // Get lowercase filetype String_256 Type(ActualFile->GetType()); Type.toLower(); // Bodge to speed galleries up for art files - doesn't check or use external previews if( (Type.Sub((String_8)"art") != -1) || (Type.Sub((String_8)"xar") != -1) ) { UseActualFile = TRUE; CheckFilenameReversed = FALSE; } else if ( (Type.Sub((String_8)"web") != -1) || (Type.Sub((String_8)"cxw") != -1) || (Type.Sub((String_8)"cxn") != -1) ) { // Check for our new version 2 native and web files //WEBSTER-Martin-23/01/97 //force us to look for previews UseActualFile = TRUE; CheckFilenameReversed = FALSE; } else if ( (Type.Sub((String_8)"cdr") != -1) || (Type.Sub((String_8)"cmx") != -1) ) { IsRIFFTypeFile = TRUE; UseActualFile = TRUE; CheckFilenameReversed = FALSE; } else if( Type.Sub((String_8)"ttf") != -1 || Type.Sub((String_8)"pfb") != -1) { // Bodge to speed font gallery up a bit - only checks encoded bmp file thumbnails CheckFilenamePng = CheckFilenameBmp = CheckFilenameReversed = CheckFilenameTif = CheckEncodedTif = FALSE; CheckEncodedBmp = TRUE; CheckEncodedPng = TRUE; UseActualFile = FALSE; } else if( Type.Sub((String_8)"pcd") != -1 ) { IsPCDTypeFile = TRUE; UseActualFile = TRUE; } // Read the file into the bm yet ? BOOL Found = FALSE; CWxBitmap *pCWxBitmap = NULL; BOOL ReadOK = FALSE; // Don't error, just set exceptions... (changed 2/10/2000 by Jonathan to use // errors rather than exceptions to avoid a pile of messy first-change exceptions // when fills were not being found) CCDiskFile File(1024, FALSE, FALSE); // internal preview if(UseActualFile) { // Open file and check if it exists at the same time Found = OpenThumbnailFile( &File, *ActualFile ); if(Found) { // Create an OILy bitmap object pCWxBitmap = new CWxBitmap; if (pCWxBitmap == NULL) { ERROR3("Problem creating thumbnail bitmap"); return FALSE; } // files with internal preveiws // WEBSTER-Martin-08/01/97 if(IsRIFFTypeFile) { #ifndef WEBSTER //WEBSTER-Martin-21/01/97 if ( AccusoftFilters::GetVersionNumber() > 0) { // search to see if we can find a thumbnail in this file if ( CMXImportFilter::SkipToPreviewBitmap(&File) ) { TRACEUSER( "Martin", _T("Accusoft read RIFF preview\n")); ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE, NULL, NULL, TRUE ); } } else { TRACEUSER( "Martin", _T("Accusoft filter not loaded\n")); ReadOK = FALSE; } #endif //WEBSTER } else if(IsPCDTypeFile) { #ifndef WEBSTER //WEBSTER-Martin-21/01/97 if ( AccusoftFilters::GetVersionNumber() > 0) { TRACEUSER( "Martin", _T("Accusoft read PCD preview\n")); // Use the tiny preview... (we're a friend of AccusoftFilters by the way) AccusoftFilters::ImagePageToRead = 2; ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE, NULL, NULL, TRUE ); } else { TRACEUSER( "Martin", _T("Accusoft filter not loaded\n")); ReadOK = FALSE; } #endif //WEBSTER } else // new native file { // First, check that we have a CX2/XaraX format file, and // try to extract its preview bitmap at the same time. BOOL IsNewFormat = FALSE; UINT32 FilterId = FILTERID_NONE; if (BaseCamelotFilter::SkipToPreviewBitmap(&File, &IsNewFormat, &FilterId)) { // Get the preview! if (FilterId != FILTERID_NONE) { Filter* pFilter = Filter::FindFilterFromID(FilterId); if (pFilter != NULL) { ERROR3IF( !pFilter->IS_KIND_OF(BaseBitmapFilter), "Preview filter is not a BaseBitmapFilter\n" ); ReadOK = ((BaseBitmapFilter *)pFilter)->ReadFromFile( pCWxBitmap, NULL, &File, FALSE ); } } // Couldn't find a preview bitmap, so we'll make a note to // check for an external preview file instead. else { UseActualFile = FALSE; Found = FALSE; File.close(); delete pCWxBitmap; pCWxBitmap = NULL; } } // SkipToPreviewBitmap failed, so we'll assume that it's an old-format file. // In that case, we must try to load in its TIFF preview. else { if (AccusoftFilters::GetVersionNumber() > 0) ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE ); else ReadOK = FALSE; } } } else { TRACEUSER( "Martin", _T("Failed to find original file %s\n"), (const TCHAR *)ActualFile->GetFileName(TRUE)); Error::ClearError(); // didn't find original so look for external preview UseActualFile = FALSE; } } //we test this again cos we can change our mind about UseActualFile if(!UseActualFile) { #ifdef THUMB_CHECK_FILENAME_WITH_PNG if(CheckFilenamePng && !Found) { // Check for c:\clipart\sublib\xarainfo\picture.png files (from picture.tif or whatever) String_256 FAP; FAP = Directory->GetPath(TRUE); FAP += ActualFile->GetFileName(FALSE); FAP += TEXT(".png"); // ERROR3_PF(("Looking for: %s", (TCHAR *)FAP)); PathName ThumbPath(FAP); // <Filename>.png Found = OpenThumbnailFile( &File, ThumbPath ); if(Found) { // Create an OILy bitmap object pCWxBitmap = new CWxBitmap; if (pCWxBitmap == NULL) { ERROR3("Problem creating bitmap"); return FALSE; } // PNGs INT32 TransColour; // ignore value returned into this ReadOK = PNGUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, &TransColour ); } } #endif #ifdef THUMB_CHECK_FILENAME_WITH_BMP if(CheckFilenameBmp && !Found) { // Check for c:\clipart\sublib\xarainfo\picture.bmp files (from picture.tif or whatever) String_256 FAP; FAP = Directory->GetPath(TRUE); FAP += ActualFile->GetFileName(FALSE); FAP += TEXT(".bmp"); PathName ThumbPath(FAP); // <Filename>.bmp Found = OpenThumbnailFile( &File, ThumbPath ); if(Found) { // Create an OILy bitmap object pCWxBitmap = new CWxBitmap; if (pCWxBitmap == NULL) { ERROR3("Problem creating bitmap"); return FALSE; } // BMPs ReadOK = DIBUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE ); if ( !ReadOK ) { delete pCWxBitmap; pCWxBitmap = NULL; Found = FALSE; Error::ClearError(); // Er, well, it might be monochrome, so use accusoft then... // <Filename>.bmp File.close(); Found = OpenThumbnailFile( &File, ThumbPath ); } } } #endif #ifdef THUMB_CHECK_REVERSED_FILENAME if( CheckFilenameReversed && !Found ) { // Check for c:\clipart\sublib\xarainfo\picture.fit file from picture.tif, etc... String_256 FAP; FAP = Directory->GetPath(TRUE); FAP += ActualFile->GetFileName(FALSE); String_256 Ending(ActualFile->GetType()); _tcsrev((TCHAR *)Ending); // reverse the bmp to pmb FAP += TEXT("."); FAP += (TCHAR *)Ending; //ERROR3_PF(("Looking for: %s", (TCHAR *)FAP)); PathName ThumbPath(FAP); // <Filename>.fit <Filename>.pmb etc. Found = OpenThumbnailFile( &File, ThumbPath ); if(Found) { // Create an OILy bitmap object pCWxBitmap = new CWxBitmap; if (pCWxBitmap == NULL) { return FALSE; } // BMPs ReadOK = DIBUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE ); if ( ReadOK ) { // Set the name to the filename (without the .bmp) String_256 Name(ActualFile->GetFileName(FALSE)); pCWxBitmap->SetName(Name); } else { delete pCWxBitmap; pCWxBitmap = NULL; Found = FALSE; Error::ClearError(); // Er, well, it might be monochrome, so use accusoft then... // <Filename>.pmb File.close(); Found = OpenThumbnailFile( &File, ThumbPath ); } } } #endif #ifdef THUMB_CHECK_FILENAME_WITH_TIF if( CheckFilenameTif && !Found ) { // Check for normal tiff thumbnail file of the form <Filename>.TIF // Construct a full pathname for actual filename with a tif extension String_256 FullThumbnailPath(Directory->GetPath(TRUE)); FullThumbnailPath += ActualFile->GetFileName(FALSE); FullThumbnailPath += TEXT(".tif"); TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath); PathName FileAndPath(FullThumbnailPath); // <Filename>.tif Found = OpenThumbnailFile( &File, FileAndPath ); } #endif // Work out the encoded thumbnail name for use in multiple places below String_256 FullThumbnailPathWithoutExtension; if(!Found) { String_8 EncodedThumbnail; // Find encoded thumbnail path if(!GetThumbnailName(ID, &EncodedThumbnail)) return FALSE; // Construct a full pathname for the encoded thumbnail file FullThumbnailPathWithoutExtension = Directory->GetPath(TRUE); FullThumbnailPathWithoutExtension += EncodedThumbnail; } #ifdef THUMB_CHECKBMPS if(CheckEncodedBmp && !Found) { // Check for standard bitmap thumbnail file of the form X00000X.BMP // And load it using internal Xara code rather than Accusoft // Construct a full pathname for the encoded thumbnail file String_256 FullThumbnailPath(FullThumbnailPathWithoutExtension); FullThumbnailPath += TEXT(".bmp"); TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath); PathName FileAndPath(FullThumbnailPath); // <Filename>.bmp Found = OpenThumbnailFile( &File, FileAndPath ); if(Found) { // Create an OILy bitmap object pCWxBitmap = new CWxBitmap; if (pCWxBitmap == NULL) { ERROR3("Problem creating bitmap"); return FALSE; } // Set the name to the thumbID name (without the .bmp) String_256 Name(FileAndPath.GetFileName(FALSE)); pCWxBitmap->SetName(Name); // BMPs ReadOK = DIBUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE ); if(!ReadOK) { delete pCWxBitmap; pCWxBitmap = NULL; Found = FALSE; Error::ClearError(); // Er, well, it might be monochrome, so use accusoft then... // <Filename>.bmp File.close(); Found = OpenThumbnailFile( &File, FileAndPath ); } } } #endif #ifdef THUMB_CHECKPNGS if(CheckEncodedPng && !Found) { // Check for downloaded thumbnail file of the form X00000X.PNG // And load it using internal Xara code rather than Accusoft // Construct a full pathname for the encoded thumbnail file String_256 FullThumbnailPath(FullThumbnailPathWithoutExtension); FullThumbnailPath += TEXT(".png"); TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath); PathName FileAndPath(FullThumbnailPath); // <Filename>.png Found = OpenThumbnailFile( &File, FileAndPath ); if(Found) { // Create an OILy bitmap object pCWxBitmap = new CWxBitmap; if (pCWxBitmap == NULL) { ERROR3("Problem creating bitmap"); return FALSE; } // Set the name to the thumbID name (without the .png) String_256 Name(FileAndPath.GetFileName(FALSE)); pCWxBitmap->SetName(Name); // PNGs INT32 TransColour; // ignore value returned into this ReadOK = PNGUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, &TransColour ); } } #endif #ifdef THUMB_CHECKTIFS if(CheckEncodedTif && !Found) { // Check for encoded tiff thumbnail file of the form X00000X.TIF // Construct a full pathname for the encoded thumbnail file String_256 FullThumbnailPath(FullThumbnailPathWithoutExtension); FullThumbnailPath += TEXT(".tif"); TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath); PathName FileAndPath(FullThumbnailPath); // X00000X.tif Found = OpenThumbnailFile( &File, FileAndPath ); } #endif #ifndef WEBSTER //WEBSTER-Martin-21/01/97 if ( Found && !ReadOK ) { // this is Accusoft's last chance if ( AccusoftFilters::GetVersionNumber() > 0) { ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE, NULL, NULL, TRUE ); } else { TRACEUSER( "Martin", _T("Accusoft filter not loaded\n")); ReadOK = FALSE; } } #endif //WEBSTER } if(!ReadOK || pCWxBitmap == NULL) { // Problems somewhere above TRACEUSER( "Richard", _T("Can't find/load thumbnail")); // We don't want error boxes popping up every time we can't find a thumbnail Error::ClearError(); if(pCWxBitmap != NULL) { delete pCWxBitmap; pCWxBitmap = NULL; } return FALSE; } // Set the name to the file's name (without the .art .xar etc) String_256 Name(ActualFile->GetFileName(FALSE)); pCWxBitmap->SetName(Name); // create the kernel bitmap, attaching the OILy bitmap to it Thumbnails[Slot].buffer = new KernelBitmap(pCWxBitmap, TRUE); if (Thumbnails[Slot].buffer == NULL) { ERROR3("Problem creating kernel bitmap for thumbnail"); delete pCWxBitmap; pCWxBitmap = NULL; return FALSE; } // Set the rest of the entries to sensible values Thumbnails[Slot].Valid = TRUE; Thumbnails[Slot].ID = ID; Thumbnails[Slot].Usage = 0; Thumbnails[Slot].Size = ThumbnailsSize; Error::ClearError(); #endif // Well, looks like we got ourselves a thumbnail... return TRUE; }