PrintMarksComponent Class Reference

An actual print mark document component. This component contains a list of handles which refer to print marks cached by the print marks manager. On saving, the mark handles will be resolved into physical marks which will be exported and subsequently imported and registered. More...

#include <prnmkcom.h>

Inheritance diagram for PrintMarksComponent:

DocComponent ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 PrintMarksComponent ()
virtual ~PrintMarksComponent ()
BOOL AddMark (UINT32 handle)
 Adds a print mark reference to our component list.
void RemoveMark (UINT32 handle)
 Remove a print marks component from the list.
void RemoveAllMarks ()
 Empty the list of all marks.
BOOL IsVirgin () const
 Is this a virgin print marks component, ie has it never had a print mark added to it?
DocPrintMarkFindMark (UINT32 SearchHandle) const
 Try to find a print mark in the doc component, using the print mark handle.
DocPrintMarkGetFirstMark () const
DocPrintMarkGetNextMark (DocPrintMark *pItem) const
virtual BOOL StartImport (BaseCamelotFilter *pFilter)
virtual BOOL EndImport (BaseCamelotFilter *pFilter, BOOL Success)
virtual BOOL StartExport (BaseCamelotFilter *pFilter)
virtual BOOL EndExport (BaseCamelotFilter *pFilter, BOOL Success)
void ImportDefaultPrintMark (CXaraFileRecord *Rec)
 To import a default print mark.
void StartImportCustomPrintMark (CamelotRecordHandler *pHandler, CXaraFileRecord *Rec)
 To start import of a custom print mark This is called when a TAG_PRINTMARKCUSTOM is found in the importing file. The tag is followed by a subtree (beginning with a NodeGroup).
void EndImportCustomPrintMark (CamelotRecordHandler *pHandler)
 To end the import a custom print mark - see the SeeAlso for details.

Private Member Functions

BOOL ExportPrintMark (BaseCamelotFilter *pFilter, PrintMarkItem *pMarkItem)
 To export a print mark.

Private Attributes

NodeCustomPreviousContext
NodeCustomCurrentContext
PrintMarkItempNewMark
DocPrintMarkList DocMarks

Detailed Description

An actual print mark document component. This component contains a list of handles which refer to print marks cached by the print marks manager. On saving, the mark handles will be resolved into physical marks which will be exported and subsequently imported and registered.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
See also:
DocComponent

Definition at line 235 of file prnmkcom.h.


Constructor & Destructor Documentation

PrintMarksComponent::PrintMarksComponent  ) 
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
See also:

Definition at line 331 of file prnmkcom.cpp.

00332 {
00333     CustomPreviousContext = NULL;
00334     CustomCurrentContext  = NULL;
00335     pNewMark = NULL;
00336 }

PrintMarksComponent::~PrintMarksComponent  )  [virtual]
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
See also:

Definition at line 349 of file prnmkcom.cpp.

00350 {
00351 }


Member Function Documentation

BOOL PrintMarksComponent::AddMark UINT32  handle  ) 
 

Adds a print mark reference to our component list.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
See also:

Definition at line 366 of file prnmkcom.cpp.

00367 {
00368     // it may well be there already!
00369     if (DocMarks.FindMark(handle))
00370         return TRUE;
00371     return DocMarks.AddMark(handle);        
00372 }

BOOL PrintMarksComponent::EndExport BaseCamelotFilter pFilter,
BOOL  Success
[virtual]
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS] Success - True if everything went swimmingly, False if just a clean up is required.
Returns:
TRUE if the component was able to end the importing; FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 577 of file prnmkcom.cpp.

00578 {
00579     BOOL ok = TRUE;
00580 
00581 // WEBSTER - markn 14/2/97
00582 // No print records needed in Webster
00583 #ifndef WEBSTER
00584 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00585     if (pFilter == NULL)
00586     {
00587         ERROR3("PrintMarksComponent::EndExport filter is null!");
00588         return(ok);
00589     }
00590 
00591     if (!Success || pFilter->IsWebFilter()) // Don't export to web files, or if we have failed
00592         return(ok);
00593 
00594 
00595     // Find the Print mark manager and it's PrintMark cache
00596     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
00597     if (pMarksMan == NULL)
00598         return(ok);
00599 
00600     // Export the list of marks
00601     DocPrintMark *pItem = DocMarks.GetFirstMark();
00602     while (ok && pItem != NULL)
00603     {
00604         // From our item, find the actual PrintMark definition in the PMM cache
00605         PrintMarkItem *pMarkItem = pMarksMan->PMMCache.FindMark(pItem->GetHandle());
00606         if (pMarkItem != NULL)
00607             ok = ExportPrintMark(pFilter, pMarkItem);
00608 
00609         pItem = DocMarks.GetNextMark(pItem);
00610     }
00611 #endif
00612 #endif // WEBSTER
00613     return ok;
00614 }

