Open Source Dolphin Smalltalk -

Unicode UI Experiment 2

After my initial Unicode UI Proof of Concept I moved on to experiment ( Experiment 1) with ways to retrofit the existing view classes to add selective Unicode UI support.  In this experiment I have continued to refine and expand my Unicode UI support.  See my prior posts for more background.

The key parts of this experiment are:

  1. In order to add Unicode support for menus I have had to create a way for the system to know (make an educated guess) about whether the active (or pre-active) view is Unicode.  Before a view is opened it won't be seen as active.  So I can't just use View<<activeHandle .  I've gotten around this by adding an accessor to expose the lastWindow instance variable of the InputState.  This is used in MenuItem<<userLibary.
    userLibrary
    
    	^((UserLibraryW default isWindowUnicode: SessionManager current inputState lastWindow asParameter) 
    		ifTrue: [UserLibraryW] ifFalse: [UserLibrary]) default
    This approach is inelegant and not guaranteed to be correct. In most cases a deployed application will either be Unicode or ANSI so there is less chance of it being wrong.  I need to support mixed mode mostly for development.  I am open to an improved handling.
  2. There are cases where the class of a string argument can be used to determine which kind of function to use (Unicode or ANSI). This is how I've done that.
    userLibraryForString: aStringOrUnicodeString
    
    	^((aStringOrUnicodeString class == UnicodeString ) 
    		ifTrue: [UserLibraryW] ifFalse: [UserLibrary]) default
    Then I used an automated code transform to detect and change methods with likely string arguments (argument names ending with "String").
    uct := MitSciUnicodeTransformer new.
    uct transformSelfMsgStr: 'userLibrary '
    	to: 'self userLibraryForString:' 
    	whithStringArgVarNameInAndAllSubClassesOf: View.
    There may be ways to look at string elements inside structures to determine whether to use a Unicode or ANSI function.  I am not presently doing that.
  3. Unicode Support has been added to the ListView class. I had to manually modify a number of methods.  See loose methods of ListView in the package.  The Windows SysListView32 control uses different messages and notifications for ANSI and Unicode.
  4. I have had to change UnicodeString<<displayString so that it returns self rather than converting to a String.  This was done to prevent UnicodeStrings from being converted to Strings by calls to displayString in ListView<<textFromRow: .  This may change functionality when displaying UnicodeStrings in non-Unicode views however as UnicodeStrings become supported in the UI it seems appropriate.  Presently, the method asString will still convert a UnicodeString to a String.  That may be another dilemma.
  5. I've revised the Presenter<<loadViewResource:inContext: method to support conditional branching based on a class side isUnicodeMode method.  To enable Unicode support just add isUnicodeMode as a class method returning true. This only really applies to Shells or Dialogs.  This method could probably be moved to Shell if special handling for other Presenters is not needed.  The isUnicodeMode method would likely be connected to a translation framework.
  6. The example TestUnicodeShell has been enhanced to show more kinds of controls (ListView and Menu).  The leftmost button will add items to the list.  I added a TestNonUnicodeShell class so I could compare differences in message traces between a Unicode and non-Unicode window.

    Screen Capture

Notes:

  1. 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.
  2. I have not had much community feedback on this Unicode UI project.  I am hopeful to  

Download Package: MitSciUnicodeUI.pac (Released on 11/9/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 experiment can be discussed in comp.lang.smalltalk.dolphin .