CCClipBoardFile Class Reference

Will be used to access Windows text clipboard files. More...

#include <oilfiles.h>

Inheritance diagram for CCClipBoardFile:

CCMemFile CCLexFile CCFile CCObject SimpleCCObject List of all members.

Public Member Functions

 CCClipBoardFile (FileAccess fProt=CCMemRead)
 Constructs an instance of CCClipBoardFile and Opens it.
 ~CCClipBoardFile ()
 Default destructor.
BOOL open (FileAccess fProt=CCMemRead)
 Constructs opens the clipboard for reading or writing.
CCFileread (TCHAR &buf)
 Reads a single character from the Memory file.
CCFileread (StringBase *buf)
 Reads a stream of characters from the Memory file.
CCFilewrite (const TCHAR &buf)
 Writes a single character to the Clipboard file.
CCFilewrite (const StringBase &buf, UINT32 length)
 Writes a stream of characters to the ClipBoard file.
BOOL eof () const
 Determines whether an instance of CCClipBoardFile is open.
void close ()
 Closes an instance of a CCClipBoardFile.

Protected Member Functions

BOOL GrowClipBoardFile ()
 Increases the size of the file by the default size of 1k.

Protected Attributes

HGLOBAL ClipBoardHandle

Detailed Description

Will be used to access Windows text clipboard files.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/9/1993 Base Class: CCMemFile
Returns:
Errors: None.

Definition at line 181 of file oilfiles.h.


Constructor & Destructor Documentation

CCClipBoardFile::CCClipBoardFile FileAccess  fProt = CCMemRead  ) 
 

Constructs an instance of CCClipBoardFile and Opens it.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Parameters:
fProt - defines the files protection - default = read only [INPUTS]
Date:
9/9/93

Definition at line 605 of file oilfiles.cpp.

00606 {
00607     // Get Current Applications main window and apply the OpenClipboard() member 
00608     // function to it!
00609     ((AfxGetApp())->m_pMainWnd)->OpenClipboard();
00610     
00611     FileProt    = fProt;
00612 
00613     if (FileProt == CCMemRead)
00614     {
00615         // Check to see if there is any text in the clipboard
00616         if (IsClipboardFormatAvailable(CF_TEXT))
00617         {
00618             IsOpen = FALSE;
00619             Error::SetError(_R(IDE_EMPTY_CLIPBOARD), 0);
00620             return;
00621         }   
00622 
00623         // Get a handle to the clipboard data
00624         ClipBoardHandle = GetClipboardData(CF_TEXT);
00625     
00626         // Check if clipboard data could be found
00627         if (ClipBoardHandle == NULL)
00628         {
00629             IsOpen = FALSE;
00630             Error::SetError(_R(IDE_LOAD_CLIPBOARD), 0);
00631             return;
00632         }   
00633     
00634         // Get a pointer to the clipboard data
00635         MemFile = (BYTE*) GlobalLock(ClipBoardHandle);
00636            
00637         // Check if memory to be occupied by data was available
00638         if (MemFile == NULL)
00639         {                  
00640             IsOpen = FALSE;
00641             Error::SetError(_R(IDE_LOAD_CLIPBOARD), 0);
00642             return;
00643         }   
00644     
00645         // Get the size of the data
00646         FileSize    = (UINT32) GlobalSize(ClipBoardHandle);
00647     }
00648     else if (FileProt == CCMemWrite)
00649     {
00650         // Empty Clipboard
00651         EmptyClipboard();
00652 
00653         // Allocate Global Memory 
00654         ClipBoardHandle = GlobalAlloc(GHND, (DWORD) CCFILE_DEFAULTSIZE);
00655 
00656         // Check if Memory was allocated properly
00657         if (ClipBoardHandle == NULL)
00658         {
00659             IsOpen = FALSE;
00660             Error::SetError(_R(IDE_LOAD_CLIPBOARD), 0);
00661             return;
00662         }   
00663 
00664         // Get a pointer to the clipboard
00665         MemFile = (BYTE*) GlobalLock(ClipBoardHandle);
00666            
00667         // Check if memory to be occupied by data was available
00668         if (MemFile == NULL)
00669         {                  
00670             IsOpen = FALSE;
00671             Error::SetError(_R(IDE_LOAD_CLIPBOARD), 0);
00672             return;
00673         }   
00674         
00675         // Set to default size.
00676         FileSize = CCFILE_DEFAULTSIZE;
00677     } 
00678      
00679     CurrentPos  = 0;    
00680     IsOpen      = TRUE;
00681 }

