wxrichtextctrl overviewmajor classes: wxrichtextctrl, wxrichtextbuffer, wxrichtextevent helper classes: wxrichtextattr, wxtextattrex, wxrichtextrange file handler classes: wxrichtextfilehandler, wxrichtexthtmlhandler, wxrichtextxmlhandler style classes: wxrichtextcharacterstyledefinition, wxrichtextparagraphstyledefinition, wxrichtextliststyledefinition, wxrichtextstylesheet additional controls: wxrichtextstylecomboctrl, wxrichtextstylelistbox, wxrichtextstylelistctrl printing classes: wxrichtextprinting, wxrichtextprintout, wxrichtextheaderfooterdata dialog classes: wxrichtextstyleorganiserdialog, wxrichtextformattingdialog, wxsymbolpickerdialog wxrichtextctrl provides a generic implementation of a rich text editor that can handle different character styles, paragraph formatting, and images. it's aimed at editing 'natural' language text - if you need an editor that supports code editing, wxstyledtextctrl is a better choice. despite its name, it cannot currently read or write rtf (rich text format) files. instead, it uses its own xml format, and can also read and write plain text. in future we expect to provide rtf file capabilities. custom file formats can be supported by creating additional file handlers and registering them with the control. wxrichtextctrl is largely compatible with the wxtextctrl api, but extends it where necessary. the control can be used where the native rich text capabilities of wxtextctrl are not adequate (this is particularly true on windows) and where more direct access to the content representation is required. it is difficult and inefficient to read the style information in a wxtextctrl, whereas this information is readily available in wxrichtextctrl. since it's written in pure wxwidgets, any customizations you make to wxrichtextctrl will be reflected on all platforms. wxrichtextctrl supports basic printing via the easy-to-use wxrichtextprinting class. creating applications with simple word processing features is simplified with the inclusion of wxrichtextformattingdialog, a tabbed dialog allowing interactive tailoring of paragraph and character styling. also provided is the multi-purpose dialog wxrichtextstyleorganiserdialog that can be used for managing style definitions, browsing styles and applying them, or selecting list styles with a renumber option. there are a few disadvantages to using wxrichtextctrl. it is not native, so does not behave exactly as a native wxtextctrl, although common editing conventions are followed. users may miss the built-in spelling correction on mac os x, or any special character input that may be provided by the native control. it would also be a poor choice if intended users rely on screen readers that would be not work well with non-native text input implementation. you might mitigate this by providing the choice between wxtextctrl and wxrichtextctrl, with fewer features in the former case. a good way to understand wxrichtextctrl's capabilities is to compile and run the sample, samples/richtext, and browse the code. the following screenshot shows the sample in action:
example the following code is taken from the sample, and adds text and styles to a rich text control programmatically.
programming with wxrichtextctrl
programming with wxrichtextctrl
starting to use wxrichtextctrlyou need to include <wx/richtext/richtextctrl.h> in your source, and link with the appropriate wxwidgets library with richtext suffix. put the rich text library first in your link line to avoid unresolved symbols. then you can create a wxrichtextctrl, with the wxwant_chars style if you want tabs to be processed by the control rather than being used for navigation between controls.
wxrichtextctrl and stylesstyling attributes are represented by three classes: wxtextattr, wxtextattrex and wxrichtextattr. wxtextattr is shared across all controls that are derived from wxtextctrlbase and can store basic character and paragraph attributes. wxtextattrex derives from wxtextattr and adds some further attributes that are only supported by wxrichtextctrl. finally, wxrichtextattr is a more efficient version of wxtextattrex that doesn't use a wxfont object and can be used to query styles more quickly. wxtextattrex and wxrichtextattr are largely interchangeable and have suitable conversion operators between them. when setting a style, the flags of the attribute object determine which attributes are applied. when querying a style, the passed flags are ignored except (optionally) to determine whether attributes should be retrieved from character content or from the paragraph object. wxrichtextctrl takes a layered approach to styles, so that different parts of the content may be responsible for contributing different attributes to the final style you see on the screen. there are four main notions of style within a control:
what you see on the screen is the dynamically combined style, found by merging the first three of the above style types (the fourth is only a guide for future content insertion and therefore does not affect the currently displayed content). to make all this more concrete, here are examples of where you might set these different styles:
naturally you can do any of these things either using your own ui, or programmatically. the basic wxtextctrl doesn't make the same distinctions as wxrichtextctrl regarding attribute storage. so we need finer control when setting and retrieving attributes. wxrichtextctrl::setstyleex takes a flags parameter:
it's great to be able to change arbitrary attributes in a wxrichtextctrl, but it can be unwieldy for the user or programmer to set attributes separately. word processors have collections of styles that you can tailor or use as-is, and this means that you can set a heading with one click instead of marking text in bold, specifying a large font size, and applying a certain paragraph spacing and alignment for every such heading. similarly, wxwidgets provides a class called wxrichtextstylesheet which manages style definitions (wxrichtextparagraphstyledefinition, wxrichtextliststyledefinition and wxrichtextcharacterstyledefinition). once you have added definitions to a style sheet and associated it with a wxrichtextctrl, you can apply a named definition to a range of text. the classes wxrichtextstylecomboctrl and wxrichtextstylelistbox can be used to present the user with a list of styles in a sheet, and apply them to the selected text. you can reapply a style sheet to the contents of the control, by calling wxrichtextctrl::applystylesheet. this is useful if the style definitions have changed, and you want the content to reflect this. it relies on the fact that when you apply a named style, the style definition name is recorded in the content. so applystylesheet works by finding the paragraph attributes with style names and re-applying the definition's attributes to the paragraph. currently, this works with paragraph and list style definitions only.
wxrichtextctrl dialogswxrichtextctrl comes with standard dialogs to make it easier to implement text editing functionality. wxrichtextformattingdialog can be used for character or paragraph formatting, or a combination of both. it's a wxpropertysheetdialog with the following available tabs: font, indents & spacing, tabs, bullets, style, and list style. you can select which pages will be shown by supplying flags to the dialog constructor. in a character formatting dialog, typically only the font page will be shown. in a paragraph formatting dialog, you'll show the indents & spacing, tabs and bullets pages. the style tab is useful when editing a style definition. you can customize this dialog by providing your own wxrichtextformattingdialogfactory object, which tells the formatting dialog how many pages are supported, what their identifiers are, and how to creates the pages. wxrichtextstyleorganiserdialog is a multi-purpose dialog that can be used for managing style definitions, browsing styles and applying them, or selecting list styles with a renumber option. see the sample for usage - it is used for the "manage styles" and "bullets and numbering" menu commands. wxsymbolpickerdialog lets the user insert a symbol from a specified font. it has no wxrichtextctrl dependencies besides being included in the rich text library.
how wxrichtextctrl is implementeddata representation is handled by wxrichtextbuffer, and a wxrichtextctrl always has one such buffer. the content is represented by a hierarchy of objects, all derived from wxrichtextobject. an object might be an image, a fragment of text, a paragraph, or a whole buffer. objects store a wxtextattrex containing style information; a paragraph object can contain both paragraph and character information, but content objects such as text can only store character information. the final style displayed in the control or in a printout is a combination of base style, paragraph style and content (character) style. the top of the hierarchy is the buffer, a kind of wxrichtextparagraphlayoutbox. containing further wxrichtextparagraph objects, each of which can include text, images and potentially other types of object. each object maintains a range (start and end position) measured from the start of the main parent object. when layout is called on an object, it is given a size which the object must limit itself to, or one or more flexible directions (vertical or horizontal). so, for example, a centred paragraph is given the page width to play with (minus any margins), but can extend indefinitely in the vertical direction. the implementation of layout caches the calculated size and position. when the buffer is modified, a range is invalidated (marked as requiring layout), so that only the minimum amount of layout is performed. a paragraph of pure text with the same style contains just one further object, a wxrichtextplaintext object. when styling is applied to part of this object, the object is decomposed into separate objects, one object for each different character style. so each object within a paragraph always has just one wxtextattrex object to denote its character style. of course, this can lead to fragmentation after a lot of edit operations, potentially leading to several objects with the same style where just one would do. so a defragment function is called when updating the control's display, to ensure that the minimum number of objects is used.
wxrichtextctrl roadmapbugs this is an incomplete list of bugs.
features this is a list of some of the features that have yet to be implemented. help with them will be appreciated.
there are also things that could be done to take advantage of the underlying text capabilities of the platform; higher-level text formatting apis are available on some platforms, such as mac os x, and some of translation from high level to low level wxdc api is unnecessary. however this would require additions to the wxwidgets api.
|