Advertisement
m3d10n

t3d_1_1_unicode.patch

Oct 9th, 2011
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- gui/controls/guiMLTextEditCtrl.cpp  Mon Jan 19 19:26:36 1970
  2. +++ gui/controls/guiMLTextEditCtrl.cpp  Mon Jan 19 19:26:36 1970
  3. @@ -434,6 +434,46 @@
  4.     ensureCursorOnScreen();
  5.  }
  6.  
  7. +bool GuiMLTextEditCtrl::onChar(const GuiEvent &event)
  8. +{
  9. +   if ( (mFont && mFont->isValidChar(event.ascii)) || (!mFont && event.ascii != 0) )
  10. +   {
  11. +      // Normal ascii keypress.  Go ahead and add the chars...
  12. +      if (mSelectionActive == true)
  13. +      {
  14. +         mSelectionActive = false;
  15. +         deleteChars(mSelectionStart, mSelectionEnd);
  16. +         mCursorPosition = mSelectionStart;
  17. +      }
  18. +
  19. +      UTF8 *outString = NULL;
  20. +      U32 outStringLen = 0;
  21. +
  22. +#ifdef TORQUE_UNICODE
  23. +
  24. +      UTF16 inData[2] = { event.ascii, 0 };
  25. +      StringBuffer inBuff(inData);
  26. +
  27. +      FrameTemp<UTF8> outBuff(4);
  28. +      inBuff.getCopy8(outBuff, 4);
  29. +
  30. +      outString = outBuff;
  31. +      outStringLen = inBuff.length();
  32. +#else
  33. +      char ascii = char(event.ascii);
  34. +      outString = &ascii;
  35. +      outStringLen = 1;
  36. +#endif
  37. +
  38. +      insertChars(outString, outStringLen, mCursorPosition);
  39. +      mVertMoveAnchorValid = false;
  40. +      return true;
  41. +   }
  42. +
  43. +   // Otherwise, let the parent have the event...
  44. +   return Parent::onChar(event);
  45. +}
  46. +
  47.  //--------------------------------------------------------------------------
  48.  void GuiMLTextEditCtrl::onRender(Point2I offset, const RectI& updateRect)
  49.  {
  50. --- gui/controls/guiMLTextEditCtrl.h    Mon Jan 19 19:26:36 1970
  51. +++ gui/controls/guiMLTextEditCtrl.h    Mon Jan 19 19:26:36 1970
  52. @@ -20,6 +20,7 @@
  53.  
  54.     // Events
  55.     bool onKeyDown(const GuiEvent&event);
  56. +   bool onChar(const GuiEvent &event);
  57.  
  58.     // Event forwards
  59.     void handleMoveKeys(const GuiEvent&);
  60. --- gui/controls/guiTextEditCtrl.cpp    Mon Jan 19 19:26:36 1970
  61. +++ gui/controls/guiTextEditCtrl.cpp    Mon Jan 19 19:26:36 1970
  62. @@ -1576,6 +1576,16 @@
  63.     execConsoleCallback();
  64.  }
  65.  
  66. +bool GuiTextEditCtrl::onChar(const GuiEvent &event)
  67. +{
  68. +   if ( mProfile->mFont->isValidChar( event.ascii ) )
  69. +   {
  70. +      handleCharInput( event.ascii );
  71. +      return true;
  72. +   }
  73. +   return Parent::onChar( event );
  74. +}
  75. +
  76.  S32 GuiTextEditCtrl::findPrevWord()
  77.  {  
  78.     // First the first word to the left of the current cursor position
  79. --- gui/controls/guiTextEditCtrl.h  Mon Jan 19 19:26:36 1970
  80. +++ gui/controls/guiTextEditCtrl.h  Mon Jan 19 19:26:36 1970
  81. @@ -114,6 +114,7 @@
  82.     void setSinkAllKeys(bool state) { mSinkAllKeyEvents = state; }
  83.  
  84.     virtual bool onKeyDown(const GuiEvent &event);
  85. +   virtual bool onChar(const GuiEvent &event);
  86.     virtual void onMouseDown(const GuiEvent &event);
  87.     virtual void onMouseDragged(const GuiEvent &event);
  88.     virtual void onMouseUp(const GuiEvent &event);
  89. --- gui/core/guiCanvas.cpp  Mon Jan 19 19:26:36 1970
  90. +++ gui/core/guiCanvas.cpp  Mon Jan 19 19:26:36 1970
  91. @@ -632,6 +632,11 @@
  92.           return mFirstResponder->onKeyRepeat(mLastEvent);
  93.        }
  94.     }
  95. +   else if(inputEvent.action == SI_CHAR)
  96. +   {
  97. +      if(mFirstResponder)      
  98. +         return mFirstResponder->onChar(mLastEvent);
  99. +   }
  100.     return false;
  101.  }
  102.  
  103. --- gui/core/guiControl.cpp Mon Jan 19 19:26:36 1970
  104. +++ gui/core/guiControl.cpp Mon Jan 19 19:26:36 1970
  105. @@ -922,6 +922,18 @@
  106.  
  107.  //-----------------------------------------------------------------------------
  108.  
  109. +bool GuiControl::onChar(const GuiEvent &event)
  110. +{
  111. +   //pass the event to the parent
  112. +   GuiControl *parent = getParent();
  113. +   if (parent)
  114. +      return parent->onChar(event);
  115. +   else
  116. +      return false;
  117. +}
  118. +
  119. +//-----------------------------------------------------------------------------
  120. +
  121.  bool GuiControl::onKeyUp(const GuiEvent &event)
  122.  {
  123.     //pass the event to the parent
  124. --- gui/core/guiControl.h   Mon Jan 19 19:26:36 1970
  125. +++ gui/core/guiControl.h   Mon Jan 19 19:26:36 1970
  126. @@ -741,6 +741,10 @@
  127.        /// Happens when a key is held down, resulting in repeated keystrokes.
  128.        /// @param   event   Event descriptor (which contains the key)
  129.        virtual bool onKeyRepeat(const GuiEvent &event);
  130. +
  131. +      /// Happens when a character is typed
  132. +      /// @param   event   Event descriptor (which contains the character)
  133. +      virtual bool onChar(const GuiEvent &event);
  134.        /// @}
  135.        
  136.        /// Return the delegate used to render tooltips on this control.
  137. --- platform/event.h    Mon Jan 19 19:26:36 1970
  138. +++ platform/event.h    Mon Jan 19 19:26:36 1970
  139. @@ -262,6 +262,9 @@
  140.  
  141.     /// A key repeat occurred. Happens in between a SI_MAKE and SI_BREAK.
  142.     SI_REPEAT = 0x04,
  143. +
  144. +   /// Character input event
  145. +   SI_CHAR   = 0x05,  
  146.  };
  147.  
  148.  ///Device Event Types
  149. --- windowManager/win32/win32Window.cpp Mon Jan 19 19:26:36 1970
  150. +++ windowManager/win32/win32Window.cpp Mon Jan 19 19:26:36 1970
  151. @@ -857,6 +857,7 @@
  152.     case WM_KEYDOWN:
  153.     case WM_SYSKEYUP:
  154.     case WM_SYSKEYDOWN:
  155. +   case WM_CHAR:
  156.         Dispatch(DelayedDispatch,hWnd,message,wParam,lParam);
  157.         return 0;
  158.     }
  159. --- windowManager/win32/winDispatch.cpp Mon Jan 19 19:26:36 1970
  160. +++ windowManager/win32/winDispatch.cpp Mon Jan 19 19:26:36 1970
  161. @@ -115,6 +115,7 @@
  162.     // mapped in the global action map, try converting the event into
  163.     // a character event first.
  164.    
  165. +   /*
  166.     if(    make
  167.         && window->getKeyboardTranslation()
  168.         && !window->shouldNotTranslate( torqueMods, newVirtKey ) )
  169. @@ -144,6 +145,7 @@
  170.              return;
  171.        }
  172.     }
  173. +   */
  174.  
  175.     // Produce a key event.
  176.    
  177. @@ -151,6 +153,12 @@
  178.     window->keyEvent.trigger(window->getWindowId(),_ModifierKeys,action,newVirtKey);
  179.  }
  180.  
  181. +static void _characterEvent(Win32Window* window,UINT message, WPARAM wParam, WPARAM lParam)
  182. +{
  183. +   if (wParam >= 32)
  184. +      window->charEvent.trigger(window->getWindowId(),0,wParam);
  185. +}
  186. +
  187.  
  188.  //-----------------------------------------------------------------------------
  189.  
  190. @@ -314,6 +322,11 @@
  191.         if (window)
  192.             _keyboardEvent(window,message,wParam,lParam);
  193.         break;
  194. +
  195. +   case WM_CHAR:
  196. +      if (window)
  197. +         _characterEvent(window,message,wParam,lParam);
  198. +      break;
  199.  
  200.         // NOTE: if wParam is NOT equal to our window handle then we are GAINING focus
  201.     case WM_SETFOCUS:
  202. --- windowManager/windowInputGenerator.cpp  Mon Jan 19 19:26:36 1970
  203. +++ windowManager/windowInputGenerator.cpp  Mon Jan 19 19:26:36 1970
  204. @@ -241,13 +241,15 @@
  205.     event.objInst     = KEY_NULL;
  206.     event.modifier    = convertModifierBits(modifier);
  207.     event.ascii       = key;
  208. -   event.action      = SI_MAKE;
  209. +   event.action      = SI_CHAR; //event.action      = SI_MAKE;
  210.     event.fValue      = 1.0;
  211.     generateInputEvent(event);
  212.  
  213. +   /*
  214.     event.action = SI_BREAK;
  215.     event.fValue = 0.f;
  216.     generateInputEvent(event);
  217. +   */
  218.  }
  219.  
  220.  
  221.  
  222.  
Advertisement
RAW Paste Data Copied
Advertisement