X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2d68e1b4f42c2c021a2a45bd9ea385153fbcbbf4..b8aa1680f21faef698d39a2bce9c09e45a5bbf7a:/samples/dnd/dnd.cpp?ds=sidebyside diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index f747e454a3..0b26e485d8 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -542,8 +542,9 @@ public: } // override base class (pure) virtuals - virtual void OnEnter() - { m_frame->SetStatusText("Mouse entered the frame"); } + virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def) + { m_frame->SetStatusText("Mouse entered the frame"); + return OnDragOver(x, y, def); } virtual void OnLeave() { m_frame->SetStatusText("Mouse left the frame"); } virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) @@ -657,10 +658,21 @@ bool DnDApp::OnInit() wxDefaultResourceTable->ParseResourceFile(path); + // switch on trace messages +#if defined(__WXGTK__) + wxLog::AddTraceMask(_T("clipboard")); +#elif defined(__WXMSW__) + wxLog::AddTraceMask(wxTRACE_OleCalls); +#endif + #if wxUSE_LIBPNG wxImage::AddHandler( new wxPNGHandler ); #endif + // under X we usually want to use the primary selection by default (which + // is shared with other apps) + wxTheClipboard->UsePrimarySelection(); + // create the main frame window DnDFrame *frame = new DnDFrame((wxFrame *) NULL, "Drag-and-Drop/Clipboard wxWindows Sample", @@ -693,7 +705,7 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h) file_menu->Append(Menu_Quit, "E&xit"); wxMenu *log_menu = new wxMenu; - log_menu->Append(Menu_Clear, "Clear\tDel"); + log_menu->Append(Menu_Clear, "Clear\tCtrl-L"); wxMenu *help_menu = new wxMenu; help_menu->Append(Menu_Help, "&Help..."); @@ -732,11 +744,7 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h) wxTE_MULTILINE | wxTE_READONLY | wxSUNKEN_BORDER ); -#ifdef __WXMSW__ - // redirect log messages to the text window and switch on OLE messages - // logging - wxLog::AddTraceMask(wxTRACE_OleCalls); -#endif + // redirect log messages to the text window m_pLog = new wxLogTextCtrl(m_ctrlLog); m_pLogPrev = wxLog::SetActiveTarget(m_pLog); @@ -799,11 +807,23 @@ void DnDFrame::OnPaint(wxPaintEvent& WXUNUSED(event)) void DnDFrame::OnUpdateUIPasteText(wxUpdateUIEvent& event) { +#ifdef __WXDEBUG__ + // too many trace messages if we don't do it - this function is called + // very often + wxLogNull nolog; +#endif + event.Enable( wxTheClipboard->IsSupported(wxDF_TEXT) ); } void DnDFrame::OnUpdateUIPasteBitmap(wxUpdateUIEvent& event) { +#ifdef __WXDEBUG__ + // too many trace messages if we don't do it - this function is called + // very often + wxLogNull nolog; +#endif + event.Enable( wxTheClipboard->IsSupported(wxDF_BITMAP) ); } @@ -869,6 +889,8 @@ void DnDFrame::OnHelp(wxCommandEvent& /* event */) void DnDFrame::OnLogClear(wxCommandEvent& /* event */ ) { m_ctrlLog->Clear(); + m_ctrlText->Clear(); + m_ctrlFile->Clear(); } void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) ) @@ -879,16 +901,17 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) ) wxTextDataObject textData(m_strText); /* wxFileDataObject textData; - textData.AddFile( "/file1.txt" ); - textData.AddFile( "/file2.txt" ); + textData.AddFile( "/file1.txt" ); + textData.AddFile( "/file2.txt" ); */ wxDropSource source(textData, this + #ifdef __WXMSW__ - ,wxCURSOR_PENCIL, // for copy + ,wxCURSOR_PENCIL, // for copy wxCURSOR_SPRAYCAN, // for move - wxCURSOR_QUESTION_ARROW // for nothing + wxCURSOR_QUESTION_ARROW // for nothing #endif - ); + ); const char *pc; @@ -1037,15 +1060,23 @@ void DnDFrame::OnPasteBitmap(wxCommandEvent& WXUNUSED(event)) void DnDFrame::OnCopyFiles(wxCommandEvent& WXUNUSED(event)) { #ifdef __WXMSW__ - wxFileDataObject *dobj = new wxFileDataObject; - wxFileDialog dialog(this, "Select a file to copy", "", "", "All files (*.*)|*.*", 0); - if ( dialog.ShowModal() == wxID_OK ) + wxArrayString filenames; + while ( dialog.ShowModal() == wxID_OK ) { - wxString filename = dialog.GetPath(); - dobj->AddFile(filename); + 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 ) @@ -1056,12 +1087,12 @@ void DnDFrame::OnCopyFiles(wxCommandEvent& WXUNUSED(event)) { if ( !wxTheClipboard->AddData(dobj) ) { - wxLogError("Can't copy file to the clipboard"); + wxLogError("Can't copy file(s) to the clipboard"); } else { - wxLogStatus(this, "File '%s' copied to the clipboard", - filename.c_str()); + wxLogStatus(this, "%d file%s copied to the clipboard", + count, count == 1 ? "" : "s"); } } }