#include "wx/wx.h"
#endif
-#if !wxUSE_DRAG_AND_DROP
- #error This sample requires drag and drop support in the library
-#endif
-
-// under Windows we also support data transfer of metafiles as an extra bonus,
-// but they're not available under other platforms
-#ifdef __WINDOWS__
- #define USE_METAFILES
-#endif // Windows
-
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/colordlg.h"
#include "wx/sizer.h"
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
#include "wx/metafile.h"
-#endif // Windows
+#endif // wxUSE_METAFILES
#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
#include "mondrian.xpm"
#include "dnd_none.xpm"
#endif
+#if wxUSE_DRAG_AND_DROP
+
// ----------------------------------------------------------------------------
// Derive two simple classes which just put in the listbox the strings (text or
// file names) we drop on them
}
};
+#endif // wxUSE_DRAG_AND_DROP
+
// ----------------------------------------------------------------------------
// Define a new application type
// ----------------------------------------------------------------------------
IMPLEMENT_APP(DnDApp);
+#if wxUSE_DRAG_AND_DROP
+
// ----------------------------------------------------------------------------
// Define canvas class to show a bitmap
// ----------------------------------------------------------------------------
DECLARE_EVENT_TABLE()
};
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
// and the same thing fo metafiles
class DnDCanvasMetafile : public wxScrolledWindow
DECLARE_EVENT_TABLE()
};
-#endif // USE_METAFILES
+#endif // wxUSE_METAFILES
// ----------------------------------------------------------------------------
// Define a new frame type for the main frame
void OnCopyBitmap(wxCommandEvent& event);
void OnPasteBitmap(wxCommandEvent& event);
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
void OnPasteMetafile(wxCommandEvent& event);
-#endif // USE_METAFILES
+#endif // wxUSE_METAFILES
void OnCopyFiles(wxCommandEvent& event);
// we don't draw the shape to a bitmap until it's really needed (i.e.
// we're asked to do so)
m_hasBitmap = FALSE;
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
m_hasMetaFile = FALSE;
-#endif // Windows
+#endif // wxUSE_METAFILES
}
virtual ~DnDShapeDataObject() { delete m_shape; }
m_shape = (DnDShape *)NULL;
m_hasBitmap = FALSE;
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
m_hasMetaFile = FALSE;
-#endif // Windows
+#endif // wxUSE_METAFILES
return shape;
}
// but the bitmap format(s) are only supported for output
nFormats += m_dobjBitmap.GetFormatCount(dir);
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
nFormats += m_dobjMetaFile.GetFormatCount(dir);
-#endif // Windows
+#endif // wxUSE_METAFILES
}
return nFormats;
// under Windows
m_dobjBitmap.GetAllFormats(&formats[1], dir);
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
// don't assume that m_dobjBitmap has only 1 format
m_dobjMetaFile.GetAllFormats(&formats[1 +
m_dobjBitmap.GetFormatCount(dir)], dir);
-#endif // Windows
+#endif // wxUSE_METAFILES
}
}
{
return m_shape->GetDataSize();
}
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
else if ( m_dobjMetaFile.IsSupported(format) )
{
if ( !m_hasMetaFile )
return m_dobjMetaFile.GetDataSize(format);
}
-#endif // Windows
+#endif // wxUSE_METAFILES
else
{
wxASSERT_MSG( m_dobjBitmap.IsSupported(format),
return TRUE;
}
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
else if ( m_dobjMetaFile.IsSupported(format) )
{
if ( !m_hasMetaFile )
return m_dobjMetaFile.GetDataHere(format, pBuf);
}
-#endif // Windows
+#endif // wxUSE_METAFILES
else
{
wxASSERT_MSG( m_dobjBitmap.IsSupported(format),
// the shape has changed
m_hasBitmap = FALSE;
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
m_hasMetaFile = FALSE;
-#endif // Windows
+#endif // wxUSE_METAFILES
return TRUE;
}
private:
// creates a bitmap and assigns it to m_dobjBitmap (also sets m_hasBitmap)
void CreateBitmap() const;
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
void CreateMetaFile() const;
-#endif // Windows
+#endif // wxUSE_METAFILES
wxDataFormat m_formatShape; // our custom format
wxBitmapDataObject m_dobjBitmap; // it handles bitmaps
bool m_hasBitmap; // true if m_dobjBitmap has valid bitmap
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
wxMetaFileDataObject m_dobjMetaFile;// handles metafiles
bool m_hasMetaFile; // true if we have valid metafile
-#endif // Windows
+#endif // wxUSE_METAFILES
DnDShape *m_shape; // our data
};
~DnDShapeFrame();
void SetShape(DnDShape *shape);
+ virtual bool SetShape(const wxRegion ®ion)
+ {
+ return wxFrame::SetShape( region );
+ }
// callbacks
void OnNewShape(wxCommandEvent& event);
static void ShowBitmap(const wxBitmap& bitmap);
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
static void ShowMetaFile(const wxMetaFile& metafile);
-#endif // USE_METAFILES
+#endif // wxUSE_METAFILES
// ----------------------------------------------------------------------------
// IDs for the menu commands
EVT_MENU(Menu_Paste, DnDFrame::OnPaste)
EVT_MENU(Menu_CopyBitmap, DnDFrame::OnCopyBitmap)
EVT_MENU(Menu_PasteBitmap,DnDFrame::OnPasteBitmap)
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
EVT_MENU(Menu_PasteMFile, DnDFrame::OnPasteMetafile)
-#endif // USE_METAFILES
+#endif // wxUSE_METAFILES
EVT_MENU(Menu_CopyFiles, DnDFrame::OnCopyFiles)
EVT_UPDATE_UI(Menu_DragMoveDef, DnDFrame::OnUpdateUIMoveByDefault)
EVT_PAINT(DnDCanvasBitmap::OnPaint)
END_EVENT_TABLE()
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
BEGIN_EVENT_TABLE(DnDCanvasMetafile, wxScrolledWindow)
EVT_PAINT(DnDCanvasMetafile::OnPaint)
END_EVENT_TABLE()
-#endif // USE_METAFILES
+#endif // wxUSE_METAFILES
+
+#endif // wxUSE_DRAG_AND_DROP
// ============================================================================
// implementation
// `Main program' equivalent, creating windows and returning main app frame
bool DnDApp::OnInit()
{
+#if wxUSE_DRAG_AND_DROP
// switch on trace messages
#if defined(__WXGTK__)
wxLog::AddTraceMask(_T("clipboard"));
SetTopWindow(frame);
return TRUE;
+#else
+ wxMessageBox( _T("This sample has to be compiled with wxUSE_DRAG_AND_DROP"), _T("Building error"), wxOK);
+ return FALSE;
+#endif // wxUSE_DRAG_AND_DROP
}
+#if wxUSE_DRAG_AND_DROP
+
DnDFrame::DnDFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h)
: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)),
m_strText(_T("wxWindows drag & drop works :-)"))
clip_menu->AppendSeparator();
clip_menu->Append(Menu_CopyBitmap, _T("Copy &bitmap\tCtrl-Shift-C"));
clip_menu->Append(Menu_PasteBitmap, _T("Paste b&itmap\tCtrl-Shift-V"));
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
clip_menu->AppendSeparator();
clip_menu->Append(Menu_PasteMFile, _T("Paste &metafile\tCtrl-M"));
-#endif // USE_METAFILES
+#endif // wxUSE_METAFILES
clip_menu->AppendSeparator();
clip_menu->Append(Menu_CopyFiles, _T("Copy &files\tCtrl-F"));
void DnDFrame::OnCopyBitmap(wxCommandEvent& WXUNUSED(event))
{
// PNG support is not always compiled in under Windows, so use BMP there
-#ifdef __WXMSW__
- wxFileDialog dialog(this, _T("Open a BMP file"), _T(""), _T(""), _T("BMP files (*.bmp)|*.bmp"), 0);
-#else
+#if wxUSE_LIBPNG
wxFileDialog dialog(this, _T("Open a PNG file"), _T(""), _T(""), _T("PNG files (*.png)|*.png"), 0);
+#else
+ wxFileDialog dialog(this, _T("Open a BMP file"), _T(""), _T(""), _T("BMP files (*.bmp)|*.bmp"), 0);
#endif
if (dialog.ShowModal() != wxID_OK)
wxImage image;
image.LoadFile( dialog.GetPath(),
-#ifdef __WXMSW__
- wxBITMAP_TYPE_BMP
-#else
+#if wxUSE_LIBPNG
wxBITMAP_TYPE_PNG
+#else
+ wxBITMAP_TYPE_BMP
#endif
);
if (!image.Ok())
wxTheClipboard->Close();
}
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
void DnDFrame::OnPasteMetafile(wxCommandEvent& WXUNUSED(event))
{
wxTheClipboard->Close();
}
-#endif // USE_METAFILES
+#endif // wxUSE_METAFILES
// ----------------------------------------------------------------------------
// file clipboard
{
size_t nFiles = filenames.GetCount();
wxString str;
- str.Printf( _T("%d files dropped"), nFiles);
+ str.Printf( _T("%d files dropped"), (int)nFiles);
m_pOwner->Append(str);
for ( size_t n = 0; n < nFiles; n++ ) {
m_pOwner->Append(filenames[n]);
SetShape(shape);
}
-void DnDShapeFrame::OnEditShape(wxCommandEvent& event)
+void DnDShapeFrame::OnEditShape(wxCommandEvent& WXUNUSED(event))
{
DnDShapeDialog dlg(this, m_shape);
if ( dlg.ShowModal() == wxID_OK )
}
}
-void DnDShapeFrame::OnNewShape(wxCommandEvent& event)
+void DnDShapeFrame::OnNewShape(wxCommandEvent& WXUNUSED(event))
{
SetShape(new DnDEllipticShape(wxPoint(10, 10), wxSize(80, 60), *wxRED));
SetStatusText(_T("You can now drag the shape to another frame"));
}
-void DnDShapeFrame::OnClearShape(wxCommandEvent& event)
+void DnDShapeFrame::OnClearShape(wxCommandEvent& WXUNUSED(event))
{
SetShape(NULL);
}
-void DnDShapeFrame::OnCopyShape(wxCommandEvent& event)
+void DnDShapeFrame::OnCopyShape(wxCommandEvent& WXUNUSED(event))
{
if ( m_shape )
{
}
}
-void DnDShapeFrame::OnPasteShape(wxCommandEvent& event)
+void DnDShapeFrame::OnPasteShape(wxCommandEvent& WXUNUSED(event))
{
wxClipboardLocker clipLocker;
if ( !clipLocker )
// DnDShapeDataObject
// ----------------------------------------------------------------------------
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
void DnDShapeDataObject::CreateMetaFile() const
{
delete mf;
}
-#endif // Windows
+#endif // wxUSE_METAFILES
void DnDShapeDataObject::CreateBitmap() const
{
frame->Show(TRUE);
}
-#ifdef USE_METAFILES
+#if wxUSE_METAFILES
static void ShowMetaFile(const wxMetaFile& metafile)
{
frame->Show();
}
-#endif // USE_METAFILES
+#endif // wxUSE_METAFILES
+
+#endif // wxUSE_DRAG_AND_DROP