Update of /cvsroot/mahogany/M/src/modules
In directory sc8-pr-cvs1:/tmp/cvs-serv21241/src/modules
Modified Files:
BareBonesEditor.cpp
Log Message:
renamed 8BIT_WARN in LANG_CHANGED_WARN and changed the text accordingly
Index: BareBonesEditor.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/BareBonesEditor.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -b -u -2 -r1.23 -r1.24
--- BareBonesEditor.cpp 6 Oct 2003 00:38:55 -0000 1.23
+++ BareBonesEditor.cpp 12 Oct 2003 11:29:01 -0000 1.24
@@ -45,5 +45,8 @@
#include "MessageEditor.h"
-class WXDLLEXPORT wxListCtrl;
+#if wxUSE_WCHAR_T && defined(OS_WIN)
+ #include <wx/encconv.h>
+ #include <wx/fontmap.h>
+#endif // wxUSE_WCHAR_T
// ----------------------------------------------------------------------------
@@ -59,5 +62,5 @@
extern const MPersMsgBox *M_MSGBOX_FORMAT_PARAGRAPH_BEFORE_EXIT;
-extern const MPersMsgBox *M_MSGBOX_8BIT_WARN;
+extern const MPersMsgBox *M_MSGBOX_LANG_CHANGED_WARN;
// ----------------------------------------------------------------------------
@@ -81,4 +84,5 @@
class FormattedParagraph;
class wxBareBonesEditorNotebook;
+class wxBareBonesTextControl;
class BareBonesEditor : public MessageEditor
@@ -134,9 +138,9 @@
// must be called when the encoding changes to reflect it at wxTextCtrl
// level
- void SetFontEncoding();
+ void SetFontEncoding(wxFontEncoding encoding);
wxBareBonesEditorNotebook *m_notebook;
- wxTextCtrl *m_textControl;
+ wxBareBonesTextControl *m_textControl;
wxListCtrl *m_attachments;
@@ -188,4 +192,8 @@
};
+// ----------------------------------------------------------------------------
+// the notebook containing wxBareBonesTextControl and wxBareBonesAttachments
+// ----------------------------------------------------------------------------
+
class wxBareBonesEditorNotebook : public wxNotebook
{
@@ -193,5 +201,5 @@
wxBareBonesEditorNotebook(BareBonesEditor *editor,wxWindow *parent);
- wxTextCtrl *GetTextControl() const { return m_textControl; }
+ wxBareBonesTextControl *GetTextControl() const { return m_textControl; }
wxListCtrl *GetList() const { return m_attachments; }
@@ -209,5 +217,5 @@
BareBonesEditor *m_editor;
- wxTextCtrl *m_textControl;
+ wxBareBonesTextControl *m_textControl;
wxListCtrl *m_attachments;
@@ -215,4 +223,8 @@
};
+// ----------------------------------------------------------------------------
+// the text control where the user types the message text
+// ----------------------------------------------------------------------------
+
class wxBareBonesTextControl : public wxTextCtrl
{
@@ -220,10 +232,12 @@
wxBareBonesTextControl(BareBonesEditor *editor,wxWindow *parent);
+#if wxUSE_WCHAR_T && defined(OS_WIN)
+ // get the text as a Unicode string
+ wxWCharBuffer GetUnicodeText() const;
+#endif // wxUSE_WCHAR_T
+
protected:
// event handlers
void OnKeyDown(wxKeyEvent& event);
-#ifdef OS_WIN
- void OnChar(wxKeyEvent& event);
-#endif // OS_WIN
void OnFocus(wxFocusEvent& event);
@@ -234,11 +248,11 @@
bool m_firstTimeFocus;
-#ifdef OS_WIN
- bool m_warning8bitShown;
-#endif // OS_WIN
-
DECLARE_EVENT_TABLE()
};
+// ----------------------------------------------------------------------------
+// the list control in icon mode showing all the attachments
+// ----------------------------------------------------------------------------
+
class wxBareBonesAttachments : public wxListView
{
@@ -256,4 +270,5 @@
};
+
// ============================================================================
// implementation
@@ -265,4 +280,46 @@
// ----------------------------------------------------------------------------
+// some global helper functions
+// ----------------------------------------------------------------------------
+
+#if wxUSE_WCHAR_T && defined(OS_WIN)
+
+// this very simple minded function tries to determine the encoding we shoudl
+// use from the given Unicode character code
+static wxFontEncoding GetEncoding(wchar_t wch)
+{
+ // basic latin
+ if ( wch < 0x7f )
+ return wxFONTENCODING_SYSTEM;
+
+ // greek
+ if ( wch >= 0x370 && wch < 0x400 )
+ return wxFONTENCODING_CP1253;
+
+ // cyrillic
+ if ( wch >= 0x400 && wch < 0x530 )
+ return wxFONTENCODING_CP1251;
+
+ // hebrew
+ if ( wch >= 0x590 && wch < 0x600 )
+ return wxFONTENCODING_CP1255;
+
+ // arabic
+ if ( wch >= 0x600 && wch < 0x700 )
+ return wxFONTENCODING_CP1255;
+
+ // unknown
+ return wxFONTENCODING_UTF8;
+}
+
+static bool CanConvert(wxFontEncoding encIn, wxFontEncoding encOut)
+{
+ return
+ wxEncodingConverter::GetAllEquivalents(encIn).Index(encOut) != wxNOT_FOUND;
+}
+
+#endif // wxUSE_WCHAR_T
+
+// ----------------------------------------------------------------------------
// FormattedParagraph
// ----------------------------------------------------------------------------
@@ -719,7 +776,4 @@
BEGIN_EVENT_TABLE(wxBareBonesTextControl, wxTextCtrl)
EVT_KEY_DOWN(wxBareBonesTextControl::OnKeyDown)
-#ifdef OS_WIN
- EVT_CHAR(wxBareBonesTextControl::OnChar)
-#endif // OS_WIN
EVT_SET_FOCUS(wxBareBonesTextControl::OnFocus)
END_EVENT_TABLE()
@@ -738,8 +792,4 @@
m_firstTimeModify = true;
m_firstTimeFocus = true;
-
-#ifdef OS_WIN
- m_warning8bitShown = false;
-#endif // OS_WIN
}
@@ -756,33 +806,4 @@
}
-#ifdef OS_WIN
-
-void wxBareBonesTextControl::OnChar(wxKeyEvent& event)
-{
- if ( event.GetKeyCode() > 0x7f && event.GetKeyCode() < WXK_START )
- {
- if ( !m_editor->HasEncoding() && !m_warning8bitShown )
- {
- m_warning8bitShown = true;
-
- MDialog_Message
- (
- _("You should specify the language if you want to use non"
- "ASCII characters in your message.\n"
- "\n"
- "Please choose one in the \"Languages\" menu, otherwise "
- "the non-ASCII characters could be lost."),
- this,
- MDIALOG_MSGTITLE,
- GetPersMsgBoxName(M_MSGBOX_8BIT_WARN)
- );
- }
- }
-
- event.Skip();
-}
-
-#endif // OS_WIN
-
void wxBareBonesTextControl::OnFocus(wxFocusEvent& event)
{
@@ -802,4 +823,16 @@
}
+
+#if wxUSE_WCHAR_T && defined(OS_WIN)
+
+wxWCharBuffer
+wxBareBonesTextControl::GetUnicodeText() const
+{
+ wxString s = StreamOut(wxFONTENCODING_UTF8);
+ return s.wc_str(wxConvUTF8);
+}
+
+#endif // wxUSE_WCHAR_T
+
// ----------------------------------------------------------------------------
// BareBonesEditor ctor/dtor
@@ -939,7 +972,7 @@
}
-void BareBonesEditor::SetFontEncoding()
+void BareBonesEditor::SetFontEncoding(wxFontEncoding encoding)
{
- if ( m_encoding == wxFONTENCODING_SYSTEM )
+ if ( encoding == wxFONTENCODING_SYSTEM )
{
return;
@@ -957,5 +990,5 @@
fontOld.GetUnderlined(),
fontOld.GetFaceName(),
- m_encoding);
+ encoding);
#endif
@@ -968,7 +1001,5 @@
void BareBonesEditor::SetEncoding(wxFontEncoding encoding)
{
- m_encoding = encoding;
-
- SetFontEncoding();
+ SetFontEncoding(m_encoding = encoding);
}
@@ -1074,5 +1105,5 @@
if ( EnsureAvailableTextEncoding(&m_encoding, &text, true /* may ask */) )
{
- SetFontEncoding();
+ SetFontEncoding(m_encoding);
}
//else: don't change the font, encoding is not supported anyhow
@@ -1108,4 +1139,106 @@
m_getNextAttachement = 0;
+ wxFontEncoding encPart = wxFONTENCODING_SYSTEM;
+ wxString text;
+
+#if wxUSE_WCHAR_T && defined(OS_WIN)
+ wxWCharBuffer wbuf = m_textControl->GetUnicodeText();
+
+ for ( const wchar_t *pwc = wbuf; *pwc; pwc++ )
+ {
+ const wxFontEncoding encThis = GetEncoding(*pwc);
+ if ( encThis != wxFONTENCODING_SYSTEM && encThis != encPart )
+ {
+ if ( encPart != wxFONTENCODING_SYSTEM )
+ {
+ // we have two (or more) different encodings here, we must use UTF8
+ // to send both of them inside a single message part
+ encPart = wxFONTENCODING_UTF8;
+
+ // and we don't have to look any further, we found all we wanted
+ break;
+ }
+
+ // assume we're going to use this encoding for this entire part
+ encPart = encThis;
+ }
+ }
+
+ // if we hadn't had any user-specified encoding before, use the one we just
+ // found
+ if ( m_encoding == wxFONTENCODING_SYSTEM )
+ {
+ m_encoding = encPart;
+ }
+
+ if ( encPart != wxFONTENCODING_SYSTEM )
+ {
+ // must do this first or we wouldn't get the data from MSW rich edit
+ // control at all (it would try to convert text to the last set encoding
+ // and drop any characters it can't convert)
+ SetFontEncoding(encPart);
+
+ text = m_textControl->GetValue();
+
+ // we now know that we have the text in encoding encPart but that we want
+ // to send it out as m_encoding -- do we need to convert?
+ if ( encPart != m_encoding )
+ {
+ if ( encPart == wxFONTENCODING_UTF8 ||
+ m_encoding == wxFONTENCODING_UTF8 )
+ {
+ // here encPart may only be UTF8 if more than one encoding or an
+ // unknown encoding was used, in either case we can't convert the
+ // text to a single non-Unicode charset, so use UTF8 as is
+ //
+ // of course, if it is m_encoding which is UTF8 we wanted to use it
+ // anyhow
+ text = wxConvUTF8.cWC2MB(wbuf);
+ encPart = wxFONTENCODING_UTF8;
+ }
+ else // 2 multibyte encodings
+ {
+ text = wxCSConv(encPart).cWC2MB(wbuf);
+
+ if ( encPart != m_encoding )
+ {
+ // is it possible to convert to the desired encoding?
+ wxEncodingConverter conv;
+ if ( CanConvert(encPart, m_encoding) &&
+ conv.Init(encPart, m_encoding) )
+ {
+ // yes, do it
+ text = conv.Convert(text);
+ encPart = m_encoding;
+ }
+ else // impossible to convert to the specified encoding
+ {
+ // tell the user about it
+ //
+ // TODO: allow cancelling?
+ MDialog_Message
+ (
+ wxString::Format
+ (
+ _("The selected language \"%s\" can't be used to "
+ "send this message, \"%s\" will be used instead."),
+ wxFontMapper::GetEncodingName(m_encoding).c_str(),
+ wxFontMapper::GetEncodingName(encPart).c_str()
+ ),
+ m_notebook,
+ M_MSGBOX_LANG_CHANGED_WARN
+ );
+ }
+ }
+ }
+ }
+ }
+ else // ASCII only, no problems
+#endif // wxUSE_WCHAR_T
+ {
+ text = m_textControl->GetValue();
+ }
+
+
// Translate LF to CRLF. All internal strings should have only LF, but
// due to long bug tradition, many strings that contain messages have
@@ -1114,5 +1247,5 @@
//
// VZ: see above (FIXME)
- return new EditorContentPart(strutil_enforceCRLF(m_textControl->GetValue()));
+ return new EditorContentPart(strutil_enforceCRLF(text), encPart);
}
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates