diff --git a/include/wx/filefn.h b/include/wx/filefn.h index b1df9ded52..57260c5fe3 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -119,13 +119,11 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; #endif // O_RDONLY #else // functions - #define wxOpen open #define wxClose close #define wxRead read #define wxWrite write #define wxLseek lseek #define wxFsync commit - #define wxAccess access #define wxEof eof #define wxMkDir mkdir @@ -133,10 +131,18 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; #define wxTell(fd) lseek(fd, 0, SEEK_CUR) - #define wxStat stat - - // types #define wxStructStat struct stat + +#if wxUSE_UNICODE +# define wxNEED_WX_UNISTD_H +WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf ); +WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode ); +WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode ); +#else + #define wxOpen open + #define wxStat stat + #define wxAccess access +#endif #endif // VC++ diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 45703a7f3d..b2943926a1 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -78,6 +78,8 @@ bool MyApp::OnInit(void) g_printData = new wxPrintData; g_pageSetupData = new wxPageSetupDialogData; + + // wxGetenv( wxT("HOME") ); // Compatibility with old system. In fact, we might keep wxThePrintSetupData // just for useful default values which we can optionally assign to our @@ -307,11 +309,18 @@ void MyFrame::Draw(wxDC& dc) dc.SetPen(* wxRED_PEN); dc.DrawRectangle(0, 30, 200, 100); - dc.DrawText("Rectangle 200 by 100", 40, 40); + + dc.DrawText( wxT("Rectangle 200 by 100"), 40, 40); dc.DrawEllipse(50, 140, 100, 50); - dc.DrawText("Test message: this is in 10 point text", 10, 180); + dc.DrawText( wxT("Test message: this is in 10 point text"), 10, 180); + +#if wxUSE_UNICODE + char *test = "Greek (Ελληνικά) Γειά σας -- Hebrew שלום -- Japanese (日本語)"; + wxString tmp = wxConvUTF8.cMB2WC( test ); + dc.DrawText( tmp, 10, 200 ); +#endif dc.SetPen(* wxBLACK_PEN); dc.DrawLine(0, 0, 200, 200); @@ -365,8 +374,8 @@ bool MyPrintout::OnPrintPage(int page) dc->SetDeviceOrigin(0, 0); dc->SetUserScale(1.0, 1.0); - char buf[200]; - sprintf(buf, "PAGE %d", page); + wxChar buf[200]; + wxSprintf(buf, wxT("PAGE %d"), page); dc->DrawText(buf, 10, 10); return TRUE; @@ -483,10 +492,11 @@ void MyPrintout::DrawPageTwo(wxDC *dc) dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250); dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits)); + return; + dc->SetFont(* wxGetApp().m_testFont); dc->SetBackgroundMode(wxTRANSPARENT); - dc->DrawText("Some test text", 200, 200 ); { // GetTextExtent demo: wxString words[7] = {"This ", "is ", "GetTextExtent ", "testing ", "string. ", "Enjoy ", "it!"}; @@ -504,6 +514,8 @@ void MyPrintout::DrawPageTwo(wxDC *dc) dc->SetFont(* wxGetApp().m_testFont); } + dc->DrawText("Some test text", 200, 300 ); + // TESTING int leftMargin = 20; diff --git a/src/common/file.cpp b/src/common/file.cpp index af237f6a89..99582fae28 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -153,18 +153,9 @@ bool wxFile::Exists(const wxChar *name) { wxStructStat st; -#if wxUSE_UNICODE && wxMBFILES - wxCharBuffer fname = wxConvFile.cWC2MB(name); - - return !wxAccess(fname, 0) && - !wxStat(wxMBSTRINGCAST fname, &st) && - (st.st_mode & S_IFREG); - -#else return !wxAccess(name, 0) && !wxStat(name, &st) && (st.st_mode & S_IFREG); -#endif } bool wxFile::Access(const wxChar *name, OpenMode mode) @@ -184,7 +175,7 @@ bool wxFile::Access(const wxChar *name, OpenMode mode) wxFAIL_MSG(wxT("bad wxFile::Access mode parameter.")); } - return wxAccess(wxFNCONV(name), how) == 0; + return wxAccess( name, how) == 0; } // ---------------------------------------------------------------------------- @@ -206,20 +197,22 @@ bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode) // if bOverwrite we create a new file or truncate the existing one, // otherwise we only create the new file and fail if it already exists #if defined(__WXMAC__) && !defined(__UNIX__) - // Dominic Mazzoni [dmazzoni+@cs.cmu.edu] reports that open is still broken on the mac, so we replace - // int fd = open(wxUnix2MacFilename( szFileName ), O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access); - int fd = creat( szFileName , accessMode); + // Dominic Mazzoni [dmazzoni+@cs.cmu.edu] reports that open is still broken on the mac, so we replace + // int fd = open(wxUnix2MacFilename( szFileName ), O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access); + int fd = creat( szFileName , accessMode); #else - int fd = wxOpen(wxFNCONV(szFileName), - O_BINARY | O_WRONLY | O_CREAT | - (bOverwrite ? O_TRUNC : O_EXCL) - ACCESS(accessMode)); + int fd = wxOpen( szFileName, + O_BINARY | O_WRONLY | O_CREAT | + (bOverwrite ? O_TRUNC : O_EXCL) + ACCESS(accessMode) ); #endif - if ( fd == -1 ) { + if ( fd == -1 ) + { wxLogSysError(_("can't create file '%s'"), szFileName); return FALSE; } - else { + else + { Attach(fd); return TRUE; } @@ -230,7 +223,8 @@ bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode) { int flags = O_BINARY; - switch ( mode ) { + switch ( mode ) + { case read: flags |= O_RDONLY; break; @@ -257,8 +251,9 @@ bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode) break; } - int fd = wxOpen(wxFNCONV(szFileName), flags ACCESS(accessMode)); - if ( fd == -1 ) { + int fd = wxOpen( szFileName, flags ACCESS(accessMode)); + if ( fd == -1 ) + { wxLogSysError(_("can't open file '%s'"), szFileName); return FALSE; } diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 8fd501fe1d..8650b3338d 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -68,6 +68,7 @@ #ifdef __UNIX__ #include #include + #include #endif #ifdef __WXPM__ @@ -150,8 +151,6 @@ # include "FSpCompat.h" #endif -IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList) - // ---------------------------------------------------------------------------- // private globals // ---------------------------------------------------------------------------- @@ -178,6 +177,32 @@ const off_t wxInvalidOffset = (off_t)-1; // implementation // ============================================================================ +#ifdef wxNEED_WX_UNISTD_H + +WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf ) +{ + return stat( wxConvFile.cWX2MB( file_name ), buf ); +} + +WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode ) +{ + return access( wxConvFile.cWX2MB( pathname ), mode ); +} + +WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode ) +{ + return open( wxConvFile.cWX2MB( pathname ), flags, mode ); +} + +#endif + // wxNEED_WX_UNISTD_H + +// ---------------------------------------------------------------------------- +// wxPathList +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList) + void wxPathList::Add (const wxString& path) { wxStringList::Add (WXSTRINGCAST path); @@ -308,7 +333,7 @@ wxFileExists (const wxString& filename) return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY); #else wxStructStat stbuf; - if ( !filename.empty() && wxStat (OS_FILENAME(filename), &stbuf) == 0 ) + if ( !filename.empty() && wxStat( filename, &stbuf) == 0 ) return TRUE; return FALSE; @@ -1090,7 +1115,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) wxStructStat fbuf; // get permissions of file1 - if ( wxStat(OS_FILENAME(file1), &fbuf) != 0 ) + if ( wxStat( file1, &fbuf) != 0 ) { // the file probably doesn't exist or we haven't the rights to read // from it anyhow @@ -1279,12 +1304,10 @@ bool wxPathExists(const wxChar *pszPathName) wxStructStat st; #ifndef __VISAGECPP__ - return wxStat(wxFNSTRINGCAST strPath.fn_str(), &st) == 0 && - ((st.st_mode & S_IFMT) == S_IFDIR); + return wxStat(pszPathName, &st) == 0 && ((st.st_mode & S_IFMT) == S_IFDIR); #else // S_IFMT not supported in VA compilers.. st_mode is a 2byte value only - return wxStat(wxFNSTRINGCAST strPath.fn_str(), &st) == 0 && - (st.st_mode == S_IFDIR); + return wxStat(pszPathName, &st) == 0 && (st.st_mode == S_IFDIR); #endif #endif // __WIN32__/!__WIN32__ @@ -1620,8 +1643,8 @@ void WXDLLEXPORT wxSplitPath(const wxChar *pszFileName, time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename) { wxStructStat buf; - - wxStat(filename.fn_str(), &buf); + wxStat( filename, &buf); + return buf.st_mtime; } diff --git a/src/common/filename.cpp b/src/common/filename.cpp index cac48112e5..b639fda809 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -1660,7 +1660,7 @@ bool wxFileName::GetTimes(wxDateTime *dtAccess, { #if defined(__UNIX_LIKE__) || defined(__WXMAC__) || (defined(__DOS__) && defined(__WATCOMC__)) wxStructStat stBuf; - if ( wxStat(GetFullPath().fn_str(), &stBuf) == 0 ) + if ( wxStat( GetFullPath().c_str(), &stBuf) == 0 ) { if ( dtAccess ) dtAccess->Set(stBuf.st_atime); diff --git a/src/common/wxchar.cpp b/src/common/wxchar.cpp index 8faa0c6eab..657a0554c2 100644 --- a/src/common/wxchar.cpp +++ b/src/common/wxchar.cpp @@ -40,6 +40,8 @@ #include "wx/hash.h" #endif +#include "wx/msgdlg.h" + #if defined(__WIN32__) && defined(wxNEED_WX_CTYPE_H) #include #include @@ -374,22 +376,22 @@ WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base) #ifdef wxNEED_WX_STDIO_H WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode) { - return fopen(wxConvFile.cWX2MB(path), wxConvLibc.cWX2MB(mode)); + return fopen( wxConvFile.cWX2MB(path), wxConvLibc.cWX2MB(mode) ); } WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream) { - return freopen(wxConvFile.cWX2MB(path), wxConvLibc.cWX2MB(mode), stream); + return freopen( wxConvFile.cWX2MB(path), wxConvLibc.cWX2MB(mode), stream ); } WXDLLEXPORT int wxRemove(const wxChar *path) { - return remove(wxConvFile.cWX2MB(path)); + return remove( wxConvFile.cWX2MB(path) ); } WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath) { - return rename(wxConvFile.cWX2MB(oldpath), wxConvFile.cWX2MB(newpath)); + return rename( wxConvFile.cWX2MB(oldpath), wxConvFile.cWX2MB(newpath) ); } int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...) @@ -493,14 +495,30 @@ long WXDLLEXPORT wxAtol(const wxChar *psz) wxChar * WXDLLEXPORT wxGetenv(const wxChar *name) { static wxHashTable env; + // check if we already have stored the converted env var wxObject *data = env.Get(name); - if (!data) { + if (!data) + { // nope, retrieve it, - const char *val = getenv(wxConvLibc.cWX2MB(name)); +#if wxUSE_UNICODE + wxCharBuffer buffer = wxConvLibc.cWX2MB(name); + // printf( "buffer %s\n", (const char*) buffer ); + const char *val = getenv( (const char *)buffer ); +#else + const char *val = getenv( name ); +#endif + if (!val) return (wxChar *)NULL; + // printf( "home %s\n", val ); + // convert it, +#ifdef wxUSE_UNICODE + data = (wxObject *)new wxString(val, wxConvLibc); +#else data = (wxObject *)new wxString(val); +#endif + // and store it env.Put(name, data); } diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 14d7dfaf85..47421d57b1 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -1902,26 +1902,13 @@ void wxPostScriptDC::EndDoc () wxChar *header_file = wxGetTempFileName("ps"); - m_pstream = fopen( wxConvFile.cWX2MB(header_file) , "w+" ); + m_pstream = wxFopen( header_file, wxT("w+") ); fprintf( m_pstream, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings fprintf( m_pstream, "%%%%Title: %s\n", (const char *)m_title.mb_str() ); - fprintf( m_pstream, "%%%%Creator: %s\n", (const char*)wxConvCurrent->cWX2MB(wxTheApp->argv[0]) ); + fprintf( m_pstream, "%%%%Creator: wxWindows PostScript renderer\n" ); fprintf( m_pstream, "%%%%CreationDate: %s\n", (const char *)wxNow().mb_str() ); - wxChar userID[256]; - if ( wxGetEmailAddress(userID, sizeof(userID)) ) - { - fprintf( m_pstream, "%%%%For: %s ", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userID) ); - wxChar userName[245]; - if (wxGetUserName(userName, sizeof(userName))) - fprintf( m_pstream, " (%s)", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userName) ); - fprintf( m_pstream, "\n" ); - } - else if ( wxGetUserName(userID, sizeof(userID)) ) - { - fprintf( m_pstream, "%%%%For: %s\n", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userID) );; - } // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe diff --git a/src/generic/prntdlgg.cpp b/src/generic/prntdlgg.cpp index afdeb78725..75ce62c8e3 100644 --- a/src/generic/prntdlgg.cpp +++ b/src/generic/prntdlgg.cpp @@ -360,12 +360,23 @@ bool wxGenericPrintDialog::TransferDataToWindow() bool wxGenericPrintDialog::TransferDataFromWindow() { + long res = 0; if(m_printDialogData.GetFromPage() != -1) { if (m_printDialogData.GetEnablePageNumbers()) { - if(m_fromText) m_printDialogData.SetFromPage(wxAtoi(m_fromText->GetValue())); - if(m_toText) m_printDialogData.SetToPage(wxAtoi(m_toText->GetValue())); + if(m_fromText) + { + wxString value = m_fromText->GetValue(); + if (value.ToLong( &res )) + m_printDialogData.SetFromPage( res ); + } + if(m_toText) + { + wxString value = m_toText->GetValue(); + if (value.ToLong( &res )) + m_printDialogData.SetToPage( res ); + } } if(m_rangeRadioBox) { @@ -380,7 +391,11 @@ bool wxGenericPrintDialog::TransferDataFromWindow() m_printDialogData.SetFromPage(1); m_printDialogData.SetToPage(32000); } - m_printDialogData.SetNoCopies(wxAtoi(m_noCopiesText->GetValue())); + + wxString value = m_noCopiesText->GetValue(); + if (value.ToLong( &res )) + m_printDialogData.SetNoCopies( res ); + m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue()); return TRUE; diff --git a/src/unix/dir.cpp b/src/unix/dir.cpp index 7be4969c30..d31f73ef6d 100644 --- a/src/unix/dir.cpp +++ b/src/unix/dir.cpp @@ -303,7 +303,7 @@ bool wxDir::HasSubDirs(const wxString& spec) // caller will learn it soon enough when it calls GetFirst(wxDIR) // anyhow wxStructStat stBuf; - if ( wxStat(M_DIR->GetName().fn_str(), &stBuf) == 0 ) + if ( wxStat(M_DIR->GetName().c_str(), &stBuf) == 0 ) { switch ( stBuf.st_nlink ) {