ClipboardMapping Class Reference

A class which describes and implements an available mapping between internal and external data formats. Each filter which can provide a useful clipboard export/import format will register with the ExternalClipboard instance, using an ClipboardMapping object to describe the available mapping, and to provide functions which will invoke that filter on windows clipboard data. More...

#include <clipmap.h>

Inheritance diagram for ClipboardMapping:

ListItem CCObject SimpleCCObject BitmapClipMap BodgeTextClipMap BodgeUnicodeClipMap CMXClipMap DIBClipMap MetaFileClipMap NativeClipMap CMX16ClipMap CMX32ClipMap List of all members.

Public Member Functions

virtual ~ClipboardMapping ()
 Destructor.
InternalClipboardFormatGetInternalDataType (void)

Static Public Member Functions

static void CreateAndRegister (ClipboardMappingType TheType, Filter *TheFilter, InternalClipboardFormat &InternalDataType, UINT32 ExternalDataType, UINT32 Priority)
 Constructs and registers a clipboard mapping with the ExternalClipboard manager. This mapping info describes a filter which is able to import data from or export data to a windows clipboard in some way.

Protected Member Functions

 ClipboardMapping ()
 Constructor.
 ClipboardMapping (ClipboardMappingType TheType, Filter *TheFilter, InternalClipboardFormat &InternalDataType, UINT32 ExternalDataType, UINT32 Priority)
 Constructs a clipboard mapping with the ExternalClipboard manager. This mapping info describes a filter which is able to import data from or export data to a windows clipboard in some way.
virtual BOOL HandleImport (SelOperation *Caller, HANDLE ClipboardData, InternalClipboard *Dest)
 Calls the parent filter as appropriate to import the given data from the external clipboard.
virtual HANDLE HandleExport (Operation *Caller, InternalClipboard *Source)
 Invokes this mapping for exporting This takes the document tree of Source, and exports it to the external (windows) clipboard. Usually this just involves calling Filter::DoExport for the parent filter, and then returning the handle to the global memory block to be placed onto the external clipboard.
BOOL ImportFromTempFile (TCHAR *filename, SelOperation *Caller, InternalClipboard *Dest)
 Internal helper function. Invokes pFilter::DoImport into the Dest doc, using the given file as a source.
BOOL ExportToTempFile (TCHAR *filename, Operation *Caller, InternalClipboard *Source)
 Internal helper function. Invokes pFilter::DoExport from the Source doc, using the given file as a destination.
char * GetTempFileName (void)
 Finds a temporary file Remove it with ClipboardMapping::RemoveTempFile.
void RemoveTempFile (void)
 Removes the last temporary file 'allocated' with GetTempFilename.

Protected Attributes

char * tempfilename
ClipboardMappingType Type
FilterpFilter
InternalClipboardFormat InternalDataType
UINT32 ExternalDataType
UINT32 RealExternalType
UINT32 Priority
BOOL Available

Friends

class ExternalClipboard
class OpClipboardExport
class OpClipboardImport

Detailed Description

A class which describes and implements an available mapping between internal and external data formats. Each filter which can provide a useful clipboard export/import format will register with the ExternalClipboard instance, using an ClipboardMapping object to describe the available mapping, and to provide functions which will invoke that filter on windows clipboard data.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/4/95
The ClipboardMapping knows whether it represents an Import or Export mapping, and knows what data types are required for the source destination, and holds a pointer to the filter which can supply such a mapping. Two methods (HandleImport, HandleExport) are used to invoke the mapping.

Filters can register several different mappings with the ExtClipboard - typically a filter will register one import and one export mapping.

A 'Priority' factor is used to determine the most compatible/preferable routes for converting data. The factors are integers. A higher number indicates a higher priority.

Notes: There is a document describing all of the available conversions in Camelot. It describes the conversions and lists their priorities. Check with this doc to determine what priority your conversion should be. Add entries to this doc describing all mappings your filter(s) will register.

See also:
ExternalClipboard; Filter

Definition at line 160 of file clipmap.h.


Constructor & Destructor Documentation

ClipboardMapping::~ClipboardMapping  )  [virtual]
 

Destructor.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/4/95

Definition at line 199 of file clipmap.cpp.

00200 {
00201     RemoveTempFile();
00202 }

ClipboardMapping::ClipboardMapping  )  [protected]
 

Constructor.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/4/95
Notes: DON'T call the constructor - call CreateAndRegister

See also:
ClipboardMapping::CreateAndRegister

Definition at line 181 of file clipmap.cpp.

