1. corrections for compilation of the wxBase apps with wxApp

2. wxCAL_NO_MONTH/YEAR_CHANGE styles implemented, cosmetic corrections
3. attempt at BC++ compilation fix


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5203 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-01-03 17:51:24 +00:00
parent 44762a6a87
commit bc385ba9eb
9 changed files with 381 additions and 55 deletions

View File

@@ -26,6 +26,7 @@
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/debug.h"
#include "wx/filefn.h"
#endif
#include "wx/module.h"
@@ -49,6 +50,13 @@ public:
virtual int OnRun() { wxFAIL_MSG(wxT("unreachable")); return 0; }
};
// ----------------------------------------------------------------------------
// private functions
// ----------------------------------------------------------------------------
static bool DoInit();
static void DoCleanUp();
// ----------------------------------------------------------------------------
// private vars
// ----------------------------------------------------------------------------
@@ -96,10 +104,7 @@ bool WXDLLEXPORT wxInitialize()
wxASSERT_MSG( !wxTheApp,
wxT("either call wxInitialize or create app, not both!") );
wxClassInfo::InitializeClasses();
wxModule::RegisterModules();
if ( !wxModule::InitializeModules() )
if ( !DoInit() )
{
return FALSE;
}
@@ -120,12 +125,110 @@ void WXDLLEXPORT wxUninitialize()
{
if ( !--gs_nInitCount )
{
wxModule::CleanUpModules();
wxClassInfo::CleanUpClasses();
// delete the application object
delete wxTheApp;
wxTheApp = (wxApp *)NULL;
DoCleanUp();
}
}
int wxEntry(int argc, char **argv)
{
// library initialization
if ( !DoInit() )
{
return -1;
}
// create the app
if ( !wxTheApp )
{
wxCHECK_MSG( wxApp::GetInitializerFunction(), -1,
wxT("No application object: use IMPLEMENT_APP macro.") );
wxAppInitializerFunction fnCreate = wxApp::GetInitializerFunction();
wxTheApp = (wxApp *)fnCreate();
}
wxCHECK_MSG( wxTheApp, -1, wxT("wxWindows error: no application object") );
// app preinitialization
wxTheApp->argc = argc;
#if wxUSE_UNICODE
wxTheApp->argv = new wxChar*[argc+1];
int mb_argc = 0;
while (mb_argc < argc)
{
wxTheApp->argv[mb_argc] = wxStrdup(wxConvLibc.cMB2WX(argv[mb_argc]));
mb_argc++;
}
wxTheApp->argv[mb_argc] = (wxChar *)NULL;
#else
wxTheApp->argv = argv;
#endif
wxString name = wxFileNameFromPath(argv[0]);
wxStripExtension(name);
wxTheApp->SetAppName(name);
int retValue = 0;
// app initialization
if ( !wxTheApp->OnInit() )
retValue = -1;
// app execution
if ( retValue == 0 )
{
retValue = wxTheApp->OnRun();
// app clean up
wxTheApp->OnExit();
}
// library clean up
DoCleanUp();
return retValue;
}
// ----------------------------------------------------------------------------
// private functions
// ----------------------------------------------------------------------------
static bool DoInit()
{
wxClassInfo::InitializeClasses();
wxModule::RegisterModules();
if ( !wxModule::InitializeModules() )
{
return FALSE;
}
return TRUE;
}
static void DoCleanUp()
{
#if wxUSE_LOG
// flush the logged messages if any
wxLog *log = wxLog::GetActiveTarget();
if (log != NULL && log->HasPendingMessages())
log->Flush();
// continuing to use user defined log target is unsafe from now on because
// some resources may be already unavailable, so replace it by something
// more safe
wxLog *oldlog = wxLog::SetActiveTarget(new wxLogStderr);
if ( oldlog )
delete oldlog;
#endif // wxUSE_LOG
wxModule::CleanUpModules();
wxClassInfo::CleanUpClasses();
// delete the application object
delete wxTheApp;
wxTheApp = (wxApp *)NULL;
}

View File

@@ -178,7 +178,7 @@ private:
const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 index) const
{ return (const char *)(m_pData + Swap(pTable[index].ofsString)); }
// convert encoding to platform native one, if neccessary
void ConvertEncoding();
@@ -478,27 +478,33 @@ void wxMsgCatalog::ConvertEncoding()
const char *hdr = StringAtOfs(m_pOrigTable, 0);
if (hdr == NULL) return; // not supported by this catalog, does not have non-fuzzy header
if (hdr[0] != 0) return; // ditto
/* we support catalogs with header (msgid "") that is _not_ marked as "#, fuzzy" (otherwise
the string would not be included into compiled catalog) */
wxString header(StringAtOfs(m_pTransTable, 0));
wxString charset;
int pos = header.Find("Content-Type: text/plain; charset=");
if (pos == -1) return; // incorrectly filled Content-Type header
pos += 34 ; /*strlen("Content-Type: text/plain; charset=")*/
while (header[pos] != '\n') charset << header[pos++];
if ((enc = wxTheFontMapper -> CharsetToEncoding(charset, FALSE)) == wxFONTENCODING_SYSTEM) return;
if (pos == wxNOT_FOUND)
return; // incorrectly filled Content-Type header
size_t n = pos + 34; /*strlen("Content-Type: text/plain; charset=")*/
while (header[n] != '\n')
charset << header[n++];
enc = wxTheFontMapper->CharsetToEncoding(charset, FALSE);
if ( enc == wxFONTENCODING_SYSTEM )
return; // unknown encoding
wxFontEncodingArray a = wxEncodingConverter::GetPlatformEquivalents(enc);
if (a[0] == enc) return; // no conversion needed, locale uses native encoding
if (a.GetCount() == 0) return; // we don't know common equiv. under this platform
if (a[0] == enc)
return; // no conversion needed, locale uses native encoding
if (a.GetCount() == 0)
return; // we don't know common equiv. under this platform
wxEncodingConverter converter;
converter.Init(enc, a[0]);
for (unsigned i = 0; i < m_numStrings; i++)
for (size_t i = 0; i < m_numStrings; i++)
converter.Convert((char*)StringAtOfs(m_pTransTable, i));
#endif
}

View File

@@ -1040,3 +1040,37 @@ wxString wxGetHomeDir()
return home;
}
#if 0
wxString wxGetCurrentDir()
{
wxString dir;
size_t len = 1024;
bool ok;
do
{
ok = getcwd(dir.GetWriteBuf(len + 1), len) != NULL;
dir.UngetWriteBuf();
if ( !ok )
{
if ( errno != ERANGE )
{
wxLogSysError(_T("Failed to get current directory"));
return wxEmptyString;
}
else
{
// buffer was too small, retry with a larger one
len *= 2;
}
}
//else: ok
} while ( !ok );
return dir;
}
#endif // 0