BodgeUnicodeClipMap Class Reference

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

#include <clipmap.h>

Inheritance diagram for BodgeUnicodeClipMap:

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

 BodgeUnicodeClipMap ()
 BodgeUnicodeClipMap (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 unicode text A proper text filter will be written one day which will replace this bodge

See also:
ClipboardMapping; ExternalClipboard; Filter

Definition at line 328 of file clipmap.h.


Constructor & Destructor Documentation

BodgeUnicodeClipMap::BodgeUnicodeClipMap  )  [protected]
 

Definition at line 1206 of file clipmap.cpp.

01207 {
01208     ERROR3("Please don't press that button again");
01209 }

BodgeUnicodeClipMap::BodgeUnicodeClipMap 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:
BodgeUnicodeClipMap::CreateAndRegister

Definition at line 1238 of file clipmap.cpp.

01239                 : ClipboardMapping(TheType, NULL, InternalClipboardFormat(CLIPTYPE_TEXT),
01240                                     CF_UNICODETEXT, 55)
01241 {
01242     if (ClaimType != 0)
01243         ExternalDataType = ClaimType;
01244 }


Member Function Documentation

void BodgeUnicodeClipMap::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 1271 of file clipmap.cpp.

01272 {
01273     BodgeUnicodeClipMap *Mapping = new BodgeUnicodeClipMap(TheType, ClaimType);
01274     if (Mapping == NULL)
01275         InformError();
01276     else
01277         ExternalClipboard::RegisterDataType(Mapping);
01278 }

HANDLE BodgeUnicodeClipMap::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 1470 of file clipmap.cpp.

01471 {
01472     const DWORD Increment = 1024 * sizeof(WCHAR);
01473     DWORD CurrentSize   = 0;
01474     DWORD MaxSize       = Increment;
01475 
01476 #if (_OLE_VER >= 0x200)
01477 
01478     // If necessary allocate the memory.
01479     BOOL fDidAlloc = FALSE;
01480     HANDLE hGlobalMem = m_hMem;
01481     if (hGlobalMem)
01482     {
01483         // We have some already.  Set the size.
01484         MaxSize = m_cbMemSize;
01485     }
01486     else
01487     {
01488         // We don't have any, so try to allocate and remember that we did so.
01489         hGlobalMem = m_hMem = GlobalAlloc(GHND, MaxSize);
01490         if (!hGlobalMem) return 0;
01491         fDidAlloc = TRUE;
01492     }
01493 
01494 #else
01495 
01496     // Allocate a block of global memory to store the text
01497     HANDLE hGlobalMem = GlobalAlloc(GHND, MaxSize);
01498 
01499     if (hGlobalMem == NULL)
01500         return(NULL);
01501 
01502 #endif
01503 
01504     // Get a UNICODE text buffer
01505     WCHAR *buff = (WCHAR *)GlobalLock(hGlobalMem);
01506     if (buff == NULL)
01507     {
01508         return(NULL);
01509     }
01510 
01511     // Scan the entire document tree, and lob every TextChar we find into the export buffer
01512     // NOTE that the Global{Re}Alloc zeros memory, so we don't need to worry about 0-termination.
01513     Node *pSubtree = InternalClipboard::GetInsertionLayer();
01514     Node *pNode = pSubtree->FindFirstDepthFirst();
01515     while (pNode != NULL)
01516     {
01517         if (pNode->IsKindOf(CC_RUNTIME_CLASS(TextChar)) || pNode->IsKindOf(CC_RUNTIME_CLASS(EOLNode)))
01518         {
01519             if (pNode->IsKindOf(CC_RUNTIME_CLASS(TextChar)))
01520             {
01521                 buff[CurrentSize] = ((TextChar *) pNode)->GetUnicodeValue();
01522                 CurrentSize++;
01523             }
01524             else
01525             {
01526                 buff[CurrentSize++] = 0x000D;       // CRLF - newline
01527                 buff[CurrentSize++] = 0x000A;
01528             }
01529 
01530             // Check if we've overrun the buffer - if so, we need to make the buffer bigger
01531             // (Allow 3 entries at the end (1 to guarantee we have a zero terminator, and 2 more
01532             // to allow room to fit the 2-char newline sequence in!)
01533             if ( (CurrentSize * sizeof(WCHAR)) >= MaxSize - 3)
01534             {
01535             #if (_OLE_VER >= 0x200)
01536                 // If we didn't allocate the block then we can't resize it.
01537                 if (!fDidAlloc) return 0;
01538                 m_hMem = 0;
01539             #endif
01540                 
01541                 GlobalUnlock(hGlobalMem);
01542 
01543                 MaxSize += Increment;
01544                 HANDLE hNewMem = GlobalReAlloc(hGlobalMem, MaxSize, GHND);
01545                 if (hNewMem == NULL)
01546                 {
01547                     GlobalFree(hGlobalMem);
01548                     return(NULL);
01549                 }
01550 
01551                 hGlobalMem = hNewMem;
01552                 buff = (WCHAR *)GlobalLock(hGlobalMem);
01553 
01554                 if (buff == NULL)
01555                 {
01556                     GlobalFree(hGlobalMem);
01557                     return(NULL);
01558                 }
01559 
01560             #if (_OLE_VER >= 0x200)
01561                 // Remember this block.
01562                 m_hMem = hNewMem;
01563             #endif
01564             }
01565         }
01566         pNode = pNode->FindNextDepthFirst(pSubtree);
01567     }
01568 
01569     // We must unlock the block before giving it to the clipboard
01570     GlobalUnlock(hGlobalMem);
01571 
01572     return(hGlobalMem);
01573 }

BOOL BodgeUnicodeClipMap::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 1297 of file clipmap.cpp.

01298 {
01299     WCHAR *buff=(WCHAR*)GlobalLock(ClipboardData);
01300     if (buff != NULL && buff[0] != 0)
01301     {
01302         // position arbitarily on clipboard - when pasted the clip contents are centered anyway
01303         TextStory* TheStory=TextStory::CreateFromChars(DocCoord(100,100), NULL, buff,
01304                                                        InternalClipboard::Instance(), NULL, TRUE);
01305 
01306         // Unlock the clipboard data, as we won't need it again
01307         GlobalUnlock(ClipboardData);
01308 
01309         if (TheStory!=NULL)
01310         {
01311             // OK, attach the new story to the clipboard document
01312             TheStory->AttachNode(InternalClipboard::GetInsertionLayer(), LASTCHILD);
01313             TheStory->NormaliseAttributes();
01314 
01315             // And make it reformat itself properly
01316             TheStory->FormatAndChildren(NULL,FALSE,FALSE);
01317             return(TRUE);
01318         }
01319 
01320         // We failed (no text story), so report and ensure the clipboard is 'clean'
01321         InformError();
01322         InternalClipboard::Clear();
01323     }
01324 
01325     // We failed
01326     return(FALSE);
01327 }


Friends And Related Function Documentation

friend class ExternalClipboard [friend]
 

Reimplemented from ClipboardMapping.

Definition at line 332 of file clipmap.h.

friend class OpClipboardExport [friend]
 

Reimplemented from ClipboardMapping.

Definition at line 333 of file clipmap.h.

friend class OpClipboardImport [friend]
 

Reimplemented from ClipboardMapping.

Definition at line 334 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