Changed wxStat, wxAccess and wxOpen to no longer

being just a define so that the signature is
    using wxChar under Unicode under Unix just as
    it does under Unicode under Mac. This required
    some modification in various places, but should
    make debugging a little easier, among others.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16426 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2002-08-08 21:44:50 +00:00
parent c4e387521b
commit 92980e9076
9 changed files with 124 additions and 68 deletions

View File

@@ -119,13 +119,11 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
#endif // O_RDONLY #endif // O_RDONLY
#else #else
// functions // functions
#define wxOpen open
#define wxClose close #define wxClose close
#define wxRead read #define wxRead read
#define wxWrite write #define wxWrite write
#define wxLseek lseek #define wxLseek lseek
#define wxFsync commit #define wxFsync commit
#define wxAccess access
#define wxEof eof #define wxEof eof
#define wxMkDir mkdir #define wxMkDir mkdir
@@ -133,11 +131,19 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
#define wxTell(fd) lseek(fd, 0, SEEK_CUR) #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
#define wxStat stat
// types
#define wxStructStat struct stat #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++ #endif // VC++
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -79,6 +79,8 @@ bool MyApp::OnInit(void)
g_printData = new wxPrintData; g_printData = new wxPrintData;
g_pageSetupData = new wxPageSetupDialogData; g_pageSetupData = new wxPageSetupDialogData;
// wxGetenv( wxT("HOME") );
// Compatibility with old system. In fact, we might keep wxThePrintSetupData // Compatibility with old system. In fact, we might keep wxThePrintSetupData
// just for useful default values which we can optionally assign to our // just for useful default values which we can optionally assign to our
// own print data object. // own print data object.
@@ -307,11 +309,18 @@ void MyFrame::Draw(wxDC& dc)
dc.SetPen(* wxRED_PEN); dc.SetPen(* wxRED_PEN);
dc.DrawRectangle(0, 30, 200, 100); 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.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.SetPen(* wxBLACK_PEN);
dc.DrawLine(0, 0, 200, 200); dc.DrawLine(0, 0, 200, 200);
@@ -365,8 +374,8 @@ bool MyPrintout::OnPrintPage(int page)
dc->SetDeviceOrigin(0, 0); dc->SetDeviceOrigin(0, 0);
dc->SetUserScale(1.0, 1.0); dc->SetUserScale(1.0, 1.0);
char buf[200]; wxChar buf[200];
sprintf(buf, "PAGE %d", page); wxSprintf(buf, wxT("PAGE %d"), page);
dc->DrawText(buf, 10, 10); dc->DrawText(buf, 10, 10);
return TRUE; return TRUE;
@@ -483,10 +492,11 @@ void MyPrintout::DrawPageTwo(wxDC *dc)
dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250); dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250);
dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits)); dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits));
return;
dc->SetFont(* wxGetApp().m_testFont); dc->SetFont(* wxGetApp().m_testFont);
dc->SetBackgroundMode(wxTRANSPARENT); dc->SetBackgroundMode(wxTRANSPARENT);
dc->DrawText("Some test text", 200, 200 );
{ // GetTextExtent demo: { // GetTextExtent demo:
wxString words[7] = {"This ", "is ", "GetTextExtent ", "testing ", "string. ", "Enjoy ", "it!"}; 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->SetFont(* wxGetApp().m_testFont);
} }
dc->DrawText("Some test text", 200, 300 );
// TESTING // TESTING
int leftMargin = 20; int leftMargin = 20;

View File

