|
Liberty BASIC Developer
Vol. 1 No. 3 September 2001
Contents:
Editors Note
LB News
Open Source: html editor
COMMAND Focus: Menu
Site links
Next Month
Feed back
Legal Stuff
Editors Note
Welcome to the third edition of Liberty BASIC Developer. I hope that you enjoyed last months issue. A special thanks to all who
responded publicly and privately.
It has been quite a busy month as I have finally installed my new hard drive and reinstalled most of my software. Unfortuneatly prior
to doing this I got a nasty virus. With all the warnings I've seen and normally give to others about opening attachments
from people I am unfamiliar with, I got stung. It became obvious that my virus scan software dat files were out of date as
it did not pick up on my error. Hopefully we can all remember this and not have to go through all the troubles of cleaning up
our systems.
With the current down turn in the technology industry there are some great deals to be had. I was able to increase the ram in this
system for quite a bargin. I guess I'll have to keep a look out for other items which I just can't do with out.
One last final note, I'm using the open source html editor to write this months issue.
Enjoy!
Neil Tremblay
top
LB News
If you haven't had a chance you should take a look at the work Carl has done on the
Liberty BASIC web site.
Its quite a cool new look with new features.
Captains Log. Computer date 27Aug2001, the last log up date was the addition of multiple and nested select case. End Captians
Log.
If you are not a subscriber to the lbexp group, you may wish to join just so that you can take a look at this message posted by
Dennis McKinney. It relates to data being transfered between programs and how to do the connection. What I think is cool is
that the calling program files a button in the receiving program to let it know that there is data to deal with. The message subject is
program to program, you can click on the link to go directly
to the message.
top
Open Source: html editor Part 2
Welcome back to our open source project of making an HTML editor. I hope that you had a chance in the past month to study up on
your html and what you want your editor to do. Last month I had directed your to Joe Burns
web site for his html goodies. Now that you are a guru I can get you to give me some pointers.
Here was our outline from last month for the html editor.
- LB text editor
FILE
- new file
- load file
- save file
- save-as file
- print
- exit
EDIT
- undo
- cut
- copy
- paste
- clear
- select all
- print selection
- find/replace
- find again
- exit
COMMANDS
- common
- font
- table
- link & graphic
- web links
- page links
- bookmarks
- graphic files
- time/date
So armed with the above information we can start to layout our program code. The first thing we do is fire up our copy of Liberty BASIC
and run freeform from the run menu. Now that we have freeform running we can set the window title, type and handle.
These being "My HTML editor" as the title, "window" as the type and we will use "#main" as the handle.
Starting at the top of our list we will add the texteditor control or widget as it is referred to in the Liberty BASIC help file.
This is done simply by clicking on the texteditor button on the left of the screen. Then it is just a matter of resizing it and moving it
to where it should approximately be. We do this by clicking and dragging the corner anchors.
I only position controls approximately at this time as we will readjust them after we generate our code and start adding the functionality.
Now it is time to add our menu commands, this is accomplished by clicking on the menu item in the menu bar or by right clicking
anywhere in the window and selecting add a menu from our popup menu. I will now add the following menu items.
- File
- Edit
- Common
- Font
- Table
- Links
- Options
- Help
You may have noticed that there is an Options menu selection in this list which was not in last months. I had a small bite of inspiration
and thought that we will be able to add some additional editor functions and this would be a good place to put them. I will discuss some
of these a little later in the article.
So now we are going to edit our menu items. You can do this by either clicking on menu in the menu bar or right clicking on a blank portion
of the screen and then by selecting edit menus. The File menu item is the first one that we will do. We select the File item in the menus list.
Next we will hit the new item button, this brings up a form entry box which will allow us to give our function a name and a branch label to
execute when ever it is selected. So we now enter these for the File menu item.
New [newFile]
Open [openFile]
Save [saveFile]
Save As [saveasFile]
Print [printFile]
Exit [exit]
This exercise will need to be performed for the remainder of our menu items. This is the list of commands which I added. I did not have
to add any thing to the Edit menu item as it will be filled automatically by the texteditor widget at program runtime.
Common
Bold [boldOn]
Italic [italicOn]
Center [centerOn]
Right [rightOn]
New line [newLine]
Font
Font size [fontSize]
Table
Table [tableStart]
Row [rowStart]
Data [dataStart]
Links
Web links [webLinks]
Page links [pageLinks]
Bookmark [bookMark]
Graphic Image [graphicImage]
Time/Date [timeDate]
Help
Help [help]
About [about]
Now that we have added all of our menu items I would like to add 1 more control. This is a button which will launch your web browser and
display the web page that you are working on. Press the text button control, a prompter box will appear, here we will enter the word Browse.
Click the OK button. The properties box will now appear for this control. Change the branch to [browse] and the .ext to browse. Click OK.
The properties window will close, click on the Browse button to make it the selected item. Click and drag it to the position that you want.
This is what your screen should look like.

