Removed wxNullRegion

Finalized wxClpboard


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1999-01-28 18:25:36 +00:00
parent 6085b116d6
commit 75ce058154
9 changed files with 204 additions and 140 deletions

View File

@ -6,7 +6,7 @@ clipboard class from wxWindows 1.xx, which has the same name but a different imp
To use the clipboard, you call member functions of the global {\bf wxTheClipboard} object.
Call \helpref{wxClipboard::Open}{wxclipboardopen} to get ownership of the clipboard. If this operation returns TRUE, you
now own the clipboard. Call \helpref{wxClipboard::SetData}{wxclipboardsetdata} to put data
now own the clipboard. Call \helpref{wxClipboard::AddData}{wxclipboardadddata} to put data
on the clipboard (one or more times), or \helpref{wxClipboard::GetData}{wxclipboardgetdata} to
retrieve data from the clipboard. Call \helpref{wxClipboard::Close}{wxclipboardclose} to close
the clipboard and relinquish ownership. You should keep the clipboard open only momentarily.
@ -17,20 +17,22 @@ For example:
// Write some text to the clipboard
if (wxTheClipboard->Open())
{
// This object is held by the clipboard, so do not delete it in the app.
wxTextDataObject* object = new wxTextDataObject("Some text");
wxTheClipboard->SetData(& object);
// This data objects are held by the clipboard,
// so do not delete them in the app.
wxTheClipboard->AddData( new wxTextDataObject("Some text") );
wxTheClipboard->Close();
}
// Read some text
if (wxTheClipboard->Open() && wxTheClipboard->IsSupportedFormat(wxDF_TEXT))
if (wxTheClipboard->Open())
{
wxTextDataObject object;
wxTheClipboard->GetData(& object);
wxTextDataObject data;
if (wxTheClipboard->IsSupported(data))
{
wxTheClipboard->GetData(data);
wxMessageBox(data.GetText());
}
wxTheClipboard->Close();
wxMessageBox(object.GetText());
}
\end{verbatim}
@ -56,6 +58,13 @@ Constructor.
Destructor.
\membersection{wxClipboard::AddData}\label{wxclipboardadddata}
\func{bool}{AddData}{\param{wxDataObject*}{ data}}
Call this function to add a data object to the clipboard. This function can be called several times
to put different formats on the clipboard.
\membersection{wxClipboard::Clear}\label{wxclipboardclear}
\func{void}{Clear}{\void}
@ -66,26 +75,20 @@ Clears the global clipboard object and the system's clipboard if possible.
\func{bool}{Close}{\void}
Call this function to close the clipboard, having opened it with \helpref{wxClipboard::Close}{wxclipboardclose}.
Call this function to close the clipboard, having opened it with \helpref{wxClipboard::Open}{wxclipboardopen}.
\membersection{wxClipboard::GetData}\label{wxclipboardgetdata}
\func{bool}{GetData}{\param{wxDataObject*}{ data}}
\func{bool}{GetData}{\param{wxDataObject&}{ data}}
Call this function to fill {\it data} with data on the clipboard, if available in the required
format.
format. Returns TRUE on success.
\membersection{wxClipboard::IsSupportedFormat}\label{wxclipboardissupportedformat}
\membersection{wxClipboard::IsSupported}\label{wxclipboardissupported}
\func{bool}{IsSupportedFormat}{\param{wxDataFormat}{ format}, \param{const wxString\&}{ id = ""}}
\func{bool}{IsSupported}{\param{wxDataObject&}{ data}}
Returns TRUE if the given format is available on the clipboard.
\wxheading{Parameters}
\docparam{format}{The format. See \helpref{wxDataObject}{wxdataobject} for a list of formats.}
\docparam{id}{ If {\it format} is wxDF\_PRIVATE, {\it id} is the identifier of the private data format.}
Returns TRUE if the format of the given data object is available on the clipboard.
\membersection{wxClipboard::Open}\label{wxclipboardopen}
@ -97,10 +100,13 @@ and \helpref{wxClipboard::GetData}{wxclipboardgetdata}.
Call \helpref{wxClipboard::Close}{wxclipboardclose} when you have finished with the clipboard. You
should keep the clipboard open for only a very short time.
\membersection{wxClipboard::SetData}\label{wxclipboardsetdata}
Returns TRUE on success. This should be tested (as in the sample shown above).
\membersection{wxClipboard::SetData}\label{wxclipboardadddata}
\func{bool}{SetData}{\param{wxDataObject*}{ data}}
Call this function to set a data object to the clipboard. This function can be called several times
to put different formats on the clipboard.
Call this function to set the data object to the clipboard. This function will
clear all previous contents in the clipboard, so calling it several times
does not make any sense.

