X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/714cfcbd468055fc74c4d0980b5dfc17594b3bec..c45ead7b4bd0697526a2eeaccfc6eb88029125ea:/samples/dnd/dnd.cpp diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index 121323349d..eb6497e083 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -227,6 +227,8 @@ public: void OnCopyFiles(wxCommandEvent& event); + void OnUsePrimary(wxCommandEvent& event); + void OnLeftDown(wxMouseEvent& event); void OnRightDown(wxMouseEvent& event); @@ -801,6 +803,7 @@ enum Menu_PasteBitmap, Menu_PasteMFile, Menu_CopyFiles, + Menu_UsePrimary, Menu_Shape_New = 500, Menu_Shape_Edit, Menu_Shape_Clear, @@ -828,6 +831,7 @@ BEGIN_EVENT_TABLE(DnDFrame, wxFrame) EVT_MENU(Menu_PasteMFile, DnDFrame::OnPasteMetafile) #endif // wxUSE_METAFILE EVT_MENU(Menu_CopyFiles, DnDFrame::OnCopyFiles) + EVT_MENU(Menu_UsePrimary, DnDFrame::OnUsePrimary) EVT_UPDATE_UI(Menu_DragMoveDef, DnDFrame::OnUpdateUIMoveByDefault) @@ -883,6 +887,9 @@ END_EVENT_TABLE() // `Main program' equivalent, creating windows and returning main app frame bool DnDApp::OnInit() { + if ( !wxApp::OnInit() ) + return false; + #if wxUSE_DRAG_AND_DROP || wxUSE_CLIPBOARD // switch on trace messages #if wxUSE_LOG @@ -897,10 +904,6 @@ bool DnDApp::OnInit() 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, _T("Drag-and-Drop/Clipboard wxWidgets Sample"), @@ -964,6 +967,8 @@ DnDFrame::DnDFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int #endif // wxUSE_METAFILE clip_menu->AppendSeparator(); clip_menu->Append(Menu_CopyFiles, _T("Copy &files\tCtrl-F")); + clip_menu->AppendSeparator(); + clip_menu->AppendCheckItem(Menu_UsePrimary, _T("Use &primary selection\tCtrl-P")); wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, _T("&File")); @@ -1164,11 +1169,6 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) ) { // start drag operation wxTextDataObject textData(m_strText); -/* - wxFileDataObject textData; - textData.AddFile( "/file1.txt" ); - textData.AddFile( "/file2.txt" ); -*/ wxDropSource source(textData, this, wxDROP_ICON(dnd_copy), wxDROP_ICON(dnd_move), @@ -1223,6 +1223,15 @@ DnDFrame::~DnDFrame() #endif // wxUSE_LOG } +void DnDFrame::OnUsePrimary(wxCommandEvent& event) +{ + const bool usePrimary = event.IsChecked(); + wxTheClipboard->UsePrimarySelection(usePrimary); + + wxLogStatus(_T("Now using %s selection"), usePrimary ? _T("primary") + : _T("clipboard")); +} + // --------------------------------------------------------------------------- // bitmap clipboard // ---------------------------------------------------------------------------