OpBitmapImport Class Reference

#include <sgliboil.h>

Inheritance diagram for OpBitmapImport:

Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpBitmapImport ()
 OpBitmapImport constructor (Creates an undoable operation).
 ~OpBitmapImport ()
 OpBitmapImport destructor.
void Do (OpDescriptor *)
void DoWithParam (OpDescriptor *pOp, OpParam *pBitmapImportParam)
 Performs a Bitmap import. Returns a pointer to the imported bitmap, without creating any objects.

Static Public Member Functions

static BOOL Init ()
 Creates an OpDescriptor for an BitmapImport operation.
static OpState GetState (String_256 *, OpDescriptor *)
 Returns the OpState of the OpBitmapImport operation.

Private Member Functions

bool ApplyFill (BitmapImportParam *pInfo, KernelBitmap *pBitmap)

Detailed Description

Definition at line 199 of file sgliboil.h.


Constructor & Destructor Documentation

OpBitmapImport::OpBitmapImport  ) 
 

OpBitmapImport constructor (Creates an undoable operation).

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/3/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-
See also:

Definition at line 657 of file sgliboil.cpp.

00657                                : Operation()
00658 {
00659     OpFlags.HasOwnTimeIndicator = TRUE; // The OpMenuImport op has its own time indicator
00660 }       

OpBitmapImport::~OpBitmapImport  ) 
 

OpBitmapImport destructor.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/3/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 677 of file sgliboil.cpp.

00678 {
00679 }


Member Function Documentation

bool OpBitmapImport::ApplyFill BitmapImportParam pInfo,
KernelBitmap pBitmap
[private]
 

Definition at line 963 of file sgliboil.cpp.

