wxArt2D
recurdoc.cpp
1 /*! \file canvas/src/recur.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2001-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: recur.cpp,v 1.107 2009/09/26 20:40:32 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20 
21 #include "wx/editor/recurdoc.h"
22 #include "wx/canvas/cameleon.h"
23 #include "wx/canvas/objlist.h"
24 #include "wx/canvas/canglob.h"
25 #include "wx/canvas/drawer.h"
26 #include "wx/docview/doccom.h"
27 
28 #include <wx/wfstream.h>
29 #include <math.h>
30 
31 //----------------------------------------------------------------------------
32 // globals
33 //----------------------------------------------------------------------------
34 IMPLEMENT_DYNAMIC_CLASS( a2dCanvasDocumentReference, a2dLibraryReference )
35 IMPLEMENT_DYNAMIC_CLASS( a2dCanvasDocumentReference2, a2dCanvasObject )
36 IMPLEMENT_DYNAMIC_CLASS( a2dCanvasDocumentReferenceAsText, a2dText )
37 
38 //----------------------------------------------------------------------------
39 // a2dCanvasDocumentReference
40 //----------------------------------------------------------------------------
41 
42 a2dCanvasDocumentReference::a2dCanvasDocumentReference( double x, double y, a2dCanvasDocument* doc, double totalheight,
43  const a2dFont& font, int imagew, int imageh, a2dCanvasObject* symbol )
44  : a2dLibraryReference( x, y, doc->GetDrawing()->GetRootObject() ,
45  doc->GetFilename().GetFullName() != wxT( "" ) ? doc->GetFilename().GetFullName() : doc->GetPrintableName(),
46  totalheight, symbol, font, imagew, imageh )
47 {
48 
49  SetObjectTip( doc->GetFilename().GetFullPath(), m_height / 2 , 0, m_height / 5 );
50 
51  m_doc = doc;
52 }
53 
54 a2dCanvasDocumentReference::a2dCanvasDocumentReference( double x, double y, double totalheight, const wxFileName& filename,
55  const a2dFont& font, int imagew, int imageh, a2dCanvasObject* symbol )
56  : a2dLibraryReference( x, y, NULL, filename.GetFullName(), totalheight, symbol, font, imagew, imageh )
57 {
58 
59  SetObjectTip( filename.GetFullPath(), m_height / 2 , 0, m_height / 5 );
60 
61  m_doc = NULL;
62 }
63 
64 a2dCanvasDocumentReference::a2dCanvasDocumentReference( const a2dCanvasDocumentReference& other, CloneOptions options, a2dRefMap* refs )
65  : a2dLibraryReference( other, options, refs )
66 {
67  m_doc = other.m_doc;
68 }
69 
70 a2dCanvasDocumentReference::~a2dCanvasDocumentReference()
71 {
72 }
73 
75 {
76  return new a2dCanvasDocumentReference( *this, options, refs );
77 }
78 
80 {
81  if ( !m_flags.m_pending && m_doc->GetDrawing()->GetRootObject()->GetPending() )
82  SetPending( true );
83 }
84 
85 //----------------------------------------------------------------------------
86 // a2dCanvasDocumentReference2
87 //----------------------------------------------------------------------------
88 
89 BEGIN_EVENT_TABLE( a2dCanvasDocumentReference2, a2dCanvasObject )
90  EVT_CANVASOBJECT_MOUSE_EVENT( a2dCanvasDocumentReference2::OnCanvasObjectMouseEvent )
91 END_EVENT_TABLE()
92 
93 a2dCanvasDocumentReference2::a2dCanvasDocumentReference2( double x, double y, a2dCanvasDocument* doc )
94  : a2dCanvasObject( x, y )
95 {
96  if ( doc )
97  {
98  SetObjectTip( doc->GetFilename().GetFullPath(), 100 , 0, 100 );
99  m_fileName = wxFileName( doc->GetFilename().GetFullPath() );
100  }
101  SetURI( m_fileName.GetFullPath() );
102  m_doc = doc;
103 }
104 
105 a2dCanvasDocumentReference2::a2dCanvasDocumentReference2( double x, double y, const wxFileName& filename )
106  : a2dCanvasObject( x, y )
107 {
108 
109  SetObjectTip( filename.GetFullPath(), 100 , 0, 100 );
110  m_fileName = filename;
111  SetURI( m_fileName.GetFullPath() );
112  m_doc = NULL;
113 }
114 
115 a2dCanvasDocumentReference2::a2dCanvasDocumentReference2( const a2dCanvasDocumentReference2& other, CloneOptions options, a2dRefMap* refs )
116  : a2dCanvasObject( other, options, refs )
117 {
118  m_doc = other.m_doc;
119 }
120 
121 a2dCanvasDocumentReference2::~a2dCanvasDocumentReference2()
122 {
123 }
124 
126 {
127  return new a2dCanvasDocumentReference2( *this, options, refs );
128 }
129 
130 #if wxART2D_USE_CVGIO
131 void a2dCanvasDocumentReference2::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
132 {
133  a2dCanvasObject::DoSave( parent, out, xmlparts, towrite );
134 }
135 
136 void a2dCanvasDocumentReference2::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
137 {
138  a2dCanvasObject::DoLoad( parent, parser, xmlparts );
139 }
140 #endif //wxART2D_USE_CVGIO
141 
143 {
144  return a2dCanvasObject::DoIsHitWorld( ic, hitEvent );
145 }
146 
147 void a2dCanvasDocumentReference2::OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event )
148 {
149  //if ( !m_doc )
150  // a2dDocviewGlobals->GetDocviewCommandProcessor()->FileOpen( ( a2dDocumentPtr& ) m_doc, m_fileName );
151 
152  //else
153  // event.Skip();
154 }
155 
156 //----------------------------------------------------------------------------
157 // a2dCanvasDocumentReferenceAsText
158 //----------------------------------------------------------------------------
159 
160 BEGIN_EVENT_TABLE( a2dCanvasDocumentReferenceAsText, a2dText )
161  EVT_CANVASOBJECT_MOUSE_EVENT( a2dCanvasDocumentReferenceAsText::OnCanvasObjectMouseEvent )
162 END_EVENT_TABLE()
163 
164 a2dCanvasDocumentReferenceAsText::a2dCanvasDocumentReferenceAsText( a2dCanvasDocument* doc, double x, double y, const a2dFont& font, double angle,
165  bool up, int alignment )
166  : a2dText( wxT("not specified"), x, y, font, angle, up, alignment )
167 {
168  m_doc = doc;
169  if ( doc )
170  {
171  m_fileName = doc->GetFilename().GetFullPath();
172  }
173  m_displayShort = true;
174  m_displayExt = true;
175 
176  if ( m_displayShort && m_displayExt )
177  m_text = m_fileName.GetName();
178  else if ( m_displayShort )
179  m_text = m_fileName.GetFullName();
180  else
181  m_text = m_fileName.GetFullPath();
182 
183  wxString pathToFile = wxT( "file:///" ) + m_fileName.GetVolume() + m_fileName.GetVolumeSeparator() + m_fileName.GetPath(wxPATH_GET_SEPARATOR, wxPATH_UNIX);
184  SetURI( pathToFile + m_fileName.GetFullName() );
185  if ( doc )
186  SetObjectTip( pathToFile, 100 , 0, 100 );
187 }
188 
189 a2dCanvasDocumentReferenceAsText::a2dCanvasDocumentReferenceAsText( const wxFileName& filename, double x, double y, const a2dFont& font, double angle,
190  bool up, int alignment )
191  : a2dText( filename.GetFullPath(), x, y, font, angle, up, alignment )
192 {
193  m_fileName = filename;
194 
195  if ( m_displayShort && m_displayExt )
196  m_text = m_fileName.GetName();
197  else if ( m_displayShort )
198  m_text = m_fileName.GetFullName();
199  else
200  m_text = m_fileName.GetFullPath();
201 
202  wxString pathToFile = wxT( "file:///" ) + m_fileName.GetVolume() + m_fileName.GetVolumeSeparator() + m_fileName.GetPath(wxPATH_GET_SEPARATOR, wxPATH_UNIX);
203  SetURI( pathToFile + m_fileName.GetFullName() );
204  SetObjectTip( pathToFile, 100 , 0, 100 );
205 
206  m_doc = NULL;
207 }
208 
209 a2dCanvasDocumentReferenceAsText::a2dCanvasDocumentReferenceAsText( const a2dCanvasDocumentReferenceAsText& other, CloneOptions options, a2dRefMap* refs )
210  : a2dText( other, options, refs )
211 {
212  m_fileName = other.m_fileName;
213  m_doc = other.m_doc;
214  m_displayShort = other.m_displayShort;
215  m_displayExt = other.m_displayExt;
216 }
217 
218 a2dCanvasDocumentReferenceAsText::~a2dCanvasDocumentReferenceAsText()
219 {
220 }
221 
223 {
224  return new a2dCanvasDocumentReferenceAsText( *this, options, refs );
225 }
226 
227 #if wxART2D_USE_CVGIO
228 void a2dCanvasDocumentReferenceAsText::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
229 {
230  a2dText::DoSave( parent, out, xmlparts, towrite );
231  if ( xmlparts == a2dXmlSer_attrib )
232  {
233  out.WriteAttribute( wxT( "filename" ), m_fileName.GetFullPath() );
234  }
235  else
236  {
237  }
238 }
239 
240 void a2dCanvasDocumentReferenceAsText::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
241 {
242  a2dText::DoLoad( parent, parser, xmlparts );
243  if ( xmlparts == a2dXmlSer_attrib )
244  {
245  m_fileName = parser.GetAttributeValue( wxT( "filename" ) );
246  /* URI is saved as a property, and will give the same as this when read in a2dObject
247  wxString pathToFile = wxT( "file:///" ) + m_fileName.GetVolume() + m_fileName.GetVolumeSeparator() + m_fileName.GetPath(wxPATH_GET_SEPARATOR, wxPATH_UNIX);
248  SetURI( pathToFile + m_fileName.GetFullName() );
249  wxURI uri = GetURI();
250  wxString link = uri.BuildURI();
251  */
252  }
253  else
254  {
255  }
256 }
257 #endif //wxART2D_USE_CVGIO
258 
260 {
261  return a2dText::DoIsHitWorld( ic, hitEvent );
262 }
263 
264 void a2dCanvasDocumentReferenceAsText::OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event )
265 {
266  wxMouseEvent mouseevent = event.GetMouseEvent();
267 
268  if( mouseevent.ControlDown() && mouseevent.ShiftDown() && m_doc )
269  {
270  a2dDocumentPtr doc = m_doc.Get();
271  a2dDocviewGlobals->GetDocviewCommandProcessor()->FileOpenCheck( doc, m_fileName, true );
272  }
273  else
274  event.Skip();
275 }
276 
277 bool a2dCanvasDocumentReferenceAsText::DoStartEdit( wxUint16 editmode, wxEditStyle editstyle )
278 {
279  if ( m_flags.m_editable )
280  {
281  a2dText* original = wxStaticCast( PROPID_Original->GetPropertyValue( this ).Get(), a2dText );
282  RemoveProperty( PROPID_Objecttip );
283  m_text = m_fileName.GetFullPath();
284  return a2dText::DoStartEdit( editmode, editstyle );
285  }
286  return false;
287 }
288 
290 {
292  a2dCanvasDocumentReferenceAsText* original = wxStaticCast( PROPID_Original->GetPropertyValue( this ).Get(), a2dCanvasDocumentReferenceAsText );
293  original->m_fileName = wxFileName( m_text );
294  if ( m_displayShort && m_displayExt )
295  original->m_text = original->m_fileName.GetName();
296  else if ( m_displayShort )
297  original->m_text = original->m_fileName.GetFullName();
298  else
299  original->m_text = original->m_fileName.GetFullPath();
300 
301  wxString pathToFile = wxT( "file:///" ) + m_fileName.GetVolume() + m_fileName.GetVolumeSeparator() + m_fileName.GetPath(wxPATH_GET_SEPARATOR, wxPATH_UNIX);
302  original->SetURI( pathToFile + m_fileName.GetFullName() );
303  original->SetObjectTip( pathToFile, 100 , 0, 100 );
304 
305  wxURI uri = original->GetURI();
306  wxString link = uri.BuildURI();
307 
308 }
309 
310 bool a2dCanvasDocumentReferenceAsText::DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox )
311 {
312  if ( !m_bbox.GetValid() )
313  {
314  }
315  return a2dText::DoUpdate( mode, childbox, clipbox, propbox );
316 }
317 
bool DoUpdate(UpdateMode mode, const a2dBoundingBox &childbox, const a2dBoundingBox &clipbox, const a2dBoundingBox &propbox)
Update derived Object specific things ( mainly boundingbox)
Definition: cantext.cpp:822
virtual bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
Definition: canobj.cpp:3713
bool DoStartEdit(wxUint16 editmode, wxEditStyle editstyle)
only used for editable objects and under control of a editing tool.
Definition: recurdoc.cpp:277
void SetURI(const wxURI &url)
quickly set a property PROPID_URI
Definition: gen.cpp:1645
mouse event sent from a2dCanvasObject to itself
Definition: canglob.h:223
virtual wxString GetName() const
Returns the name of this object, if no name is given the internal id will be returned.
Definition: gen.cpp:1310
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
a2dCanvasOFlags m_flags
holds flags for objects
Definition: canobj.h:2528
a2dCanvasObject * GetRootObject() const
get the root object, which holds the objects in the document
Definition: drawing.h:521
Ref Counted base object.
Definition: gen.h:1045
bool GetPending() const
is this object pending for update?
Definition: canobj.h:1162
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
Definition: recurdoc.cpp:74
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
Load object specific CVG data.
Definition: cantext.cpp:536
bool m_pending
set when a2dCanvasObject needs an update (redraw).
Definition: candefs.h:277
to display a2dCanvasObject references
Definition: recurdoc.h:44
bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
Definition: recurdoc.cpp:259
Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc.
Definition: stylebase.h:779
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
UpdateMode
Various mode flags for Update.
Definition: canobj.h:1091
virtual void SetPending(bool pending)
set this object pending for update
Definition: canobj.cpp:2585
bool DoUpdate(UpdateMode mode, const a2dBoundingBox &childbox, const a2dBoundingBox &clipbox, const a2dBoundingBox &propbox)
Update derived Object specific things ( mainly boundingbox)
Definition: recurdoc.cpp:310
virtual bool DoStartEdit(wxUint16 editmode, wxEditStyle editstyle)
only used for editable objects and under control of a editing tool.
Definition: cantext.cpp:937
a2dDrawing * GetDrawing() const
get the root object, which holds the objects in the document.
Definition: candoc.h:418
virtual void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
Definition: canobj.cpp:5728
bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
Definition: recurdoc.cpp:142
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
Docview framework its controlling class.
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
Write object specific CVG data.
Definition: recurdoc.cpp:228
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
Definition: recurdoc.cpp:222
Io handler to iterate through a a2dDocument.
Definition: gen.h:3911
a2dText is an abstract base class.
Definition: cantext.h:93
bool GetValid() const
returns true if boundingbox is calculated properly and therefore its valid flag is set...
Definition: bbox.cpp:299
void DependencyPending(a2dWalkerIOHandler *handler)
called by to check if this object becomes pending as a result of other objects
Definition: recurdoc.cpp:79
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
Definition: recurdoc.cpp:125
#define wxStaticCast(obj, className)
The wxWindows 2.4.2 wxStaticCast is buggy. It evaluates its argument twice.
Definition: gen.h:123
bool m_editable
object can be edited
Definition: candefs.h:295
#define EVT_CANVASOBJECT_MOUSE_EVENT(func)
static event table macro for a2dCanvasObject mouse event
Definition: canglob.h:312
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
Definition: canobj.cpp:5569
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
Definition: recurdoc.cpp:131
virtual bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
Definition: cantext.cpp:597
void DoEndEdit()
only used for editable objects and under control of a editing tool.
Definition: recurdoc.cpp:289
a2dError FileOpenCheck(a2dDocumentPtr &doc, const wxFileName &file, bool checkModification)
Return existing document, or open it from file.
Definition: doccom.cpp:612
wxURI GetURI() const
quick way to get to PROPID_URI property
Definition: gen.cpp:1650
to display a2dCanvasObject references
Definition: recurdoc.h:79
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
special a2dCanvasObject to make a multi view hierachy.
a2dDocviewGlobal * a2dDocviewGlobals
a global pointer to get to global instance of important classes.
Definition: doccom.cpp:2348
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
Write object specific CVG data.
Definition: cantext.cpp:568
wxString GetAttributeValue(const wxString &attrib, const wxString &defaultv=wxT(""))
Returns the value of an attribute.
Definition: genxmlpars.cpp:450
a2dText * SetObjectTip(const wxString &tip, double x, double y, double size=30, double angle=0, const a2dFont &font=*a2dDEFAULT_CANVASFONT)
quickly set a property name OBJECTTIP
Definition: canobj.cpp:2781
Each a2dCanvasView needs to have a a2dCanvasDocument set in order to render data. ...
Definition: candoc.h:374
list for a2dCanvasObject
to display a2dCanvasObject references
Definition: recurdoc.h:122
a2dDocumentCommandProcessor * GetDocviewCommandProcessor() const
Gets a2dDocumentCommandProcessor pointer.
Definition: doccom.h:1034
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
Load object specific CVG data.
Definition: recurdoc.cpp:240
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
Definition: recurdoc.cpp:136
virtual bool RemoveProperty(const a2dPropertyId *id, bool all=true)
This function is called by a2dPropertyId to remove a property from the list.
Definition: gen.cpp:1573
the a2dDrawingPart is a a2dView specially designed for displaying parts of a a2dDrawing. It uses a a2dDrawer2D to actually redraw things from the document, by giving that a2dDrawer2D as drawing context to the document, and telling the document to redraw a certain rectangular area. At that last is what this class is for. It optimizes the areas to be redrawn after object in the document were changed. To do that it combines redraw areas to a minimal set of redrawing areas. All the administration for this and the way things will be redrawn is from this view.
basetype GetPropertyValue(const a2dObject *obj) const
Get the property value in obj.
Definition: id.inl:325
a2dLibraryReference is a symbol object, it holds a reference
Definition: recur.h:215
a2dBoundingBox m_bbox
boundingbox in world coordinates
Definition: canobj.h:2539
a2dText(const wxString &text=wxT("not specified"))
constructor
Definition: cantext.cpp:111
wxString m_text
the text to display
Definition: cantext.h:381
list of a2dObject&#39;s
Definition: gen.h:3157
CloneOptions
options for cloning
Definition: gen.h:1200
virtual void DoEndEdit()
only used for editable objects and under control of a editing tool.
Definition: cantext.cpp:1026
structure to give as parameter to member functions of a2dCanvasObject
Definition: canobj.h:252
general canvas module declarations and classes
wxEditStyle
Definition: canobj.h:109
recurdoc.cpp Source File -- Sun Oct 12 2014 17:04:23 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation