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