NetSurf
Data Structures | Typedefs | Enumerations | Functions
textarea.h File Reference

Single/Multi-line UTF-8 text area interface. More...

#include <stdint.h>
#include <stdbool.h>
#include "netsurf/plot_style.h"
#include "netsurf/mouse.h"
Include dependency graph for textarea.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  textarea_msg
 textarea message More...
 
struct  textarea_setup
 textarea setup parameters More...
 

Typedefs

typedef struct textarea_setup textarea_setup
 textarea setup parameters More...
 
typedef void(* textarea_client_callback) (void *data, struct textarea_msg *msg)
 Client callback for the textarea. More...
 

Enumerations

enum  textarea_flags {
  TEXTAREA_DEFAULT = (1 << 0) , TEXTAREA_MULTILINE = (1 << 1) , TEXTAREA_READONLY = (1 << 2) , TEXTAREA_INTERNAL_CARET = (1 << 3) ,
  TEXTAREA_PASSWORD = (1 << 4)
}
 Text area flags. More...
 
enum  textarea_drag_type { TEXTAREA_DRAG_NONE , TEXTAREA_DRAG_SCROLLBAR , TEXTAREA_DRAG_SELECTION }
 Textarea drag status. More...
 
enum  textarea_msg_type {
  TEXTAREA_MSG_DRAG_REPORT , TEXTAREA_MSG_SELECTION_REPORT , TEXTAREA_MSG_REDRAW_REQUEST , TEXTAREA_MSG_CARET_UPDATE ,
  TEXTAREA_MSG_TEXT_MODIFIED
}
 textarea message types More...
 
enum  textarea_mouse_status {
  TEXTAREA_MOUSE_NONE = 0 , TEXTAREA_MOUSE_USED = (1 << 0) , TEXTAREA_MOUSE_EDITOR = (1 << 1) , TEXTAREA_MOUSE_SELECTION = (1 << 2) ,
  TEXTAREA_MOUSE_SCR_USED = (1 << 3) , TEXTAREA_MOUSE_SCR_BOTH = (1 << 4) , TEXTAREA_MOUSE_SCR_UP = (1 << 5) , TEXTAREA_MOUSE_SCR_PUP = (1 << 6) ,
  TEXTAREA_MOUSE_SCR_VRT = (1 << 7) , TEXTAREA_MOUSE_SCR_PDWN = (1 << 8) , TEXTAREA_MOUSE_SCR_DWN = (1 << 9) , TEXTAREA_MOUSE_SCR_LFT = (1 << 10) ,
  TEXTAREA_MOUSE_SCR_PLFT = (1 << 11) , TEXTAREA_MOUSE_SCR_HRZ = (1 << 12) , TEXTAREA_MOUSE_SCR_PRGT = (1 << 13) , TEXTAREA_MOUSE_SCR_RGT = (1 << 14)
}
 Text area mouse input status flags. More...
 

Functions

struct textareatextarea_create (const textarea_flags flags, const textarea_setup *setup, textarea_client_callback callback, void *data)
 Create a text area. More...
 
void textarea_destroy (struct textarea *ta)
 Destroy a text area. More...
 
bool textarea_set_text (struct textarea *ta, const char *text)
 Set the text in a text area, discarding any current text. More...
 
bool textarea_drop_text (struct textarea *ta, const char *text, size_t text_length)
 Insert the text in a text area at the caret, replacing any selection. More...
 
int textarea_get_text (struct textarea *ta, char *buf, unsigned int len)
 Extract the text from a text area. More...
 
const char * textarea_data (struct textarea *ta, unsigned int *len)
 Access text data in a text area. More...
 
bool textarea_set_caret (struct textarea *ta, int caret)
 Set the caret's position. More...
 
void textarea_redraw (struct textarea *ta, int x, int y, colour bg, float scale, const struct rect *clip, const struct redraw_context *ctx)
 Handle redraw requests for text areas. More...
 
bool textarea_keypress (struct textarea *ta, uint32_t key)
 Key press handling for text areas. More...
 
