[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : luke
Repository : xara
Revision   : 1712
Date       : Tue Aug 22 17:01:28 BST 2006

Changed paths:
   M /Trunk/XaraLX/wxOil/Makefile.am
   A /Trunk/XaraLX/wxOil/camdoctp.cpp
   A /Trunk/XaraLX/wxOil/camdoctp.h
   M /Trunk/XaraLX/wxOil/camelot.cpp
   M /Trunk/XaraLX/wxOil/camelot.h
   M /Trunk/XaraLX/wxOil/filedlgs.cpp
   M /Trunk/XaraLX/wxOil/menucmds.cpp

Allow bitmaps (and SVGs) to be imported via file\open route. (for BZ #1417). I'm not sure the position of import is correct though


Diff:
Index: Trunk/XaraLX/wxOil/menucmds.cpp
===================================================================
--- Trunk/XaraLX/wxOil/menucmds.cpp	(revision 1711)
+++ Trunk/XaraLX/wxOil/menucmds.cpp	(revision 1712)
@@ -302,8 +302,9 @@
 {
 	// OnFileOpen needs an event, but doesn't use it
 	wxCommandEvent		event;
-	AfxGetApp().GetDocumentManager()->SetLastDirectory(BaseFileDialog::DefaultOpenFilePath);
-	AfxGetApp().GetDocumentManager()->OnFileOpen( event );
+//	AfxGetApp().GetDocumentManager()->SetLastDirectory(BaseFileDialog::DefaultOpenFilePath);
+//	AfxGetApp().GetDocumentManager()->OnFileOpen( event );
+	AfxGetApp().OnFileOpen();
 	CCamDoc::EnableRemoveUntouchedDocs();		// Next idle event will try ro get rid of 
 												// the auto-created startup document
 }
Index: Trunk/XaraLX/wxOil/Makefile.am
===================================================================
--- Trunk/XaraLX/wxOil/Makefile.am	(revision 1711)
+++ Trunk/XaraLX/wxOil/Makefile.am	(revision 1712)
@@ -40,7 +40,7 @@
 	binreloc.c exceptio.cpp colpick.cpp dragpick.cpp sgldrag.cpp cctime.cpp \
 	lddirect.cpp prncamvw.cpp prdlgctl.cpp psdc.cpp grndprnt.cpp printprg.cpp \
 	oilruler.cpp bitmapdropdown.cpp helptabs.cpp tmplmngr.cpp imgmgkft.cpp ppmfiltr.cpp \
-	bitmapgriddropdown.cpp griddropdown.cpp \
+	bitmapgriddropdown.cpp griddropdown.cpp camdoctp.cpp \
 	resources.cpp
 
 # Keep resources.cpp on a separate line as it is odd
Index: Trunk/XaraLX/wxOil/camelot.h
===================================================================
--- Trunk/XaraLX/wxOil/camelot.h	(revision 1711)
+++ Trunk/XaraLX/wxOil/camelot.h	(revision 1712)
@@ -148,6 +148,8 @@
 
 	void OnFatalException();
 
+	void OnFileOpen();
+
 	void OnFilePrintSetup();
 
 	static BOOL LaunchWebBrowser(const wxString& strUrl);
@@ -158,6 +160,10 @@
 private:
 	INT32 RunFalseMainLoop();
 
+	wxDocument* OpenDocumentFile( PCTSTR lpcszFileName );
+	void AddToRecentFileList( LPCTSTR pPathName );
+	BOOL MakeDocumentNative(wxDocument* pDoc, PathName* Path);
+
 protected:
 	std::auto_ptr<wxDocManager> m_docManager;
 	CCamFrame			   *m_pMainFrame;
Index: Trunk/XaraLX/wxOil/camdoctp.cpp
===================================================================
--- Trunk/XaraLX/wxOil/camdoctp.cpp	(revision 0)
+++ Trunk/XaraLX/wxOil/camdoctp.cpp	(revision 1712)
@@ -0,0 +1,235 @@
+// $Id: wxOil/camdoctp.cpp, 1, 01-Jan-2006, Anonymous $
+/* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
+================================XARAHEADERSTART===========================
+ 
+               Xara LX, a vector drawing and manipulation program.
+                    Copyright (C) 1993-2006 Xara Group Ltd.
+       Copyright on certain contributions may be held in joint with their
+              respective authors. See AUTHORS file for details.
+
+LICENSE TO USE AND MODIFY SOFTWARE
+----------------------------------
+
+This file is part of Xara LX.
+
+Xara LX is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 as published
+by the Free Software Foundation.
+
+Xara LX and its component source files are distributed in the hope
+that it will be useful, but WITHOUT ANY WARRANTY; without even the
+implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with Xara LX (see the file GPL in the root directory of the
+distribution); if not, write to the Free Software Foundation, Inc., 51
+Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+
+ADDITIONAL RIGHTS
+-----------------
+
+Conditional upon your continuing compliance with the GNU General Public
+License described above, Xara Group Ltd grants to you certain additional
+rights. 
+
+The additional rights are to use, modify, and distribute the software
+together with the wxWidgets library, the wxXtra library, and the "CDraw"
+library and any other such library that any version of Xara LX relased
+by Xara Group Ltd requires in order to compile and execute, including
+the static linking of that library to XaraLX. In the case of the
+"CDraw" library, you may satisfy obligation under the GNU General Public
+License to provide source code by providing a binary copy of the library
+concerned and a copy of the license accompanying it.
+
+Nothing in this section restricts any of the rights you have under
+the GNU General Public License.
+
+
+SCOPE OF LICENSE
+----------------
+
+This license applies to this program (XaraLX) and its constituent source
+files only, and does not necessarily apply to other Xara products which may
+in part share the same code base, and are subject to their own licensing
+terms.
+
+This license does not apply to files in the wxXtra directory, which
+are built into a separate library, and are subject to the wxWindows
+license contained within that directory in the file "WXXTRA-LICENSE".
+
+This license does not apply to the binary libraries (if any) within
+the "libs" directory, which are subject to a separate license contained
+within that directory in the file "LIBS-LICENSE".
+
+This license does not apply to the clipart within the directory
+filters/clipart/OpenClipart. These have kindly been put into the
+public domain by their authors. See http://www.openclipart.org/
+
+
+ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
+----------------------------------------------
+
+Subject to the terms of the GNU Public License (see above), you are
+free to do whatever you like with your modifications. However, you may
+(at your option) wish contribute them to Xara's source tree. You can
+find details of how to do this at:
+  http://www.xaraxtreme.org/developers/
+
+Prior to contributing your modifications, you will need to complete our
+contributor agreement. This can be found at:
+  http://www.xaraxtreme.org/developers/contribute/
+
+Please note that Xara will not accept modifications which modify any of
+the text between the start and end of this header (marked
+XARAHEADERSTART and XARAHEADEREND).
+
+
+MARKS
+-----
+
+Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
+designs are registered or unregistered trademarks, design-marks, and/or
+service marks of Xara Group Ltd. All rights in these marks are reserved.
+
+
+      Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
+                        http://www.xara.com/
+
+=================================XARAHEADEREND============================
+ */
+
+
+#include "camtypes.h"
+#include "camdoctp.h"			// document template
+#include "camdoc.h"				// document
+//#include "ccmdikid.h"			// view frame
+//#include "scrcamvw.h"  			// screen view
+#include "appstate.h"
+#include "errors.h"
+//#include "mfccopy.h"
+#include "camelot.h"
+#include "clipint.h"
+
+IMPLEMENT_CLASS(CCamDocTemplate, wxDocTemplate);
+DECLARE_SOURCE("$Revision: 25 $");
+
+
+
+CCamDocTemplate::CCamDocTemplate( wxDocManager* pManager, const wxString& descr, const wxString& filter, 
+		const wxString& dir, const wxString& ext, const wxString& docTypeName, const wxString& viewTypeName, 
+		wxClassInfo* docClassInfo, wxClassInfo* viewClassInfo )
+ : wxDocTemplate( pManager, descr, filter, dir, ext, docTypeName, viewTypeName, docClassInfo, viewClassInfo )
+{
+#if 0
+	if (m_hMenu != NULL)
+	{
+		::DestroyMenu(m_hMenuShared);
+		m_hMenuShared = m_hMenu;
+	}
+		
+	if (m_hAccelTable != NULL)
+		m_hAccelTable = m_hAccelTable;
+	
+	#ifdef _DEBUG
+		// warnings about missing components (don't bother with accelerators)
+		if (m_hMenuShared == NULL)
+			TRACE1("Warning: no shared menu for document template #%d
", nIDResource);
+	#endif //_DEBUG
+
+#if _MFC_VER >= 0x400
+	// Strangeness we need to do here to create the DocManager as our derived version instead
+	// of MFC's version, so we can over-ride DoPromptFilename() - see mfccopy.cpp/h. (Tim)
+	// This code fragment taken from mfc\src\doctempl.cpp (MFC4).
+
+	// Er, Richard here... Defining _AFXDLL and using the MD version of MFC seems not to
+	// contain this bStaticInit stuff. This needs looking into...
+	if (CDocManager::bStaticInit)
+	{
+		if (CDocManager::pStaticDocManager == NULL)
+			CDocManager::pStaticDocManager = new CamelotDocManager;
+	}
+#endif // _MFC_VER >= 0x400
+#endif
+}
+
+
+
+/********************************************************************************************
+
+>	CDocTemplate::Confidence CCamDocTemplate::MatchDocType(LPCTSTR lpszPathName, CDocument*& rpDocMatch)
+
+	Author:		Rik_Heywood (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	9/5/95
+	Purpose:	This function has been overiden from its MFC version. It is actually
+				identical apart from the bit that checks to see if the document is already
+				open. The MFC version of the function goes and looks at the files involved
+				by calling AfxComparePaths(), but we just compare the paths. This stops the
+				floppy drive from being accessed all the time if you have a document opened
+				from a floppy drive (it also stops network problems if the conection to
+				an open document goes away). I am not too sure what all the params mean.
+
+********************************************************************************************/
+
+#ifndef _MAC
+CCamDocTemplate::Confidence CCamDocTemplate::MatchDocType(LPCTSTR lpszPathName, wxDocument*& rpDocMatch)
+#else
+CCamDocTemplate::Confidence CCamDocTemplate::MatchDocType(LPCTSTR lpszPathName, DWORD dwFileType,
+													   wxDocument*& rpDocMatch)
+#endif
+{
+	ASSERT(lpszPathName != NULL);
+	rpDocMatch = NULL;
+
+	// go through all documents
+	wxList&				listDocuments = GetDocumentManager()->GetDocuments();
+	wxNode*				pNode = listDocuments.GetFirst();
+	while (pNode != NULL)
+	{
+		// Get the next document
+		CCamDoc* pDoc = (CCamDoc*)pNode->GetData();
+
+	#if (_OLE_VER >= 0x200)
+		// Don't consider embedded or hidden docs.
+		if (pDoc->IsEmbedded() || pDoc->GetKernelDoc()->IsAHiddenDoc()) continue;
+	#endif
+
+		// Find out the names of the old and new documents
+		wxString OldDocName  = pDoc->GetFilename();
+		wxString OrigDocName = wxString((LPCTSTR) pDoc->GetOriginalPath());
+		wxString NewDocName  = wxString(lpszPathName);
+		OldDocName.MakeLower();
+		OrigDocName.MakeLower();
+		NewDocName.MakeLower();
+
+		// Test if the docs refer to the same existing .ART file or if the two docs are based
+		// on the same existing non-.ART file.
+		BOOL fSameArtFiles = (OldDocName == NewDocName);
+		BOOL fSameNonArtFiles = (OldDocName.IsEmpty() && OrigDocName == NewDocName);
+
+		// see if they are the same
+		if (fSameArtFiles || fSameNonArtFiles)
+		{
+			// already open
+			TRACEUSER("JustinF", _T("File %s is already open
"),  (LPCTSTR) lpszPathName);
+			rpDocMatch = pDoc;
+			return yesAlreadyOpen;
+		}
+
+		pNode = pNode->GetNext();
+	}
+
+	// see if it matches our default suffix
+	if( !m_defaultExt.IsEmpty() )
+	{
+		// see if extension matches
+		LPCTSTR			lpszDot = camStrrchr( lpszPathName, _T('.') );
+		if( NULL != lpszDot && 
+			0 == camStricmp( lpszDot + 1, m_defaultExt ) )
+			return yesAttemptNative; // extension matches, looks like ours
+	}
+
+	// otherwise we will guess it may work
+	return yesAttemptForeign;
+}
Index: Trunk/XaraLX/wxOil/camdoctp.h
===================================================================
--- Trunk/XaraLX/wxOil/camdoctp.h	(revision 0)
+++ Trunk/XaraLX/wxOil/camdoctp.h	(revision 1712)
@@ -0,0 +1,147 @@
+// $Id: wxOil/camdoctp.h, 1, 01-Jan-2006, Anonymous $
+/* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
+================================XARAHEADERSTART===========================
+ 
+               Xara LX, a vector drawing and manipulation program.
+                    Copyright (C) 1993-2006 Xara Group Ltd.
+       Copyright on certain contributions may be held in joint with their
+              respective authors. See AUTHORS file for details.
+
+LICENSE TO USE AND MODIFY SOFTWARE
+----------------------------------
+
+This file is part of Xara LX.
+
+Xara LX is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 as published
+by the Free Software Foundation.
+
+Xara LX and its component source files are distributed in the hope
+that it will be useful, but WITHOUT ANY WARRANTY; without even the
+implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with Xara LX (see the file GPL in the root directory of the
+distribution); if not, write to the Free Software Foundation, Inc., 51
+Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+
+ADDITIONAL RIGHTS
+-----------------
+
+Conditional upon your continuing compliance with the GNU General Public
+License described above, Xara Group Ltd grants to you certain additional
+rights. 
+
+The additional rights are to use, modify, and distribute the software
+together with the wxWidgets library, the wxXtra library, and the "CDraw"
+library and any other such library that any version of Xara LX relased
+by Xara Group Ltd requires in order to compile and execute, including
+the static linking of that library to XaraLX. In the case of the
+"CDraw" library, you may satisfy obligation under the GNU General Public
+License to provide source code by providing a binary copy of the library
+concerned and a copy of the license accompanying it.
+
+Nothing in this section restricts any of the rights you have under
+the GNU General Public License.
+
+
+SCOPE OF LICENSE
+----------------
+
+This license applies to this program (XaraLX) and its constituent source
+files only, and does not necessarily apply to other Xara products which may
+in part share the same code base, and are subject to their own licensing
+terms.
+
+This license does not apply to files in the wxXtra directory, which
+are built into a separate library, and are subject to the wxWindows
+license contained within that directory in the file "WXXTRA-LICENSE".
+
+This license does not apply to the binary libraries (if any) within
+the "libs" directory, which are subject to a separate license contained
+within that directory in the file "LIBS-LICENSE".
+
+This license does not apply to the clipart within the directory
+filters/clipart/OpenClipart. These have kindly been put into the
+public domain by their authors. See http://www.openclipart.org/
+
+
+ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
+----------------------------------------------
+
+Subject to the terms of the GNU Public License (see above), you are
+free to do whatever you like with your modifications. However, you may
+(at your option) wish contribute them to Xara's source tree. You can
+find details of how to do this at:
+  http://www.xaraxtreme.org/developers/
+
+Prior to contributing your modifications, you will need to complete our
+contributor agreement. This can be found at:
+  http://www.xaraxtreme.org/developers/contribute/
+
+Please note that Xara will not accept modifications which modify any of
+the text between the start and end of this header (marked
+XARAHEADERSTART and XARAHEADEREND).
+
+
+MARKS
+-----
+
+Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
+designs are registered or unregistered trademarks, design-marks, and/or
+service marks of Xara Group Ltd. All rights in these marks are reserved.
+
+
+      Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
+                        http://www.xara.com/
+
+=================================XARAHEADEREND============================
+ */
+
+/*
+ *  */
+
+#ifndef INC_CAMDOCTP
+#define INC_CAMDOCTP
+
+
+/********************************************************************************************
+>	class CCamDocTemplate : public CMultiDocTemplate
+
+	Author:		Justin_Flude (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	sometime in '93 (sorry!)
+	Purpose:	Allows the customisation of the process MFC uses to create, load,
+				and associate its view and document classes.
+	SeeAlso:	CCamDoc; CCamMDIChild; CCamView
+********************************************************************************************/
+
+class CCamDocTemplate : public wxDocTemplate
+{
+	DECLARE_CLASS(CCamDocTemplate)
+
+public:
+	enum Confidence
+	{
+		noAttempt,
+		maybeAttemptForeign,
+		maybeAttemptNative,
+		yesAttemptForeign,
+		yesAttemptNative,
+		yesAlreadyOpen
+	};
+
+public:
+	CCamDocTemplate( wxDocManager* pManager, const wxString& descr, const wxString& filter, 
+		const wxString& dir, const wxString& ext, const wxString& docTypeName, 
+		const wxString& viewTypeName, wxClassInfo* docClassInfo, wxClassInfo* viewClassInfo );
+	#ifndef _MAC
+		virtual Confidence MatchDocType(LPCTSTR lpszPathName, wxDocument*& rpDocMatch);
+	#else
+		virtual Confidence MatchDocType(LPCTSTR lpszFileName, DWORD dwFileType,
+										wxDocument*& rpDocMatch);
+	#endif
+};
+
+#endif
Index: Trunk/XaraLX/wxOil/camelot.cpp
===================================================================
--- Trunk/XaraLX/wxOil/camelot.cpp	(revision 1711)
+++ Trunk/XaraLX/wxOil/camelot.cpp	(revision 1712)
@@ -118,6 +118,7 @@
 
 #include "cversion.h"
 #include "camelot.h"
+#include "camdoctp.h"
 
 #include "keypress.h"
 #include "ccdc.h"
@@ -133,6 +134,9 @@
 #include "prdlgctl.h"
 #include "prncamvw.h"
 #include "gbrush.h"
+#include "csrstack.h"
+#include "selmedia.h"
+#include "filedlgs.h"
 
 #include "camprocess.h"
 
@@ -852,12 +856,12 @@
 	m_docManager = std::auto_ptr<wxDocManager>( new wxDocManager() );
 
 	wxDocTemplate	   *pDocTemplate;
-	pDocTemplate = new wxDocTemplate(
+	pDocTemplate = new CCamDocTemplate(
 		m_docManager.get(), wxT("Xara"), wxT("*.xar;*.web"), wxT(""), wxT("xar"), wxT("Xara document"), 
 		wxT("Text View"),
 		CLASSINFO(CCamDoc),
 		CLASSINFO(CCamView) );
-//	pDocTemplate = new wxDocTemplate(
+//	pDocTemplate = new CCamDocTemplate(
 //		m_docManager.get(), wxT("Xara"), wxT("*.web"), wxT(""), wxT("web"), wxT("Xara document"), 
 //		wxT("Text View"),
 //		CLASSINFO(CCamDoc),
@@ -1276,6 +1280,380 @@
 
 /********************************************************************************************
 
+>	void CCamApp::OnFileOpen()
+
+	Author:		Rik
+	Created:	14/2/95
+	Purpose:	Displays the File Open dialog and opens whichever file was selected.
+
+********************************************************************************************/
+
+void CCamApp::OnFileOpen()
+{
+#ifndef EXCLUDE_FROM_RALPH
+	// Build the list of filters
+	int NativeFilterPos = 0;
+	TCHAR* pFilters = OpenFileDialog::BuildFilterString(&NativeFilterPos);
+
+	TRACEUSER( "luke", _T("Filters = %s"), pFilters );
+
+	// Set up the dialog
+	OpenFileDialog OpenDialog(pFilters);
+	OpenDialog.NativeFilterPos = NativeFilterPos;
+	OpenDialog.PrepareDialog();		
+	
+	// Display the dialog and get the filename we require
+	BOOL Result = OpenDialog.OpenAndGetFileName();
+
+	// Free up the memory allocated by BuildFilterString
+	CCFree(pFilters);
+
+	// If they did not click on OK then stop right now
+	if (!Result)
+		return;
+
+	// Remember the filter for later in the opening sequence
+	OpenDialog.SelectedFilter = OpenDialog.GetSelectedFilterIndex();
+
+	// Get the filename, ensuring that the path is valid
+	PathName Path;
+	OpenDialog.GetChosenFileName(&Path);
+	String_256 Str = Path.GetPath();
+
+	// Extract directory name (minus terminating backslash) and remember for next time.
+	OpenDialog.SetDefaultPath(Path.GetLocation(FALSE));
+
+	// Andy Hills, 05-02-2001
+	// Fix for bug 6712:
+
+	// Delete the preview bitmap, if present.
+	// If we don't delete it here, when we call OpenDocumentFile (below)
+	// all global bitmaps are deleted (as part of the process of closing all
+	// existing documents), including the preview bitmap.
+	// Unfortunately, the OILBitmap is deleted without deleting the
+	// KernelBitmap which owns it; thus, at the end of this function, when the
+	// file dialogue is destructed, Camelot tries to destruct the preview
+	// bitmap even though its ActualBitmap has already been deleted, causing
+	// an access violation.
+	// It is safer to destroy both the kernel bitmap and (implicitly) its
+	// OILBitmap here.
+
+PORTNOTE( "other" ,"Removed open preview clean-up" )
+#ifndef EXCLUDE_FROM_XARALX
+	// There is a more general problem, in that when we close all documents
+	// we get rid of all global bitmaps. I don't believe it is safe to assume
+	// that all global bitmaps belong to the documents which are being closed.
+	// I.e. I think we should only delete bitmaps which we are sure belong to
+	// the documents.
+	if (OpenDialog.pBitmapToUse != NULL)
+	{
+		delete OpenDialog.pBitmapToUse;
+		OpenDialog.pBitmapToUse = NULL;
+	}
+#endif
+
+	// and open the file. if returns NULL, the user has already been alerted
+	wxDocument* pDoc = OpenDocumentFile( Str );
+	if (pDoc!=NULL)
+	{
+		// Make sure that the files name is sensible
+		MakeDocumentNative(pDoc, &Path);
+		
+		// add it to the recent file list
+		AddToRecentFileList( PCTSTR(Str) );
+
+		// ... and set the path as the "original" path to the doc.  This will be used to 
+		// "restore" the doc when we next run, if it was open when we shut down.
+		((CCamDoc*) pDoc)->SetOriginalPath(Str);
+	}
+#endif
+}
+
+
+/********************************************************************************************
+
+>	virtual void CCamApp::AddToRecentFileList(LPCTSTR pPathName)
+
+	Author:		Rik
+	Created:	8/5/95
+	Inputs:		pPathName - the full path name of the file to add to the list
+	Purpose:	Adds the file to the recent file list
+
+********************************************************************************************/
+
+void CCamApp::AddToRecentFileList(LPCTSTR pPathName)
+{
+PORTNOTE( "filelist" ,"I don't think this is needed since this all happen automatically" )
+#if !defined(EXCLUDE_FROM_XARALX) && !defined(EXCLUDE_FROM_RALPH)
+	// Make sure we have not been passed a load of junk
+	ERROR3IF(pPathName==NULL, "NULL path name in AddToRecentFilelist
");
+
+	// Make sure that there is a recent file list, but bodge it so that OpenHiddenDocument
+	// does not add to the list!
+	if (pFileList!=NULL)
+	{
+		// Add the file to it
+		pFileList->Add(pPathName);
+	}
+#endif
+}
+
+
+/********************************************************************************************
+>	virtual CDocument* CCamApp::OpenDocumentFile(LPCTSTR lpcszFileName)
+
+	Author:		JustinF
+	Created:	4/7/95
+	Inputs:		lpcszFileName				path to the document file to load
+	Returns:	A pointer to the MFC CDocument object that manages the opened file, or
+				NULL if it can't be loaded for some reason.
+	Purpose:	We override this implementation function so that when the user tries to
+				load a document that is already loaded, we can display a dialog box with
+				various load options, instead of simply bringing the document's view
+				to the front.
+
+				This function is largely copied from the MFC equivalent in APPUI.CPP.
+	Errors:		-
+	SeeAlso:	-
+********************************************************************************************/
+
+wxDocument* CCamApp::OpenDocumentFile( PCTSTR lpcszFileName )
+{
+	// find the highest confidence
+
+	wxList&				listTemplates( GetDocumentManager()->GetTemplates() );
+	wxNode*				pNode = listTemplates.GetFirst();
+
+	CCamDocTemplate::Confidence bestMatch = CCamDocTemplate::noAttempt;
+	CCamDocTemplate*	pBestTemplate = NULL;
+	wxDocument*			pOpenDocument = NULL;
+	wxDocument*			pNewDoc		  = NULL;
+
+	TCHAR				szPath[_MAX_PATH + 1];
+	{
+		wxFileName		FileName( lpcszFileName );
+		camStrncpy( szPath, FileName.GetFullPath(), _MAX_PATH );
+	}
+
+	while (pNode != NULL)
+	{
+		CCamDocTemplate* pTemplate = (CCamDocTemplate*)pNode->GetData();
+		ASSERT( pTemplate->IsKindOf( CLASSINFO(CCamDocTemplate) ) );
+
+		CCamDocTemplate::Confidence match;
+		ASSERT(pOpenDocument == NULL);
+		match = pTemplate->MatchDocType(szPath, pOpenDocument);
+
+		if (match > bestMatch)
+		{
+			bestMatch = match;
+			pBestTemplate = pTemplate;
+		}
+
+		if (match == CCamDocTemplate::yesAlreadyOpen) break;
+
+		pNode= pNode->GetNext();
+	}
+
+	if (pOpenDocument != NULL)
+	{
+		// Make sure it really is one of ours.
+		ERROR3IF( !pOpenDocument->IsKindOf( CLASSINFO(CCamDoc) ),
+					_T("Not a CCamDoc in CCamApp::OpenDocumentFile") );
+
+		wxList&			lstViews( pOpenDocument->GetViews() );
+		wxNode*			pNode = lstViews.GetFirst();
+		if( NULL != pNode )
+		{
+			// Get the first view.
+			wxView*		pView = (wxView*)pNode->GetData();
+			wxMDIChildFrame* pFrame = (wxMDIChildFrame*)pView->GetFrame();
+			
+			// Now deal with the view window.
+			if (pFrame != NULL)
+			{
+				// Run a message box to find out what the user wants to do on trying
+				// to load a document that is already loaded.  To begin, if we can't
+				// find a document template just bring the view to the front.
+				if (pBestTemplate == NULL)
+				{
+					pFrame->Activate();
+				}
+				else
+				{
+					// If the document is modified then we may have to ask the user what they
+					// want to do, ie. revert to original, load copy, do nothing.
+					int nResult;
+					if (pOpenDocument->IsModified())
+					{
+						// OK, we have a modified document.  Run the message box to find out what
+						// the user wants to do.
+						nResult = InformWarning( _R(IDE_DOC_ALREADY_OPEN),
+												_R(IDS_REVERT_BTN), _R(IDS_DETACH_BTN), _R(IDS_CANCEL), 0,
+												2, 3);
+					}
+					else
+					{
+						// If the document isn't modified then force a "load copy".
+						// no if the document is already loaded just keep the view we have (sjk 3/2/00)
+						nResult = 3;
+					}
+
+					switch (nResult)
+					{
+					case 1:
+					{
+						// REVERT.  Reload the already-open doc, discarding unsaved changes.
+						((CCamDoc*) pOpenDocument)->SetModified(FALSE);
+						pOpenDocument->OnCloseDocument();
+						pNewDoc = pBestTemplate->CreateDocument( szPath );
+						goto PerformLoad;
+					}
+
+					case 2:
+					{
+						// DETACH.  Load the doc as an "untitled" one, making sure it won't
+						// save over the already-open doc.
+						wxDocument* pCopyDoc = pBestTemplate->CreateDocument( szPath );
+						if (pCopyDoc != NULL)
+						{
+							// We managed to load the doc to detach, so now we detach it.
+							// To do this we set its path to nothing, after saving the
+							// original path.
+							((CCamDoc*) pCopyDoc)->SetOriginalPath(szPath);
+							((CCamDoc*) pCopyDoc)->SetPathNameEmpty();
+							((CCamDoc*) pCopyDoc)->SetCopy(TRUE);
+
+							goto PerformLoad;
+						}
+					#ifdef _DEBUG
+						else
+						{
+							// Oh no, we failed to load the detached doc, so we have to
+							// fail this one.
+							TRACEUSER("JustinF", _T("Couldn't load doc to detach!
") );
+							pFrame->Activate();
+						}
+					#endif						
+						return NULL;
+					}
+
+					case 3:
+						// CANCEL.  Don't load, just bring the already-open doc to the front.
+						pFrame->Activate();
+						break;
+
+					default:
+						ERROR3( _T("Bad return val from message box in CCamApp::OpenDocumentFile") );
+						break;
+					}
+				}
+			}
+			else
+				TRACE0( _T("Error: Can not find a frame for document to activate.
") );
+		}
+		else
+		{
+			TRACE0( _T("Error: Can not find a view for document to activate.
") );
+		}
+
+		return pOpenDocument;
+	}
+
+	if (pBestTemplate == NULL)
+	{
+		String_256		strReport( _R(AFX_IDP_FAILED_TO_OPEN_DOC) );
+		wxMessageBox( (PCTSTR)strReport );
+		return NULL;
+	}
+
+	pNewDoc =  pBestTemplate->CreateDocument( szPath );
+
+PerformLoad:
+	if( NULL == pNewDoc )
+		return NULL;
+
+	pNewDoc->SetDocumentName( pBestTemplate->GetDocumentName() );
+	pNewDoc->SetDocumentTemplate( pBestTemplate );
+	if( !pNewDoc->OnOpenDocument( szPath ) )
+	{
+		pNewDoc->DeleteAllViews();
+		pNewDoc = NULL;
+	}
+
+	return pNewDoc;
+}
+
+
+
+/********************************************************************************************
+
+>	BOOL CCamApp::MakeDocumentNative(CDocument* pDoc, PathName* Path)
+
+	Author:		Rik
+	Created:	14/2/95
+	Inputs:		pDoc - The document to test and change
+				Path - the path of the original document name
+	Outputs:	Path - This will have the extension modified if the function returned TRUE
+	Returns:	TRUE if it changed the document, FALSE if it did not
+	Purpose:	If you attemp to open a BMP or any other non native file, it will have a
+				bad document name (ending in .bmp or whatever, instead of .art). It also
+				causes problems when pressing save, as the original non native file can
+				be overwritten with a native file version. This makes sure that the user
+				will always be asked where they want to save it when it comes to saving
+				time by throwing away the know path info.
+	SeeAlso:	CCamApp::OnRecentFile; CCamApp::OnFileOpen
+
+********************************************************************************************/
+
+BOOL CCamApp::MakeDocumentNative( wxDocument* pDoc, PathName* Path )
+{
+	// Only bother if the was actually a document to process
+	if (pDoc==NULL)
+		return FALSE;
+
+	// Set the extension of the file to be .xar
+	String_256 Extension( _R(IDS_DEFAULT_EXTENSION) );
+	String_256 OldExtension = Path->GetType();
+	// make sure they are of the same case
+	Extension.toLower();
+	OldExtension.toLower();
+#if NEW_NATIVE_FILTER
+	String_256 NewExtension(IDS_DEFAULT_EXTENSION);
+	NewExtension.toLower();
+	// see if the extension is .xar or .cxn
+	if (Extension != OldExtension && OldExtension != NewExtension)
+#else
+	// see if the extension is .xar
+	if (Extension != OldExtension)
+#endif
+	{
+		Path->SetType(Extension);
+
+		// Find out some of the details about the filename
+		String_256 FileName = Path->GetFileName();
+
+		// Set the title of and path of the document
+		// we set the path to blank, so that we will always be prompted for a real filename
+		((CCamDoc*)pDoc)->SetTitle( FileName );
+		pDoc->SetFilename( FileName, true );
+		((CCamDoc*)pDoc)->SetPathNameEmpty();
+
+		TRACEUSER( "luke", _T("New name %s"), PCTSTR(FileName) );
+
+		// Tell 'em we changed things
+		return TRUE;
+	}
+
+	// Nothing changed
+	return FALSE;
+}
+
+
+
+/********************************************************************************************
+ *
+
 >	void CCamApp::OnRecentFile(INT32 RecentFileNumber)
 
 	Author:		Rik_Heywood (Xara Group Ltd) <camelotdev@xxxxxxxx>
Index: Trunk/XaraLX/wxOil/filedlgs.cpp
===================================================================
--- Trunk/XaraLX/wxOil/filedlgs.cpp	(revision 1711)
+++ Trunk/XaraLX/wxOil/filedlgs.cpp	(revision 1712)
@@ -2486,7 +2486,7 @@
 	FilterSize += 2;
 
 	// Try to get this string
-	TCHAR*	FilterString = (TCHAR*)CCMalloc(FilterSize);
+	TCHAR*	FilterString = (TCHAR*)CCMalloc( FilterSize * sizeof(TCHAR) );
 	if (FilterString==NULL)
 		// Error state already set by CCMalloc
 		return NULL;


Xara