13 #include "docviewprec.h"
28 #include "wx/string.h"
32 #include "wx/dialog.h"
35 #include "wx/filedlg.h"
44 #if wxUSE_PRINTING_ARCHITECTURE
45 #include "wx/prntbase.h"
46 #include "wx/printdlg.h"
49 #include "wx/msgdlg.h"
50 #include "wx/choicdlg.h"
51 #include "wx/confbase.h"
53 #include "wx/cmdproc.h"
55 #include "wx/textdlg.h"
57 #include <wx/tokenzr.h>
60 #if wxUSE_PRINTING_ARCHITECTURE
67 #include "wx/docview.h"
78 #if (defined(__WXMSW__) && defined(WXUSINGDLL) )
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 )
108 const wxString& default_path = wxEmptyString,
109 const wxString& default_filename = wxEmptyString,
110 int* indexDefaultExtension = NULL,
111 const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
113 wxWindow* parent = NULL,
114 wxArrayString* returnPaths = NULL,
115 int x = wxDefaultCoord,
int y = wxDefaultCoord )
117 wxASSERT_MSG( returnPaths, wxT(
"must have return path wxArrayString" ) );
118 returnPaths->Clear();
120 wxFileDialog fileDialog( parent,
125 flags, wxPoint( x, y ) );
128 if ( indexDefaultExtension && *indexDefaultExtension > 0 )
129 fileDialog.SetFilterIndex( *indexDefaultExtension );
131 if ( fileDialog.ShowModal() == wxID_OK )
133 if ( indexDefaultExtension )
134 *indexDefaultExtension = fileDialog.GetFilterIndex();
136 if( flags & wxFD_MULTIPLE )
137 fileDialog.GetPaths( *returnPaths );
139 returnPaths->Add( fileDialog.GetPath() );
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" ) )
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 )
212 #if wxUSE_PRINTING_ARCHITECTURE
214 EVT_UPDATE_UI( CmdMenu_Preview().GetId(), a2dDocumentCommandProcessor::OnUpdatePreview )
225 a2dDocumentCommandProcessor::a2dDocumentCommandProcessor(
long flags,
bool WXUNUSED( initialize ),
int maxCommands )
227 #if defined(_DEBUG) && defined (SMART_POINTER_DEBUG)
228 , m_initCurrentSmartPointerOwner(
this )
230 ,m_preferredImportTemplate( NULL )
231 ,m_preferredExportTemplate( NULL )
232 ,m_preferredOpenTemplate( NULL )
234 m_defaultDocumentNameCounter = 1;
236 m_maxDocsOpen = 10000;
238 #if wxUSE_PRINTING_ARCHITECTURE
239 m_pageSetupData =
new wxPageSetupDialogData;
242 m_currentDocument = NULL;
243 m_currentView = (
a2dView* ) NULL;
249 #if defined(_DEBUG) && defined (SMART_POINTER_DEBUG)
250 , m_initCurrentSmartPointerOwner( this )
257 #if wxUSE_PRINTING_ARCHITECTURE
287 #if wxUSE_PRINTING_ARCHITECTURE
295 if ( event.GetId() == CmdMenu_Exit().GetId() )
299 else if ( event.GetId() == CmdMenu_FileClose().GetId() )
303 else if ( event.GetId() == CmdMenu_FileCloseAll().GetId() )
307 else if ( event.GetId() == CmdMenu_FileOpen().GetId() )
318 else if ( event.GetId() == CmdMenu_FileNew().GetId() )
323 else if ( event.GetId() == CmdMenu_FileSave().GetId() )
327 else if ( event.GetId() == CmdMenu_FileSaveAll().GetId() )
331 else if ( event.GetId() == CmdMenu_FileSaveAs().GetId() )
335 else if ( event.GetId() == CmdMenu_FileImport().GetId() )
339 else if ( event.GetId() == CmdMenu_FileExport().GetId() )
343 else if ( event.GetId() == CmdMenu_FileRevert().GetId() )
347 else if ( event.GetId() == CmdMenu_CreateView().GetId() )
351 else if ( event.GetId() == CmdMenu_Print().GetId() )
355 else if ( event.GetId() == CmdMenu_PrintView().GetId() )
359 else if ( event.GetId() == CmdMenu_PreviewView().GetId() )
363 else if ( event.GetId() == CmdMenu_PrintDocument().GetId() )
367 else if ( event.GetId() == CmdMenu_PreviewDocument().GetId() )
371 else if ( event.GetId() == CmdMenu_PrintSetup().GetId() )
375 else if ( event.GetId() == CmdMenu_EmptyDocument().GetId() )
423 a2dDocumentList::iterator iter =
m_docs.begin();
424 while( iter !=
m_docs.end() )
432 a2dDECLARE_LOCAL_ITEM( a2dDocumentList::value_type, doc, *iter );
435 if ( doc->Close( force ) || force )
439 doc->DisConnectAllViews();
500 if (
Clear( force ) )
506 wxFrame* pf = ( wxFrame* ) wxTheApp->GetTopWindow();
507 if ( wxTopLevelWindows.Find( pf ) && !wxPendingDelete.Member( pf ) )
527 if ( doc->
Close( force ) )
556 wxString filename = file.GetFullPath();
559 if ( filename.IsEmpty() )
584 path.Add( wxT(
"." ) );
585 if ( !path.ExpandPath( filename ) )
616 wxString filename = file.GetFullPath();
617 wxASSERT_MSG( ! filename.IsEmpty(), wxT(
"need a filename that is not empty" ) );
620 if ( filename.IsEmpty() )
640 bool alreadyOpen =
false;
642 a2dDocumentList::iterator iter =
m_docs.begin();
643 while( iter !=
m_docs.end() )
646 if ( doc->
GetFilename().GetFullPath() == filename )
664 file.GetTimes( &dtAccess, &dtMod, &dtCreate );
666 if ( dtMod > doc->GetModificationTime() )
672 if ( !useDocTemplate )
677 a2dDocumentTemplateList::value_type temp = *iter;
681 useDocTemplate = temp;
700 wxString expandedPath = openPath;
702 path.Add( wxT(
"." ) );
703 if ( !path.ExpandPath( expandedPath ) )
738 bool result = doc->
Save();
751 a2dDocumentList::iterator iter =
m_docs.begin();
752 while( iter !=
m_docs.end() )
754 a2dDECLARE_LOCAL_ITEM( a2dDocumentList::value_type, doc, *iter );
755 if ( doc && doc->IsModified() )
757 bool result = doc->Save();
773 path.Add( wxT(
"." ) );
774 wxString foundfile = file.GetFullPath();
775 if ( !path.ExpandPath( foundfile ) )
781 bool result = doc->
SaveAs( foundfile, flags );
802 a2dDocumentTemplateList::value_type temp = *iter;
806 if ( ( description.IsEmpty() && !file.GetExt().IsEmpty() && file.GetExt() == temp->GetDefaultExtension() ) ||
807 temp->GetDescription() == description ||
808 file.GetExt().IsEmpty()
812 ( !temp->GetDocumentIOHandlerStrOut() || temp->GetDocumentIOHandlerStrOut()->CanSave( doc ) )
815 onlyThisDocTemplates.push_back( temp );
819 preferredExportTemplate = temp;
832 path.Add( wxT(
"." ) );
833 wxString foundfile = file.GetFullPath();
834 if ( !path.ExpandPath( foundfile ) )
840 wxString fileName( foundfile );
841 wxString dir, name, ext;
842 wxFileName::SplitPath( fileName, & dir, & name, & ext );
847 if ( !preferredExportTemplate )
852 wxArrayString selectedPaths;
855 onlyThisDocTemplates,
860 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
865 foundfile = selectedPaths.Item( 0 );
881 foundfile = wxFileSelector( _(
"Export as" ),
886 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
892 fileName += wxT(
"." );
897 return doc->
Export( docTemplate, foundfile, flags );
913 a2dDocumentTemplateList::value_type temp = *iter;
917 if ( ( description.IsEmpty() && !file.GetExt().IsEmpty() && file.GetExt() == temp->GetDefaultExtension() ) ||
918 temp->GetDescription() == description ||
919 file.GetExt().IsEmpty()
923 ( !temp->GetDocumentIOHandlerStrOut() || temp->GetDocumentIOHandlerStrOut()->CanSave( doc ) )
926 onlyThisDocTemplates.push_back( temp );
930 preferredImportTemplate = temp;
943 path.Add( wxT(
"." ) );
944 wxString foundfile = file.GetFullPath();
945 if ( !path.ExpandPath( foundfile ) )
951 wxString fileName( foundfile );
952 wxString dir, name, ext;
953 wxFileName::SplitPath( fileName, & dir, & name, & ext );
958 if ( !preferredImportTemplate )
963 wxArrayString selectedPaths;
966 onlyThisDocTemplates,
976 foundfile = selectedPaths.Item( 0 );
992 foundfile = wxFileSelector( _(
"Import" ),
1001 if ( ext.IsEmpty() )
1003 fileName += wxT(
"." );
1008 return doc->
Import( docTemplate, foundfile, flags );
1014 #if wxUSE_PRINTING_ARCHITECTURE
1019 wxPageSetupDialogData* aPageSetupData = NULL;
1022 if( !aPageSetupData )
1028 if( !aPageSetupData )
1029 aPageSetupData = GetPageSetupData();
1031 wxPrintDialogData printDialogData( aPageSetupData->GetPrintData() );
1033 wxPrintout* printout = view->
OnCreatePrintout( printWhat, *aPageSetupData );
1036 wxPrinter printer( &printDialogData );
1038 aPageSetupData->SetPrintData( printer.GetPrintDialogData().GetPrintData() );
1042 #endif // wxUSE_PRINTING_ARCHITECTURE
1048 #if wxUSE_PRINTING_ARCHITECTURE
1052 wxPageSetupDialogData* aPageSetupData = NULL;
1055 if( !aPageSetupData )
1061 if( !aPageSetupData )
1062 aPageSetupData = GetPageSetupData();
1064 wxPrintDialogData printDialogData( aPageSetupData->GetPrintData() );
1066 wxPrintout* printout = view->
OnCreatePrintout( printWhat, *aPageSetupData );
1070 wxPrintPreviewBase* preview = ( wxPrintPreviewBase* ) NULL;
1071 preview =
new wxPrintPreview( printout, view->
OnCreatePrintout( printWhat, *aPageSetupData ), &printDialogData );
1072 if ( !preview->Ok() )
1075 wxMessageBox( _(
"Sorry, print preview needs a printer to be installed." ) );
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 );
1085 #endif // wxUSE_PRINTING_ARCHITECTURE
1089 void a2dDocumentCommandProcessor::SetPageSetupData( wxPageSetupDialogData* pageSetupData )
1091 #if wxUSE_PRINTING_ARCHITECTURE
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
1111 wxPageSetupDialogData* d;
1116 d =
new wxPageSetupDialogData();
1118 d->SetDefaultInfo(
true);
1123 wxPageSetupDialog pageSetupDialog(NULL, d);
1124 if ( pageSetupDialog.ShowModal() != wxID_OK )
1130 return pageSetupDialog.GetPageSetupData();
1132 wxPageSetupDialog pageSetupDialog(NULL, d);
1133 if ( pageSetupDialog.ShowModal() != wxID_OK )
1135 d->SetDefaultInfo(
false);
1140 return pageSetupDialog.GetPageSetupData();
1146 #if wxUSE_PRINTING_ARCHITECTURE
1148 wxPageSetupDialogData* aPageSetupData = NULL;
1162 else if ( printWhat == a2dPRINT_PrintSetup )
1167 if ( !aPageSetupData )
1175 aPageSetupData = GetPageSetupData();
1177 if ( !aPageSetupData )
1178 aPageSetupData = GetPageSetupData();
1180 return aPageSetupData;
1181 #endif // wxUSE_PRINTING_ARCHITECTURE
1204 if ( !wantedDocTemplate )
1209 a2dDocumentTemplateList::value_type temp = *iter;
1210 if ( temp->CheckMask( docTemplateFlags ) )
1213 wantedDocTemplate = temp;
1235 a2dDECLARE_LOCAL_ITEM( a2dDocumentList::value_type, doc,
m_docs.front() );
1237 if ( doc->Close(
false ) )
1239 doc->DisConnectAllViews();
1254 fileTemplate = wantedDocTemplate;
1268 event.SetEventObject( newDoc );
1269 newDoc->ProcessEvent( event );
1284 if ( ret == newDoc && !newDoc->
IsClosed() )
1290 openedDocList.push_back( newDoc );
1306 a2dDocumentList::iterator iter = openedDocList.begin();
1307 for( ; iter != openedDocList.end(); iter++ )
1326 wxArrayString selectedPaths;
1332 fileTemplate = wantedDocTemplate;
1333 selectedPaths.Add( path );
1340 selectedPaths.Add( path );
1352 docTemplates.push_back( wantedDocTemplate );
1353 fileTemplate = wantedDocTemplate;
1354 wxString pathInOut = path;
1366 wxString pathInOut = path;
1386 for(
size_t i = 0; i < selectedPaths.GetCount(); i++ )
1388 newDoc = fileTemplate->
CreateDocument( selectedPaths[i], documentflags );
1396 eventopen.SetEventObject( newDoc );
1397 if ( !newDoc->ProcessEvent( eventopen ) || !eventopen.
IsAllowed() )
1400 event.SetEventObject(
this );
1409 if ( ret == newDoc && !newDoc->
IsClosed() )
1417 openedDocList.push_back( newDoc );
1433 a2dDocumentList::iterator iter = openedDocList.begin();
1434 for( ; iter != openedDocList.end(); iter++ )
1448 a2dDocument* newDoc,
const wxString& viewTypeName,
1454 return CreateView( newDoc, viewTypeName, documentflags, viewTemplateFlags );
1458 bool sentPreAddCreatedDocumentEvent,
bool sentPostCreateDocumentEvent,
1470 a2dDocumentTemplateList::value_type temp = *iter;
1471 if ( temp->CheckMask( docTemplateFlags ) )
1475 foundtemplate = temp;
1482 wxASSERT_MSG( foundtemplate,
1483 _(
"a2dDocumentCommandProcessor::AddCreatedDocument Could not find template for document type name" ) );
1486 _(
"a2dDocumentCommandProcessor::AddCreatedDocument template DocumentTypeName different from document" ) );
1488 if ( !foundtemplate )
1502 if ( doc->
Close(
false ) )
1521 event.SetEventObject( newDoc );
1522 newDoc->ProcessEvent( event );
1530 if ( sentPreAddCreatedDocumentEvent )
1538 if ( sentPostCreateDocumentEvent )
1560 wxASSERT_MSG( viewTypeName.IsEmpty(), _(
"a2dDocumentCommandProcessor::CreateView could not find template of given type" ) );
1577 bool a2dDocumentCommandProcessor::FlushDoc(
a2dDocument* WXUNUSED( doc ) )
1614 wxString appName = wxTheApp->GetAppName();
1623 docName = docName + modifiedIndicator;
1625 title = docName + wxString( wxT(
" - " ) ) + appName;
1641 m_fileHistory->AddFileToHistory( file, docTemplate, viewTemplate );
1658 histFile = item->m_filename.GetFullPath();
1683 void a2dDocumentCommandProcessor::FileHistoryLoad( wxConfigBase& config )
1689 void a2dDocumentCommandProcessor::FileHistorySave( wxConfigBase& config )
1726 a2dDocumentTemplateList::value_type temp = *iter;
1727 if ( temp->FileMatchesTemplate( path ) && temp->CheckMask( mask ) )
1741 wxWindow* parent = wxTheApp->GetTopWindow();
1743 wxWindow* focusWindow = wxWindow::FindFocus();
1746 while ( focusWindow &&
1747 !focusWindow->IsKindOf( CLASSINFO( wxDialog ) ) &&
1748 !focusWindow->IsKindOf( CLASSINFO( wxFrame ) ) )
1750 focusWindow = focusWindow->GetParent();
1753 parent = focusWindow;
1760 const wxString& title,
1764 wxArrayString* selectedPaths,
1771 int FilterIndex = -1;
1774 #if defined(__WXMSW__) || defined(__WXGTK__)
1777 int filterCount = 0;
1780 a2dDocumentTemplateList::value_type temp = *iter;
1781 if ( temp->CheckMask( docTemplateFlags ) )
1783 if( temp == preferedTemplate )
1784 FilterIndex = filterCount;
1788 if ( !descrBuf.IsEmpty() )
1789 descrBuf << wxT(
'|' );
1791 descrBuf << temp->GetDescription()
1792 << wxT(
" (" ) << temp->GetFileFilter() << wxT(
") |" )
1793 << temp->GetFileFilter();
1797 descrBuf << wxT(
"*.*" );
1801 if ( path.IsEmpty() )
1804 if ( preferedTemplate )
1806 else if ( docTemplates.size() )
1807 path = docTemplates.front()->GetDirectory();
1815 descrBuf, dialogflags, parent, selectedPaths ) )
1818 if ( selectedPaths->GetCount() )
1820 if ( dialogflags & wxFD_OPEN )
1823 for(
size_t i = 0; i < selectedPaths->GetCount(); i++ )
1824 if( !wxFileExists( selectedPaths->Item( i ) ) )
1827 if ( !wxTheApp->GetAppName().IsEmpty() )
1828 msgTitle = wxTheApp->GetAppName();
1830 msgTitle = wxString( _(
"File error" ) );
1833 buf.Printf( _(
"Sorry, could not open the file: %s\n" ), selectedPaths->Item( i ).c_str() );
1834 wxMessageBox( buf , msgTitle, wxOK | wxICON_EXCLAMATION );
1838 path = wxPathOnly( selectedPaths->Item( 0 ) );
1842 if ( FilterIndex != -1 )
1847 a2dDocumentTemplateList::value_type temp = *iter;
1849 if ( temp->CheckMask( docTemplateFlags ) )
1851 if ( n == FilterIndex )
1853 *chosenTemplate = temp;
1862 if ( dialogflags & wxFD_OPEN && !*chosenTemplate )
1872 wxArrayString strings;
1879 a2dDocumentTemplateList::value_type temp = *iter;
1880 if ( temp->CheckMask( docTemplateFlags ) )
1884 for ( j = 0; j < n; j++ )
1893 strings.Add( temp->GetDescription() );
1894 templates[n] = temp;
1906 n = strings.Count();
1907 for ( i = 0; i < n; i++ )
1911 a2dDocumentTemplateList::value_type temp = *iter;
1912 if ( strings[i] == temp->GetDescription() )
1913 templates[i] = temp;
1929 theTemplate = templates[0];
1936 _(
"Select a document template" ),
1939 (
void** )templates,
1951 const wxString& viewTypeName,
1955 if ( !viewTypeName.IsEmpty() )
1960 a2dViewTemplateList::value_type temp = *iter;
1961 if ( temp->GetViewTypeName() == viewTypeName )
1969 wxArrayString strings;
1977 a2dViewTemplateList::value_type temp = *iter;
1978 if ( !temp->GetViewTypeName().empty() && temp->CheckMask( mask ) &&
1981 strings.Add( temp->GetViewTypeName() );
1982 templates[n] = temp;
1994 n = strings.Count();
1995 for ( i = 0; i < n; i++ )
1999 a2dViewTemplateList::value_type temp = *iter;
2000 if ( strings[i] == temp->GetViewTypeName() )
2002 templates[i] = temp;
2019 theTemplate = templates[0];
2026 wxString::Format( _(
"Select a document view for the file %s" ), doc->
GetFilename().GetFullName().c_str() ),
2029 (
void** )templates,
2073 event.SetEventObject(
this );
2088 event.SetEventObject(
this );
2099 static bool recur =
false;
2176 if ( !document || changed )
2181 event.SetEventObject(
this );
2201 event.Enable(
true );
2212 event.Enable(
m_docs.size() != 0 );
2223 event.Enable(
true );
2234 a2dDocumentList::iterator iter =
m_docs.begin();
2235 while( iter !=
m_docs.end() )
2237 a2dDECLARE_LOCAL_ITEM( a2dDocumentList::value_type, doc, *iter );
2238 if ( doc && doc->IsModified() )
2240 event.Enable(
true );
2245 event.Enable(
false );
2340 return a2dCommandProcessor::ProcessEvent( event );
2352 m_docviewCommandProcessor =
new a2dDocumentCommandProcessor();
2360 m_docviewCommandProcessor = docviewCommandProcessor;
2371 wxString recordstring;
2372 va_start( ap, Format );
2376 recordstring.PrintfV( Format, ap );
2380 event.SetEventObject( sender );
2382 ProcessEvent( event );
2389 wxString recordstring;
2390 va_start( ap, Format );
2394 recordstring.PrintfV( Format, ap );
2398 event.SetEventObject(
this );
2400 ProcessEvent( event );
2413 static const wxChar* s_MRUEntryFormat = wxT( "&%lu %s" );
2416 static inline wxChar* MYcopystring( const wxString& s )
2418 wxChar* copy =
new wxChar[s.length() + 1];
2419 return wxStrcpy( copy, s.c_str() );
2422 static inline wxChar* MYcopystring(
const wxChar* s )
2424 wxChar* copy =
new wxChar[wxStrlen( s ) + 1];
2425 return wxStrcpy( copy, s );
2428 a2dFileHistory::a2dFileHistory(
size_t maxFiles, wxWindowID idBase )
2430 m_fileMaxFiles = maxFiles;
2434 a2dFileHistory::~a2dFileHistory()
2441 a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2443 for( ; iter != m_fileHistoryList.end(); iter++ )
2446 if ( fileitem->m_filename == file )
2449 RemoveFileFromHistory ( i );
2451 AddFileToHistory( file, docTemplate, viewTemplate );
2458 if ( m_fileMaxFiles == m_fileHistoryList.size() )
2460 RemoveFileFromHistory ( m_fileHistoryList.size() - 1 );
2461 AddFileToHistory( file, docTemplate, viewTemplate );
2467 if ( m_fileHistoryList.size() < m_fileMaxFiles )
2469 wxList::compatibility_iterator node = m_fileMenus.GetFirst();
2472 wxMenu* menu = ( wxMenu* ) node->GetData();
2473 if ( m_fileHistoryList.empty() && menu->GetMenuItemCount() )
2475 menu->AppendSeparator();
2478 menu->Append( m_idBase + m_fileHistoryList.size(), _(
"[EMPTY]" ) );
2479 node = node->GetNext();
2482 m_fileHistoryList.push_front(
new a2dFileHistoryItem( file, docTemplate, viewTemplate ) );
2485 iter = m_fileHistoryList.begin();
2486 wxString pathCurrent = ( *iter )->m_filename.GetPath();
2490 for( ; iter != m_fileHistoryList.end(); iter++ )
2496 wxString pathInMenu, path;
2497 path = fileitem->m_filename.GetPath();
2498 if ( path == pathCurrent )
2499 pathInMenu = fileitem->m_filename.GetFullName();
2503 pathInMenu = fileitem->m_filename.GetFullPath();
2507 pathInMenu.Replace( _T(
"&" ), _T(
"&&" ) );
2509 buf.Printf( s_MRUEntryFormat, i + 1, pathInMenu.c_str() );
2510 wxList::compatibility_iterator node = m_fileMenus.GetFirst();
2513 wxMenu* menu = ( wxMenu* ) node->GetData();
2514 menu->SetLabel( m_idBase + i, buf );
2515 node = node->GetNext();
2521 void a2dFileHistory::RemoveFileFromHistory(
size_t i )
2523 wxCHECK_RET( i < m_fileHistoryList.size(),
2524 wxT(
"invalid index in a2dFileHistory::RemoveFileFromHistory" ) );
2527 a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2529 for( ; iter != m_fileHistoryList.end(); iter++ )
2534 m_fileHistoryList.erase( iter );
2540 wxList::compatibility_iterator node = m_fileMenus.GetFirst();
2543 wxMenu* menu = ( wxMenu* ) node->GetData();
2547 a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2549 for( ; iter != m_fileHistoryList.end(); iter++ )
2552 buf.Printf( s_MRUEntryFormat, j + 1, fileitem->m_filename.GetFullPath().c_str() );
2553 menu->SetLabel( m_idBase + j, buf );
2557 node = node->GetNext();
2560 wxWindowID lastItemId = m_idBase + wx_truncate_cast( wxWindowID, m_fileHistoryList.size() );
2561 if ( menu->FindItem( lastItemId ) )
2563 menu->Delete( lastItemId );
2567 if ( m_fileHistoryList.empty() )
2569 wxMenuItemList::compatibility_iterator nodeLast = menu->GetMenuItems().GetLast();
2572 wxMenuItem* menuItem = nodeLast->GetData();
2573 if ( menuItem->IsSeparator() )
2575 menu->Delete( menuItem );
2584 wxString a2dFileHistory::GetHistoryFile(
size_t i )
const
2587 if ( i < m_fileHistoryList.size() )
2589 a2dFileHistoryItemList::const_iterator iter = m_fileHistoryList.item( i );
2591 s = fileitem->m_filename.GetFullPath();
2594 wxFAIL_MSG( wxT(
"bad index in a2dFileHistory::GetHistoryFile" ) );
2601 if ( i < m_fileHistoryList.size() )
2603 a2dFileHistoryItemList::const_iterator iter = m_fileHistoryList.item( i );
2607 wxFAIL_MSG( wxT(
"bad index in a2dFileHistory::GetHistoryFile" ) );
2611 void a2dFileHistory::UseMenu( wxMenu* menu )
2613 if ( !m_fileMenus.Member( menu ) )
2614 m_fileMenus.Append( menu );
2617 void a2dFileHistory::RemoveMenu( wxMenu* menu )
2619 m_fileMenus.DeleteObject( menu );
2623 void a2dFileHistory::Load( wxConfigBase& config )
2626 buf.Printf( wxT(
"file%d" ), 1 );
2627 wxString historyFile;
2629 while ( ( m_fileHistoryList.size() < m_fileMaxFiles ) && config.Read( buf, &historyFile ) && ( !historyFile.empty() ) )
2632 a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2633 for( ; iter != m_fileHistoryList.end(); iter++ )
2636 if ( fileitem->m_filename.GetFullPath() == historyFile )
2640 m_fileHistoryList.push_back(
new a2dFileHistoryItem( wxFileName( historyFile ), NULL, NULL ) );
2641 buf.Printf( wxT(
"file%d" ), fileid++ );
2642 historyFile = wxEmptyString;
2647 void a2dFileHistory::Save( wxConfigBase& config )
2649 a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2651 for( ; iter != m_fileHistoryList.end(); iter++ )
2655 buf.Printf( wxT(
"file%d" ), (
int )j + 1 );
2656 if ( j < m_fileHistoryList.size() )
2657 config.Write( buf, fileitem->m_filename.GetFullPath() );
2659 config.Write( buf, wxEmptyString );
2663 #endif // wxUSE_CONFIG
2665 void a2dFileHistory::AddFilesToMenu()
2667 if ( !m_fileHistoryList.empty() )
2669 wxList::compatibility_iterator node = m_fileMenus.GetFirst();
2672 wxMenu* menu = ( wxMenu* ) node->GetData();
2673 if ( menu->GetMenuItemCount() )
2675 menu->AppendSeparator();
2678 a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2680 for( ; iter != m_fileHistoryList.end(); iter++ )
2684 buf.Printf( s_MRUEntryFormat, i + 1, fileitem->m_filename.GetFullPath().c_str() );
2685 menu->Append( m_idBase + i, buf );
2688 node = node->GetNext();
2693 void a2dFileHistory::AddFilesToMenu( wxMenu* menu )
2695 if ( !m_fileHistoryList.empty() )
2697 if ( menu->GetMenuItemCount() )
2699 menu->AppendSeparator();
2702 a2dFileHistoryItemList::iterator iter = m_fileHistoryList.begin();
2704 for( ; iter != m_fileHistoryList.end(); iter++ )
2708 buf.Printf( s_MRUEntryFormat, i + 1, fileitem->m_filename.GetFullPath().c_str() );
2709 menu->Append( m_idBase + i, buf );
2723 #if wxUSE_PRINTING_ARCHITECTURE
2724 if( wxThePrintPaperDatabase == NULL )
2726 wxThePrintPaperDatabase =
new wxPrintPaperDatabase;
2727 wxThePrintPaperDatabase->CreateDatabase();
2728 m_wxThePrintPaperDatabase = wxThePrintPaperDatabase;
2737 void a2dDocviewModule::OnExit()
2739 delete wxNullRefObjectList;
2741 a2dDocviewGlobals = NULL;
2742 #if wxUSE_PRINTING_ARCHITECTURE
2743 if( m_wxThePrintPaperDatabase && m_wxThePrintPaperDatabase != wxThePrintPaperDatabase )
2744 delete m_wxThePrintPaperDatabase;
2745 m_wxThePrintPaperDatabase = NULL;
virtual void DeleteContents()
called when there is a need to clear the contents of the document.
void OnUpdateFileOpen(wxUpdateUIEvent &event)
Handlers for UI update commands.
void ReleaseTemplate(a2dDocumentTemplate *temp, long flags=0)
remove/release a template
virtual bool Undo()
Undo one command or command group.
bool IsModified() const
Has the document been modified.
virtual bool Redo()
Redo one command or command group.
const a2dError a2dError_NoDocTemplateRef
void OnUpdateFileSaveAs(wxUpdateUIEvent &event)
Handlers for UI update commands.
a2dDocumentTemplate * m_preferredExportTemplate
preferred document template for Exporting files.
a2dDocumentTemplateList m_docTemplates
templates for documents
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.
void OnActivateView(a2dViewEvent &viewevent)
Views do inform the document manager.
virtual bool CanUndo() const
Are there commands to undo and can they be undone ?
#define EVT_ACTIVATE_VIEW(func)
event sent to view and document manager
a2dDocumentTemplate * MatchTemplate(const wxString &path)
return template suitable for loading the file in path, using FindTemplateForPath. ...
fundamental classes used by all other modules.
void OnUpdateFileClose(wxUpdateUIEvent &event)
Handlers for UI update commands.
a2dDocumentTemplate * m_preferredImportTemplate
preferred document template for Importing files.
void RemoveDocument(a2dDocument *doc)
remove a document from the manager's list
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.
The a2dViewTemplate class is used to model the relationship between a document class and a view class...
const a2dError a2dError_CouldNotEvaluatePath
const a2dDocumentList & GetDocuments() const
returns a reference to the a2dDocumentList, which contains all a2dDocument's that are open...
virtual void SetCurrentView(a2dView *view)
To set the curent view.
wxString GetDocumentTypeName() const
Gets the document type name of this document. See the comment for documentTypeName.
void SetDirectory(const wxString &dir)
Sets the default directory.
wxString GetDirectory() const
Returns the default directory, as passed to the document template constructor.
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.
void OnUpdateUndo(wxUpdateUIEvent &event)
Handlers for UI update commands.
a2dDocumentTemplate * GetDocumentTemplate() const
Gets a2dDocumentTemplate pointer which was used to create the a2dView.
void OnUpdateFileCloseAll(wxUpdateUIEvent &event)
Handlers for UI update commands.
bool Exit(bool force=true)
Called to Exit the application properly.
void AssociateDocTemplate(a2dDocumentTemplate *temp)
add a reference to a a2dDocumentTemplate to the a2dDocumentTemplateList
const a2dError a2dError_NoError
void OnMenu(wxCommandEvent &event)
All menu's ( also using a2dMenuIdItem ) can be intercepted here.
wxWindow * GetDisplayWindow()
Get the display window.
virtual wxString MakeFrameTitle(a2dDocument *doc, const wxString &modifiedIndicator=wxT(""))
Make a frame title (override this to do something different)
void ConnectEvent(wxEventType type, wxEvtHandler *eventSink)
void OnCannotOpenDocument(a2dCommandEvent &event)
default handler when a file could not be opened
The a2dDocumentTemplate class is used to model the relationship between a document class and files...
virtual void RecordF(wxObject *sender, const wxChar *Format,...)
to sent a ::wxEVT_RECORD event
a2dCommandProcessor * GetCommandProcessor() const
Returns a pointer to the command processor associated with this document.
const a2dError a2dError_FileCouldNotOpen
virtual void FileHistoryAddFilesToMenu()
Appends the files in the history list, to all menus managed by the file history object.
void CheckCurrentView(a2dView *view)
Views do inform the document manager when a view will be destroyed.
bool m_busyExit
set when terminating application
void OnUpdatePreview(wxUpdateUIEvent &event)
Handlers for UI update commands.
wxPageSetupDialogData GetDefaultPrintSettings()
Return page setup data, as set in the current default printer.
void DisassociateViewTemplate(a2dViewTemplate *temp)
remove a reference to a a2dViewTemplate to the wxViewTemplateReflist
unsigned int a2dTemplateFlagMask
mask of flags for a2dTemplateFlag
bool SaveAs(const wxFileName &fileTosaveTo=wxFileName(wxT("")), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Tries to save the document by sending a a2dDocumentEvent ::wxEVT_SAVEAS_DOCUMENT event.
void SetCurrentDocument(a2dDocument *document)
set the current document, only needed in cases
virtual wxString GetHistoryFile(size_t i) const
return the filename of the i'th file in the history
a2dView event, to report events in the a2dView class
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.
a2dError FileNew(a2dDocumentPtr &doc, a2dTemplateFlagMask docTemplateFlags=a2dTemplateFlag::VISIBLE)
Creates a document from a list of templates (if more than one template).
virtual void Initialize()
Initialises the current command and menu strings.
Docview framework its controlling class.
void OnUpdateCreateView(wxUpdateUIEvent &event)
Handlers for UI update commands.
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.
bool Close(bool force)
Closes the document if not vetod.
bool FileRevert()
revert the current document to the non saved document on disk.
const a2dError a2dError_IOHandler
wxPageSetupDialogData * GetPrintSetup(a2dPrintWhat printWhat)
get printer setup the current active view or document or the one from central command processor...
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
bool IsClosed()
A closed flag is set when a view is closed.
long m_flags
user flags use at will ( not used internal )
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: ...
Holds a view on a a2dDocument.
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
void DisassociateDocTemplate(a2dDocumentTemplate *temp)
remove a reference to a a2dDocumentTemplate to the a2dDocumentTemplateList
virtual void CreateCommandProcessor()
create a command processor and set it for the document.
void OnUpdateFileRevert(wxUpdateUIEvent &event)
Handlers for UI update commands.
virtual void AddFileToHistory(const wxFileName &file, a2dDocumentTemplate *docTemplate=NULL, a2dViewTemplate *viewTemplate=NULL)
File history management.
#define EVT_ADD_VIEW(func)
event sent to document when a view has been added to the document
virtual a2dFileHistory * OnCreateFileHistory()
A hook to allow a derived class to create a different type of file history. Called from Initialize...
virtual void FileHistoryUseMenu(wxMenu *menu)
Use this menu for appending recently-visited document filenames,.
void OnUpdateFileSave(wxUpdateUIEvent &event)
Handlers for UI update commands.
void SetDocviewCommandProcessor(a2dDocumentCommandProcessor *docviewCommandProcessor)
Normally the docview commandprocessor is set in the constructor when creating new a2dDocviewGlobal...
The document class can be used to model an application's file-based data.
void OnRemoveView(a2dDocumentEvent &viewevent)
Views do inform the document manager when a view will be removed.
void DisConnectAllViews()
Disconnect a2dView's using this document.
virtual a2dFileHistoryItem * GetHistoryFileItem(size_t i) const
return the a2dFileHistoryItem of the i'th file in the history
void SetDocumentTemplate(a2dDocumentTemplate *temp)
Set a2dDocumentTemplate pointer.
virtual bool SubmitToDocument(a2dCommand *command, bool storeIt=true)
redirect the command to the current document ( if available )
bool Clear(bool force=true)
Clear remaining documents and templates.
virtual void ReportError(const a2dError &error, const wxString &errorstr=wxEmptyString)
concatenate to the the error report the given error.
virtual bool ProcessEvent(wxEvent &event)
wxPageSetupDialogData * m_pageSetupData
this is the global printer page setup data for printer
wxUint16 a2dPrintWhat
defines what to print
bool FileSaveAs(const wxFileName &file=wxFileName(wxT("")), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Calls wxDocument::SaveAs for the current document.
Docview classes for document view, window and frame.
const a2dPrintWhat a2dPRINT_PreviewDocument
preview print a2dDocument
One object of this class may be created in an application, to manage all the templates and documents...
virtual bool MakeDefaultName(wxString &buf)
Make a default document name.
bool IsAllowed() const
for implementation code only: is the operation allowed?
~a2dDocviewGlobal()
destructor
virtual bool CanRedo() const
Are there commands to redo and can they be redone ?
a2dError GetError()
in case of errors when sending an event, this is to know the reason of failure
wxString GetFileFilter() const
Returns the file filter, as passed to the document template constructor.
a2dDocument * GetCurrentDocument() const
Get the current Document, which is the document that was last accessed from a view.
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.
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.
static const a2dTemplateFlagMask EXPORTING
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.
bool FileImport(const wxFileName &file=wxFileName(wxT("")), const wxString &description=wxT(""), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Calls a2dDocument::Import for the current document.
virtual void FileHistoryRemoveMenu(wxMenu *menu)
Removes the given menu from the list of menus managed by the file history object. ...
void OnUpdatePrint(wxUpdateUIEvent &event)
Handlers for UI update commands.
void SetFileName(const wxFileName &filename)
set filename of file to open, before sending the event.
a2dError FileOpenCheck(a2dDocumentPtr &doc, const wxFileName &file, bool checkModification)
Return existing document, or open it from file.
static const a2dTemplateFlagMask IMPORTING
bool Preview(a2dPrintWhat printWhat=a2dPRINT_Preview)
print preview of the current active view.
void Activate(bool activate)
is called via ProcessEvent() when the view becomes active
a2dFileHistory * m_fileHistory
the file history
virtual bool Submit(a2dCommand *command, bool storeIt=true)
next to the base class submit, it sets a2DocumentCommandProcessor for a2dCommand
void OnUpdateRedo(wxUpdateUIEvent &event)
Handlers for UI update commands.
wxFileName GetFilename() const
Get the file name in use for this document.
One Global instance of this class exists, in order to get to.
bool PrintSetup(a2dPrintWhat printWhat)
printer setup the current active document or central command processor.
a2dView * m_currentView
the current view (active or inactive)
a2dView * GetCurrentView() const
return the one that is active right now (e.g. has focus in case of a wxWindow), or NULL ...
virtual size_t GetHistoryFilesCount() const
Return number fo files in history.
void OnRedo(wxCommandEvent &event)
default handler for GUI event with id wxID_REDO
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
virtual bool Revert()
Normally should undo all changes by rereading the file again.
bool CloseDocuments(bool force=true)
closes all currently open documents
a2dDocumentList m_docs
list of all that are open
a2dViewTemplateList m_viewTemplates
templates for views
bool Print(a2dPrintWhat printWhat=a2dPRINT_Print)
print the current active view.
a2dDocumentCommandProcessor(long flags=a2dDEFAULT_DOCUMENT_FLAGS, bool initialize=true, int maxCommands=-1)
Constructor.
a2dDocument * GetDocument() const
get the document of the view
a2dDocviewGlobal * a2dDocviewGlobals
a global pointer to get to global instance of important classes.
bool FileExport(const wxFileName &file=wxFileName(wxT("")), const wxString &description=wxT(""), a2dDocumentFlagMask flags=a2dREFDOC_NON)
Calls a2dDocument::Export for the current document.
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
static bool m_directlog
logging to wxLog target on or off
virtual void ReportErrorF(const a2dError &error, const wxChar *Format,...)
concatenate to the the error report the given error.
~a2dDocumentCommandProcessor()
destructor
wxString GetPrintableName() const
Get title, or filename if no title, else [unnamed].
const a2dPrintWhat a2dPRINT_PrintDocument
print a2dDocument
A list class for reference counted objects.
bool IsClosed()
returns true when document is closed or busy closing.
a2dCommandProcessor * GetCurrentDocumentCommandProcessor() const
get the command processor of the current document.
bool GetActive()
return if the view is active/
itSmart Find(T *object)
Find a specific object.
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.
bool FileSaveAll()
Saves the documents by calling wxDocument::Save for each document.
const a2dError a2dError_ToManyOpen
virtual void OnExit()
Called by Exit()
void OnAddView(a2dDocumentEvent &docevent)
It works when a2dView::SetDocument() executing.
A module to initialize the docview framework.
void SendToLogTarget()
all stored errors and warning are sent to log target using wxLogError()
used to report a2dDocument events
static const a2dTemplateFlagMask LOAD
void SetTitle(const wxString &title, bool notifyViews=false)
Sets the title for this document.
void OnUpdateFileNew(wxUpdateUIEvent &event)
Handlers for UI update commands.
void AddDocument(a2dDocument *doc)
Add a document to the manager's list.
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.
void OnUndo(wxCommandEvent &event)
default handler for GUI event with id wxID_UNDO
void AssociateViewTemplate(a2dViewTemplate *temp)
add a reference to a a2dViewTemplate to the wxViewTemplateReflist
wxString GetDocumentTypeName() const
Returns the document type name, as passed to the document template constructor.
#define const_forEachIn(listtype, list)
easy const iteration for a2dlist
size_t m_maxDocsOpen
the maximum of documents allowed open
void SetDocumentTypeName(const wxString &name)
Sets the document type name for this document. See the comment for documentTypeName.
const a2dPrintWhat a2dPRINT_PreviewView
preview print a2dView
static const a2dTemplateFlagMask VISIBLE
a2dDocumentTemplate * m_preferredOpenTemplate
preferred document template for Opening files.
bool FileSave()
Saves the current document by calling wxDocument::Save for the current document.
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
virtual void Initialize()
Initializes data; currently just calls OnCreateFileHistory.
const a2dPrintWhat a2dPRINT_PrintView
print a2dView
bool Save()
Saves the document by sending a a2dDocumentEvent ::wxEVT_SAVE_DOCUMENT event.
int m_defaultDocumentNameCounter
to create unique new names for file
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.
wxWindow * wxFindSuitableParent()
find a parent wxWindow pointer to place a control into
wxString GetDefaultExtension() const
Returns the default file extension for the document data, as passed to the document template construc...
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...
#define EVT_CANNOT_OPEN_DOCUMENT(func)
event sent when a file could not be opened in the a2dDocumentCommandProcessor
wxString GetTitle() const
Returns the title for this document.
wxString m_lastDirectory
the last visited directory
#define EVT_REMOVE_VIEW(func)
event sent to document when a view will be removed from the document
a2dSmrtPtr< a2dDocument > a2dDocumentPtr
document smart pointer
a2dDocument * m_currentDocument
the current active document
a2dDocviewGlobal()
constructor
bool GetEnable()
when ::wxEVT_ENABLE_VIEWS get enable value of the event
a2dDocument * GetDocument()
the document created/removed or on which the command was applied.
holds one file for placing in history list
unsigned int a2dDocumentFlagMask
mask of flags for a2dDocumentFlag
a base command for the a2dCommandProcessor