October 30, 2020, 10:59:20 pm

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Andy's editor - An example of a rich edit control editor & documentation

Started by Andy, September 17, 2020, 04:00:39 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Welcome to my rich edit editor example program (BETA) edition.

Please read the whole post first.

Firstly a warning! before loading any of your files you must make a copy of them first.
Two months ago I had problems with the wrong code being saved to the wrong file, but after
working on the proglem I have had no such issues since.

So what have I got for you here?

The culmination of almost a full year's work to produce this editor.

I have posted it here in the "Tutorials" section as it is a working example of how to
write an editor program using a rich edit control.

If you have time then I need your help!

I am very proud of the fact I was able to keep on going with this program and get it
working - that said, there is only so much testing one person can do.

I don't know exactly how you use an editor, the things you find handy, the things you
you might want - I simply don't know that.

You will I am sure find bugs in it - please tell me so I am aware of them.

The purpose of the editor:

1. To learn about rich edit controls and how they work.
2. To make all IWBasic key words either uppercase or lowercase.
3. To colour all IWBasic key words.
4. To allow editing of a file.
5. To have auto complete of key words included.
6. To be able to find & search for things in the file being viewed.
7. To incorporate an undo & redo function.
8. To load multiple files.
9. To do fast colouring and scrolling.

To that end, it is done.

What this program is not or what you will see:

1. Not an example of the best programming
2. Repeated code - I make no appologies for this
Many times I have changed on part of the program only to find out it has messed
up one or more other things - so for now I have left it as it is.

The attachment:


In the attachment you will have the following

1. Xedit46 V2 . iwb (Bin \ Bin folder)
2. Xeditor    . inc (Bin \ Bin folder)
3. The user guide  (Bin \ Bin \Res folder - can open via the editor)
4. Comctl32  . lib (Copy to your Libs folder please)
5. Ctl        . lib (Copy to your Libs folder please)
6. Ctl        . inc (Copy to your Include folder please)
7. A guide to working with rich edit controls including a detailed
explanation of how to implement the undo & redo functions yourself.
(Think you will find that one interesting!)

How to compile:

1. Create a folder on your C drive.
2. Unzip the attachment.
3. Copy the .lib & .inc files over.
4. Go to the Bin folder & compile Xeditor46 v2.iwb as F8 (a single file compile)

I really do need feedback please, tell me if you like it, hate it, if it's useful or even
terrible!

Known issues:

Large files can take several seconds to load, this really hasn't been my focus here, but
it's something I will work on.

Future development:

1. Fix any bugs reported.
2. Look into the idea of a pre-compile file check.

I have already started this in a small way by checking how many ( ) [ ] (brackets) there
are on a selected line. I always miss a ")" and get a compile error.

3. To tidy up and use less repeated code.

Finally:

I have titled the program The 2020 Hindsight Editor, well we all have 20/20 hindsight, and it is the year 2020, if I only knew at the start what I know about rich edit controls now...

With all that said here goes...

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

I also wanted to say a very big THANK YOU to all of you who have any any way, shape or form helped me to get this far with the program.

Be it, solutions, hints, tricks, tips & feedback.... Thanks!

I've added a second attachment to the original post which has the exe file included.

I also thought it might be an idea to unpick the program a little for you.


The program unpicked.

The program contains a lot of very standard code such as creating controls,
showing / hiding them, and button clicks. These things will be of little
interest to you.

However, there are certain subroutines, chunks of code that you should home in on.

In the main program:

Subroutine - QuiteMode (wrongly spelt of course - should be QuietMode!)

I'm using

QuiteMode(1) switch before I set sel selections / colour / replace etc.
and when done
QuiteMode(0)

It stop visual highlighting, and greatly speeds up the process - recommended.

In the indlude file:

Subroutine - GetAllWordsOnLine.

This is the fastest way I have found to build up words on a line.
I am chaecking each character in that line to see if it is a
delimiter, i.e. anything other than letters A - Z (upper or lower case).

I'm using the ISTRING variable CheckLetter4, it looks like this:

ISTRING CheckLetter4[50] =  CHR$(34) + "' ,0123456789-+()[]=:<>&|.\/%*!<>^_~#?" + CHR$(9) + CHR$(13)  + CHR$(0) + CHR$(10) 'Includes tabs and quotations.

Now it could be argued that it would be faster to check the ASCII value of that character...

