]> git.saurik.com Git - wxWidgets.git/blob - samples/dragimag/dragimag.h
put both versions of wxGetMousePosition in one place so they can use one implementation
[wxWidgets.git] / samples / dragimag / dragimag.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dragimag.h
3 // Purpose: wxDragImage sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 28/2/2000
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DRAGIMAGSAMPLE_
13 #define _WX_DRAGIMAGSAMPLE_
14
15 // derived classes
16
17 class MyFrame;
18 class MyApp;
19 class MyCanvas;
20 class DragShape;
21
22 // MyFrame
23
24 class MyFrame: public wxFrame
25 {
26 public:
27 MyFrame();
28
29 void OnAbout( wxCommandEvent &event );
30 void OnQuit( wxCommandEvent &event );
31
32 MyCanvas* GetCanvas() const { return m_canvas; }
33 void SetCanvas(MyCanvas* canvas) { m_canvas = canvas; }
34
35 private:
36 MyCanvas* m_canvas;
37
38 DECLARE_DYNAMIC_CLASS(MyFrame)
39 DECLARE_EVENT_TABLE()
40 };
41
42 // MyApp
43
44 class MyApp: public wxApp
45 {
46 public:
47 MyApp();
48 virtual bool OnInit();
49 virtual int OnExit();
50
51 //// Operations
52
53 // Tile the bitmap
54 bool TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap);
55
56 //// Accessors
57 wxBitmap& GetBackgroundBitmap() const { return (wxBitmap&) m_background; }
58
59 bool GetUseScreen() const { return m_useScreen; }
60 void SetUseScreen(bool useScreen) { m_useScreen = useScreen; }
61
62 void OnUseScreen(wxCommandEvent& event);
63
64 protected:
65 wxBitmap m_background;
66 bool m_useScreen;
67
68 DECLARE_EVENT_TABLE()
69 };
70
71 DECLARE_APP(MyApp)
72
73 #define TEST_USE_SCREEN 100
74
75 // MyCanvas
76
77 // Dragging modes
78 #define TEST_DRAG_NONE 0
79 #define TEST_DRAG_START 1
80 #define TEST_DRAG_DRAGGING 2
81
82 class MyCanvas: public wxScrolledWindow
83 {
84 public:
85 MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
86 ~MyCanvas();
87
88 void OnPaint( wxPaintEvent &event );
89 void OnEraseBackground(wxEraseEvent& event);
90 void OnMouseEvent(wxMouseEvent& event);
91
92 void DrawShapes(wxDC& dc);
93 void EraseShape(DragShape* shape, wxDC& dc);
94 void ClearShapes();
95 DragShape* FindShape(const wxPoint& pt) const;
96
97 wxList& GetDisplayList() { return m_displayList; }
98
99 protected:
100
101 private:
102 wxList m_displayList; // A list of DragShapes
103 int m_dragMode;
104 DragShape* m_draggedShape;
105 DragShape* m_currentlyHighlighted; // The shape that's being highlighted
106 wxPoint m_dragStartPos;
107 wxDragImage* m_dragImage;
108
109 DECLARE_CLASS(MyCanvas)
110 DECLARE_EVENT_TABLE()
111 };
112
113
114 // Ways to drag a shape
115
116 #define SHAPE_DRAG_BITMAP 1
117 #define SHAPE_DRAG_TEXT 2
118 #define SHAPE_DRAG_ICON 3
119
120 // Shape
121
122 class DragShape: public wxObject
123 {
124 public:
125 DragShape(const wxBitmap& bitmap);
126 ~DragShape(){};
127
128 //// Operations
129
130 bool HitTest(const wxPoint& pt) const;
131 bool Draw(wxDC& dc, bool highlight = false);
132
133 //// Accessors
134
135 wxPoint GetPosition() const { return m_pos; }
136 void SetPosition(const wxPoint& pos) { m_pos = pos; }
137
138 wxRect GetRect() const { return wxRect(m_pos.x, m_pos.y, m_bitmap.GetWidth(), m_bitmap.GetHeight()); }
139
140 wxBitmap& GetBitmap() const { return (wxBitmap&) m_bitmap; }
141 void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
142
143 int GetDragMethod() const { return m_dragMethod; }
144 void SetDragMethod(int method) { m_dragMethod = method; }
145
146 bool IsShown() const { return m_show; }
147 void SetShow(bool show) { m_show = show; }
148
149 protected:
150 wxPoint m_pos;
151 wxBitmap m_bitmap;
152 int m_dragMethod;
153 bool m_show;
154 };
155
156 // MyDragImage
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
159 // from a window.
160
161 class MyDragImage: public wxDragImage
162 {
163 public:
164 MyDragImage(MyCanvas* canvas): m_canvas(canvas) {}
165
166 MyDragImage(MyCanvas* canvas, const wxBitmap& image, const wxCursor& cursor = wxNullCursor):
167 wxDragImage(image, cursor), m_canvas(canvas)
168 {
169 }
170
171 MyDragImage(MyCanvas* canvas, const wxIcon& image, const wxCursor& cursor = wxNullCursor):
172 wxDragImage(image, cursor), m_canvas(canvas)
173 {
174 }
175
176 MyDragImage(MyCanvas* canvas, const wxString& str, const wxCursor& cursor = wxNullCursor):
177 wxDragImage(str, cursor), m_canvas(canvas)
178 {
179 }
180
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;
185
186 protected:
187 MyCanvas* m_canvas;
188 };
189
190 #endif
191 // _WX_DRAGIMAGSAMPLE_