+ if ( m_pLog != NULL ) {
+ if ( wxLog::SetActiveTarget(m_pLogPrev) == m_pLog )
+ delete m_pLog;
+ }
+}
+
+// ---------------------------------------------------------------------------
+// bitmap clipboard
+// ---------------------------------------------------------------------------
+
+void DnDFrame::OnCopyBitmap(wxCommandEvent& WXUNUSED(event))
+{
+ // PNG support is not always compiled in under Windows, so use BMP there
+#ifdef __WXMSW__
+ wxFileDialog dialog(this, "Open a BMP file", "", "", "BMP files (*.bmp)|*.bmp", 0);
+#else
+ wxFileDialog dialog(this, "Open a PNG file", "", "", "PNG files (*.png)|*.png", 0);
+#endif
+
+ if (dialog.ShowModal() != wxID_OK)
+ {
+ wxLogMessage( _T("Aborted file open") );
+ return;
+ }
+
+ if (dialog.GetPath().IsEmpty())
+ {
+ wxLogMessage( _T("Returned empty string.") );
+ return;
+ }
+
+ if (!wxFileExists(dialog.GetPath()))
+ {
+ wxLogMessage( _T("File doesn't exist.") );
+ return;
+ }
+
+ wxImage image;
+ image.LoadFile( dialog.GetPath(),
+#ifdef __WXMSW__
+ wxBITMAP_TYPE_BMP
+#else
+ wxBITMAP_TYPE_PNG
+#endif
+ );
+ if (!image.Ok())
+ {
+ wxLogError( _T("Invalid image file...") );
+ return;
+ }
+
+ wxLogStatus( _T("Decoding image file...") );
+ wxYield();
+
+ wxBitmap bitmap( image.ConvertToBitmap() );
+
+ if ( !wxTheClipboard->Open() )
+ {
+ wxLogError(_T("Can't open clipboard."));
+
+ return;
+ }
+
+ wxLogMessage( _T("Creating wxBitmapDataObject...") );
+ wxYield();
+
+ if ( !wxTheClipboard->AddData(new wxBitmapDataObject(bitmap)) )
+ {
+ wxLogError(_T("Can't copy image to the clipboard."));
+ }
+ else
+ {
+ wxLogMessage(_T("Image has been put on the clipboard.") );
+ wxLogMessage(_T("You can paste it now and look at it.") );
+ }
+
+ wxTheClipboard->Close();
+}
+
+void DnDFrame::OnPasteBitmap(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !wxTheClipboard->Open() )
+ {
+ wxLogError(_T("Can't open clipboard."));
+
+ return;
+ }
+
+ if ( !wxTheClipboard->IsSupported(wxDF_BITMAP) )
+ {
+ wxLogWarning(_T("No bitmap on clipboard"));
+
+ wxTheClipboard->Close();
+ return;
+ }
+
+ wxBitmapDataObject data;
+ if ( !wxTheClipboard->GetData(data) )
+ {
+ wxLogError(_T("Can't paste bitmap from the clipboard"));
+ }
+ else
+ {
+ const wxBitmap& bmp = data.GetBitmap();
+
+ wxLogMessage(_T("Bitmap %dx%d pasted from the clipboard"),
+ bmp.GetWidth(), bmp.GetHeight());
+ ShowBitmap(bmp);
+ }
+
+ wxTheClipboard->Close();
+}
+
+#ifdef USE_METAFILES
+
+void DnDFrame::OnPasteMetafile(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !wxTheClipboard->Open() )
+ {
+ wxLogError(_T("Can't open clipboard."));
+
+ return;
+ }
+
+ if ( !wxTheClipboard->IsSupported(wxDF_METAFILE) )
+ {
+ wxLogWarning(_T("No metafile on clipboard"));
+ }
+ else
+ {
+ wxMetaFileDataObject data;
+ if ( !wxTheClipboard->GetData(data) )
+ {
+ wxLogError(_T("Can't paste metafile from the clipboard"));
+ }
+ else
+ {
+ const wxMetaFile& mf = data.GetMetafile();
+
+ wxLogMessage(_T("Metafile %dx%d pasted from the clipboard"),
+ mf.GetWidth(), mf.GetHeight());
+
+ ShowMetaFile(mf);
+ }
+ }
+
+ wxTheClipboard->Close();
+}
+
+#endif // USE_METAFILES
+
+// ----------------------------------------------------------------------------
+// file clipboard
+// ----------------------------------------------------------------------------
+
+void DnDFrame::OnCopyFiles(wxCommandEvent& WXUNUSED(event))
+{
+#ifdef __WXMSW__
+ wxFileDialog dialog(this, "Select a file to copy", "", "",
+ "All files (*.*)|*.*", 0);
+
+ wxArrayString filenames;
+ while ( dialog.ShowModal() == wxID_OK )
+ {
+ filenames.Add(dialog.GetPath());
+ }
+
+ if ( !filenames.IsEmpty() )
+ {
+ wxFileDataObject *dobj = new wxFileDataObject;
+ size_t count = filenames.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ dobj->AddFile(filenames[n]);
+ }
+
+ wxClipboardLocker locker;
+ if ( !locker )
+ {
+ wxLogError("Can't open clipboard");
+ }
+ else
+ {
+ if ( !wxTheClipboard->AddData(dobj) )
+ {
+ wxLogError("Can't copy file(s) to the clipboard");
+ }
+ else
+ {
+ wxLogStatus(this, "%d file%s copied to the clipboard",
+ count, count == 1 ? "" : "s");
+ }
+ }
+ }
+ else
+ {
+ wxLogStatus(this, "Aborted");
+ }
+#else // !MSW
+ wxLogError("Sorry, not implemented");
+#endif // MSW/!MSW
+}
+
+// ---------------------------------------------------------------------------
+// text clipboard
+// ---------------------------------------------------------------------------
+
+void DnDFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !wxTheClipboard->Open() )
+ {
+ wxLogError(_T("Can't open clipboard."));
+
+ return;
+ }
+
+ if ( !wxTheClipboard->AddData(new wxTextDataObject(m_strText)) )
+ {
+ wxLogError(_T("Can't copy data to the clipboard"));
+ }
+ else
+ {
+ wxLogMessage(_T("Text '%s' put on the clipboard"), m_strText.c_str());
+ }
+
+ wxTheClipboard->Close();
+}
+
+void DnDFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !wxTheClipboard->Open() )
+ {
+ wxLogError(_T("Can't open clipboard."));
+
+ return;
+ }
+
+ if ( !wxTheClipboard->IsSupported(wxDF_TEXT) )
+ {
+ wxLogWarning(_T("No text data on clipboard"));
+
+ wxTheClipboard->Close();
+ return;
+ }
+
+ wxTextDataObject text;
+ if ( !wxTheClipboard->GetData(text) )
+ {
+ wxLogError(_T("Can't paste data from the clipboard"));
+ }
+ else
+ {
+ wxLogMessage(_T("Text '%s' pasted from the clipboard"),
+ text.GetText().c_str());
+ }
+
+ wxTheClipboard->Close();