* wxMemoryStreams updates

* Various fixes about wxGTK and Unicode
* Various fixes in wxStreams


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3010 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux
1999-07-15 18:08:57 +00:00
parent 324dbfec39
commit c980c99263
20 changed files with 107 additions and 54 deletions

View File

@@ -34,7 +34,7 @@ class wxBitmapButton;
// global data // global data
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern const char *wxButtonNameStr; extern const wxChar *wxButtonNameStr;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxBitmapButton // wxBitmapButton

View File

@@ -30,7 +30,7 @@ class wxButton;
// global data // global data
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern const char *wxButtonNameStr; extern const wxChar *wxButtonNameStr;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxButton // wxButton

View File

@@ -30,7 +30,7 @@ class wxStaticText;
// global data // global data
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern const char *wxStaticTextNameStr; extern const wxChar *wxStaticTextNameStr;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxStaticText // wxStaticText

View File

@@ -34,7 +34,7 @@ class wxBitmapButton;
// global data // global data
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern const char *wxButtonNameStr; extern const wxChar *wxButtonNameStr;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxBitmapButton // wxBitmapButton

View File

@@ -30,7 +30,7 @@ class wxButton;
// global data // global data
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern const char *wxButtonNameStr; extern const wxChar *wxButtonNameStr;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxButton // wxButton

View File

@@ -30,7 +30,7 @@ class wxStaticText;
// global data // global data
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern const char *wxStaticTextNameStr; extern const wxChar *wxStaticTextNameStr;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxStaticText // wxStaticText

View File

@@ -25,12 +25,28 @@ class wxMemoryInputStream: public wxInputStream {
virtual size_t StreamSize() const { return m_length; } virtual size_t StreamSize() const { return m_length; }
char Peek(); char Peek();
protected:
wxStreamBuffer *m_i_streambuf;
protected:
size_t OnSysRead(void *buffer, size_t nbytes);
off_t OnSysSeek(off_t pos, wxSeekMode mode);
off_t OnSysTell() const;
}; };
class wxMemoryOutputStream: public wxOutputStream { class wxMemoryOutputStream: public wxOutputStream {
public: public:
wxMemoryOutputStream(char *data = NULL, size_t length = 0); wxMemoryOutputStream(char *data = NULL, size_t length = 0);
virtual ~wxMemoryOutputStream(); virtual ~wxMemoryOutputStream();
protected:
wxStreamBuffer *m_o_streambuf;
protected:
size_t OnSysWrite(const void *buffer, size_t nbytes);
off_t OnSysSeek(off_t pos, wxSeekMode mode);
off_t OnSysTell() const;
}; };
#endif #endif

View File