View File

@ -305,9 +305,6 @@ WXDLLEXPORT_DATA(extern wxBrush) wxNullBrush;
WXDLLEXPORT_DATA(extern wxPalette) wxNullPalette;
WXDLLEXPORT_DATA(extern wxFont) wxNullFont;
WXDLLEXPORT_DATA(extern wxColour) wxNullColour;
#ifdef __WXGTK__
WXDLLEXPORT_DATA(extern wxRegion) wxNullRegion;
#endif
// Stock cursors types
WXDLLEXPORT_DATA(extern wxCursor*) wxSTANDARD_CURSOR;

View File

@ -57,11 +57,17 @@ public:
/* close the clipboard after SetData() and GetData() */
virtual void Close();
/* set the clipboard data. the clipboard will delete the broker later */
virtual bool SetData( wxDataBroker *data );
/* set the clipboard data. all other formats will be deleted. */
virtual bool SetData( wxDataObject *data );
/* add to the clipboard data. */
virtual bool AddData( wxDataObject *data );
/* ask if data in correct format is available */
virtual bool IsSupported( wxDataObject &data );
/* fill data with data on the clipboard (if available) */
virtual bool GetData( wxDataObject *data );
virtual bool GetData( wxDataObject &data );
/* clears wxTheClipboard and the system's clipboard if possible */
virtual void Clear();

View File

@ -57,11 +57,17 @@ public:
/* close the clipboard after SetData() and GetData() */
virtual void Close();
/* set the clipboard data. the clipboard will delete the broker later */
virtual bool SetData( wxDataBroker *data );
/* set the clipboard data. all other formats will be deleted. */
virtual bool SetData( wxDataObject *data );
/* add to the clipboard data. */
virtual bool AddData( wxDataObject *data );
/* ask if data in correct format is available */
virtual bool IsSupported( wxDataObject &data );
/* fill data with data on the clipboard (if available) */
virtual bool GetData( wxDataObject *data );
virtual bool GetData( wxDataObject &data );
/* clears wxTheClipboard and the system's clipboard if possible */
virtual void Clear();

View File

@ -482,7 +482,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
// panel->SetForegroundColour("blue");
m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_SPECIFY_ROWS );
// m_radio->SetBackgroundColour("wheat");
m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_SPECIFY_COLS );
m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 2, wxRA_SPECIFY_COLS );
// m_radio->SetBackgroundColour("wheat");
(void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
(void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
@ -547,24 +547,31 @@ void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) )
*m_text << "Successfully opened the clipboard." << "\n";
}
wxTextDataObject *data = new wxTextDataObject();
wxTextDataObject data;
if (wxTheClipboard->GetData( data ))
if (wxTheClipboard->IsSupported( data ))
{
*m_text << "Successfully retrieved data from the clipboard." << "\n";
*m_multitext << data->GetText() << "\n";
*m_text << "Clipboard supports requested format." << "\n";
if (wxTheClipboard->GetData( data ))
{
*m_text << "Successfully retrieved data from the clipboard." << "\n";
*m_multitext << data.GetText() << "\n";
}
else
{
*m_text << "Error getting data from the clipboard." << "\n";
}
}
else
{
*m_text << "Error getting data from the clipboard." << "\n";
*m_text << "Clipboard doesn't support requested format." << "\n";
}
wxTheClipboard->Close();
*m_text << "Closed the clipboard." << "\n";
delete data;
#endif
}
@ -588,10 +595,8 @@ void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) )
}
wxTextDataObject *data = new wxTextDataObject( text );
wxDataBroker *broker = new wxDataBroker();
broker->Add( data );
if (!wxTheClipboard->SetData( broker ))
if (!wxTheClipboard->SetData( data ))
{
*m_text << "Error while copying to the clipboard." << "\n";
}

View File