00182 {
00183     ERROR3("You can't directly construct an ClipboardMapping - Call CreateAndRegister");
00184 }

ClipboardMapping::ClipboardMapping ClipboardMappingType  TheType,
Filter TheFilter,
InternalClipboardFormat TheInternalDataType,
UINT32  TheExternalDataType,
UINT32  ThePriority
[protected]
 

Constructs a clipboard mapping with the ExternalClipboard manager. This mapping info describes a filter which is able to import data from or export data to a windows clipboard in some way.

Parameters:
TheType - indicates import / export / import & export [INPUTS]
TheFilter - The filter which can apply this conversion

TheInternalDatatType - A class defining the internal data type (see cliptype.h)

TheExternalDataType - A Windows CF_ constant defining the external clipboard data type which will be imported/exported.

ThePriority - An integer indicating the priority of this mapping. The highest available priority mapping will be used in order to retain as much information in the data as possible. See docs.doc for details of the existing mappings.

Notes: DON'T call the constructor - call CreateAndRegister

See also:
ClipboardMapping::CreateAndRegister; InternalClipboardFormat

Definition at line 240 of file clipmap.cpp.

00244 {
00245     Type        = TheType;
00246     pFilter     = TheFilter;
00247 
00248     InternalDataType.SetFormatID(TheInternalDataType.GetFormatID());
00249     ExternalDataType = RealExternalType = TheExternalDataType;
00250 
00251     Priority    = ThePriority;
00252 
00253     Available   = FALSE;
00254 
00255     tempfilename = NULL;
00256 }


Member Function Documentation

void ClipboardMapping::CreateAndRegister ClipboardMappingType  TheType,
Filter TheFilter,
InternalClipboardFormat TheInternalDataType,
UINT32  TheExternalDataType,
UINT32  ThePriority
[static]
 

Constructs and registers a clipboard mapping with the ExternalClipboard manager. This mapping info describes a filter which is able to import data from or export data to a windows clipboard in some way.

Parameters:
TheType - indicates import / export / import & export [INPUTS]
TheFilter - The filter which can apply this conversion

TheInternalDatatType - An object defining the internal data type (see cliptype.h)

TheExternalDataType - A Windows CF_ constant defining the external clipboard data type which will be imported/exported.

ThePriority - An integer indicating the priority of this mapping. The highest available priority mapping will be used in order to retain as much information in the data as possible. See docs.doc for details of the existing mappings.

See also:
InternalClipboardFormat

Reimplemented in MetaFileClipMap.

Definition at line 325 of file clipmap.cpp.

00329 {
00330     ClipboardMapping *Mapping = new ClipboardMapping(TheType, TheFilter,
00331                                                         TheInternalDataType, TheExternalDataType,
00332                                                         ThePriority);
00333     if (Mapping == NULL)
00334         InformError();
00335     else
00336         ExternalClipboard::RegisterDataType(Mapping);
00337 }

BOOL ClipboardMapping::ExportToTempFile TCHAR filename,
Operation Caller,
InternalClipboard Source
[protected]
 

Internal helper function. Invokes pFilter::DoExport from the Source doc, using the given file as a destination.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/4/95
Parameters:
filename - the file name of the temporary scratch file to be loaded [INPUTS] Caller - the operation we're being called from Source - the internal clipboard document to export from
Returns:
TRUE if it succeeds.
Notes: You must delete the temp file afterwards - use 'remove()'

Definition at line 586 of file clipmap.cpp.