textarea_mouse_status textarea_mouse_action (struct textarea *ta, browser_mouse_state mouse, int x, int y)
 Handles all kinds of mouse action. More...
 
bool textarea_clear_selection (struct textarea *ta)
 Clear any selection in the textarea. More...
 
char * textarea_get_selection (struct textarea *ta)
 Get selected text. More...
 
void textarea_get_dimensions (struct textarea *ta, int *width, int *height)
 Gets the dimensions of a textarea. More...
 
void textarea_set_dimensions (struct textarea *ta, int width, int height)
 Set the dimensions of a textarea. More...
 
void textarea_set_layout (struct textarea *ta, const plot_font_style_t *fstyle, int width, int height, int top, int right, int bottom, int left)
 Set the dimensions and padding of a textarea. More...
 
bool textarea_scroll (struct textarea *ta, int scrx, int scry)
 Scroll a textarea by an amount. More...
 

Detailed Description

Single/Multi-line UTF-8 text area interface.

Definition in file textarea.h.

Typedef Documentation

◆ textarea_client_callback

typedef void(* textarea_client_callback) (void *data, struct textarea_msg *msg)

Client callback for the textarea.

Parameters
datauser data passed at textarea creation
msgtextarea message data

Definition at line 156 of file textarea.h.

◆ textarea_setup

textarea setup parameters

Enumeration Type Documentation

◆ textarea_drag_type

Textarea drag status.

Enumerator
TEXTAREA_DRAG_NONE 
TEXTAREA_DRAG_SCROLLBAR 
TEXTAREA_DRAG_SELECTION 

Definition at line 52 of file textarea.h.

◆ textarea_flags

Text area flags.

Enumerator
TEXTAREA_DEFAULT 

Standard input.

TEXTAREA_MULTILINE 

Multiline area.

TEXTAREA_READONLY 

Non-editable.

TEXTAREA_INTERNAL_CARET 

Render own caret.

TEXTAREA_PASSWORD 

Obscured display.

Definition at line 40 of file textarea.h.

◆ textarea_mouse_status

Text area mouse input status flags.

Enumerator
TEXTAREA_MOUSE_NONE 

Not relevant.

TEXTAREA_MOUSE_USED 

Took action with input.

TEXTAREA_MOUSE_EDITOR 

Hover: caret pointer.

TEXTAREA_MOUSE_SELECTION 

Hover: selection.

TEXTAREA_MOUSE_SCR_USED 

Scrollbar action.

TEXTAREA_MOUSE_SCR_BOTH 

Scrolling both bars.

TEXTAREA_MOUSE_SCR_UP 

Hover: scroll up.

TEXTAREA_MOUSE_SCR_PUP 

Hover: scroll page up.

TEXTAREA_MOUSE_SCR_VRT 

Hover: vert.

drag bar

TEXTAREA_MOUSE_SCR_PDWN 

Hover: scroll page down.

TEXTAREA_MOUSE_SCR_DWN 

Hover: scroll down.

TEXTAREA_MOUSE_SCR_LFT 

Hover: scroll left.

TEXTAREA_MOUSE_SCR_PLFT 

Hover: scroll page left.

TEXTAREA_MOUSE_SCR_HRZ 

Hover: horiz.

drag bar

TEXTAREA_MOUSE_SCR_PRGT 

Hover: scroll page right.

TEXTAREA_MOUSE_SCR_RGT 

Hover: scroll right.

Definition at line 130 of file textarea.h.

◆ textarea_msg_type

textarea message types

Enumerator
TEXTAREA_MSG_DRAG_REPORT 

Textarea drag start/end report.

TEXTAREA_MSG_SELECTION_REPORT 

Textarea text selection presence.

TEXTAREA_MSG_REDRAW_REQUEST 

Textarea redraw request.

TEXTAREA_MSG_CARET_UPDATE 

Textarea caret.

TEXTAREA_MSG_TEXT_MODIFIED 

Textarea text modified.

Definition at line 62 of file textarea.h.

Function Documentation

◆ textarea_clear_selection()

bool textarea_clear_selection ( struct textarea ta)

◆ textarea_create()

