clipbrd.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:11k
- /*
- * clipbrd.h
- *
- * Clipboard interface.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: clipbrd.h,v $
- * Revision 1.15 1999/03/10 03:49:51 robertj
- * More documentation adjustments.
- *
- * Revision 1.14 1999/03/09 08:01:47 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.13 1999/02/16 08:08:45 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.12 1998/09/23 06:23:05 robertj
- * Added open source copyright license.
- *
- * Revision 1.11 1996/01/28 02:51:58 robertj
- * Added assert into all Compare functions to assure comparison between compatible objects.
- *
- * Revision 1.10 1995/04/22 00:37:42 robertj
- * Changed interactor owner to const pointer.
- *
- * Revision 1.9 1995/03/14 12:41:07 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.8 1994/12/05 11:34:05 robertj
- * Major rewrite of images, pictures and pixmaps.
- * Renamed PPict, PPixels and PImage to make sure all uses are found.
- *
- * Revision 1.7 1994/11/29 10:13:05 robertj
- * Documentation.
- *
- * Revision 1.6 1994/10/23 04:39:18 robertj
- * Changed PImage descendants to pointers for polymorphism.
- *
- * Revision 1.5 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.4 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.3 1994/01/03 04:42:23 robertj
- * Mass changes to common container classes and interactors etc etc etc.
- *
- * Revision 1.2 1993/10/16 20:33:20 robertj
- * Changed pixmap and metafile object names to new structure.
- *
- * Revision 1.1 1993/09/27 16:35:25 robertj
- * Initial revision
- *
- */
- #define _PCLIPBOARD
- #ifdef __GNUC__
- #pragma interface
- #endif
- /**A class representing the system clipboard. This is a platform dependent
- entity for temporary storage and/or transfering between applications of
- user data in a set of possible formats.
- There are only a few primitive data types supported, with all remaining
- types supported through a generic mechanism. The types are simple text,
- pixel images and picture images. All other types are represented by an
- arbitrary string and the data is placed in a simple memory block. The
- interpretation of that memory block is application dependent.
-
- The clipboard only ever contains one item of data, though this data may be
- available in a number of different formats. For example, a string contained
- in a drawing package may be placed in the clipboard in several ways: as a
- simple ANSI character sequence, as a pixel image of the rendered font, as a
- sequence of drawing commands that set the font, colours and a draw text
- command, or, finally, as an internal format containing the raw data
- structure used by the package.
- When transferring data between applications, only those that recognise the
- format name string will be able to use that format of data. Typically, an
- application places data in the clipboard in multiple formats for maximum
- portability across applications.
- */
- class PClipboard : public PObject
- {
- PCLASSINFO(PClipboard, PObject);
- public:
- /**Create a clipboard object to allow access to the system clipboard. As
- the clipboard is a system resource, it can only be accessed by one
- user at a time. This locking mechanism is made based on the interactor.
- Only one interactor can "own" the clipboard at any given time. The
- destruction of this object releases the lock.
- */
- PClipboard(
- const PInteractor * owner /// The interactor that "owns" the clipboard.
- );
- /**End access to the system clipboard deleting the clipboard object. It is
- very important that the clipboard object is destroyed as this releases
- the lock on the clipboard preventing access by any other user, even in
- other applications.
- */
- ~PClipboard();
- /**@name New functions for class */
- /**Determine if the clipboard was already in use. If this returns TRUE
- then all other clipboard functions will fail.
- @return
- TRUE if clipboard cannot be used.
- */
- BOOL InUse();
- /**Pre-defined formats for data that may be stored or transferred in the
- clipboard. There are individual functions available to access each type
- of data in the correct format.
- */
- enum Format {
- /// Simple lines of text
- Text,
- /// Pixel image
- Image,
- /// Picture image
- Picture,
- NumFormats
- };
- /**Determine if there is data in the clipboard of the specified format.
- @return
- TRUE if data can be retrieved in the required format.
- */
- BOOL HasFormat(
- Format fmt /// Format type identifier to check for.
- );
- /**Determine if there is data in the clipboard of the specified format.
- @return
- TRUE if data can be retrieved in the required format.
- */
- BOOL HasFormat(
- const PString & fmt /// Format type name string to check for.
- );
- /**Get the size of the data in the clipboard for the specifed format. This
- is for the generic data format as the pre-defined format data operations
- inherently know the size of the data being transferred.
- @return
- size in bytes of the data.
- */
- DWORD GetSize(
- const PString & fmt /// Format type name string to check for.
- );
- /**Get the data from the clipboard to the specified memory block. The size
- of the memory block must be greater than or equal to the length of the
- data in the clipboard.
- This function will fail if the clipboard was already in use when the
- object was constructed.
- @return
- TRUE if the data was completely copied.
- */
- BOOL GetData(
- const PString & fmt, /// Format type name string to check for.
- void * data, /// Pointer to memory to receive the data.
- DWORD max /// Size of the block of memory.
- );
- /**Set the data in the clipboard to the data specified by the memory block
- and length.
- The previous contents of the clipboard is lost on the first call to
- SetData for a particular clipboard object. Further calls to data setting
- functions will add the new format to the clipboard and not lose the
- previously set data. Once the PClipboard object is destroyed the next
- construction resets this mechanism so that data is lost once more.
- This function will fail if the clipboard was already in use when the
- object was constructed.
- @return
- TRUE if the data was completely copied.
- */
- BOOL SetData(
- const PString & fmt, /// Format type name string to check for.
- const void * data, /// Pointer to memory block to transfer.
- DWORD len /// Number of bytes to transfer to clipboard.
- );
- /**Get the data from the clipboard as a string if it is available in the
- {it Text} format.
- This function will fail, returning an empty string, if the clipboard was
- already in use when the object was constructed.
- @return
- String that was in the clipboard or empty string if the clipboard data
- was not available in this format.
- */
- PString GetText();
- /**Set the data in the clipboard to the text specified by the string in the
- {it Text} format.
- The previous contents of the clipboard is lost on the first call to
- SetText for a particular clipboard object. Further calls to data setting
- functions will add the new format to the clipboard and not lose the
- previously set data. Once the PClipboard object is destroyed the next
- construction resets this mechanism so that data is lost once more.
- This function will fail if the clipboard was already in use when the
- object was constructed.
- @return
- TRUE if the data was copied.
- */
- BOOL SetText(
- const PString & str /// New text to place in the clipboard.
- );
- /**Get the data from the clipboard as a pixel image if it is available in
- the {it Pixels} format.
- This function will fail, returning an empty image, if the clipboard was
- already in use when the object was constructed.
- @return
- String that was in the clipboard or an empty (1 bit) image if the
- clipboard data was not available in this format.
- */
- PPixelImage GetPixels();
- /**Set the data in the clipboard to the pixel image specified in the
- {it Pixels} format.
- The previous contents of the clipboard is lost on the first call to
- SetPixels for a particular clipboard object. Further calls to data
- setting functions will add the new format to the clipboard and not lose
- the previously set data. Once the PClipboard object is destroyed the
- next construction resets this mechanism so that data is lost once more.
- This function will fail if the clipboard was already in use when the
- object was constructed.
- @return
- TRUE if the data was copied.
- */
- BOOL SetPixels(
- const PPixelImage & img /// Pixel image to place into the clipboard.
- );
- /**Get the data from the clipboard as a picture image if it is available in
- the {it Picture} format.
- This function will fail, returning an empty image, if the clipboard was
- already in use when the object was constructed.
- @return
- String that was in the clipboard or an empty image if the clipboard
- data was not available in this format.
- */
- PPictImage GetPict();
- /**Set the data in the clipboard to the picture image specified in the
- {it Picture} format.
- The previous contents of the clipboard is lost on the first call to
- SetPict for a particular clipboard object. Further calls to data setting
- functions will add the new format to the clipboard and not lose the
- previously set data. Once the PClipboard object is destroyed the next
- construction resets this mechanism so that data is lost once more.
- This function will fail if the clipboard was already in use when the
- object was constructed.
- @return
- TRUE if the data was copied.
- */
- BOOL SetPict(
- const PPictImage & pic /// Picture image to place into the clipboard.
- );
- protected:
- /** The interactor that "owns" the open clipboard. */
- const PInteractor * owner;
- #ifdef DOC_PLUS_PLUS
- };
- #endif
- // Class declaration continued in platform specific header file ///////////////