BOOL PrintMarksComponent::EndImport BaseCamelotFilter pFilter,
BOOL  Success
[virtual]
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS] Success - TRUE => The import was successful; FALSE => The import failed - abandon any changes.
Returns:
TRUE if the component was able to end the importing; FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 504 of file prnmkcom.cpp.

00505 {
00506 /*
00507     if (pFilter==NULL)
00508     {
00509         ERROR3("PrintMarksComponent::EndImport filter is null!");
00510         return TRUE;
00511     }
00512 
00513     if (Success)
00514     {
00515 
00516     }
00517     else
00518     {
00519 
00520     }
00521 */
00522     CustomPreviousContext = NULL;
00523     CustomCurrentContext  = NULL;
00524     pNewMark = NULL;
00525 
00526     return TRUE;
00527 }

void PrintMarksComponent::EndImportCustomPrintMark CamelotRecordHandler pHandler  ) 
 

To end the import a custom print mark - see the SeeAlso for details.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/8/96
Parameters:
pHandler - the record handler that called us [INPUTS]
See also:
PrintMarksComponent::StartImportCustomPrintMark

Definition at line 909 of file prnmkcom.cpp.

00910 {
00911     PORTNOTETRACE("print","PrintMarksComponent::EndImportCustomPrintMark - do nothing");
00912 #ifndef EXCLUDE_FROM_XARALX
00913     ERROR3IF(CustomCurrentContext == NULL || pNewMark == NULL, "EndImportCustomPrintMark - StartImportCustomMark not called/failed");
00914 
00915     // Find the Print mark manager and it's PrintMark cache
00916     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
00917     if (pMarksMan == NULL)
00918         return;
00919 
00920     // Restore the previous import context node
00921     pHandler->SetInsertContextNode(CustomPreviousContext);
00922 
00923     // Complete the mark and add it to the PMM cache
00924     NodeGroup *Glyph = (NodeGroup *)CustomCurrentContext->FindFirstChild();
00925     ERROR3IF(Glyph == NULL, "Import of custom mark subtree must have failed");
00926     if (Glyph != NULL)
00927     {
00928         ERROR3IF(!Glyph->IsKindOf(CC_RUNTIME_CLASS(NodeGroup)), "Imported print mark doesn't start with a group");
00929 
00930         Glyph->UnlinkNodeFromTree(NULL);
00931         UINT32 MarkHandle = pMarksMan->PMMCache.AddNewMark(pNewMark, Glyph);
00932 
00933         // Add a reference to the mark to ourself, so the mark is enabled
00934         AddMark(MarkHandle);
00935     }
00936     else
00937     {
00938         // Try not to leak too much!
00939         delete pNewMark;
00940     }
00941 
00942     // Tidy up
00943     pNewMark = NULL;
00944     CustomPreviousContext = NULL;
00945     delete CustomCurrentContext;
00946     CustomCurrentContext = NULL;
00947 #endif
00948 }

BOOL PrintMarksComponent::ExportPrintMark BaseCamelotFilter pFilter,
PrintMarkItem pMarkItem
[private]
 

To export a print mark.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/8/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to export a file. [INPUTS] pMarkItem - The print mark to be exported
Returns:
TRUE if export was successful
Notes: Print marks, if disabled, will not be exported. i.e. only needed data is actually saved to the file.

Print marks are saved in 2 formats: TAG_PRINTMARKDEFAULT - Default (built in) marks - a 1-byte record indicates which mark to use by quoting its ID byte.

TAG_PRINTMARKCUSTOM - User (custom) marks - The record is zero length, but is followed by a TAG_DOWN, a clipart tree, and a TAG_UP.

NOTE that custom marks are currently not handled.

Definition at line 646 of file prnmkcom.cpp.