CCClipBoardFile::~CCClipBoardFile  ) 
 

Default destructor.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/93

Definition at line 693 of file oilfiles.cpp.

00694 {                   
00695     CCMemFile::~CCMemFile();
00696     
00697     // if the file has been left open then unlock memory and close clipboard
00698     if (isOpen())
00699     {
00700         // Unlock memory allocated
00701         GlobalUnlock(ClipBoardHandle);
00702                    
00703         // Write to clipboard - ClipBoardHandle must be unlocked before given to clipboard
00704         SetClipboardData(CF_TEXT, ClipBoardHandle);                   
00705                    
00706         // Close the clipboard
00707         CloseClipboard();
00708     }
00709 }


Member Function Documentation

void CCClipBoardFile::close  )  [virtual]
 

Closes an instance of a CCClipBoardFile.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/93

Reimplemented from CCMemFile.

Definition at line 1062 of file oilfiles.cpp.

01063 {   
01064     IsOpen = FALSE;
01065                                  
01066     // Unlock memory allocated
01067     GlobalUnlock(ClipBoardHandle);
01068                    
01069     // Write to clipboard - ClipBoardHandle must be unlocked before given to clipboard
01070     SetClipboardData(CF_TEXT, ClipBoardHandle);                   
01071                    
01072     // Close the clipboard
01073     CloseClipboard();
01074 }

BOOL CCClipBoardFile::eof  )  const [virtual]
 

Determines whether an instance of CCClipBoardFile is open.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/93 Return: TRUE if end of file and FALSE otherwize

Reimplemented from CCMemFile.

Definition at line 1039 of file oilfiles.cpp.

01040 {                                          
01041     TCHAR* tempClipFile = (TCHAR*) MemFile;             // Cast MemFile to a TCHAR pointer
01042 
01043     // Changed the '==' to '>=' in the following check on CurrentPos (MarkN 9/5/94)
01044 
01045     if ((CurrentPos >= (FileSize - 1)) || (tempClipFile[CurrentPos] == END_OF_FILE))
01046         return TRUE;
01047     else
01048         return FALSE;
01049 }

BOOL CCClipBoardFile::GrowClipBoardFile  )  [protected]
 

Increases the size of the file by the default size of 1k.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/9/93
Returns:
TRUE if File was increased ok and FALSE otherwize

Definition at line 814 of file oilfiles.cpp.

00815 {                                                 
00816     //Increase File Size
00817     FileSize += CCFILE_DEFAULTSIZE; 
00818     
00819     // Unlock memory allocated
00820     GlobalUnlock(ClipBoardHandle);
00821                    
00822     // Allocate Global Memory 
00823     ClipBoardHandle = GlobalReAlloc(ClipBoardHandle, 
00824                                     (DWORD) FileSize,
00825                                     (GMEM_MOVEABLE | GMEM_ZEROINIT)
00826                                     );
00827 
00828     // Check if Memory was allocated properly
00829     if (ClipBoardHandle == NULL)
00830     {
00831         IsOpen = FALSE;
00832         Error::SetError(_R(IDE_REALLOC_ERROR), 0);
00833         return FALSE;
00834     }                                    
00835     
00836     // Get a pointer to the clipboard
00837     MemFile = (BYTE*) GlobalLock(ClipBoardHandle);
00838 
00839     // Check if memory to be occupied by data was available
00840     if (MemFile == NULL)
00841     {                  
00842         IsOpen = FALSE;
00843         Error::SetError(_R(IDE_LOAD_CLIPBOARD), 0);
00844         return FALSE;
00845     }   
00846 
00847     return TRUE;
00848 }

BOOL CCClipBoardFile::open FileAccess  fProt = CCMemRead  ) 
 

Constructs opens the clipboard for reading or writing.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/9/93
Parameters:
fProt - defines the files protection - default = read only [INPUTS]
Returns:
TRUE if file is opened ok and FALSE otherwize

