#include "wx/list.h"
#include "wx/filedlg.h"
#include "wx/intl.h"
+ #include "wx/log.h"
#endif
+#ifdef __WXMAC__
+ #include "wx/filename.h"
+#endif
#ifdef __WXGTK__
#include "wx/mdi.h"
bool wxDocument::OnCloseDocument()
{
+ // Tell all views that we're about to close
+ NotifyClosing();
DeleteContents();
Modify(FALSE);
return TRUE;
{
wxDocManager* manager = GetDocumentManager();
- wxNode *node = m_documentViews.First();
+ wxNode *node = m_documentViews.GetFirst();
while (node)
{
- wxView *view = (wxView *)node->Data();
+ wxView *view = (wxView *)node->GetData();
if (!view->Close())
return FALSE;
- wxNode *next = node->Next();
+ wxNode *next = node->GetNext();
delete view; // Deletes node implicitly
node = next;
wxView *wxDocument::GetFirstView() const
{
- if (m_documentViews.Number() == 0)
+ if (m_documentViews.GetCount() == 0)
return (wxView *) NULL;
- return (wxView *)m_documentViews.First()->Data();
+ return (wxView *)m_documentViews.GetFirst()->GetData();
}
wxDocManager *wxDocument::GetDocumentManager() const
if (ext.IsEmpty() || ext == wxT(""))
{
- fileName += ".";
+ fileName += wxT(".");
fileName += docTemplate->GetDefaultExtension();
}
GetDocumentManager()->AddFileToHistory(fileName);
// Notify the views that the filename has changed
- wxNode *node = m_documentViews.First();
+ wxNode *node = m_documentViews.GetFirst();
while (node)
{
- wxView *view = (wxView *)node->Data();
+ wxView *view = (wxView *)node->GetData();
view->OnChangeFilename();
- node = node->Next();
+ node = node->GetNext();
}
return OnSaveDocument(m_documentFile);
msgTitle = wxString(_("File error"));
#if wxUSE_STD_IOSTREAM
- wxSTD ofstream store(wxString(file.fn_str()).mb_str());
+ wxSTD ofstream store(wxString(file.fn_str()).mb_str()); // ?????
if (store.fail() || store.bad())
#else
- wxFileOutputStream store(wxString(file.fn_str()));
- if (store.LastError() != wxSTREAM_NOERROR)
+ wxFileOutputStream store( file );
+ if (store.GetLastError() != wxSTREAM_NO_ERROR)
#endif
{
(void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION,
Modify(FALSE);
SetFilename(file);
SetDocumentSaved(TRUE);
+#ifdef __WXMAC__
+ wxFileName fn(file) ;
+ fn.MacSetDefaultTypeAndCreator() ;
+#endif
return TRUE;
}
msgTitle = wxString(_("File error"));
#if wxUSE_STD_IOSTREAM
- wxSTD ifstream store(wxString(file.fn_str()).mb_str());
+ wxSTD ifstream store(wxString(file.fn_str()).mb_str()); // ????
if (store.fail() || store.bad())
#else
- wxFileInputStream store(wxString(file.fn_str()));
- if (store.LastError() != wxSTREAM_NOERROR)
+ wxFileInputStream store( file );
+ if (store.GetLastError() != wxSTREAM_NO_ERROR)
#endif
{
(void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION,
return FALSE;
}
#if wxUSE_STD_IOSTREAM
- if (!LoadObject(store))
+ LoadObject(store);
+ if ( !store && !store.eof() )
#else
- int res = LoadObject(store).LastError();
- if ((res != wxSTREAM_NOERROR) &&
+ int res = LoadObject(store).GetLastError();
+ if ((res != wxSTREAM_NO_ERROR) &&
(res != wxSTREAM_EOF))
#endif
{
// there are no more views.
void wxDocument::OnChangedViewList()
{
- if (m_documentViews.Number() == 0)
+ if (m_documentViews.GetCount() == 0)
{
if (OnSaveModified())
{
void wxDocument::UpdateAllViews(wxView *sender, wxObject *hint)
{
- wxNode *node = m_documentViews.First();
+ wxNode *node = m_documentViews.GetFirst();
+ while (node)
+ {
+ wxView *view = (wxView *)node->GetData();
+ if (view != sender)
+ view->OnUpdate(sender, hint);
+ node = node->GetNext();
+ }
+}
+
+void wxDocument::NotifyClosing()
+{
+ wxNode *node = m_documentViews.GetFirst();
while (node)
{
- wxView *view = (wxView *)node->Data();
- view->OnUpdate(sender, hint);
- node = node->Next();
+ wxView *view = (wxView *)node->GetData();
+ view->OnClosingDocument();
+ node = node->GetNext();
}
}
if ( notifyViews )
{
// Notify the views that the filename has changed
- wxNode *node = m_documentViews.First();
+ wxNode *node = m_documentViews.GetFirst();
while (node)
{
- wxView *view = (wxView *)node->Data();
+ wxView *view = (wxView *)node->GetData();
view->OnChangeFilename();
- node = node->Next();
+ node = node->GetNext();
}
}
}
void wxView::Activate(bool activate)
{
- if (GetDocumentManager())
+ if (GetDocument() && GetDocumentManager())
{
OnActivateView(activate, this, GetDocumentManager()->GetCurrentView());
GetDocumentManager()->ActivateView(this, activate);
BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler)
EVT_MENU(wxID_OPEN, wxDocManager::OnFileOpen)
EVT_MENU(wxID_CLOSE, wxDocManager::OnFileClose)
+ EVT_MENU(wxID_CLOSE_ALL, wxDocManager::OnFileCloseAll)
EVT_MENU(wxID_REVERT, wxDocManager::OnFileRevert)
EVT_MENU(wxID_NEW, wxDocManager::OnFileNew)
EVT_MENU(wxID_SAVE, wxDocManager::OnFileSave)
EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen)
EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateFileClose)
+ EVT_UPDATE_UI(wxID_CLOSE_ALL, wxDocManager::OnUpdateFileClose)
EVT_UPDATE_UI(wxID_REVERT, wxDocManager::OnUpdateFileRevert)
EVT_UPDATE_UI(wxID_NEW, wxDocManager::OnUpdateFileNew)
EVT_UPDATE_UI(wxID_SAVE, wxDocManager::OnUpdateFileSave)
sm_docManager = (wxDocManager*) NULL;
}
-bool wxDocManager::Clear(bool force)
+bool wxDocManager::CloseDocuments(bool force)
{
- wxNode *node = m_docs.First();
+ wxNode *node = m_docs.GetFirst();
while (node)
{
- wxDocument *doc = (wxDocument *)node->Data();
- wxNode *next = node->Next();
+ wxDocument *doc = (wxDocument *)node->GetData();
+ wxNode *next = node->GetNext();
if (!doc->Close() && !force)
return FALSE;
// delete another.
node = next;
}
- node = m_templates.First();
+ return TRUE;
+}
+
+bool wxDocManager::Clear(bool force)
+{
+ if (!CloseDocuments(force))
+ return FALSE;
+
+ wxNode *node = m_templates.GetFirst();
while (node)
{
- wxDocTemplate *templ = (wxDocTemplate*) node->Data();
- wxNode* next = node->Next();
+ wxDocTemplate *templ = (wxDocTemplate*) node->GetData();
+ wxNode* next = node->GetNext();
delete templ;
node = next;
}
}
}
+void wxDocManager::OnFileCloseAll(wxCommandEvent& WXUNUSED(event))
+{
+ CloseDocuments(FALSE);
+}
+
void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event))
{
- CreateDocument(wxString(""), wxDOC_NEW);
+ CreateDocument( wxT(""), wxDOC_NEW );
}
void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event))
{
- if ( !CreateDocument(wxString(""), 0) )
+ if ( !CreateDocument( wxT(""), 0) )
{
OnOpenFileFailure();
}
void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event)
{
wxDocument *doc = GetCurrentDocument();
- event.Enable( (doc != (wxDocument*) NULL) );
+ event.Enable( doc && doc->IsModified() );
}
void wxDocManager::OnUpdateFileSaveAs(wxUpdateUIEvent& event)
{
wxDocument *doc = GetCurrentDocument();
event.Enable( (doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanUndo()) );
+ if (doc && doc->GetCommandProcessor())
+ doc->GetCommandProcessor()->SetMenuStrings();
}
void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event)
{
wxDocument *doc = GetCurrentDocument();
event.Enable( (doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanRedo()) );
+ if (doc && doc->GetCommandProcessor())
+ doc->GetCommandProcessor()->SetMenuStrings();
}
void wxDocManager::OnUpdatePrint(wxUpdateUIEvent& event)
{
if (m_currentView)
return m_currentView;
- if (m_docs.Number() == 1)
+ if (m_docs.GetCount() == 1)
{
- wxDocument* doc = (wxDocument*) m_docs.First()->Data();
+ wxDocument* doc = (wxDocument*) m_docs.GetFirst()->GetData();
return doc->GetFirstView();
}
return (wxView *) NULL;
wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
{
- wxDocTemplate **templates = new wxDocTemplate *[m_templates.Number()];
- int i;
- int n = 0;
- for (i = 0; i < m_templates.Number(); i++)
+ wxDocTemplate **templates = new wxDocTemplate *[m_templates.GetCount()];
+ int n = 0;
+
+ for (size_t i = 0; i < m_templates.GetCount(); i++)
{
- wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Nth(i)->Data());
+ wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Item(i)->GetData());
if (temp->IsVisible())
{
templates[n] = temp;
// If we've reached the max number of docs, close the
// first one.
- if (GetDocuments().Number() >= m_maxDocsOpen)
+ if ( (int)GetDocuments().GetCount() >= m_maxDocsOpen )
{
- wxDocument *doc = (wxDocument *)GetDocuments().First()->Data();
+ wxDocument *doc = (wxDocument *)GetDocuments().GetFirst()->GetData();
if (doc->Close())
{
// Implicitly deletes the document when
wxView *wxDocManager::CreateView(wxDocument *doc, long flags)
{
- wxDocTemplate **templates = new wxDocTemplate *[m_templates.Number()];
- int n =0;
- int i;
- for (i = 0; i < m_templates.Number(); i++)
+ wxDocTemplate **templates = new wxDocTemplate *[m_templates.GetCount()];
+ int n =0;
+
+ for (size_t i = 0; i < m_templates.GetCount(); i++)
{
- wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Nth(i)->Data());
+ wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Item(i)->GetData());
if (temp->IsVisible())
{
if (temp->GetDocumentName() == doc->GetDocumentName())
wxDocument *wxDocManager::GetCurrentDocument() const
{
- if (m_currentView)
- return m_currentView->GetDocument();
+ wxView *view = GetCurrentView();
+ if (view)
+ return view->GetDocument();
else
return (wxDocument *) NULL;
}
wxDocTemplate *theTemplate = (wxDocTemplate *) NULL;
// Find the template which this extension corresponds to
- int i;
- for (i = 0; i < m_templates.Number(); i++)
+ for (size_t i = 0; i < m_templates.GetCount(); i++)
{
- wxDocTemplate *temp = (wxDocTemplate *)m_templates.Nth(i)->Data();
+ wxDocTemplate *temp = (wxDocTemplate *)m_templates.Item(i)->GetData();
if ( temp->FileMatchesTemplate(path) )
{
theTemplate = temp;
// template extension.
wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
-#if defined(__WXMSW__) || defined(__WXGTK__)
+#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
int noTemplates,
#else
int WXUNUSED(noTemplates),
bool WXUNUSED(save))
{
// We can only have multiple filters in Windows and GTK
-#if defined(__WXMSW__) || defined(__WXGTK__)
+#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
wxString descrBuf;
int i;
wxDocTemplate **data = new wxDocTemplate *[noTemplates];
int i;
int n = 0;
+
for (i = 0; i < noTemplates; i++)
{
if (templates[i]->IsVisible())
{
- strings.Add(templates[i]->m_description);
- if (!sort)
+ int j;
+ bool want = TRUE;
+ for (j = 0; j < n; j++)
{
+ //filter out NOT unique documents + view combinations
+ if ( templates[i]->m_docTypeName == data[j]->m_docTypeName &&
+ templates[i]->m_viewTypeName == data[j]->m_viewTypeName
+ )
+ want = FALSE;
+ }
+
+ if ( want )
+ {
+ strings.Add(templates[i]->m_description);
+
data[n] = templates[i];
n ++;
}
wxDocTemplate **data = new wxDocTemplate *[noTemplates];
int i;
int n = 0;
+
for (i = 0; i < noTemplates; i++)
{
wxDocTemplate *templ = templates[i];
if ( templ->IsVisible() && !templ->GetViewName().empty() )
{
- strings.Add(templ->m_viewTypeName);
- if (!sort)
+ int j;
+ bool want = TRUE;
+ for (j = 0; j < n; j++)
{
+ //filter out NOT unique views
+ if ( templates[i]->m_viewTypeName == data[j]->m_viewTypeName )
+ want = FALSE;
+ }
+
+ if ( want )
+ {
+ strings.Add(templ->m_viewTypeName);
data[n] = templ;
n ++;
}
// Move existing files (if any) down so we can insert file at beginning.
if (m_fileHistoryN < m_fileMaxFiles)
{
- wxNode* node = m_fileMenus.First();
+ wxNode* node = m_fileMenus.GetFirst();
while (node)
{
- wxMenu* menu = (wxMenu*) node->Data();
- if (m_fileHistoryN == 0)
+ wxMenu* menu = (wxMenu*) node->GetData();
+ if ( m_fileHistoryN == 0 && menu->GetMenuItemCount() )
+ {
menu->AppendSeparator();
+ }
menu->Append(wxID_FILE1+m_fileHistoryN, _("[EMPTY]"));
- node = node->Next();
+ node = node->GetNext();
}
m_fileHistoryN ++;
}
wxString buf;
buf.Printf(s_MRUEntryFormat, i + 1, pathInMenu.c_str());
- wxNode* node = m_fileMenus.First();
+ wxNode* node = m_fileMenus.GetFirst();
while (node)
{
- wxMenu* menu = (wxMenu*) node->Data();
+ wxMenu* menu = (wxMenu*) node->GetData();
menu->SetLabel(wxID_FILE1 + i, buf);
- node = node->Next();
+ node = node->GetNext();
}
}
}
m_fileHistory[j] = m_fileHistory[j + 1];
}
- wxNode* node = m_fileMenus.First();
+ wxNode* node = m_fileMenus.GetFirst();
while ( node )
{
- wxMenu* menu = (wxMenu*) node->Data();
+ wxMenu* menu = (wxMenu*) node->GetData();
// shuffle filenames up
menu->SetLabel(wxID_FILE1 + j, buf);
}
- node = node->Next();
+ node = node->GetNext();
// delete the last menu item which is unused now
if (menu->FindItem(wxID_FILE1 + m_fileHistoryN - 1))
wxString buf;
buf.Printf(wxT("file%d"), m_fileHistoryN+1);
wxString historyFile;
- while ((m_fileHistoryN <= m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != wxT("")))
+ while ((m_fileHistoryN < m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != wxT("")))
{
m_fileHistory[m_fileHistoryN] = copystring((const wxChar*) historyFile);
m_fileHistoryN ++;
{
if (m_fileHistoryN > 0)
{
- wxNode* node = m_fileMenus.First();
+ wxNode* node = m_fileMenus.GetFirst();
while (node)
{
- wxMenu* menu = (wxMenu*) node->Data();
- menu->AppendSeparator();
+ wxMenu* menu = (wxMenu*) node->GetData();
+ if (menu->GetMenuItemCount())
+ {
+ menu->AppendSeparator();
+ }
+
int i;
for (i = 0; i < m_fileHistoryN; i++)
{
menu->Append(wxID_FILE1+i, buf);
}
}
- node = node->Next();
+ node = node->GetNext();
}
}
}
{
if (m_fileHistoryN > 0)
{
- menu->AppendSeparator();
+ if (menu->GetMenuItemCount())
+ {
+ menu->AppendSeparator();
+ }
+
int i;
for (i = 0; i < m_fileHistoryN; i++)
{
return FALSE;
}
- int len = stream.StreamSize();
+ int len = stream.GetSize();
// TODO: is this the correct test for EOF?
while (stream.TellI() < (len - 1))
{