WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
-// ----------------------------------------------------------------------------
-// wxMBConvFile (for conversion to filenames)
-// ----------------------------------------------------------------------------
-
-class WXDLLEXPORT wxMBConvFile : public wxMBConv
-{
-public:
- virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
- virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
-};
-
-WXDLLEXPORT_DATA(extern wxMBConvFile) wxConvFile;
-
// ----------------------------------------------------------------------------
// wxMBConvUTF7 (for conversion using UTF7 encoding)
// ----------------------------------------------------------------------------
bool m_deferred;
};
+#define wxConvFile wxConvLocal
WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
// identical to c_str()
const wxChar* GetData() const { return m_pchData; }
+ // conversion to plain ascii: this is usefull for
+ // converting numbers or strings which are certain
+ // not to contain special chars (typically system
+ // functions, X atoms, environment variables etc.)
+#if wxUSE_UNICODE
+ static wxString FromAscii( char *ascii );
+ const wxCharBuffer ToAscii() const;
+#else
+ static wxString FromAscii( char *ascii ) { return wxString( ascii ); }
+ const char *ToAscii() const { return m_pchData; }
+#endif
+
// conversions with (possible) format convertions: have to return a
// buffer with temporary data
//
if ( ::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) != 0 )
return FALSE;
#else // !Win32
- wxStructStat fbuf;
+ wxStructStat fbuf;
// get permissions of file1
- if ( wxStat( file1, &fbuf) != 0 )
+ if ( wxStat( file1.c_str(), &fbuf) != 0 )
{
// the file probably doesn't exist or we haven't the rights to read
// from it anyhow
// create file2 with the same permissions than file1 and open it for
// writing
+
wxFile fileOut;
if ( !fileOut.Create(file2, overwrite, fbuf.st_mode & 0777) )
return FALSE;
wxString buf;
buf.Printf(wxT("%s %s HTTP/1.0\r\n"), request, path.c_str());
- const wxWX2MBbuf pathbuf = wxConvLibc.cWX2MB(buf);
+ const wxWX2MBbuf pathbuf = wxConvLocal.cWX2MB(buf);
Write(pathbuf, strlen(wxMBSTRINGCAST pathbuf));
SendHeaders();
Write("\r\n", 2);
int mb_argc = 0;
while (mb_argc < argc)
{
- wxTheApp->argv[mb_argc] = wxStrdup(wxConvLibc.cMB2WX(argv[mb_argc]));
+ wxTheApp->argv[mb_argc] = wxStrdup(wxConvLocal.cMB2WX(argv[mb_argc]));
mb_argc++;
}
wxTheApp->argv[mb_argc] = (wxChar *)NULL;
}
else
{
- encname = wxConvLibc.cMB2WX(alang);
+ encname = wxString::FromAscii( alang );
}
}
else
// if we can't get at the character set directly, try to see if it's in
// the environment variables (in most cases this won't work, but I was
// out of ideas)
- wxChar *lang = wxGetenv(wxT("LC_ALL"));
- wxChar *dot = lang ? wxStrchr(lang, wxT('.')) : (wxChar *)NULL;
+ char *lang = getenv( "LC_ALL");
+ char *dot = lang ? strchr(lang, '.') : (char *)NULL;
if (!dot)
{
- lang = wxGetenv(wxT("LC_CTYPE"));
+ lang = getenv( "LC_CTYPE" );
if ( lang )
- dot = wxStrchr(lang, wxT('.'));
+ dot = strchr(lang, '.' );
}
if (!dot)
{
- lang = wxGetenv(wxT("LANG"));
+ lang = getenv( "LANG");
if ( lang )
- dot = wxStrchr(lang, wxT('.'));
+ dot = strchr(lang, '.');
}
if ( dot )
{
- encname = dot+1;
+ encname = wxString::FromAscii( dot+1 );
}
}
#endif // Win32/Unix
// wxMBConv
// ----------------------------------------------------------------------------
+#define IGNORE_LIBC 0
+
size_t wxMBConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
{
+#if IGNORE_LIBC
+ if (buf)
+ {
+ for (size_t i = 0; i < strlen( psz )+1; i++)
+ buf[i] = (wchar_t) psz[i];
+ // printf( "libc %s\n", buf );
+ return strlen( psz );
+ }
+ else
+ {
+ return strlen( psz );
+ }
+#else
return wxMB2WC(buf, psz, n);
+#endif
}
size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
{
+#if IGNORE_LIBC
+ if (buf)
+ {
+ for (size_t i = 0; i < wxStrlen( psz )+1; i++)
+ buf[i] = (char) psz[i];
+ // printf( "libc %s\n", buf );
+ return wxStrlen( psz );
+ }
+ else
+ {
+ return wxStrlen( psz );
+ }
+#else
return wxWC2MB(buf, psz, n);
+#endif
}
const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const
return wxCharBuffer((char *) NULL);
wxCharBuffer buf(nLen); // this allocates nLen+1
WC2MB((char *)(const char *) buf, psz, nLen+1);
+ // printf( "str %s\n", (const char*) buf );
return buf;
}
else
return wxCharBuffer((char *) NULL);
}
-// ----------------------------------------------------------------------------
-// standard file conversion
-// ----------------------------------------------------------------------------
-
-WXDLLEXPORT_DATA(wxMBConvFile) wxConvFile;
-
-// just use the libc conversion for now
-size_t wxMBConvFile::MB2WC(wchar_t *buf, const char *psz, size_t n) const
-{
- return wxMB2WC(buf, psz, n);
-}
-
-size_t wxMBConvFile::WC2MB(char *buf, const wchar_t *psz, size_t n) const
-{
- return wxWC2MB(buf, psz, n);
-}
-
// ----------------------------------------------------------------------------
// standard gdk conversion
// ----------------------------------------------------------------------------
{
wxString name = wxLocale::GetSystemEncodingName();
if ( !name.empty() )
+ {
SetName(name);
+ }
}
// wxGetCharacterSet() complains about NULL name
// other common string functions
// ===========================================================================
+#if wxUSE_UNICODE
+wxString wxString::FromAscii( char *ascii )
+{
+ if (!ascii)
+ return wxEmptyString;
+
+ size_t len = strlen( ascii );
+ wxString res;
+ res.AllocBuffer( len );
+ wchar_t *dest = (wchar_t*)(const wchar_t*) res.c_str();
+
+ for (size_t i = 0; i < len+1; i++)
+ dest[i] = (wchar_t) ascii[i];
+
+ return res;
+}
+
+const wxCharBuffer wxString::ToAscii() const
+{
+ if (IsNull())
+ return wxCharBuffer( (const char*)NULL );
+
+ size_t len = Len();
+ wxCharBuffer buffer( len ); // allocates len+1
+
+ char *dest = (char*)(const char*) buffer;
+
+ for (size_t i = 0; i < len+1; i++)
+ {
+ if (m_pchData[i] > 127)
+ dest[i] = '_';
+ else
+ dest[i] = (char) m_pchData[i];
+ }
+
+ return buffer;
+}
+#endif
+
// ---------------------------------------------------------------------------
// simple sub-string extraction
// ---------------------------------------------------------------------------
#ifndef wxSetlocale
WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale)
{
- char *localeOld = setlocale(category, wxConvLibc.cWX2MB(locale));
+ char *localeOld = setlocale(category, wxConvLocal.cWX2MB(locale));
- return wxWCharBuffer(wxConvLibc.cMB2WC(localeOld));
+ return wxWCharBuffer(wxConvLocal.cMB2WC(localeOld));
}
#endif
}
wxString data(nptr, nptr-start);
- wxWX2MBbuf dat = data.mb_str(wxConvLibc);
+ wxWX2MBbuf dat = data.mb_str(wxConvLocal);
char *rdat = wxMBSTRINGCAST dat;
double ret = strtod(dat, &rdat);
(wxIsalpha(*nptr) && (wxToupper(*nptr) - wxT('A') + 10 < base))) nptr++;
wxString data(nptr, nptr-start);
- wxWX2MBbuf dat = data.mb_str(wxConvLibc);
+ wxWX2MBbuf dat = data.mb_str(wxConvLocal);
char *rdat = wxMBSTRINGCAST dat;
long int ret = strtol(dat, &rdat, base);
#ifdef wxNEED_WX_STDIO_H
WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode)
{
- return fopen( wxConvFile.cWX2MB(path), wxConvLibc.cWX2MB(mode) );
+ char mode_buffer[10];
+ for (size_t i = 0; i < wxStrlen(mode)+1; i++)
+ mode_buffer[i] = (char) mode[i];
+
+ return fopen( wxConvFile.cWX2MB(path), mode_buffer );
}
WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream)
{
- return freopen( wxConvFile.cWX2MB(path), wxConvLibc.cWX2MB(mode), stream );
+ char mode_buffer[10];
+ for (size_t i = 0; i < wxStrlen(mode)+1; i++)
+ mode_buffer[i] = (char) mode[i];
+
+ return freopen( wxConvFile.cWX2MB(path), mode_buffer, stream );
}
WXDLLEXPORT int wxRemove(const wxChar *path)
#ifndef wxAtof
double WXDLLEXPORT wxAtof(const wxChar *psz)
{
- return atof(wxConvLibc.cWX2MB(psz));
+ return atof(wxConvLocal.cWX2MB(psz));
}
#endif
#ifdef wxNEED_WX_STDLIB_H
int WXDLLEXPORT wxAtoi(const wxChar *psz)
{
- return atoi(wxConvLibc.cWX2MB(psz));
+ return atoi(wxConvLocal.cWX2MB(psz));
}
long WXDLLEXPORT wxAtol(const wxChar *psz)
{
- return atol(wxConvLibc.cWX2MB(psz));
+ return atol(wxConvLocal.cWX2MB(psz));
}
wxChar * WXDLLEXPORT wxGetenv(const wxChar *name)
{
// nope, retrieve it,
#if wxUSE_UNICODE
- wxCharBuffer buffer = wxConvLibc.cWX2MB(name);
+ wxCharBuffer buffer = wxConvLocal.cWX2MB(name);
// printf( "buffer %s\n", (const char*) buffer );
const char *val = getenv( (const char *)buffer );
#else
// convert it,
#ifdef wxUSE_UNICODE
- data = (wxObject *)new wxString(val, wxConvLibc);
+ data = (wxObject *)new wxString(val, wxConvLocal);
#else
data = (wxObject *)new wxString(val);
#endif
return (wxChar *)((wxString *)data)->c_str();
}
-int WXDLLEXPORT wxSystem(const wxChar *psz)
+int WXDLLEXPORT wxSystem(const wxChar *psz)
{
- return system(wxConvLibc.cWX2MB(psz));
+ return system(wxConvLocal.cWX2MB(psz));
}
#endif
#ifdef wxNEED_WX_TIME_H
WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const struct tm *tm)
{
- if (!max) return 0;
- char *buf = (char *)malloc(max);
- size_t ret = strftime(buf, max, wxConvLibc.cWX2MB(fmt), tm);
- if (ret) {
- wxStrcpy(s, wxConvLibc.cMB2WX(buf));
- free(buf);
- return wxStrlen(s);
- } else {
- free(buf);
- *s = 0;
- return 0;
+ if (!max) return 0;
+
+ char *buf = (char *)malloc(max);
+ size_t ret = strftime(buf, max, wxConvLocal.cWX2MB(fmt), tm);
+ if (ret)
+ {
+ wxStrcpy(s, wxConvLocal.cMB2WX(buf));
+ free(buf);
+ return wxStrlen(s);
+ }
+ else
+ {
+ free(buf);
+ *s = 0;
+ return 0;
}
}
#endif
wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
#ifdef __WXGTK20__
- int dpi = GetResolution() * 2;
+ int dpi = GetResolution() * 2;
+ dpi = 300;
+
PangoContext *context = pango_ft2_get_context ( dpi, dpi );
+
// What are these for?
pango_context_set_language (context, pango_language_from_string ("en_US"));
#endif
pango_layout_set_text( layout, (const char*) buffer, strlen(buffer) );
-#if 1
+#if 0
double xx = LogicalToDeviceX(x);
double yy = LogicalToDeviceY(y /*+ bitmap.GetHeight()*/ );
#include "wx/settings.h"
#include "wx/dialog.h"
#include "wx/msgdlg.h"
+#include "wx/file.h"
#if wxUSE_WX_RESOURCES
#include "wx/resource.h"
#include "wx/settings.h"
#include "wx/dialog.h"
#include "wx/msgdlg.h"
+#include "wx/file.h"
#if wxUSE_WX_RESOURCES
#include "wx/resource.h"