Rich Edit Text Object Model project

Started by José Roca, January 17, 2025, 06:37:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

#45
New methods:

OpenDoc and SaveDoc.

Can open and save files in these formats: ansi, utf-8, unicode and rtf.

You can also load a file in a format and save it in another format.


New method:

ChangeCase

Changes the case of the characters in the specified range to lower case, upper case, title case, sentence case or it can toggle the case.

New methods:

Freeze and Unfreeze

If the freeze count is nonzero, screen updating is disabled. This allows a sequence of editing operations to be performed without the performance loss and flicker of screen updating.

Johan Klassen

hello José Roca  :)
I think that OpenDoc and SaveDoc will be immensely useful, thank you

Frank Brübach

hello jose, you have mentioned at first page to built in new features in your richEdit TOM library
and new interfaces

does that mean you can also load word files (*.doc) and Excel files (*.xls) ?

lRichEditOLE, lTExtrStrings, lTextStoryRanges.


José Roca

No. As I have said,

Can open and save files in these formats: ansi, utf-8, unicode and rtf.

José Roca

#49
I have made CRichEditCtrl zoomaable by adding the ES_EX_ZOOMABLE (&H0010) extended style.

' // EM_SETEXTENDEDSTYLE = ECM_FIRST + 10
' // EM_GETEXTENDEDSTYLE = ECM_FIRST + 11
DIM dwExStyle AS DWORD = SendMessageW(m_hRichEdit, ECM_FIRST + 11, 0, 0)
SendMessageW(m_hRichEdit, ECM_FIRST + 10, dwExStyle, &H0010)

I have used a magic number because the ES_EX_ZOOMABLE constant does not exist in the FreeBasic headers. It works like a charm.

I have tried to write a method to print RTF text. It prints, but the width and height of the page are not right.

As I don't have a printer, I'm testing it with "Microsoft Print to PDF".



José Roca

I've managed to get printing working.

I also have implemented an optional WYSIWYG option. If you pass the name of the printer, formating in the screen will be the same as it will be printed.

Also methods to get and set the position of the caret.

José Roca

Added two new methods:

AppendRtfFile

Appends the contents of an RTF file.

InsertRtfFile

Inserts the contents of an RTF file at the specified location.

José Roca

#52
Solved two problems with subclassed multiline edit rich controls.

1) If you press the ESC key, the control sends a WM_CLOSE message to its parent window, closing the application. The solution is to eat this keystroke. This can be done when processing the WM_KEYDOWN message.

2) TAB key. Its normal behavior in a rich edit control is to insert tabs and also provide naviagation between the cells of a table and to add a new row to the table y you press it in the last row and column. However, you may want to use it to provide navigation between controls. You can also eat it when processing VM_KEYDOWN, but then the control insists in inserting a tab. The solution is to eat it when procesing the WM_GETDLGCODE message

The subclassed CRichEditCtrl control uses the default behavior by default, but allows to eat the tab key and provide navigation between controls if the AcceptTab property is set to FALSE.

You can add tables by writing

+-----------------------+---------------------+---------------------+

and pressing the RETURN key.


Johan Klassen

José Roca
I am following your progress with great interest  :)

José Roca

Quote from: Johan Klassen on February 21, 2025, 11:35:28 AMJosé Roca
I am following your progress with great interest  :)

Thanks. I'm rediscovering this powerful control. It has changed very much since my first tests. For example, the addition of messages like EM_INSERTIMAGE and EM_SETTEXTEX allows the insertion of images and RTF text without having to use the more complicated and slower method of streaming. The methods that use EM_SETTEXTEX are faster because they read and set the whole file at once, whereas the methods that use EM_STREAMIN have to make repeated calls to load and set the rtf contents. One is faster but needs more memory and the other is slower but needs less memory. I will keep the two methods and the user will choose the one that it better suits him.

Also now we can use the TOM2 interfaces (previously, the older TOM interfaces could only be used with C++ because they used the thiscall calling convention). CRichEditCtrl already has support for all the Rich Edit messages and I will add support for all the methods of the ITextDocument2 interface. I have already added the most important ones: NewDoc, OpenDoc and SaveDoc.

For the other interfaces, I will write optional individual classes that you can easily use when you need them. CRichEditCtrl will have methods to get pointers to these interfaces (ITextFont, ITextRange, ITextPara, etc) and then you will only need to create an instance of the class, e.g. CTextFont, passing the retrieved pointer and use the methods that the class contain. This method has the advantage of not bloating CRichEditCtrl and also allows me to add functionalitry gradually (there are many interfaces, each one containing many methods).

Also, from my previous experience with other controls that I have wrote, like CXpButton, ex VB users and also writers of visual designers like Paul Squires, prefer properties than Get/Set methods. Get properties and methods are the same, but the Set methods allow to return a result code. To please everybody, I'm implementing both properties and methods.

After implementing a new method, I document it in GitHub. This has two advantages: it forces me to revise the code, sometimes discovering an error or making me to think of a way to improve it, and having the documentation always updated. I know by experience that if you delay this tedious task, then the work piles up and you never find time to do it.

This is the current documentation for CRichEditCtrl.

https://github.com/JoseRoca/WinFBX/blob/master/docs/RichEdit/CRichEditCtrl%20Class.md


José Roca

#55
I have removed LoadRtfFromFile and will use OpenDoc. The reason is that LoadRtfFile, that uses streaming, only works fine with RTF and ANSI files, while OpenDoc can also work with UTF8 and Unicode, and converts ANSI to Unicode. Also the OpenDoc method does not need callbacks.

José Roca

CRichEditCtrl now incorporates all the Rich Edit Windows messages and all the methods of the ITextDocument2 interface.

Documentation: https://github.com/JoseRoca/WinFBX/blob/master/docs/RichEdit/CRichEditCtrl%20Class.md

Tonight I will implement the CTextFont2, wrapping all the methods of the ITextFont2 interface.

Next, I will work in the ITextRange2 and ITextPara2 interfaces.

José Roca


José Roca


José Roca

#59
Rich Edit Control class versión 01.

CRichEditCtrl.bas demonstrates how to create an instance of the control.

The GUI has a button called "Test". Processing the IDC_TEST message you can add your code for testing.

The same source compiles to 32 or 64 bit without changes in the code.

Made with the aid of NI (Natural Intelligence). Not AI involved.

Documentation: https://github.com/JoseRoca/WinFBX/tree/master/docs/RichEdit