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.cpp
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/// Implementation of TClipboard which provides clipboard encapsulation
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/clipboar.h>
10
11namespace owl {
12
14
15/// Points to a string that specifies the name of the protocol the client needs. The
16/// default protocol is "StdFileEditing," which is the name of the object linking
17/// and embedding protocol.
18LPCTSTR TClipboard::DefaultProtocol = _T("StdFileEditing");
19
20/// \class TClipboard
21/// TClipboard encapsulates and manipulates Clipboard data. You can open, close,
22/// empty, and paste data in a variety of data formats between the Clipboard and the
23/// open window. An object on the Clipboard can exist in a variety of Clipboard
24/// formats, which range from bitmaps to text.
25///
26/// Usually, the window is in charge of manipulating Clipboard interactions between
27/// the window and the Clipboard. It does this by responding to messages sent
28/// between the Clipboard owner and the application. The following ObjectWindows
29/// event-handling functions encapsulate these Clipboard messages:
30/// EvRenderFormat - Responds to a WM_RENDERFORMAT message sent to the Clipboard
31/// owner if a specific Clipboard format that an application has requested hasn't
32/// been rendered. After the Clipboard owner renders the data in the requested
33/// format, it callsSetClipboardData to place the data on the Clipboard.
34/// EvRenderAllFormats - Responds to a message sent to the Clipboard owner if the
35/// Clipboard owner has delayed rendering a Clipboard format. After the Clipboard
36/// owner renders data in all of possible formats, it calls SetClipboardData.
37///
38/// The following example tests to see If there is a palette on the Clipboard. If
39/// one exists, TClipboard retrieves the palette, realizes it, and then closes the
40/// Clipboard.
41/// \code
42/// if (clipboard.IsClipboardFormatAvailable(CF_PALETTE)) {
43/// newPal = new TPalette(TPalette(clipboard)); // make a copy
44/// UpdatePalette(true);
45/// }
46/// // Try DIB format first
47/// if (clipboard.IsClipboardFormatAvailable(CF_DIB)) {
48/// newDib = new TDib(TDib(clipboard)); // make a copy
49/// newBitmap = new TBitmap(*newDib, newPal); // newPal==0 is OK
50/// // try metafile Second
51/// //
52/// } else if (clipboard.IsClipboardFormatAvailable(CF_METAFILEPICT)) {
53/// if (!newPal)
54/// newPal = new TPalette((HPALETTE)GetStockObject(DEFAULT_PALETTE));
55/// newBitmap = new TBitmap(TMetaFilePict(clipboard), *newPal,
56/// GetClientRect().Size());
57/// ...
58/// // Gets a bitmap , keeps it, and sets up data on the clipboard.
59/// //
60/// delete Bitmap;
61/// Bitmap = newBitmap;
62///
63/// if (!newDib)
64/// newDib = new TDib(*newBitmap, newPal);
65/// #endif // ????
66/// delete Dib;
67/// Dib = newDib;
68///
69/// delete Palette;
70/// Palette = newPal ? newPal : new TPalette(*newDib);
71/// Palette->GetObject(Colors);
72///
73/// PixelWidth = Dib->Width();
74/// PixelHeight = Dib->Height();
75/// AdjustScroller();
76/// SetCaption("(Clipboard)");
77///
78/// clipboard.CloseClipboard();
79/// \endcode
80
81
82
83//
84/// Constructs a clipboard object to grab the clipboard given a window handle.
85/// This is the preferred method of getting the clipboard;
86//
87/// Throws an exception on open failure if mustOpen is true (default)
88/// mustOpen can be passed as false for compatability
89//
90TClipboard::TClipboard(HWND hWnd, bool mustOpen)
91{
93 if (mustOpen && !IsOpen)
95}
96
97//
98/// Destruct a clipboard object & close the clipboard if open
99//
101{
102 if (IsOpen)
104}
105
106//
107/// If the Clipboard is opened (IsOpen is true), closes the Clipboard. Closing the
108/// Clipboard allows other applications to access the Clipboard.
109//
110void
112{
113 if (IsOpen) {
115 IsOpen = false;
116 }
117}
118
119//
120/// Opens the Clipboard and associates it with the window specified in Wnd. Other
121/// applications cannot change the Clipboard data until the Clipboard is closed.
122/// Returns true if successful; otherwise, returns false.
123//
124bool
126{
127 return IsOpen = ::OpenClipboard(hWnd) != 0;
128}
129
130//----------------------------------------------------------------------------
131
132//
133/// Construct an available format iterator for a clipboard.
134//
135#if __DEBUG >= 1
137#else
139#endif
140{
141 PRECONDITION(bool(clip));
142 Restart();
143}
144
145//
146/// Restart the format iterator.
147//
148void
153
154//
155/// Get the next available format.
156//
157uint
159{
160 return _Current = ::EnumClipboardFormats(_Current);
161}
162
163//
164/// Get the previous format.
165//
166uint
168{
169 uint current = _Current;
170 _Current = ::EnumClipboardFormats(_Current);
171 return current;
172}
173
174//----------------------------------------------------------------------------
175
176//
177/// Create the TXClipboard exception with a string resource.
178//
184
185//
186// Clone the exception for safe throwing in Windows.
187//
190{
191 return new TXClipboard(*this);
192}
193
194
195//
196/// Throw the exception.
197//
198void
200{
201 throw *this;
202}
203
204//
205/// Throw the exception.
206//
207void
212
213} // OWL namespace
214/////////////////////////////////
#define PRECONDITION(condition)
Definition checks.h:227
TClipboardFormatIterator(const TClipboard &)
Construct an available format iterator for a clipboard.
Definition clipboar.cpp:138
void Restart()
Restart the format iterator.
Definition clipboar.cpp:149
uint operator++()
Get the next available format.
Definition clipboar.cpp:158
The clipboard class encapsulates the methods for the clipboard object of Windows.
Definition clipboar.h:32
static LPCTSTR DefaultProtocol
Points to a string that specifies the name of the protocol the client needs.
Definition clipboar.h:77
bool OpenClipboard(HWND hWnd)
Opens the Clipboard and associates it with the window specified in Wnd.
Definition clipboar.cpp:125
~TClipboard()
Destruct a clipboard object & close the clipboard if open.
Definition clipboar.cpp:100
void CloseClipboard()
If the Clipboard is opened (IsOpen is true), closes the Clipboard.
Definition clipboar.cpp:111
TXClipboard creates the TXClipboard exception with a string resource.
Definition clipboar.h:92
TXClipboard * Clone()
Definition clipboar.cpp:189
static void Raise(uint resourceId=IDS_CLIPBOARDBUSY)
Throw the exception.
Definition clipboar.cpp:208
TXClipboard(uint resourceId=IDS_CLIPBOARDBUSY)
Create the TXClipboard exception with a string resource.
Definition clipboar.cpp:179
void Throw()
Throw the exception.
Definition clipboar.cpp:199
TXOwl is root class of the ObjectWindows exception hierarchy.
Definition except.h:38
Definition of classes for clipboard Encapsulation.
#define _T(x)
Definition cygwin.h:51
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
unsigned int uint
Definition number.h:25