Table of Contents
- xtk_textview.h
- Types
- XtkTextView
- XtkTextViewTheme
- XtkTextViewChangeCallback
- XtkTextViewEditCallback
- XtkTextViewContextItem
- XtkTextMark
- XtkTextViewExtraColors
- XtkTextFoldPoint
- XTK_LINE_MARKER_BOOKMARK and the other values
- XtkTextOverviewRun
- XtkTextOverviewMark
- XtkTextChangeRun
- Constants
- Functions
- xtk_textview_config_init_defaults
- xtk_textview_config_parse_styling
- xtk_textview_config_write_styling
- xtk_textview_create
- xtk_textview_destroy
- xtk_textview_set_text
- xtk_textview_get_text
- xtk_textview_load_file
- xtk_textview_save_file
- xtk_textview_set_theme
- xtk_textview_set_line_numbers
- xtk_textview_set_font
- xtk_textview_set_tab_width
- xtk_textview_set_read_only
- xtk_textview_get_read_only
- xtk_textview_set_background_key
- xtk_textview_set_syntax_highlighting
- xtk_textview_set_wrap
- xtk_textview_get_wrap
- xtk_textview_set_position
- xtk_textview_resize
- xtk_textview_get_window
- xtk_textview_scroll_to_line
- xtk_textview_get_scroll_position
- xtk_textview_find
- xtk_textview_replace_selection
- xtk_textview_replace_all
- xtk_textview_get_size
- xtk_textview_get_line_box_height
- xtk_textview_handle_event
- xtk_textview_draw
- xtk_textview_set_change_callback
- xtk_textview_set_edit_callback
- xtk_textview_set_focus_callback
- xtk_textview_set_ime
- xtk_textview_set_extra_context_item
- xtk_textview_set_extra_context_items
- xtk_textview_unfocus_all
- xtk_textview_set_focused
- xtk_textview_theme_init_dark
- xtk_textview_theme_init_light
- xtk_textview_set_file_path
- xtk_textview_get_file_path
- xtk_textview_update_blink
- xtk_textview_set_selection
- xtk_textview_select_range
- xtk_textview_get_selection
- xtk_textview_set_extra_colors
- xtk_textview_set_show_whitespace
- xtk_textview_set_indent_guides
- xtk_textview_set_line_ending_mark
- xtk_textview_set_marker_margin
- xtk_textview_margin_at
- xtk_textview_set_line_marker
- xtk_textview_set_numbered_markers
- xtk_textview_get_line_markers
- xtk_textview_next_line_marker
- xtk_textview_clear_line_markers
- xtk_textview_get_line_count
- xtk_textview_set_change_history
- xtk_textview_set_long_line
- xtk_textview_set_drag_text
- xtk_textview_set_rectangular_selection
- xtk_textview_get_cursor_point
- xtk_textview_has_rectangle
- xtk_textview_shift_rectangle
- xtk_textview_set_virtual_space
- xtk_textview_set_scroll_past_end
- xtk_textview_set_cursor_margin
- xtk_textview_set_folding
- xtk_textview_set_fold_points
- xtk_textview_set_fold_children
- xtk_textview_fold_all
- xtk_textview_toggle_fold_at
- xtk_textview_set_overview_width
- xtk_textview_set_overview_runs
- xtk_textview_set_overview_marks
- xtk_textview_set_change_map
- xtk_textview_set_scrollbar_shown
- xtk_textview_line_top
- xtk_textview_set_marks
- xtk_textview_get_cursor
- xtk_textview_position_at_point
- xtk_textview_set_cursor
- xtk_textview_insert_text
- xtk_textview_follow_edit
- xtk_textview_begin_group
- xtk_textview_end_group
- xtk_textview_undo
- xtk_textview_redo
- xtk_textview_can_undo
- xtk_textview_can_redo
- xtk_textview_is_modified
- xtk_textview_mark_saved
- xtk_textview_mark_unsaved
- xtk_textview_get_length
- xtk_textview_cut
- xtk_textview_copy
- xtk_textview_paste
- xtk_textview_select_all
xtk_textview.h
A multi-line plain text editor, with the features of a code editor.
An XtkTextView shows and edits plain text of any size in one font. It has a caret, selection with the mouse and the keyboard, the clipboard, undo and redo, a right-click menu (Cut, Copy, Paste, Select All, Undo, Redo), line numbers and a vertical scrollbar. A program that is an editor can also turn on line wrapping, folding, a markers margin with bookmarks, change history, visible white space, indentation guides, a long-line marker, rectangular selection, drag and drop of text, and colored runs of text (marks) that the program computes, for example from a syntax highlighter of its own.
The view's own highlighting is for INI-style files: a line that starts with # is a comment, a line that starts with [ is a section, and in a key = value line the key and the value get their own colors (a value that is a number, or one that starts with # and three or more hex digits, gets the number or hex-color color). Turn it off with xtk_textview_set_syntax_highlighting() for other text.
The text is UTF-8, and every position in this header is a byte offset into it. Lines are separated by '
' only; the program converts other line endings when it loads and saves.
Making a view. xtk_textview_create() takes the colors as an XtkTextViewTheme, which is the [textview] block of an XtkConfig, so a program passes &config.textview. The view copies the colors; call xtk_textview_set_theme() when they change. It draws in "monospace-10" until xtk_textview_set_font() is called. The view is made unmapped and is mapped by the first xtk_textview_set_position(). It owns its window, its text and its history, and xtk_textview_destroy() frees them. The clipboard is the caller's, shared with the other widgets.
Events. Pass every X event to xtk_textview_handle_event(). It returns 1 when the view used the event. Pass the clipboard's events to xtk_clipboard_handle_event() as well, or paste does not work. Call xtk_textview_update_blink() often (for example every 50 ms) to blink the caret.
Focus. A left click in the text or on a line number, or xtk_textview_set_focused(), gives it X keyboard focus (a click on the scroll bar or in the markers or fold margin, and a right click, do not); an X FocusIn on its window also counts as focus, and a FocusOut takes it away. While it has focus, it takes every key press it is given, whatever window the event names. The focus callback (xtk_textview_set_focus_callback()) runs when a click or xtk_textview_set_focused() gives it focus, and again on every X FocusIn on its window (so it can run twice for one click), so the program can take focus from other widgets; xtk_textview_unfocus_all() is the other direction. The border is drawn in focus-border while the view has focus.
Keys and mouse. The arrows move the caret (Up and Down by a row when lines wrap); Home and End go to the ends of the line, and with Ctrl to the ends of the text; Page Up and Page Down move by a screen. Shift with any of these selects. Backspace, Delete and Return edit; Tab types a tab character (Shift+Tab and Ctrl+Tab are not used, so the program can move focus with them). Ctrl+A selects all, Ctrl+C copies, Ctrl+X cuts, Ctrl+V pastes, Ctrl+Z undoes, and Ctrl+Y or Ctrl+Shift+Z redoes (also with Caps Lock on). A double click selects a word, a triple click a line, and a click on a line number selects that line. The wheel scrolls three lines. A right click opens the menu.
Undo. Typing joins into words and Backspace or Delete into runs (see xtk_edit_history.h), so one undo takes back a word, not a letter. The history holds up to 64 MB of edits. xtk_textview_is_modified() follows undo back to the saved text.
Callbacks. The change callback runs after each edit by the user or by the program (typing, paste, undo, xtk_textview_insert_text() and so on), but not for xtk_textview_set_text() or xtk_textview_load_file(). The edit callback runs just before every change of the bytes, the new text from xtk_textview_set_text() and xtk_textview_load_file() included, so a program can move offsets it keeps.
Theme keys. The view reads the [textview] section:
text: the text. Default E6E6E6.background: the background. Default #2E2E2E. It can be a gradient.selection: the selection's background. Default #4D80B3. It can be a gradient.selection-text: selected text. Default FFFFFF.cursor: the caret. Default FFFFFF.line-numbers: the line numbers. Default #808080. Also white space, indentation guides and fold boxes unlessxtk_textview_set_extra_colors()gives them colors.line-numbers-background: the line number gutter. Default #141414. It can be a gradient.border: the border and the scrollbar's edge. Default #4D4D4D.focus-border: the border while the view has focus. Default #6699E6.scrollbar-thumb: the scrollbar thumb. Default #737373. It can be a gradient.section,key,value,comment,number,hex-color: the highlighting colors. Defaults #9966CC, #66B3E6, #99CC66, #808080, E6994D and E6B34D.linkandhighlight: not used by the view;XtkRichText, which uses the same block, draws links and highlighted text in them. Defaults #66B3FF and EBDC5A.
The caret blinks at cursor-blink-ms in [behavior] (default 600), which the config reader copies into the block's cursor_blink_ms.
The right-click menu is drawn in background, text, selection, selection-text and border.
Example.
static void text_changed(XtkTextView *view, void *user_data) {
(void)user_data;
printf("%d lines\n", xtk_textview_get_line_count(view));
}
XtkConfig config;
xtk_config_init_defaults(&config);
XtkTheme *theme = xtk_theme_new();
if (theme && xtk_theme_builtin("Dark", theme)) xtk_theme_apply(&config, theme);
xtk_theme_free(theme);
XtkClipboard *clipboard = xtk_clipboard_create(display);
XtkTextView *view = xtk_textview_create(display, screen, window, 0, 0, 640, 480,
&config.textview, clipboard);
xtk_textview_set_change_callback(view, text_changed, NULL);
if (xtk_textview_load_file(view, "settings.conf") != 0)
xtk_textview_set_text(view, "# new file\n");
xtk_textview_set_position(view, 0, 0); // maps the view
for (;;) {
XEvent event;
while (XPending(display)) {
XNextEvent(display, &event);
if (xtk_clipboard_handle_event(clipboard, &event)) continue;
xtk_textview_handle_event(view, &event);
}
xtk_textview_update_blink(view);
usleep(50000);
}
if (xtk_textview_save_file(view, "settings.conf") == 0) xtk_textview_mark_saved(view);
xtk_textview_destroy(view);
xtk_clipboard_destroy(clipboard);
*
Limitations.
- Copy and Cut set only the CLIPBOARD selection; a selection does not become PRIMARY, and a middle click does not paste.
- Without wrapping, the part of a line past the right edge is not shown: there is no horizontal scrolling.
- In a read-only view the menu offers only Copy and Select All (and the program's own item); Ctrl+X copies the selection without removing it.
- A wrapped line shows at most 4096 rows.
- The view is not thread-safe.
#include "xtk_textview.h"
Types: XtkTextView, XtkTextViewTheme, XtkTextViewChangeCallback, XtkTextViewEditCallback, XtkTextViewContextItem, XtkTextMark, XtkTextViewExtraColors, XtkTextFoldPoint, XTK_LINE_MARKER_BOOKMARK and the other values, XtkTextOverviewRun, XtkTextOverviewMark, XtkTextChangeRun
Constants: XTK_TEXTVIEW_CONTEXT_ITEMS_MAX
Functions: xtk_textview_config_init_defaults, xtk_textview_config_parse_styling, xtk_textview_config_write_styling, xtk_textview_create, xtk_textview_destroy, xtk_textview_set_text, xtk_textview_get_text, xtk_textview_load_file, xtk_textview_save_file, xtk_textview_set_theme, xtk_textview_set_line_numbers, xtk_textview_set_font, xtk_textview_set_tab_width, xtk_textview_set_read_only, xtk_textview_get_read_only, xtk_textview_set_background_key, xtk_textview_set_syntax_highlighting, xtk_textview_set_wrap, xtk_textview_get_wrap, xtk_textview_set_position, xtk_textview_resize, xtk_textview_get_window, xtk_textview_scroll_to_line, xtk_textview_get_scroll_position, xtk_textview_find, xtk_textview_replace_selection, xtk_textview_replace_all, xtk_textview_get_size, xtk_textview_get_line_box_height, xtk_textview_handle_event, xtk_textview_draw, xtk_textview_set_change_callback, xtk_textview_set_edit_callback, xtk_textview_set_focus_callback, xtk_textview_set_ime, xtk_textview_set_extra_context_item, xtk_textview_set_extra_context_items, xtk_textview_unfocus_all, xtk_textview_set_focused, xtk_textview_theme_init_dark, xtk_textview_theme_init_light, xtk_textview_set_file_path, xtk_textview_get_file_path, xtk_textview_update_blink, xtk_textview_set_selection, xtk_textview_select_range, xtk_textview_get_selection, xtk_textview_set_extra_colors, xtk_textview_set_show_whitespace, xtk_textview_set_indent_guides, xtk_textview_set_line_ending_mark, xtk_textview_set_marker_margin, xtk_textview_margin_at, xtk_textview_set_line_marker, xtk_textview_set_numbered_markers, xtk_textview_get_line_markers, xtk_textview_next_line_marker, xtk_textview_clear_line_markers, xtk_textview_get_line_count, xtk_textview_set_change_history, xtk_textview_set_long_line, xtk_textview_set_drag_text, xtk_textview_set_rectangular_selection, xtk_textview_get_cursor_point, xtk_textview_has_rectangle, xtk_textview_shift_rectangle, xtk_textview_set_virtual_space, xtk_textview_set_scroll_past_end, xtk_textview_set_cursor_margin, xtk_textview_set_folding, xtk_textview_set_fold_points, xtk_textview_set_fold_children, xtk_textview_fold_all, xtk_textview_toggle_fold_at, xtk_textview_set_overview_width, xtk_textview_set_overview_runs, xtk_textview_set_overview_marks, xtk_textview_set_change_map, xtk_textview_set_scrollbar_shown, xtk_textview_line_top, xtk_textview_set_marks, xtk_textview_get_cursor, xtk_textview_position_at_point, xtk_textview_set_cursor, xtk_textview_insert_text, xtk_textview_follow_edit, xtk_textview_begin_group, xtk_textview_end_group, xtk_textview_undo, xtk_textview_redo, xtk_textview_can_undo, xtk_textview_can_redo, xtk_textview_is_modified, xtk_textview_mark_saved, xtk_textview_mark_unsaved, xtk_textview_get_length, xtk_textview_cut, xtk_textview_copy, xtk_textview_paste, xtk_textview_select_all
Types
XtkTextView
typedef struct XtkTextView XtkTextView;
A multi-line text view; opaque, made by xtk_textview_create().
XtkTextViewTheme
typedef struct TextViewBlock XtkTextViewTheme;
A text view's colors: the TextViewBlock of an XtkConfig (config.textview, the [textview] section).
XtkTextViewChangeCallback
typedef void (*XtkTextViewChangeCallback)(XtkTextView *textview, void *user_data);
The function the view calls after each edit.
It is called in the middle of an edit: it may read the text, but must not edit or destroy the view.
XtkTextViewEditCallback
typedef void (*XtkTextViewEditCallback)(XtkTextView *textview, int offset, int removed_length, const char *inserted, int inserted_length, void *user_data);
The function the view calls just before the bytes of its text change.
The removed_length bytes at offset (still in the text, see xtk_textview_get_text()) are about to become the inserted bytes. Typing, deleting, pasting, undo, redo, the program's own edits, and a whole new text (xtk_textview_set_text(), xtk_textview_load_file()) all come here, so a program can move offsets it keeps into the text.
XtkTextViewContextItem
One item of the program's own in the right-click menu (xtk_textview_set_extra_context_items()).
| Field | Type | Description |
|---|---|---|
label |
const char * |
its text, cut to 31 bytes |
callback |
void (*)(void *user_data) |
called when it is chosen, after the menu has closed and the view has redrawn |
user_data |
void * |
passed to callback |
XtkTextMark
A run of text that the program colors: a background behind it, a text color over it, or both.
Marks are how a program draws its own syntax highlighting, search matches or diagnostics. With wave, a wave is drawn under the run, as a spelling checker marks a word. With has_background, a mark whose start equals its end is a 2-pixel bar at that position (an insertion point), in the background color. With has_text and a label, the label is drawn there in the text color, over any text that follows; the text does not move to make room.
| Field | Type | Description |
|---|---|---|
start |
int |
The byte offset of the first byte. |
end |
int |
The byte offset one past the last byte. |
background |
ConfigColor |
The background, used when has_background is set. |
text |
ConfigColor |
The text color, used when has_text is set. |
has_background |
int |
Non-zero to paint the background. |
has_text |
int |
Non-zero to draw the run's text in the text color. |
label[32] |
char |
With start equal to end and has_text: text drawn there in the text color, not part of the text (a ghost: } or </section>) |
bold |
int |
With has_text: draw the run in the font's bold face (it is measured in it too) |
italic |
int |
With has_text: draw the run in the font's italic face (it is measured in it too) |
wave |
int |
Non-zero to draw a wave under the run (a misspelled word), in wave_color. |
wave_color |
ConfigColor |
The wave's color, used when wave is set. |
XtkTextViewExtraColors
Colors for what the text does not show by itself, the margins, and the caret's line.
| Field | Type | Description |
|---|---|---|
whitespace |
ConfigColor |
The dots for spaces and arrows for tabs (and the line ending boxes when line_ending is unset) |
indent_guide |
ConfigColor |
The indentation guides. |
fold_margin |
ConfigColor |
The fold margin's background. |
fold_marker |
ConfigColor |
The fold boxes. |
current_line |
ConfigColor |
The background of the caret's line, when current_line_on is set. |
current_line_on |
int |
1 to paint the caret's line in current_line |
marker_margin |
ConfigColor |
The markers margin's background. |
marker |
ConfigColor |
A bookmark's arrow in the markers margin. |
change_modified |
ConfigColor |
Change history: a line changed and not saved. |
change_saved |
ConfigColor |
Change history: a line changed and saved. |
error_indicator |
ConfigColor |
The wave under a line with an error marker. |
line_ending |
ConfigColor |
The line ending boxes; with alpha 0 (unset), whitespace's color is used. |
vcs_added |
ConfigColor |
XTK_LINE_MARKER_ADDED's bar. |
vcs_changed |
ConfigColor |
XTK_LINE_MARKER_CHANGED's bar. |
vcs_deleted |
ConfigColor |
XTK_LINE_MARKER_DELETED's wedge. |
breakpoint |
ConfigColor |
XTK_LINE_MARKER_BREAKPOINT's dot. |
execution |
ConfigColor |
XTK_LINE_MARKER_EXECUTION's arrow. |
XtkTextFoldPoint
A block that can fold: the byte offsets of the brace that opens it and of the one that closes it.
| Field | Type | Description |
|---|---|---|
open |
int |
The byte offset of the brace that opens the block. |
close |
int |
The byte offset of the brace that closes it. |
XTK_LINE_MARKER_BOOKMARK and the other values
The kinds of marker a line can have, one bit each.
Markers belong to lines and move with them when lines are added or removed above. A click in the markers margin puts a bookmark on the line or takes it off.
| Name | Value | Description |
|---|---|---|
XTK_LINE_MARKER_BOOKMARK |
1 |
The user's bookmark: an arrow in the markers margin. |
XTK_LINE_MARKER_MODIFIED |
2 |
Change history: changed and not saved (the view sets it itself) |
XTK_LINE_MARKER_SAVED |
4 |
Change history: changed and saved since the text was set (the view sets it itself) |
XTK_LINE_MARKER_ERROR |
8 |
An error, for example from a compiler: a wave under the line's text. |
XTK_LINE_MARKER_ADDED |
16 |
Version control: a line added since the last commit (a bar at the margin's left, vcs_added) |
XTK_LINE_MARKER_CHANGED |
32 |
A line changed since the last commit (a bar, vcs_changed) |
XTK_LINE_MARKER_DELETED |
64 |
Lines deleted just above this one (a wedge between the lines, vcs_deleted) |
XTK_LINE_MARKER_BREAKPOINT |
128 |
A debugger's breakpoint: a dot in the markers margin (breakpoint) |
XTK_LINE_MARKER_EXECUTION |
256 |
Where a debugged program stopped: an arrow in the markers margin (execution) |
XTK_LINE_MARKER_HOST |
1024 |
This bit and the higher ones are the program's own: kept on the line, never drawn. |
XtkTextOverviewRun
A run of the text in a color, for the minimap (xtk_textview_set_overview_runs()): byte offsets.
| Field | Type | Description |
|---|---|---|
start |
int |
|
end |
int |
|
color |
ConfigColor |
XtkTextOverviewMark
A line to mark in the minimap and on the scrollbar's track (an error, a search hit).
| Field | Type | Description |
|---|---|---|
line |
int |
From 0. |
color |
ConfigColor |
XtkTextChangeRun
Lines in a color, for the change map (xtk_textview_set_change_map()).
| Field | Type | Description |
|---|---|---|
first |
int |
The first line, from 0. |
count |
int |
How many; 0 marks the place before first (lines missing there) with a thin line. |
color |
ConfigColor |
Constants
XTK_TEXTVIEW_CONTEXT_ITEMS_MAX
#define XTK_TEXTVIEW_CONTEXT_ITEMS_MAX 16
the most items of its own a program can add to the right-click menu
Functions
xtk_textview_config_init_defaults
void xtk_textview_config_init_defaults(TextViewBlock *textview_config);
Set a TextViewBlock to the default colors of the [textview] section.
xtk_config_init_defaults() already calls it for config.textview.
| Parameter | Description |
|---|---|
textview_config |
The block to set (NULL is ignored) |
xtk_textview_config_parse_styling
int xtk_textview_config_parse_styling(
TextViewBlock *textview_config,
const char *key,
const char *value);
Read one key of the [textview] section into a TextViewBlock.
Every key is a color. The config reader calls it; a program rarely needs to.
| Parameter | Description |
|---|---|
textview_config |
The block to change |
key |
The key, for example "background" |
value |
The value, for example "#202020" |
Returns: 1 if the key is one of the section's, 0 if not or an argument is NULL
xtk_textview_config_write_styling
int xtk_textview_config_write_styling(FILE *file, const TextViewBlock *textview_config);
Write the [textview] section of a TextViewBlock to a file.
The heading and one key = #RRGGBB line for each color are written, then a blank line.
| Parameter | Description |
|---|---|
file |
The file to write to |
textview_config |
The block to write |
Returns: 1 when written, 0 if an argument is NULL
xtk_textview_create
XtkTextView *xtk_textview_create(
Display *display,
int screen,
Window parent,
int x,
int y,
int width,
int height,
const XtkTextViewTheme *theme,
XtkClipboard *clipboard);
Make a text view, unmapped, as a child of a window.
The view is empty, with line numbers and syntax highlighting on. Map it with xtk_textview_set_position().
| Parameter | Description |
|---|---|
display |
The X display |
screen |
The screen number |
parent |
The window the view is made in |
x |
The x position in the parent |
y |
The y position in the parent |
width |
The width in pixels |
height |
The height in pixels |
theme |
The colors, copied (normally &config.textview); NULL for the colors of xtk_textview_theme_init_dark() |
clipboard |
The clipboard for copy and paste, owned by the caller; NULL turns copy and paste off (Cut then deletes the selection without copying it) |
Returns: The view, or NULL if display is NULL, memory runs out or the window cannot be made
xtk_textview_destroy
void xtk_textview_destroy(XtkTextView *textview);
Destroy a view: its window, its text and its history.
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_set_text
void xtk_textview_set_text(XtkTextView *textview, const char *text);
Replace the whole text, and start a new history with the text unmodified.
The caret goes to the start, the view scrolls to the top, and folds and line markers are cleared. The edit callback is told; the change callback is not. It works in a read-only view too.
| Parameter | Description |
|---|---|
textview |
The view |
text |
The new text, copied up to its NUL; NULL for empty |
xtk_textview_get_text
const char *xtk_textview_get_text(XtkTextView *textview);
The text.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: The text, owned by the view and valid until its next change, with a NUL after its last byte. It can hold NUL bytes of its own (from a loaded file): use xtk_textview_get_length() for its length. NULL if textview is NULL.
xtk_textview_load_file
int xtk_textview_load_file(XtkTextView *textview, const char *filepath);
Replace the whole text with a file's bytes, as xtk_textview_set_text() does.
The file is read as it is: no line ending or encoding is converted. If reading fails, the view keeps its text. The file path stored with xtk_textview_set_file_path() is not changed.
| Parameter | Description |
|---|---|
textview |
The view |
filepath |
The file to read |
Returns: 0 when loaded, -1 if an argument is NULL or the file cannot be read
xtk_textview_save_file
int xtk_textview_save_file(const XtkTextView *textview, const char *filepath);
Write the text to a file, replacing it.
The view is not marked saved: call xtk_textview_mark_saved() when this returns 0.
| Parameter | Description |
|---|---|
textview |
The view |
filepath |
The file to write |
Returns: 0 when every byte was written and the file closed cleanly, -1 if an argument is NULL, the file cannot be opened, or a write or the close fails (a full disk, for example)
xtk_textview_set_theme
void xtk_textview_set_theme(XtkTextView *textview, const XtkTextViewTheme *theme);
Give the view new colors, and redraw it.
| Parameter | Description |
|---|---|
textview |
The view |
theme |
The colors, copied; NULL is ignored |
xtk_textview_set_line_numbers
void xtk_textview_set_line_numbers(XtkTextView *textview, int enabled);
Show or hide the line numbers (they show at first).
| Parameter | Description |
|---|---|
textview |
The view |
enabled |
1 to show them, 0 to hide them |
xtk_textview_set_font
void xtk_textview_set_font(XtkTextView *textview, const char *family, int size);
Draw the text in another font, and redraw.
The line height, the tab width, the gutter and the margins follow the font. A family that is not installed gets fontconfig's closest match (or "sans-14" when even that fails). A NULL or empty family, or a size of 0 or less, is ignored.
| Parameter | Description |
|---|---|
textview |
The view |
family |
A fontconfig family, for example "DejaVu Sans Mono" |
size |
The pixel size, as everywhere in xtk ("monospace-10" is about 13) |
xtk_textview_set_tab_width
void xtk_textview_set_tab_width(XtkTextView *textview, int columns);
Set how wide a tab is, in spaces of the font (4 at first), and redraw.
| Parameter | Description |
|---|---|
textview |
The view |
columns |
1 to 32; other values are ignored |
xtk_textview_set_read_only
void xtk_textview_set_read_only(XtkTextView *textview, int read_only);
Make the view read-only, or editable again.
A read-only view does not change its text from the keyboard (typing, cut, paste, undo) or from the program (insert, replace); selecting and copying still work. xtk_textview_set_text() and xtk_textview_load_file() still replace the text.
| Parameter | Description |
|---|---|
textview |
The view |
read_only |
1 for read-only, 0 for editable |
xtk_textview_get_read_only
int xtk_textview_get_read_only(const XtkTextView *textview);
Whether the view is read-only.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: 1 when it is read-only, 0 if not or if textview is NULL
xtk_textview_set_background_key
void xtk_textview_set_background_key(
XtkTextView *textview,
const char *section,
const char *key);
Name the theme key whose gradient the background is drawn with.
A view that has another widget's colors (a table cell, for example) draws that widget's background gradient when the theme gives one (see xtk_paint.h). The color itself still comes from the view's theme.
| Parameter | Description |
|---|---|
textview |
The view |
section |
The key's section: "textview" (the default), "datagrid", ... |
key |
The key: "background" (the default), "alternate-background", ... |
xtk_textview_set_syntax_highlighting
void xtk_textview_set_syntax_highlighting(XtkTextView *textview, int enabled);
Turn the view's own INI-style highlighting on (the default) or off.
| Parameter | Description |
|---|---|
textview |
The view |
enabled |
1 to turn it on, 0 to draw all text in text |
xtk_textview_set_wrap
void xtk_textview_set_wrap(XtkTextView *textview, int wrap);
Make long lines wrap, or not.
Off (the default), a line is one row however long, and what is past the right edge is not shown. On, it continues on the next row, broken after a space where it can be, else where it reaches the edge; Up and Down move a row at a time, and the line number shows on a line's first row. xtk_textview_get_scroll_position() is still the first line shown.
| Parameter | Description |
|---|---|
textview |
The view |
wrap |
1 to wrap, 0 not to |
xtk_textview_get_wrap
int xtk_textview_get_wrap(const XtkTextView *textview);
Whether long lines wrap (see xtk_textview_set_wrap()).
| Parameter | Description |
|---|---|
textview |
The view |
Returns: 1 if they wrap, 0 if not or if textview is NULL
xtk_textview_set_position
void xtk_textview_set_position(XtkTextView *textview, int x, int y);
Move the view in its parent, and map it.
| Parameter | Description |
|---|---|
textview |
The view |
x |
The new x position |
y |
The new y position |
xtk_textview_resize
void xtk_textview_resize(XtkTextView *textview, int width, int height);
Resize the view, and redraw it.
| Parameter | Description |
|---|---|
textview |
The view |
width |
The new width in pixels |
height |
The new height in pixels |
xtk_textview_get_window
Window xtk_textview_get_window(XtkTextView *textview);
The view's window.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: The window, or None if textview is NULL
xtk_textview_scroll_to_line
void xtk_textview_scroll_to_line(XtkTextView *textview, int line);
Scroll so that a line is the first one shown, as far as the text allows.
The caret does not move.
| Parameter | Description |
|---|---|
textview |
The view |
line |
The line, from 0 |
xtk_textview_get_scroll_position
int xtk_textview_get_scroll_position(XtkTextView *textview);
The first line shown.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: The line, from 0; 0 if textview is NULL
xtk_textview_find
int xtk_textview_find(XtkTextView *textview, const char *needle, int case_sensitive);
Find the next place a string occurs, and select it.
The search starts at the end of the selection (or at the caret) and goes on from the top when it reaches the end, as Find Next does.
| Parameter | Description |
|---|---|
textview |
The view |
needle |
The text to look for |
case_sensitive |
Non-zero to match case exactly, 0 to ignore the case of ASCII letters |
Returns: 1 if found (the match is selected, with the caret at its end, and scrolled into sight), 0 if it occurs nowhere or needle is empty
xtk_textview_replace_selection
int xtk_textview_replace_selection(XtkTextView *textview, const char *replacement);
Replace the selection, as typing over it would (one undo step).
| Parameter | Description |
|---|---|
textview |
The view |
replacement |
The text to put in; NULL or "" deletes the selection |
Returns: 1 if there was a selection, 0 if not or if the view is read-only
xtk_textview_replace_all
int xtk_textview_replace_all(
XtkTextView *textview,
const char *needle,
const char *replacement,
int case_sensitive);
Replace every place a string occurs, as one undo step.
The search goes once from the start to the end and never looks inside text it has just put in, so it ends even when the replacement holds the string.
| Parameter | Description |
|---|---|
textview |
The view |
needle |
The text to look for |
replacement |
The text to put in; NULL or "" deletes each match |
case_sensitive |
Non-zero to match case exactly, 0 to ignore the case of ASCII letters |
Returns: The number of replacements made; 0 in a read-only view
xtk_textview_get_size
void xtk_textview_get_size(const XtkTextView *textview, int *width, int *height);
The view's size.
| Parameter | Description |
|---|---|
textview |
The view; if NULL both sizes are 0 |
width |
Receives the width in pixels (may be NULL) |
height |
Receives the height in pixels (may be NULL) |
xtk_textview_get_line_box_height
int xtk_textview_get_line_box_height(const XtkTextView *textview);
The height of one line of text with the view's padding.
It is the least height a one-line view (a table cell, for example) needs to show its line whole, and it depends on the font.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: The height in pixels, or 0 if textview is NULL
xtk_textview_handle_event
int xtk_textview_handle_event(XtkTextView *textview, XEvent *event);
Give the view an X event.
Pass it every event; see "Events" and "Keys and mouse" in the file description.
| Parameter | Description |
|---|---|
textview |
The view |
event |
The event |
Returns: 1 if the view used the event (an Expose of its window, a key it acted on while focused, a press of the left, right or wheel buttons on it, a left-button release on it, motion it acted on, its focus events, or an event for its open menu), 0 otherwise
xtk_textview_draw
void xtk_textview_draw(XtkTextView *textview);
Draw the view now and flush the display.
The view draws itself after every change it makes; call this only after a change it cannot see.
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_set_change_callback
void xtk_textview_set_change_callback(
XtkTextView *textview,
XtkTextViewChangeCallback callback,
void *user_data);
Set the function called after each edit (see XtkTextViewChangeCallback).
| Parameter | Description |
|---|---|
textview |
The view |
callback |
The function, or NULL for none |
user_data |
Passed to the callback |
xtk_textview_set_edit_callback
void xtk_textview_set_edit_callback(
XtkTextView *textview,
XtkTextViewEditCallback callback,
void *user_data);
Set the function called before each change of the bytes (see XtkTextViewEditCallback).
| Parameter | Description |
|---|---|
textview |
The view |
callback |
The function, or NULL for none |
user_data |
Passed to the callback |
xtk_textview_set_focus_callback
void xtk_textview_set_focus_callback(XtkTextView *textview, void(*)(void)callback);
Set the function called when a click, xtk_textview_set_focused() or an X FocusIn gives the view focus.
Use it to take focus from the program's other input widgets (for example with xtk_entry_unfocus_all()).
| Parameter | Description |
|---|---|
textview |
The view |
callback |
The function, with no arguments, or NULL for none |
xtk_textview_set_ime
void xtk_textview_set_ime(XtkTextView *textview, XIM input_method);
Attach or detach an input method, for composed and CJK input.
See xtk_ime.h for the setup the program needs (setlocale() and XFilterEvent() in the event loop).
| Parameter | Description |
|---|---|
textview |
The view |
input_method |
An XIM from xtk_ime_open(), or NULL to detach |
xtk_textview_set_extra_context_item
void xtk_textview_set_extra_context_item(
XtkTextView *textview,
const char *label,
void(*)(void *user_data)callback,
void *user_data);
Add one item of the program's own to the right-click menu, or remove it.
The item goes after Redo, below a separator, so a program that embeds the view (a table cell, for example) can offer an action of its own, such as "Delete Row", without losing the view's own items. It is always enabled. The callback is called after the menu has closed and the view has redrawn, so it may destroy the view.
| Parameter | Description |
|---|---|
textview |
The view |
label |
The item's text, copied and cut to 31 bytes (the menu widens to fit it); NULL to remove the item |
callback |
Called with user_data when the item is chosen; NULL to remove the item |
user_data |
Passed to callback |
xtk_textview_set_extra_context_items
void xtk_textview_set_extra_context_items(
XtkTextView *textview,
const XtkTextViewContextItem *items,
int count);
Set the program's own items of the right-click menu: up to XTK_TEXTVIEW_CONTEXT_ITEMS_MAX, after Redo and a separator, in this order. They replace any set before.
A program can set them again just before the menu opens (on the right button's press, before it passes the event to the view), to offer items that depend on where the click is, such as Open Link over an address.
| Parameter | Description |
|---|---|
textview |
The view |
items |
The items (an item with no label or callback is left out), or NULL |
count |
How many; 0 removes them all |
xtk_textview_unfocus_all
void xtk_textview_unfocus_all(void);
Take focus from whichever view has it, and redraw that view.
Call it when another input widget takes focus.
xtk_textview_set_focused
void xtk_textview_set_focused(XtkTextView *textview, int focused);
Give the view keyboard focus, or take it away, without a click.
For the program's Tab focus handling. With focus, the focus callback runs, the view asks X for focus if its window is viewable, and the caret shows. Without, only the view's own focus state is cleared.
| Parameter | Description |
|---|---|
textview |
The view |
focused |
Non-zero to give it focus, 0 to take focus away |
xtk_textview_theme_init_dark
void xtk_textview_theme_init_dark(XtkTextViewTheme *theme);
Fill a theme with dark colors, the ones a view made with a NULL theme uses.
| Parameter | Description |
|---|---|
theme |
The theme to fill (NULL is ignored) |
xtk_textview_theme_init_light
void xtk_textview_theme_init_light(XtkTextViewTheme *theme);
Fill a theme with light colors.
| Parameter | Description |
|---|---|
theme |
The theme to fill (NULL is ignored) |
xtk_textview_set_file_path
void xtk_textview_set_file_path(XtkTextView *textview, const char *path);
Store a file path with the view, for the program's own use.
The view does not use it: xtk_textview_load_file() and xtk_textview_save_file() take their own path.
| Parameter | Description |
|---|---|
textview |
The view |
path |
The path, copied; NULL to clear it |
xtk_textview_get_file_path
const char *xtk_textview_get_file_path(XtkTextView *textview);
The path stored with xtk_textview_set_file_path().
| Parameter | Description |
|---|---|
textview |
The view |
Returns: The path, owned by the view, or NULL if none is stored or textview is NULL
xtk_textview_update_blink
void xtk_textview_update_blink(XtkTextView *textview);
Blink the caret.
Call it often from the event loop (for example every 50 ms). While the view has focus, the caret turns on or off every cursor_blink_ms of its theme ([behavior] cursor-blink-ms, default 600 ms) and the view is redrawn.
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_set_selection
void xtk_textview_set_selection(XtkTextView *textview, int start, int end);
Select a range of the text and redraw, without moving the caret or scrolling.
For showing a selection without the pointer. A folded block that holds either end opens.
| Parameter | Description |
|---|---|
textview |
The view |
start |
The byte offset where the selection starts; below 0 counts as 0 |
end |
The byte offset where it ends; -1 (or past the end) for the end of the text. When start is not before end, nothing is selected. |
xtk_textview_select_range
void xtk_textview_select_range(XtkTextView *textview, int start, int end);
Select a range with the caret at its end, scrolled into sight, as a found match is.
| Parameter | Description |
|---|---|
textview |
The view |
start |
The byte offset where the selection starts; below 0 counts as 0 |
end |
The byte offset where it ends; -1 (or past the end) for the end of the text |
xtk_textview_get_selection
int xtk_textview_get_selection(const XtkTextView *textview, int *start, int *end);
The selection, low end first.
| Parameter | Description |
|---|---|
textview |
The view |
start |
Receives its start, or the caret when nothing is selected (may be NULL) |
end |
Receives its end, or the caret when nothing is selected (may be NULL) |
Returns: 1 when something is selected, 0 when not
xtk_textview_set_extra_colors
void xtk_textview_set_extra_colors(
XtkTextView *textview,
const XtkTextViewExtraColors *colors);
Set the colors of XtkTextViewExtraColors, and redraw.
| Parameter | Description |
|---|---|
textview |
The view |
colors |
The colors, copied; NULL for the defaults: white space, indentation guides, fold boxes and line endings in line-numbers; the fold and markers margins in line-numbers-background; a bookmark in selection; change history in fixed orange (changed) and green (saved); the error wave in red; and no color for the caret's line |
xtk_textview_set_show_whitespace
void xtk_textview_set_show_whitespace(XtkTextView *textview, int enabled);
Show a dot for each space and an arrow for each tab, or not (off at first).
| Parameter | Description |
|---|---|
textview |
The view |
enabled |
1 to show them, 0 not to |
xtk_textview_set_indent_guides
void xtk_textview_set_indent_guides(XtkTextView *textview, int columns);
Draw dotted indentation guides in each line's indentation, or not.
A blank line takes the larger indentation of the lines around it.
| Parameter | Description |
|---|---|
textview |
The view |
columns |
The columns between guides (the indent width); 0 for none (the default) |
xtk_textview_set_line_ending_mark
void xtk_textview_set_line_ending_mark(XtkTextView *textview, const char *mark);
Name each line's ending in a small box after the line, or not.
The text has only '
', so the program says what the file has.
| Parameter | Description |
|---|---|
textview |
The view |
mark |
"LF", "CRLF", "CR", or NULL or "" for none (the default) |
xtk_textview_set_marker_margin
void xtk_textview_set_marker_margin(XtkTextView *textview, int enabled);
Show the markers margin, or hide it (the markers stay either way). It is hidden at first.
| Parameter | Description |
|---|---|
textview |
The view |
enabled |
1 to show it, 0 to hide it |
xtk_textview_margin_at
int xtk_textview_margin_at(const XtkTextView *textview, int x);
Which margin a point of the view is in: for a program that does something on a hover or a click there.
| Parameter | Description |
|---|---|
textview |
The view |
x |
A point's x in the view's window |
Returns: 1 the line numbers, 2 the markers margin, 3 the fold margin, 0 none of them (the text, the scrollbar)
xtk_textview_set_line_marker
void xtk_textview_set_line_marker(XtkTextView *textview, int line, unsigned kind, int on);
Put markers on a line, or take them off, and redraw.
| Parameter | Description |
|---|---|
textview |
The view |
line |
The line, from 0; a line that does not exist is ignored |
kind |
XTK_LINE_MARKER_* bits |
on |
1 to put them on, 0 to take them off |
xtk_textview_set_numbered_markers
void xtk_textview_set_numbered_markers(XtkTextView *textview, unsigned first);
Ten of the program's own marker bits drawn as numbered bookmarks: first is bookmark 0's bit, and bookmark n's is first << n. A line with one shows its digit in the markers margin, in a box of the bookmark's color.
| Parameter | Description |
|---|---|
textview |
The view |
first |
Bookmark 0's bit (XTK_LINE_MARKER_HOST or higher), or 0 for none |
xtk_textview_get_line_markers
unsigned xtk_textview_get_line_markers(const XtkTextView *textview, int line);
The markers on a line.
| Parameter | Description |
|---|---|
textview |
The view |
line |
The line, from 0 |
Returns: The XTK_LINE_MARKER_* bits on the line; 0 for none, for a line that does not exist, or if textview is NULL
xtk_textview_next_line_marker
int xtk_textview_next_line_marker(
const XtkTextView *textview,
int line,
unsigned kind,
int forward);
The next line, after or before a line, that has a marker of the given kinds.
The search does not go round from the end to the start.
| Parameter | Description |
|---|---|
textview |
The view |
line |
The line to start from, from 0 (itself is not counted); -1 with forward for the first line on |
kind |
XTK_LINE_MARKER_* bits; a line with any of them counts |
forward |
1 to look after the line, 0 to look before it |
Returns: The line, from 0, or -1 when there is none
xtk_textview_clear_line_markers
void xtk_textview_clear_line_markers(XtkTextView *textview, unsigned kinds);
Take the markers of the given kinds off every line, and redraw.
| Parameter | Description |
|---|---|
textview |
The view |
kinds |
XTK_LINE_MARKER_* bits |
xtk_textview_get_line_count
int xtk_textview_get_line_count(const XtkTextView *textview);
The number of lines in the text.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: The number of lines, at least 1 (an empty text has one line); 1 if textview is NULL
xtk_textview_set_change_history
void xtk_textview_set_change_history(XtkTextView *textview, int in_margin, int underline);
Show the change history, or not.
The view always marks the lines changed since the text was set (XTK_LINE_MARKER_MODIFIED), and xtk_textview_mark_saved() turns them into saved ones (XTK_LINE_MARKER_SAVED); this only chooses how they are shown.
| Parameter | Description |
|---|---|
textview |
The view |
in_margin |
1 for a bar in the markers margin (change_modified or change_saved color), shown only while the margin is shown (xtk_textview_set_marker_margin()) |
underline |
1 for a line under each changed line's text, in the same colors |
xtk_textview_set_long_line
void xtk_textview_set_long_line(
XtkTextView *textview,
int type,
int column,
ConfigColor color);
Set the long line marker, which shows where lines get too long.
| Parameter | Description |
|---|---|
textview |
The view |
type |
0 for none, 1 for a vertical line at the column, 2 to paint the background after the column |
column |
The column, counted in spaces of the font from the line's start; 0 or less for none |
color |
The marker's color |
xtk_textview_set_drag_text
void xtk_textview_set_drag_text(XtkTextView *textview, int enabled);
Allow drag and drop of the selected text, or not (off at first).
With it on, a press in the selection and a drag moves the selected text to where it is let go (with Ctrl held, copies it), as one undo step. A click in the selection without a drag places the caret.
| Parameter | Description |
|---|---|
textview |
The view |
enabled |
1 to turn it on, 0 to turn it off |
xtk_textview_set_rectangular_selection
void xtk_textview_set_rectangular_selection(XtkTextView *textview, int enabled);
Allow rectangular selection, or not (off at first).
With it on, Alt+drag, or Alt+Shift with the arrow keys, selects a block of columns over several lines. Typing, Backspace and Delete act on every line of the block (a block with no width is a caret on each line); Ctrl+C and Ctrl+X copy and cut its lines; Escape or any other move ends it. It does not work while lines wrap or a block is folded.
| Parameter | Description |
|---|---|
textview |
The view |
enabled |
1 to turn it on, 0 to turn it off |
xtk_textview_get_cursor_point
int xtk_textview_get_cursor_point(XtkTextView *textview, int *x, int *y);
Where the caret is drawn in the view's window: its left edge and the top of its row.
Use it to place a popup (a completion list, for example) at the caret.
| Parameter | Description |
|---|---|
textview |
The view |
x |
Receives the x position in pixels |
y |
Receives the y position in pixels |
Returns: 1, or 0 when the caret is out of sight or an argument is NULL
xtk_textview_has_rectangle
int xtk_textview_has_rectangle(const XtkTextView *textview);
Whether there is a rectangular selection now.
While there is one, the program should pass the view its keys rather than act on them itself.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: 1 when there is a rectangular selection, 0 when not
xtk_textview_shift_rectangle
int xtk_textview_shift_rectangle(XtkTextView *textview, int right_side);
Move the text of the rectangular selection one column left or right (Shift Column).
On each line, the character before the block goes after it (left), or the one after it goes before it (right; past a line's end a space comes in). The block moves with its text. One Undo step.
| Parameter | Description |
|---|---|
textview |
The view |
right_side |
1 to move right, 0 to move left |
Returns: 1 when it moved (draw the view again); 0 with no rectangular selection, one with no width, or at column 0 going left
xtk_textview_set_virtual_space
void xtk_textview_set_virtual_space(XtkTextView *textview, int mode);
Allow the caret and rectangular selections past the ends of lines.
Mode 0 (the default) allows neither. Mode 1 lets a rectangular selection go past the ends of lines; typing there fills with spaces. Mode 2 also lets the caret go there: a click past the end, Right at the end, and Up and Down keep the column. It does not work while lines wrap or a block is folded.
| Parameter | Description |
|---|---|
textview |
The view |
mode |
0, 1 or 2; any other value counts as 0 |
xtk_textview_set_scroll_past_end
void xtk_textview_set_scroll_past_end(XtkTextView *textview, int enabled);
Let the view scroll until the last line is at the top, or stop when the last line shows (the default).
| Parameter | Description |
|---|---|
textview |
The view |
enabled |
1 to scroll past the end, 0 not to |
xtk_textview_set_cursor_margin
void xtk_textview_set_cursor_margin(XtkTextView *textview, int lines);
Set how many lines are kept in sight above and below the caret when it moves.
At most half the view is kept. It does not work while lines wrap or a block is folded.
| Parameter | Description |
|---|---|
textview |
The view |
lines |
The number of lines; 0 (the default) or less for none |
xtk_textview_set_folding
void xtk_textview_set_folding(XtkTextView *textview, int enabled);
Show the fold margin and let blocks fold, or not.
Turned off, every block opens, the fold points are dropped, and the margin goes. It is off at first.
| Parameter | Description |
|---|---|
textview |
The view |
enabled |
1 to turn it on, 0 to turn it off |
xtk_textview_set_fold_points
void xtk_textview_set_fold_points(
XtkTextView *textview,
const XtkTextFoldPoint *points,
int count);
Give the view the blocks that can fold.
The view does not find blocks itself; the program does (from braces, or from its own parser) and gives them here, again after edits. A block that was folded stays folded when its opening brace is at the same offset. Until they are set again the points follow edits: a block whose brace an edit removes goes, and an edit inside a folded block opens it. A click on a block's box in the fold margin folds or opens it. Nothing happens while folding is off.
| Parameter | Description |
|---|---|
textview |
The view |
points |
The blocks, in any order; a point with close not after open, or outside the text, is skipped |
count |
The number of blocks |
xtk_textview_set_fold_children
void xtk_textview_set_fold_children(XtkTextView *textview, int enabled);
Make folding or opening a block do the same to the blocks inside it, or not (off at first).
| Parameter | Description |
|---|---|
textview |
The view |
enabled |
1 to turn it on, 0 to turn it off |
xtk_textview_fold_all
void xtk_textview_fold_all(XtkTextView *textview, int folded);
Fold or open every block, and redraw.
| Parameter | Description |
|---|---|
textview |
The view |
folded |
1 to fold them all, 0 to open them all |
xtk_textview_toggle_fold_at
int xtk_textview_toggle_fold_at(XtkTextView *textview, int position);
Fold or open the innermost block that holds a position's line, or starts on it.
| Parameter | Description |
|---|---|
textview |
The view |
position |
A byte offset in the text |
Returns: 1 when a block was folded or opened, 0 when there is none there or folding is off
xtk_textview_set_overview_width
void xtk_textview_set_overview_width(XtkTextView *textview, int width);
Show the minimap: the whole text drawn small (a pixel a column, two a line), beside the scrollbar, the part in sight shaded; a click or a drag in it scrolls there. A long text's minimap scrolls with the view.
| Parameter | Description |
|---|---|
textview |
The view |
width |
Its width in pixels; 0 hides it |
xtk_textview_set_overview_runs
void xtk_textview_set_overview_runs(
XtkTextView *textview,
const XtkTextOverviewRun *runs,
int count);
The minimap's colors: runs of the text (in the order of the text, copied); text with no run is drawn in the text color. The offsets are the text's as it is now; after edits the program sets them again.
xtk_textview_set_overview_marks
void xtk_textview_set_overview_marks(
XtkTextView *textview,
const XtkTextOverviewMark *marks,
int count);
Lines to mark (copied): a block at the minimap's right edge on each, and a tick on the scrollbar's track where the line is in the whole text.
xtk_textview_set_change_map
void xtk_textview_set_change_map(
XtkTextView *textview,
int shown,
const XtkTextChangeRun *runs,
int count);
Show the change map on the scrollbar's track: the whole text from top to bottom, each run a block in its color, with the thumb drawn as a frame round the part in sight so the blocks under it still show. While it shows, the scrollbar is a little wider and always drawn, and a press on the track off the thumb (or a drag from there) scrolls to that place. A comparison shows its changes in it.
| Parameter | Description |
|---|---|
textview |
The view |
shown |
Non-zero to show the strip (even with no runs), 0 to hide it |
runs |
The runs, copied |
count |
The number of runs |
xtk_textview_set_scrollbar_shown
void xtk_textview_set_scrollbar_shown(XtkTextView *textview, int shown);
Show or hide the view's scrollbar (shown at first). Hidden, the text takes its room; the view still scrolls by the wheel and the keys, and a program can keep it in step with another view's scrollbar.
| Parameter | Description |
|---|---|
textview |
The view |
shown |
Non-zero to show it |
xtk_textview_line_top
int xtk_textview_line_top(XtkTextView *textview, int line);
Where a line is on screen now: the y of its first row in the view, less than 0 above the view and past its height below it.
With wrap on, rows are counted only near the view: a line far off gets a y that is past the edge but not exact.
| Parameter | Description |
|---|---|
textview |
The view |
line |
The line, from 0; the line count gives the y under the last line |
Returns: The y in pixels
xtk_textview_set_marks
void xtk_textview_set_marks(XtkTextView *textview, const XtkTextMark *marks, int count);
Replace the view's marks, and redraw.
The marks are byte offsets into the text as it is now, and edits do not move them: a program that marks text sets them again from its change callback.
| Parameter | Description |
|---|---|
textview |
The view |
marks |
The marks, copied; later ones are painted over earlier ones |
count |
The number of marks; 0 clears them |
xtk_textview_get_cursor
int xtk_textview_get_cursor(const XtkTextView *textview);
The caret's position.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: The caret's byte offset in the text; 0 if textview is NULL
xtk_textview_position_at_point
int xtk_textview_position_at_point(XtkTextView *textview, int x, int y);
The text position at a point of the view's window: where a click there would put the caret.
| Parameter | Description |
|---|---|
textview |
The view |
x |
The x position in the view's window |
y |
The y position in the view's window |
Returns: The byte offset in the text, or -1 if textview is NULL
xtk_textview_set_cursor
void xtk_textview_set_cursor(XtkTextView *textview, int position);
Move the caret, clear the selection, scroll the caret into sight, and redraw.
| Parameter | Description |
|---|---|
textview |
The view |
position |
The byte offset; it is kept within the text |
xtk_textview_insert_text
void xtk_textview_insert_text(XtkTextView *textview, int position, const char *text);
Insert text at a position, as typing would: recorded for undo, with the change callback.
The selection is cleared first and the caret ends after the inserted text. In a read-only view no text goes in, but the selection is still cleared and the caret still moves to the position.
| Parameter | Description |
|---|---|
textview |
The view |
position |
The byte offset; it is kept within the text |
text |
The text to insert, up to its NUL; NULL is ignored |
xtk_textview_follow_edit
void xtk_textview_follow_edit(
XtkTextView *textview,
int offset,
int removed_length,
const char *inserted,
int inserted_length,
int record);
Make an edit made elsewhere: the same bytes change here, the cursor and the selection move with the text.
For two views of one document (a split window): an edit in one is made in the other with this. The view does not scroll to it, and the cursor stays on the text it was on. The edit callback and the change callback are called as for any edit (a program that follows both views must not copy the edit back).
| Parameter | Description |
|---|---|
textview |
The view |
offset |
Where the bytes change |
removed_length |
How many go |
inserted |
What comes in their place (not NUL-terminated), or NULL when inserted_length is 0 |
inserted_length |
How many bytes come in |
record |
1: Undo can take it back here (the view that holds the document's history); 0: not recorded |
xtk_textview_begin_group
void xtk_textview_begin_group(XtkTextView *textview);
Start a group: the edits until xtk_textview_end_group() are one step for undo and redo.
Use it for an editor command that changes several places (indenting the selected lines, moving a line), so one undo takes it all back. Groups nest: a group begun inside another (xtk_textview_replace_all() makes one of its own, for example) is part of the outer one, which stays one step until its own xtk_textview_end_group(). Every begin needs its end.
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_end_group
void xtk_textview_end_group(XtkTextView *textview);
End the group started by xtk_textview_begin_group().
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_undo
void xtk_textview_undo(XtkTextView *textview);
Undo the last edit (or group), as Ctrl+Z does, and redraw.
| Parameter | Description |
|---|---|
textview |
The view (nothing happens in a read-only view or with nothing to undo) |
xtk_textview_redo
void xtk_textview_redo(XtkTextView *textview);
Redo the last undone edit (or group), as Ctrl+Y does, and redraw.
| Parameter | Description |
|---|---|
textview |
The view (nothing happens in a read-only view or with nothing to redo) |
xtk_textview_can_undo
int xtk_textview_can_undo(const XtkTextView *textview);
Whether there is an edit to undo.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: 1 if there is one, 0 if not or if textview is NULL
xtk_textview_can_redo
int xtk_textview_can_redo(const XtkTextView *textview);
Whether there is an undone edit to redo.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: 1 if there is one, 0 if not or if textview is NULL
xtk_textview_is_modified
int xtk_textview_is_modified(const XtkTextView *textview);
Whether the text differs from when it was set, loaded or marked saved.
Undoing back to the saved text makes this 0 again. xtk_textview_load_file() and xtk_textview_set_text() start a new history, with the text unmodified.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: 1 if the text is modified, 0 if not or if textview is NULL
xtk_textview_mark_saved
void xtk_textview_mark_saved(XtkTextView *textview);
Count the text as it is now as saved, wherever the program wrote it.
The change history's changed lines become saved lines.
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_mark_unsaved
void xtk_textview_mark_unsaved(XtkTextView *textview);
Count the text as modified until the next save, whatever is undone.
Call it when the file on disk no longer matches the text, for example when its line endings were changed or it was deleted.
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_get_length
size_t xtk_textview_get_length(const XtkTextView *textview);
The text's length in bytes.
The text can hold NUL bytes, at which strlen() would stop.
| Parameter | Description |
|---|---|
textview |
The view |
Returns: The length in bytes, or 0 if textview is NULL
xtk_textview_cut
void xtk_textview_cut(XtkTextView *textview);
Cut the selection to the clipboard, as Ctrl+X does.
In a read-only view the selection is copied but not removed.
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_copy
void xtk_textview_copy(XtkTextView *textview);
Copy the selection to the clipboard, as Ctrl+C does.
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_paste
void xtk_textview_paste(XtkTextView *textview);
Paste the clipboard at the caret, as Ctrl+V does.
The paste is asynchronous: the text arrives through the clipboard's events, so the program must keep passing them to xtk_clipboard_handle_event().
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk_textview_select_all
void xtk_textview_select_all(XtkTextView *textview);
Select all the text, and redraw.
| Parameter | Description |
|---|---|
textview |
The view (NULL is ignored) |
xtk API
Widgets
- button
- checkbox
- radiobutton
- label
- entry
- textview
- edit_history
- spinbutton
- slider
- progressbar
- combobox
- scrollbar
- swatch
- panel
- statusbar
- tooltip
- toolbar
- icongrid
- iconview
- pathbar
- treeview
- datagrid
- graph
- scheme_wheel
- zoom
- tray
Containers and menus
Dialogs
Rich text
Drawing and images
Color
Configuration and themes
Input and the X server
Safety
Data formats