1. Moved m_usePrimary to wxClipboardBase as it's now also used by wxMSW/wxMac
2. Added IsUsingPrimarySelection() 3. Fail all clipboard operations when IsUsingPrimarySelection() is true on non-X11 platforms git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45183 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -52,18 +52,21 @@ For example:
|
||||
|
||||
\latexignore{\rtfignore{\wxheading{Members}}}
|
||||
|
||||
|
||||
\membersection{wxClipboard::wxClipboard}\label{wxclipboardctor}
|
||||
|
||||
\func{}{wxClipboard}{\void}
|
||||
|
||||
Constructor.
|
||||
|
||||
|
||||
\membersection{wxClipboard::\destruct{wxClipboard}}\label{wxclipboarddtor}
|
||||
|
||||
\func{}{\destruct{wxClipboard}}{\void}
|
||||
|
||||
Destructor.
|
||||
|
||||
|
||||
\membersection{wxClipboard::AddData}\label{wxclipboardadddata}
|
||||
|
||||
\func{bool}{AddData}{\param{wxDataObject*}{ data}}
|
||||
@@ -78,18 +81,21 @@ the data explicitly.
|
||||
|
||||
\helpref{wxClipboard::SetData}{wxclipboardsetdata}
|
||||
|
||||
|
||||
\membersection{wxClipboard::Clear}\label{wxclipboardclear}
|
||||
|
||||
\func{void}{Clear}{\void}
|
||||
|
||||
Clears the global clipboard object and the system's clipboard if possible.
|
||||
|
||||
|
||||
\membersection{wxClipboard::Close}\label{wxclipboardclose}
|
||||
|
||||
\func{void}{Close}{\void}
|
||||
|
||||
Call this function to close the clipboard, having opened it with \helpref{wxClipboard::Open}{wxclipboardopen}.
|
||||
|
||||
|
||||
\membersection{wxClipboard::Flush}\label{wxclipboardflush}
|
||||
|
||||
\func{bool}{Flush}{\void}
|
||||
@@ -99,6 +105,7 @@ clipboard will stay available even after the application exits (possibly
|
||||
eating memory), otherwise the clipboard will be emptied on exit.
|
||||
Returns false if the operation is unsuccessful for any reason.
|
||||
|
||||
|
||||
\membersection{wxClipboard::GetData}\label{wxclipboardgetdata}
|
||||
|
||||
\func{bool}{GetData}{\param{wxDataObject\&}{ data}}
|
||||
@@ -106,18 +113,29 @@ Returns false if the operation is unsuccessful for any reason.
|
||||
Call this function to fill {\it data} with data on the clipboard, if available in the required
|
||||
format. Returns true on success.
|
||||
|
||||
|
||||
\membersection{wxClipboard::IsOpened}\label{wxclipboardisopened}
|
||||
|
||||
\constfunc{bool}{IsOpened}{\void}
|
||||
|
||||
Returns true if the clipboard has been opened.
|
||||
|
||||
|
||||
\membersection{wxClipboard::IsSupported}\label{wxclipboardissupported}
|
||||
|
||||
\func{bool}{IsSupported}{\param{const wxDataFormat\&}{ format}}
|
||||
|
||||
Returns true if there is data which matches the data format of the given data object currently {\bf available} (IsSupported sounds like a misnomer, FIXME: better deprecate this name?) on the clipboard.
|
||||
|
||||
|
||||
\membersection{wxClipboard::IsUsingPrimarySelection}\label{wxclipboardisusingprimaryselection}
|
||||
|
||||
\constfunc{bool}{IsUsingPrimarySelection}{\void}
|
||||
|
||||
Returns \true if we are using the primary selection, \false if clipboard one.
|
||||
See \helpref{UsePrimarySelection}{wxclipboarduseprimary} for more information.
|
||||
|
||||
|
||||
\membersection{wxClipboard::Open}\label{wxclipboardopen}
|
||||
|
||||
\func{bool}{Open}{\void}
|
||||
@@ -130,6 +148,7 @@ should keep the clipboard open for only a very short time.
|
||||
|
||||
Returns true on success. This should be tested (as in the sample shown above).
|
||||
|
||||
|
||||
\membersection{wxClipboard::SetData}\label{wxclipboardsetdata}
|
||||
|
||||
\func{bool}{SetData}{\param{wxDataObject*}{ data}}
|
||||
@@ -145,12 +164,21 @@ the data explicitly.
|
||||
|
||||
\helpref{wxClipboard::AddData}{wxclipboardadddata}
|
||||
|
||||
|
||||
\membersection{wxClipboard::UsePrimarySelection}\label{wxclipboarduseprimary}
|
||||
|
||||
\func{void}{UsePrimarySelection}{\param{bool}{ primary = true}}
|
||||
|
||||
On platforms supporting it (currently only GTK), selects the so called
|
||||
PRIMARY SELECTION as the clipboard as opposed to the normal clipboard,
|
||||
if {\it primary} is true.
|
||||
On platforms supporting it (all X11-based ports), wxClipboard uses the
|
||||
CLIPBOARD X11 selection by default. When this function is called with \true
|
||||
argument, all subsequent clipboard operations will use PRIMARY selection until
|
||||
this function is called again with \false.
|
||||
|
||||
On the other platforms, there is no PRIMARY selection and so all clipboard
|
||||
operations will fail. This allows to implement the standard X11 handling of the
|
||||
clipboard which consists in copying data to the CLIPBOARD selection only when
|
||||
the user explicitly requests it (i.e. by selection \texttt{"Copy"} menu
|
||||
command) but putting the currently selected text into the PRIMARY selection
|
||||
automatically, without overwriting the normal clipboard contents with the
|
||||
currently selected text on the other platforms.
|
||||
|
||||
|
@@ -35,7 +35,7 @@ class WXDLLEXPORT wxClipboard;
|
||||
class WXDLLEXPORT wxClipboardBase : public wxObject
|
||||
{
|
||||
public:
|
||||
wxClipboardBase() {}
|
||||
wxClipboardBase() { m_usePrimary = false; }
|
||||
|
||||
// open the clipboard before Add/SetData() and GetData()
|
||||
virtual bool Open() = 0;
|
||||
@@ -70,11 +70,28 @@ public:
|
||||
// eating memory), otherwise the clipboard will be emptied on exit
|
||||
virtual bool Flush() { return false; }
|
||||
|
||||
// X11 has two clipboards which get selected by this call. Empty on MSW.
|
||||
virtual void UsePrimarySelection( bool WXUNUSED(primary) = false ) { }
|
||||
// this allows to choose whether we work with CLIPBOARD (default) or
|
||||
// PRIMARY selection on X11-based systems
|
||||
//
|
||||
// on the other ones, working with primary selection does nothing: this
|
||||
// allows to write code which sets the primary selection when something is
|
||||
// selected without any ill effects (i.e. without overwriting the
|
||||
// clipboard which would be wrong on the platforms without X11 PRIMARY)
|
||||
virtual void UsePrimarySelection(bool usePrimary = false)
|
||||
{
|
||||
m_usePrimary = usePrimary;
|
||||
}
|
||||
|
||||
// return true if we're using primary selection
|
||||
bool IsUsingPrimarySelection() const { return m_usePrimary; }
|
||||
|
||||
// Returns global instance (wxTheClipboard) of the object:
|
||||
static wxClipboard *Get();
|
||||
|
||||
|
||||
// don't use this directly, it is public for compatibility with some ports
|
||||
// (wxX11, wxMotif, ...) only
|
||||
bool m_usePrimary;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -52,11 +52,7 @@ public:
|
||||
// clears wxTheClipboard and the system's clipboard if possible
|
||||
virtual void Clear();
|
||||
|
||||
// If primary == TRUE, use primary selection in all further ops,
|
||||
// primary == FALSE resets it.
|
||||
virtual void UsePrimarySelection(bool primary = TRUE)
|
||||
{ m_usePrimary = primary; }
|
||||
|
||||
|
||||
|
||||
// implementation from now on
|
||||
// --------------------------
|
||||
@@ -111,7 +107,6 @@ private:
|
||||
GtkWidget *m_targetsWidget; // for getting list of supported formats
|
||||
|
||||
bool m_open;
|
||||
bool m_usePrimary;
|
||||
bool m_formatSupported;
|
||||
|
||||
|
||||
|
@@ -53,11 +53,6 @@ public:
|
||||
// clears wxTheClipboard and the system's clipboard if possible
|
||||
virtual void Clear();
|
||||
|
||||
// If primary == TRUE, use primary selection in all further ops,
|
||||
// primary == FALSE resets it.
|
||||
virtual void UsePrimarySelection(bool primary = TRUE)
|
||||
{ m_usePrimary = primary; }
|
||||
|
||||
// implementation from now on
|
||||
bool m_open;
|
||||
bool m_ownsClipboard;
|
||||
@@ -70,7 +65,6 @@ public:
|
||||
|
||||
bool m_formatSupported;
|
||||
GdkAtom m_targetRequested;
|
||||
bool m_usePrimary;
|
||||
wxDataObject *m_receivedData;
|
||||
|
||||
private:
|
||||
|
@@ -63,9 +63,6 @@ public:
|
||||
// eating memory), otherwise the clipboard will be emptied on exit
|
||||
virtual bool Flush();
|
||||
|
||||
// X11 has two clipboards which get selected by this call. Empty on MSW.
|
||||
void UsePrimarySelection( bool WXUNUSED(primary) = FALSE ) { }
|
||||
|
||||
private:
|
||||
wxDataObject *m_data;
|
||||
bool m_open;
|
||||
@@ -73,5 +70,4 @@ private:
|
||||
|
||||
#endif // wxUSE_CLIPBOARD
|
||||
|
||||
#endif
|
||||
// _WX_CLIPBRD_H_
|
||||
#endif // _WX_CLIPBRD_H_
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: clipboard.h
|
||||
// Name: wx/mgl/clipboard.h
|
||||
// Purpose:
|
||||
// Author: Vaclav Slavik
|
||||
// Id: $Id$
|
||||
@@ -52,11 +52,6 @@ public:
|
||||
// clears wxTheClipboard and the system's clipboard if possible
|
||||
virtual void Clear() {}
|
||||
|
||||
// If primary == TRUE, use primary selection in all further ops,
|
||||
// primary == FALSE resets it.
|
||||
virtual void UsePrimarySelection(bool primary = TRUE)
|
||||
{ m_usePrimary = primary; }
|
||||
|
||||
// implementation from now on
|
||||
bool m_open;
|
||||
bool m_ownsClipboard;
|
||||
@@ -69,7 +64,6 @@ public:
|
||||
|
||||
bool m_formatSupported;
|
||||
GdkAtom m_targetRequested;
|
||||
bool m_usePrimary;
|
||||
wxDataObject *m_receivedData;
|
||||
|
||||
private:
|
||||
|
@@ -67,13 +67,9 @@ public:
|
||||
// clears wxTheClipboard and the system's clipboard if possible
|
||||
virtual void Clear();
|
||||
|
||||
virtual void UsePrimarySelection(bool primary = true)
|
||||
{ m_usePrimary = primary; }
|
||||
|
||||
// implementation from now on
|
||||
bool m_open;
|
||||
wxDataObjectList m_data;
|
||||
bool m_usePrimary;
|
||||
wxDataIdToDataObjectList m_idToObject;
|
||||
|
||||
private:
|
||||
@@ -82,5 +78,4 @@ private:
|
||||
|
||||
#endif // wxUSE_CLIPBOARD
|
||||
|
||||
#endif
|
||||
// _WX_CLIPBRD_H_
|
||||
#endif // _WX_CLIPBRD_H_
|
||||
|
@@ -85,14 +85,11 @@ public:
|
||||
// eating memory), otherwise the clipboard will be emptied on exit
|
||||
virtual bool Flush();
|
||||
|
||||
// X11 has two clipboards which get selected by this call. Empty on MSW.
|
||||
void UsePrimarySelection( bool WXUNUSED(primary) = false ) { }
|
||||
|
||||
private:
|
||||
IDataObject *m_lastDataObject;
|
||||
bool m_isOpened;
|
||||
};
|
||||
|
||||
#endif // wxUSE_CLIPBOARD
|
||||
#endif
|
||||
// _WX_CLIPBRD_H_
|
||||
|
||||
#endif // _WX_CLIPBRD_H_
|
||||
|
@@ -88,13 +88,9 @@ public:
|
||||
// eating memory), otherwise the clipboard will be emptied on exit
|
||||
virtual bool Flush();
|
||||
|
||||
// X11 has two clipboards which get selected by this call. Empty on MSW.
|
||||
void UsePrimarySelection( bool WXUNUSED(primary) = FALSE ) { }
|
||||
|
||||
private:
|
||||
bool m_clearOnExit;
|
||||
};
|
||||
|
||||
#endif // wxUSE_CLIPBOARD
|
||||
#endif
|
||||
// _WX_CLIPBRD_H_
|
||||
#endif // _WX_CLIPBRD_H_
|
||||
|
@@ -85,9 +85,6 @@ public:
|
||||
// eating memory), otherwise the clipboard will be emptied on exit
|
||||
virtual bool Flush();
|
||||
|
||||
// X11 has two clipboards which get selected by this call. Empty on MSW.
|
||||
void UsePrimarySelection( bool WXUNUSED(primary) = FALSE ) { }
|
||||
|
||||
private:
|
||||
bool m_clearOnExit;
|
||||
bool m_isOpened;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: clipbrd.h
|
||||
// Name: wx/x11/clipbrd.h
|
||||
// Purpose: Clipboard functionality.
|
||||
// Author: Robert Roebling
|
||||
// Created: 17/09/98
|
||||
@@ -8,8 +8,8 @@
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __X11CLIPBOARDH__
|
||||
#define __X11CLIPBOARDH__
|
||||
#ifndef _WX_X11_CLIPBRD_H_
|
||||
#define _WX_X11_CLIPBRD_H_
|
||||
|
||||
#if wxUSE_CLIPBOARD
|
||||
|
||||
@@ -53,11 +53,6 @@ public:
|
||||
// clears wxTheClipboard and the system's clipboard if possible
|
||||
virtual void Clear();
|
||||
|
||||
// If primary == TRUE, use primary selection in all further ops,
|
||||
// primary == FALSE resets it.
|
||||
virtual void UsePrimarySelection(bool primary = TRUE)
|
||||
{ m_usePrimary = primary; }
|
||||
|
||||
// implementation from now on
|
||||
bool m_open;
|
||||
bool m_ownsClipboard;
|
||||
@@ -70,15 +65,12 @@ public:
|
||||
|
||||
bool m_formatSupported;
|
||||
Atom m_targetRequested;
|
||||
bool m_usePrimary;
|
||||
wxDataObject *m_receivedData;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxClipboard)
|
||||
};
|
||||
|
||||
#endif
|
||||
// wxUSE_CLIPBOARD
|
||||
#endif // wxUSE_CLIPBOARD
|
||||
|
||||
#endif
|
||||
// __X11CLIPBOARDH__
|
||||
#endif // _WX_X11_CLIPBRD_H_
|
||||
|
@@ -347,8 +347,6 @@ wxClipboard::wxClipboard()
|
||||
m_formatSupported = false;
|
||||
m_targetRequested = 0;
|
||||
|
||||
m_usePrimary = false;
|
||||
|
||||
// we use m_targetsWidget to query what formats are available
|
||||
m_targetsWidget = gtk_window_new( GTK_WINDOW_POPUP );
|
||||
gtk_widget_realize( m_targetsWidget );
|
||||
|
@@ -347,8 +347,6 @@ wxClipboard::wxClipboard()
|
||||
|
||||
m_formatSupported = false;
|
||||
m_targetRequested = 0;
|
||||
|
||||
m_usePrimary = false;
|
||||
}
|
||||
|
||||
wxClipboard::~wxClipboard()
|
||||
|
@@ -173,6 +173,9 @@ wxClipboard::~wxClipboard()
|
||||
|
||||
void wxClipboard::Clear()
|
||||
{
|
||||
if ( IsUsingPrimarySelection() )
|
||||
return;
|
||||
|
||||
if (m_data != NULL)
|
||||
{
|
||||
delete m_data;
|
||||
@@ -214,6 +217,9 @@ bool wxClipboard::IsOpened() const
|
||||
|
||||
bool wxClipboard::SetData( wxDataObject *data )
|
||||
{
|
||||
if ( IsUsingPrimarySelection() )
|
||||
return false;
|
||||
|
||||
wxCHECK_MSG( m_open, false, wxT("clipboard not open") );
|
||||
wxCHECK_MSG( data, false, wxT("data is invalid") );
|
||||
|
||||
@@ -226,6 +232,9 @@ bool wxClipboard::SetData( wxDataObject *data )
|
||||
|
||||
bool wxClipboard::AddData( wxDataObject *data )
|
||||
{
|
||||
if ( IsUsingPrimarySelection() )
|
||||
return false;
|
||||
|
||||
wxCHECK_MSG( m_open, false, wxT("clipboard not open") );
|
||||
wxCHECK_MSG( data, false, wxT("data is invalid") );
|
||||
|
||||
@@ -320,6 +329,9 @@ void wxClipboard::Close()
|
||||
|
||||
bool wxClipboard::IsSupported( const wxDataFormat &dataFormat )
|
||||
{
|
||||
if ( IsUsingPrimarySelection() )
|
||||
return false;
|
||||
|
||||
if ( m_data )
|
||||
return m_data->IsSupported( dataFormat );
|
||||
|
||||
@@ -370,6 +382,9 @@ bool wxClipboard::IsSupported( const wxDataFormat &dataFormat )
|
||||
|
||||
bool wxClipboard::GetData( wxDataObject& data )
|
||||
{
|
||||
if ( IsUsingPrimarySelection() )
|
||||
return false;
|
||||
|
||||
wxCHECK_MSG( m_open, false, wxT("clipboard not open") );
|
||||
|
||||
size_t formatcount = data.GetFormatCount() + 1;
|
||||
|
@@ -547,6 +547,9 @@ wxClipboard::~wxClipboard()
|
||||
|
||||
void wxClipboard::Clear()
|
||||
{
|
||||
if ( IsUsingPrimarySelection() )
|
||||
return;
|
||||
|
||||
#if wxUSE_OLE_CLIPBOARD
|
||||
if (m_lastDataObject)
|
||||
{
|
||||
@@ -613,6 +616,9 @@ bool wxClipboard::IsOpened() const
|
||||
|
||||
bool wxClipboard::SetData( wxDataObject *data )
|
||||
{
|
||||
if ( IsUsingPrimarySelection() )
|
||||
return false;
|
||||
|
||||
#if !wxUSE_OLE_CLIPBOARD
|
||||
(void)wxEmptyClipboard();
|
||||
#endif // wxUSE_OLE_CLIPBOARD
|
||||
@@ -625,6 +631,9 @@ bool wxClipboard::SetData( wxDataObject *data )
|
||||
|
||||
bool wxClipboard::AddData( wxDataObject *data )
|
||||
{
|
||||
if ( IsUsingPrimarySelection() )
|
||||
return false;
|
||||
|
||||
wxCHECK_MSG( data, false, wxT("data is invalid") );
|
||||
|
||||
#if wxUSE_OLE_CLIPBOARD
|
||||
@@ -718,11 +727,14 @@ void wxClipboard::Close()
|
||||
|
||||
bool wxClipboard::IsSupported( const wxDataFormat& format )
|
||||
{
|
||||
return wxIsClipboardFormatAvailable(format);
|
||||
return !IsUsingPrimarySelection() && wxIsClipboardFormatAvailable(format);
|
||||
}
|
||||
|
||||
bool wxClipboard::GetData( wxDataObject& data )
|
||||
{
|
||||
if ( IsUsingPrimarySelection() )
|
||||
return false;
|
||||
|
||||
#if wxUSE_OLE_CLIPBOARD
|
||||
IDataObject *pDataObject = NULL;
|
||||
HRESULT hr = OleGetClipboard(&pDataObject);
|
||||
|
@@ -306,8 +306,6 @@ wxClipboard::wxClipboard()
|
||||
|
||||
m_formatSupported = false;
|
||||
m_targetRequested = 0;
|
||||
|
||||
m_usePrimary = false;
|
||||
}
|
||||
|
||||
wxClipboard::~wxClipboard()
|
||||
|
Reference in New Issue
Block a user