OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
clipboar.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of classes for clipboard Encapsulation
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_CLIPBOAR_H)
10#define OWL_CLIPBOAR_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/defs.h>
18#include <owl/except.h> // Owl exception classes
19
20
21namespace owl {
22
23#include <owl/preclass.h>
24
25/// \addtogroup Clipboard
26/// @{
27/// \class TClipboard
28// ~~~~~ ~~~~~~~~~~
29/// The clipboard class encapsulates the methods for the clipboard object
30/// of Windows.
31//
33 public:
34 // Constructors / destructor
35 //
36 TClipboard(HWND hWnd, bool mustOpen=true); // aquire & open the clipboard
38
39 // Close & reopen the clipboard
40 //
41 void CloseClipboard();
42 bool OpenClipboard(HWND hWnd);
43
44 operator bool() const;
45
46 HANDLE GetClipboardData(uint format) const;
47 HWND GetOpenClipboardWindow() const;
48 HWND GetClipboardOwner() const;
49 HWND GetClipboardViewer() const;
50 int GetClipboardFormatName(uint format, LPTSTR formatName,
51 int maxCount) const;
52 int GetPriorityClipboardFormat(uint * priorityList, int count) const;
53 int CountClipboardFormats() const;
54 bool IsClipboardFormatAvailable(uint format) const;
55 bool EmptyClipboard();
56 uint RegisterClipboardFormat(const tstring& formatName) const;
57 HANDLE SetClipboardData(uint format, HANDLE handle);
58 HWND SetClipboardViewer(HWND hWnd) const;
59
60#if defined(__OLE_H) || defined(_INC_OLE)
61 bool QueryCreate(LPCTSTR protocol = DefaultProtocol,
64
66 {return QueryCreate(protocol.c_str(), renderopt, format);}
67
68 bool QueryLink(LPCTSTR protocol = DefaultProtocol,
71
73 {return QueryLink(protocol.c_str(), renderopt, format);}
74
75#endif
76
78
80 bool IsOpen;
81
82 TClipboard(); // used by the obsolete global object
83};
84/// @}
85
86/// \addtogroup except
87/// @{
88/// \class TXClipboard
89// ~~~~~ ~~~~~~~~~~~
90/// TXClipboard creates the TXClipboard exception with a string resource.
91//
92class _OWLCLASS TXClipboard : public TXOwl {
93 public:
95 TXClipboard* Clone();
96 void Throw();
97
98 static void Raise(uint resourceId = IDS_CLIPBOARDBUSY);
99};
100/// @}
101
102/// \addtogroup Clipboard
103/// @{
104// class TClipboardFormatIterator
105// ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
107 public:
109
110 uint Current();
111 operator void* ();
113 uint operator ++(int);
114 void Restart();
115
116 private:
117 uint _Current;
118};
119/// @}
120
121#include <owl/posclass.h>
122
123
124//----------------------------------------------------------------------------
125// Inline implementations
126//
127
128//
129/// Create an empty clipboard object.
130/// Set the state of the object to not opened.
131//
132inline TClipboard::TClipboard() {
133 IsOpen = false;
134}
135
136//
137/// Return true if the clipboard is currently owned by this application.
138//
139inline TClipboard::operator bool() const {
140 return IsOpen;
141}
142
143//
144/// Retrieves data from the Clipboard in the format specified by format.The
145/// following formats are supported:
146/// - \c \b CF_BITMAP Data is a handle to a bitmap format
147/// - \c \b CF_DIB Data is memory bitmap with a BITMAPINFO structure
148/// - \c \b CF_DIBV5 Data is memory bitmap with a BITMAPV5HEADER structure
149/// - \c \b CF_DIF Data is in a Data Interchange Format (DIF).
150/// - \c \b CF_DSPBITMAP Data is a handle to a private bitmap format
151/// - \c \b CF_DSPENHMETAFILE Data is a handle to a private enhanced metafile.
152/// - \c \b CF_DSPMETAFILEPICT Data is in a private metafile format.
153/// - \c \b CF_DSPTEXT Data is in a private text format.
154/// - \c \b CF_ENHMETAFILE Data is a handle to an enhanced metafile.
155/// - \c \b CF_GDIOBJFIRST Data is the start of a range of integer values for application-defined GDI object clipboard formats.
156/// - \c \b CF_GDIOBJLAST Data is the last of a range of integer values for application-defined GDI object clipboard formats.
157/// - \c \b CF_HDROP Data is a handle to type HDROP that identifies a list of files.
158/// - \c \b CF_LOCALE Data is a handle to the locale identifier associated with the clipboard text.
159/// - \c \b CF_METAFILEPICT Data is in a metafile structure.
160/// - \c \b CF_OEMTEXT Data is an array of text characters in OEM character set.
161/// - \c \b CF_OWNERDISPLAT Data is in a special format that the application must display.
162/// - \c \b CF_PALETTE Data is in a color palette format.
163/// - \c \b CF_PENDATA Data is used for pen format.
164/// - \c \b CF_PRIVATEFIRST Data is the start of a range of integer values for private clipboard formats.
165/// - \c \b CF_PRIVATELAST Data is the last of a range of integer values for private clipboard formats.
166/// - \c \b CF_RIFF Data is in Resource Interchange File Format (RIFF).
167/// - \c \b CF_SYLK Data is in symbolic Link format (SYLK).
168/// - \c \b CF_TEXT Data is stored as an array of text characters.
169/// - \c \b CF_TIFF Data is in Tag Image File Format (TIFF).
170/// - \c \b CF_UNICODETEXT Data is stored as an array of Unicode text characters.
171/// - \c \b CF_WAVE Data is in a sound wave format.
172//
174 return ::GetClipboardData(Format);
175}
176
177//
178/// Retrieves the handle of the window that currently has the Clipboard open. If the
179/// Clipboard is not open, the return value is NULL. Once the Clipboard is opened,
180/// applications cannot modify the data.
181//
183 return ::GetOpenClipboardWindow();
184}
185
186//
187/// Retrieves the handle of the window that currently owns the Clipboard, otherwise
188/// returns NULL.
189//
191 return ::GetClipboardOwner();
192}
193
194//
195/// Retrieves the handle of the first window in the Clipboard-view chain. Returns
196/// NULL if there is no viewer.
197//
199 return ::GetClipboardViewer();
200}
201
202//
203/// Retrieves the name of the registered format specified by format and copies the
204/// format to the buffer pointed to by formatName. maxCount specifies the maximum
205/// length of the name of the format. If the name is longer than maxCount, it is
206/// truncated.
207//
209 return ::GetClipboardFormatName(Format, FormatName, MaxCount);
210}
211
212//
213/// Returns the first Clipboard format in a list. priorityList points to an array
214/// that contains a list of the Clipboard formats arranged in order of priority. See
215/// GetClipboardData for the Clipboard formats.
216//
218 return ::GetPriorityClipboardFormat(priorityList, count);
219}
220
221//
222/// Returns a count of the number of types of data formats the Clipboard can use.
223//
225 return ::CountClipboardFormats();
226}
227
228//
229/// Indicates if the format specified in format exists for use in the Clipboard. See
230/// GetClipBoardData for a description of Clipboard data formats.
231/// The following code tests if the Clipboard can support the specified formats:
232/// \code
233/// void
234/// TBmpViewWindow::CePaste(TCommandEnabler& ce)
235/// {
236/// TClipboard& clipboard = OpenClipboard();
237/// ce.Enable(
238/// clipboard && (
239/// clipboard.IsClipboardFormatAvailable(CF_METAFILEPICT) ||
240/// clipboard.IsClipboardFormatAvailable(CF_DIB) ||
241/// clipboard.IsClipboardFormatAvailable(CF_BITMAP)
242/// )
243/// );
244/// clipboard.CloseClipboard();
245/// \endcode
246//
248 return ::IsClipboardFormatAvailable(format);
249}
250
251//
252/// Clears the Clipboard and frees any handles to the Clipboard's data. Returns true
253/// if the Clipboard is empty, or false if an error occurs.
254//
256 return ::EmptyClipboard();
257}
258
259//
260/// Registers a new Clipboard format. formatName points to a character string that
261/// identifies the new format. If the format can be registered, the return value
262/// indicates the registered format. If the format can't be registered, the return
263/// value is 0. Once the format is registered, it can be used as a valid format in
264/// which to render the data.
265//
267 return ::RegisterClipboardFormat(formatName.c_str());
268}
269
270//
271/// Copy the data onto the clipboard in the format.
272//
273/// Sets a handle to the block of data at the location indicated by handle. format
274/// specifies the format of the data block. The Clipboard must have been opened
275/// before the data handle is set. format can be any one of the valid Clipboard
276/// formats (for example, CF_BITMAP or CF_DIB). See GetClipboardData for a list of
277/// these formats. handle is a handle to the memory location where the data data is
278/// stored. If successful, the return value is a handle to the data; if an error
279/// occurs, the return value is 0. Before the window is updated with the Clipboard
280/// data, the Clipboard must be closed.
281//
283 return ::SetClipboardData(Format,Handle);
284}
285
286//
287/// Adds the window specified by Wnd to the chain of windows that WM_DRAWCLIPBOARD
288/// notifies whenever the contents of the Clipboard change.
289//
291 return ::SetClipboardViewer(Wnd);
292}
293
294#if defined(__OLE_H) || defined(_INC_OLE)
295//
296/// Return true if the object on the clipboard can be rendered in the
297/// requested format.
298//
299/// QueryCreate determines if the object on the Clipboard supports the specified
300/// protocol and rendering options. DefaultProtocol points to a string specifying
301/// the name of the protocol the client application needs to use. renderopt
302/// specifies the client application's display and printing preference for the
303/// Clipboard object. renderopt is set to olerender_draw, which tells the client
304/// library to obtain and manage the data presentation. format specifies the
305/// Clipboard format the client application requests. The macros _OLE_H or _INC_OLE
306/// must be defined before this function can be used.
307//
308inline bool TClipboard::QueryCreate(
312 )
313{
314 return ::OleQueryCreateFromClip(protocol, renderopt, format) == OLE_OK;
315}
316
317//
318/// Return true if the object on the clipboard can be linked to in the
319/// requested format.
320//
321/// QueryLink determines if a client application can use the Clipboard data to
322/// produce a linked object that uses the specified protocol and rendering options.
323/// See TClipboard::QueryCreate for a description of the parameters. The macros
324/// _OLE_H or _INC_OLE must be defined before this function can be used.
325//
326inline bool TClipboard::QueryLink(
330 )
331{
332 return ::OleQueryLinkFromClip(protocol, renderopt, format) == OLE_OK;
333}
334#endif
335
336
337//
338/// Return the current clipboard format.
339//
341 return _Current;
342}
343
344//
345/// Return true if the iterator is not at an end of the clipboard format
346/// chain.
347//
348inline TClipboardFormatIterator::operator void* () {
349 return _Current ? this : nullptr;
350}
351
352
353} // OWL namespace
354
355#endif // OWL_CLIPBOAR_H
uint Current()
Return the current clipboard format.
Definition clipboar.h:340
The clipboard class encapsulates the methods for the clipboard object of Windows.
Definition clipboar.h:32
HWND GetClipboardViewer() const
Retrieves the handle of the first window in the Clipboard-view chain.
Definition clipboar.h:198
int GetClipboardFormatName(uint format, TCHAR *formatName, int maxCount) const
Retrieves the name of the registered format specified by format and copies the format to the buffer p...
Definition clipboar.h:208
int GetPriorityClipboardFormat(uint *priorityList, int count) const
Returns the first Clipboard format in a list.
Definition clipboar.h:217
static LPCTSTR DefaultProtocol
Points to a string that specifies the name of the protocol the client needs.
Definition clipboar.h:77
HANDLE SetClipboardData(uint format, HANDLE handle)
Copy the data onto the clipboard in the format.
Definition clipboar.h:282
HWND SetClipboardViewer(HWND hWnd) const
Adds the window specified by Wnd to the chain of windows that WM_DRAWCLIPBOARD notifies whenever the ...
Definition clipboar.h:290
HWND GetOpenClipboardWindow() const
Retrieves the handle of the window that currently has the Clipboard open.
Definition clipboar.h:182
int CountClipboardFormats() const
Returns a count of the number of types of data formats the Clipboard can use.
Definition clipboar.h:224
bool IsClipboardFormatAvailable(uint format) const
Indicates if the format specified in format exists for use in the Clipboard.
Definition clipboar.h:247
HWND GetClipboardOwner() const
Retrieves the handle of the window that currently owns the Clipboard, otherwise returns NULL.
Definition clipboar.h:190
bool EmptyClipboard()
Clears the Clipboard and frees any handles to the Clipboard's data.
Definition clipboar.h:255
HANDLE GetClipboardData(uint format) const
Retrieves data from the Clipboard in the format specified by format.The following formats are support...
Definition clipboar.h:173
uint RegisterClipboardFormat(const tstring &formatName) const
Registers a new Clipboard format.
Definition clipboar.h:266
TXClipboard creates the TXClipboard exception with a string resource.
Definition clipboar.h:92
TXOwl is root class of the ObjectWindows exception hierarchy.
Definition except.h:38
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
General definitions used by all ObjectWindows programs.
#define protected_data
Definition defs.h:208
ObjectWindows exception class & function definitions.
#define _OWLCLASS
Definition defs.h:338