Skip to content

Commit f0738a8

Browse files
committed
If UTF-8 enabled, convert typed input from current code page into UTF-8
1 parent 14dbf2b commit f0738a8

File tree

1 file changed

+74
-43
lines changed

1 file changed

+74
-43
lines changed

sendvw.cpp

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -317,64 +317,95 @@ void CSendView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
317317
CMUSHclientDoc* pDoc = GetDocument();
318318
ASSERT_VALID(pDoc);
319319

320-
if (nChar == VK_RETURN)
321-
{
320+
// <enter> not hit? Just press on and let the edit view handle it
321+
if (nChar != VK_RETURN)
322+
{
323+
CEditView::OnChar(nChar, nRepCnt, nFlags);
324+
return;
325+
}
322326

323-
pDoc->m_iCurrentActionSource = eUserTyping;
327+
// here for <enter>
324328

325-
CString strText;
326-
GetEditCtrl().GetWindowText(strText);
327329

328-
// spell check on send?
329-
if (pDoc->m_bSpellCheckOnSend)
330-
{
331-
// look for scripting prefix
332-
if (pDoc->m_bEnableScripts && // providing scripting active
333-
!pDoc->m_strScriptPrefix.IsEmpty () && // and we *have* a script prefix
334-
strText.Left (pDoc->m_strScriptPrefix.GetLength ()) == pDoc->m_strScriptPrefix // and it matches
335-
)
336-
{ } // do nothing (don't spell check script commands)
337-
else
338-
{
339-
Frame.SetStatusMessageNow (Translate ("Spell check ..."));
340-
bool bOK = App.SpellCheck (this, &GetEditCtrl());
341-
pDoc->ShowStatusLine ();
342-
if (!bOK)
343-
return; // spell check was cancelled
344-
// get the text again, as the spell check may have changed it
345-
GetEditCtrl().GetWindowText(strText);
346-
}
330+
pDoc->m_iCurrentActionSource = eUserTyping;
331+
332+
CString strText;
333+
GetEditCtrl().GetWindowText(strText);
347334

348-
} // end of spell check wanted
349335

350-
// tell each plugin what we have received
351-
// the plugin callback OnPluginCommandEntered gets a chance to attack the entire command
352-
pDoc->SendToAllPluginCallbacksRtn (ON_PLUGIN_COMMAND_ENTERED, strText);
336+
if (pDoc->m_bUTF_8)
337+
{
338+
339+
// first convert input text to wide characters
340+
341+
// find how big table has to be
342+
343+
int iLength = MultiByteToWideChar (CP_THREAD_ACP, 0, strText, -1, NULL, 0);
344+
345+
// vector to hold Unicode message
346+
vector<WCHAR> vMessage;
347+
348+
// adjust size
349+
vMessage.resize (iLength);
350+
351+
// do the conversion now
352+
MultiByteToWideChar (CP_THREAD_ACP, 0, strText, -1, &vMessage [0], iLength);
353+
354+
// now convert back to UTF-8
355+
356+
iLength = WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR) &vMessage [0], -1, NULL, 0, NULL, NULL);
357+
358+
// get a string pointer
359+
char * buf = strText.GetBuffer (iLength);
360+
// convert into UTF-8
361+
WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR) &vMessage [0], -1, buf, iLength, NULL, NULL);
362+
strText.ReleaseBuffer ();
363+
}
353364

354-
// special string to indicate command should be discarded
355-
if (strText == "\t")
365+
// spell check on send?
366+
if (pDoc->m_bSpellCheckOnSend)
367+
{
368+
// look for scripting prefix
369+
if (pDoc->m_bEnableScripts && // providing scripting active
370+
!pDoc->m_strScriptPrefix.IsEmpty () && // and we *have* a script prefix
371+
strText.Left (pDoc->m_strScriptPrefix.GetLength ()) == pDoc->m_strScriptPrefix // and it matches
372+
)
373+
{ } // do nothing (don't spell check script commands)
374+
else
356375
{
357-
if (!pDoc->m_bAutoRepeat)
358-
SetCommand ("");
359-
return;
376+
Frame.SetStatusMessageNow (Translate ("Spell check ..."));
377+
bool bOK = App.SpellCheck (this, &GetEditCtrl());
378+
pDoc->ShowStatusLine ();
379+
if (!bOK)
380+
return; // spell check was cancelled
381+
// get the text again, as the spell check may have changed it
382+
GetEditCtrl().GetWindowText(strText);
360383
}
361384

362-
// special string to indicate command should be ignored
363-
if (strText == "\r")
364-
return;
385+
} // end of spell check wanted
365386

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

368-
// cancel any previous message on the status line
369-
pDoc->ShowStatusLine ();
391+
// special string to indicate command should be discarded
392+
if (strText == "\t")
393+
{
394+
if (!pDoc->m_bAutoRepeat)
395+
SetCommand ("");
396+
return;
397+
}
370398

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

374-
} // end of return key
403+
SendCommand (strText, FALSE);
375404

376-
377-
CEditView::OnChar(nChar, nRepCnt, nFlags);
405+
// cancel any previous message on the status line
406+
pDoc->ShowStatusLine ();
407+
408+
pDoc->m_iCurrentActionSource = eUnknownActionSource;
378409

379410
}
380411

0 commit comments

Comments
 (0)