wxArt2D
doccom.cpp
Go to the documentation of this file.
1 /*! \file docview/src/doccom.cpp
2  \brief Document/view classes
3  \author Klaas Holwerda
4  \date Created 05/07/2003
5 
6  Copyright: 2001-2004 (C) Klaas Holwerda
7 
8  Licence: wxWidgets licence
9 
10  RCS-ID: $Id: doccom.cpp,v 1.157 2009/09/26 19:01:05 titato Exp $
11 */
12 
13 #include "docviewprec.h"
14 
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18 
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22 
23 // ----------------------------------------------------------------------------
24 // headers
25 // ----------------------------------------------------------------------------
26 
27 #ifndef WX_PRECOMP
28 #include "wx/string.h"
29 #include "wx/utils.h"
30 #include "wx/app.h"
31 #include "wx/dc.h"
32 #include "wx/dialog.h"
33 #include "wx/menu.h"
34 #include "wx/list.h"
35 #include "wx/filedlg.h"
36 #include "wx/intl.h"
37 #endif
38 
39 
40 #ifdef __WXGTK__
41 #include "wx/mdi.h"
42 #endif
43 
44 #if wxUSE_PRINTING_ARCHITECTURE
45 #include "wx/prntbase.h"
46 #include "wx/printdlg.h"
47 #endif
48 
49 #include "wx/msgdlg.h"
50 #include "wx/choicdlg.h"
51 #include "wx/confbase.h"
52 #include "wx/file.h"
53 #include "wx/cmdproc.h"
54 #include "wx/log.h"
55 #include "wx/textdlg.h"
56 
57 #include <wx/tokenzr.h>
58 #include <wx/regex.h>
59 
60 #if wxUSE_PRINTING_ARCHITECTURE
61 #include <wx/paper.h>
62 #endif
63 
64 #include <stdio.h>
65 #include <string.h>
66 
67 #include "wx/docview.h"
68 #include "wx/docview/docviewref.h"
69 #include "wx/general/gen.h"
70 #include "wx/docview/doccom.h"
71 
72 // ----------------------------------------------------------------------------
73 // template instantiations
74 // ----------------------------------------------------------------------------
75 
76 //#include "wx/general/id.inl"
77 
78 #if (defined(__WXMSW__) && defined(WXUSINGDLL) )
79 template class A2DDOCVIEWDLLEXP a2dSmrtPtrList< a2dCommandLanguageWrapper >;
80 #endif
81 
82 // ============================================================================
83 // declarations
84 // ============================================================================
85 
86 DEFINE_EVENT_TYPE( wxEVT_ADD_DOCUMENT )
87 DEFINE_EVENT_TYPE( wxEVT_REMOVE_DOCUMENT )
88 DEFINE_EVENT_TYPE( wxEVT_CHANGED_DOCUMENT )
89 DEFINE_EVENT_TYPE( wxEVT_CANNOT_OPEN_DOCUMENT )
90 
91 //! select one or more files
92 /*!
93  \param message message to display
94  \param default_path path to go for selecting files
95  \param default_filename file to open by default
96  \param indexDefaultExtension Returns the index into the list of filters supplied,
97  optionally, in the wildcard parameter. Before the dialog is shown,
98  this is the index which will be used when the dialog is first displayed.
99  After the dialog is shown, this is the index selected by the user.
100  \param wildcard display files according to this filter
101  \param flags flags for multiple files etc. see wxFileDialog
102  \param parent parent window
103  \param returnPaths all returned files in case fo multiple files selection
104  \param x x display coordinate of dialog
105  \param y y display coordinate of dialog
106 */
107 a2dError a2dFileSelectorEx( const wxString& message = wxFileSelectorPromptStr,
108  const wxString& default_path = wxEmptyString,
109  const wxString& default_filename = wxEmptyString,
110  int* indexDefaultExtension = NULL,
111  const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
112  int flags = 0,
113  wxWindow* parent = NULL,
114  wxArrayString* returnPaths = NULL,
115  int x = wxDefaultCoord, int y = wxDefaultCoord )
116 {
117  wxASSERT_MSG( returnPaths, wxT( "must have return path wxArrayString" ) );
118  returnPaths->Clear();
119 
120  wxFileDialog fileDialog( parent,
121  message,
122  default_path,
123  default_filename,
124  wildcard,
125  flags, wxPoint( x, y ) );
126 
127  //set position to the preferred template
128  if ( indexDefaultExtension && *indexDefaultExtension > 0 )
129  fileDialog.SetFilterIndex( *indexDefaultExtension );
130 
131  if ( fileDialog.ShowModal() == wxID_OK )
132  {
133  if ( indexDefaultExtension )
134  *indexDefaultExtension = fileDialog.GetFilterIndex();
135 
136  if( flags & wxFD_MULTIPLE )
137  fileDialog.GetPaths( *returnPaths );
138  else
139  returnPaths->Add( fileDialog.GetPath() );
140  return a2dError_NoError;
141  }
142  return a2dError_Canceled;
143 }
144 
145 
146 // ----------------------------------------------------------------------------
147 // wxWindows macros
148 // ----------------------------------------------------------------------------
149 IMPLEMENT_DYNAMIC_CLASS( a2dDocumentCommandProcessor, a2dCommandProcessor )
150 
151 //!@{ \ingroup menus
152 DEFINE_MENU_ITEMID( CmdMenu_Exit, wxTRANSLATE("&Exit\tAlt-X"), wxTRANSLATE("Exit application" ) )
153 DEFINE_MENU_ITEMID( CmdMenu_FileClose, wxTRANSLATE("&Close"), wxTRANSLATE("Close current file" ) )
154 DEFINE_MENU_ITEMID( CmdMenu_FileCloseAll, wxTRANSLATE("&Close All"), wxTRANSLATE("Close all open files" ) )
155 DEFINE_MENU_ITEMID( CmdMenu_FileOpen, wxTRANSLATE("&Open"), wxTRANSLATE("Open existing file" ) )
156 DEFINE_MENU_ITEMID( CmdMenu_FileNew, wxTRANSLATE("&New"), wxTRANSLATE("Create new file" ) )
157 DEFINE_MENU_ITEMID( CmdMenu_FileSave, wxTRANSLATE("Save"), wxTRANSLATE("Save file" ) )
158 DEFINE_MENU_ITEMID( CmdMenu_FileSaveAll, wxTRANSLATE("&Save All"), wxTRANSLATE("Save all open files" ) )
159 DEFINE_MENU_ITEMID( CmdMenu_FileSaveAs, wxTRANSLATE("Save &As"), wxTRANSLATE("Save file with different Name" ) )
160 DEFINE_MENU_ITEMID( CmdMenu_FileImport, wxTRANSLATE("&Import"), wxTRANSLATE("Import file into current document" ) )
161 DEFINE_MENU_ITEMID( CmdMenu_FileExport, wxTRANSLATE("&Export"), wxTRANSLATE("Export file to formatX" ) )
162 DEFINE_MENU_ITEMID( CmdMenu_FileRevert, wxTRANSLATE("&Revert"), wxTRANSLATE("reload file" ) )
163 DEFINE_MENU_ITEMID( CmdMenu_CreateView, wxTRANSLATE("&CreateView"), wxTRANSLATE("create a view on current document" ) )
164 DEFINE_MENU_ITEMID( CmdMenu_Print, wxTRANSLATE("Print"), wxTRANSLATE("&Print" ) )
165 DEFINE_MENU_ITEMID( CmdMenu_Preview, wxTRANSLATE("Preview"), wxTRANSLATE("Preview" ) )
166 DEFINE_MENU_ITEMID( CmdMenu_PrintView, wxTRANSLATE("Print View"), wxTRANSLATE("Print View" ) )
167 DEFINE_MENU_ITEMID( CmdMenu_PreviewView, wxTRANSLATE("Preview View"), wxTRANSLATE("Preview Print View" ) )
168 DEFINE_MENU_ITEMID( CmdMenu_PrintDocument, wxTRANSLATE("Print Document"), wxTRANSLATE("Print Document" ) )
169 DEFINE_MENU_ITEMID( CmdMenu_PreviewDocument, wxTRANSLATE("Preview Document"), wxTRANSLATE("Preview Print Document" ) )
170 DEFINE_MENU_ITEMID( CmdMenu_PrintSetup, wxTRANSLATE("Print Setup"), wxTRANSLATE("Setup Print" ) )
171 DEFINE_MENU_ITEMID( CmdMenu_EmptyDocument, wxTRANSLATE("Empty Document"), wxTRANSLATE("Remove contents of document" ) )
172 //!@}
173 
174 // ----------------------------------------------------------------------------
175 // a2dDocumentCommandProcessor
176 // ----------------------------------------------------------------------------
177 
178 
180  EVT_MENU( CmdMenu_Exit().GetId(), a2dDocumentCommandProcessor::OnMenu )
181  EVT_MENU( CmdMenu_FileClose().GetId(), a2dDocumentCommandProcessor::OnMenu )
182  EVT_MENU( CmdMenu_FileCloseAll().GetId(), a2dDocumentCommandProcessor::OnMenu )
183  EVT_MENU( CmdMenu_FileOpen().GetId(), a2dDocumentCommandProcessor::OnMenu )
184  EVT_MENU( CmdMenu_FileNew().GetId(), a2dDocumentCommandProcessor::OnMenu )
185  EVT_MENU( CmdMenu_FileSave().GetId(), a2dDocumentCommandProcessor::OnMenu )
186  EVT_MENU( CmdMenu_FileSaveAll().GetId(), a2dDocumentCommandProcessor::OnMenu )
187  EVT_MENU( CmdMenu_FileSaveAs().GetId(), a2dDocumentCommandProcessor::OnMenu )
188  EVT_MENU( CmdMenu_FileImport().GetId(), a2dDocumentCommandProcessor::OnMenu )
189  EVT_MENU( CmdMenu_FileExport().GetId(), a2dDocumentCommandProcessor::OnMenu )
190  EVT_MENU( CmdMenu_FileRevert().GetId(), a2dDocumentCommandProcessor::OnMenu )
191  EVT_MENU( CmdMenu_CreateView().GetId(), a2dDocumentCommandProcessor::OnMenu )
192  EVT_MENU( CmdMenu_Print().GetId(), a2dDocumentCommandProcessor::OnMenu )
193  EVT_MENU( CmdMenu_Preview().GetId(), a2dDocumentCommandProcessor::OnMenu )
194  EVT_MENU( CmdMenu_PrintView().GetId(), a2dDocumentCommandProcessor::OnMenu )
195  EVT_MENU( CmdMenu_PreviewView().GetId(), a2dDocumentCommandProcessor::OnMenu )
196  EVT_MENU( CmdMenu_PrintDocument().GetId(), a2dDocumentCommandProcessor::OnMenu )
197  EVT_MENU( CmdMenu_PreviewDocument().GetId(), a2dDocumentCommandProcessor::OnMenu )
198  EVT_MENU( CmdMenu_PrintSetup().GetId(), a2dDocumentCommandProcessor::OnMenu )
199  EVT_MENU( CmdMenu_EmptyDocument().GetId(), a2dDocumentCommandProcessor::OnMenu )
200  EVT_UPDATE_UI( CmdMenu_FileOpen().GetId(), a2dDocumentCommandProcessor::OnUpdateFileOpen )
201  EVT_UPDATE_UI( CmdMenu_FileClose().GetId(), a2dDocumentCommandProcessor::OnUpdateFileClose )
202  EVT_UPDATE_UI( CmdMenu_FileCloseAll().GetId(), a2dDocumentCommandProcessor::OnUpdateFileCloseAll )
203  EVT_UPDATE_UI( CmdMenu_FileRevert().GetId(), a2dDocumentCommandProcessor::OnUpdateFileRevert )
204  EVT_UPDATE_UI( CmdMenu_FileNew().GetId(), a2dDocumentCommandProcessor::OnUpdateFileNew )
205  EVT_UPDATE_UI( CmdMenu_FileSave().GetId(), a2dDocumentCommandProcessor::OnUpdateFileSave )
206  EVT_UPDATE_UI( CmdMenu_FileSaveAll().GetId(), a2dDocumentCommandProcessor::OnUpdateFileSaveAll )
207  EVT_UPDATE_UI( CmdMenu_FileSaveAs().GetId(), a2dDocumentCommandProcessor::OnUpdateFileSaveAs )
208  EVT_UPDATE_UI( CmdMenu_CreateView().GetId(), a2dDocumentCommandProcessor::OnUpdateCreateView )
209  EVT_UPDATE_UI( wxID_UNDO, a2dDocumentCommandProcessor::OnUpdateUndo )
210  EVT_UPDATE_UI( wxID_REDO, a2dDocumentCommandProcessor::OnUpdateRedo )
211 
212 #if wxUSE_PRINTING_ARCHITECTURE
213  EVT_UPDATE_UI( CmdMenu_Print().GetId(), a2dDocumentCommandProcessor::OnUpdatePrint )
214  EVT_UPDATE_UI( CmdMenu_Preview().GetId(), a2dDocumentCommandProcessor::OnUpdatePreview )
215 #endif
216 
218  EVT_REMOVE_VIEW( a2dDocumentCommandProcessor::OnRemoveView )
219  EVT_ADD_VIEW( a2dDocumentCommandProcessor::OnAddView )
220 
221  EVT_CANNOT_OPEN_DOCUMENT( a2dDocumentCommandProcessor::OnCannotOpenDocument )
222 
223 END_EVENT_TABLE()
224 
225 a2dDocumentCommandProcessor::a2dDocumentCommandProcessor( long flags, bool WXUNUSED( initialize ), int maxCommands )
226  : a2dCommandProcessor( maxCommands )
227 #if defined(_DEBUG) && defined (SMART_POINTER_DEBUG)
228  , m_initCurrentSmartPointerOwner( this )
229 #endif
230  ,m_preferredImportTemplate( NULL )
231  ,m_preferredExportTemplate( NULL )
232  ,m_preferredOpenTemplate( NULL )
233 {
234  m_defaultDocumentNameCounter = 1;
235  m_flags = flags;
236  m_maxDocsOpen = 10000;
237  m_fileHistory = ( a2dFileHistory* ) NULL;
238 #if wxUSE_PRINTING_ARCHITECTURE
239  m_pageSetupData = new wxPageSetupDialogData;
240 #endif
241  Initialize();
242  m_currentDocument = NULL;
243  m_currentView = ( a2dView* ) NULL;
244  m_busyExit = false;
245 }
246 
247 a2dDocumentCommandProcessor::a2dDocumentCommandProcessor( a2dDocumentCommandProcessor* other )
248  : a2dCommandProcessor( other->m_maxNoCommands )
249 #if defined(_DEBUG) && defined (SMART_POINTER_DEBUG)
250  , m_initCurrentSmartPointerOwner( this )
251 #endif
252 {
254  m_flags = other->m_flags;
255  m_maxDocsOpen = 10000;
256 
257 #if wxUSE_PRINTING_ARCHITECTURE
258  m_pageSetupData = new wxPageSetupDialogData( *other->m_pageSetupData );
259 #endif
261 
263  size_t j;
264  for ( j = 0; j < other->m_fileHistory->GetCount(); j++ )
265  {
266  m_fileHistory->AddFileToHistory( other->GetHistoryFile( j ) );
267  }
268 
269  m_currentDocument = NULL;
270  m_currentView = NULL;
271 
277 
278  m_busyExit = false;
279 }
280 
282 {
283  m_busyExit = true;
284  Clear();
285  if ( m_fileHistory )
286  delete m_fileHistory;
287 #if wxUSE_PRINTING_ARCHITECTURE
288  if( m_pageSetupData )
289  delete m_pageSetupData;
290 #endif
291 }
292 
293 void a2dDocumentCommandProcessor::OnMenu( wxCommandEvent& event )
294 {
295  if ( event.GetId() == CmdMenu_Exit().GetId() )
296  {
297  Exit( false );
298  }
299  else if ( event.GetId() == CmdMenu_FileClose().GetId() )
300  {
301  FileClose( false );
302  }
303  else if ( event.GetId() == CmdMenu_FileCloseAll().GetId() )
304  {
305  CloseDocuments( false );
306  }
307  else if ( event.GetId() == CmdMenu_FileOpen().GetId() )
308  {
309  a2dDocumentPtr doc = NULL;
310  a2dError result = FileOpen( doc, wxFileName( wxT( "" ) ), a2dTemplateFlag::VISIBLE | a2dTemplateFlag::LOAD );
311  if ( !doc )
312  {
313  if ( result == a2dError_Canceled )
314  {
315  }
316  }
317  }
318  else if ( event.GetId() == CmdMenu_FileNew().GetId() )
319  {
320  a2dDocumentPtr doc;
321  a2dError result = FileNew( doc );
322  }
323  else if ( event.GetId() == CmdMenu_FileSave().GetId() )
324  {
325  FileSave();
326  }
327  else if ( event.GetId() == CmdMenu_FileSaveAll().GetId() )
328  {
329  FileSaveAll();
330  }
331  else if ( event.GetId() == CmdMenu_FileSaveAs().GetId() )
332  {
333  FileSaveAs();
334  }
335  else if ( event.GetId() == CmdMenu_FileImport().GetId() )
336  {
337  FileImport();
338  }
339  else if ( event.GetId() == CmdMenu_FileExport().GetId() )
340  {
341  FileExport();
342  }
343  else if ( event.GetId() == CmdMenu_FileRevert().GetId() )
344  {
345  FileRevert();
346  }
347  else if ( event.GetId() == CmdMenu_CreateView().GetId() )
348  {
350  }
351  else if ( event.GetId() == CmdMenu_Print().GetId() )
352  {
354  }
355  else if ( event.GetId() == CmdMenu_PrintView().GetId() )
356  {
358  }
359  else if ( event.GetId() == CmdMenu_PreviewView().GetId() )
360  {
362  }
363  else if ( event.GetId() == CmdMenu_PrintDocument().GetId() )
364  {
366  }
367  else if ( event.GetId() == CmdMenu_PreviewDocument().GetId() )
368  {
370  }
371  else if ( event.GetId() == CmdMenu_PrintSetup().GetId() )
372  {
373  PrintSetup( a2dPRINT_PrintSetup );
374  }
375  else if ( event.GetId() == CmdMenu_EmptyDocument().GetId() )
376  {
377  if ( !m_currentDocument )
378  {
380  return;
381  }
382 
384 
386  {
388  return;
389  }
391  }
393 }
394 
396 {
397 }
398 
400 {
402 
403  if ( m_fileHistory )
404  delete m_fileHistory;
406 }
407 
409 {
410  if ( !m_currentDocument )
411  return false;
412 
414  return false;
415 
416  return m_currentDocument->GetCommandProcessor()->Submit( command, storeIt );
417 }
418 
420 {
421  bool all = true;
422 
423  a2dDocumentList::iterator iter = m_docs.begin();
424  while( iter != m_docs.end() )
425  {
426  //An extra reference to make absolutely sure that the document is deleted HERE,
427  //and not deep down in views or documents.
428  //If we don't do this some other call may already release the document from here, while closing
429  //and event resulting from that are not yet finished. A typical case is that
430  // a2dDocumentCommandProcessor::FileClose() is called by the user after removing view from a document,
431  // unaware that it will be released to soon that way.
432  a2dDECLARE_LOCAL_ITEM( a2dDocumentList::value_type, doc, *iter );
433 
434  iter++;
435  if ( doc->Close( force ) || force )
436  {
437  // in case of non veto in document closing, this already did happen,
438  // but if force is true this makes sure it happens.
439  doc->DisConnectAllViews();
440 
441  // release document from a2dDocumentCommandProcessor
442  // This assumes that documents are not connected in
443  // any way, i.e. deleting one document does NOT
444  // delete another.
445  RemoveDocument( doc );
446 
447  // normally the views for this document should have bin closed/disconnected already.
448  // And therefore m_currentView and m_currentDocument already be different or al least NULL.
449  // In case not we leaf this in a save state.
450  if ( m_currentDocument && m_currentDocument == doc )
451  {
452  m_currentDocument = NULL;
453  if ( m_currentView && m_currentView->GetDocument() == doc )
454  m_currentView = NULL;
455  }
456  }
457  else
458  all = false;
459 
460  }
461  if ( all )
462  {
463  m_currentView = NULL;
464  m_currentDocument = NULL;
465  }
466  return all;
467 }
468 
470 {
471  if ( !CloseDocuments( force ) )
472  return false;
473 
474  m_docTemplates.clear();
475  m_viewTemplates.clear();
476  return true;
477 }
478 
480 {
481  if ( m_busyExit )
482  return true;
483  m_busyExit = true;
484 
485  if ( !CloseDocuments( force ) )
486  {
487  m_busyExit = false;
489  if ( !doc )
490  {
491  a2dDocument* docFirst = *m_docs.begin();
492  SetCurrentDocument( docFirst );
493  }
494  return false;
495  }
496 
497  OnExit();
498 
499  // the next will destroy all child window of view on documents
500  if ( Clear( force ) )
501  {
502  // e.g. toplevel windows, which or not THE toplevel window.
503 
504  // now check if the exit is via the windows close mechanism, or a script line.
505  // In case of window close, the toplevel window is already marked for destroy.
506  wxFrame* pf = ( wxFrame* ) wxTheApp->GetTopWindow();
507  if ( wxTopLevelWindows.Find( pf ) && !wxPendingDelete.Member( pf ) )
508  {
509  pf->Close( true );
510  }
511  return true;
512  }
513  return false;
514 }
515 
517 {
518  return new a2dFileHistory;
519 }
520 
522 {
524  if ( !doc )
525  return false;
526 
527  if ( doc->Close( force ) ) // if not vetod, closes the view(s) of this document
528  {
529  RemoveDocument( doc );
530  return true;
531  }
532  return false;
533 }
534 
536 {
537  doc = NULL;
538  a2dError result;
539  result = CreateDocuments( wxT( "" ), a2dREFDOC_NEW | a2dREFDOC_INIT, NULL, wxFD_OPEN, docTemplateFlags );
540  if ( result == a2dError_NoError )
541  doc = m_docs.back();
542  else if ( result == a2dError_Canceled )
543  doc = NULL;
544  else
545  {
546  a2dDocviewGlobals->ReportError( result, _( "could not create document, a2dDocumentCommandProcessor::FileNew" ) );
547  doc = NULL;
548  }
549 
550  return result;
551 }
552 
553 a2dError a2dDocumentCommandProcessor::FileOpen( a2dDocumentPtr& doc, const wxFileName& file, a2dTemplateFlagMask docTemplateFlags )
554 {
555  a2dError result ;
556  wxString filename = file.GetFullPath();
557 
558  doc = NULL;
559  if ( filename.IsEmpty() )
560  {
561  result = CreateDocuments( wxT( "" ), a2dREFDOC_NON, NULL, wxFD_OPEN, docTemplateFlags );
562  if ( result == a2dError_NoError )
563  doc = m_docs.back();
564  else if ( result == a2dError_Canceled )
565  doc = NULL;
566  else if ( result == a2dError_FileVersion )
567  {
568  doc = NULL;
569  }
570  else if ( result == a2dError_NoDocTemplateRef )
571  {
572  a2dDocviewGlobals->ReportError( a2dError_CouldNotCreateDocument, _( "No templates, could not create document, a2dDocumentCommandProcessor::FileOpen" ) );
573  doc = NULL;
574  }
575  else
576  {
577  a2dDocviewGlobals->ReportError( result, _( "could not create document, a2dDocumentCommandProcessor::FileOpen" ) );
578  doc = NULL;
579  }
580  }
581  else
582  {
583  a2dPathList path;
584  path.Add( wxT( "." ) );
585  if ( !path.ExpandPath( filename ) )
586  {
587  a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotEvaluatePath, _( "Could not expand %s resulted in %s" ), file.GetFullPath().c_str(), filename.c_str() );
589  return result;
590  }
591  result = CreateDocuments( filename, a2dREFDOC_SILENT, NULL, wxFD_OPEN, docTemplateFlags );
592  if ( result == a2dError_NoError )
593  doc = m_docs.back();
594  else if ( result == a2dError_Canceled )
595  doc = NULL;
596  else if ( result == a2dError_NoDocTemplateRef )
597  {
598  a2dDocviewGlobals->ReportError( a2dError_CouldNotCreateDocument, _( "No templates, could not create document, a2dDocumentCommandProcessor::FileOpen" ) );
599  doc = NULL;
600  }
601  else
602  {
603  a2dDocviewGlobals->ReportError( result, _( "could not create document, a2dDocumentCommandProcessor::FileOpen" ) );
604  doc = NULL;
605  }
606  }
607 
608  // returns (a2dDocument*) NULL if creation fails
609  return result;
610 }
611 
612 a2dError a2dDocumentCommandProcessor::FileOpenCheck( a2dDocumentPtr& doc, const wxFileName& file, bool checkModification )
613 {
614  a2dError result ;
615 
616  wxString filename = file.GetFullPath();
617  wxASSERT_MSG( ! filename.IsEmpty(), wxT( "need a filename that is not empty" ) );
618 
619  doc = NULL;
620  if ( filename.IsEmpty() )
621  {
622  result = CreateDocuments( wxT( "" ), a2dREFDOC_NON, NULL, wxFD_OPEN, a2dTemplateFlag::VISIBLE | a2dTemplateFlag::LOAD );
623  if ( result == a2dError_NoError )
624  doc = m_docs.back();
625  else if ( result == a2dError_Canceled )
626  doc = NULL;
627  else if ( result == a2dError_NoDocTemplateRef )
628  {
629  a2dDocviewGlobals->ReportError( a2dError_CouldNotCreateDocument, _( "No templates, could not create document, a2dDocumentCommandProcessor::FileOpen" ) );
630  doc = NULL;
631  }
632  else
633  {
634  a2dDocviewGlobals->ReportError( result, _( "could not create document, a2dDocumentCommandProcessor::FileOpen" ) );
635  doc = NULL;
636  }
637  }
638  else
639  {
640  bool alreadyOpen = false;
641 
642  a2dDocumentList::iterator iter = m_docs.begin();
643  while( iter != m_docs.end() )
644  {
645  a2dDocumentPtr doc = *iter;
646  if ( doc->GetFilename().GetFullPath() == filename )
647  {
648  alreadyOpen = true;
649  break;
650  }
651  iter++;
652  }
653  if ( !alreadyOpen )
654  {
655  return FileOpen( doc, file );
656  }
657  else
658  {
659  doc = *iter;
660 
661  wxDateTime dtAccess;
662  wxDateTime dtMod;
663  wxDateTime dtCreate;
664  file.GetTimes( &dtAccess, &dtMod, &dtCreate );
665 
666  if ( dtMod > doc->GetModificationTime() )
667  return FileOpen( doc, file );
668 
669  size_t n = 0;
670 
671  a2dDocumentTemplate* useDocTemplate = doc->GetDocumentTemplate();
672  if ( !useDocTemplate )
673  {
674  // check is there is only one template visible, meaning we do not have to choose one.
676  {
677  a2dDocumentTemplateList::value_type temp = *iter;
678  if ( temp->CheckMask( a2dTemplateFlag::VISIBLE ) )
679  {
680  if ( n == 0 )
681  useDocTemplate = temp;
682  n ++;
683  }
684  }
685 
686  if ( n == 0 )
687  {
689  }
690  }
691  useDocTemplate->SentPostCreateDocumentEvent( doc, a2dREFDOC_NON );
692  }
693  }
694  return result;
695 }
696 
697 a2dError a2dDocumentCommandProcessor::FilesOpen( const wxString& openPath, int dialogFlags, a2dTemplateFlagMask mask )
698 {
699  a2dError result;
700  wxString expandedPath = openPath;
701  a2dPathList path;
702  path.Add( wxT( "." ) );
703  if ( !path.ExpandPath( expandedPath ) )
704  {
705  a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotEvaluatePath, _( "Could not expand %s resulted in %s" ), openPath.c_str(), expandedPath.c_str() );
707  return result;
708  }
709  result = CreateDocuments( openPath, a2dREFDOC_NON, NULL, dialogFlags, mask );
710  if ( result == a2dError_NoError )
711  {
712  }
713  else if ( result == a2dError_Canceled )
714  {
715  }
716  else
717  {
718  a2dDocviewGlobals->ReportError( result, _( "could not create document, a2dDocumentCommandProcessor::FilesOpen" ) );
719  }
720 
721  return result;
722 }
723 
725 {
727  if ( !doc )
728  return false;
729  doc->Revert();
730  return true;
731 }
732 
734 {
736  if ( !doc )
737  return false;
738  bool result = doc->Save();
739 
740  // keep trac of last used directory
741  m_lastDirectory = doc->GetFilename().GetPath();
743  if ( result )
744  AddFileToHistory( doc->GetFilename().GetFullPath() );
745 
746  return true;
747 }
748 
750 {
751  a2dDocumentList::iterator iter = m_docs.begin();
752  while( iter != m_docs.end() )
753  {
754  a2dDECLARE_LOCAL_ITEM( a2dDocumentList::value_type, doc, *iter );
755  if ( doc && doc->IsModified() )
756  {
757  bool result = doc->Save();
758  if ( result )
759  AddFileToHistory( doc->GetFilename().GetFullPath() );
760  }
761  iter++;
762  }
763  return true;
764 }
765 
767 {
769  if ( !doc )
770  return false;
771 
772  a2dPathList path;
773  path.Add( wxT( "." ) );
774  wxString foundfile = file.GetFullPath();
775  if ( !path.ExpandPath( foundfile ) )
776  {
777  a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotEvaluatePath, _( "Could not expand %s resulted in %s" ), file.GetFullPath().c_str(), foundfile.c_str() );
778  return false;
779  }
780 
781  bool result = doc->SaveAs( foundfile, flags );
782  // keep trac of last used directory
783  m_lastDirectory = doc->GetFilename().GetPath();
785  AddFileToHistory( doc->GetFilename().GetFullPath() );
786  return result;
787 }
788 
789 bool a2dDocumentCommandProcessor::FileExport( const wxFileName& file, const wxString& description, a2dDocumentFlagMask flags )
790 {
792  if ( !doc )
793  return false;
794 
795  // Find the templates for this type of document.
796  a2dDocumentTemplate* docTemplate = NULL;
797  a2dDocumentTemplate* preferredExportTemplate = NULL;
798  size_t n = 0;
799  a2dDocumentTemplateList onlyThisDocTemplates;
801  {
802  a2dDocumentTemplateList::value_type temp = *iter;
803  if ( temp->CheckMask( a2dTemplateFlag::EXPORTING ) )
804  {
805  // check on description, or else on file extension.
806  if ( ( description.IsEmpty() && !file.GetExt().IsEmpty() && file.GetExt() == temp->GetDefaultExtension() ) ||
807  temp->GetDescription() == description ||
808  file.GetExt().IsEmpty()
809  )
810  {
811  if ( temp->GetDocumentTypeName() == doc->GetDocumentTemplate()->GetDocumentTypeName() &&
812  ( !temp->GetDocumentIOHandlerStrOut() || temp->GetDocumentIOHandlerStrOut()->CanSave( doc ) )
813  )
814  {
815  onlyThisDocTemplates.push_back( temp );
816  docTemplate = temp;
817  n++;
818  if ( m_preferredExportTemplate == temp )
819  preferredExportTemplate = temp;
820  }
821  }
822  }
823  }
824 
825  if ( !docTemplate )
826  {
827  a2dDocviewGlobals->ReportErrorF( a2dError_NoDocTemplateRef, _( "Sorry, there is no document template for exporting this document." ) );
828  return false;
829  }
830 
831  a2dPathList path;
832  path.Add( wxT( "." ) );
833  wxString foundfile = file.GetFullPath();
834  if ( !path.ExpandPath( foundfile ) )
835  {
836  a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotEvaluatePath, _( "Could not expand %s resulted in %s" ), file.GetFullPath().c_str(), foundfile.c_str() );
837  return false;
838  }
839 
840  wxString fileName( foundfile );
841  wxString dir, name, ext;
842  wxFileName::SplitPath( fileName, & dir, & name, & ext );
843 
844  if ( n > 1 )
845  {
846  //reset the preferred template if not in the list of templates.
847  if ( !preferredExportTemplate )
849  else if ( dir.IsEmpty() && !m_preferredExportTemplate->GetDirectory().IsEmpty() )
851  // let the user choose a template and file.
852  wxArrayString selectedPaths;
853  a2dError result = SelectDocumentPath(
854  _( "Export File" ),
855  onlyThisDocTemplates,
856  dir,
858  &selectedPaths,
859  &docTemplate,
860  /*wxHIDE_READONLY |*/ wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
863  if( result == a2dError_NoError )
864  {
865  foundfile = selectedPaths.Item( 0 );
866  docTemplate->SetDirectory( wxPathOnly( foundfile ) );
867  m_preferredExportTemplate = docTemplate;
868  }
869  else if( result == a2dError_Canceled )
870  {
871  return false;
872  }
873  else
874  {
875  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "suitable template I/O handler for loading not available in document templates." ) );
876  return false;
877  }
878  }
879  else if ( !( flags & a2dREFDOC_SILENT ) )
880  {
881  foundfile = wxFileSelector( _( "Export as" ),
882  docTemplate->GetDirectory(),
883  foundfile,
884  docTemplate->GetDefaultExtension(),
885  docTemplate->GetFileFilter(),
886  wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
887  doc->GetAssociatedWindow() );
888  }
889 
890  if ( ext.IsEmpty() )
891  {
892  fileName += wxT( "." );
893  fileName += docTemplate->GetDefaultExtension();
894  }
895 
896  // let the user choose a template and file if not found
897  return doc->Export( docTemplate, foundfile, flags );
898 }
899 
900 bool a2dDocumentCommandProcessor::FileImport( const wxFileName& file, const wxString& description, a2dDocumentFlagMask flags )
901 {
903  if ( !doc )
904  return false;
905 
906  // Find the templates for this type of document.
907  a2dDocumentTemplate* docTemplate = NULL;
908  a2dDocumentTemplate* preferredImportTemplate = NULL;
909  size_t n = 0;
910  a2dDocumentTemplateList onlyThisDocTemplates;
912  {
913  a2dDocumentTemplateList::value_type temp = *iter;
914  if ( temp->CheckMask( a2dTemplateFlag::IMPORTING ) )
915  {
916  // check on description, or else on file extension.
917  if ( ( description.IsEmpty() && !file.GetExt().IsEmpty() && file.GetExt() == temp->GetDefaultExtension() ) ||
918  temp->GetDescription() == description ||
919  file.GetExt().IsEmpty()
920  )
921  {
922  if ( temp->GetDocumentTypeName() == doc->GetDocumentTemplate()->GetDocumentTypeName() &&
923  ( !temp->GetDocumentIOHandlerStrOut() || temp->GetDocumentIOHandlerStrOut()->CanSave( doc ) )
924  )
925  {
926  onlyThisDocTemplates.push_back( temp );
927  docTemplate = temp;
928  n++;
929  if ( m_preferredImportTemplate == temp )
930  preferredImportTemplate = temp;
931  }
932  }
933  }
934  }
935 
936  if ( !docTemplate )
937  {
938  a2dDocviewGlobals->ReportErrorF( a2dError_NoDocTemplateRef, _( "Sorry, there is no document template for importing this document." ) );
939  return false;
940  }
941 
942  a2dPathList path;
943  path.Add( wxT( "." ) );
944  wxString foundfile = file.GetFullPath();
945  if ( !path.ExpandPath( foundfile ) )
946  {
947  a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotEvaluatePath, _( "Could not expand %s resulted in %s" ), file.GetFullPath().c_str(), foundfile.c_str() );
948  return false;
949  }
950 
951  wxString fileName( foundfile );
952  wxString dir, name, ext;
953  wxFileName::SplitPath( fileName, & dir, & name, & ext );
954 
955  if ( n > 1 )
956  {
957  //reset the preferred template if not in the list of templates.
958  if ( !preferredImportTemplate )
960  else if ( dir.IsEmpty() && !m_preferredImportTemplate->GetDirectory().IsEmpty() )
962  // let the user choose a template and file.
963  wxArrayString selectedPaths;
964  a2dError result = SelectDocumentPath(
965  _("File import"),
966  onlyThisDocTemplates,
967  dir,
969  &selectedPaths,
970  &docTemplate,
971  wxFD_OPEN,
974  if( result == a2dError_NoError )
975  {
976  foundfile = selectedPaths.Item( 0 );
977  docTemplate->SetDirectory( wxPathOnly( foundfile ) );
978  m_preferredImportTemplate = docTemplate;
979  }
980  else if( result == a2dError_Canceled )
981  {
982  return false;
983  }
984  else
985  {
986  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "suitable template I/O handler for import not available in document templates." ) );
987  return false;
988  }
989  }
990  else if ( !( flags & a2dREFDOC_SILENT ) )
991  {
992  foundfile = wxFileSelector( _( "Import" ),
993  docTemplate->GetDirectory(),
994  foundfile,
995  docTemplate->GetDefaultExtension(),
996  docTemplate->GetFileFilter(),
997  wxFD_OPEN,
998  doc->GetAssociatedWindow() );
999  }
1000 
1001  if ( ext.IsEmpty() )
1002  {
1003  fileName += wxT( "." );
1004  fileName += docTemplate->GetDefaultExtension();
1005  }
1006 
1007  // let the user choose a template and file if not found
1008  return doc->Import( docTemplate, foundfile, flags );
1009 }
1010 
1011 
1013 {
1014 #if wxUSE_PRINTING_ARCHITECTURE
1015  a2dView* view = GetCurrentView();
1016  if ( !view )
1017  return false;
1018 
1019  wxPageSetupDialogData* aPageSetupData = NULL;
1020  if ( view && view->GetViewTemplate() )
1021  aPageSetupData = view->GetViewTemplate()->GetPageSetupData();
1022  if( !aPageSetupData )
1023  {
1024  a2dDocument* aDoc = GetCurrentDocument();
1025  if ( aDoc && aDoc->GetDocumentTemplate() )
1026  aPageSetupData = aDoc->GetDocumentTemplate()->GetPageSetupData();
1027  }
1028  if( !aPageSetupData )
1029  aPageSetupData = GetPageSetupData();
1030 
1031  wxPrintDialogData printDialogData( aPageSetupData->GetPrintData() );
1032 
1033  wxPrintout* printout = view->OnCreatePrintout( printWhat, *aPageSetupData );
1034  if ( printout )
1035  {
1036  wxPrinter printer( &printDialogData );
1037  if( printer.Print( view->GetDisplayWindow(), printout, true ) )
1038  aPageSetupData->SetPrintData( printer.GetPrintDialogData().GetPrintData() );
1039 
1040  delete printout;
1041  }
1042 #endif // wxUSE_PRINTING_ARCHITECTURE
1043  return true;
1044 }
1045 
1047 {
1048 #if wxUSE_PRINTING_ARCHITECTURE
1049  a2dView* view = GetCurrentView();
1050  if ( !view )
1051  return false;
1052  wxPageSetupDialogData* aPageSetupData = NULL;
1053  if ( view && view->GetViewTemplate() )
1054  aPageSetupData = view->GetViewTemplate()->GetPageSetupData();
1055  if( !aPageSetupData )
1056  {
1057  a2dDocument* aDoc = GetCurrentDocument();
1058  if ( aDoc && aDoc->GetDocumentTemplate() )
1059  aPageSetupData = aDoc->GetDocumentTemplate()->GetPageSetupData();
1060  }
1061  if( !aPageSetupData )
1062  aPageSetupData = GetPageSetupData();
1063 
1064  wxPrintDialogData printDialogData( aPageSetupData->GetPrintData() );
1065 
1066  wxPrintout* printout = view->OnCreatePrintout( printWhat, *aPageSetupData );
1067  if ( printout )
1068  {
1069  // Pass two printout objects: for preview, and possible printing.
1070  wxPrintPreviewBase* preview = ( wxPrintPreviewBase* ) NULL;
1071  preview = new wxPrintPreview( printout, view->OnCreatePrintout( printWhat, *aPageSetupData ), &printDialogData );
1072  if ( !preview->Ok() )
1073  {
1074  delete preview;
1075  wxMessageBox( _( "Sorry, print preview needs a printer to be installed." ) );
1076  return false;
1077  }
1078 
1079  wxPreviewFrame* frame = new wxPreviewFrame( preview, ( wxFrame* )wxTheApp->GetTopWindow(), _( "Print Preview" ),
1080  wxPoint( 100, 100 ), wxSize( 600, 650 ) );
1081  frame->Centre( wxBOTH );
1082  frame->Initialize();
1083  frame->Show( true );
1084  }
1085 #endif // wxUSE_PRINTING_ARCHITECTURE
1086  return true;
1087 }
1088 
1089 void a2dDocumentCommandProcessor::SetPageSetupData( wxPageSetupDialogData* pageSetupData )
1090 {
1091 #if wxUSE_PRINTING_ARCHITECTURE
1092  if( m_pageSetupData )
1093  delete m_pageSetupData;
1094  m_pageSetupData = pageSetupData;
1095 #endif
1096 }
1097 
1099 {
1100 #if wxUSE_PRINTING_ARCHITECTURE
1101  wxPageSetupDialogData* aPageSetupData = GetPrintSetup( printWhat );
1102  wxPageSetupDialog pageSetupDialog( ( wxFrame* )wxTheApp->GetTopWindow(), aPageSetupData );
1103  pageSetupDialog.ShowModal();
1104  *aPageSetupData = pageSetupDialog.GetPageSetupData();
1105 #endif // wxUSE_PRINTING_ARCHITECTURE
1106  return true;
1107 }
1108 
1110 {
1111  wxPageSetupDialogData* d;
1112 
1113  if ( m_pageSetupData )
1114  d = m_pageSetupData;
1115  else
1116  d = new wxPageSetupDialogData();
1117 
1118  d->SetDefaultInfo(true); // set PSD_RETURNDEFAULT flag
1119  // This doesn't actually show any dialog thanks to the
1120  // above flag; it returns default data instead.
1121 
1122 #ifdef __WXGTK__
1123  wxPageSetupDialog pageSetupDialog(NULL, d);
1124  if ( pageSetupDialog.ShowModal() != wxID_OK )
1125  { /* fail somehow */ }
1126 
1127  if ( !m_pageSetupData )
1128  delete d;
1129 
1130  return pageSetupDialog.GetPageSetupData();
1131 #else
1132  wxPageSetupDialog pageSetupDialog(NULL, d);
1133  if ( pageSetupDialog.ShowModal() != wxID_OK )
1134  { /* fail somehow */ }
1135  d->SetDefaultInfo(false); // set PSD_RETURNDEFAULT flag
1136 
1137  if ( !m_pageSetupData )
1138  delete d;
1139 
1140  return pageSetupDialog.GetPageSetupData();
1141 #endif
1142 }
1143 
1145 {
1146 #if wxUSE_PRINTING_ARCHITECTURE
1147 
1148  wxPageSetupDialogData* aPageSetupData = NULL;
1149 
1150  if ( printWhat == a2dPRINT_PrintView )
1151  {
1152  a2dView* view = GetCurrentView();
1153  if ( view && view->GetViewTemplate() )
1154  aPageSetupData = view->GetViewTemplate()->GetPageSetupData();
1155  }
1156  else if ( printWhat == a2dPRINT_PrintDocument || printWhat == a2dPRINT_PreviewDocument )
1157  {
1158  a2dDocument* aDoc = GetCurrentDocument();
1159  if ( aDoc && aDoc->GetDocumentTemplate() )
1160  aPageSetupData = aDoc->GetDocumentTemplate()->GetPageSetupData();
1161  }
1162  else if ( printWhat == a2dPRINT_PrintSetup )
1163  {
1164  a2dView* view = GetCurrentView();
1165  if ( view && view->GetViewTemplate() )
1166  aPageSetupData = view->GetViewTemplate()->GetPageSetupData();
1167  if ( !aPageSetupData )
1168  {
1169  a2dDocument* aDoc = GetCurrentDocument();
1170  if ( aDoc && aDoc->GetDocumentTemplate() )
1171  aPageSetupData = aDoc->GetDocumentTemplate()->GetPageSetupData();
1172  }
1173  }
1174  else
1175  aPageSetupData = GetPageSetupData();
1176 
1177  if ( !aPageSetupData )
1178  aPageSetupData = GetPageSetupData();
1179 
1180  return aPageSetupData;
1181 #endif // wxUSE_PRINTING_ARCHITECTURE
1182  return NULL;
1183 }
1184 
1186 {
1187  return m_currentView;
1188 }
1189 
1191 {
1192  a2dDocument* newDoc = event.GetDocument();
1193  newDoc->DisConnectAllViews();
1194  newDoc->DeleteContents();
1195 }
1196 
1198  a2dDocumentTemplate* wantedDocTemplate,
1199  int dialogflags,
1200  a2dTemplateFlagMask docTemplateFlags )
1201 {
1202  // remember last used template
1203  size_t n = 0;
1204  if ( !wantedDocTemplate )
1205  {
1206  // check is there is only one template visible, meaning we do not have to choose one.
1208  {
1209  a2dDocumentTemplateList::value_type temp = *iter;
1210  if ( temp->CheckMask( docTemplateFlags ) )
1211  {
1212  if ( n == 0 )
1213  wantedDocTemplate = temp;
1214  n ++;
1215  }
1216  }
1217 
1218  if ( n == 0 )
1219  {
1221  }
1222  }
1223  else
1224  n = 1;
1225 
1226  //in an application with only one view and document,
1227  //the application wants to close ( and save ) the document when creating a new document.
1228  //so call Close to generate a a2dCloseDocumentEvent.
1229  //In such a case m_maxDocsOpen should be one.
1230 
1231  // If we've reached the max number of docs, close the
1232  // first one.
1233  if ( m_docs.size() >= m_maxDocsOpen )
1234  {
1235  a2dDECLARE_LOCAL_ITEM( a2dDocumentList::value_type, doc, m_docs.front() );
1236  //The handler that intercepts EVT_CLOSE_DOCUMENT must decide to Save and/or Empty the document
1237  if ( doc->Close( false ) )
1238  {
1239  doc->DisConnectAllViews();
1240  RemoveDocument( doc );
1241  }
1242  else
1243  {
1244  //clean up
1245  return a2dError_ToManyOpen;
1246  }
1247  }
1248 
1249  // New document: user chooses a template, unless there's only one or one was given as input.
1250  if ( documentflags & a2dREFDOC_NEW )
1251  {
1252  a2dDocumentTemplate* fileTemplate = ( a2dDocumentTemplate* ) NULL;
1253  if ( n == 1 )
1254  fileTemplate = wantedDocTemplate;
1255  else
1256  fileTemplate = SelectDocumentType( false, docTemplateFlags ); //choose document template from list of templates
1257 
1258  if ( fileTemplate )
1259  {
1260  a2dDocumentList openedDocList;
1261  a2dSmrtPtr< a2dDocument > newDoc = fileTemplate->CreateDocument( path, documentflags );
1262 
1263  // arrived here, the new document is ready for use. But the document is not loaded or initiated yet.
1264  // For that the wxEVT_NEW_DOCUMENT will take care.
1265  if ( newDoc )
1266  {
1267  a2dDocumentEvent event( wxEVT_NEW_DOCUMENT );
1268  event.SetEventObject( newDoc );
1269  newDoc->ProcessEvent( event );
1270 
1271  if ( !event.IsAllowed() )
1272  {
1273  // The document was already created, but since it is vetod, it will be deleted.
1274  // The next makes sure to leaf application in a stable state. Either last active view or NULL.
1276  //newDoc will be released if Veto was set.
1277  return a2dError_Canceled;
1278  }
1279 
1280  a2dDocument* ret = fileTemplate->SentPreAddCreatedDocumentEvent( newDoc, documentflags );
1281 
1282  //and only now if the new document is not closed because document data may have bin merged/copied
1283  //to another already opened document. In that case ret contains that document.
1284  if ( ret == newDoc && !newDoc->IsClosed() ) // really use this new document?
1285  {
1286  // add the document because every thing is properly set
1287  AddDocument( newDoc );
1288  fileTemplate->SentPostCreateDocumentEvent( newDoc, documentflags );
1289  // add the new document to opened documents list which update all views
1290  openedDocList.push_back( newDoc );
1291 
1292  // arrived here, the new document is ready and its views ( and related windows )
1293  // are in place.
1294 
1295  // now that frames and views are created, set the filename once more, this will generate proper events
1296  // for setting e.g. title of frames
1297  newDoc->SetFilename( newDoc->GetFilename(), true );
1298  newDoc->SetTitle( newDoc->GetTitle(), true );
1299  }
1300  }
1301  else
1302  {
1304  }
1305 
1306  a2dDocumentList::iterator iter = openedDocList.begin();
1307  for( ; iter != openedDocList.end(); iter++ )
1308  {
1309  a2dDocument* aDoc = *iter;
1310  // in the previous often view are created, are existing views
1311  // are connected, update them now.
1312  aDoc->UpdateAllViews();
1313  }
1314  return a2dError_NoError;
1315 
1316  }
1317  else
1318  {
1320  }
1321  }
1322 
1323  //Create new documents using the path to the file or by selecting a file or more.
1324  a2dDocumentTemplate* fileTemplate = ( a2dDocumentTemplate* ) NULL;
1325 
1326  wxArrayString selectedPaths;
1327 
1328  if ( documentflags & a2dREFDOC_SILENT )
1329  {
1330  if ( n == 1 )
1331  {
1332  fileTemplate = wantedDocTemplate;
1333  selectedPaths.Add( path );
1334  }
1335  else
1336  {
1337  // find a template which is able to load this file ( use file ext or iohandler of template )
1338  fileTemplate = FindTemplateForPath( m_docTemplates, path ); //File extension or format test to find template
1339  if( fileTemplate )
1340  selectedPaths.Add( path ); // just one file is selected this way.
1341  else
1342  {
1344  }
1345  }
1346  }
1347  else
1348  {
1349  if ( n == 1 )
1350  {
1351  a2dDocumentTemplateList docTemplates;
1352  docTemplates.push_back( wantedDocTemplate );
1353  fileTemplate = wantedDocTemplate;
1354  wxString pathInOut = path;
1355  // selection of one or more files.
1356  if( a2dError_NoError == SelectDocumentPath( _("File Open"), docTemplates, pathInOut, documentflags, &selectedPaths, &fileTemplate, dialogflags, docTemplateFlags, m_preferredOpenTemplate ) )
1357  {
1358  m_preferredOpenTemplate = fileTemplate;
1359  m_lastDirectory = pathInOut;
1360  }
1361  else
1362  return a2dError_Canceled;
1363  }
1364  else
1365  {
1366  wxString pathInOut = path;
1367  // selection of one or more files.
1368  if( a2dError_NoError == SelectDocumentPath( _("File Open"), m_docTemplates, pathInOut, documentflags, &selectedPaths, &fileTemplate, dialogflags, docTemplateFlags, m_preferredOpenTemplate ) )
1369  {
1370  m_preferredOpenTemplate = fileTemplate;
1371  m_lastDirectory = pathInOut;
1372  }
1373  else
1374  return a2dError_Canceled;
1375  }
1376  }
1377 
1378  // the selected files are in selectedPaths
1379  if ( fileTemplate )
1380  {
1381  fileTemplate->SetDirectory( m_lastDirectory );
1382 
1383  // start creating documents + views for all opened files.
1384  a2dDocumentList openedDocList; // temporary list of document added here, will be used to update its views.
1386  for( size_t i = 0; i < selectedPaths.GetCount(); i++ )
1387  {
1388  newDoc = fileTemplate->CreateDocument( selectedPaths[i], documentflags );
1389 
1390  // arrived here, the new document is ready for use. But the document is not loaded or initiated yet.
1391  // For that the wxEVT_OPEN_DOCUMENT will take care.
1392  if ( newDoc )
1393  {
1394  a2dDocumentEvent eventopen( wxEVT_OPEN_DOCUMENT );
1395  eventopen.SetFileName( selectedPaths.Item( i ) );
1396  eventopen.SetEventObject( newDoc );
1397  if ( !newDoc->ProcessEvent( eventopen ) || !eventopen.IsAllowed() )
1398  {
1399  a2dCommandEvent event( wxEVT_CANNOT_OPEN_DOCUMENT, newDoc );
1400  event.SetEventObject( this );
1401  ProcessEvent( event );
1402  return eventopen.GetError();
1403  }
1404 
1405  a2dDocument* ret = fileTemplate->SentPreAddCreatedDocumentEvent( newDoc, documentflags );
1406 
1407  //and only now if the new document is not closed because document data may have bin merged/copied
1408  //to another already opened document. In that case ret contains that document.
1409  if ( ret == newDoc && !newDoc->IsClosed() ) // really use this new document?
1410  {
1411  // add the document because every thing is properly set
1412  AddDocument( newDoc );
1413  AddFileToHistory( selectedPaths.Item( i ), fileTemplate );
1414 
1415  fileTemplate->SentPostCreateDocumentEvent( newDoc, documentflags );
1416  // add the new document to opened documents list which update all views
1417  openedDocList.push_back( newDoc );
1418 
1419  // arrived here, the new document is ready and its views ( and related windows )
1420  // are in place.
1421 
1422  // now that frames and views are created, set the filename once more, this will generate proper events
1423  // for setting e.g. title of frames
1424  newDoc->SetFilename( newDoc->GetFilename(), true );
1425  newDoc->SetTitle( newDoc->GetTitle(), true );
1426  }
1427  }
1428  else
1429  {
1431  }
1432  }
1433  a2dDocumentList::iterator iter = openedDocList.begin();
1434  for( ; iter != openedDocList.end(); iter++ )
1435  {
1436  a2dDocument* aDoc = *iter;
1437  // in the previous often views are created, or existing views are connected, update them now.
1438  aDoc->UpdateAllViews();
1439  }
1440 
1441  return a2dError_NoError;
1442  }
1443 
1445 }
1446 
1448  a2dDocument* newDoc, const wxString& viewTypeName,
1449  a2dDocumentFlagMask documentflags,
1450  a2dTemplateFlagMask documentTemplateFlags,
1451  a2dTemplateFlagMask viewTemplateFlags )
1452 {
1453  AddCreatedDocument( newDoc, false, false, documentflags, documentTemplateFlags );
1454  return CreateView( newDoc, viewTypeName, documentflags, viewTemplateFlags );
1455 }
1456 
1458  bool sentPreAddCreatedDocumentEvent, bool sentPostCreateDocumentEvent,
1459  a2dDocumentFlagMask documentflags,
1460  a2dTemplateFlagMask docTemplateFlags )
1461 {
1462  //search a template for it.
1463  a2dDocumentTemplate* foundtemplate = 0;
1464 
1465  // in case the template is set already, use it.
1466  if ( !newDoc->GetDocumentTemplate() )
1467  {
1469  {
1470  a2dDocumentTemplateList::value_type temp = *iter;
1471  if ( temp->CheckMask( docTemplateFlags ) )
1472  {
1473  if ( temp->GetDocumentTypeName() == newDoc->GetDocumentTypeName() )
1474  {
1475  foundtemplate = temp;
1476  break;
1477  }
1478  }
1479  }
1480  }
1481 
1482  wxASSERT_MSG( foundtemplate,
1483  _( "a2dDocumentCommandProcessor::AddCreatedDocument Could not find template for document type name" ) );
1484 
1485  wxASSERT_MSG( foundtemplate->GetDocumentTypeName() == newDoc->GetDocumentTypeName(),
1486  _( "a2dDocumentCommandProcessor::AddCreatedDocument template DocumentTypeName different from document" ) );
1487 
1488  if ( !foundtemplate )
1490 
1491  //in an application with only one view and document,
1492  //the application wants to close ( and save ) the document when creating a new document.
1493  //so call Close to generate a a2dCloseDocumentEvent.
1494  //In such a case m_maxDocsOpen should be one.
1495 
1496  // If we've reached the max number of docs, close the
1497  // first one.
1498  if ( m_docs.size() >= m_maxDocsOpen )
1499  {
1500  a2dDocument* doc = GetDocuments().front();
1501  //The handler that intercepts EVT_CLOSE_DOCUMENT must decide to Save and/or Empty the document
1502  if ( doc->Close( false ) )
1503  {
1504  doc->DisConnectAllViews();
1505  RemoveDocument( doc );
1506  }
1507  else
1508  {
1509  //clean up
1510  return a2dError_Canceled;
1511  }
1512  }
1513 
1514  //instead of the document template generating a new document,
1515  //here we already have that document, and we set things as if template did create the new document.
1516  newDoc->SetFilename( wxFileName( wxT( "" ) ) );
1517  newDoc->CreateCommandProcessor();
1518  newDoc->SetDocumentTypeName( foundtemplate->GetDocumentTypeName() );
1519  newDoc->SetDocumentTemplate( foundtemplate );
1520  a2dDocumentEvent event( wxEVT_NEW_DOCUMENT );
1521  event.SetEventObject( newDoc );
1522  newDoc->ProcessEvent( event );
1523 
1524  if ( !event.IsAllowed() )
1525  {
1526  //newDoc will be released if Veto was set.
1527  return a2dError_Canceled;
1528  }
1529 
1530  if ( sentPreAddCreatedDocumentEvent )
1531  {
1532  foundtemplate->SentPreAddCreatedDocumentEvent( newDoc, documentflags );
1533  }
1534 
1535  //now add the document because every thing is properly set
1536  AddDocument( newDoc );
1537 
1538  if ( sentPostCreateDocumentEvent )
1539  {
1540  foundtemplate->SentPostCreateDocumentEvent( newDoc, documentflags );
1541 
1542  // in the previous often view are created, are existing views
1543  // are connected, update them now.
1544  newDoc->UpdateAllViews();
1545  }
1546 
1547  return a2dError_NoError;
1548 }
1549 
1550 a2dView* a2dDocumentCommandProcessor::CreateView( a2dDocument* doc, const wxString& viewTypeName,
1551  a2dDocumentFlagMask flags, a2dTemplateFlagMask viewTemplateFlags )
1552 {
1553  //let the user/program choose a view from the list
1554  a2dViewTemplate* temp = SelectViewType( doc, m_viewTemplates, viewTypeName, false, viewTemplateFlags );
1555  if ( temp )
1556  {
1557  return temp->CreateView( doc, flags );
1558  }
1559 
1560  wxASSERT_MSG( viewTypeName.IsEmpty(), _( "a2dDocumentCommandProcessor::CreateView could not find template of given type" ) );
1561 
1562  return ( a2dView* ) NULL;
1563 }
1564 
1565 // Not yet implemented
1567 {
1569  iter = m_docTemplates.Find( temp );
1570  if ( m_docTemplates.end() != iter )
1571  {
1572  m_docTemplates.erase( iter );
1573  }
1574 }
1575 
1576 // Not yet implemented
1577 bool a2dDocumentCommandProcessor::FlushDoc( a2dDocument* WXUNUSED( doc ) )
1578 {
1579  return false;
1580 }
1581 
1583 {
1584  if ( m_currentDocument )
1585  return m_currentDocument;
1586  else
1587  return ( a2dDocument* ) NULL;
1588 }
1589 
1591 {
1592  if ( !m_currentDocument )
1593  return NULL;
1594 
1596  return NULL;
1597 
1599 }
1600 
1601 // Make a default document name
1603 {
1604  name.Printf( _( "unnamed%d" ), m_defaultDocumentNameCounter );
1606 
1607  return true;
1608 }
1609 
1610 // Make a frame title (override this to do something different)
1611 // If docName is empty, a document is not currently active.
1612 wxString a2dDocumentCommandProcessor::MakeFrameTitle( a2dDocument* doc, const wxString& modifiedIndicator )
1613 {
1614  wxString appName = wxTheApp->GetAppName();
1615  wxString title;
1616  if ( !doc )
1617  title = appName;
1618  else
1619  {
1620  wxString docName = doc->GetPrintableName();
1621 
1622  if ( doc->IsModified() )
1623  docName = docName + modifiedIndicator;
1624 
1625  title = docName + wxString( wxT( " - " ) ) + appName;
1626  }
1627  return title;
1628 }
1629 
1630 
1631 // Not yet implemented
1633 {
1634  return FindTemplateForPath( m_docTemplates, path ); //File extension or format test to find template
1635 }
1636 
1637 // File history management
1638 void a2dDocumentCommandProcessor::AddFileToHistory( const wxFileName& file, a2dDocumentTemplate* docTemplate, a2dViewTemplate* viewTemplate )
1639 {
1640  if ( m_fileHistory )
1641  m_fileHistory->AddFileToHistory( file, docTemplate, viewTemplate );
1642 }
1643 
1645 {
1646  if ( m_fileHistory )
1647  m_fileHistory->RemoveFileFromHistory( i );
1648 }
1649 
1651 {
1652  wxString histFile;
1653 
1654  if ( m_fileHistory )
1655  {
1656  a2dFileHistoryItem* item = m_fileHistory->GetHistoryFileItem( i );
1657  if ( item )
1658  histFile = item->m_filename.GetFullPath();
1659  }
1660  return histFile;
1661 }
1662 
1664 {
1665  if ( m_fileHistory )
1666  return m_fileHistory->GetHistoryFileItem( i );
1667  return NULL;
1668 }
1669 
1671 {
1672  if ( m_fileHistory )
1673  m_fileHistory->UseMenu( menu );
1674 }
1675 
1677 {
1678  if ( m_fileHistory )
1679  m_fileHistory->RemoveMenu( menu );
1680 }
1681 
1682 #if wxUSE_CONFIG
1683 void a2dDocumentCommandProcessor::FileHistoryLoad( wxConfigBase& config )
1684 {
1685  if ( m_fileHistory )
1686  m_fileHistory->Load( config );
1687 }
1688 
1689 void a2dDocumentCommandProcessor::FileHistorySave( wxConfigBase& config )
1690 {
1691  if ( m_fileHistory )
1692  m_fileHistory->Save( config );
1693 }
1694 #endif
1695 
1697 {
1698  if ( m_fileHistory )
1699  m_fileHistory->AddFilesToMenu( menu );
1700 }
1701 
1703 {
1704  if ( m_fileHistory )
1705  m_fileHistory->AddFilesToMenu();
1706 }
1707 
1709 {
1710  if ( m_fileHistory )
1711  return m_fileHistory->GetCount();
1712  else
1713  return 0;
1714 }
1715 
1716 
1717 // Find out the document template via matching in the document file format
1718 // against that of the template
1720 {
1721  a2dDocumentTemplate* theTemplate = ( a2dDocumentTemplate* ) NULL;
1722 
1723  // Find the template which this extension corresponds to
1724  const_forEachIn( a2dDocumentTemplateList, &docTemplates )
1725  {
1726  a2dDocumentTemplateList::value_type temp = *iter;
1727  if ( temp->FileMatchesTemplate( path ) && temp->CheckMask( mask ) )
1728  {
1729  theTemplate = temp;
1730  break;
1731  }
1732  }
1733  return theTemplate;
1734 }
1735 
1736 // Try to get a more suitable parent frame than the top window,
1737 // for selection dialogs. Otherwise you may get an unexpected
1738 // window being activated when a dialog is shown.
1740 {
1741  wxWindow* parent = wxTheApp->GetTopWindow();
1742 
1743  wxWindow* focusWindow = wxWindow::FindFocus();
1744  if ( focusWindow )
1745  {
1746  while ( focusWindow &&
1747  !focusWindow->IsKindOf( CLASSINFO( wxDialog ) ) &&
1748  !focusWindow->IsKindOf( CLASSINFO( wxFrame ) ) )
1749 
1750  focusWindow = focusWindow->GetParent();
1751 
1752  if ( focusWindow )
1753  parent = focusWindow;
1754  }
1755  return parent;
1756 }
1757 
1758 // Prompts user to open one or more files, using file specs in templates.
1760  const wxString& title,
1761  const a2dDocumentTemplateList& docTemplates,
1762  wxString& path,
1763  a2dDocumentFlagMask WXUNUSED( flags ),
1764  wxArrayString* selectedPaths,
1765  a2dDocumentTemplate** chosenTemplate,
1766  int dialogflags,
1767  a2dTemplateFlagMask docTemplateFlags,
1768  const a2dDocumentTemplate* preferedTemplate )
1769 {
1770  wxString descrBuf;
1771  int FilterIndex = -1;
1772 
1773  // We can only have multiple filters in Windows and GTK
1774 #if defined(__WXMSW__) || defined(__WXGTK__)
1775 
1776  // search visible filters, and get position of preferred template
1777  int filterCount = 0;
1778  const_forEachIn( a2dDocumentTemplateList, &docTemplates )
1779  {
1780  a2dDocumentTemplateList::value_type temp = *iter;
1781  if ( temp->CheckMask( docTemplateFlags ) )
1782  {
1783  if( temp == preferedTemplate )
1784  FilterIndex = filterCount;
1785 
1786  filterCount++;
1787  // add a '|' to separate this filter from the previous one
1788  if ( !descrBuf.IsEmpty() )
1789  descrBuf << wxT( '|' );
1790 
1791  descrBuf << temp->GetDescription()
1792  << wxT( " (" ) << temp->GetFileFilter() << wxT( ") |" )
1793  << temp->GetFileFilter();
1794  }
1795  }
1796 #else
1797  descrBuf << wxT( "*.*" );
1798 #endif
1799 
1800  // if not given a specific directory to open in, use template dir
1801  if ( path.IsEmpty() )
1802  {
1803  // use last directory chosen for this specific type of document, as was stored in the template
1804  if ( preferedTemplate )
1805  path = preferedTemplate->GetDirectory();
1806  else if ( docTemplates.size() )
1807  path = docTemplates.front()->GetDirectory(); //just the first
1808  }
1809 
1810  wxWindow* parent = wxFindSuitableParent();
1811 
1812  *chosenTemplate = ( a2dDocumentTemplate* )NULL;
1813 
1814  if ( a2dError_Canceled == a2dFileSelectorEx( title, path, wxT( "" ), &FilterIndex,
1815  descrBuf, dialogflags, parent, selectedPaths ) )
1816  return a2dError_Canceled; // since canceled file dialog
1817 
1818  if ( selectedPaths->GetCount() )
1819  {
1820  if ( dialogflags & wxFD_OPEN )
1821  {
1822  // check files for existence
1823  for( size_t i = 0; i < selectedPaths->GetCount(); i++ )
1824  if( !wxFileExists( selectedPaths->Item( i ) ) )
1825  {
1826  wxString msgTitle;
1827  if ( !wxTheApp->GetAppName().IsEmpty() )
1828  msgTitle = wxTheApp->GetAppName();
1829  else
1830  msgTitle = wxString( _( "File error" ) );
1831 
1832  wxString buf;
1833  buf.Printf( _( "Sorry, could not open the file: %s\n" ), selectedPaths->Item( i ).c_str() );
1834  wxMessageBox( buf , msgTitle, wxOK | wxICON_EXCLAMATION );
1836  }
1837  }
1838  path = wxPathOnly( selectedPaths->Item( 0 ) );
1839 
1840  // first find the template that was choosen in file dialog, if this fails (i.e.
1841  // wxFileSelectorEx() didn't fill it), then use the path
1842  if ( FilterIndex != -1 )
1843  {
1844  int n = 0;
1845  const_forEachIn( a2dDocumentTemplateList, &docTemplates )
1846  {
1847  a2dDocumentTemplateList::value_type temp = *iter;
1848  // use same filter as used for descrBuf above.
1849  if ( temp->CheckMask( docTemplateFlags ) )
1850  {
1851  if ( n == FilterIndex )
1852  {
1853  *chosenTemplate = temp;
1854  break;
1855  }
1856  // count 'n' here because FilterIndex = filterCount which count if temp->CheckMask( docTemplateFlags )
1857  n++;
1858  }
1859  }
1860  }
1861  // if not found, use the path to find a template
1862  if ( dialogflags & wxFD_OPEN && !*chosenTemplate )
1863  *chosenTemplate = FindTemplateForPath( docTemplates, path );
1864 
1865  return a2dError_NoError;
1866  }
1867  return a2dError_NoSelection;
1868 }
1869 
1871 {
1872  wxArrayString strings;
1873 
1874  a2dDocumentTemplate** templates = new a2dDocumentTemplate *[m_docTemplates.size()];
1875  int n = 0;
1876 
1878  {
1879  a2dDocumentTemplateList::value_type temp = *iter;
1880  if ( temp->CheckMask( docTemplateFlags ) )
1881  {
1882  int j;
1883  bool want = true;
1884  for ( j = 0; j < n; j++ )
1885  {
1886  //filter out NOT unique document combinations
1887  if ( temp->GetDocumentTypeName() == templates[j]->GetDocumentTypeName() )
1888  want = false;
1889  }
1890 
1891  if ( want )
1892  {
1893  strings.Add( temp->GetDescription() );
1894  templates[n] = temp;
1895  n ++;
1896  }
1897  }
1898  } // for
1899 
1900  if ( sort )
1901  {
1902  strings.Sort(); // ascending sort
1903  // Yes, this will be slow, but template lists
1904  // are typically short.
1905  int i;
1906  n = strings.Count();
1907  for ( i = 0; i < n; i++ )
1908  {
1910  {
1911  a2dDocumentTemplateList::value_type temp = *iter;
1912  if ( strings[i] == temp->GetDescription() )
1913  templates[i] = temp;
1914  }
1915  }
1916  }
1917 
1918  a2dDocumentTemplate* theTemplate;
1919 
1920  switch ( n )
1921  {
1922  case 0:
1923  // no visible templates, hence nothing to choose from
1924  theTemplate = NULL;
1925  break;
1926 
1927  case 1:
1928  // don't propose the user to choose if he heas no choice
1929  theTemplate = templates[0];
1930  break;
1931 
1932  default:
1933  // propose the user to choose one of several
1934  theTemplate = ( a2dDocumentTemplate* )wxGetSingleChoiceData
1935  (
1936  _( "Select a document template" ),
1937  _( "Templates" ),
1938  strings,
1939  ( void** )templates,
1941  );
1942  }
1943 
1944  delete[] templates;
1945 
1946  return theTemplate;
1947 }
1948 
1950  const a2dViewTemplateList& list,
1951  const wxString& viewTypeName,
1952  bool sort,
1953  a2dTemplateFlagMask mask )
1954 {
1955  if ( !viewTypeName.IsEmpty() )
1956  {
1957  //a specific view type is asked for, search it and return it.
1959  {
1960  a2dViewTemplateList::value_type temp = *iter;
1961  if ( temp->GetViewTypeName() == viewTypeName )
1962  {
1963  return temp;
1964  }
1965  }
1966  return ( a2dViewTemplate* )NULL;
1967  }
1968 
1969  wxArrayString strings;
1970  a2dViewTemplate** templates = new a2dViewTemplate *[list.size()];
1971 
1972  int n = 0;
1973 
1974  //fill new array of templates with wanted views
1976  {
1977  a2dViewTemplateList::value_type temp = *iter;
1978  if ( !temp->GetViewTypeName().empty() && temp->CheckMask( mask ) &&
1979  temp->GetDocumentTypeName() == doc->GetDocumentTypeName() )
1980  {
1981  strings.Add( temp->GetViewTypeName() );
1982  templates[n] = temp;
1983  n ++;
1984  }
1985  }
1986 
1987  if ( sort )
1988  {
1989  strings.Sort();
1990 
1991  // Yes, this will be slow, but template lists
1992  // are typically short.
1993  int i;
1994  n = strings.Count();
1995  for ( i = 0; i < n; i++ )
1996  {
1998  {
1999  a2dViewTemplateList::value_type temp = *iter;
2000  if ( strings[i] == temp->GetViewTypeName() )
2001  {
2002  templates[i] = temp;
2003  }
2004  }
2005  }
2006  }
2007 
2008  a2dViewTemplate* theTemplate;
2009 
2010  switch ( n )
2011  {
2012  case 0:
2013  // no visible templates, hence nothing to choose from
2014  theTemplate = ( a2dViewTemplate* )NULL;
2015  break;
2016 
2017  case 1:
2018  // don't propose the user to choose if he has no choice
2019  theTemplate = templates[0];
2020  break;
2021 
2022  default:
2023  // propose the user to choose one of several
2024  theTemplate = ( a2dViewTemplate* )wxGetSingleChoiceData
2025  (
2026  wxString::Format( _( "Select a document view for the file %s" ), doc->GetFilename().GetFullName().c_str() ),
2027  _( "Views" ),
2028  strings,
2029  ( void** )templates,
2031  );
2032 
2033  }
2034 
2035  delete[] templates;
2036  return theTemplate;
2037 }
2038 
2040 {
2041  if ( m_docTemplates.end() == m_docTemplates.Find( temp ) )
2042  {
2043  m_docTemplates.push_back( temp );
2044  }
2045 }
2046 
2048 {
2049  m_docTemplates.ReleaseObject( temp );
2050 }
2051 
2053 {
2054  if ( m_viewTemplates.end() == m_viewTemplates.Find( temp ) )
2055  {
2056  m_viewTemplates.push_back( temp );
2057  }
2058 }
2059 
2061 {
2063 }
2064 
2065 // Add and remove a document from the manager's list
2067 {
2068  if ( m_docs.end() == m_docs.Find( doc ) )
2069  {
2070  m_docs.push_back( a2dDocumentPtr( doc ) );
2071  SetCurrentDocument( doc );
2072  a2dCommandEvent event( wxEVT_ADD_DOCUMENT, doc );
2073  event.SetEventObject( this );
2074  ProcessEvent( event );
2075  }
2076  else
2077  SetCurrentDocument( doc );
2078 }
2079 
2081 {
2082  if ( m_currentDocument == doc )
2083  SetCurrentDocument( ( a2dDocument* ) NULL );
2084 
2085  if ( m_docs.ReleaseObject( doc ) )
2086  {
2087  a2dCommandEvent event( wxEVT_REMOVE_DOCUMENT, doc );
2088  event.SetEventObject( this );
2089  ProcessEvent( event );
2090  }
2091 }
2092 
2093 // Views or windows should inform the document manager
2094 // when a view is going in or out of focus
2096 {
2097  // SetActiveView() disables the current active view here, but in that event we are not
2098  // interested.
2099  static bool recur = false;
2100  if ( recur )
2101  return;
2102  recur = true;
2103 
2104  if ( m_currentView && m_currentView->IsClosed() )
2105  m_currentView = NULL;
2106 
2107  // Events from views are connected here, the view itself stays unaware of a2dDocviewGlobals->GetDocviewCommandProcessor().
2108  // Calling twice is not a problem, only one connection is made.
2109  // Disconnecting these events is done in a2dView::~a2dView()
2110 
2111  //deactivate the current view if different from the new one.
2112  if ( m_currentView )
2113  {
2114  if ( m_currentView != view )
2115  {
2116  if ( m_currentView->GetActive() ) // only one active at the time, so deactivate the old view.
2117  m_currentView->Activate( false );
2118  if ( view )
2119  {
2120  // now this is current
2121  m_currentView = view;
2122  m_currentView->ConnectEvent( wxEVT_CLOSE_VIEW, this );
2123  //m_currentView->ConnectEvent( wxEVT_ACTIVATE_VIEW, this );
2124  m_currentView->ConnectEvent( wxEVT_ENABLE_VIEW, this );
2125  //m_currentView->ConnectEvent( wxEVT_UPDATE_VIEWS, this ); //if wanted, connect directly to specific document
2126  m_currentView->ConnectEvent( wxEVT_ENABLE_VIEWS, this );
2127  m_currentView->ConnectEvent( wxEVT_CHANGEDFILENAME_DOCUMENT, this );
2128  m_currentView->ConnectEvent( wxEVT_CHANGEDTITLE_DOCUMENT, this );
2129  m_currentView->ConnectEvent( wxEVT_REPORT_VIEWS, this );
2130  m_currentView->ConnectEvent( wxEVT_DISCONNECT_ALLVIEWS, this );
2131  }
2132  //else we keep the last activated view
2133  }
2134  }
2135  else if ( view )
2136  {
2137  // only if new view is active
2138  m_currentView = view;
2139  m_currentView->ConnectEvent( wxEVT_CLOSE_VIEW, this );
2140  //m_currentView->ConnectEvent( wxEVT_ACTIVATE_VIEW, this );
2141  m_currentView->ConnectEvent( wxEVT_ENABLE_VIEW, this );
2142  //m_currentView->ConnectEvent( wxEVT_UPDATE_VIEWS, this ); //if wanted, connect directly to specific document
2143  m_currentView->ConnectEvent( wxEVT_ENABLE_VIEWS, this );
2144  m_currentView->ConnectEvent( wxEVT_CHANGEDFILENAME_DOCUMENT, this );
2145  m_currentView->ConnectEvent( wxEVT_CHANGEDTITLE_DOCUMENT, this );
2146  m_currentView->ConnectEvent( wxEVT_REPORT_VIEWS, this );
2147  m_currentView->ConnectEvent( wxEVT_DISCONNECT_ALLVIEWS, this );
2148  }
2149 
2150  if ( m_currentView )
2152 
2153  recur = false;
2154 }
2155 
2157 {
2158  if( !view )
2159  m_currentView = NULL;
2160  else
2161  {
2162  if( m_currentView == view )
2163  m_currentView = NULL;
2164  }
2165 }
2166 
2168 {
2169  bool changed = m_currentDocument != document;
2170  //wxLogDebug("Proc %p Doc old %p new %p\n", this, m_currentDocument, document );
2171 
2172  m_currentDocument = document;
2173  // KLAAS next changed, since this function should do what it says.
2174  // sent changed current document event only if it is NULL or added to a2dDocumentCommandProcessor
2175  // if ( !document || m_docs.end() != m_docs.Find(document))
2176  if ( !document || changed )
2177  {
2178  if ( changed )
2179  {
2180  a2dCommandEvent event( wxEVT_CHANGED_DOCUMENT, m_currentDocument );
2181  event.SetEventObject( this );
2182  ProcessEvent( event );
2183  }
2184  }
2185 }
2186 
2187 void a2dDocumentCommandProcessor::OnUndo( wxCommandEvent& WXUNUSED( event ) )
2188 {
2189  Undo();
2190 }
2191 
2192 void a2dDocumentCommandProcessor::OnRedo( wxCommandEvent& WXUNUSED( event ) )
2193 {
2194  Redo();
2195 }
2196 
2197 // Handlers for UI update commands
2198 
2200 {
2201  event.Enable( true );
2202 }
2203 
2205 {
2207  event.Enable( ( doc != ( a2dDocument* ) NULL ) );
2208 }
2209 
2211 {
2212  event.Enable( m_docs.size() != 0 );
2213 }
2214 
2216 {
2218  event.Enable( ( doc != ( a2dDocument* ) NULL ) );
2219 }
2220 
2221 void a2dDocumentCommandProcessor::OnUpdateFileNew( wxUpdateUIEvent& event )
2222 {
2223  event.Enable( true );
2224 }
2225 
2227 {
2229  event.Enable( doc && doc->IsModified() );
2230 }
2231 
2233 {
2234  a2dDocumentList::iterator iter = m_docs.begin();
2235  while( iter != m_docs.end() )
2236  {
2237  a2dDECLARE_LOCAL_ITEM( a2dDocumentList::value_type, doc, *iter );
2238  if ( doc && doc->IsModified() )
2239  {
2240  event.Enable( true );
2241  return;
2242  }
2243  iter++;
2244  }
2245  event.Enable( false );
2246 }
2247 
2249 {
2251  event.Enable( ( doc != ( a2dDocument* ) NULL ) );
2252 }
2253 
2255 {
2257  event.Enable( ( doc != ( a2dDocument* ) NULL ) );
2258 }
2259 
2260 void a2dDocumentCommandProcessor::OnUpdateUndo( wxUpdateUIEvent& event )
2261 {
2263  event.Enable( ( doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanUndo() ) );
2264 }
2265 
2266 void a2dDocumentCommandProcessor::OnUpdateRedo( wxUpdateUIEvent& event )
2267 {
2269  event.Enable( ( doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanRedo() ) );
2270 }
2271 
2272 void a2dDocumentCommandProcessor::OnUpdatePrint( wxUpdateUIEvent& event )
2273 {
2275  event.Enable( ( doc != ( a2dDocument* ) NULL ) );
2276 }
2277 
2278 void a2dDocumentCommandProcessor::OnUpdatePreview( wxUpdateUIEvent& event )
2279 {
2281  event.Enable( ( doc != ( a2dDocument* ) NULL ) );
2282 }
2283 
2284 // Views or windows should inform the document manager
2285 // when a view is going in or out of focus
2287 {
2288  a2dView* view = ( a2dView* ) viewevent.GetEventObject();
2289  SetCurrentView( view );
2290  viewevent.Skip();
2291 }
2292 
2293 //It is called when a2dView::SetDocument() executing
2295 {
2296  a2dView* view = ( a2dView* ) docevent.GetEventObject();
2297  if( docevent.GetEnable() )
2298  SetCurrentView( view );
2299 }
2300 
2302 {
2303  a2dView* view = ( a2dView* ) viewevent.GetEventObject();
2304 
2305  if ( view == m_currentView )
2306  SetCurrentView( NULL );
2307 }
2308 
2310 {
2311  /* klion: all it is not need for wxDocview, it was my mistake
2312  because from a2dCommandProcessor::SetMenuStrings we can't check for a2dCommandProcessorEvent
2313  so menus wrong update
2314  static wxEvent* lastProcessedEvent = NULL; // for any events
2315  static int lastProcessedEventId = -1; // for wxIdleEvent and wxUpdateUIEvent
2316  static bool lastProcessedRetCode = false; // return code last event
2317  static long lastProcessedEventTimeStamp = -1; // for a2d...Events
2318  static wxObject* lastProcessedEventObject = NULL; // for any wxWidgets events (menu toolbars)
2319  static wxEventType lastProcessedEventType = wxEVT_NULL;
2320 
2321  if(&event != lastProcessedEvent || lastProcessedEventId != event.GetId()
2322  || lastProcessedEventObject != event.GetEventObject() || lastProcessedEventType != event.GetEventType()
2323  || lastProcessedEventTimeStamp != event.GetTimestamp())
2324  {
2325  // if(event.GetEventType() != wxEVT_UPDATE_UI) {
2326  // wxLogDebug(wxT("Stack dump:\n%s"), a2dGetStackTrace(1, true, 20, 10).c_str());
2327  lastProcessedRetCode = a2dCommandProcessor::ProcessEvent(event);
2328  lastProcessedEventId = event.GetId();
2329  lastProcessedEvent = &event;
2330  lastProcessedEventObject = event.GetEventObject();
2331  lastProcessedEventType = event.GetEventType();
2332  lastProcessedEventTimeStamp = event.GetTimestamp();
2333  }
2334  else
2335  {
2336  // wxLogDebug(wxT("Stack dump:\n%s"), a2dGetStackTrace(1, true, 20, 10).c_str());
2337  }
2338  return lastProcessedRetCode;
2339  */
2340  return a2dCommandProcessor::ProcessEvent( event );
2341 }
2342 
2343 // ----------------------------------------------------------------------------
2344 // a2dDocviewGlobal
2345 // ----------------------------------------------------------------------------
2346 
2347 //! a global pointer to get to global instance of important classes.
2349 
2351 {
2352  m_docviewCommandProcessor = new a2dDocumentCommandProcessor();
2353 
2354  m_directlog = true;
2355 }
2356 
2357 void a2dDocviewGlobal::SetDocviewCommandProcessor( a2dDocumentCommandProcessor* docviewCommandProcessor )
2358 {
2359  docviewCommandProcessor->CheckCurrentView( NULL );
2360  m_docviewCommandProcessor = docviewCommandProcessor;
2361 }
2362 
2364 {
2365 }
2366 
2367 void a2dDocviewGlobal::RecordF( wxObject* sender, const wxChar* Format, ... )
2368 {
2369  va_list ap;
2370 
2371  wxString recordstring;
2372  va_start( ap, Format );
2373 
2374  //Format.Replace( wxT("%f"), wxT("%6.3f") );
2375 
2376  recordstring.PrintfV( Format, ap );
2377  va_end( ap );
2378 
2379  a2dCommandEvent event( recordstring );
2380  event.SetEventObject( sender );
2381 
2382  ProcessEvent( event );
2383 }
2384 
2385 void a2dDocviewGlobal::RecordF( const wxChar* Format, ... )
2386 {
2387  va_list ap;
2388 
2389  wxString recordstring;
2390  va_start( ap, Format );
2391 
2392  //Format.Replace( wxT("%f"), wxT("%6.3f") );
2393 
2394  recordstring.PrintfV( Format, ap );
2395  va_end( ap );
2396 
2397  a2dCommandEvent event( recordstring );
2398  event.SetEventObject( this );
2399 
2400  ProcessEvent( event );
2401 }
2402 
2403 // ----------------------------------------------------------------------------
2404 // a2dFileHistory
2405 // ----------------------------------------------------------------------------
2406 
2407 IMPLEMENT_DYNAMIC_CLASS( a2dFileHistory, wxObject )
2408 
2409 // ----------------------------------------------------------------------------
2410 // local constants
2411 // ----------------------------------------------------------------------------
2412 
2413 static const wxChar* s_MRUEntryFormat = wxT( "&%lu %s" );
2414 
2415 
2416 static inline wxChar* MYcopystring( const wxString& s )
2417 {
2418  wxChar* copy = new wxChar[s.length() + 1];
2419  return wxStrcpy( copy, s.c_str() );
2420 }
2421 
2422 static inline wxChar* MYcopystring( const wxChar* s )
2423 {
2424  wxChar* copy = new wxChar[wxStrlen( s ) + 1];
2425  return wxStrcpy( copy, s );
2426 }
2427 
2428 a2dFileHistory::a2dFileHistory( size_t maxFiles, wxWindowID idBase )
2429 {
2430  m_fileMaxFiles = maxFiles;
2431  m_idBase = idBase;
2432 }
2433 
2434 a2dFileHistory::~a2dFileHistory()
2435 {
2436 }
2437 
2438 // File history management
2439 void a2dFileHistory::AddFileToHistory( const wxFileName& file, a2dDocumentTemplate* docTemplate, a2dViewTemplate* viewTemplate )
2440 {
2441  a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2442  size_t i = 0;
2443  for( ; iter != m_fileHistoryList.end(); iter++ )
2444  {
2445  a2dFileHistoryItemPtr fileitem = *iter;
2446  if ( fileitem->m_filename == file )
2447  {
2448  // we do have it, move it to the top of the history
2449  RemoveFileFromHistory ( i );
2450  //recursive call, but item is laready removed, so size-1 now.
2451  AddFileToHistory( file, docTemplate, viewTemplate );
2452  return;
2453  }
2454  i++;
2455  }
2456 
2457  // if we already have a full history, delete the one at the end
2458  if ( m_fileMaxFiles == m_fileHistoryList.size() )
2459  {
2460  RemoveFileFromHistory ( m_fileHistoryList.size() - 1 );
2461  AddFileToHistory( file, docTemplate, viewTemplate );
2462  return;
2463  }
2464 
2465  // Add to the project file history:
2466  // Move existing files (if any) down so we can insert file at beginning.
2467  if ( m_fileHistoryList.size() < m_fileMaxFiles )
2468  {
2469  wxList::compatibility_iterator node = m_fileMenus.GetFirst();
2470  while ( node )
2471  {
2472  wxMenu* menu = ( wxMenu* ) node->GetData();
2473  if ( m_fileHistoryList.empty() && menu->GetMenuItemCount() )
2474  {
2475  menu->AppendSeparator();
2476  }
2477  // fill up with menu set to empty labels, will be set later
2478  menu->Append( m_idBase + m_fileHistoryList.size(), _( "[EMPTY]" ) );
2479  node = node->GetNext();
2480  }
2481  }
2482  m_fileHistoryList.push_front( new a2dFileHistoryItem( file, docTemplate, viewTemplate ) );
2483 
2484  // this is the directory of the last opened file
2485  iter = m_fileHistoryList.begin();
2486  wxString pathCurrent = ( *iter )->m_filename.GetPath();
2487 
2488  //refill menu from list
2489  i = 0;
2490  for( ; iter != m_fileHistoryList.end(); iter++ )
2491  {
2492  a2dFileHistoryItemPtr fileitem = *iter;
2493 
2494  // if in same directory just show the filename; otherwise the full
2495  // path
2496  wxString pathInMenu, path;
2497  path = fileitem->m_filename.GetPath();
2498  if ( path == pathCurrent )
2499  pathInMenu = fileitem->m_filename.GetFullName();
2500  else
2501  {
2502  // absolute path; could also set relative path
2503  pathInMenu = fileitem->m_filename.GetFullPath();
2504  }
2505 
2506  // we need to quote '&' characters which are used for mnemonics
2507  pathInMenu.Replace( _T( "&" ), _T( "&&" ) );
2508  wxString buf;
2509  buf.Printf( s_MRUEntryFormat, i + 1, pathInMenu.c_str() );
2510  wxList::compatibility_iterator node = m_fileMenus.GetFirst();
2511  while ( node )
2512  {
2513  wxMenu* menu = ( wxMenu* ) node->GetData();
2514  menu->SetLabel( m_idBase + i, buf );
2515  node = node->GetNext();
2516  }
2517  i++;
2518  }
2519 }
2520 
2521 void a2dFileHistory::RemoveFileFromHistory( size_t i )
2522 {
2523  wxCHECK_RET( i < m_fileHistoryList.size(),
2524  wxT( "invalid index in a2dFileHistory::RemoveFileFromHistory" ) );
2525 
2526  // delete the element from the list
2527  a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2528  size_t j = 0;
2529  for( ; iter != m_fileHistoryList.end(); iter++ )
2530  {
2531  a2dFileHistoryItemPtr fileitem = *iter;
2532  if ( j == i )
2533  {
2534  m_fileHistoryList.erase( iter );
2535  break;
2536  }
2537  j++;
2538  }
2539 
2540  wxList::compatibility_iterator node = m_fileMenus.GetFirst();
2541  while ( node )
2542  {
2543  wxMenu* menu = ( wxMenu* ) node->GetData();
2544 
2545  // re-fill menu labels
2546  wxString buf;
2547  a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2548  size_t j = 0;
2549  for( ; iter != m_fileHistoryList.end(); iter++ )
2550  {
2551  a2dFileHistoryItemPtr fileitem = *iter;
2552  buf.Printf( s_MRUEntryFormat, j + 1, fileitem->m_filename.GetFullPath().c_str() );
2553  menu->SetLabel( m_idBase + j, buf );
2554  j++;
2555  }
2556 
2557  node = node->GetNext();
2558 
2559  // delete the last menu item which is unused now
2560  wxWindowID lastItemId = m_idBase + wx_truncate_cast( wxWindowID, m_fileHistoryList.size() );
2561  if ( menu->FindItem( lastItemId ) )
2562  {
2563  menu->Delete( lastItemId );
2564  }
2565 
2566  // delete the last separator too if no more files are left
2567  if ( m_fileHistoryList.empty() )
2568  {
2569  wxMenuItemList::compatibility_iterator nodeLast = menu->GetMenuItems().GetLast();
2570  if ( nodeLast )
2571  {
2572  wxMenuItem* menuItem = nodeLast->GetData();
2573  if ( menuItem->IsSeparator() )
2574  {
2575  menu->Delete( menuItem );
2576  }
2577  //else: should we search backwards for the last separator?
2578  }
2579  //else: menu is empty somehow
2580  }
2581  }
2582 }
2583 
2584 wxString a2dFileHistory::GetHistoryFile( size_t i ) const
2585 {
2586  wxString s;
2587  if ( i < m_fileHistoryList.size() )
2588  {
2589  a2dFileHistoryItemList::const_iterator iter = m_fileHistoryList.item( i );
2590  a2dFileHistoryItemPtr fileitem = *iter;
2591  s = fileitem->m_filename.GetFullPath();
2592  }
2593  else
2594  wxFAIL_MSG( wxT( "bad index in a2dFileHistory::GetHistoryFile" ) );
2595  return s;
2596 }
2597 
2598 a2dFileHistoryItem* a2dFileHistory::GetHistoryFileItem( size_t i ) const
2599 {
2600  wxString s;
2601  if ( i < m_fileHistoryList.size() )
2602  {
2603  a2dFileHistoryItemList::const_iterator iter = m_fileHistoryList.item( i );
2604  return *iter;
2605  }
2606  else
2607  wxFAIL_MSG( wxT( "bad index in a2dFileHistory::GetHistoryFile" ) );
2608  return NULL;
2609 }
2610 
2611 void a2dFileHistory::UseMenu( wxMenu* menu )
2612 {
2613  if ( !m_fileMenus.Member( menu ) )
2614  m_fileMenus.Append( menu );
2615 }
2616 
2617 void a2dFileHistory::RemoveMenu( wxMenu* menu )
2618 {
2619  m_fileMenus.DeleteObject( menu );
2620 }
2621 
2622 #if wxUSE_CONFIG
2623 void a2dFileHistory::Load( wxConfigBase& config )
2624 {
2625  wxString buf;
2626  buf.Printf( wxT( "file%d" ), 1 );
2627  wxString historyFile;
2628  int fileid = 2;
2629  while ( ( m_fileHistoryList.size() < m_fileMaxFiles ) && config.Read( buf, &historyFile ) && ( !historyFile.empty() ) )
2630  {
2631  bool has = false;
2632  a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2633  for( ; iter != m_fileHistoryList.end(); iter++ )
2634  {
2635  a2dFileHistoryItemPtr fileitem = *iter;
2636  if ( fileitem->m_filename.GetFullPath() == historyFile )
2637  has = true;
2638  }
2639  if ( !has )
2640  m_fileHistoryList.push_back( new a2dFileHistoryItem( wxFileName( historyFile ), NULL, NULL ) );
2641  buf.Printf( wxT( "file%d" ), fileid++ );
2642  historyFile = wxEmptyString;
2643  }
2644  AddFilesToMenu();
2645 }
2646 
2647 void a2dFileHistory::Save( wxConfigBase& config )
2648 {
2649  a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2650  size_t j = 0;
2651  for( ; iter != m_fileHistoryList.end(); iter++ )
2652  {
2653  a2dFileHistoryItemPtr fileitem = *iter;
2654  wxString buf;
2655  buf.Printf( wxT( "file%d" ), ( int )j + 1 );
2656  if ( j < m_fileHistoryList.size() )
2657  config.Write( buf, fileitem->m_filename.GetFullPath() );
2658  else
2659  config.Write( buf, wxEmptyString );
2660  j++;
2661  }
2662 }
2663 #endif // wxUSE_CONFIG
2664 
2665 void a2dFileHistory::AddFilesToMenu()
2666 {
2667  if ( !m_fileHistoryList.empty() )
2668  {
2669  wxList::compatibility_iterator node = m_fileMenus.GetFirst();
2670  while ( node )
2671  {
2672  wxMenu* menu = ( wxMenu* ) node->GetData();
2673  if ( menu->GetMenuItemCount() )
2674  {
2675  menu->AppendSeparator();
2676  }
2677 
2678  a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2679  size_t i = 0;
2680  for( ; iter != m_fileHistoryList.end(); iter++ )
2681  {
2682  a2dFileHistoryItemPtr fileitem = *iter;
2683  wxString buf;
2684  buf.Printf( s_MRUEntryFormat, i + 1, fileitem->m_filename.GetFullPath().c_str() );
2685  menu->Append( m_idBase + i, buf );
2686  i++;
2687  }
2688  node = node->GetNext();
2689  }
2690  }
2691 }
2692 
2693 void a2dFileHistory::AddFilesToMenu( wxMenu* menu )
2694 {
2695  if ( !m_fileHistoryList.empty() )
2696  {
2697  if ( menu->GetMenuItemCount() )
2698  {
2699  menu->AppendSeparator();
2700  }
2701 
2702  a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2703  size_t i = 0;
2704  for( ; iter != m_fileHistoryList.end(); iter++ )
2705  {
2706  a2dFileHistoryItemPtr fileitem = *iter;
2707  wxString buf;
2708  buf.Printf( s_MRUEntryFormat, i + 1, fileitem->m_filename.GetFullPath().c_str() );
2709  menu->Append( m_idBase + i, buf );
2710  i++;
2711  }
2712  }
2713 }
2714 
2715 
2716 // ----------------------------------------------------------------------------
2717 // a2dDocviewModule
2718 // ----------------------------------------------------------------------------
2719 IMPLEMENT_DYNAMIC_CLASS( a2dDocviewModule, wxModule )
2720 
2721 bool a2dDocviewModule::OnInit()
2722 {
2723 #if wxUSE_PRINTING_ARCHITECTURE
2724  if( wxThePrintPaperDatabase == NULL )
2725  {
2726  wxThePrintPaperDatabase = new wxPrintPaperDatabase;
2727  wxThePrintPaperDatabase->CreateDatabase();
2728  m_wxThePrintPaperDatabase = wxThePrintPaperDatabase;
2729  }
2730 #endif
2731  a2dDocviewGlobals = new a2dDocviewGlobal();
2732  wxNullRefObjectList = new a2dObjectList();
2733 
2734  return true;
2735 }
2736 
2737 void a2dDocviewModule::OnExit()
2738 {
2739  delete wxNullRefObjectList;
2740  delete a2dDocviewGlobals;
2741  a2dDocviewGlobals = NULL;
2742 #if wxUSE_PRINTING_ARCHITECTURE
2743  if( m_wxThePrintPaperDatabase && m_wxThePrintPaperDatabase != wxThePrintPaperDatabase )
2744  delete m_wxThePrintPaperDatabase;
2745  m_wxThePrintPaperDatabase = NULL;
2746 #endif
2747 }
2748 
2749 
2750 
virtual void DeleteContents()
called when there is a need to clear the contents of the document.
Definition: docviewref.cpp:373
void OnUpdateFileOpen(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2199
void ReleaseTemplate(a2dDocumentTemplate *temp, long flags=0)
remove/release a template
Definition: doccom.cpp:1566
virtual bool Undo()
Undo one command or command group.
Definition: comevt.cpp:918
bool IsModified() const
Has the document been modified.
Definition: docviewref.h:1321
virtual bool Redo()
Redo one command or command group.
Definition: comevt.cpp:933
const a2dError a2dError_NoDocTemplateRef
void OnUpdateFileSaveAs(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2248
a2dDocumentTemplate * m_preferredExportTemplate
preferred document template for Exporting files.
Definition: doccom.h:992
a2dDocumentTemplateList m_docTemplates
templates for documents
Definition: doccom.h:971
a2dView * AddDocumentCreateView(a2dDocument *newDoc, const wxString &viewTypeName=wxT(""), a2dDocumentFlagMask documentflags=a2dREFDOC_NEW, a2dTemplateFlagMask docTemplateFlags=a2dTemplateFlag::VISIBLE, a2dTemplateFlagMask viewTemplateFlags=a2dTemplateFlag::VISIBLE)
adds the given document, and creates a view for it.
Definition: doccom.cpp:1447
void OnActivateView(a2dViewEvent &viewevent)
Views do inform the document manager.
Definition: doccom.cpp:2286
virtual bool CanUndo() const
Are there commands to undo and can they be undone ?
Definition: comevt.cpp:967
#define EVT_ACTIVATE_VIEW(func)
event sent to view and document manager
Definition: docviewref.h:999
a2dDocumentTemplate * MatchTemplate(const wxString &path)
return template suitable for loading the file in path, using FindTemplateForPath. ...
Definition: doccom.cpp:1632
fundamental classes used by all other modules.
void OnUpdateFileClose(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2204
a2dDocumentTemplate * m_preferredImportTemplate
preferred document template for Importing files.
Definition: doccom.h:989
void RemoveDocument(a2dDocument *doc)
remove a document from the manager&#39;s list
Definition: doccom.cpp:2080
void SetFilename(const wxFileName &filename, bool notifyViews=false)
Sets the filename for this document. Usually called by the framework.
void OnUpdateFileSaveAll(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2232
The a2dViewTemplate class is used to model the relationship between a document class and a view class...
Definition: docviewref.h:2635
const a2dError a2dError_CouldNotEvaluatePath
const a2dDocumentList & GetDocuments() const
returns a reference to the a2dDocumentList, which contains all a2dDocument&#39;s that are open...
Definition: doccom.h:779
virtual void SetCurrentView(a2dView *view)
To set the curent view.
Definition: doccom.cpp:2095
wxString GetDocumentTypeName() const
Gets the document type name of this document. See the comment for documentTypeName.
Definition: docviewref.h:1124
void SetDirectory(const wxString &dir)
Sets the default directory.
Definition: docviewref.h:2432
wxString GetDirectory() const
Returns the default directory, as passed to the document template constructor.
Definition: docviewref.h:2408
a2dError FileOpen(a2dDocumentPtr &doc, const wxFileName &file=wxFileName(wxT("")), a2dTemplateFlagMask docTemplateFlags=a2dTemplateFlag::VISIBLE|a2dTemplateFlag::LOAD)
Creates a new document and reads in the selected file.
Definition: doccom.cpp:553
void OnUpdateUndo(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2260
a2dDocumentTemplate * GetDocumentTemplate() const
Gets a2dDocumentTemplate pointer which was used to create the a2dView.
Definition: docviewref.h:1389
void OnUpdateFileCloseAll(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2210
bool Exit(bool force=true)
Called to Exit the application properly.
Definition: doccom.cpp:479
void AssociateDocTemplate(a2dDocumentTemplate *temp)
add a reference to a a2dDocumentTemplate to the a2dDocumentTemplateList
Definition: doccom.cpp:2039
const a2dError a2dError_NoError
void OnMenu(wxCommandEvent &event)
All menu&#39;s ( also using a2dMenuIdItem ) can be intercepted here.
Definition: doccom.cpp:293
wxWindow * GetDisplayWindow()
Get the display window.
Definition: docviewref.h:1875
virtual wxString MakeFrameTitle(a2dDocument *doc, const wxString &modifiedIndicator=wxT(""))
Make a frame title (override this to do something different)
Definition: doccom.cpp:1612
void ConnectEvent(wxEventType type, wxEvtHandler *eventSink)
Definition: gen.cpp:876
void OnCannotOpenDocument(a2dCommandEvent &event)
default handler when a file could not be opened
Definition: doccom.cpp:1190
The a2dDocumentTemplate class is used to model the relationship between a document class and files...
Definition: docviewref.h:2297
virtual void RecordF(wxObject *sender, const wxChar *Format,...)
to sent a ::wxEVT_RECORD event
Definition: doccom.cpp:2367
see a2dCommandEvent
Definition: doccom.h:79
a2dCommandProcessor * GetCommandProcessor() const
Returns a pointer to the command processor associated with this document.
Definition: docviewref.h:1294
const a2dError a2dError_FileCouldNotOpen
Path searching.
Definition: gen.h:2926
virtual void FileHistoryAddFilesToMenu()
Appends the files in the history list, to all menus managed by the file history object.
Definition: doccom.cpp:1702
void CheckCurrentView(a2dView *view)
Views do inform the document manager when a view will be destroyed.
Definition: doccom.cpp:2156
bool m_busyExit
set when terminating application
Definition: doccom.h:1001
void OnUpdatePreview(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2278
wxPageSetupDialogData GetDefaultPrintSettings()
Return page setup data, as set in the current default printer.
Definition: doccom.cpp:1109
void DisassociateViewTemplate(a2dViewTemplate *temp)
remove a reference to a a2dViewTemplate to the wxViewTemplateReflist
Definition: doccom.cpp:2060
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
void SetCurrentDocument(a2dDocument *document)
set the current document, only needed in cases
Definition: doccom.cpp:2167
virtual wxString GetHistoryFile(size_t i) const
return the filename of the i&#39;th file in the history
Definition: doccom.cpp:1650
a2dView event, to report events in the a2dView class
Definition: docviewref.h:424
virtual a2dView * CreateView(a2dDocument *doc, const wxString &viewTypeName=wxT(""), a2dDocumentFlagMask flags=a2dREFDOC_NON, a2dTemplateFlagMask viewTemplateFlags=a2dTemplateFlag::VISIBLE)
Creates a new view for the given document.
Definition: doccom.cpp:1550
a2dError FileNew(a2dDocumentPtr &doc, a2dTemplateFlagMask docTemplateFlags=a2dTemplateFlag::VISIBLE)
Creates a document from a list of templates (if more than one template).
Definition: doccom.cpp:535
virtual void Initialize()
Initialises the current command and menu strings.
Definition: comevt.cpp:989
Docview framework its controlling class.
void OnUpdateCreateView(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2254
virtual a2dDocument * CreateDocument(const wxFileName &path, a2dDocumentFlagMask flags=a2dREFDOC_NON)
Creates a new document.
bool FileClose(bool force=true)
Closes and deletes the currently active document unless Close was vetod.
Definition: doccom.cpp:521
base command processor
Definition: comevt.h:829
bool Close(bool force)
Closes the document if not vetod.
Definition: docviewref.cpp:457
bool FileRevert()
revert the current document to the non saved document on disk.
Definition: doccom.cpp:724
const a2dError a2dError_IOHandler
wxPageSetupDialogData * GetPrintSetup(a2dPrintWhat printWhat)
get printer setup the current active view or document or the one from central command processor...
Definition: doccom.cpp:1144
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.
a2dError FilesOpen(const wxString &openPath=wxT(""), int dialogFlags=wxFD_MULTIPLE|wxFD_OPEN, a2dTemplateFlagMask docTemplateFlags=a2dTemplateFlag::VISIBLE|a2dTemplateFlag::LOAD)
open one or more files using a file dialog
Definition: doccom.cpp:697
bool IsClosed()
A closed flag is set when a view is closed.
Definition: docviewref.h:1829
long m_flags
user flags use at will ( not used internal )
Definition: doccom.h:959
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
const a2dError a2dError_NoSelection
a2dError a2dFileSelectorEx(const wxString &message=wxFileSelectorPromptStr, const wxString &default_path=wxEmptyString, const wxString &default_filename=wxEmptyString, int *indexDefaultExtension=NULL, const wxString &wildcard=wxFileSelectorDefaultWildcardStr, int flags=0, wxWindow *parent=NULL, wxArrayString *returnPaths=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
select one or more files
Definition: doccom.cpp:107
void DisassociateDocTemplate(a2dDocumentTemplate *temp)
remove a reference to a a2dDocumentTemplate to the a2dDocumentTemplateList
Definition: doccom.cpp:2047
virtual void CreateCommandProcessor()
create a command processor and set it for the document.
void OnUpdateFileRevert(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2215
virtual void AddFileToHistory(const wxFileName &file, a2dDocumentTemplate *docTemplate=NULL, a2dViewTemplate *viewTemplate=NULL)
File history management.
Definition: doccom.cpp:1638
#define EVT_ADD_VIEW(func)
event sent to document when a view has been added to the document
Definition: docviewref.h:1005
virtual a2dFileHistory * OnCreateFileHistory()
A hook to allow a derived class to create a different type of file history. Called from Initialize...
Definition: doccom.cpp:516
virtual void FileHistoryUseMenu(wxMenu *menu)
Use this menu for appending recently-visited document filenames,.
Definition: doccom.cpp:1670
void OnUpdateFileSave(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2226
void SetDocviewCommandProcessor(a2dDocumentCommandProcessor *docviewCommandProcessor)
Normally the docview commandprocessor is set in the constructor when creating new a2dDocviewGlobal...
Definition: doccom.cpp:2357
The document class can be used to model an application&#39;s file-based data.
Definition: docviewref.h:1066
void OnRemoveView(a2dDocumentEvent &viewevent)
Views do inform the document manager when a view will be removed.
Definition: doccom.cpp:2301
void DisConnectAllViews()
Disconnect a2dView&#39;s using this document.
Definition: docviewref.cpp:449
virtual a2dFileHistoryItem * GetHistoryFileItem(size_t i) const
return the a2dFileHistoryItem of the i&#39;th file in the history
Definition: doccom.cpp:1663
void SetDocumentTemplate(a2dDocumentTemplate *temp)
Set a2dDocumentTemplate pointer.
Definition: docviewref.h:1392
virtual bool SubmitToDocument(a2dCommand *command, bool storeIt=true)
redirect the command to the current document ( if available )
Definition: doccom.cpp:408
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
virtual bool ProcessEvent(wxEvent &event)
Definition: doccom.cpp:2309
wxPageSetupDialogData * m_pageSetupData
this is the global printer page setup data for printer
Definition: doccom.h:1005
wxUint16 a2dPrintWhat
defines what to print
Definition: gen.h:4052
bool FileSaveAs(const wxFileName &file=wxFileName(wxT("")), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Calls wxDocument::SaveAs for the current document.
Definition: doccom.cpp:766
Docview classes for document view, window and frame.
const a2dPrintWhat a2dPRINT_PreviewDocument
preview print a2dDocument
Definition: docviewref.cpp:195
One object of this class may be created in an application, to manage all the templates and documents...
Definition: doccom.h:242
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
~a2dDocviewGlobal()
destructor
Definition: doccom.cpp:2363
virtual bool CanRedo() const
Are there commands to redo and can they be redone ?
Definition: comevt.cpp:974
a2dError GetError()
in case of errors when sending an event, this is to know the reason of failure
Definition: docviewref.h:796
wxString GetFileFilter() const
Returns the file filter, as passed to the document template constructor.
Definition: docviewref.h:2411
a2dDocument * GetCurrentDocument() const
Get the current Document, which is the document that was last accessed from a view.
Definition: doccom.cpp:1582
const a2dError a2dError_FileVersion
a2dDocument * SentPreAddCreatedDocumentEvent(a2dDocument *newDoc, a2dDocumentFlagMask flags)
sents a wxEVT_PRE_ADD_DOCUMENT event to m_connector if available.
virtual a2dDocumentTemplate * SelectDocumentType(bool sort=false, a2dTemplateFlagMask docTemplateFlags=a2dTemplateFlag::VISIBLE)
Returns a document template by asking the user.
Definition: doccom.cpp:1870
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
static const a2dTemplateFlagMask EXPORTING
Definition: docviewref.h:225
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
bool FileImport(const wxFileName &file=wxFileName(wxT("")), const wxString &description=wxT(""), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Calls a2dDocument::Import for the current document.
Definition: doccom.cpp:900
virtual void FileHistoryRemoveMenu(wxMenu *menu)
Removes the given menu from the list of menus managed by the file history object. ...
Definition: doccom.cpp:1676
void OnUpdatePrint(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2272
void SetFileName(const wxFileName &filename)
set filename of file to open, before sending the event.
Definition: docviewref.h:760
a2dError FileOpenCheck(a2dDocumentPtr &doc, const wxFileName &file, bool checkModification)
Return existing document, or open it from file.
Definition: doccom.cpp:612
static const a2dTemplateFlagMask IMPORTING
Definition: docviewref.h:224
bool Preview(a2dPrintWhat printWhat=a2dPRINT_Preview)
print preview of the current active view.
Definition: doccom.cpp:1046
void Activate(bool activate)
is called via ProcessEvent() when the view becomes active
a2dFileHistory * m_fileHistory
the file history
Definition: doccom.h:983
virtual bool Submit(a2dCommand *command, bool storeIt=true)
next to the base class submit, it sets a2DocumentCommandProcessor for a2dCommand
Definition: comevt.cpp:842
void OnUpdateRedo(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2266
wxFileName GetFilename() const
Get the file name in use for this document.
Definition: docviewref.h:1103
One Global instance of this class exists, in order to get to.
Definition: doccom.h:1022
bool PrintSetup(a2dPrintWhat printWhat)
printer setup the current active document or central command processor.
Definition: doccom.cpp:1098
a2dView * m_currentView
the current view (active or inactive)
Definition: doccom.h:977
a2dView * GetCurrentView() const
return the one that is active right now (e.g. has focus in case of a wxWindow), or NULL ...
Definition: doccom.cpp:1185
virtual size_t GetHistoryFilesCount() const
Return number fo files in history.
Definition: doccom.cpp:1708
void OnRedo(wxCommandEvent &event)
default handler for GUI event with id wxID_REDO
Definition: doccom.cpp:2192
virtual wxPrintout * OnCreatePrintout(a2dPrintWhat typeOfPrint, const wxPageSetupDialogData &pageSetupData)
called from the a2dDocumentCommandProcessor to create a wxPrintout are derived class ...
virtual wxWindow * GetAssociatedWindow() const
Returns a window that can be used as a parent for document-related dialogs. Override if necessary...
const a2dError a2dError_Canceled
a2dViewTemplate * GetViewTemplate() const
get the a2dViewTemplate with which this view was created
Definition: docviewref.h:1914
virtual bool Revert()
Normally should undo all changes by rereading the file again.
bool CloseDocuments(bool force=true)
closes all currently open documents
Definition: doccom.cpp:419
a2dDocumentList m_docs
list of all that are open
Definition: doccom.h:968
a2dViewTemplateList m_viewTemplates
templates for views
Definition: doccom.h:974
bool Print(a2dPrintWhat printWhat=a2dPRINT_Print)
print the current active view.
Definition: doccom.cpp:1012
a2dDocumentCommandProcessor(long flags=a2dDEFAULT_DOCUMENT_FLAGS, bool initialize=true, int maxCommands=-1)
Constructor.
Definition: doccom.cpp:225
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
bool FileExport(const wxFileName &file=wxFileName(wxT("")), const wxString &description=wxT(""), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Calls a2dDocument::Export for the current document.
Definition: doccom.cpp:789
virtual a2dView * CreateView(a2dDocument *doc, a2dDocumentFlagMask flags=a2dREFDOC_NON)
Creates a new view for the given document.
bool ReleaseObject(T *object)
release a certain object from the list
Definition: smrtptr.inl:118
static bool m_directlog
logging to wxLog target on or off
Definition: comevt.h:1204
virtual void ReportErrorF(const a2dError &error, const wxChar *Format,...)
concatenate to the the error report the given error.
Definition: comevt.cpp:1312
~a2dDocumentCommandProcessor()
destructor
Definition: doccom.cpp:281
wxString GetPrintableName() const
Get title, or filename if no title, else [unnamed].
const a2dPrintWhat a2dPRINT_PrintDocument
print a2dDocument
Definition: docviewref.cpp:194
A list class for reference counted objects.
Definition: smrtptr.h:653
bool IsClosed()
returns true when document is closed or busy closing.
Definition: docviewref.h:1147
a2dCommandProcessor * GetCurrentDocumentCommandProcessor() const
get the command processor of the current document.
Definition: doccom.cpp:1590
bool GetActive()
return if the view is active/
Definition: docviewref.h:2066
itSmart Find(T *object)
Find a specific object.
Definition: smrtptr.inl:76
a2dError AddCreatedDocument(a2dDocument *newDoc, bool sentPreAddCreatedDocumentEvent=false, bool sentPostCreateDocumentEvent=false, a2dDocumentFlagMask documentflags=a2dREFDOC_NEW, a2dTemplateFlagMask docTemplateFlags=a2dTemplateFlag::VISIBLE)
add a in memory created document, but do not create a view.
Definition: doccom.cpp:1457
bool FileSaveAll()
Saves the documents by calling wxDocument::Save for each document.
Definition: doccom.cpp:749
const a2dError a2dError_ToManyOpen
virtual void OnExit()
Called by Exit()
Definition: doccom.cpp:395
void OnAddView(a2dDocumentEvent &docevent)
It works when a2dView::SetDocument() executing.
Definition: doccom.cpp:2294
A module to initialize the docview framework.
Definition: doccom.h:1166
void SendToLogTarget()
all stored errors and warning are sent to log target using wxLogError()
Definition: comevt.cpp:1367
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 OnUpdateFileNew(wxUpdateUIEvent &event)
Handlers for UI update commands.
Definition: doccom.cpp:2221
void AddDocument(a2dDocument *doc)
Add a document to the manager&#39;s list.
Definition: doccom.cpp:2066
virtual a2dDocumentTemplate * FindTemplateForPath(const a2dDocumentTemplateList &docTemplates, const wxString &path, a2dTemplateFlagMask mask=a2dTemplateFlag::VISIBLE)
function used in CreateDocument() when a2dREFDOC_SILENT is used for creating it.
Definition: doccom.cpp:1719
void OnUndo(wxCommandEvent &event)
default handler for GUI event with id wxID_UNDO
Definition: doccom.cpp:2187
void AssociateViewTemplate(a2dViewTemplate *temp)
add a reference to a a2dViewTemplate to the wxViewTemplateReflist
Definition: doccom.cpp:2052
wxString GetDocumentTypeName() const
Returns the document type name, as passed to the document template constructor.
Definition: docviewref.h:2426
#define const_forEachIn(listtype, list)
easy const iteration for a2dlist
Definition: a2dlist.h:118
size_t m_maxDocsOpen
the maximum of documents allowed open
Definition: doccom.h:965
void SetDocumentTypeName(const wxString &name)
Sets the document type name for this document. See the comment for documentTypeName.
Definition: docviewref.h:1121
const a2dPrintWhat a2dPRINT_PreviewView
preview print a2dView
Definition: docviewref.cpp:193
static const a2dTemplateFlagMask VISIBLE
Definition: docviewref.h:220
a2dDocumentTemplate * m_preferredOpenTemplate
preferred document template for Opening files.
Definition: doccom.h:995
bool FileSave()
Saves the current document by calling wxDocument::Save for the current document.
Definition: doccom.cpp:733
holds one error report.
Definition: gen.h:623
virtual a2dError SelectDocumentPath(const wxString &title, const a2dDocumentTemplateList &docTemplates, wxString &path, a2dDocumentFlagMask flags, wxArrayString *selectedPaths, a2dDocumentTemplate **chosenTemplate, int dialogflags=wxFD_OPEN, a2dTemplateFlagMask docTemplateFlags=a2dTemplateFlag::VISIBLE, const a2dDocumentTemplate *preferedTemplate=NULL)
pops up a file selector with optional a list of filters
Definition: doccom.cpp:1759
virtual void Initialize()
Initializes data; currently just calls OnCreateFileHistory.
Definition: doccom.cpp:399
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
int m_defaultDocumentNameCounter
to create unique new names for file
Definition: doccom.h:962
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
wxWindow * wxFindSuitableParent()
find a parent wxWindow pointer to place a control into
Definition: doccom.cpp:1739
wxString GetDefaultExtension() const
Returns the default file extension for the document data, as passed to the document template construc...
Definition: docviewref.h:2402
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
list of a2dObject&#39;s
Definition: gen.h:3157
#define EVT_CANNOT_OPEN_DOCUMENT(func)
event sent when a file could not be opened in the a2dDocumentCommandProcessor
Definition: doccom.h:181
wxString GetTitle() const
Returns the title for this document.
Definition: docviewref.h:1118
wxString m_lastDirectory
the last visited directory
Definition: doccom.h:986
#define EVT_REMOVE_VIEW(func)
event sent to document when a view will be removed from the document
Definition: docviewref.h:1007
a2dSmrtPtr< a2dDocument > a2dDocumentPtr
document smart pointer
Definition: docviewref.h:95
a2dDocument * m_currentDocument
the current active document
Definition: doccom.h:980
a2dDocviewGlobal()
constructor
Definition: doccom.cpp:2350
bool GetEnable()
when ::wxEVT_ENABLE_VIEWS get enable value of the event
Definition: docviewref.h:793
a2dDocument * GetDocument()
the document created/removed or on which the command was applied.
Definition: doccom.h:151
holds one file for placing in history list
Definition: doccom.h:1067
unsigned int a2dDocumentFlagMask
mask of flags for a2dDocumentFlag
Definition: docviewref.h:200
a base command for the a2dCommandProcessor
Definition: comevt.h:140
doccom.cpp Source File -- Sun Oct 12 2014 17:04:15 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation