Skip to content

DocumentController

Dustin Horne edited this page Mar 5, 2026 · 1 revision

DocumentController

Namespace: ParentElement.RichText.Core.Controllers

The concrete implementation of IDocumentController. Create one instance per editor surface and connect it to your UI by wiring up the RequestRedraw and RequestCursorUpdate callbacks and forwarding pointer and keyboard events.

public class DocumentController : IDocumentController

Constructor

public DocumentController(DocumentSettings settings, IClipboardHandler clipboard)
Parameter Type Description
settings DocumentSettings Initial page configuration — size, margins, default style
clipboard IClipboardHandler Platform clipboard adapter used by copy, cut, and paste

Example

var settings = new DocumentSettings
{
    PageWidth       = 816,   // US Letter at 96 dpi
    ShowPageBreaks  = true,
    DocumentMargins = new DocumentMargins(72, 72, 72, 72),
};

IDocumentController editor = new DocumentController(settings, new MyClipboard());
editor.RequestRedraw       = () => surface.InvalidateSurface();
editor.RequestCursorUpdate = cursor => UpdatePlatformCursor(cursor);

Public Members

All members are documented on the IDocumentController page. The sections below note any implementation-specific behaviour.

Properties with Setters

Property Default Notes
SelectionColor SKColors.LightGray Updated at any time; triggers redraw
BackgroundColor SKColors.White Overrides DocumentSettings.DocumentBackgroundColor
VisibleBounds Rectangle(0,0,0,0) Must be set before the first Draw call
ReadOnly false When true, key and pointer events that modify content are ignored
HasFocus false Drives caret blinking; set true when the surface gains focus
ScrollScale 1.0 Set to the viewport zoom factor when translating pointer coordinates

Notable Implementation Details

  • Undo/Redo is handled entirely by the underlying TextDocument.
  • Shortcut handling is evaluated inside OnKeyEvent before default key processing.
  • Table cell focus is managed automatically as the user clicks or types into cells.
  • PDF export uses SkiaSharp's built-in PDF canvas backend.

See also: IDocumentController · Data-Structures · Input-and-Shortcuts · Tables

Clone this wiki locally