struct textarea * textarea_create ( const textarea_flags  flags,
const textarea_setup setup,
textarea_client_callback  callback,
void *  data 
)

Create a text area.

Parameters
flagsflags controlling the text area creation
setuptextarea settings and style
callbackwill be called when textarea wants to redraw
datauser specified data which will be passed to callbacks
Returns
Opaque handle for textarea or 0 on error

Definition at line 1852 of file textarea.c.

References textarea_utf8::alloc, textarea::bar_x, textarea::bar_y, textarea::border_col, textarea_setup::border_col, textarea::border_width, textarea_setup::border_width, textarea::byte_off, textarea::callback, textarea::caret_pos, textarea::caret_x, textarea::caret_y, textarea_utf8::data, textarea::data, textarea_undo::details, textarea_undo::details_alloc, textarea::drag_info, textarea::drag_start, textarea::flags, textarea::h_extent, textarea_setup::height, textarea_undo::last_detail, textarea_utf8::len, textarea::line, textarea::line_count, textarea::line_height, textarea::lines, textarea::lines_alloc_size, textarea_undo::next_detail, nscss_screen_dpi, NSLOG, textarea::pad_bottom, textarea_setup::pad_bottom, textarea::pad_left, textarea_setup::pad_left, textarea::pad_right, textarea_setup::pad_right, textarea::pad_top, textarea_setup::pad_top, textarea::password, PLOT_STYLE_SCALE, textarea::scroll_x, textarea::scroll_y, textarea::sel_end, textarea::sel_start, textarea_setup::selected_bg, textarea_setup::selected_text, textarea::show, plot_font_style::size, TA_ALLOC_STEP, textarea_undo::text, textarea::text, textarea_setup::text, TEXTAREA_DRAG_NONE, TEXTAREA_MULTILINE, TEXTAREA_PASSWORD, textarea_reflow_multiline(), textarea_reflow_singleline(), textarea_set_text_style(), textarea_setup_text_offsets(), textarea_drag::type, textarea::undo, textarea_utf8::utf8_len, textarea::v_extent, textarea::vis_height, textarea::vis_width, and textarea_setup::width.

Referenced by box_textarea_create_textarea(), toolbar_create(), and treeview__create_textarea().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_data()

const char * textarea_data ( struct textarea ta,
unsigned int *  len 
)

Access text data in a text area.

Parameters
[in]taText area
[out]lenReturns byte length of returned text, if passed non-NULL.
Returns
textarea string data.

Definition at line 2101 of file textarea.c.

References textarea_utf8::data, textarea_utf8::len, and textarea::text.

Referenced by treeview__search_update_display().

Here is the caller graph for this function:

◆ textarea_destroy()

void textarea_destroy ( struct textarea ta)

Destroy a text area.

Parameters
taText area to destroy

Definition at line 1975 of file textarea.c.

References textarea::bar_x, textarea::bar_y, textarea_utf8::data, textarea_undo::details, textarea::flags, textarea::lines, textarea::password, scrollbar_destroy(), textarea_undo::text, textarea::text, TEXTAREA_PASSWORD, and textarea::undo.

Referenced by form_free_control(), toolbar_destroy(), treeview_destroy(), treeview_edit_cancel(), and treeview_edit_node_at_point().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_drop_text()

bool textarea_drop_text ( struct textarea ta,
const char *  text,
size_t  text_length 
)

Insert the text in a text area at the caret, replacing any selection.

Parameters
taText area
textUTF-8 text to set text area's contents to
text_lengthlength of text.
Returns
true on success, false on memory exhaustion or if ta lacks caret

< Redraw rectangle

Definition at line 2032 of file textarea.c.

References textarea::callback, textarea::data, textarea_msg::data, textarea::flags, textarea_msg::redraw, textarea::sel_end, textarea::sel_start, textarea_msg::ta, text(), textarea_get_caret(), TEXTAREA_MSG_REDRAW_REQUEST, TEXTAREA_READONLY, textarea_replace_text(), textarea_set_caret_internal(), textarea_msg::type, textarea::vis_height, textarea::vis_width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by html_drop_file_at_point().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_get_dimensions()

