+ m_shape = shape;
+#if USE_RESOURCES
+ LoadFromResource(parent, _T("dialogShape"));
+
+ m_textX = (wxTextCtrl *)wxFindWindowByName(_T("textX"), this);
+ m_textY = (wxTextCtrl *)wxFindWindowByName(_T("textY"), this);
+ m_textW = (wxTextCtrl *)wxFindWindowByName(_T("textW"), this);
+ m_textH = (wxTextCtrl *)wxFindWindowByName(_T("textH"), this);
+
+ m_radio = (wxRadioBox *)wxFindWindowByName(_T("radio"), this);
+#else
+ 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, -1, 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, -1, wxT("&Attributes") );
+ wxStaticBoxSizer* attrSizer = new wxStaticBoxSizer( box, wxHORIZONTAL );
+ wxFlexGridSizer* xywhSizer = new wxFlexGridSizer( 4, 2 );
+
+ wxStaticText* st;
+
+ st = new wxStaticText( this, -1, wxT("Position &X:") );
+ m_textX = new wxTextCtrl( this, -1, wxEmptyString, wxDefaultPosition,
+ wxSize( 30, 20 ) );
+ xywhSizer->Add( st, 1, wxGROW|wxALL, 2 );
+ xywhSizer->Add( m_textX, 1, wxGROW|wxALL, 2 );
+
+ st = new wxStaticText( this, -1, wxT("Size &width:") );
+ m_textW = new wxTextCtrl( this, -1, wxEmptyString, wxDefaultPosition,
+ wxSize( 30, 20 ) );
+ xywhSizer->Add( st, 1, wxGROW|wxALL, 2 );
+ xywhSizer->Add( m_textW, 1, wxGROW|wxALL, 2 );
+
+ st = new wxStaticText( this, -1, wxT("&Y:") );
+ m_textY = new wxTextCtrl( this, -1, 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, -1, wxT("&height:") );
+ m_textH = new wxTextCtrl( this, -1, 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 );
+
+ SetAutoLayout( TRUE );
+ SetSizer( topSizer );
+ topSizer->Fit( this );
+#endif
+}
+
+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))
+{
+ wxColourData data;
+ data.SetChooseFull(TRUE);
+ for (int i = 0; i < 16; i++)
+ {
+ wxColour colour(i*16, i*16, i*16);
+ data.SetCustomColour(i, colour);
+ }
+
+ wxColourDialog dialog(this, &data);
+ if ( dialog.ShowModal() == wxID_OK )
+ {
+ m_col = dialog.GetColourData().GetColour();
+ }
+}
+
+// ----------------------------------------------------------------------------
+// DnDShapeFrame
+// ----------------------------------------------------------------------------
+
+DnDShapeFrame *DnDShapeFrame::ms_lastDropTarget = NULL;
+
+DnDShapeFrame::DnDShapeFrame(wxFrame *parent)
+ : wxFrame(parent, -1, _T("Shape Frame"),
+ wxDefaultPosition, wxSize(250, 150))
+{
+ CreateStatusBar();
+
+ wxMenu *menuShape = new wxMenu;
+ menuShape->Append(Menu_Shape_New, _T("&New default shape\tCtrl-S"));
+ menuShape->Append(Menu_Shape_Edit, _T("&Edit shape\tCtrl-E"));
+ menuShape->AppendSeparator();
+ menuShape->Append(Menu_Shape_Clear, _T("&Clear shape\tCtrl-L"));
+
+ wxMenu *menuClipboard = new wxMenu;
+ menuClipboard->Append(Menu_ShapeClipboard_Copy, _T("&Copy\tCtrl-C"));
+ menuClipboard->Append(Menu_ShapeClipboard_Paste, _T("&Paste\tCtrl-V"));
+
+ wxMenuBar *menubar = new wxMenuBar;
+ menubar->Append(menuShape, _T("&Shape"));
+ menubar->Append(menuClipboard, _T("&Clipboard"));
+
+ SetMenuBar(menubar);
+
+ SetStatusText(_T("Press Ctrl-S to create a new shape"));
+
+ SetDropTarget(new DnDShapeDropTarget(this));
+
+ m_shape = NULL;
+
+ SetBackgroundColour(*wxWHITE);
+}
+
+DnDShapeFrame::~DnDShapeFrame()
+{
+ if (m_shape)
+ delete m_shape;
+}
+
+void DnDShapeFrame::SetShape(DnDShape *shape)
+{
+ if (m_shape)
+ delete m_shape;
+ m_shape = shape;
+ Refresh();
+}
+
+// callbacks
+void DnDShapeFrame::OnDrag(wxMouseEvent& event)
+{
+ if ( !m_shape )
+ {
+ event.Skip();
+
+ return;
+ }
+