00588 {
00589     // Provide a current view for the filter to chomp on; We stack the current
00590     // view so that we do not corrupt it.
00591     View *OldCurrentView = View::GetCurrent();
00592     ClipboardView ExportView;
00593     if (!ExportView.Init())
00594         return(FALSE);
00595 
00596     ExportView.SetCurrent();
00597 
00598     PathName FullPath(filename);
00599 
00600     // Try and open the temporary file
00601     CCDiskFile DiskFile(1024, FALSE, TRUE);
00602     BOOL AllOK = TRUE;
00603 
00604     TRY
00605     {
00606         if (!DiskFile.open(FullPath, ios::out | ios::binary))
00607         {
00608             if (OldCurrentView != NULL)
00609                 OldCurrentView->SetCurrent();
00610             return(FALSE);      // Failed to open the export file
00611         }
00612 
00613         // Tell the filter we would like a Preview Bitmap please
00614         if (pFilter->CanIncludePreviewBmp())
00615             pFilter->IncludePreviewBmp(TRUE);
00616 
00617         // Try and export the internal clipboard document
00618         if (!pFilter->DoExport(Caller, &DiskFile, &FullPath, InternalClipboard::Instance()))
00619         {
00620             // Something went a bit wrong - tell the user what it was.
00621             // Suppress the error if it was the 'user has cancelled one'
00622             if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00623             {
00624                 InformError();
00625                 // Caller should clean up the temp file
00626             }
00627             else
00628                 Error::ClearError();    // otherwise remove the error so it won't get reported
00629             
00630             // Set the error
00631             AllOK = FALSE;
00632         }
00633 
00634         // Close the file
00635         if (DiskFile.isOpen())
00636             DiskFile.close();
00637     }
00638 
00639     // See if there was a file io error
00640     CATCH(CFileException, e)
00641     {
00642         // Report the error if no one else did
00643         if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00644         {
00645             InformError();
00646         }
00647         else
00648             Error::ClearError();    // otherwise remove the error so it won't get reported
00649 
00650         // Make sure that the file is closed
00651         TRY
00652         {
00653             // Close that file
00654             if (DiskFile.isOpen())
00655                 DiskFile.close();
00656         }
00657         CATCH(CFileException, e)
00658         {
00659             // Not a lot we can do really...
00660         }
00661         END_CATCH
00662 
00663         // And restore the previous current view
00664         if (OldCurrentView != NULL)
00665             OldCurrentView->SetCurrent();
00666 
00667         return(FALSE);
00668     }
00669     END_CATCH
00670 
00671     // Tell the filter we would NOT like a Preview Bitmap ready for next time
00672     if (pFilter->CanIncludePreviewBmp())
00673         pFilter->IncludePreviewBmp(FALSE);
00674 
00675     // And restore the previous current view
00676     if (OldCurrentView != NULL)
00677         OldCurrentView->SetCurrent();
00678 
00679     return(TRUE);
00680 }

InternalClipboardFormat* ClipboardMapping::GetInternalDataType void   )  [inline]
 

Definition at line 213 of file clipmap.h.

00213 { return(&InternalDataType); }

char * ClipboardMapping::GetTempFileName void   )  [protected]
 

Finds a temporary file Remove it with ClipboardMapping::RemoveTempFile.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/4/95
Returns:
NULL, or a a filename to be used as a temporary file
See also:
ClipboardMapping::RemoveTempFile

Definition at line 765 of file clipmap.cpp.

00766 {
00767     RemoveTempFile();   // Try to ensure any previous tempfile is gone
00768 
00769     tempfilename = _ttempnam("C:\temp", "XS~");
00770 
00771     return(tempfilename);
00772 }

HANDLE ClipboardMapping::HandleExport Operation Caller,
InternalClipboard Source
[protected, virtual]
 

Invokes this mapping for exporting This takes the document tree of Source, and exports it to the external (windows) clipboard. Usually this just involves calling Filter::DoExport for the parent filter, and then returning the handle to the global memory block to be placed onto the external clipboard.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/4/95
Parameters:
Caller - the operation within which this method is being called [INPUTS] Source - the internal clipboard (document) to be exported
Returns:
NULL (if it failed), or a windows handle of the data to be placed on the clipboard.
Notes: The returned handle should be the thing you'd pass to SetClipboardData if you were dealing with it directly. You must adhere to all the Windows rules for this - i.e. a global data block, unlocked, etc etc.

Reimplemented in BodgeTextClipMap, BodgeUnicodeClipMap, BitmapClipMap, DIBClipMap, CMXClipMap, MetaFileClipMap, and NativeClipMap.

Definition at line 709 of file clipmap.cpp.

00710 {
00711     ERROR3("Base class ClipboardMapping::HandleExport called");
00712 
00713 /*
00714     PathName FullPath;
00715 
00716     char *tempname = _ttempnam("C:\temp", "XS");
00717     if (tempname == NULL)
00718     {
00719         ERROR3("Couldn't get a temp filename");
00720         return(NULL);
00721     }
00722 
00723     if (!ExportToTempFile(tempname, Caller, Source))
00724     {
00725         remove(tempname);
00726         free(tempname);
00727         return(NULL);
00728     }
00729 
00730 
00731     // In the switch statement below, set this handle to the global mem handle
00732     // of the data you want to place on the clipboard. If you don't want to
00733     // put anything on, leave this handle NULL.
00734     HANDLE hGlobalMem = NULL;
00735 
00736 
00737     // **** !!!! Export the file
00738 
00739     // Delete the temp file, and return the result
00740     remove(tempname);
00741     free(tempname);
00742     return(hGlobalMem);
00743 */
00744     return(NULL);
00745 }

