Estimated read time: 4 minutes
Writer now has the start of content controls: a new way to set properties on a piece of text, primarily for form filling purposes. This feature improves compatibility with the DOCX format: inline content control types "rich text" and "checkbox" are the first two types we can now import.

First, thanks to NGI DAPSI who made this work by Collabora possible.

Motivation¶
Word users expect to be able to import their document to Writer and experience a matching feature set: form filling is not an exception. Word provides several content control kinds (inline, block, row and cell content controls), this project focuses on inline ("run") content controls.
In the scope of inline content controls, the plan is to support rich text, checkbox, dropdown, picture and date content controls. This blog post presents the already implemented rich text and checkbox types.
You might wonder why content controls are useful, since Writer already has form controls and fieldmarks, which provide something similar. Here are some properties of content controls, which make them incompatible with field-based fillable forms or form controls:
-
inline content controls can't span over multiple paragraphs, while this is allowed for fieldmarks (bookmark-based fields)
-
content controls must be well-formed XML elements, this allows nesting (while Writer fields can't be nested), but does not allow the start/end position to be a random place in the document (while this is allowed for fieldmarks, which have separate XML elements for start and end)
-
content controls just have a set of properties, while fieldmarks are supposed to have a field command and a result (with a separator between the two)
-
content controls can contain rich text (full set of character formatting), while Writer fields can only have one character formatting (e.g. half of the field can't be bold)
Results¶
The feature consists of menu items to insert rich text or checkbox content controls, and then you can interact with the inserted content controls:

Rich text content controls simply show an indicator when you're inside the content control:

This is similar to input fields, just allows rich text content, not limited to plain text.
Checkbox content controls contain a single character, but you can interact with them: clicking on the content control toggles the checked state of the checkbox:

And these content controls can be saved to ODT and DOCX.
How is this implemented?¶
If you would like to know a bit more about how this works, continue reading... :-)
As usual, the high-level problem was addressed by a series of incremental commits:
- sw content controls: add document model
- sw content controls: add UNO API to insert this
- sw content controls: add UNO API to insert this with custom props
- sw content controls: include this in the UNO API text portion enum
- sw content controls: add initial layout support
- sw content controls: add overlay to render a border around the text portions
- sw content controls: select the content on click when showing placeholder
- sw content controls: add ODT export
- sw content controls: add ODT import
- sw content controls: add initial DOCX export
- sw content controls, DOCX export: handle SDT end at para end
- sw content controls: add initial DOCX import
- sw content controls: add insert UI
- sw content controls: add LOK API
- sw content controls, checkbox: add document model & UNO API
- sw content controls, checkbox: toggle the checkbox on click
- sw content controls, checkbox: add ODT filter
- sw content controls, checkbox: add DOCX export
- sw content controls, checkbox: add DOCX import
- sw content controls, checkbox: add insert UI
To make this even more interesting, Rashesh Padia of Collabora started exposing this in Collabora Online, see the PR at https://github.com/CollaboraOnline/online/pull/4703.
Want to start using this?¶
You can get a snapshot / demo of Collabora Office 2022 and try it out yourself right now: try unstable snapshot. Collabora intends to continue supporting and contributing to LibreOffice, the code is merged so we expect all of this work will be available in TDF's next release too (7.4).