]>
git.saurik.com Git - wxWidgets.git/blob - samples/dragimag/dragimag.h
e70fc5faf56e416ad1523c7f11b5c155a1711e4f
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDragImage sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DRAGIMAGSAMPLE_
13 #define _WX_DRAGIMAGSAMPLE_
24 class MyFrame
: public wxFrame
29 void OnAbout( wxCommandEvent
&event
);
30 void OnQuit( wxCommandEvent
&event
);
32 MyCanvas
* GetCanvas() const { return m_canvas
; }
33 void SetCanvas(MyCanvas
* canvas
) { m_canvas
= canvas
; }
38 DECLARE_DYNAMIC_CLASS(MyFrame
)
44 class MyApp
: public wxApp
48 virtual bool OnInit();
54 bool TileBitmap(const wxRect
& rect
, wxDC
& dc
, wxBitmap
& bitmap
);
57 wxBitmap
& GetBackgroundBitmap() const { return (wxBitmap
&) m_background
; }
59 bool GetUseScreen() const { return m_useScreen
; }
60 void SetUseScreen(bool useScreen
) { m_useScreen
= useScreen
; }
62 void OnUseScreen(wxCommandEvent
& event
);
65 wxBitmap m_background
;
73 #define TEST_USE_SCREEN 100
78 #define TEST_DRAG_NONE 0
79 #define TEST_DRAG_START 1
80 #define TEST_DRAG_DRAGGING 2
82 class MyCanvas
: public wxScrolledWindow
85 MyCanvas( wxWindow
*parent
, wxWindowID
, const wxPoint
&pos
, const wxSize
&size
);
88 void OnPaint( wxPaintEvent
&event
);
89 void OnEraseBackground(wxEraseEvent
& event
);
90 void OnMouseEvent(wxMouseEvent
& event
);
92 void DrawShapes(wxDC
& dc
);
93 void EraseShape(DragShape
* shape
, wxDC
& dc
);
95 DragShape
* FindShape(const wxPoint
& pt
) const;
97 wxList
& GetDisplayList() { return m_displayList
; }
102 wxList m_displayList
; // A list of DragShapes
104 DragShape
* m_draggedShape
;
105 DragShape
* m_currentlyHighlighted
; // The shape that's being highlighted
106 wxPoint m_dragStartPos
;
107 wxDragImage
* m_dragImage
;
109 DECLARE_CLASS(MyCanvas
)
110 DECLARE_EVENT_TABLE()
114 // Ways to drag a shape
116 #define SHAPE_DRAG_BITMAP 1
117 #define SHAPE_DRAG_TEXT 2
118 #define SHAPE_DRAG_ICON 3
122 class DragShape
: public wxObject
125 DragShape(const wxBitmap
& bitmap
);
130 bool HitTest(const wxPoint
& pt
) const;
131 bool Draw(wxDC
& dc
, bool highlight
= false);
135 wxPoint
GetPosition() const { return m_pos
; }
136 void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
138 wxRect
GetRect() const { return wxRect(m_pos
.x
, m_pos
.y
, m_bitmap
.GetWidth(), m_bitmap
.GetHeight()); }
140 wxBitmap
& GetBitmap() const { return (wxBitmap
&) m_bitmap
; }
141 void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
143 int GetDragMethod() const { return m_dragMethod
; }
144 void SetDragMethod(int method
) { m_dragMethod
= method
; }
146 bool IsShown() const { return m_show
; }
147 void SetShow(bool show
) { m_show
= show
; }
157 // A derived class is required since we're overriding UpdateBackingFromWindow,
158 // for compatibility with Mac OS X (Core Graphics) which does not support blitting
161 class MyDragImage
: public wxDragImage
164 MyDragImage(MyCanvas
* canvas
): m_canvas(canvas
) {}
166 MyDragImage(MyCanvas
* canvas
, const wxBitmap
& image
, const wxCursor
& cursor
= wxNullCursor
):
167 wxDragImage(image
, cursor
), m_canvas(canvas
)
171 MyDragImage(MyCanvas
* canvas
, const wxIcon
& image
, const wxCursor
& cursor
= wxNullCursor
):
172 wxDragImage(image
, cursor
), m_canvas(canvas
)
176 MyDragImage(MyCanvas
* canvas
, const wxString
& str
, const wxCursor
& cursor
= wxNullCursor
):
177 wxDragImage(str
, cursor
), m_canvas(canvas
)
181 // On some platforms, notably Mac OS X with Core Graphics, we can't blit from
182 // a window, so we need to draw the background explicitly.
183 virtual bool UpdateBackingFromWindow(wxDC
& windowDC
, wxMemoryDC
& destDC
, const wxRect
& sourceRect
,
184 const wxRect
& destRect
) const;
191 // _WX_DRAGIMAGSAMPLE_