impexpop.cpp

Go to the documentation of this file.
00001 // $Id: impexpop.cpp 1690 2006-08-10 13:53:03Z gerry $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // The operations for importing and exporting using the filter system.
00099 // These used to be are OILy as they used to invoke common dialogs etc
00100 // and hence used to be in OilFltrs.h/cpp
00101 // Moved to new kernel based impexpop.h/cpp 4/1/96 as there is now a class, BaseFileDialog
00102 // and derived classes which handle all of the OILy based common dialog functionality
00103 
00104 #include "camtypes.h"
00105 
00106 #include "camframe.h"
00107 #include "camelot.h"
00108 //#include "pathname.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 //#include "tim.h"
00114 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 //#include "trans2d.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00117 //#include "fillattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00118 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00119 //#include "andy.h"         // for ID?_OVERWRITE, _R(IDE_FORMATNOTSUPPORTED)
00120 //#include "nev.h"          // _R(IDN_USER_CANCELLED), _R(IDN_FILTERNOTPRESENT), _R(IDS_OPMENUIMPORT_ONE), _R(IDS_OPMENUEXPORT_ONE)
00121 #include "optsmsgs.h"       // options messages IMPORTWITHLAYERS
00122 #include "bubbleid.h"
00123 //#include "simon.h"
00124 
00125 #include "impexpop.h"
00126 #include "filedlgs.h"       // for ImportFileDialog & ExportFileDialog
00127 
00128 #include "helpuser.h"
00129 //#include "barsdlgs.h"     // for the import/export bar controls
00130 
00131 #include "bitfilt.h"        // BaseBitmapFilter
00132 #include "cameleps.h"
00133 //#include "oilfltrs.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00134 //#include "will3.h"
00135 #include "bmpsdlg.h"
00136 #include "exjpeg.h"
00137 
00138 #include "fileutil.h"
00139 #include "sgliboil.h"
00140 
00141 //#include "resimmap.h"     // For _R(IDS_HTMLIMPORT_FILEDOWNLOAD)
00142 #include "webaddr.h"        // For class WebAddress
00143 
00144 #include "opbevel.h"
00145 
00146 #include "bmapprev.h"
00147 
00148 #ifdef XAR_TREE_DIALOG
00149 #include "cxftree.h"
00150 #endif
00151 
00152 #if _DEBUG
00153 //#include "cmxtree.h"
00154 #endif
00155 
00156 //Webster-Ranbirr-12\11\96
00157 #ifdef WEBSTER
00158 #define FILTER_JPEG 2
00159 #define TWENTY_FOUR 24
00160 #define ONE         1
00161 #endif //webster
00162 
00163 // generic import filter
00164 //#include "gendwnd.h"
00165 //#include "webster.h"
00166 
00167 #include "ngsentry.h"
00168 #include "ngscan.h"
00169 //#include "justin3.h"
00170 
00171 #include "filtimag.h"   // The imagemap filter class
00172 //#include "desnotes.h" // Dream weaver integration
00173 //#include "sliceres.h" // For _R(IDS_NOTES_WARNING)
00174 
00175 #include "strlist.h"
00176 
00177 CC_IMPLEMENT_DYNCREATE(OpMenuImport, SelOperation)
00178 CC_IMPLEMENT_DYNCREATE(OpMenuExport, SelOperation)
00179 CC_IMPLEMENT_DYNAMIC(BitmapExportParam, OpParam)
00180 CC_IMPLEMENT_DYNCREATE(OpDroppedFile, SelOperation)
00181 
00182 
00183 /********************************************************************************************
00184 
00185     Preference: DefaultImportFilter
00186     Section:    Filters
00187     Range:      A filter ID.
00188     Purpose:    The unique ID of the filter to default to when importing files.
00189     SeeAlso:    DefaultImportFilterPath; DefaultExportFilter; DefaultExportFilterPath
00190 
00191 ********************************************************************************************/ 
00192 
00193 /********************************************************************************************
00194 
00195     Preference: DefaultImportFilterPath
00196     Section:    Filters
00197     Range:      A pathname.
00198     Purpose:    The path to default to when opening the Import File dialog.
00199     SeeAlso:    DefaultImportFilter; DefaultExportFilter; DefaultExportFilterPath
00200 
00201 ********************************************************************************************/ 
00202 
00203 /********************************************************************************************
00204 
00205     Preference: DefaultExportFilter
00206     Section:    Filters
00207     Range:      A filter ID.
00208     Purpose:    The unique ID of the filter to default to when exporting files.
00209     SeeAlso:    DefaultExportFilterPath; DefaultImportFilter; DefaultImportFilterPath
00210 
00211 ********************************************************************************************/ 
00212 
00213 /********************************************************************************************
00214 
00215     Preference: DefaultExportFilterPath
00216     Section:    Filters
00217     Range:      A pathname.
00218     Purpose:    The path to default to when opening the Export File dialog.
00219     SeeAlso:    DefaultExportFilter; DefaultImportFilter; DefaultImportFilterPath
00220 
00221 ********************************************************************************************/ 
00222 
00223 
00224 // The most recently selected import filter
00225 UINT32 OpMenuImport::SelectedFilterID = FILTERID_GENERIC;
00226 INT32  OpMenuImport::SelectedFilter     = -1;
00227 
00228 // String to hold the default path for both import and export filter dialogs.
00229 String_256 OpMenuImport::DefaultImportFilterPath;
00230 String_256 OpMenuExport::DefaultExportFilterPath;
00231 
00232 
00233 
00234 /********************************************************************************************
00235 
00236 >   BOOL OpMenuImport::Init()
00237 
00238     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00239     Created:    22/02/94
00240     Returns:    TRUE if worked, FALSE if failed (out of memory)
00241     Purpose:    Declares op descriptors for Acorn Draw file reading.
00242     Errors:     Returns FALSE on failure.
00243 
00244 ********************************************************************************************/
00245 
00246 BOOL OpMenuImport::Init()
00247 {
00248     // Derived off SelectionOperation which does not take 15 parameters.
00249     // (Misses out trhe vertical counterpart parameter)
00250     BOOL InitOK;
00251     InitOK = RegisterOpDescriptor(  0,                          // Tool ID
00252                                     _R(IDT_IMPORT),                 // String resource ID
00253                                     CC_RUNTIME_CLASS(OpMenuImport),     // Runtime class
00254                                     OPTOKEN_MENUIMPORT,         // Token string
00255                                     GetState,                   // GetState function
00256                                     0,                          // help ID
00257                                     _R(IDBBL_FILEIMPORT),           // bubble help
00258                                     _R(IDD_BARCONTROLSTORE),        // resource ID
00259                                     _R(IDC_FILEIMPORT),             // control ID
00260                                     SYSTEMBAR_FILE,             // Bar ID
00261                                     TRUE,                       // Recieve system messages
00262                                     FALSE,                      // Smart duplicate operation
00263                                     TRUE,                       // Clean operation
00264                                     _R(IDS_OPMENUIMPORT_ONE),       // String for one copy only error
00265                                     DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC // Auto state flags
00266                                 );
00267     if (!InitOK) return FALSE; 
00268 
00269 
00270     Camelot.DeclareSection(_T("Filters"), 5);
00271     Camelot.DeclarePref(_T("Filters"), _T("DefaultImportFilter"), &SelectedFilterID);
00272     Camelot.DeclarePref(_T("Filters"), _T("DefaultImportFilterPath"), &DefaultImportFilterPath);
00273 
00274 PORTNOTE("other", "Removed OpGenericDownload" )
00275 #if 0
00276     if (!OpGenericDownload::Init())
00277         return FALSE;
00278 #endif
00279     
00280     return TRUE;
00281 }
00282 
00283 /********************************************************************************************
00284 
00285 >   void OpMenuImport::Do(OpDescriptor*)
00286 
00287     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00288     Created:    22/02/94
00289     Purpose:    Imports a file into the current document.
00290     Errors:     Various. Get reported to the user.
00291 
00292 ********************************************************************************************/
00293 
00294 void OpMenuImport::Do(OpDescriptor*)
00295 {
00296     // zero is a bad state for this to be in so ensure its not in that state
00297     if (SelectedFilter == 0)
00298         SelectedFilter = -1;
00299 
00300     // Get the list of import filters
00301     FilterString = BaseFileDialog::BuildFilterString(TRUE, SelectedFilterID, &SelectedFilter);
00302     if (FilterString == 0)
00303     {
00304         // Unable to build filter string - report error and finish operation.
00305         InformError();
00306         FailAndExecute();
00307         // Finished the operation
00308         End();
00309         return;
00310     }
00311 
00312     // Create the dialog box
00313     ImportFileDialog FDialog(FilterString);
00314     
00315     FDialog.SetTitle(_R(IDT_IMPORT_TITLE));
00316 
00317     // Select the desired filter, if the default i.e. -1 then set 1 as this is the first valid index.
00318     if (SelectedFilter != -1)
00319         FDialog.SetSelectedFilterIndex(SelectedFilter);
00320     else
00321         FDialog.SetSelectedFilterIndex(1);
00322 
00323     // Select the desired path
00324     if (DefaultImportFilterPath.Length() > 0)
00325         FDialog.SetInitialDirectory(DefaultImportFilterPath);
00326 
00327     BOOL LayersImport = Filter::ImportWithLayers;
00328 
00329     // 'Do' the dialog and get that path/filename that we so desire
00330     BOOL DlgResult = FDialog.OpenAndGetFileName();
00331 
00332     // Check if the import with layers button has been changed and if so send a message
00333     // to warn other users e.g. options dialog box
00334     if (LayersImport != Filter::ImportWithLayers)
00335         BROADCAST_TO_ALL(OptionsChangingMsg(OptionsChangingMsg::IMPORTWITHLAYERS)); 
00336 
00337     if (!DlgResult)
00338     {
00339         // Get rid of the filter string buffer
00340         CCFree(FilterString);
00341         FilterString = 0;
00342 
00343         // User aborted - exit operation quietly.
00344         FailAndExecute();
00345         End();
00346         return;
00347     }
00348 
00349     // Remember the filter for next time.
00350     SelectedFilter = FDialog.GetSelectedFilterIndex();
00351     TRACEUSER( "luke", _T("Looking for ordinal %d"), SelectedFilter );
00352 
00353     // Get the filename, ensuring that the path is valid
00354     PathName Path;
00355     if (!FDialog.GetChosenFileName(&Path))
00356     {
00357         InformError();
00358         // Get rid of the filter string buffer
00359         CCFree(FilterString);
00360         FilterString = 0;
00361         FailAndExecute(); 
00362         End();
00363         return;
00364     }
00365 
00366     // Extract directory name (minus terminating backslash) and remember for next time.
00367     DefaultImportFilterPath = Path.GetLocation(FALSE);
00368             
00369     // Find the filter that the user chose
00370     Filter *pFilter = Filter::GetFirst();
00371     while (pFilter != 0)
00372     {
00373         if( NULL != pFilter->pOILFilter )
00374         {
00375             if( ( pFilter->GetFlags().CanImport && !IS_A( pFilter, CamelotEPSFilter ) ) &&
00376                 pFilter->pOILFilter->Position == SelectedFilter )
00377             {
00378                 TRACEUSER( "luke", _T("%s is THE filter (%d)"),
00379                     (TCHAR*)pFilter->FilterName, pFilter->pOILFilter->Position );
00380 
00381                 // This is the filter!
00382                 break;
00383             }
00384 
00385             TRACEUSER( "luke", _T("%s is not selected (ord=%d)"),
00386                 (TCHAR*)pFilter->FilterName, pFilter->pOILFilter->Position );
00387         }
00388         else
00389             TRACEUSER( "luke", _T("Can't handle NULL pFilter->pOILFilter for %s"),
00390                 (TCHAR*)pFilter->FilterName );
00391         
00392         // Try the next filter
00393         pFilter = Filter::GetNext(pFilter);
00394     }
00395     
00396     // Get rid of the filter string buffer
00397     CCFree(FilterString);
00398     FilterString = 0;
00399 
00400     if (pFilter == 0)
00401     {
00402         InformError(_R(IDT_CANT_FIND_FILTER));
00403         FailAndExecute(); 
00404     }
00405     else
00406     {
00407         SelectedFilterID = pFilter->FilterID;
00408 
00409         String_256 URL = Path.GetPath();
00410         
00411         TRACEUSER( "luke", _T("Path = %s\n"), (TCHAR*)URL );
00412 
00413         //Graham 14/7/97: Get the current view
00414         DocView* pDocView=DocView::GetCurrent();
00415 
00416         //And find its centre import position
00417         ImportPosition posToUse=pDocView->GetCentreImportPosition();
00418             
00419         // call the Import function
00420         DoImport(Path, pFilter, &URL, &posToUse);
00421     }
00422 }
00423 
00424 
00425 
00426 /********************************************************************************************
00427 
00428 >   void OpMenuImport::DoImport(PathName Path, Filter* pFilter, String_256* URL, ImportPosition* pImportPosition)
00429 
00430     Author:     Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com> gascoin
00431     Created:    07/05/97
00432     Inputs:     Path - local file
00433                 pFilter - pointer to a filter
00434                 URL - original URL of the imported file
00435                 pImportPosition - position to import to (added by Graham 14/7/97)
00436     Purpose:    import function
00437 
00438 ********************************************************************************************/
00439 
00440 void OpMenuImport::DoImport(PathName Path, Filter* pFilter, String_256* URL, ImportPosition* pImportPosition)
00441 {
00442     // If this is not a filter family, check for compatibility before asking
00443     // filter to load the file.
00444     // This means the user has chosen an explicit filter to handle the import
00445     if (!pFilter->IS_KIND_OF(FilterFamily))
00446     {
00447         UINT32 Size = 1024;
00448         size_t FileSize;
00449         ADDR FilterBuf = pFilter->LoadInitialSegment(Path, &Size, &FileSize);
00450 
00451         // If there has been a problem in the load initial segment then fail now.
00452         if (FilterBuf == 0)
00453         {
00454             // Tell the user about the problem and get out now while the goings good 
00455             InformError();
00456             FailAndExecute(); 
00457             End();
00458             return;
00459         }
00460 
00461         // Inform any filters that we are about to do a HowCompatible call.
00462         // This would allow a set of filters which have common functionality hidden in a
00463         // filter that cannot import and cannot export handle this call and hence set
00464         // itself up. This would allow it to maybe cache a result which should only be
00465         // checked by the first filter in the group. 
00466         pFilter->PreHowCompatible();
00467             
00468         // Change this to be less than 8 as the filters like the Accusoft forms return
00469         // 8 and 9 to make sure that they are last in the chain.
00470         if (pFilter->HowCompatible(Path, FilterBuf, Size, FileSize) < 8)
00471         {
00472             // Not 100% happy with this file - ask for confirmation.
00473             ErrorInfo Question;
00474             Question.ErrorMsg = _R(IDT_IMPQUERY_NOTSURE);
00475             Question.Button[0] = _R(IDB_IMPQUERY_IMPORT);
00476             Question.Button[1] = _R(IDB_IMPQUERY_DONTIMPORT);
00477 
00478             if (UINT32(AskQuestion(&Question)) != _R(IDB_IMPQUERY_IMPORT))
00479             {
00480                 // User asked for this to be cancelled.
00481                 TRACEUSER( "Tim", _T("Filter compatibility was less than 10\n"));
00482 
00483                 // Close the file, report the abort and finish.
00484                 CCFree(FilterBuf);
00485                 FailAndExecute();
00486                 InformMessage(_R(IDT_IMP_USERABORT));
00487                 End();
00488                 return;
00489             }
00490         }
00491 
00492         // Get rid of initial file header
00493         CCFree(FilterBuf);
00494     }
00495 
00496     // Start the selection operation
00497     if (DoStartSelOp(FALSE)) // We don't want to save the end selection status because 
00498                              // it will be restored automatically when the operation is 
00499                              // redone
00500     {
00501         // First off, we have to try and open the file
00502         CCDiskFile DiskFile(1024, FALSE, TRUE);
00503 
00504         // Get pointer to current doc 'cos we'll need it several times...
00505         Document* pCurDoc = Document::GetCurrent();
00506 
00507         try
00508         {
00509             if (!DiskFile.open(Path, ios::in | ios::binary))
00510             {
00511                 // Failed to open the file...
00512                 TRACEUSER( "Rik", _T("Failed to open file in MenuImport Do"));
00513                 InformError(_R(IDT_IMPORT_NOTFOUND));
00514                 FailAndExecute();
00515                 End();
00516                 return;
00517             }
00518 
00519             // Import the file and see if Something went a bit wrong - tell the user what it was.
00520             if (!pFilter->DoImport(this, &DiskFile, pCurDoc, FALSE, pImportPosition, 0, 0, URL))
00521             {
00522                 // Only tell them if not special user cancelled error message
00523                 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00524                     InformError();
00525                 else
00526                     Error::ClearError();    // otherwise remove the error so it won't get reported
00527                 FailAndExecute();
00528                 End();
00529 
00530                 // Close the file again
00531                 if (DiskFile.isOpen())
00532                     DiskFile.close();
00533 
00534                 return;
00535             }
00536 
00537             // close the file
00538             if (DiskFile.isOpen())
00539                 DiskFile.close();
00540     
00541         }
00542 
00543         // See if there was a file io error
00544         catch(CFileException e)
00545         {
00546             // Report the error if no one else did
00547             if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00548                 InformError();
00549             else
00550                 Error::ClearError();    // otherwise remove the error so it won't get reported
00551 
00552             // Make sure that the file is closed
00553             try
00554             {
00555                 if (DiskFile.isOpen())
00556                     DiskFile.close();
00557             }
00558             catch(CFileException e)
00559             {
00560                 // Failed to close the file - not much we can do about it really
00561             }
00562 
00563             // and fail
00564             FailAndExecute();
00565         }
00566     }
00567 
00568     // grab the focus
00569     GetMainFrame()->SetFocus();
00570     // Finished the operation
00571     End();
00572 }
00573 
00574 
00575 /********************************************************************************************
00576 
00577 >   void OpMenuImport::EndImport()
00578 
00579     Author:     Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
00580     Created:    09/05/97
00581     Purpose:    End the operation. It's called by GenericDownloadOp::OnDownloadFail()
00582 
00583 ********************************************************************************************/
00584 
00585 void OpMenuImport::EndImport()
00586 {
00587     FailAndExecute();
00588     End();
00589 }
00590 
00591 
00592 /********************************************************************************************
00593 
00594 >   BOOL OpMenuImport::OnDocChangingMsg(Document* pChangingDoc, DocChangingMsg::DocState State)
00595 
00596     Author:     Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
00597     Created:    15/05/97
00598     Inputs:     pChangingDoc -
00599                 State -
00600     Returns:    
00601     Purpose:    End (abort) the operation when for instance the current document has been destroyed
00602                 while downloading.
00603     Errors:     
00604 
00605 ********************************************************************************************/
00606 
00607 BOOL OpMenuImport::OnDocChangingMsg(Document* pChangingDoc, DocChangingMsg::DocState State)
00608 {
00609     if (State == DocChangingMsg::ABOUTTODIE && pChangingDoc == pOurDoc)
00610     {
00611         EndImport();
00612     }
00613 
00614     return TRUE;
00615 }
00616 
00617 
00618 /********************************************************************************************
00619 
00620 >   OpMenuImport::OpMenuImport()
00621 
00622     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00623     Created:    22/02/94
00624     Purpose:    Constructor for OpMenuImport operation.
00625 
00626 ********************************************************************************************/
00627 
00628 OpMenuImport::OpMenuImport()
00629 {
00630     OpFlags.HasOwnTimeIndicator = TRUE; // The OpMenuImport op has its own time indicator
00631 }
00632 
00633 
00634 
00635 /********************************************************************************************
00636 
00637 >   OpState OpMenuImport::GetState(String_256*, OpDescriptor*)
00638 
00639     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00640     Created:    22/02/94
00641     Purpose:    This item is always available, so long as a document is visible.
00642 
00643 ********************************************************************************************/
00644 
00645 OpState OpMenuImport::GetState(String_256*, OpDescriptor*)
00646 {
00647     OpState OpSt;
00648 
00649     return OpSt;
00650 }
00651 
00652 INT32 OpMenuExport::SelectedFilter = -1;
00653 INT32 OpMenuExport::SelectedBitmapFilter = -1;
00654 
00655 // There was an #ifdef WEBSTER directive here that specified the initial file type for the
00656 // export menu. I've removed this, but should a new Webster ever be needed, the initial type
00657 // was:
00658 //
00659 // UINT32 OpMenuExport::SelectedFilterID = FILTERID_WEB;
00660 // UINT32 OpMenuExport::DefaultBitmapFilterID = FILTERID_BMP;
00661 //
00662 // The WEBSTER directive was being triggered by the full build of Camelot.
00663 UINT32 OpMenuExport::SelectedFilterID = FILTERID_EXPORT_JPEG;
00664 UINT32 OpMenuExport::DefaultBitmapFilterID = FILTERID_EXPORT_JPEG;
00665 
00666 List * OpMenuExport::m_pSelNodeList = 0;
00667 
00668 /********************************************************************************************
00669 
00670 >   BOOL OpMenuExport::Init()
00671 
00672     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00673     Created:    22/03/94
00674     Returns:    TRUE if worked, FALSE if failed (out of memory)
00675     Purpose:    Declares op descriptor for export operation.
00676     Errors:     Returns FALSE on failure.
00677 
00678 ********************************************************************************************/
00679 
00680 BOOL OpMenuExport::Init()
00681 {
00682     // derived off operation so takes 16 parameters including the vertical counterpart
00683     BOOL InitOK;
00684     InitOK = RegisterOpDescriptor(  0,                          // Tool ID
00685                                     _R(IDT_EXPORT),                 // String resource ID
00686                                     CC_RUNTIME_CLASS(OpMenuExport),     // Runtime class
00687                                     OPTOKEN_MENUEXPORT,         // Token string
00688                                     GetState,                   // GetState function
00689                                     0,                          // help ID
00690                                     _R(IDBBL_FILEEXPORT),           // bubble help
00691                                     _R(IDD_BARCONTROLSTORE),        // resource ID
00692                                     _R(IDC_FILEEXPORT),             // control ID
00693                                     SYSTEMBAR_FILE,             // Bar ID
00694                                     TRUE,                       // Recieve system messages
00695                                     FALSE,                      // Smart duplicate operation
00696                                     FALSE,                      // Clean operation
00697 //                                  0,                          // No vertical counterpart
00698                                     _R(IDS_OPMENUEXPORT_ONE),       // String for one copy only error
00699                                     DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC // Auto state flags
00700                                 );
00701     if (!InitOK) return FALSE; 
00702 
00703     Camelot.DeclareSection(_T("Filters"), 5);
00704     Camelot.DeclarePref(_T("Filters"), _T("DefaultExportFilter"), &SelectedFilterID);
00705     Camelot.DeclarePref(_T("Filters"), _T("DefaultExportFilterPath"), &DefaultExportFilterPath);
00706     Camelot.DeclarePref(_T("Filters"), _T("DefaultBitmapFilter"), &DefaultBitmapFilterID);
00707 
00708     return TRUE;
00709 }
00710 
00711 
00712 
00713 /********************************************************************************************
00714 
00715 >   void OpMenuExport::Do(OpDescriptor*)
00716 
00717     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00718     Created:    22/03/94
00719     Purpose:    Exports a file from the current document.
00720                 Most of the work is now done by the DoWithParam.
00721     Errors:     Various. Get reported to the user.
00722 
00723 ********************************************************************************************/
00724 
00725 void OpMenuExport::Do(OpDescriptor* OpDesc)
00726 {
00727     DoWithParam(OpDesc, 0);
00728 }
00729 
00730 
00731 
00732 /********************************************************************************************
00733 
00734 >   static void OpMenuExport::SaveSelection()
00735 
00736     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com> / JustinF
00737     Created:    9/1/2000
00738     Purpose:    Saves the selection so it can be restored
00739     
00740 ********************************************************************************************/
00741 void OpMenuExport::SaveSelection()
00742 {
00743     if (m_pSelNodeList)
00744     {
00745         m_pSelNodeList->DeleteAll();
00746         delete m_pSelNodeList;
00747         m_pSelNodeList = 0;
00748     }
00749 
00750     SelRange* pRng = GetApplication()->FindSelection();
00751     if (pRng == 0)
00752     {
00753         ERROR3("No SelRange in OpMenuExport::SaveSelection");
00754         return;
00755     }
00756     
00757     pRng->SetGag(TRUE);
00758     m_pSelNodeList = pRng->MakeListOfNodes(FALSE);
00759 }
00760 
00761 
00762 
00763 /********************************************************************************************
00764 >   static void OpMenuExport::NormaliseSelection()
00765 
00766     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00767     Created:    9/1/2000
00768     Purpose:    Fixes-up the selection for compound objects.
00769 ********************************************************************************************/
00770 void OpMenuExport::NormaliseSelection()
00771 {
00772     // run through the range selecting all PromoteToParent nodes
00773     SelRange* pRng = GetApplication()->FindSelection();
00774     if (pRng == 0) 
00775     {
00776         ERROR3("No range in OpMenuExport::NormaliseSelection");
00777         return;
00778     }
00779 
00780     for (Node* pNode = pRng->FindFirst(FALSE);
00781          pNode != 0;
00782          pNode = pRng->FindNext(pNode, FALSE))
00783             if (pNode->IsAnObject())
00784                 for (Node* pParent = pNode->FindParent();
00785                      pParent != 0 && pParent->IsAnObject();
00786                      pParent = pParent->FindParent())
00787                         if (pParent->ShouldITransformWithChildren())
00788                         {
00789                             pParent->SetSelected(FALSE);
00790                             pParent->SetSelected(TRUE);
00791                         }                   
00792 
00793     pRng->Update();
00794 }
00795 
00796 
00797 
00798 /********************************************************************************************
00799 
00800 >   static void OpMenuExport::RestoreSelection()
00801 
00802     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com> / JustinF
00803     Created:    9/1/2000
00804     Inputs:     
00805     Purpose:    Restores the selection given in m_pSelNodeList
00806     
00807 ********************************************************************************************/
00808 void OpMenuExport::RestoreSelection()
00809 {
00810     SelRange* pRng = GetApplication()->FindSelection();
00811     if (pRng == 0) 
00812     {
00813         ERROR3("No range in OpMenuExport::RestoreSelection");
00814         return;
00815     }
00816 
00817     if (pRng->IsSelRangeGagged()) pRng->SetGag(FALSE);
00818     NodeRenderableInk::DeselectAll(FALSE, FALSE);
00819 
00820     if (!m_pSelNodeList)
00821     {
00822         ERROR3("Sel node list not set up");
00823         return;
00824     }
00825 
00826     for (NodeListItem* pItem = (NodeListItem*) m_pSelNodeList->GetHead();
00827          pItem != 0;
00828          pItem = (NodeListItem*) m_pSelNodeList->GetNext(pItem))
00829             if (pItem->pNode != 0) pItem->pNode->SetSelected(TRUE);
00830 
00831     m_pSelNodeList->DeleteAll();
00832     delete m_pSelNodeList;
00833     m_pSelNodeList = 0;
00834 
00835     RangeControl rg = pRng->GetRangeControlFlags();
00836     rg.PromoteToParent = FALSE;
00837     pRng->Range::SetRangeControl(rg);
00838     pRng->Update();
00839 //  pRng->Update(TRUE);
00840 }
00841 
00842 void RemoveUneededReportedErrors()
00843 {
00844     // clear silly error before End()ing the op
00845     // Only tell them if not special user cancelled error message
00846     if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED) && Error::GetErrorNumber() != 0)
00847         InformError();
00848     else
00849         Error::ClearError();    // otherwise remove the error so it won't get reported
00850 }
00851 
00852 /********************************************************************************************
00853 >   void OpMenuExport::DoWithParam(OpDescriptor*, OpParam* pParam)
00854 
00855     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00856     Created:    25/04/95
00857     Inputs:     pParam  if 0 then assumed to be a normal export using any filter
00858                         if not 0 then assumed to be a KernelBitmap* and wanting to export
00859                         as a bitmap.
00860     Purpose:    Exports a file from the current document.
00861     Errors:     Various. Get reported to the user.
00862 ********************************************************************************************/
00863 
00864 void OpMenuExport::DoWithParam(OpDescriptor*, OpParam* pParam)
00865 {
00866     // DMc - need to do this so that compound nodes are treated appropriately
00867     SaveSelection();
00868     NormaliseSelection();
00869 
00870 //Webster-Ranbirr-12\11\96
00871 #ifdef WEBSTER
00872     // Temp. variable to store the filter type.
00873     INT32 BitmapFilter = 0;
00874 #endif //webster
00875 
00876     // zero is a bad state for this to be in so ensure its not in that state
00877     if (SelectedFilter == 0) SelectedFilter = -1;
00878     if (SelectedBitmapFilter == 0) SelectedBitmapFilter = -1;
00879     
00880     ERROR3IF(pParam != 0 && !pParam->IS_KIND_OF(BitmapExportParam),
00881         "OpMenuExport::DoWithParam: OpParam passed is not a BitmapExportParam");
00882 
00883     // Check whether a parameter has been specified 
00884     UINT32 Bpp = 0;
00885     BitmapExportParam* pExportParam = (BitmapExportParam*) pParam;
00886     if (pExportParam != 0)
00887     {
00888         // At present, this is only used to export the specifed bitmap so use a list
00889         // of bitmap filters. We need to limit the bitmap filters to ones that can support
00890         // the colour depth of the specified bitmap.
00891         // Recover the bitmap pointer from the parameter passed in
00892         KernelBitmap* pTheBitmap;
00893         if (pExportParam->GetBitmapCount() == 0 ||
00894             (pTheBitmap = pExportParam->GetBitmap(0)) == 0)
00895         {
00896             ERROR2RAW("OpMenuExport::DoWithParam: no bitmaps, or null pointer");
00897             FailAndExecute();
00898             RestoreSelection();
00899             End();
00900             return;
00901         }
00902 
00903         // If it is a 32 bpp bitmap then we do a conversion to 24. So really we should ask
00904         // the filters whether they like 24bpp files. Otherwise, just the BMP filter will say
00905         // yes.
00906         Bpp = pTheBitmap->GetBPP();
00907 //      if (Bpp == 32) Bpp = 24;
00908 
00909     //Webster-Ranbirr-12\11\96
00910 /*  #ifndef WEBSTER
00911         FilterString = BaseFileDialog::BuildFilterString(
00912                                 FALSE,
00913                                 DefaultBitmapFilterID,
00914                                 &SelectedBitmapFilter,
00915                                 CC_RUNTIME_CLASS(BitmapFilter),
00916                                 Bpp,
00917                                 pExportParam->GetBitmapCount());
00918     #else
00919 */      // Save a reference to the last selected Filter, in case Cancel is entered.
00920         //BitmapFilter = SelectedBitmapFilter;
00921             
00922         // Is this bitmap a compressed JPEG?
00923         BitmapSource* pSource = 0;
00924         BaseBitmapFilter* pDummyFilter;
00925 
00926         BOOL OriginalSourcePresent = pTheBitmap->GetOriginalSource(&pSource,&pDummyFilter); 
00927         if (OriginalSourcePresent)
00928         {
00929             DefaultBitmapFilterID = FILTERID_EXPORT_JPEG;
00930             SelectedBitmapFilter = 0; //FILTER_JPEG;
00931         }
00932         else
00933         {
00934 
00935         }
00936 
00937         FilterString = BaseFileDialog::BuildFilterString(
00938                                 FALSE,
00939                                 DefaultBitmapFilterID,
00940                                 &SelectedBitmapFilter,
00941                                 CC_RUNTIME_CLASS(BitmapFilter),
00942                                 Bpp,
00943                                 pExportParam->GetBitmapCount());
00944 //  #endif //webster
00945     }
00946     else
00947     {
00948         // Get the list of export filters using all filters available
00949         FilterString = BaseFileDialog::BuildFilterString(
00950                                 FALSE,
00951                                 SelectedFilterID,
00952                                 &SelectedFilter);
00953     }
00954 
00955     if (FilterString == 0)
00956     {
00957         // Unable to build filter string - report error and finish operation.
00958         InformError();
00959         FailAndExecute();
00960 
00961         // Finished the operation
00962         RestoreSelection();
00963         End();
00964         return;
00965     }
00966 
00967     // Create the dialog box
00968     ExportFileDialog FDialog(FilterString);
00969     INT32 TheSelectedFilter = -1;
00970     String_256 DefaultName;
00971     
00972     FDialog.SetTitle(_R(IDT_EXPORT_TITLE));
00973 
00974     // Note this ptr for use in JPEG export.
00975 //  KernelBitmap* pBitmap = pExportParam->GetBitmap(0);
00976 //  JPEGExportOptions::SetKernelBitmap(pBitmap);
00977     
00978     if (pExportParam == 0)
00979         TheSelectedFilter = SelectedFilter;         // Using all available filters
00980     else
00981     {
00982         // Exporting as a bitmap so fill in the name of the bitmap
00983         KernelBitmap* pTheBitmap = pExportParam->GetBitmap(0);
00984 
00985         if (pTheBitmap->ActualBitmap)
00986             DefaultName = pTheBitmap->ActualBitmap->GetName();
00987         else
00988             SetBitmapName(pTheBitmap, &DefaultName, pExportParam);
00989         
00990         // Pass this name onto the dialog box
00991         FDialog.SetDefaultFileName(DefaultName);
00992         FDialog.ExportABitmap(TRUE, pTheBitmap);
00993 
00994         // Now work out the selected index, if there is one
00995         TheSelectedFilter = SelectedBitmapFilter;
00996     }
00997 
00998     // Select the desired filter, if the default i.e. -1 then set 1 as this is the first valid index.
00999     FDialog.SetSelectedFilterIndex(TheSelectedFilter != -1 ? TheSelectedFilter : 1);
01000 
01001     // Select the desired path
01002     if (DefaultExportFilterPath.Length() > 0)
01003         FDialog.SetInitialDirectory(DefaultExportFilterPath);
01004 
01005     // We maybe asking uses to specify a file name more than
01006     // once if theie first guess already exists
01007     PathName Path;
01008     Filter* pFilter;
01009     do
01010     {
01011         // 'Do' the dialog and get that filename that we require
01012         BOOL DlgResult = FDialog.OpenAndGetFileName();
01013         if (!DlgResult)
01014         {
01015         //Webster-Ranbirr-12\11\96  
01016         #ifdef WEBSTER
01017             // If cancel is entered then ensure that our filter 
01018             // is set to the previous selected filter.
01019             SelectedBitmapFilter = BitmapFilter; 
01020         #endif //webster
01021 
01022             CCFree(FilterString);
01023             FilterString = 0;
01024             RestoreSelection();
01025             End();
01026             return;
01027         }
01028 
01029         // Remember the filter for next time.
01030         TheSelectedFilter = FDialog.GetSelectedFilterIndex();
01031         if (pExportParam == 0)
01032             SelectedFilter = TheSelectedFilter;         // Using all available filters
01033         else
01034             SelectedBitmapFilter = TheSelectedFilter;   // Exporting as a bitmap only
01035 
01036         // Get the filename.
01037         FDialog.GetChosenFileName(&Path);
01038 
01039         // Find the filter that the user chose
01040         for (pFilter = Filter::GetFirst();
01041              pFilter != 0;
01042              pFilter = Filter::GetNext(pFilter))
01043         {
01044             if( NULL == pFilter->pOILFilter )
01045                 continue;
01046 
01047             if (pFilter->GetFlags().CanExport && 
01048                 pFilter->pOILFilter->Position == TheSelectedFilter)
01049                     // This is the filter!
01050                     break;
01051         }
01052 
01053         if (pFilter == 0)
01054         {
01055             InformError(_R(IDT_CANT_FIND_FILTER));
01056 
01057             // Get rid of the filter string buffer
01058             CCFree(FilterString);
01059             FilterString = 0;
01060             RestoreSelection();
01061             FailAndExecute(); 
01062             End();
01063             return;
01064         }
01065 
01066         // This is now taken care of in FileDlgs.cpp on the ok as it then checks if the file
01067         // exists or not. If we do it here then this does not happen.
01068         // Unfortunately, chnages made to the string in the dialog do not filter through
01069         // and so we must fix it up here as well.
01070         // Always make sure that the filter's default extension is on if the user has not
01071         // specified an extension.
01072         // Get the OILFilter class to check the extension for the selected or default filter
01073         // matches
01074         if (!pFilter->pOILFilter->DoesExtensionOfPathNameMatch(&Path))
01075         {   
01076             // Extension is either blank or does not match the one supplied by the filter
01077             // Ask the OILFilter class to fix it for us
01078             pFilter->pOILFilter->FixExtensionOfPathName(&Path);
01079         }
01080 
01081         // Ensure that the path is valid
01082         if (!Path.IsValid())
01083         {
01084             InformError();
01085 
01086             // Get rid of the filter string buffer
01087             CCFree(FilterString);
01088             FilterString = 0;
01089             FailAndExecute(); 
01090             RestoreSelection();
01091             End();
01092             return;
01093         }
01094 
01095         // We must manually check the file doesn't exit here
01096         if( SGLibOil::FileExists( &Path ) )
01097         {
01098             ErrorInfo Info;
01099             Info.ErrorMsg = _R(IDS_SAVEAS_OVERWRITE);
01100             Info.Button[0] = _R(IDS_OVERWRITE);
01101             Info.Button[1] = _R(IDB_SAVEAS);
01102             Info.Button[2] = _R(IDS_CANCEL);
01103 
01104             UINT32 Answer = AskQuestion(&Info);
01105 
01106             if (Answer==_R(IDS_OVERWRITE))
01107             {
01108                 // Just use the name the user selected to overwite the existing file
01109                 break;
01110             }
01111             else if (Answer== _R(IDB_SAVEAS))
01112             {
01113                 // User wants to save as some other name
01114                 continue;
01115             }
01116             else if (Answer==_R(IDS_CANCEL))
01117             {
01118                 // User has chosen to abort the operation
01119                 End();
01120                 return;
01121             }
01122             else
01123                 ERROR3("Unknown Answer from AskQuestion");
01124         }
01125     }
01126     while( SGLibOil::FileExists( &Path ) ); 
01127 
01128 PORTNOTE("other", "Removed BmapPrevDlg usage" )
01129 #if !defined(EXCLUDE_FROM_XARALX)
01130     // Need to set the path for the export dialog (used for image map stuff etc)
01131     BmapPrevDlg::m_pthExport = Path;
01132 #endif
01133     
01134     // Extract directory name (minus terminating backslash) and remember for next time.
01135     DefaultExportFilterPath = Path.GetLocation(FALSE);
01136             
01137     UINT32 TheSelectedFilterID = pFilter->FilterID;
01138     if (pExportParam == 0)
01139         SelectedFilterID = TheSelectedFilterID;         // Using all available filters
01140     else    
01141         DefaultBitmapFilterID = TheSelectedFilterID;    // Exporting as a bitmap only
01142 
01143     // If we are exporting using an EPS based filter and not the CamelotEPS or NativeEPS
01144     // filters then must warn the user that the EPS data does not save all info and question
01145     // whether they want to continue or not.
01146     // This used to use IS_KIND_OF VectorFilter before 29/4/96 but of course this
01147     // really wants to be for all the eps based filters and not all vector filters
01148     // Graeme (11-4-00) - Added FILTERID_AIEPS to stop the warnings when doing an
01149     // AI format export. After all, the AIEPS filter is probably better specified
01150     // these days than the other EPS filters.
01151     if (TheSelectedFilterID != FILTERID_CAMELOT_EPS &&
01152         TheSelectedFilterID != FILTERID_NATIVE_EPS &&
01153         TheSelectedFilterID != FILTERID_AIEPS
01154         && pFilter->IS_KIND_OF ( EPSFilter )
01155         )
01156     {
01157         // Warn the user that they are not exporting in Camelot EPS or native
01158         // format, and get them to confirm that this is what they want to do.
01159         // (We only do this for vector formats)
01160         ErrorInfo Info;
01161         Info.ErrorMsg = _R(IDT_EXPQUERY_NOTSURE);
01162         Info.Button[0] = _R(IDB_EXPQUERY_EXPORT);
01163         Info.Button[1] = _R(IDB_EXPQUERY_DONTEXPORT);
01164         if (UINT32(AskQuestion(&Info)) == _R(IDB_EXPQUERY_DONTEXPORT))
01165         {
01166             // User decided not to export - abort.
01167             CCFree(FilterString);
01168             FilterString = 0;
01169             FailAndExecute();
01170             RestoreSelection();
01171             End();
01172             return;
01173         }
01174     }
01175 
01176     BOOL fExportedOk = FALSE;
01177 
01179     // for the future "Options" button handling
01180 
01181     // get the export options
01182     // what we need is for the export dlg to appear and give the user the chance
01183     // to fill in the export options
01184     // SMFIX
01185 
01186     BitmapExportOptions* pOptions = NULL;
01187     if (pFilter->IS_KIND_OF(BaseBitmapFilter)) 
01188     {
01189         if (BmapPrevDlg::m_pExportOptions)
01190         {
01191             delete BmapPrevDlg::m_pExportOptions;
01192             BmapPrevDlg::m_pExportOptions = 0;
01193         }
01194         
01195         // only if it is a raster type and we are not saving from the gallery
01196         if (pExportParam == 0)
01197         {
01198             // set up with default attrib for this filter
01199             // and get the user to edit these default params in the export dlg (thats the FALSE param)
01200 PORTNOTE("other", "Use SetUpExportOptions to get defaults only and not do dialog" )
01201             ((BaseBitmapFilter*) pFilter)->SetUpExportOptions(&pOptions, FALSE);
01202 //          ((BaseBitmapFilter*) pFilter)->SetUpExportOptions(&pOptions, TRUE);
01203             // the dlg has been up and the user may have the graphic type
01204             // ask the dlg for the type that it used
01205             if (BmapPrevDlg::m_pExportOptions)
01206                 pOptions = BmapPrevDlg::m_pExportOptions;
01207             // take responsibility for the export options away from the bmp preview dlg
01208             BmapPrevDlg::m_pExportOptions = 0;
01209             // the filter we want to export with will change too if the export options have changed type
01210             if (pOptions)
01211             {
01212                 Filter * pOldFilter = pFilter;
01213                 pFilter = pOptions->FindBitmapFilterForTheseExportOptions();
01214                 // change the export extent if we have changed filters
01215                 if (pFilter && pFilter != pOldFilter)
01216                 {
01217                     // set the path extention
01218                     Path.SetType(BmapPrevDlg::m_pthExport.GetType());
01219                 }
01220                 else pFilter = pOldFilter;
01221             }
01222 
01223             if (!pOptions || !pFilter)
01224             {
01225                 // User decided not to export - abort.
01226                 RemoveUneededReportedErrors();
01227                 CCFree(FilterString);
01228                 FilterString = 0;
01229                 FailAndExecute();
01230                 RestoreSelection();
01231                 End();
01232                 return;
01233             }
01234 
01235             // do the odd details that a filter may need setting before it is ready to go (sjk 5/12/00)
01236             ((BaseBitmapFilter*) pFilter)->PostGetExportOptions(pOptions);
01237         }
01238     }
01239 
01240     BOOL bFinished = FALSE;
01241 
01242     // check if we can simply rename the temp file created during preview
01243     if (pOptions != 0 && pOptions->HasTempFile() && !pOptions->GetSeparateLayerFiles())
01244     {
01245         // get the temp file name
01246         PathName TempPath = pOptions->GetPathName();
01247         String_256 FinalName = Path.GetPath();
01248         String_256 TempName = TempPath.GetPath();
01249 
01250         // delete the empty file, if one was created, and try to rename the file
01251         FileUtil::DeleteFile(&Path);
01252 /*      
01253 #if defined(__WXGTK__) && FALSE != wxUSE_UNICODE
01254         char pszTempName[256];
01255         char pszFinalName[256];
01256         wcstombs( pszTempName, TempName, 256 );
01257         wcstombs( pszFinalName, FinalName, 256 );       
01258 #else
01259         char* pszTempName = TempName;
01260         char* pszFinalName = FinalName;
01261 #endif      
01262         bFinished = !rename(pszTempName, pszFinalName);
01263 */
01264         // This should do the trick but I've left the old code in case
01265         bFinished = !camRename(TempName, FinalName);
01266 
01267         if (bFinished)
01268         {
01269             fExportedOk = TRUE;
01270             // Only tell them if not special user cancelled error message
01271             RemoveUneededReportedErrors();
01272         }
01273     }
01274 
01275     // Set flag telling exporter that we are NOT exporting a temporary file!
01276     if(pOptions)
01277         pOptions->SetTempFileFlag(FALSE);
01278 
01279 PORTNOTE( "export", "Removed image map code" )
01280 #if !defined(EXCLUDE_FROM_XARALX)
01281     // Now export the image map if required
01282     if (pOptions && pOptions->GetSupportsImageMap() && pFilter->IS_KIND_OF(BaseBitmapFilter))
01283         static_cast<BaseBitmapFilter *>(pFilter)->ExportImagemap(this, &Path, GetWorkingDoc());
01284 #endif
01285 
01286     if (pOptions != NULL)
01287     {
01288         //And if we should be exporting an HTML tag to the clipboard
01289         if (pOptions->ShouldPutHTMLTagOnClipboard() && pFilter->IS_KIND_OF(BaseBitmapFilter))
01290             static_cast<BaseBitmapFilter *>(pFilter)->ExportHTMLTag(&Path);
01291 
01292 PORTNOTE("other", "Removed DreamWeaver DesignNote code" )
01293 #if 0
01294         // Do we want to make the extra dream weaver design notes file?
01295         if (pOptions->GetCanUseDesignNotes() && UsesDesignNotes())
01296         {
01297             if( !lstrcmpi( Path.GetType(), _T("gif") ) || !lstrcmpi( Path.GetType(), _T("jpg") ) || 
01298                 !lstrcmpi( Path.GetType(), _T("bmp") ) || !lstrcmpi( Path.GetType(), _T("png") ) )
01299             {
01300                 wxString DocName( (TCHAR *)Document::GetCurrent()->GetLocation() ); 
01301                 DocName += _T("\\");
01302                 DocName += (TCHAR *)Document::GetCurrent()->GetPathName();
01303 
01304                 if (DocName != _T("\\") )
01305                 {
01306                     wxString GraphicFile( (const TCHAR *)Path.GetPath() );
01307 
01308                     // create or modify a .mno forward source file
01309                     CreateDesignNoteWithForwardSource(GraphicFile, DocName);
01310                 }
01311                 else
01312                 {
01313                     InformWarning (_R(IDS_NOTES_WARNING));
01314                 }
01315             }
01316         }
01317 #endif
01318     }
01319 
01320     if (!bFinished)
01321     {
01322         // either no temp file, or failed to rename it, do normal export
01323 
01325 
01326     // First off, we have to try and open the file
01327     CCDiskFile theDiskFile(1024, FALSE, TRUE);
01328     try
01329     {
01330         /* File now opened up, if not already opened inside the DoExport functions in the filters
01331         // themselves. This means this is done after the export options and so the file is not trashed
01332         // until we start doing something to it.
01333         // Open up the file. This will create a zero length file just to make sure that it
01334         // is possible, i.e. we have write access.
01335         // Opened up here so that the filters do not need to know about opening the files and
01336         // closing them and so the preview filter can easily be used to append data into the
01337         // middle of the native and eps files.
01338         // Added 27/9/95 ios::trunc as exporting a bitmap or eps file to the same file twice
01339         // appended the data to the end of the file on Windows 95.
01340         if (!theDiskFile.open(Path, ios::in | ios::out | ios::binary | ios::trunc))
01341         {
01342             // Failed to open the file...
01343             InformError(_R(IDT_EXPORT_NOTFOUND));
01344             FailAndExecute();
01345             End();
01346             return;
01347         } */
01348 
01349         // Do we want a Preview Bitmap?
01350         if (pFilter->CanIncludePreviewBmp()) pFilter->IncludePreviewBmp(TRUE);
01351 
01352         // Export the file
01353         if (pExportParam != 0)
01354         {
01355             ERROR3IF(!pFilter->IS_KIND_OF(BaseBitmapFilter),
01356                                         "OpMenuExport::not a bitmap filter");
01357             BaseBitmapFilter* pBitmapFilter = (BaseBitmapFilter*) pFilter;
01358 
01359             if (pExportParam->GetBitmapCount() != 1)
01360                 fExportedOk = pBitmapFilter->DoExportBitmaps(
01361                                     this,               // Export bitmaps
01362                                     &theDiskFile,
01363                                     &Path,
01364                                     pExportParam);
01365             else
01366             {
01368     // for the future "Options" button handling
01369 
01370                 if (pFilter->IS_KIND_OF(BaseBitmapFilter) && pOptions)
01371                     fExportedOk = 
01372                         pBitmapFilter->DoExportBitmapWithOptions(
01373                                         this,           // Export bitmap
01374                                         &theDiskFile, 
01375                                         &Path,
01376                                         pExportParam->GetBitmap(0),
01377                                         pOptions);
01378                 else
01380 
01381                 fExportedOk = pBitmapFilter->DoExportBitmap(
01382                                     this,               // Export bitmap
01383                                     &theDiskFile,
01384                                     &Path,
01385                                     pExportParam->GetBitmap(0)); 
01386 
01387             }
01388         }
01389         else
01390         {
01392     // for the future "Options" button handling
01393 
01394             if (pFilter->IS_KIND_OF(BaseBitmapFilter) && pOptions/*&& CCamApp::IsNewWindowsUI()*/)
01395                 fExportedOk = ((BaseBitmapFilter*) pFilter)->DoExportWithOptions(
01396                                                 this,       // Export drawing
01397                                                 &theDiskFile, 
01398                                                 &Path, 
01399                                                 GetWorkingDoc(), 
01400                                                 pOptions);  
01401             else
01402                 fExportedOk = pFilter->DoExport(this,       // Export drawing
01403                                             &theDiskFile, 
01404                                             &Path, 
01405                                             GetWorkingDoc());
01406         }
01407 
01408         if (!fExportedOk)
01409         {
01410             if (Error::GetErrorNumber() == _R(IDN_USER_CANCELLED))
01411                 // Suppress the error if it was the 'user has cancelled one'.
01412                 Error::ClearError();
01413             else
01414             {
01415                 // Something went a bit wrong - tell the user what it was.
01416                 InformError();
01417                 pFilter->DeleteExportFile(&theDiskFile);
01418             }
01419         }
01420 
01421         // We had better tell the filter we no longer want Previews
01422         if (pFilter->CanIncludePreviewBmp()) pFilter->IncludePreviewBmp(FALSE);
01423 
01424         // close the file
01425         if (theDiskFile.isOpen()) theDiskFile.close();
01426     }
01427 
01428     // See if there was a file io error
01429     catch( CFileException e )
01430     {
01431         // Report the error if no one else did
01432         RemoveUneededReportedErrors();
01433 
01434         // Make sure that the file is closed and deleted
01435         try
01436         {
01437             // First try and delete it (tries to close it first) and
01438             // double check to make sure it is closed.
01439             if (pFilter) pFilter->DeleteExportFile(&theDiskFile);
01440             if (theDiskFile.isOpen()) theDiskFile.close();
01441         }
01442         catch(CFileException e)
01443         {
01444             // Failed to close the file - not much we can do about it really
01445             TRACE( _T("Failed to close file\n"));
01446         }
01447 
01448         fExportedOk = FALSE;
01449     }
01450 
01452     // for the future "Options" button handling
01453     }
01455 
01456     // Get rid of the filter string buffer and restore the original selection.
01457     CCFree(FilterString);
01458     FilterString = 0;
01459     RestoreSelection();
01460 
01461     if (!fExportedOk)
01462     {
01463         // delete the export options
01464         if (pOptions)
01465             delete pOptions;
01466 
01467         FailAndExecute();
01468         End();
01469         return;
01470     }
01471 
01472     // TODO: did we export only the selection?
01473     BOOL fExportedSelection = FALSE;
01474     if (pFilter->IS_KIND_OF(BaseBitmapFilter) && pParam == 0 && pOptions)
01475     {
01476         fExportedSelection = (pOptions->GetSelectionType() == SELECTION);
01477     }
01478 
01479     // Make named export sets from the user's exported selections.
01480     if (fExportedSelection)
01481         CreateNamedSet(pFilter, Path);      // this will call Fail or Succeed
01482     else
01483         SucceedAndDiscard();
01484 
01485     // delete the export options
01486     if (pOptions)
01487         delete pOptions;
01488 
01489     End();
01490 }
01491 
01492 
01493 
01494 /********************************************************************************************
01495 >   void OpMenuExport::CreateNamedSet(Filter* pFilter, const PathName& pthTarget)
01496 
01497     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01498     Created:    4/1/96
01499     Inputs:     The context of the just-performed export of the selected objects.
01500     Purpose:    Creates a named export set from the selected objects and the export
01501                 information passed to it.
01502 ********************************************************************************************/
01503 
01504 void OpMenuExport::CreateNamedSet(Filter* pFilter, const PathName& pthTarget)
01505 {
01506 PORTNOTETRACE("other", "CreateNamedSet - Do nothing - Use NgScan");
01507 #if !defined(EXCLUDE_FROM_XARALX)
01508     // Try to create a named set for them based on the filename chosen.
01509     String_256 strName(pthTarget.GetFileName(FALSE));
01510     NodeSetSentinel* pSentry = GetWorkingDoc()->GetSetSentinel();
01511     NodeSetProperty* pSet = pSentry->FindPropertyNode(strName);
01512 
01513     // This code used to first check if a set of that the name & path existed with the
01514     // same type, then if it could find such a set it would reuse it rather than creating
01515     // a new set (w/ a unique name).  I have changed this so the type of the export does
01516     // not matter any more (Jonathan 2 January 2001).
01517     BOOL fMustCreateNewSet = TRUE;
01518     if (pSet != 0)
01519     {
01520         NamedExportProp* pProp =
01521                     (NamedExportProp*) pSet->GetProperty(NamedExportProp::nIndex);
01522         if (/* pProp->GetFilter() != pFilter || */
01523             pProp->GetPath().GetLocation()      !=  pthTarget.GetLocation() ||
01524             pProp->GetPath().GetFileName(FALSE) !=  pthTarget.GetFileName(FALSE))
01525         {
01526             // Make the set name unique by appending ascending numerals.
01527             String_256 strBase = strName;
01528             INT32 nAppend = 2;
01529             while (pSentry->GetNameAttr(strName) != 0)
01530                 strName.MakeMsg(_R(IDS_NAMEDLG_UNIQUE_MASK), &strBase, nAppend++);
01531         }
01532         else
01533             // Same name & same path - it must be the existing set that is
01534             // being referred to so don't make a new one, just update the properties of
01535             // the one that exists (used to include filter type when checking to see if
01536             // we can reuse the existing name but not any more).
01537             fMustCreateNewSet = FALSE;
01538     }
01539 
01540     // If necessary, create a new named set of the selected objects.
01541     if (fMustCreateNewSet)
01542     {
01543         TRACEUSER( "JustinF", _T("Creating export set %s\n"), (LPCTSTR) strName);
01544 
01545         // This is taken from the implementation of OpApplyNameToSel.
01546         AllowOpScan aosSel(this, &theSelectedObjects),
01547                     aosSentinel(this, &theSetSentinel);
01548 
01549         if (!aosSel.Scan() ||
01550             !aosSentinel.Scan() ||
01551             !DoStartSelOp(FALSE, FALSE) ||
01552             !ApplySingleScan(this, &theSelectedObjects, strName).Scan() ||
01553             !ApplySingleScan(this, &theSetSentinel, strName).Scan() ||
01554             !ApplyPropScan(this, strName).Scan() ||
01555             !aosSel.Update() ||
01556             !aosSentinel.Update() ||
01557             (pSet = pSentry->FindPropertyNode(strName)) == 0)
01558         {
01559             TRACEUSER( "JustinF", _T("OpMenuExport::CreateNamedSet: naming scan failed\n"));
01560             FailAndExecute();
01561             return;
01562         }
01563     }
01564 
01565     // Remember the export filter and the path to the target.
01566     NamedExportProp* pProp =
01567                 (NamedExportProp*) pSet->GetProperty(NamedExportProp::nIndex);
01568     ERROR3IF(pProp == 0, "OpMenuExport::CreateNamedSet: no export property");
01569     
01570     pProp->SetFilter(pFilter);
01571     pProp->SetPath(pthTarget);
01572     pProp->SetDirty(); // Since the user has picked the graphic type it has been toutched and so in NOT a virgin
01573 
01574     // Remember the options associated with the filter.
01575     // TODO: fix this one day so that all filters are supported.
01576     ERROR3IF(!pFilter->IS_KIND_OF(BaseBitmapFilter),
01577                 "OpMenuExport::CreateNamedSet: not a bitmap filter");
01578     BitmapExportOptions* pOptions =
01579                 ((BaseBitmapFilter*) pFilter)->GetBitmapExportOptions();
01580     pProp->SetOptions(pOptions);
01581 #endif
01582 }
01583 
01584 
01585 
01586 /********************************************************************************************
01587 >   BOOL OpMenuExport::SetBitmapName(KernelBitmap* pTheBitmap, String_256 * DefaultName, 
01588                                     BitmapExportParam* pExportParam = 0)
01589 
01590     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01591     Created:    4/1/96
01592     Inputs:     pTheBitmap  the bitmap that we are interested in
01593                 pExportParam    the BitmapExportParameters we're using to export this bitmap
01594     Outputs:    DefaultName name to fill in
01595     Returns:    TRUE if it worked, FALSE if not
01596     Purpose:    Interegates the bitmap for its name and dumps this into the given string.
01597                 If there is an extension on the bitmap name then it will fix this to be
01598                 correct for the filter that will be selected. If there is no extension then
01599                 it will just append the correct extension onto the name.
01600 ********************************************************************************************/
01601 
01602 BOOL OpMenuExport::SetBitmapName(KernelBitmap * pTheBitmap, String_256 * DefaultName, 
01603                             BitmapExportParam* pExportParam)
01604 {
01605     OILBitmap* pOilBitmap = pTheBitmap->ActualBitmap;
01606     if (pOilBitmap)
01607     {
01608         *DefaultName = pOilBitmap->GetName();
01609         // We must add the extension on for the selected or default filter
01610         // Only add the extension if none is present already.
01611         // If an extension is present then check that it corresponds to the selected or default filter
01612         PathName TempPath(*DefaultName);
01613         String_32 Extension = TempPath.GetType();
01614         
01615         // Find the filter that the user chose
01616         Filter *pFilter = Filter::GetFirst();
01617         while (pFilter != 0)
01618         {
01619             if ((pFilter->GetFlags().CanExport) && 
01620                 (pFilter->FilterID == DefaultBitmapFilterID))
01621                 // This is the filter!
01622                 break;
01623 
01624             // Try the next filter
01625             pFilter = Filter::GetNext(pFilter);
01626         }
01627         
01628         if (pFilter && pFilter->pOILFilter)
01629         {
01630             // Get the OILFilter class to check the extension for the selected or default filter
01631             // matches
01632             if (!pFilter->pOILFilter->DoesExtensionOfPathNameMatch(&TempPath))
01633             {   
01634                 // Extension is either blank or does not match the one supplied by the filter
01635                 // Ask the OILFilter class to fix it for us
01636                 pFilter->pOILFilter->FixExtensionOfPathName(&TempPath);
01637                 // Now copy that back into the name
01638                 *DefaultName = TempPath.GetPath();
01639             }
01640             // If this was imported from a multi-image file
01641             // then we want to either bin the number or tag it on the end
01642             // Actually this whole practice is rather dubious since file names may
01643             // contain the search string. Wait for a proper fix to import bitmap!
01644             String_256 fileName = TempPath.GetFileName(FALSE);  // without extension
01645             // Search for the image index and throw it away...
01646             String_32 searchString;
01647             searchString.MakeMsg(_R(IDS_BITMAP_NAME), "","");
01648             INT32 index = fileName.Sub(searchString);
01649             if (index > 0)      // it had a number...probably
01650             {
01651                 if (pExportParam != 0 && pExportParam->GetBitmapCount() > 1)    
01652                 {
01653                     // multiple bitmaps - throw away any numbering
01654                     // oops...keeps the LHS (ignores #1 position)
01655                     fileName.Left(&fileName, index);    
01656                 }
01657                 else                // single bitmap - tag the number on the end, no spaces
01658                 {
01659                     fileName.Remove(index, searchString.Length());
01660                 }
01661                 TempPath.SetFileName(fileName);
01662                 *DefaultName = TempPath.GetPath();
01663             }
01664         }
01665     }
01666 
01667     return TRUE; 
01668 }
01669 
01670 
01671 
01672 /********************************************************************************************
01673 
01674 >   OpState OpMenuExport::GetState(String_256*, OpDescriptor*)
01675 
01676     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01677     Created:    22/03/94
01678     Purpose:    This item is always available, so long as a document is visible.
01679 
01680 ********************************************************************************************/
01681 
01682 OpState OpMenuExport::GetState(String_256 * pUIDescription, OpDescriptor * pOpDesc)
01683 {
01684 //Removed - Ranbir. 
01685 //Fixes a bug.
01686 //We cannot set the Greyed.State to TRUE, as the Save button in the bitmap gallery 
01687 //also relies on this getstate function. 
01688 /*
01689 #ifdef WEBSTER
01690     // In Webster, we will grey out the Export option if there are no visible objects on the page
01691     OpState OpSt;
01692     String_256 DisableReason;
01693 
01694     // Is there a selected spread?
01695     Spread * pSpread = Document::GetSelectedSpread();
01696     if (pSpread)
01697     {
01698         DocRect VisibleRect = pSpread->GetPageVisibleBounds();
01699         BOOL Empty = VisibleRect.IsEmpty();
01700         if (!Empty)
01701         {
01702             // There's a visible rect, so there must be exportable objects, so don't grey out
01703             OpSt.Greyed = FALSE;
01704         }
01705         else
01706         {
01707             // No visible objects, so grey it out and say why
01708             OpSt.Greyed = TRUE; 
01709             // Load reason why operation is disabled
01710             DisableReason = String_256(_R(IDS_NO_VISIBLE_OBJECTS));
01711             if (pUIDescription)
01712                 *pUIDescription = DisableReason;            
01713         }           
01714     }
01715     else 
01716     {
01717         // No selected spread, so we are greyed
01718         OpSt.Greyed = TRUE;
01719 
01720         // Load reason why operation is disabled
01721         DisableReason = String_256(_R(IDS_NO_DOC));
01722         if (pUIDescription)
01723             *pUIDescription = DisableReason;         
01724     }
01725 
01726     return OpSt;   
01727 
01728 #else
01729 */
01730 
01731     OpState OpSt;
01732 
01733     return OpSt;
01734 //#endif // WEBSTER
01735 }
01736 
01737 
01738 
01739 
01740 
01741 /********************************************************************************************
01742 
01743 >   BOOL OpDroppedFile::Init()
01744 
01745     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01746     Created:    22/03/94
01747     Returns:    TRUE if worked, FALSE if failed (out of memory)
01748     Purpose:    Declares op descriptor for drag'n'drop file operation.
01749     Errors:     Returns FALSE on failure.
01750 
01751 ********************************************************************************************/
01752 
01753 BOOL OpDroppedFile::Init()
01754 {
01755     if (!RegisterOpDescriptor(0,
01756                              _R(IDT_IMPORT),
01757                              CC_RUNTIME_CLASS(OpDroppedFile),
01758                              OPTOKEN_DROPPEDFILE,
01759                              GetState,
01760                              0,                 // help ID 
01761                              0,
01762                              0))                // bitmap ID 
01763         return FALSE; 
01764 
01765     return TRUE;
01766 }
01767 
01768 
01769 
01770 /********************************************************************************************
01771 
01772 >   void OpDroppedFile::DoWithParam(OpDescriptor*, OpParam* pOpParam)
01773 
01774     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01775     Created:    29/07/94
01776     Inputs:     pOpDesc - the OpDescriptor for this operation
01777                 pOpParam - parameters for this operations; actually an HDROP handle.
01778     Purpose:    Import the files dropped onto the specified document.
01779 
01780 ********************************************************************************************/
01781 
01782 #define PATH_BUF_SIZE (256)
01783 
01784 void OpDroppedFile::DoWithParam(OpDescriptor*, OpParam* pOpParam)
01785 {
01786     // Get the file list
01787     FileDropInfo* pFileInfo = (FileDropInfo*) pOpParam;
01788     List* pFileList = pFileInfo->GetFileList();
01789 
01790 #ifdef XAR_TREE_DIALOG
01791     CXFTreeDlg* pCXFTreeDlg = CXFTreeDlg::GetCurrentCXFTreeDlg();
01792     if (pCXFTreeDlg != 0)
01793     {
01794         StringListItem* pItem = (StringListItem*)(pFileList->GetHead());
01795         if (pItem)
01796             pCXFTreeDlg->ShowFile((TCHAR*)(pItem->GetString()));
01797 
01798         End();
01799         return;
01800     }
01801 #endif
01802 
01803 #if FALSE
01804 #if _DEBUG
01805     CMXTreeDlg* pCMXTreeDlg = CMXTreeDlg::GetCurrentCMXTreeDlg();
01806     if (pCMXTreeDlg != 0)
01807     {
01808         char PathBuf[PATH_BUF_SIZE];
01809         PathBuf[0] = 0;
01810 
01811         // Get the next filename
01812         UINT32 cBytes = DragQueryFile(hDrop, 0, PathBuf, PATH_BUF_SIZE);
01813 
01814         pCMXTreeDlg->ShowFile(PathBuf);
01815 
01816         End();
01817         return;
01818     }
01819 #endif
01820 #endif
01821     // Make sure we have a generic filter!
01822     GenericFilter *pGenericFilter = Filter::GetGenericFilter();
01823 
01824     if (pGenericFilter == 0)
01825     {
01826         InformError(_R(IDT_CANT_FIND_FILTER));
01827         FailAndExecute(); 
01828         End();
01829         return;
01830     }
01831 
01832     // Get me a DocView!
01833     DocView *pDocView = DocView::GetCurrent();
01834     // Sanity checks...
01835     if (pDocView == 0)
01836     {
01837         ERROR3("No current DocView while procesing drag'n'drop!");
01838         // give the user a random error, should never happen but just in case give them some
01839         // indication that something has gone wrong.
01840         InformError(_R(IDT_CANT_FIND_FILTER));
01841         FailAndExecute(); 
01842         End();
01843         // Exit cleanly
01844         return;
01845     }
01846 
01847     // Find out where the files were dropped...
01848     WinCoord DropPoint = pFileInfo->GetDropPoint();
01849 //  DragQueryPoint(hDrop, &DropPoint);
01850 
01851     // Turn this into Oil coordinates...
01852     OilCoord OilPos = DropPoint.ToOil(pDocView);
01853 
01854     // ...find the spread in which the click happened...
01855     ImportPosition Pos;
01856 
01857     Pos.pSpread = pDocView->FindEnclosingSpread(OilPos);
01858     if (Pos.pSpread == 0)
01859     {
01860         ERROR3("Could not find spread in which the drag'n'drop happened");
01861         // give the user a random error, should never happen but just in case give them some
01862         // indication that something has gone wrong.
01863         InformError(_R(IDT_CANT_FIND_FILTER));
01864         FailAndExecute(); 
01865         End();
01866         return; // Exit reasonably nicely
01867     }
01868 
01869     // First of all convert the OilCoord into device coords
01870     Pos.Position = OilPos.ToDoc(Pos.pSpread, pDocView);
01871     
01872     // Translate the coord to spread coords
01873     Pos.pSpread->DocCoordToSpreadCoord(&Pos.Position);
01874 
01875     // Find out how many files were dropped
01876 //  UINT32 cFiles = DragQueryFile(hDrop, (UINT32) -1, 0, 0);
01877     UINT32 cFiles = pFileList->GetCount();
01878 
01879     StringListItem* pItem = (StringListItem*)(pFileList->GetHead());
01880 
01881     // Load each file in turn...
01882     for (UINT32 iFile = 0; iFile < cFiles; iFile++)
01883     {
01884 //      char PathBuf[PATH_BUF_SIZE];
01885 //      PathBuf[0] = 0;
01886 
01887         // Get the next filename
01888 //      UINT32 cBytes = DragQueryFile(hDrop, iFile, PathBuf, PATH_BUF_SIZE);
01889 
01890         String_256 Str = pItem->GetString();
01891 
01892         // Check it's not too long
01893 //      if (cBytes > (PATH_BUF_SIZE - 5))
01894 //      {
01895 //          // Too long - inform user and try the next file.
01896 //          Error::SetError(_R(IDT_FILENAME_TOO_LONG));
01897 //          InformError();
01898 //      }
01899 //      else
01900         {
01901             // Import this file...
01902 //          PathName Path(PathBuf);
01903             PathName Path(Str);
01904             // Ensure that the path is valid
01905             if ( !Path.IsValid() )
01906             {
01907                 // Pathname specified is invalid
01908                 InformError();
01909                 FailAndExecute(); 
01910                 End();
01911                 return;
01912             }
01913 
01914             // First off, we have to try and open the file
01915             CCDiskFile DiskFile(1024, FALSE, TRUE);
01916 
01917             // Get pointer to current doc 'cos we'll need it several times...
01918             Document* pCurDoc = Document::GetCurrent();
01919 
01920             try
01921             {
01922                 if (!DiskFile.open(Path, ios::in | ios::binary))
01923                 {
01924                     // Failed to open the file...
01925                     TRACEUSER( "Rik", _T("Failed to open file in MenuImport Do"));
01926                     InformError(_R(IDT_IMPORT_NOTFOUND));
01927                     FailAndExecute();
01928                     End();
01929                     return;
01930                 }
01931 
01932                 // Import the file and see if Something went a bit wrong - tell the user what it was.
01933                 if (!pGenericFilter->DoImport(this, &DiskFile, pCurDoc, FALSE, &Pos))
01934                 {
01935                     // Something went a bit wrong - tell the user what it was.
01936                     // Only tell them if not special user cancelled error message
01937                     if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
01938                         InformError();
01939                     else
01940                         Error::ClearError();    // otherwise remove the error so it won't get reported
01941                     FailAndExecute(); 
01942                     End();
01943 
01944                     // Close the file again
01945                     if (DiskFile.isOpen())
01946                         DiskFile.close();
01947 
01948                     return;
01949                 }
01950 
01951                 // Close the file again
01952                 if (DiskFile.isOpen())
01953                     DiskFile.close();
01954 
01955             }
01956 
01957             // See if there was a file io error
01958             catch(CFileException e)
01959             {
01960                 // Report the error if no one else did
01961                 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
01962                     InformError();
01963                 else
01964                     Error::ClearError();    // otherwise remove the error so it won't get reported
01965 
01966                 // Make sure that the file is closed
01967                 try
01968                 {
01969                     if (DiskFile.isOpen())
01970                         DiskFile.close();
01971                 }
01972                 catch(CFileException e)
01973                 {
01974                     // Failed to close the file - not much we can do about it really
01975                 }
01976 
01977                 // and fail
01978                 FailAndExecute();
01979 
01980             }
01981         }
01982 
01983         // Get the next file name item
01984         pItem = (StringListItem*)(pFileList->GetNext(pItem));
01985     }
01986     
01987     // Finished the operation
01988     End();
01989 
01990     return;
01991 }
01992 
01993 
01994 
01995 /********************************************************************************************
01996 
01997 >   OpState OpDroppedFile::GetState(String_256*, OpDescriptor*)
01998 
01999     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
02000     Created:    22/03/94
02001     Purpose:    This item is always available, so long as a document is visible.
02002 
02003 ********************************************************************************************/
02004 
02005 OpState OpDroppedFile::GetState(String_256*, OpDescriptor*)
02006 {
02007     OpState OpSt;
02008 
02009     return OpSt;
02010 }
02011 
02012 
02013 
02014 /********************************************************************************************
02015 
02016   > BitmapExportParam::BitmapExportParam()
02017 
02018     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02019     Created:    13/5/97
02020     Purpose:    Default Constructor
02021 
02022 ********************************************************************************************/
02023 
02024 BitmapExportParam::BitmapExportParam(): OpParam(0, 0)
02025 {
02026     m_pBmpDlgParam = 0; 
02027 }
02028 
02029 /********************************************************************************************
02030 >   BitmapExportParam::BitmapExportParam(UINT32 Count, KernelBitmap** pBitmap)
02031 
02032     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02033     Created:    11/6/96
02034     Inputs:     Count - The number of indexes in the array
02035                 pBitmap - pointer to an array of pointers to kernel bitmaps
02036     Outputs:    -
02037     Returns:    -
02038     Purpose:    Used to pass around lists of bitmaps.  Note that deleting the bitmap array
02039                 is the responsibility of the caller.
02040 ********************************************************************************************/
02041 BitmapExportParam::BitmapExportParam(UINT32 Count, KernelBitmap** pBitmap, BmpDlgParam* pParam) :
02042     OpParam((INT32)Count, (void *)pBitmap)
02043 {
02044     ERROR3IF(Count==0, "Zero bitmap count, that's not right");
02045     ERROR3IF(pBitmap==0, "0 bitmap array");
02046     ERROR3IF(!(*pBitmap)->IS_KIND_OF(KernelBitmap), "This dosen't seem to be an array of kernel bitmaps");
02047 
02048     // Save a reference to the BmpDlgParam, for use in BmpPrefsDlg.
02049     SetBmpDlgParam(pParam);
02050 }
02051 
02052 
02053 
02054 /********************************************************************************************
02055 >   virtual UINT32 BitmapExportParam::GetBitmapCount()
02056 
02057     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02058     Created:    11/6/96
02059     Inputs:     -
02060     Outputs:    -
02061     Returns:    The number of bitmaps in the bitmap array.  (The array runs 0..Count-1)
02062     Purpose:    For getting the number of bitmaps in the array!
02063 ********************************************************************************************/
02064 UINT32 BitmapExportParam::GetBitmapCount()
02065 {
02066     return (UINT32)Param1;
02067 }
02068 
02069 
02070 
02071 /********************************************************************************************
02072 >   virtual KernelBitmap* BitmapExportParam::GetBitmap(UINT32 Index)
02073 
02074     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02075     Created:    11/6/96
02076     Inputs:     Index - the index of the required bitmap
02077     Outputs:    -
02078     Returns:    Pointer to the nth bitmap, 0 if error
02079     Purpose:    For safely getting a pointer to a bitmap in the bitmap array
02080 ********************************************************************************************/
02081 KernelBitmap* BitmapExportParam::GetBitmap(UINT32 Index)
02082 {
02083     ERROR2IF(Index>=(UINT32)Param1, 0, "Index out of bounds");
02084     ERROR2IF(Param2==0, 0, "0 array");
02085 
02086     ERROR3IF( !( ( (KernelBitmap**)(void *)Param2 )[Index])->IS_KIND_OF(KernelBitmap), "This dosen't seem to be a pointer to a kernel bitmap");
02087     return( (KernelBitmap**)(void *)Param2 )[Index];
02088 }
02089 
02090 
02091 /********************************************************************************************
02092 >   void BitmapExportParam::SetBmpDlgParam(BmpDlgParam* pParam)
02093 
02094     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
02095     Created:    05/01/96
02096     Inputs:     pParam - Allows the transfer of bitmap info.
02097     Outputs:    -
02098     Returns:    -
02099     Purpose:    -
02100 ********************************************************************************************/
02101 BOOL BitmapExportParam::SetBmpDlgParam(BmpDlgParam* pParam)
02102 {
02103     ERROR2IF(pParam == 0,FALSE, "pParam is 0");
02104     m_pBmpDlgParam = pParam;
02105     return TRUE;
02106 }
02107 
02108 

Generated on Sat Nov 10 03:45:32 2007 for Camelot by  doxygen 1.4.4