]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/dnd/dnd.cpp
Make it possible to use svn-find-native-eols script without svn checkout.
[wxWidgets.git] / samples / dnd / dnd.cpp
index 038b87eea29f40cac43208418aae347876a32331..7987e5fab03d1789d1d60cb25c2bda524bab81f1 100644 (file)
@@ -27,7 +27,7 @@
 #include "wx/metafile.h"
 #include "wx/dirctrl.h"
 
-#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
+#ifndef wxHAS_IMAGES_IN_RESOURCES
     #include "../sample.xpm"
 #if wxUSE_DRAG_AND_DROP
     #include "dnd_copy.xpm"
@@ -141,7 +141,7 @@ public:
     {
         wxPaintDC dc(this);
 
-        if ( m_bitmap.Ok() )
+        if ( m_bitmap.IsOk() )
         {
             PrepareDC(dc);
 
@@ -177,7 +177,7 @@ public:
     {
         wxPaintDC dc(this);
 
-        if ( m_metafile.Ok() )
+        if ( m_metafile.IsOk() )
         {
             PrepareDC(dc);
 
@@ -227,6 +227,7 @@ public:
 #endif // wxUSE_METAFILE
 
     void OnCopyFiles(wxCommandEvent& event);
+    void OnCopyURL(wxCommandEvent& event);
 
     void OnUsePrimary(wxCommandEvent& event);
 
@@ -341,7 +342,7 @@ public:
 
     virtual void Draw(wxDC& dc)
     {
-        dc.SetPen(wxPen(m_col, 1, wxSOLID));
+        dc.SetPen(wxPen(m_col));
     }
 
 protected:
@@ -394,7 +395,7 @@ public:
         dc.DrawLine(p3, p1);
 
         //works in multicolor modes; on GTK (at least) will fail in 16-bit color
-        dc.SetBrush(wxBrush(m_col, wxSOLID));
+        dc.SetBrush(wxBrush(m_col));
         dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
     }
 };
@@ -430,7 +431,7 @@ public:
         dc.DrawLine(p3, p4);
         dc.DrawLine(p4, p1);
 
-        dc.SetBrush(wxBrush(m_col, wxSOLID));
+        dc.SetBrush(wxBrush(m_col));
         dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
     }
 };
@@ -458,7 +459,7 @@ public:
 
         dc.DrawEllipse(m_pos, m_size);
 
-        dc.SetBrush(wxBrush(m_col, wxSOLID));
+        dc.SetBrush(wxBrush(m_col));
         dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
     }
 };
@@ -816,6 +817,7 @@ enum
     Menu_PasteBitmap,
     Menu_PasteMFile,
     Menu_CopyFiles,
+    Menu_CopyURL,
     Menu_UsePrimary,
     Menu_Shape_New = 500,
     Menu_Shape_Edit,
@@ -844,6 +846,7 @@ BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
     EVT_MENU(Menu_PasteMFile, DnDFrame::OnPasteMetafile)
 #endif // wxUSE_METAFILE
     EVT_MENU(Menu_CopyFiles,  DnDFrame::OnCopyFiles)
+    EVT_MENU(Menu_CopyURL,    DnDFrame::OnCopyURL)
     EVT_MENU(Menu_UsePrimary, DnDFrame::OnUsePrimary)
 
     EVT_UPDATE_UI(Menu_DragMoveDef, DnDFrame::OnUpdateUIMoveByDefault)
@@ -974,6 +977,7 @@ DnDFrame::DnDFrame()
 #endif // wxUSE_METAFILE
     clip_menu->AppendSeparator();
     clip_menu->Append(Menu_CopyFiles, wxT("Copy &files\tCtrl-F"));
+    clip_menu->Append(Menu_CopyURL, wxT("Copy &URL\tCtrl-U"));
     clip_menu->AppendSeparator();
     clip_menu->AppendCheckItem(Menu_UsePrimary, wxT("Use &primary selection\tCtrl-P"));
 
@@ -1018,7 +1022,7 @@ DnDFrame::DnDFrame()
     m_ctrlDir->Connect
     (
         wxID_ANY,
-        wxEVT_COMMAND_TREE_BEGIN_DRAG,
+        wxEVT_TREE_BEGIN_DRAG,
         wxTreeEventHandler(DnDFrame::OnBeginDrag),
         NULL,
         this
@@ -1177,7 +1181,7 @@ void DnDFrame::OnHelp(wxCommandEvent& /* event */)
                            wxT("it to wordpad or any other droptarget accepting text (and of course you can just drag it\n")
                            wxT("to the right pane). Due to a lot of trace messages, the cursor might take some time to \n")
                            wxT("change, don't release the mouse button until it does. You can change the string being\n")
-                           wxT("dragged in in \"File|Test drag...\" dialog.\n")
+                           wxT("dragged in \"File|Test drag...\" dialog.\n")
                            wxT("\n")
                            wxT("\n")
                            wxT("Please send all questions/bug reports/suggestions &c to \n")
@@ -1327,7 +1331,7 @@ void DnDFrame::OnCopyBitmap(wxCommandEvent& WXUNUSED(event))
                     wxBITMAP_TYPE_BMP
 #endif
                   );
-    if (!image.Ok())
+    if (!image.IsOk())
     {
         wxLogError( wxT("Invalid image file...") );
         return;
@@ -1485,6 +1489,27 @@ void DnDFrame::OnCopyFiles(wxCommandEvent& WXUNUSED(event))
 #endif // MSW/!MSW
 }
 
+void DnDFrame::OnCopyURL(wxCommandEvent& WXUNUSED(event))
+{
+    // Just hard code it for now, we could ask the user but the point here is
+    // to test copying URLs, it doesn't really matter what it is.
+    const wxString url("http://www.wxwidgets.org/");
+
+    wxClipboardLocker locker;
+    if ( !!locker && wxTheClipboard->AddData(new wxURLDataObject(url)) )
+    {
+        wxLogStatus(this, "Copied URL \"%s\" to %s.",
+                    url,
+                    GetMenuBar()->IsChecked(Menu_UsePrimary)
+                        ? "primary selection"
+                        : "clipboard");
+    }
+    else
+    {
+        wxLogError("Failed to copy URL.");
+    }
+}
+
 // ---------------------------------------------------------------------------
 // text clipboard
 // ---------------------------------------------------------------------------
@@ -1596,7 +1621,7 @@ DnDShapeDialog::DnDShapeDialog(wxFrame *parent, DnDShape *shape)
     // attributes
     wxStaticBox* box = new wxStaticBox( this, wxID_ANY, wxT("&Attributes") );
     wxStaticBoxSizer* attrSizer = new wxStaticBoxSizer( box, wxHORIZONTAL );
-    wxFlexGridSizer* xywhSizer = new wxFlexGridSizer( 4, 2 );
+    wxFlexGridSizer* xywhSizer = new wxFlexGridSizer( 2 );
 
     wxStaticText* st;
 
@@ -1998,7 +2023,7 @@ void DnDShapeDataObject::CreateBitmap() const
     wxBitmap bitmap(x, y);
     wxMemoryDC dc;
     dc.SelectObject(bitmap);
-    dc.SetBrush(wxBrush(wxT("white"), wxSOLID));
+    dc.SetBrush(*wxWHITE_BRUSH);
     dc.Clear();
     m_shape->Draw(dc);
     dc.SelectObject(wxNullBitmap);