+// bitmap clipboard
+// ---------------------------------------------------------------------------
+
+void DnDFrame::OnCopyBitmap(wxCommandEvent& WXUNUSED(event))
+{
+ wxFileDialog dialog(this, "Open a PNG file", "", "", "PNG files (*.png)|*.png", 0);
+
+ 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(), wxBITMAP_TYPE_PNG );
+ if (!image.Ok())
+ {
+ wxLogMessage( _T("Invalid image file...") );
+ return;
+ }
+
+ wxLogMessage( _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
+ {
+ wxLogMessage(_T("Bitmap pasted from the clipboard") );
+ m_bitmap = data.GetBitmap();
+ Refresh();
+ }
+
+ wxTheClipboard->Close();
+}
+
+// ---------------------------------------------------------------------------
+// text clipboard