From: Vadim Zeitlin Date: Mon, 29 Mar 1999 16:46:18 +0000 (+0000) Subject: many miscellaneous fixes X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/0fb67cd1968707f15341792406da62045e11c5f0 many miscellaneous fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1998 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/docview.cpp b/src/common/docview.cpp index e1cebc28d1..deb4271735 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -9,37 +9,45 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ -#pragma implementation "docview.h" + #pragma implementation "docview.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP -#include "wx/defs.h" + #include "wx/defs.h" #endif #if wxUSE_DOC_VIEW_ARCHITECTURE #ifndef WX_PRECOMP -#include "wx/string.h" -#include "wx/utils.h" -#include "wx/app.h" -#include "wx/dc.h" -#include "wx/dialog.h" -#include "wx/menu.h" -#include "wx/list.h" -#include "wx/filedlg.h" -#include + #include "wx/string.h" + #include "wx/utils.h" + #include "wx/app.h" + #include "wx/dc.h" + #include "wx/dialog.h" + #include "wx/menu.h" + #include "wx/list.h" + #include "wx/filedlg.h" + #include #endif #ifdef __WXGTK__ -#include "wx/mdi.h" + #include "wx/mdi.h" #endif #include "wx/msgdlg.h" @@ -59,150 +67,175 @@ #include #endif +// ---------------------------------------------------------------------------- +// wxWindows macros +// ---------------------------------------------------------------------------- + #if !USE_SHARED_LIBRARY -IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler) -IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler) -IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxDocManager, wxEvtHandler) -IMPLEMENT_CLASS(wxDocChildFrame, wxFrame) -IMPLEMENT_CLASS(wxDocParentFrame, wxFrame) -#if wxUSE_PRINTING_ARCHITECTURE -IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout, wxPrintout) -#endif -IMPLEMENT_CLASS(wxCommand, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject) -// IMPLEMENT_DYNAMIC_CLASS(wxPrintInfo, wxObject) + IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler) + IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler) + IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate, wxObject) + IMPLEMENT_DYNAMIC_CLASS(wxDocManager, wxEvtHandler) + IMPLEMENT_CLASS(wxDocChildFrame, wxFrame) + IMPLEMENT_CLASS(wxDocParentFrame, wxFrame) + + #if wxUSE_PRINTING_ARCHITECTURE + IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout, wxPrintout) + #endif + + IMPLEMENT_CLASS(wxCommand, wxObject) + IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject) + IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject) #endif -/* - * Definition of wxDocument - */ +// ---------------------------------------------------------------------------- +// function prototypes +// ---------------------------------------------------------------------------- + +static inline wxString FindExtension(const char *path); + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// local functions +// ---------------------------------------------------------------------------- + +static wxString FindExtension(const char *path) +{ + wxString ext; + wxSplitPath(path, NULL, NULL, &ext); + + // VZ: extensions are considered not case sensitive - is this really a good + // idea? + return ext.MakeLower(); +} + +// ---------------------------------------------------------------------------- +// Definition of wxDocument +// ---------------------------------------------------------------------------- wxDocument::wxDocument(wxDocument *parent) { - m_documentModified=FALSE; - m_documentFile=""; - m_documentTitle=""; - m_documentParent=parent; - m_documentTemplate = (wxDocTemplate *) NULL; - m_documentTypeName = ""; - m_savedYet = FALSE; + m_documentModified = FALSE; + m_documentParent = parent; + m_documentTemplate = (wxDocTemplate *) NULL; + m_savedYet = FALSE; } -bool wxDocument::DeleteContents(void) +bool wxDocument::DeleteContents() { - return TRUE; + return TRUE; } -wxDocument::~wxDocument(void) +wxDocument::~wxDocument() { - DeleteContents(); + DeleteContents(); - if (m_commandProcessor) - delete m_commandProcessor; + if (m_commandProcessor) + delete m_commandProcessor; - GetDocumentManager()->RemoveDocument(this); + GetDocumentManager()->RemoveDocument(this); - // Not safe to do here, since it'll - // invoke virtual view functions expecting to see - // valid derived objects: and by the time we get - // here, we've called destructors higher up. -// DeleteAllViews(); + // Not safe to do here, since it'll invoke virtual view functions + // expecting to see valid derived objects: and by the time we get here, + // we've called destructors higher up. + //DeleteAllViews(); } - -bool wxDocument::Close(void) + +bool wxDocument::Close() { - if (OnSaveModified()) - return OnCloseDocument(); - else - return FALSE; + if (OnSaveModified()) + return OnCloseDocument(); + else + return FALSE; } - -bool wxDocument::OnCloseDocument(void) + +bool wxDocument::OnCloseDocument() { - DeleteContents(); - Modify(FALSE); - return TRUE; + DeleteContents(); + Modify(FALSE); + return TRUE; } -// Note that this implicitly deletes the document when -// the last view is deleted. -bool wxDocument::DeleteAllViews(void) +// Note that this implicitly deletes the document when the last view is +// deleted. +bool wxDocument::DeleteAllViews() { - wxNode *node = m_documentViews.First(); - while (node) - { - wxView *view = (wxView *)node->Data(); - if (!view->Close()) - return FALSE; + wxNode *node = m_documentViews.First(); + while (node) + { + wxView *view = (wxView *)node->Data(); + if (!view->Close()) + return FALSE; - wxNode *next = node->Next(); - - delete view; // Deletes node implicitly - node = next; - } - return TRUE; + wxNode *next = node->Next(); + + delete view; // Deletes node implicitly + node = next; + } + return TRUE; } wxView *wxDocument::GetFirstView(void) const { - if (m_documentViews.Number() == 0) - return (wxView *) NULL; - return (wxView *)m_documentViews.First()->Data(); + if (m_documentViews.Number() == 0) + return (wxView *) NULL; + return (wxView *)m_documentViews.First()->Data(); } wxDocManager *wxDocument::GetDocumentManager(void) const { - return m_documentTemplate->GetDocumentManager(); + return m_documentTemplate->GetDocumentManager(); } -bool wxDocument::OnNewDocument(void) +bool wxDocument::OnNewDocument() { - if (!OnSaveModified()) - return FALSE; - - if (OnCloseDocument()==FALSE) return FALSE; - DeleteContents(); - Modify(FALSE); - SetDocumentSaved(FALSE); + if (!OnSaveModified()) + return FALSE; - wxString name; - GetDocumentManager()->MakeDefaultName(name); - SetTitle(name); - SetFilename(name, TRUE); + if (OnCloseDocument()==FALSE) return FALSE; + DeleteContents(); + Modify(FALSE); + SetDocumentSaved(FALSE); - return TRUE; + wxString name; + GetDocumentManager()->MakeDefaultName(name); + SetTitle(name); + SetFilename(name, TRUE); + + return TRUE; } -bool wxDocument::Save(void) +bool wxDocument::Save() { - bool ret = FALSE; + bool ret = FALSE; - if (!IsModified()) return TRUE; - if (m_documentFile == "" || !m_savedYet) - ret = SaveAs(); - else - ret = OnSaveDocument(m_documentFile); - if ( ret ) - SetDocumentSaved(TRUE); - return ret; + if (!IsModified()) return TRUE; + if (m_documentFile == "" || !m_savedYet) + ret = SaveAs(); + else + ret = OnSaveDocument(m_documentFile); + if ( ret ) + SetDocumentSaved(TRUE); + return ret; } - -bool wxDocument::SaveAs(void) + +bool wxDocument::SaveAs() { wxDocTemplate *docTemplate = GetDocumentTemplate(); if (!docTemplate) return FALSE; - + wxString tmp = wxFileSelector(_("Save as"), - docTemplate->GetDirectory(), - GetFilename(), - docTemplate->GetDefaultExtension(), - docTemplate->GetFileFilter(), - wxSAVE | wxOVERWRITE_PROMPT, - GetDocumentWindow()); - + docTemplate->GetDirectory(), + GetFilename(), + docTemplate->GetDefaultExtension(), + docTemplate->GetFileFilter(), + wxSAVE | wxOVERWRITE_PROMPT, + GetDocumentWindow()); + if (tmp.IsEmpty()) return FALSE; @@ -220,270 +253,269 @@ bool wxDocument::SaveAs(void) SetFilename(fileName); SetTitle(wxFileNameFromPath(fileName)); - + GetDocumentManager()->AddFileToHistory(fileName); // Notify the views that the filename has changed wxNode *node = m_documentViews.First(); while (node) { - wxView *view = (wxView *)node->Data(); - view->OnChangeFilename(); - node = node->Next(); + wxView *view = (wxView *)node->Data(); + view->OnChangeFilename(); + node = node->Next(); } return OnSaveDocument(m_documentFile); } - + bool wxDocument::OnSaveDocument(const wxString& file) { - if (file == "") - return FALSE; + if ( !file ) + return FALSE; - wxString msgTitle; - if (wxTheApp->GetAppName() != "") - msgTitle = wxTheApp->GetAppName(); - else - msgTitle = wxString(_("File error")); - - ofstream store(file); - if (store.fail() || store.bad()) - { - (void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION, - GetDocumentWindow()); - // Saving error - return FALSE; - } - if (SaveObject(store)==FALSE) - { - (void)wxMessageBox(_("Sorry, could not save this file."), msgTitle, wxOK | wxICON_EXCLAMATION, - GetDocumentWindow()); - // Saving error - return FALSE; - } - Modify(FALSE); - SetFilename(file); - return TRUE; + wxString msgTitle; + if (wxTheApp->GetAppName() != "") + msgTitle = wxTheApp->GetAppName(); + else + msgTitle = wxString(_("File error")); + + ofstream store(file); + if (store.fail() || store.bad()) + { + (void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION, + GetDocumentWindow()); + // Saving error + return FALSE; + } + if (SaveObject(store)==FALSE) + { + (void)wxMessageBox(_("Sorry, could not save this file."), msgTitle, wxOK | wxICON_EXCLAMATION, + GetDocumentWindow()); + // Saving error + return FALSE; + } + Modify(FALSE); + SetFilename(file); + return TRUE; } - + bool wxDocument::OnOpenDocument(const wxString& file) { - if (!OnSaveModified()) - return FALSE; + if (!OnSaveModified()) + return FALSE; - wxString msgTitle; - if (wxTheApp->GetAppName() != "") - msgTitle = wxTheApp->GetAppName(); - else - msgTitle = wxString(_("File error")); - - ifstream store(file); - if (store.fail() || store.bad()) - { - (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION, - GetDocumentWindow()); - return FALSE; - } - if (LoadObject(store)==FALSE) - { - (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION, - GetDocumentWindow()); - return FALSE; - } - SetFilename(file, TRUE); - Modify(FALSE); - m_savedYet = TRUE; + wxString msgTitle; + if (wxTheApp->GetAppName() != "") + msgTitle = wxTheApp->GetAppName(); + else + msgTitle = wxString(_("File error")); + + ifstream store(file); + if (store.fail() || store.bad()) + { + (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION, + GetDocumentWindow()); + return FALSE; + } + if (LoadObject(store)==FALSE) + { + (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION, + GetDocumentWindow()); + return FALSE; + } + SetFilename(file, TRUE); + Modify(FALSE); + m_savedYet = TRUE; + + UpdateAllViews(); - UpdateAllViews(); - - return TRUE; + return TRUE; } - + istream& wxDocument::LoadObject(istream& stream) { -// wxObject::LoadObject(stream); + // wxObject::LoadObject(stream); - return stream; + return stream; } ostream& wxDocument::SaveObject(ostream& stream) { -// wxObject::SaveObject(stream); - - return stream; + // wxObject::SaveObject(stream); + + return stream; } -bool wxDocument::Revert(void) +bool wxDocument::Revert() { - return FALSE; + return FALSE; } // Get title, or filename if no title, else unnamed bool wxDocument::GetPrintableName(wxString& buf) const { - if (m_documentTitle != "") - { - buf = m_documentTitle; - return TRUE; - } - else if (m_documentFile != "") - { - buf = wxFileNameFromPath(m_documentFile); - return TRUE; - } - else - { - buf = _("unnamed"); - return TRUE; - } + if (m_documentTitle != "") + { + buf = m_documentTitle; + return TRUE; + } + else if (m_documentFile != "") + { + buf = wxFileNameFromPath(m_documentFile); + return TRUE; + } + else + { + buf = _("unnamed"); + return TRUE; + } } wxWindow *wxDocument::GetDocumentWindow(void) const { - wxView *view = GetFirstView(); - if (view) - return view->GetFrame(); - else - return wxTheApp->GetTopWindow(); + wxView *view = GetFirstView(); + if (view) + return view->GetFrame(); + else + return wxTheApp->GetTopWindow(); } -wxCommandProcessor *wxDocument::OnCreateCommandProcessor(void) +wxCommandProcessor *wxDocument::OnCreateCommandProcessor() { - return new wxCommandProcessor; + return new wxCommandProcessor; } // TRUE if safe to close -bool wxDocument::OnSaveModified(void) +bool wxDocument::OnSaveModified() { - if (IsModified()) - { - wxString title; - GetPrintableName(title); - - wxString msgTitle; - if (wxTheApp->GetAppName() != "") - msgTitle = wxTheApp->GetAppName(); - else - msgTitle = wxString(_("Warning")); - - wxString prompt; - prompt.Printf(_("Do you want to save changes to document %s?"), - (const char *)title); - int res = wxMessageBox(prompt, msgTitle, - wxYES_NO|wxCANCEL|wxICON_QUESTION, - GetDocumentWindow()); - if (res == wxNO) + if (IsModified()) { - Modify(FALSE); - return TRUE; + wxString title; + GetPrintableName(title); + + wxString msgTitle; + if (wxTheApp->GetAppName() != "") + msgTitle = wxTheApp->GetAppName(); + else + msgTitle = wxString(_("Warning")); + + wxString prompt; + prompt.Printf(_("Do you want to save changes to document %s?"), + (const char *)title); + int res = wxMessageBox(prompt, msgTitle, + wxYES_NO|wxCANCEL|wxICON_QUESTION, + GetDocumentWindow()); + if (res == wxNO) + { + Modify(FALSE); + return TRUE; + } + else if (res == wxYES) + return Save(); + else if (res == wxCANCEL) + return FALSE; } - else if (res == wxYES) - return Save(); - else if (res == wxCANCEL) - return FALSE; - } - return TRUE; + return TRUE; } bool wxDocument::Draw(wxDC& WXUNUSED(context)) { - return TRUE; + return TRUE; } bool wxDocument::AddView(wxView *view) { - if (!m_documentViews.Member(view)) - { - m_documentViews.Append(view); - OnChangedViewList(); - } - return TRUE; + if (!m_documentViews.Member(view)) + { + m_documentViews.Append(view); + OnChangedViewList(); + } + return TRUE; } bool wxDocument::RemoveView(wxView *view) { - (void)m_documentViews.DeleteObject(view); - OnChangedViewList(); - return TRUE; + (void)m_documentViews.DeleteObject(view); + OnChangedViewList(); + return TRUE; } bool wxDocument::OnCreate(const wxString& WXUNUSED(path), long flags) { - if (GetDocumentTemplate()->CreateView(this, flags)) - return TRUE; - else - return FALSE; + if (GetDocumentTemplate()->CreateView(this, flags)) + return TRUE; + else + return FALSE; } // Called after a view is added or removed. // The default implementation deletes the document if // there are no more views. -void wxDocument::OnChangedViewList(void) +void wxDocument::OnChangedViewList() { - if (m_documentViews.Number() == 0) - { - if (OnSaveModified()) + if (m_documentViews.Number() == 0) { - delete this; + if (OnSaveModified()) + { + delete this; + } } - } } void wxDocument::UpdateAllViews(wxView *sender, wxObject *hint) { - wxNode *node = m_documentViews.First(); - while (node) - { - wxView *view = (wxView *)node->Data(); - view->OnUpdate(sender, hint); - node = node->Next(); - } + wxNode *node = m_documentViews.First(); + while (node) + { + wxView *view = (wxView *)node->Data(); + view->OnUpdate(sender, hint); + node = node->Next(); + } } void wxDocument::SetFilename(const wxString& filename, bool notifyViews) { - m_documentFile = filename; - if ( notifyViews ) - { - // Notify the views that the filename has changed - wxNode *node = m_documentViews.First(); - while (node) + m_documentFile = filename; + if ( notifyViews ) { - wxView *view = (wxView *)node->Data(); - view->OnChangeFilename(); - node = node->Next(); + // Notify the views that the filename has changed + wxNode *node = m_documentViews.First(); + while (node) + { + wxView *view = (wxView *)node->Data(); + view->OnChangeFilename(); + node = node->Next(); + } } - } } +// ---------------------------------------------------------------------------- +// Document view +// ---------------------------------------------------------------------------- -/* - * Document view - */ - wxView::wxView() { -// SetDocument(doc); - m_viewDocument = (wxDocument*) NULL; - - m_viewTypeName = ""; - m_viewFrame = (wxFrame *) NULL; + // SetDocument(doc); + m_viewDocument = (wxDocument*) NULL; + + m_viewTypeName = ""; + m_viewFrame = (wxFrame *) NULL; } -wxView::~wxView(void) +wxView::~wxView() { - GetDocumentManager()->ActivateView(this, FALSE, TRUE); - m_viewDocument->RemoveView(this); + GetDocumentManager()->ActivateView(this, FALSE, TRUE); + m_viewDocument->RemoveView(this); } // Extend event processing to search the document's event table bool wxView::ProcessEvent(wxEvent& event) { - if ( !GetDocument() || !GetDocument()->ProcessEvent(event) ) - return wxEvtHandler::ProcessEvent(event); - else - return TRUE; + if ( !GetDocument() || !GetDocument()->ProcessEvent(event) ) + return wxEvtHandler::ProcessEvent(event); + else + return TRUE; } void wxView::OnActivateView(bool WXUNUSED(activate), wxView *WXUNUSED(activeView), wxView *WXUNUSED(deactiveView)) @@ -492,128 +524,136 @@ void wxView::OnActivateView(bool WXUNUSED(activate), wxView *WXUNUSED(activeView void wxView::OnPrint(wxDC *dc, wxObject *WXUNUSED(info)) { - OnDraw(dc); + OnDraw(dc); } void wxView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)) { } -void wxView::OnChangeFilename(void) +void wxView::OnChangeFilename() { - if (GetFrame() && GetDocument()) - { - wxString name; - GetDocument()->GetPrintableName(name); + if (GetFrame() && GetDocument()) + { + wxString name; + GetDocument()->GetPrintableName(name); - GetFrame()->SetTitle(name); - } + GetFrame()->SetTitle(name); + } } void wxView::SetDocument(wxDocument *doc) { - m_viewDocument = doc; - if (doc) - doc->AddView(this); + m_viewDocument = doc; + if (doc) + doc->AddView(this); } bool wxView::Close(bool deleteWindow) { - if (OnClose(deleteWindow)) - return TRUE; - else - return FALSE; + if (OnClose(deleteWindow)) + return TRUE; + else + return FALSE; } void wxView::Activate(bool activate) { - if (GetDocumentManager()) - { - OnActivateView(activate, this, GetDocumentManager()->GetCurrentView()); - GetDocumentManager()->ActivateView(this, activate); - } + if (GetDocumentManager()) + { + OnActivateView(activate, this, GetDocumentManager()->GetCurrentView()); + GetDocumentManager()->ActivateView(this, activate); + } } bool wxView::OnClose(bool WXUNUSED(deleteWindow)) { - return GetDocument() ? GetDocument()->Close() : TRUE; + return GetDocument() ? GetDocument()->Close() : TRUE; } #if wxUSE_PRINTING_ARCHITECTURE -wxPrintout *wxView::OnCreatePrintout(void) +wxPrintout *wxView::OnCreatePrintout() { - return new wxDocPrintout(this); + return new wxDocPrintout(this); } #endif +// ---------------------------------------------------------------------------- +// wxDocTemplate +// ---------------------------------------------------------------------------- -/* - * wxDocTemplate - */ - -wxDocTemplate::wxDocTemplate(wxDocManager *manager, const wxString& descr, - const wxString& filter, const wxString& dir, const wxString& ext, - const wxString& docTypeName, const wxString& viewTypeName, - wxClassInfo *docClassInfo, wxClassInfo *viewClassInfo, long flags) +wxDocTemplate::wxDocTemplate(wxDocManager *manager, + const wxString& descr, + const wxString& filter, + const wxString& dir, + const wxString& ext, + const wxString& docTypeName, + const wxString& viewTypeName, + wxClassInfo *docClassInfo, + wxClassInfo *viewClassInfo, + long flags) { - m_documentManager = manager; - m_flags = flags; - m_description = descr; - m_directory = dir; - m_defaultExt = ext; - m_fileFilter = filter; - m_flags = flags; - m_docTypeName = docTypeName; - m_viewTypeName = viewTypeName; - m_documentManager->AssociateTemplate(this); + m_documentManager = manager; + m_flags = flags; + m_description = descr; + m_directory = dir; + m_defaultExt = ext; + m_fileFilter = filter; + m_flags = flags; + m_docTypeName = docTypeName; + m_viewTypeName = viewTypeName; + m_documentManager->AssociateTemplate(this); - m_docClassInfo = docClassInfo; - m_viewClassInfo = viewClassInfo; + m_docClassInfo = docClassInfo; + m_viewClassInfo = viewClassInfo; } -wxDocTemplate::~wxDocTemplate(void) +wxDocTemplate::~wxDocTemplate() { - m_documentManager->DisassociateTemplate(this); + m_documentManager->DisassociateTemplate(this); } - -// Tries to dynamically construct an object of the right -// class. + +// Tries to dynamically construct an object of the right class. wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags) { - if (!m_docClassInfo) - return (wxDocument *) NULL; - wxDocument *doc = (wxDocument *)m_docClassInfo->CreateObject(); - doc->SetFilename(path); - doc->SetDocumentTemplate(this); - GetDocumentManager()->AddDocument(doc); - doc->SetCommandProcessor(doc->OnCreateCommandProcessor()); - - if (doc->OnCreate(path, flags)) - return doc; - else - { - delete doc; - return (wxDocument *) NULL; - } + if (!m_docClassInfo) + return (wxDocument *) NULL; + wxDocument *doc = (wxDocument *)m_docClassInfo->CreateObject(); + doc->SetFilename(path); + doc->SetDocumentTemplate(this); + GetDocumentManager()->AddDocument(doc); + doc->SetCommandProcessor(doc->OnCreateCommandProcessor()); + + if (doc->OnCreate(path, flags)) + return doc; + else + { + delete doc; + return (wxDocument *) NULL; + } } wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags) { - if (!m_viewClassInfo) - return (wxView *) NULL; - wxView *view = (wxView *)m_viewClassInfo->CreateObject(); - view->SetDocument(doc); - if (view->OnCreate(doc, flags)) - { - return view; - } - else - { - delete view; - return (wxView *) NULL; - } + if (!m_viewClassInfo) + return (wxView *) NULL; + wxView *view = (wxView *)m_viewClassInfo->CreateObject(); + view->SetDocument(doc); + if (view->OnCreate(doc, flags)) + { + return view; + } + else + { + delete view; + return (wxView *) NULL; + } } +// ---------------------------------------------------------------------------- +// wxDocManager +// ---------------------------------------------------------------------------- + BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler) EVT_MENU(wxID_OPEN, wxDocManager::OnFileOpen) EVT_MENU(wxID_CLOSE, wxDocManager::OnFileClose) @@ -630,182 +670,182 @@ END_EVENT_TABLE() wxDocManager::wxDocManager(long flags, bool initialize) { - m_defaultDocumentNameCounter = 1; - m_flags = flags; - m_currentView = (wxView *) NULL; - m_maxDocsOpen = 10000; - m_fileHistory = (wxFileHistory *) NULL; - if (initialize) - Initialize(); + m_defaultDocumentNameCounter = 1; + m_flags = flags; + m_currentView = (wxView *) NULL; + m_maxDocsOpen = 10000; + m_fileHistory = (wxFileHistory *) NULL; + if (initialize) + Initialize(); } -wxDocManager::~wxDocManager(void) +wxDocManager::~wxDocManager() { - Clear(); - if (m_fileHistory) - delete m_fileHistory; + Clear(); + if (m_fileHistory) + delete m_fileHistory; } bool wxDocManager::Clear(bool force) { - wxNode *node = m_docs.First(); - while (node) - { - wxDocument *doc = (wxDocument *)node->Data(); - wxNode *next = node->Next(); - - if (!doc->Close() && !force) - return FALSE; - - // Implicitly deletes the document when the last - // view is removed (deleted) - doc->DeleteAllViews(); - - // Check document is deleted - if (m_docs.Member(doc)) - delete doc; - - // This assumes that documents are not connected in - // any way, i.e. deleting one document does NOT - // delete another. - node = next; - } - node = m_templates.First(); - while (node) - { + wxNode *node = m_docs.First(); + while (node) + { + wxDocument *doc = (wxDocument *)node->Data(); + wxNode *next = node->Next(); + + if (!doc->Close() && !force) + return FALSE; + + // Implicitly deletes the document when the last + // view is removed (deleted) + doc->DeleteAllViews(); + + // Check document is deleted + if (m_docs.Member(doc)) + delete doc; + + // This assumes that documents are not connected in + // any way, i.e. deleting one document does NOT + // delete another. + node = next; + } + node = m_templates.First(); + while (node) + { wxDocTemplate *templ = (wxDocTemplate*) node->Data(); wxNode* next = node->Next(); delete templ; node = next; - } - return TRUE; + } + return TRUE; } -bool wxDocManager::Initialize(void) +bool wxDocManager::Initialize() { - m_fileHistory = OnCreateFileHistory(); - return TRUE; + m_fileHistory = OnCreateFileHistory(); + return TRUE; } -wxFileHistory *wxDocManager::OnCreateFileHistory(void) +wxFileHistory *wxDocManager::OnCreateFileHistory() { - return new wxFileHistory; + return new wxFileHistory; } void wxDocManager::OnFileClose(wxCommandEvent& WXUNUSED(event)) { - wxDocument *doc = GetCurrentDocument(); - if (!doc) - return; - if (doc->Close()) - { - doc->DeleteAllViews(); - if (m_docs.Member(doc)) - delete doc; - } + wxDocument *doc = GetCurrentDocument(); + if (!doc) + return; + if (doc->Close()) + { + doc->DeleteAllViews(); + if (m_docs.Member(doc)) + delete doc; + } } void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event)) { - CreateDocument(wxString(""), wxDOC_NEW); + CreateDocument(wxString(""), wxDOC_NEW); } void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event)) { - CreateDocument(wxString(""), 0); + CreateDocument(wxString(""), 0); } void wxDocManager::OnFileRevert(wxCommandEvent& WXUNUSED(event)) { - wxDocument *doc = GetCurrentDocument(); - if (!doc) - return; - doc->Revert(); + wxDocument *doc = GetCurrentDocument(); + if (!doc) + return; + doc->Revert(); } void wxDocManager::OnFileSave(wxCommandEvent& WXUNUSED(event)) { - wxDocument *doc = GetCurrentDocument(); - if (!doc) - return; - doc->Save(); + wxDocument *doc = GetCurrentDocument(); + if (!doc) + return; + doc->Save(); } void wxDocManager::OnFileSaveAs(wxCommandEvent& WXUNUSED(event)) { - wxDocument *doc = GetCurrentDocument(); - if (!doc) - return; - doc->SaveAs(); + wxDocument *doc = GetCurrentDocument(); + if (!doc) + return; + doc->SaveAs(); } void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event)) { - wxView *view = GetCurrentView(); - if (!view) - return; + wxView *view = GetCurrentView(); + if (!view) + return; - wxPrintout *printout = view->OnCreatePrintout(); - if (printout) - { - wxPrinter printer; - printer.Print(view->GetFrame(), printout, TRUE); + wxPrintout *printout = view->OnCreatePrintout(); + if (printout) + { + wxPrinter printer; + printer.Print(view->GetFrame(), printout, TRUE); - delete printout; - } + delete printout; + } } void wxDocManager::OnPrintSetup(wxCommandEvent& WXUNUSED(event)) { - wxWindow *parentWin = wxTheApp->GetTopWindow(); - wxView *view = GetCurrentView(); - if (view) - parentWin = view->GetFrame(); + wxWindow *parentWin = wxTheApp->GetTopWindow(); + wxView *view = GetCurrentView(); + if (view) + parentWin = view->GetFrame(); - wxPrintDialogData data; + wxPrintDialogData data; - wxPrintDialog printerDialog(parentWin, & data); - printerDialog.GetPrintDialogData().SetSetupDialog(TRUE); - printerDialog.ShowModal(); + wxPrintDialog printerDialog(parentWin, & data); + printerDialog.GetPrintDialogData().SetSetupDialog(TRUE); + printerDialog.ShowModal(); } void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event)) { - wxView *view = GetCurrentView(); - if (!view) - return; - - wxPrintout *printout = view->OnCreatePrintout(); - if (printout) - { - // Pass two printout objects: for preview, and possible printing. - wxPrintPreviewBase *preview = (wxPrintPreviewBase *) NULL; - preview = new wxPrintPreview(printout, view->OnCreatePrintout()); + wxView *view = GetCurrentView(); + if (!view) + return; - wxPreviewFrame *frame = new wxPreviewFrame(preview, (wxFrame *)wxTheApp->GetTopWindow(), _("Print Preview"), - wxPoint(100, 100), wxSize(600, 650)); - frame->Centre(wxBOTH); - frame->Initialize(); - frame->Show(TRUE); - } + wxPrintout *printout = view->OnCreatePrintout(); + if (printout) + { + // Pass two printout objects: for preview, and possible printing. + wxPrintPreviewBase *preview = (wxPrintPreviewBase *) NULL; + preview = new wxPrintPreview(printout, view->OnCreatePrintout()); + + wxPreviewFrame *frame = new wxPreviewFrame(preview, (wxFrame *)wxTheApp->GetTopWindow(), _("Print Preview"), + wxPoint(100, 100), wxSize(600, 650)); + frame->Centre(wxBOTH); + frame->Initialize(); + frame->Show(TRUE); + } } void wxDocManager::OnUndo(wxCommandEvent& WXUNUSED(event)) { - wxDocument *doc = GetCurrentDocument(); - if (!doc) - return; - if (doc->GetCommandProcessor()) - doc->GetCommandProcessor()->Undo(); + wxDocument *doc = GetCurrentDocument(); + if (!doc) + return; + if (doc->GetCommandProcessor()) + doc->GetCommandProcessor()->Undo(); } void wxDocManager::OnRedo(wxCommandEvent& WXUNUSED(event)) { - wxDocument *doc = GetCurrentDocument(); - if (!doc) - return; - if (doc->GetCommandProcessor()) - doc->GetCommandProcessor()->Redo(); + wxDocument *doc = GetCurrentDocument(); + if (!doc) + return; + if (doc->GetCommandProcessor()) + doc->GetCommandProcessor()->Redo(); } wxView *wxDocManager::GetCurrentView(void) const @@ -834,154 +874,154 @@ bool wxDocManager::ProcessEvent(wxEvent& event) 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 *temp = (wxDocTemplate *)(m_templates.Nth(i)->Data()); - if (temp->IsVisible()) + wxDocTemplate **templates = new wxDocTemplate *[m_templates.Number()]; + int i; + int n = 0; + for (i = 0; i < m_templates.Number(); i++) { - templates[n] = temp; - n ++; + wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Nth(i)->Data()); + if (temp->IsVisible()) + { + templates[n] = temp; + n ++; + } } - } - if (n == 0) - { - delete[] templates; - return (wxDocument *) NULL; - } - - // If we've reached the max number of docs, close the - // first one. - if (GetDocuments().Number() >= m_maxDocsOpen) - { - wxDocument *doc = (wxDocument *)GetDocuments().First()->Data(); - if (doc->Close()) + if (n == 0) { - // Implicitly deletes the document when - // the last view is deleted - doc->DeleteAllViews(); - - // Check we're really deleted - if (m_docs.Member(doc)) - delete doc; + delete[] templates; + return (wxDocument *) NULL; } - else - return (wxDocument *) NULL; - } - - // New document: user chooses a template, unless there's only one. - if (flags & wxDOC_NEW) - { - if (n == 1) + + // If we've reached the max number of docs, close the + // first one. + if (GetDocuments().Number() >= m_maxDocsOpen) { - wxDocTemplate *temp = templates[0]; - delete[] templates; - wxDocument *newDoc = temp->CreateDocument(path, flags); - if (newDoc) - { - newDoc->SetDocumentName(temp->GetDocumentName()); - newDoc->SetDocumentTemplate(temp); - newDoc->OnNewDocument(); - } - return newDoc; + wxDocument *doc = (wxDocument *)GetDocuments().First()->Data(); + if (doc->Close()) + { + // Implicitly deletes the document when + // the last view is deleted + doc->DeleteAllViews(); + + // Check we're really deleted + if (m_docs.Member(doc)) + delete doc; + } + else + return (wxDocument *) NULL; } - wxDocTemplate *temp = SelectDocumentType(templates, n); - delete[] templates; - if (temp) + // New document: user chooses a template, unless there's only one. + if (flags & wxDOC_NEW) { - wxDocument *newDoc = temp->CreateDocument(path, flags); - if (newDoc) - { - newDoc->SetDocumentName(temp->GetDocumentName()); - newDoc->SetDocumentTemplate(temp); - newDoc->OnNewDocument(); - } - return newDoc; + if (n == 1) + { + wxDocTemplate *temp = templates[0]; + delete[] templates; + wxDocument *newDoc = temp->CreateDocument(path, flags); + if (newDoc) + { + newDoc->SetDocumentName(temp->GetDocumentName()); + newDoc->SetDocumentTemplate(temp); + newDoc->OnNewDocument(); + } + return newDoc; + } + + wxDocTemplate *temp = SelectDocumentType(templates, n); + delete[] templates; + if (temp) + { + wxDocument *newDoc = temp->CreateDocument(path, flags); + if (newDoc) + { + newDoc->SetDocumentName(temp->GetDocumentName()); + newDoc->SetDocumentTemplate(temp); + newDoc->OnNewDocument(); + } + return newDoc; + } + else + return (wxDocument *) NULL; } - else - return (wxDocument *) NULL; - } - // Existing document - wxDocTemplate *temp = (wxDocTemplate *) NULL; + // Existing document + wxDocTemplate *temp = (wxDocTemplate *) NULL; - wxString path2(""); - if (path != "") - path2 = path; + wxString path2(""); + if (path != "") + path2 = path; - if (flags & wxDOC_SILENT) - temp = FindTemplateForPath(path2); - else - temp = SelectDocumentPath(templates, n, path2, flags); + if (flags & wxDOC_SILENT) + temp = FindTemplateForPath(path2); + else + temp = SelectDocumentPath(templates, n, path2, flags); - delete[] templates; + delete[] templates; - if (temp) - { - wxDocument *newDoc = temp->CreateDocument(path2, flags); - if (newDoc) + if (temp) { - newDoc->SetDocumentName(temp->GetDocumentName()); - newDoc->SetDocumentTemplate(temp); - if (!newDoc->OnOpenDocument(path2)) - { - delete newDoc; - return (wxDocument *) NULL; - } - AddFileToHistory(path2); + wxDocument *newDoc = temp->CreateDocument(path2, flags); + if (newDoc) + { + newDoc->SetDocumentName(temp->GetDocumentName()); + newDoc->SetDocumentTemplate(temp); + if (!newDoc->OnOpenDocument(path2)) + { + delete newDoc; + return (wxDocument *) NULL; + } + AddFileToHistory(path2); + } + return newDoc; } - return newDoc; - } - else - return (wxDocument *) NULL; + else + return (wxDocument *) NULL; } 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 *temp = (wxDocTemplate *)(m_templates.Nth(i)->Data()); - if (temp->IsVisible()) - { - if (temp->GetDocumentName() == doc->GetDocumentName()) - { - templates[n] = temp; - n ++; - } - } - } - if (n == 0) - { - delete[] templates; - return (wxView *) NULL; - } - if (n == 1) - { - wxDocTemplate *temp = templates[0]; + wxDocTemplate **templates = new wxDocTemplate *[m_templates.Number()]; + int n =0; + int i; + for (i = 0; i < m_templates.Number(); i++) + { + wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Nth(i)->Data()); + if (temp->IsVisible()) + { + if (temp->GetDocumentName() == doc->GetDocumentName()) + { + templates[n] = temp; + n ++; + } + } + } + if (n == 0) + { + delete[] templates; + return (wxView *) NULL; + } + if (n == 1) + { + wxDocTemplate *temp = templates[0]; + delete[] templates; + wxView *view = temp->CreateView(doc, flags); + if (view) + view->SetViewName(temp->GetViewName()); + return view; + } + + wxDocTemplate *temp = SelectViewType(templates, n); delete[] templates; - wxView *view = temp->CreateView(doc, flags); - if (view) - view->SetViewName(temp->GetViewName()); - return view; - } - - wxDocTemplate *temp = SelectViewType(templates, n); - delete[] templates; - if (temp) - { - wxView *view = temp->CreateView(doc, flags); - if (view) - view->SetViewName(temp->GetViewName()); - return view; - } - else - return (wxView *) NULL; + if (temp) + { + wxView *view = temp->CreateView(doc, flags); + if (view) + view->SetViewName(temp->GetViewName()); + return view; + } + else + return (wxView *) NULL; } // Not yet implemented @@ -992,142 +1032,120 @@ void wxDocManager::DeleteTemplate(wxDocTemplate *WXUNUSED(temp), long WXUNUSED(f // Not yet implemented bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc)) { - return FALSE; + return FALSE; } wxDocument *wxDocManager::GetCurrentDocument(void) const { - if (m_currentView) - return m_currentView->GetDocument(); - else - return (wxDocument *) NULL; + if (m_currentView) + return m_currentView->GetDocument(); + else + return (wxDocument *) NULL; } // Make a default document name bool wxDocManager::MakeDefaultName(wxString& name) { - name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter); - m_defaultDocumentNameCounter++; + name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter); + m_defaultDocumentNameCounter++; - return TRUE; + return TRUE; } // Not yet implemented wxDocTemplate *wxDocManager::MatchTemplate(const wxString& WXUNUSED(path)) { - return (wxDocTemplate *) NULL; + return (wxDocTemplate *) NULL; } // File history management void wxDocManager::AddFileToHistory(const wxString& file) { - if (m_fileHistory) - m_fileHistory->AddFileToHistory(file); + if (m_fileHistory) + m_fileHistory->AddFileToHistory(file); } wxString wxDocManager::GetHistoryFile(int i) const { - if (m_fileHistory) - return wxString(m_fileHistory->GetHistoryFile(i)); - else - return wxString(""); + wxString histFile; + + if (m_fileHistory) + histFile = m_fileHistory->GetHistoryFile(i); + + return histFile; } void wxDocManager::FileHistoryUseMenu(wxMenu *menu) { - if (m_fileHistory) - m_fileHistory->UseMenu(menu); + if (m_fileHistory) + m_fileHistory->UseMenu(menu); } void wxDocManager::FileHistoryRemoveMenu(wxMenu *menu) { - if (m_fileHistory) - m_fileHistory->RemoveMenu(menu); + if (m_fileHistory) + m_fileHistory->RemoveMenu(menu); } #if wxUSE_CONFIG void wxDocManager::FileHistoryLoad(wxConfigBase& config) { - if (m_fileHistory) - m_fileHistory->Load(config); + if (m_fileHistory) + m_fileHistory->Load(config); } void wxDocManager::FileHistorySave(wxConfigBase& config) { - if (m_fileHistory) - m_fileHistory->Save(config); + if (m_fileHistory) + m_fileHistory->Save(config); } #endif void wxDocManager::FileHistoryAddFilesToMenu(wxMenu* menu) { - if (m_fileHistory) - m_fileHistory->AddFilesToMenu(menu); + if (m_fileHistory) + m_fileHistory->AddFilesToMenu(menu); } void wxDocManager::FileHistoryAddFilesToMenu() { - if (m_fileHistory) - m_fileHistory->AddFilesToMenu(); + if (m_fileHistory) + m_fileHistory->AddFilesToMenu(); } int wxDocManager::GetNoHistoryFiles(void) const { - if (m_fileHistory) - return m_fileHistory->GetNoHistoryFiles(); - else - return 0; -} - -static char *FindExtension(char *path) -{ - static char ext[10]; - int len = strlen(path); - if (path) - { - int i = 0; - for (i = (len-1); i > 0; i --) - if (path[i] == '.') - break; - if (path[i] == '.') - { - int j; - for (j = i+1; j < len; j++) - ext[(int)(j-(i+1))] = (char)wxToLower(path[j]); // NOTE Should not use tolower under UNIX - ext[j-(i+1)] = 0; - return ext; - } + if (m_fileHistory) + return m_fileHistory->GetNoHistoryFiles(); else - return (char *) NULL; - } - else return (char *) NULL; + return 0; } -// Given a path, try to find a matching template. Won't -// always work, of course. +// Given a path, try to find a matching template. Won't always work, of +// course. wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path) { - char *theExt = FindExtension((char *)(const char *)path); - if (!theExt) - return (wxDocTemplate *) NULL; - wxDocTemplate *theTemplate = (wxDocTemplate *) NULL; + wxString theExt = FindExtension(path); + if (!theExt) + return (wxDocTemplate *) NULL; + wxDocTemplate *theTemplate = (wxDocTemplate *) NULL; - if (m_templates.Number() == 1) - return (wxDocTemplate *)m_templates.First()->Data(); + if (m_templates.Number() == 1) + return (wxDocTemplate *)m_templates.First()->Data(); - // Find the template which this extension corresponds to - int i; - for (i = 0; i < m_templates.Number(); i++) - { - wxDocTemplate *temp = (wxDocTemplate *)m_templates.Nth(i)->Data(); - if (strcmp(temp->GetDefaultExtension(), theExt) == 0) + // Find the template which this extension corresponds to + int i; + for (i = 0; i < m_templates.Number(); i++) { - theTemplate = temp; - break; + wxDocTemplate *temp = (wxDocTemplate *)m_templates.Nth(i)->Data(); + if (strcmp(temp->GetDefaultExtension(), theExt) == 0) + { + theTemplate = temp; + break; + } } - } - return theTemplate; + return theTemplate; } // Prompts user to open a file, using file specs in templates. @@ -1135,15 +1153,13 @@ wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path) // dialog or implement own; OR match the extension to the // template extension. -#ifdef __WXMSW__ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, - int noTemplates, wxString& path, long WXUNUSED(flags), bool WXUNUSED(save)) -#else -wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templates), - int WXUNUSED(noTemplates), wxString& path, long WXUNUSED(flags), bool WXUNUSED(save)) -#endif + int noTemplates, + wxString& path, + long WXUNUSED(flags), + bool WXUNUSED(save)) { - // We can only have multiple filters in Windows + // We can only have multiple filters in Windows #ifdef __WXMSW__ wxString descrBuf; @@ -1157,186 +1173,193 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templat descrBuf << '|'; descrBuf << templates[i]->GetDescription() - << " (" << templates[i]->GetFileFilter() << ") |" - << templates[i]->GetFileFilter(); + << " (" << templates[i]->GetFileFilter() << ") |" + << templates[i]->GetFileFilter(); } } #else - wxString descrBuf = "*.*"; + wxString descrBuf = "*.*"; #endif - wxString pathTmp = wxFileSelector(_("Select a file"), "", "", "", - descrBuf, 0, wxTheApp->GetTopWindow()); + wxString pathTmp = wxFileSelector(_("Select a file"), "", "", "", + descrBuf, 0, wxTheApp->GetTopWindow()); - if (!pathTmp.IsEmpty()) - { - path = pathTmp; - char *theExt = FindExtension((char *)(const char *)path); - if (!theExt) - return (wxDocTemplate *) NULL; - - // This is dodgy in that we're selecting the template on the - // basis of the file extension, which may not be a standard - // one. We really want to know exactly which template was - // chosen by using a more advanced file selector. - wxDocTemplate *theTemplate = FindTemplateForPath(path); - return theTemplate; - } - else - { - path = ""; - return (wxDocTemplate *) NULL; - } + if (!pathTmp.IsEmpty()) + { + path = pathTmp; + wxString theExt = FindExtension(path); + if (!theExt) + return (wxDocTemplate *) NULL; + + // This is dodgy in that we're selecting the template on the + // basis of the file extension, which may not be a standard + // one. We really want to know exactly which template was + // chosen by using a more advanced file selector. + wxDocTemplate *theTemplate = FindTemplateForPath(path); + return theTemplate; + } + else + { + path = ""; + return (wxDocTemplate *) NULL; + } #if 0 - // In all other windowing systems, until we have more advanced - // file selectors, we must select the document type (template) first, and - // _then_ pop up the file selector. - wxDocTemplate *temp = SelectDocumentType(templates, noTemplates); - if (!temp) - return (wxDocTemplate *) NULL; - - char *pathTmp = wxFileSelector(_("Select a file"), "", "", - temp->GetDefaultExtension(), - temp->GetFileFilter(), - 0, wxTheApp->GetTopWindow()); - - if (pathTmp) - { - path = pathTmp; - return temp; - } - else - return (wxDocTemplate *) NULL; -#endif + // In all other windowing systems, until we have more advanced + // file selectors, we must select the document type (template) first, and + // _then_ pop up the file selector. + wxDocTemplate *temp = SelectDocumentType(templates, noTemplates); + if (!temp) + return (wxDocTemplate *) NULL; + + char *pathTmp = wxFileSelector(_("Select a file"), "", "", + temp->GetDefaultExtension(), + temp->GetFileFilter(), + 0, wxTheApp->GetTopWindow()); + + if (pathTmp) + { + path = pathTmp; + return temp; + } + else + return (wxDocTemplate *) NULL; +#endif // 0 } wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates, - int noTemplates) -{ - char **strings = new char *[noTemplates]; - char **data = new char *[noTemplates]; - int i; - int n = 0; - for (i = 0; i < noTemplates; i++) - { - if (templates[i]->IsVisible()) - { - strings[n] = WXSTRINGCAST templates[i]->m_description; - data[n] = (char *)templates[i]; - n ++; - } - } - if (n == 0) - { - delete[] strings; - delete[] data; - return (wxDocTemplate *) NULL; - } - else if (n == 1) - { - wxDocTemplate *temp = (wxDocTemplate *)data[0]; + int noTemplates) +{ + char **strings = new char *[noTemplates]; + char **data = new char *[noTemplates]; + int i; + int n = 0; + for (i = 0; i < noTemplates; i++) + { + if (templates[i]->IsVisible()) + { + strings[n] = WXSTRINGCAST templates[i]->m_description; + data[n] = (char *)templates[i]; + n ++; + } + } + if (n == 0) + { + delete[] strings; + delete[] data; + return (wxDocTemplate *) NULL; + } + else if (n == 1) + { + wxDocTemplate *temp = (wxDocTemplate *)data[0]; + delete[] strings; + delete[] data; + return temp; + } + + wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n, + strings, data); delete[] strings; delete[] data; - return temp; - } - - wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n, - strings, data); - delete[] strings; - delete[] data; - return theTemplate; + return theTemplate; } wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates, - int noTemplates) + int noTemplates) { - char **strings = new char *[noTemplates]; - char **data = new char *[noTemplates]; - int i; - int n = 0; - for (i = 0; i < noTemplates; i++) - { - if (templates[i]->IsVisible() && (templates[i]->GetViewName() != "")) + char **strings = new char *[noTemplates]; + char **data = new char *[noTemplates]; + int i; + int n = 0; + for (i = 0; i < noTemplates; i++) { - strings[n] = WXSTRINGCAST templates[i]->m_viewTypeName; - data[n] = (char *)templates[i]; - n ++; + if (templates[i]->IsVisible() && (templates[i]->GetViewName() != "")) + { + strings[n] = WXSTRINGCAST templates[i]->m_viewTypeName; + data[n] = (char *)templates[i]; + n ++; + } } - } - wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n, - strings, data); - delete[] strings; - delete[] data; - return theTemplate; + wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n, + strings, data); + delete[] strings; + delete[] data; + return theTemplate; } void wxDocManager::AssociateTemplate(wxDocTemplate *temp) { - if (!m_templates.Member(temp)) - m_templates.Append(temp); + if (!m_templates.Member(temp)) + m_templates.Append(temp); } void wxDocManager::DisassociateTemplate(wxDocTemplate *temp) { - m_templates.DeleteObject(temp); + m_templates.DeleteObject(temp); } // Add and remove a document from the manager's list void wxDocManager::AddDocument(wxDocument *doc) { - if (!m_docs.Member(doc)) - m_docs.Append(doc); + if (!m_docs.Member(doc)) + m_docs.Append(doc); } void wxDocManager::RemoveDocument(wxDocument *doc) { - m_docs.DeleteObject(doc); + m_docs.DeleteObject(doc); } // Views or windows should inform the document manager // when a view is going in or out of focus void wxDocManager::ActivateView(wxView *view, bool activate, bool WXUNUSED(deleting)) { - // If we're deactiving, and if we're not actually deleting the view, then - // don't reset the current view because we may be going to - // a window without a view. - // WHAT DID I MEAN BY THAT EXACTLY? -/* - if (deleting) - { - if (m_currentView == view) - m_currentView = NULL; - } - else -*/ - { - if (activate) - m_currentView = view; - else - m_currentView = (wxView *) NULL; - } + // If we're deactiving, and if we're not actually deleting the view, then + // don't reset the current view because we may be going to + // a window without a view. + // WHAT DID I MEAN BY THAT EXACTLY? + /* + if (deleting) + { + if (m_currentView == view) + m_currentView = NULL; + } + else + */ + { + if (activate) + m_currentView = view; + else + m_currentView = (wxView *) NULL; + } } -/* - * Default document child frame - */ +// ---------------------------------------------------------------------------- +// Default document child frame +// ---------------------------------------------------------------------------- BEGIN_EVENT_TABLE(wxDocChildFrame, wxFrame) EVT_ACTIVATE(wxDocChildFrame::OnActivate) EVT_CLOSE(wxDocChildFrame::OnCloseWindow) END_EVENT_TABLE() -wxDocChildFrame::wxDocChildFrame(wxDocument *doc, wxView *view, wxFrame *frame, wxWindowID id, const wxString& title, - const wxPoint& pos, const wxSize& size, long style, const wxString& name): - wxFrame(frame, id, title, pos, size, style, name) -{ - m_childDocument = doc; - m_childView = view; - if (view) - view->SetFrame(this); +wxDocChildFrame::wxDocChildFrame(wxDocument *doc, + wxView *view, + wxFrame *frame, + wxWindowID id, + const wxString& title, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) + : wxFrame(frame, id, title, pos, size, style, name) +{ + m_childDocument = doc; + m_childView = view; + if (view) + view->SetFrame(this); } -wxDocChildFrame::~wxDocChildFrame(void) +wxDocChildFrame::~wxDocChildFrame() { } @@ -1346,55 +1369,55 @@ bool wxDocChildFrame::ProcessEvent(wxEvent& event) if (m_childView) m_childView->Activate(TRUE); - if ( !m_childView || ! m_childView->ProcessEvent(event) ) + if ( !m_childView || ! m_childView->ProcessEvent(event) ) { // Only hand up to the parent if it's a menu command if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event)) - return wxEvtHandler::ProcessEvent(event); + return wxEvtHandler::ProcessEvent(event); else return TRUE; } - else - return TRUE; + else + return TRUE; } void wxDocChildFrame::OnActivate(wxActivateEvent& event) { - wxFrame::OnActivate(event); + wxFrame::OnActivate(event); - if (m_childView) - m_childView->Activate(event.GetActive()); + if (m_childView) + m_childView->Activate(event.GetActive()); } void wxDocChildFrame::OnCloseWindow(wxCloseEvent& event) { - if (m_childView) - { - bool ans = FALSE; - if (!event.CanVeto()) - ans = TRUE; // Must delete. - else - ans = m_childView->Close(FALSE); // FALSE means don't delete associated window - - if (ans) + if (m_childView) { - m_childView->Activate(FALSE); - delete m_childView; - m_childView = (wxView *) NULL; - m_childDocument = (wxDocument *) NULL; + bool ans = FALSE; + if (!event.CanVeto()) + ans = TRUE; // Must delete. + else + ans = m_childView->Close(FALSE); // FALSE means don't delete associated window - this->Destroy(); + if (ans) + { + m_childView->Activate(FALSE); + delete m_childView; + m_childView = (wxView *) NULL; + m_childDocument = (wxDocument *) NULL; + + this->Destroy(); + } + else + event.Veto(); } else - event.Veto(); - } - else - event.Veto(); + event.Veto(); } -/* - * Default parent frame - */ +// ---------------------------------------------------------------------------- +// Default parent frame +// ---------------------------------------------------------------------------- BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame) EVT_MENU(wxID_EXIT, wxDocParentFrame::OnExit) @@ -1402,11 +1425,17 @@ BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame) EVT_CLOSE(wxDocParentFrame::OnCloseWindow) END_EVENT_TABLE() -wxDocParentFrame::wxDocParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, - const wxPoint& pos, const wxSize& size, long style, const wxString& name): - wxFrame(frame, id, title, pos, size, style, name) +wxDocParentFrame::wxDocParentFrame(wxDocManager *manager, + wxFrame *frame, + wxWindowID id, + const wxString& title, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) + : wxFrame(frame, id, title, pos, size, style, name) { - m_docManager = manager; + m_docManager = manager; } void wxDocParentFrame::OnExit(wxCommandEvent& WXUNUSED(event)) @@ -1416,8 +1445,8 @@ void wxDocParentFrame::OnExit(wxCommandEvent& WXUNUSED(event)) void wxDocParentFrame::OnMRUFile(wxCommandEvent& event) { - wxString f(m_docManager->GetHistoryFile(event.GetSelection() - wxID_FILE1)); - if (f != "") + wxString f(m_docManager->GetHistoryFile(event.GetSelection() - wxID_FILE1)); + if (f != "") (void)m_docManager->CreateDocument(f, wxDOC_SILENT); } @@ -1435,106 +1464,106 @@ bool wxDocParentFrame::ProcessEvent(wxEvent& event) // - must delete all frames except for the main one. void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event) { - if (m_docManager->Clear(!event.CanVeto())) - { - this->Destroy(); - } - else - event.Veto(); + if (m_docManager->Clear(!event.CanVeto())) + { + this->Destroy(); + } + else + event.Veto(); } #if wxUSE_PRINTING_ARCHITECTURE -wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title): - wxPrintout(WXSTRINGCAST title) +wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title) + : wxPrintout(WXSTRINGCAST title) { - m_printoutView = view; + m_printoutView = view; } bool wxDocPrintout::OnPrintPage(int WXUNUSED(page)) { - wxDC *dc = GetDC(); - - // Get the logical pixels per inch of screen and printer - int ppiScreenX, ppiScreenY; - GetPPIScreen(&ppiScreenX, &ppiScreenY); - int ppiPrinterX, ppiPrinterY; - GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); - - // This scales the DC so that the printout roughly represents the - // the screen scaling. The text point size _should_ be the right size - // but in fact is too small for some reason. This is a detail that will - // need to be addressed at some point but can be fudged for the - // moment. - float scale = (float)((float)ppiPrinterX/(float)ppiScreenX); - - // Now we have to check in case our real page size is reduced - // (e.g. because we're drawing to a print preview memory DC) - int pageWidth, pageHeight; - int w, h; - dc->GetSize(&w, &h); - GetPageSizePixels(&pageWidth, &pageHeight); - - // If printer pageWidth == current DC width, then this doesn't - // change. But w might be the preview bitmap width, so scale down. - float overallScale = scale * (float)(w/(float)pageWidth); - dc->SetUserScale(overallScale, overallScale); - - if (m_printoutView) - { - m_printoutView->OnDraw(dc); - } - return TRUE; + wxDC *dc = GetDC(); + + // Get the logical pixels per inch of screen and printer + int ppiScreenX, ppiScreenY; + GetPPIScreen(&ppiScreenX, &ppiScreenY); + int ppiPrinterX, ppiPrinterY; + GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); + + // This scales the DC so that the printout roughly represents the + // the screen scaling. The text point size _should_ be the right size + // but in fact is too small for some reason. This is a detail that will + // need to be addressed at some point but can be fudged for the + // moment. + float scale = (float)((float)ppiPrinterX/(float)ppiScreenX); + + // Now we have to check in case our real page size is reduced + // (e.g. because we're drawing to a print preview memory DC) + int pageWidth, pageHeight; + int w, h; + dc->GetSize(&w, &h); + GetPageSizePixels(&pageWidth, &pageHeight); + + // If printer pageWidth == current DC width, then this doesn't + // change. But w might be the preview bitmap width, so scale down. + float overallScale = scale * (float)(w/(float)pageWidth); + dc->SetUserScale(overallScale, overallScale); + + if (m_printoutView) + { + m_printoutView->OnDraw(dc); + } + return TRUE; } bool wxDocPrintout::HasPage(int pageNum) { - return (pageNum == 1); + return (pageNum == 1); } bool wxDocPrintout::OnBeginDocument(int startPage, int endPage) { - if (!wxPrintout::OnBeginDocument(startPage, endPage)) - return FALSE; + if (!wxPrintout::OnBeginDocument(startPage, endPage)) + return FALSE; - return TRUE; + return TRUE; } void wxDocPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) { - *minPage = 1; - *maxPage = 1; - *selPageFrom = 1; - *selPageTo = 1; + *minPage = 1; + *maxPage = 1; + *selPageFrom = 1; + *selPageTo = 1; } -#endif +#endif // wxUSE_PRINTING_ARCHITECTURE -/* - * Command processing framework - */ +// ---------------------------------------------------------------------------- +// Command processing framework +// ---------------------------------------------------------------------------- wxCommand::wxCommand(bool canUndoIt, const wxString& name) { - m_canUndo = canUndoIt; - m_commandName = name; + m_canUndo = canUndoIt; + m_commandName = name; } -wxCommand::~wxCommand(void) +wxCommand::~wxCommand() { } // Command processor wxCommandProcessor::wxCommandProcessor(int maxCommands) { - m_maxNoCommands = maxCommands; - m_currentCommand = (wxNode *) NULL; - m_commandEditMenu = (wxMenu *) NULL; + m_maxNoCommands = maxCommands; + m_currentCommand = (wxNode *) NULL; + m_commandEditMenu = (wxMenu *) NULL; } -wxCommandProcessor::~wxCommandProcessor(void) +wxCommandProcessor::~wxCommandProcessor() { - ClearCommands(); + ClearCommands(); } // Pass a command to the processor. The processor calls Do(); @@ -1542,95 +1571,95 @@ wxCommandProcessor::~wxCommandProcessor(void) // storeIt is FALSE. bool wxCommandProcessor::Submit(wxCommand *command, bool storeIt) { - bool success = command->Do(); - if (success && storeIt) - { - if (m_commands.Number() == m_maxNoCommands) + bool success = command->Do(); + if (success && storeIt) { - wxNode *firstNode = m_commands.First(); - wxCommand *firstCommand = (wxCommand *)firstNode->Data(); - delete firstCommand; - delete firstNode; - } + if (m_commands.Number() == m_maxNoCommands) + { + wxNode *firstNode = m_commands.First(); + wxCommand *firstCommand = (wxCommand *)firstNode->Data(); + delete firstCommand; + delete firstNode; + } - // Correct a bug: we must chop off the current 'branch' - // so that we're at the end of the command list. - if (!m_currentCommand) - ClearCommands(); - else - { - wxNode *node = m_currentCommand->Next(); - while (node) - { - wxNode *next = node->Next(); - delete (wxCommand *)node->Data(); - delete node; - node = next; - } + // Correct a bug: we must chop off the current 'branch' + // so that we're at the end of the command list. + if (!m_currentCommand) + ClearCommands(); + else + { + wxNode *node = m_currentCommand->Next(); + while (node) + { + wxNode *next = node->Next(); + delete (wxCommand *)node->Data(); + delete node; + node = next; + } + } + + m_commands.Append(command); + m_currentCommand = m_commands.Last(); + SetMenuStrings(); } - - m_commands.Append(command); - m_currentCommand = m_commands.Last(); - SetMenuStrings(); - } - return success; + return success; } -bool wxCommandProcessor::Undo(void) +bool wxCommandProcessor::Undo() { - if (m_currentCommand) - { - wxCommand *command = (wxCommand *)m_currentCommand->Data(); - if (command->CanUndo()) + if (m_currentCommand) { - bool success = command->Undo(); - if (success) - { - m_currentCommand = m_currentCommand->Previous(); - SetMenuStrings(); - return TRUE; - } + wxCommand *command = (wxCommand *)m_currentCommand->Data(); + if (command->CanUndo()) + { + bool success = command->Undo(); + if (success) + { + m_currentCommand = m_currentCommand->Previous(); + SetMenuStrings(); + return TRUE; + } + } } - } - return FALSE; + return FALSE; } -bool wxCommandProcessor::Redo(void) +bool wxCommandProcessor::Redo() { - wxCommand *redoCommand = (wxCommand *) NULL; - wxNode *redoNode = (wxNode *) NULL; - if (m_currentCommand && m_currentCommand->Next()) - { - redoCommand = (wxCommand *)m_currentCommand->Next()->Data(); - redoNode = m_currentCommand->Next(); - } - else - { - if (m_commands.Number() > 0) + wxCommand *redoCommand = (wxCommand *) NULL; + wxNode *redoNode = (wxNode *) NULL; + if (m_currentCommand && m_currentCommand->Next()) + { + redoCommand = (wxCommand *)m_currentCommand->Next()->Data(); + redoNode = m_currentCommand->Next(); + } + else { - redoCommand = (wxCommand *)m_commands.First()->Data(); - redoNode = m_commands.First(); + if (m_commands.Number() > 0) + { + redoCommand = (wxCommand *)m_commands.First()->Data(); + redoNode = m_commands.First(); + } } - } - if (redoCommand) - { - bool success = redoCommand->Do(); - if (success) + if (redoCommand) { - m_currentCommand = redoNode; - SetMenuStrings(); - return TRUE; + bool success = redoCommand->Do(); + if (success) + { + m_currentCommand = redoNode; + SetMenuStrings(); + return TRUE; + } } - } - return FALSE; + return FALSE; } bool wxCommandProcessor::CanUndo(void) const { - if (m_currentCommand) - return ((wxCommand *)m_currentCommand->Data())->CanUndo(); - return FALSE; + if (m_currentCommand) + return ((wxCommand *)m_currentCommand->Data())->CanUndo(); + return FALSE; } bool wxCommandProcessor::CanRedo(void) const @@ -1647,207 +1676,206 @@ bool wxCommandProcessor::CanRedo(void) const return FALSE; } -void wxCommandProcessor::Initialize(void) +void wxCommandProcessor::Initialize() { - m_currentCommand = m_commands.Last(); - SetMenuStrings(); + m_currentCommand = m_commands.Last(); + SetMenuStrings(); } -void wxCommandProcessor::SetMenuStrings(void) +void wxCommandProcessor::SetMenuStrings() { - if (m_commandEditMenu) - { - wxString buf; - if (m_currentCommand) - { - wxCommand *command = (wxCommand *)m_currentCommand->Data(); - wxString commandName(command->GetName()); - if (commandName == "") commandName = _("Unnamed command"); - bool canUndo = command->CanUndo(); - if (canUndo) - buf = wxString(_("&Undo ")) + commandName; - else - buf = wxString(_("Can't &Undo ")) + commandName; - - m_commandEditMenu->SetLabel(wxID_UNDO, buf); - m_commandEditMenu->Enable(wxID_UNDO, canUndo); - - // We can redo, if we're not at the end of the history. - if (m_currentCommand->Next()) - { - wxCommand *redoCommand = (wxCommand *)m_currentCommand->Next()->Data(); - wxString redoCommandName(redoCommand->GetName()); - if (redoCommandName == "") redoCommandName = _("Unnamed command"); - buf = wxString(_("&Redo ")) + redoCommandName; - m_commandEditMenu->SetLabel(wxID_REDO, buf); - m_commandEditMenu->Enable(wxID_REDO, TRUE); - } - else - { - m_commandEditMenu->SetLabel(wxID_REDO, _("&Redo")); - m_commandEditMenu->Enable(wxID_REDO, FALSE); - } - } - else + if (m_commandEditMenu) { - m_commandEditMenu->SetLabel(wxID_UNDO, _("&Undo")); - m_commandEditMenu->Enable(wxID_UNDO, FALSE); + wxString buf; + if (m_currentCommand) + { + wxCommand *command = (wxCommand *)m_currentCommand->Data(); + wxString commandName(command->GetName()); + if (commandName == "") commandName = _("Unnamed command"); + bool canUndo = command->CanUndo(); + if (canUndo) + buf = wxString(_("&Undo ")) + commandName; + else + buf = wxString(_("Can't &Undo ")) + commandName; + + m_commandEditMenu->SetLabel(wxID_UNDO, buf); + m_commandEditMenu->Enable(wxID_UNDO, canUndo); + + // We can redo, if we're not at the end of the history. + if (m_currentCommand->Next()) + { + wxCommand *redoCommand = (wxCommand *)m_currentCommand->Next()->Data(); + wxString redoCommandName(redoCommand->GetName()); + if (redoCommandName == "") redoCommandName = _("Unnamed command"); + buf = wxString(_("&Redo ")) + redoCommandName; + m_commandEditMenu->SetLabel(wxID_REDO, buf); + m_commandEditMenu->Enable(wxID_REDO, TRUE); + } + else + { + m_commandEditMenu->SetLabel(wxID_REDO, _("&Redo")); + m_commandEditMenu->Enable(wxID_REDO, FALSE); + } + } + else + { + m_commandEditMenu->SetLabel(wxID_UNDO, _("&Undo")); + m_commandEditMenu->Enable(wxID_UNDO, FALSE); - if (m_commands.Number() == 0) - { - m_commandEditMenu->SetLabel(wxID_REDO, _("&Redo")); - m_commandEditMenu->Enable(wxID_REDO, FALSE); - } - else - { - // currentCommand is NULL but there are commands: this means that - // we've undone to the start of the list, but can redo the first. - wxCommand *redoCommand = (wxCommand *)m_commands.First()->Data(); - wxString redoCommandName(redoCommand->GetName()); - if (redoCommandName == "") redoCommandName = _("Unnamed command"); - buf = wxString(_("&Redo ")) + redoCommandName; - m_commandEditMenu->SetLabel(wxID_REDO, buf); - m_commandEditMenu->Enable(wxID_REDO, TRUE); - } + if (m_commands.Number() == 0) + { + m_commandEditMenu->SetLabel(wxID_REDO, _("&Redo")); + m_commandEditMenu->Enable(wxID_REDO, FALSE); + } + else + { + // currentCommand is NULL but there are commands: this means that + // we've undone to the start of the list, but can redo the first. + wxCommand *redoCommand = (wxCommand *)m_commands.First()->Data(); + wxString redoCommandName(redoCommand->GetName()); + if (redoCommandName == "") redoCommandName = _("Unnamed command"); + buf = wxString(_("&Redo ")) + redoCommandName; + m_commandEditMenu->SetLabel(wxID_REDO, buf); + m_commandEditMenu->Enable(wxID_REDO, TRUE); + } + } } - } } -void wxCommandProcessor::ClearCommands(void) +void wxCommandProcessor::ClearCommands() { - wxNode *node = m_commands.First(); - while (node) - { - wxCommand *command = (wxCommand *)node->Data(); - delete command; - delete node; - node = m_commands.First(); - } - m_currentCommand = (wxNode *) NULL; + wxNode *node = m_commands.First(); + while (node) + { + wxCommand *command = (wxCommand *)node->Data(); + delete command; + delete node; + node = m_commands.First(); + } + m_currentCommand = (wxNode *) NULL; } - -/* - * File history processor - */ +// ---------------------------------------------------------------------------- +// File history processor +// ---------------------------------------------------------------------------- wxFileHistory::wxFileHistory(int maxFiles) { - m_fileMaxFiles = maxFiles; - m_fileHistoryN = 0; - m_fileHistory = new char *[m_fileMaxFiles]; + m_fileMaxFiles = maxFiles; + m_fileHistoryN = 0; + m_fileHistory = new char *[m_fileMaxFiles]; } -wxFileHistory::~wxFileHistory(void) +wxFileHistory::~wxFileHistory() { - int i; - for (i = 0; i < m_fileHistoryN; i++) - delete[] m_fileHistory[i]; - delete[] m_fileHistory; + int i; + for (i = 0; i < m_fileHistoryN; i++) + delete[] m_fileHistory[i]; + delete[] m_fileHistory; } // File history management void wxFileHistory::AddFileToHistory(const wxString& file) { - int i; - // Check we don't already have this file - for (i = 0; i < m_fileHistoryN; i++) - { - if (m_fileHistory[i] && wxString(m_fileHistory[i]) == file) - return; - } - - // Add to the project file history: - // Move existing files (if any) down so we can insert file at beginning. - - // First delete filename that has popped off the end of the array (if any) - if (m_fileHistoryN == m_fileMaxFiles) - { - delete[] m_fileHistory[m_fileMaxFiles-1]; - m_fileHistory[m_fileMaxFiles-1] = (char *) NULL; - } - if (m_fileHistoryN < m_fileMaxFiles) - { - wxNode* node = m_fileMenus.First(); - while (node) + int i; + // Check we don't already have this file + for (i = 0; i < m_fileHistoryN; i++) { - wxMenu* menu = (wxMenu*) node->Data(); - if (m_fileHistoryN == 0) - menu->AppendSeparator(); - menu->Append(wxID_FILE1+m_fileHistoryN, _("[EMPTY]")); - node = node->Next(); + if (m_fileHistory[i] && wxString(m_fileHistory[i]) == file) + return; } - m_fileHistoryN ++; - } - // Shuffle filenames down - for (i = (m_fileHistoryN-1); i > 0; i--) - { - m_fileHistory[i] = m_fileHistory[i-1]; - } - m_fileHistory[0] = copystring(file); - - for (i = 0; i < m_fileHistoryN; i++) - if (m_fileHistory[i]) - { - wxString buf; - buf.Printf("&%d %s", i+1, m_fileHistory[i]); - wxNode* node = m_fileMenus.First(); - while (node) - { - wxMenu* menu = (wxMenu*) node->Data(); - menu->SetLabel(wxID_FILE1+i, buf); - node = node->Next(); - } + + // Add to the project file history: + // Move existing files (if any) down so we can insert file at beginning. + + // First delete filename that has popped off the end of the array (if any) + if (m_fileHistoryN == m_fileMaxFiles) + { + delete[] m_fileHistory[m_fileMaxFiles-1]; + m_fileHistory[m_fileMaxFiles-1] = (char *) NULL; } + if (m_fileHistoryN < m_fileMaxFiles) + { + wxNode* node = m_fileMenus.First(); + while (node) + { + wxMenu* menu = (wxMenu*) node->Data(); + if (m_fileHistoryN == 0) + menu->AppendSeparator(); + menu->Append(wxID_FILE1+m_fileHistoryN, _("[EMPTY]")); + node = node->Next(); + } + m_fileHistoryN ++; + } + // Shuffle filenames down + for (i = (m_fileHistoryN-1); i > 0; i--) + { + m_fileHistory[i] = m_fileHistory[i-1]; + } + m_fileHistory[0] = copystring(file); + + for (i = 0; i < m_fileHistoryN; i++) + if (m_fileHistory[i]) + { + wxString buf; + buf.Printf("&%d %s", i+1, m_fileHistory[i]); + wxNode* node = m_fileMenus.First(); + while (node) + { + wxMenu* menu = (wxMenu*) node->Data(); + menu->SetLabel(wxID_FILE1+i, buf); + node = node->Next(); + } + } } wxString wxFileHistory::GetHistoryFile(int i) const { - if (i < m_fileHistoryN) - return wxString(m_fileHistory[i]); - else - return wxString(""); + if (i < m_fileHistoryN) + return wxString(m_fileHistory[i]); + else + return wxString(""); } void wxFileHistory::UseMenu(wxMenu *menu) { - if (!m_fileMenus.Member(menu)) - m_fileMenus.Append(menu); + if (!m_fileMenus.Member(menu)) + m_fileMenus.Append(menu); } void wxFileHistory::RemoveMenu(wxMenu *menu) { - m_fileMenus.DeleteObject(menu); + m_fileMenus.DeleteObject(menu); } #if wxUSE_CONFIG void wxFileHistory::Load(wxConfigBase& config) { - m_fileHistoryN = 0; - wxString buf; - buf.Printf("file%d", m_fileHistoryN+1); - wxString historyFile; - while ((m_fileHistoryN <= m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != "")) - { - m_fileHistory[m_fileHistoryN] = copystring((const char*) historyFile); - m_fileHistoryN ++; + m_fileHistoryN = 0; + wxString buf; buf.Printf("file%d", m_fileHistoryN+1); - historyFile = ""; - } - AddFilesToMenu(); + wxString historyFile; + while ((m_fileHistoryN <= m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != "")) + { + m_fileHistory[m_fileHistoryN] = copystring((const char*) historyFile); + m_fileHistoryN ++; + buf.Printf("file%d", m_fileHistoryN+1); + historyFile = ""; + } + AddFilesToMenu(); } void wxFileHistory::Save(wxConfigBase& config) { - int i; - for (i = 0; i < m_fileHistoryN; i++) - { - wxString buf; - buf.Printf("file%d", i+1); - config.Write(buf, wxString(m_fileHistory[i])); - } + int i; + for (i = 0; i < m_fileHistoryN; i++) + { + wxString buf; + buf.Printf("file%d", i+1); + config.Write(buf, wxString(m_fileHistory[i])); + } } -#endif +#endif // wxUSE_CONFIG void wxFileHistory::AddFilesToMenu() { @@ -1891,60 +1919,45 @@ void wxFileHistory::AddFilesToMenu(wxMenu* menu) } } -#if 0 -/* - * wxPrintInfo - */ - -wxPrintInfo::wxPrintInfo(void) -{ - pageNumber = 1; -} +// ---------------------------------------------------------------------------- +// Permits compatibility with existing file formats and functions that +// manipulate files directly +// ---------------------------------------------------------------------------- -wxPrintInfo::~wxPrintInfo(void) -{ -} -#endif - -/* - * Permits compatibility with existing file formats and functions - * that manipulate files directly - */ - bool wxTransferFileToStream(const wxString& filename, ostream& stream) { - FILE *fd1; - int ch; + FILE *fd1; + int ch; - if ((fd1 = fopen (WXSTRINGCAST filename, "rb")) == NULL) - return FALSE; + if ((fd1 = fopen (WXSTRINGCAST filename, "rb")) == NULL) + return FALSE; - while ((ch = getc (fd1)) != EOF) - stream << (unsigned char)ch; + while ((ch = getc (fd1)) != EOF) + stream << (unsigned char)ch; - fclose (fd1); - return TRUE; + fclose (fd1); + return TRUE; } bool wxTransferStreamToFile(istream& stream, const wxString& filename) { - FILE *fd1; - int ch; + FILE *fd1; + int ch; - if ((fd1 = fopen (WXSTRINGCAST filename, "wb")) == NULL) + if ((fd1 = fopen (WXSTRINGCAST filename, "wb")) == NULL) { - return FALSE; + return FALSE; } - while (!stream.eof()) - { - ch = stream.get(); - if (!stream.eof()) - putc (ch, fd1); - } - fclose (fd1); - return TRUE; + while (!stream.eof()) + { + ch = stream.get(); + if (!stream.eof()) + putc (ch, fd1); + } + fclose (fd1); + return TRUE; } -#endif - // End wxUSE_DOC_VIEW_ARCHITECTURE +#endif // wxUSE_DOC_VIEW_ARCHITECTURE + diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 2d6085250c..e772d04493 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -274,6 +274,12 @@ bool wxFileExists(const char *pszFileName) } */ +bool wxDirExists( const wxString& dir ) +{ + struct stat st; + return ((stat(dir, &st) != -1) && S_ISDIR(st.st_mode) ? TRUE : FALSE); +} + bool wxIsAbsolutePath (const wxString& filename) { @@ -785,7 +791,7 @@ wxMac2UnixFilename (char *s) if (*s == ':') *s = '/'; else - *s = wxToLower (*s); // Case INDEPENDENT + *s = tolower(*s); // Case INDEPENDENT s++; } } @@ -830,7 +836,7 @@ wxDos2UnixFilename (char *s) *s = '/'; #ifdef __WXMSW__ else - *s = wxToLower (*s); // Case INDEPENDENT + *s = tolower(*s); // Case INDEPENDENT #endif s++; } diff --git a/src/common/intl.cpp b/src/common/intl.cpp index aee8a90b39..8954ce3384 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -30,6 +30,7 @@ // standard headers #include +#include // wxWindows #include "wx/defs.h" @@ -435,7 +436,7 @@ bool wxLocale::Init(const char *szName, if ( m_strShort.IsEmpty() ) { // FIXME I don't know how these 2 letter abbreviations are formed, // this wild guess is surely wrong - m_strShort = wxToLower(szLocale[0]) + wxToLower(szLocale[1]); + m_strShort = tolower(szLocale[0]) + tolower(szLocale[1]); } // save the old locale to be able to restore it later diff --git a/src/common/log.cpp b/src/common/log.cpp index 686cd75754..050ee0c3d3 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -75,7 +75,7 @@ // we use a global variable to store the frame pointer for wxLogStatus - bad, // but it's he easiest way -static wxFrame *gs_pFrame; +static wxFrame *gs_pFrame; // FIXME MT-unsafe // ============================================================================ // implementation @@ -92,7 +92,7 @@ static wxFrame *gs_pFrame; // work!), so we use a static buffer for all log messages #define LOG_BUFFER_SIZE (4096) -// static buffer for error messages (@@@ MT-unsafe) +// static buffer for error messages (FIXME MT-unsafe) static char s_szBuf[LOG_BUFFER_SIZE]; // generic log function @@ -104,7 +104,7 @@ void wxLogGeneric(wxLogLevel level, const char *szFormat, ...) vsprintf(s_szBuf, szFormat, argptr); va_end(argptr); - wxLog::OnLog(level, s_szBuf); + wxLog::OnLog(level, s_szBuf, time(NULL)); } } @@ -117,7 +117,7 @@ void wxLogGeneric(wxLogLevel level, const char *szFormat, ...) vsprintf(s_szBuf, szFormat, argptr); \ va_end(argptr); \ \ - wxLog::OnLog(wxLOG_##level, s_szBuf); \ + wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \ } \ } @@ -141,7 +141,7 @@ void wxLogStatus(wxFrame *pFrame, const char *szFormat, ...) wxASSERT( gs_pFrame == NULL ); // should be reset! gs_pFrame = pFrame; - wxLog::OnLog(wxLOG_Status, s_szBuf); + wxLog::OnLog(wxLOG_Status, s_szBuf, time(NULL)); gs_pFrame = (wxFrame *) NULL; } } @@ -156,7 +156,7 @@ void wxLogVerbose(const char *szFormat, ...) vsprintf(s_szBuf, szFormat, argptr); va_end(argptr); - wxLog::OnLog(wxLOG_Info, s_szBuf); + wxLog::OnLog(wxLOG_Info, s_szBuf, time(NULL)); } } @@ -171,10 +171,24 @@ void wxLogVerbose(const char *szFormat, ...) vsprintf(s_szBuf, szFormat, argptr); \ va_end(argptr); \ \ - wxLog::OnLog(wxLOG_##level, s_szBuf); \ + wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \ } \ } + void wxLogTrace(const char *mask, const char *szFormat, ...) + { + wxLog *pLog = wxLog::GetActiveTarget(); + + if ( pLog != NULL && wxLog::IsAllowedTraceMask(mask) ) { + va_list argptr; + va_start(argptr, szFormat); + vsprintf(s_szBuf, szFormat, argptr); + va_end(argptr); + + wxLog::OnLog(wxLOG_Trace, s_szBuf, time(NULL)); + } + } + void wxLogTrace(wxTraceMask mask, const char *szFormat, ...) { wxLog *pLog = wxLog::GetActiveTarget(); @@ -188,7 +202,7 @@ void wxLogVerbose(const char *szFormat, ...) vsprintf(s_szBuf, szFormat, argptr); va_end(argptr); - wxLog::OnLog(wxLOG_Trace, s_szBuf); + wxLog::OnLog(wxLOG_Trace, s_szBuf, time(NULL)); } } @@ -205,31 +219,31 @@ IMPLEMENT_LOG_DEBUG_FUNCTION(Trace) // common part of both wxLogSysError void wxLogSysErrorHelper(long lErrCode) { - char szErrMsg[LOG_BUFFER_SIZE / 2]; - sprintf(szErrMsg, _(" (error %ld: %s)"), lErrCode, wxSysErrorMsg(lErrCode)); - strncat(s_szBuf, szErrMsg, WXSIZEOF(s_szBuf) - strlen(s_szBuf)); + char szErrMsg[LOG_BUFFER_SIZE / 2]; + sprintf(szErrMsg, _(" (error %ld: %s)"), lErrCode, wxSysErrorMsg(lErrCode)); + strncat(s_szBuf, szErrMsg, WXSIZEOF(s_szBuf) - strlen(s_szBuf)); - wxLog::OnLog(wxLOG_Error, s_szBuf); + wxLog::OnLog(wxLOG_Error, s_szBuf, time(NULL)); } void WXDLLEXPORT wxLogSysError(const char *szFormat, ...) { - va_list argptr; - va_start(argptr, szFormat); - vsprintf(s_szBuf, szFormat, argptr); - va_end(argptr); + va_list argptr; + va_start(argptr, szFormat); + vsprintf(s_szBuf, szFormat, argptr); + va_end(argptr); - wxLogSysErrorHelper(wxSysErrorCode()); + wxLogSysErrorHelper(wxSysErrorCode()); } void WXDLLEXPORT wxLogSysError(long lErrCode, const char *szFormat, ...) { - va_list argptr; - va_start(argptr, szFormat); - vsprintf(s_szBuf, szFormat, argptr); - va_end(argptr); + va_list argptr; + va_start(argptr, szFormat); + vsprintf(s_szBuf, szFormat, argptr); + va_end(argptr); - wxLogSysErrorHelper(lErrCode); + wxLogSysErrorHelper(lErrCode); } // ---------------------------------------------------------------------------- @@ -238,139 +252,116 @@ void WXDLLEXPORT wxLogSysError(long lErrCode, const char *szFormat, ...) wxLog::wxLog() { - m_bHasMessages = FALSE; + m_bHasMessages = FALSE; - // enable verbose messages by default in the debug builds + // enable verbose messages by default in the debug builds #ifdef __WXDEBUG__ - m_bVerbose = TRUE; + m_bVerbose = TRUE; #else // release - m_bVerbose = FALSE; + m_bVerbose = FALSE; #endif // debug/release - - m_szTimeFormat = "[%d/%b/%y %H:%M:%S] "; } wxLog *wxLog::GetActiveTarget() { - if ( ms_bAutoCreate && ms_pLogger == NULL ) { - // prevent infinite recursion if someone calls wxLogXXX() from - // wxApp::CreateLogTarget() - static bool s_bInGetActiveTarget = FALSE; - if ( !s_bInGetActiveTarget ) { - s_bInGetActiveTarget = TRUE; - - #ifdef wxUSE_NOGUI - ms_pLogger = new wxLogStderr; - #else - // ask the application to create a log target for us - if ( wxTheApp != NULL ) - ms_pLogger = wxTheApp->CreateLogTarget(); - else - ms_pLogger = new wxLogStderr; - #endif - - s_bInGetActiveTarget = FALSE; - - // do nothing if it fails - what can we do? + if ( ms_bAutoCreate && ms_pLogger == NULL ) { + // prevent infinite recursion if someone calls wxLogXXX() from + // wxApp::CreateLogTarget() + static bool s_bInGetActiveTarget = FALSE; + if ( !s_bInGetActiveTarget ) { + s_bInGetActiveTarget = TRUE; + +#ifdef wxUSE_NOGUI + ms_pLogger = new wxLogStderr; +#else + // ask the application to create a log target for us + if ( wxTheApp != NULL ) + ms_pLogger = wxTheApp->CreateLogTarget(); + else + ms_pLogger = new wxLogStderr; +#endif + + s_bInGetActiveTarget = FALSE; + + // do nothing if it fails - what can we do? + } } - } - return ms_pLogger; + return ms_pLogger; } wxLog *wxLog::SetActiveTarget(wxLog *pLogger) { - if ( ms_pLogger != NULL ) { - // flush the old messages before changing because otherwise they might - // get lost later if this target is not restored - ms_pLogger->Flush(); - } + if ( ms_pLogger != NULL ) { + // flush the old messages before changing because otherwise they might + // get lost later if this target is not restored + ms_pLogger->Flush(); + } - wxLog *pOldLogger = ms_pLogger; - ms_pLogger = pLogger; + wxLog *pOldLogger = ms_pLogger; + ms_pLogger = pLogger; - return pOldLogger; + return pOldLogger; } -wxString wxLog::TimeStamp() const +void wxLog::RemoveTraceMask(const wxString& str) { - wxString str; - -/* Let's disable TimeStamp and see if anyone complains. - * If not, we'll remove it, since it's probably unlikely - * to ever be used. -- JACS 22/11/98 - if ( !IsEmpty(m_szTimeFormat) ) { - char szBuf[128]; - time_t timeNow; - struct tm *ptmNow; + int index = ms_aTraceMasks.Index(str); + if ( index != wxNOT_FOUND ) + ms_aTraceMasks.Remove((size_t)index); +} - time(&timeNow); - ptmNow = localtime(&timeNow); +void wxLog::DoLog(wxLogLevel level, const char *szString, time_t t) +{ + wxString str; - strftime(szBuf, WXSIZEOF(szBuf), m_szTimeFormat, ptmNow); - str = szBuf; - } -*/ + switch ( level ) { + case wxLOG_FatalError: + DoLogString(str << _("Fatal error: ") << szString, t); + DoLogString(_("Program aborted."), t); + Flush(); + abort(); + break; + + case wxLOG_Error: + DoLogString(str << _("Error: ") << szString, t); + break; + + case wxLOG_Warning: + DoLogString(str << _("Warning: ") << szString, t); + break; + + case wxLOG_Info: + case wxLOG_Message: + if ( GetVerbose() ) + DoLogString(str + szString, t); + // fall through + + case wxLOG_Status: + // nothing to do + break; + + case wxLOG_Trace: + case wxLOG_Debug: +#ifdef __WXDEBUG__ + DoLogString(szString, t); +#endif - return str; -} + break; -void wxLog::DoLog(wxLogLevel level, const char *szString) -{ - // prepend a timestamp if not disabled - wxString str = TimeStamp(); - - switch ( level ) { - case wxLOG_FatalError: - DoLogString(str << _("Fatal error: ") << szString); - DoLogString(_("Program aborted.")); - Flush(); - abort(); - break; - - case wxLOG_Error: - DoLogString(str << _("Error: ") << szString); - break; - - case wxLOG_Warning: - DoLogString(str << _("Warning: ") << szString); - break; - - case wxLOG_Info: - case wxLOG_Message: - if ( GetVerbose() ) - DoLogString(str + szString); - // fall through - - case wxLOG_Status: - // nothing to do - break; - - case wxLOG_Trace: - case wxLOG_Debug: - #ifdef __WXDEBUG__ - // DoLogString(str << (level == wxLOG_Trace ? _("Trace") : _("Debug")) - // << ": " << szString); - // JACS: we don't really want to prefix with 'Debug'. It's just extra - // verbiage. - DoLogString(szString); - #endif - - break; - - default: - wxFAIL_MSG(_("unknown log level in wxLog::DoLog")); - } + default: + wxFAIL_MSG(_("unknown log level in wxLog::DoLog")); + } } -void wxLog::DoLogString(const char *WXUNUSED(szString)) +void wxLog::DoLogString(const char *WXUNUSED(szString), time_t t) { - wxFAIL_MSG("DoLogString must be overriden if it's called."); + wxFAIL_MSG("DoLogString must be overriden if it's called."); } void wxLog::Flush() { - // do nothing + // do nothing } // ---------------------------------------------------------------------------- @@ -379,22 +370,22 @@ void wxLog::Flush() wxLogStderr::wxLogStderr(FILE *fp) { - if ( fp == NULL ) - m_fp = stderr; - else - m_fp = fp; + if ( fp == NULL ) + m_fp = stderr; + else + m_fp = fp; } -void wxLogStderr::DoLogString(const char *szString) +void wxLogStderr::DoLogString(const char *szString, time_t t) { - wxString str(szString); - str << '\n'; + wxString str(szString); + str << '\n'; - fputs(str, m_fp); - fflush(m_fp); + fputs(str, m_fp); + fflush(m_fp); - // under Windows, programs usually don't have stderr at all, so make show the - // messages also under debugger + // under Windows, programs usually don't have stderr at all, so make show the + // messages also under debugger #ifdef __WXMSW__ OutputDebugString(str + '\r'); #endif // MSW @@ -407,19 +398,19 @@ void wxLogStderr::DoLogString(const char *szString) #if wxUSE_STD_IOSTREAM wxLogStream::wxLogStream(ostream *ostr) { - if ( ostr == NULL ) - m_ostr = &cerr; - else - m_ostr = ostr; + if ( ostr == NULL ) + m_ostr = &cerr; + else + m_ostr = ostr; } -void wxLogStream::DoLogString(const char *szString) +void wxLogStream::DoLogString(const char *szString, time_t t) { - (*m_ostr) << szString << endl << flush; + (*m_ostr) << szString << endl << flush; } -#endif +#endif // wxUSE_STD_IOSTREAM -#ifndef wxUSE_NOGUI +#ifndef wxUSE_NOGUI // ---------------------------------------------------------------------------- // wxLogTextCtrl implementation @@ -427,141 +418,162 @@ void wxLogStream::DoLogString(const char *szString) #if wxUSE_STD_IOSTREAM wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl) -// DLL mode in wxMSW, can't use it. -#if defined(NO_TEXT_WINDOW_STREAM) -#else - : wxLogStream(new ostream(pTextCtrl)) +#if !defined(NO_TEXT_WINDOW_STREAM) +: wxLogStream(new ostream(pTextCtrl)) #endif { } wxLogTextCtrl::~wxLogTextCtrl() { - delete m_ostr; + delete m_ostr; } -#endif +#endif // wxUSE_STD_IOSTREAM // ---------------------------------------------------------------------------- -// wxLogGui implementation +// wxLogGui implementation (FIXME MT-unsafe) // ---------------------------------------------------------------------------- wxLogGui::wxLogGui() { - m_bErrors = FALSE; + Clear(); +} + +void wxLogGui::Clear() +{ + m_bErrors = m_bWarnings = FALSE; + m_aMessages.Empty(); + m_aTimes.Empty(); } void wxLogGui::Flush() { - if ( !m_bHasMessages ) - return; + if ( !m_bHasMessages ) + return; - // do it right now to block any new calls to Flush() while we're here - m_bHasMessages = FALSE; + // do it right now to block any new calls to Flush() while we're here + m_bHasMessages = FALSE; - // @@@ ugly... + // concatenate all strings (but not too many to not overfill the msg box) + wxString str; + size_t nLines = 0, + nMsgCount = m_aMessages.Count(); - // concatenate all strings (but not too many to not overfill the msg box) - wxString str; - size_t nLines = 0, - nMsgCount = m_aMessages.Count(); + // start from the most recent message + for ( size_t n = nMsgCount; n > 0; n-- ) { + // for Windows strings longer than this value are wrapped (NT 4.0) + const size_t nMsgLineWidth = 156; - // start from the most recent message - for ( size_t n = nMsgCount; n > 0; n-- ) { - // for Windows strings longer than this value are wrapped (NT 4.0) - const size_t nMsgLineWidth = 156; + nLines += (m_aMessages[n - 1].Len() + nMsgLineWidth - 1) / nMsgLineWidth; - nLines += (m_aMessages[n - 1].Len() + nMsgLineWidth - 1) / nMsgLineWidth; + if ( nLines > 25 ) // don't put too many lines in message box + break; - if ( nLines > 25 ) // don't put too many lines in message box - break; + str << m_aMessages[n - 1] << "\n"; + } - str << m_aMessages[n - 1] << "\n"; - } + const char *title; + long style; - if ( m_bErrors ) { - wxMessageBox(str, _("Error"), wxOK | wxICON_EXCLAMATION); - } - else { - wxMessageBox(str, _("Information"), wxOK | wxICON_INFORMATION); - } + if ( m_bErrors ) { + title = _("Error"); + style = wxICON_STOP; + } + else if ( m_bWarnings ) { + title = _("Warning"); + style = wxICON_EXCLAMATION; + } + else { + title = _("Information"); + style = wxICON_INFORMATION; + } - // no undisplayed messages whatsoever - m_bErrors = FALSE; - m_aMessages.Empty(); + wxMessageBox(str, title, wxOK | style); + + // no undisplayed messages whatsoever + Clear(); } // the default behaviour is to discard all informational messages if there // are any errors/warnings. -void wxLogGui::DoLog(wxLogLevel level, const char *szString) +void wxLogGui::DoLog(wxLogLevel level, const char *szString, time_t t) { - switch ( level ) { - case wxLOG_Info: - if ( GetVerbose() ) - case wxLOG_Message: - if ( !m_bErrors ) { - m_aMessages.Add(szString); - m_bHasMessages = TRUE; - } - break; - - case wxLOG_Status: - { - // find the top window and set it's status text if it has any - wxFrame *pFrame = gs_pFrame; - if ( pFrame == NULL ) { - wxWindow *pWin = wxTheApp->GetTopWindow(); - if ( pWin != NULL && pWin->IsKindOf(CLASSINFO(wxFrame)) ) { - pFrame = (wxFrame *)pWin; - } - } - - if ( pFrame != NULL ) - pFrame->SetStatusText(szString); - } - break; - - case wxLOG_Trace: - case wxLOG_Debug: - #ifdef __WXDEBUG__ - { - wxString strTime = TimeStamp(); - - #ifdef __WXMSW__ - // don't prepend debug/trace here: it goes to the debug window - // anyhow, but do put a timestamp - OutputDebugString(strTime + szString + "\n\r"); - #else - // send them to stderr - fprintf(stderr, "%s %s: %s\n", - strTime.c_str(), - level == wxLOG_Trace ? "Trace" : "Debug", - szString); - fflush(stderr); - #endif - } - #endif // __WXDEBUG__ - break; - - case wxLOG_FatalError: - // show this one immediately - wxMessageBox(szString, _("Fatal error"), wxICON_HAND); - break; - - case wxLOG_Error: - case wxLOG_Warning: - // discard earlier informational messages if this is the 1st error - if ( !m_bErrors ) { - m_aMessages.Empty(); - m_bHasMessages = TRUE; - m_bErrors = TRUE; - } - - m_aMessages.Add(szString); - break; - - default: - wxFAIL_MSG(_("unknown log level in wxLogGui::DoLog")); - } + switch ( level ) { + case wxLOG_Info: + if ( GetVerbose() ) + case wxLOG_Message: + if ( !m_bErrors ) { + m_aMessages.Add(szString); + m_aTimes.Add((long)t); + m_bHasMessages = TRUE; + } + break; + + case wxLOG_Status: + { + // find the top window and set it's status text if it has any + wxFrame *pFrame = gs_pFrame; + if ( pFrame == NULL ) { + wxWindow *pWin = wxTheApp->GetTopWindow(); + if ( pWin != NULL && pWin->IsKindOf(CLASSINFO(wxFrame)) ) { + pFrame = (wxFrame *)pWin; + } + } + + if ( pFrame != NULL ) + pFrame->SetStatusText(szString); + } + break; + + case wxLOG_Trace: + case wxLOG_Debug: + #ifdef __WXDEBUG__ + { + #ifdef __WXMSW__ + // don't prepend debug/trace here: it goes to the + // debug window anyhow, but do put a timestamp + OutputDebugString(wxString(szString) + "\n\r"); + #else + // send them to stderr + fprintf(stderr, "%s: %s\n", + level == wxLOG_Trace ? "Trace" : "Debug", + szString); + fflush(stderr); + #endif + } + #endif // __WXDEBUG__ + + break; + + case wxLOG_FatalError: + // show this one immediately + wxMessageBox(szString, _("Fatal error"), wxICON_HAND); + break; + + case wxLOG_Error: + // discard earlier informational messages if this is the 1st + // error because they might not make sense any more + if ( !m_bErrors ) { + m_aMessages.Empty(); + m_aTimes.Empty(); + m_bHasMessages = TRUE; + m_bErrors = TRUE; + } + // fall through + + case wxLOG_Warning: + if ( !m_bErrors ) { + // for the warning we don't discard the info messages + m_bWarnings = TRUE; + } + + m_aMessages.Add(szString); + m_aTimes.Add((long)t); + break; + + default: + wxFAIL_MSG(_("unknown log level in wxLogGui::DoLog")); + } } // ---------------------------------------------------------------------------- @@ -573,256 +585,253 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString) class wxLogFrame : public wxFrame { public: - // ctor & dtor - wxLogFrame(wxFrame *pParent, wxLogWindow *log, const char *szTitle); - virtual ~wxLogFrame(); + // ctor & dtor + wxLogFrame(wxFrame *pParent, wxLogWindow *log, const char *szTitle); + virtual ~wxLogFrame(); - // menu callbacks - void OnClose(wxCommandEvent& event); - void OnCloseWindow(wxCloseEvent& event); - void OnSave (wxCommandEvent& event); - void OnClear(wxCommandEvent& event); + // menu callbacks + void OnClose(wxCommandEvent& event); + void OnCloseWindow(wxCloseEvent& event); + void OnSave (wxCommandEvent& event); + void OnClear(wxCommandEvent& event); - void OnIdle(wxIdleEvent&); + void OnIdle(wxIdleEvent&); - // accessors - wxTextCtrl *TextCtrl() const { return m_pTextCtrl; } + // accessors + wxTextCtrl *TextCtrl() const { return m_pTextCtrl; } private: - enum - { - Menu_Close = 100, - Menu_Save, - Menu_Clear - }; + enum + { + Menu_Close = 100, + Menu_Save, + Menu_Clear + }; - // instead of closing just hide the window to be able to Show() it later - void DoClose() { Show(FALSE); } + // instead of closing just hide the window to be able to Show() it later + void DoClose() { Show(FALSE); } - wxTextCtrl *m_pTextCtrl; - wxLogWindow *m_log; + wxTextCtrl *m_pTextCtrl; + wxLogWindow *m_log; - DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE() }; BEGIN_EVENT_TABLE(wxLogFrame, wxFrame) - // wxLogWindow menu events - EVT_MENU(Menu_Close, wxLogFrame::OnClose) - EVT_MENU(Menu_Save, wxLogFrame::OnSave) - EVT_MENU(Menu_Clear, wxLogFrame::OnClear) + // wxLogWindow menu events + EVT_MENU(Menu_Close, wxLogFrame::OnClose) + EVT_MENU(Menu_Save, wxLogFrame::OnSave) + EVT_MENU(Menu_Clear, wxLogFrame::OnClear) - EVT_CLOSE(wxLogFrame::OnCloseWindow) + EVT_CLOSE(wxLogFrame::OnCloseWindow) END_EVENT_TABLE() wxLogFrame::wxLogFrame(wxFrame *pParent, wxLogWindow *log, const char *szTitle) : wxFrame(pParent, -1, szTitle) { - m_log = log; - - // @@ kludge: wxSIMPLE_BORDER is simply to prevent wxWindows from creating - // a rich edit control instead of a normal one we want in wxMSW - m_pTextCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, - wxDefaultSize, - //wxSIMPLE_BORDER | - wxTE_MULTILINE | - wxHSCROLL | - wxTE_READONLY); - - // create menu - wxMenuBar *pMenuBar = new wxMenuBar; - wxMenu *pMenu = new wxMenu; - pMenu->Append(Menu_Save, _("&Save..."), _("Save log contents to file")); - pMenu->Append(Menu_Clear, _("C&lear"), _("Clear the log contents")); - pMenu->AppendSeparator(); - pMenu->Append(Menu_Close, _("&Close"), _("Close this window")); - pMenuBar->Append(pMenu, _("&Log")); - SetMenuBar(pMenuBar); - - // status bar for menu prompts - CreateStatusBar(); - - m_log->OnFrameCreate(this); + m_log = log; + + m_pTextCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, + wxDefaultSize, + wxTE_MULTILINE | + wxHSCROLL | + wxTE_READONLY); + + // create menu + wxMenuBar *pMenuBar = new wxMenuBar; + wxMenu *pMenu = new wxMenu; + pMenu->Append(Menu_Save, _("&Save..."), _("Save log contents to file")); + pMenu->Append(Menu_Clear, _("C&lear"), _("Clear the log contents")); + pMenu->AppendSeparator(); + pMenu->Append(Menu_Close, _("&Close"), _("Close this window")); + pMenuBar->Append(pMenu, _("&Log")); + SetMenuBar(pMenuBar); + + // status bar for menu prompts + CreateStatusBar(); + + m_log->OnFrameCreate(this); } void wxLogFrame::OnClose(wxCommandEvent& WXUNUSED(event)) { - DoClose(); + DoClose(); } void wxLogFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) { - DoClose(); + DoClose(); } void wxLogFrame::OnSave(wxCommandEvent& WXUNUSED(event)) { - // get the file name - // ----------------- - const char *szFileName = wxSaveFileSelector("log", "txt", "log.txt"); - if ( szFileName == NULL ) { - // cancelled - return; - } + // get the file name + // ----------------- + const char *szFileName = wxSaveFileSelector("log", "txt", "log.txt"); + if ( szFileName == NULL ) { + // cancelled + return; + } - // open file - // --------- - wxFile file; - bool bOk = FALSE; - if ( wxFile::Exists(szFileName) ) { - bool bAppend = FALSE; - wxString strMsg; - strMsg.Printf(_("Append log to file '%s' " + // open file + // --------- + wxFile file; + bool bOk = FALSE; + if ( wxFile::Exists(szFileName) ) { + bool bAppend = FALSE; + wxString strMsg; + strMsg.Printf(_("Append log to file '%s' " "(choosing [No] will overwrite it)?"), szFileName); - switch ( wxMessageBox(strMsg, _("Question"), wxYES_NO | wxCANCEL) ) { - case wxYES: - bAppend = TRUE; - break; + switch ( wxMessageBox(strMsg, _("Question"), wxYES_NO | wxCANCEL) ) { + case wxYES: + bAppend = TRUE; + break; - case wxNO: - bAppend = FALSE; - break; + case wxNO: + bAppend = FALSE; + break; - case wxCANCEL: - return; + case wxCANCEL: + return; - default: - wxFAIL_MSG(_("invalid message box return value")); - } + default: + wxFAIL_MSG(_("invalid message box return value")); + } - if ( bAppend ) { - bOk = file.Open(szFileName, wxFile::write_append); + if ( bAppend ) { + bOk = file.Open(szFileName, wxFile::write_append); + } + else { + bOk = file.Create(szFileName, TRUE /* overwrite */); + } } else { - bOk = file.Create(szFileName, TRUE /* overwrite */); + bOk = file.Create(szFileName); } - } - else { - bOk = file.Create(szFileName); - } - // retrieve text and save it - // ------------------------- - int nLines = m_pTextCtrl->GetNumberOfLines(); - for ( int nLine = 0; bOk && nLine < nLines; nLine++ ) { - bOk = file.Write(m_pTextCtrl->GetLineText(nLine) + -// we're not going to pull in the whole wxTextFile if all we need is this... + // retrieve text and save it + // ------------------------- + int nLines = m_pTextCtrl->GetNumberOfLines(); + for ( int nLine = 0; bOk && nLine < nLines; nLine++ ) { + bOk = file.Write(m_pTextCtrl->GetLineText(nLine) + + // we're not going to pull in the whole wxTextFile if all we need is this... #if wxUSE_TEXTFILE - wxTextFile::GetEOL() + wxTextFile::GetEOL() #else // !wxUSE_TEXTFILE - '\n' + '\n' #endif // wxUSE_TEXTFILE - ); - } + ); + } - if ( bOk ) - bOk = file.Close(); + if ( bOk ) + bOk = file.Close(); - if ( !bOk ) { - wxLogError(_("Can't save log contents to file.")); - } - else { - wxLogStatus(this, _("Log saved to the file '%s'."), szFileName); - } + if ( !bOk ) { + wxLogError(_("Can't save log contents to file.")); + } + else { + wxLogStatus(this, _("Log saved to the file '%s'."), szFileName); + } } void wxLogFrame::OnClear(wxCommandEvent& WXUNUSED(event)) { - m_pTextCtrl->Clear(); + m_pTextCtrl->Clear(); } wxLogFrame::~wxLogFrame() { - m_log->OnFrameDelete(this); + m_log->OnFrameDelete(this); } // wxLogWindow // ----------- wxLogWindow::wxLogWindow(wxFrame *pParent, - const char *szTitle, - bool bShow, - bool bDoPass) + const char *szTitle, + bool bShow, + bool bDoPass) { - m_bPassMessages = bDoPass; + m_bPassMessages = bDoPass; - m_pLogFrame = new wxLogFrame(pParent, this, szTitle); - m_pOldLog = wxLog::SetActiveTarget(this); + m_pLogFrame = new wxLogFrame(pParent, this, szTitle); + m_pOldLog = wxLog::SetActiveTarget(this); - if ( bShow ) - m_pLogFrame->Show(TRUE); + if ( bShow ) + m_pLogFrame->Show(TRUE); } void wxLogWindow::Show(bool bShow) { - m_pLogFrame->Show(bShow); + m_pLogFrame->Show(bShow); } void wxLogWindow::Flush() { - if ( m_pOldLog != NULL ) - m_pOldLog->Flush(); + if ( m_pOldLog != NULL ) + m_pOldLog->Flush(); - m_bHasMessages = FALSE; + m_bHasMessages = FALSE; } -void wxLogWindow::DoLog(wxLogLevel level, const char *szString) +void wxLogWindow::DoLog(wxLogLevel level, const char *szString, time_t t) { - // first let the previous logger show it - if ( m_pOldLog != NULL && m_bPassMessages ) { - // @@@ why can't we access protected wxLog method from here (we derive - // from wxLog)? gcc gives "DoLog is protected in this context", what - // does this mean? Anyhow, the cast is harmless and let's us do what - // we want. - ((wxLogWindow *)m_pOldLog)->DoLog(level, szString); - } + // first let the previous logger show it + if ( m_pOldLog != NULL && m_bPassMessages ) { + // FIXME why can't we access protected wxLog method from here (we derive + // from wxLog)? gcc gives "DoLog is protected in this context", what + // does this mean? Anyhow, the cast is harmless and let's us do what + // we want. + ((wxLogWindow *)m_pOldLog)->DoLog(level, szString, t); + } - if ( m_pLogFrame ) { - switch ( level ) { - case wxLOG_Status: - // by default, these messages are ignored by wxLog, so process - // them ourselves - { - wxString str = TimeStamp(); - str << _("Status: ") << szString; - DoLogString(str); + if ( m_pLogFrame ) { + switch ( level ) { + case wxLOG_Status: + // by default, these messages are ignored by wxLog, so process + // them ourselves + { + wxString str; + str << _("Status: ") << szString; + DoLogString(str, t); + } + break; + + // don't put trace messages in the text window for 2 reasons: + // 1) there are too many of them + // 2) they may provoke other trace messages thus sending a program + // into an infinite loop + case wxLOG_Trace: + break; + + default: + // and this will format it nicely and call our DoLogString() + wxLog::DoLog(level, szString, t); } - break; - - // don't put trace messages in the text window for 2 reasons: - // 1) there are too many of them - // 2) they may provoke other trace messages thus sending a program - // into an infinite loop - case wxLOG_Trace: - break; - - default: - // and this will format it nicely and call our DoLogString() - wxLog::DoLog(level, szString); } - } - m_bHasMessages = TRUE; + m_bHasMessages = TRUE; } -void wxLogWindow::DoLogString(const char *szString) +void wxLogWindow::DoLogString(const char *szString, time_t t) { - // put the text into our window - wxTextCtrl *pText = m_pLogFrame->TextCtrl(); + // put the text into our window + wxTextCtrl *pText = m_pLogFrame->TextCtrl(); - // remove selection (WriteText is in fact ReplaceSelection) - #ifdef __WXMSW__ + // remove selection (WriteText is in fact ReplaceSelection) +#ifdef __WXMSW__ long nLen = pText->GetLastPosition(); pText->SetSelection(nLen, nLen); - #endif // Windows +#endif // Windows - pText->WriteText(szString); - pText->WriteText("\n"); // "\n" ok here (_not_ "\r\n") + pText->WriteText(szString); + pText->WriteText("\n"); // "\n" ok here (_not_ "\r\n") - // TODO ensure that the line can be seen + // TODO ensure that the line can be seen } wxFrame *wxLogWindow::GetFrame() const { - return m_pLogFrame; + return m_pLogFrame; } void wxLogWindow::OnFrameCreate(wxFrame * WXUNUSED(frame)) @@ -831,15 +840,15 @@ void wxLogWindow::OnFrameCreate(wxFrame * WXUNUSED(frame)) void wxLogWindow::OnFrameDelete(wxFrame * WXUNUSED(frame)) { - m_pLogFrame = (wxLogFrame *)NULL; + m_pLogFrame = (wxLogFrame *)NULL; } wxLogWindow::~wxLogWindow() { - delete m_pOldLog; + delete m_pOldLog; - // may be NULL if log frame already auto destroyed itself - delete m_pLogFrame; + // may be NULL if log frame already auto destroyed itself + delete m_pLogFrame; } #endif //wxUSE_NOGUI @@ -851,10 +860,12 @@ wxLogWindow::~wxLogWindow() // ---------------------------------------------------------------------------- // static variables // ---------------------------------------------------------------------------- -wxLog *wxLog::ms_pLogger = (wxLog *) NULL; -bool wxLog::ms_doLog = TRUE; -bool wxLog::ms_bAutoCreate = TRUE; -wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0; + +wxLog *wxLog::ms_pLogger = (wxLog *)NULL; +bool wxLog::ms_doLog = TRUE; +bool wxLog::ms_bAutoCreate = TRUE; +wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0; +wxArrayString wxLog::ms_aTraceMasks; // ---------------------------------------------------------------------------- // stdout error logging helper @@ -863,33 +874,33 @@ wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0; // helper function: wraps the message and justifies it under given position // (looks more pretty on the terminal). Also adds newline at the end. // -// @@ this is now disabled until I find a portable way of determining the -// terminal window size (ok, I found it but does anybody really cares?) -#ifdef LOG_PRETTY_WRAP +// TODO this is now disabled until I find a portable way of determining the +// terminal window size (ok, I found it but does anybody really cares?) +#ifdef LOG_PRETTY_WRAP static void wxLogWrap(FILE *f, const char *pszPrefix, const char *psz) { - size_t nMax = 80; // @@@@ - size_t nStart = strlen(pszPrefix); - fputs(pszPrefix, f); - - size_t n; - while ( *psz != '\0' ) { - for ( n = nStart; (n < nMax) && (*psz != '\0'); n++ ) - putc(*psz++, f); - - // wrapped? - if ( *psz != '\0' ) { - /*putc('\n', f);*/ - for ( n = 0; n < nStart; n++ ) - putc(' ', f); - - // as we wrapped, squeeze all white space - while ( isspace(*psz) ) - psz++; + size_t nMax = 80; // FIXME + size_t nStart = strlen(pszPrefix); + fputs(pszPrefix, f); + + size_t n; + while ( *psz != '\0' ) { + for ( n = nStart; (n < nMax) && (*psz != '\0'); n++ ) + putc(*psz++, f); + + // wrapped? + if ( *psz != '\0' ) { + /*putc('\n', f);*/ + for ( n = 0; n < nStart; n++ ) + putc(' ', f); + + // as we wrapped, squeeze all white space + while ( isspace(*psz) ) + psz++; + } } - } - putc('\n', f); + putc('\n', f); } #endif //LOG_PRETTY_WRAP @@ -900,58 +911,58 @@ static void wxLogWrap(FILE *f, const char *pszPrefix, const char *psz) // get error code from syste unsigned long wxSysErrorCode() { - #ifdef __WXMSW__ - #ifdef __WIN32__ - return ::GetLastError(); - #else //WIN16 - // @@@@ what to do on Windows 3.1? - return 0; - #endif //WIN16/32 - #else //Unix +#ifdef __WXMSW__ +#ifdef __WIN32__ + return ::GetLastError(); +#else //WIN16 + // TODO what to do on Windows 3.1? + return 0; +#endif //WIN16/32 +#else //Unix return errno; - #endif //Win/Unix +#endif //Win/Unix } // get error message from system const char *wxSysErrorMsg(unsigned long nErrCode) { - if ( nErrCode == 0 ) - nErrCode = wxSysErrorCode(); - - #ifdef __WXMSW__ - #ifdef __WIN32__ - static char s_szBuf[LOG_BUFFER_SIZE / 2]; - - // get error message from system - LPVOID lpMsgBuf; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, nErrCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMsgBuf, - 0, NULL); - - // copy it to our buffer and free memory - strncpy(s_szBuf, (const char *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1); - s_szBuf[WXSIZEOF(s_szBuf) - 1] = '\0'; - LocalFree(lpMsgBuf); - - // returned string is capitalized and ended with '\r\n' - bad - s_szBuf[0] = (char)wxToLower(s_szBuf[0]); - size_t len = strlen(s_szBuf); - if ( len > 0 ) { + if ( nErrCode == 0 ) + nErrCode = wxSysErrorCode(); + +#ifdef __WXMSW__ +#ifdef __WIN32__ + static char s_szBuf[LOG_BUFFER_SIZE / 2]; + + // get error message from system + LPVOID lpMsgBuf; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, nErrCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&lpMsgBuf, + 0, NULL); + + // copy it to our buffer and free memory + strncpy(s_szBuf, (const char *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1); + s_szBuf[WXSIZEOF(s_szBuf) - 1] = '\0'; + LocalFree(lpMsgBuf); + + // returned string is capitalized and ended with '\r\n' - bad + s_szBuf[0] = (char)tolower(s_szBuf[0]); + size_t len = strlen(s_szBuf); + if ( len > 0 ) { // truncate string if ( s_szBuf[len - 2] == '\r' ) - s_szBuf[len - 2] = '\0'; - } - - return s_szBuf; - #else //Win16 - // TODO @@@@ - return NULL; - #endif // Win16/32 - #else // Unix + s_szBuf[len - 2] = '\0'; + } + + return s_szBuf; +#else //Win16 + // TODO + return NULL; +#endif // Win16/32 +#else // Unix return strerror(nErrCode); - #endif // Win/Unix +#endif // Win/Unix } // ---------------------------------------------------------------------------- @@ -960,87 +971,90 @@ const char *wxSysErrorMsg(unsigned long nErrCode) #ifdef __WXDEBUG__ +// break into the debugger void Trap() { - #ifdef __WXMSW__ +#ifdef __WXMSW__ DebugBreak(); - #elif defined(__WXSTUBS__) - // TODO - #elif defined(__WXMAC__) - #if __powerc +#elif defined(__WXMAC__) +#if __powerc Debugger(); - #else +#else SysBreak(); - #endif - #else // Unix +#endif +#elif defined(__UNIX__) raise(SIGTRAP); - #endif // Win/Unix +#else + // TODO +#endif // Win/Unix } // this function is called when an assert fails void wxOnAssert(const char *szFile, int nLine, const char *szMsg) { - // this variable can be set to true to suppress "assert failure" messages - static bool s_bNoAsserts = FALSE; - static bool s_bInAssert = FALSE; + // this variable can be set to true to suppress "assert failure" messages + static bool s_bNoAsserts = FALSE; + static bool s_bInAssert = FALSE; // FIXME MT-unsafe - if ( s_bInAssert ) { - // He-e-e-e-elp!! we're trapped in endless loop - Trap(); + if ( s_bInAssert ) { + // He-e-e-e-elp!! we're trapped in endless loop + Trap(); - s_bInAssert = FALSE; + s_bInAssert = FALSE; - return; - } + return; + } - s_bInAssert = TRUE; + s_bInAssert = TRUE; - char szBuf[LOG_BUFFER_SIZE]; + char szBuf[LOG_BUFFER_SIZE]; - // make life easier for people using VC++ IDE: clicking on the message will - // take us immediately to the place of the failed assert + // make life easier for people using VC++ IDE: clicking on the message + // will take us immediately to the place of the failed assert #ifdef __VISUALC__ - sprintf(szBuf, "%s(%d): assert failed", szFile, nLine); + sprintf(szBuf, "%s(%d): assert failed", szFile, nLine); #else // !VC++ - // make the error message more clear for all the others - sprintf(szBuf, "Assert failed in file %s at line %d", szFile, nLine); + // make the error message more clear for all the others + sprintf(szBuf, "Assert failed in file %s at line %d", szFile, nLine); #endif // VC/!VC - if ( szMsg != NULL ) { - strcat(szBuf, ": "); - strcat(szBuf, szMsg); - } - else { - strcat(szBuf, "."); - } + if ( szMsg != NULL ) { + strcat(szBuf, ": "); + strcat(szBuf, szMsg); + } + else { + strcat(szBuf, "."); + } - if ( !s_bNoAsserts ) { - // send it to the normal log destination - wxLogDebug(szBuf); - - #if wxUSE_NOGUI - Trap(); - #else - strcat(szBuf, "\nDo you want to stop the program?" - "\nYou can also choose [Cancel] to suppress " - "further warnings."); - - switch ( wxMessageBox(szBuf, _("Debug"), - wxYES_NO | wxCANCEL | wxICON_STOP ) ) { - case wxYES: - Trap(); - break; - - case wxCANCEL: - s_bNoAsserts = TRUE; - break; - - //case wxNO: nothing to do - } - #endif // USE_NOGUI - } + if ( !s_bNoAsserts ) { + // send it to the normal log destination + wxLogDebug(szBuf); - s_bInAssert = FALSE; +#if wxUSE_NOGUI + Trap(); +#else + // this message is intentionally not translated - it is for + // developpers only + strcat(szBuf, "\nDo you want to stop the program?" + "\nYou can also choose [Cancel] to suppress " + "further warnings."); + + switch ( wxMessageBox(szBuf, _("Debug"), + wxYES_NO | wxCANCEL | wxICON_STOP ) ) { + case wxYES: + Trap(); + break; + + case wxCANCEL: + s_bNoAsserts = TRUE; + break; + + //case wxNO: nothing to do + } +#endif // USE_NOGUI + } + + s_bInAssert = FALSE; } #endif //WXDEBUG diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index be9df90d2f..3520a5f0f5 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -359,28 +359,6 @@ wxString wxNow( void ) return wxString(date); } -/* Get Full RFC822 style email address */ -bool -wxGetEmailAddress (char *address, int maxSize) -{ - char host[65]; - char user[65]; - - if (wxGetHostName(host, 64) == FALSE) - return FALSE; - if (wxGetUserId(user, 64) == FALSE) - return FALSE; - - char tmp[130]; - strcpy(tmp, user); - strcat(tmp, "@"); - strcat(tmp, host); - - strncpy(address, tmp, maxSize - 1); - address[maxSize-1] = '\0'; - return TRUE; -} - /* * Strip out any menu codes */ @@ -822,37 +800,81 @@ int isascii( int c ) } #endif -bool wxGetUserId(wxString& buf) +// ---------------------------------------------------------------------------- +// network and user id functions +// ---------------------------------------------------------------------------- + +// Get Full RFC822 style email address +bool wxGetEmailAddress(char *address, int maxSize) { - bool success = wxGetUserId(wxBuffer, 500); - if (success) - { - buf = wxBuffer; - return TRUE; - } - else + wxString email = wxGetEmailAddress(); + if ( !email ) return FALSE; + + strncpy(address, email, maxSize - 1); + address[maxSize - 1] = '\0'; + + return TRUE; } -bool wxGetUserName(wxString& buf) +wxString wxGetEmailAddress() { - bool success = wxGetUserName(wxBuffer, 500); - if (success) + wxString email; + + wxString host = wxGetHostName(); + if ( !!host ) { - buf = wxBuffer; - return TRUE; + wxString user = wxGetUserId(); + if ( !!user ) + { + wxString email(user); + email << '@' << host; + } } - else - return FALSE; + + return email; +} + +wxString wxGetUserId() +{ + static const int maxLoginLen = 256; // FIXME arbitrary number + + wxString buf; + bool ok = wxGetUserId(buf.GetWriteBuf(maxLoginLen), maxLoginLen); + buf.UngetWriteBuf(); + + if ( !ok ) + buf.Empty(); + + return buf; +} + +wxString wxGetUserName() +{ + static const int maxUserNameLen = 1024; // FIXME arbitrary number + + wxString buf; + bool ok = wxGetUserName(buf.GetWriteBuf(maxUserNameLen), maxUserNameLen); + buf.UngetWriteBuf(); + + if ( !ok ) + buf.Empty(); + + return buf; } -bool wxGetHostName(wxString& buf) +wxString wxGetHostName() { static const size_t hostnameSize = 257; + + wxString buf; bool ok = wxGetHostName(buf.GetWriteBuf(hostnameSize), hostnameSize); buf.UngetWriteBuf(); - return ok; + if ( !ok ) + buf.Empty(); + + return buf; } diff --git a/src/motif/accel.cpp b/src/motif/accel.cpp index 46adbcc4b6..4c87676c43 100644 --- a/src/motif/accel.cpp +++ b/src/motif/accel.cpp @@ -29,7 +29,7 @@ class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData public: wxAcceleratorRefData(); ~wxAcceleratorRefData(); - + public: int m_count; wxAcceleratorEntry* m_entries; @@ -71,13 +71,13 @@ wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[]) { wxAcceleratorRefData* data = new wxAcceleratorRefData; m_refData = data; - + data->m_count = n; data->m_entries = new wxAcceleratorEntry[n]; int i; for (i = 0; i < n; i++) data->m_entries[i] = entries[i]; - + } bool wxAcceleratorTable::Ok() const @@ -102,15 +102,15 @@ bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent& event) const bool eventCtrlDown = event.ControlDown(); bool eventShiftDown = event.ShiftDown(); int eventKeyCode = event.KeyCode(); - + bool accAltDown = ((GetFlags() & wxACCEL_ALT) == wxACCEL_ALT); bool accCtrlDown = ((GetFlags() & wxACCEL_CTRL) == wxACCEL_CTRL); bool accShiftDown = ((GetFlags() & wxACCEL_SHIFT) == wxACCEL_SHIFT); int accKeyCode = GetKeyCode(); int accKeyCode2 = GetKeyCode(); if (isascii(accKeyCode2)) - accKeyCode2 = wxToLower(accKeyCode2); - + accKeyCode2 = tolower(accKeyCode2); + return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) && (eventShiftDown == accShiftDown) && ((eventKeyCode == accKeyCode || eventKeyCode == accKeyCode2))) ; diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 9a213ff4c0..546a34d86f 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -110,9 +110,9 @@ void wxUsleep(unsigned long milliseconds) // process management // ---------------------------------------------------------------------------- -int wxKill(long pid, int sig) +int wxKill(long pid, wxSignal sig) { - return kill(pid, sig); + return kill(pid, (int)sig); } #define WXEXECUTE_NARGS 127 @@ -350,7 +350,7 @@ char *wxGetUserHome( const wxString &user ) { struct passwd *who = (struct passwd *) NULL; - if (user.IsNull() || (user== "")) + if ( !user ) { register char *ptr; @@ -378,12 +378,15 @@ char *wxGetUserHome( const wxString &user ) } // ---------------------------------------------------------------------------- -// id routines +// network and user id routines // ---------------------------------------------------------------------------- -bool wxGetHostName(char *buf, int sz) +// retrieve either the hostname or FQDN depending on platform (caller must +// check whether it's one or the other, this is why this function is for +// private use only) +static bool wxGetHostNameInternal(char *buf, int sz) { - wxCHECK_MSG( buf, FALSE, "NULL pointer in wxGetHostName" ); + wxCHECK_MSG( buf, FALSE, "NULL pointer in wxGetHostNameInternal" ); *buf = '\0'; @@ -398,11 +401,11 @@ bool wxGetHostName(char *buf, int sz) } #elif defined(HAVE_GETHOSTNAME) bool ok = gethostname(buf, sz) != -1; -#else +#else // no uname, no gethostname wxFAIL_MSG("don't know host name for this machibe"); bool ok = FALSE; -#endif +#endif // uname/gethostname if ( !ok ) { @@ -412,6 +415,52 @@ bool wxGetHostName(char *buf, int sz) return ok; } +bool wxGetHostName(char *buf, int sz) +{ + bool ok = wxGetHostNameInternal(buf, sz); + + if ( ok ) + { + // BSD systems return the FQDN, we only want the hostname, so extract + // it (we consider that dots are domain separators) + char *dot = strchr(buf, '.'); + if ( dot ) + { + // nuke it + *dot = '\0'; + } + } + + return ok; +} + +bool wxGetFullHostName(char *buf, int sz) +{ + bool ok = wxGetHostNameInternal(buf, sz); + + if ( ok ) + { + if ( !strchr(buf, '.') ) + { + struct hostent *host = gethostbyname(buf); + if ( !host ) + { + wxLogSysError(_("Cannot get the official hostname")); + + ok = FALSE; + } + else + { + // the canonical name + strncpy(buf, host->h_name, sz); + } + } + //else: it's already a FQDN (BSD behaves this way) + } + + return ok; +} + bool wxGetUserId(char *buf, int sz) { struct passwd *who; @@ -473,14 +522,3 @@ void wxFatalError( const wxString &msg, const wxString &title ) exit(3); // the same exit code as for abort() } -//------------------------------------------------------------------------ -// directory routines -//------------------------------------------------------------------------ - -bool wxDirExists( const wxString& dir ) -{ - char buf[500]; - strcpy( buf, WXSTRINGCAST(dir) ); - struct stat sbuf; - return ((stat(buf, &sbuf) != -1) && S_ISDIR(sbuf.st_mode) ? TRUE : FALSE); -}