+void DnDFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !wxTheClipboard->Open() )
+ {
+ wxLogError(_T("Can't open clipboard."));
+
+ return;
+ }
+
+ if ( !wxTheClipboard->IsSupported(wxDF_TEXT) )
+ {
+ wxLogWarning(_T("No text data on clipboard"));
+
+ wxTheClipboard->Close();
+ return;
+ }
+
+ wxTextDataObject text;
+ if ( !wxTheClipboard->GetData(text) )
+ {
+ wxLogError(_T("Can't paste data from the clipboard"));
+ }
+ else
+ {
+ wxLogMessage(_T("Text '%s' pasted from the clipboard"),
+ text.GetText().c_str());
+ }
+
+ wxTheClipboard->Close();
+}
+
+#if wxUSE_DRAG_AND_DROP
+
+// ----------------------------------------------------------------------------
+// Notifications called by the base class
+// ----------------------------------------------------------------------------
+
+bool DnDText::OnDropText(wxCoord, wxCoord, const wxString& text)
+{
+ m_pOwner->Append(text);
+
+ return true;
+}
+
+bool DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames)
+{
+ size_t nFiles = filenames.GetCount();
+ wxString str;
+ str.Printf( _T("%d files dropped"), (int)nFiles);
+
+ if (m_pOwner != NULL)
+ {
+ m_pOwner->Append(str);
+ for ( size_t n = 0; n < nFiles; n++ )
+ m_pOwner->Append(filenames[n]);
+ }
+
+ return true;
+}
+
+// ----------------------------------------------------------------------------
+// DnDShapeDialog
+// ----------------------------------------------------------------------------
+
+DnDShapeDialog::DnDShapeDialog(wxFrame *parent, DnDShape *shape)
+ :wxDialog( parent, 6001, wxT("Choose Shape"), wxPoint( 10, 10 ),
+ wxSize( 40, 40 ),
+ wxDEFAULT_DIALOG_STYLE | wxRAISED_BORDER | wxRESIZE_BORDER )
+{
+ m_shape = shape;
+ wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL );
+
+ // radio box
+ wxBoxSizer* shapesSizer = new wxBoxSizer( wxHORIZONTAL );
+ const wxString choices[] = { wxT("None"), wxT("Triangle"),
+ wxT("Rectangle"), wxT("Ellipse") };
+
+ m_radio = new wxRadioBox( this, wxID_ANY, wxT("&Shape"),
+ wxDefaultPosition, wxDefaultSize, 4, choices, 4,
+ wxRA_SPECIFY_COLS );
+ shapesSizer->Add( m_radio, 0, wxGROW|wxALL, 5 );
+ topSizer->Add( shapesSizer, 0, wxALL, 2 );
+
+ // attributes
+ wxStaticBox* box = new wxStaticBox( this, wxID_ANY, wxT("&Attributes") );
+ wxStaticBoxSizer* attrSizer = new wxStaticBoxSizer( box, wxHORIZONTAL );
+ wxFlexGridSizer* xywhSizer = new wxFlexGridSizer( 4, 2 );
+
+ wxStaticText* st;
+
+ st = new wxStaticText( this, wxID_ANY, wxT("Position &X:") );
+ m_textX = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
+ wxSize( 30, 20 ) );
+ xywhSizer->Add( st, 1, wxGROW|wxALL, 2 );
+ xywhSizer->Add( m_textX, 1, wxGROW|wxALL, 2 );
+
+ st = new wxStaticText( this, wxID_ANY, wxT("Size &width:") );
+ m_textW = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
+ wxSize( 30, 20 ) );
+ xywhSizer->Add( st, 1, wxGROW|wxALL, 2 );
+ xywhSizer->Add( m_textW, 1, wxGROW|wxALL, 2 );
+
+ st = new wxStaticText( this, wxID_ANY, wxT("&Y:") );
+ m_textY = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
+ wxSize( 30, 20 ) );
+ xywhSizer->Add( st, 1, wxALL|wxALIGN_RIGHT, 2 );
+ xywhSizer->Add( m_textY, 1, wxGROW|wxALL, 2 );
+
+ st = new wxStaticText( this, wxID_ANY, wxT("&height:") );
+ m_textH = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
+ wxSize( 30, 20 ) );
+ xywhSizer->Add( st, 1, wxALL|wxALIGN_RIGHT, 2 );
+ xywhSizer->Add( m_textH, 1, wxGROW|wxALL, 2 );
+
+ wxButton* col = new wxButton( this, Button_Colour, wxT("&Colour...") );
+ attrSizer->Add( xywhSizer, 1, wxGROW );
+ attrSizer->Add( col, 0, wxALL|wxALIGN_CENTRE_VERTICAL, 2 );
+ topSizer->Add( attrSizer, 0, wxGROW|wxALL, 5 );
+
+ // buttons
+ wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
+ wxButton* bt;
+ bt = new wxButton( this, wxID_OK, wxT("Ok") );
+ buttonSizer->Add( bt, 0, wxALL, 2 );
+ bt = new wxButton( this, wxID_CANCEL, wxT("Cancel") );
+ buttonSizer->Add( bt, 0, wxALL, 2 );
+ topSizer->Add( buttonSizer, 0, wxALL|wxALIGN_RIGHT, 2 );
+
+ SetSizerAndFit( topSizer );
+}
+
+DnDShape *DnDShapeDialog::GetShape() const
+{
+ switch ( m_shapeKind )
+ {
+ default:
+ case DnDShape::None: return NULL;
+ case DnDShape::Triangle: return new DnDTriangularShape(m_pos, m_size, m_col);
+ case DnDShape::Rectangle: return new DnDRectangularShape(m_pos, m_size, m_col);
+ case DnDShape::Ellipse: return new DnDEllipticShape(m_pos, m_size, m_col);
+ }
+}
+
+bool DnDShapeDialog::TransferDataToWindow()
+{
+
+ if ( m_shape )
+ {
+ m_radio->SetSelection(m_shape->GetKind());
+ m_pos = m_shape->GetPosition();
+ m_size = m_shape->GetSize();
+ m_col = m_shape->GetColour();
+ }
+ else
+ {
+ m_radio->SetSelection(DnDShape::None);
+ m_pos = wxPoint(1, 1);
+ m_size = wxSize(100, 100);
+ }
+
+ m_textX->SetValue(wxString() << m_pos.x);
+ m_textY->SetValue(wxString() << m_pos.y);
+ m_textW->SetValue(wxString() << m_size.x);
+ m_textH->SetValue(wxString() << m_size.y);
+
+ return true;
+}
+
+bool DnDShapeDialog::TransferDataFromWindow()
+{
+ m_shapeKind = (DnDShape::Kind)m_radio->GetSelection();
+
+ m_pos.x = wxAtoi(m_textX->GetValue());
+ m_pos.y = wxAtoi(m_textY->GetValue());
+ m_size.x = wxAtoi(m_textW->GetValue());
+ m_size.y = wxAtoi(m_textH->GetValue());
+
+ if ( !m_pos.x || !m_pos.y || !m_size.x || !m_size.y )
+ {
+ wxMessageBox(_T("All sizes and positions should be non null!"),
+ _T("Invalid shape"), wxICON_HAND | wxOK, this);
+
+ return false;
+ }
+
+ return true;
+}
+
+void DnDShapeDialog::OnColour(wxCommandEvent& WXUNUSED(event))