00647 {
00648     BOOL ok = TRUE;
00649 
00650     PORTNOTETRACE("print","PrintMarksComponent::ExportPrintMark - do nothing");
00651 #ifndef EXCLUDE_FROM_XARALX
00652     ERROR3IF(pFilter == NULL || pMarkItem == NULL, "Illegal NULL params");
00653 
00654     PrintMark *pMarkInfo = pMarkItem->GetPrintMark();
00655     if (pMarkInfo == NULL)
00656     {
00657         ERROR3("PrintMarkItem with no PrintMark");
00658         return(FALSE);
00659     }
00660 
00661     if (pMarkInfo->IsCustom())
00662     {
00663         // A custom mark consists of a PrintMarkCustom record, defining where the
00664         // mark goes, what it's called, etc, followed records for the clipart subtree
00665         CXaraFileRecord Rec(TAG_PRINTMARKCUSTOM, TAG_PRINTMARKCUSTOM_SIZE);
00666         if (ok) ok = Rec.Init();
00667 
00668         // Write out the print mark info
00669         //  Type (bitmap ID), menu text string, orientation, positions
00670         if (ok)  ok = Rec.WriteBYTE((BYTE) pMarkInfo->GetType());
00671         if (ok)  ok = Rec.WriteBYTE((BYTE) pMarkInfo->GetOrientation());
00672         
00673         if (ok)
00674         {
00675             MarkPosition *Pos = pMarkInfo->GetFirstPosition();
00676             while (ok && Pos != NULL)
00677             {
00678                 ok = Rec.WriteBYTE((BYTE) Pos->GetRegion());                    // Write the region
00679                 if (ok) ok = Rec.WriteBYTE(Pos->GetFormat().GetAsFlagByte());   // Write the format
00680 
00681                 Pos = pMarkInfo->GetNextPosition(Pos);
00682             }
00683 
00684             if (ok) ok = Rec.WriteBYTE(MarkRegion_FileFormatTerminator);        // Terminate the list
00685         }
00686 
00687         if (ok)  ok = Rec.WriteUnicode(pMarkInfo->GetMarkMenuText());           // Write the mark name
00688 
00689         // Finish off this record
00690         if (ok) pFilter->Write(&Rec);
00691 
00692 
00693         // OK, now write the print mark "clipart" subtree to the file...
00694         if (ok) ok = pFilter->WriteZeroSizedRecord(TAG_DOWN);
00695         
00696         // BLOCK
00697         {
00698             // Find the Glyph subtree. We could strip off the default attributes
00699             // that Mike keeps around, but they only add a tiny amount (100 bytes
00700             // or so) to the file, and save a lot of problems getting attribute-completeness
00701             // when reloading the mark.
00702             Node *GlyphRoot = pMarkItem->GetMarkGlyph();
00703             if (GlyphRoot == NULL)
00704             {
00705                 ERROR3("Custom printers mark with no glyph");
00706                 ok = FALSE;
00707             }
00708 
00709             if (ok) ok = pFilter->WriteNodes(GlyphRoot);
00710         }
00711         if (ok) ok = pFilter->WriteZeroSizedRecord(TAG_UP);
00712     }
00713     else
00714     {
00715         // --- Write the record
00716         CXaraFileRecord Rec(TAG_PRINTMARKDEFAULT, TAG_PRINTMARKDEFAULT_SIZE);
00717         if (ok) ok = Rec.Init();
00718 
00719         if (ok) ok = Rec.WriteBYTE(pMarkInfo->GetIDByte());
00720 
00721         // --- Finally, output the record
00722         if (ok)
00723             pFilter->Write(&Rec);
00724     }
00725 #endif
00726     return(ok);
00727 }

DocPrintMark * PrintMarksComponent::FindMark UINT32  handle  )  const
 

Try to find a print mark in the doc component, using the print mark handle.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
Parameters:
handle = the handle of the mark to search for [INPUTS]
Returns:
A pointer to the print mark described by this handle (NULL if none)
See also:

Definition at line 424 of file prnmkcom.cpp.

00425 {
00426     return DocMarks.FindMark(handle);
00427 }

DocPrintMark * PrintMarksComponent::GetFirstMark  )  const [inline]
 

Definition at line 281 of file prnmkcom.h.

00282 {
00283     return DocMarks.GetFirstMark();
00284 }

DocPrintMark * PrintMarksComponent::GetNextMark DocPrintMark pItem  )  const [inline]
 

Definition at line 286 of file prnmkcom.h.

00287 {
00288     return DocMarks.GetNextMark(pItem);
00289 }