@@ -105,7 +105,7 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
wxTextCtrl& textCtrl = * GetTextCtrl(); wxTextCtrl& textCtrl = * GetTextCtrl();
textCtrl.Clear(); textCtrl.Clear();
textCtrl << "\nTest fstream vs. wxFileStream:\n\n"; textCtrl << _T("\nTest fstream vs. wxFileStream:\n\n");
textCtrl.WriteText( "Writing to ofstream and wxFileOutputStream:\n" ); textCtrl.WriteText( "Writing to ofstream and wxFileOutputStream:\n" );
@@ -116,31 +116,31 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
wxString tmp; wxString tmp;
signed int si = 0xFFFFFFFF; signed int si = 0xFFFFFFFF;
tmp.Printf( "Signed int: %d\n", si ); tmp.Printf( _T("Signed int: %d\n"), si );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_output << si << "\n"; text_output << si << "\n";
std_file_output << si << "\n"; std_file_output << si << "\n";
unsigned int ui = 0xFFFFFFFF; unsigned int ui = 0xFFFFFFFF;
tmp.Printf( "Unsigned int: %u\n", ui ); tmp.Printf( _T("Unsigned int: %u\n"), ui );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_output << ui << "\n"; text_output << ui << "\n";
std_file_output << ui << "\n"; std_file_output << ui << "\n";
double d = 2.01234567890123456789; double d = 2.01234567890123456789;
tmp.Printf( "Double: %f\n", d ); tmp.Printf( _T("Double: %f\n"), d );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_output << d << "\n"; text_output << d << "\n";
std_file_output << d << "\n"; std_file_output << d << "\n";
float f = 0.00001; float f = 0.00001;
tmp.Printf( "Float: %f\n", f ); tmp.Printf( _T("Float: %f\n"), f );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_output << f << "\n"; text_output << f << "\n";
std_file_output << f << "\n"; std_file_output << f << "\n";
wxString str( "Hello!" ); wxString str( _T("Hello!") );
tmp.Printf( "String: %s\n", str.c_str() ); tmp.Printf( _T("String: %s\n"), str.c_str() );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_output << str << "\n"; text_output << str << "\n";
std_file_output << str.c_str() << "\n"; std_file_output << str.c_str() << "\n";
@@ -150,23 +150,23 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
ifstream std_file_input( "test_std.dat" ); ifstream std_file_input( "test_std.dat" );
std_file_input >> si; std_file_input >> si;
tmp.Printf( "Signed int: %d\n", si ); tmp.Printf( _T("Signed int: %d\n"), si );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
std_file_input >> ui; std_file_input >> ui;
tmp.Printf( "Unsigned int: %u\n", ui ); tmp.Printf( _T("Unsigned int: %u\n"), ui );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
std_file_input >> d; std_file_input >> d;
tmp.Printf( "Double: %f\n", d ); tmp.Printf( _T("Double: %f\n"), d );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
std_file_input >> f; std_file_input >> f;
tmp.Printf( "Float: %f\n", f ); tmp.Printf( _T("Float: %f\n"), f );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
std_file_input >> str; std_file_input >> str;
tmp.Printf( "String: %s\n", str.c_str() ); tmp.Printf( _T("String: %s\n"), str.c_str() );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
textCtrl.WriteText( "\nReading from wxFileInputStream:\n" ); textCtrl.WriteText( "\nReading from wxFileInputStream:\n" );
@@ -178,23 +178,23 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
wxTextInputStream text_input( buf_input ); wxTextInputStream text_input( buf_input );
text_input >> si; text_input >> si;
tmp.Printf( "Signed int: %d\n", si ); tmp.Printf( _T("Signed int: %d\n"), si );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_input >> ui; text_input >> ui;
tmp.Printf( "Unsigned int: %u\n", ui ); tmp.Printf( _T("Unsigned int: %u\n"), ui );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_input >> d; text_input >> d;
tmp.Printf( "Double: %f\n", d ); tmp.Printf( _T("Double: %f\n"), d );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_input >> f; text_input >> f;
tmp.Printf( "Float: %f\n", f ); tmp.Printf( _T("Float: %f\n"), f );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_input >> str; text_input >> str;
tmp.Printf( "String: %s\n", str.c_str() ); tmp.Printf( _T("String: %s\n"), str.c_str() );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
@@ -206,22 +206,22 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
wxDataOutputStream data_output( buf_output ); wxDataOutputStream data_output( buf_output );
wxInt16 i16 = 0xFFFF; wxInt16 i16 = 0xFFFF;
tmp.Printf( "Signed int16: %d\n", (int)i16 ); tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
data_output.Write16( i16 ); data_output.Write16( i16 );
wxUint16 ui16 = 0xFFFF; wxUint16 ui16 = 0xFFFF;
tmp.Printf( "Unsigned int16: %u\n", (unsigned int) ui16 ); tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
data_output.Write16( ui16 ); data_output.Write16( ui16 );
d = 2.01234567890123456789; d = 2.01234567890123456789;
tmp.Printf( "Double: %f\n", d ); tmp.Printf( _T("Double: %f\n"), d );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
data_output.WriteDouble( d ); data_output.WriteDouble( d );
str = "Hello!"; str = "Hello!";
tmp.Printf( "String: %s\n", str.c_str() ); tmp.Printf( _T("String: %s\n"), str.c_str() );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
data_output.WriteString( str ); data_output.WriteString( str );
@@ -233,19 +233,19 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
wxDataInputStream data_input( buf_input ); wxDataInputStream data_input( buf_input );
i16 = data_input.Read16(); i16 = data_input.Read16();
tmp.Printf( "Signed int16: %d\n", (int)i16 ); tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
ui16 = data_input.Read16(); ui16 = data_input.Read16();
tmp.Printf( "Unsigned int16: %u\n", (unsigned int) ui16 ); tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
d = data_input.ReadDouble(); d = data_input.ReadDouble();
tmp.Printf( "Double: %f\n", d ); tmp.Printf( _T("Double: %f\n"), d );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
str = data_input.ReadString(); str = data_input.ReadString();
tmp.Printf( "String: %s\n", str.c_str() ); tmp.Printf( _T("String: %s\n"), str.c_str() );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
} }

View File

@@ -194,8 +194,9 @@ void wxDataOutputStream::Write8(wxUint8 i)
void wxDataOutputStream::WriteString(const wxString& string) void wxDataOutputStream::WriteString(const wxString& string)
{ {
const wxWX2MBbuf buf = string.mb_str();
Write32(string.Length()); Write32(string.Length());
m_output->Write((const wxChar *) string, string.Length()*sizeof(wxChar)); m_output->Write(buf, string.Len());
} }
// Must be at global scope for VC++ 5 // Must be at global scope for VC++ 5

View File

