Liberty Basic is develeopped by Carl Gundel
Original Newsletter compiled by Alyce Watson and Brosco
Translation to HTML: Raymond Roumeas

Brosco's Liberty Basic Newsletter - Issue #7 - May 98

 
 

In this issue

  1. Writing a replacement for Notepad in LB - Part 2
 

Hopefully by now you have studied the code for the basic text editor and are now ready to put in all the things to make it that little bit special.

Because of size limitations with the newsletter, the full source code for the program can be downloaded from:

http://users.orac.net.au/~brosco/newsltr/lbnote2.zip

The first addition made to the program was the Most Recently Used (MRU) File history. To see how this works, you can download a simplified version called MRUMenu from my site.

The next thing we added is a graphic toolbar with tooltips.

Rather than having a separate BMP for each icon - I have made a single BMP that contains all the icons.

Here's the code that loads the BMP and displays it:

 
'********************* Load the Toolbar
    print #w.tb, "fill lightgray;backcolor yellow;color black"
 
    print #w.tb, "font Courier_New 0 16"
    loadbmp "btn","toolbar.bmp"
    print #w.tb, "drawbmp btn 0 0"
    print #w.tb, "flush"

Now we must define each of the HotSpots to Windows:

htb=hwnd(#w.tb)
    calldll #user, "GetDC",_
        htb as word,_
        hDC as short
 
    dim Region(13)
    R = 0
 
    for xbtn = 0 to 300 step 25 ' buttons are 25 pixels wide
        x2btn=xbtn+24
 
        calldll #gdi, "CreateRectRgn",_  ' Define a hotspot
            xbtn as short,_
 
            0 as short,_
            x2btn as short,_
            25 as short,_
            hRegn as short
        R = R + 1
        Region(R) = hRegn       'Save Windows Hotspot ID (handle)
        next xbtn
 

And then set up the functions to handle MouseOver.

 
    print #w.tb, "setfocus; when mouseMove [tooltip]"
    print #w.tb, "when leftButtonDown [check.button.down]"
    print #w.tb, "when leftButtonUp [button.back.up] "
 

And here is the ToolTips that will be displayed if the user moves the mouse over one of the graphic buttons.

dim tooltips$(13)
 
tooltips$(1) = "New File      "
tooltips$(2) = "Open File     "
tooltips$(3) = "Save File     "
tooltips$(4) = "Save AS       "
tooltips$(5) = "Print         "
tooltips$(6) = "Copy          "
tooltips$(7) = "Cut           "
tooltips$(8) = "Paste         "
tooltips$(9) = "WordWrap      "
tooltips$(10) = "Word Check    "
tooltips$(11) = "Spell Check   "
tooltips$(12) = "Help          "
tooltips$(13) = "Exit          "
 
 

The following code is activated if the user moves the mouse over one of the graphic buttons.

 
[tooltip]
 
    MX=MouseX           ' Get Mouse position
    MY=MouseY
'                            erase tooltip-mouse not over button
    if MX>325 OR MX<5 OR MY<5 OR MY>15 then
        gosub [clear.tooltip]
        goto [loop]
        end if
 
    gosub [check.tip]       ' Check which region
 
    if rpoint = lastR then goto [loop]
 
    if rpoint>0 and rpoint<= 13 then
        toolTip$ = "  " + tooltips$(rpoint)
        print #w.tb, "place 500 16;";toolTip$ 
        lastR = rpoint
        end if
    goto [loop]
 

Please note the line:

    if MX>325 OR MX<5 OR MY<5 OR MY>15 then
 

Notice that MY is tested for values between 5 and 15 - but the button is 25 pixels high. If we tested for a value outside of 1 and 25, we would never get a result - because it would mean that the mouse had moved to another Control - so MouseOver would only be activated when it was over a button!

When the left button is clicked (Down) we will activate a routine to 'invert' the image colours. This will give a "positive" response to the user:

[check.button.down]
                'when left button clicked check for button clicked
    MX=MouseX:MY=MouseY
 
    gosub [check.tip]
    if rpoint>0 and rpoint<=13 then
        Rdown = Region(rpoint)
        gosub [invert.button]
 
        end if
    goto [loop]
 
[invert.button]
    calldll #gdi, "InvertRgn",_
        hDC as short,_
        Rdown as word,_
        r as ushort
    return
 
[check.tip]
    rpoint = int(MX / 25) + 1
    return

When the user releases the left button (button up), we need to restore the image to the original colours and then activate the appropriate function:

[button.back.up]
    'returns button to normal look when left mouse up
    gosub [clear.tooltip]
 
    if Rdown = 0 then goto [loop] ' no button inverted!
    gosub [invert.button]
    Rdown = 0
'               perform action for button selected
    if rpoint = 1 then goto [new.file]
    if rpoint = 2 then goto [open.file]
    if rpoint = 3 then goto [save.file]
    if rpoint = 4 then goto [save.as]
    if rpoint = 5 then goto [print.file]
    if rpoint = 6 then goto [copy.cb]
    if rpoint = 7 then goto [cut.cb]
    if rpoint = 8 then goto [paste.cb]
    if rpoint = 9 then goto [word.wrap]
 
    if rpoint = 10 then goto [word.check]
    if rpoint = 11 then goto [spell.check]
    if rpoint = 12 then goto [help]
    if rpoint = 13 then goto [close.w]
    goto [loop]
 

The WORD WRAP function first presents a dialog to determine the character width that the WRAP should take place. The width can either be entered into the TextBox, or the 'spin' control button can be used to increase or decrease the existing value.

NOTE: This Wrapping applies only to the existing text. If you enter additional text, you may need to apply Word Wrap again.

Also note that entering a larger Wrap Width will not expand a line, it is just used to set a maximum value for the width.

The code that performs the Wrap was taken from Carl's site. The modification here allows all the Wrapping to be performed in memory, rather than inputing from, and outputing to a file.

The SPELL CHECKER has two functions: Word Check and Spell Check. Word Check is used to check a single word. You copy a word to the clipboard, activate Word Check, then paste the word to the TextBox and click on SUGGEST. If the word is spelt incorrectly a list of suggestions will be made. Click on the suggestion that you want and it will be placed in the TextBox. From here you can copy the word to the clipboard and then paste it to the TextEditor.

Spell Check will check the entire document. You can Add words to the User Dictionary, replace incorrect words in the original text, etc.

The workings of the Spell Checker are beyond the scope of this newsletter. To understand more about how it works, download the Spell Check demonstration from M Rankin's site (or mine). It contains documentation on how the SoundeX algorithms works. The Binary Search techniques are explained in my Arrays Tutorial found on my site.

Also added to the Options menu is a FileSize menu item. I included this for my own purposes. Since the Newsletter Service provider (ListBot) restricts the newsletter size to 10Kb, I can use this option to keep a check on the size of the newsletter that I'm working on.

This final program uses code from:

Michael T Rankin - Spell Checker
Alyce Watson - Toolbar and Tooltips
Brosco & Alyce - Most Recently Used file list
Carl Gundel - Word Wrap (modified by Alyce)
 

ToolBox 3.0 - Message Boxand also probably some things that I have learnt from other postings. Thank you to all that have made your code available to the LB community.

Please post questions, comments, bugs, etc. to the message board on my site at:

      http://users.orac.net.au/~brosco
 

Alyce and I are also considering a version 3 of the LBNote program. Additions being considered are:

Font selection
bwcc.dll (for MessageBox)
Tabbbed notebook to allow multiple files to be Open simultaneously
etc.

If you have any interest in these (or other ideas) please post your comments to the message board.

*********************

Some thoughts on Graphic Toolbars.

The graphic Toolbar was included in this program because of the interest expressed in this topic by other LBers. If Alyce and I were writing this program for our own use - we wouldn't have bothered. Neither Alyce or I have any fondness for Graphical Toolbars in ANY program! To us, these little icons are like a set of hyrogliphics that have absolutely no meaning. Providing ToolTips is not the answer either. Why should I have to move the mouse over all the icons to find the Action that I want?

In our opinion you may provide a Graphic Toolbar if you wish, but don't assume that everybody will understand it. ALWAYS provide a TEXT oriented User Interface as well for the graphic illiterate people like us.

You will find that other users agree with this also. One LBer was so annoyed by a program that had a graphic toolbar (with tooltips) but no Text menu - he was inspired to write a program to get even with the graphicoholics of this world. In the zip file for the LBNote2 source you will find his small program called JUST4FUN.TKN - it is sums up the above comments beautifully!

Also see - Writing a replacement for Notepad in LB - Part 1


Newsletter written by: Brosco. Comments, requests or corrections to: brosco@orac.net.au Translated from Australian to English by an American: Alyce Watson - Chief Editor. Thanks Alyce.   Special thanks to Tom Watson (Alyce's 12 year old son) who did all the alpha/beta testing on the final program.