void textarea_get_dimensions ( struct textarea ta,
int *  width,
int *  height 
)

Gets the dimensions of a textarea.

Parameters
tatextarea widget
widthif not NULL, gets updated to the width of the textarea
heightif not NULL, gets updated to the height of the textarea

Definition at line 3308 of file textarea.c.

References height, textarea::vis_height, textarea::vis_width, and width.

◆ textarea_get_selection()

char * textarea_get_selection ( struct textarea ta)

Get selected text.

ownership of the returned string is passed to caller which needs to free it.

Parameters
taTextarea widget
Returns
Selected text, or NULL if none.

Definition at line 3278 of file textarea.c.

References textarea_utf8::data, textarea::sel_end, textarea::sel_start, and textarea::show.

Referenced by html_get_selection().

Here is the caller graph for this function:

◆ textarea_get_text()

int textarea_get_text ( struct textarea ta,
char *  buf,
unsigned int  len 
)

Extract the text from a text area.

Parameters
taText area
bufPointer to buffer to receive data, or NULL to read length required (includes trailing '\0')
lenLength (bytes) of buffer pointed to by buf, or 0 to read length
Returns
Length (bytes) written/required or -1 on error

Definition at line 2078 of file textarea.c.

References textarea_utf8::data, textarea_utf8::len, NSLOG, textarea::text, and text().

Referenced by toolbar_get_url(), toolbar_key_input(), treeview__search_cancel(), and treeview_edit_done().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_keypress()

bool textarea_keypress ( struct textarea ta,
uint32_t  key 
)

Key press handling for text areas.

Parameters
taThe text area which got the keypress
keyThe ucs4 character codepoint
Returns
true if the keypress is dealt with, false otherwise.

< Redraw rectangle

Definition at line 2450 of file textarea.c.

References line_info::b_length, line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::byte_off, textarea::callback, textarea::caret_pos, textarea::caret_x, netsurf_table::clipboard, clipboard, textarea_utf8::data, textarea::data, textarea_msg::data, textarea::flags, gui_clipboard_table::get, guit, textarea::h_extent, textarea_utf8::len, textarea::line, line(), textarea::line_count, textarea::line_height, textarea::lines, NS_KEY_CLEAR_SELECTION, NS_KEY_COPY_SELECTION, NS_KEY_CR, NS_KEY_CUT_SELECTION, NS_KEY_DELETE_LEFT, NS_KEY_DELETE_LINE, NS_KEY_DELETE_LINE_END, NS_KEY_DELETE_LINE_START, NS_KEY_DELETE_RIGHT, NS_KEY_DELETE_WORD_LEFT, NS_KEY_DELETE_WORD_RIGHT, NS_KEY_DOWN, NS_KEY_ESCAPE, NS_KEY_LEFT, NS_KEY_LINE_END, NS_KEY_LINE_START, NS_KEY_NL, NS_KEY_PAGE_DOWN, NS_KEY_PAGE_UP, NS_KEY_PASTE, NS_KEY_REDO, NS_KEY_RIGHT, NS_KEY_SELECT_ALL, NS_KEY_TEXT_END, NS_KEY_TEXT_START, NS_KEY_UNDO, NS_KEY_UP, NS_KEY_WORD_LEFT, NS_KEY_WORD_RIGHT, textarea::pad_bottom, textarea::pad_top, textarea_msg::redraw, textarea::sel_end, textarea::sel_start, textarea::show, textarea_msg::ta, textarea::text, textarea::text_y_offset_baseline, textarea_clear_selection(), textarea_get_caret(), TEXTAREA_MSG_REDRAW_REQUEST, TEXTAREA_MULTILINE, TEXTAREA_PASSWORD, TEXTAREA_READONLY, textarea_replace_text(), textarea_reset_selection(), textarea_scroll(), textarea_select(), textarea_set_caret_internal(), textarea_set_caret_xy(), textarea_undo(), textarea_msg::type, utf8_from_ucs4(), utf8_next(), utf8_prev(), textarea::v_extent, textarea::vis_height, textarea::vis_width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by box_textarea_keypress(), toolbar_key_input(), and treeview_keypress().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_mouse_action()

