views:

582

answers:

4

I need a cross-platform editor control to use as GUI-part in an in-house tool. The control may be commercial, but with reasonable price.

Required features:

  • Platforms: Win32, OS X, Linux
  • UTF-8 support
  • Fine-grained run-time control to the text style (or at least color)
  • Nice low-level plain C API without usual horrible bloat
  • Should not prevent me to have these features (even if I'll have to implement them myself):
    • Undo / Redo
    • Copy / Paste
    • Context menu, depending on click position in text
    • Toolbar, depending on cursor position in text
    • Sidebar panel, depending on cursor position in text

Actually above requires not simple control, but whole cross-platform GUI library.

Discarded options:

  • Scintilla and descendants
  • FLTK
  • Fox-toolkit
  • gtksourceview

Update:

Note: I've slipped in some half-written discard reasoning here, I apologize. Scintilla indeed does work on OS X. However, if I get it correctly, Scintilla's API is in C++.

Use-case:

My use-case is to write custom "semi-rigid" logic editor, where user is free to copy-paste around, add comments where he wishes, even type in text directly if he wish. But text structure is a rigid natural language representation of logic tree (somewhat AST-like in nature). I plan to write something intellisense-like (or code-template-like) to be used as the main authoring tool (instead of typing logic by hand).

BTW, storage format would not be plain text, but instead internal representation of mentioned logic tree (with comments and whitespaces etc. metainfo).

So, I have all necessary information to render text in needed colors by myself. I do not need any external lexers etc.

+2  A: 

Scintilla and descendants (no OS X)

But, scintilla does work on OS X.


You could try GTK+ with GtkTextView, or Qt's QTextEdit.

John Millikin
My apologies. Note of OS X just slipped in (along with half-written reason for FLTK).
Alexander Gladysh
1. GtkTextView: Am I right that to get GTK+ on OS X, you have to install a ton of packages with ports? (At least that is how I've did it.) It is too heavy for me.2. QTextEdit: it is C++.
Alexander Gladysh
1. No, use the framework installer at http://www.gtk-osx.org/ 2: There's not many cross-platform editors, you'd be a fool to discard one just for being written in C++.
John Millikin
+2  A: 

As John wrote, Scintilla is known to run on OS X.
Now, it is not a rich text component, if that's what you are looking for. It is a source code editor: you can't apply arbitrary colors to arbitrary segments of text, it uses a lexer to style the content.

You didn't tell us what is your use case.

[EDIT] Thanks for adding the use case.

Disclaimer 1: I don't try to "sell" Scintilla, I just try to provide you information about a component I know well, hoping that helps you... :-D
Note that the Related Sites page lists a number of alternative Editing Components which can be interesting (or not, lot of them are for Win32 only).
Disclaimer 2: I have no experience of using Scintilla outside of the Win32 platform.

But looking at the source tree, I see a scintilla/macosx folder. Among other things, it has a SciTest sub-folder with a main.cpp file. Despite its extension, it strongly looks like pure C for me. So it can be an example of how to use Scintilla in C.

Note that by design, Scintilla API is very limited: it was initially made to be used as most traditional Win32 components, by sending messages to it. The Scintilla Documentation page only lists these messages and their parameters. The main.cpp example creates the window with the component in MacOS X style and sends commands with lines like scintilla->WndProc(SCI_STYLESETFORE, 0, 0x808080);

I won't claim it does everything you need, or even that it works flawlessly on MacOS X, you have to experiment (or ask the author of the adaptation) to be sure.
Also Scintilla won't provide a toolbar nor a sidebar panel (this belongs more to the application itself). But I think it can provide enough notifications to help you keeping these side components on context.
You will need also to write a specific lexer (C++ here) for your syntax. It isn't hard if you look how works other lexers. Perhaps you will find one for a language close enough to be used as a starting point.
Perhaps of interest too is a feature to set some portions of document as read-only, although I believe this haven't been thoroughly tested.

HTH.

PhiLho
I've added the use case.
Alexander Gladysh
About Scintilla and lexer: sorry, I've described my situation poorly. I have no use for lexer. My data structure is quite rigid (albeit represented to user as natural language text), and I know all needed text styles from it. Writing lexer would be unnecessary complication.
Alexander Gladysh
Lexer: they are optional in Scintilla, they are just the standard way of doing syntax coloring. But you can either have no coloring at all, or use another way of coloring (the client program can send messages to apply arbitrary styles to any segment of text).
PhiLho
+1  A: 

Well, you might be able to use tk -- the text widget is supposedly good and flexible -- have a looksie at the tcl/tk wiki.

Or you could go for some embedded/game toolkit (like Agar) -- but there a text widget with editing capabilities would be more cumbersome, I imagine.

But saying you want to do a cross-platform C GUI and then writing off GTK seems like a whole lot of wasted time and effort, to me. You'll probably end up switching languages or using GTK.

gnud
+1  A: 

FLTK's TextEditor widget is all you need. It is simple, straightforward, and easy to use, has utf8 and you can easily have text-styles. With just few lines you can have an editor. Check the /test/editor.cxx example. It works perfectly on OSX as well. Furthermore, all you need is explained here: http://www.fltk.org/doc-1.1/editor.html .