X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0d2a2b601b1994333886dff8f53d82a714c4042f..debdd17e991830c4ced82f5e4672fe2b32a684c2:/src/gtk/clipbrd.cpp diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 11096c3a4c..b5b3c3cec7 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -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(); + + return AddData( data ); +} + +bool wxClipboard::AddData( wxDataObject *data ) +{ + wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); - m_dataBroker = data; + wxCHECK_MSG( data, FALSE, "data is invalid" ); - if (!m_dataBroker) return FALSE; + /* if clipboard has been cleared before, create new data broker */ - wxCHECK_MSG( m_open, FALSE, "clipboard not open" ); + if (!m_dataBroker) m_dataBroker = new wxDataBroker(); - wxNode *node = m_dataBroker->m_dataObjects.First(); - while (node) - { - wxDataObject *dobj = (wxDataObject*)node->Data(); - - GdkAtom format = dobj->GetFormat().GetAtom(); + /* 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(); - if (format != (GdkAtom) 0) - { - /* This should happen automatically */ + 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; + m_ownsClipboard = FALSE; + m_ownsPrimarySelection = FALSE; - /* Add handlers if someone requests data */ + /* Add handlers if someone requests data */ - gtk_selection_add_handler( m_clipboardWidget, + 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( wxDataFormat format ) { 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 = format.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->GetFormat() )) 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,