@@ -153,18 +153,9 @@
bool wxFile::Exists(const wxChar *name) bool wxFile::Exists(const wxChar *name)
{ {
wxStructStat st; 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) && return !wxAccess(name, 0) &&
!wxStat(name, &st) && !wxStat(name, &st) &&
(st.st_mode & S_IFREG); (st.st_mode & S_IFREG);
#endif
} }
bool wxFile::Access(const wxChar *name, OpenMode mode) 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.")); wxFAIL_MSG(wxT("bad wxFile::Access mode parameter."));
} }
return wxAccess(wxFNCONV(name), how) == 0; return wxAccess( name, how) == 0;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -210,16 +201,18 @@ bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode)
// int fd = open(wxUnix2MacFilename( szFileName ), O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access); // int fd = open(wxUnix2MacFilename( szFileName ), O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access);
int fd = creat( szFileName , accessMode); int fd = creat( szFileName , accessMode);
#else #else
int fd = wxOpen(wxFNCONV(szFileName), int fd = wxOpen( szFileName,
O_BINARY | O_WRONLY | O_CREAT | O_BINARY | O_WRONLY | O_CREAT |
(bOverwrite ? O_TRUNC : O_EXCL) (bOverwrite ? O_TRUNC : O_EXCL)
ACCESS(accessMode)); ACCESS(accessMode) );
#endif #endif
if ( fd == -1 ) { if ( fd == -1 )
{
wxLogSysError(_("can't create file '%s'"), szFileName); wxLogSysError(_("can't create file '%s'"), szFileName);
return FALSE; return FALSE;
} }
else { else
{
Attach(fd); Attach(fd);
return TRUE; return TRUE;
} }
@@ -230,7 +223,8 @@ bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode)
{ {
int flags = O_BINARY; int flags = O_BINARY;
switch ( mode ) { switch ( mode )
{
case read: case read:
flags |= O_RDONLY; flags |= O_RDONLY;
break; break;
@@ -257,8 +251,9 @@ bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode)
break; break;
} }
int fd = wxOpen(wxFNCONV(szFileName), flags ACCESS(accessMode)); int fd = wxOpen( szFileName, flags ACCESS(accessMode));
if ( fd == -1 ) { if ( fd == -1 )
{
wxLogSysError(_("can't open file '%s'"), szFileName); wxLogSysError(_("can't open file '%s'"), szFileName);
return FALSE; return FALSE;
} }

View File

@@ -68,6 +68,7 @@
#ifdef __UNIX__ #ifdef __UNIX__
#include <unistd.h> #include <unistd.h>
#include <dirent.h> #include <dirent.h>
#include <fcntl.h>
#endif #endif
#ifdef __WXPM__ #ifdef __WXPM__
@@ -150,8 +151,6 @@
# include "FSpCompat.h" # include "FSpCompat.h"
#endif #endif
IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// private globals // private globals
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -178,6 +177,32 @@ const off_t wxInvalidOffset = (off_t)-1;
// implementation // 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) void wxPathList::Add (const wxString& path)
{ {
wxStringList::Add (WXSTRINGCAST path); wxStringList::Add (WXSTRINGCAST path);
@@ -308,7 +333,7 @@ wxFileExists (const wxString& filename)
return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY); return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY);
#else #else
wxStructStat stbuf; wxStructStat stbuf;
if ( !filename.empty() && wxStat (OS_FILENAME(filename), &stbuf) == 0 ) if ( !filename.empty() && wxStat( filename, &stbuf) == 0 )
return TRUE; return TRUE;
return FALSE; return FALSE;
@@ -1090,7 +1115,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite)
wxStructStat fbuf; wxStructStat fbuf;
// get permissions of file1 // 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 // the file probably doesn't exist or we haven't the rights to read
// from it anyhow // from it anyhow
@@ -1279,12 +1304,10 @@ bool wxPathExists(const wxChar *pszPathName)
wxStructStat st; wxStructStat st;
#ifndef __VISAGECPP__ #ifndef __VISAGECPP__
return wxStat(wxFNSTRINGCAST strPath.fn_str(), &st) == 0 && return wxStat(pszPathName, &st) == 0 && ((st.st_mode & S_IFMT) == S_IFDIR);
((st.st_mode & S_IFMT) == S_IFDIR);
#else #else
// S_IFMT not supported in VA compilers.. st_mode is a 2byte value only // S_IFMT not supported in VA compilers.. st_mode is a 2byte value only
return wxStat(wxFNSTRINGCAST strPath.fn_str(), &st) == 0 && return wxStat(pszPathName, &st) == 0 && (st.st_mode == S_IFDIR);
(st.st_mode == S_IFDIR);
#endif #endif
#endif // __WIN32__/!__WIN32__ #endif // __WIN32__/!__WIN32__
@@ -1620,8 +1643,8 @@ void WXDLLEXPORT wxSplitPath(const wxChar *pszFileName,
time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename) time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename)
{ {
wxStructStat buf; wxStructStat buf;
wxStat( filename, &buf);
wxStat(filename.fn_str(), &buf);
return buf.st_mtime; return buf.st_mtime;
} }

View File

