Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-platform editor control [closed]

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.

like image 524
Alexander Gladysh Avatar asked Oct 13 '08 06:10

Alexander Gladysh


4 Answers

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.

like image 95
PhiLho Avatar answered Sep 23 '22 14:09

PhiLho


Scintilla and descendants (no OS X)

But, scintilla does work on OS X.


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

like image 31
John Millikin Avatar answered Sep 24 '22 14:09

John Millikin


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 .

like image 34
user36393 Avatar answered Sep 21 '22 14:09

user36393


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.

like image 37
gnud Avatar answered Sep 23 '22 14:09

gnud