IndexedColour *ColourDragInformation::GetColourForDocument(Document *pDestDoc) { // If no document supplied, assume the selected docuemnt is the destination if (pDestDoc == NULL) pDestDoc = Document::GetSelected(); // If there is no destination document, or if the colour is transparent, return NULL if (pDestDoc == NULL || TheColour.IsTransparent()) return(NULL); // If it's a document colour and already in the destination document, return it if (pParentDoc == pDestDoc) return(TheColour.FindParentIndexedColour()); // Copy the dragged colour into a temporary DocColour DocColour Temp = TheColour; IndexedColour *TempIxCol = NULL; // Check if we've got an IndexedColour to use... if (Temp.FindParentIndexedColour() == NULL) { // It's a library colour, so we must create a new IndexedColour to use TempIxCol = new IndexedColour(Temp); if (TempIxCol == NULL) return(NULL); // Failure - return "no colour" TempIxCol->SetName(ColourName); if (LibColIsSpot) // If a spot colour, make it so TempIxCol->SetLinkedParent(TempIxCol->FindLastLinkedParent(), COLOURTYPE_SPOT); // And make the DocColour reference it Temp.MakeRefToIndexedColour(TempIxCol); } // Ensure the colour (or a safe equivalent) is in the dest doc, by copying/merging it ColourManager::EnsureColourIsInDocument(pParentDoc, pDestDoc, &Temp); // And delete any temporary IndexedColour we created if (TempIxCol != NULL) delete TempIxCol; // And finally, return the resulting colour return(Temp.FindParentIndexedColour()); }