filedlgs.cpp

Go to the documentation of this file.
00001 // $Id: filedlgs.cpp 1712 2006-08-22 16:01:26Z luke $
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 // Custom File Open and Save Dialogs
00099 
00100 #include "camtypes.h"
00101 #include "camelot.h"        // IsNewWindowsUI
00102 
00103 #include "filedlgs.h"
00104 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 #include "camframe.h"
00106 //#include "rik.h"
00107 //#include "andy.h"
00108 //#include "mario.h"            // for _R(IDE_NOMORE_MEMORY)
00109 //#include "nev.h"          // for _R(IDN_IMPORTBUTTON) etc
00110 //#include "resource.h"
00111 //#include "oilfltrs.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include "native.h"         // The new designed native filter, used for v2
00114 #include "nativeps.h"       // The old style EPS native filter, used in v1.1
00115 //#include "custmsg.h"
00116 #include "helpuser.h"
00117 #include "camelot.h"
00118 //#include "filters.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00119 #include "bmapprev.h"
00120 #include "bmpfiltr.h"
00121 
00122 #include "palman.h"
00123 
00124 // WEBSTER - markn 28/1/97
00125 //#include "tim.h"
00126 #include "webparam.h"
00127 #include "xarprefs.h"
00128 #include "webprefs.h"
00129 #include "webfiltr.h"
00130 
00131 //#include "richard2.h"     // For resource strings
00132 
00133 #include "ctrlhelp.h"
00134 #include "bitfilt.h"        // BaseBitmapFilter
00135 
00136 //#include "xardlg.h"           // For the base dialogue for the web dialogue.
00137 //#include "webdlg.h"           // Additional controls in _R(IDD_SAVEWEBOPTS)
00138 //#include "filtrres.h"     // _R(IDS_FILTEREXT_WEB)
00139 //#include "reshlpid.h"       // _R(ID_CC_HELP_BUTTON) 
00140 
00141 // New for preview bitmaps
00142 #include "dlgcol.h"         // DialogColourInfo
00143 #include "dlgview.h"        // DialogView
00144 //#include "docview.h"      // DocView - in camtypes.h [AUTOMATICALLY REMOVED]
00145 #include "osrndrgn.h"       // OSRenderRegion
00146 //#include "bitmap.h"           // KernelBitmap - in camtypes.h [AUTOMATICALLY REMOVED]
00147 #include "nodebmp.h"        // NodeBitmap
00148 #include "bitmpinf.h"       // BitmapInfo
00149 #include "oilbitmap.h"      // CWxBitmap
00150 #ifndef WEBSTER
00151 //#include "extfilts.h"     // AccusoftFilters
00152 #endif //WEBSTER
00153 //#include "cmxifltr.h"     // CMXImportFilter
00154 #include "webaddr.h"        // Olivier 09/05/97, use of the WebAddress class
00155 #include "aprps.h"              
00156 #include "exjpeg.h"
00157 #include "ngprop.h"         // for NamedExportProp::m_fApplyNotExport
00158 //#include "bmpreres.h"     // for _R(IDS_PREVIEW_APPLY)
00159 
00160 //#include "resimmap.h"     // for new templates stuff
00161 #include "menuops.h"
00162 #include "progress.h"
00163 
00164 #include "qualattr.h"
00165 //#include <shfolder.h> // For SHGetFolderPath
00166 
00167 void FixFPControlRegister();
00168 
00169 // the longest name we can display as a path, before going down to the basename
00170 #define MAX_ALLOWED_NAME_LENGTH 60
00171 
00172 #define NumberOfNames 60
00173 
00174 const DWORD FCIDM_SHVIEW_THUMBNAIL = 0x702D;
00175 
00176 String_256 BaseFileDialog::DefaultSaveFilePath = TEXT("");
00177 String_256 BaseFileDialog::DefaultOpenFilePath = TEXT("");
00178 INT32        BaseFileDialog::SelectedFilter = FILTERID_VECTOR;  // changed from FILTERID_GENERIC
00179 BOOL       BaseFileDialog::MakeBakFiles = FALSE;
00180 BOOL       BaseFileDialog::ShowPreviewBitmap = TRUE;
00181 BOOL       BaseFileDialog::ThumbNailMode = FALSE;
00182 
00183 BOOL       SaveTemplateDialog::m_fUseAsDefault = TRUE;
00184 BOOL       SaveTemplateDialog::m_fDefaultTemplatesFolder = TRUE;
00185 
00186 
00187 // This points at the current running file dialog.  NB. this will only allow one file
00188 // dialog to be open at any one time!
00189 BaseFileDialog* BaseFileDialog::m_pCurrentFileDialog = NULL;
00190 
00191 // Run-time type enquiry mechanisms.  These are required by the on-line help system.
00192 IMPLEMENT_CLASS(BaseFileDialog,     wxFileDialog);
00193 IMPLEMENT_CLASS(OpenFileDialog,     BaseFileDialog);
00194 IMPLEMENT_CLASS(SaveFileDialog,     BaseFileDialog);
00195 IMPLEMENT_CLASS(SaveTemplateDialog, SaveFileDialog);
00196 IMPLEMENT_CLASS(ImportFileDialog,   BaseFileDialog);
00197 IMPLEMENT_CLASS(ExportFileDialog,   BaseFileDialog);
00198 IMPLEMENT_CLASS(GIFExportFileDialog,ExportFileDialog);
00199 
00200 PORTNOTE("other", "Removed MFC MESSAGE_MAPs" )
00201 #if !defined(EXCLUDE_FROM_XARALX)
00202 // Need to ensure we get redraw messages back from the dialog box
00203 // so that we can redraw the preview bitmap
00204 BEGIN_MESSAGE_MAP(OpenFileDialog, BaseFileDialog)
00205     ON_BN_CLICKED(_R(ID_CC_HELP_BUTTON), BaseFileDialog::OnHelp)        // Windows 95 form
00206     ON_BN_CLICKED(_R(IDC_SHOWPREVIEW), BaseFileDialog::OnShowPreviewBitmap)     // Windows 95 form
00207     ON_MESSAGE(WM_REDRAW, OnRedrawMessage)
00208     ON_WM_SIZE()
00209 END_MESSAGE_MAP()
00210 
00211 // Map the buttons on the save dialog to the web export options handling functions
00212 // Need two forms for the Windows 95 UI and Old Windows UI types.
00213 // This code is all negated now and so is disabled.
00214 // But now we have a preview bitmap on the dialog box
00215 BEGIN_MESSAGE_MAP(SaveFileDialog, BaseFileDialog)
00216     ON_BN_CLICKED(_R(ID_CC_HELP_BUTTON), BaseFileDialog::OnHelp)        // Windows 95 form
00217     ON_BN_CLICKED(_R(IDC_SHOWPREVIEW), BaseFileDialog::OnShowPreviewBitmap)     // Windows 95 form
00218     // WEBSTER - markn 28/1/97
00219     ON_BN_CLICKED(_R(IDC_FILEDLG_OPTIONS), BaseFileDialog::OnOptions)           // Windows 95 form
00220     ON_MESSAGE(WM_REDRAW, OnRedrawMessage)
00221     ON_WM_SIZE()
00222 END_MESSAGE_MAP()
00223 
00224 BEGIN_MESSAGE_MAP(SaveTemplateDialog, BaseFileDialog)
00225     ON_BN_CLICKED(_R(ID_CC_HELP_BUTTON), BaseFileDialog::OnHelp)        // Windows 95 form
00226     ON_BN_CLICKED(_R(IDC_SHOWPREVIEW), BaseFileDialog::OnShowPreviewBitmap)     // Windows 95 form
00227     ON_BN_CLICKED(_R(IDC_USEASDEFAULT), SaveTemplateDialog::OnUseAsDefault)     // Windows 95 form
00228     ON_MESSAGE(WM_REDRAW, OnRedrawMessage)
00229     ON_WM_SIZE()
00230 END_MESSAGE_MAP()
00231 
00232 
00233 // Need to ensure we get redraw messages back from the dialog box
00234 // so that we can redraw the preview bitmap
00235 BEGIN_MESSAGE_MAP(ImportFileDialog, BaseFileDialog)
00236     ON_BN_CLICKED(_R(ID_CC_HELP_BUTTON), BaseFileDialog::OnHelp)        // Windows 95 form
00237     ON_BN_CLICKED(_R(IDC_SHOWPREVIEW), BaseFileDialog::OnShowPreviewBitmap)     // Windows 95 form
00238     ON_COMMAND(IDOK, OnOK)
00239     ON_BN_CLICKED(IDOK, OnOK)
00240     ON_MESSAGE(WM_REDRAW, OnRedrawMessage)
00241     ON_WM_LBUTTONDBLCLK()
00242     ON_WM_SIZE()
00243 END_MESSAGE_MAP()
00244 
00245 BEGIN_MESSAGE_MAP(ExportFileDialog, BaseFileDialog)
00246     ON_BN_CLICKED(_R(ID_CC_HELP_BUTTON), BaseFileDialog::OnHelp)            // Windows 95 form
00247     ON_BN_CLICKED(_R(IDC_FILEDLG_OPTIONS), BaseFileDialog::OnOptions)
00248     ON_BN_CLICKED(_R(IDC_SHOWPREVIEW), BaseFileDialog::OnShowPreviewBitmap) // Windows 95 form
00249     ON_BN_CLICKED(_R(IDC_AUTO_CHECK), OnAutoPreview)                        // Windows 95 form
00250     ON_MESSAGE(WM_REDRAW, OnRedrawMessage)
00251     ON_WM_SIZE()
00252 END_MESSAGE_MAP()
00253 #endif
00254 
00255 /********************************************************************************************
00256 >   BaseFileDialog::BaseFileDialog(BOOL IsFileOpen, WORD Flags, LPCSTR lpszFilter=NULL,
00257                 wxWindow* pParentWnd=NULL)
00258 
00259     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> & JustinF
00260     Created:    26/1/95
00261     Inputs:     IsFileOpen - TRUE if this is a File Open dialog, FALSE if it is a Save Dialog
00262                 Flags - The flags you want set in the CFileDialog.
00263                 lpszFilter - The Filter String
00264                 pParentWnd - The owner of this window (by default the main frame window)
00265     Purpose:    Creates a base class file dialog, installing a hook etc.
00266 
00267 Technical Notes:
00268 We set the OFN_EXPLORER on Windows 95 only. Really this should include the new shell on NT
00269 when we work with it. If you set this flag on NT without the new shell, then you get a useful
00270 not enough memory or similar error and the dialog box fails to open. At present, the user will
00271 see nothing as we don't seem to cope with errors.
00272 We need to set the flag as some functions e.g. ExportFileDialog::OnTypeChange() will only
00273 work with it set. Used to fix the filenames up when switching to a new filter.
00274 ********************************************************************************************/
00275 
00276 // Visual C (MFC) 4 defines this constant, but Visual C 2 does not
00277 #ifndef OFN_EXPLORER
00278 #define OFN_EXPLORER 0
00279 #endif
00280 
00281 BaseFileDialog::BaseFileDialog(BOOL IsFileOpen, DWORD dwFlags, LPCTSTR lpszFilter, wxWindow* pParentWnd)
00282   : wxFileDialog( (pParentWnd != NULL) ? pParentWnd : pParentWnd = GetMainFrame(), _T("Choose a file"),
00283         _T(""), _T(""), lpszFilter, dwFlags | ( IsFileOpen ? wxOPEN : wxSAVE) )
00284 //  IsFileOpen, NULL, NULL, dwFlags | ((CCamApp::IsNewWindowsUI()) ? OFN_EXPLORER : OFN_SHOWHELP) | OFN_ENABLEHOOK,
00285 //  lpszFilter, )
00286 {
00287 PORTNOTE("other", "Removed MFC junk" )
00288 #if !defined(EXCLUDE_FROM_XARALX)
00289     // Set the address of the message hook procedure.
00290     m_ofn.lpfnHook = (LPOFNHOOKPROC) HookProc;
00291 
00292     // Unfortunately, MFC doesn't set the hwndOwner member of m_ofn . . .
00293     m_ofn.hwndOwner = (pParentWnd != NULL) ? pParentWnd->m_hWnd : NULL;
00294 
00295     // We haven't called the explorer style init function by default
00296     ExplorerInited = FALSE;
00297 #endif
00298     
00299     // Remember a pointer to this file dialog.
00300     m_pCurrentFileDialog = this;
00301 
00302     // Set the preview bitmap to be NULL
00303     pBitmapToUse = NULL;
00304 
00305     // Added by Craig Hamilton 20/9/00.
00306     m_previousPathName = _T("");
00307     // End added.
00308 }
00309 
00310 
00311 /********************************************************************************************
00312 
00313 >   BaseFileDialog::~BaseFileDialog()
00314 
00315     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00316     Created:    18/7/96
00317     Returns:    -
00318     Purpose:    Standard destructor. Need to clean up the preview bitmap, if present.
00319 
00320 ********************************************************************************************/
00321 
00322 BaseFileDialog::~BaseFileDialog()
00323 {
00324     // Must clean up our preview bitmap, if present
00325     if (pBitmapToUse != NULL)
00326     {
00327         delete pBitmapToUse;
00328         pBitmapToUse = NULL;
00329     }
00330     m_pCurrentFileDialog = NULL;
00331 }
00332 
00333 
00334 PORTNOTE("other", "Removed MFC type Hooks" )
00335 #if !defined(EXCLUDE_FROM_XARALX)
00336 /********************************************************************************************
00337 >   static UINT32 CALLBACK BaseFileDialog::HookProc(wxWindow* hwnd, UINT32 nMsg,
00338                                                   WPARAM wParam, LPARAM lParam)
00339     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00340     Created:    18/5/95
00341     Inputs:     (the usual message proc paramters, see Win32 SDK documentation)
00342     Returns:    FALSE if the dialog library should process this message, TRUE if it
00343                 should ignore it.
00344     Purpose:    Called by the common dialog library when it has a message to process.
00345                 Calls the virtual OnHookMsg function.
00346     SeeAlso:    BaseFileDialog::OnHookMsg
00347 ********************************************************************************************/
00348 
00349 UINT32 CALLBACK BaseFileDialog::HookProc(wxWindow* hwnd, UINT32 nMsg, WPARAM wParam, LPARAM lParam)
00350 {
00351     // If there is no current file dialog then just say nothing and do nothing
00352     // This MAY happen if we are bodging the web filename file dialog which is to get
00353     // round having double file dialogs on screen, which is BAD!
00354     if (m_pCurrentFileDialog == NULL) // || m_pCurrentFileDialog->hwnd == NULL)
00355         return FALSE;
00356 
00357     return m_pCurrentFileDialog->OnHookMsg(hwnd, nMsg, wParam, lParam);
00358 }
00359 
00360 
00361 
00362 /********************************************************************************************
00363 >   virtual UINT32 BaseFileDialog::OnHookMsg(wxWindow* hwnd, UINT32 nMsg, WPARAM wParam, LPARAM lParam)
00364 
00365     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00366     Created:    18/5/95
00367     Inputs:     (the usual message proc parameters)
00368     Returns:    FALSE if the dialog library should process this message, TRUE if it
00369                 should ignore it.
00370     Purpose:    Called by the common dialog library when it has a message to process.
00371                 This function checks if the help button has been clicked, and runs the
00372                 help engine if it has.
00373     SeeAlso:    BaseFileDialog::HookProc
00374 ********************************************************************************************/
00375 
00376 UINT32 BaseFileDialog::OnHookMsg(wxWindow* hwnd, UINT32 nMsg, WPARAM wParam, LPARAM lParam)
00377 {
00378     // Check for a help message.
00379     if (nMsg == WM_COMMAND && LOWORD(wParam) == pshHelp)
00380     {
00381         // Run the help engine for this dialog and don't bother processing this message
00382         // any further, we've done it.
00383         HelpUser(*this);
00384         return TRUE;
00385     }
00386 
00387     // Allow explorer style dialog boxes to set themselves up
00388     if (nMsg == WM_INITDIALOG && CCamApp::IsNewWindowsUI())
00389     {
00390         // Only call this if we are the new explorer dialog boxes
00391         return ExplorerInitDialog(hwnd);
00392     }
00393 
00394     // WM_NOTIFY notification messages indicates actions taken by the user in the dialog box.
00395     // The lParam parameter for each WM_NOTIFY message is the address of a OFNOTIFY structure
00396     // that defines the action. The code member in the header for the OFNOTIFY structure
00397     // contains the notification values
00398     if (nMsg == WM_NOTIFY && lParam != NULL)
00399     {
00400         OFNOTIFY * pNotify = (OFNOTIFY*)lParam;
00401         // This is used to inform explorer style dialogs of actions
00402         if (CCamApp::IsNewWindowsUI())
00403             return ExplorerFileHookNotify(hwnd, pNotify);
00404     }
00405 
00406     //TODO: change 'File name:' to 'File name (or URL):' (WARNING: change _R(ID_OF_FILENAME) with the correct ID)
00407     //SetDlgItemText(hwnd, _R(ID_OF_FILENAME), (TCHAR *)String_256("File name (or URL):"));
00408 
00409 #ifndef RALPH
00410     // By default let MFC handle all other messages in its own hook procedure.
00411     return _AfxCommDlgProc(hwnd, nMsg, wParam, lParam);
00412 #else
00413     // Why doesn't this work with _AFXDLL defined ?
00414     return FALSE;
00415 #endif
00416 }
00417 
00418 /********************************************************************************************
00419 
00420 >   virtual BOOL BaseFileDialog::ExplorerInitDialog(wxWindow* hDlg)
00421 
00422     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00423     Created:    2/7/96
00424     Returns:    TRUE if it worked, FALSE if it failed
00425     Purpose:    Should be called when the explorer style dialog boxes need setting up.
00426                 We can take this opportunity to add in any extra controls that we require.
00427                 Baseclass version.
00428     SeeAlso:    BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
00429 
00430 ********************************************************************************************/
00431 
00432 BOOL BaseFileDialog::ExplorerInitDialog(wxWindow* hDlg)
00433 {
00434     return TRUE;
00435 }
00436 
00437 /********************************************************************************************
00438 
00439 >   virtual BOOL BaseFileDialog::ExplorerFileHookNotify(wxWindow* hDlg, LPOFNOTIFY pofn)
00440 
00441     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00442     Created:    3/7/96
00443     Inputs:     hDlg - wxWindow* of the dialog box.
00444                 pofn - pointer to notify structure
00445     Returns:    TRUE if it worked, FALSE if it failed
00446     Purpose:    Should be called when actions happen on the explorer style dialog boxes.
00447                 We can take this opportunity to handle these actions as required.
00448                 Baseclass version.
00449     SeeAlso:    BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
00450 
00451 ********************************************************************************************/
00452 
00453 BOOL BaseFileDialog::ExplorerFileHookNotify(wxWindow* hDlg, LPOFNOTIFY pofn)
00454 {
00455     return TRUE;
00456 }
00457 
00458 /********************************************************************************************
00459 
00460 >   virtual UINT32 BaseFileDialog::OnFileTypeChange()
00461 
00462     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00463     Created:    12/1/96
00464     Returns:    TRUE if it worked, FALSE if it failed
00465     Purpose:    Should be called when the user has selected a new file type from the
00466                 "Files of type" combo box. We might need to do things like fix the file
00467                 extension for the currently selected save/export filter.
00468                 Baseclass version.
00469     SeeAlso:    BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
00470 
00471 ********************************************************************************************/
00472 
00473 UINT32 BaseFileDialog::OnFileTypeChange()
00474 {
00475     return TRUE;
00476 }
00477 #endif
00478 
00479 /********************************************************************************************
00480 
00481 >   BOOL BaseFileDialog::Init()
00482 
00483     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00484     Created:    25/1/95
00485     Returns:    TRUE if it worked, FALSE if it failed
00486     Purpose:    Declares some preferences for the Open and Save dialogs
00487 
00488 ********************************************************************************************/
00489 
00490 BOOL BaseFileDialog::Init()
00491 {
00492     // Set some defaults
00493     String_256 Blank("");
00494     DefaultSaveFilePath = Blank;
00495     DefaultOpenFilePath = Blank;
00496 
00497     // declare prefs for the open and save dialogs
00498     Camelot.DeclareSection(_T("Filters"), 6);
00499     Camelot.DeclarePref(_T("Filters"), _T("DefaultSaveFilePath"), &DefaultSaveFilePath);
00500     Camelot.DeclarePref(_T("Filters"), _T("DefaultOpenFilePath"), &DefaultOpenFilePath);
00501     Camelot.DeclarePref(_T("Filters"), _T("OpenFileFilter"), &SelectedFilter);
00502     Camelot.DeclarePref(_T("Filters"), _T("MakeBakFiles"), &MakeBakFiles);
00503     Camelot.DeclarePref(_T("Filters"), _T("ShowPreviewBitmap"), &ShowPreviewBitmap);
00504     Camelot.DeclarePref(_T("Filters"), _T("ThumbNailMode"), &ThumbNailMode);
00505 
00506 
00507     return TRUE;
00508 }
00509 
00510 
00511 
00512 /********************************************************************************************
00513 
00514 >   BOOL BaseFileDialog::PrepareDialog()
00515 
00516     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00517     Created:    26/1/95
00518     Returns:    TRUE if it worked, FALSE if not
00519     Purpose:    Does anything the dialogs want doing after they have been created, but before
00520                 they are displayed.
00521 
00522 ********************************************************************************************/
00523 
00524 BOOL BaseFileDialog::PrepareDialog()
00525 {
00526     // Nothing to do in this base class . . .
00527     return TRUE;
00528 }
00529 
00530 
00531 /********************************************************************************************
00532 
00533 >   static char *BaseFileDialog::BuildFilterString(BOOL GetImport,
00534                                                    UINT32 SelectedFilterID,
00535                                                    INT32 *SelectedFilter,
00536                                                    CCRuntimeClass *pTypeOfFilter = GenericFilter,
00537                                                    UINT32 Bpp = 0)
00538 
00539     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00540     Created:    29/03/94
00541     Inputs:     GetImport - TRUE => Build list of Import filters
00542                            FALSE => Build list of Export filters
00543                 SelectedFilterID - the ID of the last filter that was used by the
00544                                    calling Operation.
00545                 pTypeOfFilter    - optional type of filter to use. Defaults to GenericFilter
00546                                    for all.
00547                 Bpp              - if only bitmap filters required then check this bpp against
00548                                    the ones that the filter supports 
00549     Outputs:    SelectedFilter - the position in the list box of the selected filter
00550                                  identified by SelectedFilterID, or unchanged if it wasn't 
00551                                  found.
00552     Returns:    The filter string.
00553     Purpose:    Build a filter string suitable for use by Windows' common dialog 
00554                 "File open" or "File save" boxes.
00555                 This is mainly for the import and export dialog boxes.
00556                 Used to be in OilFiltrs.cpp until moved to BaseFileDialog 5/1/96.
00557     Errors:     Out of memory
00558     SeeAlso:    MetaFileFilter;
00559     SeeAlso:    OpMenuExport; OpMenuImport;
00560 
00561 ********************************************************************************************/
00562 
00563 TCHAR *BaseFileDialog::BuildFilterString(BOOL GetImport,
00564                                         UINT32 SelectedFilterID,
00565                                         INT32 *SelectedFilter,
00566                                         CCRuntimeClass *pTypeOfFilter,
00567                                         UINT32 Bpp,
00568                                         UINT32 BitmapCount)
00569 {
00570     // Find out how much space is needed
00571     UINT32 FilterSize = 0;
00572 
00573     // Used to load in the resource strings for the filter extension descriptions.
00574     String_256 FilterExtensions;
00575 
00576     Filter *pFilter = Filter::GetFirst();
00577     BOOL FilterCanCope = TRUE;
00578     while (pFilter != NULL)
00579     {
00580         // If we are filtering for bitmap filters then check that if a Bpp has been
00581         // specified that the bitmap filter can cope with that.
00582         FilterFlags Flags = pFilter->GetFlags();
00583         if (pTypeOfFilter==CC_RUNTIME_CLASS(BitmapFilter) && pFilter->IsKindOf(pTypeOfFilter))
00584         {
00585             BaseBitmapFilter* pBitmapFilter = (BaseBitmapFilter*)pFilter;
00586             if (pBitmapFilter->IsThisBppOk(Bpp))
00587             {
00588                 // Webster - RanbirR - 25\02\97  
00589                 // If this is a single bitmap and the the Bpp is 24, 
00590                 // then we do not want to dipsplay *.gif in the export filter List.
00591                 // Only allow the format for Animated GIF's (even though they do not 
00592                 // support 24 colour bitmaps.) We later convert to an 8 Bpp. 
00593                 // This fixes an animated GIF export bug in Camelot.
00594                 // At present we error if the first bitmap in our animated gif is 24Bpp.
00595                 if (pFilter->FilterID ==  FILTERID_TI_GIF && Bpp == 24 && BitmapCount == 1)
00596                     FilterCanCope = FALSE;
00597                 else
00598                     FilterCanCope = TRUE;
00599             }
00600             else
00601                 FilterCanCope = FALSE;
00602 
00603             if (BitmapCount>1 && !Flags.CanExportMultipleImages)
00604                 FilterCanCope = FALSE;
00605         }
00606         else
00607             FilterCanCope = TRUE;
00608                 
00609         // little bit of a bodge here to stop the CamelotEPSFilter from appearing in the
00610         // import list - you can't hide it from just one list. It must be availiable though
00611         // to give it's nice little error message. Other instances of this below.
00612         if (
00613             ( ( GetImport && Flags.CanImport && !IS_A( pFilter, CamelotEPSFilter ) )
00614                 || (!GetImport && Flags.CanExport)) && NULL != pFilter->pOILFilter &&
00615                 Flags.ShowFilter && (pFilter->IsKindOf(pTypeOfFilter)) && FilterCanCope
00616            )
00617         {
00618             // Add the space required to put this into the filter string
00619             // (add 1 for the separating '|' character when not the first)
00620             if (FilterSize != 0)
00621                 FilterSize += 1;
00622             FilterSize += camStrlen(pFilter->pOILFilter->ConstructFilterString(BitmapCount));
00623         }
00624 
00625         // Try the next filter
00626         pFilter = Filter::GetNext(pFilter);
00627     }
00628 
00629     // If we have found no valid filters then we must set an error and return NULL
00630     // as otherwise we are in an illegal situation
00631     if (FilterSize == 0)
00632     {
00633         Error::SetError(_R(IDE_FORMATNOTSUPPORTED));
00634         return NULL;
00635     }
00636     
00637     // Add one for the final terminator.
00638     FilterSize += 1;
00639 
00640     // Try to get this string
00641     TCHAR *FilterString = (TCHAR *) CCMalloc(FilterSize * sizeof(TCHAR));
00642     if (FilterString==NULL)
00643     {
00644         // Error state already set by CCMalloc
00645         return NULL;
00646     }
00647     
00648     // Construct the string, and set up the position numbers for the filters.
00649     UINT32 Position = 0;
00650     FilterString[0] = 0;
00651     pFilter = Filter::GetFirst();
00652 
00653     while (pFilter != NULL)
00654     {
00655         // If we are filtering for bitmap filters then check that if a Bpp has been
00656         // specified that the bitmap filter can cope with that.
00657         FilterFlags Flags = pFilter->GetFlags();
00658         if (pTypeOfFilter==CC_RUNTIME_CLASS(BitmapFilter) && pFilter->IsKindOf(pTypeOfFilter))
00659         {
00660             BaseBitmapFilter* pBitmapFilter = (BaseBitmapFilter*)pFilter;
00661             if (pBitmapFilter->IsThisBppOk(Bpp))
00662             {
00663                 // Webster - RanbirR - 25\02\97  
00664                 // If this is a single bitmap and the the Bpp is 24, 
00665                 // then we do not want to dipsplay *.gif in the export filter List.
00666                 // Only allow the format for Animated GIF's (even though they do not 
00667                 // support 24 colour bitmaps.) We later convert to an 8 Bpp. 
00668                 // This fixes an animated GIF export bug in Camelot.
00669                 // At present we error if the first bitmap in our animated gif is 24Bpp.
00670                 if (pFilter->FilterID ==  FILTERID_TI_GIF && Bpp == 24 && BitmapCount == 1)
00671                     FilterCanCope = FALSE;
00672                 else
00673                     FilterCanCope = TRUE;
00674             }
00675             else
00676                 FilterCanCope = FALSE;
00677 
00678             if (BitmapCount>1 && !Flags.CanExportMultipleImages)
00679                 FilterCanCope = FALSE;
00680         }
00681         else
00682             FilterCanCope = TRUE;
00683 
00684         if( NULL != pFilter->pOILFilter )
00685         {
00686             if (
00687                 ( ( GetImport && Flags.CanImport && !IS_A( pFilter, CamelotEPSFilter ) )
00688                     || (!GetImport && Flags.CanExport)) &&
00689                     Flags.ShowFilter && (pFilter->IsKindOf(pTypeOfFilter)) && FilterCanCope
00690                )
00691             {
00692                 // Add this filter into the list
00693                 if (Position != 0)
00694                     camStrcat(FilterString, _T("|"));
00695                 camStrcat(FilterString, pFilter->pOILFilter->ConstructFilterString(BitmapCount));
00696                 pFilter->pOILFilter->Position = Position;
00697 
00698                 // Is this the filter we used last?
00699                 if ((*SelectedFilter == -1) && (pFilter->FilterID == SelectedFilterID))
00700                     // Yes - remember this.
00701                     *SelectedFilter = Position;
00702 
00703                 Position++;
00704             }
00705             else
00706                 // Make sure we don't try this one later
00707                 pFilter->pOILFilter->Position = -1;
00708         }
00709         
00710         // Try the next filter
00711         pFilter = Filter::GetNext(pFilter);
00712     }
00713 
00714     // All ok
00715     return FilterString;
00716 }
00717 
00718 
00719 /********************************************************************************************
00720 
00721 >   virtual INT32 BaseFileDialog::GetSelectedFilterIndex()
00722 
00723     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00724     Created:    4/1/96
00725     Returns:    The index of the selected filter
00726     Purpose:    Allows access in a kernelly fashion to the selected filter index on
00727                 the common file dialog box.
00728 
00729 ********************************************************************************************/
00730 
00731 INT32 BaseFileDialog::GetSelectedFilterIndex()
00732 {
00733     return GetFilterIndex();
00734 }
00735 
00736 /********************************************************************************************
00737 
00738 >   virtual INT32 BaseFileDialog::SetSelectedFilterIndex(INT32 NewIndex)
00739 
00740     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00741     Created:    4/1/96
00742     Returns:    TRUE if it worked, FALSE if not
00743     Purpose:    Set the desired index for the filter that is going to be selected on the 
00744                 Common file dialog box.
00745 
00746 ********************************************************************************************/
00747 
00748 INT32 BaseFileDialog::SetSelectedFilterIndex(INT32 NewIndex)
00749 {
00750     INT32 Old = GetFilterIndex();
00751     SetFilterIndex( NewIndex );
00752     TRACEUSER( "Neville", _T("SetSelectedFilterIndex - new %d (old = %d)\n"), NewIndex, Old);
00753     return Old;
00754 }
00755 
00756 /********************************************************************************************
00757 
00758 >   virtual BOOL BaseFileDialog::SetTitle(INT32 TitleId)
00759 
00760     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00761     Created:    4/1/96
00762     Returns:    TRUE if it worked, FALSE if not
00763     Purpose:    Allows the title of the common file dialog box to be set up 
00764 
00765 ********************************************************************************************/
00766 
00767 BOOL BaseFileDialog::SetTitle(INT32 TitleId) 
00768 {
00769     if (SmartLoadString(0, TitleId, Title, 128))
00770         SetName( Title );
00771     
00772     return TRUE;
00773 }
00774 
00775 
00776 /********************************************************************************************
00777 
00778 >   virtual BOOL BaseFileDialog::SetInitialDirectory(const String_256& pDir)
00779 
00780     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00781     Created:    4/1/96
00782     Inputs:     pDir    String containing the pathname to use
00783     Returns:    TRUE if it worked, FALSE if not
00784     Purpose:    Sets the directory which the common file dialog box will open looking at.
00785 
00786 ********************************************************************************************/
00787 
00788 BOOL BaseFileDialog::SetInitialDirectory(const String_256& strDir)
00789 {
00790     SetDirectory( PCTSTR(strDir) );
00791     
00792     return TRUE;
00793 }
00794 
00795 /********************************************************************************************
00796 
00797 >   virtual BOOL BaseFileDialog::SetDefaultFileName(const String_256& Name)
00798 
00799     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00800     Created:    4/1/96
00801     Inputs:     Name    name of the file to be used by default
00802     Returns:    TRUE if it worked, FALSE if not
00803     Purpose:    Sets the name and length of the name of the default file to be used in the 
00804                 common file dialog box
00805 
00806 ********************************************************************************************/
00807 
00808 BOOL BaseFileDialog::SetDefaultFileName(String_256& Name)
00809 {
00810     SetFilename( PCTSTR(Name) );
00811         
00812     return TRUE;
00813 }
00814 
00815 /********************************************************************************************
00816 
00817 >   virtual BOOL BaseFileDialog::GetChosenFileName(PathName * pName)
00818 
00819     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00820     Created:    4/1/96
00821     Outputs:    The pathname that the user chose.
00822     Returns:    TRUE if it worked and patname is valid, FALSE if not
00823     Purpose:    Gets the pathname of the file that was chosen by the user. It will return
00824                 the vailidity of the pathname to the caller. Should be valid as the file
00825                 dialog box should filter out problem pathnames.
00826 
00827 ********************************************************************************************/
00828 
00829 BOOL BaseFileDialog::GetChosenFileName(PathName * pName)
00830 {
00831     TRACEUSER( "luke", _T("FileName is %s\n"), GetPath().c_str() );
00832 
00833     pName->SetPathName( GetPath() );
00834     return pName->IsValid();
00835 }
00836 
00837 /********************************************************************************************
00838 
00839 >   virtual Filter * BaseFileDialog::GetSelectedExportFilter()
00840 
00841     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00842     Created:    4/1/96
00843     Returns:    TRUE if it worked, FALSE if not
00844     Purpose:    
00845 
00846 ********************************************************************************************/
00847 
00848 Filter * BaseFileDialog::GetSelectedExportFilter(INT32 TheSelectedFilter)
00849 {
00850     // Find the filter that the user has chosen
00851     Filter *pFilter = Filter::GetFirst();
00852     while (pFilter != NULL)
00853     {
00854         if ((pFilter->GetFlags().CanExport) && 
00855             (pFilter->pOILFilter->Position == TheSelectedFilter))
00856             // This is the filter!
00857             break;
00858 
00859         // Try the next filter
00860         pFilter = Filter::GetNext(pFilter);
00861     }
00862 
00863     return pFilter;
00864 }
00865 
00866 /********************************************************************************************
00867 
00868 >   void BaseFileDialog::SetSelectedExportFilter(UINT32 uiFilterID)
00869 
00870     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00871     Created:    3/7/97
00872     Returns:    -
00873     Purpose:    Sets the selected export filter to the ID given
00874 
00875 ********************************************************************************************/
00876 
00877 void BaseFileDialog::SetSelectedExportFilter(UINT32 uiFilterID)
00878 {
00879     //Search through the filters until we find the one we want
00880     Filter* pFilter = Filter::GetFirst();
00881     while (pFilter != NULL)
00882     {
00883         if (pFilter->FilterID == uiFilterID)
00884         {
00885             //We've found it
00886             //So set this as the selected filter
00887             SetSelectedFilterIndex( pFilter->pOILFilter->Position );
00888             return;
00889         }
00890         pFilter = Filter::GetNext(pFilter);
00891     }
00892 
00893     ERROR3("BaseFileDialog::SetSelectedExportFilter - couldn't find the Filter ID");
00894 }
00895 
00896 
00897 /********************************************************************************************
00898 
00899 >   virtual BOOL BaseFileDialog::OpenAndGetFileName()
00900 
00901     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00902     Created:    4/1/96
00903     Returns:    True if the user pressed ok on the dialog box, False otherwise
00904     Purpose:    Opens the common file dialog box up, waits for the user to gives us the
00905                 filename that they wish to use and either press ok or cancel. 
00906 
00907 ********************************************************************************************/
00908 
00909 BOOL BaseFileDialog::OpenAndGetFileName()
00910 {
00911 PORTNOTE("other", "Removed ControlHelper usage" )
00912 #if !defined(EXCLUDE_FROM_XARALX)
00913     // Keep Control Helper system informed
00914     ControlHelper::InformModalDialogOpened();
00915 #endif
00916     
00917     // 'Do' the dialog
00918     INT32 DlgResult = ShowModal();
00919 
00920 PORTNOTE("other", "Removed ControlHelper usage" )
00921 #if !defined(EXCLUDE_FROM_XARALX)
00922     // Keep Control Helper system informed
00923     ControlHelper::InformModalDialogClosed();
00924 #endif
00925     
00926     return (DlgResult == wxID_OK);
00927 }
00928 
00929 /********************************************************************************************
00930 
00931 >   BOOL BaseFileDialog::IsValidFilename()
00932 
00933     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00934     Created:    31/10/95
00935     Returns:    TRUE if the current filename is Acceptable, FALSE if not
00936     Purpose:    Makes sure that the filename picked is actually OK. If there is another
00937                 file of the same name, it checks to see if the user wants to replace it.
00938                 Moved from SaveFileDialog 9/1/96
00939 ********************************************************************************************/
00940 
00941 BOOL BaseFileDialog::IsValidFilename()
00942 {
00943     // Get the pathname
00944     wxString FullPath = GetFilename();
00945     AppendExtension(&FullPath);
00946 
00947     // Webster - RanbirR 17/02/97
00948     // Save the file name with our Filter extension, for use in our Message Box.
00949 #ifdef WEBSTER
00950     wxString FileName(FullPath);
00951 #endif //webster
00952 
00953     // if doesn't exist then thats fine
00954     if( wxFile::Exists( FullPath ) )
00955     {
00956         //  WEBSTER-ranbirr-27/03/97
00957         // Remove the extension from the file. Webster - RanbirR 11\02\97.
00958     #ifdef WEBSTER
00959         RemoveFileExtension(&FileName);
00960     #endif //webster
00961         return TRUE;
00962     }
00963 
00964     // Added for Webster - Ranbir 11\02\97  
00965     // Removes the exstion from a file name.
00966 #ifdef WEBSTER
00967     RemoveFileExtension(&FileName);
00968 #endif //webster
00969 
00970     // Get the filename into a Path object
00971 #ifndef WEBSTER
00972     String_256 KernelFilename(FullPath);
00973     PathName FileMessage(KernelFilename);
00974     KernelFilename =  FileMessage.GetTruncatedPath(50);
00975 #endif //webster
00976     
00977     // Webster - RanbirR 17/02/97 
00978     // Use "FileName", since it contains the Filter extension.
00979 #ifdef WEBSTER
00980     String_256 KernelFilename(FileName);
00981     PathName FileMessage(KernelFilename);
00982     KernelFilename =  FileMessage.GetTruncatedPath(50);
00983 #endif //webster
00984 
00985     const TCHAR* Name;
00986     Name = (TCHAR*)KernelFilename;
00987 
00988     String_256 strPrompt( _R(IDM_OVERWRITE) );
00989 
00990     // fill in the %s field with the filename
00991     TCHAR ErrorMsg[256];
00992     camSnprintf( ErrorMsg, sizeof(ErrorMsg) / sizeof(ErrorMsg[0]), strPrompt, 
00993         (const TCHAR*)Name );
00994     Error::SetError( 0, ErrorMsg, 0 );
00995     SetNextMsgHelpContext(_R(IDM_OVERWRITE));
00996 
00997     // then ask the user
00998     ErrorInfo Info;
00999     Info.Button[0] = _R(IDB_OVERWRITE);
01000     Info.Button[1] = _R(IDS_CANCEL);
01001     
01002     // This makes the cancel button the default one in this situation
01003     // as defaulting to replace is bad.
01004     Info.OK = Info.Cancel = 2;
01005 
01006     UINT32  idResult = AskQuestion( &Info );
01007 
01008     // if they cancel, then the name is not acceptable to them
01009     if( _R(IDS_CANCEL) == idResult )
01010         return FALSE;
01011 
01012     // user was quite keen on the replace file idea.
01013     // delete the file we're replacing so rampant filters don't get upset
01014     // Removed 2/1/96 as the export filters should be using the new DeleteExportFile function
01015     // Problems with this approach as if the exporter pops up an expotr options dialog box then
01016     // most people would expect a cancel on this not to vape the file.
01017     //_unlink(FullPath);
01018 
01019     return TRUE;
01020 }
01021 
01022 /********************************************************************************************
01023 
01024 >   void BaseFileDialog::AppendExtension(wxString* pFilename)
01025 
01026     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01027     Created:    9/1/96
01028     Inputs:     pFilename - the filename to append an extension to
01029     Outputs:    pFilename - the input filename with the .art extension on the end (if needed)
01030     Purpose:    Given a filename, this function should attach the appropriate file extension
01031                 to the to it. This baseclass version does nothing
01032 
01033 ********************************************************************************************/
01034 
01035 void BaseFileDialog::AppendExtension(wxString* pFilename)
01036 {
01037     // baseclass version so do nothing
01038 }
01039 
01040 /********************************************************************************************
01041 
01042 >   void BaseFileDialog::RemoveFileExtension(wxString* pFilename)
01043 
01044     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
01045     Created:    11/02/97
01046     Inputs:     pName - The filename from which the extension will be removed.
01047     Outputs:    pName - The input filename with the extension removed.
01048     
01049 ********************************************************************************************/
01050 //  WEBSTER-ranbirr-27/03/97
01051 #ifdef WEBSTER
01052 BOOL  BaseFileDialog::RemoveFileExtension(wxString* pName)
01053 {
01054     // Is this a valid file name
01055     if ((pName == NULL) || (pName->IsEmpty()))
01056         return FALSE;
01057 
01058     // Does the filename have an extension? 
01059     INT32 i = pName->GetLength() - 1;
01060     INT32 ExtensionLen = 0;
01061 
01062     // look for the dot char.
01063     while ((i >= 0) && (pName->GetAt(i) != '.'))
01064     {
01065         i--;
01066         ExtensionLen++;
01067     }
01068     
01069     // Is it a valid extension?
01070     if (ExtensionLen <= 3 && ExtensionLen > 0 && i > 0)
01071     {
01072         // Remove the extension.
01073         *pName = pName->Left(i);
01074         return TRUE;
01075     }
01076     else
01077         return FALSE;
01078 }
01079 #endif //webster
01080 
01081 
01082 /********************************************************************************************
01083 ***     New help button handling code
01084 ********************************************************************************************/
01085 
01086 /********************************************************************************************
01087 
01088 >   afx_msg void BaseFileDialog::OnHelp()
01089 
01090     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01091     Created:    30/7/96
01092     Returns:    -
01093     Purpose:    Handle the clicks on the help button.
01094                 This is the Windows 95 UI form of the function.
01095 
01096 ********************************************************************************************/
01097 
01098 PORTNOTE("other", "Removed MFC type Hooks" )
01099 #if !defined(EXCLUDE_FROM_XARALX)
01100 afx_msg void BaseFileDialog::OnHelp()
01101 {
01102     // Run the help engine for this dialog and don't bother processing this message
01103     // any further, we've done it.
01104     HelpUser(*this);
01105     return;
01106 }
01107 
01108 /********************************************************************************************
01109 ***     Preview bitmap handling code
01110 ********************************************************************************************/
01111 
01112 /********************************************************************************************
01113 
01114 >   afx_msg void BaseFileDialog::OnShowPreviewBitmap()
01115 
01116     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01117     Created:    18/7/96
01118     Returns:    -
01119     Purpose:    Handle the clicks on the buttons which offer the show preview bitmap.
01120                 This is the Windows 95 UI form of the function.
01121 
01122 ********************************************************************************************/
01123 
01124 afx_msg void BaseFileDialog::OnShowPreviewBitmap()
01125 {
01126     if (!CCamApp::IsNewWindowsUI())
01127         return;
01128 
01129     // Do exactly the same as the file name change code does
01130     OnFileNameChange();
01131 }
01132 
01133 /********************************************************************************************
01134 
01135 >   afx_msg void BaseFileDialog::OnOptions()
01136 
01137     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01138     Created:    24/1/97
01139     Returns:    -
01140     Purpose:    Implements the options button installed for WEBSTER
01141                 Base class does nowt
01142 
01143 ********************************************************************************************/
01144 
01145 afx_msg void BaseFileDialog::OnOptions()
01146 {
01147     // WEBSTER - markn 28/1/97
01148     HandleOptions();
01149 }
01150 
01151 /********************************************************************************************
01152 
01153 >   virtual BOOL BaseFileDialog::HandleOptions()
01154 
01155     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01156     Created:    24/1/97
01157     Returns:    -
01158     Purpose:    Implements the options button installed for WEBSTER
01159                 Base class does nowt
01160 
01161 ********************************************************************************************/
01162 
01163 BOOL BaseFileDialog::HandleOptions()
01164 {
01165     return TRUE;
01166 }
01167 
01168 /********************************************************************************************
01169 
01170 >   void BaseFileDialog::OnFileNameChange()
01171 
01172     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01173     Created:    17/7/96
01174     Returns:    -
01175     Purpose:    Should be called when the user has selected a new file in the file list.
01176                 We might need to do things like remove the preview bitmap from the file
01177                 and display it.
01178                 Only called back if OFN_EXPLORER is set and you can only do this on Windows 95
01179                 otherwise a dialog is not popped up.
01180 
01181     SeeAlso:    BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
01182     SeeAlso:    ExportFileDialog::OnLBSelChangedNotify;
01183 
01184 ********************************************************************************************/
01185 
01186 void BaseFileDialog::OnFileNameChange()
01187 {
01188 #if _MFC_VER >= 0x400
01189     // Remove code completely if using less than MFC4.0 as calls like SetControlText
01190     // will not be present and this function will not work
01191     // Just in case Windows NT 3 decides to call this we'd better stop it as otherwise things
01192     // will be happening more than they should. This is the method used on Windows 95 or NT 4.
01193     if (!CCamApp::IsNewWindowsUI())
01194         return;
01195 
01196     // Graeme (1/12/00) - We need to update ShowPreviewBitmap here. This updates the registry
01197     // settings, and enables the dialogue to remember the show preview bitmap settings. The
01198     // single equals sign is intentional, as I want to perform an assignment, rather than an
01199     // equality operation.
01200     if ( ShowPreviewBitmap = IsDlgButtonChecked ( _R(IDC_SHOWPREVIEW) ) )
01201     {
01202         // Get the filename which the user has entered in the field.
01203         wxString FileName = GetFileName();
01204 
01205         // Added by Craig Hamilton 20/9/00.
01206         // This fixes the problem where a user drags a file over folders within the import
01207         // dialog causing the preview to be redone. If the previously selected file is the
01208         // same as the current then there is no need to regenerate a new preview.
01209         wxString pathName = GetPathName();
01210         if(m_previousPathName != pathName)
01211         {
01212             // Reinitialise. This is the only place this happens.
01213             m_previousPathName = pathName;
01214 
01215             // If its empty then return immediately
01216             if (FileName.IsEmpty())
01217                 return;
01218 
01219             PathName Path(FileName.GetBuffer(256));
01220             FileName.ReleaseBuffer();
01221             if (!Path.IsValid())
01222             {
01223                 // There was a problem e.g. user has typed f:
01224                 // Magically a bad pathname sets an error so clear it!
01225                 Error::ClearError();
01226                 return;
01227             }
01228 
01229             BOOL Previous = (pBitmapToUse != NULL);
01230 
01231             BOOL ok = GetPreviewBitmapFromFile(&Path);
01232 
01233             BOOL Now = (pBitmapToUse != NULL);
01234             
01235             // If we have changed state or read a new preview bitmap ok then force a redraw
01236             if ((!Previous && Now) || (Previous && !Now) || ok)
01237             {
01238                 // Force a redraw of the preview bitmap icon, as we have changed state
01239                 wxWindow* Icon = FindWindow( _R(IDC_PREVIEW));
01240                 ::InvalidateRect(Icon, NULL, TRUE);
01241             }
01242         }
01243         // End added.
01244     }
01245     else
01246     {
01247         // Delete the present bitmap so we show nothing
01248         if (pBitmapToUse != NULL)
01249         {
01250             delete pBitmapToUse;
01251             pBitmapToUse = NULL;
01252 
01253             // Force a redraw of the preview bitmap icon, as we have changed state
01254             wxWindow* Icon = FindWindow( _R(IDC_PREVIEW));
01255             ::InvalidateRect(Icon, NULL, TRUE);
01256         }
01257     }
01258 
01259 #endif
01260     return;
01261 }
01262 
01263 /********************************************************************************************
01264 
01265 >   BOOL BaseFileDialog::GetPreviewBitmapFromFile(PathName * pPath)
01266 
01267     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01268     Created:    18/7/96
01269     Returns:    -
01270     Purpose:    Rips a preview bitmap from the specified file, if appropriate. The class
01271                 variable pBitmapToUse will contain the bitmap or will contain NULL if no
01272                 bitmap is found.
01273     SeeAlso:    OpenFileDialog::OnFileNameChange;
01274 
01275 ********************************************************************************************/
01276 
01277 BOOL BaseFileDialog::GetPreviewBitmapFromFile(PathName * pPath)
01278 {
01279     CCDiskFile      File        ( 1024, FALSE, TRUE );
01280     String_256      Type        ( pPath->GetType() );
01281     KernelBitmap    *pThumbnail = NULL;
01282     BOOL            ReadOK      = FALSE;
01283 
01284     // If there is a preview bitmap in use, delete it first.
01285     if ( pBitmapToUse != NULL )
01286     {
01287         delete pBitmapToUse;
01288         pBitmapToUse = NULL;
01289     }
01290 
01291     // Get lowercase filetype
01292     Type.toLower();
01293 
01294     // Bodge to speed galleries up for art files - doesn't check or use external previews
01295     if ((Type.Sub((String_8)"cdr") != -1) ||
01296         (Type.Sub((String_8)"cmx") != -1) )
01297     {
01298         // Use the RIFF file import code.
01299         ReadOK = ReadRIFFPreview ( File, pPath );
01300     }
01301 
01302     // Read in a native file.
01303     else if ( !Type.Sub ( ( String_8 ) "art" ) ||
01304               !Type.Sub ( ( String_8 ) "xar" ) ||
01305               !Type.Sub ( ( String_8 ) "cxn" ) ||
01306               !Type.Sub ( ( String_8 ) "cxw" ) ||
01307               !Type.Sub ( ( String_8 ) "web" ) )
01308     {
01309         // Use the native file format import code.
01310         ReadOK = ReadNativePreview ( File, pPath );
01311     }
01312 
01313     // Try a PNG.
01314     else if ( !Type.Sub ( ( String_8 ) "png" ) )
01315     {
01316         // Use the PNG import code to load the bitmap up.
01317         ReadOK = ReadBitmapPreview ( File, pPath, FILTERID_PREVIEW_PNG );
01318     }
01319 
01320     // Try a BMP.
01321     else if ( !Type.Sub ( ( String_8 ) "bmp" ) )
01322     {
01323         // Use the BMP import code to load the bitmap up.
01324         ReadOK = ReadBitmapPreview ( File, pPath, FILTERID_PREVIEW_BMP );
01325     }
01326 
01327     // Try a GIF.
01328     else if ( !Type.Sub ( ( String_8 ) "gif" ) )
01329     {
01330         // Use the GIF import code to load the bitmap up.
01331         ReadOK = ReadBitmapPreview ( File, pPath, FILTERID_PREVIEW_GIF );
01332     }
01333 
01334     // Try a JPEG.
01335     else if ( !Type.Sub ( ( String_8 ) "jpg" ) || !Type.Sub ( ( String_8 ) "jpeg" ) )
01336     {
01337         // Use the JPEG import code to load the bitmap up.
01338         ReadOK = ReadBitmapPreview ( File, pPath, FILTERID_IMPORT_JPEG );
01339     }
01340 
01341     // Try a TIFF.
01342     else if ( !Type.Sub ( ( String_8 ) "tif" ) || !Type.Sub ( ( String_8 ) "tiff" ) )
01343     {
01344         // Use the JPEG import code to load the bitmap up.
01345         ReadOK = ReadBitmapPreview ( File, pPath, FILTERID_PREVIEW_TIFF );
01346     }
01347 
01348     // Clear any errors we encountered
01349     Error::ClearError();    
01350 
01351     return ReadOK;
01352 }
01353 
01354 /********************************************************************************************
01355 
01356 >   BOOL BaseFileDialog::OpenFileForPreview ( CCDiskFile    &File,
01357                                               PathName      *pPath )
01358 
01359     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
01360     Created:    16/5/00
01361     Inputs:     &File   - The file containing the preview bitmap.
01362                 pPath   - The pathname of the file.
01363     Returns:    TRUE    - The file was opened OK.
01364                 FALSE   - An error occured.
01365     Purpose:    Sets the file up so that the preview image can be read.
01366 
01367 ********************************************************************************************/
01368 
01369 BOOL BaseFileDialog::OpenFileForPreview ( CCDiskFile    &File,
01370                                           PathName      *pPath )
01371 {
01372     // Don't error, just set exceptions...
01373     BOOL Found = FALSE;
01374 
01375     // Open file and check if it exists at the same time
01376     TRY
01377     {
01378         Found = File.open(*pPath, ios::in | ios::binary | ios::nocreate);
01379     }       
01380     CATCH( CFileException, e)
01381     {
01382         Found = FALSE;
01383         Error::ClearError();
01384     }
01385     END_CATCH
01386 
01387     return Found;
01388 }
01389 
01390 /********************************************************************************************
01391 
01392 >   BOOL BaseFileDialog::ReadRIFFPreview ( CCDiskFile   &File,
01393                                            PathName     *pPath )
01394 
01395     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
01396     Created:    16/5/00
01397     Inputs:     &File       - The file containing the preview bitmap.
01398                 *pPath      - The pathname giving the location of the file.
01399     Returns:    TRUE        - The preview bitmap was created successfully.
01400                 FALSE       - An error occurred.
01401     Purpose:    Reads in the RIFF chunk containing the preview.
01402 
01403 ********************************************************************************************/
01404 
01405 BOOL BaseFileDialog::ReadRIFFPreview ( CCDiskFile   &File,
01406                                        PathName     *pPath )
01407 {
01408     // Set up the return variable.
01409     BOOL Result = FALSE;
01410     
01411     // Attempt to open the file, and read in the preview from the CMX or CDR file.
01412     if ( OpenFileForPreview ( File, pPath ) &&
01413          AccusoftFilters::GetVersionNumber() > 0 &&
01414          CMXImportFilter::SkipToPreviewBitmap ( &File ) )
01415     {
01416         WinBitmap *pThumbnail = new WinBitmap;
01417 
01418         // Attempt to read in the bitmap.
01419         if ( !AccusoftFilters::ReadFromFile ( &File, &pThumbnail->BMInfo,
01420                                               &pThumbnail->BMBytes, TRUE, NULL,
01421                                               NULL, TRUE ) )
01422         {
01423             // It failed to load, so clean up the bitmap.
01424             delete pThumbnail;
01425             pThumbnail = NULL;
01426         }
01427 
01428         // Create a kernel bitmap.
01429         else if ( pThumbnail != NULL &&
01430                   ( pBitmapToUse = new KernelBitmap ( pThumbnail, TRUE ) ) != NULL )
01431         {
01432             // It worked.
01433             Result = TRUE;
01434         }
01435     }
01436 
01437     // Return whether it worked or not.
01438     return Result;
01439 }
01440 
01441 /********************************************************************************************
01442 
01443 >   BOOL BaseFileDialog::ReadNativePreview ( CCDiskFile &File,
01444                                              PathName   *pPath )
01445 
01446     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
01447     Created:    16/5/00
01448     Inputs:     &File       - The file containing the preview bitmap.
01449                 *pPath      - The pathname giving the location of the file.
01450     Returns:    TRUE        - The preview bitmap was created successfully.
01451                 FALSE       - An error occurred.
01452     Purpose:    Reads in the native file chunk containing the preview.
01453 
01454 ********************************************************************************************/
01455 
01456 BOOL BaseFileDialog::ReadNativePreview ( CCDiskFile &File,
01457                                          PathName   *pPath )
01458 {
01459     // Now that we have had the decision to make .cxns become .xars, we must check to see if
01460     // its a new native file before just doing a straight Accusoft read. This will have the
01461     // added side effect of ensuring Accusoft do not see the native format files, without
01462     // our helping hand as to where they can look. Otherwise, they are likely to access
01463     // violate.
01464     BOOL    Result      = FALSE;
01465     BOOL    IsNewFormat = FALSE;
01466     UINT32  FilterId    = FILTERID_NONE;
01467 
01468     // Try to open the file up to get the preview image first!
01469     if ( !OpenFileForPreview ( File, pPath ) )
01470     {
01471         return FALSE;
01472     }
01473 
01474     // In the process it will position the file at the start of the preview bitmap image
01475     // and get the image type
01476     // Use the special version of the function to read in bitmap which uses the present
01477     // file offset as the place that the image is stored.
01478     if ( BaseCamelotFilter::SkipToPreviewBitmap ( &File, &IsNewFormat, &FilterId ) &&
01479          ( FilterId != FILTERID_NONE ) )
01480     {
01481         // Load in the bitmap starting from the present point in the file       
01482         Filter* pFilter = Filter::GetFirst();
01483 
01484         while ((pFilter != NULL) && (pFilter->FilterID != FilterId))
01485         {
01486             // Try the next filter
01487             pFilter = Filter::GetNext(pFilter);
01488         }
01489 
01490         if ( pFilter != NULL )
01491         {
01492             // Ensure that it's a bitmap filter.
01493             ERROR3IF ( !pFilter->IS_KIND_OF ( BaseBitmapFilter ),
01494                         "Preview filter is not a BaseBitmapFilter\n" );
01495 
01496             // It's necessary to cast the filter to be a base bitmap filter, so
01497             // that the bitmap loading code is exposed.
01498             BaseBitmapFilter *pBMPFilter = static_cast<BaseBitmapFilter*> ( pFilter );
01499 
01500             // Attempt to read the preview in from the file.
01501             if ( pBMPFilter->ImportBitmap ( &File, &pBitmapToUse ) )
01502             {
01503                 // It worked!
01504                 Result = TRUE;
01505             }
01506             else
01507             {
01508                 // Import failed! Delete the bitmap.
01509                 delete pBitmapToUse;
01510                 pBitmapToUse = NULL;
01511             }
01512 
01513             // I need to manually shutdown the loading bar.
01514             EndSlowJob ();
01515         }
01516     }
01517 
01518     // Try to use another method.
01519     else if ( !IsNewFormat && AccusoftFilters::GetVersionNumber() > 0 )
01520     {
01521         // Old format had a preview as the first thing in the file so
01522         // Just do a straight load from the start of the file
01523         // But only if not a new format file as otherwise Accusoft does its usual lets load
01524         // something spappy.
01525 
01526         // Create a new bitmap record.
01527         WinBitmap *pBMP = new WinBitmap;
01528         
01529         // Read in and create the new bitmap.
01530         if ( pBMP != NULL && 
01531              AccusoftFilters::ReadFromFile ( &File, &pBMP->BMInfo, &pBMP->BMBytes, TRUE ) &&
01532              ( pBitmapToUse = new KernelBitmap ( pBMP, TRUE ) ) != NULL )
01533         {
01534             // It worked!
01535             Result = TRUE;
01536         }
01537 
01538         // The bitmap wasn't loaded.
01539         else
01540         {
01541             // Import failed! Delete the bitmap.
01542             delete pBMP;
01543         }
01544     }
01545 
01546     // Return a pointer to the bitmap loaded from the file.
01547     return Result;
01548 }
01549 
01550 /********************************************************************************************
01551 
01552 >   BOOL BaseFileDialog::ReadBitmapPreview ( CCDiskFile &File,
01553                                              PathName   *pPath,
01554                                              UINT32     FilterID )
01555 
01556     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
01557     Created:    16/5/00
01558     Inputs:     &File       - The file containing the preview bitmap.
01559                 pPath       - The pathname of the file.
01560                 FilterID    - The filter to use.
01561     Returns:    TRUE        - The preview bitmap was created successfully.
01562                 FALSE       - An error occurred.
01563     Purpose:    Creates a preview image from the contents of a bitmap file.
01564 
01565 ********************************************************************************************/
01566 
01567 BOOL BaseFileDialog::ReadBitmapPreview ( CCDiskFile &File,
01568                                          PathName   *pPath,
01569                                          UINT32     FilterID )
01570 {
01571     // Set up the default return value.
01572     BOOL Result = FALSE;
01573 
01574     // Try to open the file.
01575     if ( OpenFileForPreview ( File, pPath ) )
01576     {
01577         // Find the first filter in the filter list.
01578         Filter* pFilter = Filter::GetFirst ();
01579 
01580         // Scan through the list of filters until the correct one is found.
01581         while ( ( pFilter != NULL ) && ( pFilter->FilterID != FilterID ) )
01582         {
01583             // Try the next filter
01584             pFilter = Filter::GetNext ( pFilter );
01585         }
01586 
01587         // If a filter has been found, load up its contents. The IS_KIND_OF is a sanity
01588         // check to ensure that the SetPreviewBitmap isn't called on (e.g.) a vector
01589         // filter.
01590         if ( pFilter != NULL && pFilter->IS_KIND_OF ( BaseBitmapFilter ) )
01591         {
01592             // It's necessary to cast the filter to be a base bitmap filter, so
01593             // that the bitmap loading code is exposed.
01594             BaseBitmapFilter *pBMPFilter = static_cast<BaseBitmapFilter*> ( pFilter );
01595 
01596             // Tell the filter that it *IS* a preview bitmap.
01597             pBMPFilter->SetPreviewBitmap ( TRUE );
01598 
01599             // Attempt to read the preview in from the file.
01600             if ( pBMPFilter->ImportBitmap ( &File, &pBitmapToUse ) )
01601             {
01602                 // It didn't work.
01603                 Result = TRUE;
01604             }
01605 
01606             // Something went wrong with the input, so clean up the bitmap.
01607             else
01608             {
01609                 // Delete the bitmap.
01610                 delete pBitmapToUse;
01611                 pBitmapToUse = NULL;
01612             }
01613 
01614             // I need to manually shutdown the loading bar.
01615             EndSlowJob ();
01616         }
01617     }
01618 
01619     // Return to the main loop.
01620     return Result;
01621 }
01622 
01623 /********************************************************************************************
01624 
01625 >   afx_msg LRESULT BaseFileDialog::OnRedrawMessage(WPARAM wParam, LPARAM lParam)
01626 
01627     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
01628     Created:    16/3/95
01629     Inputs:     wParam - The Windows wParam parameter
01630                 lParam - The Windows lParam parameter
01631     Returns:    TRUE
01632     Purpose:    Handles the Redraw control wanting to be drawn. This control is used to
01633                 display the Preview bitmaps from selected files in the file list. When
01634                 we get this message we will need to go and find the bitmap from the
01635                 file and display it. The message is sent up by one of our cc_DialogRedraw
01636                 custom controls.
01637 
01638 ********************************************************************************************/
01639 
01640 afx_msg LRESULT BaseFileDialog::OnRedrawMessage(WPARAM wParam, LPARAM lParam)
01641 {
01642 //  TRACEUSER( "Neville", _T("Draw the Blank version of the control now, as we don't have a filename\n"));
01643 
01644     // Do nothing if not an explorer type dialog box
01645     if (!CCamApp::IsNewWindowsUI())
01646         return TRUE;
01647 
01648     // Find out about the paint message and fill in the details in the kernel message
01649     RedrawInfo* pInfo = (RedrawInfo*) lParam;
01650     ReDrawInfoType ExtraInfo;
01651 
01652     ExtraInfo.pMousePos = NULL;     // No mouse position info for redraw events
01653     
01654     // Build a CC dc out of it for rendering to the screen
01655     // Get a MFC CDC to put the DC in
01656     CCDC MyDc(RENDERTYPE_SCREEN);
01657     MyDc.Attach(pInfo->PaintInfo.hdc);
01658     ExtraInfo.pDC = &MyDc;
01659 
01660     // The devices DPI
01661     ExtraInfo.Dpi = MyDc.GetDeviceCaps(LOGPIXELSY);
01662     
01663     // How big the window is
01664     RECT WindowSize;
01665     if (::GetClientRect((wxWindow*)wParam, &WindowSize))
01666     {
01667         ExtraInfo.dx = (((INT32)WindowSize.right)*72000) / ExtraInfo.Dpi;
01668         ExtraInfo.dy = (((INT32)WindowSize.bottom)*72000) / ExtraInfo.Dpi;
01669     }
01670 
01671     // Work out the size of the invalidated region
01672     RECT* ClipRect = &pInfo->PaintInfo.rcPaint;
01673     DocRect DocClipRect;
01674 
01675     // Convert to millipoints, Also need to flip the y coords to get a
01676     // rectangle in with the origin in the bottom left.
01677     DocClipRect.lo.x = (ClipRect->left * 72000) / ExtraInfo.Dpi;
01678     DocClipRect.lo.y = ExtraInfo.dy - ((ClipRect->bottom * 72000) / ExtraInfo.Dpi);
01679 
01680     DocClipRect.hi.x = (ClipRect->right * 72000) / ExtraInfo.Dpi;
01681     DocClipRect.hi.y = ExtraInfo.dy - ((ClipRect->top * 72000) / ExtraInfo.Dpi);
01682 
01683     // Set the pointer in the extra info structure
01684     ExtraInfo.pClipRect = &DocClipRect;
01685 
01686     // Go get a render region
01687     DocRect VirtualSize(0, 0, ExtraInfo.dx, ExtraInfo.dy);
01688     RenderRegion* pRender = CreateOSRenderRegion(&VirtualSize, &ExtraInfo);
01689     if (pRender!=NULL)
01690     {
01691         // Code stolen from ColourEditDlg::RenderControl
01692         DialogColourInfo RedrawColours;     // Get a supplier for default dlg colours
01693         INT32 PixelSize = 72000 / ExtraInfo.Dpi;        // Size of output pixel in millipoints
01694 
01695         // Render the attributes and then a rectangle
01696         pRender->SaveContext();
01697 
01698         // pBitmapToUse stores the preview bitmap of the current file
01699         if (pBitmapToUse)
01700         {
01701             // bring the left hand edge in one pixel.
01702             VirtualSize.lox += PixelSize;
01703 
01704             // Using this method we don't get flicker on the backdrop as we draw the background rectangle
01705             // followed by the white new background
01706             // Draw single pixel black line left and top and single pixel background colour 1 pixel in
01707             pRender->SetLineWidth(0);
01708             pRender->SetFillColour(RedrawColours.DialogBack());
01709             pRender->SetLineColour(COLOUR_BLACK); //RedrawColours.ButtonShadow());
01710             pRender->DrawLine(DocCoord(VirtualSize.lo.x, VirtualSize.hi.y), VirtualSize.hi);    // Top Left to Top Right
01711             pRender->DrawLine(DocCoord(VirtualSize.lo.x, VirtualSize.hi.y), VirtualSize.lo);    // Top Left to Bottom Left
01712             pRender->SetLineColour(RedrawColours.DialogBack());
01713             pRender->DrawLine(DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.hi.y - PixelSize),
01714                               DocCoord(VirtualSize.hi.x, VirtualSize.hi.y - PixelSize));        // Top Left to Top Right
01715             pRender->DrawLine(DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.lo.y),
01716                               DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.hi.y - PixelSize)); // Bottom Left to Top Left
01717 
01718             // Draw single pixel highlight line right and bottom and single pixel background colour 1 pixel in
01719             pRender->SetLineColour(RedrawColours.ButtonHighlight());
01720             pRender->DrawLine(DocCoord(VirtualSize.hi.x, VirtualSize.hi.y - PixelSize),
01721                               DocCoord(VirtualSize.hi.x, VirtualSize.lo.y));
01722             pRender->DrawLine(DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.lo.y + PixelSize),
01723                               DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.lo.y + PixelSize));
01724 
01725             pRender->SetLineColour(RedrawColours.DialogBack());
01726             pRender->DrawLine(DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.hi.y - PixelSize),
01727                               DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.lo.y + 2 * PixelSize));
01728             pRender->DrawLine(DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.lo.y + 2 * PixelSize),
01729                               DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.lo.y + 2 * PixelSize));
01730             
01731             // put the left hand edge back again
01732             VirtualSize.lox -= PixelSize;
01733 
01734             // And deflate the rect by 2 pixels
01735             VirtualSize.Inflate(-PixelSize * 2);
01736 
01737             // Code stolen from BfxDlg::RenderBitmap
01738             pRender->SetLineColour(COLOUR_TRANS);
01739 
01740             // Draw a rectangle to fill in the background - Fill with Dialogue Background colour
01741             pRender->SetFillColour(COLOUR_WHITE);
01742             pRender->DrawRect(&VirtualSize);
01743 
01744             NodeBitmap NB;
01745             NodeBitmap * pNodeBitmap = &NB;
01746         
01747             if (!((pNodeBitmap == NULL) || (!pNodeBitmap->SetUpPath(12,12))))
01748             {
01749                 // Get a new bitmap object for this node.
01750                 pNodeBitmap->GetBitmapRef()->SetBitmap(pBitmapToUse);
01751                         
01752                 ENSURE(pNodeBitmap->GetBitmap()->ActualBitmap != NULL, "No bitmap object found!");
01753         
01754                 DocRect BitmapSize(VirtualSize);
01755                 BitmapInfo BMInfo;
01756                 pBitmapToUse->ActualBitmap->GetInfo(&BMInfo);
01757                 if (BMInfo.PixelWidth==0) BMInfo.PixelWidth=1;
01758                 if (BMInfo.PixelHeight==0) BMInfo.PixelHeight=1;
01759 
01760                 double BMAspect = ((double)(BMInfo.PixelWidth))/((double)(BMInfo.PixelHeight));
01761                 double RedrawAspect = ((double)(ExtraInfo.dx))/((double)(ExtraInfo.dy));
01762 
01763                 if (BMAspect>RedrawAspect)
01764                 {
01765                     // background colour at top and bottom
01766                     INT32 NewHeight = (INT32)( 0.5 + ((double)(VirtualSize.Width()))/BMAspect);
01767                     if (NewHeight<1) NewHeight = 1;
01768                     BitmapSize.loy = (VirtualSize.hiy + VirtualSize.loy - NewHeight) / 2;
01769                     BitmapSize.hiy = BitmapSize.loy + NewHeight;
01770                 }
01771                 else
01772                 {
01773                     // background colour on left and right
01774                     INT32 NewWidth = (INT32)( 0.5 + ((double)(VirtualSize.Height()))*BMAspect);
01775                     if (NewWidth<1) NewWidth = 1;
01776                     BitmapSize.lox = (VirtualSize.hix + VirtualSize.lox - NewWidth) / 2;
01777                     BitmapSize.hix = BitmapSize.lox + NewWidth;
01778                 }
01779 
01780                 // And set this in our bitmap node
01781                 pNodeBitmap->CreateShape(BitmapSize);
01782 
01783                 QualityAttribute* pQualAttr = new QualityAttribute;
01784                 if (pQualAttr != NULL)
01785                 {
01786                     // If all that worked then turn on anti-aliasing when drawing the bitmap in preview.
01787                     pQualAttr->QualityValue = Quality::QualityMax;
01788                     pRender->SetQuality(pQualAttr, TRUE);
01789                 }
01790 
01791                 pNodeBitmap->Render(pRender);
01792             }
01793         }
01794         else
01795         {
01796             // make the right hand side out of the box so that the right black line does not show
01797             VirtualSize.hix += PixelSize;
01798 
01799             // Draw a backgound making sure we blat anything previously there wiht the dialog
01800             // background colour
01801             pRender->SetLineWidth(0);
01802             pRender->SetFillColour(RedrawColours.DialogBack());
01803             pRender->SetLineColour(COLOUR_BLACK); //RedrawColours.ButtonShadow());
01804             pRender->DrawRect(&VirtualSize);
01805             pRender->DrawLine(DocCoord(VirtualSize.lo.x, VirtualSize.hi.y), VirtualSize.hi);
01806 
01807             pRender->SetLineWidth(0);
01808             pRender->SetLineColour(RedrawColours.ButtonHighlight());
01809             pRender->DrawLine(DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.hi.y - PixelSize), DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.lo.y));
01810             pRender->DrawLine(DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.lo.y + PixelSize), DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.lo.y + PixelSize)); // Bottom Right to Bottom Left
01811 
01812             // bring the right hand side back in
01813             VirtualSize.hix -= PixelSize;
01814             // bring the bottom up
01815             VirtualSize.loy += PixelSize;
01816 
01817             // Draw the no bitmap present cross i.e. vertical
01818             // And Deflate the rect by 1 pixels so we draw to the outer lines
01819             VirtualSize.Inflate(-PixelSize);
01820             INT32 Width = VirtualSize.Width();
01821             INT32 Height = VirtualSize.Height();
01822             pRender->SetLineWidth(0);
01823             pRender->SetLineColour(COLOUR_BLACK);
01824             pRender->DrawLine(DocCoord(VirtualSize.lo.x + Width/2, VirtualSize.lo.y),
01825                               DocCoord(VirtualSize.lo.x + Width/2, VirtualSize.hi.y));
01826             pRender->DrawLine(DocCoord(VirtualSize.lo.x, VirtualSize.lo.y + Height/2),
01827                               DocCoord(VirtualSize.hi.x, VirtualSize.lo.y + Height/2));
01828         }
01829 
01830         pRender->RestoreContext();
01831 
01832         // Get rid of the render region
01833         DestroyOSRenderRegion(pRender);
01834     }
01835 
01836     // Give back the dc
01837     MyDc.Detach();
01838 
01839     return TRUE;
01840 }
01841 /********************************************************************************************
01842 
01843 >   BOOL BaseFileDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
01844 
01845     Author:     Alex
01846     Created:    06/11/2003
01847     Inputs:     wParam - The Windows wParam parameter
01848                 lParam - The Windows lParam parameter
01849     Returns:    TRUE
01850     Purpose:    Used to copy the OPENFILNAMEEX values into the
01851                 standard OPENFILENAME member variable. This is
01852                 to support XP-style common file dialogs - the
01853                 places bar on the left hand side of the dialog.
01854 
01855 ********************************************************************************************/
01856 
01857 #ifdef XPDialog
01858 BOOL BaseFileDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
01859 {
01860     memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn));
01861     m_ofn.lStructSize = sizeof(m_ofn);
01862 
01863     return CFileDialog::OnNotify(wParam, lParam, pResult);
01864 }
01865 #endif
01866 
01867 /********************************************************************************************
01868 
01869 >   INT32 BaseFileDialog::DoModal()
01870 
01871     Author:     Alex
01872     Created:    06/11/2003
01873     Inputs:     
01874     Returns:    
01875     Purpose:    Overrides the CFileDialog::DoModal() method
01876                 so that XP-style common file dialogs can be
01877                 supported.
01878                 Used to copy the OPENFILNAMEEX values into the
01879                 standard OPENFILENAME member variable. This is
01880                 to support XP-style common file dialogs - the
01881                 places bar on the left hand side of the dialog.
01882 
01883 ********************************************************************************************/
01884 
01885 #ifdef XPDialog
01886 INT32 BaseFileDialog::DoModal()
01887 {
01888     ASSERT_VALID(this);
01889     ASSERT(m_ofn.Flags & OFN_ENABLEHOOK);
01890     ASSERT(m_ofn.lpfnHook != NULL); // can still be a user hook
01891 
01892     // XP-style dialogs:
01893 //  m_ofn.Flags &= ~OFN_ENABLEHOOK;
01894     
01895     // zero out the file buffer for consistent parsing later
01896     ASSERT(AfxIsValidAddress(m_ofn.lpstrFile, m_ofn.nMaxFile));
01897     DWORD nOffset = camStrlen(m_ofn.lpstrFile)+1;
01898     ASSERT(nOffset <= m_ofn.nMaxFile);
01899     memset(m_ofn.lpstrFile+nOffset, 0, (m_ofn.nMaxFile-nOffset)*sizeof(TCHAR));
01900 
01901     // WINBUG: This is a special case for the file open/save dialog,
01902     //  which sometimes pumps while it is coming up but before it has
01903     //  disabled the main window.
01904     wxWindow* hWndFocus = ::GetFocus();
01905     BOOL bEnableParent = FALSE;
01906     m_ofn.hwndOwner = PreModal();
01907     AfxUnhookWindowCreate();
01908     if (m_ofn.hwndOwner != NULL && ::IsWindowEnabled(m_ofn.hwndOwner))
01909     {
01910         bEnableParent = TRUE;
01911         ::EnableWindow(m_ofn.hwndOwner, FALSE);
01912     }
01913 
01914     _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
01915     ASSERT(pThreadState->m_pAlternateWndInit == NULL);
01916 
01917     if (m_ofn.Flags & OFN_EXPLORER)
01918         pThreadState->m_pAlternateWndInit = this;
01919     else
01920         AfxHookWindowCreate(this);
01921 
01922     // TO ALLOW XP-style:
01923 //#ifdef XPDialog
01924     memset(&m_ofnEx, 0, sizeof(m_ofnEx));
01925     memcpy(&m_ofnEx, &m_ofn, sizeof(m_ofn));
01926     DWORD dwWinMajor = (DWORD)(LOBYTE(LOWORD(::GetVersion())));
01927     if ((BYTE)dwWinMajor >= 5)
01928        m_ofnEx.lStructSize = sizeof(m_ofnEx);
01929     // ENDS
01930 
01931     INT32 nResult;
01932     if (m_bOpenFileDialog)
01933         nResult = ::GetOpenFileName((OPENFILENAME*)&m_ofnEx);   // changed to ofnEx
01934     else
01935         nResult = ::GetSaveFileName((OPENFILENAME*)&m_ofnEx);   // changed to ofnEx
01936 
01937     // MORE
01938     memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn));
01939     m_ofn.lStructSize = sizeof(m_ofn);
01940     // ENDS
01941 /*#else
01942     INT32 nResult;
01943     if (m_bOpenFileDialog)
01944         nResult = ::GetOpenFileName(&m_ofn);
01945     else
01946         nResult = ::GetSaveFileName(&m_ofn);
01947 #endif*/
01948 
01949     if (nResult)
01950         ASSERT(pThreadState->m_pAlternateWndInit == NULL);
01951     pThreadState->m_pAlternateWndInit = NULL;
01952 
01953     // WINBUG: Second part of special case for file open/save dialog.
01954     if (bEnableParent)
01955 //#ifdef XPDialog
01956         ::EnableWindow(m_ofnEx.hwndOwner, TRUE);    // changed to ofnEx
01957 /*#else
01958         ::EnableWindow(m_ofn.hwndOwner, TRUE);
01959 #endif*/
01960     if (::IsWindow(hWndFocus))
01961         ::SetFocus(hWndFocus);
01962 
01963     PostModal();
01964     return nResult ? nResult : IDCANCEL;
01965 }
01966 #endif
01967 
01968 
01969 /****************************************************************************
01970 
01971 >   void BaseFileDialog::OnSize(UINT32 nType, INT32 cx, INT32 cy)
01972 
01973     Author:     Alex
01974     Created:    12/02/2004
01975 
01976     Inputs:     nType       - 
01977                 cx          - 
01978                 cy          - 
01979     Purpose:    
01980 
01981 ****************************************************************************/
01982 
01983 void BaseFileDialog::OnSize(UINT32 nType, INT32 cx, INT32 cy)
01984 {
01985     wxFileDialog::OnSize(nType, cx, cy);
01986     
01987     // move the darn Help button!!
01988     CWnd *wndPreview = GetDlgItem(_R(IDC_PREVIEW));
01989     CWnd *wndHelpButton = GetDlgItem(_R(ID_CC_HELP_BUTTON));
01990     CWnd *wndDlg = GetParent();
01991     CWnd *wndCancelButton = wndDlg->GetDlgItem(IDCANCEL);
01992     if(wndPreview && wndHelpButton)
01993     {
01994         wxRect rPreview, rCancel, rHelp;
01995         wndCancelButton->GetWindowRect(&rCancel);
01996         ScreenToClient(&rCancel);
01997         wndPreview->GetWindowRect(&rPreview);
01998         ScreenToClient(&rPreview);
01999         wndHelpButton->GetWindowRect(&rHelp);
02000         ScreenToClient(&rHelp);
02001 
02002         wndHelpButton->SetWindowPos(NULL, rPreview.left, rCancel.top, 0, 0, SWP_NOSIZE);    // SWP_NOSIZE to keep the current button size
02003     }
02004 
02005 }
02006 
02007 
02008 /****************************************************************************
02009 
02010 >   void BaseFileDialog::OnPaletteChanged(wxWindow* pWindow)
02011 
02012     Author:     Alex
02013     Creation:   03/03/2004
02014     Purpose:    update colours in file dialogs when the palette changes
02015 
02016 ****************************************************************************/
02017 
02018 void BaseFileDialog::OnPaletteChanged(wxWindow* pFocusWnd)
02019 {
02020     if (pFocusWnd != this)
02021     {
02022         // Select in our palette, in the background
02023         CPalette* pMainPal = PaletteManager::GetPalette();
02024         HPALETTE hMainPal = HPALETTE(pMainPal);
02025 
02026         HDC hDC = ::GetDC(m_hWnd);
02027         HPALETTE OldPal = ::SelectPalette(hDC, hMainPal, TRUE);
02028         UINT32 NumColoursChanged = ::RealizePalette(hDC);
02029         
02030         // If colours have changed, redraw the entire window
02031 //      if (NumColoursChanged > 0)
02032             // For some reason, NumColoursChanged was always 0 in my testing.
02033             // I don't think it's a problem to redraw whenever this method
02034             // is called. But just do it when in 256 colour mode
02035             INT32 ScreenDepth = GetDeviceCaps(hDC, BITSPIXEL);
02036             if(ScreenDepth <= 8)
02037                 InvalidateRect(0);
02038 
02039         // And select the previous DC palette into the DC
02040         ::SelectPalette(hDC, OldPal, TRUE);
02041         ::RealizePalette(hDC);
02042         ::ReleaseDC(m_hWnd, hDC);
02043     }
02044 }
02045 
02046 /****************************************************************************
02047 
02048 >   void BaseFileDialog::OnFolderChange()
02049 
02050     Author:     Marc_Power (Xara Group Ltd) <camelotdev@xara.com>
02051     Creation:   25/01/2005
02052     Purpose:    Read preference and apply thumbnail mode if required.
02053 
02054 ****************************************************************************/
02055 void BaseFileDialog::OnFolderChange()
02056 {
02057     if(ThumbNailMode)
02058     {
02059         wxWindow* view = FindWindowEx(GetParent()->m_hWnd, 0, "SHELLDLL_DefView", 0);
02060         ::SendMessage(view, WM_COMMAND, FCIDM_SHVIEW_THUMBNAIL, 0);
02061     }
02062 }
02063 #endif
02064 
02065 /********************************************************************************************
02066 
02067 >   RenderRegion* CreateOSRenderRegion(DocRect* pRequiredSize,
02068                                        ReDrawInfoType* ExtraInfo,
02069                                        BOOL UseSelViewColContext = FALSE)
02070 
02071     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> (Copied from Rik/Jason code in DialogOp::CreateGRenderRegion)
02072     Created:    17/7/96
02073     
02074     Inputs:     pRequiredSize - The size that you want the effective area of the window to
02075                 be. Measured in Millipoints. eg. If you want your control to appear to be
02076                 1 inch square (whatever the actual size of it is), pass in a DocRect that
02077                 looks a bit like this ... DocRect(0,0,72000,72000)
02078                 ExtraInfo - The info about the region, as supplied by the dialog manager
02079     Returns:    Render Region. This returns a pointer to a render region, or NULL if it
02080                 failed to create one.
02081 
02082     Purpose:    Simplifies the creation of a render region as used in a dialog box. It
02083                 will create a render region, scaled to the correct size etc and deal with
02084                 all the Creation, initialisation etc of the region. StartRender is also
02085                 called, so if this function does not return NULL you are able to start
02086                 drawing into it. You MUST call DestroyOSRenderRegion when you have draw
02087                 everything that you need to as this calls StopRender (which does the blit
02088                 to the screen) as well as deleting the render region for you
02089 
02090     Scope:      Global
02091 
02092     Notes:      Use GRenderRegions when you want fast redraw, grad fills, and transparency.
02093                 If only simple rendering is required, think about perhaps using an
02094                 OSRenderRegion instead.
02095 
02096     SeeAlso:    DialogOp::DestroyOSRenderRegion
02097     SeeAlso:    DialogOp::CreateGRenderRegion
02098 
02099 ********************************************************************************************/
02100 
02101 RenderRegion* CreateOSRenderRegion(DocRect* pRequiredSize, ReDrawInfoType* ExtraInfo,
02102                                    BOOL UseSelViewColContext)
02103 {
02104     // Make a new dialog view
02105     DialogView *pDialogView = new DialogView;
02106     if (pDialogView == NULL)
02107         // Error - return failure.
02108         return NULL;
02109 
02110     // Initialise the DialogView
02111     if (!pDialogView->Init())
02112     {
02113         // Error - return failure.
02114         delete pDialogView;
02115         return NULL;
02116     }
02117 
02118     // Pixelise the rectangle
02119     pRequiredSize->lo.Pixelise(pDialogView);
02120     pRequiredSize->hi.Pixelise(pDialogView);
02121     DocRect ClipRect = *pRequiredSize;
02122 
02123     // Get some default params for the render region
02124     FIXED16 Scale(1);
02125 
02126     // Ok, go and scale things
02127     INT32 ReqDx = ClipRect.Width();
02128     INT32 ReqDy = ClipRect.Height();
02129 
02130     // Work out the scale factors
02131     FIXED16 XScale = FIXED16(double(ExtraInfo->dx) / double(ReqDx));
02132     FIXED16 YScale = FIXED16(double(ExtraInfo->dy) / double(ReqDy));
02133 
02134     // Build the matricies
02135     // One to shift everything to the correct side of the X axis
02136     Matrix Translate(0, -ExtraInfo->dy);
02137 
02138     // One to scale everything into the window
02139     Matrix ScaleIt(XScale, YScale);
02140 
02141     // One to translate everything to the origin
02142     Matrix ToOrigin(-ClipRect.lo.x, -ClipRect.lo.y);
02143 
02144     // Combine them all
02145     ToOrigin *= ScaleIt;
02146     ToOrigin *= Translate;
02147 
02148     // If the caller wants to use the same colour separation options (ColourPlate) as the
02149     // currently selected view, then copy the ColourPlate across to the new DialogView
02150     if (UseSelViewColContext && DocView::GetSelected() != NULL)
02151         pDialogView->SetColourPlate(DocView::GetSelected()->GetColourPlate());
02152 
02153     // Make a render region for the screen, asking specifically for an OSRenderRegion,
02154     // and none of this sneaky & cunning diverting it back into being a GRenderRegion!
02155 //  RenderRegion* pRender = OSRenderRegion::Create(ClipRect, ToOrigin, Scale,
02156 //                                                  RENDERTYPE_SCREEN, NULL, TRUE);
02157     RenderRegion* pRender = OSRenderRegion::Create(ClipRect, ToOrigin, Scale,
02158                                                     RENDERTYPE_SCREEN, NULL, FALSE, TRUE);
02159     // Penultimate param FALSE so that a GDRAW render region is used...
02160     // Last param TRUE so that the render bitmap is forced into 32BPP mode
02161     // (this fixes problems with palettes when drawing the preview in 256 colour mode)
02162 
02163     if (pRender != NULL)
02164     {
02165         // Try and create the bitmap etc
02166         if (pRender->AttachDevice(pDialogView, ExtraInfo->pDC, NULL))
02167         {
02168             // Try and start the render region
02169             if (pRender->StartRender())
02170             {
02171                 return pRender;
02172             }
02173         }
02174 
02175         // Failed to attach and start the render region so free up the region
02176         delete pRender;
02177     }
02178 
02179     // Something went wrong, fail
02180     delete pDialogView;
02181     return NULL;
02182 }
02183 
02184 
02185 /********************************************************************************************
02186 
02187 >   BOOL DestroyGRenderRegion(RenderRegion* pRender)
02188 
02189     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> (Copied from Rik/Jason code in DialogOp::CreateGRenderRegion)
02190     Created:    17/7/96
02191 
02192     Inputs:     A pointer to a render region return by CreateOSRenderRegion
02193     Returns:    TRUE if it worked, FALSE if the render region passed in was bad
02194 
02195     Purpose:    Deinitialises the render region and deletes it.
02196 
02197     Scope:      Global
02198 
02199     Errors:     ERROR2 error if pRender is NULL
02200 
02201     SeeAlso:    DialogOp::CreateGRenderRegion
02202     SeeAlso:    DialogOp::CreateOSRenderRegion
02203 
02204 ********************************************************************************************/
02205 
02206 BOOL DestroyOSRenderRegion(RenderRegion* pRender)
02207 {
02208     // Test for preconditions
02209     ERROR2IF(pRender==NULL, FALSE, "DestroyOSRenderRegion was passed a NULL render region");
02210 
02211     // Blit to the screen
02212     pRender->StopRender();
02213 
02214     // and delete the render region and its (dialog) view
02215     // these are deleted in this order because the RenderRegion destructor may
02216     // call functions on its RenderView
02217     View* pView = pRender->GetRenderView();
02218     delete pRender;
02219     delete pView;
02220 
02221     // It worked
02222     return TRUE;
02223 }
02224 
02225 
02226 /********************************************************************************************
02227 ****    End of BaseFileDialog class                                                     *****
02228 ********************************************************************************************/
02229 
02230 
02231 
02232 /********************************************************************************************
02233 
02234 >   OpenFileDialog::OpenFileDialog(LPCTSTR FilterString)
02235 
02236     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02237     Created:    26/1/95
02238     Purpose:    Constructs a Open File Dialog. It sets the File Must Exist and Hide Read Only
02239                 Flags. Call PrepareDialog() then DoModal() to use.
02240 
02241 ********************************************************************************************/
02242 
02243 OpenFileDialog::OpenFileDialog(LPCTSTR FilterString)
02244   : BaseFileDialog( TRUE, wxFILE_MUST_EXIST, FilterString )
02245 {
02246     // Set some defaults
02247     NativeFilterPos = 0;
02248 
02249 PORTNOTE("other", "Deactivate template usage" )
02250 #if !defined(EXCLUDE_FROM_XARALX)
02251     if (CCamApp::IsNewWindowsUI())
02252     {
02253         // Use our template to do the ammendment and addition of controls to the dialog box
02254         m_ofn.lpTemplateName = MAKEINTRESOURCE(_R(IDD_PREVIEWBITMAP));
02255     }
02256     else
02257         m_ofn.lpTemplateName = NULL;
02258 #endif
02259     
02260     // Set the preview bitmap to be NULL
02261     pBitmapToUse = NULL;
02262 }
02263 
02264 /********************************************************************************************
02265 
02266 >   BOOL OpenFileDialog::OnInitDialog()
02267 
02268     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02269     Created:    25/1/95
02270     Returns:    TRUE => normal window focus is required.
02271     Purpose:    Changes a few bits and bobs about in the Save Dialog
02272     SeeAlso:    SaveFileDialog
02273 
02274 ********************************************************************************************/
02275 
02276 void OpenFileDialog::OnInitDialog( wxInitDialogEvent& event )
02277 {
02278     // Set up the string we require
02279     String_256 NewText(_R(IDS_OPENBUTTON));
02280     const TCHAR* NewTextStr = NewText;
02281 
02282     // Get the handle of the ok button.
02283     wxWindow* OkButton = FindWindow( wxID_OK );
02284 
02285     // Now replace the 'ok' by 'Save' and return
02286     OkButton->SetLabel( NewTextStr );
02287 
02288 PORTNOTE("other", "Remove code to make filter combo-deeper" )
02289 #if !defined(EXCLUDE_FROM_XARALX)
02290     // Get the handle of the filter list box.
02291     wxWindow* ComboBox = FindWindow( cmb1 );
02292 
02293     // Find out where the list box is.
02294     WINDOWPLACEMENT Placement;
02295     Placement.length = sizeof(WINDOWPLACEMENT);
02296     ::GetWindowPlacement(ComboBox, &Placement);
02297 
02298     // Make the list box deeper than usual
02299     ::MoveWindow(ComboBox,
02300                  Placement.rcNormalPosition.left,
02301                  Placement.rcNormalPosition.top,
02302                  Placement.rcNormalPosition.right - Placement.rcNormalPosition.left,
02303                  (Placement.rcNormalPosition.bottom - Placement.rcNormalPosition.top) * 5,
02304                  TRUE);
02305 #endif
02306     
02307     // Let the base class do its thang . . .
02308     return BaseFileDialog::OnInitDialog( event );
02309 }
02310 
02311 /********************************************************************************************
02312 
02313 >   virtual BOOL OpenFileDialog::ExplorerInitDialog(wxWindow* hDlg)
02314 
02315     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02316     Created:    17/7/96
02317     Returns:    TRUE if it worked, FALSE if it failed
02318     Purpose:    Should be called when the explorer style dialog boxes need setting up.
02319                 We can take this opportunity to add in any extra controls that we require.
02320     SeeAlso:    BaseFileDialog::ExplorerInitDialog; BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
02321 
02322 ********************************************************************************************/
02323 
02324 BOOL OpenFileDialog::ExplorerInitDialog(wxWindow* hDlg)
02325 {
02326 PORTNOTE("other", "Remove MFC code" )
02327 #if !defined(EXCLUDE_FROM_XARALX)
02328     // Do nothing of not on explorer type dialog boxes
02329     if (!CCamApp::IsNewWindowsUI())
02330         return TRUE;
02331 
02332 
02333     // Set up and initialise the new buttons and controls
02334 
02335     // Give it the correct state according to the preference.
02336     wxCheckBox* pCheck = (wxCheckBox*)FindWindow( _R(IDC_SHOWPREVIEW));
02337     pCheck->SetValue( BaseFileDialog::ShowPreviewBitmap != FALSE );
02338 
02339     wxWindow*   Icon = FindWindow( _R(IDC_PREVIEW));
02340     Icon->EnableWindow(TRUE);
02341 
02342     // WEBSTER - markn 28/1/97
02343     Icon = FindWindow( _R(IDC_FILEDLG_OPTIONS));
02344     Icon->Show( false );
02345 
02346     //Graham 27/10/97: And the "use as default" button
02347     Icon = FindWindow( _R(IDC_USEASDEFAULT));
02348     Icon->ShowWindow( false );
02349     
02350     // Move the Preview box down a little, so that it lines up with the top of the List box
02351     wxWindow*   wndDlg = GetParent();
02352     wxWindow*   pWndPreview = FindWindow( _R(IDC_PREVIEW) );
02353     wxRect      rPreview, rList;
02354     pWndPreview->GetWindowRect(&rPreview);
02355     ScreenToClient(rPreview);
02356     wxWindow*   pWndList = wndDlg->GetDlgItem(lst1);    // lst1 is the ID for the main list box
02357     pWndList->GetWindowRect(&rList);
02358     ScreenToClient(rList);
02359     pWndPreview->SetWindowPos(NULL, rPreview.GetLeft(), rList.GetTop(), 
02360         rPreview.GetWidth(), rPreview.GetHeight(), 0);
02361 
02362     ExplorerInited = TRUE;
02363 #endif
02364 
02365     return TRUE;
02366 }
02367 
02368 
02369 /********************************************************************************************
02370 
02371 >   BOOL OpenFileDialog::PrepareDialog()
02372 
02373     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02374     Created:    26/1/95
02375     Returns:    TRUE if it worked, FALSE if not
02376     Purpose:    Does anything the dialogs want doing after they have been created, but before
02377                 they are displayed
02378 
02379 ********************************************************************************************/
02380 
02381 BOOL OpenFileDialog::PrepareDialog()
02382 {
02383     // Set the dialogs Title
02384     if (SmartLoadString(0, _R(IDS_OPENTITLE), Title, 128))
02385         wxFileDialog::SetTitle( Title );
02386 
02387     // Select the desired path
02388     if (DefaultOpenFilePath.Length() <= 0)
02389         DefaultOpenFilePath = wxStandardPaths::Get().GetUserConfigDir();
02390 
02391     SetDirectory( DefaultOpenFilePath );
02392 
02393     // Choose the initial filter
02394     SetFilterIndex( SelectedFilter );
02395 
02396     // See if the base class wants to do anything
02397     return BaseFileDialog::PrepareDialog();
02398 }
02399 
02400 /********************************************************************************************
02401 
02402 >   void OpenFileDialog::SetDefaultPath(const String_256& NewPath)
02403 
02404     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02405     Created:    26/1/95
02406     Inputs:     NewPath - The path to use as the default
02407     Purpose:    Sets the default path. The next open dialog will default to this path
02408 
02409 ********************************************************************************************/
02410 
02411 void OpenFileDialog::SetDefaultPath(const String_256& NewPath)
02412 {
02413     // Set the default path
02414     DefaultOpenFilePath = NewPath;
02415 }
02416 
02417 /********************************************************************************************
02418 
02419 >   virtual void OpenFileDialog::DoDataExchange(CDataExchange* pDX)
02420 
02421     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02422     Created:    18/7/96
02423     Inputs:     (a standard MFC object)
02424     Purpose:    Maintains the state of the "Show preview bitmap" check-box in the open file dialog.
02425 
02426 ********************************************************************************************/
02427 
02428 PORTNOTE("other", "Removed MFC junk" )
02429 #if !defined(EXCLUDE_FROM_XARALX)
02430 void OpenFileDialog::DoDataExchange(CDataExchange* pDX)
02431 {
02432     BaseFileDialog::DoDataExchange(pDX);
02433     //{{AFX_DATA_MAP(CMyDialog)
02434     if (CCamApp::IsNewWindowsUI())
02435     {
02436         DDX_Check(pDX, _R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap);
02437     }
02438     //}}AFX_DATA_MAP
02439 }
02440 #endif
02441 
02442 
02443 /********************************************************************************************
02444 
02445 >   char* OpenFileDialog::BuildFilterString(INT32* NativeFilterPos)
02446 
02447     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02448     Created:    26/1/95
02449     Outputs:    NativeFilterPos - The position in the list of the native filter
02450     Returns:    NULL if there was not enough memory, or a pointer to a CCMalloced bit
02451                 of memory with a string in it in the form that dialogs like
02452     Purpose:    Builds the string that is passed to the dialog that lists all the file
02453                 types.
02454 
02455 ********************************************************************************************/
02456 
02457 TCHAR* OpenFileDialog::BuildFilterString(INT32* NativeFilterPos)
02458 {
02459     // Find out how much space is needed
02460     UINT32 FilterSize = 0;
02461     *NativeFilterPos = 0;
02462 
02463     // Used to load in the resource strings for the filter extension descriptions.
02464     String_256 FilterExtensions;
02465 
02466     Filter *pFilter = Filter::GetFirst();
02467     while (pFilter != NULL)
02468     {
02469         FilterFlags Flags = pFilter->GetFlags();
02470 
02471         // little bit of a bodge here to stop the CamelotEPSFilter from appearing in the
02472         // import list - you can't hide it from just one list. It must be availiable though
02473         // to give it's nice little error message. Other instances of this below.
02474         if (Flags.CanImport && Flags.ShowFilter && !IS_A(pFilter, CamelotEPSFilter))
02475         {
02476             // Add the space required to put this into the filter string
02477             // (add 1 for the separating '|' character)
02478             FilterSize += camStrlen(pFilter->pOILFilter->ConstructFilterString()) + 1;
02479         }
02480 
02481         // Try the next filter
02482         pFilter = Filter::GetNext(pFilter);
02483     }
02484 
02485     // Add two for the final "|" and the 0 terminator.
02486     FilterSize += 2;
02487 
02488     // Try to get this string
02489     TCHAR*  FilterString = (TCHAR*)CCMalloc( FilterSize * sizeof(TCHAR) );
02490     if (FilterString==NULL)
02491         // Error state already set by CCMalloc
02492         return NULL;
02493 
02494     // Construct the string, and set up the position numbers for the filters.
02495     UINT32 Position = 0;
02496     FilterString[0] = 0;
02497     pFilter = Filter::GetFirst();
02498 
02499     while (pFilter != NULL)
02500     {
02501         FilterFlags Flags = pFilter->GetFlags();
02502 
02503         if (Flags.CanImport && Flags.ShowFilter && !IS_A(pFilter, CamelotEPSFilter))
02504         {
02505             // Add this filter into the list
02506             camStrcat(FilterString, pFilter->pOILFilter->ConstructFilterString());
02507             camStrcat(FilterString, _T("|"));
02508             pFilter->pOILFilter->Position = Position;
02509 
02510             // see if it is the native filter
02511             if (IS_A(pFilter, CamelotNativeEPSFilter))
02512             {
02513                 *NativeFilterPos = Position;
02514             }
02515 
02516             // increment
02517             Position++;
02518         }
02519         else
02520             // Make sure we don't try this one later
02521             pFilter->pOILFilter->Position = -1;
02522 
02523         // Try the next filter
02524         pFilter = Filter::GetNext(pFilter);
02525     }
02526 
02527     // Terminate the string
02528     camStrcat(FilterString, _T("|"));
02529 
02530     // All ok
02531     return FilterString;
02532 }
02533 
02534 
02535 
02536 /********************************************************************************************
02537 
02538 >   SaveFileDialog::SaveFileDialog(LPCTSTR FilterString, String_256 DefaultPath,
02539                     String_256 DefaultName)
02540 
02541     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02542     Created:    26/1/95
02543     Inputs:     FilterString - The string of available filters
02544                 DefPath - The Default Path for the file
02545                 DefName - The Default FileName for the file
02546     Purpose:    Constructs a Save File Dialog. It sets the File Must Exist and Hide Read Only
02547                 Flags. Call PrepareDialog() then DoModal() to use.
02548 
02549 ********************************************************************************************/
02550 
02551 SaveFileDialog::SaveFileDialog(LPCTSTR FilterString, const String_256& DefPath, const String_256& DefName)
02552   : BaseFileDialog( FALSE, wxFILE_MUST_EXIST, FilterString )
02553 //  : BaseFileDialog(FALSE, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FilterString)
02554 {
02555     // Make a note of this lot
02556     DefaultName = DefName;
02557     DefaultPath = DefPath;
02558     DocName = DefName;
02559 
02560 PORTNOTE("other", "Removed OFN_OVERWRITEPROMPT - not sure if needed" )
02561 #if !defined(EXCLUDE_FROM_XARALX)
02562     // Under Windows 95 the OnFileNameOK system does not work, so use the default one
02563     // Disable for VC4.0/MFC 4.0 as they have fixed it.
02564 #if _MFC_VER < 0x400
02565     if (IsWin32c())
02566         m_ofn.Flags |= OFN_OVERWRITEPROMPT;
02567 #endif
02568 #endif
02569 }
02570 
02571 
02572 /********************************************************************************************
02573 
02574 >   SaveFileDialog::SaveFileDialog(LPCTSTR FilterString, String_256& DefPath,
02575                                     String_256& DefName, String_256& DocumentName)
02576 
02577     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02578     Created:    26/1/95
02579     Inputs:     FilterString - The string of available filters
02580                 DefPath - The Default Path for the file
02581                 DefName - The Default FileName for the file
02582                 DocumentName - The name of the document to put in the dialog title
02583     Purpose:    Constructs a Save File Dialog. It sets the File Must Exist and Hide Read Only
02584                 Flags. Call PrepareDialog() then DoModal() to use.
02585 
02586 ********************************************************************************************/
02587 
02588 SaveFileDialog::SaveFileDialog(LPCTSTR FilterString, const String_256& DefPath, const String_256& DefName,
02589     const String_256& DocumentName)
02590 PORTNOTE("other", "Disabled template stuff" )
02591 //  : BaseFileDialog( FALSE, ((CCamApp::IsNewWindowsUI()) ? OFN_ENABLETEMPLATE : 0) | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FilterString)
02592     : BaseFileDialog( FALSE, wxFILE_MUST_EXIST, FilterString )
02593 {
02594     // Make a note of this lot
02595     DefaultName = DefName;
02596     DefaultPath = DefPath;
02597     DocName = DocumentName;
02598 
02599 PORTNOTE("other", "Disabled template stuff" )
02600 #if !defined(EXCLUDE_FROM_XARALX)
02601     if (CCamApp::IsNewWindowsUI())
02602     {
02603         // Use our template to do the ammendment and addition of controls to the dialog box
02604         m_ofn.lpTemplateName = MAKEINTRESOURCE(_R(IDD_PREVIEWBITMAP));
02605     }
02606     else
02607         m_ofn.lpTemplateName = NULL;
02608 #endif
02609     
02610     // Set the preview bitmap to be NULL
02611     pBitmapToUse = NULL;
02612 }
02613 
02614 
02615 /********************************************************************************************
02616 
02617 >   BOOL SaveFileDialog::OnInitDialog()
02618 
02619     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02620     Created:    25/1/95
02621     Returns:    TRUE => normal window focus is required.
02622     Purpose:    Changes a few bits and bobs about in the Save Dialog
02623     SeeAlso:    SaveFileDialog
02624 
02625 ********************************************************************************************/
02626 
02627 BOOL SaveFileDialog::OnInitDialog()
02628 {
02629     // Set up the string we require
02630     String_256      NewText(_R(IDS_SAVEBUTTON));
02631     const TCHAR*    NewTextStr = NewText;
02632 
02633     // Get the handle of the ok button.
02634     wxButton*       OkButton = (wxButton*)FindWindow( wxID_OK );
02635 
02636     // Now replace the 'ok' by 'Save' and return
02637     OkButton->SetLabel( NewTextStr );
02638 
02639 PORTNOTE( "other", "Remove code to add compression check" )
02640 #if !defined(EXCLUDE_FROM_XARALX) && defined(_DEBUG)
02641     // Move the bottom of the dialog down...
02642     WINDOWPLACEMENT Placement;
02643     Placement.length = sizeof(Placement);
02644     ::GetWindowPlacement(GetSafeHwnd(), &Placement);
02645     INT32 Height = Placement.rcNormalPosition.bottom - Placement.rcNormalPosition.top;
02646     if (!CCamApp::IsNewWindowsUI())
02647     {
02648         // Only resize the window on older UI i.e. NT 3 and Win 3 as handled differently
02649         // on Windows 95 UI forms.
02650         ::MoveWindow(GetSafeHwnd(),
02651                      Placement.rcNormalPosition.left,
02652                      Placement.rcNormalPosition.top,
02653                      Placement.rcNormalPosition.right - Placement.rcNormalPosition.left,
02654                      Height + 20,
02655                      TRUE);
02656     }
02657     
02658     // ...and add a check box for the compression on/off preference.
02659     wxRect ButtonPos(10, Height - 35, 110, Height - 15);
02660 
02661     CompressButton.Create((TCHAR *)String_32(_R(IDS_FILEDLGS_COMPRESS_FILE)),
02662                         WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, 
02663                         ButtonPos, this, _R(IDC_COMPRESS_BUTTON));
02664     
02665     // Give it the correct state according to the preference.
02666     CompressButton.SetCheck(CamelotNativeEPSFilter::CompressNative != FALSE);
02667 #endif
02668 
02669     return TRUE;
02670 }
02671 
02672 // Maximum truncated length of the web filename that will fit in the display icon
02673 const INT32 MaxWebName = 40;
02674 
02675 /********************************************************************************************
02676 
02677 >   virtual BOOL SaveFileDialog::ExplorerInitDialog(wxWindow* hDlg)
02678 
02679     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02680     Created:    2/7/96
02681     Returns:    TRUE if it worked, FALSE if it failed
02682     Purpose:    Should be called when the explorer style dialog boxes need setting up.
02683                 We can take this opportunity to add in any extra controls that we require.
02684     SeeAlso:    BaseFileDialog::ExplorerInitDialog; BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
02685 
02686 ********************************************************************************************/
02687 
02688 BOOL SaveFileDialog::ExplorerInitDialog(wxWindow* hDlg)
02689 {
02690 PORTNOTE("other", "Remove MFC code" )
02691 #if !defined(EXCLUDE_FROM_XARALX)
02692     // Do nothing of not on explorer type dialog boxes
02693     if (!CCamApp::IsNewWindowsUI())
02694         return TRUE;
02695 
02696     // Set up and initialise the new buttons and controls
02697 
02698     // Give it the correct state according to the preference.
02699     CheckDlgButton(_R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap != FALSE);
02700 
02701     wxWindow* Icon = FindWindow( _R(IDC_PREVIEW));
02702     ::EnableWindow(Icon, TRUE);
02703 
02704     // WEBSTER - markn 28/1/97
02705     Icon = FindWindow( _R(IDC_FILEDLG_OPTIONS));
02706 #ifndef WEBSTER
02707     ::ShowWindow(Icon, SW_HIDE);
02708 #else
02709     ::ShowWindow(Icon, SW_SHOWNORMAL);
02710     ::EnableWindow(Icon, TRUE);
02711 #endif // WEBSTER
02712 
02713     //Graham 27/10/97: And the "use as default" button
02714     Icon = FindWindow( _R(IDC_USEASDEFAULT));
02715 
02716     ::ShowWindow(Icon, SW_HIDE);
02717     // Move the Preview box down a little, so that it lines up with the List box
02718     CWnd *wndDlg = GetParent();
02719     wxWindow* pWndPreview = GetDlgItem(_R(IDC_PREVIEW));
02720     wxRect rPreview, rList;
02721     pWndPreview->GetWindowRect(&rPreview);
02722     ScreenToClient(rPreview);
02723     wxWindow* pWndList = wndDlg->GetDlgItem(lst1);  // lst1 is the ID for the main list box
02724     pWndList->GetWindowRect(&rList);
02725     ScreenToClient(rList);
02726     pWndPreview->SetWindowPos(NULL, rPreview.left, rList.top, rPreview.Width(), rPreview.Height(), 0);
02727 
02728     ExplorerInited = TRUE;
02729 #endif
02730 
02731     return TRUE;
02732 }
02733 
02734 /********************************************************************************************
02735 >   virtual void SaveFileDialog::DoDataExchange(CDataExchange* pDX)
02736 
02737     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02738     Created:    27/5/95
02739     Inputs:     (a standard MFC object)
02740     Purpose:    Gets the state of the "Compress file" check-box in the save file dialog.
02741 ********************************************************************************************/
02742 
02743 PORTNOTE("other", "Removed MFC junk" )
02744 #if !defined(EXCLUDE_FROM_XARALX)
02745 void SaveFileDialog::DoDataExchange(CDataExchange* pDX)
02746 {
02747     BaseFileDialog::DoDataExchange(pDX);
02748     //{{AFX_DATA_MAP(CMyDialog)
02749 #ifdef _DEBUG
02750     DDX_Check(pDX, _R(IDC_COMPRESS_BUTTON), CamelotNativeEPSFilter::CompressNative);
02751 #endif
02752 //  DDX_Check(pDX, _R(IDC_SAVEASWEB_BUTTON), SaveWebFile); //BaseCamelotFilter::ExportWebFile);
02753     if (CCamApp::IsNewWindowsUI())
02754     {
02755         DDX_Check(pDX, _R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap);
02756     }
02757     //}}AFX_DATA_MAP
02758 }
02759 #endif
02760 
02761 /********************************************************************************************
02762 
02763 >   BOOL SaveFileDialog::PrepareDialog()
02764 
02765     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02766     Created:    26/1/95
02767     Returns:    TRUE if it worked, FALSE if not
02768     Purpose:    Does anything the dialogs want doing after they have been created, but before
02769                 they are displayed
02770 
02771 ********************************************************************************************/
02772 
02773 BOOL SaveFileDialog::PrepareDialog()
02774 {
02775     // Set the title of the dialog, depending on what the document name is
02776     if (!DocName.IsEmpty())
02777     {
02778         // Get a string to build the document title in
02779         String_256 DialogTitle;
02780 
02781         // make a title for the dialog, using the default name for the document
02782         // ie it will come out a bit like this... Save MyDoc.art As
02783         if (DialogTitle.MakeMsg(_R(IDS_SAVENAMEDTITLE), &DocName)!=0)
02784         {
02785             // OK, we have the title in a string 256, so put it into a normal string
02786             UINT32 CopyLength = DialogTitle.Length() + 1;
02787             if (CopyLength > TITLE_SIZE)
02788             {
02789                 CopyLength = TITLE_SIZE - 1;
02790             }
02791             camStrncpy( Title, (const TCHAR*)(DialogTitle), CopyLength);
02792             Title[CopyLength] = TEXT('\0');
02793         
02794             // Change the dialogs data structure to use the new title string
02795             wxFileDialog::SetTitle( Title );
02796         }
02797     }
02798     else
02799     {
02800         // We have no title for the document, so just use 'Save As' instead
02801         if (SmartLoadString(0, _R(IDS_SAVETITLE), Title, 128))
02802             wxFileDialog::SetTitle( Title );
02803     }
02804 
02805     // Select the desired path, use the one passed in to the constructor is available
02806     if (!DefaultPath.IsEmpty())
02807     {
02808         // Set the default path
02809         SetDirectory( DefaultPath );
02810     }
02811     else
02812     {
02813         // or use the global default path
02814         if( DefaultSaveFilePath.Length() == 0 )
02815             // use the My Documents folder
02816             DefaultOpenFilePath = wxStandardPaths::Get().GetUserConfigDir();
02817 
02818         SetDirectory( DefaultSaveFilePath );
02819     }
02820 
02821     // Do the same for the filename
02822     if (!DefaultName.IsEmpty())
02823         SetFilename( DefaultName );
02824 
02825     return TRUE;
02826 }
02827 
02828 
02829 
02830 /********************************************************************************************
02831 
02832 >   void SaveFileDialog::SetDefaultPath(const String_256& NewPath)
02833 
02834     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02835     Created:    26/1/95
02836     Inputs:     NewPath - The path to use as the default
02837     Purpose:    Sets the default path. The next Save As dialog will default to this path
02838 
02839 ********************************************************************************************/
02840 
02841 void SaveFileDialog::SetDefaultPath(const String_256& NewPath)
02842 {
02843     // Set the default path
02844     DefaultSaveFilePath = NewPath;
02845 }
02846 
02847 
02848 /********************************************************************************************
02849 
02850 >   BOOL SaveFileDialog::OnFileNameOK()
02851 
02852     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
02853     Created:    21/9/94
02854     Returns:    TRUE if we didn't like it, FALSE if it was OK. (This is contrary to the MFC
02855                 docs, but they seem to be wrong).
02856     Purpose:    So we can do our own 'that file already exists' check, as the standard one
02857                 used Y/N and that is officially forbidden (despite the fact that 99.999%
02858                 of Windows programs use it). Its an MFC overridable.
02859     SeeAlso:    ExportFileDialog
02860 
02861 ********************************************************************************************/
02862 
02863 BOOL SaveFileDialog::OnFileNameOK()
02864 {
02865     // ask the new function if the name is OK
02866     if (IsValidFilename())
02867         return FALSE;
02868     else
02869         return TRUE;
02870 }
02871 
02872 
02873 
02874 /********************************************************************************************
02875 
02876 >   void SaveFileDialog::AppendExtension(wxString* pFilename)
02877 
02878     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
02879     Created:    14/6/95
02880     Inputs:     pFilename - the filename to append an extension to
02881     Outputs:    pFilename - the input filename with the .art extension on the end (if needed)
02882     Purpose:    Given a filename, this function will attach the .art file extension to the
02883                 to it
02884 
02885 ********************************************************************************************/
02886 
02887 void SaveFileDialog::AppendExtension(wxString* pFilename)
02888 {
02889     // Make sure we were not passed rubbish
02890     if ((pFilename==NULL) || (pFilename->IsEmpty()))
02891         return;
02892 
02893     TRACEUSER( "Rik", _T("Append Extension in - %s\n"), (const TCHAR*)(*pFilename));
02894 
02895     // First we will see if this filename has an extension already
02896     INT32   ExtensionLen = pFilename->length() - pFilename->Find( '.', true );
02897     INT32   i = pFilename->Find( '.', true );
02898 
02899     // See if we found a valid extension
02900     if( ExtensionLen > 3 || i < 0 )
02901     {
02902         // No extension as yet, so add one in
02903         String_32 NewExtension(_R(IDS_DEFAULT_EXTENSION));
02904         *pFilename += wxString( _T(".") );
02905         *pFilename += wxString( (const TCHAR *)NewExtension );
02906     }
02907 
02908     TRACEUSER( "Rik", _T("Append Extension out- %s\n\n"), (const TCHAR*)(*pFilename) );
02909 }
02910 
02911 /********************************************************************************************
02912 
02913 >   BOOL SaveFileDialog::HandleOptions()
02914 
02915     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02916     Created:    24/1/97
02917     Returns:    -
02918     Purpose:    Implements the options button installed for WEBSTER
02919                 Save dlg opens up the .web save options
02920 
02921 ********************************************************************************************/
02922 
02923 PORTNOTE("other", "Removed MFC type Hooks" )
02924 #if !defined(EXCLUDE_FROM_XARALX)
02925 BOOL SaveFileDialog::HandleOptions()
02926 {
02927 #ifndef WEBSTER
02928     return BaseFileDialog::HandleOptions();
02929 #else
02930     if (CCamApp::IsNewWindowsUI())
02931     {
02932         CamelotWebFilter* pWebFilter = NULL;
02933         {
02934             // Find the web filter
02935             Filter* pFilter = Filter::GetFirst();
02936             while (pFilter != NULL && pFilter->FilterID != FILTERID_WEB)
02937                 pFilter = Filter::GetNext(pFilter);     // Try the next filter
02938 
02939             if (pFilter != NULL && IS_A(pFilter,CamelotWebFilter))
02940                 pWebFilter = (CamelotWebFilter*)pFilter;
02941         }
02942 
02943         // Make sure that we found the web Filter
02944         if (pWebFilter == NULL)
02945         {
02946             InformError(_R(IDT_CANT_FIND_FILTER));
02947             return FALSE;
02948         }
02949 
02950         WebPrefsDlgParam Prefs;
02951 
02952         Prefs.SetSelType(pWebFilter->GetSelType());
02953 
02954         // Use the preference option in the baseclass camelot filter;
02955         Prefs.SetBmpCompression(            pWebFilter->GetBitmapCompression());
02956         Prefs.SetExportPreviewBitmap(       pWebFilter->GetPreviewBitmapExport());
02957         Prefs.SetConvertTextToOutlines(     pWebFilter->GetConvertTextToOutlines());
02958         Prefs.SetConvertBlendsToOutlines(   pWebFilter->GetConvertBlendsToOutlines());
02959         Prefs.SetHTMLToClipboard(   pWebFilter->ShouldExportHTMLTag());
02960         
02961         // This is ok as we are using a modal dialog box
02962         BOOL Ok = WebPrefsDlg::InvokeDialog(&Prefs);
02963 
02964         // If ok, and the OK button was clicked to close the dlg
02965         if (OK && Prefs.GetWebOk())
02966         {
02967             // Set up some returned variables as the user has oked them
02968             pWebFilter->SetBitmapCompression(Prefs.GetBmpCompression());
02969             pWebFilter->SetPreviewBitmapExport(Prefs.GetExportPreviewBitmap());
02970             pWebFilter->SetConvertTextToOutlines(Prefs.GetConvertTextToOutlines());
02971             pWebFilter->SetConvertBlendsToOutlines(Prefs.GetConvertBlendsToOutlines());
02972             pWebFilter->SetRemoveInvisibleLayers(TRUE);
02973             pWebFilter->SetRemoveUnusedColours(FALSE);
02974             pWebFilter->SetMinimalWebFormat(FALSE);
02975             pWebFilter->SetSelType(Prefs.GetSelType());
02976             pWebFilter->SetHTMLToClipboard(Prefs.GetHTMLToClipboard());
02977         }
02978     }
02979 
02980     return TRUE;
02981 #endif // WEBSTER
02982 }
02983 #endif
02984 
02985 /********************************************************************************************
02986 >   ImportFileDialog::ImportFileDialog(LPCTSTR lpszFilter)
02987 
02988     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
02989     Created:    18/5/95
02990     Inputs:     lpszFilter          which file extensions to display/allow
02991     Purpose:    Constructs a file import dialog.
02992 
02993 Graham 6/6/97: Took out the OFN_NOVALIDATE flag. Olivier had set this to allow
02994 URLs to be typed into the "File name" field, but it was stopping wildcard searches
02995 (e.g. *.gif) from working
02996 ********************************************************************************************/
02997 
02998 ImportFileDialog::ImportFileDialog(LPCTSTR lpszFilter)
02999 //  :   BaseFileDialog(TRUE, ((CCamApp::IsNewWindowsUI()) ? OFN_ENABLETEMPLATE : 0) | 
03000 //          OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, lpszFilter, NULL)
03001     : BaseFileDialog( TRUE, wxFILE_MUST_EXIST, lpszFilter, NULL )
03002 {
03003 PORTNOTE("other", "Disabled template stuff" )
03004 #if !defined(EXCLUDE_FROM_XARALX)
03005     if (CCamApp::IsNewWindowsUI())
03006     {
03007         // Use our template to do the ammendment and addition of controls to the dialog box
03008         m_ofn.lpTemplateName = MAKEINTRESOURCE(_R(IDD_PREVIEWBITMAP));
03009     }
03010     else
03011         m_ofn.lpTemplateName = NULL;
03012 #endif
03013     
03014     // Set the preview bitmap to be NULL
03015     pBitmapToUse = NULL;
03016 }
03017 
03018 
03019 
03020 /********************************************************************************************
03021 >   BOOL ImportFileDialog::OnInitDialog()
03022 
03023     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
03024     Created:    14/03/94
03025     Returns:    TRUE => normal window focus is required.
03026     Purpose:    Make the drop-down filter box bigger than usual.
03027     SeeAlso:    ImportFileDialog
03028 ********************************************************************************************/
03029 
03030 BOOL ImportFileDialog::OnInitDialog( wxInitDialogEvent& event )
03031 {
03032     // Set up the string we require
03033     String_256 NewText(_R(IDN_IMPORTBUTTON));
03034     const TCHAR*    NewTextStr = NewText;
03035 
03036     // Get the handle of the ok button.
03037     wxButton*       OkButton = dynamic_cast<wxButton*>( FindWindow( wxID_OK ) );
03038 
03039     // Now replace the 'ok' by 'import'
03040     OkButton->SetLabel( NewTextStr ); 
03041 
03042 PORTNOTE("other", "Remove code to re-arrange ImportFileDialog" )
03043 #if !defined(EXCLUDE_FROM_XARALX)
03044     // Get the handle of the filter list box.
03045     wxComboBox*     ComboBox = dynamic_cast<wxComboBox*>( FindWindow( cmb1 ) );
03046 
03047     // Find out where the list box is.
03048     WINDOWPLACEMENT Placement;
03049     Placement.length = sizeof(Placement);
03050     ::GetWindowPlacement(ComboBox, &Placement);
03051 
03052     // Make the list box deeper than usual
03053     ::MoveWindow(ComboBox,
03054                  Placement.rcNormalPosition.left,
03055                  Placement.rcNormalPosition.top,
03056                  Placement.rcNormalPosition.right - Placement.rcNormalPosition.left,
03057                  (Placement.rcNormalPosition.bottom - Placement.rcNormalPosition.top) * 5,
03058                  TRUE);
03059 
03060     // Move the bottom of the dialog down...
03061     Placement.length = sizeof(Placement);
03062     ::GetWindowPlacement(GetSafeHwnd(), &Placement);
03063     INT32 Height = Placement.rcNormalPosition.bottom - Placement.rcNormalPosition.top;
03064 
03065     // ...and add a check box for the layers on/off preference.
03066     // We need to place the extra control differently if we are in Win 95
03067     // as the file dialog is a different size and shape. It also behaves differently,
03068     // adjusting its size to fit the controls etc. Much smarter.
03069     wxRect ButtonPos;
03070     if (CCamApp::IsNewWindowsUI()) //IsWin32c())
03071     {
03072         // Its windows 95, so use these settings
03073         ButtonPos = wxRect(10, 235, 160, 255);
03074         if (IsWin32NT())
03075         {
03076             // NT 4 seems to open the dialog box too narrow in height so the switch is hidden
03077             // Windows 95 shows the switch.
03078             ::MoveWindow(GetSafeHwnd(),
03079                  Placement.rcNormalPosition.left,
03080                  Placement.rcNormalPosition.top,
03081                  Placement.rcNormalPosition.right - Placement.rcNormalPosition.left,
03082                  Height + 20,
03083                  TRUE);
03084         }
03085     }
03086     else
03087     {
03088         // Its not Windows 95, so use these settings.
03089         // Note, we have to expand the dialog window here as well.
03090         ButtonPos = wxRect(10, Height-35, 160, Height-15);
03091         ::MoveWindow(GetSafeHwnd(),
03092                      Placement.rcNormalPosition.left,
03093                      Placement.rcNormalPosition.top,
03094                      Placement.rcNormalPosition.right - Placement.rcNormalPosition.left,
03095                      Height + 20,
03096                      TRUE);
03097     }
03098 
03099     // Get the text for the button - default to something useful
03100     // so that if SmartLoadString fails we still have something
03101     // even if it is in the wrong language
03102     char ButtonText[128] = "Import with Layers"; // Fallback - don't resourceify
03103     SmartLoadString(0, _R(IDS_IMPORTWITHLAYERS), ButtonText, 128);
03104     LayersButton.Create(ButtonText, WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
03105                         ButtonPos, this, _R(IDC_LAYERS_BUTTON));
03106 
03107     // ..and make it use the same font as the rest of the dialog
03108     HFONT hFont = (HFONT) SendMessage(WM_GETFONT);
03109     LayersButton.SendMessage(WM_SETFONT, (WPARAM) hFont, MAKELPARAM(FALSE, 0));
03110 
03111     // Give it the correct state according to the preference.
03112     LayersButton.SetCheck(Filter::ImportWithLayers != FALSE);
03113 #endif
03114 
03115     // Leave the rest up to the base class . . .
03116     BaseFileDialog::OnInitDialog( event );
03117     return TRUE;
03118 }
03119 
03120 /********************************************************************************************
03121 
03122 >   virtual BOOL ImportFileDialog::ExplorerInitDialog(wxWindow* hDlg)
03123 
03124     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
03125     Created:    26/8/96
03126     Returns:    TRUE if it worked, FALSE if it failed
03127     Purpose:    Should be called when the explorer style dialog boxes need setting up.
03128                 We can take this opportunity to add in any extra controls that we require.
03129     SeeAlso:    BaseFileDialog::ExplorerInitDialog; BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
03130 
03131 ********************************************************************************************/
03132 
03133 BOOL ImportFileDialog::ExplorerInitDialog(wxWindow* hDlg)
03134 {
03135 PORTNOTE("other", "Remove MFC code" )
03136 #if !defined(EXCLUDE_FROM_XARALX)
03137     // Do nothing of not on explorer type dialog boxes
03138     if (!CCamApp::IsNewWindowsUI())
03139         return TRUE;
03140 
03141     // Set up and initialise the new buttons and controls
03142 
03143     // Give it the correct state according to the preference.
03144     CheckDlgButton(_R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap != FALSE);
03145 
03146     wxWindow* Icon = FindWindow( _R(IDC_PREVIEW));
03147     ::EnableWindow(Icon, TRUE);
03148 
03149     // WEBSTER - markn 28/1/97
03150     Icon = FindWindow( _R(IDC_FILEDLG_OPTIONS));
03151     ::ShowWindow(Icon, SW_HIDE);
03152 
03153     //Graham 27/10/97: And the "use as default" button
03154     Icon = FindWindow( _R(IDC_USEASDEFAULT));
03155     ::ShowWindow(Icon, SW_HIDE);
03156 
03157     //And the "default templates folder" button
03158     //Icon = FindWindow( _R(IDC_DEFAULTTEMPLATESFOLDER));
03159     //::ShowWindow(Icon, SW_HIDE);
03160 
03161     // Move the Preview box down a little, so that it lines up with the List box
03162     CWnd *wndDlg = GetParent();
03163     wxWindow* pWndPreview = GetDlgItem(_R(IDC_PREVIEW));
03164     wxRect rPreview, rList;
03165     pWndPreview->GetWindowRect(&rPreview);
03166     ScreenToClient(rPreview);
03167     wxWindow* pWndList = wndDlg->GetDlgItem(lst1);  // lst1 is the ID for the main list box
03168     pWndList->GetWindowRect(&rList);
03169     ScreenToClient(rList);
03170     pWndPreview->SetWindowPos(NULL, rPreview.left, rList.top, rPreview.Width(), rPreview.Height(), 0);
03171 
03172     ExplorerInited = TRUE;
03173 #endif
03174 
03175     return TRUE;
03176 }
03177 
03178 /********************************************************************************************
03179 >   virtual void ImportFileDialog::DoDataExchange(CDataExchange* pDX)
03180 
03181     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
03182     Created:    18/5/95
03183     Inputs:     (a standard MFC object)
03184     Purpose:    Gets the state of the "Import Layers" check-box in the import file dialog.
03185 ********************************************************************************************/
03186 
03187 PORTNOTE("other", "Removed MFC junk" )
03188 #if !defined(EXCLUDE_FROM_XARALX)
03189 void ImportFileDialog::DoDataExchange(CDataExchange* pDX)
03190 {
03191     BaseFileDialog::DoDataExchange(pDX);
03192     //{{AFX_DATA_MAP(CMyDialog)
03193     DDX_Check(pDX, _R(IDC_LAYERS_BUTTON), Filter::ImportWithLayers);
03194     if (CCamApp::IsNewWindowsUI())
03195     {
03196         DDX_Check(pDX, _R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap);
03197     }
03198     //}}AFX_DATA_MAP
03199 }
03200 
03201 void ImportFileDialog::OnLButtonDblClk( wxMouseEvent& event ) 
03202 {
03203     CDialog::OnLButtonDblClk(nFlags, point);
03204 }
03205 #endif
03206 
03207 
03208 /********************************************************************************************
03209 >   ExportFileDialog::ExportFileDialog(LPCTSTR lpszFilter)
03210 
03211     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
03212     Created:    18/5/95
03213     Inputs:     lpszFilter          which file extensions to display/allow
03214     Purpose:    Contructs an export file dialog.
03215 ********************************************************************************************/
03216 
03217 ExportFileDialog::ExportFileDialog(LPCTSTR lpszFilter)
03218 //  : BaseFileDialog(FALSE, ((CCamApp::IsNewWindowsUI()) ? OFN_ENABLETEMPLATE : 0) | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, lpszFilter, NULL)
03219     : BaseFileDialog( FALSE, 0, lpszFilter, NULL )
03220 {
03221 PORTNOTE("other", "Disabled template stuff" )
03222 #if !defined(EXCLUDE_FROM_XARALX)
03223     // Under Windows 95 the OnFileNameOK system does not work, so use the default one
03224     // Disable for VC4.0/MFC 4.0 as they have fixed it.
03225 #if _MFC_VER < 0x400
03226     if (IsWin32c())
03227         m_ofn.Flags |= OFN_OVERWRITEPROMPT;
03228 #endif
03229 
03230     if (CCamApp::IsNewWindowsUI())
03231     {
03232         // Use our template to do the ammendment and addition of controls to the dialog box
03233         m_ofn.lpTemplateName = MAKEINTRESOURCE(_R(IDD_PREVIEWBITMAP));
03234     }
03235     else
03236         m_ofn.lpTemplateName = NULL;
03237 #endif
03238     
03239     // Set the preview bitmap to be NULL
03240     pBitmapToUse = NULL;    
03241 
03242     m_bExportABitmap = FALSE;
03243 
03244 #if FALSE
03245     // for the future "Options" button handling
03246 
03247     // set the options to be NULL
03248     m_pOptions = NULL;
03249 #endif
03250 }
03251 
03252 
03253 
03254 /********************************************************************************************
03255 >   BOOL ExportFileDialog::OnInitDialog()
03256 
03257     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
03258     Created:    22/03/94
03259     Returns:    TRUE => normal window focus is required.
03260     Purpose:    Make the drop-down filter box bigger than usual.
03261     SeeAlso:    ExportFileDialog
03262 ********************************************************************************************/
03263 
03264 BOOL ExportFileDialog::OnInitDialog( wxInitDialogEvent& event )
03265 {
03266     // Set up the string we require
03267     String_256 NewText(_R(IDN_EXPORTBUTTON));
03268 
03269     // Get the handle of the ok button.
03270     wxButton*   OkButton = dynamic_cast<wxButton *>( FindWindow( wxID_OK ) );
03271 
03272     // Now replace the 'ok' by 'export'
03273     OkButton->SetLabel( (LPCTSTR)NewText );
03274 
03275 PORTNOTE("other", "Remove code to re-arrange ImportFileDialog" )
03276 #if !defined(EXCLUDE_FROM_XARALX)
03277     // Get the handle of the filter list box.
03278     wxComboBox* ComboBox = dynamic_cast<wxComboBox *>( FindWindow( cmb1 ) );
03279 
03280     // Find out where the list box is.
03281     WINDOWPLACEMENT Placement;
03282     Placement.length = sizeof(WINDOWPLACEMENT);
03283     ::GetWindowPlacement(ComboBox, &Placement);
03284 
03285     // Make the list box deeper than usual
03286     ::MoveWindow(ComboBox,
03287                  Placement.rcNormalPosition.left,
03288                  Placement.rcNormalPosition.top,
03289                  Placement.rcNormalPosition.right - Placement.rcNormalPosition.left,
03290                  (Placement.rcNormalPosition.bottom - Placement.rcNormalPosition.top) * 5,
03291                  TRUE);
03292 #endif
03293 
03294     // Let the base class do the rest . . .
03295     BaseFileDialog::OnInitDialog( event );
03296     return TRUE;
03297 }
03298 
03299 /********************************************************************************************
03300 
03301 >   virtual BOOL ExportFileDialog::ExplorerInitDialog(wxWindow* hDlg)
03302 
03303     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
03304     Created:    17/7/96
03305     Returns:    TRUE if it worked, FALSE if it failed
03306     Purpose:    Should be called when the explorer style dialog boxes need setting up.
03307                 We can take this opportunity to add in any extra controls that we require.
03308     SeeAlso:    BaseFileDialog::ExplorerInitDialog; BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
03309 
03310 ********************************************************************************************/
03311 
03312 BOOL ExportFileDialog::ExplorerInitDialog(wxWindow* hDlg)
03313 {
03314 PORTNOTE("other", "Remove MFC code" )
03315 #if !defined(EXCLUDE_FROM_XARALX)
03316     // Do nothing of not on explorer type dialog boxes
03317     if (!CCamApp::IsNewWindowsUI())
03318         return TRUE;
03319 
03320     // Replace the 'OK' button by 'Export' or 'Apply'.
03321 /*  ::SetWindowText(FindWindow( IDOK),
03322                     (LPCSTR) String(NamedExportProp::m_fApplyNotExport
03323                                             ? _R(IDS_PREVIEW_APPLY) : _R(IDN_EXPORTBUTTON)));
03324 */
03325     // Actually stand a chance of replacing the 'OK' button by 'Export' or 'Apply'...
03326     SetControlText(IDOK, (LPCSTR) String(NamedExportProp::m_fApplyNotExport ? _R(IDS_PREVIEW_APPLY) : _R(IDN_EXPORTBUTTON)));
03327 
03328     // Give it the correct state according to the preference.
03329     CheckDlgButton(_R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap != FALSE);
03330 
03331     wxWindow* Icon = FindWindow( _R(IDC_PREVIEW));
03332     ::EnableWindow(Icon, TRUE);
03333 
03334     // WEBSTER - markn 28/1/97
03335     Icon = FindWindow( _R(IDC_FILEDLG_OPTIONS));
03336     // Grey the options button.
03337     ::EnableWindow(Icon, FALSE);
03338     ::ShowWindow(Icon, SW_HIDE);
03339 
03340     //Graham 27/10/97: And the "use as default" button
03341     Icon = FindWindow( _R(IDC_USEASDEFAULT));
03342     ::ShowWindow(Icon, SW_HIDE);
03343 
03344     //And the "default templates folder" button
03345     //Icon = FindWindow( _R(IDC_DEFAULTTEMPLATESFOLDER));
03346     //::ShowWindow(Icon, SW_HIDE);
03347 
03348     // initialise the state of the Options button
03349     SetStateOnFilterChange();
03350 
03351     // Move the Preview box down a little, so that it lines up with the List box
03352     CWnd *wndDlg = GetParent();
03353     wxWindow* pWndPreview = GetDlgItem(_R(IDC_PREVIEW));
03354     wxRect rPreview, rList;
03355     pWndPreview->GetWindowRect(&rPreview);
03356     ScreenToClient(rPreview);
03357     wxWindow* pWndList = wndDlg->GetDlgItem(lst1);  // lst1 is the ID for the main list box
03358     pWndList->GetWindowRect(&rList);
03359     ScreenToClient(rList);
03360     pWndPreview->SetWindowPos(NULL, rPreview.left, rList.top, rPreview.Width(), rPreview.Height(), 0);
03361 
03362     // set the state of the Auto-preview check-box
03363 //J ::CheckDlgButton(GetSafeHwnd(), _R(IDC_AUTO_CHECK), BmapPrevDlg::m_bDoAutoPreview);
03364     return ExplorerInited = TRUE;
03365 #endif
03366 
03367     return TRUE;
03368 }
03369 
03370 /********************************************************************************************
03371 
03372 >   virtual void ExportFileDialog::DoDataExchange(CDataExchange* pDX)
03373 
03374     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
03375     Created:    9/1/96
03376     Inputs:     (a standard MFC object)
03377     Purpose:    Handles data exchange messages for the export file dialog.
03378 
03379 ********************************************************************************************/
03380 
03381 PORTNOTE("other", "Removed MFC junk" )
03382 #if !defined(EXCLUDE_FROM_XARALX)
03383 void ExportFileDialog::DoDataExchange(CDataExchange* pDX)
03384 {
03385     BaseFileDialog::DoDataExchange(pDX);
03386     //{{AFX_DATA_MAP(CMyDialog)
03387     //DDX_Check(pDX, _R(IDC_LAYERS_BUTTON), Filter::ImportWithLayers);
03388     if (CCamApp::IsNewWindowsUI())
03389     {
03390         DDX_Check(pDX, _R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap);
03391     }
03392     //}}AFX_DATA_MAP
03393 }
03394 #endif                 
03395 
03396 /********************************************************************************************
03397 
03398 >   BOOL ExportFileDialog::OnFileNameOK()
03399 
03400     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
03401     Created:    21/9/94
03402     Returns:    TRUE if we didn't like it, FALSE if it was OK. (This is contrary to the MFC
03403                 docs, but they seem to be wrong).
03404     Purpose:    So we can do our own 'that file already exists' check, as the standard one
03405                 used Y/N and that is officially forbidden (despite the fact that 99.999%
03406                 of Windows programs use it). Its an MFC overridable.
03407     SeeAlso:    ExportFileDialog
03408 ********************************************************************************************/
03409 
03410 BOOL ExportFileDialog::OnFileNameOK()
03411 {
03412     // ask the new function if the name is OK
03413     if (IsValidFilename())
03414         return FALSE;
03415     else
03416         return TRUE;
03417 }
03418 
03419 /********************************************************************************************
03420 
03421 >   void ExportFileDialog::AppendExtension(wxString* pFilename)
03422 
03423     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
03424     Created:    5/7/95
03425     Inputs:     pFilename - the filename to append an extension to
03426     Outputs:    pFilename - the input filename with the .art extension on the end (if needed)
03427     Purpose:    Given a filename, this function will attach the appropriate file extension
03428                 according to the chosen filter to it.
03429                 Based on the function SaveFileDialog::AppendExtension but needs to append the
03430                 selected filer name rather than an explicit .art.
03431                 
03432                 Ideally should do this when the user selects a new export filter type on the
03433                 list and when the box is first brought up but alledgedly trapping the list
03434                 clicks is difficult.
03435                 
03436     SeeAlso:    SaveFileDialog::AppendExtension;
03437 
03438 ********************************************************************************************/
03439 
03440 void ExportFileDialog::AppendExtension(wxString* pFilename)
03441 {
03442     // Use the new routine in its default state i.e. only add extension if not present already
03443     AddExtension(pFilename);
03444     return; 
03445 }
03446 
03447 /********************************************************************************************
03448 
03449 >   void ExportFileDialog::AddExtension(wxString* pFilename, BOOL Replace = FALSE, BOOL AskAboutReplace = FALSE,
03450                                         UINT32 Selection = 0)
03451 
03452     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
03453     Created:    12/1/96
03454     Inputs:     pFilename       - the filename to append an extension to
03455                 Replace         - True if want when an extension is present, it will be replaced
03456                                 - False only adds extensions when none are present
03457                 AskAboutReplace - If extension does not match the filter the ask about replacing it
03458                 Selection       - Non-zero means that this is the selected item
03459     Outputs:    pFilename       - the input filename with the .art extension on the end (if needed)
03460     Purpose:    Given a filename, this function will attach the appropriate file extension
03461                 according to the chosen filter to it.
03462                 Based on the function SaveFileDialog::AppendExtension but needs to append the
03463                 selected filer name rather than an explicit .art.
03464                 
03465                 Ideally should do this when the user selects a new export filter type on the
03466                 list and when the box is first brought up but alledgedly trapping the list
03467                 clicks is difficult.
03468                 
03469     SeeAlso:    SaveFileDialog::AppendExtension;
03470 
03471 ********************************************************************************************/
03472 
03473 void ExportFileDialog::AddExtension(wxString* pFilename, BOOL Replace, BOOL AskAboutReplace, UINT32 Selection)
03474 {
03475     // Make sure we were not passed rubbish
03476     if ((pFilename==NULL) || (pFilename->IsEmpty()))
03477         return;
03478 
03479     TRACEUSER( "Neville", _T("Add Extension in - %s\n"), (PCTSTR)*pFilename );
03480 
03481     // First we will see if this filename has an extension already
03482     INT32   ExtensionLen = pFilename->length() - pFilename->Find( '.', true );
03483     INT32   i = pFilename->Find( '.', true );
03484 
03485     // If a selection has been passed in then use that, otherwise use the one stored in the
03486     // class variable.
03487     INT32 TheSelectedFilter = 0;
03488     if (Selection)
03489         TheSelectedFilter = Selection;
03490     else
03491         TheSelectedFilter = GetSelectedFilterIndex(); // could use m_ofn.nFilterIndex but beware bodge!
03492 
03493 TRACEUSER( "Neville", _T("TheSelectedFilter - %d\n"), TheSelectedFilter);
03494     // Find the filter that the user has chosen
03495     Filter *pFilter = GetSelectedExportFilter(TheSelectedFilter);
03496 
03497     // If no filter was found then return immediately
03498     if (pFilter == NULL)
03499         return;
03500 
03501     String_32 ExtStr = pFilter->pOILFilter->FilterExt;
03502     // Filters might have multiple extensions listed separated by commas
03503     // so use first e.g. AI eps filter has ai and eps.
03504     // Work out the position of the first separator character, - 1 if none
03505     String_8    SepMark = _T(",");
03506     INT32       Position = ExtStr.Sub( SepMark );
03507     
03508     // If comma separator was found use up to the separator 
03509     if (Position > 0)
03510         ExtStr.Left(&ExtStr, Position);
03511 
03512     // See if we found a valid extension
03513     if ((ExtensionLen > 3) || (i < 0))
03514     {
03515         // No valid extension as yet so add one
03516         *pFilename += wxString( _T(".") );
03517         *pFilename += (TCHAR*)ExtStr;
03518     }
03519     else if (ExtensionLen <= 3 && ExtensionLen > 0 && i > 0)
03520     {
03521         // FLag we don't overwrite by default
03522         BOOL OverwriteExtension = FALSE;
03523 
03524         // Only if wanting to ask and not force the replacement do we need to
03525         // check the extension and ask the user if they want to correct it
03526         if (AskAboutReplace && !Replace)
03527         {
03528             // Valid extension found so check that it is correct
03529             String_32   FoundExtStr( _T("") );
03530             TCHAR*      FoundExt = (TCHAR *)FoundExtStr;
03531             INT32       j;
03532             for( j = 0; j < ExtensionLen; j++ )
03533                 FoundExt[j] = pFilename->operator[](i + 1 + j);
03534 
03535             // Stuff a terminator on the end
03536             FoundExt[j] = '\0';
03537             // Ensure in lower case
03538             FoundExtStr.toLower();
03539 
03540             if (FoundExtStr != ExtStr)
03541             {
03542                 // Wrong extension present so warn the user
03543                 String_256 Msg;
03544                 Msg.MakeMsg(_R(IDW_REPLACEEXTENSION), (TCHAR *)FoundExtStr, (TCHAR *)ExtStr);
03545                 Error::SetError(0, Msg, 0);
03546                 INT32 ButtonPressed = InformWarning(0, _R(IDS_CORRECT), _R(IDS_DONTCORRECT));
03547                 Error::ClearError();
03548 
03549                 // If the user presses 'Correct' then go and fix the extension to what
03550                 // it should be 
03551                 if(ButtonPressed == 1)
03552                 {
03553                     OverwriteExtension = TRUE;
03554                 }
03555             }
03556         }
03557         else if (Replace)
03558         {
03559             // Flag that we require an overwrite
03560             OverwriteExtension = TRUE;
03561         }
03562         
03563         if (OverwriteExtension)
03564         {
03565             // Hack off the current extension
03566             *pFilename = pFilename->Left(i);
03567             
03568             // Add in the new one
03569             *pFilename += wxString( _T(".") );
03570             *pFilename += (TCHAR*)ExtStr;
03571         }
03572     }
03573 
03574     TRACEUSER( "Neville", _T("Add Extension out- %s\n\n"), PCTSTR(*pFilename) );
03575 }
03576 
03577 
03578 
03579 
03580 /************************************************************************************************************
03581 
03582 >   BOOL ExportFileDialog::HandleOptions()
03583 
03584     Author:     Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
03585     Created:    24/07/97
03586     Returns:    -
03587     Purpose:    Implements the options button installed for WEBSTER                              
03588     
03589 **************************************************************************************************************/
03590 
03591 #if FALSE
03592     // for the future "Options" button handling
03593 
03594 BOOL ExportFileDialog::HandleOptions()
03595 {
03596     BOOL Ok = TRUE;
03597 
03598     // get the filter index
03599     INT32 TheSelectedFilter = GetSelectedFilterIndex(); // could use m_ofn.nFilterIndex but beware bodge!
03600 
03601     // Find the filter that the user has chosen
03602     Filter *pFilter = GetSelectedExportFilter(TheSelectedFilter);
03603 
03604     // check for bitmap filter
03605     if (pFilter->IS_KIND_OF(BaseBitmapFilter))
03606     {
03607         BaseBitmapFilter *pBmpFilter = (BaseBitmapFilter *)pFilter;
03608 
03609         // delete the old options
03610         if (m_pOptions != NULL)
03611             delete m_pOptions;
03612         m_pOptions = NULL;
03613 
03614         // set up our export options
03615         if (m_bExportABitmap)
03616             Ok = pBmpFilter->SetUpExportBitmapOptions(&m_pOptions, m_pBitmapToExport);
03617         else
03618             Ok = pBmpFilter->SetUpExportOptions(&m_pOptions);
03619 
03620         if (Ok)
03621         {
03622             // check for valid options
03623             Ok = m_pOptions->IsValid();     
03624         }
03625     }
03626     else
03627         Ok = FALSE;
03628 
03629     // if everything went ok set the options to be the defaults
03630     if (Ok)
03631         m_pOptions->SetAsDefaults();
03632 
03633     // Everything ok.
03634     return Ok;
03635 }
03636 
03637 #endif
03638 
03639 
03640 /************************************************************************************************************
03641 
03642 >   BOOL ExportFileDialog::SetStateOnFilterChange()
03643 
03644     Author:     Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
03645     Created:    24/07/97
03646     Returns:    The state of the Options button
03647     Purpose:    Finds out whether to grey the Options button and/or the Auto-preview checkbox
03648     
03649 **************************************************************************************************************/
03650 BOOL ExportFileDialog::SetStateOnFilterChange()
03651 {
03652     // get the filter index
03653     INT32 TheSelectedFilter = GetSelectedFilterIndex(); // could use m_ofn.nFilterIndex but beware bodge!
03654 
03655     // Find the filter that the user has chosen
03656     Filter *pFilter = GetSelectedExportFilter(TheSelectedFilter);
03657 
03658     BOOL State; // the state of the options button
03659 
03660 PORTNOTE("other", "Removed BMPFilter usage" )
03661     // enable the Options button, but only if a bitmap filter 
03662     //and not the BMP filter if exporting a bitmap
03663     if ((pFilter != NULL) && pFilter->IS_KIND_OF(BaseBitmapFilter) && 
03664         (!m_bExportABitmap /*|| !IS_A(pFilter, BMPFilter)*/ ) )
03665         State = TRUE; // the state of the checkbox
03666     else
03667         State = FALSE;
03668     
03669 //  wxWindow* Icon;
03670 #if FALSE
03671     // for the future "Options" button handling
03672 
03673     // enable the Options button
03674     Icon = FindWindow( _R(IDC_FILEDLG_OPTIONS));
03675     ::EnableWindow(Icon, State);
03676 
03677     // delete the options created for the last filter
03678     if (m_pOptions != NULL)
03679         delete m_pOptions;
03680     m_pOptions = NULL;
03681 #endif
03682 
03683     // set the state the "Auto-preview" checkbox
03684 //  Icon = FindWindow( _R(IDC_AUTO_CHECK));
03685 
03686     // display it first
03687 //  ::ShowWindow(Icon, SW_SHOW);
03688 
03689     // when exporting a bitmap we only have auto-preview on Options if using the JPEG filter
03690 //  BOOL AutoPreviewState = State && (!m_bExportABitmap || 
03691 //                                    (pFilter != NULL) && (IS_A(pFilter,JPEGExportFilter))); 
03692 //  ::EnableWindow(Icon, AutoPreviewState);
03693 
03694     return State;
03695 }
03696 
03697 /********************************************************************************************
03698 
03699 >   void ExportFileDialog::OnTypeChange()
03700 
03701     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
03702     Created:    12/1/96
03703     Returns:    -
03704     Purpose:    Should be called when the user has selected a new file type from the
03705                 "Files of type" combo box. We might need to do things like fix the file
03706                 extension for the currently selected save/export filter.
03707                 Only called back if OFN_EXPLORER is set and you can only do this on Windows 95
03708                 otherwise a dialog is not popped up.
03709 
03710     SeeAlso:    BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
03711     SeeAlso:    ExportFileDialog::OnLBSelChangedNotify;
03712 
03713 ********************************************************************************************/
03714 
03715 void ExportFileDialog::OnTypeChange()
03716 {
03717 #if _MFC_VER >= 0x400
03718     // Remove code completely if using less than MFC4.0 as calls like SetControlText
03719     // will not be present and this function will not work
03720     // Just in case Windows NT 3 decides to call this we'd better stop it as otherwise things
03721     // will be happening more than they should. This is the method used on Windows 95 or NT 4.
03722     if (!CCamApp::IsNewWindowsUI())
03723         return;
03724 
03725     // set the state of the Options button and the Auto-preview checkbox
03726     SetStateOnFilterChange();
03727 
03728     // Get the filename which the user has entered in the field
03729     wxString FileName = GetFileName();
03730     // If its empty then return immediately
03731     if (FileName.IsEmpty())
03732         return;
03733     
03734     // Add in the selection for the newly selected filter forcing an overwrite of any extension
03735     // already present
03736     AddExtension(&FileName, TRUE);
03737 
03738     // Try and put this back into the edit box containing the filename
03739     if (!FileName.IsEmpty())
03740     {
03741         // The following call ensures on NT. 
03742         SetControlText(edt1, (LPCSTR)(FileName.GetBuffer(1))); // 1 = min buffer size!
03743     }
03744 
03745 #endif
03746     return;
03747 }
03748     
03749 /********************************************************************************************
03750 
03751 >   virtual void ExportFileDialog::OnLBSelChangedNotify(UINT32 nIDBox, UINT32 iCurSel, UINT32 nCode)
03752 
03753     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
03754     Created:    12/1/96
03755     Inputs:     nIDBox  The ID of the list box or combo box in which the selection occurred.
03756                 iCurSel The index of the current selection.
03757                 nCode   The control notification code. Values are:
03758                      CD_LBSELCHANGE Specifies iCurSel is the selected item in a single-selection list box.
03759                      CD_LBSELSUB        Specifies that iCurSel is no longer selected in a multiselection list box.
03760                      CD_LBSELADD        Specifies that iCurSel is selected in a multiselection list box.
03761                      CD_LBSELNOITEMS    Specifies that no selection exists in a multiselection list box.
03762     Returns:    TRUE if it worked, FALSE if it failed
03763     Purpose:    Should be called when the user has selected a new file type from the
03764                 "Files of type" combo box. We might need to do things like fix the file
03765                 extension for the currently selected save/export filter.
03766                 This should be called on all OS's, so we must disable it in Windows 95. This turns
03767                 out not to be the case as it does not seem to get called on Windows 95, probably
03768                 due to the ExportFileDialog::OnTypeChange() override.
03769                 It is called on initing the dialog box but shouldn't cause a problem.
03770                 Filenames of the sort *.gif are automatically fixed by the OS. As soon as you
03771                 type a real name in though, they are no longer fixed!
03772                 
03773     SeeAlso:    BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
03774     SeeAlso:    ExportFileDialog::OnTypeChange();
03775 
03776 ********************************************************************************************/
03777 
03778 void ExportFileDialog::OnLBSelChangedNotify(UINT32 nIDBox, UINT32 iCurSel, UINT32 nCode)
03779 {
03780 PORTNOTE("other", "Removed MFC junk" )
03781 #if !defined(EXCLUDE_FROM_XARALX)
03782     // If its Windows 95 or NT 4 then use the proper method of ExportFileDialog::OnTypeChange()
03783     // which is not called on Windows NT 3
03784     // It would appear that this does not get called at all on Windows 95!
03785     if (CCamApp::IsNewWindowsUI())
03786         return;
03787     
03788     // Combo box = filter type box
03789     if (nIDBox == cmb1 && nCode == CD_LBSELCHANGE)
03790     {
03791         // Find out the Path name of the newly selected file
03792         TRACEUSER( "Neville", _T("Selection Changed - New selection = (%i)\n"), iCurSel);
03793         
03794         // Try and put this back into the edit box containing the filename
03795         wxWindow* hFileNameBox = FindWindow( edt1);
03796 
03797         if (hFileNameBox)
03798         {
03799             // Get the current filename from the edit field
03800             //wxString FullPath = GetPathName(); // This doesn't work and returns zero
03801             String_256 StrVal;
03802             ::GetWindowText(hFileNameBox, (LPSTR)(TCHAR*)StrVal, StrVal.MaxLength());
03803 
03804             // List boxes go from 1..n rather than 0..n 
03805             INT32 TheSelectedFilter = iCurSel + 1;
03806             
03807             // Find the filter that the user has chosen
03808             Filter *pFilter = GetSelectedExportFilter(TheSelectedFilter);
03809 
03810             if (!StrVal.IsEmpty() && pFilter && pFilter->pOILFilter)
03811             {
03812                 PathName TempPath(StrVal);
03813                 if (!TempPath.IsValid())
03814                 {
03815                     // There was a problem e.g. user has typed f:
03816                     // Magically a bad pathname sets an error so clear it!
03817                     Error::ClearError();
03818                     return;
03819                 }
03820 
03821                 // Get the OILFilter class to check the extension for the selected or default filter
03822                 // matches
03823                 if (!pFilter->pOILFilter->DoesExtensionOfPathNameMatch(&TempPath))
03824                 {   
03825                     // Extension is either blank or does not match the one supplied by the filter
03826                     // Ask the OILFilter class to fix it for us
03827                     pFilter->pOILFilter->FixExtensionOfPathName(&TempPath);
03828                     // Now copy that back into the name
03829                     StrVal = TempPath.GetPath();
03830 
03831                     // Try and put this back into the edit box containing the filename
03832                     ::SetWindowText(hFileNameBox, (TCHAR*)(StrVal));
03833                 }
03834             }
03835         }
03836     }
03837 #endif
03838 }
03839 
03840 /********************************************************************************************
03841 
03842 >   BOOL ExportFileDialog::IsValidFilename()
03843 
03844     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
03845     Created:    9/5/97
03846     Returns:    TRUE if the current filename is Acceptable, FALSE if not
03847     Purpose:    Check to see if the file name is OK.
03848 
03849                 If the file already exists, then we check with the *currently
03850                 selected filter* to see if it wants to accept an existing file.
03851 
03852                 Most filters will put up a message to ask the user whether they
03853                 want to replace the file. However, the ImagemapFilter will
03854                 also give the user the option to intelligently insert an imagemap
03855                 into the HTML file.
03856 
03857   SeeAlso:      BaseFileDialog::IsValidFilename
03858 ********************************************************************************************/
03859 
03860 BOOL ExportFileDialog::IsValidFilename()
03861 {
03862     // Get the pathname
03863     wxString    FullPath = GetPath();
03864     AppendExtension(&FullPath);
03865 
03866     // if doesn't exist then thats fine
03867     if( !wxFile::Exists( FullPath ) )
03868     {
03869         return TRUE;
03870     }
03871 
03872     // But it does exist.
03873     // So we need to get the currently selected filter to warn the user
03874     // So get the currently selected filter
03875     Filter*     pFilter = GetSelectedExportFilter(GetSelectedFilterIndex());
03876 
03877     // Check it's there
03878     ERROR2IF(pFilter==NULL, FALSE, "ExportFileDialog::IsValidFilename - filter does not exist");
03879 
03880     // And ask that filter if it wants to accept an existing file
03881     String_256  strFullPath(FullPath);
03882     PathName    pthFullPath(strFullPath);
03883 
03884     return pFilter->WillAcceptExistingFile(pthFullPath);
03885 }
03886 
03887 
03888 /********************************************************************************************
03889 
03890 >   afx_msg void ExportFileDialog::OnAutoPreview()
03891 
03892     Author:     Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
03893     Created:    24/7/97
03894     Returns:    -
03895     Purpose:    Should be called when the user has selected a new file type from the
03896                 "Files of type" combo box. We might need to do things like fix the file
03897                 extension for the currently selected save/export filter.
03898                 Only called back if OFN_EXPLORER is set and you can only do this on Windows 95
03899                 otherwise a dialog is not popped up.
03900 
03901     SeeAlso:    BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
03902     SeeAlso:    ExportFileDialog::OnLBSelChangedNotify;
03903 
03904 ********************************************************************************************/
03905 
03906 PORTNOTE("other", "Removed MFC junk" )
03907 #if !defined(EXCLUDE_FROM_XARALX)
03908 afx_msg void ExportFileDialog::OnAutoPreview()
03909 {
03910 //J BmapPrevDlg::m_bDoAutoPreview = IsDlgButtonChecked(_R(IDC_AUTO_CHECK));
03911 }
03912 #endif
03913     
03914     
03915 /************************************************************************************************************
03916 
03917 >   BOOL ExportFileDialog::HandleOptions()
03918 
03919     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
03920     Created:    07/07/97
03921     Returns:    -
03922     Purpose:    Implements the options button installed for WEBSTER                              
03923                 This opens the GIF Animation properties tabs dialog with the Browser PReview tab selected.
03924 
03925 **************************************************************************************************************/
03926 BOOL ExportFileDialog::HandleOptions()
03927 {
03928 PORTNOTETRACE("other", "ExportFileDialog::HandleOptions - Do nothing - ControlHelper, GIFAnimationPropertyTabsDlg" );
03929 #if !defined(EXCLUDE_FROM_XARALX)
03930     // Get a ptr to the correct op. 
03931     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_EXPORTGIFANIMTABSDLG);
03932 
03933     if (pOpDesc != NULL)
03934     {
03935         // If the animation properties dialog is open, close it.
03936         if (GIFAnimationPropertyTabsDlg::GetGIFAnimationPropertyTabsDlg())
03937         {
03938             // Get a ptr to the dlg.
03939             GIFAnimationPropertyTabsDlg* pDlg = GIFAnimationPropertyTabsDlg::GetGIFAnimationPropertyTabsDlg();
03940 
03941             // Ensure it is a valid ptr.
03942             if(pDlg)
03943             {
03944                 // Close the dialog.
03945                 pDlg->Close();      
03946                 pDlg->End();            
03947             }
03948         }
03949     
03950         // Select the "Browser Preview tab".
03951         GIFAnimationPropertyTabsDlg::SetPageToOpen(0);
03952 
03953         // Hide all other tabs. This flag is set back to FALSE in the destructor of AnimExOptns.
03954         GIFAnimationPropertyTabs::SetBrowserPreviewTab(TRUE);
03955 
03956         // This ensures that the dialog process works correctly.
03957         ControlHelper::InformModalDialogOpened();
03958         
03959         // Open the dialog.
03960         pOpDesc->Invoke();
03961 
03962         // Get a ptr to the dialog.
03963         GIFAnimationPropertyTabsDlg* pDlg = GIFAnimationPropertyTabsDlg::GetGIFAnimationPropertyTabsDlg();
03964 
03965         // Ensure the ptr is valid.
03966         if (pDlg)
03967         {
03968             // Send our DIM_CANCEL message.
03969             BROADCAST_TO_CLASS( DialogMsg( pDlg->WindowID, DIM_CANCEL, 0) ,DialogOp );
03970         }
03971 
03972         // The dialog has closed.
03973         ControlHelper::InformModalDialogClosed();
03974     }
03975 #endif
03976 
03977     // Everything ok.
03978     return TRUE;
03979 }
03980 
03981 
03982 /************************************************************************************************************
03983 
03984 >   BOOL GIFExportFileDialog::GIFExportFileDialog
03985 
03986     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
03987     Created:    07/07/97
03988     Returns:    -
03989     Purpose:    Implements the options button installed for WEBSTER                              
03990                 This opens the GIF Animation properties tabs dialog.
03991 
03992 **************************************************************************************************************/
03993 
03994 GIFExportFileDialog::GIFExportFileDialog(LPCTSTR lpszFilter):ExportFileDialog(lpszFilter)
03995 {
03996     // Base class does all the work.
03997 }
03998 
03999 /************************************************************************************************************
04000 
04001 >   BOOL GIFExportFileDialog::HandleOptions()
04002 
04003     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
04004     Created:    07/07/97
04005     Returns:    -
04006     Purpose:    Implements the options button installed for WEBSTER                              
04007                 This opens the GIF Animation properties tabs dialog.
04008 
04009 **************************************************************************************************************/
04010 
04011 BOOL GIFExportFileDialog::HandleOptions()
04012 {
04013 PORTNOTETRACE("other", "GIFExportFileDialog::HandleOptions - Do nothing - Use NgScan" );
04014 #if !defined(EXCLUDE_FROM_XARALX)
04015     // Get a ptr to the correct op. 
04016     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_EXPORTGIFANIMTABSDLG);
04017 
04018     if (pOpDesc != NULL)
04019     {
04020         // If the animation properties dialog is open, close it.
04021         if (GIFAnimationPropertyTabsDlg::GetGIFAnimationPropertyTabsDlg())
04022         {
04023             // Get a ptr to the dlg.
04024             GIFAnimationPropertyTabsDlg* pDlg = GIFAnimationPropertyTabsDlg::GetGIFAnimationPropertyTabsDlg();
04025 
04026             // Ensure it is a valid ptr.
04027             if(pDlg)
04028             {
04029                 // Close the dialog.
04030                 pDlg->Close();      
04031                 pDlg->End();            
04032             }
04033         }
04034     
04035         // Select the "Animation colours tab".
04036         GIFAnimationPropertyTabsDlg::SetPageToOpen(0);
04037 
04038         // Hide the Frame propertiestab. This flag is set back to TRUE in the destructor of AnimExOptns.
04039         GIFAnimationPropertyTabs::SetIncludeFramePropertiesTab(FALSE);
04040 
04041         // This ensures that the dialog process works correctly.
04042         ControlHelper::InformModalDialogOpened();
04043 
04044         // Open the dialog.
04045         pOpDesc->Invoke();
04046 
04047         // Get a ptr to the dialog.
04048         GIFAnimationPropertyTabsDlg* pDlg = GIFAnimationPropertyTabsDlg::GetGIFAnimationPropertyTabsDlg();
04049 
04050         // Ensure the ptr is valid.
04051         if (pDlg)
04052         {
04053             // Send our DIM_CANCEL message.
04054             BROADCAST_TO_CLASS( DialogMsg( pDlg->WindowID, DIM_CANCEL, 0 ), DialogOp );
04055         }
04056 
04057         // The dialog has closed.
04058         ControlHelper::InformModalDialogClosed();
04059     }
04060 #endif
04061         
04062     // Everything ok.
04063     return TRUE;
04064 }
04065 
04066 /***********************************************************************************************************
04067 
04068 >   virtual BOOL GIFExportFileDialog::ExplorerInitDialog(wxWindow* hDlg)
04069 
04070     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
04071     Created:    07/07/97
04072     Returns:    TRUE if it worked else FALSE.
04073     Purpose:    Should be called when the explorer style dialog boxes need setting up.
04074             
04075 
04076 ************************************************************************************************************/
04077 BOOL GIFExportFileDialog::ExplorerInitDialog(wxWindow* hDlg)
04078 {
04079 PORTNOTE("other", "Remove MFC code" )
04080 #if !defined(EXCLUDE_FROM_XARALX)
04081     // Do nothing of not on explorer type dialog boxes
04082     if (!CCamApp::IsNewWindowsUI())
04083         return TRUE;
04084 
04085     // Set up and initialise any buttons and controls.
04086 
04087     //The "show preview"
04088     CheckDlgButton(_R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap != FALSE);
04089     
04090     // Get a handle to the options button.
04091     wxWindow* Icon = FindWindow( _R(IDC_FILEDLG_OPTIONS));
04092     
04093     // Ungrey the options button.
04094     ::EnableWindow(Icon, TRUE); 
04095 
04096     //Graham 27/10/97: And the "use as default" button
04097     Icon = FindWindow( _R(IDC_USEASDEFAULT));
04098     ::ShowWindow(Icon, SW_HIDE);
04099 #endif
04100     
04101     // Everything OK.
04102     return TRUE;
04103 }
04104 
04105 /********************************************************************************************
04106 
04107 >   SaveTemplateDialog::SaveTemplateDialog(PathName& pathToShowInDialog)
04108 
04109     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
04110     Created:    24/10/97
04111     Inputs:     pathToShowIngDialog     The path to show in the dialog
04112     Purpose:    Contructor
04113 
04114 ********************************************************************************************/
04115 
04116 SaveTemplateDialog::SaveTemplateDialog(PathName& pathToShowInDialog)
04117     : SaveFileDialog( PCTSTR( String_256( _R(IDS_NEWTEMPLATES_FILTER) ) ) , 
04118         String_256(pathToShowInDialog.GetLocation(TRUE)),
04119         String_256(pathToShowInDialog.GetFileName(TRUE)), String_256() )
04120 
04121 {
04122     m_fUseAsDefault=FALSE;
04123     m_fDefaultTemplatesFolder=TRUE;
04124     
04125     PrepareDialog();
04126 }
04127 
04128 
04129 /********************************************************************************************
04130 
04131 >   virtual BOOL SaveTemplateDialog::ExplorerInitDialog(wxWindow* hDlg)
04132 
04133     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
04134     Created:    24/10/97
04135     Returns:    TRUE if it worked, FALSE if it failed
04136     Purpose:    Should be called when the explorer style dialog boxes need setting up.
04137                 We can take this opportunity to add in any extra controls that we require.
04138     SeeAlso:    BaseFileDialog::ExplorerInitDialog; BaseFileDialog::OnHookMsg; BaseFileDialog::HookProc;
04139 
04140 ********************************************************************************************/
04141 
04142 BOOL SaveTemplateDialog::ExplorerInitDialog(wxWindow* hDlg)
04143 {
04144 PORTNOTE("other", "Remove MFC code" )
04145 #if !defined(EXCLUDE_FROM_XARALX)
04146     // Do nothing if not on explorer type dialog boxes
04147     if (!CCamApp::IsNewWindowsUI())
04148         return TRUE;
04149 
04150     // Set up and initialise the new buttons and controls
04151 
04152     //The "show preview"
04153     CheckDlgButton(_R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap != FALSE);
04154 
04155     //The "Use for all new drawings"
04156     CheckDlgButton(_R(IDC_USEASDEFAULT), FALSE);
04157 
04158     //And show the preview window   
04159     wxWindow* Icon = FindWindow( _R(IDC_PREVIEW));
04160     ::EnableWindow(Icon, TRUE);
04161 
04162     //But hide the options button
04163     Icon = FindWindow( _R(IDC_FILEDLG_OPTIONS));
04164     ::ShowWindow(Icon, SW_HIDE);
04165 
04166     // Move the Preview box down a little, so that it lines up with the List box
04167     wxWindow*   wndDlg = GetParent();
04168     wxWindow*   pWndPreview = GetDlgItem(_R(IDC_PREVIEW));
04169     wxRect      rPreview, rList;
04170     pWndPreview->GetWindowRect(&rPreview);
04171     ScreenToClient(rPreview);
04172     wxWindow*   pWndList = wndDlg->GetDlgItem(lst1);    // lst1 is the ID for the main list box
04173     pWndList->GetWindowRect(&rList);
04174     ScreenToClient(rList);
04175     pWndPreview->SetWindowPos(NULL, rPreview.GetLeft(), rList.GetTop(), rPreview.GetWidth(), rPreview.GetHeight(), 0);
04176 
04177     ExplorerInited = TRUE;
04178 #endif
04179 
04180     return TRUE;
04181 }
04182 
04183 /********************************************************************************************
04184 >   virtual void SaveFileDialog::DoDataExchange(CDataExchange* pDX)
04185 
04186     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
04187     Created:    27/5/95
04188     Inputs:     (a standard MFC object)
04189     Purpose:    Data exchange
04190 ********************************************************************************************/
04191 
04192 PORTNOTE("other", "Removed MFC junk" )
04193 #if !defined(EXCLUDE_FROM_XARALX)
04194 void SaveTemplateDialog::DoDataExchange(CDataExchange* pDX)
04195 {
04196     BaseFileDialog::DoDataExchange(pDX);
04197     //{{AFX_DATA_MAP(CMyDialog)
04198 #ifdef _DEBUG
04199     DDX_Check(pDX, _R(IDC_COMPRESS_BUTTON), CamelotNativeEPSFilter::CompressNative);
04200 #endif
04201 //  DDX_Check(pDX, _R(IDC_SAVEASWEB_BUTTON), SaveWebFile); //BaseCamelotFilter::ExportWebFile);
04202     if (CCamApp::IsNewWindowsUI())
04203     {
04204         DDX_Check(pDX, _R(IDC_SHOWPREVIEW), BaseFileDialog::ShowPreviewBitmap);
04205         DDX_Check(pDX, _R(IDC_USEASDEFAULT), SaveTemplateDialog::m_fUseAsDefault);
04206         //DDX_Check(pDX, _R(IDC_DEFAULTTEMPLATESFOLDER), SaveTemplateDialog::m_fDefaultTemplatesFolder);
04207     }
04208     //}}AFX_DATA_MAP
04209 }
04210 #endif
04211 
04212 /********************************************************************************************
04213 
04214 >   BOOL SaveTemplateDialog::PrepareDialog()
04215 
04216     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
04217     Created:    22/10/97
04218     Returns:    TRUE if it worked, FALSE if not
04219     Purpose:    Does anything the dialogs want doing after they have been created, but before
04220                 they are displayed
04221 
04222 ********************************************************************************************/
04223 
04224 BOOL SaveTemplateDialog::PrepareDialog()
04225 {
04226     // Set the title of the dialog
04227     m_strTitleOfDialog = String_256(_R(IDS_NEWTEMPLATES_TITLEOFDIALOG));
04228 
04229     wxFileDialog::SetTitle( (TCHAR*)m_strTitleOfDialog );
04230 
04231     // Select the desired path
04232     if (!DefaultPath.IsEmpty())
04233     {
04234         TRACEUSER( "jlh92", _T("TemplDir = %s\n"), PCTSTR(DefaultPath) );
04235         // Set the default path
04236         SetDirectory( DefaultPath );
04237     }
04238     else
04239     {
04240         // or use the global default path
04241         if (DefaultSaveFilePath.Length() > 0)
04242             SetDirectory( DefaultSaveFilePath );
04243     }
04244 
04245     // Do the same for the filename
04246     if (!DefaultName.IsEmpty())
04247         SetFilename( DefaultName );
04248 
04249     // See if the base class wants to do anything
04250     return TRUE;
04251 }
04252 
04253 /********************************************************************************************
04254 
04255 >   void SaveTemplateDialog::OnUseAsDefault()
04256 
04257     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
04258     Created:    27/10/97
04259     Returns:    -
04260     Purpose:    Called when the "Use As Default" switch is clicked on. This function
04261                 gets the value of the switch and puts it into our member variable.
04262 
04263                 (It seems that normal Data Exchange methods don't work if the control
04264                 is on an extension to the dialog)
04265 
04266 ********************************************************************************************/
04267 
04268 void SaveTemplateDialog::OnUseAsDefault()
04269 {
04270     m_fUseAsDefault = dynamic_cast<wxCheckBox*>( FindWindow( _R(IDC_USEASDEFAULT) ) )->IsChecked();
04271 }
04272 
04273 /********************************************************************************************
04274 
04275 >   void SaveTemplateDialog::OnDefaultTemplatesFolder()
04276 
04277     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
04278     Created:    28/10/97
04279     Returns:    -
04280     Purpose:    Called when the "Default templates folder" switch is clicked on. This function
04281                 gets the value of the switch and puts it into our member variable.
04282 
04283                 (It seems that normal Data Exchange methods don't work if the control
04284                 is on an extension to the dialog)
04285 
04286 ********************************************************************************************/
04287 
04288 void SaveTemplateDialog::OnDefaultTemplatesFolder()
04289 {
04290     // Do nothing.
04291 }
04292 
04293 
04294 /********************************************************************************************
04295 
04296 >   void SaveTemplateDialog::OnFileNameChange()
04297 
04298     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
04299     Created:    27/10/97
04300     Returns:    -
04301     Purpose:    Called when the user selects a new file. This checks the path of the file
04302                 against the default template path of the document type. If the paths
04303                 are the same, we put the "Use As Default" switch on.
04304         
04305 ********************************************************************************************/
04306 
04307 PORTNOTE("other", "Removed MFC junk" )
04308 #if !defined(EXCLUDE_FROM_XARALX)
04309 void SaveTemplateDialog::OnFileNameChange()
04310 {
04311 #if _MFC_VER >= 0x400
04312     if (!CCamApp::IsNewWindowsUI())
04313         return;
04314 
04315     //Get the new filename
04316     wxString cstrNameOfNewFile = GetPathName();
04317         
04318     // If its empty then return immediately
04319     if (cstrNameOfNewFile.IsEmpty())
04320         return;
04321 
04322     PathName pathOfNewFile(cstrNameOfNewFile.GetBuffer(256));
04323     
04324     cstrNameOfNewFile.ReleaseBuffer();
04325     
04326     if (!pathOfNewFile.IsValid())
04327     {
04328         // There was a problem e.g. user has typed f:
04329         // Magically a bad pathname sets an error so clear it!
04330         Error::ClearError();
04331         return;
04332     }
04333 
04334 #endif
04335 
04336     BaseFileDialog::OnFileNameChange();
04337 
04338     return;
04339 }
04340 #endif

Generated on Sat Nov 10 03:48:27 2007 for Camelot by  doxygen 1.4.4