void PrintMarksComponent::ImportDefaultPrintMark CXaraFileRecord Rec  ) 
 

To import a default print mark.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/8/96
Parameters:
Rec - The TAG_PRINTMARKDEFAULT print mark record to be imported [INPUTS]

Definition at line 744 of file prnmkcom.cpp.

00745 {
00746     PORTNOTETRACE("print","PrintMarksComponent::ExportPrintMark - do nothing");
00747 #ifndef EXCLUDE_FROM_XARALX
00748     ERROR3IF(Rec == NULL, "Illegal NULL params");
00749     BYTE ID = 0;
00750     BOOL ok = Rec->ReadBYTE(&ID);
00751 
00752     if (!ok)
00753         return;
00754 
00755     // Find the Print mark manager and it's PrintMark cache
00756     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
00757     if (pMarksMan == NULL)
00758         return;
00759 
00760     // Search the PMMCache list for a PrintMark with the given ID byte
00761     UINT32 Handle = 0;
00762     BOOL Found = FALSE;
00763     PrintMarkItem *pItem = pMarksMan->PMMCache.GetFirstMark();
00764     while (pItem != NULL)
00765     {
00766         PrintMark *pMark = pItem->GetPrintMark();
00767         if (pMark != NULL && pMark->GetIDByte() == ID)
00768         {
00769             Handle = pItem->GetHandle();
00770             Found  = TRUE;
00771             break;
00772         }
00773 
00774         pItem = pMarksMan->PMMCache.GetNextMark(pItem);
00775     }
00776 
00777     // If we found a mark, then Handle is its PMM handle - Add an entry to our
00778     // list of Enabled marks.
00779     if (Found)
00780         AddMark(Handle);
00781 #endif
00782 }

BOOL PrintMarksComponent::IsVirgin  )  const
 

Is this a virgin print marks component, ie has it never had a print mark added to it?

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
Returns:
TRUE - if no print mark has ever been added to this print mark component FALSE - if some have in past history

Definition at line 443 of file prnmkcom.cpp.

00444 {
00445     return DocMarks.IsVirgin();
00446 }

void PrintMarksComponent::RemoveAllMarks  ) 
 

Empty the list of all marks.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
See also:

Definition at line 404 of file prnmkcom.cpp.

00405 {
00406     DocMarks.RemoveAllMarks();
00407 }

void PrintMarksComponent::RemoveMark UINT32  handle  ) 
 

Remove a print marks component from the list.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
See also:

Definition at line 387 of file prnmkcom.cpp.

00388 {
00389     DocMarks.RemoveMark(handle);
00390 }

BOOL PrintMarksComponent::StartExport BaseCamelotFilter pFilter  )  [virtual]
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to export a file. [INPUTS]
Returns:
TRUE if the component was able to prepare for exporting; FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 545 of file prnmkcom.cpp.

00546 {
00547 #if !defined(EXCLUDE_FROM_RALPH)
00548 /*
00549     if (pFilter == NULL)
00550     {
00551         ERROR3("PrintMarksComponent::StartExport filter is null!");
00552         return TRUE;
00553     }
00554 
00555 */
00556 #endif
00557     return TRUE;
00558 }

BOOL PrintMarksComponent::StartImport BaseCamelotFilter pFilter  )  [virtual]
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/07/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS]
Returns:
TRUE if the component was able to prepare for importing; FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 463 of file prnmkcom.cpp.

00464 {
00465     if (pFilter == NULL)
00466     {
00467         ERROR3("PrintMarksComponent::StartImport filter is null!");
00468         return TRUE;
00469     }
00470 
00471     CustomPreviousContext = NULL;
00472     CustomCurrentContext  = NULL;
00473     pNewMark = NULL;
00474 
00475     // If we're importing into an existing document, we ignore all printer mark
00476     // information in the file being imported.
00477     if (pFilter->IsImporting())
00478         return(TRUE);
00479 
00480     // Before importing, we delete all existing marks, so that the loaded file overrides
00481     // the settings already present in the document.
00482     RemoveAllMarks();
00483 
00484     return TRUE;
00485 }

void PrintMarksComponent::StartImportCustomPrintMark CamelotRecordHandler pHandler,
CXaraFileRecord Rec
 

To start import of a custom print mark This is called when a TAG_PRINTMARKCUSTOM is found in the importing file. The tag is followed by a subtree (beginning with a NodeGroup).

