]> git.saurik.com Git - wxWidgets.git/blame - contrib/include/wx/canvas/canvas.h
attempt to fix crash in tree ctrl
[wxWidgets.git] / contrib / include / wx / canvas / canvas.h
CommitLineData
6a2c1874
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: canvas.h
3// Author: Robert Roebling
4// Created: XX/XX/XX
5// Copyright: 2000 (c) Robert Roebling
6// Licence: wxWindows Licence
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef __WXCANVAS_H__
10#define __WXCANVAS_H__
11
12#ifdef __GNUG__
13 #pragma interface "canvas.cpp"
14#endif
15
16#ifndef WX_PRECOMP
17 #include "wx/wx.h"
18#endif
19
20#include "wx/image.h"
21#include "wx/txtstrm.h"
dc16900b 22
6a2c1874
RR
23class wxCanvas;
24
25// WDR: class declarations
26
27//----------------------------------------------------------------------------
28// wxCanvasObject
29//----------------------------------------------------------------------------
30
31class wxCanvasObject: public wxEvtHandler
32{
33public:
4dbd4ee6 34 wxCanvasObject();
dc16900b 35
4dbd4ee6
RR
36 // Area occupied by object. Used for clipping, intersection,
37 // mouse enter etc. Screen coordinates
38 void SetArea( int x, int y, int width, int height );
39 void SetArea( wxRect rect );
dc16900b 40
1e1af41e
RR
41 // These are for screen output only therefore use
42 // int as coordinates.
239c1f50 43 virtual bool IsHit( int x, int y, int margin = 0 );
fcbb6b37 44 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
dc16900b 45
4dbd4ee6
RR
46 // use doubles later
47 virtual void Move( int x, int y );
dc16900b 48
1e1af41e
RR
49 // Once we have world coordinates in doubles, this will get
50 // called for every object if the world coordinate system
51 // changes (zooming).
4dbd4ee6 52 virtual void Recreate();
1e1af41e
RR
53
54 // Later...
6a2c1874 55 virtual void WriteSVG( wxTextOutputStream &stream );
dc16900b
KH
56
57 wxCanvas *GetOwner() { return m_owner; }
fcbb6b37 58 virtual void SetOwner( wxCanvas *owner ) { m_owner = owner; }
dc16900b 59
6a2c1874
RR
60 bool IsControl() { return m_isControl; }
61 bool IsVector() { return m_isVector; }
62 bool IsImage() { return m_isImage; }
63 inline int GetX() { return m_area.x; }
64 inline int GetY() { return m_area.y; }
65 inline int GetWidth() { return m_area.width; }
66 inline int GetHeight() { return m_area.height; }
67
dc16900b
KH
68 void CaptureMouse();
69 void ReleaseMouse();
70 bool IsCapturedMouse();
71
6a2c1874
RR
72protected:
73 wxCanvas *m_owner;
74 bool m_isControl;
75 bool m_isVector;
76 bool m_isImage;
fcbb6b37
KH
77
78 //relative boundingbox in parent in pixels
6a2c1874 79 wxRect m_area;
dc16900b 80
6a2c1874
RR
81 friend class wxCanvas;
82};
83
fcbb6b37
KH
84//----------------------------------------------------------------------------
85// wxCanvasObjectGroup
86//----------------------------------------------------------------------------
87
88class wxCanvasObjectGroup
89{
90public:
91 wxCanvasObjectGroup();
21840a6c 92 virtual ~wxCanvasObjectGroup();
fcbb6b37
KH
93
94 void SetOwner(wxCanvas* canvas);
95 wxCanvas *GetOwner() { return m_owner; }
96
97 virtual void Prepend( wxCanvasObject* obj );
98 virtual void Append( wxCanvasObject* obj );
99 virtual void Insert( size_t before, wxCanvasObject* obj );
100 virtual void Remove( wxCanvasObject* obj );
101
102 virtual void Recreate();
103 void DeleteContents( bool );
104 virtual void Render(int xabs, int yabs,int x, int y, int width, int height );
105 virtual void WriteSVG( wxTextOutputStream &stream );
106 virtual bool IsHit( int x, int y, int margin );
107 virtual wxCanvasObject* IsHitObject( int x, int y, int margin );
108
109 void ExtendArea(int x, int y);
110
111 inline int GetXMin() { return m_minx; }
112 inline int GetYMin() { return m_miny; }
113 inline int GetXMax() { return m_maxx; }
114 inline int GetYMax() { return m_maxy; }
115
116protected:
117 wxCanvas *m_owner;
118
119 //bounding box
120 double m_minx;
121 double m_miny;
122 double m_maxx;
123 double m_maxy;
124 bool m_validbounds;
125
126 wxList m_objects;
127
128 friend class wxCanvas;
129};
130
131//----------------------------------------------------------------------------
132// wxCanvasObjectGroupRef
133//----------------------------------------------------------------------------
134
135class wxCanvasObjectGroupRef: public wxCanvasObject
136{
137public:
138 wxCanvasObjectGroupRef(double x, double y,wxCanvasObjectGroup* group);
139
140 void SetOwner(wxCanvas* canvas);
141
142 virtual void Recreate();
143 virtual void Render(int xabs, int yabs,int x, int y, int width, int height );
144 virtual void WriteSVG( wxTextOutputStream &stream );
145 virtual bool IsHit( int x, int y, int margin );
146 void Move( int x, int y );
147
148 inline int GetPosX() { return m_x; }
149 inline int GetPosY() { return m_y; }
150
151 void ExtendArea(int x, int y);
152 virtual wxCanvasObject* IsHitObject( int x, int y, int margin );
153
154protected:
155 //position of the group
156 double m_x;
157 double m_y;
158
159 //reference to the group
160 wxCanvasObjectGroup* m_group;
161
162 //bounding box
163 double m_minx;
164 double m_miny;
165 double m_maxx;
166 double m_maxy;
167 bool m_validbounds;
168
169};
170
21544859
RR
171//----------------------------------------------------------------------------
172// wxCanvasRect
173//----------------------------------------------------------------------------
174
175class wxCanvasRect: public wxCanvasObject
176{
177public:
dc16900b 178 wxCanvasRect( double x, double y, double w, double h,
4dbd4ee6 179 unsigned char red, unsigned char green, unsigned char blue );
dc16900b 180
4dbd4ee6 181 virtual void Recreate();
dc16900b 182
fcbb6b37 183 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
21544859 184 virtual void WriteSVG( wxTextOutputStream &stream );
dc16900b 185
21544859 186private:
4dbd4ee6
RR
187 double m_x;
188 double m_y;
189 double m_width;
dc16900b 190 double m_height;
4dbd4ee6 191
21544859
RR
192 unsigned char m_red;
193 unsigned char m_green;
194 unsigned char m_blue;
195};
196
239c1f50
RR
197//----------------------------------------------------------------------------
198// wxCanvasLine
199//----------------------------------------------------------------------------
200
201class wxCanvasLine: public wxCanvasObject
202{
203public:
dc16900b 204 wxCanvasLine( double x1, double y1, double x2, double y2,
4dbd4ee6 205 unsigned char red, unsigned char green, unsigned char blue );
dc16900b 206
4dbd4ee6 207 virtual void Recreate();
dc16900b 208
fcbb6b37 209 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
239c1f50
RR
210 virtual void WriteSVG( wxTextOutputStream &stream );
211
212private:
4dbd4ee6
RR
213 double m_x1;
214 double m_y1;
215 double m_x2;
216 double m_y2;
dc16900b 217
239c1f50
RR
218 unsigned char m_red;
219 unsigned char m_green;
220 unsigned char m_blue;
221};
222
6a2c1874
RR
223//----------------------------------------------------------------------------
224// wxCanvasImage
225//----------------------------------------------------------------------------
226
227class wxCanvasImage: public wxCanvasObject
228{
229public:
4dbd4ee6
RR
230 wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
231
232 virtual void Recreate();
6a2c1874 233
fcbb6b37 234 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
6a2c1874
RR
235 virtual void WriteSVG( wxTextOutputStream &stream );
236
237private:
4dbd4ee6
RR
238 double m_x;
239 double m_y;
240 double m_width;
241 double m_height;
242
6a2c1874 243 wxImage m_image;
4dbd4ee6 244 wxImage m_tmp;
6a2c1874
RR
245};
246
3b111dbe
RR
247//----------------------------------------------------------------------------
248// wxCanvasControl
249//----------------------------------------------------------------------------
250
251class wxCanvasControl: public wxCanvasObject
252{
253public:
254 wxCanvasControl( wxWindow *control );
255 ~wxCanvasControl();
256
4dbd4ee6
RR
257 virtual void Recreate();
258
3b111dbe 259 virtual void Move( int x, int y );
3b111dbe
RR
260
261private:
262 wxWindow *m_control;
263};
264
d1f9b206
RR
265//----------------------------------------------------------------------------
266// wxCanvasText
267//----------------------------------------------------------------------------
268
269class wxCanvasText: public wxCanvasObject
270{
271public:
4dbd4ee6 272 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
d1f9b206 273 ~wxCanvasText();
dc16900b 274
4dbd4ee6 275 void Recreate();
dc16900b 276
fcbb6b37 277 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
d1f9b206
RR
278 virtual void WriteSVG( wxTextOutputStream &stream );
279
d1f9b206
RR
280 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
281 void SetFlag( int flag );
239c1f50 282 int GetFlag() { return m_flag; }
dc16900b 283
d1f9b206
RR
284private:
285 wxString m_text;
4dbd4ee6
RR
286 double m_x;
287 double m_y;
d1f9b206
RR
288 unsigned char *m_alpha;
289 void *m_faceData;
290 int m_flag;
291 int m_red;
292 int m_green;
293 int m_blue;
cb281cfc
RR
294 wxString m_fontFileName;
295 int m_size;
d1f9b206
RR
296};
297
6a2c1874
RR
298//----------------------------------------------------------------------------
299// wxCanvas
300//----------------------------------------------------------------------------
301
302class wxCanvas: public wxScrolledWindow
303{
304public:
305 // constructors and destructors
306 wxCanvas( wxWindow *parent, wxWindowID id = -1,
307 const wxPoint& pos = wxDefaultPosition,
308 const wxSize& size = wxDefaultSize,
309 long style = wxScrolledWindowStyle );
310 virtual ~wxCanvas();
dc16900b 311
6a2c1874 312 virtual void SetArea( int width, int height );
cb281cfc 313 virtual void SetColour( unsigned char red, unsigned char green, unsigned char blue );
41328253 314 virtual void Update( int x, int y, int width, int height, bool blit = TRUE );
6a2c1874 315 virtual void UpdateNow();
dc16900b 316
239c1f50
RR
317 virtual void Freeze();
318 virtual void Thaw();
dc16900b 319
6a2c1874
RR
320 virtual void Prepend( wxCanvasObject* obj );
321 virtual void Append( wxCanvasObject* obj );
322 virtual void Insert( size_t before, wxCanvasObject* obj );
323 virtual void Remove( wxCanvasObject* obj );
dc16900b 324
4dbd4ee6
RR
325 // override these to change your coordiate system ...
326 virtual int GetDeviceX( double x );
327 virtual int GetDeviceY( double y );
328 virtual int GetDeviceWidth( double width );
329 virtual int GetDeviceHeight( double height );
dc16900b 330
4dbd4ee6
RR
331 // ... and call this to tell all objets to recreate then
332 virtual void Recreate();
333
41328253
RR
334 inline wxImage *GetBuffer() { return &m_buffer; }
335 inline int GetBufferX() { return m_bufferX; }
336 inline int GetBufferY() { return m_bufferY; }
337 inline int GetBufferWidth() { return m_buffer.GetWidth(); }
338 inline int GetBufferHeight() { return m_buffer.GetHeight(); }
339
6a2c1874 340 bool NeedUpdate() { return m_needUpdate; }
1e1af41e 341 bool IsFrozen() { return m_frozen; }
dc16900b 342
3b111dbe 343 void BlitBuffer( wxDC &dc );
dc16900b
KH
344
345 void SetCaptureMouse( wxCanvasObject *obj );
346
41328253
RR
347 virtual void ScrollWindow( int dx, int dy,
348 const wxRect* rect = (wxRect *) NULL );
dc16900b 349
6a2c1874 350private:
239c1f50 351 wxImage m_buffer;
41328253
RR
352 int m_bufferX;
353 int m_bufferY;
239c1f50
RR
354 bool m_needUpdate;
355 wxList m_updateRects;
fcbb6b37
KH
356 wxCanvasObjectGroup* m_root;
357
239c1f50
RR
358 unsigned char m_green,m_red,m_blue;
359 bool m_frozen;
41328253 360 bool m_requestNewBuffer;
239c1f50 361 wxCanvasObject *m_lastMouse;
4dbd4ee6 362 wxCanvasObject *m_captureMouse;
dc16900b 363
6a2c1874 364 friend class wxCanvasObject;
dc16900b 365
6a2c1874
RR
366private:
367 void OnChar( wxKeyEvent &event );
368 void OnPaint( wxPaintEvent &event );
369 void OnMouse( wxMouseEvent &event );
370 void OnSize( wxSizeEvent &event );
371 void OnIdle( wxIdleEvent &event );
372 void OnSetFocus( wxFocusEvent &event );
373 void OnKillFocus( wxFocusEvent &event );
61b64bd9 374 void OnEraseBackground( wxEraseEvent &event );
6a2c1874
RR
375
376private:
377 DECLARE_CLASS(wxCanvas)
378 DECLARE_EVENT_TABLE()
379};
380
381
382#endif
383 // WXCANVAS
384