many miscellaneous fixes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1998 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-03-29 16:46:18 +00:00
parent 8826f46f0d
commit 0fb67cd196
7 changed files with 1826 additions and 1732 deletions

View File

@@ -9,6 +9,14 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "docview.h" #pragma implementation "docview.h"
#endif #endif
@@ -59,6 +67,10 @@
#include <fstream> #include <fstream>
#endif #endif
// ----------------------------------------------------------------------------
// wxWindows macros
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler) IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler)
IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler) IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler)
@@ -66,36 +78,58 @@ IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxDocManager, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxDocManager, wxEvtHandler)
IMPLEMENT_CLASS(wxDocChildFrame, wxFrame) IMPLEMENT_CLASS(wxDocChildFrame, wxFrame)
IMPLEMENT_CLASS(wxDocParentFrame, wxFrame) IMPLEMENT_CLASS(wxDocParentFrame, wxFrame)
#if wxUSE_PRINTING_ARCHITECTURE #if wxUSE_PRINTING_ARCHITECTURE
IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout, wxPrintout) IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout, wxPrintout)
#endif #endif
IMPLEMENT_CLASS(wxCommand, wxObject) IMPLEMENT_CLASS(wxCommand, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject)
// IMPLEMENT_DYNAMIC_CLASS(wxPrintInfo, wxObject)
#endif #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) wxDocument::wxDocument(wxDocument *parent)
{ {
m_documentModified = FALSE; m_documentModified = FALSE;
m_documentFile="";
m_documentTitle="";
m_documentParent = parent; m_documentParent = parent;
m_documentTemplate = (wxDocTemplate *) NULL; m_documentTemplate = (wxDocTemplate *) NULL;
m_documentTypeName = "";
m_savedYet = FALSE; m_savedYet = FALSE;
} }
bool wxDocument::DeleteContents(void) bool wxDocument::DeleteContents()
{ {
return TRUE; return TRUE;
} }
wxDocument::~wxDocument(void) wxDocument::~wxDocument()
{ {
DeleteContents(); DeleteContents();
@@ -104,14 +138,13 @@ wxDocument::~wxDocument(void)
GetDocumentManager()->RemoveDocument(this); GetDocumentManager()->RemoveDocument(this);
// Not safe to do here, since it'll // Not safe to do here, since it'll invoke virtual view functions
// invoke virtual view functions expecting to see // expecting to see valid derived objects: and by the time we get here,
// valid derived objects: and by the time we get // we've called destructors higher up.
// here, we've called destructors higher up.
//DeleteAllViews(); //DeleteAllViews();
} }
bool wxDocument::Close(void) bool wxDocument::Close()
{ {
if (OnSaveModified()) if (OnSaveModified())
return OnCloseDocument(); return OnCloseDocument();
@@ -119,16 +152,16 @@ bool wxDocument::Close(void)
return FALSE; return FALSE;
} }
bool wxDocument::OnCloseDocument(void) bool wxDocument::OnCloseDocument()
{ {
DeleteContents(); DeleteContents();
Modify(FALSE); Modify(FALSE);
return TRUE; return TRUE;
} }
// Note that this implicitly deletes the document when // Note that this implicitly deletes the document when the last view is
// the last view is deleted. // deleted.
bool wxDocument::DeleteAllViews(void) bool wxDocument::DeleteAllViews()
{ {
wxNode *node = m_documentViews.First(); wxNode *node = m_documentViews.First();
while (node) while (node)
@@ -157,7 +190,7 @@ wxDocManager *wxDocument::GetDocumentManager(void) const
return m_documentTemplate->GetDocumentManager(); return m_documentTemplate->GetDocumentManager();
} }
bool wxDocument::OnNewDocument(void) bool wxDocument::OnNewDocument()
{ {
if (!OnSaveModified()) if (!OnSaveModified())
return FALSE; return FALSE;
@@ -175,7 +208,7 @@ bool wxDocument::OnNewDocument(void)
return TRUE; return TRUE;
} }
bool wxDocument::Save(void) bool wxDocument::Save()
{ {
bool ret = FALSE; bool ret = FALSE;
@@ -189,7 +222,7 @@ bool wxDocument::Save(void)
return ret; return ret;
} }
bool wxDocument::SaveAs(void) bool wxDocument::SaveAs()
{ {
wxDocTemplate *docTemplate = GetDocumentTemplate(); wxDocTemplate *docTemplate = GetDocumentTemplate();
if (!docTemplate) if (!docTemplate)
@@ -237,7 +270,7 @@ bool wxDocument::SaveAs(void)
bool wxDocument::OnSaveDocument(const wxString& file) bool wxDocument::OnSaveDocument(const wxString& file)
{ {
if (file == "") if ( !file )
return FALSE; return FALSE;
wxString msgTitle; wxString msgTitle;
@@ -313,7 +346,7 @@ ostream& wxDocument::SaveObject(ostream& stream)
return stream; return stream;
} }
bool wxDocument::Revert(void) bool wxDocument::Revert()
{ {
return FALSE; return FALSE;
} }
@@ -348,13 +381,13 @@ wxWindow *wxDocument::GetDocumentWindow(void) const
return wxTheApp->GetTopWindow(); return wxTheApp->GetTopWindow();
} }
wxCommandProcessor *wxDocument::OnCreateCommandProcessor(void) wxCommandProcessor *wxDocument::OnCreateCommandProcessor()
{ {
return new wxCommandProcessor; return new wxCommandProcessor;
} }
// TRUE if safe to close // TRUE if safe to close
bool wxDocument::OnSaveModified(void) bool wxDocument::OnSaveModified()
{ {
if (IsModified()) if (IsModified())
{ {
@@ -419,7 +452,7 @@ bool wxDocument::OnCreate(const wxString& WXUNUSED(path), long flags)
// Called after a view is added or removed. // Called after a view is added or removed.
// The default implementation deletes the document if // The default implementation deletes the document if
// there are no more views. // there are no more views.
void wxDocument::OnChangedViewList(void) void wxDocument::OnChangedViewList()
{ {
if (m_documentViews.Number() == 0) if (m_documentViews.Number() == 0)
{ {
@@ -457,10 +490,9 @@ void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
} }
} }
// ----------------------------------------------------------------------------
/* // Document view
* Document view // ----------------------------------------------------------------------------
*/
wxView::wxView() wxView::wxView()
{ {
@@ -471,7 +503,7 @@ wxView::wxView()
m_viewFrame = (wxFrame *) NULL; m_viewFrame = (wxFrame *) NULL;
} }
wxView::~wxView(void) wxView::~wxView()
{ {
GetDocumentManager()->ActivateView(this, FALSE, TRUE); GetDocumentManager()->ActivateView(this, FALSE, TRUE);
m_viewDocument->RemoveView(this); m_viewDocument->RemoveView(this);
@@ -499,7 +531,7 @@ void wxView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
{ {
} }
void wxView::OnChangeFilename(void) void wxView::OnChangeFilename()
{ {
if (GetFrame() && GetDocument()) if (GetFrame() && GetDocument())
{ {
@@ -540,21 +572,26 @@ bool wxView::OnClose(bool WXUNUSED(deleteWindow))
} }
#if wxUSE_PRINTING_ARCHITECTURE #if wxUSE_PRINTING_ARCHITECTURE
wxPrintout *wxView::OnCreatePrintout(void) wxPrintout *wxView::OnCreatePrintout()
{ {
return new wxDocPrintout(this); return new wxDocPrintout(this);
} }
#endif #endif
// ----------------------------------------------------------------------------
// wxDocTemplate
// ----------------------------------------------------------------------------
/* wxDocTemplate::wxDocTemplate(wxDocManager *manager,
* wxDocTemplate const wxString& descr,
*/ const wxString& filter,
const wxString& dir,
wxDocTemplate::wxDocTemplate(wxDocManager *manager, const wxString& descr, const wxString& ext,
const wxString& filter, const wxString& dir, const wxString& ext, const wxString& docTypeName,
const wxString& docTypeName, const wxString& viewTypeName, const wxString& viewTypeName,
wxClassInfo *docClassInfo, wxClassInfo *viewClassInfo, long flags) wxClassInfo *docClassInfo,
wxClassInfo *viewClassInfo,
long flags)
{ {
m_documentManager = manager; m_documentManager = manager;
m_flags = flags; m_flags = flags;
@@ -571,13 +608,12 @@ wxDocTemplate::wxDocTemplate(wxDocManager *manager, const wxString& descr,
m_viewClassInfo = viewClassInfo; 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 // Tries to dynamically construct an object of the right class.
// class.
wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags) wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
{ {
if (!m_docClassInfo) if (!m_docClassInfo)
@@ -614,6 +650,10 @@ wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
} }
} }
// ----------------------------------------------------------------------------
// wxDocManager
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler) BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler)
EVT_MENU(wxID_OPEN, wxDocManager::OnFileOpen) EVT_MENU(wxID_OPEN, wxDocManager::OnFileOpen)
EVT_MENU(wxID_CLOSE, wxDocManager::OnFileClose) EVT_MENU(wxID_CLOSE, wxDocManager::OnFileClose)
@@ -639,7 +679,7 @@ wxDocManager::wxDocManager(long flags, bool initialize)
Initialize(); Initialize();
} }
wxDocManager::~wxDocManager(void) wxDocManager::~wxDocManager()
{ {
Clear(); Clear();
if (m_fileHistory) if (m_fileHistory)
@@ -681,13 +721,13 @@ bool wxDocManager::Clear(bool force)
return TRUE; return TRUE;
} }
bool wxDocManager::Initialize(void) bool wxDocManager::Initialize()
{ {
m_fileHistory = OnCreateFileHistory(); m_fileHistory = OnCreateFileHistory();
return TRUE; return TRUE;
} }
wxFileHistory *wxDocManager::OnCreateFileHistory(void) wxFileHistory *wxDocManager::OnCreateFileHistory()
{ {
return new wxFileHistory; return new wxFileHistory;
} }
@@ -1027,10 +1067,12 @@ void wxDocManager::AddFileToHistory(const wxString& file)
wxString wxDocManager::GetHistoryFile(int i) const wxString wxDocManager::GetHistoryFile(int i) const
{ {
wxString histFile;
if (m_fileHistory) if (m_fileHistory)
return wxString(m_fileHistory->GetHistoryFile(i)); histFile = m_fileHistory->GetHistoryFile(i);
else
return wxString(""); return histFile;
} }
void wxDocManager::FileHistoryUseMenu(wxMenu *menu) void wxDocManager::FileHistoryUseMenu(wxMenu *menu)
@@ -1079,36 +1121,12 @@ int wxDocManager::GetNoHistoryFiles(void) const
return 0; 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;
}
else
return (char *) NULL;
}
else return (char *) NULL;
}
// Given a path, try to find a matching template. Won't always work, of
// Given a path, try to find a matching template. Won't // course.
// always work, of course.
wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path) wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path)
{ {
char *theExt = FindExtension((char *)(const char *)path); wxString theExt = FindExtension(path);
if (!theExt) if (!theExt)
return (wxDocTemplate *) NULL; return (wxDocTemplate *) NULL;
wxDocTemplate *theTemplate = (wxDocTemplate *) NULL; wxDocTemplate *theTemplate = (wxDocTemplate *) NULL;
@@ -1135,13 +1153,11 @@ wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path)
// dialog or implement own; OR match the extension to the // dialog or implement own; OR match the extension to the
// template extension. // template extension.
#ifdef __WXMSW__
wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
int noTemplates, wxString& path, long WXUNUSED(flags), bool WXUNUSED(save)) int noTemplates,
#else wxString& path,
wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templates), long WXUNUSED(flags),
int WXUNUSED(noTemplates), wxString& path, long WXUNUSED(flags), bool WXUNUSED(save)) bool WXUNUSED(save))
#endif
{ {
// We can only have multiple filters in Windows // We can only have multiple filters in Windows
#ifdef __WXMSW__ #ifdef __WXMSW__
@@ -1171,7 +1187,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templat
if (!pathTmp.IsEmpty()) if (!pathTmp.IsEmpty())
{ {
path = pathTmp; path = pathTmp;
char *theExt = FindExtension((char *)(const char *)path); wxString theExt = FindExtension(path);
if (!theExt) if (!theExt)
return (wxDocTemplate *) NULL; return (wxDocTemplate *) NULL;
@@ -1207,7 +1223,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templat
} }
else else
return (wxDocTemplate *) NULL; return (wxDocTemplate *) NULL;
#endif #endif // 0
} }
wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates, wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
@@ -1317,18 +1333,25 @@ void wxDocManager::ActivateView(wxView *view, bool activate, bool WXUNUSED(delet
} }
} }
/* // ----------------------------------------------------------------------------
* Default document child frame // Default document child frame
*/ // ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxDocChildFrame, wxFrame) BEGIN_EVENT_TABLE(wxDocChildFrame, wxFrame)
EVT_ACTIVATE(wxDocChildFrame::OnActivate) EVT_ACTIVATE(wxDocChildFrame::OnActivate)
EVT_CLOSE(wxDocChildFrame::OnCloseWindow) EVT_CLOSE(wxDocChildFrame::OnCloseWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
wxDocChildFrame::wxDocChildFrame(wxDocument *doc, wxView *view, wxFrame *frame, wxWindowID id, const wxString& title, wxDocChildFrame::wxDocChildFrame(wxDocument *doc,
const wxPoint& pos, const wxSize& size, long style, const wxString& name): wxView *view,
wxFrame(frame, id, title, pos, size, style, name) 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_childDocument = doc;
m_childView = view; m_childView = view;
@@ -1336,7 +1359,7 @@ wxDocChildFrame::wxDocChildFrame(wxDocument *doc, wxView *view, wxFrame *frame,
view->SetFrame(this); view->SetFrame(this);
} }
wxDocChildFrame::~wxDocChildFrame(void) wxDocChildFrame::~wxDocChildFrame()
{ {
} }
@@ -1392,9 +1415,9 @@ void wxDocChildFrame::OnCloseWindow(wxCloseEvent& event)
event.Veto(); event.Veto();
} }
/* // ----------------------------------------------------------------------------
* Default parent frame // Default parent frame
*/ // ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame) BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame)
EVT_MENU(wxID_EXIT, wxDocParentFrame::OnExit) EVT_MENU(wxID_EXIT, wxDocParentFrame::OnExit)
@@ -1402,9 +1425,15 @@ BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame)
EVT_CLOSE(wxDocParentFrame::OnCloseWindow) EVT_CLOSE(wxDocParentFrame::OnCloseWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
wxDocParentFrame::wxDocParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, wxDocParentFrame::wxDocParentFrame(wxDocManager *manager,
const wxPoint& pos, const wxSize& size, long style, const wxString& name): wxFrame *frame,
wxFrame(frame, id, title, pos, size, style, name) 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;
} }
@@ -1445,8 +1474,8 @@ void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event)
#if wxUSE_PRINTING_ARCHITECTURE #if wxUSE_PRINTING_ARCHITECTURE
wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title): wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title)
wxPrintout(WXSTRINGCAST title) : wxPrintout(WXSTRINGCAST title)
{ {
m_printoutView = view; m_printoutView = view;
} }
@@ -1508,11 +1537,11 @@ void wxDocPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, in
*selPageTo = 1; *selPageTo = 1;
} }
#endif #endif // wxUSE_PRINTING_ARCHITECTURE
/* // ----------------------------------------------------------------------------
* Command processing framework // Command processing framework
*/ // ----------------------------------------------------------------------------
wxCommand::wxCommand(bool canUndoIt, const wxString& name) wxCommand::wxCommand(bool canUndoIt, const wxString& name)
{ {
@@ -1520,7 +1549,7 @@ wxCommand::wxCommand(bool canUndoIt, const wxString& name)
m_commandName = name; m_commandName = name;
} }
wxCommand::~wxCommand(void) wxCommand::~wxCommand()
{ {
} }
@@ -1532,7 +1561,7 @@ wxCommandProcessor::wxCommandProcessor(int maxCommands)
m_commandEditMenu = (wxMenu *) NULL; m_commandEditMenu = (wxMenu *) NULL;
} }
wxCommandProcessor::~wxCommandProcessor(void) wxCommandProcessor::~wxCommandProcessor()
{ {
ClearCommands(); ClearCommands();
} }
@@ -1576,7 +1605,7 @@ bool wxCommandProcessor::Submit(wxCommand *command, bool storeIt)
return success; return success;
} }
bool wxCommandProcessor::Undo(void) bool wxCommandProcessor::Undo()
{ {
if (m_currentCommand) if (m_currentCommand)
{ {
@@ -1595,7 +1624,7 @@ bool wxCommandProcessor::Undo(void)
return FALSE; return FALSE;
} }
bool wxCommandProcessor::Redo(void) bool wxCommandProcessor::Redo()
{ {
wxCommand *redoCommand = (wxCommand *) NULL; wxCommand *redoCommand = (wxCommand *) NULL;
wxNode *redoNode = (wxNode *) NULL; wxNode *redoNode = (wxNode *) NULL;
@@ -1647,13 +1676,13 @@ bool wxCommandProcessor::CanRedo(void) const
return FALSE; return FALSE;
} }
void wxCommandProcessor::Initialize(void) void wxCommandProcessor::Initialize()
{ {
m_currentCommand = m_commands.Last(); m_currentCommand = m_commands.Last();
SetMenuStrings(); SetMenuStrings();
} }
void wxCommandProcessor::SetMenuStrings(void) void wxCommandProcessor::SetMenuStrings()
{ {
if (m_commandEditMenu) if (m_commandEditMenu)
{ {
@@ -1713,7 +1742,7 @@ void wxCommandProcessor::SetMenuStrings(void)
} }
} }
void wxCommandProcessor::ClearCommands(void) void wxCommandProcessor::ClearCommands()
{ {
wxNode *node = m_commands.First(); wxNode *node = m_commands.First();
while (node) while (node)
@@ -1726,10 +1755,9 @@ void wxCommandProcessor::ClearCommands(void)
m_currentCommand = (wxNode *) NULL; m_currentCommand = (wxNode *) NULL;
} }
// ----------------------------------------------------------------------------
/* // File history processor
* File history processor // ----------------------------------------------------------------------------
*/
wxFileHistory::wxFileHistory(int maxFiles) wxFileHistory::wxFileHistory(int maxFiles)
{ {
@@ -1738,7 +1766,7 @@ wxFileHistory::wxFileHistory(int maxFiles)
m_fileHistory = new char *[m_fileMaxFiles]; m_fileHistory = new char *[m_fileMaxFiles];
} }
wxFileHistory::~wxFileHistory(void) wxFileHistory::~wxFileHistory()
{ {
int i; int i;
for (i = 0; i < m_fileHistoryN; i++) for (i = 0; i < m_fileHistoryN; i++)
@@ -1847,7 +1875,7 @@ void wxFileHistory::Save(wxConfigBase& config)
config.Write(buf, wxString(m_fileHistory[i])); config.Write(buf, wxString(m_fileHistory[i]));
} }
} }
#endif #endif // wxUSE_CONFIG
void wxFileHistory::AddFilesToMenu() void wxFileHistory::AddFilesToMenu()
{ {
@@ -1891,25 +1919,10 @@ void wxFileHistory::AddFilesToMenu(wxMenu* menu)
} }
} }
#if 0 // ----------------------------------------------------------------------------
/* // Permits compatibility with existing file formats and functions that
* wxPrintInfo // manipulate files directly
*/ // ----------------------------------------------------------------------------
wxPrintInfo::wxPrintInfo(void)
{
pageNumber = 1;
}
wxPrintInfo::~wxPrintInfo(void)
{
}
#endif
/*
* Permits compatibility with existing file formats and functions
* that manipulate files directly
*/
bool wxTransferFileToStream(const wxString& filename, ostream& stream) bool wxTransferFileToStream(const wxString& filename, ostream& stream)
{ {
@@ -1946,5 +1959,5 @@ bool wxTransferStreamToFile(istream& stream, const wxString& filename)
return TRUE; return TRUE;
} }
#endif #endif // wxUSE_DOC_VIEW_ARCHITECTURE
// End wxUSE_DOC_VIEW_ARCHITECTURE