textarea_mouse_status textarea_mouse_action ( struct textarea ta,
browser_mouse_state  mouse,
int  x,
int  y 
)

Handles all kinds of mouse action.

Parameters
taText area
mousethe mouse state at action moment
xX coordinate
yY coordinate
Returns
the textarea mouse status

Definition at line 3069 of file textarea.c.

References textarea::bar_x, textarea::bar_y, textarea::border_width, BROWSER_MOUSE_DOUBLE_CLICK, BROWSER_MOUSE_DRAG_1, BROWSER_MOUSE_DRAG_2, BROWSER_MOUSE_HOLDING_1, BROWSER_MOUSE_HOLDING_2, BROWSER_MOUSE_HOVER, BROWSER_MOUSE_PRESS_1, BROWSER_MOUSE_PRESS_2, BROWSER_MOUSE_TRIPLE_CLICK, textarea::callback, textarea::data, textarea_msg::data, textarea_msg::drag, textarea::drag_info, textarea::drag_start, textarea::flags, SCROLLBAR_WIDTH, textarea::sel_end, textarea::sel_start, textarea_msg::ta, textarea_clear_selection(), textarea_drag_end(), TEXTAREA_DRAG_NONE, TEXTAREA_DRAG_SELECTION, textarea_get_b_off_xy(), textarea_get_caret(), TEXTAREA_MOUSE_EDITOR, TEXTAREA_MOUSE_NONE, textarea_mouse_scrollbar_action(), TEXTAREA_MOUSE_SELECTION, TEXTAREA_MOUSE_USED, TEXTAREA_MSG_DRAG_REPORT, TEXTAREA_MULTILINE, textarea_scroll(), textarea_select(), textarea_select_fragment(), textarea_select_paragraph(), textarea_set_caret_internal(), textarea_set_caret_xy(), textarea_drag::type, textarea_msg::type, textarea::vis_height, textarea::vis_width, textarea_msg::x, and textarea_msg::y.

Referenced by gadget_mouse_action(), html_drop_file_at_point(), mouse_action_drag_textarea(), toolbar_mouse_input(), treeview_edit_node_at_point(), and treeview_mouse_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_redraw()

void textarea_redraw ( struct textarea ta,
int  x,
int  y,
colour  bg,
float  scale,
const struct rect clip,
const struct redraw_context ctx 
)

Handle redraw requests for text areas.

Parameters
tatextarea to render
xx coordinate of textarea top
yy coordinate of textarea left
bgbackground colour under textarea
scalescale to render at
clipclip rectangle
ctxcurrent redraw context

Definition at line 2131 of file textarea.c.

References line_info::b_length, line_info::b_start, plot_font_style::background, textarea::bar_x, textarea::bar_y, textarea::border_col, textarea::border_width, textarea::byte_off, textarea::caret_pos, textarea::caret_x, textarea::caret_y, clip(), plotter_table::clip, textarea_utf8::data, plot_style_s::fill_colour, textarea::flags, textarea::fstyle, guit, netsurf_table::layout, line(), plotter_table::line, textarea::line_count, line_height(), textarea::line_height, textarea::lines, NS_TRANSPARENT, textarea::pad_left, redraw_context::plot, PLOT_OP_TYPE_NONE, PLOT_OP_TYPE_SOLID, pstyle_stroke_caret, plotter_table::rectangle, textarea::scroll_x, textarea::scroll_y, scrollbar_redraw(), SCROLLBAR_WIDTH, textarea::sel_end, textarea::sel_fstyle, textarea::sel_start, textarea::show, plot_font_style::size, plot_style_s::stroke_type, plotter_table::text, textarea::text_y_offset, textarea::text_y_offset_baseline, TEXTAREA_INTERNAL_CARET, textarea::vis_height, textarea::vis_width, line_info::width, gui_layout_table::width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by html_redraw_box(), toolbar_redraw(), and treeview_redraw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_scroll()