Definition at line 723 of file oilfiles.cpp.

00724 {
00725     // Get Current Applications main window and apply the OpenClipboard() member 
00726     // function to it!
00727     ((AfxGetApp())->m_pMainWnd)->OpenClipboard();
00728     
00729     FileProt    = fProt;
00730 
00731     if (FileProt == CCMemRead)
00732     {
00733         // Check to see if there is any text in the clipboard
00734         if (IsClipboardFormatAvailable(CF_TEXT))
00735         {
00736             IsOpen = FALSE;
00737             Error::SetError(_R(IDE_EMPTY_CLIPBOARD), 0);
00738             return FALSE;
00739         }   
00740 
00741         // Get a handle to the clipboard data
00742         ClipBoardHandle = GetClipboardData(CF_TEXT);
00743     
00744         // Check if clipboard data could be found
00745         if (ClipBoardHandle == NULL)
00746         {
00747             IsOpen = FALSE;
00748             Error::SetError(_R(IDE_LOAD_CLIPBOARD), 0);
00749             return FALSE;
00750         }   
00751     
00752         // Get a pointer to the clipboard data
00753         MemFile = (BYTE*) GlobalLock(ClipBoardHandle);
00754            
00755         // Check if memory to be occupied by data was available
00756         if (MemFile == NULL)
00757         {                  
00758             IsOpen = FALSE;
00759             Error::SetError(_R(IDE_LOAD_CLIPBOARD), 0);
00760             return FALSE;
00761         }   
00762     
00763         // Get the size of the data
00764         FileSize    = (UINT32) GlobalSize(ClipBoardHandle);
00765     }
00766     else if (FileProt == CCMemWrite)
00767     {
00768         // Empty Clipboard
00769         EmptyClipboard();
00770 
00771         // Allocate Global Memory 
00772         ClipBoardHandle = GlobalAlloc(GHND, (DWORD) CCFILE_DEFAULTSIZE);
00773 
00774         // Check if Memory was allocated properly
00775         if (ClipBoardHandle == NULL)
00776         {
00777             IsOpen = FALSE;
00778             Error::SetError(_R(IDE_LOAD_CLIPBOARD), 0);
00779             return FALSE;
00780         }   
00781 
00782         // Get a pointer to the clipboard
00783         MemFile = (BYTE*) GlobalLock(ClipBoardHandle);
00784            
00785         // Check if memory to be occupied by data was available
00786         if (MemFile == NULL)
00787         {                  
00788             IsOpen = FALSE;
00789             Error::SetError(_R(IDE_LOAD_CLIPBOARD), 0);
00790             return FALSE;
00791         }   
00792         
00793         // Set to default size.
00794         FileSize = CCFILE_DEFAULTSIZE;
00795     } 
00796      
00797     CurrentPos  = 0;    
00798     IsOpen      = TRUE;
00799     
00800     return IsOpen;
00801 }

CCFile & CCClipBoardFile::read StringBase buf  )  [virtual]
 

Reads a stream of characters from the Memory file.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/93
Parameters:
Length - is number of Bytes to be read in. [INPUTS] Output: The character string read in. Return: A reference to CCClipBoardFile object

Reimplemented from CCMemFile.

Definition at line 896 of file oilfiles.cpp.

00897 {
00898     // Make sure the file is open before it is read!
00899     if (!isOpen())
00900     {
00901         GotError(_R(IDE_NOTOPEN_ERROR));
00902         return (CCFile&) *this;
00903     }
00904 
00905     TCHAR* tempClipFile     = (TCHAR*) MemFile;         // Cast MemFile to a TCHAR pointer
00906     TCHAR* pString      = *buf;                     // Cast input string to a TCHAR pointer
00907     UINT32 i = 0;
00908     
00909     UINT32 MaxLen = buf->MaxLength();
00910 
00911     while ((i <= MaxLen) && (!eof()))   
00912     {
00913         *pString = tempClipFile[CurrentPos++];
00914         pString++;
00915         i++;
00916     }
00917     
00918     return (CCFile&) *this;
00919 }

CCFile & CCClipBoardFile::read TCHAR buf  )  [virtual]
 