BOOL ClipboardMapping::HandleImport SelOperation Caller,
HANDLE  ClipboardData,
InternalClipboard Dest
[protected, virtual]
 

Calls the parent filter as appropriate to import the given data from the external clipboard.

Parameters:
Caller - The operation within which this method is being called [INPUTS] ClipboardData - The result of calling GetClipboardData for your datatype Dest - The InternalClipboard (document) to import the data into.
Returns:
TRUE for success
Notes: This base-class default treats the clipboard data as a file, and makes the associated filter import it directly. (Note: It is currently implemented by slaving a temp file to disc, in order to avoid CCMemFiles which are not currently good enough for us to use)

Reimplemented in BodgeTextClipMap, BodgeUnicodeClipMap, BitmapClipMap, DIBClipMap, CMXClipMap, MetaFileClipMap, and NativeClipMap.

Definition at line 485 of file clipmap.cpp.

00487 {
00488     BOOL ok = TRUE;
00489 
00490     // ---
00491     // Get a scratch file - if TMP isn't set, this will try for c:\temp.
00492     // The filename will have XS as a prefix
00493     char *tempname = GetTempFileName(); //_ttempnam("C:\temp", "XS~");
00494     if (tempname == NULL)
00495     {
00496         ERROR3("Couldn't get a temp filename");
00497         return(FALSE);
00498     }
00499 
00500     PathName FullPath(tempname);
00501 
00502     // ---
00503     // Save the clipboard data into our tempfile
00504     OFSTRUCT OpenBuf;
00505     OpenBuf.cBytes = sizeof(OpenBuf);
00506     HFILE OutFile = OpenFile(tempname, &OpenBuf, OF_CREATE);
00507 
00508     // Did it work ok?
00509     if (OutFile == HFILE_ERROR)
00510     {
00511         ERROR2RAW("Import tempfile couldn't be opened");
00512         InformError();
00513         free(tempname);
00514         return(FALSE);
00515     }
00516 
00517     // And write it to the tempfile
00518     LPCSTR lpbuffer = (LPCSTR) GlobalLock(ClipboardData);
00519     if (lpbuffer != NULL)
00520     {
00521         DWORD DataSize = GlobalSize(ClipboardData);
00522 
00523         if (DataSize != 0)
00524         {
00525             UINT32 BytesWritten = _lwrite(OutFile, lpbuffer, DataSize);
00526 
00527             if (BytesWritten != DataSize)
00528             {
00529                 ERROR2RAW("Import tempfile save seems to have failed");
00530                 InformError();
00531                 ok = FALSE;
00532             }
00533         }
00534         else
00535         {
00536             ERROR3("No data in clipboard!");
00537             ok = FALSE;
00538         }
00539 
00540         GlobalUnlock(ClipboardData);
00541     }
00542     else
00543     {
00544         ERROR3("Clipboard memory chunk couldn't be locked!");
00545         ok = FALSE;
00546     }
00547 
00548     _lclose(OutFile);
00549 
00550 
00551     // ---
00552     // Now, import the temp file using our 'parent' filter
00553     if (ok)
00554         ok = ImportFromTempFile(tempname, Caller, InternalClipboard::Instance());
00555 
00556 
00557     // Delete the temp file, and deallocate the tempname memory
00558     _tremove(tempname);
00559     free(tempname);
00560     return(ok);
00561 }

BOOL ClipboardMapping::ImportFromTempFile TCHAR filename,
SelOperation Caller,
InternalClipboard Dest
[protected]
 

Internal helper function. Invokes pFilter::DoImport into the Dest doc, using the given file as a source.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/4/95
Parameters:
filename - the file name of the temporary scratch file to be loaded [INPUTS] Dest - the internal clipboard document to import into
Notes: You must remove() the tem file yourself afterwards.

Definition at line 360 of file clipmap.cpp.

