A working solution - Stage 2

The following are obvious deficiencies/enhancements: What follows is a description of how each of these changes could be effected.

Start by saving the project with a different name - I use "TextView2".

Horizontal scrollbar

On the "Properties" menu select "Control Styles" to open up the options. "VScroll" is already "checked"; now do the same for "HScroll".

Re-sizing the text area

Choosing a display font

We need to add a new menu item to allow us to access the font-chooser. Go to the Menu Editor and add a menu item to the "File" menu. I have called it "MenuItem_Font" with the Caption "&Font" and I have moved it to be between the "Open" and "Exit" items.

Using the Code Editor add the following to the "General" area:

integer flags, points
atom colour
sequence font


These are now available to all parts of the program.
To avoid the program crashing if the user doesn't ask for any font setting prior to opening the file, we need to add some defaults. The following are suggested:

colour = Black
font = "Courier New"
points = 10
flags = Normal

Next find the "onClick" event handler for "MenuItem_Font" and add the code:

    sequence result
    result = getFontDialog (Viewer)
    font = result[1]
    points = result[2]
    flags = result[3]
    colour = result[4]


We now have the relevant font details stored in four variables available to the rest of the routines.

To get the font to apply to the file's contents when displayed we need to add something to the "onClick" event handler for "MenuItem_Open". Try adding the following to the end of the routine:

        setFont(TextArea,font,points,flags)
        setTextColor(TextArea,colour)


Now try testing this. Can you see when it works and when it doesn't? If we set the font before opening the file then the process works OK and the text is shown in the correct font/colour combination. But if we open the file and then chose a different font nothing changes!

If we move the declaration of the variable handle (in the "MenuItem_Open" routine) into the General area then we can test for it in the "MenuItem_Font" routine. For safety set the value to "-1" there.

Then add the following code to the end of the "onClick" event handler for "MenuItem_Font":

    if handle > 2 then
        setFont(TextArea,font,points,flags)
        setTextColor(TextArea,colour)   
    end if


Try it now! Note that the change would apply to a subsequent opening of (another) file.

Now move on to Stage 3.