#include <frameops.h>
Inheritance diagram for OpSaveAnimatedGIF:
Static Public Member Functions | |
static OpState | GetState (String_256 *, OpDescriptor *) |
For finding the OpSaveAnimatedGIF's state. | |
Protected Member Functions | |
virtual BOOL | GetFileNameFromUser () |
Gives the operation chance to get the filename from the user. In this version we need to do this before grabbing the frames so that the user is given the oppurtunity to change the options using the button on the file save dialog box. | |
virtual BOOL | SaveOrShowTheAnimation (PreviewDialog *pPreviewDialog, BitmapExportParam *pExportParam) |
Tries to actually do the preview operation required. In this case we just save the animation out to the file that the user specified. | |
BOOL | EnsureFileType (PathName *pPath) |
Ensures that the pathname has the file extension/type that we require. | |
Private Attributes | |
PathName | m_SavePath |
Definition at line 645 of file frameops.h.
|
Ensures that the pathname has the file extension/type that we require.
Definition at line 4742 of file frameops.cpp. 04743 { 04744 ERROR2IF(pPath == NULL,FALSE,"EnsureFileExtension bad path specified"); 04745 04746 // we are essentially a GIF filter so we need that extension 04747 String_32 ExtStr(_R(IDN_FILTEREXT_GIF)); 04748 ExtStr.toLower(); 04749 String_256 Extension = pPath->GetType(); 04750 Extension.toLower(); 04751 if (Extension.IsEmpty() || Extension != ExtStr) 04752 { 04753 // There is no extension set for this file, so give it one 04754 pPath->SetType(ExtStr); 04755 } 04756 04757 return TRUE; 04758 }
|
|
Gives the operation chance to get the filename from the user. In this version we need to do this before grabbing the frames so that the user is given the oppurtunity to change the options using the button on the file save dialog box.
Reimplemented from OpGrabFrame. Reimplemented in OpBrowserPreview. Definition at line 4509 of file frameops.cpp. 04510 { 04511 // This is used to export an animated GIF. So we need only show the normal 04512 // GIF filter. This is despite the fact that this is not going to be the filter 04513 // that we use for the job. 04514 04515 // We are just going to show the animated GIF filter and all files 04516 String_256 FilterString(_R(IDS_SAVEGIFANIFILTERS)); 04517 04518 // Ensure that all the filters have a -1 in their position string so any matching 04519 // of selected filter will fail. Make only the GIF filter have 1 in there. 04520 Filter* pFilter = Filter::GetFirst(); 04521 while (pFilter != NULL) 04522 { 04523 if (IS_A(pFilter, TI_GIFFilter)) 04524 { 04525 // Its the GIF filter we want, mark it as the first position 04526 pFilter->pOILFilter->Position = 1; 04527 } 04528 else 04529 { 04530 // Make sure we don't try this one later 04531 pFilter->pOILFilter->Position = -1; 04532 } 04533 04534 // Try the next filter 04535 pFilter = Filter::GetNext(pFilter); 04536 } 04537 04538 // Create the dialog box 04539 GIFExportFileDialog FDialog(FilterString); 04540 04541 FDialog.SetTitle(_R(IDS_SAVEGIFANI_TITLE)); 04542 04543 // Use the document name as the default name of animation 04544 String_256 DefaultName(_R(IDS_BUTTBAR_ANIMATION)); // GIF Animation 04545 if (m_pDocument) 04546 DefaultName = m_pDocument->GetDocName(FALSE); 04547 // This is the pathname that we are going to save to 04548 m_SavePath = DefaultName; 04549 // Ensure that we have the correct extension on the filename we have allocated 04550 EnsureFileType(&m_SavePath); 04551 04552 // Pass this name onto the dialog box 04553 DefaultName = m_SavePath.GetFileName(); 04554 FDialog.SetDefaultFileName(DefaultName); 04555 04556 //FDialog.SetSelectedFilterIndex(1); 04557 04558 // Select the desired path 04559 String_256 ExportFilterPath = OpMenuExport::DefaultExportFilterPath; 04560 //Camelot.GetPrefDirect("Filters", "DefaultExportFilterPath",&ExportFilterPath); 04561 if (ExportFilterPath.Length() > 0) 04562 FDialog.SetInitialDirectory(ExportFilterPath); 04563 04564 // 'Do' the dialog and get that filename that we require 04565 BOOL DlgResult = FDialog.OpenAndGetFileName(); 04566 if (!DlgResult) 04567 { 04568 return FALSE; 04569 } 04570 04571 // Get the filename. 04572 FDialog.GetChosenFileName(&m_SavePath); 04573 04574 // This is now taken care of in FileDlgs.cpp on the ok as it then checks if the file 04575 // exists or not. If we do it here then this does not happen. 04576 // Unfortunately, changes made to the string in the dialog do not filter through 04577 // and so we ust fix it up here as well. 04578 // Always make sure that the filter's default extension is on if the user has not 04579 // specified an extension. 04580 EnsureFileType(&m_SavePath); 04581 04582 // Ensure that the path is valid 04583 if (!m_SavePath.IsValid()) 04584 { 04585 InformError(); 04586 //delete m_pBitmapFilter; 04587 //m_pBitmapFilter = NULL; 04588 return FALSE; 04589 } 04590 04591 // Extract directory name (minus terminating backslash) and remember for next time. 04592 ExportFilterPath = m_SavePath.GetLocation(FALSE); 04593 if (ExportFilterPath.Length() > 0) 04594 OpMenuExport::DefaultExportFilterPath = ExportFilterPath; 04595 //Camelot.SetPrefDirect("Filters", "DefaultExportFilterPath",DefaultExportFilterPath, TRUE); 04596 04597 //UINT32 TheSelectedFilterID = m_pBitmapFilter->FilterID; 04598 04599 // Everything got so return to the grabbing process 04600 return TRUE; 04601 }
|
|
For finding the OpSaveAnimatedGIF's state.
Reimplemented from OpGrabFrame. Definition at line 4489 of file frameops.cpp. 04490 { 04491 // else just use the base class version 04492 return OpGrabAllFrames::GetState(pUIDescription, pOpDesc); 04493 }
|
|
Tries to actually do the preview operation required. In this case we just save the animation out to the file that the user specified.
Reimplemented from OpGrabFrame. Reimplemented in OpBrowserPreview. Definition at line 4617 of file frameops.cpp. 04618 { 04619 // A bit of checking on parameters 04620 if (pExportParam != NULL) 04621 { 04622 ERROR3IF(!pExportParam->IS_KIND_OF(BitmapExportParam), "OpParam passed is not a BitmapExportParam"); 04623 04624 if (pExportParam->GetBitmapCount() == 0) 04625 { 04626 ERROR2RAW("OpSaveAnimatedGIF::DoWithParam no bitmaps to export"); 04627 return FALSE; 04628 } 04629 } 04630 else 04631 { 04632 ERROR2RAW("OpSaveAnimatedGIF::DoWithParam bad params!"); 04633 return FALSE; 04634 } 04635 04636 // Recover the bitmap pointer from the parameter passed in 04637 // This is to ensure that we have at least one bitmap to save 04638 KernelBitmap* pTheBitmap = pExportParam->GetBitmap(0); 04639 if (pTheBitmap == NULL) 04640 { 04641 ERROR2RAW("OpSaveAnimatedGIF::DoWithParam bitmap pointer is null"); 04642 return FALSE; 04643 } 04644 04645 // Ensure that we have a special grab frame filter available 04646 if (m_pBitmapFilter == NULL) 04647 m_pBitmapFilter = new GrabFrameFilter(); 04648 if (m_pBitmapFilter == NULL) 04649 { 04650 InformError(_R(IDT_CANT_FIND_FILTER)); 04651 return FALSE; 04652 } 04653 04654 // Should really check that the pathname is not null 04655 String_256 Filename; 04656 Filename = m_SavePath.GetPath(); 04657 ERROR2IF(Filename.IsEmpty(),FALSE,"OpSaveAnimatedGIF::SaveAnimation Save path not set up!"); 04658 04659 // First off, we have to try and open the file 04660 CCDiskFile DiskFile(1024, FALSE, TRUE); 04661 04662 BOOL ExportedOk = TRUE; 04663 try 04664 { 04665 // Export bitmaps 04666 ExportedOk = m_pBitmapFilter->DoExportBitmaps(this, &DiskFile, &m_SavePath, pExportParam); 04667 04668 if (!ExportedOk) 04669 { 04670 // Something went a bit wrong - tell the user what it was. 04671 // Supress the error if it was the 'user has cancelled one' 04672 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED)) 04673 { 04674 InformError(); 04675 m_pBitmapFilter->DeleteExportFile(&DiskFile); 04676 } 04677 else 04678 { 04679 // otherwise remove the error so it won't get reported 04680 Error::ClearError(); 04681 } 04682 } 04683 04684 // close the file 04685 if (DiskFile.isOpen()) 04686 DiskFile.close(); 04687 } 04688 04689 // See if there was a file io error 04690 catch(CFileException) 04691 { 04692 // Report the error if no one else did 04693 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED)) 04694 { 04695 InformError(); 04696 } 04697 else 04698 Error::ClearError(); // otherwise remove the error so it won't get reported 04699 04700 // Make sure that the file is closed and deleted 04701 try 04702 { 04703 // First try and delete it (tries to close it first) 04704 if (m_pBitmapFilter) 04705 m_pBitmapFilter->DeleteExportFile(&DiskFile); 04706 04707 // Double check to make sure it is closed. 04708 if (DiskFile.isOpen()) 04709 DiskFile.close(); 04710 } 04711 catch(CFileException) 04712 { 04713 // Failed to close the file - not much we can do about it really 04714 } 04715 04716 // Fail 04717 ExportedOk = FALSE; 04718 } 04719 04720 // Clean out the filter we created 04721 delete m_pBitmapFilter; 04722 m_pBitmapFilter = NULL; 04723 04724 // Blank the path 04725 //m_SavePath.SetPathName(TEXT("")); 04726 // This will give us a nice pathname is invalid error! Don't you just love the pathname class! 04727 04728 return ExportedOk; 04729 }
|
|
Definition at line 663 of file frameops.h. |