00362 {
00363     PathName FileToLoad(filename);
00364     
00365     CCLexFile* pFile = new CCDiskFile(1024, FALSE, TRUE);
00366 
00367     // See if we have a valid file
00368     if (pFile == NULL)
00369         return FALSE;
00370 
00371     // we have to try and open the file
00372     TRY
00373     {
00374         if (!((CCDiskFile*)pFile)->open(FileToLoad, ios::in | ios::binary))
00375         {
00376             // Failed to open the file...
00377             delete pFile;
00378             pFile = NULL;
00379             ERROR2RAW("Failed to open temp file for import into clipboard");
00380             return(FALSE);
00381         }
00382 
00383         // Found the Filter, so ask it to import the file please
00384 
00385         // Provide a current view for the filter to chomp on; We stack the current
00386         // view so that we do not corrupt it.
00387         View *OldCurrentView = View::GetCurrent();
00388         ClipboardView ImportView;
00389         if (!ImportView.Init())
00390         {
00391             delete pFile;
00392             pFile = NULL;
00393             return(FALSE);
00394         }
00395 
00396         ImportView.SetCurrent();
00397 
00398         if (!pFilter->DoImport(Caller, pFile, InternalClipboard::Instance()))
00399         {
00400             // Something went a bit wrong - tell the user what it was.
00401             // Only tell them if not special user cancelled error message
00402             if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00403                 InformError();
00404 
00405                 // If the file is open, then close it
00406             if (pFile->isOpen())
00407                 pFile->close();
00408 
00409             // and die a bit
00410             delete pFile;
00411             pFile = NULL;
00412 
00413             if (OldCurrentView != NULL)
00414                 OldCurrentView->SetCurrent();
00415             return FALSE;
00416         }
00417 
00418         if (OldCurrentView != NULL)
00419             OldCurrentView->SetCurrent();
00420 
00421         // If the file is open, then close it
00422         if (pFile->isOpen())
00423             pFile->close();
00424     }
00425 
00426     // See if there was a file I/O error
00427     CATCH(CFileException, e)
00428     {
00429         // Report the error if no one else did
00430         if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00431             InformError();
00432 
00433         // Make sure that the file is closed
00434         TRY
00435         {
00436             // Close the file
00437             if (pFile->isOpen())
00438                 pFile->close();
00439         }
00440         CATCH(CFileException, e)
00441         {
00442             // Not a lot we can do really...
00443         }
00444         END_CATCH
00445 
00446         // and fail
00447         delete pFile;
00448         pFile = NULL;
00449         return FALSE;
00450     }
00451     END_CATCH
00452 
00453     // Make sure that we have got rid of the file
00454     delete pFile;
00455 
00456     return(TRUE);
00457 }

void ClipboardMapping::RemoveTempFile void   )  [protected]
 

Removes the last temporary file 'allocated' with GetTempFilename.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/4/95
This function is automatically called when the clipboard is wiped, as usually we had to leave the tempfile around while it was "on" the clipboard.

See also:
ClipboardMapping::GetTempFilename

Definition at line 793 of file clipmap.cpp.

00794 {
00795     if (tempfilename != NULL)
00796     {
00797         _tremove(tempfilename);
00798         free(tempfilename);
00799         tempfilename = NULL;
00800     }
00801 }


Friends And Related Function Documentation

friend class ExternalClipboard [friend]
 

Reimplemented in BodgeTextClipMap, BodgeUnicodeClipMap, BitmapClipMap, DIBClipMap, CMXClipMap, CMX16ClipMap, CMX32ClipMap, MetaFileClipMap, and NativeClipMap.

Definition at line 164 of file clipmap.h.

friend class OpClipboardExport [friend]
 

Reimplemented in BodgeTextClipMap, BodgeUnicodeClipMap, BitmapClipMap, DIBClipMap, CMXClipMap, CMX16ClipMap, CMX32ClipMap, MetaFileClipMap, and NativeClipMap.

Definition at line 165 of file clipmap.h.

friend class OpClipboardImport [friend]
 

Reimplemented in BodgeTextClipMap, BodgeUnicodeClipMap, BitmapClipMap, DIBClipMap, CMXClipMap, CMX16ClipMap, CMX32ClipMap, MetaFileClipMap, and NativeClipMap.

Definition at line 166 of file clipmap.h.


Member Data Documentation

BOOL ClipboardMapping::Available [protected]
 

Definition at line 254 of file clipmap.h.

UINT32 ClipboardMapping::ExternalDataType [protected]
 

Definition at line 248 of file clipmap.h.

InternalClipboardFormat ClipboardMapping::InternalDataType [protected]
 

Definition at line 245 of file clipmap.h.

Filter* ClipboardMapping::pFilter [protected]
 

Definition at line 243 of file clipmap.h.

UINT32 ClipboardMapping::Priority [protected]
 

Definition at line 251 of file clipmap.h.

UINT32 ClipboardMapping::RealExternalType [protected]
 

Definition at line 249 of file clipmap.h.

char* ClipboardMapping::tempfilename [protected]
 

Definition at line 232 of file clipmap.h.

ClipboardMappingType ClipboardMapping::Type [protected]
 

Definition at line 242 of file clipmap.h.


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