// 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 <wx/intl.h>
+ #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 <wx/intl.h>
#endif
#ifdef __WXGTK__
-#include "wx/mdi.h"
+ #include "wx/mdi.h"
#endif
#include "wx/msgdlg.h"
#include <fstream>
#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;
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))
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)
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
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
// 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.
// 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;
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()
{
}
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)
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))
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);
}
// - 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();
// 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
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()
{
}
}
-#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
+
// 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
// 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
vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
- wxLog::OnLog(level, s_szBuf);
+ wxLog::OnLog(level, s_szBuf, time(NULL));
}
}
vsprintf(s_szBuf, szFormat, argptr); \
va_end(argptr); \
\
- wxLog::OnLog(wxLOG_##level, s_szBuf); \
+ wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
} \
}
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;
}
}
vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
- wxLog::OnLog(wxLOG_Info, s_szBuf);
+ wxLog::OnLog(wxLOG_Info, s_szBuf, time(NULL));
}
}
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();
vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
- wxLog::OnLog(wxLOG_Trace, s_szBuf);
+ wxLog::OnLog(wxLOG_Trace, s_szBuf, time(NULL));
}
}
// 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);
}
// ----------------------------------------------------------------------------
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
}
// ----------------------------------------------------------------------------
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
#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
#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"));
+ }
}
// ----------------------------------------------------------------------------
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))
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
// ----------------------------------------------------------------------------
// 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
// 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
// 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
}
// ----------------------------------------------------------------------------
#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