#include <clipmap.h>
Inheritance diagram for ClipboardMapping:
Public Member Functions | |
virtual | ~ClipboardMapping () |
Destructor. | |
InternalClipboardFormat * | GetInternalDataType (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 |
Filter * | pFilter |
InternalClipboardFormat | InternalDataType |
UINT32 | ExternalDataType |
UINT32 | RealExternalType |
UINT32 | Priority |
BOOL | Available |
Friends | |
class | ExternalClipboard |
class | OpClipboardExport |
class | OpClipboardImport |
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.
Definition at line 160 of file clipmap.h.
|
Destructor.
Definition at line 199 of file clipmap.cpp. 00200 { 00201 RemoveTempFile(); 00202 }
|
|
Constructor.
Definition at line 181 of file clipmap.cpp. 00182 { 00183 ERROR3("You can't directly construct an ClipboardMapping - Call CreateAndRegister"); 00184 }
|
|
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.
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
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 }
|
|
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.
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.
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 }
|
|
Internal helper function. Invokes pFilter::DoExport from the Source doc, using the given file as a destination.
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 }
|
|
Definition at line 213 of file clipmap.h. 00213 { return(&InternalDataType); }
|
|
Finds a temporary file Remove it with 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 }
|
|
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.
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 }
|
|
Calls the parent filter as appropriate to import the given data from the external clipboard.
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 }
|
|
Internal helper function. Invokes pFilter::DoImport into the Dest doc, using the given file as a source.
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 }
|
|
Removes the last temporary file 'allocated' with 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 }
|
|
Reimplemented in BodgeTextClipMap, BodgeUnicodeClipMap, BitmapClipMap, DIBClipMap, CMXClipMap, CMX16ClipMap, CMX32ClipMap, MetaFileClipMap, and NativeClipMap. |
|
Reimplemented in BodgeTextClipMap, BodgeUnicodeClipMap, BitmapClipMap, DIBClipMap, CMXClipMap, CMX16ClipMap, CMX32ClipMap, MetaFileClipMap, and NativeClipMap. |
|
Reimplemented in BodgeTextClipMap, BodgeUnicodeClipMap, BitmapClipMap, DIBClipMap, CMXClipMap, CMX16ClipMap, CMX32ClipMap, MetaFileClipMap, and NativeClipMap. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|