@ -344,68 +344,74 @@ bool wxClipboard::Open()
return TRUE;
}
bool wxClipboard::SetData( wxDataBroker *data )
bool wxClipboard::SetData( wxDataObject *data )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
wxCHECK_MSG( data, FALSE, "data is invalid" );
Clear();
m_dataBroker = data;
if (!m_dataBroker) return FALSE;
return AddData( data );
}
bool wxClipboard::AddData( wxDataObject *data )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
wxNode *node = m_dataBroker->m_dataObjects.First();
while (node)
{
wxDataObject *dobj = (wxDataObject*)node->Data();
GdkAtom format = dobj->GetFormat().GetAtom();
if (format != (GdkAtom) 0)
{
/* This should happen automatically */
m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE;
wxCHECK_MSG( data, FALSE, "data is invalid" );
/* Add handlers if someone requests data */
/* if clipboard has been cleared before, create new data broker */
gtk_selection_add_handler( m_clipboardWidget,
if (!m_dataBroker) m_dataBroker = new wxDataBroker();
/* add new data to list of offered data objects */
m_dataBroker->Add( data );
/* get native format id of new data object */
GdkAtom format = data->GetFormat().GetAtom();
wxCHECK_MSG( format, FALSE, "data has invalid format" );
/* This should happen automatically, but to be on the safe side */
m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE;
/* Add handlers if someone requests data */
gtk_selection_add_handler( m_clipboardWidget,
g_clipboardAtom,
format,
selection_handler,
(gpointer) NULL );
gtk_selection_add_handler( m_clipboardWidget,
gtk_selection_add_handler( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
format,
selection_handler,
(gpointer) NULL );
/* Tell the world we offer clipboard data */
/* Tell the world we offer clipboard data */
if (!gtk_selection_owner_set( m_clipboardWidget,
if (!gtk_selection_owner_set( m_clipboardWidget,
g_clipboardAtom,
GDK_CURRENT_TIME ))
{
return FALSE;
}
m_ownsClipboard = TRUE;
{
return FALSE;
}
m_ownsClipboard = TRUE;
if (!gtk_selection_owner_set( m_clipboardWidget,
if (!gtk_selection_owner_set( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
GDK_CURRENT_TIME ))
{
return FALSE;
}
m_ownsPrimarySelection = TRUE;
}
node = node->Next();
{
return FALSE;
}
m_ownsPrimarySelection = TRUE;
return TRUE;
}
@ -416,22 +422,16 @@ void wxClipboard::Close()
m_open = FALSE;
}
bool wxClipboard::GetData( wxDataObject *data )
bool wxClipboard::IsSupported( wxDataObject &data )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
m_receivedData = data;
/* store requested format to be asked for by callbacks */
wxCHECK_MSG( m_receivedData, FALSE, "invalid data object" );
/* STEP ONE: check if there is such data in the clipboard */
m_targetRequested = data->GetFormat().GetAtom();
m_targetRequested = data.GetFormat().GetAtom();
wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" );
if (m_targetRequested == 0) return FALSE;
/* add handler for target (= format) query */
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
@ -454,8 +454,29 @@ bool wxClipboard::GetData( wxDataObject *data )
(gpointer) this );
if (!m_formatSupported) return FALSE;
return TRUE;
}
bool wxClipboard::GetData( wxDataObject &data )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
/* is data supported by clipboard ? */
if (!IsSupported( data )) return FALSE;
/* store pointer to data object to be filled up by callbacks */
m_receivedData = &data;
/* store requested format to be asked for by callbacks */
m_targetRequested = data.GetFormat().GetAtom();
/* STEP TWO: get the data from the clipboard */
wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" );
/* start query */
m_formatSupported = FALSE;
@ -464,6 +485,8 @@ bool wxClipboard::GetData( wxDataObject *data )
GTK_SIGNAL_FUNC( selection_received ),
(gpointer) this );
/* ask for clipboard contents */
gtk_selection_convert( m_clipboardWidget,
g_clipboardAtom,
m_targetRequested,

View File

@ -124,7 +124,6 @@ wxBrush wxNullBrush;
wxFont wxNullFont;
wxColour wxNullColour;
wxPalette wxNullPalette;
wxRegion wxNullRegion;
/* Default window names */
const char *wxButtonNameStr = "button";

View File

@ -344,68 +344,74 @@ bool wxClipboard::Open()
return TRUE;
}
bool wxClipboard::SetData( wxDataBroker *data )
bool wxClipboard::SetData( wxDataObject *data )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
wxCHECK_MSG( data, FALSE, "data is invalid" );
Clear();
m_dataBroker = data;
if (!m_dataBroker) return FALSE;
return AddData( data );
}
bool wxClipboard::AddData( wxDataObject *data )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
wxNode *node = m_dataBroker->m_dataObjects.First();
while (node)
{
wxDataObject *dobj = (wxDataObject*)node->Data();
GdkAtom format = dobj->GetFormat().GetAtom();
if (format != (GdkAtom) 0)
{
/* This should happen automatically */
m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE;
wxCHECK_MSG( data, FALSE, "data is invalid" );
/* Add handlers if someone requests data */
/* if clipboard has been cleared before, create new data broker */
gtk_selection_add_handler( m_clipboardWidget,
if (!m_dataBroker) m_dataBroker = new wxDataBroker();
/* add new data to list of offered data objects */
m_dataBroker->Add( data );
/* get native format id of new data object */
GdkAtom format = data->GetFormat().GetAtom();
wxCHECK_MSG( format, FALSE, "data has invalid format" );
/* This should happen automatically, but to be on the safe side */
m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE;
/* Add handlers if someone requests data */
gtk_selection_add_handler( m_clipboardWidget,
g_clipboardAtom,
format,
selection_handler,
(gpointer) NULL );
gtk_selection_add_handler( m_clipboardWidget,
gtk_selection_add_handler( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
format,
selection_handler,
(gpointer) NULL );
/* Tell the world we offer clipboard data */
/* Tell the world we offer clipboard data */
if (!gtk_selection_owner_set( m_clipboardWidget,
if (!gtk_selection_owner_set( m_clipboardWidget,
g_clipboardAtom,
GDK_CURRENT_TIME ))
{
return FALSE;
}
m_ownsClipboard = TRUE;
{
return FALSE;
}
m_ownsClipboard = TRUE;
if (!gtk_selection_owner_set( m_clipboardWidget,
if (!gtk_selection_owner_set( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
GDK_CURRENT_TIME ))
{
return FALSE;
}
m_ownsPrimarySelection = TRUE;
}
node = node->Next();
{
return FALSE;
}
m_ownsPrimarySelection = TRUE;
return TRUE;
}
@ -416,22 +422,16 @@ void wxClipboard::Close()
m_open = FALSE;
}
bool wxClipboard::GetData( wxDataObject *data )
bool wxClipboard::IsSupported( wxDataObject &data )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
m_receivedData = data;
/* store requested format to be asked for by callbacks */
wxCHECK_MSG( m_receivedData, FALSE, "invalid data object" );
/* STEP ONE: check if there is such data in the clipboard */
m_targetRequested = data->GetFormat().GetAtom();
m_targetRequested = data.GetFormat().GetAtom();
wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" );
if (m_targetRequested == 0) return FALSE;
/* add handler for target (= format) query */
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
@ -454,8 +454,29 @@ bool wxClipboard::GetData( wxDataObject *data )
(gpointer) this );
if (!m_formatSupported) return FALSE;
return TRUE;
}
bool wxClipboard::GetData( wxDataObject &data )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
/* is data supported by clipboard ? */
if (!IsSupported( data )) return FALSE;
/* store pointer to data object to be filled up by callbacks */
m_receivedData = &data;
/* store requested format to be asked for by callbacks */
m_targetRequested = data.GetFormat().GetAtom();
/* STEP TWO: get the data from the clipboard */
wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" );
/* start query */
m_formatSupported = FALSE;
@ -464,6 +485,8 @@ bool wxClipboard::GetData( wxDataObject *data )
GTK_SIGNAL_FUNC( selection_received ),
(gpointer) this );
/* ask for clipboard contents */
gtk_selection_convert( m_clipboardWidget,
g_clipboardAtom,
m_targetRequested,

View File

@ -124,7 +124,6 @@ wxBrush wxNullBrush;
wxFont wxNullFont;
wxColour wxNullColour;
wxPalette wxNullPalette;
wxRegion wxNullRegion;
/* Default window names */
const char *wxButtonNameStr = "button";