View File

@@ -274,6 +274,12 @@ bool wxFileExists(const char *pszFileName)
} }
*/ */
bool wxDirExists( const wxString& dir )
{
struct stat st;
return ((stat(dir, &st) != -1) && S_ISDIR(st.st_mode) ? TRUE : FALSE);
}
bool bool
wxIsAbsolutePath (const wxString& filename) wxIsAbsolutePath (const wxString& filename)
{ {
@@ -785,7 +791,7 @@ wxMac2UnixFilename (char *s)
if (*s == ':') if (*s == ':')
*s = '/'; *s = '/';
else else
*s = wxToLower (*s); // Case INDEPENDENT *s = tolower(*s); // Case INDEPENDENT
s++; s++;
} }
} }
@@ -830,7 +836,7 @@ wxDos2UnixFilename (char *s)
*s = '/'; *s = '/';
#ifdef __WXMSW__ #ifdef __WXMSW__
else else
*s = wxToLower (*s); // Case INDEPENDENT *s = tolower(*s); // Case INDEPENDENT
#endif #endif
s++; s++;
} }

View File

@@ -30,6 +30,7 @@
// standard headers // standard headers
#include <locale.h> #include <locale.h>
#include <ctype.h>
// wxWindows // wxWindows
#include "wx/defs.h" #include "wx/defs.h"
@@ -435,7 +436,7 @@ bool wxLocale::Init(const char *szName,
if ( m_strShort.IsEmpty() ) { if ( m_strShort.IsEmpty() ) {
// FIXME I don't know how these 2 letter abbreviations are formed, // FIXME I don't know how these 2 letter abbreviations are formed,
// this wild guess is surely wrong // this wild guess is surely wrong
m_strShort = wxToLower(szLocale[0]) + wxToLower(szLocale[1]); m_strShort = tolower(szLocale[0]) + tolower(szLocale[1]);
} }
// save the old locale to be able to restore it later // save the old locale to be able to restore it later

View File

@@ -75,7 +75,7 @@
// we use a global variable to store the frame pointer for wxLogStatus - bad, // we use a global variable to store the frame pointer for wxLogStatus - bad,
// but it's he easiest way // but it's he easiest way
static wxFrame *gs_pFrame; static wxFrame *gs_pFrame; // FIXME MT-unsafe
// ============================================================================ // ============================================================================
// implementation // implementation
@@ -92,7 +92,7 @@ static wxFrame *gs_pFrame;
// work!), so we use a static buffer for all log messages // work!), so we use a static buffer for all log messages
#define LOG_BUFFER_SIZE (4096) #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]; static char s_szBuf[LOG_BUFFER_SIZE];
// generic log function // generic log function
@@ -104,7 +104,7 @@ void wxLogGeneric(wxLogLevel level, const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr); vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr); va_end(argptr);
wxLog::OnLog(level, s_szBuf); wxLog::OnLog(level, s_szBuf, time(NULL));
} }
} }
@@ -117,7 +117,7 @@ void wxLogGeneric(wxLogLevel level, const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr); \ vsprintf(s_szBuf, szFormat, argptr); \
va_end(argptr); \ va_end(argptr); \
\ \
wxLog::OnLog(wxLOG_##level, s_szBuf); \ wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
} \ } \
} }
@@ -141,7 +141,7 @@ void wxLogStatus(wxFrame *pFrame, const char *szFormat, ...)
wxASSERT( gs_pFrame == NULL ); // should be reset! wxASSERT( gs_pFrame == NULL ); // should be reset!
gs_pFrame = pFrame; gs_pFrame = pFrame;
wxLog::OnLog(wxLOG_Status, s_szBuf); wxLog::OnLog(wxLOG_Status, s_szBuf, time(NULL));
gs_pFrame = (wxFrame *) NULL; gs_pFrame = (wxFrame *) NULL;
} }
} }
@@ -156,7 +156,7 @@ void wxLogVerbose(const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr); vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr); va_end(argptr);
wxLog::OnLog(wxLOG_Info, s_szBuf); wxLog::OnLog(wxLOG_Info, s_szBuf, time(NULL));
} }
} }
@@ -171,10 +171,24 @@ void wxLogVerbose(const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr); \ vsprintf(s_szBuf, szFormat, argptr); \
va_end(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, ...) void wxLogTrace(wxTraceMask mask, const char *szFormat, ...)
{ {
wxLog *pLog = wxLog::GetActiveTarget(); wxLog *pLog = wxLog::GetActiveTarget();
@@ -188,7 +202,7 @@ void wxLogVerbose(const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr); vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr); va_end(argptr);
wxLog::OnLog(wxLOG_Trace, s_szBuf); wxLog::OnLog(wxLOG_Trace, s_szBuf, time(NULL));
} }
} }
@@ -209,7 +223,7 @@ void wxLogSysErrorHelper(long lErrCode)
sprintf(szErrMsg, _(" (error %ld: %s)"), lErrCode, wxSysErrorMsg(lErrCode)); sprintf(szErrMsg, _(" (error %ld: %s)"), lErrCode, wxSysErrorMsg(lErrCode));
strncat(s_szBuf, szErrMsg, WXSIZEOF(s_szBuf) - strlen(s_szBuf)); 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, ...) void WXDLLEXPORT wxLogSysError(const char *szFormat, ...)
@@ -246,8 +260,6 @@ wxLog::wxLog()
#else // release #else // release
m_bVerbose = FALSE; m_bVerbose = FALSE;
#endif // debug/release #endif // debug/release
m_szTimeFormat = "[%d/%b/%y %H:%M:%S] ";
} }
wxLog *wxLog::GetActiveTarget() wxLog *wxLog::GetActiveTarget()
@@ -292,54 +304,37 @@ wxLog *wxLog::SetActiveTarget(wxLog *pLogger)
return pOldLogger; return pOldLogger;
} }
wxString wxLog::TimeStamp() const void wxLog::RemoveTraceMask(const wxString& str)
{
int index = ms_aTraceMasks.Index(str);
if ( index != wxNOT_FOUND )
ms_aTraceMasks.Remove((size_t)index);
}
void wxLog::DoLog(wxLogLevel level, const char *szString, time_t t)
{ {
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;
time(&timeNow);
ptmNow = localtime(&timeNow);
strftime(szBuf, WXSIZEOF(szBuf), m_szTimeFormat, ptmNow);
str = szBuf;
}
*/
return str;
}
void wxLog::DoLog(wxLogLevel level, const char *szString)
{
// prepend a timestamp if not disabled
wxString str = TimeStamp();
switch ( level ) { switch ( level ) {
case wxLOG_FatalError: case wxLOG_FatalError:
DoLogString(str << _("Fatal error: ") << szString); DoLogString(str << _("Fatal error: ") << szString, t);
DoLogString(_("Program aborted.")); DoLogString(_("Program aborted."), t);
Flush(); Flush();
abort(); abort();
break; break;
case wxLOG_Error: case wxLOG_Error:
DoLogString(str << _("Error: ") << szString); DoLogString(str << _("Error: ") << szString, t);
break; break;
case wxLOG_Warning: case wxLOG_Warning:
DoLogString(str << _("Warning: ") << szString); DoLogString(str << _("Warning: ") << szString, t);
break; break;
case wxLOG_Info: case wxLOG_Info:
case wxLOG_Message: case wxLOG_Message:
if ( GetVerbose() ) if ( GetVerbose() )
DoLogString(str + szString); DoLogString(str + szString, t);
// fall through // fall through
case wxLOG_Status: case wxLOG_Status:
@@ -349,11 +344,7 @@ void wxLog::DoLog(wxLogLevel level, const char *szString)
case wxLOG_Trace: case wxLOG_Trace:
case wxLOG_Debug: case wxLOG_Debug:
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
// DoLogString(str << (level == wxLOG_Trace ? _("Trace") : _("Debug")) DoLogString(szString, t);
// << ": " << szString);
// JACS: we don't really want to prefix with 'Debug'. It's just extra
// verbiage.
DoLogString(szString);
#endif #endif
break; break;
@@ -363,7 +354,7 @@ void wxLog::DoLog(wxLogLevel level, const char *szString)
} }
} }
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.");
} }
@@ -385,7 +376,7 @@ wxLogStderr::wxLogStderr(FILE *fp)
m_fp = fp; m_fp = fp;
} }
void wxLogStderr::DoLogString(const char *szString) void wxLogStderr::DoLogString(const char *szString, time_t t)
{ {
wxString str(szString); wxString str(szString);
str << '\n'; str << '\n';
@@ -413,11 +404,11 @@ wxLogStream::wxLogStream(ostream *ostr)
m_ostr = ostr; 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
@@ -427,9 +418,7 @@ void wxLogStream::DoLogString(const char *szString)
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl) wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl)
// DLL mode in wxMSW, can't use it. #if !defined(NO_TEXT_WINDOW_STREAM)
#if defined(NO_TEXT_WINDOW_STREAM)
#else
: wxLogStream(new ostream(pTextCtrl)) : wxLogStream(new ostream(pTextCtrl))
#endif #endif
{ {
@@ -439,15 +428,22 @@ wxLogTextCtrl::~wxLogTextCtrl()
{ {
delete m_ostr; delete m_ostr;
} }
#endif #endif // wxUSE_STD_IOSTREAM
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxLogGui implementation // wxLogGui implementation (FIXME MT-unsafe)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxLogGui::wxLogGui() wxLogGui::wxLogGui()
{ {
m_bErrors = FALSE; Clear();
}
void wxLogGui::Clear()
{
m_bErrors = m_bWarnings = FALSE;
m_aMessages.Empty();
m_aTimes.Empty();
} }
void wxLogGui::Flush() void wxLogGui::Flush()
@@ -458,8 +454,6 @@ void wxLogGui::Flush()
// do it right now to block any new calls to Flush() while we're here // do it right now to block any new calls to Flush() while we're here
m_bHasMessages = FALSE; m_bHasMessages = FALSE;
// @@@ ugly...
// concatenate all strings (but not too many to not overfill the msg box) // concatenate all strings (but not too many to not overfill the msg box)
wxString str; wxString str;
size_t nLines = 0, size_t nLines = 0,
@@ -478,21 +472,31 @@ void wxLogGui::Flush()
str << m_aMessages[n - 1] << "\n"; str << m_aMessages[n - 1] << "\n";
} }
const char *title;
long style;
if ( m_bErrors ) { if ( m_bErrors ) {
wxMessageBox(str, _("Error"), wxOK | wxICON_EXCLAMATION); title = _("Error");
style = wxICON_STOP;
}
else if ( m_bWarnings ) {
title = _("Warning");
style = wxICON_EXCLAMATION;
} }
else { else {
wxMessageBox(str, _("Information"), wxOK | wxICON_INFORMATION); title = _("Information");
style = wxICON_INFORMATION;
} }
wxMessageBox(str, title, wxOK | style);
// no undisplayed messages whatsoever // no undisplayed messages whatsoever
m_bErrors = FALSE; Clear();
m_aMessages.Empty();
} }
// the default behaviour is to discard all informational messages if there // the default behaviour is to discard all informational messages if there
// are any errors/warnings. // 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 ) { switch ( level ) {
case wxLOG_Info: case wxLOG_Info:
@@ -500,6 +504,7 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString)
case wxLOG_Message: case wxLOG_Message:
if ( !m_bErrors ) { if ( !m_bErrors ) {
m_aMessages.Add(szString); m_aMessages.Add(szString);
m_aTimes.Add((long)t);
m_bHasMessages = TRUE; m_bHasMessages = TRUE;
} }
break; break;
@@ -524,22 +529,20 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString)
case wxLOG_Debug: case wxLOG_Debug:
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
{ {
wxString strTime = TimeStamp();
#ifdef __WXMSW__ #ifdef __WXMSW__
// don't prepend debug/trace here: it goes to the debug window // don't prepend debug/trace here: it goes to the
// anyhow, but do put a timestamp // debug window anyhow, but do put a timestamp
OutputDebugString(strTime + szString + "\n\r"); OutputDebugString(wxString(szString) + "\n\r");
#else #else
// send them to stderr // send them to stderr
fprintf(stderr, "%s %s: %s\n", fprintf(stderr, "%s: %s\n",
strTime.c_str(),
level == wxLOG_Trace ? "Trace" : "Debug", level == wxLOG_Trace ? "Trace" : "Debug",
szString); szString);
fflush(stderr); fflush(stderr);
#endif #endif
} }
#endif // __WXDEBUG__ #endif // __WXDEBUG__
break; break;
case wxLOG_FatalError: case wxLOG_FatalError:
@@ -548,15 +551,24 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString)
break; break;
case wxLOG_Error: case wxLOG_Error:
case wxLOG_Warning: // discard earlier informational messages if this is the 1st
// discard earlier informational messages if this is the 1st error // error because they might not make sense any more
if ( !m_bErrors ) { if ( !m_bErrors ) {
m_aMessages.Empty(); m_aMessages.Empty();
m_aTimes.Empty();
m_bHasMessages = TRUE; m_bHasMessages = TRUE;
m_bErrors = 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_aMessages.Add(szString);
m_aTimes.Add((long)t);
break; break;
default: default:
@@ -619,11 +631,8 @@ wxLogFrame::wxLogFrame(wxFrame *pParent, wxLogWindow *log, const char *szTitle)
{ {
m_log = log; 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, m_pTextCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition,
wxDefaultSize, wxDefaultSize,
//wxSIMPLE_BORDER |
wxTE_MULTILINE | wxTE_MULTILINE |
wxHSCROLL | wxHSCROLL |
wxTE_READONLY); wxTE_READONLY);
@@ -764,15 +773,15 @@ void wxLogWindow::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 // first let the previous logger show it
if ( m_pOldLog != NULL && m_bPassMessages ) { if ( m_pOldLog != NULL && m_bPassMessages ) {
// @@@ why can't we access protected wxLog method from here (we derive // FIXME why can't we access protected wxLog method from here (we derive
// from wxLog)? gcc gives "DoLog is protected in this context", what // 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 // does this mean? Anyhow, the cast is harmless and let's us do what
// we want. // we want.
((wxLogWindow *)m_pOldLog)->DoLog(level, szString); ((wxLogWindow *)m_pOldLog)->DoLog(level, szString, t);
} }
if ( m_pLogFrame ) { if ( m_pLogFrame ) {
@@ -781,9 +790,9 @@ void wxLogWindow::DoLog(wxLogLevel level, const char *szString)
// by default, these messages are ignored by wxLog, so process // by default, these messages are ignored by wxLog, so process
// them ourselves // them ourselves
{ {
wxString str = TimeStamp(); wxString str;
str << _("Status: ") << szString; str << _("Status: ") << szString;
DoLogString(str); DoLogString(str, t);
} }
break; break;
@@ -796,14 +805,14 @@ void wxLogWindow::DoLog(wxLogLevel level, const char *szString)
default: default:
// and this will format it nicely and call our DoLogString() // and this will format it nicely and call our DoLogString()
wxLog::DoLog(level, szString); wxLog::DoLog(level, szString, t);
} }
} }
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 // put the text into our window
wxTextCtrl *pText = m_pLogFrame->TextCtrl(); wxTextCtrl *pText = m_pLogFrame->TextCtrl();
@@ -851,10 +860,12 @@ wxLogWindow::~wxLogWindow()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// static variables // static variables
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxLog *wxLog::ms_pLogger = (wxLog *)NULL; wxLog *wxLog::ms_pLogger = (wxLog *)NULL;
bool wxLog::ms_doLog = TRUE; bool wxLog::ms_doLog = TRUE;
bool wxLog::ms_bAutoCreate = TRUE; bool wxLog::ms_bAutoCreate = TRUE;
wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0; wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0;
wxArrayString wxLog::ms_aTraceMasks;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// stdout error logging helper // stdout error logging helper
@@ -863,12 +874,12 @@ wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0;
// helper function: wraps the message and justifies it under given position // helper function: wraps the message and justifies it under given position
// (looks more pretty on the terminal). Also adds newline at the end. // (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 // 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?) // terminal window size (ok, I found it but does anybody really cares?)
#ifdef LOG_PRETTY_WRAP #ifdef LOG_PRETTY_WRAP
static void wxLogWrap(FILE *f, const char *pszPrefix, const char *psz) static void wxLogWrap(FILE *f, const char *pszPrefix, const char *psz)
{ {
size_t nMax = 80; // @@@@ size_t nMax = 80; // FIXME
size_t nStart = strlen(pszPrefix); size_t nStart = strlen(pszPrefix);
fputs(pszPrefix, f); fputs(pszPrefix, f);
@@ -904,7 +915,7 @@ unsigned long wxSysErrorCode()
#ifdef __WIN32__ #ifdef __WIN32__
return ::GetLastError(); return ::GetLastError();
#else //WIN16 #else //WIN16
// @@@@ what to do on Windows 3.1? // TODO what to do on Windows 3.1?
return 0; return 0;
#endif //WIN16/32 #endif //WIN16/32
#else //Unix #else //Unix
@@ -936,7 +947,7 @@ const char *wxSysErrorMsg(unsigned long nErrCode)
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
// returned string is capitalized and ended with '\r\n' - bad // returned string is capitalized and ended with '\r\n' - bad
s_szBuf[0] = (char)wxToLower(s_szBuf[0]); s_szBuf[0] = (char)tolower(s_szBuf[0]);
size_t len = strlen(s_szBuf); size_t len = strlen(s_szBuf);
if ( len > 0 ) { if ( len > 0 ) {
// truncate string // truncate string
@@ -946,7 +957,7 @@ const char *wxSysErrorMsg(unsigned long nErrCode)
return s_szBuf; return s_szBuf;
#else //Win16 #else //Win16
// TODO @@@@ // TODO
return NULL; return NULL;
#endif // Win16/32 #endif // Win16/32
#else // Unix #else // Unix
@@ -960,20 +971,21 @@ const char *wxSysErrorMsg(unsigned long nErrCode)
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
// break into the debugger
void Trap() void Trap()
{ {
#ifdef __WXMSW__ #ifdef __WXMSW__
DebugBreak(); DebugBreak();
#elif defined(__WXSTUBS__)
// TODO
#elif defined(__WXMAC__) #elif defined(__WXMAC__)
#if __powerc #if __powerc
Debugger(); Debugger();
#else #else
SysBreak(); SysBreak();
#endif #endif
#else // Unix #elif defined(__UNIX__)
raise(SIGTRAP); raise(SIGTRAP);
#else
// TODO
#endif // Win/Unix #endif // Win/Unix
} }
@@ -982,7 +994,7 @@ void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
{ {
// this variable can be set to true to suppress "assert failure" messages // this variable can be set to true to suppress "assert failure" messages
static bool s_bNoAsserts = FALSE; static bool s_bNoAsserts = FALSE;
static bool s_bInAssert = FALSE; static bool s_bInAssert = FALSE; // FIXME MT-unsafe
if ( s_bInAssert ) { if ( s_bInAssert ) {
// He-e-e-e-elp!! we're trapped in endless loop // He-e-e-e-elp!! we're trapped in endless loop
@@ -997,8 +1009,8 @@ void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
char szBuf[LOG_BUFFER_SIZE]; char szBuf[LOG_BUFFER_SIZE];
// make life easier for people using VC++ IDE: clicking on the message will // make life easier for people using VC++ IDE: clicking on the message
// take us immediately to the place of the failed assert // will take us immediately to the place of the failed assert
#ifdef __VISUALC__ #ifdef __VISUALC__
sprintf(szBuf, "%s(%d): assert failed", szFile, nLine); sprintf(szBuf, "%s(%d): assert failed", szFile, nLine);
#else // !VC++ #else // !VC++
@@ -1021,6 +1033,8 @@ void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
#if wxUSE_NOGUI #if wxUSE_NOGUI
Trap(); Trap();
#else #else
// this message is intentionally not translated - it is for
// developpers only
strcat(szBuf, "\nDo you want to stop the program?" strcat(szBuf, "\nDo you want to stop the program?"
"\nYou can also choose [Cancel] to suppress " "\nYou can also choose [Cancel] to suppress "
"further warnings."); "further warnings.");

View File

@@ -359,28 +359,6 @@ wxString wxNow( void )
return wxString(date); return wxString(date);
} }
/* Get Full RFC822 style email address */
bool
wxGetEmailAddress (char *address, int maxSize)
{
char host[65];
char user[65];
if (wxGetHostName(host, 64) == FALSE)
return FALSE;
if (wxGetUserId(user, 64) == FALSE)
return FALSE;
char tmp[130];
strcpy(tmp, user);
strcat(tmp, "@");
strcat(tmp, host);
strncpy(address, tmp, maxSize - 1);
address[maxSize-1] = '\0';
return TRUE;
}
/* /*
* Strip out any menu codes * Strip out any menu codes
*/ */
@@ -822,37 +800,81 @@ int isascii( int c )
} }
#endif #endif
bool wxGetUserId(wxString& buf) // ----------------------------------------------------------------------------
// network and user id functions
// ----------------------------------------------------------------------------
// Get Full RFC822 style email address
bool wxGetEmailAddress(char *address, int maxSize)
{ {
bool success = wxGetUserId(wxBuffer, 500); wxString email = wxGetEmailAddress();
if (success) if ( !email )
{ return FALSE;
buf = wxBuffer;
strncpy(address, email, maxSize - 1);
address[maxSize - 1] = '\0';
return TRUE; return TRUE;
} }
else
return FALSE; wxString wxGetEmailAddress()
{
wxString email;
wxString host = wxGetHostName();
if ( !!host )
{
wxString user = wxGetUserId();
if ( !!user )
{
wxString email(user);
email << '@' << host;
}
} }
bool wxGetUserName(wxString& buf) return email;
{
bool success = wxGetUserName(wxBuffer, 500);
if (success)
{
buf = wxBuffer;
return TRUE;
}
else
return FALSE;
} }
bool wxGetHostName(wxString& buf) wxString wxGetUserId()
{
static const int maxLoginLen = 256; // FIXME arbitrary number
wxString buf;
bool ok = wxGetUserId(buf.GetWriteBuf(maxLoginLen), maxLoginLen);
buf.UngetWriteBuf();
if ( !ok )
buf.Empty();
return buf;
}
wxString wxGetUserName()
{
static const int maxUserNameLen = 1024; // FIXME arbitrary number
wxString buf;
bool ok = wxGetUserName(buf.GetWriteBuf(maxUserNameLen), maxUserNameLen);
buf.UngetWriteBuf();
if ( !ok )
buf.Empty();
return buf;
}
wxString wxGetHostName()
{ {
static const size_t hostnameSize = 257; static const size_t hostnameSize = 257;
wxString buf;
bool ok = wxGetHostName(buf.GetWriteBuf(hostnameSize), hostnameSize); bool ok = wxGetHostName(buf.GetWriteBuf(hostnameSize), hostnameSize);
buf.UngetWriteBuf(); buf.UngetWriteBuf();
return ok; if ( !ok )
buf.Empty();
return buf;
} }

View File

@@ -109,7 +109,7 @@ bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent& event) const
int accKeyCode = GetKeyCode(); int accKeyCode = GetKeyCode();
int accKeyCode2 = GetKeyCode(); int accKeyCode2 = GetKeyCode();
if (isascii(accKeyCode2)) if (isascii(accKeyCode2))
accKeyCode2 = wxToLower(accKeyCode2); accKeyCode2 = tolower(accKeyCode2);
return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) && return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) &&
(eventShiftDown == accShiftDown) && (eventShiftDown == accShiftDown) &&

View File

@@ -110,9 +110,9 @@ void wxUsleep(unsigned long milliseconds)
// process management // process management
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
int wxKill(long pid, int sig) int wxKill(long pid, wxSignal sig)
{ {
return kill(pid, sig); return kill(pid, (int)sig);
} }
#define WXEXECUTE_NARGS 127 #define WXEXECUTE_NARGS 127
@@ -350,7 +350,7 @@ char *wxGetUserHome( const wxString &user )
{ {
struct passwd *who = (struct passwd *) NULL; struct passwd *who = (struct passwd *) NULL;
if (user.IsNull() || (user== "")) if ( !user )
{ {
register char *ptr; register char *ptr;
@@ -378,12 +378,15 @@ char *wxGetUserHome( const wxString &user )
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// id routines // network and user id routines
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxGetHostName(char *buf, int sz) // retrieve either the hostname or FQDN depending on platform (caller must
// check whether it's one or the other, this is why this function is for
// private use only)
static bool wxGetHostNameInternal(char *buf, int sz)
{ {
wxCHECK_MSG( buf, FALSE, "NULL pointer in wxGetHostName" ); wxCHECK_MSG( buf, FALSE, "NULL pointer in wxGetHostNameInternal" );
*buf = '\0'; *buf = '\0';
@@ -398,11 +401,11 @@ bool wxGetHostName(char *buf, int sz)
} }
#elif defined(HAVE_GETHOSTNAME) #elif defined(HAVE_GETHOSTNAME)
bool ok = gethostname(buf, sz) != -1; bool ok = gethostname(buf, sz) != -1;
#else #else // no uname, no gethostname
wxFAIL_MSG("don't know host name for this machibe"); wxFAIL_MSG("don't know host name for this machibe");
bool ok = FALSE; bool ok = FALSE;
#endif #endif // uname/gethostname
if ( !ok ) if ( !ok )
{ {
@@ -412,6 +415,52 @@ bool wxGetHostName(char *buf, int sz)
return ok; return ok;
} }
bool wxGetHostName(char *buf, int sz)
{
bool ok = wxGetHostNameInternal(buf, sz);
if ( ok )
{
// BSD systems return the FQDN, we only want the hostname, so extract
// it (we consider that dots are domain separators)
char *dot = strchr(buf, '.');
if ( dot )
{
// nuke it
*dot = '\0';
}
}
return ok;
}
bool wxGetFullHostName(char *buf, int sz)
{
bool ok = wxGetHostNameInternal(buf, sz);
if ( ok )
{
if ( !strchr(buf, '.') )
{
struct hostent *host = gethostbyname(buf);
if ( !host )
{
wxLogSysError(_("Cannot get the official hostname"));
ok = FALSE;
}
else
{
// the canonical name
strncpy(buf, host->h_name, sz);
}
}
//else: it's already a FQDN (BSD behaves this way)
}
return ok;
}
bool wxGetUserId(char *buf, int sz) bool wxGetUserId(char *buf, int sz)
{ {
struct passwd *who; struct passwd *who;
@@ -473,14 +522,3 @@ void wxFatalError( const wxString &msg, const wxString &title )
exit(3); // the same exit code as for abort() exit(3); // the same exit code as for abort()
} }
//------------------------------------------------------------------------
// directory routines
//------------------------------------------------------------------------
bool wxDirExists( const wxString& dir )
{
char buf[500];
strcpy( buf, WXSTRINGCAST(dir) );
struct stat sbuf;
return ((stat(buf, &sbuf) != -1) && S_ISDIR(sbuf.st_mode) ? TRUE : FALSE);
}