@@ -1660,7 +1660,7 @@ bool wxFileName::GetTimes(wxDateTime *dtAccess,
{ {
#if defined(__UNIX_LIKE__) || defined(__WXMAC__) || (defined(__DOS__) && defined(__WATCOMC__)) #if defined(__UNIX_LIKE__) || defined(__WXMAC__) || (defined(__DOS__) && defined(__WATCOMC__))
wxStructStat stBuf; wxStructStat stBuf;
if ( wxStat(GetFullPath().fn_str(), &stBuf) == 0 ) if ( wxStat( GetFullPath().c_str(), &stBuf) == 0 )
{ {
if ( dtAccess ) if ( dtAccess )
dtAccess->Set(stBuf.st_atime); dtAccess->Set(stBuf.st_atime);

View File

@@ -40,6 +40,8 @@
#include "wx/hash.h" #include "wx/hash.h"
#endif #endif
#include "wx/msgdlg.h"
#if defined(__WIN32__) && defined(wxNEED_WX_CTYPE_H) #if defined(__WIN32__) && defined(wxNEED_WX_CTYPE_H)
#include <windef.h> #include <windef.h>
#include <winbase.h> #include <winbase.h>
@@ -374,22 +376,22 @@ WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base)
#ifdef wxNEED_WX_STDIO_H #ifdef wxNEED_WX_STDIO_H
WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode) 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) 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) 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) 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, ...) int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...)
@@ -493,14 +495,30 @@ long WXDLLEXPORT wxAtol(const wxChar *psz)
wxChar * WXDLLEXPORT wxGetenv(const wxChar *name) wxChar * WXDLLEXPORT wxGetenv(const wxChar *name)
{ {
static wxHashTable env; static wxHashTable env;
// check if we already have stored the converted env var // check if we already have stored the converted env var
wxObject *data = env.Get(name); wxObject *data = env.Get(name);
if (!data) { if (!data)
{
// nope, retrieve it, // 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; if (!val) return (wxChar *)NULL;
// printf( "home %s\n", val );
// convert it, // convert it,
#ifdef wxUSE_UNICODE
data = (wxObject *)new wxString(val, wxConvLibc);
#else
data = (wxObject *)new wxString(val); data = (wxObject *)new wxString(val);
#endif
// and store it // and store it
env.Put(name, data); env.Put(name, data);
} }

View File

@@ -1902,26 +1902,13 @@ void wxPostScriptDC::EndDoc ()
wxChar *header_file = wxGetTempFileName("ps"); 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, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings
fprintf( m_pstream, "%%%%Title: %s\n", (const char *)m_title.mb_str() ); 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() ); 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 <andy@hyperparallel.com> // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>

View File

@@ -360,12 +360,23 @@ bool wxGenericPrintDialog::TransferDataToWindow()
bool wxGenericPrintDialog::TransferDataFromWindow() bool wxGenericPrintDialog::TransferDataFromWindow()
{ {
long res = 0;
if(m_printDialogData.GetFromPage() != -1) if(m_printDialogData.GetFromPage() != -1)
{ {
if (m_printDialogData.GetEnablePageNumbers()) if (m_printDialogData.GetEnablePageNumbers())
{ {
if(m_fromText) m_printDialogData.SetFromPage(wxAtoi(m_fromText->GetValue())); if(m_fromText)
if(m_toText) m_printDialogData.SetToPage(wxAtoi(m_toText->GetValue())); {
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) if(m_rangeRadioBox)
{ {
@@ -380,7 +391,11 @@ bool wxGenericPrintDialog::TransferDataFromWindow()
m_printDialogData.SetFromPage(1); m_printDialogData.SetFromPage(1);
m_printDialogData.SetToPage(32000); 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()); m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue());
return TRUE; return TRUE;

View File

@@ -303,7 +303,7 @@ bool wxDir::HasSubDirs(const wxString& spec)
// caller will learn it soon enough when it calls GetFirst(wxDIR) // caller will learn it soon enough when it calls GetFirst(wxDIR)
// anyhow // anyhow
wxStructStat stBuf; wxStructStat stBuf;
if ( wxStat(M_DIR->GetName().fn_str(), &stBuf) == 0 ) if ( wxStat(M_DIR->GetName().c_str(), &stBuf) == 0 )
{ {
switch ( stBuf.st_nlink ) switch ( stBuf.st_nlink )
{ {