Skip to content

Text Services

marksvc edited this page Jun 16, 2021 · 1 revision

Note: This page contains old documentation from 2008, but may still be of use.

According to MSDN the Text services framework "provides a simple and scalable framework for the delivery of advanced text input and natural language technologies"

Overview of text services and it's Linux equivalents The structure of input methods in GTK

Table of Contents

GtkIM and TSF

Similarities

Similarities:

  • Both use a message passing system with callbacks
  • Both query the document

Differences

TSF GtkIM
UTF 16 (?) UTF 8 (requires conversion)
Selection aware Independent of selection
Processes delete / backspace Application handles delete \ backspace
Does not have delete callback † Has delete callback ††
? Application has to handle backspace / delete

† Might use SetText?

†† Only for automatic (context sensitive) character removal.

Implementation

Most of the Text Services stuff seems to be concentrated in the VwTextStore class, which implements the ITextStoreACP interface.

It seems that to get a ITextStoreACP object the process is:

  1. CoCreateInstance()
  2. ITfThreadMgr::CreateDocumentMgr()
  3. ITfDocumentMgr::CreateContext()
In FieldWorks, Text Services are accessed through VwTextStore. Or maybe VwRootBox::OnTyping (and hence VwSelection::OnTyping and OnTypingMethod).

In C#, keypresses go through:

 SimpleRootSite.OnKeyPressEvent()
  EditingHelper.OnKeyDown()
   EditingHelper.CommitIfWord()
    EditingHelper.IsWordBreak()
    EditingHelper.Commit()
     IVwRootBox.get_Selection()  - <span style="color:red">C++</span>
      ...?
     DataUpdateMonitor.Commit() - <span style="color:red">Unported</span>
      ...?
   EditingHelper.HandleKeyPress()
    FwViews.VwShiftStatus
    EditingHelper.GetShiftStatus()
     Views + Gdk properties
    EditingHelper.CollectTypedInput()
     Views properties
     StringBuilder()
      .
     StringBuilder.Append()
      .
    EditingHelper.OnCharAux()
     Views properties
     ResourceHelper.MakeUndoRedoLabels()
      .
     IVwRootBox.get_DataAccess()
      .
     IVwRootBox.get_Site()
      .
     IVwRootBox.get_Selection()
      .
     IVwRootSite.ScrollSelectionIntoView
    EditingHelper.RemoveCharFormattingWithUndo()
     EditingHelper.GetCharacterProps()
      .
     EditingHelper.RemoveCharFormatting()
      IVwSelection.get_IsRange()
       .
      ITsTextProps.GetIntPropValues()
       .
      ITsTextProps.GetStrPropValue()
       .
      ITsPropsBldr.SetStrPropValue()
       .
      IVwSelection.SetSelectionProps()
       .
   IEditingCallbacks.ShowContextMenuAtIp()
    .
  SimpleRootSite.OnKeyPress()
   EditingHelper.OnKeyPress()
    EditingHelper.CommitIfWord()*
    EditingHelper.HandleKeyPress()*

Also, SimpleRootSite.OnButtonPressEvent() calls EditingHelper.CommitIfWord()

Replacement

There are a number of possible replacements for Text Services, including SCIM and KMFL. Fortunately, we do not need to write separate functionality for each one of these, as they are available as GTK input method modules.

Approaches to replacing Text Services:

  • Replace the Windows APIs (msctf.h)
  • Replace the Windows API calls (VwTextStore.cpp)
  • Replace the workings of the text store (VwTextStore.cpp)
The alternative as recommended by Doug is to use GTK via GtkIMContext. A good example of this is in Gtk's GtkEntry. Another, simpler example is Inkscape's text context

Interesting terms:

  • msctf.h - Windows headers for TSF stuff in FW
  • Doug (KMFL)
  • XIM \ SCIM \ KMFL
Clone this wiki locally