Parameters:
pHandler - the record handler that called us [INPUTS] Rec - The TAG_PRINTMARKCUSTOM print mark record to be imported
We create a blank layer node, and point the importer at it, so that the subtree imports where _we_ want it. When the final TAG_UP record of the subtree is read, we will be clled back in EndImportCustomPrintMark to complete the job.

See also:
PrintMarksComponent::EndImportCustomPrintMark

Definition at line 809 of file prnmkcom.cpp.

00810 {
00811     PORTNOTETRACE("print","PrintMarksComponent::StartImportCustomPrintMark - do nothing");
00812 #ifndef EXCLUDE_FROM_XARALX
00813     ERROR3IF(CustomCurrentContext != NULL || CustomPreviousContext != NULL ||
00814                 pNewMark != NULL, "StartImportCustomPrintMark called while importing another custom mark?!");
00815 
00816     // Find the Print mark manager and it's PrintMark cache
00817     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
00818     if (pMarksMan == NULL)
00819         return;
00820 
00821     // Create a PrintMark encapsulating all the data in this record
00822     pNewMark = new PrintMarkItem;
00823     if (!pNewMark)
00824         return;
00825 
00826     PrintMark *pMarkInfo = pNewMark->GetPrintMark();
00827     pMarkInfo->SetCustomOrDefault(TRUE);                                // This is a custom mark
00828 
00829 
00830     // --- Now read the print mark info
00831     BOOL ok = TRUE;
00832     BYTE Temp;
00833 
00834     if (ok)  ok = Rec->ReadBYTE(&Temp);
00835     if (ok)  pMarkInfo->SetType((MarkType) Temp);
00836 
00837     if (ok)  ok = Rec->ReadBYTE(&Temp);
00838     if (ok)  pMarkInfo->SetOrientation((MarkOrient) Temp);
00839     
00840     while (ok)                                                          // Read all format positions
00841     {
00842         ok = Rec->ReadBYTE(&Temp);
00843         if (ok)
00844         {
00845             if (Temp == (BYTE) MarkRegion_FileFormatTerminator)         // End of list - break out of loop
00846                 break;
00847 
00848             MarkPosition *NewPos = new MarkPosition;                    // New position
00849             if (NewPos == NULL)
00850                 ok = FALSE;
00851             else
00852             {
00853                 NewPos->Initialise();
00854                 NewPos->SetRegion((MarkRegion) Temp);                   // Set region from first byte
00855 
00856                 ok = Rec->ReadBYTE(&Temp);
00857                 if (ok)
00858                 {
00859                     MarkFormat NewFormat;
00860                     NewFormat.SetFromFlagByte(Temp);                    // Set format from second byte
00861 
00862                     NewPos->SetFormat(NewFormat);
00863 
00864                     pMarkInfo->AddNewPosition(NewPos);                  // And add to the mark's positions
00865                 }
00866                 else
00867                     delete NewPos;
00868             }
00869         }
00870     }
00871 
00872     String_256 MenuName;
00873     if (ok)  ok = Rec->ReadUnicode((TCHAR *)MenuName, 255);             // Read the mark name
00874     if (ok)  pMarkInfo->SetMarkMenuText(&MenuName);
00875 
00876     if (ok)
00877     {
00878         // --- Finally, prepare for import of the following clipart subtree
00879         // Remember the current import context node
00880         CustomPreviousContext = pHandler->GetInsertContextNode();
00881 
00882         // Create a layer and set up the import system to import the mark into it
00883         // If this fails, then it'll just find somewhere "sensible" to import into
00884         CustomCurrentContext  = new Layer;
00885         pHandler->SetInsertContextNode(CustomCurrentContext);
00886     }
00887 
00888     // And now sit back and wait for the End call...
00889 #endif
00890 }


Member Data Documentation

Node* PrintMarksComponent::CustomCurrentContext [private]
 

Definition at line 264 of file prnmkcom.h.

Node* PrintMarksComponent::CustomPreviousContext [private]
 

Definition at line 263 of file prnmkcom.h.

DocPrintMarkList PrintMarksComponent::DocMarks [private]
 

Definition at line 271 of file prnmkcom.h.

PrintMarkItem* PrintMarksComponent::pNewMark [private]
 

Definition at line 265 of file prnmkcom.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:00:03 2007 for Camelot by  doxygen 1.4.4