We are now ready to generate our code outline. This would be a good time to save your work so that you would be able to come back later
and add other items if you wish. I am selecting the code output with outline to produce my program. When freeform is finished I close all
of its windows and return to the Liberty BASIC editor. You can now paste your generated code into the editor window.
I am also going to
add a template file that I use to help me break my program into different sections so that it will be easier to work on(for me that is). At this
point I reset the window size, the texteditor size and position and the button size and position so that when the program starts things
appear as I wish. To get my HTML commands into the texteditor window I need to add a second texteditor like this.
texteditor #main.tb,5,10,0,0
I am now going to also add the following lines of code. These go right after the open window code.
print #main, "font ms_sans_serif 12"
print #main.textedit1, "!autoresize";
print #main, "trapclose [exit]"
The first line sets the font of our program. The second line is a very powerful feature in that if the user resizes the program window
the texteditor will get resized for us. The last line traps the close event so that we can provide some handling features that we may
deem necessary. With trying to conform with structured programming, the next thing we will do is remove all the goto's from the
end of the event handler routines and replace it with the following.
input var$
We have to step back now and get out our pencil or crayon in my case. Starting with the File menu selection items we have to describe
what each of these functions is to accomplish. So starting with "New", the first thing that comes to mind is to clear the texteditor window.
But we can't leave it at just that. Our job as the programmer is to protect the user from them selves. To do this we need to check if there
has been any changes to the editor window. If the text has changed we should ask the user if he/she wishes to save it to file. If the user
wants it saved, has it been saved before. We will then get a file name from the user or just save the file. Then we will clear the texteditor
window.
Here is the code that results from this specification
[newFile] 'Perform action for menu File, item New
if fileSaved() = false then ' check to see if file has been modified
confirm "File changed! Do you want to save?";answer$ ' check if user wants file saved
if answer$ = "yes" then
if fileName$ = "untitled.htm" then ' check if file previously saved
filedialog "Save as html file", "*.htm", fileName$
end if
if fileName$ <> "" then
call fileSave fileName$
end if
end if
end if
print #main.textedit1, "!cls";
fileName$ = "untitled.htm"
input var$
This procedure is repeated for each of the menu commands, of defining further of what each should do, and then producing
the resulting code. You can view this code within the html editor source code.
Lets now take a look at how we will enter the different html tags in our source document. What I have decided I currently want
to do is just have the tags inserted at the current location of the cursor. This way the user can their formatting codes and then
type in the text that they want to use. To accomplish this we will need to use our invisible texteditor control which I will call our buffer.
So what we will do is print to the buffer the html tag we want to use. Next we will place the buffer contents at the current cursor
location in the texteditor control. As I am a lazy programmer, instead of writing out the same code for each html tag I created a
subroutine which when called will take the contents of the buffer and place it in to the texteditor control. Now the only code which
I need to enter for each menu command is the printing of my html tag to the buffer and then I call the subroutine which does the
rest of the work. This keeps my branch label routines smaller and easier to read. Also this should make my whole program smaller
as I am not repeating the same code over and over again. Here is the code for bold text and the subroutine for the buffer.
[boldOn] 'Perform action for menu Common, item Bold on
print #main.tb, " ";
call htmlinsert
input var$
sub htmlinsert
print #main.tb, "!selectall" ;
print #main.tb, "!cut" ;
print #main.textedit1, "!paste";
print #main.textedit1, "!setfocus";
end sub
In this first build of the HTML editor I have no options or help items. These will be added to in the next months issue. The last command
we should look at before finishing up for now is the browse button. It was suggested that I add this as it would make it simpler to
view our creation of a web page as we work on it. This required making an API call to accomplish, but it should work for most using
your default browser.
So what do you think so far about your HTML editor? What ideas can you come up with to improve and expand upon it? Some of the
things which I have thought of and had suggested to me are, display the current file name in the title bar, change the way common
commands are placed in the document if an area of text is hightlighted. How about a table building routine or a file dialog to get graphic
images. Let your imagination run wild! Hope to hear your comments and suggestions for next month.
Happy programming!
top
- COMMAND Focus: Menu
This month we will take a look at the menu command. I thought that this would be a good idea as we will be using it in our
open source html editor project.
The menu command provides us with pull down menu's for our program windows. By placing the menu command before we
open our window we can add menu items to our program. Here is the syntax for the use of the menu command from the
Liberty BASIC help file.
MENU #handle, "title", "text", [branchLabel], "text2", [branchLabel2], | , . . .
We start with the word "menu", which is the command to let Liberty BASIC know what we want to be done. This can be
in either upper, lower or a combination of case. eg MENU, Menu, meNu. Our next item "#handle", is the handle of the
window in which we wish our menu item to be displayed. You should be aware that the menu command can be used
for all window types except the dialog window. For our HTML editor I used the very exciting name of "#main" for the window.
For "title" I'll use the first one that we used which was "File". Now we will start to add our actual menu items, these consist of
a string of text and a branchlabel. The text is what will be displayed when we select our menu item. The branch label it the location
that the program jumps to when we select this menu selection. I like to refer to these branch labels as event handlers for
this selected menu item. So now we have some thing like this, "New", [newFile] . For single word menu items it is not necessary
to surround it in quotes, I do though as it keeps my source code consistant. We continue adding menu item pairs of text and
branch labels until we have all for that menu selection. Here is what it looks like from our open source project.
menu #main, "File",_
"New", [newFile],_
"Open", [openFile],_
"Save", [saveFile],_
"Save As", [saveasFile],_
"Print", [printFile],_
"Exit", [exit]
As you have noticed, I like to use the line continuation character "_", as I find it makes the code more readable and you don't
have lines going off of the screen. The above listing is fully functional. We can add another command to it to give us HOT keys for
our menu selections. We do this using the ampersand character, "&". It will look like this "&File". Now by pressing ALT-F, the file
menu will pull down. You will also notice that the F is underlined which is how it is designated as the HOT key. Now I want to
add this to all my menu selection items. Here is how my menu command will look now.
menu #main, "&File",_
"&New", [newFile],_
"&Open", [openFile],_
"&Save", [saveFile],_
"Save &As", [saveasFile],_
"&Print", [printFile],_
"E&xit", [exit]
We have one last command which we can use for the menu command. This is the separator, "|". We can use it to place a
separation bar between menu commands. This helps us group like commands. Here is how it looks in our full menu command.
menu #main, "&File",_
"&New", [newFile],_
"&Open", [openFile],_
"&Save", [saveFile],_
"Save &As", [saveasFile],_
"&Print", [printFile],_
|,_
"E&xit", [exit]
I hope that this brief explanation and example of the menu command will be helpful!
top
Site links
http://www.libertybasic.com Liberty BASIC home page
http://www.htmlgoodies.com HTML Goodies
program to program,by Dennis McKinney
The Liberty Belle Dennis McKinney's home page
HTML editor Open source, code
http://lcsoftlb.50megs.com Liberty BASIC software from the Left Coast. Editors home site
http://lbdev.5u.com Liberty BASIC Developer home page
top
Next Month
- Open Source: Html Editor
- Command Focus: Timer
top
Feed back
All readers feed back is welcome whether its to do with this issue, future acticles
or comments in general. Send your message to mailto:lbdev@lbdev.5u.com
Any one who wishes to submit an article for publication, please send it to the editor. mailto:lbdev@lbdev.5u.com
top
Legal Stuff
The Liberty BASIC Developer ezine and lbdev.5u.com are © Neil Tremblay 2001 all rights reserved.
top
|