X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2845ddc25c401eab92825563a27aade46f7cfe3d..7a120a8385f03eb419e6bcd7706399e7b47579af:/samples/dnd/dnd.cpp diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index 6fdeb7b2da..6a42410921 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -9,22 +9,26 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#include "wx/wxprec.h" +#include #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP -#include "wx/wx.h" +#include #endif -#include "wx/intl.h" -#include "wx/log.h" +#include +#include -#include "wx/dnd.h" +#include -#ifdef __WXGTK__ +#ifdef __WXMOTIF__ +#error Sorry, drag and drop is not yet implemented on wxMotif. +#endif + +#if defined(__WXGTK__) || defined(__WXMOTIF__) #include "mondrian.xpm" #endif @@ -32,12 +36,20 @@ // Derive two simple classes which just put in the listbox the strings (text or // file names) we drop on them // ---------------------------------------------------------------------------- + +// FIXME this is ugly and should be fixed in the library itself +#ifdef __WXMSW__ + typedef long wxDropPointCoord; +#else // wxGTK + typedef int wxDropPointCoord; +#endif // MSW/GTK + class DnDText : public wxTextDropTarget { public: DnDText(wxListBox *pOwner) { m_pOwner = pOwner; } - virtual bool OnDropText(long x, long y, const char *psz); + virtual bool OnDropText(wxDropPointCoord x, wxDropPointCoord y, const wxChar* psz ); private: wxListBox *m_pOwner; @@ -48,8 +60,8 @@ class DnDFile : public wxFileDropTarget public: DnDFile(wxListBox *pOwner) { m_pOwner = pOwner; } - virtual bool OnDropFiles(long x, long y, - size_t nFiles, const char * const aszFiles[]); + virtual bool OnDropFiles(wxDropPointCoord x, wxDropPointCoord y, + size_t nFiles, const wxChar* const aszFiles[] ); private: wxListBox *m_pOwner; @@ -58,6 +70,7 @@ private: // ---------------------------------------------------------------------------- // Define a new application type // ---------------------------------------------------------------------------- + class DnDApp : public wxApp { public: @@ -85,8 +98,6 @@ public: void OnLeftDown(wxMouseEvent& event); void OnRightDown(wxMouseEvent& event); - bool OnClose(); - DECLARE_EVENT_TABLE() private: @@ -102,6 +113,7 @@ private: // ---------------------------------------------------------------------------- // IDs for the menu commands // ---------------------------------------------------------------------------- + enum { Menu_Quit = 1, @@ -142,7 +154,7 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h) m_strText("wxWindows drag & drop works :-)") { - SetBackgroundColour(* wxWHITE); +// SetBackgroundColour(* wxWHITE); // frame icon and status bar SetIcon(wxICON(mondrian)); @@ -182,7 +194,7 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h) m_ctrlLog = new wxTextCtrl(this, -1, "", pos, size, wxTE_MULTILINE | wxTE_READONLY | - wxSUNKEN_BORDER| wxHSCROLL); + wxSUNKEN_BORDER ); // redirect log messages to the text window (don't forget to delete it!) m_pLog = new wxLogTextCtrl(m_ctrlLog); @@ -233,8 +245,8 @@ void DnDFrame::OnPaint(wxPaintEvent& /*event*/) GetClientSize( &w, &h ); wxPaintDC dc(this); - dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL ) ); - dc.DrawText( "Drag text from here!", 20, h-30 ); + dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) ); + dc.DrawText( "Drag text from here!", 20, h-35 ); } void DnDFrame::OnDrag(wxCommandEvent& /* event */) @@ -295,21 +307,21 @@ void DnDFrame::OnLogClear(wxCommandEvent& /* event */ ) m_ctrlLog->Clear(); } -bool DnDFrame::OnClose() -{ - return TRUE; -} - void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) ) { - if ( !m_strText.IsEmpty() ) { + if ( !m_strText.IsEmpty() ) + { // start drag operation - - wxTextDataObject data(m_strText); - wxDropSource dragSource(data, this); +#ifdef __WXMSW__ + wxTextDataObject textData(m_strText); + wxDropSource dragSource( textData, this ); +#else + wxDropSource dragSource( new wxTextDataObject (m_strText), this, wxIcon(mondrian_xpm) ); +#endif const char *pc; - switch ( dragSource.DoDragDrop(TRUE) ) { + switch ( dragSource.DoDragDrop(TRUE) ) + { case wxDragError: pc = "Error!"; break; case wxDragNone: pc = "Nothing"; break; case wxDragCopy: pc = "Copied"; break; @@ -344,18 +356,18 @@ DnDFrame::~DnDFrame() // ---------------------------------------------------------------------------- // Notifications called by the base class // ---------------------------------------------------------------------------- -bool DnDText::OnDropText(long, long, const char *psz) +bool DnDText::OnDropText( wxDropPointCoord, wxDropPointCoord, const wxChar *psz ) { m_pOwner->Append(psz); return TRUE; } -bool DnDFile::OnDropFiles(long, long, size_t nFiles, - const char * const aszFiles[]) +bool DnDFile::OnDropFiles( wxDropPointCoord, wxDropPointCoord, size_t nFiles, + const wxChar* const aszFiles[]) { wxString str; - str.Printf("%d files dropped", nFiles); + str.Printf( _T("%d files dropped"), nFiles); m_pOwner->Append(str); for ( size_t n = 0; n < nFiles; n++ ) { m_pOwner->Append(aszFiles[n]);