From c980c992630e94e71139660631a77ffbca8ed958 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Thu, 15 Jul 1999 18:08:57 +0000 Subject: [PATCH] * 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 --- include/wx/gtk/bmpbuttn.h | 2 +- include/wx/gtk/button.h | 2 +- include/wx/gtk/stattext.h | 2 +- include/wx/gtk1/bmpbuttn.h | 2 +- include/wx/gtk1/button.h | 2 +- include/wx/gtk1/stattext.h | 2 +- include/wx/mstream.h | 16 +++++++++++ samples/typetest/typetest.cpp | 50 +++++++++++++++++------------------ src/common/datstrm.cpp | 3 ++- src/common/docview.cpp | 4 +-- src/common/http.cpp | 2 +- src/common/mstream.cpp | 43 +++++++++++++++++++++++++----- src/common/txtstrm.cpp | 3 ++- src/generic/progdlgg.cpp | 6 ++--- src/gtk/choicdlg.cpp | 2 +- src/gtk/menu.cpp | 7 +++-- src/gtk/textctrl.cpp | 2 +- src/gtk1/choicdlg.cpp | 2 +- src/gtk1/menu.cpp | 7 +++-- src/gtk1/textctrl.cpp | 2 +- 20 files changed, 107 insertions(+), 54 deletions(-) diff --git a/include/wx/gtk/bmpbuttn.h b/include/wx/gtk/bmpbuttn.h index 7806bc1471..4d3a769c40 100644 --- a/include/wx/gtk/bmpbuttn.h +++ b/include/wx/gtk/bmpbuttn.h @@ -34,7 +34,7 @@ class wxBitmapButton; // global data //----------------------------------------------------------------------------- -extern const char *wxButtonNameStr; +extern const wxChar *wxButtonNameStr; //----------------------------------------------------------------------------- // wxBitmapButton diff --git a/include/wx/gtk/button.h b/include/wx/gtk/button.h index 3bd5a5f28a..9e2268309c 100644 --- a/include/wx/gtk/button.h +++ b/include/wx/gtk/button.h @@ -30,7 +30,7 @@ class wxButton; // global data //----------------------------------------------------------------------------- -extern const char *wxButtonNameStr; +extern const wxChar *wxButtonNameStr; //----------------------------------------------------------------------------- // wxButton diff --git a/include/wx/gtk/stattext.h b/include/wx/gtk/stattext.h index 1febeb3139..0e58cb15ec 100644 --- a/include/wx/gtk/stattext.h +++ b/include/wx/gtk/stattext.h @@ -30,7 +30,7 @@ class wxStaticText; // global data //----------------------------------------------------------------------------- -extern const char *wxStaticTextNameStr; +extern const wxChar *wxStaticTextNameStr; //----------------------------------------------------------------------------- // wxStaticText diff --git a/include/wx/gtk1/bmpbuttn.h b/include/wx/gtk1/bmpbuttn.h index 7806bc1471..4d3a769c40 100644 --- a/include/wx/gtk1/bmpbuttn.h +++ b/include/wx/gtk1/bmpbuttn.h @@ -34,7 +34,7 @@ class wxBitmapButton; // global data //----------------------------------------------------------------------------- -extern const char *wxButtonNameStr; +extern const wxChar *wxButtonNameStr; //----------------------------------------------------------------------------- // wxBitmapButton diff --git a/include/wx/gtk1/button.h b/include/wx/gtk1/button.h index 3bd5a5f28a..9e2268309c 100644 --- a/include/wx/gtk1/button.h +++ b/include/wx/gtk1/button.h @@ -30,7 +30,7 @@ class wxButton; // global data //----------------------------------------------------------------------------- -extern const char *wxButtonNameStr; +extern const wxChar *wxButtonNameStr; //----------------------------------------------------------------------------- // wxButton diff --git a/include/wx/gtk1/stattext.h b/include/wx/gtk1/stattext.h index 1febeb3139..0e58cb15ec 100644 --- a/include/wx/gtk1/stattext.h +++ b/include/wx/gtk1/stattext.h @@ -30,7 +30,7 @@ class wxStaticText; // global data //----------------------------------------------------------------------------- -extern const char *wxStaticTextNameStr; +extern const wxChar *wxStaticTextNameStr; //----------------------------------------------------------------------------- // wxStaticText diff --git a/include/wx/mstream.h b/include/wx/mstream.h index 83ae0ba3b5..187a0e6549 100644 --- a/include/wx/mstream.h +++ b/include/wx/mstream.h @@ -25,12 +25,28 @@ class wxMemoryInputStream: public wxInputStream { virtual size_t StreamSize() const { return m_length; } 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 { public: wxMemoryOutputStream(char *data = NULL, size_t length = 0); 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 diff --git a/samples/typetest/typetest.cpp b/samples/typetest/typetest.cpp index e2895a4b77..4cdeff9cbb 100644 --- a/samples/typetest/typetest.cpp +++ b/samples/typetest/typetest.cpp @@ -105,7 +105,7 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) wxTextCtrl& textCtrl = * GetTextCtrl(); 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" ); @@ -116,31 +116,31 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) wxString tmp; signed int si = 0xFFFFFFFF; - tmp.Printf( "Signed int: %d\n", si ); + tmp.Printf( _T("Signed int: %d\n"), si ); textCtrl.WriteText( tmp ); text_output << si << "\n"; std_file_output << si << "\n"; unsigned int ui = 0xFFFFFFFF; - tmp.Printf( "Unsigned int: %u\n", ui ); + tmp.Printf( _T("Unsigned int: %u\n"), ui ); textCtrl.WriteText( tmp ); text_output << ui << "\n"; std_file_output << ui << "\n"; double d = 2.01234567890123456789; - tmp.Printf( "Double: %f\n", d ); + tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); text_output << d << "\n"; std_file_output << d << "\n"; float f = 0.00001; - tmp.Printf( "Float: %f\n", f ); + tmp.Printf( _T("Float: %f\n"), f ); textCtrl.WriteText( tmp ); text_output << f << "\n"; std_file_output << f << "\n"; - wxString str( "Hello!" ); - tmp.Printf( "String: %s\n", str.c_str() ); + wxString str( _T("Hello!") ); + tmp.Printf( _T("String: %s\n"), str.c_str() ); textCtrl.WriteText( tmp ); text_output << 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" ); std_file_input >> si; - tmp.Printf( "Signed int: %d\n", si ); + tmp.Printf( _T("Signed int: %d\n"), si ); textCtrl.WriteText( tmp ); std_file_input >> ui; - tmp.Printf( "Unsigned int: %u\n", ui ); + tmp.Printf( _T("Unsigned int: %u\n"), ui ); textCtrl.WriteText( tmp ); std_file_input >> d; - tmp.Printf( "Double: %f\n", d ); + tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); std_file_input >> f; - tmp.Printf( "Float: %f\n", f ); + tmp.Printf( _T("Float: %f\n"), f ); textCtrl.WriteText( tmp ); 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( "\nReading from wxFileInputStream:\n" ); @@ -178,23 +178,23 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) wxTextInputStream text_input( buf_input ); text_input >> si; - tmp.Printf( "Signed int: %d\n", si ); + tmp.Printf( _T("Signed int: %d\n"), si ); textCtrl.WriteText( tmp ); text_input >> ui; - tmp.Printf( "Unsigned int: %u\n", ui ); + tmp.Printf( _T("Unsigned int: %u\n"), ui ); textCtrl.WriteText( tmp ); text_input >> d; - tmp.Printf( "Double: %f\n", d ); + tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); text_input >> f; - tmp.Printf( "Float: %f\n", f ); + tmp.Printf( _T("Float: %f\n"), f ); textCtrl.WriteText( tmp ); text_input >> str; - tmp.Printf( "String: %s\n", str.c_str() ); + tmp.Printf( _T("String: %s\n"), str.c_str() ); textCtrl.WriteText( tmp ); @@ -206,22 +206,22 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) wxDataOutputStream data_output( buf_output ); wxInt16 i16 = 0xFFFF; - tmp.Printf( "Signed int16: %d\n", (int)i16 ); + tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); textCtrl.WriteText( tmp ); data_output.Write16( i16 ); 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 ); data_output.Write16( ui16 ); d = 2.01234567890123456789; - tmp.Printf( "Double: %f\n", d ); + tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); data_output.WriteDouble( d ); str = "Hello!"; - tmp.Printf( "String: %s\n", str.c_str() ); + tmp.Printf( _T("String: %s\n"), str.c_str() ); textCtrl.WriteText( tmp ); data_output.WriteString( str ); @@ -233,19 +233,19 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) wxDataInputStream data_input( buf_input ); i16 = data_input.Read16(); - tmp.Printf( "Signed int16: %d\n", (int)i16 ); + tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); textCtrl.WriteText( tmp ); 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 ); d = data_input.ReadDouble(); - tmp.Printf( "Double: %f\n", d ); + tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); str = data_input.ReadString(); - tmp.Printf( "String: %s\n", str.c_str() ); + tmp.Printf( _T("String: %s\n"), str.c_str() ); textCtrl.WriteText( tmp ); } diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp index a13eb8cd3a..85f80d9507 100644 --- a/src/common/datstrm.cpp +++ b/src/common/datstrm.cpp @@ -194,8 +194,9 @@ void wxDataOutputStream::Write8(wxUint8 i) void wxDataOutputStream::WriteString(const wxString& string) { + const wxWX2MBbuf buf = string.mb_str(); 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 diff --git a/src/common/docview.cpp b/src/common/docview.cpp index a6687e39a6..465f22a2be 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -1297,7 +1297,7 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates, } wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n, - strings, data); + strings, (char **)data); delete[] strings; delete[] data; return theTemplate; @@ -1320,7 +1320,7 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates, } } wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n, - strings, data); + strings, (char **)data); delete[] strings; delete[] data; return theTemplate; diff --git a/src/common/http.cpp b/src/common/http.cpp index 08c4df058c..06cfbd02e8 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -181,7 +181,7 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req) { wxChar *tmp_buf; wxChar buf[200]; - const wxWX2MBbuf pathbuf; + wxWX2MBbuf pathbuf(200); wxString tmp_str; switch (req) { diff --git a/src/common/mstream.cpp b/src/common/mstream.cpp index 6519a8bc3a..4555d35062 100644 --- a/src/common/mstream.cpp +++ b/src/common/mstream.cpp @@ -33,24 +33,37 @@ wxMemoryInputStream::wxMemoryInputStream(const char *data, size_t len) : wxInputStream() { -/* + m_i_streambuf = new wxStreamBuffer(wxStreamBuffer::read); m_i_streambuf->SetBufferIO((char*) data, (char*) (data+len)); m_i_streambuf->SetIntPosition(0); // seek to start pos m_i_streambuf->Fixed(TRUE); -*/ + m_length = len; } wxMemoryInputStream::~wxMemoryInputStream() { + delete m_i_streambuf; } char wxMemoryInputStream::Peek() { -/* 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) : wxOutputStream() { -/* + m_o_streambuf = new wxStreamBuffer(wxStreamBuffer::write); if (data) m_o_streambuf->SetBufferIO(data, data+len); m_o_streambuf->Fixed(TRUE); -*/ } 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 diff --git a/src/common/txtstrm.cpp b/src/common/txtstrm.cpp index 6475674cb0..e0acaeb66c 100644 --- a/src/common/txtstrm.cpp +++ b/src/common/txtstrm.cpp @@ -23,6 +23,7 @@ #if wxUSE_STREAMS #include "wx/txtstrm.h" +#include wxTextInputStream::wxTextInputStream(wxInputStream& s) : m_input(&s) @@ -300,7 +301,7 @@ wxTextOutputStream& wxTextOutputStream::operator<<(const wxString& string) wxTextOutputStream& wxTextOutputStream::operator<<(wxChar c) { wxString tmp_str; - tmp_str.Printf("%c", c); + tmp_str.Printf(_T("%c"), c); WriteString(tmp_str); return *this; } diff --git a/src/generic/progdlgg.cpp b/src/generic/progdlgg.cpp index 0bd46a5ca9..542ffad161 100644 --- a/src/generic/progdlgg.cpp +++ b/src/generic/progdlgg.cpp @@ -231,17 +231,17 @@ wxProgressDialog::Update(int value, const wxString& newmsg) 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 (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 (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); } } diff --git a/src/gtk/choicdlg.cpp b/src/gtk/choicdlg.cpp index 96e0cc4b79..fe1352d0a5 100644 --- a/src/gtk/choicdlg.cpp +++ b/src/gtk/choicdlg.cpp @@ -138,7 +138,7 @@ wxChar *wxGetSingleChoiceData( const wxString& message, const wxString& caption, { wxSingleChoiceDialog dialog(parent, message, caption, n, choices, client_data); if ( dialog.ShowModal() == wxID_OK ) - return dialog.GetSelectionClientData(); + return (wxChar *)dialog.GetSelectionClientData(); else return NULL; } diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 48ac17d030..e56b4632f7 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -212,10 +212,13 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) /* local buffer in multibyte form */ wxString buf; - buf << '/' << str.mb_str(); + buf << _T('/') << str.c_str(); + char *cbuf = new char[buf.Length()]; + strcpy(cbuf, buf.mbc_str()); + GtkItemFactoryEntry entry; - entry.path = (gchar *)buf.c_str(); // const_cast + entry.path = (gchar *)cbuf; // const_cast entry.accelerator = (gchar*) NULL; entry.callback = (GtkItemFactoryCallback) NULL; entry.callback_action = 0; diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 93d3bf216b..9739c45681 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -390,7 +390,7 @@ void wxTextCtrl::AppendText( const wxString &text ) m_font.GetInternalFont(), m_foregroundColour.GetColor(), m_backgroundColour.GetColor(), - text, text.length()); + text.mbc_str(), text.length()); } else diff --git a/src/gtk1/choicdlg.cpp b/src/gtk1/choicdlg.cpp index 96e0cc4b79..fe1352d0a5 100644 --- a/src/gtk1/choicdlg.cpp +++ b/src/gtk1/choicdlg.cpp @@ -138,7 +138,7 @@ wxChar *wxGetSingleChoiceData( const wxString& message, const wxString& caption, { wxSingleChoiceDialog dialog(parent, message, caption, n, choices, client_data); if ( dialog.ShowModal() == wxID_OK ) - return dialog.GetSelectionClientData(); + return (wxChar *)dialog.GetSelectionClientData(); else return NULL; } diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 48ac17d030..e56b4632f7 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -212,10 +212,13 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) /* local buffer in multibyte form */ wxString buf; - buf << '/' << str.mb_str(); + buf << _T('/') << str.c_str(); + char *cbuf = new char[buf.Length()]; + strcpy(cbuf, buf.mbc_str()); + GtkItemFactoryEntry entry; - entry.path = (gchar *)buf.c_str(); // const_cast + entry.path = (gchar *)cbuf; // const_cast entry.accelerator = (gchar*) NULL; entry.callback = (GtkItemFactoryCallback) NULL; entry.callback_action = 0; diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 93d3bf216b..9739c45681 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -390,7 +390,7 @@ void wxTextCtrl::AppendText( const wxString &text ) m_font.GetInternalFont(), m_foregroundColour.GetColor(), m_backgroundColour.GetColor(), - text, text.length()); + text.mbc_str(), text.length()); } else -- 2.45.2