NetSurf
|
Single/Multi-line UTF-8 text area implementation. More...
#include <stdint.h>
#include <string.h>
#include "utils/log.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "netsurf/browser_window.h"
#include "netsurf/plotters.h"
#include "netsurf/mouse.h"
#include "netsurf/keypress.h"
#include "netsurf/clipboard.h"
#include "netsurf/layout.h"
#include "css/utils.h"
#include "desktop/textarea.h"
#include "desktop/scrollbar.h"
#include "desktop/gui_internal.h"
Go to the source code of this file.
Data Structures | |
struct | line_info |
struct | textarea_drag |
struct | textarea_utf8 |
struct | textarea_undo_detail |
struct | textarea_undo |
struct | textarea |
Macros | |
#define | CARET_COLOR 0x0000FF |
#define | TA_ALLOC_STEP 512 |
#define | PASSWORD_REPLACEMENT "\xe2\x80\xa2" |
#define | PASSWORD_REPLACEMENT_W (sizeof(PASSWORD_REPLACEMENT) - 1) |
#define | LINE_CHUNK_SIZE 32 |
Functions | |
static void | textarea_normalise_text (struct textarea *ta, unsigned int b_start, unsigned int b_len) |
Normalises any line endings within the text, replacing CRLF or CR with LF as necessary. More... | |
static void | textarea_reset_selection (struct textarea *ta) |
Reset the selection (no redraw) More... | |
static int | textarea_get_caret (struct textarea *ta) |
Get the caret's position. More... | |
static bool | textarea_scroll_visible (struct textarea *ta) |
Scrolls a textarea to make the caret visible (doesn't perform a redraw) More... | |
static bool | textarea_set_caret_internal (struct textarea *ta, int caret_b) |
Set the caret position. More... | |
static bool | textarea_select (struct textarea *ta, int b_start, int b_end, bool force_redraw) |
Selects a character range in the textarea and redraws it. More... | |
static bool | textarea_select_fragment (struct textarea *ta) |
Selects a text fragment, relative to current caret position. More... | |
static bool | textarea_select_paragraph (struct textarea *ta) |
Selects paragraph, at current caret position. More... | |
static void | textarea_scrollbar_callback (void *client_data, struct scrollbar_msg_data *scrollbar_data) |
Callback for scrollbar widget. More... | |
static bool | textarea_reflow_singleline (struct textarea *ta, size_t b_off, struct rect *r) |
Reflow a single line textarea. More... | |
static bool | textarea_reflow_multiline (struct textarea *ta, const size_t b_start, const int b_length, struct rect *r) |
Reflow a multiline textarea from the given line onwards. More... | |
static size_t | textarea_get_b_off_xy (struct textarea *ta, int x, int y, bool visible) |
get byte offset from the beginning of the text for some coordinates More... | |
static bool | textarea_set_caret_xy (struct textarea *ta, int x, int y, bool visible) |
Set the caret's position. More... | |
static bool | textarea_insert_text (struct textarea *ta, const char *text, size_t b_off, size_t b_len, int *byte_delta, struct rect *r) |
Insert text into the textarea. More... | |
static void | textarea_char_to_byte_offset (struct textarea_utf8 *text, unsigned int start, unsigned int end, size_t *b_start, size_t *b_end) |
Helper for replace_text function converts character offset to byte offset. More... | |
static bool | textarea_replace_text_internal (struct textarea *ta, size_t b_start, size_t b_end, const char *rep, size_t rep_len, bool add_to_clipboard, int *byte_delta, struct rect *r) |
Perform actual text replacment in a textarea. More... | |
static bool | textarea_copy_to_undo_buffer (struct textarea *ta, size_t b_start, size_t b_end, size_t rep_len) |
Update undo buffer by adding any text to be replaced, and allocating space as appropriate. More... | |
static bool | textarea_replace_text (struct textarea *ta, size_t b_start, size_t b_end, const char *rep, size_t rep_len, bool add_to_clipboard, int *byte_delta, struct rect *r) |
Replace text in a textarea, updating undo buffer. More... | |
static bool | textarea_undo (struct textarea *ta, bool forward, unsigned int *caret, struct rect *r) |
Undo or redo previous change. More... | |
static bool | textarea_drag_end (struct textarea *ta, browser_mouse_state mouse, int x, int y) |
Handles the end of a drag operation. More... | |
static void | textarea_setup_text_offsets (struct textarea *ta) |
Setup text offsets after height / border / padding change. More... | |
static void | textarea_set_text_style (struct textarea *ta, const plot_font_style_t *fstyle, colour selected_text, colour selected_bg) |
Set font styles up for a textarea. More... | |
struct textarea * | textarea_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... | |
static textarea_mouse_status | textarea_mouse_scrollbar_action (struct textarea *ta, browser_mouse_state mouse, int x, int y) |
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... | |
Variables | |
static plot_style_t | pstyle_stroke_caret |
Single/Multi-line UTF-8 text area implementation.
Definition in file textarea.c.
#define CARET_COLOR 0x0000FF |
Definition at line 44 of file textarea.c.
#define LINE_CHUNK_SIZE 32 |
Definition at line 140 of file textarea.c.
#define PASSWORD_REPLACEMENT "\xe2\x80\xa2" |
Definition at line 118 of file textarea.c.
#define PASSWORD_REPLACEMENT_W (sizeof(PASSWORD_REPLACEMENT) - 1) |
Definition at line 119 of file textarea.c.
#define TA_ALLOC_STEP 512 |
Definition at line 45 of file textarea.c.
|
inlinestatic |
Helper for replace_text function converts character offset to byte offset.
text utf8 textarea text object start start character offset end end character offset b_start updated to byte offset of start in text b_end updated to byte offset of end in text
Definition at line 1390 of file textarea.c.
References line_info::b_start, text(), and utf8_next().
Referenced by textarea_replace_text_internal().
bool textarea_clear_selection | ( | struct textarea * | ta | ) |
Clear any selection in the textarea.
ta | textarea widget |
Definition at line 3205 of file textarea.c.
References line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::callback, textarea_msg::caret, textarea::caret_x, textarea::caret_y, textarea_msg::clip, textarea::data, textarea_msg::data, textarea::flags, textarea_msg::have_selection, textarea_msg::height, textarea::line_count, textarea::line_height, textarea::lines, max, min, textarea_msg::pos, textarea_msg::read_only, textarea_msg::redraw, textarea::scroll_x, textarea::scroll_y, SCROLLBAR_WIDTH, textarea::sel_end, textarea::sel_start, textarea_msg::selection, textarea_msg::ta, textarea::text_y_offset, TEXTAREA_INTERNAL_CARET, TEXTAREA_MSG_CARET_UPDATE, TEXTAREA_MSG_REDRAW_REQUEST, TEXTAREA_MSG_SELECTION_REPORT, TEXTAREA_READONLY, textarea_reset_selection(), textarea_msg::type, textarea::vis_height, textarea::vis_width, textarea_msg::x, rect::x0, rect::x1, textarea_msg::y, rect::y0, and rect::y1.
Referenced by html_clear_selection(), html_set_selection(), textarea_keypress(), textarea_mouse_action(), and textarea_select().
|
static |
Update undo buffer by adding any text to be replaced, and allocating space as appropriate.
ta | Textarea widget |
b_start | Start byte index of replaced section (inclusive) |
b_end | End byte index of replaced section (exclusive) |
rep_len | Byte length of replacement UTF-8 text |
Definition at line 1543 of file textarea.c.
References textarea_utf8::alloc, textarea_undo_detail::b_end, textarea_undo_detail::b_limit, textarea_undo_detail::b_start, textarea_undo_detail::b_text_start, textarea_utf8::data, textarea_undo::details, textarea_undo::details_alloc, textarea_undo::next_detail, NSLOG, TA_ALLOC_STEP, textarea_undo::text, textarea::text, and textarea::undo.
Referenced by textarea_replace_text().
struct textarea * textarea_create | ( | const textarea_flags | flags, |
const textarea_setup * | setup, | ||
textarea_client_callback | callback, | ||
void * | data | ||
) |
Create a text area.
flags | flags controlling the text area creation |
setup | textarea settings and style |
callback | will be called when textarea wants to redraw |
data | user specified data which will be passed to callbacks |
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().
const char * textarea_data | ( | struct textarea * | ta, |
unsigned int * | len | ||
) |
Access text data in a text area.
[in] | ta | Text area |
[out] | len | Returns byte length of returned text, if passed non-NULL. |
Definition at line 2101 of file textarea.c.
References textarea_utf8::data, textarea_utf8::len, and textarea::text.
Referenced by treeview__search_update_display().
void textarea_destroy | ( | struct textarea * | ta | ) |
Destroy a text area.
ta | Text 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().
|
static |
Handles the end of a drag operation.
ta | Text area |
mouse | the mouse state at drag end moment |
x | X coordinate |
y | Y coordinate |
Definition at line 1744 of file textarea.c.
References textarea_undo_detail::b_end, textarea::bar_x, textarea::border_width, textarea::callback, textarea_drag::data, textarea::data, textarea_msg::data, textarea_msg::drag, textarea::drag_info, textarea::drag_start, textarea_drag::scrollbar, scrollbar_mouse_drag_end(), SCROLLBAR_WIDTH, textarea_msg::ta, TEXTAREA_DRAG_NONE, TEXTAREA_DRAG_SCROLLBAR, TEXTAREA_DRAG_SELECTION, textarea_get_b_off_xy(), TEXTAREA_MSG_DRAG_REPORT, textarea_select(), textarea_drag::type, textarea_msg::type, textarea::vis_height, textarea::vis_width, textarea_msg::x, and textarea_msg::y.
Referenced by textarea_mouse_action().
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.
ta | Text area |
text | UTF-8 text to set text area's contents to |
text_length | length of text. |
< 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().
|
static |
get byte offset from the beginning of the text for some coordinates
ta | textarea widget |
x | X coordinate |
y | Y coordinate |
visible | true iff (x,y) is wrt visiable area, false for global |
Definition at line 1232 of file textarea.c.
References line_info::b_length, line_info::b_start, textarea::border_width, textarea_utf8::data, textarea::flags, textarea::fstyle, guit, netsurf_table::layout, line(), textarea::line_count, textarea::line_height, textarea::lines, textarea::pad_left, textarea::pad_top, gui_layout_table::position, textarea::scroll_x, textarea::scroll_y, textarea::show, and TEXTAREA_MULTILINE.
Referenced by textarea_drag_end(), textarea_mouse_action(), and textarea_set_caret_xy().
|
static |
Get the caret's position.
ta | Text area |
Definition at line 226 of file textarea.c.
References line_info::b_start, textarea::byte_off, textarea::caret_pos, textarea_utf8::len, textarea::line, textarea::line_count, textarea::lines, textarea::show, textarea_msg::ta, textarea::text, textarea_set_caret(), and textarea_utf8::utf8_len.
Referenced by textarea_drop_text(), textarea_keypress(), textarea_mouse_action(), textarea_select_fragment(), textarea_select_paragraph(), and textarea_set_caret_internal().
void textarea_get_dimensions | ( | struct textarea * | ta, |
int * | width, | ||
int * | height | ||
) |
Gets the dimensions of a textarea.
ta | textarea widget |
width | if not NULL, gets updated to the width of the textarea |
height | if 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.
char * textarea_get_selection | ( | struct textarea * | ta | ) |
Get selected text.
ownership of the returned string is passed to caller which needs to free it.
ta | Textarea widget |
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().
int textarea_get_text | ( | struct textarea * | ta, |
char * | buf, | ||
unsigned int | len | ||
) |
Extract the text from a text area.
ta | Text area |
buf | Pointer to buffer to receive data, or NULL to read length required (includes trailing '\0') |
len | Length (bytes) of buffer pointed to by buf, or 0 to read length |
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().
|
static |
Insert text into the textarea.
ta | Textarea widget |
text | UTF-8 text to insert |
b_off | 0-based byte offset in ta->show's text to insert at |
b_len | Byte length of UTF-8 text |
byte_delta | Updated to change in byte count in textarea (ta->show) |
r | Modified/reduced to area where redraw is required |
Note: b_off must be for ta->show
Definition at line 1311 of file textarea.c.
References textarea_utf8::alloc, textarea_utf8::data, textarea::flags, textarea_utf8::len, NSLOG, textarea::password, PASSWORD_REPLACEMENT_W, TA_ALLOC_STEP, textarea::text, text(), TEXTAREA_MULTILINE, textarea_normalise_text(), TEXTAREA_PASSWORD, TEXTAREA_READONLY, textarea_reflow_multiline(), textarea_reflow_singleline(), utf8_bounded_byte_length(), utf8_bounded_length(), and textarea_utf8::utf8_len.
Referenced by textarea_replace_text_internal().
bool textarea_keypress | ( | struct textarea * | ta, |
uint32_t | key | ||
) |
Key press handling for text areas.
ta | The text area which got the keypress |
key | The ucs4 character codepoint |
< 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().
textarea_mouse_status textarea_mouse_action | ( | struct textarea * | ta, |
browser_mouse_state | mouse, | ||
int | x, | ||
int | y | ||
) |
Handles all kinds of mouse action.
ta | Text area |
mouse | the mouse state at action moment |
x | X coordinate |
y | Y coordinate |
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().
|
static |
Definition at line 3010 of file textarea.c.
References textarea::bar_x, textarea::bar_y, textarea::border_width, textarea_drag::data, textarea::drag_info, textarea_drag::scrollbar, scrollbar_mouse_action(), SCROLLBAR_MOUSE_USED, SCROLLBAR_WIDTH, TEXTAREA_DRAG_NONE, TEXTAREA_DRAG_SCROLLBAR, TEXTAREA_MOUSE_NONE, TEXTAREA_MOUSE_SCR_USED, textarea_drag::type, textarea::vis_height, and textarea::vis_width.
Referenced by textarea_mouse_action().
|
static |
Normalises any line endings within the text, replacing CRLF or CR with LF as necessary.
If the textarea is single line, then all linebreaks are converted into spaces.
ta | Text area |
b_start | Byte offset to start at |
b_len | Byte length to check |
Definition at line 166 of file textarea.c.
References textarea::callback, textarea_utf8::data, textarea::data, textarea_msg::data, textarea::flags, textarea_utf8::len, textarea_msg::len, textarea_msg::modified, textarea_msg::ta, textarea::text, textarea_msg::text, TEXTAREA_MSG_TEXT_MODIFIED, TEXTAREA_MULTILINE, textarea_msg::type, and textarea_utf8::utf8_len.
Referenced by textarea_insert_text(), textarea_replace_text_internal(), and textarea_set_text().
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.
ta | textarea to render |
x | x coordinate of textarea top |
y | y coordinate of textarea left |
bg | background colour under textarea |
scale | scale to render at |
clip | clip rectangle |
ctx | current 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().
|
static |
Reflow a multiline textarea from the given line onwards.
ta | Textarea to reflow |
b_start | 0-based byte offset in ta->text to start of modification |
b_length | Byte length of change in textarea text |
r | Modified/reduced to area where redraw is required |
Definition at line 916 of file textarea.c.
References line_info::b_length, line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, textarea_utf8::data, textarea::flags, textarea::fstyle, guit, textarea::h_extent, netsurf_table::layout, textarea_utf8::len, line(), LINE_CHUNK_SIZE, textarea::line_count, textarea::line_height, textarea::lines, textarea::lines_alloc_size, max, min, NSERROR_OK, NSLOG, textarea::pad_bottom, textarea::pad_left, textarea::pad_right, textarea::pad_top, textarea::scroll_x, textarea::scroll_y, scrollbar_create(), scrollbar_destroy(), scrollbar_make_pair(), scrollbar_set_extents(), SCROLLBAR_WIDTH, gui_layout_table::split, textarea::text, text(), textarea::text_y_offset, TEXTAREA_MULTILINE, textarea_scrollbar_callback(), textarea::v_extent, textarea::vis_height, textarea::vis_width, line_info::width, gui_layout_table::width, rect::x0, rect::y0, and rect::y1.
Referenced by textarea_create(), textarea_insert_text(), textarea_replace_text_internal(), textarea_set_dimensions(), textarea_set_layout(), and textarea_set_text().
|
static |
Reflow a single line textarea.
ta | Textarea widget to reflow |
b_off | 0-based byte offset in ta->show's text to start of modification |
r | Modified/reduced to area where redraw is required |
Definition at line 816 of file textarea.c.
References textarea_utf8::alloc, line_info::b_length, line_info::b_start, textarea::border_width, textarea_utf8::data, textarea::flags, textarea::fstyle, guit, textarea::h_extent, netsurf_table::layout, textarea_utf8::len, LINE_CHUNK_SIZE, textarea::line_count, textarea::lines, textarea::lines_alloc_size, max, min, NSLOG, textarea::pad_left, textarea::pad_right, textarea::password, PASSWORD_REPLACEMENT, PASSWORD_REPLACEMENT_W, textarea::scroll_x, textarea::show, TA_ALLOC_STEP, textarea::text, TEXTAREA_MULTILINE, TEXTAREA_PASSWORD, textarea_utf8::utf8_len, textarea::vis_width, line_info::width, gui_layout_table::width, rect::x0, and rect::x1.
Referenced by textarea_create(), textarea_insert_text(), textarea_replace_text_internal(), textarea_set_dimensions(), textarea_set_layout(), and textarea_set_text().
|
static |
Replace text in a textarea, updating undo buffer.
ta | Textarea widget |
b_start | Start byte index of replaced section (inclusive) |
b_end | End byte index of replaced section (exclusive) |
rep | Replacement UTF-8 text to insert |
rep_len | Byte length of replacement UTF-8 text |
add_to_clipboard | True if replaced text to be added to clipboard |
byte_delta | Updated to change in byte count in textarea (ta->show) |
r | Updated to area where redraw is required |
Note, b_start and b_end must be the byte offsets in ta->show, so in the password textarea case, they are for ta->password.
Definition at line 1618 of file textarea.c.
References textarea_undo_detail::b_end, textarea_undo_detail::b_start, textarea_undo_detail::b_text_end, textarea_undo::details, textarea::flags, textarea_undo::last_detail, textarea_undo::next_detail, textarea_copy_to_undo_buffer(), TEXTAREA_PASSWORD, textarea_replace_text_internal(), and textarea::undo.
Referenced by textarea_drop_text(), and textarea_keypress().
|
static |
Perform actual text replacment in a textarea.
ta | Textarea widget |
b_start | Start byte index of replaced section (inclusive) |
b_end | End byte index of replaced section (exclusive) |
rep | Replacement UTF-8 text to insert |
rep_len | Byte length of replacement UTF-8 text |
add_to_clipboard | True iff replaced text to be added to clipboard |
byte_delta | Updated to change in byte count in textarea (ta->show) |
r | Updated to area where redraw is required |
Note, b_start and b_end must be the byte offsets in ta->show, so in the password textarea case, they are for ta->password.
Definition at line 1424 of file textarea.c.
References textarea_utf8::alloc, line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, netsurf_table::clipboard, textarea_utf8::data, textarea::flags, guit, textarea_utf8::len, NSLOG, textarea::password, PASSWORD_REPLACEMENT_W, SCROLLBAR_WIDTH, gui_clipboard_table::set, textarea::show, TA_ALLOC_STEP, textarea::text, textarea_char_to_byte_offset(), textarea_insert_text(), TEXTAREA_MULTILINE, textarea_normalise_text(), TEXTAREA_PASSWORD, TEXTAREA_READONLY, textarea_reflow_multiline(), textarea_reflow_singleline(), utf8_bounded_length(), textarea_utf8::utf8_len, utf8_length(), textarea::vis_height, textarea::vis_width, rect::x0, rect::x1, rect::y0, and rect::y1.
Referenced by textarea_replace_text(), and textarea_undo().
|
inlinestatic |
Reset the selection (no redraw)
ta | Text area |
Definition at line 214 of file textarea.c.
References textarea::sel_end, textarea::sel_start, and textarea_msg::ta.
Referenced by textarea_clear_selection(), and textarea_keypress().
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.
ta | textarea widget |
scrx | number of px try to scroll in x direction |
scry | number of px try to scroll in y direction |
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().
|
static |
Scrolls a textarea to make the caret visible (doesn't perform a redraw)
ta | The text area to be scrolled |
Definition at line 251 of file textarea.c.
References textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::byte_off, textarea::caret_pos, textarea::caret_x, textarea::caret_y, textarea::flags, textarea::h_extent, textarea::line_height, textarea::pad_bottom, textarea::pad_left, textarea::pad_right, textarea::pad_top, textarea::scroll_x, textarea::scroll_y, scrollbar_get_offset(), scrollbar_set(), SCROLLBAR_WIDTH, textarea_msg::ta, TEXTAREA_MULTILINE, textarea::v_extent, textarea::vis_height, textarea::vis_width, textarea_msg::x, and textarea_msg::y.
Referenced by textarea_set_caret_internal().
|
static |
Callback for scrollbar widget.
Definition at line 719 of file textarea.c.
References textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::byte_off, textarea::callback, textarea_msg::caret, textarea::caret_pos, textarea::caret_x, textarea::caret_y, textarea_msg::clip, textarea_drag::data, textarea::data, textarea_msg::data, textarea_msg::drag, textarea::drag_info, textarea::flags, textarea_msg::height, textarea::line_height, scrollbar_msg_data::msg, textarea_msg::pos, textarea_msg::redraw, textarea::scroll_x, textarea::scroll_y, scrollbar_msg_data::scrollbar, textarea_drag::scrollbar, scrollbar_get_offset(), SCROLLBAR_MSG_MOVED, SCROLLBAR_MSG_SCROLL_FINISHED, SCROLLBAR_MSG_SCROLL_START, SCROLLBAR_WIDTH, textarea::sel_start, textarea_msg::ta, TEXTAREA_DRAG_NONE, TEXTAREA_DRAG_SCROLLBAR, TEXTAREA_INTERNAL_CARET, TEXTAREA_MSG_CARET_UPDATE, TEXTAREA_MSG_DRAG_REPORT, TEXTAREA_MSG_REDRAW_REQUEST, textarea_drag::type, textarea_msg::type, textarea::vis_height, textarea::vis_width, textarea_msg::x, rect::x0, rect::x1, textarea_msg::y, rect::y0, and rect::y1.
Referenced by textarea_reflow_multiline().
|
static |
Selects a character range in the textarea and redraws it.
ta | Text area |
b_start | First character (inclusive) byte offset |
b_end | Last character (exclusive) byte offset |
force_redraw | Redraw whether selection changed or not |
Definition at line 503 of file textarea.c.
References line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::callback, textarea_msg::caret, textarea::data, textarea_msg::data, textarea::flags, textarea_msg::have_selection, textarea::line_count, textarea::line_height, textarea::lines, max, min, textarea_msg::read_only, textarea_msg::redraw, textarea::scroll_y, SCROLLBAR_WIDTH, textarea::sel_end, textarea::sel_start, textarea_msg::selection, textarea_msg::ta, textarea::text_y_offset, textarea_msg::TEXTAREA_CARET_HIDE, textarea_clear_selection(), TEXTAREA_INTERNAL_CARET, TEXTAREA_MSG_CARET_UPDATE, TEXTAREA_MSG_REDRAW_REQUEST, TEXTAREA_MSG_SELECTION_REPORT, TEXTAREA_READONLY, textarea_msg::type, textarea::vis_height, textarea::vis_width, rect::x0, rect::x1, rect::y0, and rect::y1.
Referenced by textarea_drag_end(), textarea_keypress(), textarea_mouse_action(), textarea_select_fragment(), and textarea_select_paragraph().
|
static |
Selects a text fragment, relative to current caret position.
ta | Text area |
Definition at line 628 of file textarea.c.
References textarea_utf8::data, textarea_utf8::len, textarea::show, textarea_msg::ta, textarea_get_caret(), and textarea_select().
Referenced by textarea_mouse_action().
|
static |
Selects paragraph, at current caret position.
ta | textarea widget |
Definition at line 679 of file textarea.c.
References textarea_utf8::data, textarea_utf8::len, textarea::show, textarea_msg::ta, textarea_get_caret(), and textarea_select().
Referenced by textarea_mouse_action().
bool textarea_set_caret | ( | struct textarea * | ta, |
int | caret | ||
) |
Set the caret's position.
ta | Text area |
caret | 0-based character index to place caret at, -1 removes the caret |
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().
|
static |
Set the caret position.
ta | Text area |
caret_b | Byte offset to caret |
Definition at line 352 of file textarea.c.
References line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::byte_off, textarea::callback, textarea_msg::caret, textarea::caret_pos, textarea::caret_x, textarea::caret_y, textarea_msg::clip, textarea_utf8::data, textarea::data, textarea_msg::data, textarea::flags, textarea::fstyle, guit, textarea_msg::height, height, netsurf_table::layout, textarea_utf8::len, textarea::line, textarea::line_count, textarea::line_height, textarea::lines, max, min, textarea::pad_left, textarea_msg::pos, textarea_msg::redraw, textarea::scroll_x, textarea::scroll_y, SCROLLBAR_WIDTH, textarea::show, textarea_msg::ta, textarea::text_y_offset, textarea_get_caret(), TEXTAREA_INTERNAL_CARET, TEXTAREA_MSG_CARET_UPDATE, TEXTAREA_MSG_REDRAW_REQUEST, TEXTAREA_MULTILINE, textarea_scroll_visible(), textarea_msg::type, textarea::vis_height, textarea::vis_width, width, gui_layout_table::width, textarea_msg::x, rect::x0, rect::x1, textarea_msg::y, rect::y0, and rect::y1.
Referenced by textarea_drop_text(), textarea_keypress(), textarea_mouse_action(), textarea_set_caret(), and textarea_set_caret_xy().
|
static |
Set the caret's position.
ta | textarea widget |
x | X coordinate |
y | Y coordinate |
visible | true iff (x,y) is wrt visiable area, false for global |
Definition at line 1289 of file textarea.c.
References textarea_get_b_off_xy(), and textarea_set_caret_internal().
Referenced by textarea_keypress(), and textarea_mouse_action().
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.
ta | textarea widget |
width | the new width of the textarea |
height | the 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().
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.
ta | textarea widget |
width | the new width of the textarea |
height | the new height of the textarea |
top | the new top padding of the textarea |
right | the new right padding of the textarea |
bottom | the new bottom padding of the textarea |
left | the 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().
bool textarea_set_text | ( | struct textarea * | ta, |
const char * | text | ||
) |
Set the text in a text area, discarding any current text.
ta | Text area |
text | UTF-8 text to set text area's contents to |
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().
|
static |
Set font styles up for a textarea.
[in] | ta | Textarea to update. |
[in] | fstyle | Font style to set in textarea. |
[in] | selected_text | Textarea selected text colour. |
[in] | selected_bg | Textarea selection background colour. |
Definition at line 1837 of file textarea.c.
References plot_font_style::background, plot_font_style::foreground, textarea::fstyle, textarea::sel_fstyle, and textarea_msg::ta.
Referenced by textarea_create(), and textarea_set_layout().
|
static |
Setup text offsets after height / border / padding change.
ta | Textarea widget |
Definition at line 1802 of file textarea.c.
References textarea::border_width, textarea::flags, textarea::fstyle, textarea::line_height, nscss_screen_dpi, textarea::pad_top, PLOT_STYLE_SCALE, plot_font_style::size, textarea_msg::ta, textarea::text_y_offset, textarea::text_y_offset_baseline, TEXTAREA_MULTILINE, and textarea::vis_height.
Referenced by textarea_create(), textarea_set_dimensions(), and textarea_set_layout().
|
static |
Undo or redo previous change.
ta | Textarea widget |
forward | Iff true, redo, else undo |
caret | Updated to new caret pos in textarea (ta->show) |
r | Updated to area where redraw is required |
Definition at line 1660 of file textarea.c.
References textarea_undo_detail::b_end, textarea_undo_detail::b_start, textarea_undo_detail::b_text_end, textarea_undo_detail::b_text_start, textarea_utf8::data, textarea_undo::details, textarea::flags, textarea_undo::last_detail, textarea_undo::next_detail, textarea_undo::text, textarea::text, TEXTAREA_PASSWORD, TEXTAREA_READONLY, textarea_replace_text_internal(), and textarea::undo.
Referenced by textarea_keypress().
|
static |
Definition at line 47 of file textarea.c.
Referenced by textarea_redraw().