Hi all, I've 'nearly' completed a Gtk2 WYSIWYG editor widget, and in the interests of saving someone else the trouble I'm posting it here. It's far from perfect, but for my current requirements it fits nicely. It also contains three other 'mini' packages - one for generating html from the text contents (and parsing it back in), one for the 'font size' selector widget (just makes certain actions easier) and one for 'formatted comboboxes' (which allows formatting in the menu without applying it to the main widget). It also has an unusual mode - 'as-is' - any text tagged as such could be considered a view into the underlying 'code' (this was designed for html, but anything would do) so that things the WYSIWYG can't understand or render can at least be included. Since it's a view into the code, as-is tagged stuff is yellow text on blue - like ye olde Edit in DOS. Assuming it is at least partially ok, I'll probably put it up on CPAN too. Some interesting things I learned while building this package: 1) Older versions of perl/Gtk2 complain _a lot_ about fill justification 2) Gtk2::TextBuffer's remove-tag signal becomes far less useful unless you realise that the start and end iters it recieves are just the ones given to $buf->remove_tag[_by_name]($tag, $s, $e), NOT the actual boundaries of where the tag previously existed 3) Gtk2::TextTag's 'left-margin' property acts as a right margin for right justified text. This turned out to be a bonus 4) As far as I can tell, there's no 'simple' way of telling a Gtk2::TextTag to render text as superscript or subscript - you have to calculate the rise based on the current font size. Currently superscript and subscript don't quite work right in Heading paragraphs (since Heading changes the size of the font as well, so the rise calculations don't work out). 5) The size of a Gtk2::ComboBox is the size of the largest option after rendering - that should have been obvious, but I still got a surprise (see the Normal/Heading dropdown and imagine the button being the size of Heading 1) 6) Making tooltips work for Gtk2::TextTags is annoying - making fake ones are easy :) 7) The default icon set is missing some important editing options (superscript, subscript, increase font size, decrease font size, 'pre' (although that one's kind of understandable) Anyway, I hope someone finds this useful at some point. It is partially pod-documented, and also partially # commented as well. I would have added more to the comments before posting it, but deadlines are looming and I have to start using it instead :) MB
Attachment:
WYSIWYG.pm
Description: Binary data