[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-dev] Text input broken

> Commit by  : luke
> Repository : xara
> Revision   : 785
> Date       : Thu Apr  6 17:52:30 BST 2006
> Changed paths:
>   M /Trunk/XaraLX/wxOil/unicdman.cpp
> A fix for seg. fault when entering text, surprised no-one else saw it

Unfortunately, this change has made text input much worse than it used 
to be. The symptom is that any character outside the ASCII range 
(e.g., an accented character in the Latin-1 range) is reported as code 
0000. More seriously, all subsequent keypresses, even ASCII 
characters, are reported as 0000, too, so once a non-ASCII character 
has been entered, the application has to be quit and restarted to 
enter any further text.

Find attached a patch (patch17.txt) to fix the fix - you should not 
pass a NULL state to mbrtowc. It is much better to pass a state 
initialised to 0 because that is well-defined.

However, the whole thing is not working anyway and I am not quite sure 
what the call to MultiByteToUnicode in TextTool::OnKeyPress is 
supposed to do. Surely, the whole multi-byte thing is only needed for 
OSes that do not have a wide key event interface so they need to send 
one byte of a multi-byte code per event and the application has to 
assemble them back again. This would only work if the application 
actually kept the multi-byte state around, which neither of the 
revisions of the above routine attempted to do.

>From what I can see, our keypress events do have proper Unicode 
character codes, so calling MultiByteToUnicode is harmful (which seems 
to be confirmed by the fact that, originally, the call in 
TextTool::OnKeyPress only happened for non-Unicode OSes - 
unfortunately, someone commented that out). Find attached below 
patch18, which disables the call and finally enables non-ASCII 
characters to be entered.

Index: wxOil/unicdman.cpp
--- wxOil/unicdman.cpp	(Revision 787)
+++ wxOil/unicdman.cpp	(Arbeitskopie)
@@ -279,7 +279,9 @@
 		return 128;
-	mbrtowc( ReturnArray, MBArray, cch, NULL );
+	mbstate_t			state;
+	memset(&state, 0, sizeof(mbstate_t));
+	mbrtowc( ReturnArray, MBArray, cch, &state );
 	return ReturnArray[0];
Index: tools/texttool.cpp
--- tools/texttool.cpp	(Revision 787)
+++ tools/texttool.cpp	(Arbeitskopie)
@@ -1064,14 +1064,17 @@
 				(pKeyPress->IsAlternative() && pKeyPress->IsConstrain()) ) // Ctrl & left alt down
 			WCHAR UnicodeValue = pKeyPress->GetUnicode();
+			TRACEUSER("wuerthne", _T("UnicodeValue from keypress event = %04x"), UnicodeValue);
 			if (HandleDeadKeys(pKeyPress, &UnicodeValue))
 				return TRUE;
 		 		if ( (UnicodeValue>=32) && ((UnicodeValue < CAMELOT_UNICODE_BASE) || (UnicodeValue > CAMELOT_UNICODE_LAST)))
 					if ((UnicodeValue < 256) /*&& !TextManager::IsUnicodeCompleteOS()*/)
 						UnicodeValue = UnicodeManager::MultiByteToUnicode(UnicodeValue);
 					// Display a blank cursor (thus hiding the pointer)
 					if (!IsBlankCursorUp)
@@ -1085,6 +1088,7 @@
 					OpTextFormat* pOp = new OpTextFormat();
 					if (pOp != NULL)
+						TRACEUSER("wuerthne", _T("inserting Unicode char %04x"), UnicodeValue);
 						pOp->DoInsertChar(UnicodeValue, OpTextFormat::INSERT);
 						UpdateAfterTyping = TRUE;
 						return TRUE;