Open Source Dolphin Smalltalk -

Unicode UI Experiment 1

After my initial Unicode UI Proof of Concept I moved on to experiment with ways to retrofit the existing view classes to add selective Unicode UI support.

They key parts of this experiment are:

  1. A new class variable has been added to View (WndClassAtomW).  This is used to hold an atom when we register the new Unicode capable window class 'DolphinWindowW'. See View<<wndClassNameW.
  2. To support maintain Unicode status a new mask (UnicodeMask) has been added for use with the flag instance variable in the View class.  The value chosen, 1024, appears to be available for use.  See View<<isUnicodeView.
  3. A few View methods have been revised to support Unicode/ANSI text branching. See the loose View methods in my package.
  4. The class UserLibrary has been subclassed by UserLibraryW. In UserLibraryW<<open: you can see that I get the handle of the superclass, rather than reopening the library.
  5. Methods have been programmatically added to UserLibraryW.  These methods are included in the package so they do not need to be regenerated in most cases.  The code I used to initially generate them is:
    uct := MitSciUnicodeTransformer new.
    uct scanForAnsiAPIFunctions.
    
    uct addUnicodeMethodsFrom: UserLibrary   to: UserLibraryW.
    This code adds Unicode function calls (ending in "W") corresponding to existing ANSI UserLibrary function calls (ending in "A").  Additionally potential helper methods are created.  Presently these helpers do nothing but redirect the message call. Helper functionality (such as coercing String to UnicodeString) could be added if desired.
  6. In order to get the existing system to use the new Unicode UserLibary functions we have to transform all View and all subclasses that directly refer to "UserLibary default" to use "self userLibary".  We also have to transform any methods that use "String new:" to use "self stringClass new:". The postinstall script executes this (after a warning):
    uct := MitSciUnicodeTransformer new.
    uct transformClassRefsFromCls: UserLibrary msgStr: 'default' to: 'self userLibrary' inAndAllSubClassesOf: View.
    uct transformClassRefsFromCls: String msgStr: 'new:' to: 'self stringClass new:' inAndAllSubClassesOf: View.
    
    Note that this transformation does not currently change the package of the modified methods.
  7. We need a way to allow a Presenter subclass to cause its view to be created as a Unicode view.  I have done this by using ShellView class<<createHookBlock: .  See TestUnicodeShell class<<loadViewResource:inContext: for an example.  In my example Presenter I have hardcoded the Unicode setting and a pseudo translation that just assigns Chinese text to all subviews.  In practice the view could be opened as either ANSI or Unicode and translation applied as needed.

Notes:

  1. The code transforms are currently mostly string replacement based rather than parser based.  I just did this so I could experiment quickly.  This may be inelegant, but seems to have worked well in this experiment.
  2. There are ANSI API calls in other libraries beyond UserLibrary.  This experiment makes no attempt to handle that.  A more complete implementation will need to cover those other API calls as well.
  3. System methods are changed to hook into my code.  This may break things!
  4. Obviously if important methods are changed in a running system there is a risk the image could crash.  If you want to play with tweaking this experiment then make sure you have a recovery plan for your work.
  5.  This is just an experiment and not presently suitable for production use.  It is my hope that these experiments may lead to an eventual more robust way for Dolphin to handle Unicode text in the UI.

Download Package: CJDUnicodeUIProject.pac (Released on 10/21/2016 by Chris Demers)

The package should be installed into an experimental test image.  I used Open Source Dolphin 7.0.5 for development.  When installing accept the prompt to allow it to change system methods.  Once it is installed you can evaluate:

TestUnicodeShell show.

This expiriment can be discussed in comp.lang.smalltalk.dolphin .