Tuesday, October 12, 2004

RichTextEditor

Wangdera is my company (my wife's name is Wang - get it?), and I've set up a Source Forge project for us to publish whatever we feel like. Well, tonight I shipped the first release of the Wangdera Control suite. If you download Wangdera.Controls.dll, what you'll get is two Windows Forms controls:



  • RichTextBox2 - extends the Windows Forms RichTextBox control to allow you to do more types of formatting, as well as giving you a way to apply a whole bunch of formatting all at once in an efficient way.

  • RichTextEditor - extends RichTextBox2 with autocomplete lists and enhanced change notification.

I'm particularly excited about RichTextEditor, because autocomplete lists plus decent change notification plus advanced styling mean it's a pretty good basis for building simple (and perhaps not-so-simple) IDEs. I've already used it at work to write a lightweight SQL statement editor that turns keywords blue and strings green. I call it RichTextEditor not because I mean for it to edit Rich Text, but because I mean for it to be a text editor with rich display capabilities.


I wrote RichTextEditor with a particular goal in mind. You probably know that I've been working on FlexWikiPad for close to a year now. I've been using the scintilla control in it until now, via the ScintillaNET wrapper that makes it usable from .NET. For the most part, it's a pretty solid component, but I've always found the API to be a bit weird. And lately I've started to rub up against the edges of the styling model...nothing I couldn't work around, but it would make me do some stuff in a way I don't like.


Before running off to reinvent the wheel, though, I poked around a bit to see if I could find something else. The #develop IDE has an open source text editor component, but it's GPL, and that would make it hard for me to use in the places I want to use it. So I started looking at RichTextBox. It almost worked, and I figured if I could just tweak one or two things...two months later here I am, a shiny new invention I call “the wheel“ in my hand.


I could have just rolled RichTextEditor into the FlexWikiPad code, but I thought that this is the sort of thing that other people would want to use standalone. Hence the release in the Wangdera.Controls package. If you have a use for it, give it a try and let me know about any bugs or feature requests you might have.


My plan from here is to start integrating RichTextEditor into FlexWikiPad, while at the same time completely overhauling the formatting engine in FWP. I think I can increase performance, increase flexibility, and increase capabilities all in one go. Well see, of course; RichTextEditor works well enough in my tests but the true test is employing it in a real world application.


Here's a screenshot of the sample app I include with the Wangdera.Controls package. It shows some of the capabilities of RichTextEditor:


21 comments:

  1. Ignore my comment above .. I missed the part where you say you were using the Scintilla stuff first...



    :)



    ReplyDelete
  2. Ugh, RTF. I feel your pain, but..



    What the world needs now, and I mean right f'ing now, is a fully managed HTML rendering engine. Wrapping IE in blankets of interop is not a valid solution. We need to bite the bullet and do it.

    ReplyDelete
  3. Jeff - I agree! Why has noone made a table editor on par with Dreamweaver? Microsoft is surely aware that every table editor they've ever made sucks...

    ReplyDelete
  4. You can choose to completely ignore RTF with RichTextEditor (in fact that's the preferred programming model), so I'm not sure I understand your "Ugh". Can you explain further?



    As far as using an HTML rendering engine instead, I think that's a great idea. Why does it need to be fully managed, though? Every single control in WinForms is interop to an unmanaged piece of code, and that seems to work well enough. Also, do you think that an HTML-based engine would give you a reasonable way to enter and edit text, as you would do in scenarios where you're building an IDE? That's the primary usage pattern I'm interested in right now.

    ReplyDelete
  5. Well, one reason we need a managed HTML rendering engine-- and I'll admit, this is a purely selfish reason-- is the NINE MEGABYTE interop dll that gets generated when you reference IE in .NET. As a developer of smart client apps, that's pretty much out for us. We'd have to spool down a ~9mb interop DLL, via HTTP, to every client at least once.



    Like any self-respecting developer, I hate my users, but not that much. Yet.



    I guess what I object to most is that we have *one* option, IE interop, and that sucks. Having two or three different HTML rendering engines I could access from .NET code would be nice, even if they were all interop-y.



    In the long term, all code should be managed code, so it's really just a matter of time and patience, I guess.

    ReplyDelete
  6. So, is it an option for someone to write a managed wrapper around the Gecko engine that Firefox uses? If you wrote in it a combination of Managed C++ and C#, you could probably get it done relatively quickly.

    ReplyDelete
  7. Good ol' Lutz. A few observations, though:



    1) Having looked at the source code a bit, it appears to me that this is entirely an interop wrapper around IE.

    2) It doesn't provide intellisense-type popup error handling, which I need.

    3) It doesn't seem to provide a way to handle clicking on a link, which I also need.



    #1 isn't much of a concern for my usage in FlexWikiPad. #2 & #3 are must-haves.



    Since there's no way I'm going to work on a GotDotNet project again, and since I just experienced first-hand what it takes to move a GDN project to SourceForge, I'm in a bit of a quandry. I'd like to see if I can get Lutz's thing to work, since using an HTML-based editor makes waaay more sense in FlexWikiPad than an RTF-based one. But I need for the licensing to work out so I can basically take his code, modify it, and re-release it under the CPL. The problem is, I'm not sure that the Shared Source license allows for that.



    Looks like I'll need to contact Lutz and see what we can work out. Unless someone out there can interpret the GDN license for me?

    ReplyDelete
  8. One quick question: does this support text wrapping? Syncfusion has a full-featured IDE-like editor control that I was trying to use for on-the-fly spell checking in my application (let's hear it for red wavy lines), but they seemed never to work out the kinks for text wrapping. Does this?

    ReplyDelete
  9. Yes. Word wrap is supported. In fact, you can choose whether or not you want it via the WordWrap property.

    ReplyDelete
  10. At some point in any WinForms project, you're bound to need either: WYSIWYG text entry areas with text formatting Quick and dirty printed report generation The obvious choice for both of these things is HTML. No problem! I'll just...

    ReplyDelete
  11. It should be backwards compatible, since it derives from the standard control. As far as fast, well, I did my best - let me know if you have any problms with it.

    ReplyDelete

  12. I like what you have done with this and I would like to use it in a utility for SQL coding. However, I find it annoying that after the control has done it's syntax highliting, that it causes the current cursor location to scroll to the top of the edit control. I may not be doing it completely right as that I am still parsing the whole text after every keystroke. Is there a way to stop that behavior? It is very distracting.

    ReplyDelete
  13. I don't get that behavior in the sample app that ships with the control. Are you doing something different from what I'm doing in RichTextEditorSamples?

    ReplyDelete
  14. I did some additional testing on your sample app. I don't think that I modified the code in any of my testing.



    If you have the syntax highlighting on, paste a large amount of text in the control such that you are scrolling. When you type into the control(not on the top line) it will either scroll your cursor to the top if nothing is highlighted, or it will try to scroll towards the last syntax highlited text while keeping your cursor on screen.



    If you have horizontal scrolling enabled, it will also scroll horizontally, which is even more distracting.

    ReplyDelete
  15. Ah, OK, I didn't see the problem until I started typing somewhere in the middle. Now I can totally reproduce the problem.



    Sigh. This one is obviously a major bug. I was planning on doing a release this week, but I'll have to I'll see what I can do about it first.



    I have to tell you, RichTextBox is becoming the bane of my existence. It *almost* doesn't suck.

    ReplyDelete
  16. OK. I fixed it. The changes will appear in the next release, which I'm trying to shove out this week. I'll check everything in now so you can grab the source if you need it right now.

    ReplyDelete
  17. Thanks, that did the job. Great work.



    Keep it up. I hope that it is not that bad of a project to work on and am hoping that it is not really the bane of your existence because I really like it thus far.

    ReplyDelete
  18. Thanks. So far it has been pretty interesting. It's just one of those situations where RichTextBox is quirky enough that I keep expecting to run into something that I *can't* code my way around. Double-click was one that almost killed me - I had to rewrite all the mouse click code to fix that one.



    Anyway, I need the control for FlexWikiPad, so I'll continue to work on it. Next up: paragraph formatting. Then a round of intense bugfixing, and then I'll call it 1.0.

    ReplyDelete
  19. Just found your website, this is just what i have been looking for, for my code editor :)



    One quick question: Can i have comment highlighting? e.g: if the user types...



    // This is a comment,everything typed after this will be color highlighted



    Thanks,

    Joe.

    ReplyDelete
  20. You can have whatever you want...but it'll be up to you to implement it. :) Have a look at the sample that ships with the code - it parses and updates stuff based on syntax. You could do something similar.

    ReplyDelete
  21. i'd really like richtext editor.!!!

    ReplyDelete