00964 {
00965     // Check the document pointer points to the current document
00966     if (Document::GetCurrent() != pInfo->pTargetDoc || pInfo->pTargetDoc == 0)
00967     {
00968         // At the moment we cannot apply a fill to an object that is not in
00969         // the current document (the operations used in this function appear to
00970         // add the object to one documents tree and render the object on the other
00971         // document).
00972         ERROR3("Cannot apply fill when active document has changed");
00973         return false;
00974     }
00975 
00976     // Check the spread is valid
00977     if (!Document::SpreadBelongsToDoc(pInfo->pTargetDoc, pInfo->pSpread))
00978     {
00979         ERROR3("Trying to import a bitmap fill into a non-existent spread");
00980         return false;
00981     }
00982 
00983     // Everything looks OK, lets do the fill
00984     switch(pInfo->FillType)
00985     {
00986         // If you need to change ApplyToObject, you may need to change ApplyToObjectAsTrans
00987         case ApplyToObject:
00988         {
00989             NodeRenderableInk* pObjectToUse;
00990             if (pInfo->TagObjectValid)
00991             {
00992                 Node *pTreeRoot = pInfo->pTargetDoc->GetFirstNode()->FindFirstDepthFirst();
00993                 if (pTreeRoot) pTreeRoot = pTreeRoot->FindNext();
00994                 Node *pNode = pTreeRoot->FindFirstDepthFirst();
00995                 while ((pNode != NULL) && (pNode->GetTag() != pInfo->TagObjectToFill))
00996                     pNode = pNode->FindNextDepthFirst(pTreeRoot);
00997 
00998                 if (pNode == 0)
00999                     return false;
01000 
01001                 if (pNode->IsAnObject())
01002                     pObjectToUse = static_cast<NodeRenderableInk *>(pNode); // should use dynamic_cast but no RTTI available
01003                 else
01004                 {
01005                     ERROR3("It has the tag we saved but its type has changed.  This is odd");
01006                     return false;
01007                 }
01008             }
01009 
01010             AttrBitmapColourFill* Attrib = new AttrBitmapColourFill;
01011             if (Attrib == 0)
01012                 return false;
01013 
01014             Attrib->AttachBitmap(pBitmap);
01015 
01016             if (pInfo->TagObjectValid)
01017                 AttributeManager::ApplyAttribToNode(pObjectToUse, Attrib);
01018             else if (pInfo->pObjectValid)
01019                 AttributeManager::ApplyAttribToNode(pInfo->pObject, Attrib);
01020             else
01021                 AttributeManager::AttributeSelected(0, Attrib);
01022 
01023             return true;
01024         }
01025         // If you need to change ApplyToObjectAsTransp, you may need to change ApplyToObject
01026         case ApplyToObjectAsTransp:
01027         {
01028             NodeRenderableInk* pObjectToUse;
01029 
01030             if (pInfo->TagObjectValid)
01031             {
01032                 Node *pTreeRoot = pInfo->pTargetDoc->GetFirstNode()->FindFirstDepthFirst();
01033                 if (pTreeRoot) pTreeRoot = pTreeRoot->FindNext();
01034                 Node *pNode = pTreeRoot->FindFirstDepthFirst();
01035                 while ((pNode != NULL) && (pNode->GetTag() != pInfo->TagObjectToFill))
01036                     pNode = pNode->FindNextDepthFirst(pTreeRoot);
01037 
01038                 if (pNode == 0)
01039                     return false;
01040 
01041                 if (pNode->IsAnObject())
01042                     pObjectToUse = static_cast<NodeRenderableInk *>(pNode); // should use dynamic_cast but no RTTI available
01043                 else
01044                 {
01045                     ERROR3("It has the tag we saved but its type has changed.  This is odd");
01046                     return false;
01047                 }
01048             }
01049 
01050             pBitmap = NodeBitmap::CheckGreyscaleBitmap(pBitmap, _R(IDS_BMPGAL_MAKEGREY), _R(IDS_BMPGAL_DOGREY));
01051 
01052             AttributeManager::HaveAskedAboutContoneColours  = FALSE;
01053             AttributeManager::UserCancelledContoneColours   = FALSE;
01054 
01055             if (pBitmap == 0)
01056                 return false;
01057 
01058             // Fill colour selected so create a fill colour attribute
01059             NodeAttribute *Attrib = new AttrBitmapTranspFill;
01060             if (Attrib == 0)
01061                 return false;
01062 
01063             (static_cast<AttrBitmapTranspFill *>(Attrib))->AttachBitmap(pBitmap);
01064 
01065             if (pInfo->TagObjectValid)
01066                 AttributeManager::ApplyAttribToNode(pObjectToUse, Attrib);
01067             else if (pInfo->pObjectValid)
01068                 AttributeManager::ApplyAttribToNode(pInfo->pObject, Attrib);
01069             else
01070                 AttributeManager::AttributeSelected(0, Attrib);
01071 
01072             return true;
01073         }
01074         case SetBackground:
01075         {
01076             OpBackgroundParam Param;
01077             Param.pBitmap   = pBitmap;
01078             Param.pDoc      = pInfo->pTargetDoc;            
01079             Param.pSpread   = pInfo->pSpread;
01080             
01081             // Obtain a pointer to the op descriptor for the create operation 
01082             OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_BACKGROUND);
01083 
01084             // Invoke the operation, passing in our parameters
01085             pOpDesc->Invoke(&Param);
01086             return true;
01087         }
01088         case AddToPage:
01089         {
01090             PageDropInfo DropInfo;
01091 
01092             DropInfo.pDoc       = pInfo->pTargetDoc;
01093             DropInfo.pSpread    = pInfo->pSpread;
01094             DropInfo.DropPos    = pInfo->DropPos;
01095 
01096             // Obtain a pointer to the op descriptor for the create operation 
01097             OpDescriptor* OpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpCreateNodeBitmap));
01098 
01099             // Invoke the operation, passing DocView and Pos as parameters
01100             OpDesc->Invoke(&OpParam((INT32)pBitmap,(INT32)&DropInfo));
01101             return true;
01102         }
01103         default:
01104         {
01105             ERROR3("Unknown fill type");
01106             return false;
01107         }
01108     }
01109 }

