From f536e0f24b3bf8358a5e1cb960267d5a3abe5071 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 21 Oct 1999 13:56:34 +0000 Subject: [PATCH] wxClipboard::IsOpened() and wxCLipboardLocker helper class added git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4105 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/clipbrd.h | 33 +++++++++++++++++++++++++++++++++ include/wx/gtk/clipbrd.h | 3 +++ include/wx/gtk1/clipbrd.h | 3 +++ include/wx/msw/clipbrd.h | 3 +++ src/gtk/clipbrd.cpp | 5 +++++ src/gtk1/clipbrd.cpp | 5 +++++ src/msw/clipbrd.cpp | 9 +++++++++ 7 files changed, 61 insertions(+) diff --git a/include/wx/clipbrd.h b/include/wx/clipbrd.h index 47f0af66b5..0870a03d29 100644 --- a/include/wx/clipbrd.h +++ b/include/wx/clipbrd.h @@ -46,6 +46,9 @@ public: // close the clipboard after Add/SetData() and GetData() virtual void Close() = 0; + // query whether the clipboard is opened + virtual bool IsOpened() const = 0; + // add to the clipboard data // // NB: the clipboard owns the pointer and will delete it, so data must be @@ -102,6 +105,36 @@ public: // The global clipboard object 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 // _WX_CLIPBRD_H_BASE_ diff --git a/include/wx/gtk/clipbrd.h b/include/wx/gtk/clipbrd.h index b6d2583e84..0bc454dc22 100644 --- a/include/wx/gtk/clipbrd.h +++ b/include/wx/gtk/clipbrd.h @@ -39,6 +39,9 @@ public: // close the clipboard after SetData() and GetData() virtual void Close(); + // query whether the clipboard is opened + virtual bool IsOpened() const; + // set the clipboard data. all other formats will be deleted. virtual bool SetData( wxDataObject *data ); diff --git a/include/wx/gtk1/clipbrd.h b/include/wx/gtk1/clipbrd.h index b6d2583e84..0bc454dc22 100644 --- a/include/wx/gtk1/clipbrd.h +++ b/include/wx/gtk1/clipbrd.h @@ -39,6 +39,9 @@ public: // close the clipboard after SetData() and GetData() virtual void Close(); + // query whether the clipboard is opened + virtual bool IsOpened() const; + // set the clipboard data. all other formats will be deleted. virtual bool SetData( wxDataObject *data ); diff --git a/include/wx/msw/clipbrd.h b/include/wx/msw/clipbrd.h index 05c8cef304..67f9d9d4fb 100644 --- a/include/wx/msw/clipbrd.h +++ b/include/wx/msw/clipbrd.h @@ -66,6 +66,9 @@ public: // close the clipboard after SetData() and GetData() virtual void Close(); + // query whether the clipboard is opened + virtual bool IsOpened() const; + // set the clipboard data. all other formats will be deleted. virtual bool SetData( wxDataObject *data ); diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 1304b0ddf1..b9f2472822 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -544,6 +544,11 @@ void wxClipboard::Close() m_open = FALSE; } +bool wxClipboard::IsOpened() const +{ + return m_open; +} + bool wxClipboard::IsSupported( const wxDataFormat& format ) { /* store requested format to be asked for by callbacks */ diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index 1304b0ddf1..b9f2472822 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -544,6 +544,11 @@ void wxClipboard::Close() m_open = FALSE; } +bool wxClipboard::IsOpened() const +{ + return m_open; +} + bool wxClipboard::IsSupported( const wxDataFormat& format ) { /* store requested format to be asked for by callbacks */ diff --git a/src/msw/clipbrd.cpp b/src/msw/clipbrd.cpp index f8287de98a..d9ca91ec44 100644 --- a/src/msw/clipbrd.cpp +++ b/src/msw/clipbrd.cpp @@ -474,6 +474,15 @@ bool wxClipboard::Open() #endif } +bool wxClipboard::IsOpened() const +{ +#if wxUSE_OLE_CLIPBOARD + return TRUE; +#else + return wxIsClipboardOpened(); +#endif +} + bool wxClipboard::SetData( wxDataObject *data ) { (void)wxEmptyClipboard(); -- 2.45.2