wxClipboard::IsOpened() and wxCLipboardLocker helper class added

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4105 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-10-21 13:56:34 +00:00
parent 51d7e4e762
commit f536e0f24b
7 changed files with 61 additions and 0 deletions

View File

@@ -46,6 +46,9 @@ public:
// close the clipboard after Add/SetData() and GetData() // close the clipboard after Add/SetData() and GetData()
virtual void Close() = 0; virtual void Close() = 0;
// query whether the clipboard is opened
virtual bool IsOpened() const = 0;
// add to the clipboard data // add to the clipboard data
// //
// NB: the clipboard owns the pointer and will delete it, so data must be // NB: the clipboard owns the pointer and will delete it, so data must be
@@ -102,6 +105,36 @@ public:
// The global clipboard object // The global clipboard object
WXDLLEXPORT_DATA(extern wxClipboard *) wxTheClipboard; WXDLLEXPORT_DATA(extern wxClipboard *) wxTheClipboard;
// ----------------------------------------------------------------------------
// helpful class for opening the clipboard and automatically closing it
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxClipboardLocker
{
public:
wxClipboardLocker(wxClipboard *clipboard = (wxClipboard *)NULL)
{
m_clipboard = clipboard ? clipboard : wxTheClipboard;
if ( m_clipboard )
{
m_clipboard->Open();
}
}
bool IsOk() const { return m_clipboard->IsOpened(); }
~wxClipboardLocker()
{
if ( m_clipboard )
{
m_clipboard->Close();
}
}
private:
wxClipboard *m_clipboard;
};
#endif // wxUSE_CLIPBOARD #endif // wxUSE_CLIPBOARD
#endif // _WX_CLIPBRD_H_BASE_ #endif // _WX_CLIPBRD_H_BASE_

View File

@@ -39,6 +39,9 @@ public:
// close the clipboard after SetData() and GetData() // close the clipboard after SetData() and GetData()
virtual void Close(); virtual void Close();
// query whether the clipboard is opened
virtual bool IsOpened() const;
// set the clipboard data. all other formats will be deleted. // set the clipboard data. all other formats will be deleted.
virtual bool SetData( wxDataObject *data ); virtual bool SetData( wxDataObject *data );

View File

@@ -39,6 +39,9 @@ public:
// close the clipboard after SetData() and GetData() // close the clipboard after SetData() and GetData()
virtual void Close(); virtual void Close();
// query whether the clipboard is opened
virtual bool IsOpened() const;
// set the clipboard data. all other formats will be deleted. // set the clipboard data. all other formats will be deleted.
virtual bool SetData( wxDataObject *data ); virtual bool SetData( wxDataObject *data );

View File

@@ -66,6 +66,9 @@ public:
// close the clipboard after SetData() and GetData() // close the clipboard after SetData() and GetData()
virtual void Close(); virtual void Close();
// query whether the clipboard is opened
virtual bool IsOpened() const;
// set the clipboard data. all other formats will be deleted. // set the clipboard data. all other formats will be deleted.
virtual bool SetData( wxDataObject *data ); virtual bool SetData( wxDataObject *data );

View File

@@ -544,6 +544,11 @@ void wxClipboard::Close()
m_open = FALSE; m_open = FALSE;
} }
bool wxClipboard::IsOpened() const
{
return m_open;
}
bool wxClipboard::IsSupported( const wxDataFormat& format ) bool wxClipboard::IsSupported( const wxDataFormat& format )
{ {
/* store requested format to be asked for by callbacks */ /* store requested format to be asked for by callbacks */

View File

@@ -544,6 +544,11 @@ void wxClipboard::Close()
m_open = FALSE; m_open = FALSE;
} }
bool wxClipboard::IsOpened() const
{
return m_open;
}
bool wxClipboard::IsSupported( const wxDataFormat& format ) bool wxClipboard::IsSupported( const wxDataFormat& format )
{ {
/* store requested format to be asked for by callbacks */ /* store requested format to be asked for by callbacks */

View File

@@ -474,6 +474,15 @@ bool wxClipboard::Open()
#endif #endif
} }
bool wxClipboard::IsOpened() const
{
#if wxUSE_OLE_CLIPBOARD
return TRUE;
#else
return wxIsClipboardOpened();
#endif
}
bool wxClipboard::SetData( wxDataObject *data ) bool wxClipboard::SetData( wxDataObject *data )
{ {
(void)wxEmptyClipboard(); (void)wxEmptyClipboard();