IF Letter >= ASC(...) or Letter <= ASC(...)

The answer to that question remains to be seen, as it stands for me, the operation is quick enough, but I should test it one day.


Subroutine - ColourLineZ.

Basically a variant of the above routine, I use this for key word matching, when we have a complete word I invoke another
subroutine called:

ChangeWordEditorZ.

This subroutine checks to see if the word is a key word, if so, it changes it to either uppercase / lowercase or as typed
depending on your preference. Either way, it is then coloured in the rich edit control and the program returns back
to subroutine ColourLineZ.

This process is repeated for every word on the line, and for every line it is told to check.


In the main program:

You will see the above process being called when you look at my now badly named GetTheScrollPos.

GetTheScrollPos was originally used to get the current scroll position first then colour what you can see on screen.

In most circumstances, the variable FirstVisLine is set like this:
FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0) - rHandle is a handle to my rich edit control.

Armed with the first visible line number, GetTheScrollPos will now colour from 2 lines before the first visible
line to the first visible line plus 30. I have 29 lines visible, so I'm just making sure here.

Subroutine - Rich_Edit_Handler.

This is the handler for the sub classed rich edit, it is a must that you sub class your rich edit or you will not
be able to control what happens for certain actions.

case WM_KEYDOWN

Some keys are not detected by WM_CHAR, so this is an important check as it will tell all key presses and what they are.

CASE WM_CHAR

Probably the most important one, if it's a letter / number / space etc then I record that letter in the Undo array.
But I still need CASE WM_KEYDOWN because key presses like the Delete key are not detected here.

In any case, the important thing to remember here is that there are some things I need to do / record / check before
the Rich_Edit_Handler does a RETURN, and some things I need to do after the Rich_Edit_Handler has returned.

In other cases, I don't want it to do anything else other than what I'm telling it to do.


Subroutines DoUndo & DoRedo.

These, I hope you find of particular interest and it would be better for you to both read the guide help file as you
flick your way through these two routines.

Subroutine - Search_And_Highlight.

For those of you who are interested in how I did the auto complete function, I will try to explain here.

The process:

I'm using a fast timer

CASE 10000 - a control number way out of the other main controls.

In there I am getting all the words for the line you have clicked on.
(sub routine GetAllWordsOnLine - located in the include file).

I am also calling the subroutine GetAllWordsOnLineKeyWord - located in the include file, every time there
is a WM_CHAR action in the Rich_Edit_Handler routine.

All words on that line are stored in pointers called "w" & "m" and I have a global variable called WordCount.

Each word is stored like this:

(GetAllWordsOnLine sub)
WordCount ++
#w[WordCount].aWord    = WordIn
#w[WordCount].StartPos = StartPos
#w[WordCount].EndPos  = EndPos
#w[WordCount].Length  = (EndPos - StartPos)

(GetAllWordsOnLineKeyWord)
WordCount ++
#m[WordCount].aWord    = WordIn
#m[WordCount].StartPos = StartPos
#m[WordCount].EndPos  = EndPos
#m[WordCount].Length  = (EndPos - StartPos)

WordCount is zeroed before every call just in case you were wondering.

The #w pointer tells me what the word was before typing a character.
The #m pointer tells me what the word is now.

I then check the edit position, i.e. where you are on that line.
If the edit position has changed I update the word number edit box on screen to display the word number, that is to say
you are on word 1 or word 2 etc.

In the normal handler called main, under

CASE 1 'Rich edit
    CASE @ENCHANGE

I get the word number I am on from the word number edit box, and pass that word to the
search and highlight routine like this:

TheWordSelected = VAL(getcontroltext(w1,WordNumberEdit))
Search_And_Highlight(1,#m[TheWordSelected].aWord)

Search_And_Highlight will try to find any possible matching key words like

OPENCONSOLE
OPENFILE etc when the word we are on is "open".

When key words are being show on screen, I set a global variable called kw to 1, otherwise it's zero.

Finally, should I press the enter key on a highlighted key word (shown in a list view control) and kw = 1
the word that I'm on is replaced with the key word.

The whole line is then re-coloured and key words are set to uppercase / lowercase etc.

Simple yes? - nope!

Hope again, this is a little clearer than mud for you all.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

For those of you who just want to read through the editor user guide, I have added it as a separate attachment so you ca have a look at it and see what the program does, and what the functions / buttons do.

The attachments are at the top of this post.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.