@@ -1297,7 +1297,7 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
} }
wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n, wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n,
strings, data); strings, (char **)data);
delete[] strings; delete[] strings;
delete[] data; delete[] data;
return theTemplate; return theTemplate;
@@ -1320,7 +1320,7 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates,
} }
} }
wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n, wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n,
strings, data); strings, (char **)data);
delete[] strings; delete[] strings;
delete[] data; delete[] data;
return theTemplate; return theTemplate;

View File

@@ -181,7 +181,7 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
{ {
wxChar *tmp_buf; wxChar *tmp_buf;
wxChar buf[200]; wxChar buf[200];
const wxWX2MBbuf pathbuf; wxWX2MBbuf pathbuf(200);
wxString tmp_str; wxString tmp_str;
switch (req) { switch (req) {

View File

@@ -33,24 +33,37 @@
wxMemoryInputStream::wxMemoryInputStream(const char *data, size_t len) wxMemoryInputStream::wxMemoryInputStream(const char *data, size_t len)
: wxInputStream() : wxInputStream()
{ {
/* m_i_streambuf = new wxStreamBuffer(wxStreamBuffer::read);
m_i_streambuf->SetBufferIO((char*) data, (char*) (data+len)); m_i_streambuf->SetBufferIO((char*) data, (char*) (data+len));
m_i_streambuf->SetIntPosition(0); // seek to start pos m_i_streambuf->SetIntPosition(0); // seek to start pos
m_i_streambuf->Fixed(TRUE); m_i_streambuf->Fixed(TRUE);
*/
m_length = len; m_length = len;
} }
wxMemoryInputStream::~wxMemoryInputStream() wxMemoryInputStream::~wxMemoryInputStream()
{ {
delete m_i_streambuf;
} }
char wxMemoryInputStream::Peek() char wxMemoryInputStream::Peek()
{ {
/*
return m_i_streambuf->GetBufferStart()[m_i_streambuf->GetIntPosition()]; return m_i_streambuf->GetBufferStart()[m_i_streambuf->GetIntPosition()];
*/ }
return 0;
size_t wxMemoryInputStream::OnSysRead(void *buffer, size_t nbytes)
{
return m_i_streambuf->Read(buffer, nbytes);
}
off_t wxMemoryInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
{
return m_i_streambuf->Seek(pos, mode);
}
off_t wxMemoryInputStream::OnSysTell() const
{
return m_i_streambuf->Tell();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -60,15 +73,31 @@ char wxMemoryInputStream::Peek()
wxMemoryOutputStream::wxMemoryOutputStream(char *data, size_t len) wxMemoryOutputStream::wxMemoryOutputStream(char *data, size_t len)
: wxOutputStream() : wxOutputStream()
{ {
/* m_o_streambuf = new wxStreamBuffer(wxStreamBuffer::write);
if (data) if (data)
m_o_streambuf->SetBufferIO(data, data+len); m_o_streambuf->SetBufferIO(data, data+len);
m_o_streambuf->Fixed(TRUE); m_o_streambuf->Fixed(TRUE);
*/
} }
wxMemoryOutputStream::~wxMemoryOutputStream() wxMemoryOutputStream::~wxMemoryOutputStream()
{ {
delete m_o_streambuf;
} }
size_t wxMemoryOutputStream::OnSysWrite(const void *buffer, size_t nbytes)
{
return m_o_streambuf->Write(buffer, nbytes);
}
off_t wxMemoryOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
{
return m_o_streambuf->Seek(pos, mode);
}
off_t wxMemoryOutputStream::OnSysTell() const
{
return m_o_streambuf->Tell();
}
#endif #endif

View File

@@ -23,6 +23,7 @@
#if wxUSE_STREAMS #if wxUSE_STREAMS
#include "wx/txtstrm.h" #include "wx/txtstrm.h"
#include <ctype.h>
wxTextInputStream::wxTextInputStream(wxInputStream& s) wxTextInputStream::wxTextInputStream(wxInputStream& s)
: m_input(&s) : m_input(&s)
@@ -300,7 +301,7 @@ wxTextOutputStream& wxTextOutputStream::operator<<(const wxString& string)
wxTextOutputStream& wxTextOutputStream::operator<<(wxChar c) wxTextOutputStream& wxTextOutputStream::operator<<(wxChar c)
{ {
wxString tmp_str; wxString tmp_str;
tmp_str.Printf("%c", c); tmp_str.Printf(_T("%c"), c);
WriteString(tmp_str); WriteString(tmp_str);
return *this; return *this;
} }

View File

@@ -231,17 +231,17 @@ wxProgressDialog::Update(int value, const wxString& newmsg)
if (m_elapsed) if (m_elapsed)
{ {
s.Printf("%i:%02i:%02i", diff.GetHour(), diff.GetMinute(), diff.GetSecond()); s.Printf(_T("%i:%02i:%02i"), diff.GetHour(), diff.GetMinute(), diff.GetSecond());
if (s != m_elapsed->GetLabel()) m_elapsed->SetLabel(s); if (s != m_elapsed->GetLabel()) m_elapsed->SetLabel(s);
} }
if (m_estimated) if (m_estimated)
{ {
s.Printf("%i:%02i:%02i", estim / (60 * 60), (estim / 60) % 60, estim % 60); s.Printf(_T("%i:%02i:%02i"), estim / (60 * 60), (estim / 60) % 60, estim % 60);
if (s != m_estimated->GetLabel()) m_estimated->SetLabel(s); if (s != m_estimated->GetLabel()) m_estimated->SetLabel(s);
} }
if (m_remaining) if (m_remaining)
{ {
s.Printf("%i:%02i:%02i", remai / (60 * 60), (remai / 60) % 60, remai % 60); s.Printf(_T("%i:%02i:%02i"), remai / (60 * 60), (remai / 60) % 60, remai % 60);
if (s != m_remaining->GetLabel()) m_remaining->SetLabel(s); if (s != m_remaining->GetLabel()) m_remaining->SetLabel(s);
} }
} }

View File

@@ -138,7 +138,7 @@ wxChar *wxGetSingleChoiceData( const wxString& message, const wxString& caption,
{ {
wxSingleChoiceDialog dialog(parent, message, caption, n, choices, client_data); wxSingleChoiceDialog dialog(parent, message, caption, n, choices, client_data);
if ( dialog.ShowModal() == wxID_OK ) if ( dialog.ShowModal() == wxID_OK )
return dialog.GetSelectionClientData(); return (wxChar *)dialog.GetSelectionClientData();
else else
return NULL; return NULL;
} }

View File

@@ -212,10 +212,13 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
/* local buffer in multibyte form */ /* local buffer in multibyte form */
wxString buf; wxString buf;
buf << '/' << str.mb_str(); buf << _T('/') << str.c_str();
char *cbuf = new char[buf.Length()]; char *cbuf = new char[buf.Length()];
strcpy(cbuf, buf.mbc_str());
GtkItemFactoryEntry entry; GtkItemFactoryEntry entry;
entry.path = (gchar *)buf.c_str(); // const_cast entry.path = (gchar *)cbuf; // const_cast
entry.accelerator = (gchar*) NULL; entry.accelerator = (gchar*) NULL;
entry.callback = (GtkItemFactoryCallback) NULL; entry.callback = (GtkItemFactoryCallback) NULL;
entry.callback_action = 0; entry.callback_action = 0;

View File

@@ -390,7 +390,7 @@ void wxTextCtrl::AppendText( const wxString &text )
m_font.GetInternalFont(), m_font.GetInternalFont(),
m_foregroundColour.GetColor(), m_foregroundColour.GetColor(),
m_backgroundColour.GetColor(), m_backgroundColour.GetColor(),
text, text.length()); text.mbc_str(), text.length());
} }
else else

View File

@@ -138,7 +138,7 @@ wxChar *wxGetSingleChoiceData( const wxString& message, const wxString& caption,
{ {
wxSingleChoiceDialog dialog(parent, message, caption, n, choices, client_data); wxSingleChoiceDialog dialog(parent, message, caption, n, choices, client_data);
if ( dialog.ShowModal() == wxID_OK ) if ( dialog.ShowModal() == wxID_OK )
return dialog.GetSelectionClientData(); return (wxChar *)dialog.GetSelectionClientData();
else else
return NULL; return NULL;
} }

View File

@@ -212,10 +212,13 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
/* local buffer in multibyte form */ /* local buffer in multibyte form */
wxString buf; wxString buf;
buf << '/' << str.mb_str(); buf << _T('/') << str.c_str();
char *cbuf = new char[buf.Length()]; char *cbuf = new char[buf.Length()];
strcpy(cbuf, buf.mbc_str());
GtkItemFactoryEntry entry; GtkItemFactoryEntry entry;
entry.path = (gchar *)buf.c_str(); // const_cast entry.path = (gchar *)cbuf; // const_cast
entry.accelerator = (gchar*) NULL; entry.accelerator = (gchar*) NULL;
entry.callback = (GtkItemFactoryCallback) NULL; entry.callback = (GtkItemFactoryCallback) NULL;
entry.callback_action = 0; entry.callback_action = 0;

View File

@@ -390,7 +390,7 @@ void wxTextCtrl::AppendText( const wxString &text )
m_font.GetInternalFont(), m_font.GetInternalFont(),
m_foregroundColour.GetColor(), m_foregroundColour.GetColor(),
m_backgroundColour.GetColor(), m_backgroundColour.GetColor(),
text, text.length()); text.mbc_str(), text.length());
} }
else else