OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
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
11
namespace
owl
{
12
13
OWL_DIAGINFO
;
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.
18
LPCTSTR
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
//
90
TClipboard::TClipboard
(HWND hWnd,
bool
mustOpen)
91
{
92
OpenClipboard
(hWnd);
93
if
(mustOpen && !IsOpen)
94
throw
TXClipboard
(IDS_CLIPBOARDBUSY);
95
}
96
97
//
98
/// Destruct a clipboard object & close the clipboard if open
99
//
100
TClipboard::~TClipboard
()
101
{
102
if
(IsOpen)
103
::CloseClipboard
();
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
//
110
void
111
TClipboard::CloseClipboard
()
112
{
113
if
(IsOpen) {
114
::CloseClipboard
();
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
//
124
bool
125
TClipboard::OpenClipboard
(HWND hWnd)
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
136
TClipboardFormatIterator::TClipboardFormatIterator
(
const
TClipboard
& clip)
137
#else
138
TClipboardFormatIterator::TClipboardFormatIterator
(
const
TClipboard
&
/*clip*/
)
139
#endif
140
{
141
PRECONDITION
(
bool
(clip));
142
Restart
();
143
}
144
145
//
146
/// Restart the format iterator.
147
//
148
void
149
TClipboardFormatIterator::Restart
()
150
{
151
_Current = ::EnumClipboardFormats(0);
152
}
153
154
//
155
/// Get the next available format.
156
//
157
uint
158
TClipboardFormatIterator::operator ++
()
159
{
160
return
_Current = ::EnumClipboardFormats(_Current);
161
}
162
163
//
164
/// Get the previous format.
165
//
166
uint
167
TClipboardFormatIterator::operator ++
(
int
)
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
//
179
TXClipboard::TXClipboard
(
uint
resId)
180
:
181
TXOwl
(resId)
182
{
183
}
184
185
//
186
// Clone the exception for safe throwing in Windows.
187
//
188
TXClipboard
*
189
TXClipboard::Clone
()
190
{
191
return
new
TXClipboard
(*
this
);
192
}
193
194
195
//
196
/// Throw the exception.
197
//
198
void
199
TXClipboard::Throw
()
200
{
201
throw
*
this
;
202
}
203
204
//
205
/// Throw the exception.
206
//
207
void
208
TXClipboard::Raise
(
uint
resourceId)
209
{
210
TXClipboard
(resourceId).Throw();
211
}
212
213
}
// OWL namespace
214
/////////////////////////////////
PRECONDITION
#define PRECONDITION(condition)
Definition
checks.h:227
owl::TClipboardFormatIterator::TClipboardFormatIterator
TClipboardFormatIterator(const TClipboard &)
Construct an available format iterator for a clipboard.
Definition
clipboar.cpp:138
owl::TClipboardFormatIterator::Restart
void Restart()
Restart the format iterator.
Definition
clipboar.cpp:149
owl::TClipboardFormatIterator::operator++
uint operator++()
Get the next available format.
Definition
clipboar.cpp:158
owl::TClipboard
The clipboard class encapsulates the methods for the clipboard object of Windows.
Definition
clipboar.h:32
owl::TClipboard::DefaultProtocol
static LPCTSTR DefaultProtocol
Points to a string that specifies the name of the protocol the client needs.
Definition
clipboar.h:77
owl::TClipboard::OpenClipboard
bool OpenClipboard(HWND hWnd)
Opens the Clipboard and associates it with the window specified in Wnd.
Definition
clipboar.cpp:125
owl::TClipboard::TClipboard
TClipboard(HWND hWnd, bool mustOpen=true)
Constructs a clipboard object to grab the clipboard given a window handle.
Definition
clipboar.cpp:90
owl::TClipboard::~TClipboard
~TClipboard()
Destruct a clipboard object & close the clipboard if open.
Definition
clipboar.cpp:100
owl::TClipboard::CloseClipboard
void CloseClipboard()
If the Clipboard is opened (IsOpen is true), closes the Clipboard.
Definition
clipboar.cpp:111
owl::TXClipboard
TXClipboard creates the TXClipboard exception with a string resource.
Definition
clipboar.h:92
owl::TXClipboard::Clone
TXClipboard * Clone()
Definition
clipboar.cpp:189
owl::TXClipboard::Raise
static void Raise(uint resourceId=IDS_CLIPBOARDBUSY)
Throw the exception.
Definition
clipboar.cpp:208
owl::TXClipboard::TXClipboard
TXClipboard(uint resourceId=IDS_CLIPBOARDBUSY)
Create the TXClipboard exception with a string resource.
Definition
clipboar.cpp:179
owl::TXClipboard::Throw
void Throw()
Throw the exception.
Definition
clipboar.cpp:199
clipboar.h
Definition of classes for clipboard Encapsulation.
_T
#define _T(x)
Definition
cygwin.h:51
owl::TXOwl::TXOwl
TXOwl(const tstring &msg, uint resId=0)
An OWL exception with a given message for displaying and an unsigned Id that can be used for identifi...
Definition
except.cpp:123
pch.h
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::OWL_DIAGINFO
OWL_DIAGINFO
Definition
animctrl.cpp:14
owl::uint
unsigned int uint
Definition
number.h:25
source
owlcore
clipboar.cpp
Generated by
1.18.0