bool textarea_scroll ( struct textarea ta,
int  scrx,
int  scry 
)

Scroll a textarea by an amount.

Only does anything if multi-line textarea has scrollbars. If it scrolls, it will emit a redraw request.

Parameters
tatextarea widget
scrxnumber of px try to scroll in x direction
scrynumber of px try to scroll in y direction
Returns
true iff the textarea was scrolled

Definition at line 3367 of file textarea.c.

References textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::flags, textarea::h_extent, textarea::scroll_x, scrollbar_scroll(), TEXTAREA_MULTILINE, and textarea::vis_width.

Referenced by html_scroll_at_point(), textarea_keypress(), and textarea_mouse_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_set_caret()

bool textarea_set_caret ( struct textarea ta,
int  caret 
)

Set the caret's position.

Parameters
taText area
caret0-based character index to place caret at, -1 removes the caret
Returns
true on success false otherwise

Definition at line 2112 of file textarea.c.

References textarea_utf8::data, textarea_utf8::len, textarea::show, textarea_set_caret_internal(), and utf8_bounded_byte_length().

Referenced by box_textarea_keypress(), textarea_get_caret(), treeview__search_cancel(), and treeview_mouse_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_set_dimensions()

void textarea_set_dimensions ( struct textarea ta,
int  width,
int  height 
)

Set the dimensions of a textarea.

This causes a reflow of the text and does not emit a redraw request. Up to client to call textarea_redraw.

Parameters
tatextarea widget
widththe new width of the textarea
heightthe new height of the textarea

Definition at line 3318 of file textarea.c.

References textarea::flags, height, textarea_utf8::len, textarea::show, TEXTAREA_MULTILINE, textarea_reflow_multiline(), textarea_reflow_singleline(), textarea_setup_text_offsets(), textarea::vis_height, textarea::vis_width, and width.

Referenced by toolbar_set_dimensions(), and toolbar_set_width().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_set_layout()

void textarea_set_layout ( struct textarea ta,
const plot_font_style_t fstyle,
int  width,
int  height,
int  top,
int  right,
int  bottom,
int  left 
)

Set the dimensions and padding of a textarea.

This causes a reflow of the text. Does not emit a redraw request. Up to client to call textarea_redraw.

Parameters
tatextarea widget
widththe new width of the textarea
heightthe new height of the textarea
topthe new top padding of the textarea
rightthe new right padding of the textarea
bottomthe new bottom padding of the textarea
leftthe new left padding of the textarea

Definition at line 3336 of file textarea.c.

References plot_font_style::background, textarea::bar_x, textarea::bar_y, textarea::flags, plot_font_style::foreground, height, textarea_utf8::len, textarea::pad_bottom, textarea::pad_left, textarea::pad_right, textarea::pad_top, SCROLLBAR_WIDTH, textarea::sel_fstyle, textarea::show, TEXTAREA_MULTILINE, textarea_reflow_multiline(), textarea_reflow_singleline(), textarea_set_text_style(), textarea_setup_text_offsets(), textarea::vis_height, textarea::vis_width, and width.

Referenced by layout_block_context().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textarea_set_text()

bool textarea_set_text ( struct textarea ta,
const char *  text 
)

Set the text in a text area, discarding any current text.

Parameters
taText area
textUTF-8 text to set text area's contents to
Returns
true on success, false on memory exhaustion

Definition at line 1995 of file textarea.c.

References textarea_utf8::alloc, textarea_utf8::data, textarea::flags, textarea_undo::last_detail, textarea_utf8::len, textarea_undo::next_detail, NSLOG, TA_ALLOC_STEP, textarea::text, text(), TEXTAREA_MULTILINE, textarea_normalise_text(), textarea_reflow_multiline(), textarea_reflow_singleline(), textarea::undo, textarea_utf8::utf8_len, and utf8_length().

Referenced by box_textarea_create_textarea(), form_gadget_sync_with_dom(), toolbar_set_url(), treeview__search_cancel(), treeview_edit_node_at_point(), and treeview_set_search_string().

Here is the call graph for this function:
Here is the caller graph for this function: