X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4693b20c7500190c3cc8c02919c45436bf5efbc9..4b04699b670b4ab4632229fa0264d154acd3bec1:/samples/dnd/dnd.cpp diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index 164dd9c712..7788cfdc7d 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -54,7 +54,7 @@ #include "wx/metafile.h" #endif // Windows -#if defined(__WXGTK__) || defined(__WXMOTIF__) +#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) #include "mondrian.xpm" #include "dnd_copy.xpm" @@ -109,7 +109,10 @@ public: // URLs can't be moved, only copied virtual wxDragResult OnDragOver(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult def) - { return def == wxDragMove ? wxDragCopy : def; } + { + return wxDragLink; // At least IE 5.x needs wxDragLink, the + // other browsers on MSW seem okay with it too. + } // translate this to calls to OnDropURL() just for convenience virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) @@ -221,6 +224,7 @@ public: ~DnDFrame(); void OnPaint(wxPaintEvent& event); + void OnSize(wxSizeEvent& event); void OnQuit (wxCommandEvent& event); void OnAbout(wxCommandEvent& event); void OnDrag (wxCommandEvent& event); @@ -328,9 +332,10 @@ public: } protected: + //get a point 1 up and 1 left, otherwise the mid-point of a triangle is on the line wxPoint GetCentre() const - { return wxPoint(m_pos.x + m_size.x / 2, m_pos.y + m_size.y / 2); } - + { return wxPoint(m_pos.x + m_size.x / 2 - 1, m_pos.y + m_size.y / 2 - 1); } + struct ShapeDump { int x, y, // position @@ -375,9 +380,9 @@ public: dc.DrawLine(p2, p3); dc.DrawLine(p3, p1); -#ifdef __WXMSW__ + //works in multicolor modes; on GTK (at least) will fail in 16-bit color + dc.SetBrush(wxBrush(m_col, wxSOLID)); dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER); -#endif } }; @@ -412,9 +417,8 @@ public: dc.DrawLine(p3, p4); dc.DrawLine(p4, p1); -#ifdef __WXMSW__ + dc.SetBrush(wxBrush(m_col, wxSOLID)); dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER); -#endif } }; @@ -441,9 +445,8 @@ public: dc.DrawEllipse(m_pos, m_size); -#ifdef __WXMSW__ + dc.SetBrush(wxBrush(m_col, wxSOLID)); dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER); -#endif } }; @@ -813,6 +816,7 @@ BEGIN_EVENT_TABLE(DnDFrame, wxFrame) EVT_LEFT_DOWN( DnDFrame::OnLeftDown) EVT_RIGHT_DOWN( DnDFrame::OnRightDown) EVT_PAINT( DnDFrame::OnPaint) + EVT_SIZE( DnDFrame::OnSize) END_EVENT_TABLE() BEGIN_EVENT_TABLE(DnDShapeFrame, wxFrame) @@ -928,17 +932,17 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h) help_menu->Append(Menu_About, "&About"); wxMenu *clip_menu = new wxMenu; - clip_menu->Append(Menu_Copy, "&Copy text\tCtrl+C"); - clip_menu->Append(Menu_Paste, "&Paste text\tCtrl+V"); + clip_menu->Append(Menu_Copy, "&Copy text\tCtrl-C"); + clip_menu->Append(Menu_Paste, "&Paste text\tCtrl-V"); clip_menu->AppendSeparator(); - clip_menu->Append(Menu_CopyBitmap, "Copy &bitmap\tAlt+C"); - clip_menu->Append(Menu_PasteBitmap, "Paste b&itmap\tAlt+V"); + clip_menu->Append(Menu_CopyBitmap, "Copy &bitmap\tCtrl-Shift-C"); + clip_menu->Append(Menu_PasteBitmap, "Paste b&itmap\tCtrl-Shift-V"); #ifdef USE_METAFILES clip_menu->AppendSeparator(); clip_menu->Append(Menu_PasteMFile, "Paste &metafile\tCtrl-M"); #endif // USE_METAFILES clip_menu->AppendSeparator(); - clip_menu->Append(Menu_CopyFiles, "Copy &files\tCtrl+F"); + clip_menu->Append(Menu_CopyFiles, "Copy &files\tCtrl-F"); wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, "&File"); @@ -1006,6 +1010,13 @@ void DnDFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) Close(TRUE); } +void DnDFrame::OnSize(wxSizeEvent& event) +{ + Refresh(); + + event.Skip(); +} + void DnDFrame::OnPaint(wxPaintEvent& WXUNUSED(event)) { int w = 0; @@ -1013,6 +1024,7 @@ void DnDFrame::OnPaint(wxPaintEvent& WXUNUSED(event)) GetClientSize( &w, &h ); wxPaintDC dc(this); + dc.Clear(); dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) ); dc.DrawText( "Drag text from here!", 100, h-50 ); } @@ -1204,7 +1216,7 @@ void DnDFrame::OnCopyBitmap(wxCommandEvent& WXUNUSED(event)) wxLogStatus( _T("Decoding image file...") ); wxYield(); - wxBitmap bitmap( image.ConvertToBitmap() ); + wxBitmap bitmap( image ); if ( !wxTheClipboard->Open() ) { @@ -1462,7 +1474,7 @@ DnDShapeDialog::DnDShapeDialog(wxFrame *parent, DnDShape *shape) const wxString choices[] = { wxT("None"), wxT("Triangle"), wxT("Rectangle"), wxT("Ellipse") }; - m_radio = new wxRadioBox( this, -1, wxT("&Shape"), + m_radio = new wxRadioBox( this, -1, wxT("&Shape"), wxDefaultPosition, wxDefaultSize, 4, choices, 4, wxRA_SPECIFY_COLS ); shapesSizer->Add( m_radio, 0, wxGROW|wxALL, 5 ); @@ -1472,32 +1484,32 @@ DnDShapeDialog::DnDShapeDialog(wxFrame *parent, DnDShape *shape) 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 ); + 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 ); + 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 ); + 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 ); + 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 ); @@ -1861,7 +1873,7 @@ void DnDShapeDataObject::CreateBitmap() const wxBitmap bitmap(x, y); wxMemoryDC dc; dc.SelectObject(bitmap); - dc.SetBrush(wxBrush("white", wxSOLID)); + dc.SetBrush(wxBrush(wxT("white"), wxSOLID)); dc.Clear(); m_shape->Draw(dc); dc.SelectObject(wxNullBitmap);