wxArt2D
docviewref.cpp
Go to the documentation of this file.
1 /*! \file docview/src/docviewref.cpp
2  \brief Document/view classes
3  \author Julian Smart
4  \date Created 01/02/97
5 
6  Copyright: (c) Julian Smart and Markus Holzem
7 
8  Licence: wxWidgets licence
9 
10  Modified by: Klaas Holwerda
11 
12  RCS-ID: $Id: docviewref.cpp,v 1.191 2009/10/01 19:22:35 titato Exp $
13 */
14 
15 // ============================================================================
16 // declarations
17 // ============================================================================
18 
19 // ----------------------------------------------------------------------------
20 // headers
21 // ----------------------------------------------------------------------------
22 
23 #include "docviewprec.h"
24 
25 #ifdef __BORLANDC__
26 #pragma hdrstop
27 #endif
28 
29 //#if wxUSE_DOC_VIEW_ARCHITECTUR
30 
31 #ifndef WX_PRECOMP
32 #include "wx/wx.h"
33 /*
34  #include "wx/string.h"
35  #include "wx/utils.h"
36  #include "wx/app.h"
37  #include "wx/dc.h"
38  #include "wx/dialog.h"
39  #include "wx/menu.h"
40  #include "wx/list.h"
41  #include "wx/filedlg.h"
42  #include "wx/intl.h"
43  #include "wx/file.h"
44 */
45 #endif
46 
47 
48 #ifdef __WXGTK__
49 #include "wx/mdi.h"
50 #endif
51 
52 #if wxUSE_PRINTING_ARCHITECTURE
53 #include "wx/prntbase.h"
54 #include "wx/printdlg.h"
55 #endif
56 
57 #include "wx/msgdlg.h"
58 #include "wx/choicdlg.h"
59 #include "wx/confbase.h"
60 #include "wx/file.h"
61 #include "wx/cmdproc.h"
62 #include "wx/log.h"
63 #include "wx/tokenzr.h"
64 #include <wx/xrc/xmlres.h>
65 
66 #include <stdio.h>
67 #include <string.h>
68 
69 #include "wx/docview.h"
70 
71 // ----------------------------------------------------------------------------
72 // template instantiations
73 // ----------------------------------------------------------------------------
74 
75 #include "wx/docview/docviewref.h"
76 #include "wx/docview/doccom.h"
77 
78 #if wxUSE_STD_IOSTREAM
79 #include "wx/ioswrap.h"
80 #if wxUSE_IOSTREAMH
81 #include <fstream.h>
82 #else
83 #include <fstream>
84 #endif
85 #else
86 #include "wx/wfstream.h"
87 #endif
88 
89 
90 //#include "wx/general/id.inl"
91 #include "wx/general/smrtptr.inl"
92 
93 //----------------------------------------------------------------------------
94 // template instanitiations
95 //----------------------------------------------------------------------------
96 
97 // MSVC warning 4660 is quite stupid. It says that the template is already instantiated
98 // by using it, but it is not fully instantiated as required for a library
99 #ifdef _MSC_VER
100 #pragma warning(disable: 4660)
101 #endif
102 
103 //#if defined(WXDOCVIEW_USINGDLL) || defined( __UNIX__ )
104 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dView>;
105 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dDocument>;
106 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dIOHandler>;
107 template class A2DDOCVIEWDLLEXP a2dlist<class a2dSmrtPtr<class a2dDocument> >;
108 template class A2DDOCVIEWDLLEXP a2dSmrtPtrList<a2dDocument>;
109 template class A2DDOCVIEWDLLEXP a2dlist<class a2dSmrtPtr<class a2dView> >;
110 template class A2DDOCVIEWDLLEXP a2dSmrtPtrList<a2dView>;
111 template class A2DDOCVIEWDLLEXP a2dlist<class a2dSmrtPtr<class a2dDocumentTemplate> >;
112 template class A2DDOCVIEWDLLEXP a2dSmrtPtrList<a2dDocumentTemplate>;
113 template class A2DDOCVIEWDLLEXP a2dlist<class a2dSmrtPtr<class a2dViewTemplate> >;
114 template class A2DDOCVIEWDLLEXP a2dSmrtPtrList<a2dViewTemplate>;
115 //#endif
116 
117 #ifdef _MSC_VER
118 #pragma warning(default: 4660)
119 #endif
120 
121 // ----------------------------------------------------------------------------
122 // wxWindows macros
123 // ----------------------------------------------------------------------------
124 
125 IMPLEMENT_ABSTRACT_CLASS( a2dDocument, a2dObject )
126 IMPLEMENT_ABSTRACT_CLASS( a2dView, a2dObject )
127 IMPLEMENT_CLASS( a2dDocumentTemplate, wxObject )
128 IMPLEMENT_CLASS( a2dDocumentTemplateAuto, a2dDocumentTemplate )
129 IMPLEMENT_CLASS( a2dViewTemplate, wxObject )
130 
131 IMPLEMENT_ABSTRACT_CLASS( a2dViewConnector, a2dObject )
132 IMPLEMENT_ABSTRACT_CLASS( a2dFrameViewConnector, a2dViewConnector )
133 
134 IMPLEMENT_CLASS( a2dCloseViewEvent, wxEvent )
135 IMPLEMENT_CLASS( a2dDocumentEvent, wxEvent )
136 IMPLEMENT_CLASS( a2dViewEvent, wxEvent )
137 IMPLEMENT_CLASS( a2dTemplateEvent, wxEvent )
138 
139 IMPLEMENT_CLASS( a2dCloseDocumentEvent, wxCloseEvent )
140 
141 DEFINE_EVENT_TYPE( wxEVT_SIGNAL )
142 DEFINE_EVENT_TYPE( wxEVT_DISCONNECT_ALLVIEWS )
143 DEFINE_EVENT_TYPE( wxEVT_SAVE_DOCUMENT )
144 DEFINE_EVENT_TYPE( wxEVT_SAVEAS_DOCUMENT )
145 DEFINE_EVENT_TYPE( wxEVT_EXPORT_DOCUMENT )
146 DEFINE_EVENT_TYPE( wxEVT_IMPORT_DOCUMENT )
147 DEFINE_EVENT_TYPE( wxEVT_CLOSE_DOCUMENT )
148 DEFINE_EVENT_TYPE( wxEVT_OPEN_DOCUMENT )
149 DEFINE_EVENT_TYPE( wxEVT_NEW_DOCUMENT )
150 DEFINE_EVENT_TYPE( wxEVT_CREATE_DOCUMENT )
151 DEFINE_EVENT_TYPE( wxEVT_ADD_VIEW )
152 DEFINE_EVENT_TYPE( wxEVT_REMOVE_VIEW )
153 DEFINE_EVENT_TYPE( wxEVT_UPDATE_VIEWS )
154 DEFINE_EVENT_TYPE( wxEVT_ENABLE_VIEWS )
155 DEFINE_EVENT_TYPE( wxEVT_DISCONNECT_VIEW )
156 
157 DEFINE_EVENT_TYPE( wxEVT_REPORT_VIEWS )
158 DEFINE_EVENT_TYPE( wxEVT_CHANGEDFILENAME_DOCUMENT )
159 DEFINE_EVENT_TYPE( wxEVT_CHANGEDTITLE_DOCUMENT )
160 DEFINE_EVENT_TYPE( wxEVT_CHANGEDMODIFY_DOCUMENT )
161 DEFINE_EVENT_TYPE( wxEVT_POST_LOAD_DOCUMENT )
162 
163 DEFINE_EVENT_TYPE( wxEVT_CLOSE_VIEW )
164 DEFINE_EVENT_TYPE( wxEVT_CREATE_VIEW )
165 DEFINE_EVENT_TYPE( wxEVT_SET_DOCUMENT )
166 DEFINE_EVENT_TYPE( wxEVT_ACTIVATE_VIEW )
167 DEFINE_EVENT_TYPE( wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD )
168 DEFINE_EVENT_TYPE( wxEVT_ENABLE_VIEW )
169 DEFINE_EVENT_TYPE( wxEVT_CHANGEDFILENAME_VIEW )
170 DEFINE_EVENT_TYPE( wxEVT_CHANGEDTITLE_VIEW )
171 
172 DEFINE_EVENT_TYPE( wxEVT_PRE_ADD_DOCUMENT )
173 DEFINE_EVENT_TYPE( wxEVT_POST_CREATE_DOCUMENT )
174 DEFINE_EVENT_TYPE( wxEVT_POST_CREATE_VIEW )
175 
176 #if wxUSE_PRINTING_ARCHITECTURE
177 IMPLEMENT_DYNAMIC_CLASS( a2dDocumentPrintout, wxPrintout )
178 #endif
179 
180 // ----------------------------------------------------------------------------
181 // function prototypes
182 // ----------------------------------------------------------------------------
183 
184 static inline wxString FindExtension( const wxChar* path );
185 
186 // ----------------------------------------------------------------------------
187 // local constants
188 // ----------------------------------------------------------------------------
189 
190 const a2dPrintWhat a2dPRINT_Print = 1; //!< general print
191 const a2dPrintWhat a2dPRINT_Preview = 2; //!< general print preview
192 const a2dPrintWhat a2dPRINT_PrintView = 3; //!< print a2dView
193 const a2dPrintWhat a2dPRINT_PreviewView = 4; //!< preview print a2dView
194 const a2dPrintWhat a2dPRINT_PrintDocument = 5; //!< print a2dDocument
195 const a2dPrintWhat a2dPRINT_PreviewDocument = 6; //!< preview print a2dDocument
196 const a2dPrintWhat a2dPRINT_PrintSetup = 9;
197 
198 // ============================================================================
199 // implementation
200 // ============================================================================
201 
202 // ----------------------------------------------------------------------------
203 // local functions
204 // ----------------------------------------------------------------------------
205 
206 static wxString FindExtension( const wxChar* path )
207 {
208  wxString ext;
209  wxFileName::SplitPath( path, NULL, NULL, &ext );
210 
211 #ifdef __WXMSW__
212  // extension is shown in case, so why not use it that way!
213  //return ext.MakeLower();
214  return ext;
215 #else
216  return ext;
217 #endif
218 }
219 
220 // ----------------------------------------------------------------------------
221 // class a2dTemplateFlag
222 // ----------------------------------------------------------------------------
223 
224 const a2dTemplateFlagMask a2dTemplateFlag::NON = 0x00000000; /*!< no flags set */
225 const a2dTemplateFlagMask a2dTemplateFlag::VISIBLE = 0x00000001; /*!< is the template visible */
226 const a2dTemplateFlagMask a2dTemplateFlag::MARK = 0x00000002; /*!< for general use to temporary mark a template*/
227 const a2dTemplateFlagMask a2dTemplateFlag::LOAD = 0x00000004; /*!< a template for loading files*/
228 const a2dTemplateFlagMask a2dTemplateFlag::SAVE = 0x00000008; /*!< a template for saving files*/
229 const a2dTemplateFlagMask a2dTemplateFlag::IMPORTING = 0x00000010; /*!< a template for importing files*/
230 const a2dTemplateFlagMask a2dTemplateFlag::EXPORTING = 0x00000020; /*!< a template for exporting files*/
231 const a2dTemplateFlagMask a2dTemplateFlag::ALL = 0x00000040; /*!< all flags set */
232 const a2dTemplateFlagMask a2dTemplateFlag::DEFAULT = a2dTemplateFlag::VISIBLE |
233  a2dTemplateFlag::LOAD | a2dTemplateFlag::SAVE | a2dTemplateFlag::IMPORTING | a2dTemplateFlag::EXPORTING; /*!< default */
234 const a2dTemplateFlagMask a2dTemplateFlag::LOAD_IMPORT = a2dTemplateFlag::VISIBLE |
235  a2dTemplateFlag::LOAD | a2dTemplateFlag::IMPORTING; /*!< for load + import */
236 const a2dTemplateFlagMask a2dTemplateFlag::SAVE_EXPORT = a2dTemplateFlag::VISIBLE |
237  a2dTemplateFlag::SAVE | a2dTemplateFlag::EXPORTING; /*!< for save + export */
238 
239 a2dTemplateFlag::a2dTemplateFlag( a2dTemplateFlagMask newmask )
240 {
241  SetFlags( newmask );
242 }
243 
245 {
246  if ( mask == a2dTemplateFlag::NON )
247  return true;
248  if ( mask == a2dTemplateFlag::ALL )
249  return true;
250 
251  //check the bits in the mask, is set, the corresponding bit in m_flags must be true.
252  if ( 0 < ( mask & a2dTemplateFlag::VISIBLE ) && !m_visible ) return false;
253  if ( 0 < ( mask & a2dTemplateFlag::MARK ) && !m_mark ) return false;
254  if ( 0 < ( mask & a2dTemplateFlag::LOAD ) && !m_load ) return false;
255  if ( 0 < ( mask & a2dTemplateFlag::SAVE ) && !m_save ) return false;
256  if ( 0 < ( mask & a2dTemplateFlag::IMPORTING ) && !m_import ) return false;
257  if ( 0 < ( mask & a2dTemplateFlag::EXPORTING ) && !m_export ) return false;
258 
259  return true;
260 }
261 
262 void a2dTemplateFlag::SetFlags( a2dTemplateFlagMask which )
263 {
264  if ( which == a2dTemplateFlag::ALL )
265  {
266  m_visible = true;
267  m_mark = true;
268  m_load = true;
269  m_save = true;
270  m_import = true;
271  m_export = true;
272 
273  return;
274  }
275 
276  m_visible = 0 < ( which & a2dTemplateFlag::VISIBLE );
277  m_mark = 0 < ( which & a2dTemplateFlag::MARK );
278  m_load = 0 < ( which & a2dTemplateFlag::LOAD );
279  m_save = 0 < ( which & a2dTemplateFlag::SAVE );
280  m_import = 0 < ( which & a2dTemplateFlag::IMPORTING );
281  m_export = 0 < ( which & a2dTemplateFlag::EXPORTING );
282 
283 }
284 
285 a2dTemplateFlagMask a2dTemplateFlag::GetFlags() const
286 {
288 
289  if ( m_visible ) oflags = oflags | a2dTemplateFlag::VISIBLE;
290  if ( m_mark ) oflags = oflags | a2dTemplateFlag::MARK;
291  if ( m_load ) oflags = oflags | a2dTemplateFlag::LOAD;
292  if ( m_save ) oflags = oflags | a2dTemplateFlag::SAVE;
293  if ( m_import ) oflags = oflags | a2dTemplateFlag::IMPORTING;
294  if ( m_export ) oflags = oflags | a2dTemplateFlag::EXPORTING;
295 
296  return oflags;
297 }
298 
299 bool a2dTemplateFlag::GetFlag( a2dTemplateFlagMask which ) const
300 {
301  switch ( which )
302  {
303  case a2dTemplateFlag::VISIBLE: return m_visible;
304  case a2dTemplateFlag::MARK: return m_mark;
305  case a2dTemplateFlag::LOAD: return m_load;
306  case a2dTemplateFlag::SAVE: return m_save;
307  case a2dTemplateFlag::IMPORTING: return m_import;
308  case a2dTemplateFlag::EXPORTING: return m_export;
309  default:
310  wxFAIL_MSG( wxT( "This Flag not implemented" ) );
311  return false;
312  }
313  return false;
314 }
315 
316 // ----------------------------------------------------------------------------
317 // Definition of a2dDocument
318 // ----------------------------------------------------------------------------
319 
320 BEGIN_EVENT_TABLE( a2dDocument, a2dObject )
321  EVT_CLOSE_VIEW( a2dDocument::OnCloseView )
322  EVT_ADD_VIEW( a2dDocument::OnAddView )
323  EVT_REMOVE_VIEW( a2dDocument::OnRemoveView )
324  EVT_CLOSE_DOCUMENT( a2dDocument::OnCloseDocument )
325  EVT_OPEN_DOCUMENT( a2dDocument::OnOpenDocument )
326  EVT_SAVE_DOCUMENT( a2dDocument::OnSaveDocument )
327  EVT_SAVEAS_DOCUMENT( a2dDocument::OnSaveAsDocument )
328  EVT_EXPORT_DOCUMENT( a2dDocument::OnExportDocument )
329  EVT_IMPORT_DOCUMENT( a2dDocument::OnImportDocument )
330  EVT_NEW_DOCUMENT( a2dDocument::OnNewDocument )
331  EVT_CREATE_DOCUMENT( a2dDocument::OnCreateDocument )
332 END_EVENT_TABLE()
333 
334 
336 {
337  m_askSaveWhenOwned = true;
338 
339  m_documentModified = 0;
340  m_documentParent = parent;
341  m_commandProcessor = ( a2dCommandProcessor* ) NULL;
342 
343  m_documentTitle = wxT( "" );
344 
345  m_documentTypeName = wxT( "" );
346  m_documentFile = wxFileName();
347 
348  m_savedYet = false;
349  m_isClosed = false;
350  m_id = wxNewId();
351  m_lastError = a2dError_NoError;
352  m_modificationtime = wxDateTime::Now();
353 }
354 
356  : a2dObject()
357 {
359 
363  m_documentModified = 0;
366  m_savedYet = other.m_savedYet;
367  m_isClosed = other.m_isClosed;
368  m_id = wxNewId();
371 }
372 
374 {
375  return;
376 }
377 
379 {
381  DeleteContents();
382 }
383 
385 {
386  return new a2dDocument( *this );
387 }
388 
389 a2dObject* a2dDocument::SmrtPtrOwn()
390 {
391  m_refcount++;
392  return this;
393 }
394 
395 bool a2dDocument::SmrtPtrRelease()
396 {
397  m_refcount--;
398 
399  if ( m_refcount <= 0 )
400  {
402  }
403 
404  wxASSERT_MSG( m_refcount >= 0, wxT( "a2dDocument::Release Negative reference count" ) );
405  if ( m_refcount <= 0 )
406  {
407  delete this;
408  return true;
409  }
410  return false;
411 }
412 
413 void a2dDocument::OnCloseView( a2dCloseViewEvent& event )
414 {
415  //a2dView* viewtoclose = (a2dView*) event.GetEventObject();
416 
417  if ( m_refcount == 1 || m_askSaveWhenOwned ) //will become zero when view is allowed to close.
418  {
419  if ( SaveModifiedDialog() != wxCANCEL )//default ask user to save or not.
420  {
421  //if saved or not, that is what the users wants.
422  //Still the view will be closed.
423  }
424  else if ( event.CanVeto() )
425  event.Veto();
426  }
427 }
428 
429 void a2dDocument::OnRemoveView( a2dDocumentEvent& event )
430 {
431  //a2dView* viewtoremove = (a2dView*) event.GetView();
432 
433  if ( m_refcount == 1 || m_askSaveWhenOwned ) //refcount will become zero
434  {
435  if ( SaveModifiedDialog() != wxCANCEL )//default ask user to save or not.
436  {
437  //if saved or not, that is what the users wants.
438  //Still the view will be removed
439  }
440  else
441  event.Veto();
442  }
443 }
444 
445 void a2dDocument::OnAddView( a2dDocumentEvent& event )
446 {
447 }
448 
450 {
451  a2dDocumentEvent eventremoveall( wxEVT_DISCONNECT_ALLVIEWS, m_documentFile );
452  eventremoveall.SetEventObject( this );
453 
454  ProcessEvent( eventremoveall );
455 }
456 
457 bool a2dDocument::Close( bool force )
458 {
459  //prevent recursive calls
460  if ( m_isClosed )
461  return true; //was already closed
462 
463  m_isClosed = true;
464 
465  a2dCloseDocumentEvent event( m_id );
466  event.SetEventObject( this );
467  event.SetCanVeto( !force );
468 
469  // return false if window wasn't closed because the application vetoed the
470  // close event
471  if ( ProcessEvent( event ) && !event.GetVeto() )
472  {
473  return true;
474  }
475  m_isClosed = false;
476  return false;
477 }
478 
479 void a2dDocument::OnCloseDocument( a2dCloseDocumentEvent& event )
480 {
481  if ( SaveModifiedDialog( event.CanVeto() ) != wxCANCEL ) //default ask user to save or not.
482  {
483  //emptying a document while other views are using it, is dangerous.
484  //views may refer or use object in the document.
485  //Therefore only clear the contents when there or no more references to the document.
486  //Remember a view also Owns a reference to a document, so certainly all views need to be gone.
488 
490  DeleteContents();
491  //undo stack can hold Owners to Documents etc.
492  if ( GetCommandProcessor() )
494  Modify( false );
495  }
496  else if ( event.CanVeto() )
497  event.Veto();
498  else
499  wxFAIL_MSG( wxT( "You can not Cancel this Close Document event" ) );
500 }
501 
502 void a2dDocument::OnNewDocument( a2dDocumentEvent& WXUNUSED( event ) )
503 {
504  m_isClosed = false;
505  Modify( false );
506  SetDocumentSaved( false );
507 
508  wxString name = wxT( "" );
510 
511  SetTitle( name );
512 
513  //set file name for views and document
514  SetFilename( name, true );
515 }
516 
518 {
519  a2dDocumentEvent event( wxEVT_SAVE_DOCUMENT, m_documentFile );
520  event.SetFileName( m_documentFile );
521  event.SetEventObject( this );
522 
523  if ( ProcessEvent( event ) && event.IsAllowed() )
524  {
525  return true;
526  }
527  return false;
528 }
529 
530 bool a2dDocument::SaveAs( const wxFileName& fileTosaveTo, a2dDocumentFlagMask flags )
531 {
532  wxString filename = fileTosaveTo.GetFullPath();
533  a2dDocumentEvent event( wxEVT_SAVEAS_DOCUMENT, filename.IsEmpty() ? m_documentFile : fileTosaveTo, flags );
534 
535  event.SetEventObject( this );
536 
537  if ( ProcessEvent( event ) && event.IsAllowed() )
538  {
539  return true;
540  }
541  return false;
542 }
543 
544 void a2dDocument::OnSaveAsDocument( a2dDocumentEvent& event )
545 {
546  a2dDocumentTemplate* docTemplate = GetDocumentTemplate();
547  if ( ! docTemplate )
548  {
550  event.Veto();
552  return;
553  }
554 
555  //wxString fullname = event.GetFileName().GetFullPath();
556  wxString fullname = event.GetFileName().GetFullName();
557  wxString filter = docTemplate->GetDescription()
558  + wxT( " (" ) << docTemplate->GetFileFilter() << wxT( ") |" )
559  << docTemplate->GetFileFilter();
560 
561  if ( !( event.GetFlags() & a2dREFDOC_SILENT ) )
562  {
563  fullname = wxFileSelector( _( "Save as" ),
564  docTemplate->GetDirectory(),
565  fullname,
566  docTemplate->GetDefaultExtension(),
567  filter,
568  wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
570 
571  if ( fullname.IsEmpty() )
572  {
573  event.Veto();
574  return;
575  }
576  }
577 
578  wxString ext;
579  wxFileName::SplitPath( fullname, NULL, NULL, &ext );
580 
581  if ( ext.IsEmpty() )
582  {
583  fullname += wxT( "." );
584  fullname += docTemplate->GetDefaultExtension();
585  }
586 
587 #if wxUSE_STD_IOSTREAM
588  a2dDocumentFileOutputStream store( fullname.mb_str(), wxSTD ios_base::out | wxSTD ios_base::binary );
589  if ( store.fail() || store.bad() )
590  {
591  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for saving" ), fullname.c_str() );
592  // Saving error
593  event.Veto();
595  return;
596  }
597 #else
598  wxFileOutputStream storeUnbuf( fullname );
599  if ( storeUnbuf.GetLastError() != wxSTREAM_NO_ERROR )
600  {
601  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for saving" ), fullname.c_str() );
602  // Saving error
603  event.Veto();
605  return;
606  }
607  wxBufferedOutputStream store( storeUnbuf );
608 #endif
609 
610  wxBusyCursor wait;
612 
613  a2dIOHandlerStrOut* handler = docTemplate->GetDocumentIOHandlerForSave( fullname, this );
614  handler->SetFileName( fullname );
615  SaveObject( store, handler );
616 
617  if ( m_lastError != a2dError_NoError )
618  {
619  a2dDocviewGlobals->ReportErrorF( a2dError_SaveFile, _( "Sorry, could not save document to file %s" ), fullname.c_str() );
620  // Saving error
621  event.Veto();
622  event.SetError( m_lastError );
623  return;
624  }
625  Modify( false );
626 
627  // Inform events of changed filename, too
628  SetFilename( fullname, true );
629  SetDocumentSaved( true );
630 }
631 
632 void a2dDocument::OnSaveDocument( a2dDocumentEvent& event )
633 {
634  wxString filetosave = event.GetFileName().GetFullPath();
635 
636  if ( !IsModified() && m_savedYet )
637  {
638  event.Veto();
639  return;
640  }
641 
642  if ( filetosave.IsEmpty() || !m_savedYet )
643  {
644  if ( !SaveAs() )
645  event.Veto();
646  return;
647  }
648 
649 #if wxUSE_STD_IOSTREAM
650  a2dDocumentFileOutputStream store( filetosave.mb_str(), wxSTD ios_base::out | wxSTD ios_base::binary );
651  if ( store.fail() || store.bad() )
652  {
653  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for saving." ), filetosave.c_str() );
654  // Saving error
655  event.Veto();
657  return;
658  }
659 #else
660  wxFileOutputStream storeUnbuf( filetosave );
661  if ( storeUnbuf.GetLastError() != wxSTREAM_NO_ERROR )
662  {
663  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for saving." ), filetosave.c_str() );
664  // Saving error
665  event.Veto();
667  return;
668  }
669  wxBufferedOutputStream store( storeUnbuf );
670 #endif
671 
672  if ( ! GetDocumentTemplate() )
673  {
675  event.Veto();
677  return;
678  }
679 
680  wxBusyCursor wait;
682 
683  a2dIOHandlerStrOut* handler = m_documentTemplate->GetDocumentIOHandlerForSave( filetosave, this );
684  handler->SetFileName( filetosave );
685  SaveObject( store, handler );
686 
687  if ( m_lastError != a2dError_NoError )
688  {
689  a2dDocviewGlobals->ReportErrorF( a2dError_SaveFile, _( "Sorry, could not save document to file %s" ), filetosave.c_str() );
690  // Saving error
691  event.Veto();
692  event.SetError( m_lastError );
693  return;
694  }
695  Modify( false );
696  SetFilename( filetosave );
697  SetDocumentSaved( true );
698 }
699 
700 bool a2dDocument::Export( a2dDocumentTemplate* doctemplate, const wxFileName& fileTosaveTo, a2dDocumentFlagMask flags )
701 {
702  wxString filename = fileTosaveTo.GetFullPath();
703  a2dDocumentEvent event( wxEVT_EXPORT_DOCUMENT, doctemplate, filename.IsEmpty() ? m_documentFile : fileTosaveTo, flags );
704  event.SetEventObject( this );
705 
706  if ( ProcessEvent( event ) && event.IsAllowed() )
707  {
708  return true;
709  }
710  return false;
711 }
712 
713 void a2dDocument::OnExportDocument( a2dDocumentEvent& event )
714 {
715  a2dDocumentTemplate* docTemplate = event.GetDocumentTemplate();
716  wxString path = event.GetFileName().GetFullPath();
717  if ( !docTemplate )
718  {
719  a2dDocviewGlobals->ReportErrorF( a2dError_NoDocTemplateRef, _( "Sorry, no document template for %s export." ), path.c_str() );
720  // Export error
721  event.Veto();
723  return;
724  }
725 
726  if ( path.IsEmpty() )
727  {
728  event.Veto();
729  return;
730  }
731 
732  wxBusyCursor wait;
733 
734  wxString fileName( path );
735  wxString name, ext;
736  wxFileName::SplitPath( fileName, & path, & name, & ext );
737 
738  if ( ext.IsEmpty() || ext == wxT( "" ) )
739  {
740  fileName += wxT( "." );
741  fileName += docTemplate->GetDefaultExtension();
742  }
743 
744 #if wxUSE_STD_IOSTREAM
745  a2dDocumentFileOutputStream store( fileName.mb_str(), wxSTD ios_base::out | wxSTD ios_base::binary );
746  if ( store.fail() || store.bad() )
747  {
748  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for export." ), fileName.c_str() );
749  // Export error
750  event.Veto();
752  return;
753  }
754 #else
755  wxFileOutputStream storeUnbuf( fileName );
756  if ( storeUnbuf.GetLastError() != wxSTREAM_NO_ERROR )
757  {
758  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for export." ), fileName.c_str() );
759  // Export error
760  event.Veto();
762  return;
763  }
764  wxBufferedOutputStream store( storeUnbuf );
765 #endif
767 
768  a2dIOHandlerStrOut* handler = docTemplate->GetDocumentIOHandlerForSave( fileName, this );
769  if ( handler )
770  {
771  handler->SetFileName( fileName );
772  SaveObject( store, handler );
773  }
774  else
775  a2dDocviewGlobals->ReportErrorF( a2dError_ExportFile, _( "could not export document to file, no io handler %s" ), fileName.c_str() );
776  if ( m_lastError != a2dError_NoError )
777  {
778  a2dDocviewGlobals->ReportErrorF( a2dError_ExportFile, _( "Sorry, could not export document to file %s" ), fileName.c_str() );
779  // export error
780  event.Veto();
781  event.SetError( m_lastError );
782  return;
783  }
784 }
785 
786 bool a2dDocument::Import( a2dDocumentTemplate* doctemplate, const wxFileName& fileToImport, a2dDocumentFlagMask flags )
787 {
788  wxString filename = fileToImport.GetFullPath();
789  a2dDocumentEvent event( wxEVT_IMPORT_DOCUMENT, doctemplate, filename, flags );
790  event.SetEventObject( this );
791 
792  if ( ProcessEvent( event ) && event.IsAllowed() )
793  {
794  return true;
795  }
796  return false;
797 }
798 
799 void a2dDocument::OnImportDocument( a2dDocumentEvent& event )
800 {
801  a2dDocumentTemplate* docTemplate = event.GetDocumentTemplate();
802 
803  wxFileName file = event.GetFileName();
804  wxString path = file.GetFullPath();
805 
806  if ( !docTemplate )
807  {
808  a2dDocviewGlobals->ReportErrorF( a2dError_NoDocTemplateRef, _( "Sorry, no document template for %s import." ), path.c_str() );
809  event.Veto();
811  return;
812  }
813 
814  if ( path.IsEmpty() )
815  {
816  event.Veto();
818  return;
819  }
820 
821  wxString fileName( path );
822  wxString name, ext;
823  wxFileName::SplitPath( fileName, & path, & name, & ext );
824 
825  if ( ext.IsEmpty() )
826  {
827  fileName += wxT( "." );
828  fileName += docTemplate->GetDefaultExtension();
829  }
830 
831  wxBusyCursor wait;
832 
833 #if wxUSE_STD_IOSTREAM
834  a2dDocumentFileInputStream store( fileName.mb_str(), wxSTD ios_base::in | wxSTD ios_base::binary );
835  if ( store.fail() || store.bad() )
836  {
837  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for import" ), fileName.c_str() );
838  event.Veto();
840  return;
841  }
842 #else
843  wxFileInputStream storeUnbuf( fileName );
844  if ( !storeUnbuf.Ok() )
845  {
846  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for import" ), fileName.c_str() );
847  event.Veto();
849  return;
850  }
851  wxBufferedInputStream store( storeUnbuf );
852 #endif
853 
854  a2dIOHandlerStrIn* handler = docTemplate->GetDocumentIOHandlerForLoad( store, this );
855 
857  handler->SetFileName( path );
858 
859 #if wxUSE_STD_IOSTREAM
860  LoadObject( store, handler );
861  if ( m_lastError != a2dError_NoError || ( !store && !store.eof() ) )
862 #else
863  int res = LoadObject( store, handler ).GetLastError();
864  if ( m_lastError != a2dError_NoError || ( ( res != wxSTREAM_NO_ERROR ) && ( res != wxSTREAM_EOF ) ) )
865 #endif
866  {
867  a2dDocviewGlobals->ReportErrorF( a2dError_ExportFile, _( "template I/O handler not capable of importing this format from file %s" ), fileName.c_str() );
868  event.Veto();
869  event.SetError( m_lastError );
870  }
871  UpdateAllViews();
872 }
873 
874 void a2dDocument::OnOpenDocument( a2dDocumentEvent& event )
875 {
876  wxFileName file = event.GetFileName();
877 
878  if ( SaveModifiedDialog() == wxCANCEL )
879  {
880  event.Veto();
881  event.SetError( a2dError_Canceled );
882  return;
883  }
884 
885 #if wxUSE_STD_IOSTREAM
886  a2dDocumentFileInputStream store( file.GetFullPath().mb_str(), wxSTD ios_base::in | wxSTD ios_base::binary );
887  if ( store.fail() || store.bad() )
888  {
889  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for loading" ), file.GetFullPath().c_str() );
890  event.Veto();
892 
893  return;
894  }
895 #else
896  wxFileInputStream storeUnbuf( file.GetFullPath() );
897  if ( !storeUnbuf.Ok() )
898  {
899  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for loading" ), file.GetFullPath().c_str() );
900  event.Veto();
902  return;
903  }
904  wxBufferedInputStream store( storeUnbuf );
905 #endif
907  {
909  event.Veto();
911  return;
912  }
913 
915 
916  wxBusyCursor wait;
917 
919  handler->SetFileName( file.GetFullPath() );
920 
921 #if wxUSE_STD_IOSTREAM
922  LoadObject( store, handler );
923  if ( m_lastError != a2dError_NoError || ( !store && !store.eof() ) )
924 #else
925 
926  int res = LoadObject( store, handler ).GetLastError();
927  if ( m_lastError != a2dError_NoError || ( ( res != wxSTREAM_NO_ERROR ) && ( res != wxSTREAM_EOF ) ) )
928 #endif
929  {
930  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not Load file %s" ), file.GetFullPath().c_str() );
931  event.Veto();
932  event.SetError( m_lastError );
933  }
934  SetFilename( file, true );
935  Modify( false );
936  m_savedYet = true;
937  m_isClosed = false;
938 
939  UpdateAllViews();
940 }
941 
943 {
944 #if wxUSE_STD_IOSTREAM
945  int isOK = ( stream.fail() || stream.bad() ) == 0;
946 #else
947  int isOK = stream.IsOk ();
948 #endif
949 
950  bool oke = false;
951  if ( isOK )
952  {
953  if ( handler )
954  {
955  if ( handler->CanLoad( stream, this, m_documentTemplate ? m_documentTemplate->GetDocumentClassInfo() : NULL ) )
956  {
957  if ( !handler->Load( stream, this ) )
958  {
961  }
962  else
963  {
964  oke = true;
965  a2dDocumentEvent event( wxEVT_POST_LOAD_DOCUMENT );
966  event.SetEventObject( this );
967  ProcessEvent( event );
968  }
969  }
970  else
971  {
974  }
975  }
976  else
977  {
978  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "I/O handler must be != NULL, maybe template I/O handler not available in document template." ) );
980  }
981  }
982  else
983  {
986  }
987 
988  return stream;
989 }
990 
991 #if wxART2D_USE_CVGIO
992 void a2dDocument::Load( wxObject* WXUNUSED( parent ), a2dIOHandlerXmlSerIn& parser )
993 {
994  parser.Next();
995  parser.Require( START_TAG, wxT( "cvg" ) );
996  parser.Next();
997  if ( parser.GetName() == wxT( "title" ) )
998  {
999  m_documentTitle = parser.GetContent();
1000  parser.Next();
1001  parser.Require( END_TAG, wxT( "title" ) );
1002  parser.Next();
1003  }
1004 
1005  parser.Require( END_TAG, wxT( "cvg" ) );
1006 }
1007 
1008 void a2dDocument::Save( wxObject* WXUNUSED( parent ), a2dIOHandlerXmlSerOut& out, a2dObjectList* WXUNUSED( towrite ) )
1009 {
1010  out.WriteStartDocument( wxT( "1.0" ), wxT( "UTF-8" ) , true );
1011 
1012  out.WriteStartElementAttributes( wxT( "cvg" ) );
1013  out.WriteAttribute( wxT( "classname" ), GetClassInfo()->GetClassName() );
1014  out.WriteEndAttributes();
1015 
1016  out.WriteElement( wxT( "title" ), GetPrintableName() );
1017 
1018  out.WriteEndElement();
1019 }
1020 
1021 
1022 void a2dDocument::Save( a2dIOHandlerXmlSerOut& out, wxObject* WXUNUSED( start ) )
1023 {
1024  out.WriteStartDocument( wxT( "1.0" ), wxT( "UTF-8" ) , true );
1025 
1026  out.WriteStartElementAttributes( wxT( "cvg" ) );
1027  out.WriteAttribute( wxT( "classname" ), GetClassInfo()->GetClassName() );
1028  out.WriteEndAttributes();
1029 
1030  out.WriteElement( wxT( "title" ), GetPrintableName() );
1031 
1032  out.WriteEndElement();
1033 }
1034 
1035 #endif //wxART2D_USE_CVGIO
1036 
1038 {
1039 #if wxUSE_STD_IOSTREAM
1040  int isOK = ( stream.fail() || stream.bad() ) == 0;
1041 #else
1042  int isOK = stream.IsOk ();
1043 #endif
1044 
1045  if ( isOK )
1046  {
1047  if ( handler )
1048  {
1049  if ( handler->CanSave( this ) )
1050  {
1051  if ( !handler->Save( stream, this ) )
1052  {
1055  }
1056  }
1057  else
1058  {
1059  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "I/O handler cannot save document" ) );
1061  }
1062  }
1063  else
1064  {
1065  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "I/O handler must be != NULL, maybe not available in template" ) );
1067  }
1068  }
1069  else
1070  {
1073  }
1074 
1075  return stream;
1076 }
1077 
1079 {
1080  return false;
1081 }
1082 
1083 
1084 // Get title, or filename if no title, else unnamed
1086 {
1087  if ( m_documentTitle != wxT( "" ) )
1088  {
1089  return m_documentTitle;
1090  }
1091  else if ( m_documentFile.GetFullPath() != wxT( "" ) )
1092  {
1093  return m_documentFile.GetFullPath();
1094  }
1095  else
1096  {
1097  return _( "unnamed" );
1098  }
1099 }
1100 
1102 {
1103  return wxTheApp->GetTopWindow();
1104 }
1105 
1106 
1108 {
1110  // the next signals look like a good idea to always get from the document
1111  // its command processor.
1112  m_commandProcessor->ConnectEvent( wxEVT_MENUSTRINGS, this );
1113  m_commandProcessor->ConnectEvent( wxEVT_DO, this );
1114  m_commandProcessor->ConnectEvent( wxEVT_UNDO, this );
1115  m_commandProcessor->ConnectEvent( wxEVT_REDO, this );
1116 }
1117 
1118 int a2dDocument::SaveModifiedDialog( bool canCancel )
1119 {
1120  if ( IsModified() )
1121  {
1122  wxString title = _( "unnamed" );
1123 
1124  if ( !m_documentFile.GetFullPath().IsEmpty() )
1125  title = m_documentFile.GetFullPath();
1126 
1127  wxString msgTitle;
1128  if ( wxTheApp->GetAppName() != wxT( "" ) )
1129  msgTitle = wxTheApp->GetAppName();
1130  else
1131  msgTitle = _( "Warning" );
1132 
1133  wxString prompt;
1134  prompt.Printf( _( "Do you want to save changes to document %s?" ),
1135  ( const wxChar* )title );
1136 
1137  int res = wxMessageBox( prompt, msgTitle,
1138  canCancel ? wxYES_NO | wxCANCEL | wxICON_QUESTION : wxYES_NO | wxICON_QUESTION,
1139  GetAssociatedWindow() );
1140 
1141  if ( res == wxNO )
1142  {
1143  Modify( false );
1144  return wxNO;
1145  }
1146  else if ( res == wxYES )
1147  {
1148  if ( Save() )
1149  return wxYES;
1150  else
1151  return wxCANCEL;
1152  }
1153  else if ( res == wxCANCEL )
1154  return wxCANCEL;
1155  }
1156  return wxNO;
1157 }
1158 
1159 bool a2dDocument::Draw( wxDC& WXUNUSED( context ) )
1160 {
1161  return true;
1162 }
1163 
1164 void a2dDocument::OnCreateDocument( a2dDocumentEvent& WXUNUSED( event ) )
1165 {
1166 }
1167 
1168 void a2dDocument::Modify( bool mod )
1169 {
1170  if ( mod )
1172  else
1173  m_documentModified = 0;
1174  a2dDocumentEvent event( wxEVT_CHANGEDMODIFY_DOCUMENT );
1175  event.SetEventObject( this );
1176  ProcessEvent( event );
1177 }
1178 
1180 {
1181  a2dDocumentEvent event( wxEVT_REPORT_VIEWS, allviews );
1182  event.SetEventObject( this );
1183  ProcessEvent( event );
1184 }
1185 
1186 void a2dDocument::UpdateAllViews( a2dView* sender, unsigned int hint, wxObject* objecthint )
1187 {
1188  a2dDocumentEvent event( wxEVT_UPDATE_VIEWS, sender );
1189  event.SetEventObject( this );
1190  event.SetUpdateHint( hint );
1191  event.SetUpdateObject( objecthint );
1192  ProcessEvent( event );
1193 }
1194 
1195 void a2dDocument::EnableAllViews( bool enable, a2dView* sender )
1196 {
1197  a2dDocumentEvent event( wxEVT_ENABLE_VIEWS, sender, enable );
1198  event.SetEventObject( this );
1199  ProcessEvent( event );
1200 }
1201 
1202 void a2dDocument::SetFilename( const wxFileName& filename, bool notifyViews )
1203 {
1204  //if (m_documentFile != filename)
1205  {
1206  m_documentFile = filename;
1207  if ( notifyViews )
1208  {
1209  a2dDocumentEvent event( wxEVT_CHANGEDFILENAME_DOCUMENT, m_documentFile, ( a2dDocumentFlagMask ) a2dREFDOC_NON, m_id );
1210  event.SetEventObject( this );
1211  ProcessEvent( event );
1212  }
1213  }
1214 }
1215 
1216 void a2dDocument::SetTitle( const wxString& title, bool notifyViews )
1217 {
1218  //if (m_documentTitle != title)
1219  {
1220  m_documentTitle = title;
1221  if ( notifyViews )
1222  {
1223  a2dDocumentEvent event( wxEVT_CHANGEDTITLE_DOCUMENT, m_documentFile, ( a2dDocumentFlagMask ) a2dREFDOC_NON, m_id );
1224  event.SetEventObject( this );
1225  ProcessEvent( event );
1226  }
1227  }
1228 }
1229 
1230 // ----------------------------------------------------------------------------
1231 // Document view
1232 // ----------------------------------------------------------------------------
1233 
1234 BEGIN_EVENT_TABLE( a2dView, a2dObject )
1235  EVT_CLOSE_VIEW( a2dView::OnCloseView )
1236  EVT_CHANGEDFILENAME_DOCUMENT( a2dView::OnChangeFilename )
1237  EVT_CHANGEDTITLE_DOCUMENT( a2dView::OnChangeTitle )
1238  EVT_ENABLE_VIEW( a2dView::OnEnable )
1239  EVT_UPDATE_VIEWS( a2dView::OnUpdate )
1240  EVT_ENABLE_VIEWS( a2dView::OnEnableViews )
1241  EVT_REPORT_VIEWS( a2dView::OnReport )
1242  EVT_DISCONNECT_ALLVIEWS( a2dView::OnDisConnectView )
1243 END_EVENT_TABLE()
1244 
1245 a2dView::a2dView()
1246 {
1247  m_display = NULL;
1248 
1249  m_id = wxNewId();
1250 
1251  m_isClosed = false;
1252 
1253  m_viewDocument = ( a2dDocument* ) NULL;
1254 
1255  m_viewTypeName = wxT( "" );
1256 
1257  m_active = false;
1258 
1259  m_viewEnabled = true;
1260 
1261  //! the view owns itself until Close() or SetClosed()
1262  m_keepalive = this;
1263 }
1264 
1265 a2dView::a2dView( const a2dView& other )
1266  : a2dObject()
1267 {
1268  m_isClosed = false;
1269 
1270  m_display = other.m_display;
1274  m_viewEnabled = other.m_viewEnabled;
1275  m_active = other.m_active;
1276 
1277  m_id = wxNewId();
1278 }
1279 
1281 {
1282  wxASSERT_MSG( m_refcount == 0, wxT( "deleting a2dView while referenced" ) );
1283  if ( m_viewDocument )
1287 }
1288 
1289 a2dObject* a2dView::SmrtPtrOwn()
1290 {
1291  m_refcount++;
1292  return this;
1293 }
1294 
1295 bool a2dView::SmrtPtrRelease()
1296 {
1297  m_refcount--;
1298 
1299  wxASSERT_MSG( m_refcount >= 0, wxT( "a2dView::Release Negative reference count" ) );
1300  if ( m_refcount <= 0 )
1301  {
1302  delete this;
1303  return true;
1304  }
1305  return false;
1306 }
1307 
1308 void a2dView::SetDisplayWindow( wxWindow* display )
1309 {
1310  if ( GetEvtHandlerEnabled() )
1311  {
1312  if ( m_display != display )
1313  Activate( false );
1314  m_display = display;
1315  if ( m_display )
1316  Activate( true );
1317  }
1318 }
1319 
1320 bool a2dView::Enable( bool enable )
1321 {
1322  if ( enable != m_viewEnabled ) //only if needed.
1323  {
1324  bool restorestate = GetEvtHandlerEnabled();
1325  if ( m_display )
1326  {
1327  //sent event to inform the display window
1328  //( and if handled right, in all above since it travels up in wxWindow classes )
1329  a2dViewEvent event( wxEVT_ENABLE_VIEW, enable, m_id );
1330  event.SetEventObject( this );
1331 
1332  SetEvtHandlerEnabled( false ); //this event coming back from the display will not be handled
1333  event.ResumePropagation( wxEVENT_PROPAGATE_MAX );
1334  m_display->GetEventHandler()->ProcessEvent( event );
1335  event.StopPropagation();
1336  }
1337 
1338  //this event always will be processed
1339  SetEvtHandlerEnabled( true );
1340  if ( enable )
1341  {
1342  //inform view that it just was enabled or disabled
1343  a2dViewEvent Event( wxEVT_ENABLE_VIEW, enable, m_id );
1344  Event.SetEventObject( this );
1345  ProcessEvent( Event );
1346  }
1347 
1348  m_viewEnabled = enable;
1349 
1350  SetEvtHandlerEnabled( restorestate ); //restore state.
1351  return true;
1352  }
1353  else
1354  {
1355  return false; //no change in viewEnable state
1356  }
1357 }
1358 
1360 {
1361  if( m_viewDocument != doc )
1362  {
1363  Activate( false );
1364  bool viewRemoved = false;
1365  if ( m_viewDocument )
1366  {
1367  //a2dView belongs to other a2dDocument so remove it from that document first.
1368  viewRemoved = true;
1369  a2dDocumentEvent eventremove( wxEVT_REMOVE_VIEW, this, true, m_id );
1370  eventremove.SetEventObject( this );
1371  m_viewDocument->ProcessEvent( eventremove );
1373  }
1374 
1375  m_viewDocument = doc;
1376  if ( doc )
1377  {
1378  m_viewDocument->ConnectEvent( wxEVT_CLOSE_VIEW, this );
1379  m_viewDocument->ConnectEvent( wxEVT_CHANGEDFILENAME_DOCUMENT, this );
1380  m_viewDocument->ConnectEvent( wxEVT_CHANGEDTITLE_DOCUMENT, this );
1381  m_viewDocument->ConnectEvent( wxEVT_ENABLE_VIEW, this );
1382  m_viewDocument->ConnectEvent( wxEVT_UPDATE_VIEWS, this );
1383  m_viewDocument->ConnectEvent( wxEVT_ENABLE_VIEWS, this );
1384  m_viewDocument->ConnectEvent( wxEVT_REPORT_VIEWS, this );
1385  m_viewDocument->ConnectEvent( wxEVT_DISCONNECT_ALLVIEWS, this );
1386 
1387  Activate( true );
1388 
1389  a2dDocumentEvent eventadd( wxEVT_ADD_VIEW, this, viewRemoved , m_id );
1390  eventadd.SetEventObject( this );
1391  m_viewDocument->ProcessEvent( eventadd );
1392  }
1393 
1394  a2dViewEvent viewevent( wxEVT_SET_DOCUMENT, ( a2dDocumentFlagMask ) a2dREFDOC_NON, m_id );
1395  viewevent.SetEventObject( this );
1396  ProcessEvent( viewevent );
1397  }
1398 }
1399 
1400 void a2dView::Activate( bool activate )
1401 {
1402  //wxLogDebug(wxT("a2dView::Activate(this=0x%p'%s' %s) (%s,%d,%s)"),
1403  // this, GetClassInfo()->GetClassName(), activate ? wxT("true") : wxT("false"), __A2DFILE__, __LINE__, __DATE__);
1404 
1405  if( !activate && !m_active )
1406  {
1407  //wxLogDebug(wxT("a2dView::Activate(false) Ignoring (%s,%d,%s)"),
1408  // __A2DFILE__, __LINE__, __DATE__);
1409  // ignoring activate event if already not active
1410  return;
1411  }
1412 
1413  m_active = activate; //first set it.
1414 
1415  a2dViewEvent activateEvent( wxEVT_ACTIVATE_VIEW, activate, m_id );
1416  activateEvent.SetEventObject( this );
1418 
1419  bool oldEnableState = GetEvtHandlerEnabled();
1420  SetEvtHandlerEnabled( false );
1421 
1422  if ( m_display )
1423  {
1424  a2dViewEvent activateEvent( wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD, activate, m_id );
1425  activateEvent.SetEventObject( this );
1426  activateEvent.ResumePropagation( wxEVENT_PROPAGATE_MAX );
1427  m_display->GetEventHandler()->ProcessEvent( activateEvent );
1428  activateEvent.StopPropagation();
1429  }
1430 
1431  SetEvtHandlerEnabled( oldEnableState ); //back to normal
1432 
1433  // the event to the view itself, but also to registered event handlers
1434  ProcessEvent( activateEvent );
1435 }
1436 
1437 // Extend event processing to search the document's event table
1438 bool a2dView::ProcessEvent( wxEvent& event )
1439 {
1440  if ( ( GetEvtHandlerEnabled() && m_viewEnabled ) ||
1441  ( event.GetEventType() == wxEVT_ENABLE_VIEW ) ||
1442  ( event.GetEventType() == wxEVT_ENABLE_VIEWS )
1443  )
1444  {
1445  //prevent the object from being deleted until this process event is at an end
1447 // a2dObjectPtr keepAlive = this;
1448  bool processed = false;
1449 
1450  if ( event.GetEventType() == wxEVT_ACTIVATE )
1451  {
1452  Activate( ( ( wxActivateEvent& ) event ).GetActive() );
1453 
1454  //wxLogDebug(wxT("Activate Event(this=0x%p'%s' %s) (%s,%d)"),
1455  //this, GetClassInfo()->GetClassName(), m_active ? wxT("true") : wxT("false"), __A2DFILE__, __LINE__);
1456 
1457  return true;
1458  }
1459  else if ( event.GetEventType() == wxEVT_SET_FOCUS )
1460  {
1461  processed = a2dObject::ProcessEvent( event );
1462 
1463  //wxLogDebug(wxT("Focus SET Event(this=0x%p'%s' %s) (%s,%d)"),
1464  //this, GetClassInfo()->GetClassName(), m_active ? wxT("true") : wxT("false"), __A2DFILE__, __LINE__);
1465 
1466  //Activate( true );
1467  return processed;
1468  }
1469  else if ( event.GetEventType() == wxEVT_KILL_FOCUS )
1470  {
1471 
1472  //wxLogDebug(wxT("Focus KILL Event(this=0x%p'%s' %s) (%s,%d)"),
1473  //this, GetClassInfo()->GetClassName(), m_active ? wxT("true") : wxT("false"), __A2DFILE__, __LINE__);
1474 
1475  processed = a2dObject::ProcessEvent( event );
1476  //Activate( false );
1477  return processed;
1478  }
1479  else if ( event.GetEventType() == wxEVT_CLOSE_WINDOW )
1480  {
1481  wxCloseEvent& closeevent = ( wxCloseEvent& ) event;
1482 
1483  //close window events received either through frame of window containing
1484  //this view, always go through this base class its Close()
1485  if ( !GetDocument() )
1486  {
1487  processed = Close( !closeevent.CanVeto() ); //a view without a document? strange but handle it.
1488  return processed;
1489  }
1490 
1491  //view to close and cleanup
1492  processed = Close( !closeevent.CanVeto() );
1493  return processed;
1494  }
1495  else if ( event.GetEventType() == wxEVT_IDLE )
1496  {
1497  //first to document then (if not handled ) normal processing via view
1498  if ( GetDocument() && GetDocument()->ProcessEvent( event ) )
1499  return true;
1500  }
1501 
1502  //normal processing via view
1503  event.Skip(); //skipped because not processed so prepare for view
1504  processed = a2dObject::ProcessEvent( event );
1505  return processed;
1506  }
1507  return false;
1508 }
1509 
1510 void a2dView::OnCloseView( a2dCloseViewEvent& event )
1511 {
1512  if ( this != event.GetEventObject() )
1513  return;
1514 }
1515 
1516 void a2dView::OnDisConnectView( a2dDocumentEvent& event )
1517 {
1518  //prevent recursive calls
1519  if ( m_isClosed )
1520  return; //was already closed and diconnected.
1521 
1522  if ( m_viewDocument != event.GetEventObject() )
1523  return;
1524 
1525  bool processed = false;
1526  Activate( false );
1527 
1528  // we first try the connector to solve the problem of disconnecting a view.
1529  // This prevents need for deriving new views just to change disconnect behaviour.
1530  if ( m_viewTemplate && m_viewTemplate->GetViewConnector() )
1531  {
1532  a2dTemplateEvent event( wxEVT_DISCONNECT_VIEW, this, a2dREFDOC_NON, m_id );
1533  event.SetEventObject( this );
1534  processed = m_viewTemplate->GetViewConnector()->ProcessEvent( event );
1535  }
1536 
1537  // if a view was not disconnected (and re-used for a new/old document) or closed by the connector,
1538  // we proceed with closing down a view.
1539  if ( !processed )
1540  {
1541  Close( true );
1542  }
1543 }
1544 
1546 {
1547  m_isClosed = true;
1548  if ( m_viewDocument )
1550  m_viewDocument = 0;
1551  // release the self owning
1552  m_keepalive = 0;
1553 }
1554 
1555 bool a2dView::Close( bool force )
1556 {
1557  //prevent recursive calls
1558  if ( m_isClosed )
1559  return true; //was already closed
1560 
1561  //prevent the object from being deleted until this process event is at an end
1562  wxASSERT( m_keepalive == this );
1563 
1564  m_isClosed = true; //prevent recursive calls.
1565 
1566  a2dCloseViewEvent event( m_id );
1567  event.SetEventObject( this );
1568  event.SetCanVeto( !force );
1569 
1570  //first inform document about the attempt to close the view.
1571  if ( m_viewDocument )
1572  {
1573  SetEvtHandlerEnabled( false ); //prevent handling via dynamic connect
1574  m_viewDocument->ProcessEvent( event );
1575  SetEvtHandlerEnabled( true );
1576  }
1577 
1578  // document finds it oke, try the connector to see if it can do it.
1579  if ( !event.GetVeto() )
1580  {
1581  // now if a viewtemplate and connector does exist, we assume that the display is handled by that.
1582  if ( m_viewTemplate.Get() && m_viewTemplate->GetViewConnector() )
1583  m_viewTemplate->GetViewConnector()->ProcessEvent( event );
1584  else
1585  {
1586  //we do it ourselfs
1587  if ( m_display )
1588  {
1589  bool oldEnableState = GetEvtHandlerEnabled();
1590  SetEvtHandlerEnabled( false ); //this event coming back from the display will not be handled
1591  event.ResumePropagation( wxEVENT_PROPAGATE_MAX );
1592  //second inform display about the attempt to close the view.
1593  m_display->GetEventHandler()->ProcessEvent( event );
1594  event.StopPropagation();
1595  SetEvtHandlerEnabled( oldEnableState ); //back to normal
1596  }
1597  }
1598  }
1599 
1600  if ( !event.GetVeto() )
1601  {
1602  //not vetod by m_display or parent frame/windows.
1603  // That means that the m_display is disconnected from the view, and maybe also destroyed.
1604  // That depends on the a2dViewConnector.
1605  // In any case the m_display is not valid anymore right now.
1606  m_display = NULL;
1607 
1608  //third inform view about the attempt to close the view.
1609  ProcessEvent( event );
1610  if ( !event.GetVeto() )
1611  {
1612  Activate( false );
1613  if ( m_viewDocument )
1614  {
1615  a2dDocumentEvent eventremove( wxEVT_REMOVE_VIEW, this, true, m_id );
1616  eventremove.SetEventObject( this );
1617  m_viewDocument->ProcessEvent( eventremove );
1618  }
1619  if ( m_viewDocument )
1621  m_viewDocument = 0;
1622 
1623  //! release of itself
1624  m_keepalive = 0;
1625  return true;
1626  }
1627  }
1628 
1629  m_isClosed = false;
1630 
1631  //because the view is not allowed to close, we do not release itself using m_keepalive = 0
1632  return false;
1633 }
1634 
1635 void a2dView::OnPrint( wxDC* dc, wxObject* WXUNUSED( info ) )
1636 {
1637  OnDraw( dc );
1638 }
1639 
1640 
1641 void a2dView::Update( unsigned int hint, wxObject* hintObject )
1642 {
1643  a2dDocumentEvent event( wxEVT_UPDATE_VIEWS, this );
1644  event.SetEventObject( m_viewDocument ); //Document receiver is a2dView itself, but
1645  // event also sent from outside a2dView class in a2dDocument, therefore eventObject is document.
1646  event.SetUpdateHint( hint );
1647  event.SetUpdateObject( hintObject );
1648  ProcessEvent( event );
1649 }
1650 
1651 void a2dView::OnUpdate( a2dDocumentEvent& event )
1652 {
1653  if ( m_viewDocument == event.GetEventObject() && GetEvtHandlerEnabled() && m_display )
1654  m_display->Refresh();
1655 }
1656 
1657 void a2dView::OnReport( a2dDocumentEvent& event )
1658 {
1659  if ( m_viewDocument == event.GetEventObject() && !m_isClosed )
1660  event.GetReportList()->push_back( this );
1661 }
1662 
1663 void a2dView::OnEnable( a2dViewEvent& event )
1664 {
1665  if ( this != event.GetEventObject() )
1666  return;
1667 
1668  if ( event.GetEnable() )
1669  Update();
1670 }
1671 
1672 void a2dView::OnEnableViews( a2dDocumentEvent& event )
1673 {
1674  if ( m_viewDocument == event.GetEventObject() &&
1675  ( event.GetView() != this || event.GetView() == NULL ) //sender is skipped id not NULL
1676  )
1677  Enable( event.GetEnable() );
1678 }
1679 
1680 void a2dView::OnChangeFilename( a2dDocumentEvent& event )
1681 {
1682  if ( m_viewDocument != event.GetEventObject() )
1683  return;
1684 
1685  bool oldEnableState = GetEvtHandlerEnabled();
1686  SetEvtHandlerEnabled( false ); //this event coming back from the display will not be handled
1687 
1688  if ( m_display )
1689  {
1690  a2dViewEvent eventView( wxEVT_CHANGEDFILENAME_VIEW, ( a2dDocumentFlagMask ) a2dREFDOC_NON, m_id );
1691  eventView.SetEventObject( this );
1692  eventView.ResumePropagation( wxEVENT_PROPAGATE_MAX );
1693  m_display->GetEventHandler()->ProcessEvent( eventView );
1694  eventView.StopPropagation();
1695  }
1696 
1697  SetEvtHandlerEnabled( oldEnableState ); //back to normal
1698 }
1699 
1700 void a2dView::OnChangeTitle( a2dDocumentEvent& event )
1701 {
1702  if ( m_viewDocument != event.GetEventObject() )
1703  return;
1704 
1705  bool oldEnableState = GetEvtHandlerEnabled();
1706  SetEvtHandlerEnabled( false ); //this event coming back from the display will not be handled
1707 
1708  if ( m_display )
1709  {
1710  a2dViewEvent eventView( wxEVT_CHANGEDTITLE_VIEW, ( a2dDocumentFlagMask ) a2dREFDOC_NON, m_id );
1711  eventView.SetEventObject( this );
1712  eventView.ResumePropagation( wxEVENT_PROPAGATE_MAX );
1713  m_display->GetEventHandler()->ProcessEvent( eventView );
1714  eventView.StopPropagation();
1715  }
1716 
1717  SetEvtHandlerEnabled( oldEnableState ); //back to normal
1718 }
1719 
1720 #if wxUSE_PRINTING_ARCHITECTURE
1721 wxPrintout* a2dView::OnCreatePrintout( a2dPrintWhat WXUNUSED( typeOfPrint ), const wxPageSetupDialogData& pageSetupData )
1722 {
1723  return new a2dDocumentPrintout( this );
1724 }
1725 #endif // wxUSE_PRINTING_ARCHITECTURE
1726 
1727 void a2dView::OnSetFocus( wxFocusEvent& event )
1728 {
1729  event.Skip( true );
1730 }
1731 
1732 void a2dView::OnKillFocus( wxFocusEvent& event )
1733 {
1734  event.Skip( true );
1735 }
1736 
1737 // ----------------------------------------------------------------------------
1738 // a2dDocumentTemplate
1739 // ----------------------------------------------------------------------------
1741  const wxString& descr,
1742  const wxString& filter,
1743  const wxString& dir,
1744  const wxString& ext,
1745  const wxString& docTypeName,
1746  wxClassInfo* docClassInfo,
1747  a2dViewConnector* connector,
1748  long flags,
1749  a2dIOHandlerStrIn* handlerIn,
1750  a2dIOHandlerStrOut* handlerOut )
1751 {
1752  m_description = descr;
1753  m_directory = dir;
1754  m_defaultExt = ext;
1755  m_fileFilter = filter;
1756  m_flags = flags;
1757  m_docTypeName = docTypeName;
1758  m_connector = connector;
1759 
1760  m_docClassInfo = docClassInfo;
1761  m_documentCreate = NULL;
1762 
1763  m_ioHandlerStrIn = handlerIn;
1764  m_ioHandlerStrOut = handlerOut;
1765 #if wxUSE_PRINTING_ARCHITECTURE
1766  m_pageSetupData = new wxPageSetupDialogData( *a2dDocviewGlobals->GetDocviewCommandProcessor()->GetPageSetupData() );
1767 #endif
1768 }
1769 
1771 {
1772 #if wxUSE_PRINTING_ARCHITECTURE
1773  if( m_pageSetupData )
1774  delete m_pageSetupData;
1775 #endif
1776 }
1777 
1778 a2dObject* a2dDocumentTemplate::SmrtPtrOwn()
1779 {
1780  m_refcount++;
1781  return this;
1782 }
1783 
1784 bool a2dDocumentTemplate::SmrtPtrRelease()
1785 {
1786  m_refcount--;
1787 
1788  wxASSERT_MSG( m_refcount >= 0, wxT( "a2dDocumentTemplate::Release Negative reference count" ) );
1789  if ( m_refcount <= 0 )
1790  {
1791  delete this;
1792  return true;
1793  }
1794  return false;
1795 }
1796 
1797 a2dObject* a2dDocumentTemplate::DoClone( CloneOptions WXUNUSED( options ), a2dRefMap* refs ) const
1798 {
1799  wxLogMessage( _( "Not implemented" ) );
1800  return NULL;
1801 }
1802 
1803 void a2dDocumentTemplate::SetPageSetupData( wxPageSetupDialogData* pageSetupData )
1804 {
1805 #if wxUSE_PRINTING_ARCHITECTURE
1806  if( m_pageSetupData )
1807  delete m_pageSetupData;
1808  m_pageSetupData = pageSetupData;
1809 #endif
1810 }
1811 
1813 {
1814  if ( m_ioHandlerStrIn && m_ioHandlerStrIn->CanLoad( stream, document, m_docClassInfo ) )
1815  return m_ioHandlerStrIn;
1816  return NULL;
1817 }
1818 
1820 {
1821  if ( m_ioHandlerStrOut && m_ioHandlerStrOut->CanSave( document ) )
1822  return m_ioHandlerStrOut;
1823  return NULL;
1824 }
1825 
1826 
1827 #if wxART2D_USE_CVGIO
1828 void a2dDocumentTemplate::DoSave( wxObject* WXUNUSED( parent ), a2dIOHandlerXmlSerOut& WXUNUSED( out ), a2dXmlSer_flag WXUNUSED( xmlparts ), a2dObjectList* WXUNUSED( towrite ) )
1829 {
1830  wxLogMessage( _( "Not implemented" ) );
1831 }
1832 
1833 void a2dDocumentTemplate::DoLoad( wxObject* WXUNUSED( parent ), a2dIOHandlerXmlSerIn& WXUNUSED( parser ), a2dXmlSer_flag WXUNUSED( xmlparts ) )
1834 {
1835  wxLogMessage( _( "Not implemented" ) );
1836 }
1837 
1838 #endif //wxART2D_USE_CVGIO
1839 
1840 // Tries to dynamically construct an object of the right class.
1842 {
1843  if ( !m_docClassInfo )
1844  return ( a2dDocument* ) NULL;
1845 
1846  a2dDocument* doc;
1847  if ( m_documentCreate )
1848  doc = ( a2dDocument* ) m_documentCreate->Clone( clone_deep );
1849  else
1850  doc = ( a2dDocument* ) m_docClassInfo->CreateObject();
1851 
1852  if ( doc )
1853  {
1854  //do not yet add the document to the docmanager
1855  doc->SetFilename( path, false ); // no events to be send internal, to early
1856  doc->SetDocumentTemplate( this );
1857  if ( !doc->GetCommandProcessor() )
1858  doc->CreateCommandProcessor();
1860 
1861  a2dDocumentEvent createdDocument( wxEVT_CREATE_DOCUMENT, path, flags );
1862  createdDocument.SetEventObject( this );
1863  doc->ProcessEvent( createdDocument );
1864 
1865  return doc;
1866  }
1867  return ( a2dDocument* ) NULL;
1868 }
1869 
1871 {
1872  bool ret = false;
1873  // we only sent this event to the viewconnector of the template.
1874  // This makes it easier to couple specific templates to specific
1875  // connector classes.
1876  a2dTemplateEvent preAddCreatedDocumentEvent( newDoc, wxEVT_PRE_ADD_DOCUMENT, flags );
1877  preAddCreatedDocumentEvent.SetEventObject( this );
1878  if ( m_connector )
1879  ret = m_connector->ProcessEvent( preAddCreatedDocumentEvent );
1880  else
1881  // in applications without viewconnectors, try this one for registered event handlers
1882  ret = ProcessEvent( preAddCreatedDocumentEvent );
1883 
1884  return preAddCreatedDocumentEvent.GetDocument();
1885 }
1886 
1888 {
1889  bool ret = false;
1890  // we only sent this event to the viewconnector of the template.
1891  // This makes it easier to couple specific templates to specific
1892  // connector classes.
1893  a2dTemplateEvent postCreatedDocumentEvent( newDoc, wxEVT_POST_CREATE_DOCUMENT, flags );
1894  postCreatedDocumentEvent.SetEventObject( this );
1895  if ( m_connector )
1896  ret = m_connector->ProcessEvent( postCreatedDocumentEvent );
1897  else
1898  // in applications without viewconnectors, try this one for registered event handlers
1899  ret = ProcessEvent( postCreatedDocumentEvent );
1900 
1901  return ret;
1902 }
1903 
1904 bool a2dDocumentTemplate::FileMatchesTemplate( const wxString& path )
1905 {
1906  // first test for default extension
1907  if ( FindExtension( path ) != wxT( "" ) )
1908  if ( GetDefaultExtension().IsSameAs( FindExtension( path ) ) )
1909  return true;
1910 
1911 
1912 #if wxUSE_STD_IOSTREAM
1913  a2dDocumentFileInputStream store( path.mb_str(), wxSTD ios_base::in | wxSTD ios_base::binary );
1914  if ( store.fail() || store.bad() )
1915  {
1916  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for testing format" ), path.c_str() );
1917  return false;
1918  }
1919 #else
1920  wxFileInputStream storeUnbuf( path );
1921  if ( !storeUnbuf.Ok() )
1922  {
1923  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for testing format" ), path.c_str() );
1924  return false;
1925  }
1926  wxBufferedInputStream store( storeUnbuf );
1927 #endif
1928 
1929  a2dIOHandlerStrIn* handler = GetDocumentIOHandlerForLoad( store, NULL );
1930  if ( handler )
1931  return true;
1932 
1933  wxStringTokenizer parser ( GetFileFilter(), wxT( ";" ) );
1934  wxString anything = wxT ( "*" );
1935  while ( parser.HasMoreTokens() )
1936  {
1937  wxString filter = parser.GetNextToken();
1938  wxString filterExt = FindExtension ( filter );
1939  if ( filter.IsSameAs ( anything ) ||
1940  filterExt.IsSameAs ( anything ) ||
1941  filterExt.IsSameAs ( FindExtension ( path ) ) )
1942  return true;
1943  }
1944  return false;
1945 }
1946 
1947 //----------------------------------------------------------------------------
1948 // a2dDocumentTemplateAuto
1949 //----------------------------------------------------------------------------
1950 
1951 a2dDocumentTemplateAuto::a2dDocumentTemplateAuto(
1952  const wxString& descr,
1953  const wxString& filter,
1954  const wxString& dir,
1955  const wxString& ext,
1956  const wxString& docTypeName,
1957  wxClassInfo* docClassInfo,
1958  a2dViewConnector* connector,
1959  long flags ):
1960  a2dDocumentTemplate( descr, filter, dir, ext, docTypeName, docClassInfo, connector, flags, NULL )
1961 {
1962 }
1963 
1965 {
1966 }
1967 
1969 {
1970  // Find the template for this type of document.
1972  for( a2dDocumentTemplateList::const_iterator iter = allDocTemplates.begin(); iter != allDocTemplates.end(); ++iter )
1973  {
1974  a2dDocumentTemplateList::value_type temp = *iter;
1975  if ( temp != this && temp->GetDocumentTypeName() == GetDocumentTypeName() &&
1976  temp->GetDocumentIOHandlerStrIn() &&
1977  temp->GetDocumentIOHandlerStrIn()->CanLoad( stream, document, temp->GetDocumentClassInfo() ) )
1978  return temp->GetDocumentIOHandlerStrIn();
1979  }
1980  return NULL;
1981 }
1982 
1984 {
1985  // Find the template for this type of document.
1987  for( a2dDocumentTemplateList::const_iterator iter = allDocTemplates.begin(); iter != allDocTemplates.end(); ++iter )
1988  {
1989  a2dDocumentTemplateList::value_type temp = *iter;
1990  if ( temp != this && temp->GetDocumentTypeName() == GetDocumentTypeName() && temp->GetDocumentIOHandlerStrOut() && temp->GetDocumentIOHandlerStrOut()->CanSave( document ) )
1991  {
1992  if ( filename.IsEmpty() )
1993  return temp->GetDocumentIOHandlerStrOut();
1994  else
1995  {
1996  wxString path, name, ext;
1997  wxFileName::SplitPath( filename, & path, & name, & ext );
1998  if ( ext == temp->GetDefaultExtension() )
1999  return temp->GetDocumentIOHandlerStrOut();
2000  }
2001  }
2002  }
2003  return NULL;
2004 }
2005 
2006 // ----------------------------------------------------------------------------
2007 // a2dViewTemplate
2008 // ----------------------------------------------------------------------------
2010  const wxString& descr,
2011  const wxString& docTypeName,
2012  const wxString& viewTypeName,
2013  wxClassInfo* viewClassInfo,
2014  a2dViewConnector* connector,
2015  long flags,
2016  const wxSize& size
2017 )
2018 {
2019  m_description = descr;
2020  m_flags = flags;
2021  m_docTypeName = docTypeName;
2022  m_viewTypeName = viewTypeName;
2023  m_connector = connector;
2024 
2025  m_viewClassInfo = viewClassInfo;
2026 
2027  m_initialSize = size;
2028 #if wxUSE_PRINTING_ARCHITECTURE
2029  m_pageSetupData = new wxPageSetupDialogData( *a2dDocviewGlobals->GetDocviewCommandProcessor()->GetPageSetupData() );
2030 #endif
2031 }
2032 
2034 {
2035 #if wxUSE_PRINTING_ARCHITECTURE
2036  if( m_pageSetupData )
2037  delete m_pageSetupData;
2038 #endif
2039 }
2040 
2041 a2dObject* a2dViewTemplate::SmrtPtrOwn()
2042 {
2043  m_refcount++;
2044  return this;
2045 }
2046 
2047 bool a2dViewTemplate::SmrtPtrRelease()
2048 {
2049  m_refcount--;
2050 
2051  wxASSERT_MSG( m_refcount >= 0, wxT( "a2dViewTemplate::Release Negative reference count" ) );
2052  if ( m_refcount <= 0 )
2053  {
2054  delete this;
2055  return true;
2056  }
2057  return false;
2058 }
2059 
2060 a2dObject* a2dViewTemplate::DoClone( CloneOptions WXUNUSED( options ), a2dRefMap* refs ) const
2061 {
2062  wxLogMessage( _( "Not implemented" ) );
2063  return NULL;
2064 }
2065 
2066 void a2dViewTemplate::SetPageSetupData( wxPageSetupDialogData* pageSetupData )
2067 {
2068 #if wxUSE_PRINTING_ARCHITECTURE
2069  if( m_pageSetupData )
2070  delete m_pageSetupData;
2071  m_pageSetupData = pageSetupData;
2072 #endif
2073 }
2074 
2075 #if wxART2D_USE_CVGIO
2076 void a2dViewTemplate::DoSave( wxObject* WXUNUSED( parent ), a2dIOHandlerXmlSerOut& WXUNUSED( out ), a2dXmlSer_flag WXUNUSED( xmlparts ), a2dObjectList* WXUNUSED( towrite ) )
2077 {
2078  wxLogMessage( _( "Not implemented" ) ) ;
2079 }
2080 
2081 void a2dViewTemplate::DoLoad( wxObject* WXUNUSED( parent ), a2dIOHandlerXmlSerIn& WXUNUSED( parser ), a2dXmlSer_flag WXUNUSED( xmlparts ) )
2082 {
2083  wxLogMessage( _( "Not implemented" ) );
2084 }
2085 #endif //wxART2D_USE_CVGIO
2086 
2088 {
2089  if ( !m_viewClassInfo )
2090  return ( a2dView* ) NULL;
2091 
2092  a2dView* view = ( a2dView* )m_viewClassInfo->CreateObject();
2093 
2094  if ( view )
2095  {
2096  view->SetDocument( doc );
2098  view->SetViewTemplate( this );
2099 
2100  a2dViewEvent createdView( wxEVT_CREATE_VIEW, flags, view->GetId() );
2101  createdView.SetEventObject( this ); //Template, a specific view is receiver
2102 
2103  //we are not interested if it was handled or not here.
2104  view->ProcessEvent( createdView );
2105 
2106  a2dTemplateEvent postCreatedViewEvent( wxEVT_POST_CREATE_VIEW, view, flags );
2107  postCreatedViewEvent.SetEventObject( this ); //Template, a specific connector is receiver
2108  m_connector->ProcessEvent( postCreatedViewEvent );
2109  view->Activate( true );
2110  return view;
2111  }
2112 
2113  return ( a2dView* ) NULL;
2114 }
2115 
2116 // ----------------------------------------------------------------------------
2117 // a2dViewConnector
2118 // ----------------------------------------------------------------------------
2119 
2120 BEGIN_EVENT_TABLE( a2dViewConnector, a2dObject )
2121  EVT_POST_CREATE_DOCUMENT( a2dViewConnector::OnPostCreateDocument )
2122  EVT_DISCONNECT_VIEW( a2dViewConnector::OnDisConnectView )
2123  EVT_CLOSE_VIEW( a2dViewConnector::OnCloseView )
2124 END_EVENT_TABLE()
2125 
2126 a2dViewConnector::a2dViewConnector()
2127 {
2128  m_initialPos = wxPoint( 0, 0 );
2129  m_initialSize = wxSize( 300, 400 );
2130  m_initialStyle = wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE;
2131  //m_initialStyle = wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR ;
2132  m_OnlyDisconnect = false;
2133 }
2134 
2136 {
2137  wxASSERT_MSG( m_refcount == 0, wxT( "deleting a2dViewConnector while referenced" ) );
2138 }
2139 
2140 a2dViewConnector::a2dViewConnector( const a2dViewConnector& other )
2141 {
2142  m_initialPos = other.m_initialPos;
2143  m_initialSize = other.m_initialSize;
2146 }
2147 
2148 void a2dViewConnector::AssociateViewTemplate( a2dViewTemplate* temp )
2149 {
2150  if ( m_viewTemplates.end() == m_viewTemplates.Find( temp ) )
2151  {
2152  m_viewTemplates.push_back( temp );
2153  }
2154 }
2155 
2156 void a2dViewConnector::DisassociateViewTemplate( a2dViewTemplate* temp )
2157 {
2159 }
2160 
2162 {
2163  m_viewTemplates.clear();
2164 }
2165 
2166 void a2dViewConnector::OnPostCreateDocument( a2dTemplateEvent& event )
2167 {
2168  //a2dDocumentTemplate* templ = (a2dDocumentTemplate*) event.GetEventObject();
2169  a2dViewTemplate* viewtempl;
2170 
2173  wxT( "" ),
2174  true, event.GetTemplateMaskFlags() );
2175 
2176  if ( !viewtempl )
2177  {
2178  wxLogMessage( _( "No view available for this document in a2dViewConnector" ) );
2179  return;
2180  }
2181  else
2182  {
2183  a2dView* view = viewtempl->CreateView( event.GetDocument(), event.GetFlags() );
2184  event.SetView( view );
2185  if ( view )
2186  return;
2187  }
2188  wxLogMessage( _( "a2dViewConnector no view was created" ) );
2189 }
2190 
2191 a2dView* a2dViewConnector::CreateView( a2dDocument* doc, const wxString& viewTypeName,
2192  a2dDocumentFlagMask flags,
2193  a2dTemplateFlagMask viewTemplateFlags )
2194 {
2195  //a2dDocumentTemplate* templ = (a2dDocumentTemplate*) event.GetEventObject();
2196  a2dViewTemplate* viewtempl;
2197 
2199  m_viewTemplates.size() ? m_viewTemplates :
2201  true, viewTemplateFlags );
2202 
2203  a2dView* createdView;
2204 
2205  if ( !viewtempl )
2206  {
2207  wxLogMessage( _( "No view available for this document in a2dViewConnector" ) );
2208  return NULL;
2209  }
2210  else
2211  {
2212  createdView = viewtempl->CreateView( doc, flags );
2213  if ( createdView )
2214  return createdView;
2215  }
2216  wxLogMessage( _( "a2dViewConnector no view was created" ) );
2217  return NULL;
2218 }
2219 
2220 void a2dViewConnector::OnDisConnectView( a2dTemplateEvent& event )
2221 {
2222  a2dSmrtPtr<a2dView> theViewToDisconnect = ( a2dView* ) event.GetEventObject();
2223 
2224  if ( !m_OnlyDisconnect )
2225  // fall back on view bahaviour which is closing down the view and its display window etc.
2226  theViewToDisconnect->Close( true );
2227  else
2228  {
2229  // keep the view and its display window, only remove it from the document.
2230  theViewToDisconnect->Activate( false );
2231  if ( theViewToDisconnect->GetDocument() )
2232  {
2233  a2dDocumentEvent eventremove( wxEVT_REMOVE_VIEW, theViewToDisconnect, true, theViewToDisconnect->GetId() );
2234  eventremove.SetEventObject( theViewToDisconnect );
2235  theViewToDisconnect->GetDocument()->ProcessEvent( eventremove );
2236  }
2237  theViewToDisconnect->SetDocument( NULL );
2238  }
2239 }
2240 
2241 void a2dViewConnector::OnCloseView( a2dCloseViewEvent& event )
2242 {
2243  a2dSmrtPtr<a2dView> theViewToClose = ( a2dView* ) event.GetEventObject();
2244 
2245  if ( theViewToClose->GetDisplayWindow() )
2246  {
2247  bool oldEnableState = theViewToClose->GetEvtHandlerEnabled();
2248  theViewToClose->SetEvtHandlerEnabled( false ); //this event coming back from the display will not be handled
2249 
2250  event.ResumePropagation( wxEVENT_PROPAGATE_MAX );
2251  //second inform view about the attempt to close the view.
2252  theViewToClose->GetDisplayWindow()->GetEventHandler()->ProcessEvent( event );
2253  event.StopPropagation();
2254 
2255  theViewToClose->SetEvtHandlerEnabled( oldEnableState ); //back to normal
2256  }
2257 }
2258 
2259 // ----------------------------------------------------------------------------
2260 // a2dFrameViewConnector
2261 // ----------------------------------------------------------------------------
2262 
2264 {
2265  m_docframe = ( a2dDocumentFrame* ) NULL;
2266  m_createChildframe = false;
2267 }
2268 
2269 a2dFrameViewConnector::a2dFrameViewConnector( const a2dFrameViewConnector& other ): a2dViewConnector( other )
2270 {
2271  m_docframe = other.m_docframe;
2272  m_createChildframe = other.m_createChildframe;
2273 }
2274 
2275 void a2dFrameViewConnector::Init( wxFrame* frame, bool createChildframe )
2276 {
2277  m_docframe = frame;
2278  m_createChildframe = createChildframe;
2279 }
2280 
2281 void a2dFrameViewConnector::OnPostCreateView( a2dTemplateEvent& event )
2282 {
2283  a2dView* newview = event.GetView();
2284  //a2dDocument *doc = newview->GetDocument();
2285 
2286  if ( m_createChildframe )
2287  {
2288  a2dDocumentFrame* viewFrame = new a2dDocumentFrame( false,
2289  m_docframe, newview, -1, newview->GetViewTypeName(),
2291  GetInitialSize(),
2292  GetInitialStyle()
2293  );
2294  viewFrame->Show( true );
2295  }
2296  else
2297  {
2298  a2dView* oldview = ( ( a2dDocumentFrame* ) m_docframe )->GetView();
2299  if ( oldview )
2300  {
2301  oldview->SetDisplayWindow( NULL );
2302  }
2303  ( ( a2dDocumentFrame* ) m_docframe )->SetView( newview );
2304  newview->SetDisplayWindow( m_docframe );
2305  }
2306  newview->Update();
2307 }
2308 
2309 // ----------------------------------------------------------------------------
2310 // a2dScrolledWindowViewConnector
2311 // ----------------------------------------------------------------------------
2312 
2313 IMPLEMENT_DYNAMIC_CLASS( a2dScrolledWindowViewConnector, a2dViewConnector )
2314 
2315 // ----------------------------------------------------------------------------
2316 // a2dWindowViewConnector
2317 // ----------------------------------------------------------------------------
2318 
2319 IMPLEMENT_DYNAMIC_CLASS( a2dWindowViewConnector, a2dViewConnector )
2320 
2321 /********************************************************************
2322 * a2dDocumentViewScrolledWindow
2323 *********************************************************************/
2324 IMPLEMENT_CLASS( a2dDocumentViewScrolledWindow, a2dViewWindow<wxScrolledWindow> )
2325 
2326 BEGIN_EVENT_TABLE( a2dDocumentViewScrolledWindow, a2dViewWindow<wxScrolledWindow> )
2327  EVT_CLOSE_VIEW( a2dDocumentViewScrolledWindow::OnCloseView )
2328  EVT_PAINT( a2dDocumentViewScrolledWindow::OnPaint )
2329 END_EVENT_TABLE()
2330 
2331 a2dDocumentViewScrolledWindow::a2dDocumentViewScrolledWindow( a2dView* view, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, const wxString& name ):
2332  a2dViewWindow<wxScrolledWindow>( view, parent, id, pos, size, style, name )
2333 {
2334 }
2335 
2336 a2dDocumentViewScrolledWindow::a2dDocumentViewScrolledWindow( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, const wxString& name ):
2337  a2dViewWindow<wxScrolledWindow>( parent, id, pos, size, style, name )
2338 {
2339 }
2340 
2342 {
2343 }
2344 
2345 /********************************************************************
2346 * a2dDocumentViewWindow
2347 *********************************************************************/
2348 
2350 
2351 BEGIN_EVENT_TABLE( a2dDocumentViewWindow, a2dViewWindow<wxWindow> )
2352  EVT_CLOSE_VIEW( a2dViewWindow<wxWindow>::OnCloseView )
2353  EVT_PAINT( a2dViewWindow<wxWindow>::OnPaint )
2354 END_EVENT_TABLE()
2355 
2356 a2dDocumentViewWindow::a2dDocumentViewWindow( a2dView* view, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, const wxString& name ):
2357  a2dViewWindow<wxWindow>( view, parent, id, pos, size, style, name )
2358 {
2359 }
2360 
2361 a2dDocumentViewWindow::a2dDocumentViewWindow( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, const wxString& name ):
2362  a2dViewWindow<wxWindow>( parent, id, pos, size, style, name )
2363 {
2364 }
2365 
2367 {
2368 }
2369 
2370 /********************************************************************
2371 * a2dDocumentPrintout
2372 *********************************************************************/
2373 
2374 
2375 #if wxUSE_PRINTING_ARCHITECTURE
2376 
2377 a2dDocumentPrintout::a2dDocumentPrintout( a2dView* view, const wxString& title )
2378  : wxPrintout( title )
2379 {
2380  m_printoutView = view;
2381 }
2382 
2383 bool a2dDocumentPrintout::OnPrintPage( int WXUNUSED( page ) )
2384 {
2385  wxDC* dc = GetDC();
2386 
2387  // Get the logical pixels per inch of screen and printer
2388  int ppiScreenX, ppiScreenY;
2389  GetPPIScreen( &ppiScreenX, &ppiScreenY );
2390  int ppiPrinterX, ppiPrinterY;
2391  GetPPIPrinter( &ppiPrinterX, &ppiPrinterY );
2392 
2393  // This scales the DC so that the printout roughly represents the
2394  // the screen scaling. The text point size _should_ be the right size
2395  // but in fact is too small for some reason. This is a detail that will
2396  // need to be addressed at some point but can be fudged for the
2397  // moment.
2398  float scale = ( float )( ( float )ppiPrinterX / ( float )ppiScreenX );
2399 
2400  // Now we have to check in case our real page size is reduced
2401  // (e.g. because we're drawing to a print preview memory DC)
2402  int pageWidth, pageHeight;
2403  int w, h;
2404  dc->GetSize( &w, &h );
2405  GetPageSizePixels( &pageWidth, &pageHeight );
2406 
2407  // If printer pageWidth == current DC width, then this doesn't
2408  // change. But w might be the preview bitmap width, so scale down.
2409  float overallScale = scale * ( float )( w / ( float )pageWidth );
2410  dc->SetUserScale( overallScale, overallScale );
2411 
2412  if ( m_printoutView )
2413  {
2414  m_printoutView->OnPrint( dc, NULL );
2415  }
2416  return true;
2417 }
2418 
2419 bool a2dDocumentPrintout::HasPage( int pageNum )
2420 {
2421  return ( pageNum == 1 );
2422 }
2423 
2424 bool a2dDocumentPrintout::OnBeginDocument( int startPage, int endPage )
2425 {
2426  if ( !wxPrintout::OnBeginDocument( startPage, endPage ) )
2427  return false;
2428 
2429  return true;
2430 }
2431 
2432 void a2dDocumentPrintout::GetPageInfo( int* minPage, int* maxPage, int* selPageFrom, int* selPageTo )
2433 {
2434  *minPage = 1;
2435  *maxPage = 1;
2436  *selPageFrom = 1;
2437  *selPageTo = 1;
2438 }
2439 
2440 #endif // wxUSE_PRINTING_ARCHITECTURE
2441 
2442 
2443 /********************************************************************
2444 * a2dDocumentFrame
2445 *********************************************************************/
2446 
2447 IMPLEMENT_CLASS( a2dDocumentFrame, wxFrame )
2448 
2449 BEGIN_EVENT_TABLE( a2dDocumentFrame, wxFrame )
2450  EVT_MENU( wxID_EXIT, a2dDocumentFrame::OnExit )
2451  EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, a2dDocumentFrame::OnMRUFile )
2452  EVT_CHANGEDFILENAME_VIEW( a2dDocumentFrame::OnChangeFilename )
2453  EVT_CLOSE_VIEW( a2dDocumentFrame::OnCloseView )
2454  EVT_CLOSE( a2dDocumentFrame::OnCloseWindow )
2455  EVT_PAINT( a2dDocumentFrame::OnPaint )
2456  EVT_ACTIVATE_VIEW_SENT_FROM_CHILD( a2dDocumentFrame::OnActivateViewSentFromChild )
2457 END_EVENT_TABLE()
2458 
2459 a2dDocumentFrame::a2dDocumentFrame()
2460 {
2461  m_destroyOnCloseView = true;
2462  m_isParentFrame = true;
2463  m_view = NULL;
2464 }
2465 
2467  wxWindow* frame,
2468  a2dView* view,
2469  wxWindowID id,
2470  const wxString& title,
2471  const wxPoint& pos,
2472  const wxSize& size,
2473  long style,
2474  const wxString& name )
2475  : wxFrame( frame, id, title, pos, size, style, name )
2476 {
2477  m_destroyOnCloseView = true;
2478  m_isParentFrame = parentFrame;
2479  m_view = view;
2480  if ( m_view )
2481  {
2482  m_view->SetDisplayWindow( this );
2483  }
2484 }
2485 
2487  wxWindow* frame,
2488  wxWindowID id,
2489  const wxString& title,
2490  const wxPoint& pos,
2491  const wxSize& size,
2492  long style,
2493  const wxString& name )
2494  : wxFrame( frame, id, title, pos, size, style, name )
2495 {
2496  m_destroyOnCloseView = true;
2497  m_isParentFrame = true;
2498  m_view = NULL;
2499  if ( m_view )
2500  {
2501  m_view->SetDisplayWindow( this );
2502  }
2503 }
2504 
2506  bool parentFrame,
2507  wxWindow* frame,
2508  a2dView* view,
2509  wxWindowID id,
2510  const wxString& title,
2511  const wxPoint& pos,
2512  const wxSize& size,
2513  long style,
2514  const wxString& name )
2515 {
2516  bool res = wxFrame::Create( frame, id, title, pos, size, style, name );
2517  m_destroyOnCloseView = true;
2518  m_isParentFrame = parentFrame;
2519  m_view = view;
2520  if ( m_view )
2521  {
2522  m_view->SetDisplayWindow( this );
2523  }
2524  return res;
2525 }
2526 
2527 
2529 {
2530 }
2531 
2532 bool a2dDocumentFrame::ProcessConnectedEvent( wxEvent& event )
2533 {
2534  if ( ProcessEvent( event ) )
2535  {
2536  event.Skip( false );
2537  return true;
2538  }
2539  event.Skip( true );
2540  return false;
2541 }
2542 
2543 void a2dDocumentFrame::ConnectEvent( wxEventType type, wxEvtHandler* evtObject )
2544 {
2545  Connect( type, wxObjectEventFunction( &a2dObject::ProcessConnectedEvent ), 0, evtObject );
2546 }
2547 
2548 bool a2dDocumentFrame::DisconnectEvent( wxEventType type, wxEvtHandler* evtObject )
2549 {
2550  return Disconnect( type, wxObjectEventFunction( &a2dObject::ProcessConnectedEvent ), 0, evtObject );
2551 }
2552 
2553 void a2dDocumentFrame::SetView( a2dView* view )
2554 {
2555  m_view = view;
2556 }
2557 
2558 // Clean up frames/windows used for displaying the view.
2559 // They or not really deleted here only flagged for deletion using Destroy(),
2560 // this means that they will really be deleted in idle time by wxWindows.
2561 void a2dDocumentFrame::OnCloseView( a2dCloseViewEvent& event )
2562 {
2563  //there is no need to handle the parent frame differently
2564 
2565  if ( m_view && m_view == event.GetEventObject() )
2566  {
2567  //frames can be destroyed savely ( happening in idle time )
2568  //This default, asumes a multi frame application, where each view has one frame
2569  if ( m_destroyOnCloseView )
2570  Destroy(); //very likely done somewhere else, but makes sure it happens.
2571 
2572  m_view = NULL; //this here prevents looping, when called a second time
2573  //or prevent whatever other of m_view
2574  }
2575 
2576  if ( m_isParentFrame && GetParent() )
2577  GetParent()->Refresh();
2578  else
2579  Refresh();
2580 
2581  // typically event is propogated and handled by the window chain
2582  event.Skip();
2583 }
2584 
2585 void a2dDocumentFrame::OnChangeFilename( a2dViewEvent& event )
2586 {
2587  a2dDocument* doc = ( ( a2dView* )event.GetEventObject() )->GetDocument();
2588 
2589  if ( doc )
2590  {
2591  wxString title = doc->GetPrintableName();
2592 
2593  SetTitle( title );
2594  }
2595 }
2596 
2597 bool a2dDocumentFrame::ProcessEvent( wxEvent& event )
2598 {
2599  static wxEvent* ActiveEvent = NULL;
2600 
2601  // Break recursion loops
2602  if ( ActiveEvent == &event )
2603  return false;
2604 
2605  ActiveEvent = &event;
2606 
2607  bool ret = false;
2608  if ( event.GetEventType() == wxEVT_CLOSE_WINDOW )
2609  {
2610  //window close events should lead to view close events.
2611  //
2612  //In case of the parent frame being closed all other child frames should be closed also.
2613  //Therefore the docmanager closes all documents, the document closes all views, and each view
2614  //sents a view close event to its display window.
2615  //The event is not handled in the window, and goes up to this a2dDocumentFrame.
2616  //The frame will then Destroy the child frame in a multi child application.
2617  //In the parent frame closes its own view. ( the parentFrame already
2618  //has flagged itself for Destroy. )
2619  //
2620  //In case of a child frame being closed only the child view will be closed and the frame flaged
2621  //for Destroy ( see OnCloseView )
2622 
2623  wxCloseEvent& closeevent = ( wxCloseEvent& ) event;
2624 
2625  if ( m_isParentFrame )
2626  {
2627  //First give the Frame the right to veto in for instance a OnCloseWindow which is called by
2628  // the wxEVT_CLOSE_WINDOW handler
2629  if ( wxEvtHandler::ProcessEvent( event ) && !closeevent.GetVeto() )
2630  {
2631  // Define the behaviour for the parent frame closing
2632  // - must delete all child frames except for the main one.
2633  // All Documents will be closed, and because of that views will
2634  // first be disconnected via a2dView::OnDisConnectView().
2635  // This by default also closes the view, and that will normally lead
2636  // to the m_display and parent windows/frames being closed.
2637  // The wxEVT_CLOSE_VIEW generated in a2dView::Close()
2638  // leads via its display window to this a2dDocumentFrame.
2639  // This may decide to destroy the Frame and window associated with the view.
2640 
2641  // You should normally exit the main event loop (and the application) by deleting the top window.
2642  // So if closing the top window, its is clear we want to exit.
2643  if ( wxTheApp->GetTopWindow() == this )
2644  {
2645  if ( !a2dDocviewGlobals->GetDocviewCommandProcessor()->Exit( !closeevent.CanVeto() ) )
2646  closeevent.Veto();
2647  }
2648  else
2649  {
2650  if ( !a2dDocviewGlobals->GetDocviewCommandProcessor()->Clear( !closeevent.CanVeto() ) )
2651  closeevent.Veto();
2652  }
2653  }
2654  else
2655  closeevent.Veto();
2656  ret = true;
2657  }
2658  else
2659  {
2660  //give the Frame the right to veto in for instance a OnCloseWindow which is called by wxEVT_CLOSE
2661  if ( wxEvtHandler::ProcessEvent( event ) && !closeevent.GetVeto() )
2662  {
2663  closeevent.SetCanVeto( false );
2664  if ( m_view )
2665  m_view->ProcessEvent( closeevent );
2666  m_view = NULL;
2667  }
2668  else
2669  closeevent.Veto();
2670  ret = true;
2671  }
2672  }
2673  else if ( event.GetEventType() == wxEVT_ACTIVATE )
2674  {
2675  // the wxEVT_ACTIVATE event should lead to a wxEVT_ACTIVATE_VIEW event here.
2676  // This last event is always sent to a2dDocviewGlobals->GetDocviewCommandProcessor()() from
2677  // within a2dView::Activate()
2678 
2679  if ( m_view && !m_view->IsClosed() )
2680  m_view->ProcessEvent( event );
2681 
2682  ret = wxEvtHandler::ProcessEvent( event );
2683  }
2684  else if ( event.GetEventType() == wxEVT_IDLE )
2685  {
2686  // we need to get idle events to the document of the view, in order to have the document
2687  // sent update events if changed internally.
2688  if ( m_view && !m_view->IsClosed() )
2689  m_view->ProcessEvent( event );
2690 
2691  ret = wxEvtHandler::ProcessEvent( event );
2692  }
2693  else
2694  {
2695  // EVENTS needed for view directly, should be handled above.
2696  // events down here go only to the parent window or commandprocessor
2697 
2698  //In case the event is a commandevent, it will automatically be redirected to the parent window by
2699  // wxEvtHandler::ProcessEvent
2700  //There is no need to handle that case in here.
2701  if ( !wxEvtHandler::ProcessEvent( event ) )
2702  {
2703  // Try the document manager, then do default processing
2705  {
2707  }
2708  else
2709  ret = false;
2710  }
2711  else
2712  ret = true;
2713  }
2714  ActiveEvent = NULL;
2715  return ret;
2716 }
2717 
2718 void a2dDocumentFrame::OnCloseWindow( wxCloseEvent& event )
2719 {
2720  if ( event.CanVeto() )
2721  {
2722  if ( !GetIsParentFrame() )
2723  {
2724  if ( !m_view || m_view->Close( !event.CanVeto() ) )
2725  {
2726  Destroy();
2727  m_view = NULL;
2728  }
2729  else
2730  event.Veto( true );
2731  }
2732  else
2733  {
2734  if ( !a2dDocviewGlobals->GetDocviewCommandProcessor()->Clear( !event.CanVeto() ) )
2735  event.Veto( true );
2736  }
2737  }
2738  else
2739  Destroy();
2740 }
2741 
2742 void a2dDocumentFrame::OnExit( wxCommandEvent& WXUNUSED( event ) )
2743 {
2744  if ( m_isParentFrame )
2745  {
2746  Close( true );
2747  }
2748 }
2749 
2750 void a2dDocumentFrame::OnMRUFile( wxCommandEvent& event )
2751 {
2752  if ( m_isParentFrame )
2753  {
2754  int n = event.GetId() - wxID_FILE1; // the index in MRU list
2756  if ( fileHistItem )
2757  {
2758  // verify that the file exists before doing anything else
2759  if ( wxFile::Exists( fileHistItem->m_filename.GetFullPath() ) )
2760  {
2761  // try to open it
2762  a2dError returncode = a2dDocviewGlobals->GetDocviewCommandProcessor()->CreateDocuments( fileHistItem->m_filename.GetFullPath(), a2dREFDOC_SILENT, fileHistItem->m_docTemplate );
2763  if ( returncode == a2dError_NoDocTemplateRef )
2764  {
2765  a2dDocviewGlobals->ReportError( a2dError_CouldNotCreateDocument, _( "No templates to create document, removed from history, a2dDocumentCommandProcessor::OnMRUFile" ) );
2767  }
2768  }
2769  else
2770  {
2771  a2dDocviewGlobals->ReportErrorF( a2dError_FileHistory, _( "The file '%s' doesn't exist and couldn't be opened.\nIt has been removed from the most recently used files list." ),
2772  fileHistItem->m_filename.GetFullPath().c_str() );
2773 
2774  // remove the bogus filename from the MRU list and notify the user
2775  // about it
2777  }
2778  }
2779  }
2780 }
2781 
2782 void a2dDocumentFrame::OnPaint( wxPaintEvent& WXUNUSED( event ) )
2783 {
2784  wxPaintDC dc( this );
2785  PrepareDC( dc );
2786 
2787  if ( m_view && m_view->GetDisplayWindow() == this )
2788  OnDraw( dc );
2789 }
2790 
2791 // Define the repainting behaviour
2793 {
2794  if ( m_view && m_view->GetDisplayWindow() == this )
2795  m_view->OnDraw( & dc );
2796 }
2797 
2798 void a2dDocumentFrame::OnActivateViewSentFromChild( a2dViewEvent& viewevent )
2799 {
2800  if ( viewevent.GetActive() )
2801  {
2802  m_view = ( a2dView* ) viewevent.GetEventObject();
2803  }
2804 }
2805 
2806 void a2dDocumentFrame::OnCmdMenuId( wxCommandEvent& event )
2807 {
2808  event.Skip();
2809 }
2810 
2812 {
2813  if ( ! GetToolBar() )
2814  return;
2815  Connect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentFrame::OnCmdMenuId ) );
2816 
2817  wxASSERT_MSG( a2dMenuIdItem::GetInitialized(), _T( "call a2dMenuIdItem::InitializeBitmaps() before using AddCmdToToolbar" ) );
2818 
2819  wxString error = _T( "No Bitmap for a2dToolCmd found for:" ) + cmdId.GetIdName();
2820  wxASSERT_MSG( cmdId.GetBitmap().Ok(), error );
2821  GetToolBar()->AddTool( cmdId.GetId(), cmdId.GetLabel(), cmdId.GetBitmap(), cmdId.GetHelp(), cmdId.GetKind() );
2822 }
2823 
2824 void a2dDocumentFrame::ConnectCmdId( const a2dMenuIdItem& cmdId )
2825 {
2826  Connect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentFrame::OnCmdMenuId ) );
2827 }
2828 
2829 void a2dDocumentFrame::AddCmdMenu( wxMenu* parentMenu, wxMenuItem* item )
2830 {
2831  Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentFrame::OnCmdMenuId ) );
2832  parentMenu->Append( item );
2833 }
2834 
2835 void a2dDocumentFrame::AddCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId )
2836 {
2837  Connect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentFrame::OnCmdMenuId ) );
2838  parentMenu->Append( cmdId.GetId(), wxGetTranslation( cmdId.GetText() ), wxGetTranslation( cmdId.GetHelp() ), cmdId.IsCheckable() );
2839 }
2840 
2841 void a2dDocumentFrame::RemoveCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId )
2842 {
2843  Disconnect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentFrame::OnCmdMenuId ) );
2844  parentMenu->Delete( cmdId.GetId() );
2845 }
2846 
2847 void a2dDocumentFrame::OnExecuteCommand( wxCommandEvent& event )
2848 {
2849  a2dCommandStore* command = ( a2dCommandStore* ) event.m_callbackUserData;
2850  a2dDocviewGlobals->GetDocviewCommandProcessor()->Submit( command->m_smrtP->TClone() );
2851 }
2852 
2853 //#endif // wxUSE_DOC_VIEW_ARCHITECTURE
Automatic template, which searches a suitable handler for the document.
Definition: docviewref.h:2576
#define EVT_UPDATE_VIEWS(func)
event from a document when its views need to be updated
Definition: docviewref.h:979
void EnableAllViews(bool enable, a2dView *sender=(a2dView *) NULL)
calls Enable( true/false ) for each view.
virtual void DeleteContents()
called when there is a need to clear the contents of the document.
Definition: docviewref.cpp:373
a2dSmrtPtr< a2dCommandProcessor > m_commandProcessor
A pointer to the command processor associated with this document.
Definition: docviewref.h:1643
void DisassociateViewTemplates()
remove All references to a a2dViewTemplate from the wxViewTemplateReflist
a2dError m_lastError
error code used when LoadObject is returning.
Definition: docviewref.h:1656
virtual void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
Load settings.
a2dDocument * m_documentParent
parant document if set.
Definition: docviewref.h:1640
void ReportViews(a2dViewList *allviews)
sents a ::wxEVT_REPORT_VIEWS to all views, via the a2dDocumentCommandProcessor.
#define EVT_OPEN_DOCUMENT(func)
event for document when a document has been opened
Definition: docviewref.h:963
bool IsModified() const
Has the document been modified.
Definition: docviewref.h:1321
void WriteElement(const wxString &name, const wxString &content=wxT(""), bool newLine=true)
Writes start and end tag.
Definition: genxmlpars.cpp:794
const a2dError a2dError_NoDocTemplateRef
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
static const a2dTemplateFlagMask LOAD_IMPORT
Definition: docviewref.h:228
wxString m_documentTypeName
The document type name given to the a2dDocumentTemplate constructor,.
Definition: docviewref.h:1631
virtual void OnPrint(wxDC *dc, wxObject *info)
called from a2dDocumentPrintout when printing a view.
#define EVT_SAVE_DOCUMENT(func)
event sent to document when a document needs to be saved
Definition: docviewref.h:969
bool IsCheckable() const
get if menu is checkable
Definition: comevt.h:1612
virtual a2dIOHandlerStrIn * GetDocumentIOHandlerForLoad(a2dDocumentInputStream &stream, a2dDocument *document)
if there is an io handler, and it can load the document of this template, return it ...
void OnCloseView(a2dCloseViewEvent &event)
Intercept to do cleanup/veto closing of a view.
Definition: docviewref.cpp:413
XMLeventType Next()
Walks to next element and returns event type.
Definition: genxmlpars.cpp:422
virtual bool Load(a2dDocumentInputStream &stream, wxObject *obj)=0
override to read the stream and store (part of) the contents in to a specific a2dDocument or othere o...
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
extend a2dViewConnector to have a a2dDocumentViewScrolledWindow for each view.
Definition: docviewref.h:3141
#define EVT_NEW_DOCUMENT(func)
event for document when a document new document was created
Definition: docviewref.h:965
void SetFilename(const wxFileName &filename, bool notifyViews=false)
Sets the filename for this document. Usually called by the framework.
a2dViewConnector()
Constructor.
wxClassInfo * m_viewClassInfo
For dynamic creation of appropriate instances.
Definition: docviewref.h:2774
The a2dViewTemplate class is used to model the relationship between a document class and a view class...
Definition: docviewref.h:2635
void RemoveCmdMenu(wxMenu *parentMenu, const a2dMenuIdItem &cmdId)
remove a command menu from the parent menu.
a2dView * GetView()
Gives the a2dView in case of event types concerning a view.
Definition: docviewref.h:774
const a2dError a2dError_CouldNotEvaluatePath
static const a2dTemplateFlagMask SAVE
Definition: docviewref.h:223
wxString GetDirectory() const
Returns the default directory, as passed to the document template constructor.
Definition: docviewref.h:2408
void WriteStartElementAttributes(const wxString &name, bool newLine=true)
Writes start tag which has attributes.
Definition: genxmlpars.cpp:757
const a2dPrintWhat a2dPRINT_Preview
general print preview
Definition: docviewref.cpp:191
const a2dViewTemplateList & GetViewTemplates()
returns a reference to the a2dViewTemplateList, which contains all a2dViewTemplate&#39;s.
Definition: doccom.h:785
bool m_isClosed
set true when document is closed or when busy closing document.
Definition: docviewref.h:1649
a2dDocumentTemplate * GetDocumentTemplate() const
Gets a2dDocumentTemplate pointer which was used to create the a2dView.
Definition: docviewref.h:1389
a2dDocument(a2dDocument *parent=(a2dDocument *) NULL)
Constructor.
Definition: docviewref.cpp:335
Ref Counted base object.
Definition: gen.h:1045
wxPageSetupDialogData * m_pageSetupData
this is the printer page setup data for all views with this template
Definition: docviewref.h:2781
virtual void SetDisplayWindow(wxWindow *display)
Set the display window.
bool Exit(bool force=true)
Called to Exit the application properly.
Definition: doccom.cpp:479
static const a2dTemplateFlagMask DEFAULT
Definition: docviewref.h:227
const a2dError a2dError_NoError
wxWindow * GetDisplayWindow()
Get the display window.
Definition: docviewref.h:1875
void OnExportDocument(a2dDocumentEvent &event)
The default handler for ::wxEVT_EXPORT_DOCUMENT.
Definition: docviewref.cpp:713
a2dObject * Clone(CloneOptions options, a2dRefMap *refs=NULL) const
create an exact copy of this property
Definition: gen.cpp:1199
wxString m_directory
The default directory for files of this type.
Definition: docviewref.h:2524
wxOutputStream a2dDocumentOutputStream
output stream based wxStreams
Definition: gen.h:3458
store a menu Id generated by XRCID( menuIdString ) plus a menustring and helpstring ...
Definition: comevt.h:1563
void OnNewDocument(a2dDocumentEvent &event)
called after creating a new document from a template , in order to initialize it. ...
Definition: docviewref.cpp:502
void ConnectEvent(wxEventType type, wxEvtHandler *eventSink)
Definition: gen.cpp:876
void SetError(a2dError error)
in case of errors when sending an event, this can be set to tell the reason of failure ...
Definition: docviewref.h:799
The a2dDocumentTemplate class is used to model the relationship between a document class and files...
Definition: docviewref.h:2297
static const a2dTemplateFlagMask SAVE_EXPORT
Definition: docviewref.h:229
a2dCommandProcessor * GetCommandProcessor() const
Returns a pointer to the command processor associated with this document.
Definition: docviewref.h:1294
void OnDisConnectView(a2dTemplateEvent &event)
handler for ::wxEVT_DISCONNECT_VIEW
const a2dError a2dError_FileCouldNotOpen
virtual ~a2dViewConnector()=0
destructor
void SetClosed()
sets closed flag to true, and calls Release() view.
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
wxString GetDescription() const
Returns the text description of this template, as passed to the document template constructor...
Definition: docviewref.h:2405
void AddCmdToToolbar(const a2dMenuIdItem &cmdId)
add items to toolbar using a predefined command ID.
void OnDisConnectView(a2dDocumentEvent &event)
handler for ::wxEVT_DISCONNECT_ALLVIEWS
const wxString & GetText() const
get plain text for menu
Definition: comevt.h:1599
void CheckCurrentView(a2dView *view)
Views do inform the document manager when a view will be destroyed.
Definition: doccom.cpp:2156
a2dDocumentPtr m_documentCreate
if set this will be used instead of m_docClassInfo to initiate new documents
Definition: docviewref.h:2539
virtual a2dDocumentInputStream & LoadObject(a2dDocumentInputStream &stream, a2dIOHandlerStrIn *handler)
handling loading of the document from a stream
Definition: docviewref.cpp:942
bool GetEnable()
when ::wxEVT_ENABLE_VIEW get enable value of the event
Definition: docviewref.h:524
a2dView * GetView()
Get the view created.
Definition: docviewref.h:916
#define EVT_SAVEAS_DOCUMENT(func)
event sent to document when a document needs to be saved in a different file
Definition: docviewref.h:971
using a file stream for input, stream the file into a a2dDocument or other object ...
Definition: gen.h:3632
void OnCloseWindow(wxCloseEvent &event)
default for closing this frame via close button.
wxSize m_initialSize
size for new view
Definition: docviewref.h:2759
a2dSmrtPtr< a2dIOHandlerStrOut > m_ioHandlerStrOut
used for writing the document to streams.
Definition: docviewref.h:2545
void Load(wxObject *parent, a2dIOHandlerXmlSerIn &parser)
used by CVG parser
Definition: docviewref.cpp:992
const a2dDocumentTemplateList & GetDocTemplates()
returns a reference to the a2dDocumentTemplateList, which contains all a2dDocumentTemplate&#39;s.
Definition: doccom.h:782
unsigned int a2dTemplateFlagMask
mask of flags for a2dTemplateFlag
Definition: docviewref.h:206
bool SaveAs(const wxFileName &fileTosaveTo=wxFileName(wxT("")), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Tries to save the document by sending a a2dDocumentEvent ::wxEVT_SAVEAS_DOCUMENT event.
Definition: docviewref.cpp:530
see wx/general/smrtptr.h
virtual void OnDraw(wxDC *dc)=0
needs to be implemented to print a view, also so used for simple redrawing of views.
a2dView event, to report events in the a2dView class
Definition: docviewref.h:424
bool m_mark
template is marked
Definition: docviewref.h:246
bool m_askSaveWhenOwned
Set when Owners become zero and document will be deleted. May also be overruled by user...
Definition: docviewref.h:1601
bool m_export
template is for exporting documents
Definition: docviewref.h:254
virtual bool CanLoad(a2dDocumentInputStream &stream, const wxObject *obj=NULL, wxClassInfo *docClassInfo=NULL)=0
Should return true if the handler can read from the stream.
This class is used to connect newly created a2dView&#39;s to a wxFrame and/or wxWindow.
Definition: docviewref.h:2857
wxPoint & GetInitialPosition()
Get position used for new created views or frames or windows.
Definition: docviewref.h:2883
Docview framework its controlling class.
wxString GetContent()
Returns the current content.
Definition: genxmlpars.cpp:570
specialized wxWindow to handle a2dView events
Definition: docviewref.h:3927
#define EVT_ENABLE_VIEWS(func)
event from a document when its views need to be enabled or disabled
Definition: docviewref.h:981
a2dSmrtPtr< a2dView > m_keepalive
Definition: docviewref.h:2251
a2dSmrtPtr< a2dDocument > m_viewDocument
the document to which this view belongs.
Definition: docviewref.h:2225
void OnImportDocument(a2dDocumentEvent &event)
The default handler for ::wxEVT_IMPORT_DOCUMENT.
Definition: docviewref.cpp:799
bool GetActive()
when ::wxEVT_ACTIVATE_VIEW get activation value of the event
Definition: docviewref.h:521
virtual a2dDocument * CreateDocument(const wxFileName &path, a2dDocumentFlagMask flags=a2dREFDOC_NON)
Creates a new document.
bool m_viewEnabled
Is the view enabled?
Definition: docviewref.h:2241
void OnOpenDocument(a2dDocumentEvent &event)
load a document from a file into this document
Definition: docviewref.cpp:874
~a2dDocumentTemplate()
Destructor.
void WriteEndElement(bool newLine=true)
Writes correspondending end tag for the current start tag.
Definition: genxmlpars.cpp:862
base command processor
Definition: comevt.h:829
bool Close(bool force)
Closes the document if not vetod.
Definition: docviewref.cpp:457
const a2dError a2dError_FileHistory
void OnChangeFilename(a2dViewEvent &event)
default handler for file changed event sent from a2dView
const a2dError a2dError_IOHandler
#define EVT_DISCONNECT_ALLVIEWS(func)
event for document before all view are closed.
Definition: docviewref.h:959
void WriteStartDocument(const wxString &version, const wxString &encoding, bool standalone)
Writes the XML header declaration.
Definition: genxmlpars.cpp:723
virtual void Update(unsigned int hint=0, wxObject *hintObject=NULL)
force a2dDocumentEvent ::wxEVT_UPDATE_VIEWS event
virtual void UpdateAllViews(a2dView *sender=(a2dView *) NULL, unsigned int hint=a2dVIEW_UPDATE_ALL, wxObject *objecthint=(wxObject *) NULL)
sent Update events to all a2dView which display or use this document.
bool IsClosed()
A closed flag is set when a view is closed.
Definition: docviewref.h:1829
void SetCanVeto(bool canVeto)
If the event can not be vetod this is set to false.
Definition: docviewref.h:393
a2dSmrtPtr< a2dViewConnector > m_connector
class used to connect new views with Frames and windows.
Definition: docviewref.h:2548
const a2dError a2dError_CouldNotCreateDocument
virtual a2dError CreateDocuments(const wxString &path, a2dDocumentFlagMask documentflags=a2dREFDOC_NON, a2dDocumentTemplate *wantedDocTemplate=NULL, int dialogflags=wxFD_OPEN, a2dTemplateFlagMask docTemplateFlags=a2dTemplateFlag::VISIBLE)
Creates new documents in a manner determined by the flags parameter, which can be: ...
Definition: doccom.cpp:1197
Holds a view on a a2dDocument.
Definition: docviewref.h:1804
void AssociateViewTemplate(a2dViewTemplate *temp)
add a reference to a a2dViewTemplate to the wxViewTemplateReflist
virtual void CreateCommandProcessor()
create a command processor and set it for the document.
wxString m_docTypeName
The named type of the document associated with this template.
Definition: docviewref.h:2533
void OnRemoveView(a2dDocumentEvent &event)
what to do when a view using this document will stop using it.
Definition: docviewref.cpp:429
~a2dView()
destructor
event sent to a2dViewConnector
Definition: docviewref.h:870
#define EVT_REPORT_VIEWS(func)
event from a document when its views need to reported
Definition: docviewref.h:983
a2dView * GetView()
get the pointer to a a2dView to which view events are sent
Definition: docviewref.h:3443
~a2dDocumentFrame()
destructor
#define EVT_ADD_VIEW(func)
event sent to document when a view has been added to the document
Definition: docviewref.h:1005
#define EVT_CLOSE_DOCUMENT(func)
event for document before a document will be closed ( can veto)
Definition: docviewref.h:961
a2dView()
constructor
void OnChangeFilename(a2dDocumentEvent &event)
default handler for file changed event sent from a2dDocument with type wxEVT_CHANGEDFILENAME_DOCUMENT...
void OnCmdMenuId(wxCommandEvent &event)
std list compatible list
Definition: a2dlist.h:42
wxDateTime m_modificationtime
last modification time when this document was stored.
Definition: docviewref.h:1607
a2dDocument * GetDocument()
the document created.
Definition: docviewref.h:903
The document class can be used to model an application&#39;s file-based data.
Definition: docviewref.h:1066
bool m_visible
template is visible
Definition: docviewref.h:244
extend a2dViewConnector to have a a2dDocumentViewScrolledWindow for each view.
Definition: docviewref.h:3129
void DisConnectAllViews()
Disconnect a2dView&#39;s using this document.
Definition: docviewref.cpp:449
const a2dError a2dError_SaveFile
static const a2dTemplateFlagMask NON
Definition: docviewref.h:219
bool Create(bool parentFrame, wxWindow *frame, a2dView *view=NULL, wxWindowID id=-1, const wxString &title=wxT("a2dDocumentFrame"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxT("frame"))
Constructor for two-step-creation (2nd step)
void AddCmdMenu(wxMenu *parentMenu, const a2dMenuIdItem &cmdId)
add a menu to the parent menu, and connect it to the eventhandler of the frame
virtual a2dFileHistoryItem * GetHistoryFileItem(size_t i) const
return the a2dFileHistoryItem of the i&#39;th file in the history
Definition: doccom.cpp:1663
#define EVT_DISCONNECT_VIEW(func)
event sent to connector to disconnect a certain view from its document
Definition: docviewref.h:1015
wxSize m_initialSize
size for new frames
Definition: docviewref.h:2973
void SetDocumentTemplate(a2dDocumentTemplate *temp)
Set a2dDocumentTemplate pointer.
Definition: docviewref.h:1392
bool ProcessEvent(wxEvent &event)
Modified event handler to also sent event to a2dView or wxDocviewCommonEvents.
wxString m_documentTitle
Document title.
Definition: docviewref.h:1614
#define EVT_CHANGEDFILENAME_DOCUMENT(func)
event sent to view when the filename of a document has changed.
Definition: docviewref.h:985
bool Clear(bool force=true)
Clear remaining documents and templates.
Definition: doccom.cpp:469
virtual void ReportError(const a2dError &error, const wxString &errorstr=wxEmptyString)
concatenate to the the error report the given error.
Definition: comevt.cpp:1221
void OnSetFocus(wxFocusEvent &event)
called on (de)activating (wxWindow) containing the view.
virtual bool ProcessEvent(wxEvent &event)
Definition: doccom.cpp:2309
void Veto()
veto the operation (usually it&#39;s allowed by default)
Definition: docviewref.h:751
wxUint16 a2dPrintWhat
defines what to print
Definition: gen.h:4052
Docview classes for document view, window and frame.
const a2dPrintWhat a2dPRINT_PreviewDocument
preview print a2dDocument
Definition: docviewref.cpp:195
long m_documentModified
modified flag
Definition: docviewref.h:1637
void OnAddView(a2dDocumentEvent &event)
what to do when a view starts using this document
Definition: docviewref.cpp:445
virtual bool MakeDefaultName(wxString &buf)
Make a default document name.
Definition: doccom.cpp:1602
bool IsAllowed() const
for implementation code only: is the operation allowed?
Definition: docviewref.h:757
void OnCloseView(a2dCloseViewEvent &event)
::wxEVT_CLOSE_VIEW event handler to do cleanup/veto Close of the view.
The a2dDocumentFrame class provides a default frame for displaying documents.
Definition: docviewref.h:3357
bool m_isClosed
close flag, to indicate that the view is being closed are is closed.
Definition: docviewref.h:2222
const a2dError a2dError_CouldNotLoad
void OnKillFocus(wxFocusEvent &event)
when a view goes out of focus ( when only one view per window
virtual a2dIOHandlerStrOut * GetDocumentIOHandlerForSave(const wxString &filename, a2dDocument *document)
if there is an io handler, and it can save the document of this template, return it ...
wxString GetFileFilter() const
Returns the file filter, as passed to the document template constructor.
Definition: docviewref.h:2411
#define EVT_CLOSE_VIEW(func)
event sent to document and view when a view needs to be closed ( can veto)
Definition: docviewref.h:993
int GetId() const
get id
Definition: comevt.h:1583
a2dDocument * SentPreAddCreatedDocumentEvent(a2dDocument *newDoc, a2dDocumentFlagMask flags)
sents a wxEVT_PRE_ADD_DOCUMENT event to m_connector if available.
void OnEnable(a2dViewEvent &event)
default handler for EVT_ENABLE_VIEW event.
#define EVT_POST_CREATE_DOCUMENT(func)
sent from a doc template after it created a document
Definition: docviewref.h:1011
void Veto(bool veto=true)
use to veto event when the closing of the view needs to be refused in a handler.
Definition: docviewref.h:383
bool m_import
template is for importing documents
Definition: docviewref.h:252
#define EVT_ACTIVATE_VIEW_SENT_FROM_CHILD(func)
event sent from view and its display up the parent chain.
Definition: docviewref.h:1001
void OnChangeTitle(a2dDocumentEvent &event)
default handler for file changed event sent from a2dDocument with type wxEVT_CHANGEDTITLE_DOCUMENT ...
a2dViewTemplate(const wxString &descr, const wxString &docTypeName, const wxString &viewTypeName, wxClassInfo *viewClassInfo=(wxClassInfo *) NULL, a2dViewConnector *connector=(a2dViewConnector *) NULL, long flags=a2dTemplateFlag::DEFAULT, const wxSize &size=wxSize(0, 0))
Associate document and view types. They&#39;re for identifying what view is associated with what template...
wxUint32 m_id
This identifies the view in event processing.
Definition: docviewref.h:2247
a2dSmrtPtr< a2dViewConnector > m_connector
class used to connect new views with Frames and windows.
Definition: docviewref.h:2777
virtual bool Draw(wxDC &context)
Might be used to draw the contents of a document to a a2dView using a wxDc as the drawing context...
bool SentPostCreateDocumentEvent(a2dDocument *newDoc, a2dDocumentFlagMask flags)
sents a wxEVT_POST_CREATE_DOCUMENT called in general from a2dDocumentCommandProcessor() when a new do...
virtual void RemoveFileFromHistory(size_t i)
Remove a file from history.
Definition: doccom.cpp:1644
void Modify(bool mod)
set the docuent as modified or not
static const a2dTemplateFlagMask EXPORTING
Definition: docviewref.h:225
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
bool GetVeto() const
If the event can be vetod this return true.
Definition: docviewref.h:399
wxClassInfo * m_docClassInfo
Run-time class information that allows document instances to be constructed dynamically.
Definition: docviewref.h:2536
help class which makes it possible to store a smart pointer as a wxObject*
Definition: comevt.h:1053
bool Export(a2dDocumentTemplate *doctemplate, const wxFileName &fileTosaveTo=wxFileName(wxT("")), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Tries to save the document by sending a a2dDocumentEvent ::wxEVT_EXPORT_DOCUMENT event.
Definition: docviewref.cpp:700
virtual void OnDraw(wxDC &dc)
Override this function to draw the graphic (or just process EVT_PAINT)
uses a wxFrame to hold new views or to create child wxFrame&#39;s to hold new views.
Definition: docviewref.h:2997
virtual void ClearCommands()
remove all commands stored
Definition: comevt.cpp:1059
void SetFileName(const wxFileName &filename)
set filename of file to open, before sending the event.
Definition: docviewref.h:760
wxFrame * m_docframe
the frame which receives events and often redirect those to the document manager. ...
Definition: docviewref.h:3051
#define EVT_CREATE_DOCUMENT(func)
event sent to document from template when a document has been created
Definition: docviewref.h:967
virtual bool Save(a2dDocumentOutputStream &stream, const wxObject *obj)=0
Override to write to the stream and store (part of) of the document contents in the stream...
void WriteEndAttributes(bool close=false)
&quot;Closes&quot; the start tag after writing all attributes (writes the &quot;&gt;&quot; or &quot;/&gt;&quot; bracket).
Definition: genxmlpars.cpp:837
static const a2dTemplateFlagMask IMPORTING
Definition: docviewref.h:224
void Activate(bool activate)
is called via ProcessEvent() when the view becomes active
virtual bool Submit(a2dCommand *command, bool storeIt=true)
next to the base class submit, it sets a2DocumentCommandProcessor for a2dCommand
Definition: comevt.cpp:842
int m_refcount
how many references to this object do exist
Definition: gen.h:1564
const a2dPrintWhat a2dPRINT_Print
general print
Definition: docviewref.cpp:190
a2dDocumentTemplate * GetDocumentTemplate()
Get the template choosen to import / export.
Definition: docviewref.h:780
void OnSaveDocument(a2dDocumentEvent &event)
Called by wxWindows when a file needs to be saved.
Definition: docviewref.cpp:632
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
Save settings.
wxString m_description
A short description of this template.
Definition: docviewref.h:2765
a2dViewTemplatePtr m_viewTemplate
view was created from this view template or if not used NULL
Definition: docviewref.h:2231
using a file stream for output, stream a a2dDocument or other wxObject into a stream.
Definition: gen.h:3751
const a2dError a2dError_SaveObject
virtual a2dIOHandlerStrIn * GetDocumentIOHandlerForLoad(a2dDocumentInputStream &stream, a2dDocument *document)
if there is an io handler, and it can load the document of this template, return it ...
long m_initialStyle
style for new frames
Definition: docviewref.h:2976
a2dDocumentFlagMask GetFlags()
gives the a2dDocumentFlagMask in case of event types concerning a document.
Definition: docviewref.h:768
bool m_savedYet
saved flag
Definition: docviewref.h:1646
const a2dError a2dError_ImportObject
void OnMRUFile(wxCommandEvent &event)
called by API and only handled if this is the Parent Frame
virtual wxPrintout * OnCreatePrintout(a2dPrintWhat typeOfPrint, const wxPageSetupDialogData &pageSetupData)
called from the a2dDocumentCommandProcessor to create a wxPrintout are derived class ...
a2dDocumentFlagMask GetFlags()
the document flags as set by a2dDocumentTemplate::CreateDocument()
Definition: docviewref.h:908
a2dDocumentFrame()
Constructor for two step creation, call a2dDocumentFrame::Create later.
virtual wxWindow * GetAssociatedWindow() const
Returns a window that can be used as a parent for document-related dialogs. Override if necessary...
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
Save settings.
void OnExit(wxCommandEvent &event)
called by API and only handled if this is the Parent Frame
const a2dError a2dError_Canceled
virtual bool Revert()
Normally should undo all changes by rereading the file again.
#define EVT_CHANGEDTITLE_DOCUMENT(func)
event sent to view when the title of a document has changed.
Definition: docviewref.h:987
void OnCloseView(a2dCloseViewEvent &event)
default for closing a view in this frame
#define EVT_IMPORT_DOCUMENT(func)
event for document when a document will be imported
Definition: docviewref.h:977
wxInputStream a2dDocumentInputStream
input stream based wxStreams
Definition: gen.h:3456
wxString m_description
A short description of this template.
Definition: docviewref.h:2527
~a2dViewTemplate()
Destructor.
static const a2dTemplateFlagMask MARK
Definition: docviewref.h:221
virtual bool CanSave(const wxObject *obj=NULL)=0
Should return true if the handler can write this document to a stream.
wxItemKind GetKind() const
what kind of menu item we are
Definition: comevt.h:1605
wxPoint m_initialPos
position for new frames
Definition: docviewref.h:2970
void OnPaint(wxPaintEvent &event)
default handler for paint events, it calls OnDraw().
a2dDocument * GetDocument() const
get the document of the view
Definition: docviewref.h:1882
a2dDocviewGlobal * a2dDocviewGlobals
a global pointer to get to global instance of important classes.
Definition: doccom.cpp:2348
void ProcessConnectedEvent(wxEvent &event)
wxCHECK_VERSION(2,9,0)
Definition: gen.cpp:855
wxString GetIdName() const
name of the menu coupled to unique id
Definition: comevt.h:1653
wxFileName m_documentFile
Filename associated with this document (&quot;&quot; if none).
Definition: docviewref.h:1604
long GetInitialStyle()
Get style used for new created a2dDocumentFrame.
Definition: docviewref.h:2889
a2dDocumentViewWindow(a2dView *view, wxWindow *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxHSCROLL|wxVSCROLL, const wxString &name=wxT("a2dDocumentViewWindow"))
Constructor for creation with view.
virtual bool Close(bool force=false)
Close a view and remove the view from its document.
wxUint32 GetId()
Get the id of the view (used for identification in event processing.
Definition: docviewref.h:1878
a2dFrameViewConnector()
Constructor.
wxPageSetupDialogData * m_pageSetupData
this is the printer page setup data for all documents with this template
Definition: docviewref.h:2552
wxString GetLabel() const
get label text
Definition: comevt.h:1597
virtual a2dIOHandlerStrOut * GetDocumentIOHandlerForSave(const wxString &filename, a2dDocument *document)
if there is an io handler, and it can save the document of this template, return it ...
bool m_isParentFrame
is this the docframe or not.
Definition: docviewref.h:3597
a2dTemplateFlag m_flags
The flags passed to the constructor.
Definition: docviewref.h:2762
specialized wxScrolledWindow to handle a2dView events
Definition: docviewref.h:3856
virtual a2dView * CreateView(a2dDocument *doc, a2dDocumentFlagMask flags=a2dREFDOC_NON)
Creates a new view for the given document.
#define EVT_CHANGEDFILENAME_VIEW(func)
event sent from view upwards to display, when the filename of a document has changed.
Definition: docviewref.h:1017
~a2dDocumentViewScrolledWindow()
Destructor.
void OnEnableViews(a2dDocumentEvent &event)
default handler for a2dDocumentEvent of type ::wxEVT_ENABLE_VIEWS
wxFileName & GetFileName()
get filename of file to open
Definition: docviewref.h:763
void Require(const XMLeventType &type, wxString name)
Forces a special tag.
Definition: genxmlpars.cpp:390
bool ReleaseObject(T *object)
release a certain object from the list
Definition: smrtptr.inl:118
#define EVT_ENABLE_VIEW(func)
event sent to connector to disable or enable for a certain view
Definition: docviewref.h:1003
a2dViewTemplateList m_viewTemplates
templates for views
Definition: docviewref.h:2979
wxString m_docTypeName
The named type of the document associated with this template.
Definition: docviewref.h:2768
virtual bool ProcessEvent(wxEvent &event)
Extend event processing to search the view&#39;s event table.
print a document
Definition: docviewref.h:3311
void SetViewTypeName(const wxString &name)
set type name of the view.
Definition: docviewref.h:1924
a2dAutoZeroPtr< a2dObject > ** GetAutoZeroPtrList()
return the list head pointer for autozero pointers to this object
Definition: gen.h:1359
a2dDocumentViewScrolledWindow(a2dView *view, wxWindow *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxHSCROLL|wxVSCROLL, const wxString &name=wxT("a2dDocumentViewScrolledWindow"))
Constructor for creation with view.
sent to document before closing
Definition: docviewref.h:558
virtual void ReportErrorF(const a2dError &error, const wxChar *Format,...)
concatenate to the the error report the given error.
Definition: comevt.cpp:1312
wxString GetPrintableName() const
Get title, or filename if no title, else [unnamed].
a2dObject * DoClone(a2dObject::CloneOptions options, a2dRefMap *refs) const
Clone document.
Definition: docviewref.cpp:384
const a2dPrintWhat a2dPRINT_PrintDocument
print a2dDocument
Definition: docviewref.cpp:194
bool GetActive()
return if the view is active/
Definition: docviewref.h:2066
itSmart Find(T *object)
Find a specific object.
Definition: smrtptr.inl:76
~a2dDocumentTemplateAuto()
Destructor.
wxString m_defaultExt
The default extension for files of this type.
Definition: docviewref.h:2530
wxUint32 m_id
This identifies the document in event processing.
Definition: docviewref.h:1653
see a2dDocumentEvent
Definition: docviewref.h:356
a2dDocumentCommandProcessor * GetDocviewCommandProcessor() const
Gets a2dDocumentCommandProcessor pointer.
Definition: doccom.h:1034
virtual a2dView * CreateView(a2dDocument *doc, const wxString &viewTypeName=wxT(""), a2dDocumentFlagMask flags=a2dREFDOC_NON, a2dTemplateFlagMask mask=a2dTemplateFlag::DEFAULT)
create a new view from a list of a2dViewTemplate&#39;s
bool DisconnectEventAll(wxEvtHandler *eventSink)
Remove all dynamic events in classA, going to classB (eventSink)
Definition: gen.cpp:1021
void SetDocumentSaved(bool saved=true)
Sets the document saved flag.
Definition: docviewref.h:1136
void OnUpdate(a2dDocumentEvent &event)
default handler for a2dDocumentEvent ::wxEVT_UPDATE_VIEWS
bool m_active
true if this view is activated ( its display window has the focus and recieves mouse events ) ...
Definition: docviewref.h:2234
used to report a2dDocument events
Definition: docviewref.h:591
static const a2dTemplateFlagMask LOAD
Definition: docviewref.h:222
void SetTitle(const wxString &title, bool notifyViews=false)
Sets the title for this document.
void OnSaveAsDocument(a2dDocumentEvent &event)
default handler for a2dDocumentEvent of type ::wxEVT_SAVEAS_DOCUMENT
Definition: docviewref.cpp:544
wxString m_fileFilter
The file filter (such as *.txt) to be used in file selector dialogs.
Definition: docviewref.h:2521
const a2dError a2dError_ExportFile
wxSize & GetInitialSize()
GGet size used for new created views or frames or windows.
Definition: docviewref.h:2886
bool m_save
template is for saving documents
Definition: docviewref.h:250
wxString m_viewTypeName
The named type of the view associated with this template.
Definition: docviewref.h:2771
bool Enable(bool enable)
returns true if view was enabled/disabled, false if nothing done
wxString GetDocumentTypeName() const
Returns the document type name, as passed to the document template constructor.
Definition: docviewref.h:2426
void SetDocument(a2dDocument *doc)
Set the document for the view and add it to the document its viewlist.
void OnExecuteCommand(wxCommandEvent &event)
void SetDocumentTypeName(const wxString &name)
Sets the document type name for this document. See the comment for documentTypeName.
Definition: docviewref.h:1121
void SetView(a2dView *view)
set a pointer to a a2dView to sent view events to.
bool m_load
template is for loading documents
Definition: docviewref.h:248
const a2dPrintWhat a2dPRINT_PreviewView
preview print a2dView
Definition: docviewref.cpp:193
void OnCreateDocument(a2dDocumentEvent &event)
default handler for ::wxEVT_CREATE_DOCUMENT, Called after creation of document from a template...
a2dTemplateFlag m_flags
The flags passed to the constructor.
Definition: docviewref.h:2518
a2dSmrtPtr< a2dIOHandlerStrIn > m_ioHandlerStrIn
used for reading the document from streams.
Definition: docviewref.h:2542
static const a2dTemplateFlagMask VISIBLE
Definition: docviewref.h:220
specialized wxWindow derived template class to handle a2dView events
Definition: docviewref.h:3630
holds one error report.
Definition: gen.h:623
const a2dPrintWhat a2dPRINT_PrintView
print a2dView
Definition: docviewref.cpp:192
bool Save()
Saves the document by sending a a2dDocumentEvent ::wxEVT_SAVE_DOCUMENT event.
Definition: docviewref.cpp:517
void DisassociateViewTemplate(a2dViewTemplate *temp)
remove a reference to a a2dViewTemplate from the wxViewTemplateReflist
virtual void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
Load settings.
~a2dDocumentViewWindow()
Destructor.
a2dDocumentTemplate(const wxString &descr, const wxString &filter, const wxString &dir, const wxString &ext, const wxString &docTypeName, wxClassInfo *docClassInfo=(wxClassInfo *) NULL, a2dViewConnector *connector=(a2dViewConnector *) NULL, long flags=a2dTemplateFlag::DEFAULT, a2dIOHandlerStrIn *handlerIn=NULL, a2dIOHandlerStrOut *handlerOut=NULL)
Associate document and view types. They&#39;re for identifying what view is associated with what template...
wxWindow * m_display
In case of using a window for displaying the view, this holds the window.
Definition: docviewref.h:2244
virtual a2dViewTemplate * SelectViewType(a2dDocument *doc, const a2dViewTemplateList &list, const wxString &viewTypeName=wxT(""), bool sort=false, a2dTemplateFlagMask viewTemplateFlags=a2dTemplateFlag::VISIBLE)
Returns a view template by asking the user.
Definition: doccom.cpp:1949
void OnReport(a2dDocumentEvent &event)
handler for the ::wxEVT_REPORT_VIEWS
wxString GetDefaultExtension() const
Returns the default file extension for the document data, as passed to the document template construc...
Definition: docviewref.h:2402
bool CheckMask(a2dTemplateFlagMask mask)
Check if given mask matches (flags in mask, or at least set)
Definition: docviewref.cpp:244
static bool GetInitialized()
Are the bitmaps for button bar etc. initlialized?
Definition: comevt.h:1665
void OnCloseDocument(a2dCloseDocumentEvent &event)
called when document is closed
Definition: docviewref.cpp:479
bool Import(a2dDocumentTemplate *doctemplate, const wxFileName &fileToImport=wxFileName(wxT("")), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Tries to read a file into the document by sending a a2dDocumentEvent ::wxEVT_IMPORT_DOCUMENT event...
Definition: docviewref.cpp:786
bool m_destroyOnCloseView
when closing the view the frame will be destroyed.
Definition: docviewref.h:3600
list of a2dObject&#39;s
Definition: gen.h:3157
virtual bool FileMatchesTemplate(const wxString &path)
to test if a file that needs to be loaded, is suitable for this template.
virtual int SaveModifiedDialog(bool canCancel=true)
dialog when the user needs to confirm saving a document
wxString m_viewTypeName
set via the a2dViewTemplate on generation of this view.
Definition: docviewref.h:2228
void Init(wxFrame *docframe, bool createChildframe=true)
The pointer m_docframe will be initialized.
a2dDocumentTemplatePtr m_documentTemplate
A pointer to the template from which this document was created.
Definition: docviewref.h:1634
CloneOptions
options for cloning
Definition: gen.h:1200
~a2dDocument()
destructor
Definition: docviewref.cpp:378
virtual a2dDocumentOutputStream & SaveObject(a2dDocumentOutputStream &stream, a2dIOHandlerStrOut *handler)
handling saving and exporting of the document to a stream
#define EVT_REMOVE_VIEW(func)
event sent to document when a view will be removed from the document
Definition: docviewref.h:1007
a2dSmrtPtr< a2dView > m_view
Definition: docviewref.h:3594
void SetView(a2dView *view)
Set the view created.
Definition: docviewref.h:919
bool CanVeto() const
If the event can be vetod this is set.
Definition: docviewref.h:396
static const a2dTemplateFlagMask ALL
Definition: docviewref.h:226
bool GetEnable()
when ::wxEVT_ENABLE_VIEWS get enable value of the event
Definition: docviewref.h:793
bool m_OnlyDisconnect
see SetOnlyDisconnect()
Definition: docviewref.h:2982
void OnActivateViewSentFromChild(a2dViewEvent &viewevent)
sets m_view to the current active view, generate by a2dView::Activate()
void SetViewTemplate(a2dViewTemplate *viewtemplate)
to set the view template from which this view was created.
Definition: docviewref.h:1917
holds one file for placing in history list
Definition: doccom.h:1067
unsigned int a2dDocumentFlagMask
mask of flags for a2dDocumentFlag
Definition: docviewref.h:200
#define a2dREFOBJECTPTR_KEEPALIVE
Definition: gen.h:1631
wxString GetViewTypeName() const
get type name of the view.
Definition: docviewref.h:1908
#define EVT_EXPORT_DOCUMENT(func)
event for document when a document will be exported
Definition: docviewref.h:975
docviewref.cpp Source File -- Sun Oct 12 2014 17:04:16 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation