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

[XaraXtreme-dev] Open file, get standard colours



I noticed a problem when opening a file (not importing) that is not a
XAR file. Since it is not a XAR file, when the document is opened, no
colours are added to the colour line. This itself is not so bad, as
named colours are specific to Xara, but it reeks havoc on other parts of
the software that expects the list of colours to be non-empty.

For example, wxAsserts pop up when the colour dialog is opened. It's top
drop-down combo box expects at least one named colour.

Also, it seems like the correct thing to do in this situation is to give
the user the standard set of colours anyway. That way, they don't have
to worry about opening or importing a document, and are given a sane set
of defaults when opening.

To that end, I have modified the CCamDoc::OnOpenDocument function. At
the end of the routine, I added a check to see if the document has any
colours. If it does not, I add the standard set of colours.

After some searching, I realized that the "standard set of colours",
really means the list of colours saved with the template XAR file, and
is not listed in any code form. I also noticed some useful code in the
CDRFilter stuff. I don't think that code is being used currently. So I
took the relevant code from those files and put them into the
impcol.(cpp|h) files. Now there is a static member function of
ImportColours called AddStandardColourSet which takes a pointer to a
document and adds the standard colours to it.

One thing that does not happen properly is that the shades of gray are
not tints of black, but individual colors. I believe I can fix that, but
this is a good start.
Index: Kernel/impcol.h
===================================================================
--- Kernel/impcol.h	(revision 1775)
+++ Kernel/impcol.h	(working copy)
@@ -342,6 +342,7 @@
 	// record number or colour reference
 	IndexedColour *GetColour(INT32 ReqRecordNumber);
 
+	static BOOL AddStandardColourSet(Document*);
 protected:
 	// The sort comparator we use for SortColoursByEntryNumber()
 	static INT32 __cdecl SortComparator(const void *Item1, const void *Item2);
Index: Kernel/impcol.cpp
===================================================================
--- Kernel/impcol.cpp	(revision 1775)
+++ Kernel/impcol.cpp	(working copy)
@@ -1610,3 +1610,120 @@
 
 	return((pColourItem1->EntryNumber == pColourItem2->EntryNumber) ? 0 : 1);
 }
+
+typedef struct {
+	BYTE C, M, Y, K;
+	TCHAR *Name;
+} StandardColour;
+
+static StandardColour StandardColours[] = {
+	{0,		100,	100,	0,	_T("Red")},
+	{0,		75,		100,	0,	_T("Orange-Red")},
+	{0,		50,		100,	0,	_T("Orange")},
+	{0,		25,		100,	0,	_T("Orange-Yellow")},
+	{0,		0,		100,	0,	_T("Yellow")},
+	{25,	0,		100,	0,	_T("Yellow-Chartreuse")},
+	{50,	0,		100,	0,	_T("Chartreuse")},
+	{75,	0,		100,	0,	_T("Chartreuse-Green")},
+	{100,	0,		100,	0,	_T("Green")},
+	{100,	0,		75,		0,	_T("Green-SpringGreen")},
+	{100,	0,		50,		0,	_T("Spring Green")},
+	{100,	0,		25,		0,	_T("SpringGreen-Cyan")},
+	{100,	0,		0,		0,	_T("Cyan")},
+	{100,	25,		0,		0,	_T("Sky Blue")},
+	{100,	50,		0,		0,	_T("Mid Blue")},
+	{100,	75,		0,		0,	_T("MidBlue-Blue")},
+	{100,	100,	0,		0,	_T("Blue")},
+	{75,	100,	0,		0,	_T("Blue-Indigo")},
+	{50,	100,	0,		0,	_T("Indigo")},
+	{25,	100,	0,		0,	_T("Violet")},
+	{0,		100,	0,		0,	_T("Magenta")},
+	{0,		100,	25,		0,	_T("Magenta-Crimson")},
+	{0,		100,	50,		0,	_T("Crimson")},
+	{0,		100,	75,		0,	_T("Crimson-Red")},
+	{0,	0,	0,	100,	_T("Black")},
+	{0,	0,	0,	90,	_T("90% Black")},
+	{0,	0,	0,	80,	_T("80% Black")},
+	{0,	0,	0,	70,	_T("70% Black")},
+	{0,	0,	0,	60,	_T("60% Black")},
+	{0,	0,	0,	50,	_T("50% Black")},
+	{0,	0,	0,	40,	_T("40% Black")},
+	{0,	0,	0,	30,	_T("30% Black")},
+	{0,	0,	0,	20,	_T("20% Black")},
+	{0,	0,	0,	10,	_T("10% Black")},
+	{0,	0,	0,	0,	_T("White")},
+};
+
+/********************************************************************************************
+
+>	BOOL ImportedColours::AddStandardColourSet(Document *pDocument)
+
+	Author:		Ben_Summers (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	05/06/95
+	Inputs:		
+	Returns:	
+	Purpose:	Adds the standard set of colours to a Corel file
+
+********************************************************************************************/
+
+BOOL ImportedColours::AddStandardColourSet(Document *pDocument)
+{
+	ColourListComponent *pColours = 0;
+
+	DocComponent *pComponent = pDocument->EnumerateDocComponents(NULL);
+
+	while (pComponent != NULL)
+	{
+		// If this is the colour component, remember it
+		if (pComponent->GetRuntimeClass() == CC_RUNTIME_CLASS(ColourListComponent))
+		{
+			pColours = (ColourListComponent *) pComponent;
+			break;
+		}
+
+		// Look for next doc component
+		pComponent = pDocument->EnumerateDocComponents(pComponent);
+	}
+
+	if(pColours == 0)
+		return TRUE;			// can't be bothered to complain nicely about this very unlikely error
+
+	// get an importedcolours object
+	ImportedColours *pNewColours = new ImportedColours(pColours, FALSE);
+	if(pNewColours == 0 || !pNewColours->Init())
+		return FALSE;
+
+	BOOL ok = TRUE;
+
+	// add colours to it...
+	ColourCMYK NewColour;
+	for(UINT32 l = 0; l < (sizeof(StandardColours) / sizeof(StandardColour)); l++)
+	{
+		NewColour.Cyan = ((double)StandardColours[l].C) / 100;
+		NewColour.Magenta = ((double)StandardColours[l].M) / 100;
+		NewColour.Yellow = ((double)StandardColours[l].Y) / 100;
+		NewColour.Key = ((double)StandardColours[l].K) / 100;
+		
+		String_64 ColNameS(StandardColours[l].Name);
+		if(!pNewColours->AddColour(&ColNameS, &NewColour))
+		{
+			ok = FALSE;
+			break;
+		}
+	}
+
+	// add the colours to the document
+	if(ok)
+	{
+		pNewColours->AddColoursToDocument();
+	}
+	else
+	{
+		pNewColours->DestroyColours();
+	}
+
+	// delete the imported colours object
+	delete pNewColours;
+
+	return ok;
+}
Index: wxOil/camdoc.cpp
===================================================================
--- wxOil/camdoc.cpp	(revision 1775)
+++ wxOil/camdoc.cpp	(working copy)
@@ -111,6 +111,8 @@
 #include "menuops.h"
 #include "camelot.h"
 #include "filedlgs.h"
+#include "colormgr.h"
+#include "impcol.h"
 
 IMPLEMENT_DYNAMIC_CLASS( CCamDoc, wxDocument )
 
@@ -951,6 +953,14 @@
 	m_bIsModifiable = TRUE;
 	SetModified(FALSE);
 
+	// Determine if this new document has any named colours. If it does not, give it the
+	// new document default set.
+	ColourList* newDocColList=ColourManager::GetCurrentColourList();
+	if(newDocColList->GetUndeletedCount() == 0)
+	{
+		ImportedColours::AddStandardColourSet(Document::GetSelected());
+	}
+
 #if defined(_DEBUG)
 	if ( Error::IsUserName("Gavin") )
 		DebugTreeDlg::TweeDump( GetKernelDoc() );