+
+bool wxClipboard::IsSupported( wxDataFormat format )
+{
+ wxCHECK_MSG( m_open, FALSE, _T("clipboard not open") );
+
+ /* store requested format to be asked for by callbacks */
+
+ m_targetRequested = format.GetAtom();
+
+ wxCHECK_MSG( m_targetRequested, FALSE, _T("invalid clipboard format") );
+
+ m_formatSupported = FALSE;
+
+ /* perform query. this will set m_formatSupported to
+ TRUE if m_targetRequested is supported.
+ alsom we have to wait for the "answer" from the
+ clipboard owner which is an asynchronous process.
+ therefore we set m_waiting = TRUE here and wait
+ until the callback "targets_selection_received"
+ sets it to FALSE */
+
+ m_waiting = TRUE;
+
+ gtk_selection_convert( m_targetsWidget,
+ m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom,
+ g_targetsAtom,
+ GDK_CURRENT_TIME );
+
+ while (m_waiting) gtk_main_iteration();
+
+ if (!m_formatSupported) return FALSE;
+
+ return TRUE;
+}
+
+bool wxClipboard::GetData( wxDataObject *data )
+{
+ wxCHECK_MSG( m_open, FALSE, _T("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();
+
+ wxCHECK_MSG( m_targetRequested, FALSE, _T("invalid clipboard format") );
+
+ /* start query */
+
+ m_formatSupported = FALSE;
+
+ /* ask for clipboard contents. this will set
+ m_formatSupported to TRUE if m_targetRequested
+ is supported.
+ also, we have to wait for the "answer" from the
+ clipboard owner which is an asynchronous process.
+ therefore we set m_waiting = TRUE here and wait
+ until the callback "targets_selection_received"
+ sets it to FALSE */
+
+ m_waiting = TRUE;
+
+ gtk_selection_convert( m_clipboardWidget,
+ m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom,
+ m_targetRequested,
+ GDK_CURRENT_TIME );
+
+ while (m_waiting) gtk_main_iteration();
+
+ /* this is a true error as we checked for the presence of such data before */
+
+ wxCHECK_MSG( m_formatSupported, FALSE, _T("error retrieving data from clipboard") );
+
+ return TRUE;
+}
+
+//-----------------------------------------------------------------------------
+// wxClipboardModule
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)
+
+bool wxClipboardModule::OnInit()
+{
+ wxTheClipboard = new wxClipboard();
+
+ return TRUE;
+}
+
+void wxClipboardModule::OnExit()
+{
+ if (wxTheClipboard) delete wxTheClipboard;
+ wxTheClipboard = (wxClipboard*) NULL;
+}
+
+#endif
+
+ // wxUSE_CLIPBOARD
+