Update of /cvsroot/mahogany/M/src/gui
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv17663/src/gui

Modified Files:
        wxComposeView.cpp 
Log Message:
when running in UTF-8 locale, check if the files inserted in the composer 
contain valid UTF-8 and suppose that they are in latin1 otherwise

Index: wxComposeView.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxComposeView.cpp,v
retrieving revision 1.417
retrieving revision 1.418
diff -b -u -2 -r1.417 -r1.418
--- wxComposeView.cpp   23 Aug 2006 15:35:54 -0000      1.417
+++ wxComposeView.cpp   25 Aug 2006 13:25:48 -0000      1.418
@@ -4059,10 +4059,8 @@
       else // non empty file
       {
-         wxChar *p = text.GetWriteBuf(lenFile + 1);
-         p[lenFile] = '\0';
+         wxStringBuffer buf(text, lenFile + 1);
+         buf[lenFile] = '\0';
 
-         ok = file.Read(p, lenFile) != wxInvalidOffset;
-
-         text.UngetWriteBuf();
+         ok = file.Read(buf, lenFile) != wxInvalidOffset;
       }
    }
@@ -4080,9 +4078,35 @@
 }
 
-/// inserts a text
 void
 wxComposeView::InsertText(const String &text)
 {
-   m_editor->InsertText(text, MessageEditor::Insert_Append);
+   // the text here may come from a file and so can be in an encoding different
+   // from the one we currently use, but we -- unfortunately -- have no way of
+   // knowing about it, except in the special case when we use UTF-8 and then
+   // we must check if text is a valid UTF-8 string as otherwise inserting it
+   // is going to fail
+   String textCopy;
+   if ( wxLocale::GetSystemEncoding() == wxFONTENCODING_UTF8 )
+   {
+      if ( wxConvUTF8.MB2WC(NULL, text, 0) == (size_t)-1 )
+      {
+         // not a valid UTF-8 string, must suppose it's in some other encoding
+         // and as we have no idea about what it is, choose latin1 as the most
+         // common (among Mahogany users, anyhow)
+         if ( m_encoding == wxFONTENCODING_SYSTEM )
+         {
+            // change the encoding to latin1 if none explicitly specified
+            SetEncoding(wxFONTENCODING_ISO8859_1);
+         }
+         else // we already have an existing encoding
+         {
+            // transform the text from latin1 to the current encoding
+            textCopy = 
wxCSConv(m_encoding).cWC2MB(wxConvISO8859_1.cMB2WC(text));
+         }
+      }
+   }
+
+   m_editor->InsertText(textCopy.empty() ? text : textCopy,
+                        MessageEditor::Insert_Append);
 }
 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to