BodgeTextClipMap Class Reference

Describes and handles import/export mappings for UNICODE text. More...

#include <clipmap.h>

Inheritance diagram for BodgeTextClipMap:

ClipboardMapping ListItem CCObject SimpleCCObject List of all members.

Static Public Member Functions

static void CreateAndRegister (ClipboardMappingType TheType, UINT32 ClaimType=0)
 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

 BodgeTextClipMap ()
 BodgeTextClipMap (ClipboardMappingType TheType, UINT32 ClaimType=0)
 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.

Friends

class ExternalClipboard
class OpClipboardExport
class OpClipboardImport

Detailed Description

Describes and handles import/export mappings for UNICODE text.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/4/95
This provides bodge import/export of ASCII text A proper text filter will be written one day which will replace this bodge

Notes: This mapping is used twice - once for CF_TEXT, and once as an alias for CF_OEMTEXT (which the clipboard will convert to CF_TEXT when we ask for it)

See also:
ClipboardMapping; ExternalClipboard; Filter

Definition at line 281 of file clipmap.h.


Constructor & Destructor Documentation

BodgeTextClipMap::BodgeTextClipMap  )  [protected]
 

Definition at line 818 of file clipmap.cpp.

00819 {
00820     ERROR3("Please don't press that button again");
00821 }

BodgeTextClipMap::BodgeTextClipMap ClipboardMappingType  TheType,
UINT32  ClaimType = 0
[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]
ClaimType - specifies the text type that this mapping will claim from the windows clipboard - that is, create 3 of these mappings, specifying CF_TEXT, CF_UNICODETEXT, and CF_OEMTEXT, and they will all ask the clipboard for UNICODE text when they actually go to import. This allows us to detect the 3 implicitly-converted clipboard formats, and map them all to UNICODE, i.e. use the UNICODE mapping for all 3 available formats. If ClaimType == 0, UNICODE is assumed

Notes: DON'T call the constructor - call CreateAndRegister

See also:
BodgeTextClipMap::CreateAndRegister

Definition at line 850 of file clipmap.cpp.

00851                 : ClipboardMapping(TheType, NULL, InternalClipboardFormat(CLIPTYPE_TEXT),
00852                                     CF_TEXT, 50)
00853 {
00854     if (ClaimType != 0)
00855         ExternalDataType = ClaimType;
00856 }


Member Function Documentation

