void OnNewFrame(wxCommandEvent& event);
void OnHelp (wxCommandEvent& event);
void OnLogClear(wxCommandEvent& event);
+
void OnCopy(wxCommandEvent& event);
void OnPaste(wxCommandEvent& event);
+
void OnCopyBitmap(wxCommandEvent& event);
void OnPasteBitmap(wxCommandEvent& event);
+ void OnCopyFiles(wxCommandEvent& event);
+
void OnLeftDown(wxMouseEvent& event);
void OnRightDown(wxMouseEvent& event);
}
// 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)
Menu_Paste,
Menu_CopyBitmap,
Menu_PasteBitmap,
- Menu_ToBeGreyed, /* for testing */
- Menu_ToBeDeleted, /* for testing */
+ Menu_CopyFiles,
Menu_Shape_New = 500,
Menu_Shape_Edit,
Menu_Shape_Clear,
EVT_MENU(Menu_Paste, DnDFrame::OnPaste)
EVT_MENU(Menu_CopyBitmap, DnDFrame::OnCopyBitmap)
EVT_MENU(Menu_PasteBitmap,DnDFrame::OnPasteBitmap)
+ EVT_MENU(Menu_CopyFiles, DnDFrame::OnCopyFiles)
EVT_UPDATE_UI(Menu_Paste, DnDFrame::OnUpdateUIPasteText)
EVT_UPDATE_UI(Menu_PasteBitmap, DnDFrame::OnUpdateUIPasteBitmap)
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",
- 50, 50, 450, 340);
+ 10, 10, 450, 340);
// activate it
frame->Show(TRUE);
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...");
clip_menu->AppendSeparator();
clip_menu->Append(Menu_CopyBitmap, "&Copy bitmap\tAlt+C");
clip_menu->Append(Menu_PasteBitmap, "&Paste bitmap\tAlt+V");
+ clip_menu->AppendSeparator();
+ clip_menu->Append(Menu_CopyFiles, "&Copy files\tCtrl+F");
wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, "&File");
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);
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) );
}
void DnDFrame::OnLogClear(wxCommandEvent& /* event */ )
{
m_ctrlLog->Clear();
+ m_ctrlText->Clear();
+ m_ctrlFile->Clear();
}
void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
{
// start drag operation
wxTextDataObject textData(m_strText);
- wxDropSource source(textData, this, wxICON(mondrian));
+/*
+ wxFileDataObject textData;
+ textData.AddFile( "/file1.txt" );
+ textData.AddFile( "/file2.txt" );
+*/
+ wxDropSource source(textData, this
+
+#ifdef __WXMSW__
+ ,wxCURSOR_PENCIL, // for copy
+ wxCURSOR_SPRAYCAN, // for move
+ wxCURSOR_QUESTION_ARROW // for nothing
+#endif
+ );
const char *pc;
void DnDFrame::OnRightDown(wxMouseEvent &event )
{
- wxMenu *menu = new wxMenu;
+ wxMenu menu("Dnd sample menu");
- menu->Append(Menu_Drag, "&Test drag...");
- menu->Append(Menu_About, "&About");
- menu->Append(Menu_Quit, "E&xit");
- menu->Append(Menu_ToBeDeleted, "To be deleted");
- menu->Append(Menu_ToBeGreyed, "To be greyed");
+ menu.Append(Menu_Drag, "&Test drag...");
+ menu.AppendSeparator();
+ menu.Append(Menu_About, "&About");
- menu->Delete( Menu_ToBeDeleted );
- menu->Enable( Menu_ToBeGreyed, FALSE );
-
- PopupMenu( menu, event.GetX(), event.GetY() );
+ PopupMenu( &menu, event.GetX(), event.GetY() );
}
DnDFrame::~DnDFrame()
wxTheClipboard->Close();
}
+// ----------------------------------------------------------------------------
+// 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
// ---------------------------------------------------------------------------
// start drag operation
DnDShapeDataObject shapeData(m_shape);
- wxDropSource source(shapeData, this, wxICON(mondrian));
+ wxDropSource source(shapeData, this);
const char *pc = NULL;
switch ( source.DoDragDrop(TRUE) )