Reads a single character from the Memory file.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/9/93 Outputs; character read in Return: A reference to a memory file object

Reimplemented from CCMemFile.

Definition at line 862 of file oilfiles.cpp.

00863 {
00864     // Make sure the file is open before it is read!
00865     if (!isOpen())
00866     {
00867         GotError(_R(IDE_NOTOPEN_ERROR));
00868         return (CCFile&) *this;
00869     }
00870 
00871     TCHAR* tempClipFile = (TCHAR*) MemFile;         // Cast MemFile to a TCHAR pointer
00872 
00873     if (!eof())
00874         buf = tempClipFile[CurrentPos++];
00875     else
00876     {
00877         GotError(_R(IDE_EOF_ERROR));
00878     }
00879 
00880     return (CCFile&) *this;
00881 }

CCFile & CCClipBoardFile::write const StringBase buf,
UINT32  length
[virtual]
 

Writes a stream of characters to the ClipBoard file.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/9/93
Parameters:
constant unicode string [INPUTS] Length denotes number of bytes to written Return: A reference to a clipboard file object

Reimplemented from CCMemFile.

Definition at line 979 of file oilfiles.cpp.

00980 {                                      
00981     // Make sure the file is open before it is written!
00982     if (!isOpen())
00983     {
00984         GotError(_R(IDE_NOTOPEN_ERROR));
00985         return (CCFile&) *this;
00986     }
00987 
00988     // if file is read only then exit
00989     if (FileProt != CCMemWrite)
00990     {
00991         GotError(_R(IDE_READ_ONLY));
00992         return (CCFile&) *this;
00993     }
00994     
00995     // Ensure that the length of the string to be written is not longer
00996     // than the string's maximum size
00997     if (length == 0)
00998         length = buf.Length();
00999     else if ((INT32) length > buf.MaxLength())
01000     {
01001         GotError(_R(IDE_STRING_SIZE_ERROR));
01002         return (CCFile&) *this;
01003     }
01004 
01005     const TCHAR* tempBuf = buf;
01006     TCHAR* tempClipFile;
01007     
01008     // Cast pointer to memory file to TCHAR
01009     tempClipFile = (TCHAR*) MemFile;
01010 
01011     for (UINT32 i = 0; (i <= length); i++)
01012     {
01013         // if the file size limit is reached then increase memory file by default amount
01014         if (CurrentPos != (FileSize - 1))
01015             tempClipFile[CurrentPos++] = *tempBuf++;
01016         else
01017             if (GrowClipBoardFile())
01018                 // write input byte
01019                 tempClipFile[CurrentPos++] = *tempBuf++;
01020             else
01021                 break;
01022     }
01023     
01024     return (CCFile&) *this;
01025 }

CCFile & CCClipBoardFile::write const TCHAR buf  ) 
 

Writes a single character to the Clipboard file.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/9/93
Parameters:
A pointer to a single char [INPUTS] Return: A reference to a clipboard file object

Definition at line 934 of file oilfiles.cpp.

00935 {
00936     // Make sure the file is open before it is written!
00937     if (!isOpen())
00938     {
00939         GotError(_R(IDE_NOTOPEN_ERROR));
00940         return (CCFile&) *this;
00941     }
00942 
00943     // if file is read only then exit
00944     if (FileProt != CCMemWrite)
00945     {
00946         GotError(_R(IDE_READ_ONLY));
00947         return (CCFile&) *this;
00948     }
00949     
00950     TCHAR* tempClipFile;
00951     
00952     // Cast pointer to memory file to TCHAR
00953     tempClipFile = (TCHAR*) MemFile;
00954     
00955     // if the file size limit is reached then increase memory file by default amount
00956     if (CurrentPos != (FileSize - 1)) 
00957         tempClipFile[CurrentPos++] = buf;
00958     else 
00959         if (GrowClipBoardFile())
00960             // write input byte
00961             tempClipFile[CurrentPos++] = buf;
00962                 
00963     return (CCFile&) *this;
00964 }


Member Data Documentation

HGLOBAL CCClipBoardFile::ClipBoardHandle [protected]
 

Definition at line 184 of file oilfiles.h.


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