#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"
// 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)
{
public:
DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
- ~DnDFrame();
+ virtual ~DnDFrame();
void OnPaint(wxPaintEvent& event);
- void OnQuit (wxCommandEvent& event);
+ void OnSize(wxSizeEvent& event);
+ void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
- void OnDrag (wxCommandEvent& event);
+ void OnDrag(wxCommandEvent& event);
+ void OnDragMoveByDefault(wxCommandEvent& event);
+ void OnDragMoveAllow(wxCommandEvent& event);
void OnNewFrame(wxCommandEvent& event);
void OnHelp (wxCommandEvent& event);
void OnLogClear(wxCommandEvent& event);
void OnLeftDown(wxMouseEvent& event);
void OnRightDown(wxMouseEvent& event);
+ void OnUpdateUIMoveByDefault(wxUpdateUIEvent& event);
+
void OnUpdateUIPasteText(wxUpdateUIEvent& event);
void OnUpdateUIPasteBitmap(wxUpdateUIEvent& event);
DECLARE_EVENT_TABLE()
private:
+ // GUI controls
wxListBox *m_ctrlFile,
*m_ctrlText;
wxTextCtrl *m_ctrlLog;
wxLog *m_pLog,
*m_pLogPrev;
+ // move the text by default (or copy)?
+ bool m_moveByDefault;
+
+ // allow moving the text at all?
+ bool m_moveAllow;
+
+ // the text we drag
wxString m_strText;
};
}
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
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
}
};
dc.DrawLine(p3, p4);
dc.DrawLine(p4, p1);
-#ifdef __WXMSW__
+ dc.SetBrush(wxBrush(m_col, wxSOLID));
dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
-#endif
}
};
dc.DrawEllipse(m_pos, m_size);
-#ifdef __WXMSW__
+ dc.SetBrush(wxBrush(m_col, wxSOLID));
dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
-#endif
}
};
{
Menu_Quit = 1,
Menu_Drag,
+ Menu_DragMoveDef,
+ Menu_DragMoveAllow,
Menu_NewFrame,
Menu_About = 101,
Menu_Help,
EVT_MENU(Menu_Quit, DnDFrame::OnQuit)
EVT_MENU(Menu_About, DnDFrame::OnAbout)
EVT_MENU(Menu_Drag, DnDFrame::OnDrag)
+ EVT_MENU(Menu_DragMoveDef, DnDFrame::OnDragMoveByDefault)
+ EVT_MENU(Menu_DragMoveAllow,DnDFrame::OnDragMoveAllow)
EVT_MENU(Menu_NewFrame, DnDFrame::OnNewFrame)
EVT_MENU(Menu_Help, DnDFrame::OnHelp)
EVT_MENU(Menu_Clear, DnDFrame::OnLogClear)
#endif // USE_METAFILES
EVT_MENU(Menu_CopyFiles, DnDFrame::OnCopyFiles)
+ EVT_UPDATE_UI(Menu_DragMoveDef, DnDFrame::OnUpdateUIMoveByDefault)
+
EVT_UPDATE_UI(Menu_Paste, DnDFrame::OnUpdateUIPasteText)
EVT_UPDATE_UI(Menu_PasteBitmap, DnDFrame::OnUpdateUIPasteBitmap)
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)
// construct menu
wxMenu *file_menu = new wxMenu;
file_menu->Append(Menu_Drag, "&Test drag...");
+ file_menu->AppendCheckItem(Menu_DragMoveDef, "&Move by default");
+ file_menu->AppendCheckItem(Menu_DragMoveAllow, "&Allow moving");
file_menu->AppendSeparator();
file_menu->Append(Menu_NewFrame, "&New frame\tCtrl-N");
file_menu->AppendSeparator();
- file_menu->Append(Menu_Quit, "E&xit");
+ file_menu->Append(Menu_Quit, "E&xit\tCtrl-Q");
wxMenu *log_menu = new wxMenu;
log_menu->Append(Menu_Clear, "Clear\tCtrl-L");
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");
m_ctrlLog->SetConstraints(c);
SetAutoLayout(TRUE);
+
+ // copy data by default but allow moving it as well
+ m_moveByDefault = FALSE;
+ m_moveAllow = TRUE;
+ menu_bar->Check(Menu_DragMoveAllow, TRUE);
}
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;
GetClientSize( &w, &h );
wxPaintDC dc(this);
+ // dc.Clear(); -- this kills wxGTK
dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) );
dc.DrawText( "Drag text from here!", 100, h-50 );
}
+void DnDFrame::OnUpdateUIMoveByDefault(wxUpdateUIEvent& event)
+{
+ // only can move by default if moving is allowed at all
+ event.Enable(m_moveAllow);
+}
+
void DnDFrame::OnUpdateUIPasteText(wxUpdateUIEvent& event)
{
#ifdef __WXDEBUG__
m_strText = strText;
}
+void DnDFrame::OnDragMoveByDefault(wxCommandEvent& event)
+{
+ m_moveByDefault = event.IsChecked();
+}
+
+void DnDFrame::OnDragMoveAllow(wxCommandEvent& event)
+{
+ m_moveAllow = event.IsChecked();
+}
+
void DnDFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox("Drag-&-Drop Demo\n"
wxDROP_ICON(dnd_move),
wxDROP_ICON(dnd_none));
- const char *pc;
+ int flags = 0;
+ if ( m_moveByDefault )
+ flags |= wxDrag_DefaultMove;
+ else if ( m_moveAllow )
+ flags |= wxDrag_AllowMove;
- switch ( source.DoDragDrop(TRUE) )
+ const char *pc;
+ switch ( source.DoDragDrop(flags) )
{
case wxDragError: pc = "Error!"; break;
case wxDragNone: pc = "Nothing"; break;
wxLogStatus( _T("Decoding image file...") );
wxYield();
- wxBitmap bitmap( image.ConvertToBitmap() );
+ wxBitmap bitmap( image );
if ( !wxTheClipboard->Open() )
{
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 );
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 );
wxPoint pt(x, y);
wxString s;
- s.Printf(wxT("Shape dropped at (%ld, %ld)"), pt.x, pt.y);
+ s.Printf(wxT("Shape dropped at (%d, %d)"), pt.x, pt.y);
SetStatusText(s);
shape->Move(pt);
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);