void BodgeTextClipMap::CreateAndRegister ClipboardMappingType  TheType,
UINT32  ClaimType = 0
[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.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/4/95
Parameters:
TheType - indicates import / export / import & export [INPUTS]
ClaimType - specifies the text type that this mapping will claim from the windows clipboard - that is, create 3 of these mappings, specifying CF_TEXT, CF_UNICODETEXT, and CF_OEMTEXT, and they will all ask the clipboard for UNICODE text when they actually go to import. This allows us to detect the 3 implicitly-converted clipboard formats, and map them all to UNICODE, i.e. use the UNICODE mapping for all 3 available formats. If ClaimType == 0, UNICODE is assumed

Definition at line 883 of file clipmap.cpp.

00884 {
00885     BodgeTextClipMap *Mapping = new BodgeTextClipMap(TheType, ClaimType);
00886     if (Mapping == NULL)
00887         InformError();
00888     else
00889         ExternalClipboard::RegisterDataType(Mapping);
00890 }

HANDLE BodgeTextClipMap::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.

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.
This bodge mapping for text scans the docuemnt tree for text chars and strips them out by hand. Styles and suchlike are lost. It's a bodge.

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 from ClipboardMapping.

Definition at line 1082 of file clipmap.cpp.

01083 {
01084     const DWORD Increment = 1024 * sizeof(char);
01085     DWORD CurrentSize   = 0;
01086     DWORD MaxSize       = Increment;
01087 
01088 #if (_OLE_VER >= 0x200)
01089 
01090     // If necessary allocate the memory.
01091     BOOL fDidAlloc = FALSE;
01092     HANDLE hGlobalMem = m_hMem;
01093     if (hGlobalMem)
01094     {
01095         // We have some already.  Set the size.
01096         MaxSize = m_cbMemSize;
01097     }
01098     else
01099     {
01100         // We don't have any, so try to allocate and remember that we did so.
01101         hGlobalMem = m_hMem = GlobalAlloc(GHND, MaxSize);
01102         if (!hGlobalMem) return 0;
01103         fDidAlloc = TRUE;
01104     }
01105 
01106 #else
01107 
01108     // Allocate a block of global memory to store the text
01109     HANDLE hGlobalMem = GlobalAlloc(GHND, MaxSize);
01110 
01111     if (hGlobalMem == NULL)
01112         return(NULL);
01113 
01114 #endif
01115 
01116     // Get a UNICODE text buffer
01117     char* buff = (char*) GlobalLock(hGlobalMem);
01118     if (buff == NULL)
01119     {
01120         return(NULL);
01121     }
01122 
01123     // Scan the entire document tree, and lob every TextChar we find into the export buffer
01124     // NOTE that the Global{Re}Alloc zeros memory, so we don't need to worry about 0-termination.
01125     Node *pSubtree = InternalClipboard::GetInsertionLayer();
01126     Node *pNode = pSubtree->FindFirstDepthFirst();
01127     while (pNode != NULL)
01128     {
01129         if (pNode->IsKindOf(CC_RUNTIME_CLASS(TextChar)) || pNode->IsKindOf(CC_RUNTIME_CLASS(EOLNode)))
01130         {
01131             if (pNode->IsKindOf(CC_RUNTIME_CLASS(TextChar)))
01132             {
01133                 UINT32 ComposedChar = UnicodeManager::UnicodeToMultiByte(((TextChar *) pNode)->GetUnicodeValue());
01134                 BYTE LeadByte = 0;
01135                 BYTE TrailByte = 0;
01136                 UnicodeManager::DecomposeMultiBytes(ComposedChar, &LeadByte, &TrailByte);
01137 
01138                 if (LeadByte != 0)
01139                     buff[CurrentSize++] = LeadByte;
01140 
01141                 buff[CurrentSize++] = TrailByte;
01142             }
01143             else
01144             {
01145                 if (!((EOLNode*)pNode)->IsVirtual())
01146                 {
01147                     buff[CurrentSize++] = (char) 0x0D;      // CRLF - newline
01148                     buff[CurrentSize++] = (char) 0x0A;
01149                 }
01150             }
01151 
01152             // Check if we've overrun the buffer - if so, we need to make the buffer bigger
01153             // (Allow 3 entries at the end (1 to guarantee we have a zero terminator, and 2 more
01154             // to allow room to fit the 2-char newline sequence in!)
01155             if ( (CurrentSize * sizeof(char)) >= MaxSize - 3)
01156             {
01157             #if (_OLE_VER >= 0x200)
01158                 // If we didn't allocate the block then we can't resize it.
01159                 if (!fDidAlloc) return 0;
01160                 m_hMem = 0;
01161             #endif
01162                 
01163                 GlobalUnlock(hGlobalMem);
01164 
01165                 MaxSize += Increment;
01166                 HANDLE hNewMem = GlobalReAlloc(hGlobalMem, MaxSize, GHND);
01167                 if (hNewMem == NULL)
01168                 {
01169                     GlobalFree(hGlobalMem);
01170                     return(NULL);
01171                 }
01172 
01173                 hGlobalMem = hNewMem;
01174                 buff = (char *)GlobalLock(hGlobalMem);
01175 
01176                 if (buff == NULL)
01177                 {
01178                     GlobalFree(hGlobalMem);
01179                     return(NULL);
01180                 }
01181 
01182             #if (_OLE_VER >= 0x200)
01183                 // Remember this block.
01184                 m_hMem = hNewMem;
01185             #endif
01186             }
01187         }
01188         pNode = pNode->FindNextDepthFirst(pSubtree);
01189     }
01190 
01191     // We must unlock the block before giving it to the clipboard
01192     GlobalUnlock(hGlobalMem);
01193 
01194     return(hGlobalMem);
01195 }

BOOL BodgeTextClipMap::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 from ClipboardMapping.

Definition at line 909 of file clipmap.cpp.

00910 {
00911     char *buff=(char*)GlobalLock(ClipboardData);
00912     if (buff != NULL && buff[0] != 0)
00913     {
00914         // position arbitarily on clipboard - when pasted the clip contents are centered anyway
00915         TextStory* TheStory=TextStory::CreateFromChars(DocCoord(100,100), buff, NULL,
00916                                                        InternalClipboard::Instance(), NULL, TRUE);
00917 
00918         // Unlock the clipboard data, as we won't need it again
00919         GlobalUnlock(ClipboardData);
00920 
00921         if (TheStory!=NULL)
00922         {
00923             // OK, attach the new story to the clipboard document
00924             TheStory->AttachNode(InternalClipboard::GetInsertionLayer(), LASTCHILD);
00925             TheStory->NormaliseAttributes();
00926 
00927             // And make it reformat itself properly
00928             TheStory->FormatAndChildren(NULL,FALSE,FALSE);
00929             return(TRUE);
00930         }
00931 
00932         // We failed (no text story), so report and ensure the clipboard is 'clean'
00933         InformError();
00934         InternalClipboard::Clear();
00935     }
00936 
00937     // We failed
00938     return(FALSE);
00939 }


Friends And Related Function Documentation

friend class ExternalClipboard [friend]
 

Reimplemented from ClipboardMapping.

Definition at line 285 of file clipmap.h.

friend class OpClipboardExport [friend]
 

Reimplemented from ClipboardMapping.

Definition at line 286 of file clipmap.h.

friend class OpClipboardImport [friend]
 

Reimplemented from ClipboardMapping.

Definition at line 287 of file clipmap.h.


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