void OpBitmapImport::Do OpDescriptor NotUsed  )  [virtual]
 

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/3/95
Parameters:
OpBitmapImport (unused) [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: Always fails because this Do doesn't.

See also:
-

Reimplemented from Operation.

Definition at line 743 of file sgliboil.cpp.

00744 {
00745     ERROR3("OpBitmapImport does not provide a Do() function - Use DoWithParam");
00746     End();
00747 }

void OpBitmapImport::DoWithParam OpDescriptor pOp,
OpParam pBitmapImportParam
[virtual]
 

Performs a Bitmap import. Returns a pointer to the imported bitmap, without creating any objects.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/4/95
Parameters:
pOp - OpDescriptor as for all Do() functions [INPUTS] Param - points to a handy BitmapImport structure which says which file to import, etc...
- [OUTPUTS]
Returns:
-
See also:

Reimplemented from Operation.

Definition at line 765 of file sgliboil.cpp.

00766 {
00767     BitmapImportParam *pInfo = (BitmapImportParam *) pBitmapImportParam;
00768     KernelBitmap* pBitmap = 0;
00769 
00770     if(pInfo == NULL)
00771     {
00772         ERROR3("OpBitmapImport called with NULL info pointer");
00773         FailAndExecute(); 
00774         End();
00775         return;
00776     }
00777     else
00778     {
00779         if(pInfo->File == NULL)
00780         {
00781             ERROR3("OpBitmapImport called with NULL file pointer");
00782             FailAndExecute(); 
00783             End();
00784             return;
00785         }
00786     }
00787 
00788     PathName Path = *(pInfo->File);
00789 
00790     if(!Path.IsValid())
00791     {
00792         ERROR3("Filename is invalid");
00793         //InformError(_R(IDT_IMPORT_NOTFOUND));
00794         FailAndExecute();
00795         End();
00796         return;
00797     }
00798 
00799     // Import a file
00800     UINT32 SelFilter = FILTERID_GENERIC;
00801     BOOL LayersImport = FALSE;
00802     
00803     // Find the filter that the user chose
00804     Filter *pFilter = Filter::GetFirst();
00805 
00806     if(pFilter == NULL)
00807         return;
00808 
00809     while (pFilter != NULL)
00810     {
00811         if ((pFilter->GetFlags().CanImport) && (pFilter->FilterID == SelFilter))
00812             // This is the filter!
00813             break;
00814 
00815         // Try the next filter
00816         pFilter = Filter::GetNext(pFilter);
00817     }
00818 
00819     if (pFilter == NULL)
00820     {
00821         InformError(_R(IDT_CANT_FIND_FILTER));
00822         FailAndExecute(); 
00823         End();
00824         return;
00825     }
00826     else
00827     {
00828         // If this is not a filter family, check for compatibility before asking
00829         // filter to load the file.
00830         // This means the user has chosen an explicit filter to handle the import
00831         if (!pFilter->IS_KIND_OF(FilterFamily))
00832         {
00833             UINT32 Size = 1024;
00834             INT32 FileSize;
00835             ADDR FilterBuf = pFilter->LoadInitialSegment(Path, &Size, &FileSize);
00836 
00837             // If there has been a problem in the load initial segment then fail now.
00838             if (FilterBuf == NULL)
00839             {
00840                 // Tell the user about the problem and get out now while the goings good 
00841                 InformError();
00842                 FailAndExecute(); 
00843                 End();
00844                 return;
00845             }
00846 
00847             // Inform any filters that we are about to do a HowCompatible call.
00848             // This would allow a set of filters which have common functionality hidden in a
00849             // filter that cannot import and cannot export handle this call and hence set
00850             // itself up. This would allow it to maybe cache a result which should only be
00851             // checked by the first filter in the group. 
00852             pFilter->PreHowCompatible();
00853     
00854             // Change this to be less than 9 as the built in BMP filter returns 8 if it
00855             // is not too sure about the file and would like the AccusoftBMp filter to 
00856             // load the file if it is present.  
00857             if (pFilter->HowCompatible(Path, FilterBuf, Size, FileSize) < 9)
00858             {
00859                 // Not 100% happy with this file - ask for confirmation.
00860                 ErrorInfo Question;
00861                 Question.ErrorMsg = _R(IDT_IMPQUERY_NOTSURE);
00862                 Question.Button[0] = _R(IDB_IMPQUERY_IMPORT);
00863                 Question.Button[1] = _R(IDB_IMPQUERY_DONTIMPORT);
00864 
00865                 if (AskQuestion(&Question) != _R(IDB_IMPQUERY_IMPORT))
00866                 {
00867                     // User asked for this to be cancelled.
00868                     TRACEUSER( "Richard", wxT("Filter compatibility was less than 10\n") );
00869 
00870                     // Close the file, report the abort and finish.
00871                     CCFree(FilterBuf);
00872                     FailAndExecute();
00873                     InformMessage(_R(IDT_IMP_USERABORT));
00874                     End();
00875                     return;
00876                 }
00877             }
00878 
00879             // Get rid of initial file header
00880             CCFree(FilterBuf);
00881         }
00882 
00883         // First off, we have to try and open the file
00884         CCDiskFile DiskFile(1024, FALSE, TRUE);
00885 
00886         TRY
00887         {
00888             if (!DiskFile.open(Path, ios::in | ios::binary))
00889             {
00890                 // Failed to open the file...
00891                 TRACEUSER( "Richard", wxT("Failed to open file in BitmapImport Do") );
00892                 InformError(_R(IDT_IMPORT_NOTFOUND));
00893                 FailAndExecute();
00894                 End();
00895                 return;
00896             }
00897 
00898             // Import the file and see if Something went a bit wrong - tell the user what it was.
00899             if (!pFilter->ImportBitmap(&DiskFile, &pBitmap))
00900             {
00901                 // Only tell them if not special user cancelled error message
00902                 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00903                     InformError();
00904                 else
00905                     Error::ClearError();    // otherwise remove the error so it won't get reported
00906                 FailAndExecute();
00907                 End();
00908 
00909                 return;
00910             }
00911 
00912             // close the file
00913             if (DiskFile.isOpen())
00914                 DiskFile.close();
00915         }
00916 
00917         // See if there was a file io error
00918         CATCH(CFileException, e)
00919         {
00920             // Report the error if no one else did
00921             if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00922                 InformError();
00923             else
00924                 Error::ClearError();    // otherwise remove the error so it won't get reported
00925 
00926             // Make sure that the file is closed
00927             TRY
00928             {
00929                 if (DiskFile.isOpen())
00930                     DiskFile.close();
00931             }
00932             CATCH(CFileException, e)
00933             {
00934                 // Failed to close the file - not much we can do about it really
00935             }
00936             END_CATCH
00937 
00938             // and fail
00939             FailAndExecute();
00940             End();
00941             return;
00942         }
00943         END_CATCH
00944     }
00945 
00946     // Should really check the return value of ApplyFill(...)
00947     ApplyFill(pInfo, pBitmap);
00948 
00949     // If we have created a bitmap and it hasn't been added to a list somewhere
00950     if (pBitmap && pBitmap->GetParentBitmapList() == NULL)
00951     {
00952         // Delete it
00953         delete pBitmap;
00954     }
00955 
00956     // grab the focus
00957     GetMainFrame()->SetActiveWindow();
00958 
00959     // Finished the operation
00960     End();
00961 }

OpState OpBitmapImport::GetState String_256 pString,
OpDescriptor pOpDesc
[static]
 

Returns the OpState of the OpBitmapImport operation.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/3/95
See also:

Definition at line 720 of file sgliboil.cpp.

00721 {
00722     //OpState OpSt;
00723     OpState OpSt;
00724 
00725     return(OpSt);
00726 }

BOOL OpBitmapImport::Init void   )  [static]
 

Creates an OpDescriptor for an BitmapImport operation.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/3/95
Returns:
FALSE if it fails (due to lack of memory)
See also:

Reimplemented from SimpleCCObject.

Definition at line 693 of file sgliboil.cpp.

00694 {
00695     return RegisterOpDescriptor(
00696         0,                              // Tool ID
00697         _R(IDS_OPCLIPARTIMPORT),                // String resource ID
00698         CC_RUNTIME_CLASS(OpBitmapImport),   // Runtime class
00699         OPTOKEN_OPBITMAPIMPORT,         // Token string
00700         OpBitmapImport::GetState,           // GetState function
00701         0,                              // Help ID
00702         0,                              // Bubble ID
00703         0,                              // Resource ID
00704         0                               // Control ID
00705 //  needs   'GREY_WHEN_NO_CURRENT_DOC'
00706     );
00707 }   


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