Skip to content

Commit

Permalink
Reverted changes to UTF-8 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Jul 31, 2013
1 parent 449d34a commit def1a4f
Showing 1 changed file with 43 additions and 74 deletions.
117 changes: 43 additions & 74 deletions sendvw.cpp
Expand Up @@ -317,95 +317,64 @@ void CSendView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
CMUSHclientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

// <enter> not hit? Just press on and let the edit view handle it
if (nChar != VK_RETURN)
{
CEditView::OnChar(nChar, nRepCnt, nFlags);
return;
}

// here for <enter>


pDoc->m_iCurrentActionSource = eUserTyping;

CString strText;
GetEditCtrl().GetWindowText(strText);

if (nChar == VK_RETURN)
{

if (pDoc->m_bUTF_8)
{

// first convert input text to wide characters
pDoc->m_iCurrentActionSource = eUserTyping;

// find how big table has to be
CString strText;
GetEditCtrl().GetWindowText(strText);

int iWideLength = MultiByteToWideChar (CP_THREAD_ACP, 0, strText, strText.GetLength (), NULL, 0);

// vector to hold Unicode message
vector<WCHAR> vMessage;
// spell check on send?
if (pDoc->m_bSpellCheckOnSend)
{
// look for scripting prefix
if (pDoc->m_bEnableScripts && // providing scripting active
!pDoc->m_strScriptPrefix.IsEmpty () && // and we *have* a script prefix
strText.Left (pDoc->m_strScriptPrefix.GetLength ()) == pDoc->m_strScriptPrefix // and it matches
)
{ } // do nothing (don't spell check script commands)
else
{
Frame.SetStatusMessageNow (Translate ("Spell check ..."));
bool bOK = App.SpellCheck (this, &GetEditCtrl());
pDoc->ShowStatusLine ();
if (!bOK)
return; // spell check was cancelled
// get the text again, as the spell check may have changed it
GetEditCtrl().GetWindowText(strText);
}

// adjust size
vMessage.resize (iWideLength);
} // end of spell check wanted

// do the conversion now
MultiByteToWideChar (CP_THREAD_ACP, 0, strText, -1, &vMessage [0], iWideLength);

// now convert back to UTF-8

int iUTFLength = WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR) &vMessage [0], iWideLength, NULL, 0, NULL, NULL);

// get a string pointer
char * buf = strText.GetBuffer (iUTFLength);
// convert into UTF-8
WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR) &vMessage [0], iWideLength, buf, iUTFLength, NULL, NULL);
strText.ReleaseBuffer ();
}
// tell each plugin what we have received
// the plugin callback OnPluginCommandEntered gets a chance to attack the entire command
pDoc->SendToAllPluginCallbacksRtn (ON_PLUGIN_COMMAND_ENTERED, strText);

// spell check on send?
if (pDoc->m_bSpellCheckOnSend)
{
// look for scripting prefix
if (pDoc->m_bEnableScripts && // providing scripting active
!pDoc->m_strScriptPrefix.IsEmpty () && // and we *have* a script prefix
strText.Left (pDoc->m_strScriptPrefix.GetLength ()) == pDoc->m_strScriptPrefix // and it matches
)
{ } // do nothing (don't spell check script commands)
else
// special string to indicate command should be discarded
if (strText == "\t")
{
Frame.SetStatusMessageNow (Translate ("Spell check ..."));
bool bOK = App.SpellCheck (this, &GetEditCtrl());
pDoc->ShowStatusLine ();
if (!bOK)
return; // spell check was cancelled
// get the text again, as the spell check may have changed it
GetEditCtrl().GetWindowText(strText);
if (!pDoc->m_bAutoRepeat)
SetCommand ("");
return;
}

} // end of spell check wanted
// special string to indicate command should be ignored
if (strText == "\r")
return;

// tell each plugin what we have received
// the plugin callback OnPluginCommandEntered gets a chance to attack the entire command
pDoc->SendToAllPluginCallbacksRtn (ON_PLUGIN_COMMAND_ENTERED, strText);
SendCommand (strText, FALSE);

// special string to indicate command should be discarded
if (strText == "\t")
{
if (!pDoc->m_bAutoRepeat)
SetCommand ("");
return;
}
// cancel any previous message on the status line
pDoc->ShowStatusLine ();

// special string to indicate command should be ignored
if (strText == "\r")
pDoc->m_iCurrentActionSource = eUnknownActionSource;
return;

SendCommand (strText, FALSE);
} // end of return key

// cancel any previous message on the status line
pDoc->ShowStatusLine ();

pDoc->m_iCurrentActionSource = eUnknownActionSource;

CEditView::OnChar(nChar, nRepCnt, nFlags);

}

Expand Down

0 comments on commit def1a4f

Please sign in to comment.